From b0e9b25d25f0932f3da6d0613df16c8e33798fd2 Mon Sep 17 00:00:00 2001 From: Adrian Szyndela Date: Mon, 6 Feb 2017 12:17:24 +0100 Subject: tests: generating coverage version of the library Additionally: - immediate output of test results instead of caching and printing at the end; - removed manual-authz test, because it is not meant to be run automatically. Change-Id: I7354c21e0fa457ad7e2a4a53e1c898e5039b7f73 --- packaging/coverage.txt | 14 ++++++++ packaging/dbus.spec | 87 +++++++++++++++++++++++++++++++++++++++++++++++--- test-runner.c | 23 ++----------- 3 files changed, 99 insertions(+), 25 deletions(-) create mode 100644 packaging/coverage.txt diff --git a/packaging/coverage.txt b/packaging/coverage.txt new file mode 100644 index 00000000..b3674cb2 --- /dev/null +++ b/packaging/coverage.txt @@ -0,0 +1,14 @@ +How to analyze coverage: +1. read HACKING file. +2. gbs build adding --define '_with_coverage 1' +3. take *.o and *.gcno files from compilation (/home/abuild/rpmbuild/BUILD/dbus-1.10.6/dbus/.libs) into a /safe/place + you may also use generated rpm package dbus-coverage-objects. +4. install coverage package (dbus-coverage) on the target +5. run test programs adding LD_LIBRARY_PATH=/usr/lib/dbus-tests/coverage-libs + Data gathering is cumulative, so you can run multiple programs one after another. + Use GCOV_PREFIX and GCOV_PREFIX_STRIP environment variables to set output directory. + If not set, data files (*.gcda) will be generated in /home/abuild/rpmbuild/BUILD/dbus-1.10.6 +6. download generated gcda files from the target to /safe/place +7. put source code *.c files together with object files into a /safe/place +8. run gcov /safe/place/*.o + or gcov -r /safe/place/*.o for only local source code output diff --git a/packaging/dbus.spec b/packaging/dbus.spec index a468e265..afaad50d 100644 --- a/packaging/dbus.spec +++ b/packaging/dbus.spec @@ -2,6 +2,7 @@ %bcond_with kdbus %bcond_with dbuspolicy +%bcond_with coverage Name: dbus Url: http://dbus.freedesktop.org/ @@ -82,6 +83,24 @@ Summary: Package with binaries and data for dbus tests %description tests This package contains installable tests. Tests are compatible with 'dbus-integration-tests' framework. +%if %{with coverage} +%package coverage +Summary: Special version of dbus library for getting coverage analysis + +%description coverage +Special version of dbus library for getting coverage analysis. *.gcda coverage files +are generated on each use of library in directory set by GCOV_PREFIX and GCOV_PREFIX_STRIP. +Use the library by modifying LD_LIBRARY_PATH. +This package is intended for debug/test use only. + +%package coverage-objects +Summary: Generated object files and gcov notes for coverage analysis + +%description coverage-objects +We need to keep objects and gcno files to analyze coverage. +This package is intended for debug/test use only. +%endif + %prep # COMMON2-BEGIN %setup -n dbus-%{version} -q @@ -96,6 +115,47 @@ export CXXFLAGS="${RPM_OPT_FLAGS} -fno-strict-aliasing" export CFLAGS="$CFLAGS -fstack-protector" export CXXFLAGS="$CXXFLAGS -fstack-protector" export V=1 + +# Support for generating separate packages with libraries generating coverage files +# WARNING: if coverage build is enabled, incremental builds will not work correctly. +# Use the option only to generate dbus-coverage packages. +%if %{with coverage} +%reconfigure \ + --disable-static \ + --with-pic \ + --with-dbus-user=dbus \ + --libexecdir=%{_libdir}/%{name} \ + --libdir=%{_libdir} \ + --with-init-scripts=suse \ + --enable-inotify \ + --disable-doxygen-docs \ + --disable-xml-docs \ +%if %{with_systemd} + --enable-systemd \ +%endif +%if %{with kdbus} + --enable-kdbus-transport \ +%if %{with dbuspolicy} + --enable-libdbuspolicy \ +%endif +%endif + --with-system-pid-file=/tmp/dbus_launch \ + --with-console-auth-dir=/var/run/dbus/at_console/ \ + --with-systemdsystemunitdir=%{_unitdir} \ + --enable-smack \ + --enable-cynara \ + --enable-modular-tests \ + --enable-installed-tests \ + --enable-compiler-coverage +make %{?_smp_mflags} +mkdir coverage +cp dbus/.libs/libdbus-1.so.3 coverage +mkdir coverage-objects +find dbus -name '*.o' -exec cp '{}' coverage-objects ';' +find dbus -name '*.gcno' -exec cp '{}' coverage-objects ';' + +%endif + %reconfigure \ --disable-static \ --with-pic \ @@ -160,13 +220,25 @@ install -m 0644 %{SOURCE7} %{buildroot}%{_sysconfdir}/profile.d/dbus.sh rm -rf %{buildroot}%{_datadir}/doc # build test binaries and copy test data -mkdir -p %{buildroot}/usr/lib/dbus-tests/test-suites/dbus-tests/ -mkdir -p %{buildroot}/usr/lib/dbus-tests/runner/ -%__cc %{_builddir}/%{name}-%{version}/test-runner.c -o %{buildroot}/usr/lib/dbus-tests/runner/dbus-tests -cp -fr %{buildroot}%{_libdir}/dbus/installed-tests/dbus/* %{buildroot}/usr/lib/dbus-tests/test-suites/dbus-tests/ +%define relative_dbus_tests_base_dir %{_prefix}/lib/dbus-tests +%define dbus_tests_base_dir %{buildroot}%{relative_dbus_tests_base_dir} +mkdir -p %{dbus_tests_base_dir}/test-suites/dbus-tests/ + +mkdir -p %{dbus_tests_base_dir}/runner/ +%__cc %{_builddir}/%{name}-%{version}/test-runner.c -o %{dbus_tests_base_dir}/runner/dbus-tests +cp -fr %{buildroot}%{_libdir}/dbus/installed-tests/dbus/* %{dbus_tests_base_dir}/test-suites/dbus-tests/ rm -fr %{buildroot}%{_libdir}/dbus/installed-tests/dbus rm -fr %{buildroot}/usr/share/installed-tests/dbus +%if %{with coverage} +%define relative_cov_lib_dir %{relative_dbus_tests_base_dir}/coverage-libs +%define cov_lib_dir %{buildroot}%{relative_cov_lib_dir} +mkdir -p %{cov_lib_dir} +mkdir -p %{cov_lib_dir}/objects +install -m 0755 coverage/* %{cov_lib_dir} +install -m 0644 coverage-objects/* %{cov_lib_dir}/objects +%endif + %pre # Add the "dbus" user and group /usr/sbin/groupadd -r -g %{dbus_user_uid} dbus 2>/dev/null || : @@ -246,4 +318,11 @@ rm -fr %{buildroot}/usr/share/installed-tests/dbus %{_prefix}/lib/dbus-tests/test-suites/dbus-tests %{_prefix}/lib/dbus-tests/runner/dbus-tests +%if %{with coverage} +%files coverage +%{relative_cov_lib_dir}/* +%files coverage-objects +%{relative_cov_lib_dir}/objects/* +%endif + %changelog diff --git a/test-runner.c b/test-runner.c index 66400c00..c750e321 100644 --- a/test-runner.c +++ b/test-runner.c @@ -87,9 +87,6 @@ char** prepare_args_for_binary(const struct binary* b, const char* test_name); char** prepare_args_for_dir_iter(const struct binary* b, const char* test_name); int init_environment_vars(); -static struct test_case desc_1[] = { - {"", "Simple sanity-check for authentication and authorization."}, {NULL, NULL} -}; static struct test_case desc_2[] = { {"", "Testing DBus ability to iterate over directory contents."}, {NULL, NULL} }; @@ -145,8 +142,6 @@ static struct test_case desc_18[] = { /* This table is used to start binaries */ struct binary tests[] = { /*path, name, TC_table, timeout in us, prepare_args_handler, parse_function_handler, init_handler, clean_handler*/ - {"/usr/lib/dbus-tests/test-suites/dbus-tests/manual-authz", - "manual-authz", desc_1, 1000*1000, prepare_args_for_binary, parse_binary_outputs, init_environment_vars, NULL}, {"/usr/lib/dbus-tests/test-suites/dbus-tests/manual-dir-iter", "manual-dir-iter", desc_2, 1000*1000, prepare_args_for_dir_iter, parse_binary_outputs, init_environment_vars, NULL}, {"/usr/lib/dbus-tests/test-suites/dbus-tests/manual-tcp", @@ -317,8 +312,6 @@ static int stdin_pipe[2]; static int stdout_pipe[2]; static int stderr_pipe[2]; static int gravedigger_pipe[2]; -static struct test_result test_results[MAX_TC_NUM]; -static int test_results_i; static char buffer[MAX_BUFFER]; static const char* requested_tc[MAX_TC_NUM]; @@ -616,19 +609,8 @@ static int parse_option(int argc, char* argv[]) void add_test_result(const char* test_id, const char* result, const char* comment, int res) { - test_results[test_results_i].is_positive = res; - strcpy(test_results[test_results_i].result, result); - strcpy(test_results[test_results_i].comment, comment); - strcpy(test_results[test_results_i++].name, test_id); -} - -static void print_results() -{ - int i = 0; - for (i = 0; i < test_results_i; i++) - { - printf("%s;%s;%s\n", test_results[i].name, test_results[i].result, test_results[i].comment); - } + printf("%s;%s;%s\n", test_id, result, comment); + fflush(stdout); } int main(int argc, char* argv[]) @@ -649,6 +631,5 @@ int main(int argc, char* argv[]) } } - print_results(); return 0; } -- cgit v1.2.3 From 321a18e45eaf5a04597749c541f35deaa723ee1d Mon Sep 17 00:00:00 2001 From: Adrian Szyndela Date: Thu, 16 Feb 2017 12:47:41 +0100 Subject: tests: general fix for tests setup Before this patch tests were installed into custom directory /usr/lib/dbus-tests/test-suites/dbus-tests Originally, dbus wants its installed tests in /usr/lib/dbus/installed-tests/dbus This path seems to be partially hardcoded in the configuration files - it relies on defined datadir. As datadir is used also for something else than tests, we don't want to change it. This commit switches installation directory to the original, and adds symbolic links in our custom directory. Change-Id: Icf330ba3b5be59ee941d51b15a8f78a082297846 --- packaging/dbus.spec | 20 ++++++++++++++------ test-runner.c | 6 ++++-- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/packaging/dbus.spec b/packaging/dbus.spec index afaad50d..50d1da33 100644 --- a/packaging/dbus.spec +++ b/packaging/dbus.spec @@ -220,15 +220,22 @@ install -m 0644 %{SOURCE7} %{buildroot}%{_sysconfdir}/profile.d/dbus.sh rm -rf %{buildroot}%{_datadir}/doc # build test binaries and copy test data -%define relative_dbus_tests_base_dir %{_prefix}/lib/dbus-tests +%define relative_dbus_tests_base_dir %{_libdir}/dbus-tests %define dbus_tests_base_dir %{buildroot}%{relative_dbus_tests_base_dir} +%define dbus_installed_tests_dir %{_libdir}/dbus/installed-tests/dbus mkdir -p %{dbus_tests_base_dir}/test-suites/dbus-tests/ mkdir -p %{dbus_tests_base_dir}/runner/ -%__cc %{_builddir}/%{name}-%{version}/test-runner.c -o %{dbus_tests_base_dir}/runner/dbus-tests -cp -fr %{buildroot}%{_libdir}/dbus/installed-tests/dbus/* %{dbus_tests_base_dir}/test-suites/dbus-tests/ -rm -fr %{buildroot}%{_libdir}/dbus/installed-tests/dbus +%__cc %{_builddir}/%{name}-%{version}/test-runner.c -g -o %{dbus_tests_base_dir}/runner/dbus-tests rm -fr %{buildroot}/usr/share/installed-tests/dbus +# The tests are installed in standard directory for dbus tests. +# However, we need to have the tests also available for dbus-integration-tests package. +# Thus, we link selected tests to our dbus-integration-tests directory +for f in manual-dir-iter manual-tcp test-corrupt test-dbus-daemon \ + test-dbus-daemon-eavesdrop test-fdpass test-loopback test-marshal \ + test-monitor test-printf test-refs test-relay test-sd-activation \ + test-shell test-syntax test-syslog test-uid-permissions +do ln -s %{dbus_installed_tests_dir}/$f %{dbus_tests_base_dir}/test-suites/dbus-tests/$f; done %if %{with coverage} %define relative_cov_lib_dir %{relative_dbus_tests_base_dir}/coverage-libs @@ -315,8 +322,9 @@ install -m 0644 coverage-objects/* %{cov_lib_dir}/objects %files tests %manifest %{name}.manifest %defattr(-,root,root) -%{_prefix}/lib/dbus-tests/test-suites/dbus-tests -%{_prefix}/lib/dbus-tests/runner/dbus-tests +%{_libdir}/dbus-tests/test-suites/dbus-tests +%{_libdir}/dbus-tests/runner/dbus-tests +%{_libdir}/dbus/installed-tests %if %{with coverage} %files coverage diff --git a/test-runner.c b/test-runner.c index c750e321..a248c641 100644 --- a/test-runner.c +++ b/test-runner.c @@ -41,6 +41,8 @@ #define MAX_BUFFER (64*1024) #define MAX_COMMENT 1024 +#define INSTALLED_TESTS_DIR "/usr/lib/dbus/installed-tests/dbus/data" + enum { INIT_TEST, NEW_STDOUT, @@ -255,13 +257,13 @@ char** prepare_args_for_dir_iter(const struct binary* b, const char* test_name) { static char* args_dir[2]; args_dir[0] = (char*)b->name; - args_dir[1] = "/usr/lib/dbus-tests/test-suites/dbus-tests/data"; + args_dir[1] = INSTALLED_TESTS_DIR; return args_dir; } int init_environment_vars() { - return !(putenv("DBUS_TEST_DATA=/usr/lib/dbus-tests/test-suites/dbus-tests/data")); + return !(putenv("DBUS_TEST_DATA="INSTALLED_TESTS_DIR)); } void parse_binary_outputs(const struct binary* b, const char* test_name, char* buffer, int state_change, int state_option) -- cgit v1.2.3