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