static void test_ack_over_eof(LogQueueDiskReliable *dq, LogMessage *msg1, LogMessage *msg2) { log_queue_ack_backlog(&dq->super.super, 3); assert_gint(dq->qbacklog->length, 0, ASSERTION_ERROR("Messages are in the qbacklog")); assert_gint(dq->super.qdisk->hdr->backlog_head, dq->super.qdisk->hdr->read_head, ASSERTION_ERROR("Backlog head in bad position")); }
static void _prepare_eof_test(LogQueueDiskReliable *dq, LogMessage **msg1, LogMessage **msg2) { LogPathOptions local_options = LOG_PATH_OPTIONS_INIT; gint64 start_pos = TEST_DISKQ_SIZE; *msg1 = log_msg_new_mark(); *msg2 = log_msg_new_mark(); (*msg1)->ack_func = _dummy_ack; log_msg_add_ack(*msg1, &local_options); (*msg2)->ack_func = _dummy_ack; log_msg_add_ack(*msg2, &local_options); dq->super.qdisk->hdr->write_head = start_pos; dq->super.qdisk->hdr->read_head = QDISK_RESERVED_SPACE + mark_message_serialized_size + 1; dq->super.qdisk->hdr->backlog_head = dq->super.qdisk->hdr->read_head; log_queue_push_tail(&dq->super.super, *msg1, &local_options); log_queue_push_tail(&dq->super.super, *msg2, &local_options); assert_gint(dq->qreliable->length, NUMBER_MESSAGES_IN_QUEUE(2), ASSERTION_ERROR("Messages aren't in qreliable")); assert_gint64(dq->super.qdisk->hdr->write_head, QDISK_RESERVED_SPACE + mark_message_serialized_size, ASSERTION_ERROR("Bad write head")); assert_gint(num_of_ack, 0, ASSERTION_ERROR("Messages are acked")); dq->super.qdisk->hdr->read_head = start_pos; dq->super.qdisk->hdr->backlog_head = dq->super.qdisk->hdr->read_head; }
void __test_seeks(Journald *journald) { gint result = journald_seek_head(journald); assert_gint(result, 0, ASSERTION_ERROR("Can't seek in empty journald mock")); result = journald_next(journald); assert_gint(result, 0, ASSERTION_ERROR("Bad next step result")); MockEntry *entry = mock_entry_new("test_data1"); mock_entry_add_data(entry, "MESSAGE=test message"); mock_entry_add_data(entry, "KEY=VALUE"); mock_entry_add_data(entry, "HOST=testhost"); journald_mock_add_entry(journald, entry); entry = mock_entry_new("test_data2"); mock_entry_add_data(entry, "MESSAGE=test message2"); mock_entry_add_data(entry, "KEY=VALUE2"); mock_entry_add_data(entry, "HOST=testhost2"); journald_mock_add_entry(journald, entry); result = journald_seek_head(journald); assert_gint(result, 0, ASSERTION_ERROR("Can't seek in journald mock")); result = journald_next(journald); assert_gint(result, 1, ASSERTION_ERROR("Bad next step result")); }
void test_journald_helper() { Journald *journald = journald_mock_new(); journald_open(journald, 0); MockEntry *entry = mock_entry_new("test_data1"); mock_entry_add_data(entry, "MESSAGE=test message"); mock_entry_add_data(entry, "KEY=VALUE"); mock_entry_add_data(entry, "HOST=testhost"); journald_mock_add_entry(journald, entry); journald_seek_head(journald); journald_next(journald); GHashTable *result = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); journald_foreach_data(journald, __helper_test, result); gchar *message = g_hash_table_lookup(result, "MESSAGE"); gchar *key = g_hash_table_lookup(result, "KEY"); gchar *host = g_hash_table_lookup(result, "HOST"); assert_string(message, "test message", ASSERTION_ERROR("Bad item")); assert_string(key, "VALUE", ASSERTION_ERROR("Bad item")); assert_string(host, "testhost", ASSERTION_ERROR("Bad item")); journald_close(journald); journald_free(journald); g_hash_table_unref(result); }
void __test_cursors(Journald *journald) { gchar *cursor; gint result = journald_get_cursor(journald, &cursor); assert_string(cursor, "test_data1", ASSERTION_ERROR("Bad cursor fetched"));\ g_free(cursor); result = journald_next(journald); assert_gint(result, 1, ASSERTION_ERROR("Bad next step result")); result = journald_get_cursor(journald, &cursor); assert_string(cursor, "test_data2", ASSERTION_ERROR("Bad cursor fetched")); g_free(cursor); result = journald_next(journald); assert_gint(result, 0, ASSERTION_ERROR("Should not contain more elements")); result = journald_seek_cursor(journald, "test_data1"); assert_gint(result, 0, ASSERTION_ERROR("Should find cursor")); result = journald_next(journald); assert_gint(result, 1, ASSERTION_ERROR("Bad next step result")); result = journald_get_cursor(journald, &cursor); assert_string(cursor, "test_data1", ASSERTION_ERROR("Bad cursor fetched")); g_free(cursor); result = journald_seek_cursor(journald, "test_data2"); assert_gint(result, 0, ASSERTION_ERROR("Should find cursor")); result = journald_next(journald); assert_gint(result, 1, ASSERTION_ERROR("Bad next step result")); result = journald_get_cursor(journald, &cursor); assert_string(cursor, "test_data2", ASSERTION_ERROR("Bad cursor fetched")); g_free(cursor); }
void test_set_field_exist_and_group_set_multiple_fields_with_multiple_glob_pattern_literal_string() { LogRewrite *test_rewrite = create_rewrite_rule("groupset(\"value\" values(\"field1\" \"field2\") );"); LogMessage *msg = create_message_with_fields("field1", "oldvalue","field2", "oldvalue", NULL); invoke_rewrite_rule(test_rewrite, msg); assert_msg_field_equals(msg, "field1", "value", -1, ASSERTION_ERROR("Couldn't set message field")); assert_msg_field_equals(msg, "field2", "value", -1, ASSERTION_ERROR("Couldn't set message field")); rewrite_teardown(msg); }
void test_reference_on_condition_cloned() { LogRewrite *test_rewrite = create_rewrite_rule("set(\"00100\", value(\"device_id\") condition(program(\"ARCGIS\")));"); LogPipe *cloned_rule = log_pipe_clone(&test_rewrite->super); assert_guint32(test_rewrite->condition->ref_cnt, 2, ASSERTION_ERROR("Bad reference number of condition")); log_pipe_unref(cloned_rule); assert_guint32(test_rewrite->condition->ref_cnt, 1, ASSERTION_ERROR("Bad reference number of condition")); cfg_free(configuration); }
/* * The method make the following situation * the backlog contains 6 messages * the qbacklog contains 3 messages, * but messages in qbacklog are the end of the backlog */ void _prepare_rewind_backlog_test(LogQueueDiskReliable *dq, gint64 *start_pos) { gint i; for (i = 0; i < 8; i++) { LogPathOptions path_options = LOG_PATH_OPTIONS_INIT; LogMessage *mark_message; mark_message = log_msg_new_mark(); mark_message->ack_func = _dummy_ack; log_queue_push_tail(&dq->super.super, mark_message, &path_options); } /* Lets read the messages and leave them in the backlog */ for (i = 0; i < 8; i++) { LogMessage *msg; LogPathOptions path_options = LOG_PATH_OPTIONS_INIT; msg = log_queue_pop_head(&dq->super.super, &path_options); log_msg_unref(msg); } /* Ack the messages which are not in the qbacklog */ log_queue_ack_backlog(&dq->super.super, 5); assert_gint(dq->qbacklog->length, NUMBER_MESSAGES_IN_QUEUE(3), ASSERTION_ERROR("Incorrect number of items in the qbacklog")); *start_pos = dq->super.qdisk->hdr->read_head; /* Now write 3 more messages and read them from buffer * the number of messages in the qbacklog should not be changed * The backlog should contain 6 messages * from these 6 messages 3 messages are cached in the qbacklog * No readable messages are in the queue */ for (i = 0; i < 3; i++) { LogPathOptions path_options = LOG_PATH_OPTIONS_INIT; LogMessage *mark_message; mark_message = log_msg_new_mark(); mark_message->ack_func = _dummy_ack; log_queue_push_tail(&dq->super.super, mark_message, &path_options); mark_message = log_queue_pop_head(&dq->super.super, &path_options); assert_gint(dq->qreliable->length, 0, ASSERTION_ERROR("Incorrect number of items in the qreliable")); assert_gint(dq->qbacklog->length, NUMBER_MESSAGES_IN_QUEUE(3), ASSERTION_ERROR("Incorrect number of items in the qbacklog")); log_msg_unref(mark_message); } assert_gint(dq->super.qdisk->hdr->backlog_len, 6, ASSERTION_ERROR("Incorrect number of messages in the backlog")); assert_gint(dq->super.qdisk->hdr->length, 0, ASSERTION_ERROR("Reliable diskq isn't empty")); }
LogRewrite * create_rewrite_rule(const char *raw_rewrite_rule) { char raw_config[1024]; configuration = cfg_new(VERSION_VALUE); snprintf(raw_config, sizeof(raw_config), "rewrite s_test{ %s }; log{ rewrite(s_test); };", raw_rewrite_rule); assert_true(parse_config(raw_config, LL_CONTEXT_ROOT, NULL, NULL), ASSERTION_ERROR("Parsing the given configuration failed")); assert_true(cfg_init(configuration), ASSERTION_ERROR("Config initialization failed")); LogExprNode *expr_node = cfg_tree_get_object(&configuration->tree, ENC_REWRITE, "s_test"); return (LogRewrite *)expr_node->children->object; }
void test_rewind_backlog_without_using_qbacklog(LogQueueDiskReliable *dq, gint64 old_read_pos) { /* * Rewind the last 2 messages * - the read_head should be moved to the good position * - the qbacklog and qreliable should be untouched */ log_queue_rewind_backlog(&dq->super.super, 2); assert_gint64(dq->super.qdisk->hdr->read_head, old_read_pos + mark_message_serialized_size, ASSERTION_ERROR("Bad reader position")); assert_gint(dq->qreliable->length, 0, ASSERTION_ERROR("Incorrect number of items in the qreliable")); assert_gint(dq->qbacklog->length, NUMBER_MESSAGES_IN_QUEUE(3), ASSERTION_ERROR("Incorrect number of items in the qbacklog")); }
void test_rewind_backlog_partially_used_qbacklog(LogQueueDiskReliable *dq, gint64 old_read_pos) { /* * Rewind more 2 messages * - the reader the should be moved to the good position * - the qreliable should contain 1 items * - the qbackbacklog should contain 2 items */ log_queue_rewind_backlog(&dq->super.super, 2); assert_gint64(dq->super.qdisk->hdr->read_head, old_read_pos - mark_message_serialized_size, ASSERTION_ERROR("Bad reader position")); assert_gint(dq->qreliable->length, NUMBER_MESSAGES_IN_QUEUE(1), ASSERTION_ERROR("Incorrect number of items in the qreliable")); assert_gint(dq->qbacklog->length, NUMBER_MESSAGES_IN_QUEUE(2), ASSERTION_ERROR("Incorrect number of items in the qbacklog")); }
void __test_enumerate(Journald *journald) { const void *data; const void *prev_data; gsize length; gsize prev_len; gint result; journald_restart_data(journald); result = journald_enumerate_data(journald, &data, &length); assert_gint(result, 1, ASSERTION_ERROR("Data should exist")); prev_data = data; prev_len = length; result = journald_enumerate_data(journald, &data, &length); assert_gint(result, 1, ASSERTION_ERROR("Data should exist")); result = journald_enumerate_data(journald, &data, &length); assert_gint(result, 1, ASSERTION_ERROR("Data should exist")); result = journald_enumerate_data(journald, &data, &length); assert_gint(result, 0, ASSERTION_ERROR("Data should not exist")); journald_restart_data(journald); result = journald_enumerate_data(journald, &data, &length); assert_gint(result, 1, ASSERTION_ERROR("Data should exist")); assert_gpointer((gpointer )data, (gpointer )prev_data, ASSERTION_ERROR("restart data should seek the start of the data")); assert_gint(length, prev_len, ASSERTION_ERROR("Bad length after restart data")); result = journald_next(journald); assert_gint(result, 0, ASSERTION_ERROR("Should not contain more elements")); }
void _test_default_facility_test(TestCase *self, TestSource *src, LogMessage *msg) { gint facility = GPOINTER_TO_INT(self->user_data); assert_gint(msg->pri, facility | LOG_NOTICE, ASSERTION_ERROR("Bad default prio")); test_source_finish_tc(src); }
void _test_default_level_test(TestCase *self, TestSource *src, LogMessage *msg) { gint level = GPOINTER_TO_INT(self->user_data); assert_gint(msg->pri, LOG_LOCAL0 | level, ASSERTION_ERROR("Bad default prio")); test_source_finish_tc(src); }
void test_subst_field_exist_and_substring_substituted_when_regexp_matched() { LogRewrite *test_rewrite = create_rewrite_rule("subst(\"[0-9]+\" \"substitute\" value(\"field1\") );"); LogMessage *msg = create_message_with_fields("field1", "a123b", NULL); invoke_rewrite_rule(test_rewrite, msg); assert_msg_field_equals(msg, "field1", "asubstituteb", -1, ASSERTION_ERROR("Couldn't subst message field with literal")); rewrite_teardown(msg); }
void test_set_field_exist_and_set_literal_string() { LogRewrite *test_rewrite = create_rewrite_rule("set(\"value\" value(\"field1\") );"); LogMessage *msg = create_message_with_field("field1", "oldvalue"); invoke_rewrite_rule(test_rewrite, msg); assert_msg_field_equals(msg, "field1", "value", -1, ASSERTION_ERROR("Couldn't set message field")); rewrite_teardown(msg); }
void test_set_field_cloned() { LogRewrite *test_rewrite = create_rewrite_rule("groupset(\"value\" values(\"field1\") condition( program(\"program\") ) );"); LogPipe *cloned_rule = log_pipe_clone(&test_rewrite->super); assert_true(cloned_rule != NULL, ASSERTION_ERROR("Can't cloned the rewrite")); log_pipe_unref(cloned_rule); cfg_free(configuration); }
void test_set_field_exist_and_group_set_when_condition_matches() { LogRewrite *test_rewrite = create_rewrite_rule("groupset(\"value\" values(\"field1\") condition( program(\"program\") ) );"); LogMessage *msg = create_message_with_fields("field1", "oldvalue", "PROGRAM", "program", NULL); invoke_rewrite_rule(test_rewrite, msg); assert_msg_field_equals(msg, "field1", "value", -1, ASSERTION_ERROR("Shouldn't rewrite when condition doesn't match")); rewrite_teardown(msg); }
void test_set_field_not_exist_and_set_literal_string() { LogRewrite *test_rewrite = create_rewrite_rule("set(\"value\" value(\"field1\") );"); LogMessage *msg = log_msg_new_empty(); invoke_rewrite_rule(test_rewrite, msg); assert_msg_field_equals(msg, "field1", "value", -1, ASSERTION_ERROR("Couldn't set message field when it doesn't exists")); rewrite_teardown(msg); }
void test_subst_field_exist_and_substring_substituted_with_template() { LogRewrite *test_rewrite = create_rewrite_rule("subst(\"substring\" \"$field2\" value(\"field1\") );"); LogMessage *msg = create_message_with_fields("field1", "asubstringb", "field2","substitute", NULL); invoke_rewrite_rule(test_rewrite, msg); assert_msg_field_equals(msg, "field1", "asubstituteb", -1, ASSERTION_ERROR("Couldn't subst message field with template")); rewrite_teardown(msg); }
void test_subst_field_exist_and_substring_substituted_every_occurence_with_global() { LogRewrite *test_rewrite = create_rewrite_rule("subst(\"substring\" \"substitute\" value(\"field1\") flags(global) );"); LogMessage *msg = create_message_with_fields("field1", "substring substring", NULL); invoke_rewrite_rule(test_rewrite, msg); assert_msg_field_equals(msg, "field1", "substitute substitute", -1, ASSERTION_ERROR("Field substituted less than every occurence with global flag")); rewrite_teardown(msg); }
void test_set_field_honors_time_zone() { LogRewrite *test_rewrite = create_rewrite_rule("set('${ISODATE}' value('UTCDATE') time-zone('Asia/Tokyo'));"); LogMessage *msg = create_message_with_fields("field1", "a123b", NULL); invoke_rewrite_rule(test_rewrite, msg); assert_msg_field_equals(msg, "UTCDATE", "1970-01-01T08:59:59+09:00", -1, ASSERTION_ERROR("Couldn't use time-zone option in rewrite-set")); rewrite_teardown(msg); }
void test_set_field_exist_and_group_set_template_string_with_old_value() { LogRewrite *test_rewrite = create_rewrite_rule("groupset(\"$_ alma\" values(\"field1\") );"); LogMessage *msg = create_message_with_field("field1", "value"); invoke_rewrite_rule(test_rewrite, msg); assert_msg_field_equals(msg, "field1", "value alma", -1, ASSERTION_ERROR("Couldn't set message field")); rewrite_teardown(msg); }
void handle_new_entry(gpointer user_data) { Journald *journald = user_data; journald_process(journald); assert_false(poll_triggered, ASSERTION_ERROR("Should called only once")); poll_triggered = TRUE; }
static void test_rewind_over_eof(LogQueueDiskReliable *dq) { LogMessage *msg3 = log_msg_new_mark(); LogMessage *read_message3; LogPathOptions local_options = LOG_PATH_OPTIONS_INIT; msg3->ack_func = _dummy_ack; log_queue_push_tail(&dq->super.super, msg3, &local_options); gint64 previous_read_head = dq->super.qdisk->hdr->read_head; read_message3 = log_queue_pop_head(&dq->super.super, &local_options); assert_true(read_message3 != NULL, ASSERTION_ERROR("Can't read message from queue")); assert_gint(dq->super.qdisk->hdr->read_head, dq->super.qdisk->hdr->write_head, ASSERTION_ERROR("Read head in bad position")); assert_true(msg3 == read_message3, ASSERTION_ERROR("Message 3 isn't read from qreliable")); log_msg_unref(read_message3); log_queue_rewind_backlog(&dq->super.super, 1); assert_gint(dq->super.qdisk->hdr->read_head, previous_read_head, ASSERTION_ERROR("Read head is corrupted")); read_message3 = log_queue_pop_head(&dq->super.super, &local_options); assert_true(read_message3 != NULL, ASSERTION_ERROR("Can't read message from queue")); assert_gint(dq->super.qdisk->hdr->read_head, dq->super.qdisk->hdr->write_head, ASSERTION_ERROR("Read head in bad position")); assert_true(msg3 == read_message3, ASSERTION_ERROR("Message 3 isn't read from qreliable")); log_msg_drop(msg3, &local_options, AT_PROCESSED); }
void Assertion_Failed(const char* function,const char* file,unsigned int line,const char* condition,const std::string& message) { std::string error=STRING_UTILITIES::string_sprintf("%s:%s:%d: %s, condition = %s",file,function,line,message.c_str(),condition); LOG::cout<<std::flush;LOG::cerr<<"\n"; PROCESS_UTILITIES::Backtrace(); LOG::cerr<<"\n*** ERROR: "<<error<<'\n'<<std::endl; PROCESS_UTILITIES::Set_Backtrace(false); throw ASSERTION_ERROR(error); }
void test_rewind_backlog_use_whole_qbacklog(LogQueueDiskReliable *dq) { /* * Rewind more 2 messages * - the reader the should be moved to the backlog head * - the qreliable should contain 3 items * - the qbackbacklog should be empty */ log_queue_rewind_backlog(&dq->super.super, 2); assert_gint64(dq->super.qdisk->hdr->read_head, dq->super.qdisk->hdr->backlog_head, ASSERTION_ERROR("Bad reader position")); assert_gint(dq->qreliable->length, NUMBER_MESSAGES_IN_QUEUE(3), ASSERTION_ERROR("Incorrect number of items in the qreliable")); assert_gint(dq->qbacklog->length, 0, ASSERTION_ERROR("Incorrect number of items in the qbacklog")); }
void test_condition_success() { LogRewrite *test_rewrite = create_rewrite_rule("set(\"00100\", value(\"device_id\") condition(program(\"ARCGIS\")));"); LogMessage *msg = create_message_with_field("PROGRAM", "ARCGIS"); invoke_rewrite_rule(test_rewrite, msg); assert_msg_field_equals(msg, "device_id", "00100", -1, ASSERTION_ERROR("Bad device_id")); rewrite_teardown(msg); }
void __test_other_has_prefix(TestCase *self, LogMessage *msg) { gchar *requested_name = g_strdup_printf("%s%s", (gchar *) self->user_data, "_CMDLINE"); NVHandle handle = log_msg_get_value_handle(requested_name); gssize value_len; const gchar *value = log_msg_get_value(msg, handle, &value_len); assert_string(value, "sshd: foo_user [priv]", ASSERTION_ERROR("Bad value for prefixed key")); g_free(requested_name); }
void __test_message_has_no_prefix(TestCase *self, LogMessage *msg) { gchar *requested_name = g_strdup_printf("%s%s", (gchar *)self->user_data, "MESSAGE"); NVHandle handle = log_msg_get_value_handle(requested_name); gssize value_len; log_msg_get_value(msg, handle, &value_len); assert_gint(value_len, 0, ASSERTION_ERROR("MESSAGE has prefix")); g_free(requested_name); }