<commit_before>/* SPDX-License-Identifier: BSD-3-Clause
 * Copyright(c) 2018 Intel Corporation
 */

#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/wait.h>

#include <rte_common.h>
#include <rte_debug.h>
#include <rte_eal.h>
#include <rte_errno.h>
#include <rte_malloc.h>
#include <rte_ring.h>
#include <rte_string_fns.h>

#include "test.h"

#define EXTERNAL_MEM_SZ (RTE_PGSIZE_4K << 10) /* 4M of data */

static int
check_mem(void *addr, rte_iova_t *iova, size_t pgsz, int n_pages)
{
	int i;

	/* check that we can get this memory from EAL now */
	for (i = 0; i < n_pages; i++) {
		const struct rte_memseg *ms;
		void *cur = RTE_PTR_ADD(addr, pgsz * i);
		rte_iova_t expected_iova;

		ms = rte_mem_virt2memseg(cur, NULL);
		if (ms == NULL) {
			printf("%s():%i: Failed to retrieve memseg for external mem\n",
				__func__, __LINE__);
			return -1;
		}
		if (ms->addr != cur) {
			printf("%s():%i: VA mismatch\n", __func__, __LINE__);
			return -1;
		}
		expected_iova = (iova == NULL) ? RTE_BAD_IOVA : iova[i];
		if (ms->iova != expected_iova) {
			printf("%s():%i: IOVA mismatch\n", __func__, __LINE__);
			return -1;
		}
	}
	return 0;
}

static int
test_malloc_invalid_param(void *addr, size_t len, size_t pgsz, rte_iova_t *iova,
		int n_pages)
{
	static const char * const names[] = {
		NULL, /* NULL name */
		"",   /* empty name */
		"this heap name is definitely way too long to be valid"
	};
	const char *valid_name = "valid heap name";<commit_msg>test/mem: check external memseg list<commit_after>/* SPDX-License-Identifier: BSD-3-Clause
 * Copyright(c) 2018 Intel Corporation
 */

#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/wait.h>

#include <rte_common.h>
#include <rte_debug.h>
#include <rte_eal.h>
#include <rte_eal_memconfig.h>
#include <rte_errno.h>
#include <rte_malloc.h>
#include <rte_ring.h>
#include <rte_string_fns.h>

#include "test.h"

#define EXTERNAL_MEM_SZ (RTE_PGSIZE_4K << 10) /* 4M of data */

static int
check_mem(void *addr, rte_iova_t *iova, size_t pgsz, int n_pages)
{
	int i;

	/* check that we can get this memory from EAL now */
	for (i = 0; i < n_pages; i++) {
		const struct rte_memseg_list *msl;
		const struct rte_memseg *ms;
		void *cur = RTE_PTR_ADD(addr, pgsz * i);
		rte_iova_t expected_iova;

		msl = rte_mem_virt2memseg_list(cur);
		if (!msl->external) {
			printf("%s():%i: Memseg list is not marked as external\n",
				__func__, __LINE__);
			return -1;
		}

		ms = rte_mem_virt2memseg(cur, msl);
		if (ms == NULL) {
			printf("%s():%i: Failed to retrieve memseg for external mem\n",
				__func__, __LINE__);
			return -1;
		}
		if (ms->addr != cur) {
			printf("%s():%i: VA mismatch\n", __func__, __LINE__);
			return -1;
		}
		expected_iova = (iova == NULL) ? RTE_BAD_IOVA : iova[i];
		if (ms->iova != expected_iova) {
			printf("%s():%i: IOVA mismatch\n", __func__, __LINE__);
			return -1;
		}
	}
	return 0;
}

static int
test_malloc_invalid_param(void *addr, size_t len, size_t pgsz, rte_iova_t *iova,
		int n_pages)
{
	static const char * const names[] = {
		NULL, /* NULL name */
		"",   /* empty name */
		"this heap name is definitely way too long to be valid"
	};
	const char *valid_name = "valid heap name";
{'fraction_non_alphanumeric': 0.15474408859622868, 'fraction_numerical': 0.009577970667464832, 'mean_word_length': 3.8575581395348837, 'pattern_counts': {'":': 0, '<': 38, '<?xml version=': 0, '>': 37, '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': '3804238', 'n_tokens_mistral': 1478, 'n_tokens_neox': 1380, 'n_words': 359}