mirror of https://github.com/ARMmbed/mbed-os.git
Add tests for synchronous dns
parent
812c6d5c88
commit
0c758b9ee1
|
@ -56,8 +56,9 @@ void ASYNCHRONOUS_DNS_CACHE()
|
|||
int delay_ms = (ticker_us - started_us) / 1000;
|
||||
|
||||
static int delay_first = delay_ms / 2;
|
||||
printf("Delays: first: %i, delay_ms: %i\n", delay_first, delay_ms);
|
||||
// Check that cached accesses are at least twice as fast as the first one
|
||||
TEST_ASSERT_FALSE(i != 0 && delay_ms > delay_first);
|
||||
TEST_ASSERT_TRUE(i == 0 || delay_ms <= delay_first);
|
||||
|
||||
printf("DNS: query \"%s\" => \"%s\", time %i ms\n",
|
||||
dns_test_hosts[0], data.addr.get_ip_address(), delay_ms);
|
||||
|
|
|
@ -59,6 +59,7 @@ extern const char dns_test_hosts_second[MBED_CONF_APP_DNS_TEST_HOSTS_NUM][DNS_TE
|
|||
NetworkInterface *get_interface();
|
||||
void hostbyname_cb(void *data, nsapi_error_t result, SocketAddress *address);
|
||||
void do_asynchronous_gethostbyname(const char hosts[][DNS_TEST_HOST_LEN], unsigned int op_count, int *exp_ok, int *exp_no_mem, int *exp_dns_failure, int *exp_timeout);
|
||||
void do_gethostbyname(const char hosts[][DNS_TEST_HOST_LEN], unsigned int op_count, int *exp_ok, int *exp_no_mem, int *exp_dns_failure, int *exp_timeout);
|
||||
|
||||
/*
|
||||
* Test cases
|
||||
|
@ -73,5 +74,8 @@ void ASYNCHRONOUS_DNS_EXTERNAL_EVENT_QUEUE();
|
|||
void ASYNCHRONOUS_DNS_INVALID_HOST();
|
||||
void ASYNCHRONOUS_DNS_TIMEOUTS();
|
||||
void ASYNCHRONOUS_DNS_SIMULTANEOUS_REPEAT();
|
||||
|
||||
void SYNCHRONOUS_DNS();
|
||||
void SYNCHRONOUS_DNS_MULTIPLE();
|
||||
void SYNCHRONOUS_DNS_CACHE();
|
||||
void SYNCHRONOUS_DNS_INVALID();
|
||||
#endif
|
||||
|
|
|
@ -107,6 +107,39 @@ void do_asynchronous_gethostbyname(const char hosts[][DNS_TEST_HOST_LEN], unsign
|
|||
delete[] data;
|
||||
}
|
||||
|
||||
void do_gethostbyname(const char hosts[][DNS_TEST_HOST_LEN], unsigned int op_count, int *exp_ok, int *exp_no_mem, int *exp_dns_failure, int *exp_timeout)
|
||||
{
|
||||
// Verify that there is enough hosts in the host list
|
||||
TEST_ASSERT(op_count <= MBED_CONF_APP_DNS_TEST_HOSTS_NUM)
|
||||
|
||||
// Reset counters
|
||||
(*exp_ok) = 0;
|
||||
(*exp_no_mem) = 0;
|
||||
(*exp_dns_failure) = 0;
|
||||
(*exp_timeout) = 0;
|
||||
|
||||
for (unsigned int i = 0; i < op_count; i++) {
|
||||
SocketAddress address;
|
||||
nsapi_error_t err = net->gethostbyname(hosts[i], &address);
|
||||
|
||||
TEST_ASSERT(err == NSAPI_ERROR_OK || err == NSAPI_ERROR_NO_MEMORY || err == NSAPI_ERROR_DNS_FAILURE || err == NSAPI_ERROR_TIMEOUT);
|
||||
if (err == NSAPI_ERROR_OK) {
|
||||
(*exp_ok)++;
|
||||
printf("DNS: query \"%s\" => \"%s\"\n",
|
||||
hosts[i], address.get_ip_address());
|
||||
} else if (err == NSAPI_ERROR_DNS_FAILURE) {
|
||||
(*exp_dns_failure)++;
|
||||
printf("DNS: query \"%s\" => DNS failure\n", hosts[i]);
|
||||
} else if (err == NSAPI_ERROR_TIMEOUT) {
|
||||
(*exp_timeout)++;
|
||||
printf("DNS: query \"%s\" => timeout\n", hosts[i]);
|
||||
} else if (err == NSAPI_ERROR_NO_MEMORY) {
|
||||
(*exp_no_mem)++;
|
||||
printf("DNS: query \"%s\" => no memory\n", hosts[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
NetworkInterface *get_interface()
|
||||
{
|
||||
return net;
|
||||
|
@ -145,6 +178,10 @@ Case cases[] = {
|
|||
#ifdef MBED_EXTENDED_TESTS
|
||||
Case("ASYNCHRONOUS_DNS_SIMULTANEOUS_REPEAT", ASYNCHRONOUS_DNS_SIMULTANEOUS_REPEAT),
|
||||
#endif
|
||||
Case("SYNCHRONOUS_DNS", SYNCHRONOUS_DNS),
|
||||
Case("SYNCHRONOUS_DNS_MULTIPLE", SYNCHRONOUS_DNS_MULTIPLE),
|
||||
Case("SYNCHRONOUS_DNS_CACHE", SYNCHRONOUS_DNS_CACHE),
|
||||
Case("SYNCHRONOUS_DNS_INVALID", SYNCHRONOUS_DNS_INVALID),
|
||||
};
|
||||
|
||||
Specification specification(test_setup, cases);
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* Copyright (c) 2018, ARM Limited, All Rights Reserved
|
||||
* 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 "mbed.h"
|
||||
#include "greentea-client/test_env.h"
|
||||
#include "unity.h"
|
||||
#include "utest.h"
|
||||
#include "dns_tests.h"
|
||||
|
||||
using namespace utest::v1;
|
||||
|
||||
namespace {
|
||||
int result_ok;
|
||||
int result_no_mem;
|
||||
int result_dns_failure;
|
||||
int result_exp_timeout;
|
||||
}
|
||||
|
||||
void SYNCHRONOUS_DNS()
|
||||
{
|
||||
do_gethostbyname(dns_test_hosts, 1, &result_ok, &result_no_mem, &result_dns_failure, &result_exp_timeout);
|
||||
|
||||
TEST_ASSERT(result_ok == 1);
|
||||
TEST_ASSERT(result_no_mem == 0);
|
||||
TEST_ASSERT(result_dns_failure == 0);
|
||||
TEST_ASSERT(result_exp_timeout == 0);
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
/*
|
||||
* Copyright (c) 2018, ARM Limited, All Rights Reserved
|
||||
* 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 "mbed.h"
|
||||
#include "greentea-client/test_env.h"
|
||||
#include "unity.h"
|
||||
#include "utest.h"
|
||||
#include "dns_tests.h"
|
||||
|
||||
using namespace utest::v1;
|
||||
|
||||
namespace {
|
||||
int ticker_us = 0;
|
||||
}
|
||||
|
||||
static void test_dns_query_ticker(void)
|
||||
{
|
||||
ticker_us += 100;
|
||||
}
|
||||
|
||||
void SYNCHRONOUS_DNS_CACHE()
|
||||
{
|
||||
rtos::Semaphore semaphore;
|
||||
|
||||
Ticker ticker;
|
||||
ticker.attach_us(&test_dns_query_ticker, 100);
|
||||
|
||||
for (unsigned int i = 0; i < 5; i++) {
|
||||
SocketAddress address;
|
||||
int started_us = ticker_us;
|
||||
nsapi_error_t err = get_interface()->gethostbyname(dns_test_hosts_second[0], &address);
|
||||
|
||||
int delay_ms = (ticker_us - started_us) / 1000;
|
||||
|
||||
static int delay_first = delay_ms / 2;
|
||||
// Check that cached accesses are at least twice as fast as the first one
|
||||
TEST_ASSERT_TRUE(i == 0 || delay_ms <= delay_first);
|
||||
|
||||
printf("DNS: query \"%s\" => \"%s\", time %i ms\n",
|
||||
dns_test_hosts_second[0], address.get_ip_address(), delay_ms);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* Copyright (c) 2018, ARM Limited, All Rights Reserved
|
||||
* 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 "mbed.h"
|
||||
#include "greentea-client/test_env.h"
|
||||
#include "unity.h"
|
||||
#include "utest.h"
|
||||
#include "dns_tests.h"
|
||||
|
||||
|
||||
using namespace utest::v1;
|
||||
|
||||
namespace {
|
||||
int result_ok;
|
||||
int result_no_mem;
|
||||
int result_dns_failure;
|
||||
int result_exp_timeout;
|
||||
}
|
||||
|
||||
void SYNCHRONOUS_DNS_INVALID()
|
||||
{
|
||||
//Ensure that there are no addressess in cache
|
||||
do_gethostbyname(dns_test_hosts_second, MBED_CONF_NSAPI_DNS_CACHE_SIZE, &result_ok, &result_no_mem, &result_dns_failure, &result_exp_timeout);
|
||||
|
||||
char dns_test_hosts_new[MBED_CONF_APP_DNS_TEST_HOSTS_NUM][DNS_TEST_HOST_LEN];
|
||||
memcpy(dns_test_hosts_new, dns_test_hosts, sizeof(dns_test_hosts_new));
|
||||
|
||||
int expected_failures = 0;
|
||||
int expected_successes = 0;
|
||||
|
||||
for (int i = 0; i < MBED_CONF_APP_DNS_TEST_HOSTS_NUM; i++) {
|
||||
if ((i % 2) == 0) {
|
||||
expected_failures++;
|
||||
strcat(&(dns_test_hosts_new[i][0]), "_invalid");
|
||||
} else {
|
||||
expected_successes++;
|
||||
}
|
||||
}
|
||||
|
||||
do_gethostbyname(dns_test_hosts_new, MBED_CONF_APP_DNS_TEST_HOSTS_NUM, &result_ok, &result_no_mem, &result_dns_failure, &result_exp_timeout);
|
||||
|
||||
TEST_ASSERT(result_ok == expected_successes);
|
||||
TEST_ASSERT(result_no_mem == 0);
|
||||
TEST_ASSERT(result_dns_failure == expected_failures);
|
||||
TEST_ASSERT(result_exp_timeout == 0);
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* Copyright (c) 2018, ARM Limited, All Rights Reserved
|
||||
* 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 "mbed.h"
|
||||
#include "greentea-client/test_env.h"
|
||||
#include "unity.h"
|
||||
#include "utest.h"
|
||||
#include "dns_tests.h"
|
||||
|
||||
using namespace utest::v1;
|
||||
|
||||
namespace {
|
||||
int result_ok;
|
||||
int result_no_mem;
|
||||
int result_dns_failure;
|
||||
int result_exp_timeout;
|
||||
}
|
||||
|
||||
void SYNCHRONOUS_DNS_MULTIPLE()
|
||||
{
|
||||
do_gethostbyname(dns_test_hosts, MBED_CONF_APP_DNS_TEST_HOSTS_NUM, &result_ok, &result_no_mem, &result_dns_failure, &result_exp_timeout);
|
||||
|
||||
TEST_ASSERT(result_ok == MBED_CONF_APP_DNS_TEST_HOSTS_NUM);
|
||||
TEST_ASSERT(result_no_mem == 0);
|
||||
TEST_ASSERT(result_dns_failure == 0);
|
||||
TEST_ASSERT(result_exp_timeout == 0);
|
||||
}
|
Loading…
Reference in New Issue