Skip to content

Commit 11880cf

Browse files
committed
More work on test cases
1 parent 16e934e commit 11880cf

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed

examples/src/linux/Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ TARGETS = \
3737
x8664_onestraw_server \
3838
x8664_epoll_0 \
3939
x8664_linux_utime \
40+
x8664_onestraw_server \
41+
x8664_epoll_0 \
4042
patch_test.bin
4143

4244
.PHONY: all clean
@@ -131,6 +133,10 @@ x8664_linux_utime: x8664_linux_utime.c
131133
$(CC) $(CPPFLAGS) $(CFLAGS) -m64 -o $@ $<
132134
x86_linux_utime: x8664_linux_utime.c
133135
$(CC) $(CPPFLAGS) $(CFLAGS) -m32 -o x86_linux_utime $<
136+
x8664_epoll_0: x8664_epoll_0.c
137+
$(CC) $(CPPFLAGS) $(CFLAGS) -m64 -static -o $@ $<
138+
x8664_onestraw_server: x8664_onestraw_server.c
139+
$(CC) $(CPPFLAGS) $(CFLAGS) -m64 -static -o $@ $<
134140

135141

136142
libpatch_test.so: patch_test.so.h patch_test.so.c

qiling/os/posix/syscall/epoll.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,13 @@ def is_present(self, fd):
6565
fds for an instance of epoll being watched.
6666
If a chain of over 5 levels is detected, return
6767
1, which will return ELOOP in ql_syscall_epoll_wait
68+
<<<<<<< HEAD
6869
"""
6970

7071

72+
=======
73+
'''
74+
>>>>>>> 342d61da (More work on test cases)
7175
def check_epoll_depth(ql_fd_list, epolls_list, depth):
7276
if depth == 7:
7377
=======
@@ -92,6 +96,7 @@ def check_epoll_depth(ql_fd_list, epolls_list, depth):
9296
"""
9397
Modify an existing epoll
9498
man 7 epoll for more details
99+
<<<<<<< HEAD
95100
"""
96101
97102
@@ -101,6 +106,10 @@ def ql_syscall_epoll_ctl(
101106
=======
102107
def ql_epoll_ctl(ql: qiling.Qiling, epfd: int, op: int, fd: int, event: POINTER):
103108
>>>>>>> 0aef533c (Initial commit for epoll)
109+
=======
110+
'''
111+
def ql_syscall_epoll_ctl(ql: qiling.Qiling, epfd: int, op: int, fd: int, event: POINTER):
112+
>>>>>>> 342d61da (More work on test cases)
104113
# Basic sanity checks first
105114
if event != 0:
106115
ql_event = ql.unpack32(ql.mem.read(event, 4)) # events list is uint32_t
@@ -157,6 +166,7 @@ def ql_epoll_ctl(ql: qiling.Qiling, epfd: int, op: int, fd: int, event: POINTER)
157166
if epoll_obj is None or fd_obj is None:
158167
# epfd or fd is not a valid file descriptor.
159168
return EBADF
169+
<<<<<<< HEAD
160170
<<<<<<< HEAD
161171
if epfd == fd: # epoll can't monitor itself
162172
return EINVAL
@@ -193,6 +203,9 @@ def ql_epoll_ctl(ql: qiling.Qiling, epfd: int, op: int, fd: int, event: POINTER)
193203
epoll_parent_obj.set_eventmask(ql_event)
194204
=======
195205
if epfd == fd:
206+
=======
207+
if epfd == fd: # epoll can't monitor itself
208+
>>>>>>> 342d61da (More work on test cases)
196209
return EINVAL
197210
if epoll_obj.fileno() == fd:
198211
return ELOOP # ELOOP ...or a nesting depth of epoll instances greater than 5.
@@ -202,6 +215,7 @@ def ql_epoll_ctl(ql: qiling.Qiling, epfd: int, op: int, fd: int, event: POINTER)
202215
fd
203216
): # can't add an fd that's already being waited on
204217
return EEXIST # op was EPOLL_CTL_ADD, and the supplied file descriptor fd is already registered with this epoll instance.
218+
205219
epoll_parent_obj.monitor_fd(
206220
fd, ql_event
207221
) # add to list of fds to be monitored with per-fd eventmask
@@ -232,13 +246,18 @@ def ql_epoll_ctl(ql: qiling.Qiling, epfd: int, op: int, fd: int, event: POINTER)
232246
"""
233247
Wait on an existing epoll for events specified
234248
earlier. man 7 epoll_wait for more info
249+
<<<<<<< HEAD
235250
"""
236251

237252

238253
def ql_syscall_epoll_wait(
239254
=======
240255
def ql_epoll_wait(
241256
>>>>>>> 0aef533c (Initial commit for epoll)
257+
=======
258+
'''
259+
def ql_syscall_epoll_wait(
260+
>>>>>>> 342d61da (More work on test cases)
242261
ql: qiling.Qiling, epfd: int, epoll_events: POINTER, maxevents: int, timeout: int
243262
):
244263
if maxevents <= 0:
@@ -289,13 +308,17 @@ def ql_epoll_wait(
289308
Use select.epoll for underlying implementation,
290309
just as select.poll is used for emulating poll()
291310
"""
311+
<<<<<<< HEAD
292312

293313

294314
<<<<<<< HEAD
295315
def ql_syscall_epoll_create1(ql: qiling.Qiling, flags: int):
296316
=======
297317
def ql_epoll_create1(ql: qiling.Qiling, flags: int):
298318
>>>>>>> 0aef533c (Initial commit for epoll)
319+
=======
320+
def ql_syscall_epoll_create1(ql: qiling.Qiling, flags: int):
321+
>>>>>>> 342d61da (More work on test cases)
299322
if flags != select.EPOLL_CLOEXEC and flags != 0:
300323
return EINVAL
301324
ret = select.epoll(sizehint=-1, flags=flags)
@@ -310,6 +333,7 @@ def ql_epoll_create1(ql: qiling.Qiling, flags: int):
310333
<<<<<<< HEAD
311334
because of the slightly different prototype
312335
"""
336+
<<<<<<< HEAD
313337
314338
315339
def ql_syscall_epoll_create(ql: qiling.Qiling, size: int):
@@ -321,6 +345,9 @@ def ql_syscall_epoll_create(ql: qiling.Qiling, size: int):
321345

322346
def ql_epoll_create(ql: qiling.Qiling, size: int):
323347
>>>>>>> 0aef533c (Initial commit for epoll)
348+
=======
349+
def ql_syscall_epoll_create(ql: qiling.Qiling, size: int):
350+
>>>>>>> 342d61da (More work on test cases)
324351
if size < 0:
325352
return EINVAL
326353
ret = select.epoll(sizehint=size, flags=0)

tests/test_elf.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -772,6 +772,8 @@ def test_elf_linux_x8664_path_traversion(self):
772772

773773
del ql
774774
@unittest.skip('postpone until further discussion')
775+
776+
@unittest.skip("hangs, possibly bc of newfstatat?")
775777
def test_elf_linux_x8664_epoll_simple(self):
776778
def hook_newfstatat(ql: Qiling, dirfd: int, path: int, buf: int, flags: int):
777779
return 1
@@ -795,6 +797,7 @@ def hook_newfstatat(ql: Qiling, dirfd: int, path: int, buf: int, flags: int):
795797
self.assertIn("echo", ql.os.stdout.read(10).decode("utf-8"))
796798
del ql
797799
@unittest.skip('remove until rootfs is added, more discussion too')
800+
798801
def test_elf_linux_x8664_epoll_server(self):
799802
def hook_newfstatat(ql: Qiling, dirfd: int, path: int, buf: int, flags: int):
800803
return 1
@@ -804,6 +807,23 @@ def client():
804807
conn = http.client.HTTPConnection('localhost', 8000, timeout=10)
805808
conn.request('GET', '/')
806809
conn.close()
810+
'''
811+
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
812+
dest = ("localhost", 8000)
813+
try:
814+
s.connect(dest)
815+
except Exception as e:
816+
ql.log.debug(
817+
"socket.connect() failed in test_elf_linux_x8664_epoll_server"
818+
)
819+
ql.log.debug(e)
820+
test = b"hello world"
821+
s.send(test)
822+
s.close()
823+
'''
824+
conn = http.client.HTTPConnection('localhost', 8000, timeout=10)
825+
conn.request('GET', '/')
826+
807827
# use threads here to test how the server
808828
# handles the request
809829
client_thread = threading.Thread(target=client, daemon=True)
@@ -815,6 +835,7 @@ def client():
815835

816836
ql = Qiling(argv, rootfs, multithread=False, verbose=QL_VERBOSE.DEBUG)
817837
ql.os.stdout = pipe.SimpleOutStream(1) # server prints data received to stdout
838+
818839
ql.os.set_syscall(
819840
"newfstatat", hook_newfstatat, QL_INTERCEPT.CALL
820841
) # workaround for issue ENOENT issue in prior test case

0 commit comments

Comments
 (0)