From: lufei <lufei@uniontech.com>
To: chrubis@suse.cz, ltp@lists.linux.it
Cc: lufei <lufei@uniontech.com>
Subject: [LTP] [PATCH] Add case about arch_prctl syscall.
Date: Tue, 7 May 2024 12:32:35 +0800 [thread overview]
Message-ID: <20240507043235.1692-2-lufei@uniontech.com> (raw)
In-Reply-To: <20240507043235.1692-1-lufei@uniontech.com>
Add testcase about arch_prctl syscall.
Signed-off-by: Lu Fei <lufei@uniontech.com>
---
configure.ac | 1 +
runtest/syscalls | 2 +
.../kernel/syscalls/arch_prctl/.gitignore | 1 +
testcases/kernel/syscalls/arch_prctl/Makefile | 8 ++
.../kernel/syscalls/arch_prctl/arch_prctl01.c | 103 ++++++++++++++++++
5 files changed, 115 insertions(+)
create mode 100644 testcases/kernel/syscalls/arch_prctl/.gitignore
create mode 100644 testcases/kernel/syscalls/arch_prctl/Makefile
create mode 100644 testcases/kernel/syscalls/arch_prctl/arch_prctl01.c
diff --git a/configure.ac b/configure.ac
index 1d7e862d8..0dcaddc0f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -41,6 +41,7 @@ AC_CHECK_DECLS([SEM_STAT_ANY],,,[#include <sys/sem.h>])
AC_CHECK_HEADERS_ONCE([ \
asm/ldt.h \
+ asm/prctl.h \
cpuid.h \
emmintrin.h \
ifaddrs.h \
diff --git a/runtest/syscalls b/runtest/syscalls
index 7794f1465..505b4243d 100644
--- a/runtest/syscalls
+++ b/runtest/syscalls
@@ -31,6 +31,8 @@ alarm05 alarm05
alarm06 alarm06
alarm07 alarm07
+arch_prctl01 arch_prctl01
+
bind01 bind01
bind02 bind02
bind03 bind03
diff --git a/testcases/kernel/syscalls/arch_prctl/.gitignore b/testcases/kernel/syscalls/arch_prctl/.gitignore
new file mode 100644
index 000000000..24871e249
--- /dev/null
+++ b/testcases/kernel/syscalls/arch_prctl/.gitignore
@@ -0,0 +1 @@
+/arch_prctl01
diff --git a/testcases/kernel/syscalls/arch_prctl/Makefile b/testcases/kernel/syscalls/arch_prctl/Makefile
new file mode 100644
index 000000000..272949d57
--- /dev/null
+++ b/testcases/kernel/syscalls/arch_prctl/Makefile
@@ -0,0 +1,8 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) UnionTech Software Technology Co.,Ltd. 2024
+
+top_srcdir ?= ../../../..
+
+include $(top_srcdir)/include/mk/testcases.mk
+
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/syscalls/arch_prctl/arch_prctl01.c b/testcases/kernel/syscalls/arch_prctl/arch_prctl01.c
new file mode 100644
index 000000000..cce204f2d
--- /dev/null
+++ b/testcases/kernel/syscalls/arch_prctl/arch_prctl01.c
@@ -0,0 +1,103 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) UnionTech Software Technology Co.,Ltd., 2024
+ * Author: Lu Fei <lufei@uniontech.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Simple test on arch_prctl to set and get cpuid instruction of test thread.
+ */
+
+#include "tst_test.h"
+#include "tst_safe_stdio.h"
+#include "lapi/syscalls.h"
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#ifdef HAVE_ASM_PRCTL_H
+#include <asm/prctl.h>
+
+static int arch_prctl_get(int code)
+{
+ return tst_syscall(__NR_arch_prctl, code, NULL);
+}
+
+static int arch_prctl_set(int code, unsigned long addr)
+{
+ return tst_syscall(__NR_arch_prctl, code, addr);
+}
+
+static struct tcase {
+ const int input;
+ int set_exp;
+ int get_exp;
+ const int tst_errno;
+} tcases[] = {
+ {0, 0, 0, ENODEV},
+ {1, 0, 1, ENODEV},
+};
+
+static void setup(void)
+{
+ FILE *f;
+ char flag_mid[] = " cpuid_fault ";
+ char flag_end[] = " cpuid_fault\n";
+ char *line = NULL;
+ size_t len = 0;
+ bool tag = 0;
+
+ f = SAFE_FOPEN("/proc/cpuinfo", "r");
+
+ while (getline(&line, &len, f) != -1)
+ if (strncmp(line, "flags", strlen("flags")) == 0 &&
+ (strstr(line, flag_mid) != NULL ||
+ strstr(line, flag_end) != NULL)) {
+ tag = 1;
+ break;
+ }
+ if (!tag)
+ for (unsigned long i = 0; i < ARRAY_SIZE(tcases); i++) {
+ tcases[i].set_exp = -1;
+ // get default value
+ tcases[i].get_exp = 1;
+ }
+}
+
+static void run(unsigned int index)
+{
+ struct tcase tc = tcases[index];
+
+ TEST(arch_prctl_set(ARCH_SET_CPUID, tc.input));
+
+ if (TST_RET == tc.set_exp)
+ if (tc.set_exp == -1)
+ tst_res((TST_ERR == tc.tst_errno ? TPASS : TFAIL),
+ "set cpuid, expect: %s, get: %s",
+ tst_strerrno(tc.tst_errno),
+ tst_strerrno(TST_ERR));
+ else
+ tst_res(TPASS, "set cpuid succeed.");
+ else
+ tst_res(TFAIL, "set cpuid failed.");
+
+ TEST(arch_prctl_get(ARCH_GET_CPUID));
+
+ if (TST_RET == tc.get_exp)
+ tst_res(TPASS, "get cpuid succeed.");
+ else
+ tst_res(TFAIL, "get cpuid failed.");
+}
+
+static struct tst_test test = {
+ .test = run,
+ .setup = setup,
+ .tcnt = ARRAY_SIZE(tcases),
+ .min_kver = "4.12",
+ .supported_archs = (const char *const []){"x86_64", "x86", NULL}
+};
+
+#else /* HAVE_ASM_PRCTL_H */
+TST_TEST_TCONF("missing <asm/prctl.h>");
+#endif
--
2.39.3
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2024-05-07 4:33 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-19 7:07 [LTP] [PATCH v2] Add case about arch_prctl syscall lufei
2024-04-19 15:46 ` Cyril Hrubis
2024-04-21 6:25 ` lufei
2024-04-21 7:15 ` [LTP] (no subject) lufei
2024-04-21 7:15 ` [LTP] [PATCH v2] Add case about arch_prctl syscall lufei
2024-04-26 8:36 ` [LTP] (no subject) Cyril Hrubis
2024-04-26 9:42 ` 路斐
2024-04-26 10:28 ` Cyril Hrubis
2024-04-26 12:27 ` 路斐
2024-04-26 12:47 ` Jan Stancek
2024-04-23 1:05 ` [LTP] [PATCH v2] Add case about arch_prctl syscall lufei
2024-04-28 7:44 ` [LTP] (no subject) lufei
2024-04-28 7:44 ` [LTP] [PATCH] Add case about arch_prctl syscall lufei
2024-04-29 15:02 ` Cyril Hrubis
[not found] ` <20240506070336.2711930-1-lufei@uniontech.com>
2024-05-06 7:03 ` lufei
2024-05-06 9:53 ` Cyril Hrubis
[not found] ` <20240507043235.1692-1-lufei@uniontech.com>
2024-05-07 4:32 ` lufei [this message]
2024-05-07 12:50 ` Cyril Hrubis
2024-05-08 2:29 ` 路斐
[not found] ` <20240508015852.3362-1-lufei@uniontech.com>
2024-05-08 1:58 ` lufei
2024-05-09 10:27 ` Cyril Hrubis
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=20240507043235.1692-2-lufei@uniontech.com \
--to=lufei@uniontech.com \
--cc=chrubis@suse.cz \
--cc=ltp@lists.linux.it \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox