Skip to content

Commit

Permalink
Merge pull request #18 from rekter0/winProcessFix
Browse files Browse the repository at this point in the history
Fix WinProcess
  • Loading branch information
ptr-yudai authored Feb 16, 2023
2 parents e1537f5 + 8ece46c commit 3028e81
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
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.

0 comments on commit 3028e81

Please sign in to comment.