From a00aa0a4607da8926a95b65d6a0e28c61eda073c Mon Sep 17 00:00:00 2001 From: henri Date: Thu, 5 Jun 2014 19:44:00 +0000 Subject: [PATCH] New nsock regression test: TestConnectFailure. Trigger a ENETUNREACH error on connect() and check if properly reported. As of now the test fails, the error isn't delivered. --- nsock/tests/connect.c | 22 ++++++++++++++++++++++ nsock/tests/tests_main.c | 2 ++ 2 files changed, 24 insertions(+) diff --git a/nsock/tests/connect.c b/nsock/tests/connect.c index d190da066..7fff6256e 100644 --- a/nsock/tests/connect.c +++ b/nsock/tests/connect.c @@ -80,6 +80,21 @@ static int connect_tcp(void *tdata) { return ctd->connect_result; } +static int connect_tcp_failure(void *tdata) { + struct connect_test_data *ctd = (struct connect_test_data *)tdata; + struct sockaddr_in peer; + + memset(&peer, 0, sizeof(peer)); + peer.sin_family = AF_INET; + inet_aton("192.0.2.1", &peer.sin_addr); /* Unreachable by RFC5737 */ + + nsock_connect_tcp(ctd->nsp, ctd->nsi, connect_handler, 4000, NULL, + (struct sockaddr *)&peer, sizeof(peer), PORT_TCP); + + nsock_loop(ctd->nsp, 4000); + return ctd->connect_result == -ENETUNREACH ? 0 : ctd->connect_result; +} + const struct test_case TestConnectTCP = { .t_name = "simple tcp connection", @@ -87,3 +102,10 @@ const struct test_case TestConnectTCP = { .t_run = connect_tcp, .t_teardown = connect_teardown }; + +const struct test_case TestConnectFailure = { + .t_name = "tcp connection failure case", + .t_setup = connect_setup, + .t_run = connect_tcp_failure, + .t_teardown = connect_teardown +}; diff --git a/nsock/tests/tests_main.c b/nsock/tests/tests_main.c index a88f612ee..192aa8036 100644 --- a/nsock/tests/tests_main.c +++ b/nsock/tests/tests_main.c @@ -30,6 +30,7 @@ extern const struct test_case TestTimer; extern const struct test_case TestLogLevels; extern const struct test_case TestErrLevels; extern const struct test_case TestConnectTCP; +extern const struct test_case TestConnectFailure; extern const struct test_case TestGHLists; extern const struct test_case TestGHHeaps; extern const struct test_case TestHeapOrdering; @@ -48,6 +49,7 @@ static const struct test_case *TestCases[] = { &TestErrLevels, /* ---- connect.c */ &TestConnectTCP, + &TestConnectFailure, /* ---- ghlists.c */ &TestGHLists, /* ---- ghheaps.c */