From b0e9b25d25f0932f3da6d0613df16c8e33798fd2 Mon Sep 17 00:00:00 2001 From: Adrian Szyndela Date: Mon, 6 Feb 2017 12:17:24 +0100 Subject: [PATCH] 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 0000000..b3674cb --- /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 a468e26..afaad50 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 66400c0..c750e32 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; } -- 2.7.4