* [LTP] [PATCH 1/2] Rewrite ftrace_regression01.sh with new C API
@ 2026-03-04 8:05 lufei
2026-03-04 8:05 ` [LTP] [PATCH 2/2] Rewrite ftrace_regression02.sh " lufei
` (2 more replies)
0 siblings, 3 replies; 10+ messages in thread
From: lufei @ 2026-03-04 8:05 UTC (permalink / raw)
To: ltp; +Cc: lufei
This is regression test for panic bug while using userstacktrace,
set userstacktrace in loop and check if success.
Signed-off-by: lufei <lufei@uniontech.com>
---
.../kernel/tracing/ftrace_test/.gitignore | 2 +
.../tracing/ftrace_test/ftrace_regression.h | 34 ++++++++
.../tracing/ftrace_test/ftrace_regression01.c | 85 +++++++++++++++++++
.../ftrace_test/ftrace_regression01.sh | 83 ------------------
4 files changed, 121 insertions(+), 83 deletions(-)
create mode 100644 testcases/kernel/tracing/ftrace_test/.gitignore
create mode 100644 testcases/kernel/tracing/ftrace_test/ftrace_regression.h
create mode 100644 testcases/kernel/tracing/ftrace_test/ftrace_regression01.c
delete mode 100755 testcases/kernel/tracing/ftrace_test/ftrace_regression01.sh
diff --git a/testcases/kernel/tracing/ftrace_test/.gitignore b/testcases/kernel/tracing/ftrace_test/.gitignore
new file mode 100644
index 000000000..b0153e9fa
--- /dev/null
+++ b/testcases/kernel/tracing/ftrace_test/.gitignore
@@ -0,0 +1,2 @@
+ftrace_regression01
+ftrace_regression02
diff --git a/testcases/kernel/tracing/ftrace_test/ftrace_regression.h b/testcases/kernel/tracing/ftrace_test/ftrace_regression.h
new file mode 100644
index 000000000..c19d3d8fd
--- /dev/null
+++ b/testcases/kernel/tracing/ftrace_test/ftrace_regression.h
@@ -0,0 +1,34 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later
+ *
+ * Copyright (c) 2026 lufei <lufei@uniontech.com>
+ *
+ * Shared header for ftrace regression tests.
+ */
+
+#ifndef FTRACE_REGRESSION_H
+#define FTRACE_REGRESSION_H
+
+#include "tst_test.h"
+#include "tst_safe_file_ops.h"
+#include <string.h>
+
+#define FTRACE_FILE_CONTAINS_BUF_SIZE (1024 * 1024)
+
+/**
+ * file_contains - Check if a file contains the given string
+ * path: Path to the file
+ * str: String to search for
+ *
+ * Returns: 1 if file contains str, 0 otherwise
+ */
+static inline int file_contains(const char *path, const char *str)
+{
+ char buf[FTRACE_FILE_CONTAINS_BUF_SIZE];
+
+ buf[0] = '\0';
+ SAFE_FILE_SCANF(path, "%1048575[^\x01]", buf);
+ return strstr(buf, str) != NULL;
+}
+
+#endif /* FTRACE_REGRESSION_H */
+
diff --git a/testcases/kernel/tracing/ftrace_test/ftrace_regression01.c b/testcases/kernel/tracing/ftrace_test/ftrace_regression01.c
new file mode 100644
index 000000000..1aafb9122
--- /dev/null
+++ b/testcases/kernel/tracing/ftrace_test/ftrace_regression01.c
@@ -0,0 +1,85 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2015 Red Hat Inc.
+ * Copyright (c) 2026 lufei <lufei@uniontech.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Regression test for panic while using userstacktrace.
+ *
+ * BUG: unable to handle kernel paging request at 00000000417683c0
+ * IP: [<ffffffff8105c834>] update_curr+0x124/0x1e0
+ * Thread overran stack, or stack corrupted
+ * Oops: 0000 [#1] SMP
+ * last sysfs file: ../system/cpu/cpu15/cache/index2/shared_cpu_map
+ *
+ * The bug was fixed by:
+ * 1dbd195 (tracing: Fix preempt count leak)
+ */
+
+#include <unistd.h>
+#include <stdio.h>
+#include "ftrace_regression.h"
+
+#define DEBUGFS_DIR "debugfs"
+#define STACK_TRACER_PATH "/proc/sys/kernel/stack_tracer_enabled"
+#define TRACE_OPTIONS DEBUGFS_DIR "/tracing/trace_options"
+#define EXC_PAGE_FAULT DEBUGFS_DIR "/tracing/events/exceptions/page_fault_kernel/enable"
+#define MM_PAGE_FAULT DEBUGFS_DIR "/tracing/events/kmem/mm_kernel_pagefault/enable"
+
+#define LOOP 10
+
+static const char *page_fault_path;
+
+static void setup(void)
+{
+ SAFE_MKDIR(DEBUGFS_DIR, 0755);
+ SAFE_MOUNT(NULL, DEBUGFS_DIR, "debugfs", 0, NULL);
+
+ if (access(EXC_PAGE_FAULT, F_OK) == 0)
+ page_fault_path = EXC_PAGE_FAULT;
+ else if (access(MM_PAGE_FAULT, F_OK) == 0)
+ page_fault_path = MM_PAGE_FAULT;
+ else
+ tst_brk(TCONF, "Page fault event not available");
+}
+
+static void run(void)
+{
+ int i;
+
+ for (i = 0; i < LOOP; i++) {
+ SAFE_FILE_PRINTF(STACK_TRACER_PATH, "1");
+ SAFE_FILE_PRINTF(TRACE_OPTIONS, "userstacktrace");
+
+ if (!file_contains(TRACE_OPTIONS, "userstacktrace"))
+ tst_brk(TBROK, "Failed to set userstacktrace");
+
+ SAFE_FILE_PRINTF(page_fault_path, "1");
+ }
+
+ tst_res(TPASS, "Finished running the test");
+}
+
+static void cleanup(void)
+{
+ SAFE_UMOUNT(DEBUGFS_DIR);
+}
+
+static struct tst_test test = {
+ .needs_root = 1,
+ .needs_tmpdir = 1,
+ .setup = setup,
+ .test_all = run,
+ .cleanup = cleanup,
+ .save_restore = (const struct tst_path_val[]) {
+ {STACK_TRACER_PATH, NULL, TST_SR_TCONF},
+ {}
+ },
+ .tags = (const struct tst_tag[]) {
+ {"linux-git", "1dbd195"},
+ {}
+ },
+};
diff --git a/testcases/kernel/tracing/ftrace_test/ftrace_regression01.sh b/testcases/kernel/tracing/ftrace_test/ftrace_regression01.sh
deleted file mode 100755
index d6969cfc6..000000000
--- a/testcases/kernel/tracing/ftrace_test/ftrace_regression01.sh
+++ /dev/null
@@ -1,83 +0,0 @@
-#! /bin/sh
-
-###########################################################################
-## ##
-## Copyright (c) 2015, Red Hat Inc. ##
-## ##
-## This program is free software: you can redistribute it and/or modify ##
-## it under the terms of the GNU General Public License as published by ##
-## the Free Software Foundation, either version 3 of the License, or ##
-## (at your option) any later version. ##
-## ##
-## This program is distributed in the hope that it will be useful, ##
-## but WITHOUT ANY WARRANTY; without even the implied warranty of ##
-## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ##
-## GNU General Public License for more details. ##
-## ##
-## You should have received a copy of the GNU General Public License ##
-## along with this program. If not, see <http://www.gnu.org/licenses/>. ##
-## ##
-## Author: Li Wang <liwang@redhat.com> ##
-## ##
-###########################################################################
-## ##
-## Summary: panic while using userstacktrace ##
-## ##
-## BUG: unable to handle kernel paging request at 00000000417683c0 ##
-## IP: [<ffffffff8105c834>] update_curr+0x124/0x1e0 ##
-## PGD 41a796067 PUD 0 ##
-## Thread overran stack, or stack corrupted ##
-## Oops: 0000 [#1] SMP ##
-## last sysfs file: ../system/cpu/cpu15/cache/index2/shared_cpu_map ##
-## ##
-## The bug was fixed by: ##
-## 1dbd195 (tracing: Fix preempt count leak) ##
-## ##
-###########################################################################
-
-export TCID="ftrace_regression01"
-export TST_TOTAL=1
-
-. ftrace_lib.sh
-
-LOOP=10
-
-TSTACK_TRACE_PATH="/proc/sys/kernel/stack_tracer_enabled"
-EXC_PAGE_FAULT_ENABLE="$TRACING_PATH/events/exceptions/page_fault_kernel/enable"
-MM_PAGE_FAULT_ENABLE="$TRACING_PATH/events/kmem/mm_kernel_pagefault/enable"
-
-ftrace_userstacktrace_test()
-{
- if [ ! -e "$TSTACK_TRACE_PATH" ]; then
- tst_brkm TCONF "Stack Tracer is not cofigured in This kernel"
- fi
-
- for i in $(seq $LOOP); do
- echo 1 > $TSTACK_TRACE_PATH
- echo userstacktrace > $TRACING_PATH/trace_options
- grep -q "^userstacktrace" $TRACING_PATH/trace_options
- if [ $? -ne 0 ]; then
- tst_brkm TBROK "Failed to set userstacktrace"
- fi
-
- if [ -f "$EXC_PAGE_FAULT_ENABLE" ]; then
- exc_page_fault_enable=`cat $EXC_PAGE_FAULT_ENABLE`
- echo 1 > $EXC_PAGE_FAULT_ENABLE
- else
- mm_page_fault_enable=`cat $MM_PAGE_FAULT_ENABLE`
- echo 1 > $MM_PAGE_FAULT_ENABLE
- fi
- done
-
- if [ -f "$EXC_PAGE_FAULT_ENABLE" ]; then
- echo "$exc_page_fault_enable" > $EXC_PAGE_FAULT_ENABLE
- else
- echo "$mm_page_fault_enable" > $MM_PAGE_FAULT_ENABLE
- fi
-
- tst_resm TPASS "Finished running the test"
-}
-
-ftrace_userstacktrace_test
-
-tst_exit
--
2.39.3
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 10+ messages in thread
* [LTP] [PATCH 2/2] Rewrite ftrace_regression02.sh with new C API
2026-03-04 8:05 [LTP] [PATCH 1/2] Rewrite ftrace_regression01.sh with new C API lufei
@ 2026-03-04 8:05 ` lufei
2026-03-27 10:34 ` [LTP] [PATCH 1/2] Rewrite ftrace_regression01.sh " Andrea Cervesato via ltp
2026-03-30 7:15 ` [LTP] [PATCH v2] Rewrite ftrace_regression tests " lufei
2 siblings, 0 replies; 10+ messages in thread
From: lufei @ 2026-03-04 8:05 UTC (permalink / raw)
To: ltp; +Cc: lufei
This test is for checking signal:signal_generate gives 2 more fields:
grp res.
Signed-off-by: lufei <lufei@uniontech.com>
---
.../tracing/ftrace_test/ftrace_regression02.c | 73 +++++++++++++++++++
1 file changed, 73 insertions(+)
create mode 100644 testcases/kernel/tracing/ftrace_test/ftrace_regression02.c
diff --git a/testcases/kernel/tracing/ftrace_test/ftrace_regression02.c b/testcases/kernel/tracing/ftrace_test/ftrace_regression02.c
new file mode 100644
index 000000000..aa3500090
--- /dev/null
+++ b/testcases/kernel/tracing/ftrace_test/ftrace_regression02.c
@@ -0,0 +1,73 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2015 Red Hat Inc.
+ * Copyright (c) 2026 lufei <lufei@uniontech.com>
+ */
+
+/*\
+ *
+ * Check signal:signal_generate gives 2 more fields: grp res
+ *
+ */
+
+#include <unistd.h>
+#include <stdio.h>
+#include "ftrace_regression.h"
+
+#define DEBUGFS_DIR "debugfs"
+#define SET_EVENT DEBUGFS_DIR "/tracing/set_event"
+#define TRACING_ON DEBUGFS_DIR "/tracing/tracing_on"
+#define TRACE_FILE DEBUGFS_DIR "/tracing/trace"
+
+#define LOOP 100
+
+static void setup(void)
+{
+ SAFE_MKDIR(DEBUGFS_DIR, 0755);
+ SAFE_MOUNT(NULL, DEBUGFS_DIR, "debugfs", 0, NULL);
+}
+
+static void run(void)
+{
+ int i;
+
+ SAFE_FILE_PRINTF(SET_EVENT, "signal:signal_generate");
+ SAFE_FILE_PRINTF(TRACING_ON, "1");
+ SAFE_FILE_PRINTF(TRACE_FILE, "\n");
+
+ for (i = 0; i < LOOP; i++)
+ tst_cmd((const char *[]){"ls", "-l", "/proc", NULL},
+ "/dev/null", "/dev/null", 0);
+
+ if (file_contains(TRACE_FILE, "grp=") && file_contains(TRACE_FILE, "res="))
+ tst_res(TPASS, "Finished running the test");
+ else
+ tst_res(TFAIL, "Pattern grp=[0-9] res=[0-9] not found in trace");
+}
+
+static void cleanup(void)
+{
+ SAFE_UMOUNT(DEBUGFS_DIR);
+}
+
+static struct tst_test test = {
+ .needs_root = 1,
+ .needs_tmpdir = 1,
+ .setup = setup,
+ .test_all = run,
+ .cleanup = cleanup,
+ .needs_cmds = (struct tst_cmd[]) {
+ {.cmd = "ls"},
+ {}
+ },
+ .save_restore = (const struct tst_path_val[]) {
+ {"/proc/sys/kernel/stack_tracer_enabled", NULL, TST_SR_TCONF},
+ {}
+ },
+ .tags = (const struct tst_tag[]) {
+ {"linux-git", "6c303d3"},
+ {"linux-git", "163566f"},
+ {}
+ },
+};
+
--
2.39.3
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [LTP] [PATCH 1/2] Rewrite ftrace_regression01.sh with new C API
2026-03-04 8:05 [LTP] [PATCH 1/2] Rewrite ftrace_regression01.sh with new C API lufei
2026-03-04 8:05 ` [LTP] [PATCH 2/2] Rewrite ftrace_regression02.sh " lufei
@ 2026-03-27 10:34 ` Andrea Cervesato via ltp
2026-03-30 7:15 ` [LTP] [PATCH v2] Rewrite ftrace_regression tests " lufei
2 siblings, 0 replies; 10+ messages in thread
From: Andrea Cervesato via ltp @ 2026-03-27 10:34 UTC (permalink / raw)
To: lufei; +Cc: lufei, ltp
Hi lufei,
A few issues need fixing before this can be merged.
[PATCH 1/2]
> +/*\
> + * [Description]
> + *
> + * Regression test for panic while using userstacktrace.
Drop the [Description] tag, it's deprecated.
> +#define FTRACE_FILE_CONTAINS_BUF_SIZE (1024 * 1024)
[...]
> +static inline int file_contains(const char *path, const char *str)
> +{
> + char buf[FTRACE_FILE_CONTAINS_BUF_SIZE];
This puts 1 MiB on the stack. Use SAFE_MALLOC/free or a static buffer
instead.
> + if (!file_contains(TRACE_OPTIONS, "userstacktrace"))
> + tst_brk(TBROK, "Failed to set userstacktrace");
strstr("nouserstacktrace", "userstacktrace") is true, so this check
always passes even when the option is disabled. The original shell
version used grep -q "^userstacktrace" which anchored to line start.
[PATCH 2/2]
> --- /dev/null
> +++ b/testcases/kernel/tracing/ftrace_test/ftrace_regression02.c
The old ftrace_regression02.sh is not deleted by this patch. You need
to remove it, same as you did for ftrace_regression01.sh in patch 1/2.
> + .save_restore = (const struct tst_path_val[]) {
> + {"/proc/sys/kernel/stack_tracer_enabled", NULL, TST_SR_TCONF},
> + {}
> + },
This test doesn't use stack_tracer_enabled. Looks like copy-paste from
ftrace_regression01. Remove it.
The original shell test gated on kernel >= 3.2. Add .min_kver = "3.2"
to preserve that check.
[Both patches]
The runtest/tracing entries still reference the .sh files:
ftrace_regression01 ftrace_regression01.sh
ftrace_regression02 ftrace_regression02.sh
Update them to point to the C binaries.
The Makefile has INSTALL_TARGETS := *.sh ftrace_stress/* which won't
install the new C binaries. It needs updating as well.
Regards,
--
Andrea Cervesato
SUSE QE Automation Engineer Linux
andrea.cervesato@suse.com
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 10+ messages in thread
* [LTP] [PATCH v2] Rewrite ftrace_regression tests with new C API
2026-03-04 8:05 [LTP] [PATCH 1/2] Rewrite ftrace_regression01.sh with new C API lufei
2026-03-04 8:05 ` [LTP] [PATCH 2/2] Rewrite ftrace_regression02.sh " lufei
2026-03-27 10:34 ` [LTP] [PATCH 1/2] Rewrite ftrace_regression01.sh " Andrea Cervesato via ltp
@ 2026-03-30 7:15 ` lufei
2026-03-30 8:39 ` Andrea Cervesato via ltp
2026-03-31 1:55 ` [LTP] [PATCH v3] " lufei
2 siblings, 2 replies; 10+ messages in thread
From: lufei @ 2026-03-30 7:15 UTC (permalink / raw)
To: ltp; +Cc: lufei
Rewritten from old shell scripts.
ftrace_regression01: regression test for panic bug while using
userstacktrace, set userstacktrace in loop and check if success.
ftrace_regression02: for checking signal:signal_generate gives
2 more fields: grp res.
Signed-off-by: lufei <lufei@uniontech.com>
---
runtest/tracing | 4 +-
testcases/kernel/tracing/ftrace_test/Makefile | 3 +-
.../tracing/ftrace_test/ftrace_regression.h | 65 +++++++++++++++
.../tracing/ftrace_test/ftrace_regression01.c | 83 +++++++++++++++++++
.../ftrace_test/ftrace_regression01.sh | 83 -------------------
.../tracing/ftrace_test/ftrace_regression02.c | 70 ++++++++++++++++
.../ftrace_test/ftrace_regression02.sh | 63 --------------
7 files changed, 222 insertions(+), 149 deletions(-)
create mode 100644 testcases/kernel/tracing/ftrace_test/ftrace_regression.h
create mode 100644 testcases/kernel/tracing/ftrace_test/ftrace_regression01.c
delete mode 100755 testcases/kernel/tracing/ftrace_test/ftrace_regression01.sh
create mode 100644 testcases/kernel/tracing/ftrace_test/ftrace_regression02.c
delete mode 100755 testcases/kernel/tracing/ftrace_test/ftrace_regression02.sh
diff --git a/runtest/tracing b/runtest/tracing
index 674e2ad97..2a4a92c5f 100644
--- a/runtest/tracing
+++ b/runtest/tracing
@@ -1,6 +1,6 @@
#DESCRIPTION:Tracing testing
-ftrace_regression01 ftrace_regression01.sh
-ftrace_regression02 ftrace_regression02.sh
+ftrace_regression01 ftrace_regression01
+ftrace_regression02 ftrace_regression02
ftrace-stress-test ftrace_stress_test.sh 90
dynamic_debug01 dynamic_debug01.sh
fanotify25 fanotify25
diff --git a/testcases/kernel/tracing/ftrace_test/Makefile b/testcases/kernel/tracing/ftrace_test/Makefile
index e4a913a56..618cce7e1 100644
--- a/testcases/kernel/tracing/ftrace_test/Makefile
+++ b/testcases/kernel/tracing/ftrace_test/Makefile
@@ -2,6 +2,7 @@ top_srcdir ?= ../../../..
include $(top_srcdir)/include/mk/testcases.mk
-INSTALL_TARGETS := *.sh ftrace_stress/*
+INSTALL_TARGETS := *.sh ftrace_stress/* ftrace_regression01 \
+ ftrace_regression02
include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/tracing/ftrace_test/ftrace_regression.h b/testcases/kernel/tracing/ftrace_test/ftrace_regression.h
new file mode 100644
index 000000000..710276202
--- /dev/null
+++ b/testcases/kernel/tracing/ftrace_test/ftrace_regression.h
@@ -0,0 +1,65 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later
+ *
+ * Copyright (c) 2026 lufei <lufei@uniontech.com>
+ *
+ * Shared header for ftrace regression tests.
+ */
+
+#ifndef FTRACE_REGRESSION_H
+#define FTRACE_REGRESSION_H
+
+#include "tst_test.h"
+#include "tst_safe_file_ops.h"
+#include "tst_safe_stdio.h"
+
+#include <string.h>
+
+#define FTRACE_FILE_BUF_SIZE (1024*1024)
+#define FTRACE_LINE_BUF_SIZE 1024
+
+/**
+ * file_contains - Check if a file contains the given string
+ * path: Path to the file
+ * str: String to search for
+ *
+ * Returns: 1 if file contains str, 0 otherwise
+ */
+static inline int file_contains(const char *path, const char *str)
+{
+ char *buf = SAFE_MALLOC(FTRACE_FILE_BUF_SIZE);
+ bool found = false;
+
+ buf[0] = '\0';
+ SAFE_FILE_SCANF(path, "%1048575[^\x01]", buf);
+ found = strstr(buf, str) != NULL;
+ free(buf);
+
+ return found;
+}
+
+/**
+ * file_contains_line - Check if a file ocntains specific line, strictly
+ *
+ */
+static inline int file_contains_line(const char *path, const char *str)
+{
+ char *buf = SAFE_MALLOC(FTRACE_LINE_BUF_SIZE);
+ bool found = false;
+ FILE *fp = SAFE_FOPEN(path, "r");
+
+ while (fgets(buf, FTRACE_LINE_BUF_SIZE, fp)) {
+ buf[strcspn(buf, "\r\n")] = 0;
+ if (strcmp(buf, str) == 0) {
+ found = true;
+ break;
+ }
+ }
+
+ SAFE_FCLOSE(fp);
+ free(buf);
+
+ return found;
+}
+
+#endif /* FTRACE_REGRESSION_H */
+
diff --git a/testcases/kernel/tracing/ftrace_test/ftrace_regression01.c b/testcases/kernel/tracing/ftrace_test/ftrace_regression01.c
new file mode 100644
index 000000000..a67d07fd1
--- /dev/null
+++ b/testcases/kernel/tracing/ftrace_test/ftrace_regression01.c
@@ -0,0 +1,83 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2015 Red Hat Inc.
+ * Copyright (c) 2026 lufei <lufei@uniontech.com>
+ */
+
+/*\
+ * Regression test for panic while using userstacktrace.
+ *
+ * BUG: unable to handle kernel paging request at 00000000417683c0
+ * IP: [<ffffffff8105c834>] update_curr+0x124/0x1e0
+ * Thread overran stack, or stack corrupted
+ * Oops: 0000 [#1] SMP
+ * last sysfs file: ../system/cpu/cpu15/cache/index2/shared_cpu_map
+ *
+ * The bug was fixed by:
+ * 1dbd195 (tracing: Fix preempt count leak)
+ */
+
+#include <unistd.h>
+#include <stdio.h>
+#include "ftrace_regression.h"
+
+#define DEBUGFS_DIR "debugfs"
+#define STACK_TRACER_PATH "/proc/sys/kernel/stack_tracer_enabled"
+#define TRACE_OPTIONS DEBUGFS_DIR "/tracing/trace_options"
+#define EXC_PAGE_FAULT DEBUGFS_DIR "/tracing/events/exceptions/page_fault_kernel/enable"
+#define MM_PAGE_FAULT DEBUGFS_DIR "/tracing/events/kmem/mm_kernel_pagefault/enable"
+
+#define LOOP 10
+
+static const char *page_fault_path;
+
+static void setup(void)
+{
+ SAFE_MKDIR(DEBUGFS_DIR, 0755);
+ SAFE_MOUNT(NULL, DEBUGFS_DIR, "debugfs", 0, NULL);
+
+ if (access(EXC_PAGE_FAULT, F_OK) == 0)
+ page_fault_path = EXC_PAGE_FAULT;
+ else if (access(MM_PAGE_FAULT, F_OK) == 0)
+ page_fault_path = MM_PAGE_FAULT;
+ else
+ tst_brk(TCONF, "Page fault event not available");
+}
+
+static void run(void)
+{
+ int i;
+
+ for (i = 0; i < LOOP; i++) {
+ SAFE_FILE_PRINTF(STACK_TRACER_PATH, "1");
+ SAFE_FILE_PRINTF(TRACE_OPTIONS, "userstacktrace");
+
+ if (!file_contains_line(TRACE_OPTIONS, "userstacktrace"))
+ tst_brk(TBROK, "Failed to set userstacktrace");
+
+ SAFE_FILE_PRINTF(page_fault_path, "1");
+ }
+
+ tst_res(TPASS, "Finished running the test");
+}
+
+static void cleanup(void)
+{
+ SAFE_UMOUNT(DEBUGFS_DIR);
+}
+
+static struct tst_test test = {
+ .needs_root = 1,
+ .needs_tmpdir = 1,
+ .setup = setup,
+ .test_all = run,
+ .cleanup = cleanup,
+ .save_restore = (const struct tst_path_val[]) {
+ {STACK_TRACER_PATH, NULL, TST_SR_TCONF},
+ {}
+ },
+ .tags = (const struct tst_tag[]) {
+ {"linux-git", "1dbd195"},
+ {}
+ },
+};
diff --git a/testcases/kernel/tracing/ftrace_test/ftrace_regression01.sh b/testcases/kernel/tracing/ftrace_test/ftrace_regression01.sh
deleted file mode 100755
index d6969cfc6..000000000
--- a/testcases/kernel/tracing/ftrace_test/ftrace_regression01.sh
+++ /dev/null
@@ -1,83 +0,0 @@
-#! /bin/sh
-
-###########################################################################
-## ##
-## Copyright (c) 2015, Red Hat Inc. ##
-## ##
-## This program is free software: you can redistribute it and/or modify ##
-## it under the terms of the GNU General Public License as published by ##
-## the Free Software Foundation, either version 3 of the License, or ##
-## (at your option) any later version. ##
-## ##
-## This program is distributed in the hope that it will be useful, ##
-## but WITHOUT ANY WARRANTY; without even the implied warranty of ##
-## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ##
-## GNU General Public License for more details. ##
-## ##
-## You should have received a copy of the GNU General Public License ##
-## along with this program. If not, see <http://www.gnu.org/licenses/>. ##
-## ##
-## Author: Li Wang <liwang@redhat.com> ##
-## ##
-###########################################################################
-## ##
-## Summary: panic while using userstacktrace ##
-## ##
-## BUG: unable to handle kernel paging request at 00000000417683c0 ##
-## IP: [<ffffffff8105c834>] update_curr+0x124/0x1e0 ##
-## PGD 41a796067 PUD 0 ##
-## Thread overran stack, or stack corrupted ##
-## Oops: 0000 [#1] SMP ##
-## last sysfs file: ../system/cpu/cpu15/cache/index2/shared_cpu_map ##
-## ##
-## The bug was fixed by: ##
-## 1dbd195 (tracing: Fix preempt count leak) ##
-## ##
-###########################################################################
-
-export TCID="ftrace_regression01"
-export TST_TOTAL=1
-
-. ftrace_lib.sh
-
-LOOP=10
-
-TSTACK_TRACE_PATH="/proc/sys/kernel/stack_tracer_enabled"
-EXC_PAGE_FAULT_ENABLE="$TRACING_PATH/events/exceptions/page_fault_kernel/enable"
-MM_PAGE_FAULT_ENABLE="$TRACING_PATH/events/kmem/mm_kernel_pagefault/enable"
-
-ftrace_userstacktrace_test()
-{
- if [ ! -e "$TSTACK_TRACE_PATH" ]; then
- tst_brkm TCONF "Stack Tracer is not cofigured in This kernel"
- fi
-
- for i in $(seq $LOOP); do
- echo 1 > $TSTACK_TRACE_PATH
- echo userstacktrace > $TRACING_PATH/trace_options
- grep -q "^userstacktrace" $TRACING_PATH/trace_options
- if [ $? -ne 0 ]; then
- tst_brkm TBROK "Failed to set userstacktrace"
- fi
-
- if [ -f "$EXC_PAGE_FAULT_ENABLE" ]; then
- exc_page_fault_enable=`cat $EXC_PAGE_FAULT_ENABLE`
- echo 1 > $EXC_PAGE_FAULT_ENABLE
- else
- mm_page_fault_enable=`cat $MM_PAGE_FAULT_ENABLE`
- echo 1 > $MM_PAGE_FAULT_ENABLE
- fi
- done
-
- if [ -f "$EXC_PAGE_FAULT_ENABLE" ]; then
- echo "$exc_page_fault_enable" > $EXC_PAGE_FAULT_ENABLE
- else
- echo "$mm_page_fault_enable" > $MM_PAGE_FAULT_ENABLE
- fi
-
- tst_resm TPASS "Finished running the test"
-}
-
-ftrace_userstacktrace_test
-
-tst_exit
diff --git a/testcases/kernel/tracing/ftrace_test/ftrace_regression02.c b/testcases/kernel/tracing/ftrace_test/ftrace_regression02.c
new file mode 100644
index 000000000..97dbaf371
--- /dev/null
+++ b/testcases/kernel/tracing/ftrace_test/ftrace_regression02.c
@@ -0,0 +1,70 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2015 Red Hat Inc.
+ * Copyright (c) 2026 lufei <lufei@uniontech.com>
+ */
+
+/*\
+ *
+ * Check signal:signal_generate gives 2 more fields: grp res
+ *
+ */
+
+#include <unistd.h>
+#include <stdio.h>
+#include "ftrace_regression.h"
+
+#define DEBUGFS_DIR "debugfs"
+#define SET_EVENT DEBUGFS_DIR "/tracing/set_event"
+#define TRACING_ON DEBUGFS_DIR "/tracing/tracing_on"
+#define TRACE_FILE DEBUGFS_DIR "/tracing/trace"
+
+#define LOOP 100
+
+static void setup(void)
+{
+ SAFE_MKDIR(DEBUGFS_DIR, 0755);
+ SAFE_MOUNT(NULL, DEBUGFS_DIR, "debugfs", 0, NULL);
+}
+
+static void run(void)
+{
+ int i;
+
+ SAFE_FILE_PRINTF(SET_EVENT, "signal:signal_generate");
+ SAFE_FILE_PRINTF(TRACING_ON, "1");
+ SAFE_FILE_PRINTF(TRACE_FILE, "\n");
+
+ for (i = 0; i < LOOP; i++)
+ tst_cmd((const char *[]){"ls", "-l", "/proc", NULL},
+ "/dev/null", "/dev/null", 0);
+
+ if (file_contains(TRACE_FILE, "grp=") && file_contains(TRACE_FILE, "res="))
+ tst_res(TPASS, "Finished running the test");
+ else
+ tst_res(TFAIL, "Pattern grp=[0-9] res=[0-9] not found in trace");
+}
+
+static void cleanup(void)
+{
+ SAFE_UMOUNT(DEBUGFS_DIR);
+}
+
+static struct tst_test test = {
+ .needs_root = 1,
+ .needs_tmpdir = 1,
+ .setup = setup,
+ .test_all = run,
+ .cleanup = cleanup,
+ .needs_cmds = (struct tst_cmd[]) {
+ {.cmd = "ls"},
+ {}
+ },
+ .min_kver = "3.2",
+ .tags = (const struct tst_tag[]) {
+ {"linux-git", "6c303d3"},
+ {"linux-git", "163566f"},
+ {}
+ },
+};
+
diff --git a/testcases/kernel/tracing/ftrace_test/ftrace_regression02.sh b/testcases/kernel/tracing/ftrace_test/ftrace_regression02.sh
deleted file mode 100755
index 3c32f219e..000000000
--- a/testcases/kernel/tracing/ftrace_test/ftrace_regression02.sh
+++ /dev/null
@@ -1,63 +0,0 @@
-#! /bin/sh
-
-###########################################################################
-## ##
-## Copyright (c) 2015, Red Hat Inc. ##
-## ##
-## This program is free software: you can redistribute it and/or modify ##
-## it under the terms of the GNU General Public License as published by ##
-## the Free Software Foundation, either version 3 of the License, or ##
-## (at your option) any later version. ##
-## ##
-## This program is distributed in the hope that it will be useful, ##
-## but WITHOUT ANY WARRANTY; without even the implied warranty of ##
-## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ##
-## GNU General Public License for more details. ##
-## ##
-## You should have received a copy of the GNU General Public License ##
-## along with this program. If not, see <http://www.gnu.org/licenses/>. ##
-## ##
-## Author: Li Wang <liwang@redhat.com> ##
-## ##
-###########################################################################
-## ##
-## Summary: check signal:signal_generate gives 2 more fields: grp res ##
-## ##
-## This testcase is writing for signal events change: ##
-## 6c303d3 tracing: let trace_signal_generate() report more info...##
-## 163566f tracing: send_sigqueue() needs trace_signal_generate() ##
-## ##
-###########################################################################
-
-export TCID="ftrace_regression02"
-export TST_TOTAL=1
-
-. ftrace_lib.sh
-
-ftrace_signal_test()
-{
- # Set envent
- echo 'signal:signal_generate' > $TRACING_PATH/set_event
- echo 1 > $TRACING_PATH/tracing_on
- echo > $TRACING_PATH/trace
-
- # just to generate trace
- for i in $(seq 100); do
- ls -l /proc > /dev/null 2>&1
- done
-
- grep -q 'grp=[0-9] res=[0-9]' $TRACING_PATH/trace
- if [ $? -eq 0 ]; then
- tst_resm TPASS "finished running the test."
- else
- tst_resm TFAIL "running the test failed, please check log message."
- fi
-}
-
-if tst_kvcmp -lt "3.2"; then
- tst_brkm TCONF "The test should be run in kernels >= 3.2.0 Skip the test..."
-fi
-
-ftrace_signal_test
-
-tst_exit
--
2.39.3
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [LTP] [PATCH v2] Rewrite ftrace_regression tests with new C API
2026-03-30 7:15 ` [LTP] [PATCH v2] Rewrite ftrace_regression tests " lufei
@ 2026-03-30 8:39 ` Andrea Cervesato via ltp
2026-03-31 1:55 ` [LTP] [PATCH v3] " lufei
1 sibling, 0 replies; 10+ messages in thread
From: Andrea Cervesato via ltp @ 2026-03-30 8:39 UTC (permalink / raw)
To: lufei; +Cc: lufei, ltp
Hi lufei,
> +/**
> + * file_contains_line - Check if a file ocntains specific line, strictly
Typo: "ocntains" -> "contains".
> +static inline int file_contains(const char *path, const char *str)
> +{
> + char *buf = SAFE_MALLOC(FTRACE_FILE_BUF_SIZE);
> +
> + buf[0] = '\0';
> + SAFE_FILE_SCANF(path, "%1048575[^\x01]", buf);
The hardcoded width 1048575 must be kept in sync with FTRACE_FILE_BUF_SIZE - 1
manually. Also, allocating 1 MB on each call is heavy — file_contains() is
called twice in ftrace_regression02. Consider a simpler file reading approach.
> diff --git a/testcases/kernel/tracing/ftrace_test/ftrace_regression01.c b/testcases/kernel/tracing/ftrace_test/ftrace_regression01.c
> new file mode 100644
[...]
> + for (i = 0; i < LOOP; i++) {
> + SAFE_FILE_PRINTF(STACK_TRACER_PATH, "1");
> + SAFE_FILE_PRINTF(TRACE_OPTIONS, "userstacktrace");
[...]
> + SAFE_FILE_PRINTF(page_fault_path, "1");
> + }
The old shell script saved and restored the page fault enable value after
the loop. This version writes "1" but never restores it. Unmounting debugfs
does not reset kernel tracing state. Please add the page_fault_path to
.save_restore or save/restore it manually.
> diff --git a/testcases/kernel/tracing/ftrace_test/ftrace_regression02.c b/testcases/kernel/tracing/ftrace_test/ftrace_regression02.c
> new file mode 100644
[...]
> +/*\
> + *
> + * Check signal:signal_generate gives 2 more fields: grp res
> + *
> + */
Remove the blank lines before/after the description inside the /*\ block.
> + if (file_contains(TRACE_FILE, "grp=") && file_contains(TRACE_FILE, "res="))
The old test used 'grp=[0-9] res=[0-9]' which verified both fields appear on
the same line with digit values. This only checks for substrings independently,
which is less strict.
Also, there is no .gitignore in the ftrace_test directory. Please add one
with entries for ftrace_regression01 and ftrace_regression02.
Regards,
--
Andrea Cervesato
SUSE QE Automation Engineer Linux
andrea.cervesato@suse.com
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 10+ messages in thread
* [LTP] [PATCH v3] Rewrite ftrace_regression tests with new C API
2026-03-30 7:15 ` [LTP] [PATCH v2] Rewrite ftrace_regression tests " lufei
2026-03-30 8:39 ` Andrea Cervesato via ltp
@ 2026-03-31 1:55 ` lufei
2026-03-31 7:53 ` Petr Vorel
` (2 more replies)
1 sibling, 3 replies; 10+ messages in thread
From: lufei @ 2026-03-31 1:55 UTC (permalink / raw)
To: ltp; +Cc: lufei
Rewritten from old shell scripts.
ftrace_regression01: regression test for panic bug while using
userstacktrace, set userstacktrace in loop and check if success.
ftrace_regression02: for checking signal:signal_generate gives
2 more fields: grp res.
Signed-off-by: lufei <lufei@uniontech.com>
---
runtest/tracing | 4 +-
.../kernel/tracing/ftrace_test/.gitignore | 2 +
testcases/kernel/tracing/ftrace_test/Makefile | 3 +-
.../tracing/ftrace_test/ftrace_regression.h | 49 +++++++++++
.../tracing/ftrace_test/ftrace_regression01.c | 88 +++++++++++++++++++
.../ftrace_test/ftrace_regression01.sh | 83 -----------------
.../tracing/ftrace_test/ftrace_regression02.c | 68 ++++++++++++++
.../ftrace_test/ftrace_regression02.sh | 63 -------------
8 files changed, 211 insertions(+), 149 deletions(-)
create mode 100644 testcases/kernel/tracing/ftrace_test/.gitignore
create mode 100644 testcases/kernel/tracing/ftrace_test/ftrace_regression.h
create mode 100644 testcases/kernel/tracing/ftrace_test/ftrace_regression01.c
delete mode 100755 testcases/kernel/tracing/ftrace_test/ftrace_regression01.sh
create mode 100644 testcases/kernel/tracing/ftrace_test/ftrace_regression02.c
delete mode 100755 testcases/kernel/tracing/ftrace_test/ftrace_regression02.sh
diff --git a/runtest/tracing b/runtest/tracing
index 674e2ad97..2a4a92c5f 100644
--- a/runtest/tracing
+++ b/runtest/tracing
@@ -1,6 +1,6 @@
#DESCRIPTION:Tracing testing
-ftrace_regression01 ftrace_regression01.sh
-ftrace_regression02 ftrace_regression02.sh
+ftrace_regression01 ftrace_regression01
+ftrace_regression02 ftrace_regression02
ftrace-stress-test ftrace_stress_test.sh 90
dynamic_debug01 dynamic_debug01.sh
fanotify25 fanotify25
diff --git a/testcases/kernel/tracing/ftrace_test/.gitignore b/testcases/kernel/tracing/ftrace_test/.gitignore
new file mode 100644
index 000000000..b0153e9fa
--- /dev/null
+++ b/testcases/kernel/tracing/ftrace_test/.gitignore
@@ -0,0 +1,2 @@
+ftrace_regression01
+ftrace_regression02
diff --git a/testcases/kernel/tracing/ftrace_test/Makefile b/testcases/kernel/tracing/ftrace_test/Makefile
index e4a913a56..618cce7e1 100644
--- a/testcases/kernel/tracing/ftrace_test/Makefile
+++ b/testcases/kernel/tracing/ftrace_test/Makefile
@@ -2,6 +2,7 @@ top_srcdir ?= ../../../..
include $(top_srcdir)/include/mk/testcases.mk
-INSTALL_TARGETS := *.sh ftrace_stress/*
+INSTALL_TARGETS := *.sh ftrace_stress/* ftrace_regression01 \
+ ftrace_regression02
include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/tracing/ftrace_test/ftrace_regression.h b/testcases/kernel/tracing/ftrace_test/ftrace_regression.h
new file mode 100644
index 000000000..82687089b
--- /dev/null
+++ b/testcases/kernel/tracing/ftrace_test/ftrace_regression.h
@@ -0,0 +1,49 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later
+ *
+ * Copyright (c) 2026 lufei <lufei@uniontech.com>
+ *
+ * Shared header for ftrace regression tests.
+ */
+
+#ifndef FTRACE_REGRESSION_H
+#define FTRACE_REGRESSION_H
+
+#include "tst_test.h"
+#include "tst_safe_file_ops.h"
+#include "tst_safe_stdio.h"
+
+#include <string.h>
+#include <regex.h>
+
+#define FTRACE_LINE_BUF_SIZE 1024
+
+/**
+ * file_contains - Check if a file contains specific regex pattern.
+ */
+static inline int file_contains(const char *path, const char *pattern)
+{
+ FILE *fp = SAFE_FOPEN(path, "r");
+ char *buf = SAFE_MALLOC(FTRACE_LINE_BUF_SIZE);
+ bool found = false;
+
+ regex_t re;
+
+ if (regcomp(&re, pattern, REG_EXTENDED | REG_NOSUB) != 0) {
+ SAFE_FCLOSE(fp);
+ return found;
+ }
+
+ while (fgets(buf, FTRACE_LINE_BUF_SIZE, fp)) {
+ if (regexec(&re, buf, 0, NULL, 0) == 0) {
+ found = true;
+ break;
+ }
+ }
+
+ regfree(&re);
+ SAFE_FCLOSE(fp);
+ free(buf);
+ return found;
+}
+
+#endif /* FTRACE_REGRESSION_H */
diff --git a/testcases/kernel/tracing/ftrace_test/ftrace_regression01.c b/testcases/kernel/tracing/ftrace_test/ftrace_regression01.c
new file mode 100644
index 000000000..b76d5bf7e
--- /dev/null
+++ b/testcases/kernel/tracing/ftrace_test/ftrace_regression01.c
@@ -0,0 +1,88 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2015 Red Hat Inc.
+ * Copyright (c) 2026 lufei <lufei@uniontech.com>
+ */
+
+/*\
+ * Regression test for panic while using userstacktrace.
+ *
+ * BUG: unable to handle kernel paging request at 00000000417683c0
+ * IP: [<ffffffff8105c834>] update_curr+0x124/0x1e0
+ * Thread overran stack, or stack corrupted
+ * Oops: 0000 [#1] SMP
+ * last sysfs file: ../system/cpu/cpu15/cache/index2/shared_cpu_map
+ *
+ * The bug was fixed by:
+ * 1dbd195 (tracing: Fix preempt count leak)
+ */
+
+#include <unistd.h>
+#include <stdio.h>
+#include "ftrace_regression.h"
+
+#define DEBUGFS_DIR "debugfs"
+#define STACK_TRACER_PATH "/proc/sys/kernel/stack_tracer_enabled"
+#define TRACE_OPTIONS DEBUGFS_DIR "/tracing/trace_options"
+#define EXC_PAGE_FAULT DEBUGFS_DIR "/tracing/events/exceptions/page_fault_kernel/enable"
+#define MM_PAGE_FAULT DEBUGFS_DIR "/tracing/events/kmem/mm_kernel_pagefault/enable"
+
+#define LOOP 10
+
+static const char *page_fault_path;
+static int page_fault_origin;
+
+static void setup(void)
+{
+ SAFE_MKDIR(DEBUGFS_DIR, 0755);
+ SAFE_MOUNT(NULL, DEBUGFS_DIR, "debugfs", 0, NULL);
+
+ if (access(EXC_PAGE_FAULT, F_OK) == 0)
+ page_fault_path = EXC_PAGE_FAULT;
+ else if (access(MM_PAGE_FAULT, F_OK) == 0)
+ page_fault_path = MM_PAGE_FAULT;
+ else
+ tst_brk(TCONF, "Page fault event not available");
+
+ SAFE_FILE_SCANF(page_fault_path, "%d", &page_fault_origin);
+}
+
+static void run(void)
+{
+ int i;
+
+ for (i = 0; i < LOOP; i++) {
+ SAFE_FILE_PRINTF(STACK_TRACER_PATH, "1");
+ SAFE_FILE_PRINTF(TRACE_OPTIONS, "userstacktrace");
+
+ if (!file_contains(TRACE_OPTIONS, "^userstacktrace"))
+ tst_brk(TBROK, "Failed to set userstacktrace");
+
+ SAFE_FILE_PRINTF(page_fault_path, "1");
+ }
+
+ SAFE_FILE_PRINTF(page_fault_path, "%d", page_fault_origin);
+
+ tst_res(TPASS, "Finished running the test");
+}
+
+static void cleanup(void)
+{
+ SAFE_UMOUNT(DEBUGFS_DIR);
+}
+
+static struct tst_test test = {
+ .needs_root = 1,
+ .needs_tmpdir = 1,
+ .setup = setup,
+ .test_all = run,
+ .cleanup = cleanup,
+ .save_restore = (const struct tst_path_val[]) {
+ {STACK_TRACER_PATH, NULL, TST_SR_TCONF},
+ {}
+ },
+ .tags = (const struct tst_tag[]) {
+ {"linux-git", "1dbd195"},
+ {}
+ },
+};
diff --git a/testcases/kernel/tracing/ftrace_test/ftrace_regression01.sh b/testcases/kernel/tracing/ftrace_test/ftrace_regression01.sh
deleted file mode 100755
index d6969cfc6..000000000
--- a/testcases/kernel/tracing/ftrace_test/ftrace_regression01.sh
+++ /dev/null
@@ -1,83 +0,0 @@
-#! /bin/sh
-
-###########################################################################
-## ##
-## Copyright (c) 2015, Red Hat Inc. ##
-## ##
-## This program is free software: you can redistribute it and/or modify ##
-## it under the terms of the GNU General Public License as published by ##
-## the Free Software Foundation, either version 3 of the License, or ##
-## (at your option) any later version. ##
-## ##
-## This program is distributed in the hope that it will be useful, ##
-## but WITHOUT ANY WARRANTY; without even the implied warranty of ##
-## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ##
-## GNU General Public License for more details. ##
-## ##
-## You should have received a copy of the GNU General Public License ##
-## along with this program. If not, see <http://www.gnu.org/licenses/>. ##
-## ##
-## Author: Li Wang <liwang@redhat.com> ##
-## ##
-###########################################################################
-## ##
-## Summary: panic while using userstacktrace ##
-## ##
-## BUG: unable to handle kernel paging request at 00000000417683c0 ##
-## IP: [<ffffffff8105c834>] update_curr+0x124/0x1e0 ##
-## PGD 41a796067 PUD 0 ##
-## Thread overran stack, or stack corrupted ##
-## Oops: 0000 [#1] SMP ##
-## last sysfs file: ../system/cpu/cpu15/cache/index2/shared_cpu_map ##
-## ##
-## The bug was fixed by: ##
-## 1dbd195 (tracing: Fix preempt count leak) ##
-## ##
-###########################################################################
-
-export TCID="ftrace_regression01"
-export TST_TOTAL=1
-
-. ftrace_lib.sh
-
-LOOP=10
-
-TSTACK_TRACE_PATH="/proc/sys/kernel/stack_tracer_enabled"
-EXC_PAGE_FAULT_ENABLE="$TRACING_PATH/events/exceptions/page_fault_kernel/enable"
-MM_PAGE_FAULT_ENABLE="$TRACING_PATH/events/kmem/mm_kernel_pagefault/enable"
-
-ftrace_userstacktrace_test()
-{
- if [ ! -e "$TSTACK_TRACE_PATH" ]; then
- tst_brkm TCONF "Stack Tracer is not cofigured in This kernel"
- fi
-
- for i in $(seq $LOOP); do
- echo 1 > $TSTACK_TRACE_PATH
- echo userstacktrace > $TRACING_PATH/trace_options
- grep -q "^userstacktrace" $TRACING_PATH/trace_options
- if [ $? -ne 0 ]; then
- tst_brkm TBROK "Failed to set userstacktrace"
- fi
-
- if [ -f "$EXC_PAGE_FAULT_ENABLE" ]; then
- exc_page_fault_enable=`cat $EXC_PAGE_FAULT_ENABLE`
- echo 1 > $EXC_PAGE_FAULT_ENABLE
- else
- mm_page_fault_enable=`cat $MM_PAGE_FAULT_ENABLE`
- echo 1 > $MM_PAGE_FAULT_ENABLE
- fi
- done
-
- if [ -f "$EXC_PAGE_FAULT_ENABLE" ]; then
- echo "$exc_page_fault_enable" > $EXC_PAGE_FAULT_ENABLE
- else
- echo "$mm_page_fault_enable" > $MM_PAGE_FAULT_ENABLE
- fi
-
- tst_resm TPASS "Finished running the test"
-}
-
-ftrace_userstacktrace_test
-
-tst_exit
diff --git a/testcases/kernel/tracing/ftrace_test/ftrace_regression02.c b/testcases/kernel/tracing/ftrace_test/ftrace_regression02.c
new file mode 100644
index 000000000..498db29e5
--- /dev/null
+++ b/testcases/kernel/tracing/ftrace_test/ftrace_regression02.c
@@ -0,0 +1,68 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2015 Red Hat Inc.
+ * Copyright (c) 2026 lufei <lufei@uniontech.com>
+ */
+
+/*\
+ * Check signal:signal_generate gives 2 more fields: grp=[0-9] res=[0-9]
+ */
+
+#include <unistd.h>
+#include <stdio.h>
+#include "ftrace_regression.h"
+
+#define DEBUGFS_DIR "debugfs"
+#define SET_EVENT DEBUGFS_DIR "/tracing/set_event"
+#define TRACING_ON DEBUGFS_DIR "/tracing/tracing_on"
+#define TRACE_FILE DEBUGFS_DIR "/tracing/trace"
+
+#define LOOP 100
+
+static void setup(void)
+{
+ SAFE_MKDIR(DEBUGFS_DIR, 0755);
+ SAFE_MOUNT(NULL, DEBUGFS_DIR, "debugfs", 0, NULL);
+}
+
+static void run(void)
+{
+ int i;
+
+ SAFE_FILE_PRINTF(SET_EVENT, "signal:signal_generate");
+ SAFE_FILE_PRINTF(TRACING_ON, "1");
+ SAFE_FILE_PRINTF(TRACE_FILE, "\n");
+
+ for (i = 0; i < LOOP; i++)
+ tst_cmd((const char *[]){"ls", "-l", "/proc", NULL},
+ "/dev/null", "/dev/null", 0);
+
+ if (file_contains(TRACE_FILE, "grp=[0-9]") && file_contains(TRACE_FILE, "res=[0-9]"))
+ tst_res(TPASS, "Finished running the test");
+ else
+ tst_res(TFAIL, "Pattern grp=[0-9] res=[0-9] not found in trace");
+}
+
+static void cleanup(void)
+{
+ SAFE_UMOUNT(DEBUGFS_DIR);
+}
+
+static struct tst_test test = {
+ .needs_root = 1,
+ .needs_tmpdir = 1,
+ .setup = setup,
+ .test_all = run,
+ .cleanup = cleanup,
+ .needs_cmds = (struct tst_cmd[]) {
+ {.cmd = "ls"},
+ {}
+ },
+ .min_kver = "3.2",
+ .tags = (const struct tst_tag[]) {
+ {"linux-git", "6c303d3"},
+ {"linux-git", "163566f"},
+ {}
+ },
+};
+
diff --git a/testcases/kernel/tracing/ftrace_test/ftrace_regression02.sh b/testcases/kernel/tracing/ftrace_test/ftrace_regression02.sh
deleted file mode 100755
index 3c32f219e..000000000
--- a/testcases/kernel/tracing/ftrace_test/ftrace_regression02.sh
+++ /dev/null
@@ -1,63 +0,0 @@
-#! /bin/sh
-
-###########################################################################
-## ##
-## Copyright (c) 2015, Red Hat Inc. ##
-## ##
-## This program is free software: you can redistribute it and/or modify ##
-## it under the terms of the GNU General Public License as published by ##
-## the Free Software Foundation, either version 3 of the License, or ##
-## (at your option) any later version. ##
-## ##
-## This program is distributed in the hope that it will be useful, ##
-## but WITHOUT ANY WARRANTY; without even the implied warranty of ##
-## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ##
-## GNU General Public License for more details. ##
-## ##
-## You should have received a copy of the GNU General Public License ##
-## along with this program. If not, see <http://www.gnu.org/licenses/>. ##
-## ##
-## Author: Li Wang <liwang@redhat.com> ##
-## ##
-###########################################################################
-## ##
-## Summary: check signal:signal_generate gives 2 more fields: grp res ##
-## ##
-## This testcase is writing for signal events change: ##
-## 6c303d3 tracing: let trace_signal_generate() report more info...##
-## 163566f tracing: send_sigqueue() needs trace_signal_generate() ##
-## ##
-###########################################################################
-
-export TCID="ftrace_regression02"
-export TST_TOTAL=1
-
-. ftrace_lib.sh
-
-ftrace_signal_test()
-{
- # Set envent
- echo 'signal:signal_generate' > $TRACING_PATH/set_event
- echo 1 > $TRACING_PATH/tracing_on
- echo > $TRACING_PATH/trace
-
- # just to generate trace
- for i in $(seq 100); do
- ls -l /proc > /dev/null 2>&1
- done
-
- grep -q 'grp=[0-9] res=[0-9]' $TRACING_PATH/trace
- if [ $? -eq 0 ]; then
- tst_resm TPASS "finished running the test."
- else
- tst_resm TFAIL "running the test failed, please check log message."
- fi
-}
-
-if tst_kvcmp -lt "3.2"; then
- tst_brkm TCONF "The test should be run in kernels >= 3.2.0 Skip the test..."
-fi
-
-ftrace_signal_test
-
-tst_exit
--
2.39.3
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [LTP] [PATCH v3] Rewrite ftrace_regression tests with new C API
2026-03-31 1:55 ` [LTP] [PATCH v3] " lufei
@ 2026-03-31 7:53 ` Petr Vorel
2026-03-31 7:56 ` Petr Vorel
2026-03-31 10:01 ` [LTP] [PATCH v4] " lufei
2 siblings, 0 replies; 10+ messages in thread
From: Petr Vorel @ 2026-03-31 7:53 UTC (permalink / raw)
To: lufei; +Cc: ltp
Hi lufei,
> Rewritten from old shell scripts.
> ftrace_regression01: regression test for panic bug while using
> userstacktrace, set userstacktrace in loop and check if success.
> ftrace_regression02: for checking signal:signal_generate gives
> 2 more fields: grp res.
Thanks for the rewrite. Few things should be changed.
> +++ b/testcases/kernel/tracing/ftrace_test/Makefile
> @@ -2,6 +2,7 @@ top_srcdir ?= ../../../..
> include $(top_srcdir)/include/mk/testcases.mk
> -INSTALL_TARGETS := *.sh ftrace_stress/*
> +INSTALL_TARGETS := *.sh ftrace_stress/* ftrace_regression01 \
> + ftrace_regression02
It's nice to actually run make install to verify it works:
$ make install
../../../../include/mk/env_post.mk:65: warning: overriding recipe for target '/opt/ltp/testcases/bin/ftrace_regression01'
../../../../include/mk/env_post.mk:64: warning: ignoring old recipe for target '/opt/ltp/testcases/bin/ftrace_regression01'
../../../../include/mk/env_post.mk:65: warning: overriding recipe for target '/opt/ltp/testcases/bin/ftrace_regression02'
../../../../include/mk/env_post.mk:64: warning: ignoring old recipe for target '/opt/ltp/testcases/bin/ftrace_regression02'
=> ftrace_regression01 ftrace_regression02 should not be added (C sources are already included).
...
> +#endif /* FTRACE_REGRESSION_H */
> diff --git a/testcases/kernel/tracing/ftrace_test/ftrace_regression01.c b/testcases/kernel/tracing/ftrace_test/ftrace_regression01.c
> new file mode 100644
> index 000000000..b76d5bf7e
> --- /dev/null
> +++ b/testcases/kernel/tracing/ftrace_test/ftrace_regression01.c
> @@ -0,0 +1,88 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Copyright (c) 2015 Red Hat Inc.
> + * Copyright (c) 2026 lufei <lufei@uniontech.com>
> + */
> +
> +/*\
> + * Regression test for panic while using userstacktrace.
> + *
> + * BUG: unable to handle kernel paging request at 00000000417683c0
> + * IP: [<ffffffff8105c834>] update_curr+0x124/0x1e0
> + * Thread overran stack, or stack corrupted
> + * Oops: 0000 [#1] SMP
> + * last sysfs file: ../system/cpu/cpu15/cache/index2/shared_cpu_map
> + *
> + * The bug was fixed by:
> + * 1dbd195 (tracing: Fix preempt count leak)
Please use longer hash (12 chars).
> + */
> +
> +#include <unistd.h>
> +#include <stdio.h>
> +#include "ftrace_regression.h"
> +
> +#define DEBUGFS_DIR "debugfs"
> +#define STACK_TRACER_PATH "/proc/sys/kernel/stack_tracer_enabled"
> +#define TRACE_OPTIONS DEBUGFS_DIR "/tracing/trace_options"
> +#define EXC_PAGE_FAULT DEBUGFS_DIR "/tracing/events/exceptions/page_fault_kernel/enable"
> +#define MM_PAGE_FAULT DEBUGFS_DIR "/tracing/events/kmem/mm_kernel_pagefault/enable"
> +
> +#define LOOP 10
> +
> +static const char *page_fault_path;
> +static int page_fault_origin;
> +
> +static void setup(void)
> +{
> + SAFE_MKDIR(DEBUGFS_DIR, 0755);
> + SAFE_MOUNT(NULL, DEBUGFS_DIR, "debugfs", 0, NULL);
Maybe have helpers for mounting/unmounting debugfs in the header?
> +
> + if (access(EXC_PAGE_FAULT, F_OK) == 0)
> + page_fault_path = EXC_PAGE_FAULT;
> + else if (access(MM_PAGE_FAULT, F_OK) == 0)
> + page_fault_path = MM_PAGE_FAULT;
> + else
> + tst_brk(TCONF, "Page fault event not available");
> +
> + SAFE_FILE_SCANF(page_fault_path, "%d", &page_fault_origin);
> +}
> +
> +static void run(void)
> +{
> + int i;
> +
> + for (i = 0; i < LOOP; i++) {
> + SAFE_FILE_PRINTF(STACK_TRACER_PATH, "1");
> + SAFE_FILE_PRINTF(TRACE_OPTIONS, "userstacktrace");
> +
> + if (!file_contains(TRACE_OPTIONS, "^userstacktrace"))
> + tst_brk(TBROK, "Failed to set userstacktrace");
> +
> + SAFE_FILE_PRINTF(page_fault_path, "1");
> + }
> +
> + SAFE_FILE_PRINTF(page_fault_path, "%d", page_fault_origin);
> +
> + tst_res(TPASS, "Finished running the test");
Rewrite is not blind converting shell into C, but opportunity to improve the test.
Can we, please, have a meaningful message what passed?
> +}
> +
> +static void cleanup(void)
> +{
> + SAFE_UMOUNT(DEBUGFS_DIR);
> +}
> +
> +static struct tst_test test = {
> + .needs_root = 1,
> + .needs_tmpdir = 1,
> + .setup = setup,
> + .test_all = run,
> + .cleanup = cleanup,
> + .save_restore = (const struct tst_path_val[]) {
> + {STACK_TRACER_PATH, NULL, TST_SR_TCONF},
> + {}
> + },
> + .tags = (const struct tst_tag[]) {
> + {"linux-git", "1dbd195"},
> + {}
> + },
> +};
> diff --git a/testcases/kernel/tracing/ftrace_test/ftrace_regression02.c b/testcases/kernel/tracing/ftrace_test/ftrace_regression02.c
> new file mode 100644
> index 000000000..498db29e5
> --- /dev/null
> +++ b/testcases/kernel/tracing/ftrace_test/ftrace_regression02.c
> @@ -0,0 +1,68 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Copyright (c) 2015 Red Hat Inc.
> + * Copyright (c) 2026 lufei <lufei@uniontech.com>
> + */
> +
> +/*\
> + * Check signal:signal_generate gives 2 more fields: grp=[0-9] res=[0-9]
> + */
> +
> +#include <unistd.h>
> +#include <stdio.h>
> +#include "ftrace_regression.h"
> +
> +#define DEBUGFS_DIR "debugfs"
> +#define SET_EVENT DEBUGFS_DIR "/tracing/set_event"
> +#define TRACING_ON DEBUGFS_DIR "/tracing/tracing_on"
> +#define TRACE_FILE DEBUGFS_DIR "/tracing/trace"
> +
> +#define LOOP 100
> +
> +static void setup(void)
> +{
> + SAFE_MKDIR(DEBUGFS_DIR, 0755);
> + SAFE_MOUNT(NULL, DEBUGFS_DIR, "debugfs", 0, NULL);
> +}
> +
> +static void run(void)
> +{
> + int i;
> +
> + SAFE_FILE_PRINTF(SET_EVENT, "signal:signal_generate");
> + SAFE_FILE_PRINTF(TRACING_ON, "1");
> + SAFE_FILE_PRINTF(TRACE_FILE, "\n");
> +
> + for (i = 0; i < LOOP; i++)
> + tst_cmd((const char *[]){"ls", "-l", "/proc", NULL},
> + "/dev/null", "/dev/null", 0);
> + if (file_contains(TRACE_FILE, "grp=[0-9]") && file_contains(TRACE_FILE, "res=[0-9]"))
> + tst_res(TPASS, "Finished running the test");
Also here, please, better tpass message.
> + else
> + tst_res(TFAIL, "Pattern grp=[0-9] res=[0-9] not found in trace");
> +}
> +
> +static void cleanup(void)
> +{
> + SAFE_UMOUNT(DEBUGFS_DIR);
> +}
> +
> +static struct tst_test test = {
> + .needs_root = 1,
> + .needs_tmpdir = 1,
> + .setup = setup,
> + .test_all = run,
> + .cleanup = cleanup,
> + .needs_cmds = (struct tst_cmd[]) {
> + {.cmd = "ls"},
> + {}
> + },
> + .min_kver = "3.2",
We now support kernel >= 4.4, this should be removed.
https://linux-test-project.readthedocs.io/en/latest/users/supported_systems.html#kernel-version
> + .tags = (const struct tst_tag[]) {
> + {"linux-git", "6c303d3"},
> + {"linux-git", "163566f"},
And longer hash.
> + {}
> + },
> +};
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [LTP] [PATCH v3] Rewrite ftrace_regression tests with new C API
2026-03-31 1:55 ` [LTP] [PATCH v3] " lufei
2026-03-31 7:53 ` Petr Vorel
@ 2026-03-31 7:56 ` Petr Vorel
2026-03-31 18:28 ` Cyril Hrubis
2026-03-31 10:01 ` [LTP] [PATCH v4] " lufei
2 siblings, 1 reply; 10+ messages in thread
From: Petr Vorel @ 2026-03-31 7:56 UTC (permalink / raw)
To: lufei; +Cc: ltp
Hi all,
...
> --- /dev/null
> +++ b/testcases/kernel/tracing/ftrace_test/ftrace_regression02.c
...
> + for (i = 0; i < LOOP; i++)
> + tst_cmd((const char *[]){"ls", "-l", "/proc", NULL},
> + "/dev/null", "/dev/null", 0);
It should probably be SAFE_CMD().
@Cyril are we ok with 'ls' as external dependency, or do we want to have test
to have simple binary helper run as child to not depend on userspace?
Kind regards,
Petr
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 10+ messages in thread
* [LTP] [PATCH v4] Rewrite ftrace_regression tests with new C API
2026-03-31 1:55 ` [LTP] [PATCH v3] " lufei
2026-03-31 7:53 ` Petr Vorel
2026-03-31 7:56 ` Petr Vorel
@ 2026-03-31 10:01 ` lufei
2 siblings, 0 replies; 10+ messages in thread
From: lufei @ 2026-03-31 10:01 UTC (permalink / raw)
To: ltp; +Cc: lufei
Rewritten from old shell scripts.
ftrace_regression01: regression test for panic bug while using
userstacktrace, set userstacktrace in loop and check if success.
ftrace_regression02: for checking signal:signal_generate gives
2 more fields: grp res.
Signed-off-by: lufei <lufei@uniontech.com>
---
runtest/tracing | 4 +-
.../kernel/tracing/ftrace_test/.gitignore | 2 +
.../tracing/ftrace_test/ftrace_regression.h | 61 ++++++++++++++
.../tracing/ftrace_test/ftrace_regression01.c | 82 ++++++++++++++++++
.../ftrace_test/ftrace_regression01.sh | 83 -------------------
.../tracing/ftrace_test/ftrace_regression02.c | 56 +++++++++++++
.../ftrace_test/ftrace_regression02.sh | 63 --------------
7 files changed, 203 insertions(+), 148 deletions(-)
create mode 100644 testcases/kernel/tracing/ftrace_test/.gitignore
create mode 100644 testcases/kernel/tracing/ftrace_test/ftrace_regression.h
create mode 100644 testcases/kernel/tracing/ftrace_test/ftrace_regression01.c
delete mode 100755 testcases/kernel/tracing/ftrace_test/ftrace_regression01.sh
create mode 100644 testcases/kernel/tracing/ftrace_test/ftrace_regression02.c
delete mode 100755 testcases/kernel/tracing/ftrace_test/ftrace_regression02.sh
diff --git a/runtest/tracing b/runtest/tracing
index 674e2ad97..2a4a92c5f 100644
--- a/runtest/tracing
+++ b/runtest/tracing
@@ -1,6 +1,6 @@
#DESCRIPTION:Tracing testing
-ftrace_regression01 ftrace_regression01.sh
-ftrace_regression02 ftrace_regression02.sh
+ftrace_regression01 ftrace_regression01
+ftrace_regression02 ftrace_regression02
ftrace-stress-test ftrace_stress_test.sh 90
dynamic_debug01 dynamic_debug01.sh
fanotify25 fanotify25
diff --git a/testcases/kernel/tracing/ftrace_test/.gitignore b/testcases/kernel/tracing/ftrace_test/.gitignore
new file mode 100644
index 000000000..b0153e9fa
--- /dev/null
+++ b/testcases/kernel/tracing/ftrace_test/.gitignore
@@ -0,0 +1,2 @@
+ftrace_regression01
+ftrace_regression02
diff --git a/testcases/kernel/tracing/ftrace_test/ftrace_regression.h b/testcases/kernel/tracing/ftrace_test/ftrace_regression.h
new file mode 100644
index 000000000..0efae7268
--- /dev/null
+++ b/testcases/kernel/tracing/ftrace_test/ftrace_regression.h
@@ -0,0 +1,61 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later
+ *
+ * Copyright (c) 2026 lufei <lufei@uniontech.com>
+ *
+ * Shared header for ftrace regression tests.
+ */
+
+#ifndef FTRACE_REGRESSION_H
+#define FTRACE_REGRESSION_H
+
+#include "tst_test.h"
+#include "tst_safe_file_ops.h"
+#include "tst_safe_stdio.h"
+
+#include <regex.h>
+#include <stdio.h>
+
+#define FTRACE_LINE_BUF_SIZE 1024
+#define DEBUGFS_DIR "debugfs"
+
+/**
+ * file_contains - Check if a file contains specific regex pattern.
+ */
+static inline int file_contains(const char *path, const char *pattern)
+{
+ FILE *fp = SAFE_FOPEN(path, "r");
+ char *buf = SAFE_MALLOC(FTRACE_LINE_BUF_SIZE);
+ bool found = false;
+
+ regex_t re;
+
+ if (regcomp(&re, pattern, REG_EXTENDED | REG_NOSUB) != 0) {
+ SAFE_FCLOSE(fp);
+ return found;
+ }
+
+ while (fgets(buf, FTRACE_LINE_BUF_SIZE, fp)) {
+ if (regexec(&re, buf, 0, NULL, 0) == 0) {
+ found = true;
+ break;
+ }
+ }
+
+ regfree(&re);
+ SAFE_FCLOSE(fp);
+ free(buf);
+ return found;
+}
+
+static inline void mount_debugfs(void)
+{
+ SAFE_MKDIR(DEBUGFS_DIR, 0755);
+ SAFE_MOUNT(NULL, DEBUGFS_DIR, "debugfs", 0, NULL);
+}
+
+static inline void umount_debugfs(void)
+{
+ SAFE_UMOUNT(DEBUGFS_DIR);
+}
+
+#endif /* FTRACE_REGRESSION_H */
diff --git a/testcases/kernel/tracing/ftrace_test/ftrace_regression01.c b/testcases/kernel/tracing/ftrace_test/ftrace_regression01.c
new file mode 100644
index 000000000..be2327582
--- /dev/null
+++ b/testcases/kernel/tracing/ftrace_test/ftrace_regression01.c
@@ -0,0 +1,82 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2015 Red Hat Inc.
+ * Copyright (c) 2026 lufei <lufei@uniontech.com>
+ */
+
+/*\
+ * Regression test for panic while using userstacktrace.
+ *
+ * BUG: unable to handle kernel paging request at 00000000417683c0
+ * IP: [<ffffffff8105c834>] update_curr+0x124/0x1e0
+ * Thread overran stack, or stack corrupted
+ * Oops: 0000 [#1] SMP
+ * last sysfs file: ../system/cpu/cpu15/cache/index2/shared_cpu_map
+ *
+ * The bug was fixed by:
+ * 1dbd195 (tracing: Fix preempt count leak)
+ */
+
+#include <unistd.h>
+#include "ftrace_regression.h"
+
+#define STACK_TRACER_PATH "/proc/sys/kernel/stack_tracer_enabled"
+#define TRACE_OPTIONS DEBUGFS_DIR "/tracing/trace_options"
+#define EXC_PAGE_FAULT DEBUGFS_DIR "/tracing/events/exceptions/page_fault_kernel/enable"
+#define MM_PAGE_FAULT DEBUGFS_DIR "/tracing/events/kmem/mm_kernel_pagefault/enable"
+
+#define LOOP 10
+
+static const char *page_fault_path;
+static int page_fault_origin;
+
+static void setup(void)
+{
+ mount_debugfs();
+
+ if (access(EXC_PAGE_FAULT, F_OK) == 0)
+ page_fault_path = EXC_PAGE_FAULT;
+ else if (access(MM_PAGE_FAULT, F_OK) == 0)
+ page_fault_path = MM_PAGE_FAULT;
+ else
+ tst_brk(TCONF, "Page fault event not available");
+
+ SAFE_FILE_SCANF(page_fault_path, "%d", &page_fault_origin);
+}
+
+static void run(void)
+{
+ int i;
+
+ for (i = 0; i < LOOP; i++) {
+ SAFE_FILE_PRINTF(STACK_TRACER_PATH, "1");
+ SAFE_FILE_PRINTF(TRACE_OPTIONS, "userstacktrace");
+
+ if (!file_contains(TRACE_OPTIONS, "^userstacktrace"))
+ tst_brk(TBROK, "Failed to set userstacktrace");
+
+ SAFE_FILE_PRINTF(page_fault_path, "1");
+ }
+
+ SAFE_FILE_PRINTF(page_fault_path, "%d", page_fault_origin);
+
+ tst_res(TPASS, "Test passed for setting userstacktrace "
+ "bug(preempt count leak) not reproduced"
+ );
+}
+
+static struct tst_test test = {
+ .needs_root = 1,
+ .needs_tmpdir = 1,
+ .setup = setup,
+ .test_all = run,
+ .cleanup = umount_debugfs,
+ .save_restore = (const struct tst_path_val[]) {
+ {STACK_TRACER_PATH, NULL, TST_SR_TCONF},
+ {}
+ },
+ .tags = (const struct tst_tag[]) {
+ {"linux-git", "1dbd1951f39e"},
+ {}
+ },
+};
diff --git a/testcases/kernel/tracing/ftrace_test/ftrace_regression01.sh b/testcases/kernel/tracing/ftrace_test/ftrace_regression01.sh
deleted file mode 100755
index d6969cfc6..000000000
--- a/testcases/kernel/tracing/ftrace_test/ftrace_regression01.sh
+++ /dev/null
@@ -1,83 +0,0 @@
-#! /bin/sh
-
-###########################################################################
-## ##
-## Copyright (c) 2015, Red Hat Inc. ##
-## ##
-## This program is free software: you can redistribute it and/or modify ##
-## it under the terms of the GNU General Public License as published by ##
-## the Free Software Foundation, either version 3 of the License, or ##
-## (at your option) any later version. ##
-## ##
-## This program is distributed in the hope that it will be useful, ##
-## but WITHOUT ANY WARRANTY; without even the implied warranty of ##
-## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ##
-## GNU General Public License for more details. ##
-## ##
-## You should have received a copy of the GNU General Public License ##
-## along with this program. If not, see <http://www.gnu.org/licenses/>. ##
-## ##
-## Author: Li Wang <liwang@redhat.com> ##
-## ##
-###########################################################################
-## ##
-## Summary: panic while using userstacktrace ##
-## ##
-## BUG: unable to handle kernel paging request at 00000000417683c0 ##
-## IP: [<ffffffff8105c834>] update_curr+0x124/0x1e0 ##
-## PGD 41a796067 PUD 0 ##
-## Thread overran stack, or stack corrupted ##
-## Oops: 0000 [#1] SMP ##
-## last sysfs file: ../system/cpu/cpu15/cache/index2/shared_cpu_map ##
-## ##
-## The bug was fixed by: ##
-## 1dbd195 (tracing: Fix preempt count leak) ##
-## ##
-###########################################################################
-
-export TCID="ftrace_regression01"
-export TST_TOTAL=1
-
-. ftrace_lib.sh
-
-LOOP=10
-
-TSTACK_TRACE_PATH="/proc/sys/kernel/stack_tracer_enabled"
-EXC_PAGE_FAULT_ENABLE="$TRACING_PATH/events/exceptions/page_fault_kernel/enable"
-MM_PAGE_FAULT_ENABLE="$TRACING_PATH/events/kmem/mm_kernel_pagefault/enable"
-
-ftrace_userstacktrace_test()
-{
- if [ ! -e "$TSTACK_TRACE_PATH" ]; then
- tst_brkm TCONF "Stack Tracer is not cofigured in This kernel"
- fi
-
- for i in $(seq $LOOP); do
- echo 1 > $TSTACK_TRACE_PATH
- echo userstacktrace > $TRACING_PATH/trace_options
- grep -q "^userstacktrace" $TRACING_PATH/trace_options
- if [ $? -ne 0 ]; then
- tst_brkm TBROK "Failed to set userstacktrace"
- fi
-
- if [ -f "$EXC_PAGE_FAULT_ENABLE" ]; then
- exc_page_fault_enable=`cat $EXC_PAGE_FAULT_ENABLE`
- echo 1 > $EXC_PAGE_FAULT_ENABLE
- else
- mm_page_fault_enable=`cat $MM_PAGE_FAULT_ENABLE`
- echo 1 > $MM_PAGE_FAULT_ENABLE
- fi
- done
-
- if [ -f "$EXC_PAGE_FAULT_ENABLE" ]; then
- echo "$exc_page_fault_enable" > $EXC_PAGE_FAULT_ENABLE
- else
- echo "$mm_page_fault_enable" > $MM_PAGE_FAULT_ENABLE
- fi
-
- tst_resm TPASS "Finished running the test"
-}
-
-ftrace_userstacktrace_test
-
-tst_exit
diff --git a/testcases/kernel/tracing/ftrace_test/ftrace_regression02.c b/testcases/kernel/tracing/ftrace_test/ftrace_regression02.c
new file mode 100644
index 000000000..b4aac7ad0
--- /dev/null
+++ b/testcases/kernel/tracing/ftrace_test/ftrace_regression02.c
@@ -0,0 +1,56 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2015 Red Hat Inc.
+ * Copyright (c) 2026 lufei <lufei@uniontech.com>
+ */
+
+/*\
+ * Check signal:signal_generate gives 2 more fields: grp=[0-9] res=[0-9]
+ */
+
+#include "ftrace_regression.h"
+
+#define SET_EVENT DEBUGFS_DIR "/tracing/set_event"
+#define TRACING_ON DEBUGFS_DIR "/tracing/tracing_on"
+#define TRACE_FILE DEBUGFS_DIR "/tracing/trace"
+
+#define LOOP 100
+
+static void run(void)
+{
+ int i;
+ const char *const cmd_ls[] = {"ls", "-l", "/proc", NULL};
+
+ SAFE_FILE_PRINTF(SET_EVENT, "signal:signal_generate");
+ SAFE_FILE_PRINTF(TRACING_ON, "1");
+ SAFE_FILE_PRINTF(TRACE_FILE, "\n");
+
+ // to generate trace
+ for (i = 0; i < LOOP; i++)
+ SAFE_CMD(cmd_ls, "/dev/null", "/dev/null");
+
+ if (file_contains(TRACE_FILE, "grp=[0-9]") &&
+ file_contains(TRACE_FILE, "res=[0-9]"))
+ tst_res(TPASS, "Pattern grp=[0-9] res=[0-9] reported after "
+ "setting signal:signal_generate");
+ else
+ tst_res(TFAIL, "Pattern grp=[0-9] res=[0-9] not found in trace");
+}
+
+static struct tst_test test = {
+ .needs_root = 1,
+ .needs_tmpdir = 1,
+ .setup = mount_debugfs,
+ .test_all = run,
+ .cleanup = umount_debugfs,
+ .needs_cmds = (struct tst_cmd[]) {
+ {.cmd = "ls"},
+ {}
+ },
+ .tags = (const struct tst_tag[]) {
+ {"linux-git", "6c303d3ab39f"},
+ {"linux-git", "163566f60bfe"},
+ {}
+ },
+};
+
diff --git a/testcases/kernel/tracing/ftrace_test/ftrace_regression02.sh b/testcases/kernel/tracing/ftrace_test/ftrace_regression02.sh
deleted file mode 100755
index 3c32f219e..000000000
--- a/testcases/kernel/tracing/ftrace_test/ftrace_regression02.sh
+++ /dev/null
@@ -1,63 +0,0 @@
-#! /bin/sh
-
-###########################################################################
-## ##
-## Copyright (c) 2015, Red Hat Inc. ##
-## ##
-## This program is free software: you can redistribute it and/or modify ##
-## it under the terms of the GNU General Public License as published by ##
-## the Free Software Foundation, either version 3 of the License, or ##
-## (at your option) any later version. ##
-## ##
-## This program is distributed in the hope that it will be useful, ##
-## but WITHOUT ANY WARRANTY; without even the implied warranty of ##
-## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ##
-## GNU General Public License for more details. ##
-## ##
-## You should have received a copy of the GNU General Public License ##
-## along with this program. If not, see <http://www.gnu.org/licenses/>. ##
-## ##
-## Author: Li Wang <liwang@redhat.com> ##
-## ##
-###########################################################################
-## ##
-## Summary: check signal:signal_generate gives 2 more fields: grp res ##
-## ##
-## This testcase is writing for signal events change: ##
-## 6c303d3 tracing: let trace_signal_generate() report more info...##
-## 163566f tracing: send_sigqueue() needs trace_signal_generate() ##
-## ##
-###########################################################################
-
-export TCID="ftrace_regression02"
-export TST_TOTAL=1
-
-. ftrace_lib.sh
-
-ftrace_signal_test()
-{
- # Set envent
- echo 'signal:signal_generate' > $TRACING_PATH/set_event
- echo 1 > $TRACING_PATH/tracing_on
- echo > $TRACING_PATH/trace
-
- # just to generate trace
- for i in $(seq 100); do
- ls -l /proc > /dev/null 2>&1
- done
-
- grep -q 'grp=[0-9] res=[0-9]' $TRACING_PATH/trace
- if [ $? -eq 0 ]; then
- tst_resm TPASS "finished running the test."
- else
- tst_resm TFAIL "running the test failed, please check log message."
- fi
-}
-
-if tst_kvcmp -lt "3.2"; then
- tst_brkm TCONF "The test should be run in kernels >= 3.2.0 Skip the test..."
-fi
-
-ftrace_signal_test
-
-tst_exit
--
2.39.3
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 10+ messages in thread
* Re: [LTP] [PATCH v3] Rewrite ftrace_regression tests with new C API
2026-03-31 7:56 ` Petr Vorel
@ 2026-03-31 18:28 ` Cyril Hrubis
0 siblings, 0 replies; 10+ messages in thread
From: Cyril Hrubis @ 2026-03-31 18:28 UTC (permalink / raw)
To: Petr Vorel; +Cc: lufei, ltp
Hi!
> > + for (i = 0; i < LOOP; i++)
> > + tst_cmd((const char *[]){"ls", "-l", "/proc", NULL},
> > + "/dev/null", "/dev/null", 0);
> It should probably be SAFE_CMD().
>
> @Cyril are we ok with 'ls' as external dependency, or do we want to have test
> to have simple binary helper run as child to not depend on userspace?
Hmm, I guess that even tooling such as rapido[1] have ls in the initrd
so I guess that ls is just going to be there.
[1] https://github.com/rapido-linux/rapido
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2026-03-31 18:28 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-04 8:05 [LTP] [PATCH 1/2] Rewrite ftrace_regression01.sh with new C API lufei
2026-03-04 8:05 ` [LTP] [PATCH 2/2] Rewrite ftrace_regression02.sh " lufei
2026-03-27 10:34 ` [LTP] [PATCH 1/2] Rewrite ftrace_regression01.sh " Andrea Cervesato via ltp
2026-03-30 7:15 ` [LTP] [PATCH v2] Rewrite ftrace_regression tests " lufei
2026-03-30 8:39 ` Andrea Cervesato via ltp
2026-03-31 1:55 ` [LTP] [PATCH v3] " lufei
2026-03-31 7:53 ` Petr Vorel
2026-03-31 7:56 ` Petr Vorel
2026-03-31 18:28 ` Cyril Hrubis
2026-03-31 10:01 ` [LTP] [PATCH v4] " lufei
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox