• 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 <algorithm>
17 #include <string>
18 #include <vector>
19 
20 #include <gtest/gtest.h>
21 
22 #include <android-base/file.h>
23 #include <android-base/logging.h>
24 
25 #include "host/commands/cvd/server_command/flags_collector.h"
26 #include "host/commands/cvd/types.h"
27 #include "host/commands/cvd/unittests/server/cmd_runner.h"
28 
29 namespace cuttlefish {
30 
TEST(CvdHelpFlagCollect,LauncCvd)31 TEST(CvdHelpFlagCollect, LauncCvd) {
32   cvd_common::Envs envs;
33   const auto home_dir = StringFromEnv("HOME", "");
34   envs["HOME"] = home_dir;
35   const auto android_host_out = StringFromEnv(
36       "ANDROID_HOST_OUT",
37       android::base::Dirname(android::base::GetExecutableDirectory()));
38   envs["ANDROID_HOST_OUT"] = android_host_out;
39   const auto launch_cvd_path = android_host_out + "/bin/launch_cvd";
40   if (!FileExists(launch_cvd_path)) {
41     GTEST_SKIP() << "Can't find " << launch_cvd_path << " for testing.";
42   }
43   CmdRunner::Run("cvd kill-server", envs);
44   cvd_common::Args helpxml_args{launch_cvd_path, "--helpxml"};
45 
46   auto cmd_help_xml = CmdRunner::Run(helpxml_args, envs);
47   auto flags_opt = CollectFlagsFromHelpxml(cmd_help_xml.Stdout());
48 
49   ASSERT_FALSE(cmd_help_xml.Stdout().empty()) << "output shouldn't be empty.";
50   ASSERT_TRUE(flags_opt);
51   auto& flags = *flags_opt;
52   auto daemon_flag_itr = std::find_if(
53       flags.cbegin(), flags.cend(),
54       [](const FlagInfoPtr& ptr) { return (ptr && ptr->Name() == "daemon"); });
55   auto bad_flag_itr = std::find_if(
56       flags.cbegin(), flags.cend(),
57       [](const FlagInfoPtr& ptr) { return (ptr && ptr->Name() == "@bad@"); });
58   ASSERT_NE(daemon_flag_itr, flags.cend());
59   ASSERT_EQ(bad_flag_itr, flags.cend());
60 }
61 
62 }  // namespace cuttlefish
63