-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from rekter0/winProcessFix
Fix WinProcess
- Loading branch information
Showing
3 changed files
with
52 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 not shown.