Skip to content

Commit

Permalink
tests: fix memory issues
Browse files Browse the repository at this point in the history
Signed-off-by: Patrick Stephens <[email protected]>
  • Loading branch information
patrick-stephens committed Dec 5, 2024
1 parent b21fc3a commit 7092fb5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 21 deletions.
5 changes: 1 addition & 4 deletions lib/cprofiles/include/cprofiles/cprof_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,9 @@
#ifndef CPROF_INFO_H
#define CPROF_INFO_H

#define CPROF_SOURCE_DIR "/Users/leonardo/Work/Calyptia/fluent-bit"
#define CPROF_SOURCE_DIR "/src/fluent-bit"

/* General flags set by /CMakeLists.txt */
#ifndef CPROF_HAVE_SANITIZE_ADDRESS
#define CPROF_HAVE_SANITIZE_ADDRESS
#endif
#ifndef CPROF_HAVE_TIMESPEC_GET
#define CPROF_HAVE_TIMESPEC_GET
#endif
Expand Down
46 changes: 29 additions & 17 deletions tests/runtime/custom_calyptia_input_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ static void test_calyptia_machine_id_generation() {
TEST_CHECK(ret == 0);

/* Verify properties were set correctly */
const char *value, *expectedValue, *machine_id;
const char *value;

/* Check config_dir */
value = flb_input_get_property("config_dir", t_ctx->fleet);
Expand All @@ -221,48 +221,60 @@ static void test_calyptia_machine_id_generation() {
* Subsequent generation should reuse the previous one
* Repeat with custom directory to confirm that works too
*/
char expectedValue[CALYPTIA_MAX_DIR_SIZE];
ret = sprintf(expectedValue, "%s/machine-id.conf", FLEET_DEFAULT_CONFIG_DIR);
TEST_CHECK(ret > 0);

value = machine_id_fleet_config_filename(t_ctx->ctx);
expectedValue = flb_sds_printf(expectedValue, "%s/machine-id.conf", FLEET_DEFAULT_CONFIG_DIR);
TEST_CHECK(value != NULL);
TEST_CHECK(expectedValue != NULL);
TEST_MSG("machine_id filename expected=%s got=%s", expectedValue, value);
TEST_CHECK(value && strcmp(value, expectedValue) == 0);

/* generate a new machine ID and verify it is not null then store for later use */
machine_id = get_machine_id(t_ctx->ctx);
flb_sds_t machine_id = get_machine_id(t_ctx->ctx);
TEST_CHECK(machine_id != NULL);

/* repeat to confirm existing UUID is maintained */
value = get_machine_id(t_ctx->ctx);
TEST_CHECK(value != NULL);
TEST_MSG("machine_id changed, expected=%s got=%s", machine_id, value);
TEST_CHECK(value && strcmp(value, machine_id) == 0);
flb_sds_t new_machine_id = get_machine_id(t_ctx->ctx);
TEST_CHECK(new_machine_id != NULL);
TEST_MSG("machine_id changed, expected=%s got=%s", machine_id, new_machine_id);
TEST_CHECK(value && strcmp(new_machine_id, machine_id) == 0);
flb_free(new_machine_id);
new_machine_id = NULL;

/* repeat with new config directory */
t_ctx = update_config_dir(t_ctx, "/test/config/fleet");
TEST_CHECK(t_ctx != NULL);

/* check we use the new directory for the filename */
ret = sprintf(expectedValue, "/test/config/fleet/machine-id.conf");
TEST_CHECK(ret > 0);

value = machine_id_fleet_config_filename(t_ctx->ctx);
expectedValue = flb_sds_printf(expectedValue, "/test/config/fleet/machine-id.conf");
TEST_CHECK(value != NULL);
TEST_CHECK(expectedValue != NULL);
TEST_MSG("machine_id filename expected=%s got=%s", expectedValue, value);
TEST_CHECK(value && strcmp(value, expectedValue) == 0);

/* check we generate a new value */
value = get_machine_id(t_ctx->ctx);
TEST_CHECK(value != NULL);
TEST_MSG("machine_id did not change, expected!=%s got=%s", machine_id, value);
TEST_CHECK(value && strcmp(value, machine_id) != 0);
new_machine_id = get_machine_id(t_ctx->ctx);
TEST_CHECK(new_machine_id != NULL);
TEST_MSG("machine_id did not change, expected!=%s got=%s", machine_id, new_machine_id);
TEST_CHECK(new_machine_id && strcmp(new_machine_id, machine_id) != 0);

flb_free(machine_id);
machine_id = new_machine_id;
new_machine_id = NULL;

machine_id = value;
/* repeat to confirm existing UUID is maintained */
value = get_machine_id(t_ctx->ctx);
TEST_CHECK(value != NULL);
TEST_MSG("machine_id changed, expected=%s got=%s", machine_id, value);
TEST_CHECK(value && strcmp(value, machine_id) == 0);
new_machine_id = get_machine_id(t_ctx->ctx);
TEST_CHECK(new_machine_id != NULL);
TEST_MSG("machine_id changed, expected=%s got=%s", machine_id, new_machine_id);
TEST_CHECK(new_machine_id && strcmp(new_machine_id, machine_id) == 0);

flb_free(new_machine_id);
flb_free(machine_id);
cleanup_test_context(t_ctx);
}

Expand Down

0 comments on commit 7092fb5

Please sign in to comment.