General Purpose library for Freestanding C++ and POSIX systems
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

79 líneas
1.8 KiB

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