diff options
author | Elliott Hughes <enh@google.com> | 2017-08-22 15:26:07 -0700 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2017-08-23 00:05:21 +0000 |
commit | d706fe5f9e83707901389914c77afa69c19e07e6 (patch) | |
tree | dffb701fa9e822f6c45c2d14d711e51d1701e22a /benchmarks/stdio_benchmark.cpp | |
parent | 096fa4497c50cffdb56f06d7038adbeb3c1254d6 (diff) |
Fix the stdio fwrite benchmark.
Can't write to a read-only file. (Mode "rw" isn't meaningful, but isn't
considered an error by any libc I know of.)
Bug: http://b/64585477
Test: ran benchmarks
Change-Id: Ifec1d68414bfc8f3cc8d7f912cb135dccb2e7a41
Diffstat (limited to 'benchmarks/stdio_benchmark.cpp')
-rw-r--r-- | benchmarks/stdio_benchmark.cpp | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/benchmarks/stdio_benchmark.cpp b/benchmarks/stdio_benchmark.cpp index 2ab7264a0..3f5e0f138 100644 --- a/benchmarks/stdio_benchmark.cpp +++ b/benchmarks/stdio_benchmark.cpp @@ -26,7 +26,7 @@ template <typename Fn> void ReadWriteTest(benchmark::State& state, Fn f, bool buffered) { size_t chunk_size = state.range(0); - FILE* fp = fopen("/dev/zero", "rw"); + FILE* fp = fopen("/dev/zero", "r+e"); __fsetlocking(fp, FSETLOCKING_BYCALLER); char* buf = new char[chunk_size]; @@ -35,7 +35,9 @@ void ReadWriteTest(benchmark::State& state, Fn f, bool buffered) { } while (state.KeepRunning()) { - f(buf, chunk_size, 1, fp); + if (f(buf, chunk_size, 1, fp) != 1) { + errx(1, "ERROR: op of %zu bytes failed.", chunk_size); + } } state.SetBytesProcessed(int64_t(state.iterations()) * int64_t(chunk_size)); @@ -70,7 +72,7 @@ static void FopenFgetsFclose(benchmark::State& state, bool no_locking) { FILE* fp = fopen("/dev/zero", "re"); if (no_locking) __fsetlocking(fp, FSETLOCKING_BYCALLER); if (fgets(buf, sizeof(buf), fp) == nullptr) { - errx(1, "ERROR: fgets of %zu bytes failed.", nbytes); + errx(1, "ERROR: fgets of %zu bytes failed.", nbytes); } fclose(fp); } @@ -108,4 +110,3 @@ void BM_stdio_fopen_fgetc_fclose_no_locking(benchmark::State& state) { FopenFgetcFclose(state, true); } BIONIC_BENCHMARK(BM_stdio_fopen_fgetc_fclose_no_locking); - |