Simon Glass | 41f0725 | 2013-06-11 11:14:45 -0700 | [diff] [blame] | 1 | # Copyright (c) 2013 The Chromium OS Authors. |
| 2 | # |
| 3 | # This program is free software; you can redistribute it and/or |
| 4 | # modify it under the terms of the GNU General Public License as |
| 5 | # published by the Free Software Foundation; either version 2 of |
| 6 | # the License, or (at your option) any later version. |
| 7 | # |
| 8 | # This program is distributed in the hope that it will be useful, |
| 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | # GNU General Public License for more details. |
| 12 | # |
| 13 | # You should have received a copy of the GNU General Public License |
| 14 | # along with this program; if not, write to the Free Software |
| 15 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 16 | # MA 02111-1307 USA |
| 17 | # |
| 18 | |
| 19 | # Simple test script for tracing with sandbox |
| 20 | |
| 21 | OUTPUT_DIR=sandbox |
| 22 | TRACE_OPT="FTRACE=1" |
| 23 | |
| 24 | fail() { |
| 25 | echo "Test failed: $1" |
| 26 | if [ -n ${tmp} ]; then |
| 27 | rm ${tmp} |
| 28 | fi |
| 29 | exit 1 |
| 30 | } |
| 31 | |
| 32 | build_uboot() { |
| 33 | echo "Build sandbox" |
| 34 | OPTS="O=${OUTPUT_DIR} ${TRACE_OPT}" |
| 35 | NUM_CPUS=$(grep -c processor /proc/cpuinfo) |
| 36 | make ${OPTS} sandbox_config |
| 37 | make ${OPTS} -s -j${NUM_CPUS} |
| 38 | } |
| 39 | |
| 40 | run_trace() { |
| 41 | echo "Run trace" |
| 42 | ./${OUTPUT_DIR}/u-boot <<END |
| 43 | trace stats |
| 44 | hash sha256 0 10000 |
| 45 | trace pause |
| 46 | trace stats |
| 47 | hash sha256 0 10000 |
| 48 | trace stats |
| 49 | trace resume |
| 50 | hash sha256 0 10000 |
| 51 | trace pause |
| 52 | trace stats |
| 53 | reset |
| 54 | END |
| 55 | } |
| 56 | |
| 57 | check_results() { |
| 58 | echo "Check results" |
| 59 | |
| 60 | # Expect sha256 to run 3 times, so we see the string 6 times |
| 61 | if [ $(grep -c sha256 ${tmp}) -ne 6 ]; then |
| 62 | fail "sha256 error" |
| 63 | fi |
| 64 | |
| 65 | # 4 sets of results (output of 'trace stats') |
| 66 | if [ $(grep -c "traced function calls" ${tmp}) -ne 4 ]; then |
| 67 | fail "trace output error" |
| 68 | fi |
| 69 | |
| 70 | # Check trace counts. We expect to see an increase in the number of |
| 71 | # traced function calls between each 'trace stats' command, except |
| 72 | # between calls 2 and 3, where tracing is paused. |
| 73 | # This code gets the sign of the difference between each number and |
| 74 | # its predecessor. |
| 75 | counts="$(tr -d , <${tmp} | awk '/traced function calls/ { diff = $1 - upto; upto = $1; printf "%d ", diff < 0 ? -1 : (diff > 0 ? 1 : 0)}')" |
| 76 | |
| 77 | if [ "${counts}" != "1 1 0 1 " ]; then |
| 78 | fail "trace collection error: ${counts}" |
| 79 | fi |
| 80 | } |
| 81 | |
| 82 | echo "Simple trace test / sanity check using sandbox" |
| 83 | echo |
| 84 | tmp="$(tempfile)" |
| 85 | build_uboot |
| 86 | run_trace >${tmp} |
| 87 | check_results ${tmp} |
| 88 | rm ${tmp} |
| 89 | echo "Test passed" |