fdi_logger divided into positive and negative tests 00/230200/2
authorAgnieszka Baumann <a.baumann@samsung.com>
Mon, 30 Mar 2020 11:22:53 +0000 (13:22 +0200)
committerMichal Bloch <m.bloch@partner.samsung.com>
Tue, 14 Apr 2020 10:32:55 +0000 (10:32 +0000)
Change-Id: I73c6729446d2025269c5517f4457fc68177fc4fa

Makefile.am
src/tests/fdi_logger_neg.c [new file with mode: 0644]
src/tests/fdi_logger_pos.c [new file with mode: 0644]
src/tests/fdi_logger_wrap.c [moved from src/tests/fdi_logger.c with 52% similarity]

index 9254107..fdfb7f6 100644 (file)
@@ -276,7 +276,8 @@ check_PROGRAMS = \
        src/tests/sort_vector \
        src/tests/fd_info_pos \
        src/tests/fd_info_neg \
-       src/tests/fdi_logger \
+       src/tests/fdi_logger_pos \
+       src/tests/fdi_logger_neg \
        src/tests/fdi_pipe \
        src/tests/libdlog_pipe \
        src/tests/libdlog_android_pos \
@@ -362,9 +363,13 @@ src_tests_fd_info_neg_SOURCES = src/tests/fd_info_neg.c \
 src_tests_fd_info_neg_CFLAGS = $(check_CFLAGS)
 src_tests_fd_info_neg_LDFLAGS = $(AM_LDFLAGS) -Wl,--wrap=sort_vector_push,--wrap=malloc,--wrap=free,--wrap=close,--wrap=dlogutil_entry_get_timestamp,--wrap=log_should_print_line
 
-src_tests_fdi_logger_SOURCES = src/tests/fdi_logger.c src/libdlogutil/fdi_logger.c src/shared/ptrs_list.c src/shared/logcommon.c
-src_tests_fdi_logger_CFLAGS = $(check_CFLAGS)
-src_tests_fdi_logger_LDFLAGS = $(AM_LDFLAGS) -Wl,--wrap=logger_open_buffer_from_config_get_path,--wrap=dlogutil_filter_options_set_filterspec,--wrap=parse_androidlogger_message,--wrap=copy_recv_timestamp,--wrap=malloc,--wrap=read,--wrap=close,--wrap=ioctl,--wrap=calloc
+src_tests_fdi_logger_pos_SOURCES = src/tests/fdi_logger_pos.c src/libdlogutil/fdi_logger.c src/shared/ptrs_list.c src/shared/logcommon.c
+src_tests_fdi_logger_pos_CFLAGS = $(check_CFLAGS)
+src_tests_fdi_logger_pos_LDFLAGS = $(AM_LDFLAGS) -Wl,--wrap=logger_open_buffer_from_config_get_path,--wrap=dlogutil_filter_options_set_filterspec,--wrap=parse_androidlogger_message,--wrap=copy_recv_timestamp,--wrap=malloc,--wrap=read,--wrap=close,--wrap=ioctl,--wrap=calloc
+
+src_tests_fdi_logger_neg_SOURCES = src/tests/fdi_logger_neg.c src/libdlogutil/fdi_logger.c src/shared/ptrs_list.c src/shared/logcommon.c
+src_tests_fdi_logger_neg_CFLAGS = $(check_CFLAGS)
+src_tests_fdi_logger_neg_LDFLAGS = $(AM_LDFLAGS) -Wl,--wrap=logger_open_buffer_from_config_get_path,--wrap=dlogutil_filter_options_set_filterspec,--wrap=parse_androidlogger_message,--wrap=copy_recv_timestamp,--wrap=malloc,--wrap=read,--wrap=close,--wrap=ioctl,--wrap=calloc
 
 src_tests_fdi_pipe_SOURCES = src/tests/fdi_pipe.c src/libdlogutil/fdi_pipe.c src/shared/logconfig.c src/shared/ptrs_list.c src/shared/logprint.c src/shared/parsers.c src/shared/logcommon.c
 src_tests_fdi_pipe_CFLAGS = $(check_CFLAGS)
diff --git a/src/tests/fdi_logger_neg.c b/src/tests/fdi_logger_neg.c
new file mode 100644 (file)
index 0000000..9fbacd9
--- /dev/null
@@ -0,0 +1,110 @@
+/*
+ * Copyright (c) 2019-2020, Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "fdi_logger_wrap.c"
+
+int main()
+{
+       struct fd_info fdi = {
+               .fd = -1,
+               .priv_data = NULL,
+       };
+       list_head used_paths = NULL;
+
+       ops_logger.destroy(&fdi);
+
+       fail_malloc = 1;
+       assert(-ENOMEM == ops_logger.create(&fdi, (struct log_config *) 0xABDUL, "radio", &used_paths));
+
+       open_buf_ret = -536;
+       assert(-536 == ops_logger.create(&fdi, (struct log_config *) 0xABDUL, "radio", &used_paths));
+       open_buf_ret = 0;
+       assert(-EINVAL == ops_logger.create(&fdi, (struct log_config *) 0xABDUL, "radio", &used_paths));
+
+       open_buf_path = "abc";
+       open_buf_ret = 1;
+       fail_malloc = 2;
+       assert(-ENOMEM == ops_logger.create(&fdi, (struct log_config *) 0xABDUL, "radio", &used_paths));
+       assert(fdi.fd < 0);
+       assert(!fdi.priv_data);
+
+       fail_calloc = true;
+       assert(-ENOMEM == ops_logger.create(&fdi, (struct log_config *) 0xABDUL, "radio", &used_paths));
+       assert(fdi.fd < 0);
+       assert(!fdi.priv_data);
+       fail_calloc = false;
+
+       assert(!ops_logger.create(&fdi, (struct log_config *) 0xABDUL, "radio", &used_paths));
+       ops_logger.destroy(&fdi);
+       fdi.fd = -1;
+
+       assert(-EALREADY == ops_logger.create(&fdi, (struct log_config *) 0xABDUL, "radio", &used_paths));
+       assert(fdi.fd == -1);
+       assert(!fdi.priv_data);
+
+       open_buf_path = "def";
+       assert(!ops_logger.create(&fdi, (struct log_config *) 0xABDUL, "radio", &used_paths));
+
+       expected_ioctl = LOGGER_FLUSH_LOG;
+       ioctl_ret = -77;
+       assert(-77 == ops_logger.clear(&fdi));
+
+       unsigned int sz;
+       expected_ioctl = LOGGER_GET_LOG_BUF_SIZE;
+       ioctl_ret = -EALREADY;
+       assert(-EALREADY == ops_logger.getsize(&fdi, &sz));
+
+       expected_ioctl = LOGGER_GET_LOG_LEN;
+       ioctl_ret = -67;
+       assert(-67 == ops_logger.prepare_print(&fdi, 123, false, (dlogutil_filter_options_s *) 0xCA5CADE));
+
+       expected_ioctl = -1;
+       assert(!ops_logger.prepare_print(&fdi, DLOGUTIL_MODE_CONTINUOUS, false, (dlogutil_filter_options_s *) 0xCA5CADE));
+
+       fail_read = true;
+       assert(-334 == ops_logger.read(&fdi));
+       fail_read = false;
+
+       for (size_t i = 0; i < NELEMS(READS) + 15; ++i) {
+               assert(!ops_logger.has_log(&fdi));
+               fail_read = true;
+               assert(NULL == ops_logger.extract_entry(&fdi));
+               assert(NULL == ops_logger.peek_entry(&fdi));
+               assert(NULL == ops_logger.extract_entry(&fdi));
+               fail_read = false;
+               fail_malloc = !(rand() % 4) * 3;
+               ops_logger.read(&fdi);
+               if (!fail_malloc && i < NELEMS(READS) && READS[i] > sizeof(struct android_logger_entry)) {
+                       assert(ops_logger.has_log(&fdi));
+                       assert(-EAGAIN == ops_logger.read(&fdi));
+                       const dlogutil_entry_s *const le = ops_logger.peek_entry(&fdi);
+                       assert(le);
+                       assert(le == ops_logger.peek_entry(&fdi));
+                       fail_read = true;
+                       assert(le == ops_logger.extract_entry(&fdi));
+                       fail_read = false;
+                       free((dlogutil_entry_s *) le);
+               }
+               fail_malloc = 0;
+               assert(!ops_logger.has_log(&fdi));
+               assert(NULL == ops_logger.peek_entry(&fdi));
+               fail_read = true;
+               assert(NULL == ops_logger.extract_entry(&fdi));
+               fail_read = false;
+       }
+
+       ops_logger.destroy(&fdi);
+}
diff --git a/src/tests/fdi_logger_pos.c b/src/tests/fdi_logger_pos.c
new file mode 100644 (file)
index 0000000..814f5a8
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2019-2020, Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "fdi_logger_wrap.c"
+
+int main()
+{
+       struct fd_info fdi = {
+               .fd = -1,
+               .priv_data = NULL,
+       };
+       list_head used_paths = NULL;
+
+       open_buf_ret = 1;
+       assert(!ops_logger.create(&fdi, (struct log_config *) 0xABDUL, "radio", &used_paths));
+       assert(fdi.fd == 0xFD);
+       assert(fdi.priv_data);
+
+       ops_logger.destroy(&fdi);
+       assert(!fdi.priv_data);
+
+       open_buf_path = "def";
+       assert(!ops_logger.create(&fdi, (struct log_config *) 0xABDUL, "radio", &used_paths));
+
+       expected_ioctl = LOGGER_FLUSH_LOG;
+       ioctl_ret = 15;
+       assert(0 == ops_logger.clear(&fdi));
+
+       unsigned int sz;
+       expected_ioctl = LOGGER_GET_LOG_BUF_SIZE;
+       ioctl_ret = 2019;
+       assert(0 == ops_logger.getsize(&fdi, &sz));
+       assert(2019 == sz);
+
+       expected_ioctl = LOGGER_GET_LOG_LEN;
+       ioctl_ret = 0;
+       assert(1 == ops_logger.prepare_print(&fdi, 123, false, (dlogutil_filter_options_s *) 0xCA5CADE));
+
+       ops_logger.destroy(&fdi);
+}
similarity index 52%
rename from src/tests/fdi_logger.c
rename to src/tests/fdi_logger_wrap.c
index 7072b17..5dc396a 100644 (file)
@@ -1,3 +1,19 @@
+/*
+ * Copyright (c) 2019-2020, Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
 // C
 #include <assert.h>
 
@@ -119,107 +135,3 @@ int __wrap_ioctl(int fd, int request, char *argp)
        return ioctl_ret;
 }
 
-int main()
-{
-       struct fd_info fdi = {
-               .fd = -1,
-               .priv_data = NULL,
-       };
-       list_head used_paths = NULL;
-
-       ops_logger.destroy(&fdi);
-
-       fail_malloc = 1;
-       assert(-ENOMEM == ops_logger.create(&fdi, (struct log_config *) 0xABDUL, "radio", &used_paths));
-
-       open_buf_ret = -536;
-       assert(-536 == ops_logger.create(&fdi, (struct log_config *) 0xABDUL, "radio", &used_paths));
-       open_buf_ret = 0;
-       assert(-EINVAL == ops_logger.create(&fdi, (struct log_config *) 0xABDUL, "radio", &used_paths));
-
-       open_buf_path = "abc";
-       open_buf_ret = 1;
-       fail_malloc = 2;
-       assert(-ENOMEM == ops_logger.create(&fdi, (struct log_config *) 0xABDUL, "radio", &used_paths));
-       assert(fdi.fd < 0);
-       assert(!fdi.priv_data);
-
-       fail_calloc = true;
-       assert(-ENOMEM == ops_logger.create(&fdi, (struct log_config *) 0xABDUL, "radio", &used_paths));
-       assert(fdi.fd < 0);
-       assert(!fdi.priv_data);
-       fail_calloc = false;
-
-       assert(!ops_logger.create(&fdi, (struct log_config *) 0xABDUL, "radio", &used_paths));
-       assert(fdi.fd == 0xFD);
-       assert(fdi.priv_data);
-
-       ops_logger.destroy(&fdi);
-       assert(!fdi.priv_data);
-       fdi.fd = -1;
-
-       assert(-EALREADY == ops_logger.create(&fdi, (struct log_config *) 0xABDUL, "radio", &used_paths));
-       assert(fdi.fd == -1);
-       assert(!fdi.priv_data);
-
-       open_buf_path = "def";
-       assert(!ops_logger.create(&fdi, (struct log_config *) 0xABDUL, "radio", &used_paths));
-
-       expected_ioctl = LOGGER_FLUSH_LOG;
-       ioctl_ret = -77;
-       assert(-77 == ops_logger.clear(&fdi));
-       ioctl_ret = 15;
-       assert(0 == ops_logger.clear(&fdi));
-
-       unsigned int sz;
-       expected_ioctl = LOGGER_GET_LOG_BUF_SIZE;
-       ioctl_ret = -EALREADY;
-       assert(-EALREADY == ops_logger.getsize(&fdi, &sz));
-       ioctl_ret = 2019;
-       assert(0 == ops_logger.getsize(&fdi, &sz));
-       assert(2019 == sz);
-
-       expected_ioctl = LOGGER_GET_LOG_LEN;
-       ioctl_ret = -67;
-       assert(-67 == ops_logger.prepare_print(&fdi, 123, false, (dlogutil_filter_options_s *) 0xCA5CADE));
-       expected_ioctl = LOGGER_GET_LOG_LEN;
-       ioctl_ret = 0;
-       assert(1 == ops_logger.prepare_print(&fdi, 123, false, (dlogutil_filter_options_s *) 0xCA5CADE));
-
-       expected_ioctl = -1;
-       assert(!ops_logger.prepare_print(&fdi, DLOGUTIL_MODE_CONTINUOUS, false, (dlogutil_filter_options_s *) 0xCA5CADE));
-
-       fail_read = true;
-       assert(-334 == ops_logger.read(&fdi));
-       fail_read = false;
-
-       for (size_t i = 0; i < NELEMS(READS) + 15; ++i) {
-               assert(!ops_logger.has_log(&fdi));
-               fail_read = true;
-               assert(NULL == ops_logger.extract_entry(&fdi));
-               assert(NULL == ops_logger.peek_entry(&fdi));
-               assert(NULL == ops_logger.extract_entry(&fdi));
-               fail_read = false;
-               fail_malloc = !(rand() % 4) * 3;
-               ops_logger.read(&fdi);
-               if (!fail_malloc && i < NELEMS(READS) && READS[i] > sizeof(struct android_logger_entry)) {
-                       assert(ops_logger.has_log(&fdi));
-                       assert(-EAGAIN == ops_logger.read(&fdi));
-                       const dlogutil_entry_s *const le = ops_logger.peek_entry(&fdi);
-                       assert(le);
-                       assert(le == ops_logger.peek_entry(&fdi));
-                       fail_read = true;
-                       assert(le == ops_logger.extract_entry(&fdi));
-                       fail_read = false;
-                       free((dlogutil_entry_s *) le);
-               }
-               fail_malloc = 0;
-               assert(!ops_logger.has_log(&fdi));
-               assert(NULL == ops_logger.peek_entry(&fdi));
-               fail_read = true;
-               assert(NULL == ops_logger.extract_entry(&fdi));
-               fail_read = false;
-       }
-
-       ops_logger.destroy(&fdi);
-}