Added a testsuite. More support for COPY relocations.
[external/binutils.git] / gold / testsuite / test.cc
1 // test.cc -- simplistic test framework for gold.
2
3 #include "gold.h"
4
5 #include <cstdio>
6
7 #include "test.h"
8
9 namespace gold_testsuite
10 {
11
12 // Test_framework methods.
13
14 // The current test being run.
15
16 Test_report* Test_framework::current_report;
17
18 // Run a test.
19
20 void
21 Test_framework::run(const char *name, bool (*pfn)(Test_report*))
22 {
23   this->testname_ = name;
24   this->current_fail_ = false;
25
26   Test_report tr(this);
27   Test_framework::current_report = &tr;
28
29   if ((*pfn)(&tr) && !this->current_fail_)
30     {
31       printf("PASS: %s\n", name);
32       ++this->passes_;
33     }
34   else
35     {
36       printf("FAIL: %s\n", name);
37       ++this->failures_;
38     }
39
40   Test_framework::current_report = NULL;
41   this->testname_ = NULL;
42 }
43
44 // Let a test report an error.
45
46 void
47 Test_framework::error(const char* message)
48 {
49   printf("ERROR: %s: %s\n", this->testname_, message);
50   this->fail();
51 }
52
53 // Register_test methods.
54
55 // Linked list of all registered tests.
56
57 Register_test* Register_test::all_tests;
58
59 // Register a test.
60
61 Register_test::Register_test(const char* name, bool (*pfn)(Test_report*))
62   : name_(name), pfn_(pfn), next_(Register_test::all_tests)
63 {
64   Register_test::all_tests = this;
65 }
66
67 // Run all registered tests.
68
69 void
70 Register_test::run_tests(Test_framework* tf)
71 {
72   for (Register_test* p = Register_test::all_tests;
73        p != NULL;
74        p = p->next_)
75     tf->run(p->name_, p->pfn_);
76 }
77
78 } // End namespace gold_testsuite.