OXYGENHUB
# 9120e87480a6 enhanced-x16-emulator / tests / support / harness.c
1.6 KiB · C · last changed chore(): initial commit 26 days ago source blame history raw
1
#include "harness.h"
2
3
#include <stdio.h>
4
5
int x16_failures = 0;
6
int x16_checks   = 0;
7
int x16_divergences = 0;
8
9
void
10
check(bool cond, const char *what)
11
{
12
	x16_checks++;
13
	if (cond) {
14
		printf("ok  : %s\n", what);
15
	} else {
16
		x16_failures++;
17
		printf("FAIL: %s\n", what);
18
	}
19
}
20
21
void
22
check_eq(uint32_t got, uint32_t want, const char *what)
23
{
24
	x16_checks++;
25
	if (got == want) {
26
		printf("ok  : %s\n", what);
27
	} else {
28
		x16_failures++;
29
		printf("FAIL: %s (got 0x%X, want 0x%X)\n", what, got, want);
30
	}
31
}
32
33
void
34
check_divergent(bool passed, const char *what, const char *why)
35
{
36
	x16_checks++;
37
	if (passed) {
38
		// Better than expected, and still wrong: the marker says this differs
39
		// from the hardware, and it no longer does.
40
		x16_failures++;
41
		printf("FIXED: %s -- this passes now; drop the divergence marker\n", what);
42
	} else {
43
		x16_divergences++;
44
		printf("DIVERGE: %s\n         %s\n", what, why);
45
	}
46
}
47
48
int
49
x16_test_summary(const char *suite)
50
{
51
	printf("\n%s: %d checks, %d failed", suite, x16_checks, x16_failures);
52
	if (x16_divergences > 0) {
53
		printf(", %d known divergence%s",
54
		       x16_divergences, x16_divergences == 1 ? "" : "s");
55
	}
56
	printf("\n");
57
58
	// Said plainly, because a divergence does not fail the run and would
59
	// otherwise be invisible to anyone reading a green result.
60
	if (x16_divergences > 0) {
61
		printf("WARNING: %s differs from real hardware in %d known place%s. "
62
		       "See the DIVERGE line%s above.\n",
63
		       suite, x16_divergences,
64
		       x16_divergences == 1 ? "" : "s",
65
		       x16_divergences == 1 ? "" : "s");
66
	}
67
68
	return x16_failures ? 1 : 0;
69
}