Skip to content

Commit aaa4f9d

Browse files
committed
Add websocket testing script
1 parent 3b3257a commit aaa4f9d

File tree

3 files changed

+79
-0
lines changed

3 files changed

+79
-0
lines changed

Windows/PPSSPP.vcxproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1331,6 +1331,14 @@
13311331
<None Include="..\ppsspp.iss" />
13321332
<None Include="..\Qt\macbundle.sh" />
13331333
<None Include="..\README.md" />
1334+
<None Include="..\scripts\websocket-test.py">
1335+
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
1336+
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>
1337+
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|ARM64'">true</ExcludedFromBuild>
1338+
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|ARM64'">true</ExcludedFromBuild>
1339+
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">true</ExcludedFromBuild>
1340+
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|x64'">true</ExcludedFromBuild>
1341+
</None>
13341342
<None Include="..\SDL\CocoaBarItems.mm">
13351343
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">true</ExcludedFromBuild>
13361344
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">true</ExcludedFromBuild>

Windows/PPSSPP.vcxproj.filters

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -806,6 +806,9 @@
806806
<None Include="..\ios\ViewControllerMetal.mm">
807807
<Filter>Other Platforms\iOS</Filter>
808808
</None>
809+
<None Include="..\scripts\websocket-test.py">
810+
<Filter>Other Platforms</Filter>
811+
</None>
809812
</ItemGroup>
810813
<ItemGroup>
811814
<ResourceCompile Include="ppsspp.rc">

scripts/websocket-test.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Initially by Nemoumbra, extended to support more parameters and receive responses by ChatGPT.
2+
# Example usage from the root:
3+
# > python scripts\websocket-test.py 56244 gpu.stats.get
4+
# NOTE: For some reason fails to connect from WSL, this should be investigated.
5+
6+
import sys
7+
import time
8+
from websocket import WebSocket
9+
from json import dumps
10+
11+
12+
def main():
13+
if len(sys.argv) not in (3, 4):
14+
print(f"Usage: {sys.argv[0]} <port> <cmd> [wait_secs]")
15+
print("Example commands: gpu.stats.get game.reset game.status (there are more)")
16+
print("Default wait time: 2 seconds")
17+
sys.exit(1)
18+
19+
# Validate port
20+
try:
21+
port = int(sys.argv[1])
22+
if not (1 <= port <= 65535):
23+
raise ValueError("Port must be between 1 and 65535")
24+
except ValueError as e:
25+
print(f"Invalid port: {e}")
26+
sys.exit(1)
27+
28+
cmd = sys.argv[2]
29+
30+
# Parse wait time (default = 2)
31+
try:
32+
wait_secs = int(sys.argv[3]) if len(sys.argv) == 4 else 2
33+
if wait_secs < 0:
34+
raise ValueError("Wait time must be non-negative")
35+
except ValueError as e:
36+
print(f"Invalid wait_secs: {e}")
37+
sys.exit(1)
38+
39+
host = "127.0.0.1"
40+
uri = f"ws://{host}:{port}/debugger"
41+
42+
ws = WebSocket()
43+
try:
44+
ws.connect(uri)
45+
request = {"event": cmd}
46+
ws.send(dumps(request))
47+
print(f"Sent {cmd} event to {uri}, listening for {wait_secs} second(s)...")
48+
49+
ws.settimeout(wait_secs)
50+
start = time.time()
51+
while True:
52+
try:
53+
response = ws.recv()
54+
print("Received response:", response)
55+
except Exception:
56+
# Stop when timeout occurs or no more messages
57+
break
58+
if time.time() - start > wait_secs:
59+
break
60+
61+
except Exception as e:
62+
print(f"Connection failed: {e}")
63+
finally:
64+
ws.close()
65+
66+
67+
if __name__ == "__main__":
68+
main()

0 commit comments

Comments
 (0)