1 #include <cstdlib>
2 #include <cstdio>
3 
4 #include "TestDesc.h"
5 #if defined(EMBEDDED)
6 #include "FPGA.h"
7 #else
8 #include "Semihosting.h"
9 #endif
10 #include "IORunner.h"
11 #include "ArrayMemory.h"
12 using namespace std;
13 
14 #ifndef MEMSIZE
15 #ifdef BENCHMARK
16 #define MEMSIZE 300000
17 #else
18 #define MEMSIZE 230000
19 #endif
20 #endif
21 
22 // Dummy (will be generated by python scripts)
23 // char* array describing the tests and the input patterns.
24 // Reference patterns are ignored in this case.
25 #include "TestDrive.h"
26 
27 extern "C" void testmain_hook(void) __attribute__ ((weak));
28 
testmain_hook(void)29 void testmain_hook(void)
30 {
31 }
32 
testmain(const char * patterns)33 int testmain(const char *patterns)
34 {
35     testmain_hook();
36     char *memoryBuf=NULL;
37 
38     memoryBuf = (char*)malloc(MEMSIZE);
39     if (memoryBuf !=NULL)
40     {
41         try
42         {
43            // Choice of a memory manager.
44            // Here we choose the Array one (only implemented one)
45            Client::ArrayMemory memory(memoryBuf,MEMSIZE);
46 
47            // There is also possibility of using "FPGA" io
48            #if defined(EMBEDDED)
49               Client::FPGA io(testDesc,patterns);
50            #else
51               Client::Semihosting io("../TestDesc.txt","../Patterns","../Output","../Parameters");
52            #endif
53 
54 
55            // Pattern Manager making the link between IO and Memory
56            Client::PatternMgr mgr(&io,&memory);
57 
58 
59            // A Runner to run the test.
60            // An IO runner is driven by some IO
61            // In future one may have a client/server runner driven
62            // by a server running on a host.
63            #if defined(EMBEDDED)
64            Client::IORunner runner(&io,&mgr,Testing::kTestOnly);
65            //Client::IORunner runner(&io,&mgr,Testing::kTestAndDump);
66            #else
67            // Works also in embedded but slower since data is dumped
68            Client::IORunner runner(&io,&mgr,Testing::kTestAndDump);
69            #endif
70 
71 
72            // Root object containing all the tests
73            Root d(1);
74 
75            // Runner applied to the tree of tests
76            d.accept(&runner);
77 
78         }
79         catch(...)
80         {
81             printf("Exception\n");
82         }
83 
84 
85         free(memoryBuf);
86     }
87     else
88     {
89       printf("NOT ENOUGH MEMORY\n");
90     }
91 
92     /* code */
93     return 0;
94 }
95