Skip to content

Commit

Permalink
Update Intel PT testing by adding 11 cases
Browse files Browse the repository at this point in the history
Add 4 perf related PT cases
Add 7 C program related PT cases

Signed-off-by: qwang59 <[email protected]>
  • Loading branch information
qwang59 committed Mar 30, 2024
1 parent d60c261 commit f57a285
Show file tree
Hide file tree
Showing 4 changed files with 182 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pt/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

CC ?= "${CC}" -g -Wall
CFLAGS += -DMAINLINE -I./
BIN = cpl branch psb nonroot_test negative_test
BIN = cpl branch psb nonroot_test negative_test sort_test
LFLAGS = -L./ -lipt


Expand All @@ -25,5 +25,8 @@ nonroot_test:
negative_test:
$(CC) -o $@ $@.c utils.c ${CFLAGS} ${LFLAGS}

sort_test:
$(CC) -o $@ $@.c utils.c ${CFLAGS} ${LFLAGS}

clean:
rm -rf $(BIN) *.o
93 changes: 93 additions & 0 deletions pt/perf_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ __EOF
perf_log="perf_record.log"
temp_log="perf.log"

# Perf tool is required to run this processor trace cases
if which perf 1>/dev/null 2>&1; then
perf list 1>/dev/null || block_test "Failed to run perf tool,
please check perf tool error message."
else
block_test "perf tool is required to run processor trace cases,
please get it from latest upstream kernel-tools."
fi

result_check() {
grep lost $perf_log
[[ $? -eq 1 ]] || die "Data loss occurs during the perf record!"
Expand Down Expand Up @@ -305,6 +314,26 @@ the CYC package will be disabled if MTC is disabled!"
rm -f $temp_log
}

# Function to check if the CYC package is disabled by default
time_full_test() {
local cyc
cyc=$(cat /sys/bus/event_source/devices/intel_pt/caps/psb_cyc)
[[ $cyc -eq 0 ]] && block_test "Platform does not support Cycle Counter package"
if [[ $cyc -eq 1 ]]; then
test_print_trc "Platform supports CYC, will check if CYC package is disabled by default"
do_cmd "perf record -e intel_pt//u sleep 1 >& $perf_log"
result_check
sleep 1
sync
sync
do_cmd "perf script -D > $temp_log"
should_fail "grep \"CYC 0x\" $temp_log"
##TODO will add more logic after confirming with Adrian
fi
rm -f $perf_log
rm -f $temp_log
}

# PEBS: Precise Event-Based Sampling
# Function to record and filter PT's branch events, cycles, and instructions
# while executing uname command
Expand Down Expand Up @@ -488,6 +517,58 @@ event_trace_test() {
rm -f $temp_log
}

# Function to check if tracestop is supported and detected.
tracestop_test() {
local path
path=$(pwd)
path=$path"/sort_test"
do_cmd "perf record -e intel_pt//u '--filter=tracestop main @ $path' sort_test >& $perf_log"
result_check
rm -f $perf_log
}

# Function to check trace filter with main count
tracefilter_test() {
local path
path=$(pwd)
path=$path"/sort_test"
do_cmd "perf record -e intel_pt//u '--filter=filter main @ $path' sort_test >& $perf_log"
result_check
sleep 1
sync
sync
do_cmd "perf script --itrace=ibxwe | tail > $temp_log"
count_e=$(grep -c main $temp_log)
count_cbr=$(grep -c "cbr" $temp_log)
count_p=$(grep -c "branch" $temp_log)
test_print_trc "count_e=$count_e, count_cbr=$count_cbr, count_p=$count_p"
[[ $count_e -eq $count_p ]] || die "main count is not right, trace filter with main is failed!"
should_fail "sed -n $count_p'p' $temp_log | grep unknown"
rm -f $perf_log
rm -f $temp_log
}

# Function to check if trace filter with __sched for kernel is supported and detected.
filter_kernel_cpu_test() {
rm perfdata -rf
do_cmd "perf record --kcore -e intel_pt// --filter 'filter __schedule / __schedule' -a -- sleep 1 >& $perf_log"
result_check
sleep 1
sync
sync
do_cmd "perf script --itrace=ibxwpe | tail > $temp_log"
count_e=$(grep -c "__sched" $temp_log)
count_cbr=$(grep -c "cbr" $temp_log)
count_p=$(awk 'END{print NR}' $temp_log)
test_print_trc "count_e = $count_e count_cbr=$count_cbr count_p=$count_p"

[[ $count_e -eq $count_p ]] || die "__sched count is not right, trace filter with __sched for kernel is failed!"
should_fail "sed -n $count_p'p' $temp_log | grep unknown"
rm perfdata -rf
rm -f $perf_log
rm -f $temp_log
}

perftest() {
case $TEST_SCENARIO in
fp)
Expand Down Expand Up @@ -520,6 +601,9 @@ perftest() {
mtc)
time_mtc_test
;;
time_full)
time_full_test
;;
pebs)
pebs_test
;;
Expand Down Expand Up @@ -553,6 +637,15 @@ perftest() {
event_trace)
event_trace_test
;;
trace_stop)
tracestop_test
;;
trace_filter)
tracefilter_test
;;
trace_filter_kernel_cpu)
filter_kernel_cpu_test
;;
esac
return 0
}
Expand Down
49 changes: 49 additions & 0 deletions pt/sort_test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#define ARRAY_LEN 3000

static struct timeval tm1;

static inline void start() {
gettimeofday(&tm1, NULL);
}

static inline void stop() {
struct timeval tm2;
gettimeofday(&tm2, NULL);
unsigned long long t = 1000 * (tm2.tv_sec - tm1.tv_sec) +\
(tm2.tv_usec - tm1.tv_usec) / 1000;
printf("%llu ms\n", t);
}

void bubble_sort (int *a, int n) {
int i, t, s = 1;
while (s) {
s = 0;
for (i = 1; i < n; i++) {
if (a[i] < a[i - 1]) {
t = a[i];
a[i] = a[i - 1];
a[i - 1] = t;
s = 1;
}
}
}
}

void sort_array() {
printf("Bubble sorting array of %d elements\n", ARRAY_LEN);
int data[ARRAY_LEN], i;
for(i=0; i<ARRAY_LEN; ++i){
data[i] = rand();
}
bubble_sort(data, ARRAY_LEN);
}

int main(){
start();
sort_array();
stop();
return 0;
}
36 changes: 36 additions & 0 deletions pt/tests
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ perf_tests.sh -t cyc
# Verify if the CYC (cycle count) will be disabled
# if MTC(mini time counter) is disabled in perf
perf_tests.sh -t mtc
# Verify if the CYC package is disabled by default
perf_tests.sh -t time_full
# Record and filter PT's branch events, cycles, and instructions
perf_tests.sh -t pebs
# Verify Intel PT's last branch recorded stack information
Expand All @@ -43,3 +45,37 @@ perf_tests.sh -t lost_data
perf_tests.sh -t notnt
# Verify if the event trace is supported and detected
perf_tests.sh -t event_trace
# Verify if the tracestop is supported and detected
perf_tests.sh -t trace_stop
# Verify the trace filter with main count
perf_tests.sh -t trace_filter
# Verify if trace filter with __sched for kernel is supported and detected
perf_tests.sh -t trace_filter_kernel_cpu

# Below cases are designed with C program
# Disable branch and check if TIP/FUP/TNT packages are disabled
# TIP: (Target IP Package)
# FUP: (Flow Update Package)
# TNT: (Take/Not-taken)
branch

# User mode trace check for current privilege level
# CPL: Current Privilege Level
cpl 1

# Kernel mode trace check for current privilege level
cpl 2

# Verify if the psb package is available
# PSB: Package Stream Boundary
psb

# Check if the reserved bit cannot be set.
negative_test

# Doing the full trace check with non root user
nonroot_test 1

# Doing snapshot trace check with non root user
nonroot_test 2

0 comments on commit f57a285

Please sign in to comment.