Cellular: Unit tests fixes

pull/6965/head
Mirela Chirica 2018-05-21 16:43:37 +03:00
parent 3bcc076c0c
commit b59ef26930
17 changed files with 124 additions and 28 deletions

View File

@ -21,6 +21,7 @@ TEST_SRC_FILES = \
../../stubs/Timer_stub.cpp \ ../../stubs/Timer_stub.cpp \
../../stubs/equeue_stub.cpp \ ../../stubs/equeue_stub.cpp \
../../stubs/Kernel.cpp \ ../../stubs/Kernel.cpp \
../../stubs/Thread_stub.cpp \
include ../../MakefileWorker.mk include ../../MakefileWorker.mk

View File

@ -479,6 +479,9 @@ void Test_ATHandler::test_ATHandler_read_bytes()
char table[] = "ssssssssssssssssssssssssssssOK\r\n\0"; char table[] = "ssssssssssssssssssssssssssssOK\r\n\0";
filehandle_stub_table = table; filehandle_stub_table = table;
filehandle_stub_table_pos = 0; filehandle_stub_table_pos = 0;
mbed_poll_stub::revents_value = POLLIN;
mbed_poll_stub::int_value = strlen(table);
at.clear_error(); at.clear_error();
CHECK(5 == at.read_bytes(buf, 5)); CHECK(5 == at.read_bytes(buf, 5));
@ -491,57 +494,66 @@ void Test_ATHandler::test_ATHandler_read_string()
ATHandler at(&fh1, que, 0, ","); ATHandler at(&fh1, que, 0, ",");
at.clear_error();
char table[] = "\"s,\"OK\r\n\0"; char table[] = "\"s,\"OK\r\n\0";
filehandle_stub_table = table; filehandle_stub_table = table;
filehandle_stub_table_pos = 0; filehandle_stub_table_pos = 0;
mbed_poll_stub::revents_value = POLLIN;
mbed_poll_stub::int_value = strlen(table);
char buf[5]; char buf[5];
uint8_t buf2[5]; uint8_t buf2[5];
at.flush();
at.clear_error();
at.resp_start(); at.resp_start();
at.read_bytes(buf2, 5); at.read_bytes(buf2, 5);
CHECK(-1 == at.read_string(buf, 15)); CHECK(-1 == at.read_string(buf, 15));
at.flush();
at.clear_error();
filehandle_stub_table = table; filehandle_stub_table = table;
filehandle_stub_table_pos = 0; filehandle_stub_table_pos = 0;
at.flush();
at.clear_error();
at.resp_start(); at.resp_start();
at.read_bytes(buf2, 1); at.read_bytes(buf2, 1);
CHECK(1 == at.read_string(buf, 5, true)); CHECK(1 == at.read_string(buf, 5, true));
at.flush();
at.clear_error();
char table2[] = "\"s\"OK\r\n\0"; char table2[] = "\"s\"OK\r\n\0";
filehandle_stub_table = table2; filehandle_stub_table = table2;
filehandle_stub_table_pos = 0; filehandle_stub_table_pos = 0;
mbed_poll_stub::revents_value = POLLIN;
mbed_poll_stub::int_value = strlen(table2);
at.flush();
at.clear_error();
at.resp_start(); at.resp_start();
at.read_bytes(buf2, 1); at.read_bytes(buf2, 1);
CHECK(1 == at.read_string(buf, 5, true)); CHECK(1 == at.read_string(buf, 5, true));
at.flush();
at.clear_error();
char table3[] = "sss\rsss\0"; char table3[] = "sss\rsss\0";
filehandle_stub_table = table3; filehandle_stub_table = table3;
filehandle_stub_table_pos = 0; filehandle_stub_table_pos = 0;
mbed_poll_stub::revents_value = POLLIN;
mbed_poll_stub::int_value = strlen(table);
at.flush();
at.clear_error();
at.resp_start("s"); at.resp_start("s");
at.read_string(buf, 5, true); at.read_string(buf, 5, true);
at.flush();
at.clear_error();
char table4[] = "\"s\"\0"; char table4[] = "\"s\"\0";
filehandle_stub_table = table4; filehandle_stub_table = table4;
filehandle_stub_table_pos = 0; filehandle_stub_table_pos = 0;
mbed_poll_stub::revents_value = POLLIN;
mbed_poll_stub::int_value = strlen(table);
at.flush();
at.clear_error();
at.resp_start("s"); at.resp_start("s");
at.read_string(buf, 5, true); at.read_string(buf, 5, true);
filehandle_stub_table = NULL; filehandle_stub_table = NULL;
filehandle_stub_table_pos = 0; filehandle_stub_table_pos = 0;
mbed_poll_stub::revents_value = POLLOUT;
mbed_poll_stub::int_value = 0;
} }
void Test_ATHandler::test_ATHandler_read_int() void Test_ATHandler::test_ATHandler_read_int()
@ -553,24 +565,27 @@ void Test_ATHandler::test_ATHandler_read_int()
int32_t ret= at.read_int(); int32_t ret= at.read_int();
CHECK(-1 == ret); CHECK(-1 == ret);
at.clear_error();
char table[] = "\",\"OK\r\n\0"; char table[] = "\",\"OK\r\n\0";
filehandle_stub_table = table; filehandle_stub_table = table;
filehandle_stub_table_pos = 0; filehandle_stub_table_pos = 0;
mbed_poll_stub::revents_value = POLLIN;
mbed_poll_stub::int_value = strlen(table);
at.flush();
at.clear_error();
at.resp_start(); at.resp_start();
ret= at.read_int(); ret= at.read_int();
CHECK(-1 == ret); CHECK(-1 == ret);
at.flush();
at.clear_error();
char table2[] = "\"2,\"OK\r\n\0"; char table2[] = "\"2,\"OK\r\n\0";
filehandle_stub_table = table2; filehandle_stub_table = table2;
filehandle_stub_table_pos = 0; filehandle_stub_table_pos = 0;
mbed_poll_stub::revents_value = POLLIN;
mbed_poll_stub::int_value = strlen(table2);
at.flush();
at.clear_error();
at.resp_start(); at.resp_start();
ret= at.read_int(); ret= at.read_int();
@ -694,23 +709,29 @@ void Test_ATHandler::test_ATHandler_info_resp()
at.resp_start(); at.resp_start();
CHECK(!at.info_resp()); CHECK(!at.info_resp());
at.flush();
at.clear_error();
char table2[] = "21 OK\r\n\0"; char table2[] = "21 OK\r\n\0";
filehandle_stub_table = table2; filehandle_stub_table = table2;
filehandle_stub_table_pos = 0; filehandle_stub_table_pos = 0;
mbed_poll_stub::revents_value = POLLIN;
mbed_poll_stub::int_value = strlen(table2);
at.flush();
at.clear_error();
at.resp_start("21"); at.resp_start("21");
CHECK(at.info_resp()); CHECK(at.info_resp());
CHECK(!at.info_resp()); CHECK(!at.info_resp());
at.flush();
at.clear_error();
char table3[] = "21 OK\r\n\0"; char table3[] = "21 OK\r\n\0";
filehandle_stub_table = table3; filehandle_stub_table = table3;
filehandle_stub_table_pos = 0; filehandle_stub_table_pos = 0;
mbed_poll_stub::revents_value = POLLIN;
mbed_poll_stub::int_value = strlen(table3);
at.flush();
at.clear_error();
CHECK(at.info_resp()); CHECK(at.info_resp());
} }
@ -722,25 +743,27 @@ void Test_ATHandler::test_ATHandler_info_elem()
char table[] = "21 OK\r\n\0"; char table[] = "21 OK\r\n\0";
filehandle_stub_table = table; filehandle_stub_table = table;
filehandle_stub_table_pos = 0; filehandle_stub_table_pos = 0;
mbed_poll_stub::revents_value = POLLIN;
mbed_poll_stub::int_value = strlen(table);
ATHandler at(&fh1, que, 0, ","); ATHandler at(&fh1, que, 0, ",");
CHECK(!at.info_elem(char(79))); CHECK(!at.info_elem('O'));
at.flush();
char table2[] = "21 OK\r\n\0"; char table2[] = "21 OK\r\n\0";
filehandle_stub_table = table2; filehandle_stub_table = table2;
filehandle_stub_table_pos = 0; filehandle_stub_table_pos = 0;
mbed_poll_stub::revents_value = POLLIN;
mbed_poll_stub::int_value = strlen(table2);
at.flush();
at.clear_error(); at.clear_error();
at.resp_start("21"); at.resp_start("21");
CHECK(at.info_elem(char(79))); CHECK(at.info_elem('O'));
at.flush();
CHECK(at.info_elem('2'));
filehandle_stub_table = NULL; filehandle_stub_table = NULL;
filehandle_stub_table_pos = 0; filehandle_stub_table_pos = 0;
at.flush();
at.clear_error(); at.clear_error();
at.resp_start("21"); at.resp_start("21");
CHECK(!at.info_elem('2')); CHECK(!at.info_elem('2'));

View File

@ -85,6 +85,10 @@ nsapi_error_t ATHandler::set_urc_handler(const char *urc, mbed::Callback<void()>
return NSAPI_ERROR_OK; return NSAPI_ERROR_OK;
} }
void ATHandler::remove_urc_handler(const char *prefix, mbed::Callback<void()> callback)
{
}
nsapi_error_t ATHandler::get_last_error() const nsapi_error_t ATHandler::get_last_error() const
{ {
if (ATHandler_stub::nsapi_error_ok_counter) { if (ATHandler_stub::nsapi_error_ok_counter) {

View File

@ -102,13 +102,14 @@ const void *SocketAddress::get_ip_bytes() const
nsapi_version_t SocketAddress::get_ip_version() const nsapi_version_t SocketAddress::get_ip_version() const
{ {
nsapi_version_t ver; nsapi_version_t ver = NSAPI_IPv6;
return ver; return ver;
} }
nsapi_addr_t SocketAddress::get_addr() const nsapi_addr_t SocketAddress::get_addr() const
{ {
nsapi_addr_t addr; nsapi_addr_t addr;
addr.version = NSAPI_IPv6;
return _addr; return _addr;
} }

View File

@ -15,4 +15,12 @@
* limitations under the License. * limitations under the License.
*/ */
#define EAGAIN 11 #include "Thread.h"
namespace rtos {
osStatus Thread::wait_until(uint64_t millisec) {
return 0;
}
}

View File

@ -0,0 +1,13 @@
#ifndef CMSIS_OS_H_
#define CMSIS_OS_H_
#include "cmsis_os2.h"
#define osPriority osPriority_t
#define osThreadId osThreadId_t
typedef struct {
} osEvent;
#endif

View File

@ -35,6 +35,17 @@ typedef struct {
uint32_t cb_size; ///< size of provided memory for control block uint32_t cb_size; ///< size of provided memory for control block
} osSemaphoreAttr_t; } osSemaphoreAttr_t;
//Thread
typedef enum {
osPriorityNormal = 24 ///< Priority: normal
} osPriority_t;
typedef void *osThreadId_t;
/// Attributes structure for thread.
typedef struct {
} osThreadAttr_t;
#define osWaitForever 0xFFFFFFFFU #define osWaitForever 0xFFFFFFFFU

View File

@ -14,3 +14,5 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
#include "cmsis_os.h"

View File

@ -18,5 +18,7 @@
#include "cmsis_os2.h" #include "cmsis_os2.h"
#include "rtx_os.h" #include "rtx_os.h"
#include "rtx_lib.h" #include "rtx_lib.h"
#include "mbed_rtx_conf.h"
typedef os_semaphore_t mbed_rtos_storage_semaphore_t; typedef os_semaphore_t mbed_rtos_storage_semaphore_t;
typedef os_thread_t mbed_rtos_storage_thread_t;

View File

@ -0,0 +1 @@
#define OS_STACK_SIZE 0

View File

@ -15,4 +15,5 @@
* limitations under the License. * limitations under the License.
*/ */
#include <sys/types.h>
#define EAGAIN 11 #define EAGAIN 11

View File

@ -0,0 +1 @@
typedef void* Mutex;

View File

@ -0,0 +1 @@
typedef void* Semaphore;

View File

@ -20,5 +20,6 @@
#include "rtx_os.h" #include "rtx_os.h"
#define os_semaphore_t osRtxSemaphore_t #define os_semaphore_t osRtxSemaphore_t
#define os_thread_t osRtxThread_t
#endif #endif

View File

@ -30,4 +30,31 @@ typedef struct osRtxSemaphore_s {
uint16_t max_tokens; ///< Maximum number of tokens uint16_t max_tokens; ///< Maximum number of tokens
} osRtxSemaphore_t; } osRtxSemaphore_t;
typedef struct osRtxThread_s {
uint8_t id; ///< Object Identifier
uint8_t state; ///< Object State
uint8_t flags; ///< Object Flags
uint8_t attr; ///< Object Attributes
const char *name; ///< Object Name
struct osRtxThread_s *thread_next; ///< Link pointer to next Thread in Object list
struct osRtxThread_s *thread_prev; ///< Link pointer to previous Thread in Object list
struct osRtxThread_s *delay_next; ///< Link pointer to next Thread in Delay list
struct osRtxThread_s *delay_prev; ///< Link pointer to previous Thread in Delay list
struct osRtxThread_s *thread_join; ///< Thread waiting to Join
uint32_t delay; ///< Delay Time
int8_t priority; ///< Thread Priority
int8_t priority_base; ///< Base Priority
uint8_t stack_frame; ///< Stack Frame (EXC_RETURN[7..0])
uint8_t flags_options; ///< Thread/Event Flags Options
uint32_t wait_flags; ///< Waiting Thread/Event Flags
uint32_t thread_flags; ///< Thread Flags
struct osRtxMutex_s *mutex_list; ///< Link pointer to list of owned Mutexes
void *stack_mem; ///< Stack Memory
uint32_t stack_size; ///< Stack Size
uint32_t sp; ///< Current Stack Pointer
uint32_t thread_addr; ///< Thread entry address
uint32_t tz_memory; ///< TrustZone Memory Identifier
void *context; ///< Context for OsEventObserver objects
} osRtxThread_t;
#endif #endif

View File

@ -23,9 +23,7 @@
#include "FileHandle.h" #include "FileHandle.h"
#include "mbed_wait_api.h" #include "mbed_wait_api.h"
#include "mbed_debug.h" #include "mbed_debug.h"
#ifdef MBED_CONF_RTOS_PRESENT
#include "rtos/Thread.h" #include "rtos/Thread.h"
#endif
#include "Kernel.h" #include "Kernel.h"
#include "CellularUtil.h" #include "CellularUtil.h"

View File

@ -17,6 +17,7 @@
#include <time.h> #include <time.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h>
#include "mbed_wait_api.h" #include "mbed_wait_api.h"
#include "AT_CellularSMS.h" #include "AT_CellularSMS.h"
#include "CellularUtil.h" #include "CellularUtil.h"