diff options
Diffstat (limited to 'tests/stdio_test.cpp')
-rw-r--r-- | tests/stdio_test.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/stdio_test.cpp b/tests/stdio_test.cpp index 65a942c37..c237d6d32 100644 --- a/tests/stdio_test.cpp +++ b/tests/stdio_test.cpp @@ -29,6 +29,7 @@ #include <locale.h> #include <string> +#include <thread> #include <vector> #include <android-base/file.h> @@ -2577,3 +2578,24 @@ TEST(STDIO_TEST, dev_std_files) { ASSERT_LT(0, length); ASSERT_EQ("/proc/self/fd/2", std::string(path, length)); } + +TEST(STDIO_TEST, fread_with_locked_file) { + // Reading an unbuffered/line-buffered file from one thread shouldn't block on + // files locked on other threads, even if it flushes some line-buffered files. + FILE* fp1 = fopen("/dev/zero", "r"); + ASSERT_TRUE(fp1 != nullptr); + flockfile(fp1); + + std::thread([] { + for (int mode : { _IONBF, _IOLBF }) { + FILE* fp2 = fopen("/dev/zero", "r"); + ASSERT_TRUE(fp2 != nullptr); + setvbuf(fp2, nullptr, mode, 0); + ASSERT_EQ('\0', fgetc(fp2)); + fclose(fp2); + } + }).join(); + + funlockfile(fp1); + fclose(fp1); +} |