Mads Ager | 7e5bd72 | 2017-05-24 07:17:27 +0200 | [diff] [blame] | 1 | #!/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 Henaff | ce162f3 | 2017-10-04 10:39:27 +0200 | [diff] [blame] | 6 | import os |
Mads Ager | 7e5bd72 | 2017-05-24 07:17:27 +0200 | [diff] [blame] | 7 | from os import makedirs, listdir |
| 8 | from os.path import join, exists, isdir |
| 9 | from string import Template, upper |
| 10 | from sys import exit |
| 11 | from shutil import rmtree |
| 12 | |
Jean-Marie Henaff | ce162f3 | 2017-10-04 10:39:27 +0200 | [diff] [blame] | 13 | OUTPUT_DIR = os.path.join('build', 'generated', 'test', 'java', 'com', |
| 14 | 'android', 'tools', 'r8', 'art') |
mikaelpeltier | c2aa665 | 2017-10-06 12:53:37 +0200 | [diff] [blame] | 15 | # Test that comes from Jack are generated from the legacy snapshot. |
| 16 | JACK_TEST = os.path.join('tests', '2016-12-19', 'art') |
| 17 | TEST_DIR = os.path.join('tests', '2017-10-04', 'art') |
Mads Ager | 7e5bd72 | 2017-05-24 07:17:27 +0200 | [diff] [blame] | 18 | TOOLCHAINS = ["dx", "jack", "none"] |
Rico Wind | c872f06 | 2018-03-07 16:59:34 +0000 | [diff] [blame] | 19 | TOOLS = ["r8", "d8"] |
Mads Ager | 7e5bd72 | 2017-05-24 07:17:27 +0200 | [diff] [blame] | 20 | TEMPLATE = 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. |
| 24 | package com.android.tools.r8.art.$testGeneratingToolchain.$compilerUnderTest; |
| 25 | |
| 26 | import static com.android.tools.r8.R8RunArtTestsTest.DexTool.$testGeneratingToolchainEnum; |
| 27 | |
| 28 | import com.android.tools.r8.R8RunArtTestsTest; |
| 29 | import 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 | */ |
| 36 | public 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 Gjesse | 8b7cca4 | 2018-01-17 11:58:13 +0100 | [diff] [blame] | 45 | // runArtTest, e.g. runArtTest(DexVm.ART_4_4_4_HOST, CompilerUnderTest.$compilerUnderTestEnum). |
Mads Ager | 7e5bd72 | 2017-05-24 07:17:27 +0200 | [diff] [blame] | 46 | runArtTest(CompilerUnderTest.$compilerUnderTestEnum); |
| 47 | } |
| 48 | } |
| 49 | """) |
| 50 | |
| 51 | def 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 | |
| 58 | def 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 | |
| 63 | def create_tests(toolchain): |
| 64 | source_dir = join(TEST_DIR, "dx" if toolchain == "none" else toolchain) |
mikaelpeltier | c2aa665 | 2017-10-06 12:53:37 +0200 | [diff] [blame] | 65 | # For the toolchain "jack" tests are generated from a previous snapshot. |
| 66 | if (toolchain == "jack"): |
| 67 | source_dir = join(JACK_TEST, toolchain) |
Mads Ager | 7e5bd72 | 2017-05-24 07:17:27 +0200 | [diff] [blame] | 68 | 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 Kenez | c41d304 | 2017-06-01 17:26:08 +0200 | [diff] [blame] | 73 | if tool == "d8" and toolchain == "none": |
Tamas Kenez | 070843c | 2017-06-02 11:52:59 +0200 | [diff] [blame] | 74 | tool_enum = 'R8_AFTER_D8' |
Tamas Kenez | c41d304 | 2017-06-01 17:26:08 +0200 | [diff] [blame] | 75 | else: |
| 76 | tool_enum = upper(tool) |
Mads Ager | 7e5bd72 | 2017-05-24 07:17:27 +0200 | [diff] [blame] | 77 | contents = TEMPLATE.substitute( |
| 78 | name=dir, |
Tamas Kenez | c41d304 | 2017-06-01 17:26:08 +0200 | [diff] [blame] | 79 | compilerUnderTestEnum=tool_enum, |
Mads Ager | 7e5bd72 | 2017-05-24 07:17:27 +0200 | [diff] [blame] | 80 | compilerUnderTest=tool, |
| 81 | testGeneratingToolchain=toolchain, |
| 82 | testGeneratingToolchainEnum=upper(toolchain), |
| 83 | testClassName=class_name) |
| 84 | write_file(toolchain, tool, class_name, contents) |
| 85 | |
| 86 | |
| 87 | def main(): |
| 88 | for toolchain in TOOLCHAINS: |
| 89 | create_toolchain_dirs(toolchain) |
| 90 | create_tests(toolchain) |
| 91 | |
| 92 | if __name__ == "__main__": |
| 93 | exit(main()) |