From 18ad4c0799b43a6eb719431583e7e4229aa74c44 Mon Sep 17 00:00:00 2001 From: Thomas Cort Date: Sat, 30 Mar 2013 01:45:02 +0000 Subject: [PATCH] test69: add clock_getres() and clock_gettime() tests. --- distrib/sets/lists/minix/mi | 1 + test/Makefile | 2 +- test/run | 2 +- test/test69.c | 95 +++++++++++++++++++++++++++++++++++++ 4 files changed, 98 insertions(+), 2 deletions(-) create mode 100644 test/test69.c diff --git a/distrib/sets/lists/minix/mi b/distrib/sets/lists/minix/mi index d9a1eb97d..33c4e431f 100644 --- a/distrib/sets/lists/minix/mi +++ b/distrib/sets/lists/minix/mi @@ -4616,6 +4616,7 @@ ./usr/tests/minix-posix/test66 minix-sys ./usr/tests/minix-posix/test67 minix-sys ./usr/tests/minix-posix/test68 minix-sys +./usr/tests/minix-posix/test69 minix-sys ./usr/tests/minix-posix/test7 minix-sys ./usr/tests/minix-posix/test8 minix-sys ./usr/tests/minix-posix/test9 minix-sys diff --git a/test/Makefile b/test/Makefile index 6deda404e..4ded59455 100644 --- a/test/Makefile +++ b/test/Makefile @@ -36,7 +36,7 @@ MINIX_TESTS= \ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 \ 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 \ 41 42 43 44 45 46 48 49 50 52 53 54 55 56 58 59 60 \ -61 64 65 66 67 68 +61 64 65 66 67 68 69 .if ${MACHINE_ARCH} == "i386" MINIX_TESTS+= \ diff --git a/test/run b/test/run index 4d3cc8fd8..8d6e69fef 100755 --- a/test/run +++ b/test/run @@ -17,7 +17,7 @@ setuids="test11 test33 test43 test44 test46 test56 test60 test61 test65" tests=" 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 \ 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 \ 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 \ - 61 62 63 64 65 66 67 68\ + 61 62 63 64 65 66 67 68 69\ sh1.sh sh2.sh interp.sh" tests_no=`expr 0` diff --git a/test/test69.c b/test/test69.c new file mode 100644 index 000000000..368cb4abb --- /dev/null +++ b/test/test69.c @@ -0,0 +1,95 @@ +/* Test 69. clock_getres(), clock_gettime(). */ + +#include +#include +#include +#include +#include +#include +#include + +#define TRIALS 100 +#define MAX_ERROR 4 +#define DEBUG 0 + +int subtest = 1; + +#include "common.c" + +int main(void); +void quit(void); +static void test_clock_getres(); +static void test_clock_gettime(); +static void show_timespec(char *msg, struct timespec *ts); + +static void test_clock_getres() +{ + struct timespec res; + + /* valid clock_id should succeed, invalid clock_id should fail */ + if (clock_getres(CLOCK_REALTIME, &res) == -1) e(10); + if (res.tv_sec < 0 || res.tv_nsec < 0) e(11); + show_timespec("res(CLOCK_REALTIME)", &res); + + if (clock_getres(CLOCK_MONOTONIC, &res) == -1) e(12); + if (res.tv_sec < 0 || res.tv_nsec < 0) e(13); + show_timespec("res(CLOCK_MONOTONIC)", &res); + + if (clock_getres(-1, &res) == 0) e(14); +} + +static void test_clock_gettime() +{ + struct timespec ts, ts2; + + /* valid clock_id should succeed, invalid clock_id should fail */ + if (clock_gettime(CLOCK_REALTIME, &ts) == -1) e(21); + if (ts.tv_sec < 0 || ts.tv_nsec < 0) e(22); + show_timespec("time(CLOCK_REALTIME)", &ts); + sleep(2); + if (clock_gettime(CLOCK_REALTIME, &ts2) == -1) e(23); + if (ts2.tv_sec < 0 || ts2.tv_nsec < 0) e(24); + if (ts2.tv_sec <= ts.tv_sec) e(25); + + if (clock_gettime(CLOCK_MONOTONIC, &ts) == -1) e(26); + if (ts.tv_sec < 0 || ts.tv_nsec < 0) e(27); + show_timespec("time(CLOCK_MONOTONIC)", &ts); + sleep(2); + if (clock_gettime(CLOCK_MONOTONIC, &ts2) == -1) e(28); + if (ts2.tv_sec < 0 || ts2.tv_nsec < 0) e(29); + if (ts2.tv_sec <= ts.tv_sec) e(30); + + + if (clock_gettime(-1, &ts) == 0) e(31); +} + +static void show_timespec(char *msg, struct timespec *ts) +{ +#if DEBUG == 1 + printf("[%s] tv_sec=%d tv_nsec=%ld\n", msg, ts->tv_sec, ts->tv_nsec); +#endif /* DEBUG == 1 */ +} + +int main() +{ + start(69); + struct timespec starttime, endtime; + + /* get test start time */ + if (clock_gettime(CLOCK_MONOTONIC, &starttime) == -1) e(1); + + test_clock_getres(); + test_clock_gettime(); + + /* get test end time */ + if (clock_gettime(CLOCK_MONOTONIC, &endtime) == -1) e(2); + + /* we shouldn't have gone backwards in time during this test */ + if ((starttime.tv_sec > endtime.tv_sec) || + (starttime.tv_sec == endtime.tv_sec && + starttime.tv_nsec > endtime.tv_nsec)) e(3); + + quit(); + return(-1); /* impossible */ +} +