From: David Goulet Date: Mon, 11 Mar 2013 17:00:33 +0000 (-0400) Subject: Merge remote-tracking branch 'cbab-github/tests-cleanup' into cbab X-Git-Tag: v2.2.0-rc1~60 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=5d2e1e66a968d9e555f9b8b00d0589ebfaf3de32;p=lttng-tools.git Merge remote-tracking branch 'cbab-github/tests-cleanup' into cbab Conflicts: tests/regression/tools/streaming/test_high_throughput_limits tests/unit/test_kernel_data.c tests/unit/test_ust_data.c --- 5d2e1e66a968d9e555f9b8b00d0589ebfaf3de32 diff --cc tests/regression/tools/streaming/test_high_throughput_limits index 000000000,7c253ba84..2412374bb mode 000000,100755..100755 --- a/tests/regression/tools/streaming/test_high_throughput_limits +++ b/tests/regression/tools/streaming/test_high_throughput_limits @@@ -1,0 -1,200 +1,191 @@@ + #!/bin/bash + # + # Copyright (C) - 2012 Christian Babeux + # David Goulet + # + # 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 + + TEST_DESC="Streaming - High throughput with bandwidth limits" + + CURDIR=$(dirname $0)/ + TESTDIR=$CURDIR/../../.. + NR_APP_ITER=10 + NR_ITER=1000000 + BIN_NAME="gen-ust-events" + SESSION_NAME="high-throughput" + EVENT_NAME="tp:tptest" + SESSIOND_CTRL_PORT=5342 + SESSIOND_DATA_PORT=5343 + DEFAULT_IF="lo" + + TRACE_PATH=$(mktemp -d) + + NUM_TESTS=112 + + source $TESTDIR/utils/utils.sh + + print_test_banner "$TEST_DESC" + + if [ ! -x "$CURDIR/$BIN_NAME" ]; then + BAIL_OUT "No UST nevents binary detected." + fi + + function set_bw_limit + { + limit=$1 + ctrlportlimit=$(($limit/10)) + # failsafe to have at least 1kbit/s for control (in the case where $1 < 10) + [ $ctrlportlimit = 0 ] && ctrlportlimit=1 + # if $1 < 10, we might bust the limit set here, but the + # parent qdisc (1:) will always limit us to the right max value + dataportlimit=$((9*${ctrlportlimit})) + + + tc qdisc add dev $DEFAULT_IF root handle 1: htb default 15 >/dev/null 2>&1 + + # the total bandwidth is the limit set by the user + tc class add dev $DEFAULT_IF parent 1: classid 1:1 htb rate ${limit}kbit ceil ${limit}kbit >/dev/null 2>&1 + # 1/10 of the bandwidth guaranteed and traffic prioritized for the control port + tc class add dev $DEFAULT_IF parent 1:1 classid 1:10 htb rate ${ctrlportlimit}kbit ceil ${limit}kbit prio 1 >/dev/null 2>&1 + # 9/10 of the bandwidth guaranteed and can borrow up to the total bandwidth (if unused) + tc class add dev $DEFAULT_IF parent 1:1 classid 1:11 htb rate ${dataportlimit}kbit ceil ${limit}kbit prio 2 >/dev/null 2>&1 + + # filter to assign control traffic to the 1:10 class + tc filter add dev $DEFAULT_IF parent 1: protocol ip u32 match ip dport $SESSIOND_CTRL_PORT 0xffff flowid 1:10 >/dev/null 2>&1 + # filter to assign data traffic to the 1:11 class + tc filter add dev $DEFAULT_IF parent 1: protocol ip u32 match ip dport $SESSIOND_DATA_PORT 0xffff flowid 1:11 >/dev/null 2>&1 + + ok $? "Set bandwidth limits to ${limit}kbits, ${ctrlportlimit} for control and ${dataportlimit} for data" + } + + function reset_bw_limit + { + tc qdisc del dev $DEFAULT_IF root >/dev/null 2>&1 + ok $? "Reset bandwith limits" + } + + function create_lttng_session_with_uri + { + sess_name=$1 + uri=$2 + # Create session with custom URI + $TESTDIR/../src/bin/lttng/$LTTNG_BIN create -U $uri $sess_name >/dev/null 2>&1 + ok $? "Create session with uri $uri" + } + -function enable_lttng_consumer -{ - uri=$1 - # Create session with custom URI - $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-consumer -u $uri >/dev/null 2>&1 - ok $? "Enable consumer with uri $uri" -} - + function run_apps + { + for i in `seq 1 $NR_APP_ITER`; do + # With bandwidth limitation, unfortunately, application easily timeout + # due to very slow communication between the consumer and relayd making + # the status reply from the consumer quite slow thus delaying the + # registration done message. + LTTNG_UST_REGISTER_TIMEOUT=-1 ./$CURDIR/$BIN_NAME $NR_ITER & >/dev/null 2>&1 + done + } + + function wait_apps + { + while [ -n "$(pidof $BIN_NAME)" ]; do + sleep 1 + done + pass "Wait for applications to end" + } + + function test_high_throughput + { + NETWORK_URI="net://localhost" + create_lttng_session_with_uri $SESSION_NAME $NETWORK_URI - enable_lttng_consumer $NETWORK_URI + enable_ust_lttng_event $SESSION_NAME $EVENT_NAME + start_lttng_tracing $SESSION_NAME + run_apps + wait_apps + stop_lttng_tracing $SESSION_NAME + destroy_lttng_session $SESSION_NAME + validate_event_count + } + + function validate_event_count + { + + TEMP_FILE=$(mktemp) + TEMP_FILE_2=$(mktemp) + + traced=$(babeltrace $TRACE_PATH 2>/dev/null | wc -l) + babeltrace $TRACE_PATH >/dev/null 2>$TEMP_FILE_2 + + cat $TEMP_FILE_2 | cut -f4 -d " " >$TEMP_FILE + + dropped=0 + while read line; + do + let dropped=$dropped+$line + done < $TEMP_FILE + + let total=$dropped+$traced + let wanted=$NR_APP_ITER*$NR_ITER + + if [ $wanted -ne $total ]; then + fail "Validate trace event count" + diag "Expected $wanted. Dropped $dropped. Recorded $traced. Total $total... " + return 1 + else + pass "Validate trace event count" + diag "Expected $wanted. Dropped $dropped. Recorded $traced. Total $total... " + + rm -rf $TRACE_PATH + rm $TEMP_FILE $TEMP_FILE_2 + + return 0 + fi + } + + function interrupt_cleanup() + { + diag "*** Exiting ***" + stop_lttng_relayd + stop_lttng_sessiond + reset_bw_limit + exit 1 + } + + plan_tests $NUM_TESTS + + if [ "$(id -u)" == "0" ]; then + isroot=1 + else + isroot=0 + fi + + skip $isroot "Root access is needed to set bandwith limits. Skipping all tests." $NUM_TESTS || + { + + # Catch sigint and try to cleanup limits + trap interrupt_cleanup SIGINT + + BW_LIMITS=(3200 1600 800 400 200 100 50 25) + for BW in ${BW_LIMITS[@]}; + do + diag "Test high-throughput with bandwidth limit set to ${BW}kbits" + set_bw_limit $BW + + start_lttng_sessiond + start_lttng_relayd "-o $TRACE_PATH" + test_high_throughput + result=$? + stop_lttng_relayd + stop_lttng_sessiond + reset_bw_limit + done + } diff --cc tests/unit/test_kernel_data.c index 000000000,1359b7fa8..13f48f9b5 mode 000000,100644..100644 --- a/tests/unit/test_kernel_data.c +++ b/tests/unit/test_kernel_data.c @@@ -1,0 -1,189 +1,189 @@@ + /* + * Copyright (c) 2011 David Goulet + * + * 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 + * as published by the Free Software Foundation; only 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. + */ + + #define _GNU_SOURCE + #include + #include + #include + #include + #include + #include + #include + + #include + #include + + #include + + /* This path will NEVER be created in this test */ + #define PATH1 "/tmp/.test-junk-lttng" + + #define RANDOM_STRING_LEN 11 + + /* Number of TAP tests in this file */ + #define NUM_TESTS 10 + + /* For lttngerr.h */ + int lttng_opt_quiet = 1; + int lttng_opt_verbose; + + static const char alphanum[] = + "0123456789" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "abcdefghijklmnopqrstuvwxyz"; + + static struct ltt_kernel_session *kern; + static char random_string[RANDOM_STRING_LEN]; + + /* + * Return random string of 10 characters. + * Not thread-safe. + */ + static char *get_random_string(void) + { + int i; + + for (i = 0; i < RANDOM_STRING_LEN - 1; i++) { + random_string[i] = alphanum[rand() % (sizeof(alphanum) - 1)]; + } + + random_string[RANDOM_STRING_LEN - 1] = '\0'; + + return random_string; + } + + static void test_create_one_kernel_session(void) + { + kern = trace_kernel_create_session(PATH1); + ok(kern != NULL, "Create kernel session"); + + ok(kern->fd == -1 && + kern->metadata_stream_fd == -1 && + kern->consumer_fds_sent == 0 && + kern->channel_count == 0 && + kern->stream_count_global == 0 && + kern->metadata == NULL, + "Validate kernel session"); + + /* Init list in order to avoid sefaults from cds_list_del */ + trace_kernel_destroy_session(kern); + } + + static void test_create_kernel_metadata(void) + { + assert(kern != NULL); + + kern->metadata = trace_kernel_create_metadata(); + ok(kern->metadata != NULL, "Create kernel metadata"); + + ok(kern->metadata->fd == -1 && + kern->metadata->conf != NULL && + kern->metadata->conf->attr.overwrite + == DEFAULT_CHANNEL_OVERWRITE && + kern->metadata->conf->attr.subbuf_size + == default_get_metadata_subbuf_size() && + kern->metadata->conf->attr.num_subbuf + == DEFAULT_METADATA_SUBBUF_NUM && + kern->metadata->conf->attr.switch_timer_interval - == DEFAULT_CHANNEL_SWITCH_TIMER && ++ == DEFAULT_KERNEL_CHANNEL_SWITCH_TIMER && + kern->metadata->conf->attr.read_timer_interval - == DEFAULT_CHANNEL_READ_TIMER && ++ == DEFAULT_KERNEL_CHANNEL_READ_TIMER && + kern->metadata->conf->attr.output + == DEFAULT_KERNEL_CHANNEL_OUTPUT, + "Validate kernel session metadata"); + + trace_kernel_destroy_metadata(kern->metadata); + } + + static void test_create_kernel_channel(void) + { + struct ltt_kernel_channel *chan; + struct lttng_channel attr; + + memset(&attr, 0, sizeof(attr)); + + chan = trace_kernel_create_channel(&attr); + ok(chan != NULL, "Create kernel channel"); + + ok(chan->fd == -1 && + chan->enabled == 1 && + chan->stream_count == 0 && + chan->ctx == NULL && + chan->channel->attr.overwrite == attr.attr.overwrite, + "Validate kernel channel"); + + /* Init list in order to avoid sefaults from cds_list_del */ + CDS_INIT_LIST_HEAD(&chan->list); + trace_kernel_destroy_channel(chan); + } + + static void test_create_kernel_event(void) + { + struct ltt_kernel_event *event; + struct lttng_event ev; + + memset(&ev, 0, sizeof(ev)); + strncpy(ev.name, get_random_string(), LTTNG_KERNEL_SYM_NAME_LEN); + ev.type = LTTNG_EVENT_TRACEPOINT; + ev.loglevel_type = LTTNG_EVENT_LOGLEVEL_ALL; + + event = trace_kernel_create_event(&ev); + ok(event != NULL, "Create kernel event"); + + ok(event->fd == -1 && + event->enabled == 1 && + event->event->instrumentation == LTTNG_KERNEL_TRACEPOINT && + strlen(event->event->name), + "Validate kernel event"); + + /* Init list in order to avoid sefaults from cds_list_del */ + CDS_INIT_LIST_HEAD(&event->list); + trace_kernel_destroy_event(event); + } + + static void test_create_kernel_stream(void) + { + struct ltt_kernel_stream *stream; + + stream = trace_kernel_create_stream("stream1", 0); + ok(stream != NULL, "Create kernel stream"); + + ok(stream->fd == -1 && + stream->state == 0, + "Validate kernel stream"); + + /* Init list in order to avoid sefaults from cds_list_del */ + CDS_INIT_LIST_HEAD(&stream->list); + trace_kernel_destroy_stream(stream); + } + + int main(int argc, char **argv) + { + diag("Kernel data structure unit test"); + + plan_tests(NUM_TESTS); + + test_create_one_kernel_session(); + test_create_kernel_metadata(); + test_create_kernel_channel(); + test_create_kernel_event(); + test_create_kernel_stream(); + + /* Success */ + return 0; + } diff --cc tests/unit/test_ust_data.c index 000000000,ae59c07a0..0f1c99b95 mode 000000,100644..100644 --- a/tests/unit/test_ust_data.c +++ b/tests/unit/test_ust_data.c @@@ -1,0 -1,195 +1,195 @@@ + /* + * Copyright (c) 2011 David Goulet + * + * 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 + * as published by the Free Software Foundation; only 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. + */ + + #define _GNU_SOURCE + #include + #include + #include + #include + #include + #include + #include + + #include + #include + #include + #include + + #include + + #include "utils.h" + + /* This path will NEVER be created in this test */ + #define PATH1 "/tmp/.test-junk-lttng" + + #define RANDOM_STRING_LEN 11 + + /* Number of TAP tests in this file */ + #define NUM_TESTS 10 + + /* For lttngerr.h */ + int lttng_opt_quiet = 1; + int lttng_opt_verbose; + + static const char alphanum[] = + "0123456789" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "abcdefghijklmnopqrstuvwxyz"; + static char random_string[RANDOM_STRING_LEN]; + + static struct ltt_ust_session *usess; + static struct lttng_domain dom; + + /* + * Return random string of 10 characters. + * Not thread-safe. + */ + static char *get_random_string(void) + { + int i; + + for (i = 0; i < RANDOM_STRING_LEN - 1; i++) { + random_string[i] = alphanum[rand() % (sizeof(alphanum) - 1)]; + } + + random_string[RANDOM_STRING_LEN - 1] = '\0'; + + return random_string; + } + + static void test_create_one_ust_session(void) + { + dom.type = LTTNG_DOMAIN_UST; + + usess = trace_ust_create_session(PATH1, 42); + ok(usess != NULL, "Create UST session"); + + ok(usess->id == 42 && + usess->start_trace == 0 && + usess->domain_global.channels != NULL && + usess->domain_pid != NULL && + usess->domain_exec != NULL && + usess->uid == 0 && + usess->gid == 0, + "Validate UST session"); + + trace_ust_destroy_session(usess); + } + + static void test_create_ust_metadata(void) + { + struct ltt_ust_metadata *metadata; + + assert(usess != NULL); + + metadata = trace_ust_create_metadata(PATH1); + ok(metadata != NULL, "Create UST metadata"); + + ok(metadata->handle == -1 && + strlen(metadata->pathname) && + metadata->attr.overwrite + == DEFAULT_CHANNEL_OVERWRITE && + metadata->attr.subbuf_size + == default_get_metadata_subbuf_size() && + metadata->attr.num_subbuf + == DEFAULT_METADATA_SUBBUF_NUM && + metadata->attr.switch_timer_interval - == DEFAULT_CHANNEL_SWITCH_TIMER && ++ == DEFAULT_UST_CHANNEL_SWITCH_TIMER && + metadata->attr.read_timer_interval - == DEFAULT_CHANNEL_READ_TIMER && ++ == DEFAULT_UST_CHANNEL_READ_TIMER && + metadata->attr.output == LTTNG_UST_MMAP, + "Validate UST session metadata"); + + trace_ust_destroy_metadata(metadata); + } + + static void test_create_ust_channel(void) + { + struct ltt_ust_channel *uchan; + struct lttng_channel attr; + + memset(&attr, 0, sizeof(attr)); + + strncpy(attr.name, "channel0", 8); + + uchan = trace_ust_create_channel(&attr, PATH1); + ok(uchan != NULL, "Create UST channel"); + + ok(uchan->enabled == 0 && + strcmp(PATH1, uchan->pathname) == 0 && + strncmp(uchan->name, "channel0", 8) == 0 && + uchan->name[LTTNG_UST_SYM_NAME_LEN - 1] == '\0' && + uchan->ctx != NULL && + uchan->events != NULL && + uchan->attr.overwrite == attr.attr.overwrite, + "Validate UST channel"); + + trace_ust_destroy_channel(uchan); + } + + static void test_create_ust_event(void) + { + struct ltt_ust_event *event; + struct lttng_event ev; + + memset(&ev, 0, sizeof(ev)); + strncpy(ev.name, get_random_string(), LTTNG_SYMBOL_NAME_LEN); + ev.type = LTTNG_EVENT_TRACEPOINT; + ev.loglevel_type = LTTNG_EVENT_LOGLEVEL_ALL; + + event = trace_ust_create_event(&ev, NULL); + + ok(event != NULL, "Create UST event"); + + ok(event->enabled == 0 && + event->attr.instrumentation == LTTNG_UST_TRACEPOINT && + strcmp(event->attr.name, ev.name) == 0 && + event->attr.name[LTTNG_UST_SYM_NAME_LEN - 1] == '\0', + "Validate UST event"); + + trace_ust_destroy_event(event); + } + + static void test_create_ust_context(void) + { + struct lttng_event_context ectx; + struct ltt_ust_context *uctx; + + ectx.ctx = LTTNG_EVENT_CONTEXT_VTID; + + uctx = trace_ust_create_context(&ectx); + ok(uctx != NULL, "Create UST context"); + + ok((int) uctx->ctx.ctx == LTTNG_UST_CONTEXT_VTID, + "Validate UST context"); + } + + int main(int argc, char **argv) + { + diag("UST data structures unit test"); + + plan_tests(NUM_TESTS); + + test_create_one_ust_session(); + test_create_ust_metadata(); + test_create_ust_channel(); + test_create_ust_event(); + test_create_ust_context(); + + return exit_status(); + }