libnet: Fix Coverity ID 1634803 Dereference after null check
[samba4-gss.git] / source3 / script / tests / test_winbind_call_depth_trace.sh
blob6d978beca8f905ba2d5860f56c2161450fc711f4
1 #!/bin/sh
3 # Copyright (c) Pavel Filipenský <pfilipensky@samba.org>
4 # License: GPLv3
6 if [ $# -lt 4 ]; then
7 echo "Usage: test_winbind_call_depth_trace SMBCONTROL CONFIGURATION PREFIX TESTENV"
8 exit 1
9 fi
11 SMBCONTROL="${1}"
12 CONFIGURATION=${2}
13 PREFIX="${3}"
14 TESTENV="${4}"
15 shift 4
17 incdir=$(dirname "$0")/../../../testprogs/blackbox
18 . "$incdir"/subunit.sh
20 failed=0
22 PREFIX_ABS="$(readlink -f "${PREFIX}")"
23 # Strip from TESTENV the ':local' if present
24 TESTENV_SUBDIR=${TESTENV%:*}
26 LOGFILE="${PREFIX_ABS}/${TESTENV_SUBDIR}/logs/log.winbindd"
27 # Add support for "WINBINDD_DONT_LOG_STDOUT=1"
28 if [ ! -r "${LOGFILE}" ]; then
29 TEST_LOGFILE="${PREFIX_ABS}/${TESTENV_SUBDIR}/winbindd_test.log"
30 subunit_start_test "test winbind call depth trace"
31 subunit_skip_test "test winbind call depth trace" <<EOF
32 Test is skipped, we need $LOGFILE but have only $TEST_LOGFILE which is missing debug headers (they are not printed to stdout).
33 EOF
34 exit 0
37 saved_level=1
39 get_winbind_loglevel()
41 s1=$(${SMBCONTROL} "${CONFIGURATION}" winbind debuglevel)
42 # We need to get the all level from output like this:
43 # "PID 664474: all:1 tdb:1 printdrivers:1 lanman:1 smb:1 rpc_parse:1 rpc_srv:1 rpc_cli:1 passdb:1 sam:1..."
44 # 1. remove PID 664474:
45 s2=${s1#PID*: }
46 # "all:1 tdb:1 printdrivers:1 lanman:1 smb:1 rpc_parse:1 rpc_srv:1 rpc_cli:1 passdb"
47 # 2. remove " tdb:1 printdrivers:1 ..."
48 s3=${s2%% *}
49 # "all:1"
50 # 3. remove "all:"
51 saved_level=${s3#all:}
54 # Example of trace line
55 # [2023/01/25 00:20:33.307038, 5, pid=535581, effective(0, 0), real(0, 0), class=winbind, traceid=78, depth=4] ../../source3/winbindd/wb_group_members.c:310(wb_group_members_send)
56 test_winbind_call_depth_trace()
58 get_winbind_loglevel
60 # If loglevel < 10, set it to 10.
61 if [ "$saved_level" -lt 10 ]; then
62 ${SMBCONTROL} "${CONFIGURATION}" winbind debug 10
65 COUNT1=$(grep -c wb_group_members_send "$LOGFILE")
67 id ADDOMAIN/alice
68 ret=$?
70 # Restore loglevel, if it was changed.
71 if [ "$saved_level" -lt 10 ]; then
72 ${SMBCONTROL} "${CONFIGURATION}" winbind debug "$saved_level"
75 if [ $ret != 0 ]; then
76 echo "Command 'id ADDOMAIN/alice' failed!"
77 return 1
80 # Check that there are more lines with wb_group_members_send
81 COUNT2=$(grep -c wb_group_members_send "$LOGFILE")
82 if [ "$COUNT1" -eq "$COUNT2" ]; then
83 echo "The number of the trace lines in $LOGFILE has not increased."
84 return 1
87 # Test that the depth of last line with 'wb_group_members_send' is: depth=4
88 COUNT3=$(grep wb_group_members_send "$LOGFILE" | tail -1 | grep -c depth=4)
89 if [ "$COUNT3" -ne 1 ]; then
90 echo "The last line with wb_group_members_send should have depth=4."
91 return 1
94 # Test that the indentation of the line below last 'wb_group_members_send' is indented by 2+4*4 spaces:
95 COUNT4=$(grep -A1 wb_group_members_send "$LOGFILE" | tail -1| grep -c '^ WB command group_members start')
96 if [ "$COUNT4" -ne 1 ]; then
97 echo "The line after the last line with wb_group_members_send should be indented by 18 spaces."
98 return 1
101 return 0
104 case ${TESTENV} in
105 ad_member*)
108 echo "Test is for ad_member only, but called for ${TESTENV}." | subunit_fail_test "test winbind call depth trace"
109 exit 1;
110 esac
112 testit "test winbind call depth trace" test_winbind_call_depth_trace || failed=$((failed + 1))
113 testok "$0" "$failed"