MMgr v2.3.0
Zero-heap memory manager in C11. One borrowed buffer, carved by asserted offset.
Loading...
Searching...
No Matches
praet_procurator.h
Go to the documentation of this file.
1/* MMgr - Copyright (C) 2026 Douglas Quigg (dstroy0) <dquigg123@gmail.com>
2 * SPDX-License-Identifier: AGPL-3.0-or-later OR LicenseRef-Commercial OR LicenseRef-Educational
3 *
4 * Every use falls under AGPL-3.0-or-later unless you hold explicit permission, which is either a
5 * negotiated commercial licensing contract or an educator's license issued to you personally.
6 */
7/**
8 * @file praet_procurator.h
9 * @brief Which states and transitions a run actually reached.
10 * @author dstroy0 (Douglas Quigg) <dquigg123@gmail.com>
11 * @date 2026-09-01
12 *
13 * @note The examination arm. The correctness arm says every case passed, and that says nothing about
14 * which of the machine's states and transitions any case walked through. A four state core with
15 * eight statuses has more paths than a suite this size can cover by accident. So the ones it
16 * misses are worth a look before any of it reaches a part.
17 * @note Reports and does not gate. A transition nothing reached is a hole in the cases. Whether it
18 * is worth a case is a reading of the report and not a build failure. The optimization arm is
19 * this same instrument with timings.
20 * @note Off unless PRAET_PROCURATOR is 1, and every entry is then a macro that expands to nothing. A
21 * build that did not ask for it carries no counter and no call.
22 * @note Declared here and defined in the suite. The one function that writes a flag word calls these.
23 * The counters and the table they print belong to a run of the suite, at
24 * test/integration/test_praet_correctness/praet_procurator.c.
25 * @warning A build with PRAET_PROCURATOR at 1 links against those definitions and fails to link
26 * without them. An image for a part has no reason to set it.
27 * @warning Not a knob praet_iudex.h asks about. Every knob there describes the image a
28 * caller ships; this describes a run of the suite, the harness's business and not
29 * the caller's.
30 */
31#ifndef MMGR_PRAET_PROCURATOR_H
32#define MMGR_PRAET_PROCURATOR_H
33
34/** @addtogroup mod_praet
35 * @{ */
36
38
39/**
40 * @brief Whether a run records the work it did, on top of the states it reached.
41 *
42 * @note The optimization arm, and it is the examination arm with more counters. It records
43 * work. Entries called, channels walked, times the poll short circuited, times the port heard
44 * a question, and the bytes of state a context costs.
45 * @note No times, and none deliberately. A count of work is the same on every run of one build, and so it
46 * is a fact a host can state. What that work costs is a property of a part. A number taken
47 * here would be a number about this machine dressed as a number about the library.
48 * @note Reports and does not gate, the same as the examination arm. A count that grew is worth reading
49 * and is not a build failure, because the measure of whether it matters lives somewhere else.
50 */
51#ifndef PRAET_OPTIMIZE
52#define PRAET_OPTIMIZE 0
53#endif
54
55#if (PRAET_OPTIMIZE != 0) && (PRAET_OPTIMIZE != 1)
56#error "PRAET_OPTIMIZE must be 0 or 1."
57#endif
58
59/**
60 * @brief Whether a run records the states and transitions it reached.
61 *
62 * @note Turned on by PRAET_OPTIMIZE as well. The work counts read beside the states they bought,
63 * and a report with one half absent says less than either half alone.
64 */
65#ifndef PRAET_PROCURATOR
66#if PRAET_OPTIMIZE
67#define PRAET_PROCURATOR 1
68#else
69#define PRAET_PROCURATOR 0
70#endif
71#endif
72
73#if (PRAET_PROCURATOR != 0) && (PRAET_PROCURATOR != 1)
74#error "PRAET_PROCURATOR must be 0 or 1."
75#endif
76
77#if PRAET_OPTIMIZE && !PRAET_PROCURATOR
78#error "PRAET_OPTIMIZE needs PRAET_PROCURATOR, which it turns on by itself unless something set it to 0."
79#endif
80
81#if PRAET_PROCURATOR
82
83EMBED_BEGIN_DECLS
84
85/**
86 * @brief Records one change of a channel's flag word.
87 *
88 * @param[in] channel Channel whose word changed.
89 * @param[in] was The word before.
90 * @param[in] now The word after.
91 * @note Called from the one function that writes a flag word, and that leaves the record complete,
92 * with the sites nobody remembered to instrument in it.
93 * @note Records the core transition as a pair, and every status bit that came on or went off. A word
94 * that changed only its region descriptor records neither, and nothing here reads the region.
95 */
96EMBED_HOST_DEVICE void praet_procurator_transitus(embed_word channel, uint32_t was, uint32_t now);
97
98/**
99 * @brief Prints what the run reached, as a table.
100 *
101 * @note Written to stdout, because this is a report a person reads and not a result anything asserts
102 * on. A suite that fails still prints it, which is when it is worth max.
103 * @note Prints the work the run did as well, where PRAET_OPTIMIZE is on.
104 */
105EMBED_HOST_DEVICE void praet_procurator_report(void);
106
107EMBED_END_DECLS
108
109#else
110
111/**
112 * @brief Expands to nothing where PRAET_PROCURATOR is 0.
113 *
114 * @param channel_ Channel whose word changed, discarded.
115 * @param was_ The word before, discarded.
116 * @param now_ The word after, discarded.
117 * @note Casts each argument to void, which retains a build without the instrument from a warning about the values
118 * it received.
119 */
120#define praet_procurator_transitus(channel_, was_, now_) ((void)(channel_), (void)(was_), (void)(now_))
121
122/**
123 * @brief Expands to nothing where PRAET_PROCURATOR is 0.
124 */
125#define praet_procurator_report() ((void)0)
126
127#endif
128
129#if PRAET_OPTIMIZE
130
131EMBED_BEGIN_DECLS
132
133/**
134 * @brief The pieces of work an optimization run counts.
135 *
136 * @note One id per entry a caller can reach, plus the two things the poll does that are worth a split
137 * apart. Dense from zero, because the counters are an array indexed by these.
138 */
139typedef enum
140{
141 PRAET_OPUS_ADNECTERE = 0, /**< praet_ordo_adnectere ran. */
142 PRAET_OPUS_SEPARARE = 1, /**< praet_ordo_separare ran. */
143 PRAET_OPUS_RELATIO = 2, /**< praet_ordo_relatio ran. */
144 PRAET_OPUS_EFFICERE = 3, /**< praet_ordo_efficere ran. */
145 PRAET_OPUS_COMPLETED = 4, /**< praet_ordo_completed ran. */
146 PRAET_OPUS_RESOLVE = 5, /**< praet_ordo_resolve ran. */
147 PRAET_OPUS_POLL = 6, /**< praet_ordo_poll ran. */
148 PRAET_OPUS_POLL_SHORT = 7, /**< A poll that found nothing to do and returned. */
149 PRAET_OPUS_POLL_WALK = 8, /**< A poll that walked every channel. */
150 PRAET_OPUS_ALVEUS = 9, /**< One channel visited inside a walk. */
151 PRAET_OPUS_PROGRESS = 10, /**< The port heard a question about how far a channel got. */
152 PRAET_OPUS_KINDS = 11 /**< How many types there are, which sizes the counters. */
153} PraetOpus;
154
155/**
156 * @brief Counts one piece of work.
157 *
158 * @param[in] type The work done, as a PraetOpus.
159 */
160EMBED_HOST_DEVICE void praet_procurator_opus(unsigned type);
161
162EMBED_END_DECLS
163
164#else
165
166/**
167 * @brief Expands to nothing where PRAET_OPTIMIZE is 0.
168 *
169 * @param type_ The work done, dropped.
170 */
171#define praet_procurator_opus(type_) ((void)0)
172
173#endif
174
175/** @} */
176
177#endif
#define praet_procurator_transitus(channel_, was_, now_)
Expands to nothing where PRAET_PROCURATOR is 0.
#define praet_procurator_opus(type_)
Expands to nothing where PRAET_OPTIMIZE is 0.
#define praet_procurator_report()
Expands to nothing where PRAET_PROCURATOR is 0.
Every bit of the channel flag word, and the assertions that retain the map from drift.