1#!/usr/bin/env python3 2# Copyright (C) 2023 The Android Open Source Project 3# 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License a 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15 16from python.generators.diff_tests.testing import Path, DataPath, Metric 17from python.generators.diff_tests.testing import Csv, Json, TextProto 18from python.generators.diff_tests.testing import DiffTestBlueprint 19from python.generators.diff_tests.testing import TestSuite 20 21 22class Pkvm(TestSuite): 23 24 def test_pkvm_hypervisor_events(self): 25 return DiffTestBlueprint( 26 trace=Path('pkvm_hypervisor_events.textproto'), 27 query=""" 28 INCLUDE PERFETTO MODULE pkvm.hypervisor; 29 SELECT 30 cpu, 31 ts, 32 dur, 33 reason 34 FROM 35 pkvm_hypervisor_events 36 ORDER BY cpu, ts, dur, reason; 37 """, 38 out=Csv(""" 39 "cpu","ts","dur","reason" 40 0,84798810112835,936,"host_smc" 41 0,84798810182293,285,"[NULL]" 42 1,84798810660565,11190,"host_mem_abort" 43 1,84798811118003,3703,"host_hcall" 44 """)) 45 46 def test_pkvm_hypervisor_host_hcall(self): 47 return DiffTestBlueprint( 48 trace=Path('pkvm_hypervisor_events.textproto'), 49 query=""" 50 INCLUDE PERFETTO MODULE pkvm.hypervisor; 51 SELECT 52 pkvm_hyp.cpu as cpu, 53 pkvm_hyp.ts as ts, 54 pkvm_hyp.dur as dur, 55 EXTRACT_ARG(slices.arg_set_id, 'id') as id, 56 EXTRACT_ARG(slices.arg_set_id, 'invalid') as invalid 57 FROM 58 pkvm_hypervisor_events as pkvm_hyp 59 JOIN slices 60 ON pkvm_hyp.slice_id = slices.id 61 WHERE 62 reason = "host_hcall" 63 ORDER BY cpu, ts, dur, id, invalid; 64 """, 65 out=Csv(""" 66 "cpu","ts","dur","id","invalid" 67 1,84798811118003,3703,2818048,0 68 """)) 69 70 def test_pkvm_hypervisor_host_smc(self): 71 return DiffTestBlueprint( 72 trace=Path('pkvm_hypervisor_events.textproto'), 73 query=""" 74 INCLUDE PERFETTO MODULE pkvm.hypervisor; 75 SELECT 76 pkvm_hyp.cpu as cpu, 77 pkvm_hyp.ts as ts, 78 pkvm_hyp.dur as dur, 79 EXTRACT_ARG(slices.arg_set_id, 'id') as id, 80 EXTRACT_ARG(slices.arg_set_id, 'forwarded') as forwarded 81 FROM 82 pkvm_hypervisor_events as pkvm_hyp 83 JOIN slices 84 ON pkvm_hyp.slice_id = slices.id 85 WHERE 86 reason = "host_smc" 87 ORDER BY cpu, ts, dur, id, forwarded; 88 """, 89 out=Csv(""" 90 "cpu","ts","dur","id","forwarded" 91 0,84798810112835,936,281474976710656,0 92 """)) 93 94 def test_pkvm_hypervisor_host_mem_abort(self): 95 return DiffTestBlueprint( 96 trace=Path('pkvm_hypervisor_events.textproto'), 97 query=""" 98 INCLUDE PERFETTO MODULE pkvm.hypervisor; 99 SELECT 100 pkvm_hyp.cpu as cpu, 101 pkvm_hyp.ts as ts, 102 pkvm_hyp.dur as dur, 103 EXTRACT_ARG(slices.arg_set_id, 'esr') as esr, 104 EXTRACT_ARG(slices.arg_set_id, 'addr') as addr 105 FROM 106 pkvm_hypervisor_events as pkvm_hyp 107 JOIN slices 108 ON pkvm_hyp.slice_id = slices.id 109 WHERE 110 reason = "host_mem_abort" 111 ORDER BY cpu, ts, dur, esr, addr; 112 """, 113 out=Csv(""" 114 "cpu","ts","dur","esr","addr" 115 1,84798810660565,11190,1970324836974592,-4810970301938499072 116 """)) 117