All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH lttng-tools 2/5] Tests: Add a test for invalid filters
       [not found] <1350412403-9974-1-git-send-email-christian.babeux@efficios.com>
@ 2012-10-16 18:33 ` Christian Babeux
  2012-10-16 18:33 ` [PATCH lttng-tools 3/5] Tests: Add a trace statistics utility Christian Babeux
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 4+ messages in thread
From: Christian Babeux @ 2012-10-16 18:33 UTC (permalink / raw)
  To: dgoulet; +Cc: lttng-dev

This test validate that an invalid filter (unmatched parenthesis,
field dereferences, unsupported ops, etc.) are correctly flagged
as such.

Signed-off-by: Christian Babeux <christian.babeux@efficios.com>
---
 tests/tools/filtering/Makefile.am     |   4 +-
 tests/tools/filtering/invalid-filters | 135 ++++++++++++++++++++++++++++++++++
 2 files changed, 137 insertions(+), 2 deletions(-)
 create mode 100755 tests/tools/filtering/invalid-filters

diff --git a/tests/tools/filtering/Makefile.am b/tests/tools/filtering/Makefile.am
index 62f7099..5f3423a 100644
--- a/tests/tools/filtering/Makefile.am
+++ b/tests/tools/filtering/Makefile.am
@@ -1,2 +1,2 @@
-noinst_SCRIPTS = unsupported-ops
-EXTRA_DIST = unsupported-ops
+noinst_SCRIPTS = unsupported-ops invalid-filters
+EXTRA_DIST = unsupported-ops invalid-filters
diff --git a/tests/tools/filtering/invalid-filters b/tests/tools/filtering/invalid-filters
new file mode 100755
index 0000000..d0777e5
--- /dev/null
+++ b/tests/tools/filtering/invalid-filters
@@ -0,0 +1,135 @@
+#!/bin/bash
+#
+# Copyright (C) - 2012 Christian Babeux <christian.babeux@efficios.com>
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License, version 2 only, as
+# published by the Free Software Foundation.
+#
+# 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.
+
+TEST_DESC="Filtering - Invalid filters"
+
+CURDIR=$(dirname $0)/
+TESTDIR=$CURDIR/../..
+LTTNG_BIN="lttng"
+SESSION_NAME="filter-invalid"
+EVENT_NAME="bogus"
+ENABLE_EVENT_STDERR="/tmp/invalid-filters-stderr"
+TRACE_PATH=$(mktemp -d)
+
+source $TESTDIR/utils.sh
+
+print_test_banner "$TEST_DESC"
+
+function enable_ust_lttng_event_filter
+{
+	sess_name="$1"
+	event_name="$2"
+	filter="$3"
+	echo -n "Enabling lttng event with filtering and invalid filter "
+
+	$TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event $event_name -s $sess_name -u --filter "$filter" 2> $ENABLE_EVENT_STDERR 1> /dev/null
+
+	# Enable must fail
+	if [ $? -eq 0 ]; then
+		print_fail
+		return 1
+	else
+		print_ok
+		return 0
+	fi
+}
+
+function test_invalid_filter
+{
+	test_invalid_filter="$1"
+
+	echo ""
+	echo -e "=== Testing filter expression with invalid filter"
+	echo -e "Filter: $test_invalid_filter"
+
+	# Create session
+	create_lttng_session $SESSION_NAME $TRACE_PATH
+
+	# Apply filter
+	enable_ust_lttng_event_filter $SESSION_NAME $EVENT_NAME "$test_invalid_filter"
+
+	# Destroy session
+	destroy_lttng_session $SESSION_NAME
+}
+
+function test_bytecode_limit
+{
+	# Current bytecode limitation is 65536 bytes long.
+	# Generate a huge bytecode with some perl-fu
+	BYTECODE_LIMIT=`perl -e 'print "intfield" . " && 1" x5460'`
+
+	echo ""
+	echo -e "=== Testing filter bytecode limits (64KiB)"
+
+	# Create session
+	create_lttng_session $SESSION_NAME $TRACE_PATH
+
+	# Apply filter
+	enable_ust_lttng_event_filter $SESSION_NAME $EVENT_NAME "$BYTECODE_LIMIT"
+
+	# Destroy session
+	destroy_lttng_session $SESSION_NAME
+}
+
+IFS=$'\n'
+INVALID_FILTERS=(
+		# Unsupported ops
+		"intfield*1"
+		"intfield/1"
+		"intfield+1"
+		"intfield-1"
+		"intfield>>1"
+		"intfield<<1"
+		"intfield&1"
+		"intfield|1"
+		"intfield^1"
+		"~intfield"
+		"1+11111-3333+1"
+		"(1+2)*(55*666)"
+		"1+2*55*666"
+		"asdf + 1 > 1"
+		"asdfas < 2332 || asdf + 1 > 1"
+		"!+-+++-------+++++++++++-----!!--!44+1"
+		"aaa||(gg)+(333----1)"
+		"1+1"
+		# Unmatched parenthesis
+		"((((((((((((((intfield)))))))))))))"
+		'0 || ("abc" != "def")) && (3 < 4)'
+		# Field dereference
+		"a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a.a"
+		"a->"
+		"a-->a"
+		"a->a"
+		"a.b.c->d.e.f+1"
+		"!a.f.d"
+		"asdf.asdfsd.sadf < 4"
+		"asdfasdf->asdfasdf < 2"
+		)
+
+start_lttng_sessiond
+for FILTER in ${INVALID_FILTERS[@]};
+do
+	test_invalid_filter "$FILTER"
+done
+
+test_bytecode_limit
+
+unset IFS
+stop_lttng_sessiond
+
+rm -f $ENABLE_EVENT_STDERR
+rm -rf $TRACE_PATH
-- 
1.7.12.2

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH lttng-tools 3/5] Tests: Add a trace statistics utility
       [not found] <1350412403-9974-1-git-send-email-christian.babeux@efficios.com>
  2012-10-16 18:33 ` [PATCH lttng-tools 2/5] Tests: Add a test for invalid filters Christian Babeux
@ 2012-10-16 18:33 ` Christian Babeux
  2012-10-16 18:33 ` [PATCH lttng-tools 4/5] Tests: Add a test for valid filters Christian Babeux
  2012-10-16 18:33 ` [PATCH lttng-tools 5/5] Tests: Add filtering tests to configure Christian Babeux
  3 siblings, 0 replies; 4+ messages in thread
From: Christian Babeux @ 2012-10-16 18:33 UTC (permalink / raw)
  To: dgoulet; +Cc: lttng-dev

The babelstats script output statistics on fields values for
a particular tracepoint. At the moment, the script only show
minimum and maximum value for each fields of a particular
tracepoint.

The trace must be in the babeltrace text format. It can be
passed via stdin.

The script output this format:
field_name min max

Sample usage:

> babeltrace sometracedir | babelstats.pl --tracepoint tp:tptest

_seqfield1_length 4 4
seqfield2 "test" "test"
stringfield2 "\*" "\*"
floatfield 2222 2222
netintfieldhex 0x0 0x63
_seqfield2_length 4 4
longfield 0 99
netintfield 0 99
intfield2 0x0 0x63
intfield 0 99
stringfield "test" "test"
doublefield 2 2
arrfield2 "test" "test"

Use case:
This script could be useful to validate that fields values
are within some predefined expected ranges.

Signed-off-by: Christian Babeux <christian.babeux@efficios.com>
---
 tests/tools/filtering/Makefile.am   |   4 +-
 tests/tools/filtering/babelstats.pl | 174 ++++++++++++++++++++++++++++++++++++
 2 files changed, 176 insertions(+), 2 deletions(-)
 create mode 100755 tests/tools/filtering/babelstats.pl

diff --git a/tests/tools/filtering/Makefile.am b/tests/tools/filtering/Makefile.am
index 5f3423a..df99e27 100644
--- a/tests/tools/filtering/Makefile.am
+++ b/tests/tools/filtering/Makefile.am
@@ -1,2 +1,2 @@
-noinst_SCRIPTS = unsupported-ops invalid-filters
-EXTRA_DIST = unsupported-ops invalid-filters
+noinst_SCRIPTS = unsupported-ops invalid-filters babelstats.pl
+EXTRA_DIST = unsupported-ops invalid-filters babelstats.pl
diff --git a/tests/tools/filtering/babelstats.pl b/tests/tools/filtering/babelstats.pl
new file mode 100755
index 0000000..d8d4dd0
--- /dev/null
+++ b/tests/tools/filtering/babelstats.pl
@@ -0,0 +1,174 @@
+#!/usr/bin/perl
+
+# Copyright (C) - 2012 Christian Babeux <christian.babeux@efficios.com>
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License, version 2 only, as
+# published by the Free Software Foundation.
+#
+# 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.
+
+use strict;
+use warnings;
+
+use Getopt::Long;
+
+my $opt_tracepoint;
+
+GetOptions('tracepoint=s' => \$opt_tracepoint)
+	or die("Invalid command-line option\n");
+
+defined($opt_tracepoint)
+	or die("Missing tracepoint, use --tracepoint <name>");
+
+# Parse an array string.
+# The format is as follow: [ [index] = value, ... ]
+sub parse_array
+{
+	my ($arr_str) = @_;
+	my @array = ();
+
+	# Strip leading and ending brackets, remove whitespace
+	$arr_str =~ s/^\[//;
+	$arr_str =~ s/\]$//;
+	$arr_str =~ s/\s//g;
+
+	my @entries = split(',', $arr_str);
+
+	foreach my $entry (@entries) {
+		if ($entry =~ /^\[(\d+)\]=(\d+)$/) {
+			my $index = $1;
+			my $value = $2;
+			splice @array, $index, 0, $value;
+		}
+	}
+
+	return \@array;
+}
+
+# Parse fields values.
+# Format can either be a name = array or a name = value pair.
+sub parse_fields
+{
+	my ($fields_str) = @_;
+	my %fields_hash;
+
+	my $field_name = '[\w\d_]+';
+	my $field_value = '[\w\d_\\\*"]+';
+	my $array = '\[(?:\s\[\d+\]\s=\s\d+,)*\s\[\d+\]\s=\s\d+\s\]';
+
+	# Split the various fields
+	my @fields = ($fields_str =~ /$field_name\s=\s(?:$array|$field_value)/g);
+
+	foreach my $field (@fields) {
+		if ($field =~ /($field_name)\s=\s($array)/) {
+			my $name  = $1;
+			my $value = parse_array($2);
+			$fields_hash{$name} = $value;
+		}
+
+		if ($field =~ /($field_name)\s=\s($field_value)/) {
+			my $name  = $1;
+			my $value = $2;
+			$fields_hash{$name} = $value;
+		}
+	}
+
+	return \%fields_hash;
+}
+
+# Using an event array, merge all the fields
+# of a particular tracepoint.
+sub merge_fields
+{
+	my ($events_ref) = @_;
+	my %merged;
+
+	foreach my $event (@{$events_ref}) {
+		my $tp_provider = $event->{'tp_provider'};
+		my $tp_name     = $event->{'tp_name'};
+		my $tracepoint  = "$tp_provider:$tp_name";
+
+		foreach my $key (keys %{$event->{'fields'}}) {
+			my $val = $event->{'fields'}->{$key};
+
+			# TODO: Merge of array is not implemented.
+			next if (ref($val) eq 'ARRAY');
+			$merged{$tracepoint}{$key}{$val} = undef;
+		}
+	}
+
+	return \%merged;
+}
+
+# Print the minimum and maximum of each fields
+# for a particular tracepoint.
+sub print_fields_stats
+{
+	my ($merged_ref, $tracepoint) = @_;
+
+	return unless ($tracepoint && exists $merged_ref->{$tracepoint});
+
+	foreach my $field (keys %{$merged_ref->{$tracepoint}}) {
+		my @sorted;
+		my @val = keys ($merged_ref->{$tracepoint}->{$field});
+
+		if ($val[0] =~ /^\d+$/) {
+			# Sort numerically
+			@sorted = sort { $a <=> $b } @val;
+		} elsif ($val[0] =~ /^0x[\da-f]+$/i) {
+			# Convert the hex values and sort numerically
+			@sorted = sort { hex($a) <=> hex($b) } @val;
+		} else {
+			# Fallback, alphabetical sort
+			@sorted = sort { lc($a) cmp lc($b) } @val;
+		}
+
+		my $min = $sorted[0];
+		my $max = $sorted[-1];
+
+		print "$field $min $max\n";
+	}
+}
+
+my @events;
+
+while (<>)
+{
+	my $timestamp   = '\[(.*)\]';
+	my $elapsed     = '\((.*)\)';
+	my $hostname    = '.*';
+	my $pname       = '.*';
+	my $pid         = '\d+';
+	my $tp_provider = '.*';
+	my $tp_name     = '.*';
+	my $cpu_info    = '{\scpu_id\s=\s(\d+)\s\}';
+	my $fields      = '{(.*)}';
+
+	# Parse babeltrace text output format
+	if (/$timestamp\s$elapsed\s($hostname):($pname):($pid)\s($tp_provider):($tp_name):\s$cpu_info,\s$fields/) {
+		my %event_hash;
+
+		$event_hash{'timestamp'}   = $1;
+		$event_hash{'elapsed'}     = $2;
+		$event_hash{'hostname'}    = $3;
+		$event_hash{'pname'}       = $4;
+		$event_hash{'pid'}         = $5;
+		$event_hash{'tp_provider'} = $6;
+		$event_hash{'tp_name'}     = $7;
+		$event_hash{'cpu_id'}      = $8;
+		$event_hash{'fields'}      = parse_fields($9);
+
+		push @events, \%event_hash;
+	}
+}
+
+my %merged_fields = %{merge_fields(\@{events})};
+print_fields_stats(\%merged_fields, $opt_tracepoint);
-- 
1.7.12.2

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH lttng-tools 4/5] Tests: Add a test for valid filters
       [not found] <1350412403-9974-1-git-send-email-christian.babeux@efficios.com>
  2012-10-16 18:33 ` [PATCH lttng-tools 2/5] Tests: Add a test for invalid filters Christian Babeux
  2012-10-16 18:33 ` [PATCH lttng-tools 3/5] Tests: Add a trace statistics utility Christian Babeux
@ 2012-10-16 18:33 ` Christian Babeux
  2012-10-16 18:33 ` [PATCH lttng-tools 5/5] Tests: Add filtering tests to configure Christian Babeux
  3 siblings, 0 replies; 4+ messages in thread
From: Christian Babeux @ 2012-10-16 18:33 UTC (permalink / raw)
  To: dgoulet; +Cc: lttng-dev

This test validate that for a given filter the expected
trace output is conform to the expected filter behavior.

This test rely on the babelstats utility. With the help
of this script, we can verify that the expected minimum
and maximum values on fields of interest are within the
expected ranges.

For example, given 100 iterations on a tracepoint with the
field 'intfield', with values starting from 0 and incrementing
on each iteration, and the filter expression 'intfield < 4',
we would expect that the min-max range lie within [0,3].

Thus, if the babelstat computed range does not match the
expected range, this could potentially indicate failure in
the filtering mechanism.

Signed-off-by: Christian Babeux <christian.babeux@efficios.com>
---
 tests/tools/filtering/Makefile.am      |  20 +-
 tests/tools/filtering/gen-ust-events.c |  59 +++++
 tests/tools/filtering/tp.c             |  15 ++
 tests/tools/filtering/tp.h             |  57 +++++
 tests/tools/filtering/valid-filters    | 411 +++++++++++++++++++++++++++++++++
 5 files changed, 560 insertions(+), 2 deletions(-)
 create mode 100644 tests/tools/filtering/gen-ust-events.c
 create mode 100644 tests/tools/filtering/tp.c
 create mode 100644 tests/tools/filtering/tp.h
 create mode 100755 tests/tools/filtering/valid-filters

diff --git a/tests/tools/filtering/Makefile.am b/tests/tools/filtering/Makefile.am
index df99e27..a3bf866 100644
--- a/tests/tools/filtering/Makefile.am
+++ b/tests/tools/filtering/Makefile.am
@@ -1,2 +1,18 @@
-noinst_SCRIPTS = unsupported-ops invalid-filters babelstats.pl
-EXTRA_DIST = unsupported-ops invalid-filters babelstats.pl
+AM_CFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/src -I$(top_srcdir)/tests -I$(srcdir) -O2 -g
+AM_LDFLAGS =
+
+if LTTNG_TOOLS_BUILD_WITH_LIBDL
+AM_LDFLAGS += -ldl
+endif
+if LTTNG_TOOLS_BUILD_WITH_LIBC_DL
+AM_LDFLAGS += -lc
+endif
+
+if HAVE_LIBLTTNG_UST_CTL
+noinst_PROGRAMS = gen-ust-events
+gen_ust_events_SOURCES = gen-ust-events.c tp.c tp.h
+gen_ust_events_LDADD = -llttng-ust
+endif
+
+noinst_SCRIPTS = unsupported-ops invalid-filters valid-filters babelstats.pl
+EXTRA_DIST = unsupported-ops invalid-filters valid-filters babelstats.pl
diff --git a/tests/tools/filtering/gen-ust-events.c b/tests/tools/filtering/gen-ust-events.c
new file mode 100644
index 0000000..c789c89
--- /dev/null
+++ b/tests/tools/filtering/gen-ust-events.c
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) - 2012 David Goulet <dgoulet@efficios.com>
+ *
+ * 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
+ */
+
+#include <arpa/inet.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/mman.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#define TRACEPOINT_DEFINE
+#include "tp.h"
+
+int main(int argc, char **argv)
+{
+	int i, netint;
+	long values[] = { 1, 2, 3 };
+	char text[10] = "test";
+	char escape[10] = "\\*";
+	double dbl = 2.0;
+	float flt = 2222.0;
+	/* Generate 30 events. */
+	unsigned int nr_iter = 100;
+	useconds_t nr_usec = 0;
+
+	if (argc >= 2) {
+		nr_iter = atoi(argv[1]);
+	}
+
+	if (argc == 3) {
+		/* By default, don't wait unless user specifies. */
+		nr_usec = atoi(argv[2]);
+	}
+
+	for (i = 0; i < nr_iter; i++) {
+		netint = htonl(i);
+		tracepoint(tp, tptest, i, netint, values, text, strlen(text), escape, dbl, flt);
+		usleep(nr_usec);
+	}
+
+	return 0;
+}
diff --git a/tests/tools/filtering/tp.c b/tests/tools/filtering/tp.c
new file mode 100644
index 0000000..a09561d
--- /dev/null
+++ b/tests/tools/filtering/tp.c
@@ -0,0 +1,15 @@
+/*
+ * Copyright (c) - 2012 David Goulet <dgoulet@efficios.com>
+ *
+ * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED OR
+ * IMPLIED. ANY USE IS AT YOUR OWN RISK.
+ *
+ * Permission is hereby granted to use or copy this program for any purpose,
+ * provided the above notices are retained on all copies.  Permission to modify
+ * the code and to distribute modified code is granted, provided the above
+ * notices are retained, and a notice that the code was modified is included
+ * with the above copyright notice.
+ */
+
+#define TRACEPOINT_CREATE_PROBES
+#include "tp.h"
diff --git a/tests/tools/filtering/tp.h b/tests/tools/filtering/tp.h
new file mode 100644
index 0000000..15f81e5
--- /dev/null
+++ b/tests/tools/filtering/tp.h
@@ -0,0 +1,57 @@
+#undef TRACEPOINT_PROVIDER
+#define TRACEPOINT_PROVIDER tp
+
+#if !defined(_TRACEPOINT_TP_H) || defined(TRACEPOINT_HEADER_MULTI_READ)
+#define _TRACEPOINT_TP_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * Copyright (C) 2011  Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *
+ * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
+ * OR IMPLIED.  ANY USE IS AT YOUR OWN RISK.
+ *
+ * Permission is hereby granted to use or copy this program
+ * for any purpose,  provided the above notices are retained on all copies.
+ * Permission to modify the code and to distribute modified code is granted,
+ * provided the above notices are retained, and a notice that the code was
+ * modified is included with the above copyright notice.
+ */
+
+#include <lttng/tracepoint.h>
+
+TRACEPOINT_EVENT(tp, tptest,
+	TP_ARGS(int, anint, int, netint, long *, values,
+		char *, text, size_t, textlen,
+		char *, etext, double, doublearg, float, floatarg),
+	TP_FIELDS(
+		ctf_integer(int, intfield, anint)
+		ctf_integer_hex(int, intfield2, anint)
+		ctf_integer(long, longfield, anint)
+		ctf_integer_network(int, netintfield, netint)
+		ctf_integer_network_hex(int, netintfieldhex, netint)
+		ctf_array(long, arrfield1, values, 3)
+		ctf_array_text(char, arrfield2, text, 10)
+		ctf_sequence(char, seqfield1, text, size_t, textlen)
+		ctf_sequence_text(char, seqfield2, text, size_t, textlen)
+		ctf_string(stringfield, text)
+		ctf_string(stringfield2, etext)
+		ctf_float(float, floatfield, floatarg)
+		ctf_float(double, doublefield, doublearg)
+	)
+)
+
+#endif /* _TRACEPOINT_TP_H */
+
+#undef TRACEPOINT_INCLUDE_FILE
+#define TRACEPOINT_INCLUDE_FILE ./tp.h
+
+/* This part must be outside ifdef protection */
+#include <lttng/tracepoint-event.h>
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/tests/tools/filtering/valid-filters b/tests/tools/filtering/valid-filters
new file mode 100755
index 0000000..b48b6ed
--- /dev/null
+++ b/tests/tools/filtering/valid-filters
@@ -0,0 +1,411 @@
+#!/bin/bash
+#
+# Copyright (C) - 2012 Christian Babeux <christian.babeux@efficios.com>
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License, version 2 only, as
+# published by the Free Software Foundation.
+#
+# 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.
+
+TEST_DESC="Filtering - Valid filters"
+
+CURDIR=$(dirname $0)/
+TESTDIR=$CURDIR/../..
+LTTNG_BIN="lttng"
+BIN_NAME="gen-ust-events"
+STATS_BIN="babelstats.pl"
+SESSION_NAME="valid_filter"
+EVENT_NAME="tp:tptest"
+NR_ITER=100
+
+source $TESTDIR/utils.sh
+
+print_test_banner "$TEST_DESC"
+
+if [ ! -x "$CURDIR/$BIN_NAME" ]; then
+	echo -e "No UST nevents binary detected. Passing."
+	exit 0
+fi
+
+function enable_ust_lttng_event_filter()
+{
+	sess_name="$1"
+	event_name="$2"
+	filter="$3"
+	echo -n "Enabling lttng event with filtering "
+
+	$TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event $event_name -s $sess_name -u --filter "$filter" 2>&1 >/dev/null
+
+	if [ $? -eq 0 ]; then
+		print_ok
+		return 0
+	else
+		print_fail
+		return 1
+	fi
+}
+
+function run_apps
+{
+	./$CURDIR/$BIN_NAME $NR_ITER & >/dev/null 2>&1
+}
+
+function wait_apps
+{
+	echo "Waiting for applications to end"
+	while [ -n "$(pidof $BIN_NAME)" ]; do
+		echo -n "."
+		sleep 1
+	done
+	echo ""
+}
+
+function test_valid_filter
+{
+	filter="$1"
+	validator="$2"
+
+	echo ""
+	echo -e "=== Testing valid filter: $1"
+
+	trace_path=$(mktemp -d)
+
+	# Create session
+	create_lttng_session $SESSION_NAME $trace_path
+
+	# Enable filter
+	enable_ust_lttng_event_filter $SESSION_NAME $EVENT_NAME $filter
+
+	# Trace apps
+	start_lttng_tracing $SESSION_NAME
+	run_apps
+	wait_apps
+	stop_lttng_tracing $SESSION_NAME
+
+	# Destroy session
+	destroy_lttng_session $SESSION_NAME
+
+	echo -n "Validating filter output "
+	stats=`babeltrace $trace_path | $CURDIR/$STATS_BIN --tracepoint $EVENT_NAME`
+
+	$validator "$stats"
+
+	if [ $? -eq 0 ]; then
+		print_ok
+#		rm -rf $trace_path
+		return 0
+	else
+		print_fail
+		return 1
+	fi
+}
+
+function validate_min_max
+{
+	stats="$1"
+	field=$2
+	expected_min=$3
+	expected_max=$4
+
+	echo $stats | grep -q "$field $expected_min $expected_max"
+
+	return $?
+}
+
+function validator_intfield
+{
+	stats="$1"
+	status=0
+
+	validate_min_max "$stats" "intfield" "1" "99"
+	status=$(($status|$?))
+
+	validate_min_max "$stats" "intfield2" "0x1" "0x63"
+	status=$(($status|$?))
+
+	validate_min_max "$stats" "longfield" "1" "99"
+	status=$(($status|$?))
+
+	validate_min_max "$stats" "netintfield" "1" "99"
+	status=$(($status|$?))
+
+	validate_min_max "$stats" "netintfieldhex" "0x1" "0x63"
+	status=$(($status|$?))
+
+	validate_min_max "$stats" "floatfield" "2222" "2222"
+	status=$(($status|$?))
+
+	validate_min_max "$stats" "doublefield" "2" "2"
+	status=$(($status|$?))
+
+	return $status
+}
+
+function validator_intfield_gt
+{
+	stats="$1"
+	status=0
+
+	validate_min_max "$stats" "intfield" "2" "99"
+	status=$(($status|$?))
+
+	return $status
+}
+
+function validator_intfield_ge
+{
+	stats="$1"
+	status=0
+
+	validate_min_max "$stats" "intfield" "1" "99"
+	status=$(($status|$?))
+
+	return $status
+}
+
+function validator_intfield_lt
+{
+	stats="$1"
+	status=0
+
+	validate_min_max "$stats" "intfield" "0" "1"
+	status=$(($status|$?))
+
+	return $status
+}
+
+function validator_intfield_le
+{
+	stats="$1"
+	status=0
+
+	validate_min_max "$stats" "intfield" "0" "2"
+	status=$(($status|$?))
+
+	return $status
+}
+
+function validator_intfield_eq
+{
+	stats="$1"
+	status=0
+
+	validate_min_max "$stats" "intfield" "1" "1"
+	status=$(($status|$?))
+
+	return $status
+}
+
+function validator_intfield_ne
+{
+	stats="$1"
+	status=0
+
+	validate_min_max "$stats" "intfield" "0" "98"
+	status=$(($status|$?))
+
+	return $status
+}
+
+function validator_intfield_not
+{
+	stats="$1"
+	status=0
+
+	validate_min_max "$stats" "intfield" "0" "0"
+	status=$(($status|$?))
+
+	return $status
+}
+
+function validator_intfield_gt_and_longfield_gt
+{
+	stats="$1"
+	status=0
+
+	validate_min_max "$stats" "intfield" "43" "99"
+	status=$(($status|$?))
+	validate_min_max "$stats" "longfield" "43" "99"
+	status=$(($status|$?))
+
+	return $status
+}
+
+function validator_intfield_ge_and_longfield_le
+{
+	stats="$1"
+	status=0
+
+	validate_min_max "$stats" "intfield" "42" "42"
+	status=$(($status|$?))
+	validate_min_max "$stats" "longfield" "42" "42"
+	status=$(($status|$?))
+
+	return $status
+}
+
+function validator_intfield_lt_or_longfield_gt
+{
+	stats="$1"
+	status=0
+
+	validate_min_max "$stats" "intfield" "0" "99"
+	status=$(($status|$?))
+	validate_min_max "$stats" "longfield" "0" "99"
+	status=$(($status|$?))
+
+	return $status
+}
+
+function validator_mixed_str_or_int_and_int
+{
+	stats="$1"
+	status=0
+
+	validate_min_max "$stats" "intfield" "34" "99"
+	status=$(($status|$?))
+
+	validate_min_max "$stats" "stringfield" "\"test\"" "\"test\""
+	status=$(($status|$?))
+
+	return $status
+}
+
+function validator_mixed_int_double
+{
+	stats="$1"
+	status=0
+
+	validate_min_max "$stats" "intfield" "0" "42"
+	status=$(($status|$?))
+
+	return $status
+}
+
+function validator_true_statement
+{
+	stats="$1"
+	status=0
+
+	validate_min_max "$stats" "intfield" "0" "99"
+	status=$(($status|$?))
+
+	validate_min_max "$stats" "intfield2" "0x0" "0x63"
+	status=$(($status|$?))
+
+	validate_min_max "$stats" "longfield" "0" "99"
+	status=$(($status|$?))
+
+	validate_min_max "$stats" "netintfield" "0" "99"
+	status=$(($status|$?))
+
+	validate_min_max "$stats" "netintfieldhex" "0x0" "0x63"
+	status=$(($status|$?))
+
+	validate_min_max "$stats" "floatfield" "2222" "2222"
+	status=$(($status|$?))
+
+	validate_min_max "$stats" "doublefield" "2" "2"
+	status=$(($status|$?))
+
+	validate_min_max "$stats" "stringfield" "\"test\"" "\"test\""
+	status=$(($status|$?))
+
+	validate_min_max "$stats" "stringfield2" ""\*"" ""\*""
+	status=$(($status|$?))
+
+	return $status
+}
+
+IFS=$'\n'
+
+issue_356_filter="intfield > 0 && intfield > 1 && "
+issue_356_filter+="intfield > 2 && intfield > 3 && "
+issue_356_filter+="intfield > 4 && intfield > 5 && "
+issue_356_filter+="intfield > 6 && intfield > 7 && "
+issue_356_filter+="intfield > 8 || intfield > 0"
+
+# One to one mapping between filters and validators
+
+FILTERS=("intfield"                                                     #1
+	 "intfield > 1"                                                 #2
+	 "intfield >= 1"                                                #3
+	 "intfield < 2"                                                 #4
+	 "intfield <= 2"                                                #5
+	 "intfield == 1"                                                #6
+	 "intfield != 99"                                               #7
+	 "!intfield"                                                    #8
+	 "-intfield"                                                    #9
+	 "--intfield"                                                   #10
+	 "+intfield"                                                    #11
+	 "++intfield"                                                   #12
+	 "intfield > 1 && longfield > 42"                               #13
+	 "intfield >= 42 && longfield <= 42"                            #14
+	 "intfield < 1 || longfield > 98"                               #15
+	 "(stringfield == \"test\" || intfield != 10) && intfield > 33" #16
+	 "intfield < 42.4242424242"                                     #17
+	 "\"test\" == \"test\""                                         #18 #Issue #342
+	 "stringfield == \"test\""                                      #19
+	 "stringfield == \"t*\""                                        #20
+	 "stringfield == \"*\""                                         #21
+	 $issue_356_filter                                              #22 #Issue #356
+	 "intfield < 0xDEADBEEF"                                        #23
+	 "intfield < 0x2"                                               #24
+	 "intfield < 02"                                                #25
+	 "stringfield2 == \"\\\*\""                                     #26
+)
+
+VALIDATOR=("validator_intfield"                     #1
+	   "validator_intfield_gt"                  #2
+	   "validator_intfield_ge"                  #3
+	   "validator_intfield_lt"                  #4
+	   "validator_intfield_le"                  #5
+	   "validator_intfield_eq"                  #6
+	   "validator_intfield_ne"                  #7
+	   "validator_intfield_not"                 #8
+	   "validator_intfield"                     #9
+	   "validator_intfield"                     #10
+	   "validator_intfield"                     #11
+	   "validator_intfield"                     #12
+	   "validator_intfield_gt_and_longfield_gt" #13
+	   "validator_intfield_ge_and_longfield_le" #14
+	   "validator_intfield_lt_or_longfield_gt"  #15
+	   "validator_mixed_str_or_int_and_int"     #16
+	   "validator_mixed_int_double"             #17
+	   "validator_true_statement"               #18
+	   "validator_true_statement"               #19
+	   "validator_true_statement"               #20
+	   "validator_true_statement"               #21
+	   "validator_intfield"                     #22
+	   "validator_true_statement"               #23
+	   "validator_intfield_lt"                  #24
+	   "validator_intfield_lt"                  #25
+	   "validator_true_statement"               #26
+)
+
+FILTER_COUNT=${#FILTERS[@]}
+i=0
+
+start_lttng_sessiond
+
+while [ "$i" -lt "$FILTER_COUNT" ]; do
+
+	test_valid_filter "${FILTERS[$i]}" "${VALIDATOR[$i]}"
+
+	if [ $? -eq 1 ]; then
+		stop_lttng_sessiond
+		exit 1
+	fi
+
+	let "i++"
+done
+
+stop_lttng_sessiond
-- 
1.7.12.2

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH lttng-tools 5/5] Tests: Add filtering tests to configure
       [not found] <1350412403-9974-1-git-send-email-christian.babeux@efficios.com>
                   ` (2 preceding siblings ...)
  2012-10-16 18:33 ` [PATCH lttng-tools 4/5] Tests: Add a test for valid filters Christian Babeux
@ 2012-10-16 18:33 ` Christian Babeux
  3 siblings, 0 replies; 4+ messages in thread
From: Christian Babeux @ 2012-10-16 18:33 UTC (permalink / raw)
  To: dgoulet; +Cc: lttng-dev

Add filtering folder to top-level Makefile.am.
Also add a runall script to run all filtering tests.

Signed-off-by: Christian Babeux <christian.babeux@efficios.com>
---
 configure.ac                      |  1 +
 tests/tools/Makefile.am           |  2 +-
 tests/tools/filtering/Makefile.am |  4 ++--
 tests/tools/filtering/runall      | 28 ++++++++++++++++++++++++++++
 tests/tools/runall.sh             |  2 +-
 5 files changed, 33 insertions(+), 4 deletions(-)
 create mode 100755 tests/tools/filtering/runall

diff --git a/configure.ac b/configure.ac
index cb5dc38..fbaae6f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -288,6 +288,7 @@ AC_CONFIG_FILES([
 	tests/kernel/Makefile
 	tests/tools/Makefile
 	tests/tools/streaming/Makefile
+	tests/tools/filtering/Makefile
 	tests/tools/health/Makefile
 	tests/ust/Makefile
 	tests/ust/nprocesses/Makefile
diff --git a/tests/tools/Makefile.am b/tests/tools/Makefile.am
index 173dce2..56eda3a 100644
--- a/tests/tools/Makefile.am
+++ b/tests/tools/Makefile.am
@@ -1,4 +1,4 @@
-SUBDIRS = streaming health
+SUBDIRS = streaming filtering health
 
 AM_CFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/src -I$(top_srcdir)/tests -g -Wall
 AM_LDFLAGS = -lurcu -lurcu-cds
diff --git a/tests/tools/filtering/Makefile.am b/tests/tools/filtering/Makefile.am
index a3bf866..e1e715d 100644
--- a/tests/tools/filtering/Makefile.am
+++ b/tests/tools/filtering/Makefile.am
@@ -14,5 +14,5 @@ gen_ust_events_SOURCES = gen-ust-events.c tp.c tp.h
 gen_ust_events_LDADD = -llttng-ust
 endif
 
-noinst_SCRIPTS = unsupported-ops invalid-filters valid-filters babelstats.pl
-EXTRA_DIST = unsupported-ops invalid-filters valid-filters babelstats.pl
+noinst_SCRIPTS = runall unsupported-ops invalid-filters valid-filters babelstats.pl
+EXTRA_DIST = runall unsupported-ops invalid-filters valid-filters babelstats.pl
diff --git a/tests/tools/filtering/runall b/tests/tools/filtering/runall
new file mode 100755
index 0000000..c92e399
--- /dev/null
+++ b/tests/tools/filtering/runall
@@ -0,0 +1,28 @@
+#!/bin/bash
+
+DIR=$(dirname $0)
+
+tests=( $DIR/unsupported-ops $DIR/invalid-filters $DIR/valid-filters )
+exit_code=0
+
+function start_tests ()
+{
+	for bin in ${tests[@]};
+	do
+		if [ ! -e $bin ]; then
+			echo -e "$bin not found, passing"
+			continue
+		fi
+
+		./$bin
+		# Test must return 0 to pass.
+		if [ $? -ne 0 ]; then
+			exit_code=1
+			break
+		fi
+	done
+}
+
+start_tests
+
+exit $exit_code
diff --git a/tests/tools/runall.sh b/tests/tools/runall.sh
index 0ad7cf1..b2be91c 100755
--- a/tests/tools/runall.sh
+++ b/tests/tools/runall.sh
@@ -3,7 +3,7 @@
 DIR=$(dirname $0)
 
 tests=( $DIR/test_kernel_data_trace $DIR/test_sessions $DIR/test_ust_data_trace \
-		$DIR/streaming/runall $DIR/health/runall )
+		$DIR/streaming/runall $DIR/health/runall $DIR/filtering/runall)
 
 exit_code=0
 
-- 
1.7.12.2

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-10-16 18:33 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <1350412403-9974-1-git-send-email-christian.babeux@efficios.com>
2012-10-16 18:33 ` [PATCH lttng-tools 2/5] Tests: Add a test for invalid filters Christian Babeux
2012-10-16 18:33 ` [PATCH lttng-tools 3/5] Tests: Add a trace statistics utility Christian Babeux
2012-10-16 18:33 ` [PATCH lttng-tools 4/5] Tests: Add a test for valid filters Christian Babeux
2012-10-16 18:33 ` [PATCH lttng-tools 5/5] Tests: Add filtering tests to configure Christian Babeux

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.