From ada250c7d61c99dddfa4368e4b7772a2f5a80269 Mon Sep 17 00:00:00 2001 From: RAJKUMAR KANAGARAJ Date: Tue, 19 Nov 2019 07:43:46 -0800 Subject: [PATCH 1/2] Fixed greentea FileHandle test for microlib. As per "Difference between microlib and the default c library" from "http://arminfo.emea.arm.com/help/index.jsp?topic=/com.arm.doc.100073_0612_00_en/chr1358938938431.html" Microlib is not supported feof() and ferror() functions so modified all the test cases to pass without using feof() and ferror(). --- TESTS/mbed_platform/FileHandle/main.cpp | 38 ++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/TESTS/mbed_platform/FileHandle/main.cpp b/TESTS/mbed_platform/FileHandle/main.cpp index 65d670e6f5..dbabfb82d1 100644 --- a/TESTS/mbed_platform/FileHandle/main.cpp +++ b/TESTS/mbed_platform/FileHandle/main.cpp @@ -94,7 +94,9 @@ void test_fwrite_fread() TestFile::resetFunctionCallHistory(); write_ret = std::fwrite(str2, 1, str2_size, file); TEST_ASSERT_TRUE(TestFile::functionCalled(TestFile::fnWrite)); +#if !defined(__MICROLIB) TEST_ASSERT_TRUE(std::ferror(file) != 0); +#endif std::clearerr(file); // ARMCC/IAR returns 0 here instead of number of elements successfully written !!! @@ -104,7 +106,9 @@ void test_fwrite_fread() TestFile::resetFunctionCallHistory(); write_ret = std::fwrite(str1, 1, str1_size, file); TEST_ASSERT_TRUE(TestFile::functionCalled(TestFile::fnWrite)); +#if !defined(__MICROLIB) TEST_ASSERT_TRUE(std::ferror(file) != 0); +#endif TEST_ASSERT_EQUAL_INT(0, write_ret); std::rewind(file); @@ -120,7 +124,9 @@ void test_fwrite_fread() TestFile::resetFunctionCallHistory(); read_ret = std::fread(read_buf, 1, str2_size, file); TEST_ASSERT_TRUE(TestFile::functionCalled(TestFile::fnRead)); +#if !defined(__MICROLIB) TEST_ASSERT_TRUE(std::feof(file) != 0); +#endif std::clearerr(file); TEST_ASSERT_EQUAL_INT(str2_size - 1, read_ret); TEST_ASSERT_EQUAL_INT(0, strncmp(str2, read_buf, str2_size - 1)); @@ -129,7 +135,9 @@ void test_fwrite_fread() TestFile::resetFunctionCallHistory(); read_ret = std::fread(read_buf, 1, str2_size, file); TEST_ASSERT_TRUE(TestFile::functionCalled(TestFile::fnRead)); +#if !defined(__MICROLIB) TEST_ASSERT_TRUE(std::feof(file) != 0); +#endif TEST_ASSERT_EQUAL_INT(0, read_ret); std::fclose(file); @@ -187,7 +195,9 @@ void test_fputc_fgetc() TestFile::resetFunctionCallHistory(); ret = std::fputc(char_buf[0], file); TEST_ASSERT_TRUE(TestFile::functionCalled(TestFile::fnWrite)); +#if !defined(__MICROLIB) TEST_ASSERT_TRUE(std::ferror(file) != 0); +#endif TEST_ASSERT_EQUAL_INT(EOF, ret); std::rewind(file); @@ -212,7 +222,9 @@ void test_fputc_fgetc() TestFile::resetFunctionCallHistory(); ret = std::fgetc(file); TEST_ASSERT_TRUE(TestFile::functionCalled(TestFile::fnRead)); +#if !defined(__MICROLIB) TEST_ASSERT_TRUE(std::feof(file) != 0); +#endif TEST_ASSERT_EQUAL_INT(EOF, ret); std::fclose(file); @@ -261,7 +273,9 @@ void test_fputs_fgets() TestFile::resetFunctionCallHistory(); fputs_ret = std::fputs(str2, file); TEST_ASSERT_TRUE(TestFile::functionCalled(TestFile::fnWrite)); +#if !defined(__MICROLIB) TEST_ASSERT_TRUE(std::ferror(file) != 0); +#endif std::clearerr(file); TEST_ASSERT_EQUAL_INT(EOF, fputs_ret); @@ -269,7 +283,9 @@ void test_fputs_fgets() TestFile::resetFunctionCallHistory(); fputs_ret = std::fputs(str1, file); TEST_ASSERT_TRUE(TestFile::functionCalled(TestFile::fnWrite)); +#if !defined(__MICROLIB) TEST_ASSERT_TRUE(std::ferror(file) != 0); +#endif TEST_ASSERT_EQUAL_INT(EOF, fputs_ret); std::rewind(file); @@ -285,7 +301,9 @@ void test_fputs_fgets() TestFile::resetFunctionCallHistory(); fgets_ret = std::fgets(read_buf, str2_size + 1, file); TEST_ASSERT_TRUE(TestFile::functionCalled(TestFile::fnRead)); +#if !defined(__MICROLIB) TEST_ASSERT_TRUE(std::feof(file) != 0); +#endif std::clearerr(file); TEST_ASSERT_EQUAL_INT(read_buf, fgets_ret); TEST_ASSERT_EQUAL_INT(0, strncmp(read_buf, str2, str2_size - 2)); @@ -294,7 +312,9 @@ void test_fputs_fgets() TestFile::resetFunctionCallHistory(); fgets_ret = std::fgets(read_buf, str2_size + 1, file); TEST_ASSERT_TRUE(TestFile::functionCalled(TestFile::fnRead)); +#if !defined(__MICROLIB) TEST_ASSERT_TRUE(std::feof(file) != 0); +#endif TEST_ASSERT_EQUAL_INT(NULL, fgets_ret); std::fclose(file); @@ -339,6 +359,8 @@ void test_fprintf_fscanf() TEST_ASSERT_TRUE(TestFile::functionCalled(TestFile::fnWrite)); TEST_ASSERT_EQUAL_INT(str1_size, fprintf_ret); +#if !defined(__MICROLIB) + // feof() and ferror() functions are not supported for Microlib. // write 3; expected written 2 TestFile::resetFunctionCallHistory(); fprintf_ret = fprintf(file, "%s", str2); @@ -353,7 +375,17 @@ void test_fprintf_fscanf() TEST_ASSERT_TRUE(TestFile::functionCalled(TestFile::fnWrite)); TEST_ASSERT_TRUE(std::ferror(file) != 0); TEST_ASSERT_TRUE(fprintf_ret < 0); - +#else + // Writing remaining available file space of 2 characters + // to make further fscanf() test to pass. + // write 2; expected written 2 + TestFile::resetFunctionCallHistory(); + fprintf_ret = 0; + fprintf_ret += fprintf(file, "%c", str2[0]); + fprintf_ret += fprintf(file, "%c", str2[1]); + TEST_ASSERT_TRUE(TestFile::functionCalled(TestFile::fnWrite)); + TEST_ASSERT_EQUAL_INT(2, fprintf_ret); +#endif std::rewind(file); // read 3; expected read 3 @@ -367,8 +399,10 @@ void test_fprintf_fscanf() TestFile::resetFunctionCallHistory(); fscanf_ret = fscanf(file, "%3s", read_buf); TEST_ASSERT_TRUE(TestFile::functionCalled(TestFile::fnRead)); +#if !defined(__MICROLIB) TEST_ASSERT_TRUE(std::feof(file) != 0); std::clearerr(file); +#endif TEST_ASSERT_EQUAL_INT(1, fscanf_ret); TEST_ASSERT_EQUAL_INT(0, strncmp(read_buf, str2, str2_size - 1)); @@ -376,7 +410,9 @@ void test_fprintf_fscanf() TestFile::resetFunctionCallHistory(); fscanf_ret = fscanf(file, "%3s", read_buf); TEST_ASSERT_TRUE(TestFile::functionCalled(TestFile::fnRead)); +#if !defined(__MICROLIB) TEST_ASSERT_TRUE(std::feof(file) != 0); +#endif TEST_ASSERT_EQUAL_INT(EOF, fscanf_ret); std::fclose(file); From 93f3db2c3d067302c201cf73a774ddf1d74a5c5a Mon Sep 17 00:00:00 2001 From: RAJKUMAR KANAGARAJ Date: Fri, 22 Nov 2019 07:21:15 -0800 Subject: [PATCH 2/2] Incorporated review comment --- TESTS/mbed_platform/FileHandle/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TESTS/mbed_platform/FileHandle/main.cpp b/TESTS/mbed_platform/FileHandle/main.cpp index dbabfb82d1..ff38bb21b6 100644 --- a/TESTS/mbed_platform/FileHandle/main.cpp +++ b/TESTS/mbed_platform/FileHandle/main.cpp @@ -360,7 +360,7 @@ void test_fprintf_fscanf() TEST_ASSERT_EQUAL_INT(str1_size, fprintf_ret); #if !defined(__MICROLIB) - // feof() and ferror() functions are not supported for Microlib. + // feof() and ferror() functions are not supported in Microlib. // write 3; expected written 2 TestFile::resetFunctionCallHistory(); fprintf_ret = fprintf(file, "%s", str2);