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 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/2017-07-07/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 if tool == "d8" and toolchain == "none": 67 tool_enum = 'R8_AFTER_D8' 68 else: 69 tool_enum = upper(tool) 70 contents = TEMPLATE.substitute( 71 name=dir, 72 compilerUnderTestEnum=tool_enum, 73 compilerUnderTest=tool, 74 testGeneratingToolchain=toolchain, 75 testGeneratingToolchainEnum=upper(toolchain), 76 testClassName=class_name) 77 write_file(toolchain, tool, class_name, contents) 78 79 80def main(): 81 for toolchain in TOOLCHAINS: 82 create_toolchain_dirs(toolchain) 83 create_tests(toolchain) 84 85if __name__ == "__main__": 86 exit(main()) 87