summaryrefslogtreecommitdiff
path: root/tools/testing/selftests/net/lib
diff options
context:
space:
mode:
authorJakub Kicinski <kuba@kernel.org>2026-03-17 20:38:18 -0700
committerJakub Kicinski <kuba@kernel.org>2026-03-19 16:57:28 -0700
commitff1cb3ad2abce4d03eaf3e8d5f38a7a5dfd36e79 (patch)
tree1fc3aaac4bc0824610e640db32fdd70aefbb64e6 /tools/testing/selftests/net/lib
parentba5d4128fca8d141cced21f7ed10d14582cd5c1c (diff)
downloadlinux-next-ff1cb3ad2abce4d03eaf3e8d5f38a7a5dfd36e79.tar.gz
linux-next-ff1cb3ad2abce4d03eaf3e8d5f38a7a5dfd36e79.zip
selftests: drv-net: gro: add test for packet ordering
Add a test to check if the NIC reorders packets if the hit GRO. Link: https://patch.msgid.link/20260318033819.1469350-6-kuba@kernel.org Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Diffstat (limited to 'tools/testing/selftests/net/lib')
-rw-r--r--tools/testing/selftests/net/lib/gro.c38
1 files changed, 35 insertions, 3 deletions
diff --git a/tools/testing/selftests/net/lib/gro.c b/tools/testing/selftests/net/lib/gro.c
index 41794b9f6f8a..3e611ae25f61 100644
--- a/tools/testing/selftests/net/lib/gro.c
+++ b/tools/testing/selftests/net/lib/gro.c
@@ -131,6 +131,7 @@ static int ethhdr_proto = -1;
static bool ipip;
static uint64_t txtime_ns;
static int num_flows = 4;
+static bool order_check;
#define CAPACITY_PAYLOAD_LEN 200
@@ -1136,6 +1137,7 @@ static void check_capacity_pkts(int fd)
static char buffer[IP_MAXPACKET + ETH_HLEN + 1];
struct iphdr *iph = (struct iphdr *)(buffer + ETH_HLEN);
struct ipv6hdr *ip6h = (struct ipv6hdr *)(buffer + ETH_HLEN);
+ int num_pkt = 0, num_coal = 0, pkt_idx;
const char *fail_reason = NULL;
int flow_order[num_flows * 2];
int coalesced[num_flows];
@@ -1144,8 +1146,6 @@ static void check_capacity_pkts(int fd)
int total_data = 0;
int pkt_size = -1;
int data_len = 0;
- int num_pkt = 0;
- int num_coal = 0;
int flow_id;
int sport;
@@ -1203,6 +1203,34 @@ static void check_capacity_pkts(int fd)
total_data += data_len;
}
+ /* Check flow ordering. We expect to see all non-coalesced first segs
+ * then interleaved coalesced and non-coalesced second frames.
+ */
+ pkt_idx = 0;
+ for (flow_id = 0; order_check && flow_id < num_flows; flow_id++) {
+ bool coaled = coalesced[flow_id] > CAPACITY_PAYLOAD_LEN;
+
+ if (coaled)
+ continue;
+
+ if (flow_order[pkt_idx] != flow_id) {
+ vlog("Flow order mismatch (non-coalesced) at position %d: expected flow %d, got flow %d\n",
+ pkt_idx, flow_id, flow_order[pkt_idx]);
+ fail_reason = fail_reason ?: "bad packet order (1)";
+ }
+ pkt_idx++;
+ }
+ for (flow_id = 0; order_check && flow_id < num_flows; flow_id++) {
+ bool coaled = coalesced[flow_id] > CAPACITY_PAYLOAD_LEN;
+
+ if (flow_order[pkt_idx] != flow_id) {
+ vlog("Flow order mismatch at position %d: expected flow %d, got flow %d, coalesced: %d\n",
+ pkt_idx, flow_id, flow_order[pkt_idx], coaled);
+ fail_reason = fail_reason ?: "bad packet order (2)";
+ }
+ pkt_idx++;
+ }
+
if (!fail_reason) {
vlog("All %d flows coalesced correctly\n", num_flows);
printf("Test succeeded\n\n");
@@ -1622,12 +1650,13 @@ static void parse_args(int argc, char **argv)
{ "saddr", required_argument, NULL, 's' },
{ "smac", required_argument, NULL, 'S' },
{ "test", required_argument, NULL, 't' },
+ { "order-check", no_argument, NULL, 'o' },
{ "verbose", no_argument, NULL, 'v' },
{ 0, 0, 0, 0 }
};
int c;
- while ((c = getopt_long(argc, argv, "46d:D:ei:n:rs:S:t:v", opts, NULL)) != -1) {
+ while ((c = getopt_long(argc, argv, "46d:D:ei:n:rs:S:t:ov", opts, NULL)) != -1) {
switch (c) {
case '4':
proto = PF_INET;
@@ -1666,6 +1695,9 @@ static void parse_args(int argc, char **argv)
case 't':
testname = optarg;
break;
+ case 'o':
+ order_check = true;
+ break;
case 'v':
verbose = true;
break;