Add unit tests for utils macros
authorMichael Jeanson <mjeanson@efficios.com>
Thu, 25 Mar 2021 15:01:17 +0000 (11:01 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Mon, 29 Mar 2021 18:01:55 +0000 (14:01 -0400)
Change-Id: I1908e7031f8b4493813f7a5fe6ac1ab90d062afc
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
.gitignore
configure.ac
tests/Makefile.am
tests/unit/Makefile.am
tests/unit/ust-utils/Makefile.am [new file with mode: 0644]
tests/unit/ust-utils/ust-utils-common.h [new file with mode: 0644]
tests/unit/ust-utils/ust-utils-cxx.cpp [new file with mode: 0644]
tests/unit/ust-utils/ust-utils.c [new file with mode: 0644]

index 00588540b95a388344722c5e6d3c983a58d781b5..8732df01a811a4f0508e6c72029c385022312fc5 100644 (file)
@@ -86,6 +86,8 @@ tests/unit/pthread_name/test_pthread_name
 tests/unit/snprintf/test_snprintf
 tests/unit/ust-elf/ust-elf
 tests/unit/ust-error/test_ust_error
+tests/unit/ust-utils/test_ust_utils
+tests/unit/ust-utils/test_ust_utils_cxx
 
 # Java agent library
 *.class
index 5e4f8671b61a65bdb4aaa5d5a22ed8ecd2170187..6bb13b8847cfad2c30fea116f17986523a2af177 100644 (file)
@@ -563,6 +563,7 @@ AC_CONFIG_FILES([
   tests/unit/snprintf/Makefile
   tests/unit/ust-elf/Makefile
   tests/unit/ust-error/Makefile
+  tests/unit/ust-utils/Makefile
   tests/utils/Makefile
   lttng-ust.pc
   lttng-ust-ctl.pc
index d3ba1f631fbdbb6b2144b8f40e506dcb3df5b0f5..b2c1c2b51e4cc96105a6b59c5b598640512caee6 100644 (file)
@@ -15,7 +15,13 @@ TESTS = \
        unit/pthread_name/test_pthread_name \
        unit/snprintf/test_snprintf \
        unit/ust-elf/test_ust_elf \
-       unit/ust-error/test_ust_error
+       unit/ust-error/test_ust_error \
+       unit/ust-utils/test_ust_utils
+
+if HAVE_CXX
+TESTS += \
+       unit/ust-utils/test_ust_utils_cxx
+endif
 
 EXTRA_DIST = README
 
index c8f52c3ca012b3221165688a43346164dffea907..47cec612ef2708d5823189b82e7d1749ed2b59f3 100644 (file)
@@ -7,4 +7,5 @@ SUBDIRS = \
        pthread_name \
        snprintf \
        ust-elf \
-       ust-error
+       ust-error \
+       ust-utils
diff --git a/tests/unit/ust-utils/Makefile.am b/tests/unit/ust-utils/Makefile.am
new file mode 100644 (file)
index 0000000..ec9ebe2
--- /dev/null
@@ -0,0 +1,15 @@
+# SPDX-License-Identifier: LGPL-2.1-only
+
+AM_CPPFLAGS += -I$(top_srcdir)/tests/utils
+
+noinst_PROGRAMS = test_ust_utils
+test_ust_utils_SOURCES = ust-utils.c ust-utils-common.h
+test_ust_utils_LDADD = $(top_builddir)/liblttng-ust/liblttng-ust.la \
+       $(top_builddir)/tests/utils/libtap.a
+
+if HAVE_CXX
+noinst_PROGRAMS += test_ust_utils_cxx
+test_ust_utils_cxx_SOURCES = ust-utils-cxx.cpp ust-utils-common.h
+test_ust_utils_cxx_LDADD = $(top_builddir)/liblttng-ust/liblttng-ust.la \
+       $(top_builddir)/tests/utils/libtap.a
+endif
diff --git a/tests/unit/ust-utils/ust-utils-common.h b/tests/unit/ust-utils/ust-utils-common.h
new file mode 100644 (file)
index 0000000..0792a10
--- /dev/null
@@ -0,0 +1,128 @@
+/*
+ * SPDX-License-Identifier: LGPL-2.1-or-later
+ *
+ * Copyright (C) 2021 Michael Jeanson <mjeanson@efficios.com>
+ */
+
+#include "tap.h"
+
+#define NUM_TESTS 60
+
+static
+void test_ust_stringify(void)
+{
+       ok(strcmp(lttng_ust_stringify(1), "1") == 0, "lttng_ust_stringify - literal integer");
+       ok(strcmp(lttng_ust_stringify(random_identifier), "random_identifier") == 0, "lttng_ust_stringify - identifier");
+}
+
+#define ok_is_signed(_type) \
+       ok(lttng_ust_is_signed_type(_type) == true, "lttng_ust_is_signed_type - '" lttng_ust_stringify(_type) "' is signed")
+
+#define ok_is_unsigned(_type) \
+       ok(lttng_ust_is_signed_type(_type) == false, "lttng_ust_is_signed_type - '" lttng_ust_stringify(_type) "' is unsigned")
+
+static
+void test_ust_is_signed(void)
+{
+       /*
+        * Signed types
+        */
+
+       ok_is_signed(signed char);
+       ok_is_signed(short);
+       ok_is_signed(int);
+       ok_is_signed(long);
+       ok_is_signed(long long);
+       ok_is_signed(float);
+       ok_is_signed(double);
+       ok_is_signed(long double);
+
+       ok_is_signed(int8_t);
+       ok_is_signed(int16_t);
+       ok_is_signed(int32_t);
+       ok_is_signed(int64_t);
+       ok_is_signed(intmax_t);
+
+       ok_is_signed(ssize_t);
+       ok_is_signed(ptrdiff_t);
+       ok_is_signed(intptr_t);
+
+       /*
+        * Unsigned types
+        */
+
+       ok_is_unsigned(unsigned char);
+       ok_is_unsigned(unsigned short);
+       ok_is_unsigned(unsigned int);
+       ok_is_unsigned(unsigned long);
+       ok_is_unsigned(unsigned long long);
+
+       ok_is_unsigned(uint8_t);
+       ok_is_unsigned(uint16_t);
+       ok_is_unsigned(uint32_t);
+       ok_is_unsigned(uint64_t);
+       ok_is_unsigned(uintmax_t);
+
+       ok_is_unsigned(bool);
+       ok_is_unsigned(size_t);
+
+       ok_is_unsigned(void *);
+}
+
+
+#define ok_is_integer_type(_type) \
+       ok(lttng_ust_is_integer_type(_type) == true, "lttng_ust_is_integer_type - '" lttng_ust_stringify(_type) "' is an integer")
+
+#define ok_is_not_integer_type(_type) \
+       ok(lttng_ust_is_integer_type(_type) == false, "lttng_ust_is_integer_type - '" lttng_ust_stringify(_type) "' is not an integer")
+
+static
+void test_ust_is_integer_type(void)
+{
+       ok_is_integer_type(char);
+       ok_is_integer_type(short);
+       ok_is_integer_type(int);
+       ok_is_integer_type(long);
+       ok_is_integer_type(long long);
+
+       ok_is_integer_type(signed char);
+       ok_is_integer_type(signed short);
+       ok_is_integer_type(signed int);
+       ok_is_integer_type(signed long);
+       ok_is_integer_type(signed long long);
+
+       ok_is_integer_type(unsigned char);
+       ok_is_integer_type(unsigned short);
+       ok_is_integer_type(unsigned int);
+       ok_is_integer_type(unsigned long);
+       ok_is_integer_type(unsigned long long);
+
+       ok_is_integer_type(int8_t);
+       ok_is_integer_type(int16_t);
+       ok_is_integer_type(int32_t);
+       ok_is_integer_type(int64_t);
+       ok_is_integer_type(intmax_t);
+
+       ok_is_integer_type(uint8_t);
+       ok_is_integer_type(uint16_t);
+       ok_is_integer_type(uint32_t);
+       ok_is_integer_type(uint64_t);
+       ok_is_integer_type(uintmax_t);
+
+       ok_is_not_integer_type(float);
+       ok_is_not_integer_type(double);
+       ok_is_not_integer_type(long double);
+
+       ok_is_not_integer_type(void *);
+}
+
+int main(void)
+{
+       plan_tests(NUM_TESTS);
+
+       test_ust_stringify();
+       test_ust_is_signed();
+       test_ust_is_integer_type();
+
+       return exit_status();
+}
diff --git a/tests/unit/ust-utils/ust-utils-cxx.cpp b/tests/unit/ust-utils/ust-utils-cxx.cpp
new file mode 100644 (file)
index 0000000..05ee302
--- /dev/null
@@ -0,0 +1,19 @@
+/*
+ * SPDX-License-Identifier: LGPL-2.1-or-later
+ *
+ * Copyright (C) 2021 Michael Jeanson <mjeanson@efficios.com>
+ */
+
+#include <stdbool.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <lttng/ust-utils.h>
+
+extern "C" {
+       /*
+        * Share test code with C test
+        */
+       #include "./ust-utils-common.h"
+}
diff --git a/tests/unit/ust-utils/ust-utils.c b/tests/unit/ust-utils/ust-utils.c
new file mode 100644 (file)
index 0000000..25fcfbe
--- /dev/null
@@ -0,0 +1,17 @@
+/*
+ * SPDX-License-Identifier: LGPL-2.1-or-later
+ *
+ * Copyright (C) 2021 Michael Jeanson <mjeanson@efficios.com>
+ */
+
+#include <stdbool.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <lttng/ust-utils.h>
+
+/*
+ * Share test code with CXX test
+ */
+#include "./ust-utils-common.h"
This page took 0.02934 seconds and 4 git commands to generate.