<commit_before>/* Copyright (c) 2014, Linaro Limited
 * All rights reserved.
 *
 * SPDX-License-Identifier:	BSD-3-Clause
 */

#include <stdlib.h>

#include <odp_api.h>
#include <odp_cunit_common.h>
#include "packet.h"

#define PACKET_BUF_LEN	ODP_CONFIG_PACKET_SEG_LEN_MIN
/* Reserve some tailroom for tests */
#define PACKET_TAILROOM_RESERVE  4

static odp_pool_t packet_pool, packet_pool_no_uarea, packet_pool_double_uarea;
static uint32_t packet_len;

static uint32_t segmented_packet_len;
static odp_bool_t segmentation_supported = true;

odp_packet_t test_packet, segmented_test_packet;

static struct udata_struct {
	uint64_t u64;
	uint32_t u32;
	char str[10];
} test_packet_udata = {
	123456,
	789912,
	"abcdefg",
};

#define packet_compare_offset(pkt1, off1, pkt2, off2, len) \
	_packet_compare_offset((pkt1), (off1), (pkt2), (off2), (len), __LINE__)

#define packet_compare_data(pkt1, pkt2) \
	_packet_compare_data((pkt1), (pkt2), __LINE__)

static void _packet_compare_data(odp_packet_t pkt1, odp_packet_t pkt2,
				 int line)
{
	uint32_t len = odp_packet_len(pkt1);
	uint32_t offset = 0;
	uint32_t seglen1, seglen2, cmplen;
	int ret;

	CU_ASSERT_FATAL(len == odp_packet_len(pkt2));

	while (len > 0) {
		void *pkt1map = odp_packet_offset(pkt1, offset, &seglen1, NULL);
		void *pkt2map = odp_packet_offset(pkt2, offset, &seglen2, NULL);

		CU_ASSERT_PTR_NOT_NULL_FATAL(pkt1map);
		CU_ASSERT_PTR_NOT_NULL_FATAL(pkt2map);
		cmplen = seglen1 < seglen2 ? seglen1 : seglen2;
		ret = memcmp(pkt1map, pkt2map, cmplen);

		if (ret) {
			printf("\ncompare_data failed: line %i, offset %"
			       PRIu32 "\n", line, offset);
		}

		CU_ASSERT(ret == 0);

		offset += cmplen;
		len    -= cmplen;
	}
}

static int fill_data_forward(odp_packet_t pkt, uint32_t offset, uint32_t len,
			     uint32_t *cur_data)
{
	uint8_t buf[len];
	uint32_t i, data;

	data = *cur_data;

	for (i = 0; i < len; i++)
		buf[i] = data++;

	*cur_data = data;

	return odp_packet_copy_from_mem(pkt, offset, len, buf);
}

static int fill_data_backward(odp_packet_t pkt, uint32_t offset, uint32_t len,
			      uint32_t *cur_data)
{
	uint8_t buf[len];
	uint32_t i, data;

	data = *cur_data;

	for (i = 0; i < len; i++)
		buf[len - i - 1] = data++;

	*cur_data = data;

	return odp_packet_copy_from_mem(pkt, offset, len, buf);
}

int packet_suite_init(void)
{
	odp_pool_param_t params;
	odp_pool_capability_t capa;
	struct udata_struct *udat;
	uint32_t udat_size;
	uint8_t data = 0;
	uint32_t i;

	if (odp_pool_capability(&capa) < 0) {
		printf("pool_capability failed\n");
		return -1;
	}
	if (capa.pkt.max_segs_per_pkt == 0)
		capa.pkt.max_segs_per_pkt = 10;

	/* Pick a typical packet size and decrement it to the single segment
	 * limit if needed (min_seg_len maybe equal to max_len
	 * on some systems). */
	packet_len = 512;
	while (packet_len > (capa.pkt.min_seg_len - PACKET_TAILROOM_RESERVE))
		packet_len--;

	if (capa.pkt.max_len) {
		segmented_packet_len = capa.pkt.max_len;
	} else {
		segmented_packet_len = capa.pkt.min_seg_len *
				       capa.pkt.max_segs_per_pkt;
	}

	odp_pool_param_init(&params);

	params.type           = ODP_POOL_PACKET;
	params.pkt.seg_len    = capa.pkt.min_seg_len;
	params.pkt.len        = capa.pkt.min_seg_len;
	params.pkt.num        = 100;
	params.pkt.uarea_size = sizeof(struct udata_struct);

	packet_pool = odp_pool_create("packet_pool", &params);
	if (packet_pool == ODP_POOL_INVALID) {
		printf("pool_create failed: 1\n");
		return -1;
	}

	params.pkt.uarea_size = 0;
	packet_pool_no_uarea = odp_pool_create("packet_pool_no_uarea",
					       &params);
	if (packet_pool_no_uarea == ODP_POOL_INVALID) {
		odp_pool_destroy(packet_pool);
		printf("pool_create failed: 2\n");
		return -1;<commit_msg>validation: packet: increase test pool size<commit_after>/* Copyright (c) 2014, Linaro Limited
 * All rights reserved.
 *
 * SPDX-License-Identifier:	BSD-3-Clause
 */

#include <stdlib.h>

#include <odp_api.h>
#include <odp_cunit_common.h>
#include "packet.h"

#define PACKET_BUF_LEN	ODP_CONFIG_PACKET_SEG_LEN_MIN
/* Reserve some tailroom for tests */
#define PACKET_TAILROOM_RESERVE  4
/* Number of packets in the test packet pool */
#define PACKET_POOL_NUM 300

static odp_pool_t packet_pool, packet_pool_no_uarea, packet_pool_double_uarea;
static uint32_t packet_len;

static uint32_t segmented_packet_len;
static odp_bool_t segmentation_supported = true;

odp_packet_t test_packet, segmented_test_packet;

static struct udata_struct {
	uint64_t u64;
	uint32_t u32;
	char str[10];
} test_packet_udata = {
	123456,
	789912,
	"abcdefg",
};

#define packet_compare_offset(pkt1, off1, pkt2, off2, len) \
	_packet_compare_offset((pkt1), (off1), (pkt2), (off2), (len), __LINE__)

#define packet_compare_data(pkt1, pkt2) \
	_packet_compare_data((pkt1), (pkt2), __LINE__)

static void _packet_compare_data(odp_packet_t pkt1, odp_packet_t pkt2,
				 int line)
{
	uint32_t len = odp_packet_len(pkt1);
	uint32_t offset = 0;
	uint32_t seglen1, seglen2, cmplen;
	int ret;

	CU_ASSERT_FATAL(len == odp_packet_len(pkt2));

	while (len > 0) {
		void *pkt1map = odp_packet_offset(pkt1, offset, &seglen1, NULL);
		void *pkt2map = odp_packet_offset(pkt2, offset, &seglen2, NULL);

		CU_ASSERT_PTR_NOT_NULL_FATAL(pkt1map);
		CU_ASSERT_PTR_NOT_NULL_FATAL(pkt2map);
		cmplen = seglen1 < seglen2 ? seglen1 : seglen2;
		ret = memcmp(pkt1map, pkt2map, cmplen);

		if (ret) {
			printf("\ncompare_data failed: line %i, offset %"
			       PRIu32 "\n", line, offset);
		}

		CU_ASSERT(ret == 0);

		offset += cmplen;
		len    -= cmplen;
	}
}

static int fill_data_forward(odp_packet_t pkt, uint32_t offset, uint32_t len,
			     uint32_t *cur_data)
{
	uint8_t buf[len];
	uint32_t i, data;

	data = *cur_data;

	for (i = 0; i < len; i++)
		buf[i] = data++;

	*cur_data = data;

	return odp_packet_copy_from_mem(pkt, offset, len, buf);
}

static int fill_data_backward(odp_packet_t pkt, uint32_t offset, uint32_t len,
			      uint32_t *cur_data)
{
	uint8_t buf[len];
	uint32_t i, data;

	data = *cur_data;

	for (i = 0; i < len; i++)
		buf[len - i - 1] = data++;

	*cur_data = data;

	return odp_packet_copy_from_mem(pkt, offset, len, buf);
}

int packet_suite_init(void)
{
	odp_pool_param_t params;
	odp_pool_capability_t capa;
	struct udata_struct *udat;
	uint32_t udat_size;
	uint8_t data = 0;
	uint32_t i;
	uint32_t num = PACKET_POOL_NUM;

	if (odp_pool_capability(&capa) < 0) {
		printf("pool_capability failed\n");
		return -1;
	}
	if (capa.pkt.max_segs_per_pkt == 0)
		capa.pkt.max_segs_per_pkt = 10;

	/* Pick a typical packet size and decrement it to the single segment
	 * limit if needed (min_seg_len maybe equal to max_len
	 * on some systems). */
	packet_len = 512;
	while (packet_len > (capa.pkt.min_seg_len - PACKET_TAILROOM_RESERVE))
		packet_len--;

	if (capa.pkt.max_len) {
		segmented_packet_len = capa.pkt.max_len;
	} else {
		segmented_packet_len = capa.pkt.min_seg_len *
				       capa.pkt.max_segs_per_pkt;
	}
	if (capa.pkt.max_num != 0 && capa.pkt.max_num < num)
		num = capa.pkt.max_num;

	odp_pool_param_init(&params);

	params.type           = ODP_POOL_PACKET;
	params.pkt.seg_len    = capa.pkt.min_seg_len;
	params.pkt.len        = capa.pkt.min_seg_len;
	params.pkt.num        = num;
	params.pkt.uarea_size = sizeof(struct udata_struct);

	packet_pool = odp_pool_create("packet_pool", &params);
	if (packet_pool == ODP_POOL_INVALID) {
		printf("pool_create failed: 1\n");
		return -1;
	}

	params.pkt.uarea_size = 0;
	packet_pool_no_uarea = odp_pool_create("packet_pool_no_uarea",
					       &params);
	if (packet_pool_no_uarea == ODP_POOL_INVALID) {
		odp_pool_destroy(packet_pool);
		printf("pool_create failed: 2\n");
		return -1;
{'fraction_non_alphanumeric': 0.11701710852814418, 'fraction_numerical': 0.0312132689042706, 'mean_word_length': 4.362745098039215, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '246684', 'n_tokens_mistral': 3448, 'n_tokens_neox': 3276, 'n_words': 651}