source: src/Fragmentation/Automation/unittests/FragmentQueueUnitTest.cpp@ d920b9

Action_Thermostats Add_AtomRandomPerturbation Add_FitFragmentPartialChargesAction Add_RotateAroundBondAction Add_SelectAtomByNameAction Added_ParseSaveFragmentResults AddingActions_SaveParseParticleParameters Adding_Graph_to_ChangeBondActions Adding_MD_integration_tests Adding_ParticleName_to_Atom Adding_StructOpt_integration_tests AtomFragments Automaking_mpqc_open AutomationFragmentation_failures Candidate_v1.5.4 Candidate_v1.6.0 Candidate_v1.6.1 ChangeBugEmailaddress ChangingTestPorts ChemicalSpaceEvaluator CombiningParticlePotentialParsing Combining_Subpackages Debian_Package_split Debian_package_split_molecuildergui_only Disabling_MemDebug Docu_Python_wait EmpiricalPotential_contain_HomologyGraph EmpiricalPotential_contain_HomologyGraph_documentation Enable_parallel_make_install Enhance_userguide Enhanced_StructuralOptimization Enhanced_StructuralOptimization_continued Example_ManyWaysToTranslateAtom Exclude_Hydrogens_annealWithBondGraph FitPartialCharges_GlobalError Fix_BoundInBox_CenterInBox_MoleculeActions Fix_ChargeSampling_PBC Fix_ChronosMutex Fix_FitPartialCharges Fix_FitPotential_needs_atomicnumbers Fix_ForceAnnealing Fix_IndependentFragmentGrids Fix_ParseParticles Fix_ParseParticles_split_forward_backward_Actions Fix_PopActions Fix_QtFragmentList_sorted_selection Fix_Restrictedkeyset_FragmentMolecule Fix_StatusMsg Fix_StepWorldTime_single_argument Fix_Verbose_Codepatterns Fix_fitting_potentials Fixes ForceAnnealing_goodresults ForceAnnealing_oldresults ForceAnnealing_tocheck ForceAnnealing_with_BondGraph ForceAnnealing_with_BondGraph_continued ForceAnnealing_with_BondGraph_continued_betteresults ForceAnnealing_with_BondGraph_contraction-expansion FragmentAction_writes_AtomFragments FragmentMolecule_checks_bonddegrees GeometryObjects Gui_Fixes Gui_displays_atomic_force_velocity ImplicitCharges IndependentFragmentGrids IndependentFragmentGrids_IndividualZeroInstances IndependentFragmentGrids_IntegrationTest IndependentFragmentGrids_Sole_NN_Calculation JobMarket_RobustOnKillsSegFaults JobMarket_StableWorkerPool JobMarket_unresolvable_hostname_fix MoreRobust_FragmentAutomation ODR_violation_mpqc_open PartialCharges_OrthogonalSummation PdbParser_setsAtomName PythonUI_with_named_parameters QtGui_reactivate_TimeChanged_changes Recreated_GuiChecks Rewrite_FitPartialCharges RotateToPrincipalAxisSystem_UndoRedo SaturateAtoms_findBestMatching SaturateAtoms_singleDegree StoppableMakroAction Subpackage_CodePatterns Subpackage_JobMarket Subpackage_LinearAlgebra Subpackage_levmar Subpackage_mpqc_open Subpackage_vmg Switchable_LogView ThirdParty_MPQC_rebuilt_buildsystem TrajectoryDependenant_MaxOrder TremoloParser_IncreasedPrecision TremoloParser_MultipleTimesteps TremoloParser_setsAtomName Ubuntu_1604_changes stable
Last change on this file since d920b9 was d920b9, checked in by Frederik Heber <heber@…>, 13 years ago

Abstracted FragmentJob and introduced SystemCommandJob which has its former functionality.

  • FragmentJob now has just virtual function Work(), not implemented.
  • former command and outputfile is taken over by SystemCommandJob.
  • a FragmentJob or derived class is default cstor'ed always with JobId::IllegalJob.
  • so far SystemCommandJob captures command's stdout and parses it back from file. We use mkstemps() for creating a random file and popen() to pipe stdout directly. For this we require boost::iostreams and ::filesystem.
  • SystemCommandJob has virtual method extractString() to be adaptable to the output of various system commands.
  • changes almost everywhere due to SystemCommandJob taking place of FragmentJob and FragmentJob::ptr and FragmentResult::ptr requirements.
  • added FragmentWorker::dummyInit() to enforce binding of the executable to all possible derived FragmentJob's.
  • added unit test for SystemCommandJob.
  • added FragmentJobStub that implements a no-brainer job for testing.
  • NOTE: boost::iostreams is incompatible with MemDebug due to placement new.
  • Property mode set to 100644
File size: 8.2 KB
RevLine 
[b5ebb5]1/*
2 * Project: MoleCuilder
3 * Description: creates and alters molecular systems
4 * Copyright (C) 2011 University of Bonn. All rights reserved.
5 * Please see the LICENSE file or "Copyright notice" in builder.cpp for details.
6 */
7
8/*
9 * FragmentQueueUnitTest.cpp
10 *
11 * Created on: Oct 23, 2011
12 * Author: heber
13 */
14
15// include config.h
16#ifdef HAVE_CONFIG_H
17#include <config.h>
18#endif
19
20#include <cppunit/CompilerOutputter.h>
21#include <cppunit/extensions/TestFactoryRegistry.h>
22#include <cppunit/ui/text/TestRunner.h>
23
24#include "FragmentQueueUnitTest.hpp"
25
[9875cc]26#include <vector>
27
[02f346]28#include "CodePatterns/Assert.hpp"
[9875cc]29#include "FragmentQueue.hpp"
30
[02f346]31
[b5ebb5]32#ifdef HAVE_TESTRUNNER
33#include "UnitTestMain.hpp"
34#endif /*HAVE_TESTRUNNER*/
35
36/********************************************** Test classes **************************************/
37
[d920b9]38#include "stubs/FragmentJobStub.hpp"
39
[b5ebb5]40// Registers the fixture into the 'registry'
41CPPUNIT_TEST_SUITE_REGISTRATION( FragmentQueueTest );
42
43
44void FragmentQueueTest::setUp()
45{
[02f346]46 // Throw assertions
47 ASSERT_DO(Assert::Throw);
48
[b5ebb5]49 queue = new FragmentQueue();
50}
51
52
53void FragmentQueueTest::tearDown()
54{
55 delete queue;
56}
57
58/** UnitTest for working JobQueue
59 */
[9875cc]60void FragmentQueueTest::JobTest()
[b5ebb5]61{
[d920b9]62 FragmentJob::ptr testJob(new FragmentJobStub(JobId::IllegalJob));
[02f346]63 /// check for illegal id
64#ifndef NDEBUG
65 std::cout << "The following assertion is intended and does not indicate a failure." << std::endl;
66 CPPUNIT_ASSERT_THROW( queue->pushJob(testJob), Assert::AssertionFailure );
67#endif
68 // set to valid id
[78ad7d]69 testJob->setId(1);
[02f346]70
[12d15a]71 CPPUNIT_ASSERT_EQUAL(false, queue->isJobPresent() );
72
[02f346]73#ifndef NDEBUG
74 CPPUNIT_ASSERT_NO_THROW( queue->pushJob(testJob) );
75#else
76 queue->pushJob(testJob);
77#endif
78
79 CPPUNIT_ASSERT_EQUAL((size_t)1, queue->jobs.size());
[12d15a]80 CPPUNIT_ASSERT_EQUAL(true, queue->isJobPresent() );
81 CPPUNIT_ASSERT_EQUAL((size_t)1, queue->results.size());
[9875cc]82 {
83 FragmentQueue::ResultMap::const_iterator iter = queue->results.find((JobId_t)1);
84 CPPUNIT_ASSERT( iter != queue->results.end() );
85 CPPUNIT_ASSERT( FragmentQueue::NoResult == iter->second );
86 }
[02f346]87
88 // push same id again
89#ifndef NDEBUG
90 std::cout << "The following assertion is intended and does not indicate a failure." << std::endl;
91 CPPUNIT_ASSERT_THROW( queue->pushJob(testJob), Assert::AssertionFailure );
92#endif
93
94 CPPUNIT_ASSERT_EQUAL((size_t)1, queue->jobs.size());
[12d15a]95 CPPUNIT_ASSERT_EQUAL((size_t)1, queue->results.size());
96
[78ad7d]97 FragmentJob::ptr poppedJob;
[12d15a]98#ifndef NDEBUG
99 CPPUNIT_ASSERT_NO_THROW( poppedJob = queue->popJob() );
100#else
101 poppedJob = queue->popJob();
102#endif
103 CPPUNIT_ASSERT( poppedJob == testJob );
104
105 CPPUNIT_ASSERT_EQUAL((size_t)0, queue->jobs.size());
106 CPPUNIT_ASSERT_EQUAL(false, queue->isJobPresent() );
107 CPPUNIT_ASSERT_EQUAL((size_t)1, queue->results.size());
[9875cc]108 {
109 FragmentQueue::ResultMap::const_iterator iter = queue->results.find((JobId_t)1);
110 CPPUNIT_ASSERT( iter != queue->results.end() );
111 CPPUNIT_ASSERT( FragmentQueue::NoResultQueued == iter->second );
112 }
[12d15a]113
114#ifndef NDEBUG
115 std::cout << "The following assertion is intended and does not indicate a failure." << std::endl;
116 CPPUNIT_ASSERT_THROW( queue->popJob(), Assert::AssertionFailure );
117#endif
[b5ebb5]118}
119
[9875cc]120/** UnitTest for adding multiple jobs at a time.
121 */
122void FragmentQueueTest::JobsTest()
123{
124 // prepare some jobs
[d920b9]125 FragmentJob::ptr testJob(new FragmentJobStub(JobId::IllegalJob));
[78ad7d]126 testJob->setId((JobId_t)1);
[d920b9]127 FragmentJob::ptr anothertestJob(new FragmentJobStub(JobId::IllegalJob));
[78ad7d]128 anothertestJob->setId((JobId_t)2);
[9875cc]129
130 // prepare a vector of them
[78ad7d]131 std::vector<FragmentJob::ptr> testjobs;
[9875cc]132 testjobs.push_back(testJob);
133 testjobs.push_back(anothertestJob);
134
135 // prepare another vector of them
[78ad7d]136 std::vector<FragmentJob::ptr> sametestjobs;
[9875cc]137 sametestjobs.push_back(testJob);
138 sametestjobs.push_back(anothertestJob);
139
140 // push the vector
141 CPPUNIT_ASSERT_EQUAL( (size_t)0, queue->jobs.size() );
142#ifndef NDEBUG
143 CPPUNIT_ASSERT_NO_THROW( queue->pushJobs(testjobs) );
144#else
145 queue->pushJobs(testjobs);
146#endif
147 CPPUNIT_ASSERT_EQUAL( (size_t)2, queue->jobs.size() );
148 CPPUNIT_ASSERT_EQUAL((size_t)2, queue->results.size());
149 {
150 FragmentQueue::ResultMap::const_iterator iter = queue->results.find((JobId_t)1);
151 CPPUNIT_ASSERT( iter != queue->results.end() );
152 CPPUNIT_ASSERT( FragmentQueue::NoResult == iter->second );
153 }
154 {
155 FragmentQueue::ResultMap::const_iterator iter = queue->results.find((JobId_t)2);
156 CPPUNIT_ASSERT( iter != queue->results.end() );
157 CPPUNIT_ASSERT( FragmentQueue::NoResult == iter->second );
158 }
159 // push again
160#ifndef NDEBUG
161 std::cout << "The following assertion is intended and does not indicate a failure." << std::endl;
162 CPPUNIT_ASSERT_THROW( queue->pushJobs(testjobs), Assert::AssertionFailure );
163#endif
164
165 CPPUNIT_ASSERT_EQUAL( (size_t)2, queue->jobs.size() );
166 CPPUNIT_ASSERT_EQUAL((size_t)2, queue->results.size());
167}
168
[b5ebb5]169/** UnitTest for working ResultMap
170 */
171void FragmentQueueTest::ResultsTest()
172{
[02f346]173 // prepare a job
[d920b9]174 FragmentJob::ptr testJob(new FragmentJobStub(JobId::IllegalJob));
[78ad7d]175 testJob->setId(1);
[12d15a]176#ifndef NDEBUG
177 CPPUNIT_ASSERT_NO_THROW( queue->pushJob(testJob) );
178#else
[02f346]179 queue->pushJob(testJob);
[12d15a]180#endif
181#ifndef NDEBUG
182 CPPUNIT_ASSERT_NO_THROW( queue->popJob() );
183#else
184 queue->popJob();
185#endif
186
[02f346]187
188 // prepare a result
[35f587]189 FragmentResult::ptr testResult( new FragmentResult(1) );
190 FragmentResult::ptr wrongIdResult( new FragmentResult(2) );
[02f346]191
[b0b64c]192 // check that none are present and we can't get result yet
[8ee5ac]193 CPPUNIT_ASSERT_EQUAL( (size_t)0, queue->getDoneJobs() );
[02f346]194 CPPUNIT_ASSERT( !queue->isResultPresent(1) );
195 CPPUNIT_ASSERT( !queue->isResultPresent(2) );
196#ifndef NDEBUG
197 std::cout << "The following assertion is intended and does not indicate a failure." << std::endl;
198 CPPUNIT_ASSERT_THROW( queue->getResult(1), Assert::AssertionFailure );
199#endif
200
[b0b64c]201 /// check for admonishing wrong id
[02f346]202#ifndef NDEBUG
203 std::cout << "The following assertion is intended and does not indicate a failure." << std::endl;
204 CPPUNIT_ASSERT_THROW( queue->pushResult(wrongIdResult), Assert::AssertionFailure );
205#endif
[b0b64c]206
207 // push correct result
[02f346]208#ifndef NDEBUG
209 CPPUNIT_ASSERT_NO_THROW( queue->pushResult(testResult) );
210#else
211 queue->pushResult(testResult);
212#endif
213
214 // check presence again
215 CPPUNIT_ASSERT( queue->isResultPresent(1) );
[8ee5ac]216 CPPUNIT_ASSERT_EQUAL( (size_t)1, queue->getDoneJobs() );
[02f346]217
[b0b64c]218 // obtain result again
[02f346]219#ifndef NDEBUG
220 CPPUNIT_ASSERT_NO_THROW( queue->getResult(1) );
221#else
222 queue->getResult(1);
223#endif
224
225 // check presence one more time
[8ee5ac]226 CPPUNIT_ASSERT_EQUAL( (size_t)0, queue->getDoneJobs() );
[02f346]227 CPPUNIT_ASSERT( !queue->isResultPresent(1) );
228 CPPUNIT_ASSERT( !queue->isResultPresent(2) );
229#ifndef NDEBUG
230 std::cout << "The following assertion is intended and does not indicate a failure." << std::endl;
231 CPPUNIT_ASSERT_THROW( queue->getResult(1), Assert::AssertionFailure );
232#endif
[b5ebb5]233}
[b9c486]234
235/** UnitTest for working ResultMap
236 */
237void FragmentQueueTest::AllResultsTest()
238{
239 // prepare a job
[d920b9]240 FragmentJob::ptr testJob( new FragmentJobStub(JobId::IllegalJob) );
241 testJob->setId((JobId_t)1);
242 FragmentJob::ptr anothertestJob( new FragmentJobStub(JobId::IllegalJob) );
243 anothertestJob->setId((JobId_t)2);
[b9c486]244
245#ifndef NDEBUG
246 CPPUNIT_ASSERT_NO_THROW( queue->pushJob(testJob) );
247 CPPUNIT_ASSERT_NO_THROW( queue->pushJob(anothertestJob) );
248#else
249 queue->pushJob(testJob);
250 queue->pushJob(anothertestJob);
251#endif
252
253 // check that no results are returned.
254 {
[35f587]255 const std::vector<FragmentResult::ptr> results = queue->getAllResults();
[b9c486]256 CPPUNIT_ASSERT_EQUAL( (size_t)0, results.size() );
257 }
258
259 // pop both as if some work was being done
260#ifndef NDEBUG
261 CPPUNIT_ASSERT_NO_THROW( queue->popJob() );
262 CPPUNIT_ASSERT_NO_THROW( queue->popJob() );
263#else
264 queue->popJob();
265 queue->popJob();
266#endif
267
268 // prepare a result
[35f587]269 FragmentResult::ptr testResult( new FragmentResult(1) );
270 FragmentResult::ptr anothertestResult( new FragmentResult(2) );
[b9c486]271
272 // push correct result
273#ifndef NDEBUG
274 CPPUNIT_ASSERT_NO_THROW( queue->pushResult(testResult) );
275 CPPUNIT_ASSERT_NO_THROW( queue->pushResult(anothertestResult) );
276#else
277 queue->pushResult(testResult);
278 queue->pushResult(anothertestResult);
279#endif
280
281 // check that two results are returned.
282 {
[35f587]283 const std::vector<FragmentResult::ptr> results = queue->getAllResults();
[b9c486]284 CPPUNIT_ASSERT_EQUAL( (size_t)2, results.size() );
285 }
286}
287
Note: See TracBrowser for help on using the repository browser.