Skip to content
Merged
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
2 changes: 1 addition & 1 deletion cmake/add_tests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ function (add_unit_test)

add_test (${ADD_UNIT_TEST_TARGET} ${ADD_UNIT_TEST_TARGET})
set_tests_properties(${ADD_UNIT_TEST_TARGET} PROPERTIES ENVIRONMENT "ASAN_OPTIONS=detect_odr_violation=0")
set_tests_properties(${ADD_UNIT_TEST_TARGET} PROPERTIES FAIL_REGULAR_EXPRESSION "ERROR: LeakSanitizer")
set_tests_properties(${ADD_UNIT_TEST_TARGET} PROPERTIES FAIL_REGULAR_EXPRESSION "ERROR: (LeakSanitizer|AddressSanitizer)")
endfunction ()

macro (add_test_subdirectory SUBDIR)
Expand Down
1 change: 1 addition & 0 deletions lib/cfg-grammar.y
Original file line number Diff line number Diff line change
Expand Up @@ -1034,6 +1034,7 @@ yesno
gboolean value;
gboolean success = cfg_process_yesno($1, &value);
CHECK_ERROR((TRUE == success), @1, "invalid yesno value: %s. Use one of the following: yes/no, on/off, true/false, enable/disable, enabled/disabled", $1);
free($1);
$$ = value;
}
| LL_NUMBER
Expand Down
2 changes: 2 additions & 0 deletions lib/logmsg/tests/test_log_message.c
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,8 @@ Test(log_message, test_local_logmsg_created_with_the_right_flags_and_timestamps)

cr_assert_neq((msg->flags & LF_LOCAL), 0, "LogMessage created by log_msg_new_local() should have LF_LOCAL flag set");
cr_assert(are_equals, "The timestamps in a LogMessage created by log_msg_new_local() should be equals");

log_msg_unref(msg);
}

Test(log_message, test_sdata_sanitization)
Expand Down
22 changes: 11 additions & 11 deletions lib/logmsg/tests/test_tags.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
#define NUM_TAGS 8159
#define FILTER_TAGS 100

gchar *
static gchar *
get_tag_by_id(LogTagId id)
{
return g_strdup_printf("tags%d", id);
Expand Down Expand Up @@ -148,32 +148,32 @@ Test(tags, test_filters_true)
guint i;
GList *l = NULL;
gchar *name;
gboolean not = TRUE;

cr_log_info("=== filter tests %s===\n", not ? "not " : "");
cr_log_info("=== filter tests not===\n");

for (i = 1; i < FILTER_TAGS; i += 3)
l = g_list_prepend(l, get_tag_by_id(i));

filter_tags_add(f, l);
f->comp = not;
f->comp = TRUE;

for (i = 0; i < FILTER_TAGS; i++)
{
cr_log_info("Testing filter, message has tag %d\n", i);

name = get_tag_by_id(i);
LogTagId id = log_tags_get_by_name(name);
g_free(name);

log_msg_set_tag_by_id(msg, id);

cr_assert_not(((i % 3 == 1) ^ filter_expr_eval(f, msg)) ^ not, "Failed to match message by tag %d\n", id);
cr_assert(((i % 3 == 1) ^ filter_expr_eval(f, msg)), "Failed to match message by tag %d\n", id);

cr_log_info("Testing filter, message no tag\n");

log_msg_clear_tag_by_id(msg, id);

cr_assert_not(filter_expr_eval(f, msg) ^ not, "Failed to match message with no tags\n");
cr_assert(filter_expr_eval(f, msg), "Failed to match message with no tags\n");
}

filter_expr_unref(f);
Expand All @@ -187,32 +187,32 @@ Test(tags, test_filters_false)
guint i;
GList *l = NULL;
gchar *name;
gboolean not = FALSE;

cr_log_info("=== filter tests %s===\n", not ? "not " : "");
cr_log_info("=== filter tests ===\n");

for (i = 1; i < FILTER_TAGS; i += 3)
l = g_list_prepend(l, get_tag_by_id(i));

filter_tags_add(f, l);
f->comp = not;
f->comp = FALSE;

for (i = 0; i < FILTER_TAGS; i++)
{
cr_log_info("Testing filter, message has tag %d\n", i);

name = get_tag_by_id(i);
LogTagId id = log_tags_get_by_name(name);
g_free(name);

log_msg_set_tag_by_id(msg, id);

cr_assert_not(((i % 3 == 1) ^ filter_expr_eval(f, msg)) ^ not, "Failed to match message by tag %d\n", id);
cr_assert_not(((i % 3 == 1) ^ filter_expr_eval(f, msg)), "Failed to match message by tag %d\n", id);

cr_log_info("Testing filter, message no tag\n");

log_msg_clear_tag_by_id(msg, id);

cr_assert_not(filter_expr_eval(f, msg) ^ not, "Failed to match message with no tags\n");
cr_assert_not(filter_expr_eval(f, msg), "Failed to match message with no tags\n");
}

filter_expr_unref(f);
Expand Down
3 changes: 3 additions & 0 deletions lib/logproto/tests/test-framed-server.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ Test(log_proto, test_log_proto_framed_server_too_long_line_trimmed_multiple_cycl
assert_proto_server_fetch(proto, "1a", 2);
assert_proto_server_fetch(proto, "2", 1);
assert_proto_server_fetch_failure(proto, LPS_EOF, NULL);
log_proto_server_free(proto);
}

Test(log_proto, test_log_proto_framed_server_too_long_line_trimmed_frame_at_the_end)
Expand Down Expand Up @@ -180,6 +181,7 @@ Test(log_proto, test_log_proto_framed_server_too_long_line_trimmed_frame_at_the_
// dropping: 1234567
assert_proto_server_fetch(proto, "2abc", 4);
assert_proto_server_fetch_failure(proto, LPS_EOF, NULL);
log_proto_server_free(proto);
}

Test(log_proto, test_log_proto_framed_server_too_long_line_trimmed_one_big_message)
Expand All @@ -197,6 +199,7 @@ Test(log_proto, test_log_proto_framed_server_too_long_line_trimmed_one_big_messa
get_inited_proto_server_options());
assert_proto_server_fetch(proto, "ab", 2);
assert_proto_server_fetch(proto, "0123456789", 10);
log_proto_server_free(proto);
}

Test(log_proto, test_log_proto_framed_server_message_exceeds_buffer)
Expand Down
21 changes: 11 additions & 10 deletions lib/string-list.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ string_list_clone(GList *string_list)
GList *l;

for (l = string_list; l; l = l->next)
cloned = g_list_append(cloned, GPOINTER_TO_UINT(l->data) > 4096 ? g_strdup(l->data) : l->data);
cloned = g_list_append(cloned, (gulong)(l->data) > 4096 ? g_strdup(l->data) : l->data);

return cloned;
}
Expand All @@ -64,16 +64,17 @@ string_array_to_list(const gchar *strlist[])
* values used by the application code and are not freed. Since this
* is the NULL page, this should not cause memory leaks.
*/
static void
_free_valid_str_pointers(gpointer data)
{
/* some of the string lists use invalid pointer values as special
* items, see SQL "default" item */
if ((gulong)data > 4096)
g_free(data);
}

void
string_list_free(GList *l)
{
while (l)
{
/* some of the string lists use invalid pointer values as special
* items, see SQL "default" item */

if (GPOINTER_TO_UINT(l->data) > 4096)
g_free(l->data);
l = g_list_delete_link(l, l);
}
g_list_free_full(l, _free_valid_str_pointers);
}
6 changes: 6 additions & 0 deletions lib/tests/test_lexer_block.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ Test(test_block, mandatory_arguments)
cfg_args_set(args, "mandatory-param", "value");
cr_assert(generator->generate(generator, configuration, args, result, ""));
cr_assert_str_eq(result->str, "value");

cfg_args_unref(args);
cfg_block_generator_unref(generator);
}

Test(test_block, varargs)
Expand All @@ -90,4 +93,7 @@ Test(test_block, varargs)
cfg_args_accept_varargs(arg_defs);
cr_assert(generator->generate(generator, configuration, args, result, ""));
cr_assert_str_eq(result->str, "value");

cfg_args_unref(args);
cfg_block_generator_unref(generator);
}
4 changes: 4 additions & 0 deletions lib/transport/tests/test_transport_factory_id.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ Test(transport_factory_id_basic_macros, generated_ids_are_uniq)
TransportFactoryId *id = _transport_factory_id_new("tcp");
TransportFactoryId *id2 = _transport_factory_id_new("tcp");
cr_expect_not(transport_factory_id_equal(id, id2));
transport_factory_id_free(id);
transport_factory_id_free(id2);
}

Test(transport_factory_id_basic_macros, clones_are_equals)
Expand All @@ -62,4 +64,6 @@ Test(transport_factory_id_basic_macros, clones_are_equals)
TransportFactoryId *cloned = _transport_factory_id_clone(id);
cr_expect(transport_factory_id_equal(id, cloned));
cr_expect_eq(transport_factory_id_hash(id), transport_factory_id_hash(cloned));
transport_factory_id_free(id);
transport_factory_id_free(cloned);
}
2 changes: 1 addition & 1 deletion modules/csvparser/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
add_unit_test(CRITERION TARGET test_csvparser DEPENDS csvparser syslogformat)
add_unit_test(CRITERION TARGET test_csvparser_perf DEPENDS csvparser)
add_unit_test(CRITERION TARGET test_csvparser_statistics DEPENDS csvparser syslogformat)
add_unit_test(CRITERION TARGET test_csvparser_statistics DEPENDS csvparser)
1 change: 0 additions & 1 deletion modules/csvparser/tests/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,4 @@ modules_csvparser_tests_test_csvparser_statistics_CFLAGS = \
$(TEST_CFLAGS) -I$(top_srcdir)/modules/csvparser
modules_csvparser_tests_test_csvparser_statistics_LDADD = \
$(TEST_LDADD) \
$(PREOPEN_SYSLOGFORMAT) \
-dlpreopen $(top_builddir)/modules/csvparser/libcsvparser.la
16 changes: 6 additions & 10 deletions modules/csvparser/tests/test_csvparser_statistics.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

#include <criterion/criterion.h>

MsgFormatOptions parse_options;
LogPathOptions path_options = LOG_PATH_OPTIONS_INIT;

static LogParser *
Expand Down Expand Up @@ -66,7 +65,8 @@ _unregister_statistics(LogParser *p)
static void
_parse_msg(LogParser *self, gchar *msg)
{
LogMessage *logmsg = log_msg_new(msg, strlen(msg), NULL, &parse_options);
LogMessage *logmsg = log_msg_new_empty();
log_msg_set_value(logmsg, LM_V_MESSAGE, msg, -1);
log_parser_process_message(self, &logmsg, &path_options);
log_msg_unref(logmsg);
}
Expand All @@ -78,22 +78,18 @@ Test(test_filters_statistics, filter_stastistics)
configuration->stats_options.level = 1;
cr_assert(cfg_init(configuration));

cfg_load_module(configuration, "syslogformat");
msg_format_options_defaults(&parse_options);
msg_format_options_init(&parse_options, configuration);

LogParser *parser = _create_parser(configuration);
cr_assert_eq(stats_counter_get(parser->super.discarded_messages), 0);
_parse_msg(parser, "column1, column2, column3, column4");
cr_assert_eq(stats_counter_get(parser->super.discarded_messages), 1);
_parse_msg(parser, "column1, column2, column3");
cr_assert_eq(stats_counter_get(parser->super.discarded_messages), 2);
cr_assert_eq(stats_counter_get(parser->super.discarded_messages), 1);
_parse_msg(parser, "column1, column2");
cr_assert_eq(stats_counter_get(parser->super.discarded_messages), 2);
_parse_msg(parser, "column1");
cr_assert_eq(stats_counter_get(parser->super.discarded_messages), 2);

_unregister_statistics(parser);

log_parser_free_method((LogPipe *)parser);
log_pipe_unref(&parser->super);
cfg_deinit(configuration);
cfg_free(configuration);
app_shutdown();
Expand Down
2 changes: 1 addition & 1 deletion modules/graphite/graphite-output.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ tf_graphite_format(GString *result, ValuePairs *vp, LogMessage *msg, const LogTe

return_value = value_pairs_foreach(vp, tf_graphite_foreach_func, msg, 0, time_zone_mode, template_options, &userdata);

g_string_free(userdata.formatted_unixtime, FALSE);
g_string_free(userdata.formatted_unixtime, TRUE);
return return_value;
}

Expand Down
2 changes: 1 addition & 1 deletion modules/graphite/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
add_unit_test(LIBTEST CRITERION TARGET test_graphite_output DEPENDS syslogformat graphite)
add_unit_test(LIBTEST CRITERION TARGET test_graphite_output DEPENDS graphite)
1 change: 0 additions & 1 deletion modules/graphite/tests/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@ EXTRA_DIST += modules/graphite/tests/CMakeLists.txt
modules_graphite_tests_test_graphite_output_CFLAGS = $(TEST_CFLAGS)
modules_graphite_tests_test_graphite_output_LDADD = $(TEST_LDADD)
modules_graphite_tests_test_graphite_output_LDFLAGS = \
$(PREOPEN_SYSLOGFORMAT) \
-dlpreopen $(top_builddir)/modules/graphite/libgraphite.la
modules_graphite_tests_test_graphite_output_DEPENDENCIES = $(top_builddir)/modules/graphite/libgraphite.la
27 changes: 26 additions & 1 deletion modules/graphite/tests/test_graphite_output.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

#include <criterion/criterion.h>

#include "logmsg/logmsg.h"
#include "timeutils/misc.h"
#include "libtest/cr_template.h"
#include "apphook.h"
#include "cfg.h"
Expand All @@ -42,16 +44,35 @@ teardown(void)
app_shutdown();
}

static void
_log_msg_set_recvd_time(LogMessage *msg, time_t t)
{
msg->timestamps[LM_TS_RECVD].ut_sec = t;
msg->timestamps[LM_TS_RECVD].ut_usec = 0;
msg->timestamps[LM_TS_RECVD].ut_gmtoff = get_local_timezone_ofs(t);
}

TestSuite(graphite_output, .init = setup, .fini = teardown);

Test(graphite_output, test_graphite_plaintext_proto_simple)
{
assert_template_format("$(graphite-output local.random.diceroll=4)", "local.random.diceroll 4 1139684315\n");
}

Test(graphite_output, test_graphite_output_hard_macro)
{
LogMessage *msg = log_msg_new_empty();

log_msg_set_value(msg, LM_V_MESSAGE, "árvíztűrőtükörfúrógép", -1);
_log_msg_set_recvd_time(msg, 1139684315);

assert_template_format_with_escaping_msg("$(graphite-output --key MESSAGE)", FALSE,
"MESSAGE árvíztűrőtükörfúrógép 1139684315\n", msg);
log_msg_unref(msg);
}

Test(graphite_output, test_graphite_output_key)
{
assert_template_format("$(graphite-output --key MESSAGE)", "MESSAGE árvíztűrőtükörfúrógép 1139684315\n");
assert_template_format("$(graphite-output --key APP.VALUE*)",
"APP.VALUE value 1139684315\n"
"APP.VALUE2 value 1139684315\n"
Expand All @@ -60,6 +81,10 @@ Test(graphite_output, test_graphite_output_key)
"APP.VALUE5 value 1139684315\n"
"APP.VALUE6 value 1139684315\n"
"APP.VALUE7 value 1139684315\n");
}

Test(graphite_output, test_graphite_output_custome_key_name)
{
assert_template_format("$(graphite-output local.value=${APP.VALUE})", "local.value value 1139684315\n");
}

Expand Down