Jeff Sharkey | 58a81b6 | 2024-01-29 14:23:09 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | # |
| 3 | # Copyright (C) 2024 The Android Open Source Project |
| 4 | # |
| 5 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | # you may not use this file except in compliance with the License. |
| 7 | # You may obtain a copy of the License at |
| 8 | # |
| 9 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | # |
| 11 | # Unless required by applicable law or agreed to in writing, software |
| 12 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | # See the License for the specific language governing permissions and |
| 15 | # limitations under the License. |
| 16 | |
| 17 | """ |
| 18 | Tool to bulk-enable tests that are now passing on Ravenwood. |
| 19 | |
| 20 | Currently only offers to include classes which are fully passing; ignores |
| 21 | classes that have partial success. |
| 22 | |
| 23 | Typical usage: |
Makoto Onuki | 03e9c7c | 2024-02-01 09:42:37 -0800 | [diff] [blame] | 24 | $ RAVENWOOD_RUN_DISABLED_TESTS=1 atest MyTestsRavenwood |
Jeff Sharkey | 58a81b6 | 2024-01-29 14:23:09 -0700 | [diff] [blame] | 25 | $ cd /path/to/tests/root |
| 26 | $ python bulk_enable.py /path/to/atest/output/host_log.txt |
| 27 | """ |
| 28 | |
| 29 | import collections |
| 30 | import os |
| 31 | import re |
| 32 | import subprocess |
| 33 | import sys |
| 34 | |
| 35 | re_result = re.compile("I/ModuleListener.+?null-device-0 (.+?)#(.+?) ([A-Z_]+)(.*)$") |
| 36 | |
Jeff Sharkey | 18a656b | 2024-01-31 13:41:06 -0700 | [diff] [blame] | 37 | DRY_RUN = "-n" in sys.argv |
| 38 | |
Jeff Sharkey | 58a81b6 | 2024-01-29 14:23:09 -0700 | [diff] [blame] | 39 | ANNOTATION = "@android.platform.test.annotations.EnabledOnRavenwood" |
| 40 | SED_ARG = "s/^((public )?class )/%s\\n\\1/g" % (ANNOTATION) |
| 41 | |
| 42 | STATE_PASSED = "PASSED" |
| 43 | STATE_FAILURE = "FAILURE" |
| 44 | STATE_ASSUMPTION_FAILURE = "ASSUMPTION_FAILURE" |
| 45 | STATE_CANDIDATE = "CANDIDATE" |
| 46 | |
| 47 | stats_total = collections.defaultdict(int) |
| 48 | stats_class = collections.defaultdict(lambda: collections.defaultdict(int)) |
| 49 | stats_method = collections.defaultdict() |
| 50 | |
Jeff Sharkey | 18a656b | 2024-01-31 13:41:06 -0700 | [diff] [blame] | 51 | with open(sys.argv[-1]) as f: |
Jeff Sharkey | 58a81b6 | 2024-01-29 14:23:09 -0700 | [diff] [blame] | 52 | for line in f.readlines(): |
| 53 | result = re_result.search(line) |
| 54 | if result: |
| 55 | clazz, method, state, msg = result.groups() |
| 56 | if state == STATE_FAILURE and "actually passed under Ravenwood" in msg: |
| 57 | state = STATE_CANDIDATE |
| 58 | stats_total[state] += 1 |
| 59 | stats_class[clazz][state] += 1 |
| 60 | stats_method[(clazz, method)] = state |
| 61 | |
| 62 | # Find classes who are fully "candidates" (would be entirely green if enabled) |
| 63 | num_enabled = 0 |
| 64 | for clazz in stats_class.keys(): |
| 65 | stats = stats_class[clazz] |
| 66 | if STATE_CANDIDATE in stats and len(stats) == 1: |
| 67 | num_enabled += stats[STATE_CANDIDATE] |
| 68 | print("Enabling fully-passing class", clazz) |
| 69 | clazz_match = re.compile("%s\.(kt|java)" % (clazz.split(".")[-1])) |
| 70 | for root, dirs, files in os.walk("."): |
| 71 | for f in files: |
Jeff Sharkey | 18a656b | 2024-01-31 13:41:06 -0700 | [diff] [blame] | 72 | if clazz_match.match(f) and not DRY_RUN: |
Jeff Sharkey | 58a81b6 | 2024-01-29 14:23:09 -0700 | [diff] [blame] | 73 | path = os.path.join(root, f) |
| 74 | subprocess.run(["sed", "-i", "-E", SED_ARG, path]) |
| 75 | |
| 76 | print("Overall stats", stats_total) |
| 77 | print("Candidates actually enabled", num_enabled) |