2 // Name : test_stopwatch
3 // Author : Chris Koeritz
4 // Rights : Copyright (c) 1991-$now By Author
6 // This file is free software; you can modify/redistribute it under the terms
7 // of the GNU General Public License. [ http://www.gnu.org/licenses/gpl.html ]
8 // Feel free to send updates to: [ fred@gruntose.com ]
11 #include <application/application_shell.h>
12 #include <application/hoople_main.h>
13 #include <basis/functions.h>
14 #include <basis/guards.h>
15 #include <loggers/console_logger.h>
16 #include <loggers/critical_events.h>
17 #include <loggers/program_wide_logger.h>
18 #include <mathematics/chaos.h>
19 #include <structures/static_memory_gremlin.h>
20 #include <timely/stopwatch.h>
21 #include <timely/time_control.h>
23 using namespace basis;
24 using namespace application;
25 using namespace loggers;
26 using namespace mathematics;
27 using namespace structures;
28 using namespace timely;
32 // ACCEPT: acceptable timer deviation from the total time to wait.
33 // NOTE: timer characteristics and the sleep characteristics for machines vary.
34 // it may be necessary to play with ACCEPT to get this program to accept the
35 // machine's particular characteristics.
37 //#define WIDER_ACCEPT 0.05
38 //#define WIDEST_ACCEPT 0.20
40 #define WIDER_ACCEPT 0.95
41 #define WIDEST_ACCEPT 1.20
43 #define LOG(s) EMERGENCY_LOG(program_wide_logger::get(), s)
45 class test_stopwatch : public application_shell
48 test_stopwatch() : application_shell() {}
49 DEFINE_CLASS_NAME("test_stopwatch");
50 virtual int execute();
53 int test_stopwatch::execute()
58 int to_sleep = randomizer.inclusive(20, 100);
59 // needs longer ints for the last two checks...
61 time_control::sleep_ms(to_sleep);
64 LOG(a_sprintf("sleep of %0.3f seconds took %d milliseconds\n",
65 float(to_sleep) / 1000.0, fred_time.milliseconds()));
67 if (absolute_value(to_sleep - fred_time.milliseconds())
69 deadly_error(class_name(), "first", "unacceptable timer deviation");
72 to_sleep = randomizer.inclusive(76, 420);
74 time_control::sleep_ms(to_sleep);
77 LOG(a_sprintf("sleep of %0.3f seconds took %d milliseconds\n",
78 float(to_sleep) / 1000.0, fred_time.milliseconds()));
80 if (absolute_value(to_sleep - fred_time.milliseconds()) > ACCEPT * to_sleep)
81 deadly_error(class_name(), "second", "unacceptable timer deviation");
84 critical_events::alert_message("stopwatch:: works for those functions tested.");
88 HOOPLE_MAIN(test_stopwatch, )