blob: 746793c83bc38a3ddb68c24d8613fa921a340804 [file] [log] [blame]
Simon Glass37544a62013-06-11 11:14:45 -07001# Copyright (c) 2013 The Chromium OS Authors.
2#
Wolfgang Denk1a459662013-07-08 09:37:19 +02003# SPDX-License-Identifier: GPL-2.0+
Simon Glass37544a62013-06-11 11:14:45 -07004#
5
6# Simple test script for tracing with sandbox
7
Simon Glass37544a62013-06-11 11:14:45 -07008TRACE_OPT="FTRACE=1"
9
Simon Glass129acd42014-09-14 12:40:17 -060010BASE="$(dirname $0)/.."
11. $BASE/common.sh
Simon Glass37544a62013-06-11 11:14:45 -070012
13run_trace() {
14 echo "Run trace"
15 ./${OUTPUT_DIR}/u-boot <<END
Simon Glass07b34272014-09-14 12:40:16 -060016trace stats
17hash sha256 0 10000
18trace pause
19trace stats
20hash sha256 0 10000
21trace stats
22trace resume
23hash sha256 0 10000
24trace pause
25trace stats
26reset
Simon Glass37544a62013-06-11 11:14:45 -070027END
28}
29
30check_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 Glassf91281b2016-02-24 09:14:47 -070048 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 Glass37544a62013-06-11 11:14:45 -070051
52 if [ "${counts}" != "1 1 0 1 " ]; then
53 fail "trace collection error: ${counts}"
54 fi
55}
56
57echo "Simple trace test / sanity check using sandbox"
58echo
59tmp="$(tempfile)"
Simon Glass129acd42014-09-14 12:40:17 -060060build_uboot "${TRACE_OPT}"
Simon Glass37544a62013-06-11 11:14:45 -070061run_trace >${tmp}
62check_results ${tmp}
63rm ${tmp}
64echo "Test passed"