From e4e84b967cf1f28892c47ee9d8fa771b657961f7 Mon Sep 17 00:00:00 2001 From: Ross Morsali Date: Fri, 6 Feb 2026 15:54:50 +0100 Subject: [PATCH] Fix test on Windows --- Testing/Temporary/CTestCostData.txt | 1 + Testing/Temporary/LastTest.log | 3 ++ tests/CMakeLists.txt | 2 +- tests/test-stream-pcm.cpp | 54 ++++++++++++++++++++++++----- 4 files changed, 50 insertions(+), 10 deletions(-) create mode 100644 Testing/Temporary/CTestCostData.txt create mode 100644 Testing/Temporary/LastTest.log diff --git a/Testing/Temporary/CTestCostData.txt b/Testing/Temporary/CTestCostData.txt new file mode 100644 index 00000000..ed97d539 --- /dev/null +++ b/Testing/Temporary/CTestCostData.txt @@ -0,0 +1 @@ +--- diff --git a/Testing/Temporary/LastTest.log b/Testing/Temporary/LastTest.log new file mode 100644 index 00000000..3651f745 --- /dev/null +++ b/Testing/Temporary/LastTest.log @@ -0,0 +1,3 @@ +Start testing: Feb 06 15:52 Romance Standard Time +---------------------------------------------------------- +End testing: Feb 06 15:52 Romance Standard Time diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 2d3aaa3a..5503435f 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -115,7 +115,7 @@ if (WHISPER_BUILD_EXAMPLES) set(TEST_TARGET test-stream-pcm) add_executable(${TEST_TARGET} ${TEST_TARGET}.cpp) target_compile_definitions(${TEST_TARGET} PRIVATE - WHISPER_STREAM_PCM_PATH="${CMAKE_BINARY_DIR}/bin/whisper-stream-pcm" + WHISPER_STREAM_PCM_PATH="$" WHISPER_TEST_MODEL_PATH="${PROJECT_SOURCE_DIR}/models/for-tests-ggml-tiny.en.bin") add_test(NAME ${TEST_TARGET} COMMAND ${TEST_TARGET}) set_tests_properties(${TEST_TARGET} PROPERTIES LABELS "tiny;stream") diff --git a/tests/test-stream-pcm.cpp b/tests/test-stream-pcm.cpp index 3c29e94a..dca5961c 100644 --- a/tests/test-stream-pcm.cpp +++ b/tests/test-stream-pcm.cpp @@ -1,10 +1,14 @@ #include #include +#include #include #include #include #include +#if defined(_WIN32) +#include +#endif #ifndef WHISPER_STREAM_PCM_PATH #error "WHISPER_STREAM_PCM_PATH is not defined" #endif @@ -29,7 +33,8 @@ int main() { std::vector zeros(n_samples, 0.0f); - const auto pcm_path = temp_pcm_path(); + auto pcm_path = temp_pcm_path(); + pcm_path.make_preferred(); std::ofstream out(pcm_path, std::ios::binary); if (!out.is_open()) { fprintf(stderr, "failed to open temp PCM path: %s\n", pcm_path.string().c_str()); @@ -39,17 +44,48 @@ int main() { out.write(reinterpret_cast(zeros.data()), zeros.size() * sizeof(float)); out.close(); - const std::string stream_bin = WHISPER_STREAM_PCM_PATH; - const std::string model_path = WHISPER_TEST_MODEL_PATH; + const std::string stream_bin = std::filesystem::path(WHISPER_STREAM_PCM_PATH).make_preferred().string(); + const std::string model_path = std::filesystem::path(WHISPER_TEST_MODEL_PATH).make_preferred().string(); + std::vector args = { + stream_bin, + "-m", model_path, + "--input", pcm_path.string(), + "--format", "f32", + "--sample-rate", "16000", + "--step", "500", + "--length", "2000", + "-t", "1", + "-ng", + }; + + int rc = 1; +#if defined(_WIN32) + std::vector argv; + argv.reserve(args.size() + 1); + for (const auto & arg : args) { + argv.push_back(arg.c_str()); + } + argv.push_back(nullptr); + + rc = _spawnv(_P_WAIT, stream_bin.c_str(), argv.data()); + if (rc == -1) { + fprintf(stderr, "failed to spawn whisper-stream-pcm: %s\n", std::strerror(errno)); + rc = 1; + } +#else std::string cmd; cmd.reserve(1024); - cmd += "\"" + stream_bin + "\""; - cmd += " -m \"" + model_path + "\""; - cmd += " --input \"" + pcm_path.string() + "\""; - cmd += " --format f32 --sample-rate 16000 --step 500 --length 2000 -t 1 -ng"; - - const int rc = std::system(cmd.c_str()); + for (const auto & arg : args) { + if (!cmd.empty()) { + cmd += " "; + } + cmd += "\""; + cmd += arg; + cmd += "\""; + } + rc = std::system(cmd.c_str()); +#endif std::error_code ec; std::filesystem::remove(pcm_path, ec);