public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Petr Vorel <pvorel@suse.cz>
To: lufei <lufei@uniontech.com>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH v3] Rewrite ftrace_regression tests with new C API
Date: Tue, 31 Mar 2026 09:53:46 +0200	[thread overview]
Message-ID: <20260331075346.GB5254@pevik> (raw)
In-Reply-To: <20260331015538.53326-1-lufei@uniontech.com>

Hi lufei,

> Rewritten from old shell scripts.

> ftrace_regression01: regression test for panic bug while using
> userstacktrace, set userstacktrace in loop and check if success.

> ftrace_regression02: for checking signal:signal_generate gives
> 2 more fields: grp res.

Thanks for the rewrite. Few things should be changed.

> +++ b/testcases/kernel/tracing/ftrace_test/Makefile
> @@ -2,6 +2,7 @@ top_srcdir              ?= ../../../..

>  include $(top_srcdir)/include/mk/testcases.mk

> -INSTALL_TARGETS         := *.sh ftrace_stress/*
> +INSTALL_TARGETS         := *.sh ftrace_stress/* ftrace_regression01 \
> +				ftrace_regression02

It's nice to actually run make install to verify it works:

$ make install
../../../../include/mk/env_post.mk:65: warning: overriding recipe for target '/opt/ltp/testcases/bin/ftrace_regression01'
../../../../include/mk/env_post.mk:64: warning: ignoring old recipe for target '/opt/ltp/testcases/bin/ftrace_regression01'
../../../../include/mk/env_post.mk:65: warning: overriding recipe for target '/opt/ltp/testcases/bin/ftrace_regression02'
../../../../include/mk/env_post.mk:64: warning: ignoring old recipe for target '/opt/ltp/testcases/bin/ftrace_regression02'

=> ftrace_regression01 ftrace_regression02 should not be added (C sources are already included).


...
> +#endif /* FTRACE_REGRESSION_H */
> diff --git a/testcases/kernel/tracing/ftrace_test/ftrace_regression01.c b/testcases/kernel/tracing/ftrace_test/ftrace_regression01.c
> new file mode 100644
> index 000000000..b76d5bf7e
> --- /dev/null
> +++ b/testcases/kernel/tracing/ftrace_test/ftrace_regression01.c
> @@ -0,0 +1,88 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Copyright (c) 2015 Red Hat Inc.
> + * Copyright (c) 2026 lufei <lufei@uniontech.com>
> + */
> +
> +/*\
> + * Regression test for panic while using userstacktrace.
> + *
> + * BUG: unable to handle kernel paging request at 00000000417683c0
> + *      IP: [<ffffffff8105c834>] update_curr+0x124/0x1e0
> + *      Thread overran stack, or stack corrupted
> + *      Oops: 0000 [#1] SMP
> + *      last sysfs file: ../system/cpu/cpu15/cache/index2/shared_cpu_map
> + *
> + * The bug was fixed by:
> + *      1dbd195 (tracing: Fix preempt count leak)
Please use longer hash (12 chars).

> + */
> +
> +#include <unistd.h>
> +#include <stdio.h>
> +#include "ftrace_regression.h"
> +
> +#define DEBUGFS_DIR "debugfs"
> +#define STACK_TRACER_PATH "/proc/sys/kernel/stack_tracer_enabled"
> +#define TRACE_OPTIONS DEBUGFS_DIR "/tracing/trace_options"
> +#define EXC_PAGE_FAULT DEBUGFS_DIR "/tracing/events/exceptions/page_fault_kernel/enable"
> +#define MM_PAGE_FAULT DEBUGFS_DIR "/tracing/events/kmem/mm_kernel_pagefault/enable"
> +
> +#define LOOP 10
> +
> +static const char *page_fault_path;
> +static int page_fault_origin;
> +
> +static void setup(void)
> +{
> +	SAFE_MKDIR(DEBUGFS_DIR, 0755);
> +	SAFE_MOUNT(NULL, DEBUGFS_DIR, "debugfs", 0, NULL);
Maybe have helpers for mounting/unmounting debugfs in the header?
> +
> +	if (access(EXC_PAGE_FAULT, F_OK) == 0)
> +		page_fault_path = EXC_PAGE_FAULT;
> +	else if (access(MM_PAGE_FAULT, F_OK) == 0)
> +		page_fault_path = MM_PAGE_FAULT;
> +	else
> +		tst_brk(TCONF, "Page fault event not available");
> +
> +	SAFE_FILE_SCANF(page_fault_path, "%d", &page_fault_origin);
> +}
> +
> +static void run(void)
> +{
> +	int i;
> +
> +	for (i = 0; i < LOOP; i++) {
> +		SAFE_FILE_PRINTF(STACK_TRACER_PATH, "1");
> +		SAFE_FILE_PRINTF(TRACE_OPTIONS, "userstacktrace");
> +
> +		if (!file_contains(TRACE_OPTIONS, "^userstacktrace"))
> +			tst_brk(TBROK, "Failed to set userstacktrace");
> +
> +		SAFE_FILE_PRINTF(page_fault_path, "1");
> +	}
> +
> +	SAFE_FILE_PRINTF(page_fault_path, "%d", page_fault_origin);
> +
> +	tst_res(TPASS, "Finished running the test");
Rewrite is not blind converting shell into C, but opportunity to improve the test.
Can we, please, have a meaningful message what passed?

> +}
> +
> +static void cleanup(void)
> +{
> +	SAFE_UMOUNT(DEBUGFS_DIR);
> +}
> +
> +static struct tst_test test = {
> +	.needs_root = 1,
> +	.needs_tmpdir = 1,
> +	.setup = setup,
> +	.test_all = run,
> +	.cleanup = cleanup,
> +	.save_restore = (const struct tst_path_val[]) {
> +		{STACK_TRACER_PATH, NULL, TST_SR_TCONF},
> +		{}
> +	},
> +	.tags = (const struct tst_tag[]) {
> +		{"linux-git", "1dbd195"},
> +		{}
> +	},
> +};
> diff --git a/testcases/kernel/tracing/ftrace_test/ftrace_regression02.c b/testcases/kernel/tracing/ftrace_test/ftrace_regression02.c
> new file mode 100644
> index 000000000..498db29e5
> --- /dev/null
> +++ b/testcases/kernel/tracing/ftrace_test/ftrace_regression02.c
> @@ -0,0 +1,68 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Copyright (c) 2015 Red Hat Inc.
> + * Copyright (c) 2026 lufei <lufei@uniontech.com>
> + */
> +
> +/*\
> + * Check signal:signal_generate gives 2 more fields: grp=[0-9] res=[0-9]
> + */
> +
> +#include <unistd.h>
> +#include <stdio.h>
> +#include "ftrace_regression.h"
> +
> +#define DEBUGFS_DIR "debugfs"
> +#define SET_EVENT DEBUGFS_DIR "/tracing/set_event"
> +#define TRACING_ON DEBUGFS_DIR "/tracing/tracing_on"
> +#define TRACE_FILE DEBUGFS_DIR "/tracing/trace"
> +
> +#define LOOP 100
> +
> +static void setup(void)
> +{
> +	SAFE_MKDIR(DEBUGFS_DIR, 0755);
> +	SAFE_MOUNT(NULL, DEBUGFS_DIR, "debugfs", 0, NULL);
> +}
> +
> +static void run(void)
> +{
> +	int i;
> +
> +	SAFE_FILE_PRINTF(SET_EVENT, "signal:signal_generate");
> +	SAFE_FILE_PRINTF(TRACING_ON, "1");
> +	SAFE_FILE_PRINTF(TRACE_FILE, "\n");
> +
> +	for (i = 0; i < LOOP; i++)
> +		tst_cmd((const char *[]){"ls", "-l", "/proc", NULL},
> +			"/dev/null", "/dev/null", 0);

> +	if (file_contains(TRACE_FILE, "grp=[0-9]") && file_contains(TRACE_FILE, "res=[0-9]"))
> +		tst_res(TPASS, "Finished running the test");
Also here, please, better tpass message.
> +	else
> +		tst_res(TFAIL, "Pattern grp=[0-9] res=[0-9] not found in trace");
> +}
> +
> +static void cleanup(void)
> +{
> +	SAFE_UMOUNT(DEBUGFS_DIR);
> +}
> +
> +static struct tst_test test = {
> +	.needs_root = 1,
> +	.needs_tmpdir = 1,
> +	.setup = setup,
> +	.test_all = run,
> +	.cleanup = cleanup,
> +	.needs_cmds = (struct tst_cmd[]) {
> +		{.cmd = "ls"},
> +		{}
> +	},
> +	.min_kver = "3.2",
We now support kernel >= 4.4, this should be removed.
https://linux-test-project.readthedocs.io/en/latest/users/supported_systems.html#kernel-version

> +	.tags = (const struct tst_tag[]) {
> +		{"linux-git", "6c303d3"},
> +		{"linux-git", "163566f"},
And longer hash.
> +		{}
> +	},
> +};

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

  reply	other threads:[~2026-03-31  7:54 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-04  8:05 [LTP] [PATCH 1/2] Rewrite ftrace_regression01.sh with new C API lufei
2026-03-04  8:05 ` [LTP] [PATCH 2/2] Rewrite ftrace_regression02.sh " lufei
2026-03-27 10:34 ` [LTP] [PATCH 1/2] Rewrite ftrace_regression01.sh " Andrea Cervesato via ltp
2026-03-30  7:15 ` [LTP] [PATCH v2] Rewrite ftrace_regression tests " lufei
2026-03-30  8:39   ` Andrea Cervesato via ltp
2026-03-31  1:55   ` [LTP] [PATCH v3] " lufei
2026-03-31  7:53     ` Petr Vorel [this message]
2026-03-31  7:56     ` Petr Vorel
2026-03-31 18:28       ` Cyril Hrubis
2026-03-31 10:01     ` [LTP] [PATCH v4] " lufei

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260331075346.GB5254@pevik \
    --to=pvorel@suse.cz \
    --cc=ltp@lists.linux.it \
    --cc=lufei@uniontech.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox