hello-knight-posix.sh 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #! /bin/sh
  2. ## Copyright (C) 2017 Jeremiah Orians
  3. ## Copyright (C) 2021 deesix <deesix@tuta.io>
  4. ## This file is part of M2-Planet.
  5. ##
  6. ## M2-Planet is free software: you can redistribute it and/or modify
  7. ## it under the terms of the GNU General Public License as published by
  8. ## the Free Software Foundation, either version 3 of the License, or
  9. ## (at your option) any later version.
  10. ##
  11. ## M2-Planet is distributed in the hope that it will be useful,
  12. ## but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. ## GNU General Public License for more details.
  15. ##
  16. ## You should have received a copy of the GNU General Public License
  17. ## along with M2-Planet. If not, see <http://www.gnu.org/licenses/>.
  18. set -x
  19. TMPDIR="test/test0101/tmp-knight-posix"
  20. mkdir -p ${TMPDIR}
  21. # Build the test
  22. ./bin/M2-Planet \
  23. --architecture knight-posix \
  24. -f test/common_knight/functions/exit.c \
  25. -f test/common_knight/functions/file.c \
  26. -f functions/file_print.c \
  27. -f test/common_knight/functions/malloc.c \
  28. -f functions/calloc.c \
  29. -f functions/match.c \
  30. -f functions/in_set.c \
  31. -f functions/numerate_number.c \
  32. -f test/common_knight/functions/stat.c \
  33. -f test/test0101/hex2_linker.c \
  34. --bootstrap-mode \
  35. -o ${TMPDIR}/hex2_linker.M1 \
  36. || exit 1
  37. # Macro assemble with libc written in M1-Macro
  38. M1 \
  39. -f test/common_knight/knight_defs.M1 \
  40. -f test/common_knight/libc-core.M1 \
  41. -f ${TMPDIR}/hex2_linker.M1 \
  42. --BigEndian \
  43. --architecture knight-posix \
  44. -o ${TMPDIR}/hex2_linker.hex2 \
  45. || exit 3
  46. # Resolve all linkages
  47. hex2 \
  48. -f test/common_knight/ELF-knight.hex2 \
  49. -f ${TMPDIR}/hex2_linker.hex2 \
  50. --BigEndian \
  51. --architecture knight-posix \
  52. --BaseAddress 0x00 \
  53. -o test/results/test0101-knight-posix-binary \
  54. --exec_enable \
  55. || exit 4
  56. # Ensure binary works if host machine supports test
  57. if [ "$(get_machine ${GET_MACHINE_FLAGS})" = "knight*" ]
  58. then
  59. # Verify that the compiled program returns the correct result
  60. out=$(./test/results/test0101-knight-posix-binary --version 2>&1 )
  61. [ 0 = $? ] || exit 5
  62. [ "$out" = "hex2 0.3" ] || exit 6
  63. . ./sha256.sh
  64. # Verify that the resulting file works
  65. ./test/results/test0101-knight-posix-binary -f test/common_x86/ELF-i386.hex2 \
  66. -f test/test0101/test.hex2 \
  67. --LittleEndian \
  68. --architecture x86 \
  69. --BaseAddress 0x8048000 \
  70. -o test/test0101/proof || exit 7
  71. out=$(sha256_check test/test0101/proof.answer)
  72. [ "$out" = "test/test0101/proof: OK" ] || exit 8
  73. fi
  74. exit 0