Skip to content

Commit 0270378

Browse files
committed
Migrate NFIPosixSupport to FFM API
1 parent f5ede88 commit 0270378

6 files changed

Lines changed: 1938 additions & 1081 deletions

File tree

‎graalpython/com.oracle.graal.python.test/src/tests/test_posix.py‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,18 @@ def __fspath__(self):
258258
with self.assertRaisesRegex(TypeError, r"expected C.__fspath__\(\) to return str or bytes, not bytearray"):
259259
os.open(C(), 0)
260260

261+
def test_open_bytes_path(self):
262+
try:
263+
with open(os.fsencode(TEST_FULL_PATH1), os.O_WRONLY | os.O_CREAT) as fd:
264+
os.write(fd, b'hello')
265+
with open(os.fsencode(TEST_FULL_PATH1), os.O_RDONLY) as fd:
266+
self.assertEqual(b'hello', os.read(fd, 5))
267+
finally:
268+
try:
269+
os.unlink(TEST_FULL_PATH1)
270+
except Exception:
271+
pass
272+
261273
def test_fd_converter(self):
262274
class MyInt(int):
263275
def fileno(self): return 0

‎graalpython/com.oracle.graal.python.test/src/tests/test_socket.py‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,33 @@ def server():
110110
sock.recv_into(buffer, 1)
111111
assert b == b'123'
112112
thread.join()
113+
114+
115+
def test_sendto_recvfrom_roundtrip():
116+
try:
117+
if __graalpython__.posix_module_backend() == "java":
118+
return
119+
except NameError:
120+
pass
121+
122+
with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as server:
123+
server.bind(("127.0.0.1", 0))
124+
server_addr = server.getsockname()
125+
126+
with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as client:
127+
client.bind(("127.0.0.1", 0))
128+
client_addr = client.getsockname()
129+
130+
sent = client.sendto(b"phase5", server_addr)
131+
assert sent == 6
132+
133+
data, addr = server.recvfrom(64)
134+
assert data == b"phase5"
135+
assert addr == client_addr
136+
137+
sent = server.sendto(b"reply", client_addr)
138+
assert sent == 5
139+
140+
data, addr = client.recvfrom(64)
141+
assert data == b"reply"
142+
assert addr == server_addr

0 commit comments

Comments
 (0)