Marco Zecchini
/
Example_RTOS
Rtos API example
mbed-os/TESTS/mbed_drivers/echo/main.cpp@0:9fca2b23d0ba, 2019-02-23 (annotated)
- Committer:
- marcozecchini
- Date:
- Sat Feb 23 12:13:36 2019 +0000
- Revision:
- 0:9fca2b23d0ba
final commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
marcozecchini | 0:9fca2b23d0ba | 1 | /* |
marcozecchini | 0:9fca2b23d0ba | 2 | * Copyright (c) 2013-2016, ARM Limited, All Rights Reserved |
marcozecchini | 0:9fca2b23d0ba | 3 | * SPDX-License-Identifier: Apache-2.0 |
marcozecchini | 0:9fca2b23d0ba | 4 | * |
marcozecchini | 0:9fca2b23d0ba | 5 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
marcozecchini | 0:9fca2b23d0ba | 6 | * not use this file except in compliance with the License. |
marcozecchini | 0:9fca2b23d0ba | 7 | * You may obtain a copy of the License at |
marcozecchini | 0:9fca2b23d0ba | 8 | * |
marcozecchini | 0:9fca2b23d0ba | 9 | * http://www.apache.org/licenses/LICENSE-2.0 |
marcozecchini | 0:9fca2b23d0ba | 10 | * |
marcozecchini | 0:9fca2b23d0ba | 11 | * Unless required by applicable law or agreed to in writing, software |
marcozecchini | 0:9fca2b23d0ba | 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
marcozecchini | 0:9fca2b23d0ba | 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
marcozecchini | 0:9fca2b23d0ba | 14 | * See the License for the specific language governing permissions and |
marcozecchini | 0:9fca2b23d0ba | 15 | * limitations under the License. |
marcozecchini | 0:9fca2b23d0ba | 16 | */ |
marcozecchini | 0:9fca2b23d0ba | 17 | #include <stdio.h> |
marcozecchini | 0:9fca2b23d0ba | 18 | #include <string.h> |
marcozecchini | 0:9fca2b23d0ba | 19 | #include "mbed.h" |
marcozecchini | 0:9fca2b23d0ba | 20 | #include "greentea-client/test_env.h" |
marcozecchini | 0:9fca2b23d0ba | 21 | #include "unity/unity.h" |
marcozecchini | 0:9fca2b23d0ba | 22 | #include "utest/utest.h" |
marcozecchini | 0:9fca2b23d0ba | 23 | |
marcozecchini | 0:9fca2b23d0ba | 24 | using namespace utest::v1; |
marcozecchini | 0:9fca2b23d0ba | 25 | |
marcozecchini | 0:9fca2b23d0ba | 26 | // Echo server (echo payload to host) |
marcozecchini | 0:9fca2b23d0ba | 27 | template<int N> |
marcozecchini | 0:9fca2b23d0ba | 28 | void test_case_echo_server_x() { |
marcozecchini | 0:9fca2b23d0ba | 29 | char _key[11] = {}; |
marcozecchini | 0:9fca2b23d0ba | 30 | char _value[128] = {}; |
marcozecchini | 0:9fca2b23d0ba | 31 | const int echo_count = N; |
marcozecchini | 0:9fca2b23d0ba | 32 | const char _key_const[] = "echo_count"; |
marcozecchini | 0:9fca2b23d0ba | 33 | int expected_key = 1; |
marcozecchini | 0:9fca2b23d0ba | 34 | |
marcozecchini | 0:9fca2b23d0ba | 35 | greentea_send_kv(_key_const, echo_count); |
marcozecchini | 0:9fca2b23d0ba | 36 | // Handshake with host |
marcozecchini | 0:9fca2b23d0ba | 37 | do { |
marcozecchini | 0:9fca2b23d0ba | 38 | greentea_parse_kv(_key, _value, sizeof(_key), sizeof(_value)); |
marcozecchini | 0:9fca2b23d0ba | 39 | expected_key = strcmp(_key_const, _key); |
marcozecchini | 0:9fca2b23d0ba | 40 | } while (expected_key); |
marcozecchini | 0:9fca2b23d0ba | 41 | TEST_ASSERT_EQUAL_INT(echo_count, atoi(_value)); |
marcozecchini | 0:9fca2b23d0ba | 42 | |
marcozecchini | 0:9fca2b23d0ba | 43 | for (int i=0; i < echo_count; ++i) { |
marcozecchini | 0:9fca2b23d0ba | 44 | greentea_parse_kv(_key, _value, sizeof(_key), sizeof(_value)); |
marcozecchini | 0:9fca2b23d0ba | 45 | greentea_send_kv(_key, _value); |
marcozecchini | 0:9fca2b23d0ba | 46 | } |
marcozecchini | 0:9fca2b23d0ba | 47 | } |
marcozecchini | 0:9fca2b23d0ba | 48 | |
marcozecchini | 0:9fca2b23d0ba | 49 | utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason) { |
marcozecchini | 0:9fca2b23d0ba | 50 | greentea_case_failure_abort_handler(source, reason); |
marcozecchini | 0:9fca2b23d0ba | 51 | return STATUS_CONTINUE; |
marcozecchini | 0:9fca2b23d0ba | 52 | } |
marcozecchini | 0:9fca2b23d0ba | 53 | |
marcozecchini | 0:9fca2b23d0ba | 54 | Case cases[] = { |
marcozecchini | 0:9fca2b23d0ba | 55 | Case("Echo server: x16", test_case_echo_server_x<16>, greentea_failure_handler), |
marcozecchini | 0:9fca2b23d0ba | 56 | }; |
marcozecchini | 0:9fca2b23d0ba | 57 | |
marcozecchini | 0:9fca2b23d0ba | 58 | utest::v1::status_t greentea_test_setup(const size_t number_of_cases) { |
marcozecchini | 0:9fca2b23d0ba | 59 | GREENTEA_SETUP(30, "echo"); |
marcozecchini | 0:9fca2b23d0ba | 60 | return greentea_test_setup_handler(number_of_cases); |
marcozecchini | 0:9fca2b23d0ba | 61 | } |
marcozecchini | 0:9fca2b23d0ba | 62 | |
marcozecchini | 0:9fca2b23d0ba | 63 | Specification specification(greentea_test_setup, cases, greentea_test_teardown_handler); |
marcozecchini | 0:9fca2b23d0ba | 64 | |
marcozecchini | 0:9fca2b23d0ba | 65 | int main() { |
marcozecchini | 0:9fca2b23d0ba | 66 | Harness::run(specification); |
marcozecchini | 0:9fca2b23d0ba | 67 | } |