blob: 99e908569e56f1680ebe3a6f4fd835d743a0ca10 [file] [log] [blame]
Ian Zernydcb172e2022-02-22 15:36:45 +01001#!/usr/bin/env python3
Mads Ager7e5bd722017-05-24 07:17:27 +02002# Copyright (c) 2017, the R8 project authors. Please see the AUTHORS file
3# for details. All rights reserved. Use of this source code is governed by a
4# BSD-style license that can be found in the LICENSE file.
5
Jean-Marie Henaffce162f32017-10-04 10:39:27 +02006import os
Mathias Rav6d1a71c2018-04-24 13:35:41 +02007import shutil
8from string import Template
Mads Ager7e5bd722017-05-24 07:17:27 +02009
Jean-Marie Henaffce162f32017-10-04 10:39:27 +020010OUTPUT_DIR = os.path.join('build', 'generated', 'test', 'java', 'com',
11 'android', 'tools', 'r8', 'art')
mikaelpeltierc2aa6652017-10-06 12:53:37 +020012TEST_DIR = os.path.join('tests', '2017-10-04', 'art')
Mathias Rav6d1a71c2018-04-24 13:35:41 +020013TOOLCHAINS = [
Mathias Rav6d1a71c2018-04-24 13:35:41 +020014 ("none", os.path.join(TEST_DIR, "dx")),
15]
Mathias Rav88ac49e2018-03-09 13:11:02 +010016TOOLS = ["r8", "d8", "r8cf"]
Mads Ager7e5bd722017-05-24 07:17:27 +020017TEMPLATE = Template(
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +020018 """// Copyright (c) 2016, the R8 project authors. Please see the AUTHORS file
Mads Ager7e5bd722017-05-24 07:17:27 +020019// for details. All rights reserved. Use of this source code is governed by a
20// BSD-style license that can be found in the LICENSE file.
21package com.android.tools.r8.art.$testGeneratingToolchain.$compilerUnderTest;
22
23import static com.android.tools.r8.R8RunArtTestsTest.DexTool.$testGeneratingToolchainEnum;
24
25import com.android.tools.r8.R8RunArtTestsTest;
Ian Zerny5b878ac2020-09-23 20:48:05 +020026import com.android.tools.r8.TestBase;
27import com.android.tools.r8.TestParameters;
28import com.android.tools.r8.TestParametersCollection;
29import com.android.tools.r8.ToolHelper.DexVm;
Mads Ager7e5bd722017-05-24 07:17:27 +020030import org.junit.Test;
Ian Zerny5b878ac2020-09-23 20:48:05 +020031import org.junit.runner.RunWith;
32import org.junit.runners.Parameterized;
33import org.junit.runners.Parameterized.Parameters;
Mads Ager7e5bd722017-05-24 07:17:27 +020034
35/**
36 * Auto-generated test for the art $name test using the $testGeneratingToolchain toolchain.
37 *
38 * DO NOT EDIT THIS FILE. EDIT THE HERE DOCUMENT TEMPLATE IN tools/create_art_tests.py INSTEAD!
39 */
Ian Zerny5b878ac2020-09-23 20:48:05 +020040@RunWith(Parameterized.class)
Mads Ager7e5bd722017-05-24 07:17:27 +020041public class $testClassName extends R8RunArtTestsTest {
42
Ian Zerny5b878ac2020-09-23 20:48:05 +020043 @Parameters(name = "{0}")
44 public static TestParametersCollection data() {
45 return TestBase.getTestParameters().withDexRuntimes().build();
46 }
47
48 private final TestParameters parameters;
49
50 public $testClassName(TestParameters parameters) {
Mads Ager7e5bd722017-05-24 07:17:27 +020051 super("$name", $testGeneratingToolchainEnum);
Ian Zerny5b878ac2020-09-23 20:48:05 +020052 this.parameters = parameters;
Mads Ager7e5bd722017-05-24 07:17:27 +020053 }
54
55 @Test
Ian Zerny5b878ac2020-09-23 20:48:05 +020056 public void test() throws Throwable {
57 runArtTest(parameters.getRuntime().asDex().getVm(), CompilerUnderTest.$compilerUnderTestEnum);
Mads Ager7e5bd722017-05-24 07:17:27 +020058 }
59}
60""")
61
Mads Ager7e5bd722017-05-24 07:17:27 +020062
Mathias Rav6d1a71c2018-04-24 13:35:41 +020063def get_test_configurations():
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +020064 for toolchain, source_dir in TOOLCHAINS:
65 for tool in TOOLS:
66 if tool == "d8" and toolchain == "none":
67 tool_enum = 'R8_AFTER_D8'
68 else:
69 tool_enum = tool.upper()
70 if tool == "r8cf":
71 if toolchain != "none":
72 continue
73 tool_enum = 'D8_AFTER_R8CF'
74 output_dir = os.path.join(OUTPUT_DIR, toolchain, tool)
75 yield (tool_enum, tool, toolchain, source_dir, output_dir)
Mathias Rav6d1a71c2018-04-24 13:35:41 +020076
77
78def create_tests():
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +020079 for tool_enum, tool, toolchain, source_dir, output_dir in get_test_configurations(
80 ):
81 test_cases = [
82 d for d in os.listdir(source_dir)
83 if os.path.isdir(os.path.join(source_dir, d))
84 ]
85 if os.path.exists(output_dir):
86 shutil.rmtree(output_dir)
87 os.makedirs(output_dir)
88 for test_case in test_cases:
89 class_name = "Art" + test_case.replace("-", "_") + "Test"
90 contents = TEMPLATE.substitute(
91 name=test_case,
92 compilerUnderTestEnum=tool_enum,
93 compilerUnderTest=tool,
94 testGeneratingToolchain=toolchain,
95 testGeneratingToolchainEnum=toolchain.upper(),
96 testClassName=class_name)
97 with open(os.path.join(output_dir, class_name + ".java"),
98 "w") as fp:
99 fp.write(contents)
Mads Ager7e5bd722017-05-24 07:17:27 +0200100
101
102def main():
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200103 create_tests()
Mathias Rav6d1a71c2018-04-24 13:35:41 +0200104
Mads Ager7e5bd722017-05-24 07:17:27 +0200105
106if __name__ == "__main__":
Christoffer Quist Adamsen2434a4d2023-10-16 11:29:03 +0200107 main()