From 5dbcc396dad13996d7558cc90165f15fa54e5366 Mon Sep 17 00:00:00 2001 From: Martin Janiczek Date: Tue, 24 Oct 2023 00:21:48 +0200 Subject: [PATCH] LibTest: Add the Chunk abstraction A prerequisite for shrinking the failing RandomRuns in randomized tests. --- Userland/Libraries/LibTest/Randomized/Chunk.h | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 Userland/Libraries/LibTest/Randomized/Chunk.h diff --git a/Userland/Libraries/LibTest/Randomized/Chunk.h b/Userland/Libraries/LibTest/Randomized/Chunk.h new file mode 100644 index 0000000000..2cd78e1c25 --- /dev/null +++ b/Userland/Libraries/LibTest/Randomized/Chunk.h @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2023, Martin Janiczek + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include +#include + +namespace Test { +namespace Randomized { + +// Chunk is a description of a RandomRun slice. +// Used to say which part of a given RandomRun will be shrunk by some +// ShrinkCommand. +// +// For a RandomRun [0,1,2,3,4,5,6,7,8], the Chunk{size=4, index=2} means this: +// [_,_,X,X,X,X,_,_,_] +// +// Different ShrinkCommands will use the Chunk in different ways. +// A few examples: +// +// Original RandomRun: [5,1,3,9,4,2,3,0] +// Chunk we'll show off: [_,_,X,X,X,X,_,_] +// +// ZeroChunk: [5,1,0,0,0,0,3,0] +// SortChunk: [5,1,2,3,4,9,3,0] +// DeleteChunkAndMaybeDecPrevious: [5,1, 3,0] +struct Chunk { + // Possible sizes: 1,2,3,4,8 + u8 size = 0; + size_t index = 0; +}; + +} // namespace Randomized +} // namespace Test + +template<> +struct AK::Formatter : Formatter { + ErrorOr format(FormatBuilder& builder, Test::Randomized::Chunk chunk) + { + return Formatter::format(builder, TRY(String::formatted("Chunk", chunk.size, chunk.index))); + } +};