BB2 C port
API reference: Blitz libraries in C and the shared code
Loading...
Searching...
No Matches
basictest.h
Go to the documentation of this file.
1/*
2 * basictest.h - the codec of the result file of the Blitz test library
3 * (spec testing/basic-test-interface, "Lines of the result file",
4 * "Entries of the result file", "One codec for writer and reader").
5 *
6 * The result file holds one entry per line, fields separated by TAB, each
7 * line ended by LF:
8 *
9 * begin VERSION the format version (1)
10 * block init | case NAME | final the block the next entries
11 * belong to (NAME a string value,
12 * a field of its own)
13 * check K ok|fail EXP ACT a check of two longs
14 * checkq K ok|fail EXP ACT a check of two quicks (their bits)
15 * checkflt K ok|fail EXP ACT DELTA a check of two floats within a
16 * delta (their FFP bits)
17 * checkstr K ok|fail EXP$ ELEN ECRC ACT$ ALEN ACRC CUT
18 * a check of two strings, each
19 * followed by the length and the
20 * CRC32 of the whole string; CUT
21 * `-` (both complete) or `cut` (a
22 * value shortened to fit the line)
23 * require K broken a failed precondition
24 * expect-error K an announced runtime error
25 * blockend the end of the block
26 * broken REASON the library's state is broken
27 * incomplete the finit found a block open
28 * end the finit
29 * run K a program is started (!RunProgram)
30 * runend K RC|- it returned: its return code (a
31 * long value), `-` where the system
32 * gives none (Kickstart 1.x)
33 *
34 * K and a length are decimal (0 to 4294967295, no sign, no leading zero),
35 * a long value (also the 32 bits of a quick or an FFP float) and a CRC32
36 * `$` and 8 upper-case hex digits, a string value the bytes $20 to $7E
37 * other than `\` as they are and every other byte as `\xHH` (upper-case
38 * hex digits). A string value is cut if it is shorter than its length
39 * (it is the start of the string then); the reader refuses a value longer
40 * than its length, a complete value whose CRC32 is not that of its bytes,
41 * CUT `-` with a cut value and CUT `cut` without one. The CRC32 is the
42 * standard CRC-32 of IEEE 802.3 (basictest_crc32).
43 *
44 * Shared code like shared/tokenizer: every user compiles the files itself
45 * with its own options - the host tools all (tools/lib/basictest), the
46 * build the writer and the CRC32 (basictest_write.c, basictest_crc.c) with
47 * the Blitz library conventions (cmake/BlitzLibrary.cmake), the form the
48 * test library (libs/userlibs/testlib) links. C99 on the freestanding
49 * headers: no libc, no libgcc (no 32-bit multiply, divide or modulo on
50 * the 68000), no writable static data, no allocation - the caller gives
51 * the memory. The build compiles writer and CRC32 in the library
52 * environment and refuses them if they refer to any symbol they do not
53 * define (shared/basictest/CMakeLists.txt).
54 */
55#ifndef BASICTEST_H
56#define BASICTEST_H
57
58#include <stddef.h>
59#include <stdint.h>
60
61#ifdef __cplusplus
62extern "C" {
63#endif
64
65/** @brief The format version the codec writes and reads (`begin`). */
66#define BASICTEST_VERSION 1
67
68/** @brief The entry kinds. */
85
86/** @brief The blocks of a `block` entry. */
88 BASICTEST_BLOCK_INIT, /* the batch init */
89 BASICTEST_BLOCK_CASE, /* a case, with its name */
90 BASICTEST_BLOCK_FINAL /* the batch cleanup */
91};
92
93/** @brief A string value: bytes, any value, not 0-terminated. */
95 const uint8_t *data;
96 size_t length;
97};
98
99/**
100 * @brief One entry. Only the members of its kind count:
101 * begin version
102 * block block, name (BASICTEST_BLOCK_CASE)
103 * check k, ok, expected, actual
104 * checkq k, ok, expected, actual (the quicks' bits)
105 * checkflt k, ok, expected, actual, delta (the floats' FFP bits)
106 * checkstr k, ok, expected_str, expected_length, expected_crc,
107 * actual_str, actual_length, actual_crc, cut
108 * require k (always broken)
109 * expect-error k
110 * broken reason
111 * run k
112 * runend k, ok (1: the return code is known), actual (it)
113 */
115 int kind; /* enum basictest_kind */
116 uint32_t version;
117 int block; /* enum basictest_block */
119 uint32_t k;
120 int ok; /* 1 ok, 0 fail */
121 uint32_t expected, actual; /* the bits of the longs */
122 uint32_t delta; /* checkflt: the FFP bits of the delta */
123 struct basictest_str expected_str, actual_str;
124 uint32_t expected_length, expected_crc; /* checkstr: of the whole */
125 uint32_t actual_length, actual_crc; /* strings, cut or not */
126 int cut; /* checkstr: 1 a value was shortened */
128};
129
130/**
131 * @brief Writes the line of an entry, with its LF, to buf.
132 * @return the number of bytes written, 0 if the line does not fit into
133 * size bytes or the entry is not one of the kinds above, or a case
134 * without a name (buf then holds no complete line).
135 */
136size_t basictest_write(const struct basictest_entry *e, uint8_t *buf, size_t size);
137
138/**
139 * @brief Writes v in decimal (no sign, no leading zero) to buf, which has
140 * room for 10 bytes; the writer's and the error text's helper.
141 * @return the number of digits.
142 */
143size_t basictest_decimal(uint32_t v, uint8_t *buf);
144
145/**
146 * @brief The CRC32 of a string value: the standard CRC-32 of IEEE 802.3
147 * (zlib, PNG; the polynomial $EDB88320 reflected, $FFFFFFFF at the
148 * start and XORed at the end); $CBF43926 for "123456789", 0 for none.
149 */
150uint32_t basictest_crc32(const uint8_t *data, size_t length);
151
152/** @brief Why the reader refused a line (BASICTEST_OK = 0). */
155 BASICTEST_E_KIND, /* unknown entry */
156 BASICTEST_E_FIELDS, /* wrong number of fields for the entry */
157 BASICTEST_E_VALUE, /* malformed value */
158 BASICTEST_E_VERSION /* unknown format version */
159};
160
161/**
162 * @brief The reader's error: line, reason, field (1 = the entry name) and
163 * the entry name as it stands in the line (valid while the line is).
164 */
166 uint32_t line;
167 int code; /* enum basictest_err */
168 unsigned field; /* the field at fault (E_VALUE, E_VERSION) */
169 const uint8_t *kind; /* the first field of the line */
171};
172
173/**
174 * @brief Reads one line of the result file (without its LF) into e.
175 *
176 * The string values are decoded in place: e's strings point into line,
177 * which the call changes. line_number is the number of the line in the
178 * file, for the error.
179 * @return BASICTEST_OK, or the reason; err (if not NULL) then names line,
180 * reason and field.
181 */
182int basictest_read(uint8_t *line, size_t length, uint32_t line_number,
183 struct basictest_entry *e, struct basictest_error *err);
184
185/**
186 * @brief Writes the text of a reader error ("line 3: check: malformed
187 * value in field 5"), 0-terminated, cut to fit size bytes (size > 0).
188 * The entry name is written as a string value.
189 * @return the length of the text without the 0.
190 */
191size_t basictest_error_text(const struct basictest_error *err, char *buf, size_t size);
192
193#ifdef __cplusplus
194}
195#endif
196
197#endif
UWORD size
Definition 2dlib.c:1170
basictest_kind
The entry kinds.
Definition basictest.h:69
@ BASICTEST_RUNEND
Definition basictest.h:83
@ BASICTEST_EXPECT_ERROR
Definition basictest.h:75
@ BASICTEST_END
Definition basictest.h:79
@ BASICTEST_BROKEN
Definition basictest.h:77
@ BASICTEST_BLOCKEND
Definition basictest.h:76
@ BASICTEST_CHECK
Definition basictest.h:72
@ BASICTEST_CHECKFLT
Definition basictest.h:81
@ BASICTEST_BLOCK
Definition basictest.h:71
@ BASICTEST_RUN
Definition basictest.h:82
@ BASICTEST_INCOMPLETE
Definition basictest.h:78
@ BASICTEST_CHECKQ
Definition basictest.h:80
@ BASICTEST_REQUIRE
Definition basictest.h:74
@ BASICTEST_BEGIN
Definition basictest.h:70
@ BASICTEST_CHECKSTR
Definition basictest.h:73
basictest_block
The blocks of a block entry.
Definition basictest.h:87
@ BASICTEST_BLOCK_CASE
Definition basictest.h:89
@ BASICTEST_BLOCK_INIT
Definition basictest.h:88
@ BASICTEST_BLOCK_FINAL
Definition basictest.h:90
int basictest_read(uint8_t *line, size_t length, uint32_t line_number, struct basictest_entry *e, struct basictest_error *err)
Reads one line of the result file (without its LF) into e.
Definition basictest_read.c:191
size_t basictest_decimal(uint32_t v, uint8_t *buf)
Writes v in decimal (no sign, no leading zero) to buf, which has room for 10 bytes; the writer's and ...
Definition basictest_write.c:31
size_t basictest_error_text(const struct basictest_error *err, char *buf, size_t size)
Writes the text of a reader error ("line 3: check: malformed value in field 5"), 0-terminated,...
Definition basictest_read.c:343
size_t basictest_write(const struct basictest_entry *e, uint8_t *buf, size_t size)
Writes the line of an entry, with its LF, to buf.
Definition basictest_write.c:92
basictest_err
Why the reader refused a line (BASICTEST_OK = 0).
Definition basictest.h:153
@ BASICTEST_OK
Definition basictest.h:154
@ BASICTEST_E_VALUE
Definition basictest.h:157
@ BASICTEST_E_KIND
Definition basictest.h:155
@ BASICTEST_E_FIELDS
Definition basictest.h:156
@ BASICTEST_E_VERSION
Definition basictest.h:158
uint32_t basictest_crc32(const uint8_t *data, size_t length)
The CRC32 of a string value: the standard CRC-32 of IEEE 802.3 (zlib, PNG; the polynomial $EDB88320 r...
Definition basictest_crc.c:22
static void line(WORD x1, WORD y1, WORD x2, WORD y2, ULONG c)
Definition blitzoslib.c:392
void data(void)
static ULONG length(const UBYTE *s)
Definition filereq_core.c:280
static UWORD buf
Definition rawkeylib.c:83
static struct @342026374002303043102303243063125232020331002053 v
One entry. Only the members of its kind count: begin version block block, name (BASICTEST_BLOCK_CASE)...
Definition basictest.h:114
int kind
Definition basictest.h:115
uint32_t delta
Definition basictest.h:122
uint32_t expected
Definition basictest.h:121
uint32_t k
Definition basictest.h:119
uint32_t version
Definition basictest.h:116
int ok
Definition basictest.h:120
uint32_t expected_crc
Definition basictest.h:124
int block
Definition basictest.h:117
struct basictest_str expected_str actual_str
Definition basictest.h:123
uint32_t actual_crc
Definition basictest.h:125
struct basictest_str reason
Definition basictest.h:127
uint32_t actual_length
Definition basictest.h:125
struct basictest_str name
Definition basictest.h:118
int cut
Definition basictest.h:126
uint32_t expected_length
Definition basictest.h:124
uint32_t actual
Definition basictest.h:121
The reader's error: line, reason, field (1 = the entry name) and the entry name as it stands in the l...
Definition basictest.h:165
uint32_t line
Definition basictest.h:166
const uint8_t * kind
Definition basictest.h:169
int code
Definition basictest.h:167
unsigned field
Definition basictest.h:168
size_t kind_length
Definition basictest.h:170
A string value: bytes, any value, not 0-terminated.
Definition basictest.h:94
const uint8_t * data
Definition basictest.h:95
size_t length
Definition basictest.h:96