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
17 #include <android/sysprop/HypervisorProperties.sysprop.h>
18
19 #include "virt/VirtualizationTest.h"
20
21 using android::sysprop::HypervisorProperties::hypervisor_protected_vm_supported;
22 using android::sysprop::HypervisorProperties::hypervisor_vm_supported;
23
24 namespace {
25
isVmSupported()26 bool isVmSupported() {
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 = {
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
42 namespace virt {
43
SetUp()44 void VirtualizationTest::SetUp() {
45 if (!isVmSupported()) {
46 GTEST_SKIP() << "Device doesn't support KVM.";
47 }
48
49 mVirtualizationService = waitForService<IVirtualizationService>(
50 String16("android.system.virtualizationservice"));
51 ASSERT_NE(mVirtualizationService, nullptr);
52 }
53
54 } // namespace virt
55