Skip to content

Commit b7726f2

Browse files
authored
Merge pull request #6182 from maciejbocianski/fileHandle_compilers_fix
platform: FileHandle test - remove optimization for stdlib diversity
2 parents d49862b + 0b6f14f commit b7726f2

File tree

1 file changed

+11
-35
lines changed

1 file changed

+11
-35
lines changed

TESTS/mbed_platform/FileHandle/main.cpp

Lines changed: 11 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -90,25 +90,22 @@ void test_fwrite_fread()
9090
TEST_ASSERT_TRUE(TestFile<FS>::functionCalled(TestFile<FS>::fnWrite));
9191
TEST_ASSERT_EQUAL_INT(str1_size, write_ret);
9292

93-
#ifndef __ICCARM__ // prevents IAR infinite loop
9493
// write 3; expected written 2
9594
TestFile<FS>::resetFunctionCallHistory();
9695
write_ret = std::fwrite(str2, 1, str2_size, file);
9796
TEST_ASSERT_TRUE(TestFile<FS>::functionCalled(TestFile<FS>::fnWrite));
9897
TEST_ASSERT_TRUE(std::ferror(file) != 0);
99-
std::clearerr(file); // for ARMCC
100-
#ifndef __ARMCC_VERSION
101-
// ARMCC returns 0 here instead of number of elements successfully written
102-
TEST_ASSERT_EQUAL_INT(str2_size - 1, write_ret);
103-
#endif
98+
std::clearerr(file);
99+
100+
// ARMCC/IAR returns 0 here instead of number of elements successfully written !!!
101+
TEST_ASSERT_TRUE(write_ret >= 0 && write_ret <= (str2_size - 1));
104102

105103
// write 3; expected written 0
106104
TestFile<FS>::resetFunctionCallHistory();
107105
write_ret = std::fwrite(str1, 1, str1_size, file);
108106
TEST_ASSERT_TRUE(TestFile<FS>::functionCalled(TestFile<FS>::fnWrite));
109107
TEST_ASSERT_TRUE(std::ferror(file) != 0);
110108
TEST_ASSERT_EQUAL_INT(0, write_ret);
111-
#endif
112109

113110
std::rewind(file);
114111

@@ -119,13 +116,12 @@ void test_fwrite_fread()
119116
TEST_ASSERT_EQUAL_INT(str1_size, read_ret);
120117
TEST_ASSERT_EQUAL_INT(0, strncmp(str1, read_buf, str1_size));
121118

122-
#ifndef __ICCARM__
123119
// read 3; expected read 2
124120
TestFile<FS>::resetFunctionCallHistory();
125121
read_ret = std::fread(read_buf, 1, str2_size, file);
126122
TEST_ASSERT_TRUE(TestFile<FS>::functionCalled(TestFile<FS>::fnRead));
127123
TEST_ASSERT_TRUE(std::feof(file) != 0);
128-
std::clearerr(file); // for ARMCC
124+
std::clearerr(file);
129125
TEST_ASSERT_EQUAL_INT(str2_size - 1, read_ret);
130126
TEST_ASSERT_EQUAL_INT(0, strncmp(str2, read_buf, str2_size - 1));
131127

@@ -135,11 +131,12 @@ void test_fwrite_fread()
135131
TEST_ASSERT_TRUE(TestFile<FS>::functionCalled(TestFile<FS>::fnRead));
136132
TEST_ASSERT_TRUE(std::feof(file) != 0);
137133
TEST_ASSERT_EQUAL_INT(0, read_ret);
138-
#endif
139134

140135
std::fclose(file);
141136
}
142137

138+
139+
143140
/** Test fputc and fgetc
144141
*
145142
* Given already opened file
@@ -168,7 +165,6 @@ void test_fputc_fgetc()
168165
TEST_ASSERT_NOT_NULL(file);
169166
std::setbuf(file, NULL);
170167

171-
172168
// write 1; expected written 1
173169
TestFile<FS>::resetFunctionCallHistory();
174170
ret = std::fputc(char_buf[0], file);
@@ -187,14 +183,12 @@ void test_fputc_fgetc()
187183
TEST_ASSERT_TRUE(TestFile<FS>::functionCalled(TestFile<FS>::fnWrite));
188184
TEST_ASSERT_EQUAL_INT(char_buf[2], ret);
189185

190-
#ifndef __ICCARM__ // prevents IAR infinite loop
191186
// write 1; expected written 0
192187
TestFile<FS>::resetFunctionCallHistory();
193188
ret = std::fputc(char_buf[0], file);
194189
TEST_ASSERT_TRUE(TestFile<FS>::functionCalled(TestFile<FS>::fnWrite));
195190
TEST_ASSERT_TRUE(std::ferror(file) != 0);
196191
TEST_ASSERT_EQUAL_INT(EOF, ret);
197-
#endif
198192

199193
std::rewind(file);
200194

@@ -207,29 +201,19 @@ void test_fputc_fgetc()
207201
// read 1; expected read 1
208202
TestFile<FS>::resetFunctionCallHistory();
209203
ret = std::fgetc(file);
210-
#ifndef __ICCARM__
211-
// IAR optimize reads
212-
TEST_ASSERT_TRUE(TestFile<FS>::functionCalled(TestFile<FS>::fnRead));
213-
#endif
214204
TEST_ASSERT_EQUAL_INT(char_buf[1], ret);
215205

216206
// read 1; expected read 1
217207
TestFile<FS>::resetFunctionCallHistory();
218208
ret = std::fgetc(file);
219-
#ifndef __ICCARM__
220-
// IAR optimize reads
221-
TEST_ASSERT_TRUE(TestFile<FS>::functionCalled(TestFile<FS>::fnRead));
222-
#endif
223209
TEST_ASSERT_EQUAL_INT(char_buf[2], ret);
224210

225-
#ifndef __ICCARM__
226211
// read 1; expected read 0
227212
TestFile<FS>::resetFunctionCallHistory();
228213
ret = std::fgetc(file);
229214
TEST_ASSERT_TRUE(TestFile<FS>::functionCalled(TestFile<FS>::fnRead));
230215
TEST_ASSERT_TRUE(std::feof(file) != 0);
231216
TEST_ASSERT_EQUAL_INT(EOF, ret);
232-
#endif
233217

234218
std::fclose(file);
235219
}
@@ -273,13 +257,12 @@ void test_fputs_fgets()
273257
TEST_ASSERT_TRUE(TestFile<FS>::functionCalled(TestFile<FS>::fnWrite));
274258
TEST_ASSERT_TRUE(fputs_ret >= 0);
275259

276-
#ifndef __ICCARM__ // prevents IAR infinite loop
277260
// write 3; expected written 2
278261
TestFile<FS>::resetFunctionCallHistory();
279262
fputs_ret = std::fputs(str2, file);
280263
TEST_ASSERT_TRUE(TestFile<FS>::functionCalled(TestFile<FS>::fnWrite));
281264
TEST_ASSERT_TRUE(std::ferror(file) != 0);
282-
std::clearerr(file); // for ARMCC
265+
std::clearerr(file);
283266
TEST_ASSERT_EQUAL_INT(EOF, fputs_ret);
284267

285268
// write 3; expected written 0
@@ -288,7 +271,6 @@ void test_fputs_fgets()
288271
TEST_ASSERT_TRUE(TestFile<FS>::functionCalled(TestFile<FS>::fnWrite));
289272
TEST_ASSERT_TRUE(std::ferror(file) != 0);
290273
TEST_ASSERT_EQUAL_INT(EOF, fputs_ret);
291-
#endif
292274

293275
std::rewind(file);
294276

@@ -299,13 +281,12 @@ void test_fputs_fgets()
299281
TEST_ASSERT_EQUAL_INT(read_buf, fgets_ret);
300282
TEST_ASSERT_EQUAL_INT(0, strncmp(read_buf, str1, str1_size));
301283

302-
#ifndef __ICCARM__
303284
// read 3; expected read 2
304285
TestFile<FS>::resetFunctionCallHistory();
305286
fgets_ret = std::fgets(read_buf, str2_size + 1, file);
306287
TEST_ASSERT_TRUE(TestFile<FS>::functionCalled(TestFile<FS>::fnRead));
307288
TEST_ASSERT_TRUE(std::feof(file) != 0);
308-
std::clearerr(file); // for ARMCC
289+
std::clearerr(file);
309290
TEST_ASSERT_EQUAL_INT(read_buf, fgets_ret);
310291
TEST_ASSERT_EQUAL_INT(0, strncmp(read_buf, str2, str2_size - 2));
311292

@@ -315,7 +296,6 @@ void test_fputs_fgets()
315296
TEST_ASSERT_TRUE(TestFile<FS>::functionCalled(TestFile<FS>::fnRead));
316297
TEST_ASSERT_TRUE(std::feof(file) != 0);
317298
TEST_ASSERT_EQUAL_INT(NULL, fgets_ret);
318-
#endif
319299

320300
std::fclose(file);
321301
}
@@ -359,13 +339,12 @@ void test_fprintf_fscanf()
359339
TEST_ASSERT_TRUE(TestFile<FS>::functionCalled(TestFile<FS>::fnWrite));
360340
TEST_ASSERT_EQUAL_INT(str1_size, fprintf_ret);
361341

362-
#ifndef __ICCARM__ // prevents IAR infinite loop
363342
// write 3; expected written 2
364343
TestFile<FS>::resetFunctionCallHistory();
365344
fprintf_ret = fprintf(file, "%s", str2);
366345
TEST_ASSERT_TRUE(TestFile<FS>::functionCalled(TestFile<FS>::fnWrite));
367346
TEST_ASSERT_TRUE(std::ferror(file) != 0);
368-
std::clearerr(file); // for ARMCC
347+
std::clearerr(file);
369348
TEST_ASSERT_TRUE(fprintf_ret < 0);
370349

371350
// write 3; expected written 0
@@ -374,7 +353,6 @@ void test_fprintf_fscanf()
374353
TEST_ASSERT_TRUE(TestFile<FS>::functionCalled(TestFile<FS>::fnWrite));
375354
TEST_ASSERT_TRUE(std::ferror(file) != 0);
376355
TEST_ASSERT_TRUE(fprintf_ret < 0);
377-
#endif
378356

379357
std::rewind(file);
380358

@@ -385,13 +363,12 @@ void test_fprintf_fscanf()
385363
TEST_ASSERT_EQUAL_INT(1, fscanf_ret);
386364
TEST_ASSERT_EQUAL_INT(0, strncmp(read_buf, str1, str1_size));
387365

388-
#ifndef __ICCARM__
389366
// read 3; expected read 2
390367
TestFile<FS>::resetFunctionCallHistory();
391368
fscanf_ret = fscanf(file, "%3s", read_buf);
392369
TEST_ASSERT_TRUE(TestFile<FS>::functionCalled(TestFile<FS>::fnRead));
393370
TEST_ASSERT_TRUE(std::feof(file) != 0);
394-
std::clearerr(file); // for ARMCC
371+
std::clearerr(file);
395372
TEST_ASSERT_EQUAL_INT(1, fscanf_ret);
396373
TEST_ASSERT_EQUAL_INT(0, strncmp(read_buf, str2, str2_size - 1));
397374

@@ -401,7 +378,6 @@ void test_fprintf_fscanf()
401378
TEST_ASSERT_TRUE(TestFile<FS>::functionCalled(TestFile<FS>::fnRead));
402379
TEST_ASSERT_TRUE(std::feof(file) != 0);
403380
TEST_ASSERT_EQUAL_INT(EOF, fscanf_ret);
404-
#endif
405381

406382
std::fclose(file);
407383
}

0 commit comments

Comments
 (0)