From db30b8eacce34d6fc901f50982acade589eecd04 Mon Sep 17 00:00:00 2001 From: lonkaars Date: Fri, 3 Feb 2023 18:46:44 +0100 Subject: add makefile for bin tests --- test/bin/.gitignore | 1 + test/bin/bs.m4 | 19 +++++++++++++++++++ test/bin/example.bs | 9 +++++++++ test/bin/makefile | 13 +++++++++++++ test/bin/readme.md | 19 +++++++++++++++++++ 5 files changed, 61 insertions(+) create mode 100644 test/bin/.gitignore create mode 100644 test/bin/bs.m4 create mode 100644 test/bin/example.bs create mode 100644 test/bin/makefile create mode 100644 test/bin/readme.md diff --git a/test/bin/.gitignore b/test/bin/.gitignore new file mode 100644 index 0000000..a8a0dce --- /dev/null +++ b/test/bin/.gitignore @@ -0,0 +1 @@ +*.bin diff --git a/test/bin/bs.m4 b/test/bin/bs.m4 new file mode 100644 index 0000000..4312cc0 --- /dev/null +++ b/test/bin/bs.m4 @@ -0,0 +1,19 @@ +dnl library functions +define(`forloop',`pushdef(`$1',$2)_forloop(`$1',$2,$3,`$4')popdef(`$1')')dnl +define(`_forloop',`$4`'ifelse($1,$3,`',`define(`$1',incr($1))_forloop(`$1',$2,$3,`$4')')')dnl +define(`repeat',`forloop(`i',1,verbose_hex($1),`$2 ')')dnl +define(`hexc2dec',`eval(10 + translit(`$1',`a-f',`0-5'))')dnl +define(`hex2dec',`patsubst(translit(`$1',`A-F',`a-f'),`\([a-z]\)',`hexc2dec(\1)')')dnl +define(`_hex',`ifelse(len($2),0,$3,`_hex(incr($1),substr($2,0,decr(len($2))),eval($3 + (hex2dec(substr($2,decr(len($2)))) * (16 ** $1))))')')dnl +define(`verbose_hex',`patsubst(`$1',`\(0x\)\([0-9a-fA-F]*\)',`hex(\2)')')dnl +define(`hex',`_hex(0,patsubst(`$1',`0x',`'),`0')')dnl +dnl +dnl main +define(`INPUT',`include(`/dev/stdin')')dnl +define(`NOCOMMENTS',`patsubst(`$1', `;.*', `')')dnl +define(`ONELINE',`patsubst(`$1', `[ \t +]', `')')dnl +define(`BYTES',`patsubst(`$1',`\(..\)',`\1 +')')dnl +define(`OUTPUT',`BYTES(ONELINE(NOCOMMENTS($1)))')dnl +OUTPUT(INPUT())dnl diff --git a/test/bin/example.bs b/test/bin/example.bs new file mode 100644 index 0000000..ce5f292 --- /dev/null +++ b/test/bin/example.bs @@ -0,0 +1,9 @@ +00 00 00 00 ; this is an example binary source file +repeat(5,8f) ; 5 0x8f bytes +repeat(hex(a),bb) ; 10 0xbb bytes +repeat(0x40,00) ; 64 0x00 bytes +; ^ 0x prefix works too +ff ; single byte +00000000 ; 32-bit number +; ^ this is the comment character + diff --git a/test/bin/makefile b/test/bin/makefile new file mode 100644 index 0000000..736f51b --- /dev/null +++ b/test/bin/makefile @@ -0,0 +1,13 @@ +SRCS := $(wildcard *.bs) +TARGETS := $(patsubst %.bs,%.bin, $(SRCS)) + +.PHONY: all clean + +all: $(TARGETS) + +%.bin: %.bs + m4 bs.m4 < $< | xxd -r -p > $@ + +clean: + $(RM) $(TARGETS) + diff --git a/test/bin/readme.md b/test/bin/readme.md new file mode 100644 index 0000000..2c80382 --- /dev/null +++ b/test/bin/readme.md @@ -0,0 +1,19 @@ +# binary tests + +this folder contains binary source (.bs) files, that can be converted to .bin +files using the provided makefile. these files can contain comments, and are +processed using `m4` and `xxd`. + +example syntax: +``` +00 00 00 00 ; this is an example binary source file +repeat(5,8f) ; 5 0x8f bytes +repeat(hex(a),bb) ; 10 0xbb bytes +repeat(0x40,00) ; 64 0x00 bytes +; ^ 0x prefix works too +ff ; single byte +00000000 ; 32-bit number +; ^ this is the comment character +``` + +if compilation hangs, you probably broke the syntax -- cgit v1.2.3