Increase coverage even further. 72/298272/2 accepted/tizen/unified/20230906.014618
authorMichal Bloch <m.bloch@samsung.com>
Mon, 4 Sep 2023 12:46:56 +0000 (14:46 +0200)
committerMichal Bloch <m.bloch@samsung.com>
Mon, 4 Sep 2023 15:49:24 +0000 (17:49 +0200)
Change-Id: I4c546d8e3479b7498c9ed2def85b7f710672b024

src/shared/loglimiter.c
tests/dlog_coverage.in
tests/test_libdlogutil.c

index 481a754..2628360 100644 (file)
@@ -426,6 +426,7 @@ struct pass_log_result __log_limiter_pass_log_pid(struct limiter_data *limiter_d
                return (struct pass_log_result) { .decision = DECISION_ALLOWED, };
 
        /* Decide, if it should go through or stop */
+       // LCOV_EXCL_START : no limiter when gathering coverage since other tests need to send logs. See above
        time_t now = time(NULL);
        if (0 > now)
                return (struct pass_log_result) { .decision = DECISION_ALLOWED, };
@@ -450,6 +451,7 @@ struct pass_log_result __log_limiter_pass_log_pid(struct limiter_data *limiter_d
 
        r->hit++;
        return (struct pass_log_result) { .decision = DECISION_ALLOWED, };
+       // LCOV_EXCL_STOP
 }
 
 struct pass_log_result __log_limiter_pass_log(struct limiter_data *limiter_data, const char *tag, int prio)
@@ -457,6 +459,7 @@ struct pass_log_result __log_limiter_pass_log(struct limiter_data *limiter_data,
        return __log_limiter_pass_log_pid(limiter_data, tag, prio, getpid());
 }
 
+
 struct iteration_data {
        struct rule **rules_table;
        struct limiter_data *limiter_data;
@@ -510,6 +513,7 @@ static void pid_limiter_iteration(const char *key, const char *value, void *user
        if (strncmp(key, "pidlimit|", sizeof "pidlimit|" - 1))
                return;
 
+       // LCOV_EXCL_START : no limiter when gathering coverage since other tests need to send logs. See above
        int pid = atoi(key + sizeof "pidlimit|" - 1);
 
        int limit;
@@ -527,6 +531,7 @@ static void pid_limiter_iteration(const char *key, const char *value, void *user
        p->pid = pid;
 
        list_add(&data->limiter_data->pid_rules, p);
+       // LCOV_EXCL_STOP
 }
 
 static void __config_iteration(const char *key, const char *value, void *userdata)
@@ -560,6 +565,7 @@ struct limiter_data *__log_limiter_create(const struct log_config *config)
 
        const int r = __log_limiter_initialize(ret, ret->original_rules_table);
        if (r) {
+               // LCOV_EXCL_START : error case.
                rules_destroy(&ret->original_rules_table);
                if (ret->pid_rules != NULL)
                        return ret;
@@ -567,6 +573,7 @@ struct limiter_data *__log_limiter_create(const struct log_config *config)
                        free(ret);
                        return NULL;
                }
+               // LCOV_EXCL_STOP
        }
 
        for (struct rule *i = ret->original_rules_table; i; i = i->prev)
index 9b42036..ee11684 100644 (file)
@@ -11,7 +11,7 @@
 
 @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
+for MODE in monitor priority_exact pid_wrong tid_wrong tag_wrong prefix_wrong sorting clear alias negative misc; do
        @bindir@/tizen-unittests/dlog/test_libdlogutil_cov $MODE 0 pipe
 done
 
@@ -70,11 +70,25 @@ dlog_logger -t 0 &
 LOGGER=$!
 sleep 5
 echo "blabla" > /dev/kmsg
+
+# run dlogsend/dlogutil again because this counts for a different backend.
 dlogsend -b main "blablabla"
 dlogsend -c 999 -b main "blablabla999"
 dlogsend -t FLOOD -b main "blablabla"
+dlog_redirect_stdout --outtag FOO -- /usr/bin/echo Hi
+dlog_redirect_stdout --errtag BAR -- /usr/bin/sh -c "echo Hi >&2"
+dlog_redirect_stdout --outbuffer radio --outtag MONTAG --outprio W -- /usr/bin/echo Hi
+dlog_redirect_stdout --errbuffer radio --errtag DIENSTAG --errprio I -- /usr/bin/sh -c "echo Hi >&2"
 sleep 0.3233
 dlogutil -db main
+dlogutil -db main TEST:*
+dlogutil -db main TEST:=E
+dlogutil -db main TEST:E
+dlogutil -db main *:E
+dlogutil -db main --pid 123
+dlogutil -db main --tid 123
+dlogutil -b main -c
+dlogutil -b main -g
 dlogutil -u 10 -db main
 dlogutil -u 1 -db main
 dlogutil --sort-by recv_real -db main
index d4238d6..e4383af 100644 (file)
@@ -53,6 +53,7 @@ enum test_mode {
        MODE_CLEAR,
        MODE_ALIAS,
        MODE_NEGATIVE,
+       MODE_MISC,
        MODE_INVALID,
 };
 
@@ -77,6 +78,7 @@ const char *mode_names[] = {
        [MODE_CLEAR] = "clear",
        [MODE_ALIAS] = "alias",
        [MODE_NEGATIVE] = "negative",
+       [MODE_MISC] = "misc",
 };
 
 const char *mode_desc[] = {
@@ -101,6 +103,7 @@ const char *mode_desc[] = {
        [MODE_CLEAR] = "test clearing functionality -- in this case, the PID is ignored",
        [MODE_ALIAS] = "test buffer aliasing -- in this case, the PID is ignored",
        [MODE_NEGATIVE] = "test whether libdlogutil errors out correctly",
+       [MODE_MISC] = "run some miscellaneous calls",
 };
 
 void print_usage_and_die(const char *name)
@@ -536,6 +539,36 @@ void negative_main(void)
        dlogutil_state_destroy(state);
 }
 
+void misc_calls(void)
+{
+       dlogutil_config_s *config = dlogutil_config_create();
+
+       dlogutil_config_sorting_disable(config);
+       dlogutil_config_sorting_enable(config);
+       dlogutil_config_buffer_add(config, LOG_ID_MAIN);
+       dlogutil_config_buffer_add(config, LOG_ID_APPS);
+
+       dlogutil_state_s *state;
+       assert(dlogutil_config_connect(config, &state) == 0);
+       dlogutil_config_destroy(config);
+
+       dlogutil_entry_s *e;
+       int r = dlogutil_get_log(state, -1, &e);
+       if (r == 0) {
+               pid_t x;
+               dlogutil_entry_get_tid(e, &x);
+               dlogutil_entry_get_pid(e, &x);
+               log_priority p;
+               dlogutil_entry_get_priority(e, &p);
+               free(e);
+       } else {
+               dlogutil_entry_get_tid(NULL, NULL);
+               dlogutil_entry_get_pid(NULL, NULL);
+               dlogutil_entry_get_priority(NULL, NULL);
+       }
+
+       dlogutil_state_destroy(state);
+}
 
 int main(int argc, char **argv)
 {
@@ -588,6 +621,9 @@ int main(int argc, char **argv)
                case MODE_NEGATIVE:
                        negative_main();
                        break;
+               case MODE_MISC:
+                       misc_calls();
+                       break;
                default:
                        assert(false);
        }