Moved test from test_libdlogutil.c to libdlogutil_neg.c. 90/263490/14
authorHubert Kowalski <h.kowalski@samsung.com>
Thu, 2 Sep 2021 09:34:27 +0000 (11:34 +0200)
committerHubert Kowalski <h.kowalski@samsung.com>
Thu, 9 Sep 2021 09:07:30 +0000 (11:07 +0200)
negative_main test was moved to libdlogutil_neg as this test didn't really
test anything related to integration. Essentialy it was a misplaced unit test.
So it is moved where it belongs.

Change-Id: Idc8b4b005e7d3cc5a07a771915600d559994abd1

Makefile.am
src/tests/libdlogutil_neg.c [new file with mode: 0644]
src/tests/libdlogutil_pos.c [new file with mode: 0644]
tests/test_libdlogutil.c

index b3115c1..3917565 100644 (file)
@@ -438,7 +438,9 @@ check_PROGRAMS = \
        src/tests/deduplicate_test \
        src/tests/pid_limiter \
        src/tests/qos_distributions \
-       src/tests/filters
+       src/tests/filters \
+       src/tests/libdlogutil_neg \
+       src/tests/libdlogutil_pos
 
 check_CFLAGS = $(AM_CFLAGS) -O0 -fprofile-arcs -DUNIT_TEST \
        -DEXIT_SKIP=77 -DEXIT_HARD_ERROR=99 # autotools convention exit codes
@@ -709,6 +711,47 @@ src_tests_hash_test_SOURCES = src/tests/hash_test.c src/shared/hash.c
 src_tests_hash_test_CFLAGS = $(check_CFLAGS)
 src_tests_hash_test_LDFLAGS = $(AM_LDFLAGS)
 
+src_tests_libdlogutil_neg_SOURCES = src/tests/libdlogutil_neg.c  \
+       src/libdlogutil/lib.c \
+       src/shared/queued_entry_timestamp.c \
+       src/shared/logprint.c \
+       src/shared/ptrs_list.c \
+       src/libdlogutil/logretrieve.c \
+       src/shared/logcommon.c \
+       src/libdlogutil/fd_info.c \
+       src/libdlogutil/sort_vector.c \
+       src/shared/logconfig.c \
+       src/shared/parsers.c \
+       src/libdlogutil/fdi_pipe.c \
+       src/libdlogutil/fdi_logger.c \
+       src/shared/backend_androidlogger.c \
+       src/shared/queued_entry.c \
+       src/shared/translate_syslog.c
+src_tests_libdlogutil_neg_CFLAGS = $(check_CFLAGS) -DLIBDLOGUTIL_BUILD
+# Use LIBDLOGUTIL_BUILD because we're checking this from a client application PoV, not internal
+src_tests_libdlogutil_neg_LDFLAGS = $(AM_LDFLAGS)
+
+
+src_tests_libdlogutil_pos_SOURCES = src/tests/libdlogutil_pos.c  \
+       src/libdlogutil/lib.c \
+       src/shared/queued_entry_timestamp.c \
+       src/shared/logprint.c \
+       src/shared/ptrs_list.c \
+       src/libdlogutil/logretrieve.c \
+       src/shared/logcommon.c \
+       src/libdlogutil/fd_info.c \
+       src/libdlogutil/sort_vector.c \
+       src/shared/logconfig.c \
+       src/shared/parsers.c \
+       src/libdlogutil/fdi_pipe.c \
+       src/libdlogutil/fdi_logger.c \
+       src/shared/backend_androidlogger.c \
+       src/shared/queued_entry.c \
+       src/shared/translate_syslog.c
+src_tests_libdlogutil_pos_CFLAGS = $(check_CFLAGS) -DLIBDLOGUTIL_BUILD
+# Use LIBDLOGUTIL_BUILD because we're checking this from a client application PoV, not internal
+src_tests_libdlogutil_pos_LDFLAGS = $(AM_LDFLAGS)
+
 src_tests_metrics_SOURCES = src/tests/metrics.c \
        src/shared/metrics.c \
        src/shared/hash.c
diff --git a/src/tests/libdlogutil_neg.c b/src/tests/libdlogutil_neg.c
new file mode 100644 (file)
index 0000000..6b8ab19
--- /dev/null
@@ -0,0 +1,129 @@
+#include "../include/dlogutil.h"
+#include <stdlib.h>
+#include <assert.h>
+#include <logcommon.h>
+#include <dlog_ioctl.h>
+#include "../libdlogutil/logretrieve.h"
+
+void negative_main(void)
+{
+       void *bad_ptr = (void *)0xFA1L;
+
+       assert(TIZEN_ERROR_INVALID_PARAMETER == dlogutil_config_buffer_add(NULL, LOG_ID_MAIN));
+
+       dlogutil_config_s *c = dlogutil_config_create();
+       assert(c);
+       assert(TIZEN_ERROR_INVALID_PARAMETER == dlogutil_config_buffer_add(c, LOG_ID_INVALID));
+       assert(TIZEN_ERROR_INVALID_PARAMETER == dlogutil_config_buffer_add(c, LOG_ID_MAX));
+       assert(TIZEN_ERROR_INVALID_PARAMETER == dlogutil_config_buffer_add(c, (log_id_t) -1));
+       assert(TIZEN_ERROR_INVALID_PARAMETER == dlogutil_config_buffer_add(c, (log_id_t) 98));
+
+       dlogutil_state_s *s;
+       assert(TIZEN_ERROR_NONE == dlogutil_config_mode_set_continuous(c));
+
+       assert(TIZEN_ERROR_INVALID_PARAMETER == dlogutil_config_connect(c, &s)); // empty set
+
+       assert(TIZEN_ERROR_NONE == dlogutil_config_buffer_add(c, LOG_ID_MAIN));
+       assert(TIZEN_ERROR_NONE == dlogutil_config_buffer_add(c, LOG_ID_KMSG));
+       assert(TIZEN_ERROR_NOT_SUPPORTED == dlogutil_config_connect(c, &s)); // incompatible pair
+
+       // Invalid single buffer
+       const log_id_t invalid_ids[] =
+               { LOG_ID_INVALID
+               , LOG_ID_INVALID - 1
+               , LOG_ID_MAX
+               , LOG_ID_MAX + 1
+               , (log_id_t) -17
+               , (log_id_t) 42
+       };
+       for (size_t i = 0; i < NELEMS(invalid_ids); ++i) {
+               const log_id_t id = invalid_ids[i];
+               assert(dlogutil_buffer_get_name(id, bad_ptr) ==
+                       TIZEN_ERROR_INVALID_PARAMETER);
+               assert(dlogutil_buffer_get_default_ts_type(id, bad_ptr) ==
+                       TIZEN_ERROR_INVALID_PARAMETER);
+               assert(dlogutil_buffer_check_ts_type_available(id, DLOGUTIL_SORT_SENT_MONO, bad_ptr) ==
+                       TIZEN_ERROR_INVALID_PARAMETER);
+       }
+
+       // Retrieval of data from NULL
+       assert(dlogutil_entry_get_tid(NULL, bad_ptr) ==
+               TIZEN_ERROR_INVALID_PARAMETER);
+       assert(dlogutil_entry_get_pid(NULL, bad_ptr) ==
+               TIZEN_ERROR_INVALID_PARAMETER);
+       assert(dlogutil_entry_get_priority(NULL, bad_ptr) ==
+               TIZEN_ERROR_INVALID_PARAMETER);
+       assert(dlogutil_entry_get_timestamp(NULL, DLOGUTIL_SORT_RECV_MONO, bad_ptr) ==
+               TIZEN_ERROR_INVALID_PARAMETER);
+       assert(dlogutil_entry_get_tag(NULL, bad_ptr) ==
+               TIZEN_ERROR_INVALID_PARAMETER);
+       assert(dlogutil_entry_get_message(NULL, bad_ptr) ==
+               TIZEN_ERROR_INVALID_PARAMETER);
+       assert(dlogutil_buffer_get_alias(NULL, LOG_ID_MAIN, bad_ptr) ==
+               TIZEN_ERROR_INVALID_PARAMETER);
+
+       // Retrieval of data into NULL
+       assert(dlogutil_entry_get_tid(bad_ptr, NULL) ==
+               TIZEN_ERROR_INVALID_PARAMETER);
+       assert(dlogutil_entry_get_pid(bad_ptr, NULL) ==
+               TIZEN_ERROR_INVALID_PARAMETER);
+       assert(dlogutil_entry_get_priority(bad_ptr, NULL) ==
+               TIZEN_ERROR_INVALID_PARAMETER);
+       assert(dlogutil_entry_get_timestamp(bad_ptr, DLOGUTIL_SORT_RECV_MONO, NULL) ==
+               TIZEN_ERROR_INVALID_PARAMETER);
+       assert(dlogutil_entry_get_tag(bad_ptr, NULL) ==
+               TIZEN_ERROR_INVALID_PARAMETER);
+       assert(dlogutil_entry_get_message(bad_ptr, NULL) ==
+               TIZEN_ERROR_INVALID_PARAMETER);
+       assert(dlogutil_buffer_get_name(LOG_ID_MAIN, NULL) ==
+               TIZEN_ERROR_INVALID_PARAMETER);
+       assert(dlogutil_buffer_get_default_ts_type(LOG_ID_MAIN, NULL) ==
+               TIZEN_ERROR_INVALID_PARAMETER);
+       assert(dlogutil_buffer_check_ts_type_available(LOG_ID_MAIN, DLOGUTIL_SORT_RECV_MONO, NULL) ==
+               TIZEN_ERROR_INVALID_PARAMETER);
+       assert(dlogutil_buffer_get_alias(bad_ptr, LOG_ID_MAIN, NULL) ==
+               TIZEN_ERROR_INVALID_PARAMETER);
+
+       // Wrong timestamp
+       assert(dlogutil_entry_get_timestamp(bad_ptr, 1337, bad_ptr) ==
+               TIZEN_ERROR_INVALID_PARAMETER);
+
+       // NULL options
+       assert(dlogutil_config_filter_tid(NULL, 0) ==
+               TIZEN_ERROR_INVALID_PARAMETER);
+       assert(dlogutil_config_filter_pid(NULL, 0) ==
+               TIZEN_ERROR_INVALID_PARAMETER);
+       assert(dlogutil_config_filter_filterspec(NULL, "TIZEN") ==
+               TIZEN_ERROR_INVALID_PARAMETER);
+       assert(dlogutil_config_sorting_disable(NULL) ==
+               TIZEN_ERROR_INVALID_PARAMETER);
+       assert(dlogutil_config_sorting_enable(NULL) ==
+               TIZEN_ERROR_INVALID_PARAMETER);
+       assert(dlogutil_config_sorting_enable_with_size(NULL, 7) ==
+               TIZEN_ERROR_INVALID_PARAMETER);
+       assert(dlogutil_config_order_set(NULL, DLOGUTIL_SORT_RECV_MONO) ==
+               TIZEN_ERROR_INVALID_PARAMETER);
+
+       // Invalid buffer
+       assert(dlogutil_buffer_get_alias(bad_ptr, LOG_ID_INVALID, bad_ptr) ==
+               TIZEN_ERROR_INVALID_PARAMETER);
+       assert(dlogutil_buffer_get_alias(bad_ptr, LOG_ID_MAX, bad_ptr) ==
+               TIZEN_ERROR_INVALID_PARAMETER);
+       assert(dlogutil_buffer_get_alias(bad_ptr, (log_id_t) -1, bad_ptr) ==
+               TIZEN_ERROR_INVALID_PARAMETER);
+       assert(dlogutil_buffer_get_alias(bad_ptr, (log_id_t) 99, bad_ptr) ==
+               TIZEN_ERROR_INVALID_PARAMETER);
+
+       // Destroying a NULL - no error, but doesn't crash either
+       dlogutil_config_destroy(NULL);
+
+       // Actual cleanup
+       dlogutil_config_destroy(c);
+}
+
+
+int main(int argc, char **argv)
+{
+       negative_main();
+       return 0;
+}
\ No newline at end of file
diff --git a/src/tests/libdlogutil_pos.c b/src/tests/libdlogutil_pos.c
new file mode 100644 (file)
index 0000000..8d7dc2a
--- /dev/null
@@ -0,0 +1,19 @@
+#include <stdlib.h>
+#include <assert.h>
+#include <logcommon.h>
+
+void positive_main(void)
+{
+       dlogutil_config_s *config = dlogutil_config_create();
+       assert(config);
+       assert(dlogutil_config_buffer_add(config, LOG_ID_MAIN) == 0);
+
+       dlogutil_config_destroy(config);
+}
+
+
+int main(int argc, char **argv)
+{
+       positive_main();
+       return 0;
+}
\ No newline at end of file
index d14ec48..3d7c3a0 100644 (file)
@@ -494,24 +494,6 @@ void negative_main(void)
 
        void *bad_ptr = (void *)0xFA1l;
 
-       assert(TIZEN_ERROR_INVALID_PARAMETER == dlogutil_config_buffer_add(NULL, LOG_ID_MAIN));
-
-       dlogutil_config_s *c = dlogutil_config_create();
-       assert(c);
-       assert(TIZEN_ERROR_INVALID_PARAMETER == dlogutil_config_buffer_add(c, LOG_ID_INVALID));
-       assert(TIZEN_ERROR_INVALID_PARAMETER == dlogutil_config_buffer_add(c, LOG_ID_MAX));
-       assert(TIZEN_ERROR_INVALID_PARAMETER == dlogutil_config_buffer_add(c, (log_id_t) -1));
-       assert(TIZEN_ERROR_INVALID_PARAMETER == dlogutil_config_buffer_add(c, (log_id_t) 98));
-
-       dlogutil_state_s *s;
-       assert(TIZEN_ERROR_NONE == dlogutil_config_mode_set_continuous(c));
-
-       assert(TIZEN_ERROR_INVALID_PARAMETER == dlogutil_config_connect(c, &s)); // empty set
-
-       assert(TIZEN_ERROR_NONE == dlogutil_config_buffer_add(c, LOG_ID_MAIN));
-       assert(TIZEN_ERROR_NONE == dlogutil_config_buffer_add(c, LOG_ID_KMSG));
-       assert(TIZEN_ERROR_NOT_SUPPORTED == dlogutil_config_connect(c, &s)); // incompatible pair
-
        // Invalid single buffer
        const log_id_t invalid_ids[] =
                { LOG_ID_INVALID
@@ -529,91 +511,14 @@ void negative_main(void)
                        TIZEN_ERROR_INVALID_PARAMETER);
                assert(dlogutil_buffer_get_usage(state, id, bad_ptr) ==
                        TIZEN_ERROR_INVALID_PARAMETER);
-               assert(dlogutil_buffer_get_name(id, bad_ptr) ==
-                       TIZEN_ERROR_INVALID_PARAMETER);
-               assert(dlogutil_buffer_get_default_ts_type(id, bad_ptr) ==
-                       TIZEN_ERROR_INVALID_PARAMETER);
-               assert(dlogutil_buffer_check_ts_type_available(id, DLOGUTIL_SORT_SENT_MONO, bad_ptr) ==
-                       TIZEN_ERROR_INVALID_PARAMETER);
        }
 
-       // Retrieval of data from NULL
-       assert(dlogutil_entry_get_tid(NULL, bad_ptr) ==
-               TIZEN_ERROR_INVALID_PARAMETER);
-       assert(dlogutil_entry_get_pid(NULL, bad_ptr) ==
-               TIZEN_ERROR_INVALID_PARAMETER);
-       assert(dlogutil_entry_get_priority(NULL, bad_ptr) ==
-               TIZEN_ERROR_INVALID_PARAMETER);
-       assert(dlogutil_entry_get_timestamp(NULL, DLOGUTIL_SORT_RECV_MONO, bad_ptr) ==
-               TIZEN_ERROR_INVALID_PARAMETER);
-       assert(dlogutil_entry_get_tag(NULL, bad_ptr) ==
-               TIZEN_ERROR_INVALID_PARAMETER);
-       assert(dlogutil_entry_get_message(NULL, bad_ptr) ==
-               TIZEN_ERROR_INVALID_PARAMETER);
-       assert(dlogutil_buffer_get_alias(NULL, LOG_ID_MAIN, bad_ptr) ==
-               TIZEN_ERROR_INVALID_PARAMETER);
-
        // Retrieval of data into NULL
-       assert(dlogutil_entry_get_tid(bad_ptr, NULL) ==
-               TIZEN_ERROR_INVALID_PARAMETER);
-       assert(dlogutil_entry_get_pid(bad_ptr, NULL) ==
-               TIZEN_ERROR_INVALID_PARAMETER);
-       assert(dlogutil_entry_get_priority(bad_ptr, NULL) ==
-               TIZEN_ERROR_INVALID_PARAMETER);
-       assert(dlogutil_entry_get_timestamp(bad_ptr, DLOGUTIL_SORT_RECV_MONO, NULL) ==
-               TIZEN_ERROR_INVALID_PARAMETER);
-       assert(dlogutil_entry_get_tag(bad_ptr, NULL) ==
-               TIZEN_ERROR_INVALID_PARAMETER);
-       assert(dlogutil_entry_get_message(bad_ptr, NULL) ==
-               TIZEN_ERROR_INVALID_PARAMETER);
-       assert(dlogutil_buffer_get_name(LOG_ID_MAIN, NULL) ==
-               TIZEN_ERROR_INVALID_PARAMETER);
        assert(dlogutil_buffer_get_capacity(state, LOG_ID_MAIN, NULL) ==
                TIZEN_ERROR_INVALID_PARAMETER);
        assert(dlogutil_buffer_get_usage(state, LOG_ID_MAIN, NULL) ==
                TIZEN_ERROR_INVALID_PARAMETER);
-       assert(dlogutil_buffer_get_default_ts_type(LOG_ID_MAIN, NULL) ==
-               TIZEN_ERROR_INVALID_PARAMETER);
-       assert(dlogutil_buffer_check_ts_type_available(LOG_ID_MAIN, DLOGUTIL_SORT_RECV_MONO, NULL) ==
-               TIZEN_ERROR_INVALID_PARAMETER);
-       assert(dlogutil_buffer_get_alias(bad_ptr, LOG_ID_MAIN, NULL) ==
-               TIZEN_ERROR_INVALID_PARAMETER);
-
-       // Wrong timestamp
-       assert(dlogutil_entry_get_timestamp(bad_ptr, 1337, bad_ptr) ==
-               TIZEN_ERROR_INVALID_PARAMETER);
-
-       // NULL options
-       assert(dlogutil_config_filter_tid(NULL, 0) ==
-               TIZEN_ERROR_INVALID_PARAMETER);
-       assert(dlogutil_config_filter_pid(NULL, 0) ==
-               TIZEN_ERROR_INVALID_PARAMETER);
-       assert(dlogutil_config_filter_filterspec(NULL, "TIZEN") ==
-               TIZEN_ERROR_INVALID_PARAMETER);
-       assert(dlogutil_config_sorting_disable(NULL) ==
-               TIZEN_ERROR_INVALID_PARAMETER);
-       assert(dlogutil_config_sorting_enable(NULL) ==
-               TIZEN_ERROR_INVALID_PARAMETER);
-       assert(dlogutil_config_sorting_enable_with_size(NULL, 7) ==
-               TIZEN_ERROR_INVALID_PARAMETER);
-       assert(dlogutil_config_order_set(NULL, DLOGUTIL_SORT_RECV_MONO) ==
-               TIZEN_ERROR_INVALID_PARAMETER);
-
-       // Invalid buffer
-       assert(dlogutil_buffer_get_alias(bad_ptr, LOG_ID_INVALID, bad_ptr) ==
-               TIZEN_ERROR_INVALID_PARAMETER);
-       assert(dlogutil_buffer_get_alias(bad_ptr, LOG_ID_MAX, bad_ptr) ==
-               TIZEN_ERROR_INVALID_PARAMETER);
-       assert(dlogutil_buffer_get_alias(bad_ptr, (log_id_t) -1, bad_ptr) ==
-               TIZEN_ERROR_INVALID_PARAMETER);
-       assert(dlogutil_buffer_get_alias(bad_ptr, (log_id_t) 99, bad_ptr) ==
-               TIZEN_ERROR_INVALID_PARAMETER);
-
-       // Destroying a NULL - no error, but doesn't crash either
-       dlogutil_config_destroy(NULL);
-
        // Actual cleanup
-       dlogutil_config_destroy(c);
        dlogutil_state_destroy(state);
 }
 
@@ -672,4 +577,4 @@ int main(int argc, char **argv)
        }
 
        return EXIT_SUCCESS;
-}
+}
\ No newline at end of file