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