libdlogutil: various getters work upon the state 26/238826/4
authorMateusz Majewski <m.majewski2@samsung.com>
Mon, 6 Jul 2020 13:16:43 +0000 (15:16 +0200)
committerMichal Bloch <m.bloch@partner.samsung.com>
Tue, 21 Jul 2020 15:08:50 +0000 (15:08 +0000)
Change-Id: I1d95a84731f669d0a5ea6a9a6fb2a51869f5780c

include/dlogutil-internal.h
include/dlogutil.h
src/libdlogutil/lib.c
src/libdlogutil/logretrieve.c
src/logutil/logutil.c
tests/test_libdlogutil.c

index 767849c..6741ca5 100644 (file)
@@ -20,9 +20,10 @@ typedef struct dlogutil_filter_options dlogutil_filter_options_s;
 typedef struct dlogutil_sorting_options dlogutil_sorting_options_s;
 
 typedef enum {
-       DLOGUTIL_MODE_CONTINUOUS = 0,
+       DLOGUTIL_MODE_NONPRINTING = 0,
+       DLOGUTIL_MODE_CONTINUOUS,
        DLOGUTIL_MODE_DUMP,
-       DLOGUTIL_MODE_MONITOR
+       DLOGUTIL_MODE_MONITOR,
 } dlogutil_mode_e;
 
 struct dlogutil_config {
index 3f7dfd2..dabc8bf 100644 (file)
@@ -398,31 +398,35 @@ int dlogutil_get_log(dlogutil_state_s *state, int timeout, dlogutil_entry_s **en
 /**
  * @brief Clears a log buffer.
  * @since_tizen 6.0
- * @param[in] buffer A single buffer to be cleared
+ * @remarks In the current version of DLog, dlogutil_config_connect() already begins the log retrieval process.
+ *          Therefore, if you call dlogutil_get_log() on the same #dlogutil_state_s struct you used this function
+ *          on, you may still get some of the old logs, even if the clear is successful. In order to fix this,
+ *          call dlogutil_config_connect() the second time and use dlogutil_get_log() on a separate object.
+ *          Alternatively, consider using the monitor mode instead (see dlogutil_config_mode_set_monitor()).
+ * @param[in] state A handle to the state struct
+ * @param[in] buffer A buffer to be cleared
  * @remarks Either CAP_SYSLOG or being in the log group is required.
  * @return An error code
  * @retval TIZEN_ERROR_NONE Success
  * @retval TIZEN_ERROR_INVALID_PARAMETER Invalid buffer
- * @retval TIZEN_ERROR_INVALID_PARAMETER More than one buffer
+ * @retval TIZEN_ERROR_INVALID_PARAMETER State pointer was null
  * @retval Other An arbitrary Tizen error code
  */
-int dlogutil_buffer_clear(dlogutil_buffer_e buffer);
+int dlogutil_buffer_clear(dlogutil_state_s *state, log_id_t buffer);
 
 /**
  * @brief Gets the name of a buffer.
  * @since_tizen 6.0
  * @remarks The returned string will have the static lifetime.
- *          Either CAP_SYSLOG or being in the log group is required.
- * @param[in] buffer A single buffer to be inspected
+ * @param[in] buffer A buffer to be inspected
  * @param[out] name The name of the passed buffer
  * @return An error code
  * @retval TIZEN_ERROR_NONE Success
  * @retval TIZEN_ERROR_INVALID_PARAMETER Invalid buffer
- * @retval TIZEN_ERROR_INVALID_PARAMETER More than one buffer
  * @retval TIZEN_ERROR_INVALID_PARAMETER The pointer was NULL
  * @retval Other An arbitrary Tizen error code
  */
-int dlogutil_buffer_get_name(dlogutil_buffer_e buffer, const char **name);
+int dlogutil_buffer_get_name(log_id_t buffer, const char **name);
 
 /**
  * @brief Gets the capacity of a buffer.
@@ -432,16 +436,17 @@ int dlogutil_buffer_get_name(dlogutil_buffer_e buffer, const char **name);
  *      this can desync from the value of the server if the config file changes. Note that this is mostly
  *      a theoretical concern, since the file is not intended to change during the runtime (the daemon asks
  *      to reboot the system in such a case).
- * @param[in] buffer A single buffer to be inspected
+ * @param[in] state A handle to the state struct
+ * @param[in] buffer A buffer to be inspected
  * @param[out] capacity The buffer's maximum capacity, in bytes
  * @return An error code
  * @retval TIZEN_ERROR_NONE Success
  * @retval TIZEN_ERROR_INVALID_PARAMETER Invalid buffer
- * @retval TIZEN_ERROR_INVALID_PARAMETER More than one buffer
- * @retval TIZEN_ERROR_INVALID_PARAMETER The pointer was NULL
+ * @retval TIZEN_ERROR_INVALID_PARAMETER The state pointer was NULL
+ * @retval TIZEN_ERROR_INVALID_PARAMETER The capacity pointer was NULL
  * @retval Other An arbitrary Tizen error code
  */
-int dlogutil_buffer_get_capacity(dlogutil_buffer_e buffer, unsigned int *capacity);
+int dlogutil_buffer_get_capacity(dlogutil_state_s *state, log_id_t buffer, unsigned int *capacity);
 
 /**
  * @brief Gets the usage of a buffer.
@@ -451,16 +456,17 @@ int dlogutil_buffer_get_capacity(dlogutil_buffer_e buffer, unsigned int *capacit
  *      this can desync from the value of the server if the config file changes. Note that this is mostly
  *      a theoretical concern, since the file is not intended to change during the runtime (the daemon asks
  *      to reboot the system in such a case).
- * @param[in] buffer A single buffer to be inspected
+ * @param[in] state A handle to the state struct
+ * @param[in] buffer A buffer to be inspected
  * @param[out] usage Buffer's current usage, in bytes
  * @return An error code
  * @retval TIZEN_ERROR_NONE Success
  * @retval TIZEN_ERROR_INVALID_PARAMETER Invalid buffer
- * @retval TIZEN_ERROR_INVALID_PARAMETER More than one buffer
- * @retval TIZEN_ERROR_INVALID_PARAMETER The pointer was NULL
+ * @retval TIZEN_ERROR_INVALID_PARAMETER The state pointer was NULL
+ * @retval TIZEN_ERROR_INVALID_PARAMETER The usage pointer was NULL
  * @retval Other An arbitrary Tizen error code
  */
-int dlogutil_buffer_get_usage(dlogutil_buffer_e buffer, unsigned int *usage);
+int dlogutil_buffer_get_usage(dlogutil_state_s *state, log_id_t buffer, unsigned int *usage);
 
 /**
  * @brief Gets the default timestamp type of a buffer.
@@ -482,6 +488,7 @@ int dlogutil_buffer_get_usage(dlogutil_buffer_e buffer, unsigned int *usage);
  * @retval TIZEN_ERROR_INVALID_PARAMETER The pointer was NULL
  * @retval Other An arbitrary Tizen error code
  */
+// TODO: This should take log_id_t
 int dlogutil_buffer_get_default_ts_type(dlogutil_buffer_e buffer, dlogutil_sorting_order_e *type);
 
 /**
@@ -504,6 +511,7 @@ int dlogutil_buffer_get_default_ts_type(dlogutil_buffer_e buffer, dlogutil_sorti
  * @retval TIZEN_ERROR_INVALID_PARAMETER More than one buffer
  * @retval TIZEN_ERROR_INVALID_PARAMETER The pointer was NULL
  */
+// TODO: This should take log_id_t
 int dlogutil_buffer_check_ts_type_available(dlogutil_buffer_e buffer, dlogutil_sorting_order_e type, bool *available);
 
 /**
index ec6a08a..98056b1 100644 (file)
@@ -39,6 +39,7 @@ EXPORT_API dlogutil_config_s *dlogutil_config_create(void)
        if (!ret)
                goto fail;
 
+       ret->mode = DLOGUTIL_MODE_NONPRINTING;
        ret->filter = filter;
        ret->sorting = sorting;
        return ret;
@@ -185,22 +186,6 @@ EXPORT_API int dlogutil_config_buffer_add(dlogutil_config_s *config, log_id_t bu
        return TIZEN_ERROR_NONE;
 }
 
-#define COMMON_INIT_IMPL(buf_varname) \
-       __attribute__ ((cleanup(log_config_free))) struct log_config conf = { .begin = NULL, .last = NULL }; \
-       __attribute__ ((cleanup(fdi_array_free))) struct fd_info **fdi_ptrs = NULL; \
-       int r = log_config_read(&conf); \
-       if (r < 0) \
-               return r; \
-       const char *const backend = log_config_get(&conf, "backend"); \
-       if (!backend) \
-               return -EINVAL; \
-       const bool is_pipe = !strcmp(backend, "pipe"); \
-       int fdi_cnt = create_initial_fdis(&fdi_ptrs, buf_varname, is_pipe, &conf); \
-       if (fdi_cnt < 0) \
-               return fdi_cnt;
-
-#define COMMON_INIT COMMON_INIT_IMPL(buffers)
-
 EXPORT_API void dlogutil_state_destroy(dlogutil_state_s *state)
 {
        if (state->epollfd >= 0)
@@ -216,31 +201,53 @@ EXPORT_API void dlogutil_state_destroy(dlogutil_state_s *state)
        free(state);
 }
 
+static int check_is_pipe(struct log_config *conf, bool *is_pipe) {
+       const char *const backend = log_config_get(conf, "backend");
+       if (!backend)
+               return TIZEN_ERROR_INVALID_PARAMETER;
+
+       *is_pipe = !strcmp(backend, "pipe");
+       return TIZEN_ERROR_NONE;
+}
+
 EXPORT_API int dlogutil_config_connect(dlogutil_config_s *config, dlogutil_state_s **out_state)
 {
        CHECK_PARAM(config);
        CHECK_PARAM(out_state);
 
-       int buffers = config->buffers;
-       if (!buffers)
+       if (config->mode != DLOGUTIL_MODE_NONPRINTING) {
+               /* KMSG lacks some timestamps so we have trouble sorting
+                * it with core buffers, thus mixing them is not supported
+                * at the moment. Possibly in the future we could reduce
+                * the timestamp bloat and allow it. */
+               if (config->buffers &  DLOGUTIL_BUF_KMSG
+               &&  config->buffers & ~DLOGUTIL_BUF_KMSG)
+                       return TIZEN_ERROR_NOT_SUPPORTED;
+       }
+
+       if (!config->buffers)
                return TIZEN_ERROR_INVALID_PARAMETER;
 
-       /* KMSG lacks some timestamps so we have trouble sorting
-        * it with core buffers, thus mixing them is not supported
-        * at the moment. Possibly in the future we could reduce
-        * the timestamp bloat and allow it. */
-       if (buffers &  DLOGUTIL_BUF_KMSG
-       &&  buffers & ~DLOGUTIL_BUF_KMSG)
-               return TIZEN_ERROR_NOT_SUPPORTED;
+       __attribute__ ((cleanup(log_config_free))) struct log_config conf = { .begin = NULL, .last = NULL };
+       int r = log_config_read(&conf);
+       if (r < 0)
+               return r;
 
-       COMMON_INIT
+       bool is_pipe;
+       r = check_is_pipe(&conf, &is_pipe);
+       if (r < 0)
+               return r;
+
+       __attribute__ ((cleanup(fdi_array_free))) struct fd_info **fdi_ptrs = NULL;
+       int fdi_cnt = create_initial_fdis(&fdi_ptrs, config->buffers, is_pipe, &conf);
+       if (fdi_cnt < 0)
+               return fdi_cnt;
 
        if (!has_required_privilege(is_pipe, config->mode, fdi_ptrs, fdi_cnt))
                return -EPERM;
 
        bool sorting_needed;
-       dlogutil_sorting_order_e proper_sort_by =
-               get_proper_sort_by((config && config->sorting) ? config->sorting->sort_by : DLOGUTIL_SORT_DEFAULT, buffers, is_pipe, &conf, &sorting_needed);
+       dlogutil_sorting_order_e proper_sort_by = get_proper_sort_by(config->sorting->sort_by, config->buffers, is_pipe, &conf, &sorting_needed);
 
        dlogutil_state_s *state = malloc(sizeof(struct dlogutil_state));
        if (!state)
@@ -283,57 +290,71 @@ EXPORT_API int dlogutil_config_mode_set_dump(dlogutil_config_s *config, unsigned
 
 EXPORT_API int dlogutil_get_log(dlogutil_state_s *state, int timeout, dlogutil_entry_s **entry_out)
 {
-       assert(entry_out);
+       CHECK_PARAM(state);
+       CHECK_PARAM(state->mode != DLOGUTIL_MODE_NONPRINTING);
+       CHECK_PARAM(entry_out);
+
        *entry_out = NULL;
 
        return do_print_once(state, timeout, entry_out);
 }
 
-#define COMMON_INIT_SINGLE \
-       COMMON_INIT_IMPL(buffer) \
-       if (fdi_cnt != 1) \
-               return -EINVAL;
-
-EXPORT_API int dlogutil_buffer_clear(dlogutil_buffer_e buffer)
+EXPORT_API int dlogutil_buffer_clear(dlogutil_state_s *state, log_id_t buffer)
 {
-       COMMON_INIT_SINGLE
+       CHECK_PARAM(state);
 
-       return fdi_ptrs[0]->ops->clear(fdi_ptrs[0]);
+       for (int i = 0; i < state->fd_count; ++i)
+               if (state->data_fds[i]->id == buffer)
+                       return state->data_fds[i]->ops->clear(state->data_fds[i]);
+
+       return TIZEN_ERROR_INVALID_PARAMETER;
 }
 
-EXPORT_API int dlogutil_buffer_get_name(dlogutil_buffer_e buffer, const char **name)
+EXPORT_API int dlogutil_buffer_get_name(log_id_t buffer, const char **name)
 {
        CHECK_PARAM(name);
 
-       COMMON_INIT_SINGLE
-
-       *name = log_name_by_id(fdi_ptrs[0]->id);
+       *name = log_name_by_id(buffer);
        return TIZEN_ERROR_NONE;
 }
 
-EXPORT_API int dlogutil_buffer_get_capacity(dlogutil_buffer_e buffer, unsigned int *capacity)
+EXPORT_API int dlogutil_buffer_get_capacity(dlogutil_state_s *state, log_id_t buffer, unsigned int *capacity)
 {
+       CHECK_PARAM(state);
        CHECK_PARAM(capacity);
 
-       COMMON_INIT_SINGLE
+       for (int i = 0; i < state->fd_count; ++i)
+               if (state->data_fds[i]->id == buffer)
+                       return state->data_fds[i]->ops->get_capacity(state->data_fds[i], capacity);
 
-       return fdi_ptrs[0]->ops->get_capacity(fdi_ptrs[0], capacity);
+       return TIZEN_ERROR_INVALID_PARAMETER;
 }
 
-EXPORT_API int dlogutil_buffer_get_usage(dlogutil_buffer_e buffer, unsigned int *usage)
+EXPORT_API int dlogutil_buffer_get_usage(dlogutil_state_s *state, log_id_t buffer, unsigned int *usage)
 {
+       CHECK_PARAM(state);
        CHECK_PARAM(usage);
 
-       COMMON_INIT_SINGLE
+       for (int i = 0; i < state->fd_count; ++i)
+               if (state->data_fds[i]->id == buffer)
+                       return state->data_fds[i]->ops->get_usage(state->data_fds[i], usage);
 
-       return fdi_ptrs[0]->ops->get_usage(fdi_ptrs[0], usage);
+       return TIZEN_ERROR_INVALID_PARAMETER;
 }
 
 EXPORT_API int dlogutil_buffer_get_default_ts_type(dlogutil_buffer_e buffer, dlogutil_sorting_order_e *type)
 {
        CHECK_PARAM(type);
 
-       COMMON_INIT_SINGLE
+       __attribute__ ((cleanup(log_config_free))) struct log_config conf = { .begin = NULL, .last = NULL };
+       int r = log_config_read(&conf);
+       if (r < 0)
+               return r;
+
+       bool is_pipe;
+       r = check_is_pipe(&conf, &is_pipe);
+       if (r < 0)
+               return r;
 
        *type = get_proper_sort_by(DLOGUTIL_SORT_DEFAULT, buffer, is_pipe, &conf, &(bool){ false });
        return TIZEN_ERROR_NONE;
@@ -343,7 +364,15 @@ EXPORT_API int dlogutil_buffer_check_ts_type_available(dlogutil_buffer_e buffer,
 {
        CHECK_PARAM(available);
 
-       COMMON_INIT_SINGLE
+       __attribute__ ((cleanup(log_config_free))) struct log_config conf = { .begin = NULL, .last = NULL };
+       int r = log_config_read(&conf);
+       if (r < 0)
+               return r;
+
+       bool is_pipe;
+       r = check_is_pipe(&conf, &is_pipe);
+       if (r < 0)
+               return r;
 
        switch (type) {
        case DLOGUTIL_SORT_SENT_MONO:
@@ -362,7 +391,3 @@ EXPORT_API int dlogutil_buffer_check_ts_type_available(dlogutil_buffer_e buffer,
 
        return TIZEN_ERROR_NONE;
 }
-
-#undef COMMON_INIT
-#undef COMMON_INIT_SINGLE
-#undef COMMON_INIT_IMPL
index 1c26221..83e701d 100644 (file)
@@ -165,6 +165,7 @@ int dlogutil_state_init(dlogutil_state_s *state, struct fd_info ***data_fds_ptr,
        assert(data_fds);
        assert(conf);
 
+       // TODO: optimize mode == DLOGUTIL_MODE_NONPRINTING case
        state->epollfd = -1;
        state->epoll_cnt = 0;
        state->enabled = NULL;
index b627fcc..63c8f0d 100644 (file)
@@ -245,7 +245,7 @@ static void config_cleanup(dlogutil_config_s *const *config) {
        dlogutil_config_destroy(*config);
 }
 
-static int print_buffer_capacity(dlogutil_buffer_e buffer)
+static int print_buffer_capacity(dlogutil_state_s *state, log_id_t buffer)
 {
        const char *name;
        int r = dlogutil_buffer_get_name(buffer, &name);
@@ -253,11 +253,11 @@ static int print_buffer_capacity(dlogutil_buffer_e buffer)
                return r;
 
        unsigned int usage, capacity;
-       r = dlogutil_buffer_get_capacity(buffer, &capacity);
+       r = dlogutil_buffer_get_capacity(state, buffer, &capacity);
        if (r != 0)
                return r;
 
-       r = dlogutil_buffer_get_usage(buffer, &usage);
+       r = dlogutil_buffer_get_usage(state, buffer, &usage);
        if (r != 0)
                return r;
 
@@ -265,15 +265,33 @@ static int print_buffer_capacity(dlogutil_buffer_e buffer)
        return 0;
 }
 
-static int for_each_buffer(int enabled_buffers, int (*func)(dlogutil_buffer_e buffer))
+static int for_each_buffer(int enabled_buffers, int (*func)(dlogutil_state_s *state, log_id_t buffer))
 {
+       dlogutil_config_s *c = dlogutil_config_create();
+       int r;
+
        for (int i = 0; i < LOG_ID_MAX; ++i) {
                const int single_buf_mask = (1 << i);
-               if ((single_buf_mask & enabled_buffers) == 0)
-                       continue;
-               const int r = func(single_buf_mask);
-               if (r != 0)
-                       return r;
+               if (single_buf_mask & enabled_buffers) {
+                       r = dlogutil_config_buffer_add(c, i);
+                       if (r != 0)
+                               return r;
+               }
+       }
+
+
+       dlogutil_state_s *s;
+       r = dlogutil_config_connect(c, &s);
+       if (r != 0)
+               return r;
+
+       for (int i = 0; i < LOG_ID_MAX; ++i) {
+               const int single_buf_mask = (1 << i);
+               if (single_buf_mask & enabled_buffers) {
+                       r = func(s, i);
+                       if (r != 0)
+                               return r;
+               }
        }
 
        return 0;
index 1de6597..96500e6 100644 (file)
@@ -303,16 +303,26 @@ unsigned int MB(unsigned int x)
 
 void traits_main(bool pipe)
 {
+       dlogutil_config_s *config = dlogutil_config_create();
+       assert(config);
+
+       assert(dlogutil_config_buffer_add(config, LOG_ID_MAIN) == 0);
+       assert(dlogutil_config_buffer_add(config, LOG_ID_KMSG) == 0);
+
+       dlogutil_state_s *state;
+       assert(dlogutil_config_connect(config, &state) == 0);
+       dlogutil_config_destroy(config);
+
        const char *name;
-       assert(dlogutil_buffer_get_name(DLOGUTIL_BUF_MAIN, &name) == 0);
+       assert(dlogutil_buffer_get_name(LOG_ID_MAIN, &name) == 0);
        assert(!strcmp(name, "main"));
 
-       assert(dlogutil_buffer_get_name(DLOGUTIL_BUF_KMSG, &name) == 0);
+       assert(dlogutil_buffer_get_name(LOG_ID_KMSG, &name) == 0);
        assert(!strcmp(name, "kmsg"));
 
        unsigned int capacity, usage;
-       assert(dlogutil_buffer_get_capacity(DLOGUTIL_BUF_MAIN, &capacity) == 0);
-       assert(dlogutil_buffer_get_usage(DLOGUTIL_BUF_MAIN, &usage) == 0);
+       assert(dlogutil_buffer_get_capacity(state, LOG_ID_MAIN, &capacity) == 0);
+       assert(dlogutil_buffer_get_usage(state, LOG_ID_MAIN, &usage) == 0);
        if (pipe)
                        assert(capacity == MB(1));
        else {
@@ -323,8 +333,8 @@ void traits_main(bool pipe)
        }
 
 
-       assert(dlogutil_buffer_get_capacity(DLOGUTIL_BUF_KMSG, &capacity) == 0);
-       assert(dlogutil_buffer_get_usage(DLOGUTIL_BUF_KMSG, &usage) == 0);
+       assert(dlogutil_buffer_get_capacity(state, LOG_ID_KMSG, &capacity) == 0);
+       assert(dlogutil_buffer_get_usage(state, LOG_ID_KMSG, &usage) == 0);
        assert(capacity == MB(1));
 
        dlogutil_sorting_order_e type;
@@ -355,11 +365,12 @@ void traits_main(bool pipe)
 
        assert(dlogutil_buffer_check_ts_type_available(DLOGUTIL_BUF_KMSG, DLOGUTIL_SORT_RECV_REAL, &available) == 0);
        assert(available);
+
+       dlogutil_state_destroy(state);
 }
 
 void clear_main()
 {
-       assert(dlogutil_buffer_clear(DLOGUTIL_BUF_MAIN) == 0);
 
        dlogutil_config_s *c = dlogutil_config_create();
        assert(c);
@@ -367,12 +378,16 @@ void clear_main()
        assert(dlogutil_config_mode_set_dump(c, DLOGUTIL_MAX_DUMP_SIZE) == 0);
 
        dlogutil_state_s *s;
+
        assert(dlogutil_config_connect(c, &s) == 0);
+       assert(dlogutil_buffer_clear(s, LOG_ID_MAIN) == 0);
+       dlogutil_state_destroy(s);
 
+       assert(dlogutil_config_connect(c, &s) == 0);
        dlogutil_entry_s *e;
        assert(dlogutil_get_log(s, 1000, &e) == TIZEN_ERROR_NO_DATA);
-
        dlogutil_state_destroy(s);
+
        dlogutil_config_destroy(c);
 }
 
@@ -437,7 +452,15 @@ void sorting_main(int left)
 
 void negative_main()
 {
-       void *bad_ptr = (void *)0xFA1L;
+       dlogutil_config_s *config = dlogutil_config_create();
+       assert(config);
+       assert(dlogutil_config_buffer_add(config, LOG_ID_MAIN) == 0);
+
+       dlogutil_state_s *state;
+       assert(dlogutil_config_connect(config, &state) == 0);
+       dlogutil_config_destroy(config);
+
+       void *bad_ptr = (void *)0xFA1l;
 
        assert(TIZEN_ERROR_INVALID_PARAMETER == dlogutil_config_buffer_add(NULL, LOG_ID_MAIN));
 
@@ -458,41 +481,18 @@ void negative_main()
        assert(TIZEN_ERROR_NOT_SUPPORTED == dlogutil_config_connect(c, &s)); // incompatible pair
 
        // Invalid single buffer
-       assert(dlogutil_buffer_clear(0) ==
-               TIZEN_ERROR_INVALID_PARAMETER);
-       assert(dlogutil_buffer_get_name(0, bad_ptr) ==
-               TIZEN_ERROR_INVALID_PARAMETER);
-       assert(dlogutil_buffer_get_capacity(0, bad_ptr) ==
-               TIZEN_ERROR_INVALID_PARAMETER);
-       assert(dlogutil_buffer_get_usage(0, bad_ptr) ==
-               TIZEN_ERROR_INVALID_PARAMETER);
-       assert(dlogutil_buffer_get_default_ts_type(0, bad_ptr) ==
-               TIZEN_ERROR_INVALID_PARAMETER);
-       assert(dlogutil_buffer_check_ts_type_available(0, DLOGUTIL_SORT_RECV_MONO, bad_ptr) ==
+       assert(dlogutil_buffer_clear(state, (log_id_t) -1) ==
                TIZEN_ERROR_INVALID_PARAMETER);
-       assert(dlogutil_buffer_clear(1 << 16) ==
+       assert(dlogutil_buffer_get_capacity(state, (log_id_t) -1, bad_ptr) ==
                TIZEN_ERROR_INVALID_PARAMETER);
-       assert(dlogutil_buffer_get_name(1 << 16, bad_ptr) ==
+       assert(dlogutil_buffer_get_usage(state, (log_id_t) -1, bad_ptr) ==
                TIZEN_ERROR_INVALID_PARAMETER);
-       assert(dlogutil_buffer_get_capacity(1 << 16, bad_ptr) ==
-               TIZEN_ERROR_INVALID_PARAMETER);
-       assert(dlogutil_buffer_get_usage(1 << 16, bad_ptr) ==
-               TIZEN_ERROR_INVALID_PARAMETER);
-       assert(dlogutil_buffer_get_default_ts_type(1 << 16, bad_ptr) ==
-               TIZEN_ERROR_INVALID_PARAMETER);
-       assert(dlogutil_buffer_check_ts_type_available(1 << 16, DLOGUTIL_SORT_RECV_MONO, bad_ptr) ==
-               TIZEN_ERROR_INVALID_PARAMETER);
-       assert(dlogutil_buffer_clear(DLOGUTIL_BUF_MAIN | DLOGUTIL_BUF_KMSG) ==
-               TIZEN_ERROR_INVALID_PARAMETER);
-       assert(dlogutil_buffer_get_name(DLOGUTIL_BUF_MAIN | DLOGUTIL_BUF_KMSG, bad_ptr) ==
-               TIZEN_ERROR_INVALID_PARAMETER);
-       assert(dlogutil_buffer_get_capacity(DLOGUTIL_BUF_MAIN | DLOGUTIL_BUF_KMSG, bad_ptr) ==
-               TIZEN_ERROR_INVALID_PARAMETER);
-       assert(dlogutil_buffer_get_usage(DLOGUTIL_BUF_MAIN | DLOGUTIL_BUF_KMSG, bad_ptr) ==
+
+       assert(dlogutil_buffer_clear(state, LOG_ID_MAX + 7) ==
                TIZEN_ERROR_INVALID_PARAMETER);
-       assert(dlogutil_buffer_get_default_ts_type(DLOGUTIL_BUF_MAIN | DLOGUTIL_BUF_KMSG, bad_ptr) ==
+       assert(dlogutil_buffer_get_capacity(state, LOG_ID_MAX + 7, bad_ptr) ==
                TIZEN_ERROR_INVALID_PARAMETER);
-       assert(dlogutil_buffer_check_ts_type_available(DLOGUTIL_BUF_MAIN | DLOGUTIL_BUF_KMSG, DLOGUTIL_SORT_RECV_MONO, bad_ptr) ==
+       assert(dlogutil_buffer_get_usage(state, LOG_ID_MAX + 7, bad_ptr) ==
                TIZEN_ERROR_INVALID_PARAMETER);
 
        // Retrieval of data from NULL
@@ -522,11 +522,11 @@ void negative_main()
                TIZEN_ERROR_INVALID_PARAMETER);
        assert(dlogutil_entry_get_message(bad_ptr, NULL) ==
                TIZEN_ERROR_INVALID_PARAMETER);
-       assert(dlogutil_buffer_get_name(DLOGUTIL_BUF_MAIN, NULL) ==
+       assert(dlogutil_buffer_get_name(LOG_ID_MAIN, NULL) ==
                TIZEN_ERROR_INVALID_PARAMETER);
-       assert(dlogutil_buffer_get_capacity(DLOGUTIL_BUF_MAIN, NULL) ==
+       assert(dlogutil_buffer_get_capacity(state, LOG_ID_MAIN, NULL) ==
                TIZEN_ERROR_INVALID_PARAMETER);
-       assert(dlogutil_buffer_get_usage(DLOGUTIL_BUF_MAIN, NULL) ==
+       assert(dlogutil_buffer_get_usage(state, LOG_ID_MAIN, NULL) ==
                TIZEN_ERROR_INVALID_PARAMETER);
        assert(dlogutil_buffer_get_default_ts_type(DLOGUTIL_BUF_MAIN, NULL) ==
                TIZEN_ERROR_INVALID_PARAMETER);
@@ -558,6 +558,7 @@ void negative_main()
 
        // Actual cleanup
        dlogutil_config_destroy(c);
+       dlogutil_state_destroy(state);
 }