diff options
author | Elliott Hughes <enh@google.com> | 2016-01-22 19:22:44 -0800 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2016-01-22 19:22:44 -0800 |
commit | 71288cbfdfe138a7f0d59fa2e642dc6e2317eb6d (patch) | |
tree | e43ec640511e866b1f732493b4b99ba18d17307c /tests/stdio_test.cpp | |
parent | a42483baad9a37297e6bbbe02d433ecbde890386 (diff) | |
download | android_bionic-71288cbfdfe138a7f0d59fa2e642dc6e2317eb6d.tar.gz android_bionic-71288cbfdfe138a7f0d59fa2e642dc6e2317eb6d.tar.bz2 android_bionic-71288cbfdfe138a7f0d59fa2e642dc6e2317eb6d.zip |
Add another stdio test.
This test didn't catch anything, but it does ensure that we exercise
the "lots of files" case.
Bug: http://b/26747402
Change-Id: I6c51c6436029572a49190d509f131eb93b808652
Diffstat (limited to 'tests/stdio_test.cpp')
-rw-r--r-- | tests/stdio_test.cpp | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/stdio_test.cpp b/tests/stdio_test.cpp index 31acfec90..a7df78448 100644 --- a/tests/stdio_test.cpp +++ b/tests/stdio_test.cpp @@ -1093,3 +1093,31 @@ TEST(STDIO_TEST, fseek_ftell_unseekable) { fclose(fp); #endif } + +TEST(STDIO_TEST, lots_of_concurrent_files) { + std::vector<TemporaryFile*> tfs; + std::vector<FILE*> fps; + + for (size_t i = 0; i < 256; ++i) { + TemporaryFile* tf = new TemporaryFile; + tfs.push_back(tf); + FILE* fp = fopen(tf->filename, "w+"); + fps.push_back(fp); + fprintf(fp, "hello %zu!\n", i); + fflush(fp); + } + + for (size_t i = 0; i < 256; ++i) { + rewind(fps[i]); + + char buf[BUFSIZ]; + ASSERT_TRUE(fgets(buf, sizeof(buf), fps[i]) != nullptr); + + char expected[BUFSIZ]; + snprintf(expected, sizeof(expected), "hello %zu!\n", i); + ASSERT_STREQ(expected, buf); + + fclose(fps[i]); + delete tfs[i]; + } +} |