David Brazdil | 49f8a4d | 2021-03-04 09:57:33 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2021 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 at |
| 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 | */ |
| 16 | |
Alan Stokes | 459a5da | 2022-03-07 12:15:21 +0000 | [diff] [blame] | 17 | #include <android/sysprop/HypervisorProperties.sysprop.h> |
| 18 | |
David Brazdil | 49f8a4d | 2021-03-04 09:57:33 +0000 | [diff] [blame] | 19 | #include "virt/VirtualizationTest.h" |
| 20 | |
Alan Stokes | 459a5da | 2022-03-07 12:15:21 +0000 | [diff] [blame] | 21 | using android::sysprop::HypervisorProperties::hypervisor_protected_vm_supported; |
| 22 | using android::sysprop::HypervisorProperties::hypervisor_vm_supported; |
| 23 | |
Jiyong Park | aaf32f2 | 2021-08-30 19:11:19 +0900 | [diff] [blame] | 24 | namespace { |
| 25 | |
| 26 | bool isVmSupported() { |
Alan Stokes | 459a5da | 2022-03-07 12:15:21 +0000 | [diff] [blame] | 27 | bool has_capability = hypervisor_vm_supported().value_or(false) || |
| 28 | hypervisor_protected_vm_supported().value_or(false); |
| 29 | if (!has_capability) { |
| 30 | return false; |
| 31 | } |
| 32 | const std::array<const char *, 2> needed_files = { |
Jiyong Park | aaf32f2 | 2021-08-30 19:11:19 +0900 | [diff] [blame] | 33 | "/apex/com.android.virt/bin/crosvm", |
| 34 | "/apex/com.android.virt/bin/virtualizationservice", |
| 35 | }; |
| 36 | return std::all_of(needed_files.begin(), needed_files.end(), |
| 37 | [](const char *file) { return access(file, F_OK) == 0; }); |
| 38 | } |
| 39 | |
| 40 | } // namespace |
| 41 | |
David Brazdil | 49f8a4d | 2021-03-04 09:57:33 +0000 | [diff] [blame] | 42 | namespace virt { |
| 43 | |
| 44 | void VirtualizationTest::SetUp() { |
Jiyong Park | aaf32f2 | 2021-08-30 19:11:19 +0900 | [diff] [blame] | 45 | if (!isVmSupported()) { |
| 46 | GTEST_SKIP() << "Device doesn't support KVM."; |
| 47 | } |
| 48 | |
Andrew Walbran | f145380 | 2021-03-29 17:12:54 +0000 | [diff] [blame] | 49 | mVirtualizationService = waitForService<IVirtualizationService>( |
| 50 | String16("android.system.virtualizationservice")); |
| 51 | ASSERT_NE(mVirtualizationService, nullptr); |
David Brazdil | 49f8a4d | 2021-03-04 09:57:33 +0000 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | } // namespace virt |