blob: 248f893c1327ab63b24b542135942d175fa211ac [file] [log] [blame]
Mads Ager7e5bd722017-05-24 07:17:27 +02001#!/usr/bin/env python
2# 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 = [
14 ("dx", os.path.join(TEST_DIR, "dx")),
Mathias Rav6d1a71c2018-04-24 13:35:41 +020015 ("none", os.path.join(TEST_DIR, "dx")),
16]
Mathias Rav88ac49e2018-03-09 13:11:02 +010017TOOLS = ["r8", "d8", "r8cf"]
Mads Ager7e5bd722017-05-24 07:17:27 +020018TEMPLATE = Template(
19"""// Copyright (c) 2016, the R8 project authors. Please see the AUTHORS file
20// for details. All rights reserved. Use of this source code is governed by a
21// BSD-style license that can be found in the LICENSE file.
22package com.android.tools.r8.art.$testGeneratingToolchain.$compilerUnderTest;
23
24import static com.android.tools.r8.R8RunArtTestsTest.DexTool.$testGeneratingToolchainEnum;
25
26import com.android.tools.r8.R8RunArtTestsTest;
27import org.junit.Test;
28
29/**
30 * Auto-generated test for the art $name test using the $testGeneratingToolchain toolchain.
31 *
32 * DO NOT EDIT THIS FILE. EDIT THE HERE DOCUMENT TEMPLATE IN tools/create_art_tests.py INSTEAD!
33 */
34public class $testClassName extends R8RunArtTestsTest {
35
36 public $testClassName() {
37 super("$name", $testGeneratingToolchainEnum);
38 }
39
40 @Test
41 public void run$testClassName() throws Throwable {
42 // For testing with other Art VMs than the default pass the VM version as a argument to
Søren Gjesse8b7cca42018-01-17 11:58:13 +010043 // runArtTest, e.g. runArtTest(DexVm.ART_4_4_4_HOST, CompilerUnderTest.$compilerUnderTestEnum).
Mads Ager7e5bd722017-05-24 07:17:27 +020044 runArtTest(CompilerUnderTest.$compilerUnderTestEnum);
45 }
46}
47""")
48
Mads Ager7e5bd722017-05-24 07:17:27 +020049
Mathias Rav6d1a71c2018-04-24 13:35:41 +020050def get_test_configurations():
51 for toolchain, source_dir in TOOLCHAINS:
Mads Ager7e5bd722017-05-24 07:17:27 +020052 for tool in TOOLS:
Tamas Kenezc41d3042017-06-01 17:26:08 +020053 if tool == "d8" and toolchain == "none":
Tamas Kenez070843c2017-06-02 11:52:59 +020054 tool_enum = 'R8_AFTER_D8'
Tamas Kenezc41d3042017-06-01 17:26:08 +020055 else:
Mathias Rav6d1a71c2018-04-24 13:35:41 +020056 tool_enum = tool.upper()
Mathias Rav88ac49e2018-03-09 13:11:02 +010057 if tool == "r8cf":
58 if toolchain != "none":
59 continue
60 tool_enum = 'D8_AFTER_R8CF'
Mathias Rav6d1a71c2018-04-24 13:35:41 +020061 output_dir = os.path.join(OUTPUT_DIR, toolchain, tool)
62 yield (tool_enum, tool, toolchain, source_dir, output_dir)
63
64
65def create_tests():
66 for tool_enum, tool, toolchain, source_dir, output_dir in get_test_configurations():
67 test_cases = [d for d in os.listdir(source_dir)
68 if os.path.isdir(os.path.join(source_dir, d))]
69 if os.path.exists(output_dir):
70 shutil.rmtree(output_dir)
71 os.makedirs(output_dir)
72 for test_case in test_cases:
73 class_name = "Art" + test_case.replace("-", "_") + "Test"
Mads Ager7e5bd722017-05-24 07:17:27 +020074 contents = TEMPLATE.substitute(
Mathias Rav6d1a71c2018-04-24 13:35:41 +020075 name=test_case,
Tamas Kenezc41d3042017-06-01 17:26:08 +020076 compilerUnderTestEnum=tool_enum,
Mads Ager7e5bd722017-05-24 07:17:27 +020077 compilerUnderTest=tool,
78 testGeneratingToolchain=toolchain,
Mathias Rav6d1a71c2018-04-24 13:35:41 +020079 testGeneratingToolchainEnum=toolchain.upper(),
Mads Ager7e5bd722017-05-24 07:17:27 +020080 testClassName=class_name)
Mathias Rav6d1a71c2018-04-24 13:35:41 +020081 with open(os.path.join(output_dir, class_name + ".java"), "w") as fp:
82 fp.write(contents)
Mads Ager7e5bd722017-05-24 07:17:27 +020083
84
85def main():
Mathias Rav6d1a71c2018-04-24 13:35:41 +020086 create_tests()
87
Mads Ager7e5bd722017-05-24 07:17:27 +020088
89if __name__ == "__main__":
Mathias Rav6d1a71c2018-04-24 13:35:41 +020090 main()