blob: 36d398cc160c74996b1fdcdf73264f7f1f1df3a6 [file] [log] [blame]
Jeff Sharkey58a81b62024-01-29 14:23:09 -07001#!/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"""
18Tool to bulk-enable tests that are now passing on Ravenwood.
19
20Currently only offers to include classes which are fully passing; ignores
21classes that have partial success.
22
23Typical usage:
24$ ENABLE_PROBE_IGNORED=1 atest MyTestsRavenwood
25$ cd /path/to/tests/root
26$ python bulk_enable.py /path/to/atest/output/host_log.txt
27"""
28
29import collections
30import os
31import re
32import subprocess
33import sys
34
35re_result = re.compile("I/ModuleListener.+?null-device-0 (.+?)#(.+?) ([A-Z_]+)(.*)$")
36
37ANNOTATION = "@android.platform.test.annotations.EnabledOnRavenwood"
38SED_ARG = "s/^((public )?class )/%s\\n\\1/g" % (ANNOTATION)
39
40STATE_PASSED = "PASSED"
41STATE_FAILURE = "FAILURE"
42STATE_ASSUMPTION_FAILURE = "ASSUMPTION_FAILURE"
43STATE_CANDIDATE = "CANDIDATE"
44
45stats_total = collections.defaultdict(int)
46stats_class = collections.defaultdict(lambda: collections.defaultdict(int))
47stats_method = collections.defaultdict()
48
49with open(sys.argv[1]) as f:
50 for line in f.readlines():
51 result = re_result.search(line)
52 if result:
53 clazz, method, state, msg = result.groups()
54 if state == STATE_FAILURE and "actually passed under Ravenwood" in msg:
55 state = STATE_CANDIDATE
56 stats_total[state] += 1
57 stats_class[clazz][state] += 1
58 stats_method[(clazz, method)] = state
59
60# Find classes who are fully "candidates" (would be entirely green if enabled)
61num_enabled = 0
62for clazz in stats_class.keys():
63 stats = stats_class[clazz]
64 if STATE_CANDIDATE in stats and len(stats) == 1:
65 num_enabled += stats[STATE_CANDIDATE]
66 print("Enabling fully-passing class", clazz)
67 clazz_match = re.compile("%s\.(kt|java)" % (clazz.split(".")[-1]))
68 for root, dirs, files in os.walk("."):
69 for f in files:
70 if clazz_match.match(f):
71 path = os.path.join(root, f)
72 subprocess.run(["sed", "-i", "-E", SED_ARG, path])
73
74print("Overall stats", stats_total)
75print("Candidates actually enabled", num_enabled)