Run VirtualizationTestCases for presubmit builds

Bug: 192204736
Test: watch TH
Change-Id: Id4cd15b551c3cd8db20276401cfc95b1010f9db6
This commit is contained in:
Jiyong Park 2021-08-30 19:11:19 +09:00
parent adc38d1e55
commit aaf32f25bd
3 changed files with 24 additions and 27 deletions

View File

@ -5,12 +5,7 @@
},
{
"name": "ComposHostTestCases"
}
],
"postsubmit": [
// TODO(jiyong): promote this to presubmit. That currently doesn't work because
// this test is skipped for cf_x86_64_phone (not aosp_cf_x86_64_phone), but tradefed
// somehow thinks that the test wasn't executed at all and reports it as a failure.
},
{
"name": "VirtualizationTestCases"
}

View File

@ -16,9 +16,28 @@
#include "virt/VirtualizationTest.h"
namespace {
bool isVmSupported() {
const std::array<const char *, 4> needed_files = {
"/dev/kvm",
"/dev/vhost-vsock",
"/apex/com.android.virt/bin/crosvm",
"/apex/com.android.virt/bin/virtualizationservice",
};
return std::all_of(needed_files.begin(), needed_files.end(),
[](const char *file) { return access(file, F_OK) == 0; });
}
} // namespace
namespace virt {
void VirtualizationTest::SetUp() {
if (!isVmSupported()) {
GTEST_SKIP() << "Device doesn't support KVM.";
}
mVirtualizationService = waitForService<IVirtualizationService>(
String16("android.system.virtualizationservice"));
ASSERT_NE(mVirtualizationService, nullptr);

View File

@ -48,17 +48,6 @@ static constexpr const char kVmInitrdPath[] = "/data/local/tmp/virt-test/initram
static constexpr const char kVmParams[] = "rdinit=/bin/init bin/vsock_client 2 45678 HelloWorld";
static constexpr const char kTestMessage[] = "HelloWorld";
bool isVmSupported() {
const std::array<const char *, 4> needed_files = {
"/dev/kvm",
"/dev/vhost-vsock",
"/apex/com.android.virt/bin/crosvm",
"/apex/com.android.virt/bin/virtualizationservice",
};
return std::all_of(needed_files.begin(), needed_files.end(),
[](const char *file) { return access(file, F_OK) == 0; });
}
/** Returns true if the kernel supports Protected KVM. */
bool isPkvmSupported() {
unique_fd kvm_fd(open("/dev/kvm", O_NONBLOCK | O_CLOEXEC));
@ -66,6 +55,10 @@ bool isPkvmSupported() {
}
void runTest(sp<IVirtualizationService> virtualization_service, bool protected_vm) {
if (protected_vm && !isPkvmSupported()) {
GTEST_SKIP() << "Skipping as pKVM is not supported on this device.";
}
binder::Status status;
unique_fd server_fd(TEMP_FAILURE_RETRY(socket(AF_VSOCK, SOCK_STREAM, 0)));
@ -117,20 +110,10 @@ void runTest(sp<IVirtualizationService> virtualization_service, bool protected_v
}
TEST_F(VirtualizationTest, TestVsock) {
if (!isVmSupported()) {
GTEST_SKIP() << "Device doesn't support KVM.";
}
runTest(mVirtualizationService, false);
}
TEST_F(VirtualizationTest, TestVsockProtected) {
if (!isVmSupported()) {
GTEST_SKIP() << "Device doesn't support KVM.";
} else if (!isPkvmSupported()) {
GTEST_SKIP() << "Skipping as pKVM is not supported on this device.";
}
runTest(mVirtualizationService, true);
}