forked from ARMmbed/mbed-os
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request ARMmbed#9 from yennster/uart-new
Added peripherals & updated Mbed OS
- Loading branch information
Showing
639 changed files
with
16,990 additions
and
5,516 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 ASYNCHRONOUS_DNS() | ||
{ | ||
do_asynchronous_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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* 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 ASYNCHRONOUS_DNS_CACHE() | ||
{ | ||
rtos::Semaphore semaphore; | ||
dns_application_data data; | ||
data.semaphore = &semaphore; | ||
|
||
Ticker ticker; | ||
ticker.attach_us(&test_dns_query_ticker, 100); | ||
|
||
for (unsigned int i = 0; i < 5; i++) { | ||
int started_us = ticker_us; | ||
|
||
nsapi_error_t err = get_interface()->gethostbyname_async(dns_test_hosts[0], | ||
mbed::Callback<void(nsapi_error_t, SocketAddress *)>(hostbyname_cb, (void *) &data)); | ||
TEST_ASSERT(err >= 0); | ||
|
||
semaphore.wait(); | ||
|
||
TEST_ASSERT(data.result == NSAPI_ERROR_OK); | ||
TEST_ASSERT(strlen(data.addr.get_ip_address()) > 1); | ||
|
||
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_FALSE(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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
* 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; | ||
|
||
void ASYNCHRONOUS_DNS_CANCEL() | ||
{ | ||
rtos::Semaphore semaphore; | ||
dns_application_data *data = new dns_application_data[MBED_CONF_APP_DNS_TEST_HOSTS_NUM]; | ||
|
||
int count = 0; | ||
|
||
for (unsigned int i = 0; i < MBED_CONF_APP_DNS_TEST_HOSTS_NUM; i++) { | ||
data[i].value_set = false; | ||
data[i].semaphore = &semaphore; | ||
data[i].req_result = get_interface()->gethostbyname_async(dns_test_hosts[i], | ||
mbed::Callback<void(nsapi_error_t, SocketAddress *)>(hostbyname_cb, (void *) &data[i])); | ||
TEST_ASSERT(data[i].req_result >= 0 || data[i].req_result == NSAPI_ERROR_NO_MEMORY); | ||
|
||
if (data[i].req_result >= 0) { | ||
// Callback will be called | ||
count++; | ||
} else { | ||
// No memory to initiate DNS query, callback will not be called | ||
data[i].result = NSAPI_ERROR_NO_MEMORY; | ||
data[i].value_set = true; | ||
} | ||
} | ||
|
||
for (unsigned int i = 0; i < MBED_CONF_APP_DNS_TEST_HOSTS_NUM; i++) { | ||
if (data[i].req_result > 0) { | ||
if (get_interface()->gethostbyname_async_cancel(data[i].req_result) == NSAPI_ERROR_OK) { | ||
count--; | ||
} | ||
} | ||
} | ||
|
||
// Wait for callback(s) to complete | ||
for (int i = 0; i < count; i++) { | ||
semaphore.wait(); | ||
} | ||
|
||
for (unsigned int i = 0; i < MBED_CONF_APP_DNS_TEST_HOSTS_NUM; i++) { | ||
if (!data[i].value_set) { | ||
printf("DNS: query \"%s\" => cancel\n", dns_test_hosts[i]); | ||
continue; | ||
} | ||
TEST_ASSERT(data[i].result == NSAPI_ERROR_OK || data[i].result == NSAPI_ERROR_NO_MEMORY || data[i].result == NSAPI_ERROR_DNS_FAILURE || data[i].result == NSAPI_ERROR_TIMEOUT); | ||
if (data[i].result == NSAPI_ERROR_OK) { | ||
printf("DNS: query \"%s\" => \"%s\"\n", | ||
dns_test_hosts[i], data[i].addr.get_ip_address()); | ||
} else if (data[i].result == NSAPI_ERROR_DNS_FAILURE) { | ||
printf("DNS: query \"%s\" => DNS failure\n", dns_test_hosts[i]); | ||
} else if (data[i].result == NSAPI_ERROR_TIMEOUT) { | ||
printf("DNS: query \"%s\" => timeout\n", dns_test_hosts[i]); | ||
} else if (data[i].result == NSAPI_ERROR_NO_MEMORY) { | ||
printf("DNS: query \"%s\" => no memory\n", dns_test_hosts[i]); | ||
} | ||
} | ||
|
||
delete[] data; | ||
|
||
wait(5.0); | ||
} |
85 changes: 85 additions & 0 deletions
85
TESTS/netsocket/dns/asynchronous_dns_external_event_queue.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
* 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" | ||
|
||
#include "nsapi_dns.h" | ||
|
||
using namespace utest::v1; | ||
|
||
namespace { | ||
int result_ok; | ||
int result_no_mem; | ||
int result_dns_failure; | ||
int result_exp_timeout; | ||
|
||
const int EXTERNAL_THREAD_SIZE = 2048; | ||
const int EVENT_QUEUE_SIZE = 10; | ||
|
||
events::EventQueue *event_queue; | ||
} | ||
|
||
static nsapi_error_t event_queue_call(int delay, mbed::Callback<void()> func) | ||
{ | ||
if (delay) { | ||
if (event_queue->call_in(delay, func) == 0) { | ||
return NSAPI_ERROR_NO_MEMORY; | ||
} | ||
} else { | ||
if (event_queue->call(func) == 0) { | ||
return NSAPI_ERROR_NO_MEMORY; | ||
} | ||
} | ||
return NSAPI_ERROR_OK; | ||
} | ||
|
||
void ASYNCHRONOUS_DNS_EXTERNAL_EVENT_QUEUE() | ||
{ | ||
// Ensures that cache does not contain entries | ||
do_asynchronous_gethostbyname(dns_test_hosts, MBED_CONF_NSAPI_DNS_CACHE_SIZE, &result_ok, &result_no_mem, | ||
&result_dns_failure, &result_exp_timeout); | ||
|
||
TEST_ASSERT(result_ok == MBED_CONF_NSAPI_DNS_CACHE_SIZE); | ||
TEST_ASSERT(result_no_mem == 0); | ||
TEST_ASSERT(result_dns_failure == 0); | ||
TEST_ASSERT(result_exp_timeout == 0); | ||
|
||
// Dispatch event queue | ||
Thread eventThread(osPriorityNormal, EXTERNAL_THREAD_SIZE); | ||
EventQueue queue(EVENT_QUEUE_SIZE * EVENTS_EVENT_SIZE); | ||
eventThread.start(callback(&queue, &EventQueue::dispatch_forever)); | ||
event_queue = &queue; | ||
|
||
nsapi_dns_call_in_set(event_queue_call); | ||
|
||
do_asynchronous_gethostbyname(dns_test_hosts_second, MBED_CONF_APP_DNS_SIMULT_QUERIES + 1, &result_ok, &result_no_mem, | ||
&result_dns_failure, &result_exp_timeout); | ||
|
||
TEST_ASSERT(result_ok == MBED_CONF_APP_DNS_SIMULT_QUERIES); | ||
TEST_ASSERT(result_no_mem == 1); // last query fails for no memory as expected | ||
TEST_ASSERT(result_dns_failure == 0); | ||
TEST_ASSERT(result_exp_timeout == 0); | ||
|
||
// Give event queue time to finalise before destructors | ||
wait(2.0); | ||
|
||
nsapi_dns_call_in_set(0); | ||
} |
Oops, something went wrong.