]>
Commit | Line | Data |
---|---|---|
96d57912 JT |
1 | #!/bin/sh |
2 | # Simple test that compiles and runs ircd, verifying that certain aspects of | |
3 | # PRIVMSG work. | |
4 | ||
5 | case $# in | |
6 | 1) ;; | |
7 | *) printf 'Usage: %s tarball\n' "$0" >&2; exit 64 ;; | |
8 | esac | |
9 | cr=$(printf '\r') | |
10 | rc=0 ircdpid= tarball=${1:?} | |
11 | case $tarball in | |
12 | /*) ;; | |
13 | *) tarball=$PWD/$tarball ;; | |
14 | esac | |
15 | dir=$(mktemp -d "${TMPDIR:-/tmp}/ircdtest.XXXXXXXXXX") || exit 2 | |
16 | trap '[ -z "$ircdpid" ] || kill $ircdpid; rm -rf "$dir"' 0 | |
17 | cd "$dir" || exit 2 | |
18 | tar xjf "$tarball" || exit 2 | |
19 | srcdir=${tarball##*/} | |
20 | srcdir=${srcdir%.tbz2} | |
21 | srcdir=${srcdir%.tgz} | |
22 | srcdir=${srcdir%.tar.*} | |
23 | srcdir=${srcdir%.tar} | |
24 | cd "$srcdir" || exit 2 | |
25 | prefix=$dir/prefix | |
26 | ./configure --prefix="$prefix" >"$dir/out" 2>&1 || { cat "$dir/out"; exit 2; } | |
27 | make -j2 >"$dir/out" 2>&1 || { cat "$dir/out"; exit 2; } | |
28 | make install >"$dir/out" 2>&1 || { cat "$dir/out"; exit 2; } | |
29 | cd "$prefix" || exit 2 | |
30 | servername=smoke$(date +%Y%m%d%H%M%S).test | |
31 | port=$(date +50%S) | |
32 | sed -e '/^serverinfo/,/^}/s/name = ".*";/name = "'"$servername"'";/' \ | |
33 | -e '/^listen/,/^}/s/port = .*;/port = '"$port"';/' \ | |
bdad42f0 | 34 | -e '/^blacklist/,/^}/s/^/#/' \ |
96d57912 JT |
35 | etc/example.conf >etc/ircd.conf || exit 2 |
36 | bin/ircd || exit 2 | |
37 | ircdpid=$(cat etc/ircd.pid) || exit 2 | |
38 | cd "$dir" || exit 2 | |
39 | echo "Will use servername $servername port $port, pid is $ircdpid" | |
40 | { | |
41 | echo 'USER testu . . :Test user' | |
42 | echo 'NICK test1' | |
43 | sleep 1 | |
44 | echo 'JOIN #test' | |
45 | sleep 1 | |
46 | echo "PRIVMSG #test :channel message via $servername" | |
47 | echo "PRIVMSG @#test :chanops 1 via $servername" | |
48 | echo "MODE #test +o test2" | |
49 | echo "PRIVMSG @#test :chanops 2 via $servername" | |
50 | sleep 1 | |
51 | echo "QUIT" | |
52 | } | nc 127.0.0.1 "$port" >out1 & | |
53 | { | |
54 | echo 'NICK test2' | |
55 | echo 'USER testu2 . . :Test user' | |
56 | sleep 1 | |
57 | echo 'JOIN #test' | |
58 | echo "PRIVMSG test1 :private message via $servername" | |
59 | sleep 2 | |
60 | echo "QUIT :Bye" | |
61 | } | nc 127.0.0.1 "$port" >out2 & | |
62 | wait | |
63 | if ! grep -q "^:$servername 001 test1 :" out1; then | |
64 | echo "FAIL: Missing 001 in out1 or wrong server" | |
65 | rc=1 | |
66 | fi | |
67 | if ! grep -q "^:$servername 001 test2 :" out2; then | |
68 | echo "FAIL: Missing 001 in out2 or wrong server" | |
69 | rc=1 | |
70 | fi | |
71 | if ! grep -q "^:test2!.*@.* PRIVMSG test1 :private message via $servername$cr\$" out1; then | |
72 | echo "FAIL: Missing private message in out1" | |
73 | rc=1 | |
74 | fi | |
75 | if ! grep -q "^:test1!.*@.* PRIVMSG #test :channel message via $servername$cr\$" out2; then | |
76 | echo "FAIL: Missing channel message in out2" | |
77 | rc=1 | |
78 | fi | |
79 | if grep -q "chanops 1 via" out2; then | |
80 | echo "FAIL: Wrong chanops message in out2" | |
81 | rc=1 | |
82 | fi | |
83 | if ! grep -q "^:test1!.* MODE #test +o test2[[:space:]]*$cr\$" out1; then | |
84 | echo "FAIL: Missing mode in out1" | |
85 | rc=1 | |
86 | fi | |
87 | if ! grep -q "^:test1!.* MODE #test +o test2[[:space:]]*$cr\$" out2; then | |
88 | echo "FAIL: Missing mode in out2" | |
89 | rc=1 | |
90 | fi | |
91 | if ! grep -q "^:test1!.* PRIVMSG @#test :chanops 2 via $servername$cr\$" out2; then | |
92 | echo "FAIL: Missing chanops message in out2" | |
93 | rc=1 | |
94 | fi | |
95 | if [ "$rc" -ne 0 ] && [ -t 0 ] && [ -t 1 ] && [ -t 2 ]; then | |
96 | echo 'Starting shell for investigation...' | |
97 | PS1='ircd-smoketest$ ' sh -i | |
98 | fi | |
99 | if [ "$rc" -eq 0 ]; then | |
100 | echo 'PASS' | |
101 | fi | |
102 | exit $rc |