From: Volker Lendecke Date: Wed, 31 Mar 2021 11:22:16 +0000 (+0000) Subject: test: Add a test for background_job_send crash X-Git-Tag: tevent-0.11.0~1330 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=6f4e6fc631a4f43d22fe65cd53daf635b4324d53;p=thirdparty%2Fsamba.git test: Add a test for background_job_send crash I haven't figured out how to properly add a crashing test to "knownfail", so this is added after the fix. Signed-off-by: Volker Lendecke --- diff --git a/selftest/tests.py b/selftest/tests.py index 6bf46ae5621..9685a744d0d 100644 --- a/selftest/tests.py +++ b/selftest/tests.py @@ -378,6 +378,12 @@ plantestsuite("samba.unittests.sambafs_srv_pipe", "none", [os.path.join(bindir(), "default/testsuite/unittests/test_sambafs_srv_pipe")]) plantestsuite("samba.unittests.lib_util_modules", "none", [os.path.join(bindir(), "default/testsuite/unittests/test_lib_util_modules")]) +plantestsuite("samba.unittests.background_send", + "none", + [os.path.join( + bindir(), + "default/testsuite/unittests/test_background_send"), + "$SMB_CONF_PATH"]) plantestsuite("samba.unittests.smb1cli_session", "none", [os.path.join(bindir(), "default/libcli/smb/test_smb1cli_session")]) diff --git a/testsuite/unittests/test_background_send.c b/testsuite/unittests/test_background_send.c new file mode 100644 index 00000000000..ea654287305 --- /dev/null +++ b/testsuite/unittests/test_background_send.c @@ -0,0 +1,82 @@ +/* + * Unix SMB/CIFS implementation. + * + * 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 . + */ + +#include "replace.h" +#include +#include "source3/lib/background.h" +#include "source3/include/messages.h" +#include "lib/util/talloc_stack.h" +#include "source3/param/loadparm.h" +#include "dynconfig/dynconfig.h" + +static int bg_trigger(void *private_data) +{ + return 1; +} + +static void test_background_send(void) +{ + TALLOC_CTX *frame = talloc_stackframe(); + struct tevent_context *ev = NULL; + struct messaging_context *msg_ctx = NULL; + struct tevent_req *req = NULL; + uint32_t ping_msg = MSG_PING; + + ev = tevent_context_init(frame); + assert(ev != NULL); + + msg_ctx = messaging_init(frame, ev); + assert(msg_ctx != NULL); + + req = background_job_send( + frame, ev, msg_ctx, &ping_msg, 1, 0, bg_trigger, NULL); + assert(req != NULL); + + /* + * Here's the core of this test: TALLOC_FREE msg_ctx before + * req. This happens if you use background_job_send() smbd and + * don't manually TALLOC_FREE req before exit_server() + */ + TALLOC_FREE(msg_ctx); + TALLOC_FREE(req); + + TALLOC_FREE(frame); +} + +int main(int argc, const char *argv[]) +{ + const char testname[] = "test_background_send"; + bool ok; + + if (argc != 2) { + fprintf(stderr, "usage: %s \n", argv[0]); + return 1; + } + + printf("test: %s\n", testname); + + ok = lp_load_initial_only(argv[1]); + if (!ok) { + fprintf(stderr, "lp_load_initial_only(%s) failed\n", argv[1]); + return 1; + } + + test_background_send(); /* crashes on failure */ + + printf("success: %s\n", testname); + return 0; +} diff --git a/testsuite/unittests/wscript b/testsuite/unittests/wscript index 2b4b37b92de..f0cda5bcdc1 100644 --- a/testsuite/unittests/wscript +++ b/testsuite/unittests/wscript @@ -28,6 +28,13 @@ def build(bld): ''', for_selftest=True) + bld.SAMBA_BINARY('test_background_send', + source='test_background_send.c', + deps=''' + samba3core + ''', + for_selftest=True) + bld.SAMBA_MODULE('rpc_test_dummy_module', source='rpc_test_dummy_module.c', deps='ndr smbd_base',