Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def check_exitcode_extern(self, result, exitcode, msg=None):
exitcode = util.ProcessExitCode.from_raw(exitcode)
if exitcode.value is not None:
self.assertEqual(int(result["returnvalue"]), exitcode.value, msg)
else:
self.assertEqual(int(result["exitsignal"]), exitcode.signal, msg)
logging.warning(
"CPU throttled itself during benchmarking due to overheating. "
"Benchmark results are unreliable!"
)
if swap_check.has_swapped():
logging.warning(
"System has swapped during benchmarking. "
"Benchmark results are unreliable!"
)
if error_filename is not None:
_reduce_file_size_if_necessary(error_filename, max_output_size)
_reduce_file_size_if_necessary(output_filename, max_output_size)
result["exitcode"] = util.ProcessExitCode.from_raw(returnvalue)
if energy:
if packages is True:
result["cpuenergy"] = energy
else:
result["cpuenergy"] = {
pkg: energy[pkg] for pkg in energy if pkg in packages
}
if self._termination_reason:
result["terminationreason"] = self._termination_reason
elif memlimit and "memory" in result and result["memory"] >= memlimit:
# The kernel does not always issue OOM notifications and thus the OOMHandler
# does not always run even in case of OOM. We detect this there and report OOM.
result["terminationreason"] = "memory"
return result
raise e
if not received:
# Typically this means the child exited prematurely because an error
# occurred, and check_child_exitcode() will handle this.
# We close the pipe first, otherwise child could hang infinitely.
os.close(from_grandchild_copy)
os.close(to_grandchild_copy)
check_child_exit_code()
assert False, "Child process terminated cleanly without sending result"
exitcode, ru_child = pickle.loads(received)
base_path = "/proc/{}/root".format(child_pid)
parent_cleanup = parent_cleanup_fn(
parent_setup, util.ProcessExitCode.from_raw(exitcode), base_path
)
if result_files_patterns:
# As long as the child process exists
# we can access the container file system here
self._transfer_output_files(
base_path + temp_dir, cwd, output_dir, result_files_patterns
)
os.close(from_grandchild_copy)
os.write(to_grandchild_copy, MARKER_PARENT_POST_RUN_COMPLETED)
os.close(to_grandchild_copy) # signal child that it can terminate
check_child_exit_code()
return exitcode, ru_child, parent_cleanup
if "exitcode" in result_values:
old = result_values["exitcode"]
assert (
old == new
), "Inconsistent exit codes {} and {} from VerifierCloud".format(old, new)
else:
result_values["exitcode"] = new
for key, value in values:
value = value.strip()
if key in ["cputime", "walltime"]:
result_values[key] = parse_time_value(value)
elif key == "memory":
result_values["memory"] = int(value.strip("B"))
elif key == "exitcode":
set_exitcode(benchexec.util.ProcessExitCode.from_raw(int(value)))
elif key == "returnvalue":
set_exitcode(benchexec.util.ProcessExitCode.create(value=int(value)))
elif key == "exitsignal":
set_exitcode(benchexec.util.ProcessExitCode.create(signal=int(value)))
elif (
key in ["host", "terminationreason", "cpuCores", "memoryNodes", "starttime"]
or key.startswith("blkio-")
or key.startswith("cpuenergy")
or key.startswith("energy-")
or key.startswith("cputime-cpu")
):
result_values[key] = value
elif key not in ["command", "timeLimit", "coreLimit", "memoryLimit"]:
result_values["vcloud-" + key] = value
return result_values
def check_child_exit_code():
"""Check if the child process terminated cleanly
and raise an error otherwise."""
child_exitcode, unused_child_rusage = self._wait_for_process(
child_pid, args[0]
)
child_exitcode = util.ProcessExitCode.from_raw(child_exitcode)
logging.debug(
"Parent: child process of RunExecutor with PID %d"
" terminated with %s.",
child_pid,
child_exitcode,
)
if child_exitcode:
if child_exitcode.value:
if child_exitcode.value == CHILD_OSERROR:
# This was an OSError in the child,
# details were already logged
raise BenchExecException(
"execution in container failed, check log for details"
)
elif child_exitcode.value == CHILD_UNKNOWN_ERROR:
if "exitcode" in result_values:
old = result_values["exitcode"]
assert (
old == new
), "Inconsistent exit codes {} and {} from VerifierCloud".format(old, new)
else:
result_values["exitcode"] = new
for key, value in values:
value = value.strip()
if key in ["cputime", "walltime"]:
result_values[key] = parse_time_value(value)
elif key == "memory":
result_values["memory"] = int(value.strip("B"))
elif key == "exitcode":
set_exitcode(benchexec.util.ProcessExitCode.from_raw(int(value)))
elif key == "returnvalue":
set_exitcode(benchexec.util.ProcessExitCode.create(value=int(value)))
elif key == "exitsignal":
set_exitcode(benchexec.util.ProcessExitCode.create(signal=int(value)))
elif (
key in ["host", "terminationreason", "cpuCores", "memoryNodes", "starttime"]
or key.startswith("blkio-")
or key.startswith("cpuenergy")
or key.startswith("energy-")
or key.startswith("cputime-cpu")
):
result_values[key] = value
elif key not in ["command", "timeLimit", "coreLimit", "memoryLimit"]:
result_values["vcloud-" + key] = value
return result_values
def wait_and_get_result():
exitcode, ru_child = self._wait_for_process(p.pid, args[0])
parent_cleanup = parent_cleanup_fn(
parent_setup, util.ProcessExitCode.from_raw(exitcode), ""
)
return exitcode, ru_child, parent_cleanup