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

connectivity tests: avoid HardFault with null pointer #15068

Merged
merged 1 commit into from
Oct 14, 2021
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 connectivity/netsocket/tests/TESTS/netsocket/dns/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ static void net_bringup()
MBED_ASSERT(MBED_CONF_APP_DNS_TEST_HOSTS_NUM >= MBED_CONF_NSAPI_DNS_CACHE_SIZE && MBED_CONF_APP_DNS_TEST_HOSTS_NUM >= MBED_CONF_APP_DNS_SIMULT_QUERIES + 1);

net = NetworkInterface::get_default_instance();
TEST_ASSERT_NOT_NULL_MESSAGE(net, "No NetworkInterface configured");
nsapi_error_t err = net->connect();
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, err);
SocketAddress address;
Expand Down
1 change: 1 addition & 0 deletions connectivity/netsocket/tests/TESTS/netsocket/tcp/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ nsapi_version_t get_ip_version()
static void _ifup()
{
NetworkInterface *net = NetworkInterface::get_default_instance();
TEST_ASSERT_NOT_NULL_MESSAGE(net, "No NetworkInterface configured");
nsapi_error_t err = net->connect();
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, err);
SocketAddress address;
Expand Down
1 change: 1 addition & 0 deletions connectivity/netsocket/tests/TESTS/netsocket/tls/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ void drop_bad_packets(TLSSocket &sock, int orig_timeout)
static void _ifup()
{
NetworkInterface *net = NetworkInterface::get_default_instance();
TEST_ASSERT_NOT_NULL_MESSAGE(net, "No NetworkInterface configured");
nsapi_error_t err = net->connect();
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, err);
SocketAddress address;
Expand Down
1 change: 1 addition & 0 deletions connectivity/netsocket/tests/TESTS/netsocket/udp/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ void drop_bad_packets(UDPSocket &sock, int orig_timeout)
static void _ifup()
{
NetworkInterface *net = NetworkInterface::get_default_instance();
TEST_ASSERT_NOT_NULL_MESSAGE(net, "No NetworkInterface configured");
nsapi_error_t err = net->connect();
TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, err);
SocketAddress address;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ void NETWORKINTERFACE_STATUS()
current_status = NSAPI_STATUS_ERROR_UNSUPPORTED;

net = NetworkInterface::get_default_instance();
TEST_ASSERT_NOT_NULL_MESSAGE(net, "No NetworkInterface configured");
net->attach(status_cb);
net->set_blocking(true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ using namespace utest::v1;
void wifi_connect(void)
{
WiFiInterface *wifi = get_interface();
TEST_ASSERT(wifi);
if (wifi == NULL) {
Copy link
Contributor

Choose a reason for hiding this comment

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

what's the difference between wifi tests returning (assert before) and asserting with a message (TEST_ASSERT_NOT_NULL_MESSAGE not in this case)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Other tests are stopping as soon as a test assert comes.
This one doesn't stop, so it needs a "clean" return.

return;
}

char ssid[SSID_MAX_LEN + 1] = MBED_CONF_APP_WIFI_UNSECURE_SSID;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ using namespace utest::v1;
void wifi_connect_disconnect_repeat(void)
{
WiFiInterface *wifi = get_interface();
TEST_ASSERT(wifi);
if (wifi == NULL) {
return;
}
nsapi_error_t error;

error = wifi->set_credentials(MBED_CONF_APP_WIFI_SECURE_SSID, MBED_CONF_APP_WIFI_PASSWORD, get_security());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ using namespace utest::v1;
void wifi_connect_nocredentials(void)
{
WiFiInterface *wifi = get_interface();
TEST_ASSERT(wifi);
if (wifi == NULL) {
return;
}
nsapi_error_t error_connect, error_disconnect;
error_connect = wifi->connect();
error_disconnect = wifi->disconnect();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ using namespace utest::v1;
void wifi_connect_params_channel(void)
{
WiFiInterface *wifi = get_interface();
TEST_ASSERT(wifi);
if (wifi == NULL) {
return;
}

if (wifi->set_channel(1) == NSAPI_ERROR_UNSUPPORTED && wifi->set_channel(36) == NSAPI_ERROR_UNSUPPORTED) {
TEST_IGNORE_MESSAGE("set_channel() not supported");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ using namespace utest::v1;
void wifi_connect_params_channel_fail(void)
{
WiFiInterface *wifi = get_interface();
TEST_ASSERT(wifi);
if (wifi == NULL) {
return;
}

if (wifi->set_channel(1) == NSAPI_ERROR_UNSUPPORTED && wifi->set_channel(36) == NSAPI_ERROR_UNSUPPORTED) {
TEST_IGNORE_MESSAGE("set_channel() not supported");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ void wifi_connect_params_null(void)
{
nsapi_error_t error;
WiFiInterface *wifi = get_interface();
TEST_ASSERT(wifi);
if (wifi == NULL) {
return;
}
error = wifi->connect(NULL, NULL);
wifi->disconnect();
TEST_ASSERT_EQUAL(NSAPI_ERROR_PARAMETER, error);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ using namespace utest::v1;
void wifi_connect_params_valid_secure(void)
{
WiFiInterface *wifi = get_interface();
TEST_ASSERT(wifi);
if (wifi == NULL) {
return;
}

if (wifi->connect(MBED_CONF_APP_WIFI_SECURE_SSID, MBED_CONF_APP_WIFI_PASSWORD, get_security()) == NSAPI_ERROR_OK) {
if (wifi->disconnect() == NSAPI_ERROR_OK) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ using namespace utest::v1;
void wifi_connect_secure(void)
{
WiFiInterface *wifi = get_interface();
TEST_ASSERT(wifi);
if (wifi == NULL) {
return;
}

// Driver shall cache the credentials
char ssid[] = MBED_CONF_APP_WIFI_SECURE_SSID;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ using namespace utest::v1;
void wifi_connect_secure_fail(void)
{
WiFiInterface *wifi = get_interface();
TEST_ASSERT(wifi);
if (wifi == NULL) {
return;
}

TEST_ASSERT_EQUAL_INT(NSAPI_ERROR_OK, wifi->set_credentials(MBED_CONF_APP_WIFI_SECURE_SSID, "aaaaaaaa", get_security()));
nsapi_error_t error;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ using namespace utest::v1;
void wifi_get_rssi(void)
{
WiFiInterface *wifi = get_interface();
TEST_ASSERT(wifi);
if (wifi == NULL) {
return;
}

TEST_ASSERT_EQUAL_INT(NSAPI_ERROR_OK, wifi->set_credentials(MBED_CONF_APP_WIFI_SECURE_SSID, MBED_CONF_APP_WIFI_PASSWORD, get_security()));

Expand Down
4 changes: 4 additions & 0 deletions connectivity/netsocket/tests/TESTS/network/wifi/wifi_scan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ using namespace utest::v1;
void wifi_scan(void)
{
WiFiInterface *wifi = get_interface();
TEST_ASSERT(wifi);
if (wifi == NULL) {
return;
}

WiFiAccessPoint ap[MBED_CONF_APP_MAX_SCAN_SIZE];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,9 @@ using namespace utest::v1;
void wifi_scan_null(void)
{
WiFiInterface *wifi = get_interface();
TEST_ASSERT(wifi);
if (wifi == NULL) {
return;
}
TEST_ASSERT(wifi->scan(NULL, 0) >= 1);
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ void wifi_set_channel(void)
bool is_5Ghz = false;

WiFiInterface *wifi = get_interface();
TEST_ASSERT(wifi);
if (wifi == NULL) {
return;
}

if (wifi->set_channel(1) == NSAPI_ERROR_UNSUPPORTED && wifi->set_channel(36) == NSAPI_ERROR_UNSUPPORTED) {
TEST_IGNORE_MESSAGE("set_channel() not supported");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ using namespace utest::v1;
void wifi_set_credential(void)
{
WiFiInterface *iface = get_interface();
TEST_ASSERT(iface);
if (iface == NULL) {
return;
}
nsapi_error_t error;

error = iface->set_credentials(NULL, NULL, NSAPI_SECURITY_NONE);
Expand Down