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