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);
}
fflush(stdout);
len = (int)read(pipe, buffer, 512);
- close(STDOUT_FILENO);
- close(pipe);
-
ck_assert_int_eq(len, 1);
}
END_TEST
}
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);
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);
}
#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
}
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);
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);
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);
#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
fflush(stdout);
len = (int)read(pipe, buffer, 512);
- close(STDOUT_FILENO);
- close(pipe);
ck_assert_str_eq(buffer, " rrrrrrrrrr");
}
END_TEST
fflush(stdout);
len = (int)read(pipe, buffer, 512);
- close(STDOUT_FILENO);
- close(pipe);
ck_assert_str_eq(buffer, " tttttttttt");
}
END_TEST
fflush(stdout);
len = (int)read(pipe, buffer, 512);
- close(STDOUT_FILENO);
- close(pipe);
ck_assert_str_eq(buffer, " rrrrrttttt");
}
END_TEST
fflush(stdout);
len = (int)read(pipe, buffer, 512);
- close(STDOUT_FILENO);
- close(pipe);
ck_assert_str_eq(buffer, " rttttttttt");
}
END_TEST
fflush(stdout);
len = (int)read(pipe, buffer, 512);
- close(STDOUT_FILENO);
- close(pipe);
ck_assert_str_eq(buffer, " tttttttttt");
}
END_TEST
fflush(stdout);
len = (int)read(pipe, buffer, 512);
- close(STDOUT_FILENO);
- close(pipe);
ck_assert_str_eq(buffer, " rrrttt");
}
END_TEST
}
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);
#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
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);
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);
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) {
}
void teardown(void) {
- restore_output();
+ ;
}
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];
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);