ublox-cellular-driver-gen Fork

Fork of ublox-cellular-driver-gen by u-blox

Committer:
rob.meades@u-blox.com
Date:
Thu Jun 15 01:14:18 2017 +0100
Revision:
5:b935404dcf7c
Parent:
3:027c9eaec52c
Child:
6:804d544f8d8c
Tests now pass on C027: cope with filenames being returned without quotation marks, reduce file size to write since some modules can't keep up when there's no HW flow control, increase USSD timeout, simplify JSON template and run test without debug.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
RobMeades 0:bb5fabac67ab 1 #include "mbed.h"
RobMeades 0:bb5fabac67ab 2 #include "greentea-client/test_env.h"
RobMeades 0:bb5fabac67ab 3 #include "unity.h"
RobMeades 0:bb5fabac67ab 4 #include "utest.h"
RobMeades 0:bb5fabac67ab 5 #include "UbloxCellularDriverGen.h"
RobMeades 0:bb5fabac67ab 6 #include "UDPSocket.h"
rob.meades@u-blox.com 3:027c9eaec52c 7 #ifdef FEATURE_COMMON_PAL
RobMeades 0:bb5fabac67ab 8 #include "mbed_trace.h"
RobMeades 0:bb5fabac67ab 9 #define TRACE_GROUP "TEST"
rob.meades@u-blox.com 3:027c9eaec52c 10 #else
rob.meades@u-blox.com 3:027c9eaec52c 11 #define tr_debug(format, ...) debug(format "\n", ## __VA_ARGS__)
rob.meades@u-blox.com 3:027c9eaec52c 12 #define tr_info(format, ...) debug(format "\n", ## __VA_ARGS__)
rob.meades@u-blox.com 3:027c9eaec52c 13 #define tr_warn(format, ...) debug(format "\n", ## __VA_ARGS__)
rob.meades@u-blox.com 3:027c9eaec52c 14 #define tr_error(format, ...) debug(format "\n", ## __VA_ARGS__)
rob.meades@u-blox.com 3:027c9eaec52c 15 #endif
RobMeades 0:bb5fabac67ab 16
RobMeades 0:bb5fabac67ab 17 using namespace utest::v1;
RobMeades 0:bb5fabac67ab 18
RobMeades 0:bb5fabac67ab 19 // ----------------------------------------------------------------
RobMeades 0:bb5fabac67ab 20 // COMPILE-TIME MACROS
RobMeades 0:bb5fabac67ab 21 // ----------------------------------------------------------------
RobMeades 0:bb5fabac67ab 22
RobMeades 0:bb5fabac67ab 23 // These macros can be overridden with an mbed_app.json file and
RobMeades 0:bb5fabac67ab 24 // contents of the following form:
RobMeades 0:bb5fabac67ab 25 //
RobMeades 0:bb5fabac67ab 26 //{
RobMeades 0:bb5fabac67ab 27 // "config": {
RobMeades 0:bb5fabac67ab 28 // "default-pin": {
RobMeades 0:bb5fabac67ab 29 // "value": "\"my_pin\""
RobMeades 0:bb5fabac67ab 30 // }
RobMeades 0:bb5fabac67ab 31 //}
RobMeades 0:bb5fabac67ab 32
rob.meades@u-blox.com 5:b935404dcf7c 33 // Whether debug trace is on
rob.meades@u-blox.com 5:b935404dcf7c 34 #ifndef MBED_CONF_APP_DEBUG_ON
rob.meades@u-blox.com 5:b935404dcf7c 35 # define MBED_CONF_APP_DEBUG_ON false
rob.meades@u-blox.com 5:b935404dcf7c 36 #endif
rob.meades@u-blox.com 5:b935404dcf7c 37
RobMeades 0:bb5fabac67ab 38 // The credentials of the SIM in the board.
RobMeades 0:bb5fabac67ab 39 #ifndef MBED_CONF_APP_DEFAULT_PIN
RobMeades 0:bb5fabac67ab 40 // Note: this is the PIN for the SIM with ICCID
RobMeades 0:bb5fabac67ab 41 // 8944501104169548380.
RobMeades 0:bb5fabac67ab 42 # define MBED_CONF_APP_DEFAULT_PIN "5134"
RobMeades 0:bb5fabac67ab 43 #endif
RobMeades 0:bb5fabac67ab 44
RobMeades 0:bb5fabac67ab 45 // The size of file to use.
RobMeades 0:bb5fabac67ab 46 #ifndef MBED_CONF_APP_FILE_SIZE
rob.meades@u-blox.com 5:b935404dcf7c 47 # define MBED_CONF_APP_FILE_SIZE 1500
RobMeades 0:bb5fabac67ab 48 #endif
RobMeades 0:bb5fabac67ab 49
RobMeades 0:bb5fabac67ab 50 // The name of the file to use.
RobMeades 0:bb5fabac67ab 51 #ifndef MBED_CONF_APP_FILE_NAME
RobMeades 0:bb5fabac67ab 52 # define MBED_CONF_APP_FILE_NAME "test_file"
RobMeades 0:bb5fabac67ab 53 #endif
RobMeades 0:bb5fabac67ab 54
RobMeades 0:bb5fabac67ab 55 // ----------------------------------------------------------------
RobMeades 0:bb5fabac67ab 56 // PRIVATE VARIABLES
RobMeades 0:bb5fabac67ab 57 // ----------------------------------------------------------------
RobMeades 0:bb5fabac67ab 58
rob.meades@u-blox.com 5:b935404dcf7c 59 #ifdef FEATURE_COMMON_PAL
RobMeades 0:bb5fabac67ab 60 // Lock for debug prints
RobMeades 0:bb5fabac67ab 61 static Mutex mtx;
rob.meades@u-blox.com 5:b935404dcf7c 62 #endif
RobMeades 0:bb5fabac67ab 63
RobMeades 0:bb5fabac67ab 64 // An instance of the generic cellular class
RobMeades 0:bb5fabac67ab 65 static UbloxCellularDriverGen *pDriver =
RobMeades 0:bb5fabac67ab 66 new UbloxCellularDriverGen(MDMTXD, MDMRXD,
RobMeades 0:bb5fabac67ab 67 MBED_CONF_UBLOX_CELL_BAUD_RATE,
rob.meades@u-blox.com 5:b935404dcf7c 68 MBED_CONF_APP_DEBUG_ON);
RobMeades 0:bb5fabac67ab 69
RobMeades 0:bb5fabac67ab 70 // A general purpose buffer
RobMeades 0:bb5fabac67ab 71 char buf[MBED_CONF_APP_FILE_SIZE];
RobMeades 0:bb5fabac67ab 72
RobMeades 0:bb5fabac67ab 73 // ----------------------------------------------------------------
RobMeades 0:bb5fabac67ab 74 // PRIVATE FUNCTIONS
RobMeades 0:bb5fabac67ab 75 // ----------------------------------------------------------------
RobMeades 0:bb5fabac67ab 76
rob.meades@u-blox.com 3:027c9eaec52c 77 #ifdef FEATURE_COMMON_PAL
RobMeades 0:bb5fabac67ab 78 // Locks for debug prints
RobMeades 0:bb5fabac67ab 79 static void lock()
RobMeades 0:bb5fabac67ab 80 {
RobMeades 0:bb5fabac67ab 81 mtx.lock();
RobMeades 0:bb5fabac67ab 82 }
RobMeades 0:bb5fabac67ab 83
RobMeades 0:bb5fabac67ab 84 static void unlock()
RobMeades 0:bb5fabac67ab 85 {
RobMeades 0:bb5fabac67ab 86 mtx.unlock();
RobMeades 0:bb5fabac67ab 87 }
rob.meades@u-blox.com 3:027c9eaec52c 88 #endif
RobMeades 0:bb5fabac67ab 89
RobMeades 0:bb5fabac67ab 90 // ----------------------------------------------------------------
RobMeades 0:bb5fabac67ab 91 // TESTS
RobMeades 0:bb5fabac67ab 92 // ----------------------------------------------------------------
RobMeades 0:bb5fabac67ab 93
RobMeades 0:bb5fabac67ab 94 // Initialise the module
RobMeades 0:bb5fabac67ab 95 void test_start() {
RobMeades 0:bb5fabac67ab 96 TEST_ASSERT(pDriver->init(MBED_CONF_APP_DEFAULT_PIN));
RobMeades 0:bb5fabac67ab 97 }
RobMeades 0:bb5fabac67ab 98
RobMeades 0:bb5fabac67ab 99 // Write a file to the module's file system with known contents
RobMeades 0:bb5fabac67ab 100 void test_write() {
RobMeades 0:bb5fabac67ab 101
rob.meades@u-blox.com 5:b935404dcf7c 102 for (unsigned int x = 0; x < sizeof (buf); x++) {
RobMeades 0:bb5fabac67ab 103 buf[x] = (char) x;
RobMeades 0:bb5fabac67ab 104 }
RobMeades 0:bb5fabac67ab 105
RobMeades 0:bb5fabac67ab 106 TEST_ASSERT(pDriver->writeFile(MBED_CONF_APP_FILE_NAME, buf, sizeof (buf)) == sizeof (buf));
rob.meades@u-blox.com 5:b935404dcf7c 107 TEST_ASSERT(pDriver->fileSize(MBED_CONF_APP_FILE_NAME) >= (int) sizeof (buf));
RobMeades 0:bb5fabac67ab 108 tr_debug("%d bytes written to file \"%s\"", sizeof (buf), MBED_CONF_APP_FILE_NAME);
RobMeades 0:bb5fabac67ab 109 }
RobMeades 0:bb5fabac67ab 110
RobMeades 0:bb5fabac67ab 111 // Read a file back from the module's file system and check the contents
RobMeades 0:bb5fabac67ab 112 void test_read() {
RobMeades 0:bb5fabac67ab 113 memset(buf, 0, sizeof (buf));
RobMeades 0:bb5fabac67ab 114
RobMeades 0:bb5fabac67ab 115 TEST_ASSERT(pDriver->readFile(MBED_CONF_APP_FILE_NAME, buf, sizeof (buf)) == sizeof (buf));
RobMeades 0:bb5fabac67ab 116
RobMeades 0:bb5fabac67ab 117 tr_debug("%d bytes read from file \"%s\"", sizeof (buf), MBED_CONF_APP_FILE_NAME);
RobMeades 0:bb5fabac67ab 118
rob.meades@u-blox.com 5:b935404dcf7c 119 for (unsigned int x = 0; x < sizeof (buf); x++) {
RobMeades 0:bb5fabac67ab 120 TEST_ASSERT(buf[x] == (char) x);
RobMeades 0:bb5fabac67ab 121 }
RobMeades 0:bb5fabac67ab 122 }
RobMeades 0:bb5fabac67ab 123
RobMeades 0:bb5fabac67ab 124 // Delete a file from the module's file system
RobMeades 0:bb5fabac67ab 125 void test_delete() {
RobMeades 0:bb5fabac67ab 126 TEST_ASSERT(pDriver->delFile(MBED_CONF_APP_FILE_NAME));
RobMeades 0:bb5fabac67ab 127 tr_debug("File \"%s\" deleted", MBED_CONF_APP_FILE_NAME);
RobMeades 0:bb5fabac67ab 128 }
RobMeades 0:bb5fabac67ab 129
RobMeades 0:bb5fabac67ab 130 // ----------------------------------------------------------------
RobMeades 0:bb5fabac67ab 131 // TEST ENVIRONMENT
RobMeades 0:bb5fabac67ab 132 // ----------------------------------------------------------------
RobMeades 0:bb5fabac67ab 133
RobMeades 0:bb5fabac67ab 134 // Setup the test environment
RobMeades 0:bb5fabac67ab 135 utest::v1::status_t test_setup(const size_t number_of_cases) {
RobMeades 0:bb5fabac67ab 136 // Setup Greentea with a timeout
RobMeades 0:bb5fabac67ab 137 GREENTEA_SETUP(180, "default_auto");
RobMeades 0:bb5fabac67ab 138 return verbose_test_setup_handler(number_of_cases);
RobMeades 0:bb5fabac67ab 139 }
RobMeades 0:bb5fabac67ab 140
RobMeades 0:bb5fabac67ab 141 // Test cases
RobMeades 0:bb5fabac67ab 142 Case cases[] = {
RobMeades 0:bb5fabac67ab 143 Case("Start", test_start),
RobMeades 0:bb5fabac67ab 144 Case("Write file", test_write),
RobMeades 0:bb5fabac67ab 145 Case("Read file", test_read),
RobMeades 0:bb5fabac67ab 146 Case("Delete file", test_delete)
RobMeades 0:bb5fabac67ab 147 };
RobMeades 0:bb5fabac67ab 148
RobMeades 0:bb5fabac67ab 149 Specification specification(test_setup, cases);
RobMeades 0:bb5fabac67ab 150
RobMeades 0:bb5fabac67ab 151 // ----------------------------------------------------------------
RobMeades 0:bb5fabac67ab 152 // MAIN
RobMeades 0:bb5fabac67ab 153 // ----------------------------------------------------------------
RobMeades 0:bb5fabac67ab 154
RobMeades 0:bb5fabac67ab 155 int main() {
rob.meades@u-blox.com 3:027c9eaec52c 156
rob.meades@u-blox.com 3:027c9eaec52c 157 #ifdef FEATURE_COMMON_PAL
RobMeades 0:bb5fabac67ab 158 mbed_trace_init();
RobMeades 0:bb5fabac67ab 159
RobMeades 0:bb5fabac67ab 160 mbed_trace_mutex_wait_function_set(lock);
RobMeades 0:bb5fabac67ab 161 mbed_trace_mutex_release_function_set(unlock);
rob.meades@u-blox.com 3:027c9eaec52c 162 #endif
RobMeades 0:bb5fabac67ab 163
RobMeades 0:bb5fabac67ab 164 // Run tests
RobMeades 0:bb5fabac67ab 165 return !Harness::run(specification);
RobMeades 0:bb5fabac67ab 166 }
RobMeades 0:bb5fabac67ab 167
RobMeades 0:bb5fabac67ab 168 // End Of File
RobMeades 0:bb5fabac67ab 169