DummyComponent.cc Source File

Back to the index.

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

Generated on Tue Aug 25 2020 19:25:06 for GXemul by doxygen 1.8.18