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