QoS: add distribution unit tests 13/240813/2
authorMichal Bloch <m.bloch@samsung.com>
Tue, 11 Aug 2020 13:22:59 +0000 (15:22 +0200)
committerMichal Bloch <m.bloch@samsung.com>
Wed, 12 Aug 2020 11:00:48 +0000 (13:00 +0200)
Change-Id: I68865ce93bc6435c33ee4774037d4db6eb1af688
Signed-off-by: Michal Bloch <m.bloch@samsung.com>
Makefile.am
src/tests/qos_distributions.c [new file with mode: 0644]

index 4747440..ceffc67 100644 (file)
@@ -338,6 +338,7 @@ check_PROGRAMS = \
        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 \
@@ -486,6 +487,11 @@ src_tests_logprint_SOURCES = src/tests/logprint.c src/shared/ptrs_list.c src/sha
 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
diff --git a/src/tests/qos_distributions.c b/src/tests/qos_distributions.c
new file mode 100644 (file)
index 0000000..e8b68b5
--- /dev/null
@@ -0,0 +1,52 @@
+#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();
+}