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.
emac_test_memory.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 #include "emac_tests.h" 00024 #include "emac_util.h" 00025 #include "emac_ctp.h" 00026 00027 using namespace utest::v1; 00028 00029 void test_emac_memory_cb(int opt) 00030 { 00031 static bool send_request = true; 00032 static bool memory = true; 00033 static int no_response_cnt = 0; 00034 static int retries = 0; 00035 static int msg_len = 0; 00036 static int test_step = 0; 00037 static bool next_step = true; 00038 static int options = CTP_OPT_NON_ALIGNED; 00039 00040 // Defines test step 00041 if (next_step) { 00042 next_step = false; 00043 switch (test_step) { 00044 case 0: 00045 printf("STEP 0: memory available\r\n\r\n"); 00046 emac_if_set_output_memory(true); 00047 emac_if_set_input_memory(true); 00048 memory = true; 00049 break; 00050 00051 case 1: 00052 printf("STEP 1: no input memory buffer memory available\r\n\r\n"); 00053 emac_if_set_output_memory(true); 00054 emac_if_set_input_memory(false); 00055 memory = false; 00056 break; 00057 00058 case 2: 00059 printf("STEP 2: memory available\r\n\r\n"); 00060 emac_if_set_output_memory(true); 00061 emac_if_set_input_memory(true); 00062 memory = true; 00063 break; 00064 00065 case 3: 00066 printf("STEP 3: no output memory buffer memory available\r\n\r\n"); 00067 emac_if_set_output_memory(false); 00068 emac_if_set_input_memory(true); 00069 memory = false; 00070 break; 00071 00072 case 4: 00073 printf("STEP 4: memory available\r\n\r\n"); 00074 emac_if_set_output_memory(true); 00075 emac_if_set_input_memory(true); 00076 memory = true; 00077 break; 00078 00079 case 5: 00080 printf("STEP 5: no output or input memory buffer memory available\r\n\r\n"); 00081 emac_if_set_output_memory(false); 00082 emac_if_set_input_memory(false); 00083 memory = false; 00084 break; 00085 00086 case 6: 00087 printf("STEP 6: memory available\r\n\r\n"); 00088 emac_if_set_output_memory(true); 00089 emac_if_set_input_memory(true); 00090 memory = true; 00091 break; 00092 00093 case 7: 00094 printf("STEP 7: memory available, alloc from heap\r\n\r\n"); 00095 emac_if_set_output_memory(true); 00096 emac_if_set_input_memory(true); 00097 options |= CTP_OPT_HEAP; 00098 memory = true; 00099 break; 00100 00101 case 8: 00102 // Test ended 00103 END_TEST_LOOP; 00104 } 00105 } 00106 00107 bool next_len = false; 00108 00109 // Timeout 00110 if (opt == TIMEOUT && send_request) { 00111 CTP_MSG_SEND(msg_len, emac_if_get_echo_server_addr(0), emac_if_get_own_addr(), emac_if_get_own_addr(), options); 00112 send_request = false; 00113 no_response_cnt = 0; 00114 } else if (opt == TIMEOUT) { 00115 if (++no_response_cnt > 5) { 00116 if (++retries > 3) { 00117 // If echo replies should be received fails the test case 00118 if (memory) { 00119 printf("too many retries\r\n\r\n"); 00120 SET_ERROR_FLAGS(TEST_FAILED); 00121 END_TEST_LOOP; 00122 // Otherwise continues test 00123 } else { 00124 RESET_OUTGOING_MSG_DATA; 00125 next_len = true; 00126 } 00127 } else { 00128 printf("retry count %i\r\n\r\n", retries); 00129 send_request = true; 00130 } 00131 } 00132 } 00133 00134 // Echo response received or retry count exceeded for memory buffers are not available 00135 if (opt == INPUT || next_len) { 00136 if (msg_len == ETH_MAX_LEN) { 00137 msg_len = 0; 00138 test_step++; 00139 next_step = true; 00140 } else if (msg_len + 50 >= ETH_MAX_LEN) { 00141 msg_len = ETH_MAX_LEN; 00142 } else { 00143 msg_len += 50; 00144 } 00145 printf("message length %i\r\n\r\n", msg_len); 00146 retries = 0; 00147 send_request = true; 00148 } 00149 } 00150 00151 void test_emac_memory() 00152 { 00153 RESET_ALL_ERROR_FLAGS; 00154 SET_TRACE_LEVEL(TRACE_SEND | TRACE_SUCCESS | TRACE_FAILURE); 00155 00156 if (ECHO_SERVER_ADDRESS_KNOWN) { 00157 START_TEST_LOOP(test_emac_memory_cb, 100); 00158 } 00159 00160 PRINT_ERROR_FLAGS; 00161 TEST_ASSERT_FALSE(ERROR_FLAGS); 00162 RESET_OUTGOING_MSG_DATA; 00163 }
Generated on Tue Aug 9 2022 00:37:06 by
1.7.2