feisty meow concerns codebase 2.140
test_time_stamp.cpp
Go to the documentation of this file.
1/*****************************************************************************\
2* *
3* Name : test_time_stamp *
4* Author : Chris Koeritz *
5* *
6*******************************************************************************
7* Copyright (c) 1998-$now By Author. This program is free software; you can *
8* redistribute it and/or modify it under the terms of the GNU General Public *
9* License as published by the Free Software Foundation; either version 2 of *
10* the License or (at your option) any later version. This is online at: *
11* http://www.fsf.org/copyleft/gpl.html *
12* Please send any updates to: fred@gruntose.com *
13\*****************************************************************************/
14
17#include <basis/astring.h>
18#include <basis/guards.h>
21#include <timely/time_control.h>
22#include <timely/time_stamp.h>
23#include <unit_test/unit_base.h>
24
25using namespace application;
26using namespace basis;
27using namespace loggers;
28using namespace structures;
29using namespace textual;
30using namespace timely;
31using namespace unit_test;
32
33#undef LOG
34#define LOG(s) CLASS_EMERGENCY_LOG(program_wide_logger::get(), s)
35
37
38//#define DEBUG_TIME_STAMP
39
40//const int RUN_DURATION = 5 * MINUTE_ms;
41const int RUN_DURATION = 3 * SECOND_ms;
42 // how long the test will run.
43
44const int SLEEP_DURATION = 42;
45 // the period of sleep between checks on the time stamp.
46
47const int REPORT_INTERVAL = 500; // every half second.
48 // how often we show the current time stamp.
49
51
52class time_stamp_tester : virtual public unit_base, virtual public application_shell
53{
54public:
55 time_stamp_tester() : application_shell() {}
56
57 DEFINE_CLASS_NAME("time_stamp_tester");
58
59 int execute() {
60 time_stamp start;
61 log(a_sprintf("initial time stamp: %0.0f", start.value()));
62
63 time_stamp curr;
64 time_stamp get_out(RUN_DURATION);
65 time_stamp report_time(REPORT_INTERVAL);
66 int iterations = RUN_DURATION / SLEEP_DURATION;
67 while (iterations-- > 0) {
68 if (time_stamp() < curr)
69 deadly_error(class_name(), "compare test", "failure; now is less "
70 "than earlier!");
71
72//hmmm: how about some more verifications, like the sleep time we asked for is reflected (or nearly) in the time stamp difference?
73
75 curr = time_stamp();
76 if (time_stamp() >= report_time) {
77 log(a_sprintf("current time stamp: %0.0f", time_stamp().value()));
78 report_time.reset(REPORT_INTERVAL);
79 }
80 }
81
82 time_stamp end;
83 log(a_sprintf(" ending time stamp: %0.0f", end.value()));
84
85 critical_events::alert_message("time_stamp:: works for those functions tested.");
86 return 0;
87 }
88};
89
91
92HOOPLE_MAIN(time_stamp_tester, )
93
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.
virtual basis::outcome log(const basis::base_string &to_print, int filter=basis::ALWAYS_PRINT)
< returns the full name of the current application.
a_sprintf is a specialization of astring that provides printf style support.
Definition astring.h:440
virtual const char * class_name() const =0
Returns the bare name of this class as a constant character pointer.
static void alert_message(const char *info, const char *title="Alert Message")
shows the message in "info", with an optional "title" on the message.
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.
Definition time_stamp.h:38
void reset()
sets the stamp time back to now.
time_representation value() const
returns the time_stamp in terms of the lower level type.
Definition time_stamp.h:61
#define deadly_error(c, f, i)
#define DEFINE_CLASS_NAME(objname)
Defines the name of a class by providing a couple standard methods.
Definition enhance_cpp.h:42
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.
Definition hoople_main.h:61
Implements an application lock to ensure only one is running at once.
The guards collection helps in testing preconditions and reporting errors.
Definition array.h:30
const int SECOND_ms
Number of milliseconds in a second.
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.
Definition amorph.h:55
#include <time.h>
Useful support functions for unit testing, especially within hoople.
Definition unit_base.cpp:35
const int REPORT_INTERVAL
const int SLEEP_DURATION
const int RUN_DURATION