[PATCH 1/6] test: Make test_timeperiods functional
Robin Sonefors
robin.sonefors at op5.com
Mon May 6 18:04:28 CEST 2013
I intend to refactor the time periods, and need a bit of encouragement
from something that tells me that everything is OK.
Signed-off-by: Robin Sonefors <robin.sonefors at op5.com>
---
base/utils.c | 2 +-
t-tap/Makefile.in | 8 +-
t-tap/test_timeperiods.c | 196 ++---------------------------------------------
3 files changed, 13 insertions(+), 193 deletions(-)
diff --git a/base/utils.c b/base/utils.c
index 44cf98d..73ac13b 100644
--- a/base/utils.c
+++ b/base/utils.c
@@ -991,7 +991,7 @@ int check_time_against_period(time_t test_time, timeperiod *tperiod) {
/*#define TEST_TIMEPERIODS_B 1*/
/* Separate this out from public get_next_valid_time for testing, so we can mock current_time */
-static void _get_next_valid_time(time_t pref_time, time_t current_time, time_t *valid_time, timeperiod *tperiod) {
+void _get_next_valid_time(time_t pref_time, time_t current_time, time_t *valid_time, timeperiod *tperiod) {
time_t preferred_time = (time_t)0L;
timerange *temp_timerange;
daterange *temp_daterange;
diff --git a/t-tap/Makefile.in b/t-tap/Makefile.in
index f686d99..3079ee0 100644
--- a/t-tap/Makefile.in
+++ b/t-tap/Makefile.in
@@ -10,7 +10,7 @@ SRC_CGI=../cgi
SRC_COMMON=../common
CC=@CC@
-CFLAGS=@CFLAGS@ @DEFS@ -DNSCORE -I../include -I../tap/src
+CFLAGS=@CFLAGS@ @DEFS@ -DNSCORE -I../include -I../tap/src -I..
TESTS = test_logging test_events test_timeperiods test_nagios_config
TESTS += test_xsddefault
@@ -22,11 +22,11 @@ TESTS += test_downtime
XSD_OBJS = $(SRC_CGI)/statusdata-cgi.o $(SRC_CGI)/xstatusdata-cgi.o
XSD_OBJS += $(SRC_CGI)/objects-cgi.o $(SRC_CGI)/xobjects-cgi.o
XSD_OBJS += $(SRC_CGI)/comments-cgi.o $(SRC_CGI)/downtime-cgi.o
-XSD_OBJS += $(SRC_CGI)/cgiutils.o $(SRC_CGI)/skiplist.o ../common/shared.o
+XSD_OBJS += $(SRC_CGI)/cgiutils.o ../common/shared.o
TP_OBJS = $(SRC_BASE)/utils.o $(SRC_BASE)/config.o $(SRC_BASE)/macros-base.o
TP_OBJS += $(SRC_BASE)/objects-base.o $(SRC_BASE)/xobjects-base.o
-TP_OBJS += $(SRC_BASE)/skiplist.o ../common/shared.o
+TP_OBJS += ../common/shared.o
CFG_OBJS = $(TP_OBJS)
CFG_OBJS += $(SRC_BASE)/comments-base.o $(SRC_BASE)/xcomments-base.o
@@ -35,7 +35,7 @@ CFG_OBJS += $(SRC_BASE)/retention-base.o $(SRC_BASE)/xretention-base.o
LDFLAGS=@LDFLAGS@
-LIBS=@LIBS@
+LIBS=@LIBS@ ../lib/libnagios.a
prefix=@prefix@
exec_prefix=@exec_prefix@
diff --git a/t-tap/test_timeperiods.c b/t-tap/test_timeperiods.c
index 534ece1..9663231 100644
--- a/t-tap/test_timeperiods.c
+++ b/t-tap/test_timeperiods.c
@@ -43,191 +43,6 @@
#include "../include/nebmodules.h"
#include "tap.h"
-char *config_file = NULL;
-char *log_file = NULL;
-char *command_file = NULL;
-char *temp_file = NULL;
-char *temp_path = NULL;
-char *check_result_path = NULL;
-char *lock_file = NULL;
-char *log_archive_path = NULL;
-char *nagios_user = NULL;
-char *nagios_group = NULL;
-
-extern char *macro_x[MACRO_X_COUNT];
-
-char *global_host_event_handler = NULL;
-char *global_service_event_handler = NULL;
-command *global_host_event_handler_ptr = NULL;
-command *global_service_event_handler_ptr = NULL;
-
-char *ocsp_command = NULL;
-char *ochp_command = NULL;
-command *ocsp_command_ptr = NULL;
-command *ochp_command_ptr = NULL;
-
-char *illegal_object_chars = NULL;
-char *illegal_output_chars = NULL;
-
-int use_regexp_matches = FALSE;
-int use_true_regexp_matching = FALSE;
-
-int use_syslog = DEFAULT_USE_SYSLOG;
-int log_notifications = DEFAULT_NOTIFICATION_LOGGING;
-int log_service_retries = DEFAULT_LOG_SERVICE_RETRIES;
-int log_host_retries = DEFAULT_LOG_HOST_RETRIES;
-int log_event_handlers = DEFAULT_LOG_EVENT_HANDLERS;
-int log_initial_states = DEFAULT_LOG_INITIAL_STATES;
-int log_external_commands = DEFAULT_LOG_EXTERNAL_COMMANDS;
-int log_passive_checks = DEFAULT_LOG_PASSIVE_CHECKS;
-
-unsigned long logging_options = 0;
-unsigned long syslog_options = 0;
-
-int service_check_timeout = DEFAULT_SERVICE_CHECK_TIMEOUT;
-int host_check_timeout = DEFAULT_HOST_CHECK_TIMEOUT;
-int event_handler_timeout = DEFAULT_EVENT_HANDLER_TIMEOUT;
-int notification_timeout = DEFAULT_NOTIFICATION_TIMEOUT;
-int ocsp_timeout = DEFAULT_OCSP_TIMEOUT;
-int ochp_timeout = DEFAULT_OCHP_TIMEOUT;
-
-int interval_length = DEFAULT_INTERVAL_LENGTH;
-int service_inter_check_delay_method = ICD_SMART;
-int host_inter_check_delay_method = ICD_SMART;
-int service_interleave_factor_method = ILF_SMART;
-int max_host_check_spread = DEFAULT_HOST_CHECK_SPREAD;
-int max_service_check_spread = DEFAULT_SERVICE_CHECK_SPREAD;
-
-int command_check_interval = DEFAULT_COMMAND_CHECK_INTERVAL;
-int check_reaper_interval = DEFAULT_CHECK_REAPER_INTERVAL;
-int max_check_reaper_time = DEFAULT_MAX_REAPER_TIME;
-int service_freshness_check_interval = DEFAULT_FRESHNESS_CHECK_INTERVAL;
-int host_freshness_check_interval = DEFAULT_FRESHNESS_CHECK_INTERVAL;
-int auto_rescheduling_interval = DEFAULT_AUTO_RESCHEDULING_INTERVAL;
-
-int check_external_commands = DEFAULT_CHECK_EXTERNAL_COMMANDS;
-int check_orphaned_services = DEFAULT_CHECK_ORPHANED_SERVICES;
-int check_orphaned_hosts = DEFAULT_CHECK_ORPHANED_HOSTS;
-int check_service_freshness = DEFAULT_CHECK_SERVICE_FRESHNESS;
-int check_host_freshness = DEFAULT_CHECK_HOST_FRESHNESS;
-int auto_reschedule_checks = DEFAULT_AUTO_RESCHEDULE_CHECKS;
-int auto_rescheduling_window = DEFAULT_AUTO_RESCHEDULING_WINDOW;
-
-int additional_freshness_latency = DEFAULT_ADDITIONAL_FRESHNESS_LATENCY;
-int allow_empty_hostgroup_assignment = DEFAULT_ALLOW_EMPTY_HOSTGROUP_ASSIGNMENT;
-
-int check_for_updates = DEFAULT_CHECK_FOR_UPDATES;
-int bare_update_check = DEFAULT_BARE_UPDATE_CHECK;
-time_t last_update_check = 0L;
-int update_available = FALSE;
-char *last_program_version = NULL;
-char *new_program_version = NULL;
-
-time_t last_log_rotation = 0L;
-
-int use_aggressive_host_checking = DEFAULT_AGGRESSIVE_HOST_CHECKING;
-unsigned long cached_host_check_horizon = DEFAULT_CACHED_HOST_CHECK_HORIZON;
-unsigned long cached_service_check_horizon = DEFAULT_CACHED_SERVICE_CHECK_HORIZON;
-int enable_predictive_host_dependency_checks = DEFAULT_ENABLE_PREDICTIVE_HOST_DEPENDENCY_CHECKS;
-int enable_predictive_service_dependency_checks = DEFAULT_ENABLE_PREDICTIVE_SERVICE_DEPENDENCY_CHECKS;
-
-int soft_state_dependencies = FALSE;
-
-int retain_state_information = FALSE;
-int retention_update_interval = DEFAULT_RETENTION_UPDATE_INTERVAL;
-int use_retained_program_state = TRUE;
-int use_retained_scheduling_info = FALSE;
-int retention_scheduling_horizon = DEFAULT_RETENTION_SCHEDULING_HORIZON;
-unsigned long modified_host_process_attributes = MODATTR_NONE;
-unsigned long modified_service_process_attributes = MODATTR_NONE;
-unsigned long retained_host_attribute_mask = 0L;
-unsigned long retained_service_attribute_mask = 0L;
-unsigned long retained_contact_host_attribute_mask = 0L;
-unsigned long retained_contact_service_attribute_mask = 0L;
-unsigned long retained_process_host_attribute_mask = 0L;
-unsigned long retained_process_service_attribute_mask = 0L;
-
-unsigned long next_comment_id = 0L;
-unsigned long next_downtime_id = 0L;
-unsigned long next_event_id = 0L;
-unsigned long next_problem_id = 0L;
-unsigned long next_notification_id = 0L;
-
-int log_rotation_method = LOG_ROTATION_NONE;
-
-int sigshutdown = FALSE;
-int sigrestart = FALSE;
-char *sigs[35] = {"EXIT", "HUP", "INT", "QUIT", "ILL", "TRAP", "ABRT", "BUS", "FPE", "KILL", "USR1", "SEGV", "USR2", "PIPE", "ALRM", "TERM", "STKFLT", "CHLD", "CONT", "STOP", "TSTP", "TTIN", "TTOU", "URG", "XCPU", "XFSZ", "VTALRM", "PROF", "WINCH", "IO", "PWR", "UNUSED", "ZERR", "DEBUG", (char *)NULL};
-int caught_signal = FALSE;
-int sig_id = 0;
-
-int restarting = FALSE;
-
-int verify_config = FALSE;
-int test_scheduling = FALSE;
-int precache_objects = FALSE;
-int use_precached_objects = FALSE;
-
-int daemon_mode = FALSE;
-int daemon_dumps_core = TRUE;
-
-int max_parallel_service_checks = DEFAULT_MAX_PARALLEL_SERVICE_CHECKS;
-int currently_running_service_checks = 0;
-int currently_running_host_checks = 0;
-
-time_t program_start = 0L;
-time_t event_start = 0L;
-int nagios_pid = 0;
-int enable_notifications = TRUE;
-int execute_service_checks = TRUE;
-int accept_passive_service_checks = TRUE;
-int execute_host_checks = TRUE;
-int accept_passive_host_checks = TRUE;
-int enable_event_handlers = TRUE;
-int obsess_over_services = FALSE;
-int obsess_over_hosts = FALSE;
-
-int translate_passive_host_checks = DEFAULT_TRANSLATE_PASSIVE_HOST_CHECKS;
-int passive_host_checks_are_soft = DEFAULT_PASSIVE_HOST_CHECKS_SOFT;
-
-int status_update_interval = DEFAULT_STATUS_UPDATE_INTERVAL;
-
-int time_change_threshold = DEFAULT_TIME_CHANGE_THRESHOLD;
-
-unsigned long event_broker_options = BROKER_NOTHING;
-
-int process_performance_data = DEFAULT_PROCESS_PERFORMANCE_DATA;
-
-int enable_flap_detection = DEFAULT_ENABLE_FLAP_DETECTION;
-
-double low_service_flap_threshold = DEFAULT_LOW_SERVICE_FLAP_THRESHOLD;
-double high_service_flap_threshold = DEFAULT_HIGH_SERVICE_FLAP_THRESHOLD;
-double low_host_flap_threshold = DEFAULT_LOW_HOST_FLAP_THRESHOLD;
-double high_host_flap_threshold = DEFAULT_HIGH_HOST_FLAP_THRESHOLD;
-
-int use_large_installation_tweaks = DEFAULT_USE_LARGE_INSTALLATION_TWEAKS;
-int enable_environment_macros = TRUE;
-int free_child_process_memory = -1;
-int child_processes_fork_twice = -1;
-
-int date_format = DATE_FORMAT_US;
-char *use_timezone = NULL;
-
-unsigned long update_uid = 0L;
-
-
-notification *notification_list;
-
-unsigned long max_check_result_file_age = DEFAULT_MAX_CHECK_RESULT_AGE;
-
-check_stats check_statistics[MAX_CHECK_STATS_TYPES];
-
-char *debug_file;
-int debug_level = DEFAULT_DEBUG_LEVEL;
-int debug_verbosity = DEFAULT_DEBUG_VERBOSITY;
-unsigned long max_debug_file_size = DEFAULT_MAX_DEBUG_FILE_SIZE;
-
-
/* Dummy variables */
sched_info scheduling_info;
timed_event event_list_low;
@@ -249,10 +64,15 @@ int neb_unload_all_modules(int flags, int reason) {}
int neb_add_module(char *filename, char *args, int should_be_loaded) {}
void broker_system_command(int type, int flags, int attr, struct timeval start_time, struct timeval end_time, double exectime, int timeout, int early_timeout, int retcode, char *cmd, char *output, struct timeval *timestamp) {}
-int schedule_new_event(int event_type, int high_priority, time_t run_time, int recurring, unsigned long event_interval, void *timing_func, int compensate_for_time_change, void *event_data, void *event_args, int event_options) {}
+timed_event *schedule_new_event(int event_type, int high_priority, time_t run_time, int recurring, unsigned long event_interval, void *timing_func, int compensate_for_time_change, void *event_data, void *event_args, int event_options) {}
int my_tcp_connect(char *host_name, int port, int *sd, int timeout) {}
int my_recvall(int s, char *buf, int *len, int timeout) {}
int neb_free_module_list(void) {}
+int close_command_file(void) {}
+int close_log_file(void) {}
+int fix_log_file_owner(uid_t uid, gid_t gid) {}
+int handle_async_service_check_result(service *temp_service, check_result *queued_check_result) {}
+int handle_async_host_check_result(host *temp_host, check_result *queued_check_result) {}
int main(int argc, char **argv) {
int result;
@@ -376,7 +196,7 @@ int main(int argc, char **argv) {
/* Timeperiod exclude tests, from Jean Gabes */
temp_timeperiod = find_timeperiod("Test_exclude");
ok(temp_timeperiod != NULL, "ME: Testing Exclude timeperiod");
- test_time = 1278939600;
+ test_time = 1278939600; //mon jul 12 15:00:00
/* printf("Testing at time %s", ctime(&test_time)); */
is_valid_time = check_time_against_period(test_time, temp_timeperiod);
ok(is_valid_time == ERROR, "ME: 12 Jul 2010 15:00:00 - false");
@@ -384,7 +204,7 @@ int main(int argc, char **argv) {
_get_next_valid_time(test_time, test_time, &chosen_valid_time, temp_timeperiod);
/* printf("JEAN: Got chosent time at %s", ctime(&chosen_valid_time)); */
todo_start("Bug in exclude");
- ok(chosen_valid_time == 1288103400, "ME: Next valid time=Tue Oct 26 16:30:00 2010");
+ ok(chosen_valid_time == 1288103400, "ME: Next valid time=Tue Oct 26 16:30:00 2010, was %i", chosen_valid_time);
todo_end();
--
1.7.11.7
------------------------------------------------------------------------------
Introducing AppDynamics Lite, a free troubleshooting tool for Java/.NET
Get 100% visibility into your production application - at no cost.
Code-level diagnostics for performance bottlenecks with <2% overhead
Download for free and get started troubleshooting in minutes.
http://p.sf.net/sfu/appdyn_d2d_ap1
More information about the Developers
mailing list