diff --git a/.gitignore b/.gitignore index 758e4bb..31636ac 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ build/ **/.DS_Store +__pycache__/ diff --git a/tests/integration/README.md b/tests/integration/README.md index d7a6352..69b6181 100644 --- a/tests/integration/README.md +++ b/tests/integration/README.md @@ -26,11 +26,22 @@ GitHub-hosted runners are not a good fit for that combination. - `AMIGAOS32_ISO` can be used as a convenient local fallback image - `ODFS_HANDLER` optionally overrides the handler path - `AMIFUSE` optionally overrides the `amifuse` executable path +- `PYTHON` optionally names the Python interpreter AmiFUSE is installed for (default `python3`) - `AMIFUSE_PARTITION` optionally selects the partition name/index - `AMIFUSE_BLOCK_SIZE` optionally overrides AmiFUSE block size - `AMIFUSE_EXPECT_FILE` optionally overrides the default probe file - `AMIFUSE_EXPECT_CONTENT` optionally overrides the default text probe +## AmiFUSE Version + +The handler waits for its first packet on a message port that causes a +software interrupt (`PA_SOFTINT`). AmiFUSE serves such a port, and has +`Cause()`, when it runs on amitools 0.10 or later. With AmiFUSE 1.0.0 or +older the mounted volume stays empty and the test stops with +`FAIL: mount did not expose ...`. + +The script and its checks themselves run on AmiFUSE 0.6.0 and later. + ## Default Probe Expectations By default the script expects: diff --git a/tests/integration/amifuse_compat.py b/tests/integration/amifuse_compat.py new file mode 100644 index 0000000..200f829 --- /dev/null +++ b/tests/integration/amifuse_compat.py @@ -0,0 +1,28 @@ +# SPDX-License-Identifier: BSD-2-Clause +"""Packets to the handler, for the AmiFUSE versions the checks run on.""" + +ACTION_FINDINPUT = 1005 + + +def do_packet(bridge, action, args, **limits): + """Send a packet and run the handler until it has answered. + + Returns (res1, res2), or None if no answer came. limits are for the + wait of an AmiFUSE up to 1.0. + """ + launcher = bridge.launcher + if not hasattr(launcher, "send_packet"): + # With amitools 0.10 the bridge sends packets through DosPktHandler. + return bridge._packet(action, args, "check") + packet, _ = launcher.send_packet(bridge.state, action, args) + for _, pkt, res1, res2 in bridge._run_until_replies(sleep_base=0.0, **limits): + if pkt == packet: + return res1, res2 + return None + + +def find_input(bridge, dir_lock, name_bptr, fh_addr, **limits): + """ACTION_FINDINPUT for a name under a lock, into the handle at fh_addr.""" + return do_packet( + bridge, ACTION_FINDINPUT, [fh_addr >> 2, dir_lock, name_bptr], **limits + ) diff --git a/tests/integration/check_assign_prefix.py b/tests/integration/check_assign_prefix.py index 4023a16..28053b6 100644 --- a/tests/integration/check_assign_prefix.py +++ b/tests/integration/check_assign_prefix.py @@ -8,6 +8,8 @@ from amifuse.fuse_fs import HandlerBridge from amifuse.rdb_inspect import detect_iso +from amifuse_compat import find_input + def open_via_findinput(bridge: HandlerBridge, dir_path: str, name: str): dir_lock, _, locks = bridge.locate_path(dir_path) @@ -17,14 +19,13 @@ def open_via_findinput(bridge: HandlerBridge, dir_path: str, name: str): try: _, name_bptr = bridge._alloc_bstr(name) fh_addr = bridge._alloc_fh() - bridge.launcher.send_findinput(bridge.state, name_bptr, dir_lock, fh_addr) - replies = bridge._run_until_replies( - max_iters=500, cycles=200_000, sleep_base=0.0 + reply = find_input( + bridge, dir_lock, name_bptr, fh_addr, max_iters=500, cycles=200_000 ) - if not replies: + if reply is None: return False, "no-reply" - if replies[-1][2] == 0: - return False, replies[-1][3] + if reply[0] == 0: + return False, reply[1] bridge.close_file(fh_addr) return True, 0 finally: diff --git a/tests/integration/check_cdda_icon.py b/tests/integration/check_cdda_icon.py index e3071e5..2b355a2 100644 --- a/tests/integration/check_cdda_icon.py +++ b/tests/integration/check_cdda_icon.py @@ -19,6 +19,9 @@ from amifuse.startup_runner import HandlerLauncher from amitools.vamos.lib.DosLibrary import DosLibrary from amitools.vamos.lib.dos.FileHandle import FileHandle +from amitools.vamos.libstructs.dos import DosPacketStruct, MessageStruct + +from amifuse_compat import do_packet ROOT = Path(__file__).resolve().parents[2] @@ -33,7 +36,6 @@ def check(handler: Path, source: str) -> None: original_io = ScsiDevice.BeginIO original_open = DosLibrary.Open original_launch = HandlerLauncher.launch_with_startup - original_poll = HandlerLauncher.poll_replies pending = set() answered = set() lookups = [] @@ -43,6 +45,23 @@ def check(handler: Path, source: str) -> None: def launch_handler(self, *args, **kwargs): state = original_launch(self, *args, **kwargs) launch.update(launcher=self, state=state, process_port=state.port_addr) + # Who takes the replies depends on the AmiFUSE version: the launcher + # up to 1.0, amitools' DosPktHandler after it. Both take them from + # the reply port with the port manager's get_msg(). + ports = self.exec_impl.port_mgr + take = ports.get_msg + + def get_msg(port_addr): + msg = take(port_addr) + if msg and port_addr == state.reply_port_addr: + pkt = MessageStruct(self.mem, msg).node.name.aptr + if pkt in pending: + reply = DosPacketStruct(self.mem, pkt) + if reply.res1.val == -1 and reply.res2.val == 0: + answered.add(pkt) + return msg + + ports.get_msg = get_msg return state def audio_io(self, ctx, io_request): @@ -75,7 +94,11 @@ def open_icon(self, ctx, name_ptr, mode): launcher = launch["launcher"] state = launch["state"] dn = DeviceNodeStruct(ctx.mem, launcher.boot["dn_addr"]) - port = dn.dn_Task.val + try: + port = dn.dn_Task.val + except AttributeError: + # amitools 0.9 names the fields of a DosList entry dol_* + port = dn.dol_Task.aptr pkt, _ = launcher._build_std_packet( port, state.reply_port_addr, ACTION_IS_FILESYSTEM, [] ) @@ -91,15 +114,7 @@ def open_icon(self, ctx, name_ptr, mode): self.file_mgr._register_file(fh) return fh.b_addr - def poll(self, *args, **kwargs): - replies = original_poll(self, *args, **kwargs) - for _, pkt, res1, res2 in replies: - if pkt in pending and res1 == -1 and res2 == 0: - answered.add(pkt) - return replies - with patch.object(HandlerLauncher, "launch_with_startup", launch_handler), \ - patch.object(HandlerLauncher, "poll_replies", poll), \ patch.object(ScsiDevice, "BeginIO", audio_io), \ patch.object(DosLibrary, "Open", open_icon): bridge = HandlerBridge(IMAGE, handler, debug=False, iso_info=detect_iso(IMAGE)) @@ -117,9 +132,8 @@ def poll(self, *args, **kwargs): answered.clear() # Repeat loading after an inhibit/uninhibit cycle. for state in (-1, 0): - bridge.launcher.send_packet(bridge.state, ACTION_INHIBIT, [state]) - replies = bridge._run_until_replies(sleep_base=0.0) - assert replies and replies[0][2] == -1, "inhibit cycle failed" + reply = do_packet(bridge, ACTION_INHIBIT, [state]) + assert reply and reply[0] == -1, "inhibit cycle failed" expected = ["ENV:Sys/def_cdda.info"] if source != "ENV": expected.append("ENVARC:Sys/def_cdda.info") @@ -129,9 +143,8 @@ def poll(self, *args, **kwargs): messages = bridge.vh.slm.exec_impl.msg_func with patch.object(messages, "delete_msg_port", wraps=messages.delete_msg_port) as delete: - bridge.launcher.send_packet(bridge.state, 5, []) # ACTION_DIE - replies = bridge._run_until_replies(sleep_base=0.0) - assert replies and replies[0][2] == -1, "shutdown was not acknowledged" + reply = do_packet(bridge, 5, []) # ACTION_DIE + assert reply and reply[0] == -1, "shutdown was not acknowledged" freed = [call.args[0].addr for call in delete.call_args_list] assert freed.count(bridge.state.port_addr) == 1, "request port leaked" assert launch["process_port"] not in freed, "process port was deleted" diff --git a/tests/integration/check_cdda_toc.py b/tests/integration/check_cdda_toc.py index 0863baa..eac1d1a 100644 --- a/tests/integration/check_cdda_toc.py +++ b/tests/integration/check_cdda_toc.py @@ -11,6 +11,8 @@ from amifuse.rdb_inspect import detect_iso from amifuse.scsi_device import IORequestStruct, SCSICmdStruct, ScsiDevice +from amifuse_compat import do_packet + ROOT = Path(__file__).resolve().parents[2] IMAGE = ROOT / "tests/images/test_plain.iso" @@ -83,10 +85,8 @@ def audio_io(self, ctx, io_request): f"{name}: audio length does not match TOC LBAs" assert int.from_bytes(header[4:8], "little") == data_bytes + 36, \ f"{name}: incorrect RIFF size" - packet, _ = bridge.launcher.send_packet(bridge.state, 5, []) # ACTION_DIE - replies = bridge._run_until_replies(sleep_base=0.0) - assert any(pkt == packet and res1 == -1 and res2 == 0 - for _, pkt, res1, res2 in replies), \ + # ACTION_DIE + assert do_packet(bridge, 5, []) == (-1, 0), \ "shutdown was not acknowledged" print("CDDA raw TOC passed: 804 bytes, 99 tracks, lead-out-derived length") finally: diff --git a/tests/integration/check_fh_packets.py b/tests/integration/check_fh_packets.py index 438f711..7deb95c 100644 --- a/tests/integration/check_fh_packets.py +++ b/tests/integration/check_fh_packets.py @@ -10,6 +10,8 @@ from amifuse.rdb_inspect import detect_iso from amitools.vamos.libstructs.dos import FileInfoBlockStruct, FileLockStruct +from amifuse_compat import do_packet, find_input + ACTION_COPY_DIR_FH = 1030 ACTION_PARENT_FH = 1031 @@ -31,13 +33,10 @@ def fib_name(bridge: HandlerBridge, fib_addr: int) -> str: def send_and_wait(bridge: HandlerBridge, pkt_type: int, args): - bridge.launcher.send_packet(bridge.state, pkt_type, args) - replies = bridge._run_until_replies( - max_iters=500, cycles=200_000, sleep_base=0.0 - ) - if not replies: + reply = do_packet(bridge, pkt_type, args, max_iters=500, cycles=200_000) + if reply is None: return None, "no-reply" - return replies[-1][2], replies[-1][3] + return reply def lock_examined_word(bridge: HandlerBridge, lock_bptr: int) -> int: @@ -70,19 +69,16 @@ def check_candidate( _, name_bptr = bridge._alloc_bstr(leaf) fh_addr = bridge._alloc_fh() - bridge.launcher.send_findinput( - bridge.state, name_bptr, dir_lock, fh_addr - ) - replies = bridge._run_until_replies( - max_iters=500, cycles=200_000, sleep_base=0.0 + reply = find_input( + bridge, dir_lock, name_bptr, fh_addr, max_iters=500, cycles=200_000 ) - if not replies: + if reply is None: print(f"FAIL: FINDINPUT had no reply for {dir_path}/{leaf}") return 1 - if replies[-1][2] == 0: + if reply[0] == 0: print( f"FAIL: FINDINPUT failed for {dir_path}/{leaf} " - f"({replies[-1][3]})" + f"({reply[1]})" ) return 1 fh_opened = True diff --git a/tests/integration/test_amifuse.sh b/tests/integration/test_amifuse.sh index 7b15367..c84ba2a 100755 --- a/tests/integration/test_amifuse.sh +++ b/tests/integration/test_amifuse.sh @@ -6,6 +6,8 @@ set -eu AMIFUSE="${AMIFUSE:-amifuse}" +# the interpreter AmiFUSE is installed for +PYTHON="${PYTHON:-python3}" ODFS_HANDLER="${ODFS_HANDLER:-build/amiga/ODFileSystem}" IMAGE="${AMIFUSE_IMAGE:-${AMIGAOS32_ISO:-}}" PARTITION="${AMIFUSE_PARTITION:-}" @@ -90,7 +92,9 @@ fi mkdir -p "$MOUNTPOINT" CREATED_MOUNTPOINT=1 -set -- "$AMIFUSE" mount "$IMAGE" --driver "$ODFS_HANDLER" --mountpoint "$MOUNTPOINT" +# amifuse detaches after mounting unless told to stay; the wait below +# watches this process +set -- "$AMIFUSE" mount "$IMAGE" --driver "$ODFS_HANDLER" --mountpoint "$MOUNTPOINT" --interactive if [ -n "$PARTITION" ]; then set -- "$@" --partition "$PARTITION" @@ -135,11 +139,17 @@ fi ls "$MOUNTPOINT" >/dev/null -python3 tests/integration/check_assign_prefix.py "$IMAGE" "$ODFS_HANDLER" -python3 tests/integration/check_fh_packets.py "$IMAGE" "$ODFS_HANDLER" -python3 tests/integration/check_cdda_toc.py "$ODFS_HANDLER" +# AmiFUSE 1.0 locks the image while it is mounted, and the checks below +# open it themselves +umount "$MOUNTPOINT" +wait "$AMIFUSE_PID" >/dev/null 2>&1 || true +AMIFUSE_PID="" + +"$PYTHON" tests/integration/check_assign_prefix.py "$IMAGE" "$ODFS_HANDLER" +"$PYTHON" tests/integration/check_fh_packets.py "$IMAGE" "$ODFS_HANDLER" +"$PYTHON" tests/integration/check_cdda_toc.py "$ODFS_HANDLER" for icon_source in ENV ENVARC missing; do - python3 tests/integration/check_cdda_icon.py "$ODFS_HANDLER" "$icon_source" + "$PYTHON" tests/integration/check_cdda_icon.py "$ODFS_HANDLER" "$icon_source" done echo "AmiFUSE integration test passed"