In C, argumentless functions are declared as receiving (void). It is,
however, more natural to declare them as receiving (). But this means
that the function can receive any number of arguments. This is bad.
We don't want this. We could miss some calls when adding arguments in
a refactor, leading to stack garbage/corruption.
Change-Id: I94732497663937fd3f9d30cea71a2eb966d6f439
66 files changed:
#define DYNAMIC_CONFIG_FILENAME "05-logctl.conf"
bool __dynamic_config_create(struct log_config *config);
#define DYNAMIC_CONFIG_FILENAME "05-logctl.conf"
bool __dynamic_config_create(struct log_config *config);
-void __dynamic_config_destroy();
-void __dynamic_config_update();
+void __dynamic_config_destroy(void);
+void __dynamic_config_update(void);
struct log_config;
extern int (*write_to_log)(log_id_t, log_priority, const char *tag, const char *msg, struct timespec *tp_mono);
struct log_config;
extern int (*write_to_log)(log_id_t, log_priority, const char *tag, const char *msg, struct timespec *tp_mono);
-extern void (*destroy_backend)();
+extern void (*destroy_backend)(void);
extern pthread_rwlock_t log_limiter_lock;
extern bool limiter;
extern pthread_rwlock_t log_limiter_lock;
extern bool limiter;
int __log_limiter_dump_rule(struct rule **, char *, const size_t);
// Note: result only valid until next __log_limiter_{update,destroy}
int __log_limiter_dump_rule(struct rule **, char *, const size_t);
// Note: result only valid until next __log_limiter_{update,destroy}
-list_head __log_limiter_get_pid_limits();
+list_head __log_limiter_get_pid_limits(void);
size_t size;
struct timespec oldest_log;
};
size_t size;
struct timespec oldest_log;
};
-struct log_filter *log_filter_new();
+struct log_filter *log_filter_new(void);
void log_filter_free(struct log_filter *p_filter);
struct log_filter {
void log_filter_free(struct log_filter *p_filter);
struct log_filter {
void log_filter_init(struct log_filter *p_filter);
void log_filter_init(struct log_filter *p_filter);
-struct log_write_buffer log_write_buffer_new();
+struct log_write_buffer log_write_buffer_new(void);
void log_write_buffer_free(struct log_write_buffer *buf);
void log_write_buffer_free(struct log_write_buffer *buf);
-struct metrics *metrics_create();
+struct metrics *metrics_create(void);
void metrics_destroy(struct metrics *);
bool metrics_add_log(struct metrics *, const dlogutil_entry_s *);
void metrics_destroy(struct metrics *);
bool metrics_add_log(struct metrics *, const dlogutil_entry_s *);
static char warning_content[WARNING_MAX];
static deduplicate_log basic_log;
static char warning_content[WARNING_MAX];
static deduplicate_log basic_log;
-static void refresh_deduplication_limits()
+static void refresh_deduplication_limits(void)
{
known_hashes_size = 0;
}
{
known_hashes_size = 0;
}
-void __deduplicate_destroy()
+void __deduplicate_destroy(void)
{
known_hashes_size = 0;
free(known_hashes_vector);
{
known_hashes_size = 0;
free(known_hashes_vector);
void deduplicate_warn(char *buf, size_t size, size_t len);
void __configure_deduplicate(struct log_config *config);
void deduplicate_warn(char *buf, size_t size, size_t len);
void __configure_deduplicate(struct log_config *config);
-void __deduplicate_destroy();
+void __deduplicate_destroy(void);
extern dlog_deduplicate_e (*deduplicate_func)(const char *, size_t, struct timespec *);
#endif /* _DEDUPLICATE_H_ */
extern dlog_deduplicate_e (*deduplicate_func)(const char *, size_t, struct timespec *);
#endif /* _DEDUPLICATE_H_ */
-static void __apply_update()
+static void __apply_update(void)
}
/// caller has to guarantee exclusive access
}
/// caller has to guarantee exclusive access
-void __dynamic_config_destroy()
+void __dynamic_config_destroy(void)
{
assert(inotify_fd < 0 || inotify_path);
assert(inotify_fd >= 0 || !inotify_path);
{
assert(inotify_fd < 0 || inotify_path);
assert(inotify_fd >= 0 || !inotify_path);
-void __dynamic_config_update()
+void __dynamic_config_update(void)
{
if (inotify_fd < 0)
return;
{
if (inotify_fd < 0)
return;
* @see __dlog_init_backend
*/
int (*write_to_log)(log_id_t log_id, log_priority prio, const char *tag, const char *msg, struct timespec *tp_mono) = NULL;
* @see __dlog_init_backend
*/
int (*write_to_log)(log_id_t log_id, log_priority prio, const char *tag, const char *msg, struct timespec *tp_mono) = NULL;
-void (*destroy_backend)();
+void (*destroy_backend)(void);
int (*stash_failed_log)(log_id_t log_id, log_priority prio, const char *tag, const char *msg) = NULL;
#ifndef UNIT_TEST
int (*stash_failed_log)(log_id_t log_id, log_priority prio, const char *tag, const char *msg) = NULL;
#ifndef UNIT_TEST
-static void __set_plog_default_values()
+static void __set_plog_default_values(void)
{
for (size_t i = 0; i < NELEMS(plog); ++i)
plog_default_values[i] = plog[i];
{
for (size_t i = 0; i < NELEMS(plog); ++i)
plog_default_values[i] = plog[i];
}
static bool first = true;
}
static bool first = true;
-static bool initialize()
+static bool initialize(void)
{
if (is_initialized)
return true;
{
if (is_initialized)
return true;
-static void __destroy_androidlogger()
+static void __destroy_androidlogger(void)
{
/* No need for an explicit lock here; this should only be called
* by the library destructor which has its own lock */
{
/* No need for an explicit lock here; this should only be called
* by the library destructor which has its own lock */
-static void __destroy_pipe()
+static void __destroy_pipe(void)
{
/* No need for an explicit lock here; this should only be called
* by the library destructor which has its own lock */
{
/* No need for an explicit lock here; this should only be called
* by the library destructor which has its own lock */
* @brief Print help
* @details Prints basic usage tips
*/
* @brief Print help
* @details Prints basic usage tips
*/
{
printf("Usage: %s [options]\n"
"\t-h Show this help\n"
{
printf("Usage: %s [options]\n"
"\t-h Show this help\n"
* @details Resets privileges to those specified at build-time
* @return 0 on success, else -errno
*/
* @details Resets privileges to those specified at build-time
* @return 0 on success, else -errno
*/
-int reset_self_privileges()
+int reset_self_privileges(void)
#include <sys/types.h>
int parse_permissions(const char *str);
#include <sys/types.h>
int parse_permissions(const char *str);
-int reset_self_privileges();
+int reset_self_privileges(void);
int usergr2id(const char *user, const char *group, uid_t *uid, gid_t *gid);
int usergr2id(const char *user, const char *group, uid_t *uid, gid_t *gid);
-static struct reader_logger *reader_logger_alloc()
+static struct reader_logger *reader_logger_alloc(void)
{
struct reader_logger *const ret = calloc(1, sizeof *ret);
if (!ret)
{
struct reader_logger *const ret = calloc(1, sizeof *ret);
if (!ret)
static const char dev_log_sock[] = "/run/dlog/dev-log";
static const char dev_log_link[] = "/dev/log";
static const char dev_log_sock[] = "/run/dlog/dev-log";
static const char dev_log_link[] = "/dev/log";
+int dev_log_sock_get(void)
{
return systemd_sock_get(dev_log_sock, SOCK_DGRAM);
}
{
return systemd_sock_get(dev_log_sock, SOCK_DGRAM);
}
-int dev_log_sock_create()
+int dev_log_sock_create(void)
{
int fd = bind_fd_create(dev_log_sock, SOCK_DGRAM);
if (fd >= 0) {
{
int fd = bind_fd_create(dev_log_sock, SOCK_DGRAM);
if (fd >= 0) {
int socket_initialize(struct sock_data *sock, struct log_buffer *buffer, service_socket_t service_socket, struct socket_config_data *data);
void socket_close(struct sock_data *sock);
int socket_initialize(struct sock_data *sock, struct log_buffer *buffer, service_socket_t service_socket, struct socket_config_data *data);
void socket_close(struct sock_data *sock);
-int dev_log_sock_get();
-int dev_log_sock_create();
+int dev_log_sock_get(void);
+int dev_log_sock_create(void);
#ifdef UNIT_TEST
int bind_fd_create(const char *path, int type);
#ifdef UNIT_TEST
int bind_fd_create(const char *path, int type);
-static struct pass_log_result block_by_pid()
+static struct pass_log_result block_by_pid(void)
{
pid_t my_pid = getpid();
{
pid_t my_pid = getpid();
-static void destroy_hashmap_etc()
+static void destroy_hashmap_etc(void)
{
hashmap_destroy(&rules_hashmap);
rules_destroy(&original_rules_table);
{
hashmap_destroy(&rules_hashmap);
rules_destroy(&original_rules_table);
-list_head __log_limiter_get_pid_limits()
+list_head __log_limiter_get_pid_limits(void)
-struct metrics *metrics_create()
+struct metrics *metrics_create(void)
{
return calloc(1, sizeof(struct metrics));
}
{
return calloc(1, sizeof(struct metrics));
}
return fail_calloc ? NULL : __real_calloc(nmemb, size);
}
return fail_calloc ? NULL : __real_calloc(nmemb, size);
}
{
const char * get;
struct log_config config;
{
const char * get;
struct log_config config;
{
called_atexit = false;
assert(!atexit(atexit_f));
{
called_atexit = false;
assert(!atexit(atexit_f));
assert(dlog_print(DLOG_INFO, "tag", fmt) == ret);
}
assert(dlog_print(DLOG_INFO, "tag", fmt) == ret);
}
-void test_basic_1ms_interval()
+void test_basic_1ms_interval(void)
{
local_advanced = "only_identical_neighbours";
local_time_ms = "1";
{
local_advanced = "only_identical_neighbours";
local_time_ms = "1";
-void test_basic_10ms_interval()
+void test_basic_10ms_interval(void)
{
local_advanced = "only_identical_neighbours";
local_time_ms = "10";
{
local_advanced = "only_identical_neighbours";
local_time_ms = "10";
-void test_basic_1ms_interval_warning()
+void test_basic_1ms_interval_warning(void)
{
local_advanced = "only_identical_neighbours";
local_time_ms = "10";
{
local_advanced = "only_identical_neighbours";
local_time_ms = "10";
-void test_advanced_1ms_interval()
+void test_advanced_1ms_interval(void)
{
local_advanced = "all_identical_logs";
local_time_ms = "1";
{
local_advanced = "all_identical_logs";
local_time_ms = "1";
-void test_advanced_10ms_interval()
+void test_advanced_10ms_interval(void)
{
local_advanced = "all_identical_logs";
local_time_ms = "10";
{
local_advanced = "all_identical_logs";
local_time_ms = "10";
-void test_advanced_10ms_interval_warning()
+void test_advanced_10ms_interval_warning(void)
{
local_advanced = "all_identical_logs";
local_time_ms = "10";
{
local_advanced = "all_identical_logs";
local_time_ms = "10";
-void test_advanced_many_hashes()
+void test_advanced_many_hashes(void)
{
local_advanced = "all_identical_logs";
local_time_ms = "1";
{
local_advanced = "all_identical_logs";
local_time_ms = "1";
-void test_advanced_many_millisec()
+void test_advanced_many_millisec(void)
{
local_advanced = "all_identical_logs";
local_time_ms = "1";
{
local_advanced = "all_identical_logs";
local_time_ms = "1";
-void test_deduplicate_warn()
+void test_deduplicate_warn(void)
{
use_real_deduplicate_warn = true;
local_warn_quantity = "11";
{
use_real_deduplicate_warn = true;
local_warn_quantity = "11";
-void test_deduplicate_warn_random()
+void test_deduplicate_warn_random(void)
{
use_real_deduplicate_warn = false;
local_advanced = "only_identical_neighbours";
{
use_real_deduplicate_warn = false;
local_advanced = "only_identical_neighbours";
{
test_basic_1ms_interval();
test_basic_10ms_interval();
{
test_basic_1ms_interval();
test_basic_10ms_interval();
return pretend_the_mutex_is_locked ? -1 : __real_pthread_mutex_trylock(mutex);
}
return pretend_the_mutex_is_locked ? -1 : __real_pthread_mutex_trylock(mutex);
}
{
// check whether these blow up when called before init
__dynamic_config_update();
{
// check whether these blow up when called before init
__dynamic_config_update();
#include "fd_info_wrap.c"
#include "fd_info_wrap.c"
{
struct fd_ops fops = {
.destroy = test_destroy,
{
struct fd_ops fops = {
.destroy = test_destroy,
#include "fd_info_wrap.c"
#include "fd_info_wrap.c"
{
struct fd_ops fops = {
.destroy = test_destroy,
{
struct fd_ops fops = {
.destroy = test_destroy,
#include "fdi_logger_wrap.c"
#include "fdi_logger_wrap.c"
{
struct fd_info fdi = {
.fd = -1,
{
struct fd_info fdi = {
.fd = -1,
assert(READS[N] == ops_logger.read(fdi));
}
assert(READS[N] == ops_logger.read(fdi));
}
{
struct fd_info fdi = {
.fd = -1,
{
struct fd_info fdi = {
.fd = -1,
#include "fdi_pipe_wrap.c"
#include "fdi_pipe_wrap.c"
{
struct fd_info info = {
.ops = &ops_pipe,
{
struct fd_info info = {
.ops = &ops_pipe,
#include "fdi_pipe_wrap.c"
#include "fdi_pipe_wrap.c"
{
struct fd_info info = {
.ops = &ops_pipe,
{
struct fd_info info = {
.ops = &ops_pipe,
{
struct log_filter *const f = log_filter_new();
assert(f);
{
struct log_filter *const f = log_filter_new();
assert(f);
{
int err;
int result = 0;
{
int err;
int result = 0;
-static void validate_hash()
+static void validate_hash(void)
{
static const size_t BUCKET_SIZE = UINT32_MAX / NUM_BUCKETS + 1;
static const size_t BUCKET_AVG_COUNT = NELEMS(hash_values) / NUM_BUCKETS;
{
static const size_t BUCKET_SIZE = UINT32_MAX / NUM_BUCKETS + 1;
static const size_t BUCKET_AVG_COUNT = NELEMS(hash_values) / NUM_BUCKETS;
-static void test_permutations()
+static void test_permutations(void)
add_hash(hash, sizeof hash);
}
add_hash(hash, sizeof hash);
}
{
assert_result("" , -EINVAL);
assert_result("invalid" , -EINVAL);
{
assert_result("" , -EINVAL);
assert_result("invalid" , -EINVAL);
{
struct dlogutil_entry_with_msg lem;
{
struct dlogutil_entry_with_msg lem;
#include "libdlog_android_wrapper.c"
#include "libdlog_android_wrapper.c"
{
fail_open = true;
__dlog_init_android(&CONF);
{
fail_open = true;
__dlog_init_android(&CONF);
#include "libdlog_android_wrapper.c"
#include "libdlog_android_wrapper.c"
{
fail_open = false;
__dlog_init_android(&CONF);
{
fail_open = false;
__dlog_init_android(&CONF);
#endif /* USE_ANDROID_MONOTONIC */
int (*write_to_log)(log_id_t, log_priority, const char *tag, const char *msg, struct timespec *tp_mono) = NULL;
#endif /* USE_ANDROID_MONOTONIC */
int (*write_to_log)(log_id_t, log_priority, const char *tag, const char *msg, struct timespec *tp_mono) = NULL;
-void (*destroy_backend)() = NULL;
+void (*destroy_backend)(void) = NULL;
extern void __dlog_init_android(const struct log_config *conf);
static struct log_config CONF;
extern void __dlog_init_android(const struct log_config *conf);
static struct log_config CONF;
#include "libdlog_base_wrap.c"
#include "libdlog_base_wrap.c"
{
fail_conf_read = true;
__configure();
{
fail_conf_read = true;
__configure();
#include "libdlog_base_wrap.c"
#include "libdlog_base_wrap.c"
{
log_config_set(&CONFIG, "backend", "pipe");
log_config_set(&CONFIG, "limiter", "0");
{
log_config_set(&CONFIG, "backend", "pipe");
log_config_set(&CONFIG, "limiter", "0");
void __log_limiter_update(const struct log_config *config) { }
void __log_limiter_destroy(void) { }
void __log_limiter_update(const struct log_config *config) { }
void __log_limiter_destroy(void) { }
-void __dynamic_config_destroy() { }
+void __dynamic_config_destroy(void) { }
bool __dynamic_config_create(struct log_config *config) { return use_dynamic_conf; }
static bool dynamic_config_called;
bool __dynamic_config_create(struct log_config *config) { return use_dynamic_conf; }
static bool dynamic_config_called;
-void __dynamic_config_update() { dynamic_config_called = true; }
+void __dynamic_config_update(void) { dynamic_config_called = true; }
bool fail_snprintf;
int __wrap_snprintf(char *str, size_t size, const char *format, ...)
bool fail_snprintf;
int __wrap_snprintf(char *str, size_t size, const char *format, ...)
{
/* These are a copy of TCT tests:
* repository: test/tct/native/api on tizen.org
{
/* These are a copy of TCT tests:
* repository: test/tct/native/api on tizen.org
#include <logconfig.h>
int (*write_to_log)(log_id_t, log_priority, const char *tag, const char *msg) = NULL;
#include <logconfig.h>
int (*write_to_log)(log_id_t, log_priority, const char *tag, const char *msg) = NULL;
-void (*destroy_backend)() = NULL;
+void (*destroy_backend)(void) = NULL;
extern void __dlog_init_pipe(const struct log_config *conf);
extern void __dlog_init_pipe(const struct log_config *conf);
{
struct log_config conf = {NULL, NULL};
{
struct log_config conf = {NULL, NULL};
// lobotomize various mechanisms I don't want to deal with
void __log_limiter_update(const struct log_config *config) { }
void __log_limiter_destroy(void) { }
// lobotomize various mechanisms I don't want to deal with
void __log_limiter_update(const struct log_config *config) { }
void __log_limiter_destroy(void) { }
-void __dynamic_config_destroy() { }
+void __dynamic_config_destroy(void) { }
struct pass_log_result __log_limiter_pass_log(const char *tag, int prio) { return (struct pass_log_result) { .decision = DECISION_ALLOWED }; }
int __log_limiter_create(const struct log_config *config) { return 1; }
bool __dynamic_config_create(struct log_config *config) { return false; }
struct pass_log_result __log_limiter_pass_log(const char *tag, int prio) { return (struct pass_log_result) { .decision = DECISION_ALLOWED }; }
int __log_limiter_create(const struct log_config *config) { return 1; }
bool __dynamic_config_create(struct log_config *config) { return false; }
-void __dynamic_config_update() { }
+void __dynamic_config_update(void) { }
void __dlog_init_android(const struct log_config *conf) { }
void __dlog_init_android(const struct log_config *conf) { }
{
#define VALID_FILTER(x) assert(dlog_set_minimum_priority(x) == DLOG_ERROR_NONE)
#define INVALID_FILTER(x) assert(dlog_set_minimum_priority(x) == DLOG_ERROR_INVALID_PARAMETER)
{
#define VALID_FILTER(x) assert(dlog_set_minimum_priority(x) == DLOG_ERROR_NONE)
#define INVALID_FILTER(x) assert(dlog_set_minimum_priority(x) == DLOG_ERROR_INVALID_PARAMETER)
#include "limiter_wrap.c"
#include "limiter_wrap.c"
{
__log_limiter_destroy(); // check whether it explodes if called before init
{
__log_limiter_destroy(); // check whether it explodes if called before init
#include "limiter_wrap.c"
#include "limiter_wrap.c"
{
struct log_config conf = {NULL, NULL};
assert(!__log_limiter_create(&conf));
{
struct log_config conf = {NULL, NULL};
assert(!__log_limiter_create(&conf));
#include <loglimiter.h>
#include <loglimiter-internal.h>
#include <loglimiter.h>
#include <loglimiter-internal.h>
-static size_t get_rulecount()
+static size_t get_rulecount(void)
{
size_t cnt = 0;
struct rule *r = NULL;
{
size_t cnt = 0;
struct rule *r = NULL;
// We should also set errno, but we won't
}
// We should also set errno, but we won't
}
{
struct log_file lf;
logfile_init(&lf);
{
struct log_file lf;
logfile_init(&lf);
}
#define COMPARE_FILE(lines) _compare_file(lines, NELEMS(lines))
}
#define COMPARE_FILE(lines) _compare_file(lines, NELEMS(lines))
-void test_copy_file_with_exceptions()
+void test_copy_file_with_exceptions(void)
{
static const char *const lines_in[] = {
"FOO=BAR",
{
static const char *const lines_in[] = {
"FOO=BAR",
-void test_handle_clear()
+void test_handle_clear(void)
{
static const char *const lines_in[] = {
"limiter|x|y=BAR",
{
static const char *const lines_in[] = {
"limiter|x|y=BAR",
COMPARE_FILE(lines_out);
}
COMPARE_FILE(lines_out);
}
+void test_handle_set(void)
{
static const char *const lines_in[] = {
"QWER=QWER",
{
static const char *const lines_in[] = {
"QWER=QWER",
assert(EXIT_SUCCESS == handle_set(&pp, TMPFILE_PATH, NULL));
}
assert(EXIT_SUCCESS == handle_set(&pp, TMPFILE_PATH, NULL));
}
+void test_handle_plog(void)
{
static const char *const lines_in[] = {
"QWER=QWER",
{
static const char *const lines_in[] = {
"QWER=QWER",
assert(!pp.tag || !strcmp(exp->pp.tag, pp.tag));
}
assert(!pp.tag || !strcmp(exp->pp.tag, pp.tag));
}
-void test_parse_options()
+void test_parse_options(void)
{
/* These are primarily covered by integration tests but there's some value
* in running this at build time as well to detect any breakage ASAP. */
{
/* These are primarily covered by integration tests but there's some value
* in running this at build time as well to detect any breakage ASAP. */
#undef CHECK_OPTION_SET
}
#undef CHECK_OPTION_SET
}
{
test_copy_file_with_exceptions();
test_parse_options();
{
test_copy_file_with_exceptions();
test_parse_options();
int bind_fd_create(const char *path, int type);
int listen_fd_create(const char *path, int permissions);
int systemd_sock_get(const char *path, int type);
int bind_fd_create(const char *path, int type);
int listen_fd_create(const char *path, int permissions);
int systemd_sock_get(const char *path, int type);
-int dev_log_sock_get();
-int dev_log_sock_create();
+int dev_log_sock_get(void);
+int dev_log_sock_create(void);
int create_kmsg_writer(struct writer **writer, struct log_buffer *log_buffer);
int service_writer_kmsg(struct logger *server, struct writer *wr, struct epoll_event *event);
int create_syslog_writer(struct writer **writer, struct log_buffer *log_buffer);
int create_kmsg_writer(struct writer **writer, struct log_buffer *log_buffer);
int service_writer_kmsg(struct logger *server, struct writer *wr, struct epoll_event *event);
int create_syslog_writer(struct writer **writer, struct log_buffer *log_buffer);
return new_reader_fail ? NULL : (log_storage_reader *)0x600D;
}
return new_reader_fail ? NULL : (log_storage_reader *)0x600D;
}
{
assert(parse_permissions(NULL) == (S_IWUSR | S_IWGRP | S_IWOTH));
assert(parse_permissions("All the permissions") == 0);
{
assert(parse_permissions(NULL) == (S_IWUSR | S_IWGRP | S_IWOTH));
assert(parse_permissions("All the permissions") == 0);
#define CHECK_LOGPRINT_TESTCASES(MSG, TESTS) check_logprint_testcases_standard(MSG, sizeof MSG, TESTS, NELEMS(TESTS))
#define CHECK_LOGPRINT_TESTCASES_INVALID(MSG, TESTS) check_logprint_testcases_invalid(MSG, sizeof MSG, TESTS, NELEMS(TESTS))
#define CHECK_LOGPRINT_TESTCASES(MSG, TESTS) check_logprint_testcases_standard(MSG, sizeof MSG, TESTS, NELEMS(TESTS))
#define CHECK_LOGPRINT_TESTCASES_INVALID(MSG, TESTS) check_logprint_testcases_invalid(MSG, sizeof MSG, TESTS, NELEMS(TESTS))
-void check_log_print_log_line()
+void check_log_print_log_line(void)
{
static const struct logprint_test_case tests_basic[] = {
// formats using the SENT timestamp
{
static const struct logprint_test_case tests_basic[] = {
// formats using the SENT timestamp
CHECK_LOGPRINT_TESTCASES_INVALID("BASIC TAG\0Basic message.", tests_fixup_pipe);
}
CHECK_LOGPRINT_TESTCASES_INVALID("BASIC TAG\0Basic message.", tests_fixup_pipe);
}
-void check_log_print_log_line_buffer()
+void check_log_print_log_line_buffer(void)
{
struct dlogutil_entry_with_msg entry;
const char tag_msg[] = "tag\0msg";
{
struct dlogutil_entry_with_msg entry;
const char tag_msg[] = "tag\0msg";
const char *json_priority_name(log_priority prio);
struct timespec entry_get_ts(const dlogutil_entry_s *entry, bool sent, bool mono);
char *log_format_json(char *default_buffer, size_t default_buffer_size, const dlogutil_entry_s *entry, size_t *p_outLength, char *tag, char *msg);
const char *json_priority_name(log_priority prio);
struct timespec entry_get_ts(const dlogutil_entry_s *entry, bool sent, bool mono);
char *log_format_json(char *default_buffer, size_t default_buffer_size, const dlogutil_entry_s *entry, size_t *p_outLength, char *tag, char *msg);
{
// TODO: Failure testing
check_json_escape_string_testcase("abc/def", "abc/def");
{
// TODO: Failure testing
check_json_escape_string_testcase("abc/def", "abc/def");
-void check_utf8_correctness()
+void check_utf8_correctness(void)
{
/* © is two bytes */
static const struct logprint_test_case test_2_bytes_0_shift[] = {
{
/* © is two bytes */
static const struct logprint_test_case test_2_bytes_0_shift[] = {
CHECK_LOGPRINT_TESTCASES("123💯💯💯💯💯💯💯💯💯💯💯💯💯💯💯💯💯💯💯💯💯💯💯💯💯💯💯💯💯💯💯💯💯💯💯💯💯💯💯💯💯💯💯💯💯💯💯💯💯💯\0foo1", test_4_bytes_3_shift);
}
CHECK_LOGPRINT_TESTCASES("123💯💯💯💯💯💯💯💯💯💯💯💯💯💯💯💯💯💯💯💯💯💯💯💯💯💯💯💯💯💯💯💯💯💯💯💯💯💯💯💯💯💯💯💯💯💯💯💯💯💯\0foo1", test_4_bytes_3_shift);
}
-void check_syscall_failure_handling()
+void check_syscall_failure_handling(void)
{
struct log_filter *const filter = log_filter_new();
assert(filter);
{
struct log_filter *const filter = log_filter_new();
assert(filter);
log_filter_free(filter);
}
log_filter_free(filter);
}
-void check_invalid_input()
+void check_invalid_input(void)
{
const dlogutil_entry_s entry = { .len = 1 };
const char *data;
{
const dlogutil_entry_s entry = { .len = 1 };
const char *data;
log_filter_free(filter);
}
log_filter_free(filter);
}
-void check_log_format_from_string()
+void check_log_format_from_string(void)
{
static const struct {
char const *string;
{
static const struct {
char const *string;
assert(log_format_from_string(expected_formats[i].string) == expected_formats[i].format);
}
assert(log_format_from_string(expected_formats[i].string) == expected_formats[i].format);
}
-void check_get_format_sorting()
+void check_get_format_sorting(void)
{
static const struct {
log_print_format format;
{
static const struct {
log_print_format format;
-void check_filter_pri_to_char()
+void check_filter_pri_to_char(void)
{
static const struct {
log_priority pri;
{
static const struct {
log_priority pri;
assert(filter_pri_to_char(expected_chars[i].pri) == expected_chars[i].c);
}
assert(filter_pri_to_char(expected_chars[i].pri) == expected_chars[i].c);
}
-void log_filter_default()
+void log_filter_default(void)
{
struct log_filter *const filter = log_filter_new();
bool ret = log_filter_need_apply_default(filter);
{
struct log_filter *const filter = log_filter_new();
bool ret = log_filter_need_apply_default(filter);
log_filter_free(filter);
}
log_filter_free(filter);
}
{
check_log_format_from_string();
check_get_format_sorting();
{
check_log_format_from_string();
check_get_format_sorting();
{
struct sort_vector sv;
sort_vector_init(&sv);
{
struct sort_vector sv;
sort_vector_init(&sv);
#include "logutil_wrap.c"
#include "logutil_wrap.c"
{
struct sort_vector sv;
sort_vector_init(&sv);
{
struct sort_vector sv;
sort_vector_init(&sv);
#include "logutil_wrap.c"
#include "logutil_wrap.c"
{
struct sort_vector sv;
sort_vector_init(&sv);
{
struct sort_vector sv;
sort_vector_init(&sv);
{
struct metrics *m = metrics_create();
assert(m);
{
struct metrics *m = metrics_create();
assert(m);
#include <loglimiter-internal.h>
time_t time_ret = 0;
#include <loglimiter-internal.h>
time_t time_ret = 0;
+void advance_clock(void)
+pid_t __wrap_getpid(void)
{
struct log_config conf = {NULL, NULL};
log_config_set(&conf, "pidlimit|77", "7");
{
struct log_config conf = {NULL, NULL};
log_config_set(&conf, "pidlimit|77", "7");
{
int prio = 5;
char tag[] = "TEST_TAG";
{
int prio = 5;
char tag[] = "TEST_TAG";
-void test_proportional_raw()
+void test_proportional_raw(void)
{
struct metrics_pid_aggr_info i1 [] =
{{ .count = 8, }
{
struct metrics_pid_aggr_info i1 [] =
{{ .count = 8, }
assert(i1[3].count == 80);
}
assert(i1[3].count == 80);
}
{
struct metrics_pid_aggr_info i1 [] =
{{ .count = 1, }
{
struct metrics_pid_aggr_info i1 [] =
{{ .count = 1, }
assert(i1[3].count == 50);
}
assert(i1[3].count == 50);
}
+void test_equal_dual(void)
{
struct metrics_pid_aggr_info i1 [] =
{{ .count = 20, }
{
struct metrics_pid_aggr_info i1 [] =
{{ .count = 20, }
assert(i1[2].count == 90); // 120 >= 200/3, 90 == (200-20)/2
}
assert(i1[2].count == 90); // 120 >= 200/3, 90 == (200-20)/2
}
+void test_equal_multi(void)
{
struct metrics_pid_aggr_info i1 [] =
{{ .count = 30, }
{
struct metrics_pid_aggr_info i1 [] =
{{ .count = 30, }
assert(i2[2].count == 95); // 120 >= 200/3, and 120 >= (200-20)/2, and 120 >= (200-20-85)/1
}
assert(i2[2].count == 95); // 120 >= 200/3, and 120 >= (200-20)/2, and 120 >= (200-20-85)/1
}
-void test_proportional_talmud()
+void test_proportional_talmud(void)
{
struct metrics_pid_aggr_info i1 [] =
{{ .count = 50, }
{
struct metrics_pid_aggr_info i1 [] =
{{ .count = 50, }
assert(i8[3].count == 317);
}
assert(i8[3].count == 317);
}
{
test_proportional_raw();
test_equal();
{
test_proportional_raw();
test_equal();
#include <queued_entry.h>
#include <queued_entry_timestamp.h>
#include <queued_entry.h>
#include <queued_entry_timestamp.h>
{
struct log_config conf = {NULL, NULL};
const struct {
{
struct log_config conf = {NULL, NULL};
const struct {
#include <queued_entry.h>
#include <queued_entry_timestamp.h>
#include <queued_entry.h>
#include <queued_entry_timestamp.h>
{
assert(get_proper_clock(DLOGUTIL_SORT_SENT_MONO) == CLOCK_MONOTONIC);
assert(get_proper_clock(DLOGUTIL_SORT_SENT_REAL) == CLOCK_REALTIME);
{
assert(get_proper_clock(DLOGUTIL_SORT_SENT_MONO) == CLOCK_MONOTONIC);
assert(get_proper_clock(DLOGUTIL_SORT_SENT_REAL) == CLOCK_REALTIME);
#include <logcommon.h>
#include <queued_entry.h>
#include <logcommon.h>
#include <queued_entry.h>
+void test_negative(void)
{
struct dlogutil_entry_with_msg dewm;
{
struct dlogutil_entry_with_msg dewm;
assert(dewm.header.nsec_sent_mono == -1);
}
assert(dewm.header.nsec_sent_mono == -1);
}
+void test_positive(void)
{
struct dlogutil_entry_with_msg dewm;
{
struct dlogutil_entry_with_msg dewm;
assert(dewm.header.nsec_sent_real == 666666666);
}
assert(dewm.header.nsec_sent_real == 666666666);
}
{
test_negative();
test_positive();
{
test_negative();
test_positive();
return fail_calloc ? NULL : __real_calloc(nmemb, size);
}
return fail_calloc ? NULL : __real_calloc(nmemb, size);
}
+void fail_calloc_test(void)
{
struct sort_vector sv;
sort_vector_init(&sv);
{
struct sort_vector sv;
sort_vector_init(&sv);
+void empty_timestamp(void)
{
struct sort_vector sv;
sort_vector_init(&sv);
{
struct sort_vector sv;
sort_vector_init(&sv);
assert(sort_vector_time_span(&sv, (struct timespec) { .tv_nsec = -1, }) == -1);
}
assert(sort_vector_time_span(&sv, (struct timespec) { .tv_nsec = -1, }) == -1);
}
+void logs_order_empty(void)
{
struct sort_vector sv;
sort_vector_init(&sv);
{
struct sort_vector sv;
sort_vector_init(&sv);
assert(third->pid == 789);
}
assert(third->pid == 789);
}
+void logs_order_mix(void)
{
struct sort_vector sv;
sort_vector_init(&sv);
{
struct sort_vector sv;
sort_vector_init(&sv);
assert(fourth->pid == 789);
}
assert(fourth->pid == 789);
}
{
fail_calloc_test();
empty_timestamp();
{
fail_calloc_test();
empty_timestamp();
{
struct sort_vector sv;
sort_vector_init(&sv);
{
struct sort_vector sv;
sort_vector_init(&sv);
+time_t get_time_t_max(void)
{
return ~(1UL << (sizeof(time_t) * CHAR_BIT - 1));
}
{
return ~(1UL << (sizeof(time_t) * CHAR_BIT - 1));
}
+time_t get_time_t_min(void)
{
return 1UL << (sizeof(time_t) * CHAR_BIT - 1);
}
{
return 1UL << (sizeof(time_t) * CHAR_BIT - 1);
}
assert((unsigned long) (sort_vector_time_span(&sv, (struct timespec) { .tv_nsec = -1 })) == time_span);
}
assert((unsigned long) (sort_vector_time_span(&sv, (struct timespec) { .tv_nsec = -1 })) == time_span);
}
-void call_time_span_test()
+void call_time_span_test(void)
{
time_span_test(5, 7, 2000);
time_span_test(7, 5, (unsigned long) -2000);
{
time_span_test(5, 7, 2000);
time_span_test(7, 5, (unsigned long) -2000);
{
complex_test();
call_time_span_test();
{
complex_test();
call_time_span_test();
#include <stdio.h>
#include <assert.h>
#include <stdio.h>
#include <assert.h>
{
char buffer[1024];
int len;
{
char buffer[1024];
int len;
#include <stdio.h>
#include <assert.h>
#include <stdio.h>
#include <assert.h>
{
char buffer[1024];
int len;
{
char buffer[1024];
int len;
test_reader_get_new_entry(r, check_base+i+1);
}
test_reader_get_new_entry(r, check_base+i+1);
}
{
/************* TEST 1 ***************/
/* Small storage, calling callbacks on removing log entries */
{
/************* TEST 1 ***************/
/* Small storage, calling callbacks on removing log entries */
#include "test_ptrs_list_wrap.c"
#include "test_ptrs_list_wrap.c"
{
list_head head = NULL;
assert(list_count(head) == 0);
{
list_head head = NULL;
assert(list_count(head) == 0);
#include "test_ptrs_list_wrap.c"
#include "test_ptrs_list_wrap.c"
{
list_head head = NULL;
assert(list_count(head) == 0);
{
list_head head = NULL;
assert(list_count(head) == 0);
dlogutil_state_destroy(state);
}
dlogutil_state_destroy(state);
}
{
dlogutil_config_s *c = dlogutil_config_create();
{
dlogutil_config_s *c = dlogutil_config_create();
dlogutil_state_destroy(state);
}
dlogutil_state_destroy(state);
}
+void negative_main(void)
{
dlogutil_config_s *config = dlogutil_config_create();
assert(config);
{
dlogutil_config_s *config = dlogutil_config_create();
assert(config);