[ltt-dev] [UST PATCH] Add a TRACEPOINT test program

Nils Carlson nils.carlson at ericsson.com
Mon Oct 11 09:38:15 EDT 2010


Acked and pulled.

/Nils

On Fri, 1 Oct 2010, David Goulet wrote:

> This test is aimed at testing different tracepoint case and
> be used to ensure no bugs are added.
>
> Complete description of the test in tracepoint_test.c
>
> Signed-off-by: David Goulet <david.goulet at polymtl.ca>
> ---
> configure.ac                       |    1 +
> tests/Makefile.am                  |    2 +-
> tests/runtests                     |    2 +
> tests/tracepoint/Makefile.am       |    9 +++
> tests/tracepoint/run               |   17 ++++++
> tests/tracepoint/tracepoint_test.c |  107 ++++++++++++++++++++++++++++++++++++
> tests/tracepoint/tracepoint_test.h |    8 +++
> 7 files changed, 145 insertions(+), 1 deletions(-)
> create mode 100644 tests/tracepoint/Makefile.am
> create mode 100755 tests/tracepoint/run
> create mode 100644 tests/tracepoint/tracepoint_test.c
> create mode 100644 tests/tracepoint/tracepoint_test.h
>
> diff --git a/configure.ac b/configure.ac
> index 10a02e0..42982c5 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -122,6 +122,7 @@ AC_CONFIG_FILES([
> 	tests/dlopen/Makefile
> 	tests/same_line_marker/Makefile
> 	tests/trace_event/Makefile
> +	tests/tracepoint/Makefile
> 	tests/register_test/Makefile
> 	libustinstr-malloc/Makefile
> 	libustfork/Makefile
> diff --git a/tests/Makefile.am b/tests/Makefile.am
> index 1d31c3f..69801c0 100644
> --- a/tests/Makefile.am
> +++ b/tests/Makefile.am
> @@ -1,3 +1,3 @@
> -SUBDIRS = hello hello2 basic basic_long fork simple_include snprintf test-nevents test-libustinstr-malloc dlopen same_line_marker trace_event register_test
> +SUBDIRS = hello hello2 basic basic_long fork simple_include snprintf test-nevents test-libustinstr-malloc dlopen same_line_marker trace_event register_test tracepoint
>
> dist_noinst_SCRIPTS = test_loop runtests trace_matches
> diff --git a/tests/runtests b/tests/runtests
> index 602fc1e..ff00253 100755
> --- a/tests/runtests
> +++ b/tests/runtests
> @@ -43,6 +43,8 @@ simple_harness_run dlopen/dlopen.sh
>
> simple_harness_run same_line_marker/same_line_marker.sh
>
> +simple_harness_run tracepoint/run
> +
> echo "************************************"
> if [[ $tests_failed -eq 0 ]]; then
>     echo "$0: All passed"
> diff --git a/tests/tracepoint/Makefile.am b/tests/tracepoint/Makefile.am
> new file mode 100644
> index 0000000..37c8f20
> --- /dev/null
> +++ b/tests/tracepoint/Makefile.am
> @@ -0,0 +1,9 @@
> +AM_CPPFLAGS = -I$(top_srcdir)/include
> +
> +noinst_PROGRAMS = tracepoint_test
> +tracepoint_test_SOURCES = tracepoint_test.c tracepoint_test.h
> +tracepoint_test_LDADD = $(top_builddir)/libust/libust.la $(top_builddir)/libust-initializer.o
> +
> +CFLAGS_tracepoint_test.o = -I$(src)
> +noinst_SCRIPTS = run
> +EXTRA_DIST = run
> diff --git a/tests/tracepoint/run b/tests/tracepoint/run
> new file mode 100755
> index 0000000..0da9864
> --- /dev/null
> +++ b/tests/tracepoint/run
> @@ -0,0 +1,17 @@
> +#!/bin/bash
> +
> +TESTDIR=$(dirname $0)/..
> +
> +source $TESTDIR/test_functions.sh
> +source $TESTDIR/tap.sh
> +
> +starttest "Testing Tracepoints"
> +plan_tests 6
> +
> +okx usttrace $TESTDIR/tracepoint/tracepoint_test
> +trace_loc=$(usttrace -W)
> +trace_matches -N "probe1" -n "5" "probe = 13" $trace_loc
> +trace_matches -N "probe2" -n "5" "probe = 42" $trace_loc
> +trace_matches -N "probe3" -n "1" "probe = \"probe3\"" $trace_loc
> +trace_matches -N "probe4" -n "100" "probe4 = 42" $trace_loc
> +check_trace_logs "$trace_loc"
> diff --git a/tests/tracepoint/tracepoint_test.c b/tests/tracepoint/tracepoint_test.c
> new file mode 100644
> index 0000000..cd3939c
> --- /dev/null
> +++ b/tests/tracepoint/tracepoint_test.c
> @@ -0,0 +1,107 @@
> +/* Copyright (C) 2010 David Goulet <david.goulet at polymtl.ca>
> + *
> + * 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; either
> + * version 2.1 of the License, or (at your option) any later version.
> + *
> + * 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
> + */
> +
> +/*
> + * This test is aimed at testing tracepoint *with* trace_mark :
> + *
> + * 1) tracepoint named : "ust_event"
> + * 	-) Probe 1 registered and recording the value 13 (x5)
> + * 	-) Probe 2 registered and recording the value 42 (x5)
> + * 	-) Probe 3 registered and recording the payload of the struct message
> + * 	but using a *different* tracepoint (event_msg)
> + *
> + * 2) tracepoint named : "ust_event2"
> + * 	-) Probe 4 registered and recording the value 42 (x100)
> + */
> +
> +#include <stdio.h>
> +#include <ust/marker.h>
> +#include "tracepoint_test.h"
> +
> +DEFINE_TRACE(ust_event);
> +DEFINE_TRACE(ust_event2);
> +
> +static struct message msg_probe3 = {
> +	.payload = "probe3",
> +};
> +
> +/*
> + * Probe 4 --> ust_event2
> + * 	Will record 100 times the value 42
> + */
> +void tp_probe4(void *data, unsigned int p4)
> +{
> +	int i;
> +	for (i = 0; i < 100; i++) {
> +		trace_mark_tp(ust, event2, ust_event2, tp_probe4, "probe4 %u", p4);
> +	}
> +}
> +
> +/*
> + * Probe 3 --> ust_event *and* event_msg (from inside)
> + * 	Will record the payload of msg_prob3 struct
> + * 	from the data pointer of the probe
> + */
> +void tp_probe3(void *data, unsigned int p3)
> +{
> +	struct message *msg;
> +	msg = (struct message*) data;
> +	trace_mark_tp(ust, event_msg, ust_event_msg,
> +			tp_probe3, "probe %s", msg->payload);
> +}
> +
> +/*
> + * Probe 2 --> ust_event
> + * 	Will record 5 times the number 13
> + */
> +void tp_probe2(void *data, unsigned int p2)
> +{
> +	int i;
> +	for (i = 0; i < 5; i++) {
> +		trace_mark_tp(ust, event, ust_event, tp_probe2, "probe %u", 13);
> +	}
> +}
> +
> +/*
> + * Probe 1 --> ust_event
> + * 	Will record 5 times the unsigned int v = 42
> + */
> +void tp_probe(void *data, unsigned int p1)
> +{
> +	int i;
> +	for (i = 0; i < 5; i++) {
> +		trace_mark_tp(ust, event, ust_event, tp_probe, "probe %u", p1);
> +	}
> +}
> +
> +static void __attribute__((constructor)) init()
> +{
> +	register_trace_ust_event(tp_probe, NULL);
> +	register_trace_ust_event(tp_probe2, NULL);
> +	register_trace_ust_event(tp_probe3, &msg_probe3);
> +	register_trace_ust_event2(tp_probe4, NULL);
> +}
> +
> +int main(int argc, char **argv) {
> +	unsigned int v = 42;
> +	/* Tracepoint 1 : ust_event */
> +	trace_ust_event(v);
> +	/* Tracepoint 2 : ust_event2 */
> +	trace_ust_event2(v);
> +
> +	return 0;
> +}
> diff --git a/tests/tracepoint/tracepoint_test.h b/tests/tracepoint/tracepoint_test.h
> new file mode 100644
> index 0000000..6b4dcdb
> --- /dev/null
> +++ b/tests/tracepoint/tracepoint_test.h
> @@ -0,0 +1,8 @@
> +#include <ust/tracepoint.h>
> +
> +DECLARE_TRACE(ust_event, TP_PROTO(unsigned int v), TP_ARGS(v));
> +DECLARE_TRACE(ust_event2, TP_PROTO(unsigned int v), TP_ARGS(v));
> +
> +struct message {
> +	char *payload;
> +};
> -- 
> 1.7.3
>
>
> _______________________________________________
> ltt-dev mailing list
> ltt-dev at lists.casi.polymtl.ca
> http://lists.casi.polymtl.ca/cgi-bin/mailman/listinfo/ltt-dev
>




More information about the lttng-dev mailing list