All of lore.kernel.org
 help / color / mirror / Atom feed
From: chensong <chensong@tj.kylinos.cn>
To: florian.bezdeka@siemens.com, xenomai@xenomai.org, rpm@xenomai.org
Subject: [PATCH v3] y2038: testsuite/smokey/y2038: testcase for settime64 and gettime64
Date: Tue, 30 Mar 2021 18:23:42 +0800	[thread overview]
Message-ID: <1617099822-19340-1-git-send-email-chensong@tj.kylinos.cn> (raw)

new test case for clock_settime64 and clock_gettime64 and reorganize
run_2038.

If you want to trigger and verify y2038 problem, please be careful and
make sure it has no impact to your test device.

Signed-off-by: chensong <chensong@tj.kylinos.cn>

---
v3:
1, rename structs, variables
2, reorganize registration in run_y2038
3, remove unnecessary definitions
---
 testsuite/smokey/y2038/syscall-tests.c | 109 ++++++++++++++++++++++++++++++---
 1 file changed, 102 insertions(+), 7 deletions(-)

diff --git a/testsuite/smokey/y2038/syscall-tests.c b/testsuite/smokey/y2038/syscall-tests.c
index 1d61bbd..b927a41 100644
--- a/testsuite/smokey/y2038/syscall-tests.c
+++ b/testsuite/smokey/y2038/syscall-tests.c
@@ -17,6 +17,36 @@
 
 smokey_test_plugin(y2038, SMOKEY_NOARGS, "Validate correct y2038 support");
 
+
+#define TEST_NAME(name) test_ ## name
+struct test_info {
+	char *name;
+	int (*test_fn)(void);
+};
+
+static int test_sc_cobalt_sem_timedwait64(void);
+static int test_sc_cobalt_clock_gettime64(void);
+static int test_sc_cobalt_clock_settime64(void);
+
+static struct test_info test_table[] = {
+	{
+		.name = "sc_cobalt_sem_timedwait64",
+		.test_fn = TEST_NAME(sc_cobalt_sem_timedwait64),
+	},
+	{
+		.name = "sc_cobalt_clock_gettime64",
+		.test_fn = TEST_NAME(sc_cobalt_clock_gettime64),
+	},
+	{
+		.name = "sc_cobalt_clock_settime64",
+		.test_fn = TEST_NAME(sc_cobalt_clock_settime64),
+	},
+	{
+		.name = NULL,
+		.test_fn = NULL,
+	},
+};
+
 /*
  * libc independent data type representing a time64_t based struct timespec
  */
@@ -25,7 +55,8 @@ struct xn_timespec64 {
 	int64_t tv_nsec;
 };
 
-#define NSEC_PER_SEC 1000000000
+#define NSEC_PER_SEC		1000000000
+#define USEC_PER_SEC		1000000
 
 static void ts_normalise(struct xn_timespec64 *ts)
 {
@@ -114,10 +145,10 @@ static int test_sc_cobalt_sem_timedwait64(void)
 
 	/*
 	 * The semaphore is already exhausted, so calling again will validate
-	 * the provided timeout now. Providing an invalid adress has to deliver
+	 * the provided timeout now. Providing an invalid address has to deliver
 	 * EFAULT
 	 */
-	ret = syscall(code, &sem, (void*) 0xdeadbeefUL);
+	ret = syscall(code, &sem, (void *)0xdeadbeefUL);
 	if (!smokey_assert(ret == -1) || !smokey_assert(errno == EFAULT))
 		return errno;
 
@@ -163,13 +194,77 @@ static int test_sc_cobalt_sem_timedwait64(void)
 	return 0;
 }
 
+static int test_sc_cobalt_clock_gettime64(void)
+{
+	long ret;
+	int code = __xn_syscode(sc_cobalt_clock_gettime64);
+	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_gettime64: 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_REALTIME, (void *)0xdeadbeefUL);
+	if (!smokey_assert(ret == -1) || !smokey_assert(errno == EFAULT))
+		return errno;
+
+	/* Provide a valid 64bit timespec*/
+	ret = syscall(code, CLOCK_REALTIME, &ts64);
+	if (!smokey_assert(ret == 0) || !smokey_assert(errno == EFAULT))
+		return errno;
+
+	return 0;
+}
+
+static int test_sc_cobalt_clock_settime64(void)
+{
+	long ret;
+	int code = __xn_syscode(sc_cobalt_clock_settime64);
+	struct xn_timespec64 ts64;
+	struct timespec now;
+
+	/*Get current time and set it back at the end of the test*/
+	clock_gettime(CLOCK_REALTIME, &now);
+
+	/* Make sure we don't crash because of NULL pointers */
+	ret = syscall(code, NULL, NULL);
+	if (ret == -1 && errno == ENOSYS) {
+		smokey_note("clock_settime64: skipped. (no kernel support)");
+		return 0; // Not implemented, nothing to test, success
+	}
+	if (!smokey_assert(ret == -1) || !smokey_assert(errno == EFAULT))
+		goto out;
+
+	/* Providing an invalid address has to deliver EFAULT */
+	ret = syscall(code, CLOCK_REALTIME, (void *)0xdeadbeefUL);
+	if (!smokey_assert(ret == -1) || !smokey_assert(errno == EFAULT))
+		goto out;
+
+	/* Provide a valid 64bit timespec*/
+	ts64.tv_sec  = now.tv_sec;
+	ts64.tv_nsec = now.tv_nsec;
+	ret = syscall(code, CLOCK_REALTIME, &ts64);
+	if (!smokey_assert(ret == 0) || !smokey_assert(errno == EFAULT))
+		goto out;
+
+out:
+	clock_settime(CLOCK_REALTIME, &now);
+	return errno;
+}
+
+
 static int run_y2038(struct smokey_test *t, int argc, char *const argv[])
 {
-	int ret;
+	struct test_info *ti;
 
-	ret = test_sc_cobalt_sem_timedwait64();
-	if (ret)
-		return ret;
+	for (ti = test_table; ti->test_fn != NULL; ti++)
+		ti->test_fn();
 
 	return 0;
 }
-- 
2.7.4





             reply	other threads:[~2021-03-30 10:23 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-30 10:23 chensong [this message]
2021-03-30 19:54 ` [PATCH v3] y2038: testsuite/smokey/y2038: testcase for settime64 and gettime64 Florian Bezdeka
2021-03-31  0:34   ` chensong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1617099822-19340-1-git-send-email-chensong@tj.kylinos.cn \
    --to=chensong@tj.kylinos.cn \
    --cc=florian.bezdeka@siemens.com \
    --cc=rpm@xenomai.org \
    --cc=xenomai@xenomai.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.