hello-x86.sh 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #! /bin/sh
  2. ## Copyright (C) 2017 Jeremiah Orians
  3. ## This file is part of M2-Planet.
  4. ##
  5. ## M2-Planet is free software: you can redistribute it and/or modify
  6. ## it under the terms of the GNU General Public License as published by
  7. ## the Free Software Foundation, either version 3 of the License, or
  8. ## (at your option) any later version.
  9. ##
  10. ## M2-Planet is distributed in the hope that it will be useful,
  11. ## but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ## GNU General Public License for more details.
  14. ##
  15. ## You should have received a copy of the GNU General Public License
  16. ## along with M2-Planet. If not, see <http://www.gnu.org/licenses/>.
  17. set -ex
  18. # Build the test
  19. bin/M2-Planet --architecture x86 \
  20. -f test/common_x86/functions/putchar.c \
  21. -f test/common_x86/functions/getchar.c \
  22. -f test/common_x86/functions/exit.c \
  23. -f test/common_x86/functions/malloc.c \
  24. -f test/test0106/cc500.c \
  25. -o test/test0106/cc0.M1 || exit 1
  26. # Macro assemble with libc written in M1-Macro
  27. M1 -f test/common_x86/x86_defs.M1 \
  28. -f test/common_x86/libc-core.M1 \
  29. -f test/test0106/cc0.M1 \
  30. --LittleEndian \
  31. --architecture x86 \
  32. -o test/test0106/cc0.hex2 || exit 2
  33. # Resolve all linkages
  34. hex2 -f test/common_x86/ELF-i386.hex2 -f test/test0106/cc0.hex2 --LittleEndian --architecture x86 --BaseAddress 0x8048000 -o test/results/test0106-x86-binary --exec_enable || exit 3
  35. # Ensure binary works if host machine supports test
  36. if [ "$(get_machine ${GET_MACHINE_FLAGS})" = "x86" ]
  37. then
  38. . ./sha256.sh
  39. # Verify that the compiled program can compile itself
  40. ./test/results/test0106-x86-binary < test/test0106/cc500.c >| test/test0106/cc1 || exit 4
  41. out=$(sha256_check test/test0106/proof0.answer)
  42. [ "$out" = "test/test0106/cc1: OK" ] || exit 5
  43. # Make it executable
  44. chmod u+x test/test0106/cc1
  45. # Verify that the result of it compiling itself can compile itself
  46. ./test/test0106/cc1 < test/test0106/cc500.c >| test/test0106/cc2 || exit 6
  47. out=$(sha256_check test/test0106/proof1.answer)
  48. [ "$out" = "test/test0106/cc2: OK" ] || exit 7
  49. fi
  50. exit 0