Tests: port validate_select_poll_epoll.py to bt2 python bindings
authorFrancis Deslauriers <francis.deslauriers@efficios.com>
Thu, 7 Oct 2021 19:25:28 +0000 (15:25 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 29 Oct 2021 21:12:00 +0000 (17:12 -0400)
Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: I6ed3177e5bd31a56f4a1e84b53bf1d9025ac3161

tests/regression/kernel/validate_select_poll_epoll.py

index 3a62a1f1bba088da910d05a6a871f86c077d3628..b0cb590dbac2502190cb83f4296b7cac241dc019 100755 (executable)
@@ -12,20 +12,19 @@ import time
 
 from collections import defaultdict
 
-NSEC_PER_SEC = 1000000000
-
 try:
-    from babeltrace import TraceCollection
+    import bt2
 except ImportError:
     # quick fix for debian-based distros
     sys.path.append("/usr/local/lib/python%d.%d/site-packages" %
                     (sys.version_info.major, sys.version_info.minor))
-    from babeltrace import TraceCollection
+    import bt2
 
+NSEC_PER_SEC = 1000000000
 
 class TraceParser:
-    def __init__(self, trace, pid):
-        self.trace = trace
+    def __init__(self, trace_msg_iter, pid):
+        self.trace = trace_msg_iter
         self.pid = pid
 
         # This dictionnary holds the results of each testcases of a test.
@@ -51,16 +50,19 @@ class TraceParser:
 
     def parse(self):
         # iterate over all the events
-        for event in self.trace.events:
-            if self.pid is not None and event["pid"] != self.pid:
+        for msg in self.trace:
+            if type(msg) is not bt2._EventMessageConst:
                 continue
 
-            method_name = "handle_%s" % event.name.replace(":", "_").replace(
+            if self.pid is not None and msg.event["pid"] != self.pid:
+                continue
+
+            method_name = "handle_%s" % msg.event.name.replace(":", "_").replace(
                 "+", "_")
             # call the function to handle each event individually
             if hasattr(TraceParser, method_name):
                 func = getattr(TraceParser, method_name)
-                func(self, event)
+                func(self, msg.event)
 
         ret = 0
         # For each event of the test case, check all entries for failed
@@ -317,7 +319,7 @@ class Test1(TraceParser):
 
         # check that we have FD 0 waiting for EPOLLIN|EPOLLPRI and that
         # data.fd = 0
-        if epfd == 3 and op_enum == "EPOLL_CTL_ADD" and fd == 0 and \
+        if epfd == 3 and 'EPOLL_CTL_ADD' in op_enum.labels and fd == 0 and \
                 _event["data_union"]["fd"] == 0 and \
                 _event["events"]["EPOLLIN"] == 1 and \
                 _event["events"]["EPOLLPRI"] == 1:
@@ -435,7 +437,7 @@ class Test2(TraceParser):
         _event = event["event"]
 
         # make sure we see a EPOLLIN|EPOLLPRI
-        if op_enum == "EPOLL_CTL_ADD" and \
+        if 'EPOLL_CTL_ADD' in op_enum.labels and \
                 _event["events"]["EPOLLIN"] == 1 and \
                 _event["events"]["EPOLLPRI"] == 1:
             self.expect["epoll_ctl_entry"]["epoll_ctl_timeout_in_add"] = 1
@@ -720,10 +722,7 @@ if __name__ == "__main__":
         print("Need to pass the PID to check (-p)")
         sys.exit(1)
 
-    traces = TraceCollection()
-    handle = traces.add_traces_recursive(args.path, "ctf")
-    if handle is None:
-        sys.exit(1)
+    traces = bt2.TraceCollectionMessageIterator(args.path)
 
     t = None
 
@@ -758,7 +757,4 @@ if __name__ == "__main__":
     if t is not None:
         ret = t.parse()
 
-    for h in handle.values():
-        traces.remove_trace(h)
-
     sys.exit(ret)
This page took 0.026905 seconds and 4 git commands to generate.