1 // Copyright 2014, 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 #ifndef TEST_TEST_H_ 28 #define TEST_TEST_H_ 29 30 #include "utils-vixl.h" 31 32 #include "aarch64/instructions-aarch64.h" 33 34 namespace vixl { 35 36 // Each test is represented by a Test instance. 37 // Tests are appended to a static linked list upon creation. 38 class Test { 39 typedef void(TestFunction)(); 40 typedef void(TestFunctionWithConfig)(Test* config); 41 42 public: 43 // Most tests require no per-test configuration, and so take no arguments. A 44 // few tests require dynamic configuration, and are passed a `Test` object. 45 template <typename Fn> Test(const char* name, Fn* callback)46 Test(const char* name, Fn* callback) 47 : name_(name), sve_vl_(aarch64::kZRegMinSize), next_(NULL) { 48 set_callback(callback); 49 // Append this test to the linked list. 50 if (first_ == NULL) { 51 VIXL_ASSERT(last_ == NULL); 52 first_ = this; 53 } else { 54 last_->next_ = this; 55 } 56 last_ = this; 57 } 58 MakeSVETest(int vl, const char* name, TestFunctionWithConfig* fn)59 static Test* MakeSVETest(int vl, 60 const char* name, 61 TestFunctionWithConfig* fn) { 62 // We never free this memory, but we need it to live for as long as the 63 // static 64 // linked list of tests, and this is the easiest way to do it. 65 Test* test = new Test(name, fn); 66 test->set_sve_vl_in_bits(vl); 67 return test; 68 } 69 name()70 const char* name() { return name_; } 71 void run(); 72 73 // The SVE vector length can be configured by each test, based on either 74 // hardware feature detection (in the test itself) or Simulator configuration. sve_vl_in_bits() const75 int sve_vl_in_bits() const { return sve_vl_; } set_sve_vl_in_bits(unsigned sve_vl)76 void set_sve_vl_in_bits(unsigned sve_vl) { 77 VIXL_ASSERT(sve_vl >= aarch64::kZRegMinSize); 78 VIXL_ASSERT(sve_vl <= aarch64::kZRegMaxSize); 79 VIXL_ASSERT((sve_vl % aarch64::kZRegMinSize) == 0); 80 sve_vl_ = sve_vl; 81 } 82 sve_vl_in_bytes() const83 int sve_vl_in_bytes() const { 84 VIXL_ASSERT((sve_vl_ % kBitsPerByte) == 0); 85 return sve_vl_ / kBitsPerByte; 86 } 87 first()88 static Test* first() { return first_; } last()89 static Test* last() { return last_; } next()90 Test* next() { return next_; } verbose()91 static bool verbose() { return verbose_; } set_verbose(bool value)92 static void set_verbose(bool value) { verbose_ = value; } trace_sim()93 static bool trace_sim() { return trace_sim_; } set_trace_sim(bool value)94 static void set_trace_sim(bool value) { trace_sim_ = value; } trace_reg()95 static bool trace_reg() { return trace_reg_; } set_trace_reg(bool value)96 static void set_trace_reg(bool value) { trace_reg_ = value; } trace_write()97 static bool trace_write() { return trace_write_; } set_trace_write(bool value)98 static void set_trace_write(bool value) { trace_write_ = value; } trace_branch()99 static bool trace_branch() { return trace_branch_; } set_trace_branch(bool value)100 static void set_trace_branch(bool value) { trace_branch_ = value; } disassemble()101 static bool disassemble() { return disassemble_; } set_disassemble(bool value)102 static void set_disassemble(bool value) { disassemble_ = value; } disassemble_infrastructure()103 static bool disassemble_infrastructure() { 104 return disassemble_infrastructure_; 105 } set_disassemble_infrastructure(bool value)106 static void set_disassemble_infrastructure(bool value) { 107 disassemble_infrastructure_ = value; 108 } coloured_trace()109 static bool coloured_trace() { return coloured_trace_; } set_coloured_trace(bool value)110 static void set_coloured_trace(bool value) { coloured_trace_ = value; } generate_test_trace()111 static bool generate_test_trace() { return generate_test_trace_; } set_generate_test_trace(bool value)112 static void set_generate_test_trace(bool value) { 113 generate_test_trace_ = value; 114 } 115 116 private: 117 const char* name_; 118 119 TestFunction* callback_; 120 TestFunctionWithConfig* callback_with_config_; 121 122 void set_callback(TestFunction* callback); 123 void set_callback(TestFunctionWithConfig* callback); 124 125 int sve_vl_; 126 127 static Test* first_; 128 static Test* last_; 129 Test* next_; 130 static bool verbose_; 131 static bool trace_sim_; 132 static bool trace_reg_; 133 static bool trace_write_; 134 static bool trace_branch_; 135 static bool disassemble_; 136 static bool disassemble_infrastructure_; 137 static bool coloured_trace_; 138 static bool generate_test_trace_; 139 }; 140 141 // Define helper macros for test files. 142 143 // Macro to register a test. It instantiates a Test and registers its 144 // callback function. 145 #define TEST_(Name) \ 146 void Test##Name(); \ 147 Test test_##Name(#Name, &Test##Name); \ 148 void Test##Name() 149 } // namespace vixl 150 151 #endif // TEST_TEST_H_ 152