@@ -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 \
@@ -31,6 +31,8 @@ alarm05 alarm05
alarm06 alarm06
alarm07 alarm07
+arch_prctl01 arch_prctl01
+
bind01 bind01
bind02 bind02
bind03 bind03
new file mode 100644
@@ -0,0 +1 @@
+/arch_prctl01
new file mode 100644
@@ -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
new file mode 100644
@@ -0,0 +1,82 @@
+// 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>
+#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 bool tag;
+
+static void setup(void)
+{
+ FILE *f;
+ char flag_mid[] = " cpuid_fault ";
+ char flag_end[] = " cpuid_fault\n";
+ char *line = NULL;
+ size_t len = 0;
+
+ tag = false;
+
+ 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 = true;
+ break;
+ }
+}
+
+static void run(unsigned int index)
+{
+ if (tag)
+ TST_EXP_PASS(arch_prctl_set(ARCH_SET_CPUID, index));
+ else
+ TST_EXP_FAIL(arch_prctl_set(ARCH_SET_CPUID, index), ENODEV);
+
+ // if cpu has cpuid_fault flag, ARCH_GET_CPUID returns what has been
+ // set: index, otherwise, returns default status: 1
+ int exp = tag ? index : 1;
+
+ TEST(arch_prctl_get(ARCH_GET_CPUID));
+ if (TST_RET == exp)
+ tst_res(TPASS, "get cpuid succeed.");
+ else
+ tst_res(TFAIL, "get wrong cpuid status");
+}
+
+static struct tst_test test = {
+ .test = run,
+ .setup = setup,
+ .tcnt = 2,
+ .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
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 | 82 +++++++++++++++++++ 5 files changed, 94 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