Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cellular: Unit tests fixes #6965

Merged
merged 3 commits into from
May 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions features/cellular/UNITTESTS/at/athandler/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ TEST_SRC_FILES = \
../../stubs/Timer_stub.cpp \
../../stubs/equeue_stub.cpp \
../../stubs/Kernel.cpp \
../../stubs/Thread_stub.cpp \

include ../../MakefileWorker.mk

Expand Down
71 changes: 47 additions & 24 deletions features/cellular/UNITTESTS/at/athandler/test_athandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,9 @@ void Test_ATHandler::test_ATHandler_read_bytes()
char table[] = "ssssssssssssssssssssssssssssOK\r\n\0";
filehandle_stub_table = table;
filehandle_stub_table_pos = 0;
mbed_poll_stub::revents_value = POLLIN;
mbed_poll_stub::int_value = strlen(table);


at.clear_error();
CHECK(5 == at.read_bytes(buf, 5));
Expand All @@ -491,57 +494,66 @@ void Test_ATHandler::test_ATHandler_read_string()

ATHandler at(&fh1, que, 0, ",");

at.clear_error();
char table[] = "\"s,\"OK\r\n\0";
filehandle_stub_table = table;
filehandle_stub_table_pos = 0;
mbed_poll_stub::revents_value = POLLIN;
mbed_poll_stub::int_value = strlen(table);

char buf[5];
uint8_t buf2[5];
at.flush();
at.clear_error();
at.resp_start();
at.read_bytes(buf2, 5);
CHECK(-1 == at.read_string(buf, 15));
at.flush();
at.clear_error();

filehandle_stub_table = table;
filehandle_stub_table_pos = 0;

at.flush();
at.clear_error();
at.resp_start();
at.read_bytes(buf2, 1);
CHECK(1 == at.read_string(buf, 5, true));
at.flush();
at.clear_error();

char table2[] = "\"s\"OK\r\n\0";
filehandle_stub_table = table2;
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.read_bytes(buf2, 1);
CHECK(1 == at.read_string(buf, 5, true));
at.flush();
at.clear_error();

char table3[] = "sss\rsss\0";
filehandle_stub_table = table3;
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.read_string(buf, 5, true);
at.flush();
at.clear_error();

char table4[] = "\"s\"\0";
filehandle_stub_table = table4;
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.read_string(buf, 5, true);

filehandle_stub_table = NULL;
filehandle_stub_table_pos = 0;
mbed_poll_stub::revents_value = POLLOUT;
mbed_poll_stub::int_value = 0;
}

void Test_ATHandler::test_ATHandler_read_int()
Expand All @@ -553,24 +565,27 @@ void Test_ATHandler::test_ATHandler_read_int()

int32_t ret= at.read_int();
CHECK(-1 == ret);
at.clear_error();

char table[] = "\",\"OK\r\n\0";
filehandle_stub_table = table;
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();

ret= at.read_int();
CHECK(-1 == ret);
at.flush();
at.clear_error();

char table2[] = "\"2,\"OK\r\n\0";
filehandle_stub_table = table2;
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();

ret= at.read_int();
Expand Down Expand Up @@ -694,23 +709,29 @@ void Test_ATHandler::test_ATHandler_info_resp()
at.resp_start();
CHECK(!at.info_resp());

at.flush();
at.clear_error();

char table2[] = "21 OK\r\n\0";
filehandle_stub_table = table2;
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");
CHECK(at.info_resp());

CHECK(!at.info_resp());

at.flush();
at.clear_error();

char table3[] = "21 OK\r\n\0";
filehandle_stub_table = table3;
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());
}

Expand All @@ -722,25 +743,27 @@ void Test_ATHandler::test_ATHandler_info_elem()
char table[] = "21 OK\r\n\0";
filehandle_stub_table = table;
filehandle_stub_table_pos = 0;
mbed_poll_stub::revents_value = POLLIN;
mbed_poll_stub::int_value = strlen(table);

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";
filehandle_stub_table = table2;
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");
CHECK(at.info_elem(char(79)));

CHECK(at.info_elem('2'));
CHECK(at.info_elem('O'));
at.flush();

filehandle_stub_table = NULL;
filehandle_stub_table_pos = 0;

at.flush();
at.clear_error();
at.resp_start("21");
CHECK(!at.info_elem('2'));
Expand Down
4 changes: 4 additions & 0 deletions features/cellular/UNITTESTS/stubs/ATHandler_stub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ nsapi_error_t ATHandler::set_urc_handler(const char *urc, mbed::Callback<void()>
return NSAPI_ERROR_OK;
}

void ATHandler::remove_urc_handler(const char *prefix, mbed::Callback<void()> callback)
{
}

nsapi_error_t ATHandler::get_last_error() const
{
if (ATHandler_stub::nsapi_error_ok_counter) {
Expand Down
3 changes: 2 additions & 1 deletion features/cellular/UNITTESTS/stubs/SocketAddress_stub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,14 @@ const void *SocketAddress::get_ip_bytes() const

nsapi_version_t SocketAddress::get_ip_version() const
{
nsapi_version_t ver;
nsapi_version_t ver = NSAPI_IPv6;
return ver;
}

nsapi_addr_t SocketAddress::get_addr() const
{
nsapi_addr_t addr;
addr.version = NSAPI_IPv6;
return _addr;
}

Expand Down
26 changes: 26 additions & 0 deletions features/cellular/UNITTESTS/stubs/Thread_stub.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright (c) , Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "Thread.h"

namespace rtos {

osStatus Thread::wait_until(uint64_t millisec) {
return 0;
}

}
30 changes: 30 additions & 0 deletions features/cellular/UNITTESTS/target_h/cmsis_os.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright (c) , Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef CMSIS_OS_H_
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing copyrights.

#define CMSIS_OS_H_

#include "cmsis_os2.h"

#define osPriority osPriority_t

#define osThreadId osThreadId_t

typedef struct {
} osEvent;

#endif
11 changes: 11 additions & 0 deletions features/cellular/UNITTESTS/target_h/cmsis_os2.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@ typedef struct {
uint32_t cb_size; ///< size of provided memory for control block
} 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


Expand Down
2 changes: 2 additions & 0 deletions features/cellular/UNITTESTS/target_h/mbed_rtos1_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "cmsis_os.h"
2 changes: 2 additions & 0 deletions features/cellular/UNITTESTS/target_h/mbed_rtos_storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,7 @@
#include "cmsis_os2.h"
#include "rtx_os.h"
#include "rtx_lib.h"
#include "mbed_rtx_conf.h"

typedef os_semaphore_t mbed_rtos_storage_semaphore_t;
typedef os_thread_t mbed_rtos_storage_thread_t;
18 changes: 18 additions & 0 deletions features/cellular/UNITTESTS/target_h/mbed_rtx_conf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright (c) , Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#define OS_STACK_SIZE 0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing copyrights.

2 changes: 2 additions & 0 deletions features/cellular/UNITTESTS/target_h/platform/mbed_retarget.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@
* limitations under the License.
*/

#include <sys/types.h>
#define EAGAIN 11
#define ENOTTY 25
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
* limitations under the License.
*/

#define EAGAIN 11
typedef void* Mutex;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing copyrights.

18 changes: 18 additions & 0 deletions features/cellular/UNITTESTS/target_h/rtos/Semaphore.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright (c) , Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

typedef void* Semaphore;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing copyrights.

1 change: 1 addition & 0 deletions features/cellular/UNITTESTS/target_h/rtx_lib.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@
#include "rtx_os.h"

#define os_semaphore_t osRtxSemaphore_t
#define os_thread_t osRtxThread_t

#endif
Loading