[0fa325b] | 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 | |
---|
[904702d] | 5 | import os |
---|
| 6 | from waflib.TaskGen import feature,after_method,taskgen_method |
---|
[0fa325b] | 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) |
---|
[904702d] | 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] |
---|
[0fa325b] | 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 |
---|
[904702d] | 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): |
---|
[0fa325b] | 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): |
---|
[c101fe1] | 45 | s=tg.link_task.outputs[0].parent.abspath() |
---|
| 46 | if s not in lst: |
---|
| 47 | lst.append(s) |
---|
[0fa325b] | 48 | if Utils.is_win32: |
---|
[904702d] | 49 | self.add_path(fu,lst,'PATH') |
---|
[0fa325b] | 50 | elif Utils.unversioned_sys_platform()=='darwin': |
---|
[904702d] | 51 | self.add_path(fu,lst,'DYLD_LIBRARY_PATH') |
---|
| 52 | self.add_path(fu,lst,'LD_LIBRARY_PATH') |
---|
[0fa325b] | 53 | else: |
---|
[904702d] | 54 | self.add_path(fu,lst,'LD_LIBRARY_PATH') |
---|
[0fa325b] | 55 | self.generator.bld.all_test_paths=fu |
---|
[904702d] | 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) |
---|
[0fa325b] | 62 | cwd=getattr(self.generator,'ut_cwd','')or self.inputs[0].parent.abspath() |
---|
[904702d] | 63 | testcmd=getattr(self.generator,'ut_cmd',False)or getattr(Options.options,'testcmd',False) |
---|
[0fa325b] | 64 | if testcmd: |
---|
| 65 | self.ut_exec=(testcmd%self.ut_exec[0]).split(' ') |
---|
[904702d] | 66 | proc=Utils.subprocess.Popen(self.ut_exec,cwd=cwd,env=self.get_test_env(),stderr=Utils.subprocess.PIPE,stdout=Utils.subprocess.PIPE) |
---|
[0fa325b] | 67 | (stdout,stderr)=proc.communicate() |
---|
| 68 | tup=(filename,proc.returncode,stdout,stderr) |
---|
| 69 | testlock.acquire() |
---|
| 70 | try: |
---|
[904702d] | 71 | return self.generator.add_test_results(tup) |
---|
[0fa325b] | 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') |
---|