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.
esp8266-driver/TESTS/net/connectivity/main.cpp@0:8f8e8f3cbd1c, 2018-06-21 (annotated)
- Committer:
- mayur098
- Date:
- Thu Jun 21 17:50:21 2018 +0000
- Revision:
- 0:8f8e8f3cbd1c
first commit;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mayur098 | 0:8f8e8f3cbd1c | 1 | #include "mbed.h" |
mayur098 | 0:8f8e8f3cbd1c | 2 | #include "greentea-client/test_env.h" |
mayur098 | 0:8f8e8f3cbd1c | 3 | #include "unity.h" |
mayur098 | 0:8f8e8f3cbd1c | 4 | #include "utest.h" |
mayur098 | 0:8f8e8f3cbd1c | 5 | |
mayur098 | 0:8f8e8f3cbd1c | 6 | #include "ESP8266Interface.h" |
mayur098 | 0:8f8e8f3cbd1c | 7 | |
mayur098 | 0:8f8e8f3cbd1c | 8 | using namespace utest::v1; |
mayur098 | 0:8f8e8f3cbd1c | 9 | |
mayur098 | 0:8f8e8f3cbd1c | 10 | #ifndef MBED_CFG_ESP8266_TX |
mayur098 | 0:8f8e8f3cbd1c | 11 | #define MBED_CFG_ESP8266_TX D1 |
mayur098 | 0:8f8e8f3cbd1c | 12 | #endif |
mayur098 | 0:8f8e8f3cbd1c | 13 | |
mayur098 | 0:8f8e8f3cbd1c | 14 | #ifndef MBED_CFG_ESP8266_RX |
mayur098 | 0:8f8e8f3cbd1c | 15 | #define MBED_CFG_ESP8266_RX D0 |
mayur098 | 0:8f8e8f3cbd1c | 16 | #endif |
mayur098 | 0:8f8e8f3cbd1c | 17 | |
mayur098 | 0:8f8e8f3cbd1c | 18 | #ifndef MBED_CFG_ESP8266_DEBUG |
mayur098 | 0:8f8e8f3cbd1c | 19 | #define MBED_CFG_ESP8266_DEBUG false |
mayur098 | 0:8f8e8f3cbd1c | 20 | #endif |
mayur098 | 0:8f8e8f3cbd1c | 21 | |
mayur098 | 0:8f8e8f3cbd1c | 22 | #define STRINGIZE(x) STRINGIZE2(x) |
mayur098 | 0:8f8e8f3cbd1c | 23 | #define STRINGIZE2(x) #x |
mayur098 | 0:8f8e8f3cbd1c | 24 | |
mayur098 | 0:8f8e8f3cbd1c | 25 | |
mayur098 | 0:8f8e8f3cbd1c | 26 | // Bringing the network up and down |
mayur098 | 0:8f8e8f3cbd1c | 27 | template <int COUNT> |
mayur098 | 0:8f8e8f3cbd1c | 28 | void test_bring_up_down() { |
mayur098 | 0:8f8e8f3cbd1c | 29 | ESP8266Interface net(MBED_CFG_ESP8266_TX, MBED_CFG_ESP8266_RX, MBED_CFG_ESP8266_DEBUG); |
mayur098 | 0:8f8e8f3cbd1c | 30 | net.set_credentials(STRINGIZE(MBED_CFG_ESP8266_SSID), STRINGIZE(MBED_CFG_ESP8266_PASS)); |
mayur098 | 0:8f8e8f3cbd1c | 31 | |
mayur098 | 0:8f8e8f3cbd1c | 32 | for (int i = 0; i < COUNT; i++) { |
mayur098 | 0:8f8e8f3cbd1c | 33 | int err = net.connect(); |
mayur098 | 0:8f8e8f3cbd1c | 34 | TEST_ASSERT_EQUAL(0, err); |
mayur098 | 0:8f8e8f3cbd1c | 35 | |
mayur098 | 0:8f8e8f3cbd1c | 36 | printf("MBED: IP Address %s\r\n", net.get_ip_address()); |
mayur098 | 0:8f8e8f3cbd1c | 37 | printf("MBED: Netmask %s\r\n", net.get_netmask()); |
mayur098 | 0:8f8e8f3cbd1c | 38 | printf("MBED: Gateway %s\r\n", net.get_gateway()); |
mayur098 | 0:8f8e8f3cbd1c | 39 | TEST_ASSERT(net.get_ip_address()); |
mayur098 | 0:8f8e8f3cbd1c | 40 | TEST_ASSERT(net.get_netmask()); |
mayur098 | 0:8f8e8f3cbd1c | 41 | TEST_ASSERT(net.get_gateway()); |
mayur098 | 0:8f8e8f3cbd1c | 42 | |
mayur098 | 0:8f8e8f3cbd1c | 43 | UDPSocket udp; |
mayur098 | 0:8f8e8f3cbd1c | 44 | err = udp.open(&net); |
mayur098 | 0:8f8e8f3cbd1c | 45 | TEST_ASSERT_EQUAL(0, err); |
mayur098 | 0:8f8e8f3cbd1c | 46 | err = udp.close(); |
mayur098 | 0:8f8e8f3cbd1c | 47 | TEST_ASSERT_EQUAL(0, err); |
mayur098 | 0:8f8e8f3cbd1c | 48 | |
mayur098 | 0:8f8e8f3cbd1c | 49 | TCPSocket tcp; |
mayur098 | 0:8f8e8f3cbd1c | 50 | err = tcp.open(&net); |
mayur098 | 0:8f8e8f3cbd1c | 51 | TEST_ASSERT_EQUAL(0, err); |
mayur098 | 0:8f8e8f3cbd1c | 52 | err = tcp.close(); |
mayur098 | 0:8f8e8f3cbd1c | 53 | TEST_ASSERT_EQUAL(0, err); |
mayur098 | 0:8f8e8f3cbd1c | 54 | |
mayur098 | 0:8f8e8f3cbd1c | 55 | err = net.disconnect(); |
mayur098 | 0:8f8e8f3cbd1c | 56 | TEST_ASSERT_EQUAL(0, err); |
mayur098 | 0:8f8e8f3cbd1c | 57 | } |
mayur098 | 0:8f8e8f3cbd1c | 58 | } |
mayur098 | 0:8f8e8f3cbd1c | 59 | |
mayur098 | 0:8f8e8f3cbd1c | 60 | |
mayur098 | 0:8f8e8f3cbd1c | 61 | // Test setup |
mayur098 | 0:8f8e8f3cbd1c | 62 | utest::v1::status_t test_setup(const size_t number_of_cases) { |
mayur098 | 0:8f8e8f3cbd1c | 63 | GREENTEA_SETUP(120, "default_auto"); |
mayur098 | 0:8f8e8f3cbd1c | 64 | return verbose_test_setup_handler(number_of_cases); |
mayur098 | 0:8f8e8f3cbd1c | 65 | } |
mayur098 | 0:8f8e8f3cbd1c | 66 | |
mayur098 | 0:8f8e8f3cbd1c | 67 | Case cases[] = { |
mayur098 | 0:8f8e8f3cbd1c | 68 | Case("Bringing the network up and down", test_bring_up_down<1>), |
mayur098 | 0:8f8e8f3cbd1c | 69 | Case("Bringing the network up and down twice", test_bring_up_down<2>), |
mayur098 | 0:8f8e8f3cbd1c | 70 | }; |
mayur098 | 0:8f8e8f3cbd1c | 71 | |
mayur098 | 0:8f8e8f3cbd1c | 72 | Specification specification(test_setup, cases); |
mayur098 | 0:8f8e8f3cbd1c | 73 | |
mayur098 | 0:8f8e8f3cbd1c | 74 | int main() { |
mayur098 | 0:8f8e8f3cbd1c | 75 | return !Harness::run(specification); |
mayur098 | 0:8f8e8f3cbd1c | 76 | } |