Add tests for CLI version commands
authorHugo Villeneuve <hugo@hugovil.com>
Tue, 18 Feb 2014 03:58:44 +0000 (22:58 -0500)
committerHugo Villeneuve <hugo@hugovil.com>
Tue, 18 Feb 2014 04:06:51 +0000 (23:06 -0500)
tests/Makefile.am
tests/cmd.sh [new file with mode: 0644]
tests/cmd_de.sh [new file with mode: 0755]
tests/cmd_di.sh [new file with mode: 0755]
tests/cmd_dp.sh [new file with mode: 0755]
tests/cmd_dr.sh [new file with mode: 0755]
tests/cmd_we.sh [new file with mode: 0755]
tests/cmd_wi.sh [new file with mode: 0755]
tests/cmd_wp.sh [new file with mode: 0755]
tests/cmd_wr.sh [new file with mode: 0755]

index 2dbcf9b..d1aa30d 100644 (file)
@@ -19,7 +19,7 @@ ASM_SRC = \
 
 if RUN_TESTS
 
 
 if RUN_TESTS
 
-TESTS = \
+TESTS_ASM = \
     add.sh \
     mul1.sh mul2.sh \
     div.sh div32u.sh \
     add.sh \
     mul1.sh mul2.sh \
     div.sh div32u.sh \
@@ -28,6 +28,24 @@ TESTS = \
     sqroot.sh \
     timer0.sh timer1.sh timer2.sh
 
     sqroot.sh \
     timer0.sh timer1.sh timer2.sh
 
+TESTS_CMD = \
+    cmd_dr.sh \
+    cmd_de.sh \
+    cmd_di.sh \
+    cmd_dp.sh \
+    cmd_we.sh \
+    cmd_wi.sh \
+    cmd_wp.sh \
+    cmd_wr.sh
+
+TESTS = \
+    $(TESTS_CMD) \
+    $(TESTS_ASM)
+
+# If you do not want an implicit rule to be used for a target that has no
+# commands, you can give that target empty commands by writing a semicolon.
+cli.sh: ;
+
 # Tell make how to generate a .sh file after a .hex file is generated:
 .hex.sh:
        @ln -sf $(srcdir)/opcodes.sh $@
 # Tell make how to generate a .sh file after a .hex file is generated:
 .hex.sh:
        @ln -sf $(srcdir)/opcodes.sh $@
@@ -54,8 +72,8 @@ else
 TESTS =
 endif
 
 TESTS =
 endif
 
-EXTRA_DIST = opcodes.sh $(ASM_SRC)
+EXTRA_DIST = $(TESTS_CMD) cmd.sh opcodes.sh $(ASM_SRC)
 
 
-CLEANFILES = *~ *.lst *.hex $(TESTS)
+CLEANFILES = *~ *.lst *.hex $(TESTS_ASM)
 
 MAINTAINERCLEANFILES = Makefile.in
 
 MAINTAINERCLEANFILES = Makefile.in
diff --git a/tests/cmd.sh b/tests/cmd.sh
new file mode 100644 (file)
index 0000000..02cc242
--- /dev/null
@@ -0,0 +1,29 @@
+#!/bin/sh
+
+# Get the symlink name (how we were called):
+test_name=`basename $0`
+
+lf=${test_name}.log
+
+name=$(basename ${test_name} .sh)
+
+echo "Testing command ${CMD_NAME}" > ${lf}
+
+echo "${CMD}" | ../src/cli/emu8051-cli -d 2 >> ${lf}
+if test $? -ne 0 ; then
+    return 1
+fi
+
+# Verify syntax errors
+if grep -q "syntax" ${lf}; then
+    echo "Failed test: ${CMD_NAME} (syntax error)" >> ${lf}
+    exit 1
+fi
+
+# Verify for valid test values
+if ! grep -q "${TEST_OUTPUT}" ${lf}; then
+    echo "Failed test: ${CMD_NAME} (values not found)" >> ${lf}
+    exit 1
+fi
+
+exit 0
diff --git a/tests/cmd_de.sh b/tests/cmd_de.sh
new file mode 100755 (executable)
index 0000000..3a36687
--- /dev/null
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+CMD_NAME="de"
+CMD=$'de 0x00 16\x0a'
+TEST_OUTPUT="0000  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................"
+
+. $srcdir/cmd.sh
diff --git a/tests/cmd_di.sh b/tests/cmd_di.sh
new file mode 100755 (executable)
index 0000000..933e83d
--- /dev/null
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+CMD_NAME="di"
+CMD=$'di 0x80 16\x0a'
+TEST_OUTPUT="0080  FF 07 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................"
+
+. $srcdir/cmd.sh
diff --git a/tests/cmd_dp.sh b/tests/cmd_dp.sh
new file mode 100755 (executable)
index 0000000..6d067ab
--- /dev/null
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+CMD_NAME="dp"
+CMD=$'dp 0x00 16\x0a'
+TEST_OUTPUT="0000  00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................"
+
+. $srcdir/cmd.sh
diff --git a/tests/cmd_dr.sh b/tests/cmd_dr.sh
new file mode 100755 (executable)
index 0000000..1d3c951
--- /dev/null
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+CMD_NAME="dr"
+CMD=$'dr\x0a'
+TEST_OUTPUT="| 0000 | 07 |"
+
+. $srcdir/cmd.sh
diff --git a/tests/cmd_we.sh b/tests/cmd_we.sh
new file mode 100755 (executable)
index 0000000..2580329
--- /dev/null
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+CMD_NAME="we"
+CMD=$'we 0x80 0x30\x0a we 0x81 0x31\x0a we 0x82 0x32\x0a de 0x80 16'
+TEST_OUTPUT="0080  30 31 32 00 00 00 00 00 00 00 00 00 00 00 00 00  012............."
+
+. $srcdir/cmd.sh
diff --git a/tests/cmd_wi.sh b/tests/cmd_wi.sh
new file mode 100755 (executable)
index 0000000..a68fed1
--- /dev/null
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+CMD_NAME="wi"
+CMD=$'wi 0x40 0x30\x0a wi 0x41 0x31\x0a wi 0x42 0x32\x0a di 0x40 16'
+TEST_OUTPUT="0040  30 31 32 00 00 00 00 00 00 00 00 00 00 00 00 00  012............."
+
+. $srcdir/cmd.sh
diff --git a/tests/cmd_wp.sh b/tests/cmd_wp.sh
new file mode 100755 (executable)
index 0000000..ca6347b
--- /dev/null
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+CMD_NAME="wp"
+CMD=$'wp 0x1000 0x41\x0a wp 0x1001 0x42\x0a wp 0x1002 0x43\x0a dp 0x1000 16'
+TEST_OUTPUT="1000  41 42 43 00 00 00 00 00 00 00 00 00 00 00 00 00  ABC............."
+
+. $srcdir/cmd.sh
diff --git a/tests/cmd_wr.sh b/tests/cmd_wr.sh
new file mode 100755 (executable)
index 0000000..96f6011
--- /dev/null
@@ -0,0 +1,7 @@
+#!/bin/sh
+
+CMD_NAME="wr"
+CMD=$'wr pc 0x5555 \x0a dr \x0a'
+TEST_OUTPUT="| 5555 | 07 |"
+
+. $srcdir/cmd.sh