Skip to content

Commit 6b8292d

Browse files
authored
Merge branch 'master' into hk-deprecate-serial-class
2 parents 1dc9c09 + b1b0673 commit 6b8292d

File tree

34 files changed

+340
-169
lines changed

34 files changed

+340
-169
lines changed

TESTS/mbed_platform/SharedPtr/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ void test_single_sharedptr_lifetime()
6565
*/
6666
void test_instance_sharing()
6767
{
68-
SharedPtr<TestStruct> s_ptr1(NULL);
68+
SharedPtr<TestStruct> s_ptr1(nullptr);
6969

7070
// Sanity-check value of counter
7171
TEST_ASSERT_EQUAL(0, TestStruct::s_count);
@@ -80,7 +80,7 @@ void test_instance_sharing()
8080

8181
TEST_ASSERT_EQUAL(1, TestStruct::s_count);
8282

83-
s_ptr1 = NULL;
83+
s_ptr1 = nullptr;
8484

8585
// Destroy shared pointer
8686
TEST_ASSERT_EQUAL(0, TestStruct::s_count);

TESTS/mbed_platform/crash_reporting/main.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16-
#if !defined(MBED_CONF_RTOS_PRESENT)
17-
#error [NOT_SUPPORTED] crash_reporting test cases require a RTOS to run.
18-
#else
1916
#include "mbed.h"
2017
#include "mbed_error.h"
2118
#include "mbed_crash_data_offsets.h"
@@ -83,4 +80,3 @@ int main(void)
8380
}
8481

8582
#endif // !MBED_CONF_PLATFORM_CRASH_CAPTURE_ENABLED
86-
#endif // !defined(MBED_CONF_RTOS_PRESENT)

TESTS/mbedmicro-mbed/attributes/attributes.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,24 @@ int testNoReturn()
145145
}
146146

147147

148+
int testFallthrough1(int i)
149+
{
150+
switch (i) {
151+
case 1:
152+
case 2:
153+
i *= 2;
154+
MBED_FALLTHROUGH;
155+
default:
156+
return i;
157+
}
158+
}
159+
160+
int testFallthrough()
161+
{
162+
return testFallthrough1(0);
163+
}
164+
165+
148166
int testUnreachable1(int i)
149167
{
150168
switch (i) {

TESTS/mbedmicro-mbed/attributes/main.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ extern "C" {
3333
int testPure();
3434
int testForceInline();
3535
int testNoReturn();
36+
int testFallthrough();
3637
int testUnreachable();
3738
int testDeprecated();
3839
}
@@ -59,6 +60,7 @@ Case cases[] = {
5960
Case("Testing PURE attribute", test_wrapper<testPure>),
6061
Case("Testing FORCEINLINE attribute", test_wrapper<testForceInline>),
6162
Case("Testing NORETURN attribute", test_wrapper<testNoReturn>),
63+
Case("Testing FALLTHROUGH attribute", test_wrapper<testFallthrough>),
6264
Case("Testing UNREACHABLE attribute", test_wrapper<testUnreachable>),
6365
Case("Testing DEPRECATED attribute", test_wrapper<testDeprecated>),
6466
};

UNITTESTS/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,10 @@ if (COVERAGE)
8282

8383
endif(COVERAGE)
8484

85+
if (VALGRIND)
86+
find_program(MEMORYCHECK_COMMAND valgrind)
87+
endif(VALGRIND)
88+
8589
####################
8690
# UNIT TESTS
8791
####################
@@ -196,6 +200,7 @@ foreach(testfile ${unittest-file-list})
196200
if (unittest-test-sources)
197201
# Create the executable.
198202
add_executable(${TEST_SUITE_NAME} ${unittest-test-sources})
203+
199204
target_include_directories(${TEST_SUITE_NAME} PRIVATE
200205
${unittest-includes})
201206
target_compile_options(${TEST_SUITE_NAME} PRIVATE

UNITTESTS/MODULETESTS/features/netsocket/IfaceDnsSocket/test_IfaceDnsSocket.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ TEST_F(Test_IfaceDnsSocket, async_cancel)
499499

500500
TEST_F(Test_IfaceDnsSocket, add_server)
501501
{
502-
SocketAddress server_address("1.2.3.4", 8000);
502+
SocketAddress server_address("1.2.3.4", 53);
503503
EXPECT_EQ(NSAPI_ERROR_OK, nsapi_dns_add_server(server_address, NULL));
504504
EXPECT_EQ(NSAPI_ERROR_OK, nsapi_dns_add_server(server_address, NULL)); // Duplicate add - no error.
505505

@@ -533,7 +533,7 @@ TEST_F(Test_IfaceDnsSocket, attempts)
533533
SocketAddress known_server_address[DNS_SERVER_SIZE];
534534
for (uint8_t i = DNS_SERVER_SIZE; i > 0; i--) {
535535
uint8_t bytes[NSAPI_IPv4_SIZE] = {i, i, i, i};
536-
known_server_address[i - 1] = SocketAddress(bytes, NSAPI_IPv4);
536+
known_server_address[i - 1] = SocketAddress(bytes, NSAPI_IPv4, 53);
537537
EXPECT_EQ(NSAPI_ERROR_OK, nsapi_dns_add_server(known_server_address[i - 1], NULL));
538538
}
539539

@@ -573,7 +573,7 @@ TEST_F(Test_IfaceDnsSocket, retries_attempts)
573573
SocketAddress known_server_address[DNS_SERVER_SIZE];
574574
for (uint8_t i = DNS_SERVER_SIZE; i > 0; i--) {
575575
uint8_t bytes[NSAPI_IPv4_SIZE] = {i, i, i, i};
576-
known_server_address[i - 1] = SocketAddress(bytes, NSAPI_IPv4);
576+
known_server_address[i - 1] = SocketAddress(bytes, NSAPI_IPv4, 53);
577577
EXPECT_EQ(NSAPI_ERROR_OK, nsapi_dns_add_server(known_server_address[i - 1], NULL));
578578
}
579579

UNITTESTS/mbed_unittest.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,15 @@ def _mbed_unittest_test(options, cwd, pwd):
7676
tool.create_makefiles(path_to_src=src_path,
7777
generator=options.cmake_generator,
7878
coverage_output_type=options.coverage,
79-
debug=options.debug_build)
79+
debug=options.debug_build,
80+
valgrind=options.valgrind)
8081

8182
# Build tests
8283
tool.build_tests()
8384

8485
if options.run_only:
85-
tool.run_tests(filter_regex=options.test_regex)
86+
tool.run_tests(filter_regex=options.test_regex,
87+
valgrind=options.valgrind)
8688

8789
# If code coverage generation:
8890
if options.coverage:

UNITTESTS/moduletests/storage/blockdevice/SlicingBlockDevice/moduletest.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ TEST_F(SlicingBlockModuleTest, slice_in_middle)
120120
EXPECT_EQ(0, memcmp(buf, magic, BLOCK_SIZE));
121121
bd.read(buf, BLOCK_SIZE * 3, BLOCK_SIZE);
122122
EXPECT_EQ(0, memcmp(buf, magic, BLOCK_SIZE));
123+
124+
delete[] program;
123125
}
124126

125127
TEST_F(SlicingBlockModuleTest, slice_at_the_end)
@@ -143,6 +145,8 @@ TEST_F(SlicingBlockModuleTest, slice_at_the_end)
143145
//Verify that blocks before and after the slicing blocks are not touched
144146
bd.read(buf, BLOCK_SIZE * 7, BLOCK_SIZE);
145147
EXPECT_EQ(0, memcmp(buf, magic, BLOCK_SIZE));
148+
149+
delete[] program;
146150
}
147151

148152
TEST_F(SlicingBlockModuleTest, over_write)
@@ -163,6 +167,8 @@ TEST_F(SlicingBlockModuleTest, over_write)
163167

164168
//Program a test value to address that is one pass the device size
165169
EXPECT_EQ(slice.program(program, 2 * BLOCK_SIZE, BLOCK_SIZE), BD_ERROR_DEVICE_ERROR);
170+
171+
delete[] buf;
166172
delete[] program;
167173
}
168174

UNITTESTS/unit_test/get_tools.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,13 @@ def get_cmake_tool():
5353

5454
return _get_program(["cmake"])
5555

56+
def get_valgrind_tool():
57+
"""
58+
Get Valgrind program
59+
"""
60+
61+
return _get_program(["valgrind"])
62+
5663
def get_cxx_tool():
5764
"""
5865
Get C++ compiler

UNITTESTS/unit_test/options.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@ def get_options_parser():
103103
help="Build directory. Default: UNITTESTS/build/",
104104
dest="build")
105105

106+
parser.add_argument("--valgrind",
107+
help="Use Valgrind when running executables",
108+
action="store_true",
109+
dest="valgrind")
110+
106111
parser.add_argument("--new",
107112
action="append",
108113
help="Source file from which to generate test files. E.g. rtos/Semaphore.cpp",

UNITTESTS/unit_test/test.py

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@
2828
from .get_tools import get_make_tool, \
2929
get_cmake_tool, \
3030
get_cxx_tool, \
31-
get_c_tool
31+
get_c_tool, \
32+
get_valgrind_tool
3233
from .settings import DEFAULT_CMAKE_GENERATORS
3334

3435
class UnitTestTool(object):
@@ -59,7 +60,8 @@ def create_makefiles(self,
5960
path_to_src=None,
6061
generator=None,
6162
coverage_output_type=None,
62-
debug=False):
63+
debug=False,
64+
valgrind=False):
6365
"""
6466
Create Makefiles and prepare targets with CMake.
6567
@@ -94,6 +96,17 @@ def create_makefiles(self,
9496
if coverage_output_type:
9597
args.append("-DCOVERAGE:STRING=%s" % coverage_output_type)
9698

99+
if valgrind:
100+
valgrind = get_valgrind_tool()
101+
if valgrind is None:
102+
logging.error(
103+
"No Valgrind found in Path. Install all the required tools.\n")
104+
sys.exit(1)
105+
args.append("-DVALGRIND=1")
106+
args.append("-DMEMORYCHECK_COMMAND_OPTIONS=\"--track-origins=yes\" \"--leak-check=full\" \"--show-reachable=yes\" \"--error-exitcode=1\"")
107+
else:
108+
args.append("-DVALGRIND=0")
109+
97110
if path_to_src is not None:
98111
args.append(path_to_src)
99112

@@ -118,7 +131,7 @@ def build_tests(self):
118131
"Building unit tests failed.",
119132
"Unit tests built successfully.")
120133

121-
def run_tests(self, filter_regex=None):
134+
def run_tests(self, filter_regex=None, valgrind=False):
122135
"""
123136
Run unit tests.
124137
@@ -127,11 +140,16 @@ def run_tests(self, filter_regex=None):
127140
"""
128141

129142
args = [self.make_program, "test"]
130-
131-
if filter_regex:
132-
args.append("ARGS=-R %s -V -D ExperimentalTest" % filter_regex)
143+
if valgrind:
144+
if filter_regex:
145+
args.append("ARGS=-R %s -V -D ExperimentalMemCheck" % filter_regex)
146+
else:
147+
args.append("ARGS=-V -D ExperimentalMemCheck")
133148
else:
134-
args.append("ARGS=-V -D ExperimentalTest")
149+
if filter_regex:
150+
args.append("ARGS=-R %s -V -D ExperimentalTest" % filter_regex)
151+
else:
152+
args.append("ARGS=-V -D ExperimentalTest")
135153

136154
if logging.getLogger().getEffectiveLevel() == logging.DEBUG:
137155
args.append("VERBOSE=1")

components/wifi/esp8266-driver/ESP8266Interface.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,10 +637,10 @@ int ESP8266Interface::scan(WiFiAccessPoint *res, unsigned count, scan_mode mode,
637637

638638
nsapi_error_t status = _init();
639639
if (status != NSAPI_ERROR_OK) {
640-
return status;
641640
if (_software_conn_stat == IFACE_STATUS_DISCONNECTED) {
642641
_esp.uart_enable_input(false);
643642
}
643+
return status;
644644
}
645645

646646
int ret = _esp.scan(res, count, (mode == SCANMODE_ACTIVE ? ESP8266::SCANMODE_ACTIVE : ESP8266::SCANMODE_PASSIVE),

drivers/Serial.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,12 @@ class
6666
using SerialBase::write;
6767
#endif
6868

69+
/** Resolve ambiguities in SerialBase and FileHandle
70+
* (for enable_input and enable_output)
71+
*/
72+
using SerialBase::enable_input;
73+
using SerialBase::enable_output;
74+
6975
/** @deprecated
7076
* Create a Serial port, connected to the specified transmit and receive pins
7177
*

features/cellular/framework/AT/AT_CellularContext.cpp

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -486,14 +486,26 @@ nsapi_error_t AT_CellularContext::activate_ip_context()
486486
while (pdp) {
487487
SocketAddress addr;
488488
if (addr.set_ip_address(pdp->dns_secondary_addr)) {
489-
tr_info("DNS secondary %s", pdp->dns_secondary_addr);
490-
char ifn[5]; // "ce" + two digit _cid + zero
491-
add_dns_server(addr, get_interface_name(ifn));
489+
nsapi_addr_t taddr = addr.get_addr();
490+
for (int i = 0; i < ((taddr.version == NSAPI_IPv6) ? NSAPI_IPv6_BYTES : NSAPI_IPv4_BYTES); i++) {
491+
if (taddr.bytes[i] != 0) { // check the address is not all zero
492+
tr_info("DNS secondary %s", pdp->dns_secondary_addr);
493+
char ifn[5]; // "ce" + two digit _cid + zero
494+
add_dns_server(addr, get_interface_name(ifn));
495+
break;
496+
}
497+
}
492498
}
493499
if (addr.set_ip_address(pdp->dns_primary_addr)) {
494-
tr_info("DNS primary %s", pdp->dns_primary_addr);
495-
char ifn[5]; // "ce" + two digit _cid + zero
496-
add_dns_server(addr, get_interface_name(ifn));
500+
nsapi_addr_t taddr = addr.get_addr();
501+
for (int i = 0; i < ((taddr.version == NSAPI_IPv6) ? NSAPI_IPv6_BYTES : NSAPI_IPv4_BYTES); i++) {
502+
if (taddr.bytes[i] != 0) { // check the address is not all zero
503+
tr_info("DNS primary %s", pdp->dns_primary_addr);
504+
char ifn[5]; // "ce" + two digit _cid + zero
505+
add_dns_server(addr, get_interface_name(ifn));
506+
break;
507+
}
508+
}
497509
}
498510
pdp = pdp->next;
499511
}

features/cellular/framework/AT/AT_CellularNetwork.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ nsapi_error_t AT_CellularNetwork::set_registration(const char *plmn)
224224
if (_op_act != RAT_UNKNOWN) {
225225
return _at.at_cmd_discard("+COPS", "=1,2,", "%s%d", plmn, _op_act);
226226
} else {
227-
return _at.at_cmd_discard("+COPS", "=1,2", "%s", plmn);
227+
return _at.at_cmd_discard("+COPS", "=1,2,", "%s", plmn);
228228
}
229229
}
230230
}

features/cellular/framework/AT/AT_ControlPlane_netif.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class AT_ControlPlane_netif: public ControlPlane_netif {
3232
private:
3333
void (*_cb)(void *);
3434
void *_data;
35-
char _recv_buffer[MAX_CP_DATA_RECV_LEN];
35+
char _recv_buffer[MBED_CONF_CELLULAR_MAX_CP_DATA_RECV_LEN];
3636
size_t _recv_len;
3737
// Called on receiving URC: +CRTDCP
3838
void urc_cp_recv();

features/cellular/mbed_lib.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@
3232
"clear-on-connect" : {
3333
"help": "Clear modem to a known default state on connect() before SIM pin is entered, null to disable",
3434
"value": null
35+
},
36+
"max-cp-data-recv-len" : {
37+
"help": "Max length of the buffer storing data received over control plane",
38+
"value": 1358
3539
}
3640
}
3741
}

features/nanostack/mbed-mesh-api/source/wisun_tasklet.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,8 @@ static void wisun_tasklet_parse_network_event(arm_event_s *event)
215215
case ARM_NWK_NWK_CONNECTION_DOWN:
216216
/* Connection to Access point is lost wait for Scan Result */
217217
tr_debug("WS/RPL scan new network");
218-
wisun_tasklet_data_ptr->tasklet_state = TASKLET_STATE_BOOTSTRAP_FAILED;
219-
wisun_tasklet_network_state_changed(MESH_BOOTSTRAP_FAILED);
218+
wisun_tasklet_data_ptr->tasklet_state = TASKLET_STATE_BOOTSTRAP_STARTED;
219+
wisun_tasklet_network_state_changed(MESH_BOOTSTRAP_STARTED);
220220
break;
221221
case ARM_NWK_NWK_PARENT_POLL_FAIL:
222222
wisun_tasklet_data_ptr->tasklet_state = TASKLET_STATE_BOOTSTRAP_FAILED;
@@ -232,7 +232,8 @@ static void wisun_tasklet_parse_network_event(arm_event_s *event)
232232
break;
233233
}
234234

235-
if (wisun_tasklet_data_ptr->tasklet_state != TASKLET_STATE_BOOTSTRAP_READY &&
235+
if ((wisun_tasklet_data_ptr->tasklet_state != TASKLET_STATE_BOOTSTRAP_READY &&
236+
wisun_tasklet_data_ptr->tasklet_state != TASKLET_STATE_BOOTSTRAP_STARTED) &&
236237
wisun_tasklet_data_ptr->network_interface_id != INVALID_INTERFACE_ID) {
237238
// Set 5s timer for new network scan
238239
eventOS_event_timer_request(TIMER_EVENT_START_BOOTSTRAP,

features/netsocket/SocketAddress.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,8 @@ bool operator==(const SocketAddress &a, const SocketAddress &b)
182182
return true;
183183
} else if (a._addr.version != b._addr.version) {
184184
return false;
185+
} else if (a._port != b._port) {
186+
return false;
185187
} else if (a._addr.version == NSAPI_IPv4) {
186188
return memcmp(a._addr.bytes, b._addr.bytes, NSAPI_IPv4_BYTES) == 0;
187189
} else if (a._addr.version == NSAPI_IPv6) {

features/netsocket/cellular/ControlPlane_netif.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@
2727
namespace mbed {
2828

2929
/* Length of the buffer storing data received over control plane */
30-
#define MAX_CP_DATA_RECV_LEN 2048
30+
#ifndef MBED_CONF_CELLULAR_MAX_CP_DATA_RECV_LEN
31+
#define MBED_CONF_CELLULAR_MAX_CP_DATA_RECV_LEN 1358
32+
#endif
3133

32-
// TODO: need to make this l3ip compatible
3334

3435
/**
3536
* @addtogroup cellular

0 commit comments

Comments
 (0)