All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mark Hatle <mark.hatle@kernel.crashing.org>
To: yocto-patches@lists.yoctoproject.org
Subject: [pseudo][PATCH 22/34] pseudo_util: Make -v and numeric PSEUDO_DEBUG add debug flags
Date: Tue, 10 Nov 2026 22:20:50 -0600	[thread overview]
Message-ID: <1794370862-30908-23-git-send-email-mark.hatle@kernel.crashing.org> (raw)
In-Reply-To: <1794370862-30908-1-git-send-email-mark.hatle@kernel.crashing.org>

From: Mark Hatle <mark.hatle@amd.com>

Since 2a7591e, pseudo_debug_set() replaces the debug flags, so each -v,
and each step of a numeric PSEUDO_DEBUG level, replaced the previous
flag instead of adding to it: -v -v -v gave "o" instead of "nfo".  Add
the flag in pseudo_debug_verbose() instead.  Also start a numeric level
from no flags, as pseudo_init_util() can run more than once in a
process and each run added another set.

Add test-debug-flags, covering -v, numeric PSEUDO_DEBUG, and how
PSEUDO_SEVERITY and -k reach programs run under pseudo.

AI-Generated: Uses GitHub Copilot
Signed-off-by: Mark Hatle <mark.hatle@amd.com>
---
 pseudo_util.c            | 12 ++++++----
 test/test-debug-flags.sh | 59 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 67 insertions(+), 4 deletions(-)
 create mode 100755 test/test-debug-flags.sh

diff --git a/pseudo_util.c b/pseudo_util.c
index 631c3e9..1eb90d5 100644
--- a/pseudo_util.c
+++ b/pseudo_util.c
@@ -96,6 +96,8 @@ static unsigned long pseudo_severity_flags_in(char *);
  * best to handle that case.
  */
 static int pseudo_util_initted = -1;  /* Not yet run */
+/* number of debug flags turned on by pseudo_debug_verbose() */
+static int max_debug_level = 0;
 
 /* bypass wrapper logic on path computations */
 int (*pseudo_real_lstat)(const char *path, PSEUDO_STATBUF *buf) = NULL;
@@ -217,6 +219,10 @@ pseudo_init_util(void) {
 		int i;
 		int level = pseudo_atoi_wrapper(env);
 		if (level > 0) {
+			/* a level selects the first <level> flags, even if
+			 * this runs more than once in a process */
+			pseudo_util_debug_flags = 0;
+			max_debug_level = 0;
 			for (i = 0; i < level; ++i) {
 				pseudo_debug_verbose();
 			}
@@ -379,9 +385,6 @@ with_libpseudo(char *list) {
 
 char *pseudo_version = PSEUDO_VERSION;
 
-/* going away soon */
-static int max_debug_level = 0;
-
 void
 pseudo_debug_terse(void) {
 	char s[2] = { pseudo_debug_type_symbolic(max_debug_level) };
@@ -397,7 +400,8 @@ pseudo_debug_verbose(void) {
 	char s[2] = { pseudo_debug_type_symbolic(max_debug_level + 1) };
 
 	if (s[0]) {
-		pseudo_debug_set(s);
+		/* add to the flags already set, unlike pseudo_debug_set() */
+		pseudo_util_debug_flags |= pseudo_debug_flags_in(s);
 		++max_debug_level;
 	}
 }
diff --git a/test/test-debug-flags.sh b/test/test-debug-flags.sh
new file mode 100755
index 0000000..1cf6b14
--- /dev/null
+++ b/test/test-debug-flags.sh
@@ -0,0 +1,59 @@
+#!/bin/bash
+#
+# SPDX-License-Identifier: LGPL-2.1-only
+#
+# Check how debugging and severity settings reach programs run under pseudo:
+# - each -v adds the next debugging flag to those already set;
+# - a numeric PSEUDO_DEBUG turns on exactly that many flags, even in a process
+#   which initializes the client library more than once;
+# - PSEUDO_SEVERITY is passed on as severity names, from the default or -k.
+
+tmpdir="$(mktemp -d -p "$PWD" debug_flags_XXXXXX)"
+mkdir "$tmpdir/state"
+
+# Run a separate pseudo, with its own state directory, outside of the pseudo
+# running this test: PSEUDO_UNLOAD keeps libpseudo out of env(1), which then
+# starts pseudo with a clean environment.
+new_pseudo() {
+	PSEUDO_UNLOAD=1 env -u PSEUDO_UNLOAD -u PSEUDO_DEBUG -u PSEUDO_SEVERITY \
+		PSEUDO_LOCALSTATEDIR="$tmpdir/state" ./bin/pseudo "$@"
+}
+trap "new_pseudo -S >/dev/null 2>&1; rm -rf '$tmpdir'" EXIT TERM INT
+
+rc=0
+fail() {
+	echo "FAILED: $*"
+	rc=1
+}
+
+# value of a variable in the environment of a program run by a new pseudo
+var_under() {
+	local var=$1
+	shift
+	new_pseudo "$@" env | sed -n "s/^$var=//p"
+}
+
+check() {
+	local want=$1 got=$2
+	shift 2
+	[ "$got" = "$want" ] || fail "$*: got '$got', expected '$want'"
+}
+
+check nfo "$(var_under PSEUDO_DEBUG -v -v -v)" "pseudo -v -v -v"
+check no "$(var_under PSEUDO_DEBUG -x o -v)" "pseudo -x o -v"
+check info,warn,error "$(var_under PSEUDO_SEVERITY)" "default PSEUDO_SEVERITY"
+check warn,error "$(var_under PSEUDO_SEVERITY -k warn,error)" "pseudo -k warn,error"
+
+# A level turns on the first flags in order: o (operations, which logs
+# "exec" messages) is the third and P (process IDs, "new pid") the fourth.
+# The commands initialize the client library more than once.
+for level in 2 4; do
+	PSEUDO_DEBUG=$level PSEUDO_DEBUG_FILE="$tmpdir/debug.$level" \
+		sh -c '/bin/true; sh -c /bin/true' 2>/dev/null
+done
+grep -q "new pid:" "$tmpdir/debug.2" 2>/dev/null &&
+	fail "PSEUDO_DEBUG=2 turned on more than the first two debugging flags"
+grep -q "exec /" "$tmpdir/debug.4" 2>/dev/null ||
+	fail "PSEUDO_DEBUG=4 didn't turn on the first four debugging flags"
+
+exit $rc
-- 
1.8.3.1


  parent reply	other threads:[~2026-11-11  4:21 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-11  4:20 [pseudo][PATCH 00/34] Various fixes Mark Hatle
2026-11-11  4:20 ` [pseudo][PATCH 01/34] pseudo_client: serialize path changes across clients Mark Hatle
2026-11-11  4:20 ` [pseudo][PATCH 02/34] ports: hold the path lock in create and metadata wrappers Mark Hatle
2026-11-11  4:20 ` [pseudo][PATCH 03/34] ports: check created files under the path lock before recording them Mark Hatle
2026-11-11  4:20 ` [pseudo][PATCH 04/34] test-parallel-ops: Add a parallel create/rename/link/chmod test Mark Hatle
2026-11-11  4:20 ` [pseudo][PATCH 05/34] ports: Remove PSEUDO_NO_REAL_AT_FUNCTIONS Mark Hatle
2026-11-11  4:20 ` [pseudo][PATCH 06/34] ports/unix: Remove guts overridden by the Linux port Mark Hatle
2026-11-11  4:20 ` [pseudo][PATCH 07/34] ports: Let the port define how pseudo stats files Mark Hatle
2026-11-11  4:20 ` [pseudo][PATCH 08/34] patches/yocto-older-glibc-symbols.patch: Update to latest YP version Mark Hatle
2026-11-11  4:20 ` [pseudo][PATCH 09/34] Remove unused #if 0 debug code Mark Hatle
2026-11-11  4:20 ` [pseudo][PATCH 10/34] Replace #if 0 strerror() debug messages with a comment Mark Hatle
2026-11-11  4:20 ` [pseudo][PATCH 11/34] pseudo_util: Remove stale with_libpseudo() comment Mark Hatle
2026-11-11  4:20 ` [pseudo][PATCH 12/34] ports/common/subports: Show the unknown OS name in the error Mark Hatle
2026-11-11  4:20 ` [pseudo][PATCH 13/34] ports/linux: Drop redundant PSEUDO_LINK_SYMLINK_BEHAVIOR override Mark Hatle
2026-11-11  4:20 ` [pseudo][PATCH 14/34] pseudo_server: Skip events for clients closed earlier in the batch Mark Hatle
2026-11-11  4:20 ` [pseudo][PATCH 15/34] pseudo_server: Drop an idle client when out of file descriptors Mark Hatle
2026-11-11  4:20 ` [pseudo][PATCH 16/34] pseudo_server: Always use epoll Mark Hatle
2026-11-11  4:20 ` [pseudo][PATCH 17/34] configure: Fix --disable-* options Mark Hatle
2026-11-11  4:20 ` [pseudo][PATCH 18/34] pseudo_server: Lower highest_client when the highest client closes Mark Hatle
2026-11-11  4:20 ` [pseudo][PATCH 19/34] pseudo_server: Set highest_client to the new client when growing Mark Hatle
2026-11-11  4:20 ` [pseudo][PATCH 20/34] pseudo_util: Store PSEUDO_SEVERITY as severity names Mark Hatle
2026-11-11  4:20 ` [pseudo][PATCH 21/34] pseudo: Fix the -k severity option Mark Hatle
2026-11-11  4:20 ` Mark Hatle [this message]
2026-11-11  4:20 ` [pseudo][PATCH 23/34] AGENTS.md: Add to assist future developers Mark Hatle
2026-11-11  4:20 ` [pseudo][PATCH 24/34] pseudo_util: Fix the date format in the event log dump Mark Hatle
2026-11-11  4:20 ` [pseudo][PATCH 25/34] pseudo: List -p in the usage message Mark Hatle
2026-11-11  4:20 ` [pseudo][PATCH 26/34] pseudo_util: Write the event log to PSEUDO_EVLOG_FILE Mark Hatle
2026-11-11  4:20 ` [pseudo][PATCH 27/34] pseudo.1: Update to match the current code Mark Hatle
2026-11-11  4:20 ` [pseudo][PATCH 28/34] ports/linux: Don't require <linux/mount.h> Mark Hatle
2026-11-11  4:20 ` [pseudo][PATCH 29/34] configure: Require GCC 5 or later Mark Hatle
2026-11-11  4:20 ` [pseudo][PATCH 30/34] doc: Update README and doc/ to match the code Mark Hatle
2026-11-11  4:20 ` [pseudo][PATCH 31/34] configure: Fix the --enable-profiling default Mark Hatle
2026-11-11  4:21 ` [pseudo][PATCH 32/34] pseudo_util: Skip unneeded lstat calls when canonicalizing paths Mark Hatle
2026-11-11  4:21 ` [pseudo][PATCH 33/34] wrappers: Don't re-block signals in nested wrapper calls Mark Hatle
2026-11-11  4:21 ` [pseudo][PATCH 34/34] Wrap execvpe(), fexecve() and execveat() Mark Hatle

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=1794370862-30908-23-git-send-email-mark.hatle@kernel.crashing.org \
    --to=mark.hatle@kernel.crashing.org \
    --cc=yocto-patches@lists.yoctoproject.org \
    /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 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.