aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorElliott Hughes2014-12-01 18:13:30 -0600
committerElliott Hughes2014-12-02 16:22:02 -0600
commit20841a137beac5caa824e3586c7bd91d879ff92e (patch)
tree3ccc88081ddcdbe9a4448c462eb16e971007f86e /tests
parent5cd127d3aa4a2f225be202af01581838fdd3c721 (diff)
downloadplatform-bionic-20841a137beac5caa824e3586c7bd91d879ff92e.tar.gz
platform-bionic-20841a137beac5caa824e3586c7bd91d879ff92e.tar.xz
platform-bionic-20841a137beac5caa824e3586c7bd91d879ff92e.zip
Avoid pathological behavior in OpenBSD's fread.
Bug: https://code.google.com/p/android/issues/detail?id=81155 Bug: 18556607 Change-Id: Idc60976b79610e2202cc42dc393dcb4ca6c42e05
Diffstat (limited to 'tests')
-rw-r--r--tests/stdio_test.cpp31
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/stdio_test.cpp b/tests/stdio_test.cpp
index 6be372c5..854fc7b7 100644
--- a/tests/stdio_test.cpp
+++ b/tests/stdio_test.cpp
@@ -813,3 +813,34 @@ TEST(stdio, freopen_CLOEXEC) {
813 813
814 fclose(fp); 814 fclose(fp);
815} 815}
816
817// https://code.google.com/p/android/issues/detail?id=81155
818// http://b/18556607
819TEST(stdio, fread_unbuffered_pathological_performance) {
820 FILE* fp = fopen("/dev/zero", "r");
821 ASSERT_TRUE(fp != NULL);
822
823 // Make this stream unbuffered.
824 setvbuf(fp, 0, _IONBF, 0);
825
826 char buf[65*1024];
827 memset(buf, 0xff, sizeof(buf));
828
829 time_t t0 = time(NULL);
830 for (size_t i = 0; i < 1024; ++i) {
831 fread(buf, 64*1024, 1, fp);
832 }
833 time_t t1 = time(NULL);
834
835 fclose(fp);
836
837 // 1024 64KiB reads should have been very quick.
838 ASSERT_LE(t1 - t0, 1);
839
840 for (size_t i = 0; i < 64*1024; ++i) {
841 ASSERT_EQ('\0', buf[i]);
842 }
843 for (size_t i = 64*1024; i < 65*1024; ++i) {
844 ASSERT_EQ('\xff', buf[i]);
845 }
846}