public inbox for git@vger.kernel.org
 help / color / mirror / Atom feed
From: "Matthew John Cheetham via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: gitster@pobox.com, stolee@gmail.com, johannes.schindelin@gmx.de,
	Kristoffer Haugsbakk <kristofferhaugsbakk@fastmail.com>,
	Matthew John Cheetham <mjcheetham@outlook.com>,
	Matthew John Cheetham <mjcheetham@outlook.com>,
	Matthew John Cheetham <mjcheetham@outlook.com>
Subject: [PATCH v2 5/6] test-tool: extend trace2 helper with 400ancestry
Date: Fri, 13 Feb 2026 19:54:59 +0000	[thread overview]
Message-ID: <b9a94291a6238bfe8d4fd05d479b4d6d8ab6efc1.1771012500.git.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.2040.v2.git.1771012500.gitgitgadget@gmail.com>

From: Matthew John Cheetham <mjcheetham@outlook.com>

Add a new test helper "400ancestry" to the trace2 test-tool that
spawns a child process with a controlled trace2 environment, capturing
only the child's trace2 output (including cmd_ancestry events) in
isolation.

The helper clears all inherited GIT_TRACE2* variables in the child
and enables only the requested target (normal, perf, or event),
directing output to a specified file. This gives the test suite a
reliable way to capture cmd_ancestry events: the child always sees
"test-tool" as its immediate parent in the process ancestry, providing
a predictable value to verify in tests.

Signed-off-by: Matthew John Cheetham <mjcheetham@outlook.com>
---
 t/helper/test-trace2.c | 59 ++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 59 insertions(+)

diff --git a/t/helper/test-trace2.c b/t/helper/test-trace2.c
index 415df078c1..3b12f4173e 100644
--- a/t/helper/test-trace2.c
+++ b/t/helper/test-trace2.c
@@ -466,6 +466,63 @@ static int ut_303redact_def_param(int argc, const char **argv)
 	return 0;
 }
 
+/*
+ * Run a child process with specific trace2 environment settings so that
+ * we can capture its trace2 output (including cmd_ancestry) in isolation.
+ *
+ * test-tool trace2 400ancestry <target> <output_file> [<child_command_line>]
+ *
+ * <target> is one of: normal, perf, event
+ *
+ * For example:
+ *     test-tool trace2 400ancestry normal out.normal test-tool trace2 001return 0
+ *
+ * The child process inherits a controlled trace2 environment where only
+ * the specified target is directed to <output_file>. The parent's trace2
+ * environment variables are cleared in the child so that only the child's
+ * events are captured.
+ *
+ * This is used by t0213-trace2-ancestry.sh to test cmd_ancestry events.
+ * The child process will see "test-tool" as its immediate parent in the
+ * process ancestry, giving us a predictable value to verify.
+ */
+static int ut_400ancestry(int argc, const char **argv)
+{
+	struct child_process cmd = CHILD_PROCESS_INIT;
+	const char *target;
+	const char *outfile;
+	int result;
+
+	if (argc < 3)
+		die("expect <target> <output_file> <child_command_line>");
+
+	target = argv[0];
+	outfile = argv[1];
+	argv += 2;
+	argc -= 2;
+
+	/* Clear all trace2 environment variables in the child. */
+	strvec_push(&cmd.env, "GIT_TRACE2=");
+	strvec_push(&cmd.env, "GIT_TRACE2_PERF=");
+	strvec_push(&cmd.env, "GIT_TRACE2_EVENT=");
+	strvec_push(&cmd.env, "GIT_TRACE2_BRIEF=1");
+
+	/* Set only the requested target. */
+	if (!strcmp(target, "normal"))
+		strvec_pushf(&cmd.env, "GIT_TRACE2=%s", outfile);
+	else if (!strcmp(target, "perf"))
+		strvec_pushf(&cmd.env, "GIT_TRACE2_PERF=%s", outfile);
+	else if (!strcmp(target, "event"))
+		strvec_pushf(&cmd.env, "GIT_TRACE2_EVENT=%s", outfile);
+	else
+		die("invalid target '%s', expected: normal, perf, event",
+		    target);
+
+	strvec_pushv(&cmd.args, argv);
+	result = run_command(&cmd);
+	exit(result);
+}
+
 /*
  * Usage:
  *     test-tool trace2 <ut_name_1> <ut_usage_1>
@@ -497,6 +554,8 @@ static struct unit_test ut_table[] = {
 	{ ut_301redact_child_start, "301redact_child_start", "<argv...>" },
 	{ ut_302redact_exec,        "302redact_exec",        "<exe> <argv...>" },
 	{ ut_303redact_def_param,   "303redact_def_param",   "<key> <value>" },
+
+	{ ut_400ancestry,           "400ancestry",           "<target> <output_file> [<child_command_line>]" },
 };
 /* clang-format on */
 
-- 
gitgitgadget


  parent reply	other threads:[~2026-02-13 19:55 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-05 16:05 [PATCH 0/4] trace2: add macOS and Windows process ancestry tracing Matthew John Cheetham via GitGitGadget
2026-02-05 16:05 ` [PATCH 1/4] trace2: add macOS " Matthew John Cheetham via GitGitGadget
2026-02-09 14:36   ` Derrick Stolee
2026-02-09 15:13     ` Matthew John Cheetham
2026-02-10  4:15       ` Derrick Stolee
2026-02-05 16:05 ` [PATCH 2/4] build: include procinfo.c impl for macOS Matthew John Cheetham via GitGitGadget
2026-02-09 14:37   ` Derrick Stolee
2026-02-05 16:05 ` [PATCH 3/4] trace2: refactor Windows process ancestry trace2 event Matthew John Cheetham via GitGitGadget
2026-02-09 14:41   ` Derrick Stolee
2026-02-05 16:05 ` [PATCH 4/4] trace2: emit cmd_ancestry data for Windows Matthew John Cheetham via GitGitGadget
2026-02-05 16:19   ` Kristoffer Haugsbakk
2026-02-09 14:42   ` Derrick Stolee
2026-02-09 14:48 ` [PATCH 0/4] trace2: add macOS and Windows process ancestry tracing Derrick Stolee
2026-02-09 17:05   ` Junio C Hamano
2026-02-13 19:54 ` [PATCH v2 0/6] " Matthew John Cheetham via GitGitGadget
2026-02-13 19:54   ` [PATCH v2 1/6] trace2: add macOS " Matthew John Cheetham via GitGitGadget
2026-02-13 19:54   ` [PATCH v2 2/6] build: include procinfo.c impl for macOS Matthew John Cheetham via GitGitGadget
2026-02-13 20:34     ` Junio C Hamano
2026-02-13 19:54   ` [PATCH v2 3/6] trace2: refactor Windows process ancestry trace2 event Matthew John Cheetham via GitGitGadget
2026-02-13 20:36     ` Junio C Hamano
2026-02-13 19:54   ` [PATCH v2 4/6] trace2: emit cmd_ancestry data for Windows Matthew John Cheetham via GitGitGadget
2026-02-13 20:52     ` Junio C Hamano
2026-02-13 19:54   ` Matthew John Cheetham via GitGitGadget [this message]
2026-02-13 19:55   ` [PATCH v2 6/6] t0213: add trace2 cmd_ancestry tests Matthew John Cheetham via GitGitGadget
2026-02-14  0:30   ` [PATCH v2 0/6] trace2: add macOS and Windows process ancestry tracing Derrick Stolee

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=b9a94291a6238bfe8d4fd05d479b4d6d8ab6efc1.1771012500.git.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=johannes.schindelin@gmx.de \
    --cc=kristofferhaugsbakk@fastmail.com \
    --cc=mjcheetham@outlook.com \
    --cc=stolee@gmail.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