blob: 5d323510dc7944d6f54358b626ca2ef33a532c3e [file] [log] [blame]
David Brazdil49f8a4d2021-03-04 09:57:33 +00001/*
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 Stokes459a5da2022-03-07 12:15:21 +000017#include <android/sysprop/HypervisorProperties.sysprop.h>
18
David Brazdil49f8a4d2021-03-04 09:57:33 +000019#include "virt/VirtualizationTest.h"
20
Alan Stokes459a5da2022-03-07 12:15:21 +000021using android::sysprop::HypervisorProperties::hypervisor_protected_vm_supported;
22using android::sysprop::HypervisorProperties::hypervisor_vm_supported;
23
Jiyong Parkaaf32f22021-08-30 19:11:19 +090024namespace {
25
26bool isVmSupported() {
Alan Stokes459a5da2022-03-07 12:15:21 +000027 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 Parkaaf32f22021-08-30 19:11:19 +090033 "/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 Brazdil49f8a4d2021-03-04 09:57:33 +000042namespace virt {
43
44void VirtualizationTest::SetUp() {
Jiyong Parkaaf32f22021-08-30 19:11:19 +090045 if (!isVmSupported()) {
46 GTEST_SKIP() << "Device doesn't support KVM.";
47 }
48
Andrew Walbranf1453802021-03-29 17:12:54 +000049 mVirtualizationService = waitForService<IVirtualizationService>(
50 String16("android.system.virtualizationservice"));
51 ASSERT_NE(mVirtualizationService, nullptr);
David Brazdil49f8a4d2021-03-04 09:57:33 +000052}
53
54} // namespace virt