FOREACH(flag ${pkgs_CFLAGS})
SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
ENDFOREACH(flag)
-SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -flto -Wall -Werror -Winline")
+SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -Wall -Werror -Winline")
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${EXTRA_CFLAGS}")
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include)
INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/src/library)
-function(add_mocked_test name test_flags)
- add_executable(test_${name} test_${name}.c ${ADD_MOCKED_TEST_SOURCES}
- ${COMPILE_OPTIONS} ${DEFAULT_C_COMPILE_FLAGS} ${ADD_MOCKED_TEST_COMPILE_OPTIONS}
- ${LINK_LIBRARIES} ${CMOCKA_LIBRARIES} ${ADD_MOCKED_TEST_LINK_LIBRARIES}
- ${LINK_OPTIONS} ${ADD_MOCKED_TEST_LINK_OPTIONS})
- add_test(test_${name} ${CMAKE_CURRENT_BINARY_DIR}/test_${name})
- target_link_libraries(test_${name} cmocka ${target}_static ${pkgs_LDFLAGS} ${test_flags})
+function(add_mocked_test name wraps)
+ add_executable(test_${name} test_${name}.c)
+
+ target_link_libraries(test_${name} cmocka ${target}_static ${pkgs_LDFLAGS} ${wraps})
if(ENABLE_COVERAGE)
target_link_libraries(test_${name} -fprofile-arcs -ftest-coverage -lgcov)
endif(ENABLE_COVERAGE)
+
+ add_test(test_${name} ${CMAKE_CURRENT_BINARY_DIR}/test_${name})
ADD_DEPENDENCIES(ctest test_${name})
endfunction(add_mocked_test)
-# register test files (source filename: test_[name].c)
-add_mocked_test(diagnostics_set_notification_cb "-Wl,--wrap,dbus_subscribe,--wrap,system_info_get_platform_bool")
-add_mocked_test(diagnostics_request_client_data "-Wl,--wrap,dumpsys_dump")
-add_mocked_test(diagnostics_get_client_id "")
+add_mocked_test(diagnostics_set_notification_cb "-Wl,--wrap=system_info_get_platform_bool,--wrap=dbus_subscribe")
+add_mocked_test(diagnostics_request_client_data "-Wl,--wrap=system_info_get_platform_bool,--wrap=dumpsys_dump")
+add_mocked_test(diagnostics_get_client_id "-Wl,--wrap=system_info_get_platform_bool")
add_mocked_test(diagnostics_get_report_path "")
-add_mocked_test(diagnostics_get_data "-Wl,--wrap,dbus_get_file_from_report")
-add_mocked_test(diagnostics_data_read "-Wl,--wrap,poll,--wrap,read")
+add_mocked_test(diagnostics_get_data "-Wl,--wrap=system_info_get_platform_bool,--wrap=dbus_get_file_from_report")
+add_mocked_test(diagnostics_data_read "-Wl,--wrap=system_info_get_platform_bool,--wrap=poll,--wrap=read")
add_mocked_test(diagnostics_create "")
add_mocked_test(diagnostics_data_create "")
add_mocked_test(diagnostics_signal_handler "")
#include <stdlib.h>
#include <system_info.h>
+#include <poll.h>
#include "signal.h"
#include "dbus.h"
int fd;
};
-int system_info_get_platform_bool(const char *key, bool *value)
+int __wrap_system_info_get_platform_bool(const char *key, bool *value)
{
*value = true;
return SYSTEM_INFO_ERROR_NONE;
}
+int __wrap_dumpsys_dump(const char *service_name, int argc, const char **argv, int *out_fd)
+{
+ (void) service_name;
+ (void) argc;
+ (void) argv;
+ (void) out_fd;
+
+ *out_fd = 1;
+
+ return (int)mock();
+}
+
+int __wrap_dbus_subscribe(void (*signal_handler)(GDBusConnection *, const gchar *, const gchar *, const gchar *, const gchar *, GVariant *, gpointer))
+{
+ (void) signal_handler;
+ return (int)mock();
+}
+
+int __wrap_dbus_get_file_from_report(const char *report_path, const int entry, int *fd)
+{
+ (void) report_path;
+ (void) entry;
+ *fd = 1;
+
+ return (int)mock();
+}
+
+int __wrap_poll(struct pollfd *__fds, nfds_t __nfds, int __timeout)
+{
+ (void) __fds;
+ (void) __nfds;
+ (void) __timeout;
+
+ __fds->revents = POLLIN;
+
+ return (int)mock();
+}
+
+ssize_t __wrap_read(int fd, void *buf, size_t nbytes)
+{
+ (void) fd;
+ (void) buf;
+ (void) nbytes;
+
+ return (int)mock();
+}
+
struct _diagnostics_ctx_s *build_ctx_crash()
{
struct _diagnostics_ctx_s *ctx = calloc(1, sizeof(struct _diagnostics_ctx_s));
#include "dbus.h"
#include <stdio.h>
-#include <poll.h>
#include "test_diagnostics.h"
assert_int_equal(diagnostics_data_read(&data, buf, count, timeout, NULL), DIAGNOSTICS_ERROR_INVALID_PARAMETER);
}
-int poll(struct pollfd *__fds, nfds_t __nfds, int __timeout)
-{
- (void) __fds;
- (void) __nfds;
- (void) __timeout;
-
- __fds->revents = POLLIN;
-
- return (int)mock();
-}
-
static void test_diagnostics_data_read_n5(void **state) {
(void) state;
struct _diagnostics_data_s data;
int timeout = 100;
size_t bytes_read = 0;
- will_return(poll, 0);
+ will_return(__wrap_poll, 0);
assert_int_equal(diagnostics_data_read(&data, buf, count, timeout, &bytes_read), DIAGNOSTICS_ERROR_TIMED_OUT);
}
int timeout = 100;
size_t bytes_read = 0;
- will_return(poll, -1);
+ will_return(__wrap_poll, -1);
assert_int_equal(diagnostics_data_read(&data, buf, count, timeout, &bytes_read), DIAGNOSTICS_ERROR_IO_ERROR);
}
-ssize_t read(int fd, void *buf, size_t nbytes)
-{
- (void) fd;
- (void) buf;
- (void) nbytes;
-
- return (int)mock();
-}
-
static void test_diagnostics_data_read_p1(void **state) {
(void) state;
struct _diagnostics_data_s data;
int timeout = 100;
size_t bytes_read = 0;
- will_return(poll, 1);
- will_return(read, 2);
+ will_return(__wrap_poll, 1);
+ will_return(__wrap_read, 2);
assert_int_equal(diagnostics_data_read(&data, buf, count, timeout, &bytes_read), DIAGNOSTICS_ERROR_NONE);
assert_int_equal(bytes_read, 2);
destroy_ctx(br_ptr);
}
-int dbus_get_file_from_report(const char *report_path, const int entry, int *fd)
-{
- (void) report_path;
- (void) entry;
- *fd = 1;
-
- return (int)mock();;
-}
-
static void test_diagnostics_get_data_p1(void **state) {
(void) state;
struct _diagnostics_ctx_s *ctx = build_ctx_crash();
struct _diagnostics_data_s *data = NULL;
const char *params[] = {"cs_full"};
- will_return(dbus_get_file_from_report, 0);
+ will_return(__wrap_dbus_get_file_from_report, 0);
int result = diagnostics_get_data(ctx, params, 1, (void**)&data);
int params_size = 0;
diagnostics_data_h data;
- will_return(dumpsys_dump, DIAGNOSTICS_ERROR_INVALID_PARAMETER);
+ will_return(__wrap_dumpsys_dump, DIAGNOSTICS_ERROR_INVALID_PARAMETER);
assert_int_equal(diagnostics_request_client_data(client_id, NULL, params_size, (void**)&data), DIAGNOSTICS_ERROR_IO_ERROR);
}
assert_int_equal(diagnostics_request_client_data(client_id, params, params_size, NULL), DIAGNOSTICS_ERROR_INVALID_PARAMETER);
}
-int dumpsys_dump(const char *service_name, int argc, const char **argv, int *out_fd)
-{
- (void) service_name;
- (void) argc;
- (void) argv;
- (void) out_fd;
-
- *out_fd = 1;
-
- return (int)mock();
-}
-
static void test_diagnostics_request_client_data_n5(void **state) {
(void) state;
const char *client_id = "";
const char *params[] = {"a", "b", "c"};
diagnostics_data_h data = NULL;
- will_return(dumpsys_dump, TIZEN_ERROR_CONNECTION_REFUSED);
+ will_return(__wrap_dumpsys_dump, TIZEN_ERROR_CONNECTION_REFUSED);
int result = diagnostics_request_client_data(client_id, params, params_size, (void**)&data);
const char *params[] = {"a", "b", "c"};
struct _diagnostics_data_s *data = NULL;
- will_return(dumpsys_dump, DIAGNOSTICS_ERROR_NONE);
+ will_return(__wrap_dumpsys_dump, DIAGNOSTICS_ERROR_NONE);
int result = diagnostics_request_client_data(client_id, params, params_size, (void**)&data);
assert_int_equal(diagnostics_set_notification_cb(NULL, NULL), DIAGNOSTICS_ERROR_INVALID_PARAMETER);
}
-int dbus_subscribe(void (*signal_handler)(GDBusConnection *,
- const gchar *,
- const gchar *,
- const gchar *,
- const gchar *,
- GVariant *,
- gpointer))
-{
- (void) signal_handler;
- return (int)mock();
-}
-
static void test_diagnostics_set_notification_cb_p1(void **state) {
(void) state;
- will_return(dbus_subscribe, DIAGNOSTICS_ERROR_NONE);
+ will_return(__wrap_dbus_subscribe, DIAGNOSTICS_ERROR_NONE);
assert_int_equal(diagnostics_set_notification_cb(callback, NULL), DIAGNOSTICS_ERROR_NONE);
assert_ptr_equal(cb_info.cb, callback);
static void test_diagnostics_set_notification_cb_p2(void **state) {
(void) state;
- will_return(dbus_subscribe, DIAGNOSTICS_ERROR_NONE);
+ will_return(__wrap_dbus_subscribe, DIAGNOSTICS_ERROR_NONE);
assert_int_equal(diagnostics_set_notification_cb(callback, NULL), DIAGNOSTICS_ERROR_NONE);
assert_int_equal(diagnostics_set_notification_cb(callback, NULL), DIAGNOSTICS_ERROR_RESOURCE_BUSY);