• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 namespace vixl {
33 
34 // Each actual test is represented by a Test instance.
35 // Tests are appended to a static linked list upon creation.
36 class Test {
37   typedef void(TestFunction)();
38 
39  public:
40   Test(const char* name, TestFunction* callback);
41 
name()42   const char* name() { return name_; }
callback()43   TestFunction* callback() { return callback_; }
first()44   static Test* first() { return first_; }
last()45   static Test* last() { return last_; }
next()46   Test* next() { return next_; }
verbose()47   static bool verbose() { return verbose_; }
set_verbose(bool value)48   static void set_verbose(bool value) { verbose_ = value; }
trace_sim()49   static bool trace_sim() { return trace_sim_; }
set_trace_sim(bool value)50   static void set_trace_sim(bool value) { trace_sim_ = value; }
trace_reg()51   static bool trace_reg() { return trace_reg_; }
set_trace_reg(bool value)52   static void set_trace_reg(bool value) { trace_reg_ = value; }
trace_write()53   static bool trace_write() { return trace_write_; }
set_trace_write(bool value)54   static void set_trace_write(bool value) { trace_write_ = value; }
trace_branch()55   static bool trace_branch() { return trace_branch_; }
set_trace_branch(bool value)56   static void set_trace_branch(bool value) { trace_branch_ = value; }
disassemble()57   static bool disassemble() { return disassemble_; }
set_disassemble(bool value)58   static void set_disassemble(bool value) { disassemble_ = value; }
disassemble_infrastructure()59   static bool disassemble_infrastructure() {
60     return disassemble_infrastructure_;
61   }
set_disassemble_infrastructure(bool value)62   static void set_disassemble_infrastructure(bool value) {
63     disassemble_infrastructure_ = value;
64   }
coloured_trace()65   static bool coloured_trace() { return coloured_trace_; }
set_coloured_trace(bool value)66   static void set_coloured_trace(bool value) { coloured_trace_ = value; }
instruction_stats()67   static bool instruction_stats() { return instruction_stats_; }
set_instruction_stats(bool value)68   static void set_instruction_stats(bool value) { instruction_stats_ = value; }
generate_test_trace()69   static bool generate_test_trace() { return generate_test_trace_; }
set_generate_test_trace(bool value)70   static void set_generate_test_trace(bool value) {
71     generate_test_trace_ = value;
72   }
73 
74  private:
75   const char* name_;
76   TestFunction* callback_;
77 
78   static Test* first_;
79   static Test* last_;
80   Test* next_;
81   static bool verbose_;
82   static bool trace_sim_;
83   static bool trace_reg_;
84   static bool trace_write_;
85   static bool trace_branch_;
86   static bool disassemble_;
87   static bool disassemble_infrastructure_;
88   static bool coloured_trace_;
89   static bool instruction_stats_;
90   static bool generate_test_trace_;
91 };
92 
93 // Define helper macros for test files.
94 
95 // Macro to register a test. It instantiates a Test and registers its
96 // callback function.
97 #define TEST_(Name)                     \
98   void Test##Name();                    \
99   Test test_##Name(#Name, &Test##Name); \
100   void Test##Name()
101 }  // namespace vixl
102 
103 #endif  // TEST_TEST_H_
104