Skip to content

Commit c58cf69

Browse files
[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
1 parent ce77039 commit c58cf69

File tree

3 files changed

+27
-24
lines changed

3 files changed

+27
-24
lines changed

flang/unittests/Runtime/CMakeLists.txt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,3 @@ add_flang_nongtest_unittest(external-io
3131
RuntimeTesting
3232
FortranRuntime
3333
)
34-
35-
add_flang_nongtest_unittest(buffer
36-
RuntimeTesting
37-
FortranRuntime
38-
)

flang/unittests/Runtime/buffer.cpp renamed to flang/unittests/RuntimeGTest/BufferTest.cpp

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
1+
//===-- flang/unittests/RuntimeGTest/BufferTest.cpp -------------*- C++ -*-===//
2+
//
3+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
// See https://llvm.org/LICENSE.txt for license information.
5+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
//
7+
//===----------------------------------------------------------------------===//
8+
19
#include "../../runtime/buffer.h"
2-
#include "testing.h"
10+
#include "CrashHandlerFixture.h"
11+
#include "gtest/gtest.h"
312
#include <algorithm>
413
#include <cstdint>
514
#include <cstring>
615
#include <memory>
716

8-
static constexpr std::size_t tinyBuffer{32};
17+
static constexpr std::size_t tinyBufferSize{32};
918
using FileOffset = std::int64_t;
1019
using namespace Fortran::runtime;
1120
using namespace Fortran::runtime::io;
1221

13-
class Store : public FileFrame<Store, tinyBuffer> {
22+
class Store : public FileFrame<Store, tinyBufferSize> {
1423
public:
1524
explicit Store(std::size_t bytes = 65536) : bytes_{bytes} {
1625
data_.reset(new char[bytes]);
@@ -60,16 +69,17 @@ class Store : public FileFrame<Store, tinyBuffer> {
6069

6170
inline int ChunkSize(int j, int most) {
6271
// 31, 1, 29, 3, 27, ...
63-
j %= tinyBuffer;
64-
auto chunk{
65-
static_cast<int>(((j % 2) ? j : (tinyBuffer - 1 - j)) % tinyBuffer)};
72+
j %= tinyBufferSize;
73+
auto chunk{static_cast<int>(
74+
((j % 2) ? j : (tinyBufferSize - 1 - j)) % tinyBufferSize)};
6675
return std::min(chunk, most);
6776
}
6877

6978
inline int ValueFor(int at) { return (at ^ (at >> 8)) & 0xff; }
7079

71-
int main() {
72-
StartTests();
80+
struct BufferTests : CrashHandlerFixture {};
81+
82+
TEST(BufferTests, TestFrameBufferReadAndWrite) {
7383
Terminator terminator{__FILE__, __LINE__};
7484
IoErrorHandler handler{terminator};
7585
Store store;
@@ -94,22 +104,19 @@ int main() {
94104
while (at < bytes) {
95105
auto chunk{ChunkSize(j, static_cast<int>(bytes - at))};
96106
std::size_t frame{store.ReadFrame(at, chunk, handler)};
97-
if (frame < static_cast<std::size_t>(chunk)) {
98-
Fail() << "Badly-sized ReadFrame at " << at << ", chunk=" << chunk
99-
<< ", got " << frame << '\n';
100-
break;
101-
}
107+
ASSERT_GE(frame, static_cast<std::size_t>(chunk))
108+
<< "Badly-sized ReadFrame at " << at << ", chunk=" << chunk << ", got "
109+
<< frame << '\n';
110+
102111
const char *from{store.Frame()};
103112
for (int k{0}; k < chunk; ++k) {
104113
auto expect{static_cast<char>(ValueFor(at + k))};
105-
if (from[k] != expect) {
106-
Fail() << "At " << at << '+' << k << '(' << (at + k) << "), read "
107-
<< (from[k] & 0xff) << ", expected " << static_cast<int>(expect)
108-
<< '\n';
109-
}
114+
ASSERT_EQ(from[k], expect)
115+
<< "At " << at << '+' << k << '(' << (at + k) << "), read "
116+
<< (from[k] & 0xff) << ", expected " << static_cast<int>(expect)
117+
<< '\n';
110118
}
111119
at += chunk;
112120
++j;
113121
}
114-
return EndTests();
115122
}

flang/unittests/RuntimeGTest/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
add_flang_unittest(FlangRuntimeTests
2+
BufferTest.cpp
23
CharacterTest.cpp
34
CrashHandlerFixture.cpp
45
Format.cpp

0 commit comments

Comments
 (0)