-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_utils.h
145 lines (114 loc) · 4.65 KB
/
test_utils.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
// Copyright 2020 The ChromiumOS Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef DLCSERVICE_TEST_UTILS_H_
#define DLCSERVICE_TEST_UTILS_H_
#include <memory>
#include <set>
#include <string>
#include <vector>
#include <base/files/file_path.h>
#include <base/files/scoped_temp_dir.h>
#include <base/test/simple_test_clock.h>
#include <brillo/message_loops/fake_message_loop.h>
#include <dbus/mock_bus.h>
#include <dbus/mock_object_proxy.h>
#include <dlcservice/proto_bindings/dlcservice.pb.h>
#include <imageloader/proto_bindings/imageloader.pb.h>
#include <imageloader/dbus-proxy-mocks.h>
#if USE_LVM_STATEFUL_PARTITION
#include <lvmd/proto_bindings/lvmd.pb.h>
// NOLINTNEXTLINE(build/include_alpha)
#include <lvmd/dbus-proxy-mocks.h>
#endif // USE_LVM_STATEFUL_PARTITION
#include <update_engine/proto_bindings/update_engine.pb.h>
// NOLINTNEXTLINE(build/include_alpha)
#include <update_engine/dbus-proxy-mocks.h>
#include "dlcservice/boot/mock_boot_slot.h"
#include "dlcservice/dlc_base.h"
#include "dlcservice/dlc_service.h"
#include "dlcservice/mock_metrics.h"
#include "dlcservice/mock_state_change_reporter.h"
#include "dlcservice/mock_system_properties.h"
#include "dlcservice/types.h"
#if USE_LVM_STATEFUL_PARTITION
#include "dlcservice/lvm/mock_lvmd_proxy_wrapper.h"
#endif // USE_LVM_STATEFUL_PARTITION
namespace dlcservice {
extern const char kFirstDlc[];
extern const char kSecondDlc[];
extern const char kThirdDlc[];
extern const char kFourthDlc[];
extern const char kScaledDlc[];
extern const char kPackage[];
extern const char kDefaultOmahaUrl[];
MATCHER_P3(CheckDlcStateProto, state, progress, root_path, "") {
return arg.state() == state && arg.progress() == progress &&
arg.root_path() == root_path;
};
MATCHER_P(CheckInstallRequest,
install_request,
"Matches the InstallRequest protobuf") {
return arg.SerializeAsString() == install_request.SerializeAsString();
}
int64_t GetFileSize(const base::FilePath& path);
class BaseTest : public testing::Test {
public:
BaseTest();
BaseTest(const BaseTest&) = delete;
BaseTest& operator=(const BaseTest&) = delete;
void SetUp() override;
void SetUpFilesAndDirectories();
// Will create |path|/|id|/|package|/dlc.img file. Will return the path to the
// generated preloaded image.
base::FilePath SetUpDlcPreloadedImage(const DlcId& id);
// Will create |path|/|id|/|package|/dlc.img file. Will return the path to the
// generated factory install image.
base::FilePath SetUpDlcFactoryImage(const DlcId& id);
// Will create |path|/|id|/|package|/dlc.img file. Will return the path to the
// generated deployed image.
base::FilePath SetUpDlcDeployedImage(const DlcId& id);
// Will create |path/|id|/|package|/dlc_[a|b]/dlc.img files.
void SetUpDlcWithSlots(const DlcId& id);
// Mimics an installation form update_engine on the current boot slot.
void InstallWithUpdateEngine(const std::vector<std::string>& ids);
void SetMountPath(const std::string& mount_path_expected);
protected:
brillo::ErrorPtr err_;
base::ScopedTempDir scoped_temp_dir_;
base::FilePath testdata_path_;
base::FilePath manifest_path_;
base::FilePath preloaded_content_path_;
base::FilePath factory_install_path_;
base::FilePath deployed_content_path_;
base::FilePath content_path_;
base::FilePath prefs_path_;
base::FilePath users_path_;
base::FilePath verification_file_path_;
base::FilePath mount_path_;
base::FilePath resume_in_progress_path_;
std::set<DlcId> supported_dlc_;
#if USE_LVM_STATEFUL_PARTITION
std::unique_ptr<MockLvmdProxyWrapper> mock_lvmd_proxy_wrapper_;
MockLvmdProxyWrapper* mock_lvmd_proxy_wrapper_ptr_;
#endif // USE_LVM_STATEFUL_PARTITION
using ImageLoaderProxyMock = org::chromium::ImageLoaderInterfaceProxyMock;
std::unique_ptr<ImageLoaderProxyMock> mock_image_loader_proxy_;
ImageLoaderProxyMock* mock_image_loader_proxy_ptr_;
scoped_refptr<dbus::MockBus> mock_bus_;
scoped_refptr<dbus::MockObjectProxy> mock_update_engine_object_proxy_;
using UpdateEngineProxyMock = org::chromium::UpdateEngineInterfaceProxyMock;
std::unique_ptr<UpdateEngineProxyMock> mock_update_engine_proxy_;
UpdateEngineProxyMock* mock_update_engine_proxy_ptr_;
std::unique_ptr<MockBootSlot> mock_boot_slot_;
MockBootSlot* mock_boot_slot_ptr_;
MockMetrics* mock_metrics_;
MockSystemProperties* mock_system_properties_;
MockStateChangeReporter mock_state_change_reporter_;
base::SimpleTestClock clock_;
brillo::FakeMessageLoop loop_{&clock_};
private:
base::FilePath SetUpImage(const base::FilePath& root, const DlcId& id);
};
} // namespace dlcservice
#endif // DLCSERVICE_TEST_UTILS_H_