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 | |
| 17 | #include "virt/VirtualizationTest.h" |
| 18 | |
Jiyong Park | aaf32f2 | 2021-08-30 19:11:19 +0900 | [diff] [blame] | 19 | namespace { |
| 20 | |
| 21 | bool isVmSupported() { |
| 22 | const std::array<const char *, 4> needed_files = { |
| 23 | "/dev/kvm", |
| 24 | "/dev/vhost-vsock", |
| 25 | "/apex/com.android.virt/bin/crosvm", |
| 26 | "/apex/com.android.virt/bin/virtualizationservice", |
| 27 | }; |
| 28 | return std::all_of(needed_files.begin(), needed_files.end(), |
| 29 | [](const char *file) { return access(file, F_OK) == 0; }); |
| 30 | } |
| 31 | |
| 32 | } // namespace |
| 33 | |
David Brazdil | 49f8a4d | 2021-03-04 09:57:33 +0000 | [diff] [blame] | 34 | namespace virt { |
| 35 | |
| 36 | void VirtualizationTest::SetUp() { |
Jiyong Park | aaf32f2 | 2021-08-30 19:11:19 +0900 | [diff] [blame] | 37 | if (!isVmSupported()) { |
| 38 | GTEST_SKIP() << "Device doesn't support KVM."; |
| 39 | } |
| 40 | |
Andrew Walbran | f145380 | 2021-03-29 17:12:54 +0000 | [diff] [blame] | 41 | mVirtualizationService = waitForService<IVirtualizationService>( |
| 42 | String16("android.system.virtualizationservice")); |
| 43 | ASSERT_NE(mVirtualizationService, nullptr); |
David Brazdil | 49f8a4d | 2021-03-04 09:57:33 +0000 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | } // namespace virt |