Preliminary main mbed library for nexpaq development

Committer:
nexpaq
Date:
Fri Nov 04 20:54:50 2016 +0000
Revision:
1:d96dbedaebdb
Parent:
0:6c56fb4bc5f0
Removed extra directories for other platforms

Who changed what in which revision?

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