test: tolerate ENOMEM on packet mmap creation.
[dabba.git] / libdabba / tests / test-packet-mmap.c
blob8cede2ddd98831090c4ba64a5740c2905b2d4b8a
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <string.h>
5 #include <unistd.h>
6 #include <errno.h>
7 #include <assert.h>
8 #include <sys/socket.h>
9 #include <sys/user.h>
10 #include <arpa/inet.h>
12 #include <linux/if_ether.h>
14 #include <libdabba/macros.h>
15 #include <libdabba/interface.h>
16 #include <libdabba/packet-mmap.h>
18 #define MIN_FRAME_NR (1<<3)
19 #define MAX_FRAME_NR (1<<16)
21 int main(int argc, char **argv)
23 int rc;
24 size_t a, i, fnr;
25 int pf_sock = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL));
26 struct packet_mmap pkt_rx;
27 enum packet_mmap_type types[] = { PACKET_MMAP_RX, PACKET_MMAP_TX };
28 enum packet_mmap_frame_size fsize[] =
29 { PACKET_MMAP_ETH_FRAME_LEN, PACKET_MMAP_JUMBO_FRAME_LEN,
30 PACKET_MMAP_SUPER_JUMBO_FRAME_LEN
33 assert(argc);
34 assert(argv);
36 assert(pf_sock > 0);
38 for (a = 0; a < ARRAY_SIZE(types); a++)
39 for (i = 0; i < ARRAY_SIZE(fsize); i++)
40 for (fnr = MIN_FRAME_NR; fnr < MAX_FRAME_NR; fnr <<= 1) {
41 rc = ldab_packet_mmap_create(&pkt_rx,
42 ANY_INTERFACE,
43 pf_sock, types[a],
44 fsize[i], fnr);
46 printf("packet mmap type: %i frame number=%zu",
47 types[a], fnr);
48 printf(" frame size=%i rc=%s\n", fsize[i],
49 strerror(rc));
51 * Tolerate ENOMEM as we cannot accurately foresee
52 * if the allocation will fail or succeed
54 assert(rc == 0 || rc == ENOMEM);
55 ldab_packet_mmap_destroy(&pkt_rx);
58 return (EXIT_SUCCESS);