ctdb-client: Remove client code for old event daemon
[Samba.git] / ctdb / tests / src / protocol_event_test.c
blob46123b4eeeacfdf13a71e4494415feaa956cd446
1 /*
2 protocol types tests
4 Copyright (C) Amitay Isaacs 2015
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, see <http://www.gnu.org/licenses/>.
20 #include <assert.h>
22 #include "protocol/protocol_basic.c"
23 #include "protocol/protocol_types.c"
24 #include "protocol/protocol_event.c"
25 #include "protocol/protocol_packet.c"
26 #include "protocol/protocol_sock.c"
28 #include "tests/src/protocol_common.h"
29 #include "tests/src/protocol_common_event.h"
31 #define REQID 0x34567890
35 * Functions to test eventd protocol marshalling
38 /* for ctdb_event_request_data, ctdb_event_reply_data */
39 #define PROTOCOL_EVENT1_TEST(TYPE, NAME) \
40 static void TEST_FUNC(NAME)(uint32_t command) \
41 { \
42 TALLOC_CTX *mem_ctx; \
43 TYPE c1, c2; \
44 uint8_t *buf; \
45 size_t buflen, np; \
46 int ret; \
48 printf("%s %u\n", #NAME, command); \
49 fflush(stdout); \
50 mem_ctx = talloc_new(NULL); \
51 assert(mem_ctx != NULL); \
52 FILL_FUNC(NAME)(mem_ctx, &c1, command); \
53 buflen = LEN_FUNC(NAME)(&c1); \
54 buf = talloc_size(mem_ctx, buflen); \
55 assert(buf != NULL); \
56 np = 0; \
57 PUSH_FUNC(NAME)(&c1, buf, &np); \
58 assert(np == buflen); \
59 np = 0; \
60 ret = PULL_FUNC(NAME)(buf, buflen, mem_ctx, &c2, &np); \
61 assert(ret == 0); \
62 assert(np == buflen); \
63 VERIFY_FUNC(NAME)(&c1, &c2); \
64 talloc_free(mem_ctx); \
67 #define PROTOCOL_EVENT2_TEST(TYPE, NAME) \
68 static void TEST_FUNC(NAME)(uint32_t command) \
69 { \
70 TALLOC_CTX *mem_ctx; \
71 TYPE c1, c2; \
72 uint8_t *buf; \
73 size_t buflen, len; \
74 int ret; \
76 printf("%s %u\n", #NAME, command); \
77 fflush(stdout); \
78 mem_ctx = talloc_new(NULL); \
79 assert(mem_ctx != NULL); \
80 FILL_FUNC(NAME)(mem_ctx, &c1, command); \
81 buflen = LEN_FUNC(NAME)(&c1); \
82 buf = talloc_size(mem_ctx, buflen); \
83 assert(buf != NULL); \
84 len = 0; \
85 ret = PUSH_FUNC(NAME)(&c1, buf, &len); \
86 assert(ret == EMSGSIZE); \
87 assert(len == buflen); \
88 ret = PUSH_FUNC(NAME)(&c1, buf, &buflen); \
89 assert(ret == 0); \
90 ret = PULL_FUNC(NAME)(buf, buflen, mem_ctx, &c2); \
91 assert(ret == 0); \
92 assert(c2.header.length == buflen); \
93 VERIFY_FUNC(NAME)(&c1, &c2); \
94 talloc_free(mem_ctx); \
97 #define NUM_COMMANDS 5
99 PROTOCOL_TYPE3_TEST(struct ctdb_event_request_run, ctdb_event_request_run);
100 PROTOCOL_TYPE3_TEST(struct ctdb_event_request_status,
101 ctdb_event_request_status);
102 PROTOCOL_TYPE3_TEST(struct ctdb_event_request_script_enable,
103 ctdb_event_request_script_enable);
104 PROTOCOL_TYPE3_TEST(struct ctdb_event_request_script_disable,
105 ctdb_event_request_script_disable);
106 PROTOCOL_TYPE3_TEST(struct ctdb_event_reply_status, ctdb_event_reply_status);
107 PROTOCOL_TYPE3_TEST(struct ctdb_event_reply_script_list,
108 ctdb_event_reply_script_list);
110 PROTOCOL_EVENT1_TEST(struct ctdb_event_request_data, ctdb_event_request_data);
111 PROTOCOL_EVENT1_TEST(struct ctdb_event_reply_data, ctdb_event_reply_data);
112 PROTOCOL_EVENT2_TEST(struct ctdb_event_request, ctdb_event_request);
113 PROTOCOL_EVENT2_TEST(struct ctdb_event_reply, ctdb_event_reply);
115 int main(int argc, char *argv[])
117 uint32_t command;
119 if (argc == 2) {
120 int seed = atoi(argv[1]);
121 srandom(seed);
124 TEST_FUNC(ctdb_event_request_run)();
125 TEST_FUNC(ctdb_event_request_status)();
126 TEST_FUNC(ctdb_event_request_script_enable)();
127 TEST_FUNC(ctdb_event_request_script_disable)();
128 TEST_FUNC(ctdb_event_reply_status)();
129 TEST_FUNC(ctdb_event_reply_script_list)();
131 for (command=1; command<=NUM_COMMANDS; command++) {
132 TEST_FUNC(ctdb_event_request_data)(command);
134 for (command=1; command<=NUM_COMMANDS; command++) {
135 TEST_FUNC(ctdb_event_reply_data)(command);
138 for (command=1; command<=NUM_COMMANDS; command++) {
139 TEST_FUNC(ctdb_event_request)(command);
141 for (command=1; command<=NUM_COMMANDS; command++) {
142 TEST_FUNC(ctdb_event_reply)(command);
145 return 0;