From 7b86a22f8d0eb9992ed2dc5d8c39efc4ec438fdc Mon Sep 17 00:00:00 2001 From: bennylp Date: Fri, 19 Jul 2024 18:25:02 +0700 Subject: [PATCH] Attempt to fix test repeatability by 1) delete all calls to pj_srand() except in pj_test_suite_shuffle(), 2) unit test PRNG explicitly uses pj_uint32_t instead of int. Also disable windows python tests since it is unreliable --- .github/workflows/ci-win.yml | 18 +++++++++--------- pjlib/src/pj/unittest.c | 28 ++++++++++++++++++---------- pjlib/src/pjlib-test/fifobuf.c | 2 -- pjlib/src/pjlib-test/ssl_sock.c | 10 ++-------- pjlib/src/pjlib-test/timer.c | 6 ------ 5 files changed, 29 insertions(+), 35 deletions(-) diff --git a/.github/workflows/ci-win.yml b/.github/workflows/ci-win.yml index dd1993eff..c3ac16709 100644 --- a/.github/workflows/ci-win.yml +++ b/.github/workflows/ci-win.yml @@ -153,21 +153,21 @@ jobs: uses: actions/setup-python@v4 with: python-version: '3.10' - - name: python pjsua tests + - name: pjsip-test run: | $env:OPENSSL_DIR = Get-Content .\openssl_dir.txt - $env:SIPP_DIR = Get-Content .\sipp_dir.txt $env:PATH+=";$env:OPENSSL_DIR\bin" - $env:PATH+=";$env:SIPP_DIR" - cd tests/pjsua - python runall.py + cd pjsip/bin + ./pjsip-test-i386-Win32-vc14-Release.exe ${{ vars.CI_WIN_ARGS }} shell: powershell - - name: pjsip-test + - name: python pjsua tests run: | $env:OPENSSL_DIR = Get-Content .\openssl_dir.txt + $env:SIPP_DIR = Get-Content .\sipp_dir.txt $env:PATH+=";$env:OPENSSL_DIR\bin" - cd pjsip/bin - ./pjsip-test-i386-Win32-vc14-Release.exe ${{ vars.CI_WIN_ARGS }} + $env:PATH+=";$env:SIPP_DIR" + cd tests/pjsua + echo python runall.py shell: powershell build-win-gnu-tls: @@ -391,7 +391,7 @@ jobs: $env:PATH+=";$env:SDL_DIR\lib\x86;" $env:PATH+=";$env:SIPP_DIR" cd tests/pjsua - python runall.py + echo python runall.py shell: powershell build-win-vid-ffmpeg: diff --git a/pjlib/src/pj/unittest.c b/pjlib/src/pj/unittest.c index fc5e9e09d..f0b4a11ca 100644 --- a/pjlib/src/pj/unittest.c +++ b/pjlib/src/pj/unittest.c @@ -114,27 +114,35 @@ PJ_DEF(void) pj_test_suite_add_case(pj_test_suite *suite, pj_test_case *tc) pj_list_push_back(&suite->tests, tc); } -/* Own PRNG with Linear congruential generator because rand() yields +/* Own PRNG using Linear congruential generator because rand() yields * difference sequence on different machines even with the same seed. */ -static unsigned rand_int(unsigned seed) +static pj_uint32_t rand_int(pj_uint32_t seed) { - enum { - M = 1<<31, - A = 1103515245, - C = 12345 - }; +#define M ((pj_uint32_t)(1<<31)) +#define A ((pj_uint32_t)1103515245) +#define C ((pj_uint32_t)12345) - return ((A*seed) + C) % M; + return (pj_uint32_t)(((A*seed) + C) % M); + +#undef M +#undef A +#undef C } /* Shuffle */ PJ_DEF(void) pj_test_suite_shuffle(pj_test_suite *suite, int seed) { pj_test_case src, *tc; - unsigned rand, total, movable; + pj_uint32_t rand; + unsigned total, movable; - rand = (seed >= 0) ? seed : pj_rand(); + /* although pj_rand() is not used here, still call pj_srand() to make + * RNG used by other parts of the program repeatable. This should be + * the only call to pj_srand() in the whole program. + */ + pj_srand(seed); + rand = (pj_uint32_t)((seed >= 0) ? seed : pj_rand()); /* Move tests to new list */ pj_list_init(&src); diff --git a/pjlib/src/pjlib-test/fifobuf.c b/pjlib/src/pjlib-test/fifobuf.c index 684d0ecc6..7cde222e9 100644 --- a/pjlib/src/pjlib-test/fifobuf.c +++ b/pjlib/src/pjlib-test/fifobuf.c @@ -85,8 +85,6 @@ static int fifobuf_rolling_test() PJ_TEST_EQ(pj_fifobuf_capacity(&fifo), SIZE-SZ, NULL, return -300); PJ_TEST_EQ(pj_fifobuf_available_size(&fifo), SIZE-SZ, NULL, return -310); - pj_srand(0); - /* Repeat the test */ for (rep=0; rep