Commit 5428a247 authored by Yusuke Sato's avatar Yusuke Sato Committed by Chromium LUCI CQ

arc: Make arc_vm_client_adapter.cc's test coverage 100%

BUG=None
TEST=try

Change-Id: I9ecee3fa64eb3192adcf62b8ce5e43324d04edf5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2594449Reviewed-by: default avatarWillie Koomson <wvk@google.com>
Commit-Queue: Yusuke Sato <yusukes@chromium.org>
Cr-Commit-Position: refs/heads/master@{#837718}
parent bc664a2c
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include <sys/socket.h> #include <sys/socket.h>
#include <sys/un.h> #include <sys/un.h>
#include <time.h> #include <time.h>
#include <unistd.h>
#include <deque> #include <deque>
#include <set> #include <set>
...@@ -90,6 +91,7 @@ constexpr base::TimeDelta kConnectSleepDurationInitial = ...@@ -90,6 +91,7 @@ constexpr base::TimeDelta kConnectSleepDurationInitial =
base::Optional<base::TimeDelta> g_connect_timeout_limit_for_testing; base::Optional<base::TimeDelta> g_connect_timeout_limit_for_testing;
base::Optional<base::TimeDelta> g_connect_sleep_duration_initial_for_testing; base::Optional<base::TimeDelta> g_connect_sleep_duration_initial_for_testing;
base::Optional<int> g_boot_notification_server_fd;
bool g_enable_adb_over_usb_for_testing = false; bool g_enable_adb_over_usb_for_testing = false;
chromeos::ConciergeClient* GetConciergeClient() { chromeos::ConciergeClient* GetConciergeClient() {
...@@ -300,6 +302,9 @@ const sockaddr_un* GetArcVmBootNotificationServerAddress() { ...@@ -300,6 +302,9 @@ const sockaddr_un* GetArcVmBootNotificationServerAddress() {
// Returns the connected socket fd if successful, or else an invalid fd. This // Returns the connected socket fd if successful, or else an invalid fd. This
// function can only be called with base::MayBlock(). // function can only be called with base::MayBlock().
base::ScopedFD ConnectToArcVmBootNotificationServer() { base::ScopedFD ConnectToArcVmBootNotificationServer() {
if (g_boot_notification_server_fd)
return base::ScopedFD(HANDLE_EINTR(dup(*g_boot_notification_server_fd)));
base::ScopedBlockingCall scoped_blocking_call(FROM_HERE, base::ScopedBlockingCall scoped_blocking_call(FROM_HERE,
base::BlockingType::WILL_BLOCK); base::BlockingType::WILL_BLOCK);
base::ScopedFD fd(socket(AF_UNIX, SOCK_STREAM, 0)); base::ScopedFD fd(socket(AF_UNIX, SOCK_STREAM, 0));
...@@ -358,8 +363,6 @@ bool SendUpgradePropsToArcVmBootNotificationServer( ...@@ -358,8 +363,6 @@ bool SendUpgradePropsToArcVmBootNotificationServer(
return false; return false;
if (!base::WriteFileDescriptor(fd.get(), props.c_str(), props.size())) { if (!base::WriteFileDescriptor(fd.get(), props.c_str(), props.size())) {
// TODO(wvk): Add a unittest to cover this failure once the UpgradeArc flow
// requires this function to run successfully.
PLOG(ERROR) << "Unable to write props to " PLOG(ERROR) << "Unable to write props to "
<< kArcVmBootNotificationServerSocketPath; << kArcVmBootNotificationServerSocketPath;
return false; return false;
...@@ -860,6 +863,10 @@ void SetArcVmBootNotificationServerAddressForTesting( ...@@ -860,6 +863,10 @@ void SetArcVmBootNotificationServerAddressForTesting(
g_connect_sleep_duration_initial_for_testing = connect_sleep_duration_initial; g_connect_sleep_duration_initial_for_testing = connect_sleep_duration_initial;
} }
void SetArcVmBootNotificationServerFdForTesting(base::Optional<int> fd) {
g_boot_notification_server_fd = fd;
}
void EnableAdbOverUsbForTesting() { void EnableAdbOverUsbForTesting() {
g_enable_adb_over_usb_for_testing = true; g_enable_adb_over_usb_for_testing = true;
} }
......
...@@ -38,6 +38,9 @@ void SetArcVmBootNotificationServerAddressForTesting( ...@@ -38,6 +38,9 @@ void SetArcVmBootNotificationServerAddressForTesting(
base::TimeDelta connect_timeout_limit, base::TimeDelta connect_timeout_limit,
base::TimeDelta connect_sleep_duration_initial); base::TimeDelta connect_sleep_duration_initial);
// Sets the an FD ConnectToArcVmBootNotificationServer() returns for testing.
void SetArcVmBootNotificationServerFdForTesting(base::Optional<int> fd);
// Enable adb-over-usb and let the adapter start the support daemon for testing. // Enable adb-over-usb and let the adapter start the support daemon for testing.
void EnableAdbOverUsbForTesting(); void EnableAdbOverUsbForTesting();
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include <sys/socket.h> #include <sys/socket.h>
#include <sys/un.h> #include <sys/un.h>
#include <unistd.h>
#include <algorithm> #include <algorithm>
#include <memory> #include <memory>
...@@ -272,6 +273,7 @@ class ArcVmClientAdapterTest : public testing::Test, ...@@ -272,6 +273,7 @@ class ArcVmClientAdapterTest : public testing::Test,
// Reset to the original behavior. // Reset to the original behavior.
RemoveUpstartStartStopJobFailures(); RemoveUpstartStartStopJobFailures();
SetArcVmBootNotificationServerFdForTesting(base::nullopt);
boot_server_ = std::make_unique<TestArcVmBootNotificationServer>(); boot_server_ = std::make_unique<TestArcVmBootNotificationServer>();
boot_server_->Start(); boot_server_->Start();
...@@ -1408,6 +1410,36 @@ TEST_F(ArcVmClientAdapterTest, TestBootNotificationServerIsNotListening) { ...@@ -1408,6 +1410,36 @@ TEST_F(ArcVmClientAdapterTest, TestBootNotificationServerIsNotListening) {
StartMiniArcWithParams(false, {}); StartMiniArcWithParams(false, {});
} }
// Tests that UpgradeArc() still succeeds even when sending the upgrade props
// to the boot notification server fails.
// TODO(wvk): Once mini-VM is implemented, UpgradeArc(true) should be rewritten
// to UpgradeArc(false).
TEST_F(ArcVmClientAdapterTest, UpgradeArc_SendPropFail) {
SetValidUserInfo();
StartMiniArc();
// Let ConnectToArcVmBootNotificationServer() return an invalid FD.
SetArcVmBootNotificationServerFdForTesting(-1);
UpgradeArc(true);
ASSERT_TRUE(GetTestConciergeClient()->start_arc_vm_called());
}
// Tests that UpgradeArc() still succeeds even when sending the upgrade props
// to the boot notification server fails.
// TODO(wvk): Rewrite this test too.
TEST_F(ArcVmClientAdapterTest, UpgradeArc_SendPropFailNotWritable) {
SetValidUserInfo();
StartMiniArc();
// Let ConnectToArcVmBootNotificationServer() return dup(STDIN_FILENO) which
// is not writable.
SetArcVmBootNotificationServerFdForTesting(STDIN_FILENO);
UpgradeArc(true);
ASSERT_TRUE(GetTestConciergeClient()->start_arc_vm_called());
}
struct DalvikMemoryProfileTestParam { struct DalvikMemoryProfileTestParam {
// Requested profile. // Requested profile.
StartParams::DalvikMemoryProfile profile; StartParams::DalvikMemoryProfile profile;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment