[posix] apply -d once the instance exists (#13773)

ot-daemon and ot-cli set the log level from -d with otLoggingSetLevel()
before otSysInit() creates the instance; the Instance constructor then
resets the level to OPENTHREAD_CONFIG_LOG_LEVEL_INIT, so -d had no effect
and the daemon logged critical lines only, whatever the value.

Set the level after otSysInit(). The two scripts that start ot-daemon
with -d7 asked for a level that does not exist (otLoggingSetLevel()
rejects anything above OT_LOG_LEVEL_DEBG, 5); they ask for 5 now, and
check-posix-pty verifies that OpenThread's own log lines reach the
daemon's output.
This commit is contained in:
Clara
2026-10-21 23:25:05 -07:00
committed by GitHub
parent ae19db64d8
commit 26ff9473d0
3 changed files with 9 additions and 5 deletions
+1 -1
View File
@@ -112,7 +112,7 @@ do_check()
RADIO_NCP_PATH="$PWD/build/simulation/examples/apps/ncp/ot-rcp"
RADIO_URL="spinel+hdlc+forkpty://${RADIO_NCP_PATH}?forkpty-arg=2"
sudo -E "$PWD/build/posix/src/posix/ot-daemon" -d7 -v -I wpan0 -B veth-a "${RADIO_URL}" &
sudo -E "$PWD/build/posix/src/posix/ot-daemon" -d5 -v -I wpan0 -B veth-a "${RADIO_URL}" &
wait_for "state" "Done" || die "failed to start daemon"
# verify this reset and factoryreset end immediately
+6 -3
View File
@@ -211,7 +211,7 @@ do_check()
if [[ ${OT_DAEMON} == 'on' ]]; then
# The log file is in our own tmp directory, so the redirect does not need sudo.
# shellcheck disable=SC2024
sudo -E "$PWD/build/posix/src/posix/ot-daemon" -d7 -v -I "${VALID_NETIF_NAME}" "${RADIO_URL}" >"${OT_DAEMON_OUTPUT}" 2>&1 &
sudo -E "$PWD/build/posix/src/posix/ot-daemon" -d5 -v -I "${VALID_NETIF_NAME}" "${RADIO_URL}" >"${OT_DAEMON_OUTPUT}" 2>&1 &
OT_DAEMON_JOB=$!
sleep 3
# macOS cannot explicitly set network interface name
@@ -222,6 +222,9 @@ do_check()
else
OT_CTL=(sudo "${OT_CTL_PATH}")
fi
# -d5 asks for debug logging; the daemon's output must carry OpenThread's own log lines, not only the
# syslog() lines of its startup.
timeout_run 10 grep -qE '\[(D|I)\] ' "${OT_DAEMON_OUTPUT}" || die 'the daemon does not log at the level -d asked for'
"${OT_CTL[@]}" -I "${NETIF_NAME}" panid 0xface | grep 'Done' || die 'failed to set panid with ot-ctl'
# verify supports options in OpenThread commands without separator --
@@ -250,8 +253,8 @@ do_check()
die
fi
# check_daemon_multicast_group reads INFO lines of the netif; `-d7` does not take
# effect, as main.c sets the level before the instance exists.
# check_daemon_multicast_group reads INFO lines of the netif; -d5 above gives them along
# with everything at DEBG, so settle on INFO for the rest of the run.
"${OT_CTL[@]}" -I "${NETIF_NAME}" log level 4 | grep 'Done' || die 'failed to set log level'
OT_CLI_CMD="${OT_CTL[*]} -I ${NETIF_NAME}"
else
+2 -1
View File
@@ -323,10 +323,11 @@ static otInstance *InitInstance(PosixConfig *aConfig)
syslog(LOG_INFO, "Running %s", otGetVersionString());
syslog(LOG_INFO, "Thread version: %hu", otThreadGetVersion());
IgnoreError(otLoggingSetLevel(aConfig->mLogLevel));
instance = otSysInit(&aConfig->mPlatformConfig);
VerifyOrDie(instance != NULL, OT_EXIT_FAILURE);
// The instance starts at OPENTHREAD_CONFIG_LOG_LEVEL_INIT; a level set before it exists is lost.
IgnoreError(otLoggingSetLevel(aConfig->mLogLevel));
syslog(LOG_INFO, "Thread interface: %s", otSysGetThreadNetifName());
if (aConfig->mPlatformConfig.mCoprocessorType != OT_COPROCESSOR_RCP)