|
|
- #include "gp_config.hpp"
-
- #include "gp/system/logging_segment.hpp"
-
- #include "allocator.hpp"
- #include "test_scaffold.h"
-
- #include <iostream>
-
- alignas(2048) gp::array<char, 4096> static_mapper::store;
- gp::buddy<> static_mapper::impl = gp::buddy<>{store.begin().data, store.size()};
-
- static_logging_segment<128> logger;
-
- void log_failure(const char* failure) {
- log_segment("FAILURE", failure, std::numeric_limits<int16_t>::max());
- }
-
- void log_segment(const char* name, const char* text, int16_t prio) {
- logger.push_segment(name, text, prio);
- }
-
- void print_logs() {
- auto end = logger.size();
- for(size_t idx = 0; idx < end; idx++) {
- auto seg = logger.get_segment_by_idx(idx);
- std::cout << "\t";
- for(char c : seg.name) {
- std::cout << c;
- }
- std::cout << ":\t";
- for(char c : seg.text) {
- std::cout << c;
- }
- std::cout << "\n";
- }
- }
-
- std::vector<std::unique_ptr<test_scaffold>> tests;
-
- int main()
- {
- uint failed = 0;
- uint runned = 0;
- for(auto& test : tests)
- {
- ++runned;
- int value;
- try{
- value = test->run();
- if(value)
- {
- std::cout << std::dec << test->name << " failed with "<< value << std::endl;
- print_logs();
- }
- } catch (gp::runtime_error err) {
- std::cout << test->name << " failed with an exception: " << err.what() << std::endl;
- print_logs();
- value = -1;
- } catch (gp_config::assert_failure err) {
- std::cout << test->name << " failed with an assertion failure: " << err.what() << std::endl;
- print_logs();
- value = -1;
- } catch (...) {
- std::cout << test->name << " failed with an exception" << std::endl;
- print_logs();
- value = -1;
- }
- logger.clear();
- failed += (value != 0);
- }
- std::cout << std::dec << "Runned " << runned << " tests with " << failed << " failures" << std::endl;
- return 0;
- }
|