1 | /*
|
---|
2 | Unix SMB/CIFS implementation.
|
---|
3 |
|
---|
4 | local test for messaging code
|
---|
5 |
|
---|
6 | Copyright (C) Andrew Tridgell 2004
|
---|
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 "lib/events/events.h"
|
---|
24 | #include "lib/messaging/irpc.h"
|
---|
25 | #include "torture/torture.h"
|
---|
26 | #include "cluster/cluster.h"
|
---|
27 | #include "param/param.h"
|
---|
28 |
|
---|
29 |
|
---|
30 | static uint32_t msg_pong;
|
---|
31 |
|
---|
32 | static void ping_message(struct messaging_context *msg, void *private_data,
|
---|
33 | uint32_t msg_type, struct server_id src, DATA_BLOB *data)
|
---|
34 | {
|
---|
35 | NTSTATUS status;
|
---|
36 | status = messaging_send(msg, src, msg_pong, data);
|
---|
37 | if (!NT_STATUS_IS_OK(status)) {
|
---|
38 | printf("pong failed - %s\n", nt_errstr(status));
|
---|
39 | }
|
---|
40 | }
|
---|
41 |
|
---|
42 | static void pong_message(struct messaging_context *msg, void *private_data,
|
---|
43 | uint32_t msg_type, struct server_id src, DATA_BLOB *data)
|
---|
44 | {
|
---|
45 | int *count = (int *)private_data;
|
---|
46 | (*count)++;
|
---|
47 | }
|
---|
48 |
|
---|
49 | static void exit_message(struct messaging_context *msg, void *private_data,
|
---|
50 | uint32_t msg_type, struct server_id src, DATA_BLOB *data)
|
---|
51 | {
|
---|
52 | talloc_free(private_data);
|
---|
53 | exit(0);
|
---|
54 | }
|
---|
55 |
|
---|
56 | /*
|
---|
57 | test ping speed
|
---|
58 | */
|
---|
59 | static bool test_ping_speed(struct torture_context *tctx)
|
---|
60 | {
|
---|
61 | struct tevent_context *ev;
|
---|
62 | struct messaging_context *msg_client_ctx;
|
---|
63 | struct messaging_context *msg_server_ctx;
|
---|
64 | int ping_count = 0;
|
---|
65 | int pong_count = 0;
|
---|
66 | struct timeval tv;
|
---|
67 | int timelimit = torture_setting_int(tctx, "timelimit", 10);
|
---|
68 | uint32_t msg_ping, msg_exit;
|
---|
69 |
|
---|
70 | lp_set_cmdline(tctx->lp_ctx, "pid directory", "piddir.tmp");
|
---|
71 |
|
---|
72 | ev = tctx->ev;
|
---|
73 |
|
---|
74 | msg_server_ctx = messaging_init(tctx,
|
---|
75 | lp_messaging_path(tctx, tctx->lp_ctx),
|
---|
76 | cluster_id(0, 1),
|
---|
77 | lp_iconv_convenience(tctx->lp_ctx),
|
---|
78 | ev);
|
---|
79 |
|
---|
80 | torture_assert(tctx, msg_server_ctx != NULL, "Failed to init ping messaging context");
|
---|
81 |
|
---|
82 | messaging_register_tmp(msg_server_ctx, NULL, ping_message, &msg_ping);
|
---|
83 | messaging_register_tmp(msg_server_ctx, tctx, exit_message, &msg_exit);
|
---|
84 |
|
---|
85 | msg_client_ctx = messaging_init(tctx,
|
---|
86 | lp_messaging_path(tctx, tctx->lp_ctx),
|
---|
87 | cluster_id(0, 2),
|
---|
88 | lp_iconv_convenience(tctx->lp_ctx),
|
---|
89 | ev);
|
---|
90 |
|
---|
91 | torture_assert(tctx, msg_client_ctx != NULL,
|
---|
92 | "msg_client_ctx messaging_init() failed");
|
---|
93 |
|
---|
94 | messaging_register_tmp(msg_client_ctx, &pong_count, pong_message, &msg_pong);
|
---|
95 |
|
---|
96 | tv = timeval_current();
|
---|
97 |
|
---|
98 | torture_comment(tctx, "Sending pings for %d seconds\n", timelimit);
|
---|
99 | while (timeval_elapsed(&tv) < timelimit) {
|
---|
100 | DATA_BLOB data;
|
---|
101 | NTSTATUS status1, status2;
|
---|
102 |
|
---|
103 | data.data = discard_const_p(uint8_t, "testing");
|
---|
104 | data.length = strlen((const char *)data.data);
|
---|
105 |
|
---|
106 | status1 = messaging_send(msg_client_ctx, cluster_id(0, 1), msg_ping, &data);
|
---|
107 | status2 = messaging_send(msg_client_ctx, cluster_id(0, 1), msg_ping, NULL);
|
---|
108 |
|
---|
109 | torture_assert_ntstatus_ok(tctx, status1, "msg1 failed");
|
---|
110 | ping_count++;
|
---|
111 |
|
---|
112 | torture_assert_ntstatus_ok(tctx, status2, "msg2 failed");
|
---|
113 | ping_count++;
|
---|
114 |
|
---|
115 | while (ping_count > pong_count + 20) {
|
---|
116 | event_loop_once(ev);
|
---|
117 | }
|
---|
118 | }
|
---|
119 |
|
---|
120 | torture_comment(tctx, "waiting for %d remaining replies (done %d)\n",
|
---|
121 | ping_count - pong_count, pong_count);
|
---|
122 | while (timeval_elapsed(&tv) < 30 && pong_count < ping_count) {
|
---|
123 | event_loop_once(ev);
|
---|
124 | }
|
---|
125 |
|
---|
126 | torture_comment(tctx, "sending exit\n");
|
---|
127 | messaging_send(msg_client_ctx, cluster_id(0, 1), msg_exit, NULL);
|
---|
128 |
|
---|
129 | torture_assert_int_equal(tctx, ping_count, pong_count, "ping test failed");
|
---|
130 |
|
---|
131 | torture_comment(tctx, "ping rate of %.0f messages/sec\n",
|
---|
132 | (ping_count+pong_count)/timeval_elapsed(&tv));
|
---|
133 |
|
---|
134 | talloc_free(msg_client_ctx);
|
---|
135 | talloc_free(msg_server_ctx);
|
---|
136 |
|
---|
137 | return true;
|
---|
138 | }
|
---|
139 |
|
---|
140 | struct torture_suite *torture_local_messaging(TALLOC_CTX *mem_ctx)
|
---|
141 | {
|
---|
142 | struct torture_suite *s = torture_suite_create(mem_ctx, "MESSAGING");
|
---|
143 | torture_suite_add_simple_test(s, "ping_speed", test_ping_speed);
|
---|
144 | return s;
|
---|
145 | }
|
---|