git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 5/6] test-tool: extend trace2 helper with 400ancestry

From
Matthew John Cheetham via GitGitGadget <gitgitgadget@gmail.com>
Date
Feb 13, 2026, 19:54 UTC
Message-ID
<b9a94291a6238bfe8d4fd05d479b4d6d8ab6efc1.1771012500.git.gitgitgadget@gmail.com>
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
Previous: Junio C HamanoNext: Matthew John Cheetham via GitGitGadget
Message 23 of 25 in “trace2: add macOS and Windows process ancestry tracing”
  1. 0/4 trace2: add macOS and Windows process ancestry tracingMatthew John Cheetham via GitGitGadget, Feb 5, 2026
  2. 2/4 build: include procinfo.c impl for macOSMatthew John Cheetham via GitGitGadget, Feb 5, 2026
  3. Derrick StoleeFeb 9, 2026
  4. 1/4 trace2: add macOS process ancestry tracingMatthew John Cheetham via GitGitGadget, Feb 5, 2026
  5. Derrick StoleeFeb 9, 2026
  6. Matthew John CheethamFeb 9, 2026
  7. Derrick StoleeFeb 10, 2026
  8. 3/4 trace2: refactor Windows process ancestry trace2 eventMatthew John Cheetham via GitGitGadget, Feb 5, 2026
  9. Derrick StoleeFeb 9, 2026
  10. 4/4 trace2: emit cmd_ancestry data for WindowsMatthew John Cheetham via GitGitGadget, Feb 5, 2026
  11. Kristoffer HaugsbakkFeb 5, 2026
  12. Derrick StoleeFeb 9, 2026
  13. Derrick StoleeFeb 9, 2026
  14. Junio C HamanoFeb 9, 2026
  15. 0/6 trace2: add macOS and Windows process ancestry tracingMatthew John Cheetham via GitGitGadget, Feb 13, 2026
  16. 1/6 trace2: add macOS process ancestry tracingMatthew John Cheetham via GitGitGadget, Feb 13, 2026
  17. 2/6 build: include procinfo.c impl for macOSMatthew John Cheetham via GitGitGadget, Feb 13, 2026
  18. Junio C HamanoFeb 13, 2026
  19. 3/6 trace2: refactor Windows process ancestry trace2 eventMatthew John Cheetham via GitGitGadget, Feb 13, 2026
  20. Junio C HamanoFeb 13, 2026
  21. 4/6 trace2: emit cmd_ancestry data for WindowsMatthew John Cheetham via GitGitGadget, Feb 13, 2026
  22. Junio C HamanoFeb 13, 2026
  23. 5/6 test-tool: extend trace2 helper with 400ancestryMatthew John Cheetham via GitGitGadget, Feb 13, 2026
  24. 6/6 t0213: add trace2 cmd_ancestry testsMatthew John Cheetham via GitGitGadget, Feb 13, 2026
  25. Derrick StoleeFeb 14, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.