@@ -344,6 +344,12 @@ class Chip:
return request
+ def fileno(self) -> int:
+ """
+ Return the underlying file descriptor.
+ """
+ return self.fd
+
def __repr__(self) -> str:
"""
Return a string that can be used to re-create this chip object.
@@ -224,6 +224,12 @@ class LineRequest:
return cast(_ext.Request, self._req).read_edge_events(max_events)
+ def fileno(self) -> int:
+ """
+ Return the underlying file descriptor.
+ """
+ return self.fd
+
def __str__(self) -> str:
"""
Return a user-friendly, human-readable description of this request.
@@ -4,6 +4,7 @@
import time
from datetime import timedelta
from functools import partial
+from select import select
from threading import Thread
from typing import Optional
from unittest import TestCase
@@ -201,6 +202,42 @@ class ReadingMultipleEdgeEvents(TestCase):
self.global_seqno += 1
+class PollLineRequestObject(TestCase):
+ def setUp(self) -> None:
+ self.sim = gpiosim.Chip(num_lines=8)
+ self.request = gpiod.request_lines(
+ self.sim.dev_path, {2: gpiod.LineSettings(edge_detection=Edge.BOTH)}
+ )
+ self.thread: Optional[Thread] = None
+
+ def tearDown(self) -> None:
+ if self.thread:
+ self.thread.join()
+ del self.thread
+ self.request.release()
+ del self.request
+ del self.sim
+
+ def trigger_rising_edge(self, offset: int) -> None:
+ time.sleep(0.05)
+ self.sim.set_pull(offset, Pull.UP)
+
+ def test_select_request_object(self):
+ self.thread = Thread(target=partial(self.trigger_rising_edge, 2))
+ self.thread.start()
+
+ rd, wr, ex = select([self.request], [], [], 1)
+ self.assertFalse(wr)
+ self.assertFalse(ex)
+ self.assertEqual(rd[0], self.request)
+
+ events = rd[0].read_edge_events()
+ self.assertEqual(len(events), 1)
+
+ event = events[0]
+ self.assertEqual(event.line_offset, 2)
+
+
class EdgeEventStringRepresentation(TestCase):
def test_edge_event_str(self) -> None:
sim = gpiosim.Chip()
@@ -7,6 +7,7 @@ import threading
import time
from dataclasses import FrozenInstanceError
from functools import partial
+from select import select
from typing import Optional
from unittest import TestCase
@@ -131,6 +132,23 @@ class WatchingInfoEventWorks(TestCase):
self.assertGreater(ts_rel, ts_rec)
self.assertGreater(ts_rec, ts_req)
+ def test_select_chip_object(self):
+ info = self.chip.watch_line_info(7)
+
+ self.thread = threading.Thread(
+ target=partial(request_reconfigure_release_line, self.sim.dev_path, 7)
+ )
+ self.thread.start()
+
+ rd, wr, ex = select([self.chip], [], [], 1)
+ self.assertFalse(wr)
+ self.assertFalse(ex)
+ self.assertEqual(rd[0], self.chip)
+
+ event = rd[0].read_info_event()
+ self.assertEqual(event.event_type, _EventType.LINE_REQUESTED)
+ self.assertEqual(event.line_info.offset, 7)
+
class UnwatchingLineInfo(TestCase):
def setUp(self) -> None: