Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Win process fix #18

Merged
merged 2 commits into from
Feb 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion ptrlib/connection/tube.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,6 @@ def __enter__(self):
def __exit__(self, e_type, e_value, traceback):
self.close()

@abstractmethod
def is_alive(self) -> bool:
pass

Expand Down
52 changes: 52 additions & 0 deletions tests/connection/test_windows_proc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import unittest
import os
import random
from ptrlib import Process, is_scanf_safe
from logging import getLogger, FATAL


class TestProcess(unittest.TestCase):
def setUp(self):
getLogger("ptrlib").setLevel(FATAL)

def test_basic(self):
while True:
msg = os.urandom(16)
if is_scanf_safe(msg):
break

p = Process("./tests/test.bin/test_echo.pe.exe")

# send / recv
p.sendline(b"Message : " + msg)
self.assertEqual(p.recvlineafter(" : "), msg)

# send / recvregex
a, b = random.randrange(1<<32), random.randrange(1<<32)
p.sendline("Hello 0x{:08x}, 0x{:08x}".format(a, b))
r = p.recvregex("0x([0-9a-f]+), 0x([0-9a-f]+)")
p.recvline()
self.assertEqual(int(r[0], 16), a)
self.assertEqual(int(r[1], 16), b)

# shutdown
p.send(msg[::-1])
p.shutdown('write')
self.assertEqual(p.recvonce(len(msg)), msg[::-1])


p.close()

def test_timeout(self):
p = Process("./tests/test.bin/test_echo.pe.exe")
try:
p.recvuntil("*** never expected ***", timeout=1)
result = False
except TimeoutError:
result = True
except:
result = False
finally:
p.close()

self.assertEqual(result, True)
Binary file added tests/test.bin/test_echo.pe.exe
Binary file not shown.