From ef535d9897878bedeade57e0f3b757e194736ed0 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Mon, 2 Sep 2013 00:26:04 +0200 Subject: [PATCH] provide a dummy job for unit testing --- src/backend/engine/job.cpp | 3 +- src/backend/engine/job.h | 32 +++-- src/proc/engine/calc-plan-continuation.cpp | 2 +- src/proc/engine/calc-plan-continuation.hpp | 2 +- src/proc/engine/job-ticket.cpp | 2 +- tests/core/backend/engine/dummy-job.hpp | 111 ++++++++++++++++++ .../engine/scheduler-interface-test.cpp | 86 ++++---------- 7 files changed, 158 insertions(+), 80 deletions(-) create mode 100644 tests/core/backend/engine/dummy-job.hpp diff --git a/src/backend/engine/job.cpp b/src/backend/engine/job.cpp index d109f039d..34776ae33 100644 --- a/src/backend/engine/job.cpp +++ b/src/backend/engine/job.cpp @@ -106,7 +106,8 @@ namespace engine { Job::isValid() const { return this->jobClosure - && myClosure(this).verify (getNominalTime()); + && myClosure(this).verify (getNominalTime(), + getInvocationInstanceID()); } diff --git a/src/backend/engine/job.h b/src/backend/engine/job.h index bec9318c3..fd46a4152 100644 --- a/src/backend/engine/job.h +++ b/src/backend/engine/job.h @@ -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; }; diff --git a/src/proc/engine/calc-plan-continuation.cpp b/src/proc/engine/calc-plan-continuation.cpp index 106727e59..49c5c5971 100644 --- a/src/proc/engine/calc-plan-continuation.cpp +++ b/src/proc/engine/calc-plan-continuation.cpp @@ -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; diff --git a/src/proc/engine/calc-plan-continuation.hpp b/src/proc/engine/calc-plan-continuation.hpp index 3cb3237e5..fa40a0927 100644 --- a/src/proc/engine/calc-plan-continuation.hpp +++ b/src/proc/engine/calc-plan-continuation.hpp @@ -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); diff --git a/src/proc/engine/job-ticket.cpp b/src/proc/engine/job-ticket.cpp index 1f0a4b365..b5d6f5afb 100644 --- a/src/proc/engine/job-ticket.cpp +++ b/src/proc/engine/job-ticket.cpp @@ -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; diff --git a/tests/core/backend/engine/dummy-job.hpp b/tests/core/backend/engine/dummy-job.hpp new file mode 100644 index 000000000..9ea60f531 --- /dev/null +++ b/tests/core/backend/engine/dummy-job.hpp @@ -0,0 +1,111 @@ +/* + DUMMY-JOB.hpp - diagnostic job for unit tests + + Copyright (C) Lumiera.org + 2013, Hermann Vosseler + + 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 +#include + + +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 diff --git a/tests/core/backend/engine/scheduler-interface-test.cpp b/tests/core/backend/engine/scheduler-interface-test.cpp index 0495da1c8..0057cc9e2 100644 --- a/tests/core/backend/engine/scheduler-interface-test.cpp +++ b/tests/core/backend/engine/scheduler-interface-test.cpp @@ -27,8 +27,7 @@ #include "backend/real-clock.hpp" #include "backend/engine/scheduler-frontend.hpp" #include "backend/engine/scheduler-diagnostics.hpp" - -#include +#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);