3 # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file
6 from waflib.TaskGen import feature,after_method
7 from waflib import Utils,Task,Logs,Options
8 testlock=Utils.threading.Lock()
10 @after_method('apply_link')
12 if getattr(self,'link_task',None):
13 self.create_task('utest',self.link_task.outputs)
14 class utest(Task.Task):
18 def runnable_status(self):
19 if getattr(Options.options,'no_tests',False):
21 ret=super(utest,self).runnable_status()
23 if getattr(Options.options,'all_tests',False):
27 filename=self.inputs[0].abspath()
28 self.ut_exec=getattr(self.generator,'ut_exec',[filename])
29 if getattr(self.generator,'ut_fun',None):
30 self.generator.ut_fun(self)
32 fu=getattr(self.generator.bld,'all_test_paths')
33 except AttributeError:
36 for g in self.generator.bld.groups:
38 if getattr(tg,'link_task',None):
39 s=tg.link_task.outputs[0].parent.abspath()
42 def add_path(dct,path,var):
43 dct[var]=os.pathsep.join(Utils.to_list(path)+[os.environ.get(var,'')])
45 add_path(fu,lst,'PATH')
46 elif Utils.unversioned_sys_platform()=='darwin':
47 add_path(fu,lst,'DYLD_LIBRARY_PATH')
48 add_path(fu,lst,'LD_LIBRARY_PATH')
50 add_path(fu,lst,'LD_LIBRARY_PATH')
51 self.generator.bld.all_test_paths=fu
52 cwd=getattr(self.generator,'ut_cwd','')or self.inputs[0].parent.abspath()
53 testcmd=getattr(Options.options,'testcmd',False)
55 self.ut_exec=(testcmd%self.ut_exec[0]).split(' ')
56 proc=Utils.subprocess.Popen(self.ut_exec,cwd=cwd,env=fu,stderr=Utils.subprocess.PIPE,stdout=Utils.subprocess.PIPE)
57 (stdout,stderr)=proc.communicate()
58 tup=(filename,proc.returncode,stdout,stderr)
59 self.generator.utest_result=tup
62 bld=self.generator.bld
63 Logs.debug("ut: %r",tup)
65 bld.utest_results.append(tup)
66 except AttributeError:
67 bld.utest_results=[tup]
71 lst=getattr(bld,'utest_results',[])
73 Logs.pprint('CYAN','execution summary')
75 tfail=len([x for x in lst if x[1]])
76 Logs.pprint('CYAN',' tests that pass %d/%d'%(total-tfail,total))
77 for(f,code,out,err)in lst:
79 Logs.pprint('CYAN',' %s'%f)
80 Logs.pprint('CYAN',' tests that fail %d/%d'%(tfail,total))
81 for(f,code,out,err)in lst:
83 Logs.pprint('CYAN',' %s'%f)
84 def set_exit_code(bld):
85 lst=getattr(bld,'utest_results',[])
86 for(f,code,out,err)in lst:
90 msg.append('stdout:%s%s'%(os.linesep,out.decode('utf-8')))
92 msg.append('stderr:%s%s'%(os.linesep,err.decode('utf-8')))
93 bld.fatal(os.linesep.join(msg))
95 opt.add_option('--notests',action='store_true',default=False,help='Exec no unit tests',dest='no_tests')
96 opt.add_option('--alltests',action='store_true',default=False,help='Exec all unit tests',dest='all_tests')
97 opt.add_option('--testcmd',action='store',default=False,help='Run the unit tests using the test-cmd string'' example "--test-cmd="valgrind --error-exitcode=1'' %s" to run under valgrind',dest='testcmd')