summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVolker Lendecke <vl@samba.org>2023-03-06 10:05:41 +0100
committerJule Anger <janger@samba.org>2023-03-07 10:13:09 +0000
commit529e76a51dfde8218362ce478e852f53553332d7 (patch)
treee86ebb17f2cf2d9542f46127c90bdd7fa03b8a34
parentf07883a09eae34e78dd5d765a56c6d55ec97fb27 (diff)
downloadsamba-529e76a51dfde8218362ce478e852f53553332d7.tar.gz
torture3: test rpc scalability
With smbtorture3 //127.0.0.1/ipc\$ rpc-scale -N 50 -o 1000 I am able to immediately trigger bug 15130. Not running by default, this is a pure load test. BUG: https://bugzilla.samba.org/show_bug.cgi?id=15310 Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org> (back-ported from commit 86e95b57d6848482dc73c624c2e8d2bdb79c1d21)
-rw-r--r--source3/torture/proto.h1
-rw-r--r--source3/torture/test_rpc_scale.c301
-rw-r--r--source3/torture/torture.c4
-rw-r--r--source3/torture/wscript_build1
4 files changed, 307 insertions, 0 deletions
diff --git a/source3/torture/proto.h b/source3/torture/proto.h
index 551c4ea80ac..4fa2fbd12a1 100644
--- a/source3/torture/proto.h
+++ b/source3/torture/proto.h
@@ -167,5 +167,6 @@ bool run_local_idmap_cache1(int dummy);
bool run_hidenewfiles(int dummy);
bool run_readdir_timestamp(int dummy);
bool run_ctdbd_conn1(int dummy);
+bool run_rpc_scale(int dummy);
#endif /* __TORTURE_H__ */
diff --git a/source3/torture/test_rpc_scale.c b/source3/torture/test_rpc_scale.c
new file mode 100644
index 00000000000..6ef26f37a99
--- /dev/null
+++ b/source3/torture/test_rpc_scale.c
@@ -0,0 +1,301 @@
+/*
+ * 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 <http://www.gnu.org/licenses/>.
+ */
+
+#include "source3/include/includes.h"
+#include "source3/torture/proto.h"
+#include "source3/libsmb/libsmb.h"
+#include "librpc/gen_ndr/ndr_spoolss_c.h"
+#include "lib/util/tevent_ntstatus.h"
+#include "source3/rpc_client/rpc_client.h"
+#include "source3/rpc_client/cli_pipe.h"
+#include "libcli/smb/smbXcli_base.h"
+
+extern int torture_nprocs;
+extern int torture_numops;
+
+struct rpc_scale_one_state {
+ struct tevent_context *ev;
+ struct cli_state *cli;
+ size_t num_iterations;
+ struct rpc_pipe_client *rpccli;
+ DATA_BLOB buffer;
+ uint32_t needed;
+ uint32_t num_printers;
+ union spoolss_PrinterInfo *printers;
+};
+
+static void rpc_scale_one_opened(struct tevent_req *subreq);
+static void rpc_scale_one_bound(struct tevent_req *subreq);
+static void rpc_scale_one_listed(struct tevent_req *subreq);
+
+static struct tevent_req *rpc_scale_one_send(
+ TALLOC_CTX *mem_ctx,
+ struct tevent_context *ev,
+ struct cli_state *cli,
+ size_t num_iterations)
+{
+ struct tevent_req *req = NULL, *subreq = NULL;
+ struct rpc_scale_one_state *state = NULL;
+
+ req = tevent_req_create(mem_ctx, &state, struct rpc_scale_one_state);
+ if (req == NULL) {
+ return NULL;
+ }
+ state->ev = ev;
+ state->cli = cli;
+ state->num_iterations = num_iterations;
+
+ subreq = rpc_pipe_open_np_send(
+ state, ev, cli, &ndr_table_spoolss);
+ if (tevent_req_nomem(subreq, req)) {
+ return tevent_req_post(req, ev);
+ }
+ tevent_req_set_callback(subreq, rpc_scale_one_opened, req);
+ return req;
+}
+
+static void rpc_scale_one_opened(struct tevent_req *subreq)
+{
+ struct tevent_req *req = tevent_req_callback_data(
+ subreq, struct tevent_req);
+ struct rpc_scale_one_state *state = tevent_req_data(
+ req, struct rpc_scale_one_state);
+ struct pipe_auth_data *auth = NULL;
+ NTSTATUS status;
+
+ status = rpc_pipe_open_np_recv(subreq, state, &state->rpccli);
+ TALLOC_FREE(subreq);
+ if (tevent_req_nterror(req, status)) {
+ return;
+ }
+
+ status = rpccli_anon_bind_data(state, &auth);
+ if (tevent_req_nterror(req, status)) {
+ return;
+ }
+
+ subreq = rpc_pipe_bind_send(state, state->ev, state->rpccli, auth);
+ if (tevent_req_nomem(subreq, req)) {
+ return;
+ }
+ tevent_req_set_callback(subreq, rpc_scale_one_bound, req);
+}
+
+static void rpc_scale_one_bound(struct tevent_req *subreq)
+{
+ struct tevent_req *req = tevent_req_callback_data(
+ subreq, struct tevent_req);
+ struct rpc_scale_one_state *state = tevent_req_data(
+ req, struct rpc_scale_one_state);
+ char *server = NULL;
+ NTSTATUS status;
+
+ status = rpc_pipe_bind_recv(subreq);
+ if (tevent_req_nterror(req, status)) {
+ return;
+ }
+
+ server = talloc_asprintf(
+ state,
+ "\\%s\n",
+ smbXcli_conn_remote_name(state->cli->conn));
+ if (tevent_req_nomem(server, req)) {
+ return;
+ }
+ state->buffer = data_blob_talloc(state, NULL, 4096);
+ if (tevent_req_nomem(state->buffer.data, req)) {
+ return;
+ }
+
+ subreq = dcerpc_spoolss_EnumPrinters_send(
+ state,
+ state->ev,
+ state->rpccli->binding_handle,
+ PRINTER_ENUM_LOCAL,
+ server,
+ 1, /* level */
+ &state->buffer,
+ state->buffer.length,
+ &state->num_printers,
+ &state->printers,
+ &state->needed);
+ if (tevent_req_nomem(subreq, req)) {
+ return;
+ }
+ tevent_req_set_callback(subreq, rpc_scale_one_listed, req);
+}
+
+static void rpc_scale_one_listed(struct tevent_req *subreq)
+{
+ struct tevent_req *req = tevent_req_callback_data(
+ subreq, struct tevent_req);
+ struct rpc_scale_one_state *state = tevent_req_data(
+ req, struct rpc_scale_one_state);
+ NTSTATUS status;
+ WERROR result;
+
+ status = dcerpc_spoolss_EnumPrinters_recv(subreq, state, &result);
+ if (tevent_req_nterror(req, status)) {
+ return;
+ }
+
+ if (!W_ERROR_IS_OK(result)) {
+ status = werror_to_ntstatus(result);
+ tevent_req_nterror(req, status);
+ return;
+ }
+
+ /*
+ * This will trigger a sync close. Making that async will be a
+ * lot of effort, and even with this being sync this test is
+ * nasty enough.
+ */
+ TALLOC_FREE(state->rpccli);
+
+ state->num_iterations -= 1;
+
+ if (state->num_iterations == 0) {
+ tevent_req_done(req);
+ return;
+ }
+
+ subreq = rpc_pipe_open_np_send(
+ state, state->ev, state->cli, &ndr_table_spoolss);
+ if (tevent_req_nomem(subreq, req)) {
+ return;
+ }
+ tevent_req_set_callback(subreq, rpc_scale_one_opened, req);
+}
+
+static NTSTATUS rpc_scale_one_recv(struct tevent_req *req)
+{
+ return tevent_req_simple_recv_ntstatus(req);
+}
+
+struct rpc_scale_state {
+ size_t num_reqs;
+ size_t done;
+};
+
+static void rpc_scale_done(struct tevent_req *subreq);
+
+static struct tevent_req *rpc_scale_send(
+ TALLOC_CTX *mem_ctx,
+ struct tevent_context *ev,
+ struct cli_state **clis)
+{
+ struct tevent_req *req = NULL;
+ struct rpc_scale_state *state = NULL;
+ size_t i, num_clis = talloc_array_length(clis);
+
+ req = tevent_req_create(mem_ctx, &state, struct rpc_scale_state);
+ if (req == NULL) {
+ return NULL;
+ }
+ state->num_reqs = num_clis;
+
+ for (i=0; i<num_clis; i++) {
+ struct tevent_req *subreq = rpc_scale_one_send(
+ state, ev, clis[i], torture_numops);
+ if (tevent_req_nomem(subreq, req)) {
+ return tevent_req_post(req, ev);
+ }
+ tevent_req_set_callback(subreq, rpc_scale_done, req);
+ }
+ return req;
+}
+
+static void rpc_scale_done(struct tevent_req *subreq)
+{
+ struct tevent_req *req = tevent_req_callback_data(
+ subreq, struct tevent_req);
+ struct rpc_scale_state *state = tevent_req_data(
+ req, struct rpc_scale_state);
+ NTSTATUS status;
+
+ status = rpc_scale_one_recv(subreq);
+ TALLOC_FREE(subreq);
+ if (tevent_req_nterror(req, status)) {
+ return;
+ }
+
+ state->done += 1;
+
+ if (state->done == state->num_reqs) {
+ tevent_req_done(req);
+ }
+}
+
+static NTSTATUS rpc_scale_recv(struct tevent_req *req)
+{
+ return tevent_req_simple_recv_ntstatus(req);
+}
+
+bool run_rpc_scale(int dummy)
+{
+ TALLOC_CTX *frame = talloc_stackframe();
+ struct cli_state **clis = NULL;
+ struct tevent_req *req = NULL;
+ struct tevent_context *ev = NULL;
+ bool ok, result = false;
+ NTSTATUS status;
+ int i;
+
+ clis = talloc_zero_array(
+ talloc_tos(), struct cli_state *, torture_nprocs);
+ if (clis == NULL) {
+ fprintf(stderr, "talloc failed\n");
+ goto fail;
+ }
+
+ for (i=0; i<torture_nprocs; i++) {
+ ok = torture_open_connection_flags(&clis[i], i, 0);
+ if (!ok) {
+ fprintf(stderr, "could not open connection %d\n", i);
+ goto fail;
+ }
+ }
+
+ ev = samba_tevent_context_init(talloc_tos());
+ if (ev == NULL) {
+ goto fail;
+ }
+
+ req = rpc_scale_send(talloc_tos(), ev, clis);
+ if (req == NULL) {
+ goto fail;
+ }
+
+ ok = tevent_req_poll_ntstatus(req, ev, &status);
+ if (!ok) {
+ fprintf(stderr,
+ "rpc_scale_send failed: %s\n",
+ nt_errstr(status));
+ goto fail;
+ }
+
+ status = rpc_scale_recv(req);
+ if (!NT_STATUS_IS_OK(status)) {
+ fprintf(stderr, "rpc_scale failed: %s\n", nt_errstr(status));
+ goto fail;
+ }
+
+ result = true;
+fail:
+ TALLOC_FREE(frame);
+ return result;
+}
diff --git a/source3/torture/torture.c b/source3/torture/torture.c
index af28b171cf1..cd32156ae42 100644
--- a/source3/torture/torture.c
+++ b/source3/torture/torture.c
@@ -15593,6 +15593,10 @@ static struct {
.fn = run_readdir_timestamp,
},
{
+ .name = "rpc-scale",
+ .fn = run_rpc_scale,
+ },
+ {
.name = NULL,
},
};
diff --git a/source3/torture/wscript_build b/source3/torture/wscript_build
index b9241d14a40..bb9091448af 100644
--- a/source3/torture/wscript_build
+++ b/source3/torture/wscript_build
@@ -57,6 +57,7 @@ bld.SAMBA3_BINARY('smbtorture' + bld.env.suffix3,
test_idmap_cache.c
test_hidenewfiles.c
test_readdir_timestamp.c
+ test_rpc_scale.c
../lib/util_sd.c
''' + TORTURE3_ADDITIONAL_SOURCE,
deps='''