MCPcopy Create free account
hub / github.com/F-Stack/f-stack / test_write_packets

Function test_write_packets

dpdk/app/test/test_pcapng.c:385–440  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

383}
384
385static int
386test_write_packets(void)
387{
388 char file_name[] = "/tmp/pcapng_test_XXXXXX.pcapng";
389 static rte_pcapng_t *pcapng;
390 int ret, tmp_fd, count;
391 uint64_t now = current_timestamp();
392
393 tmp_fd = mkstemps(file_name, strlen(".pcapng"));
394 if (tmp_fd == -1) {
395 perror("mkstemps() failure");
396 goto fail;
397 }
398 printf("pcapng: output file %s\n", file_name);
399
400 /* open a test capture file */
401 pcapng = rte_pcapng_fdopen(tmp_fd, NULL, NULL, "pcapng_test", NULL);
402 if (pcapng == NULL) {
403 fprintf(stderr, "rte_pcapng_fdopen failed\n");
404 close(tmp_fd);
405 goto fail;
406 }
407
408 /* Add interface to the file */
409 ret = rte_pcapng_add_interface(pcapng, port_id,
410 NULL, NULL, NULL);
411 if (ret < 0) {
412 fprintf(stderr, "can not add port %u\n", port_id);
413 goto fail;
414 }
415
416 count = fill_pcapng_file(pcapng, TOTAL_PACKETS);
417 if (count < 0)
418 goto fail;
419
420 /* write a statistics block */
421 ret = rte_pcapng_write_stats(pcapng, port_id,
422 count, 0, "end of test");
423 if (ret <= 0) {
424 fprintf(stderr, "Write of statistics failed\n");
425 goto fail;
426 }
427
428 rte_pcapng_close(pcapng);
429
430 ret = valid_pcapng_file(file_name, now, count);
431 /* if test fails want to investigate the file */
432 if (ret == 0)
433 unlink(file_name);
434
435 return ret;
436
437fail:
438 rte_pcapng_close(pcapng);
439 return -1;
440}
441
442static void

Callers

nothing calls this directly

Calls 9

current_timestampFunction · 0.85
rte_pcapng_fdopenFunction · 0.85
rte_pcapng_add_interfaceFunction · 0.85
fill_pcapng_fileFunction · 0.85
rte_pcapng_write_statsFunction · 0.85
rte_pcapng_closeFunction · 0.85
valid_pcapng_fileFunction · 0.85
printfFunction · 0.50
closeFunction · 0.50

Tested by

no test coverage detected