void
test_cloning_with_log_message(gchar *msg)
{
  LogMessage *original_log_message, *log_message, *cloned_log_message;
  regex_t bad_hostname;
  GSockAddr *addr = g_sockaddr_inet_new("10.10.10.10", 1010);
  LogPathOptions path_options = LOG_PATH_OPTIONS_INIT;

  testcase_begin("Testing log message cloning; msg='%s'", msg);

  parse_options.flags = LP_SYSLOG_PROTOCOL;
  parse_options.bad_hostname = &bad_hostname;

  original_log_message = log_msg_new(msg, strlen(msg), addr, &parse_options);
  log_message = log_msg_new(msg, strlen(msg), addr, &parse_options);

  log_msg_set_tag_by_name(log_message, "newtag");
  path_options.ack_needed = FALSE;

  cloned_log_message = log_msg_clone_cow(log_message, &path_options);
  assert_log_messages_equal(cloned_log_message, original_log_message);

  set_new_log_message_attributes(cloned_log_message);

  assert_log_messages_equal(log_message, original_log_message);
  assert_new_log_message_attributes(cloned_log_message);
  assert_log_message_has_tag(cloned_log_message, "newtag");

  log_msg_unref(cloned_log_message);
  log_msg_unref(log_message);
  log_msg_unref(original_log_message);

  testcase_end();
}
示例#2
0
static void
test_type_hint_parse(void)
{
  TypeHint t;
  GError *e = NULL;

  testcase_begin("Testing type hint parsing");

  assert_type_hint(NULL, TYPE_HINT_STRING);
  assert_type_hint("string", TYPE_HINT_STRING);
  assert_type_hint("literal", TYPE_HINT_LITERAL);
  assert_type_hint("boolean", TYPE_HINT_BOOLEAN);
  assert_type_hint("int", TYPE_HINT_INT32);
  assert_type_hint("int32", TYPE_HINT_INT32);
  assert_type_hint("int64", TYPE_HINT_INT64);
  assert_type_hint("datetime", TYPE_HINT_DATETIME);
  assert_type_hint("default", TYPE_HINT_DEFAULT);

  assert_false(type_hint_parse("invalid-hint", &t, &e),
               "Parsing an invalid hint results in an error.");

  assert_error(e, TYPE_HINTING_INVALID_TYPE, "invalid-hint");

  testcase_end();
}
示例#3
0
static void
test_pipe_init_fail (void)
{
  testcase_begin ("A pipe that always fails, results in an unstartable tree");

  assert_almighty_always_pipe (FALSE, FALSE, TRUE, TRUE, FALSE);

  testcase_end ();
}
示例#4
0
static void
test_pipe_init_success (void)
{
  testcase_begin ("A pipe that always succeeds, results in a startable tree");

  assert_almighty_always_pipe (TRUE, TRUE, TRUE, TRUE, TRUE);

  testcase_end ();
}
示例#5
0
static gboolean
_execute(const gchar *testcase, Checks checks, const gchar *user_data)
{
  gboolean uri_init_ok = _after_test();

  testcase_begin("%s(%s, %s)", __FUNCTION__, testcase, user_data);
  if (!checks(user_data))
    _tests_failed = 1;
  reset_grabbed_messages();
  testcase_end();

  _free_test();
  _before_test();
  return uri_init_ok;
}
示例#6
0
static void
test_type_cast(void)
{
  GError *error = NULL;
  gboolean ob;
  gint32 i32;
  gint64 i64;
  guint64 dt;

  testcase_begin("Testing type casting");

  /* Boolean */

  assert_bool_cast("True", TRUE);
  assert_bool_cast("true", TRUE);
  assert_bool_cast("1", TRUE);
  assert_bool_cast("totally true", TRUE);
  assert_bool_cast("False", FALSE);
  assert_bool_cast("false", FALSE);
  assert_bool_cast("0", FALSE);
  assert_bool_cast("fatally false", FALSE);

  assert_type_cast_fail(boolean, "booyah", &ob);

  /* int32 */
  assert_int_cast("12345", 32, 12345);
  assert_type_cast_fail(int32, "12345a", &i32);

  /* int64 */
  assert_int_cast("12345", 64, 12345);
  assert_type_cast_fail(int64, "12345a", &i64);

  /* datetime */
  assert_type_cast(datetime_int, "12345", &dt);
  assert_guint64(dt, 12345000, "Casting '12345' to datetime works");
  assert_type_cast(datetime_int, "12345.5", &dt);
  assert_guint64(dt, 12345500, "Casting '12345.5' to datetime works");
  assert_type_cast(datetime_int, "12345.54", &dt);
  assert_guint64(dt, 12345540, "Casting '12345.54' to datetime works");
  assert_type_cast(datetime_int, "12345.543", &dt);
  assert_guint64(dt, 12345543, "Casting '12345.543' to datetime works");
  assert_type_cast(datetime_int, "12345.54321", &dt);
  assert_guint64(dt, 12345543, "Casting '12345.54321' to datetime works");

  assert_type_cast_fail(datetime_int, "invalid", &dt);

  testcase_end();
}
void
test_kmsg_device_parsing(void)
{
  gchar msg_subsys[] = "6,202,98513;pci_root PNP0A08:00: host bridge window [io  0x0000-0x0cf7]\n" \
    " SUBSYSTEM=acpi\n" \
    " DEVICE=+acpi:PNP0A08:00\n";
  gchar msg_block[] = "6,202,98513;Fake message\n" \
    " DEVICE=b12:1\n";
  gchar msg_char[] = "6,202,98513;Fake message\n" \
    " DEVICE=c3:4\n";
  gchar msg_netdev[] = "6,202,98513;Fake message\n" \
    " DEVICE=n8\n";
  gchar msg_unknown[] = "6,202,98513;Fake message\n" \
    " DEVICE=w12345\n";
  LogMessage *parsed_message;

  testcase_begin("Testing /dev/kmsg DEVICE= parsing");

  parsed_message = kmsg_parse_message(msg_subsys);
  assert_log_kmsg_value(parsed_message, ".linux.DEVICE.type", "acpi");
  assert_log_kmsg_value(parsed_message, ".linux.DEVICE.name", "PNP0A08:00");
  log_msg_unref(parsed_message);

  parsed_message = kmsg_parse_message(msg_block);
  assert_log_kmsg_value(parsed_message, ".linux.DEVICE.type", "block");
  assert_log_kmsg_value(parsed_message, ".linux.DEVICE.major", "12");
  assert_log_kmsg_value(parsed_message, ".linux.DEVICE.minor", "1");
  log_msg_unref(parsed_message);

  parsed_message = kmsg_parse_message(msg_char);
  assert_log_kmsg_value(parsed_message, ".linux.DEVICE.type", "char");
  assert_log_kmsg_value(parsed_message, ".linux.DEVICE.major", "3");
  assert_log_kmsg_value(parsed_message, ".linux.DEVICE.minor", "4");
  log_msg_unref(parsed_message);

  parsed_message = kmsg_parse_message(msg_netdev);
  assert_log_kmsg_value(parsed_message, ".linux.DEVICE.type", "netdev");
  assert_log_kmsg_value(parsed_message, ".linux.DEVICE.index", "8");
  log_msg_unref(parsed_message);

  parsed_message = kmsg_parse_message(msg_unknown);
  assert_log_kmsg_value(parsed_message, ".linux.DEVICE.type", "<unknown>");
  assert_log_kmsg_value(parsed_message, ".linux.DEVICE.name", "w12345");
  log_msg_unref(parsed_message);

  testcase_end();
}
void
test_kmsg_with_extra_fields(void)
{
  gchar msg[] = "5,2,0,some extra field,3,4,5;And this is the real message\n";
  LogMessage *parsed_message;

  testcase_begin("Testing /dev/kmsg parsing, with extra fields; msg='%s'", msg);

  parsed_message = kmsg_parse_message(msg);
  assert_guint16(parsed_message->pri, 5, "Unexpected message priority");
  assert_log_message_value(parsed_message, LM_V_MSGID, "2");
  assert_log_message_value(parsed_message, LM_V_MESSAGE, "And this is the real message");

  log_msg_unref(parsed_message);

  testcase_end();
}
void
test_kmsg_single_line(void)
{
  gchar msg[] = "5,2,1;Linux version 3.5-trunk-amd64 (Debian 3.5.2-1~experimental.1) ([email protected]) (gcc version 4.6.3 (Debian 4.6.3-1) ) #1 SMP Mon Aug 20 04:17:46 UTC 2012\n";
  LogMessage *parsed_message;

  testcase_begin("Testing single-line /dev/kmsg parsing; msg='%s'", msg);

  parsed_message = kmsg_parse_message(msg);

  assert_guint16(parsed_message->pri, 5, "Unexpected message priority");
  assert_log_message_value(parsed_message, LM_V_MSGID, "2");
  msg[sizeof(msg) - 2] = '\0';
  assert_log_message_value(parsed_message, LM_V_MESSAGE, msg + 6);
  assert_log_kmsg_value(parsed_message, ".linux.timestamp", "1");

  log_msg_unref(parsed_message);

  testcase_end();
}
示例#10
0
static void
test_template_on_error(void)
{
  testcase_begin("Testing LogTemplate on-error parsing");

  assert_on_error_parse("drop-message", ON_ERROR_DROP_MESSAGE);
  assert_on_error_parse("silently-drop-message",
                        ON_ERROR_DROP_MESSAGE | ON_ERROR_SILENT);

  assert_on_error_parse("drop-property", ON_ERROR_DROP_PROPERTY);
  assert_on_error_parse("silently-drop-property",
                        ON_ERROR_DROP_PROPERTY | ON_ERROR_SILENT);

  assert_on_error_parse("fallback-to-string", ON_ERROR_FALLBACK_TO_STRING);
  assert_on_error_parse("silently-fallback-to-string",
                        ON_ERROR_FALLBACK_TO_STRING | ON_ERROR_SILENT);

  assert_on_error_parse_fails("do-what-i-mean");

  testcase_end();
}
示例#11
0
static void
test_pipe_init_multi_success (void)
{
  CfgTree tree;

  testcase_begin ("A pipe of all good nodes will start & stop properly");

  cfg_tree_init_instance (&tree, NULL);

  create_and_attach_almighty_pipe (&tree, TRUE);
  create_and_attach_almighty_pipe (&tree, TRUE);
  create_and_attach_almighty_pipe (&tree, TRUE);

  assert_true (cfg_tree_start (&tree),
               "Starting a tree of all-good nodes works");
  assert_true (cfg_tree_stop (&tree),
               "Stopping a tree of all-good nodes works");

  cfg_tree_free_instance (&tree);

  testcase_end ();
}
void
test_kmsg_multi_line(void)
{
  gchar msg[] = "6,202,98513;pci_root PNP0A08:00: host bridge window [io  0x0000-0x0cf7]\n" \
    " SUBSYSTEM=acpi\n" \
    " DEVICE=+acpi:PNP0A08:00\n";
  LogMessage *parsed_message;

  testcase_begin("Testing multi-line /dev/kmsg parsing; msg='%s'", msg);

  parsed_message = kmsg_parse_message(msg);

  assert_guint16(parsed_message->pri, 6, "Unexpected message priority");
  assert_log_message_value(parsed_message, LM_V_MSGID, "202");
  assert_log_message_value(parsed_message, LM_V_MESSAGE, "pci_root PNP0A08:00: host bridge window [io  0x0000-0x0cf7]");
  assert_log_kmsg_value(parsed_message, ".linux.SUBSYSTEM", "acpi");
  assert_log_kmsg_value(parsed_message, ".linux.DEVICE.type", "acpi");
  assert_log_kmsg_value(parsed_message, ".linux.DEVICE.name", "PNP0A08:00");

  log_msg_unref(parsed_message);

  testcase_end();
}
示例#13
0
static void
test_pipe_init_multi_with_bad_node (void)
{
  AlmightyAlwaysPipe *pipe1, *pipe2, *pipe3;
  CfgTree tree;

  testcase_begin ("A pipe of some bad nodes will not start, but cleans up nicely.");

  cfg_tree_init_instance (&tree, NULL);

  pipe1 = create_and_attach_almighty_pipe (&tree, TRUE);
  pipe2 = create_and_attach_almighty_pipe (&tree, FALSE);
  pipe3 = create_and_attach_almighty_pipe (&tree, TRUE);

  assert_false (cfg_tree_start (&tree),
               "Starting a tree of all-good nodes works");
  assert_true (cfg_tree_stop (&tree),
               "Stopping a tree of all-good nodes works");

  assert_true (pipe1->init_called,
               "The initializer of the first good pipe is called");
  assert_true (pipe2->init_called,
               "The initializer of the bad pipe is called");
  assert_false (pipe3->init_called,
                "The initializer of the second good pipe is NOT called");

  assert_true (pipe1->deinit_called,
               "The deinitializer of the first good pipe is called");
  assert_false (pipe2->deinit_called,
               "The deinitializer of the bad pipe is NOT called");
  assert_false (pipe3->deinit_called,
               "The deinitializer of the second good pipe is NOT called");

  cfg_tree_free_instance (&tree);

  testcase_end ();
}
示例#14
0
void
testcase(gchar *msg,
         gint parse_flags,
         gchar *bad_hostname_re,
         gint expected_pri,
         unsigned long expected_stamp_sec,
         unsigned long expected_stamp_usec,
         unsigned long expected_stamp_ofs,
         const gchar *expected_host,
         const gchar *expected_program,
         const gchar *expected_msg,
         const gchar *expected_sd_str,
         const gchar *expected_pid,
         const gchar *expected_msgid,
         const gchar *expected_sd_pairs[][2])
{
  LogMessage *parsed_message;
  LogStamp *parsed_timestamp;
  time_t now;
  GString *sd_str;

  testcase_begin("Testing log message parsing; parse_flags='%x', bad_hostname_re='%s', msg='%s'",
                 parse_flags, bad_hostname_re ? : "(null)", msg);

  parsed_message = parse_log_message(msg, parse_flags, bad_hostname_re);
  parsed_timestamp = &(parsed_message->timestamps[LM_TS_STAMP]);

  if (expected_stamp_sec)
    {
      if (expected_stamp_sec != 1)
        assert_guint(parsed_timestamp->tv_sec, expected_stamp_sec, "Unexpected timestamp");
      assert_guint32(parsed_timestamp->tv_usec, expected_stamp_usec, "Unexpected microseconds");
      assert_guint32(parsed_timestamp->zone_offset, expected_stamp_ofs, "Unexpected timezone offset");
    }
  else
    {
      time(&now);
      assert_true(absolute_value(parsed_timestamp->tv_sec - now) <= 5,
                  "Expected parsed message timestamp to be set to now; now='%d', timestamp->tv_sec='%d'",
                  (gint)now, (gint)parsed_timestamp->tv_sec, NULL);
    }
  assert_guint16(parsed_message->pri, expected_pri, "Unexpected message priority");
  assert_log_message_value(parsed_message, LM_V_HOST, expected_host);
  assert_log_message_value(parsed_message, LM_V_PROGRAM, expected_program);
  assert_log_message_value(parsed_message, LM_V_MESSAGE, expected_msg);
  if (expected_pid)
    assert_log_message_value(parsed_message, LM_V_PID, expected_pid);
  if (expected_msgid)
    assert_log_message_value(parsed_message, LM_V_MSGID, expected_msgid);
  if (expected_sd_str)
    {
      sd_str = g_string_sized_new(0);
      log_msg_format_sdata(parsed_message, sd_str, 0);
      assert_string(sd_str->str, expected_sd_str, "Unexpected formatted SData");
      g_string_free(sd_str, TRUE);
    }

  assert_log_message_sdata_pairs(parsed_message, expected_sd_pairs);

  log_msg_unref(parsed_message);

  testcase_end();
}
示例#15
0
i4
Is_it_If_statement(FILE *testFile,i4 *counter,bool Ignore_it)
{
    char                  *cp1 = NULL ;
    char                  *cp2 = NULL ;
    i4                     cmd ;
    bool                   yes_its_if = FALSE ;
    bool                   yes_its_tc = FALSE ;

    cmd = 0;
    if ((!shellMode)&&(SEP_CMstlen(lineTokens[0],0) > 1)&&
	(CMcmpcase(lineTokens[0],ERx(".")) == 0))
    {
	cp1 = buffer_1 ;		/* Fix the ".if" statement. */
	cp2 = buffer_2 ;

	STcopy(buffer_1, holdBuf);
	CMcpyinc(cp1,cp2);
	CMcpychar(ERx(" "),cp2);
	CMnext(cp2);
	STcopy(cp1, cp2);
	STcopy(buffer_2, buffer_1);
	break_line(buffer_2, counter, lineTokens);
    }

    cmd = classify_cmmd(sepcmmds, lineTokens[1]);
    if (cmd == IF_CMMD || cmd == ELSE_CMMD || cmd == ENDIF_CMMD)
    {
	yes_its_if = TRUE;
    }
    else if (cmd == TEST_CASE_CMMD || cmd == TEST_CASE_END_CMMD)
    {
	yes_its_tc = TRUE;
    }

    if (yes_its_if || yes_its_tc)
    {
	append_line(holdBuf, 0);

	if (Ignore_it)
	    ignore_silent == TRUE;

	if (yes_its_if)
	{
	    process_if(testFile, lineTokens, cmd);
	}
	else if (yes_its_tc)
	{
	    if (cmd == TEST_CASE_CMMD)
	    {
		testcase_start(&lineTokens[1]);
	    }
	    else if (cmd == TEST_CASE_END_CMMD)
	    {
		testcase_end(FALSE);
	    }
	}

	if (Ignore_it)
	    ignore_silent == FALSE;
    }
    else
    {
	cmd = 0;
    }

    return (cmd);
}
示例#16
0
static void
test_type_cast(void)
{
  GError *error = NULL;
  gboolean ob;
  gint32 i32;
  gint64 i64;
  guint64 dt;
  gdouble d;

  testcase_begin("Testing type casting");

  /* Boolean */

  assert_bool_cast("True", TRUE);
  assert_bool_cast("true", TRUE);
  assert_bool_cast("1", TRUE);
  assert_bool_cast("totally true", TRUE);
  assert_bool_cast("False", FALSE);
  assert_bool_cast("false", FALSE);
  assert_bool_cast("0", FALSE);
  assert_bool_cast("fatally false", FALSE);

  assert_type_cast_fail(boolean, "booyah", &ob);

  /* int32 */
  assert_int_cast("12345", 32, 12345);
  assert_type_cast_fail(int32, "12345a", &i32);

  /* int64 */
  assert_int_cast("12345", 64, 12345);
  assert_type_cast_fail(int64, "12345a", &i64);

  /* double */
  assert_double_cast("1.0", 1.0);
  assert_type_cast_fail(double, "2.0bad", &d);
  assert_type_cast_fail(double, "bad", &d);
  assert_type_cast_fail(double, "", &d);
  assert_type_cast_fail(double, "1e1000000", &d);
  assert_type_cast_fail(double, "-1e1000000", &d);
  assert_double_cast("1e-100000000", 0.0);
#ifdef INFINITY
  assert_double_cast("INF", INFINITY);
#endif

  /* datetime */
  assert_type_cast(datetime_int, "12345", &dt);
  assert_guint64(dt, 12345000, "Casting '12345' to datetime works");
  assert_type_cast(datetime_int, "12345.5", &dt);
  assert_guint64(dt, 12345500, "Casting '12345.5' to datetime works");
  assert_type_cast(datetime_int, "12345.54", &dt);
  assert_guint64(dt, 12345540, "Casting '12345.54' to datetime works");
  assert_type_cast(datetime_int, "12345.543", &dt);
  assert_guint64(dt, 12345543, "Casting '12345.543' to datetime works");
  assert_type_cast(datetime_int, "12345.54321", &dt);
  assert_guint64(dt, 12345543, "Casting '12345.54321' to datetime works");

  assert_type_cast_fail(datetime_int, "invalid", &dt);

  testcase_end();
}