summaryrefslogtreecommitdiffstats
path: root/source3/script/tests/test_winbind_call_depth_trace.sh
blob: 6d978beca8f905ba2d5860f56c2161450fc711f4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
#!/bin/sh

# Copyright (c) Pavel Filipenský <pfilipensky@samba.org>
# License: GPLv3

if [ $# -lt 4 ]; then
	echo "Usage: test_winbind_call_depth_trace SMBCONTROL CONFIGURATION PREFIX TESTENV"
	exit 1
fi

SMBCONTROL="${1}"
CONFIGURATION=${2}
PREFIX="${3}"
TESTENV="${4}"
shift 4

incdir=$(dirname "$0")/../../../testprogs/blackbox
. "$incdir"/subunit.sh

failed=0

PREFIX_ABS="$(readlink -f "${PREFIX}")"
# Strip from TESTENV the ':local' if present
TESTENV_SUBDIR=${TESTENV%:*}

LOGFILE="${PREFIX_ABS}/${TESTENV_SUBDIR}/logs/log.winbindd"
# Add support for "WINBINDD_DONT_LOG_STDOUT=1"
if [ ! -r "${LOGFILE}" ]; then
	TEST_LOGFILE="${PREFIX_ABS}/${TESTENV_SUBDIR}/winbindd_test.log"
	subunit_start_test "test winbind call depth trace"
	subunit_skip_test "test winbind call depth trace" <<EOF
Test is skipped, we need $LOGFILE but have only $TEST_LOGFILE which is missing debug headers (they are not printed to stdout).
EOF
	exit 0
fi

saved_level=1

get_winbind_loglevel()
{
	s1=$(${SMBCONTROL} "${CONFIGURATION}" winbind debuglevel)
	# We need to get the all level from output like this:
	# "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..."
	# 1. remove PID 664474:
	s2=${s1#PID*: }
	# "all:1 tdb:1 printdrivers:1  lanman:1 smb:1 rpc_parse:1 rpc_srv:1 rpc_cli:1 passdb"
	# 2. remove " tdb:1 printdrivers:1 ..."
	s3=${s2%% *}
	# "all:1"
	# 3. remove "all:"
	saved_level=${s3#all:}
}

# Example of trace line
# [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)
test_winbind_call_depth_trace()
{
	get_winbind_loglevel

	# If loglevel < 10, set it to 10.
	if [ "$saved_level" -lt 10 ]; then
		${SMBCONTROL}  "${CONFIGURATION}" winbind debug 10
	fi

	COUNT1=$(grep -c wb_group_members_send "$LOGFILE")

	id ADDOMAIN/alice
	ret=$?

	# Restore loglevel, if it was changed.
	if [ "$saved_level" -lt 10 ]; then
		${SMBCONTROL} "${CONFIGURATION}" winbind debug "$saved_level"
	fi

	if [ $ret != 0 ]; then
		echo "Command 'id ADDOMAIN/alice' failed!"
		return 1
	fi

	# Check that there are more lines with wb_group_members_send
	COUNT2=$(grep -c wb_group_members_send "$LOGFILE")
	if [ "$COUNT1" -eq "$COUNT2" ]; then
		echo "The number of the trace lines in $LOGFILE has not increased."
		return 1
	fi

	# Test that the depth of last line with 'wb_group_members_send' is: depth=4
	COUNT3=$(grep wb_group_members_send "$LOGFILE" | tail -1 | grep -c depth=4)
	if [ "$COUNT3" -ne 1 ]; then
		echo "The last line with wb_group_members_send should have depth=4."
		return 1
	fi

	# Test that the indentation of the line below last 'wb_group_members_send' is indented by 2+4*4 spaces:
	COUNT4=$(grep -A1 wb_group_members_send "$LOGFILE" | tail -1| grep -c '^                  WB command group_members start')
	if [ "$COUNT4" -ne 1 ]; then
		echo "The line after the last line with wb_group_members_send should be indented by 18 spaces."
		return 1
	fi

	return 0
}

case ${TESTENV} in
ad_member*)
	;;
*)
	echo "Test is for ad_member only, but called for ${TESTENV}." | subunit_fail_test "test winbind call depth trace"
	exit 1;
esac

testit "test winbind call depth trace"  test_winbind_call_depth_trace || failed=$((failed + 1))
testok "$0" "$failed"