48#define LOG(s) STAMPED_EMERGENCY_LOG(program_wide_logger::get(), s)
63 virtual ~timer_driver_tester() {}
69 bool in_progress()
const {
return _in_progress; }
83class timer_test_thread :
public ethread
94 deadly_error(class_name(), func,
"start time is before current time.");
96 deadly_error(class_name(), func,
"last check is before current time.");
101 deadly_error(class_name(), func,
"jed is less than test.");
112class my_timer_handler :
public timeable
115 my_timer_handler(timer_driver_tester &parent,
int id) : _id(id), _parent(parent) {}
116 virtual ~my_timer_handler() {}
120 FUNCDEF(
"handle_timer_callback");
121 if (_parent.in_progress())
122 LOG(
"saw in progress flag set to true! we interrupted real "
123 "ops, not just sleep!");
125 timer_test_thread *new_thread =
new timer_test_thread(_parent);
129 deadly_error(class_name(), func,
"failed to start a new thread.");
132 int gone_index = _parent.randomizer().inclusive(0, _parent.threads().threads() - 1);
133 unique_int gone_thread = _parent.threads().thread_ids()[gone_index];
134 _parent.threads().cancel_thread(gone_thread);
137 _parent.threads().clean_debris();
139 LOG(
a_sprintf(
"%d threads checking time_stamp.", _parent.threads().threads()));
144 timer_driver_tester &_parent;
149#define CREATE_TIMER(name, id, dur) \
150 my_timer_handler name(*this, id); \
151 program_wide_timer().set_timer(dur, &name); \
152 LOG(astring("created timer ") + #name + " which hits every " + #dur + " ms")
154#define ZAP_TIMER(name) \
155 program_wide_timer().zap_timer(&name)
157int timer_driver_tester::execute()
174 LOG(
"pausing for a while...");
182 for (
int i = 1; i < 50; i++) {
185 _in_progress =
false;
189 bool okay = event_extensions::poll();
The application_shell is a base object for console programs.
virtual int execute()=0
< retrieves the command line from the /proc hierarchy on linux.
application_shell()
constructs an application_shell to serve as the root of the program.
a_sprintf is a specialization of astring that provides printf style support.
Provides a dynamically resizable ASCII character string.
int convert(int default_value) const
Converts the string into a corresponding integer.
static void alert_message(const char *info, const char *title="Alert Message")
shows the message in "info", with an optional "title" on the message.
Provides a platform-independent object for adding threads to a program.
bool start(void *thread_data)
causes the thread to start, if it has not already been started.
virtual void perform_activity(void *thread_data)=0
< invoked just after after start(), when the OS thread is created.
Manages a collection of threads.
A unique identifier based on integers.
static void sleep_ms(basis::un_int msec)
a system independent name for a forced snooze measured in milliseconds.
Represents a point in time relative to the operating system startup time.
timeable is the base for objects that can be hooked into timer events.
virtual void handle_timer_callback()=0
this method is invoked when the timer period elapses for this object.
#define deadly_error(c, f, i)
#define NULL_POINTER
The value representing a pointer to nothing.
#define DEFINE_CLASS_NAME(objname)
Defines the name of a class by providing a couple standard methods.
#define FUNCDEF(func_in)
FUNCDEF sets the name of a function (and plugs it into the callstack).
Provides macros that implement the 'main' program of an application.
#define HOOPLE_MAIN(obj_name, obj_args)
options that should work for most unix and linux apps.
Implements an application lock to ensure only one is running at once.
The guards collection helps in testing preconditions and reporting errors.
const int SECOND_ms
Number of milliseconds in a second.
A platform independent way to obtain the timestamp of a file.
A logger that sends to the console screen using the standard output device.
A dynamic container class that holds any kind of object via pointers.
Useful support functions for unit testing, especially within hoople.
#define CREATE_TIMER(name, id, dur)
const int DEFAULT_TEST_DURATION