• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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(CvdInstanceIds,CvdTakenInstanceIds)28 TEST(CvdInstanceIds, CvdTakenInstanceIds) {
29   cvd_common::Envs envs;
30   envs["HOME"] = StringFromEnv("HOME", "");
31   CmdRunner::Run("cvd reset -y", envs);
32 
33   cvd_common::Args start_1_2_args{"cvd",
34                                   "--disable_default_group",
35                                   "start",
36                                   "--report_anonymous_usage_stats=yes",
37                                   "--daemon",
38                                   "--norestart_subprocesses",
39                                   "--instance_nums=1,2"};
40   cvd_common::Args start_3_args{"cvd",
41                                 "--disable_default_group",
42                                 "start",
43                                 "--report_anonymous_usage_stats=yes",
44                                 "--daemon",
45                                 "--norestart_subprocesses",
46                                 "--instance_nums=3"};
47   cvd_common::Args start_4_5_6_args{"cvd",
48                                     "--disable_default_group",
49                                     "start",
50                                     "--report_anonymous_usage_stats=yes",
51                                     "--daemon",
52                                     "--norestart_subprocesses",
53                                     "--instance_nums=4,5,6"};
54   cvd_common::Args start_5_7_args{"cvd",
55                                   "--disable_default_group",
56                                   "start",
57                                   "--report_anonymous_usage_stats=yes",
58                                   "--daemon",
59                                   "--norestart_subprocesses",
60                                   "--instance_nums=4,5,6"};
61 
62   auto cmd_start_1_2 = CmdRunner::Run(start_1_2_args, envs);
63   auto cmd_start_3 = CmdRunner::Run(start_3_args, envs);
64   auto cmd_start_4_5_6 = CmdRunner::Run(start_4_5_6_args, envs);
65   ASSERT_TRUE(cmd_start_1_2.Success()) << cmd_start_1_2.Stderr();
66   ASSERT_TRUE(cmd_start_3.Success()) << cmd_start_3.Stderr();
67   ASSERT_TRUE(cmd_start_4_5_6.Success()) << cmd_start_4_5_6.Stderr();
68 
69   auto cmd_fleet = CmdRunner::Run("cvd fleet", envs);
70   ASSERT_TRUE(cmd_fleet.Success()) << cmd_fleet.Stderr();
71   ASSERT_EQ(NumberOfOccurrences(cmd_fleet.Stdout(), "instance_name"), 6)
72       << cmd_fleet.Stdout();
73 
74   auto cmd_3_to_fail = CmdRunner::Run(start_3_args, envs);
75   auto cmd_5_7_to_fail = CmdRunner::Run(start_5_7_args, envs);
76   ASSERT_TRUE(cmd_start_3.Success()) << cmd_start_3.Stderr();
77   ASSERT_TRUE(cmd_start_4_5_6.Success()) << cmd_start_4_5_6.Stderr();
78 
79   // clean up for the next test
80   CmdRunner::Run("cvd reset -y", envs);
81 }
82 
83 }  // namespace cuttlefish
84