X-Git-Url: https://git.lttng.org/?a=blobdiff_plain;f=tests%2Fcompile%2Ftest-app-ctx%2Fhello.c;h=26cca016df7d4c0a17f661bbac0fec34eb1c7a59;hb=9d315d6d74aac2986b10d708c864d152a0febec7;hp=e9e45ec7c51db46aae588276d14085322136ac06;hpb=dbe6ade0ba17270b2cb119b9961bbb7e48ce4733;p=lttng-ust.git diff --git a/tests/compile/test-app-ctx/hello.c b/tests/compile/test-app-ctx/hello.c index e9e45ec7..26cca016 100644 --- a/tests/compile/test-app-ctx/hello.c +++ b/tests/compile/test-app-ctx/hello.c @@ -1,20 +1,8 @@ /* - * Copyright (C) 2009 Pierre-Marc Fournier - * Copyright (C) 2011 Mathieu Desnoyers + * SPDX-License-Identifier: LGPL-2.1-only * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; version 2.1 of - * the License. - * - * This library 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 - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Copyright (C) 2009 Pierre-Marc Fournier + * Copyright (C) 2011 Mathieu Desnoyers */ #include @@ -40,67 +28,68 @@ struct mmsghdr; #define TRACEPOINT_DEFINE #include "ust_tests_hello.h" -/* Internal header. */ #include -#include -#include +#include +/* Internal header. */ +#include static __thread unsigned int test_count; +static void test_inc_count(void) { test_count++; } static -size_t test_get_size(struct lttng_ctx_field *field, size_t offset) +size_t test_get_size(void *priv __attribute__((unused)), size_t offset) { int sel = test_count % _NR_LTTNG_UST_DYNAMIC_TYPES; size_t size = 0; - size += lib_ring_buffer_align(offset, lttng_alignof(char)); + size += lttng_ust_lib_ring_buffer_align(offset, lttng_ust_rb_alignof(char)); size += sizeof(char); /* tag */ switch (sel) { case LTTNG_UST_DYNAMIC_TYPE_NONE: break; case LTTNG_UST_DYNAMIC_TYPE_S8: - size += lib_ring_buffer_align(offset, lttng_alignof(int8_t)); + size += lttng_ust_lib_ring_buffer_align(offset, lttng_ust_rb_alignof(int8_t)); size += sizeof(int8_t); /* variant */ break; case LTTNG_UST_DYNAMIC_TYPE_S16: - size += lib_ring_buffer_align(offset, lttng_alignof(int16_t)); + size += lttng_ust_lib_ring_buffer_align(offset, lttng_ust_rb_alignof(int16_t)); size += sizeof(int16_t); /* variant */ break; case LTTNG_UST_DYNAMIC_TYPE_S32: - size += lib_ring_buffer_align(offset, lttng_alignof(int32_t)); + size += lttng_ust_lib_ring_buffer_align(offset, lttng_ust_rb_alignof(int32_t)); size += sizeof(int32_t); /* variant */ break; case LTTNG_UST_DYNAMIC_TYPE_S64: - size += lib_ring_buffer_align(offset, lttng_alignof(int64_t)); + size += lttng_ust_lib_ring_buffer_align(offset, lttng_ust_rb_alignof(int64_t)); size += sizeof(int64_t); /* variant */ break; case LTTNG_UST_DYNAMIC_TYPE_U8: - size += lib_ring_buffer_align(offset, lttng_alignof(uint8_t)); + size += lttng_ust_lib_ring_buffer_align(offset, lttng_ust_rb_alignof(uint8_t)); size += sizeof(uint8_t); /* variant */ break; case LTTNG_UST_DYNAMIC_TYPE_U16: - size += lib_ring_buffer_align(offset, lttng_alignof(uint16_t)); + size += lttng_ust_lib_ring_buffer_align(offset, lttng_ust_rb_alignof(uint16_t)); size += sizeof(uint16_t); /* variant */ break; case LTTNG_UST_DYNAMIC_TYPE_U32: - size += lib_ring_buffer_align(offset, lttng_alignof(uint32_t)); + size += lttng_ust_lib_ring_buffer_align(offset, lttng_ust_rb_alignof(uint32_t)); size += sizeof(uint32_t); /* variant */ break; case LTTNG_UST_DYNAMIC_TYPE_U64: - size += lib_ring_buffer_align(offset, lttng_alignof(uint64_t)); + size += lttng_ust_lib_ring_buffer_align(offset, lttng_ust_rb_alignof(uint64_t)); size += sizeof(uint64_t); /* variant */ break; case LTTNG_UST_DYNAMIC_TYPE_FLOAT: - size += lib_ring_buffer_align(offset, lttng_alignof(float)); + size += lttng_ust_lib_ring_buffer_align(offset, lttng_ust_rb_alignof(float)); size += sizeof(float); /* variant */ break; case LTTNG_UST_DYNAMIC_TYPE_DOUBLE: - size += lib_ring_buffer_align(offset, lttng_alignof(double)); + size += lttng_ust_lib_ring_buffer_align(offset, lttng_ust_rb_alignof(double)); size += sizeof(double); /* variant */ break; case LTTNG_UST_DYNAMIC_TYPE_STRING: @@ -114,15 +103,14 @@ size_t test_get_size(struct lttng_ctx_field *field, size_t offset) } static -void test_record(struct lttng_ctx_field *field, +void test_record(void *priv __attribute__((unused)), struct lttng_ust_lib_ring_buffer_ctx *ctx, - struct lttng_channel *chan) + struct lttng_ust_channel_buffer *lttng_chan_buf) { int sel = test_count % _NR_LTTNG_UST_DYNAMIC_TYPES; char sel_char = (char) sel; - lib_ring_buffer_align_ctx(ctx, lttng_alignof(char)); - chan->ops->event_write(ctx, &sel_char, sizeof(sel_char)); + lttng_chan_buf->ops->event_write(ctx, &sel_char, sizeof(sel_char), lttng_ust_rb_alignof(char)); switch (sel) { case LTTNG_UST_DYNAMIC_TYPE_NONE: break; @@ -130,86 +118,76 @@ void test_record(struct lttng_ctx_field *field, { int8_t v = -8; - lib_ring_buffer_align_ctx(ctx, lttng_alignof(v)); - chan->ops->event_write(ctx, &v, sizeof(v)); + lttng_chan_buf->ops->event_write(ctx, &v, sizeof(v), lttng_ust_rb_alignof(v)); break; } case LTTNG_UST_DYNAMIC_TYPE_S16: { int16_t v = -16; - lib_ring_buffer_align_ctx(ctx, lttng_alignof(v)); - chan->ops->event_write(ctx, &v, sizeof(v)); + lttng_chan_buf->ops->event_write(ctx, &v, sizeof(v), lttng_ust_rb_alignof(v)); break; } case LTTNG_UST_DYNAMIC_TYPE_S32: { int32_t v = -32; - lib_ring_buffer_align_ctx(ctx, lttng_alignof(v)); - chan->ops->event_write(ctx, &v, sizeof(v)); + lttng_chan_buf->ops->event_write(ctx, &v, sizeof(v), lttng_ust_rb_alignof(v)); break; } case LTTNG_UST_DYNAMIC_TYPE_S64: { int64_t v = -64; - lib_ring_buffer_align_ctx(ctx, lttng_alignof(v)); - chan->ops->event_write(ctx, &v, sizeof(v)); + lttng_chan_buf->ops->event_write(ctx, &v, sizeof(v), lttng_ust_rb_alignof(v)); break; } case LTTNG_UST_DYNAMIC_TYPE_U8: { uint8_t v = 8; - lib_ring_buffer_align_ctx(ctx, lttng_alignof(v)); - chan->ops->event_write(ctx, &v, sizeof(v)); + lttng_chan_buf->ops->event_write(ctx, &v, sizeof(v), lttng_ust_rb_alignof(v)); break; } case LTTNG_UST_DYNAMIC_TYPE_U16: { uint16_t v = 16; - lib_ring_buffer_align_ctx(ctx, lttng_alignof(v)); - chan->ops->event_write(ctx, &v, sizeof(v)); + lttng_chan_buf->ops->event_write(ctx, &v, sizeof(v), lttng_ust_rb_alignof(v)); break; } case LTTNG_UST_DYNAMIC_TYPE_U32: { uint32_t v = 32; - lib_ring_buffer_align_ctx(ctx, lttng_alignof(v)); - chan->ops->event_write(ctx, &v, sizeof(v)); + lttng_chan_buf->ops->event_write(ctx, &v, sizeof(v), lttng_ust_rb_alignof(v)); break; } case LTTNG_UST_DYNAMIC_TYPE_U64: { uint64_t v = 64; - lib_ring_buffer_align_ctx(ctx, lttng_alignof(v)); - chan->ops->event_write(ctx, &v, sizeof(v)); + lttng_chan_buf->ops->event_write(ctx, &v, sizeof(v), lttng_ust_rb_alignof(v)); break; } case LTTNG_UST_DYNAMIC_TYPE_FLOAT: { float f = 22322.0; - lib_ring_buffer_align_ctx(ctx, lttng_alignof(f)); - chan->ops->event_write(ctx, &f, sizeof(f)); + lttng_chan_buf->ops->event_write(ctx, &f, sizeof(f), lttng_ust_rb_alignof(f)); break; } case LTTNG_UST_DYNAMIC_TYPE_DOUBLE: { double d = 2.0; - lib_ring_buffer_align_ctx(ctx, lttng_alignof(d)); - chan->ops->event_write(ctx, &d, sizeof(d)); + lttng_chan_buf->ops->event_write(ctx, &d, sizeof(d), lttng_ust_rb_alignof(d)); break; } case LTTNG_UST_DYNAMIC_TYPE_STRING: { const char *str = "teststr"; - chan->ops->event_write(ctx, str, strlen(str) + 1); + lttng_chan_buf->ops->event_write(ctx, str, strlen(str) + 1, 1); break; } default: @@ -218,8 +196,8 @@ void test_record(struct lttng_ctx_field *field, } static -void test_get_value(struct lttng_ctx_field *field, - struct lttng_ctx_value *value) +void test_get_value(void *priv __attribute__((unused)), + struct lttng_ust_ctx_value *value) { int sel = test_count % _NR_LTTNG_UST_DYNAMIC_TYPES; @@ -240,16 +218,16 @@ void test_get_value(struct lttng_ctx_field *field, value->u.s64 = -64; break; case LTTNG_UST_DYNAMIC_TYPE_U8: - value->u.s64 = 8; + value->u.u64 = 8; break; case LTTNG_UST_DYNAMIC_TYPE_U16: - value->u.s64 = 16; + value->u.u64 = 16; break; case LTTNG_UST_DYNAMIC_TYPE_U32: - value->u.s64 = 32; + value->u.u64 = 32; break; case LTTNG_UST_DYNAMIC_TYPE_U64: - value->u.s64 = 64; + value->u.u64 = 64; break; case LTTNG_UST_DYNAMIC_TYPE_FLOAT: value->u.d = 22322.0; @@ -265,19 +243,23 @@ void test_get_value(struct lttng_ctx_field *field, } } +static char myprovider_name[] = "$app.myprovider"; struct lttng_ust_context_provider myprovider = { - .name = "$app.myprovider", + .struct_size = sizeof(struct lttng_ust_context_provider), + .name = myprovider_name, .get_size = test_get_size, .record = test_record, .get_value = test_get_value, }; -void inthandler(int sig) +static +void inthandler(int sig __attribute__((unused))) { printf("in SIGUSR1 handler\n"); tracepoint(ust_tests_hello, tptest_sighandler); } +static int init_int_handler(void) { int result; @@ -305,10 +287,9 @@ int init_int_handler(void) return 0; } -void test_inc_count(void); - int main(int argc, char **argv) { + struct lttng_ust_registered_context_provider *reg_provider; int i, netint; long values[] = { 1, 2, 3 }; char text[10] = "test"; @@ -322,7 +303,8 @@ int main(int argc, char **argv) if (argc == 2) delay = atoi(argv[1]); - if (lttng_ust_context_provider_register(&myprovider)) + reg_provider = lttng_ust_context_provider_register(&myprovider); + if (!reg_provider) abort(); fprintf(stderr, "Hello, World!\n"); @@ -337,7 +319,7 @@ int main(int argc, char **argv) test_inc_count(); //usleep(100000); } - lttng_ust_context_provider_unregister(&myprovider); + lttng_ust_context_provider_unregister(reg_provider); fprintf(stderr, " done.\n"); return 0; }