blob: 181039f76179aaf21d3ffbccca01c15549bfe77d [file] [log] [blame]
Lalit Magantidf500092020-07-16 23:56:24 +01001#!/usr/bin/env python3
Lalit Maganti21160e82018-10-16 09:40:29 +01002# Copyright (C) 2018 The Android Open Source Project
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
Florian Mayercdc44b32020-06-29 17:18:29 +010016from __future__ import absolute_import
17from __future__ import division
18from __future__ import print_function
19
Lalit Maganti21160e82018-10-16 09:40:29 +010020import argparse
Lalit Maganti467a8ef2019-12-05 15:54:20 +000021import datetime
Lalit Maganti46a0a532019-07-15 15:09:22 +010022import json
Lalit Maganti21160e82018-10-16 09:40:29 +010023import os
Lalit Maganti4be82e12019-12-05 15:33:09 +000024import re
Primiano Tucci521d6202022-07-29 11:41:25 +010025import signal
Lalit Maganti21160e82018-10-16 09:40:29 +010026import sys
Lalit Maganti21160e82018-10-16 09:40:29 +010027
Lalit Magantida1c1d02019-05-08 11:55:50 +010028ROOT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
Anna Mayzner6e723ce2023-01-09 17:03:13 +000029sys.path.append(os.path.join(ROOT_DIR))
30
Anna Mayznera0d461d2023-01-13 16:45:45 +000031from python.generators.diff_tests.testing import TestType
Anna Mayznerf60f53d2023-01-13 15:46:00 +000032from python.generators.diff_tests.utils import ctrl_c_handler
Anna Mayzner6988df82023-01-23 10:37:16 +000033from python.generators.diff_tests.runner import DiffTestsRunner
Primiano Tucci521d6202022-07-29 11:41:25 +010034
35
Lalit Maganti21160e82018-10-16 09:40:29 +010036def main():
Primiano Tucci521d6202022-07-29 11:41:25 +010037 signal.signal(signal.SIGINT, ctrl_c_handler)
Lalit Maganti21160e82018-10-16 09:40:29 +010038 parser = argparse.ArgumentParser()
Lalit Maganti0ec47c62020-02-12 16:24:08 +000039 parser.add_argument('--test-type', type=str, default='all')
Lalit Magantida1c1d02019-05-08 11:55:50 +010040 parser.add_argument('--trace-descriptor', type=str)
Rasika Navarange63981132023-07-05 11:26:50 +000041 parser.add_argument('--metrics-descriptor', nargs='+', type=str)
42 parser.add_argument('--chrome-track-event-descriptor', type=str, default=None)
43 parser.add_argument('--test-extensions', type=str, default=None)
Kean Mariottib4a6d112024-04-11 13:57:22 +000044 parser.add_argument('--winscope-extensions', type=str, default=None)
Lalit Maganti75869e62019-07-12 16:55:38 +010045 parser.add_argument('--perf-file', type=str)
Primiano Tucci834fdc72019-10-04 11:33:44 +010046 parser.add_argument(
Rasika Navarange63981132023-07-05 11:26:50 +000047 '--override-sql-module', type=str, action='append', default=[])
48 parser.add_argument('--test-dir', type=str, default=ROOT_DIR)
49 parser.add_argument(
Anna Mayzner73148f72023-01-24 16:32:16 +000050 '--name-filter',
Lalit Maganti4be82e12019-12-05 15:33:09 +000051 default='.*',
52 type=str,
Anna Mayzner73148f72023-01-24 16:32:16 +000053 help='Filter the name of the tests to run (regex syntax)')
Lalit Maganti4be82e12019-12-05 15:33:09 +000054 parser.add_argument(
Eric Secklerfbd9aed2020-03-10 18:07:38 +000055 '--keep-input',
56 action='store_true',
57 help='Save the (generated) input pb file for debugging')
58 parser.add_argument(
Dan Elphicke603bf72020-12-21 16:01:06 +000059 '--rebase',
60 action='store_true',
61 help='Update the expected output file with the actual result')
62 parser.add_argument(
Anna Mayznerceaa8b82024-11-06 13:35:23 +000063 '--quiet', action='store_true', help='Only print if the test failed.')
64 parser.add_argument(
Anna Mayzner364c0c92022-07-08 17:51:05 +000065 '--no-colors', action='store_true', help='Print without coloring')
66 parser.add_argument(
Primiano Tucci834fdc72019-10-04 11:33:44 +010067 'trace_processor', type=str, help='location of trace processor binary')
Lalit Maganti21160e82018-10-16 09:40:29 +010068 args = parser.parse_args()
69
Rasika Navarange63981132023-07-05 11:26:50 +000070 out_path = os.path.dirname(args.trace_processor)
71 if args.chrome_track_event_descriptor is None:
72 args.chrome_track_event_descriptor = os.path.join(
73 out_path, 'gen', 'protos', 'third_party', 'chromium',
74 'chrome_track_event.descriptor')
75 if args.test_extensions is None:
76 args.test_extensions = os.path.join(out_path, 'gen', 'protos', 'perfetto',
77 'trace', 'test_extensions.descriptor')
Kean Mariottib4a6d112024-04-11 13:57:22 +000078 if args.winscope_extensions is None:
Lalit Magantibdd33a22024-05-29 17:58:14 +010079 args.winscope_extensions = os.path.join(out_path, 'gen', 'protos',
80 'perfetto', 'trace', 'android',
81 'winscope.descriptor')
Rasika Navarange63981132023-07-05 11:26:50 +000082
Anna Mayzner73148f72023-01-24 16:32:16 +000083 test_runner = DiffTestsRunner(args.name_filter, args.trace_processor,
Rasika Navarange63981132023-07-05 11:26:50 +000084 args.trace_descriptor, args.no_colors,
Anna Mayznerceaa8b82024-11-06 13:35:23 +000085 args.override_sql_module, args.test_dir,
86 args.quiet)
Anna Mayznerf60f53d2023-01-13 15:46:00 +000087 sys.stderr.write(f"[==========] Running {len(test_runner.tests)} tests.\n")
Lalit Maganti0ec47c62020-02-12 16:24:08 +000088
Rasika Navarange63981132023-07-05 11:26:50 +000089 results = test_runner.run_all_tests(args.metrics_descriptor,
Lalit Magantibdd33a22024-05-29 17:58:14 +010090 args.chrome_track_event_descriptor,
91 args.test_extensions,
92 args.winscope_extensions, args.keep_input,
93 args.rebase)
Anna Mayznerf60f53d2023-01-13 15:46:00 +000094 sys.stderr.write(results.str(args.no_colors, len(test_runner.tests)))
Anna Mayzner364c0c92022-07-08 17:51:05 +000095
Dan Elphicke603bf72020-12-21 16:01:06 +000096 if args.rebase:
Anna Mayznerf60f53d2023-01-13 15:46:00 +000097 sys.stderr.write(results.rebase_str())
Lalit Maganti04a450a2019-07-03 16:04:19 +010098
Anna Mayznerf60f53d2023-01-13 15:46:00 +000099 if len(results.test_failures) > 0:
Lalit Maganti21160e82018-10-16 09:40:29 +0100100 return 1
101
Ryan Savitskia6aecee2022-10-03 12:36:30 +0100102 if args.perf_file:
103 test_dir = os.path.join(ROOT_DIR, 'test')
104 trace_processor_dir = os.path.join(test_dir, 'trace_processor')
105
106 metrics = []
107 sorted_data = sorted(
Anna Mayzner95b5b752023-01-19 13:32:44 +0000108 results.perf_data, key=lambda x: (x.test.type.name, x.test.name))
Ryan Savitskia6aecee2022-10-03 12:36:30 +0100109 for perf_args in sorted_data:
Ryan Savitskia6aecee2022-10-03 12:36:30 +0100110 metrics.append({
111 'metric': 'tp_perf_test_ingest_time',
112 'value': float(perf_args.ingest_time_ns) / 1.0e9,
113 'unit': 's',
114 'tags': {
Anna Mayzner95b5b752023-01-19 13:32:44 +0000115 'test_name': perf_args.test.name,
116 'test_type': perf_args.test.type.name,
Ryan Savitskia6aecee2022-10-03 12:36:30 +0100117 },
118 'labels': {},
119 })
120 metrics.append({
121 'metric': 'perf_test_real_time',
122 'value': float(perf_args.real_time_ns) / 1.0e9,
123 'unit': 's',
124 'tags': {
Anna Mayzner95b5b752023-01-19 13:32:44 +0000125 'test_name': perf_args.test.name,
126 'test_type': perf_args.test.type.name,
Ryan Savitskia6aecee2022-10-03 12:36:30 +0100127 },
128 'labels': {},
129 })
130
131 output_data = {'metrics': metrics}
132 with open(args.perf_file, 'w+') as perf_file:
133 perf_file.write(json.dumps(output_data, indent=2))
134 return 0
135
Primiano Tucci834fdc72019-10-04 11:33:44 +0100136
Lalit Maganti21160e82018-10-16 09:40:29 +0100137if __name__ == '__main__':
138 sys.exit(main())