Skip to content

Commit 17fcee4

Browse files
authored
test: Write logs to correct output stream (#8236)
1 parent 1b8c818 commit 17fcee4

File tree

2 files changed

+56
-4
lines changed

2 files changed

+56
-4
lines changed

qa/L0_logging/test.sh

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
2-
# Copyright 2022-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
# Copyright 2022-2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
33
#
44
# Redistribution and use in source and binary forms, with or without
55
# modification, are permitted provided that the following conditions
@@ -490,7 +490,7 @@ set -e
490490
kill $SERVER_PID
491491
wait $SERVER_PID
492492

493-
#Test Negative Test Cases
493+
# Test Negative Test Cases
494494
SERVER_ARGS="--log-warn="false" --model-repository=$MODELSDIR"
495495
SERVER_LOG="./server.log"
496496
run_server
@@ -607,6 +607,53 @@ fi
607607

608608
set -e
609609

610+
# Test Log Output Stream
611+
# Set up an invalid model with a leading zero in the version number. This will print warning and error logs.
612+
MODELSDIR_INVALID=`pwd`/log_models_invalid
613+
rm -rf $MODELSDIR_INVALID && \
614+
cp -r $MODELSDIR $MODELSDIR_INVALID && \
615+
mv $MODELSDIR_INVALID/simple/1 $MODELSDIR_INVALID/simple/01
616+
617+
rm -f log_file.log
618+
LOG_REGEX="(?P<month>\d{2})(?P<day>\d{2}) (?P<timestamp>\d{2}:\d{2}:\d{2}\.\d{6}) (?P<pid>\d+) (?P<file>[\w\.]+):(?P<line>\d+)] (?P<message>.*)"
619+
SERVER_ARGS="--log-verbose=1 --model-repository=$MODELSDIR_INVALID"
620+
SERVER_LOG="./inference_server_log_file.log"
621+
SERVER_ERROR_LOG="./inference_server_error_log_file.log"
622+
run_server
623+
if [ "$SERVER_PID" != "0" ]; then
624+
echo -e "*** FAILED: unexpected success starting $SERVER" >> $CLIENT_LOG
625+
cat $SERVER_LOG
626+
kill_server
627+
exit 1
628+
fi
629+
630+
set +e
631+
# Only INFO logs in SERVER_LOG
632+
if [ `grep -c -P "I$LOG_REGEX" $SERVER_LOG` == "0" ]; then
633+
echo -e "\n***\n*** Test Failed: INFO logs are not written to $SERVER_LOG\n***"
634+
RET=1
635+
fi
636+
if [ `grep -c -P "(W|E)$LOG_REGEX" $SERVER_LOG` != "0" ]; then
637+
echo -e "\n***\n*** Test Failed: WARNING/ERROR logs are written to $SERVER_LOG\n***"
638+
RET=1
639+
fi
640+
# Only WARNING and ERROR logs in SERVER_ERROR_LOG
641+
if [ `grep -c -P "I$LOG_REGEX" $SERVER_ERROR_LOG` != "0" ]; then
642+
echo -e "\n***\n*** Test Failed: INFO logs are written to $SERVER_ERROR_LOG\n***"
643+
RET=1
644+
fi
645+
if [ `grep -c -P "W$LOG_REGEX" $SERVER_ERROR_LOG` == "0" ]; then
646+
echo -e "\n***\n*** Test Failed: ERROR logs are not written to $SERVER_ERROR_LOG\n***"
647+
RET=1
648+
fi
649+
if [ `grep -c -P "E$LOG_REGEX" $SERVER_ERROR_LOG` == "0" ]; then
650+
echo -e "\n***\n*** Test Failed: ERROR logs are not written to $SERVER_ERROR_LOG\n***"
651+
RET=1
652+
fi
653+
654+
unset $SERVER_ERROR_LOG
655+
set -e
656+
610657
if [ $RET -eq 0 ]; then
611658
echo -e "\n***\n*** Test Passed\n***"
612659
else

qa/common/util.sh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
2-
# Copyright 2018-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2+
# Copyright 2018-2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
33
#
44
# Redistribution and use in source and binary forms, with or without
55
# modification, are permitted provided that the following conditions
@@ -196,7 +196,12 @@ function run_server () {
196196
echo "=== Running LD_PRELOAD=$SERVER_LD_PRELOAD $SERVER $SERVER_ARGS"
197197
fi
198198

199-
LD_PRELOAD=$SERVER_LD_PRELOAD:${LD_PRELOAD} $SERVER $SERVER_ARGS > $SERVER_LOG 2>&1 &
199+
# If SERVER_ERROR_LOG is not set, redirect stderr to stdout
200+
if [ -z "${SERVER_ERROR_LOG:-}" ]; then
201+
LD_PRELOAD=$SERVER_LD_PRELOAD:${LD_PRELOAD} $SERVER $SERVER_ARGS > $SERVER_LOG 2>&1 &
202+
else
203+
LD_PRELOAD=$SERVER_LD_PRELOAD:${LD_PRELOAD} $SERVER $SERVER_ARGS > $SERVER_LOG 2>$SERVER_ERROR_LOG &
204+
fi
200205
SERVER_PID=$!
201206

202207
wait_for_server_ready $SERVER_PID $SERVER_TIMEOUT

0 commit comments

Comments
 (0)