Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
00001 /* 00002 * Copyright (c) 2013-2016, ARM Limited, All Rights Reserved 00003 * SPDX-License-Identifier: Apache-2.0 00004 * 00005 * Licensed under the Apache License, Version 2.0 (the "License"); you may 00006 * not use this file except in compliance with the License. 00007 * You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 00013 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 00016 */ 00017 #include <stdio.h> 00018 #include <string.h> 00019 #include "mbed.h" 00020 #include "greentea-client/test_env.h" 00021 #include "unity/unity.h" 00022 #include "utest/utest.h" 00023 00024 using namespace utest::v1; 00025 00026 // Echo server (echo payload to host) 00027 template<int N> 00028 void test_case_echo_server_x() { 00029 char _key[11] = {}; 00030 char _value[128] = {}; 00031 const int echo_count = N; 00032 const char _key_const[] = "echo_count"; 00033 int expected_key = 1; 00034 00035 greentea_send_kv(_key_const, echo_count); 00036 // Handshake with host 00037 do { 00038 greentea_parse_kv(_key, _value, sizeof(_key), sizeof(_value)); 00039 expected_key = strcmp(_key_const, _key); 00040 } while (expected_key); 00041 TEST_ASSERT_EQUAL_INT(echo_count, atoi(_value)); 00042 00043 for (int i=0; i < echo_count; ++i) { 00044 greentea_parse_kv(_key, _value, sizeof(_key), sizeof(_value)); 00045 greentea_send_kv(_key, _value); 00046 } 00047 } 00048 00049 utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason) { 00050 greentea_case_failure_abort_handler(source, reason); 00051 return STATUS_CONTINUE; 00052 } 00053 00054 Case cases[] = { 00055 Case("Echo server: x16", test_case_echo_server_x<16>, greentea_failure_handler), 00056 }; 00057 00058 utest::v1::status_t greentea_test_setup(const size_t number_of_cases) { 00059 GREENTEA_SETUP(30, "echo"); 00060 return greentea_test_setup_handler(number_of_cases); 00061 } 00062 00063 Specification specification(greentea_test_setup, cases, greentea_test_teardown_handler); 00064 00065 int main() { 00066 Harness::run(specification); 00067 }
Generated on Thu Jul 14 2022 14:36:19 by
