diff options
author | Mole Shang <[email protected]> | 2024-02-19 14:10:32 +0800 |
---|---|---|
committer | Mole Shang <[email protected]> | 2024-02-19 14:36:21 +0800 |
commit | d86118fc80267649b4791c8c0c72ebd60edf1ef2 (patch) | |
tree | b792b617b4df80a5803a9c1164d0e3fdfe9cfe31 /grade-lab-thread | |
parent | b20ef9d0210fd7d9403acde1857eed1b9880c0b2 (diff) | |
parent | 0cf897cbe05fd8485162619db4244f4159d0eb52 (diff) | |
download | xv6-labs-d86118fc80267649b4791c8c0c72ebd60edf1ef2.tar.gz xv6-labs-d86118fc80267649b4791c8c0c72ebd60edf1ef2.tar.bz2 xv6-labs-d86118fc80267649b4791c8c0c72ebd60edf1ef2.zip |
Merge branch 'fs' into mmap
Conflicts:
.gitignore
Makefile
conf/lab.mk
kernel/defs.h
user/user.h
Diffstat (limited to 'grade-lab-thread')
-rwxr-xr-x | grade-lab-thread | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/grade-lab-thread b/grade-lab-thread new file mode 100755 index 0000000..18df65f --- /dev/null +++ b/grade-lab-thread @@ -0,0 +1,70 @@ +#!/usr/bin/env python3 + +import re +import subprocess +from gradelib import * + + +r = Runner(save("xv6.out")) + +@test(20, "uthread") +def test_uthread(): + r.run_qemu(shell_script([ + 'uthread' + ])) + expected = ['thread_a started', 'thread_b started', 'thread_c started'] + expected.extend(['thread_%s %d' % (tid, n) for n in range(100) for tid in ('c', 'a', 'b')]) + expected.extend(['thread_c: exit after 100', 'thread_a: exit after 100', 'thread_b: exit after 100']) + expected.append('thread_schedule: no runnable threads') + if not re.findall('\n'.join(expected), r.qemu.output, re.M): + raise AssertionError('Output does not match expected output') + +@test(5, "answers-thread.txt") +def test_answers(): + # just a simple sanity check, will be graded manually + check_answers("answers-thread.txt") + +# test the first ph task: add locks to eliminate the missing keys. +@test(10, "ph_safe") +def test_ph_safe(): + subprocess.run(['make', 'ph'], check=True) + result = subprocess.run(['./ph', '2'], stdout=subprocess.PIPE, check=True) + out = result.stdout.decode("utf-8") + matches = re.findall(r'^\d+: (\d+) keys missing$', out, re.MULTILINE) + assert_equal(len(matches), 2) + assert_equal(int(matches[0]), 0) + assert_equal(int(matches[1]), 0) + +# test the second ph task: locking that allows put() parallelism +@test(10, "ph_fast") +def test_ph_fast(): + subprocess.run(['make', 'ph'], check=True) + result = subprocess.run(['./ph', '2'], stdout=subprocess.PIPE, check=True) + out = result.stdout.decode("utf-8") + rate2 = re.findall(r' (\d+) puts.second$', out, re.MULTILINE) + assert_equal(len(rate2), 1) + result = subprocess.run(['./ph', '1'], stdout=subprocess.PIPE) + out = result.stdout.decode("utf-8") + rate1 = re.findall(r' (\d+) puts.second$', out, re.MULTILINE) + assert_equal(len(rate1), 1) + rate1 = float(rate1[0]) + rate2 = float(rate2[0]) + # demand that 2 threads yield at least 1.25x the + # throughput of a single thread. + if rate2 < 1.25 * rate1: + raise AssertionError('Parallel put() speedup is less than 1.25x') + +@test(14, "barrier") +def test_barrier(): + subprocess.run(['make', 'barrier']) + result = subprocess.run(['./barrier', '2'], stdout=subprocess.PIPE) + out = result.stdout.decode("utf-8") + if not re.match(r'^OK; passed$', out): + raise AssertionError('Barrier failed') + +@test(1, "time") +def test_time(): + check_time() + +run_tests() + |