Android-cuttlefish cvd tool
instance_database_helper.h
Go to the documentation of this file.
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#pragma once
17
18#include <string>
19#include <vector>
20
21#include <gtest/gtest.h>
22
23#include "cuttlefish/host/commands/cvd/instances/cvd_persistent_data.pb.h"
25
26namespace cuttlefish {
27namespace selector {
28
46class CvdInstanceDatabaseTest : public ::testing::Test {
47 protected:
48 enum class ErrorCode : std::int32_t {
49 kOk,
50 kFileError,
51 kInstanceDabaseError,
52 };
53
54 struct SetupError {
56 std::string msg;
57 };
58
61
62 bool SetUpOk() const { return error_.error_code == ErrorCode::kOk; }
63 const std::string& Workspace() const { return workspace_dir_; }
64 /*
65 * Returns a valid host artifacts dir, which is a prerequisite for
66 * InstanceDatabase APIs.
67 */
68 const std::string& HostArtifactsPath() const {
70 }
71
72 // Adds InstanceGroup by:
73 // "mkdir" : Workspace() + "/" + base_name, HostArtifactsPath()
74 // db_.AddInstanceGroup()
75 bool AddGroup(const std::string& base_name,
76 const std::vector<cvd::Instance>& instances);
77 InstanceDatabase& GetDb() { return db_; }
78 const SetupError& Error() const { return error_; }
79
80 private:
81 void ClearWorkspace();
82 bool InitWorkspace();
84 // set error_ when there is an error
85 void SetErrorCode(ErrorCode error_code, const std::string& msg);
86
88 std::string workspace_dir_;
90 std::string db_backing_path_;
93};
94
96
97} // namespace selector
98} // namespace cuttlefish
Definition: instance_database.h:34
Definition: instance_database_helper.h:46
const SetupError & Error() const
Definition: instance_database_helper.h:78
void ClearWorkspace()
Definition: instance_database_helper.cpp:72
std::string db_backing_path_
Definition: instance_database_helper.h:90
const std::string & Workspace() const
Definition: instance_database_helper.h:63
bool InitMockAndroidHostOut()
Definition: instance_database_helper.cpp:95
InstanceDatabase db_
Definition: instance_database_helper.h:92
bool InitWorkspace()
Definition: instance_database_helper.cpp:84
std::string android_artifacts_path_
Definition: instance_database_helper.h:87
InstanceDatabase & GetDb()
Definition: instance_database_helper.h:77
ErrorCode
Definition: instance_database_helper.h:48
~CvdInstanceDatabaseTest()
Definition: instance_database_helper.cpp:67
SetupError error_
Definition: instance_database_helper.h:89
bool SetUpOk() const
Definition: instance_database_helper.h:62
std::string workspace_dir_
Definition: instance_database_helper.h:88
bool AddGroup(const std::string &base_name, const std::vector< cvd::Instance > &instances)
Definition: instance_database_helper.cpp:121
const std::string & HostArtifactsPath() const
Definition: instance_database_helper.h:68
int db_backing_fd_
Definition: instance_database_helper.h:91
CvdInstanceDatabaseTest()
Definition: instance_database_helper.cpp:56
void SetErrorCode(ErrorCode error_code, const std::string &msg)
Definition: instance_database_helper.cpp:78
Definition: alloc_utils.cpp:23
Definition: instance_database_helper.h:54
ErrorCode error_code
Definition: instance_database_helper.h:55
std::string msg
Definition: instance_database_helper.h:56