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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
|
#ifndef __FAPItestRc_H
#define __FAPItestRc_H
/**
* @file fapitestRc.H
*
* @brief Test case for FAPI return codes
*/
#include <cxxtest/TestSuite.H>
#include <fapi.H>
using namespace fapi;
class FapitestRc: public CxxTest::TestSuite
{
public:
/**
* @brief Test FAPI return codes #1
*/
void testRc1(void)
{
// Create ReturnCode using default constructor
ReturnCode l_rc;
// Ensure that the embedded return code is success
if (l_rc != FAPI_RC_SUCCESS)
{
TS_FAIL("testRc1. ReturnCode init is not FAPI_RC_SUCCESS");
}
else
{
// Ensure that OK function works
if (l_rc.ok() == false)
{
TS_FAIL("testRc1. ok() returned false");
}
else
{
// Ensure that testing l_rc works
if (l_rc)
{
TS_FAIL("testRc1. testing rc returned true");
}
}
}
return;
}
/**
* @brief Test FAPI return codes #2
*/
void testRc2()
{
// Create ReturnCode using default constructor
ReturnCode l_rc;
// Set the return code to a FAPI code
l_rc = FAPI_RC_FAPI_MASK | 0x05;
// Ensure that the creator is FAPI
ReturnCode::returnCodeCreator l_creator = l_rc.getCreator();
if (l_creator != ReturnCode::CREATOR_FAPI)
{
TS_FAIL("testRc2. Creator is not CREATOR_FAPI");
}
else
{
// Set the return code to a PLAT code
l_rc = FAPI_RC_PLAT_ERR_SEE_DATA;
// Ensure that the creator is PLAT
l_creator = l_rc.getCreator();
if (l_creator != ReturnCode::CREATOR_PLAT)
{
TS_FAIL("testRc2. Creator is not CREATOR_PLAT");
}
else
{
l_rc = 5;
// Ensure that the creator is HWP
l_creator = l_rc.getCreator();
if (l_creator != ReturnCode::CREATOR_HWP)
{
TS_FAIL("testRc2. Creator is not CREATOR_HWP");
}
}
}
return;
}
/**
* @brief Test FAPI return codes #3
*/
void testRc3()
{
uint32_t l_code = 4;
// Create ReturnCode specifying a return code
ReturnCode l_rc(l_code);
// Ensure that the embedded return code is as expected
uint32_t l_codeCheck = l_rc;
if (l_codeCheck != l_code)
{
TS_FAIL("testRc3. Code is not set as desired");
}
else
{
// Ensure that ok function returns false
if (l_rc.ok())
{
TS_FAIL("testRc3. ok returned true");
}
else
{
// Ensure that testing l_rc works
if (!l_rc)
{
TS_FAIL("testRc3. testing rc returned false");
}
}
}
return;
}
/**
* @brief Test FAPI return codes #4
*/
void testRc4()
{
uint32_t l_code = 6;
uint32_t l_code2 = 7;
// Create similar ReturnCodes
ReturnCode l_rc(l_code);
ReturnCode l_rc2(l_code);
// Ensure that the equality comparison returns true
if (!(l_rc == l_rc2))
{
TS_FAIL("testRc4. Equality comparison false");
}
else
{
// Ensure that the inequality comparison returns false
if (l_rc != l_rc2)
{
TS_FAIL("testRc4.Inequality comparison true");
}
else
{
// Change the code of l_rc2
l_rc2 = l_code2;
// Ensure that the equality comparison returns false
if (l_rc == l_rc2)
{
TS_FAIL("testRc4. Equality comparison true");
}
else
{
// Ensure that the inequality comparison returns true
if (!(l_rc != l_rc2))
{
TS_FAIL("testRc4. Inequality comparison false");
}
}
}
}
return;
}
/**
* @brief Test FAPI return codes #5
*/
void testRc5()
{
uint32_t l_code = 6;
uint32_t l_code2 = 7;
// Create a ReturnCode
ReturnCode l_rc(l_code);
// Ensure that the equality comparison returns true when comparing to the
// same return code value
if (!(l_rc == l_code))
{
TS_FAIL("testRc5. 1. Equality comparison false");
}
else
{
// Ensure that the inequality comparison returns false when comparing to
// the same return code value
if (l_rc != l_code)
{
TS_FAIL("testRc5. 2. Inequality comparison true");
}
else
{
// Ensure that the equality comparison returns false when comparing
// to a different return code value
if (l_rc == l_code2)
{
TS_FAIL("testRc5. 3. Equality comparison true");
}
else
{
// Ensure that the inequality comparison returns true when
// comparing to a different return code value
if (!(l_rc != l_code2))
{
TS_FAIL("testRc5. 4. Inequality comparison false");
}
}
}
}
return;
}
/**
* @brief Test FAPI return codes #6
*/
void testRc6()
{
uint32_t l_code = 6;
// Create a ReturnCode
ReturnCode l_rc(l_code);
// Ensure that the getData function returns NULL
void * l_pData = reinterpret_cast<void *> (0x12345678);
l_pData = l_rc.getData();
if (l_pData != NULL)
{
TS_FAIL("testRc6. getData did not return NULL");
}
else
{
// Ensure that the releaseData function returns NULL
l_pData = reinterpret_cast<void *> (0x12345678);
l_pData = l_rc.releaseData();
if (l_pData != NULL)
{
TS_FAIL("testRc6. releaseData did not return NULL");
}
}
return;
}
/**
* @brief Test FAPI return codes #7
*/
void testRc7()
{
uint32_t l_code = 10;
// Create a ReturnCode
ReturnCode l_rc(l_code);
// Assign ReturnCodeData. Note that this should really be an errlHndl_t,
// because the FSP deleteData function will attempt to delete an error
// log, but this is just for test, the data will be released before the
// ReturnCode is destructed.
uint32_t l_myData = 6;
void * l_pMyData = reinterpret_cast<void *> (&l_myData);
(void) l_rc.setData(l_pMyData);
// Ensure that getData retrieves the ReturnCodeData
void * l_pMyDataCheck = l_rc.getData();
if (l_pMyDataCheck != l_pMyData)
{
TS_FAIL("testRc7. getData returned unexpected data ptr");
}
else
{
// Ensure that getData retrieves the ReturnCodeData again
l_pMyDataCheck = NULL;
l_pMyDataCheck = l_rc.getData();
if (l_pMyDataCheck != l_pMyData)
{
TS_FAIL("testRc7. getData returned unexpected data ptr");
}
}
// Release the data to avoid ReturnCode from deleting in on destruction
l_pMyDataCheck = l_rc.releaseData();
return;
}
/**
* @brief Test FAPI return codes #8
*/
void testRc8()
{
uint32_t l_code = 10;
// Create a ReturnCode
ReturnCode l_rc(l_code);
// Assign ReturnCodeData. Note that this should really be an errlHndl_t,
// because the FSP deleteData function will attempt to delete an error
// log, but this is just for test, the data will be released before the
// ReturnCode is destructed.
uint32_t l_myData = 6;
void * l_pMyData = reinterpret_cast<void *> (&l_myData);
(void) l_rc.setData(l_pMyData);
// Ensure that releaseData retrieves the ReturnCodeData
void * l_pMyDataCheck = l_rc.releaseData();
if (l_pMyDataCheck != l_pMyData)
{
TS_FAIL("testRc8. getData returned unexpected data ptr");
}
else
{
// Ensure that releaseData now returns NULL
l_pMyDataCheck = NULL;
l_pMyDataCheck = l_rc.releaseData();
if (l_pMyDataCheck != NULL)
{
TS_FAIL("testRc8. getData returned non NULL ptr");
}
}
return;
}
/**
* @brief Test FAPI return codes #9
*/
void testRc9()
{
uint32_t l_code = 10;
// Create a ReturnCode
ReturnCode l_rc(l_code);
// Assign ReturnCodeData. Note that this should really be an errlHndl_t,
// because the FSP deleteData function will attempt to delete an error
// log, but this is just for test, the data will be released before the
// ReturnCode is destructed.
uint32_t l_myData = 6;
void * l_pMyData = reinterpret_cast<void *> (&l_myData);
(void) l_rc.setData(l_pMyData);
// Create a ReturnCode using the copy constructor
ReturnCode l_rc2(l_rc);
// Ensure that the two ReturnCodes are the same
if (l_rc != l_rc2)
{
TS_FAIL("testRc9. ReturnCodes differ");
}
else
{
// Ensure that getData retrieves the ReturnCodeData from l_rc
void * l_pMyDataCheck = l_rc.getData();
if (l_pMyDataCheck != l_pMyData)
{
TS_FAIL("testRc9. getData returned unexpected data ptr (1)");
}
else
{
// Ensure that getData retrieves the ReturnCodeData from l_rc2
l_pMyDataCheck = NULL;
l_pMyDataCheck = l_rc2.getData();
if (l_pMyDataCheck != l_pMyData)
{
TS_FAIL("testRc9. getData returned unexpected data ptr (2)");
}
}
}
// Release the data to avoid ReturnCode from deleting in on destruction.
// This will release the data from both copies of the ReturnCode.
(void) l_rc.releaseData();
return;
}
/**
* @brief Test FAPI return codes #10
*/
void testRc10()
{
uint32_t l_code = 10;
// Create a ReturnCode
ReturnCode l_rc(l_code);
// Assign ReturnCodeData. Note that this should really be an errlHndl_t,
// because the FSP deleteData function will attempt to delete an error
// log, but this is just for test, the data will be released before the
// ReturnCode is destructed.
uint32_t l_myData = 6;
void * l_pMyData = reinterpret_cast<void *> (&l_myData);
(void) l_rc.setData(l_pMyData);
// Create a ReturnCode using the assignment operator
ReturnCode l_rc2;
l_rc2 = l_rc;
// Ensure that the two ReturnCodes are the same
if (l_rc != l_rc2)
{
TS_FAIL("testRc10. ReturnCodes differ");
}
else
{
// Ensure that releaseData retrieves the ReturnCodeData from l_rc
void * l_pMyDataCheck = l_rc.releaseData();
if (l_pMyDataCheck != l_pMyData)
{
TS_FAIL("testRc10. releaseData returned unexpected data ptr");
}
else
{
// Ensure that releaseData retrieves NULL from l_rc2
l_pMyDataCheck = NULL;
l_pMyDataCheck = l_rc2.releaseData();
if (l_pMyDataCheck != NULL)
{
TS_FAIL("testRc10. releaseData returned non NULL ptr");
}
}
}
return;
}
};
#endif
|