blob: feb36a2f71997168f323e5f52e247cc0a54cf71d [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
Mads Ager7e5bd722017-05-24 07:17:27 +02007from os import makedirs, listdir
8from os.path import join, exists, isdir
9from string import Template, upper
10from sys import exit
11from shutil import rmtree
12
Jean-Marie Henaffce162f32017-10-04 10:39:27 +020013OUTPUT_DIR = os.path.join('build', 'generated', 'test', 'java', 'com',
14 'android', 'tools', 'r8', 'art')
mikaelpeltierc2aa6652017-10-06 12:53:37 +020015# Test that comes from Jack are generated from the legacy snapshot.
16JACK_TEST = os.path.join('tests', '2016-12-19', 'art')
17TEST_DIR = os.path.join('tests', '2017-10-04', 'art')
Mads Ager7e5bd722017-05-24 07:17:27 +020018TOOLCHAINS = ["dx", "jack", "none"]
Rico Windc872f062018-03-07 16:59:34 +000019TOOLS = ["r8", "d8"]
Mads Ager7e5bd722017-05-24 07:17:27 +020020TEMPLATE = Template(
21"""// Copyright (c) 2016, the R8 project authors. Please see the AUTHORS file
22// for details. All rights reserved. Use of this source code is governed by a
23// BSD-style license that can be found in the LICENSE file.
24package com.android.tools.r8.art.$testGeneratingToolchain.$compilerUnderTest;
25
26import static com.android.tools.r8.R8RunArtTestsTest.DexTool.$testGeneratingToolchainEnum;
27
28import com.android.tools.r8.R8RunArtTestsTest;
29import org.junit.Test;
30
31/**
32 * Auto-generated test for the art $name test using the $testGeneratingToolchain toolchain.
33 *
34 * DO NOT EDIT THIS FILE. EDIT THE HERE DOCUMENT TEMPLATE IN tools/create_art_tests.py INSTEAD!
35 */
36public class $testClassName extends R8RunArtTestsTest {
37
38 public $testClassName() {
39 super("$name", $testGeneratingToolchainEnum);
40 }
41
42 @Test
43 public void run$testClassName() throws Throwable {
44 // 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 +010045 // runArtTest, e.g. runArtTest(DexVm.ART_4_4_4_HOST, CompilerUnderTest.$compilerUnderTestEnum).
Mads Ager7e5bd722017-05-24 07:17:27 +020046 runArtTest(CompilerUnderTest.$compilerUnderTestEnum);
47 }
48}
49""")
50
51def create_toolchain_dirs(toolchain):
52 toolchain_dir = join(OUTPUT_DIR, toolchain)
53 if exists(toolchain_dir):
54 rmtree(toolchain_dir)
55 makedirs(join(toolchain_dir, "d8"))
56 makedirs(join(toolchain_dir, "r8"))
57
58def write_file(toolchain, tool, class_name, contents):
59 file_name = join(OUTPUT_DIR, toolchain, tool, class_name + ".java")
60 with open(file_name, "w") as file:
61 file.write(contents)
62
63def create_tests(toolchain):
64 source_dir = join(TEST_DIR, "dx" if toolchain == "none" else toolchain)
mikaelpeltierc2aa6652017-10-06 12:53:37 +020065 # For the toolchain "jack" tests are generated from a previous snapshot.
66 if (toolchain == "jack"):
67 source_dir = join(JACK_TEST, toolchain)
Mads Ager7e5bd722017-05-24 07:17:27 +020068 dirs = [d for d in listdir(source_dir)
69 if isdir(join(source_dir, d))]
70 for dir in dirs:
71 class_name = "Art" + dir.replace("-", "_") + "Test"
72 for tool in TOOLS:
Tamas Kenezc41d3042017-06-01 17:26:08 +020073 if tool == "d8" and toolchain == "none":
Tamas Kenez070843c2017-06-02 11:52:59 +020074 tool_enum = 'R8_AFTER_D8'
Tamas Kenezc41d3042017-06-01 17:26:08 +020075 else:
76 tool_enum = upper(tool)
Mads Ager7e5bd722017-05-24 07:17:27 +020077 contents = TEMPLATE.substitute(
78 name=dir,
Tamas Kenezc41d3042017-06-01 17:26:08 +020079 compilerUnderTestEnum=tool_enum,
Mads Ager7e5bd722017-05-24 07:17:27 +020080 compilerUnderTest=tool,
81 testGeneratingToolchain=toolchain,
82 testGeneratingToolchainEnum=upper(toolchain),
83 testClassName=class_name)
84 write_file(toolchain, tool, class_name, contents)
85
86
87def main():
88 for toolchain in TOOLCHAINS:
89 create_toolchain_dirs(toolchain)
90 create_tests(toolchain)
91
92if __name__ == "__main__":
93 exit(main())