aboutsummaryrefslogtreecommitdiff
path: root/testcases/kernel
diff options
context:
space:
mode:
authorXiao Yang <yangx.jy@cn.fujitsu.com>2019-03-28 13:01:51 +0800
committerXiao Yang <yangx.jy@cn.fujitsu.com>2019-03-28 13:20:33 +0800
commit88a9c5590e7ce14a7917c17c7e9d7c1d3945dc0e (patch)
tree900bea1f08b9886f0549701d5f79e0c1c408c1a5 /testcases/kernel
parent32fbecbe14ca44e8ad02cc84e29699d72b6f9171 (diff)
syscalls/stime: Use 3 variants via test_multiplex()
We will test stime() libc wrapper, __NR_stime and __NR_settimeofday syscalls. Note: 1) bionic (Android libc) does not provide stime(), so avoid testing it on Android. 2) some arches(e.g. x86_64) don't define __NR_stime directly because glibc implements stime() by __NR_settimeofday. Signed-off-by: Xiao Yang <yangx.jy@cn.fujitsu.com> Reviewed-by: Steve Muckle <smuckle@google.com> Tested-by: Steve Muckle <smuckle@google.com>
Diffstat (limited to 'testcases/kernel')
-rw-r--r--testcases/kernel/syscalls/stime/stime01.c11
-rw-r--r--testcases/kernel/syscalls/stime/stime02.c8
-rw-r--r--testcases/kernel/syscalls/stime/stime_var.h54
3 files changed, 68 insertions, 5 deletions
diff --git a/testcases/kernel/syscalls/stime/stime01.c b/testcases/kernel/syscalls/stime/stime01.c
index 279b0b1b1..82a340258 100644
--- a/testcases/kernel/syscalls/stime/stime01.c
+++ b/testcases/kernel/syscalls/stime/stime01.c
@@ -17,8 +17,8 @@
#include <time.h>
#include <sys/time.h>
-#include "lapi/syscalls.h"
#include "tst_test.h"
+#include "stime_var.h"
static struct timeval real_time_tv;
@@ -32,7 +32,7 @@ static void run(void)
new_time = real_time_tv.tv_sec + 30;
- if (tst_syscall(__NR_stime, &new_time) < 0) {
+ if (do_stime(&new_time) < 0) {
tst_res(TFAIL | TERRNO, "stime(%ld) failed", new_time);
return;
}
@@ -52,8 +52,15 @@ static void run(void)
}
}
+static void setup(void)
+{
+ stime_info();
+}
+
static struct tst_test test = {
.test_all = run,
.needs_root = 1,
.restore_wallclock = 1,
+ .setup = setup,
+ .test_variants = TEST_VARIANTS,
};
diff --git a/testcases/kernel/syscalls/stime/stime02.c b/testcases/kernel/syscalls/stime/stime02.c
index 1aa10212b..126a49ade 100644
--- a/testcases/kernel/syscalls/stime/stime02.c
+++ b/testcases/kernel/syscalls/stime/stime02.c
@@ -19,15 +19,14 @@
#include <time.h>
#include <pwd.h>
-#include "lapi/syscalls.h"
#include "tst_test.h"
+#include "stime_var.h"
static time_t new_time;
static void run(void)
{
- TEST(tst_syscall(__NR_stime, &new_time));
-
+ TEST(do_stime(&new_time));
if (TST_RET != -1) {
tst_res(TFAIL,
"stime() returned %ld, expected -1 EPERM", TST_RET);
@@ -48,6 +47,8 @@ static void setup(void)
time_t curr_time;
struct passwd *ltpuser;
+ stime_info();
+
ltpuser = SAFE_GETPWNAM("nobody");
SAFE_SETUID(ltpuser->pw_uid);
@@ -61,4 +62,5 @@ static struct tst_test test = {
.test_all = run,
.setup = setup,
.needs_root = 1,
+ .test_variants = TEST_VARIANTS,
};
diff --git a/testcases/kernel/syscalls/stime/stime_var.h b/testcases/kernel/syscalls/stime/stime_var.h
new file mode 100644
index 000000000..b014f0a10
--- /dev/null
+++ b/testcases/kernel/syscalls/stime/stime_var.h
@@ -0,0 +1,54 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2019 FUJITSU LIMITED. All rights reserved.
+ * Author: Xiao Yang <yangx.jy@cn.fujitsu.com>
+ */
+
+#ifndef STIME_VAR__
+#define STIME_VAR__
+
+#include <sys/time.h>
+#include "lapi/syscalls.h"
+
+#define TEST_VARIANTS 3
+
+static int do_stime(time_t *ntime)
+{
+ switch (tst_variant) {
+ case 0:
+#ifdef __ANDROID__
+ tst_brk(TCONF, "libc stime() is not implemented on Android");
+#else
+ return stime(ntime);
+#endif
+ case 1:
+ return tst_syscall(__NR_stime, ntime);
+ case 2: {
+ struct timeval tv;
+
+ tv.tv_sec = *ntime;
+ tv.tv_usec = 0;
+
+ return tst_syscall(__NR_settimeofday, &tv, (struct timezone *) 0);
+ }
+ }
+
+ return -1;
+}
+
+static void stime_info(void)
+{
+ switch (tst_variant) {
+ case 0:
+ tst_res(TINFO, "Testing libc stime()");
+ break;
+ case 1:
+ tst_res(TINFO, "Testing SYS_stime syscall");
+ break;
+ case 2:
+ tst_res(TINFO, "Testing SYS_settimeofday syscall");
+ break;
+ }
+}
+
+#endif /* STIME_VAR__ */