Coverage Report

Created: 2025-10-10 06:44

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/immer/extra/fuzzer/set-st.cpp
Line
Count
Source
1
//
2
// immer: immutable data structures for C++
3
// Copyright (C) 2016, 2017, 2018 Juan Pedro Bolivar Puente
4
//
5
// This software is distributed under the Boost Software License, Version 1.0.
6
// See accompanying file LICENSE or copy at http://boost.org/LICENSE_1_0.txt
7
//
8
9
#include "fuzzer_input.hpp"
10
11
#include <immer/heap/gc_heap.hpp>
12
#include <immer/refcount/no_refcount_policy.hpp>
13
#include <immer/set.hpp>
14
15
#include <immer/algorithm.hpp>
16
17
#include <array>
18
19
using st_memory = immer::memory_policy<immer::heap_policy<immer::cpp_heap>,
20
                                       immer::unsafe_refcount_policy,
21
                                       immer::no_lock_policy,
22
                                       immer::no_transience_policy,
23
                                       false>;
24
25
struct colliding_hash_t
26
{
27
638k
    std::size_t operator()(std::size_t x) const { return x & ~15; }
28
};
29
30
extern "C" int LLVMFuzzerTestOneInput(const std::uint8_t* data,
31
                                      std::size_t size)
32
4.22k
{
33
4.22k
    constexpr auto var_count = 4;
34
35
4.22k
    using set_t =
36
4.22k
        immer::set<size_t, colliding_hash_t, std::equal_to<>, st_memory>;
37
38
4.22k
    auto vars = std::array<set_t, var_count>{};
39
40
665k
    auto is_valid_var = [&](auto idx) { return idx >= 0 && idx < var_count; };
41
42
184k
    return fuzzer_input{data, size}.run([&](auto& in) {
43
184k
        enum ops
44
184k
        {
45
184k
            op_insert,
46
184k
            op_erase,
47
184k
            op_insert_move,
48
184k
            op_erase_move,
49
184k
            op_iterate,
50
184k
            op_diff
51
184k
        };
52
184k
        auto src = read<char>(in, is_valid_var);
53
184k
        auto dst = read<char>(in, is_valid_var);
54
184k
        switch (read<char>(in)) {
55
90.0k
        case op_insert: {
56
90.0k
            auto value = read<size_t>(in);
57
90.0k
            vars[dst]  = vars[src].insert(value);
58
90.0k
            break;
59
0
        }
60
11.6k
        case op_erase: {
61
11.6k
            auto value = read<size_t>(in);
62
11.6k
            vars[dst]  = vars[src].erase(value);
63
11.6k
            break;
64
0
        }
65
21.3k
        case op_insert_move: {
66
21.3k
            auto value = read<size_t>(in);
67
21.3k
            vars[dst]  = std::move(vars[src]).insert(value);
68
21.3k
            break;
69
0
        }
70
10.4k
        case op_erase_move: {
71
10.4k
            auto value = read<size_t>(in);
72
10.4k
            vars[dst]  = std::move(vars[src]).erase(value);
73
10.4k
            break;
74
0
        }
75
8.09k
        case op_iterate: {
76
8.09k
            auto srcv = vars[src];
77
228k
            for (const auto& v : srcv) {
78
228k
                vars[dst] = vars[dst].insert(v);
79
228k
            }
80
8.09k
            break;
81
0
        }
82
14.3k
        case op_diff: {
83
14.3k
            auto&& a = vars[src];
84
14.3k
            auto&& b = vars[dst];
85
14.3k
            diff(
86
14.3k
                a,
87
14.3k
                b,
88
58.6k
                [&](auto&& x) {
89
58.6k
                    assert(!a.count(x));
90
58.6k
                    assert(b.count(x));
91
58.6k
                },
92
60.6k
                [&](auto&& x) {
93
60.6k
                    assert(a.count(x));
94
60.6k
                    assert(!b.count(x));
95
60.6k
                },
96
14.3k
                [&](auto&& x, auto&& y) { assert(false); });
97
14.3k
        }
98
38.6k
        default:
99
38.6k
            break;
100
184k
        };
101
180k
        return true;
102
184k
    });
103
4.22k
}