From 355f483d1713d1e047ad6256bea039cb693ae38e Mon Sep 17 00:00:00 2001 From: David Goulet Date: Tue, 6 Mar 2012 16:59:55 -0500 Subject: [PATCH] Improve tests and change tests/ directory layout Add run-report.py and test_list.py files which are an extended test framework providing memory and CPU sampling of the session daemon during the tests. Tests are now divided on a per package basis. The kernel/ directory contains integration tests for lttng-modules (kernel tracer). ust/ directory contains tests for lttng-ust and tools/ directory has the unit tests of lttng-tools itself which does not test tracer integration. First patch aimed at improving test coverage of the lttng 2.0 toolchain and provide the python framework for more detailled analysis. Use make check to run them all or use run-report.py and select which tests to run in test_list.py. Signed-off-by: David Goulet --- .gitignore | 20 +- configure.ac | 7 +- tests/Makefile.am | 37 +- tests/kernel/Makefile.am | 15 + .../kernel_all_events_basic.c | 2 +- tests/{lttng => kernel}/kernel_event_basic.c | 2 +- tests/{lttng => kernel}/run-kernel-tests.sh | 14 +- tests/{lttng => kernel}/runall.sh | 4 +- tests/run-report.py | 416 ++++++++++++++++++ tests/runall.sh | 42 +- tests/test_list.py | 49 +++ tests/tools/Makefile.am | 24 + tests/tools/runall.sh | 23 + tests/{ => tools}/test_kernel_data_trace.c | 0 tests/{ => tools}/test_sessions.c | 0 tests/{ => tools}/test_ust_data_trace.c | 0 tests/ust/Makefile.am | 16 + .../{ust-nevents => ust/nevents}/Makefile.am | 0 .../nevents}/gen-nevents.c | 0 tests/ust/nevents/run | 41 ++ tests/{ust-nevents => ust/nevents}/tp.c | 0 .../run => ust/nevents/ust-nevents} | 13 +- .../nevents}/ust_gen_nevents.h | 0 .../nprocesses}/Makefile.am | 0 .../nprocesses}/gen-events-time.c | 0 tests/ust/nprocesses/run | 41 ++ tests/{ust-nprocesses => ust/nprocesses}/tp.c | 0 .../run => ust/nprocesses/ust-nprocesses} | 13 +- .../nprocesses}/ust_gen_event.h | 2 +- tests/{lttng => ust}/run-ust-global-tests.sh | 14 +- tests/ust/runall.sh | 23 + .../ust_global_all_events_basic.c | 2 +- tests/{lttng => ust}/ust_global_event_basic.c | 0 tests/utils.h | 23 +- tests/utils.sh | 35 +- 35 files changed, 741 insertions(+), 137 deletions(-) create mode 100644 tests/kernel/Makefile.am rename tests/{lttng => kernel}/kernel_all_events_basic.c (99%) rename tests/{lttng => kernel}/kernel_event_basic.c (99%) rename tests/{lttng => kernel}/run-kernel-tests.sh (75%) rename tests/{lttng => kernel}/runall.sh (80%) create mode 100755 tests/run-report.py create mode 100644 tests/test_list.py create mode 100644 tests/tools/Makefile.am create mode 100755 tests/tools/runall.sh rename tests/{ => tools}/test_kernel_data_trace.c (100%) rename tests/{ => tools}/test_sessions.c (100%) rename tests/{ => tools}/test_ust_data_trace.c (100%) create mode 100644 tests/ust/Makefile.am rename tests/{ust-nevents => ust/nevents}/Makefile.am (100%) rename tests/{ust-nevents => ust/nevents}/gen-nevents.c (100%) create mode 100755 tests/ust/nevents/run rename tests/{ust-nevents => ust/nevents}/tp.c (100%) rename tests/{ust-nevents/run => ust/nevents/ust-nevents} (81%) rename tests/{ust-nevents => ust/nevents}/ust_gen_nevents.h (100%) rename tests/{ust-nprocesses => ust/nprocesses}/Makefile.am (100%) rename tests/{ust-nprocesses => ust/nprocesses}/gen-events-time.c (100%) create mode 100755 tests/ust/nprocesses/run rename tests/{ust-nprocesses => ust/nprocesses}/tp.c (100%) rename tests/{ust-nprocesses/run => ust/nprocesses/ust-nprocesses} (87%) rename tests/{ust-nprocesses => ust/nprocesses}/ust_gen_event.h (98%) rename tests/{lttng => ust}/run-ust-global-tests.sh (77%) create mode 100755 tests/ust/runall.sh rename tests/{lttng => ust}/ust_global_all_events_basic.c (99%) rename tests/{lttng => ust}/ust_global_event_basic.c (100%) diff --git a/.gitignore b/.gitignore index 0eacb03bb..ac0b2f433 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ *.swp *.o *.swo +*.pyc Makefile .libs/ .deps/ @@ -34,14 +35,15 @@ src/bin/lttng-sessiond/lttng-sessiond src/bin/lttng/lttng src/bin/lttng-consumerd/lttng-consumerd -tests/test_sessions -tests/test_kernel_data_trace -tests/test_ust_data_trace -tests/kernel_all_events_basic -tests/kernel_event_basic -tests/ust_global_all_events_basic -tests/ust_global_event_basic -tests/ust-nevents/gen-nevents -tests/ust-nprocesses/gen-events-time +# Tests +test_sessions +test_kernel_data_trace +test_ust_data_trace +kernel_all_events_basic +kernel_event_basic +ust_global_all_events_basic +ust_global_event_basic +gen-nevents +gen-events-time benchmark/ diff --git a/configure.ac b/configure.ac index 5808c7914..f8518c568 100644 --- a/configure.ac +++ b/configure.ac @@ -194,8 +194,11 @@ AC_CONFIG_FILES([ src/bin/lttng-sessiond/Makefile src/bin/lttng/Makefile tests/Makefile - tests/ust-nevents/Makefile - tests/ust-nprocesses/Makefile + tests/kernel/Makefile + tests/tools/Makefile + tests/ust/Makefile + tests/ust/nevents/Makefile + tests/ust/nprocesses/Makefile ]) AC_OUTPUT diff --git a/tests/Makefile.am b/tests/Makefile.am index 8dd05a4f0..27570566b 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,43 +1,12 @@ -SUBDIRS = . +SUBDIRS = . tools kernel AM_CFLAGS = -g -Wall AM_LDFLAGS = -lurcu -lurcu-cds -EXTRA_DIST = runall.sh utils.sh lttng/runall.sh lttng/run-kernel-tests.sh - -noinst_PROGRAMS = test_sessions test_kernel_data_trace \ - kernel_all_events_basic kernel_event_basic - -UTILS=utils.h -SESSIONS=$(top_srcdir)/src/bin/lttng-sessiond/session.c -KERN_DATA_TRACE=$(top_srcdir)/src/bin/lttng-sessiond/trace-kernel.c -LIBLTTNG=$(top_srcdir)/src/lib/lttng-ctl/lttng-ctl.c \ - $(top_srcdir)/src/common/sessiond-comm/sessiond-comm.c - -test_sessions_SOURCES = test_sessions.c $(UTILS) $(SESSIONS) -test_sessions_LDADD = $(top_builddir)/src/common/libcommon.la \ - $(top_builddir)/src/common/hashtable/libhashtable.la - -test_kernel_data_trace_SOURCES = test_kernel_data_trace.c $(UTILS) $(KERN_DATA_TRACE) - -kernel_all_events_basic_SOURCES = lttng/kernel_all_events_basic.c $(UTILS) $(LIBLTTNG) - -kernel_event_basic_SOURCES = lttng/kernel_event_basic.c $(UTILS) $(LIBLTTNG) +EXTRA_DIST = run-report.py test_list.py utils.sh utils.h if HAVE_LIBLTTNG_UST_CTL -SUBDIRS += ust-nevents ust-nprocesses -EXTRA_DIST += lttng/run-ust-global-tests.sh -noinst_PROGRAMS += ust_global_event_basic ust_global_all_events_basic test_ust_data_trace - -UST_DATA_TRACE=$(top_srcdir)/src/bin/lttng-sessiond/trace-ust.c - -test_ust_data_trace_SOURCES = test_ust_data_trace.c $(UTILS) $(UST_DATA_TRACE) -test_ust_data_trace_LDADD = $(top_builddir)/src/common/libcommon.la \ - $(top_builddir)/src/common/hashtable/libhashtable.la - -ust_global_all_events_basic_SOURCES = lttng/ust_global_all_events_basic.c $(UTILS) $(LIBLTTNG) - -ust_global_event_basic_SOURCES = lttng/ust_global_event_basic.c $(UTILS) $(LIBLTTNG) +SUBDIRS += ust endif # HAVE_LIBLTTNG_UST_CTL check-am: diff --git a/tests/kernel/Makefile.am b/tests/kernel/Makefile.am new file mode 100644 index 000000000..50e771961 --- /dev/null +++ b/tests/kernel/Makefile.am @@ -0,0 +1,15 @@ +AM_CFLAGS = -g -Wall -I../ +AM_LDFLAGS = -lurcu -lurcu-cds + +EXTRA_DIST = runall.sh run-kernel-tests.sh + +noinst_PROGRAMS = kernel_all_events_basic kernel_event_basic + +UTILS=utils.h +LIBLTTNG=$(top_srcdir)/src/lib/lttng-ctl/lttng-ctl.c \ + $(top_srcdir)/src/common/sessiond-comm/sessiond-comm.c + + +kernel_all_events_basic_SOURCES = kernel_all_events_basic.c $(UTILS) $(LIBLTTNG) + +kernel_event_basic_SOURCES = kernel_event_basic.c $(UTILS) $(LIBLTTNG) diff --git a/tests/lttng/kernel_all_events_basic.c b/tests/kernel/kernel_all_events_basic.c similarity index 99% rename from tests/lttng/kernel_all_events_basic.c rename to tests/kernel/kernel_all_events_basic.c index 6964a6f97..2e56e6a67 100644 --- a/tests/lttng/kernel_all_events_basic.c +++ b/tests/kernel/kernel_all_events_basic.c @@ -27,7 +27,7 @@ #include -#include "../utils.h" +#include "utils.h" int lttng_opt_quiet; diff --git a/tests/lttng/kernel_event_basic.c b/tests/kernel/kernel_event_basic.c similarity index 99% rename from tests/lttng/kernel_event_basic.c rename to tests/kernel/kernel_event_basic.c index 0af797c05..a7d7dfae8 100644 --- a/tests/lttng/kernel_event_basic.c +++ b/tests/kernel/kernel_event_basic.c @@ -27,7 +27,7 @@ #include -#include "../utils.h" +#include "utils.h" int lttng_opt_quiet; diff --git a/tests/lttng/run-kernel-tests.sh b/tests/kernel/run-kernel-tests.sh similarity index 75% rename from tests/lttng/run-kernel-tests.sh rename to tests/kernel/run-kernel-tests.sh index d5a41382b..2881c426e 100755 --- a/tests/lttng/run-kernel-tests.sh +++ b/tests/kernel/run-kernel-tests.sh @@ -13,12 +13,16 @@ function start_tests () { for bin in ${tests[@]}; do + start_sessiond + ./$bin $tmpdir # Test must return 0 to pass. if [ $? -ne 0 ]; then exit_code=1 + stop_sessiond break fi + stop_sessiond done # Cleaning up @@ -36,17 +40,13 @@ function check_lttng_modules () fi } -echo -e "\n--------------------------------------------------" -echo -e "Kernel tracer - Testing lttng client (liblttngctl)" -echo -e "--------------------------------------------------" +echo -e "\n---------------------" +echo -e "Testing Kernel tracer" +echo -e "---------------------" # Detect lttng-modules installed - check_lttng_modules -# Simply wait for the session daemon bootstrap -sleep 1 - start_tests exit $exit_code diff --git a/tests/lttng/runall.sh b/tests/kernel/runall.sh similarity index 80% rename from tests/lttng/runall.sh rename to tests/kernel/runall.sh index c5446c990..2b76e5355 100755 --- a/tests/lttng/runall.sh +++ b/tests/kernel/runall.sh @@ -1,6 +1,8 @@ #!/bin/bash -tests=( lttng/run-kernel-tests.sh lttng/run-ust-global-tests.sh ) +DIR=$(dirname $0) + +tests=( $DIR/run-kernel-tests.sh ) exit_code=0 function start_tests () diff --git a/tests/run-report.py b/tests/run-report.py new file mode 100755 index 000000000..0b67027de --- /dev/null +++ b/tests/run-report.py @@ -0,0 +1,416 @@ +#!/usr/bin/env python + +import os, sys +import subprocess +import threading +import Queue +import time + +from signal import signal, SIGTERM, SIGINT + +SESSIOND_BIN_NAME = "lttng-sessiond" +SESSIOND_BIN_PATH = "src/bin/lttng-sessiond/.libs/" +TESTDIR_PATH = "" + +PRINT_BRACKET = "\033[1;34m[\033[1;33m+\033[1;34m]\033[00m" +PRINT_RED_BRACKET = "\033[1;31m[+]\033[00m" +PRINT_GREEN_BRACKET = "\033[1;32m[+]\033[00m" +PRINT_ARROW = "\033[1;32m-->\033[00m" + +is_root = 1 +no_stats = 0 +stop_sampling = 1 + +top_cpu_legend = { 'us': "User CPU time", 'sy': "System CPU time", + 'id': "Idle CPU time", 'ni': "Nice CPU time", 'wa': "iowait", + 'hi': "Hardware IRQ", 'si': "Software Interrupts", 'st': "Steal Time", } + +cpu_ret_q = Queue.Queue() +mem_ret_q = Queue.Queue() +test_ret_q = Queue.Queue() + +global sdaemon_proc +global worker_proc + +def cpu_create_usage_dict(top_line): + """ + Return a dictionnary from a 'top' cpu line. + Ex: Cpu(s): 2.1%us, 1.2%sy, 0.0%ni, 96.2%id, 0.4%wa, 0.0%hi, 0.0%si, 0.0%st + """ + top_dict = {'us': 0, 'sy': 0, 'ni': 0, 'id': 0, 'wa': 0, 'hi': 0, 'si': 0, 'st': 0} + + # Split expression and remove first value which is "Cpu(s)" + top_line = top_line.replace(",","") + words = top_line.split()[1:] + + for word in words: + index = word.find('%') + # Add the value to the dictionnary + top_dict[word[index + 1:]] = float(word[:index]) + + return top_dict + +def cpu_average_usage(top_lines): + """ + Return a dictionnary of 'top' CPU stats but averaging all values. + """ + avg_dict = {'us': 0, 'sy': 0, 'ni': 0, 'id': 0, 'wa': 0, 'hi': 0, 'si': 0, 'st': 0} + # Average count + count = 0.0 + + for line in top_lines: + tmp_dict = cpu_create_usage_dict(line) + # Add value to avg dictionnary + for key in tmp_dict: + avg_dict[key] += tmp_dict[key] + + count += 1.0 + + for key in avg_dict: + avg_dict[key] = avg_dict[key] / count + + return (count, avg_dict) + +def cpu_sample_usage(pid=None): + """ + Sample CPU usage for num iterations. + If num is greater than 1, the average will be computed. + """ + args = ["top", "-b", "-n", "1"] + if pid: + args.append("-p") + args.append(str(pid)) + + # Spawn top process + top = subprocess.Popen(args, stdout = subprocess.PIPE) + + grep = subprocess.Popen(["grep", "^Cpu"], stdin = top.stdout, + stdout = subprocess.PIPE) + top.stdout.close() + + return grep.communicate()[0].strip("\n") + +def mem_sample_usage(pid): + """ + Sample memory usage using /proc and a pid + """ + args = ["cat", "/proc/" + str(pid) + "/status"] + + if not os.path.isfile(args[1]): + return -1 + + mem_proc = subprocess.Popen(args, stdout = subprocess.PIPE) + + grep = subprocess.Popen(["grep", "^VmRSS"], stdin = mem_proc.stdout, + stdout = subprocess.PIPE) + mem_proc.stdout.close() + + # Return virtual memory size in kilobytes (kB) + #ret = grep.communicate()[0].split() + ret = grep.communicate()[0].split() + + if len(ret) > 1: + ret = ret[1] + else: + ret = 0 + + return int(ret) + +class SamplingWorker(threading.Thread): + def __init__(self, s_type, worker = None, delay = 0.2, pid = 0): + threading.Thread.__init__ (self) + self.s_type = s_type + self.delay = delay + self.pid = pid + self.worker = worker + + def run(self): + count = 1 + lines = [] + + if self.s_type == "cpu": + while 1: + if self.worker == None: + cpu_line = cpu_sample_usage(self.pid) + lines.append(cpu_line) + break + elif self.worker.is_alive(): + cpu_line = cpu_sample_usage(self.pid) + lines.append(cpu_line) + else: + break + + # Delay sec per memory sampling + time.sleep(self.delay) + + count, stats = cpu_average_usage(lines) + cpu_ret_q.put((count, stats)) + # grep process has ended here + + elif self.s_type == "mem": + count = 0 + mem_stat = 0 + + while 1: + if self.worker == None: + cpu_line = cpu_sample_usage(self.pid) + lines.append(cpu_line) + break + elif self.worker.is_alive(): + mem_stat += get_mem_usage(self.pid) + count += 1 + else: + break + + # Delay sec per memory sampling + time.sleep(self.delay) + + mem_ret_q.put((count, mem_stat)) + +class TestWorker(threading.Thread): + def __init__(self, path, name): + threading.Thread.__init__(self) + self.path = path + self.name = name + + def run(self): + bin_path_name = os.path.join(self.path, self.name) + + env = os.environ + env['TEST_NO_SESSIOND'] = '1' + + test = subprocess.Popen([bin_path_name], env=env) + test.wait() + + # Send ret value to main thread + test_ret_q.put(test.returncode) + +def get_pid(procname): + """ + Return pid of process name using 'pidof' command + """ + pidof = subprocess.Popen(["pidof", procname], stdout = subprocess.PIPE) + pid = pidof.communicate()[0].split() + + if pid == []: + return 0 + + return int(pid[0]) + +def spawn_session_daemon(): + """ + Exec the session daemon and return PID + """ + global sdaemon_proc + + pid = get_pid(SESSIOND_BIN_NAME) + if pid != 0: + os.kill(pid, SIGTERM) + + bin_path = os.path.join(TESTDIR_PATH, "..", SESSIOND_BIN_PATH, SESSIOND_BIN_NAME) + + if not os.path.isfile(bin_path): + print "Error: No session daemon binary found. Compiled?" + return 0 + + try: + sdaemon_proc = subprocess.Popen([bin_path, "-d"], shell=False, + stderr = subprocess.PIPE) + except OSError, e: + print e + return 0 + + return get_pid(SESSIOND_BIN_NAME) + +def start_test(name): + """ + Spawn test and return exit code + """ + tw = TestWorker(".", name) + tw.start() + + return test_ret_q.get(True) + +def print_cpu_stats(stats, count): + """ + Pretty print on one line the CPU stats + """ + sys.stdout.write(PRINT_ARROW + " Cpu [sampled %d time(s)]:\n " % (count)) + for stat in stats: + sys.stdout.write(" %s: %.2f, " % (stat, stats[stat])) + print "" + +def get_cpu_usage(delay=1, pid=0): + """ + Spawn a worker thread to sample cpu usage. + """ + sw = SamplingWorker("cpu", delay = delay, pid = pid) + sw.start() + + return cpu_ret_q.get(True) + +def get_mem_usage(pid): + """ + Get memory usage for PID + """ + return mem_sample_usage(pid) + +def print_test_success(ret, expect): + """ + Print if test has failed or pass according to the expected value. + """ + if ret != expect: + print "\n" + PRINT_RED_BRACKET + \ + " Failed: ret = %d (expected %d)" % (ret, expect) + return 1 + else: + print "\n" + PRINT_BRACKET + \ + " Passed: ret = %d (expected %d)" % (ret, expect) + return 0 + +def run_test(test): + """ + Run test 'name' and output report of the test with stats. + """ + global worker_proc + global sdaemon_proc + dem_pid = 0 # Session daemon pid + + print PRINT_BRACKET + " %s" % (test['name']) + print PRINT_ARROW + " %s" % (test['desc']) + if no_stats: + print PRINT_ARROW + " Statistics will NOT be collected" + else: + print PRINT_ARROW + " Statistics of the session daemon will be collected" + + if test['kern'] and not is_root: + print "Needs root for kernel tracing. Skipping" + return 0 + + if not os.path.isfile(test['bin']): + print "Unable to find test file '%s'. Skipping" + return 0 + + # No session daemon needed + if not test['daemon']: + print PRINT_ARROW + " No session daemon needed" + ret = start_test(test['bin']) + print_test_success(ret, test['success']) + return 0 + else: + print PRINT_ARROW + " Session daemon needed" + + dem_pid = spawn_session_daemon() + if dem_pid <= 0: + print "Unable to start %s. Stopping" % (SESSIOND_BIN_NAME) + print sdaemon_proc.communicate()[1] + return 0 + + print PRINT_BRACKET + " Session daemon spawned (pid: %d)\n" % (dem_pid) + + if not no_stats: + mem_before = get_mem_usage(dem_pid) + print PRINT_BRACKET + " Stats *before* test:" + print PRINT_ARROW + " Mem (kB): %d" % (mem_before) + cpu_count, cpu_stats = get_cpu_usage(pid = dem_pid) + print_cpu_stats(cpu_stats, cpu_count) + + tw = TestWorker(".", test['bin']) + tw.start() + + if not no_stats: + # Start CPU sampling for test + sw_cpu = SamplingWorker("cpu", worker = tw, pid = dem_pid) + sw_cpu.start() + sw_mem = SamplingWorker("mem", worker = tw, pid = dem_pid) + sw_mem.start() + + ret = test_ret_q.get(True) + + if not no_stats: + time.sleep(2) + # Compute memory average + mem_count, mem_during = mem_ret_q.get(True) + mem_during = float(mem_during) / float(mem_count) + cpu_count, cpu_stats = cpu_ret_q.get(True) + + print "\n" + PRINT_BRACKET + " Stats *during* test:" + print PRINT_ARROW + " Mem (kB): %.0f [sampled %d time(s)]" % (mem_during, mem_count) + print_cpu_stats(cpu_stats, cpu_count) + + mem_after = get_mem_usage(dem_pid) + print "\n" + PRINT_BRACKET + " Stats *after* test:" + print PRINT_ARROW + " Mem (kB): %d" % (mem_after) + cpu_count, cpu_stats = get_cpu_usage(pid = dem_pid) + print_cpu_stats(cpu_stats, cpu_count) + + print "\n" + PRINT_BRACKET + " Memory usage differences:" + print PRINT_ARROW + " Diff during and before (kB): %d" % (mem_during - mem_before) + print PRINT_ARROW + " Diff during and after (kB): %d" % (mem_during - mem_after) + print PRINT_ARROW + " Diff before and after (kB): %d" % (mem_after - mem_before) + + # Return value of 0 means that is passed else it failed + ret = print_test_success(ret, test['success']) + + # Stop session daemon + if dem_pid > 0: + print PRINT_BRACKET + " Stopping session daemon (pid: %d)..." % (dem_pid) + try: + os.kill(dem_pid, SIGTERM) + # This call simply does not work... It seems python does not relay the signal + # to the child processes of sdaemon_proc. + # sdaemon_proc.terminate() + if ret != 0: + print sdaemon_proc.communicate()[1] + elif sdaemon_proc.returncode == None: + sdaemon_proc.communicate() + except OSError, e: + print e + + # Make sure all thread are released + if not no_stats: + tw.join() + sw_cpu.join() + sw_mem.join() + + return ret + +def main(): + for test in Tests: + if not test['enabled']: + continue + + ret = run_test(test) + if ret != 0: + # Stop all tests, the last one failed + return + print "" + +def cleanup(signo, stack): + """ Cleanup function """ + sys.exit(0) + +if __name__ == "__main__": + if not os.getuid() == 0: + is_root = 0 + print "NOTICE: Not root. No kernel tracing will be tested\n" + + if os.path.isfile("test_list.py"): + from test_list import Tests + else: + print "No test_list.py found. Stopping" + cleanup(0, 0) + + TESTDIR_PATH = os.getcwd() + + if len(sys.argv) > 1: + if sys.argv[1] == "--no-stats": + no_stats = 1 + + try: + signal(SIGTERM, cleanup) + signal(SIGINT, cleanup) + main() + cleanup(0, 0) + except KeyboardInterrupt: + cleanup(0, 0) diff --git a/tests/runall.sh b/tests/runall.sh index 5e1c0f537..0adbb2e4b 100755 --- a/tests/runall.sh +++ b/tests/runall.sh @@ -19,11 +19,7 @@ #### ADD TESTS HERE #### -# A spawned session daemon is needed for those tests -test_with_sessiond=( lttng/runall.sh ust-nevents/run ust-nprocesses/run ) - -# No session daemon needed -test_no_sessiond=( test_sessions test_kernel_data_trace test_ust_data_trace ) +tests=( kernel/runall.sh ust/runall.sh tools/runall.sh ) #### END TESTS HERE #### @@ -31,35 +27,9 @@ TESTDIR=$(dirname $0) source $TESTDIR/utils.sh -## NO Session daemon ## -for bin in ${test_no_sessiond[@]}; -do - if [ ! -e $bin ]; then - echo -e "$bin not found, passing" - continue - fi - - ./$bin - # Test must return 0 to pass. - if [ $? -ne 0 ]; then - echo -e '\e[1;31mFAIL\e[0m' - echo "" - exit 1 - fi -done - -# With session daemon -start_sessiond -out=$? -if [ $out -eq 2 ]; then - # Kernel version is not compatible. - exit 0 -elif [ $out -ne 0 ]; then - echo "NOT bad $?" - exit 1 -fi - -for bin in ${test_with_sessiond[@]}; +## lttng-tools unit tests ## +# No session daemon needed +for bin in ${tests[@]}; do if [ ! -e $bin ]; then echo -e "$bin not found, passing" @@ -71,11 +41,9 @@ do if [ $? -ne 0 ]; then echo -e '\e[1;31mFAIL\e[0m' echo "" - stop_sessiond exit 1 fi done -echo "" -stop_sessiond +# All passed exit 0 diff --git a/tests/test_list.py b/tests/test_list.py new file mode 100644 index 000000000..bb9748afc --- /dev/null +++ b/tests/test_list.py @@ -0,0 +1,49 @@ +Tests = \ +[ + # lttng-tools unit tests + { + 'bin': "tools/test_sessions", 'daemon': False, 'kern': False, 'name': "Test sessions", + 'desc': "Test tracing session data structures and methods.", + 'success': 0, 'enabled': True + }, + { + 'bin': "tools/test_kernel_data_trace", 'daemon': False, 'kern': False, + 'name': "Kernel data structures", + 'desc': "Test Kernel data structures and methods.", + 'success': 0, 'enabled': True + }, + { + 'bin': "tools/test_ust_data_trace", 'daemon': False, 'kern': False, + 'name': "UST data structures", + 'desc': "Test UST data structures and methods.", + 'success': 0, 'enabled': True + }, + + #### KERNEL #### + { + 'bin': "kernel/run-kernel-tests.sh", 'daemon': True, 'kern': True, + 'name': "Kernel tracer - lttng client", + 'desc': "Test the Kernel tracer using the lttng client", + 'success': 0, 'enabled': True + }, + + #### UST #### + { + 'bin': "ust/run-ust-global-tests.sh", 'daemon': True, 'kern': False, + 'name': "UST tracer - Global domain", + 'desc': "Test the UST tracer functionnalities for domain LTTNG_DOMAIN_UST", + 'success': 0, 'enabled': True + }, + { + 'bin': "ust/nprocesses/run", 'daemon': True, 'kern': False, + 'name': "UST tracer - Multiple processes", + 'desc': "Test multiple process registering and tracing", + 'success': 0, 'enabled': True + }, + { + 'bin': "ust/nevents/run", 'daemon': True, 'kern': False, + 'name': "UST tracer - Generate multiple events", + 'desc': "Test multiple events during tracing", + 'success': 0, 'enabled': True + }, +] diff --git a/tests/tools/Makefile.am b/tests/tools/Makefile.am new file mode 100644 index 000000000..d13868025 --- /dev/null +++ b/tests/tools/Makefile.am @@ -0,0 +1,24 @@ +AM_CFLAGS = -g -Wall -I../ +AM_LDFLAGS = -lurcu -lurcu-cds + +EXTRA_DIST = runall.sh + +noinst_PROGRAMS = test_sessions test_kernel_data_trace test_ust_data_trace + +UTILS=utils.h +SESSIONS=$(top_srcdir)/src/bin/lttng-sessiond/session.c +KERN_DATA_TRACE=$(top_srcdir)/src/bin/lttng-sessiond/trace-kernel.c +UST_DATA_TRACE=$(top_srcdir)/src/bin/lttng-sessiond/trace-ust.c +COMMON=$(top_builddir)/src/common/libcommon.la +HASHTABLE=$(top_builddir)/src/common/hashtable/libhashtable.la + +# Tracing sessions unit tests +test_sessions_SOURCES = test_sessions.c $(UTILS) $(SESSIONS) +test_sessions_LDADD = $(COMMON) $(HASHTABLE) + +# Kernel trace data unit tests +test_kernel_data_trace_SOURCES = test_kernel_data_trace.c $(UTILS) $(KERN_DATA_TRACE) + +# UST trace data unit tests +test_ust_data_trace_SOURCES = test_ust_data_trace.c $(UTILS) $(UST_DATA_TRACE) +test_ust_data_trace_LDADD = $(COMMON) $(HASHTABLE) diff --git a/tests/tools/runall.sh b/tests/tools/runall.sh new file mode 100755 index 000000000..5fdbda62b --- /dev/null +++ b/tests/tools/runall.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +DIR=$(dirname $0) + +tests=( $DIR/test_kernel_data_trace $DIR/test_sessions $DIR/test_ust_data_trace ) +exit_code=0 + +function start_tests () +{ + for bin in ${tests[@]}; + do + ./$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/test_kernel_data_trace.c b/tests/tools/test_kernel_data_trace.c similarity index 100% rename from tests/test_kernel_data_trace.c rename to tests/tools/test_kernel_data_trace.c diff --git a/tests/test_sessions.c b/tests/tools/test_sessions.c similarity index 100% rename from tests/test_sessions.c rename to tests/tools/test_sessions.c diff --git a/tests/test_ust_data_trace.c b/tests/tools/test_ust_data_trace.c similarity index 100% rename from tests/test_ust_data_trace.c rename to tests/tools/test_ust_data_trace.c diff --git a/tests/ust/Makefile.am b/tests/ust/Makefile.am new file mode 100644 index 000000000..822e33c51 --- /dev/null +++ b/tests/ust/Makefile.am @@ -0,0 +1,16 @@ +SUBDIRS = nevents nprocesses + +AM_CFLAGS = -g -Wall -I../ +AM_LDFLAGS = -lurcu -lurcu-cds + +EXTRA_DIST = runall.sh utils.sh run-ust-global-tests.sh + +noinst_PROGRAMS = ust_global_event_basic ust_global_all_events_basic + +UTILS=utils.h +LIBLTTNG=$(top_srcdir)/src/lib/lttng-ctl/lttng-ctl.c \ + $(top_srcdir)/src/common/sessiond-comm/sessiond-comm.c + +ust_global_all_events_basic_SOURCES = ust_global_all_events_basic.c $(UTILS) $(LIBLTTNG) + +ust_global_event_basic_SOURCES = ust_global_event_basic.c $(UTILS) $(LIBLTTNG) diff --git a/tests/ust-nevents/Makefile.am b/tests/ust/nevents/Makefile.am similarity index 100% rename from tests/ust-nevents/Makefile.am rename to tests/ust/nevents/Makefile.am diff --git a/tests/ust-nevents/gen-nevents.c b/tests/ust/nevents/gen-nevents.c similarity index 100% rename from tests/ust-nevents/gen-nevents.c rename to tests/ust/nevents/gen-nevents.c diff --git a/tests/ust/nevents/run b/tests/ust/nevents/run new file mode 100755 index 000000000..946e8b204 --- /dev/null +++ b/tests/ust/nevents/run @@ -0,0 +1,41 @@ +#!/bin/bash +# +# Copyright (C) - 2012 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 + +CURDIR=$(dirname $0)/ +TESTDIR=$CURDIR/../.. +NR_ITER=100 + +source $TESTDIR/utils.sh + +echo -e "\n-----------------------------------" +echo -e "UST tracer - Generate $NR_ITER events" +echo -e "-------------------------------------" + +if [ ! -e "$CURDIR/gen-nevents" ]; then + echo -e "No UST nevents binary detected. Passing." + exit 0 +fi + +# MUST set TESTDIR before calling those functions + +start_sessiond + +./$CURDIR/ust-nevents $NR_ITER + +stop_sessiond + +rm -rf $TRACE_PATH diff --git a/tests/ust-nevents/tp.c b/tests/ust/nevents/tp.c similarity index 100% rename from tests/ust-nevents/tp.c rename to tests/ust/nevents/tp.c diff --git a/tests/ust-nevents/run b/tests/ust/nevents/ust-nevents similarity index 81% rename from tests/ust-nevents/run rename to tests/ust/nevents/ust-nevents index 301b70d97..eed4dcb1b 100755 --- a/tests/ust-nevents/run +++ b/tests/ust/nevents/ust-nevents @@ -16,22 +16,13 @@ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA CURDIR=$(dirname $0)/ -TESTDIR=$CURDIR/.. -NR_ITER=100 +TESTDIR=$CURDIR/../.. +NR_ITER=$1 SESSION_NAME="ust-nevents" EVENT_NAME="ust_gen_nevents:tptest" source $TESTDIR/utils.sh -echo -e "\n-----------------------------------" -echo -e "UST tracer - Generate $NR_ITER events" -echo -e "-------------------------------------" - -if [ ! -e "$CURDIR/gen-nevents" ]; then - echo -e "No UST nevents binary detected. Passing." - exit 0 -fi - TRACE_PATH=$(mktemp -d) # MUST set TESTDIR before calling those functions diff --git a/tests/ust-nevents/ust_gen_nevents.h b/tests/ust/nevents/ust_gen_nevents.h similarity index 100% rename from tests/ust-nevents/ust_gen_nevents.h rename to tests/ust/nevents/ust_gen_nevents.h diff --git a/tests/ust-nprocesses/Makefile.am b/tests/ust/nprocesses/Makefile.am similarity index 100% rename from tests/ust-nprocesses/Makefile.am rename to tests/ust/nprocesses/Makefile.am diff --git a/tests/ust-nprocesses/gen-events-time.c b/tests/ust/nprocesses/gen-events-time.c similarity index 100% rename from tests/ust-nprocesses/gen-events-time.c rename to tests/ust/nprocesses/gen-events-time.c diff --git a/tests/ust/nprocesses/run b/tests/ust/nprocesses/run new file mode 100755 index 000000000..d2f6d555f --- /dev/null +++ b/tests/ust/nprocesses/run @@ -0,0 +1,41 @@ +#!/bin/bash +# +# Copyright (C) - 2012 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 + +CURDIR=$(dirname $0)/ +TESTDIR=$CURDIR/../.. +NR_ITER=100 + +source $TESTDIR/utils.sh + +echo -e "\n-------------------------------------" +echo -e "UST tracer - Generate $NR_ITER process" +echo -e "---------------------------------------" + +if [ ! -e "$CURDIR/$TEST_BIN_NAME" ]; then + echo -e "No UST $TEST_BIN_NAME binary detected. Passing." + exit 0 +fi + +# MUST set TESTDIR before calling those functions + +start_sessiond + +./$CURDIR/ust-nprocesses $NR_ITER + +stop_sessiond + +exit 0 diff --git a/tests/ust-nprocesses/tp.c b/tests/ust/nprocesses/tp.c similarity index 100% rename from tests/ust-nprocesses/tp.c rename to tests/ust/nprocesses/tp.c diff --git a/tests/ust-nprocesses/run b/tests/ust/nprocesses/ust-nprocesses similarity index 87% rename from tests/ust-nprocesses/run rename to tests/ust/nprocesses/ust-nprocesses index cab42ef5c..eab6d3965 100755 --- a/tests/ust-nprocesses/run +++ b/tests/ust/nprocesses/ust-nprocesses @@ -16,8 +16,8 @@ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA CURDIR=$(dirname $0)/ -TESTDIR=$CURDIR/.. -NR_ITER=100 +TESTDIR=$CURDIR/../.. +NR_ITER=$1 TEST_BIN_NAME="gen-events-time" SESSION_NAME="ust-nprocesses" EVENT_NAME="ust_gen_event:tptest" @@ -25,15 +25,6 @@ TEST_WAIT_SEC=5 source $TESTDIR/utils.sh -echo -e "\n-------------------------------------" -echo -e "UST tracer - Generate $NR_ITER process" -echo -e "---------------------------------------" - -if [ ! -e "$CURDIR/$TEST_BIN_NAME" ]; then - echo -e "No UST $TEST_BIN_NAME binary detected. Passing." - exit 0 -fi - # MUST set TESTDIR before calling those functions # Start test for 1000 seconds diff --git a/tests/ust-nprocesses/ust_gen_event.h b/tests/ust/nprocesses/ust_gen_event.h similarity index 98% rename from tests/ust-nprocesses/ust_gen_event.h rename to tests/ust/nprocesses/ust_gen_event.h index df53ccc98..5bdcb37c5 100644 --- a/tests/ust-nprocesses/ust_gen_event.h +++ b/tests/ust/nprocesses/ust_gen_event.h @@ -51,6 +51,6 @@ TRACEPOINT_EVENT(ust_gen_event, tptest, /* This part must be outside ifdef protection */ #include -#ifdef __cplusplus +#ifdef __cplusplus } #endif diff --git a/tests/lttng/run-ust-global-tests.sh b/tests/ust/run-ust-global-tests.sh similarity index 77% rename from tests/lttng/run-ust-global-tests.sh rename to tests/ust/run-ust-global-tests.sh index a99ff43b3..96c1f9e54 100755 --- a/tests/lttng/run-ust-global-tests.sh +++ b/tests/ust/run-ust-global-tests.sh @@ -1,12 +1,13 @@ #!/bin/bash SESSIOND_BIN="lttng-sessiond" -TESTDIR=$(dirname $0)/.. +CURDIR=$(dirname $0) +TESTDIR=$CURDIR/.. source $TESTDIR/utils.sh tmpdir=`mktemp -d` -tests=( ust_global_event_basic ust_global_all_events_basic ) +tests=( $CURDIR/ust_global_event_basic $CURDIR/ust_global_all_events_basic ) exit_code=0 function start_tests () @@ -18,12 +19,16 @@ function start_tests () continue fi + start_sessiond + ./$bin $tmpdir # Test must return 0 to pass. if [ $? -ne 0 ]; then exit_code=1 + stop_sessiond break fi + stop_sessiond done # Cleaning up @@ -34,11 +39,6 @@ echo -e "\n-------------------------------------------" echo -e "UST tracer - Global domain (LTTNG_DOMAIN_UST)" echo -e "---------------------------------------------" -PID_SESSIOND=`pidof lt-$SESSIOND_BIN` - -# Simply wait for the session daemon bootstrap -sleep 1 - start_tests exit $exit_code diff --git a/tests/ust/runall.sh b/tests/ust/runall.sh new file mode 100755 index 000000000..78182cb92 --- /dev/null +++ b/tests/ust/runall.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +DIR=$(dirname $0) + +tests=( $DIR/run-ust-global-tests.sh $DIR/nevents/run $DIR/nprocesses/run ) +exit_code=0 + +function start_tests () +{ + for bin in ${tests[@]}; + do + ./$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/lttng/ust_global_all_events_basic.c b/tests/ust/ust_global_all_events_basic.c similarity index 99% rename from tests/lttng/ust_global_all_events_basic.c rename to tests/ust/ust_global_all_events_basic.c index 03363a86b..3ae786e8c 100644 --- a/tests/lttng/ust_global_all_events_basic.c +++ b/tests/ust/ust_global_all_events_basic.c @@ -27,7 +27,7 @@ #include -#include "../utils.h" +#include "utils.h" int lttng_opt_quiet; diff --git a/tests/lttng/ust_global_event_basic.c b/tests/ust/ust_global_event_basic.c similarity index 100% rename from tests/lttng/ust_global_event_basic.c rename to tests/ust/ust_global_event_basic.c diff --git a/tests/utils.h b/tests/utils.h index 52893b207..7650865dd 100644 --- a/tests/utils.h +++ b/tests/utils.h @@ -1,19 +1,18 @@ /* - * Copyright (c) 2011 David Goulet + * 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 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. + * 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. + * 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. */ #include diff --git a/tests/utils.sh b/tests/utils.sh index 55bc9e9d5..f0a2e25dd 100644 --- a/tests/utils.sh +++ b/tests/utils.sh @@ -24,6 +24,8 @@ KERNEL_MAJOR_VERSION=2 KERNEL_MINOR_VERSION=6 KERNEL_PATCHLEVEL_VERSION=27 +alias realpath='readlink -f' + function validate_kernel_version () { kern_version=($(uname -r | awk -F. '{ printf("%d.%d.%d\n",$1,$2,$3); }' | tr '.' '\n')) @@ -39,7 +41,7 @@ function validate_kernel_version () return 1 } -function start_sessiond () +function spawn_sessiond () { echo "" echo -n "Starting session daemon... " @@ -49,8 +51,10 @@ function start_sessiond () return 2 fi + DIR=$(realpath $TESTDIR) + if [ -z $(pidof lt-$SESSIOND_BIN) ]; then - $TESTDIR/../src/bin/lttng-sessiond/$SESSIOND_BIN --daemonize --quiet --consumerd32-path="$(pwd)/../src/bin/lttng-consumerd/lttng-consumerd" --consumerd64-path="$(pwd)/../src/bin/lttng-consumerd/lttng-consumerd" + $DIR/../src/bin/lttng-sessiond/$SESSIOND_BIN --daemonize --quiet --consumerd32-path="$DIR/../src/bin/lttng-consumerd/lttng-consumerd" --consumerd64-path="$DIR/../src/bin/lttng-consumerd/lttng-consumerd" if [ $? -eq 1 ]; then echo -e "\e[1;31mFAILED\e[0m" return 1 @@ -62,8 +66,35 @@ function start_sessiond () return 0 } +function start_sessiond() +{ + if [ -n $TEST_NO_SESSIOND ] && [ "$TEST_NO_SESSIOND" == "1" ]; then + # Env variable requested no session daemon + return + fi + + spawn_sessiond + out=$? + if [ $out -eq 2 ]; then + # Kernel version is not compatible. + exit 0 + elif [ $out -ne 0 ]; then + echo "NOT bad $?" + exit 1 + fi + + # Simply wait for the session daemon bootstrap + echo "Waiting for the session daemon to bootstrap (2 secs)" + sleep 2 +} + function stop_sessiond () { + if [ -n $TEST_NO_SESSIOND ] && [ "$TEST_NO_SESSIOND" == "1" ]; then + # Env variable requested no session daemon + return + fi + PID_SESSIOND=`pidof lt-$SESSIOND_BIN` echo -e -n "Killing session daemon... " -- 2.34.1