blob: 3a83cbc3663228496585fd37663f3c0cbb1647f9 [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
6from os import makedirs, listdir
7from os.path import join, exists, isdir
8from string import Template, upper
9from sys import exit
10from shutil import rmtree
11
12OUTPUT_DIR = "build/generated/test/java/com/android/tools/r8/art"
13TEST_DIR = "tests/art"
14TOOLCHAINS = ["dx", "jack", "none"]
15TOOLS = ["r8", "d8"]
16TEMPLATE = Template(
17"""// Copyright (c) 2016, the R8 project authors. Please see the AUTHORS file
18// for details. All rights reserved. Use of this source code is governed by a
19// BSD-style license that can be found in the LICENSE file.
20package com.android.tools.r8.art.$testGeneratingToolchain.$compilerUnderTest;
21
22import static com.android.tools.r8.R8RunArtTestsTest.DexTool.$testGeneratingToolchainEnum;
23
24import com.android.tools.r8.R8RunArtTestsTest;
25import org.junit.Test;
26
27/**
28 * Auto-generated test for the art $name test using the $testGeneratingToolchain toolchain.
29 *
30 * DO NOT EDIT THIS FILE. EDIT THE HERE DOCUMENT TEMPLATE IN tools/create_art_tests.py INSTEAD!
31 */
32public class $testClassName extends R8RunArtTestsTest {
33
34 public $testClassName() {
35 super("$name", $testGeneratingToolchainEnum);
36 }
37
38 @Test
39 public void run$testClassName() throws Throwable {
40 // For testing with other Art VMs than the default pass the VM version as a argument to
41 // runArtTest, e.g. runArtTest(ToolHelper.ART_4_4_4).
42 runArtTest(CompilerUnderTest.$compilerUnderTestEnum);
43 }
44}
45""")
46
47def create_toolchain_dirs(toolchain):
48 toolchain_dir = join(OUTPUT_DIR, toolchain)
49 if exists(toolchain_dir):
50 rmtree(toolchain_dir)
51 makedirs(join(toolchain_dir, "d8"))
52 makedirs(join(toolchain_dir, "r8"))
53
54def write_file(toolchain, tool, class_name, contents):
55 file_name = join(OUTPUT_DIR, toolchain, tool, class_name + ".java")
56 with open(file_name, "w") as file:
57 file.write(contents)
58
59def create_tests(toolchain):
60 source_dir = join(TEST_DIR, "dx" if toolchain == "none" else toolchain)
61 dirs = [d for d in listdir(source_dir)
62 if isdir(join(source_dir, d))]
63 for dir in dirs:
64 class_name = "Art" + dir.replace("-", "_") + "Test"
65 for tool in TOOLS:
66 contents = TEMPLATE.substitute(
67 name=dir,
68 compilerUnderTestEnum=upper(tool),
69 compilerUnderTest=tool,
70 testGeneratingToolchain=toolchain,
71 testGeneratingToolchainEnum=upper(toolchain),
72 testClassName=class_name)
73 write_file(toolchain, tool, class_name, contents)
74
75
76def main():
77 for toolchain in TOOLCHAINS:
78 create_toolchain_dirs(toolchain)
79 create_tests(toolchain)
80
81if __name__ == "__main__":
82 exit(main())