Merge "Statically link AIDL code"
diff --git a/TEST_MAPPING b/TEST_MAPPING
index 11648c4..4c9907f 100644
--- a/TEST_MAPPING
+++ b/TEST_MAPPING
@@ -7,9 +7,6 @@
"name": "ComposHostTestCases"
},
{
- "name": "VirtualizationTestCases.64"
- },
- {
"name": "MicrodroidTestApp"
},
{
diff --git a/authfs/tests/common/src/java/com/android/fs/common/AuthFsTestRule.java b/authfs/tests/common/src/java/com/android/fs/common/AuthFsTestRule.java
index 57fef9f..6087eef 100644
--- a/authfs/tests/common/src/java/com/android/fs/common/AuthFsTestRule.java
+++ b/authfs/tests/common/src/java/com/android/fs/common/AuthFsTestRule.java
@@ -99,14 +99,6 @@
sTestInfo = testInfo;
TestDevice androidDevice = getDevice();
sAndroid = new CommandRunner(androidDevice);
-
- // NB: We can't use assumeTrue because the assumption exception is NOT handled by the test
- // infra when it is thrown from a class method (see b/37502066). We need to skip both here
- // and in setUp.
- if (!androidDevice.supportsMicrodroid()) {
- CLog.i("Microdroid not supported. Skipping.");
- return;
- }
}
public static void tearDownAndroid() {
diff --git a/tests/Android.bp b/tests/Android.bp
deleted file mode 100644
index 5c1b5c4..0000000
--- a/tests/Android.bp
+++ /dev/null
@@ -1,92 +0,0 @@
-// Copyright (C) 2020 The Android Open Source Project
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package {
- default_applicable_licenses: ["Android-Apache-2.0"],
-}
-
-kernel_version = "5.15"
-
-kernel_stem = "kernel_prebuilts-" + kernel_version
-
-cc_test {
- // ".64" suffix is to work around cts-unit-test which is demanding that all
- // executables in CTS should have both 32 and 64 ABIs.
- name: "VirtualizationTestCases.64",
- test_suites: [
- "general-tests",
- ],
- srcs: [
- "common.cc",
- "vsock_test.cc",
- ],
- local_include_dirs: ["include"],
- compile_multilib: "64",
- data: [
- ":virt_test_kernel",
- ":virt_test_initramfs",
- ],
- static_libs: [
- // The existence of the library in the system partition is not guaranteed.
- // Let's have our own copy of it.
- "android.system.virtualizationservice-cpp",
- "libPlatformProperties",
- ],
- shared_libs: [
- "libbase",
- "libbinder",
- "liblog",
- "libutils",
- ],
-}
-
-cc_defaults {
- name: "virt_test_guest_binary",
- static_libs: [
- "libbase",
- "liblog",
- ],
- static_executable: true,
- installable: false,
-}
-
-cc_binary {
- name: "virt_test_vsock_guest",
- srcs: ["vsock_guest.cc"],
- stem: "vsock_client",
- defaults: ["virt_test_guest_binary"],
-}
-
-prebuilt_etc {
- name: "virt_test_kernel",
- src: "nofile",
- arch: {
- arm64: {
- src: ":" + kernel_stem + "-arm64",
- },
- x86_64: {
- src: ":" + kernel_stem + "-x86_64",
- },
- },
-}
-
-android_filesystem {
- name: "virt_test_initramfs",
- deps: [
- "microdroid_kernel_modules",
- "virt_test_guest_init",
- "virt_test_vsock_guest",
- ],
- type: "cpio",
-}
diff --git a/tests/AndroidTest.xml b/tests/AndroidTest.xml
deleted file mode 100644
index 68e9c1b..0000000
--- a/tests/AndroidTest.xml
+++ /dev/null
@@ -1,42 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2020 The Android Open Source Project
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
--->
-
-<configuration description="Config for Virtualization tests">
- <option name="test-suite-tag" value="cts" />
- <option name="config-descriptor:metadata" key="component" value="security" />
- <option name="config-descriptor:metadata" key="parameter" value="not_instant_app" />
- <option name="config-descriptor:metadata" key="parameter" value="not_multi_abi" />
- <option name="config-descriptor:metadata" key="parameter" value="secondary_user" />
- <!-- Push test binaries to the device. -->
- <target_preparer class="com.android.tradefed.targetprep.PushFilePreparer">
- <option name="cleanup" value="true" />
- <option name="abort-on-push-failure" value="true" />
- <option name="push-file" key="VirtualizationTestCases.64" value="/data/local/tmp/virt-test/VirtualizationTestCases.64" />
- <option name="push-file" key="virt_test_kernel" value="/data/local/tmp/virt-test/kernel" />
- <option name="push-file" key="virt_test_initramfs.img" value="/data/local/tmp/virt-test/initramfs" />
- </target_preparer>
-
- <target_preparer class="com.android.tradefed.targetprep.RootTargetPreparer">
- <option name="force-root" value="true" />
- </target_preparer>
-
- <test class="com.android.tradefed.testtype.GTest" >
- <option name="native-test-device-path" value="/data/local/tmp/virt-test" />
- <option name="module-name" value="VirtualizationTestCases.64" />
- <!-- test-timeout unit is ms, value = 2 minutes -->
- <option name="native-test-timeout" value="120000" />
- </test>
-</configuration>
diff --git a/tests/common.cc b/tests/common.cc
deleted file mode 100644
index 5d32351..0000000
--- a/tests/common.cc
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * Copyright (C) 2021 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <android/sysprop/HypervisorProperties.sysprop.h>
-
-#include "virt/VirtualizationTest.h"
-
-using android::sysprop::HypervisorProperties::hypervisor_protected_vm_supported;
-using android::sysprop::HypervisorProperties::hypervisor_vm_supported;
-
-namespace {
-
-bool isVmSupported() {
- bool has_capability = hypervisor_vm_supported().value_or(false) ||
- hypervisor_protected_vm_supported().value_or(false);
- if (!has_capability) {
- return false;
- }
- const std::array<const char *, 2> needed_files = {
- "/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);
-}
-
-} // namespace virt
diff --git a/tests/include/virt/VirtualizationTest.h b/tests/include/virt/VirtualizationTest.h
deleted file mode 100644
index 29509ba..0000000
--- a/tests/include/virt/VirtualizationTest.h
+++ /dev/null
@@ -1,34 +0,0 @@
-/*
- * Copyright (C) 2021 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "android/system/virtualizationservice/IVirtualMachine.h"
-#include "android/system/virtualizationservice/IVirtualizationService.h"
-#include "binder/IServiceManager.h"
-#include "gtest/gtest.h"
-
-using namespace android;
-using namespace android::system::virtualizationservice;
-
-namespace virt {
-
-class VirtualizationTest : public ::testing::Test {
-protected:
- void SetUp() override;
-
- sp<IVirtualizationService> mVirtualizationService;
-};
-
-} // namespace virt
diff --git a/tests/init/Android.bp b/tests/init/Android.bp
deleted file mode 100644
index 1643acd..0000000
--- a/tests/init/Android.bp
+++ /dev/null
@@ -1,30 +0,0 @@
-// Copyright (C) 2020 The Android Open Source Project
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package {
- default_applicable_licenses: ["Android-Apache-2.0"],
-}
-
-cc_binary {
- name: "virt_test_guest_init",
- srcs: ["main.cc"],
- static_executable: true,
- installable: false,
- static_libs: [
- "libbase",
- "liblog",
- "libmodprobe",
- ],
- stem: "init",
-}
diff --git a/tests/init/main.cc b/tests/init/main.cc
deleted file mode 100644
index fe4cc80..0000000
--- a/tests/init/main.cc
+++ /dev/null
@@ -1,125 +0,0 @@
-/*
- * Copyright (C) 2020 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <dirent.h>
-#include <sys/mount.h>
-#include <sys/stat.h>
-#include <sys/types.h>
-#include <sys/utsname.h>
-#include <sys/wait.h>
-#include <unistd.h>
-
-#include <cstdlib>
-#include <filesystem>
-#include <fstream>
-#include <iostream>
-#include <memory>
-#include <string>
-#include <vector>
-
-#include <modprobe/modprobe.h>
-
-#include "android-base/logging.h"
-#include "android-base/strings.h"
-
-using namespace android::base;
-
-static constexpr const char MODULE_BASE_DIR[] = "/lib/modules";
-
-bool LoadKernelModules() {
- struct utsname uts;
- if (uname(&uts)) {
- LOG(ERROR) << "Failed to get kernel version.";
- return false;
- }
- int major, minor;
- if (sscanf(uts.release, "%d.%d", &major, &minor) != 2) {
- LOG(ERROR) << "Failed to parse kernel version " << uts.release;
- return false;
- }
-
- std::unique_ptr<DIR, decltype(&closedir)> base_dir(opendir(MODULE_BASE_DIR), closedir);
- if (!base_dir) {
- LOG(ERROR) << "Unable to open /lib/modules, skipping module loading.";
- return false;
- }
- dirent* entry;
- std::vector<std::string> module_dirs;
- while ((entry = readdir(base_dir.get()))) {
- if (entry->d_type != DT_DIR) {
- continue;
- }
- int dir_major, dir_minor;
- if (sscanf(entry->d_name, "%d.%d", &dir_major, &dir_minor) != 2 || dir_major != major ||
- dir_minor != minor) {
- continue;
- }
- module_dirs.emplace_back(entry->d_name);
- }
-
- // Sort the directories so they are iterated over during module loading
- // in a consistent order. Alphabetical sorting is fine here because the
- // kernel version at the beginning of the directory name must match the
- // current kernel version, so the sort only applies to a label that
- // follows the kernel version, for example /lib/modules/5.4 vs.
- // /lib/modules/5.4-gki.
- std::sort(module_dirs.begin(), module_dirs.end());
-
- for (const auto& module_dir : module_dirs) {
- std::string dir_path(MODULE_BASE_DIR);
- dir_path.append("/");
- dir_path.append(module_dir);
- Modprobe m({dir_path});
- bool retval = m.LoadListedModules();
- int modules_loaded = m.GetModuleCount();
- if (modules_loaded > 0) {
- return retval;
- }
- }
-
- Modprobe m({MODULE_BASE_DIR});
- bool retval = m.LoadListedModules();
- int modules_loaded = m.GetModuleCount();
- if (modules_loaded > 0) {
- return retval;
- }
-
- return true;
-}
-
-int main(int argc, const char* argv[]) {
- SetLogger(StderrLogger);
-
- LOG(INFO) << "Guest VM init process";
- LOG(INFO) << "Command line: " << Join(std::vector(argv, argv + argc), " ");
-
- if (clearenv() != EXIT_SUCCESS) {
- PLOG(ERROR) << "clearenv";
- return EXIT_FAILURE;
- }
-
- LOG(INFO) << "Loading kernel modules...";
- if (!LoadKernelModules()) {
- LOG(ERROR) << "LoadKernelModules failed";
- return EXIT_FAILURE;
- }
-
- LOG(INFO) << "Executing test binary " << argv[1] << "...";
- execv(argv[1], (char**)(argv + 1));
-
- PLOG(ERROR) << "execv";
- return EXIT_FAILURE;
-}
diff --git a/tests/nofile b/tests/nofile
deleted file mode 100644
index 9e4b854..0000000
--- a/tests/nofile
+++ /dev/null
@@ -1,2 +0,0 @@
-// This file is used as src of virt_test_kernel module for the architectures
-// other than arm64 and x86_64
diff --git a/tests/vsock_guest.cc b/tests/vsock_guest.cc
deleted file mode 100644
index 884c8a4..0000000
--- a/tests/vsock_guest.cc
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- * Copyright (C) 2020 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <sys/socket.h>
-
-// Needs to be included after sys/socket.h
-#include <linux/vm_sockets.h>
-
-#include <iostream>
-
-#include "android-base/file.h"
-#include "android-base/logging.h"
-#include "android-base/parseint.h"
-#include "android-base/unique_fd.h"
-
-using namespace android::base;
-
-int main(int argc, const char *argv[]) {
- SetLogger(StderrLogger);
-
- unsigned int cid, port;
- if (argc != 4 || !ParseUint(argv[1], &cid) || !ParseUint(argv[2], &port)) {
- LOG(ERROR) << "Usage: " << argv[0] << " <cid> <port> <msg>";
- return EXIT_FAILURE;
- }
- std::string msg(argv[3]);
-
- unique_fd fd(TEMP_FAILURE_RETRY(socket(AF_VSOCK, SOCK_STREAM, 0)));
- if (fd < 0) {
- PLOG(ERROR) << "socket";
- return EXIT_FAILURE;
- }
-
- struct sockaddr_vm sa = (struct sockaddr_vm){
- .svm_family = AF_VSOCK,
- .svm_port = port,
- .svm_cid = cid,
- };
-
- LOG(INFO) << "Connecting to CID " << cid << " on port " << port << "...";
- int ret = TEMP_FAILURE_RETRY(connect(fd, (struct sockaddr *)&sa, sizeof(sa)));
- if (ret < 0) {
- PLOG(ERROR) << "connect";
- return EXIT_FAILURE;
- }
-
- LOG(INFO) << "Sending message to server...";
- if (!WriteStringToFd(msg, fd)) {
- PLOG(ERROR) << "WriteStringToFd";
- return EXIT_FAILURE;
- }
- shutdown(fd.get(), SHUT_WR); // close socket for writing
-
- // Must not shut down until the server ACKs the message. Shutting down
- // the VM would otherwise terminate the VMM and reset the server's socket.
- LOG(INFO) << "Waiting for ACK from the server...";
- if (!ReadFdToString(fd, &msg)) {
- PLOG(ERROR) << "ReadFdToString";
- return EXIT_FAILURE;
- }
- shutdown(fd.get(), SHUT_RD); // close socket for reading
-
- LOG(INFO) << "Exiting...";
- return EXIT_SUCCESS;
-}
diff --git a/tests/vsock_test.cc b/tests/vsock_test.cc
deleted file mode 100644
index 1460660..0000000
--- a/tests/vsock_test.cc
+++ /dev/null
@@ -1,135 +0,0 @@
-/*
- * Copyright (C) 2020 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include <android/sysprop/HypervisorProperties.sysprop.h>
-#include <linux/kvm.h>
-#include <sys/ioctl.h>
-#include <sys/socket.h>
-#include <unistd.h>
-
-// Needs to be included after sys/socket.h
-#include <linux/vm_sockets.h>
-
-#include <algorithm>
-#include <array>
-#include <iostream>
-#include <optional>
-
-#include "android-base/file.h"
-#include "android-base/logging.h"
-#include "android-base/parseint.h"
-#include "android-base/unique_fd.h"
-#include "android/system/virtualizationservice/VirtualMachineConfig.h"
-#include "android/system/virtualizationservice/VirtualMachineRawConfig.h"
-#include "virt/VirtualizationTest.h"
-
-#define KVM_CAP_ARM_PROTECTED_VM 0xffbadab1
-
-using namespace android::base;
-using namespace android::os;
-
-namespace virt {
-
-static constexpr int kGuestPort = 45678;
-static constexpr const char kVmKernelPath[] = "/data/local/tmp/virt-test/kernel";
-static constexpr const char kVmInitrdPath[] = "/data/local/tmp/virt-test/initramfs";
-static constexpr const char kVmParams[] = "rdinit=/bin/init bin/vsock_client 2 45678 HelloWorld";
-static constexpr const char kTestMessage[] = "HelloWorld";
-static constexpr const char kAckMessage[] = "ACK";
-static constexpr const char kPlatformVersion[] = "~1.0";
-
-/** Returns true if the kernel supports unprotected VMs. */
-bool isUnprotectedVmSupported() {
- return android::sysprop::HypervisorProperties::hypervisor_vm_supported().value_or(false);
-}
-
-TEST_F(VirtualizationTest, TestVsock) {
- if (!isUnprotectedVmSupported()) {
- GTEST_SKIP() << "Skipping as unprotected VMs are not supported on this device.";
- }
-
- binder::Status status;
-
- unique_fd server_fd(TEMP_FAILURE_RETRY(socket(AF_VSOCK, SOCK_STREAM, 0)));
- ASSERT_GE(server_fd, 0) << strerror(errno);
-
- struct sockaddr_vm server_sa = (struct sockaddr_vm){
- .svm_family = AF_VSOCK,
- .svm_port = kGuestPort,
- .svm_cid = VMADDR_CID_ANY,
- };
-
- int ret = TEMP_FAILURE_RETRY(bind(server_fd, (struct sockaddr *)&server_sa, sizeof(server_sa)));
- ASSERT_EQ(ret, 0) << strerror(errno);
-
- LOG(INFO) << "Listening on port " << kGuestPort << "...";
- ret = TEMP_FAILURE_RETRY(listen(server_fd, 1));
- ASSERT_EQ(ret, 0) << strerror(errno);
-
- VirtualMachineRawConfig raw_config;
- raw_config.kernel = ParcelFileDescriptor(unique_fd(open(kVmKernelPath, O_RDONLY | O_CLOEXEC)));
- raw_config.initrd = ParcelFileDescriptor(unique_fd(open(kVmInitrdPath, O_RDONLY | O_CLOEXEC)));
- raw_config.params = kVmParams;
- raw_config.protectedVm = false;
- raw_config.platformVersion = kPlatformVersion;
-
- VirtualMachineConfig config(std::move(raw_config));
- sp<IVirtualMachine> vm;
- status = mVirtualizationService->createVm(config, std::nullopt, std::nullopt, &vm);
- ASSERT_TRUE(status.isOk()) << "Error creating VM: " << status;
-
- int32_t cid;
- status = vm->getCid(&cid);
- ASSERT_TRUE(status.isOk()) << "Error getting CID: " << status;
- LOG(INFO) << "VM starting with CID " << cid;
-
- status = vm->start();
- ASSERT_TRUE(status.isOk()) << "Error starting VM: " << status;
-
- LOG(INFO) << "Accepting connection...";
- struct sockaddr_vm client_sa;
- socklen_t client_sa_len = sizeof(client_sa);
- unique_fd client_fd(
- TEMP_FAILURE_RETRY(accept(server_fd, (struct sockaddr *)&client_sa, &client_sa_len)));
- ASSERT_GE(client_fd, 0) << strerror(errno);
- LOG(INFO) << "Connection from CID " << client_sa.svm_cid << " on port " << client_sa.svm_port;
-
- LOG(INFO) << "Reading message from the client...";
- std::string msg;
- ASSERT_TRUE(ReadFdToString(client_fd, &msg)) << strerror(errno);
- LOG(INFO) << "Received message: " << msg;
-
- // The client is waiting for a response to signal it can shut down.
- LOG(INFO) << "Replying with '" << kAckMessage << "'...";
- ASSERT_TRUE(WriteStringToFd(kAckMessage, client_fd));
-
- ASSERT_EQ(msg, kTestMessage);
-}
-
-TEST_F(VirtualizationTest, RejectIncompatiblePlatformVersion) {
- VirtualMachineRawConfig raw_config;
- raw_config.kernel = ParcelFileDescriptor(unique_fd(open(kVmKernelPath, O_RDONLY | O_CLOEXEC)));
- raw_config.initrd = ParcelFileDescriptor(unique_fd(open(kVmInitrdPath, O_RDONLY | O_CLOEXEC)));
- raw_config.params = kVmParams;
- raw_config.platformVersion = "~2.0"; // The current platform version is 1.0.0.
-
- VirtualMachineConfig config(std::move(raw_config));
- sp<IVirtualMachine> vm;
- auto status = mVirtualizationService->createVm(config, std::nullopt, std::nullopt, &vm);
- ASSERT_FALSE(status.isOk());
-}
-
-} // namespace virt