mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-02-25 13:05:04 +00:00
[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
This commit is contained in:
parent
ce77039596
commit
c58cf692f4
@ -31,8 +31,3 @@ add_flang_nongtest_unittest(external-io
|
||||
RuntimeTesting
|
||||
FortranRuntime
|
||||
)
|
||||
|
||||
add_flang_nongtest_unittest(buffer
|
||||
RuntimeTesting
|
||||
FortranRuntime
|
||||
)
|
||||
|
@ -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 @@ private:
|
||||
|
||||
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();
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
add_flang_unittest(FlangRuntimeTests
|
||||
BufferTest.cpp
|
||||
CharacterTest.cpp
|
||||
CrashHandlerFixture.cpp
|
||||
Format.cpp
|
||||
|
Loading…
x
Reference in New Issue
Block a user