File: common

package info (click to toggle)
syncmaildir 1.2.5-1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 1,104 kB
  • sloc: ansic: 6,643; sh: 1,780; makefile: 247
file content (177 lines) | stat: -rw-r--r-- 3,799 bytes parent folder | download
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#!/bin/bash
#
# BASE: where you can run make/make install
# TESTSUITE: client-server, pull-push

#set -x
VALGRIND=${VALGRIND:-"valgrind --log-file=log.valgrind --leak-check=no --error-exitcode=1 --"}

ROOT=$BASE/tests.d/run/$TESTSUITE/

TOKILL=""

if [ ! -z "$VALGRIND" ]; then
	if which valgrind >/dev/null 2>&1; then
	       :
      	else
		echo 'VALGRIND set but not installed. Disabling it'
		VALGRIND=
	fi
fi

out(){
	(
	for P in $TOKILL; do
		kill $P
	done
	) 2>/dev/null
}

trap out EXIT

test_eq(){
	if diff -ruN "$1" "$2" >/dev/null; then
		echo -n .
	else
		echo ERROR: diff
		exit 1
	fi
}

run_server(){
	HOME=$ROOT/$TESTSUITE/$__N__/ \
	PATH=$ROOT/$TESTSUITE/$__N__/bin:$PATH \
	LUA_INIT="package.path='$ROOT/$TESTSUITE/$__N__/share/lua/5.1/?.lua;'" \
		smd-server -v test Mail < c2s 2> log.server.$1 \
		| tee log.s2c > s2c &
	RC=$!
	TOKILL="$TOKILL $RC"
}

run_client(){
	rm -rf target/.smd/workarea/
	mkdir -p target/.smd/workarea/
	cd target/.smd/workarea/
	local DD=../../../
	HOME=$ROOT/$TESTSUITE/$__N__/target \
	PATH=$ROOT/$TESTSUITE/$__N__/bin:$PATH \
	LUA_INIT="package.path='$ROOT/$TESTSUITE/$__N__/share/lua/5.1/?.lua;'" \
		smd-client -t 'cat' -v \
		test Mail < $DD/s2c 2> $DD/log.client.$1 \
		| tee $DD/log.c2s > $DD/c2s &
	RC=$!
	TOKILL="$TOKILL $RC"
	cd $DD
}

msync(){
	run_server $__N__
	local SERVER=$RC
	run_client $__N__
	local CLIENT=$RC
	
	wait $SERVER
	wait $CLIENT
}

mpull(){
	LUA_INIT="package.path='$ROOT/$TESTSUITE/$__N__/share/lua/5.1/?.lua;'" \
	HOME=$ROOT/$TESTSUITE/$__N__/target \
	PATH=$ROOT/$TESTSUITE/$__N__/bin:$PATH \
	HOMES=$ROOT/$TESTSUITE/$__N__/ \
		$ROOT/$TESTSUITE/$__N__/bin/smd-pull "$@" > log.pull 2>&1
}

mpush(){
	LUA_INIT="package.path='$ROOT/$TESTSUITE/$__N__/share/lua/5.1/?.lua;'" \
	HOME=$ROOT/$TESTSUITE/$__N__/target \
	PATH=$ROOT/$TESTSUITE/$__N__/bin:$PATH \
	HOMES=$ROOT/$TESTSUITE/$__N__/ \
		$ROOT/$TESTSUITE/$__N__/bin/smd-push "$@" > log.push 2>&1
}

mdiff(){
	LUA_INIT="package.path='$ROOT/$TESTSUITE/$__N__/share/lua/5.1/?.lua;'" \
	PATH=$ROOT/$TESTSUITE/$__N__/bin:$PATH \
	HOME=$ROOT/$TESTSUITE/$__N__/ \
		$VALGRIND $ROOT/$TESTSUITE/$__N__/bin/mddiff "$@" > log.mddiff 2>&1
}

mcheck(){
	PATH=$ROOT/$TESTSUITE/$__N__/bin:$PATH \
	HOME=$ROOT/$TESTSUITE/$__N__/target/ \
	HOMES=$ROOT/$TESTSUITE/$__N__/ \
		$ROOT/$TESTSUITE/$__N__/bin/smd-check-conf "$@" > log.check 2>&1
}

muniform(){
	LUA_INIT="package.path='$ROOT/$TESTSUITE/$__N__/share/lua/5.1/?.lua;'" \
	HOME=$ROOT/$TESTSUITE/$__N__/target \
	PATH=$ROOT/$TESTSUITE/$__N__/bin:$PATH \
	HOMES=$ROOT/$TESTSUITE/$__N__/ \
		$ROOT/$TESTSUITE/$__N__/bin/smd-uniform-names "$@" \
		> log.uniform 2>&1

}

assert(){
	if [ "$1" = "$2" ]; then
		echo -n '.'
	else
		echo 'ERROR: ' $3
		exit 1
	fi
}

prepare(){
	local testcase=$1
	local __N__=$2

	cd $BASE
	rm -rf $ROOT/$TESTSUITE/$__N__
	mkdir -p $ROOT/$TESTSUITE/$__N__/target
	make --no-print-directory --quiet text/all
	make --no-print-directory --quiet text/install-bin \
		SSH=$ROOT/$TESTSUITE/$__N__/bin/fakessh \
		PREFIX=$ROOT/$TESTSUITE/$__N__

	cd $ROOT/$TESTSUITE/$__N__
	cat > bin/fakessh <<-EOT
	#!/bin/sh
	shift
	cd \$HOMES
	HOME=\$HOMES "\$@"
	EOT
	chmod a+x bin/fakessh
	tar -xzf $BASE/$testcase
	mkfifo s2c
	mkfifo c2s
	mkdir -p .smd/fifo/
	mkdir -p target/.smd/fifo/
}

run_test() {
	local testcase="$1"
	local T="$2"
	echo -n "running $TESTSUITE/`basename $T`: "
	local __N__=`echo $T | sed 's/^[^0-9]*\([0-9][0-9]*\).*$/\1/'`
	prepare $testcase $__N__
	cd $ROOT/$TESTSUITE/$__N__
	. $T
	echo OK
}

run_tests() {
	local testcase="$1"
	local testfile="$2"
	if [ ! -z "$testfile" ]; then
		if [ -f $testfile ] && 
		   (echo $testfile | grep $TESTSUITE > /dev/null); then
			run_test $testcase $testfile
		fi
	else
		for T in $BASE/tests.d/$TESTSUITE/[0-9]*; do
			run_test $testcase $T
		done
	fi
}