Back to home page

OSCL-LXR

 
 

    


0001 #!/bin/sh
0002 # Check Arm64 callgraphs are complete in fp mode
0003 # SPDX-License-Identifier: GPL-2.0
0004 
0005 lscpu | grep -q "aarch64" || exit 2
0006 
0007 if ! [ -x "$(command -v cc)" ]; then
0008         echo "failed: no compiler, install gcc"
0009         exit 2
0010 fi
0011 
0012 PERF_DATA=$(mktemp /tmp/__perf_test.perf.data.XXXXX)
0013 TEST_PROGRAM_SOURCE=$(mktemp /tmp/test_program.XXXXX.c)
0014 TEST_PROGRAM=$(mktemp /tmp/test_program.XXXXX)
0015 
0016 cleanup_files()
0017 {
0018         rm -f $PERF_DATA
0019         rm -f $TEST_PROGRAM_SOURCE
0020         rm -f $TEST_PROGRAM
0021 }
0022 
0023 trap cleanup_files exit term int
0024 
0025 cat << EOF > $TEST_PROGRAM_SOURCE
0026 int a = 0;
0027 void leaf(void) {
0028   for (;;)
0029     a += a;
0030 }
0031 void parent(void) {
0032   leaf();
0033 }
0034 int main(void) {
0035   parent();
0036   return 0;
0037 }
0038 EOF
0039 
0040 echo " + Compiling test program ($TEST_PROGRAM)..."
0041 
0042 CFLAGS="-g -O0 -fno-inline -fno-omit-frame-pointer"
0043 cc $CFLAGS $TEST_PROGRAM_SOURCE -o $TEST_PROGRAM || exit 1
0044 
0045 # Add a 1 second delay to skip samples that are not in the leaf() function
0046 perf record -o $PERF_DATA --call-graph fp -e cycles//u -D 1000 --user-callchains -- $TEST_PROGRAM 2> /dev/null &
0047 PID=$!
0048 
0049 echo " + Recording (PID=$PID)..."
0050 sleep 2
0051 echo " + Stopping perf-record..."
0052 
0053 kill $PID
0054 wait $PID
0055 
0056 # expected perf-script output:
0057 #
0058 # program
0059 #       728 leaf
0060 #       753 parent
0061 #       76c main
0062 # ...
0063 
0064 perf script -i $PERF_DATA -F comm,ip,sym | head -n4
0065 perf script -i $PERF_DATA -F comm,ip,sym | head -n4 | \
0066         awk '{ if ($2 != "") sym[i++] = $2 } END { if (sym[0] != "leaf" ||
0067                                                        sym[1] != "parent" ||
0068                                                        sym[2] != "main") exit 1 }'