40 using namespace basis;
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; }
83 class timer_test_thread :
public ethread
91 void perform_activity(
void *) {
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.");
112 class my_timer_handler :
public timeable
115 my_timer_handler(timer_driver_tester &parent,
int id) : _id(id), _parent(parent) {}
116 virtual ~my_timer_handler() {}
119 virtual void handle_timer_callback() {
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);
135 time_control::sleep_ms(100);
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)
157 int timer_driver_tester::execute()
174 LOG(
"pausing for a while...");
182 for (
int i = 1; i < 50; i++) {
185 _in_progress =
false;
187 time_control::sleep_ms(100);
189 bool okay = event_extensions::poll();
200 critical_events::alert_message(
astring(class_name()) +
": works for those functions tested.");
The application_shell is a base object for console programs.
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.
Provides a platform-independent object for adding threads to a program.
Manages a collection of threads.
A unique identifier based on integers.
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.
#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