Skip to content

Commit

Permalink
Rebuild globals() table in child processes on Windows to minimize cha…
Browse files Browse the repository at this point in the history
…nges
  • Loading branch information
timwoj committed Jan 4, 2023
1 parent b703e50 commit 39e7e54
Showing 1 changed file with 25 additions and 29 deletions.
54 changes: 25 additions & 29 deletions btest
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,6 @@ class Test(object):
self.log = None
self.measure_time = False
self.mgr = None
self.mgr_data = None
self.monitor = None
self.monitor_quit = None
self.name = None
Expand Down Expand Up @@ -1049,15 +1048,17 @@ class Test(object):
self.mgr = mgr
mgr.testStart(self)

# Pull the proxied data from the manager and save it since it's going to be used
# more later
self.mgr_data = mgr_data
# Globals get lost moving from the parent to the child on Windows, so we need to use
# the data proxied from the manager to rebuild the dict of globals before continuing.
if sys.platform == 'win32':
for (global_key, global_value) in mgr_data.items():
globals()[global_key] = global_value

self.tmpdir = normalize_path_join(self.mgr_data["TmpDir"], self.name)
self.tmpdir = normalize_path_join(TmpDir, self.name)
self.diag = normalize_path_join(self.tmpdir, ".diag")
self.verbose = normalize_path_join(self.tmpdir, ".verbose")
self.baselines = []
for d in self.mgr_data['BaselineDirs']:
for d in BaselineDirs:
self.baselines.append(normalize_path_join(d, self.name))
self.diagmsgs = []
self.utime = -1
Expand Down Expand Up @@ -1116,7 +1117,7 @@ class Test(object):

if not success:
self.mgr.testSkipped(self)
if not self.mgr_data["Options"].tmps:
if not Options.tmps:
self.rmTmp(with_close=True)
self.finish()
return
Expand All @@ -1140,20 +1141,16 @@ class Test(object):

seq = CmdSeq()

if self.mgr_data['Initializer']:
seq.cmds.append(
CmdLine("%s %s" % (self.mgr_data["Initializer"], self.name), True, 1,
"<Initializer>"))
if Initializer:
seq.cmds.append(CmdLine("%s %s" % (Initializer, self.name), True, 1, "<Initializer>"))

seq.cmds += self.cmdseqs

if self.mgr_data['Finalizer']:
seq.cmds.append(
CmdLine("%s %s" % (self.mgr_data["Finalizer"], self.name), True, 1, "<Finalizer>"))
if Finalizer:
seq.cmds.append(CmdLine("%s %s" % (Finalizer, self.name), True, 1, "<Finalizer>"))

if self.mgr_data['Teardown']:
seq.teardown = CmdLine("%s %s" % (self.mgr_data["Teardown"], self.name), True, 1,
"<Teardown>")
if Teardown:
seq.teardown = CmdLine("%s %s" % (Teardown, self.name), True, 1, "<Teardown>")

failures = 0
rc = 0
Expand All @@ -1167,7 +1164,7 @@ class Test(object):
# Run commands only when successful so far, if the most recent
# command asked to continue despite error (code 100), or in Sphinx
# mode.
if failures == 0 or rc == 100 or self.mgr_data['Options'].sphinx:
if failures == 0 or rc == 100 or Options.sphinx:
skip_part = -1

for cmd in seq.cmds:
Expand All @@ -1194,7 +1191,7 @@ class Test(object):
if not success:
failures += 1

if self.mgr_data['Options'].sphinx:
if Options.sphinx:
# We still execute the remaining commands and
# raise a failure for each one that fails.
self.mgr.testFailed(self)
Expand Down Expand Up @@ -1225,7 +1222,7 @@ class Test(object):
rc = teardown_rc
failures += 1

if self.mgr_data["Options"].sphinx or failures == 1:
if Options.sphinx or failures == 1:
self.mgr.testFailed(self)

return need_teardown
Expand Down Expand Up @@ -1253,7 +1250,7 @@ class Test(object):
self.utime_perc = (100.0 * (self.utime - self.utime_base) / self.utime_base)
self.utime_exceeded = (abs(self.utime_perc) > float(delta))

if self.utime_exceeded and not self.mgr_data["Options"].update_times:
if self.utime_exceeded and not Options.update_times:
self.diagmsgs += [
"'%s' exceeded permitted execution time deviation%s" %
(self.name, self.timePostfix())
Expand All @@ -1263,7 +1260,7 @@ class Test(object):
else:
self.mgr.testSucceeded(self)

if not self.mgr_data['Options'].tmps and self.reruns == 0:
if not Options.tmps and self.reruns == 0:
self.rmTmp(with_close=True)

self.finish()
Expand Down Expand Up @@ -1297,7 +1294,7 @@ class Test(object):
# Apply alternative if requested.
if apply_alternative:

alt = self.mgr_data['Alternatives'][apply_alternative]
alt = Alternatives[apply_alternative]

try:
(path, executable) = os.path.split(cmdline.split()[0])
Expand Down Expand Up @@ -1334,9 +1331,9 @@ class Test(object):
# Replace special names.

if localfile:
cmdline = self.mgr_data['re_input'].sub(localfile, cmdline)
cmdline = re_input.sub(localfile, cmdline)

cmdline = self.mgr_data['re_dir'].sub(self.dir, cmdline)
cmdline = re_dir.sub(self.dir, cmdline)

print("%s (expect %s)" % (cmdline, ("failure", "success")[cmd.expect_success]),
file=self.log)
Expand All @@ -1347,8 +1344,7 @@ class Test(object):
env.update(addl_envs)

env = self.prepareEnv(cmd, env)
measure_time = self.measure_time and (self.mgr_data['Options'].update_times
or self.utime_base >= 0)
measure_time = self.measure_time and (Options.update_times or self.utime_base >= 0)

(success, rc, utime) = runTestCommandLine(cmdline,
measure_time,
Expand Down Expand Up @@ -1399,11 +1395,11 @@ class Test(object):

env["TEST_BASELINE"] = os.pathsep.join(self.baselines)
env["TEST_DIAGNOSTICS"] = self.diag
env["TEST_MODE"] = self.mgr_data['Options'].mode.upper()
env["TEST_MODE"] = Options.mode.upper()
env["TEST_NAME"] = self.name
env["TEST_VERBOSE"] = self.verbose
env["TEST_PART"] = str(cmd.part)
env["TEST_BASE"] = self.mgr_data['TestBase']
env["TEST_BASE"] = TestBase

for (key, val) in addl.items():
# Convert val to string since otherwise os.environ (and our clone)
Expand Down

0 comments on commit 39e7e54

Please sign in to comment.