diff options
-rw-r--r-- | test/app.cpp | 118 | ||||
-rw-r--r-- | test/app.hpp | 18 | ||||
-rw-r--r-- | test/path-search-result.cpp | 2 | ||||
-rw-r--r-- | test/serializer.cpp | 4 | ||||
-rw-r--r-- | test/zzz_test_misc.cpp | 2 |
5 files changed, 105 insertions, 39 deletions
diff --git a/test/app.cpp b/test/app.cpp index 7eb2b6af..6aaebb80 100644 --- a/test/app.cpp +++ b/test/app.cpp @@ -1,11 +1,25 @@ #include "app.hpp" -#include "compat/assert.hpp" #include "loader/loader.hpp" -#include <stdlib.h> -#include <cstdlib> +#include <stdlib.h> // NOLINT(*-deprecated-headers) +#include <cstdio> +#include <Corrade/Containers/StringView.h> +#include <Magnum/Math/Functions.h> +#include <Magnum/Timeline.h> +#include <Magnum/GL/Context.h> namespace floormat { +namespace { + +bool is_log_quiet() // copy-pasted from src/chunk.cpp +{ + using GLCCF = GL::Implementation::ContextConfigurationFlag; + auto flags = GL::Context::current().configurationFlags(); + return !!(flags & GLCCF::QuietLog); +} + +} // namespace + test_app::test_app(const Arguments& arguments): Application { arguments, @@ -21,27 +35,79 @@ test_app::~test_app() int test_app::exec() { - test_coords(); - test_json(); - test_tile_iter(); - test_magnum_math(); - test_entity(); - test_math(); - test_hash(); - test_intrusive_ptr(); - test_loader(); - test_bitmask(); - test_wall_atlas(); - test_wall_atlas2(); - test_serializer_1(); - test_serializer_2(); - test_scenery(); - test_raycast(); - test_path_search_node_pool(); - test_path_search(); - test_dijkstra(); - - zzz_test_misc(); + constexpr auto SV_flags = StringViewFlag::Global|StringViewFlag::NullTerminated; + constexpr auto name_prefix = "test_"_s; + +#define FM_TEST(name) { ( StringView{#name, arraySize(#name)-1, SV_flags} ), ( &(name) ), } + + constexpr struct { + StringView name; + void(*function)(); + } list[] = { + FM_TEST(test_coords), + FM_TEST(test_tile_iter), + FM_TEST(test_magnum_math), + FM_TEST(test_math), + FM_TEST(test_entity), + FM_TEST(test_intrusive_ptr), + FM_TEST(test_hash), + FM_TEST(test_json), + FM_TEST(test_wall_atlas), + FM_TEST(test_wall_atlas2), + FM_TEST(test_bitmask), + FM_TEST(test_loader), + FM_TEST(test_serializer1), + FM_TEST(test_scenery), + FM_TEST(test_raycast), + FM_TEST(test_path_search_pool), + FM_TEST(test_path_search), + FM_TEST(test_dijkstra), // todo add dummy atlases to avoid expensive loading + FM_TEST(test_serializer2), + FM_TEST(test_zzz_misc), + }; + + if (is_log_quiet()) + for (const auto [_, fun] : list) + (*fun)(); + else + { + FILE* const s = stdout; + static constexpr auto sep = ""_s; + constexpr auto get_tabs = [](StringView name) constexpr { + return (name.size()+sep.size()) / 8; + }; + constexpr size_t tab_limit = 5; + constexpr auto get_time = [](auto&& fn) { + Timeline t; + t.start(); + (*fn)(); + return t.currentFrameTime() * 1e3f; + }; + + size_t max_tabs = 1; + for (const auto [name, _] : list) + max_tabs = Math::max(max_tabs, get_tabs(name)); + max_tabs++; + if (max_tabs > tab_limit) + max_tabs = 1; + + std::fflush(s); + + for (auto [name, fun] : list) + { + name = name.exceptPrefix(name_prefix); + std::fwrite(name.data(), name.size(), 1, s); + std::fflush(stdout); + auto ms = get_time(fun); + std::fwrite(sep.data(), sep.size(), 1, s); + auto num_tabs = max_tabs - get_tabs(name); + fm_assert(num_tabs <= tab_limit); + for (auto i = 0uz; i < num_tabs; i++) + std::fputc('\t', s); + std::fprintf(s, "% 9.3f ms\n", (double)ms); + std::fflush(s); + } + } return 0; } @@ -53,9 +119,9 @@ int main(int argc, char** argv) #ifdef _WIN32 // NOLINTNEXTLINE(concurrency-mt-unsafe) if (const auto* s = std::getenv("MAGNUM_LOG"); !s || !*s) - _putenv("MAGNUM_LOG=quiet"); + ::_putenv("MAGNUM_LOG=quiet"); #else - setenv("MAGNUM_LOG", "quiet", 0); + ::setenv("MAGNUM_LOG", "quiet", 0); #endif floormat::test_app application{{argc, argv}}; return application.exec(); diff --git a/test/app.hpp b/test/app.hpp index 78794cd3..f2a169fb 100644 --- a/test/app.hpp +++ b/test/app.hpp @@ -22,24 +22,24 @@ struct test_app final : private FM_APPLICATION int exec() override; static void test_coords(); - static void test_json(); static void test_tile_iter(); static void test_magnum_math(); static void test_math(); - static void test_serializer_1(); - static void test_serializer_2(); + static void test_intrusive_ptr(); static void test_entity(); - static void test_loader(); + static void test_serializer1(); static void test_bitmask(); - static void test_path_search(); - static void test_dijkstra(); static void test_hash(); + static void test_json(); + static void test_dijkstra(); + static void test_serializer2(); + static void test_loader(); + static void test_path_search(); static void test_scenery(); - static void test_path_search_node_pool(); + static void test_path_search_pool(); static void test_wall_atlas(); static void test_wall_atlas2(); static void test_raycast(); - static void test_intrusive_ptr(); - static void zzz_test_misc(); + static void test_zzz_misc(); }; } // namespace floormat diff --git a/test/path-search-result.cpp b/test/path-search-result.cpp index 2ce61ff6..960f43dc 100644 --- a/test/path-search-result.cpp +++ b/test/path-search-result.cpp @@ -5,7 +5,7 @@ namespace floormat { -void test_app::test_path_search_node_pool() +void test_app::test_path_search_pool() { auto& pool = path_search_result::_pool; fm_assert(!pool); diff --git a/test/serializer.cpp b/test/serializer.cpp index 906a911f..b810f974 100644 --- a/test/serializer.cpp +++ b/test/serializer.cpp @@ -138,14 +138,14 @@ void test_serializer(StringView input, StringView tmp) } // namespace -void test_app::test_serializer_1() +void test_app::test_serializer1() { fm_assert(Path::exists(Path::join(loader.TEMP_PATH, "CMakeCache.txt"))); const auto tmp_filename = Path::join(loader.TEMP_PATH, "test/test-serializer1.dat"_s); test_serializer({}, tmp_filename); } -void test_app::test_serializer_2() +void test_app::test_serializer2() { fm_assert(Path::exists(Path::join(loader.TEMP_PATH, "CMakeCache.txt"))); const auto tmp_filename = Path::join(loader.TEMP_PATH, "test/test-serializer2.dat"_s); diff --git a/test/zzz_test_misc.cpp b/test/zzz_test_misc.cpp index 66b3d8fa..b5a13884 100644 --- a/test/zzz_test_misc.cpp +++ b/test/zzz_test_misc.cpp @@ -9,7 +9,7 @@ void test_foo() {} } // namespace -void test_app::zzz_test_misc() +void test_app::test_zzz_misc() { test_foo(); } |