blob: a5af16c7acb1d27aad89570248679682dd525365 [file] [log] [blame]
Luigi Semenzato6fdc0b42013-04-11 17:22:13 -07001#! /bin/bash
Steve Fung6c34c252015-08-20 00:27:30 -07002
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.
Luigi Semenzato6fdc0b42013-04-11 17:22:13 -070016
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
21set -e
22
Mike Frysinger44054a02013-05-22 17:50:39 -040023fail() {
24 printf '[ FAIL ] %b\n' "$*"
25 exit 1
26}
Luigi Semenzato6fdc0b42013-04-11 17:22:13 -070027
Mike Frysinger44054a02013-05-22 17:50:39 -040028if [[ -z ${SYSROOT} ]]; then
29 fail "SYSROOT must be set for this test to work"
30fi
31: ${OUT:=${PWD}}
32cd "${OUT}"
33PATH=${OUT}:${PATH}
34TESTLOG="${OUT}/warn-test-log"
35
36echo "Testing: $(which warn_collector)"
Luigi Semenzato6fdc0b42013-04-11 17:22:13 -070037
38cleanup() {
39 # Kill daemon (if started) on exit
40 kill %
41}
42
43check_log() {
Mike Frysinger44054a02013-05-22 17:50:39 -040044 local n_expected=$1
45 if [[ ! -f ${TESTLOG} ]]; then
46 fail "${TESTLOG} was not created"
Luigi Semenzato6fdc0b42013-04-11 17:22:13 -070047 fi
Mike Frysinger44054a02013-05-22 17:50:39 -040048 if [[ $(wc -l < "${TESTLOG}") -ne ${n_expected} ]]; then
49 fail "expected ${n_expected} lines in ${TESTLOG}, found this instead:
50$(<"${TESTLOG}")"
Luigi Semenzato6fdc0b42013-04-11 17:22:13 -070051 fi
Luigi Semenzatoa59b3df2013-12-16 13:59:03 -080052 if egrep -qv '^[0-9a-f]{8}' "${TESTLOG}"; then
Mike Frysinger44054a02013-05-22 17:50:39 -040053 fail "found bad lines in ${TESTLOG}:
54$(<"${TESTLOG}")"
Luigi Semenzato6fdc0b42013-04-11 17:22:13 -070055 fi
56}
57
Mike Frysinger44054a02013-05-22 17:50:39 -040058rm -f "${TESTLOG}"
59cp "${SRC}/warn_collector_test_reporter.sh" .
60cp "${SRC}/TEST_WARNING" .
Luigi Semenzato6fdc0b42013-04-11 17:22:13 -070061cp 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.
66warn_collector --test &
Mike Frysinger44054a02013-05-22 17:50:39 -040067trap cleanup EXIT
Luigi Semenzato6fdc0b42013-04-11 17:22:13 -070068
69# After a while, check that the first warning has been collected.
70sleep 1
71check_log 1
72
73# Add the same warning to messages, verify that it is NOT collected
74cat TEST_WARNING >> messages
75sleep 1
76check_log 1
77
78# Add a slightly different warning to messages, check that it is collected.
79sed s/intel_dp.c/intel_xx.c/ < TEST_WARNING >> messages
80sleep 1
81check_log 2
82
83# Emulate log rotation, add a warning, and check.
84mv messages messages.1
85sed s/intel_dp.c/intel_xy.c/ < TEST_WARNING > messages
86sleep 2
87check_log 3
88
89# Success!
90exit 0