Add CAPI coverage tests 48/297848/2
authorMichal Bloch <m.bloch@samsung.com>
Thu, 24 Aug 2023 19:21:15 +0000 (21:21 +0200)
committerMichal Bloch <m.bloch@samsung.com>
Fri, 25 Aug 2023 14:16:41 +0000 (16:16 +0200)
Change-Id: I4c546d8e3479b7498c9ed2def85b7f710672b014

Makefile.am
packaging/dlog.spec
tests/dlog_coverage.in
tests/test_capi_coverage.c [new file with mode: 0644]

index 5a9f71f..7a6ffa3 100644 (file)
@@ -489,7 +489,6 @@ test_config_redirect_LDADD = \
 test_config_redirect_SOURCES = \
        tests/test_config_redirect.c
 
-
 check_PROGRAMS = \
        src/tests/test_ptrs_list_foreach_pos \
        src/tests/test_compression_common \
@@ -968,8 +967,38 @@ modulesloadd_DATA = \
 
 bin_SCRIPTS = dlog_test dlog_test_header dlog_cpu
 
+
+
+
 coveragetestsdir = $(bindir)/tizen-unittests/dlog
 coveragetests_SCRIPTS = run-unittest.sh
+coveragetests_PROGRAMS = test_capi_coverage test_libdlogutil_cov
+test_capi_coverage_CFLAGS = \
+       $(AM_CFLAGS) \
+       -fPIE
+test_capi_coverage_LDFLAGS = \
+       $(AM_LDFLAGS) \
+       -pie
+test_capi_coverage_DEPENDENCIES = \
+       libdlog.la \
+       libdlogutil.la \
+       libdlog_redirect_stdout.la
+test_capi_coverage_LDADD = \
+       libdlog.la \
+       libdlogutil.la \
+       libdlog_redirect_stdout.la
+test_capi_coverage_SOURCES = \
+       tests/test_capi_coverage.c
+
+# packaging won't let us have the same program in 2 packages
+test_libdlogutil_cov_CFLAGS       = $(test_libdlogutil_CFLAGS)
+test_libdlogutil_cov_LDFLAGS      = $(test_libdlogutil_LDFLAGS)
+test_libdlogutil_cov_DEPENDENCIES = $(test_libdlogutil_DEPENDENCIES)
+test_libdlogutil_cov_LDADD        = $(test_libdlogutil_LDADD)
+test_libdlogutil_cov_SOURCES      = $(test_libdlogutil_SOURCES)
+
+
+
 
 docdir = $(datadir)/doc/dlog
 doc_DATA = \
index b2bc902..a4c41d9 100644 (file)
@@ -274,6 +274,8 @@ chsmack -e 'System' %{_libexecdir}/dlog-log-critical
 
 %files unittests
 %{_bindir}/tizen-unittests/%{name}/run-unittest.sh
+%{_bindir}/tizen-unittests/%{name}/test_capi_coverage
+%{_bindir}/tizen-unittests/%{name}/test_libdlogutil_cov
 %{_datadir}/dlog-coverage.conf
 %dir %attr(755,log,log) /var/lib/dlog-unittests
 %dir %attr(755,log,log) /usr/share/dlog-filters.conf.unittest
index 1cedec3..78957ba 100644 (file)
@@ -8,6 +8,13 @@
 # here I am going to run a bunch of useless commands in hopes that it
 # hits as many lines as possible.
 
+
+@bindir@/tizen-unittests/dlog/test_capi_coverage
+
+for MODE in monitor priority_exact pid_wrong tid_wrong tag_wrong prefix_wrong sorting clear alias negative; do
+       @bindir@/tizen-unittests/dlog/test_libdlogutil_cov $MODE 123 pipe
+done
+
 dlogsend -b main -b radio -b apps -b dotnet -b dotnet_api -b native -b native_api bla
 dlogsend -h
 dlogsend -kszc 1 -d 1 -f 1 -x
diff --git a/tests/test_capi_coverage.c b/tests/test_capi_coverage.c
new file mode 100644 (file)
index 0000000..32e1046
--- /dev/null
@@ -0,0 +1,112 @@
+/*  MIT License
+ *
+ * Copyright (c) 2023 Samsung Electronics Co., Ltd
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is furnished
+ * to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in all
+ * copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE. */
+
+// dlog public API
+#include <dlog.h>
+#include <dlog-redirect-stdout.h>
+
+// dlog secret API
+#include <extra_sinks.h>
+
+#include <fcntl.h>
+#include <unistd.h>
+
+#include <limits.h>
+
+int dlog_vprint_native(log_priority prio, const char *tag, const char *fmt, va_list ap);
+int  dlog_print_native(log_priority prio, const char *tag, const char *fmt, ...);
+int dlog_vprint_dotnet(log_priority prio, const char *tag, const char *fmt, va_list ap);
+int  dlog_print_dotnet(log_priority prio, const char *tag, const char *fmt, ...);
+
+void va_stuff(log_priority prio, const char *tag, const char *fmt, ...)
+{
+       va_list va;
+       va_start(va, fmt);
+
+       va_list va_dotnet, va_native, va_vprint, va_iprint;
+       va_copy(va_native, va);
+       va_copy(va_dotnet, va);
+       va_copy(va_vprint, va);
+       va_copy(va_iprint, va);
+
+       dlog_vprint_native(prio, tag, fmt, va_native);
+       dlog_vprint_dotnet(prio, tag, fmt, va_dotnet);
+       dlog_vprint(prio, tag, fmt, va_vprint);
+       __dlog_vprint(LOG_ID_MAIN, prio, tag, fmt, va_iprint);
+
+       va_end(va);
+       va_end(va_native);
+       va_end(va_dotnet);
+       va_end(va_vprint);
+       va_end(va_iprint);
+}
+
+int main()
+{
+       dlog_connect_fd(LOG_ID_INVALID,             1,   "x", DLOG_INFO);
+       dlog_connect_fd(SINK_DOTNET   ,             1,   "x", DLOG_INFO);
+       dlog_connect_fd(LOG_ID_MAIN   ,            -1,   "x", DLOG_INFO);
+       dlog_connect_fd(LOG_ID_MAIN   ,             1,  NULL, DLOG_INFO);
+       dlog_connect_fd(LOG_ID_MAIN   ,             1,    "", DLOG_INFO);
+       dlog_connect_fd(LOG_ID_MAIN   ,             1,   "x",      -999);
+       dlog_connect_fd(LOG_ID_MAIN   ,             1,   "x",      +999);
+       dlog_connect_fd(LOG_ID_MAIN   ,           999,   "x", DLOG_INFO);
+       dlog_connect_fd(LOG_ID_MAIN   ,       INT_MAX,   "x", DLOG_INFO);
+
+       dlog_connect_fd(LOG_ID_MAIN   , STDOUT_FILENO,   "x", DLOG_INFO);
+       dlog_connect_fd(LOG_ID_RADIO  , STDOUT_FILENO,   "x", DLOG_INFO);
+       dlog_connect_fd(LOG_ID_SYSTEM , STDOUT_FILENO,   "x", DLOG_INFO);
+       dlog_connect_fd(LOG_ID_APPS   , STDOUT_FILENO,   "x", DLOG_INFO);
+       dlog_connect_fd(SINK_DOTNET   , STDOUT_FILENO,   "x", DLOG_INFO);
+       dlog_connect_fd(SINK_NATIVE   , STDOUT_FILENO,   "x", DLOG_INFO);
+       dlog_connect_fd(LOG_ID_MAIN   , STDERR_FILENO,   "x", DLOG_INFO);
+
+
+       int const fd_null = open("/dev/null"    , O_RDONLY);
+       int const fd_logs = open("/dev/log_main", O_RDONLY);
+       int const fd_else = open("/dev/kmsg"    , O_RDONLY);
+
+       dlog_is_log_fd(     -1);
+       dlog_is_log_fd(    999);
+       dlog_is_log_fd(fd_null);
+       dlog_is_log_fd(fd_logs);
+       dlog_is_log_fd(fd_else);
+
+       close(fd_null);
+       close(fd_logs);
+       close(fd_else);
+
+
+       dlog_set_minimum_priority(         -99);
+       dlog_set_minimum_priority(         +99);
+       dlog_set_minimum_priority(DLOG_VERBOSE);
+
+       va_stuff(DLOG_ERROR, "x", "x");
+
+       dlog_print_native(DLOG_ERROR, "x", "x");
+       dlog_print_dotnet(DLOG_ERROR, "x", "x");
+
+                __dlog_print(LOG_ID_MAIN, DLOG_ERROR, "x", "x");
+            __dlog_sec_print(LOG_ID_MAIN, DLOG_ERROR, "x", "x");
+       __dlog_critical_print(LOG_ID_MAIN, DLOG_ERROR, "x", "x");
+                __dlog_print(LOG_ID_MAIN, DLOG_ERROR, "x", "x");
+}