OSDN Git Service

Merge \\\\\"DO NOT MERGE: debuggerd: verify that traced threads belong to the right...
[android-x86/system-core.git] / crash_reporter / warn_collector_test.sh
1 #! /bin/bash
2
3 # Copyright (C) 2013 The Android Open Source Project
4 #
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
8 #
9 #      http://www.apache.org/licenses/LICENSE-2.0
10 #
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.
16
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.
20
21 set -e
22
23 fail() {
24   printf '[ FAIL ] %b\n' "$*"
25   exit 1
26 }
27
28 if [[ -z ${SYSROOT} ]]; then
29   fail "SYSROOT must be set for this test to work"
30 fi
31 : ${OUT:=${PWD}}
32 cd "${OUT}"
33 PATH=${OUT}:${PATH}
34 TESTLOG="${OUT}/warn-test-log"
35
36 echo "Testing: $(which warn_collector)"
37
38 cleanup() {
39   # Kill daemon (if started) on exit
40   kill %
41 }
42
43 check_log() {
44   local n_expected=$1
45   if [[ ! -f ${TESTLOG} ]]; then
46     fail "${TESTLOG} was not created"
47   fi
48   if [[ $(wc -l < "${TESTLOG}") -ne ${n_expected} ]]; then
49     fail "expected ${n_expected} lines in ${TESTLOG}, found this instead:
50 $(<"${TESTLOG}")"
51   fi
52   if egrep -qv '^[0-9a-f]{8}' "${TESTLOG}"; then
53     fail "found bad lines in ${TESTLOG}:
54 $(<"${TESTLOG}")"
55   fi
56 }
57
58 rm -f "${TESTLOG}"
59 cp "${SRC}/warn_collector_test_reporter.sh" .
60 cp "${SRC}/TEST_WARNING" .
61 cp TEST_WARNING messages
62
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 &
67 trap cleanup EXIT
68
69 # After a while, check that the first warning has been collected.
70 sleep 1
71 check_log 1
72
73 # Add the same warning to messages, verify that it is NOT collected
74 cat TEST_WARNING >> messages
75 sleep 1
76 check_log 1
77
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
80 sleep 1
81 check_log 2
82
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
86 sleep 2
87 check_log 3
88
89 # Success!
90 exit 0