]> granicus.if.org Git - vnstat/commitdiff
show error if Check doesn't have fork mode enabled when tests are executed
authorTeemu Toivola <git@humdi.net>
Sun, 7 Jul 2019 23:10:51 +0000 (02:10 +0300)
committerTeemu Toivola <git@humdi.net>
Sun, 7 Jul 2019 23:10:51 +0000 (02:10 +0300)
tests/common_tests.c
tests/common_tests.h
tests/daemon_tests.c
tests/daemon_tests.h
tests/database_tests.c
tests/id_tests.c
tests/id_tests.h
tests/vnstat_tests.c
tests/vnstat_tests.h

index 0cd60edc1ff1ed5fd48485d8f87eda7334a05123..dc2ff7f58dcfff172e6be8a1452c0c371422946a 100644 (file)
@@ -359,9 +359,6 @@ 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);
 }
@@ -385,9 +382,6 @@ 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
@@ -421,7 +415,7 @@ START_TEST(can_panic)
 }
 END_TEST
 
-void add_common_tests(Suite *s, const int can_fork)
+void add_common_tests(Suite *s)
 {
        TCase *tc_common = tcase_create("Common");
        tcase_add_checked_fixture(tc_common, setup, teardown);
@@ -454,8 +448,6 @@ void add_common_tests(Suite *s, const int can_fork)
        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);
-       if (can_fork) {
-               tcase_add_exit_test(tc_common, can_panic, 1);
-       }
+       tcase_add_exit_test(tc_common, can_panic, 1);
        suite_add_tcase(s, tc_common);
 }
index 7cd854c4cc240561dadbfab079f681765fa96119..2b3f4473f1f943184b60791903414b3d2dd7be43 100644 (file)
@@ -1,6 +1,6 @@
 #ifndef COMMON_TESTS_H
 #define COMMON_TESTS_H
 
-void add_common_tests(Suite *s, const int can_fork);
+void add_common_tests(Suite *s);
 
 #endif
index 1cfc1a2db1e7e3601d3f23d29a3221789fa87757..50e5e0ca2dae25cefa08d161e93ce93069878c10 100644 (file)
@@ -1434,7 +1434,7 @@ START_TEST(datacache_status_has_no_issues_with_large_number_of_interfaces)
 }
 END_TEST
 
-void add_daemon_tests(Suite *s, const int can_fork)
+void add_daemon_tests(Suite *s)
 {
        TCase *tc_daemon = tcase_create("Daemon");
        tcase_add_checked_fixture(tc_daemon, setup, teardown);
@@ -1445,16 +1445,12 @@ void add_daemon_tests(Suite *s, const int can_fork)
        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);
-       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_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);
-       if (can_fork) {
-               tcase_add_exit_test(tc_daemon, filldatabaselist_exits_with_no_database_dir, 1);
-       }
+       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);
@@ -1489,19 +1485,13 @@ void add_daemon_tests(Suite *s, const int can_fork)
        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);
-       if (can_fork) {
-               tcase_add_exit_test(tc_daemon, handledatabaseerror_exits_on_fatal_error, 1);
-       }
+       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);
-       if (can_fork) {
-               tcase_add_exit_test(tc_daemon, handledatabaseerror_exits_if_limit_is_reached, 1);
-       }
+       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);
-       if (can_fork) {
-               tcase_add_exit_test(tc_daemon, processifinfo_exits_if_timestamps_really_make_no_sense, 1);
-       }
+       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 dc63756e39768acfb1be5923ed88691e0d7951e0..09deb8c15227462d1bd6c63b5795458a3dc87f82 100644 (file)
@@ -1,6 +1,6 @@
 #ifndef DAEMON_TESTS_H
 #define DAEMON_TESTS_H
 
-void add_daemon_tests(Suite *s, const int can_fork);
+void add_daemon_tests(Suite *s);
 
 #endif
index ef49af4738d3291390f6d4bf4f37c5e010d9bd14..5e6b3d8a99982d4a1556a8c9bb25403b3616b62f 100644 (file)
@@ -444,8 +444,6 @@ 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
@@ -465,8 +463,6 @@ 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
@@ -486,8 +482,6 @@ 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
@@ -507,8 +501,6 @@ 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
@@ -528,8 +520,6 @@ 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
@@ -558,8 +548,6 @@ 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
index 66a6a119bb468f80e014f313f7059fe4db7d3fc9..4c60d88e8bd60e18236373ed673efc3414db4a31 100644 (file)
@@ -107,23 +107,19 @@ START_TEST(setgroup_with_current_group)
 }
 END_TEST
 
-void add_id_tests(Suite *s, const int can_fork)
+void add_id_tests(Suite *s)
 {
        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);
-       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_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);
-       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_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 50829cf7111e322f1eb20d1529445525acc29454..c7b2c1fe4fc0f4536c5f0df40cdb24a159e2759c 100644 (file)
@@ -1,6 +1,6 @@
 #ifndef ID_TESTS_H
 #define ID_TESTS_H
 
-void add_id_tests(Suite *s, const int can_fork);
+void add_id_tests(Suite *s);
 
 #endif
index ce6f4761e4f9944e78de59447d22812e495750e7..0a3906580452426ca61c4102f340bd1645fbfd75 100644 (file)
@@ -19,11 +19,13 @@ int output_suppressed = 0;
 
 int main(void)
 {
+       Suite *s;
+       SRunner *sr;
        int number_failed = 0;
-       debug = 0;
 
-       Suite *s = test_suite(get_fork_status());
-       SRunner *sr = srunner_create(s);
+       verify_fork_status();
+       s = test_suite();
+       sr = srunner_create(s);
        srunner_set_log(sr, "test.log");
        srunner_set_xml(sr, "test.xml");
        srunner_run_all(sr, CK_NORMAL);
@@ -37,20 +39,20 @@ int main(void)
        return number_failed;
 }
 
-Suite *test_suite(const int can_fork)
+Suite *test_suite(void)
 {
        Suite *s = suite_create("vnStat");
 
-       add_common_tests(s, can_fork);
+       add_common_tests(s);
        add_dbsql_tests(s);
        add_database_tests(s);
        add_config_tests(s);
        add_ifinfo_tests(s);
        add_misc_tests(s);
-       add_daemon_tests(s, can_fork);
+       add_daemon_tests(s);
        add_datacache_tests(s);
        add_fs_tests(s);
-       add_id_tests(s, can_fork);
+       add_id_tests(s);
        add_iflist_tests(s);
 #if defined(HAVE_IMAGE)
        add_image_tests(s);
@@ -59,18 +61,17 @@ Suite *test_suite(const int can_fork)
        return s;
 }
 
-/* exit tests can't be executed if check doesn't have forking enabled */
+/* tests can't reliably 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)
+void verify_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;
+       if (srunner_fork_status(sr) == CK_NOFORK) {
+               printf("Error: Tests require Check to have fork mode enabled.\n");
+               exit(1);
        }
        srunner_free(sr);
-       return can_fork;
 }
 
 void setup(void) {
@@ -78,7 +79,7 @@ void setup(void) {
 }
 
 void teardown(void) {
-       restore_output();
+       ;
 }
 
 void suppress_output(void)
@@ -89,14 +90,6 @@ void suppress_output(void)
        }
 }
 
-void restore_output(void)
-{
-       if (output_suppressed) {
-               freopen("/dev/tty", "w", stdout);
-               output_suppressed = 0;
-       }
-}
-
 int pipe_output(void)
 {
        int out_pipe[2];
index a675c2114cb9d28234aa08a892472b84cd624400..bfdecf1e68c4107e939f1b1d339ad71d8c51842e 100644 (file)
@@ -5,8 +5,8 @@
 
 extern int output_suppressed;
 
-Suite *test_suite(const int can_fork);
-int get_fork_status(void);
+Suite *test_suite(void);
+void verify_fork_status(void);
 void setup(void);
 void teardown(void);
 void suppress_output(void);