Annotation of hatari/tests/debugger/test-evaluate.c, revision 1.1.1.4

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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.