M2-Planet/test/test100/hello-knight-posix.sh

152 lines
4.2 KiB
Bash
Raw Normal View History

2018-02-24 02:18:23 +00:00
#! /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/>.
2018-02-24 02:18:23 +00:00
set -ex
# Build the test
2018-06-22 02:33:50 +01:00
if [ -f bin/M2-Planet ]
then
2019-03-09 16:56:16 +00:00
./bin/M2-Planet --architecture knight-posix \
-f test/common_knight/functions/file.c \
-f test/common_knight/functions/malloc.c \
2018-08-21 01:41:37 +01:00
-f functions/calloc.c \
2019-03-09 16:56:16 +00:00
-f test/common_knight/functions/exit.c \
2018-08-21 01:41:37 +01:00
-f functions/match.c \
-f functions/in_set.c \
2018-08-21 01:41:37 +01:00
-f functions/numerate_number.c \
-f functions/file_print.c \
2019-02-24 22:46:05 +00:00
-f functions/number_pack.c \
2018-08-21 01:41:37 +01:00
-f functions/string.c \
2018-06-22 02:33:50 +01:00
-f cc.h \
-f cc_reader.c \
-f cc_strings.c \
-f cc_types.c \
-f cc_core.c \
-f cc.c \
2018-08-26 21:34:31 +01:00
--debug \
2018-06-22 02:33:50 +01:00
-o test/test100/cc.M1 || exit 1
elif [ -f bin/M2-Planet-seed ]
then
2019-03-09 16:56:16 +00:00
[ ! -f test/results ] && mkdir -p test/results
./bin/M2-Planet-seed -f test/common_knight/functions/file.c \
-f test/common_knight/functions/malloc.c \
-f functions/calloc.c \
2019-03-09 16:56:16 +00:00
-f test/common_knight/functions/exit.c \
-f functions/match.c \
-f functions/in_set.c \
-f functions/numerate_number.c \
-f functions/file_print.c \
2019-02-24 22:46:05 +00:00
-f functions/number_pack.c \
-f functions/string.c \
-f cc.h \
-f cc_reader.c \
-f cc_strings.c \
-f cc_types.c \
-f cc_core.c \
-f cc.c \
--debug \
-o test/test100/cc.M1 || exit 1
2018-06-22 02:33:50 +01:00
else
[ -z "${CC+x}" ] && export CC=gcc
[ -z "${CFLAGS+x}" ] && export CFLAGS=" -D_GNU_SOURCE -O0 -std=c99 -ggdb"
${CC} ${CFLAGS} \
functions/match.c \
functions/in_set.c \
functions/numerate_number.c \
functions/file_print.c \
2019-02-24 22:46:05 +00:00
functions/number_pack.c \
functions/string.c \
cc_reader.c \
cc_strings.c \
cc_types.c \
cc_core.c \
cc.c \
cc.h \
gcc_req.h \
-o bin/M2-Planet-gcc
2019-03-09 16:56:16 +00:00
./bin/M2-Planet-gcc --architecture knight-posix \
-f test/common_knight/functions/file.c \
-f test/common_knight/functions/malloc.c \
2018-08-21 01:41:37 +01:00
-f functions/calloc.c \
2019-03-09 16:56:16 +00:00
-f test/common_knight/functions/exit.c \
2018-08-21 01:41:37 +01:00
-f functions/match.c \
-f functions/in_set.c \
2018-08-21 01:41:37 +01:00
-f functions/numerate_number.c \
-f functions/file_print.c \
2019-02-24 22:46:05 +00:00
-f functions/number_pack.c \
2018-08-21 01:41:37 +01:00
-f functions/string.c \
2018-02-24 02:18:23 +00:00
-f cc.h \
-f cc_reader.c \
-f cc_strings.c \
-f cc_types.c \
-f cc_core.c \
-f cc.c \
2018-08-26 21:34:31 +01:00
--debug \
2018-02-24 02:18:23 +00:00
-o test/test100/cc.M1 || exit 1
2018-06-22 02:33:50 +01:00
fi
2018-02-24 02:18:23 +00:00
# Macro assemble with libc written in M1-Macro
2019-03-09 16:56:16 +00:00
M1 -f test/common_knight/knight_defs.M1 \
-f test/common_knight/libc-core.M1 \
2018-02-24 02:18:23 +00:00
-f test/test100/cc.M1 \
2019-03-09 16:56:16 +00:00
--BigEndian \
--architecture knight-posix \
2018-08-26 21:34:31 +01:00
-o test/test100/cc.hex2 || exit 3
2018-02-24 02:18:23 +00:00
# Resolve all linkages
2019-03-09 16:56:16 +00:00
hex2 -f test/common_knight/ELF-knight.hex2 \
2018-08-26 21:34:31 +01:00
-f test/test100/cc.hex2 \
2019-03-09 16:56:16 +00:00
--BigEndian \
--architecture knight-posix \
--BaseAddress 0x00 \
-o test/results/test100-knight-posix-binary --exec_enable || exit 4
2018-02-24 02:18:23 +00:00
# Ensure binary works if host machine supports test
2019-03-09 16:56:16 +00:00
if [ "$(get_machine ${GET_MACHINE_FLAGS})" = "knight*" ]
2018-02-24 02:18:23 +00:00
then
# Verify that the resulting file works
2019-03-09 16:56:16 +00:00
./test/results/test100-knight-posix-binary --architecture x86 \
-f test/common_x86/functions/file.c \
2019-02-24 22:46:05 +00:00
-f test/common_x86/functions/malloc.c \
2018-08-21 01:41:37 +01:00
-f functions/calloc.c \
2019-02-24 01:18:53 +00:00
-f test/common_x86/functions/exit.c \
2018-08-21 01:41:37 +01:00
-f functions/match.c \
-f functions/in_set.c \
2018-08-21 01:41:37 +01:00
-f functions/numerate_number.c \
-f functions/file_print.c \
2019-02-24 22:46:05 +00:00
-f functions/number_pack.c \
2018-08-21 01:41:37 +01:00
-f functions/string.c \
2018-02-24 02:18:23 +00:00
-f cc.h \
-f cc_reader.c \
-f cc_strings.c \
-f cc_types.c \
-f cc_core.c \
-f cc.c \
2018-08-26 21:34:31 +01:00
-o test/test100/proof || exit 5
2018-02-24 02:18:23 +00:00
out=$(sha256sum -c test/test100/proof.answer)
2018-08-26 21:34:31 +01:00
[ "$out" = "test/test100/proof: OK" ] || exit 6
2019-03-09 16:56:16 +00:00
[ ! -e bin/M2-Planet ] && mv test/results/test100-knight-posix-binary bin/M2-Planet
2018-02-24 02:18:23 +00:00
else
[ -e bin/M2-Planet-gcc ] && cp bin/M2-Planet-gcc bin/M2-Planet
# Seeds only exist if you can build natively
2019-03-09 16:56:16 +00:00
[ -e bin/M2-Planet-seed ] && cp test/results/test100-knight-posix-binary bin/M2-Planet
2018-02-24 02:18:23 +00:00
fi
exit 0