Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions tests/runtime/in_netif.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,14 @@ static struct test_ctx *test_ctx_create(struct flb_lib_out_cb *data)
return ctx;
}

static void test_ctx_destroy(struct test_ctx *ctx)
static void test_ctx_destroy(struct test_ctx *ctx, int ret)
{
TEST_CHECK(ctx != NULL);

sleep(1);
flb_stop(ctx->flb);
if (ret == 0) {
flb_stop(ctx->flb);
}
flb_destroy(ctx->flb);
flb_free(ctx);
}
Expand Down Expand Up @@ -226,7 +228,7 @@ static void flb_test_normal()
TEST_MSG("expect: >=1 got: %d", got);
}

test_ctx_destroy(ctx);
test_ctx_destroy(ctx, ret);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

All call sites now propagate flb_start()’s return into teardown — consistent and correct

Passing ret into test_ctx_destroy(ctx, ret) ensures we only stop when the engine actually started. Call-site updates look complete for this file.

To ensure there are no remaining tests with the old pattern, run this repo-wide sweep:

Also applies to: 256-256, 290-290, 343-343


🏁 Script executed:

#!/usr/bin/env bash
set -euo pipefail

echo "1) Any direct flb_stop() in tests without an obvious guard?"
rg -n -C2 -g 'tests/runtime/**' --type=c '\bflb_stop\s*\('

echo
echo "2) Common teardown helpers calling flb_stop(); check they accept start ret and guard the stop"
rg -nU -g 'tests/runtime/**' --type=c '(?s)void\s+\w*(do_destroy|_destroy|_ctx_destroy)\s*\([^)]*\)\s*\{.*?\bflb_stop\s*\(' -C0

echo
echo "3) Call sites of teardown helpers; verify they pass the flb_start() result"
rg -n -g 'tests/runtime/**' --type=c '\b(do_destroy|test_ctx_destroy)\s*\(' -C2

echo
echo "4) Places that start but might still do unconditional flb_stop()"
rg -n -C3 -g 'tests/runtime/**' --type=c '\bret\s*=\s*flb_start\s*\('

Length of output: 263775


Update Remaining Tests to Propagate flb_start() Return Into Teardown

While tests/runtime/in_netif.c has been updated correctly—its test_ctx_destroy(ctx, ret) guard ensures we only call flb_stop() when ret == 0—the repo-wide sweep still shows numerous test files using the old pattern. These need to be updated to maintain consistency and avoid unguarded calls to flb_stop().

Key areas requiring changes:

  • Any test in tests/runtime/** with an unconditional

      flb_stop(ctx);       // or flb_stop(ctx->flb);
      flb_destroy(ctx);    // (or flb_destroy(ctx->flb);)

    should instead

    1. Use a teardown helper that accepts the ret value (e.g., test_ctx_destroy(ctx, ret) or do_destroy(ctx, ret)), and
    2. Guard the call to flb_stop() inside that helper with if (ret == 0).
  • Teardown helper definitions (e.g., static void test_ctx_destroy(struct test_ctx *ctx)) must be refactored to accept an int ret parameter and wrap flb_stop() accordingly.

Examples of files to update (non-exhaustive):

  • tests/runtime/filter_parser.c (multiple flb_stop(ctx); at lines 162, 249, 326, …)
  • tests/runtime/out_flowcounter.c (lines 64, 100, 135, …)
  • tests/runtime/out_loki.c (lines 106, 165, 225, …)
  • tests/runtime/in_tail.c (lines 241, 551, 671, …)
  • tests/runtime/processor_metrics_selector.c (lines 144, 220, 302, …)
  • And many more under tests/runtime/**

Please extend the pattern used in in_netif.c across the suite:

-    flb_stop(ctx);
-    flb_destroy(ctx);
+    test_ctx_destroy(ctx, ret);   // or do_destroy(ctx, ret)

And update the helper:

-static void test_ctx_destroy(struct test_ctx *ctx)
+static void test_ctx_destroy(struct test_ctx *ctx, int ret)
 {
     if (ret == 0) {
         flb_stop(ctx->flb);
     }
     flb_destroy(ctx->flb);
 }

With these changes, all tests will uniformly propagate and respect the return value of flb_start().

}

static void flb_test_no_interface()
Expand All @@ -251,7 +253,7 @@ static void flb_test_no_interface()
ret = flb_start(ctx->flb);
TEST_CHECK(ret != 0);

test_ctx_destroy(ctx);
test_ctx_destroy(ctx, ret);
}

static void flb_test_invalid_interface()
Expand Down Expand Up @@ -285,7 +287,7 @@ static void flb_test_invalid_interface()
ret = flb_start(ctx->flb);
TEST_CHECK(ret != 0);

test_ctx_destroy(ctx);
test_ctx_destroy(ctx, ret);
}

static void flb_test_verbose()
Expand Down Expand Up @@ -338,7 +340,7 @@ static void flb_test_verbose()
TEST_MSG("expect: >10 got: %d", got);
}

test_ctx_destroy(ctx);
test_ctx_destroy(ctx, ret);
}

TEST_LIST = {
Expand Down
54 changes: 36 additions & 18 deletions tests/runtime/in_podman_metrics.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,15 @@ void do_create(flb_ctx_t *ctx, char *system, ...)
NULL) == 0);
}

void do_destroy(flb_ctx_t *ctx) {
flb_stop(ctx);
void do_destroy(flb_ctx_t *ctx, int ret) {
if (ret == 0) {
flb_stop(ctx);
}
flb_destroy(ctx);
}

void flb_test_ipm_regular() {
int ret;
flb_ctx_t *ctx = flb_create();
do_create(ctx,
"podman_metrics",
Expand All @@ -97,14 +100,16 @@ void flb_test_ipm_regular() {
"path.sysfs", DPATH_PODMAN_REGULAR,
"path.procfs", DPATH_PODMAN_REGULAR,
NULL);
TEST_CHECK(flb_start(ctx) == 0);
ret = flb_start(ctx);
TEST_CHECK(ret == 0);
sleep(1);
TEST_CHECK(check_metric(ctx, "usage_bytes") == 0);
TEST_CHECK(check_metric(ctx, "receive_bytes_total") == 0);
do_destroy(ctx);
do_destroy(ctx, ret);
}

void flb_test_ipm_reversed() {
int ret;
flb_ctx_t *ctx = flb_create();
do_create(ctx,
"podman_metrics",
Expand All @@ -113,14 +118,16 @@ void flb_test_ipm_reversed() {
"path.sysfs", DPATH_PODMAN_REVERSED,
"path.procfs", DPATH_PODMAN_REVERSED,
NULL);
TEST_CHECK(flb_start(ctx) == 0);
ret = flb_start(ctx);
TEST_CHECK(ret == 0);
sleep(1);
TEST_CHECK(check_metric(ctx, "usage_bytes") == 0);
TEST_CHECK(check_metric(ctx, "receive_bytes_total") == 0);
do_destroy(ctx);
do_destroy(ctx, ret);
}

void flb_test_ipm_garbage_config() {
int ret;
flb_ctx_t *ctx = flb_create();
do_create(ctx,
"podman_metrics",
Expand All @@ -129,11 +136,13 @@ void flb_test_ipm_garbage_config() {
"path.sysfs", DPATH_PODMAN_GARBAGE_CONFIG,
"path.procfs", DPATH_PODMAN_GARBAGE_CONFIG,
NULL);
TEST_CHECK(flb_start(ctx) != 0);
do_destroy(ctx);
ret = flb_start(ctx);
TEST_CHECK(ret != 0);
do_destroy(ctx, ret);
}

void flb_test_ipm_no_config() {
int ret;
flb_ctx_t *ctx = flb_create();
do_create(ctx,
"podman_metrics",
Expand All @@ -142,11 +151,13 @@ void flb_test_ipm_no_config() {
"path.sysfs", DPATH_PODMAN_NO_CONFIG,
"path.procfs", DPATH_PODMAN_NO_CONFIG,
NULL);
TEST_CHECK(flb_start(ctx) != 0);
do_destroy(ctx);
ret = flb_start(ctx);
TEST_CHECK(ret != 0);
do_destroy(ctx, ret);
}

void flb_test_ipm_no_sysfs() {
int ret;
flb_ctx_t *ctx = flb_create();
do_create(ctx,
"podman_metrics",
Expand All @@ -155,14 +166,16 @@ void flb_test_ipm_no_sysfs() {
"path.sysfs", DPATH_PODMAN_NO_SYSFS,
"path.procfs", DPATH_PODMAN_NO_SYSFS,
NULL);
TEST_CHECK(flb_start(ctx) == 0);
ret = flb_start(ctx);
TEST_CHECK(ret == 0);
sleep(1);
TEST_CHECK(check_metric(ctx, "usage_bytes") != 0);
TEST_CHECK(check_metric(ctx, "receive_bytes_total") != 0);
do_destroy(ctx);
do_destroy(ctx, ret);
}

void flb_test_ipm_no_proc() {
int ret;
flb_ctx_t *ctx = flb_create();
do_create(ctx,
"podman_metrics",
Expand All @@ -171,14 +184,16 @@ void flb_test_ipm_no_proc() {
"path.sysfs", DPATH_PODMAN_NO_PROC,
"path.procfs", DPATH_PODMAN_NO_PROC,
NULL);
TEST_CHECK(flb_start(ctx) == 0);
ret = flb_start(ctx);
TEST_CHECK(ret == 0);
sleep(1);
TEST_CHECK(check_metric(ctx, "usage_bytes") == 0);
TEST_CHECK(check_metric(ctx, "receive_bytes_total") != 0);
do_destroy(ctx);
do_destroy(ctx, ret);
}

void flb_test_ipm_garbage() {
int ret;
flb_ctx_t *ctx = flb_create();
do_create(ctx,
"podman_metrics",
Expand All @@ -187,14 +202,16 @@ void flb_test_ipm_garbage() {
"path.sysfs", DPATH_PODMAN_GARBAGE,
"path.procfs", DPATH_PODMAN_GARBAGE,
NULL);
TEST_CHECK(flb_start(ctx) == 0);
ret = flb_start(ctx);
TEST_CHECK(ret == 0);
sleep(1);
TEST_CHECK(check_metric(ctx, "usage_bytes") != 0);
TEST_CHECK(check_metric(ctx, "receive_bytes_total") != 0);
do_destroy(ctx);
do_destroy(ctx, ret);
}

void flb_test_ipm_cgroupv2() {
int ret;
flb_ctx_t *ctx = flb_create();
do_create(ctx,
"podman_metrics",
Expand All @@ -203,11 +220,12 @@ void flb_test_ipm_cgroupv2() {
"path.sysfs", DPATH_PODMAN_CGROUP_V2,
"path.procfs", DPATH_PODMAN_CGROUP_V2,
NULL);
TEST_CHECK(flb_start(ctx) == 0);
ret = flb_start(ctx);
TEST_CHECK(ret == 0);
sleep(1);
TEST_CHECK(check_metric(ctx, "usage_bytes") == 0);
TEST_CHECK(check_metric(ctx, "receive_bytes_total") == 0);
do_destroy(ctx);
do_destroy(ctx, ret);
}

TEST_LIST = {
Expand Down
Loading