diff --git a/runtime/CMakeLists.txt b/runtime/CMakeLists.txt index ed946d115..b1e86d55b 100644 --- a/runtime/CMakeLists.txt +++ b/runtime/CMakeLists.txt @@ -308,6 +308,10 @@ if(BUILD_TESTING) add_executable(pipeline_cache_file_test test/pipeline_cache_file_test.cpp) add_test(NAME pipeline_cache_file COMMAND pipeline_cache_file_test) + + add_executable(xdxr_build_output_test test/xdxr_build_output_test.cpp) + add_test(NAME xdxr_build_output COMMAND xdxr_build_output_test) + # vk_pipeline_check's memory budget for large modules: pure stdlib, no Vulkan device. add_executable(large_module_gate_test test/large_module_gate_test.cpp) find_package(Threads REQUIRED) diff --git a/runtime/test/vk_xdxr_build_test.cpp b/runtime/test/vk_xdxr_build_test.cpp index 1f4686869..9e46abadc 100644 --- a/runtime/test/vk_xdxr_build_test.cpp +++ b/runtime/test/vk_xdxr_build_test.cpp @@ -13,6 +13,7 @@ // one submission each, after one warm-up; result and scratch in device-local memory), then in-place updates // (refits) of the same structure, and writes nothing. #include "vk_test_device.h" +#include "xdxr_build_output.h" #include "../src/xdxr_build.h" #include @@ -21,7 +22,6 @@ #include #include #include -#include #include #include #include @@ -222,13 +222,9 @@ int main(int argc, char** argv) { return 2; } const std::string dir = argv[1]; - // A failed run must not leave the previous run's cases for the checker to pass. - if (argc == 2) { - std::error_code ec; - for (const auto& entry : std::filesystem::directory_iterator(dir, ec)) { - const auto ext = entry.path().extension(); - if (ext == ".bin" || ext == ".json") std::filesystem::remove(entry.path(), ec); - } + if (const auto ec = prepare_xdxr_build_output(dir, argc > 2)) { + std::fprintf(stderr, "cannot create output directory %s: %s\n", dir.c_str(), ec.message().c_str()); + return 1; } vktest::Device gpu; gpu.request_buffer_device_address = true; diff --git a/runtime/test/xdxr_build_output.h b/runtime/test/xdxr_build_output.h new file mode 100644 index 000000000..8693ecad5 --- /dev/null +++ b/runtime/test/xdxr_build_output.h @@ -0,0 +1,18 @@ +#pragma once + +#include + +inline std::error_code prepare_xdxr_build_output(const std::filesystem::path& dir, bool timing_only) { + if (timing_only) return {}; + + std::error_code ec; + std::filesystem::create_directories(dir, ec); + if (ec) return ec; + + // A failed run must not leave the previous run's cases for the checker to pass. + for (const auto& entry : std::filesystem::directory_iterator(dir, ec)) { + const auto ext = entry.path().extension(); + if (ext == ".bin" || ext == ".json") std::filesystem::remove(entry.path(), ec); + } + return {}; +} diff --git a/runtime/test/xdxr_build_output_test.cpp b/runtime/test/xdxr_build_output_test.cpp new file mode 100644 index 000000000..9113a3866 --- /dev/null +++ b/runtime/test/xdxr_build_output_test.cpp @@ -0,0 +1,43 @@ +// Exercise the fixture's output preparation without initializing Vulkan. +#include "xdxr_build_output.h" + +#include +#include +#include +#include + +namespace fs = std::filesystem; + +#define CHECK(condition) do { \ + if (!(condition)) { std::fprintf(stderr, "line %d: %s\n", __LINE__, #condition); return 1; } \ +} while (0) + +int main() { + const auto suffix = std::chrono::steady_clock::now().time_since_epoch().count(); + const auto root = fs::temp_directory_path() / ("leonida-xdxr-output-" + std::to_string(suffix)); + CHECK(fs::create_directory(root)); + struct Cleanup { + fs::path path; + ~Cleanup() { std::error_code ec; fs::remove_all(path, ec); } + } cleanup{root}; + + const auto output = root / "relocated" / "xdxr_build_cases"; + CHECK(!prepare_xdxr_build_output(output, true)); + CHECK(!fs::exists(output.parent_path())); + + CHECK(!prepare_xdxr_build_output(output, false)); + CHECK(fs::is_directory(output)); + CHECK(bool(std::ofstream(output / "old.json") << "{}")); + CHECK(bool(std::ofstream(output / "old.bin") << "case")); + CHECK(bool(std::ofstream(output / "keep.txt") << "keep")); + + CHECK(!prepare_xdxr_build_output(output, true)); + CHECK(fs::is_regular_file(output / "old.json")); + CHECK(fs::is_regular_file(output / "old.bin")); + + CHECK(!prepare_xdxr_build_output(output, false)); + CHECK(!fs::exists(output / "old.json")); + CHECK(!fs::exists(output / "old.bin")); + CHECK(fs::is_regular_file(output / "keep.txt")); + CHECK(prepare_xdxr_build_output(output / "keep.txt", false)); +}