Replace libuuid with internal implementation
authorMichael Jeanson <mjeanson@efficios.com>
Thu, 27 Jun 2019 21:41:53 +0000 (17:41 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 18 Jul 2019 15:53:34 +0000 (11:53 -0400)
We use a very small subset of libuuid features to transform UUIDs
between their string and binary representation. Plus we have a lot of
compat code for different platforms with some unspecified default
behavior regarding the use of upper/lower case.

Drop the dependency on libuuid and replace it with a minimal internal
implementation that respects RFC4122.

Change-Id: Ic170ce26ade23d177195cad117bd0fab590b328e
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1572
Tested-by: jenkins <jenkins@lttng.org>
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
49 files changed:
.gitignore
README
configure.ac
include/babeltrace2/ctf-writer/clock-class.h
include/babeltrace2/ctf-writer/clock.h
include/babeltrace2/ctf-writer/trace.h
src/babeltrace2-ctf-writer.pc.in
src/babeltrace2.pc.in
src/common/Makefile.am
src/common/uuid.c [new file with mode: 0644]
src/common/uuid.h [new file with mode: 0644]
src/compat/Makefile.am
src/compat/uuid.c [deleted file]
src/compat/uuid.h [deleted file]
src/ctf-writer/Makefile.am
src/ctf-writer/clock-class.c
src/ctf-writer/clock-class.h
src/ctf-writer/clock.c
src/ctf-writer/clock.h
src/ctf-writer/trace.c
src/ctf-writer/trace.h
src/ctf-writer/writer.c
src/lib/graph/iterator.c
src/lib/graph/message/iterator.h
src/lib/lib-logging.c
src/lib/trace-ir/Makefile.am
src/lib/trace-ir/clock-class.c
src/lib/trace-ir/clock-class.h
src/lib/trace-ir/clock-snapshot.c
src/lib/trace-ir/trace-class.h
src/lib/trace-ir/trace.c
src/lib/trace-ir/trace.h
src/plugins/ctf/common/metadata/Makefile.am
src/plugins/ctf/common/metadata/ctf-meta.h
src/plugins/ctf/common/metadata/decoder-packetized-file-stream-to-buf.c
src/plugins/ctf/common/metadata/decoder.c
src/plugins/ctf/common/metadata/visitor-generate-ir.c
src/plugins/ctf/fs-sink/fs-sink-ctf-meta.h
src/plugins/ctf/fs-sink/fs-sink-stream.c
src/plugins/ctf/fs-sink/translate-ctf-ir-to-tsdl.c
src/plugins/ctf/fs-src/fs.c
src/plugins/ctf/fs-src/metadata.c
src/plugins/text/details/write.c
src/plugins/text/pretty/print.c
src/plugins/utils/muxer/muxer.c
tests/Makefile.am
tests/ctf-writer/ctf_writer.c
tests/lib/Makefile.am
tests/lib/test_bt_uuid.c [new file with mode: 0644]

index a00cd4997b38cf2d876725923a02a321e83a2017..572ac7a995a61f342728154992e9550318e5a0d3 100644 (file)
@@ -1,6 +1,7 @@
 /tests/ctf-writer/ctf_writer
 /tests/lib/plugin
 /tests/lib/test_bitfield
+/tests/lib/test_bt_uuid
 /tests/lib/test_bt_values
 /tests/lib/test_graph_topo
 /tests/lib/test_trace_ir_ref
diff --git a/README b/README
index cfd9693bdad58b560c7ea6cd535dd30a1839aa93..5e0e76647f81758f936a3aa795b4f85774fc17b9 100644 (file)
--- a/README
+++ b/README
@@ -43,9 +43,6 @@ To compile Babeltrace, you will need:
        glib 2.22 or better development libraries
          (Debian : libglib2.0-0, libglib2.0-dev)
          (Fedora : glib2, glib2-devel)
-       uuid development libraries
-         (Debian : uuid-dev)
-         (Fedora : uuid-devel)
        libpopt >= 1.13 development libraries
          (Debian : libpopt-dev)
          (Fedora : popt)
index eb72e613c63360c5dab5aa0eceeb36ba91e29131..30fa06b0538f92a61934ea1b26ab518bdd2d87ff 100644 (file)
@@ -293,51 +293,6 @@ AC_CHECK_FUNCS([ \
 #AC_FUNC_MALLOC
 #AC_FUNC_REALLOC
 
-# First, check for uuid in system libs
-AH_TEMPLATE([BABELTRACE_HAVE_LIBUUID], [Define if you have libuuid support])
-AC_CHECK_FUNCS([uuid_generate],
-  [
-    AC_DEFINE([BABELTRACE_HAVE_LIBUUID], [1])
-    UUID_LIBS=""
-  ],
-  [
-    # Then, check if the pkg-config module is available, otherwise explicitly check
-    # for libuuid, or uuid support in the C-library.
-    PKG_CHECK_MODULES([UUID], [uuid],
-      [
-        AC_DEFINE([BABELTRACE_HAVE_LIBUUID], [1])
-        dnl PKG_CHECK_MODULES defines UUID_LIBS
-      ],
-      [
-        AC_MSG_WARN([pkg-config was unable to find a valid .pc for libuuid. Set PKG_CONFIG_PATH to specify the pkgconfig configuration file location])
-        AC_MSG_WARN([Finding libuuid without pkg-config.])
-        AC_CHECK_LIB([uuid], [uuid_generate],
-          [
-            AC_DEFINE([BABELTRACE_HAVE_LIBUUID], [1])
-            UUID_LIBS="-luuid"
-          ],
-          [
-            # libuuid not found, check for uuid_create in libc.
-            AC_CHECK_LIB([c], [uuid_create],
-              [
-                AC_DEFINE([BABELTRACE_HAVE_LIBUUID], [1])
-                UUID_LIBS="-lc"
-              ],
-              [
-                # for MinGW32 we have our own internal implementation of uuid using Windows functions.
-                AS_IF([test "x$MINGW32" = xno],
-                  [AC_MSG_FAILURE([Cannot find libuuid uuid_generate nor libc uuid_create. Either set PKG_CONFIG_PATH to the configuration file location or use LDFLAGS=-Ldir to specify the library location])]
-               )
-              ]
-            )
-          ]
-        )
-      ]
-    )
-  ]
-)
-AC_SUBST(UUID_LIBS)
-
 # Check for fmemopen
 AC_CHECK_LIB([c], [fmemopen],
   [AC_DEFINE_UNQUOTED([BABELTRACE_HAVE_FMEMOPEN], 1, [Has fmemopen support.])]
index ae074b82de31df1d4edd68f5f58f7759f5c7cc14..d8b7b4e7270255f409fdcaedf9c80e53f55b1db4 100644 (file)
@@ -84,11 +84,11 @@ extern bt_bool bt_ctf_clock_class_is_absolute(
 extern int bt_ctf_clock_class_set_is_absolute(
                 struct bt_ctf_clock_class *clock_class, bt_bool is_absolute);
 
-extern const unsigned char *bt_ctf_clock_class_get_uuid(
+extern const uint8_t *bt_ctf_clock_class_get_uuid(
                 struct bt_ctf_clock_class *clock_class);
 
 extern int bt_ctf_clock_class_set_uuid(struct bt_ctf_clock_class *clock_class,
-                const unsigned char *uuid);
+                const uint8_t *uuid);
 #ifdef __cplusplus
 }
 #endif
index 8cef6b6910e43c7b9f593769c9942e3b3f52692f..ccb1f26ba5e7dac24c27b3bd5177620f2bab6bfe 100644 (file)
@@ -224,7 +224,7 @@ extern int bt_ctf_clock_set_is_absolute(struct bt_ctf_clock *clock,
  * Returns a pointer to the clock's UUID (16 byte array) on success,
  * NULL on error.
  */
-extern const unsigned char *bt_ctf_clock_get_uuid(struct bt_ctf_clock *clock);
+extern const uint8_t *bt_ctf_clock_get_uuid(struct bt_ctf_clock *clock);
 
 /*
  * bt_ctf_clock_set_uuid: set a clock's UUID.
@@ -237,7 +237,7 @@ extern const unsigned char *bt_ctf_clock_get_uuid(struct bt_ctf_clock *clock);
  * Returns 0 on success, a negative value on error.
  */
 extern int bt_ctf_clock_set_uuid(struct bt_ctf_clock *clock,
-        const unsigned char *uuid);
+        const uint8_t *uuid);
 
 /*
  * bt_ctf_clock_set_time: set a clock's current time value.
index 27b18214958bfa39ea872b238aad65bb50777c81..d9d10f616bc00f37197e5138312631abe35e5eb3 100644 (file)
@@ -42,11 +42,11 @@ extern enum bt_ctf_byte_order bt_ctf_trace_get_native_byte_order(
 extern int bt_ctf_trace_set_native_byte_order(struct bt_ctf_trace *trace,
                enum bt_ctf_byte_order native_byte_order);
 
-extern const unsigned char *bt_ctf_trace_get_uuid(
+extern const uint8_t *bt_ctf_trace_get_uuid(
                struct bt_ctf_trace *trace);
 
 extern int bt_ctf_trace_set_uuid(struct bt_ctf_trace *trace,
-               const unsigned char *uuid);
+               const uint8_t *uuid);
 
 extern int bt_ctf_trace_set_environment_field_integer(
                struct bt_ctf_trace *trace, const char *name,
index 380ac930e0e10812a773980ec031f6fc1784a4e7..960f5b47ae239f70d9927ae940535845a79a0666 100644 (file)
@@ -7,6 +7,4 @@ Name: Babeltrace 2 CTF writer library
 Description: Common Trace Format (CTF) writer library from Babeltrace 2
 Version: @PACKAGE_VERSION@
 Libs: -L${libdir} -lbabeltrace2-ctf-writer
-Libs.private: @UUID_LIBS@
 Cflags: -I${includedir}
-Cflags.private: @UUID_CFLAGS@
index af831e00127c13b8cf9449af56d15c7cbae88827..8d812a5b0ad6672bc8da1aa2feeab992718ae477 100644 (file)
@@ -7,6 +7,4 @@ Name: Babeltrace 2 library
 Description: Babeltrace 2 library to support plugins and create trace processing graphs
 Version: @PACKAGE_VERSION@
 Libs: -L${libdir} -lbabeltrace2
-Libs.private: @UUID_LIBS@
 Cflags: -I${includedir}
-Cflags.private: @UUID_CFLAGS@
index b2a232e899b29b6c439a9f27bd4dcbd4adea91bd..02b8106a0f7b604b56074c3f06dfc6b07dcabee1 100644 (file)
@@ -3,10 +3,12 @@ AM_CPPFLAGS += -DINSTALL_LIBDIR=\"$(libdir)\"
 noinst_LTLIBRARIES = libbabeltrace2-common.la
 
 libbabeltrace2_common_la_SOURCES = \
-       assert.h \
        assert.c \
+       assert.h \
        common.c \
-       common.h
+       common.h \
+       uuid.c \
+       uuid.h
 
 noinst_HEADERS = \
        align.h \
diff --git a/src/common/uuid.c b/src/common/uuid.c
new file mode 100644 (file)
index 0000000..f6d895a
--- /dev/null
@@ -0,0 +1,123 @@
+/*
+ * Copyright (C) 2019 Michael Jeanson <mjeanson@efficios.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include <glib.h>
+#include <stdio.h>
+#include <string.h>
+#include <inttypes.h>
+
+#include "common/assert.h"
+#include "common/uuid.h"
+
+
+/*
+ * Generate a random UUID according to RFC4122, section 4.4.
+ */
+BT_HIDDEN
+void bt_uuid_generate(bt_uuid_t uuid_out)
+{
+       int i;
+       GRand *rand;
+
+       BT_ASSERT(uuid_out);
+
+       rand = g_rand_new();
+
+       /*
+        * Generate 16 bytes of random bits.
+        */
+       for (i = 0; i < BT_UUID_LEN; i++) {
+               uuid_out[i] = (uint8_t) g_rand_int(rand);
+       }
+
+       /*
+        * Set the two most significant bits (bits 6 and 7) of the
+        * clock_seq_hi_and_reserved to zero and one, respectively.
+        */
+       uuid_out[8] &= ~(1 << 6);
+       uuid_out[8] |= (1 << 7);
+
+       /*
+        * Set the four most significant bits (bits 12 through 15) of the
+        * time_hi_and_version field to the 4-bit version number from
+        * Section 4.1.3.
+        */
+       uuid_out[6] &= 0x0f;
+       uuid_out[6] |= (BT_UUID_VER << 4);
+
+       g_rand_free(rand);
+}
+
+BT_HIDDEN
+void bt_uuid_to_str(const bt_uuid_t uuid_in, char *str_out)
+{
+       BT_ASSERT(uuid_in);
+       BT_ASSERT(str_out);
+
+       sprintf(str_out, BT_UUID_FMT, BT_UUID_FMT_VALUES(uuid_in));
+}
+
+BT_HIDDEN
+int bt_uuid_from_str(const char *str_in, bt_uuid_t uuid_out)
+{
+       int ret = 0;
+       bt_uuid_t uuid_scan;
+
+       BT_ASSERT(uuid_out);
+       BT_ASSERT(str_in);
+
+       if (strnlen(str_in, BT_UUID_STR_LEN + 1) != BT_UUID_STR_LEN) {
+               ret = -1;
+               goto end;
+       }
+
+       /* Scan to a temporary location in case of a partial match. */
+       if (sscanf(str_in, BT_UUID_FMT, BT_UUID_SCAN_VALUES(uuid_scan)) != BT_UUID_LEN) {
+               ret = -1;
+       }
+
+       bt_uuid_copy(uuid_out, uuid_scan);
+end:
+       return ret;
+}
+
+BT_HIDDEN
+int bt_uuid_compare(const bt_uuid_t uuid_a, const bt_uuid_t uuid_b)
+{
+       int ret = 0;
+
+       if (memcmp(uuid_a, uuid_b, BT_UUID_LEN) != 0) {
+               ret = -1;
+       }
+
+       return ret;
+}
+
+BT_HIDDEN
+void bt_uuid_copy(bt_uuid_t uuid_dest, const bt_uuid_t uuid_src)
+{
+       BT_ASSERT(uuid_dest);
+       BT_ASSERT(uuid_src);
+       BT_ASSERT(uuid_dest != uuid_src);
+
+       memcpy(uuid_dest, uuid_src, BT_UUID_LEN);
+}
diff --git a/src/common/uuid.h b/src/common/uuid.h
new file mode 100644 (file)
index 0000000..3630351
--- /dev/null
@@ -0,0 +1,57 @@
+#ifndef _BABELTRACE_COMMON_UUID_H
+#define _BABELTRACE_COMMON_UUID_H
+
+/*
+ * Copyright (C) 2019 Michael Jeanson <mjeanson@efficios.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include <stdint.h>
+#include "common/macros.h"
+
+#define BT_UUID_STR_LEN 36 /* Excludes final \0 */
+#define BT_UUID_LEN 16
+#define BT_UUID_VER 4
+
+#define BT_UUID_FMT \
+       "%02" SCNx8 "%02" SCNx8 "%02" SCNx8 "%02" SCNx8 "-%02" SCNx8 \
+       "%02" SCNx8 "-%02" SCNx8 "%02" SCNx8 "-%02" SCNx8 "%02" SCNx8 \
+       "-%02" SCNx8 "%02" SCNx8 "%02" SCNx8 "%02" SCNx8 "%02" SCNx8 \
+       "%02" SCNx8
+
+#define BT_UUID_FMT_VALUES(uuid) \
+       (uuid)[0], (uuid)[1], (uuid)[2], (uuid)[3], (uuid)[4], (uuid)[5], \
+       (uuid)[6], (uuid)[7], (uuid)[8], (uuid)[9], (uuid)[10], (uuid)[11], \
+       (uuid)[12], (uuid)[13], (uuid)[14], (uuid)[15]
+
+#define BT_UUID_SCAN_VALUES(uuid) \
+       &(uuid)[0], &(uuid)[1], &(uuid)[2], &(uuid)[3], &(uuid)[4], &(uuid)[5], \
+       &(uuid)[6], &(uuid)[7], &(uuid)[8], &(uuid)[9], &(uuid)[10], &(uuid)[11], \
+       &(uuid)[12], &(uuid)[13], &(uuid)[14], &(uuid)[15]
+
+typedef uint8_t bt_uuid_t[BT_UUID_LEN];
+
+BT_HIDDEN void bt_uuid_generate(bt_uuid_t uuid_out);
+BT_HIDDEN void bt_uuid_to_str(const bt_uuid_t uuid_in, char *str_out);
+BT_HIDDEN int bt_uuid_from_str(const char *str_in, bt_uuid_t uuid_out);
+BT_HIDDEN int bt_uuid_compare(const bt_uuid_t uuid_a, const bt_uuid_t uuid_b);
+BT_HIDDEN void bt_uuid_copy(bt_uuid_t uuid_dest, const bt_uuid_t uuid_src);
+
+#endif /* _BABELTRACE_COMMON_UUID_H */
index 939b169b56f0093ca1be769413c32fa7dff3c7bd..0d87ccc0a5bb739bc2f6652190bb994a6247ac55 100644 (file)
@@ -2,17 +2,11 @@ noinst_LTLIBRARIES = libcompat.la
 
 libcompat_la_SOURCES = \
        mman.c \
-       mman.h \
-       uuid.c \
-       uuid.h
+       mman.h
 
 libcompat_la_LDFLAGS = \
        $(LD_NO_AS_NEEDED)
 
-if BABELTRACE_BUILD_WITH_MINGW
-libcompat_la_LDFLAGS += -lrpcrt4
-endif
-
 noinst_HEADERS = \
        bitfield.h \
        compiler.h \
diff --git a/src/compat/uuid.c b/src/compat/uuid.c
deleted file mode 100644 (file)
index 0cc5976..0000000
+++ /dev/null
@@ -1,119 +0,0 @@
-/*
- * compat/compat_uuid.h
- *
- * Copyright (C) 2013   Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-#ifdef __APPLE__
-#include "common/macros.h"
-
-/*
- * On macOS, we need a dummy symbol so that the linker won't
- * complain of an empty table of contents.
- */
-BT_HIDDEN
-int bt_uuid_dummy_symbol;
-#endif /* __APPLE__ */
-
-#ifdef __MINGW32__
-
-#include <rpc.h>
-#include <stdlib.h>
-#include "compat/uuid.h"
-
-/* MinGW does not provide byteswap - implement our own version. */
-static
-void swap(unsigned char *ptr, unsigned int i, unsigned int j)
-{
-       unsigned char tmp;
-
-       tmp = ptr[i];
-       ptr[i] = ptr[j];
-       ptr[j] = tmp;
-}
-
-static
-void fix_uuid_endian(unsigned char * ptr)
-{
-       swap(ptr, 0, 3);
-       swap(ptr, 1, 2);
-       swap(ptr, 4, 5);
-       swap(ptr, 6, 7);
-}
-
-int bt_uuid_generate(unsigned char *uuid_out)
-{
-       RPC_STATUS status;
-
-       status = UuidCreate((UUID *) uuid_out);
-       if (status == RPC_S_OK)
-               return 0;
-       else
-               return -1;
-}
-
-int bt_uuid_unparse(const unsigned char *uuid_in, char *str_out)
-{
-       RPC_STATUS status;
-       unsigned char *alloc_str;
-       int ret;
-       unsigned char copy_of_uuid_in[BABELTRACE_UUID_LEN];
-
-       /* make a modifyable copy of uuid_in */
-       memcpy(copy_of_uuid_in, uuid_in, BABELTRACE_UUID_LEN);
-
-       fix_uuid_endian(copy_of_uuid_in);
-       status = UuidToString((UUID *) copy_of_uuid_in, &alloc_str);
-
-       if (status == RPC_S_OK) {
-               strncpy(str_out, (char *) alloc_str, BABELTRACE_UUID_STR_LEN);
-               str_out[BABELTRACE_UUID_STR_LEN - 1] = '\0';
-               ret = 0;
-       } else {
-               ret = -1;
-       }
-       RpcStringFree(&alloc_str);
-       return ret;
-}
-
-int bt_uuid_parse(const char *str_in, unsigned char *uuid_out)
-{
-       RPC_STATUS status;
-
-       status = UuidFromString((unsigned char *) str_in,
-                       (UUID *) uuid_out);
-       fix_uuid_endian(uuid_out);
-
-       if (status == RPC_S_OK)
-               return 0;
-       else
-               return -1;
-}
-
-int bt_uuid_compare(const unsigned char *uuid_a,
-               const unsigned char *uuid_b)
-{
-       RPC_STATUS status;
-
-       return !UuidCompare((UUID *) uuid_a, (UUID *) uuid_b, &status) ? 0 : -1;
-}
-
-#endif
diff --git a/src/compat/uuid.h b/src/compat/uuid.h
deleted file mode 100644 (file)
index 2c2e929..0000000
+++ /dev/null
@@ -1,157 +0,0 @@
-#ifndef _BABELTRACE_COMPAT_UUID_H
-#define _BABELTRACE_COMPAT_UUID_H
-
-/*
- * Copyright (C) 2011   Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-/* Includes final \0. */
-#define BABELTRACE_UUID_STR_LEN                37
-#define BABELTRACE_UUID_LEN            16
-
-#ifdef BABELTRACE_HAVE_LIBUUID
-#include <uuid/uuid.h>
-
-static inline
-int bt_uuid_generate(unsigned char *uuid_out)
-{
-       uuid_generate(uuid_out);
-       return 0;
-}
-
-/* Sun's libuuid lacks const qualifiers */
-#if defined(__sun__)
-static inline
-int bt_uuid_unparse(const unsigned char *uuid_in, char *str_out)
-{
-       uuid_unparse((unsigned char *) uuid_in, str_out);
-       return 0;
-}
-
-static inline
-int bt_uuid_parse(const char *str_in, unsigned char *uuid_out)
-{
-       return uuid_parse((char *) str_in, uuid_out);
-}
-
-static inline
-int bt_uuid_compare(const unsigned char *uuid_a,
-               const unsigned char *uuid_b)
-{
-       return uuid_compare((unsigned char *) uuid_a,
-               (unsigned char *) uuid_b);
-}
-#else
-static inline
-int bt_uuid_unparse(const unsigned char *uuid_in, char *str_out)
-{
-       uuid_unparse(uuid_in, str_out);
-       return 0;
-}
-
-static inline
-int bt_uuid_parse(const char *str_in, unsigned char *uuid_out)
-{
-       return uuid_parse(str_in, uuid_out);
-}
-
-static inline
-int bt_uuid_compare(const unsigned char *uuid_a,
-               const unsigned char *uuid_b)
-{
-       return uuid_compare(uuid_a, uuid_b);
-}
-#endif
-
-#elif defined(BABELTRACE_HAVE_LIBC_UUID)
-#include <uuid.h>
-#include <stdint.h>
-#include <string.h>
-#include <stdlib.h>
-
-static inline
-int bt_uuid_generate(unsigned char *uuid_out)
-{
-       uint32_t status;
-
-       uuid_create((uuid_t *) uuid_out, &status);
-       if (status == uuid_s_ok)
-               return 0;
-       else
-               return -1;
-}
-
-static inline
-int bt_uuid_unparse(const unsigned char *uuid_in, char *str_out)
-{
-       uint32_t status;
-       char *alloc_str;
-       int ret;
-
-       uuid_to_string((uuid_t *) uuid_in, &alloc_str, &status);
-       if (status == uuid_s_ok) {
-               strcpy(str_out, alloc_str);
-               ret = 0;
-       } else {
-               ret = -1;
-       }
-       free(alloc_str);
-       return ret;
-}
-
-static inline
-int bt_uuid_parse(const char *str_in, unsigned char *uuid_out)
-{
-       uint32_t status;
-
-       uuid_from_string(str_in, (uuid_t *) uuid_out, &status);
-       if (status == uuid_s_ok)
-               return 0;
-       else
-               return -1;
-}
-
-static inline
-int bt_uuid_compare(const unsigned char *uuid_a,
-               const unsigned char *uuid_b)
-{
-       uint32_t status;
-
-       uuid_compare((uuid_t *) uuid_a, (uuid_t *) uuid_b, &status);
-       if (status == uuid_s_ok)
-               return 0;
-       else
-               return -1;
-}
-
-#elif defined(__MINGW32__)
-
-int bt_uuid_generate(unsigned char *uuid_out);
-int bt_uuid_unparse(const unsigned char *uuid_in, char *str_out);
-int bt_uuid_parse(const char *str_in, unsigned char *uuid_out);
-int bt_uuid_compare(const unsigned char *uuid_a,
-               const unsigned char *uuid_b);
-
-#else
-#error "Babeltrace needs to have a UUID generator configured."
-#endif
-
-#endif /* _BABELTRACE_COMPAT_UUID_H */
index be8d1e1ca7102f34a8b734da63fef3a1cc01451a..234d0c19fdf1fd118e62681b661df23958ddd972 100644 (file)
@@ -54,5 +54,4 @@ libbabeltrace2_ctf_writer_la_LIBADD = \
        $(top_builddir)/src/logging/libbabeltrace2-logging.la \
        $(top_builddir)/src/common/libbabeltrace2-common.la \
        $(top_builddir)/src/ctfser/libbabeltrace2-ctfser.la \
-       $(top_builddir)/src/compat/libcompat.la \
-       $(UUID_LIBS)
+       $(top_builddir)/src/compat/libcompat.la
index c4332c536957920021e61a8392c2dc60fe9d10cd..d186f89a67d4ab95a7660c2742cb17d4e242ff94 100644 (file)
@@ -29,7 +29,7 @@
 #define BT_LOG_TAG "CTF-WRITER/CLOCK-CLASS"
 #include "logging.h"
 
-#include "compat/uuid.h"
+#include "common/uuid.h"
 #include <babeltrace2/ctf-writer/utils.h>
 #include <babeltrace2/ctf-writer/object.h>
 #include "compat/compiler.h"
@@ -454,10 +454,10 @@ end:
 }
 
 BT_HIDDEN
-const unsigned char *bt_ctf_clock_class_get_uuid(
+const uint8_t *bt_ctf_clock_class_get_uuid(
                struct bt_ctf_clock_class *clock_class)
 {
-       const unsigned char *ret;
+       const uint8_t *ret;
 
        if (!clock_class) {
                BT_LOGW_STR("Invalid parameter: clock class is NULL.");
@@ -479,7 +479,7 @@ end:
 
 BT_HIDDEN
 int bt_ctf_clock_class_set_uuid(struct bt_ctf_clock_class *clock_class,
-               const unsigned char *uuid)
+               const uint8_t *uuid)
 {
        int ret = 0;
 
@@ -499,27 +499,11 @@ int bt_ctf_clock_class_set_uuid(struct bt_ctf_clock_class *clock_class,
                goto end;
        }
 
-       memcpy(clock_class->uuid, uuid, BABELTRACE_UUID_LEN);
+       bt_uuid_copy(clock_class->uuid, uuid);
        clock_class->uuid_set = 1;
-       BT_LOGT("Set clock class's UUID: addr=%p, name=\"%s\", "
-               "uuid=\"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\"",
+       BT_LOGT("Set clock class's UUID: addr=%p, name=\"%s\", uuid=\"" BT_UUID_FMT "\"",
                clock_class, bt_ctf_clock_class_get_name(clock_class),
-               (unsigned int) uuid[0],
-               (unsigned int) uuid[1],
-               (unsigned int) uuid[2],
-               (unsigned int) uuid[3],
-               (unsigned int) uuid[4],
-               (unsigned int) uuid[5],
-               (unsigned int) uuid[6],
-               (unsigned int) uuid[7],
-               (unsigned int) uuid[8],
-               (unsigned int) uuid[9],
-               (unsigned int) uuid[10],
-               (unsigned int) uuid[11],
-               (unsigned int) uuid[12],
-               (unsigned int) uuid[13],
-               (unsigned int) uuid[14],
-               (unsigned int) uuid[15]);
+               BT_UUID_FMT_VALUES(uuid));
 end:
        return ret;
 }
@@ -641,43 +625,12 @@ int bt_ctf_clock_class_compare(struct bt_ctf_clock_class *clock_class_a,
                        goto end;
                }
 
-               if (memcmp(clock_class_a->uuid, clock_class_b->uuid,
-                               BABELTRACE_UUID_LEN) != 0) {
+               if (bt_uuid_compare(clock_class_a->uuid, clock_class_b->uuid) != 0) {
                        BT_LOGT("Clock classes differ: different UUIDs: "
-                               "cc-a-uuid=\"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\", "
-                               "cc-b-uuid=\"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\"",
-                               (unsigned int) clock_class_a->uuid[0],
-                               (unsigned int) clock_class_a->uuid[1],
-                               (unsigned int) clock_class_a->uuid[2],
-                               (unsigned int) clock_class_a->uuid[3],
-                               (unsigned int) clock_class_a->uuid[4],
-                               (unsigned int) clock_class_a->uuid[5],
-                               (unsigned int) clock_class_a->uuid[6],
-                               (unsigned int) clock_class_a->uuid[7],
-                               (unsigned int) clock_class_a->uuid[8],
-                               (unsigned int) clock_class_a->uuid[9],
-                               (unsigned int) clock_class_a->uuid[10],
-                               (unsigned int) clock_class_a->uuid[11],
-                               (unsigned int) clock_class_a->uuid[12],
-                               (unsigned int) clock_class_a->uuid[13],
-                               (unsigned int) clock_class_a->uuid[14],
-                               (unsigned int) clock_class_a->uuid[15],
-                               (unsigned int) clock_class_b->uuid[0],
-                               (unsigned int) clock_class_b->uuid[1],
-                               (unsigned int) clock_class_b->uuid[2],
-                               (unsigned int) clock_class_b->uuid[3],
-                               (unsigned int) clock_class_b->uuid[4],
-                               (unsigned int) clock_class_b->uuid[5],
-                               (unsigned int) clock_class_b->uuid[6],
-                               (unsigned int) clock_class_b->uuid[7],
-                               (unsigned int) clock_class_b->uuid[8],
-                               (unsigned int) clock_class_b->uuid[9],
-                               (unsigned int) clock_class_b->uuid[10],
-                               (unsigned int) clock_class_b->uuid[11],
-                               (unsigned int) clock_class_b->uuid[12],
-                               (unsigned int) clock_class_b->uuid[13],
-                               (unsigned int) clock_class_b->uuid[14],
-                               (unsigned int) clock_class_b->uuid[15]);
+                               "cc-a-uuid=\"" BT_UUID_FMT "\", "
+                               "cc-b-uuid=\"" BT_UUID_FMT "\"",
+                               BT_UUID_FMT_VALUES(clock_class_a->uuid),
+                               BT_UUID_FMT_VALUES(clock_class_b->uuid));
                        goto end;
                }
        } else {
index dfe95cc71ef8b87cec08774210b08cbb5fb0d98a..ec78f66bddc359569950bafe6f879177b92f82b1 100644 (file)
@@ -27,7 +27,7 @@
 
 #include "common/macros.h"
 #include "object-pool.h"
-#include "compat/uuid.h"
+#include "common/uuid.h"
 #include <babeltrace2/types.h>
 #include <stdbool.h>
 #include <stdint.h>
@@ -43,7 +43,7 @@ struct bt_ctf_clock_class {
        uint64_t precision;
        int64_t offset_s;       /* Offset in seconds */
        int64_t offset;         /* Offset in ticks */
-       unsigned char uuid[BABELTRACE_UUID_LEN];
+       bt_uuid_t uuid;
        int uuid_set;
        int absolute;
 
@@ -111,10 +111,10 @@ BT_HIDDEN
 int bt_ctf_clock_class_set_is_absolute(
                struct bt_ctf_clock_class *clock_class, bt_bool is_absolute);
 BT_HIDDEN
-const unsigned char *bt_ctf_clock_class_get_uuid(
+const uint8_t *bt_ctf_clock_class_get_uuid(
                struct bt_ctf_clock_class *clock_class);
 BT_HIDDEN
 int bt_ctf_clock_class_set_uuid(struct bt_ctf_clock_class *clock_class,
-               const unsigned char *uuid);
+               const uint8_t *uuid);
 
 #endif /* BABELTRACE_CTF_WRITER_CLOCK_CLASS_INTERNAL_H */
index 58d86d1ce1cf7ca3fa4d0192e58210f498daca02..e1c00dacce50d3a035ab285caeea321c9831ea17 100644 (file)
@@ -31,7 +31,7 @@
 #include "logging.h"
 
 #include "common/assert.h"
-#include "compat/uuid.h"
+#include "common/uuid.h"
 #include "compat/compiler.h"
 #include <babeltrace2/ctf-writer/utils.h>
 #include <babeltrace2/ctf-writer/object.h>
@@ -49,7 +49,7 @@ struct bt_ctf_clock *bt_ctf_clock_create(const char *name)
 {
        int ret;
        struct bt_ctf_clock *clock = NULL;
-       unsigned char cc_uuid[BABELTRACE_UUID_LEN];
+       bt_uuid_t cc_uuid;
 
        BT_CTF_ASSERT_PRE_NON_NULL(name, "Name");
        clock = g_new0(struct bt_ctf_clock, 1);
@@ -67,10 +67,7 @@ struct bt_ctf_clock *bt_ctf_clock_create(const char *name)
        }
 
        /* Automatically set clock class's UUID. */
-       ret = bt_uuid_generate(cc_uuid);
-       if (ret) {
-               goto error;
-       }
+       bt_uuid_generate(cc_uuid);
 
        ret = bt_ctf_clock_class_set_uuid(clock->clock_class, cc_uuid);
        BT_ASSERT(ret == 0);
@@ -167,13 +164,13 @@ int bt_ctf_clock_set_is_absolute(struct bt_ctf_clock *clock, int is_absolute)
                is_absolute);
 }
 
-const unsigned char *bt_ctf_clock_get_uuid(struct bt_ctf_clock *clock)
+const uint8_t *bt_ctf_clock_get_uuid(struct bt_ctf_clock *clock)
 {
        BT_CTF_ASSERT_PRE_NON_NULL(clock, "CTF writer clock");
        return bt_ctf_clock_class_get_uuid(clock->clock_class);
 }
 
-int bt_ctf_clock_set_uuid(struct bt_ctf_clock *clock, const unsigned char *uuid)
+int bt_ctf_clock_set_uuid(struct bt_ctf_clock *clock, const uint8_t *uuid)
 {
        BT_CTF_ASSERT_PRE_NON_NULL(clock, "CTF writer clock");
        return bt_ctf_clock_class_set_uuid(clock->clock_class, uuid);
@@ -226,7 +223,7 @@ BT_HIDDEN
 void bt_ctf_clock_class_serialize(struct bt_ctf_clock_class *clock_class,
                struct metadata_context *context)
 {
-       unsigned char *uuid;
+       uint8_t *uuid;
 
        BT_LOGD("Serializing clock class's metadata: clock-class-addr=%p, "
                "name=\"%s\", metadata-context-addr=%p", clock_class,
@@ -249,11 +246,8 @@ void bt_ctf_clock_class_serialize(struct bt_ctf_clock_class *clock_class,
 
        if (clock_class->uuid_set) {
                g_string_append_printf(context->string,
-                       "\tuuid = \"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\";\n",
-                       uuid[0], uuid[1], uuid[2], uuid[3],
-                       uuid[4], uuid[5], uuid[6], uuid[7],
-                       uuid[8], uuid[9], uuid[10], uuid[11],
-                       uuid[12], uuid[13], uuid[14], uuid[15]);
+                       "\tuuid = \"" BT_UUID_FMT "\";\n",
+                       BT_UUID_FMT_VALUES(uuid));
        }
 
        if (clock_class->description) {
index d38d8ea591a0e5fa50a084fa13f6458b2b3392a2..01cddc47eea52a26e5b700ee01afde431bcc3f2b 100644 (file)
@@ -26,7 +26,6 @@
 #include <babeltrace2/ctf-writer/clock.h>
 #include "common/macros.h"
 #include <glib.h>
-#include "compat/uuid.h"
 
 #include "clock-class.h"
 #include "object.h"
index 82eb35b3501c4de01c4a3f93e98e1640a1877b7f..f7ef692d13abf66be23ae43456253ec56dec6573 100644 (file)
@@ -180,7 +180,7 @@ end:
 
 BT_HIDDEN
 int bt_ctf_trace_common_set_uuid(struct bt_ctf_trace_common *trace,
-               const unsigned char *uuid)
+               const uint8_t *uuid)
 {
        int ret = 0;
 
@@ -204,27 +204,12 @@ int bt_ctf_trace_common_set_uuid(struct bt_ctf_trace_common *trace,
                goto end;
        }
 
-       memcpy(trace->uuid, uuid, BABELTRACE_UUID_LEN);
+       bt_uuid_copy(trace->uuid, uuid);
        trace->uuid_set = BT_TRUE;
        BT_LOGT("Set trace's UUID: addr=%p, name=\"%s\", "
-               "uuid=\"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\"",
+               "uuid=\"" BT_UUID_FMT "\"",
                trace, bt_ctf_trace_common_get_name(trace),
-               (unsigned int) uuid[0],
-               (unsigned int) uuid[1],
-               (unsigned int) uuid[2],
-               (unsigned int) uuid[3],
-               (unsigned int) uuid[4],
-               (unsigned int) uuid[5],
-               (unsigned int) uuid[6],
-               (unsigned int) uuid[7],
-               (unsigned int) uuid[8],
-               (unsigned int) uuid[9],
-               (unsigned int) uuid[10],
-               (unsigned int) uuid[11],
-               (unsigned int) uuid[12],
-               (unsigned int) uuid[13],
-               (unsigned int) uuid[14],
-               (unsigned int) uuid[15]);
+               BT_UUID_FMT_VALUES(uuid));
 
 end:
        return ret;
@@ -1461,13 +1446,13 @@ error:
        return trace;
 }
 
-const unsigned char *bt_ctf_trace_get_uuid(struct bt_ctf_trace *trace)
+const uint8_t *bt_ctf_trace_get_uuid(struct bt_ctf_trace *trace)
 {
        return bt_ctf_trace_common_get_uuid(BT_CTF_TO_COMMON(trace));
 }
 
 int bt_ctf_trace_set_uuid(struct bt_ctf_trace *trace,
-               const unsigned char *uuid)
+               const uint8_t *uuid)
 {
        return bt_ctf_trace_common_set_uuid(BT_CTF_TO_COMMON(trace), uuid);
 }
@@ -1684,7 +1669,7 @@ static
 int append_trace_metadata(struct bt_ctf_trace *trace,
                struct metadata_context *context)
 {
-       unsigned char *uuid = trace->common.uuid;
+       uint8_t *uuid = trace->common.uuid;
        int ret = 0;
 
        if (trace->common.native_byte_order == BT_CTF_BYTE_ORDER_NATIVE ||
@@ -1706,11 +1691,8 @@ int append_trace_metadata(struct bt_ctf_trace *trace,
 
        if (trace->common.uuid_set) {
                g_string_append_printf(context->string,
-                       "\tuuid = \"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\";\n",
-                       uuid[0], uuid[1], uuid[2], uuid[3],
-                       uuid[4], uuid[5], uuid[6], uuid[7],
-                       uuid[8], uuid[9], uuid[10], uuid[11],
-                       uuid[12], uuid[13], uuid[14], uuid[15]);
+                       "\tuuid = \"" BT_UUID_FMT "\";\n",
+                       BT_UUID_FMT_VALUES(uuid));
        }
 
        g_string_append_printf(context->string, "\tbyte_order = %s;\n",
index ca6328fba7973be40a36a352212b4809545d53f7..231e97b0a26ce027908ad2f446129bbabc866802 100644 (file)
@@ -29,7 +29,7 @@
  */
 
 #include "common/macros.h"
-#include "compat/uuid.h"
+#include "common/uuid.h"
 #include <babeltrace2/ctf-writer/field-types.h>
 #include <babeltrace2/ctf-writer/fields.h>
 #include <babeltrace2/ctf-writer/trace.h>
@@ -49,7 +49,7 @@ struct bt_ctf_trace_common {
        struct bt_ctf_object base;
        GString *name;
        int frozen;
-       unsigned char uuid[BABELTRACE_UUID_LEN];
+       bt_uuid_t uuid;
        bt_bool uuid_set;
        enum bt_ctf_byte_order native_byte_order;
        struct bt_ctf_private_value *environment;
@@ -88,14 +88,14 @@ BT_HIDDEN
 int bt_ctf_trace_common_set_name(struct bt_ctf_trace_common *trace, const char *name);
 
 static inline
-const unsigned char *bt_ctf_trace_common_get_uuid(struct bt_ctf_trace_common *trace)
+const uint8_t *bt_ctf_trace_common_get_uuid(struct bt_ctf_trace_common *trace)
 {
        BT_CTF_ASSERT_PRE_NON_NULL(trace, "Trace");
        return trace->uuid_set ? trace->uuid : NULL;
 }
 
 BT_HIDDEN
-int bt_ctf_trace_common_set_uuid(struct bt_ctf_trace_common *trace, const unsigned char *uuid);
+int bt_ctf_trace_common_set_uuid(struct bt_ctf_trace_common *trace, const uint8_t *uuid);
 
 BT_HIDDEN
 int bt_ctf_trace_common_set_environment_field(struct bt_ctf_trace_common *trace,
index 6c72acaf5f808928326e4468d1dbebaf3376878c..650d68f30d6879a50016c517b9ca092e64aad604 100644 (file)
@@ -42,7 +42,7 @@
 #include "common/assert.h"
 #include "compat/compiler.h"
 #include "compat/endian.h"
-#include "compat/uuid.h"
+#include "common/uuid.h"
 
 #include "clock.h"
 #include "fields.h"
@@ -109,7 +109,7 @@ struct bt_ctf_writer *bt_ctf_writer_create(const char *path)
 {
        int ret;
        struct bt_ctf_writer *writer = NULL;
-       unsigned char uuid[16];
+       bt_uuid_t uuid;
        char *metadata_path = NULL;
 
        if (!path) {
@@ -140,11 +140,7 @@ struct bt_ctf_writer *bt_ctf_writer_create(const char *path)
        }
 
        /* Generate a UUID for this writer's trace */
-       ret = bt_uuid_generate(uuid);
-       if (ret) {
-               BT_LOGE_STR("Cannot generate UUID for CTF writer's trace.");
-               goto error_destroy;
-       }
+       bt_uuid_generate(uuid);
 
        ret = bt_ctf_trace_set_uuid(writer->trace, uuid);
        if (ret) {
index 048daaf1c3834f4d52847848c85320159406cb6a..41805663d40dfa1d8a0b85c4d3125ab42c5a25e8 100644 (file)
@@ -681,7 +681,7 @@ bool clock_classes_are_compatible_one(struct bt_self_component_port_input_messag
                                iterator->clock_expectation.type = CLOCK_EXPECTATION_ORIGIN_UNIX;
                        } else if (clock_class_uuid) {
                                iterator->clock_expectation.type = CLOCK_EXPECTATION_ORIGIN_OTHER_UUID;
-                               memcpy(iterator->clock_expectation.uuid, clock_class_uuid, BABELTRACE_UUID_LEN);
+                               bt_uuid_copy(iterator->clock_expectation.uuid, clock_class_uuid);
                        } else {
                                iterator->clock_expectation.type = CLOCK_EXPECTATION_ORIGIN_OTHER_NO_UUID;
                        }
index d28a88102ac0be6dc53cdb44aae8c8dc88baa7d6..b8a9dfa2f65e090cb0cd7840360d66e4ba261ffe 100644 (file)
@@ -31,7 +31,7 @@
 #include <babeltrace2/types.h>
 #include "common/assert.h"
 #include <stdbool.h>
-#include <compat/uuid.h>
+#include "common/uuid.h"
 
 struct bt_port;
 struct bt_graph;
@@ -144,7 +144,7 @@ struct bt_self_component_port_input_message_iterator {
                 * irrelevant (as the clock will be correlatable with other
                 * clocks having the same origin).
                 */
-               uint8_t uuid[BABELTRACE_UUID_LEN];
+               bt_uuid_t uuid;
        } clock_expectation;
 
        /*
index dcfee70ff92dcf0daa3af70076e2524281afb73a..b48c5db7b4274de39f04905cbad53bf2e9452aa1 100644 (file)
@@ -32,6 +32,7 @@
 #include <wchar.h>
 #include <glib.h>
 #include "common/common.h"
+#include "common/uuid.h"
 #include <babeltrace2/trace-ir/event-const.h>
 #include <babeltrace2/trace-ir/packet-const.h>
 #include <babeltrace2/trace-ir/stream-const.h>
@@ -134,23 +135,7 @@ static inline void format_object(char **buf_ch, bool extended,
 
 static inline void format_uuid(char **buf_ch, bt_uuid uuid)
 {
-       BUF_APPEND("\"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\"",
-               (unsigned int) uuid[0],
-               (unsigned int) uuid[1],
-               (unsigned int) uuid[2],
-               (unsigned int) uuid[3],
-               (unsigned int) uuid[4],
-               (unsigned int) uuid[5],
-               (unsigned int) uuid[6],
-               (unsigned int) uuid[7],
-               (unsigned int) uuid[8],
-               (unsigned int) uuid[9],
-               (unsigned int) uuid[10],
-               (unsigned int) uuid[11],
-               (unsigned int) uuid[12],
-               (unsigned int) uuid[13],
-               (unsigned int) uuid[14],
-               (unsigned int) uuid[15]);
+       BUF_APPEND("\"" BT_UUID_FMT "\"", BT_UUID_FMT_VALUES(uuid));
 }
 
 static inline void format_object_pool(char **buf_ch, bool extended,
index 159f4b4a8973d09e261534c03f7798cc514286c2..11e1e542e93becee3dad24fe811b04ed1aaeecf5 100644 (file)
@@ -35,5 +35,3 @@ libtrace_ir_la_SOURCES = \
        trace.h \
        utils.c \
        utils.h
-
-libtrace_ir_la_LIBADD = $(UUID_LIBS)
index 43341d0f963561a77970c3724cf0169b95186b09..119b4db929e887a3877c5b54f0489b0b6d32311f 100644 (file)
@@ -25,7 +25,7 @@
 #include "lib/logging.h"
 
 #include "lib/assert-pre.h"
-#include "compat/uuid.h"
+#include "common/uuid.h"
 #include <babeltrace2/trace-ir/clock-class-const.h>
 #include <babeltrace2/trace-ir/clock-class.h>
 #include "clock-class.h"
@@ -262,7 +262,7 @@ void bt_clock_class_set_uuid(struct bt_clock_class *clock_class,
        BT_ASSERT_PRE_NON_NULL(clock_class, "Clock class");
        BT_ASSERT_PRE_NON_NULL(uuid, "UUID");
        BT_ASSERT_PRE_CLOCK_CLASS_HOT(clock_class);
-       memcpy(clock_class->uuid.uuid, uuid, BABELTRACE_UUID_LEN);
+       bt_uuid_copy(clock_class->uuid.uuid, uuid);
        clock_class->uuid.value = clock_class->uuid.uuid;
        BT_LIB_LOGD("Set clock class's UUID: %!+K", clock_class);
 }
index 153456ddb018b800061f7109f3e42bdbd12fc1dd..f3daa67c431cdced1e4a07658fe18f59aceda0e5 100644 (file)
@@ -29,7 +29,7 @@
 #include "common/macros.h"
 #include "common/common.h"
 #include "lib/object-pool.h"
-#include "compat/uuid.h"
+#include "common/uuid.h"
 #include <babeltrace2/types.h>
 #include "lib/property.h"
 #include "common/assert.h"
@@ -62,7 +62,7 @@ struct bt_clock_class {
        uint64_t offset_cycles;
 
        struct {
-               uint8_t uuid[BABELTRACE_UUID_LEN];
+               bt_uuid_t uuid;
 
                /* NULL or `uuid` above */
                bt_uuid value;
index 53f6be654478454fb051468c4e5cbfd75b33278d..307198d2a27c8813098f0feefc204707955469c5 100644 (file)
@@ -24,7 +24,7 @@
 #include "lib/logging.h"
 
 #include "lib/assert-pre.h"
-#include "compat/uuid.h"
+#include "common/uuid.h"
 #include "clock-class.h"
 #include "clock-snapshot.h"
 #include <babeltrace2/trace-ir/clock-snapshot-const.h>
index 589da127a315b5747e963f599e9fd6f3c54eb1c4..0b06bf32fda0a8fa27fa3e645922591e50053c89 100644 (file)
@@ -35,7 +35,6 @@
 #include <babeltrace2/types.h>
 #include <glib.h>
 #include <sys/types.h>
-#include "compat/uuid.h"
 
 #include "stream-class.h"
 #include "attributes.h"
index ce76ce5e92d70d8e3c2e47384d923f1851b7a296..8b6650dbe11c5339e36e7e4c5ee9c957515b1c16 100644 (file)
@@ -227,7 +227,7 @@ void bt_trace_set_uuid(struct bt_trace *trace, bt_uuid uuid)
        BT_ASSERT_PRE_NON_NULL(trace, "Trace");
        BT_ASSERT_PRE_NON_NULL(uuid, "UUID");
        BT_ASSERT_PRE_TRACE_HOT(trace);
-       memcpy(trace->uuid.uuid, uuid, BABELTRACE_UUID_LEN);
+       bt_uuid_copy(trace->uuid.uuid, uuid);
        trace->uuid.value = trace->uuid.uuid;
        BT_LIB_LOGD("Set trace's UUID: %!+t", trace);
 }
index c5c244b58dcf29be9dbaf1a23a63e8c2ace57c46..288bfa36cdca207d6ab3683d81fdbeeabeee0062 100644 (file)
@@ -35,7 +35,7 @@
 #include <babeltrace2/types.h>
 #include <glib.h>
 #include <sys/types.h>
-#include "compat/uuid.h"
+#include "common/uuid.h"
 
 #include "attributes.h"
 #include "clock-class.h"
@@ -56,7 +56,7 @@ struct bt_trace {
        } name;
 
        struct {
-               uint8_t uuid[BABELTRACE_UUID_LEN];
+               bt_uuid_t uuid;
 
                /* NULL or `uuid` above */
                bt_uuid value;
index 2e1d4d0335b647e516f93ff5dfb7e4237f263a1e..8cdf35e526c834f53fe78ff2dce8a4ea348b3332 100644 (file)
@@ -41,10 +41,8 @@ libctf_ast_la_SOURCES = \
        ctf-meta-configure-ir-trace.c \
        ctf-meta-configure-ir-trace.h
 
-libctf_ast_la_LIBADD = $(UUID_LIBS)
-
 if BABELTRACE_BUILD_WITH_MINGW
-libctf_ast_la_LIBADD += -lrpcrt4 -lintl -liconv -lole32 $(POPT_LIBS)
+libctf_ast_la_LIBADD = -lintl -liconv -lole32 $(POPT_LIBS)
 endif
 
 # start with empty files to clean
index 29c5e178797d738c5da4752f74e90cca98565c31..e62b40ada6b2c07ed990606c65552fe91e2fecc8 100644 (file)
@@ -17,6 +17,7 @@
 
 #include <babeltrace2/babeltrace.h>
 #include "common/common.h"
+#include "common/uuid.h"
 #include "common/assert.h"
 #include <glib.h>
 #include <stdint.h>
@@ -75,7 +76,7 @@ struct ctf_clock_class {
        uint64_t precision;
        int64_t offset_seconds;
        uint64_t offset_cycles;
-       uint8_t uuid[16];
+       bt_uuid_t uuid;
        bool has_uuid;
        bool is_absolute;
 
@@ -278,7 +279,7 @@ struct ctf_trace_class_env_entry {
 struct ctf_trace_class {
        unsigned int major;
        unsigned int minor;
-       uint8_t uuid[16];
+       bt_uuid_t uuid;
        bool is_uuid_set;
        enum ctf_byte_order default_byte_order;
 
index 29986fabd8789f17f331288c5ccd3e3a961f2b74..e14c54d7907d542d3031795ea97e4633aba0a8ed 100644 (file)
@@ -23,7 +23,7 @@
 #include <stdlib.h>
 #include <inttypes.h>
 #include "common/assert.h"
-#include "compat/uuid.h"
+#include "common/uuid.h"
 #include "compat/memstream.h"
 #include <babeltrace2/babeltrace.h>
 #include <glib.h>
@@ -41,7 +41,7 @@ int yydebug;
 
 struct ctf_metadata_decoder {
        struct ctf_visitor_generate_ir *visitor;
-       uint8_t uuid[16];
+       bt_uuid_t uuid;
        bool is_uuid_set;
        int bo;
        struct ctf_metadata_decoder_config config;
@@ -49,7 +49,7 @@ struct ctf_metadata_decoder {
 
 struct packet_header {
        uint32_t magic;
-       uint8_t  uuid[16];
+       bt_uuid_t  uuid;
        uint32_t checksum;
        uint32_t content_size;
        uint32_t packet_size;
@@ -127,45 +127,15 @@ int decode_packet(FILE *in_fp, FILE *out_fp,
        /* Set expected trace UUID if not set; otherwise validate it */
        if (is_uuid_set) {
                if (!*is_uuid_set) {
-                       memcpy(uuid, header.uuid, sizeof(header.uuid));
+                       bt_uuid_copy(uuid, header.uuid);
                        *is_uuid_set = true;
                } else if (bt_uuid_compare(header.uuid, uuid)) {
                        BT_COMP_LOGE("Metadata UUID mismatch between packets of the same stream: "
-                               "packet-uuid=\"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\", "
-                               "expected-uuid=\"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\", "
+                               "packet-uuid=\"" BT_UUID_FMT "\", "
+                               "expected-uuid=\"" BT_UUID_FMT "\", "
                                "offset=%ld",
-                               (unsigned int) header.uuid[0],
-                               (unsigned int) header.uuid[1],
-                               (unsigned int) header.uuid[2],
-                               (unsigned int) header.uuid[3],
-                               (unsigned int) header.uuid[4],
-                               (unsigned int) header.uuid[5],
-                               (unsigned int) header.uuid[6],
-                               (unsigned int) header.uuid[7],
-                               (unsigned int) header.uuid[8],
-                               (unsigned int) header.uuid[9],
-                               (unsigned int) header.uuid[10],
-                               (unsigned int) header.uuid[11],
-                               (unsigned int) header.uuid[12],
-                               (unsigned int) header.uuid[13],
-                               (unsigned int) header.uuid[14],
-                               (unsigned int) header.uuid[15],
-                               (unsigned int) uuid[0],
-                               (unsigned int) uuid[1],
-                               (unsigned int) uuid[2],
-                               (unsigned int) uuid[3],
-                               (unsigned int) uuid[4],
-                               (unsigned int) uuid[5],
-                               (unsigned int) uuid[6],
-                               (unsigned int) uuid[7],
-                               (unsigned int) uuid[8],
-                               (unsigned int) uuid[9],
-                               (unsigned int) uuid[10],
-                               (unsigned int) uuid[11],
-                               (unsigned int) uuid[12],
-                               (unsigned int) uuid[13],
-                               (unsigned int) uuid[14],
-                               (unsigned int) uuid[15],
+                               BT_UUID_FMT_VALUES(header.uuid),
+                               BT_UUID_FMT_VALUES(uuid),
                                offset);
                        goto error;
                }
index a690ca7127b89666376ec17166aedfeab2a586a2..6215403ca1041dfa5945a09e6d64a75815055e6d 100644 (file)
@@ -23,7 +23,7 @@
 #include <stdlib.h>
 #include <inttypes.h>
 #include "common/assert.h"
-#include "compat/uuid.h"
+#include "common/uuid.h"
 #include "compat/memstream.h"
 #include <babeltrace2/babeltrace.h>
 #include <glib.h>
@@ -41,7 +41,7 @@ int yydebug;
 
 struct ctf_metadata_decoder {
        struct ctf_visitor_generate_ir *visitor;
-       uint8_t uuid[16];
+       bt_uuid_t uuid;
        bool is_uuid_set;
        int bo;
        struct ctf_metadata_decoder_config config;
@@ -49,7 +49,7 @@ struct ctf_metadata_decoder {
 
 struct packet_header {
        uint32_t magic;
-       uint8_t  uuid[16];
+       bt_uuid_t  uuid;
        uint32_t checksum;
        uint32_t content_size;
        uint32_t packet_size;
index d52104f8841d44ec50b06c291b0ae4dc05777bb2..56e5b70605471f3ab5164fd595d336120039029a 100644 (file)
@@ -43,7 +43,7 @@
 #include <inttypes.h>
 #include <errno.h>
 #include "common/common.h"
-#include "compat/uuid.h"
+#include "common/uuid.h"
 #include "compat/endian.h"
 #include <babeltrace2/babeltrace.h>
 
@@ -979,7 +979,7 @@ end:
 
 static
 int get_unary_uuid(struct ctx *ctx, struct bt_list_head *head,
-               unsigned char *uuid)
+               uint8_t *uuid)
 {
        int i = 0;
        int ret = 0;
@@ -999,7 +999,7 @@ int get_unary_uuid(struct ctx *ctx, struct bt_list_head *head,
                }
 
                src_string = node->u.unary_expression.u.string;
-               ret = bt_uuid_parse(src_string, uuid);
+               ret = bt_uuid_from_str(src_string, uuid);
                if (ret) {
                        _BT_COMP_LOGE_NODE(node,
                                "Cannot parse UUID: uuid=\"%s\"", src_string);
@@ -4415,7 +4415,7 @@ int visit_clock_decl_entry(struct ctx *ctx, struct ctf_node *entry_node,
                g_free(right);
                _SET(set, _CLOCK_NAME_SET);
        } else if (!strcmp(left, "uuid")) {
-               uint8_t uuid[BABELTRACE_UUID_LEN];
+               bt_uuid_t uuid;
 
                if (_IS_SET(set, _CLOCK_UUID_SET)) {
                        _BT_COMP_LOGE_DUP_ATTR(entry_node, "uuid", "clock class");
@@ -4432,7 +4432,7 @@ int visit_clock_decl_entry(struct ctx *ctx, struct ctf_node *entry_node,
                }
 
                clock->has_uuid = true;
-               memcpy(&clock->uuid[0], uuid, 16);
+               bt_uuid_copy(clock->uuid, uuid);
                _SET(set, _CLOCK_UUID_SET);
        } else if (!strcmp(left, "description")) {
                char *right;
index 7585ac745735c5f75a97aa1e9c76c4fd42405303..0d26a32e0efe5efbbc7af5123da59880102b26ce 100644 (file)
@@ -18,7 +18,7 @@
 #include <babeltrace2/babeltrace.h>
 #include "common/common.h"
 #include "common/assert.h"
-#include "compat/uuid.h"
+#include "common/uuid.h"
 #include <glib.h>
 #include <stdint.h>
 #include <string.h>
@@ -162,7 +162,7 @@ struct fs_sink_ctf_trace {
        /* Weak */
        const bt_trace_class *ir_tc;
 
-       unsigned char uuid[BABELTRACE_UUID_LEN];
+       bt_uuid_t uuid;
 
        /* Array of `struct fs_sink_ctf_stream_class *` (owned by this) */
        GPtrArray *stream_classes;
@@ -823,11 +823,7 @@ struct fs_sink_ctf_trace *fs_sink_ctf_trace_create(const bt_trace *ir_trace)
 
        BT_ASSERT(trace);
 
-       if (bt_uuid_generate(trace->uuid)) {
-               fs_sink_ctf_trace_destroy(trace);
-               trace = NULL;
-               goto end;
-       }
+       bt_uuid_generate(trace->uuid);
 
        trace->ir_trace = ir_trace;
        trace->ir_tc = bt_trace_borrow_class_const(ir_trace);
@@ -835,7 +831,6 @@ struct fs_sink_ctf_trace *fs_sink_ctf_trace_create(const bt_trace *ir_trace)
                (GDestroyNotify) fs_sink_ctf_stream_class_destroy);
        BT_ASSERT(trace->stream_classes);
 
-end:
        return trace;
 }
 
index d622a9c357ab64ea951025f224125f789e677e79..a6f39a376b53a76a13ed84381fd3687da966e715 100644 (file)
@@ -567,7 +567,7 @@ int fs_sink_stream_open_packet(struct fs_sink_stream *stream,
        }
 
        /* Packet header: UUID */
-       for (i = 0; i < BABELTRACE_UUID_LEN; i++) {
+       for (i = 0; i < BT_UUID_LEN; i++) {
                ret = bt_ctfser_write_byte_aligned_unsigned_int(&stream->ctfser,
                        (uint64_t) stream->sc->trace->uuid[i], 8, 8, BYTE_ORDER);
                if (ret) {
index 4fdd6241b13dfdec9816b49218232c75c33a9e18..99739e2fd1f48d0afdc7e7b41106971ea4dd9d34 100644 (file)
@@ -50,23 +50,8 @@ static
 void append_uuid(struct ctx *ctx, bt_uuid uuid)
 {
        g_string_append_printf(ctx->tsdl,
-               "\"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\"",
-               (unsigned int) uuid[0],
-               (unsigned int) uuid[1],
-               (unsigned int) uuid[2],
-               (unsigned int) uuid[3],
-               (unsigned int) uuid[4],
-               (unsigned int) uuid[5],
-               (unsigned int) uuid[6],
-               (unsigned int) uuid[7],
-               (unsigned int) uuid[8],
-               (unsigned int) uuid[9],
-               (unsigned int) uuid[10],
-               (unsigned int) uuid[11],
-               (unsigned int) uuid[12],
-               (unsigned int) uuid[13],
-               (unsigned int) uuid[14],
-               (unsigned int) uuid[15]);
+               "\"" BT_UUID_FMT "\"",
+               BT_UUID_FMT_VALUES(uuid));
 }
 
 static
index 4ad1853927948fd93fac81f89724257951a9b17b..fb5fa1c545f92accd8c1e0c422bacc178107043b 100644 (file)
@@ -32,7 +32,7 @@
 
 #include "common/common.h"
 #include <babeltrace2/babeltrace.h>
-#include "compat/uuid.h"
+#include "common/uuid.h"
 #include <glib.h>
 #include "common/assert.h"
 #include <inttypes.h>
@@ -427,9 +427,9 @@ gchar *ctf_fs_make_port_name(struct ctf_fs_ds_file_group *ds_file_group)
 
        /* For the trace, use the uuid if present, else the path. */
        if (ds_file_group->ctf_fs_trace->metadata->tc->is_uuid_set) {
-               char uuid_str[BABELTRACE_UUID_STR_LEN];
+               char uuid_str[BT_UUID_STR_LEN + 1];
 
-               bt_uuid_unparse(ds_file_group->ctf_fs_trace->metadata->tc->uuid, uuid_str);
+               bt_uuid_to_str(ds_file_group->ctf_fs_trace->metadata->tc->uuid, uuid_str);
                g_string_assign(name, uuid_str);
        } else {
                g_string_assign(name, ds_file_group->ctf_fs_trace->path->str);
@@ -1580,7 +1580,7 @@ int merge_ctf_fs_traces(struct ctf_fs_trace **traces, unsigned int num_traces)
        struct ctf_fs_trace *winner;
        guint i;
        int ret = 0;
-       char uuid_str[BABELTRACE_UUID_STR_LEN];
+       char uuid_str[BT_UUID_STR_LEN + 1];
 
        BT_ASSERT(num_traces >= 2);
 
@@ -1626,7 +1626,7 @@ int merge_ctf_fs_traces(struct ctf_fs_trace **traces, unsigned int num_traces)
        }
 
        /* Use the string representation of the UUID as the trace name. */
-       bt_uuid_unparse(winner->metadata->tc->uuid, uuid_str);
+       bt_uuid_to_str(winner->metadata->tc->uuid, uuid_str);
        g_string_printf(winner->name, "%s", uuid_str);
 
 end:
index 94ff889abe6741b9b5f3a4f503fc19d5a3f7740b..63b7f0ed417564b267e724001386b63e10cfd0d0 100644 (file)
@@ -34,7 +34,7 @@
 #include <stdbool.h>
 #include "common/assert.h"
 #include <glib.h>
-#include "compat/uuid.h"
+#include "common/uuid.h"
 #include "compat/memstream.h"
 #include <babeltrace2/babeltrace.h>
 
index e79e7e03ef2d2f78896af2f5b6a877ad3ac22f53..788416d89f72b648c1228bdf186c0441e7e26dd2 100644 (file)
@@ -26,6 +26,7 @@
 
 #include "common/assert.h"
 #include "common/common.h"
+#include "common/uuid.h"
 #include "details.h"
 #include "write.h"
 #include "obj-lifetime-mgmt.h"
@@ -329,24 +330,9 @@ void write_uuid_prop_line(struct details_write_ctx *ctx, const char *prop_name,
        write_indent(ctx);
        write_prop_name(ctx, prop_name);
        g_string_append_printf(ctx->str,
-               ": %s%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x%s\n",
+               ": %s" BT_UUID_FMT "%s\n",
                color_bold(ctx),
-               (unsigned int) uuid[0],
-               (unsigned int) uuid[1],
-               (unsigned int) uuid[2],
-               (unsigned int) uuid[3],
-               (unsigned int) uuid[4],
-               (unsigned int) uuid[5],
-               (unsigned int) uuid[6],
-               (unsigned int) uuid[7],
-               (unsigned int) uuid[8],
-               (unsigned int) uuid[9],
-               (unsigned int) uuid[10],
-               (unsigned int) uuid[11],
-               (unsigned int) uuid[12],
-               (unsigned int) uuid[13],
-               (unsigned int) uuid[14],
-               (unsigned int) uuid[15],
+               BT_UUID_FMT_VALUES(uuid),
                color_reset(ctx));
 }
 
index 80651f15fa97e23a4b54df71d4186d1e6461e2d1..9645827e15bd6b7d912e5bcdb98d57cae52db3ae 100644 (file)
@@ -26,6 +26,7 @@
 #include <babeltrace2/babeltrace.h>
 #include "compat/bitfield.h"
 #include "common/common.h"
+#include "common/uuid.h"
 #include "compat/time.h"
 #include "common/assert.h"
 #include <inttypes.h>
@@ -1280,23 +1281,8 @@ int print_discarded_elements_msg(struct pretty_component *pretty,
 
        if (trace_uuid) {
                g_string_append_printf(pretty->string,
-                       "(UUID: %02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x) ",
-                       trace_uuid[0],
-                       trace_uuid[1],
-                       trace_uuid[2],
-                       trace_uuid[3],
-                       trace_uuid[4],
-                       trace_uuid[5],
-                       trace_uuid[6],
-                       trace_uuid[7],
-                       trace_uuid[8],
-                       trace_uuid[9],
-                       trace_uuid[10],
-                       trace_uuid[11],
-                       trace_uuid[12],
-                       trace_uuid[13],
-                       trace_uuid[14],
-                       trace_uuid[15]);
+                       "(UUID: " BT_UUID_FMT ") ",
+                       BT_UUID_FMT_VALUES(trace_uuid));
        } else {
                g_string_append(pretty->string, "(no UUID) ");
        }
index 37d006087866d92a535c12f953bc343a246eb519..e1603fedabb2225260a95395cd6ef095c78302e8 100644 (file)
@@ -26,7 +26,7 @@
 #include "plugins/comp-logging.h"
 
 #include "common/macros.h"
-#include "compat/uuid.h"
+#include "common/uuid.h"
 #include <babeltrace2/babeltrace.h>
 #include <glib.h>
 #include <stdbool.h>
@@ -103,7 +103,7 @@ struct muxer_msg_iter {
         * clock_class_expectation is
         * MUXER_MSG_ITER_CLOCK_CLASS_EXPECTATION_NOT_ABS_SPEC_UUID.
         */
-       unsigned char expected_clock_class_uuid[BABELTRACE_UUID_LEN];
+       bt_uuid_t expected_clock_class_uuid;
 };
 
 static
@@ -668,7 +668,7 @@ int validate_clock_class(struct muxer_msg_iter *muxer_msg_iter,
                const bt_clock_class *clock_class)
 {
        int ret = 0;
-       const unsigned char *cc_uuid;
+       const uint8_t *cc_uuid;
        const char *cc_name;
 
        BT_ASSERT(clock_class);
@@ -696,8 +696,7 @@ int validate_clock_class(struct muxer_msg_iter *muxer_msg_iter,
                                 */
                                muxer_msg_iter->clock_class_expectation =
                                        MUXER_MSG_ITER_CLOCK_CLASS_EXPECTATION_NOT_ABS_SPEC_UUID;
-                               memcpy(muxer_msg_iter->expected_clock_class_uuid,
-                                       cc_uuid, BABELTRACE_UUID_LEN);
+                               bt_uuid_copy(muxer_msg_iter->expected_clock_class_uuid, cc_uuid);
                        } else {
                                /*
                                 * Expect non-absolute clock classes
@@ -733,24 +732,8 @@ int validate_clock_class(struct muxer_msg_iter *muxer_msg_iter,
                                BT_COMP_LOGE("Expecting a non-absolute clock class with no UUID, "
                                        "but got one with a UUID: "
                                        "clock-class-addr=%p, clock-class-name=\"%s\", "
-                                       "uuid=\"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\"",
-                                       clock_class, cc_name,
-                                       (unsigned int) cc_uuid[0],
-                                       (unsigned int) cc_uuid[1],
-                                       (unsigned int) cc_uuid[2],
-                                       (unsigned int) cc_uuid[3],
-                                       (unsigned int) cc_uuid[4],
-                                       (unsigned int) cc_uuid[5],
-                                       (unsigned int) cc_uuid[6],
-                                       (unsigned int) cc_uuid[7],
-                                       (unsigned int) cc_uuid[8],
-                                       (unsigned int) cc_uuid[9],
-                                       (unsigned int) cc_uuid[10],
-                                       (unsigned int) cc_uuid[11],
-                                       (unsigned int) cc_uuid[12],
-                                       (unsigned int) cc_uuid[13],
-                                       (unsigned int) cc_uuid[14],
-                                       (unsigned int) cc_uuid[15]);
+                                       "uuid=\"" BT_UUID_FMT "\"",
+                                       clock_class, cc_name, BT_UUID_FMT_VALUES(cc_uuid));
                                goto error;
                        }
                        break;
@@ -771,46 +754,15 @@ int validate_clock_class(struct muxer_msg_iter *muxer_msg_iter,
                                goto error;
                        }
 
-                       if (memcmp(muxer_msg_iter->expected_clock_class_uuid,
-                                       cc_uuid, BABELTRACE_UUID_LEN) != 0) {
+                       if (bt_uuid_compare(muxer_msg_iter->expected_clock_class_uuid, cc_uuid) != 0) {
                                BT_COMP_LOGE("Expecting a non-absolute clock class with a specific UUID, "
                                        "but got one with different UUID: "
                                        "clock-class-addr=%p, clock-class-name=\"%s\", "
-                                       "expected-uuid=\"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\", "
-                                       "uuid=\"%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x\"",
+                                       "expected-uuid=\"" BT_UUID_FMT "\", "
+                                       "uuid=\"" BT_UUID_FMT "\"",
                                        clock_class, cc_name,
-                                       (unsigned int) muxer_msg_iter->expected_clock_class_uuid[0],
-                                       (unsigned int) muxer_msg_iter->expected_clock_class_uuid[1],
-                                       (unsigned int) muxer_msg_iter->expected_clock_class_uuid[2],
-                                       (unsigned int) muxer_msg_iter->expected_clock_class_uuid[3],
-                                       (unsigned int) muxer_msg_iter->expected_clock_class_uuid[4],
-                                       (unsigned int) muxer_msg_iter->expected_clock_class_uuid[5],
-                                       (unsigned int) muxer_msg_iter->expected_clock_class_uuid[6],
-                                       (unsigned int) muxer_msg_iter->expected_clock_class_uuid[7],
-                                       (unsigned int) muxer_msg_iter->expected_clock_class_uuid[8],
-                                       (unsigned int) muxer_msg_iter->expected_clock_class_uuid[9],
-                                       (unsigned int) muxer_msg_iter->expected_clock_class_uuid[10],
-                                       (unsigned int) muxer_msg_iter->expected_clock_class_uuid[11],
-                                       (unsigned int) muxer_msg_iter->expected_clock_class_uuid[12],
-                                       (unsigned int) muxer_msg_iter->expected_clock_class_uuid[13],
-                                       (unsigned int) muxer_msg_iter->expected_clock_class_uuid[14],
-                                       (unsigned int) muxer_msg_iter->expected_clock_class_uuid[15],
-                                       (unsigned int) cc_uuid[0],
-                                       (unsigned int) cc_uuid[1],
-                                       (unsigned int) cc_uuid[2],
-                                       (unsigned int) cc_uuid[3],
-                                       (unsigned int) cc_uuid[4],
-                                       (unsigned int) cc_uuid[5],
-                                       (unsigned int) cc_uuid[6],
-                                       (unsigned int) cc_uuid[7],
-                                       (unsigned int) cc_uuid[8],
-                                       (unsigned int) cc_uuid[9],
-                                       (unsigned int) cc_uuid[10],
-                                       (unsigned int) cc_uuid[11],
-                                       (unsigned int) cc_uuid[12],
-                                       (unsigned int) cc_uuid[13],
-                                       (unsigned int) cc_uuid[14],
-                                       (unsigned int) cc_uuid[15]);
+                                       BT_UUID_FMT_VALUES(muxer_msg_iter->expected_clock_class_uuid),
+                                       BT_UUID_FMT_VALUES(cc_uuid));
                                goto error;
                        }
                        break;
index 00f69f51ef613fefa6d3810005f6955597bd7d67..877ec1c778bcc8323d2209aa65de8ccef41a3520 100644 (file)
@@ -57,6 +57,7 @@ TESTS_CLI = \
 TESTS_LIB = \
        lib/test_bitfield \
        lib/test_bt_values \
+       lib/test_bt_uuid \
        lib/test_graph_topo \
        lib/test_trace_ir_ref
 
index 1ed4cc6737d764f730c1b8d2b7e00215b1be392e..81dc58d74ee748827af2ba96057e86d4aad6f504 100644 (file)
@@ -38,6 +38,7 @@
 #include "compat/stdio.h"
 #include <string.h>
 #include "common/assert.h"
+#include "common/uuid.h"
 #include <fcntl.h>
 #include "tap/tap.h"
 #include <math.h>
@@ -72,7 +73,7 @@ static unsigned int packet_resize_test_length = PACKET_RESIZE_TEST_DEF_LENGTH;
 
 /* Return 1 if uuids match, zero if different. */
 static
-int uuid_match(const unsigned char *uuid_a, const unsigned char *uuid_b)
+int uuid_match(const uint8_t *uuid_a, const uint8_t *uuid_b)
 {
        int ret = 0;
        int i;
@@ -1600,8 +1601,8 @@ int main(int argc, char **argv)
        struct bt_ctf_stream *stream1;
        struct bt_ctf_stream *stream;
        const char *ret_string;
-       const unsigned char *ret_uuid;
-       unsigned char tmp_uuid[16] = { 0 };
+       const uint8_t *ret_uuid;
+       bt_uuid_t tmp_uuid = { 0 };
        struct bt_ctf_field_type *packet_context_type,
                *packet_context_field_type,
                *packet_header_type,
index efbb6c860deb0a76320af830b0a05a23125aa805..ce8d17a72f353c991465e13bb56529e588598956 100644 (file)
@@ -11,6 +11,10 @@ test_bitfield_LDADD = $(COMMON_TEST_LDADD)
 test_bt_values_LDADD = $(COMMON_TEST_LDADD) \
        $(top_builddir)/src/lib/libbabeltrace2.la
 
+test_bt_uuid_LDADD = $(COMMON_TEST_LDADD) \
+       $(top_builddir)/src/common/libbabeltrace2-common.la \
+       $(top_builddir)/src/logging/libbabeltrace2-logging.la
+
 test_trace_ir_ref_LDADD = $(COMMON_TEST_LDADD) \
        $(top_builddir)/src/lib/libbabeltrace2.la \
        $(top_builddir)/src/ctf-writer/libbabeltrace2-ctf-writer.la
@@ -18,11 +22,16 @@ test_trace_ir_ref_LDADD = $(COMMON_TEST_LDADD) \
 test_graph_topo_LDADD = $(COMMON_TEST_LDADD) \
        $(top_builddir)/src/lib/libbabeltrace2.la
 
-noinst_PROGRAMS = test_bitfield test_bt_values \
-       test_trace_ir_ref test_graph_topo
+noinst_PROGRAMS = \
+       test_bitfield \
+       test_bt_values \
+       test_bt_uuid \
+       test_trace_ir_ref \
+       test_graph_topo
 
 test_bitfield_SOURCES = test_bitfield.c
 test_bt_values_SOURCES = test_bt_values.c
+test_bt_uuid_SOURCES = test_bt_uuid.c
 test_trace_ir_ref_SOURCES = test_trace_ir_ref.c
 test_graph_topo_SOURCES = test_graph_topo.c
 
diff --git a/tests/lib/test_bt_uuid.c b/tests/lib/test_bt_uuid.c
new file mode 100644 (file)
index 0000000..3aef05e
--- /dev/null
@@ -0,0 +1,192 @@
+/*
+ * test_bt_uuid.c
+ *
+ * Copyright 2019 Michael Jeanson <mjeanson@efficios.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; under version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include <stdio.h>
+#include <string.h>
+
+#include <tap/tap.h>
+
+#include "common/uuid.h"
+
+#define NR_TESTS 21
+
+static const char valid_str_1[] = "3d260c88-75ea-47b8-a7e2-d6077c0378d9";
+static const char valid_str_2[] = "611cf3a6-a68b-4515-834f-208bc2762592";
+static const char valid_str_3[] = "1b4855cc-96de-4ae8-abe3-86449c2a43c4";
+static const char valid_str_4[] = "8ADED5B9-ACD2-439F-A60C-897403AA2AB4";
+static const char valid_str_5[] = "f109e0a2-C619-4d18-b760-20EA20E0F69A";
+
+static bt_uuid_t valid_uuid_1 = {
+       0x3d, 0x26, 0x0c, 0x88, 0x75, 0xea, 0x47, 0xb8,
+       0xa7, 0xe2, 0xd6, 0x07, 0x7c, 0x03, 0x78, 0xd9
+};
+static bt_uuid_t valid_uuid_2 = {
+       0x61, 0x1c, 0xf3, 0xa6, 0xa6, 0x8b, 0x45, 0x15,
+       0x83, 0x4f, 0x20, 0x8b, 0xc2, 0x76, 0x25, 0x92
+};
+static bt_uuid_t valid_uuid_3 = {
+       0x1b, 0x48, 0x55, 0xcc, 0x96, 0xde, 0x4a, 0xe8,
+       0xab, 0xe3, 0x86, 0x44, 0x9c, 0x2a, 0x43, 0xc4
+};
+
+static const char invalid_str_1[] = "1b485!cc-96de-4XX8-abe3-86449c2a43?4";
+static const char invalid_str_2[] = "c2e6eddb&3955&4006&be3a&70bb63bd5f25";
+static const char invalid_str_3[] = "81b1cb88-ff42-45b9-ba4d-964088ee45";
+static const char invalid_str_4[] = "2d-6c6d756574-470e-9142-a4e6ad03f143";
+static const char invalid_str_5[] = "4542ad19-9e4f-4931-8261-2101c3e089ae7";
+static const char invalid_str_6[] = "XX0123";
+
+static
+void run_test_bt_uuid_from_str(void)
+{
+       int ret;
+       bt_uuid_t uuid1;
+
+       /*
+        * Parse valid UUID strings, expect success.
+        */
+       ret = bt_uuid_from_str(valid_str_1, uuid1);
+       ok(ret == 0, "bt_uuid_from_str - Parse valid string '%s', expect success", valid_str_1);
+
+       ret = bt_uuid_from_str(valid_str_2, uuid1);
+       ok(ret == 0, "bt_uuid_from_str - Parse valid string '%s', expect success", valid_str_2);
+
+       ret = bt_uuid_from_str(valid_str_3, uuid1);
+       ok(ret == 0, "bt_uuid_from_str - Parse valid string '%s', expect success", valid_str_3);
+
+       ret = bt_uuid_from_str(valid_str_4, uuid1);
+       ok(ret == 0, "bt_uuid_from_str - Parse valid string '%s', expect success", valid_str_4);
+
+       ret = bt_uuid_from_str(valid_str_5, uuid1);
+       ok(ret == 0, "bt_uuid_from_str - Parse valid string '%s', expect success", valid_str_5);
+
+       /*
+        * Parse invalid UUID strings, expect failure.
+        */
+       ret = bt_uuid_from_str(invalid_str_1, uuid1);
+       ok(ret != 0, "bt_uuid_from_str - Parse invalid string '%s', expect failure", invalid_str_1);
+
+       ret = bt_uuid_from_str(invalid_str_2, uuid1);
+       ok(ret != 0, "bt_uuid_from_str - Parse invalid string '%s', expect failure", invalid_str_2);
+
+       ret = bt_uuid_from_str(invalid_str_3, uuid1);
+       ok(ret != 0, "bt_uuid_from_str - Parse invalid string '%s', expect failure", invalid_str_3);
+
+       ret = bt_uuid_from_str(invalid_str_4, uuid1);
+       ok(ret != 0, "bt_uuid_from_str - Parse invalid string '%s', expect failure", invalid_str_4);
+
+       ret = bt_uuid_from_str(invalid_str_5, uuid1);
+       ok(ret != 0, "bt_uuid_from_str - Parse invalid string '%s', expect failure", invalid_str_5);
+
+       ret = bt_uuid_from_str(invalid_str_6, uuid1);
+       ok(ret != 0, "bt_uuid_from_str - Parse invalid string '%s', expect failure", invalid_str_6);
+}
+
+static
+void run_test_bt_uuid_to_str(void)
+{
+       char uuid_str[BT_UUID_STR_LEN + 1];
+
+       bt_uuid_to_str(valid_uuid_1, uuid_str);
+       ok(strcmp(uuid_str, valid_str_1) == 0, "bt_uuid_to_str - Convert UUID '%s' to string, expect success", valid_str_1);
+
+       bt_uuid_to_str(valid_uuid_2, uuid_str);
+       ok(strcmp(uuid_str, valid_str_2) == 0, "bt_uuid_to_str - Convert UUID '%s' to string, expect success", valid_str_2);
+
+       bt_uuid_to_str(valid_uuid_3, uuid_str);
+       ok(strcmp(uuid_str, valid_str_3) == 0, "bt_uuid_to_str - Convert UUID '%s' to string, expect success", valid_str_3);
+}
+
+static
+void run_test_bt_uuid_compare(void)
+{
+       int ret;
+       bt_uuid_t uuid1, uuid2;
+
+       bt_uuid_from_str(valid_str_1, uuid1);
+       bt_uuid_from_str(valid_str_1, uuid2);
+       ret = bt_uuid_compare(uuid1, uuid2);
+       ok(ret == 0, "bt_uuid_compare - Compare same UUID, expect success");
+
+       bt_uuid_from_str(valid_str_2, uuid2);
+       ret = bt_uuid_compare(uuid1, uuid2);
+       ok(ret != 0, "bt_uuid_compare - Compare different UUID, expect failure");
+}
+
+static
+void run_test_bt_uuid_copy(void)
+{
+       int ret;
+       bt_uuid_t uuid1;
+
+       bt_uuid_copy(uuid1, valid_uuid_1);
+       ret = bt_uuid_compare(uuid1, valid_uuid_1);
+
+       ok(ret == 0, "bt_uuid_copy - Compare copied UUID with source, expect success");
+}
+
+static
+void run_test_bt_uuid_generate(void)
+{
+       int ret;
+       bt_uuid_t uuid1, uuid2;
+
+       bt_uuid_generate(uuid1);
+       bt_uuid_generate(uuid2);
+
+       ok(bt_uuid_compare(uuid1, uuid2) != 0, "bt_uuid_generate - Generated UUIDs are different");
+
+       /*
+        * Set the two most significant bits (bits 6 and 7) of the
+        * clock_seq_hi_and_reserved to zero and one, respectively.
+        */
+       ret = uuid1[8] & (1 << 6);
+       ok(ret == 0, "bt_uuid_generate - bit 6 of clock_seq_hi_and_reserved is set to zero");
+
+       ret = uuid1[8] & (1 << 7);
+       ok(ret != 0, "bt_uuid_generate - bit 7 of clock_seq_hi_and_reserved is set to one");
+
+       /*
+        * Set the four most significant bits (bits 12 through 15) of the
+        * time_hi_and_version field to the 4-bit version number from
+        * Section 4.1.3.
+        */
+       ret = uuid1[6] >> 4;
+       ok(ret == BT_UUID_VER, "bt_uuid_generate - Generated UUID version check");
+}
+
+static
+void run_test(void)
+{
+       plan_tests(NR_TESTS);
+
+       run_test_bt_uuid_from_str();
+       run_test_bt_uuid_to_str();
+       run_test_bt_uuid_compare();
+       run_test_bt_uuid_copy();
+       run_test_bt_uuid_generate();
+}
+
+int main(int argc, char **argv)
+{
+       /* Run tap-formated tests */
+       run_test();
+
+       return exit_status();
+}
This page took 0.059587 seconds and 4 git commands to generate.