From 71288cbfdfe138a7f0d59fa2e642dc6e2317eb6d Mon Sep 17 00:00:00 2001 From: Elliott Hughes Date: Fri, 22 Jan 2016 19:22:44 -0800 Subject: 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 --- tests/stdio_test.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'tests/stdio_test.cpp') 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 tfs; + std::vector 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]; + } +} -- cgit v1.2.3