Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
fuzz_checkpoint_loader.cc
Go to the documentation of this file.
1/*
2 Aleph_w
3
4 Data structures & Algorithms
5 https://github.com/lrleon/Aleph-w
6
7 This file is part of Aleph-w library
8
9 Copyright (c) 2002-2026 Leandro Rabindranath Leon
10
11 Permission is hereby granted, free of charge, to any person obtaining a copy
12 of this software and associated documentation files (the "Software"), to deal
13 in the Software without restriction, including without limitation the rights
14 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 copies of the Software, and to permit persons to whom the Software is
16 furnished to do so, subject to the following conditions:
17
18 The above copyright notice and this permission notice shall be included in all
19 copies or substantial portions of the Software.
20
21 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27 SOFTWARE.
28*/
29
42#include <cstddef>
43#include <cstdint>
44#include <filesystem>
45#include <fstream>
46#include <string>
47#include <unistd.h>
48
49#include <ca-checkpoint.H>
50#include <ca-traits.H>
51#include <tpl_ca_engine.H>
52#include <tpl_ca_lattice.H>
53#include <tpl_ca_neighborhood.H>
54#include <tpl_ca_rule.H>
55#include <tpl_ca_storage.H>
56
57using namespace Aleph;
58using namespace Aleph::CA;
59
60namespace
61{
62
65
66// Per-process scratch file, created once and overwritten each iteration.
67const std::filesystem::path &scratch_path()
68{
69 static const std::filesystem::path p =
70 std::filesystem::temp_directory_path() /
71 ("aleph_fuzz_ckpt_" + std::to_string(::getpid()) + ".bin");
72 return p;
73}
74
75} // namespace
76
77extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
78{
79 const auto &path = scratch_path();
80 {
81 std::ofstream out(path, std::ios::binary | std::ios::trunc);
82 out.write(reinterpret_cast<const char *>(data),
83 static_cast<std::streamsize>(size));
84 }
85
86 try
87 {
88 Engine engine(Grid({16, 16}, 0), make_game_of_life_rule(), Moore<2, 1>{});
89 const Resume_Token token = load_checkpoint_into(engine, path);
90 (void) token;
91 }
92 catch (...)
93 {
94 // Rejecting a malformed/incompatible checkpoint is correct.
95 }
96
97 return 0;
98}
size_t size_t int32_t * out
Definition ca-c-api.h:120
Binary checkpoint format for Aleph::CA engines (Phase 15 + Phase 17 crash-safe / compress / async wri...
Common typedefs and tag types for the Cellular Automata module.
Lattice that adds boundary-aware access on top of a storage.
Moore (Chebyshev) neighborhood of radius R in N dimensions.
Synchronous double-buffered engine.
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
size_t blossom_maximum_cardinality_matching(const GT &g, DynDlist< typename GT::Arc * > &matching, SA sa=SA())
Alias of compute_maximum_cardinality_general_matching().
Definition Blossom.H:466
constexpr Game_Of_Life_Rule make_game_of_life_rule() noexcept
Build the canonical Game of Life rule.
Resume_Token load_checkpoint_into(Engine &engine, const std::filesystem::path &path)
Restore an engine's state in-place from a checkpoint file.
Main namespace for Aleph-w library functions.
Definition ah-arena.H:89
size_t size(Node *root) noexcept
Resume handle returned by load_checkpoint_into.
The lattice wraps around on every axis.
Definition ca-traits.H:124
static mt19937 engine
Synchronous double-buffered engine for cellular automata.
Cellular automata lattice with pluggable boundary policies.
Neighborhoods catalogue for Aleph::CA.
Rule mechanisms for Aleph::CA.
Dense, contiguous storage for cellular automata cells (1D/2D/3D).