xref: /OK3568_Linux_fs/u-boot/test/trace/test-trace.sh (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun# Copyright (c) 2013 The Chromium OS Authors.
2*4882a593Smuzhiyun#
3*4882a593Smuzhiyun# SPDX-License-Identifier:	GPL-2.0+
4*4882a593Smuzhiyun#
5*4882a593Smuzhiyun
6*4882a593Smuzhiyun# Simple test script for tracing with sandbox
7*4882a593Smuzhiyun
8*4882a593SmuzhiyunTRACE_OPT="FTRACE=1"
9*4882a593Smuzhiyun
10*4882a593SmuzhiyunBASE="$(dirname $0)/.."
11*4882a593Smuzhiyun. $BASE/common.sh
12*4882a593Smuzhiyun
13*4882a593Smuzhiyunrun_trace() {
14*4882a593Smuzhiyun	echo "Run trace"
15*4882a593Smuzhiyun	./${OUTPUT_DIR}/u-boot <<END
16*4882a593Smuzhiyuntrace stats
17*4882a593Smuzhiyunhash sha256 0 10000
18*4882a593Smuzhiyuntrace pause
19*4882a593Smuzhiyuntrace stats
20*4882a593Smuzhiyunhash sha256 0 10000
21*4882a593Smuzhiyuntrace stats
22*4882a593Smuzhiyuntrace resume
23*4882a593Smuzhiyunhash sha256 0 10000
24*4882a593Smuzhiyuntrace pause
25*4882a593Smuzhiyuntrace stats
26*4882a593Smuzhiyunreset
27*4882a593SmuzhiyunEND
28*4882a593Smuzhiyun}
29*4882a593Smuzhiyun
30*4882a593Smuzhiyuncheck_results() {
31*4882a593Smuzhiyun	echo "Check results"
32*4882a593Smuzhiyun
33*4882a593Smuzhiyun	# Expect sha256 to run 3 times, so we see the string 6 times
34*4882a593Smuzhiyun	if [ $(grep -c sha256 ${tmp}) -ne 6 ]; then
35*4882a593Smuzhiyun		fail "sha256 error"
36*4882a593Smuzhiyun	fi
37*4882a593Smuzhiyun
38*4882a593Smuzhiyun	# 4 sets of results (output of 'trace stats')
39*4882a593Smuzhiyun	if [ $(grep -c "traced function calls" ${tmp}) -ne 4 ]; then
40*4882a593Smuzhiyun		fail "trace output error"
41*4882a593Smuzhiyun	fi
42*4882a593Smuzhiyun
43*4882a593Smuzhiyun	# Check trace counts. We expect to see an increase in the number of
44*4882a593Smuzhiyun	# traced function calls between each 'trace stats' command, except
45*4882a593Smuzhiyun	# between calls 2 and 3, where tracing is paused.
46*4882a593Smuzhiyun	# This code gets the sign of the difference between each number and
47*4882a593Smuzhiyun	# its predecessor.
48*4882a593Smuzhiyun	counts="$(tr -d ',\r' <${tmp} | awk \
49*4882a593Smuzhiyun		'/traced function calls/ { diff = $1 - upto; upto = $1; \
50*4882a593Smuzhiyun		printf "%d ", diff < 0 ? -1 : (diff > 0 ? 1 : 0)}')"
51*4882a593Smuzhiyun
52*4882a593Smuzhiyun	if [ "${counts}" != "1 1 0 1 " ]; then
53*4882a593Smuzhiyun		fail "trace collection error: ${counts}"
54*4882a593Smuzhiyun	fi
55*4882a593Smuzhiyun}
56*4882a593Smuzhiyun
57*4882a593Smuzhiyunecho "Simple trace test / sanity check using sandbox"
58*4882a593Smuzhiyunecho
59*4882a593Smuzhiyuntmp="$(tempfile)"
60*4882a593Smuzhiyunbuild_uboot "${TRACE_OPT}"
61*4882a593Smuzhiyunrun_trace >${tmp}
62*4882a593Smuzhiyuncheck_results ${tmp}
63*4882a593Smuzhiyunrm ${tmp}
64*4882a593Smuzhiyunecho "Test passed"
65