1 //
2 // Copyright (C) 2023 The Android Open Source Project
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15
16 #include <string>
17 #include <vector>
18
19 #include <gtest/gtest.h>
20
21 #include "common/libs/utils/contains.h"
22 #include "host/commands/cvd/types.h"
23 #include "host/commands/cvd/unittests/server/cmd_runner.h"
24 #include "host/commands/cvd/unittests/server/utils.h"
25
26 namespace cuttlefish {
27
TEST(CvdAutoGenId,CvdTwoFollowedByFive)28 TEST(CvdAutoGenId, CvdTwoFollowedByFive) {
29 cvd_common::Envs envs;
30 envs["HOME"] = StringFromEnv("HOME", "");
31 CmdRunner::Run("cvd reset -y", envs);
32
33 cvd_common::Args start_two_instances_args{
34 "cvd",
35 "--disable_default_group",
36 "start",
37 "--report_anonymous_usage_stats=yes",
38 "--daemon",
39 "--norestart_subprocesses",
40 "--num_instances=2"};
41 cvd_common::Args start_three_instances_args{
42 "cvd",
43 "--disable_default_group",
44 "start",
45 "--report_anonymous_usage_stats=yes",
46 "--daemon",
47 "--norestart_subprocesses",
48 "--num_instances=3"};
49
50 auto cmd_start_two = CmdRunner::Run(start_two_instances_args, envs);
51 ASSERT_TRUE(cmd_start_two.Success()) << cmd_start_two.Stderr();
52 auto cmd_fleet = CmdRunner::Run("cvd fleet", envs);
53 ASSERT_TRUE(cmd_fleet.Success()) << cmd_fleet.Stderr();
54 ASSERT_EQ(NumberOfOccurrences(cmd_fleet.Stdout(), "instance_name"), 2)
55 << cmd_fleet.Stdout();
56
57 auto cmd_start_three = CmdRunner::Run(start_three_instances_args, envs);
58 ASSERT_TRUE(cmd_start_three.Success()) << cmd_start_three.Stderr();
59 cmd_fleet = CmdRunner::Run("cvd fleet", envs);
60 ASSERT_TRUE(cmd_fleet.Success()) << cmd_fleet.Stderr();
61 ASSERT_EQ(NumberOfOccurrences(cmd_fleet.Stdout(), "instance_name"), 5)
62 << cmd_fleet.Stdout();
63
64 auto cmd_stop = CmdRunner::Run("cvd reset -y", envs);
65 ASSERT_TRUE(cmd_stop.Success()) << cmd_stop.Stderr();
66
67 cmd_fleet = CmdRunner::Run("cvd fleet", envs);
68 ASSERT_FALSE(Contains(cmd_fleet.Stdout(), "instance_name"));
69
70 // clean up for the next test
71 CmdRunner::Run("cvd reset -y", envs);
72 }
73
74 } // namespace cuttlefish
75