Add unit tests for num possible cpus
authorMichael Jeanson <mjeanson@efficios.com>
Mon, 25 Jul 2022 18:32:36 +0000 (14:32 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 26 Jul 2022 15:06:09 +0000 (11:06 -0400)
Change-Id: I90eff0090b28cef64a8f4a5bd9745971ed89c711
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
.gitignore
configure.ac
tests/Makefile.am
tests/libringbuffer/Makefile.am [new file with mode: 0644]
tests/libringbuffer/test_smp.c [new file with mode: 0644]

index 00361c4b5269ae2402a8ab2f97480232440a9779..22e0e76635131637ee83ea67d301a7196aa5f15a 100644 (file)
@@ -85,6 +85,7 @@ tests/benchmark/bench2
 tests/ctf-types/ctf-types
 tests/test-app-ctx/hello
 tests/gcc-weak-hidden/test_gcc_weak_hidden
+tests/libringbuffer/test_smp
 
 # Java agent library
 *.class
index 80a03798d8013c5a9e27abf2e482f6ad869ecfd0..ccb7117eb528550b4a4b5e2c3770a2018f976880 100644 (file)
@@ -587,6 +587,7 @@ AC_CONFIG_FILES([
        tests/utils/Makefile
        tests/test-app-ctx/Makefile
        tests/gcc-weak-hidden/Makefile
+       tests/libringbuffer/Makefile
        lttng-ust.pc
        lttng-ust-ctl.pc
 ])
index c8505eb5ff77da7aec5ee633125c575abd09ef14..91b4ceffdcbf9be865c199dddb03e422ef03d9c0 100644 (file)
@@ -1,5 +1,6 @@
 SUBDIRS = utils hello same_line_tracepoint snprintf benchmark ust-elf \
-               ctf-types test-app-ctx gcc-weak-hidden hello-many
+               ctf-types test-app-ctx gcc-weak-hidden hello-many \
+               libringbuffer
 
 if CXX_WORKS
 SUBDIRS += hello.cxx
@@ -11,7 +12,8 @@ LOG_DRIVER = env AM_TAP_AWK='$(AWK)' $(SHELL) \
 
 TESTS = snprintf/test_snprintf \
        ust-elf/test_ust_elf \
-       gcc-weak-hidden/test_gcc_weak_hidden
+       gcc-weak-hidden/test_gcc_weak_hidden \
+       libringbuffer/test_smp
 
 check-loop:
        while [ 0 ]; do \
diff --git a/tests/libringbuffer/Makefile.am b/tests/libringbuffer/Makefile.am
new file mode 100644 (file)
index 0000000..53a527d
--- /dev/null
@@ -0,0 +1,10 @@
+# SPDX-License-Identifier: LGPL-2.1-only
+
+AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/tests/utils
+
+noinst_PROGRAMS = test_smp
+test_smp_SOURCES = test_smp.c
+test_smp_LDADD = \
+       $(top_builddir)/libringbuffer/libringbuffer.la \
+       $(top_builddir)/snprintf/libustsnprintf.la \
+       $(top_builddir)/tests/utils/libtap.a
diff --git a/tests/libringbuffer/test_smp.c b/tests/libringbuffer/test_smp.c
new file mode 100644 (file)
index 0000000..59ce6af
--- /dev/null
@@ -0,0 +1,85 @@
+/*
+ * SPDX-License-Identifier: LGPL-2.1-only
+ *
+ * Copyright (C) 2020 Francis Deslauriers <francis.deslauriers@efficios.com>
+ */
+
+#define _GNU_SOURCE
+#include <assert.h>
+#include <limits.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "tap.h"
+
+#include "../../libringbuffer/smp.h"
+
+struct parse_test_data {
+       const char *buf;
+       int expected;
+};
+
+static struct parse_test_data parse_test_data[] = {
+       { "", 0 },
+       { "abc", 0 },
+       { ",,,", 0 },
+       { "--", 0 },
+       { ",", 0 },
+       { "-", 0 },
+       { "2147483647", 0 },
+       { "18446744073709551615", 0 },
+       { "0-2147483647", 0 },
+       { "0-18446744073709551615", 0 },
+       { "0", 1 },
+       { "1", 2 },
+       { "0-1", 2 },
+       { "1-3", 4 },
+       { "0,2", 3 },
+       { "1,2", 3 },
+       { "0,4-6,127", 128 },
+       { "0-4095", 4096 },
+
+       { "\n", 0 },
+       { "abc\n", 0 },
+       { ",,,\n", 0 },
+       { "--\n", 0 },
+       { ",\n", 0 },
+       { "-\n", 0 },
+       { "2147483647\n", 0 },
+       { "18446744073709551615\n", 0 },
+       { "0-2147483647\n", 0 },
+       { "0-18446744073709551615\n", 0 },
+       { "0\n", 1 },
+       { "1\n", 2 },
+       { "0-1\n", 2 },
+       { "1-3\n", 4 },
+       { "0,2\n", 3 },
+       { "1,2\n", 3 },
+       { "0,4-6,127\n", 128 },
+       { "0-4095\n", 4096 },
+};
+
+static int parse_test_data_len = sizeof(parse_test_data) / sizeof(parse_test_data[0]);
+
+int main(void)
+{
+       int ret, i;
+
+       plan_tests(parse_test_data_len + 1);
+
+       diag("Testing smp helpers");
+
+       for (i = 0; i < parse_test_data_len; i++) {
+               ret = get_num_possible_cpus_from_mask(parse_test_data[i].buf,
+                               strlen(parse_test_data[i].buf));
+               ok(ret == parse_test_data[i].expected,
+                       "get_num_possible_cpus_from_mask '%s', expected: '%d', result: '%d'",
+                       parse_test_data[i].buf, parse_test_data[i].expected, ret);
+       }
+
+       ok(num_possible_cpus() > 0, "num_possible_cpus (%d > 0)", num_possible_cpus());
+
+       return exit_status();
+}
This page took 0.027538 seconds and 4 git commands to generate.