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.

73 lines
1.7 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. std::vector<std::unique_ptr<test_scaffold>> tests;
  31. int main()
  32. {
  33. uint failed = 0;
  34. uint runned = 0;
  35. for(auto& test : tests)
  36. {
  37. ++runned;
  38. int value;
  39. try{
  40. value = test->run();
  41. if(value)
  42. {
  43. std::cout << std::dec << test->name << " failed with "<< value << std::endl;
  44. print_logs();
  45. }
  46. } catch (gp::runtime_error err) {
  47. std::cout << test->name << " failed with an exception: " << err.what() << std::endl;
  48. print_logs();
  49. value = -1;
  50. } catch (gp_config::assert_failure err) {
  51. std::cout << test->name << " failed with an assertion failure: " << err.what() << std::endl;
  52. print_logs();
  53. value = -1;
  54. } catch (...) {
  55. std::cout << test->name << " failed with an exception" << std::endl;
  56. print_logs();
  57. value = -1;
  58. }
  59. logger.clear();
  60. failed += (value != 0);
  61. }
  62. std::cout << std::dec << "Runned " << runned << " tests with " << failed << " failures" << std::endl;
  63. return 0;
  64. }