file name: tester.hpp, tester.cpp
classification: pure simulation
contents: class CTester, class CSleeper
derived from: both derived from class ACProcess
use: provides a test process for starting the simulation in
Linux using C++SIM
Note: all code of the tester class concerning the C++SIM simulation
*must* look like this. So if some other class is implemented to start a
simulation, the C++SIM code should be taken over without any changes.
global items used:
class CSleeper:
a simple process that can delay the simulation for g_delayTime
seconds per simulated second.
const INT23
PidSleeper: the process ID of the sleeper process (200).
const INT23
PidTester: the process ID of the tester process (100).
const double
WaitTime: the scheduling period of the tester process. It periodically
sleeps for waitTime seconds before checking if g_finished
is True.
global variables (tester.cpp):
EBool g_finished:
Is set to True by the Controller after the command DeleteSimulation
was received from the evaluation. It notifies the tester that the simulation
run is finished.
default: False
member functions of CTester:
CTester():
Sets the nodeID of the process to PidTester.
void Await
(): Calls Resume(), and then suspends the active thread calling
Thread::Self()->Suspend().
void Body
(): Creates an error handler of type CErrorTask,
a software controller (cont_sw.hpp) and, if
LINUX_SIM is defined, a sleeper
process of type CSleeper. The UNIX socket address used for communication
with the evaluation is /tmp/simUTC. The event queue of the controller
is called "CTRL", the message queue of the error handler is called "QERR".
Both the error handler and the controller are referenced if resource control
is turned on (macro NO_RESOURCE is not defined),
and they are scheduled to become active at once. After these initializations
the simulation scheduler is resumed (that starts the simulation).
As long as g_finished is not set to True, the tester process
holds for 200 simulation seconds and then checks g_finished again.
If g_finished is True, the tester deinstalls the error handler
and then cancels and terminates the error handler and controller processes.
The queue of the error handler is flushed to print all remaining error
messages. Then, the two simulation processes are unreferenced (resource
control is active) or deleted (no resource control). If LINUX_SIM
is defined, the sleeper process is treated like this as well. At last,
the scheduler itself is suspended and terminated, and the main thread is
resumed by calling Thread::mainResume().
void Exit
(): Calls Suspend() and then Thread_Type::Exit(),
the exit function of the type of threads that is used.
member functions of CSleeper:
CSleeper():
Sets the nodeID of the process to PidSleeper.
Body():
If LINUX_SIM is defined,
then the function periodically checks g_finished (if it is True,
then tm_wkafter() is called to delay the process for 500 seconds
to avoid blocking the shutdown of the simulation), uses the system call
usleep() to delay program execution for g_delayTime*g_sleeperPeriod
seconds, and then calls tm_wkafter() to let the simulation proceed
for another g_sleeperPeriod seconds of simulated
time. If g_delayTime is zero, then usleep()
is not called. Nevertheless, the process is executed with the period g_sleeperPeriod.
If DOS_SIM is defined, then
the function just calls tm_wkafter() to delay the process for
500 seconds, since the -d option is not available
in DOS.
If neither of the macros is defined, then an assert fails.