Dennis Kempin | 22c7c4d | 2012-07-26 13:04:24 -0700 | [diff] [blame] | 1 | # Copyright (c) 2012 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 | # This module is the main module for the console interface. It takes care |
| 6 | # of parsing the command line arguments and formating the output |
Harry Cutts | 684f78c | 2020-04-09 18:37:05 -0700 | [diff] [blame] | 7 | from __future__ import absolute_import |
| 8 | from __future__ import division |
| 9 | from __future__ import print_function |
| 10 | |
Dennis Kempin | c2b5986 | 2013-02-20 14:02:25 -0800 | [diff] [blame] | 11 | from optparse import OptionParser |
Dennis Kempin | 1c7ffab | 2013-02-28 11:43:45 -0800 | [diff] [blame] | 12 | from subprocess import Popen, PIPE, STDOUT |
Dennis Kempin | c2b5986 | 2013-02-20 14:02:25 -0800 | [diff] [blame] | 13 | from tempfile import NamedTemporaryFile |
Dennis Kempin | 725ee5b | 2012-08-10 14:17:15 -0700 | [diff] [blame] | 14 | import json |
Dennis Kempin | d97cd72 | 2014-01-31 13:32:07 -0800 | [diff] [blame] | 15 | import logging |
Dennis Kempin | 725ee5b | 2012-08-10 14:17:15 -0700 | [diff] [blame] | 16 | import math |
Dennis Kempin | a44de38 | 2013-04-29 14:53:31 -0700 | [diff] [blame] | 17 | import multiprocessing |
Dennis Kempin | 725ee5b | 2012-08-10 14:17:15 -0700 | [diff] [blame] | 18 | import os |
Dennis Kempin | 725ee5b | 2012-08-10 14:17:15 -0700 | [diff] [blame] | 19 | import sys |
| 20 | |
Dennis Kempin | 5495f8a | 2013-06-13 13:42:03 -0700 | [diff] [blame] | 21 | from mtedit import MTEdit |
Dennis Kempin | 07e90e7 | 2014-04-15 13:54:39 -0700 | [diff] [blame] | 22 | from mtlib import Log, PlatformDatabase |
Dennis Kempin | c2b5986 | 2013-02-20 14:02:25 -0800 | [diff] [blame] | 23 | |
Dennis Kempin | 725ee5b | 2012-08-10 14:17:15 -0700 | [diff] [blame] | 24 | from table import Table |
Dennis Kempin | 22c7c4d | 2012-07-26 13:04:24 -0700 | [diff] [blame] | 25 | from test_case import TestCase |
Dennis Kempin | 31c0fbd | 2012-07-30 13:20:37 -0700 | [diff] [blame] | 26 | from test_factory import TestFactory |
Dennis Kempin | 93a7141 | 2014-01-10 13:39:37 -0800 | [diff] [blame] | 27 | from test_robot import RobotTestGenerator |
Andrew de los Reyes | 8063b66 | 2014-07-11 14:58:30 -0700 | [diff] [blame] | 28 | from test_collector import TestCollector |
Dennis Kempin | 963fb15 | 2013-01-11 15:40:19 -0800 | [diff] [blame] | 29 | from test_runner import ParallelTestRunner as TestRunner |
Dennis Kempin | 22c7c4d | 2012-07-26 13:04:24 -0700 | [diff] [blame] | 30 | |
Dennis Kempin | 1c7ffab | 2013-02-28 11:43:45 -0800 | [diff] [blame] | 31 | |
Dennis Kempin | 22c7c4d | 2012-07-26 13:04:24 -0700 | [diff] [blame] | 32 | _help_text = """\ |
Dennis Kempin | c2b5986 | 2013-02-20 14:02:25 -0800 | [diff] [blame] | 33 | Multitouch Regression Test Suite: |
| 34 | --------------------------------- |
Dennis Kempin | 22c7c4d | 2012-07-26 13:04:24 -0700 | [diff] [blame] | 35 | |
Dennis Kempin | c2b5986 | 2013-02-20 14:02:25 -0800 | [diff] [blame] | 36 | $ %prog [all|glob] |
| 37 | Executes tests. Either all of them or selected tests by providing a glob match |
| 38 | In order to test for regressions use: |
| 39 | $ %prog all --out filename |
| 40 | make a change |
| 41 | $ %prog all --ref filename |
| 42 | Which will display the changes in test results compared to before the change |
Dennis Kempin | 22c7c4d | 2012-07-26 13:04:24 -0700 | [diff] [blame] | 43 | |
Dennis Kempin | c2b5986 | 2013-02-20 14:02:25 -0800 | [diff] [blame] | 44 | $ %prog testname -v %info% |
| 45 | Run test and display information. %info% can be: |
| 46 | - a or activity: to view the touchpad activity in mtedit |
| 47 | - g or gestures: to view the generated gestures |
| 48 | - al or activity-log: to view the generated activity log |
| 49 | - gl or gestures-log: to view the generated gestures log |
| 50 | - el or evdev-log: to view the generated evdev log |
| 51 | |
| 52 | $ %prog test_name -c %source% |
| 53 | Create a new test case from %source%. Source can be: |
| 54 | - A feedback URL |
| 55 | - A device IP |
| 56 | - The path to an activity log file |
| 57 | When using a file name test.log, %prog will look at test.log.evdev |
| 58 | for the evdev log file. You can optionally supply -e to override this path. |
| 59 | %prog will display an URL where you can trim the log file, the trimmed |
| 60 | log file will then be used to create the new test case. Specify --no-edit in |
| 61 | case you do not want to use the original files without trimming. |
Dennis Kempin | 22c7c4d | 2012-07-26 13:04:24 -0700 | [diff] [blame] | 62 | |
Dennis Kempin | 462c875 | 2013-04-04 16:01:54 -0700 | [diff] [blame] | 63 | $ %prog test_name --gdb |
| 64 | Run the test using gdb for debugging the gestures library |
| 65 | |
Dennis Kempin | 22c7c4d | 2012-07-26 13:04:24 -0700 | [diff] [blame] | 66 | General Info: |
| 67 | ------------- |
| 68 | testname arguments: |
| 69 | Tests are always names as [platform]/[name of test case]. You can find the tests |
| 70 | available in the tests folder. |
| 71 | For example: lumpy/scroll_test |
| 72 | |
| 73 | Tests Folder: |
| 74 | The tests folder contains a folder for each platform and all the test cases. |
| 75 | Each test case is made up of 3 files: |
| 76 | [testcase].py which contains the validation script |
| 77 | [testcase].log which contains the input_event log |
| 78 | [testcase].props which contains user_defined properties passed to gestures lib. |
| 79 | |
| 80 | Platform folders: |
| 81 | To add a new platform you need to add a new folder to the Tests folder, and |
| 82 | generate a platform.dat file. This can be done using the evemu-describe tool |
| 83 | on the target platform: |
| 84 | |
| 85 | $ gmerge utouch-evemu |
| 86 | $ evemu-describe /path/to/device > platform.dat |
| 87 | """ |
| 88 | |
Dennis Kempin | 1c7ffab | 2013-02-28 11:43:45 -0800 | [diff] [blame] | 89 | |
| 90 | def Compile(): |
| 91 | if "SRC_DIR" not in os.environ: |
Harry Cutts | 684f78c | 2020-04-09 18:37:05 -0700 | [diff] [blame] | 92 | print("Requires SRC_DIR env-var. Re-run $ sudo make setup-in-place") |
Harry Cutts | 91c0d25 | 2020-04-28 17:10:02 -0700 | [diff] [blame] | 93 | sys.exit(1) |
Dennis Kempin | 1c7ffab | 2013-02-28 11:43:45 -0800 | [diff] [blame] | 94 | |
| 95 | dir = os.environ["SRC_DIR"] |
Harry Cutts | 684f78c | 2020-04-09 18:37:05 -0700 | [diff] [blame] | 96 | print("Recompiling gestures/libevdev/replay...") |
| 97 | print("SRC_DIR is %s" % dir) |
Dennis Kempin | a44de38 | 2013-04-29 14:53:31 -0700 | [diff] [blame] | 98 | process = Popen(["make", "-j", str(multiprocessing.cpu_count()), |
| 99 | "in-place"], cwd=dir, stdout=PIPE, stderr=STDOUT) |
Dennis Kempin | 1c7ffab | 2013-02-28 11:43:45 -0800 | [diff] [blame] | 100 | ret = process.wait() |
| 101 | if ret != 0: |
Harry Cutts | f023614 | 2020-07-22 15:37:02 -0700 | [diff] [blame^] | 102 | print(process.stdout.read().decode(errors='replace')) |
Harry Cutts | 91c0d25 | 2020-04-28 17:10:02 -0700 | [diff] [blame] | 103 | sys.exit(1) |
Dennis Kempin | 1c7ffab | 2013-02-28 11:43:45 -0800 | [diff] [blame] | 104 | |
| 105 | |
Harry Cutts | 4f5a88c | 2020-04-28 16:13:00 -0700 | [diff] [blame] | 106 | def RunAndCompare(glob, ref_file=None, autotest=False): |
Dennis Kempin | 1c7ffab | 2013-02-28 11:43:45 -0800 | [diff] [blame] | 107 | if not autotest: |
| 108 | Compile() |
Harry Cutts | 684f78c | 2020-04-09 18:37:05 -0700 | [diff] [blame] | 109 | print("Running tests...") |
Dennis Kempin | aad2bbb | 2013-06-18 13:48:35 -0700 | [diff] [blame] | 110 | runner = TestRunner(os.environ["TESTS_DIR"]) |
Dennis Kempin | 22c7c4d | 2012-07-26 13:04:24 -0700 | [diff] [blame] | 111 | results = runner.RunAll(glob) |
Dennis Kempin | 22c7c4d | 2012-07-26 13:04:24 -0700 | [diff] [blame] | 112 | |
Dennis Kempin | 97397c6 | 2013-02-28 10:49:59 -0800 | [diff] [blame] | 113 | # load reference |
| 114 | ref = {} |
Harry Cutts | 4f5a88c | 2020-04-28 16:13:00 -0700 | [diff] [blame] | 115 | deltas = {} |
Dennis Kempin | 97397c6 | 2013-02-28 10:49:59 -0800 | [diff] [blame] | 116 | if ref_file: |
| 117 | ref = json.load(open(ref_file)) |
Harry Cutts | 4f5a88c | 2020-04-28 16:13:00 -0700 | [diff] [blame] | 118 | for name, res in results.items(): |
| 119 | if name in ref: |
| 120 | deltas[name] = res["score"] - ref[name]["score"] |
| 121 | |
| 122 | return (results, ref, deltas) |
| 123 | |
| 124 | def MakeResultsTable(title, names_to_include, results, ref, deltas): |
| 125 | """Returns a table of test results.""" |
| 126 | def ResultStr(value): |
| 127 | if value["result"] == "success": |
| 128 | msg = "success" if value["score"] >= 0.5 else "bad" |
| 129 | return "%s (%.4f)" % (msg, value["score"]) |
| 130 | else: |
| 131 | return value["result"] |
| 132 | |
| 133 | def ColoredDelta(delta): |
| 134 | if math.fabs(delta) < 1e-10: |
| 135 | return "\x1b[0m%.4f\x1b[0m" % delta # default color |
| 136 | elif delta < 0: |
| 137 | return "\x1b[31m%+.4f\x1b[0m" % delta # red |
| 138 | else: |
| 139 | return "\x1b[32m%+.4f\x1b[0m" % delta # green |
| 140 | |
| 141 | table = Table() |
| 142 | table.title = title |
| 143 | table.header("Test", "reference score", "new score", "delta") |
| 144 | for name in sorted(names_to_include): |
| 145 | ref_score = ResultStr(ref[name]) if name in ref else "(new)" |
| 146 | delta_str = ColoredDelta(deltas[name]) if name in deltas else "" |
| 147 | table.row(name, ref_score, ResultStr(results[name]), delta_str) |
| 148 | |
| 149 | return table |
| 150 | |
| 151 | def ManualRun(glob, out_file=None, ref_file=None, autotest=False, |
| 152 | compact_results=False): |
| 153 | """ |
| 154 | Runs the specified tests, printing a table of results as well as logs for |
| 155 | failures (if ref_file isn't specified) or regressions (if it is). |
| 156 | """ |
| 157 | results, ref, deltas = RunAndCompare(glob, ref_file, autotest) |
Dennis Kempin | 97397c6 | 2013-02-28 10:49:59 -0800 | [diff] [blame] | 158 | |
Dennis Kempin | 725ee5b | 2012-08-10 14:17:15 -0700 | [diff] [blame] | 159 | # print reports |
Andrew de los Reyes | bf5fa42 | 2012-10-17 16:45:45 -0700 | [diff] [blame] | 160 | sorted_results_items = sorted(results.items()) |
Harry Cutts | 4f5a88c | 2020-04-28 16:13:00 -0700 | [diff] [blame] | 161 | for case_name, value in sorted_results_items: |
| 162 | if case_name in ref: |
| 163 | should_show_report = math.fabs(deltas[case_name]) >= 1e-10 |
| 164 | else: |
| 165 | should_show_report = value["result"] != "success" |
| 166 | if not should_show_report and len(results) > 1: |
| 167 | continue |
Dennis Kempin | 97397c6 | 2013-02-28 10:49:59 -0800 | [diff] [blame] | 168 | |
Harry Cutts | 4f5a88c | 2020-04-28 16:13:00 -0700 | [diff] [blame] | 169 | print("### Validation report for", case_name) |
Harry Cutts | 684f78c | 2020-04-09 18:37:05 -0700 | [diff] [blame] | 170 | print(value["description"]) |
Dennis Kempin | 9cfc484 | 2013-02-28 10:39:24 -0800 | [diff] [blame] | 171 | if value["disabled"]: |
Harry Cutts | 684f78c | 2020-04-09 18:37:05 -0700 | [diff] [blame] | 172 | print("DISABLED") |
Dennis Kempin | 9cfc484 | 2013-02-28 10:39:24 -0800 | [diff] [blame] | 173 | else: |
Harry Cutts | 684f78c | 2020-04-09 18:37:05 -0700 | [diff] [blame] | 174 | print(value["logs"]["validation"]) |
| 175 | print(value["error"]) |
Dennis Kempin | 4bc397b | 2012-08-08 16:51:47 -0700 | [diff] [blame] | 176 | |
Harry Cutts | 4f5a88c | 2020-04-28 16:13:00 -0700 | [diff] [blame] | 177 | print(MakeResultsTable("Test Results", results.keys(), results, ref, deltas)) |
Dennis Kempin | 22c7c4d | 2012-07-26 13:04:24 -0700 | [diff] [blame] | 178 | |
Dennis Kempin | 1296830 | 2012-08-09 15:37:09 -0700 | [diff] [blame] | 179 | if out_file: |
Harry Cutts | ffcfa77 | 2020-04-22 16:17:10 -0700 | [diff] [blame] | 180 | if compact_results: |
| 181 | for test_name in results: |
| 182 | r = results[test_name] |
| 183 | del r["logs"], r["events"], r["gestures"] |
| 184 | |
Dennis Kempin | 1296830 | 2012-08-09 15:37:09 -0700 | [diff] [blame] | 185 | json.dump(results, open(out_file, "w"), indent=2) |
Harry Cutts | 684f78c | 2020-04-09 18:37:05 -0700 | [diff] [blame] | 186 | print("results stored in:", out_file) |
Dennis Kempin | 1296830 | 2012-08-09 15:37:09 -0700 | [diff] [blame] | 187 | |
Harry Cutts | 4f5a88c | 2020-04-28 16:13:00 -0700 | [diff] [blame] | 188 | regression = any(name in ref and deltas[name] < 0 for name in results.keys()) |
Dennis Kempin | 725ee5b | 2012-08-10 14:17:15 -0700 | [diff] [blame] | 189 | if regression: |
Harry Cutts | 684f78c | 2020-04-09 18:37:05 -0700 | [diff] [blame] | 190 | print("\x1b[91mThere are regressions present in this test run!\x1b[0m") |
Harry Cutts | 91c0d25 | 2020-04-28 17:10:02 -0700 | [diff] [blame] | 191 | sys.exit(1) |
Dennis Kempin | 725ee5b | 2012-08-10 14:17:15 -0700 | [diff] [blame] | 192 | |
Dennis Kempin | 1c7ffab | 2013-02-28 11:43:45 -0800 | [diff] [blame] | 193 | |
Harry Cutts | 4f5a88c | 2020-04-28 16:13:00 -0700 | [diff] [blame] | 194 | _IMPROVEMENT_MESSAGE = """ |
| 195 | Some tests have been fixed or had their scores improved! Please update |
| 196 | tools/touchtests-report.json by running the following in the chroot: |
| 197 | |
| 198 | $ touchtests --compact-results \\ |
| 199 | --out ~/trunk/src/platform/gestures/tools/touchtests-report.json |
| 200 | |
| 201 | Then add commit the JSON file changes to your CL. |
| 202 | """ |
| 203 | |
| 204 | def PresubmitRun(ref_file, autotest=False): |
| 205 | """ |
| 206 | Runs a gestures library presubmit, meaning it runs all tests, and exits with |
| 207 | an error if any have regressed or been fixed (so that the user can update the |
| 208 | reference file). |
| 209 | """ |
| 210 | results, ref, deltas = RunAndCompare("all", ref_file, autotest) |
| 211 | |
| 212 | new_tests = results.keys() - ref.keys() |
| 213 | failing_new_tests = set(filter(lambda n: results[n]["result"] != "success", |
| 214 | new_tests)) |
| 215 | regressions = set(filter(lambda name: deltas[name] <= -1e-10, deltas.keys())) |
| 216 | problems = regressions | failing_new_tests |
| 217 | if len(problems) > 0: |
| 218 | print(MakeResultsTable("Regressions or failures", problems, results, ref, |
| 219 | deltas)) |
| 220 | |
| 221 | if len(problems) > 0: |
| 222 | print("\x1b[91mPlease fix these failures or regressions, then re-run the " |
| 223 | "presubmit.\x1b[0m") |
| 224 | sys.exit(1) |
| 225 | |
| 226 | fixed_tests = set(filter(lambda name: deltas[name] >= 1e-10, deltas.keys())) |
| 227 | if len(fixed_tests) > 0: |
| 228 | print(MakeResultsTable("Improvements", fixed_tests, results, ref, deltas)) |
| 229 | print(_IMPROVEMENT_MESSAGE) |
| 230 | sys.exit(1) |
| 231 | |
| 232 | |
Dennis Kempin | 64f513f | 2012-08-10 15:09:18 -0700 | [diff] [blame] | 233 | def Get(test_name, what, file=None): |
Dennis Kempin | 1c7ffab | 2013-02-28 11:43:45 -0800 | [diff] [blame] | 234 | Compile() |
Dennis Kempin | 64f513f | 2012-08-10 15:09:18 -0700 | [diff] [blame] | 235 | if file: |
| 236 | data = json.load(open(file)) |
| 237 | results = data[test_name] |
| 238 | else: |
Dennis Kempin | aad2bbb | 2013-06-18 13:48:35 -0700 | [diff] [blame] | 239 | runner = TestRunner(os.environ["TESTS_DIR"]) |
Dennis Kempin | 64f513f | 2012-08-10 15:09:18 -0700 | [diff] [blame] | 240 | data = runner.RunAll(test_name) |
| 241 | results = data[test_name] |
| 242 | |
| 243 | if what == "gestures-log": |
Harry Cutts | 684f78c | 2020-04-09 18:37:05 -0700 | [diff] [blame] | 244 | print(results["logs"]["gestures"]) |
Dennis Kempin | 64f513f | 2012-08-10 15:09:18 -0700 | [diff] [blame] | 245 | elif what == "evdev-log": |
Harry Cutts | 684f78c | 2020-04-09 18:37:05 -0700 | [diff] [blame] | 246 | print(results["logs"]["evdev"]) |
Dennis Kempin | 64f513f | 2012-08-10 15:09:18 -0700 | [diff] [blame] | 247 | elif what == "activity-log": |
Harry Cutts | 684f78c | 2020-04-09 18:37:05 -0700 | [diff] [blame] | 248 | print(results["logs"]["activity"]) |
Dennis Kempin | 64f513f | 2012-08-10 15:09:18 -0700 | [diff] [blame] | 249 | elif what == "gestures": |
Harry Cutts | 684f78c | 2020-04-09 18:37:05 -0700 | [diff] [blame] | 250 | print(results["gestures"]) |
Dennis Kempin | 64f513f | 2012-08-10 15:09:18 -0700 | [diff] [blame] | 251 | elif what == "events": |
Harry Cutts | 684f78c | 2020-04-09 18:37:05 -0700 | [diff] [blame] | 252 | print(results["events"]) |
Dennis Kempin | 3b1fca7 | 2014-01-09 11:54:59 -0800 | [diff] [blame] | 253 | elif what == "activity": |
| 254 | log = Log(activity=results["logs"]["activity"]) |
| 255 | editor = MTEdit() |
| 256 | editor.View(log) |
Dennis Kempin | 64f513f | 2012-08-10 15:09:18 -0700 | [diff] [blame] | 257 | |
Dennis Kempin | 462c875 | 2013-04-04 16:01:54 -0700 | [diff] [blame] | 258 | def GDB(test_name): |
| 259 | Compile() |
Dennis Kempin | aad2bbb | 2013-06-18 13:48:35 -0700 | [diff] [blame] | 260 | runner = TestRunner(os.environ["TESTS_DIR"]) |
Dennis Kempin | 462c875 | 2013-04-04 16:01:54 -0700 | [diff] [blame] | 261 | data = runner.RunGDB(test_name) |
Dennis Kempin | 1c7ffab | 2013-02-28 11:43:45 -0800 | [diff] [blame] | 262 | |
Dennis Kempin | 3b1fca7 | 2014-01-09 11:54:59 -0800 | [diff] [blame] | 263 | def Add(testname, log, gdb): |
Dennis Kempin | 22c7c4d | 2012-07-26 13:04:24 -0700 | [diff] [blame] | 264 | """ |
| 265 | Adds a new test case. |
| 266 | """ |
| 267 | # determine test name from activity_log name |
Dennis Kempin | aad2bbb | 2013-06-18 13:48:35 -0700 | [diff] [blame] | 268 | factory = TestFactory(os.environ["TESTS_DIR"]) |
Dennis Kempin | 3b1fca7 | 2014-01-09 11:54:59 -0800 | [diff] [blame] | 269 | case = factory.CreateTest(testname, log, gdb) |
Dennis Kempin | 15967a4 | 2013-02-25 12:41:54 -0800 | [diff] [blame] | 270 | if case: |
Harry Cutts | 684f78c | 2020-04-09 18:37:05 -0700 | [diff] [blame] | 271 | print("Test \"" + case.name + "\" created") |
Dennis Kempin | 22c7c4d | 2012-07-26 13:04:24 -0700 | [diff] [blame] | 272 | |
Dennis Kempin | 07e90e7 | 2014-04-15 13:54:39 -0700 | [diff] [blame] | 273 | def AddPlatform(ip): |
| 274 | name = PlatformDatabase.RegisterPlatformFromDevice(ip) |
| 275 | if not name: |
| 276 | return |
| 277 | dirname = os.path.join(os.environ["TESTS_DIR"], name) |
| 278 | propsfile = os.path.join(dirname, "platform.props") |
Dennis Kempin | 544dfde | 2014-06-09 14:02:55 -0700 | [diff] [blame] | 279 | if not os.path.exists(dirname): |
| 280 | os.mkdir(dirname) |
Dennis Kempin | 07e90e7 | 2014-04-15 13:54:39 -0700 | [diff] [blame] | 281 | open(propsfile, "w").write("{\"platform\": \"%s\"}" % name) |
Harry Cutts | 684f78c | 2020-04-09 18:37:05 -0700 | [diff] [blame] | 282 | print(" ", propsfile) |
Dennis Kempin | 1c7ffab | 2013-02-28 11:43:45 -0800 | [diff] [blame] | 283 | |
Dennis Kempin | 22c7c4d | 2012-07-26 13:04:24 -0700 | [diff] [blame] | 284 | def Main(): |
| 285 | """ |
| 286 | Main entry point for the console interface |
| 287 | """ |
| 288 | |
| 289 | # setup paths from environment variables |
| 290 | if "TESTS_DIR" not in os.environ: |
Harry Cutts | 684f78c | 2020-04-09 18:37:05 -0700 | [diff] [blame] | 291 | print("Require TESTS_DIR environment variable") |
Harry Cutts | 91c0d25 | 2020-04-28 17:10:02 -0700 | [diff] [blame] | 292 | sys.exit(1) |
Dennis Kempin | 22c7c4d | 2012-07-26 13:04:24 -0700 | [diff] [blame] | 293 | |
Dennis Kempin | 22c7c4d | 2012-07-26 13:04:24 -0700 | [diff] [blame] | 294 | TestCase.tests_path = os.environ["TESTS_DIR"] |
Dennis Kempin | 22c7c4d | 2012-07-26 13:04:24 -0700 | [diff] [blame] | 295 | |
Dennis Kempin | c2b5986 | 2013-02-20 14:02:25 -0800 | [diff] [blame] | 296 | parser = OptionParser(usage=_help_text) |
| 297 | parser.add_option("-c", "--create", |
| 298 | dest="create", default=None, |
| 299 | help="create new test case from URL/IP or log file") |
Andrew de los Reyes | 408678b | 2015-01-09 14:21:55 -0800 | [diff] [blame] | 300 | parser.add_option("-p", "--platform", |
| 301 | dest="platform", default=None, |
| 302 | help="specify platform when using --create") |
Dennis Kempin | c2b5986 | 2013-02-20 14:02:25 -0800 | [diff] [blame] | 303 | parser.add_option("-e", "--evdev", |
| 304 | dest="evdev", default=None, |
| 305 | help="path to evdev log for creating a new test") |
| 306 | parser.add_option("-v", "--view", |
| 307 | dest="view", default=None, |
| 308 | help="view generated gestures(g), activity in mtedit(a) " + |
| 309 | "gestures-log(gl), evdev-log(el) or activity-log(al)") |
| 310 | parser.add_option("-r", "--ref", |
| 311 | dest="ref", default=None, |
| 312 | help="reference test results for detecting regressions") |
| 313 | parser.add_option("-o", "--out", |
| 314 | dest="out", default=None, |
| 315 | help="output test results to file.") |
Harry Cutts | ffcfa77 | 2020-04-22 16:17:10 -0700 | [diff] [blame] | 316 | parser.add_option("--compact-results", |
| 317 | dest="compact_results", action="store_true", default=False, |
| 318 | help="exclude logs from the test result file when using " |
| 319 | "--out, making it much smaller") |
Dennis Kempin | c2b5986 | 2013-02-20 14:02:25 -0800 | [diff] [blame] | 320 | parser.add_option("-n", "--new", |
| 321 | dest="new", action="store_true", default=False, |
| 322 | help="Create new device logs before downloading. " + |
| 323 | "[Default: False]") |
| 324 | parser.add_option("--no-edit", |
| 325 | dest="noedit", action="store_true", default=False, |
| 326 | help="Skip editing when creating tests. Add original log " + |
| 327 | "[Default: False]") |
Dennis Kempin | 8e3201c | 2013-03-14 13:49:01 -0700 | [diff] [blame] | 328 | parser.add_option("--autotest", |
| 329 | dest="autotest", action="store_true", default=False, |
| 330 | help="Run in autotest mode. Skips recompilation.") |
Dennis Kempin | 462c875 | 2013-04-04 16:01:54 -0700 | [diff] [blame] | 331 | parser.add_option("--gdb", |
| 332 | dest="gdb", action="store_true", default=False, |
Dennis Kempin | 93a7141 | 2014-01-10 13:39:37 -0800 | [diff] [blame] | 333 | help="Run the test case in GDB"), |
Dennis Kempin | d97cd72 | 2014-01-31 13:32:07 -0800 | [diff] [blame] | 334 | parser.add_option("--verbose", |
| 335 | dest="verbose", action="store_true", default=False, |
Dennis Kempin | 93a7141 | 2014-01-10 13:39:37 -0800 | [diff] [blame] | 336 | help="Verbose debug output"), |
| 337 | parser.add_option("--robot", |
| 338 | dest="robot", default=None, |
| 339 | help="Instruct robot to generate test cases") |
Andrew de los Reyes | 8063b66 | 2014-07-11 14:58:30 -0700 | [diff] [blame] | 340 | parser.add_option("--collect_from", |
| 341 | dest="collect_ip", default=None, |
| 342 | help="Interactively collect tests at given device IP"); |
| 343 | parser.add_option( |
| 344 | "--overwrite", |
| 345 | dest="overwrite", action="store_true", default=False, |
| 346 | help="(use with --robot or --collect_from) Overwrite existing tests") |
Dennis Kempin | 93a7141 | 2014-01-10 13:39:37 -0800 | [diff] [blame] | 347 | parser.add_option("--no-calib", |
| 348 | dest="nocalib", action="store_true", default=False, |
| 349 | help="(use with --robot) Skip calibration step.") |
| 350 | parser.add_option("--manual-fingertips", |
| 351 | dest="manual_fingertips", action="store_true", |
| 352 | default=False, |
| 353 | help="(use with --robot) Use fingertips that are present.") |
| 354 | parser.add_option("--slow", |
| 355 | dest="slow", action="store_true", default=False, |
| 356 | help="(use with --robot) Force slow movement.") |
Dennis Kempin | 07e90e7 | 2014-04-15 13:54:39 -0700 | [diff] [blame] | 357 | parser.add_option("--add-platform", |
| 358 | dest="add_platform", default=None, |
| 359 | help="add platform from IP address of remote device.") |
Harry Cutts | 4f5a88c | 2020-04-28 16:13:00 -0700 | [diff] [blame] | 360 | parser.add_option("--presubmit", |
| 361 | dest="presubmit", action="store_true", default=False, |
| 362 | help="run tests as part of a Gestures library presubmit") |
Dennis Kempin | 93a7141 | 2014-01-10 13:39:37 -0800 | [diff] [blame] | 363 | |
Dennis Kempin | c2b5986 | 2013-02-20 14:02:25 -0800 | [diff] [blame] | 364 | (options, args) = parser.parse_args() |
Andrew de los Reyes | 8c5585b | 2013-05-20 15:32:05 -0700 | [diff] [blame] | 365 | options.download = False # For compatibility with mtedit |
Andrew de los Reyes | 0489c66 | 2013-06-04 12:47:50 -0700 | [diff] [blame] | 366 | options.screenshot = False # For compatibility with mtedit |
Dennis Kempin | 22c7c4d | 2012-07-26 13:04:24 -0700 | [diff] [blame] | 367 | |
Dennis Kempin | 07e90e7 | 2014-04-15 13:54:39 -0700 | [diff] [blame] | 368 | if options.add_platform: |
| 369 | AddPlatform(options.add_platform) |
| 370 | return |
| 371 | |
Dennis Kempin | c2b5986 | 2013-02-20 14:02:25 -0800 | [diff] [blame] | 372 | if len(args) == 0: |
| 373 | test_name = "all" |
| 374 | elif len(args) == 1: |
| 375 | test_name = args[0] |
| 376 | else: |
| 377 | parser.print_help() |
Harry Cutts | 91c0d25 | 2020-04-28 17:10:02 -0700 | [diff] [blame] | 378 | sys.exit(1) |
Dennis Kempin | c2b5986 | 2013-02-20 14:02:25 -0800 | [diff] [blame] | 379 | |
Dennis Kempin | d97cd72 | 2014-01-31 13:32:07 -0800 | [diff] [blame] | 380 | level = logging.INFO if options.verbose else logging.WARNING |
| 381 | logging.basicConfig(level=level) |
| 382 | |
Dennis Kempin | c2b5986 | 2013-02-20 14:02:25 -0800 | [diff] [blame] | 383 | if options.create: |
Dennis Kempin | c2b5986 | 2013-02-20 14:02:25 -0800 | [diff] [blame] | 384 | # obtain trimmed log data |
| 385 | original_log = Log(options.create, options) |
| 386 | if options.noedit: |
| 387 | log = original_log |
Dennis Kempin | 1296830 | 2012-08-09 15:37:09 -0700 | [diff] [blame] | 388 | else: |
Dennis Kempin | aad2bbb | 2013-06-18 13:48:35 -0700 | [diff] [blame] | 389 | editor = MTEdit() |
Andrew de los Reyes | 408678b | 2015-01-09 14:21:55 -0800 | [diff] [blame] | 390 | platform = options.platform or test_name.split(os.sep)[0] |
Andrew de los Reyes | 8cc4b0a | 2014-10-24 12:34:58 -0700 | [diff] [blame] | 391 | log = editor.Edit(original_log, force_platform=platform) |
Dennis Kempin | 22c7c4d | 2012-07-26 13:04:24 -0700 | [diff] [blame] | 392 | |
Dennis Kempin | c2b5986 | 2013-02-20 14:02:25 -0800 | [diff] [blame] | 393 | # pass to touchtests |
Dennis Kempin | 3b1fca7 | 2014-01-09 11:54:59 -0800 | [diff] [blame] | 394 | Add(test_name, log, options.gdb) |
Dennis Kempin | c2b5986 | 2013-02-20 14:02:25 -0800 | [diff] [blame] | 395 | |
| 396 | elif options.view: |
| 397 | view = options.view |
| 398 | if view == "g": |
| 399 | view = "gestures" |
| 400 | elif view == "gl": |
| 401 | view = "gestures-log" |
| 402 | elif view == "el": |
| 403 | view = "evdev-log" |
| 404 | elif view == "al": |
| 405 | view = "activity-log" |
| 406 | elif view == "a": |
| 407 | view = "activity" |
Dennis Kempin | 3b1fca7 | 2014-01-09 11:54:59 -0800 | [diff] [blame] | 408 | Get(test_name, view) |
Dennis Kempin | 462c875 | 2013-04-04 16:01:54 -0700 | [diff] [blame] | 409 | elif options.gdb: |
| 410 | GDB(test_name) |
Andrew de los Reyes | 8063b66 | 2014-07-11 14:58:30 -0700 | [diff] [blame] | 411 | elif options.collect_ip: |
| 412 | generator = TestCollector(options.collect_ip, os.environ["TESTS_DIR"]) |
| 413 | generator.GenerateAll(test_name, options.overwrite) |
Dennis Kempin | 93a7141 | 2014-01-10 13:39:37 -0800 | [diff] [blame] | 414 | elif options.robot: |
| 415 | generator = RobotTestGenerator(options.robot, not options.nocalib, |
| 416 | options.slow, options.manual_fingertips, os.environ["TESTS_DIR"]) |
| 417 | generator.GenerateAll(test_name, options.overwrite) |
Harry Cutts | 4f5a88c | 2020-04-28 16:13:00 -0700 | [diff] [blame] | 418 | elif options.presubmit: |
| 419 | if options.ref is None: |
| 420 | print("Error: --ref must be specified with --presubmit.") |
| 421 | sys.exit(1) |
| 422 | |
| 423 | PresubmitRun(options.ref, options.autotest) |
Dennis Kempin | 22c7c4d | 2012-07-26 13:04:24 -0700 | [diff] [blame] | 424 | else: |
Harry Cutts | 4f5a88c | 2020-04-28 16:13:00 -0700 | [diff] [blame] | 425 | ManualRun(test_name, options.out, options.ref, options.autotest, |
| 426 | options.compact_results) |
Dennis Kempin | 1c7ffab | 2013-02-28 11:43:45 -0800 | [diff] [blame] | 427 | |
Dennis Kempin | 22c7c4d | 2012-07-26 13:04:24 -0700 | [diff] [blame] | 428 | |
Dennis Kempin | 22c7c4d | 2012-07-26 13:04:24 -0700 | [diff] [blame] | 429 | if __name__ == "__main__": |
| 430 | Main() |