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