Generated on for Gecode by doxygen 1.15.0
failpoint.cpp
Go to the documentation of this file.
1/* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2/*
3 * Main authors:
4 * Mikael Zayenz Lagerkvist <lagerkvist@gecode.dev>
5 *
6 * Copyright:
7 * Mikael Zayenz Lagerkvist, 2026
8 *
9 * This file is part of Gecode, the generic constraint
10 * development environment:
11 * http://www.gecode.dev
12 *
13 * Permission is hereby granted, free of charge, to any person obtaining
14 * a copy of this software and associated documentation files (the
15 * "Software"), to deal in the Software without restriction, including
16 * without limitation the rights to use, copy, modify, merge, publish,
17 * distribute, sublicense, and/or sell copies of the Software, and to
18 * permit persons to whom the Software is furnished to do so, subject to
19 * the following conditions:
20 *
21 * The above copyright notice and this permission notice shall be
22 * included in all copies or substantial portions of the Software.
23 *
24 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 *
32 */
33
34#include <gecode/support.hh>
35
36#ifdef GECODE_HAS_FAULT_INJECTION
37
38namespace Gecode { namespace Support { namespace FailPoint {
39
40 namespace {
41 std::atomic<unsigned long long> fail_after_count;
42 std::atomic<unsigned long long> seen_count;
43 std::atomic<int> active_phase;
44 }
45
46 void reset(void) {
47 active_phase.store(static_cast<int>(Phase::Disabled),
48 std::memory_order_release);
49 fail_after_count.store(0, std::memory_order_release);
50 seen_count.store(0, std::memory_order_release);
51 }
52
53 void fail_after(Phase p, unsigned long long n) {
54 seen_count.store(0, std::memory_order_release);
55 fail_after_count.store(n, std::memory_order_release);
56 active_phase.store(static_cast<int>(p), std::memory_order_release);
57 }
58
59 void check(Phase p) {
60 if (active_phase.load(std::memory_order_acquire) != static_cast<int>(p))
61 return;
62 unsigned long long seen =
63 seen_count.fetch_add(1, std::memory_order_acq_rel);
64 if (seen >= fail_after_count.load(std::memory_order_acquire))
65 throw MemoryExhausted();
66 }
67
68 unsigned long long count(void) {
69 return seen_count.load(std::memory_order_acquire);
70 }
71
72}}}
73
74#endif
75
76// STATISTICS: support-any
Phase
Named phase for deterministic test failure injection.
Definition failpoint.hpp:49
void reset(void)
Reset all failpoint state.
void check(Phase p)
Check failpoint for phase p.
unsigned long long count(void)
Number of checks observed for the configured phase.
void fail_after(Phase p, unsigned long long n)
Fail after n successful checks for phase p.
Support algorithms and datastructures
Gecode toplevel namespace