Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests/cond_order: refactor the test to avoid knowing the thread IDs #14228

Merged
merged 1 commit into from
Jun 9, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 20 additions & 17 deletions tests/cond_order/tests/01-run.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,31 @@
import os
import sys

thread_prio = {
3: 6,
4: 4,
5: 0,
6: 2,
7: 1
}
first_group_size = 3
NUM_THREADS = 5


def testfunc(child):
# First collect the thread info how they are created
# A number of lines with:
# T4 (prio 6): waiting on condition variable now
thread_prios = {}
for _ in range(NUM_THREADS):
child.expect(r"T(\d+) \(prio (\d+)\): waiting on condition variable now")
thread_id = int(child.match.group(1))
thread_prio = int(child.match.group(2))
thread_prios[thread_id] = thread_prio

for k in thread_prio.keys():
child.expect_exact("T{} (prio {}): waiting on condition variable now"
.format(k, thread_prio[k]))
count = 0
last = -1
child.expect_exact("First batch was signaled")
for _ in range(len(thread_prio)):
child.expect(r"T\d+ \(prio (\d+)\): condition variable was signaled now")
assert(int(child.match.group(1)) > last)
last = int(child.match.group(1))

count = 0
last_prio = -1
for _ in range(len(thread_prios)):
child.expect(r"T(\d+) \(prio (\d+)\): condition variable was signaled now")
thread_id = int(child.match.group(1))
thread_prio = int(child.match.group(2))
assert thread_prios[thread_id] == thread_prio
assert thread_prio > last_prio
last_prio = thread_prio
count += 1
if count == 3:
child.expect_exact("First batch has woken up")
Expand Down