From aaa4f9d72ea3184b9902d6871057a20fb75b777b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Tue, 26 Aug 2025 10:26:35 +0200 Subject: [PATCH] Add websocket testing script --- Windows/PPSSPP.vcxproj | 8 ++++ Windows/PPSSPP.vcxproj.filters | 3 ++ scripts/websocket-test.py | 68 ++++++++++++++++++++++++++++++++++ 3 files changed, 79 insertions(+) create mode 100644 scripts/websocket-test.py diff --git a/Windows/PPSSPP.vcxproj b/Windows/PPSSPP.vcxproj index e63b8887c0..1ce49e3ec2 100644 --- a/Windows/PPSSPP.vcxproj +++ b/Windows/PPSSPP.vcxproj @@ -1331,6 +1331,14 @@ + + true + true + true + true + true + true + true true diff --git a/Windows/PPSSPP.vcxproj.filters b/Windows/PPSSPP.vcxproj.filters index 419c774d6c..4455fa8d94 100644 --- a/Windows/PPSSPP.vcxproj.filters +++ b/Windows/PPSSPP.vcxproj.filters @@ -806,6 +806,9 @@ Other Platforms\iOS + + Other Platforms + diff --git a/scripts/websocket-test.py b/scripts/websocket-test.py new file mode 100644 index 0000000000..eee6b8e8f5 --- /dev/null +++ b/scripts/websocket-test.py @@ -0,0 +1,68 @@ +# Initially by Nemoumbra, extended to support more parameters and receive responses by ChatGPT. +# Example usage from the root: +# > python scripts\websocket-test.py 56244 gpu.stats.get +# NOTE: For some reason fails to connect from WSL, this should be investigated. + +import sys +import time +from websocket import WebSocket +from json import dumps + + +def main(): + if len(sys.argv) not in (3, 4): + print(f"Usage: {sys.argv[0]} [wait_secs]") + print("Example commands: gpu.stats.get game.reset game.status (there are more)") + print("Default wait time: 2 seconds") + sys.exit(1) + + # Validate port + try: + port = int(sys.argv[1]) + if not (1 <= port <= 65535): + raise ValueError("Port must be between 1 and 65535") + except ValueError as e: + print(f"Invalid port: {e}") + sys.exit(1) + + cmd = sys.argv[2] + + # Parse wait time (default = 2) + try: + wait_secs = int(sys.argv[3]) if len(sys.argv) == 4 else 2 + if wait_secs < 0: + raise ValueError("Wait time must be non-negative") + except ValueError as e: + print(f"Invalid wait_secs: {e}") + sys.exit(1) + + host = "127.0.0.1" + uri = f"ws://{host}:{port}/debugger" + + ws = WebSocket() + try: + ws.connect(uri) + request = {"event": cmd} + ws.send(dumps(request)) + print(f"Sent {cmd} event to {uri}, listening for {wait_secs} second(s)...") + + ws.settimeout(wait_secs) + start = time.time() + while True: + try: + response = ws.recv() + print("Received response:", response) + except Exception: + # Stop when timeout occurs or no more messages + break + if time.time() - start > wait_secs: + break + + except Exception as e: + print(f"Connection failed: {e}") + finally: + ws.close() + + +if __name__ == "__main__": + main() \ No newline at end of file