From 6f81601756cfd132e6a6ce6d9f5f2df2cb037685 Mon Sep 17 00:00:00 2001 From: "A. Cody Schuffelen" Date: Thu, 11 Jun 2026 16:06:57 +0000 Subject: [PATCH] Remove base/cvd/cuttlefish/host/commands/cvd/unittests/server These files are unused. --- .../cvd/unittests/server/autogen_ids_test.cpp | 71 --------- .../cvd/unittests/server/basic_test.cpp | 52 ------- .../cvd/unittests/server/clear_test.cpp | 76 ---------- .../cvd/unittests/server/cmd_runner.cpp | 62 -------- .../cvd/unittests/server/cmd_runner.h | 72 --------- .../unittests/server/collect_flags_test.cpp | 61 -------- .../cvd/unittests/server/help_test.cpp | 140 ------------------ .../unittests/server/instance_ids_test.cpp | 77 ---------- .../cvd/unittests/server/snapshot_test.cpp | 87 ----------- .../unittests/server/snapshot_test_helper.cpp | 45 ------ .../commands/cvd/unittests/server/utils.cpp | 30 ---- .../commands/cvd/unittests/server/utils.h | 24 --- 12 files changed, 797 deletions(-) delete mode 100644 base/cvd/cuttlefish/host/commands/cvd/unittests/server/autogen_ids_test.cpp delete mode 100644 base/cvd/cuttlefish/host/commands/cvd/unittests/server/basic_test.cpp delete mode 100644 base/cvd/cuttlefish/host/commands/cvd/unittests/server/clear_test.cpp delete mode 100644 base/cvd/cuttlefish/host/commands/cvd/unittests/server/cmd_runner.cpp delete mode 100644 base/cvd/cuttlefish/host/commands/cvd/unittests/server/cmd_runner.h delete mode 100644 base/cvd/cuttlefish/host/commands/cvd/unittests/server/collect_flags_test.cpp delete mode 100644 base/cvd/cuttlefish/host/commands/cvd/unittests/server/help_test.cpp delete mode 100644 base/cvd/cuttlefish/host/commands/cvd/unittests/server/instance_ids_test.cpp delete mode 100644 base/cvd/cuttlefish/host/commands/cvd/unittests/server/snapshot_test.cpp delete mode 100644 base/cvd/cuttlefish/host/commands/cvd/unittests/server/snapshot_test_helper.cpp delete mode 100644 base/cvd/cuttlefish/host/commands/cvd/unittests/server/utils.cpp delete mode 100644 base/cvd/cuttlefish/host/commands/cvd/unittests/server/utils.h diff --git a/base/cvd/cuttlefish/host/commands/cvd/unittests/server/autogen_ids_test.cpp b/base/cvd/cuttlefish/host/commands/cvd/unittests/server/autogen_ids_test.cpp deleted file mode 100644 index d5cfe54578e..00000000000 --- a/base/cvd/cuttlefish/host/commands/cvd/unittests/server/autogen_ids_test.cpp +++ /dev/null @@ -1,71 +0,0 @@ -// -// Copyright (C) 2023 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 - -#include - -#include "cuttlefish/common/libs/utils/contains.h" -#include "cuttlefish/host/commands/cvd/cli/types.h" -#include "cuttlefish/host/commands/cvd/unittests/server/cmd_runner.h" -#include "cuttlefish/host/commands/cvd/unittests/server/utils.h" - -namespace cuttlefish { - -TEST(CvdAutoGenId, CvdTwoFollowedByFive) { - cvd_common::Envs envs; - envs["HOME"] = StringFromEnv("HOME", ""); - CmdRunner::Run("cvd reset -y", envs); - - cvd_common::Args start_two_instances_args{ - "cvd", - "start", - "--report_anonymous_usage_stats=yes", - "--daemon", - "--norestart_subprocesses", - "--num_instances=2"}; - cvd_common::Args start_three_instances_args{ - "cvd", - "start", - "--report_anonymous_usage_stats=yes", - "--daemon", - "--norestart_subprocesses", - "--num_instances=3"}; - - auto cmd_start_two = CmdRunner::Run(start_two_instances_args, envs); - ASSERT_TRUE(cmd_start_two.Success()) << cmd_start_two.Stderr(); - auto cmd_fleet = CmdRunner::Run("cvd fleet", envs); - ASSERT_TRUE(cmd_fleet.Success()) << cmd_fleet.Stderr(); - ASSERT_EQ(NumberOfOccurrences(cmd_fleet.Stdout(), "instance_name"), 2) - << cmd_fleet.Stdout(); - - auto cmd_start_three = CmdRunner::Run(start_three_instances_args, envs); - ASSERT_TRUE(cmd_start_three.Success()) << cmd_start_three.Stderr(); - cmd_fleet = CmdRunner::Run("cvd fleet", envs); - ASSERT_TRUE(cmd_fleet.Success()) << cmd_fleet.Stderr(); - ASSERT_EQ(NumberOfOccurrences(cmd_fleet.Stdout(), "instance_name"), 5) - << cmd_fleet.Stdout(); - - auto cmd_stop = CmdRunner::Run("cvd reset -y", envs); - ASSERT_TRUE(cmd_stop.Success()) << cmd_stop.Stderr(); - - cmd_fleet = CmdRunner::Run("cvd fleet", envs); - ASSERT_FALSE(Contains(cmd_fleet.Stdout(), "instance_name")); - - // clean up for the next test - CmdRunner::Run("cvd reset -y", envs); -} - -} // namespace cuttlefish diff --git a/base/cvd/cuttlefish/host/commands/cvd/unittests/server/basic_test.cpp b/base/cvd/cuttlefish/host/commands/cvd/unittests/server/basic_test.cpp deleted file mode 100644 index 45df17425e5..00000000000 --- a/base/cvd/cuttlefish/host/commands/cvd/unittests/server/basic_test.cpp +++ /dev/null @@ -1,52 +0,0 @@ -// -// Copyright (C) 2023 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 - -#include - -#include "cuttlefish/common/libs/utils/contains.h" -#include "cuttlefish/host/commands/cvd/cli/types.h" -#include "cuttlefish/host/commands/cvd/unittests/server/cmd_runner.h" - -namespace cuttlefish { - -TEST(CvdBasic, CvdDefaultStart) { - cvd_common::Envs envs; - const auto home_dir = StringFromEnv("HOME", ""); - envs["HOME"] = home_dir; - CmdRunner::Run("cvd reset -y", envs); - - cvd_common::Args start_args{"cvd", "start", - "--report_anonymous_usage_stats=yes", "--daemon"}; - - auto cmd_start = CmdRunner::Run(start_args, envs); - ASSERT_TRUE(cmd_start.Success()) << cmd_start.Stderr(); - - auto cmd_fleet = CmdRunner::Run("cvd fleet", envs); - ASSERT_TRUE(cmd_fleet.Success()) << cmd_fleet.Stderr(); - ASSERT_TRUE(Contains(cmd_fleet.Stdout(), home_dir)); - - auto cmd_stop = CmdRunner::Run("cvd stop", envs); - ASSERT_TRUE(cmd_stop.Success()) << cmd_stop.Stderr(); - - cmd_fleet = CmdRunner::Run("cvd fleet", envs); - ASSERT_FALSE(Contains(cmd_fleet.Stdout(), home_dir)); - - // clean up for the next test - CmdRunner::Run("cvd reset -y", envs); -} - -} // namespace cuttlefish diff --git a/base/cvd/cuttlefish/host/commands/cvd/unittests/server/clear_test.cpp b/base/cvd/cuttlefish/host/commands/cvd/unittests/server/clear_test.cpp deleted file mode 100644 index 40712eef060..00000000000 --- a/base/cvd/cuttlefish/host/commands/cvd/unittests/server/clear_test.cpp +++ /dev/null @@ -1,76 +0,0 @@ -// -// Copyright (C) 2023 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 - -#include - -#include "cuttlefish/common/libs/utils/contains.h" -#include "cuttlefish/host/commands/cvd/cli/types.h" -#include "cuttlefish/host/commands/cvd/unittests/server/cmd_runner.h" -#include "cuttlefish/host/commands/cvd/unittests/server/utils.h" - -namespace cuttlefish { - -TEST(CvdClear, ClearAfterThreeStarts) { - cvd_common::Envs envs; - envs["HOME"] = StringFromEnv("HOME", ""); - CmdRunner::Run("cvd reset -y", envs); - - cvd_common::Args start_two_instances_args{ - "cvd", - "start", - "--report_anonymous_usage_stats=yes", - "--daemon", - "--norestart_subprocesses", - "--num_instances=2"}; - cvd_common::Args start_three_instances_args{ - "cvd", - "start", - "--report_anonymous_usage_stats=yes", - "--daemon", - "--norestart_subprocesses", - "--num_instances=3"}; - cvd_common::Args start_one_instances_args{ - "cvd", - "start", - "--report_anonymous_usage_stats=yes", - "--daemon", - "--norestart_subprocesses", - "--num_instances=1"}; - - auto cmd_start_two = CmdRunner::Run(start_two_instances_args, envs); - ASSERT_TRUE(cmd_start_two.Success()) << cmd_start_two.Stderr(); - auto cmd_start_three = CmdRunner::Run(start_three_instances_args, envs); - ASSERT_TRUE(cmd_start_three.Success()) << cmd_start_three.Stderr(); - auto cmd_start_one = CmdRunner::Run(start_one_instances_args, envs); - ASSERT_TRUE(cmd_start_one.Success()) << cmd_start_one.Stderr(); - - auto cmd_fleet = CmdRunner::Run("cvd fleet", envs); - ASSERT_TRUE(cmd_fleet.Success()) << cmd_fleet.Stderr(); - ASSERT_EQ(NumberOfOccurrences(cmd_fleet.Stdout(), "instance_name"), 2 + 3 + 1) - << cmd_fleet.Stdout(); - - auto cmd_stop = CmdRunner::Run("cvd clear", envs); - ASSERT_TRUE(cmd_stop.Success()) << cmd_stop.Stderr(); - - cmd_fleet = CmdRunner::Run("cvd fleet", envs); - ASSERT_FALSE(Contains(cmd_fleet.Stdout(), "instance_name")); - - // clean up for the next test - CmdRunner::Run("cvd reset -y", envs); -} - -} // namespace cuttlefish diff --git a/base/cvd/cuttlefish/host/commands/cvd/unittests/server/cmd_runner.cpp b/base/cvd/cuttlefish/host/commands/cvd/unittests/server/cmd_runner.cpp deleted file mode 100644 index 8770a651872..00000000000 --- a/base/cvd/cuttlefish/host/commands/cvd/unittests/server/cmd_runner.cpp +++ /dev/null @@ -1,62 +0,0 @@ -// -// Copyright (C) 2023 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 "cuttlefish/host/commands/cvd/unittests/server/cmd_runner.h" - -#include "absl/strings/str_split.h" - -namespace cuttlefish { - -CmdResult::CmdResult(const std::string& stdout_str, - const std::string& stderr_str, const int ret_code) - : stdout_{stdout_str}, stderr_{stderr_str}, code_{ret_code} {} - -CmdResult CmdRunner::Run(const cvd_common::Args& args, - const cvd_common::Envs& envs) { - if (args.empty() || args.front().empty()) { - return CmdResult("", "Empty or invalid command", -1); - } - const auto& cmd = args.front(); - cvd_common::Args cmd_args{args.begin() + 1, args.end()}; - CmdRunner cmd_runner(Command(cmd), cmd_args, envs); - return cmd_runner.Run(); -} - -CmdResult CmdRunner::Run(const std::string& args, - const cvd_common::Envs& envs) { - return CmdRunner::Run(absl::StrSplit(args, ' ', absl::SkipEmpty()), envs); -} - -CmdRunner::CmdRunner(Command&& cmd, const cvd_common::Args& args, - const cvd_common::Envs& envs) - : cmd_(std::move(cmd)) { - for (const auto& arg : args) { - cmd_.AddParameter(arg); - } - for (const auto& [key, value] : envs) { - cmd_.AddEnvironmentVariable(key, value); - } -} - -CmdResult CmdRunner::Run() { - std::string stdout_str; - std::string stderr_str; - auto ret_code = - RunWithManagedStdio(std::move(cmd_), nullptr, std::addressof(stdout_str), - std::addressof(stderr_str)); - return CmdResult(stdout_str, stderr_str, ret_code); -} - -} // namespace cuttlefish diff --git a/base/cvd/cuttlefish/host/commands/cvd/unittests/server/cmd_runner.h b/base/cvd/cuttlefish/host/commands/cvd/unittests/server/cmd_runner.h deleted file mode 100644 index 9269a71259c..00000000000 --- a/base/cvd/cuttlefish/host/commands/cvd/unittests/server/cmd_runner.h +++ /dev/null @@ -1,72 +0,0 @@ -// -// Copyright (C) 2023 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. - -#pragma once - -#include -#include -#include -#include - -#include "cuttlefish/common/libs/utils/contains.h" -#include "cuttlefish/common/libs/utils/environment.h" -#include "cuttlefish/common/libs/utils/files.h" -#include "cuttlefish/common/libs/utils/subprocess.h" -#include "cuttlefish/host/commands/cvd/cli/types.h" - -namespace cuttlefish { - -class CmdResult { - public: - CmdResult(const std::string& stdout, const std::string& stderr, - const int ret_code); - const std::string& Stdout() const { return stdout_; } - const std::string& Stderr() const { return stderr_; } - int Code() const { return code_; } - bool Success() const { return code_ == 0; } - - private: - std::string stdout_; - std::string stderr_; - int code_; -}; - -class CmdRunner { - public: - template < - typename... CmdArgs, - typename std::enable_if<(sizeof...(CmdArgs) >= 1), bool>::type = true> - static CmdResult Run(const std::string& exec, const cvd_common::Envs& envs, - CmdArgs&&... cmd_args) { - cvd_common::Args args; - args.reserve(sizeof...(CmdArgs)); - (args.emplace_back(std::forward(cmd_args)), ...); - CmdRunner cmd_runner(Command(exec), args, envs); - return cmd_runner.Run(); - } - static CmdResult Run(const cvd_common::Args& args, - const cvd_common::Envs& envs); - static CmdResult Run(const std::string& args, const cvd_common::Envs& envs); - - private: - CmdRunner(Command&& cmd, const cvd_common::Args& args, - const cvd_common::Envs& envs); - - CmdResult Run(); - - Command cmd_; -}; - -} // namespace cuttlefish diff --git a/base/cvd/cuttlefish/host/commands/cvd/unittests/server/collect_flags_test.cpp b/base/cvd/cuttlefish/host/commands/cvd/unittests/server/collect_flags_test.cpp deleted file mode 100644 index 1d334f0d84b..00000000000 --- a/base/cvd/cuttlefish/host/commands/cvd/unittests/server/collect_flags_test.cpp +++ /dev/null @@ -1,61 +0,0 @@ -// -// Copyright (C) 2023 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 -#include -#include - -#include - -#include - -#include "cuttlefish/host/commands/cvd/cli/types.h" -#include "cuttlefish/host/commands/cvd/unittests/server/cmd_runner.h" -#include "cuttlefish/host/commands/cvd/utils/flags_collector.h" - -namespace cuttlefish { - -TEST(CvdHelpFlagCollect, LauncCvd) { - cvd_common::Envs envs; - const auto home_dir = StringFromEnv("HOME", ""); - envs["HOME"] = home_dir; - const auto android_host_out = StringFromEnv( - "ANDROID_HOST_OUT", - android::base::Dirname(android::base::GetExecutableDirectory())); - envs["ANDROID_HOST_OUT"] = android_host_out; - const auto launch_cvd_path = android_host_out + "/bin/launch_cvd"; - if (!FileExists(launch_cvd_path)) { - GTEST_SKIP() << "Can't find " << launch_cvd_path << " for testing."; - } - CmdRunner::Run("cvd kill-server", envs); - cvd_common::Args helpxml_args{launch_cvd_path, "--helpxml"}; - - auto cmd_help_xml = CmdRunner::Run(helpxml_args, envs); - auto flags_opt = CollectFlagsFromHelpxml(cmd_help_xml.Stdout()); - - ASSERT_FALSE(cmd_help_xml.Stdout().empty()) << "output shouldn't be empty."; - ASSERT_TRUE(flags_opt); - auto& flags = *flags_opt; - auto daemon_flag_itr = std::find_if( - flags.cbegin(), flags.cend(), - [](const FlagInfoPtr& ptr) { return (ptr && ptr->Name() == "daemon"); }); - auto bad_flag_itr = std::find_if( - flags.cbegin(), flags.cend(), - [](const FlagInfoPtr& ptr) { return (ptr && ptr->Name() == "@bad@"); }); - ASSERT_NE(daemon_flag_itr, flags.cend()); - ASSERT_EQ(bad_flag_itr, flags.cend()); -} - -} // namespace cuttlefish diff --git a/base/cvd/cuttlefish/host/commands/cvd/unittests/server/help_test.cpp b/base/cvd/cuttlefish/host/commands/cvd/unittests/server/help_test.cpp deleted file mode 100644 index c269c7ea793..00000000000 --- a/base/cvd/cuttlefish/host/commands/cvd/unittests/server/help_test.cpp +++ /dev/null @@ -1,140 +0,0 @@ -// -// Copyright (C) 2023 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 -#include - -#include - -#include "cuttlefish/common/libs/utils/contains.h" -#include "cuttlefish/host/commands/cvd/cli/types.h" -#include "cuttlefish/host/commands/cvd/unittests/server/cmd_runner.h" - -namespace cuttlefish { -namespace { - -bool ContainsAll(const std::string& stream, - const std::vector& tokens) { - for (const auto& token : tokens) { - if (!Contains(stream, token)) { - return false; - } - } - return true; -} - -/* - * Sees if this might be cvd --help output. - * - * Not very accurate. - */ -bool MaybeCvdHelp(const CmdResult& result) { - const auto& stdout = result.Stdout(); - return ContainsAll(stdout, {"help", "start", "stop", "fleet"}); -} - -bool MaybeCvdStop(const CmdResult& result) { - const auto& stderr = result.Stderr(); - const auto& stdout = result.Stdout(); - return Contains(stderr, "cvd_internal_stop") || - Contains(stdout, "cvd_internal_stop") || - Contains(stderr, "stop_cvd") || Contains(stdout, "stop_cvd"); -} - -bool MaybeCvdStart(const CmdResult& result) { - const auto& stdout = result.Stdout(); - return ContainsAll(stdout, {"vhost", "modem", "daemon", "adb"}); -} - -} // namespace - -TEST(CvdDriver, CvdHelp) { - cvd_common::Envs envs; - CmdRunner::Run("cvd reset -y", envs); - - auto cmd_help = CmdRunner::Run("cvd help", envs); - auto cmd_dash_help = CmdRunner::Run("cvd --help", envs); - - ASSERT_TRUE(cmd_help.Success()) << cmd_help.Stderr(); - ASSERT_TRUE(MaybeCvdHelp(cmd_help)); - ASSERT_TRUE(cmd_dash_help.Success()) << cmd_dash_help.Stderr(); - ASSERT_TRUE(MaybeCvdHelp(cmd_dash_help)); - - // clean up for the next test - CmdRunner::Run("cvd reset -y", envs); -} - -TEST(CvdDriver, CvdOnly) { - cvd_common::Envs envs; - CmdRunner::Run("cvd reset -y", envs); - - auto cmd_help = CmdRunner::Run("cvd help", envs); - auto cmd_only = CmdRunner::Run("cvd", envs); - - ASSERT_TRUE(cmd_help.Success()) << cmd_help.Stderr(); - ASSERT_TRUE(cmd_only.Success()) << cmd_only.Stderr(); - ASSERT_EQ(cmd_help.Stdout(), cmd_only.Stdout()); - - // clean up for the next test - CmdRunner::Run("cvd reset -y", envs); -} - -// this test is expected to fail. included proactively. -TEST(CvdDriver, CvdHelpWrong) { - cvd_common::Envs envs; - CmdRunner::Run("cvd reset -y", envs); - - auto cmd_help_ref = CmdRunner::Run("cvd help", envs); - auto cmd_help_wrong = CmdRunner::Run("cvd help not_exist", envs); - - EXPECT_TRUE(cmd_help_ref.Success()) << cmd_help_ref.Stderr(); - EXPECT_TRUE(cmd_help_wrong.Success()) << cmd_help_wrong.Stderr(); - EXPECT_EQ(cmd_help_ref.Stdout(), cmd_help_wrong.Stdout()); - - // clean up for the next test - CmdRunner::Run("cvd reset -y", envs); -} - -TEST(CvdSubtool, CvdStopHelp) { - cvd_common::Envs envs; - CmdRunner::Run("cvd reset -y", envs); - - auto cmd_stop_help = CmdRunner::Run("cvd help stop", envs); - - ASSERT_TRUE(cmd_stop_help.Success()) << cmd_stop_help.Stderr(); - ASSERT_TRUE(MaybeCvdStop(cmd_stop_help)) - << "stderr: " << cmd_stop_help.Stderr() - << "stdout: " << cmd_stop_help.Stdout(); - - // clean up for the next test - CmdRunner::Run("cvd reset -y", envs); -} - -TEST(CvdSubtool, CvdStartHelp) { - cvd_common::Envs envs; - CmdRunner::Run("cvd reset -y", envs); - - auto cmd_start_help = CmdRunner::Run("cvd help start", envs); - - ASSERT_TRUE(cmd_start_help.Success()) << cmd_start_help.Stderr(); - ASSERT_TRUE(MaybeCvdStart(cmd_start_help)) - << "stderr: " << cmd_start_help.Stderr() - << "stdout: " << cmd_start_help.Stdout(); - - // clean up for the next test - CmdRunner::Run("cvd reset -y", envs); -} - -} // namespace cuttlefish diff --git a/base/cvd/cuttlefish/host/commands/cvd/unittests/server/instance_ids_test.cpp b/base/cvd/cuttlefish/host/commands/cvd/unittests/server/instance_ids_test.cpp deleted file mode 100644 index 0f06012ba8e..00000000000 --- a/base/cvd/cuttlefish/host/commands/cvd/unittests/server/instance_ids_test.cpp +++ /dev/null @@ -1,77 +0,0 @@ -// -// Copyright (C) 2023 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 - -#include - -#include "cuttlefish/host/commands/cvd/cli/types.h" -#include "cuttlefish/host/commands/cvd/unittests/server/cmd_runner.h" -#include "cuttlefish/host/commands/cvd/unittests/server/utils.h" - -namespace cuttlefish { - -TEST(CvdInstanceIds, CvdTakenInstanceIds) { - cvd_common::Envs envs; - envs["HOME"] = StringFromEnv("HOME", ""); - CmdRunner::Run("cvd reset -y", envs); - - cvd_common::Args start_1_2_args{"cvd", - "start", - "--report_anonymous_usage_stats=yes", - "--daemon", - "--norestart_subprocesses", - "--instance_nums=1,2"}; - cvd_common::Args start_3_args{"cvd", - "start", - "--report_anonymous_usage_stats=yes", - "--daemon", - "--norestart_subprocesses", - "--instance_nums=3"}; - cvd_common::Args start_4_5_6_args{"cvd", - "start", - "--report_anonymous_usage_stats=yes", - "--daemon", - "--norestart_subprocesses", - "--instance_nums=4,5,6"}; - cvd_common::Args start_5_7_args{"cvd", - "start", - "--report_anonymous_usage_stats=yes", - "--daemon", - "--norestart_subprocesses", - "--instance_nums=4,5,6"}; - - auto cmd_start_1_2 = CmdRunner::Run(start_1_2_args, envs); - auto cmd_start_3 = CmdRunner::Run(start_3_args, envs); - auto cmd_start_4_5_6 = CmdRunner::Run(start_4_5_6_args, envs); - ASSERT_TRUE(cmd_start_1_2.Success()) << cmd_start_1_2.Stderr(); - ASSERT_TRUE(cmd_start_3.Success()) << cmd_start_3.Stderr(); - ASSERT_TRUE(cmd_start_4_5_6.Success()) << cmd_start_4_5_6.Stderr(); - - auto cmd_fleet = CmdRunner::Run("cvd fleet", envs); - ASSERT_TRUE(cmd_fleet.Success()) << cmd_fleet.Stderr(); - ASSERT_EQ(NumberOfOccurrences(cmd_fleet.Stdout(), "instance_name"), 6) - << cmd_fleet.Stdout(); - - auto cmd_3_to_fail = CmdRunner::Run(start_3_args, envs); - auto cmd_5_7_to_fail = CmdRunner::Run(start_5_7_args, envs); - ASSERT_TRUE(cmd_start_3.Success()) << cmd_start_3.Stderr(); - ASSERT_TRUE(cmd_start_4_5_6.Success()) << cmd_start_4_5_6.Stderr(); - - // clean up for the next test - CmdRunner::Run("cvd reset -y", envs); -} - -} // namespace cuttlefish diff --git a/base/cvd/cuttlefish/host/commands/cvd/unittests/server/snapshot_test.cpp b/base/cvd/cuttlefish/host/commands/cvd/unittests/server/snapshot_test.cpp deleted file mode 100644 index 1c5ee6925a2..00000000000 --- a/base/cvd/cuttlefish/host/commands/cvd/unittests/server/snapshot_test.cpp +++ /dev/null @@ -1,87 +0,0 @@ -// -// Copyright (C) 2023 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 -#include - -#include - -#include "cuttlefish/common/libs/utils/contains.h" -#include "cuttlefish/host/commands/cvd/cli/types.h" -#include "cuttlefish/host/commands/cvd/unittests/server/cmd_runner.h" -#include "cuttlefish/host/commands/cvd/unittests/server/snapshot_test_helper.h" - -namespace cuttlefish { -namespace cvdsnapshot { - -TEST_F(CvdSnapshotTest, CvdSuspendResume) { - auto cmd_suspend = CmdRunner::Run("cvd suspend", envs); - ASSERT_TRUE(cmd_suspend.Success()) << cmd_suspend.Stderr(); - - auto cmd_resume = CmdRunner::Run("cvd resume", envs); - ASSERT_TRUE(cmd_resume.Success()) << cmd_resume.Stderr(); - - auto cmd_stop = CmdRunner::Run("cvd stop", envs); - ASSERT_TRUE(cmd_stop.Success()) << cmd_stop.Stderr(); -} - -TEST_F(CvdSnapshotTest, CvdSuspendSnapshotResume) { - auto cmd_suspend = CmdRunner::Run("cvd suspend", envs); - ASSERT_TRUE(cmd_suspend.Success()) << cmd_suspend.Stderr(); - - auto cmd_snapshot = CmdRunner::Run( - "cvd snapshot_take --snapshot_path=/tmp/snapshots/snapshot", envs); - ASSERT_TRUE(cmd_snapshot.Success()) << cmd_snapshot.Stderr(); - - auto cmd_resume = CmdRunner::Run("cvd resume", envs); - ASSERT_TRUE(cmd_resume.Success()) << cmd_resume.Stderr(); - - auto cmd_stop = CmdRunner::Run("cvd stop", envs); - ASSERT_TRUE(cmd_stop.Success()) << cmd_stop.Stderr(); - - auto cmd_rm = CmdRunner::Run("rm -rf /tmp/snapshots/snapshot", envs); - ASSERT_TRUE(cmd_rm.Success()) << cmd_rm.Stderr(); -} - -TEST_F(CvdSnapshotTest, CvdSuspendSnapshotResumeRestore) { - auto cmd_suspend = CmdRunner::Run("cvd suspend", envs); - ASSERT_TRUE(cmd_suspend.Success()) << cmd_suspend.Stderr(); - - auto cmd_snapshot = CmdRunner::Run( - "cvd snapshot_take --snapshot_path=/tmp/snapshots/snapshot", envs); - ASSERT_TRUE(cmd_snapshot.Success()) << cmd_snapshot.Stderr(); - - auto cmd_stop = CmdRunner::Run("cvd stop", envs); - ASSERT_TRUE(cmd_stop.Success()) << cmd_stop.Stderr(); - - // clean up for the next test - CmdRunner::Run("cvd reset -y", envs); - - cvd_common::Args start_args{"cvd", "start", - "--report_anonymous_usage_stats=yes", "--daemon", - "--snapshot_path=/tmp/snapshots/snapshot"}; - - auto cmd_start_2 = CmdRunner::Run(start_args, envs); - ASSERT_TRUE(cmd_start_2.Success()) << cmd_start_2.Stderr(); - - auto cmd_stop_2 = CmdRunner::Run("cvd stop", envs); - ASSERT_TRUE(cmd_stop_2.Success()) << cmd_stop_2.Stderr(); - - auto cmd_rm = CmdRunner::Run("rm -rf /tmp/snapshots/snapshot", envs); - ASSERT_TRUE(cmd_rm.Success()) << cmd_rm.Stderr(); -} - -} // namespace cvdsnapshot -} // namespace cuttlefish diff --git a/base/cvd/cuttlefish/host/commands/cvd/unittests/server/snapshot_test_helper.cpp b/base/cvd/cuttlefish/host/commands/cvd/unittests/server/snapshot_test_helper.cpp deleted file mode 100644 index 128bc3809a0..00000000000 --- a/base/cvd/cuttlefish/host/commands/cvd/unittests/server/snapshot_test_helper.cpp +++ /dev/null @@ -1,45 +0,0 @@ -// -// Copyright (C) 2023 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 - -#include - -#include "cuttlefish/host/commands/cvd/cli/types.h" -#include "cuttlefish/host/commands/cvd/unittests/server/cmd_runner.h" - -namespace cuttlefish { -namespace cvdsnapshot { - -class CvdSnapshotTest : public ::testing::Test { - protected: - void SetUp() override { - CmdRunner::Run("cvd reset -y", envs); - - cvd_common::Args start_args{ - "cvd", "start", "--report_anonymous_usage_stats=yes", "--daemon"}; - - auto cmd_start = CmdRunner::Run(start_args, envs); - ASSERT_TRUE(cmd_start.Success()) << cmd_start.Stderr(); - }; - void TearDown() override { - // clean up for the next test - CmdRunner::Run("cvd reset -y", envs); - } - cvd_common::Envs envs; -}; - -} // namespace cvdsnapshot -} // namespace cuttlefish diff --git a/base/cvd/cuttlefish/host/commands/cvd/unittests/server/utils.cpp b/base/cvd/cuttlefish/host/commands/cvd/unittests/server/utils.cpp deleted file mode 100644 index bbce70a6c55..00000000000 --- a/base/cvd/cuttlefish/host/commands/cvd/unittests/server/utils.cpp +++ /dev/null @@ -1,30 +0,0 @@ -// -// Copyright (C) 2023 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 "cuttlefish/host/commands/cvd/unittests/server/utils.h" - -namespace cuttlefish { - -int NumberOfOccurrences(const std::string& str, const std::string& substr) { - int cnt = 0; - int pos = str.find(substr, 0); - while (pos != std::string::npos) { - ++cnt; - pos = str.find(substr, pos + 1); - } - return cnt; -} - -} // namespace cuttlefish diff --git a/base/cvd/cuttlefish/host/commands/cvd/unittests/server/utils.h b/base/cvd/cuttlefish/host/commands/cvd/unittests/server/utils.h deleted file mode 100644 index 4bddab06e44..00000000000 --- a/base/cvd/cuttlefish/host/commands/cvd/unittests/server/utils.h +++ /dev/null @@ -1,24 +0,0 @@ -// -// Copyright (C) 2023 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. - -#pragma once - -#include - -namespace cuttlefish { - -int NumberOfOccurrences(const std::string& str, const std::string& substr); - -} // namespace cuttlefish