| 1 | /*
|
|---|
| 2 | Unix SMB/CIFS implementation.
|
|---|
| 3 |
|
|---|
| 4 | Example echo torture tests
|
|---|
| 5 |
|
|---|
| 6 | Copyright (C) 2010 Kai Blin <[email protected]>
|
|---|
| 7 |
|
|---|
| 8 | This program is free software; you can redistribute it and/or modify
|
|---|
| 9 | it under the terms of the GNU General Public License as published by
|
|---|
| 10 | the Free Software Foundation; either version 3 of the License, or
|
|---|
| 11 | (at your option) any later version.
|
|---|
| 12 |
|
|---|
| 13 | This program is distributed in the hope that it will be useful,
|
|---|
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 16 | GNU General Public License for more details.
|
|---|
| 17 |
|
|---|
| 18 | You should have received a copy of the GNU General Public License
|
|---|
| 19 | along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|---|
| 20 | */
|
|---|
| 21 |
|
|---|
| 22 | #include "includes.h"
|
|---|
| 23 | #include "torture/smbtorture.h"
|
|---|
| 24 | #include "libcli/resolve/resolve.h"
|
|---|
| 25 | #include <tevent.h>
|
|---|
| 26 | #include "libcli/util/ntstatus.h"
|
|---|
| 27 | #include "libcli/echo/libecho.h"
|
|---|
| 28 |
|
|---|
| 29 | NTSTATUS torture_libcli_echo_init(void);
|
|---|
| 30 |
|
|---|
| 31 | /* Basic test function that sends an echo request and checks the reply */
|
|---|
| 32 | static bool echo_udp_basic(struct torture_context *tctx, const char *address)
|
|---|
| 33 | {
|
|---|
| 34 | struct tevent_req *req;
|
|---|
| 35 | NTSTATUS status;
|
|---|
| 36 | const char *msg_send = "This is a test string\n";
|
|---|
| 37 | char *msg_recv;
|
|---|
| 38 |
|
|---|
| 39 | req = echo_request_send(tctx, tctx->ev, address, msg_send);
|
|---|
| 40 | torture_assert(tctx, req != NULL,
|
|---|
| 41 | "echo_request_send returned non-null tevent_req");
|
|---|
| 42 |
|
|---|
| 43 | while(tevent_req_is_in_progress(req)) {
|
|---|
| 44 | tevent_loop_once(tctx->ev);
|
|---|
| 45 | }
|
|---|
| 46 |
|
|---|
| 47 | status = echo_request_recv(req, tctx, &msg_recv);
|
|---|
| 48 | torture_assert_ntstatus_ok(tctx, status,
|
|---|
| 49 | "echo_request_recv returned ok");
|
|---|
| 50 |
|
|---|
| 51 | torture_assert_str_equal(tctx, msg_recv, msg_send,
|
|---|
| 52 | "Echo server echoed request string");
|
|---|
| 53 |
|
|---|
| 54 | return true;
|
|---|
| 55 | }
|
|---|
| 56 |
|
|---|
| 57 | /*Test case to set up the environment and perform UDP-based echo tests */
|
|---|
| 58 | static bool torture_echo_udp(struct torture_context *tctx)
|
|---|
| 59 | {
|
|---|
| 60 | const char *address;
|
|---|
| 61 | struct nbt_name name;
|
|---|
| 62 | NTSTATUS status;
|
|---|
| 63 | bool ret = true;
|
|---|
| 64 |
|
|---|
| 65 | make_nbt_name_server(&name,
|
|---|
| 66 | torture_setting_string(tctx, "host", NULL));
|
|---|
| 67 | status = resolve_name(lpcfg_resolve_context(tctx->lp_ctx), &name, tctx,
|
|---|
| 68 | &address, tctx->ev);
|
|---|
| 69 | if (!NT_STATUS_IS_OK(status)) {
|
|---|
| 70 | printf("Failed to resolve %s - %s\n", name.name,
|
|---|
| 71 | nt_errstr(status));
|
|---|
| 72 | return false;
|
|---|
| 73 | }
|
|---|
| 74 |
|
|---|
| 75 | /* All tests are now called here */
|
|---|
| 76 | ret &= echo_udp_basic(tctx, address);
|
|---|
| 77 |
|
|---|
| 78 | return ret;
|
|---|
| 79 | }
|
|---|
| 80 |
|
|---|
| 81 | /* Test suite that bundles all the libecho tests */
|
|---|
| 82 | NTSTATUS torture_libcli_echo_init(void)
|
|---|
| 83 | {
|
|---|
| 84 | struct torture_suite *suite;
|
|---|
| 85 |
|
|---|
| 86 | suite = torture_suite_create(talloc_autofree_context(), "echo");
|
|---|
| 87 | NT_STATUS_HAVE_NO_MEMORY(suite);
|
|---|
| 88 |
|
|---|
| 89 | torture_suite_add_simple_test(suite, "udp", torture_echo_udp);
|
|---|
| 90 |
|
|---|
| 91 | suite->description = talloc_strdup(suite, "libcli/echo interface tests");
|
|---|
| 92 | torture_register_suite(suite);
|
|---|
| 93 |
|
|---|
| 94 | return NT_STATUS_OK;
|
|---|
| 95 | }
|
|---|