summaryrefslogtreecommitdiffstats
path: root/test/run_unit.sh.in
blob: 10ee948de973573c0f5efe3bd5614f67dfac8300 (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
114
115
116
117
118
119
120
121
122
123
124
125
#!/usr/bin/env bash
#
# DO NOT EDIT - this file is generated from run_unit.sh.in.
#

cmd_line="$0 $@"

# substituted variables in one place:
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
abs_top_builddir="${DIR}/.."
systemplate_path="@SYSTEMPLATE_PATH@"
enable_debug="@ENABLE_DEBUG@"
if test -z "@ENABLE_SETCAP@"; then
    capabilities=false
else
    capabilities=true
fi
jails_path="@JAILS_PATH@"
lo_path="@LO_PATH@"
valgrind_cmd="valgrind --tool=memcheck --trace-children=no -v --read-var-info=yes"
verbose=''
capabilities="@ENABLE_SETCAP@"
fail_fast=''

if test "h$capabilities" != "htrue"; then
    capabilities=false
fi

# Note that these options are used by commands in the Makefile that
# Automake generates. Don't be mislead by 'git grep' not showing any
# use of --test-name for instance.

print_help ()
{
    echo "Usage: run_unit.sh --test-name <name.la> [OPTIONS]"
    echo "Runs a specified unit test"
    echo ""
    echo "   --log-file <file>   Log output to this file - default /dev/stderr"
    echo "   --trs-file <file>   Records the results of a test for automake (default /dev/stderr)"
    echo "   --gdb               Run under gdb if enabled"
    echo "   --valgrind          Run under valgrind if enabled"
    echo "   --fail-fast         If a test fails, subsequent tests will not run and no report is generated"
    echo "   --verbose           Print out more stuff - if you run out of things to read"
    exit 1
}

tst=
tst_log=/dev/stderr
tst_output=/dev/stderr
while test $# -gt 0; do
  case $1 in
      --test-name) tst=$2; shift;;
      --log-file)  tst_log=$2; shift;;
      --trs-file)  test_output=$2; shift;;
      --gdb)       trace='gdb --args'; shift;;
      --valgrind)  trace=$valgrind_cmd; shift;;
      --fail-fast) fail_fast='true'; shift;;
      --verbose)   verbose="--verbose";;
      --help)      print_help ;;
  -*) ;; # ignore
  esac
  shift
done

if test "z$enable_debug" != "ztrue"; then
    echo ""
    echo "It is necessary to configure with --enable-debug for unit tests to pass"
    echo ""
    echo ":test-result: FAIL $tst" > $test_output
    exit 1;
fi

# drop .la suffix
tst=`echo $tst | sed "s/\.la//"`;

# result logging
echo > $test_output

printf "\nRunning $tst | $tst_log | $test_output $cmd_line\n";
echo > $tst_log
if ${trace} \
       ${abs_top_builddir}/coolwsd --o:sys_template_path="$systemplate_path" \
				   --o:child_root_path="$jails_path" \
				   --o:security.capabilities="${capabilities}" \
				   --o:storage.filesystem[@allow]=true \
				   --o:logging.level=trace \
				   --o:ssl.key_file_path="${abs_top_builddir}/etc/key.pem" \
				   --o:ssl.cert_file_path="${abs_top_builddir}/etc/cert.pem" \
				   --o:ssl.ca_file_path="${abs_top_builddir}/etc/ca-chain.cert.pem" \
				   --o:admin_console.username=admin --o:admin_console.password=admin \
				   --o:storage.ssl.enable=false \
				   --o:experimental_features=true \
				   --unattended \
				   --unitlib="${abs_top_builddir}/test/.libs/$tst.so" 2> "$tst_log" 1>&2; then
	echo "Test $tst passed. Finished in ${SECONDS}s."
	echo ":test-result: PASS $tst" >> $test_output
	exit 0
else
	echo "Test $tst FAILED. Finished in ${SECONDS}s."
	cat $tst_log
	echo "============================================================="
	echo "Test failed on $tst after ${SECONDS}s. Re-run with (remove --unattended to run without gdb and get prompted):"
	echo "   $ gdb --args ${abs_top_builddir}/coolwsd --o:sys_template_path=\"$systemplate_path\" \\"
	echo "         --o:child_root_path=\"$jails_path\" \\"
	echo "         --o:security.capabilities=\"${capabilities}\" \\"
	echo "         --o:storage.filesystem[@allow]=true \\"
	echo "         --o:logging.level=error\\" # logs and gdb don't go well together
	echo "         --o:ssl.key_file_path=\"${abs_top_builddir}/etc/key.pem\" \\"
	echo "         --o:ssl.cert_file_path=\"${abs_top_builddir}/etc/cert.pem\" \\"
	echo "         --o:ssl.ca_file_path=\"${abs_top_builddir}/etc/ca-chain.cert.pem\" \\"
	echo "         --o:admin_console.username=admin --o:admin_console.password=admin \\"
	echo "         --o:storage.ssl.enable=false \\"
	echo "         --unattended \\"
	echo "         --unitlib=\"${abs_top_builddir}/test/.libs/$tst.so\""
	echo ""
	echo "   $ less $tst_log # for detailed failure log files"
	echo "============================================================="
	echo ":test-result: FAIL $tst" >> $test_output
fi

if test "z$fail_fast" == "ztrue"; then
    exit 1
fi

# vim:set shiftwidth=4 expandtab: