~oriansj/M2-Planet

6cb48f31cfb47e65fe334d3973cd19b5ecc68039 — Jeremiah Orians 3 months ago 6b27d94
Refinements to switch tests
6 files changed, 104 insertions(+), 78 deletions(-)

M makefile-tests
M test/test.answers
D test/test0031/hello-knight-native.sh
M test/test0031/hello-knight-posix.sh
M test/test0031/run_test.sh
M test/test0031/switch.c
M makefile-tests => makefile-tests +0 -4
@@ 165,7 165,6 @@ knight-native-tests: \
	test0024-knight-native-binary\
	test0028-knight-native-binary\
	test0030-knight-native-binary\
	test0031-knight-native-binary\
	test0106-knight-native-binary | results

armv7l-tests: \


@@ 981,9 980,6 @@ test0028-knight-native-binary: M2-Planet | results
test0030-knight-native-binary: M2-Planet | results
	test/test0030/hello-knight-native.sh

test0031-knight-native-binary: M2-Planet | results
	test/test0031/hello-knight-native.sh

test0106-knight-native-binary: M2-Planet | results
	test/test0106/hello-knight-native.sh


M test/test.answers => test/test.answers +7 -8
@@ 232,14 232,13 @@ fed413508d1298d8b7a215fc4369b3890c55a436c23aa23ff7485db7fb459bb3  test/results/t
05c7fff4736996014dbe1c10864a3f908591f664433c1b11678655f832c3e054  test/results/test0030-riscv32-binary
af8682b8250efb2d23341cde5c4336052dba8268b4748cf553329fe2d7427e51  test/results/test0030-riscv64-binary
00c9c1d8f53e7444fdff62ea8764eacc59d23b11c5c7239b9ce2f69e6d23453b  test/results/test0030-x86-binary
106768554e0aea11eb3f2ec021b104bad9a4846890a1a76b33eebd5901b94a41  test/results/test0031-aarch64-binary
c9dd7f796f344ce7e0cd5dd32b991d1055a26fc1893b3cf683cf85ab701b0948  test/results/test0031-amd64-binary
9f76e39b23e38d5dbe64297e76f0b551428b5cbf363784a5fc2e1c7e231b45af  test/results/test0031-armv7l-binary
47db0de953b0a4af6e74896626c4cb1191a57445b241dee372f3015777c91373  test/results/test0031-knight-native-binary
62d906dcd06e1629dc011721446f5ce34a46f52bf50cff98b5f4d19b81692c33  test/results/test0031-knight-posix-binary
b299207032b29795b821552828c5c448613a4d7f93ef237477f9138cfc6da899  test/results/test0031-riscv32-binary
1f819f11d990e9354c033d0a059bfbb6ff06e2a4ceb92c756b83abb65f355277  test/results/test0031-riscv64-binary
ad7e561f1de43e4b5215e9d72cf40f9024efbb5e66139b612519285c1b8f9e2d  test/results/test0031-x86-binary
46270c34f86f4a591bc949af47a2b7b8c6096dfc70a06b28a64dc420fd980865  test/results/test0031-aarch64-binary
88f148df5eac71730ddf2ea02eebf4b461f32088ace5b4399e281f967466e735  test/results/test0031-amd64-binary
4f65b9c088a571127e601a8911c9ca22a99afb3a6fd73c6bec4e74a269655c07  test/results/test0031-armv7l-binary
ddd8ebeafdd020001d818387f2124707c9b4b7f69281e3d076d8211a54f4ff78  test/results/test0031-knight-posix-binary
6925df5191c9b347450f6b0d1a31b1a18ecd0764e0c40a33fe5bfbabe2348dd8  test/results/test0031-riscv32-binary
cad29eb52659762b97ee47811dba81e7cf2af3860a06865565cf8906778d0adf  test/results/test0031-riscv64-binary
665bff272efd5f1f473b9e49ef454ab940291f144152434969fc9c7c6526aebf  test/results/test0031-x86-binary
beb67fe013999035dfd85d863d69ee8065a133ce00c6e1e3e1eb49ee36c7f6d7  test/results/test0100-aarch64-binary
879b107b7b636627d54c1a2667b20b2ad9208d14a205b848bca8c3b391c14eb8  test/results/test0100-amd64-binary
2cc0d8878e14e4061e2dd295226b4cf283d600f1b4e2ae058786f7e8c9c75911  test/results/test0100-armv7l-binary

D test/test0031/hello-knight-native.sh => test/test0031/hello-knight-native.sh +0 -56
@@ 1,56 0,0 @@
#! /bin/sh
## Copyright (C) 2017 Jeremiah Orians
## This file is part of M2-Planet.
##
## M2-Planet is free software: you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
##
## M2-Planet is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with M2-Planet.  If not, see <http://www.gnu.org/licenses/>.

set -x

TMPDIR="test/test0031/tmp-knight-native"
mkdir -p ${TMPDIR}

# Build the test
bin/M2-Planet \
	--architecture knight-native \
	-f test/test0031/switch.c \
	-o ${TMPDIR}/switch.M1 \
	|| exit 1

# Macro assemble with libc written in M1-Macro
M1 \
	-f M2libc/knight/knight-native_defs.M1 \
	-f M2libc/knight/libc-native.M1 \
	-f ${TMPDIR}/switch.M1 \
	--big-endian \
	--architecture knight-native \
	-o ${TMPDIR}/switch.hex2 \
	|| exit 2

# Resolve all linkages
hex2 \
	-f ${TMPDIR}/switch.hex2 \
	--big-endian \
	--architecture knight-native \
	--base-address 0x0 \
	-o test/results/test0031-knight-native-binary \
	|| exit 3

# Ensure binary works if host machine supports test
if [ "$(get_machine ${GET_MACHINE_FLAGS})" = "knight-native" ]
then
	# Verify that the compiled program returns the correct result
	vm --rom ./test/results/test0031-knight-native-binary
	[ 42 = $? ] || exit 4
fi
exit 0

M test/test0031/hello-knight-posix.sh => test/test0031/hello-knight-posix.sh +10 -0
@@ 23,6 23,16 @@ mkdir -p ${TMPDIR}
# Build the test
bin/M2-Planet \
	--architecture knight-posix \
	-f M2libc/sys/types.h \
	-f M2libc/stddef.h \
	-f M2libc/knight/linux/unistd.c \
	-f M2libc/knight/linux/fcntl.c \
	-f M2libc/knight/linux/sys/stat.c \
	-f M2libc/fcntl.c \
	-f M2libc/stdlib.c \
	-f M2libc/stdio.h \
	-f M2libc/stdio.c \
	-f M2libc/bootstrappable.c\
	-f test/test0031/switch.c \
	-o ${TMPDIR}/switch.M1 \
	|| exit 1

M test/test0031/run_test.sh => test/test0031/run_test.sh +34 -2
@@ 27,6 27,16 @@ mkdir -p ${TMPDIR}
bin/M2-Planet \
	--architecture ${ARCH} \
	--debug \
	-f M2libc/sys/types.h \
	-f M2libc/stddef.h \
	-f M2libc/signal.h \
	-f M2libc/${ARCH}/linux/unistd.c \
	-f M2libc/${ARCH}/linux/fcntl.c \
	-f M2libc/fcntl.c \
	-f M2libc/stdlib.c \
	-f M2libc/stdio.h \
	-f M2libc/stdio.c \
	-f M2libc/bootstrappable.c \
	-f test/test0031/switch.c \
	-o ${TMPDIR}/switch.M1 \
	|| exit 1


@@ 64,8 74,30 @@ hex2 \
# Ensure binary works if host machine supports test
if [ "$(get_machine ${GET_MACHINE_FLAGS})" = "${ARCH}" ]
then
	# Verify that the resulting file works
	# Verify that the resulting file works first default case
	./test/results/test0031-${ARCH}-binary
	[ 42 = $? ] || exit 4
	[ 111 = $? ] || exit 4

	./test/results/test0031-${ARCH}-binary test1
	[ 122 = $? ] || exit 4

	./test/results/test0031-${ARCH}-binary test2
	[ 31 = $? ] || exit 4

	./test/results/test0031-${ARCH}-binary test3
	[ 43 = $? ] || exit 4

	./test/results/test0031-${ARCH}-binary test4
	[ 155 = $? ] || exit 4

	./test/results/test0031-${ARCH}-binary test5
	[ 133 = $? ] || exit 4

	./test/results/test0031-${ARCH}-binary test6
	[ 84 = $? ] || exit 4

	./test/results/test0031-${ARCH}-binary test7
	[ 151 = $? ] || exit 4

fi
exit 0

M test/test0031/switch.c => test/test0031/switch.c +53 -8
@@ 15,20 15,65 @@
 * along with M2-Planet.  If not, see <http://www.gnu.org/licenses/>.
 */

int match(char* a, char* b);


int main()
int main(int argc, char** argv)
{
	char* a = argv[1];
	int b = 0;

	if(match("test1", a))
	{
		b = 1;
	}
	else if(match("test2", a))
	{
		b = 3;
	}
	else if(match("test3", a))
	{
		b = 4;
	}
	else if(match("test4", a))
	{
		b = 6;
	}
	else if(match("test5", a))
	{
		b = 9;
	}
	else if(match("test6", a))
	{
		b = 8;
	}
	else if(match("test7", a))
	{
		b = 7;
	}

	int i = 31;
	switch(i)
	switch(b)
	{
		case 0: return 11;
		case 0: return 111;
		case 1:
		case 2: return 22;
		case 2: return 122;
		case 3: break;
		case 31: i = 42;
		         break;
		default: return 55;
		case 4: i = 42;
		case 5: i = i + 1;
		        break;
		case 7: i = i + 2;
		case 8: i = i + 1;
		case 9:
			switch(i)
			{
				case 31: return 133;
				case 32: i = 77;
				case 33: break;
				default: i = 144;
			}
			i = i + 7;
			break;
		default: return 155;
	}

	return i;