xref: /aosp_15_r20/art/test/Android.run-test.bp.py (revision 795d594fd825385562da6b089ea9b2033f3abf5a)
1*795d594fSAndroid Build Coastguard Worker#!/usr/bin/env python3
2*795d594fSAndroid Build Coastguard Worker#
3*795d594fSAndroid Build Coastguard Worker# Copyright (C) 2021 The Android Open Source Project
4*795d594fSAndroid Build Coastguard Worker#
5*795d594fSAndroid Build Coastguard Worker# Licensed under the Apache License, Version 2.0 (the "License");
6*795d594fSAndroid Build Coastguard Worker# you may not use this file except in compliance with the License.
7*795d594fSAndroid Build Coastguard Worker# You may obtain a copy of the License at
8*795d594fSAndroid Build Coastguard Worker#
9*795d594fSAndroid Build Coastguard Worker#      http://www.apache.org/licenses/LICENSE-2.0
10*795d594fSAndroid Build Coastguard Worker#
11*795d594fSAndroid Build Coastguard Worker# Unless required by applicable law or agreed to in writing, software
12*795d594fSAndroid Build Coastguard Worker# distributed under the License is distributed on an "AS IS" BASIS,
13*795d594fSAndroid Build Coastguard Worker# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14*795d594fSAndroid Build Coastguard Worker# See the License for the specific language governing permissions and
15*795d594fSAndroid Build Coastguard Worker# limitations under the License.
16*795d594fSAndroid Build Coastguard Worker
17*795d594fSAndroid Build Coastguard Worker""" This script generates the Android.run-test.bp build file"""
18*795d594fSAndroid Build Coastguard Worker
19*795d594fSAndroid Build Coastguard Workerimport glob
20*795d594fSAndroid Build Coastguard Workerimport json
21*795d594fSAndroid Build Coastguard Workerimport os
22*795d594fSAndroid Build Coastguard Workerimport textwrap
23*795d594fSAndroid Build Coastguard Workerimport sys
24*795d594fSAndroid Build Coastguard Worker
25*795d594fSAndroid Build Coastguard Workerdef main():
26*795d594fSAndroid Build Coastguard Worker  os.chdir(os.path.dirname(__file__))
27*795d594fSAndroid Build Coastguard Worker  with open("Android.run-test.bp", mode="wt") as f:
28*795d594fSAndroid Build Coastguard Worker    f.write(textwrap.dedent(f"""
29*795d594fSAndroid Build Coastguard Worker      // This file was generated by {os.path.basename(__file__)}
30*795d594fSAndroid Build Coastguard Worker      // It is not necessary to regenerate it when tests are added/removed/modified.
31*795d594fSAndroid Build Coastguard Worker
32*795d594fSAndroid Build Coastguard Worker      TEST_BUILD_COMMON_ARGS = "$(location run_test_build.py) --out $(out) " +
33*795d594fSAndroid Build Coastguard Worker          "--bootclasspath $(location :art-run-test-bootclasspath) " +
34*795d594fSAndroid Build Coastguard Worker          "--d8 $(location d8) " +
35*795d594fSAndroid Build Coastguard Worker          "--jasmin $(location jasmin) " +
36*795d594fSAndroid Build Coastguard Worker          "--rewrapper $(location rewrapper) " +
37*795d594fSAndroid Build Coastguard Worker          "--smali $(location android-smali) " +
38*795d594fSAndroid Build Coastguard Worker          "--soong_zip $(location soong_zip) " +
39*795d594fSAndroid Build Coastguard Worker          "--zipalign $(location zipalign) "
40*795d594fSAndroid Build Coastguard Worker    """).lstrip())
41*795d594fSAndroid Build Coastguard Worker    for mode in ["host", "target", "jvm"]:
42*795d594fSAndroid Build Coastguard Worker      names = []
43*795d594fSAndroid Build Coastguard Worker      # Group the tests into shards based on the last two digits of the test number.
44*795d594fSAndroid Build Coastguard Worker      # This keeps the number of generated genrules low so we don't overwhelm soong,
45*795d594fSAndroid Build Coastguard Worker      # but it still allows iterating on single test without recompiling all tests.
46*795d594fSAndroid Build Coastguard Worker      for shard in ["{:02}".format(i) for i in range(100)]:
47*795d594fSAndroid Build Coastguard Worker        name = f"art-run-test-{mode}-data-shard{shard}"
48*795d594fSAndroid Build Coastguard Worker        names.append(name)
49*795d594fSAndroid Build Coastguard Worker        f.write(textwrap.dedent(f"""
50*795d594fSAndroid Build Coastguard Worker          java_genrule {{
51*795d594fSAndroid Build Coastguard Worker              name: "{name}-tmp",
52*795d594fSAndroid Build Coastguard Worker              out: ["{name}.zip"],
53*795d594fSAndroid Build Coastguard Worker              srcs: [
54*795d594fSAndroid Build Coastguard Worker                  "?{shard}-*/**/*",
55*795d594fSAndroid Build Coastguard Worker                  "??{shard}-*/**/*",
56*795d594fSAndroid Build Coastguard Worker              ],
57*795d594fSAndroid Build Coastguard Worker              cmd: TEST_BUILD_COMMON_ARGS + "--mode {mode} --test-dir-regex 'art/test/..?{shard}-' $(in)",
58*795d594fSAndroid Build Coastguard Worker              defaults: ["art-run-test-{mode}-data-defaults"],
59*795d594fSAndroid Build Coastguard Worker          }}
60*795d594fSAndroid Build Coastguard Worker
61*795d594fSAndroid Build Coastguard Worker          // This filegroup is so that the host prebuilt etc can depend on a device genrule,
62*795d594fSAndroid Build Coastguard Worker          // as prebuilt_etc doesn't have the equivalent of device_common_srcs.
63*795d594fSAndroid Build Coastguard Worker          filegroup {{
64*795d594fSAndroid Build Coastguard Worker              name: "{name}-fg",
65*795d594fSAndroid Build Coastguard Worker              device_common_srcs: [":{name}-tmp"],
66*795d594fSAndroid Build Coastguard Worker          }}
67*795d594fSAndroid Build Coastguard Worker
68*795d594fSAndroid Build Coastguard Worker          // Install in the output directory to make it accessible for tests.
69*795d594fSAndroid Build Coastguard Worker          prebuilt_etc_host {{
70*795d594fSAndroid Build Coastguard Worker              name: "{name}",
71*795d594fSAndroid Build Coastguard Worker              src: ":{name}-fg",
72*795d594fSAndroid Build Coastguard Worker              sub_dir: "art",
73*795d594fSAndroid Build Coastguard Worker              filename: "{name}.zip",
74*795d594fSAndroid Build Coastguard Worker          }}
75*795d594fSAndroid Build Coastguard Worker          """))
76*795d594fSAndroid Build Coastguard Worker
77*795d594fSAndroid Build Coastguard Worker      # Build all hiddenapi tests in their own shard.
78*795d594fSAndroid Build Coastguard Worker      # This removes the dependency on hiddenapi from all other shards,
79*795d594fSAndroid Build Coastguard Worker      # which in turn removes dependency on ART C++ source code.
80*795d594fSAndroid Build Coastguard Worker      name = "art-run-test-{mode}-data-shardHiddenApi".format(mode=mode)
81*795d594fSAndroid Build Coastguard Worker      names.append(name)
82*795d594fSAndroid Build Coastguard Worker      f.write(textwrap.dedent(f"""
83*795d594fSAndroid Build Coastguard Worker        java_genrule {{
84*795d594fSAndroid Build Coastguard Worker            name: "{name}-tmp",
85*795d594fSAndroid Build Coastguard Worker            out: ["{name}.zip"],
86*795d594fSAndroid Build Coastguard Worker            srcs: [
87*795d594fSAndroid Build Coastguard Worker                "???-*hiddenapi*/**/*",
88*795d594fSAndroid Build Coastguard Worker                "????-*hiddenapi*/**/*",
89*795d594fSAndroid Build Coastguard Worker            ],
90*795d594fSAndroid Build Coastguard Worker            defaults: ["art-run-test-{mode}-data-defaults"],
91*795d594fSAndroid Build Coastguard Worker            tools: ["hiddenapi"],
92*795d594fSAndroid Build Coastguard Worker            cmd: TEST_BUILD_COMMON_ARGS + "--hiddenapi $(location hiddenapi) --mode {mode} --test-dir-regex 'art/test/....?-[^/]*hiddenapi' $(in)",
93*795d594fSAndroid Build Coastguard Worker        }}
94*795d594fSAndroid Build Coastguard Worker
95*795d594fSAndroid Build Coastguard Worker        // This filegroup is so that the host prebuilt etc can depend on a device genrule,
96*795d594fSAndroid Build Coastguard Worker        // as prebuilt_etc doesn't have the equivalent of device_common_srcs.
97*795d594fSAndroid Build Coastguard Worker        filegroup {{
98*795d594fSAndroid Build Coastguard Worker            name: "{name}-fg",
99*795d594fSAndroid Build Coastguard Worker            device_common_srcs: [":{name}-tmp"],
100*795d594fSAndroid Build Coastguard Worker        }}
101*795d594fSAndroid Build Coastguard Worker
102*795d594fSAndroid Build Coastguard Worker        // Install in the output directory to make it accessible for tests.
103*795d594fSAndroid Build Coastguard Worker        prebuilt_etc_host {{
104*795d594fSAndroid Build Coastguard Worker            name: "{name}",
105*795d594fSAndroid Build Coastguard Worker            src: ":{name}-fg",
106*795d594fSAndroid Build Coastguard Worker            sub_dir: "art",
107*795d594fSAndroid Build Coastguard Worker            filename: "{name}.zip",
108*795d594fSAndroid Build Coastguard Worker        }}
109*795d594fSAndroid Build Coastguard Worker        """))
110*795d594fSAndroid Build Coastguard Worker
111*795d594fSAndroid Build Coastguard Worker      f.write(textwrap.dedent(f"""
112*795d594fSAndroid Build Coastguard Worker        genrule_defaults {{
113*795d594fSAndroid Build Coastguard Worker            name: "art-run-test-{mode}-data-defaults",
114*795d594fSAndroid Build Coastguard Worker            srcs: [
115*795d594fSAndroid Build Coastguard Worker                // Since genrules are sandboxed, all the sources they use must be listed in
116*795d594fSAndroid Build Coastguard Worker                // the Android.bp file. Some tests have symlinks to files from other tests, and
117*795d594fSAndroid Build Coastguard Worker                // those must also be listed to avoid a dangling symlink in the sandbox.
118*795d594fSAndroid Build Coastguard Worker                "jvmti-common/*.java",
119*795d594fSAndroid Build Coastguard Worker                "utils/python/**/*.py",
120*795d594fSAndroid Build Coastguard Worker                ":art-run-test-bootclasspath",
121*795d594fSAndroid Build Coastguard Worker                ":development_docs",
122*795d594fSAndroid Build Coastguard Worker                ":asm-9.6-filegroup",
123*795d594fSAndroid Build Coastguard Worker                ":ojluni-AbstractCollection",
124*795d594fSAndroid Build Coastguard Worker                "988-method-trace/expected-stdout.txt",
125*795d594fSAndroid Build Coastguard Worker                "988-method-trace/expected-stderr.txt",
126*795d594fSAndroid Build Coastguard Worker                "988-method-trace/src/art/Test988Intrinsics.java",
127*795d594fSAndroid Build Coastguard Worker                "988-method-trace/src/art/Test988.java",
128*795d594fSAndroid Build Coastguard Worker                "988-method-trace/trace_fib.cc",
129*795d594fSAndroid Build Coastguard Worker                "1953-pop-frame/src/art/Test1953.java",
130*795d594fSAndroid Build Coastguard Worker                "1953-pop-frame/src/art/SuspendEvents.java",
131*795d594fSAndroid Build Coastguard Worker                // Files needed to generate runner scripts.
132*795d594fSAndroid Build Coastguard Worker                "testrunner/*.py",
133*795d594fSAndroid Build Coastguard Worker                "knownfailures.json",
134*795d594fSAndroid Build Coastguard Worker                "default_run.py",
135*795d594fSAndroid Build Coastguard Worker                "globals.py",
136*795d594fSAndroid Build Coastguard Worker                "run-test",
137*795d594fSAndroid Build Coastguard Worker                "run_test_build.py",
138*795d594fSAndroid Build Coastguard Worker            ],
139*795d594fSAndroid Build Coastguard Worker            tools: [
140*795d594fSAndroid Build Coastguard Worker                "android-smali",
141*795d594fSAndroid Build Coastguard Worker                "d8",
142*795d594fSAndroid Build Coastguard Worker                "jasmin",
143*795d594fSAndroid Build Coastguard Worker                "rewrapper",
144*795d594fSAndroid Build Coastguard Worker                "soong_zip",
145*795d594fSAndroid Build Coastguard Worker                "zipalign",
146*795d594fSAndroid Build Coastguard Worker            ],
147*795d594fSAndroid Build Coastguard Worker        }}
148*795d594fSAndroid Build Coastguard Worker        """))
149*795d594fSAndroid Build Coastguard Worker
150*795d594fSAndroid Build Coastguard Worker      name = "art-run-test-{mode}-data-merged".format(mode=mode)
151*795d594fSAndroid Build Coastguard Worker      srcs = ("\n"+" "*16).join('":{}-tmp",'.format(n) for n in names)
152*795d594fSAndroid Build Coastguard Worker      deps = ("\n"+" "*16).join('"{}",'.format(n) for n in names)
153*795d594fSAndroid Build Coastguard Worker      f.write(textwrap.dedent(f"""
154*795d594fSAndroid Build Coastguard Worker        java_genrule {{
155*795d594fSAndroid Build Coastguard Worker            name: "{name}-tmp",
156*795d594fSAndroid Build Coastguard Worker            out: ["{name}.tgz"],
157*795d594fSAndroid Build Coastguard Worker            srcs: [
158*795d594fSAndroid Build Coastguard Worker                {srcs}
159*795d594fSAndroid Build Coastguard Worker            ],
160*795d594fSAndroid Build Coastguard Worker            tool_files: ["merge_zips_to_tgz.py"],
161*795d594fSAndroid Build Coastguard Worker            cmd: "$(location merge_zips_to_tgz.py) $(out) $(in)",
162*795d594fSAndroid Build Coastguard Worker        }}
163*795d594fSAndroid Build Coastguard Worker
164*795d594fSAndroid Build Coastguard Worker        // This filegroup is so that the host prebuilt etc can depend on a device genrule,
165*795d594fSAndroid Build Coastguard Worker        // as prebuilt_etc doesn't have the equivalent of device_common_srcs.
166*795d594fSAndroid Build Coastguard Worker        filegroup {{
167*795d594fSAndroid Build Coastguard Worker            name: "{name}-fg",
168*795d594fSAndroid Build Coastguard Worker            device_common_srcs: [":{name}-tmp"],
169*795d594fSAndroid Build Coastguard Worker        }}
170*795d594fSAndroid Build Coastguard Worker
171*795d594fSAndroid Build Coastguard Worker        // Install in the output directory to make it accessible for tests.
172*795d594fSAndroid Build Coastguard Worker        prebuilt_etc_host {{
173*795d594fSAndroid Build Coastguard Worker            name: "{name}",
174*795d594fSAndroid Build Coastguard Worker            src: ":{name}-fg",
175*795d594fSAndroid Build Coastguard Worker            required: [
176*795d594fSAndroid Build Coastguard Worker                {deps}
177*795d594fSAndroid Build Coastguard Worker            ],
178*795d594fSAndroid Build Coastguard Worker            sub_dir: "art",
179*795d594fSAndroid Build Coastguard Worker            filename: "{name}.tgz",
180*795d594fSAndroid Build Coastguard Worker        }}
181*795d594fSAndroid Build Coastguard Worker        """))
182*795d594fSAndroid Build Coastguard Worker
183*795d594fSAndroid Build Coastguard Worker      name = "art-run-test-{mode}-data".format(mode=mode)
184*795d594fSAndroid Build Coastguard Worker      srcs = ("\n"+" "*16).join('":{}-tmp",'.format(n) for n in names)
185*795d594fSAndroid Build Coastguard Worker      deps = ("\n"+" "*16).join('"{}",'.format(n) for n in names)
186*795d594fSAndroid Build Coastguard Worker      f.write(textwrap.dedent(f"""
187*795d594fSAndroid Build Coastguard Worker        // Phony target used to build all shards
188*795d594fSAndroid Build Coastguard Worker        java_genrule {{
189*795d594fSAndroid Build Coastguard Worker            name: "{name}-tmp",
190*795d594fSAndroid Build Coastguard Worker            out: ["{name}.txt"],
191*795d594fSAndroid Build Coastguard Worker            srcs: [
192*795d594fSAndroid Build Coastguard Worker                {srcs}
193*795d594fSAndroid Build Coastguard Worker            ],
194*795d594fSAndroid Build Coastguard Worker            cmd: "echo $(in) > $(out)",
195*795d594fSAndroid Build Coastguard Worker        }}
196*795d594fSAndroid Build Coastguard Worker
197*795d594fSAndroid Build Coastguard Worker        // This filegroup is so that the host prebuilt etc can depend on a device genrule,
198*795d594fSAndroid Build Coastguard Worker        // as prebuilt_etc doesn't have the equivalent of device_common_srcs.
199*795d594fSAndroid Build Coastguard Worker        filegroup {{
200*795d594fSAndroid Build Coastguard Worker            name: "{name}-fg",
201*795d594fSAndroid Build Coastguard Worker            device_common_srcs: [":{name}-tmp"],
202*795d594fSAndroid Build Coastguard Worker        }}
203*795d594fSAndroid Build Coastguard Worker
204*795d594fSAndroid Build Coastguard Worker        // Phony target used to install all shards
205*795d594fSAndroid Build Coastguard Worker        prebuilt_etc_host {{
206*795d594fSAndroid Build Coastguard Worker            name: "{name}",
207*795d594fSAndroid Build Coastguard Worker            src: ":{name}-fg",
208*795d594fSAndroid Build Coastguard Worker            required: [
209*795d594fSAndroid Build Coastguard Worker                {deps}
210*795d594fSAndroid Build Coastguard Worker            ],
211*795d594fSAndroid Build Coastguard Worker            sub_dir: "art",
212*795d594fSAndroid Build Coastguard Worker            filename: "{name}.txt",
213*795d594fSAndroid Build Coastguard Worker        }}
214*795d594fSAndroid Build Coastguard Worker        """))
215*795d594fSAndroid Build Coastguard Worker
216*795d594fSAndroid Build Coastguard Workerif __name__ == "__main__":
217*795d594fSAndroid Build Coastguard Worker  main()
218