Test ring buffer generation
(self)
| 25 | super(TestRingBuffer, self).tearDown() |
| 26 | |
| 27 | def test_ring_buffer_generation(self): |
| 28 | """Test ring buffer generation""" |
| 29 | |
| 30 | # Step 1: Generate messages using the VPPApiClient CLI |
| 31 | cli_cmd = f"test stats ring-buffer-gen {RING_NAME} {COUNT} {INTERVAL_USEC} {RING_SIZE}" |
| 32 | result = self.vapi.cli(cli_cmd) |
| 33 | assert "Generated" in result, f"CLI failed: {result}" |
| 34 | |
| 35 | # Step 2: Connect to stats segment and get the ring buffer |
| 36 | ring_buffer = self.statistics.get_ring_buffer(f"{RING_NAME}") |
| 37 | |
| 38 | # Step 3: Poll for all messages |
| 39 | received = [] |
| 40 | start = time.time() |
| 41 | while len(received) < COUNT and (time.time() - start) < 10: |
| 42 | data = ring_buffer.poll_for_data(thread_index=0, timeout=0.5) |
| 43 | for entry in data: |
| 44 | # Unpack the struct: u64 seq, f64 timestamp |
| 45 | seq, ts = struct.unpack("<Qd", entry) |
| 46 | received.append((seq, ts)) |
| 47 | time.sleep(0.01) |
| 48 | |
| 49 | # Step 4: Validate |
| 50 | assert len(received) == COUNT, f"Expected {COUNT} messages, got {len(received)}" |
| 51 | for i, (seq, ts) in enumerate(received): |
| 52 | assert seq == i, f"Sequence mismatch at {i}: got {seq}" |
| 53 | assert ts > 0, f"Timestamp should be positive, got {ts}" |
| 54 | |
| 55 | # print(f"Received {len(received)} messages from ring buffer '{RING_NAME}'") |
| 56 | |
| 57 | def test_ring_buffer_overwrite(self): |
| 58 | """Test ring buffer overwrite behavior""" |
nothing calls this directly
no test coverage detected