-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathverifier_impl_test.cc
146 lines (118 loc) · 5.31 KB
/
verifier_impl_test.cc
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
146
/* Copyright 2019 The Chromium OS Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include <memory>
#include <string>
#include <base/files/file_path.h>
#include <base/files/file_util.h>
#include <google/protobuf/util/message_differencer.h>
#include <gtest/gtest.h>
#include <runtime_probe/proto_bindings/runtime_probe.pb.h>
#include "hardware_verifier/hardware_verifier.pb.h"
#include "hardware_verifier/hw_verification_spec_getter_impl.h"
#include "hardware_verifier/probe_result_getter_impl.h"
#include "hardware_verifier/test_utils.h"
#include "hardware_verifier/verifier_impl.h"
using google::protobuf::util::MessageDifferencer;
namespace hardware_verifier {
namespace {
constexpr auto kPrototxtExtension = ".prototxt";
class FakeVbSystemPropertyGetter : public VbSystemPropertyGetter {
public:
int GetCrosDebug() const override { return 1; }
};
} // namespace
class TestVerifierImpl : public testing::Test {
protected:
void SetUp() override {
pr_getter_.reset(new ProbeResultGetterImpl());
vs_getter_.reset(new HwVerificationSpecGetterImpl(
std::unique_ptr<VbSystemPropertyGetter>(
new FakeVbSystemPropertyGetter())));
hw_verification_report_differencer_.TreatAsSet(
HwVerificationReport::descriptor()->FindFieldByName(
"found_component_infos"));
const auto* category_enum_desc =
runtime_probe::ProbeRequest_SupportCategory_descriptor();
for (int i = 0; i < category_enum_desc->value_count(); ++i) {
const auto* field_desc =
HwVerificationReport_GenericDeviceInfo::descriptor()->FindFieldByName(
category_enum_desc->value(i)->name());
if (field_desc) {
hw_verification_report_differencer_.TreatAsSet(field_desc);
}
}
}
HwVerificationSpec LoadHwVerificationSpec(const base::FilePath& file_path) {
const auto& result = vs_getter_->GetFromFile(file_path);
EXPECT_TRUE(result);
return result.value();
}
runtime_probe::ProbeResult LoadProbeResult(const base::FilePath& file_path) {
const auto& result = pr_getter_->GetFromFile(file_path);
EXPECT_TRUE(result);
return result.value();
}
void TestVerifySuccWithSampleData(const std::string& probe_result_sample_name,
const std::string& spec_sample_name,
const std::string& report_sample_name) {
const auto& probe_result = LoadProbeResult(GetSampleDataPath().Append(
probe_result_sample_name + kPrototxtExtension));
const auto& hw_verification_spec = LoadHwVerificationSpec(
GetSampleDataPath().Append(spec_sample_name + kPrototxtExtension));
const auto& expect_hw_verification_report = LoadHwVerificationReport(
GetSampleDataPath().Append(report_sample_name + kPrototxtExtension));
VerifierImpl verifier;
const auto& actual_hw_verification_report =
verifier.Verify(probe_result, hw_verification_spec);
EXPECT_TRUE(actual_hw_verification_report);
EXPECT_TRUE(hw_verification_report_differencer_.Compare(
actual_hw_verification_report.value(), expect_hw_verification_report));
}
void TestVerifyFailWithSampleData(const std::string& probe_result_sample_name,
const std::string& spec_sample_name) {
const auto& probe_result = LoadProbeResult(GetSampleDataPath().Append(
probe_result_sample_name + kPrototxtExtension));
const auto& hw_verification_spec = LoadHwVerificationSpec(
GetSampleDataPath().Append(spec_sample_name + kPrototxtExtension));
VerifierImpl verifier;
EXPECT_FALSE(verifier.Verify(probe_result, hw_verification_spec));
}
base::FilePath GetSampleDataPath() {
return GetTestDataPath().Append("verifier_impl_sample_data");
}
private:
std::unique_ptr<ProbeResultGetter> pr_getter_;
std::unique_ptr<HwVerificationSpecGetter> vs_getter_;
MessageDifferencer hw_verification_report_differencer_;
};
TEST_F(TestVerifierImpl, TestVerifySuccWithSample1) {
TestVerifySuccWithSampleData("probe_result_1", "hw_verification_spec_1",
"expect_hw_verification_report_1");
}
TEST_F(TestVerifierImpl, TestVerifySuccWithSample2) {
TestVerifySuccWithSampleData("probe_result_2", "hw_verification_spec_1",
"expect_hw_verification_report_2");
}
TEST_F(TestVerifierImpl, TestVerifySuccWithSample3) {
TestVerifySuccWithSampleData("probe_result_3", "hw_verification_spec_1",
"expect_hw_verification_report_3");
}
TEST_F(TestVerifierImpl, TestVerifySuccWithSample4) {
TestVerifySuccWithSampleData("probe_result_4", "hw_verification_spec_1",
"expect_hw_verification_report_4");
}
TEST_F(TestVerifierImpl, TestVerifyFailWithSample1) {
TestVerifyFailWithSampleData("probe_result_bad_1", "hw_verification_spec_1");
}
TEST_F(TestVerifierImpl, TestVerifyFailWithSample2) {
TestVerifyFailWithSampleData("probe_result_bad_2", "hw_verification_spec_1");
}
TEST_F(TestVerifierImpl, TestVerifyFailWithSample3) {
TestVerifyFailWithSampleData("probe_result_1", "hw_verification_spec_bad_1");
}
TEST_F(TestVerifierImpl, TestVerifyFailWithSample4) {
TestVerifyFailWithSampleData("probe_result_1", "hw_verification_spec_bad_2");
}
} // namespace hardware_verifier