From: j8takagi Date: Tue, 28 Dec 2010 03:53:47 +0000 (+0900) Subject: ユニットテストをソースに合わせて修正 X-Git-Tag: v0.1p15~7 X-Git-Url: http://j8takagi.net/cgi-bin/gitweb.cgi?p=YACASL2.git;a=commitdiff_plain;h=373540e9b114c01712121c36b40f47a98e12d263 ユニットテストをソースに合わせて修正 --- diff --git a/test/unit/.gitignore b/test/unit/.gitignore index 0f6d05f..4d71d67 100644 --- a/test/unit/.gitignore +++ b/test/unit/.gitignore @@ -1,3 +1,4 @@ */1.txt */err.txt -*/*.log \ No newline at end of file +*/*.log +*/cmd.dSYM diff --git a/test/unit/Define.mk b/test/unit/Define.mk index 641f823..92e3b8e 100644 --- a/test/unit/Define.mk +++ b/test/unit/Define.mk @@ -27,7 +27,7 @@ RM ?= rm -f ECHO ?= echo -TIME ?= /usr/bin/time --quiet +TIME ?= time DIFF ?= diff -c diff --git a/test/unit/Define_group.mk b/test/unit/Define_group.mk index f3cda2c..a572469 100644 --- a/test/unit/Define_group.mk +++ b/test/unit/Define_group.mk @@ -56,6 +56,7 @@ endef # テストのログファイルをグループログファイルに出力。引数は、テスト、グループログファイル # 用例: $(call group_log_each,file_test_log,file_group_log) define group_log_each + $(ECHO) $(dir $1) >>$2; if test -s $1; then $(CAT) $1 >>$2; else $(ECHO) $(dir $1)": no log" >>$2; fi $(ECHO) >>$2; diff --git a/test/unit/Define_test.mk b/test/unit/Define_test.mk index 65bfcaf..c3508ca 100644 --- a/test/unit/Define_test.mk +++ b/test/unit/Define_test.mk @@ -16,10 +16,10 @@ endef # テスト実行の経過時間を、ファイルに出力して表示 # 引数は、テスト名、コマンドファイル、出力ファイル -# 用例: $(call time_cmd,name,file_cmd,file_out) +# 用例: $(call time_cmd,file_cmd,file_out) define time_cmd - if test ! -x $2; then $(CHMOD) u+x $2; fi - $(TIME) -f"$1: %E" -o $3 ./$2 >$(DEV_NULL) 2>&1 + if test ! -x $1; then $(CHMOD) u+x $1; fi + ($(TIME) ./$1 1>$(DEV_NULL) 2>$(DEV_NULL)) 2>&1 | $(GREP) '^real' >$2 endef # テスト実行コマンド。引数は、コマンドファイル、出力ファイル、エラーファイル @@ -27,7 +27,7 @@ endef # エラー発生時は、エラー出力を出力ファイルとエラーファイルに保存。 # 用例: $(call exec_cmd,file_cmd,file_out,file_err) define exec_cmd - @if test ! -x $1; then $(CHMOD) u+x $1; fi + if test ! -x $1; then $(CHMOD) u+x $1; fi ./$1 >>$2 2>$3 if test -s $3; then $(CAT) $3 >>$2; fi $(call rm_null,$3) @@ -61,7 +61,6 @@ endef # 引数は、対象ファイル群、出力ファイル # 用例: $(call report_files,list_file_target,file_out) define report_files - $(call chk_file_ext,$2) $(foreach tfile,$1,$(call report_file,$(tfile),$2)) endef diff --git a/test/unit/Makefile b/test/unit/Makefile index e22d03c..6be7c11 100644 --- a/test/unit/Makefile +++ b/test/unit/Makefile @@ -2,14 +2,13 @@ # テストグループのMakefile # # オペレーター -# make : すべてのテストを実施し、ログファイルを作成 -# make check : ↓ -# make create : TESTNAMEで指定されたテストを新規に作成 -# make set : すべてのテストの、想定結果を出力 -# make checkeach: すべてのテストを実施 -# make report : ログファイルから、テストの結果をレポート -# make clean : すべてのテストで、"make" で生成されたファイルをクリア -# make cleanall: すべてのテストで、"make" と "make set" で生成されたファイルをクリア +# make : すべてのテストを実行し、結果をログファイルに出力 +# make check : ↓ +# make checkall : すべてのテストを実行し、結果と実行時間をログファイルに出力 +# make time : すべてのテストを実行し、実行時間をログファイルに出力 +# make create : TESTNAMEで指定されたテストを新規に作成 +# make clean : すべてのテストで、"make" で生成されたファイルをクリア +# make cleantime: すべてのテストで、実行時間のログファイルをクリア SHELL = /bin/sh diff --git a/test/unit/Test.mk b/test/unit/Test.mk index 8e2628d..ada87ae 100644 --- a/test/unit/Test.mk +++ b/test/unit/Test.mk @@ -13,30 +13,29 @@ # make clean : "make" で作成されたファイルをクリア # make cleanall: "make" と "make set" で作成されたファイルをクリア -SHELL = /bin/sh +SHELL = /bin/bash # テスト名。カレントディレクトリー名から取得 TEST = $(notdir $(CURRDIR)) # コマンドファイルのソース -#CMDSRC_FILE := $(CMD_FILE) -CMDSRC_FILE := $(CMD_FILE).c +CMDSRC_FILE = $(CMD_FILE).c .PHONY: check set reset time cleantime clean cleanall check: clean $(DETAIL_FILE) @$(call disp_test_log,$(LOG_FILE)) -checkall: check $(TIME_FILE) +checkall: clean $(DETAIL_FILE) $(TIME_FILE) @$(CAT) $(TIME_FILE) >>$(LOG_FILE) @$(call disp_test_log,$(LOG_FILE)) -set: $(TEST0_FILE) - @$(CAT) $^ - -reset: cleanall $(TEST0_FILE) +set: $(CMD_FILE) + @-$(call exec_cmd,$(CMD_FILE),$(TEST0_FILE),$(ERR_FILE)) @$(CAT) $(TEST0_FILE) +reset: cleanall set + time: cleantime $(TIME_FILE) cleantime: @@ -48,7 +47,7 @@ clean: cleanall: clean @$(RM) $(TEST0_FILE) -$(TEST0_FILE) $(TEST1_FILE): $(CMD_FILE) +$(TEST1_FILE): $(CMD_FILE) @-$(call exec_cmd,$^,$@,$(ERR_FILE)) $(DIFF_FILE): $(TEST0_FILE) $(TEST1_FILE) @@ -61,5 +60,4 @@ $(DETAIL_FILE): $(LOG_FILE) @$(call report_files,$(LOG_FILE) $(CMDSRC_FILE) $(TEST0_FILE) $(ERR_FILE) $(DIFF_FILE) $(TEST1_FILE),$@) $(TIME_FILE): $(CMD_FILE) - @if test ! -x $^; then $(CHMOD) u+x $^; fi - @-$(call time_cmd,$(TEST),$^,$@) + $(call time_cmd,$^,$@) diff --git a/test/unit/addcerrlist/Makefile b/test/unit/addcerrlist/Makefile index 526ac3a..654317f 100644 --- a/test/unit/addcerrlist/Makefile +++ b/test/unit/addcerrlist/Makefile @@ -9,3 +9,5 @@ SRCFILES = $(SRCDIR)/cmem.c $(SRCDIR)/cerr.c cmd.c cmd: cmd.c $(SRCFILES) gcc -g -Wall -I ../../../include -o $@ $^ + rm -rf cmd.dSYM + diff --git a/test/unit/getcmdcode/Makefile b/test/unit/getcmdcode/Makefile index 155e27e..a8df80c 100644 --- a/test/unit/getcmdcode/Makefile +++ b/test/unit/getcmdcode/Makefile @@ -5,7 +5,7 @@ include ../Test.mk .INTERMEDIATE: cmd SRCDIR = ../../../src -SRCFILES = $(SRCDIR)/word.c $(SRCDIR)/struct.c $(SRCDIR)/hash.c $(SRCDIR)/cmd.c $(SRCDIR)/cmem.c $(SRCDIR)/cerr.c +SRCFILES = $(SRCDIR)/hash.c $(SRCDIR)/cmd.c $(SRCDIR)/cmem.c $(SRCDIR)/cerr.c cmd: cmd.c $(SRCFILES) gcc -g -Wall -I ../../../include -o $@ $^ diff --git a/test/unit/getcmdcode/cmd.c b/test/unit/getcmdcode/cmd.c index b8eed2b..55bf9a9 100644 --- a/test/unit/getcmdcode/cmd.c +++ b/test/unit/getcmdcode/cmd.c @@ -1,4 +1,6 @@ -#include "casl2.h" +#include +#include "struct.h" +#include "cerr.h" int main(){ int i; @@ -23,7 +25,7 @@ int main(){ { "SVC", ADR_X }, { "RET", NONE } }; create_cmdtype_code(); - cerr = malloc_chk(sizeof(CERR), "cerr"); /* エラーの初期化 */ + cerr_init(); 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/cmd.c b/test/unit/getcmdtype/cmd.c index e4379a9..a4f2856 100644 --- a/test/unit/getcmdtype/cmd.c +++ b/test/unit/getcmdtype/cmd.c @@ -1,4 +1,6 @@ -#include "casl2.h" +#include +#include "struct.h" +#include "cerr.h" int main(){ int i; diff --git a/test/unit/getgr/0.txt b/test/unit/getgr/0.txt deleted file mode 100644 index 8b7ead1..0000000 --- a/test/unit/getgr/0.txt +++ /dev/null @@ -1,30 +0,0 @@ -== Generel Register == - #FFFF -0 #FFFF -aaa #FFFF -GR #FFFF -GR8 #FFFF -GR20 #FFFF -GR0 #0000 -GR1 #0001 -GR2 #0002 -GR3 #0003 -GR4 #0004 -GR5 #0005 -GR6 #0006 -GR7 #0007 -== Index Register == - #FFFF -0 #FFFF -aaa #FFFF -GR #FFFF -GR8 #FFFF -GR20 #FFFF -GR0 #0000 Error - 120 GR0 in operand x -GR1 #0001 -GR2 #0002 -GR3 #0003 -GR4 #0004 -GR5 #0005 -GR6 #0006 -GR7 #0007 diff --git a/test/unit/getgr/Makefile b/test/unit/getgr/Makefile deleted file mode 100644 index 52c2f81..0000000 --- a/test/unit/getgr/Makefile +++ /dev/null @@ -1,11 +0,0 @@ -include ../Define.mk -include ../Define_test.mk -include ../Test.mk - -.INTERMEDIATE: cmd - -SRCDIR = ../../../src -SRCFILES = $(SRCDIR)/hash.c $(SRCDIR)/cmem.c $(SRCDIR)/cerr.c $(SRCDIR)/cmd.c $(SRCDIR)/assemble.c $(SRCDIR)/word.c $(SRCDIR)/label.c $(SRCDIR)/struct.c $(SRCDIR)/macro.c $(SRCDIR)/token.c - -cmd: cmd.c $(SRCFILES) - gcc -g -Wall -I ../../../include -o $@ $^ diff --git a/test/unit/getgr/cmd.c b/test/unit/getgr/cmd.c deleted file mode 100644 index c7fc5e3..0000000 --- a/test/unit/getgr/cmd.c +++ /dev/null @@ -1,33 +0,0 @@ -#include "casl2.h" -#include "assemble.h" - -int main(){ - int i, j; - char *title = malloc(64); - WORD r; - bool is_x[] = { - false, true - }; - char *str[] = { - "", "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(cerr->num > 0) { - printf("\tError - %d\t%s", cerr->num, cerr->msg); - } - printf("\n"); - } - } - freecerr(); - return 0; -} diff --git a/test/unit/h2word/0.txt b/test/unit/h2word/0.txt deleted file mode 100644 index e7d7881..0000000 --- a/test/unit/h2word/0.txt +++ /dev/null @@ -1,9 +0,0 @@ -#32768 #0000 Error - 116 #32768: out of hex range -#-1 #0000 Error - 116 #-1: out of hex range -#G #0000 Error - 115 #G: not hex -#FFFF #FFFF -#0 #0000 -#1 #0001 -#ab #00AB -#AB #00AB -#20 #0020 diff --git a/test/unit/h2word/Makefile b/test/unit/h2word/Makefile deleted file mode 100644 index 52c2f81..0000000 --- a/test/unit/h2word/Makefile +++ /dev/null @@ -1,11 +0,0 @@ -include ../Define.mk -include ../Define_test.mk -include ../Test.mk - -.INTERMEDIATE: cmd - -SRCDIR = ../../../src -SRCFILES = $(SRCDIR)/hash.c $(SRCDIR)/cmem.c $(SRCDIR)/cerr.c $(SRCDIR)/cmd.c $(SRCDIR)/assemble.c $(SRCDIR)/word.c $(SRCDIR)/label.c $(SRCDIR)/struct.c $(SRCDIR)/macro.c $(SRCDIR)/token.c - -cmd: cmd.c $(SRCFILES) - gcc -g -Wall -I ../../../include -o $@ $^ diff --git a/test/unit/h2word/cmd.c b/test/unit/h2word/cmd.c deleted file mode 100644 index 3514241..0000000 --- a/test/unit/h2word/cmd.c +++ /dev/null @@ -1,26 +0,0 @@ -#include -#include "casl2.h" -#include "assemble.h" -#include "exec.h" - -int main(){ - int i; - WORD r; - 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(cerr->num > 0) { - printf("\tError - %d\t%s", cerr->num, cerr->msg); - } - printf("\n"); - } - freecerr(); - return 0; -} diff --git a/test/unit/hash/Makefile b/test/unit/hash/Makefile index 4d41f4b..1c59dcd 100644 --- a/test/unit/hash/Makefile +++ b/test/unit/hash/Makefile @@ -9,3 +9,4 @@ SRCFILES = $(SRCDIR)/hash.c $(SRCDIR)/cmem.c $(SRCDIR)/cerr.c cmd: cmd.c $(SRCFILES) gcc -g -Wall -I ../../../include -o $@ $^ + @rm -rf cmd.dSYM diff --git a/test/unit/linetok/Makefile b/test/unit/linetok/Makefile index 52c2f81..eff49e8 100644 --- a/test/unit/linetok/Makefile +++ b/test/unit/linetok/Makefile @@ -5,7 +5,8 @@ include ../Test.mk .INTERMEDIATE: cmd SRCDIR = ../../../src -SRCFILES = $(SRCDIR)/hash.c $(SRCDIR)/cmem.c $(SRCDIR)/cerr.c $(SRCDIR)/cmd.c $(SRCDIR)/assemble.c $(SRCDIR)/word.c $(SRCDIR)/label.c $(SRCDIR)/struct.c $(SRCDIR)/macro.c $(SRCDIR)/token.c +SRCFILES = $(SRCDIR)/cmem.c $(SRCDIR)/cerr.c $(SRCDIR)/cmd.c $(SRCDIR)/word.c $(SRCDIR)/struct.c $(SRCDIR)/token.c $(SRCDIR)/hash.c cmd: cmd.c $(SRCFILES) gcc -g -Wall -I ../../../include -o $@ $^ + @rm -rf cmd.dSYM diff --git a/test/unit/linetok/cmd.c b/test/unit/linetok/cmd.c index 28555cd..cec26fc 100644 --- a/test/unit/linetok/cmd.c +++ b/test/unit/linetok/cmd.c @@ -1,7 +1,8 @@ #include -#include -#include "casl2.h" #include "assemble.h" +#include "cmem.h" +#include "cerr.h" +#include "word.h" int main(){ int i, j; @@ -19,8 +20,7 @@ int main(){ }; CMDLINE *testcl = malloc(sizeof(CMDLINE)); - cerr = malloc_chk(sizeof(CERR), "cerr"); /* エラーの初期化 */ - addcerrlist_assemble(); + cerr_init(); /* エラーの初期化 */ for(i = 0; i < sizeof testline /sizeof testline[0]; i++) { printf("%d: %s", i, testline[i]); testcl = linetok(testline[i]); diff --git a/test/unit/n2word/0.txt b/test/unit/n2word/0.txt deleted file mode 100644 index e56aa1f..0000000 --- a/test/unit/n2word/0.txt +++ /dev/null @@ -1,13 +0,0 @@ -0 0x0000 -01 0x0001 -1a 0x0000 Error - 114 1a: not integer --5G 0x0000 Error - 114 -5G: not integer -123 0x007b -32767 0x7fff -32768 0x8000 -32769 0x8001 --1 0xffff --2345 0xf6d7 --32768 0x8000 --32769 0x7fff --32770 0x7ffe diff --git a/test/unit/n2word/Makefile b/test/unit/n2word/Makefile deleted file mode 100644 index 52c2f81..0000000 --- a/test/unit/n2word/Makefile +++ /dev/null @@ -1,11 +0,0 @@ -include ../Define.mk -include ../Define_test.mk -include ../Test.mk - -.INTERMEDIATE: cmd - -SRCDIR = ../../../src -SRCFILES = $(SRCDIR)/hash.c $(SRCDIR)/cmem.c $(SRCDIR)/cerr.c $(SRCDIR)/cmd.c $(SRCDIR)/assemble.c $(SRCDIR)/word.c $(SRCDIR)/label.c $(SRCDIR)/struct.c $(SRCDIR)/macro.c $(SRCDIR)/token.c - -cmd: cmd.c $(SRCFILES) - gcc -g -Wall -I ../../../include -o $@ $^ diff --git a/test/unit/nh2word/0.txt b/test/unit/nh2word/0.txt new file mode 100644 index 0000000..5828c18 --- /dev/null +++ b/test/unit/nh2word/0.txt @@ -0,0 +1,21 @@ +#32768 #0000 Error - 116 #32768: out of hex range +#-1 #0000 Error - 116 #-1: out of hex range +#G #0000 Error - 115 #G: not hex +#FFFF #FFFF +#0 #0000 +#1 #0001 +#ab #00AB +#AB #00AB +#200 #0200 +01 #0001 +1a #0000 Error - 114 1a: not integer +-5G #0000 Error - 114 -5G: not integer +123 #007B +32767 #7FFF +32768 #8000 +32769 #8001 +-1 #FFFF +-2345 #F6D7 +-32768 #8000 +-32769 #7FFF +-32770 #7FFE diff --git a/test/unit/nh2word/Makefile b/test/unit/nh2word/Makefile new file mode 100644 index 0000000..f7dabb5 --- /dev/null +++ b/test/unit/nh2word/Makefile @@ -0,0 +1,11 @@ +include ../Define.mk +include ../Define_test.mk +include ../Test.mk + +.INTERMEDIATE: cmd + +SRCDIR = ../../../src +SRCFILES = cmd.c $(SRCDIR)/cmem.c $(SRCDIR)/cerr.c $(SRCDIR)/word.c + +cmd: cmd.c $(SRCFILES) + gcc -g -Wall -I ../../../include -o $@ $^ diff --git a/test/unit/n2word/cmd.c b/test/unit/nh2word/cmd.c similarity index 64% rename from test/unit/n2word/cmd.c rename to test/unit/nh2word/cmd.c index 8d1d04e..06d68e5 100644 --- a/test/unit/n2word/cmd.c +++ b/test/unit/nh2word/cmd.c @@ -1,21 +1,23 @@ #include -#include "casl2.h" #include "assemble.h" +#include "test_h2word.h" +#include "cerr.h" +#include "word.h" int main(){ int i; WORD r; char *str[] = { + "#32768", "#-1", "#G", "#FFFF", "#0", "#1", "#ab", "#AB", "#20" "0", "01", "1a", "-5G", "123", "32767", "32768", "32769", "-1", "-2345", "-32768", "-32769", "-32770" }; - cerr = malloc_chk(sizeof(CERR), "cerr"); /* エラーの初期化 */ - addcerrlist_word(); + cerr_init(); /* エラーの初期化 */ for(i = 0; i < sizeof(str)/sizeof(str[0]); i++) { cerr->num = 0; - r = n2word(str[i]); - printf("%s\t0x%04x", str[i], r); + r = nh2word(str[i]); + printf("%s\t#%04X", str[i], r); if(cerr->num > 0) { printf("\tError - %d\t%s", cerr->num, cerr->msg); } diff --git a/test/unit/nh2word/test_h2word.h b/test/unit/nh2word/test_h2word.h new file mode 100644 index 0000000..4204e10 --- /dev/null +++ b/test/unit/nh2word/test_h2word.h @@ -0,0 +1,3 @@ +#define UNITTEST 1 + +WORD h2word(const char *str); diff --git a/test/unit/opdtok/Makefile b/test/unit/opdtok/Makefile index 52c2f81..754591e 100644 --- a/test/unit/opdtok/Makefile +++ b/test/unit/opdtok/Makefile @@ -5,7 +5,8 @@ include ../Test.mk .INTERMEDIATE: cmd SRCDIR = ../../../src -SRCFILES = $(SRCDIR)/hash.c $(SRCDIR)/cmem.c $(SRCDIR)/cerr.c $(SRCDIR)/cmd.c $(SRCDIR)/assemble.c $(SRCDIR)/word.c $(SRCDIR)/label.c $(SRCDIR)/struct.c $(SRCDIR)/macro.c $(SRCDIR)/token.c +SRCFILES = $(SRCDIR)/hash.c $(SRCDIR)/cmem.c $(SRCDIR)/cerr.c $(SRCDIR)/cmd.c $(SRCDIR)/assemble.c $(SRCDIR)/word.c $(SRCDIR)/label.c $(SRCDIR)/struct.c $(SRCDIR)/token.c cmd: cmd.c $(SRCFILES) gcc -g -Wall -I ../../../include -o $@ $^ + @rm -rf cmd.dSYM diff --git a/test/unit/opdtok/cmd.c b/test/unit/opdtok/cmd.c index bad4603..cfc32ea 100644 --- a/test/unit/opdtok/cmd.c +++ b/test/unit/opdtok/cmd.c @@ -1,5 +1,8 @@ -#include "casl2.h" +#include #include "assemble.h" +#include "cerr.h" + +OPD *opdtok(const char *str); int main(){ int i, j; @@ -14,7 +17,6 @@ int main(){ }; cerr = malloc_chk(sizeof(CERR), "cerr"); /* エラーの初期化 */ - addcerrlist_assemble(); for(i = 0; i < ARRAYSIZE(str); i++) { cerr->num = 0; printf("%s\n", str[i]); diff --git a/test/unit/setcerr/cmd.c b/test/unit/setcerr/cmd.c index 8e3ea72..ede0095 100644 --- a/test/unit/setcerr/cmd.c +++ b/test/unit/setcerr/cmd.c @@ -1,5 +1,5 @@ #include -#include "casl2.h" +#include "cerr.h" static CERR cerr_utest[] = { { 101, "label already defined" },