mirror of
https://github.com/ProjectLeonida/mandy.git
synced 2026-12-06 09:18:37 +00:00
Create XDXR fixture output directory at startup
This commit is contained in:
@ -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)
|
||||
|
||||
@ -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 <algorithm>
|
||||
@ -21,7 +22,6 @@
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <random>
|
||||
#include <string>
|
||||
@ -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;
|
||||
|
||||
18
runtime/test/xdxr_build_output.h
Normal file
18
runtime/test/xdxr_build_output.h
Normal file
@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#include <filesystem>
|
||||
|
||||
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 {};
|
||||
}
|
||||
43
runtime/test/xdxr_build_output_test.cpp
Normal file
43
runtime/test/xdxr_build_output_test.cpp
Normal file
@ -0,0 +1,43 @@
|
||||
// Exercise the fixture's output preparation without initializing Vulkan.
|
||||
#include "xdxr_build_output.h"
|
||||
|
||||
#include <chrono>
|
||||
#include <cstdio>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
|
||||
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));
|
||||
}
|
||||
Reference in New Issue
Block a user