1// Copyright 2017, VIXL authors 2// All rights reserved. 3// 4// Redistribution and use in source and binary forms, with or without 5// modification, are permitted provided that the following conditions are met: 6// 7// * Redistributions of source code must retain the above copyright notice, 8// this list of conditions and the following disclaimer. 9// * Redistributions in binary form must reproduce the above copyright notice, 10// this list of conditions and the following disclaimer in the documentation 11// and/or other materials provided with the distribution. 12// * Neither the name of ARM Limited nor the names of its contributors may be 13// used to endorse or promote products derived from this software without 14// specific prior written permission. 15// 16// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS CONTRIBUTORS "AS IS" AND 17// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 20// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 23// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 27/// This file is a template read by tools/generate_tests.py, it isn't valid C++ 28/// as it is. Variables written as ${substitute_me} are replaced by the script. 29/// Comments starting with three forward slashes such as this one are also 30/// removed. 31 32${do_not_edit_comment} 33 34#include <map> 35 36#include "test-runner.h" 37 38#include "test-utils.h" 39 40#include "aarch32/macro-assembler-aarch32.h" 41 42#define BUF_SIZE (4096) 43 44namespace vixl { 45namespace aarch32 { 46 47// List of instruction mnemonics. 48#define FOREACH_INSTRUCTION(M) \ 49 ${instruction_list_declaration} 50 51// The following definitions are defined again in each generated test, therefore 52// we need to place them in an anomymous namespace. It expresses that they are 53// local to this file only, and the compiler is not allowed to share these types 54// across test files during template instantiation. Specifically, `Operands` has 55// various layouts across generated tests so it absolutely cannot be shared. 56 57#ifdef ${isa_guard} 58namespace { 59 60// Values to be passed to the assembler to produce the instruction under test. 61struct Operands { 62 ${operand_list_declaration} 63}; 64 65// This structure contains all data needed to test one specific 66// instruction. 67struct TestData { 68 // The `operands` field represents what to pass to the assembler to 69 // produce the instruction. 70 Operands operands; 71 // Description of the operands, used for error reporting. 72 const char* operands_description; 73 // Unique identifier, used for generating traces. 74 const char* identifier; 75}; 76 77#ifdef VIXL_NEGATIVE_TESTING 78// Each element of this array produce one instruction encoding. 79const TestData kTests[] = {${test_case_definitions}}; 80#endif 81 82typedef void (MacroAssembler::*Fn)(${macroassembler_method_args}); 83 84#ifdef VIXL_NEGATIVE_TESTING 85void TestHelper(Fn instruction, const char* mnemonic) { 86 for (unsigned i = 0; i < ARRAY_SIZE(kTests); i++) { 87 MacroAssembler masm(BUF_SIZE); 88 ${macroassembler_set_isa} 89 90 // Values to pass to the assembler. 91 ${code_instantiate_operands} 92 93 try { 94 { 95 ExactAssemblyScope scope(&masm, 4, ExactAssemblyScope::kMaximumSize); 96 (masm.*instruction)(${code_parameter_list}); 97 } 98 printf("\nNegative test for: %s\n", mnemonic); 99 printf("%s:%d:%s\nNo exception raised.\n", 100 __FILE__, 101 __LINE__, 102 masm.IsUsingT32() ? "T32" : "A32"); 103 abort(); 104 } catch (const std::runtime_error&) { 105 // Nothing to do, test passed. 106 // TODO: Consider checking the error message here, if possible. 107 } 108 } 109} 110#else 111void TestHelper(Fn, const char*) { 112 printf("Skipping negative tests. To enable them, build with" 113 " 'negative_testing=on'.\n"); 114} 115#endif 116 117// Instantiate tests for each instruction in the list. 118#define TEST(mnemonic) \ 119 void Test_##mnemonic() { \ 120 TestHelper(&MacroAssembler::mnemonic, #mnemonic); \ 121 } \ 122 Test test_##mnemonic("AARCH32_${test_name}_" #mnemonic "_${test_isa}", \ 123 &Test_##mnemonic); 124FOREACH_INSTRUCTION(TEST) 125#undef TEST 126 127} // namespace 128#endif 129 130} // namespace aarch32 131} // namespace vixl 132