blob: 61db8a8cde1997b32f552d649afd682b5a3e9b7f [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 +020012# Test that comes from Jack are generated from the legacy snapshot.
13JACK_TEST = os.path.join('tests', '2016-12-19', 'art')
14TEST_DIR = os.path.join('tests', '2017-10-04', 'art')
Mathias Rav6d1a71c2018-04-24 13:35:41 +020015TOOLCHAINS = [
16 ("dx", os.path.join(TEST_DIR, "dx")),
17 ("jack", os.path.join(JACK_TEST, "jack")),
18 ("none", os.path.join(TEST_DIR, "dx")),
19]
Mathias Rav88ac49e2018-03-09 13:11:02 +010020TOOLS = ["r8", "d8", "r8cf"]
Mads Ager7e5bd722017-05-24 07:17:27 +020021TEMPLATE = Template(
22"""// Copyright (c) 2016, the R8 project authors. Please see the AUTHORS file
23// for details. All rights reserved. Use of this source code is governed by a
24// BSD-style license that can be found in the LICENSE file.
25package com.android.tools.r8.art.$testGeneratingToolchain.$compilerUnderTest;
26
27import static com.android.tools.r8.R8RunArtTestsTest.DexTool.$testGeneratingToolchainEnum;
28
29import com.android.tools.r8.R8RunArtTestsTest;
30import org.junit.Test;
31
32/**
33 * Auto-generated test for the art $name test using the $testGeneratingToolchain toolchain.
34 *
35 * DO NOT EDIT THIS FILE. EDIT THE HERE DOCUMENT TEMPLATE IN tools/create_art_tests.py INSTEAD!
36 */
37public class $testClassName extends R8RunArtTestsTest {
38
39 public $testClassName() {
40 super("$name", $testGeneratingToolchainEnum);
41 }
42
43 @Test
44 public void run$testClassName() throws Throwable {
45 // 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 +010046 // runArtTest, e.g. runArtTest(DexVm.ART_4_4_4_HOST, CompilerUnderTest.$compilerUnderTestEnum).
Mads Ager7e5bd722017-05-24 07:17:27 +020047 runArtTest(CompilerUnderTest.$compilerUnderTestEnum);
48 }
49}
50""")
51
Mads Ager7e5bd722017-05-24 07:17:27 +020052
Mathias Rav6d1a71c2018-04-24 13:35:41 +020053def get_test_configurations():
54 for toolchain, source_dir in TOOLCHAINS:
Mads Ager7e5bd722017-05-24 07:17:27 +020055 for tool in TOOLS:
Tamas Kenezc41d3042017-06-01 17:26:08 +020056 if tool == "d8" and toolchain == "none":
Tamas Kenez070843c2017-06-02 11:52:59 +020057 tool_enum = 'R8_AFTER_D8'
Tamas Kenezc41d3042017-06-01 17:26:08 +020058 else:
Mathias Rav6d1a71c2018-04-24 13:35:41 +020059 tool_enum = tool.upper()
Mathias Rav88ac49e2018-03-09 13:11:02 +010060 if tool == "r8cf":
61 if toolchain != "none":
62 continue
63 tool_enum = 'D8_AFTER_R8CF'
Mathias Rav6d1a71c2018-04-24 13:35:41 +020064 output_dir = os.path.join(OUTPUT_DIR, toolchain, tool)
65 yield (tool_enum, tool, toolchain, source_dir, output_dir)
66
67
68def create_tests():
69 for tool_enum, tool, toolchain, source_dir, output_dir in get_test_configurations():
70 test_cases = [d for d in os.listdir(source_dir)
71 if os.path.isdir(os.path.join(source_dir, d))]
72 if os.path.exists(output_dir):
73 shutil.rmtree(output_dir)
74 os.makedirs(output_dir)
75 for test_case in test_cases:
76 class_name = "Art" + test_case.replace("-", "_") + "Test"
Mads Ager7e5bd722017-05-24 07:17:27 +020077 contents = TEMPLATE.substitute(
Mathias Rav6d1a71c2018-04-24 13:35:41 +020078 name=test_case,
Tamas Kenezc41d3042017-06-01 17:26:08 +020079 compilerUnderTestEnum=tool_enum,
Mads Ager7e5bd722017-05-24 07:17:27 +020080 compilerUnderTest=tool,
81 testGeneratingToolchain=toolchain,
Mathias Rav6d1a71c2018-04-24 13:35:41 +020082 testGeneratingToolchainEnum=toolchain.upper(),
Mads Ager7e5bd722017-05-24 07:17:27 +020083 testClassName=class_name)
Mathias Rav6d1a71c2018-04-24 13:35:41 +020084 with open(os.path.join(output_dir, class_name + ".java"), "w") as fp:
85 fp.write(contents)
Mads Ager7e5bd722017-05-24 07:17:27 +020086
87
88def main():
Mathias Rav6d1a71c2018-04-24 13:35:41 +020089 create_tests()
90
Mads Ager7e5bd722017-05-24 07:17:27 +020091
92if __name__ == "__main__":
Mathias Rav6d1a71c2018-04-24 13:35:41 +020093 main()