In commit 0d4d8fd6752521bed92a4be194403b89955b591f we fixed a bug where fread() on a directory hangs, instead of resulting in an error as expected. However, we didn't have a test for this case - and this patch adds one.
The new test hangs before the aforementioned commit, and passes without it. The test also passes on Linux. Signed-off-by: Nadav Har'El <n...@scylladb.com> --- tests/tst-fread.cc | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tests/tst-fread.cc b/tests/tst-fread.cc index 2da01f54..c65589ea 100644 --- a/tests/tst-fread.cc +++ b/tests/tst-fread.cc @@ -69,6 +69,20 @@ int main() fclose(fp); } + // Test that if read from a directory with fread(), we get an error, + // not an endless loop as we did before commit + // 0d4d8fd6752521bed92a4be194403b89955b591f. + std::cerr << "opening /\n"; + fp = fopen("/", "r"); + expect(!fp, false); + if (fp) { + char buf[4096]; + expect(fread(buf, 1, 4096, fp), (size_t)0); + expect(ferror(fp), 1); + expect(feof(fp), 0); + fclose(fp); + } + std::cout << "SUMMARY: " << tests << " tests, " << fails << " failures\n"; return fails == 0 ? 0 : 1; -- 2.26.2 -- You received this message because you are subscribed to the Google Groups "OSv Development" group. To unsubscribe from this group and stop receiving emails from it, send an email to osv-dev+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/osv-dev/20201229135830.3414999-1-nyh%40scylladb.com.