Skip tests instead of failing when running on unsupported devices
... in preparation for running tests in presubmit builds Bug: 181615964 Test: watch TH Change-Id: Id2544a3324efd09521b6a60f392e9bba200886b9
This commit is contained in:
parent
7f55256b8a
commit
dd4720bbfa
|
@ -19,19 +19,6 @@
|
||||||
a test-only permission, run it without selinux -->
|
a test-only permission, run it without selinux -->
|
||||||
<target_preparer class="com.android.tradefed.targetprep.DisableSELinuxTargetPreparer"/>
|
<target_preparer class="com.android.tradefed.targetprep.DisableSELinuxTargetPreparer"/>
|
||||||
|
|
||||||
<!-- Basic checks that the device has all the prerequisites. -->
|
|
||||||
<target_preparer class="com.android.tradefed.targetprep.RunCommandTargetPreparer">
|
|
||||||
<option name="throw-if-cmd-fail" value="true" />
|
|
||||||
<!-- Kernel has KVM enabled. -->
|
|
||||||
<option name="run-command" value="ls /dev/kvm" />
|
|
||||||
<!-- Kernel has vhost-vsock enabled. -->
|
|
||||||
<option name="run-command" value="ls /dev/vhost-vsock" />
|
|
||||||
<!-- CrosVM is installed. -->
|
|
||||||
<option name="run-command" value="ls /apex/com.android.virt/bin/crosvm" />
|
|
||||||
<!-- VirtualizationService is installed. -->
|
|
||||||
<option name="run-command" value="ls /apex/com.android.virt/bin/virtualizationservice" />
|
|
||||||
</target_preparer>
|
|
||||||
|
|
||||||
<!-- Push test binaries to the device. -->
|
<!-- Push test binaries to the device. -->
|
||||||
<target_preparer class="com.android.tradefed.targetprep.PushFilePreparer">
|
<target_preparer class="com.android.tradefed.targetprep.PushFilePreparer">
|
||||||
<option name="cleanup" value="true" />
|
<option name="cleanup" value="true" />
|
||||||
|
|
|
@ -20,6 +20,8 @@
|
||||||
// Needs to be included after sys/socket.h
|
// Needs to be included after sys/socket.h
|
||||||
#include <linux/vm_sockets.h>
|
#include <linux/vm_sockets.h>
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <array>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
|
||||||
|
@ -41,7 +43,22 @@ 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 kVmParams[] = "rdinit=/bin/init bin/vsock_client 2 45678 HelloWorld";
|
||||||
static constexpr const char kTestMessage[] = "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; });
|
||||||
|
}
|
||||||
|
|
||||||
TEST_F(VirtualizationTest, TestVsock) {
|
TEST_F(VirtualizationTest, TestVsock) {
|
||||||
|
if (!isVmSupported()) {
|
||||||
|
GTEST_SKIP() << "Device doesn't support VM.";
|
||||||
|
}
|
||||||
|
|
||||||
binder::Status status;
|
binder::Status status;
|
||||||
|
|
||||||
unique_fd server_fd(TEMP_FAILURE_RETRY(socket(AF_VSOCK, SOCK_STREAM, 0)));
|
unique_fd server_fd(TEMP_FAILURE_RETRY(socket(AF_VSOCK, SOCK_STREAM, 0)));
|
||||||
|
|
Loading…
Reference in New Issue