forked from llvm-mos/llvm-mos-sdk
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest-lib-emutest.c
45 lines (39 loc) · 1.49 KB
/
test-lib-emutest.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <peekpoke.h>
#include <string.h>
#include "test-lib-emutest.h"
// The emutest runner expects to find one of two
// signatures in main RAM.
// These are encoded to avoid false positives: encoded_char = plain_char + 1
// the section attribute is because clang still wants to put it into the data section (TODO?)
__attribute__((section(".rodata"))) static const char signature_pass[SIGNATURE_SIZE] = "UftuQbtt"; // "TestPass";
__attribute__((section(".rodata"))) static const char signature_fail[SIGNATURE_SIZE] = "UftuGbjm"; // "TestFail";
#ifdef __NES__
// NES tests currently can't spare a byte
// so we'll just write wherever
#define test_result ((char*)0x180)
#else
// this array will contain the test signature
// (use macro because clang requires extension for constant array size?)
char test_result[SIGNATURE_SIZE];
#endif
// set pass/fail manually, if you can't use exit()
void test_set_result(bool passed) {
const char* const sig = passed ? signature_pass : signature_fail;
for (int i=0; i<SIGNATURE_SIZE; i++) {
test_result[i] = sig[i] - 1;
}
}
bool test_has_result(bool passed) {
const char* const sig = passed ? signature_pass : signature_fail;
for (int i=0; i<SIGNATURE_SIZE; i++) {
if (test_result[i] != sig[i] - 1)
return false;
}
return true;
}
_Noreturn void _Exit(int status) {
// For emutest, we put a pass/fail signature into the main RAM area.
test_set_result(status == 0);
// emutest needs us to hang here, so it can read the signature.
while (1) ;
}