blob: 973063c39780998f73cf25d19af3ffb980feb2e6 [file] [log] [blame]
Simon Glass41f07252013-06-11 11:14:45 -07001# Copyright (c) 2013 The Chromium OS Authors.
2#
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02003# SPDX-License-Identifier: GPL-2.0+
Simon Glass41f07252013-06-11 11:14:45 -07004#
5
6# Simple test script for tracing with sandbox
7
8OUTPUT_DIR=sandbox
9TRACE_OPT="FTRACE=1"
10
11fail() {
12 echo "Test failed: $1"
13 if [ -n ${tmp} ]; then
14 rm ${tmp}
15 fi
16 exit 1
17}
18
19build_uboot() {
20 echo "Build sandbox"
21 OPTS="O=${OUTPUT_DIR} ${TRACE_OPT}"
22 NUM_CPUS=$(grep -c processor /proc/cpuinfo)
23 make ${OPTS} sandbox_config
24 make ${OPTS} -s -j${NUM_CPUS}
25}
26
27run_trace() {
28 echo "Run trace"
29 ./${OUTPUT_DIR}/u-boot <<END
Simon Glass01326482014-09-14 12:40:16 -060030trace stats
31hash sha256 0 10000
32trace pause
33trace stats
34hash sha256 0 10000
35trace stats
36trace resume
37hash sha256 0 10000
38trace pause
39trace stats
40reset
Simon Glass41f07252013-06-11 11:14:45 -070041END
42}
43
44check_results() {
45 echo "Check results"
46
47 # Expect sha256 to run 3 times, so we see the string 6 times
48 if [ $(grep -c sha256 ${tmp}) -ne 6 ]; then
49 fail "sha256 error"
50 fi
51
52 # 4 sets of results (output of 'trace stats')
53 if [ $(grep -c "traced function calls" ${tmp}) -ne 4 ]; then
54 fail "trace output error"
55 fi
56
57 # Check trace counts. We expect to see an increase in the number of
58 # traced function calls between each 'trace stats' command, except
59 # between calls 2 and 3, where tracing is paused.
60 # This code gets the sign of the difference between each number and
61 # its predecessor.
62 counts="$(tr -d , <${tmp} | awk '/traced function calls/ { diff = $1 - upto; upto = $1; printf "%d ", diff < 0 ? -1 : (diff > 0 ? 1 : 0)}')"
63
64 if [ "${counts}" != "1 1 0 1 " ]; then
65 fail "trace collection error: ${counts}"
66 fi
67}
68
69echo "Simple trace test / sanity check using sandbox"
70echo
71tmp="$(tempfile)"
72build_uboot
73run_trace >${tmp}
74check_results ${tmp}
75rm ${tmp}
76echo "Test passed"