Greg Steiert / pegasus_dev

Dependents:   blinky_max32630fthr

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

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[10] = {};
00030     char _value[128] = {};
00031     const int echo_count = N;
00032 
00033     // Handshake with host
00034     greentea_send_kv("echo_count", echo_count);
00035     greentea_parse_kv(_key, _value, sizeof(_key), sizeof(_value));
00036     TEST_ASSERT_EQUAL_INT(echo_count, atoi(_value));
00037 
00038     for (int i=0; i < echo_count; ++i) {
00039         greentea_parse_kv(_key, _value, sizeof(_key), sizeof(_value));
00040         greentea_send_kv(_key, _value);
00041     }
00042 }
00043 
00044 utest::v1::status_t  greentea_failure_handler(const Case *const source, const failure_t reason) {
00045     greentea_case_failure_abort_handler(source, reason);
00046     return STATUS_CONTINUE;
00047 }
00048 
00049 Case cases[] = {
00050     Case("Echo server: x16", test_case_echo_server_x<16>, greentea_failure_handler),
00051     Case("Echo server: x32", test_case_echo_server_x<32>, greentea_failure_handler),
00052     Case("Echo server: x64", test_case_echo_server_x<64>, greentea_failure_handler),
00053 };
00054 
00055 utest::v1::status_t  greentea_test_setup(const size_t number_of_cases) {
00056     GREENTEA_SETUP(180, "echo");
00057     return greentea_test_setup_handler(number_of_cases);
00058 }
00059 
00060 Specification specification(greentea_test_setup, cases, greentea_test_teardown_handler);
00061 
00062 int main() {
00063     Harness::run(specification);
00064 }