|WARNING| test: add CRC length and alignment sweep

dpdklab at iol.unh.edu dpdklab at iol.unh.edu
Sun Nov 8 12:33:52 CET 2026


Test-Label: ai-code-review
Test-Status: WARNING
https://dpdk.org/patch/172729

_AI Code Review_

=== Patch Review: series.patch (via Claude) ===
Review date: 2026-11-08

# DPDK Patch Review

## Patch: test: add CRC length and alignment sweep

### ERRORS

**Error 1: Missing error check on rte_net_crc_set_alg()**

In `crc_length_sweep()`, the calls to `rte_net_crc_set_alg()` at lines 121 and 125 do not check for NULL return values. If algorithm selection fails, subsequent calls to `rte_net_crc_calc()` will dereference a NULL pointer.

```c
struct rte_net_crc *ref =
	rte_net_crc_set_alg(RTE_NET_CRC_SCALAR, types[t]);
```

**Suggested fix:**

```c
struct rte_net_crc *ref =
	rte_net_crc_set_alg(RTE_NET_CRC_SCALAR, types[t]);
if (ref == NULL)
	return TEST_FAILED;

/* ... later ... */

struct rte_net_crc *ctx =
	rte_net_crc_set_alg(algs[a], types[t]);
if (ctx == NULL) {
	rte_net_crc_free(ref);
	return TEST_FAILED;
}
```

**Error 2: Resource leak on early return**

At line 136, when the CRC mismatch is detected, the function returns TEST_FAILED immediately. However, `ref` was allocated in the outer loop (line 121) but only `ctx` is freed. The `ref` context leaks on this error path.

```c
if (rte_net_crc_calc(ctx, buf + off, len) !=
		rte_net_crc_calc(ref, buf + off, len)) {
	printf("alg %u type %u off %u len %u\n",
			algs[a], types[t], off, len);
	rte_net_crc_free(ctx);
	rte_net_crc_free(ref);
	return TEST_FAILED;
}
```

**The code IS correct** - both `ctx` and `ref` are freed before returning. This is not an error. (Removing this finding per final check pass 2.)

---

### WARNINGS

**Warning 1: rte_rand() seeding not guaranteed**

At line 118, `rte_rand()` is called without verifying that the RNG has been seeded. While DPDK's `rte_rand()` seeds from system entropy on first use, relying on this implicit behavior is fragile. For test code, consider explicit `rte_srand()` or a fixed seed for reproducibility.

**Suggested fix:**

```c
rte_srand(0xDEADBEEF);  /* fixed seed for reproducible tests */
for (i = 0; i < sizeof(buf); i++)
	buf[i] = rte_rand();
```

---

### INFO

**Info 1: Loop variable scope (C99 style)**

The `crc_length_sweep()` function declares loop counters at the start of the function (line 115). Modern C99 style allows declaring them at point of use in the loop initializer, which limits their scope and is now acceptable per the guidelines.

**Optional improvement:**

```c
for (unsigned int t = 0; t < RTE_DIM(types); t++) {
	/* ... */
}
```

This is a style preference, not an error. The current code is acceptable.

---

## Summary

The patch has two errors that must be fixed:
1. Missing NULL checks on `rte_net_crc_set_alg()` return values
2. (Removed after verification - cleanup is correct)

One warning about RNG seeding for test reproducibility.

The core logic of the length sweep test is sound: it compares SIMD implementations against the scalar reference across varying alignments and lengths, which is valuable test coverage. The fix for Test 4 result accumulation (line 172) is correct.

Review-Result: ERROR


More information about the test-report mailing list