2 Unix SMB/CIFS implementation.
4 Example echo torture tests
6 Copyright (C) 2010 Kai Blin <kai@samba.org>
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.
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.
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/>.
23 #include "torture/smbtorture.h"
24 #include "libcli/resolve/resolve.h"
26 #include "libcli/util/ntstatus.h"
27 #include "libcli/echo/libecho.h"
29 /* Basic test function that sends an echo request and checks the reply */
30 static bool echo_udp_basic(struct torture_context *tctx, const char *address)
32 struct tevent_req *req;
34 const char *msg_send = "This is a test string\n";
37 req = echo_request_send(tctx, tctx->ev, address, msg_send);
38 torture_assert(tctx, req != NULL,
39 "echo_request_send returned non-null tevent_req");
41 while(tevent_req_is_in_progress(req)) {
42 tevent_loop_once(tctx->ev);
45 status = echo_request_recv(req, tctx, &msg_recv);
46 torture_assert_ntstatus_ok(tctx, status,
47 "echo_request_recv returned ok");
49 torture_assert_str_equal(tctx, msg_recv, msg_send,
50 "Echo server echoed request string");
55 /*Test case to set up the environment and perform UDP-based echo tests */
56 static bool torture_echo_udp(struct torture_context *tctx)
63 make_nbt_name_server(&name,
64 torture_setting_string(tctx, "host", NULL));
65 status = resolve_name(lpcfg_resolve_context(tctx->lp_ctx), &name, tctx,
67 if (!NT_STATUS_IS_OK(status)) {
68 printf("Failed to resolve %s - %s\n", name.name,
73 /* All tests are now called here */
74 ret &= echo_udp_basic(tctx, address);
79 /* Test suite that bundles all the libecho tests */
80 NTSTATUS torture_libcli_echo_init(void)
82 struct torture_suite *suite;
84 suite = torture_suite_create(talloc_autofree_context(), "echo");
85 NT_STATUS_HAVE_NO_MEMORY(suite);
87 torture_suite_add_simple_test(suite, "udp", torture_echo_udp);
89 suite->description = talloc_strdup(suite, "libcli/echo interface tests");
90 torture_register_suite(suite);