1 /*
2 Copyright (c) 2018, MIPI Alliance, Inc.
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions
7 are met:
8
9 * Redistributions of source code must retain the above copyright
10 notice, this list of conditions and the following disclaimer.
11
12 * Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in
14 the documentation and/or other materials provided with the
15 distribution.
16
17 * Neither the name of the copyright holder nor the names of its
18 contributors may be used to endorse or promote products derived
19 from this software without specific prior written permission.
20
21 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33
34 /*
35 * Contributors:
36 * Norbert Schulz (Intel Corporation) - Initial API and implementation
37 */
38
39 #include "mipi_syst_gtest.h"
40
41 #if defined(MIPI_SYST_PCFG_ENABLE_PLATFORM_STATE_DATA) &&\
42 defined(MIPI_SYST_PCFG_ENABLE_DEFAULT_SCATTER_WRITE) &&\
43 defined(MIPI_SYST_PCFG_ENABLE_STRING_API)
44
45
46 class MipiSysTFixtureDebugString : public MipiSysTFixtureOutput
47 {
48 public:
SetUp()49 void SetUp() {
50 MipiSysTFixtureOutput::SetUp();
51 }
52
TearDown()53 void TearDown(){
54 MipiSysTFixtureOutput::TearDown();
55 }
56
mipi_syst_write_debug_string(struct mipi_syst_handle * svh,struct mipi_syst_msglocation * loc,enum mipi_syst_subtype_string type,enum mipi_syst_severity severity,mipi_syst_u16 len,const char * str)57 const char * mipi_syst_write_debug_string(struct mipi_syst_handle* svh,
58 struct mipi_syst_msglocation* loc,
59 enum mipi_syst_subtype_string type,
60 enum mipi_syst_severity severity,
61 mipi_syst_u16 len,
62 const char * str)
63 {
64 sstr.str("");
65
66 ::mipi_syst_write_debug_string(svh, loc, type, severity, len, str);
67 result = sstr.str();
68
69 return result.c_str();
70 }
71
72 static std::string result;
73 };
74
75 std::string MipiSysTFixtureDebugString::result;
76
TEST_F(MipiSysTFixtureDebugString,syst_string_null)77 TEST_F(MipiSysTFixtureDebugString, syst_string_null)
78 {
79 EXPECT_STREQ(
80 xform(""),
81 MIPI_SYST_DEBUG(NULL, MIPI_SYST_SEVERITY_WARNING, "", 1)
82 );
83
84 EXPECT_STREQ(
85 xform("<D32TS>05012232[typ=2:5 mu=1:2 sev=3 len]<D16>0007<D32>6c756e28<D16>296c<D8>00<FLAG>"),
86 MIPI_SYST_DEBUG(ph, MIPI_SYST_SEVERITY_WARNING, NULL, 1)
87 );
88 }
89
TEST_F(MipiSysTFixtureDebugString,syst_func_enter_output)90 TEST_F(MipiSysTFixtureDebugString, syst_func_enter_output)
91 {
92 EXPECT_STREQ(
93 xform("<D32TS>02012232[typ=2:2 mu=1:2 sev=3 len]<D16>000b<D64>3736353433323130<D16>3938<D8>00<FLAG>"),
94 MIPI_SYST_FUNC_ENTER(ph, MIPI_SYST_SEVERITY_WARNING)
95 );
96 }
97
TEST_F(MipiSysTFixtureDebugString,syst_func_exit_output)98 TEST_F(MipiSysTFixtureDebugString, syst_func_exit_output)
99 {
100 EXPECT_STREQ(
101 xform("<D32TS>03012232[typ=2:3 mu=1:2 sev=3 len]<D16>000b<D64>3736353433323130<D16>3938<D8>00<FLAG>"),
102 MIPI_SYST_FUNC_EXIT(ph, MIPI_SYST_SEVERITY_WARNING)
103 );
104 }
105
106
TEST_F(MipiSysTFixtureDebugString,syst_debugstring_output)107 TEST_F(MipiSysTFixtureDebugString, syst_debugstring_output)
108 {
109 EXPECT_STREQ(
110 xform("<D32TS>01012232[typ=2:1 mu=1:2 sev=3 len]<D16>000c<D64>6f77206f6c6c6548<D32>21646c72<FLAG>"),
111 MIPI_SYST_DEBUG(ph, MIPI_SYST_SEVERITY_WARNING, "Hello world!" , 12)
112 );
113
114 #if defined(MIPI_SYST_PCFG_ENABLE_CHECKSUM)
115 MIPI_SYST_ENABLE_HANDLE_CHECKSUM(ph,1);
116 #if defined(MIPI_SYST_PCFG_LENGTH_FIELD)
117 EXPECT_STREQ(
118 xform("<D32TS>01012632[typ=2:1 mu=1:2 sev=3 len chk]<D16>000c<D64>6f77206f6c6c6548<D32>21646c72<D32>eab806d3<FLAG>"),
119 MIPI_SYST_DEBUG(ph, MIPI_SYST_SEVERITY_WARNING, "Hello world!" , 12)
120 );
121 #else
122 EXPECT_STREQ(
123 xform("<D32TS>01012432[typ=2:1 mu=1:2 sev=3 chk]<D64>6f77206f6c6c6548<D32>21646c72<D32>ff19ff90<FLAG>"),
124 MIPI_SYST_DEBUG(ph, MIPI_SYST_SEVERITY_WARNING, "Hello world!", 12)
125 );
126 #endif
127 MIPI_SYST_ENABLE_HANDLE_CHECKSUM(ph,0);
128 #endif
129
130
131 #if defined(MIPI_SYST_PCFG_ENABLE_ORIGIN_GUID)
132 // {8887160A-C965-463b-9F43-1EFE9FDFE3F9}
133 const struct mipi_syst_guid aguid = MIPI_SYST_GEN_GUID(0x8887160A, 0xC965, 0x463b, 0x9F43, 0x1EFE9FDFE3F9);
134
135 MIPI_SYST_SET_HANDLE_GUID_UNIT(ph, aguid, 7);
136 EXPECT_STREQ(
137 xform("<D32TS>01807252[typ=2:1 mu=0:7 sev=5 len]<D64>3b4665c90a168788<D64>f9e3df9ffe1e439f<D16>000c<D64>6f77206f6c6c6548<D32>21646c72<FLAG>"),
138 MIPI_SYST_DEBUG(ph, MIPI_SYST_SEVERITY_USER1, "Hello world!" , 12)
139 );
140 #endif
141 }
142
143 #if defined(MIPI_SYST_PCFG_ENABLE_LOCATION_RECORD)
TEST_F(MipiSysTFixtureDebugString,syst_debugstring_loc)144 TEST_F(MipiSysTFixtureDebugString, syst_debugstring_loc)
145 {
146 EXPECT_STREQ(
147 xform("<D32TS>01012332[typ=2:1 mu=1:2 sev=3 loc len]<D8>00<D32>5678abcd<D16>000c<D64>6f77206f6c6c6548<D32>21646c72<FLAG>"),
148 MIPI_SYST_DEBUG_LOC16(ph, MIPI_SYST_SEVERITY_WARNING, 0xabcd, "Hello world!" , 12)
149 );
150
151 EXPECT_STREQ(
152 xform("<D32TS>01012332[typ=2:1 mu=1:2 sev=3 loc len]<D8>01<D64>123456780000abcd<D16>000c<D64>6f77206f6c6c6548<D32>21646c72<FLAG>"),
153 MIPI_SYST_DEBUG_LOC32(ph, MIPI_SYST_SEVERITY_WARNING,0xabcd, "Hello world!" , 12)
154 );
155 #if defined(MIPI_SYST_PCFG_ENABLE_LOCATION_ADDRESS)
156 #if defined(MIPI_SYST_PCFG_ENABLE_64BIT_ADDR)
157 EXPECT_STREQ(
158 xform("<D32TS>01012332[typ=2:1 mu=1:2 sev=3 loc len]<D8>03<D64>12345678aabbccdd<D16>000c<D64>6f77206f6c6c6548<D32>21646c72<FLAG>"),
159 MIPI_SYST_DEBUG_LOCADDR(ph, MIPI_SYST_SEVERITY_WARNING, "Hello world!" , 12)
160 );
161 #else
162 EXPECT_STREQ(
163 xform("<D32TS>01012332[typ=2:1 mu=1:2 sev=3 loc len]<D8>02<D32>12345678<D16>000c<D64>6f77206f6c6c6548<D32>21646c72<FLAG>"),
164 MIPI_SYST_DEBUG_LOCADDR(ph, MIPI_SYST_SEVERITY_WARNING, "Hello world!" , 12)
165 );
166 #endif
167 #endif //MIPI_SYST_PCFG_ENABLE_LOCATION_ADDRESS
168 }
169 #endif //MIPI_SYST_PCFG_ENABLE_LOCATION_RECORD
170
TEST_F(MipiSysTFixtureDebugString,syst_debugstring_nolength)171 TEST_F(MipiSysTFixtureDebugString, syst_debugstring_nolength)
172 {
173 MIPI_SYST_ENABLE_HANDLE_LENGTH(ph,0);
174 EXPECT_STREQ(
175 xform("<D32TS>01012032[typ=2:1 mu=1:2 sev=3]<D64>6f77206f6c6c6548<D32>21646c72<FLAG>"),
176 MIPI_SYST_DEBUG(ph, MIPI_SYST_SEVERITY_WARNING, "Hello world!" , 12)
177 );
178
179 MIPI_SYST_ENABLE_HANDLE_LENGTH(ph,1);
180
181 EXPECT_STREQ(
182 xform("<D32TS>01012232[typ=2:1 mu=1:2 sev=3 len]<D16>000c<D64>6f77206f6c6c6548<D32>21646c72<FLAG>"),
183 MIPI_SYST_DEBUG(ph, MIPI_SYST_SEVERITY_WARNING, "Hello world!" , 12)
184 );
185 }
186
TEST_F(MipiSysTFixtureDebugString,syst_func_enter)187 TEST_F(MipiSysTFixtureDebugString, syst_func_enter)
188 {
189 EXPECT_STREQ(
190 xform("<D32TS>02012242[typ=2:2 mu=1:2 sev=4 len]<D16>000b<D64>3736353433323130<D16>3938<D8>00<FLAG>"),
191 MIPI_SYST_FUNC_ENTER(ph, MIPI_SYST_SEVERITY_INFO)
192 );
193
194 #if defined(MIPI_SYST_PCFG_ENABLE_LOCATION_RECORD)
195 EXPECT_STREQ(
196 xform("<D32TS>02012342[typ=2:2 mu=1:2 sev=4 loc len]<D8>00<D32>5678abcd<D16>000b<D64>3736353433323130<D16>3938<D8>00<FLAG>"),
197 MIPI_SYST_FUNC_ENTER_LOC16(ph, MIPI_SYST_SEVERITY_INFO,0xabcd)
198 );
199
200 EXPECT_STREQ(
201 xform("<D32TS>02012342[typ=2:2 mu=1:2 sev=4 loc len]<D8>01<D64>123456780000abcd<D16>000b<D64>3736353433323130<D16>3938<D8>00<FLAG>"),
202 MIPI_SYST_FUNC_ENTER_LOC32(ph, MIPI_SYST_SEVERITY_INFO,0xabcd)
203 );
204 #if defined(MIPI_SYST_PCFG_ENABLE_LOCATION_ADDRESS)
205 #if defined(MIPI_SYST_PCFG_ENABLE_64BIT_ADDR)
206 EXPECT_STREQ(
207 xform("<D32TS>02012342[typ=2:2 mu=1:2 sev=4 loc len]<D8>03<D64>12345678aabbccdd<D16>000b<D64>3736353433323130<D16>3938<D8>00<FLAG>"),
208 MIPI_SYST_FUNC_ENTER_LOCADDR(ph, MIPI_SYST_SEVERITY_INFO)
209 );
210 #else
211 EXPECT_STREQ(
212 xform("<D32TS>02012342[typ=2:2 mu=1:2 sev=4 loc len]<D8>02<D32>12345678<D16>000b<D64>3736353433323130<D16>3938<D8>00<FLAG>"),
213 MIPI_SYST_FUNC_ENTER_LOCADDR(ph, MIPI_SYST_SEVERITY_INFO)
214 );
215 #endif //MIPI_SYST_PCFG_ENABLE_64BIT_ADDR
216 #endif //MIPI_SYST_PCFG_ENABLE_LOCATION_ADDRESS
217 #endif //MIPI_SYST_PCFG_ENABLE_LOCATION_RECORD
218 }
219
TEST_F(MipiSysTFixtureDebugString,syst_func_exit)220 TEST_F(MipiSysTFixtureDebugString, syst_func_exit)
221 {
222 EXPECT_STREQ(
223 xform("<D32TS>03012242[typ=2:3 mu=1:2 sev=4 len]<D16>000b<D64>3736353433323130<D16>3938<D8>00<FLAG>"),
224 MIPI_SYST_FUNC_EXIT(ph, MIPI_SYST_SEVERITY_INFO)
225 );
226
227 #if defined(MIPI_SYST_PCFG_ENABLE_LOCATION_RECORD)
228 EXPECT_STREQ(
229 xform("<D32TS>03012342[typ=2:3 mu=1:2 sev=4 loc len]<D8>00<D32>5678abcd<D16>000b<D64>3736353433323130<D16>3938<D8>00<FLAG>"),
230 MIPI_SYST_FUNC_EXIT_LOC16(ph, MIPI_SYST_SEVERITY_INFO,0xabcd)
231 );
232
233 EXPECT_STREQ(
234 xform("<D32TS>03012342[typ=2:3 mu=1:2 sev=4 loc len]<D8>01<D64>123456780000abcd<D16>000b<D64>3736353433323130<D16>3938<D8>00<FLAG>"),
235 MIPI_SYST_FUNC_EXIT_LOC32(ph, MIPI_SYST_SEVERITY_INFO,0xabcd)
236 );
237 #if defined(MIPI_SYST_PCFG_ENABLE_LOCATION_ADDRESS)
238 #if defined(MIPI_SYST_PCFG_ENABLE_64BIT_ADDR)
239 EXPECT_STREQ(
240 xform("<D32TS>03012342[typ=2:3 mu=1:2 sev=4 loc len]<D8>03<D64>12345678aabbccdd<D16>000b<D64>3736353433323130<D16>3938<D8>00<FLAG>"),
241 MIPI_SYST_FUNC_EXIT_LOCADDR(ph, MIPI_SYST_SEVERITY_INFO)
242 );
243 #else
244 EXPECT_STREQ(
245 xform("<D32TS>03012342[typ=2:3 mu=1:2 sev=4 loc len]<D8>02<D32>12345678<D16>000b<D64>3736353433323130<D16>3938<D8>00<FLAG>"),
246 MIPI_SYST_FUNC_EXIT_LOCADDR(ph, MIPI_SYST_SEVERITY_INFO)
247 );
248 #endif //MIPI_SYST_PCFG_ENABLE_64BIT_ADDR
249 #endif //MIPI_SYST_PCFG_ENABLE_LOCATION_ADDRESS
250 #endif //MIPI_SYST_PCFG_ENABLE_LOCATION_RECORD
251 }
252
253 #if defined(MIPI_SYST_PCFG_ENABLE_LOCATION_RECORD)
TEST_F(MipiSysTFixtureDebugString,syst_debug_assert)254 TEST_F(MipiSysTFixtureDebugString, syst_debug_assert)
255 {
256 MIPI_SYST_ASSERT(ph, MIPI_SYST_SEVERITY_ERROR, 0);
257
258 EXPECT_STREQ(
259 xform("<D32TS>07012222[typ=2:7 mu=1:2 sev=2 len]<D16>0018<D64>7473657474696e75<D64>33323178303a632e<D64>0030203837363534<FLAG>"),
260 result.c_str()
261 );
262
263 result = "";
264 MIPI_SYST_ASSERT(ph, MIPI_SYST_SEVERITY_ERROR, 1);
265
266 EXPECT_STREQ(
267 "",
268 result.c_str()
269 );
270
271 #if defined(MIPI_SYST_PCFG_ENABLE_LOCATION_ADDRESS)
272 MIPI_SYST_ASSERT_LOCADDR(ph, MIPI_SYST_SEVERITY_ERROR, 0);
273 #if defined(MIPI_SYST_PCFG_ENABLE_64BIT_ADDR)
274 EXPECT_STREQ(
275 xform("<D32TS>07012322[typ=2:7 mu=1:2 sev=2 loc len]<D8>03<D64>12345678aabbccdd<D16>0018<D64>7473657474696e75<D64>33323178303a632e<D64>0030203837363534<FLAG>"),
276 result.c_str()
277 );
278 #else
279 EXPECT_STREQ(
280 xform("<D32TS>07012322[typ=2:7 mu=1:2 sev=2 loc len]<D8>02<D32>12345678<D16>0018<D64>7473657474696e75<D64>33323178303a632e<D64>0030203837363534<FLAG>"),
281 result.c_str()
282 );
283 #endif
284 result = "";
285 MIPI_SYST_ASSERT_LOCADDR(ph, MIPI_SYST_SEVERITY_ERROR, 1);
286
287 EXPECT_STREQ(
288 "",
289 result.c_str()
290 );
291 #endif //MIPI_SYST_PCFG_ENABLE_LOCATION_ADDRESS
292
293 MIPI_SYST_ASSERT_LOC16(ph, MIPI_SYST_SEVERITY_ERROR, 0xabcd, 0);
294
295 EXPECT_STREQ(
296 xform("<D32TS>07012322[typ=2:7 mu=1:2 sev=2 loc len]<D8>00<D32>5678abcd<D16>0018<D64>7473657474696e75<D64>33323178303a632e<D64>0030203837363534<FLAG>"),
297 result.c_str()
298 );
299
300 result = "";
301 MIPI_SYST_ASSERT_LOC16(ph, MIPI_SYST_SEVERITY_ERROR,0xabcd, 1);
302
303 EXPECT_STREQ(
304 "",
305 result.c_str()
306 );
307
308 MIPI_SYST_ASSERT_LOC32(ph, MIPI_SYST_SEVERITY_ERROR, 0xabcd, 0);
309
310 EXPECT_STREQ(
311 xform("<D32TS>07012322[typ=2:7 mu=1:2 sev=2 loc len]<D8>01<D64>123456780000abcd<D16>0018<D64>7473657474696e75<D64>33323178303a632e<D64>0030203837363534<FLAG>"),
312 result.c_str()
313 );
314
315 result = "";
316 MIPI_SYST_ASSERT_LOC32(ph, MIPI_SYST_SEVERITY_ERROR, 0xabcd, 1);
317
318 EXPECT_STREQ(
319 "",
320 result.c_str()
321 );
322 }
323 #endif //MIPI_SYST_PCFG_ENABLE_LOCATION_RECORD
324
325 #endif //MIPI_SYST_PCFG_ENABLE_PLATFORM_STATE_DATA && MIPI_SYST_PCFG_ENABLE_DEFAULT_SCATTER_WRITE && MIPI_SYST_PCFG_ENABLE_STRING_API