diff options
author | Robert Morris <[email protected]> | 2019-08-05 02:04:44 -0400 |
---|---|---|
committer | Robert Morris <[email protected]> | 2019-08-05 02:04:44 -0400 |
commit | d96a8c5661ac27c82e577edc6714832b970586dc (patch) | |
tree | a78e0d1bb187e5f40816d89509ee1380170e71d8 /user/alarmtest.c | |
parent | deec67f05db8377dc912c33ff910002364f9199a (diff) | |
download | xv6-labs-d96a8c5661ac27c82e577edc6714832b970586dc.tar.gz xv6-labs-d96a8c5661ac27c82e577edc6714832b970586dc.tar.bz2 xv6-labs-d96a8c5661ac27c82e577edc6714832b970586dc.zip |
add alarmtest.c to the repository
they don't have to modify alarmtest.c, so we can use the
original version to test, to make it harder to cheat.
Diffstat (limited to 'user/alarmtest.c')
-rw-r--r-- | user/alarmtest.c | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/user/alarmtest.c b/user/alarmtest.c new file mode 100644 index 0000000..c6da547 --- /dev/null +++ b/user/alarmtest.c @@ -0,0 +1,88 @@ +// +// test program for the alarm lab. +// you can modify this file for testing, +// but please make sure your kernel +// modifications pass the original +// versions of these tests. +// + +#include "kernel/param.h" +#include "kernel/types.h" +#include "kernel/stat.h" +#include "kernel/riscv.h" +#include "user/user.h" + +void test0(); +void test1(); +void periodic(); + +int +main(int argc, char *argv[]) +{ + test0(); + test1(); + exit(); +} + +volatile static int count; + +void +periodic() +{ + count = count + 1; + printf(1, "alarm!\n"); + sigreturn(); +} + +// tests whether the kernel calls +// the alarm handler even a single time. +void +test0() +{ + int i; + printf(1, "test0 start\n"); + count = 0; + sigalarm(2, periodic); + for(i = 0; i < 1000*500000; i++){ + if((i % 250000) == 0) + write(2, ".", 1); + if(count > 0) + break; + } + sigalarm(0, 0); + if(count > 0){ + printf(1, "test0 passed\n"); + } else { + printf(1, "test0 failed\n"); + } +} + +void __attribute__ ((noinline)) foo(int i, int *j) { + if((i % 2500000) == 0) { + write(2, ".", 1); + } + *j += 1; +} + +void +test1() +{ + int i; + int j; + + printf(1, "test1 start\n"); + count = 0; + j = 0; + sigalarm(2, periodic); + for(i = 0; i < 500000000; i++){ + if(count >= 10) + break; + foo(i, &j); + } + if(i != j || count < 10){ + // i should equal j + printf(1, "test1 failed\n"); + } else { + printf(1, "test1 passed\n"); + } +} |