Vodafone Test Suite

Dependencies:   mbed-rtos mbed HTTPClient VodafoneUSBModem

Files at this revision

API Documentation at this revision

Comitter:
ashleymills
Date:
Fri Oct 12 10:03:37 2012 +0000
Parent:
52:de6cc9d823ab
Child:
56:6ca2d4c1ffc4
Commit message:
File download test, now tests files between 128 bytes and 1MB in successive powers of 2.

Changed in this revision

LogHeader.h Show annotated file Show diff for this revision Revisions of this file
Tests/Test08.cpp Show annotated file Show diff for this revision Revisions of this file
Tests/Test10.cpp Show annotated file Show diff for this revision Revisions of this file
Tests/Tests.cpp Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/LogHeader.h	Thu Oct 11 10:00:19 2012 +0000
+++ b/LogHeader.h	Fri Oct 12 10:03:37 2012 +0000
@@ -2,7 +2,7 @@
 #define LOGGER
 #ifdef LOGGER
     #define LOG(...) { fprintf(stdout,"[LOG] "); fprintf(stdout,__VA_ARGS__); fprintf(stdout,"\r\n"); }
-    #define LOGX(...) { fprintf(stdout,"[LOG] "); fprintf(stdout,__VA_ARGS__) }
+    #define LOGX(...) { fprintf(stdout,"[LOG] "); fprintf(stdout,__VA_ARGS__); }
 #else
     #define LOG(...)
     #define LOGX(...)
--- a/Tests/Test08.cpp	Thu Oct 11 10:00:19 2012 +0000
+++ b/Tests/Test08.cpp	Fri Oct 12 10:03:37 2012 +0000
@@ -69,10 +69,12 @@
    // try connecting to DNS server directly
    int sockfd;
    //if(connectToSocket("88.82.13.28",53,&sockfd)) {
+   
    if(connectToSocket("109.74.199.96",80,&sockfd)) {
       close(sockfd);
    }
    
+   
    struct hostent *server;
    do {
       while(1) {
--- a/Tests/Test10.cpp	Thu Oct 11 10:00:19 2012 +0000
+++ b/Tests/Test10.cpp	Fri Oct 12 10:03:37 2012 +0000
@@ -1,46 +1,111 @@
-#include "Test10.h"
-
-Test10::Test10(VodafoneUSBModem *m) : VodafoneTestCase(m) {
-   _description = gTest10Description;
-   _testCaseNumber = 10;
-}
-      
-void Test10::setupTest() {}
-   
-bool Test10::executeTest() {
-   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("Doing HTTP GET for http://www.m2mthings.com/test100.txt");
-   if(http.get("http://www.m2mthings.com/test100.txt", msgBuffer, 125)==0) {
-      LOG("Got buffer");
-      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;
-      }
-      LOG("All bytes match! PASS.");
-   } else {
-      LOG("HTTP get failure");
-      outcome = false;
-   }
-   _modem->disconnect();
-   return outcome;
-}
-      
+#include "Test10.h"
+
+class HTTPFileValidator : public IHTTPDataIn {
+public:
+    HTTPFileValidator(int sockfd) {
+       _fileIsValid = false;
+       _bytesRead = 0;
+    }
+    
+    bool isValid() {
+       return _fileIsValid;
+    }
+    
+    int bytesRead() {
+       return _bytesRead;
+    }
+
+protected:
+    //IHTTPDataIn
+    virtual int write(const char* buf, size_t len) {
+        int i = 0;
+        // do nothing if file already found invalid
+        if(!_fileIsValid)
+           return len;
+           
+        // check that received characters are in correct sequence
+        for(i=0; i<len; i++) {
+           if(buf[i]!=_expectedChar) {
+              _fileIsValid = false;
+              break;
+           }
+           _expectedChar++;
+           if(_expectedChar==256) {
+              _expectedChar = 0;
+           }
+        }
+        _bytesRead += i;
+        
+        return len;
+    }
+    virtual void writeReset() {
+       _fileIsValid = true;
+       _expectedChar = 0;
+       _bytesRead = 0;  
+    }
+    virtual void setDataType(const char* type) {}
+    virtual void setIsChunked(bool chunked) {}
+    virtual void setDataLen(size_t len) {}
+    bool _fileIsValid;
+    char _expectedChar;
+    int _bytesRead;
+};
+
+
+Test10::Test10(VodafoneUSBModem *m) : VodafoneTestCase(m) {
+   _description = gTest10Description;
+   _testCaseNumber = 10;
+}
+      
+void Test10::setupTest() {}
+   
+bool Test10::executeTest() {
+   HTTPClient http;
+   char urlBuffer[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");
+      _modem->disconnect();
+      return false;
+   }
+   
+   // retrieve files whose sizes are successive powers of 2 from 128 bytes upto 1MB
+   int bytesToRead = 128;
+   HTTPFileValidator fileValidator(0);
+   Timer t;
+   for(int i=0; i<14; i++) {
+      sprintf(urlBuffer,"http://www.m2mthings.com/test%d.txt",bytesToRead);
+      LOGX("Doing HTTP GET for %s ... ",urlBuffer);
+      
+      // read the file
+      t.reset();
+      t.start();
+      if(http.get(urlBuffer, &fileValidator)!=0) {
+         LOG("ERROR reading file from website");
+         outcome = false;
+         t.stop();
+         break;
+      }
+      t.stop();
+      
+      // check that all received bytes were valid, and that the total number of bytes read is as expected
+      if(fileValidator.isValid()&&fileValidator.bytesRead()==bytesToRead) {
+         LOG("OK. (%f seconds, %f kb/s)",t.read(),((float)bytesToRead/1000.0)/t.read());
+      } else {
+         LOG("ERROR in file validation after %f seconds and %d bytes read.",t.read(),fileValidator.bytesRead());
+         outcome = false;
+         break;
+      }
+      
+      bytesToRead *= 2;
+   }
+   
+   _modem->disconnect();
+   return outcome;
+}
+      
 void Test10::endTest() { }
\ No newline at end of file
--- a/Tests/Tests.cpp	Thu Oct 11 10:00:19 2012 +0000
+++ b/Tests/Tests.cpp	Fri Oct 12 10:03:37 2012 +0000
@@ -10,7 +10,7 @@
 const char* gTest07Description = "Test 7";
 const char* gTest08Description = "Test 8: Resolve 5 different DNS entries and match against IPs.";
 const char* gTest09Description = "Test 9";
-const char* gTest10Description = "Connects to internet and downloads 100 byte file.";
+const char* gTest10Description = "Downloads files from 128 bytes to 1MB, in ^2 increments.";
 const char* gTest11Description = "Test 11";
 const char* gTest12Description = "Sends and SMS and then does something.";
 const char* gTest13Description = "Waiting for an SMS message with irregular characters and numbers";
--- a/main.cpp	Thu Oct 11 10:00:19 2012 +0000
+++ b/main.cpp	Fri Oct 12 10:03:37 2012 +0000
@@ -23,28 +23,6 @@
 time_t gPreviousUptime = 0;
 time_t gUptime = 0;
 
-void loopForever() {
-   while(1) {
-      Thread::wait(1000);
-      time_t now = time(NULL);
-      gPreviousUptime = gUptime;
-      gUptime = now-startTime;
-   }
-}
-
-void test(void const*) {
-  VodafoneUSBModem modem;
-  LOG("Constructing TestManager");
-  LOG("Running tests.");
-  TestManager *m = new TestManager(&modem);
-  //m->runTestProfile(TESTS_AUTOMATED);
-  m->runTest(8);
-  //m->executeTest(26);
-  //m->executeTest(10);
-  //m->executeTest(21);
-  loopForever();
-}
-
 void setTime() {
   struct tm t;
   t.tm_year  = 100;
@@ -72,13 +50,18 @@
   LOG("Constructing TestManager");
   LOG("Running tests.");
   TestManager *m = new TestManager(&modem);
-  //m->runTestProfile(TESTS_AUTOMATED);
-  m->runTest(8);
+  m->runTestProfile(TESTS_AUTOMATED);
+  //m->runTest(10);
+  
+  
   // this thread just waits and blinks leds periodically
   while(1) {
      led1 = !led1;
      Thread::wait(500);
      led1 = !led1;
      Thread::wait(1000);
+     time_t now = time(NULL);
+     gPreviousUptime = gUptime;
+     gUptime = now-startTime;
   }
 }
\ No newline at end of file