Skip to content

platform: FileHandle test - remove optimization for stdlib diversity #6182

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 26, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 11 additions & 35 deletions TESTS/mbed_platform/FileHandle/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,25 +90,22 @@ void test_fwrite_fread()
TEST_ASSERT_TRUE(TestFile<FS>::functionCalled(TestFile<FS>::fnWrite));
TEST_ASSERT_EQUAL_INT(str1_size, write_ret);

#ifndef __ICCARM__ // prevents IAR infinite loop
// write 3; expected written 2
TestFile<FS>::resetFunctionCallHistory();
write_ret = std::fwrite(str2, 1, str2_size, file);
TEST_ASSERT_TRUE(TestFile<FS>::functionCalled(TestFile<FS>::fnWrite));
TEST_ASSERT_TRUE(std::ferror(file) != 0);
std::clearerr(file); // for ARMCC
#ifndef __ARMCC_VERSION
// ARMCC returns 0 here instead of number of elements successfully written
TEST_ASSERT_EQUAL_INT(str2_size - 1, write_ret);
#endif
std::clearerr(file);

// ARMCC/IAR returns 0 here instead of number of elements successfully written !!!
TEST_ASSERT_TRUE(write_ret >= 0 && write_ret <= (str2_size - 1));

// write 3; expected written 0
TestFile<FS>::resetFunctionCallHistory();
write_ret = std::fwrite(str1, 1, str1_size, file);
TEST_ASSERT_TRUE(TestFile<FS>::functionCalled(TestFile<FS>::fnWrite));
TEST_ASSERT_TRUE(std::ferror(file) != 0);
TEST_ASSERT_EQUAL_INT(0, write_ret);
#endif

std::rewind(file);

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

#ifndef __ICCARM__
// read 3; expected read 2
TestFile<FS>::resetFunctionCallHistory();
read_ret = std::fread(read_buf, 1, str2_size, file);
TEST_ASSERT_TRUE(TestFile<FS>::functionCalled(TestFile<FS>::fnRead));
TEST_ASSERT_TRUE(std::feof(file) != 0);
std::clearerr(file); // for ARMCC
std::clearerr(file);
TEST_ASSERT_EQUAL_INT(str2_size - 1, read_ret);
TEST_ASSERT_EQUAL_INT(0, strncmp(str2, read_buf, str2_size - 1));

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

std::fclose(file);
}



/** Test fputc and fgetc
*
* Given already opened file
Expand Down Expand Up @@ -168,7 +165,6 @@ void test_fputc_fgetc()
TEST_ASSERT_NOT_NULL(file);
std::setbuf(file, NULL);


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

#ifndef __ICCARM__ // prevents IAR infinite loop
// write 1; expected written 0
TestFile<FS>::resetFunctionCallHistory();
ret = std::fputc(char_buf[0], file);
TEST_ASSERT_TRUE(TestFile<FS>::functionCalled(TestFile<FS>::fnWrite));
TEST_ASSERT_TRUE(std::ferror(file) != 0);
TEST_ASSERT_EQUAL_INT(EOF, ret);
#endif

std::rewind(file);

Expand All @@ -207,29 +201,19 @@ void test_fputc_fgetc()
// read 1; expected read 1
TestFile<FS>::resetFunctionCallHistory();
ret = std::fgetc(file);
#ifndef __ICCARM__
// IAR optimize reads
TEST_ASSERT_TRUE(TestFile<FS>::functionCalled(TestFile<FS>::fnRead));
#endif
TEST_ASSERT_EQUAL_INT(char_buf[1], ret);

// read 1; expected read 1
TestFile<FS>::resetFunctionCallHistory();
ret = std::fgetc(file);
#ifndef __ICCARM__
// IAR optimize reads
TEST_ASSERT_TRUE(TestFile<FS>::functionCalled(TestFile<FS>::fnRead));
#endif
TEST_ASSERT_EQUAL_INT(char_buf[2], ret);

#ifndef __ICCARM__
// read 1; expected read 0
TestFile<FS>::resetFunctionCallHistory();
ret = std::fgetc(file);
TEST_ASSERT_TRUE(TestFile<FS>::functionCalled(TestFile<FS>::fnRead));
TEST_ASSERT_TRUE(std::feof(file) != 0);
TEST_ASSERT_EQUAL_INT(EOF, ret);
#endif

std::fclose(file);
}
Expand Down Expand Up @@ -273,13 +257,12 @@ void test_fputs_fgets()
TEST_ASSERT_TRUE(TestFile<FS>::functionCalled(TestFile<FS>::fnWrite));
TEST_ASSERT_TRUE(fputs_ret >= 0);

#ifndef __ICCARM__ // prevents IAR infinite loop
// write 3; expected written 2
TestFile<FS>::resetFunctionCallHistory();
fputs_ret = std::fputs(str2, file);
TEST_ASSERT_TRUE(TestFile<FS>::functionCalled(TestFile<FS>::fnWrite));
TEST_ASSERT_TRUE(std::ferror(file) != 0);
std::clearerr(file); // for ARMCC
std::clearerr(file);
TEST_ASSERT_EQUAL_INT(EOF, fputs_ret);

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

std::rewind(file);

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

#ifndef __ICCARM__
// read 3; expected read 2
TestFile<FS>::resetFunctionCallHistory();
fgets_ret = std::fgets(read_buf, str2_size + 1, file);
TEST_ASSERT_TRUE(TestFile<FS>::functionCalled(TestFile<FS>::fnRead));
TEST_ASSERT_TRUE(std::feof(file) != 0);
std::clearerr(file); // for ARMCC
std::clearerr(file);
TEST_ASSERT_EQUAL_INT(read_buf, fgets_ret);
TEST_ASSERT_EQUAL_INT(0, strncmp(read_buf, str2, str2_size - 2));

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

std::fclose(file);
}
Expand Down Expand Up @@ -359,13 +339,12 @@ void test_fprintf_fscanf()
TEST_ASSERT_TRUE(TestFile<FS>::functionCalled(TestFile<FS>::fnWrite));
TEST_ASSERT_EQUAL_INT(str1_size, fprintf_ret);

#ifndef __ICCARM__ // prevents IAR infinite loop
// write 3; expected written 2
TestFile<FS>::resetFunctionCallHistory();
fprintf_ret = fprintf(file, "%s", str2);
TEST_ASSERT_TRUE(TestFile<FS>::functionCalled(TestFile<FS>::fnWrite));
TEST_ASSERT_TRUE(std::ferror(file) != 0);
std::clearerr(file); // for ARMCC
std::clearerr(file);
TEST_ASSERT_TRUE(fprintf_ret < 0);

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

std::rewind(file);

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

#ifndef __ICCARM__
// read 3; expected read 2
TestFile<FS>::resetFunctionCallHistory();
fscanf_ret = fscanf(file, "%3s", read_buf);
TEST_ASSERT_TRUE(TestFile<FS>::functionCalled(TestFile<FS>::fnRead));
TEST_ASSERT_TRUE(std::feof(file) != 0);
std::clearerr(file); // for ARMCC
std::clearerr(file);
TEST_ASSERT_EQUAL_INT(1, fscanf_ret);
TEST_ASSERT_EQUAL_INT(0, strncmp(read_buf, str2, str2_size - 1));

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

std::fclose(file);
}
Expand Down