Skip to content

Commit 206cab9

Browse files
author
Cruz Monrreal
authored
Merge pull request #6965 from mirelachirica/fix_unittests
Cellular: Unit tests fixes
2 parents fe43377 + 853c4c6 commit 206cab9

File tree

17 files changed

+193
-28
lines changed

17 files changed

+193
-28
lines changed

features/cellular/UNITTESTS/at/athandler/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ TEST_SRC_FILES = \
2121
../../stubs/Timer_stub.cpp \
2222
../../stubs/equeue_stub.cpp \
2323
../../stubs/Kernel.cpp \
24+
../../stubs/Thread_stub.cpp \
2425

2526
include ../../MakefileWorker.mk
2627

features/cellular/UNITTESTS/at/athandler/test_athandler.cpp

Lines changed: 47 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,9 @@ void Test_ATHandler::test_ATHandler_read_bytes()
479479
char table[] = "ssssssssssssssssssssssssssssOK\r\n\0";
480480
filehandle_stub_table = table;
481481
filehandle_stub_table_pos = 0;
482+
mbed_poll_stub::revents_value = POLLIN;
483+
mbed_poll_stub::int_value = strlen(table);
484+
482485

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

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

497+
at.clear_error();
494498
char table[] = "\"s,\"OK\r\n\0";
495499
filehandle_stub_table = table;
496500
filehandle_stub_table_pos = 0;
501+
mbed_poll_stub::revents_value = POLLIN;
502+
mbed_poll_stub::int_value = strlen(table);
497503

498504
char buf[5];
499505
uint8_t buf2[5];
500-
at.flush();
501-
at.clear_error();
502506
at.resp_start();
503507
at.read_bytes(buf2, 5);
504508
CHECK(-1 == at.read_string(buf, 15));
509+
at.flush();
510+
at.clear_error();
505511

506512
filehandle_stub_table = table;
507513
filehandle_stub_table_pos = 0;
508514

509-
at.flush();
510-
at.clear_error();
511515
at.resp_start();
512516
at.read_bytes(buf2, 1);
513517
CHECK(1 == at.read_string(buf, 5, true));
518+
at.flush();
519+
at.clear_error();
514520

515521
char table2[] = "\"s\"OK\r\n\0";
516522
filehandle_stub_table = table2;
517523
filehandle_stub_table_pos = 0;
524+
mbed_poll_stub::revents_value = POLLIN;
525+
mbed_poll_stub::int_value = strlen(table2);
518526

519-
at.flush();
520-
at.clear_error();
521527
at.resp_start();
522528
at.read_bytes(buf2, 1);
523529
CHECK(1 == at.read_string(buf, 5, true));
530+
at.flush();
531+
at.clear_error();
524532

525533
char table3[] = "sss\rsss\0";
526534
filehandle_stub_table = table3;
527535
filehandle_stub_table_pos = 0;
536+
mbed_poll_stub::revents_value = POLLIN;
537+
mbed_poll_stub::int_value = strlen(table);
528538

529-
at.flush();
530-
at.clear_error();
531539
at.resp_start("s");
532540
at.read_string(buf, 5, true);
541+
at.flush();
542+
at.clear_error();
533543

534544
char table4[] = "\"s\"\0";
535545
filehandle_stub_table = table4;
536546
filehandle_stub_table_pos = 0;
547+
mbed_poll_stub::revents_value = POLLIN;
548+
mbed_poll_stub::int_value = strlen(table);
537549

538-
at.flush();
539-
at.clear_error();
540550
at.resp_start("s");
541551
at.read_string(buf, 5, true);
542552

543553
filehandle_stub_table = NULL;
544554
filehandle_stub_table_pos = 0;
555+
mbed_poll_stub::revents_value = POLLOUT;
556+
mbed_poll_stub::int_value = 0;
545557
}
546558

547559
void Test_ATHandler::test_ATHandler_read_int()
@@ -553,24 +565,27 @@ void Test_ATHandler::test_ATHandler_read_int()
553565

554566
int32_t ret= at.read_int();
555567
CHECK(-1 == ret);
568+
at.clear_error();
556569

557570
char table[] = "\",\"OK\r\n\0";
558571
filehandle_stub_table = table;
559572
filehandle_stub_table_pos = 0;
573+
mbed_poll_stub::revents_value = POLLIN;
574+
mbed_poll_stub::int_value = strlen(table);
560575

561-
at.flush();
562-
at.clear_error();
563576
at.resp_start();
564577

565578
ret= at.read_int();
566579
CHECK(-1 == ret);
580+
at.flush();
581+
at.clear_error();
567582

568583
char table2[] = "\"2,\"OK\r\n\0";
569584
filehandle_stub_table = table2;
570585
filehandle_stub_table_pos = 0;
586+
mbed_poll_stub::revents_value = POLLIN;
587+
mbed_poll_stub::int_value = strlen(table2);
571588

572-
at.flush();
573-
at.clear_error();
574589
at.resp_start();
575590

576591
ret= at.read_int();
@@ -694,23 +709,29 @@ void Test_ATHandler::test_ATHandler_info_resp()
694709
at.resp_start();
695710
CHECK(!at.info_resp());
696711

712+
at.flush();
713+
at.clear_error();
714+
697715
char table2[] = "21 OK\r\n\0";
698716
filehandle_stub_table = table2;
699717
filehandle_stub_table_pos = 0;
718+
mbed_poll_stub::revents_value = POLLIN;
719+
mbed_poll_stub::int_value = strlen(table2);
700720

701-
at.flush();
702-
at.clear_error();
703721
at.resp_start("21");
704722
CHECK(at.info_resp());
705723

706724
CHECK(!at.info_resp());
707725

726+
at.flush();
727+
at.clear_error();
728+
708729
char table3[] = "21 OK\r\n\0";
709730
filehandle_stub_table = table3;
710731
filehandle_stub_table_pos = 0;
732+
mbed_poll_stub::revents_value = POLLIN;
733+
mbed_poll_stub::int_value = strlen(table3);
711734

712-
at.flush();
713-
at.clear_error();
714735
CHECK(at.info_resp());
715736
}
716737

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

726749
ATHandler at(&fh1, que, 0, ",");
727-
CHECK(!at.info_elem(char(79)));
750+
CHECK(!at.info_elem('O'));
751+
at.flush();
728752

729753
char table2[] = "21 OK\r\n\0";
730754
filehandle_stub_table = table2;
731755
filehandle_stub_table_pos = 0;
756+
mbed_poll_stub::revents_value = POLLIN;
757+
mbed_poll_stub::int_value = strlen(table2);
732758

733-
at.flush();
734759
at.clear_error();
735760
at.resp_start("21");
736-
CHECK(at.info_elem(char(79)));
737-
738-
CHECK(at.info_elem('2'));
761+
CHECK(at.info_elem('O'));
762+
at.flush();
739763

740764
filehandle_stub_table = NULL;
741765
filehandle_stub_table_pos = 0;
742766

743-
at.flush();
744767
at.clear_error();
745768
at.resp_start("21");
746769
CHECK(!at.info_elem('2'));

features/cellular/UNITTESTS/stubs/ATHandler_stub.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ nsapi_error_t ATHandler::set_urc_handler(const char *urc, mbed::Callback<void()>
8585
return NSAPI_ERROR_OK;
8686
}
8787

88+
void ATHandler::remove_urc_handler(const char *prefix, mbed::Callback<void()> callback)
89+
{
90+
}
91+
8892
nsapi_error_t ATHandler::get_last_error() const
8993
{
9094
if (ATHandler_stub::nsapi_error_ok_counter) {

features/cellular/UNITTESTS/stubs/SocketAddress_stub.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,14 @@ const void *SocketAddress::get_ip_bytes() const
102102

103103
nsapi_version_t SocketAddress::get_ip_version() const
104104
{
105-
nsapi_version_t ver;
105+
nsapi_version_t ver = NSAPI_IPv6;
106106
return ver;
107107
}
108108

109109
nsapi_addr_t SocketAddress::get_addr() const
110110
{
111111
nsapi_addr_t addr;
112+
addr.version = NSAPI_IPv6;
112113
return _addr;
113114
}
114115

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright (c) , Arm Limited and affiliates.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#include "Thread.h"
19+
20+
namespace rtos {
21+
22+
osStatus Thread::wait_until(uint64_t millisec) {
23+
return 0;
24+
}
25+
26+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright (c) , Arm Limited and affiliates.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#ifndef CMSIS_OS_H_
19+
#define CMSIS_OS_H_
20+
21+
#include "cmsis_os2.h"
22+
23+
#define osPriority osPriority_t
24+
25+
#define osThreadId osThreadId_t
26+
27+
typedef struct {
28+
} osEvent;
29+
30+
#endif

features/cellular/UNITTESTS/target_h/cmsis_os2.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,17 @@ typedef struct {
3535
uint32_t cb_size; ///< size of provided memory for control block
3636
} osSemaphoreAttr_t;
3737

38+
//Thread
39+
typedef enum {
40+
osPriorityNormal = 24 ///< Priority: normal
41+
} osPriority_t;
42+
43+
typedef void *osThreadId_t;
44+
45+
/// Attributes structure for thread.
46+
typedef struct {
47+
} osThreadAttr_t;
48+
3849
#define osWaitForever 0xFFFFFFFFU
3950

4051

features/cellular/UNITTESTS/target_h/mbed_rtos1_types.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,5 @@
1414
* See the License for the specific language governing permissions and
1515
* limitations under the License.
1616
*/
17+
18+
#include "cmsis_os.h"

features/cellular/UNITTESTS/target_h/mbed_rtos_storage.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,7 @@
1818
#include "cmsis_os2.h"
1919
#include "rtx_os.h"
2020
#include "rtx_lib.h"
21+
#include "mbed_rtx_conf.h"
2122

2223
typedef os_semaphore_t mbed_rtos_storage_semaphore_t;
24+
typedef os_thread_t mbed_rtos_storage_thread_t;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* Copyright (c) , Arm Limited and affiliates.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#define OS_STACK_SIZE 0

features/cellular/UNITTESTS/target_h/platform/mbed_retarget.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,6 @@
1515
* limitations under the License.
1616
*/
1717

18+
#include <sys/types.h>
1819
#define EAGAIN 11
20+
#define ENOTTY 25

features/cellular/UNITTESTS/target_h/mbed_retarget.h renamed to features/cellular/UNITTESTS/target_h/rtos/Mutex.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@
1515
* limitations under the License.
1616
*/
1717

18-
#define EAGAIN 11
18+
typedef void* Mutex;
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* Copyright (c) , Arm Limited and affiliates.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
typedef void* Semaphore;

features/cellular/UNITTESTS/target_h/rtx_lib.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,6 @@
2020
#include "rtx_os.h"
2121

2222
#define os_semaphore_t osRtxSemaphore_t
23+
#define os_thread_t osRtxThread_t
2324

2425
#endif

0 commit comments

Comments
 (0)