blob: ae73911d1424d71b8b3b10bc76700382e68abb86 [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"
armvixlad96eda2013-06-14 11:42:37 +010031
32namespace vixl {
33
armvixl330dc712014-11-25 10:38:32 +000034// Each actual test is represented by a Test instance.
35// Tests are appended to a static linked list upon creation.
36class Test {
37 typedef void (TestFunction)();
armvixlad96eda2013-06-14 11:42:37 +010038
39 public:
armvixl330dc712014-11-25 10:38:32 +000040 Test(const char* name, TestFunction* callback);
armvixlad96eda2013-06-14 11:42:37 +010041
42 const char* name() { return name_; }
armvixl330dc712014-11-25 10:38:32 +000043 TestFunction* callback() { return callback_; }
44 static Test* first() { return first_; }
45 static Test* last() { return last_; }
46 Test* next() { return next_; }
armvixlad96eda2013-06-14 11:42:37 +010047 static bool debug() { return debug_; }
48 static void set_debug(bool value) { debug_ = value; }
49 static bool trace_sim() { return trace_sim_; }
50 static void set_trace_sim(bool value) { trace_sim_ = value; }
51 static bool trace_reg() { return trace_reg_; }
52 static void set_trace_reg(bool value) { trace_reg_ = value; }
armvixl330dc712014-11-25 10:38:32 +000053 static bool trace_write() { return trace_write_; }
54 static void set_trace_write(bool value) { trace_write_ = value; }
Jacob Bramleye79723a2016-06-07 17:50:47 +010055 static bool trace_branch() { return trace_branch_; }
56 static void set_trace_branch(bool value) { trace_branch_ = value; }
Pierre Langloisbc01be62016-10-12 14:33:00 +010057 static bool disassemble() { return disassemble_; }
58 static void set_disassemble(bool value) { disassemble_ = value; }
armvixlad96eda2013-06-14 11:42:37 +010059 static bool coloured_trace() { return coloured_trace_; }
60 static void set_coloured_trace(bool value) { coloured_trace_ = value; }
armvixl578645f2013-08-15 17:21:42 +010061 static bool instruction_stats() { return instruction_stats_; }
62 static void set_instruction_stats(bool value) { instruction_stats_ = value; }
armvixl0f35e362016-05-10 13:57:58 +010063 static bool generate_test_trace() { return generate_test_trace_; }
64 static void set_generate_test_trace(bool value) {
65 generate_test_trace_ = value;
66 }
armvixlad96eda2013-06-14 11:42:37 +010067
68 // The debugger is needed to trace register values.
armvixl330dc712014-11-25 10:38:32 +000069 static bool run_debugger() { return debug_; }
armvixlad96eda2013-06-14 11:42:37 +010070
71 private:
72 const char* name_;
armvixl330dc712014-11-25 10:38:32 +000073 TestFunction* callback_;
armvixlad96eda2013-06-14 11:42:37 +010074
armvixl330dc712014-11-25 10:38:32 +000075 static Test* first_;
76 static Test* last_;
77 Test* next_;
armvixlad96eda2013-06-14 11:42:37 +010078 static bool debug_;
79 static bool trace_sim_;
80 static bool trace_reg_;
armvixl330dc712014-11-25 10:38:32 +000081 static bool trace_write_;
Jacob Bramleye79723a2016-06-07 17:50:47 +010082 static bool trace_branch_;
Pierre Langloisbc01be62016-10-12 14:33:00 +010083 static bool disassemble_;
armvixlad96eda2013-06-14 11:42:37 +010084 static bool coloured_trace_;
armvixl578645f2013-08-15 17:21:42 +010085 static bool instruction_stats_;
armvixl0f35e362016-05-10 13:57:58 +010086 static bool generate_test_trace_;
armvixlad96eda2013-06-14 11:42:37 +010087};
88
armvixl330dc712014-11-25 10:38:32 +000089// Define helper macros for test files.
armvixlad96eda2013-06-14 11:42:37 +010090
armvixl330dc712014-11-25 10:38:32 +000091// Macro to register a test. It instantiates a Test and registers its
armvixlad96eda2013-06-14 11:42:37 +010092// callback function.
93#define TEST_(Name) \
94void Test##Name(); \
armvixl330dc712014-11-25 10:38:32 +000095Test test_##Name(#Name, &Test##Name); \
armvixlad96eda2013-06-14 11:42:37 +010096void Test##Name()
97} // namespace vixl
98
armvixl330dc712014-11-25 10:38:32 +000099#endif // TEST_TEST_H_