X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=tests%2Funit%2Ftest_ust_data.cpp;h=cdd9cbd66dd033a3e6b60486562a6107a6722c4f;hb=a9cfc0f36bf8ade64df08392b03a9f15409dc01b;hp=a6dfba4293a4c2192f13c070d6672aab7eb592cb;hpb=7966af5763c4aaca39df9bbfa9277ff15715c720;p=lttng-tools.git diff --git a/tests/unit/test_ust_data.cpp b/tests/unit/test_ust_data.cpp index a6dfba429..cdd9cbd66 100644 --- a/tests/unit/test_ust_data.cpp +++ b/tests/unit/test_ust_data.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2011 David Goulet + * Copyright (C) 2011 EfficiOS Inc. * * SPDX-License-Identifier: GPL-2.0-only * @@ -13,12 +13,12 @@ #include #include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include #include @@ -32,7 +32,7 @@ /* Number of TAP tests in this file */ #define NUM_TESTS 16 -DEFINE_LTTNG_UST_SIGBUS_STATE(); +LTTNG_EXPORT DEFINE_LTTNG_UST_SIGBUS_STATE(); static const char alphanum[] = "0123456789" @@ -77,6 +77,7 @@ static void test_create_one_ust_session(void) "Validate UST session"); trace_ust_destroy_session(usess); + trace_ust_free_session(usess); } static void test_create_ust_channel(void) @@ -143,6 +144,7 @@ static void test_create_ust_event(void) static void test_create_ust_event_exclusion(void) { + int copy_ret; enum lttng_error_code ret; struct ltt_ust_event *event; struct lttng_event ev; @@ -164,7 +166,7 @@ static void test_create_ust_event_exclusion(void) ev.loglevel_type = LTTNG_EVENT_LOGLEVEL_ALL; /* set up an exclusion set */ - exclusion = (lttng_event_exclusion *) zmalloc(sizeof(*exclusion) + + exclusion = zmalloc(sizeof(*exclusion) + LTTNG_SYMBOL_NAME_LEN * exclusion_count); ok(exclusion != NULL, "Create UST exclusion"); if (!exclusion) { @@ -175,16 +177,16 @@ static void test_create_ust_event_exclusion(void) exclusion->count = exclusion_count; random_name = get_random_string(); strncpy(LTTNG_EVENT_EXCLUSION_NAME_AT(exclusion, 0), random_name, - LTTNG_SYMBOL_NAME_LEN); + LTTNG_SYMBOL_NAME_LEN - 1); strncpy(LTTNG_EVENT_EXCLUSION_NAME_AT(exclusion, 1), random_name, - LTTNG_SYMBOL_NAME_LEN); + LTTNG_SYMBOL_NAME_LEN - 1); ret = trace_ust_create_event(&ev, NULL, NULL, exclusion, false, &event); exclusion = NULL; ok(ret != LTTNG_OK, "Create UST event with identical exclusion names fails"); - exclusion = (lttng_event_exclusion *) zmalloc(sizeof(*exclusion) + + exclusion = zmalloc(sizeof(*exclusion) + LTTNG_SYMBOL_NAME_LEN * exclusion_count); ok(exclusion != NULL, "Create UST exclusion"); if (!exclusion) { @@ -192,7 +194,7 @@ static void test_create_ust_event_exclusion(void) goto end; } - exclusion_copy = (lttng_event_exclusion *) zmalloc(sizeof(*exclusion) + + exclusion_copy = zmalloc(sizeof(*exclusion) + LTTNG_SYMBOL_NAME_LEN * exclusion_count); if (!exclusion_copy) { skip(2, "zmalloc failed"); @@ -206,16 +208,24 @@ static void test_create_ust_event_exclusion(void) */ exclusion->count = exclusion_count; - strncpy(LTTNG_EVENT_EXCLUSION_NAME_AT(exclusion, 0), - get_random_string(), LTTNG_SYMBOL_NAME_LEN); - strncpy(LTTNG_EVENT_EXCLUSION_NAME_AT(exclusion, 1), - get_random_string(), LTTNG_SYMBOL_NAME_LEN); + copy_ret = lttng_strncpy(LTTNG_EVENT_EXCLUSION_NAME_AT(exclusion, 0), + get_random_string(), + sizeof(LTTNG_EVENT_EXCLUSION_NAME_AT(exclusion, 0))); + LTTNG_ASSERT(copy_ret == 0); + copy_ret = lttng_strncpy(LTTNG_EVENT_EXCLUSION_NAME_AT(exclusion, 1), + get_random_string(), + sizeof(LTTNG_EVENT_EXCLUSION_NAME_AT(exclusion, 1))); + LTTNG_ASSERT(copy_ret == 0); exclusion_copy->count = exclusion_count; - strncpy(LTTNG_EVENT_EXCLUSION_NAME_AT(exclusion_copy, 0), - LTTNG_EVENT_EXCLUSION_NAME_AT(exclusion, 0), LTTNG_SYMBOL_NAME_LEN); - strncpy(LTTNG_EVENT_EXCLUSION_NAME_AT(exclusion_copy, 1), - LTTNG_EVENT_EXCLUSION_NAME_AT(exclusion, 1), LTTNG_SYMBOL_NAME_LEN); + copy_ret = lttng_strncpy(LTTNG_EVENT_EXCLUSION_NAME_AT(exclusion_copy, 0), + LTTNG_EVENT_EXCLUSION_NAME_AT(exclusion, 0), + sizeof(LTTNG_EVENT_EXCLUSION_NAME_AT(exclusion_copy, 0))); + LTTNG_ASSERT(copy_ret == 0); + copy_ret = lttng_strncpy(LTTNG_EVENT_EXCLUSION_NAME_AT(exclusion_copy, 1), + LTTNG_EVENT_EXCLUSION_NAME_AT(exclusion, 1), + sizeof(LTTNG_EVENT_EXCLUSION_NAME_AT(exclusion_copy, 1))); + LTTNG_ASSERT(copy_ret == 0); ret = trace_ust_create_event(&ev, NULL, NULL, exclusion, false, &event); exclusion = NULL; @@ -263,7 +273,7 @@ static void test_create_ust_context(void) free(uctx); } -int main(int argc, char **argv) +int main(void) { plan_tests(NUM_TESTS);