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 | |
| 6 | from os import makedirs, listdir |
| 7 | from os.path import join, exists, isdir |
| 8 | from string import Template, upper |
| 9 | from sys import exit |
| 10 | from shutil import rmtree |
| 11 | |
| 12 | OUTPUT_DIR = "build/generated/test/java/com/android/tools/r8/art" |
mikaelpeltier | 962da33 | 2017-08-18 11:40:55 +0200 | [diff] [blame] | 13 | TEST_DIR = "tests/2017-07-27/art" |
Mads Ager | 7e5bd72 | 2017-05-24 07:17:27 +0200 | [diff] [blame] | 14 | TOOLCHAINS = ["dx", "jack", "none"] |
| 15 | TOOLS = ["r8", "d8"] |
| 16 | TEMPLATE = 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. |
| 20 | package com.android.tools.r8.art.$testGeneratingToolchain.$compilerUnderTest; |
| 21 | |
| 22 | import static com.android.tools.r8.R8RunArtTestsTest.DexTool.$testGeneratingToolchainEnum; |
| 23 | |
| 24 | import com.android.tools.r8.R8RunArtTestsTest; |
| 25 | import 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 | */ |
| 32 | public 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 | |
| 47 | def 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 | |
| 54 | def 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 | |
| 59 | def 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: |
Tamas Kenez | c41d304 | 2017-06-01 17:26:08 +0200 | [diff] [blame] | 66 | if tool == "d8" and toolchain == "none": |
Tamas Kenez | 070843c | 2017-06-02 11:52:59 +0200 | [diff] [blame] | 67 | tool_enum = 'R8_AFTER_D8' |
Tamas Kenez | c41d304 | 2017-06-01 17:26:08 +0200 | [diff] [blame] | 68 | else: |
| 69 | tool_enum = upper(tool) |
Mads Ager | 7e5bd72 | 2017-05-24 07:17:27 +0200 | [diff] [blame] | 70 | contents = TEMPLATE.substitute( |
| 71 | name=dir, |
Tamas Kenez | c41d304 | 2017-06-01 17:26:08 +0200 | [diff] [blame] | 72 | compilerUnderTestEnum=tool_enum, |
Mads Ager | 7e5bd72 | 2017-05-24 07:17:27 +0200 | [diff] [blame] | 73 | compilerUnderTest=tool, |
| 74 | testGeneratingToolchain=toolchain, |
| 75 | testGeneratingToolchainEnum=upper(toolchain), |
| 76 | testClassName=class_name) |
| 77 | write_file(toolchain, tool, class_name, contents) |
| 78 | |
| 79 | |
| 80 | def main(): |
| 81 | for toolchain in TOOLCHAINS: |
| 82 | create_toolchain_dirs(toolchain) |
| 83 | create_tests(toolchain) |
| 84 | |
| 85 | if __name__ == "__main__": |
| 86 | exit(main()) |