diff --git a/flang/unittests/Runtime/CMakeLists.txt b/flang/unittests/Runtime/CMakeLists.txt --- a/flang/unittests/Runtime/CMakeLists.txt +++ b/flang/unittests/Runtime/CMakeLists.txt @@ -31,8 +31,3 @@ RuntimeTesting FortranRuntime ) - -add_flang_nongtest_unittest(buffer - RuntimeTesting - FortranRuntime -) diff --git a/flang/unittests/Runtime/buffer.cpp b/flang/unittests/RuntimeGTest/BufferTest.cpp rename from flang/unittests/Runtime/buffer.cpp rename to flang/unittests/RuntimeGTest/BufferTest.cpp --- a/flang/unittests/Runtime/buffer.cpp +++ b/flang/unittests/RuntimeGTest/BufferTest.cpp @@ -1,16 +1,25 @@ +//===-- flang/unittests/RuntimeGTest/BufferTest.cpp -------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + #include "../../runtime/buffer.h" -#include "testing.h" +#include "CrashHandlerFixture.h" +#include "gtest/gtest.h" #include #include #include #include -static constexpr std::size_t tinyBuffer{32}; +static constexpr std::size_t tinyBufferSize{32}; using FileOffset = std::int64_t; using namespace Fortran::runtime; using namespace Fortran::runtime::io; -class Store : public FileFrame { +class Store : public FileFrame { public: explicit Store(std::size_t bytes = 65536) : bytes_{bytes} { data_.reset(new char[bytes]); @@ -60,16 +69,17 @@ inline int ChunkSize(int j, int most) { // 31, 1, 29, 3, 27, ... - j %= tinyBuffer; - auto chunk{ - static_cast(((j % 2) ? j : (tinyBuffer - 1 - j)) % tinyBuffer)}; + j %= tinyBufferSize; + auto chunk{static_cast( + ((j % 2) ? j : (tinyBufferSize - 1 - j)) % tinyBufferSize)}; return std::min(chunk, most); } inline int ValueFor(int at) { return (at ^ (at >> 8)) & 0xff; } -int main() { - StartTests(); +struct BufferTests : CrashHandlerFixture {}; + +TEST(BufferTests, TestFrameBufferReadAndWrite) { Terminator terminator{__FILE__, __LINE__}; IoErrorHandler handler{terminator}; Store store; @@ -94,22 +104,19 @@ while (at < bytes) { auto chunk{ChunkSize(j, static_cast(bytes - at))}; std::size_t frame{store.ReadFrame(at, chunk, handler)}; - if (frame < static_cast(chunk)) { - Fail() << "Badly-sized ReadFrame at " << at << ", chunk=" << chunk - << ", got " << frame << '\n'; - break; - } + ASSERT_GE(frame, static_cast(chunk)) + << "Badly-sized ReadFrame at " << at << ", chunk=" << chunk << ", got " + << frame << '\n'; + const char *from{store.Frame()}; for (int k{0}; k < chunk; ++k) { auto expect{static_cast(ValueFor(at + k))}; - if (from[k] != expect) { - Fail() << "At " << at << '+' << k << '(' << (at + k) << "), read " - << (from[k] & 0xff) << ", expected " << static_cast(expect) - << '\n'; - } + ASSERT_EQ(from[k], expect) + << "At " << at << '+' << k << '(' << (at + k) << "), read " + << (from[k] & 0xff) << ", expected " << static_cast(expect) + << '\n'; } at += chunk; ++j; } - return EndTests(); } diff --git a/flang/unittests/RuntimeGTest/CMakeLists.txt b/flang/unittests/RuntimeGTest/CMakeLists.txt --- a/flang/unittests/RuntimeGTest/CMakeLists.txt +++ b/flang/unittests/RuntimeGTest/CMakeLists.txt @@ -1,4 +1,5 @@ add_flang_unittest(FlangRuntimeTests + BufferTest.cpp CharacterTest.cpp CrashHandlerFixture.cpp Format.cpp