1#!/usr/bin/env python 2# Copyright 2019 The Chromium Authors 3# Use of this source code is governed by a BSD-style license that can be 4# found in the LICENSE file. 5 6import argparse 7import json 8import os 9import sys 10 11import common 12 13sys.path.append( 14 os.path.abspath( 15 os.path.join(os.path.dirname(__file__), os.path.pardir, os.path.pardir, 16 'content', 'test', 'gpu'))) 17 18# //content/test/gpu imports. 19import gather_power_measurement_results 20import gather_swarming_json_results 21 22 23class BuildBucketApiGpuUseCaseTests: 24 25 @classmethod 26 def GenerateTests(cls): 27 return [ 28 'TestGatherPowerMeasurementResultsFromLatestGreenBuild', 29 'TestGatherWebGL2TestTimesFromLatestGreenBuild', 30 ] 31 32 @staticmethod 33 def TestGatherPowerMeasurementResultsFromLatestGreenBuild(): 34 # Verify we can get power measurement test data from latest successful 35 # build, including the swarming bot that runs the test, and actual test 36 # results. 37 bot = 'Win10 FYI x64 Release (Intel)' 38 step = 'power_measurement_test' 39 build_id = gather_power_measurement_results.GetLatestGreenBuild(bot) 40 build_json = gather_power_measurement_results.GetJsonForBuildSteps( 41 bot, build_id) 42 if 'steps' not in build_json: 43 return '"steps" is missing from the build json' 44 stdout_url = gather_power_measurement_results.FindStepLogURL( 45 build_json['steps'], step, 'stdout') 46 if not stdout_url: 47 return 'Unable to find stdout from step %s' % step 48 results = {'number': build_id, 'tests': []} 49 gather_power_measurement_results.ProcessStepStdout(stdout_url, results) 50 if 'bot' not in results or not results['bot'].startswith('BUILD'): 51 return 'Failed to find bot name as BUILD*' 52 if not results['tests']: 53 return 'Failed to find power measurment test data' 54 return None 55 56 @staticmethod 57 def TestGatherWebGL2TestTimesFromLatestGreenBuild(): 58 # Verify we can get more than 2000 WebGL2 tests running time from the 59 # latest successful build. 60 extracted_times, _ = gather_swarming_json_results.GatherResults( 61 bot='Linux FYI Release (NVIDIA)', 62 build=None, # Use the latest green build 63 step='webgl2_conformance_validating_tests') 64 65 if 'times' not in extracted_times: 66 return '"times" is missing from the extracted dict' 67 num_of_tests = len(extracted_times['times']) 68 # From local run, there are 2700+ tests. This is sanity check that we 69 # get reasonable data. 70 if num_of_tests < 2000: 71 return 'expected 2000+ tests, got %d tests' % num_of_tests 72 return None 73 74 75def main(argv): 76 parser = argparse.ArgumentParser() 77 parser.add_argument('--isolated-script-test-output', type=str) 78 parser.add_argument('--isolated-script-test-chartjson-output', 79 type=str, 80 required=False) 81 parser.add_argument('--isolated-script-test-perf-output', 82 type=str, 83 required=False) 84 parser.add_argument('--isolated-script-test-filter', type=str, required=False) 85 86 args = parser.parse_args(argv) 87 88 # Run actual tests 89 failures = [] 90 retval = 1 91 for test_name in BuildBucketApiGpuUseCaseTests.GenerateTests(): 92 test = getattr(BuildBucketApiGpuUseCaseTests, test_name) 93 error_msg = test() 94 if error_msg is not None: 95 result = '%s: %s' % (test_name, error_msg) 96 print('FAIL: %s' % result) 97 failures.append(result) 98 99 if not failures: 100 print('PASS: test_buildbucket_api_gpu_use_cases ran successfully.') 101 retval = 0 102 103 if args.isolated_script_test_output: 104 with open(args.isolated_script_test_output, 'w') as json_file: 105 json.dump({ 106 'valid': True, 107 'failures': failures, 108 }, json_file) 109 110 return retval 111 112 113# This is not really a "script test" so does not need to manually add 114# any additional compile targets. 115def main_compile_targets(args): 116 json.dump([], args.output) 117 118 119if __name__ == '__main__': 120 # Conform minimally to the protocol defined by ScriptTest. 121 if 'compile_targets' in sys.argv: 122 funcs = { 123 'run': None, 124 'compile_targets': main_compile_targets, 125 } 126 sys.exit(common.run_script(sys.argv[1:], funcs)) 127 sys.exit(main(sys.argv[1:])) 128