3 # Copyright (C) 2013 The Android Open Source Project
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
17 # Test for warn_collector. Run the warn collector in the background, emulate
18 # the kernel by appending lines to the log file "messages", and observe the log
19 # of the (fake) crash reporter each time is run by the warn collector daemon.
24 printf '[ FAIL ] %b\n' "$*"
28 if [[ -z ${SYSROOT} ]]; then
29 fail "SYSROOT must be set for this test to work"
34 TESTLOG="${OUT}/warn-test-log"
36 echo "Testing: $(which warn_collector)"
39 # Kill daemon (if started) on exit
45 if [[ ! -f ${TESTLOG} ]]; then
46 fail "${TESTLOG} was not created"
48 if [[ $(wc -l < "${TESTLOG}") -ne ${n_expected} ]]; then
49 fail "expected ${n_expected} lines in ${TESTLOG}, found this instead:
52 if egrep -qv '^[0-9a-f]{8}' "${TESTLOG}"; then
53 fail "found bad lines in ${TESTLOG}:
59 cp "${SRC}/warn_collector_test_reporter.sh" .
60 cp "${SRC}/TEST_WARNING" .
61 cp TEST_WARNING messages
63 # Start the collector daemon. With the --test option, the daemon reads input
64 # from ./messages, writes the warning into ./warning, and invokes
65 # ./warn_collector_test_reporter.sh to report the warning.
66 warn_collector --test &
69 # After a while, check that the first warning has been collected.
73 # Add the same warning to messages, verify that it is NOT collected
74 cat TEST_WARNING >> messages
78 # Add a slightly different warning to messages, check that it is collected.
79 sed s/intel_dp.c/intel_xx.c/ < TEST_WARNING >> messages
83 # Emulate log rotation, add a warning, and check.
84 mv messages messages.1
85 sed s/intel_dp.c/intel_xy.c/ < TEST_WARNING > messages