Home | History | Annotate | Download | only in test
      1 // Copyright 2013, ARM Limited
      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_CCTEST_H_
     28 #define TEST_CCTEST_H_
     29 
     30 #include "utils-vixl.h"
     31 
     32 namespace vixl {
     33 
     34 // Each actual test is represented by a CCtest instance.
     35 // Cctests are appended to a static linked list upon creation.
     36 class Cctest {
     37   typedef void (CctestFunction)();
     38 
     39  public:
     40   Cctest(const char* name, CctestFunction* callback);
     41 
     42   const char* name() { return name_; }
     43   CctestFunction* callback() { return callback_; }
     44   static Cctest* first() { return first_; }
     45   static Cctest* last() { return last_; }
     46   Cctest* next() { return next_; }
     47   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; }
     53   static bool coloured_trace() { return coloured_trace_; }
     54   static void set_coloured_trace(bool value) { coloured_trace_ = value; }
     55   static bool instruction_stats() { return instruction_stats_; }
     56   static void set_instruction_stats(bool value) { instruction_stats_ = value; }
     57   static bool sim_test_trace() { return sim_test_trace_; }
     58   static void set_sim_test_trace(bool value) { sim_test_trace_ = value; }
     59 
     60   // The debugger is needed to trace register values.
     61   static bool run_debugger() { return debug_ || trace_reg_; }
     62 
     63  private:
     64   const char* name_;
     65   CctestFunction* callback_;
     66 
     67   static Cctest* first_;
     68   static Cctest* last_;
     69   Cctest* next_;
     70   static bool debug_;
     71   static bool trace_sim_;
     72   static bool trace_reg_;
     73   static bool coloured_trace_;
     74   static bool instruction_stats_;
     75   static bool sim_test_trace_;
     76 };
     77 
     78 // Define helper macros for cctest files.
     79 
     80 // Macro to register a cctest. It instantiates a Cctest and registers its
     81 // callback function.
     82 #define TEST_(Name)                                                            \
     83 void Test##Name();                                                             \
     84 Cctest cctest_##Name(#Name, &Test##Name);                                      \
     85 void Test##Name()
     86 }  // namespace vixl
     87 
     88 #endif  // TEST_CCTEST_H_
     89