• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //
2 // Copyright (C) 2022 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 "host/commands/cvd/unittests/selector/creation_analyzer_helper.h"
17 
18 #include <android-base/strings.h>
19 
20 #include "host/commands/cvd/types.h"
21 
22 namespace cuttlefish {
23 namespace selector {
24 namespace {
25 
26 // copied from server.h
27 struct CommandInvocation {
28   std::string command;
29   std::vector<std::string> arguments;
30 };
31 
MockParseInvocation(const std::vector<std::string> & args)32 CommandInvocation MockParseInvocation(const std::vector<std::string>& args) {
33   if (args.empty()) {
34     return CommandInvocation{};
35   }
36   if (args[0] != "cvd") {
37     return CommandInvocation{.command = args[0],
38                              .arguments = cvd_common::Args{}};
39   }
40   if (args.size() == 1) {
41     return CommandInvocation{.command = "help",
42                              .arguments = cvd_common::Args{}};
43   }
44   cvd_common::Args program_args{args.begin() + 2, args.end()};
45   return CommandInvocation{.command = args[1], .arguments = program_args};
46 }
47 
48 }  // namespace
49 
CreationInfoGenTest()50 CreationInfoGenTest::CreationInfoGenTest() { Init(); }
Init()51 void CreationInfoGenTest::Init() {
52   const auto& input_param = GetParam();
53   selector_args_ = android::base::Tokenize(input_param.selector_args, " ");
54   auto cmd_invocation =
55       MockParseInvocation(android::base::Tokenize(input_param.cmd_args, " "));
56   sub_cmd_ = cmd_invocation.command;
57   cmd_args_ = std::move(cmd_invocation.arguments);
58   if (!input_param.home.empty()) {
59     envs_["HOME"] = input_param.home;
60   }
61   if (!input_param.android_host_out.empty()) {
62     envs_["ANDROID_HOST_OUT"] = input_param.android_host_out;
63   }
64   expected_output_ = input_param.expected_output.output;
65   expected_success_ = input_param.expected_output.is_success;
66   credential_ = ucred{.pid = getpid(), .uid = getuid(), .gid = getgid()};
67 }
68 
69 }  // namespace selector
70 }  // namespace cuttlefish
71