Luigi Semenzato | 6fdc0b4 | 2013-04-11 17:22:13 -0700 | [diff] [blame] | 1 | #! /bin/bash |
Steve Fung | 6c34c25 | 2015-08-20 00:27:30 -0700 | [diff] [blame] | 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. |
Luigi Semenzato | 6fdc0b4 | 2013-04-11 17:22:13 -0700 | [diff] [blame] | 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 | |
Mike Frysinger | 44054a0 | 2013-05-22 17:50:39 -0400 | [diff] [blame] | 23 | fail() { |
| 24 | printf '[ FAIL ] %b\n' "$*" |
| 25 | exit 1 |
| 26 | } |
Luigi Semenzato | 6fdc0b4 | 2013-04-11 17:22:13 -0700 | [diff] [blame] | 27 | |
Mike Frysinger | 44054a0 | 2013-05-22 17:50:39 -0400 | [diff] [blame] | 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)" |
Luigi Semenzato | 6fdc0b4 | 2013-04-11 17:22:13 -0700 | [diff] [blame] | 37 | |
| 38 | cleanup() { |
| 39 | # Kill daemon (if started) on exit |
| 40 | kill % |
| 41 | } |
| 42 | |
| 43 | check_log() { |
Mike Frysinger | 44054a0 | 2013-05-22 17:50:39 -0400 | [diff] [blame] | 44 | local n_expected=$1 |
| 45 | if [[ ! -f ${TESTLOG} ]]; then |
| 46 | fail "${TESTLOG} was not created" |
Luigi Semenzato | 6fdc0b4 | 2013-04-11 17:22:13 -0700 | [diff] [blame] | 47 | fi |
Mike Frysinger | 44054a0 | 2013-05-22 17:50:39 -0400 | [diff] [blame] | 48 | if [[ $(wc -l < "${TESTLOG}") -ne ${n_expected} ]]; then |
| 49 | fail "expected ${n_expected} lines in ${TESTLOG}, found this instead: |
| 50 | $(<"${TESTLOG}")" |
Luigi Semenzato | 6fdc0b4 | 2013-04-11 17:22:13 -0700 | [diff] [blame] | 51 | fi |
Luigi Semenzato | a59b3df | 2013-12-16 13:59:03 -0800 | [diff] [blame] | 52 | if egrep -qv '^[0-9a-f]{8}' "${TESTLOG}"; then |
Mike Frysinger | 44054a0 | 2013-05-22 17:50:39 -0400 | [diff] [blame] | 53 | fail "found bad lines in ${TESTLOG}: |
| 54 | $(<"${TESTLOG}")" |
Luigi Semenzato | 6fdc0b4 | 2013-04-11 17:22:13 -0700 | [diff] [blame] | 55 | fi |
| 56 | } |
| 57 | |
Mike Frysinger | 44054a0 | 2013-05-22 17:50:39 -0400 | [diff] [blame] | 58 | rm -f "${TESTLOG}" |
| 59 | cp "${SRC}/warn_collector_test_reporter.sh" . |
| 60 | cp "${SRC}/TEST_WARNING" . |
Luigi Semenzato | 6fdc0b4 | 2013-04-11 17:22:13 -0700 | [diff] [blame] | 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 & |
Mike Frysinger | 44054a0 | 2013-05-22 17:50:39 -0400 | [diff] [blame] | 67 | trap cleanup EXIT |
Luigi Semenzato | 6fdc0b4 | 2013-04-11 17:22:13 -0700 | [diff] [blame] | 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 |