Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
remove gras from the main documentation
[simgrid.git] / teshsuite / gras / numerous_rpc / numerous_rpc.c
1 /* numerous_rpc -- ensures that no race condition occurs when there is a    */
2 /*                 huge amount of very small messages                       */
3
4 /* Copyright (c) 2012. The SimGrid Team. All rights reserved.               */
5 /* Thanks to Soumeya Leila Hernane for reporting an issue around this       */
6
7 /* This program is free software; you can redistribute it and/or modify it
8  * under the terms of the license (GNU LGPL) which comes with this package. */
9
10 #include "gras.h"
11
12 #define RPC_AMOUNT 50000 /* amount of RPC calls to do in a raw */
13
14 XBT_LOG_NEW_DEFAULT_CATEGORY(numerous_rpc,"logs attached to the RPC crash test");
15
16 int give_hostname(gras_msg_cb_ctx_t ctx, void *payload);
17 int server(int argc, char *argv[]);
18 int client(int argc, char *argv[]);
19
20 /*************************************/
21
22 /* callback used for the test */
23 int give_hostname(gras_msg_cb_ctx_t ctx, void *payload) {            /* rpc, return hostname */
24   const char* myself = gras_os_myname();
25
26   gras_msg_rpcreturn(-1,ctx,&myself);
27
28   gras_socket_close(gras_msg_cb_ctx_from(ctx));
29   return 0;
30 }
31
32 /*************************************/
33 int server(int argc, char *argv[]) {
34   xbt_socket_t mysock;
35   int i;
36
37   gras_init(&argc, argv);
38   gras_msgtype_declare_rpc("give_hostname",xbt_datadesc_by_name("xbt_string_t"),xbt_datadesc_by_name("xbt_string_t"));
39   gras_cb_register("give_hostname", &give_hostname);
40
41   mysock = gras_socket_server(2222);
42
43   for (i=0;i<RPC_AMOUNT;i++)
44     gras_msg_handle(-1);
45
46   gras_socket_close(mysock);
47   gras_exit();
48   return 0;
49
50 }
51
52 /* ****************** Code of the client ****************************** */
53 int client(int argc, char *argv[]) {
54   long int i;
55   xbt_socket_t server_sock,client_sock;
56   xbt_string_t myself = xbt_strdup(gras_os_myname());
57   xbt_string_t hostname = xbt_malloc(60);
58
59   gras_init(&argc, argv);
60   gras_msgtype_declare_rpc("give_hostname",xbt_datadesc_by_name("xbt_string_t"),xbt_datadesc_by_name("xbt_string_t"));
61
62   client_sock = gras_socket_server_range(1024, 10000, 0, 0);
63
64   for(i=0;i<RPC_AMOUNT;i++) {
65     server_sock = gras_socket_client(argv[1], 2222);
66     //if (i%1000==0)
67       XBT_INFO("iteration %ld",i);
68     gras_msg_rpccall(server_sock,-1,"give_hostname",&myself,&hostname);
69     gras_socket_close(server_sock) ;
70   }
71
72   gras_socket_close(client_sock);
73
74   xbt_free(hostname);
75   xbt_free(myself);
76   gras_exit();
77
78   return 0;
79 }
80
81
82
83
84
85
86
87