]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
test-journal-importer: add a test case with broken input
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sun, 6 Nov 2016 05:01:17 +0000 (01:01 -0400)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Wed, 15 Feb 2017 05:31:55 +0000 (00:31 -0500)
Makefile.am
src/test/test-journal-importer.c
test/journal-data/journal-2.txt [new file with mode: 0644]

index fef13fabcd455f75ae50f5b27040f89b4b255d12..10839e922a17b4e3603ce4ae6ef1e988deb2d2d7 100644 (file)
@@ -2470,7 +2470,8 @@ test_journal_importer_LDADD = \
        libsystemd-shared.la
 
 EXTRA_DIST += \
-       test/journal-data/journal-1.txt
+       test/journal-data/journal-1.txt \
+       test/journal-data/journal-2.txt
 
 # ------------------------------------------------------------------------------
 ## .PHONY so it always rebuilds it
index fea5c1d51c4dba44048a79a1a98e01de8e5885bf..1f0684863e991bed0dc1a739a381d2bdb222b040 100644 (file)
@@ -44,7 +44,7 @@ static void test_basic_parsing(void) {
 
         do
                 r = journal_importer_process_data(&imp);
-        while (r == 0);
+        while (r == 0 && !journal_importer_eof(&imp));
         assert_se(r == 1);
 
         /* We read one entry, so we should get EOF on next read, but not yet */
@@ -64,11 +64,27 @@ static void test_basic_parsing(void) {
         assert_se(journal_importer_eof(&imp));
 }
 
+static void test_bad_input(void) {
+        _cleanup_(journal_importer_cleanup) JournalImporter imp = {};
+        int r;
+
+        imp.fd = open(TEST_DATA_DIR("/journal-data/journal-2.txt"), O_RDONLY|O_CLOEXEC);
+        assert_se(imp.fd >= 0);
+
+        do
+                r = journal_importer_process_data(&imp);
+        while (!journal_importer_eof(&imp));
+        assert_se(r == 0); /* If we don't have enough input, 0 is returned */
+
+        assert_se(journal_importer_eof(&imp));
+}
+
 int main(int argc, char **argv) {
         log_set_max_level(LOG_DEBUG);
         log_parse_environment();
 
         test_basic_parsing();
+        test_bad_input();
 
         return 0;
 }
diff --git a/test/journal-data/journal-2.txt b/test/journal-data/journal-2.txt
new file mode 100644 (file)
index 0000000..4f582a0
Binary files /dev/null and b/test/journal-data/journal-2.txt differ