Skip to contentSkip to conversation

y2038: testsuite/smokey/y2038: testcase for getres64

PATCH In review Song Chen 1 participant 1 message Apr 27, 2021

lore
Share & tools
lore

Song Chen

author
#0 lore raw

PATCH 3/3 y2038: testsuite/smokey/y2038: testcase for getres64

From: chensong <[email protected]>

add test case for clock_getres64 in testsuite

---
 testsuite/smokey/y2038/syscall-tests.c | 35 ++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)
testsuite/smokey/y2038/syscall-tests.c +35 -0
index 5bbd35e..c59a9d6 100644
@@ -296,8 +296,39 @@ static int test_sc_cobalt_clock_nanosleep64(void)
 	return 0;
 }
 
+static int test_sc_cobalt_clock_getres64(void)
+{
+	long ret;
+	int code = __xn_syscode(sc_cobalt_clock_getres64);
+	struct xn_timespec64 ts64;
+
+	/* Make sure we don't crash because of NULL pointers */
+	ret = syscall(code, NULL, NULL);
+	if (ret == -1 && errno == ENOSYS) {
+		smokey_note("clock_getres64: skipped. (no kernel support)");
+		return 0; // Not implemented, nothing to test, success
+	}
+	if (!smokey_assert(ret == -1) || !smokey_assert(errno == EFAULT))
+		return errno;
+
+	/* Providing an invalid address has to deliver EFAULT */
+	ret = syscall(code, CLOCK_MONOTONIC, (void *)0xdeadbeefUL);
+	if (!smokey_assert(ret == -1) || !smokey_assert(errno == EFAULT))
+		return errno;
+
+	/* Provide a valid 64bit timespec*/
+	ret = syscall(code, CLOCK_MONOTONIC, &ts64);
+	if (!smokey_assert(!ret))
+		return errno;
+	if (ts64.tv_sec != 0 || ts64.tv_nsec != 1)
+		smokey_warning("High resolution timers not available\n");
+
+	return 0;
+}
+
 static int run_y2038(struct smokey_test *t, int argc, char *const argv[])
 {
+
 	int ret;
 
 	ret = test_sc_cobalt_sem_timedwait64();
@@ -316,5 +347,9 @@ static int run_y2038(struct smokey_test *t, int argc, char *const argv[])
 	if (ret)
 		return ret;
 
+	ret = test_sc_cobalt_clock_getres64();
+	if (ret)
+		return ret;
+
 	return 0;
 }
Signature · 1 line
2.7.4