|
|
1.1 root 1: /*
2: * Code to test Hatari expression evaluation in src/debug/evaluate.c
1.1.1.2 root 3: * (including Hatari variable and CPU register values in expressions)
1.1 root 4: */
5: #include <stdio.h>
6: #include <SDL_types.h>
7: #include <stdbool.h>
8: #include "stMemory.h"
9: #include "evaluate.h"
10: #include "m68000.h"
11: #include "main.h"
12: #include "screen.h"
13: #include "video.h"
14:
15: #define VBL_VALUE 21
16:
17: int main(int argc, const char *argv[])
18: {
19: /* expected to fail */
20: const char *failure[] = {
21: "1+2*",
22: "*1+2",
23: "1+(2",
24: "1)+2",
25: "foo+1+bar",
26: };
27: /* expected to succeed, with given result */
28: struct {
29: const char *expression;
30: Uint32 result;
31: } success[] = {
32: { "1+2*3", 7 },
33: { "(2+5)*3", 9 },
34: { "d0 + 2", 12 },
35: { "VBL+10", VBL_VALUE + 10 },
36: { "~%101 & $f0f0f ^ 0x21 * 0x200", 0xF4D0A },
37: };
38: int i, offset, tests = 0, errors = 0;
39: const char *expression, *errstr;
40: Uint32 result;
41:
42: /* set values needed by above succesful calculations */
43: nVBLs = VBL_VALUE;
44: memset(Regs, 0, sizeof(Regs));
45: Regs[REG_D0] = 10;
46: memset(STRam, 0, sizeof(STRam));
1.1.1.3 ! root 47: /* expressions use long access, 3*3 -> 9 */
! 48: STMemory_WriteLong(2+5, 3);
1.1 root 49:
50: fprintf(stderr, "\nExpressions that should FAIL:\n");
51:
52: for (i = 0; i < ARRAYSIZE(failure); i++) {
53: expression = failure[i];
54: fprintf(stderr, "- '%s'\n", expression);
55: errstr = Eval_Expression(expression, &result, &offset, false);
56: if (errstr) {
57: fprintf(stderr, "%*c-%s\n",
58: 3+offset, '^', errstr);
59: } else {
60: fprintf(stderr, " => %x\n ***Unexpected SUCCESS from expression***\n",
61: (Uint32)result);
62: errors++;
63: }
64: }
65: tests += i;
66:
67: fprintf(stderr, "\nExpressions that should SUCCEED with given result:\n");
68:
69: for (i = 0; i < ARRAYSIZE(success); i++) {
70: expression = success[i].expression;
71: fprintf(stderr, "- '%s'\n", expression);
72: errstr = Eval_Expression(expression, &result, &offset, false);
73: if (errstr) {
74: fprintf(stderr, "%*c-%s\n ***Unexpected ERROR in expression***\n",
75: 3+offset, '^', errstr);
76: errors++;
77: } else if (result != success[i].result) {
78: fprintf(stderr, " => %x (not %x)\n ***Wrong result from expression***\n",
79: (Uint32)result, (Uint32)success[i].result);
80: errors++;
81: } else {
82: fprintf(stderr, " => 0x%x\n", (Uint32)result);
83: }
84: }
85: tests += i;
86:
87: if (errors) {
88: fprintf(stderr, "\n***Detected %d ERRORs in %d automated tests!***\n\n",
89: errors, tests);
90: } else {
91: fprintf(stderr, "\nFinished without any errors!\n\n");
92: }
93: return errors;
94: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.