1 # Copyright (c) 2013 The Chromium OS Authors. All rights reserved. 2 # Use of this source code is governed by a BSD-style license that can be 3 # found in the LICENSE file. 4 5 from autotest_lib.client.common_lib import error 6 7 8 def get_datetime_float(host): 9 """ 10 Returns host's system time in seconds since epoch. 11 12 @param host: an Autotest host object. 13 @returns a float, timestamp since epoch in <seconds>.<nanoseconds>. 14 15 @raises TestError: if error reading datetime or converting its value 16 from string to float. 17 """ 18 r = host.run('date +%s.%N') 19 if r.exit_status > 0: 20 err = ('Error reading datetime from capturer (%r): %r' % 21 (r.exit_status, r.stderr)) 22 raise error.TestError(err) 23 try: 24 return float(r.stdout) 25 except ValueError as e: 26 raise error.TestError('Error converting datetime string: %r', e) 27