hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
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
// SPDX-License-Identifier: GPL-2.0
/*
 * Copyright (c) 2014, STMicroelectronics International N.V.
 */
 
/*************************************************************************
 * 1. Includes
 ************************************************************************/
#include "adbg_int.h"
 
/*************************************************************************
 * 2. Definition of external constants and variables
 ************************************************************************/
 
/*************************************************************************
 * 3. File scope types, constants and variables
 ************************************************************************/
 
/*************************************************************************
 * 4. Declaration of file local functions
 ************************************************************************/
 
static bool ADBG_AssertHelper(ADBG_Case_t *const Case_p,
                 const char *const FileName_p,
                 const int LineNumber, const bool ExpressionOK);
 
static const char *ADBG_GetFileBase(const char *const FileName_p);
 
/*************************************************************************
 * 5. Definition of external functions
 ************************************************************************/
bool Do_ADBG_Expect(
   ADBG_Case_t *const Case_p,
   const char *const FileName_p,
   const int LineNumber,
   const int Expected,
   const int Got,
   const char *const GotVarName_p,
   const ADBG_EnumTable_t *const EnumTable_p
   )
{
   if (ADBG_AssertHelper(Case_p, FileName_p, LineNumber, Expected == Got))
       return true;
 
   if (EnumTable_p != NULL) {
       Do_ADBG_Log("%s:%d: %s has an unexpected value: 0x%x = %s, "
               "expected 0x%x = %s",
               ADBG_GetFileBase(FileName_p), LineNumber,
               GotVarName_p,
               Got, Do_ADBG_GetEnumName(Got, EnumTable_p),
               Expected,
               Do_ADBG_GetEnumName(Expected, EnumTable_p));
   } else {
       Do_ADBG_Log(
           "%s:%d: %s has an unexpected value: 0x%x, expected 0x%x",
           ADBG_GetFileBase(FileName_p), LineNumber,
           GotVarName_p, Got, Expected);
   }
 
   return false;
}
 
bool Do_ADBG_ExpectNot(
   ADBG_Case_t *const Case_p,
   const char *const FileName_p,
   const int LineNumber,
   const int NotExpected,
   const int Got,
   const char *const GotVarName_p,
   const ADBG_EnumTable_t *const EnumTable_p
   )
{
   if (ADBG_AssertHelper(Case_p, FileName_p, LineNumber, NotExpected !=
                 Got))
       return true;
 
   if (EnumTable_p != NULL) {
       Do_ADBG_Log("%s:%d: %s has an unexpected value: 0x%x = %s, "
               "expected 0x%x = %s",
               ADBG_GetFileBase(FileName_p), LineNumber,
               GotVarName_p,
               Got, Do_ADBG_GetEnumName(Got, EnumTable_p),
               NotExpected,
               Do_ADBG_GetEnumName(NotExpected, EnumTable_p));
   } else {
       Do_ADBG_Log(
           "%s:%d: %s has an unexpected value: 0x%zu, expected 0x%zu",
           ADBG_GetFileBase(FileName_p), LineNumber,
           GotVarName_p, (size_t)Got, (size_t)NotExpected);
   }
 
   return false;
}
 
bool Do_ADBG_ExpectBuffer(
   ADBG_Case_t *const Case_p,
   const char *const FileName_p,
   const int LineNumber,
   const void *const ExpectedBuffer_p,
   const size_t ExpectedBufferLength,
   const char *const GotBufferName_p,
   const void *const GotBuffer_p,
   const char *const GotBufferLengthName_p,
   const size_t GotBufferLength
   )
{
   if (!ADBG_AssertHelper(Case_p, FileName_p, LineNumber,
                  ExpectedBufferLength == GotBufferLength)) {
       Do_ADBG_Log(
           "%s:%d: %s has an unexpected value: %zu, expected %zu",
           ADBG_GetFileBase(
               FileName_p), LineNumber,
           GotBufferLengthName_p, GotBufferLength,
           ExpectedBufferLength);
       return false;
   }
 
   if (!ADBG_AssertHelper(Case_p, FileName_p, LineNumber,
                  memcmp(ExpectedBuffer_p, GotBuffer_p,
                     ExpectedBufferLength) == 0)) {
       Do_ADBG_Log("%s:%d: %s has an unexpected content:",
               ADBG_GetFileBase(
                   FileName_p), LineNumber, GotBufferName_p);
       Do_ADBG_Log("Got");
       Do_ADBG_HexLog(GotBuffer_p, GotBufferLength, 16);
       Do_ADBG_Log("Expected");
       Do_ADBG_HexLog(ExpectedBuffer_p, ExpectedBufferLength, 16);
       return false;
   }
 
   return true;
}
 
bool Do_ADBG_ExpectPointer(
   ADBG_Case_t *const Case_p,
   const char *const FileName_p,
   const int LineNumber,
   const void *Expected_p,
   const void *Got_p,
   const char *const GotVarName_p
   )
{
   if (ADBG_AssertHelper(Case_p, FileName_p, LineNumber, Expected_p ==
                 Got_p))
       return true;
 
   Do_ADBG_Log("%s:%d: %s has an unexpected value: %p, expected %p",
           ADBG_GetFileBase(FileName_p), LineNumber,
           GotVarName_p, Got_p, Expected_p);
 
   return false;
}
 
 
 
bool Do_ADBG_ExpectPointerNotNULL(
   ADBG_Case_t *const Case_p,
   const char *const FileName_p,
   const int LineNumber,
   const void *Got_p,
   const char *const GotVarName_p
   )
{
   if (ADBG_AssertHelper(Case_p, FileName_p, LineNumber, Got_p != NULL))
       return true;
 
   Do_ADBG_Log("%s:%d: %s has an unexpected value: %p, expected not NULL",
           ADBG_GetFileBase(FileName_p), LineNumber,
           GotVarName_p, Got_p);
 
   return false;
}
 
bool Do_ADBG_ExpectCompareSigned(
   ADBG_Case_t *const Case_p,
   const char *const FileName_p,
   const int LineNumber,
   const long Value1,
   const long Value2,
   const bool Result,
   const char *const Value1Str_p,
   const char *const ComparStr_p,
   const char *const Value2Str_p
   )
{
   if (!ADBG_AssertHelper(Case_p, FileName_p, LineNumber, Result)) {
       Do_ADBG_Log(
           "%s:%d: Expression \"%s %s %s\" (%ld %s %ld) is false",
           ADBG_GetFileBase(FileName_p), LineNumber,
           Value1Str_p, ComparStr_p, Value2Str_p,
           Value1, ComparStr_p, Value2);
   }
   return Result;
}
 
bool Do_ADBG_ExpectCompareUnsigned(
   ADBG_Case_t *const Case_p,
   const char *const FileName_p,
   const int LineNumber,
   const unsigned long Value1,
   const unsigned long Value2,
   const bool Result,
   const char *const Value1Str_p,
   const char *const ComparStr_p,
   const char *const Value2Str_p
   )
{
   if (!ADBG_AssertHelper(Case_p, FileName_p, LineNumber, Result)) {
       Do_ADBG_Log(
           "%s:%d: Expression \"%s %s %s\" (%lu %s %lu) is false",
           ADBG_GetFileBase(FileName_p), LineNumber,
           Value1Str_p, ComparStr_p, Value2Str_p,
           Value1, ComparStr_p, Value2);
   }
   return Result;
}
 
 
bool Do_ADBG_ExpectComparePointer(
   ADBG_Case_t *const Case_p,
   const char *const FileName_p,
   const int LineNumber,
   const void *const Value1_p,
   const void *const Value2_p,
   const bool Result,
   const char *const Value1Str_p,
   const char *const ComparStr_p,
   const char *const Value2Str_p
   )
{
   if (!ADBG_AssertHelper(Case_p, FileName_p, LineNumber, Result)) {
       Do_ADBG_Log(
           "%s:%d: Expression \"%s %s %s\" (%p %s %p) is false",
           ADBG_GetFileBase(FileName_p), LineNumber,
           Value1Str_p, ComparStr_p, Value2Str_p,
           Value1_p, ComparStr_p, Value2_p);
   }
   return Result;
}
 
/*************************************************************************
 * 6. Definitions of internal functions
 ************************************************************************/
static bool ADBG_AssertHelper(
   ADBG_Case_t *const Case_p,
   const char *const FileName_p,
   const int LineNumber,
   const bool ExpressionOK
   )
{
   ADBG_SubCase_t *SubCase_p = Case_p->CurrentSubCase_p;
 
   IDENTIFIER_NOT_USED(Case_p)
 
   SubCase_p->Result.NumTests++;
 
   if (!ExpressionOK) {
       SubCase_p->Result.NumFailedTests++;
       if (SubCase_p->Result.FirstFailedRow == 0) {
           SubCase_p->Result.FirstFailedRow = LineNumber;
           SubCase_p->Result.FirstFailedFile_p = ADBG_GetFileBase(
               FileName_p);
       }
   }
 
   return ExpressionOK;
}
 
static const char *ADBG_GetFileBase(const char *const FileName_p)
{
   const char *Ch_p = FileName_p;
   const char *Base_p = FileName_p;
 
   while (*Ch_p != '\0') {
       if (*Ch_p == '\\')
           Base_p = Ch_p + 1;
 
       Ch_p++;
   }
 
   return Base_p;
}