From f2aab63d165d0bc787095133e5b4a8682b63544b Mon Sep 17 00:00:00 2001 From: sean Date: Sun, 21 Apr 2024 18:19:29 +0200 Subject: [PATCH] Change: Set thread & process priorities in tests/benchmarks --- fetch_test_deps.py | 2 +- tests/CMakeLists.txt | 9 ++------- tests/benchmarks.cpp | 4 ++-- tests/main.cpp | 15 +++++++++++++++ 4 files changed, 20 insertions(+), 10 deletions(-) create mode 100644 tests/main.cpp diff --git a/fetch_test_deps.py b/fetch_test_deps.py index 1929ef66b..9546cc2d5 100755 --- a/fetch_test_deps.py +++ b/fetch_test_deps.py @@ -15,7 +15,7 @@ 'imgui': "https://github.com/ocornut/imgui/archive/refs/tags/v1.90.4.zip" } test_deps_urls = { - 'catch2': "https://github.com/catchorg/Catch2/archive/refs/tags/v3.5.2.zip", + 'catch2': "https://github.com/catchorg/Catch2/archive/refs/tags/v3.5.4.zip", 'corrosion': "https://github.com/corrosion-rs/corrosion/archive/refs/heads/master.zip", } deps_folder = "deps/" diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index c6ada28f7..e1496124a 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,19 +1,14 @@ set_directory_properties(PROPERTIES EXCLUDE_FROM_ALL TRUE) # We want these tests to be a optional executable. -add_executable(fastgltf_tests EXCLUDE_FROM_ALL +add_executable(fastgltf_tests EXCLUDE_FROM_ALL "main.cpp" "base64_tests.cpp" "basic_test.cpp" "benchmarks.cpp" "glb_tests.cpp" "gltf_path.hpp" "util_tests.cpp" "vector_tests.cpp" "uri_tests.cpp" "extension_tests.cpp" "accessor_tests.cpp" "write_tests.cpp") target_compile_features(fastgltf_tests PRIVATE ${FASTGLTF_COMPILE_TARGET}) target_link_libraries(fastgltf_tests PRIVATE fastgltf) -target_link_libraries(fastgltf_tests PRIVATE glm::glm Catch2::Catch2WithMain) +target_link_libraries(fastgltf_tests PRIVATE glm::glm Catch2::Catch2) fastgltf_compiler_flags(fastgltf_tests) -if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/deps/catch2") - add_subdirectory(deps/catch2) - target_link_libraries(fastgltf_tests PRIVATE Catch2::Catch2) -endif() - # We only use tinygltf to compare against. if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/gltf_loaders/tinygltf/tiny_gltf.h") message(STATUS "fastgltf: Found tinygltf") diff --git a/tests/benchmarks.cpp b/tests/benchmarks.cpp index 1859622cd..dc67ee446 100644 --- a/tests/benchmarks.cpp +++ b/tests/benchmarks.cpp @@ -76,13 +76,13 @@ void setTinyGLTFCallbacks(tinygltf::TinyGLTF& gltf) { #include #endif -std::vector readFileAsBytes(const std::filesystem::path& path) { +fastgltf::StaticVector readFileAsBytes(const std::filesystem::path& path) { std::ifstream file(path, std::ios::ate | std::ios::binary); if (!file.is_open()) throw std::runtime_error(std::string { "Failed to open file: " } + path.string()); auto fileSize = file.tellg(); - std::vector bytes(static_cast(fileSize) + fastgltf::getGltfBufferPadding()); + fastgltf::StaticVector bytes(static_cast(fileSize) + fastgltf::getGltfBufferPadding()); file.seekg(0, std::ifstream::beg); file.read(reinterpret_cast(bytes.data()), fileSize); file.close(); diff --git a/tests/main.cpp b/tests/main.cpp new file mode 100644 index 000000000..aded51fb0 --- /dev/null +++ b/tests/main.cpp @@ -0,0 +1,15 @@ +#include + +#ifdef _WIN32 +#include +#endif + +// See https://github.com/catchorg/Catch2/blob/v3.5.4/docs/own-main.md +int main(int argc, char* argv[]) { +#if defined(_WIN32) && defined(NDEBUG) + // Guarantee the best performance and result stability across runs + SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL); + SetPriorityClass(GetCurrentProcess(), REALTIME_PRIORITY_CLASS); +#endif + return Catch::Session().run(argc, argv); +}