Alexandre Rames | b78f139 | 2016-07-01 14:22:22 +0100 | [diff] [blame] | 1 | // Copyright 2014, VIXL authors |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 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 | |
armvixl | 330dc71 | 2014-11-25 10:38:32 +0000 | [diff] [blame] | 27 | #ifndef TEST_TEST_H_ |
| 28 | #define TEST_TEST_H_ |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 29 | |
Alexandre Rames | 1f9074d | 2016-05-23 15:50:01 +0100 | [diff] [blame] | 30 | #include "utils-vixl.h" |
Jacob Bramley | 9e5da2a | 2019-08-06 18:52:07 +0100 | [diff] [blame] | 31 | #include "aarch64/instructions-aarch64.h" |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 32 | |
| 33 | namespace vixl { |
| 34 | |
armvixl | 330dc71 | 2014-11-25 10:38:32 +0000 | [diff] [blame] | 35 | // Each actual test is represented by a Test instance. |
| 36 | // Tests are appended to a static linked list upon creation. |
| 37 | class Test { |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 38 | public: |
Jacob Bramley | e828920 | 2019-07-31 11:25:23 +0100 | [diff] [blame] | 39 | // Most tests require no per-test configuration, and so take no arguments. A |
| 40 | // few tests require dynamic configuration, and are passed a `Test` object. |
| 41 | template <typename Fn> |
Jacob Bramley | 32a7cd9 | 2020-08-06 18:00:10 +0100 | [diff] [blame] | 42 | Test(const char* name, Fn* callback) |
| 43 | : name_(name), sve_vl_(aarch64::kZRegMinSize), next_(NULL) { |
Jacob Bramley | e828920 | 2019-07-31 11:25:23 +0100 | [diff] [blame] | 44 | set_callback(callback); |
| 45 | // Append this test to the linked list. |
| 46 | if (first_ == NULL) { |
| 47 | VIXL_ASSERT(last_ == NULL); |
| 48 | first_ = this; |
| 49 | } else { |
| 50 | last_->next_ = this; |
| 51 | } |
| 52 | last_ = this; |
| 53 | } |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 54 | |
| 55 | const char* name() { return name_; } |
Jacob Bramley | e828920 | 2019-07-31 11:25:23 +0100 | [diff] [blame] | 56 | void run(); |
| 57 | |
| 58 | // The SVE vector length can be configured by each test, based on either |
| 59 | // hardware feature detection (in the test itself) or Simulator configuration. |
| 60 | int sve_vl_in_bits() const { return sve_vl_; } |
Jacob Bramley | 9e5da2a | 2019-08-06 18:52:07 +0100 | [diff] [blame] | 61 | void set_sve_vl_in_bits(unsigned sve_vl) { |
Jacob Bramley | 32a7cd9 | 2020-08-06 18:00:10 +0100 | [diff] [blame] | 62 | VIXL_ASSERT(sve_vl >= aarch64::kZRegMinSize); |
Jacob Bramley | 9e5da2a | 2019-08-06 18:52:07 +0100 | [diff] [blame] | 63 | VIXL_ASSERT(sve_vl <= aarch64::kZRegMaxSize); |
| 64 | VIXL_ASSERT((sve_vl % aarch64::kZRegMinSize) == 0); |
| 65 | sve_vl_ = sve_vl; |
| 66 | } |
| 67 | |
| 68 | int sve_vl_in_bytes() const { |
| 69 | VIXL_ASSERT((sve_vl_ % kBitsPerByte) == 0); |
| 70 | return sve_vl_ / kBitsPerByte; |
| 71 | } |
Jacob Bramley | e828920 | 2019-07-31 11:25:23 +0100 | [diff] [blame] | 72 | |
armvixl | 330dc71 | 2014-11-25 10:38:32 +0000 | [diff] [blame] | 73 | static Test* first() { return first_; } |
| 74 | static Test* last() { return last_; } |
| 75 | Test* next() { return next_; } |
Georgia Kouveli | 1cb7144 | 2017-01-30 13:35:28 +0000 | [diff] [blame] | 76 | static bool verbose() { return verbose_; } |
| 77 | static void set_verbose(bool value) { verbose_ = value; } |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 78 | static bool trace_sim() { return trace_sim_; } |
| 79 | static void set_trace_sim(bool value) { trace_sim_ = value; } |
| 80 | static bool trace_reg() { return trace_reg_; } |
| 81 | static void set_trace_reg(bool value) { trace_reg_ = value; } |
armvixl | 330dc71 | 2014-11-25 10:38:32 +0000 | [diff] [blame] | 82 | static bool trace_write() { return trace_write_; } |
| 83 | static void set_trace_write(bool value) { trace_write_ = value; } |
Jacob Bramley | e79723a | 2016-06-07 17:50:47 +0100 | [diff] [blame] | 84 | static bool trace_branch() { return trace_branch_; } |
| 85 | static void set_trace_branch(bool value) { trace_branch_ = value; } |
Pierre Langlois | bc01be6 | 2016-10-12 14:33:00 +0100 | [diff] [blame] | 86 | static bool disassemble() { return disassemble_; } |
| 87 | static void set_disassemble(bool value) { disassemble_ = value; } |
Jacob Bramley | d817e1e | 2017-06-22 11:31:43 +0100 | [diff] [blame] | 88 | static bool disassemble_infrastructure() { |
| 89 | return disassemble_infrastructure_; |
| 90 | } |
| 91 | static void set_disassemble_infrastructure(bool value) { |
| 92 | disassemble_infrastructure_ = value; |
| 93 | } |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 94 | static bool coloured_trace() { return coloured_trace_; } |
| 95 | static void set_coloured_trace(bool value) { coloured_trace_ = value; } |
armvixl | 0f35e36 | 2016-05-10 13:57:58 +0100 | [diff] [blame] | 96 | static bool generate_test_trace() { return generate_test_trace_; } |
| 97 | static void set_generate_test_trace(bool value) { |
| 98 | generate_test_trace_ = value; |
| 99 | } |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 100 | |
Jacob Bramley | e828920 | 2019-07-31 11:25:23 +0100 | [diff] [blame] | 101 | typedef void(TestFunction)(); |
| 102 | typedef void(TestFunctionWithConfig)(Test* config); |
| 103 | |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 104 | private: |
| 105 | const char* name_; |
Jacob Bramley | e828920 | 2019-07-31 11:25:23 +0100 | [diff] [blame] | 106 | |
armvixl | 330dc71 | 2014-11-25 10:38:32 +0000 | [diff] [blame] | 107 | TestFunction* callback_; |
Jacob Bramley | e828920 | 2019-07-31 11:25:23 +0100 | [diff] [blame] | 108 | TestFunctionWithConfig* callback_with_config_; |
| 109 | |
| 110 | void set_callback(TestFunction* callback); |
| 111 | void set_callback(TestFunctionWithConfig* callback); |
| 112 | |
| 113 | int sve_vl_; |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 114 | |
armvixl | 330dc71 | 2014-11-25 10:38:32 +0000 | [diff] [blame] | 115 | static Test* first_; |
| 116 | static Test* last_; |
| 117 | Test* next_; |
Georgia Kouveli | 1cb7144 | 2017-01-30 13:35:28 +0000 | [diff] [blame] | 118 | static bool verbose_; |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 119 | static bool trace_sim_; |
| 120 | static bool trace_reg_; |
armvixl | 330dc71 | 2014-11-25 10:38:32 +0000 | [diff] [blame] | 121 | static bool trace_write_; |
Jacob Bramley | e79723a | 2016-06-07 17:50:47 +0100 | [diff] [blame] | 122 | static bool trace_branch_; |
Pierre Langlois | bc01be6 | 2016-10-12 14:33:00 +0100 | [diff] [blame] | 123 | static bool disassemble_; |
Jacob Bramley | d817e1e | 2017-06-22 11:31:43 +0100 | [diff] [blame] | 124 | static bool disassemble_infrastructure_; |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 125 | static bool coloured_trace_; |
armvixl | 0f35e36 | 2016-05-10 13:57:58 +0100 | [diff] [blame] | 126 | static bool generate_test_trace_; |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 127 | }; |
| 128 | |
armvixl | 330dc71 | 2014-11-25 10:38:32 +0000 | [diff] [blame] | 129 | // Define helper macros for test files. |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 130 | |
armvixl | 330dc71 | 2014-11-25 10:38:32 +0000 | [diff] [blame] | 131 | // Macro to register a test. It instantiates a Test and registers its |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 132 | // callback function. |
Pierre Langlois | bde2e4b | 2017-01-24 17:41:26 +0000 | [diff] [blame] | 133 | #define TEST_(Name) \ |
| 134 | void Test##Name(); \ |
| 135 | Test test_##Name(#Name, &Test##Name); \ |
| 136 | void Test##Name() |
armvixl | ad96eda | 2013-06-14 11:42:37 +0100 | [diff] [blame] | 137 | } // namespace vixl |
| 138 | |
armvixl | 330dc71 | 2014-11-25 10:38:32 +0000 | [diff] [blame] | 139 | #endif // TEST_TEST_H_ |