DummyComponent.cc Source File

Back to the index.

DummyComponent.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2007-2010 Anders Gavare. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  * 1. Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * 3. The name of the author may not be used to endorse or promote products
13  * derived from this software without specific prior written permission.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25  * SUCH DAMAGE.
26  */
27 
29 #include "Checksum.h"
30 #include "ComponentFactory.h"
31 
32 
34  : Component(className, className)
35 {
36  // The dummy component should have no additional state.
37 }
38 
39 
41 {
42  return new DummyComponent();
43 }
44 
45 
46 string DummyComponent::GetAttribute(const string& attributeName)
47 {
48  if (attributeName == "stable")
49  return "yes";
50 
51  if (attributeName == "description")
52  return "A dummy component, which does nothing.";
53 
54  return Component::GetAttribute(attributeName);
55 }
56 
57 
58 /*****************************************************************************/
59 
60 
61 #ifdef WITHUNITTESTS
62 
63 #include "GXemul.h"
64 
65 static void Test_DummyComponent_CreateComponent()
66 {
67  refcount_ptr<Component> component;
68 
69  component = ComponentFactory::CreateComponent("dummy");
70  UnitTest::Assert("creating a dummy component should be possible",
71  component.IsNULL() == false);
72 
73  UnitTest::Assert("the name should be 'dummy'",
74  component->GetClassName() == "dummy");
75 }
76 
77 static void Test_DummyComponent_GetSetParent()
78 {
81 
82  UnitTest::Assert("parent should initially be NULL",
83  dummyA->GetParent() == NULL);
84 
85  dummyA->SetParent(dummyB);
86 
87  UnitTest::Assert("parent should be dummyB",
88  dummyA->GetParent() == dummyB);
89 
90  dummyA->SetParent(NULL);
91 
92  UnitTest::Assert("parent should now be NULL",
93  dummyA->GetParent() == NULL);
94 }
95 
96 static void Test_DummyComponent_AddChild_Sets_Parent()
97 {
99  refcount_ptr<Component> dummyChildA = new DummyComponent;
100 
101  UnitTest::Assert("child A's parent should initially be NULL",
102  dummyChildA->GetParent() == NULL);
103 
104  dummy->AddChild(dummyChildA);
105 
106  UnitTest::Assert("child A's parent should now be dummy",
107  dummyChildA->GetParent() == dummy);
108 }
109 
110 static void Test_DummyComponent_AddChildren_Count()
111 {
113  refcount_ptr<Component> dummyChildA = new DummyComponent;
114  refcount_ptr<Component> dummyChildB = new DummyComponent;
115  refcount_ptr<Component> dummyChildC = new DummyComponent;
116 
117  UnitTest::Assert("there should initially be no child components",
118  dummy->GetChildren().size() == 0);
119 
120  dummy->AddChild(dummyChildA);
121  dummy->AddChild(dummyChildB);
122  dummy->AddChild(dummyChildC);
123 
124  UnitTest::Assert("there should be 3 child components",
125  dummy->GetChildren().size() == 3);
126 }
127 
128 static void Test_DummyComponent_Add_Tree_Of_Children()
129 {
131  refcount_ptr<Component> dummyChildA = new DummyComponent;
132  refcount_ptr<Component> dummyChildB = new DummyComponent;
133  refcount_ptr<Component> dummyChildC = new DummyComponent;
134 
135  dummyChildA->AddChild(dummyChildB);
136  dummyChildA->AddChild(dummyChildC);
137  dummy->AddChild(dummyChildA);
138 
139  UnitTest::Assert("there should be 1 child component",
140  dummy->GetChildren().size() == 1);
141  UnitTest::Assert("there should be 2 child components in dummyChildA",
142  dummyChildA->GetChildren().size() == 2);
143 }
144 
145 static void Test_DummyComponent_RemoveChild()
146 {
148  refcount_ptr<Component> dummyChildA = new DummyComponent;
149  refcount_ptr<Component> dummyChildB = new DummyComponent;
150  refcount_ptr<Component> dummyChildC = new DummyComponent;
151 
152  dummyChildA->AddChild(dummyChildB);
153  dummyChildA->AddChild(dummyChildC);
154  dummy->AddChild(dummyChildA);
155 
156  UnitTest::Assert("there should be 1 child component",
157  dummy->GetChildren().size() == 1);
158  UnitTest::Assert("child A's parent should be dummy",
159  dummyChildA->GetParent() == dummy);
160  UnitTest::Assert("there should be 2 child components in dummyChildA",
161  dummyChildA->GetChildren().size() == 2);
162 
163  dummy->RemoveChild(dummyChildA);
164 
165  UnitTest::Assert("there should now be 0 child components",
166  dummy->GetChildren().size() == 0);
167 
169  "there should still be 2 child components in dummyChildA",
170  dummyChildA->GetChildren().size() == 2);
171  UnitTest::Assert("child A should have no parent",
172  dummyChildA->GetParent() == NULL);
173 }
174 
175 static void Test_DummyComponent_AddChild_UniqueName()
176 {
178  refcount_ptr<Component> dummyChildA = new DummyComponent;
179  refcount_ptr<Component> dummyChildB = new DummyComponent;
180  refcount_ptr<Component> dummyChildC = new DummyComponent;
181 
182  UnitTest::Assert("dummyChildA should have no initial name",
183  dummyChildA->GetVariable("name")->ToString(), "");
184 
185  dummy->AddChild(dummyChildA);
186 
187  const StateVariable* name = dummyChildA->GetVariable("name");
188  UnitTest::Assert("dummyChildA's name mismatch",
189  name->ToString(), "dummy0");
190 
191  dummy->AddChild(dummyChildB);
192 
193  name = dummyChildA->GetVariable("name");
194  UnitTest::Assert("dummyChildA should still have a name",
195  name != NULL);
196  UnitTest::Assert("dummyChildA's name changed unexpectedly?",
197  name->ToString(), "dummy0");
198 
199  name = dummyChildB->GetVariable("name");
200  UnitTest::Assert("dummyChildB should have a name now",
201  name != NULL);
202  UnitTest::Assert("dummyChildB's name mismatch",
203  name->ToString(), "dummy1");
204 
205  dummy->AddChild(dummyChildC);
206 
207  name = dummyChildC->GetVariable("name");
208  UnitTest::Assert("dummyChildC should have a name now",
209  name != NULL);
210  UnitTest::Assert("dummyChildC's name mismatch",
211  name->ToString(), "dummy2");
212 
213  dummy->RemoveChild(dummyChildA);
214 
215  name = dummyChildB->GetVariable("name");
216  UnitTest::Assert("dummyChildB should still have a name, after"
217  " removing child A",
218  name != NULL);
219  UnitTest::Assert("dummyChildB's should not have changed",
220  name->ToString(), "dummy1");
221 }
222 
223 static void Test_DummyComponent_GeneratePath()
224 {
228 
229  UnitTest::Assert("generated path with no name",
230  dummyA->GeneratePath(), "(dummy)");
231 
232  dummyB->AddChild(dummyA);
233 
234  UnitTest::Assert("generated path with default name fallback",
235  dummyA->GeneratePath(), "(dummy).dummy0");
236 
237  dummyC->AddChild(dummyB);
238 
239  UnitTest::Assert("generated path with two parent levels",
240  dummyA->GeneratePath(), "(dummy).dummy0.dummy0");
241 
242  dummyC->RemoveChild(dummyB);
243 
244  UnitTest::Assert("generated path with one parent level again",
245  dummyA->GeneratePath(), "dummy0.dummy0");
246 }
247 
248 static void Test_DummyComponent_GenerateShortestPossiblePath()
249 {
253 
254  dummyA->SetVariableValue("name", "\"machine0\"");
255  dummyB->SetVariableValue("name", "\"mainbus0\"");
256  dummyC->SetVariableValue("name", "\"ram0\"");
257  dummyA->AddChild(dummyB);
258  dummyB->AddChild(dummyC);
259 
260  UnitTest::Assert("shortest path first",
261  dummyC->GenerateShortestPossiblePath(), "ram0");
262 
265  dummyB2->SetVariableValue("name", "\"mainbus1\"");
266  dummyC2->SetVariableValue("name", "\"ram0\"");
267  dummyA->AddChild(dummyB2);
268  dummyB2->AddChild(dummyC2);
269 
270  UnitTest::Assert("shortest path C",
271  dummyC->GenerateShortestPossiblePath(), "mainbus0.ram0");
272  UnitTest::Assert("shortest path C2",
273  dummyC2->GenerateShortestPossiblePath(), "mainbus1.ram0");
274 }
275 
276 static void Test_DummyComponent_LookupPath()
277 {
279 
280  dummyA->SetVariableValue("name", "\"hello\"");
281 
282  refcount_ptr<Component> component1 = dummyA->LookupPath("nonsense");
283  UnitTest::Assert("nonsense lookup should fail",
284  component1.IsNULL() == true);
285 
286  refcount_ptr<Component> component2 = dummyA->LookupPath("hello");
287  UnitTest::Assert("lookup should have found the component itself",
288  component2 == dummyA);
289 
291  refcount_ptr<Component> childchild = new DummyComponent;
292  child->SetVariableValue("name", "\"x\"");
293  childchild->SetVariableValue("name", "\"y\"");
294  dummyA->AddChild(child);
295  child->AddChild(childchild);
296 
297  refcount_ptr<Component> component3 = dummyA->LookupPath("hello");
298  UnitTest::Assert("lookup should still succeed, when dummyA has"
299  " children",
300  component3 == dummyA);
301 
302  refcount_ptr<Component> component4 = dummyA->LookupPath("hello.z");
303  UnitTest::Assert("lookup of nonsense child of dummyA should fail",
304  component4.IsNULL() == true);
305 
306  refcount_ptr<Component> component5 = dummyA->LookupPath("hello.x");
307  UnitTest::Assert("lookup of child of dummyA should succeed",
308  component5 == child);
309 
310  refcount_ptr<Component> component6 = dummyA->LookupPath("hello.x.y");
311  UnitTest::Assert("lookup of grandchild of dummyA should succeed",
312  component6 == childchild);
313 }
314 
315 static void Test_DummyComponent_FindPathByPartialMatch()
316 {
322  refcount_ptr<Component> m0isabus0 = new DummyComponent;
323  refcount_ptr<Component> m1pcibus0 = new DummyComponent;
324  refcount_ptr<Component> m1pcibus1 = new DummyComponent;
325  refcount_ptr<Component> m2pcibus0 = new DummyComponent;
326  refcount_ptr<Component> m3otherpci = new DummyComponent;
327 
328  root->GetVariable("name")->SetValue("\"root\"");
329  machine0->GetVariable("name")->SetValue("\"machine0\"");
330  machine1->GetVariable("name")->SetValue("\"machine1\"");
331  machine2->GetVariable("name")->SetValue("\"machine2\"");
332  machine3->GetVariable("name")->SetValue("\"machine3\"");
333  m0isabus0->GetVariable("name")->SetValue("\"isabus0\"");
334  m1pcibus0->GetVariable("name")->SetValue("\"pcibus0\"");
335  m1pcibus1->GetVariable("name")->SetValue("\"pcibus1\"");
336  m2pcibus0->GetVariable("name")->SetValue("\"pcibus0\"");
337  m3otherpci->GetVariable("name")->SetValue("\"otherpci\"");
338 
339  root->AddChild(machine0);
340  root->AddChild(machine1);
341  root->AddChild(machine2);
342  root->AddChild(machine3);
343 
344  machine0->AddChild(m0isabus0);
345  machine1->AddChild(m1pcibus0);
346  machine1->AddChild(m1pcibus1);
347  machine2->AddChild(m2pcibus0);
348  machine3->AddChild(m3otherpci);
349 
350  vector<string> matches;
351 
352  matches = root->FindPathByPartialMatch("nonsense");
353  UnitTest::Assert("there should be no nonsense matches",
354  matches.size(), 0);
355 
356  matches = root->FindPathByPartialMatch("");
357  UnitTest::Assert("empty string should return all components",
358  matches.size(), 10);
359 
360  matches = root->FindPathByPartialMatch("pci");
361  UnitTest::Assert("pci matches mismatch",
362  matches.size(), 3);
363  UnitTest::Assert("pci match 0 mismatch",
364  matches[0], "root.machine1.pcibus0");
365  UnitTest::Assert("pci match 1 mismatch",
366  matches[1], "root.machine1.pcibus1");
367  UnitTest::Assert("pci match 2 mismatch",
368  matches[2], "root.machine2.pcibus0");
369 
370  matches = root->FindPathByPartialMatch("machine1");
371  UnitTest::Assert("machine1 match mismatch",
372  matches.size(), 1);
373  UnitTest::Assert("machine1 match 0 mismatch",
374  matches[0], "root.machine1");
375 
376  matches = root->FindPathByPartialMatch("machine2.pcibus");
377  UnitTest::Assert("machine2.pcibus match mismatch",
378  matches.size(), 1);
379  UnitTest::Assert("machine2.pcibus match 0 mismatch",
380  matches[0], "root.machine2.pcibus0");
381 
382  matches = root->FindPathByPartialMatch("machine.pcibus");
383  UnitTest::Assert("machine.pcibus should have no matches",
384  matches.size(), 0);
385 }
386 
387 static void Test_DummyComponent_GetUnknownVariable()
388 {
390 
391  UnitTest::Assert("variable variablename should not be set",
392  dummy->GetVariable("variablename") == NULL);
393 }
394 
395 static void Test_DummyComponent_NonexistantMethodNotReexecutable()
396 {
398 
399  UnitTest::Assert("by default, methods should NOT be re-executable"
400  " without args",
401  dummy->MethodMayBeReexecutedWithoutArgs("nonexistant") == false);
402 }
403 
404 static void Test_DummyComponent_Clone_Basic()
405 {
407  refcount_ptr<Component> dummyChildA = new DummyComponent;
408  refcount_ptr<Component> dummyChildA1 = new DummyComponent;
409  refcount_ptr<Component> dummyChildA2 = new DummyComponent;
410 
411  dummyChildA->AddChild(dummyChildA1);
412  dummyChildA->AddChild(dummyChildA2);
413  dummy->AddChild(dummyChildA);
414 
415  Checksum originalChecksum;
416  dummy->AddChecksum(originalChecksum);
417 
418  refcount_ptr<Component> clone = dummy->Clone();
419 
420  Checksum cloneChecksum;
421  clone->AddChecksum(cloneChecksum);
422 
423  UnitTest::Assert("clone should have same checksum",
424  originalChecksum == cloneChecksum);
425 
426  dummy->SetVariableValue("name", "\"modified\"");
427 
428  Checksum originalChecksumAfterModifyingOriginal;
429  dummy->AddChecksum(originalChecksumAfterModifyingOriginal);
430  Checksum cloneChecksumAfterModifyingOriginal;
431  clone->AddChecksum(cloneChecksumAfterModifyingOriginal);
432 
433  UnitTest::Assert("original should have changed checksum",
434  originalChecksum != originalChecksumAfterModifyingOriginal);
435  UnitTest::Assert("clone should have same checksum",
436  cloneChecksum == cloneChecksumAfterModifyingOriginal);
437 
438  clone->SetVariableValue("name", "\"modified\"");
439 
440  Checksum originalChecksumAfterModifyingClone;
441  dummy->AddChecksum(originalChecksumAfterModifyingClone);
442  Checksum cloneChecksumAfterModifyingClone;
443  clone->AddChecksum(cloneChecksumAfterModifyingClone);
444 
445  UnitTest::Assert("original should have same checksum, after the "
446  "clone has been modified",
447  originalChecksumAfterModifyingClone ==
448  originalChecksumAfterModifyingOriginal);
449  UnitTest::Assert("modified clone should have same checksum as "
450  "modified original",
451  cloneChecksumAfterModifyingClone ==
452  originalChecksumAfterModifyingOriginal);
453 }
454 
455 class DummyComponentWithAllVariableTypes
456  : public DummyComponent
457 {
458 public:
459  DummyComponentWithAllVariableTypes()
460  : DummyComponent("dummy2")
461  {
462  AddVariable("m_string", &m_string);
463  AddVariable("m_uint8", &m_uint8);
464  AddVariable("m_uint16", &m_uint16);
465  AddVariable("m_uint32", &m_uint32);
466  AddVariable("m_uint64", &m_uint64);
467  AddVariable("m_sint8", &m_sint8);
468  AddVariable("m_sint16", &m_sint16);
469  AddVariable("m_sint32", &m_sint32);
470  AddVariable("m_sint64", &m_sint64);
471  // TODO: Custom
472  // TODO: Bool
473 
474  ResetState();
475  }
476 
477  virtual void ResetState()
478  {
480 
481  m_string = "some value";
482  m_uint8 = 123;
483  m_uint16 = 0xf9a2;
484  m_uint32 = 0x98f8aa01;
485  m_uint64 = ((uint64_t)0xf8192929 << 32) | 0x30300a0a;
486  m_sint8 = -123;
487  m_sint16 = -400;
488  m_sint32 = -10000;
489  m_sint64 = -42;
490  }
491 
493  {
494  return new DummyComponentWithAllVariableTypes();
495  }
496 
497 private:
498  string m_string;
499  uint8_t m_uint8;
500  uint16_t m_uint16;
501  uint32_t m_uint32;
502  uint64_t m_uint64;
503  int8_t m_sint8;
504  int16_t m_sint16;
505  int32_t m_sint32;
506  int64_t m_sint64;
507 };
508 
509 static void Test_DummyComponent_Clone_AllVariableTypes()
510 {
511  refcount_ptr<Component> dummy = new DummyComponentWithAllVariableTypes;
512  refcount_ptr<Component> dA = new DummyComponentWithAllVariableTypes;
513  refcount_ptr<Component> dA1 = new DummyComponentWithAllVariableTypes;
514  refcount_ptr<Component> dA2 = new DummyComponentWithAllVariableTypes;
515 
516  dA->AddChild(dA1);
517  dA->AddChild(dA2);
518  dummy->AddChild(dA);
519 
520  Checksum originalChecksum;
521  dummy->AddChecksum(originalChecksum);
522 
523  refcount_ptr<Component> clone = dummy->Clone();
524 
525  Checksum cloneChecksum;
526  clone->AddChecksum(cloneChecksum);
527 
528  UnitTest::Assert("clone should have same checksum",
529  originalChecksum == cloneChecksum);
530 
531  dummy->SetVariableValue("name", "\"modified\"");
532 
533  Checksum originalChecksumAfterModifyingOriginal;
534  dummy->AddChecksum(originalChecksumAfterModifyingOriginal);
535  Checksum cloneChecksumAfterModifyingOriginal;
536  clone->AddChecksum(cloneChecksumAfterModifyingOriginal);
537 
538  UnitTest::Assert("original should have changed checksum",
539  originalChecksum != originalChecksumAfterModifyingOriginal);
540  UnitTest::Assert("clone should have same checksum",
541  cloneChecksum == cloneChecksumAfterModifyingOriginal);
542 
543  clone->SetVariableValue("name", "\"modified\"");
544 
545  Checksum originalChecksumAfterModifyingClone;
546  dummy->AddChecksum(originalChecksumAfterModifyingClone);
547  Checksum cloneChecksumAfterModifyingClone;
548  clone->AddChecksum(cloneChecksumAfterModifyingClone);
549 
550  UnitTest::Assert("original should have same checksum, after the "
551  "clone has been modified",
552  originalChecksumAfterModifyingClone ==
553  originalChecksumAfterModifyingOriginal);
554  UnitTest::Assert("modified clone should have same checksum as "
555  "modified original",
556  cloneChecksumAfterModifyingClone ==
557  originalChecksumAfterModifyingOriginal);
558 }
559 
560 static void Test_DummyComponent_SerializeDeserialize()
561 {
563  refcount_ptr<Component> dummyChildA = new DummyComponent;
564  refcount_ptr<Component> dummyChildA1 = new DummyComponent;
565  refcount_ptr<Component> dummyChildA2 = new DummyComponent;
566 
567  dummyChildA->AddChild(dummyChildA1);
568  dummyChildA->AddChild(dummyChildA2);
569  dummy->AddChild(dummyChildA);
570 
571  UnitTest::Assert("serialize/deserialize consistency failure",
572  dummy->CheckConsistency() == true);
573 }
574 
575 class DummyComponentWithCounter
576  : public DummyComponent
577 {
578 public:
579  DummyComponentWithCounter(ostream* os = NULL, char c = 'X')
580  : DummyComponent("testcounter")
581  , m_frequency(1e6)
582  , m_os(os)
583  , m_c(c)
584  {
585  ResetState();
586  AddVariable("frequency", &m_frequency);
587  AddVariable("counter", &m_counter);
588  }
589 
590  virtual void ResetState()
591  {
593  m_counter = 42;
594  }
595 
597  {
598  return new DummyComponentWithCounter();
599  }
600 
601  virtual int Execute(GXemul* gxemul, int nrOfCycles)
602  {
603  // Increase counter one per cycle.
604  m_counter += nrOfCycles;
605 
606  if (m_os != NULL) {
607  for (int i=0; i<nrOfCycles; ++i)
608  (*m_os) << m_c;
609  }
610 
611  return nrOfCycles;
612  }
613 
614 private:
615  double m_frequency;
616  uint64_t m_counter;
617  ostream* m_os;
618  char m_c;
619 };
620 
621 static void Test_DummyComponent_Execute_SingleStep()
622 {
623  GXemul gxemul;
624  gxemul.GetCommandInterpreter().RunCommand("add testcounter");
625 
626  UnitTest::Assert("the testcounter should have been added",
627  gxemul.GetRootComponent()->GetChildren().size(), 1);
628 
629  refcount_ptr<Component> counter = gxemul.GetRootComponent()->GetChildren()[0];
630 
631  UnitTest::Assert("the component should be the counter",
632  counter->GetVariable("name")->ToString(), "testcounter0");
633 
634  // Step 0:
635  UnitTest::Assert("the step should initially be 0",
636  gxemul.GetStep(), 0);
637  UnitTest::Assert("the counter should initially be 42",
638  counter->GetVariable("counter")->ToInteger(), 42);
639 
641  gxemul.Execute();
642 
643  // Step 1:
644  UnitTest::Assert("runstate wasn't reset after step 0?",
645  gxemul.GetRunState() == GXemul::Paused);
646  UnitTest::Assert("the step should now be 1", gxemul.GetStep(), 1);
647  UnitTest::Assert("the counter should now be 43",
648  counter->GetVariable("counter")->ToInteger(), 43);
649 
651  gxemul.Execute();
652 
653  // Step 2:
654  UnitTest::Assert("runstate wasn't reset after step 1?",
655  gxemul.GetRunState() == GXemul::Paused);
656  UnitTest::Assert("the step should now be 2", gxemul.GetStep(), 2);
657  UnitTest::Assert("the counter should now be 44",
658  counter->GetVariable("counter")->ToInteger(), 44);
659 }
660 
661 static void Test_DummyComponent_Execute_MultiSingleStep()
662 {
663  GXemul gxemul;
664  gxemul.GetCommandInterpreter().RunCommand("add testcounter");
665 
666  UnitTest::Assert("the testcounter should have been added",
667  gxemul.GetRootComponent()->GetChildren().size(), 1);
668 
669  refcount_ptr<Component> counter = gxemul.GetRootComponent()->GetChildren()[0];
670 
671  UnitTest::Assert("the component should be the counter",
672  counter->GetVariable("name")->ToString(), "testcounter0");
673 
674  const int nrOfStepsToRun = 23;
675  gxemul.SetNrOfSingleStepsInARow(nrOfStepsToRun);
676 
678 
679  // Note: This should execute all nrOfStepsToRun steps, unless there
680  // was some fatal abort condition.
681  gxemul.Execute();
682 
683  // Step n:
684  UnitTest::Assert("runstate wasn't reset?",
685  gxemul.GetRunState() == GXemul::Paused);
686  UnitTest::Assert("the step should now be n", gxemul.GetStep(), nrOfStepsToRun);
687  UnitTest::Assert("the counter should now be 42+nrOfStepsToRun",
688  counter->GetVariable("counter")->ToInteger(), 42+nrOfStepsToRun);
689 
691  gxemul.Execute();
692 
693  // Step n+1:
694  UnitTest::Assert("runstate wasn't reset after step 1?",
695  gxemul.GetRunState() == GXemul::Paused);
696  UnitTest::Assert("the step should now be n+1", gxemul.GetStep(), nrOfStepsToRun+1);
697  UnitTest::Assert("the counter should now be 43+nrOfStepsToRun",
698  counter->GetVariable("counter")->ToInteger(), 43+nrOfStepsToRun);
699 }
700 
701 static void Test_DummyComponent_Execute_TwoComponentsSameSpeed()
702 {
703  GXemul gxemul;
704  gxemul.GetCommandInterpreter().RunCommand("add testcounter");
705  gxemul.GetCommandInterpreter().RunCommand("add testcounter");
706 
707  UnitTest::Assert("the testcounters should have been added",
708  gxemul.GetRootComponent()->GetChildren().size(), 2);
709 
710  refcount_ptr<Component> counterA = gxemul.GetRootComponent()->GetChildren()[0];
711  refcount_ptr<Component> counterB = gxemul.GetRootComponent()->GetChildren()[1];
712 
713  UnitTest::Assert("name A mismatch",
714  counterA->GetVariable("name")->ToString(), "testcounter0");
715  UnitTest::Assert("name B mismatch",
716  counterB->GetVariable("name")->ToString(), "testcounter1");
717 
718  counterB->SetVariableValue("counter", "10042");
719 
720  // Step 0:
721  UnitTest::Assert("the step should initially be 0",
722  gxemul.GetStep(), 0);
723  UnitTest::Assert("counterA should initially be 42",
724  counterA->GetVariable("counter")->ToInteger(), 42);
725  UnitTest::Assert("counterB should initially be 10042",
726  counterB->GetVariable("counter")->ToInteger(), 10042);
727 
729  gxemul.Execute();
730 
731  // Step 1:
732  UnitTest::Assert("runstate wasn't reset after step 0?",
733  gxemul.GetRunState() == GXemul::Paused);
734  UnitTest::Assert("the step should now be 1", gxemul.GetStep(), 1);
735  UnitTest::Assert("counter A should now be 43",
736  counterA->GetVariable("counter")->ToInteger(), 43);
737  UnitTest::Assert("counter B should now be 10043",
738  counterB->GetVariable("counter")->ToInteger(), 10043);
739 
741  gxemul.Execute();
742 
743  // Step 2:
744  UnitTest::Assert("runstate wasn't reset after step 1?",
745  gxemul.GetRunState() == GXemul::Paused);
746  UnitTest::Assert("the step should now be 2", gxemul.GetStep(), 2);
747  UnitTest::Assert("counter A should now be 44",
748  counterA->GetVariable("counter")->ToInteger(), 44);
749  UnitTest::Assert("counter B should now be 10044",
750  counterB->GetVariable("counter")->ToInteger(), 10044);
751 }
752 
753 static void Test_DummyComponent_Execute_TwoComponentsDifferentSpeed()
754 {
755  GXemul gxemul;
756  stringstream os;
757  gxemul.GetRootComponent()->AddChild(new DummyComponentWithCounter(&os, 'A'));
758  gxemul.GetRootComponent()->AddChild(new DummyComponentWithCounter(&os, 'B'));
759 
760  UnitTest::Assert("the testcounters should have been added",
761  gxemul.GetRootComponent()->GetChildren().size(), 2);
762 
763  refcount_ptr<Component> counterA = gxemul.GetRootComponent()->GetChildren()[0];
764  refcount_ptr<Component> counterB = gxemul.GetRootComponent()->GetChildren()[1];
765 
766  UnitTest::Assert("name A mismatch",
767  counterA->GetVariable("name")->ToString(), "testcounter0");
768  UnitTest::Assert("name B mismatch",
769  counterB->GetVariable("name")->ToString(), "testcounter1");
770 
771  // Counter B should run twice as fast:
772  counterA->SetVariableValue("frequency", "100000");
773  counterB->SetVariableValue("frequency", "200000");
774 
775  counterB->SetVariableValue("counter", "10042");
776 
777  // Step 0:
778  UnitTest::Assert("the step should initially be 0",
779  gxemul.GetStep(), 0);
780  UnitTest::Assert("counterA should initially be 42",
781  counterA->GetVariable("counter")->ToInteger(), 42);
782  UnitTest::Assert("counterB should initially be 10042",
783  counterB->GetVariable("counter")->ToInteger(), 10042);
784 
786  gxemul.Execute();
787  // B executes in the first step.
788 
790  gxemul.Execute();
791  // A,B execute in the second step.
792 
793  // Step 2:
794  UnitTest::Assert("the step should now be 2", gxemul.GetStep(), 2);
795  UnitTest::Assert("counter A should now be 43",
796  counterA->GetVariable("counter")->ToInteger(), 43);
797  UnitTest::Assert("counter B should now be 10044",
798  counterB->GetVariable("counter")->ToInteger(), 10044);
799 
801  gxemul.Execute();
803  gxemul.Execute();
804 
805  // Step 4:
806  UnitTest::Assert("the step should now be 4", gxemul.GetStep(), 4);
807  UnitTest::Assert("counter A should now be 44",
808  counterA->GetVariable("counter")->ToInteger(), 44);
809  UnitTest::Assert("counter B should now be 10046",
810  counterB->GetVariable("counter")->ToInteger(), 10046);
811 
812  UnitTest::Assert("output stream mismatch?",
813  os.str(), "BABBAB");
814 }
815 
816 static void Test_DummyComponent_Execute_Continuous_SingleComponent()
817 {
818  GXemul gxemul;
819  gxemul.GetCommandInterpreter().RunCommand("add testcounter");
820  refcount_ptr<Component> counterA = gxemul.GetRootComponent()->GetChildren()[0];
821 
822  counterA->SetVariableValue("counter", "10042");
823 
824  // Step 0:
825  UnitTest::Assert("the step should initially be 0",
826  gxemul.GetStep(), 0);
827  UnitTest::Assert("counterA should initially be 10042",
828  counterA->GetVariable("counter")->ToInteger(), 10042);
829 
831  gxemul.Execute();
832 
833  // Step n:
834  int n = gxemul.GetStep();
835  UnitTest::Assert("counter A should now be 10042 + n",
836  counterA->GetVariable("counter")->ToInteger(), 10042 + n);
837 
839  gxemul.Execute();
840 
841  // Step n + 1:
842  UnitTest::Assert("the step should now be n + 1", gxemul.GetStep(), n + 1);
843  UnitTest::Assert("counter B should now be 10042 + n + 1",
844  counterA->GetVariable("counter")->ToInteger(), 10042 + n + 1);
845 }
846 
847 static void Test_DummyComponent_Execute_Continuous_TwoComponentsSameSpeed()
848 {
849  GXemul gxemul;
850  stringstream os;
851  gxemul.GetRootComponent()->AddChild(new DummyComponentWithCounter(&os, 'A'));
852  gxemul.GetRootComponent()->AddChild(new DummyComponentWithCounter(&os, 'B'));
853 
854  UnitTest::Assert("accuracy should be cycle!",
855  gxemul.GetRootComponent()->GetVariable("accuracy")->ToString(), "cycle");
856 
857  refcount_ptr<Component> counterA = gxemul.GetRootComponent()->GetChildren()[0];
858  refcount_ptr<Component> counterB = gxemul.GetRootComponent()->GetChildren()[1];
859 
860  counterA->SetVariableValue("counter", "123");
861  counterB->SetVariableValue("counter", "0");
862 
863  // Step 0:
864  UnitTest::Assert("counterA should initially be 123",
865  counterA->GetVariable("counter")->ToInteger(), 123);
866  UnitTest::Assert("counterB should initially be 0",
867  counterB->GetVariable("counter")->ToInteger(), 0);
868 
869  // The two components have the same speed, which is a "worst case"
870  // for cycle accurate emulation. They have to be interleaved one
871  // cycle at a time.
873  gxemul.Execute(10000);
874 
875  // Step n:
876  int n = gxemul.GetStep();
877  UnitTest::Assert("n very low?", n > 100);
878  UnitTest::Assert("counter A should now be 123 + n",
879  counterA->GetVariable("counter")->ToInteger(), 123 + n);
880  UnitTest::Assert("counter B should now be 0 + n",
881  counterB->GetVariable("counter")->ToInteger(), 0 + n);
882 
883  // After n steps, the stream should be ABABABAB... n times.
884  stringstream correct;
885  for (int i=0; i<n; ++i)
886  correct << "AB";
887 
888  UnitTest::Assert("output stream mismatch?", os.str(), correct.str());
889 }
890 
891 static void Test_DummyComponent_Execute_Continuous_TwoComponentsDifferentSpeed()
892 {
893  GXemul gxemul;
894  stringstream os;
895  gxemul.GetRootComponent()->AddChild(new DummyComponentWithCounter(&os, 'A'));
896  gxemul.GetRootComponent()->AddChild(new DummyComponentWithCounter(&os, 'B'));
897 
898  UnitTest::Assert("accuracy should be cycle!",
899  gxemul.GetRootComponent()->GetVariable("accuracy")->ToString(), "cycle");
900 
901  refcount_ptr<Component> counterA = gxemul.GetRootComponent()->GetChildren()[0];
902  refcount_ptr<Component> counterB = gxemul.GetRootComponent()->GetChildren()[1];
903 
904  counterA->SetVariableValue("counter", "123");
905  counterB->SetVariableValue("counter", "0");
906 
907  // Counter B should run three times as fast:
908  counterA->SetVariableValue("frequency", "100000");
909  counterB->SetVariableValue("frequency", "300000");
910 
911  // Step 0:
912  UnitTest::Assert("counterA should initially be 123",
913  counterA->GetVariable("counter")->ToInteger(), 123);
914  UnitTest::Assert("counterB should initially be 0",
915  counterB->GetVariable("counter")->ToInteger(), 0);
916 
917  // Step 0: B
918  // Step 1: B
919  // Step 2: A and B
921  gxemul.Execute(1000);
922 
923  // Step n: B should have executed 1 per cycle
924  // but A only 1/3 of the cycles.
925  int n = gxemul.GetStep();
926  int a = counterA->GetVariable("counter")->ToInteger();
927  UnitTest::Assert("counter A should now be approximately 123 + n/3",
928  (a >= 122 + n/3) && (a <= 123 + n/3));
929  UnitTest::Assert("counter B should now be 0 + n",
930  counterB->GetVariable("counter")->ToInteger(), 0 + n);
931 
932  // After n steps, the stream should be BBAB... n cycles.
933  stringstream correct;
934  for (int i=0; i<n; ++i) {
935  if ((i%3) <= 1)
936  correct << "B";
937  else
938  correct << "AB";
939  }
940 
941  UnitTest::Assert("output stream mismatch?", os.str(), correct.str());
942 }
943 
944 static void Test_DummyComponent_Execute_Continuous_ThreeComponentsDifferentSpeed()
945 {
946  GXemul gxemul;
947  stringstream os;
948  gxemul.GetRootComponent()->AddChild(new DummyComponentWithCounter(&os, 'A'));
949  gxemul.GetRootComponent()->AddChild(new DummyComponentWithCounter(&os, 'B'));
950  gxemul.GetRootComponent()->AddChild(new DummyComponentWithCounter(&os, 'C'));
951 
952  UnitTest::Assert("accuracy should be cycle!",
953  gxemul.GetRootComponent()->GetVariable("accuracy")->ToString(), "cycle");
954 
955  refcount_ptr<Component> counterA = gxemul.GetRootComponent()->GetChildren()[0];
956  refcount_ptr<Component> counterB = gxemul.GetRootComponent()->GetChildren()[1];
957  refcount_ptr<Component> counterC = gxemul.GetRootComponent()->GetChildren()[2];
958 
959  counterA->SetVariableValue("counter", "0");
960  counterB->SetVariableValue("counter", "0");
961  counterC->SetVariableValue("counter", "0");
962 
963  counterA->SetVariableValue("frequency", "1");
964  counterB->SetVariableValue("frequency", "100");
965  counterC->SetVariableValue("frequency", "10");
966 
968  gxemul.Execute(2000);
969 
970  int n = gxemul.GetStep();
971  UnitTest::Assert("n very low?", n >= 2000);
972 
973  int a = counterA->GetVariable("counter")->ToInteger();
974  UnitTest::Assert("counter A should now be approximately n / 100",
975  (a >= n / 100 - 1) && (a <= n / 100 + 1));
976 
977  UnitTest::Assert("counter B should now be n",
978  counterB->GetVariable("counter")->ToInteger(), n);
979 
980  int c = counterC->GetVariable("counter")->ToInteger();
981  UnitTest::Assert("counter C should now be approximately n / 10",
982  (c >= n / 10 - 1) && (c <= n / 10 + 1));
983 
984 
985  // Compare with single-step stream:
986  {
987  GXemul gxemul2;
988  stringstream singleStepStream;
989  gxemul2.GetRootComponent()->AddChild(new DummyComponentWithCounter(&singleStepStream, 'A'));
990  gxemul2.GetRootComponent()->AddChild(new DummyComponentWithCounter(&singleStepStream, 'B'));
991  gxemul2.GetRootComponent()->AddChild(new DummyComponentWithCounter(&singleStepStream, 'C'));
992 
993  counterA = gxemul2.GetRootComponent()->GetChildren()[0];
994  counterB = gxemul2.GetRootComponent()->GetChildren()[1];
995  counterC = gxemul2.GetRootComponent()->GetChildren()[2];
996 
997  counterA->SetVariableValue("counter", "0");
998  counterB->SetVariableValue("counter", "0");
999  counterC->SetVariableValue("counter", "0");
1000 
1001  counterA->SetVariableValue("frequency", "1");
1002  counterB->SetVariableValue("frequency", "100");
1003  counterC->SetVariableValue("frequency", "10");
1004 
1005  for (int i=0; i<n; ++i) {
1007  gxemul2.Execute();
1008  }
1009 
1010  UnitTest::Assert("output stream mismatch?", os.str() == singleStepStream.str());
1011  }
1012 }
1013 
1014 static void Test_DummyComponent_Execute_Continuous_ThreeComponentsDifferentSpeedWeird()
1015 {
1016  // Same as the test above, but with horribly choosen frequencies.
1017  GXemul gxemul;
1018  stringstream os;
1019  gxemul.GetRootComponent()->AddChild(new DummyComponentWithCounter(&os, 'A'));
1020  gxemul.GetRootComponent()->AddChild(new DummyComponentWithCounter(&os, 'B'));
1021  gxemul.GetRootComponent()->AddChild(new DummyComponentWithCounter(&os, 'C'));
1022 
1023  UnitTest::Assert("accuracy should be cycle!",
1024  gxemul.GetRootComponent()->GetVariable("accuracy")->ToString(), "cycle");
1025 
1026  refcount_ptr<Component> counterA = gxemul.GetRootComponent()->GetChildren()[0];
1027  refcount_ptr<Component> counterB = gxemul.GetRootComponent()->GetChildren()[1];
1028  refcount_ptr<Component> counterC = gxemul.GetRootComponent()->GetChildren()[2];
1029 
1030  counterA->SetVariableValue("counter", "0");
1031  counterB->SetVariableValue("counter", "0");
1032  counterC->SetVariableValue("counter", "0");
1033 
1034  counterA->SetVariableValue("frequency", "7");
1035  counterB->SetVariableValue("frequency", "101");
1036  counterC->SetVariableValue("frequency", "18");
1037 
1038  gxemul.SetRunState(GXemul::Running);
1039  gxemul.Execute(2000);
1040 
1041  int n = gxemul.GetStep();
1042  UnitTest::Assert("n very low?", n >= 2000);
1043 
1044  // Compare with single-step stream:
1045  {
1046  GXemul gxemul2;
1047  stringstream singleStepStream;
1048  gxemul2.GetRootComponent()->AddChild(new DummyComponentWithCounter(&singleStepStream, 'A'));
1049  gxemul2.GetRootComponent()->AddChild(new DummyComponentWithCounter(&singleStepStream, 'B'));
1050  gxemul2.GetRootComponent()->AddChild(new DummyComponentWithCounter(&singleStepStream, 'C'));
1051 
1052  counterA = gxemul2.GetRootComponent()->GetChildren()[0];
1053  counterB = gxemul2.GetRootComponent()->GetChildren()[1];
1054  counterC = gxemul2.GetRootComponent()->GetChildren()[2];
1055 
1056  counterA->SetVariableValue("counter", "0");
1057  counterB->SetVariableValue("counter", "0");
1058  counterC->SetVariableValue("counter", "0");
1059 
1060  counterA->SetVariableValue("frequency", "7");
1061  counterB->SetVariableValue("frequency", "101");
1062  counterC->SetVariableValue("frequency", "18");
1063 
1064  for (int i=0; i<n; ++i) {
1066  gxemul2.Execute();
1067  }
1068 
1069  UnitTest::Assert("output stream mismatch?", os.str() == singleStepStream.str());
1070  }
1071 }
1072 
1073 /*
1074 static void Test_DummyComponent_Execute_Continuous_ThreeComponentsDifferentSpeedWeird2()
1075 {
1076  // Same as the test above, but with even more horribly choosen frequencies.
1077  GXemul gxemul;
1078  stringstream os;
1079  gxemul.GetRootComponent()->AddChild(new DummyComponentWithCounter(&os, 'A'));
1080  gxemul.GetRootComponent()->AddChild(new DummyComponentWithCounter(&os, 'B'));
1081  gxemul.GetRootComponent()->AddChild(new DummyComponentWithCounter(&os, 'C'));
1082 
1083  UnitTest::Assert("accuracy should be cycle!",
1084  gxemul.GetRootComponent()->GetVariable("accuracy")->ToString(), "cycle");
1085 
1086  refcount_ptr<Component> counterA = gxemul.GetRootComponent()->GetChildren()[0];
1087  refcount_ptr<Component> counterB = gxemul.GetRootComponent()->GetChildren()[1];
1088  refcount_ptr<Component> counterC = gxemul.GetRootComponent()->GetChildren()[2];
1089 
1090  counterA->SetVariableValue("counter", "0");
1091  counterB->SetVariableValue("counter", "0");
1092  counterC->SetVariableValue("counter", "0");
1093 
1094  counterA->SetVariableValue("frequency", "183");
1095  counterB->SetVariableValue("frequency", "191");
1096  counterC->SetVariableValue("frequency", "194");
1097 
1098  gxemul.SetRunState(GXemul::Running);
1099  gxemul.Execute(1000);
1100 
1101  int n = gxemul.GetStep();
1102  UnitTest::Assert("n very low?", n >= 1000);
1103 
1104  // Compare with single-step stream:
1105  {
1106  GXemul gxemul;
1107  stringstream singleStepStream;
1108  gxemul.GetRootComponent()->AddChild(new DummyComponentWithCounter(&singleStepStream, 'A'));
1109  gxemul.GetRootComponent()->AddChild(new DummyComponentWithCounter(&singleStepStream, 'B'));
1110  gxemul.GetRootComponent()->AddChild(new DummyComponentWithCounter(&singleStepStream, 'C'));
1111 
1112  refcount_ptr<Component> counterA = gxemul.GetRootComponent()->GetChildren()[0];
1113  refcount_ptr<Component> counterB = gxemul.GetRootComponent()->GetChildren()[1];
1114  refcount_ptr<Component> counterC = gxemul.GetRootComponent()->GetChildren()[2];
1115 
1116  counterA->SetVariableValue("counter", "0");
1117  counterB->SetVariableValue("counter", "0");
1118  counterC->SetVariableValue("counter", "0");
1119 
1120  counterA->SetVariableValue("frequency", "183");
1121  counterB->SetVariableValue("frequency", "191");
1122  counterC->SetVariableValue("frequency", "194");
1123 
1124  for (int i=0; i<n; ++i) {
1125  gxemul.SetRunState(GXemul::SingleStepping);
1126  gxemul.Execute();
1127  }
1128 
1129  UnitTest::Assert("output stream mismatch?", os.str(), singleStepStream.str());
1130  }
1131 }
1132 */
1133 
1135 {
1137  DummyComponentWithAllVariableTypes::Create,
1139 
1141  DummyComponentWithCounter::Create,
1143 
1144  // Creation using CreateComponent
1145  UNITTEST(Test_DummyComponent_CreateComponent);
1146 
1147  // Parent tests
1148  UNITTEST(Test_DummyComponent_GetSetParent);
1149 
1150  // Add/Remove children
1151  UNITTEST(Test_DummyComponent_AddChild_Sets_Parent);
1152  UNITTEST(Test_DummyComponent_AddChildren_Count);
1153  UNITTEST(Test_DummyComponent_Add_Tree_Of_Children);
1154  UNITTEST(Test_DummyComponent_RemoveChild);
1155  UNITTEST(Test_DummyComponent_AddChild_UniqueName);
1156 
1157  // Path tests
1158  UNITTEST(Test_DummyComponent_GeneratePath);
1159  UNITTEST(Test_DummyComponent_GenerateShortestPossiblePath);
1160  UNITTEST(Test_DummyComponent_LookupPath);
1161  UNITTEST(Test_DummyComponent_FindPathByPartialMatch);
1162 
1163  // Get state variables
1164  UNITTEST(Test_DummyComponent_GetUnknownVariable);
1165 
1166  // Methods
1167  UNITTEST(Test_DummyComponent_NonexistantMethodNotReexecutable);
1168 
1169  // Clone
1170  UNITTEST(Test_DummyComponent_Clone_Basic);
1171  UNITTEST(Test_DummyComponent_Clone_AllVariableTypes);
1172 
1173  // Serialization/deserialization
1174  UNITTEST(Test_DummyComponent_SerializeDeserialize);
1175 
1176  // Cycle execution
1177  UNITTEST(Test_DummyComponent_Execute_SingleStep);
1178  UNITTEST(Test_DummyComponent_Execute_MultiSingleStep);
1179  UNITTEST(Test_DummyComponent_Execute_TwoComponentsSameSpeed);
1180  UNITTEST(Test_DummyComponent_Execute_TwoComponentsDifferentSpeed);
1181  UNITTEST(Test_DummyComponent_Execute_Continuous_SingleComponent);
1182  UNITTEST(Test_DummyComponent_Execute_Continuous_TwoComponentsSameSpeed);
1183  UNITTEST(Test_DummyComponent_Execute_Continuous_TwoComponentsDifferentSpeed);
1184  UNITTEST(Test_DummyComponent_Execute_Continuous_ThreeComponentsDifferentSpeed);
1185  UNITTEST(Test_DummyComponent_Execute_Continuous_ThreeComponentsDifferentSpeedWeird);
1186 // TODO: This currently fails!
1187 // UNITTEST(Test_DummyComponent_Execute_Continuous_ThreeComponentsDifferentSpeedWeird2);
1188 }
1189 
1190 #endif
1191 
void SetRunState(RunState newState)
Sets the RunState.
Definition: GXemul.cc:741
StateVariable * GetVariable(const string &name)
Gets a pointer to a state variable.
Definition: Component.cc:949
Component * GetParent()
Gets this component&#39;s parent component, if any.
Definition: Component.cc:381
virtual bool MethodMayBeReexecutedWithoutArgs(const string &methodName) const
Returns whether a method name may be re-executed without args.
Definition: Component.cc:399
static refcount_ptr< Component > CreateComponent(const string &componentNameAndOptionalArgs, GXemul *gxemul=NULL)
Creates a component given a short component name.
RunState GetRunState() const
Gets the current RunState.
Definition: GXemul.cc:749
vector< string > FindPathByPartialMatch(const string &partialPath, bool shortestPossible=false) const
Finds complete component paths, given a partial path.
Definition: Component.cc:912
string GeneratePath() const
Generates a string representation of the path to the Component.
Definition: Component.cc:686
bool RunCommand(const string &command, bool *pSuccess=NULL)
Runs a command, given as a string.
bool AddVariable(const string &name, T *variablePointer)
Adds a state variable of type T to the Component.
Definition: Component.h:563
uint64_t GetStep() const
Gets the current step of the emulation.
Definition: GXemul.cc:637
static refcount_ptr< Component > Create(const ComponentCreateArgs &args)
Creates a DummyComponent.
A checksum accumulator.
Definition: Checksum.h:47
Components & GetChildren()
Gets pointers to child components.
Definition: Component.cc:674
string GenerateShortestPossiblePath() const
Generates a short string representation of the path to the Component.
Definition: Component.cc:721
void SetNrOfSingleStepsInARow(uint64_t steps)
Sets the nr of single-steps to perform in a row.
Definition: GXemul.cc:800
static string GetAttribute(const string &attributeName)
Creates a Component.
Definition: Component.cc:66
string GetClassName() const
Gets the class name of the component.
Definition: Component.cc:54
void AddChecksum(Checksum &checksum) const
Adds this component&#39;s state, including children, to a checksum.
Definition: Component.cc:1253
The main emulator class.
Definition: GXemul.h:54
#define UNITTESTS(class)
Helper for unit test case execution.
Definition: UnitTest.h:184
CommandInterpreter & GetCommandInterpreter()
Gets a reference to the CommandInterpreter.
Definition: GXemul.cc:631
bool SetValue(const string &expression)
Set the variable&#39;s value, using a string expression.
A dummy Component, for unit testing purposes.
string ToString() const
Returns the variable as a readable string.
A Component is a node in the configuration tree that makes up an emulation setup. ...
Definition: Component.h:62
static string GetAttribute(const string &attributeName)
Get attribute information about the DummyComponent class.
DummyComponent(string className="dummy")
Constructs a DummyComponent.
bool CheckConsistency() const
Checks consistency by serializing and deserializing the component (including all its child components...
Definition: Component.cc:1226
virtual int Execute(GXemul *gxemul, int nrOfCycles)
Execute one or more cycles.
Definition: Component.cc:333
uint64_t ToInteger() const
Returns the variable as an unsignedinteger value.
StateVariables make up the persistent state of Component objects.
Definition: StateVariable.h:67
static bool RegisterComponentClass(const char *name, refcount_ptr< Component >(*createFunc)(const ComponentCreateArgs &args), string(*getAttributeFunc)(const string &attributeName))
Adds a new component class to the factory at runtime.
size_t RemoveChild(Component *childToRemove)
Removes a reference to a child component.
Definition: Component.cc:655
static void Assert(const string &strFailMessage, bool condition)
Asserts that a boolean condition is correct.
Definition: UnitTest.cc:40
bool SetVariableValue(const string &name, const string &expression)
Sets a variable to a new value.
Definition: Component.cc:1030
refcount_ptr< Component > Clone() const
Clones the component and all its children.
Definition: Component.cc:76
refcount_ptr< Component > GetRootComponent()
Gets a pointer to the root configuration component.
Definition: GXemul.cc:667
void AddChild(refcount_ptr< Component > childComponent, size_t insertPosition=(size_t) -1)
Adds a reference to a child component.
Definition: Component.cc:595
void SetParent(Component *parentComponent)
Sets the parent component of this component.
Definition: Component.cc:375
const refcount_ptr< Component > LookupPath(string path) const
Looks up a path from this Component, and returns a pointer to the found Component, if any.
Definition: Component.cc:778
void Execute(const int longestTotalRun=100000)
Run the emulation for "a while".
Definition: GXemul.cc:894
virtual void ResetState()
Resets the state variables of this component.
Definition: Component.cc:291
#define UNITTEST(functionname)
Helper for unit test case execution.
Definition: UnitTest.h:217
bool IsNULL() const
Checks whether or not an object is referenced by the reference counted pointer.
Definition: refcount_ptr.h:216

Generated on Fri Dec 7 2018 19:52:23 for GXemul by doxygen 1.8.13