* Test to read mbuf packet data from offset */
| 1947 | * Test to read mbuf packet data from offset |
| 1948 | */ |
| 1949 | static int |
| 1950 | test_pktmbuf_read_from_offset(struct rte_mempool *pktmbuf_pool) |
| 1951 | { |
| 1952 | struct rte_mbuf *m = NULL; |
| 1953 | struct ether_hdr *hdr = NULL; |
| 1954 | char *data = NULL; |
| 1955 | const char *data_copy = NULL; |
| 1956 | unsigned int off; |
| 1957 | unsigned int hdr_len = sizeof(struct rte_ether_hdr); |
| 1958 | |
| 1959 | /* alloc a mbuf */ |
| 1960 | m = rte_pktmbuf_alloc(pktmbuf_pool); |
| 1961 | if (m == NULL) |
| 1962 | GOTO_FAIL("%s: mbuf allocation failed!\n", __func__); |
| 1963 | |
| 1964 | if (rte_pktmbuf_pkt_len(m) != 0) |
| 1965 | GOTO_FAIL("%s: Bad packet length\n", __func__); |
| 1966 | rte_mbuf_sanity_check(m, 0); |
| 1967 | |
| 1968 | /* prepend an ethernet header */ |
| 1969 | hdr = (struct ether_hdr *)rte_pktmbuf_prepend(m, hdr_len); |
| 1970 | if (hdr == NULL) |
| 1971 | GOTO_FAIL("%s: Cannot prepend header\n", __func__); |
| 1972 | if (rte_pktmbuf_pkt_len(m) != hdr_len) |
| 1973 | GOTO_FAIL("%s: Bad pkt length", __func__); |
| 1974 | if (rte_pktmbuf_data_len(m) != hdr_len) |
| 1975 | GOTO_FAIL("%s: Bad data length", __func__); |
| 1976 | memset(hdr, 0xde, hdr_len); |
| 1977 | |
| 1978 | /* read mbuf header info from 0 offset */ |
| 1979 | data_copy = rte_pktmbuf_read(m, 0, hdr_len, NULL); |
| 1980 | if (data_copy == NULL) |
| 1981 | GOTO_FAIL("%s: Error in reading header!\n", __func__); |
| 1982 | for (off = 0; off < hdr_len; off++) { |
| 1983 | if (data_copy[off] != (char)0xde) |
| 1984 | GOTO_FAIL("Header info corrupted at offset %u", off); |
| 1985 | } |
| 1986 | |
| 1987 | /* append sample data after ethernet header */ |
| 1988 | data = rte_pktmbuf_append(m, MBUF_TEST_DATA_LEN2); |
| 1989 | if (data == NULL) |
| 1990 | GOTO_FAIL("%s: Cannot append data\n", __func__); |
| 1991 | if (rte_pktmbuf_pkt_len(m) != hdr_len + MBUF_TEST_DATA_LEN2) |
| 1992 | GOTO_FAIL("%s: Bad packet length\n", __func__); |
| 1993 | if (rte_pktmbuf_data_len(m) != hdr_len + MBUF_TEST_DATA_LEN2) |
| 1994 | GOTO_FAIL("%s: Bad data length\n", __func__); |
| 1995 | memset(data, 0xcc, MBUF_TEST_DATA_LEN2); |
| 1996 | |
| 1997 | /* read mbuf data after header info */ |
| 1998 | data_copy = rte_pktmbuf_read(m, hdr_len, MBUF_TEST_DATA_LEN2, NULL); |
| 1999 | if (data_copy == NULL) |
| 2000 | GOTO_FAIL("%s: Error in reading header data!\n", __func__); |
| 2001 | for (off = 0; off < MBUF_TEST_DATA_LEN2; off++) { |
| 2002 | if (data_copy[off] != (char)0xcc) |
| 2003 | GOTO_FAIL("Data corrupted at offset %u", off); |
| 2004 | } |
| 2005 | |
| 2006 | /* partial reading of mbuf data */ |
no test coverage detected