blob: d2947a16698cd836c774d1a2e5a88b79f33aeef7 [file] [log] [blame]
Matt Spinler18c42b02020-06-02 15:59:50 -05001/**
2 * Copyright © 2020 IBM Corporation
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
17#include "extensions/openpower-pels/device_callouts.hpp"
18#include "extensions/openpower-pels/paths.hpp"
19
20#include <fstream>
21
22#include <gtest/gtest.h>
23
24using namespace openpower::pels;
25using namespace openpower::pels::device_callouts;
26namespace fs = std::filesystem;
27
28// The callout JSON looks like:
29// "I2C":
30// "<bus>":
31// "<address>":
32// "Callouts": ...
33//
34// "FSI":
35// "<fsi link>":
36// "Callouts": ...
37//
38// "FSI-I2C":
39// "<fsi link>":
40// "<bus>":
41// "<address>":
42// "Callouts": ...
43//
44// "FSI-SPI":
45// "<fsi link>":
46// "<bus>":
47// "Callouts": ...
48
49const auto calloutJSON = R"(
50{
51 "I2C":
52 {
53 "0":
54 {
55 "32":
56 {
57 "Callouts":[
58 {
59 "Name": "/chassis/motherboard/cpu0",
60 "LocationCode": "P1-C19",
61 "Priority": "H"
62 }
63 ],
64 "Dest": "proc-0 target"
65 },
66 "81":
67 {
68 "Callouts":[
69 {
70 "Name": "/chassis/motherboard/cpu0",
71 "LocationCode": "P1-C19",
72 "Priority": "H"
73 }
74 ],
75 "Dest": "proc-0 target"
76 }
77 },
78 "14":
79 {
80 "112":
81 {
82 "Callouts":[
83 {
84 "Name": "/chassis/motherboard/cpu0",
85 "LocationCode": "P1-C19",
86 "Priority": "H"
87 }
88 ],
89 "Dest": "proc-0 target"
90 },
91 "114":
92 {
93 "Callouts":[
94 {
95 "Name": "/chassis/motherboard/cpu0",
96 "LocationCode": "P1-C19",
97 "Priority": "H"
98 },
99 {
100 "Name": "/chassis/motherboard",
101 "LocationCode": "P1",
102 "Priority": "M"
103 }
104 ],
105 "Dest": "proc-0 target"
106 }
107 }
108 },
109 "FSI":
110 {
111 "0":
112 {
113 "Callouts":[
114 {
115 "Name": "/chassis/motherboard/cpu0",
116 "LocationCode": "P1-C19",
117 "Priority": "H"
118 }
119 ],
120 "Dest": "proc-0 target"
121 },
122 "0-1":
123 {
124 "Callouts":[
125 {
126 "Name": "/chassis/motherboard/cpu0",
127 "LocationCode": "P1-C19",
128 "Priority": "H",
129 "MRU": "core"
130 }
131 ],
132 "Dest": "proc-0 target"
133 }
134 },
135 "FSI-I2C":
136 {
137 "0-3":
138 {
139 "7":
140 {
141 "24":
142 {
143 "Callouts":[
144 {
145 "Name": "/chassis/motherboard/cpu0",
146 "LocationCode": "P1-C19",
147 "Priority": "H"
148 }
149 ],
150 "Dest": "proc-0 target"
151 },
152 "25":
153 {
154 "Callouts":[
155 {
156 "Name": "/chassis/motherboard/cpu5",
157 "LocationCode": "P1-C25",
158 "Priority": "H"
159 },
160 {
161 "Name": "/chassis/motherboard",
162 "LocationCode": "P1",
163 "Priority": "M"
164 },
165 {
166 "Name": "/chassis/motherboard/bmc",
167 "LocationCode": "P2",
168 "Priority": "L"
169 }
170 ],
171 "Dest": "proc-5 target"
172 }
173 }
174 }
175 },
176 "FSI-SPI":
177 {
178 "8":
179 {
180 "3":
181 {
182 "Callouts":[
183 {
184 "Name": "/chassis/motherboard/cpu0",
185 "LocationCode": "P1-C19",
186 "Priority": "H"
187 }
188 ],
189 "Dest": "proc-0 target"
190 },
191 "4":
192 {
193 "Callouts":[
194 {
195 "Name": "/chassis/motherboard/cpu0",
196 "LocationCode": "P1-C19",
197 "Priority": "H"
198 }
199 ],
200 "Dest": "proc-0 target"
201 }
202 }
203 }
204})"_json;
205
206class DeviceCalloutsTest : public ::testing::Test
207{
208 public:
209 static void SetUpTestCase()
210 {
211 dataPath = getPELReadOnlyDataPath();
212 std::ofstream file{dataPath / filename};
213 file << calloutJSON.dump();
214 }
215
216 static void TearDownTestCase()
217 {
218 fs::remove_all(dataPath);
219 }
220
221 static std::string filename;
222 static fs::path dataPath;
223};
224
225std::string DeviceCalloutsTest::filename = "systemA_dev_callouts.json";
226fs::path DeviceCalloutsTest::dataPath;
227
228// Test looking up the JSON file based on the system compatible names
229TEST_F(DeviceCalloutsTest, getJSONFilenameTest)
230{
231 {
232 std::vector<std::string> compatibles{"system1", "systemA", "system3"};
233 EXPECT_EQ(util::getJSONFilename(compatibles),
234 fs::path{dataPath / filename});
235 }
236
237 // Actual filename not in compatibles
238 {
239 std::vector<std::string> compatibles{"system5", "system6"};
240 EXPECT_THROW(util::getJSONFilename(compatibles), std::invalid_argument);
241 }
242}