provide a dummy job for unit testing

This commit is contained in:
Fischlurch 2013-09-02 00:26:04 +02:00
parent 7ba0ef92c8
commit ef535d9897
7 changed files with 158 additions and 80 deletions

View file

@ -106,7 +106,8 @@ namespace engine {
Job::isValid() const
{
return this->jobClosure
&& myClosure(this).verify (getNominalTime());
&& myClosure(this).verify (getNominalTime(),
getInvocationInstanceID());
}

View file

@ -55,17 +55,6 @@
#include "lib/time.h"
/** opaque ID attached to each individual job invocation.
* Used by the implementation of the Jobs (i.e. the JobClosure)
* for internal organisation; will be fed back on job activation.
*/
union InvocationInstanceID
{
int64_t frameNumber;
lumiera_uid luid;
};
enum JobState
{
@ -106,6 +95,23 @@ struct lumiera_jobClosure { /* placeholder */ };
typedef struct lumiera_jobClosure* LumieraJobClosure;
/** opaque ID attached to each individual job invocation.
* Used by the implementation of the Jobs (i.e. the JobClosure)
* for internal organisation; will be fed back on job activation.
*/
union InvocationInstanceID
{
int64_t frameNumber;
lumiera_uid luid;
struct {int a,b;}
metaInfo;
};
/**
* invocation parameter for the individual frame calculation job.
* Embedded into the job descriptor and passed to #lumiera_job_invoke when triggering
@ -206,8 +212,8 @@ namespace engine {
virtual void invokeJobOperation (JobParameter parameter) =0;
virtual void signalFailure (JobParameter,JobFailureReason) =0;
virtual JobKind getJobKind() const =0;
virtual bool verify (Time nominalJobTime) const =0;
virtual JobKind getJobKind() const =0;
virtual bool verify (Time, InvocationInstanceID) const =0;
virtual size_t hashOfInstance(InvocationInstanceID) const =0;
};

View file

@ -56,7 +56,7 @@ namespace engine {
bool
CalcPlanContinuation::verify (Time nominalJobTime) const
CalcPlanContinuation::verify (Time nominalTime, InvocationInstanceID invoKey) const
{
UNIMPLEMENTED ("verify the planning coordinates");
return false;

View file

@ -75,7 +75,7 @@ namespace engine {
return META_JOB;
}
bool verify (Time nominalJobTime) const;
bool verify (Time, InvocationInstanceID) const;
size_t hashOfInstance (InvocationInstanceID) const;
void invokeJobOperation (JobParameter);

View file

@ -63,7 +63,7 @@ using backend::engine::JobClosure;
}
bool
verify (Time nominalJobTime) const
verify (Time nominalTime, InvocationInstanceID invoKey) const
{
UNIMPLEMENTED ("access the underlying JobTicket and verify the given job time is within the relevant timeline segment");
return false;

View file

@ -0,0 +1,111 @@
/*
DUMMY-JOB.hpp - diagnostic job for unit tests
Copyright (C) Lumiera.org
2013, Hermann Vosseler <Ichthyostega@web.de>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of
the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef BACKEND_ENGINE_DUMMY_JOB_H
#define BACKEND_ENGINE_DUMMY_JOB_H
#include "backend/engine/job.h"
#include "lib/test/test-helper.hpp"
#include <cstdlib>
#include <boost/functional/hash.hpp>
namespace backend{
namespace engine {
namespace {
class DummyClosure
: public JobClosure
{
void
invokeJobOperation (JobParameter parameter)
{
UNIMPLEMENTED ("conjure a verifiable dummy job operation");
}
void
signalFailure (JobParameter,JobFailureReason)
{
NOTREACHED ("Job failure is not subject of this test");
}
JobKind
getJobKind() const
{
return META_JOB;
}
bool
verify (Time nominalJobTime, InvocationInstanceID invoKey) const
{
UNIMPLEMENTED ("what the hell do we need to mock for this operation????");
}
size_t
hashOfInstance(InvocationInstanceID invoKey) const
{
return boost::hash_value (invoKey.metaInfo.a);
}
};
/** actual instance of the test dummy job operation */
DummyClosure dummyClosure;
const int MAX_PARAM_A(1000);
const int MAX_PARAM_B(10);
}
class DummyJob
{
public:
static Job
build()
{
InvocationInstanceID invoKey;
invoKey.metaInfo.a = rand() % MAX_PARAM_A;
invoKey.metaInfo.b = rand() % MAX_PARAM_B;
Time nominalTime = lib::test::randTime();
return Job(dummyClosure, invoKey, nominalTime);
}
static Job
build (Time nominalTime, int additionalKey)
{
InvocationInstanceID invoKey;
invoKey.metaInfo.a = additionalKey;
invoKey.metaInfo.b = rand() % MAX_PARAM_B;
return Job(dummyClosure, invoKey, nominalTime);
}
};
}} // namespace backend::engine
#endif

View file

@ -27,8 +27,7 @@
#include "backend/real-clock.hpp"
#include "backend/engine/scheduler-frontend.hpp"
#include "backend/engine/scheduler-diagnostics.hpp"
#include <boost/functional/hash.hpp>
#include "backend/engine/dummy-job.hpp"
namespace backend {
@ -42,46 +41,7 @@ namespace test {
using lib::time::FSecs;
namespace { // test fixture: a dummy job operation...
class DummyClosure
: public JobClosure
{
void
invokeJobOperation (JobParameter parameter)
{
UNIMPLEMENTED ("conjure a verifiable dummy job operation");
}
void
signalFailure (JobParameter,JobFailureReason)
{
NOTREACHED ("Job failure is not subject of this test");
}
JobKind
getJobKind() const
{
return META_JOB;
}
bool
verify (Time nominalJobTime) const
{
UNIMPLEMENTED ("what the hell do we need to mock for this operation????");
}
size_t
hashOfInstance(InvocationInstanceID invoKey) const
{
return boost::hash_value (invoKey.frameNumber);
}
};
/** actual instance of the test dummy job operation */
DummyClosure dummyClosure;
namespace { // test fixture: scheduling a dummy job operation...
Time TEST_START_TIME (backend::RealClock::now());
@ -96,6 +56,9 @@ namespace test {
} //(End) test fixture
typedef SchedulerFrontend::JobTransaction JobTransaction;
@ -125,10 +88,7 @@ namespace test {
{
SchedulerDiagnostics monitor(scheduler);
InvocationInstanceID invoKey;
invoKey.frameNumber = 111;
Job job(dummyClosure, invoKey, Time::ZERO);
Job job = DummyJob::build();
Time deadline(TEST_START_TIME);
scheduler.startJobTransaction()
@ -146,25 +106,28 @@ namespace test {
{
SchedulerDiagnostics monitor(scheduler);
InvocationInstanceID invoKey;
invoKey.frameNumber = 111;
Job job(dummyClosure, invoKey, Time::ZERO);
JobTransaction tx = scheduler.startJobTransaction();
tx.addFreewheeling(job);
tx.addBackground (job);
Job job1 = DummyJob::build();
Job job2 = DummyJob::build();
CHECK (!monitor.is_scheduled_timebound (job));
CHECK (!monitor.is_scheduled_background (job));
CHECK (!monitor.is_scheduled_freewheeling (job));
tx.addFreewheeling(job1);
tx.addBackground (job2);
CHECK (!monitor.is_scheduled_timebound (job1));
CHECK (!monitor.is_scheduled_timebound (job2));
CHECK (!monitor.is_scheduled_background (job1));
CHECK (!monitor.is_scheduled_background (job2));
CHECK (!monitor.is_scheduled_freewheeling (job1));
CHECK (!monitor.is_scheduled_freewheeling (job2));
tx.commit();
CHECK (!monitor.is_scheduled_timebound (job));
CHECK ( monitor.is_scheduled_background (job));
CHECK ( monitor.is_scheduled_freewheeling (job));
CHECK (!monitor.is_scheduled_timebound (job1));
CHECK (!monitor.is_scheduled_timebound (job2));
CHECK ( monitor.is_scheduled_background (job1));
CHECK ( monitor.is_scheduled_freewheeling (job2));
}
@ -209,13 +172,10 @@ namespace test {
specifyJobs (JobTransaction& currentTx, uint dummyLevel)
{
uint frameNr = dummyLevel;
InvocationInstanceID invoKey;
invoKey.frameNumber = frameNr;
Time nominalTime(dummyFrameStart(frameNr));
Time deadline(TEST_START_TIME + nominalTime);
Job job(dummyClosure, invoKey, nominalTime);
Job job = DummyJob::build(nominalTime, frameNr);
currentTx.addJob (deadline, job);