From 95b87bd10068d4f0f65912a7678d0aba8463724c Mon Sep 17 00:00:00 2001 From: j8takagi Date: Tue, 14 Dec 2010 00:56: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=AB=E3=80=81=E6=9C=80=E6=96=B0=E7=89=88?= =?utf8?q?=E3=81=AEAutotest.mk=E3=82=92=E5=8F=8D=E6=98=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- test/Makefile.TESTGROUPS.mk | 54 -------- test/TEST.mk | 41 ------ test/unit/.gitignore | 5 +- test/unit/CERRARRAY.c | 42 ------ test/unit/Define.mk | 125 ++++++++++++++++++ test/unit/Define_group.mk | 95 +++++++++++++ test/unit/Define_test.mk | 78 +++++++++++ test/unit/Makefile | 97 +++++++------- test/unit/Report.log | 2 + test/unit/TEMPLATE.c | 22 --- test/unit/TEST.mk | 48 ------- test/unit/Test.mk | 65 +++++++++ test/unit/UNIT.log | 31 +++++ test/unit/addcerrlist/Makefile | 14 +- .../unit/addcerrlist/{addcerrlist.c => cmd.c} | 2 +- test/unit/cerrtest/Makefile | 3 - test/unit/getcmdcode/Makefile | 14 +- test/unit/getcmdcode/{getcmdcode.c => cmd.c} | 0 test/unit/getcmdtype/Makefile | 14 +- test/unit/getcmdtype/{getcmdtype.c => cmd.c} | 2 +- test/unit/getgr/Makefile | 14 +- test/unit/getgr/{getgr.c => cmd.c} | 0 test/unit/h2word/Makefile | 14 +- test/unit/h2word/{h2word.c => cmd.c} | 0 test/unit/hash/Makefile | 14 +- test/unit/hash/{hash.c => cmd.c} | 0 test/unit/linetok/Makefile | 14 +- test/unit/linetok/{linetok.c => cmd.c} | 0 test/unit/n2word/Makefile | 14 +- test/unit/n2word/{getint.c => cmd.c} | 0 test/unit/opdtok/Makefile | 14 +- test/unit/opdtok/{opdtok.c => cmd.c} | 0 test/unit/print_cerrmsg/0.txt | 31 ----- test/unit/print_cerrmsg/Makefile | 3 - test/unit/print_cerrmsg/cerrtest.c | 23 ---- test/unit/print_cerrmsg/print_cerrmsg.c | 19 --- test/unit/print_cmdtype_code/0.txt | 38 ------ test/unit/print_cmdtype_code/Makefile | 3 - .../print_cmdtype_code/print_cmdtype_code.c | 54 -------- test/unit/print_cmdtype_code_hash/0.txt | 38 ------ test/unit/print_cmdtype_code_hash/Makefile | 3 - .../print_cmdtype_code.c | 34 ----- test/unit/print_code_type/0.txt | 38 ------ test/unit/print_code_type/Makefile | 3 - test/unit/print_code_type/print_code_type.c | 46 ------- test/unit/print_code_type_hash/0.txt | 38 ------ test/unit/print_code_type_hash/Makefile | 3 - .../print_code_type_hash/print_code_type.c | 34 ----- test/unit/{cerrtest => setcerr}/0.txt | 0 test/unit/setcerr/Makefile | 11 ++ .../{cerrtest/cerrtest.c => setcerr/cmd.c} | 0 test/unit/setcerr/desc.txt | 1 + 52 files changed, 563 insertions(+), 695 deletions(-) delete mode 100644 test/Makefile.TESTGROUPS.mk delete mode 100644 test/TEST.mk delete mode 100644 test/unit/CERRARRAY.c create mode 100644 test/unit/Define.mk create mode 100644 test/unit/Define_group.mk create mode 100644 test/unit/Define_test.mk create mode 100644 test/unit/Report.log delete mode 100644 test/unit/TEMPLATE.c delete mode 100644 test/unit/TEST.mk create mode 100644 test/unit/Test.mk create mode 100644 test/unit/UNIT.log rename test/unit/addcerrlist/{addcerrlist.c => cmd.c} (99%) delete mode 100644 test/unit/cerrtest/Makefile rename test/unit/getcmdcode/{getcmdcode.c => cmd.c} (100%) rename test/unit/getcmdtype/{getcmdtype.c => cmd.c} (96%) rename test/unit/getgr/{getgr.c => cmd.c} (100%) rename test/unit/h2word/{h2word.c => cmd.c} (100%) rename test/unit/hash/{hash.c => cmd.c} (100%) rename test/unit/linetok/{linetok.c => cmd.c} (100%) rename test/unit/n2word/{getint.c => cmd.c} (100%) rename test/unit/opdtok/{opdtok.c => cmd.c} (100%) delete mode 100644 test/unit/print_cerrmsg/0.txt delete mode 100644 test/unit/print_cerrmsg/Makefile delete mode 100644 test/unit/print_cerrmsg/cerrtest.c delete mode 100644 test/unit/print_cerrmsg/print_cerrmsg.c delete mode 100644 test/unit/print_cmdtype_code/0.txt delete mode 100644 test/unit/print_cmdtype_code/Makefile delete mode 100644 test/unit/print_cmdtype_code/print_cmdtype_code.c delete mode 100644 test/unit/print_cmdtype_code_hash/0.txt delete mode 100644 test/unit/print_cmdtype_code_hash/Makefile delete mode 100644 test/unit/print_cmdtype_code_hash/print_cmdtype_code.c delete mode 100644 test/unit/print_code_type/0.txt delete mode 100644 test/unit/print_code_type/Makefile delete mode 100644 test/unit/print_code_type/print_code_type.c delete mode 100644 test/unit/print_code_type_hash/0.txt delete mode 100644 test/unit/print_code_type_hash/Makefile delete mode 100644 test/unit/print_code_type_hash/print_code_type.c rename test/unit/{cerrtest => setcerr}/0.txt (100%) create mode 100644 test/unit/setcerr/Makefile rename test/unit/{cerrtest/cerrtest.c => setcerr/cmd.c} (100%) create mode 100644 test/unit/setcerr/desc.txt diff --git a/test/Makefile.TESTGROUPS.mk b/test/Makefile.TESTGROUPS.mk deleted file mode 100644 index 37ec308..0000000 --- a/test/Makefile.TESTGROUPS.mk +++ /dev/null @@ -1,54 +0,0 @@ -# テストグループ -# make : すべてのテストを実施し、ログを作成 -# make all : ↓ -# make clean : すべてのテストで、「make」で生成されたファイルをクリア -# make check : すべてのテストを実施 -# make cleanall: すべてのテストで、「make」と「make prepare」で生成されたファイルをクリア -# make prepare : すべてのテストの、想定結果を出力 -# make create : UNITNAMEで指定されたテストを新規に作成 -GROUPNAME = `pwd | xargs basename` -TESTS = `ls | grep "^[^A-Z].*"` -LOGFILE = Test.log - -.PHONY: all check checkeach report clean cleanall prepare create - -check: checkeach report - -checkeach: - @rm -f $(LOGFILE) - @for target in $(TESTS); do \ - $(MAKE) check -C $$target; \ - done - -$(LOGFILE): - @for target in $(TESTS); do \ - cat <$$target/report.txt >>$(LOGFILE) || echo $$target ": no report" >>$(LOGFILE); \ - done - -report: $(LOGFILE) - @success=`grep "Success" $(LOGFILE) | wc -l`; \ - all=`cat $(LOGFILE) | wc -l`; \ - echo "$(GROUPNAME): $$success / $$all tests passed. Details in `pwd`/$(LOGFILE)"; \ - if test $$success -eq $$all; then \ - echo "$(GROUPNAME): All tests are succeded."; \ - fi - -clean: - @for target in $(TESTS); do $(MAKE) clean -C $$target; done - @rm -f $(LOGFILE) - -cleanall: - @for target in $(TESTS); do $(MAKE) cleanall -C $$target; done - @rm -f $(LOGFILE) - -prepare: - @for target in $(TESTS) ; do $(MAKE) prepare -C $$target ; done - -create: -ifndef UNITNAME - @echo "no test created. set UNITNAME" -else - @mkdir $(UNITNAME) - @echo 'CMD = ' >>$(UNITNAME)/Makefile; \ - echo 'include ../TEST.mk' >>$(UNITNAME)/Makefile -endif diff --git a/test/TEST.mk b/test/TEST.mk deleted file mode 100644 index 753f6c0..0000000 --- a/test/TEST.mk +++ /dev/null @@ -1,41 +0,0 @@ -# テストのテンプレート -# 次の変数を定義する -# CMD: 実行するコマンド -# MAINTARGET_OVERRIDE: メインターゲットを独自に定義し、オーバーライドする -# make : CMDで設定されたコマンドを実行した出力結果を1.txtに出力し、0.txtと比較し、レポート -# make check : ↓ -# make prepare : CMDで設定されたコマンドを実行した出力結果を0.txt(テストの想定結果)に出力 -# make clean : 「make」で生成されたファイルをクリア -# make cleanall: 「make」と「make prepare」で生成されたファイルをクリア -UNITNAME = `pwd | xargs basename` -DATE = `date +"%F %T"` -ERR_FILE = err.txt -DIFF_FILE = diff.txt -REPORT_FILE = report.txt -TEST0_FILE = 0.txt -TEST1_FILE = 1.txt - -.PHONY: check prepare clean cleanall - -check: clean $(REPORT_FILE) - -prepare: cleanall $(TEST0_FILE) - -clean: - @rm -f $(TEST1_FILE) $(DIFF_FILE) $(REPORT_FILE) $(ERR_FILE) - -cleanall: clean - @rm -f $(TEST0_FILE) - -ifndef MAINTARGET_OVERRIDE -$(TEST0_FILE) $(TEST1_FILE): - @echo $(CMD) >$@; \ - $(CMD) >>$@ 2>$(ERR_FILE); \ - if test -s $(ERR_FILE); then cat $(ERR_FILE) >>$@; else rm -f $(ERR_FILE); fi -endif - -$(DIFF_FILE): $(TEST1_FILE) - @-diff -c $(TEST0_FILE) $(TEST1_FILE) >$@ 2>&1 - -$(REPORT_FILE): $(DIFF_FILE) - @if test ! -s $^; then echo "$(UNITNAME): Test Success $(DATE)" >>$@; rm -f $^; else echo "$(UNITNAME): Test Failure $(DATE)" >>$@; fi; diff --git a/test/unit/.gitignore b/test/unit/.gitignore index d7756c2..0f6d05f 100644 --- a/test/unit/.gitignore +++ b/test/unit/.gitignore @@ -1,2 +1,3 @@ -a.out -*.o +*/1.txt +*/err.txt +*/*.log \ No newline at end of file diff --git a/test/unit/CERRARRAY.c b/test/unit/CERRARRAY.c deleted file mode 100644 index a20b7c7..0000000 --- a/test/unit/CERRARRAY.c +++ /dev/null @@ -1,42 +0,0 @@ -#include "cerr.h" - -/* エラー番号とエラーメッセージ */ -CERR cerr_utest[] = { - { 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 count mismatch" }, - { 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, "command not defined" }, - { 114, "not integer" }, - { 115, "not hex" }, - { 116, "out of hex range" }, - { 117, "operand is too many" }, - { 118, "operand length is 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" }, - { 201, "execute - out 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" }, -}; - -void addcerr_utest() -{ - addcerrlist((sizeof(cerr_utest)/sizeof(cerr_utest[0])), cerr_utest); -} diff --git a/test/unit/Define.mk b/test/unit/Define.mk new file mode 100644 index 0000000..641f823 --- /dev/null +++ b/test/unit/Define.mk @@ -0,0 +1,125 @@ +# autotest.mk > test_template > Define.mk +# 自動テスト用の変数、マクロ定義 + +ifndef DEFINE_INCLUDED +DEFINE_INCLUDED = 1 + +# 現在の日時 +DATE = $(shell date +"%F %T") + +# 現在のディレクトリー +CURRDIR = $(shell pwd) + +# Makefile +MAKEFILE := Makefile + +###################################################################### +# コマンド +###################################################################### + +CP ?= cp + +CAT ?= cat + +MKDIR ?= mkdir -p + +RM ?= rm -f + +ECHO ?= echo + +TIME ?= /usr/bin/time --quiet + +DIFF ?= diff -c + +DEV_NULL ?= /dev/null + +CHMOD ?= chmod + +GREP ?= grep + +LINECOUNT ?= wc -l + +FIND ?= find + +TR ?= tr + +EXPR ?= expr + +LN ?= ln -s + +###################################################################### +# テストグループとテストでの共通マクロ +###################################################################### + +# chk_var_null: 引数がNULLの場合、エラー +# 用例: $(call chk_var_null,var) +define chk_var_null + $(if $1,,$(error NULL argument)) +endef + +# chk_file_ext: 指定されたファイルが実在する場合、エラー +# 用例: $(call chk_file_ext,file) +define chk_file_ext + $(if $(wildcard $1),$(error $1 exists in $(CURRDIR))) +endef + +###################################################################### +# テストグループのディレクトリー +###################################################################### + +# テストグループとテストの変数を定義したMakefile +DEF_FILE := Define.mk + +# テストグループの変数を定義したMakefile +DEF_GROUP_FILE := Define_group.mk + +# テストの変数を定義したMakefile +DEF_TEST_FILE := Define_test.mk + +# テストのターゲットを定義したMakefile +TEST_MAKEFILE := Test.mk + +# すべてのMakefile群 +MAKEFILES := $(DEF_FILE) $(DEF_GROUP_FILE) $(DEF_TEST_FILE) $(TEST_MAKEFILE) + +# すべてのMakefile群の絶対パス +MAKEFILES_ABS := $(foreach file,$(MAKEFILES),$(CURRDIR)/$(file)) + +# テストごとのMakefileでインクルードするMakefile群 +TEST_MAKEFILES := $(DEF_FILE) $(DEF_TEST_FILE) $(TEST_MAKEFILE) + +###################################################################### +# テストのディレクトリー +###################################################################### + +# テストコマンドファイル +CMD_FILE := cmd + +# テスト説明ファイル +DESC_FILE := desc.txt + +# テスト想定結果ファイル +TEST0_FILE := 0.txt + +# テスト結果ファイル +TEST1_FILE := 1.txt + +# テストの、想定結果と結果の差分ファイル +DIFF_FILE := diff.txt + +# テストエラーファイル +ERR_FILE := err.txt + +# テストログファイル +LOG_FILE := test.log + +# 実行時間ファイル +TIME_FILE := time.log + +# テスト詳細レポートファイル +DETAIL_FILE := detail.log + +# テストの結果として作成されるファイル群 +TEST_RES_FILES := $(TEST1_FILE) $(DIFF_FILE) $(ERR_FILE) $(LOG_FILE) $(DETAIL_FILE) $(TIME_FILE) + +endif diff --git a/test/unit/Define_group.mk b/test/unit/Define_group.mk new file mode 100644 index 0000000..f3cda2c --- /dev/null +++ b/test/unit/Define_group.mk @@ -0,0 +1,95 @@ +###################################################################### +# テストグループのディレクトリー +# ほかに、Define.mkでも一部定義 +###################################################################### + +# グループディレクトリー +GROUP_DIR := $(CURRDIR) + +# グループ名。ディレクトリ名から取得 +GROUP := $(notdir $(GROUP_DIR)) + +# テスト名。カレントディレクトリー内の、名前が大文字または.以外で始まるディレクトリー +TESTS = $(notdir $(shell $(FIND) -maxdepth 1 -name "[^A-Z.]*" -type d)) + +# テストグループログファイル +GROUP_LOG_FILE := $(shell $(ECHO) $(GROUP) | $(TR) '[a-z]' '[A-Z]').log + +# テストグループレポートファイル +GROUP_REPORT_FILE := Report.log + +# テストグループ実行時間ファイル +GROUP_TIME_FILE := $(shell echo $(GROUP) | $(TR) '[a-z]' '[A-Z]')_time.log + +# グループで、テスト結果として作成されるファイル群 +GROUP_RES_FILES := $(GROUP_LOG_FILE) $(GROUP_REPORT_FILE) $(GROUP_TIME_FILE) + +# テストごとのログファイル +TEST_LOG_FILES := $(foreach test,$(TESTS),$(test)/$(LOG_FILE)) + +###################################################################### +# テストグループのマクロ +###################################################################### + +# 指定したディレクトリーを作成 +# 用例: $(call create_dir,name) +define create_dir + $(call chk_var_null,$1) + $(call chk_file_ext,$1) + $(MKDIR) $1 +endef + +# リストで指定された親ディレクトリーにあるMakefileをインクルードするMakefileを作成 +# 用例: $(call create_makefile,file,list_include_file) +define create_makefile + $(RM) $1 + $(foreach infile,$2,$(ECHO) "include ../$(infile)" >>$1; ) +endef + +# テストごとのファイルをグループファイルに出力 +# 引数は、テストのリスト、グループファイル、テストファイル +# 用例: $(call group_log,files_test_log,file_group_log) +define group_log + $(foreach target,$1,$(call group_log_each,$(target),$2)) +endef + +# テストのログファイルをグループログファイルに出力。引数は、テスト、グループログファイル +# 用例: $(call group_log_each,file_test_log,file_group_log) +define group_log_each + if test -s $1; then $(CAT) $1 >>$2; else $(ECHO) $(dir $1)": no log" >>$2; fi + $(ECHO) >>$2; + +endef + +# 成功したテストの数。テストグループログファイルから取得 +SUCCESS_TEST = $(shell $(GREP) "^[^A-Z.].*: Test Success" $(GROUP_LOG_FILE) | $(LINECOUNT)) + +# 失敗したテストの数。テストグループログファイルから取得 +FAIL_TEST = $(shell $(GREP) "^[^A-Z.].*: Test Failure" $(GROUP_LOG_FILE) | $(LINECOUNT)) + +# すべてのテストの数 +ALL_TEST = $(shell $(EXPR) $(SUCCESS_TEST) + $(FAIL_TEST)) + +# テストごとの実行時間ファイル +TEST_TIME_FILES := $(foreach test,$(TESTS),$(test)/$(TIME_FILE)) + +# テストの結果を、グループログファイルを元にレポート。 +# 引数は、グループ名、グループログファイル、グループレポートファイル +# 用例: $(call group_report,name,file_log,file_report) +define group_report + $(ECHO) "$1: $(SUCCESS_TEST) / $(ALL_TEST) tests passed. Detail in $(GROUP_DIR)/$2" >$3; + if test $(FAIL_TEST) -eq 0; then $(ECHO) "$1: All tests are succeded." >>$3; fi +endef + +# リストで指定したディレクトリーでmakeを実行 +# 用例: $(call make_tests,list_dir,target) +define make_tests + $(foreach dir,$1,$(call make_test_each,$(dir),$2)) +endef + +# 指定したディレクトリーでmakeを実行 +# 用例: $(call make_test_each,tests,target) +define make_test_each + $(MAKE) $2 -sC $1; + +endef diff --git a/test/unit/Define_test.mk b/test/unit/Define_test.mk new file mode 100644 index 0000000..65bfcaf --- /dev/null +++ b/test/unit/Define_test.mk @@ -0,0 +1,78 @@ +###################################################################### +# マクロ +###################################################################### + +# 引数のファイルをチェックし、内容がない場合は削除 +# 用例: $(call rm_null,file) +define rm_null + if test ! -s $1; then $(RM) $1; fi +endef + +# 説明ファイルの内容を、引数のファイルに出力 +# 用例: $(call desc_log,file_out) +define desc_log + if test -s $(DESC_FILE); then $(CAT) $(DESC_FILE) >>$1; fi +endef + +# テスト実行の経過時間を、ファイルに出力して表示 +# 引数は、テスト名、コマンドファイル、出力ファイル +# 用例: $(call time_cmd,name,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 +endef + +# テスト実行コマンド。引数は、コマンドファイル、出力ファイル、エラーファイル +# コマンドファイルを実行し、標準出力を出力ファイルに保存。 +# エラー発生時は、エラー出力を出力ファイルとエラーファイルに保存。 +# 用例: $(call exec_cmd,file_cmd,file_out,file_err) +define exec_cmd + @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) +endef + +# 2つのファイルを比較し、差分ファイルを作成 +# 引数は、2ファイルのリスト、差分ファイル +# 用例: $(call diff_files,files,file_out) +define diff_files + $(DIFF) $1 >$2 2>&1 + $(call rm_null,$2) +endef + +# 差分ファイルの内容をログファイルに出力 +# 引数は、テスト名、差分ファイル、ログファイル +# 用例: $(call test_log,name,file_diff,file_log) +define test_log + $(call desc_log,$3) + if test ! -s $2; then RES=Success; else RES=Failure; fi; $(ECHO) "$1: Test $$RES $(DATE)" >>$3 + $(ECHO) "Detail in $(CURRDIR)/$(DETAIL_FILE)" >>$3 +endef + +# NODISPが設定されていない時は、ログファイルを表示 +# 引数は、ログファイル +# 用例: $(call disp_test_log,file_log) +define disp_test_log + $(if $(NODISP),,$(CAT) $1) +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 + +# ファイル名とファイルの内容を出力 +# 引数は、対象ファイル、出力ファイル +# 用例: $(call report_file,file_target,file_out) +define report_file + $(call chk_var_null,$1) + if test -s $1; then $(ECHO) "== $1 ==" >>$2; $(call echo_hr,$2); cat $1 >>$2; $(call echo_hr,$2); $(ECHO) >>$2; fi +endef + +define echo_hr + $(ECHO) "----------------------------------------------------------------------" >>$1 +endef diff --git a/test/unit/Makefile b/test/unit/Makefile index f5b6616..e22d03c 100644 --- a/test/unit/Makefile +++ b/test/unit/Makefile @@ -1,47 +1,52 @@ -# テストグループ -# make : すべてのテストを実施し、ログを作成 -# make all : ↓ -# make clean : すべてのテストで、「make」で生成されたファイルをクリア -# make check : すべてのテストを実施 -# make cleanall: すべてのテストで、「make」と「make prepare」で生成されたファイルをクリア -# make prepare : すべてのテストの、想定結果を出力 -# make create : UNITNAMEで指定されたテストを新規に作成 -TESTS = `ls | grep "^[^A-Z].*"` -LOGFILE = Test.log - -.PHONY: all check report clean cleanall prepare create -all: check report -check: - @rm -f $(LOGFILE) - @for target in $(TESTS); do \ - $(MAKE) check -sC $$target; \ - done -$(LOGFILE): - @for target in $(TESTS); do \ - cat <$$target/report.txt >>$(LOGFILE) || echo $$target ": no report"; \ - done -report: $(LOGFILE) - @success=`grep "Success" $(LOGFILE) | wc -l`; \ - all=`cat $(LOGFILE) | wc -l`; \ - echo "$$success / $$all tests passed. Details in `pwd`/$(LOGFILE)"; \ - if test $$success -eq $$all; then \ - echo "All tests are succeded."; \ - fi -clean: - @for target in $(TESTS); do $(MAKE) clean -C $$target; done - @rm -f $(LOGFILE) -cleanall: - @for target in $(TESTS); do $(MAKE) cleanall -C $$target; done - @rm -f $(LOGFILE) -prepare: - @for target in $(TESTS) ; do $(MAKE) prepare -C $$target ; done +# autotest.mk > template > Group.mk +# テストグループのMakefile +# +# オペレーター +# make : すべてのテストを実施し、ログファイルを作成 +# make check : ↓ +# make create : TESTNAMEで指定されたテストを新規に作成 +# make set : すべてのテストの、想定結果を出力 +# make checkeach: すべてのテストを実施 +# make report : ログファイルから、テストの結果をレポート +# make clean : すべてのテストで、"make" で生成されたファイルをクリア +# make cleanall: すべてのテストで、"make" と "make set" で生成されたファイルをクリア + +SHELL = /bin/sh + +include Define.mk +include Define_group.mk + +.PHONY: check checkall time create clean cleantime + +check checkall: clean $(GROUP_REPORT_FILE) + @$(CAT) $(GROUP_REPORT_FILE) + +time: cleantime $(GROUP_TIME_FILE) + @$(CAT) $(GROUP_TIME_FILE) + create: -ifdef UNITNAME - @mkdir $(UNITNAME); \ - echo 'UCLASS = ' >>$(UNITNAME)/Makefile; \ - echo 'TESTSRCFILE = $(UNITNAME).c' >>$(UNITNAME)/Makefile; \ - echo 'include ../TEST.mk' >>$(UNITNAME)/Makefile; \ - cp TEMPLATE.c $(UNITNAME)/$(UNITNAME).c -else - @echo "no test created. set UNITNAME" -endif + @$(call create_dir,$(TEST)) + @$(call create_makefile,$(TEST)/$(MAKEFILE),$(TEST_MAKEFILES)) + +clean: + @$(call make_tests,$(TESTS),$@) + @$(RM) $(GROUP_RES_FILES) + +cleantime: + @$(call make_tests,$(TESTS),$@) + @$(RM) $(GROUP_TIME_FILE) + +$(GROUP_REPORT_FILE): $(GROUP_LOG_FILE) + @$(call group_report,$(GROUP),$^,$@) + +$(GROUP_LOG_FILE): $(TEST_LOG_FILES) + @$(call group_log,$^,$@) + +$(TEST_LOG_FILES): + @$(MAKE) $(MAKECMDGOALS) -sC $(dir $@) NODISP=1 + +$(GROUP_TIME_FILE): $(TEST_TIME_FILES) + @$(call group_log,$^,$@) + +$(TEST_TIME_FILES): + @$(MAKE) time -sC $(dir $@) diff --git a/test/unit/Report.log b/test/unit/Report.log new file mode 100644 index 0000000..d55aed3 --- /dev/null +++ b/test/unit/Report.log @@ -0,0 +1,2 @@ +unit: 10 / 10 tests passed. Detail in /home/kazubito/2010_12/yacasl2/test/unit/UNIT.log +unit: All tests are succeded. diff --git a/test/unit/TEMPLATE.c b/test/unit/TEMPLATE.c deleted file mode 100644 index d5838fe..0000000 --- a/test/unit/TEMPLATE.c +++ /dev/null @@ -1,22 +0,0 @@ -#include -#include "casl2.h" -#include "assemble.h" -#include "exec.h" - -int main(){ - int i; - WORD r; - char *str[] = { - "str0", "str1", "str2", "str3", "str4", "str5", "str6", ... - }; - for(i = 0; i < sizeof(str)/sizeof(str[0]); i++) { - r = ##testfunc##(str[i]); - printf("%s\t0x%04x", str[i], r); - if(cerrno > 0) { - printf("\tError - %d\t%s", cerrno, cerrmsg); - freecerr(); - } - printf("\n"); - } - return 0; -} diff --git a/test/unit/TEST.mk b/test/unit/TEST.mk deleted file mode 100644 index fbda62a..0000000 --- a/test/unit/TEST.mk +++ /dev/null @@ -1,48 +0,0 @@ -# テストのテンプレート -# make : CMDで設定されたコマンドを実行した出力結果を1.txtに出力し、0.txtと比較し、レポート -# make check : ↓ -# make prepare : CMDで設定されたコマンドを実行した出力結果を0.txt(テストの想定結果)に出力 -# make clean : 「make」で生成されたファイルをクリア -# make cleanall: 「make」と「make clean」で生成されたファイルをクリア -ERRFILE = err.txt -UNITNAME = `pwd | xargs basename` - -SRCDIR = ../../../src -INCLUDE = ../../../include -CC = gcc -CFLAGS = -g -Wall -I $(INCLUDE) -COMMONSRC = $(SRCDIR)/word.o $(SRCDIR)/struct.o $(SRCDIR)/hash.o $(SRCDIR)/cmd.o $(SRCDIR)/cmem.o $(SRCDIR)/cerr.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 -ifeq "$(UCLASS)" "EXEC" - SRC = $(COMMONSRC) $(EXECSRC) -endif -ifeq "$(UCLASS)" "COMMON" - SRC = $(COMMONSRC) -endif - -.PHPNY: check prepare clean cleanall -check: clean report.txt -prepare: cleanall 0.txt -clean: - @rm -f a.out 1.txt diff.txt report.txt -cleanall: clean - @rm -f 0.txt -a.out: $(SRC) $(TESTSRCFILE) - @make -sC $(SRCDIR) - gcc $(CFLAGS) $(SRC) $(TESTSRCFILE) -0.txt 1.txt: a.out - @./a.out >$@ 2>&1 -diff.txt: 1.txt - @-diff -c 0.txt 1.txt >$@ 2>&1 -report.txt: diff.txt - @echo -n "$(UNITNAME): Test " >$@; \ - if test ! -s $^; then echo -n "Success " >>$@; rm -f $^; else echo -n "Failure " >>$@; fi; \ - echo `date +"%F %T"` >>$@ diff --git a/test/unit/Test.mk b/test/unit/Test.mk new file mode 100644 index 0000000..8e2628d --- /dev/null +++ b/test/unit/Test.mk @@ -0,0 +1,65 @@ +# autotest.mk > test_template > Test.mk +# 自動テスト用のMakefile +# +# 要: Define.mk Define_test.mk +# +# オペレーター +# make : CMDの標準出力をTEST1_FILEに保存したあと、TEST0_FILEとの差分を比較し、結果をLOG_FILEに出力 +# make check : ↓ +# make set : CMDの標準出力をTEST0_FILEに保存。TEST0_FILEが存在する場合は実行しない +# make reset : CMDの標準出力をTEST0_FILEに保存。TEST0_FILEが存在する場合は上書き +# make time : CMDの実行にかかった時間をTIME_FILEに保存し、出力 +# make cleantime: "make time" で作成されたファイルをクリア +# make clean : "make" で作成されたファイルをクリア +# make cleanall: "make" と "make set" で作成されたファイルをクリア + +SHELL = /bin/sh + +# テスト名。カレントディレクトリー名から取得 +TEST = $(notdir $(CURRDIR)) + +# コマンドファイルのソース +#CMDSRC_FILE := $(CMD_FILE) +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) + @$(CAT) $(TIME_FILE) >>$(LOG_FILE) + @$(call disp_test_log,$(LOG_FILE)) + +set: $(TEST0_FILE) + @$(CAT) $^ + +reset: cleanall $(TEST0_FILE) + @$(CAT) $(TEST0_FILE) + +time: cleantime $(TIME_FILE) + +cleantime: + @$(RM) $(TIME_FILE) + +clean: + @$(RM) $(TEST_RES_FILES) + +cleanall: clean + @$(RM) $(TEST0_FILE) + +$(TEST0_FILE) $(TEST1_FILE): $(CMD_FILE) + @-$(call exec_cmd,$^,$@,$(ERR_FILE)) + +$(DIFF_FILE): $(TEST0_FILE) $(TEST1_FILE) + @-$(call diff_files,$^,$@) + +$(LOG_FILE): $(DIFF_FILE) + @$(call test_log,$(TEST),$^,$@) + +$(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),$^,$@) diff --git a/test/unit/UNIT.log b/test/unit/UNIT.log new file mode 100644 index 0000000..84ee99c --- /dev/null +++ b/test/unit/UNIT.log @@ -0,0 +1,31 @@ +getcmdtype: Test Success 2010-12-14 00:22:16 +Detail in /home/kazubito/2010_12/yacasl2/test/unit/getcmdtype/detail.log + +hash: Test Success 2010-12-14 00:22:16 +Detail in /home/kazubito/2010_12/yacasl2/test/unit/hash/detail.log + +addcerrlist: Test Success 2010-12-14 00:22:16 +Detail in /home/kazubito/2010_12/yacasl2/test/unit/addcerrlist/detail.log + +関数setcerrのテスト +setcerr: Test Success 2010-12-14 00:22:17 +Detail in /home/kazubito/2010_12/yacasl2/test/unit/setcerr/detail.log + +getcmdcode: Test Success 2010-12-14 00:22:17 +Detail in /home/kazubito/2010_12/yacasl2/test/unit/getcmdcode/detail.log + +linetok: Test Success 2010-12-14 00:22:18 +Detail in /home/kazubito/2010_12/yacasl2/test/unit/linetok/detail.log + +opdtok: Test Success 2010-12-14 00:22:19 +Detail in /home/kazubito/2010_12/yacasl2/test/unit/opdtok/detail.log + +h2word: Test Success 2010-12-14 00:22:21 +Detail in /home/kazubito/2010_12/yacasl2/test/unit/h2word/detail.log + +getgr: Test Success 2010-12-14 00:22:22 +Detail in /home/kazubito/2010_12/yacasl2/test/unit/getgr/detail.log + +n2word: Test Success 2010-12-14 00:22:23 +Detail in /home/kazubito/2010_12/yacasl2/test/unit/n2word/detail.log + diff --git a/test/unit/addcerrlist/Makefile b/test/unit/addcerrlist/Makefile index e742823..526ac3a 100644 --- a/test/unit/addcerrlist/Makefile +++ b/test/unit/addcerrlist/Makefile @@ -1,3 +1,11 @@ -UCLASS = COMMON -TESTSRCFILE = addcerrlist.c -include ../TEST.mk +include ../Define.mk +include ../Define_test.mk +include ../Test.mk + +SRCDIR = ../../../src +SRCFILES = $(SRCDIR)/cmem.c $(SRCDIR)/cerr.c cmd.c + +.INTERMEDIATE: cmd + +cmd: cmd.c $(SRCFILES) + gcc -g -Wall -I ../../../include -o $@ $^ diff --git a/test/unit/addcerrlist/addcerrlist.c b/test/unit/addcerrlist/cmd.c similarity index 99% rename from test/unit/addcerrlist/addcerrlist.c rename to test/unit/addcerrlist/cmd.c index 884931c..2fccdb9 100644 --- a/test/unit/addcerrlist/addcerrlist.c +++ b/test/unit/addcerrlist/cmd.c @@ -1,5 +1,5 @@ #include -#include "casl2.h" +#include "cerr.h" CERR cerr_0[] = { { 126, "source file is not specified" }, diff --git a/test/unit/cerrtest/Makefile b/test/unit/cerrtest/Makefile deleted file mode 100644 index 6d8b231..0000000 --- a/test/unit/cerrtest/Makefile +++ /dev/null @@ -1,3 +0,0 @@ -UCLASS = COMMON -TESTSRCFILE = cerrtest.c -include ../TEST.mk diff --git a/test/unit/getcmdcode/Makefile b/test/unit/getcmdcode/Makefile index ab85bfa..155e27e 100644 --- a/test/unit/getcmdcode/Makefile +++ b/test/unit/getcmdcode/Makefile @@ -1,3 +1,11 @@ -UCLASS = COMMON -TESTSRCFILE = getcmdcode.c -include ../TEST.mk +include ../Define.mk +include ../Define_test.mk +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 + +cmd: cmd.c $(SRCFILES) + gcc -g -Wall -I ../../../include -o $@ $^ diff --git a/test/unit/getcmdcode/getcmdcode.c b/test/unit/getcmdcode/cmd.c similarity index 100% rename from test/unit/getcmdcode/getcmdcode.c rename to test/unit/getcmdcode/cmd.c diff --git a/test/unit/getcmdtype/Makefile b/test/unit/getcmdtype/Makefile index ce4bf22..9329b17 100644 --- a/test/unit/getcmdtype/Makefile +++ b/test/unit/getcmdtype/Makefile @@ -1,3 +1,11 @@ -UCLASS = COMMON -TESTSRCFILE = getcmdtype.c -include ../TEST.mk +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 + +cmd: cmd.c $(SRCFILES) + gcc -g -Wall -I ../../../include -o $@ $^ diff --git a/test/unit/getcmdtype/getcmdtype.c b/test/unit/getcmdtype/cmd.c similarity index 96% rename from test/unit/getcmdtype/getcmdtype.c rename to test/unit/getcmdtype/cmd.c index 2c3337c..e4379a9 100644 --- a/test/unit/getcmdtype/getcmdtype.c +++ b/test/unit/getcmdtype/cmd.c @@ -12,7 +12,7 @@ int main(){ 0x4100, 0x4400, 0x4500, 0x5000, 0x5100, 0x5200, 0x5300, 0x6100, 0x6200, 0x6300, 0x6400, 0x6500, 0x6600, 0x7000, 0x7100, - 0x8000, 0xF000, 0x8100 + 0x8000, 0xF000, 0x8100, }; cerr = malloc_chk(sizeof(CERR), "cerr"); /* エラーの初期化 */ diff --git a/test/unit/getgr/Makefile b/test/unit/getgr/Makefile index 32db8d8..52c2f81 100644 --- a/test/unit/getgr/Makefile +++ b/test/unit/getgr/Makefile @@ -1,3 +1,11 @@ -UCLASS = AS -TESTSRCFILE = getgr.c -include ../TEST.mk +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/getgr.c b/test/unit/getgr/cmd.c similarity index 100% rename from test/unit/getgr/getgr.c rename to test/unit/getgr/cmd.c diff --git a/test/unit/h2word/Makefile b/test/unit/h2word/Makefile index c48a61e..52c2f81 100644 --- a/test/unit/h2word/Makefile +++ b/test/unit/h2word/Makefile @@ -1,3 +1,11 @@ -UCLASS = AS -TESTSRCFILE = h2word.c -include ../TEST.mk +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/h2word.c b/test/unit/h2word/cmd.c similarity index 100% rename from test/unit/h2word/h2word.c rename to test/unit/h2word/cmd.c diff --git a/test/unit/hash/Makefile b/test/unit/hash/Makefile index 3a6807e..4d41f4b 100644 --- a/test/unit/hash/Makefile +++ b/test/unit/hash/Makefile @@ -1,3 +1,11 @@ -UCLASS = COMMON -TESTSRCFILE = ../CERRARRAY.c hash.c -include ../TEST.mk +include ../Define.mk +include ../Define_test.mk +include ../Test.mk + +.INTERMEDIATE: cmd + +SRCDIR = ../../../src +SRCFILES = $(SRCDIR)/hash.c $(SRCDIR)/cmem.c $(SRCDIR)/cerr.c + +cmd: cmd.c $(SRCFILES) + gcc -g -Wall -I ../../../include -o $@ $^ diff --git a/test/unit/hash/hash.c b/test/unit/hash/cmd.c similarity index 100% rename from test/unit/hash/hash.c rename to test/unit/hash/cmd.c diff --git a/test/unit/linetok/Makefile b/test/unit/linetok/Makefile index f38bdf0..52c2f81 100644 --- a/test/unit/linetok/Makefile +++ b/test/unit/linetok/Makefile @@ -1,3 +1,11 @@ -UCLASS = AS -TESTSRCFILE = ../CERRARRAY.c linetok.c -include ../TEST.mk +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/linetok/linetok.c b/test/unit/linetok/cmd.c similarity index 100% rename from test/unit/linetok/linetok.c rename to test/unit/linetok/cmd.c diff --git a/test/unit/n2word/Makefile b/test/unit/n2word/Makefile index 5d07682..52c2f81 100644 --- a/test/unit/n2word/Makefile +++ b/test/unit/n2word/Makefile @@ -1,3 +1,11 @@ -UCLASS = AS -TESTSRCFILE = ../CERRARRAY.c getint.c -include ../TEST.mk +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/n2word/getint.c b/test/unit/n2word/cmd.c similarity index 100% rename from test/unit/n2word/getint.c rename to test/unit/n2word/cmd.c diff --git a/test/unit/opdtok/Makefile b/test/unit/opdtok/Makefile index 2b496bf..52c2f81 100644 --- a/test/unit/opdtok/Makefile +++ b/test/unit/opdtok/Makefile @@ -1,3 +1,11 @@ -UCLASS = AS -TESTSRCFILE = ../CERRARRAY.c opdtok.c -include ../TEST.mk +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/opdtok/opdtok.c b/test/unit/opdtok/cmd.c similarity index 100% rename from test/unit/opdtok/opdtok.c rename to test/unit/opdtok/cmd.c diff --git a/test/unit/print_cerrmsg/0.txt b/test/unit/print_cerrmsg/0.txt deleted file mode 100644 index 7c01ffb..0000000 --- a/test/unit/print_cerrmsg/0.txt +++ /dev/null @@ -1,31 +0,0 @@ -114: not integer -115: not hex -116: out of hex range -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 -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/print_cerrmsg/Makefile b/test/unit/print_cerrmsg/Makefile deleted file mode 100644 index e253b41..0000000 --- a/test/unit/print_cerrmsg/Makefile +++ /dev/null @@ -1,3 +0,0 @@ -UCLASS = ALL -TESTSRCFILE = ../CERRARRAY.c print_cerrmsg.c -include ../TEST.mk diff --git a/test/unit/print_cerrmsg/cerrtest.c b/test/unit/print_cerrmsg/cerrtest.c deleted file mode 100644 index ed8d0ae..0000000 --- a/test/unit/print_cerrmsg/cerrtest.c +++ /dev/null @@ -1,23 +0,0 @@ -#include -#include "casl2.h" - -int main(){ - int i, j; - int code[] = { - 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, - 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, - 121, 122, 123, 124, 201, 202, 203, 204, 205, 206, 207, 999 - }; - const char *str[] = {NULL, "foobar"}; - - for(i = 0; i < sizeof(str)/sizeof(str[0]); i++) { - for(j = 0; j < sizeof(code)/sizeof(code[0]); j++) { - setcerr(code[j], str[i]); - printf("%d: %s - %d\t%s\n", code[j], str[i], cerrno, cerrmsg); - if(cerrno != 0) { - freecerr(); - } - } - } - return 0; -} diff --git a/test/unit/print_cerrmsg/print_cerrmsg.c b/test/unit/print_cerrmsg/print_cerrmsg.c deleted file mode 100644 index 34de8f8..0000000 --- a/test/unit/print_cerrmsg/print_cerrmsg.c +++ /dev/null @@ -1,19 +0,0 @@ -#include -#include "casl2.h" -#include "assemble.h" -#include "exec.h" - -int main(){ - CERRLIST *p; - - 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/0.txt b/test/unit/print_cmdtype_code/0.txt deleted file mode 100644 index 53ad80d..0000000 --- a/test/unit/print_cmdtype_code/0.txt +++ /dev/null @@ -1,38 +0,0 @@ -ADDA 011 #2000 -ADDA 020 #2400 -ADDL 011 #2200 -ADDL 020 #2600 -AND 011 #3000 -AND 020 #3400 -CALL 030 #8000 -CPA 011 #4000 -CPA 020 #4400 -CPL 011 #4100 -CPL 020 #4500 -JMI 030 #6100 -JNZ 030 #6200 -JOV 030 #6600 -JPL 030 #6500 -JUMP 030 #6400 -JZE 030 #6300 -LAD 010 #1200 -LD 011 #1000 -LD 020 #1400 -NOP 000 #0000 -OR 011 #3100 -OR 020 #3500 -POP 040 #7100 -PUSH 030 #7000 -RET 000 #8100 -SLA 010 #5000 -SLL 010 #5200 -SRA 010 #5100 -SRL 010 #5300 -ST 010 #1100 -SUBA 011 #2100 -SUBA 020 #2500 -SUBL 011 #2300 -SUBL 020 #2700 -SVC 030 #F000 -XOR 011 #3200 -XOR 020 #3600 diff --git a/test/unit/print_cmdtype_code/Makefile b/test/unit/print_cmdtype_code/Makefile deleted file mode 100644 index 2b1571f..0000000 --- a/test/unit/print_cmdtype_code/Makefile +++ /dev/null @@ -1,3 +0,0 @@ -UCLASS = COMMON -TESTSRCFILE = ../CERRARRAY.c print_cmdtype_code.c -include ../TEST.mk diff --git a/test/unit/print_cmdtype_code/print_cmdtype_code.c b/test/unit/print_cmdtype_code/print_cmdtype_code.c deleted file mode 100644 index 70bcd78..0000000 --- a/test/unit/print_cmdtype_code/print_cmdtype_code.c +++ /dev/null @@ -1,54 +0,0 @@ -#include "casl2.h" -#include "cerr.h" -#include - -int compare_code(const void *a, const void *b) -{ - const CMD ca = **(const CMD **)a; - const CMD cb = **(const CMD **)b; - int diff; - - if((diff = strcmp(ca.name, cb.name)) == 0) { - return ca.type - cb.type; - } else { - return diff; - } -} - -/* 命令と命令タイプがキーのハッシュ表を表示する */ -void print_cmdtype_code() -{ - int i, j = 0; - 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->cmd; - np = np->next; - } - } - 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); - } -} - -int main() -{ - /* エラーの初期化 */ - cerr = malloc_chk(sizeof(CERR), "cerr"); - /* ハッシュ表作成 */ - create_cmdtype_code(); - /* 命令表の表示 */ - print_cmdtype_code(); - /* ハッシュ表解放 */ - free_cmdtype_code(); - if(cerr->num != 0) { - printf("\terror - %d: %s\n", cerr->num, cerr->msg); - freecerr(); - exit(-1); - } - return 0; -} diff --git a/test/unit/print_cmdtype_code_hash/0.txt b/test/unit/print_cmdtype_code_hash/0.txt deleted file mode 100644 index a040405..0000000 --- a/test/unit/print_cmdtype_code_hash/0.txt +++ /dev/null @@ -1,38 +0,0 @@ -( 0) - SVC 030 #F000 -( 1) - JZE 030 #6300 -( 1) - SLL 010 #5200 -( 2) - SLA 010 #5000 -( 3) - ADDL 011 #2200 -( 3) - NOP 000 #0000 -( 4) - ADDA 011 #2000 -( 7) - OR 020 #3500 -(10) - CALL 030 #8000 -(11) - ADDL 020 #2600 -(12) - ADDA 020 #2400 -(13) - RET 000 #8100 -(14) - SUBL 011 #2300 -(15) - SUBA 011 #2100 -(19) - LAD 010 #1200 -(20) - JMI 030 #6100 -(21) - AND 011 #3000 -(22) - JUMP 030 #6400 -(22) - SUBL 020 #2700 -(23) - CPL 011 #4100 -(23) - SUBA 020 #2500 -(24) - CPA 011 #4000 -(25) - XOR 011 #3200 -(26) - JNZ 030 #6200 -(26) - LD 011 #1000 -(27) - JOV 030 #6600 -(29) - SRL 010 #5300 -(29) - AND 020 #3400 -(29) - ST 010 #1100 -(30) - SRA 010 #5100 -(31) - CPL 020 #4500 -(32) - JPL 030 #6500 -(32) - CPA 020 #4400 -(33) - POP 040 #7100 -(33) - XOR 020 #3600 -(34) - PUSH 030 #7000 -(34) - LD 020 #1400 -(37) - OR 011 #3100 diff --git a/test/unit/print_cmdtype_code_hash/Makefile b/test/unit/print_cmdtype_code_hash/Makefile deleted file mode 100644 index 2b1571f..0000000 --- a/test/unit/print_cmdtype_code_hash/Makefile +++ /dev/null @@ -1,3 +0,0 @@ -UCLASS = COMMON -TESTSRCFILE = ../CERRARRAY.c print_cmdtype_code.c -include ../TEST.mk diff --git a/test/unit/print_cmdtype_code_hash/print_cmdtype_code.c b/test/unit/print_cmdtype_code_hash/print_cmdtype_code.c deleted file mode 100644 index ba26a74..0000000 --- a/test/unit/print_cmdtype_code_hash/print_cmdtype_code.c +++ /dev/null @@ -1,34 +0,0 @@ -#include "casl2.h" - -/* 命令と命令タイプがキーのハッシュ表を表示する */ -void print_cmdtype_code() -{ - int 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->cmd->name, np->cmd->type, np->cmd->code); - np = np->next; - } - } -} - -int main(){ - /* エラーの初期化 */ - cerr = malloc_chk(sizeof(CERR), "cerr"); - /* ハッシュ表作成 */ - create_cmdtype_code(); - /* ハッシュ表表示 */ - print_cmdtype_code(); - /* ハッシュ表解放 */ - free_cmdtype_code(); - /* エラーの表示 */ - if(cerr->num != 0) { - printf("\terror - %d: %s\n", cerr->num, cerr->msg); - freecerr(); - exit(-1); - } - return 0; -} diff --git a/test/unit/print_code_type/0.txt b/test/unit/print_code_type/0.txt deleted file mode 100644 index e34b3c6..0000000 --- a/test/unit/print_code_type/0.txt +++ /dev/null @@ -1,38 +0,0 @@ -#0000 000 NOP -#1000 011 LD -#1100 010 ST -#1200 010 LAD -#1400 020 LD -#2000 011 ADDA -#2100 011 SUBA -#2200 011 ADDL -#2300 011 SUBL -#2400 020 ADDA -#2500 020 SUBA -#2600 020 ADDL -#2700 020 SUBL -#3000 011 AND -#3100 011 OR -#3200 011 XOR -#3400 020 AND -#3500 020 OR -#3600 020 XOR -#4000 011 CPA -#4100 011 CPL -#4400 020 CPA -#4500 020 CPL -#5000 010 SLA -#5100 010 SRA -#5200 010 SLL -#5300 010 SRL -#6100 030 JMI -#6200 030 JNZ -#6300 030 JZE -#6400 030 JUMP -#6500 030 JPL -#6600 030 JOV -#7000 030 PUSH -#7100 040 POP -#8000 030 CALL -#8100 000 RET -#F000 030 SVC diff --git a/test/unit/print_code_type/Makefile b/test/unit/print_code_type/Makefile deleted file mode 100644 index 17eb22a..0000000 --- a/test/unit/print_code_type/Makefile +++ /dev/null @@ -1,3 +0,0 @@ -UCLASS = COMMON -TESTSRCFILE = ../CERRARRAY.c print_code_type.c -include ../TEST.mk diff --git a/test/unit/print_code_type/print_code_type.c b/test/unit/print_code_type/print_code_type.c deleted file mode 100644 index 0a5a312..0000000 --- a/test/unit/print_code_type/print_code_type.c +++ /dev/null @@ -1,46 +0,0 @@ -#include "casl2.h" -#include "cerr.h" - -int compare_code(const void *a, const void *b) -{ - return (**(const CMD **)a).code - (**(const CMD **)b).code; -} - -/* 命令コードがキーのハッシュ表を表示する */ -void print_code_type() -{ - int i, j = 0; - 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->cmd; - np = np->next; - } - } - 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); - } -} - -int main() -{ - /* エラーの初期化 */ - cerr = malloc_chk(sizeof(CERR), "cerr"); - /* ハッシュ表作成 */ - create_code_type(); - /* 命令表表示 */ - print_code_type(); - /* ハッシュ表削除 */ - free_code_type(); - /* エラーの表示 */ - if(cerr->num != 0) { - printf("\terror - %d: %s\n", cerr->num, cerr->msg); - freecerr(); - exit(-1); - } - return 0; -} diff --git a/test/unit/print_code_type_hash/0.txt b/test/unit/print_code_type_hash/0.txt deleted file mode 100644 index 206a466..0000000 --- a/test/unit/print_code_type_hash/0.txt +++ /dev/null @@ -1,38 +0,0 @@ -( 0) - #2600 020 ADDL -( 0) - #0000 000 NOP -( 1) - #2700 020 SUBL -( 4) - #5000 010 SLA -( 5) - #5100 010 SRA -( 6) - #5200 010 SLL -( 7) - #5300 010 SRL -(10) - #3000 011 AND -(11) - #3100 011 OR -(12) - #F000 030 SVC -(12) - #3200 011 XOR -(14) - #8000 030 CALL -(14) - #3400 020 AND -(15) - #8100 000 RET -(15) - #3500 020 OR -(16) - #3600 020 XOR -(16) - #1000 011 LD -(17) - #1100 010 ST -(18) - #1200 010 LAD -(20) - #1400 020 LD -(21) - #6100 030 JMI -(22) - #6200 030 JNZ -(23) - #6300 030 JZE -(24) - #6400 030 JUMP -(25) - #6500 030 JPL -(26) - #6600 030 JOV -(26) - #4000 011 CPA -(27) - #4100 011 CPL -(30) - #4400 020 CPA -(31) - #4500 020 CPL -(32) - #2000 011 ADDA -(33) - #2100 011 SUBA -(34) - #2200 011 ADDL -(35) - #2300 011 SUBL -(36) - #7000 030 PUSH -(36) - #2400 020 ADDA -(37) - #7100 040 POP -(37) - #2500 020 SUBA diff --git a/test/unit/print_code_type_hash/Makefile b/test/unit/print_code_type_hash/Makefile deleted file mode 100644 index 17eb22a..0000000 --- a/test/unit/print_code_type_hash/Makefile +++ /dev/null @@ -1,3 +0,0 @@ -UCLASS = COMMON -TESTSRCFILE = ../CERRARRAY.c print_code_type.c -include ../TEST.mk diff --git a/test/unit/print_code_type_hash/print_code_type.c b/test/unit/print_code_type_hash/print_code_type.c deleted file mode 100644 index 80fea83..0000000 --- a/test/unit/print_code_type_hash/print_code_type.c +++ /dev/null @@ -1,34 +0,0 @@ -#include "casl2.h" -#include "cerr.h" - -/* 命令コードがキーのハッシュ表を表示する */ -void print_code_type() -{ - int i; - 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->cmd->code, np->cmd->type, np->cmd->name); - } - } -} - -int main() -{ - /* エラーの初期化 */ - cerr = malloc_chk(sizeof(CERR), "cerr"); - /* ハッシュ表作成 */ - create_code_type(); - /* ハッシュ表表示 */ - print_code_type(); - /* ハッシュ表解放 */ - free_code_type(); - /* エラーの表示 */ - if(cerr->num != 0) { - printf("\terror - %d: %s\n", cerr->num, cerr->msg); - freecerr(); - exit(-1); - } - return 0; -} diff --git a/test/unit/cerrtest/0.txt b/test/unit/setcerr/0.txt similarity index 100% rename from test/unit/cerrtest/0.txt rename to test/unit/setcerr/0.txt diff --git a/test/unit/setcerr/Makefile b/test/unit/setcerr/Makefile new file mode 100644 index 0000000..88cbf20 --- /dev/null +++ b/test/unit/setcerr/Makefile @@ -0,0 +1,11 @@ +include ../Define.mk +include ../Define_test.mk +include ../Test.mk + +SRCDIR = ../../../src +SRCFILES = $(SRCDIR)/cmem.c $(SRCDIR)/cerr.c + +.INTERMEDIATE: cmd + +cmd: cmd.c $(SRCFILES) + gcc -g -Wall -I ../../../include -o $@ $^ diff --git a/test/unit/cerrtest/cerrtest.c b/test/unit/setcerr/cmd.c similarity index 100% rename from test/unit/cerrtest/cerrtest.c rename to test/unit/setcerr/cmd.c diff --git a/test/unit/setcerr/desc.txt b/test/unit/setcerr/desc.txt new file mode 100644 index 0000000..2435d5b --- /dev/null +++ b/test/unit/setcerr/desc.txt @@ -0,0 +1 @@ +関数setcerrのテスト -- 2.18.0