@@ -23,6 +23,7 @@ errfile="${temp_dir}/test-err.txt"
2323workload=" ${temp_dir} /workload"
2424awkscript=" ${temp_dir} /awkscript"
2525jitdump_workload=" ${temp_dir} /jitdump_workload"
26+ maxbrstack=" ${temp_dir} /maxbrstack.py"
2627
2728cleanup ()
2829{
@@ -422,14 +423,197 @@ test_jitdump()
422423 # Should be no errors
423424 if [ " ${decode_err_cnt} " -ne 0 ] ; then
424425 echo " Decode failed, ${decode_err_cnt} errors"
425- perf script -i " ${perfdatafile} " --itrace=e-o-l
426+ perf script -i " ${perfdatafile} " --itrace=e-o-l --show-mmap-events | cat
426427 return 1
427428 fi
428429
429430 echo OK
430431 return 0
431432}
432433
434+ test_packet_filter ()
435+ {
436+ echo " --- Test with MTC and TSC disabled ---"
437+ # Disable MTC and TSC
438+ perf_record_no_decode -o " ${perfdatafile} " -e intel_pt/mtc=0,tsc=0/u uname
439+ # Should not get MTC packet
440+ mtc_cnt=$( perf script -i " ${perfdatafile} " -D 2> /dev/null | grep -c " MTC 0x" )
441+ if [ " ${mtc_cnt} " -ne 0 ] ; then
442+ echo " Failed to filter with mtc=0"
443+ return 1
444+ fi
445+ # Should not get TSC package
446+ tsc_cnt=$( perf script -i " ${perfdatafile} " -D 2> /dev/null | grep -c " TSC 0x" )
447+ if [ " ${tsc_cnt} " -ne 0 ] ; then
448+ echo " Failed to filter with tsc=0"
449+ return 1
450+ fi
451+ echo OK
452+ return 0
453+ }
454+
455+ test_disable_branch ()
456+ {
457+ echo " --- Test with branches disabled ---"
458+ # Disable branch
459+ perf_record_no_decode -o " ${perfdatafile} " -e intel_pt/branch=0/u uname
460+ # Should not get branch related packets
461+ tnt_cnt=$( perf script -i " ${perfdatafile} " -D 2> /dev/null | grep -c " TNT 0x" )
462+ tip_cnt=$( perf script -i " ${perfdatafile} " -D 2> /dev/null | grep -c " TIP 0x" )
463+ fup_cnt=$( perf script -i " ${perfdatafile} " -D 2> /dev/null | grep -c " FUP 0x" )
464+ if [ " ${tnt_cnt} " -ne 0 ] || [ " ${tip_cnt} " -ne 0 ] || [ " ${fup_cnt} " -ne 0 ] ; then
465+ echo " Failed to disable branches"
466+ return 1
467+ fi
468+ echo OK
469+ return 0
470+ }
471+
472+ test_time_cyc ()
473+ {
474+ echo " --- Test with/without CYC ---"
475+ # Check if CYC is supported
476+ cyc=$( cat /sys/bus/event_source/devices/intel_pt/caps/psb_cyc)
477+ if [ " ${cyc} " != " 1" ] ; then
478+ echo " SKIP: CYC is not supported"
479+ return 2
480+ fi
481+ # Enable CYC
482+ perf_record_no_decode -o " ${perfdatafile} " -e intel_pt/cyc/u uname
483+ # should get CYC packets
484+ cyc_cnt=$( perf script -i " ${perfdatafile} " -D 2> /dev/null | grep -c " CYC 0x" )
485+ if [ " ${cyc_cnt} " = " 0" ] ; then
486+ echo " Failed to get CYC packet"
487+ return 1
488+ fi
489+ # Without CYC
490+ perf_record_no_decode -o " ${perfdatafile} " -e intel_pt//u uname
491+ # Should not get CYC packets
492+ cyc_cnt=$( perf script -i " ${perfdatafile} " -D 2> /dev/null | grep -c " CYC 0x" )
493+ if [ " ${cyc_cnt} " -gt 0 ] ; then
494+ echo " Still get CYC packet without cyc"
495+ return 1
496+ fi
497+ echo OK
498+ return 0
499+ }
500+
501+ test_sample ()
502+ {
503+ echo " --- Test recording with sample mode ---"
504+ # Check if recording with sample mode is working
505+ if ! perf_record_no_decode -o " ${perfdatafile} " --aux-sample=8192 -e ' {intel_pt//u,branch-misses:u}' uname ; then
506+ echo " perf record failed with --aux-sample"
507+ return 1
508+ fi
509+ echo OK
510+ return 0
511+ }
512+
513+ test_kernel_trace ()
514+ {
515+ echo " --- Test with kernel trace ---"
516+ # Check if recording with kernel trace is working
517+ can_kernel || return 2
518+ if ! perf_record_no_decode -o " ${perfdatafile} " -e intel_pt//k -m1,128 uname ; then
519+ echo " perf record failed with intel_pt//k"
520+ return 1
521+ fi
522+ echo OK
523+ return 0
524+ }
525+
526+ test_virtual_lbr ()
527+ {
528+ echo " --- Test virtual LBR ---"
529+
530+ # Python script to determine the maximum size of branch stacks
531+ cat << "_end_of_file_ " > "${maxbrstack}"
532+ from __future__ import print_function
533+
534+ bmax = 0
535+
536+ def process_event(param_dict):
537+ if "brstack" in param_dict:
538+ brstack = param_dict["brstack"]
539+ n = len(brstack)
540+ global bmax
541+ if n > bmax:
542+ bmax = n
543+
544+ def trace_end():
545+ print("max brstack", bmax)
546+ _end_of_file_
547+
548+ # Check if virtual lbr is working
549+ perf_record_no_bpf -o " ${perfdatafile} " --aux-sample -e ' {intel_pt//,cycles}:u' uname
550+ times_val=$( perf script -i " ${perfdatafile} " --itrace=L -s " ${maxbrstack} " 2> /dev/null | grep " max brstack " | cut -d " " -f 3)
551+ case " ${times_val} " in
552+ [0-9]* ) ;;
553+ * ) times_val=0;;
554+ esac
555+ if [ " ${times_val} " -lt 2 ] ; then
556+ echo " Failed with virtual lbr"
557+ return 1
558+ fi
559+ echo OK
560+ return 0
561+ }
562+
563+ test_power_event ()
564+ {
565+ echo " --- Test power events ---"
566+ # Check if power events are supported
567+ power_event=$( cat /sys/bus/event_source/devices/intel_pt/caps/power_event_trace)
568+ if [ " ${power_event} " != " 1" ] ; then
569+ echo " SKIP: power_event_trace is not supported"
570+ return 2
571+ fi
572+ if ! perf_record_no_decode -o " ${perfdatafile} " -a -e intel_pt/pwr_evt/u uname ; then
573+ echo " perf record failed with pwr_evt"
574+ return 1
575+ fi
576+ echo OK
577+ return 0
578+ }
579+
580+ test_no_tnt ()
581+ {
582+ echo " --- Test with TNT packets disabled ---"
583+ # Check if TNT disable is supported
584+ notnt=$( cat /sys/bus/event_source/devices/intel_pt/caps/tnt_disable)
585+ if [ " ${notnt} " != " 1" ] ; then
586+ echo " SKIP: tnt_disable is not supported"
587+ return 2
588+ fi
589+ perf_record_no_decode -o " ${perfdatafile} " -e intel_pt/notnt/u uname
590+ # Should be no TNT packets
591+ tnt_cnt=$( perf script -i " ${perfdatafile} " -D | grep -c TNT)
592+ if [ " ${tnt_cnt} " -ne 0 ] ; then
593+ echo " TNT packets still there after notnt"
594+ return 1
595+ fi
596+ echo OK
597+ return 0
598+ }
599+
600+ test_event_trace ()
601+ {
602+ echo " --- Test with event_trace ---"
603+ # Check if event_trace is supported
604+ event_trace=$( cat /sys/bus/event_source/devices/intel_pt/caps/event_trace)
605+ if [ " ${event_trace} " != 1 ] ; then
606+ echo " SKIP: event_trace is not supported"
607+ return 2
608+ fi
609+ if ! perf_record_no_decode -o " ${perfdatafile} " -e intel_pt/event/u uname ; then
610+ echo " perf record failed with event trace"
611+ return 1
612+ fi
613+ echo OK
614+ return 0
615+ }
616+
433617count_result ()
434618{
435619 if [ " $1 " -eq 2 ] ; then
@@ -448,6 +632,15 @@ test_system_wide_side_band || ret=$? ; count_result $ret ; ret=0
448632test_per_thread " " " " || ret=$? ; count_result $ret ; ret=0
449633test_per_thread " k" " (incl. kernel) " || ret=$? ; count_result $ret ; ret=0
450634test_jitdump || ret=$? ; count_result $ret ; ret=0
635+ test_packet_filter || ret=$? ; count_result $ret ; ret=0
636+ test_disable_branch || ret=$? ; count_result $ret ; ret=0
637+ test_time_cyc || ret=$? ; count_result $ret ; ret=0
638+ test_sample || ret=$? ; count_result $ret ; ret=0
639+ test_kernel_trace || ret=$? ; count_result $ret ; ret=0
640+ test_virtual_lbr || ret=$? ; count_result $ret ; ret=0
641+ test_power_event || ret=$? ; count_result $ret ; ret=0
642+ test_no_tnt || ret=$? ; count_result $ret ; ret=0
643+ test_event_trace || ret=$? ; count_result $ret ; ret=0
451644
452645cleanup
453646
0 commit comments