2 ################################################################################
6 # Runs the Privoxy tests based on curl's runtests.pl framework.
8 # Copyright (c) 2021 Fabian Keil <fk@fabiankeil.de>
10 # Permission to use, copy, modify, and distribute this software for any
11 # purpose with or without fee is hereby granted, provided that the above
12 # copyright notice and this permission notice appear in all copies.
14 # THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
15 # WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
16 # MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
17 # ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
18 # WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
19 # ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
20 # OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
21 ################################################################################
23 UPSTREAM_TEST_SCENARIO=upstream-tests
25 # Delaying the test run by a whole second is annoying on fast systems
26 # and may not be long enough on slow systems. There must be a more
27 # elegant method to verify that Privoxy is running or failed to start.
28 SECONDS_TO_WAIT_FOR_PRIVOXY_TO_START=1
31 local test_dir test_scenario
32 local privoxy_config privoxy_binary pid_file
36 privoxy_config_dir="${test_dir}/${test_scenario}"
37 privoxy_binary="$(realpath "${test_dir}/../../privoxy")"
38 pid_file="${test_dir}/${test_scenario}/../privoxy.pid"
39 log_file="${test_dir}/logs/${test_scenario}.log"
42 cd "${privoxy_config_dir}" || exit 1
43 "${privoxy_binary}" --no-daemon \
44 --pidfile "${pid_file}" \
45 privoxy.conf > "${log_file}" 2>&1 || exit 1 &
48 sleep "${SECONDS_TO_WAIT_FOR_PRIVOXY_TO_START}"
50 if [ ! -f "${pid_file}" ]; then
51 echo "Privoxy failed to start or did not start in time"
52 if [ -f "${log_file}" ]; then
53 tail -n 1 "${log_file}"
60 local test_dir test_scenario
64 pid_file="${test_dir}/${test_scenario}/../privoxy.pid"
65 if [ -f "${pid_file}" ]; then
66 kill "$(cat "${pid_file}")"
71 local start_privoxy="$1"
72 local test_scenario="$2"
73 local directory_name="$(dirname "$0")"
74 local test_dir="$(realpath "${directory_name}")"
77 echo "Test scenario: ${test_scenario}"
78 $start_privoxy && start_privoxy "${test_dir}" "${test_scenario}"
80 "${test_dir}/runtests-wrapper.sh" -A -E -t "${test_dir}/${test_scenario}/data" HTTP HTTPS
83 $start_privoxy && stop_privoxy "${test_dir}" "${test_scenario}"
88 run_upstream_tests() {
89 local start_privoxy="$1"
90 local directory_name="$(dirname "$0")"
91 local test_dir="$(realpath "${directory_name}")"
94 echo "Test scenario: ${UPSTREAM_TEST_SCENARIO}"
95 $start_privoxy && start_privoxy "${test_dir}" "${UPSTREAM_TEST_SCENARIO}"
97 "${test_dir}/runtests-wrapper.sh" -A -T HTTP
100 $start_privoxy && stop_privoxy "${test_dir}" "${UPSTREAM_TEST_SCENARIO}"
105 get_test_scenarios() {
106 local directory_name="$(dirname "$0")"
107 local test_dir="$(realpath "${directory_name}")"
111 for privoxy_config in "${test_dir}"/*/privoxy.conf; do
112 test_scenario="${privoxy_config%%/privoxy.conf}"
113 test_scenario="${test_scenario##$test_dir/}"
114 echo "${test_scenario}"
119 local test_scenario=""
120 local test_scenarios=""
121 local start_privoxy=true
127 echo "Not starting privoxy."
137 echo "Invalid parameter: $1"
143 if [ -z "${test_scenarios}" ]; then
144 test_scenarios="$(get_test_scenarios)"
147 for test_scenario in ${test_scenarios}; do
148 if [ "${test_scenario}" = "${UPSTREAM_TEST_SCENARIO}" ]; then
149 run_upstream_tests ${start_privoxy} || exit 1
151 run_privoxy_tests ${start_privoxy} "${test_scenario}" || exit 1