[flang-commits] [flang] c58cf69 - [flang] Move buffer runtime test to GTest
Asher Mancinelli via flang-commits
flang-commits at lists.llvm.org
Mon Jun 14 10:16:26 PDT 2021
Author: Asher Mancinelli
Date: 2021-06-14T10:13:32-07:00
New Revision: c58cf692f4197bf1f8ea7e0efb95c1afd2d6d81f
URL: https://github.com/llvm/llvm-project/commit/c58cf692f4197bf1f8ea7e0efb95c1afd2d6d81f
DIFF: https://github.com/llvm/llvm-project/commit/c58cf692f4197bf1f8ea7e0efb95c1afd2d6d81f.diff
LOG: [flang] Move buffer runtime test to GTest
Move buffer unit test from Runtime directory to RuntimeGtest
directory and use GTest. Test coverage is only maintained.
Differential Revision: https://reviews.llvm.org/D102335
Reviewed By: awarzynski, klausler
Added:
flang/unittests/RuntimeGTest/BufferTest.cpp
Modified:
flang/unittests/Runtime/CMakeLists.txt
flang/unittests/RuntimeGTest/CMakeLists.txt
Removed:
flang/unittests/Runtime/buffer.cpp
################################################################################
diff --git a/flang/unittests/Runtime/CMakeLists.txt b/flang/unittests/Runtime/CMakeLists.txt
index 2459aed47bb7..f4dba0d68e4c 100644
--- a/flang/unittests/Runtime/CMakeLists.txt
+++ b/flang/unittests/Runtime/CMakeLists.txt
@@ -31,8 +31,3 @@ add_flang_nongtest_unittest(external-io
RuntimeTesting
FortranRuntime
)
-
-add_flang_nongtest_unittest(buffer
- RuntimeTesting
- FortranRuntime
-)
diff --git a/flang/unittests/Runtime/buffer.cpp b/flang/unittests/RuntimeGTest/BufferTest.cpp
similarity index 73%
rename from flang/unittests/Runtime/buffer.cpp
rename to flang/unittests/RuntimeGTest/BufferTest.cpp
index f5eca0338939..e4096883f209 100644
--- 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 <algorithm>
#include <cstdint>
#include <cstring>
#include <memory>
-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<Store, tinyBuffer> {
+class Store : public FileFrame<Store, tinyBufferSize> {
public:
explicit Store(std::size_t bytes = 65536) : bytes_{bytes} {
data_.reset(new char[bytes]);
@@ -60,16 +69,17 @@ class Store : public FileFrame<Store, tinyBuffer> {
inline int ChunkSize(int j, int most) {
// 31, 1, 29, 3, 27, ...
- j %= tinyBuffer;
- auto chunk{
- static_cast<int>(((j % 2) ? j : (tinyBuffer - 1 - j)) % tinyBuffer)};
+ j %= tinyBufferSize;
+ auto chunk{static_cast<int>(
+ ((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 @@ int main() {
while (at < bytes) {
auto chunk{ChunkSize(j, static_cast<int>(bytes - at))};
std::size_t frame{store.ReadFrame(at, chunk, handler)};
- if (frame < static_cast<std::size_t>(chunk)) {
- Fail() << "Badly-sized ReadFrame at " << at << ", chunk=" << chunk
- << ", got " << frame << '\n';
- break;
- }
+ ASSERT_GE(frame, static_cast<std::size_t>(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<char>(ValueFor(at + k))};
- if (from[k] != expect) {
- Fail() << "At " << at << '+' << k << '(' << (at + k) << "), read "
- << (from[k] & 0xff) << ", expected " << static_cast<int>(expect)
- << '\n';
- }
+ ASSERT_EQ(from[k], expect)
+ << "At " << at << '+' << k << '(' << (at + k) << "), read "
+ << (from[k] & 0xff) << ", expected " << static_cast<int>(expect)
+ << '\n';
}
at += chunk;
++j;
}
- return EndTests();
}
diff --git a/flang/unittests/RuntimeGTest/CMakeLists.txt b/flang/unittests/RuntimeGTest/CMakeLists.txt
index a1e5348ee401..fb842c7d69f8 100644
--- 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
More information about the flang-commits
mailing list