Back to home page

OSCL-LXR

 
 

    


0001 #!/bin/sh
0002 # Check Arm SPE doesn't hang when there are forks
0003 
0004 # SPDX-License-Identifier: GPL-2.0
0005 # German Gomez <german.gomez@arm.com>, 2022
0006 
0007 skip_if_no_arm_spe_event() {
0008         perf list | egrep -q 'arm_spe_[0-9]+//' && return 0
0009         return 2
0010 }
0011 
0012 skip_if_no_arm_spe_event || exit 2
0013 
0014 # skip if there's no compiler
0015 if ! [ -x "$(command -v cc)" ]; then
0016         echo "failed: no compiler, install gcc"
0017         exit 2
0018 fi
0019 
0020 TEST_PROGRAM_SOURCE=$(mktemp /tmp/__perf_test.program.XXXXX.c)
0021 TEST_PROGRAM=$(mktemp /tmp/__perf_test.program.XXXXX)
0022 PERF_DATA=$(mktemp /tmp/__perf_test.perf.data.XXXXX)
0023 PERF_RECORD_LOG=$(mktemp /tmp/__perf_test.log.XXXXX)
0024 
0025 cleanup_files()
0026 {
0027         echo "Cleaning up files..."
0028         rm -f ${PERF_RECORD_LOG}
0029         rm -f ${PERF_DATA}
0030         rm -f ${TEST_PROGRAM_SOURCE}
0031         rm -f ${TEST_PROGRAM}
0032 }
0033 
0034 trap cleanup_files exit term int
0035 
0036 # compile test program
0037 cat << EOF > $TEST_PROGRAM_SOURCE
0038 #include <math.h>
0039 #include <stdio.h>
0040 #include <stdlib.h>
0041 #include <unistd.h>
0042 #include <sys/wait.h>
0043 
0044 int workload() {
0045   while (1)
0046     sqrt(rand());
0047   return 0;
0048 }
0049 
0050 int main() {
0051   switch (fork()) {
0052     case 0:
0053       return workload();
0054     case -1:
0055       return 1;
0056     default:
0057       wait(NULL);
0058   }
0059   return 0;
0060 }
0061 EOF
0062 
0063 echo "Compiling test program..."
0064 CFLAGS="-lm"
0065 cc $TEST_PROGRAM_SOURCE $CFLAGS -o $TEST_PROGRAM || exit 1
0066 
0067 echo "Recording workload..."
0068 perf record -o ${PERF_DATA} -e arm_spe/period=65536/ -vvv -- $TEST_PROGRAM > ${PERF_RECORD_LOG} 2>&1 &
0069 PERFPID=$!
0070 
0071 # Check if perf hangs by checking the perf-record logs.
0072 sleep 1
0073 log0=$(wc -l $PERF_RECORD_LOG)
0074 echo Log lines = $log0
0075 sleep 1
0076 log1=$(wc -l $PERF_RECORD_LOG)
0077 echo Log lines after 1 second = $log1
0078 
0079 kill $PERFPID
0080 wait $PERFPID
0081 # test program may leave an orphan process running the workload
0082 killall $(basename $TEST_PROGRAM)
0083 
0084 if [ "$log0" = "$log1" ];
0085 then
0086         echo "SPE hang test: FAIL"
0087         exit 1
0088 else
0089         echo "SPE hang test: PASS"
0090 fi
0091 
0092 exit 0