General Purpose library for Freestanding C++ and POSIX systems
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

81 lines
1.8 KiB

4 years ago
4 years ago
  1. #include "gp_config.hpp"
  2. #include "gp/system/logging_segment.hpp"
  3. #include "allocator.hpp"
  4. #include "test_scaffold.h"
  5. #include <iostream>
  6. alignas(2048) gp::array<char, 4096> static_mapper::store;
  7. gp::buddy<> static_mapper::impl = gp::buddy<>{store.begin().data, store.size()};
  8. static_logging_segment<1024> logger;
  9. void log_failure(const char* failure) {
  10. log_segment("FAILURE", failure, std::numeric_limits<int16_t>::max());
  11. }
  12. void log_segment(const char* name, const char* text, int16_t prio) {
  13. logger.push_segment(name, text, prio);
  14. }
  15. void print_logs() {
  16. auto end = logger.size();
  17. for(size_t idx = 0; idx < end; idx++) {
  18. auto seg = logger.get_segment_by_idx(idx);
  19. std::cout << "\t";
  20. for(char c : seg.name) {
  21. std::cout << c;
  22. }
  23. std::cout << ":\t";
  24. for(char c : seg.text) {
  25. std::cout << c;
  26. }
  27. std::cout << "\n";
  28. }
  29. }
  30. #ifndef CATCH_EXCEPTIONS
  31. #define CATCH_EXCEPTIONS 0
  32. #endif
  33. std::vector<std::unique_ptr<test_scaffold>> tests;
  34. int main()
  35. {
  36. uint failed = 0;
  37. uint runned = 0;
  38. for(auto& test : tests)
  39. {
  40. ++runned;
  41. int value;
  42. #if CATCH_EXCEPTIONS
  43. try{
  44. #endif
  45. value = test->run();
  46. if(value)
  47. {
  48. std::cout << std::dec << test->name << " failed with "<< value << std::endl;
  49. print_logs();
  50. }
  51. #if CATCH_EXCEPTIONS
  52. } catch (gp::runtime_error err) {
  53. std::cout << test->name << " failed with an exception: " << err.what() << std::endl;
  54. print_logs();
  55. value = -1;
  56. } catch (gp_config::assert_failure err) {
  57. std::cout << test->name << " failed with an assertion failure: " << err.what() << std::endl;
  58. print_logs();
  59. value = -1;
  60. } catch (...) {
  61. std::cout << test->name << " failed with an exception" << std::endl;
  62. print_logs();
  63. value = -1;
  64. }
  65. #endif
  66. logger.clear();
  67. failed += (value != 0);
  68. }
  69. std::cout << std::dec << "Runned " << runned << " tests with " << failed << " failures" << std::endl;
  70. return 0;
  71. }