Vodafone Test Suite
Dependencies: mbed-rtos mbed HTTPClient VodafoneUSBModem
TestManager.cpp@32:8ff0b67bb58c, 2012-09-13 (annotated)
- Committer:
- ashleymills
- Date:
- Thu Sep 13 08:21:25 2012 +0000
- Revision:
- 32:8ff0b67bb58c
- Parent:
- 30:dd2beda340c6
- Child:
- 33:16126e029d58
Changing the framework slightly.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ashleymills | 2:ea883307d02f | 1 | #include "TestManager.h" |
ashleymills | 3:28336c2e94e4 | 2 | #include "Tests.h" |
nherriot | 28:c630a04a7198 | 3 | |
ashleymills | 32:8ff0b67bb58c | 4 | // adds a test into the master test index |
ashleymills | 32:8ff0b67bb58c | 5 | void TestManager::addTest(VodafoneTestCase* testCase) { |
ashleymills | 32:8ff0b67bb58c | 6 | int index = testCase->_testCaseNumber; |
ashleymills | 32:8ff0b67bb58c | 7 | // make space for test |
ashleymills | 32:8ff0b67bb58c | 8 | int currentSize = _tests.size(); |
ashleymills | 32:8ff0b67bb58c | 9 | if(index>=currentSize) { |
ashleymills | 32:8ff0b67bb58c | 10 | int pushCount = (index-currentSize)+1; |
ashleymills | 32:8ff0b67bb58c | 11 | while(pushCount--) |
ashleymills | 32:8ff0b67bb58c | 12 | _tests.push_back(NULL); |
ashleymills | 32:8ff0b67bb58c | 13 | } |
ashleymills | 32:8ff0b67bb58c | 14 | if(_tests[index]==NULL) { |
ashleymills | 32:8ff0b67bb58c | 15 | _tests[index] = testCase; |
ashleymills | 32:8ff0b67bb58c | 16 | } |
ashleymills | 32:8ff0b67bb58c | 17 | } |
ashleymills | 32:8ff0b67bb58c | 18 | |
ashleymills | 32:8ff0b67bb58c | 19 | TestManager::TestManager(VodafoneUSBModem *m) : _modem(m) { |
ashleymills | 32:8ff0b67bb58c | 20 | // using direct array indexing instead of searching each time |
ashleymills | 32:8ff0b67bb58c | 21 | // dummy tests are inserted by the addTest function |
ashleymills | 32:8ff0b67bb58c | 22 | addTest((VodafoneTestCase*)new Test10(_modem,10)); |
ashleymills | 32:8ff0b67bb58c | 23 | addTest((VodafoneTestCase*)new Test12(_modem,12)); |
ashleymills | 32:8ff0b67bb58c | 24 | addTest((VodafoneTestCase*)new Test13(_modem,13)); |
ashleymills | 32:8ff0b67bb58c | 25 | addTest((VodafoneTestCase*)new Test16(_modem,16)); |
ashleymills | 32:8ff0b67bb58c | 26 | addTest((VodafoneTestCase*)new Test21(_modem,21)); |
ashleymills | 32:8ff0b67bb58c | 27 | addTest((VodafoneTestCase*)new Test22(_modem,22)); |
ashleymills | 32:8ff0b67bb58c | 28 | addTest((VodafoneTestCase*)new Test23(_modem,23)); |
ashleymills | 32:8ff0b67bb58c | 29 | addTest((VodafoneTestCase*)new Test25(_modem,25)); |
ashleymills | 32:8ff0b67bb58c | 30 | addTest((VodafoneTestCase*)new Test26(_modem,26)); |
ashleymills | 32:8ff0b67bb58c | 31 | addTest((VodafoneTestCase*)new Test50(_modem,50)); |
ashleymills | 32:8ff0b67bb58c | 32 | addTest((VodafoneTestCase*)new Test56(_modem,56)); |
ashleymills | 2:ea883307d02f | 33 | } |
ashleymills | 2:ea883307d02f | 34 | |
ashleymills | 22:5b1feecf2aeb | 35 | int TestManager::getTestProfileLength(TestProfile profile) { |
ashleymills | 26:9eefab9e28df | 36 | if(profile < TESTS_END) { // no test for >= 0 since TestProfile is unsigned |
ashleymills | 22:5b1feecf2aeb | 37 | return gTestProfileLengths[profile]; |
ashleymills | 22:5b1feecf2aeb | 38 | } else { |
ashleymills | 22:5b1feecf2aeb | 39 | LOG("Test profile out of bounds. Must be between 0 and %d",TESTS_END-1); |
ashleymills | 22:5b1feecf2aeb | 40 | return 0; |
ashleymills | 22:5b1feecf2aeb | 41 | } |
ashleymills | 22:5b1feecf2aeb | 42 | } |
ashleymills | 22:5b1feecf2aeb | 43 | |
ashleymills | 22:5b1feecf2aeb | 44 | int TestManager::executeTestProfile(TestProfile profile) { |
ashleymills | 24:8f0f9551122a | 45 | int numPassed = 0; |
ashleymills | 32:8ff0b67bb58c | 46 | if(profile<TESTS_END) { // no test for >= 0 since TestProfile is unsigned |
ashleymills | 24:8f0f9551122a | 47 | numPassed = executeTestList(gTestProfiles[profile], gTestProfileLengths[profile]); |
ashleymills | 22:5b1feecf2aeb | 48 | } else { |
ashleymills | 22:5b1feecf2aeb | 49 | LOG("Test profile out of bounds. Must be between 0 and %d",TESTS_END-1); |
ashleymills | 22:5b1feecf2aeb | 50 | return 0; |
ashleymills | 22:5b1feecf2aeb | 51 | } |
ashleymills | 24:8f0f9551122a | 52 | int numTests = getTestProfileLength(profile); |
ashleymills | 24:8f0f9551122a | 53 | LOG("%d tests complete: %d passes and %d failures.",numTests,numPassed,numTests-numPassed); |
ashleymills | 27:0297dbc3252b | 54 | LOG("Listing failures:"); |
ashleymills | 27:0297dbc3252b | 55 | listFailures(gTestProfiles[profile], gTestProfileLengths[profile]); |
ashleymills | 24:8f0f9551122a | 56 | return numPassed; |
ashleymills | 22:5b1feecf2aeb | 57 | } |
ashleymills | 22:5b1feecf2aeb | 58 | |
ashleymills | 27:0297dbc3252b | 59 | void TestManager::listFailures(const int *list, const int listLen) { |
ashleymills | 27:0297dbc3252b | 60 | int successfullTests = 0; |
ashleymills | 27:0297dbc3252b | 61 | for(int i=0; i<listLen; i++) { |
ashleymills | 27:0297dbc3252b | 62 | int testIndex = list[i]; |
ashleymills | 27:0297dbc3252b | 63 | if(testIndex>=_tests.size()) { |
ashleymills | 27:0297dbc3252b | 64 | LOG("Test out of bounds. Test index must be betweeen 0 and %d!",_tests.size()); |
ashleymills | 27:0297dbc3252b | 65 | continue; |
ashleymills | 27:0297dbc3252b | 66 | } |
ashleymills | 27:0297dbc3252b | 67 | |
ashleymills | 32:8ff0b67bb58c | 68 | VodafoneTestCase* test = _tests[testIndex]; |
ashleymills | 27:0297dbc3252b | 69 | if(test->_lastRunOutcome==false) { |
ashleymills | 27:0297dbc3252b | 70 | LOG("Test %d:",list[i]); |
ashleymills | 27:0297dbc3252b | 71 | LOG(gTestDescriptions[list[i]]); |
ashleymills | 27:0297dbc3252b | 72 | } |
ashleymills | 27:0297dbc3252b | 73 | } |
ashleymills | 22:5b1feecf2aeb | 74 | } |
ashleymills | 22:5b1feecf2aeb | 75 | |
ashleymills | 32:8ff0b67bb58c | 76 | VodafoneTestCase* TestManager::getTest(int index) { |
ashleymills | 32:8ff0b67bb58c | 77 | for(int i=0; i<_tests.size(); i++) { |
ashleymills | 32:8ff0b67bb58c | 78 | if(index==_tests[i]->_testCaseNumber) |
ashleymills | 32:8ff0b67bb58c | 79 | return _tests[i]; |
ashleymills | 32:8ff0b67bb58c | 80 | } |
ashleymills | 32:8ff0b67bb58c | 81 | return NULL; |
ashleymills | 32:8ff0b67bb58c | 82 | } |
ashleymills | 32:8ff0b67bb58c | 83 | |
ashleymills | 19:26fbed33d4e7 | 84 | int TestManager::executeTestList(const int *list, const int listLen) { |
nherriot | 29:c0e6f198db84 | 85 | LOG("The executeTestList is: %d", list); |
nherriot | 29:c0e6f198db84 | 86 | LOG("The executeTestListLength is: %d", listLen); |
ashleymills | 2:ea883307d02f | 87 | int successfullTests = 0; |
ashleymills | 19:26fbed33d4e7 | 88 | LOG("Running %d tests...",listLen); |
ashleymills | 19:26fbed33d4e7 | 89 | for(int i=0; i<listLen; i++) { |
ashleymills | 19:26fbed33d4e7 | 90 | int testIndex = list[i]; |
ashleymills | 19:26fbed33d4e7 | 91 | LOG("Running test %d...",testIndex); |
ashleymills | 19:26fbed33d4e7 | 92 | if(testIndex>=_tests.size()) { |
ashleymills | 19:26fbed33d4e7 | 93 | LOG("Test out of bounds. Test index must be betweeen 0 and %d!",_tests.size()); |
ashleymills | 19:26fbed33d4e7 | 94 | continue; |
ashleymills | 19:26fbed33d4e7 | 95 | } |
ashleymills | 19:26fbed33d4e7 | 96 | |
ashleymills | 32:8ff0b67bb58c | 97 | VodafoneTestCase* test = _tests[testIndex]; |
ashleymills | 19:26fbed33d4e7 | 98 | if(test==NULL) { |
ashleymills | 19:26fbed33d4e7 | 99 | LOG("NULL test! This will be counted as a failure."); |
ashleymills | 19:26fbed33d4e7 | 100 | continue; |
ashleymills | 19:26fbed33d4e7 | 101 | } |
ashleymills | 19:26fbed33d4e7 | 102 | |
ashleymills | 19:26fbed33d4e7 | 103 | if(test->run()) { |
ashleymills | 2:ea883307d02f | 104 | LOG("...OK"); |
ashleymills | 2:ea883307d02f | 105 | successfullTests++; |
ashleymills | 2:ea883307d02f | 106 | } else { |
ashleymills | 2:ea883307d02f | 107 | LOG("...FAIL"); |
ashleymills | 2:ea883307d02f | 108 | } |
ashleymills | 2:ea883307d02f | 109 | } |
ashleymills | 2:ea883307d02f | 110 | return successfullTests; |
ashleymills | 2:ea883307d02f | 111 | } |
ashleymills | 2:ea883307d02f | 112 | |
ashleymills | 4:1f8e079924ba | 113 | bool TestManager::runTest(int id) { |
ashleymills | 4:1f8e079924ba | 114 | if(id<0||id>=_tests.size()) { |
ashleymills | 4:1f8e079924ba | 115 | LOG("Test ID must be between 0 and %d",_tests.size()); |
ashleymills | 19:26fbed33d4e7 | 116 | return false; |
ashleymills | 4:1f8e079924ba | 117 | } |
ashleymills | 19:26fbed33d4e7 | 118 | if(_tests[id]==NULL) { |
ashleymills | 19:26fbed33d4e7 | 119 | LOG("NULL test! This will be counted as a failure."); |
ashleymills | 19:26fbed33d4e7 | 120 | return false; |
ashleymills | 19:26fbed33d4e7 | 121 | } |
ashleymills | 19:26fbed33d4e7 | 122 | |
ashleymills | 4:1f8e079924ba | 123 | return _tests[id]->run(); |
ashleymills | 4:1f8e079924ba | 124 | } |
ashleymills | 4:1f8e079924ba | 125 | |
ashleymills | 4:1f8e079924ba | 126 | |
ashleymills | 4:1f8e079924ba | 127 | bool TestManager::runTest(int id, int numTimes) { |
ashleymills | 4:1f8e079924ba | 128 | for(int i=0; i<numTimes; i++) { |
ashleymills | 4:1f8e079924ba | 129 | if(!runTest(id)) |
ashleymills | 4:1f8e079924ba | 130 | return false; |
ashleymills | 4:1f8e079924ba | 131 | } |
ashleymills | 4:1f8e079924ba | 132 | return true; |
ashleymills | 2:ea883307d02f | 133 | } |