On Sun, 18 Jan 2026 12:09:10 -0800
Stephen Hemminger <[email protected]> wrote:
> The BPF ELF tests sporadically fail with EINVAL when loading from
> the temporary file. This is a race condition where the BPF loader
> reads the file before the data is fully flushed to disk.
>
> Add fsync() before close() in create_temp_bpf_file() to ensure the
> BPF object data is visible on the filesystem before attempting to
> load it.
>
> Also fix two related issues found during review
> - Add missing TEST_ASSERT for mempool creation in test_bpf_elf_tx_load
> - Initialize port variable in test_bpf_elf_rx_load to avoid undefined
> behavior in cleanup path if null_vdev_setup fails early
>
> Fixes: cf1e03f881af ("test/bpf: add ELF loading")
> Cc: [email protected]
>
> Signed-off-by: Stephen Hemminger <[email protected]>
> ---
> app/test/test_bpf.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/app/test/test_bpf.c b/app/test/test_bpf.c
> index a7d56f8d86..03705075d8 100644
> --- a/app/test/test_bpf.c
> +++ b/app/test/test_bpf.c
> @@ -3311,6 +3311,8 @@ create_temp_bpf_file(const uint8_t *data, size_t size,
> const char *name)
>
> /* Write BPF object data */
> written = write(fd, data, size);
> + if (written == (ssize_t)size)
> + fsync(fd);
Agree, I don't think fsync is really needed.
This was a bandaid that changed the timing. The root cause of the
test failures was the overlap of parallel tests, so let me drop this bit.