Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests: ust: clock override plugin #14

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,7 @@ AC_CONFIG_FILES([
tests/regression/ust/java-log4j/Makefile
tests/regression/ust/python-logging/Makefile
tests/regression/ust/getcpu-override/Makefile
tests/regression/ust/clock-override/Makefile
tests/stress/Makefile
tests/unit/Makefile
tests/unit/ini_config/Makefile
Expand Down
1 change: 1 addition & 0 deletions tests/fast_regression
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ regression/ust/java-jul/test_java_jul
regression/ust/java-log4j/test_java_log4j
regression/ust/python-logging/test_python_logging
regression/ust/getcpu-override/test_getcpu_override
regression/ust/clock-override/test_clock_override
regression/ust/test_event_basic
regression/ust/test_event_tracef
regression/ust/test_event_wildcard
Expand Down
2 changes: 1 addition & 1 deletion tests/regression/ust/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ if HAVE_LIBLTTNG_UST_CTL
SUBDIRS = nprocesses high-throughput low-throughput before-after multi-session \
overlap buffers-pid linking daemon exit-fast fork libc-wrapper \
periodical-metadata-flush java-jul java-log4j python-logging \
getcpu-override
getcpu-override clock-override

EXTRA_DIST = test_event_basic test_event_wildcard test_event_tracef test_event_perf

Expand Down
37 changes: 37 additions & 0 deletions tests/regression/ust/clock-override/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
AM_CPPFLAGS = -I$(srcdir)

# The rpath is necessary because libtool won't build a shared library
# if it's noinst_
GETCPU_LIBTOOL_FLAGS = \
-module \
-shared \
-avoid-version \
--no-as-needed \
-rpath $(abs_builddir)

noinst_LTLIBRARIES = lttng-ust-clock-override-test.la
lttng_ust_clock_override_test_la_LDFLAGS = $(GETCPU_LIBTOOL_FLAGS)

if LTTNG_TOOLS_BUILD_WITH_LIBDL
lttng_ust_clock_override_test_la_LIBADD = -ldl
endif
if LTTNG_TOOLS_BUILD_WITH_LIBC_DL
lttng_ust_clock_override_test_la_LIBADD = -lc
endif

noinst_SCRIPTS = test_clock_override run-clock-override
EXTRA_DIST = test_clock_override run-clock-override

all-local:
@if [ x"$(srcdir)" != x"$(builddir)" ]; then \
for script in $(EXTRA_DIST); do \
cp -f $(srcdir)/$$script $(builddir); \
done; \
fi

clean-local:
@if [ x"$(srcdir)" != x"$(builddir)" ]; then \
for script in $(EXTRA_DIST); do \
rm -f $(builddir)/$$script; \
done; \
fi
114 changes: 114 additions & 0 deletions tests/regression/ust/clock-override/lttng-ust-clock-override-test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/*
* lttng-clock-override-test.c
*
* Copyright (c) 2014 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
* Copyright (c) 2015 Jonthan Rajotte <jonathan.rajotte-julien@efficios.com>
* Based on lttng-clock-override-example.c from LTTng-ust example
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <stdio.h>
#include <lttng/ust-clock.h>

static
uint64_t plugin_read64(void)
{
/* Freeze time */
return 0;
}

static
uint64_t plugin_freq(void)
{
return 1000; /* 1KHz clock (very coarse!) */
}

static
int plugin_uuid(char *uuid)
{
const char myuuid[] = "83c63deb-7aa4-48fb-abda-946f400d76e6";
memcpy(uuid, myuuid, LTTNG_UST_UUID_STR_LEN);
return 0;
}

static
const char *plugin_name(void)
{
return "lttng_test_clock_override";
}

static
const char *plugin_description(void)
{
return "Freeze time with 1KHz for regression test";
}

void lttng_ust_clock_plugin_init(void)
{
int ret;

ret = lttng_ust_trace_clock_set_read64_cb(plugin_read64);
if (ret) {
fprintf(stderr, "Error setting clock override read64 callback: %s\n",
strerror(-ret));
goto error;
}
ret = lttng_ust_trace_clock_set_freq_cb(plugin_freq);
if (ret) {
fprintf(stderr, "Error setting clock override freq callback: %s\n",
strerror(-ret));
goto error;
}
ret = lttng_ust_trace_clock_set_uuid_cb(plugin_uuid);
if (ret) {
fprintf(stderr, "Error setting clock override uuid callback: %s\n",
strerror(-ret));
goto error;
}

ret = lttng_ust_trace_clock_set_name_cb(plugin_name);
if (ret) {
fprintf(stderr, "Error setting clock override name callback: %s\n",
strerror(-ret));
goto error;
}

ret = lttng_ust_trace_clock_set_description_cb(plugin_description);
if (ret) {
fprintf(stderr, "Error setting clock override description callback: %s\n",
strerror(-ret));
goto error;
}

ret = lttng_ust_enable_trace_clock_override();
if (ret) {
fprintf(stderr, "Error enabling clock override: %s\n",
strerror(-ret));
goto error;
}

return;

error:
exit(EXIT_FAILURE);
}
13 changes: 13 additions & 0 deletions tests/regression/ust/clock-override/run-clock-override
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/sh

# launch with: run-clock-override progname args
DIR=$(dirname $0)
DIR=$(readlink -f $DIR)

if [ -x "$DIR/.libs/lttng-ust-clock-override-test.so" ]; then
ret=`LTTNG_UST_CLOCK_PLUGIN="$DIR/.libs/lttng-ust-clock-override-test.so" $@`
exit $ret
else
echo "Clock-override missing shared object"
exit $1
fi
190 changes: 190 additions & 0 deletions tests/regression/ust/clock-override/test_clock_override
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
#!/bin/bash
#
# Copyright (C) - 2015 Jonathan Rajotte <jonathan.rajotte-julien@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
TEST_DESC="UST - Getcpu override plugin"

CURDIR=$(dirname $0)/
TESTDIR=$CURDIR/../../..
SESSION_NAME="clock_override"

TESTAPP_PATH="$TESTDIR/utils/testapp"
TESTAPP_NAME="gen-ust-events"
TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
TESTAPP_WRAPPER="run-getcpu-override"
NUM_EVENT=256
EVENT_NAME="tp:tptest"
LTTNG_UST_CLOCK_PLUGIN_SO="lttng-ust-clock-override-test.so"
LIBS_DIR=".libs"

METADATA_CLOCK_START_TOKEN="clock {"
METADATA_CLOCK_END_TOKEN="};"

METADATA_TOKEN_LIST=(
"name"
"uuid"
"description"
"freq"
)

UST_CLOCK_TOKEN_VALUE=(
"lttng_test_clock_override"
"83c63deb-7aa4-48fb-abda-946f400d76e6"
"Freeze time with 1KHz for regression test"
"1000"
)

NUM_TESTS=33

source $TESTDIR/utils/utils.sh

if [ ! -x "$CURDIR/$LIBS_DIR/$LTTNG_UST_CLOCK_PLUGIN_SO" ]; then
BAIL_OUT "No shared object generated"
fi

# MUST set TESTDIR before calling those functions
function run_app()
{
$TESTAPP_BIN $NUM_EVENT
ok $? "Application done"
}

function extract_clock_metadata()
{
local metadata_file=$1
local clock_metadata_file_destination=$2
cat $metadata_file \
| sed -n "/$METADATA_CLOCK_START_TOKEN/,/$METADATA_CLOCK_END_TOKEN/p" \
> $clock_metadata_file_destination
ok $? "Clock metadata extraction"
}

function extract_clock_metadata_token()
{
local clock_metadata_file=$1
local token=$2
# Look for token and get value between ""
cat $clock_metadata_file | grep $token | awk -F"= |;" '{print $2}' | tr -d '"'
}

function test_getcpu_override_metadata()
{
local ctf_metadata_file=$(mktemp -p $TRACE_PATH ctf-metadata.XXXXX)
local clock_metadata_file=$(mktemp -p $TRACE_PATH clock-metadata.XXXXX)
local result=""

diag "Clock override plugin metadata test"

# LTTNG_UST_CLOCK_PLUGIN need to be defined for lttng-sessiond.
export LTTNG_UST_CLOCK_PLUGIN=$CURDIR/.libs/$LTTNG_UST_CLOCK_PLUGIN_SO
start_lttng_sessiond
unset LTTNG_UST_CLOCK_PLUGIN

create_lttng_session_ok $SESSION_NAME $TRACE_PATH
enable_ust_lttng_event_ok $SESSION_NAME "$EVENT_NAME"
start_lttng_tracing_ok $SESSION_NAME
run_app
stop_lttng_tracing_ok $SESSION_NAME
destroy_lttng_session_ok $SESSION_NAME
stop_lttng_sessiond

$BABELTRACE_BIN -o ctf-metadata -w $ctf_metadata_file $TRACE_PATH
ok $? "Metadata extraction from babeltrace"

extract_clock_metadata $ctf_metadata_file $clock_metadata_file

test ${#METADATA_TOKEN_LIST[@]} -eq ${#UST_CLOCK_TOKEN_VALUE[@]}
ok $? "Tokens to check(${#METADATA_TOKEN_LIST[@]}) and provided values(${#UST_CLOCK_TOKEN_VALUE[@]}) count is equal"

local counter=0
while [ "$counter" -lt "${#METADATA_TOKEN_LIST[@]}" ]; do
result=$(extract_clock_metadata_token $clock_metadata_file \
${METADATA_TOKEN_LIST[$counter]})
test "$result" == "${UST_CLOCK_TOKEN_VALUE[$counter]}"
ok $? "Token \"${METADATA_TOKEN_LIST[$counter]}\" expect:${UST_CLOCK_TOKEN_VALUE[$counter]} got:$result"
let "counter++"
done
rm -rf $ctf_metadata_file
rm -rf $clock_metadata_file
}

function test_getcpu_override_timestamp()
{
diag "Clock override test"

# Test without the plugin
diag "Plugin disabled"
start_lttng_sessiond
create_lttng_session_ok $SESSION_NAME $TRACE_PATH
enable_ust_lttng_event_ok $SESSION_NAME "$EVENT_NAME"
start_lttng_tracing_ok $SESSION_NAME
run_app
stop_lttng_tracing_ok $SESSION_NAME
destroy_lttng_session_ok $SESSION_NAME

# Use Babeltrace with "-n all" to give a comma separated list for
# easy extraction of timestamps.
unique_timestamps_count=$($BABELTRACE_BIN -n all $TRACE_PATH | \
cut -d, -f1 | uniq | wc -l)
test $unique_timestamps_count -gt 1
ok $? "Unique event timestamps without clock override: $unique_timestamps_count expect >1"
stop_lttng_sessiond

# Test with clock override plugin.
# LTTNG_UST_CLOCK_PLUGIN need to be defined for both lttng-sessiond.
diag "Plugin enabled"
export LTTNG_UST_CLOCK_PLUGIN=$CURDIR/.libs/$LTTNG_UST_CLOCK_PLUGIN_SO
start_lttng_sessiond
unset LTTNG_UST_CLOCK_PLUGIN
create_lttng_session_ok $SESSION_NAME $TRACE_PATH
enable_ust_lttng_event_ok $SESSION_NAME "$EVENT_NAME"
start_lttng_tracing_ok $SESSION_NAME
run_app
stop_lttng_tracing_ok $SESSION_NAME
destroy_lttng_session_ok $SESSION_NAME
stop_lttng_sessiond

# Use Babeltrace with "-n all" to give a comman separated list for
# easy extraction of timestamps.
unique_timestamps_count=$($BABELTRACE_BIN -n all $TRACE_PATH | \
cut -d, -f1 | uniq | wc -l)
test $unique_timestamps_count -eq 1
ok $? "Unique event timestamps with clock override: $unique_timestamps_count expect 1"
}

plan_tests $NUM_TESTS

print_test_banner "$TEST_DESC"

TESTS=(
"test_getcpu_override_metadata"
"test_getcpu_override_timestamp"
)

TEST_COUNT=${#TESTS[@]}
i=0

while [ "$i" -lt "$TEST_COUNT" ]; do

TRACE_PATH=$(mktemp -d)

# Execute test
${TESTS[$i]}

rm -rf $TRACE_PATH

let "i++"
done