From 06ccc214315a98123b3ac4c91af1e1b09ab7fc07 Mon Sep 17 00:00:00 2001 From: j8takagi Date: Mon, 22 Mar 2010 03:46:54 +0900 Subject: [PATCH] =?utf8?q?=E3=83=A6=E3=83=8B=E3=83=83=E3=83=88=E3=83=86?= =?utf8?q?=E3=82=B9=E3=83=88=E3=81=AE=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- test/unit/Makefile | 2 +- test/unit/TEST.mk | 3 ++ test/unit/addcerrlist/0.txt | 36 +++++++++++++++++++ test/unit/cerrtest/0.txt | 4 +-- test/unit/getcmdcode/getcmdcode.c | 3 +- test/unit/getcmdtype/getcmdtype.c | 6 ++-- test/unit/getgr/getgr.c | 10 ++++-- test/unit/h2word/h2word.c | 10 ++++-- test/unit/hash/0.txt | 2 +- test/unit/hash/hash.c | 16 ++++----- test/unit/linetok/0.txt | 2 ++ test/unit/linetok/linetok.c | 10 +++--- test/unit/n2word/getint.c | 10 ++++-- test/unit/opdtok/0.txt | 4 +-- test/unit/opdtok/opdtok.c | 10 ++++-- test/unit/print_cerrmsg/Makefile | 2 +- test/unit/print_cerrmsg/print_cerrmsg.c | 16 ++++++--- .../print_cmdtype_code/print_cmdtype_code.c | 23 ++++++------ .../print_cmdtype_code.c | 6 ++-- test/unit/print_code_type/print_code_type.c | 16 ++++----- .../print_code_type_hash/print_code_type.c | 4 +-- 21 files changed, 131 insertions(+), 64 deletions(-) create mode 100644 test/unit/addcerrlist/0.txt diff --git a/test/unit/Makefile b/test/unit/Makefile index e1a3dff..f5b6616 100644 --- a/test/unit/Makefile +++ b/test/unit/Makefile @@ -14,7 +14,7 @@ all: check report check: @rm -f $(LOGFILE) @for target in $(TESTS); do \ - $(MAKE) check -C $$target; \ + $(MAKE) check -sC $$target; \ done $(LOGFILE): @for target in $(TESTS); do \ diff --git a/test/unit/TEST.mk b/test/unit/TEST.mk index 4e506fc..2a26dde 100644 --- a/test/unit/TEST.mk +++ b/test/unit/TEST.mk @@ -15,6 +15,9 @@ COMMONSRC = $(SRCDIR)/word.o $(SRCDIR)/struct.o $(SRCDIR)/hash.o $(SRCDIR)/cmd.o ASSRC = $(SRCDIR)/assemble.o $(SRCDIR)/token.o $(SRCDIR)/label.o $(SRCDIR)/macro.o EXECSRC = $(SRCDIR)/exec.o $(SRCDIR)/dump.o +ifeq "$(UCLASS)" "ALL" + SRC = $(COMMONSRC) $(ASSRC) $(EXECSRC) +endif ifeq "$(UCLASS)" "AS" SRC = $(COMMONSRC) $(ASSRC) endif diff --git a/test/unit/addcerrlist/0.txt b/test/unit/addcerrlist/0.txt new file mode 100644 index 0000000..96fdd38 --- /dev/null +++ b/test/unit/addcerrlist/0.txt @@ -0,0 +1,36 @@ +126: source file is not specified +101: label already defined +102: label table is full +103: label not found +104: label length is too long +105: no command in the line +106: operand mismatch in assemble command +107: no label in START +108: not command of operand "r" +109: not command of operand "r1,r2" +110: not command of operand "r,adr[,x]" +111: not command of operand "adr[,x]" +112: not command of no operand +113: operand too many in COMET II command +117: operand too many in DC +118: operand length too long +119: out of COMET II memory +120: GR0 in operand x +121: cannot get operand token +122: cannot create hash table +123: unclosed quote +124: more than one character in literal +125: not GR in operand x +114: not integer +115: not hex +116: out of hex range +114: not integer +115: not hex +116: out of hex range +201: Load object file - full of COMET II memory +202: SVC input - out of Input memory +203: SVC output - out of COMET II memory +204: Program Register (PR) - out of COMET II memory +205: Stack Pointer (SP) - cannot allocate stack buffer +206: Address - out of COMET II memory +207: Stack Pointer (SP) - out of COMET II memory diff --git a/test/unit/cerrtest/0.txt b/test/unit/cerrtest/0.txt index fcbc023..40776ec 100644 --- a/test/unit/cerrtest/0.txt +++ b/test/unit/cerrtest/0.txt @@ -29,7 +29,7 @@ 205: (null) - 205 Stack Pointer (SP) - cannot allocate stack buffer 206: (null) - 206 Address - out of COMET II memory 207: (null) - 207 Stack Pointer (SP) - out of COMET II memory -999: (null) - 999 unkown error +999: (null) - 999 unknown error 101: foobar - 101 foobar: label already defined 102: foobar - 102 foobar: label table is full 103: foobar - 103 foobar: label not found @@ -61,4 +61,4 @@ 205: foobar - 205 foobar: Stack Pointer (SP) - cannot allocate stack buffer 206: foobar - 206 foobar: Address - out of COMET II memory 207: foobar - 207 foobar: Stack Pointer (SP) - out of COMET II memory -999: foobar - 999 foobar: unkown error +999: foobar - 999 foobar: unknown error diff --git a/test/unit/getcmdcode/getcmdcode.c b/test/unit/getcmdcode/getcmdcode.c index 2c5286d..b8eed2b 100644 --- a/test/unit/getcmdcode/getcmdcode.c +++ b/test/unit/getcmdcode/getcmdcode.c @@ -23,8 +23,7 @@ int main(){ { "SVC", ADR_X }, { "RET", NONE } }; create_cmdtype_code(); - /* エラーの初期化 */ - cerr = malloc_chk(sizeof(CERR), "cerr"); + cerr = malloc_chk(sizeof(CERR), "cerr"); /* エラーの初期化 */ for(i = 0; i < sizeof(cmdcodelist)/sizeof(cmdcodelist[0]); i++) { code = getcmdcode(cmdcodelist[i].cmd, cmdcodelist[i].type); printf("%s:0%02o ---> #%04X\n", cmdcodelist[i].cmd, cmdcodelist[i].type, code); diff --git a/test/unit/getcmdtype/getcmdtype.c b/test/unit/getcmdtype/getcmdtype.c index f020b4e..2c3337c 100644 --- a/test/unit/getcmdtype/getcmdtype.c +++ b/test/unit/getcmdtype/getcmdtype.c @@ -14,12 +14,14 @@ int main(){ 0x6400, 0x6500, 0x6600, 0x7000, 0x7100, 0x8000, 0xF000, 0x8100 }; + + cerr = malloc_chk(sizeof(CERR), "cerr"); /* エラーの初期化 */ create_code_type(); for(i = 0; i < ARRAYSIZE(codelist); i++) { type = getcmdtype(codelist[i]); printf("#%04X ---> 0%02o\n", codelist[i], type); - if(cerrno != 0) { - printf("\t%s", cerrmsg); + if(cerr->num != 0) { + printf("\t%s", cerr->msg); freecerr(); } } diff --git a/test/unit/getgr/getgr.c b/test/unit/getgr/getgr.c index e342501..c7fc5e3 100644 --- a/test/unit/getgr/getgr.c +++ b/test/unit/getgr/getgr.c @@ -12,18 +12,22 @@ int main(){ "", "0", "aaa", "GR", "GR8", "GR20", "GR0", "GR1", "GR2", "GR3", "GR4", "GR5", "GR6", "GR7" }; + + cerr = malloc_chk(sizeof(CERR), "cerr"); /* エラーの初期化 */ + addcerrlist_assemble(); for(i = 0; i <= 1; i++) { title = (is_x[i] == false) ? "Generel Register" : "Index Register"; printf("== %s ==\n", title); for(j = 0; j < ARRAYSIZE(str); j++) { + cerr->num = 0; r = getgr(str[j], is_x[i]); printf("%s\t#%04X", str[j], r); - if(cerrno > 0) { - printf("\tError - %d\t%s", cerrno, cerrmsg); - freecerr(); + if(cerr->num > 0) { + printf("\tError - %d\t%s", cerr->num, cerr->msg); } printf("\n"); } } + freecerr(); return 0; } diff --git a/test/unit/h2word/h2word.c b/test/unit/h2word/h2word.c index a4c34f8..3514241 100644 --- a/test/unit/h2word/h2word.c +++ b/test/unit/h2word/h2word.c @@ -9,14 +9,18 @@ int main(){ char *str[] = { "#32768", "#-1", "#G", "#FFFF", "#0", "#1", "#ab", "#AB", "#20" }; + + cerr = malloc_chk(sizeof(CERR), "cerr"); /* エラーの初期化 */ + addcerrlist_word(); for(i = 0; i < sizeof(str)/sizeof(str[0]); i++) { + cerr->num = 0; r = h2word(str[i]); printf("%s\t#%04X", str[i], r); - if(cerrno > 0) { - printf("\tError - %d\t%s", cerrno, cerrmsg); - freecerr(); + if(cerr->num > 0) { + printf("\tError - %d\t%s", cerr->num, cerr->msg); } printf("\n"); } + freecerr(); return 0; } diff --git a/test/unit/hash/0.txt b/test/unit/hash/0.txt index bc8892a..352fe24 100644 --- a/test/unit/hash/0.txt +++ b/test/unit/hash/0.txt @@ -1,3 +1,3 @@ HASH VALUE: 20 HASH VALUE: 11 -HASH VALUE: 2 +HASH VALUE: 16 diff --git a/test/unit/hash/hash.c b/test/unit/hash/hash.c index 57e1cae..2acdc81 100644 --- a/test/unit/hash/hash.c +++ b/test/unit/hash/hash.c @@ -37,19 +37,19 @@ unsigned hash_int2(int tsize) unsigned hash_char2_int2(int tsize) { char *str[2] = {"abc", "123"}; - int num[2] = {19, 11}, i; + int num[2] = {19, 11}, i, cnt = 0; HKEY *keys[4]; /* ハッシュ共用体の設定 */ for(i = 0; i < 2; i++) { - keys[i] = malloc(sizeof(HKEY)); - keys[i]->type = CHARS; - keys[i]->val.s = strdup(str[i]); + keys[cnt] = malloc(sizeof(HKEY)); + keys[cnt]->type = CHARS; + keys[cnt++]->val.s = strdup(str[i]); } - for(i = 2; i < 4; i++) { - keys[i] = malloc(sizeof(HKEY)); - keys[i]->type = INT; - keys[i]->val.i = num[i]; + for(i = 0; i < 2; i++) { + keys[cnt] = malloc(sizeof(HKEY)); + keys[cnt]->type = INT; + keys[cnt++]->val.i = num[i]; } /* ハッシュ値を取得する */ return hash(4, keys, tsize); diff --git a/test/unit/linetok/0.txt b/test/unit/linetok/0.txt index b83e906..40c7fb3 100644 --- a/test/unit/linetok/0.txt +++ b/test/unit/linetok/0.txt @@ -48,7 +48,9 @@ cl->opdv[0]: GR1 8: cl is NULL + error - 121: cannot get operand token 9: ;comment cl is NULL + error - 121: cannot get operand token diff --git a/test/unit/linetok/linetok.c b/test/unit/linetok/linetok.c index a4ea173..28555cd 100644 --- a/test/unit/linetok/linetok.c +++ b/test/unit/linetok/linetok.c @@ -17,8 +17,10 @@ int main(){ "\n", " ;comment\n" }; + CMDLINE *testcl = malloc(sizeof(CMDLINE)); - + cerr = malloc_chk(sizeof(CERR), "cerr"); /* エラーの初期化 */ + addcerrlist_assemble(); for(i = 0; i < sizeof testline /sizeof testline[0]; i++) { printf("%d: %s", i, testline[i]); testcl = linetok(testline[i]); @@ -36,11 +38,11 @@ int main(){ } } } - if(cerrno != 0) { - printf("\terror - %d: %s\n", cerrno, cerrmsg); - freecerr(); + if(cerr->num != 0) { + printf("\terror - %d: %s\n", cerr->num, cerr->msg); } printf("\n"); } + freecerr(); return 0; } diff --git a/test/unit/n2word/getint.c b/test/unit/n2word/getint.c index 945db38..8d1d04e 100644 --- a/test/unit/n2word/getint.c +++ b/test/unit/n2word/getint.c @@ -9,14 +9,18 @@ int main(){ "0", "01", "1a", "-5G", "123", "32767", "32768", "32769", "-1", "-2345", "-32768", "-32769", "-32770" }; + + cerr = malloc_chk(sizeof(CERR), "cerr"); /* エラーの初期化 */ + addcerrlist_word(); for(i = 0; i < sizeof(str)/sizeof(str[0]); i++) { + cerr->num = 0; r = n2word(str[i]); printf("%s\t0x%04x", str[i], r); - if(cerrno > 0) { - printf("\tError - %d\t%s", cerrno, cerrmsg); - freecerr(); + if(cerr->num > 0) { + printf("\tError - %d\t%s", cerr->num, cerr->msg); } printf("\n"); } + freecerr(); return 0; } diff --git a/test/unit/opdtok/0.txt b/test/unit/opdtok/0.txt index 6930eb2..acdfb42 100644 --- a/test/unit/opdtok/0.txt +++ b/test/unit/opdtok/0.txt @@ -126,7 +126,7 @@ OPDC[36]:7 OPDC[37]:8 OPDC[38]:9 OPDC[39]:0 -Error - 117: operand is too many +Error - 117: operand too many in DC '1234567890123456789012345678901234567890' OPDC:1 @@ -134,5 +134,5 @@ OPDC[0]:'1234567890123456789012345678901234567890' '12345678901234567890123456789012345678901' OPDC:0 -Error - 118: operand length is too long +Error - 118: operand length too long diff --git a/test/unit/opdtok/opdtok.c b/test/unit/opdtok/opdtok.c index d65a420..bad4603 100644 --- a/test/unit/opdtok/opdtok.c +++ b/test/unit/opdtok/opdtok.c @@ -12,18 +12,22 @@ int main(){ "\'1234567890123456789012345678901234567890\'", "\'12345678901234567890123456789012345678901\'", }; + + cerr = malloc_chk(sizeof(CERR), "cerr"); /* エラーの初期化 */ + addcerrlist_assemble(); for(i = 0; i < ARRAYSIZE(str); i++) { + cerr->num = 0; printf("%s\n", str[i]); opd = opdtok(str[i]); printf("OPDC:%d\n", opd->opdc); for(j = 0; j < opd->opdc; j++) { printf("OPDC[%d]:%s\n", j, opd->opdv[j]); } - if(cerrno > 0){ - printf("Error - %d: %s\n", cerrno, cerrmsg); - freecerr(); + if(cerr->num > 0){ + printf("Error - %d: %s\n", cerr->num, cerr->msg); } printf("\n"); } + freecerr(); return 0; } diff --git a/test/unit/print_cerrmsg/Makefile b/test/unit/print_cerrmsg/Makefile index fd5d996..e253b41 100644 --- a/test/unit/print_cerrmsg/Makefile +++ b/test/unit/print_cerrmsg/Makefile @@ -1,3 +1,3 @@ -UCLASS = COMMON +UCLASS = ALL TESTSRCFILE = ../CERRARRAY.c print_cerrmsg.c include ../TEST.mk diff --git a/test/unit/print_cerrmsg/print_cerrmsg.c b/test/unit/print_cerrmsg/print_cerrmsg.c index 09c274e..34de8f8 100644 --- a/test/unit/print_cerrmsg/print_cerrmsg.c +++ b/test/unit/print_cerrmsg/print_cerrmsg.c @@ -1,13 +1,19 @@ #include #include "casl2.h" +#include "assemble.h" +#include "exec.h" int main(){ - int i, num; + CERRLIST *p; - for(i = 0; (num = cerr[i].num) > 0; i++) { - setcerr(num, NULL); - printf("%d: %s\n", cerrno, cerrmsg); - freecerr(); + addcerrlist_word(); + addcerrlist_assemble(); + addcerrlist_exec(); + cerr = malloc_chk(sizeof(CERR), "cerr"); /* エラーの初期化 */ + for(p = cerrlist; p != NULL; p = p->next) { + setcerr(p->cerr->num, NULL); + printf("%d: %s\n", cerr->num, cerr->msg); } + freecerr(); return 0; } diff --git a/test/unit/print_cmdtype_code/print_cmdtype_code.c b/test/unit/print_cmdtype_code/print_cmdtype_code.c index 04d311e..70bcd78 100644 --- a/test/unit/print_cmdtype_code/print_cmdtype_code.c +++ b/test/unit/print_cmdtype_code/print_cmdtype_code.c @@ -4,10 +4,11 @@ int compare_code(const void *a, const void *b) { - const CMDTYPECODE ca = **(const CMDTYPECODE **)a; - const CMDTYPECODE cb = **(const CMDTYPECODE **)b; + const CMD ca = **(const CMD **)a; + const CMD cb = **(const CMD **)b; int diff; - if((diff = strcmp(ca.cmd, cb.cmd)) == 0) { + + if((diff = strcmp(ca.name, cb.name)) == 0) { return ca.type - cb.type; } else { return diff; @@ -18,19 +19,19 @@ int compare_code(const void *a, const void *b) void print_cmdtype_code() { int i, j = 0; - CMDCODETAB *np; - CMDTYPECODE **ar; - ar = malloc(sizeof(*ar) * cmdtypecodesize); - for(i = 0; i < cmdtabsize; i++) { + CMDTAB *np; + CMD **ar; + ar = malloc(sizeof(*ar) * comet2cmdsize); + for(i = 0; i < comet2cmdsize; i++) { np = cmdtype_code[i]; while(np != NULL) { - ar[j++] = np->cmdtypecode; + ar[j++] = np->cmd; np = np->next; } } - qsort(ar, cmdcodesize, sizeof(*ar), (int (*)(const void*, const void*))compare_code); - for(i = 0; i < cmdcodesize; i++) { - fprintf(stdout, "%s\t0%02o\t#%04X\n", ar[i]->cmd, ar[i]->type, ar[i]->code); + qsort(ar, comet2cmdsize, sizeof(*ar), (int (*)(const void*, const void*))compare_code); + for(i = 0; i < comet2cmdsize; i++) { + fprintf(stdout, "%s\t0%02o\t#%04X\n", ar[i]->name, ar[i]->type, ar[i]->code); } } diff --git a/test/unit/print_cmdtype_code_hash/print_cmdtype_code.c b/test/unit/print_cmdtype_code_hash/print_cmdtype_code.c index d075ae4..ba26a74 100644 --- a/test/unit/print_cmdtype_code_hash/print_cmdtype_code.c +++ b/test/unit/print_cmdtype_code_hash/print_cmdtype_code.c @@ -4,12 +4,12 @@ void print_cmdtype_code() { int i; - CMDCODETAB *np; - for(i = 0; i < cmdtabsize; i++){ + CMDTAB *np; + for(i = 0; i < comet2cmdsize; i++){ np = cmdtype_code[i]; while(np != NULL) { fprintf(stdout, "(%2d) - %s\t0%02o\t#%04X\n", - i, np->cmdtypecode->cmd, np->cmdtypecode->type, np->cmdtypecode->code); + i, np->cmd->name, np->cmd->type, np->cmd->code); np = np->next; } } diff --git a/test/unit/print_code_type/print_code_type.c b/test/unit/print_code_type/print_code_type.c index a7ba676..0a5a312 100644 --- a/test/unit/print_code_type/print_code_type.c +++ b/test/unit/print_code_type/print_code_type.c @@ -3,26 +3,26 @@ int compare_code(const void *a, const void *b) { - return (**(const CMDTYPECODE **)a).code - (**(const CMDTYPECODE **)b).code; + return (**(const CMD **)a).code - (**(const CMD **)b).code; } /* 命令コードがキーのハッシュ表を表示する */ void print_code_type() { int i, j = 0; - CMDCODETAB *np; - CMDTYPECODE **ar; - ar = malloc(sizeof(*ar) * cmdtypecodesize); + CMDTAB *np; + CMD **ar; + ar = malloc(sizeof(*ar) * comet2cmdsize); for(i = 0; i < cmdtabsize; i++) { np = code_type[i]; while(np != NULL) { - ar[j++] = np->cmdtypecode; + ar[j++] = np->cmd; np = np->next; } } - qsort(ar, cmdtypecodesize, sizeof(*ar), (int (*)(const void*, const void*))compare_code); - for(i = 0; i < cmdtypecodesize; i++) { - fprintf(stdout, "#%04X\t0%02o\t%s\n", ar[i]->code, ar[i]->type, ar[i]->cmd); + qsort(ar, comet2cmdsize, sizeof(*ar), (int (*)(const void*, const void*))compare_code); + for(i = 0; i < comet2cmdsize; i++) { + fprintf(stdout, "#%04X\t0%02o\t%s\n", ar[i]->code, ar[i]->type, ar[i]->name); } } diff --git a/test/unit/print_code_type_hash/print_code_type.c b/test/unit/print_code_type_hash/print_code_type.c index a8860c4..80fea83 100644 --- a/test/unit/print_code_type_hash/print_code_type.c +++ b/test/unit/print_code_type_hash/print_code_type.c @@ -5,11 +5,11 @@ void print_code_type() { int i; - CMDCODETAB *np; + CMDTAB *np; for(i = 0; i < cmdtabsize; i++){ for(np = code_type[i]; np != NULL; np = np->next) { fprintf(stdout, "(%2d) - #%04X\t0%02o\t%s\n", - i, np->cmdtypecode->code, np->cmdtypecode->type, np->cmdtypecode->cmd); + i, np->cmd->code, np->cmd->type, np->cmd->name); } } } -- 2.18.0