Changeset 988 for vendor/current/selftest/selftesthelpers.py
- Timestamp:
- Nov 24, 2016, 1:14:11 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
vendor/current/selftest/selftesthelpers.py
r740 r988 21 21 import os 22 22 import subprocess 23 import sys 23 24 24 25 def srcdir(): 25 return os.path.normpath(os. path.join(os.path.dirname(os.path.abspath(__file__)), ".."))26 return os.path.normpath(os.getenv("SRCDIR", os.path.join(os.path.dirname(os.path.abspath(__file__)), ".."))) 26 27 27 28 def source4dir(): 28 return os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), "../source4")) 29 return os.path.normpath(os.path.join(srcdir(), "source4")) 30 31 def source3dir(): 32 return os.path.normpath(os.path.join(srcdir(), "source3")) 29 33 30 34 def bindir(): 31 return os.path.normpath(os. path.join(os.getenv("BUILDDIR", "."), "bin"))35 return os.path.normpath(os.getenv("BINDIR", "./bin")) 32 36 33 37 def binpath(name): 34 return os.path.join(bindir(), "%s%s" % (name, os.getenv("EXEEXT", "")))38 return os.path.join(bindir(), name) 35 39 36 perl = os.getenv("PERL", "perl") 37 perl = perl.split()40 # Split perl variable to allow $PERL to be set to e.g. "perl -W" 41 perl = os.getenv("PERL", "perl").split() 38 42 39 43 if subprocess.call(perl + ["-e", "eval require Test::More;"]) == 0: … … 42 46 has_perl_test_more = False 43 47 44 try:45 from subunit.run import TestProgram46 except ImportError:47 has_system_subunit_run = False48 else:49 has_system_subunit_run = True50 51 48 python = os.getenv("PYTHON", "python") 52 49 53 #Set a default value, overridden if we find a working one on the system 54 tap2subunit = "PYTHONPATH=%s/lib/subunit/python:%s/lib/testtools %s %s/lib/subunit/filters/tap2subunit" % (srcdir(), srcdir(), python, srcdir()) 50 tap2subunit = python + " " + os.path.join(srcdir(), "selftest", "tap2subunit") 55 51 56 sub = subprocess.Popen("tap2subunit 2> /dev/null", stdout=subprocess.PIPE, stdin=subprocess.PIPE, shell=True)57 sub.communicate("")58 59 if sub.returncode == 0:60 cmd = "echo -ne \"1..1\nok 1 # skip doesn't seem to work yet\n\" | tap2subunit 2> /dev/null | grep skip"61 sub = subprocess.Popen(cmd, stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)62 if sub.returncode == 0:63 tap2subunit = "tap2subunit"64 52 65 53 def valgrindify(cmdline): … … 71 59 72 60 73 def plantestsuite(name, env, cmdline , allow_empty_output=False):61 def plantestsuite(name, env, cmdline): 74 62 """Plan a test suite. 75 63 … … 83 71 if isinstance(cmdline, list): 84 72 cmdline = " ".join(cmdline) 85 filter_subunit_args = []86 if not allow_empty_output:87 filter_subunit_args.append("--fail-on-empty")88 73 if "$LISTOPT" in cmdline: 89 filter_subunit_args.append("$LISTOPT") 90 print "%s 2>&1 | %s/selftest/filter-subunit %s --prefix=\"%s.\"" % (cmdline, 91 srcdir(), 92 " ".join(filter_subunit_args), 93 name) 94 if allow_empty_output: 95 print "WARNING: allowing empty subunit output from %s" % name 74 raise AssertionError("test %s supports --list, but not --load-list" % name) 75 print cmdline + " 2>&1 " + " | " + add_prefix(name, env) 96 76 97 77 98 def add_prefix(prefix, support_list=False):78 def add_prefix(prefix, env, support_list=False): 99 79 if support_list: 100 80 listopt = "$LISTOPT " 101 81 else: 102 82 listopt = "" 103 return "%s/selftest/filter-subunit %s--fail-on-empty --prefix=\"%s.\" " % (srcdir(), listopt, prefix)83 return "%s/selftest/filter-subunit %s--fail-on-empty --prefix=\"%s.\" --suffix=\"(%s)\"" % (srcdir(), listopt, prefix, env) 104 84 105 85 … … 115 95 cmdline = " ".join(cmdline) 116 96 support_list = ("$LISTOPT" in cmdline) 117 print "%s $LOADLIST 2>&1 | %s" % (cmdline, add_prefix(name, support_list)) 118 119 120 def plantestsuite_idlist(name, env, cmdline): 121 print "-- TEST-IDLIST --" 122 print name 123 print env 124 if isinstance(cmdline, list): 125 cmdline = " ".join(cmdline) 126 print cmdline 97 if not "$LISTOPT" in cmdline: 98 raise AssertionError("loadlist test %s does not support not --list" % name) 99 if not "$LOADLIST" in cmdline: 100 raise AssertionError("loadlist test %s does not support --load-list" % name) 101 print ("%s | %s" % (cmdline.replace("$LOADLIST", ""), add_prefix(name, env, support_list))).replace("$LISTOPT", "--list") 102 print cmdline.replace("$LISTOPT", "") + " 2>&1 " + " | " + add_prefix(name, env, False) 127 103 128 104 … … 134 110 """ 135 111 # FIXME: Report this using subunit, but re-adjust the testsuite count somehow 136 print "skipping %s (%s)" % (name, reason)112 print >>sys.stderr, "skipping %s (%s)" % (name, reason) 137 113 138 114 … … 149 125 150 126 151 def planpythontestsuite(env, module): 152 if has_system_subunit_run: 153 plantestsuite_idlist(module, env, [python, "-m", "subunit.run", "$LISTOPT", module]) 154 else: 155 plantestsuite_idlist(module, env, "PYTHONPATH=$PYTHONPATH:%s/lib/subunit/python:%s/lib/testtools %s -m subunit.run $LISTOPT %s" % (srcdir(), srcdir(), python, module)) 127 def planpythontestsuite(env, module, name=None, extra_path=[]): 128 if name is None: 129 name = module 130 pypath = list(extra_path) 131 args = [python, "-m", "samba.subunit.run", "$LISTOPT", "$LOADLIST", module] 132 if pypath: 133 args.insert(0, "PYTHONPATH=%s" % ":".join(["$PYTHONPATH"] + pypath)) 134 plantestsuite_loadlist(name, env, args) 156 135 157 136 137 def get_env_torture_options(): 138 ret = [] 139 if not os.getenv("SELFTEST_VERBOSE"): 140 ret.append("--option=torture:progress=no") 141 if os.getenv("SELFTEST_QUICK"): 142 ret.append("--option=torture:quick=yes") 143 return ret 144 145 146 samba4srcdir = source4dir() 147 samba3srcdir = source3dir() 148 bbdir = os.path.join(srcdir(), "testprogs/blackbox") 149 configuration = "--configfile=$SMB_CONF_PATH" 150 151 smbtorture4 = binpath("smbtorture") 152 smbtorture4_testsuite_list = subprocess.Popen([smbtorture4, "--list-suites"], stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate("")[0].splitlines() 153 154 smbtorture4_options = [ 155 configuration, 156 "--option=\'fss:sequence timeout=1\'", 157 "--maximum-runtime=$SELFTEST_MAXTIME", 158 "--basedir=$SELFTEST_TMPDIR", 159 "--format=subunit" 160 ] + get_env_torture_options() 161 162 163 def plansmbtorture4testsuite(name, env, options, target, modname=None): 164 if modname is None: 165 modname = "samba4.%s" % name 166 if isinstance(options, list): 167 options = " ".join(options) 168 options = " ".join(smbtorture4_options + ["--target=%s" % target]) + " " + options 169 cmdline = "%s $LISTOPT $LOADLIST %s %s" % (valgrindify(smbtorture4), options, name) 170 plantestsuite_loadlist(modname, env, cmdline) 171 172 173 def smbtorture4_testsuites(prefix): 174 return filter(lambda x: x.startswith(prefix), smbtorture4_testsuite_list) 175 176 177 smbclient3 = binpath('smbclient') 178 smbtorture3 = binpath('smbtorture3') 179 ntlm_auth3 = binpath('ntlm_auth') 180 net = binpath('net') 181 scriptdir = os.path.join(srcdir(), "script/tests") 182 183 wbinfo = binpath('wbinfo') 184 dbwrap_tool = binpath('dbwrap_tool') 185 vfstest = binpath('vfstest') 186 smbcquotas = binpath('smbcquotas') 187 smbget = binpath('smbget')
Note:
See TracChangeset
for help on using the changeset viewer.