| 47 | b.cleanup() |
| 48 | |
| 49 | def test_queue(self): |
| 50 | text = b""" |
| 51 | BPF_QUEUE(queue, u64, 10); |
| 52 | """ |
| 53 | b = BPF(text=text) |
| 54 | queue = b[b'queue'] |
| 55 | |
| 56 | for i in range(10): |
| 57 | queue.push(ct.c_uint64(i)) |
| 58 | |
| 59 | with self.assertRaises(Exception): |
| 60 | queue.push(ct.c_uint(10)) |
| 61 | |
| 62 | assert queue.peek().value == 0 |
| 63 | |
| 64 | for i in range(10): |
| 65 | assert queue.pop().value == i |
| 66 | |
| 67 | with self.assertRaises(KeyError): |
| 68 | queue.peek() |
| 69 | |
| 70 | with self.assertRaises(KeyError): |
| 71 | queue.pop() |
| 72 | |
| 73 | for i in range(10): |
| 74 | queue.push(ct.c_uint64(i)) |
| 75 | |
| 76 | # testing itervalues() |
| 77 | for i,v in enumerate(queue.values()): |
| 78 | assert v.value == i |
| 79 | |
| 80 | b.cleanup() |
| 81 | |
| 82 | |
| 83 | if __name__ == "__main__": |