48 if (attributeName ==
"stable")
51 if (attributeName ==
"description")
52 return "A dummy component, which does nothing.";
65 static void Test_DummyComponent_CreateComponent()
71 component.
IsNULL() ==
false);
77 static void Test_DummyComponent_GetSetParent()
96 static void Test_DummyComponent_AddChild_Sets_Parent()
110 static void Test_DummyComponent_AddChildren_Count()
128 static void Test_DummyComponent_Add_Tree_Of_Children()
145 static void Test_DummyComponent_RemoveChild()
169 "there should still be 2 child components in dummyChildA",
175 static void Test_DummyComponent_AddChild_UniqueName()
203 name->ToString(),
"dummy1");
211 name->ToString(),
"dummy2");
220 name->ToString(),
"dummy1");
223 static void Test_DummyComponent_GeneratePath()
248 static void Test_DummyComponent_GenerateShortestPossiblePath()
265 dummyB2->SetVariableValue(
"name",
"\"mainbus1\"");
268 dummyB2->AddChild(dummyC2);
276 static void Test_DummyComponent_LookupPath()
284 component1.
IsNULL() ==
true);
288 component2 == dummyA);
300 component3 == dummyA);
304 component4.
IsNULL() ==
true);
308 component5 == child);
312 component6 == childchild);
315 static void Test_DummyComponent_FindPathByPartialMatch()
350 vector<string> matches;
364 matches[0],
"root.machine1.pcibus0");
366 matches[1],
"root.machine1.pcibus1");
368 matches[2],
"root.machine2.pcibus0");
374 matches[0],
"root.machine1");
380 matches[0],
"root.machine2.pcibus0");
387 static void Test_DummyComponent_GetUnknownVariable()
395 static void Test_DummyComponent_NonexistantMethodNotReexecutable()
404 static void Test_DummyComponent_Clone_Basic()
411 dummyChildA->
AddChild(dummyChildA1);
412 dummyChildA->
AddChild(dummyChildA2);
424 originalChecksum == cloneChecksum);
428 Checksum originalChecksumAfterModifyingOriginal;
429 dummy->
AddChecksum(originalChecksumAfterModifyingOriginal);
430 Checksum cloneChecksumAfterModifyingOriginal;
431 clone->
AddChecksum(cloneChecksumAfterModifyingOriginal);
434 originalChecksum != originalChecksumAfterModifyingOriginal);
436 cloneChecksum == cloneChecksumAfterModifyingOriginal);
440 Checksum originalChecksumAfterModifyingClone;
441 dummy->
AddChecksum(originalChecksumAfterModifyingClone);
442 Checksum cloneChecksumAfterModifyingClone;
443 clone->
AddChecksum(cloneChecksumAfterModifyingClone);
446 "clone has been modified",
447 originalChecksumAfterModifyingClone ==
448 originalChecksumAfterModifyingOriginal);
451 cloneChecksumAfterModifyingClone ==
452 originalChecksumAfterModifyingOriginal);
455 class DummyComponentWithAllVariableTypes
459 DummyComponentWithAllVariableTypes()
481 m_string =
"some value";
484 m_uint32 = 0x98f8aa01;
485 m_uint64 = ((uint64_t)0xf8192929 << 32) | 0x30300a0a;
494 return new DummyComponentWithAllVariableTypes();
509 static void Test_DummyComponent_Clone_AllVariableTypes()
529 originalChecksum == cloneChecksum);
533 Checksum originalChecksumAfterModifyingOriginal;
534 dummy->
AddChecksum(originalChecksumAfterModifyingOriginal);
535 Checksum cloneChecksumAfterModifyingOriginal;
536 clone->
AddChecksum(cloneChecksumAfterModifyingOriginal);
539 originalChecksum != originalChecksumAfterModifyingOriginal);
541 cloneChecksum == cloneChecksumAfterModifyingOriginal);
545 Checksum originalChecksumAfterModifyingClone;
546 dummy->
AddChecksum(originalChecksumAfterModifyingClone);
547 Checksum cloneChecksumAfterModifyingClone;
548 clone->
AddChecksum(cloneChecksumAfterModifyingClone);
551 "clone has been modified",
552 originalChecksumAfterModifyingClone ==
553 originalChecksumAfterModifyingOriginal);
556 cloneChecksumAfterModifyingClone ==
557 originalChecksumAfterModifyingOriginal);
560 static void Test_DummyComponent_SerializeDeserialize()
567 dummyChildA->
AddChild(dummyChildA1);
568 dummyChildA->
AddChild(dummyChildA2);
575 class DummyComponentWithCounter
579 DummyComponentWithCounter(ostream* os = NULL,
char c =
'X')
598 return new DummyComponentWithCounter();
604 m_counter += nrOfCycles;
607 for (
int i=0; i<nrOfCycles; ++i)
621 static void Test_DummyComponent_Execute_SingleStep()
632 counter->GetVariable(
"name")->ToString(),
"testcounter0");
638 counter->GetVariable(
"counter")->ToInteger(), 42);
648 counter->GetVariable(
"counter")->ToInteger(), 43);
658 counter->GetVariable(
"counter")->ToInteger(), 44);
661 static void Test_DummyComponent_Execute_MultiSingleStep()
672 counter->GetVariable(
"name")->ToString(),
"testcounter0");
674 const int nrOfStepsToRun = 23;
688 counter->GetVariable(
"counter")->ToInteger(), 42+nrOfStepsToRun);
698 counter->GetVariable(
"counter")->ToInteger(), 43+nrOfStepsToRun);
701 static void Test_DummyComponent_Execute_TwoComponentsSameSpeed()
714 counterA->GetVariable(
"name")->ToString(),
"testcounter0");
724 counterA->GetVariable(
"counter")->ToInteger(), 42);
736 counterA->GetVariable(
"counter")->ToInteger(), 43);
748 counterA->GetVariable(
"counter")->ToInteger(), 44);
753 static void Test_DummyComponent_Execute_TwoComponentsDifferentSpeed()
767 counterA->GetVariable(
"name")->ToString(),
"testcounter0");
772 counterA->SetVariableValue(
"frequency",
"100000");
781 counterA->GetVariable(
"counter")->ToInteger(), 42);
796 counterA->GetVariable(
"counter")->ToInteger(), 43);
808 counterA->GetVariable(
"counter")->ToInteger(), 44);
816 static void Test_DummyComponent_Execute_Continuous_SingleComponent()
847 static void Test_DummyComponent_Execute_Continuous_TwoComponentsSameSpeed()
860 counterA->SetVariableValue(
"counter",
"123");
865 counterA->GetVariable(
"counter")->ToInteger(), 123);
879 counterA->GetVariable(
"counter")->ToInteger(), 123 + n);
884 stringstream correct;
885 for (
int i=0; i<n; ++i)
891 static void Test_DummyComponent_Execute_Continuous_TwoComponentsDifferentSpeed()
904 counterA->SetVariableValue(
"counter",
"123");
908 counterA->SetVariableValue(
"frequency",
"100000");
913 counterA->GetVariable(
"counter")->ToInteger(), 123);
926 int a = counterA->GetVariable(
"counter")->ToInteger();
928 (a >= 122 + n/3) && (a <= 123 + n/3));
933 stringstream correct;
934 for (
int i=0; i<n; ++i) {
944 static void Test_DummyComponent_Execute_Continuous_ThreeComponentsDifferentSpeed()
959 counterA->SetVariableValue(
"counter",
"0");
963 counterA->SetVariableValue(
"frequency",
"1");
973 int a = counterA->GetVariable(
"counter")->ToInteger();
975 (a >= n / 100 - 1) && (a <= n / 100 + 1));
982 (c >= n / 10 - 1) && (c <= n / 10 + 1));
988 stringstream singleStepStream;
997 counterA->SetVariableValue(
"counter",
"0");
1001 counterA->SetVariableValue(
"frequency",
"1");
1005 for (
int i=0; i<n; ++i) {
1010 UnitTest::Assert(
"output stream mismatch?", os.str() == singleStepStream.str());
1014 static void Test_DummyComponent_Execute_Continuous_ThreeComponentsDifferentSpeedWeird()
1030 counterA->SetVariableValue(
"counter",
"0");
1034 counterA->SetVariableValue(
"frequency",
"7");
1047 stringstream singleStepStream;
1056 counterA->SetVariableValue(
"counter",
"0");
1060 counterA->SetVariableValue(
"frequency",
"7");
1064 for (
int i=0; i<n; ++i) {
1069 UnitTest::Assert(
"output stream mismatch?", os.str() == singleStepStream.str());
1137 DummyComponentWithAllVariableTypes::Create,
1141 DummyComponentWithCounter::Create,
1145 UNITTEST(Test_DummyComponent_CreateComponent);
1148 UNITTEST(Test_DummyComponent_GetSetParent);
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);
1158 UNITTEST(Test_DummyComponent_GeneratePath);
1159 UNITTEST(Test_DummyComponent_GenerateShortestPossiblePath);
1160 UNITTEST(Test_DummyComponent_LookupPath);
1161 UNITTEST(Test_DummyComponent_FindPathByPartialMatch);
1164 UNITTEST(Test_DummyComponent_GetUnknownVariable);
1167 UNITTEST(Test_DummyComponent_NonexistantMethodNotReexecutable);
1170 UNITTEST(Test_DummyComponent_Clone_Basic);
1171 UNITTEST(Test_DummyComponent_Clone_AllVariableTypes);
1174 UNITTEST(Test_DummyComponent_SerializeDeserialize);
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);
void SetRunState(RunState newState)
Sets the RunState.
StateVariable * GetVariable(const string &name)
Gets a pointer to a state variable.
Component * GetParent()
Gets this component's parent component, if any.
virtual bool MethodMayBeReexecutedWithoutArgs(const string &methodName) const
Returns whether a method name may be re-executed without args.
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.
vector< string > FindPathByPartialMatch(const string &partialPath, bool shortestPossible=false) const
Finds complete component paths, given a partial path.
string GeneratePath() const
Generates a string representation of the path to the Component.
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.
uint64_t GetStep() const
Gets the current step of the emulation.
static refcount_ptr< Component > Create(const ComponentCreateArgs &args)
Creates a DummyComponent.
Components & GetChildren()
Gets pointers to child components.
string GenerateShortestPossiblePath() const
Generates a short string representation of the path to the Component.
void SetNrOfSingleStepsInARow(uint64_t steps)
Sets the nr of single-steps to perform in a row.
static string GetAttribute(const string &attributeName)
Creates a Component.
string GetClassName() const
Gets the class name of the component.
void AddChecksum(Checksum &checksum) const
Adds this component's state, including children, to a checksum.
#define UNITTESTS(class)
Helper for unit test case execution.
CommandInterpreter & GetCommandInterpreter()
Gets a reference to the CommandInterpreter.
bool SetValue(const string &expression)
Set the variable'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. ...
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...
virtual int Execute(GXemul *gxemul, int nrOfCycles)
Execute one or more cycles.
uint64_t ToInteger() const
Returns the variable as an unsignedinteger value.
StateVariables make up the persistent state of Component objects.
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.
static void Assert(const string &strFailMessage, bool condition)
Asserts that a boolean condition is correct.
bool SetVariableValue(const string &name, const string &expression)
Sets a variable to a new value.
refcount_ptr< Component > Clone() const
Clones the component and all its children.
refcount_ptr< Component > GetRootComponent()
Gets a pointer to the root configuration component.
void AddChild(refcount_ptr< Component > childComponent, size_t insertPosition=(size_t) -1)
Adds a reference to a child component.
void SetParent(Component *parentComponent)
Sets the parent component of this component.
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.
void Execute(const int longestTotalRun=100000)
Run the emulation for "a while".
virtual void ResetState()
Resets the state variables of this component.
#define UNITTEST(functionname)
Helper for unit test case execution.
bool IsNULL() const
Checks whether or not an object is referenced by the reference counted pointer.