summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGergely Nagy <algernon@balabit.hu>2012-08-11 01:13:37 +0200
committerGergely Nagy <algernon@balabit.hu>2012-08-11 01:20:47 +0200
commit1dfe00133e63764ece587ba75084dcf275bb22ab (patch)
tree0e21357f37d97ed501fa3216a73851009b4f8e14
parentfbeba09ae5050ef0adf2791b9d1a29993e9f6658 (diff)
downloadlibumberlog-1dfe00133e63764ece587ba75084dcf275bb22ab.tar.gz
libumberlog-1dfe00133e63764ece587ba75084dcf275bb22ab.tar.xz
libumberlog-1dfe00133e63764ece587ba75084dcf275bb22ab.zip
Test reorganisation
Moved some tests around between test_umberlog and test_umberlog_preload, so only those tests remain in test_umberlog_preload that do test something that the LD_PRELOAD lib variant provides. Also added a comment above each test to quickly clarify what they're meant to test. Signed-off-by: Gergely Nagy <algernon@balabit.hu>
-rw-r--r--t/test_umberlog.c188
-rw-r--r--t/test_umberlog_preload.c220
2 files changed, 230 insertions, 178 deletions
diff --git a/t/test_umberlog.c b/t/test_umberlog.c
index 9be5d08..68b5a95 100644
--- a/t/test_umberlog.c
+++ b/t/test_umberlog.c
@@ -15,6 +15,9 @@
#include <check.h>
+/**
+ * Test the umberlog defaults.
+ */
START_TEST (test_defaults)
{
char *msg;
@@ -46,6 +49,10 @@ START_TEST (test_defaults)
}
END_TEST
+/**
+ * Test that openlog() is not overridden when using the linkable
+ * library.
+ */
START_TEST (test_overrides)
{
char *msg;
@@ -80,6 +87,10 @@ START_TEST (test_overrides)
}
END_TEST
+/**
+ * Test that using ul_openlog() does work, and sets up the program
+ * identity appropriately.
+ */
START_TEST (test_ul_openlog)
{
char *msg;
@@ -110,6 +121,9 @@ START_TEST (test_ul_openlog)
}
END_TEST
+/**
+ * Test that ul_openlog() will ignore any LOG_UL_* flags.
+ */
START_TEST (test_ul_openlog_flag_ignore)
{
char *msg;
@@ -133,6 +147,10 @@ START_TEST (test_ul_openlog_flag_ignore)
}
END_TEST
+/**
+ * Test that setting LOG_UL_NOIMPLICIT will, indeed, turn off
+ * automatically discovered fields.
+ */
START_TEST (test_no_implicit)
{
char *msg;
@@ -161,6 +179,9 @@ START_TEST (test_no_implicit)
}
END_TEST
+/**
+ * Test turning off the timestamp.
+ */
START_TEST (test_no_timestamp)
{
char *msg;
@@ -189,6 +210,9 @@ START_TEST (test_no_timestamp)
}
END_TEST
+/**
+ * Test that closelog() does not clear the previous flag settings.
+ */
START_TEST (test_closelog)
{
char *msg;
@@ -225,12 +249,164 @@ START_TEST (test_closelog)
}
END_TEST
+/**
+ * Test adding additional fields.
+ */
+START_TEST (test_additional_fields)
+{
+ char *msg;
+ struct json_object *jo;
+
+ ul_openlog ("umberlog/test_additional_fields", 0, LOG_LOCAL0);
+
+ msg = ul_format (LOG_DEBUG, "testing 1, 2, 3...",
+ "random_number", "%d", 42,
+ "random_string", "fourty-two",
+ NULL);
+ jo = parse_msg (msg);
+ free (msg);
+
+ verify_value (jo, "msg", "testing 1, 2, 3...");
+ verify_value (jo, "random_number", "42");
+ verify_value (jo, "random_string", "fourty-two");
+
+ json_object_put (jo);
+
+ ul_closelog ();
+}
+END_TEST
+
+/**
+ * Test that discovering priorities work, and the implicit pid
+ * overrides the explicit one.
+ */
+START_TEST (test_discover_priority)
+{
+ char *msg, *pid;
+ struct json_object *jo;
+
+ ul_openlog ("umberlog/test_discover_priority", 0, LOG_LOCAL0);
+
+ msg = ul_format (LOG_DEBUG, "testing 1, 2, 3...",
+ "pid", "%d", getpid () + 42,
+ NULL);
+ jo = parse_msg (msg);
+ free (msg);
+
+ verify_value (jo, "msg", "testing 1, 2, 3...");
+
+ if (asprintf (&pid, "%d", getpid ()) == -1)
+ abort ();
+ verify_value (jo, "pid", pid);
+ free (pid);
+
+ json_object_put (jo);
+
+ ul_closelog ();
+}
+END_TEST
+
+/**
+ * Test for correct JSON escaping.
+ */
+START_TEST (test_json_escape)
+{
+ static const char control_chars[] =
+ "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"
+ "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f"
+ "\x20";
+
+ char *msg;
+ struct json_object *jo;
+
+ ul_openlog ("umberlog/test_json_escape", 0, LOG_LOCAL0);
+
+ msg = ul_format (LOG_DEBUG, "%s", __FUNCTION__,
+ "quotes", "Hi, \"quoted value\" speaking!",
+ "\"really\"", "yeah",
+ "control", "foo\nbar",
+ "utf8", "Árvíztűrő tükörfúrógép",
+ "junk", "\013foo",
+ "all_control", control_chars,
+ NULL);
+ jo = parse_msg (msg);
+ free (msg);
+
+ verify_value (jo, "quotes", "Hi, \"quoted value\" speaking!");
+ verify_value (jo, "\"really\"", "yeah");
+ verify_value (jo, "control", "foo\nbar");
+ verify_value (jo, "utf8", "Árvíztűrő tükörfúrógép");
+ verify_value (jo, "junk", "\013foo");
+ verify_value (jo, "all_control", control_chars);
+
+ json_object_put (jo);
+
+ ul_closelog ();
+}
+END_TEST
+
+/**
+ * Test that using a FACILITY | PRIORITY combo with ul_format has the
+ * desired result.
+ */
+START_TEST (test_facprio)
+{
+ char *msg;
+ struct json_object *jo;
+
+ msg = ul_format (LOG_LOCAL1 | LOG_DEBUG, "%s", __FUNCTION__,
+ NULL);
+ jo = parse_msg (msg);
+ free (msg);
+
+ verify_value (jo, "facility", "local1");
+ verify_value (jo, "priority", "debug");
+
+ json_object_put (jo);
+}
+END_TEST
+
+#ifdef HAVE_PARSE_PRINTF_FORMAT
+/**
+ * Test parsing additional format strings, that are only supported if
+ * we're under glibc.
+ */
+START_TEST (test_positional_params)
+{
+ char *msg;
+ struct json_object *jo;
+
+ ul_openlog ("umberlog/test_positional_params", 0, LOG_LOCAL0);
+
+#define COMPLEX_FORMAT \
+ "%3$*5$.*2$hhd , %1$Lf , %4$.3s , %4$s", 1.0L, 5, (char)100, "prefix", -8
+#define COMPLEX_RESULT "00100 , 1.000000 , pre , prefix"
+ msg = ul_format (LOG_DEBUG, COMPLEX_FORMAT,
+ "simple1", "value1",
+ "complex", COMPLEX_FORMAT,
+ "simple2", "value2",
+ NULL);
+ jo = parse_msg (msg);
+ free (msg);
+
+ verify_value (jo, "msg", COMPLEX_RESULT);
+ verify_value (jo, "simple1", "value1");
+ verify_value (jo, "complex", COMPLEX_RESULT);
+ verify_value (jo, "simple2", "value2");
+
+ json_object_put (jo);
+
+ ul_closelog ();
+}
+END_TEST
+#endif
+
int
main (void)
{
Suite *s;
SRunner *sr;
- TCase *ft;
+ TCase *ft, *bt;
int nfailed;
s = suite_create ("Umberlog (linkable) functional testsuite");
@@ -242,8 +418,18 @@ main (void)
tcase_add_test (ft, test_ul_openlog_flag_ignore);
tcase_add_test (ft, test_closelog);
tcase_add_test (ft, test_no_implicit);
+ tcase_add_test (ft, test_additional_fields);
+ tcase_add_test (ft, test_discover_priority);
+#ifdef HAVE_PARSE_PRINTF_FORMAT
+ tcase_add_test (ft, test_positional_params);
+#endif
suite_add_tcase (s, ft);
+ bt = tcase_create ("Bug tests");
+ tcase_add_test (bt, test_json_escape);
+ tcase_add_test (bt, test_facprio);
+ suite_add_tcase (s, bt);
+
sr = srunner_create (s);
srunner_run_all (sr, CK_ENV);
diff --git a/t/test_umberlog_preload.c b/t/test_umberlog_preload.c
index 66f8aad..99451c6 100644
--- a/t/test_umberlog_preload.c
+++ b/t/test_umberlog_preload.c
@@ -14,171 +14,12 @@
#include <check.h>
-START_TEST (test_simple)
-{
- char *msg;
- struct json_object *jo;
- char host[_POSIX_HOST_NAME_MAX + 1];
-
- openlog ("umberlog/test_simple", 0, LOG_LOCAL0);
-
- msg = ul_format (LOG_DEBUG, "hello, I'm %s!", __FUNCTION__, NULL);
- jo = parse_msg (msg);
- free (msg);
-
- gethostname (host, _POSIX_HOST_NAME_MAX);
-
- verify_value (jo, "msg", "hello, I'm test_simple!");
- verify_value (jo, "facility", "local0");
- verify_value (jo, "priority", "debug");
- verify_value (jo, "program", "umberlog/test_simple");
- verify_value_exists (jo, "pid");
- verify_value_exists (jo, "uid");
- verify_value_exists (jo, "gid");
- verify_value_exists (jo, "timestamp");
- verify_value (jo, "host", host);
-
- json_object_put (jo);
-
- closelog ();
-}
-END_TEST
-
-START_TEST (test_additional_fields)
-{
- char *msg;
- struct json_object *jo;
-
- openlog ("umberlog/test_additional_fields", 0, LOG_LOCAL0);
-
- msg = ul_format (LOG_DEBUG, "testing 1, 2, 3...",
- "random_number", "%d", 42,
- "random_string", "fourty-two",
- NULL);
- jo = parse_msg (msg);
- free (msg);
-
- verify_value (jo, "msg", "testing 1, 2, 3...");
- verify_value (jo, "random_number", "42");
- verify_value (jo, "random_string", "fourty-two");
-
- json_object_put (jo);
-
- closelog ();
-}
-END_TEST
-
-START_TEST (test_discover_priority)
-{
- char *msg, *pid;
- struct json_object *jo;
-
- openlog ("umberlog/test_discover_priority", 0, LOG_LOCAL0);
-
- msg = ul_format (LOG_DEBUG, "testing 1, 2, 3...",
- "pid", "%d", getpid () + 42,
- NULL);
- jo = parse_msg (msg);
- free (msg);
-
- verify_value (jo, "msg", "testing 1, 2, 3...");
-
- if (asprintf (&pid, "%d", getpid ()) == -1)
- abort ();
- verify_value (jo, "pid", pid);
- free (pid);
-
- json_object_put (jo);
-
- closelog ();
-}
-END_TEST
-
-START_TEST (test_json_escape)
-{
- static const char control_chars[] =
- "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"
- "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f"
- "\x20";
-
- char *msg;
- struct json_object *jo;
-
- openlog ("umberlog/test_json_escape", 0, LOG_LOCAL0);
-
- msg = ul_format (LOG_DEBUG, "%s", __FUNCTION__,
- "quotes", "Hi, \"quoted value\" speaking!",
- "\"really\"", "yeah",
- "control", "foo\nbar",
- "utf8", "Árvíztűrő tükörfúrógép",
- "junk", "\013foo",
- "all_control", control_chars,
- NULL);
- jo = parse_msg (msg);
- free (msg);
-
- verify_value (jo, "quotes", "Hi, \"quoted value\" speaking!");
- verify_value (jo, "\"really\"", "yeah");
- verify_value (jo, "control", "foo\nbar");
- verify_value (jo, "utf8", "Árvíztűrő tükörfúrógép");
- verify_value (jo, "junk", "\013foo");
- verify_value (jo, "all_control", control_chars);
-
- json_object_put (jo);
-
- closelog ();
-}
-END_TEST
-
-START_TEST (test_facprio)
-{
- char *msg;
- struct json_object *jo;
-
- msg = ul_format (LOG_LOCAL1 | LOG_DEBUG, "%s", __FUNCTION__,
- NULL);
- jo = parse_msg (msg);
- free (msg);
-
- verify_value (jo, "facility", "local1");
- verify_value (jo, "priority", "debug");
-
- json_object_put (jo);
-}
-END_TEST
-#ifdef HAVE_PARSE_PRINTF_FORMAT
-START_TEST (test_positional_params)
-{
- char *msg;
- struct json_object *jo;
-
- openlog ("umberlog/test_positional_params", 0, LOG_LOCAL0);
-
-#define COMPLEX_FORMAT \
- "%3$*5$.*2$hhd , %1$Lf , %4$.3s , %4$s", 1.0L, 5, (char)100, "prefix", -8
-#define COMPLEX_RESULT "00100 , 1.000000 , pre , prefix"
- msg = ul_format (LOG_DEBUG, COMPLEX_FORMAT,
- "simple1", "value1",
- "complex", COMPLEX_FORMAT,
- "simple2", "value2",
- NULL);
- jo = parse_msg (msg);
- free (msg);
-
- verify_value (jo, "msg", COMPLEX_RESULT);
- verify_value (jo, "simple1", "value1");
- verify_value (jo, "complex", COMPLEX_RESULT);
- verify_value (jo, "simple2", "value2");
-
- json_object_put (jo);
-
- closelog ();
-}
-END_TEST
-#endif
-
-/* This must be the first test! */
+/** This must be the first test!
+ *
+ * This check verifies the openlog() defaults, and that additional
+ * fields are properly added.
+ */
START_TEST (test_openlog_defaults)
{
char *msg;
@@ -209,6 +50,10 @@ START_TEST (test_openlog_defaults)
}
END_TEST
+/**
+ * This verifies that adding any LOG_UL_* flags to openlog() will have
+ * no effect.
+ */
START_TEST (test_openlog_flags)
{
char *msg;
@@ -239,6 +84,39 @@ START_TEST (test_openlog_flags)
}
END_TEST
+/**
+ * A simple test that options that should be respected, are respected.
+ */
+START_TEST (test_simple)
+{
+ char *msg;
+ struct json_object *jo;
+ char host[_POSIX_HOST_NAME_MAX + 1];
+
+ openlog ("umberlog/test_simple", 0, LOG_LOCAL0);
+
+ msg = ul_format (LOG_DEBUG, "hello, I'm %s!", __FUNCTION__, NULL);
+ jo = parse_msg (msg);
+ free (msg);
+
+ gethostname (host, _POSIX_HOST_NAME_MAX);
+
+ verify_value (jo, "msg", "hello, I'm test_simple!");
+ verify_value (jo, "facility", "local0");
+ verify_value (jo, "priority", "debug");
+ verify_value (jo, "program", "umberlog/test_simple");
+ verify_value_exists (jo, "pid");
+ verify_value_exists (jo, "uid");
+ verify_value_exists (jo, "gid");
+ verify_value_exists (jo, "timestamp");
+ verify_value (jo, "host", host);
+
+ json_object_put (jo);
+
+ closelog ();
+}
+END_TEST
+
int
main (void)
{
@@ -249,25 +127,13 @@ main (void)
s = suite_create ("Umberlog (LD_PRELOAD) functional testsuite");
- ft = tcase_create ("Basic tests");
#if DEFAULT_DISCOVER_FLAGS == LOG_UL_ALL
+ ft = tcase_create ("Basic tests");
tcase_add_test (ft, test_openlog_defaults);
tcase_add_test (ft, test_openlog_flags);
tcase_add_test (ft, test_simple);
- tcase_add_test (ft, test_discover_priority);
-#endif
- tcase_add_test (ft, test_additional_fields);
-#ifdef HAVE_PARSE_PRINTF_FORMAT
- tcase_add_test (ft, test_positional_params);
-#endif
suite_add_tcase (s, ft);
-
- bt = tcase_create ("Bug tests");
- tcase_add_test (bt, test_json_escape);
-#if DEFAULT_DISCOVER_FLAGS == LOG_UL_ALL
- tcase_add_test (bt, test_facprio);
#endif
- suite_add_tcase (s, bt);
sr = srunner_create (s);