Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame^] | 1 | #!/bin/bash |
| 2 | # SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | 41f0725 | 2013-06-11 11:14:45 -0700 | [diff] [blame] | 3 | # Copyright (c) 2013 The Chromium OS Authors. |
| 4 | # |
Simon Glass | 41f0725 | 2013-06-11 11:14:45 -0700 | [diff] [blame] | 5 | |
| 6 | # Simple test script for tracing with sandbox |
| 7 | |
Simon Glass | 41f0725 | 2013-06-11 11:14:45 -0700 | [diff] [blame] | 8 | TRACE_OPT="FTRACE=1" |
| 9 | |
Simon Glass | 7b41cb1 | 2014-09-14 12:40:17 -0600 | [diff] [blame] | 10 | BASE="$(dirname $0)/.." |
| 11 | . $BASE/common.sh |
Simon Glass | 41f0725 | 2013-06-11 11:14:45 -0700 | [diff] [blame] | 12 | |
| 13 | run_trace() { |
| 14 | echo "Run trace" |
| 15 | ./${OUTPUT_DIR}/u-boot <<END |
Simon Glass | 0132648 | 2014-09-14 12:40:16 -0600 | [diff] [blame] | 16 | trace stats |
| 17 | hash sha256 0 10000 |
| 18 | trace pause |
| 19 | trace stats |
| 20 | hash sha256 0 10000 |
| 21 | trace stats |
| 22 | trace resume |
| 23 | hash sha256 0 10000 |
| 24 | trace pause |
| 25 | trace stats |
| 26 | reset |
Simon Glass | 41f0725 | 2013-06-11 11:14:45 -0700 | [diff] [blame] | 27 | END |
| 28 | } |
| 29 | |
| 30 | check_results() { |
| 31 | echo "Check results" |
| 32 | |
| 33 | # Expect sha256 to run 3 times, so we see the string 6 times |
| 34 | if [ $(grep -c sha256 ${tmp}) -ne 6 ]; then |
| 35 | fail "sha256 error" |
| 36 | fi |
| 37 | |
| 38 | # 4 sets of results (output of 'trace stats') |
| 39 | if [ $(grep -c "traced function calls" ${tmp}) -ne 4 ]; then |
| 40 | fail "trace output error" |
| 41 | fi |
| 42 | |
| 43 | # Check trace counts. We expect to see an increase in the number of |
| 44 | # traced function calls between each 'trace stats' command, except |
| 45 | # between calls 2 and 3, where tracing is paused. |
| 46 | # This code gets the sign of the difference between each number and |
| 47 | # its predecessor. |
Simon Glass | 170e5b9 | 2016-02-24 09:14:47 -0700 | [diff] [blame] | 48 | counts="$(tr -d ',\r' <${tmp} | awk \ |
| 49 | '/traced function calls/ { diff = $1 - upto; upto = $1; \ |
| 50 | printf "%d ", diff < 0 ? -1 : (diff > 0 ? 1 : 0)}')" |
Simon Glass | 41f0725 | 2013-06-11 11:14:45 -0700 | [diff] [blame] | 51 | |
| 52 | if [ "${counts}" != "1 1 0 1 " ]; then |
| 53 | fail "trace collection error: ${counts}" |
| 54 | fi |
| 55 | } |
| 56 | |
| 57 | echo "Simple trace test / sanity check using sandbox" |
| 58 | echo |
| 59 | tmp="$(tempfile)" |
Simon Glass | 7b41cb1 | 2014-09-14 12:40:17 -0600 | [diff] [blame] | 60 | build_uboot "${TRACE_OPT}" |
Simon Glass | 41f0725 | 2013-06-11 11:14:45 -0700 | [diff] [blame] | 61 | run_trace >${tmp} |
| 62 | check_results ${tmp} |
| 63 | rm ${tmp} |
| 64 | echo "Test passed" |