|
|
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));
47: /* expressions use long access */
48: STRam[2+5] = 0;
49: STRam[2+6] = 0;
50: STRam[2+7] = 0;
51: STRam[2+8] = 3;
52:
53: fprintf(stderr, "\nExpressions that should FAIL:\n");
54:
55: for (i = 0; i < ARRAYSIZE(failure); i++) {
56: expression = failure[i];
57: fprintf(stderr, "- '%s'\n", expression);
58: errstr = Eval_Expression(expression, &result, &offset, false);
59: if (errstr) {
60: fprintf(stderr, "%*c-%s\n",
61: 3+offset, '^', errstr);
62: } else {
63: fprintf(stderr, " => %x\n ***Unexpected SUCCESS from expression***\n",
64: (Uint32)result);
65: errors++;
66: }
67: }
68: tests += i;
69:
70: fprintf(stderr, "\nExpressions that should SUCCEED with given result:\n");
71:
72: for (i = 0; i < ARRAYSIZE(success); i++) {
73: expression = success[i].expression;
74: fprintf(stderr, "- '%s'\n", expression);
75: errstr = Eval_Expression(expression, &result, &offset, false);
76: if (errstr) {
77: fprintf(stderr, "%*c-%s\n ***Unexpected ERROR in expression***\n",
78: 3+offset, '^', errstr);
79: errors++;
80: } else if (result != success[i].result) {
81: fprintf(stderr, " => %x (not %x)\n ***Wrong result from expression***\n",
82: (Uint32)result, (Uint32)success[i].result);
83: errors++;
84: } else {
85: fprintf(stderr, " => 0x%x\n", (Uint32)result);
86: }
87: }
88: tests += i;
89:
90: if (errors) {
91: fprintf(stderr, "\n***Detected %d ERRORs in %d automated tests!***\n\n",
92: errors, tests);
93: } else {
94: fprintf(stderr, "\nFinished without any errors!\n\n");
95: }
96: return errors;
97: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.