Author: sebastien.lelong
Date: Sat Nov  1 02:27:53 2008
New Revision: 513

Added:
    trunk/tools/testing_matrix.tmpl
Modified:
    trunk/tools/jallib.py

Log:
generate htm page from a testing matrix + refactoring sample/test  
filename/path functions

Modified: trunk/tools/jallib.py
==============================================================================
--- trunk/tools/jallib.py       (original)
+++ trunk/tools/jallib.py       Sat Nov  1 02:27:53 2008
@@ -80,6 +80,32 @@
                        
jalfiles.update(get_jal_filenames(fulldf,subdir=os.path.join(subdir and  
subdir or "",df)))
        return jalfiles

+def get_full_sample_path(sample_dir,pic="",sample=""):
+       return os.path.join(sample_dir,"by_device",pic,sample)
+
+
+# cache found files
+explored_tests = None
+def get_full_test_path(sample_dir,test=""):
+       global explored_tests
+       testdir = os.path.join(sample_dir,"test")
+       if not test:
+               return testdir
+       else:
+               if not explored_tests:
+                       # exclude board
+                       tdirs = [(d,os.path.join(testdir,d)) for d in 
os.listdir(testdir) if  
not d.startswith(".") and d != "board"]
+                       # search for test file...
+                       test_files = {}
+                       for (subdir,tdir) in tdirs:
+                               
test_files.update(get_jal_filenames(tdir,subdir)) ## if  
f.startswith("test_")])
+                       explored_tests = test_files
+
+               return os.path.join(testdir,explored_tests[test])
+
+def get_full_board_path(sample_dir,board=""):
+       return os.path.join(sample_dir,"test","board",board)
+       

  ################
  # MAIN TARGETS #
@@ -128,7 +154,7 @@
        if not original_args:
                print >> sys.stderr, "Missing arguments to jalv2 compiler..."
                sys.exit(255)
-       
+
        # Try to extract jallib args
        opts, args = parse_args(args)
        if not opts:
@@ -168,7 +194,6 @@
        # Complete with compiler args
        if args:
                cmd.extend(args)
-       print "cmd: %s" % repr(cmd)
        try:
                status = subprocess.check_call(cmd,shell=False)
                return status
@@ -496,7 +521,7 @@
        elif do_html:
                if not got_html:
                        html_file = ".".join(tmpl_file.split(".")[:-1]) + 
".html"
-               
generate_html(tmpl_file,html_file,outfile,only_passed,each_pic_tmpl)
+                
generate_html(tmpl_file,html_file,outfile,sample_dir,only_passed,each_pic_tmpl)
        elif do_print:
                display_test_results(pic,outfile)
        else:
@@ -534,15 +559,15 @@
                if not "by_device" in os.listdir(dir):
                        print >> sys.stderr, "Sample dir '%s' does not contain 
'by_device'  
map." % dir
                        sys.exit(1)
-               for devicedir in os.listdir(os.path.join(dir,'by_device')):
+               for devicedir in os.listdir(get_full_sample_path(dir)):
                        if selected_pics and not devicedir in selected_pics:
                                # skip, not wanted by user
                                continue
-                       fullpath = os.path.join(dir,'by_device',devicedir)
+                       fullpath = get_full_sample_path(dir,devicedir)
                        if not os.path.isdir(fullpath) or 
devicedir.startswith("."):
                                continue
                        matrix.setdefault(devicedir,{'samples' : {}, 'tests' : 
{}})
-                       
analyze_samples(devicedir,os.path.join(dir,'by_device',devicedir))
+                       analyze_samples(devicedir,fullpath)

        def analyse_testdir(dir):
                if not "test" in os.listdir(dir):
@@ -552,13 +577,13 @@
                        print >> sys.stderr, "Sample dir '%s' does not contain 
'board' map." %  
os.path.join(dir,"test")
                        sys.exit(1)
                # Get ALL test files
-               testdir = os.path.join(dir,"test")
+               testdir = get_full_test_path(dir)
                tdirs = [(d,os.path.join(testdir,d)) for d in 
os.listdir(testdir) if not  
d.startswith(".") and d != "board"]
                test_files = {}
                for (subdir,tdir) in tdirs:
                        test_files.update(get_jal_filenames(tdir,subdir)) ## if 
 
f.startswith("test_")])
                # analyse board files, so pic can be deduced
-               boarddir = os.path.join(dir,"test","board")
+               boarddir = get_full_board_path(dir)
                for boardfile in os.listdir(boarddir):
                        if not boardfile.endswith(".jal"):
                                continue
@@ -572,7 +597,7 @@
                                continue
                        # now try to compile every tests with this given board
                        for test,pathtest in test_files.items():
-                               status =  
do_compile(["-i",os.path.join(boarddir,boardfile),os.path.join(testdir,pathtest)],exitonerror=False)
+                               status =  
do_compile(["-i",get_full_board_path(dir,boardfile),os.path.join(testdir,pathtest)],exitonerror=False)
                                if status == 0:
                                        # dispatch to devices
                                        
matrix[pic]['tests'].setdefault(test,{'pass' : None, 'revision' :  
None})
@@ -612,7 +637,7 @@
                        if not os.path.isdir(testdir):
                                print >> sys.stderr, "'%s' is not a valid 
directory" % testdir
                                sys.exit(1)
-                       tfiles = 
get_jal_filenames(os.path.join(sample_dir,'test'))
+                       tfiles = 
get_jal_filenames(get_full_test_path(sample_dir))
                        if not testfile in tfiles.keys():
                                print >> sys.stderr, "Can't find test '%s'" % 
testfile
                                sys.exit(1)
@@ -620,7 +645,7 @@
                else:
                        tdict = matrix[pic]['samples']
                        # check if sample exist, and under svn
-                       bydevice = os.path.join(sample_dir,'by_device')
+                       bydevice = get_full_sample_path(sample_dir)
                        if not os.path.isdir(bydevice):
                                print >> sys.stderr, "'%s' is not a valid 
directory" % bydevice
                                sys.exit(1)
@@ -679,7 +704,12 @@
                print >> sys.stderr, "Unable to delete '%s' from PIC %s, cannot 
 
find '%s'" % (testfile,pic,e)
                sys.exit(1)

-def  
generate_html(tmpl_file,html_file,outfile,only_passed=False,for_each_pic_tmpl=None):
+def find_includes(jalfile):
+       content = file(jalfile).read()
+       return re.findall("^\s*include\s+(\w+)\s*",content,re.MULTILINE)
+
+
+def  
generate_html(tmpl_file,html_file,outfile,sample_dir,only_passed=False,for_each_pic_tmpl=None):
        if not has_cheetah:
                print >> sys.stderr, "You can't use this action, because 
cheetah module  
is not installed"
                sys.exit(255)
@@ -688,12 +718,31 @@
        tmplsrc = "".join(file(tmpl_file,"r").readlines())
        klass = Cheetah.Template.Template.compile(tmplsrc)
        tmpl = klass()
-       if only_passed:
+
+       # TODO
+       for pic,res in matrix.items():
                newtr = {}
-               for pic,res in matrix.items():
-                       if True in [res['samples'][k]['pass'] for k in 
res['samples'].keys()]:
-                               newtr[pic] = res
-               matrix = newtr
+               libs = {True : [], False : [], None: []}
+               # build libds list for all samples attached to this PIC
+               # and also a list of libs for each samples
+               # (both used for main matrix and dedicated test page)
+               for sample,info in res['samples'].items() + 
res['tests'].items():
+                       if sample.startswith("test_"):
+                               found_libs = 
find_includes(get_full_test_path(sample_dir,sample))
+                       else:
+                               found_libs = 
find_includes(get_full_sample_path(sample_dir,pic,sample))
+                       # normalize
+                       found_libs = map(lambda x: x.lower(),found_libs)
+                       info['libs'] = found_libs
+                       libs[info['pass']].extend(found_libs)
+               # unique
+               for k in libs.keys():
+                       libs[k] = list(set(libs[k]))
+               if only_passed and len(libs[True]) == 0:
+                       continue
+               else:
+                       matrix[pic]['libs'] = libs
+
        tmpl.test_results = matrix
        fout = file(html_file,"w")
        print >> fout, tmpl.main()

Added: trunk/tools/testing_matrix.tmpl
==============================================================================
--- (empty file)
+++ trunk/tools/testing_matrix.tmpl     Sat Nov  1 02:27:53 2008
@@ -0,0 +1,116 @@
+
+#def header
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
+<html>
+        <head>
+        </head>
+        <body>
+#end def
+
+#def get_meter_label(meter)
+       #silent print "met:er %s" % repr(meter)
+       #if meter < 0
+               #return "not supported"
+       #elif meter == 0
+               #return "not tested"
+       #elif meter <= 10
+               #return "poor"
+       #elif meter <= 30
+               #return "risky"
+       #elif meter <= 50
+               #return "average"
+       #elif meter <= 60
+               #return "nice"
+       #elif meter <= 70
+               #return "good"
+       #elif meter <= 80
+               #return "very good"
+       #elif meter <= 90
+               #return "awesome"
+       #elif meter <= 100
+               #return "oh my..."
+       #else
+               #return "can't be serious"
+       #end if
+#end def
+
+#def sample_stat(data)
+       #set true = false = none = 0
+       #for what in ('samples','tests')
+               #silent true += len([s for s in data[what] if 
data[what][s]['pass'] ==  
True])
+               #silent false += len([s for s in data[what] if 
data[what][s]['pass'] ==  
False])
+               #silent none += len([s for s in data[what] if 
data[what][s]['pass'] ==  
None])
+       #end for
+       #return (true,false,none)
+#end def
+
+#def compute_meter(data)
+       #silent print "data: %s" % data
+       #set sample_num = len(data['samples']) + len(data['tests'])
+       #if sample_num == 0
+               #return 0.0
+       #end if
+       #set true,false,none = $sample_stat(data)
+       #silent print "true_samples: %s, false_samples: %s, none_samples: %s  
--- %s sample_num" % (true,false,none,sample_num)
+       #set note = ((float(true) - float(false)) / float(sample_num)) * 100.0
+       #silent print "note: %s" % note
+       #return note
+#end def
+
+#def matrix
+       
+       <table border=1 width="100%" cellpadding=5>
+       <tr>
+               <th>PIC</th>
+               <th>Testing meter</th>
+               <th>Libraries</th>
+       </tr>
+
+       #for pic,data in sorted($test_results.items(),lambda x,y: 
cmp(x[0],y[0]))
+       <tr>
+               <td align="center" width="10%"><a 
href="test_${pic}.html">$pic</a></td>
+               #silent print "PIC: %s" % pic
+               #silent print "true: %s" % data['libs'][True]
+               #silent print "false: %s" % data['libs'][False]
+               #silent print "none: %s" % data['libs'][None]
+               #set note = int($compute_meter($data))
+               #set label = $get_meter_label($note)
+               #set true,false,none = $sample_stat($data)
+               #set sample_num = sum([true,false,none])
+               #silent print "..."
+               <td align="center" width="15%" nowrap="true">
+                       <div style="font-size: 10px;">$label</div>
+                       <img alt="$note% / $label"  
src="http://chart.apis.google.com/chart?cht=bhs&amp;chs=200x20&amp;chd=t:$note%7C100&amp;chco=4d89f9,c6d9fd&amp;chbh=15"/>
+               </td>
+               ## precedence: true libs > none libs > false libs
+               #set true_libs = set(data['libs'][True])
+               #set none_libs = set(data['libs'][None]).difference(true_libs)
+               #set false_libs =  
set(data['libs'][False]).difference(none_libs).difference(true_libs)
+               <td>
+                       #set strtrue = ", ".join(sorted(true_libs))
+                       #set strnone = ", ".join(sorted(none_libs))
+                       #set strfalse = ", ".join(sorted(false_libs))
+                       <table width="100%">
+                       <tr><td width="10%"><i>success</i></td><td><span 
style="color:  
green;">$strtrue</span></td></tr>
+                       <tr><td width="10%"><i>untested</i></td><td><span  
style="color:blue;">$strnone</span></td></tr>
+                       <tr><td width="10%"><i>failed</i></td><td><span 
style="color:  
red;">$strfalse</span></td></tr>
+                       </table>
+                       <div style="font-size: 12px;">
+                               <i>number of tests: 
</i>$sample_num&nbsp;&nbsp;<i>pass:  
</i>$true&nbsp;&nbsp;<i>fail: </i>$false&nbsp;&nbsp;<i>unknown: </i>$none
+                       </div>
+               </td>
+       </tr>
+       #end for
+       
+#end def
+
+#def footer
+       </body>
+</html>
+#end def
+
+#def main
+   $header
+   $matrix
+   $footer
+#end def

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"jallib" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/jallib?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to