From 21c83759299d64d45fd1b8a3ad53c2f58f0e042c Mon Sep 17 00:00:00 2001 From: Fei Hao Date: Fri, 26 Jun 2026 11:21:52 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=B7=20[Runtime]=20enable=20unittest=20?= =?UTF-8?q?on=20Ci?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/runtime.yml | 14 ++++++++++++++ runtime/test/CMakeLists.txt | 4 ++++ runtime/test/processor_test.cc | 12 +++++++++--- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/.github/workflows/runtime.yml b/.github/workflows/runtime.yml index 2ebacaa0..2edf961a 100644 --- a/.github/workflows/runtime.yml +++ b/.github/workflows/runtime.yml @@ -20,6 +20,18 @@ jobs: run: | cmake -B build -G Ninja -S runtime -DBUILD_TESTING=ON cmake --build build --parallel + - uses: actions/setup-python@v5 + if: matrix.os == 'ubuntu-latest' + with: + python-version: '3.x' + - name: Install dependencies & Generate TN models + if: matrix.os == 'ubuntu-latest' + run: | + pip install pynini importlib_resources + python -m tn --language zh --overwrite_cache + - name: Run tests + if: matrix.os == 'ubuntu-latest' + run: ctest --test-dir build/test --output-on-failure build-windows: name: build (windows-latest) @@ -45,6 +57,8 @@ jobs: cmake --version gcc --version + # Tests are skipped on Windows: processor_test needs zh_tn_*.fst, which + # are generated via pynini, and pynini has no Windows build. cmake -S runtime -B build -G Ninja \ -DCMAKE_BUILD_TYPE=Release \ -DBUILD_TESTING=OFF diff --git a/runtime/test/CMakeLists.txt b/runtime/test/CMakeLists.txt index bf1b67f7..4b43bb73 100644 --- a/runtime/test/CMakeLists.txt +++ b/runtime/test/CMakeLists.txt @@ -15,4 +15,8 @@ endif() add_executable(processor_test processor_test.cc) target_link_libraries(processor_test PUBLIC wetext_processor) +# Inject an absolute path to the *.fst models and golden data so the test does +# not depend on the working directory. +target_compile_definitions(processor_test PRIVATE + WETEXT_TN_DIR="${CMAKE_CURRENT_SOURCE_DIR}/../../tn") gtest_discover_tests(processor_test) diff --git a/runtime/test/processor_test.cc b/runtime/test/processor_test.cc index e4be9673..16e91bcb 100644 --- a/runtime/test/processor_test.cc +++ b/runtime/test/processor_test.cc @@ -20,6 +20,12 @@ #include "processor/wetext_processor.h" #include "utils/wetext_string.h" +// Absolute path to the dir with *.fst models and golden data, injected by CMake +// so the test does not depend on the current working directory. +#ifndef WETEXT_TN_DIR +#define WETEXT_TN_DIR "../tn" +#endif + std::vector> ParseTestCase( const std::string& file_path) { const std::string delimiter = "=>"; @@ -52,8 +58,8 @@ class ProcessorTest std::string spoken; virtual void SetUp() { - std::string tagger_path = "../tn/zh_tn_tagger.fst"; - std::string verbalizer_path = "../tn/zh_tn_verbalizer.fst"; + std::string tagger_path = WETEXT_TN_DIR "/zh_tn_tagger.fst"; + std::string verbalizer_path = WETEXT_TN_DIR "/zh_tn_verbalizer.fst"; processor = new wetext::Processor(tagger_path, verbalizer_path); written = GetParam().first; spoken = GetParam().second; @@ -67,6 +73,6 @@ TEST_P(ProcessorTest, NormalizeTest) { } std::vector> test_cases = - ParseTestCase("../tn/chinese/test/data/normalizer.txt"); + ParseTestCase(WETEXT_TN_DIR "/chinese/test/data/normalizer.txt"); INSTANTIATE_TEST_SUITE_P(NormalizeTest, ProcessorTest, testing::ValuesIn(test_cases));