aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMike Frysinger <vapier@gentoo.org>2015-09-28 16:00:17 -0400
committerMike Frysinger <vapier@gentoo.org>2015-09-28 16:00:17 -0400
commit6b0db7d9abfded8bdf8c7d061b261f053eec886d (patch)
tree28ae6101e6a8b3232ecfc40cf763e1a1409e88c7 /tests
parentbuild: bump min autoconf/automake requirements (diff)
downloadsandbox-6b0db7d9abfded8bdf8c7d061b261f053eec886d.tar.gz
sandbox-6b0db7d9abfded8bdf8c7d061b261f053eec886d.tar.bz2
sandbox-6b0db7d9abfded8bdf8c7d061b261f053eec886d.zip
tests: add basic parsing of timespec fields
Signed-off-by: Mike Frysinger <vapier@gentoo.org>
Diffstat (limited to 'tests')
-rw-r--r--tests/test-skel-0.c23
-rw-r--r--tests/tests.h3
-rw-r--r--tests/utimensat-0.c2
3 files changed, 26 insertions, 2 deletions
diff --git a/tests/test-skel-0.c b/tests/test-skel-0.c
index dbe60db..96e42ae 100644
--- a/tests/test-skel-0.c
+++ b/tests/test-skel-0.c
@@ -9,7 +9,6 @@ const char *color_red = "\033[31;01m";
# define CONFIG 1
#endif
-#define V_TIMESPEC "NULL"
#define V_STRMODE "<r|w|a>[+bcemx] (see `man 3 fopen`)"
static bool _strtoul(const char *sul, unsigned long *ul)
@@ -132,6 +131,28 @@ int at_get_fd(const char *str_dirfd)
return open(str_path, f_get_flags(str_flags), sscanf_mode_t(str_mode));
}
+#define V_TIMESPEC "NULL | NOW | #[,#]"
+struct timespec *parse_timespec(const char *s)
+{
+ struct timespec *times;
+
+ if (!strcmp(s, "NULL"))
+ return NULL;
+
+ times = xzalloc(sizeof(*times));
+
+ if (!strcmp(s, "NOW")) {
+ times->tv_sec = time(0);
+ } else {
+ long sec = 0, nsec = 0;
+ sscanf(s, "%li,%li", &sec, &nsec);
+ times->tv_sec = sec;
+ times->tv_nsec = nsec;
+ }
+
+ return times;
+}
+
#define V_ACCESS_MODE "r | w | x | f"
int access_mode(const char *s)
{
diff --git a/tests/tests.h b/tests/tests.h
index 51dc68a..22733ca 100644
--- a/tests/tests.h
+++ b/tests/tests.h
@@ -10,6 +10,9 @@
#define err(fmt, args...) ({ _stderr_msg(fmt, ##args); exit(1); })
#define errp(fmt, args...) ({ _stderr_pmsg(fmt, ##args); exit(1); })
+#define xmalloc(size) ({ void *ret = malloc(size); assert(ret); ret; })
+#define xzalloc(size) ({ void *ret = xmalloc(size); memset(ret, 0, size); ret; })
+
typedef struct {
const char *name;
int val;
diff --git a/tests/utimensat-0.c b/tests/utimensat-0.c
index 431d179..99c3fa4 100644
--- a/tests/utimensat-0.c
+++ b/tests/utimensat-0.c
@@ -14,7 +14,7 @@
const char *file = f_get_file(s); \
\
s = argv[i++]; \
- const struct timespec *times = NULL; \
+ const struct timespec *times = parse_timespec(s); \
\
s = argv[i++]; \
int flags = at_get_flags(s);