]> granicus.if.org Git - vnstat/commitdiff
fix tests to work even if check has been compiled without fork support
authorTeemu Toivola <git@humdi.net>
Sun, 7 Jul 2019 22:35:32 +0000 (01:35 +0300)
committerTeemu Toivola <git@humdi.net>
Sun, 7 Jul 2019 22:35:32 +0000 (01:35 +0300)
18 files changed:
.travis.yml
tests/common_tests.c
tests/common_tests.h
tests/config_tests.c
tests/daemon_tests.c
tests/daemon_tests.h
tests/database_tests.c
tests/datacache_tests.c
tests/dbsql_tests.c
tests/fs_tests.c
tests/id_tests.c
tests/id_tests.h
tests/ifinfo_tests.c
tests/iflist_tests.c
tests/image_tests.c
tests/misc_tests.c
tests/vnstat_tests.c
tests/vnstat_tests.h

index e9997c28d94c1a0f23104486b9f28c5659de38a1..1157c25ae24d8917b5550d4fc049a55137cc8da1 100644 (file)
@@ -54,7 +54,7 @@ before_install:
  - if [ "${TRAVIS_OS_NAME}" == "osx" ]; then brew install gd sqlite check ; fi
 
 script:
- - ./configure ${CPARAMS} && make check || ( cat test.log ; exit 1 ) && egrep '^[0-9]+%' test.log && ./vnstat --version
+ - ./configure ${CPARAMS} && make check || ( cat test.log ; exit 1 ) && egrep '^[0-9]+%' test.log && CK_FORK=no ./check_vnstat || ( cat test.log ; exit 1 ) && ./vnstat --version
 
 notifications:
   email:
index 36b9c0cdcff1792b178a2c9907927d46291fa127..0cd60edc1ff1ed5fd48485d8f87eda7334a05123 100644 (file)
@@ -359,6 +359,9 @@ START_TEST(timeused_debug_outputs_something_expected_when_debug_is_enabled)
        fflush(stdout);
 
        len = (int)read(pipe, buffer, 512);
+       close(STDOUT_FILENO);
+       close(pipe);
+
        ck_assert_int_gt(len, 1);
        ck_assert_ptr_ne(strstr(buffer, "that_func() in 0"), NULL);
 }
@@ -382,6 +385,9 @@ START_TEST(timeused_debug_does_not_output_anything_when_debug_is_disabled)
        fflush(stdout);
 
        len = (int)read(pipe, buffer, 512);
+       close(STDOUT_FILENO);
+       close(pipe);
+
        ck_assert_int_eq(len, 1);
 }
 END_TEST
@@ -415,9 +421,11 @@ START_TEST(can_panic)
 }
 END_TEST
 
-void add_common_tests(Suite *s)
+void add_common_tests(Suite *s, const int can_fork)
 {
        TCase *tc_common = tcase_create("Common");
+       tcase_add_checked_fixture(tc_common, setup, teardown);
+       tcase_add_unchecked_fixture(tc_common, setup, teardown);
        tcase_add_test(tc_common, printe_options);
        tcase_add_test(tc_common, logprint_options);
        tcase_add_loop_test(tc_common, dmonth_return_within_range, 0, 12);
@@ -446,6 +454,8 @@ void add_common_tests(Suite *s)
        tcase_add_test(tc_common, timeused_debug_outputs_something_expected_when_debug_is_enabled);
        tcase_add_test(tc_common, timeused_debug_does_not_output_anything_when_debug_is_disabled);
        tcase_add_test(tc_common, timeused_tracks_used_time);
-       tcase_add_exit_test(tc_common, can_panic, 1);
+       if (can_fork) {
+               tcase_add_exit_test(tc_common, can_panic, 1);
+       }
        suite_add_tcase(s, tc_common);
 }
index 2b3f4473f1f943184b60791903414b3d2dd7be43..7cd854c4cc240561dadbfab079f681765fa96119 100644 (file)
@@ -1,6 +1,6 @@
 #ifndef COMMON_TESTS_H
 #define COMMON_TESTS_H
 
-void add_common_tests(Suite *s);
+void add_common_tests(Suite *s, const int can_fork);
 
 #endif
index 664862365c564d2693284b46978b15d99e92ae0f..db8a4071b658e57a1f4fdee526829aa84ab18903 100644 (file)
@@ -130,6 +130,7 @@ START_TEST(ibwget_with_empty_list_and_no_maxbw)
 {
        uint32_t limit;
        cfg.maxbw = 0;
+       ibwflush();
        ck_assert_int_eq(ibwget("does_not_exist", &limit), 0);
 }
 END_TEST
@@ -139,6 +140,7 @@ START_TEST(ibwget_with_empty_list_and_maxbw)
        int ret;
        uint32_t limit;
        cfg.maxbw = 10;
+       ibwflush();
        ret = ibwget("does_not_exist", &limit);
        ck_assert_int_eq(ret, 1);
        ck_assert_int_eq(limit, 10);
@@ -518,6 +520,8 @@ END_TEST
 void add_config_tests(Suite *s)
 {
        TCase *tc_config = tcase_create("Config");
+       tcase_add_checked_fixture(tc_config, setup, teardown);
+       tcase_add_unchecked_fixture(tc_config, setup, teardown);
        tcase_add_test(tc_config, validatecfg_default);
        tcase_add_test(tc_config, validatecfg_does_not_modify_valid_changes);
        tcase_add_test(tc_config, validatecfg_restores_invalid_values_back_to_default);
index d7caa7c8a577680e41505517438b35400a29a59f..1cfc1a2db1e7e3601d3f23d29a3221789fa87757 100644 (file)
@@ -17,6 +17,15 @@ START_TEST(debugtimestamp_does_not_exit)
 }
 END_TEST
 
+
+START_TEST(initdstate_does_not_crash)
+{
+       DSTATE s;
+       defaultcfg();
+       initdstate(&s);
+}
+END_TEST
+
 START_TEST(addinterfaces_does_nothing_with_no_files)
 {
        DSTATE s;
@@ -182,14 +191,6 @@ START_TEST(addinterfaces_adds_to_cache_when_running)
 }
 END_TEST
 
-START_TEST(initdstate_does_not_crash)
-{
-       DSTATE s;
-       defaultcfg();
-       initdstate(&s);
-}
-END_TEST
-
 START_TEST(preparedatabases_exits_with_no_database_dir)
 {
        DSTATE s;
@@ -1433,21 +1434,27 @@ START_TEST(datacache_status_has_no_issues_with_large_number_of_interfaces)
 }
 END_TEST
 
-void add_daemon_tests(Suite *s)
+void add_daemon_tests(Suite *s, const int can_fork)
 {
        TCase *tc_daemon = tcase_create("Daemon");
+       tcase_add_checked_fixture(tc_daemon, setup, teardown);
+       tcase_add_unchecked_fixture(tc_daemon, setup, teardown);
        tcase_add_test(tc_daemon, debugtimestamp_does_not_exit);
        tcase_add_test(tc_daemon, initdstate_does_not_crash);
        tcase_add_test(tc_daemon, addinterfaces_does_nothing_with_no_files);
        tcase_add_test(tc_daemon, addinterfaces_adds_interfaces);
        tcase_add_test(tc_daemon, addinterfaces_adds_only_new_interfaces);
        tcase_add_test(tc_daemon, addinterfaces_adds_to_cache_when_running);
-       tcase_add_exit_test(tc_daemon, preparedatabases_exits_with_no_database_dir, 1);
-       tcase_add_exit_test(tc_daemon, preparedatabases_exits_with_no_databases, 1);
-       tcase_add_exit_test(tc_daemon, preparedatabases_exits_with_no_databases_and_noadd, 1);
+       if (can_fork) {
+               tcase_add_exit_test(tc_daemon, preparedatabases_exits_with_no_database_dir, 1);
+               tcase_add_exit_test(tc_daemon, preparedatabases_exits_with_no_databases, 1);
+               tcase_add_exit_test(tc_daemon, preparedatabases_exits_with_no_databases_and_noadd, 1);
+       }
        tcase_add_test(tc_daemon, preparedatabases_with_no_databases_creates_databases);
        tcase_add_test(tc_daemon, setsignaltraps_does_not_exit);
-       tcase_add_exit_test(tc_daemon, filldatabaselist_exits_with_no_database_dir, 1);
+       if (can_fork) {
+               tcase_add_exit_test(tc_daemon, filldatabaselist_exits_with_no_database_dir, 1);
+       }
        tcase_add_test(tc_daemon, filldatabaselist_does_not_exit_with_empty_database_dir);
        tcase_add_test(tc_daemon, filldatabaselist_adds_databases);
        tcase_add_test(tc_daemon, adjustsaveinterval_with_empty_cache);
@@ -1482,13 +1489,19 @@ void add_daemon_tests(Suite *s)
        tcase_add_test(tc_daemon, detectboot_sets_btime_if_missing_from_database);
        tcase_add_test(tc_daemon, detectboot_sets_btime_for_new_database);
        tcase_add_test(tc_daemon, detectboot_can_detect_boot);
-       tcase_add_exit_test(tc_daemon, handledatabaseerror_exits_on_fatal_error, 1);
+       if (can_fork) {
+               tcase_add_exit_test(tc_daemon, handledatabaseerror_exits_on_fatal_error, 1);
+       }
        tcase_add_test(tc_daemon, handledatabaseerror_does_not_exit_if_limit_is_not_reached);
-       tcase_add_exit_test(tc_daemon, handledatabaseerror_exits_if_limit_is_reached, 1);
+       if (can_fork) {
+               tcase_add_exit_test(tc_daemon, handledatabaseerror_exits_if_limit_is_reached, 1);
+       }
        tcase_add_test(tc_daemon, cleanremovedinterfaces_allows_interfaces_to_be_removed);
        tcase_add_test(tc_daemon, processifinfo_syncs_when_needed);
        tcase_add_test(tc_daemon, processifinfo_skips_update_if_timestamps_make_no_sense);
-       tcase_add_exit_test(tc_daemon, processifinfo_exits_if_timestamps_really_make_no_sense, 1);
+       if (can_fork) {
+               tcase_add_exit_test(tc_daemon, processifinfo_exits_if_timestamps_really_make_no_sense, 1);
+       }
        tcase_add_test(tc_daemon, processifinfo_syncs_if_timestamps_match);
        tcase_add_test(tc_daemon, processifinfo_adds_traffic);
        tcase_add_test(tc_daemon, processifinfo_does_not_add_traffic_when_over_limit);
index 09deb8c15227462d1bd6c63b5795458a3dc87f82..dc63756e39768acfb1be5923ed88691e0d7951e0 100644 (file)
@@ -1,6 +1,6 @@
 #ifndef DAEMON_TESTS_H
 #define DAEMON_TESTS_H
 
-void add_daemon_tests(Suite *s);
+void add_daemon_tests(Suite *s, const int can_fork);
 
 #endif
index caa666a9937752bf73585feeb00e6852f476a234..ef49af4738d3291390f6d4bf4f37c5e010d9bd14 100644 (file)
@@ -444,6 +444,8 @@ START_TEST(showbar_with_all_rx)
        fflush(stdout);
 
        len = (int)read(pipe, buffer, 512);
+       close(STDOUT_FILENO);
+       close(pipe);
        ck_assert_str_eq(buffer, "  rrrrrrrrrr");
 }
 END_TEST
@@ -463,6 +465,8 @@ START_TEST(showbar_with_all_tx)
        fflush(stdout);
 
        len = (int)read(pipe, buffer, 512);
+       close(STDOUT_FILENO);
+       close(pipe);
        ck_assert_str_eq(buffer, "  tttttttttt");
 }
 END_TEST
@@ -482,6 +486,8 @@ START_TEST(showbar_with_half_and_half)
        fflush(stdout);
 
        len = (int)read(pipe, buffer, 512);
+       close(STDOUT_FILENO);
+       close(pipe);
        ck_assert_str_eq(buffer, "  rrrrrttttt");
 }
 END_TEST
@@ -501,6 +507,8 @@ START_TEST(showbar_with_one_tenth)
        fflush(stdout);
 
        len = (int)read(pipe, buffer, 512);
+       close(STDOUT_FILENO);
+       close(pipe);
        ck_assert_str_eq(buffer, "  rttttttttt");
 }
 END_TEST
@@ -520,6 +528,8 @@ START_TEST(showbar_with_small_rx_shows_all_tx)
        fflush(stdout);
 
        len = (int)read(pipe, buffer, 512);
+       close(STDOUT_FILENO);
+       close(pipe);
        ck_assert_str_eq(buffer, "  tttttttttt");
 }
 END_TEST
@@ -548,6 +558,8 @@ START_TEST(showbar_with_half_and_half_of_half)
        fflush(stdout);
 
        len = (int)read(pipe, buffer, 512);
+       close(STDOUT_FILENO);
+       close(pipe);
        ck_assert_str_eq(buffer, "  rrrttt");
 }
 END_TEST
@@ -730,6 +742,8 @@ END_TEST
 void add_database_tests(Suite *s)
 {
        TCase *tc_db = tcase_create("Database");
+       tcase_add_checked_fixture(tc_db, setup, teardown);
+       tcase_add_unchecked_fixture(tc_db, setup, teardown);
        tcase_add_test(tc_db, initdb_activates_database);
        tcase_add_test(tc_db, readdb_with_empty_file);
        tcase_add_test(tc_db, readdb_with_empty_file_and_backup);
index e04d7fa96c6449b9ea3f2faf39438ee8192c3336..31aff5f6a7c90c7f197d82e9b5516c6468dcb529 100644 (file)
@@ -291,6 +291,8 @@ END_TEST
 void add_datacache_tests(Suite *s)
 {
        TCase *tc_datacache = tcase_create("Datacache");
+       tcase_add_checked_fixture(tc_datacache, setup, teardown);
+       tcase_add_unchecked_fixture(tc_datacache, setup, teardown);
        tcase_add_test(tc_datacache, datacache_can_clear_empty_cache);
        tcase_add_test(tc_datacache, datacache_can_add_to_cache);
        tcase_add_test(tc_datacache, datacache_can_add_to_cache_consistently);
index 1211409d7498b218417c8700f2f39ae69436e513..94f68b803aafbe7679e2b274cfd5f00104d900bc 100644 (file)
@@ -883,7 +883,6 @@ START_TEST(db_validate_with_valid_version)
        int ret;
        defaultcfg();
        suppress_output();
-       debug = 1;
 
        ret = db_open_rw(1);
        ck_assert_int_eq(ret, 1);
@@ -2186,6 +2185,8 @@ END_TEST
 void add_dbsql_tests(Suite *s)
 {
        TCase *tc_dbsql = tcase_create("DB SQL");
+       tcase_add_checked_fixture(tc_dbsql, setup, teardown);
+       tcase_add_unchecked_fixture(tc_dbsql, setup, teardown);
        tcase_add_test(tc_dbsql, db_close_does_no_harm_when_db_is_already_closed);
        tcase_add_test(tc_dbsql, db_open_rw_can_create_database_if_file_does_not_exist);
        tcase_add_test(tc_dbsql, db_open_ro_cannot_create_a_database);
index 4dc60dd5faac30f7bf38c095e6e02f699f03f6d2..177a08746c183f69355e678f6f0dd3b66e5736bd 100644 (file)
@@ -129,6 +129,8 @@ END_TEST
 void add_fs_tests(Suite *s)
 {
        TCase *tc_fs = tcase_create("FS");
+       tcase_add_checked_fixture(tc_fs, setup, teardown);
+       tcase_add_unchecked_fixture(tc_fs, setup, teardown);
        tcase_add_test(tc_fs, fileexists_with_no_file);
        tcase_add_test(tc_fs, fileexists_with_file);
        tcase_add_test(tc_fs, direxists_with_no_dir);
index 9f7bc25ffeaeb538d796d7d8c076f5f1f49a0451..66a6a119bb468f80e014f313f7059fe4db7d3fc9 100644 (file)
@@ -107,17 +107,23 @@ START_TEST(setgroup_with_current_group)
 }
 END_TEST
 
-void add_id_tests(Suite *s)
+void add_id_tests(Suite *s, const int can_fork)
 {
        TCase *tc_id = tcase_create("ID");
+       tcase_add_checked_fixture(tc_id, setup, teardown);
+       tcase_add_unchecked_fixture(tc_id, setup, teardown);
        tcase_add_test(tc_id, getuser_root_string);
        tcase_add_test(tc_id, getuser_root_numeric);
-       tcase_add_exit_test(tc_id, getuser_no_such_user_string, 1);
-       tcase_add_exit_test(tc_id, getuser_no_such_user_numeric, 1);
+       if (can_fork) {
+               tcase_add_exit_test(tc_id, getuser_no_such_user_string, 1);
+               tcase_add_exit_test(tc_id, getuser_no_such_user_numeric, 1);
+       }
        tcase_add_test(tc_id, getgroup_root_string);
        tcase_add_test(tc_id, getgroup_root_numeric);
-       tcase_add_exit_test(tc_id, getgroup_no_such_user_string, 1);
-       tcase_add_exit_test(tc_id, getgroup_no_such_user_numeric, 1);
+       if (can_fork) {
+               tcase_add_exit_test(tc_id, getgroup_no_such_user_string, 1);
+               tcase_add_exit_test(tc_id, getgroup_no_such_user_numeric, 1);
+       }
        tcase_add_test(tc_id, setuser_with_empty_user);
        tcase_add_test(tc_id, setuser_with_current_user);
        tcase_add_test(tc_id, setgroup_with_empty_group);
index c7b2c1fe4fc0f4536c5f0df40cdb24a159e2759c..50829cf7111e322f1eb20d1529445525acc29454 100644 (file)
@@ -1,6 +1,6 @@
 #ifndef ID_TESTS_H
 #define ID_TESTS_H
 
-void add_id_tests(Suite *s);
+void add_id_tests(Suite *s, const int can_fork);
 
 #endif
index 183493a428dff6aefe8ae49fd140ff5e0070ec25..da7b33dcb68f98015a2d7421a5c6c157067a3010 100644 (file)
@@ -241,6 +241,7 @@ START_TEST(readproc_success)
 {
        linuxonly;
 
+       noexit = 0;
        ck_assert_int_eq(remove_directory(TESTDIR), 1);
        fake_proc_net_dev("w", "ethwrong", 10, 20, 30, 40);
        fake_proc_net_dev("a", "ethunusual", 1, 2, 3, 4);
@@ -270,6 +271,7 @@ START_TEST(readsysclassnet_success)
 {
        linuxonly;
 
+       noexit = 0;
        ck_assert_int_eq(remove_directory(TESTDIR), 1);
        fake_sys_class_net("ethwrong", 10, 20, 30, 40, 50);
        fake_sys_class_net("ethunusual", 1, 2, 3, 4, 5);
@@ -288,10 +290,11 @@ START_TEST(getifinfo_not_found)
 {
        linuxonly;
 
-       suppress_output();
        ck_assert_int_eq(remove_directory(TESTDIR), 1);
        fake_proc_net_dev("w", "ethwrong", 10, 20, 30, 40);
 
+       suppress_output();
+
        ck_assert_int_eq(getifinfo("ethunusual"), 0);
 }
 END_TEST
@@ -300,12 +303,13 @@ START_TEST(getifinfo_success)
 {
        linuxonly;
 
-       suppress_output();
-
+       noexit = 0;
        ck_assert_int_eq(remove_directory(TESTDIR), 1);
        fake_proc_net_dev("w", "ethwrong", 10, 20, 30, 40);
        fake_proc_net_dev("a", "ethunusual", 1, 2, 3, 4);
 
+       suppress_output();
+
        ck_assert_int_eq(getifinfo("ethunusual"), 1);
        ck_assert_str_eq(ifinfo.name, "ethunusual");
        ck_assert_int_eq(ifinfo.filled, 1);
@@ -320,12 +324,12 @@ START_TEST(isifavailable_knows_interface_availability)
 {
        linuxonly;
 
-       suppress_output();
-
        ck_assert_int_eq(remove_directory(TESTDIR), 1);
        fake_proc_net_dev("w", "eth0", 10, 20, 30, 40);
        fake_proc_net_dev("a", "eth1", 1, 2, 3, 4);
 
+       suppress_output();
+
        ck_assert_int_eq(isifavailable("eth0"), 1);
        ck_assert_int_eq(isifavailable("eth1"), 1);
        ck_assert_int_eq(isifavailable("eth2"), 0);
@@ -335,6 +339,8 @@ END_TEST
 void add_ifinfo_tests(Suite *s)
 {
        TCase *tc_ifinfo = tcase_create("Ifinfo");
+       tcase_add_checked_fixture(tc_ifinfo, setup, teardown);
+       tcase_add_unchecked_fixture(tc_ifinfo, setup, teardown);
        tcase_add_test(tc_ifinfo, getifliststring_no_source);
        tcase_add_test(tc_ifinfo, getifliststring_proc_one_interface);
        tcase_add_test(tc_ifinfo, getifliststring_proc_one_interface_with_speed);
index 474b685938ca68d71d61d5d51c6354ee3c82afa3..6793134f8dc37c9bc49ada5cc2761a8819ca8b87 100644 (file)
@@ -111,6 +111,8 @@ END_TEST
 void add_iflist_tests(Suite *s)
 {
        TCase *tc_iflist = tcase_create("Iflist");
+       tcase_add_checked_fixture(tc_iflist, setup, teardown);
+       tcase_add_unchecked_fixture(tc_iflist, setup, teardown);
        tcase_add_test(tc_iflist, iflistfree_can_free_null);
     tcase_add_test(tc_iflist, iflistadd_can_add);
     tcase_add_test(tc_iflist, iflistsearch_can_search);
index 3d573142c41876a53dd3d84d8e7d589dd59f4ff3..9b73e20d48146c0bffa3c8dedbf9da85ca37a64f 100644 (file)
@@ -94,6 +94,7 @@ END_TEST
 
 START_TEST(getimagescale_zero)
 {
+       cfg.rateunit = 0;
        ck_assert_str_eq(getimagescale(0, 0), "--");
        ck_assert_str_eq(getimagescale(0, 1), "--");
 }
@@ -101,6 +102,7 @@ END_TEST
 
 START_TEST(getimagescale_normal)
 {
+       cfg.rateunit = 0;
        ck_assert_str_eq(getimagescale(1, 0), "B");
        ck_assert_str_eq(getimagescale(2, 0), "B");
        ck_assert_str_eq(getimagescale(10, 0), "B");
@@ -116,6 +118,7 @@ END_TEST
 
 START_TEST(getimagescale_rate)
 {
+       cfg.rateunit = 0;
        ck_assert_str_eq(getimagescale(1, 1), "B/s");
        ck_assert_str_eq(getimagescale(2, 1), "B/s");
        ck_assert_str_eq(getimagescale(10, 1), "B/s");
@@ -695,6 +698,8 @@ END_TEST
 void add_image_tests(Suite *s)
 {
        TCase *tc_image = tcase_create("Image");
+       tcase_add_checked_fixture(tc_image, setup, teardown);
+       tcase_add_unchecked_fixture(tc_image, setup, teardown);
        tcase_set_timeout(tc_image, 10);
        tcase_add_test(tc_image, initimagecontent_does_not_crash);
        tcase_add_test(tc_image, colorinit_does_not_crash);
index a1bbe43d66d0a824c9daa630d2c5677d426406cd..6856b0fb0c1eaa41053a714c8654e680bf3d61f7 100644 (file)
@@ -708,6 +708,8 @@ END_TEST
 void add_misc_tests(Suite *s)
 {
        TCase *tc_misc = tcase_create("Misc");
+       tcase_add_checked_fixture(tc_misc, setup, teardown);
+       tcase_add_unchecked_fixture(tc_misc, setup, teardown);
        tcase_add_test(tc_misc, getbtime_does_not_return_zero);
        tcase_add_loop_test(tc_misc, getunitprefix_returns_something_with_all_cfg_combinations, 0, 2);
        tcase_add_loop_test(tc_misc, getrateunitprefix_returns_something_with_all_cfg_combinations, 0, 3);
index d91a01f57a720522b3380f83d4ee07cba029020c..ce6f4761e4f9944e78de59447d22812e495750e7 100644 (file)
 #include "image_tests.h"
 #endif
 
+int output_suppressed = 0;
+
 int main(void)
 {
        int number_failed = 0;
        debug = 0;
 
-       Suite *s = test_suite();
+       Suite *s = test_suite(get_fork_status());
        SRunner *sr = srunner_create(s);
        srunner_set_log(sr, "test.log");
        srunner_set_xml(sr, "test.xml");
@@ -35,20 +37,20 @@ int main(void)
        return number_failed;
 }
 
-Suite *test_suite(void)
+Suite *test_suite(const int can_fork)
 {
        Suite *s = suite_create("vnStat");
 
-       add_common_tests(s);
+       add_common_tests(s, can_fork);
        add_dbsql_tests(s);
        add_database_tests(s);
        add_config_tests(s);
        add_ifinfo_tests(s);
        add_misc_tests(s);
-       add_daemon_tests(s);
+       add_daemon_tests(s, can_fork);
        add_datacache_tests(s);
        add_fs_tests(s);
-       add_id_tests(s);
+       add_id_tests(s, can_fork);
        add_iflist_tests(s);
 #if defined(HAVE_IMAGE)
        add_image_tests(s);
@@ -57,9 +59,42 @@ Suite *test_suite(void)
        return s;
 }
 
+/* exit tests can't be executed if check doesn't have forking enabled */
+/* and only SRunner knows that so a dummy runner needs to be created */
+int get_fork_status(void)
+{
+       int can_fork = 0;
+       Suite *s = suite_create("fork status check");
+       SRunner *sr = srunner_create(s);
+       if (srunner_fork_status(sr) != CK_NOFORK) {
+               can_fork = 1;
+       }
+       srunner_free(sr);
+       return can_fork;
+}
+
+void setup(void) {
+       debug = 0;
+}
+
+void teardown(void) {
+       restore_output();
+}
+
 void suppress_output(void)
 {
-       fclose(stdout);
+       if (!output_suppressed) {
+               fclose(stdout);
+               output_suppressed = 1;
+       }
+}
+
+void restore_output(void)
+{
+       if (output_suppressed) {
+               freopen("/dev/tty", "w", stdout);
+               output_suppressed = 0;
+       }
 }
 
 int pipe_output(void)
@@ -70,9 +105,12 @@ int pipe_output(void)
                ck_abort_msg("error \"%s\" while creating pipe", strerror(errno));
        }
 
-       dup2(out_pipe[1], STDOUT_FILENO);
-       close(out_pipe[1]);
+       if (out_pipe[1] != STDOUT_FILENO) {
+               dup2(out_pipe[1], STDOUT_FILENO);
+               close(out_pipe[1]);
+       }
 
+       output_suppressed = 1;
        return out_pipe[0];
 }
 
index 7e83d4b4b6e2ba697c6e0923f8d81b2631cb436a..a675c2114cb9d28234aa08a892472b84cd624400 100644 (file)
@@ -3,8 +3,14 @@
 
 #include <check.h>
 
-Suite *test_suite(void);
+extern int output_suppressed;
+
+Suite *test_suite(const int can_fork);
+int get_fork_status(void);
+void setup(void);
+void teardown(void);
 void suppress_output(void);
+void restore_output(void);
 int pipe_output(void);
 void disable_logprints(void);
 int clean_testdbdir(void);