Skip to content

Commit b292022

Browse files
authored
👷 [Runtime] enable unittest on Ci (wenet-e2e#372)
1 parent 57e2d57 commit b292022

3 files changed

Lines changed: 27 additions & 3 deletions

File tree

‎.github/workflows/runtime.yml‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,18 @@ jobs:
2020
run: |
2121
cmake -B build -G Ninja -S runtime -DBUILD_TESTING=ON
2222
cmake --build build --parallel
23+
- uses: actions/setup-python@v5
24+
if: matrix.os == 'ubuntu-latest'
25+
with:
26+
python-version: '3.x'
27+
- name: Install dependencies & Generate TN models
28+
if: matrix.os == 'ubuntu-latest'
29+
run: |
30+
pip install pynini importlib_resources
31+
python -m tn --language zh --overwrite_cache
32+
- name: Run tests
33+
if: matrix.os == 'ubuntu-latest'
34+
run: ctest --test-dir build/test --output-on-failure
2335

2436
build-windows:
2537
name: build (windows-latest)
@@ -45,6 +57,8 @@ jobs:
4557
cmake --version
4658
gcc --version
4759
60+
# Tests are skipped on Windows: processor_test needs zh_tn_*.fst, which
61+
# are generated via pynini, and pynini has no Windows build.
4862
cmake -S runtime -B build -G Ninja \
4963
-DCMAKE_BUILD_TYPE=Release \
5064
-DBUILD_TESTING=OFF

‎runtime/test/CMakeLists.txt‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,8 @@ endif()
1515

1616
add_executable(processor_test processor_test.cc)
1717
target_link_libraries(processor_test PUBLIC wetext_processor)
18+
# Inject an absolute path to the *.fst models and golden data so the test does
19+
# not depend on the working directory.
20+
target_compile_definitions(processor_test PRIVATE
21+
WETEXT_TN_DIR="${CMAKE_CURRENT_SOURCE_DIR}/../../tn")
1822
gtest_discover_tests(processor_test)

‎runtime/test/processor_test.cc‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,12 @@
2020
#include "processor/wetext_processor.h"
2121
#include "utils/wetext_string.h"
2222

23+
// Absolute path to the dir with *.fst models and golden data, injected by CMake
24+
// so the test does not depend on the current working directory.
25+
#ifndef WETEXT_TN_DIR
26+
#define WETEXT_TN_DIR "../tn"
27+
#endif
28+
2329
std::vector<std::pair<std::string, std::string>> ParseTestCase(
2430
const std::string& file_path) {
2531
const std::string delimiter = "=>";
@@ -52,8 +58,8 @@ class ProcessorTest
5258
std::string spoken;
5359

5460
virtual void SetUp() {
55-
std::string tagger_path = "../tn/zh_tn_tagger.fst";
56-
std::string verbalizer_path = "../tn/zh_tn_verbalizer.fst";
61+
std::string tagger_path = WETEXT_TN_DIR "/zh_tn_tagger.fst";
62+
std::string verbalizer_path = WETEXT_TN_DIR "/zh_tn_verbalizer.fst";
5763
processor = new wetext::Processor(tagger_path, verbalizer_path);
5864
written = GetParam().first;
5965
spoken = GetParam().second;
@@ -67,6 +73,6 @@ TEST_P(ProcessorTest, NormalizeTest) {
6773
}
6874

6975
std::vector<std::pair<std::string, std::string>> test_cases =
70-
ParseTestCase("../tn/chinese/test/data/normalizer.txt");
76+
ParseTestCase(WETEXT_TN_DIR "/chinese/test/data/normalizer.txt");
7177
INSTANTIATE_TEST_SUITE_P(NormalizeTest, ProcessorTest,
7278
testing::ValuesIn(test_cases));

0 commit comments

Comments
 (0)