src/tests/hash_test \
src/tests/deduplicate_test \
src/tests/pid_limiter \
+ src/tests/qos_distributions \
src/tests/filters
check_CFLAGS = $(AM_CFLAGS) -O0 -fprofile-arcs -DUNIT_TEST \
src_tests_logprint_CFLAGS = $(check_CFLAGS)
src_tests_logprint_LDFLAGS = $(AM_LDFLAGS) -Wl,--wrap=write,--wrap=malloc,--wrap=calloc,--wrap=localtime_r,--wrap=strdup,--wrap=strndup,--wrap=list_add
+src_tests_qos_distributions_SOURCES = src/tests/qos_distributions.c \
+ src/logger/qos.c
+src_tests_qos_distributions_CFLAGS = $(check_CFLAGS)
+src_tests_qos_distributions_LDFLAGS = $(AM_LDFLAGS)
+
src_tests_logger_SOURCES = src/tests/logger.c $(dlog_logger_SOURCES)
src_tests_logger_CFLAGS = $(check_CFLAGS)
src_tests_logger_LDFLAGS = $(AM_LDFLAGS) -Wl,--wrap=getgrnam_r,--wrap=getpwnam_r,--wrap=getegid,--wrap=geteuid,--wrap=setgid,--wrap=setuid,--wrap=socket,--wrap=unlink,--wrap=bind,--wrap=close,--wrap=chmod,--wrap=listen,--wrap=sysconf,--wrap=sd_listen_fds,--wrap=sd_is_socket_unix,--wrap=symlink,--wrap=calloc,--wrap=open,--wrap=open64,--wrap=fcntl,--wrap=fcntl64,--wrap=log_storage_reader_get_ready_bytes,--wrap=free,--wrap=logfile_free,--wrap=log_storage_add_new_entry,--wrap=log_storage_release_reader,--wrap=epoll_ctl,--wrap=log_storage_new_reader
--- /dev/null
+#include <assert.h>
+#include "../logger/qos.h"
+
+/* Some proportional modes look at the cached total log count, which
+ * is cached in the metrics struct which we don't want to fill normally,
+ * so we just implement this function instead of linking to the actual
+ * metrics implementation. */
+int total_logs;
+int metrics_get_total(const struct metrics *m)
+{
+ return total_logs;
+}
+
+void test_proportional()
+{
+ struct metrics_pid_aggr_info i1 [] =
+ {{ .count = 8, }
+ ,{ .count = 12, }
+ ,{ .count = 4, }
+ ,{ .count = 16, }
+ };
+ total_logs = 8 + 12 + 4 + 16;
+
+ qos_distribution_proportional(&(struct qos_module) { .max_throughput = 200 }, i1, 4);
+ assert(i1[0].count == 40);
+ assert(i1[1].count == 60);
+ assert(i1[2].count == 20);
+ assert(i1[3].count == 80);
+}
+
+void test_equal()
+{
+ struct metrics_pid_aggr_info i1 [] =
+ {{ .count = 1, }
+ ,{ .count = 66, }
+ ,{ .count = 17, }
+ ,{ .count = 42, }
+ };
+ total_logs = 1 + 66 + 17 + 42;
+
+ qos_distribution_equal(&(struct qos_module) { .max_throughput = 200 }, i1, 4);
+ assert(i1[0].count == 50);
+ assert(i1[1].count == 50);
+ assert(i1[2].count == 50);
+ assert(i1[3].count == 50);
+}
+
+int main()
+{
+ test_proportional();
+ test_equal();
+}