未验证 提交 9c09db67 编写于 作者: X Xu Han 提交者: GitHub

Merge pull request #1332 from luckyh/qemu-python3-file-cmp

[qemu] Python 3: Update file() and cmp()
......@@ -7,6 +7,13 @@ from avocado.utils import process
from virttest import error_context
try:
cmp
except NameError:
def cmp(x, y):
return (x > y) - (x < y)
@error_context.context_aware
def run(test, params, env):
"""
......
......@@ -172,7 +172,8 @@ def run(test, params, env):
finally:
netperf_server.stop()
file(os.path.join(test.debugdir, "udp_results"), "w").write(msg)
with open(os.path.join(test.debugdir, "udp_results"), "w") as result_file:
result_file.write(msg)
failratio = float(params.get("failratio", 0.3))
error_context.context("Compare UDP performance.", logging.info)
for i in range(len(throughput) - 1):
......
......@@ -7,6 +7,13 @@ from virttest import env_process
from virttest import error_context
try:
cmp
except NameError:
def cmp(x, y):
return (x > y) - (x < y)
@env_process.context_aware
def run(test, params, env):
"""
......
......@@ -38,9 +38,8 @@ def run(test, params, env):
if float(tv) < float(lasttv):
p_tv = "time value = " + tv + "\n"
p_lasttv = "last time value = " + lasttv + "\n"
time_log = file(host_path, 'a')
time_log.write("time went backwards:\n" + p_tv + p_lasttv)
time_log.close()
with open(host_path, 'a') as time_log:
time_log.write("time went backwards:\n" + p_tv + p_lasttv)
lasttv = tv
time.sleep(0.1)
......@@ -86,12 +85,11 @@ def run(test, params, env):
log_dir = os.path.join(test.outputdir,
"timedrift-monotonicity-result.txt")
shutil.copyfile(host_path, log_dir)
myfile = file(host_path, 'r')
for line in myfile:
if "time went backwards" in line:
myfile.close()
test.fail("Failed Time Monotonicity testing, "
"Please check log %s" % host_path)
with open(host_path, 'r') as myfile:
for line in myfile:
if "time went backwards" in line:
test.fail("Failed Time Monotonicity testing, "
"Please check log %s" % host_path)
finally:
session1.close()
# remove flags add for this test.
......
......@@ -75,7 +75,8 @@ def run(test, params, env):
logging.warn("trace-cmd could not finish after 120s.")
trace_job = None
process.system(trace_report_cmd, shell=True)
report_txt = file(report_file).read()
with open(report_file) as report_f:
report_txt = report_f.read()
txt = "Check whether the trace.txt includes the error log."
error_context.context(txt, logging.info)
if re.findall(re_trace, report_txt, re.S):
......
......@@ -39,7 +39,8 @@ def run(test, params, env):
def receive_data(test, session, serial_receive_cmd, data_file):
output = session.cmd_output(serial_receive_cmd, timeout=30)
ori_data = file(data_file, "r").read()
with open(data_file, "r") as data_file:
ori_data = data_file.read()
if ori_data.strip() != output.strip():
err = "Data lost during transfer. Origin data is:\n%s" % ori_data
err += "Guest receive data:\n%s" % output
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册