From 553c2a46e83b11d53d4ff523a74f56e04e192b20 Mon Sep 17 00:00:00 2001 From: Kees Bakker Date: Mon, 8 Jun 2020 20:46:37 +0200 Subject: [PATCH] tests/rmutex: refactor the test to avoid having to know the thread IDs When CDC ACM is used as stdio the first thread in the test may have a different ID than #3. The test code will now look at the printed thread information (id, prio) as they are created. This avoids the need for a table with ID/prio. --- tests/rmutex/tests/01-run.py | 43 +++++++++++++++--------------------- 1 file changed, 18 insertions(+), 25 deletions(-) diff --git a/tests/rmutex/tests/01-run.py b/tests/rmutex/tests/01-run.py index 0ca8ae3748fed..0354987a018a6 100755 --- a/tests/rmutex/tests/01-run.py +++ b/tests/rmutex/tests/01-run.py @@ -11,38 +11,31 @@ import sys from testrunner import run +NR_THREADS = 5 -thread_prio = { - 3: 6, - 4: 4, - 5: 5, - 6: 2, - 7: 4 - } - -lock_depth = { - 3: 5, - 4: 3, - 5: 3, - 6: 4, - 7: 5 - } - - -def thread_prio_sort(x): - return thread_prio.get(x)*1000 + x +# Make sure this matches main.c +# static const char depth[THREAD_NUMOF] = {5, 3, 3, 4, 5}; +expected_lock_depth = [ 5, 3, 3, 4, 5] def testfunc(child): - for k in thread_prio.keys(): - child.expect_exact("T{} (prio {}, depth 0): trying to lock rmutex now" - .format(k, thread_prio[k])) - - pri_sorted = sorted(thread_prio, key=thread_prio_sort) + # First collect the thread info how they are created + # A number of lines with: + # T4 (prio 6): waiting on condition variable now + thread_prios = {} + lock_depth = {} + for nr in range(NR_THREADS): + child.expect(r"T(\d+) \(prio (\d+), depth 0\): trying to lock rmutex now") + thr_id = int(child.match.group(1)) + thr_prio = int(child.match.group(2)) + thread_prios[thr_id] = thr_prio + lock_depth[thr_id] = expected_lock_depth[nr] + + pri_sorted = sorted(thread_prios, key=lambda x: thread_prios[x] * 1000 + x) for T in pri_sorted: for depth in range(lock_depth[T]): child.expect_exact("T{} (prio {}, depth {}): locked rmutex now" - .format(T, thread_prio[T], depth)) + .format(T, thread_prios[T], depth)) if __name__ == "__main__":