swtpm/tests/test_common
Stefan Berger 89d85f9a93 test: Add --log parameter to test logging
Add the --log parameter to test log levels 1 and 20.

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
2017-02-03 15:15:31 -05:00

58 lines
1.1 KiB
Plaintext

# For the license, see the LICENSE file in the root directory.
function wait_for_file()
{
local filename="$1"
local timeout="$2"
local loops=$((timeout * 10)) loop
for ((loop=0; loop<loops; loop++)); do
[ -f "${filename}" ] && return 1
sleep 0.1
done
return 0
}
function check_logfile_patterns_level_20()
{
local logfile="$1"
for pattern in \
"^ [[:print:]]+$" \
"^ [[:print:]]+$" \
"^ [[:print:]]+$" \
"^ [[:print:]]+$" \
"^ [[:print:]]+$" \
"^ [[:print:]]+$" \
"^ [[:print:]]+$" \
; do
shift
ctr=$(grep -E "${pattern}" $logfile | wc -l)
if [ $ctr -eq 0 ]; then
echo "Counted $ctr occurrences of pattern '${pattern}' in logfile; expected at least 1"
exit 1
fi
echo "'${pattern}' occurrences: $ctr (OK)"
done
}
function check_logfile_patterns_level_1()
{
local logfile="$1"
local minocc="$2"
for pattern in \
"^[[:print:]]+$" \
; do
shift
ctr=$(grep -E "${pattern}" $logfile | wc -l)
if [ $ctr -lt $minocc ]; then
echo "Counted $ctr occurrences of pattern '${pattern}' in logfile; expected at least $minocc"
exit 1
fi
echo "'${pattern}' occurrences: $ctr (OK)"
done
}