Fix build error.
[openais.git] / test / testevs.c
blob7ce43b070bd92530066875eea15e8673fe22314b
1 /*
2 * Copyright (c) 2004 MontaVista Software, Inc.
3 * Copyright (c) 2006 Sun Microsystems, Inc.
5 * All rights reserved.
7 * Author: Steven Dake (sdake@mvista.com)
9 * This software licensed under BSD license, the text of which follows:
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions are met:
14 * - Redistributions of source code must retain the above copyright notice,
15 * this list of conditions and the following disclaimer.
16 * - Redistributions in binary form must reproduce the above copyright notice,
17 * this list of conditions and the following disclaimer in the documentation
18 * and/or other materials provided with the distribution.
19 * - Neither the name of the MontaVista Software, Inc. nor the names of its
20 * contributors may be used to endorse or promote products derived from this
21 * software without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
27 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
33 * THE POSSIBILITY OF SUCH DAMAGE.
35 #include <stdio.h>
36 #include <stdlib.h>
37 #include <sys/socket.h>
38 #include <netinet/in.h>
39 #include <arpa/inet.h>
40 #include <errno.h>
41 #include "../include/evs.h"
43 char *delivery_string;
45 int deliveries = 0;
46 void evs_deliver_fn (
47 unsigned int nodeid,
48 void *msg,
49 int msg_len)
51 char *buf = msg;
53 // buf += 100000;
54 // printf ("Delivery callback\n");
55 printf ("API '%s' msg '%s'\n", delivery_string, buf);
56 deliveries++;
59 void evs_confchg_fn (
60 unsigned int *member_list, int member_list_entries,
61 unsigned int *left_list, int left_list_entries,
62 unsigned int *joined_list, int joined_list_entries)
64 int i;
66 printf ("CONFIGURATION CHANGE\n");
67 printf ("--------------------\n");
68 printf ("New configuration\n");
69 for (i = 0; i < member_list_entries; i++) {
70 printf ("%x\n", member_list[i]);
72 printf ("Members Left:\n");
73 for (i = 0; i < left_list_entries; i++) {
74 printf ("%x\n", left_list[i]);
76 printf ("Members Joined:\n");
77 for (i = 0; i < joined_list_entries; i++) {
78 printf ("%x\n", joined_list[i]);
82 evs_callbacks_t callbacks = {
83 evs_deliver_fn,
84 evs_confchg_fn
87 struct evs_group groups[3] = {
88 { "key1" },
89 { "key2" },
90 { "key3" }
93 char buffer[200000];
94 struct iovec iov = {
95 .iov_base = buffer,
96 .iov_len = sizeof (buffer)
99 int main (void)
101 evs_handle_t handle;
102 evs_error_t result;
103 int i = 0;
104 int fd;
105 unsigned int member_list[32];
106 unsigned int local_nodeid;
107 unsigned int member_list_entries = 32;
109 result = evs_initialize (&handle, &callbacks);
110 if (result != EVS_OK) {
111 printf ("Couldn't initialize EVS service %d\n", result);
112 exit (0);
115 result = evs_membership_get (handle, &local_nodeid,
116 member_list, &member_list_entries);
117 printf ("Current membership from evs_membership_get entries %d\n",
118 member_list_entries);
119 for (i = 0; i < member_list_entries; i++) {
120 printf ("member [%d] is %x\n", i, member_list[i]);
122 printf ("local processor from evs_membership_get %x\n", local_nodeid);
124 printf ("Init result %d\n", result);
125 result = evs_join (handle, groups, 3);
126 printf ("Join result %d\n", result);
127 result = evs_leave (handle, &groups[0], 1);
128 printf ("Leave result %d\n", result);
129 delivery_string = "evs_mcast_joined";
132 * Demonstrate evs_mcast_joined
134 for (i = 0; i < 500; i++) {
135 sprintf (buffer, "evs_mcast_joined: This is message %d", i);
136 #ifdef COMPILE_OUT
137 sprintf (buffer,
138 "%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d",
139 i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i,
140 i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i, i);
141 #endif
142 try_again_one:
143 result = evs_mcast_joined (handle, EVS_TYPE_AGREED,
144 &iov, 1);
145 if (result == EVS_ERR_TRY_AGAIN) {
146 //printf ("try again\n");
147 goto try_again_one;
149 result = evs_dispatch (handle, EVS_DISPATCH_ALL);
152 do {
153 result = evs_dispatch (handle, EVS_DISPATCH_ALL);
154 } while (deliveries < 20);
156 * Demonstrate evs_mcast_joined
158 delivery_string = "evs_mcast_groups";
159 for (i = 0; i < 500; i++) {
160 sprintf (buffer, "evs_mcast_groups: This is message %d", i);
161 try_again_two:
162 result = evs_mcast_groups (handle, EVS_TYPE_AGREED,
163 &groups[1], 1, &iov, 1);
164 if (result == EVS_ERR_TRY_AGAIN) {
165 goto try_again_two;
168 result = evs_dispatch (handle, EVS_DISPATCH_ALL);
171 * Flush any pending callbacks
173 do {
174 result = evs_dispatch (handle, EVS_DISPATCH_ALL);
175 } while (deliveries < 900);
177 evs_fd_get (handle, &fd);
179 evs_finalize (handle);
181 return (0);