Knight KE / Mbed OS Game_Master
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers emac_test_unicast_burst.cpp Source File

emac_test_unicast_burst.cpp

00001 /*
00002  * Copyright (c) 2018, 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 
00018 #include "mbed.h"
00019 #include "greentea-client/test_env.h"
00020 #include "unity.h"
00021 #include "utest.h"
00022 
00023 #if MBED_CONF_APP_TEST_WIFI || MBED_CONF_APP_TEST_ETHERNET
00024 
00025 #include "emac_tests.h"
00026 #include "emac_util.h"
00027 #include "emac_ctp.h"
00028 
00029 using namespace utest::v1;
00030 
00031 void test_emac_unicast_burst_cb(int opt)
00032 {
00033     static bool send_request = true;
00034     static int no_response_cnt = 0;
00035     static int retries = 0;
00036     static int msg_len = 0;
00037     static int test_step = 0;
00038 
00039     // Timeout
00040     if (opt == TIMEOUT && send_request) {
00041         CTP_MSG_SEND(msg_len, emac_if_get_echo_server_addr(0), emac_if_get_own_addr(), emac_if_get_own_addr(), 0);
00042         send_request = false;
00043         no_response_cnt = 0;
00044     } else if (opt == TIMEOUT) {
00045         if (++no_response_cnt > 50) {
00046             if (++retries > 5) {
00047                 printf("too many retries\r\n\r\n");
00048                 SET_ERROR_FLAGS(TEST_FAILED);
00049                 END_TEST_LOOP;
00050             } else {
00051                 printf("retry count %i\r\n\r\n", retries);
00052                 send_request = true;
00053             }
00054         }
00055     }
00056 
00057     // Echo response received
00058     if (opt == INPUT) {
00059         if (msg_len == ETH_MAX_LEN) {
00060             if (++test_step > 10) {
00061                 END_TEST_LOOP;
00062             } else {
00063                 msg_len = 0;
00064             }
00065         } else if (msg_len + 50 >= ETH_MAX_LEN) {
00066             msg_len = ETH_MAX_LEN;
00067         } else {
00068             msg_len += 50;
00069         }
00070         printf("message length %i\r\n\r\n", msg_len);
00071         retries = 0;
00072         send_request = true;
00073     }
00074 }
00075 
00076 void test_emac_unicast_burst()
00077 {
00078     RESET_ALL_ERROR_FLAGS;
00079     SET_TRACE_LEVEL(TRACE_SEND | TRACE_SUCCESS | TRACE_FAILURE);
00080 
00081     if (ECHO_SERVER_ADDRESS_KNOWN) {
00082         START_TEST_LOOP(test_emac_unicast_burst_cb, 100);
00083     }
00084 
00085     PRINT_ERROR_FLAGS;
00086     TEST_ASSERT_FALSE(ERROR_FLAGS);
00087     RESET_OUTGOING_MSG_DATA;
00088 }
00089 
00090 #endif