tools/testing/selftests/bpf/prog_tests/test_xsk.c

Source file repositories/reference/linux-study-clean/tools/testing/selftests/bpf/prog_tests/test_xsk.c

File Facts

System
Linux kernel
Corpus path
tools/testing/selftests/bpf/prog_tests/test_xsk.c
Extension
.c
Size
67880 bytes
Lines
2637
Domain
Support Tooling And Documentation
Bucket
tools
Inferred role
Support Tooling And Documentation: implementation source
Status
source implementation candidate

Why This File Exists

Repository support layer: documentation, build tooling, samples, user-space helper tools, generated initramfs support, licenses, and validation utilities.

Dependency Surface

Detected Declarations

Annotated Snippet

if (i == 0) {
			ifobj->rx_on = false;
			ifobj->tx_on = true;
		} else {
			ifobj->rx_on = true;
			ifobj->tx_on = false;
		}

		umem_real = ifobj->xsk_arr[0].umem_real;
		memset(umem_real, 0, sizeof(*umem_real));
		for (j = 0; j < MAX_SOCKETS; j++) {
			struct xsk_socket_info *xsk = &ifobj->xsk_arr[j];

			memset(xsk, 0, sizeof(*xsk));
			xsk->rxqsize = XSK_RING_CONS__DEFAULT_NUM_DESCS;
			if (j == 0)
				xsk->umem_real = umem_real;
			xsk->umem = umem_real;
			xsk->batch_size = DEFAULT_BATCH_SIZE;
			if (i == 0)
				xsk->pkt_stream = test->tx_pkt_stream_default;
			else
				xsk->pkt_stream = test->rx_pkt_stream_default;

			memcpy(xsk->src_mac, g_mac, ETH_ALEN);
			memcpy(xsk->dst_mac, g_mac, ETH_ALEN);
			xsk->src_mac[5] += ((j * 2) + 0);
			xsk->dst_mac[5] += ((j * 2) + 1);
		}

		ifobj->xsk->umem->num_frames = DEFAULT_UMEM_BUFFERS;
		ifobj->xsk->umem->frame_size = XSK_UMEM__DEFAULT_FRAME_SIZE;
	}

	if (ifobj_tx->hw_ring_size_supp)
		hw_ring_size_reset(ifobj_tx);

	test->ifobj_tx = ifobj_tx;
	test->ifobj_rx = ifobj_rx;
	test->current_step = 0;
	test->total_steps = 1;
	test->nb_sockets = 1;
	test->fail = false;
	test->set_ring = false;
	test->adjust_tail = false;
	test->adjust_tail_support = false;
	test->mtu = MAX_ETH_PKT_SIZE;
	test->xdp_prog_rx = ifobj_rx->xdp_progs->progs.xsk_def_prog;
	test->xskmap_rx = ifobj_rx->xdp_progs->maps.xsk;
	test->xdp_prog_tx = ifobj_tx->xdp_progs->progs.xsk_def_prog;
	test->xskmap_tx = ifobj_tx->xdp_progs->maps.xsk;
}

void test_init(struct test_spec *test, struct ifobject *ifobj_tx,
			   struct ifobject *ifobj_rx, enum test_mode mode,
			   const struct test_spec *test_to_run)
{
	struct pkt_stream *tx_pkt_stream;
	struct pkt_stream *rx_pkt_stream;
	u32 i;

	tx_pkt_stream = test->tx_pkt_stream_default;
	rx_pkt_stream = test->rx_pkt_stream_default;
	memset(test, 0, sizeof(*test));
	test->tx_pkt_stream_default = tx_pkt_stream;
	test->rx_pkt_stream_default = rx_pkt_stream;

	for (i = 0; i < MAX_INTERFACES; i++) {
		struct ifobject *ifobj = i ? ifobj_rx : ifobj_tx;

		ifobj->bind_flags = XDP_USE_NEED_WAKEUP;
		if (mode == TEST_MODE_ZC)
			ifobj->bind_flags |= XDP_ZEROCOPY;
		else
			ifobj->bind_flags |= XDP_COPY;
	}

	memcpy(test->name, test_to_run->name, MAX_TEST_NAME_SIZE);
	test->test_func = test_to_run->test_func;
	test->mode = mode;
	__test_spec_init(test, ifobj_tx, ifobj_rx);
}

static void test_spec_reset(struct test_spec *test)
{
	__test_spec_init(test, test->ifobj_tx, test->ifobj_rx);
}

static void test_spec_set_unaligned(struct test_spec *test)
{

Annotation

Implementation Notes