From db328d2a861f5aedec900e44fbe1fd542b307afb Mon Sep 17 00:00:00 2001 From: Jean-Philippe Bruyère Date: Sun, 22 Jun 2025 12:06:15 +0200 Subject: unified samples app in c++, unit testing wip --- samples/main.cpp | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 samples/main.cpp (limited to 'samples/main.cpp') diff --git a/samples/main.cpp b/samples/main.cpp new file mode 100644 index 0000000..4a6a122 --- /dev/null +++ b/samples/main.cpp @@ -0,0 +1,86 @@ +#include "SampleApp.hpp" +#include "VkvgTest.hpp" + +#include "argparse/argparse.hpp" + +int main(int argc, char **argv) { + SampleApp app{}; + + argparse::ArgumentParser program("samples"); + program.add_argument("-w", "--width") + .help("Output width") + .default_value(512) + .store_into(app.width); + program.add_argument("-h", "--height") + .help("Output height") + .default_value(512) + .store_into(app.height); + program.add_argument("-i", "--iterations") + .help("iterations for each test, 0 is infinite loop") + .default_value(0) + .store_into(app.iterations); + program.add_argument("-s", "--size") + .help("test size when applicable") + .default_value(500) + .store_into(app.testSize); + +#if defined(DEBUG) && defined(VKVG_DBG_UTILS) + program.add_argument("--severity") + .help("Debug messenger severity: 3:Err 2:Warn 1:Info 0:Verbose") + .default_value>({0}) + .scan<'u', uint32_t>() + .nargs(argparse::nargs_pattern::at_least_one); + program.add_argument("--logtype") + .help("Log type bits: 1:General 2:Validation 4:Perf 8:DevAddrBind") + .default_value(2) + .store_into(app.logType); +#endif + + program.add_argument("-t", "--test-indices") + .default_value>({}) + .help("test indices to run") + .scan<'u', uint32_t>() + .nargs(argparse::nargs_pattern::at_least_one); + + program.add_argument("--list-tests") + .help("Get tests list") + .default_value(false) + .implicit_value(true); + + program.add_argument("--list-gpus") + .help("Get available GPU's, select with option '-g'") + .default_value(false) + .implicit_value(true) + .store_into(app.listGpus); + program.add_argument("-g", "--gpu") + .help("GPU index") + .default_value(-1) + .store_into(app.gpuIndex); + + try { + program.parse_args(argc, argv); + } + catch (const std::exception& err) { + std::cerr << err.what() << std::endl; + std::cerr << program; + std::exit(1); + } + + if (program["--list-tests"] == true) { + for (auto it = VkvgTest::tests.begin(); it != VkvgTest::tests.end(); ++it) { + int index = std::distance(VkvgTest::tests.begin(), it); + std::cout << std::setw(4) << index << " " << (*it)->name << std::endl; + } + exit(0); + } + + app.testsToRun = program.get>("--test-indices"); + +#if defined(DEBUG) && defined(VKVG_DBG_UTILS) + app.logSeverity = program.get>("--severity"); +#endif + + app.Init(); + app.Run(); + +} -- cgit v1.3.1-4-g156e