Coverage Report

Created: 2026-05-30 06:17

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
883k
    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.33k
{
33
4.33k
    constexpr auto var_count = 4;
34
35
4.33k
    using set_t =
36
4.33k
        immer::set<size_t, colliding_hash_t, std::equal_to<>, st_memory>;
37
38
4.33k
    auto vars = std::array<set_t, var_count>{};
39
40
649k
    auto is_valid_var = [&](auto idx) { return idx >= 0 && idx < var_count; };
41
42
199k
    return fuzzer_input{data, size}.run([&](auto& in) {
43
199k
        enum ops
44
199k
        {
45
199k
            op_insert,
46
199k
            op_erase,
47
199k
            op_insert_move,
48
199k
            op_erase_move,
49
199k
            op_iterate,
50
199k
            op_diff
51
199k
        };
52
199k
        auto src = read<char>(in, is_valid_var);
53
199k
        auto dst = read<char>(in, is_valid_var);
54
199k
        switch (read<char>(in)) {
55
94.3k
        case op_insert: {
56
94.3k
            auto value = read<size_t>(in);
57
94.3k
            vars[dst]  = vars[src].insert(value);
58
94.3k
            break;
59
0
        }
60
14.2k
        case op_erase: {
61
14.2k
            auto value = read<size_t>(in);
62
14.2k
            vars[dst]  = vars[src].erase(value);
63
14.2k
            break;
64
0
        }
65
24.4k
        case op_insert_move: {
66
24.4k
            auto value = read<size_t>(in);
67
24.4k
            vars[dst]  = std::move(vars[src]).insert(value);
68
24.4k
            break;
69
0
        }
70
13.0k
        case op_erase_move: {
71
13.0k
            auto value = read<size_t>(in);
72
13.0k
            vars[dst]  = std::move(vars[src]).erase(value);
73
13.0k
            break;
74
0
        }
75
9.24k
        case op_iterate: {
76
9.24k
            auto srcv = vars[src];
77
337k
            for (const auto& v : srcv) {
78
337k
                vars[dst] = vars[dst].insert(v);
79
337k
            }
80
9.24k
            break;
81
0
        }
82
16.9k
        case op_diff: {
83
16.9k
            auto&& a = vars[src];
84
16.9k
            auto&& b = vars[dst];
85
16.9k
            diff(
86
16.9k
                a,
87
16.9k
                b,
88
88.0k
                [&](auto&& x) {
89
88.0k
                    assert(!a.count(x));
90
88.0k
                    assert(b.count(x));
91
88.0k
                },
92
92.1k
                [&](auto&& x) {
93
92.1k
                    assert(a.count(x));
94
92.1k
                    assert(!b.count(x));
95
92.1k
                },
96
16.9k
                [&](auto&& x, auto&& y) { assert(false); });
97
16.9k
        }
98
40.4k
        default:
99
40.4k
            break;
100
199k
        };
101
195k
        return true;
102
199k
    });
103
4.33k
}