From 09b6dc6652ccfbdfe5770b47ebe495844b2aecab Mon Sep 17 00:00:00 2001 From: Chris Koeritz Date: Thu, 28 Feb 2013 21:14:23 -0500 Subject: [PATCH] cleaned up stopwatch test and added it. --- doc/headers/fmc_header.java | 5 +- doc/headers/gnu_header.h | 6 +- doc/headers/shell_header.txt | 4 +- doc/headers/uva_header.java | 3 +- nucleus/library/tests_timely/makefile | 2 +- .../library/tests_timely/test_stopwatch.cpp | 89 +++++++++++++++++++ 6 files changed, 98 insertions(+), 11 deletions(-) create mode 100644 nucleus/library/tests_timely/test_stopwatch.cpp diff --git a/doc/headers/fmc_header.java b/doc/headers/fmc_header.java index bc60f6ad..fb76d4f7 100644 --- a/doc/headers/fmc_header.java +++ b/doc/headers/fmc_header.java @@ -4,8 +4,7 @@ * {extended information...} * @author Chris Koeritz * @copyright Copyright (c) 2012-$now By Feisty Meow Concerns, Ltd. - * @license This file is free software; you can modify/redistribute it under the terms of the GNU - * General Public License. [ http://www.gnu.org/licenses/gpl.html ] - * @contribute Feel free to send updates to: [ fred@feistymeow.org ] + * @license GNU General Public License -- http://www.gnu.org/licenses/gpl.html + * @contribute Feel free to send updates to: fred@feistymeow.org */ diff --git a/doc/headers/gnu_header.h b/doc/headers/gnu_header.h index 054630fa..5e74be08 100644 --- a/doc/headers/gnu_header.h +++ b/doc/headers/gnu_header.h @@ -1,8 +1,8 @@ -#ifndef {NAME}_CLASS -#define {NAME}_CLASS +#ifndef NAMEOF_CLASS +#define NAMEOF_CLASS ////////////// -// Name : {class name} +// Name : THISCLASSNAME // Author : Chris Koeritz // Rights : Copyright (c) 2012-$now By Author ////////////// diff --git a/doc/headers/shell_header.txt b/doc/headers/shell_header.txt index 1f2dd32e..15e2b440 100644 --- a/doc/headers/shell_header.txt +++ b/doc/headers/shell_header.txt @@ -2,9 +2,9 @@ #!/usr/bin/perl #!/usr/bin/python ############## -# Name : {script name} +# Name : NAMEOFSCRIPT # Author : Chris Koeritz -# Rights : Copyright (C) 2012-$now by Feisty Meow Concerns, Ltd. +# Rights : Copyright (C) 2013-$now by Feisty Meow Concerns, Ltd. ############## # This script is free software; you can modify/redistribute it under the terms # of the GNU General Public License. [ http://www.gnu.org/licenses/gpl.html ] diff --git a/doc/headers/uva_header.java b/doc/headers/uva_header.java index 55985ee9..c7481628 100644 --- a/doc/headers/uva_header.java +++ b/doc/headers/uva_header.java @@ -4,7 +4,6 @@ * {extended information...} * @author Chris Koeritz * @copyright Copyright (c) 2012-$now By University of Virginia - * @license This file is free software; you can modify and redistribute it under the terms of the - * Apache License v2.0: http://www.apache.org/licenses/LICENSE-2.0 + * @license Apache License v2.0: http://www.apache.org/licenses/LICENSE-2.0 */ diff --git a/nucleus/library/tests_timely/makefile b/nucleus/library/tests_timely/makefile index 3b91fe7b..a5e17ec0 100644 --- a/nucleus/library/tests_timely/makefile +++ b/nucleus/library/tests_timely/makefile @@ -2,7 +2,7 @@ include cpp/variables.def PROJECT = tests_timely TYPE = test -TARGETS = test_earth_time.exe +TARGETS = test_earth_time.exe test_stopwatch.exe DEFINITIONS += USE_HOOPLE_DLLS LOCAL_LIBS_USED = unit_test application processes loggers configuration mathematics nodes \ structures textual timely filesystem structures basis diff --git a/nucleus/library/tests_timely/test_stopwatch.cpp b/nucleus/library/tests_timely/test_stopwatch.cpp new file mode 100644 index 00000000..6352cba9 --- /dev/null +++ b/nucleus/library/tests_timely/test_stopwatch.cpp @@ -0,0 +1,89 @@ +////////////// +// Name : test_stopwatch +// Author : Chris Koeritz +// Rights : Copyright (c) 1991-$now By Author +////////////// +// This file is free software; you can modify/redistribute it under the terms +// of the GNU General Public License. [ http://www.gnu.org/licenses/gpl.html ] +// Feel free to send updates to: [ fred@gruntose.com ] +////////////// + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace basis; +using namespace application; +using namespace loggers; +using namespace mathematics; +using namespace structures; +using namespace timely; + +#define DEBUG_TIMER + +// ACCEPT: acceptable timer deviation from the total time to wait. +// NOTE: timer characteristics and the sleep characteristics for machines vary. +// it may be necessary to play with ACCEPT to get this program to accept the +// machine's particular characteristics. +//#define ACCEPT 0.01 +//#define WIDER_ACCEPT 0.05 +//#define WIDEST_ACCEPT 0.20 +#define ACCEPT 0.9 +#define WIDER_ACCEPT 0.95 +#define WIDEST_ACCEPT 1.20 + +#define LOG(s) EMERGENCY_LOG(program_wide_logger::get(), s) + +class test_stopwatch : public application_shell +{ +public: + test_stopwatch() : application_shell() {} + DEFINE_CLASS_NAME("test_stopwatch"); + virtual int execute(); +}; + +int test_stopwatch::execute() +{ + stopwatch fred_time; + chaos randomizer; + + int to_sleep = randomizer.inclusive(20, 100); + // needs longer ints for the last two checks... + fred_time.start(); + time_control::sleep_ms(to_sleep); + fred_time.halt(); +#ifdef DEBUG_TIMER + LOG(a_sprintf("sleep of %0.3f seconds took %d milliseconds\n", + float(to_sleep) / 1000.0, fred_time.milliseconds())); +#endif + if (absolute_value(to_sleep - fred_time.milliseconds()) + > ACCEPT * to_sleep) + deadly_error(class_name(), "first", "unacceptable timer deviation"); + fred_time.reset(); + + to_sleep = randomizer.inclusive(76, 420); + fred_time.start(); + time_control::sleep_ms(to_sleep); + fred_time.halt(); +#ifdef DEBUG_TIMER + LOG(a_sprintf("sleep of %0.3f seconds took %d milliseconds\n", + float(to_sleep) / 1000.0, fred_time.milliseconds())); +#endif + if (absolute_value(to_sleep - fred_time.milliseconds()) > ACCEPT * to_sleep) + deadly_error(class_name(), "second", "unacceptable timer deviation"); + fred_time.reset(); + + critical_events::alert_message("stopwatch:: works for those functions tested."); + return 0; +} + +HOOPLE_MAIN(test_stopwatch, ) + -- 2.34.1