From a76b858332a05c3c987d23dafa7218dba4775755 Mon Sep 17 00:00:00 2001 From: libumem <163767094+libumem@users.noreply.github.com> Date: Fri, 14 Nov 2025 04:39:15 +0000 Subject: [PATCH] Tentative fix for epoll server test case --- qiling/os/posix/syscall/epoll.py | 2 +- tests/test_elf.py | 9 +++------ tests/test_onlinux.sh | 2 +- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/qiling/os/posix/syscall/epoll.py b/qiling/os/posix/syscall/epoll.py index 46911678..9afb57f2 100644 --- a/qiling/os/posix/syscall/epoll.py +++ b/qiling/os/posix/syscall/epoll.py @@ -118,7 +118,7 @@ def ql_syscall_epoll_ctl(ql: Qiling, epfd: int, op: int, fd: int, event: int): if op not in (EPOLL_CTL_ADD, EPOLL_CTL_DEL, EPOLL_CTL_MOD): return -EINVAL - if epfd == fd: + if epfd == fd or fd == 0xffffffff: # latter condition was seen in testing, but should not happen in the real world return -EINVAL if epfd not in range(NR_OPEN): diff --git a/tests/test_elf.py b/tests/test_elf.py index 52db6719..afaca75c 100644 --- a/tests/test_elf.py +++ b/tests/test_elf.py @@ -217,13 +217,13 @@ class ELFTest(unittest.TestCase): ql = Qiling(["../examples/rootfs/x8664_linux/bin/x8664_hello_static"], "../examples/rootfs/x8664_linux", verbose=QL_VERBOSE.DEBUG) ql.run() del ql - + #@unittest.skip('Experiment to avoid FD issue') def test_elf_linux_x86(self): filename = 'test.qlog' ql = Qiling(["../examples/rootfs/x86_linux/bin/x86_hello"], "../examples/rootfs/x86_linux", verbose=QL_VERBOSE.DEBUG, log_devices=[filename]) ql.run() - + ql._log_file_fd.handlers[0].close() # prevent FD leak that causes downstream issues os.remove(filename) del ql @@ -789,8 +789,7 @@ class ELFTest(unittest.TestCase): ql.run() self.assertIn(b'echo\n', ql.os.stdout.read()) - del ql - @unittest.skip("See comment in https://github.com/qilingframework/qiling/pull/1558") + del ql def test_elf_linux_x8664_epoll_server(self): # This tests a simple server that uses epoll to wait for data, then prints it out. It has # been modified to exit after data has been received; instead of a typical server operation @@ -810,7 +809,6 @@ class ELFTest(unittest.TestCase): def client(): # give time for the server to listen time.sleep(3) - s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect(("127.0.0.1", 8000)) s.send(b"hello world") @@ -826,7 +824,6 @@ class ELFTest(unittest.TestCase): client_thread = threading.Thread(target=client, daemon=True) client_thread.start() - ql.run() self.assertIn(b'hello world', ql.os.stdout.read(200)) # 200 is arbitrary--"good enough" for this task diff --git a/tests/test_onlinux.sh b/tests/test_onlinux.sh index 557b2e77..9a333a68 100755 --- a/tests/test_onlinux.sh +++ b/tests/test_onlinux.sh @@ -4,7 +4,7 @@ # Cross Platform and Multi Architecture Advanced Binary Emulation Framework # -python3 ./test_posix.py && +python3 -m pdb ./test_posix.py && python3 ./test_elf_multithread.py && python3 ./test_elf_ko.py && python3 ./test_debugger.py &&