testmain.cpp 2.2 KB

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