summaryrefslogtreecommitdiffstats
path: root/libcli/echo/tests
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-05 17:47:29 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-05 17:47:29 +0000
commit4f5791ebd03eaec1c7da0865a383175b05102712 (patch)
tree8ce7b00f7a76baa386372422adebbe64510812d4 /libcli/echo/tests
parentInitial commit. (diff)
downloadsamba-upstream.tar.xz
samba-upstream.zip
Adding upstream version 2:4.17.12+dfsg.upstream/2%4.17.12+dfsgupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'libcli/echo/tests')
-rw-r--r--libcli/echo/tests/echo.c97
-rw-r--r--libcli/echo/tests/wscript_build8
2 files changed, 105 insertions, 0 deletions
diff --git a/libcli/echo/tests/echo.c b/libcli/echo/tests/echo.c
new file mode 100644
index 0000000..e465b99
--- /dev/null
+++ b/libcli/echo/tests/echo.c
@@ -0,0 +1,97 @@
+/*
+ Unix SMB/CIFS implementation.
+
+ Example echo torture tests
+
+ Copyright (C) 2010 Kai Blin <kai@samba.org>
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "includes.h"
+#include "torture/smbtorture.h"
+#include "libcli/resolve/resolve.h"
+#include <tevent.h>
+#include "libcli/util/ntstatus.h"
+#include "libcli/echo/libecho.h"
+
+NTSTATUS torture_libcli_echo_init(TALLOC_CTX *);
+
+/* Basic test function that sends an echo request and checks the reply */
+static bool echo_udp_basic(struct torture_context *tctx, const char *address)
+{
+ struct tevent_req *req;
+ NTSTATUS status;
+ const char *msg_send = "This is a test string\n";
+ char *msg_recv;
+
+ req = echo_request_send(tctx, tctx->ev, address, msg_send);
+ torture_assert(tctx, req != NULL,
+ "echo_request_send returned non-null tevent_req");
+
+ while(tevent_req_is_in_progress(req)) {
+ tevent_loop_once(tctx->ev);
+ }
+
+ status = echo_request_recv(req, tctx, &msg_recv);
+ torture_assert_ntstatus_ok(tctx, status,
+ "echo_request_recv returned ok");
+
+ torture_assert_str_equal(tctx, msg_recv, msg_send,
+ "Echo server echoed request string");
+
+ return true;
+}
+
+/*Test case to set up the environment and perform UDP-based echo tests */
+static bool torture_echo_udp(struct torture_context *tctx)
+{
+ const char *address;
+ struct nbt_name name;
+ NTSTATUS status;
+ bool ret = true;
+
+ make_nbt_name_server(&name,
+ torture_setting_string(tctx, "host", NULL));
+ status = resolve_name_ex(lpcfg_resolve_context(tctx->lp_ctx),
+ 0, 0,
+ &name, tctx,
+ &address, tctx->ev);
+ if (!NT_STATUS_IS_OK(status)) {
+ printf("Failed to resolve %s - %s\n", name.name,
+ nt_errstr(status));
+ return false;
+ }
+
+ /* All tests are now called here */
+ ret &= echo_udp_basic(tctx, address);
+
+ return ret;
+}
+
+/* Test suite that bundles all the libecho tests */
+NTSTATUS torture_libcli_echo_init(TALLOC_CTX *ctx)
+{
+ struct torture_suite *suite;
+
+ suite = torture_suite_create(ctx, "echo");
+ NT_STATUS_HAVE_NO_MEMORY(suite);
+
+ torture_suite_add_simple_test(suite, "udp", torture_echo_udp);
+
+ suite->description = talloc_strdup(suite, "libcli/echo interface tests");
+ torture_register_suite(ctx, suite);
+
+ return NT_STATUS_OK;
+}
diff --git a/libcli/echo/tests/wscript_build b/libcli/echo/tests/wscript_build
new file mode 100644
index 0000000..366c895
--- /dev/null
+++ b/libcli/echo/tests/wscript_build
@@ -0,0 +1,8 @@
+#!/usr/bin/env python
+
+bld.SAMBA_MODULE('TORTURE_LIBCLI_ECHO',
+ source='echo.c',
+ subsystem='smbtorture',
+ init_function='torture_libcli_echo_init',
+ deps='LIBTSOCKET tevent-util LIBCLI_ECHO',
+ internal_module=True);