ANDROID: KVM: arm64: Add ftrace to kselftest for hyp tracefs
Add a couple of test to the kselftest for the pKVM hypervisor tracing
infrastructure.
Signed-off-by: Vincent Donnefort <vdonnefort@google.com>
diff --git a/tools/testing/selftests/hyp-trace/hyp-trace-test b/tools/testing/selftests/hyp-trace/hyp-trace-test
index 868eb81..699deb10 100755
--- a/tools/testing/selftests/hyp-trace/hyp-trace-test
+++ b/tools/testing/selftests/hyp-trace/hyp-trace-test
@@ -243,6 +243,80 @@
echo "done."
}
+validate_event()
+{
+ local line="$1"
+ local expect_event="$2"
+ local expect_arg="$3"
+ local event="$(echo "$line" | awk '{print $3}')"
+ local arg="$(echo "$line" | awk '{print $4}')"
+
+ [ $event == $expect_event ] || log_and_die "Expected event '$expect_event', got: '$event'"
+ [ $arg == $expect_arg ] || log_and_die "Expected arg '$expect_arg', got: '$arg'"
+}
+
+setup_hyp_ftrace()
+{
+ reset_hyp_trace()
+ echo 1 > events/hypervisor/func/enable
+ echo 1 > events/hypervisor/func_ret/enable
+}
+
+run_test_ftrace()
+{
+ local output="$2"
+
+ setup_hyp_ftrace
+
+ echo 1 > tracing_on
+ write_events 1
+ echo 0 > tracing_on
+
+ pid=$(consuming_read $tmp)
+ sleep 1
+ kill $pid
+
+}
+
+test_ftrace_nofilter()
+{
+ local func="__kvm_nvhe_handle___pkvm_selftest_event"
+ local tmp="$(mktemp)"
+
+ echo "Test ftrace..."
+
+ echo "*" > set_ftrace_filter
+
+ run_test_ftrace $tmp
+
+ grep -qE "func *$func" $tmp || \
+ log_and_die "Couldn't find 'func' event with arg '$func'"
+ grep -q "func_ret $func" $tmp || \
+ log_and_die "Couldn't find 'func_ret' event with arg '$func'"
+
+ rm $tmp
+}
+
+test_ftrace_filter()
+{
+ local func="__kvm_nvhe_handle___pkvm_selftest_event"
+ local tmp="$(mktemp)"
+
+ echo "Test ftrace filtering..."
+
+ echo "$func" > set_ftrace_filter
+
+ [ "$(cat set_ftrace_filter)" == "$func" ] || \
+ log_and_die "Failed to set set_ftrace_filter"
+
+ run_test_ftrace $tmp
+
+ validate_event "$(awk 'NR==1 {print}' $tmp)" "func" "$func"
+ validate_event "$(awk 'NR==2 {print}' $tmp)" "func_ret" "$func"
+
+ rm $tmp
+}
+
goto_hyp_trace
test_reset
@@ -250,5 +324,7 @@
test_big_bpacking
test_ts
test_extended_ts
+test_ftrace_nofilter
+test_ftrace_filter
exit 0