blob: bb72ce67f8bef6c4d1113ddade29b29b5cdc9d47 [file] [log] [blame]
Alexandre Ramesb78f1392016-07-01 14:22:22 +01001// Copyright 2014, VIXL authors
armvixlad96eda2013-06-14 11:42:37 +01002// 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
armvixl330dc712014-11-25 10:38:32 +000027#ifndef TEST_TEST_H_
28#define TEST_TEST_H_
armvixlad96eda2013-06-14 11:42:37 +010029
Alexandre Rames1f9074d2016-05-23 15:50:01 +010030#include "utils-vixl.h"
Jacob Bramley9e5da2a2019-08-06 18:52:07 +010031#include "aarch64/instructions-aarch64.h"
armvixlad96eda2013-06-14 11:42:37 +010032
33namespace vixl {
34
Martyn Capewelldba51cc2020-08-27 13:48:26 +010035// Each test is represented by a Test instance.
armvixl330dc712014-11-25 10:38:32 +000036// Tests are appended to a static linked list upon creation.
37class Test {
Martyn Capewelldba51cc2020-08-27 13:48:26 +010038 typedef void(TestFunction)();
39 typedef void(TestFunctionWithConfig)(Test* config);
40
armvixlad96eda2013-06-14 11:42:37 +010041 public:
Jacob Bramleye8289202019-07-31 11:25:23 +010042 // Most tests require no per-test configuration, and so take no arguments. A
43 // few tests require dynamic configuration, and are passed a `Test` object.
44 template <typename Fn>
Jacob Bramley32a7cd92020-08-06 18:00:10 +010045 Test(const char* name, Fn* callback)
46 : name_(name), sve_vl_(aarch64::kZRegMinSize), next_(NULL) {
Jacob Bramleye8289202019-07-31 11:25:23 +010047 set_callback(callback);
48 // Append this test to the linked list.
49 if (first_ == NULL) {
50 VIXL_ASSERT(last_ == NULL);
51 first_ = this;
52 } else {
53 last_->next_ = this;
54 }
55 last_ = this;
56 }
armvixlad96eda2013-06-14 11:42:37 +010057
Martyn Capewelldba51cc2020-08-27 13:48:26 +010058 static Test* MakeSVETest(int vl,
59 const char* name,
60 TestFunctionWithConfig* fn) {
61 // We never free this memory, but we need it to live for as long as the
62 // static
63 // linked list of tests, and this is the easiest way to do it.
64 Test* test = new Test(name, fn);
65 test->set_sve_vl_in_bits(vl);
66 return test;
67 }
68
armvixlad96eda2013-06-14 11:42:37 +010069 const char* name() { return name_; }
Jacob Bramleye8289202019-07-31 11:25:23 +010070 void run();
71
72 // The SVE vector length can be configured by each test, based on either
73 // hardware feature detection (in the test itself) or Simulator configuration.
74 int sve_vl_in_bits() const { return sve_vl_; }
Jacob Bramley9e5da2a2019-08-06 18:52:07 +010075 void set_sve_vl_in_bits(unsigned sve_vl) {
Jacob Bramley32a7cd92020-08-06 18:00:10 +010076 VIXL_ASSERT(sve_vl >= aarch64::kZRegMinSize);
Jacob Bramley9e5da2a2019-08-06 18:52:07 +010077 VIXL_ASSERT(sve_vl <= aarch64::kZRegMaxSize);
78 VIXL_ASSERT((sve_vl % aarch64::kZRegMinSize) == 0);
79 sve_vl_ = sve_vl;
80 }
81
82 int sve_vl_in_bytes() const {
83 VIXL_ASSERT((sve_vl_ % kBitsPerByte) == 0);
84 return sve_vl_ / kBitsPerByte;
85 }
Jacob Bramleye8289202019-07-31 11:25:23 +010086
armvixl330dc712014-11-25 10:38:32 +000087 static Test* first() { return first_; }
88 static Test* last() { return last_; }
89 Test* next() { return next_; }
Georgia Kouveli1cb71442017-01-30 13:35:28 +000090 static bool verbose() { return verbose_; }
91 static void set_verbose(bool value) { verbose_ = value; }
armvixlad96eda2013-06-14 11:42:37 +010092 static bool trace_sim() { return trace_sim_; }
93 static void set_trace_sim(bool value) { trace_sim_ = value; }
94 static bool trace_reg() { return trace_reg_; }
95 static void set_trace_reg(bool value) { trace_reg_ = value; }
armvixl330dc712014-11-25 10:38:32 +000096 static bool trace_write() { return trace_write_; }
97 static void set_trace_write(bool value) { trace_write_ = value; }
Jacob Bramleye79723a2016-06-07 17:50:47 +010098 static bool trace_branch() { return trace_branch_; }
99 static void set_trace_branch(bool value) { trace_branch_ = value; }
Pierre Langloisbc01be62016-10-12 14:33:00 +0100100 static bool disassemble() { return disassemble_; }
101 static void set_disassemble(bool value) { disassemble_ = value; }
Jacob Bramleyd817e1e2017-06-22 11:31:43 +0100102 static bool disassemble_infrastructure() {
103 return disassemble_infrastructure_;
104 }
105 static void set_disassemble_infrastructure(bool value) {
106 disassemble_infrastructure_ = value;
107 }
armvixlad96eda2013-06-14 11:42:37 +0100108 static bool coloured_trace() { return coloured_trace_; }
109 static void set_coloured_trace(bool value) { coloured_trace_ = value; }
armvixl0f35e362016-05-10 13:57:58 +0100110 static bool generate_test_trace() { return generate_test_trace_; }
111 static void set_generate_test_trace(bool value) {
112 generate_test_trace_ = value;
113 }
armvixlad96eda2013-06-14 11:42:37 +0100114
armvixlad96eda2013-06-14 11:42:37 +0100115 private:
116 const char* name_;
Jacob Bramleye8289202019-07-31 11:25:23 +0100117
armvixl330dc712014-11-25 10:38:32 +0000118 TestFunction* callback_;
Jacob Bramleye8289202019-07-31 11:25:23 +0100119 TestFunctionWithConfig* callback_with_config_;
120
121 void set_callback(TestFunction* callback);
122 void set_callback(TestFunctionWithConfig* callback);
123
124 int sve_vl_;
armvixlad96eda2013-06-14 11:42:37 +0100125
armvixl330dc712014-11-25 10:38:32 +0000126 static Test* first_;
127 static Test* last_;
128 Test* next_;
Georgia Kouveli1cb71442017-01-30 13:35:28 +0000129 static bool verbose_;
armvixlad96eda2013-06-14 11:42:37 +0100130 static bool trace_sim_;
131 static bool trace_reg_;
armvixl330dc712014-11-25 10:38:32 +0000132 static bool trace_write_;
Jacob Bramleye79723a2016-06-07 17:50:47 +0100133 static bool trace_branch_;
Pierre Langloisbc01be62016-10-12 14:33:00 +0100134 static bool disassemble_;
Jacob Bramleyd817e1e2017-06-22 11:31:43 +0100135 static bool disassemble_infrastructure_;
armvixlad96eda2013-06-14 11:42:37 +0100136 static bool coloured_trace_;
armvixl0f35e362016-05-10 13:57:58 +0100137 static bool generate_test_trace_;
armvixlad96eda2013-06-14 11:42:37 +0100138};
139
armvixl330dc712014-11-25 10:38:32 +0000140// Define helper macros for test files.
armvixlad96eda2013-06-14 11:42:37 +0100141
armvixl330dc712014-11-25 10:38:32 +0000142// Macro to register a test. It instantiates a Test and registers its
armvixlad96eda2013-06-14 11:42:37 +0100143// callback function.
Pierre Langloisbde2e4b2017-01-24 17:41:26 +0000144#define TEST_(Name) \
145 void Test##Name(); \
146 Test test_##Name(#Name, &Test##Name); \
147 void Test##Name()
armvixlad96eda2013-06-14 11:42:37 +0100148} // namespace vixl
149
armvixl330dc712014-11-25 10:38:32 +0000150#endif // TEST_TEST_H_