Add websocket testing script

This commit is contained in:
Henrik Rydgård 2025-08-26 10:26:35 +02:00
parent 3b3257ad99
commit aaa4f9d72e
3 changed files with 79 additions and 0 deletions

View File

@ -1331,6 +1331,14 @@
<None Include="..\ppsspp.iss" />
<None Include="..\Qt\macbundle.sh" />
<None Include="..\README.md" />
<None Include="..\scripts\websocket-test.py">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
</None>
<None Include="..\SDL\CocoaBarItems.mm">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>

View File

@ -806,6 +806,9 @@
<None Include="..\ios\ViewControllerMetal.mm">
<Filter>Other Platforms\iOS</Filter>
</None>
<None Include="..\scripts\websocket-test.py">
<Filter>Other Platforms</Filter>
</None>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="ppsspp.rc">

68
scripts/websocket-test.py Normal file
View File

@ -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]} <port> <cmd> [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()