mirror of
https://github.com/servalproject/serval-dna.git
synced 2024-12-27 08:32:33 +00:00
ec481e5f0f
Because Android <stdio.h> defines 'stderr' as a macro...
201 lines
7.5 KiB
Bash
Executable File
201 lines
7.5 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
# Tests for Serval DNA logging.
|
|
#
|
|
# Copyright 2013 Serval Project, Inc.
|
|
#
|
|
# This program is free software; you can redistribute it and/or
|
|
# modify it under the terms of the GNU General Public License
|
|
# as published by the Free Software Foundation; either version 2
|
|
# of the License, or (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with this program; if not, write to the Free Software
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
source "${0%/*}/../testframework.sh"
|
|
source "${0%/*}/../testdefs.sh"
|
|
|
|
setup() {
|
|
setup_servald
|
|
}
|
|
|
|
doc_LogStderrDefault="By default, only errors and warnings are logged to stderr"
|
|
test_LogStderrDefault() {
|
|
execute $servald log error 'hoopla'
|
|
assertExitStatus '==' 0
|
|
assertStderrGrep --matches=1 '^ERROR:.*hoopla$'
|
|
executeOk_servald log warn 'buckle'
|
|
assertStderrGrep --matches=1 '^WARN:.*buckle$'
|
|
executeOk_servald log info 'lymph'
|
|
assertStderrGrep --matches=0 'lymph'
|
|
executeOk_servald log debug 'eccles'
|
|
assertStderrGrep --matches=0 'eccles'
|
|
}
|
|
|
|
doc_LogStderrConfigAll="Configure all messages logged to stderr"
|
|
test_LogStderrConfigAll() {
|
|
executeOk_servald config set log.console.level debug
|
|
execute $servald log error 'hoopla'
|
|
assertExitStatus '==' 0
|
|
assertStderrGrep --matches=1 '^ERROR:.*hoopla$'
|
|
executeOk_servald log warn 'buckle'
|
|
assertStderrGrep --matches=1 '^WARN:.*buckle$'
|
|
executeOk_servald log info 'lymph'
|
|
assertStderrGrep --matches=1 'INFO:.*lymph$'
|
|
executeOk_servald log debug 'eccles'
|
|
assertStderrGrep --matches=1 'DEBUG:.*eccles$'
|
|
}
|
|
|
|
doc_LogStderrConfigNone="Configure no messages logged to stderr"
|
|
test_LogStderrConfigNone() {
|
|
executeOk_servald config set log.console.level none
|
|
executeOk_servald log error 'hoopla'
|
|
assertStderrIs ''
|
|
executeOk_servald log warn 'buckle'
|
|
assertStderrIs ''
|
|
executeOk_servald log info 'lymph'
|
|
assertStderrIs ''
|
|
executeOk_servald log debug 'eccles'
|
|
assertStderrIs ''
|
|
}
|
|
|
|
doc_LogFileDefault="By Default, all messages are appended to a configured file"
|
|
test_LogFileDefault() {
|
|
executeOk_servald config set log.console.level none
|
|
executeOk_servald config set log.file.path "$PWD/log.txt"
|
|
executeOk_servald log error 'hoopla'
|
|
assertGrep --matches=1 log.txt '^ERROR:.*hoopla$'
|
|
executeOk_servald log warn 'buckle'
|
|
assertGrep --matches=1 log.txt '^ERROR:.*hoopla$'
|
|
assertGrep --matches=1 log.txt '^WARN:.*buckle$'
|
|
executeOk_servald log info 'lymph'
|
|
assertGrep --matches=1 log.txt '^ERROR:.*hoopla$'
|
|
assertGrep --matches=1 log.txt '^WARN:.*buckle$'
|
|
assertGrep --matches=1 log.txt 'INFO:.*lymph$'
|
|
executeOk_servald log debug 'eccles'
|
|
assertGrep --matches=1 log.txt '^ERROR:.*hoopla$'
|
|
assertGrep --matches=1 log.txt '^WARN:.*buckle$'
|
|
assertGrep --matches=1 log.txt 'INFO:.*lymph$'
|
|
assertGrep --matches=1 log.txt 'DEBUG:.*eccles$'
|
|
}
|
|
|
|
doc_LogFileConfigLevel="Configure level of messages appended to a configured file"
|
|
test_LogFileConfigLevel() {
|
|
executeOk_servald config set log.console.level none
|
|
executeOk_servald config set log.file.level info
|
|
executeOk_servald config set log.file.path "$PWD/log.txt"
|
|
executeOk_servald log warn 'buckle'
|
|
assertGrep --matches=1 log.txt '^WARN:.*buckle$'
|
|
executeOk_servald log debug 'eccles'
|
|
assertGrep --matches=1 log.txt '^WARN:.*buckle$'
|
|
assertGrep --matches=0 log.txt 'DEBUG:.*eccles$'
|
|
executeOk_servald log error 'hoopla'
|
|
assertGrep --matches=1 log.txt '^WARN:.*buckle$'
|
|
assertGrep --matches=0 log.txt 'DEBUG:.*eccles$'
|
|
assertGrep --matches=1 log.txt '^ERROR:.*hoopla$'
|
|
executeOk_servald log info 'lymph'
|
|
assertGrep --matches=1 log.txt '^WARN:.*buckle$'
|
|
assertGrep --matches=0 log.txt 'DEBUG:.*eccles$'
|
|
assertGrep --matches=1 log.txt '^ERROR:.*hoopla$'
|
|
assertGrep --matches=1 log.txt 'INFO:.*lymph$'
|
|
}
|
|
|
|
doc_LogFileStderrFile="Log messages to stderr and a configured file"
|
|
test_LogFileStderrFile() {
|
|
executeOk_servald config set log.file.path "$PWD/log.txt"
|
|
executeOk_servald log info 'lymph'
|
|
assertGrep --matches=1 log.txt 'INFO:.*lymph$'
|
|
assertStderrIs ''
|
|
executeOk_servald log warn 'buckle'
|
|
assertGrep --matches=1 log.txt 'INFO:.*lymph$'
|
|
assertGrep --matches=1 log.txt '^WARN:.*buckle$'
|
|
assertStderrGrep --matches=1 '^WARN:.*buckle$'
|
|
executeOk_servald log debug 'eccles'
|
|
assertStderrIs ''
|
|
assertGrep --matches=1 log.txt 'INFO:.*lymph$'
|
|
assertGrep --matches=1 log.txt '^WARN:.*buckle$'
|
|
assertGrep --matches=1 log.txt 'DEBUG:.*eccles$'
|
|
execute $servald log error 'hoopla'
|
|
assertExitStatus '==' 0
|
|
assertStderrGrep --matches=1 '^ERROR:.*hoopla$'
|
|
assertGrep --matches=1 log.txt 'INFO:.*lymph$'
|
|
assertGrep --matches=1 log.txt '^WARN:.*buckle$'
|
|
assertGrep --matches=1 log.txt 'DEBUG:.*eccles$'
|
|
assertGrep --matches=1 log.txt '^ERROR:.*hoopla$'
|
|
}
|
|
|
|
doc_LogFileRotation="Log file rotation and deletion"
|
|
test_LogFileRotation() {
|
|
executeOk_servald config \
|
|
set log.file.directory_path "$PWD" \
|
|
set log.file.rotate 3 \
|
|
set log.file.duration 2s
|
|
assert --message="no log files yet" [ $(ls *.log | wc -l) -eq 0 ]
|
|
executeOk_servald log info one
|
|
assert --message="one log file" [ $(ls *.log | wc -l) -eq 1 ]
|
|
log1=*.log
|
|
sleep 2.1
|
|
executeOk_servald log info two
|
|
assert --message="two log files" [ $(ls *.log | wc -l) -eq 2 ]
|
|
log2=$(ls *.log | tail -n 1)
|
|
assert --message="ascending log file name" [ "$log2" != "$log1" ]
|
|
sleep 2.1
|
|
executeOk_servald log info three
|
|
assert --message="three log files" [ $(ls *.log | wc -l) -eq 3 ]
|
|
log3=$(ls *.log | tail -n 1)
|
|
assert --message="ascending log file name" [ "$log3" != "$log1" -a "$log3" != "$log2" ]
|
|
sleep 2.1
|
|
executeOk_servald log info four
|
|
assert --message="three log files" [ $(ls *.log | wc -l) -eq 3 ]
|
|
assert --message="first log file gone" ! [ -e $log1 ]
|
|
log4=$(ls *.log | tail -n 1)
|
|
assert --message="ascending log file name" [ "$log4" != "$log2" -a "$log4" != "$log3" -a "$log4" != "$log1" ]
|
|
}
|
|
|
|
doc_LogFileDirectoryAbsolute="Absolute log file directory path"
|
|
test_LogFileDirectoryAbsolute() {
|
|
executeOk_servald config \
|
|
set debug.verbose true \
|
|
set log.file.directory_path "$PWD/wakawaka"
|
|
executeOk_servald echo one
|
|
assert --message="exactly one log file" [ $(ls -d wakawaka/*.log | wc -l) -eq 1 ]
|
|
assertGrep wakawaka/*.log '^DEBUG:.*echo:argv\[1\]="one"$'
|
|
}
|
|
|
|
doc_LogFileDirectoryRelative="Relative log file directory path"
|
|
test_LogFileDirectoryRelative() {
|
|
executeOk_servald config \
|
|
set debug.verbose true \
|
|
set log.file.directory_path "blah"
|
|
executeOk_servald echo one
|
|
assert --message="exactly one log file" [ $(ls -d "$SERVALINSTANCE_PATH/blah/"*.log | wc -l) -eq 1 ]
|
|
assertGrep "$SERVALINSTANCE_PATH/blah/"*.log '^DEBUG:.*echo:argv\[1\]="one"$'
|
|
}
|
|
|
|
doc_LogFileAbsolute="Absolute log file path"
|
|
test_LogFileAbsolute() {
|
|
executeOk_servald config \
|
|
set debug.verbose true \
|
|
set log.file.path "$PWD/log.txt"
|
|
executeOk_servald echo one
|
|
assertGrep log.txt '^DEBUG:.*echo:argv\[1\]="one"$'
|
|
}
|
|
|
|
doc_LogFileRelative="Relative log file path"
|
|
test_LogFileRelative() {
|
|
executeOk_servald config \
|
|
set debug.verbose true \
|
|
set log.file.directory_path "$PWD" \
|
|
set log.file.path "log.txt"
|
|
executeOk_servald echo one
|
|
assertGrep log.txt '^DEBUG:.*echo:argv\[1\]="one"$'
|
|
}
|
|
|
|
runTests "$@"
|