Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(120)

Side by Side Diff: client/tests/kvm/kvm_test_utils.py

Issue 3554003: Merge remote branch 'cros/upstream' into tempbranch3 (Closed) Base URL: http://git.chromium.org/git/autotest.git
Patch Set: Created 10 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « client/tests/kvm/deps/whql_submission_15.exe ('k') | client/tests/kvm/kvm_vm.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 """ 1 """
2 High-level KVM test utility functions. 2 High-level KVM test utility functions.
3 3
4 This module is meant to reduce code size by performing common test procedures. 4 This module is meant to reduce code size by performing common test procedures.
5 Generally, code here should look like test code. 5 Generally, code here should look like test code.
6 More specifically: 6 More specifically:
7 - Functions in this module should raise exceptions if things go wrong 7 - Functions in this module should raise exceptions if things go wrong
8 (unlike functions in kvm_utils.py and kvm_vm.py which report failure via 8 (unlike functions in kvm_utils.py and kvm_vm.py which report failure via
9 their returned values). 9 their returned values).
10 - Functions in this module may use logging.info(), in addition to 10 - Functions in this module may use logging.info(), in addition to
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 previous commands). 252 previous commands).
253 253
254 @param session: A shell session. 254 @param session: A shell session.
255 @param time_command: Command to issue to get the current guest time. 255 @param time_command: Command to issue to get the current guest time.
256 @param time_filter_re: Regex filter to apply on the output of 256 @param time_filter_re: Regex filter to apply on the output of
257 time_command in order to get the current time. 257 time_command in order to get the current time.
258 @param time_format: Format string to pass to time.strptime() with the 258 @param time_format: Format string to pass to time.strptime() with the
259 result of the regex filter. 259 result of the regex filter.
260 @return: A tuple containing the host time and guest time. 260 @return: A tuple containing the host time and guest time.
261 """ 261 """
262 host_time = time.time() 262 if len(re.findall("ntpdate|w32tm", time_command)) == 0:
263 session.sendline(time_command) 263 host_time = time.time()
264 (match, s) = session.read_up_to_prompt() 264 session.sendline(time_command)
265 if not match: 265 (match, s) = session.read_up_to_prompt()
266 raise error.TestError("Could not get guest time") 266 if not match:
267 raise error.TestError("Could not get guest time")
267 268
268 try: 269 try:
269 s = re.findall(time_filter_re, s)[0] 270 s = re.findall(time_filter_re, s)[0]
270 except IndexError: 271 except IndexError:
271 logging.debug("The time string from guest is:\n%s" % s) 272 logging.debug("The time string from guest is:\n%s" % s)
272 raise error.TestError("The time string from guest is unexpected.") 273 raise error.TestError("The time string from guest is unexpected.")
273 except Exception, e: 274 except Exception, e:
274 logging.debug("(time_filter_re, time_string): (%s, %s)" % 275 logging.debug("(time_filter_re, time_string): (%s, %s)" %
275 (time_filter_re, s)) 276 (time_filter_re, s))
276 raise e 277 raise e
277 278
278 guest_time = time.mktime(time.strptime(s, time_format)) 279 guest_time = time.mktime(time.strptime(s, time_format))
280 else:
281 s , o = session.get_command_status_output(time_command)
282 if s != 0:
283 raise error.TestError("Could not get guest time")
284 if re.match('ntpdate', time_command):
285 offset = re.findall('offset (.*) sec',o)[0]
286 host_main, host_mantissa = re.findall(time_filter_re, o)[0]
287 host_time = time.mktime(time.strptime(host_main, time_format)) \
288 + float("0.%s" % host_mantissa)
289 guest_time = host_time + float(offset)
290 else:
291 guest_time = re.findall(time_filter_re, o)[0]
292 offset = re.findall("o:(.*)s", o)[0]
293 if re.match('PM', guest_time):
294 hour = re.findall('\d+ (\d+):', guest_time)[0]
295 hour = str(int(hour) + 12)
296 guest_time = re.sub('\d+\s\d+:', "\d+\s%s:" % hour,
297 guest_time)[:-3]
298 else:
299 guest_time = guest_time[:-3]
300 guest_time = time.mktime(time.strptime(guest_time, time_format))
301 host_time = guest_time - float(offset)
302
279 return (host_time, guest_time) 303 return (host_time, guest_time)
280 304
281 305
282 def get_memory_info(lvms): 306 def get_memory_info(lvms):
283 """ 307 """
284 Get memory information from host and guests in format: 308 Get memory information from host and guests in format:
285 Host: memfree = XXXM; Guests memsh = {XXX,XXX,...} 309 Host: memfree = XXXM; Guests memsh = {XXX,XXX,...}
286 310
287 @params lvms: List of VM objects 311 @params lvms: List of VM objects
288 @return: String with memory info report 312 @return: String with memory info report
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
474 raise error.TestFail("Autotest control file run did not produce any " 498 raise error.TestFail("Autotest control file run did not produce any "
475 "recognizable results") 499 "recognizable results")
476 if bad_results: 500 if bad_results:
477 if len(bad_results) == 1: 501 if len(bad_results) == 1:
478 e_msg = ("Test %s failed during control file execution" % 502 e_msg = ("Test %s failed during control file execution" %
479 bad_results[0]) 503 bad_results[0])
480 else: 504 else:
481 e_msg = ("Tests %s failed during control file execution" % 505 e_msg = ("Tests %s failed during control file execution" %
482 " ".join(bad_results)) 506 " ".join(bad_results))
483 raise error.TestFail(e_msg) 507 raise error.TestFail(e_msg)
OLDNEW
« no previous file with comments | « client/tests/kvm/deps/whql_submission_15.exe ('k') | client/tests/kvm/kvm_vm.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698