BB2 C port
API reference: Blitz libraries in C and the shared code
Loading...
Searching...
No Matches
tlcore.h
Go to the documentation of this file.
1/*
2 * tlcore.h - the logic of the Blitz test library (testlib.c): blocks,
3 * checks, preconditions and the entries of the result file (spec
4 * testing/basic-test-interface, testing/basic-testlib).
5 *
6 * The library's routines call these functions with the one state of the
7 * library; the host tests (tests/host) call them with states of their
8 * own. Plain C99 on the freestanding headers, like the codec of
9 * shared/basictest whose writer makes the lines: no libc, no libgcc, no
10 * allocation. The entries leave through two functions the user defines:
11 *
12 * tl_os_write(line, n) writes n bytes to the result file (one call per
13 * write; on the Amiga one dos Write)
14 * tl_os_can_write() 1 if an entry may be written now, 0 if it must
15 * be kept (the program is in Blitz mode, or has
16 * multitasking or interrupts off)
17 * tl_os_fltnear(e,a,d) 1 if the FFP floats e and a differ by at most d,
18 * 0 if not, -1 if they cannot be compared (on the
19 * Amiga: mathffp.library is not open)
20 *
21 * What the functions write (the entries of basictest.h):
22 *
23 * tl_begin begin 1 (the state is cleared first)
24 * tl_block block init | block case NAME | block final; for a
25 * case after a batch init that failed a check: the
26 * first failed check of the init again (the case
27 * fails); after a batch init whose precondition
28 * failed: the precondition again and blockend (the
29 * case is broken and does not run); for the batch
30 * end after such an init nothing (it does not run)
31 * tl_blockend blockend
32 * tl_check(str) check / checkstr K ok|fail EXP ACT (checkstr: each
33 * value with the length and the CRC32 of the whole
34 * string, and - or cut)
35 * tl_checkq checkq K ok|fail EXP ACT (the quicks' bits)
36 * tl_checkflt checkflt K ok|fail EXP ACT DELTA (FFP bits); if the
37 * floats cannot be compared: `broken float compare
38 * not available` and the check as fail
39 * tl_require require K broken and blockend, if the condition is 0
40 * tl_expect_error expect-error K
41 * tl_finit incomplete (a block is open), end
42 * tl_run_start run K, if a program may start now (inside a block, in
43 * Amiga mode); else `broken run outside a block` or
44 * `broken run in Blitz mode` and it does not start
45 * tl_run_end runend K with the return code, or - where the system
46 * gave none; fills the result of the run (struct tl_run)
47 *
48 * A call out of order (a block inside a block, a check outside one, the
49 * batch init after a case, a case after the batch cleanup, a block end
50 * without a block, a second tl_begin) writes `broken REASON` before its
51 * own entry. A damaged state (its guard words overwritten) writes
52 * `broken state damaged` once; then only tl_finit writes, its `end`.
53 *
54 * Entries that cannot be written (tl_os_can_write() 0) are kept in the
55 * state, TL_PENDING bytes, and written before the next entry that can
56 * be, or by tl_finit, which always writes. Entries that do not fit are
57 * lost; `broken entries lost while kept` follows the kept ones then. A
58 * string check whose line does not fit into TL_LINE bytes has its two
59 * values cut until it fits and its last field `cut` (the verdict, the
60 * lengths and the CRC32s are those of the whole strings).
61 */
62#ifndef TLCORE_H
63#define TLCORE_H
64
65#include <stddef.h>
66#include <stdint.h>
67#include "basictest.h"
68
69#ifdef __cplusplus
70extern "C" {
71#endif
72
73#define TL_LINE 512 /* the longest entry */
74#define TL_PENDING 1024 /* entries kept while they cannot be written */
75
76#define TL_GUARD_LO 0x544C7374UL /* "TLst" */
77#define TL_GUARD_HI 0x7473544CUL /* "tsTL" */
78
79/** @brief The open block (enum basictest_block + 1; TL_NONE: none). */
82
83/** @brief The state of the library; all of it between two guard words. */
84struct tl_state {
85 uint32_t guard_lo;
86 uint8_t begun; /* tl_begin ran, tl_finit not yet */
87 uint8_t dead; /* the state was damaged: write nothing more */
88 uint8_t open; /* the open block (TL_NONE ...) */
89 uint8_t phase; /* the furthest block opened: TL_NONE ... TL_FINAL */
90 uint8_t init_failed; /* the batch init failed a check: init_line */
91 uint8_t init_broken; /* the batch init failed a precondition */
92 uint8_t lost; /* kept entries were lost */
93 uint8_t damaged; /* the note of a damaged state is to be written */
94 uint32_t init_broken_k; /* that precondition */
97 uint8_t line[TL_LINE]; /* the entry being written */
98 uint8_t init_line[TL_LINE]; /* the first failed check of the batch init */
100 uint32_t guard_hi;
101};
102
103/*
104 * The result of a started program (change basic-test-local-data, D6): the
105 * NewType TLRun of shared/basictest/macros.bas - on the Amiga the layout
106 * rc at 0, rcknown at 4, cut at 6, size at 8, printed at 12 (testlib.c
107 * checks it) - and the Blitz string its field printed points at: the
108 * characters, their length as a long before them and a 0 behind them.
109 * One static block of the library; a later run overwrites it.
110 */
111#define TL_RUN_TEXT 1024 /* the bytes of the output printed holds */
112
113struct tl_run {
114 int32_t rc; /* the return code, 0 if unknown */
115 int16_t rcknown; /* -1: the system gave it; 0: it gave none */
116 int16_t cut; /* -1: printed holds only the first TL_RUN_TEXT bytes */
117 uint32_t size; /* the bytes the program wrote */
118 const uint8_t *printed; /* the characters of the output (text.chars) */
119};
120
122 uint32_t length; /* the Blitz string: its length ... */
123 uint8_t chars[TL_RUN_TEXT + 2]; /* ... its characters and a 0 (even size) */
124};
125
126/* defined by the user of the functions (testlib.c, the host tests) */
127void tl_os_write(const uint8_t *data, size_t length);
128int tl_os_can_write(void);
129int tl_os_fltnear(uint32_t expected, uint32_t actual, uint32_t delta);
130
131/** @brief Clears the state and writes `begin`. */
132void tl_begin(struct tl_state *st);
133
134/**
135 * @brief Opens a block (block: enum basictest_block; name and length:
136 * the case name, ignored for the batch init and end).
137 * @return 1 if the block runs, 0 if it does not (no tl_begin, or after a
138 * batch init whose precondition failed).
139 */
140int tl_block(struct tl_state *st, int block, const uint8_t *name, size_t length);
141
142/** @brief Closes the open block. */
143void tl_blockend(struct tl_state *st);
144
145/** @brief A check of two longs: ok if they are equal. */
146void tl_check(struct tl_state *st, uint32_t k, uint32_t expected, uint32_t actual);
147
148/** @brief A check of two quicks (their 32 bits): ok if they are equal. */
149void tl_checkq(struct tl_state *st, uint32_t k, uint32_t expected, uint32_t actual);
150
151/** @brief A check of two FFP floats: ok if |actual-expected| <= delta. */
152void tl_checkflt(struct tl_state *st, uint32_t k, uint32_t expected, uint32_t actual,
153 uint32_t delta);
154
155/** @brief A check of two strings (bytes): ok if they are equal. */
156void tl_checkstr(struct tl_state *st, uint32_t k, const uint8_t *expected, size_t expected_length,
157 const uint8_t *actual, size_t actual_length);
158
159/**
160 * @brief A precondition.
161 * @return 1 if it failed inside a block: the caller leaves the block (the
162 * block's call returns a second time, with 0); 0 otherwise.
163 */
164int tl_require(struct tl_state *st, uint32_t k, uint32_t condition);
165
166/** @brief The announcement of an expected runtime error. */
167void tl_expect_error(struct tl_state *st, uint32_t k);
168
169/** @brief The end of the run: kept entries, `incomplete` if a block is open, `end`. */
170void tl_finit(struct tl_state *st);
171
172/**
173 * @brief A program is to start (TLRunProgram): the result r and its text t
174 * cleared (rc 0, unknown, nothing printed: printed the empty string), and
175 * `run K` written if it may start.
176 * @return 1 if it may start; 0 if not: no tl_begin, a damaged state, or
177 * refused with `broken` (outside a block, or while entries cannot be
178 * written: Blitz mode, Forbid, Disable).
179 */
180int tl_run_start(struct tl_state *st, uint32_t k, struct tl_run *r, struct tl_run_text *t);
181
182/**
183 * @brief The program ended (after tl_run_start gave 1): its output's first
184 * n bytes are in t->chars (n <= TL_RUN_TEXT), size the whole output; the
185 * result filled (printed of n bytes and a 0 behind, cut if size > n) and
186 * `runend K` written with rc if known, else `-`.
187 */
188void tl_run_end(struct tl_state *st, uint32_t k, struct tl_run *r, struct tl_run_text *t, int known, int32_t rc,
189 size_t n, uint32_t size);
190
191#ifdef __cplusplus
192}
193#endif
194
195#endif
ULONG WORD UWORD UWORD border ULONG ULONG struct bb_bitmap *dst void UWORD n
Definition 2dlib.c:2498
UWORD size
Definition 2dlib.c:1170
char * name
Definition asllib.c:150
@ BASICTEST_BLOCK_CASE
Definition basictest.h:89
@ BASICTEST_BLOCK_INIT
Definition basictest.h:88
@ BASICTEST_BLOCK_FINAL
Definition basictest.h:90
BL_ALWAYS_INLINE void block(const struct bb_shape *shape, const struct bb_bitmap *bm, UBYTE *cb, WORD x, WORD y)
Definition blitlib.c:241
void data(void)
static ULONG length(const UBYTE *s)
Definition filereq_core.c:280
static struct @116141142274037024203205202074071112317221044374 st
Definition animlib.c:142
Definition tlcore.h:121
uint32_t length
Definition tlcore.h:122
uint8_t chars[TL_RUN_TEXT+2]
Definition tlcore.h:123
Definition tlcore.h:113
int32_t rc
Definition tlcore.h:114
uint32_t size
Definition tlcore.h:117
int16_t rcknown
Definition tlcore.h:115
int16_t cut
Definition tlcore.h:116
const uint8_t * printed
Definition tlcore.h:118
The state of the library; all of it between two guard words.
Definition tlcore.h:84
uint32_t guard_lo
Definition tlcore.h:85
uint8_t init_line[TL_LINE]
Definition tlcore.h:98
size_t init_length
Definition tlcore.h:95
uint8_t phase
Definition tlcore.h:89
size_t pending_length
Definition tlcore.h:96
uint8_t lost
Definition tlcore.h:92
uint8_t line[TL_LINE]
Definition tlcore.h:97
uint8_t open
Definition tlcore.h:88
uint8_t pending[TL_PENDING]
Definition tlcore.h:99
uint8_t dead
Definition tlcore.h:87
uint32_t init_broken_k
Definition tlcore.h:94
uint8_t init_broken
Definition tlcore.h:91
uint8_t damaged
Definition tlcore.h:93
uint8_t init_failed
Definition tlcore.h:90
uint32_t guard_hi
Definition tlcore.h:100
uint8_t begun
Definition tlcore.h:86
void tl_os_write(const uint8_t *data, size_t length)
Definition testlib.c:160
#define TL_RUN_TEXT
Definition tlcore.h:111
void tl_check(struct tl_state *st, uint32_t k, uint32_t expected, uint32_t actual)
A check of two longs: ok if they are equal.
Definition tlcore.c:241
void tl_run_end(struct tl_state *st, uint32_t k, struct tl_run *r, struct tl_run_text *t, int known, int32_t rc, size_t n, uint32_t size)
The program ended (after tl_run_start gave 1): its output's first n bytes are in t->chars (n <= TL_RU...
Definition tlcore.c:405
int tl_os_fltnear(uint32_t expected, uint32_t actual, uint32_t delta)
Definition testlib.c:174
#define TL_LINE
Definition tlcore.h:73
void tl_checkq(struct tl_state *st, uint32_t k, uint32_t expected, uint32_t actual)
A check of two quicks (their 32 bits): ok if they are equal.
Definition tlcore.c:258
void tl_finit(struct tl_state *st)
The end of the run: kept entries, incomplete if a block is open, end.
Definition tlcore.c:357
int tl_block(struct tl_state *st, int block, const uint8_t *name, size_t length)
Opens a block (block: enum basictest_block; name and length: the case name, ignored for the batch ini...
Definition tlcore.c:176
void tl_expect_error(struct tl_state *st, uint32_t k)
The announcement of an expected runtime error.
Definition tlcore.c:346
int tl_run_start(struct tl_state *st, uint32_t k, struct tl_run *r, struct tl_run_text *t)
A program is to start (TLRunProgram): the result r and its text t cleared (rc 0, unknown,...
Definition tlcore.c:385
void tl_blockend(struct tl_state *st)
Closes the open block.
Definition tlcore.c:221
void tl_checkflt(struct tl_state *st, uint32_t k, uint32_t expected, uint32_t actual, uint32_t delta)
A check of two FFP floats: ok if |actual-expected| <= delta.
Definition tlcore.c:275
void tl_begin(struct tl_state *st)
Clears the state and writes begin.
Definition tlcore.c:155
int tl_require(struct tl_state *st, uint32_t k, uint32_t condition)
A precondition.
Definition tlcore.c:326
int tl_os_can_write(void)
Definition testlib.c:166
@ TL_FINAL
Definition tlcore.h:81
@ TL_NONE
Definition tlcore.h:80
@ TL_CASE
Definition tlcore.h:80
@ TL_INIT
Definition tlcore.h:80
void tl_checkstr(struct tl_state *st, uint32_t k, const uint8_t *expected, size_t expected_length, const uint8_t *actual, size_t actual_length)
A check of two strings (bytes): ok if they are equal.
Definition tlcore.c:298
#define TL_PENDING
Definition tlcore.h:74