mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-28 06:13:31 +01:00
test/parseconf: Add an expected_log file
The "expected_log" file is a set of patterns that matches the output of "tor --verify-config". Unlike "error", it expects a successful exit status. Part of 32451.
This commit is contained in:
parent
4cf5d4cb3c
commit
3df6432006
@ -8,11 +8,16 @@
|
|||||||
# Valid configurations are tested with --dump-config, which parses and
|
# Valid configurations are tested with --dump-config, which parses and
|
||||||
# validates the configuration before writing it out. We then make sure that
|
# validates the configuration before writing it out. We then make sure that
|
||||||
# the result is what we expect, before parsing and dumping it again to make
|
# the result is what we expect, before parsing and dumping it again to make
|
||||||
# sure that there is no change.
|
# sure that there is no change. Optionally, we can also test the log messages
|
||||||
|
# with --verify-config.
|
||||||
#
|
#
|
||||||
# Invalid configurations are tested with --verify-config, which parses
|
# Invalid configurations are tested with --verify-config, which parses
|
||||||
# and validates the configuration. We capture its output and make sure that
|
# and validates the configuration. We capture its output and make sure that
|
||||||
# it contains the error message we expect.
|
# it contains the error message we expect.
|
||||||
|
#
|
||||||
|
# When tor is compiled with different libraries or modules, some
|
||||||
|
# configurations may have different results. We can specify these result
|
||||||
|
# variants using additional result files.
|
||||||
|
|
||||||
# This script looks for its test cases as individual directories in
|
# This script looks for its test cases as individual directories in
|
||||||
# src/test/conf_examples/. Each test may have these files:
|
# src/test/conf_examples/. Each test may have these files:
|
||||||
@ -41,33 +46,42 @@
|
|||||||
# of "--dump-config short" for this test case. Exactly one of
|
# of "--dump-config short" for this test case. Exactly one of
|
||||||
# "expected" or "error" must be present, or the test will fail.
|
# "expected" or "error" must be present, or the test will fail.
|
||||||
#
|
#
|
||||||
|
# expected_log -- Optional. If this file is present, then it contains a regex
|
||||||
|
# that must be matched by some line in the output of "--verify-config",
|
||||||
|
# which must succeed. Only used if "expected" is also present.
|
||||||
|
#
|
||||||
# error -- If this file is present, then it contains a regex that must be
|
# error -- If this file is present, then it contains a regex that must be
|
||||||
# matched by some line in the output of "--verify-config", which must
|
# matched by some line in the output of "--verify-config", which must
|
||||||
# fail. Exactly one of "expected" or "error" must be present, or the
|
# fail. Exactly one of "expected" or "error" must be present, or the
|
||||||
# test will fail.
|
# test will fail.
|
||||||
#
|
#
|
||||||
# {expected,error}_${TOR_LIBS_ENABLED}* -- If this file is present,
|
# {expected,expected_log,error}_${TOR_LIBS_ENABLED}* -- If this file is
|
||||||
# then the outcome is different when some optional libraries are
|
# present, then the outcome is different when some optional libraries are
|
||||||
# enabled. If there is no result file matching the exact list of enabled
|
# enabled. If there is no result file matching the exact list of enabled
|
||||||
# libraries, the script searches for result files with one or more of
|
# libraries, the script searches for result files with one or more of
|
||||||
# those libraries disabled. The search terminates at the standard result
|
# those libraries disabled. The search terminates at the standard result
|
||||||
# file.
|
# file. If expected* is present, the script also searches for
|
||||||
|
# expected_log*.
|
||||||
#
|
#
|
||||||
# For example:
|
# For example:
|
||||||
# A test that succeeds, regardless of any enabled libraries:
|
# A test that succeeds, regardless of any enabled libraries:
|
||||||
# - expected
|
# - expected
|
||||||
# A test that has a different result if the nss library is enabled
|
# A test that has a different result if the nss library is enabled
|
||||||
# (but the same result if any other library is enabled):
|
# (but the same result if any other library is enabled). We also check
|
||||||
|
# the log output in this test:
|
||||||
# - expected
|
# - expected
|
||||||
|
# - expected_log
|
||||||
# - expected_nss
|
# - expected_nss
|
||||||
|
# - expected_log_nss
|
||||||
# A test that fails if the lzma and zstd modules are *not* enabled:
|
# A test that fails if the lzma and zstd modules are *not* enabled:
|
||||||
# - error
|
# - error
|
||||||
# - expected_lzma_zstd
|
# - expected_lzma_zstd
|
||||||
#
|
#
|
||||||
# {expected,error}*_no_${TOR_MODULES_DISABLED} -- If this file is present,
|
# {expected,expected_log,error}*_no_${TOR_MODULES_DISABLED} -- If this file is
|
||||||
# then the outcome is different when some modules are disabled. If there
|
# present, then the outcome is different when some modules are disabled.
|
||||||
# is no result file matching the exact list of disabled modules, the
|
# If there is no result file matching the exact list of disabled modules,
|
||||||
# standard result file is used.
|
# the standard result file is used. If expected* is present, the script
|
||||||
|
# also searches for expected_log*.
|
||||||
#
|
#
|
||||||
# For example:
|
# For example:
|
||||||
# A test that succeeds, regardless of any disabled modules:
|
# A test that succeeds, regardless of any disabled modules:
|
||||||
@ -225,6 +239,7 @@ for dir in "${EXAMPLEDIR}"/*; do
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
EXPECTED=
|
EXPECTED=
|
||||||
|
EXPECTED_LOG=
|
||||||
ERROR=
|
ERROR=
|
||||||
# Search for a custom result file for any combination of enabled optional
|
# Search for a custom result file for any combination of enabled optional
|
||||||
# libraries
|
# libraries
|
||||||
@ -246,6 +261,9 @@ for dir in "${EXAMPLEDIR}"/*; do
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
EXPECTED="./expected${suffix}"
|
EXPECTED="./expected${suffix}"
|
||||||
|
if test -f "./expected_log${suffix}"; then
|
||||||
|
EXPECTED_LOG="./expected_log${suffix}"
|
||||||
|
fi
|
||||||
break
|
break
|
||||||
|
|
||||||
elif test -f "./error${suffix}"; then
|
elif test -f "./error${suffix}"; then
|
||||||
@ -261,8 +279,17 @@ for dir in "${EXAMPLEDIR}"/*; do
|
|||||||
done
|
done
|
||||||
|
|
||||||
if test -f "$EXPECTED"; then
|
if test -f "$EXPECTED"; then
|
||||||
|
|
||||||
# This case should succeed: run dump-config and see if it does.
|
# This case should succeed: run dump-config and see if it does.
|
||||||
|
FAILED_LOG=
|
||||||
|
FAILED_CONFIG=
|
||||||
|
|
||||||
|
if test -f "$EXPECTED_LOG"; then
|
||||||
|
if ! test -s "$EXPECTED_LOG"; then
|
||||||
|
echo "FAIL: expected log file '$EXPECTED_LOG' is empty." >&2
|
||||||
|
echo "Empty expected log files match any output." >&2
|
||||||
|
FINAL_EXIT=$EXITCODE
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
"${TOR_BINARY}" -f "./torrc" \
|
"${TOR_BINARY}" -f "./torrc" \
|
||||||
--defaults-torrc "${DEFAULTS}" \
|
--defaults-torrc "${DEFAULTS}" \
|
||||||
@ -271,6 +298,7 @@ for dir in "${EXAMPLEDIR}"/*; do
|
|||||||
| "${FILTER}" > "${DATA_DIR}/output.${testname}" \
|
| "${FILTER}" > "${DATA_DIR}/output.${testname}" \
|
||||||
|| die "FAIL: $EXPECTED: Tor reported an error."
|
|| die "FAIL: $EXPECTED: Tor reported an error."
|
||||||
|
|
||||||
|
|
||||||
if cmp "$EXPECTED" "${DATA_DIR}/output.${testname}">/dev/null ; then
|
if cmp "$EXPECTED" "${DATA_DIR}/output.${testname}">/dev/null ; then
|
||||||
# Check round-trip.
|
# Check round-trip.
|
||||||
"${TOR_BINARY}" -f "${DATA_DIR}/output.${testname}" \
|
"${TOR_BINARY}" -f "${DATA_DIR}/output.${testname}" \
|
||||||
@ -286,9 +314,8 @@ for dir in "${EXAMPLEDIR}"/*; do
|
|||||||
echo "FAIL: $EXPECTED did not match on round-trip." >&2
|
echo "FAIL: $EXPECTED did not match on round-trip." >&2
|
||||||
FINAL_EXIT=$EXITCODE
|
FINAL_EXIT=$EXITCODE
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "OK"
|
|
||||||
else
|
else
|
||||||
|
FAILED_CONFIG="yes"
|
||||||
echo "FAIL" >&2
|
echo "FAIL" >&2
|
||||||
if test "$(wc -c < "${DATA_DIR}/output.${testname}")" = 0; then
|
if test "$(wc -c < "${DATA_DIR}/output.${testname}")" = 0; then
|
||||||
# There was no output -- probably we failed.
|
# There was no output -- probably we failed.
|
||||||
@ -303,6 +330,34 @@ for dir in "${EXAMPLEDIR}"/*; do
|
|||||||
FINAL_EXIT=$EXITCODE
|
FINAL_EXIT=$EXITCODE
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if test -f "$EXPECTED_LOG"; then
|
||||||
|
# This case should succeed: run verify-config and see if it does.
|
||||||
|
|
||||||
|
"${TOR_BINARY}" --verify-config \
|
||||||
|
-f ./torrc \
|
||||||
|
--defaults-torrc "${DEFAULTS}" \
|
||||||
|
${CMDLINE} \
|
||||||
|
> "${DATA_DIR}/output_log.${testname}" \
|
||||||
|
|| die "FAIL: $EXPECTED_LOG: Tor reported an error."
|
||||||
|
|
||||||
|
expect_log="$(cat "$EXPECTED_LOG")"
|
||||||
|
if grep "${expect_log}" "${DATA_DIR}/output_log.${testname}" \
|
||||||
|
>/dev/null; then
|
||||||
|
:
|
||||||
|
else
|
||||||
|
FAILED_LOG="yes"
|
||||||
|
echo "FAIL" >&2
|
||||||
|
echo "Expected $EXPECTED_LOG: ${expect_log}" >&2
|
||||||
|
echo "Tor said:" >&2
|
||||||
|
cat "${DATA_DIR}/output_log.${testname}" >&2
|
||||||
|
FINAL_EXIT=$EXITCODE
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if test -z "${FAILED_LOG}${FAILED_CONFIG}"; then
|
||||||
|
echo "OK"
|
||||||
|
fi
|
||||||
|
|
||||||
elif test -f "$ERROR"; then
|
elif test -f "$ERROR"; then
|
||||||
# This case should fail: run verify-config and see if it does.
|
# This case should fail: run verify-config and see if it does.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user