* [LTP] [PATCH v6 0/5] ftrace: Convert shell tests to C
@ 2026-06-09 4:16 Praveen K Pandey
2026-06-09 4:16 ` [LTP] [PATCH v6 1/5] ftrace: Add common library for C implementation Praveen K Pandey
` (4 more replies)
0 siblings, 5 replies; 8+ messages in thread
From: Praveen K Pandey @ 2026-06-09 4:16 UTC (permalink / raw)
To: ltp
This patch series converts the ftrace shell-based tests to C using
the new LTP test API. This addresses issue #1282 and provides better
error handling, maintainability, and integration with LTP's modern
test infrastructure.
Changes in v6:
- ftrace_lib.c:
* Removed C++ style comment
* Removed unused variable 'ret' in ftrace_set_tracer()
* Added NULL check for strdup() in ftrace_restore_settings()
* Added Suggested-by tag for Cyril Hrubis who provided the
refactoring suggestions implemented in v5
- ftrace_regression01.c:
* Fixed commit message to accurately describe the test
(tests for kernel panic with userstacktrace, not "all tracers")
* Removed incorrect .min_kver reference from commit message
- ftrace_regression02.c:
* Fixed commit message to correctly state .min_kver = "3.2"
- ftrace_stress_test.c:
* Fixed pthread_join() being called twice (undefined behavior)
by resetting thread_count to 0 in stop_stress_tests()
* Reset stop_testing and thread_count at start of run_test()
to support multiple iterations (-i N)
* Simplified cleanup() to avoid redundant stop_testing assignment
- Makefile changes:
* Moved to patch 1 to maintain bisectability - each commit
in the series now builds independently
Changes in v5:
- ftrace_lib.c: Major refactoring based on review feedback
* Removed static variable initialization to 0/NULL (C standard)
* Removed obvious comments for cleaner code
* Replaced manual debugfs mount check with tst_is_mounted()
* Used SAFE_ASPRINTF() for all path construction
* Used SAFE_FILE_PRINTF() in ftrace_set_tracer()
* Simplified ftrace_get_available_tracers() to read line by line
* Added proper error checking for strdup() calls
- ftrace_lib.h: Cleaned up API
* Fixed kernel-doc comment format (use - instead of ())
* Removed low-level implementation details from header
- ftrace_regression01.c/ftrace_regression02.c:
* Removed deprecated [Description] header line
- ftrace_stress_test.c:
* Fixed use-after-free: join threads before ftrace_cleanup()
Changes in v4:
- Fixed trailing whitespace issues
- Corrected commit message format and content
- Replaced tst_kvercmp() with .min_kver = "2.6.29"
- Removed LTP_TIMEOUT_MUL parsing (handled by framework)
- Updated documentation to reflect root requirement
Changes in v3:
- Fixed tst_tmpdir_path() usage in ftrace_lib.c
- Removed CVE tag from test documentation
- Fixed memory leaks in ftrace_get_available_tracers()
- Changed Algorithm sections to bullet points
- Added root requirement to test documentation
- Fixed Makefile to include ftrace_lib.o in LDLIBS
- Created .gitignore for compiled binaries
- Removed deprecated tst_reinit.h include
- Deleted orphaned shell test files
Changes in v2:
- Moved TST_NO_DEFAULT_MAIN before includes
- Fixed include order (tst_test.h before tst_safe_*.h)
- Removed tst_reinit() calls (not needed with new API)
- Fixed test structure initialization
- Improved error messages
The conversion provides:
- Better error handling using LTP's SAFE_* macros
- Proper resource cleanup and state restoration
- Modern LTP test API usage
- Improved code maintainability
- Type safety and compile-time checks
- Bisectable commit history
Testing:
- Compiled successfully on x86_64 and ppc64le
- All tests pass on systems with ftrace support
- Proper cleanup verified (settings restored after test)
- Multiple iterations tested (-i N flag)
Praveen K Pandey (5):
ftrace: Add common library for C implementation
ftrace: Convert ftrace_regression01.sh to C
ftrace: Convert ftrace_regression02.sh to C
ftrace: Convert ftrace_stress_test.sh to C
ftrace: Remove obsolete shell test files
runtest/tracing | 6 +-
.../kernel/tracing/ftrace_test/.gitignore | 4 +
testcases/kernel/tracing/ftrace_test/Makefile | 19 +-
.../kernel/tracing/ftrace_test/ftrace_lib.c | 374 ++++++++++++++++++
.../kernel/tracing/ftrace_test/ftrace_lib.h | 136 +++++++
.../kernel/tracing/ftrace_test/ftrace_lib.sh | 180 ---------
.../tracing/ftrace_test/ftrace_regression01.c | 126 ++++++
.../ftrace_test/ftrace_regression01.sh | 83 ----
.../tracing/ftrace_test/ftrace_regression02.c | 101 +++++
.../ftrace_test/ftrace_regression02.sh | 63 ---
.../ftrace_stress/ftrace_buffer_size_kb.sh | 45 ---
.../ftrace_stress/ftrace_current_tracer.sh | 32 --
.../ftrace_stress/ftrace_ftrace_enabled.sh | 38 --
.../ftrace_function_profile_enabled.sh | 38 --
.../ftrace_stress/ftrace_set_event.sh | 46 ---
.../ftrace_stress/ftrace_set_ftrace_filter.sh | 119 ------
.../ftrace_stress/ftrace_set_ftrace_pid.sh | 37 --
.../ftrace_stress/ftrace_stack_max_size.sh | 27 --
.../ftrace_stress/ftrace_stack_trace.sh | 35 --
.../ftrace_test/ftrace_stress/ftrace_trace.sh | 25 --
.../ftrace_stress/ftrace_trace_clock.sh | 27 --
.../ftrace_stress/ftrace_trace_options.sh | 58 ---
.../ftrace_stress/ftrace_trace_pipe.sh | 45 ---
.../ftrace_stress/ftrace_trace_stat.sh | 38 --
.../ftrace_stress/ftrace_tracing_cpumask.sh | 91 -----
.../ftrace_stress/ftrace_tracing_enabled.sh | 38 --
.../ftrace_tracing_max_latency.sh | 27 --
.../ftrace_stress/ftrace_tracing_on.sh | 38 --
.../tracing/ftrace_test/ftrace_stress_test.c | 328 +++++++++++++++
./tracing/ftrace_test/ftrace_stress_test.sh | 121 ------
30 files changed, 1086 insertions(+), 1256 deletions(-)
create mode 100644 testcases/kernel/tracing/ftrace_test/.gitignore
create mode 100644 testcases/kernel/tracing/ftrace_test/ftrace_lib.c
create mode 100644 testcases/kernel/tracing/ftrace_test/ftrace_lib.h
delete mode 100755 testcases/kernel/tracing/ftrace_test/ftrace_lib.sh
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
delete mode 100755 testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_buffer_size_kb.sh
delete mode 100755 testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_current_tracer.sh
delete mode 100755 testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_ftrace_enabled.sh
delete mode 100755 testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_function_profile_enabled.sh
delete mode 100755 testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_set_event.sh
delete mode 100755 testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_set_ftrace_filter.sh
delete mode 100755 testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_set_ftrace_pid.sh
delete mode 100755 testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_stack_max_size.sh
delete mode 100755 testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_stack_trace.sh
delete mode 100755 testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_trace.sh
delete mode 100755 testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_trace_clock.sh
delete mode 100755 testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_trace_options.sh
delete mode 100755 testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_trace_pipe.sh
delete mode 100755 testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_trace_stat.sh
delete mode 100755 testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_tracing_cpumask.sh
delete mode 100755 testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_tracing_enabled.sh
delete mode 100755 testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_tracing_max_latency.sh
delete mode 100755 testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_tracing_on.sh
create mode 100644 testcases/kernel/tracing/ftrace_test/ftrace_stress_test.c
delete mode 100755 testcases/kernel/tracing/ftrace_test/ftrace_stress_test.sh
--
2.50.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 8+ messages in thread
* [LTP] [PATCH v6 1/5] ftrace: Add common library for C implementation
2026-06-09 4:16 [LTP] [PATCH v6 0/5] ftrace: Convert shell tests to C Praveen K Pandey
@ 2026-06-09 4:16 ` Praveen K Pandey
2026-06-09 5:14 ` [LTP] " linuxtestproject.agent
2026-06-10 9:31 ` [LTP] [PATCH v6 1/5] " Cyril Hrubis
2026-06-09 4:16 ` [LTP] [PATCH v6 2/5] ftrace: Convert ftrace_regression01.sh to C Praveen K Pandey
` (3 subsequent siblings)
4 siblings, 2 replies; 8+ messages in thread
From: Praveen K Pandey @ 2026-06-09 4:16 UTC (permalink / raw)
To: ltp
Add ftrace_lib.c and ftrace_lib.h to provide common functionality
for ftrace test cases. The library handles:
- Debugfs mounting and detection using tst_is_mounted()
- Ftrace initialization and cleanup
- Reading and writing ftrace files
- Saving and restoring ftrace settings
- Getting available tracers
- Setting current tracer using SAFE_FILE_PRINTF()
The library uses LTP's SAFE_* macros for robust error handling
and SAFE_ASPRINTF() for memory allocation. Proper NULL checks
are included for all strdup() calls.
Also update Makefile and .gitignore to support building the new
C tests. This ensures each commit in the series can be built
independently (bisectability).
Signed-off-by: Praveen K Pandey <praveen@linux.ibm.com>
Suggested-by: Cyril Hrubis <chrubis@suse.cz>
---
.../kernel/tracing/ftrace_test/.gitignore | 4 +
testcases/kernel/tracing/ftrace_test/Makefile | 19 +-
.../kernel/tracing/ftrace_test/ftrace_lib.c | 371 ++++++++++++++++++
.../kernel/tracing/ftrace_test/ftrace_lib.h | 136 +++++++
4 files changed, 528 insertions(+), 2 deletions(-)
create mode 100644 testcases/kernel/tracing/ftrace_test/.gitignore
create mode 100644 testcases/kernel/tracing/ftrace_test/ftrace_lib.c
create mode 100644 testcases/kernel/tracing/ftrace_test/ftrace_lib.h
diff --git a/testcases/kernel/tracing/ftrace_test/.gitignore b/testcases/kernel/tracing/ftrace_test/.gitignore
new file mode 100644
index 000000000..9e102074c
--- /dev/null
+++ b/testcases/kernel/tracing/ftrace_test/.gitignore
@@ -0,0 +1,4 @@
+ftrace_regression01
+ftrace_regression02
+ftrace_stress_test
+
diff --git a/testcases/kernel/tracing/ftrace_test/Makefile b/testcases/kernel/tracing/ftrace_test/Makefile
index e4a913a56..2528b9f15 100644
--- a/testcases/kernel/tracing/ftrace_test/Makefile
+++ b/testcases/kernel/tracing/ftrace_test/Makefile
@@ -1,7 +1,22 @@
-top_srcdir ?= ../../../..
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2010 FUJITSU LIMITED
+# Copyright (c) 2024 Linux Test Project
+# Copyright (c) IBM, 2026
+# Converted to C by: Praveen K Pandey <praveen@linux.ibm.com>
+
+top_srcdir ?= ../../../..
include $(top_srcdir)/include/mk/testcases.mk
-INSTALL_TARGETS := *.sh ftrace_stress/*
+# Filter out ftrace_lib from standalone build targets
+FILTER_OUT_MAKE_TARGETS := ftrace_lib
+
+# Only ftrace_stress_test needs pthread
+ftrace_stress_test: LDLIBS += -lpthread
include $(top_srcdir)/include/mk/generic_leaf_target.mk
+
+# C test binaries with shared library dependencies
+ftrace_regression01: ftrace_lib.o
+ftrace_regression02: ftrace_lib.o
+ftrace_stress_test: ftrace_lib.o
diff --git a/testcases/kernel/tracing/ftrace_test/ftrace_lib.c b/testcases/kernel/tracing/ftrace_test/ftrace_lib.c
new file mode 100644
index 000000000..9aad863a9
--- /dev/null
+++ b/testcases/kernel/tracing/ftrace_test/ftrace_lib.c
@@ -0,0 +1,371 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2010 FUJITSU LIMITED
+ * Copyright (c) 2024 Linux Test Project
+ * Copyright (c) IBM, 2026
+ *
+ * Author: Li Zefan <lizf@cn.fujitsu.com>
+ * Converted to C by: Praveen K Pandey <praveen@linux.ibm.com>
+ */
+
+#define TST_NO_DEFAULT_MAIN
+#include "ftrace_lib.h"
+#include "tst_test.h"
+#include "tst_safe_macros.h"
+#include "tst_safe_stdio.h"
+#include "tst_safe_file_ops.h"
+#include "tst_device.h"
+
+char *tracing_path;
+char *debugfs_path;
+static int debugfs_mounted_by_us;
+
+struct ftrace_saved_state saved_state;
+
+void ftrace_initialize(void)
+{
+ if (tst_is_mounted("/sys/kernel/debug")) {
+ debugfs_path = strdup("/sys/kernel/debug");
+ if (!debugfs_path)
+ tst_brk(TBROK | TERRNO, "strdup failed");
+ } else {
+ char *tmpdir = tst_tmpdir_path();
+
+ SAFE_ASPRINTF(&debugfs_path, "%s/debugfs", tmpdir);
+ SAFE_MKDIR(debugfs_path, 0755);
+ SAFE_MOUNT("debugfs", debugfs_path, "debugfs", 0, NULL);
+ debugfs_mounted_by_us = 1;
+ }
+
+ SAFE_ASPRINTF(&tracing_path, "%s/tracing", debugfs_path);
+
+ if (access(tracing_path, F_OK) != 0)
+ tst_brk(TCONF, "Tracing is not supported");
+
+ ftrace_save_settings();
+}
+
+void ftrace_cleanup(void)
+{
+ ftrace_restore_settings();
+
+ if (debugfs_mounted_by_us && debugfs_path) {
+ tst_umount(debugfs_path);
+ rmdir(debugfs_path);
+ }
+
+ free(tracing_path);
+ free(debugfs_path);
+
+ free(saved_state.trace_options);
+ free(saved_state.tracing_on);
+ free(saved_state.buffer_size);
+ free(saved_state.tracing_cpumask);
+ free(saved_state.tracing_enabled);
+ free(saved_state.stack_tracer_enabled);
+ free(saved_state.ftrace_enabled);
+ free(saved_state.function_profile_enabled);
+}
+
+char *ftrace_get_path(const char *filename)
+{
+ char *path;
+
+ SAFE_ASPRINTF(&path, "%s/%s", tracing_path, filename);
+ return path;
+}
+
+char *ftrace_read_file(const char *filename)
+{
+ char *path;
+ FILE *fp;
+ char *content = NULL;
+ size_t len = 0;
+ ssize_t read;
+ char *line = NULL;
+ size_t total_size = 0;
+
+ path = ftrace_get_path(filename);
+ if (!path)
+ return NULL;
+
+ fp = fopen(path, "r");
+ free(path);
+
+ if (!fp)
+ return NULL;
+
+ while ((read = getline(&line, &len, fp)) != -1) {
+ char *new_content = realloc(content, total_size + read + 1);
+
+ if (!new_content) {
+ free(content);
+ free(line);
+ fclose(fp);
+ return NULL;
+ }
+ content = new_content;
+ memcpy(content + total_size, line, read);
+ total_size += read;
+ }
+
+ if (content)
+ content[total_size] = '\0';
+
+ free(line);
+ fclose(fp);
+
+ return content;
+}
+
+int ftrace_write_file(const char *filename, const char *content)
+{
+ char *path;
+ FILE *fp;
+ int ret;
+
+ path = ftrace_get_path(filename);
+ if (!path)
+ return -1;
+
+ fp = fopen(path, "w");
+ free(path);
+
+ if (!fp)
+ return -1;
+
+ ret = fprintf(fp, "%s", content);
+ fclose(fp);
+
+ return (ret > 0) ? 0 : -1;
+}
+
+int ftrace_file_exists(const char *filename)
+{
+ char *path;
+ int ret;
+
+ path = ftrace_get_path(filename);
+ if (!path)
+ return 0;
+
+ ret = (access(path, F_OK) == 0);
+ free(path);
+
+ return ret;
+}
+
+void ftrace_save_settings(void)
+{
+ if (saved_state.saved)
+ return;
+
+ saved_state.trace_options = ftrace_read_file("trace_options");
+ saved_state.tracing_on = ftrace_read_file("tracing_on");
+ saved_state.buffer_size = ftrace_read_file("buffer_size_kb");
+
+ if (ftrace_file_exists("tracing_cpumask"))
+ saved_state.tracing_cpumask = ftrace_read_file("tracing_cpumask");
+
+ if (ftrace_file_exists("tracing_enabled"))
+ saved_state.tracing_enabled = ftrace_read_file("tracing_enabled");
+
+ if (ftrace_file_exists("stack_max_size")) {
+ FILE *fp = fopen("/proc/sys/kernel/stack_tracer_enabled", "r");
+
+ if (fp) {
+ saved_state.stack_tracer_enabled = malloc(32);
+ if (saved_state.stack_tracer_enabled)
+ fgets(saved_state.stack_tracer_enabled, 32, fp);
+ fclose(fp);
+ }
+ }
+
+ if (access("/proc/sys/kernel/ftrace_enabled", F_OK) == 0) {
+ FILE *fp = fopen("/proc/sys/kernel/ftrace_enabled", "r");
+
+ if (fp) {
+ saved_state.ftrace_enabled = malloc(32);
+ if (saved_state.ftrace_enabled)
+ fgets(saved_state.ftrace_enabled, 32, fp);
+ fclose(fp);
+ }
+ }
+
+ if (ftrace_file_exists("function_profile_enabled"))
+ saved_state.function_profile_enabled = ftrace_read_file("function_profile_enabled");
+
+ saved_state.saved = 1;
+}
+
+void ftrace_restore_settings(void)
+{
+ if (!saved_state.saved)
+ return;
+
+ ftrace_write_file("current_tracer", "nop\n");
+ ftrace_write_file("events/enable", "0\n");
+
+ if (ftrace_file_exists("tracing_max_latency"))
+ ftrace_write_file("tracing_max_latency", "0\n");
+
+ if (saved_state.tracing_cpumask)
+ ftrace_write_file("tracing_cpumask", saved_state.tracing_cpumask);
+
+ if (ftrace_file_exists("trace_clock"))
+ ftrace_write_file("trace_clock", "local\n");
+
+ if (saved_state.function_profile_enabled)
+ ftrace_write_file("function_profile_enabled", saved_state.function_profile_enabled);
+
+ if (saved_state.ftrace_enabled) {
+ FILE *fp = fopen("/proc/sys/kernel/ftrace_enabled", "w");
+
+ if (fp) {
+ fprintf(fp, "%s", saved_state.ftrace_enabled);
+ fclose(fp);
+ }
+ }
+
+ if (saved_state.stack_tracer_enabled && ftrace_file_exists("stack_max_size")) {
+ FILE *fp = fopen("/proc/sys/kernel/stack_tracer_enabled", "w");
+
+ if (fp) {
+ fprintf(fp, "%s", saved_state.stack_tracer_enabled);
+ fclose(fp);
+ }
+ ftrace_write_file("stack_max_size", "0\n");
+ }
+
+ if (saved_state.buffer_size)
+ ftrace_write_file("buffer_size_kb", saved_state.buffer_size);
+
+ if (saved_state.tracing_on)
+ ftrace_write_file("tracing_on", saved_state.tracing_on);
+
+ if (saved_state.tracing_enabled)
+ ftrace_write_file("tracing_enabled", saved_state.tracing_enabled);
+
+ if (saved_state.trace_options) {
+ char *options = strdup(saved_state.trace_options);
+
+ if (options) {
+ char *token = strtok(options, "\n");
+
+ while (token) {
+ ftrace_write_file("trace_options", token);
+ token = strtok(NULL, "\n");
+ }
+ free(options);
+ }
+ }
+
+ ftrace_clear_trace();
+
+ if (ftrace_file_exists("set_ftrace_filter"))
+ ftrace_write_file("set_ftrace_filter", "\n");
+}
+
+char **ftrace_get_available_tracers(int *count)
+{
+ char *path;
+ FILE *fp;
+ char **tracers = NULL;
+ char *line = NULL;
+ size_t len = 0;
+ int n = 0;
+ int capacity = 16;
+
+ path = ftrace_get_path("available_tracers");
+ if (!path) {
+ *count = 0;
+ return NULL;
+ }
+
+ fp = fopen(path, "r");
+ free(path);
+
+ if (!fp) {
+ *count = 0;
+ return NULL;
+ }
+
+ tracers = malloc(sizeof(char *) * capacity);
+ if (!tracers) {
+ fclose(fp);
+ *count = 0;
+ return NULL;
+ }
+
+ if (getline(&line, &len, fp) != -1) {
+ char *token;
+ char *saveptr;
+
+ token = strtok_r(line, " \n", &saveptr);
+ while (token) {
+ if (n >= capacity) {
+ capacity *= 2;
+ char **new_tracers = realloc(tracers, sizeof(char *) * capacity);
+
+ if (!new_tracers) {
+ while (n > 0)
+ free(tracers[--n]);
+ free(tracers);
+ free(line);
+ fclose(fp);
+ *count = 0;
+ return NULL;
+ }
+ tracers = new_tracers;
+ }
+
+ tracers[n] = strdup(token);
+ if (!tracers[n]) {
+ while (n > 0)
+ free(tracers[--n]);
+ free(tracers);
+ free(line);
+ fclose(fp);
+ *count = 0;
+ return NULL;
+ }
+ n++;
+ token = strtok_r(NULL, " \n", &saveptr);
+ }
+ }
+
+ free(line);
+ fclose(fp);
+
+ *count = n;
+ return tracers;
+}
+
+int ftrace_set_tracer(const char *tracer)
+{
+ char *path;
+
+ path = ftrace_get_path("current_tracer");
+ if (!path)
+ return -1;
+
+ SAFE_FILE_PRINTF(path, "%s", tracer);
+ free(path);
+
+ return 0;
+}
+
+void ftrace_clear_trace(void)
+{
+ ftrace_write_file("trace", "\n");
+}
+
+void ftrace_enable_tracing(void)
+{
+ ftrace_write_file("tracing_on", "1\n");
+}
+
+void ftrace_disable_tracing(void)
+{
+ ftrace_write_file("tracing_on", "0\n");
+}
diff --git a/testcases/kernel/tracing/ftrace_test/ftrace_lib.h b/testcases/kernel/tracing/ftrace_test/ftrace_lib.h
new file mode 100644
index 000000000..79fdfee28
--- /dev/null
+++ b/testcases/kernel/tracing/ftrace_test/ftrace_lib.h
@@ -0,0 +1,136 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright (c) 2010 FUJITSU LIMITED
+ * Copyright (c) 2024 Linux Test Project
+ * Copyright (c) IBM, 2026
+ *
+ * Author: Li Zefan <lizf@cn.fujitsu.com>
+ * Converted to C by: Praveen K Pandey <praveen@linux.ibm.com>
+ */
+
+#ifndef FTRACE_LIB_H
+#define FTRACE_LIB_H
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <sys/mount.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <errno.h>
+#include <limits.h>
+
+extern char *tracing_path;
+extern char *debugfs_path;
+
+struct ftrace_saved_state {
+ char *trace_options;
+ char *tracing_on;
+ char *buffer_size;
+ char *tracing_cpumask;
+ char *tracing_enabled;
+ char *stack_tracer_enabled;
+ char *ftrace_enabled;
+ char *function_profile_enabled;
+ int saved;
+};
+
+extern struct ftrace_saved_state saved_state;
+
+/**
+ * ftrace_initialize - Initialize ftrace test environment
+ *
+ * Checks if debugfs is mounted, mounts it if needed, verifies tracing
+ * support, and saves current ftrace settings.
+ */
+void ftrace_initialize(void);
+
+/**
+ * ftrace_cleanup - Cleanup and restore ftrace settings
+ *
+ * Restores all saved ftrace settings and unmounts debugfs if needed.
+ */
+void ftrace_cleanup(void);
+
+/**
+ * ftrace_save_settings - Save current ftrace settings
+ *
+ * Saves all ftrace configuration to restore later.
+ */
+void ftrace_save_settings(void);
+
+/**
+ * ftrace_restore_settings - Restore saved ftrace settings
+ *
+ * Restores ftrace configuration saved by ftrace_save_settings().
+ */
+void ftrace_restore_settings(void);
+
+/**
+ * ftrace_get_path - Get full path to a tracing file
+ * @filename: Name of the file in tracing directory
+ *
+ * Return: Allocated string with full path (caller must free)
+ */
+char *ftrace_get_path(const char *filename);
+
+/**
+ * ftrace_read_file - Read content from a tracing file
+ * @filename: Name of the file in tracing directory
+ *
+ * Return: Allocated string with file content (caller must free)
+ */
+char *ftrace_read_file(const char *filename);
+
+/**
+ * ftrace_write_file - Write content to a tracing file
+ * @filename: Name of the file in tracing directory
+ * @content: Content to write
+ *
+ * Return: 0 on success, -1 on failure
+ */
+int ftrace_write_file(const char *filename, const char *content);
+
+/**
+ * ftrace_file_exists - Check if a tracing file exists
+ * @filename: Name of the file in tracing directory
+ *
+ * Return: 1 if exists, 0 otherwise
+ */
+int ftrace_file_exists(const char *filename);
+
+/**
+ * ftrace_get_available_tracers - Get list of available tracers
+ * @count: Pointer to store number of tracers
+ *
+ * Return: Array of tracer names (caller must free)
+ */
+char **ftrace_get_available_tracers(int *count);
+
+/**
+ * ftrace_set_tracer - Set current tracer
+ * @tracer: Name of the tracer to set
+ *
+ * Return: 0 on success, -1 on failure
+ */
+int ftrace_set_tracer(const char *tracer);
+
+/**
+ * ftrace_clear_trace - Clear the trace buffer
+ */
+void ftrace_clear_trace(void);
+
+/**
+ * ftrace_enable_tracing - Enable tracing
+ */
+void ftrace_enable_tracing(void);
+
+/**
+ * ftrace_disable_tracing - Disable tracing
+ */
+void ftrace_disable_tracing(void);
+
+#endif /* FTRACE_LIB_H */
+
--
2.50.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [LTP] [PATCH v6 2/5] ftrace: Convert ftrace_regression01.sh to C
2026-06-09 4:16 [LTP] [PATCH v6 0/5] ftrace: Convert shell tests to C Praveen K Pandey
2026-06-09 4:16 ` [LTP] [PATCH v6 1/5] ftrace: Add common library for C implementation Praveen K Pandey
@ 2026-06-09 4:16 ` Praveen K Pandey
2026-06-09 4:16 ` [LTP] [PATCH v6 3/5] ftrace: Convert ftrace_regression02.sh " Praveen K Pandey
` (2 subsequent siblings)
4 siblings, 0 replies; 8+ messages in thread
From: Praveen K Pandey @ 2026-06-09 4:16 UTC (permalink / raw)
To: ltp
Convert ftrace_regression01.sh to C using the new LTP test API.
This test validates that the kernel does not panic when enabling
userstacktrace with page fault events.
This is a regression test for commit 1dbd195 (tracing: Fix preempt
count leak). The bug caused kernel panics when enabling userstacktrace
option together with page fault events.
Key changes:
- Uses new LTP C API (tst_test.h)
- Leverages ftrace_lib for common operations
- Proper error handling with LTP macros
- Requires root privileges (.needs_root = 1)
- Tests for kernel panic by enabling stack tracer, userstacktrace,
and page fault events in a loop
Signed-off-by: Praveen K Pandey <praveen@linux.ibm.com>
---
runtest/tracing | 6 +-
.../tracing/ftrace_test/ftrace_regression01.c | 126 ++++++++++++++++++
.../ftrace_test/ftrace_regression01.sh | 83 ------------
3 files changed, 129 insertions(+), 86 deletions(-)
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/runtest/tracing b/runtest/tracing
index 674e2ad97..4204c2dc4 100644
--- a/runtest/tracing
+++ b/runtest/tracing
@@ -1,7 +1,7 @@
#DESCRIPTION:Tracing testing
-ftrace_regression01 ftrace_regression01.sh
-ftrace_regression02 ftrace_regression02.sh
-ftrace-stress-test ftrace_stress_test.sh 90
+ftrace_regression01 ftrace_regression01
+ftrace_regression02 ftrace_regression02
+ftrace-stress-test ftrace_stress_test
dynamic_debug01 dynamic_debug01.sh
fanotify25 fanotify25
pt_full_trace_basic pt_test
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..baa8d01aa
--- /dev/null
+++ b/testcases/kernel/tracing/ftrace_test/ftrace_regression01.c
@@ -0,0 +1,126 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2015 Red Hat Inc.
+ * Copyright (c) 2024 Linux Test Project
+ * Copyright (c) IBM, 2026
+ *
+ * Author: Li Wang <liwang@redhat.com>
+ * Converted to C by: Praveen K Pandey <praveen@linux.ibm.com>
+ */
+
+/*\
+ * Test for kernel panic while using userstacktrace with page fault events.
+ *
+ * This is a regression test for commit 1dbd195 (tracing: Fix preempt count leak).
+ * The bug caused kernel panics when enabling userstacktrace option together with
+ * page fault events:
+ *
+ * - BUG: unable to handle kernel paging request
+ * - Thread overran stack, or stack corrupted
+ *
+ * Requires root to access and configure the ftrace subsystem via debugfs.
+ *
+ * [Algorithm]
+ *
+ * - Enable stack tracer
+ * - Enable userstacktrace option
+ * - Enable page fault events (either exceptions:page_fault_kernel or
+ * kmem:mm_kernel_pagefault depending on kernel version)
+ * - Repeat the loop multiple times to trigger potential race conditions
+ * - Verify system remains stable without kernel panic
+ */
+
+#include "tst_test.h"
+#include "ftrace_lib.h"
+
+#define LOOP_COUNT 10
+
+static void run_test(void)
+{
+ int i;
+ char *exc_page_fault_enable = NULL;
+ char *mm_page_fault_enable = NULL;
+ int use_exc_event = 0;
+
+ /* Check if stack tracer is available */
+ if (access("/proc/sys/kernel/stack_tracer_enabled", F_OK) != 0)
+ tst_brk(TCONF, "Stack tracer is not configured in this kernel");
+
+ /* Determine which page fault event is available */
+ if (ftrace_file_exists("events/exceptions/page_fault_kernel/enable")) {
+ use_exc_event = 1;
+ exc_page_fault_enable = ftrace_read_file("events/exceptions/page_fault_kernel/enable");
+ } else if (ftrace_file_exists("events/kmem/mm_kernel_pagefault/enable")) {
+ use_exc_event = 0;
+ mm_page_fault_enable = ftrace_read_file("events/kmem/mm_kernel_pagefault/enable");
+ } else {
+ tst_brk(TCONF, "Neither page_fault_kernel nor mm_kernel_pagefault event is available");
+ }
+
+ /* Run the test loop */
+ for (i = 0; i < LOOP_COUNT; i++) {
+ char *options;
+
+ /* Enable stack tracer */
+ SAFE_FILE_PRINTF("/proc/sys/kernel/stack_tracer_enabled", "1");
+
+ /* Enable userstacktrace option */
+ if (ftrace_write_file("trace_options", "userstacktrace\n") != 0)
+ tst_brk(TBROK, "Failed to set userstacktrace option");
+
+ /* Verify userstacktrace is enabled */
+ options = ftrace_read_file("trace_options");
+ if (!options || !strstr(options, "userstacktrace")) {
+ free(options);
+ tst_brk(TBROK, "Failed to enable userstacktrace");
+ }
+ free(options);
+
+ /* Enable page fault event */
+ if (use_exc_event) {
+ if (ftrace_write_file("events/exceptions/page_fault_kernel/enable", "1\n") != 0)
+ tst_res(TINFO, "Failed to enable page_fault_kernel event");
+ } else {
+ if (ftrace_write_file("events/kmem/mm_kernel_pagefault/enable", "1\n") != 0)
+ tst_res(TINFO, "Failed to enable mm_kernel_pagefault event");
+ }
+
+ /* Wait for trace events to be written */
+ char *trace_content = TST_RETRY_FUNC(ftrace_read_file("trace"), TST_RETVAL_NOTNULL);
+ free(trace_content);
+ }
+
+ /* Restore page fault event state */
+ if (use_exc_event && exc_page_fault_enable) {
+ ftrace_write_file("events/exceptions/page_fault_kernel/enable", exc_page_fault_enable);
+ free(exc_page_fault_enable);
+ } else if (!use_exc_event && mm_page_fault_enable) {
+ ftrace_write_file("events/kmem/mm_kernel_pagefault/enable", mm_page_fault_enable);
+ free(mm_page_fault_enable);
+ }
+
+ tst_res(TPASS, "System did not panic with userstacktrace enabled");
+}
+
+static void setup(void)
+{
+ ftrace_initialize();
+}
+
+static void cleanup(void)
+{
+ ftrace_cleanup();
+}
+
+static struct tst_test test = {
+ .test_all = run_test,
+ .setup = setup,
+ .cleanup = cleanup,
+ .needs_root = 1,
+ .needs_tmpdir = 1,
+ .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.50.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [LTP] [PATCH v6 3/5] ftrace: Convert ftrace_regression02.sh to C
2026-06-09 4:16 [LTP] [PATCH v6 0/5] ftrace: Convert shell tests to C Praveen K Pandey
2026-06-09 4:16 ` [LTP] [PATCH v6 1/5] ftrace: Add common library for C implementation Praveen K Pandey
2026-06-09 4:16 ` [LTP] [PATCH v6 2/5] ftrace: Convert ftrace_regression01.sh to C Praveen K Pandey
@ 2026-06-09 4:16 ` Praveen K Pandey
2026-06-09 4:16 ` [LTP] [PATCH v6 4/5] ftrace: Convert ftrace_stress_test.sh " Praveen K Pandey
2026-06-09 4:16 ` [LTP] [PATCH v6 5/5] ftrace: Remove obsolete shell test files Praveen K Pandey
4 siblings, 0 replies; 8+ messages in thread
From: Praveen K Pandey @ 2026-06-09 4:16 UTC (permalink / raw)
To: ltp
Convert ftrace_regression02.sh to C using the new LTP test API.
This test validates ftrace event tracing functionality, specifically
checking for grp and res fields in signal_generate events.
This is a regression test for commits 6c303d3 and 163566f which
added group and result fields to signal events.
Key changes:
- Uses new LTP C API (tst_test.h)
- Leverages ftrace_lib for common operations
- Proper error handling with LTP macros
- Sets .min_kver = "3.2" for kernel version requirement
- Requires root privileges (.needs_root = 1)
The test enables event tracing, generates events, and verifies
they are captured in the trace buffer with the expected fields.
Signed-off-by: Praveen K Pandey <praveen@linux.ibm.com>
---
.../tracing/ftrace_test/ftrace_regression02.c | 101 ++++++++++++++++++
.../ftrace_test/ftrace_regression02.sh | 63 -----------
2 files changed, 101 insertions(+), 63 deletions(-)
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/testcases/kernel/tracing/ftrace_test/ftrace_regression02.c b/testcases/kernel/tracing/ftrace_test/ftrace_regression02.c
new file mode 100644
index 000000000..4484ba613
--- /dev/null
+++ b/testcases/kernel/tracing/ftrace_test/ftrace_regression02.c
@@ -0,0 +1,101 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2015 Red Hat Inc.
+ * Copyright (c) 2024 Linux Test Project
+ * Copyright (c) IBM, 2026
+ *
+ * Author: Li Wang <liwang@redhat.com>
+ * Converted to C by: Praveen K Pandey <praveen@linux.ibm.com>
+ */
+
+/*\
+ * Verify that signal:signal_generate tracepoint exposes 'grp=' and 'res=' fields.
+ *
+ * This test verifies kernel commits that added more information to the
+ * signal_generate tracepoint:
+ *
+ * - Commit 6c303d3 (tracing: let trace_signal_generate() report more info...)
+ * - Commit 163566f (tracing: send_sigqueue() needs trace_signal_generate())
+ *
+ * These fields were added in kernel 3.2.
+ *
+ * Requires root to access and configure the ftrace subsystem via debugfs.
+ *
+ * [Algorithm]
+ *
+ * - Enable signal:signal_generate event
+ * - Enable tracing
+ * - Generate signals by running commands
+ * - Read trace output and search for 'grp=' and 'res=' fields
+ * - Test passes if both fields are found in the trace
+ */
+
+#include "tst_test.h"
+#include "ftrace_lib.h"
+
+#define SIGNAL_LOOP 100
+
+static void run_test(void)
+{
+ int i;
+ char *trace_content;
+ int found = 0;
+
+ /* Set event */
+ if (ftrace_write_file("set_event", "signal:signal_generate\n") != 0)
+ tst_brk(TBROK, "Failed to set signal:signal_generate event");
+
+ /* Enable tracing */
+ ftrace_enable_tracing();
+
+ /* Clear trace buffer */
+ ftrace_clear_trace();
+
+ /* Generate some signals by running commands */
+ for (i = 0; i < SIGNAL_LOOP; i++) {
+ /* Run a simple command that will generate signals */
+ if (system("ls -l /proc > /dev/null 2>&1") == -1)
+ tst_res(TINFO, "Command execution failed, continuing...");
+ }
+
+ /* Wait for trace to be written and contain signal events */
+ trace_content = TST_RETRY_FUNC(ftrace_read_file("trace"), TST_RETVAL_NOTNULL);
+ if (!trace_content)
+ tst_brk(TBROK, "Failed to read trace file");
+
+ /* Check for 'grp=' and 'res=' fields in trace */
+ if (strstr(trace_content, "grp=") && strstr(trace_content, "res="))
+ found = 1;
+
+ free(trace_content);
+
+ if (found)
+ tst_res(TPASS, "signal_generate event contains grp and res fields");
+ else
+ tst_res(TFAIL, "signal_generate event missing grp or res fields");
+}
+
+static void setup(void)
+{
+ ftrace_initialize();
+}
+
+static void cleanup(void)
+{
+ ftrace_cleanup();
+}
+
+static struct tst_test test = {
+ .test_all = run_test,
+ .setup = setup,
+ .cleanup = cleanup,
+ .needs_root = 1,
+ .needs_tmpdir = 1,
+ .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.50.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [LTP] [PATCH v6 4/5] ftrace: Convert ftrace_stress_test.sh to C
2026-06-09 4:16 [LTP] [PATCH v6 0/5] ftrace: Convert shell tests to C Praveen K Pandey
` (2 preceding siblings ...)
2026-06-09 4:16 ` [LTP] [PATCH v6 3/5] ftrace: Convert ftrace_regression02.sh " Praveen K Pandey
@ 2026-06-09 4:16 ` Praveen K Pandey
2026-06-09 4:16 ` [LTP] [PATCH v6 5/5] ftrace: Remove obsolete shell test files Praveen K Pandey
4 siblings, 0 replies; 8+ messages in thread
From: Praveen K Pandey @ 2026-06-09 4:16 UTC (permalink / raw)
To: ltp
Convert ftrace_stress_test.sh to C using the new LTP test API.
This test performs stress testing of ftrace by running multiple
threads that concurrently modify various ftrace settings.
Key changes:
- Uses new LTP C API (tst_test.h)
- Leverages ftrace_lib for common operations
- Multi-threaded stress testing with proper synchronization
- Proper cleanup: stop_stress_tests() resets thread_count to 0
after joining threads to avoid double-join (undefined behavior)
- Variables stop_testing and thread_count are reset at the start
of run_test() to support multiple test iterations (-i N)
- Requires root privileges (.needs_root = 1)
- Test timeout set to 300 seconds
The test creates multiple threads that stress test different
ftrace interfaces concurrently for a specified duration.
Signed-off-by: Praveen K Pandey <praveen@linux.ibm.com>
---
.../tracing/ftrace_test/ftrace_stress_test.c | 328 ++++++++++++++++++
.../tracing/ftrace_test/ftrace_stress_test.sh | 121 -------
2 files changed, 328 insertions(+), 121 deletions(-)
create mode 100644 testcases/kernel/tracing/ftrace_test/ftrace_stress_test.c
delete mode 100755 testcases/kernel/tracing/ftrace_test/ftrace_stress_test.sh
diff --git a/testcases/kernel/tracing/ftrace_test/ftrace_stress_test.c b/testcases/kernel/tracing/ftrace_test/ftrace_stress_test.c
new file mode 100644
index 000000000..f4d267254
--- /dev/null
+++ b/testcases/kernel/tracing/ftrace_test/ftrace_stress_test.c
@@ -0,0 +1,328 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2010 FUJITSU LIMITED
+ * Copyright (c) 2024 Linux Test Project
+ * Copyright (c) IBM, 2026
+ *
+ * Author: Li Zefan <lizf@cn.fujitsu.com>
+ * Converted to C by: Praveen K Pandey <praveen@linux.ibm.com>
+ */
+
+/*\
+ * Stress test for ftrace subsystem.
+ *
+ * This test exercises various ftrace features concurrently to detect
+ * race conditions, memory leaks, and other issues in the ftrace subsystem.
+ *
+ * Requires root to access and configure the ftrace subsystem via debugfs.
+ *
+ * [Algorithm]
+ *
+ * The test spawns multiple threads, each exercising a different ftrace
+ * feature:
+ *
+ * - Switching between different tracers
+ * - Reading from trace_pipe
+ * - Enabling/disabling events
+ * - Modifying buffer size
+ * - Setting trace filters
+ * - Modifying trace options
+ * - And more...
+ *
+ * All threads run concurrently for a specified duration, then the test
+ * verifies the system is still stable.
+ */
+
+#include <pthread.h>
+#include <signal.h>
+#include "tst_test.h"
+#include "ftrace_lib.h"
+
+#define DEFAULT_TEST_DURATION 60 /* seconds */
+#define MAX_THREADS 20
+
+static volatile int stop_testing = 0;
+static int test_duration = DEFAULT_TEST_DURATION;
+static pthread_t threads[MAX_THREADS];
+static int thread_count = 0;
+
+struct stress_test {
+ const char *name;
+ const char *file;
+ void *(*func)(void *);
+ int enabled;
+};
+
+/* Thread function for current_tracer stress test */
+static void *stress_current_tracer(void *arg)
+{
+ int count;
+ char **tracers;
+ int i, loop;
+
+ (void)arg;
+
+ tracers = ftrace_get_available_tracers(&count);
+ if (!tracers || count == 0) {
+ tst_res(TINFO, "No tracers available");
+ return NULL;
+ }
+
+ loop = 0;
+ while (!stop_testing) {
+ for (i = 0; i < count && !stop_testing; i++) {
+ /* Skip mmiotrace as it can cause issues */
+ if (strcmp(tracers[i], "mmiotrace") == 0)
+ continue;
+
+ ftrace_set_tracer(tracers[i]);
+ }
+ loop++;
+ if (loop >= 200)
+ usleep(1000000); /* Sleep 1 second after 200 loops */
+ }
+
+ for (i = 0; i < count; i++)
+ free(tracers[i]);
+ free(tracers);
+
+ return NULL;
+}
+
+/* Thread function for trace_pipe stress test */
+static void *stress_trace_pipe(void *arg)
+{
+ char *path;
+ FILE *fp;
+ int loop = 0;
+
+ (void)arg;
+
+ path = ftrace_get_path("trace_pipe");
+ if (!path)
+ return NULL;
+
+ while (!stop_testing) {
+ fp = fopen(path, "r");
+ if (fp) {
+ /* Read for a short time */
+ usleep(200000); /* 200ms */
+ fclose(fp);
+ }
+
+ usleep(200000); /* 200ms */
+ loop++;
+ if (loop >= 20) {
+ sleep(2);
+ loop = 0;
+ }
+ }
+
+ free(path);
+ return NULL;
+}
+
+/* Thread function for set_event stress test */
+static void *stress_set_event(void *arg)
+{
+ int i;
+
+ (void)arg;
+
+ while (!stop_testing) {
+ /* Enable/disable all events */
+ for (i = 0; i < 100 && !stop_testing; i++) {
+ ftrace_write_file("events/enable", "1\n");
+ ftrace_write_file("events/enable", "0\n");
+ }
+
+ sleep(1);
+ }
+
+ return NULL;
+}
+
+/* Thread function for buffer_size_kb stress test */
+static void *stress_buffer_size(void *arg)
+{
+ const char *sizes[] = {"1024", "2048", "4096", "8192"};
+ int i;
+
+ (void)arg;
+
+ while (!stop_testing) {
+ for (i = 0; i < 4 && !stop_testing; i++) {
+ char buf[32];
+ snprintf(buf, sizeof(buf), "%s\n", sizes[i]);
+ ftrace_write_file("buffer_size_kb", buf);
+ usleep(100000);
+ }
+ sleep(1);
+ }
+
+ return NULL;
+}
+
+/* Thread function for tracing_on stress test */
+static void *stress_tracing_on(void *arg)
+{
+ int i;
+
+ (void)arg;
+
+ while (!stop_testing) {
+ for (i = 0; i < 100 && !stop_testing; i++) {
+ ftrace_enable_tracing();
+ ftrace_disable_tracing();
+ }
+ sleep(1);
+ }
+
+ return NULL;
+}
+
+/* Thread function for trace_options stress test */
+static void *stress_trace_options(void *arg)
+{
+ const char *options[] = {
+ "print-parent", "sym-offset", "sym-addr",
+ "verbose", "raw", "hex", "bin", "block"
+ };
+ int i;
+
+ (void)arg;
+
+ while (!stop_testing) {
+ for (i = 0; i < 8 && !stop_testing; i++) {
+ char buf[64];
+ snprintf(buf, sizeof(buf), "%s\n", options[i]);
+ ftrace_write_file("trace_options", buf);
+ snprintf(buf, sizeof(buf), "no%s\n", options[i]);
+ ftrace_write_file("trace_options", buf);
+ }
+ sleep(1);
+ }
+
+ return NULL;
+}
+
+/* Thread function for set_ftrace_filter stress test */
+static void *stress_set_ftrace_filter(void *arg)
+{
+ (void)arg;
+
+ if (!ftrace_file_exists("set_ftrace_filter"))
+ return NULL;
+
+ while (!stop_testing) {
+ ftrace_write_file("set_ftrace_filter", "schedule\n");
+ ftrace_write_file("set_ftrace_filter", "\n");
+ usleep(500000);
+ }
+
+ return NULL;
+}
+
+static struct stress_test stress_tests[] = {
+ {"current_tracer", "current_tracer", stress_current_tracer, 0},
+ {"trace_pipe", "trace_pipe", stress_trace_pipe, 0},
+ {"set_event", "events/enable", stress_set_event, 0},
+ {"buffer_size_kb", "buffer_size_kb", stress_buffer_size, 0},
+ {"tracing_on", "tracing_on", stress_tracing_on, 0},
+ {"trace_options", "trace_options", stress_trace_options, 0},
+ {"set_ftrace_filter", "set_ftrace_filter", stress_set_ftrace_filter, 0},
+ {NULL, NULL, NULL, 0}
+};
+
+static void check_available_tests(void)
+{
+ int i;
+
+ for (i = 0; stress_tests[i].name; i++) {
+ if (ftrace_file_exists(stress_tests[i].file) ||
+ access(stress_tests[i].file, F_OK) == 0) {
+ stress_tests[i].enabled = 1;
+ tst_res(TINFO, "Test target available: %s", stress_tests[i].name);
+ } else {
+ tst_res(TINFO, "Test target not available: %s", stress_tests[i].name);
+ }
+ }
+}
+
+static void start_stress_tests(void)
+{
+ int i;
+
+ thread_count = 0;
+ for (i = 0; stress_tests[i].name; i++) {
+ if (!stress_tests[i].enabled)
+ continue;
+
+ if (pthread_create(&threads[thread_count], NULL,
+ stress_tests[i].func, NULL) != 0) {
+ tst_res(TWARN, "Failed to create thread for %s",
+ stress_tests[i].name);
+ } else {
+ tst_res(TINFO, "Started stress test: %s", stress_tests[i].name);
+ thread_count++;
+ }
+ }
+
+ tst_res(TINFO, "Started %d stress test threads", thread_count);
+}
+
+static void stop_stress_tests(void)
+{
+ int i;
+
+ stop_testing = 1;
+
+ for (i = 0; i < thread_count; i++) {
+ pthread_join(threads[i], NULL);
+ }
+
+ thread_count = 0;
+ tst_res(TINFO, "All stress test threads stopped");
+}
+
+static void run_test(void)
+{
+ stop_testing = 0;
+ thread_count = 0;
+
+ tst_res(TINFO, "Starting ftrace stress test for %d seconds", test_duration);
+
+ check_available_tests();
+ start_stress_tests();
+
+ /* Run for specified duration */
+ sleep(test_duration);
+
+ stop_stress_tests();
+
+ tst_res(TPASS, "Ftrace stress test completed successfully");
+ tst_res(TINFO, "Check dmesg for any kernel warnings or errors");
+}
+
+static void setup(void)
+{
+ ftrace_initialize();
+}
+
+static void cleanup(void)
+{
+ if (thread_count > 0)
+ stop_stress_tests();
+
+ ftrace_cleanup();
+}
+
+static struct tst_test test = {
+ .test_all = run_test,
+ .setup = setup,
+ .cleanup = cleanup,
+ .needs_root = 1,
+ .needs_tmpdir = 1,
+ .timeout = DEFAULT_TEST_DURATION + 30,
+};
+
diff --git a/testcases/kernel/tracing/ftrace_test/ftrace_stress_test.sh b/testcases/kernel/tracing/ftrace_test/ftrace_stress_test.sh
deleted file mode 100755
index 159ba1a66..000000000
--- a/testcases/kernel/tracing/ftrace_test/ftrace_stress_test.sh
+++ /dev/null
@@ -1,121 +0,0 @@
-#! /bin/sh
-
-###########################################################################
-## ##
-## Copyright (c) 2010 FUJITSU LIMITED ##
-## ##
-## 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 Zefan <lizf@cn.fujitsu.com> ##
-## ##
-###########################################################################
-
-export TCID="ftrace-stress-test"
-export TST_TOTAL=1
-export TST_COUNT=1
-
-. ftrace_lib.sh
-
-test_targets=" \
-trace_pipe current_tracer ftrace_enabled function_profile_enabled \
-set_event set_ftrace_pid stack_max_size stack_trace trace trace_clock \
-trace_options trace_stat tracing_enabled tracing_max_latency \
-tracing_on function_profile_enabled buffer_size_kb tracing_cpumask \
-set_ftrace_filter"
-
-get_skip_targets()
-{
- NR_PIDS=0
- for target in ${test_targets}; do
- if [ ! -e $TRACING_PATH/$target ] &&
- [ ! -e /proc/sys/kernel/$target ]; then
- eval skip_$target=1
- tst_resm TINFO "$target is not supported. Skip it."
- else
- eval skip_$target=0
- NR_PIDS=$((NR_PIDS + 1))
- fi
- done
- # Export it before sub case is lanuched.
- export NR_PIDS
-}
-
-should_skip_target()
-{
- local skip_var=skip_$1
- eval local skip_val=\$${skip_var}
- [ "$skip_val" = 1 ]
-}
-
-test_kill()
-{
- tst_resm TINFO "killing ${pid0}"
- kill -USR1 ${pid0}
- wait ${pid0}
-
- local p=1;
- while [ $p -lt $NR_PIDS ]; do
- local pid_var=pid${p}
- eval local kill_pid=\$${pid_var}
- tst_resm TINFO "killing ${kill_pid}"
- kill -KILL $kill_pid
- wait ${kill_pid}
- p=$((p + 1))
- done
-}
-
-test_stress()
-{
- local index=0;
-
- tst_resm TINFO "Test targets: ${test_targets}"
-
- get_skip_targets
- for target in ${test_targets}; do
- if should_skip_target $target; then
- continue
- fi
- sh ftrace_${target}.sh &
- eval pid${index}=$!
- tst_resm TINFO "Start pid${index}=$! $SPATH/ftrace_${target}.sh"
- index=$((index + 1))
- done
- export_pids
-}
-
-export_pids()
-{
- local p=0
- while [ $p -lt $NR_PIDS ]; do
- export pid${p}
- p=$((p + 1))
- done
-}
-
-cd ftrace_stress/
-# ----------------------------
-tst_resm TINFO "Ftrace Stress Test Begin"
-
-test_begin
-
-test_stress
-
-test_wait
-
-test_kill
-
-tst_resm TINFO "Finished running the test. Run dmesg to double-check for bugs"
-
-tst_exit
-
--
2.50.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [LTP] [PATCH v6 5/5] ftrace: Remove obsolete shell test files
2026-06-09 4:16 [LTP] [PATCH v6 0/5] ftrace: Convert shell tests to C Praveen K Pandey
` (3 preceding siblings ...)
2026-06-09 4:16 ` [LTP] [PATCH v6 4/5] ftrace: Convert ftrace_stress_test.sh " Praveen K Pandey
@ 2026-06-09 4:16 ` Praveen K Pandey
4 siblings, 0 replies; 8+ messages in thread
From: Praveen K Pandey @ 2026-06-09 4:16 UTC (permalink / raw)
To: ltp
Remove the old shell-based ftrace test files and helper scripts
that have been converted to C. This includes:
- ftrace_lib.sh (replaced by ftrace_lib.c/h)
- ftrace_stress/*.sh (18 helper scripts, replaced by ftrace_stress_test.c)
The C implementation provides better error handling, uses LTP's
modern test API, and is more maintainable.
Signed-off-by: Praveen K Pandey <praveen@linux.ibm.com>
---
.../kernel/tracing/ftrace_test/ftrace_lib.sh | 180 ------------------
.../ftrace_stress/ftrace_buffer_size_kb.sh | 45 -----
.../ftrace_stress/ftrace_current_tracer.sh | 32 ----
.../ftrace_stress/ftrace_ftrace_enabled.sh | 38 ----
.../ftrace_function_profile_enabled.sh | 38 ----
.../ftrace_stress/ftrace_set_event.sh | 46 -----
.../ftrace_stress/ftrace_set_ftrace_filter.sh | 119 ------------
.../ftrace_stress/ftrace_set_ftrace_pid.sh | 37 ----
.../ftrace_stress/ftrace_stack_max_size.sh | 27 ---
.../ftrace_stress/ftrace_stack_trace.sh | 35 ----
.../ftrace_test/ftrace_stress/ftrace_trace.sh | 25 ---
.../ftrace_stress/ftrace_trace_clock.sh | 27 ---
.../ftrace_stress/ftrace_trace_options.sh | 58 ------
.../ftrace_stress/ftrace_trace_pipe.sh | 45 -----
.../ftrace_stress/ftrace_trace_stat.sh | 38 ----
.../ftrace_stress/ftrace_tracing_cpumask.sh | 91 ---------
.../ftrace_stress/ftrace_tracing_enabled.sh | 38 ----
.../ftrace_tracing_max_latency.sh | 27 ---
.../ftrace_stress/ftrace_tracing_on.sh | 38 ----
19 files changed, 984 deletions(-)
delete mode 100755 testcases/kernel/tracing/ftrace_test/ftrace_lib.sh
delete mode 100755 testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_buffer_size_kb.sh
delete mode 100755 testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_current_tracer.sh
delete mode 100755 testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_ftrace_enabled.sh
delete mode 100755 testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_function_profile_enabled.sh
delete mode 100755 testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_set_event.sh
delete mode 100755 testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_set_ftrace_filter.sh
delete mode 100755 testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_set_ftrace_pid.sh
delete mode 100755 testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_stack_max_size.sh
delete mode 100755 testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_stack_trace.sh
delete mode 100755 testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_trace.sh
delete mode 100755 testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_trace_clock.sh
delete mode 100755 testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_trace_options.sh
delete mode 100755 testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_trace_pipe.sh
delete mode 100755 testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_trace_stat.sh
delete mode 100755 testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_tracing_cpumask.sh
delete mode 100755 testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_tracing_enabled.sh
delete mode 100755 testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_tracing_max_latency.sh
delete mode 100755 testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_tracing_on.sh
diff --git a/testcases/kernel/tracing/ftrace_test/ftrace_lib.sh b/testcases/kernel/tracing/ftrace_test/ftrace_lib.sh
deleted file mode 100755
index 5f8f8a2c4..000000000
--- a/testcases/kernel/tracing/ftrace_test/ftrace_lib.sh
+++ /dev/null
@@ -1,180 +0,0 @@
-#!/bin/sh
-
-###########################################################################
-## ##
-## Copyright (c) 2010 FUJITSU LIMITED ##
-## ##
-## 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 Zefan <lizf@cn.fujitsu.com> ##
-## ##
-###########################################################################
-
-. test.sh
-
-ftrace_test_init()
-{
- export TPATH="$PWD"
- export SPATH="$TPATH/ftrace_stress"
-
- if grep -q debugfs /proc/mounts; then
- export DEBUGFS_PATH=/sys/kernel/debug/
- export TRACING_PATH="$DEBUGFS_PATH/tracing"
- debugfs_def_mounted=1
- else
- tst_tmpdir
- export DEBUGFS_PATH="$PWD/debugfs"
- export TRACING_PATH="$PWD/debugfs/tracing"
- mkdir $DEBUGFS_PATH
- mount -t debugfs xxx $DEBUGFS_PATH
- fi
-
- TST_CLEANUP=clean_up
-
- trap clean_up_exit INT
-
- tst_require_root
-
- # Check to see tracing feature is supported or not
- if [ ! -d $TRACING_PATH ]; then
- tst_brkm TCONF "Tracing is not supported. Skip the test..."
- fi
-
- save_old_setting
-}
-
-test_interval=$1
-
-save_old_setting()
-{
- cd $TRACING_PATH
-
- old_trace_options=`cat trace_options`
- old_tracing_on=`cat tracing_on`
- old_buffer_size=`cat buffer_size_kb`
- old_tracing_cpumask=`cat tracing_cpumask`
-
- if [ -e tracing_cpumask ]; then
- old_tracing_cpumask=`cat tracing_cpumask`
- fi
-
- if [ -e tracing_enabled ]; then
- old_tracing_enabled=`cat tracing_enabled`
- fi
-
- if [ -e stack_max_size ]; then
- old_stack_tracer_enabled=`cat /proc/sys/kernel/stack_tracer_enabled`
- fi
-
- if [ -e "/proc/sys/kernel/ftrace_enabled" ]; then
- old_ftrace_enabled=`cat /proc/sys/kernel/ftrace_enabled`
- fi
-
- if [ -e "function_profile_enabled" ]; then
- old_profile_enabled=`cat function_profile_enabled`
- fi
-
- setting_saved=1
-
- cd - > /dev/null
-}
-
-restore_old_setting()
-{
- if [ ! "$setting_saved" = 1 ]; then
- return
- fi
-
- cd $TRACING_PATH
-
- echo nop > current_tracer
- echo 0 > events/enable
- if [ -e tracing_max_latency ]; then
- echo 0 > tracing_max_latency
- fi
-
- if [ -e tracing_cpumask ]; then
- echo $old_tracing_cpumask > tracing_cpumask
- fi
-
- if [ -e trace_clock ]; then
- echo local > trace_clock
- fi
-
- if [ -e "function_pofile_enabled" ]; then
- echo $old_profile_enabled > function_profile_enabled
- fi
-
- if [ -e "/proc/sys/kernel/ftrace_enabled" ]; then
- echo $old_ftrace_enabled > /proc/sys/kernel/ftrace_enabled
- fi
-
- if [ -e stack_max_size ]; then
- echo $old_stack_tracer_enabled > /proc/sys/kernel/stack_tracer_enabled
- echo 0 > stack_max_size
- fi
-
- echo $old_buffer_size > buffer_size_kb
- echo $old_tracing_on > tracing_on
-
- if [ -e tracing_enabled ]; then
- echo $old_tracing_enabled > tracing_enabled
- fi
-
- for option in $old_trace_options; do
- echo $option > trace_options 2> /dev/null
- done
-
- echo > trace
-
- if [ -f set_ftrace_filter ]; then
- echo > set_ftrace_filter
- fi
-
- cd - > /dev/null
-}
-
-clean_up_mount()
-{
- if [ ! "$debugfs_def_mounted" = "1" ]; then
- umount $DEBUGFS_PATH
- rmdir $DEBUGFS_PATH
- fi
-}
-
-clean_up()
-{
- restore_old_setting
- clean_up_mount
-}
-
-clean_up_exit()
-{
- restore_old_setting
- clean_up_mount
- exit 1
-}
-
-test_begin()
-{
- start_time=`date +%s`
-}
-
-test_wait()
-{
- # run the test for $test_interval secs
- tst_sleep ${test_interval}s
-}
-
-ftrace_test_init
diff --git a/testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_buffer_size_kb.sh b/testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_buffer_size_kb.sh
deleted file mode 100755
index 665291406..000000000
--- a/testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_buffer_size_kb.sh
+++ /dev/null
@@ -1,45 +0,0 @@
-#! /bin/sh
-
-###############################################################################
-# #
-# Copyright (c) 2010 FUJITSU LIMITED #
-# #
-# 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 2 of the License, or (at your option) #
-# any later version. #
-# #
-# Author: Li Zefan <lizf@cn.fujitsu.com> #
-# #
-###############################################################################
-
-LOOP=200
-
-# Use up to 10% of free memory
-free_mem=`cat /proc/meminfo | grep '^MemFree' | awk '{ print $2 }'`
-cpus=`tst_ncpus`
-
-step=$(( $free_mem / 10 / $LOOP / $cpus ))
-
-if [ $step -eq 0 ]; then
- step=1
- LOOP=50
-fi
-
-while true; do
- new_size=1
- i=0
- while [ $i -lt $LOOP ]; do
- echo $new_size > "$TRACING_PATH"/buffer_size_kb
- new_size=$(( $new_size + $step ))
- i=$((i + 1))
- done
-
- i=0
- while [ $i -lt $LOOP ]; do
- new_size=$(( $new_size - $step ))
- echo $new_size > "$TRACING_PATH"/buffer_size_kb
- i=$((i + 1))
- done
- sleep 1
-done
diff --git a/testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_current_tracer.sh b/testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_current_tracer.sh
deleted file mode 100755
index 104b57750..000000000
--- a/testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_current_tracer.sh
+++ /dev/null
@@ -1,32 +0,0 @@
-#! /bin/sh
-
-###############################################################################
-# #
-# Copyright (c) 2010 FUJITSU LIMITED #
-# #
-# 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 2 of the License, or (at your option) #
-# any later version. #
-# #
-# Author: Li Zefan <lizf@cn.fujitsu.com> #
-# #
-###############################################################################
-
-LOOP=200
-
-while true; do
- i=0
- while [ $i -lt $LOOP ]; do
- for tracer in `cat "$TRACING_PATH"/available_tracers`
- do
- if [ "$tracer" = mmiotrace ]; then
- continue
- fi
-
- echo $tracer > "$TRACING_PATH"/current_tracer 2> /dev/null
- done
- i=$((i + 1))
- done
- sleep 1
-done
diff --git a/testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_ftrace_enabled.sh b/testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_ftrace_enabled.sh
deleted file mode 100755
index c6f8b48df..000000000
--- a/testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_ftrace_enabled.sh
+++ /dev/null
@@ -1,38 +0,0 @@
-#! /bin/sh
-
-###############################################################################
-# #
-# Copyright (c) 2010 FUJITSU LIMITED #
-# #
-# 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 2 of the License, or (at your option) #
-# any later version. #
-# #
-# Author: Li Zefan <lizf@cn.fujitsu.com> #
-# #
-###############################################################################
-
-MAX_LOOP=1500
-count=0
-
-while true; do
- count=$(( $count + 1 ))
- i=0
- while [ $i -lt $MAX_LOOP ]; do
- echo 0 > /proc/sys/kernel/ftrace_enabled
- echo 1 > /proc/sys/kernel/ftrace_enabled
- i=$((i + 1))
- done
-
- enable=$(( $count % 3 ))
-
- if [ $enable -eq 0 ]; then
- echo 1 > /proc/sys/kernel/ftrace_enabled
- else
- echo 0 > /proc/sys/kernel/ftrace_enabled
- fi
-
- sleep 1
-done
-
diff --git a/testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_function_profile_enabled.sh b/testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_function_profile_enabled.sh
deleted file mode 100755
index 7687420c7..000000000
--- a/testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_function_profile_enabled.sh
+++ /dev/null
@@ -1,38 +0,0 @@
-#! /bin/sh
-
-###############################################################################
-# #
-# Copyright (c) 2010 FUJITSU LIMITED #
-# #
-# 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 2 of the License, or (at your option) #
-# any later version. #
-# #
-# Author: Li Zefan <lizf@cn.fujitsu.com> #
-# #
-###############################################################################
-
-MAX_LOOP=1500
-count=0
-
-
-while true; do
- count=$(( $count + 1 ))
- i=0
- while [ $i -lt $MAX_LOOP ]; do
- echo 0 > "$TRACING_PATH"/function_profile_enabled 2> /dev/null
- echo 1 > "$TRACING_PATH"/function_profile_enabled 2> /dev/null
- i=$((i + 1))
- done
-
- enable=$(( $count % 3 ))
-
- if [ $enable -eq 0 ]; then
- echo 1 > "$TRACING_PATH"/function_profile_enabled 2> /dev/null
- else
- echo 0 > "$TRACING_PATH"/function_profile_enabled 2> /dev/null
- fi
-
- sleep 1
-done
diff --git a/testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_set_event.sh b/testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_set_event.sh
deleted file mode 100755
index 9a79b4201..000000000
--- a/testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_set_event.sh
+++ /dev/null
@@ -1,46 +0,0 @@
-#! /bin/sh
-
-###############################################################################
-# #
-# Copyright (c) 2010 FUJITSU LIMITED #
-# #
-# 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 2 of the License, or (at your option) #
-# any later version. #
-# #
-# Author: Li Zefan <lizf@cn.fujitsu.com> #
-# #
-###############################################################################
-
-while true; do
- i=0
- while [ $i -lt 100 ]; do
- echo 1 > "$TRACING_PATH"/events/enable
- echo 0 > "$TRACING_PATH"/events/enable
- i=$((i + 1))
- done
-
- for dir in `ls $TRACING_PATH/events/`; do
- if [ ! -d $dir -o "$dir" = ftrace ]; then
- continue;
- fi
-
- i=0
- while [ $i -lt 20 ]; do
- echo 1 > "$TRACING_PATH"/events/$dir/enable
- echo 0 > "$TRACING_PATH"/events/$dir/enable
- i=$((i + 1))
- done
- done
-
- for event in `cat $TRACING_PATH/available_events`; do
- # ftrace event sys is special, skip it
- if echo "$event" | grep "ftrace:*"; then
- continue
- fi
- echo $event >> "$TRACING_PATH"/set_event
- done
-
- sleep 1
-done
diff --git a/testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_set_ftrace_filter.sh b/testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_set_ftrace_filter.sh
deleted file mode 100755
index af6ec9f05..000000000
--- a/testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_set_ftrace_filter.sh
+++ /dev/null
@@ -1,119 +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: Chunyu Hu <chuhu@redhat.com> ##
-## ##
-###########################################################################
-
-. test.sh
-
-triggers="traceon traceoff enable_event disable_event snapshot \
- dump cpudump stacktrace module function"
-nr_triggers=$(echo ${triggers} | wc -w)
-
-module_pick()
-{
- nr_module=$(lsmod | wc -l)
- pick_one=$(tst_random 1 $nr_module)
- picked_module=$(lsmod | awk "{if (NR == $pick_one) {print \$1}}")
-}
-
-filter_file=$TRACING_PATH/available_filter_functions
-nr_functions=$(awk 'END{print NR}' $filter_file)
-
-function_pick()
-{
- if [ -f $filter_file ]; then
- local pick_one=$(tst_random 1 $nr_functions)
- picked_function=$(awk "{if (NR == $pick_one) {print \$1}}" $filter_file)
- echo $picked_function
- else
- echo "\*sched\*"
- fi
-}
-
-event_pick()
-{
- local events_file=$TRACING_PATH/available_events
- if [ -f $events_file ]; then
- nr_events=$(awk 'END{print NR}' $events_file)
- local pick_one=$(tst_random 1 $nr_events)
- picked_event=$(awk "{if (NR == $pick_one) {print \$0}}" $events_file)
- echo "$picked_event"
- else
- echo "sched:sched_switch"
- fi
-}
-
-filter_formatter()
-{
- function_str=$(function_pick)
- count=$(tst_random 0 2)
-
- case $1 in
- traceon|traceoff|snapshot|dump|cpudump|stacktrace)
- trigger=$1
- ;;
- enable_event|disable_event)
- event_sys_name=$(event_pick)
- trigger=$1:$event_sys_name
- ;;
- module)
- module_pick
- echo ":mod:$picked_module"
- return
- ;;
- function)
- echo "$function_str"
- return
- ;;
- *)
- trigger=$1
- ;;
- esac
-
- if [ $count -gt 0 ]; then
- trigger=$trigger:$count
- fi
- echo $function_str:$trigger
-}
-
-signal_handler()
-{
- tst_exit
-}
-
-trap signal_handler SIGTERM
-
-while true; do
- # Here try to check if a race caused issue can be hit.
- cat $TRACING_PATH/set_ftrace_filter > /dev/null
-
- trigger_index=$(tst_random 1 $nr_triggers)
- trigger_name=$(echo $triggers | awk "{print \$$trigger_index}")
- filter_format=$(filter_formatter $trigger_name)
-
- echo "$filter_format" > $TRACING_PATH/set_ftrace_filter
- [ $? -ne 0 ] && tst_resm TFAIL "$0: setup filter <$filter_format> failed"
-
- sleep 2
-
- echo "!$filter_format" > $TRACING_PATH/set_ftrace_filter
- [ $? -ne 0 ] && tst_resm TFAIL "$0: remove filter <$filter_format> failed"
-done
-
diff --git a/testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_set_ftrace_pid.sh b/testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_set_ftrace_pid.sh
deleted file mode 100755
index fd42de4f3..000000000
--- a/testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_set_ftrace_pid.sh
+++ /dev/null
@@ -1,37 +0,0 @@
-#! /bin/sh
-
-###############################################################################
-# #
-# Copyright (c) 2010 FUJITSU LIMITED #
-# #
-# 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 2 of the License, or (at your option) #
-# any later version. #
-# #
-# Author: Li Zefan <lizf@cn.fujitsu.com> #
-# #
-###############################################################################
-
-LOOP=300
-
-while true; do
- j=0
- while [ $j -lt $LOOP ]; do
- k=1
- while [ $k -le $NR_PIDS ]; do
- str="\$pid$k"
- eval echo $str >> "$TRACING_PATH"/set_ftrace_pid
- k=$((k + 1))
- done
-
- if ! echo > "$TRACING_PATH"/set_ftrace_pid >/dev/null 2>&1; then
- if ! echo -1 > "$TRACING_PATH"/set_ftrace_pid >/dev/null 2>&1; then
- tst_resm TBROK "Cannot disable set_ftrace_pid!"
- exit 1
- fi
- fi
- j=$((j + 1))
- done
- sleep 1
-done
diff --git a/testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_stack_max_size.sh b/testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_stack_max_size.sh
deleted file mode 100755
index 0842929aa..000000000
--- a/testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_stack_max_size.sh
+++ /dev/null
@@ -1,27 +0,0 @@
-#! /bin/sh
-
-###############################################################################
-# #
-# Copyright (c) 2010 FUJITSU LIMITED #
-# #
-# 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 2 of the License, or (at your option) #
-# any later version. #
-# #
-# Author: Li Zefan <lizf@cn.fujitsu.com> #
-# #
-###############################################################################
-
-MAX_STACK_SIZE=8192
-
-while true; do
- i=0
- while [ $i -lt $MAX_STACK_SIZE ]; do
- echo $i > "$TRACING_PATH"/stack_max_size
- cat "$TRACING_PATH"/stack_max_size > /dev/null
- i=$((i + 1))
- done
- sleep 1
-done
-
diff --git a/testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_stack_trace.sh b/testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_stack_trace.sh
deleted file mode 100755
index 4c16a0a1d..000000000
--- a/testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_stack_trace.sh
+++ /dev/null
@@ -1,35 +0,0 @@
-#! /bin/sh
-
-###############################################################################
-# #
-# Copyright (c) 2010 FUJITSU LIMITED #
-# #
-# 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 2 of the License, or (at your option) #
-# any later version. #
-# #
-# Author: Li Zefan <lizf@cn.fujitsu.com> #
-# #
-###############################################################################
-
-LOOP=400
-
-while true; do
- i=0
- while [ $i -lt $LOOP ]; do
- cat "$TRACING_PATH"/stack_trace > /dev/null
- i=$((i + 1))
- done
-
- sleep 1
-
- i=0
- while [ $i -lt $LOOP ]; do
- echo 0 > /proc/sys/kernel/stack_tracer_enabled
- echo 1 > /proc/sys/kernel/stack_tracer_enabled
- i=$((i + 1))
- done
-
- sleep 1
-done
diff --git a/testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_trace.sh b/testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_trace.sh
deleted file mode 100755
index 7c45f504a..000000000
--- a/testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_trace.sh
+++ /dev/null
@@ -1,25 +0,0 @@
-#! /bin/sh
-
-###############################################################################
-# #
-# Copyright (c) 2010 FUJITSU LIMITED #
-# #
-# 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 2 of the License, or (at your option) #
-# any later version. #
-# #
-# Author: Li Zefan <lizf@cn.fujitsu.com> #
-# #
-###############################################################################
-
-LOOP=200
-
-i=0;
-while true; do
- while [ $i -lt $LOOP ]; do
- cat "$TRACING_PATH"/trace > /dev/null
- i=$((i + 1))
- done
- sleep 1
-done
diff --git a/testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_trace_clock.sh b/testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_trace_clock.sh
deleted file mode 100755
index 50329c684..000000000
--- a/testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_trace_clock.sh
+++ /dev/null
@@ -1,27 +0,0 @@
-#! /bin/sh
-
-###############################################################################
-# #
-# Copyright (c) 2010 FUJITSU LIMITED #
-# #
-# 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 2 of the License, or (at your option) #
-# any later version. #
-# #
-# Author: Li Zefan <lizf@cn.fujitsu.com> #
-# #
-###############################################################################
-
-LOOP=400
-
-while true; do
- i=0
- while [ $i -lt $LOOP ]; do
- echo local > "$TRACING_PATH"/trace_clock
- echo global > "$TRACING_PATH"/trace_clock
- i=$((i + 1))
- done
- sleep 1
-done
-
diff --git a/testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_trace_options.sh b/testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_trace_options.sh
deleted file mode 100755
index 95da3f6c7..000000000
--- a/testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_trace_options.sh
+++ /dev/null
@@ -1,58 +0,0 @@
-#! /bin/sh
-
-###############################################################################
-# #
-# Copyright (c) 2010 FUJITSU LIMITED #
-# #
-# 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 2 of the License, or (at your option) #
-# any later version. #
-# #
-# Author: Li Zefan <lizf@cn.fujitsu.com> #
-# #
-###############################################################################
-
-. test.sh
-
-LOOP=200
-
-while true; do
- j=0
- while [ $j -lt $LOOP ]; do
- trace_options="$(ls $TRACING_PATH/options/)"
- # enable the nop_test_refuse can cause an
- # 'write error: Invalid argument'. So don't test it.
- trace_options="$(echo $trace_options | sed 's/test_nop_refuse//')"
- nr_trace_options=$(echo "${trace_options}" | wc -w)
-
- option_index=$(tst_random 1 $nr_trace_options)
- option=$(echo "$trace_options" | awk "{print \$$option_index}")
- i=0
- while [ $i -lt $nr_trace_options ]; do
- n=$(tst_random 0 1)
- opt_f="$TRACING_PATH"/options/$option
- ret_val=0
- if [ $n -eq 0 ]; then
- operation="setup"
- else
- operation="clear"
- fi
- # On old kernel, some trace option dirs
- # won't be made if the option has nothing
- # to do with the current tracer. But on newer
- # kernel(4.4-rc1), all option dirs will be made.
- # So here check it to avoid 'Permision denied'
- if [ -f $opt_f ]; then
- echo $n > $opt_f
- ret_val=$?
- fi
-
- if [ $ret_val -ne 0 ]; then
- tst_resm TFAIL "$0: $operation trace option $option failed"
- fi
- i=$((i + 1))
- done
- j=$((j + 1))
- done
-done
diff --git a/testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_trace_pipe.sh b/testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_trace_pipe.sh
deleted file mode 100755
index 7d49745ba..000000000
--- a/testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_trace_pipe.sh
+++ /dev/null
@@ -1,45 +0,0 @@
-#! /bin/sh
-
-###############################################################################
-# #
-# Copyright (c) 2010 FUJITSU LIMITED #
-# #
-# 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 2 of the License, or (at your option) #
-# any later version. #
-# #
-# Author: Li Zefan <lizf@cn.fujitsu.com> #
-# #
-###############################################################################
-
-kill_this_pid()
-{
- kill -KILL $this_pid
- wait $this_pid
- exit 0
-}
-
-trap kill_this_pid SIGUSR1
-
-LOOP=20
-
-while true; do
- i=0
- while [ $i -lt $LOOP ]; do
- cat "$TRACING_PATH"/trace_pipe > /dev/null &
- this_pid=$!
-
- tst_sleep 200000us
-
- kill -INT $this_pid
- wait $this_pid
-
- this_pid=0
-
- tst_sleep 200000us
-
- i=$((i + 1))
- done
- sleep 2
-done
diff --git a/testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_trace_stat.sh b/testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_trace_stat.sh
deleted file mode 100755
index f7177c988..000000000
--- a/testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_trace_stat.sh
+++ /dev/null
@@ -1,38 +0,0 @@
-#! /bin/sh
-
-###############################################################################
-# #
-# Copyright (c) 2010 FUJITSU LIMITED #
-# #
-# 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 2 of the License, or (at your option) #
-# any later version. #
-# #
-# Author: Li Zefan <lizf@cn.fujitsu.com> #
-# #
-###############################################################################
-
-LOOP=200
-
-should_skip=0
-nr_cpus=`tst_ncpus`
-
-if [ ! -e "$TRACING_PATH"/function_profile_enabled ]; then
- should_skip=1
-fi
-
-while true; do
- if [ $should_skip -eq 1 ]; then
- sleep 2
- continue
- fi
- cpu=$(tst_random 0 $((nr_cpus - 1)))
- i=0;
- while [ $i -lt $LOOP ]; do
- cat "$TRACING_PATH"/trace_stat/function${cpu} > /dev/null 2>&1
- i=$((i + 1))
- done
-
- sleep 1
-done
diff --git a/testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_tracing_cpumask.sh b/testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_tracing_cpumask.sh
deleted file mode 100755
index aeb0d92f8..000000000
--- a/testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_tracing_cpumask.sh
+++ /dev/null
@@ -1,91 +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: Chunyu Hu <chuhu@redhat.com> ##
-## ##
-###########################################################################
-
-. test.sh
-nr_cpus=`tst_ncpus`
-
-# the 32 bit integer count 32 cpus. One integer is not
-# enough to store the cpu mask for nr_cpu > 32.
-if [ $nr_cpus -gt 32 ]; then
- group_cnt=$((nr_cpus / 32))
- range=31
- rem=$((nr_cpus % 32))
- if [ $rem -ne 0 ]; then
- range_last=$((rem -1))
- fi
-else
- group_cnt=1
- range=$((nr_cpus - 1))
-fi
-
-get_test_cpumask()
-{
- mask=""
-
- local i=0
- while [ $i -lt $group_cnt ]; do
- # select count of cpu in one group, include the duplicate.
- local set_cnt=$(tst_random 1 $((range + 1)))
-
- local c=0
- local temp_mask=0
- while [ $c -lt $set_cnt ]; do
- local group_cpuid=$(tst_random 1 $range)
- temp_mask=$((temp_mask | $((1 << $group_cpuid))))
- c=$((c + 1))
- done
-
- if [ $i = 0 ]; then
- mask=`echo $temp_mask | awk '{printf "%x",$0}'`
- else
- mask=$mask","`echo $temp_mask | awk '{printf "%x",$0}'`
- fi
-
- i=$((i + 1))
- done
-
- if [ $group_cnt -gt 1 ]; then
- set_cnt=$(tst_random 1 $((range_last +1)))
- c=0;
- temp_mask=0
- while [ $c -lt $set_cnt ]; do
- local group_cpuid=$(tst_random 1 $range_last)
- temp_mask=$((temp_mask | $((1 << $group_cpuid))))
- c=$((c + 1))
- done
- mask=`echo $temp_mask | awk '{printf "%x",$0}'`
- fi
-
- echo "$mask"
-}
-
-signal_handler()
-{
- tst_exit
-}
-
-trap signal_handler SIGTERM SIGKILL
-
-while true; do
- get_test_cpumask > $TRACING_PATH/tracing_cpumask
-done
diff --git a/testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_tracing_enabled.sh b/testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_tracing_enabled.sh
deleted file mode 100755
index 9e0f5a7cf..000000000
--- a/testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_tracing_enabled.sh
+++ /dev/null
@@ -1,38 +0,0 @@
-#! /bin/sh
-
-###############################################################################
-# #
-# Copyright (c) 2010 FUJITSU LIMITED #
-# #
-# 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 2 of the License, or (at your option) #
-# any later version. #
-# #
-# Author: Li Zefan <lizf@cn.fujitsu.com> #
-# #
-###############################################################################
-
-MAX_LOOP=1500
-count=0
-
-while true; do
- count=$(( $count + 1 ))
- i=0
- while [ $i -lt $MAX_LOOP ]; do
- echo 0 > "$TRACING_PATH"/tracing_enabled
- echo 1 > "$TRACING_PATH"/tracing_enabled
- i=$((i + 1))
- done
-
- enable=$(( $count % 3 ))
-
- if [ $enable -eq 0 ]; then
- echo 0 > "$TRACING_PATH"/tracing_enabled
- else
- echo 1 > "$TRACING_PATH"/tracing_enabled
- fi
-
- sleep 1
-done
-
diff --git a/testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_tracing_max_latency.sh b/testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_tracing_max_latency.sh
deleted file mode 100755
index 4ad88910c..000000000
--- a/testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_tracing_max_latency.sh
+++ /dev/null
@@ -1,27 +0,0 @@
-#! /bin/sh
-
-###############################################################################
-# #
-# Copyright (c) 2010 FUJITSU LIMITED #
-# #
-# 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 2 of the License, or (at your option) #
-# any later version. #
-# #
-# Author: Li Zefan <lizf@cn.fujitsu.com> #
-# #
-###############################################################################
-
-MAX_LATENCY=100000
-
-while true; do
- i=0
- while [ $i -lt $MAX_LATENCY ]; do
- echo $i > "$TRACING_PATH"/tracing_max_latency
- i=$((i + 400))
- done
-
- sleep 1
-
-done
diff --git a/testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_tracing_on.sh b/testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_tracing_on.sh
deleted file mode 100755
index 5ae9d762c..000000000
--- a/testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_tracing_on.sh
+++ /dev/null
@@ -1,38 +0,0 @@
-#! /bin/sh
-
-###############################################################################
-# #
-# Copyright (c) 2010 FUJITSU LIMITED #
-# #
-# 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 2 of the License, or (at your option) #
-# any later version. #
-# #
-# Author: Li Zefan <lizf@cn.fujitsu.com> #
-# #
-###############################################################################
-
-MAX_LOOP=1500
-count=0
-
-while true; do
- count=$(( $count + 1 ))
- i=0
- while [ $i -lt $MAX_LOOP ]; do
- echo 0 > "$TRACING_PATH"/tracing_on
- echo 1 > "$TRACING_PATH"/tracing_on
- i=$((i + 1))
- done
-
- enable=$(( $count % 3 ))
-
- if [ $enable -eq 0 ]; then
- echo 0 > "$TRACING_PATH"/tracing_on
- else
- echo 1 > "$TRACING_PATH"/tracing_on
- fi
-
- sleep 1
-done
-
--
2.50.1
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [LTP] ftrace: Add common library for C implementation
2026-06-09 4:16 ` [LTP] [PATCH v6 1/5] ftrace: Add common library for C implementation Praveen K Pandey
@ 2026-06-09 5:14 ` linuxtestproject.agent
2026-06-10 9:31 ` [LTP] [PATCH v6 1/5] " Cyril Hrubis
1 sibling, 0 replies; 8+ messages in thread
From: linuxtestproject.agent @ 2026-06-09 5:14 UTC (permalink / raw)
To: Praveen K Pandey; +Cc: ltp
Hi Praveen,
On Tue, Jun 9, 2026, Praveen K Pandey wrote:
> ftrace: Add common library for C implementation
--- [PATCH 1/5] ---
> -INSTALL_TARGETS := *.sh ftrace_stress/*
> +# Filter out ftrace_lib from standalone build targets
> +FILTER_OUT_MAKE_TARGETS := ftrace_lib
Removing INSTALL_TARGETS here means the ftrace_stress/* helper
scripts are no longer installed, but ftrace_stress_test.sh still
exists and depends on them (it is not converted until patch 4/5).
This breaks the shell-based stress test at this intermediate
commit.
Moving this removal to patch 5/5 (where the helper scripts are
actually deleted) would preserve bisectability.
--- [PATCH 2/5] ---
> -ftrace_regression01 ftrace_regression01.sh
> -ftrace_regression02 ftrace_regression02.sh
> -ftrace-stress-test ftrace_stress_test.sh 90
> +ftrace_regression01 ftrace_regression01
> +ftrace_regression02 ftrace_regression02
> +ftrace-stress-test ftrace_stress_test
This patch converts only ftrace_regression01, but all three
runtest/tracing entries are updated to reference C binaries.
At this point ftrace_regression02 and ftrace_stress_test binaries
do not exist -- their .c files are added in patches 3/5 and 4/5
respectively.
After this commit, running ftrace_regression02 or ftrace-stress-test
from the runtest file will look for binaries that cannot be built.
Each conversion patch should only update its own runtest entry.
--- [PATCH 4/5] ---
> +static struct stress_test stress_tests[] = {
> + {"current_tracer", "current_tracer", stress_current_tracer, 0},
> + {"trace_pipe", "trace_pipe", stress_trace_pipe, 0},
> + {"set_event", "events/enable", stress_set_event, 0},
> + {"buffer_size_kb", "buffer_size_kb", stress_buffer_size, 0},
> + {"tracing_on", "tracing_on", stress_tracing_on, 0},
> + {"trace_options", "trace_options", stress_trace_options, 0},
> + {"set_ftrace_filter", "set_ftrace_filter", stress_set_ftrace_filter, 0},
The original shell test exercised 17 ftrace interfaces concurrently:
trace_pipe, current_tracer, ftrace_enabled,
function_profile_enabled, set_event, set_ftrace_pid,
stack_max_size, stack_trace, trace, trace_clock, trace_options,
trace_stat, tracing_enabled, tracing_max_latency, tracing_on,
buffer_size_kb, tracing_cpumask, and set_ftrace_filter.
The C version implements 7 of these, dropping 10 stress targets.
Is the reduced coverage intentional? If so, it would be good to
note it in the commit message.
> * Converted to C by: Praveen K Pandey <praveen@linux.ibm.com>
> */
>
> +/*\
> * ...
> * The test creates multiple threads that stress test different
> * ftrace interfaces concurrently for a specified duration.
> *
> * Signed-off-by: Praveen K Pandey <praveen@linux.ibm.com>
The commit message states "Test timeout set to 300 seconds", but
the code has `.timeout = DEFAULT_TEST_DURATION + 30` which
evaluates to 90, not 300.
Verdict: Needs revision
---
Note:
The agent can sometimes produce false positives although often its
findings are genuine. If you find issues with the review, please
comment this email or ignore the suggestions.
Regards,
LTP AI Reviewer
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: [LTP] [PATCH v6 1/5] ftrace: Add common library for C implementation
2026-06-09 4:16 ` [LTP] [PATCH v6 1/5] ftrace: Add common library for C implementation Praveen K Pandey
2026-06-09 5:14 ` [LTP] " linuxtestproject.agent
@ 2026-06-10 9:31 ` Cyril Hrubis
1 sibling, 0 replies; 8+ messages in thread
From: Cyril Hrubis @ 2026-06-10 9:31 UTC (permalink / raw)
To: Praveen K Pandey; +Cc: ltp
Hi!
> +char *ftrace_get_path(const char *filename)
> +{
> + char *path;
> +
> + SAFE_ASPRINTF(&path, "%s/%s", tracing_path, filename);
> + return path;
> +}
> +
> +char *ftrace_read_file(const char *filename)
> +{
> + char *path;
> + FILE *fp;
> + char *content = NULL;
> + size_t len = 0;
> + ssize_t read;
> + char *line = NULL;
> + size_t total_size = 0;
> +
> + path = ftrace_get_path(filename);
> + if (!path)
> + return NULL;
> +
> + fp = fopen(path, "r");
> + free(path);
> +
> + if (!fp)
> + return NULL;
> +
> + while ((read = getline(&line, &len, fp)) != -1) {
> + char *new_content = realloc(content, total_size + read + 1);
> +
> + if (!new_content) {
> + free(content);
> + free(line);
> + fclose(fp);
> + return NULL;
> + }
> + content = new_content;
> + memcpy(content + total_size, line, read);
> + total_size += read;
> + }
> +
> + if (content)
> + content[total_size] = '\0';
> +
> + free(line);
> + fclose(fp);
> +
> + return content;
> +}
> +
> +int ftrace_write_file(const char *filename, const char *content)
> +{
> + char *path;
> + FILE *fp;
> + int ret;
> +
> + path = ftrace_get_path(filename);
> + if (!path)
> + return -1;
> +
> + fp = fopen(path, "w");
> + free(path);
> +
> + if (!fp)
> + return -1;
> +
> + ret = fprintf(fp, "%s", content);
> + fclose(fp);
> +
> + return (ret > 0) ? 0 : -1;
> +}
> +
> +int ftrace_file_exists(const char *filename)
> +{
> + char *path;
> + int ret;
> +
> + path = ftrace_get_path(filename);
> + if (!path)
> + return 0;
> +
> + ret = (access(path, F_OK) == 0);
> + free(path);
> +
> + return ret;
> +}
> +
> +void ftrace_save_settings(void)
> +{
> + if (saved_state.saved)
> + return;
> +
> + saved_state.trace_options = ftrace_read_file("trace_options");
> + saved_state.tracing_on = ftrace_read_file("tracing_on");
> + saved_state.buffer_size = ftrace_read_file("buffer_size_kb");
> +
> + if (ftrace_file_exists("tracing_cpumask"))
> + saved_state.tracing_cpumask = ftrace_read_file("tracing_cpumask");
> +
> + if (ftrace_file_exists("tracing_enabled"))
> + saved_state.tracing_enabled = ftrace_read_file("tracing_enabled");
> +
> + if (ftrace_file_exists("stack_max_size")) {
> + FILE *fp = fopen("/proc/sys/kernel/stack_tracer_enabled", "r");
> +
> + if (fp) {
> + saved_state.stack_tracer_enabled = malloc(32);
> + if (saved_state.stack_tracer_enabled)
> + fgets(saved_state.stack_tracer_enabled, 32, fp);
> + fclose(fp);
> + }
> + }
> +
> + if (access("/proc/sys/kernel/ftrace_enabled", F_OK) == 0) {
> + FILE *fp = fopen("/proc/sys/kernel/ftrace_enabled", "r");
> +
> + if (fp) {
> + saved_state.ftrace_enabled = malloc(32);
> + if (saved_state.ftrace_enabled)
> + fgets(saved_state.ftrace_enabled, 32, fp);
> + fclose(fp);
> + }
> + }
> +
> + if (ftrace_file_exists("function_profile_enabled"))
> + saved_state.function_profile_enabled = ftrace_read_file("function_profile_enabled");
> +
> + saved_state.saved = 1;
> +}
> +
> +void ftrace_restore_settings(void)
> +{
> + if (!saved_state.saved)
> + return;
> +
> + ftrace_write_file("current_tracer", "nop\n");
> + ftrace_write_file("events/enable", "0\n");
> +
> + if (ftrace_file_exists("tracing_max_latency"))
> + ftrace_write_file("tracing_max_latency", "0\n");
> +
> + if (saved_state.tracing_cpumask)
> + ftrace_write_file("tracing_cpumask", saved_state.tracing_cpumask);
> +
> + if (ftrace_file_exists("trace_clock"))
> + ftrace_write_file("trace_clock", "local\n");
> +
> + if (saved_state.function_profile_enabled)
> + ftrace_write_file("function_profile_enabled", saved_state.function_profile_enabled);
> +
> + if (saved_state.ftrace_enabled) {
> + FILE *fp = fopen("/proc/sys/kernel/ftrace_enabled", "w");
> +
> + if (fp) {
> + fprintf(fp, "%s", saved_state.ftrace_enabled);
> + fclose(fp);
> + }
> + }
> +
> + if (saved_state.stack_tracer_enabled && ftrace_file_exists("stack_max_size")) {
> + FILE *fp = fopen("/proc/sys/kernel/stack_tracer_enabled", "w");
> +
> + if (fp) {
> + fprintf(fp, "%s", saved_state.stack_tracer_enabled);
> + fclose(fp);
> + }
> + ftrace_write_file("stack_max_size", "0\n");
> + }
> +
> + if (saved_state.buffer_size)
> + ftrace_write_file("buffer_size_kb", saved_state.buffer_size);
> +
> + if (saved_state.tracing_on)
> + ftrace_write_file("tracing_on", saved_state.tracing_on);
> +
> + if (saved_state.tracing_enabled)
> + ftrace_write_file("tracing_enabled", saved_state.tracing_enabled);
> +
> + if (saved_state.trace_options) {
> + char *options = strdup(saved_state.trace_options);
> +
> + if (options) {
> + char *token = strtok(options, "\n");
> +
> + while (token) {
> + ftrace_write_file("trace_options", token);
> + token = strtok(NULL, "\n");
> + }
> + free(options);
> + }
> + }
> +
> + ftrace_clear_trace();
> +
> + if (ftrace_file_exists("set_ftrace_filter"))
> + ftrace_write_file("set_ftrace_filter", "\n");
> +}
> +
> +char **ftrace_get_available_tracers(int *count)
> +{
> + char *path;
> + FILE *fp;
> + char **tracers = NULL;
> + char *line = NULL;
> + size_t len = 0;
> + int n = 0;
> + int capacity = 16;
> +
> + path = ftrace_get_path("available_tracers");
> + if (!path) {
> + *count = 0;
> + return NULL;
> + }
> +
> + fp = fopen(path, "r");
> + free(path);
> +
> + if (!fp) {
> + *count = 0;
> + return NULL;
> + }
> +
> + tracers = malloc(sizeof(char *) * capacity);
> + if (!tracers) {
> + fclose(fp);
> + *count = 0;
> + return NULL;
> + }
> +
> + if (getline(&line, &len, fp) != -1) {
> + char *token;
> + char *saveptr;
> +
> + token = strtok_r(line, " \n", &saveptr);
> + while (token) {
> + if (n >= capacity) {
> + capacity *= 2;
> + char **new_tracers = realloc(tracers, sizeof(char *) * capacity);
> +
> + if (!new_tracers) {
> + while (n > 0)
> + free(tracers[--n]);
> + free(tracers);
> + free(line);
> + fclose(fp);
> + *count = 0;
> + return NULL;
> + }
> + tracers = new_tracers;
> + }
> +
> + tracers[n] = strdup(token);
> + if (!tracers[n]) {
> + while (n > 0)
> + free(tracers[--n]);
> + free(tracers);
> + free(line);
> + fclose(fp);
> + *count = 0;
> + return NULL;
> + }
> + n++;
> + token = strtok_r(NULL, " \n", &saveptr);
> + }
The loop here does not make any sense, we are reading the file line by
line now, the strtok_r() will not split the line into tokens, there is
going to be only a single line in the buffer.
> + }
> +
> + free(line);
> + fclose(fp);
> +
> + *count = n;
> + return tracers;
> +}
> +
> +int ftrace_set_tracer(const char *tracer)
> +{
> + char *path;
> +
> + path = ftrace_get_path("current_tracer");
> + if (!path)
> + return -1;
> +
> + SAFE_FILE_PRINTF(path, "%s", tracer);
> + free(path);
> +
> + return 0;
It's way too ugly to construct the path each time we need to write to
the tracing file.
I guess that the ideal solution is to use the SAFE_FILE_PRINTFAT() that
way we will only need to open the tracing directory with O_DIRECTORY in
the ftrace_initialize() and then we can print to all these files
relative to the dirfd without construction any paths, which can replace
all the ftrace_write_file() with SAFE_FILE_PRINTFAT().
For reading small files we can use SAFE_FILE_READAT().
> diff --git a/testcases/kernel/tracing/ftrace_test/ftrace_lib.h b/testcases/kernel/tracing/ftrace_test/ftrace_lib.h
> new file mode 100644
> index 000000000..79fdfee28
> --- /dev/null
> +++ b/testcases/kernel/tracing/ftrace_test/ftrace_lib.h
> @@ -0,0 +1,136 @@
> +/* SPDX-License-Identifier: GPL-2.0-or-later */
> +/*
> + * Copyright (c) 2010 FUJITSU LIMITED
> + * Copyright (c) 2024 Linux Test Project
> + * Copyright (c) IBM, 2026
> + *
> + * Author: Li Zefan <lizf@cn.fujitsu.com>
> + * Converted to C by: Praveen K Pandey <praveen@linux.ibm.com>
> + */
> +
> +#ifndef FTRACE_LIB_H
> +#define FTRACE_LIB_H
> +
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <string.h>
> +#include <unistd.h>
> +#include <fcntl.h>
> +#include <sys/mount.h>
> +#include <sys/stat.h>
> +#include <sys/types.h>
> +#include <errno.h>
> +#include <limits.h>
> +
> +extern char *tracing_path;
> +extern char *debugfs_path;
> +
> +struct ftrace_saved_state {
> + char *trace_options;
> + char *tracing_on;
> + char *buffer_size;
> + char *tracing_cpumask;
> + char *tracing_enabled;
> + char *stack_tracer_enabled;
> + char *ftrace_enabled;
> + char *function_profile_enabled;
> + int saved;
> +};
> +
> +extern struct ftrace_saved_state saved_state;
> +
> +/**
> + * ftrace_initialize - Initialize ftrace test environment
> + *
> + * Checks if debugfs is mounted, mounts it if needed, verifies tracing
> + * support, and saves current ftrace settings.
> + */
> +void ftrace_initialize(void);
> +
> +/**
> + * ftrace_cleanup - Cleanup and restore ftrace settings
> + *
> + * Restores all saved ftrace settings and unmounts debugfs if needed.
> + */
> +void ftrace_cleanup(void);
> +
> +/**
> + * ftrace_save_settings - Save current ftrace settings
> + *
> + * Saves all ftrace configuration to restore later.
> + */
> +void ftrace_save_settings(void);
> +
> +/**
> + * ftrace_restore_settings - Restore saved ftrace settings
> + *
> + * Restores ftrace configuration saved by ftrace_save_settings().
> + */
> +void ftrace_restore_settings(void);
> +
> +/**
> + * ftrace_get_path - Get full path to a tracing file
> + * @filename: Name of the file in tracing directory
> + *
> + * Return: Allocated string with full path (caller must free)
> + */
> +char *ftrace_get_path(const char *filename);
> +
> +/**
> + * ftrace_read_file - Read content from a tracing file
> + * @filename: Name of the file in tracing directory
> + *
> + * Return: Allocated string with file content (caller must free)
> + */
> +char *ftrace_read_file(const char *filename);
> +
> +/**
> + * ftrace_write_file - Write content to a tracing file
> + * @filename: Name of the file in tracing directory
> + * @content: Content to write
> + *
> + * Return: 0 on success, -1 on failure
> + */
> +int ftrace_write_file(const char *filename, const char *content);
> +
> +/**
> + * ftrace_file_exists - Check if a tracing file exists
> + * @filename: Name of the file in tracing directory
> + *
> + * Return: 1 if exists, 0 otherwise
> + */
> +int ftrace_file_exists(const char *filename);
> +
> +/**
> + * ftrace_get_available_tracers - Get list of available tracers
> + * @count: Pointer to store number of tracers
> + *
> + * Return: Array of tracer names (caller must free)
> + */
> +char **ftrace_get_available_tracers(int *count);
> +
> +/**
> + * ftrace_set_tracer - Set current tracer
> + * @tracer: Name of the tracer to set
> + *
> + * Return: 0 on success, -1 on failure
> + */
> +int ftrace_set_tracer(const char *tracer);
> +
> +/**
> + * ftrace_clear_trace - Clear the trace buffer
> + */
> +void ftrace_clear_trace(void);
> +
> +/**
> + * ftrace_enable_tracing - Enable tracing
> + */
> +void ftrace_enable_tracing(void);
> +
> +/**
> + * ftrace_disable_tracing - Disable tracing
> + */
> +void ftrace_disable_tracing(void);
> +
> +#endif /* FTRACE_LIB_H */
> +
> --
> 2.50.1
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2026-06-10 9:31 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-09 4:16 [LTP] [PATCH v6 0/5] ftrace: Convert shell tests to C Praveen K Pandey
2026-06-09 4:16 ` [LTP] [PATCH v6 1/5] ftrace: Add common library for C implementation Praveen K Pandey
2026-06-09 5:14 ` [LTP] " linuxtestproject.agent
2026-06-10 9:31 ` [LTP] [PATCH v6 1/5] " Cyril Hrubis
2026-06-09 4:16 ` [LTP] [PATCH v6 2/5] ftrace: Convert ftrace_regression01.sh to C Praveen K Pandey
2026-06-09 4:16 ` [LTP] [PATCH v6 3/5] ftrace: Convert ftrace_regression02.sh " Praveen K Pandey
2026-06-09 4:16 ` [LTP] [PATCH v6 4/5] ftrace: Convert ftrace_stress_test.sh " Praveen K Pandey
2026-06-09 4:16 ` [LTP] [PATCH v6 5/5] ftrace: Remove obsolete shell test files Praveen K Pandey
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.