Committer:
leothedragon
Date:
Sun Apr 18 15:20:23 2021 +0000
Revision:
0:25fa8795676b
DS

Who changed what in which revision?

UserRevisionLine numberNew contents of line
leothedragon 0:25fa8795676b 1 /*
leothedragon 0:25fa8795676b 2 * mbed Microcontroller Library
leothedragon 0:25fa8795676b 3 * Copyright (c) 2006-2018 ARM Limited
leothedragon 0:25fa8795676b 4 *
leothedragon 0:25fa8795676b 5 * SPDX-License-Identifier: Apache-2.0
leothedragon 0:25fa8795676b 6 *
leothedragon 0:25fa8795676b 7 * Licensed under the Apache License, Version 2.0 (the "License");
leothedragon 0:25fa8795676b 8 * you may not use this file except in compliance with the License.
leothedragon 0:25fa8795676b 9 * You may obtain a copy of the License at
leothedragon 0:25fa8795676b 10 *
leothedragon 0:25fa8795676b 11 * http://www.apache.org/licenses/LICENSE-2.0
leothedragon 0:25fa8795676b 12 *
leothedragon 0:25fa8795676b 13 * Unless required by applicable law or agreed to in writing, software
leothedragon 0:25fa8795676b 14 * distributed under the License is distributed on an "AS IS" BASIS,
leothedragon 0:25fa8795676b 15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
leothedragon 0:25fa8795676b 16 * See the License for the specific language governing permissions and
leothedragon 0:25fa8795676b 17 * limitations under the License.
leothedragon 0:25fa8795676b 18 */
leothedragon 0:25fa8795676b 19
leothedragon 0:25fa8795676b 20 /*
leothedragon 0:25fa8795676b 21 * Based on mbed-stress-test by Marcus Chang @ Arm Mbed - http://github.com/ARMmbed/mbed-stress-test
leothedragon 0:25fa8795676b 22 */
leothedragon 0:25fa8795676b 23
leothedragon 0:25fa8795676b 24 #include "mbed.h"
leothedragon 0:25fa8795676b 25 #include "utest/utest.h"
leothedragon 0:25fa8795676b 26 #include "unity/unity.h"
leothedragon 0:25fa8795676b 27 #include "greentea-client/test_env.h"
leothedragon 0:25fa8795676b 28 #include "common_defines_test.h"
leothedragon 0:25fa8795676b 29 #include "download_test.h"
leothedragon 0:25fa8795676b 30 #include <string>
leothedragon 0:25fa8795676b 31
leothedragon 0:25fa8795676b 32 #ifdef MBED_CONF_APP_BASICS_TEST_FILENAME
leothedragon 0:25fa8795676b 33 #include MBED_CONF_APP_BASICS_TEST_FILENAME
leothedragon 0:25fa8795676b 34 #else
leothedragon 0:25fa8795676b 35 #include "alice.h"
leothedragon 0:25fa8795676b 36 #endif
leothedragon 0:25fa8795676b 37
leothedragon 0:25fa8795676b 38 #ifndef MBED_CONF_APP_TESTS_FS_SIZE
leothedragon 0:25fa8795676b 39 #define MBED_CONF_APP_TESTS_FS_SIZE (2*1024*1024)
leothedragon 0:25fa8795676b 40 #endif
leothedragon 0:25fa8795676b 41
leothedragon 0:25fa8795676b 42 using namespace utest::v1;
leothedragon 0:25fa8795676b 43
leothedragon 0:25fa8795676b 44 #if !defined(MBED_CONF_APP_NO_LED)
leothedragon 0:25fa8795676b 45 DigitalOut led1(LED1);
leothedragon 0:25fa8795676b 46 DigitalOut led2(LED2);
leothedragon 0:25fa8795676b 47 void led_thread() {
leothedragon 0:25fa8795676b 48 led1 = !led1;
leothedragon 0:25fa8795676b 49 led2 = !led1;
leothedragon 0:25fa8795676b 50 }
leothedragon 0:25fa8795676b 51 #endif
leothedragon 0:25fa8795676b 52
leothedragon 0:25fa8795676b 53 #define MAX_RETRIES 3
leothedragon 0:25fa8795676b 54 NetworkInterface* interface = NULL;
leothedragon 0:25fa8795676b 55 static control_t setup_network(const size_t call_count) {
leothedragon 0:25fa8795676b 56 interface = NetworkInterface::get_default_instance();
leothedragon 0:25fa8795676b 57 TEST_ASSERT_NOT_NULL_MESSAGE(interface, "failed to initialize network");
leothedragon 0:25fa8795676b 58
leothedragon 0:25fa8795676b 59 nsapi_error_t err = -1;
leothedragon 0:25fa8795676b 60 for (int tries = 0; tries < MAX_RETRIES; tries++) {
leothedragon 0:25fa8795676b 61 err = interface->connect();
leothedragon 0:25fa8795676b 62 if (err == NSAPI_ERROR_OK) {
leothedragon 0:25fa8795676b 63 break;
leothedragon 0:25fa8795676b 64 } else {
leothedragon 0:25fa8795676b 65 printf("[ERROR] Connecting to network. Retrying %d of %d.\r\n", tries, MAX_RETRIES);
leothedragon 0:25fa8795676b 66 }
leothedragon 0:25fa8795676b 67 }
leothedragon 0:25fa8795676b 68 TEST_ASSERT_EQUAL(NSAPI_ERROR_OK, err);
leothedragon 0:25fa8795676b 69 printf("[NET] IP address is '%s'\n", interface->get_ip_address());
leothedragon 0:25fa8795676b 70 printf("[NET] MAC address is '%s'\n", interface->get_mac_address());
leothedragon 0:25fa8795676b 71 return CaseNext;
leothedragon 0:25fa8795676b 72 }
leothedragon 0:25fa8795676b 73
leothedragon 0:25fa8795676b 74 static control_t download_128(const size_t call_count) {
leothedragon 0:25fa8795676b 75 download_test(interface, story, sizeof(story), 128);
leothedragon 0:25fa8795676b 76
leothedragon 0:25fa8795676b 77 return CaseNext;
leothedragon 0:25fa8795676b 78 }
leothedragon 0:25fa8795676b 79 static control_t download_256(const size_t call_count) {
leothedragon 0:25fa8795676b 80 download_test(interface, story, sizeof(story), 256);
leothedragon 0:25fa8795676b 81
leothedragon 0:25fa8795676b 82 return CaseNext;
leothedragon 0:25fa8795676b 83 }
leothedragon 0:25fa8795676b 84
leothedragon 0:25fa8795676b 85 static control_t download_1k(const size_t call_count) {
leothedragon 0:25fa8795676b 86 download_test(interface, story, sizeof(story), 1024);
leothedragon 0:25fa8795676b 87
leothedragon 0:25fa8795676b 88 return CaseNext;
leothedragon 0:25fa8795676b 89 }
leothedragon 0:25fa8795676b 90
leothedragon 0:25fa8795676b 91 static control_t download_2k(const size_t call_count) {
leothedragon 0:25fa8795676b 92 download_test(interface, story, sizeof(story), 2*1024);
leothedragon 0:25fa8795676b 93
leothedragon 0:25fa8795676b 94 return CaseNext;
leothedragon 0:25fa8795676b 95 }
leothedragon 0:25fa8795676b 96
leothedragon 0:25fa8795676b 97 static control_t download_4k(const size_t call_count) {
leothedragon 0:25fa8795676b 98 download_test(interface, story, sizeof(story), 4*1024);
leothedragon 0:25fa8795676b 99
leothedragon 0:25fa8795676b 100 return CaseNext;
leothedragon 0:25fa8795676b 101 }
leothedragon 0:25fa8795676b 102
leothedragon 0:25fa8795676b 103 utest::v1::status_t greentea_setup(const size_t number_of_cases) {
leothedragon 0:25fa8795676b 104 GREENTEA_SETUP(5*60, "default_auto");
leothedragon 0:25fa8795676b 105 return greentea_test_setup_handler(number_of_cases);
leothedragon 0:25fa8795676b 106 }
leothedragon 0:25fa8795676b 107
leothedragon 0:25fa8795676b 108 Case cases[] = {
leothedragon 0:25fa8795676b 109 Case(TEST_NETWORK_TYPE " network setup", setup_network),
leothedragon 0:25fa8795676b 110 Case(TEST_NETWORK_TYPE " 128 buffer", download_128),
leothedragon 0:25fa8795676b 111 #if MBED_CONF_TARGET_NETWORK_DEFAULT_INTERFACE_TYPE != CELLULAR
leothedragon 0:25fa8795676b 112 Case(TEST_NETWORK_TYPE " 256 buffer", download_256),
leothedragon 0:25fa8795676b 113 Case(TEST_NETWORK_TYPE " 1024 buffer", download_1k),
leothedragon 0:25fa8795676b 114 Case(TEST_NETWORK_TYPE " 4096 buffer", download_4k),
leothedragon 0:25fa8795676b 115 #endif
leothedragon 0:25fa8795676b 116 };
leothedragon 0:25fa8795676b 117
leothedragon 0:25fa8795676b 118 Specification specification(greentea_setup, cases);
leothedragon 0:25fa8795676b 119
leothedragon 0:25fa8795676b 120 int main() {
leothedragon 0:25fa8795676b 121 //Create a thread to blink an LED and signal that the device is alive
leothedragon 0:25fa8795676b 122 #if !defined(MBED_CONF_APP_NO_LED)
leothedragon 0:25fa8795676b 123 Ticker t;
leothedragon 0:25fa8795676b 124 t.attach(led_thread, 0.5);
leothedragon 0:25fa8795676b 125 #endif
leothedragon 0:25fa8795676b 126
leothedragon 0:25fa8795676b 127 return !Harness::run(specification);
leothedragon 0:25fa8795676b 128 }