Vodafone Test Suite
Dependencies: mbed-rtos mbed HTTPClient VodafoneUSBModem
Revision 44:6d0ac4747f5b, committed 2012-09-17
- Comitter:
- ashleymills
- Date:
- Mon Sep 17 13:28:39 2012 +0000
- Parent:
- 43:6db6a72d722b
- Child:
- 45:f68fea0831d7
- Commit message:
- Refactored names. Privatised virtuals to avoid bugs (bitten).
Changed in this revision
--- a/TestManager.cpp Fri Sep 14 15:14:29 2012 +0000 +++ b/TestManager.cpp Mon Sep 17 13:28:39 2012 +0000 @@ -74,8 +74,8 @@ } TestManager::TestManager(VodafoneUSBModem *m) : _modem(m) { - //_testOutcomes = (bool*)malloc(NUMBER_OF_TESTS*sizeof(bool)); - //resetTestOutcomes(); + _testOutcomes = (bool*)malloc(NUMBER_OF_TESTS*sizeof(bool)); + resetTestOutcomes(); } void TestManager::resetTestOutcomes() { @@ -93,11 +93,11 @@ } } -int TestManager::executeTestProfile(TestProfile profile) { - //resetTestOutcomes(); +int TestManager::runTestProfile(TestProfile profile) { + resetTestOutcomes(); int numPassed = 0; if(profile<TESTS_END) { // no test for >= 0 since TestProfile is unsigned - numPassed = executeTestList(gTestProfiles[profile], gTestProfileLengths[profile]); + numPassed = runTestList(gTestProfiles[profile], gTestProfileLengths[profile]); } else { LOG("Test profile out of bounds. Must be between 0 and %d",TESTS_END-1); return 0; @@ -120,47 +120,27 @@ } } -/* -VodafoneTestCase* TestManager::getTest(int index) { - for(int i=0; i<_tests.size(); i++) { - if(index==_tests[i]->_testCaseNumber) - return _tests[i]; - } - return NULL; -} -*/ - -int TestManager::executeTestList(const int *list, const int listLen) { +int TestManager::runTestList(const int *list, const int listLen) { int successfullTests = 0; LOG("Running %d tests...",listLen); for(int i=0; i<listLen; i++) { int testIndex = list[i]; - if(executeTest(testIndex)) { + if(runTest(testIndex)) { successfullTests++; } } return successfullTests; } -bool TestManager::executeTest(int testID) { - VodafoneTestCase* test = constructTest(testID);//getTest(testID); +bool TestManager::runTest(int testID) { + VodafoneTestCase* test = constructTest(testID); if(test==NULL) { LOG("Error. Test %d is not in test list! This will be counted as a failure.",testID); - //delete test; return false; } LOG("Running test %d...",testID); - //if(test->execute()) { //FIX Donatien - /* - Error was there: - If execute() is called directly, setupTest() and endTest() are NOT called! - In Tests 21 & 22 these routines were used to allocate/deallocate the buffer where - the USSD result was supposed to be stored - This pointer being random, random stuff happened when the USSDInterface tried to copy the response to this address - */ - if(test->run()) - { + if(test->run()) { LOG("...OK"); delete test; return true; @@ -170,9 +150,9 @@ return false; } -bool TestManager::executeTest(int id, int numTimes) { +bool TestManager::runTest(int id, int numTimes) { for(int i=0; i<numTimes; i++) { - if(!executeTest(id)) + if(!runTest(id)) return false; } return true;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TestManager.cpp.orig Mon Sep 17 13:28:39 2012 +0000 @@ -0,0 +1,169 @@ +#include "TestManager.h" +#include "Tests.h" + +// adds a test into the master test index +void TestManager::addTest(VodafoneTestCase* testCase) { + _tests.push_back(testCase); +} + +VodafoneTestCase* TestManager::constructTest(int testID) { + switch(testID) { + case 0: break; + case 1: break; + case 2: break; + case 3: break; + case 4: break; + case 5: break; + case 6: break; + case 7: break; + case 8: break; + case 9: break; + case 10: return (VodafoneTestCase*) new Test10(_modem); + case 11: break; + case 12: return (VodafoneTestCase*) new Test12(_modem); + case 13: return (VodafoneTestCase*) new Test13(_modem); + case 14: return (VodafoneTestCase*) new Test14(_modem); + case 15: break; + case 16: return (VodafoneTestCase*) new Test16(_modem); + case 17: break; + case 18: break; + case 19: break; + case 20: break; + case 21: return (VodafoneTestCase*) new Test21(_modem); + case 22: return (VodafoneTestCase*) new Test22(_modem); + case 23: return (VodafoneTestCase*) new Test23(_modem); + case 24: break; + case 25: return (VodafoneTestCase*) new Test25(_modem); + case 26: return (VodafoneTestCase*) new Test26(_modem); + case 27: break; + case 28: break; + case 29: break; + case 30: break; + case 31: break; + case 32: break; + case 33: break; + case 34: break; + case 35: break; + case 36: break; + case 37: break; + case 38: break; + case 39: break; + case 40: break; + case 41: break; + case 42: break; + case 43: break; + case 44: break; + case 45: break; + case 46: break; + case 47: break; + case 48: break; + case 49: break; + case 50: return (VodafoneTestCase*) new Test50(_modem); + case 51: break; + case 52: break; + case 53: break; + case 54: break; + case 55: break; + case 56: return (VodafoneTestCase*) new Test56(_modem); + case 57: break; + case 58: break; + case 59: break; + default: return NULL; + }; + return NULL; //< For compiler warning +} + +TestManager::TestManager(VodafoneUSBModem *m) : _modem(m) { + //_testOutcomes = (bool*)malloc(NUMBER_OF_TESTS*sizeof(bool)); + //resetTestOutcomes(); +} + +void TestManager::resetTestOutcomes() { + for(int i=0; i<NUMBER_OF_TESTS; i++) { + _testOutcomes[i] = false; + } +} + +int TestManager::getTestProfileLength(TestProfile profile) { + if(profile < TESTS_END) { // no test for >= 0 since TestProfile is unsigned + return gTestProfileLengths[profile]; + } else { + LOG("Test profile out of bounds. Must be between 0 and %d",TESTS_END-1); + return 0; + } +} + +int TestManager::executeTestProfile(TestProfile profile) { + //resetTestOutcomes(); + int numPassed = 0; + if(profile<TESTS_END) { // no test for >= 0 since TestProfile is unsigned + numPassed = executeTestList(gTestProfiles[profile], gTestProfileLengths[profile]); + } else { + LOG("Test profile out of bounds. Must be between 0 and %d",TESTS_END-1); + return 0; + } + int numTests = getTestProfileLength(profile); + LOG("%d tests complete: %d passes and %d failures.",numTests,numPassed,numTests-numPassed); + LOG("Listing failures:"); + listFailures(gTestProfiles[profile], gTestProfileLengths[profile]); + return numPassed; +} + +void TestManager::listFailures(const int *list, const int listLen) { + for(int i=0; i<listLen; i++) { + int testIndex = list[i]; + + if(_testOutcomes[testIndex]==false) { + LOG("Test %d:",testIndex); + //LOG(gTestDescriptions[testIndex]); + } + } +} + +/* +VodafoneTestCase* TestManager::getTest(int index) { + for(int i=0; i<_tests.size(); i++) { + if(index==_tests[i]->_testCaseNumber) + return _tests[i]; + } + return NULL; +} +*/ + +int TestManager::executeTestList(const int *list, const int listLen) { + int successfullTests = 0; + LOG("Running %d tests...",listLen); + for(int i=0; i<listLen; i++) { + int testIndex = list[i]; + if(executeTest(testIndex)) { + successfullTests++; + } + } + return successfullTests; +} + +bool TestManager::executeTest(int testID) { + VodafoneTestCase* test = constructTest(testID);//getTest(testID); + if(test==NULL) { + LOG("Error. Test %d is not in test list! This will be counted as a failure.",testID); + return false; + } + + LOG("Running test %d...",testID); + if(test->execute()) { + LOG("...OK"); + delete test; + return true; + } + LOG("...FAIL"); + delete test; + return false; +} + +bool TestManager::executeTest(int id, int numTimes) { + for(int i=0; i<numTimes; i++) { + if(!executeTest(id)) + return false; + } + return true; +} \ No newline at end of file
--- a/TestManager.h Fri Sep 14 15:14:29 2012 +0000 +++ b/TestManager.h Mon Sep 17 13:28:39 2012 +0000 @@ -12,17 +12,17 @@ TestManager(VodafoneUSBModem *m); void addTest(VodafoneTestCase *tc); - bool executeTest(int id); - bool executeTest(int id, int numTimes); - int executeTestProfile(TestProfile profile); - int getTestProfileLength(TestProfile profile); + bool runTest(int id); + bool runTest(int id, int numTimes); + int runTestProfile(TestProfile profile); + int getTestProfileLength(TestProfile profile); private: VodafoneUSBModem *_modem; vector<VodafoneTestCase*> _tests; VodafoneTestCase* constructTest(int id); - int executeTestList(const int *list, const int listLen); + int runTestList(const int *list, const int listLen); void listFailures(const int *list, const int listLen); void resetTestOutcomes(); bool *_testOutcomes;
--- a/Tests/Test10.cpp Fri Sep 14 15:14:29 2012 +0000 +++ b/Tests/Test10.cpp Mon Sep 17 13:28:39 2012 +0000 @@ -7,7 +7,7 @@ void Test10::setupTest() {} -bool Test10::execute() { +bool Test10::executeTest() { HTTPClient http; char msgBuffer[125]; bool outcome = true;
--- a/Tests/Test10.h Fri Sep 14 15:14:29 2012 +0000 +++ b/Tests/Test10.h Mon Sep 17 13:28:39 2012 +0000 @@ -6,7 +6,9 @@ class Test10 : public VodafoneTestCase { public: Test10(VodafoneUSBModem *m); + + private: virtual void setupTest(); - virtual bool execute(); + virtual bool executeTest(); virtual void endTest(); }; \ No newline at end of file
--- a/Tests/Test12.h Fri Sep 14 15:14:29 2012 +0000 +++ b/Tests/Test12.h Mon Sep 17 13:28:39 2012 +0000 @@ -22,8 +22,10 @@ _description = gTest12Description; _testCaseNumber = 12; } + + private: - virtual bool execute() { + virtual bool executeTest() { LOG("Test: %d",_testCaseNumber); LOG(gTest12Description); LOG("Receiving SMS from test phone, waiting for response.");
--- a/Tests/Test13.h Fri Sep 14 15:14:29 2012 +0000 +++ b/Tests/Test13.h Mon Sep 17 13:28:39 2012 +0000 @@ -24,8 +24,10 @@ _description = gTest13Description; _testCaseNumber = 13; } + + private: - virtual bool execute() { + virtual bool executeTest() { LOG("Test %d waiting for an SMS message...", _testCaseNumber); LOG("Receiving SMS from test phone, waiting for response."); @@ -63,7 +65,4 @@ } } - - private: - }; \ No newline at end of file
--- a/Tests/Test14.h Fri Sep 14 15:14:29 2012 +0000 +++ b/Tests/Test14.h Mon Sep 17 13:28:39 2012 +0000 @@ -15,14 +15,13 @@ class Test14 : public VodafoneTestCase { public: - Test14(VodafoneUSBModem *m) : VodafoneTestCase(m) { _description = gTest14Description; _testCaseNumber = 14; } - - virtual bool execute() { + private: + virtual bool executeTest() { LinkMonitor::REGISTRATION_STATE regState = LinkMonitor::REGISTRATION_STATE_UNKNOWN; LinkMonitor::BEARER bearer = LinkMonitor::BEARER_UNKNOWN; @@ -81,8 +80,4 @@ LOG("Test %d passed...", _testCaseNumber); return true; } - - private: - - }; \ No newline at end of file
--- a/Tests/Test16.h Fri Sep 14 15:14:29 2012 +0000 +++ b/Tests/Test16.h Mon Sep 17 13:28:39 2012 +0000 @@ -20,8 +20,9 @@ _testCaseNumber = 16; } + private: - virtual bool execute() { + virtual bool executeTest() { LinkMonitor::REGISTRATION_STATE regState = LinkMonitor::REGISTRATION_STATE_UNKNOWN; LinkMonitor::BEARER bearer = LinkMonitor::BEARER_UNKNOWN; @@ -80,8 +81,4 @@ LOG("Test %d passed...", _testCaseNumber); return true; } - - private: - - }; \ No newline at end of file
--- a/Tests/Test21.h Fri Sep 14 15:14:29 2012 +0000 +++ b/Tests/Test21.h Mon Sep 17 13:28:39 2012 +0000 @@ -11,11 +11,13 @@ _testCaseNumber = 21; } + private: + virtual void setupTest() { _ussdResponse = (char*)malloc(16*sizeof(char)); } - virtual bool execute() { + virtual bool executeTest() { LOG(_description); if(_modem->sendUSSD("*#100#",_ussdResponse,16)!=0) { @@ -31,6 +33,5 @@ free(_ussdResponse); } - private: char *_ussdResponse; };
--- a/Tests/Test22.h Fri Sep 14 15:14:29 2012 +0000 +++ b/Tests/Test22.h Mon Sep 17 13:28:39 2012 +0000 @@ -9,11 +9,12 @@ _testCaseNumber = 22; } + private: virtual void setupTest() { _ussdResponse = (char*)malloc(16*sizeof(char)); } - virtual bool execute() { + virtual bool executeTest() { LOG(_description); if(_modem->sendUSSD(".2890",_ussdResponse,16)!=0) { @@ -29,6 +30,5 @@ free(_ussdResponse); } - private: char *_ussdResponse; };
--- a/Tests/Test23.cpp Fri Sep 14 15:14:29 2012 +0000 +++ b/Tests/Test23.cpp Mon Sep 17 13:28:39 2012 +0000 @@ -14,7 +14,7 @@ } // virtual -bool Test23::execute() { +bool Test23::executeTest() { LOG(gTest23Description);
--- a/Tests/Test23.h Fri Sep 14 15:14:29 2012 +0000 +++ b/Tests/Test23.h Mon Sep 17 13:28:39 2012 +0000 @@ -6,10 +6,9 @@ class Test23 : public VodafoneTestCase { public: Test23(VodafoneUSBModem *m); + private: virtual void setupTest(); - virtual bool execute(); + virtual bool executeTest(); virtual void endTest(); - - private: char *_ussdResponse; }; \ No newline at end of file
--- a/Tests/Test25.h Fri Sep 14 15:14:29 2012 +0000 +++ b/Tests/Test25.h Mon Sep 17 13:28:39 2012 +0000 @@ -9,12 +9,13 @@ _description = gTest25Description; _testCaseNumber = 25; } + private: virtual void setupTest() { } - virtual bool execute() { + virtual bool executeTest() { LOG(gTest25Description); int rssi = -1000; @@ -88,6 +89,4 @@ } - private: - };
--- a/Tests/Test26.h Fri Sep 14 15:14:29 2012 +0000 +++ b/Tests/Test26.h Mon Sep 17 13:28:39 2012 +0000 @@ -9,12 +9,14 @@ _description = gTest26Description; _testCaseNumber = 26; } + + private: virtual void setupTest() { } - virtual bool execute() { + virtual bool executeTest() { LOG(gTest26Description); for(int count=0; count<30; count++) { LOG("Iteration %d of 30",count); @@ -89,7 +91,5 @@ } - private: - };
--- a/Tests/Test50.h Fri Sep 14 15:14:29 2012 +0000 +++ b/Tests/Test50.h Mon Sep 17 13:28:39 2012 +0000 @@ -12,6 +12,8 @@ _testCaseNumber = 50; } + private: + virtual void setupTest() { allocStorage(); } @@ -20,7 +22,7 @@ freeStorage(); } - virtual bool execute() { + virtual bool executeTest() { LOG(gTest50Description); int numIterations = 10; size_t smCount; @@ -66,7 +68,6 @@ return true; } - private: void createRandomString(char *target, int len) { for(int i=0; i<len; i++) { target[i] = 65+rand()%16;
--- a/Tests/Test56.h Fri Sep 14 15:14:29 2012 +0000 +++ b/Tests/Test56.h Mon Sep 17 13:28:39 2012 +0000 @@ -16,8 +16,9 @@ _testCaseNumber = 56; } + private: - virtual bool execute() { + virtual bool executeTest() { LinkMonitor::REGISTRATION_STATE regState = LinkMonitor::REGISTRATION_STATE_UNKNOWN; LinkMonitor::BEARER bearer = LinkMonitor::BEARER_UNKNOWN; @@ -92,7 +93,6 @@ } - private: char gsm03dot38CharacterSet[127];
--- a/VodafoneTestCase.h Fri Sep 14 15:14:29 2012 +0000 +++ b/VodafoneTestCase.h Mon Sep 17 13:28:39 2012 +0000 @@ -9,15 +9,17 @@ bool run() { setupTest(); - _lastRunOutcome = execute(); + _lastRunOutcome = executeTest(); endTest(); return _lastRunOutcome; } + private: + virtual void setupTest() { } - virtual bool execute() { + virtual bool executeTest() { LOG("Base class runTest called!"); return true; }
--- a/main.cpp Fri Sep 14 15:14:29 2012 +0000 +++ b/main.cpp Mon Sep 17 13:28:39 2012 +0000 @@ -36,7 +36,11 @@ LOG("Constructing TestManager"); LOG("Running tests."); TestManager *m = new TestManager(&modem); - int numPassed = m->executeTestProfile(TESTS_AUTOMATED); + m->runTestProfile(TESTS_AUTOMATED); + //m->executeTest(25); + //m->executeTest(26); + //m->executeTest(10); + //m->executeTest(21); loopForever(); }