blob: d9bb6f945d46fdf44490814311de71c824d80c37 [file] [log] [blame]
Luigi Semenzato6fdc0b42013-04-11 17:22:13 -07001#! /bin/bash
2# Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
3# Use of this source code is governed by a BSD-style license that can be
4# found in the LICENSE file.
5
6# Test for warn_collector. Run the warn collector in the background, emulate
7# the kernel by appending lines to the log file "messages", and observe the log
8# of the (fake) crash reporter each time is run by the warn collector daemon.
9
10set -e
11
Mike Frysinger44054a02013-05-22 17:50:39 -040012fail() {
13 printf '[ FAIL ] %b\n' "$*"
14 exit 1
15}
Luigi Semenzato6fdc0b42013-04-11 17:22:13 -070016
Mike Frysinger44054a02013-05-22 17:50:39 -040017if [[ -z ${SYSROOT} ]]; then
18 fail "SYSROOT must be set for this test to work"
19fi
20: ${OUT:=${PWD}}
21cd "${OUT}"
22PATH=${OUT}:${PATH}
23TESTLOG="${OUT}/warn-test-log"
24
25echo "Testing: $(which warn_collector)"
Luigi Semenzato6fdc0b42013-04-11 17:22:13 -070026
27cleanup() {
28 # Kill daemon (if started) on exit
29 kill %
30}
31
32check_log() {
Mike Frysinger44054a02013-05-22 17:50:39 -040033 local n_expected=$1
34 if [[ ! -f ${TESTLOG} ]]; then
35 fail "${TESTLOG} was not created"
Luigi Semenzato6fdc0b42013-04-11 17:22:13 -070036 fi
Mike Frysinger44054a02013-05-22 17:50:39 -040037 if [[ $(wc -l < "${TESTLOG}") -ne ${n_expected} ]]; then
38 fail "expected ${n_expected} lines in ${TESTLOG}, found this instead:
39$(<"${TESTLOG}")"
Luigi Semenzato6fdc0b42013-04-11 17:22:13 -070040 fi
Luigi Semenzatoa59b3df2013-12-16 13:59:03 -080041 if egrep -qv '^[0-9a-f]{8}' "${TESTLOG}"; then
Mike Frysinger44054a02013-05-22 17:50:39 -040042 fail "found bad lines in ${TESTLOG}:
43$(<"${TESTLOG}")"
Luigi Semenzato6fdc0b42013-04-11 17:22:13 -070044 fi
45}
46
Mike Frysinger44054a02013-05-22 17:50:39 -040047rm -f "${TESTLOG}"
48cp "${SRC}/warn_collector_test_reporter.sh" .
49cp "${SRC}/TEST_WARNING" .
Luigi Semenzato6fdc0b42013-04-11 17:22:13 -070050cp TEST_WARNING messages
51
52# Start the collector daemon. With the --test option, the daemon reads input
53# from ./messages, writes the warning into ./warning, and invokes
54# ./warn_collector_test_reporter.sh to report the warning.
55warn_collector --test &
Mike Frysinger44054a02013-05-22 17:50:39 -040056trap cleanup EXIT
Luigi Semenzato6fdc0b42013-04-11 17:22:13 -070057
58# After a while, check that the first warning has been collected.
59sleep 1
60check_log 1
61
62# Add the same warning to messages, verify that it is NOT collected
63cat TEST_WARNING >> messages
64sleep 1
65check_log 1
66
67# Add a slightly different warning to messages, check that it is collected.
68sed s/intel_dp.c/intel_xx.c/ < TEST_WARNING >> messages
69sleep 1
70check_log 2
71
72# Emulate log rotation, add a warning, and check.
73mv messages messages.1
74sed s/intel_dp.c/intel_xy.c/ < TEST_WARNING > messages
75sleep 2
76check_log 3
77
78# Success!
79exit 0