diff options
author | Austin Foxley <austinf@cetoncorp.com> | 2009-11-22 11:46:31 -0800 |
---|---|---|
committer | Austin Foxley <austinf@cetoncorp.com> | 2009-11-22 11:51:37 -0800 |
commit | f757db2d319ccc5f7034165046fb2bb58901afb1 (patch) | |
tree | 7dc465febb3a802d3f0e8856fcda856b13b04c0a /test/time | |
parent | 76c0c0ed99f74b8a5965be6e1c6a0c0e7a72513c (diff) | |
parent | b71274eebd68b7c68ab95c856f8075bdf4524cd7 (diff) |
Merge remote branch 'origin/master' into nptl_merge
Conflicts:
Rules.mak
libc/misc/sysvipc/msgq.c
test/Rules.mak
Signed-off-by: Austin Foxley <austinf@cetoncorp.com>
Diffstat (limited to 'test/time')
-rw-r--r-- | test/time/tst-futimens1.c | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/test/time/tst-futimens1.c b/test/time/tst-futimens1.c new file mode 100644 index 000000000..a452de2c7 --- /dev/null +++ b/test/time/tst-futimens1.c @@ -0,0 +1,90 @@ +/* vi: set sw=4 ts=4: */ +/* testcase + * Copyright (C) 2009 Bernhard Reutner-Fischer <uClibc@uClibc.org> + * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball. + */ +#include <sys/types.h> +#include <sys/stat.h> +#include <errno.h> +#include <stdlib.h> +#include <fcntl.h> +#include <stdio.h> +#include <unistd.h> + +struct +{ + char *name; /* name of file to open */ + int flags; /* flags for file descriptor */ + const struct timespec ts[2]; + int err; /* expected errno */ +} tests [] = +{ + {"futimens.tst", (O_CREAT|O_TRUNC), {{0,0},{0,0}}, 0}, + {"futimens.tst", (O_CREAT|O_TRUNC), {{99,0},{0,0}}, 0}, + {"futimens.tst", (O_CREAT|O_TRUNC), {{0,99},{0,0}}, 0}, + {"futimens.tst", (O_CREAT|O_TRUNC), {{0,0},{99,0}}, 0}, + {"futimens.tst", (O_CREAT|O_TRUNC), {{0,0},{0,99}}, 0}, + {"futimens.tst", (O_CREAT|O_TRUNC), {{11,2},{3,4}}, 0}, +}; +int do_test(int argc, char **argv) { + char *name; + int i, errors; + errors = argc - argc + 0; + + for (i=0; i < (int) (sizeof(tests)/sizeof(tests[0])); ++i) { + int err, fd; + struct stat sb; + name = tests[i].name; + if (*name != '.') + unlink(name); + fd = open(name, tests[i].flags); + if (fd < 0) + abort(); + errno = 0; + err = futimens(fd, tests[i].ts); + if ((errno && !err) || (!errno && err)) { + err = errno; + printf("%s: FAILED test %d (errno and return value disagree)\n", + argv[0], i); + ++errors; + } else + err = errno; + if (err != tests[i].err) { + printf("%s: FAILED test %d (expected errno %d, got %d)\n", + argv[0], i, tests[i].err, err); + ++errors; + continue; + } + if (stat(name, &sb) < 0) { + printf("%s: FAILED test %d (verification)\n", argv[0], i); + ++errors; + continue; + } else { + unsigned wrong = tests[i].ts[0].tv_sec != sb.st_atim.tv_sec || + tests[i].ts[0].tv_nsec != sb.st_atim.tv_nsec || + tests[i].ts[1].tv_sec != sb.st_mtim.tv_sec || + tests[i].ts[1].tv_nsec != sb.st_mtim.tv_nsec; + if (wrong) { + ++errors; + if (tests[i].ts[0].tv_sec != sb.st_atim.tv_sec) + printf("%s: FAILED test %d (access time, sec: expected %ld, got %ld)\n", + argv[0], i, tests[i].ts[0].tv_sec, sb.st_atim.tv_sec); + if (tests[i].ts[0].tv_nsec != sb.st_atim.tv_nsec) + printf("%s: FAILED test %d (access time, nsec: expected %ld, got %ld)\n", + argv[0], i, tests[i].ts[0].tv_nsec, sb.st_atim.tv_nsec); + + if (tests[i].ts[1].tv_sec != sb.st_mtim.tv_sec) + printf("%s: FAILED test %d (modification time, sec: expected %ld, got %ld)\n", + argv[0], i, tests[i].ts[1].tv_sec, sb.st_mtim.tv_sec); + if (tests[i].ts[1].tv_nsec != sb.st_mtim.tv_nsec) + printf("%s: FAILED test %d (modification time, nsec: expected %ld, got %ld)\n", + argv[0], i, tests[i].ts[1].tv_nsec, sb.st_mtim.tv_nsec); + } + } + } + if (*name != '.') + unlink(name); + printf("%d errors.\n", errors); + return (!errors) ? EXIT_SUCCESS : EXIT_FAILURE; +} +#include <test-skeleton.c> |