From 6162e6b7a6d907974d954419c2375f654f39eb72 Mon Sep 17 00:00:00 2001 From: Michael Jeanson Date: Thu, 27 Jun 2019 17:41:53 -0400 Subject: [PATCH] Replace libuuid with internal implementation 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 Reviewed-on: https://review.lttng.org/c/babeltrace/+/1572 Tested-by: jenkins Reviewed-by: Philippe Proulx --- .gitignore | 1 + README | 3 - configure.ac | 45 ---- include/babeltrace2/ctf-writer/clock-class.h | 4 +- include/babeltrace2/ctf-writer/clock.h | 4 +- include/babeltrace2/ctf-writer/trace.h | 4 +- src/babeltrace2-ctf-writer.pc.in | 2 - src/babeltrace2.pc.in | 2 - src/common/Makefile.am | 6 +- src/common/uuid.c | 123 +++++++++++ src/common/uuid.h | 57 ++++++ src/compat/Makefile.am | 8 +- src/compat/uuid.c | 119 ----------- src/compat/uuid.h | 157 -------------- src/ctf-writer/Makefile.am | 3 +- src/ctf-writer/clock-class.c | 71 ++----- src/ctf-writer/clock-class.h | 8 +- src/ctf-writer/clock.c | 22 +- src/ctf-writer/clock.h | 1 - src/ctf-writer/trace.c | 36 +--- src/ctf-writer/trace.h | 8 +- src/ctf-writer/writer.c | 10 +- src/lib/graph/iterator.c | 2 +- src/lib/graph/message/iterator.h | 4 +- src/lib/lib-logging.c | 19 +- src/lib/trace-ir/Makefile.am | 2 - src/lib/trace-ir/clock-class.c | 4 +- src/lib/trace-ir/clock-class.h | 4 +- src/lib/trace-ir/clock-snapshot.c | 2 +- src/lib/trace-ir/trace-class.h | 1 - src/lib/trace-ir/trace.c | 2 +- src/lib/trace-ir/trace.h | 4 +- src/plugins/ctf/common/metadata/Makefile.am | 4 +- src/plugins/ctf/common/metadata/ctf-meta.h | 5 +- .../decoder-packetized-file-stream-to-buf.c | 46 +---- src/plugins/ctf/common/metadata/decoder.c | 6 +- .../ctf/common/metadata/visitor-generate-ir.c | 10 +- src/plugins/ctf/fs-sink/fs-sink-ctf-meta.h | 11 +- src/plugins/ctf/fs-sink/fs-sink-stream.c | 2 +- .../ctf/fs-sink/translate-ctf-ir-to-tsdl.c | 19 +- src/plugins/ctf/fs-src/fs.c | 10 +- src/plugins/ctf/fs-src/metadata.c | 2 +- src/plugins/text/details/write.c | 20 +- src/plugins/text/pretty/print.c | 20 +- src/plugins/utils/muxer/muxer.c | 70 +------ tests/Makefile.am | 1 + tests/ctf-writer/ctf_writer.c | 7 +- tests/lib/Makefile.am | 13 +- tests/lib/test_bt_uuid.c | 192 ++++++++++++++++++ 49 files changed, 503 insertions(+), 673 deletions(-) create mode 100644 src/common/uuid.c create mode 100644 src/common/uuid.h delete mode 100644 src/compat/uuid.c delete mode 100644 src/compat/uuid.h create mode 100644 tests/lib/test_bt_uuid.c diff --git a/.gitignore b/.gitignore index a00cd499..572ac7a9 100644 --- a/.gitignore +++ b/.gitignore @@ -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 cfd9693b..5e0e7664 100644 --- 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) diff --git a/configure.ac b/configure.ac index 25b8f866..4077a039 100644 --- a/configure.ac +++ b/configure.ac @@ -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.])] diff --git a/include/babeltrace2/ctf-writer/clock-class.h b/include/babeltrace2/ctf-writer/clock-class.h index ae074b82..d8b7b4e7 100644 --- a/include/babeltrace2/ctf-writer/clock-class.h +++ b/include/babeltrace2/ctf-writer/clock-class.h @@ -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 diff --git a/include/babeltrace2/ctf-writer/clock.h b/include/babeltrace2/ctf-writer/clock.h index 8cef6b69..ccb1f26b 100644 --- a/include/babeltrace2/ctf-writer/clock.h +++ b/include/babeltrace2/ctf-writer/clock.h @@ -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. diff --git a/include/babeltrace2/ctf-writer/trace.h b/include/babeltrace2/ctf-writer/trace.h index 27b18214..d9d10f61 100644 --- a/include/babeltrace2/ctf-writer/trace.h +++ b/include/babeltrace2/ctf-writer/trace.h @@ -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, diff --git a/src/babeltrace2-ctf-writer.pc.in b/src/babeltrace2-ctf-writer.pc.in index 380ac930..960f5b47 100644 --- a/src/babeltrace2-ctf-writer.pc.in +++ b/src/babeltrace2-ctf-writer.pc.in @@ -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@ diff --git a/src/babeltrace2.pc.in b/src/babeltrace2.pc.in index af831e00..8d812a5b 100644 --- a/src/babeltrace2.pc.in +++ b/src/babeltrace2.pc.in @@ -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@ diff --git a/src/common/Makefile.am b/src/common/Makefile.am index b2a232e8..02b8106a 100644 --- a/src/common/Makefile.am +++ b/src/common/Makefile.am @@ -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 index 00000000..f6d895a8 --- /dev/null +++ b/src/common/uuid.c @@ -0,0 +1,123 @@ +/* + * Copyright (C) 2019 Michael Jeanson + * + * 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 +#include +#include +#include + +#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 index 00000000..3630351d --- /dev/null +++ b/src/common/uuid.h @@ -0,0 +1,57 @@ +#ifndef _BABELTRACE_COMMON_UUID_H +#define _BABELTRACE_COMMON_UUID_H + +/* + * Copyright (C) 2019 Michael Jeanson + * + * 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 +#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 */ diff --git a/src/compat/Makefile.am b/src/compat/Makefile.am index 939b169b..0d87ccc0 100644 --- a/src/compat/Makefile.am +++ b/src/compat/Makefile.am @@ -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 index 0cc5976f..00000000 --- a/src/compat/uuid.c +++ /dev/null @@ -1,119 +0,0 @@ -/* - * compat/compat_uuid.h - * - * Copyright (C) 2013 Mathieu Desnoyers - * - * 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 -#include -#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 index 2c2e9295..00000000 --- a/src/compat/uuid.h +++ /dev/null @@ -1,157 +0,0 @@ -#ifndef _BABELTRACE_COMPAT_UUID_H -#define _BABELTRACE_COMPAT_UUID_H - -/* - * Copyright (C) 2011 Mathieu Desnoyers - * - * 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 - -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 -#include -#include -#include - -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 */ diff --git a/src/ctf-writer/Makefile.am b/src/ctf-writer/Makefile.am index be8d1e1c..234d0c19 100644 --- a/src/ctf-writer/Makefile.am +++ b/src/ctf-writer/Makefile.am @@ -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 diff --git a/src/ctf-writer/clock-class.c b/src/ctf-writer/clock-class.c index c4332c53..d186f89a 100644 --- a/src/ctf-writer/clock-class.c +++ b/src/ctf-writer/clock-class.c @@ -29,7 +29,7 @@ #define BT_LOG_TAG "CTF-WRITER/CLOCK-CLASS" #include "logging.h" -#include "compat/uuid.h" +#include "common/uuid.h" #include #include #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 { diff --git a/src/ctf-writer/clock-class.h b/src/ctf-writer/clock-class.h index dfe95cc7..ec78f66b 100644 --- a/src/ctf-writer/clock-class.h +++ b/src/ctf-writer/clock-class.h @@ -27,7 +27,7 @@ #include "common/macros.h" #include "object-pool.h" -#include "compat/uuid.h" +#include "common/uuid.h" #include #include #include @@ -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 */ diff --git a/src/ctf-writer/clock.c b/src/ctf-writer/clock.c index 58d86d1c..e1c00dac 100644 --- a/src/ctf-writer/clock.c +++ b/src/ctf-writer/clock.c @@ -31,7 +31,7 @@ #include "logging.h" #include "common/assert.h" -#include "compat/uuid.h" +#include "common/uuid.h" #include "compat/compiler.h" #include #include @@ -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) { diff --git a/src/ctf-writer/clock.h b/src/ctf-writer/clock.h index d38d8ea5..01cddc47 100644 --- a/src/ctf-writer/clock.h +++ b/src/ctf-writer/clock.h @@ -26,7 +26,6 @@ #include #include "common/macros.h" #include -#include "compat/uuid.h" #include "clock-class.h" #include "object.h" diff --git a/src/ctf-writer/trace.c b/src/ctf-writer/trace.c index 82eb35b3..f7ef692d 100644 --- a/src/ctf-writer/trace.c +++ b/src/ctf-writer/trace.c @@ -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", diff --git a/src/ctf-writer/trace.h b/src/ctf-writer/trace.h index ca6328fb..231e97b0 100644 --- a/src/ctf-writer/trace.h +++ b/src/ctf-writer/trace.h @@ -29,7 +29,7 @@ */ #include "common/macros.h" -#include "compat/uuid.h" +#include "common/uuid.h" #include #include #include @@ -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, diff --git a/src/ctf-writer/writer.c b/src/ctf-writer/writer.c index 6c72acaf..650d68f3 100644 --- a/src/ctf-writer/writer.c +++ b/src/ctf-writer/writer.c @@ -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) { diff --git a/src/lib/graph/iterator.c b/src/lib/graph/iterator.c index 048daaf1..41805663 100644 --- a/src/lib/graph/iterator.c +++ b/src/lib/graph/iterator.c @@ -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; } diff --git a/src/lib/graph/message/iterator.h b/src/lib/graph/message/iterator.h index d28a8810..b8a9dfa2 100644 --- a/src/lib/graph/message/iterator.h +++ b/src/lib/graph/message/iterator.h @@ -31,7 +31,7 @@ #include #include "common/assert.h" #include -#include +#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; /* diff --git a/src/lib/lib-logging.c b/src/lib/lib-logging.c index dcfee70f..b48c5db7 100644 --- a/src/lib/lib-logging.c +++ b/src/lib/lib-logging.c @@ -32,6 +32,7 @@ #include #include #include "common/common.h" +#include "common/uuid.h" #include #include #include @@ -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, diff --git a/src/lib/trace-ir/Makefile.am b/src/lib/trace-ir/Makefile.am index 159f4b4a..11e1e542 100644 --- a/src/lib/trace-ir/Makefile.am +++ b/src/lib/trace-ir/Makefile.am @@ -35,5 +35,3 @@ libtrace_ir_la_SOURCES = \ trace.h \ utils.c \ utils.h - -libtrace_ir_la_LIBADD = $(UUID_LIBS) diff --git a/src/lib/trace-ir/clock-class.c b/src/lib/trace-ir/clock-class.c index 43341d0f..119b4db9 100644 --- a/src/lib/trace-ir/clock-class.c +++ b/src/lib/trace-ir/clock-class.c @@ -25,7 +25,7 @@ #include "lib/logging.h" #include "lib/assert-pre.h" -#include "compat/uuid.h" +#include "common/uuid.h" #include #include #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); } diff --git a/src/lib/trace-ir/clock-class.h b/src/lib/trace-ir/clock-class.h index 153456dd..f3daa67c 100644 --- a/src/lib/trace-ir/clock-class.h +++ b/src/lib/trace-ir/clock-class.h @@ -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 #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; diff --git a/src/lib/trace-ir/clock-snapshot.c b/src/lib/trace-ir/clock-snapshot.c index 53f6be65..307198d2 100644 --- a/src/lib/trace-ir/clock-snapshot.c +++ b/src/lib/trace-ir/clock-snapshot.c @@ -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 diff --git a/src/lib/trace-ir/trace-class.h b/src/lib/trace-ir/trace-class.h index 589da127..0b06bf32 100644 --- a/src/lib/trace-ir/trace-class.h +++ b/src/lib/trace-ir/trace-class.h @@ -35,7 +35,6 @@ #include #include #include -#include "compat/uuid.h" #include "stream-class.h" #include "attributes.h" diff --git a/src/lib/trace-ir/trace.c b/src/lib/trace-ir/trace.c index ce76ce5e..8b6650db 100644 --- a/src/lib/trace-ir/trace.c +++ b/src/lib/trace-ir/trace.c @@ -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); } diff --git a/src/lib/trace-ir/trace.h b/src/lib/trace-ir/trace.h index c5c244b5..288bfa36 100644 --- a/src/lib/trace-ir/trace.h +++ b/src/lib/trace-ir/trace.h @@ -35,7 +35,7 @@ #include #include #include -#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; diff --git a/src/plugins/ctf/common/metadata/Makefile.am b/src/plugins/ctf/common/metadata/Makefile.am index 2e1d4d03..8cdf35e5 100644 --- a/src/plugins/ctf/common/metadata/Makefile.am +++ b/src/plugins/ctf/common/metadata/Makefile.am @@ -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 diff --git a/src/plugins/ctf/common/metadata/ctf-meta.h b/src/plugins/ctf/common/metadata/ctf-meta.h index 29c5e178..e62b40ad 100644 --- a/src/plugins/ctf/common/metadata/ctf-meta.h +++ b/src/plugins/ctf/common/metadata/ctf-meta.h @@ -17,6 +17,7 @@ #include #include "common/common.h" +#include "common/uuid.h" #include "common/assert.h" #include #include @@ -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; diff --git a/src/plugins/ctf/common/metadata/decoder-packetized-file-stream-to-buf.c b/src/plugins/ctf/common/metadata/decoder-packetized-file-stream-to-buf.c index 29986fab..e14c54d7 100644 --- a/src/plugins/ctf/common/metadata/decoder-packetized-file-stream-to-buf.c +++ b/src/plugins/ctf/common/metadata/decoder-packetized-file-stream-to-buf.c @@ -23,7 +23,7 @@ #include #include #include "common/assert.h" -#include "compat/uuid.h" +#include "common/uuid.h" #include "compat/memstream.h" #include #include @@ -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; } diff --git a/src/plugins/ctf/common/metadata/decoder.c b/src/plugins/ctf/common/metadata/decoder.c index a690ca71..6215403c 100644 --- a/src/plugins/ctf/common/metadata/decoder.c +++ b/src/plugins/ctf/common/metadata/decoder.c @@ -23,7 +23,7 @@ #include #include #include "common/assert.h" -#include "compat/uuid.h" +#include "common/uuid.h" #include "compat/memstream.h" #include #include @@ -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; diff --git a/src/plugins/ctf/common/metadata/visitor-generate-ir.c b/src/plugins/ctf/common/metadata/visitor-generate-ir.c index d52104f8..56e5b706 100644 --- a/src/plugins/ctf/common/metadata/visitor-generate-ir.c +++ b/src/plugins/ctf/common/metadata/visitor-generate-ir.c @@ -43,7 +43,7 @@ #include #include #include "common/common.h" -#include "compat/uuid.h" +#include "common/uuid.h" #include "compat/endian.h" #include @@ -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; diff --git a/src/plugins/ctf/fs-sink/fs-sink-ctf-meta.h b/src/plugins/ctf/fs-sink/fs-sink-ctf-meta.h index 7585ac74..0d26a32e 100644 --- a/src/plugins/ctf/fs-sink/fs-sink-ctf-meta.h +++ b/src/plugins/ctf/fs-sink/fs-sink-ctf-meta.h @@ -18,7 +18,7 @@ #include #include "common/common.h" #include "common/assert.h" -#include "compat/uuid.h" +#include "common/uuid.h" #include #include #include @@ -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; } diff --git a/src/plugins/ctf/fs-sink/fs-sink-stream.c b/src/plugins/ctf/fs-sink/fs-sink-stream.c index d622a9c3..a6f39a37 100644 --- a/src/plugins/ctf/fs-sink/fs-sink-stream.c +++ b/src/plugins/ctf/fs-sink/fs-sink-stream.c @@ -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) { diff --git a/src/plugins/ctf/fs-sink/translate-ctf-ir-to-tsdl.c b/src/plugins/ctf/fs-sink/translate-ctf-ir-to-tsdl.c index 4fdd6241..99739e2f 100644 --- a/src/plugins/ctf/fs-sink/translate-ctf-ir-to-tsdl.c +++ b/src/plugins/ctf/fs-sink/translate-ctf-ir-to-tsdl.c @@ -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 diff --git a/src/plugins/ctf/fs-src/fs.c b/src/plugins/ctf/fs-src/fs.c index 4ad18539..fb5fa1c5 100644 --- a/src/plugins/ctf/fs-src/fs.c +++ b/src/plugins/ctf/fs-src/fs.c @@ -32,7 +32,7 @@ #include "common/common.h" #include -#include "compat/uuid.h" +#include "common/uuid.h" #include #include "common/assert.h" #include @@ -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: diff --git a/src/plugins/ctf/fs-src/metadata.c b/src/plugins/ctf/fs-src/metadata.c index 94ff889a..63b7f0ed 100644 --- a/src/plugins/ctf/fs-src/metadata.c +++ b/src/plugins/ctf/fs-src/metadata.c @@ -34,7 +34,7 @@ #include #include "common/assert.h" #include -#include "compat/uuid.h" +#include "common/uuid.h" #include "compat/memstream.h" #include diff --git a/src/plugins/text/details/write.c b/src/plugins/text/details/write.c index e79e7e03..788416d8 100644 --- a/src/plugins/text/details/write.c +++ b/src/plugins/text/details/write.c @@ -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)); } diff --git a/src/plugins/text/pretty/print.c b/src/plugins/text/pretty/print.c index 80651f15..9645827e 100644 --- a/src/plugins/text/pretty/print.c +++ b/src/plugins/text/pretty/print.c @@ -26,6 +26,7 @@ #include #include "compat/bitfield.h" #include "common/common.h" +#include "common/uuid.h" #include "compat/time.h" #include "common/assert.h" #include @@ -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) "); } diff --git a/src/plugins/utils/muxer/muxer.c b/src/plugins/utils/muxer/muxer.c index 37d00608..e1603fed 100644 --- a/src/plugins/utils/muxer/muxer.c +++ b/src/plugins/utils/muxer/muxer.c @@ -26,7 +26,7 @@ #include "plugins/comp-logging.h" #include "common/macros.h" -#include "compat/uuid.h" +#include "common/uuid.h" #include #include #include @@ -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; diff --git a/tests/Makefile.am b/tests/Makefile.am index 00f69f51..877ec1c7 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -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 diff --git a/tests/ctf-writer/ctf_writer.c b/tests/ctf-writer/ctf_writer.c index 1ed4cc67..81dc58d7 100644 --- a/tests/ctf-writer/ctf_writer.c +++ b/tests/ctf-writer/ctf_writer.c @@ -38,6 +38,7 @@ #include "compat/stdio.h" #include #include "common/assert.h" +#include "common/uuid.h" #include #include "tap/tap.h" #include @@ -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, diff --git a/tests/lib/Makefile.am b/tests/lib/Makefile.am index efbb6c86..ce8d17a7 100644 --- a/tests/lib/Makefile.am +++ b/tests/lib/Makefile.am @@ -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 index 00000000..3aef05ed --- /dev/null +++ b/tests/lib/test_bt_uuid.c @@ -0,0 +1,192 @@ +/* + * test_bt_uuid.c + * + * Copyright 2019 Michael Jeanson + * + * 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 +#include + +#include + +#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(); +} -- 2.34.1