diff options
author | Elliott Hughes <enh@google.com> | 2014-12-01 16:13:30 -0800 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2014-12-02 14:54:52 -0800 |
commit | 27d276f3a6d81d29fab13de96496efb7bc072773 (patch) | |
tree | f15aacb70521bf895148e9741387c70f708e7c41 /tests | |
parent | 152e978f73fc6cd37d0d82de69f1cf8134b34b90 (diff) | |
download | bionic-27d276f3a6d81d29fab13de96496efb7bc072773.zip bionic-27d276f3a6d81d29fab13de96496efb7bc072773.tar.gz bionic-27d276f3a6d81d29fab13de96496efb7bc072773.tar.bz2 |
Avoid pathological behavior in OpenBSD's fread.
(cherry picked from commit 20841a137beac5caa824e3586c7bd91d879ff92e)
Bug: https://code.google.com/p/android/issues/detail?id=81155
Bug: 18556607
Change-Id: Ibdfebc20dce4c34ad565014523c9b074e90ea665
Diffstat (limited to 'tests')
-rw-r--r-- | tests/stdio_test.cpp | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/stdio_test.cpp b/tests/stdio_test.cpp index 6a2991f..bba744a 100644 --- a/tests/stdio_test.cpp +++ b/tests/stdio_test.cpp @@ -694,3 +694,34 @@ TEST(stdio, fpos_t_and_seek) { fclose(fp); } + +// https://code.google.com/p/android/issues/detail?id=81155 +// http://b/18556607 +TEST(stdio, fread_unbuffered_pathological_performance) { + FILE* fp = fopen("/dev/zero", "r"); + ASSERT_TRUE(fp != NULL); + + // Make this stream unbuffered. + setvbuf(fp, 0, _IONBF, 0); + + char buf[65*1024]; + memset(buf, 0xff, sizeof(buf)); + + time_t t0 = time(NULL); + for (size_t i = 0; i < 1024; ++i) { + fread(buf, 64*1024, 1, fp); + } + time_t t1 = time(NULL); + + fclose(fp); + + // 1024 64KiB reads should have been very quick. + ASSERT_LE(t1 - t0, 1); + + for (size_t i = 0; i < 64*1024; ++i) { + ASSERT_EQ('\0', buf[i]); + } + for (size_t i = 64*1024; i < 65*1024; ++i) { + ASSERT_EQ('\xff', buf[i]); + } +} |