hello-knight-posix.sh 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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 -ex
  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 M2libc/sys/types.h \
  25. -f M2libc/stddef.h \
  26. -f M2libc/sys/utsname.h \
  27. -f M2libc/knight/linux/unistd.c \
  28. -f M2libc/knight/linux/fcntl.c \
  29. -f M2libc/knight/linux/sys/stat.c \
  30. -f M2libc/fcntl.c \
  31. -f M2libc/stdlib.c \
  32. -f M2libc/stdio.h \
  33. -f M2libc/stdio.c \
  34. -f M2libc/bootstrappable.c\
  35. -f test/test0101/hex2_linker.c \
  36. -o ${TMPDIR}/hex2_linker.M1 \
  37. || exit 1
  38. # Macro assemble with libc written in M1-Macro
  39. M1 \
  40. -f M2libc/knight/knight_defs.M1 \
  41. -f M2libc/knight/libc-full.M1 \
  42. -f ${TMPDIR}/hex2_linker.M1 \
  43. --big-endian \
  44. --architecture knight-posix \
  45. -o ${TMPDIR}/hex2_linker.hex2 \
  46. || exit 3
  47. # Resolve all linkages
  48. hex2 \
  49. -f M2libc/knight/ELF-knight.hex2 \
  50. -f ${TMPDIR}/hex2_linker.hex2 \
  51. --big-endian \
  52. --architecture knight-posix \
  53. --base-address 0x00 \
  54. -o test/results/test0101-knight-posix-binary \
  55. || exit 4
  56. # Ensure binary works if host machine supports test
  57. if [ "$(get_machine ${GET_MACHINE_FLAGS})" = "knight" ] && [ ! -z "${KNIGHT_EMULATION}" ]
  58. then
  59. # Verify that the compiled program returns the correct result
  60. execve_image \
  61. ./test/results/test0101-knight-posix-binary \
  62. --version \
  63. >| ${TMPDIR}/image || exit 5
  64. out=$(vm --POSIX-MODE --rom ${TMPDIR}/image --memory 2M)
  65. [ 0 = $? ] || exit 6
  66. [ "$out" = "hex2 0.3" ] || exit 7
  67. . ./sha256.sh
  68. # Verify that the resulting file works
  69. execve_image \
  70. ./test/results/test0101-knight-posix-binary \
  71. -f M2libc/x86/ELF-x86.hex2 \
  72. -f test/test0101/test.hex2 \
  73. --LittleEndian \
  74. --architecture x86 \
  75. --BaseAddress 0x8048000 \
  76. -o test/test0101/proof \
  77. >| ${TMPDIR}/image || exit 8
  78. vm --POSIX-MODE --rom ${TMPDIR}/image --memory 2M || exit 9
  79. out=$(sha256_check test/test0101/proof.answer)
  80. [ "$out" = "test/test0101/proof: OK" ] || exit 10
  81. elif [ "$(get_machine ${GET_MACHINE_FLAGS})" = "knight" ]
  82. then
  83. # Verify that the compiled program returns the correct result
  84. out=$(./test/results/test0101-knight-posix-binary --version 2>&1 )
  85. [ 0 = $? ] || exit 6
  86. [ "$out" = "hex2 0.3" ] || exit 7
  87. . ./sha256.sh
  88. # Verify that the resulting file works
  89. ./test/results/test0101-knight-posix-binary \
  90. -f M2libc/x86/ELF-x86.hex2 \
  91. -f test/test0101/test.hex2 \
  92. --LittleEndian \
  93. --architecture x86 \
  94. --BaseAddress 0x8048000 \
  95. -o test/test0101/proof \
  96. || exit 9
  97. out=$(sha256_check test/test0101/proof.answer)
  98. [ "$out" = "test/test0101/proof: OK" ] || exit 10
  99. fi
  100. exit 0