1 | #! /usr/bin/env python |
---|
2 | # encoding: utf-8 |
---|
3 | # WARNING! Do not edit! http://waf.googlecode.com/git/docs/wafbook/single.html#_obtaining_the_waf_file |
---|
4 | |
---|
5 | import os |
---|
6 | from waflib.TaskGen import feature,after_method,taskgen_method |
---|
7 | from waflib import Utils,Task,Logs,Options |
---|
8 | testlock=Utils.threading.Lock() |
---|
9 | @feature('test') |
---|
10 | @after_method('apply_link') |
---|
11 | def make_test(self): |
---|
12 | if getattr(self,'link_task',None): |
---|
13 | self.create_task('utest',self.link_task.outputs) |
---|
14 | @taskgen_method |
---|
15 | def add_test_results(self,tup): |
---|
16 | Logs.debug("ut: %r",tup) |
---|
17 | self.utest_result=tup |
---|
18 | try: |
---|
19 | self.bld.utest_results.append(tup) |
---|
20 | except AttributeError: |
---|
21 | self.bld.utest_results=[tup] |
---|
22 | class utest(Task.Task): |
---|
23 | color='PINK' |
---|
24 | after=['vnum','inst'] |
---|
25 | vars=[] |
---|
26 | def runnable_status(self): |
---|
27 | if getattr(Options.options,'no_tests',False): |
---|
28 | return Task.SKIP_ME |
---|
29 | ret=super(utest,self).runnable_status() |
---|
30 | if ret==Task.SKIP_ME: |
---|
31 | if getattr(Options.options,'all_tests',False): |
---|
32 | return Task.RUN_ME |
---|
33 | return ret |
---|
34 | def add_path(self,dct,path,var): |
---|
35 | dct[var]=os.pathsep.join(Utils.to_list(path)+[os.environ.get(var,'')]) |
---|
36 | def get_test_env(self): |
---|
37 | try: |
---|
38 | fu=getattr(self.generator.bld,'all_test_paths') |
---|
39 | except AttributeError: |
---|
40 | fu=os.environ.copy() |
---|
41 | lst=[] |
---|
42 | for g in self.generator.bld.groups: |
---|
43 | for tg in g: |
---|
44 | if getattr(tg,'link_task',None): |
---|
45 | s=tg.link_task.outputs[0].parent.abspath() |
---|
46 | if s not in lst: |
---|
47 | lst.append(s) |
---|
48 | if Utils.is_win32: |
---|
49 | self.add_path(fu,lst,'PATH') |
---|
50 | elif Utils.unversioned_sys_platform()=='darwin': |
---|
51 | self.add_path(fu,lst,'DYLD_LIBRARY_PATH') |
---|
52 | self.add_path(fu,lst,'LD_LIBRARY_PATH') |
---|
53 | else: |
---|
54 | self.add_path(fu,lst,'LD_LIBRARY_PATH') |
---|
55 | self.generator.bld.all_test_paths=fu |
---|
56 | return fu |
---|
57 | def run(self): |
---|
58 | filename=self.inputs[0].abspath() |
---|
59 | self.ut_exec=getattr(self.generator,'ut_exec',[filename]) |
---|
60 | if getattr(self.generator,'ut_fun',None): |
---|
61 | self.generator.ut_fun(self) |
---|
62 | cwd=getattr(self.generator,'ut_cwd','')or self.inputs[0].parent.abspath() |
---|
63 | testcmd=getattr(self.generator,'ut_cmd',False)or getattr(Options.options,'testcmd',False) |
---|
64 | if testcmd: |
---|
65 | self.ut_exec=(testcmd%self.ut_exec[0]).split(' ') |
---|
66 | proc=Utils.subprocess.Popen(self.ut_exec,cwd=cwd,env=self.get_test_env(),stderr=Utils.subprocess.PIPE,stdout=Utils.subprocess.PIPE) |
---|
67 | (stdout,stderr)=proc.communicate() |
---|
68 | tup=(filename,proc.returncode,stdout,stderr) |
---|
69 | testlock.acquire() |
---|
70 | try: |
---|
71 | return self.generator.add_test_results(tup) |
---|
72 | finally: |
---|
73 | testlock.release() |
---|
74 | def summary(bld): |
---|
75 | lst=getattr(bld,'utest_results',[]) |
---|
76 | if lst: |
---|
77 | Logs.pprint('CYAN','execution summary') |
---|
78 | total=len(lst) |
---|
79 | tfail=len([x for x in lst if x[1]]) |
---|
80 | Logs.pprint('CYAN',' tests that pass %d/%d'%(total-tfail,total)) |
---|
81 | for(f,code,out,err)in lst: |
---|
82 | if not code: |
---|
83 | Logs.pprint('CYAN',' %s'%f) |
---|
84 | Logs.pprint('CYAN',' tests that fail %d/%d'%(tfail,total)) |
---|
85 | for(f,code,out,err)in lst: |
---|
86 | if code: |
---|
87 | Logs.pprint('CYAN',' %s'%f) |
---|
88 | def set_exit_code(bld): |
---|
89 | lst=getattr(bld,'utest_results',[]) |
---|
90 | for(f,code,out,err)in lst: |
---|
91 | if code: |
---|
92 | msg=[] |
---|
93 | if out: |
---|
94 | msg.append('stdout:%s%s'%(os.linesep,out.decode('utf-8'))) |
---|
95 | if err: |
---|
96 | msg.append('stderr:%s%s'%(os.linesep,err.decode('utf-8'))) |
---|
97 | bld.fatal(os.linesep.join(msg)) |
---|
98 | def options(opt): |
---|
99 | opt.add_option('--notests',action='store_true',default=False,help='Exec no unit tests',dest='no_tests') |
---|
100 | opt.add_option('--alltests',action='store_true',default=False,help='Exec all unit tests',dest='all_tests') |
---|
101 | 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') |
---|