74 lines
3.2 KiB
CMake
74 lines
3.2 KiB
CMake
# End-to-end check of the packer, at the CLI level: assemble a tape, pack it,
|
|
# then run the *file* both ways and require identical output. The in-process
|
|
# test (r8forge_tape_pack_test) covers the codec and the bracket strategies; this
|
|
# one covers the two programs a person actually runs, including the image format
|
|
# and its trailer.
|
|
#
|
|
# cmake -DR8FORGE=... -DPACK=... -DRUN=... -DSOURCE=... -DWORK=... -P pack_roundtrip.cmake
|
|
foreach(var R8FORGE PACK RUN SOURCE WORK)
|
|
if(NOT DEFINED ${var})
|
|
message(FATAL_ERROR "pack_roundtrip.cmake needs -D${var}=...")
|
|
endif()
|
|
endforeach()
|
|
|
|
execute_process(COMMAND ${R8FORGE} ${SOURCE} OUTPUT_VARIABLE text
|
|
RESULT_VARIABLE rc)
|
|
if(NOT rc STREQUAL "0")
|
|
message(FATAL_ERROR "assembling ${SOURCE} failed: ${rc}")
|
|
endif()
|
|
string(LENGTH "${text}" length)
|
|
file(WRITE ${WORK}/pack_roundtrip.rot8 "${text}")
|
|
|
|
execute_process(COMMAND ${PACK} ${WORK}/pack_roundtrip.rot8
|
|
-o ${WORK}/pack_roundtrip.r8t --verify
|
|
OUTPUT_VARIABLE packed RESULT_VARIABLE rc)
|
|
if(NOT rc STREQUAL "0")
|
|
message(FATAL_ERROR "packing failed: ${rc} ${packed}")
|
|
endif()
|
|
message(STATUS "${packed}")
|
|
|
|
foreach(flags "" "--loop-stack" "--retest" "--loop-stack --retest")
|
|
separate_arguments(flag_list UNIX_COMMAND "${flags}")
|
|
execute_process(COMMAND ${RUN} ${WORK}/pack_roundtrip.rot8 ${flag_list}
|
|
OUTPUT_VARIABLE from_text RESULT_VARIABLE rc)
|
|
if(NOT rc STREQUAL "0")
|
|
message(FATAL_ERROR "text run failed (${flags}): ${rc}")
|
|
endif()
|
|
execute_process(COMMAND ${RUN} ${WORK}/pack_roundtrip.r8t ${flag_list}
|
|
OUTPUT_VARIABLE from_image RESULT_VARIABLE rc)
|
|
if(NOT rc STREQUAL "0")
|
|
message(FATAL_ERROR "packed run failed (${flags}): ${rc}")
|
|
endif()
|
|
if(NOT from_image STREQUAL from_text)
|
|
message(FATAL_ERROR
|
|
"packed image prints something else (${flags})\n"
|
|
" text: ${from_text}\n image: ${from_image}")
|
|
endif()
|
|
string(REGEX MATCH "\\(([0-9]+) steps" _ "${from_text}")
|
|
message(STATUS "${length} instructions, ${from_image}")
|
|
endforeach()
|
|
|
|
# The ROM layout must also round-trip through the CLI.
|
|
execute_process(COMMAND ${PACK} ${WORK}/pack_roundtrip.rot8
|
|
-o ${WORK}/pack_roundtrip_eprom.r8t --eprom --verify
|
|
RESULT_VARIABLE rc)
|
|
if(NOT rc STREQUAL "0")
|
|
message(FATAL_ERROR "EPROM packing failed: ${rc}")
|
|
endif()
|
|
execute_process(COMMAND ${RUN} ${WORK}/pack_roundtrip_eprom.r8t --loop-stack --retest
|
|
OUTPUT_VARIABLE from_eprom RESULT_VARIABLE rc)
|
|
if(NOT rc STREQUAL "0" OR NOT from_eprom STREQUAL from_text)
|
|
message(FATAL_ERROR "EPROM image differs from the text tape: ${rc} ${from_eprom}")
|
|
endif()
|
|
|
|
foreach(argument "--not-a-real-option" "x=1" "0=2x" "0=4294967296")
|
|
execute_process(COMMAND ${RUN} ${WORK}/pack_roundtrip.rot8 "${argument}"
|
|
OUTPUT_VARIABLE out ERROR_VARIABLE diagnostic RESULT_VARIABLE rc)
|
|
if(NOT rc STREQUAL "2" OR diagnostic STREQUAL "" OR NOT out STREQUAL "")
|
|
message(FATAL_ERROR "invalid argument did not produce a usage error: ${argument}")
|
|
endif()
|
|
endforeach()
|
|
|
|
# Image damage (flipped bit, missing trailer, nonsense geometry) is covered by
|
|
# r8forge_tape_pack_test, which can corrupt a vector without touching files.
|