From 56583b1402a7f8fad0f8c3c296e26f12b1114c95 Mon Sep 17 00:00:00 2001 From: Robert Morris Date: Thu, 3 Oct 2019 15:02:19 -0400 Subject: updated alarmtest --- user/alarmtest.c | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) (limited to 'user') diff --git a/user/alarmtest.c b/user/alarmtest.c index ca3db23..d3746c4 100644 --- a/user/alarmtest.c +++ b/user/alarmtest.c @@ -21,7 +21,7 @@ main(int argc, char *argv[]) { test0(); test1(); - exit(); + exit(0); } volatile static int count; @@ -44,7 +44,7 @@ test0() count = 0; sigalarm(2, periodic); for(i = 0; i < 1000*500000; i++){ - if((i % 250000) == 0) + if((i % 1000000) == 0) write(2, ".", 1); if(count > 0) break; @@ -53,7 +53,7 @@ test0() if(count > 0){ printf("test0 passed\n"); } else { - printf("test0 failed\n"); + printf("\ntest0 failed: the kernel never called the alarm handler\n"); } } @@ -64,6 +64,14 @@ void __attribute__ ((noinline)) foo(int i, int *j) { *j += 1; } +// +// tests that the kernel calls the handler multiple times. +// +// tests that, when the handler returns, it returns to +// the point in the program where the timer interrupt +// occurred, with all registers holding the same values they +// held when the interrupt occurred. +// void test1() { @@ -79,9 +87,19 @@ test1() break; foo(i, &j); } - if(i != j || count < 10){ - // i should equal j - printf("test1 failed\n"); + if(count < 10){ + printf("\ntest1 failed: too few calls to the handler\n"); + exit(1); + } else if(i != j){ + // the loop should have called foo() i times, and foo() should + // have incremented j once per call, so j should equal i. + // once possible source of errors is that the handler may + // return somewhere other than where the timer interrupt + // occurred; another is that that registers may not be + // restored correctly, causing i or j or the address ofj + // to get an incorrect value. + printf("\ntest1 failed: foo() executed fewer times than it was called\n"); + exit(1); } else { printf("test1 passed\n"); } -- cgit v1.2.3