Vodafone Test Suite
Dependencies: mbed-rtos mbed HTTPClient VodafoneUSBModem
Revision 24:8f0f9551122a, committed 2012-09-06
- Comitter:
- ashleymills
- Date:
- Thu Sep 06 12:15:54 2012 +0000
- Parent:
- 23:408199b5d2cb
- Child:
- 25:55b865c41f21
- Commit message:
- Added HTTP test
Changed in this revision
--- a/TestManager.cpp Wed Sep 05 16:38:06 2012 +0000 +++ b/TestManager.cpp Thu Sep 06 12:15:54 2012 +0000 @@ -37,12 +37,16 @@ } int TestManager::executeTestProfile(TestProfile profile) { + int numPassed = 0; if(profile>=0 && profile <TESTS_END) { - return executeTestList(gTestProfiles[profile], gTestProfileLengths[profile]); + 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); + return numPassed; } int TestManager::executeTestList(const int *list, const int listLen) {
--- a/Tests/Test10.h Wed Sep 05 16:38:06 2012 +0000 +++ b/Tests/Test10.h Thu Sep 06 12:15:54 2012 +0000 @@ -1,41 +1,57 @@ -#pragma once -#include "VodafoneTestCase.h" -#include "HTTPClient.h" -class Test10 : public VodafoneTestCase { - public: - Test10(VodafoneUSBModem *m, int tcNumber) : VodafoneTestCase(m, tcNumber) { - } - - virtual void setupTest() { - - - } - - virtual bool runTest() { - HTTPClient http; - char msgBuffer[125]; - bool outcome = false; - - LOG("Connecting to internet"); - if(_modem->connect("internet","web","web")==0) { - LOG("Connected to internet"); - } else { - LOG("Failed to connect to internet"); - } - - LOG("Test %d, retrieving a 5MB file via HTTP.", _testCaseNumber); - if(http.get("http://www.m2mthings.com/test100.txt", msgBuffer, 125)==0) { - LOG("Got %s",msgBuffer); - outcome = true; - } - _modem->disconnect(); - return outcome; - } - - virtual void endTest() { - - } - - private: - +#pragma once +#include "VodafoneTestCase.h" +#include "HTTPClient.h" + +static const char* gTest10Description = "Connects to internet and downloads 100 byte file.\0"; +class Test10 : public VodafoneTestCase { + public: + Test10(VodafoneUSBModem *m, int tcNumber) : VodafoneTestCase(m, tcNumber) { + } + + virtual void setupTest() { + + + } + + virtual bool runTest() { + HTTPClient http; + char msgBuffer[125]; + bool outcome = true; + LOG("Description: %s",gTest10Description); + LOG("Connecting to internet"); + if(_modem->connect("internet","web","web")==0) { + LOG("Connected to internet"); + } else { + LOG("Failed to connect to internet"); + outcome = false; + } + + LOG("Test %d, retrieving a 5MB file via HTTP.", _testCaseNumber); + if(http.get("http://www.m2mthings.com/test100.txt", msgBuffer, 125)==0) { + LOG("Got \"%s\"",msgBuffer); + char c = 0; + for(int i=0; i<100; i++) { + if(msgBuffer[i]!=c) { + LOG("Strings do not match at char %d (%x,%x)",i,c,msgBuffer[i]); + outcome = false; + break; + } + c++; + if(c==256) + c = 0; + } + } else { + LOG("HTTP get failure"); + outcome = false; + } + _modem->disconnect(); + return outcome; + } + + virtual void endTest() { + + } + + private: + }; \ No newline at end of file
--- a/Tests/Tests.h Wed Sep 05 16:38:06 2012 +0000 +++ b/Tests/Tests.h Thu Sep 06 12:15:54 2012 +0000 @@ -39,4 +39,8 @@ gNumAutomatedTests, gNumInteractiveTests, gNumSoakTests +}; + +static const char* gTestDescriptions[] = { + gTest10Description }; \ No newline at end of file
--- a/main.cpp Wed Sep 05 16:38:06 2012 +0000 +++ b/main.cpp Thu Sep 06 12:15:54 2012 +0000 @@ -19,22 +19,30 @@ extern "C" void HardFault_Handler() { error("Hard Fault!\n"); } +time_t startTime = 0; +time_t gPreviousUptime = 0; +time_t gUptime = 0; + +void loopForever() { + while(1) { + Thread::wait(1000); + time_t now = time(NULL); + gPreviousUptime = gUptime; + } +} + void test(void const*) { VodafoneUSBModem modem; LOG("Constructing TestManager"); TestManager *m = new TestManager(&modem); LOG("Running tests."); - TestProfile profile = TESTS_AUTOMATED; - int numPassed = m->executeTestProfile(profile); - int numTests = m->getTestProfileLength(profile); - LOG("%d tests complete: %d passes and %d failures.",numTests,numPassed,numTests-numPassed); - while(1) { - Thread::wait(1000); - } + int numPassed = m->executeTestProfile(TESTS_AUTOMATED); + + loopForever(); } -time_t startTime = 0; + void setTime() { struct tm t;