173471bf0Spatrickimport os 273471bf0Spatrick 373471bf0Spatrick 473471bf0Spatrickdef read_test_times(suite): 573471bf0Spatrick test_times = {} 673471bf0Spatrick test_times_file = os.path.join(suite.exec_root, '.lit_test_times.txt') 773471bf0Spatrick if not os.path.exists(test_times_file): 873471bf0Spatrick test_times_file = os.path.join( 973471bf0Spatrick suite.source_root, '.lit_test_times.txt') 1073471bf0Spatrick if os.path.exists(test_times_file): 1173471bf0Spatrick with open(test_times_file, 'r') as time_file: 1273471bf0Spatrick for line in time_file: 1373471bf0Spatrick time, path = line.split(maxsplit=1) 1473471bf0Spatrick test_times[path.strip('\n')] = float(time) 1573471bf0Spatrick return test_times 1673471bf0Spatrick 1773471bf0Spatrick 1873471bf0Spatrickdef record_test_times(tests, lit_config): 1973471bf0Spatrick times_by_suite = {} 2073471bf0Spatrick for t in tests: 2173471bf0Spatrick assert t.suite.test_times is None 2273471bf0Spatrick if not t.result.elapsed: 2373471bf0Spatrick continue 2473471bf0Spatrick if not t.suite.exec_root in times_by_suite: 2573471bf0Spatrick times_by_suite[t.suite.exec_root] = read_test_times(t.suite) 2673471bf0Spatrick time = -t.result.elapsed if t.isFailure() else t.result.elapsed 2773471bf0Spatrick # The "path" here is only used as a key into a dictionary. It is never 2873471bf0Spatrick # used as an actual path to a filesystem API, therefore we use '/' as 2973471bf0Spatrick # the canonical separator so that Unix and Windows machines can share 3073471bf0Spatrick # timing data. 31*d415bd75Srobert times_by_suite[t.suite.exec_root]['/'.join(t.path_in_suite)] = time 3273471bf0Spatrick 3373471bf0Spatrick for s, value in times_by_suite.items(): 3473471bf0Spatrick try: 3573471bf0Spatrick path = os.path.join(s, '.lit_test_times.txt') 3673471bf0Spatrick with open(path, 'w') as time_file: 3773471bf0Spatrick for name, time in value.items(): 3873471bf0Spatrick time_file.write(("%e" % time) + ' ' + name + '\n') 3973471bf0Spatrick except: 4073471bf0Spatrick lit_config.warning('Could not save test time: ' + path) 4173471bf0Spatrick continue 42