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 * mbed Microcontroller Library 00003 * Copyright (c) 2006-2018 ARM Limited 00004 * 00005 * SPDX-License-Identifier: Apache-2.0 00006 * 00007 * Licensed under the Apache License, Version 2.0 (the "License"); 00008 * you may not use this file except in compliance with the License. 00009 * You may obtain a copy of the License at 00010 * 00011 * http://www.apache.org/licenses/LICENSE-2.0 00012 * 00013 * Unless required by applicable law or agreed to in writing, software 00014 * distributed under the License is distributed on an "AS IS" BASIS, 00015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00016 * See the License for the specific language governing permissions and 00017 * limitations under the License. 00018 */ 00019 00020 /* 00021 * Based on mbed-stress-test by Marcus Chang @ Arm Mbed - http://github.com/ARMmbed/mbed-stress-test 00022 */ 00023 00024 #include "mbed.h" 00025 #include "utest/utest.h" 00026 #include "unity/unity.h" 00027 #include "greentea-client/test_env.h" 00028 #include "common_defines_test.h" 00029 #include "download_test.h" 00030 #include <string> 00031 00032 #ifdef MBED_CONF_APP_BASICS_TEST_FILENAME 00033 #include MBED_CONF_APP_BASICS_TEST_FILENAME 00034 #else 00035 #include "alice.h" 00036 #endif 00037 00038 #ifndef MBED_CONF_APP_TESTS_FS_SIZE 00039 #define MBED_CONF_APP_TESTS_FS_SIZE (2*1024*1024) 00040 #endif 00041 00042 using namespace utest::v1; 00043 00044 #if !defined(MBED_CONF_APP_NO_LED) 00045 DigitalOut led1(LED1); 00046 DigitalOut led2(LED2); 00047 void led_thread() { 00048 led1 = !led1; 00049 led2 = !led1; 00050 } 00051 #endif 00052 00053 #define MAX_RETRIES 3 00054 NetworkInterface* interface = NULL; 00055 static control_t setup_network(const size_t call_count) { 00056 interface = NetworkInterface::get_default_instance(); 00057 TEST_ASSERT_NOT_NULL_MESSAGE(interface, "failed to initialize network"); 00058 00059 nsapi_error_t err = -1; 00060 for (int tries = 0; tries < MAX_RETRIES; tries++) { 00061 err = interface->connect(); 00062 if (err == NSAPI_ERROR_OK) { 00063 break; 00064 } else { 00065 printf("[ERROR] Connecting to network. Retrying %d of %d.\r\n", tries, MAX_RETRIES); 00066 } 00067 } 00068 TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, err); 00069 printf("[NET] IP address is '%s'\n", interface->get_ip_address()); 00070 printf("[NET] MAC address is '%s'\n", interface->get_mac_address()); 00071 return CaseNext; 00072 } 00073 00074 static control_t download_128(const size_t call_count) { 00075 download_test(interface, story, sizeof(story), 128); 00076 00077 return CaseNext; 00078 } 00079 static control_t download_256(const size_t call_count) { 00080 download_test(interface, story, sizeof(story), 256); 00081 00082 return CaseNext; 00083 } 00084 00085 static control_t download_1k(const size_t call_count) { 00086 download_test(interface, story, sizeof(story), 1024); 00087 00088 return CaseNext; 00089 } 00090 00091 static control_t download_2k(const size_t call_count) { 00092 download_test(interface, story, sizeof(story), 2*1024); 00093 00094 return CaseNext; 00095 } 00096 00097 static control_t download_4k(const size_t call_count) { 00098 download_test(interface, story, sizeof(story), 4*1024); 00099 00100 return CaseNext; 00101 } 00102 00103 utest::v1::status_t greentea_setup(const size_t number_of_cases) { 00104 GREENTEA_SETUP(5*60, "default_auto"); 00105 return greentea_test_setup_handler(number_of_cases); 00106 } 00107 00108 Case cases[] = { 00109 Case(TEST_NETWORK_TYPE " network setup", setup_network), 00110 Case(TEST_NETWORK_TYPE " 128 buffer", download_128), 00111 #if MBED_CONF_TARGET_NETWORK_DEFAULT_INTERFACE_TYPE != CELLULAR 00112 Case(TEST_NETWORK_TYPE " 256 buffer", download_256), 00113 Case(TEST_NETWORK_TYPE " 1024 buffer", download_1k), 00114 Case(TEST_NETWORK_TYPE " 4096 buffer", download_4k), 00115 #endif 00116 }; 00117 00118 Specification specification(greentea_setup, cases); 00119 00120 int main() { 00121 //Create a thread to blink an LED and signal that the device is alive 00122 #if !defined(MBED_CONF_APP_NO_LED) 00123 Ticker t; 00124 t.attach(led_thread, 0.5); 00125 #endif 00126 00127 return !Harness::run(specification); 00128 }
Generated on Mon Aug 29 2022 19:53:40 by
