Page MenuHomePhabricator

[compiler-rt] [sanitizer_common] Add tests for more stdio.h functions
ClosedPublic

Authored by mgorny on Dec 28 2018, 12:20 PM.

Details

Summary

Add two new test cases that test the following stdio.h functions:

  • clearerr()
  • feof()
  • ferror()
  • fileno()
  • fgetc()
  • getc()
  • ungetc()

Diff Detail

Repository
rL LLVM

Event Timeline

mgorny created this revision.Dec 28 2018, 12:20 PM
krytarowski added inline comments.Dec 28 2018, 1:32 PM
test/sanitizer_common/TestCases/Posix/feof_fileno_ferror.cc
7 ↗(On Diff #179655)

Please move local variable declaration to the first line used (whenever possible)

test/sanitizer_common/TestCases/Posix/fgetc_ungetc_getc.cc
6 ↗(On Diff #179655)

FILE *fp = fp = fopen(argv[0], "r");

vitalybuka added inline comments.Dec 28 2018, 1:42 PM
test/sanitizer_common/TestCases/Posix/feof_fileno_ferror.cc
49 ↗(On Diff #179655)

why does this close file only on success?
I assume normal test behavior is return 0;
So please replace all return N with asserts so when it fail we will have verbose output
e.g

assert(close(fd) != -1);
....
assert(ferror(fp));
mgorny marked 4 inline comments as done.Dec 29 2018, 1:00 AM
mgorny added inline comments.
test/sanitizer_common/TestCases/Posix/feof_fileno_ferror.cc
49 ↗(On Diff #179655)

Will do. I've copied this from fgets.cc, fputs_puts.cc tests, and wrongly presumed it's expected coding style.

mgorny updated this revision to Diff 179679.Dec 29 2018, 1:00 AM
mgorny marked an inline comment as done.

Moved variable definitions, and added asserts.

krytarowski accepted this revision.Dec 29 2018, 4:23 AM
krytarowski added inline comments.
test/sanitizer_common/TestCases/Posix/feof_fileno_ferror.cc
38 ↗(On Diff #179679)

assert(!fclose(fp));

test/sanitizer_common/TestCases/Posix/fgetc_ungetc_getc.cc
17 ↗(On Diff #179679)

assert(!fclose(fp));

This revision is now accepted and ready to land.Dec 29 2018, 4:23 AM
krytarowski added inline comments.Dec 29 2018, 4:29 AM
test/sanitizer_common/TestCases/Posix/feof_fileno_ferror.cc
38 ↗(On Diff #179679)

alternatively != EOF

mgorny added inline comments.Dec 29 2018, 6:56 AM
test/sanitizer_common/TestCases/Posix/feof_fileno_ferror.cc
38 ↗(On Diff #179679)

It will fail most likely, due to us closing the fd before. However, I'm not sure if we want to strictly rely on this error condition.

(Do you have another idea how to reliably trigger ferror?)

krytarowski added inline comments.Dec 29 2018, 8:27 AM
test/sanitizer_common/TestCases/Posix/feof_fileno_ferror.cc
38 ↗(On Diff #179679)

Ah, OK. Please just add a comment that this call might fail.

mgorny updated this revision to Diff 179691.Dec 29 2018, 8:28 AM

Added asserts for fclose().

krytarowski accepted this revision.Dec 29 2018, 8:33 AM
This revision was automatically updated to reflect the committed changes.