]>
Commit | Line | Data |
---|---|---|
37544a6d SG |
1 | # Copyright (c) 2013 The Chromium OS Authors. |
2 | # | |
1a459660 | 3 | # SPDX-License-Identifier: GPL-2.0+ |
37544a6d SG |
4 | # |
5 | ||
6 | # Simple test script for tracing with sandbox | |
7 | ||
8 | OUTPUT_DIR=sandbox | |
9 | TRACE_OPT="FTRACE=1" | |
10 | ||
11 | fail() { | |
12 | echo "Test failed: $1" | |
13 | if [ -n ${tmp} ]; then | |
14 | rm ${tmp} | |
15 | fi | |
16 | exit 1 | |
17 | } | |
18 | ||
19 | build_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 | ||
27 | run_trace() { | |
28 | echo "Run trace" | |
29 | ./${OUTPUT_DIR}/u-boot <<END | |
30 | trace stats | |
31 | hash sha256 0 10000 | |
32 | trace pause | |
33 | trace stats | |
34 | hash sha256 0 10000 | |
35 | trace stats | |
36 | trace resume | |
37 | hash sha256 0 10000 | |
38 | trace pause | |
39 | trace stats | |
40 | reset | |
41 | END | |
42 | } | |
43 | ||
44 | check_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 | ||
69 | echo "Simple trace test / sanity check using sandbox" | |
70 | echo | |
71 | tmp="$(tempfile)" | |
72 | build_uboot | |
73 | run_trace >${tmp} | |
74 | check_results ${tmp} | |
75 | rm ${tmp} | |
76 | echo "Test passed" |