ftrace: Convert shell tests to C
v6 cover ftrace: Convert shell tests to C
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
Signature · 5 lines
2.50.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v6 1/5 ftrace: Add common library for C implementation
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).
--- .../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
testcases/kernel/tracing/ftrace_test/.gitignore new file +4 -0
@@ -0,0 +1,4 @@ +ftrace_regression01 +ftrace_regression02 +ftrace_stress_test +
testcases/kernel/tracing/ftrace_test/Makefile +17 -2
@@ -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 <[email protected]> + +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
testcases/kernel/tracing/ftrace_test/ftrace_lib.c new file +371 -0
371 lines not on this page · raw message
testcases/kernel/tracing/ftrace_test/ftrace_lib.h new file +136 -0
136 lines not on this page · raw message
Signature · 4 lines
2.50.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] ftrace: Add common library for C implementation
Hi Praveen,
Quoted 1 line · Praveen K Pandey
ftrace: Add common library for C implementation
--- [PATCH 1/5] ---
testcases/kernel/tracing/ftrace_test/Makefile line 12
Quoted 3 lines
testcases/kernel/tracing/ftrace_test/Makefile +2
-1-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] ---
Review
Quoted 6 lines
(quoted diff) +3
-3-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] ---
Review
Quoted 8 lines
(quoted diff) +8
-0+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.
Quoted 9 lines
* Converted to C by: Praveen K Pandey <[email protected]> */
+/*\
* ...
* The test creates multiple threads that stress test different
* ftrace interfaces concurrently for a specified duration.
*
* Signed-off-by: Praveen K Pandey <[email protected]>
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
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Re: [LTP] [PATCH v6 1/5] ftrace: Add common library for C implementation
In reply to Praveen K PandeyHi!
Quoted 255 lines
testcases/kernel/tracing/ftrace_test/ftrace_lib.c new file +255
-0+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 )
testcases/kernel/tracing/ftrace_test/ftrace_lib.c line 334
Quoted 10 lines
testcases/kernel/tracing/ftrace_test/ftrace_lib.c new file +10
-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.
Quoted 11 lines
testcases/kernel/tracing/ftrace_test/ftrace_lib.c new file +11
-0+ } + +free (line); +fclose (fp); + + *count = n; +return tracers; +} + +int ftrace_set_tracer (const char *tracer) +{
testcases/kernel/tracing/ftrace_test/ftrace_lib.c line 355
Quoted 10 lines
testcases/kernel/tracing/ftrace_test/ftrace_lib.c new file +10
-0+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().
Quoted 144 lines
testcases/kernel/tracing/ftrace_test/ftrace_lib.h new file +136
-0@@ -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 <[email protected]> +* Converted to C by: Praveen K Pandey <[email protected]> +*/ + +#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 */ +Signature · 1 line
2.50.1
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v6 2/5 ftrace: Convert ftrace_regression01.sh to C
In reply to Praveen K PandeyConvert 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
--- 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
runtest/tracing +3 -3
@@ -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
testcases/kernel/tracing/ftrace_test/ftrace_regression01.c new file +126 -0
126 lines not on this page · raw message
testcases/kernel/tracing/ftrace_test/ftrace_regression01.sh deleted +0 -83
83 lines not on this page · raw message
Signature · 4 lines
2.50.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v6 3/5 ftrace: Convert ftrace_regression02.sh to C
In reply to Praveen K PandeyConvert 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.
--- .../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
testcases/kernel/tracing/ftrace_test/ftrace_regression02.c new file +101 -0
@@ -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 <[email protected]> +* Converted to C by: Praveen K Pandey <[email protected]> +*/ + +/*\ +* 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" }, + {} + } +}; +
testcases/kernel/tracing/ftrace_test/ftrace_regression02.sh deleted +0 -63
63 lines not on this page · raw message
Signature · 4 lines
2.50.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v6 4/5 ftrace: Convert ftrace_stress_test.sh to C
In reply to Praveen K PandeyConvert 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.
--- .../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
testcases/kernel/tracing/ftrace_test/ftrace_stress_test.c new file +328 -0
@@ -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 <[email protected]> +* Converted to C by: Praveen K Pandey <[email protected]> +*/ + +/*\ +* 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 , +}; +
testcases/kernel/tracing/ftrace_test/ftrace_stress_test.sh deleted +0 -121
121 lines not on this page · raw message
Signature · 4 lines
2.50.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v6 5/5 ftrace: Remove obsolete shell test files
In reply to Praveen K PandeyRemove 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.
--- .../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
testcases/kernel/tracing/ftrace_test/ftrace_lib.sh deleted +0 -180
@@ -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 <[email protected]> ## -## ## -########################################################################### - -. 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
testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_buffer_size_kb.sh deleted +0 -45
45 lines not on this page · raw message
testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_current_tracer.sh deleted +0 -32
@@ -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 <[email protected]> # -# # -############################################################################### - -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
testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_ftrace_enabled.sh deleted +0 -38
@@ -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 <[email protected]> # -# # -############################################################################### - -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 -
testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_function_profile_enabled.sh deleted +0 -38
@@ -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 <[email protected]> # -# # -############################################################################### - -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
testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_set_event.sh deleted +0 -46
46 lines not on this page · raw message
testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_set_ftrace_filter.sh deleted +0 -119
119 lines not on this page · raw message
testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_set_ftrace_pid.sh deleted +0 -37
@@ -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 <[email protected]> # -# # -############################################################################### - -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
testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_stack_max_size.sh deleted +0 -27
@@ -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 <[email protected]> # -# # -############################################################################### - -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 -
testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_stack_trace.sh deleted +0 -35
@@ -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 <[email protected]> # -# # -############################################################################### - -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
testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_trace.sh deleted +0 -25
@@ -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 <[email protected]> # -# # -############################################################################### - -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
testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_trace_clock.sh deleted +0 -27
@@ -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 <[email protected]> # -# # -############################################################################### - -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 -
testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_trace_options.sh deleted +0 -58
58 lines not on this page · raw message
testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_trace_pipe.sh deleted +0 -45
45 lines not on this page · raw message
testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_trace_stat.sh deleted +0 -38
@@ -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 <[email protected]> # -# # -############################################################################### - -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
testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_tracing_cpumask.sh deleted +0 -91
91 lines not on this page · raw message
testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_tracing_enabled.sh deleted +0 -38
@@ -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 <[email protected]> # -# # -############################################################################### - -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 -
testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_tracing_max_latency.sh deleted +0 -27
@@ -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 <[email protected]> # -# # -############################################################################### - -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
testcases/kernel/tracing/ftrace_test/ftrace_stress/ftrace_tracing_on.sh deleted +0 -38
@@ -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 <[email protected]> # -# # -############################################################################### - -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 -
Signature · 4 lines
2.50.1 -- Mailing list info: https://lists.linux.it/listinfo/ltp