17e5bd72e92445ba11c0ad0d6a969b04c72f06cbaMads Ager#!/usr/bin/env python 27e5bd72e92445ba11c0ad0d6a969b04c72f06cbaMads Ager# Copyright (c) 2017, the R8 project authors. Please see the AUTHORS file 37e5bd72e92445ba11c0ad0d6a969b04c72f06cbaMads Ager# for details. All rights reserved. Use of this source code is governed by a 47e5bd72e92445ba11c0ad0d6a969b04c72f06cbaMads Ager# BSD-style license that can be found in the LICENSE file. 57e5bd72e92445ba11c0ad0d6a969b04c72f06cbaMads Ager 67e5bd72e92445ba11c0ad0d6a969b04c72f06cbaMads Agerfrom os import makedirs, listdir 77e5bd72e92445ba11c0ad0d6a969b04c72f06cbaMads Agerfrom os.path import join, exists, isdir 87e5bd72e92445ba11c0ad0d6a969b04c72f06cbaMads Agerfrom string import Template, upper 97e5bd72e92445ba11c0ad0d6a969b04c72f06cbaMads Agerfrom sys import exit 107e5bd72e92445ba11c0ad0d6a969b04c72f06cbaMads Agerfrom shutil import rmtree 117e5bd72e92445ba11c0ad0d6a969b04c72f06cbaMads Ager 127e5bd72e92445ba11c0ad0d6a969b04c72f06cbaMads AgerOUTPUT_DIR = "build/generated/test/java/com/android/tools/r8/art" 1334b777388424f74036e1f600301ed8c1b16e4bdcSøren GjesseTEST_DIR = "tests/2017-07-07/art" 147e5bd72e92445ba11c0ad0d6a969b04c72f06cbaMads AgerTOOLCHAINS = ["dx", "jack", "none"] 157e5bd72e92445ba11c0ad0d6a969b04c72f06cbaMads AgerTOOLS = ["r8", "d8"] 167e5bd72e92445ba11c0ad0d6a969b04c72f06cbaMads AgerTEMPLATE = Template( 177e5bd72e92445ba11c0ad0d6a969b04c72f06cbaMads Ager"""// Copyright (c) 2016, the R8 project authors. Please see the AUTHORS file 187e5bd72e92445ba11c0ad0d6a969b04c72f06cbaMads Ager// for details. All rights reserved. Use of this source code is governed by a 197e5bd72e92445ba11c0ad0d6a969b04c72f06cbaMads Ager// BSD-style license that can be found in the LICENSE file. 207e5bd72e92445ba11c0ad0d6a969b04c72f06cbaMads Agerpackage com.android.tools.r8.art.$testGeneratingToolchain.$compilerUnderTest; 217e5bd72e92445ba11c0ad0d6a969b04c72f06cbaMads Ager 227e5bd72e92445ba11c0ad0d6a969b04c72f06cbaMads Agerimport static com.android.tools.r8.R8RunArtTestsTest.DexTool.$testGeneratingToolchainEnum; 237e5bd72e92445ba11c0ad0d6a969b04c72f06cbaMads Ager 247e5bd72e92445ba11c0ad0d6a969b04c72f06cbaMads Agerimport com.android.tools.r8.R8RunArtTestsTest; 257e5bd72e92445ba11c0ad0d6a969b04c72f06cbaMads Agerimport org.junit.Test; 267e5bd72e92445ba11c0ad0d6a969b04c72f06cbaMads Ager 277e5bd72e92445ba11c0ad0d6a969b04c72f06cbaMads Ager/** 287e5bd72e92445ba11c0ad0d6a969b04c72f06cbaMads Ager * Auto-generated test for the art $name test using the $testGeneratingToolchain toolchain. 297e5bd72e92445ba11c0ad0d6a969b04c72f06cbaMads Ager * 307e5bd72e92445ba11c0ad0d6a969b04c72f06cbaMads Ager * DO NOT EDIT THIS FILE. EDIT THE HERE DOCUMENT TEMPLATE IN tools/create_art_tests.py INSTEAD! 317e5bd72e92445ba11c0ad0d6a969b04c72f06cbaMads Ager */ 327e5bd72e92445ba11c0ad0d6a969b04c72f06cbaMads Agerpublic class $testClassName extends R8RunArtTestsTest { 337e5bd72e92445ba11c0ad0d6a969b04c72f06cbaMads Ager 347e5bd72e92445ba11c0ad0d6a969b04c72f06cbaMads Ager public $testClassName() { 357e5bd72e92445ba11c0ad0d6a969b04c72f06cbaMads Ager super("$name", $testGeneratingToolchainEnum); 367e5bd72e92445ba11c0ad0d6a969b04c72f06cbaMads Ager } 377e5bd72e92445ba11c0ad0d6a969b04c72f06cbaMads Ager 387e5bd72e92445ba11c0ad0d6a969b04c72f06cbaMads Ager @Test 397e5bd72e92445ba11c0ad0d6a969b04c72f06cbaMads Ager public void run$testClassName() throws Throwable { 407e5bd72e92445ba11c0ad0d6a969b04c72f06cbaMads Ager // For testing with other Art VMs than the default pass the VM version as a argument to 417e5bd72e92445ba11c0ad0d6a969b04c72f06cbaMads Ager // runArtTest, e.g. runArtTest(ToolHelper.ART_4_4_4). 427e5bd72e92445ba11c0ad0d6a969b04c72f06cbaMads Ager runArtTest(CompilerUnderTest.$compilerUnderTestEnum); 437e5bd72e92445ba11c0ad0d6a969b04c72f06cbaMads Ager } 447e5bd72e92445ba11c0ad0d6a969b04c72f06cbaMads Ager} 457e5bd72e92445ba11c0ad0d6a969b04c72f06cbaMads Ager""") 467e5bd72e92445ba11c0ad0d6a969b04c72f06cbaMads Ager 477e5bd72e92445ba11c0ad0d6a969b04c72f06cbaMads Agerdef create_toolchain_dirs(toolchain): 487e5bd72e92445ba11c0ad0d6a969b04c72f06cbaMads Ager toolchain_dir = join(OUTPUT_DIR, toolchain) 497e5bd72e92445ba11c0ad0d6a969b04c72f06cbaMads Ager if exists(toolchain_dir): 507e5bd72e92445ba11c0ad0d6a969b04c72f06cbaMads Ager rmtree(toolchain_dir) 517e5bd72e92445ba11c0ad0d6a969b04c72f06cbaMads Ager makedirs(join(toolchain_dir, "d8")) 527e5bd72e92445ba11c0ad0d6a969b04c72f06cbaMads Ager makedirs(join(toolchain_dir, "r8")) 537e5bd72e92445ba11c0ad0d6a969b04c72f06cbaMads Ager 547e5bd72e92445ba11c0ad0d6a969b04c72f06cbaMads Agerdef write_file(toolchain, tool, class_name, contents): 557e5bd72e92445ba11c0ad0d6a969b04c72f06cbaMads Ager file_name = join(OUTPUT_DIR, toolchain, tool, class_name + ".java") 567e5bd72e92445ba11c0ad0d6a969b04c72f06cbaMads Ager with open(file_name, "w") as file: 577e5bd72e92445ba11c0ad0d6a969b04c72f06cbaMads Ager file.write(contents) 587e5bd72e92445ba11c0ad0d6a969b04c72f06cbaMads Ager 597e5bd72e92445ba11c0ad0d6a969b04c72f06cbaMads Agerdef create_tests(toolchain): 607e5bd72e92445ba11c0ad0d6a969b04c72f06cbaMads Ager source_dir = join(TEST_DIR, "dx" if toolchain == "none" else toolchain) 617e5bd72e92445ba11c0ad0d6a969b04c72f06cbaMads Ager dirs = [d for d in listdir(source_dir) 627e5bd72e92445ba11c0ad0d6a969b04c72f06cbaMads Ager if isdir(join(source_dir, d))] 637e5bd72e92445ba11c0ad0d6a969b04c72f06cbaMads Ager for dir in dirs: 647e5bd72e92445ba11c0ad0d6a969b04c72f06cbaMads Ager class_name = "Art" + dir.replace("-", "_") + "Test" 657e5bd72e92445ba11c0ad0d6a969b04c72f06cbaMads Ager for tool in TOOLS: 66c41d304b166cc829dab0a9394b2b45aaa6fdc84eTamas Kenez if tool == "d8" and toolchain == "none": 67070843c96b9e96bec61c9f8aec7c6b09cda163e2Tamas Kenez tool_enum = 'R8_AFTER_D8' 68c41d304b166cc829dab0a9394b2b45aaa6fdc84eTamas Kenez else: 69c41d304b166cc829dab0a9394b2b45aaa6fdc84eTamas Kenez tool_enum = upper(tool) 707e5bd72e92445ba11c0ad0d6a969b04c72f06cbaMads Ager contents = TEMPLATE.substitute( 717e5bd72e92445ba11c0ad0d6a969b04c72f06cbaMads Ager name=dir, 72c41d304b166cc829dab0a9394b2b45aaa6fdc84eTamas Kenez compilerUnderTestEnum=tool_enum, 737e5bd72e92445ba11c0ad0d6a969b04c72f06cbaMads Ager compilerUnderTest=tool, 747e5bd72e92445ba11c0ad0d6a969b04c72f06cbaMads Ager testGeneratingToolchain=toolchain, 757e5bd72e92445ba11c0ad0d6a969b04c72f06cbaMads Ager testGeneratingToolchainEnum=upper(toolchain), 767e5bd72e92445ba11c0ad0d6a969b04c72f06cbaMads Ager testClassName=class_name) 777e5bd72e92445ba11c0ad0d6a969b04c72f06cbaMads Ager write_file(toolchain, tool, class_name, contents) 787e5bd72e92445ba11c0ad0d6a969b04c72f06cbaMads Ager 797e5bd72e92445ba11c0ad0d6a969b04c72f06cbaMads Ager 807e5bd72e92445ba11c0ad0d6a969b04c72f06cbaMads Agerdef main(): 817e5bd72e92445ba11c0ad0d6a969b04c72f06cbaMads Ager for toolchain in TOOLCHAINS: 827e5bd72e92445ba11c0ad0d6a969b04c72f06cbaMads Ager create_toolchain_dirs(toolchain) 837e5bd72e92445ba11c0ad0d6a969b04c72f06cbaMads Ager create_tests(toolchain) 847e5bd72e92445ba11c0ad0d6a969b04c72f06cbaMads Ager 857e5bd72e92445ba11c0ad0d6a969b04c72f06cbaMads Agerif __name__ == "__main__": 867e5bd72e92445ba11c0ad0d6a969b04c72f06cbaMads Ager exit(main()) 87