Vodafone Test Suite
Dependencies: mbed-rtos mbed HTTPClient VodafoneUSBModem
Revision 72:0e8e769fcf76, committed 2013-09-20
- Comitter:
- ashleymills
- Date:
- Fri Sep 20 12:36:03 2013 +0000
- Parent:
- 71:0d1b99ae9b58
- Child:
- 73:effa8fcd45fc
- Commit message:
- Updated VodafoneUSBModem to latest version.
Changed in this revision
--- a/TestManager.cpp Thu Jun 27 13:09:14 2013 +0000 +++ b/TestManager.cpp Fri Sep 20 12:36:03 2013 +0000 @@ -23,7 +23,7 @@ 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 15: return (VodafoneTestCase*) new Test15(_modem); case 16: break; case 17: break; case 18: break;
--- a/TestManager.cpp.orig Thu Jun 27 13:09:14 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,169 +0,0 @@ -#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/Tests/Test07.h Thu Jun 27 13:09:14 2013 +0000 +++ b/Tests/Test07.h Fri Sep 20 12:36:03 2013 +0000 @@ -14,12 +14,10 @@ virtual bool executeTest() { LOG(gTest07Description); - if(_modem->sendUSSD(".2890",_ussdResponse,16)!=0) { - LOG("Error sending USSD"); - return false; - } + _modem->sendUSSD(".2890",_ussdResponse,16); LOG("Expecting \"Unknown command\". Received USSD response: \"%s\"",_ussdResponse); + return (strcmp(_ussdResponse,"Unknown command")==0); }
--- a/Tests/Test11.h Thu Jun 27 13:09:14 2013 +0000 +++ b/Tests/Test11.h Fri Sep 20 12:36:03 2013 +0000 @@ -60,16 +60,28 @@ LOG("Artificially waiting for 2 seconds"); Thread::wait(2000); LOG("Attempting to send SMS %d of %d",i+1,numIterations); - if(_modem->sendSM(_ownNumber,_smsOut)!=0) { + int tries = 3; + int sent = 0; + while(tries--) { + if(_modem->sendSM(_ownNumber,_smsOut)==0) { + sent = 1; + break; + } LOG("Error sending short message"); } - LOG("Sent: %s",_smsOut); + if(!sent) { + LOG("Failure to send SMS after 3 tries, aborting."); + return false; + } else { + LOG("Sent: %s",_smsOut); + } + bool gotMessage = false; Timer t; t.start(); - int msToWait = 10000; + int msToWait = 60000; LOG("Waiting %d seconds for response",msToWait/1000); while(!gotMessage && t.read_ms()<msToWait) { if(_modem->getSMCount(&smCount)!=0) {
--- a/Tests/Test12.h Thu Jun 27 13:09:14 2013 +0000 +++ b/Tests/Test12.h Fri Sep 20 12:36:03 2013 +0000 @@ -1,6 +1,7 @@ #pragma once #include "VodafoneTestCase.h" +// Test 12: x2 -> Send 25 SMS, wait for recv, read them quickly. extern const char* gTest12Description; class Test12 : public VodafoneTestCase { @@ -24,6 +25,7 @@ virtual bool executeTest() { // locals int smsToSend = 50, mailBoxSize = 25; + int tries = 0, sent = 0; size_t smCount, oldSMCount; Timer t; @@ -34,7 +36,7 @@ LOG("... Clearing out SMS mail box first"); for(int j=0; j<3; j++) { if(_modem->getSMCount(&smCount)!=0) { - LOG("Faiure getting SM count"); + LOG("Failure getting SM count"); return false; } @@ -61,18 +63,31 @@ } else { sprintf(_smsOut,"B SMS %d",i); } - if(_modem->sendSM(_ownNumber,_smsOut)!=0) { + tries = 3; + sent = 0; + while(tries--) { + if(_modem->sendSM(_ownNumber,_smsOut)==0) { + sent = 1; + break; + } + LOG("Error sending SM, trying again."); + } + + if(!sent) { LOG("Error sending short message"); return false; } else { LOG("Sent %d/%d: \"%s\"",i,smsToSend,_smsOut); } + Thread::wait(50); } Thread::wait(5000); // wait for 25 to arrive and then read them as quickly as possible smCount = 0, oldSMCount = 0; t.start(); + LOG("waiting for messages"); + // wait a maximum of 10 minutes while(smCount<mailBoxSize&&t.read_ms()<600000) { if(_modem->getSMCount(&smCount)!=0) { @@ -91,6 +106,7 @@ return false; } + LOG("dumping SMS"); for(int i=0; i<mailBoxSize; i++) { if(_modem->getSM(_senderNumber,_smsIn,_smsLen)!=0) { @@ -105,6 +121,8 @@ smCount = 0, oldSMCount = 0; t.start(); // wait a maximum of 10 minutes + LOG("Waiting for messages"); + while(smCount<mailBoxSize&&t.read_ms()<600000) { if(_modem->getSMCount(&smCount)!=0) { LOG("Failure getting SM count");
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Tests/Test15.h Fri Sep 20 12:36:03 2013 +0000 @@ -0,0 +1,158 @@ +#pragma once +#include "VodafoneTestCase.h" +// Test 15: Sends SMSs to self that contain carriage returns and newlines +extern const char* gTest15Description; + +class Test15 : public VodafoneTestCase { + public: + Test15(VodafoneUSBModem *m) : VodafoneTestCase(m) { + _smsLen = 32; + _smsMaxSize = 160; // max size of SMS + _numberLen = 16; + } + + private: + + virtual void setupTest() { + allocStorage(); + } + + virtual void endTest() { + freeStorage(); + } + + virtual bool executeTest() { + LOG(gTest15Description); + size_t smCount; + + // Clear out the SMS mail box before we run this test. + // loop 3 times with a 1/2 second break in between each + LOG("... Clearing out SMS mail box first"); + bool smsCleared = false; + for(int j=0; j<3; j++) { + if(_modem->getSMCount(&smCount)!=0) { + LOG("Failure getting SM count"); + return false; + } + + for(int i=0; i<smCount; i++) { + if(_modem->getSM(_senderNumber,_smsJunkBuffer,_smsMaxSize)!=0) { + LOG("Strange! The SMS count is bigger than zero but I can't fetch the SMS?"); + return false; + } + LOG("Got SMS: %s",_smsJunkBuffer); + LOG("Clearing that out before running the test."); + smsCleared = true; + } + Thread::wait(500); + } + if(!smsCleared) { + LOG("Nothing found to clear out."); + } + + LOG("Getting MSISDN"); + _modem->sendUSSD("*#100#",_ownNumber,_numberLen); + LOG("Got MSISDN %s",_ownNumber); + + // try sending SMS to self that contain CRLF sequences + // CR + // LF + // CRLF + // LFCR + + // note, you can't pass in a pointer to a const string, because the SMSInterface.cpp tries to write to the string + // this is probably a bug as the user might not expect this + + char crTestString[20],lfTestString[20],crlfTestString[20]; + sprintf((char*)&crTestString,"CR\rCR\rCR"); + sprintf((char*)&lfTestString,"LF\nLF\nLF"); + sprintf((char*)&crlfTestString,"CRLF\r\nCRLF"); + + int numTestMessages = 3; + char *testMessages[3] = { + (char*)&lfTestString, + (char*)&crTestString, + (char*)&crlfTestString + }; + + for(int i=0; i<numTestMessages; i++) { + _smsOut = testMessages[i]; + + LOG("Artificially waiting for 2 seconds"); + Thread::wait(2000); + LOG("Attempting to send SMS %d of %d",i+1,numTestMessages); + int tries = 3; + int sent = 0; + while(tries--) { + if(_modem->sendSM(_ownNumber,_smsOut)==0) { + sent = 1; + break; + } + LOG("Error sending short message"); + } + + if(!sent) { + LOG("Failure to send SMS after 3 tries, aborting."); + return false; + } else { + LOG("Sent: %s",_smsOut); + } + + + bool gotMessage = false; + Timer t; + t.start(); + int msToWait = 60000; + LOG("Waiting %d seconds for response",msToWait/1000); + while(!gotMessage && t.read_ms()<msToWait) { + if(_modem->getSMCount(&smCount)!=0) { + LOG("Failure getting SM count"); + return false; + } + + if(smCount>0) { + if(_modem->getSM(_senderNumber,_smsIn,_smsLen)!=0) { + LOG("Failure getting SM"); + return false; + } + LOG("Got SMS: %s after %f seconds.",_smsIn,t.read_ms()/1000.0); + if(strcmp(_smsIn,_smsOut)!=0) { + LOG("FAIL: strings did not match"); + return false; + } + gotMessage = true; + } + Thread::wait(50); + } + if(!gotMessage) { + LOG("FAIL: timeout on waiting for SMS"); + return false; + } + } + + return true; + } + + void allocStorage() { + _ownNumber = (char*)malloc(_numberLen*sizeof(char)); + _senderNumber = (char*)malloc(_numberLen*sizeof(char)); + _smsIn = (char*)malloc(_smsLen*sizeof(char)); + _smsJunkBuffer= (char*)malloc(_smsMaxSize*sizeof(char)); + } + + void freeStorage() { + free(_ownNumber); + free(_senderNumber); + free(_smsIn); + free(_smsJunkBuffer); + } + + char* _ownNumber; + char* _senderNumber; + char* _smsOut; + char* _smsIn; + char* _smsJunkBuffer; + int _smsLen; + int _smsMaxSize; + int _numberLen; +}; \ No newline at end of file
--- a/Tests/TestHelper.h Thu Jun 27 13:09:14 2013 +0000 +++ b/Tests/TestHelper.h Fri Sep 20 12:36:03 2013 +0000 @@ -1,13 +1,13 @@ #pragma once bool connectToSocket(char *ipAddress, int port, int *sockfd); -#define APN_PAYG +//#define APN_PAYG //#define APN_CUSTOM //#define APN_GDSP -//#define APN_CONTRACT +#define APN_CONTRACT #ifdef APN_GDSP - #define APN "ppinternet.gdsp" + #define APN "ppinternetd.gdsp" #define APN_USERNAME "" #define APN_PASSWORD "" #endif
--- a/Tests/Tests.cpp Thu Jun 27 13:09:14 2013 +0000 +++ b/Tests/Tests.cpp Fri Sep 20 12:36:03 2013 +0000 @@ -15,7 +15,7 @@ const char* gTest12Description = "Test 12: x2 -> Send 25 SMS, wait for recv, read them quickly."; const char* gTest13Description = "Test 13: Wait for SMS. Send a response."; const char* gTest14Description = "Test 14: Uploads \"files\" from 128 bytes to 1MB, in ^2 increments."; -const char* gTest15Description = "Test 15"; +const char* gTest15Description = "Test 15: Sends SMSs to self that contain carriage returns and newlines."; const char* gTest16Description = "Test 16"; const char* gTest17Description = "Test 17"; const char* gTest18Description = "Test 18";
--- a/Tests/Tests.h Thu Jun 27 13:09:14 2013 +0000 +++ b/Tests/Tests.h Fri Sep 20 12:36:03 2013 +0000 @@ -14,9 +14,10 @@ #include "Test12.h" #include "Test13.h" #include "Test14.h" +#include "Test15.h" -const int gAllTests[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14}; -const int gNumAllTests = 15; +const int gAllTests[] = {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}; +const int gNumAllTests = 16; const int gAutomatedTests[] = {0,1,6,7,9,10,11,12,14}; const int gNumAutomatedTests = 9; const int gInteractiveTests[] = {2,3,4,5,13}; @@ -25,6 +26,8 @@ const int gNumSoakTests = 0; const int gTestsInternet[] = {0,1,14}; const int gNumTestsInternet = 3; +const int gTestsSMS[] = {11,12}; +const int gNumTestsSMS = 2; enum TestProfile { TESTS_ALL, @@ -32,24 +35,28 @@ TESTS_MANUAL, TESTS_SOAK, TESTS_INTERNET, + TESTS_SMS, TESTS_END }; -static const int* gTestProfiles[5] = { +static const int* gTestProfiles[7] = { gAllTests, gAutomatedTests, gInteractiveTests, gSoakTests, - gTestsInternet + gTestsInternet, + gTestsSMS, + NULL }; -static const int gTestProfileLengths[5] = { +static const int gTestProfileLengths[7] = { gNumAllTests, gNumAutomatedTests, gNumInteractiveTests, gNumSoakTests, - gNumTestsInternet + gNumTestsInternet, + gNumTestsSMS, + 0 }; -extern const char* gTestDescriptions[]; - +extern const char* gTestDescriptions[]; \ No newline at end of file
--- a/VodafoneUSBModem.lib Thu Jun 27 13:09:14 2013 +0000 +++ b/VodafoneUSBModem.lib Fri Sep 20 12:36:03 2013 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/VodafoneUSBModem/#f8d65dc86a97 +http://mbed.org/users/mbed_official/code/VodafoneUSBModem/#7b311719374d
--- a/main.cpp Thu Jun 27 13:09:14 2013 +0000 +++ b/main.cpp Fri Sep 20 12:36:03 2013 +0000 @@ -49,9 +49,10 @@ LOG("Running tests."); TestManager *m = new TestManager(&modem); - //m->runTestProfile(TESTS_AUTOMATED); + m->runTestProfile(TESTS_AUTOMATED); //m->runTestProfile(TESTS_INTERNET); - m->runTest(11); + //m->runTestProfile(TESTS_SMS); + //m->runTest(15); // this thread just waits and blinks leds periodically while(1) {