doxygen
[oweals/gnunet.git] / src / testbed / gnunet-testbed-profiler.c
1 /*
2      This file is part of GNUnet.
3      (C) 2011, 2012 Christian Grothoff (and other contributing authors)
4
5      GNUnet is free software; you can redistribute it and/or modify
6      it under the terms of the GNU General Public License as published
7      by the Free Software Foundation; either version 3, or (at your
8      option) any later version.
9
10      GNUnet is distributed in the hope that it will be useful, but
11      WITHOUT ANY WARRANTY; without even the implied warranty of
12      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13      General Public License for more details.
14
15      You should have received a copy of the GNU General Public License
16      along with GNUnet; see the file COPYING.  If not, write to the
17      Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18      Boston, MA 02111-1307, USA.
19 */
20
21 /**
22  * @file testbed/gnunet-testbed-profiler.c
23  * @brief Profiling driver for the testbed.
24  * @author Sree Harsha Totakura <sreeharsha@totakura.in> 
25  */
26
27 #include "platform.h"
28 #include "gnunet_common.h"
29 #include "gnunet_testbed_service.h"
30 #include "testbed_api_hosts.h"
31
32 /**
33  * Generic loggins shorthand
34  */
35 #define LOG(kind,...)                                           \
36   GNUNET_log (kind, __VA_ARGS__)
37
38
39 /**
40  * DLL of operations
41  */
42 struct DLLOperation
43 {
44   /**
45    * The testbed operation handle
46    */
47   struct GNUNET_TESTBED_Operation *op;
48
49   /**
50    * Closure
51    */
52   void *cls;
53
54   /**
55    * The next pointer for DLL
56    */
57   struct DLLOperation *next;
58
59   /**
60    * The prev pointer for DLL
61    */
62   struct DLLOperation *prev;
63 };
64
65
66 /**
67  * Availanle states during profiling
68  */
69 enum State
70 {
71   /**
72    * Initial state
73    */
74   STATE_INIT = 0,
75
76   /**
77    * Starting slaves
78    */
79   STATE_SLAVES_STARTING,
80
81   /**
82    * Creating peers
83    */
84   STATE_PEERS_CREATING,
85
86   /**
87    * Starting peers
88    */
89   STATE_PEERS_STARTING,
90
91   /**
92    * Linking peers
93    */
94   STATE_PEERS_LINKING,
95
96   /**
97    * Destroying peers; we can do this as the controller takes care of stopping a
98    * peer if it is running
99    */
100   STATE_PEERS_DESTROYING
101 };
102
103
104 /**
105  * An array of hosts loaded from the hostkeys file
106  */
107 static struct GNUNET_TESTBED_Host **hosts;
108
109 /**
110  * The array of peers; we fill this as the peers are given to us by the testbed
111  */
112 static struct GNUNET_TESTBED_Peer **peers;
113
114 /* /\** */
115 /*  * Operation handle */
116 /*  *\/ */
117 /* static struct GNUNET_TESTBED_Operation *op; */
118
119 /**
120  * Host registration handle
121  */
122 static struct GNUNET_TESTBED_HostRegistrationHandle *reg_handle;
123
124 /**
125  * Handle to the master controller process
126  */
127 struct GNUNET_TESTBED_ControllerProc *mc_proc;
128
129 /**
130  * Handle to the master controller
131  */
132 struct GNUNET_TESTBED_Controller *mc;
133
134 /**
135  * Handle to global configuration
136  */
137 struct GNUNET_CONFIGURATION_Handle *cfg;
138
139 /**
140  * Head of the operations list
141  */
142 struct DLLOperation *dll_op_head;
143
144 /**
145  * Tail of the operations list
146  */
147 struct DLLOperation *dll_op_tail;
148
149 /**
150  * Peer linking - topology operation
151  */
152 struct GNUNET_TESTBED_Operation *topology_op;
153
154 /**
155  * Abort task identifier
156  */
157 static GNUNET_SCHEDULER_TaskIdentifier abort_task;
158
159 /**
160  * Shutdown task identifier
161  */
162 static GNUNET_SCHEDULER_TaskIdentifier shutdown_task;
163
164 /**
165  * Host registration task identifier
166  */
167 static GNUNET_SCHEDULER_TaskIdentifier register_hosts_task;
168
169 /**
170  * Global event mask for all testbed events
171  */
172 uint64_t event_mask;
173
174 /**
175  * The starting time of a profiling step
176  */
177 struct GNUNET_TIME_Absolute prof_start_time;
178
179 /**
180  * Duration profiling step has taken
181  */
182 struct GNUNET_TIME_Relative prof_time;
183
184 /**
185  * Current peer id
186  */
187 unsigned int peer_id;
188
189 /**
190  * Number of peers to be started by the profiler
191  */
192 static unsigned int num_peers;
193
194 /**
195  * Number of hosts in the hosts array
196  */
197 static unsigned int num_hosts;
198
199 /**
200  * Number of random links to be established between peers
201  */
202 static unsigned int num_links;
203
204 /**
205  * Number of timeout failures to tolerate
206  */
207 static unsigned int num_cont_fails;
208
209 /**
210  * Number of times we try overlay connect operations
211  */
212 static unsigned int retry_links;
213
214 /**
215  * Continuous failures during overlay connect operations
216  */
217 static unsigned int cont_fails;
218
219 /**
220  * Global testing status
221  */
222 static int result;
223
224 /**
225  * current state of profiling
226  */
227 enum State state;
228
229
230 /**
231  * Shutdown nicely
232  *
233  * @param cls NULL
234  * @param tc the task context
235  */
236 static void
237 do_shutdown (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
238 {
239   struct DLLOperation *dll_op;
240   unsigned int nhost;
241
242   shutdown_task = GNUNET_SCHEDULER_NO_TASK;
243   if (GNUNET_SCHEDULER_NO_TASK != abort_task)
244     GNUNET_SCHEDULER_cancel (abort_task);
245   if (GNUNET_SCHEDULER_NO_TASK != register_hosts_task)
246     GNUNET_SCHEDULER_cancel (register_hosts_task);
247   if (NULL != reg_handle)
248     GNUNET_TESTBED_cancel_registration (reg_handle);
249   if (NULL != topology_op)
250     GNUNET_TESTBED_operation_cancel (topology_op);
251   for (nhost = 0; nhost < num_hosts; nhost++)
252     if (NULL != hosts[nhost])
253       GNUNET_TESTBED_host_destroy (hosts[nhost]);
254   GNUNET_free_non_null (hosts);
255   while (NULL != (dll_op = dll_op_head))
256   {
257     GNUNET_TESTBED_operation_cancel (dll_op->op);
258     GNUNET_CONTAINER_DLL_remove (dll_op_head, dll_op_tail, dll_op);
259     GNUNET_free (dll_op);
260   }
261   if (NULL != mc)
262     GNUNET_TESTBED_controller_disconnect (mc);
263   if (NULL != mc_proc)
264     GNUNET_TESTBED_controller_stop (mc_proc);
265   if (NULL != cfg)
266     GNUNET_CONFIGURATION_destroy (cfg);
267   GNUNET_SCHEDULER_shutdown (); /* Stop scheduler to shutdown testbed run */
268 }
269
270
271 /**
272  * abort task to run on test timed out
273  *
274  * @param cls NULL
275  * @param tc the task context
276  */
277 static void
278 do_abort (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
279 {
280   LOG (GNUNET_ERROR_TYPE_WARNING, "Aborting\n");
281   abort_task = GNUNET_SCHEDULER_NO_TASK;
282   result = GNUNET_SYSERR;
283   if (GNUNET_SCHEDULER_NO_TASK != shutdown_task)
284     GNUNET_SCHEDULER_cancel (shutdown_task);
285   shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
286 }
287
288
289
290
291
292 /**
293  * Functions of this signature are called when a peer has been successfully
294  * started or stopped.
295  *
296  * @param cls the closure from GNUNET_TESTBED_peer_start/stop()
297  * @param emsg NULL on success; otherwise an error description
298  */
299 static void 
300 peer_churn_cb (void *cls, const char *emsg)
301 {
302   struct DLLOperation *dll_op = cls;
303   struct GNUNET_TESTBED_Operation *op;  
304   static unsigned int started_peers;
305
306   op = dll_op->op;
307   GNUNET_CONTAINER_DLL_remove (dll_op_head, dll_op_tail, dll_op);
308   GNUNET_free (dll_op);
309   if (NULL != emsg)
310   {
311     LOG (GNUNET_ERROR_TYPE_WARNING,
312          _("An operation has failed while starting peers\n"));
313     GNUNET_TESTBED_operation_done (op);
314     GNUNET_SCHEDULER_cancel (abort_task);
315     abort_task = GNUNET_SCHEDULER_add_now (&do_abort, NULL);
316     return;
317   }
318   GNUNET_TESTBED_operation_done (op);
319   if (++started_peers == num_peers)
320   {
321     prof_time = GNUNET_TIME_absolute_get_duration (prof_start_time);
322     printf ("%u peers started successfully in %.2f seconds\n",
323             num_peers, ((double) prof_time.rel_value) / 1000.00);
324     fflush (stdout);
325     result = GNUNET_OK;
326     if (0 == num_links)
327     {      
328       shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
329       return;
330     }
331     state = STATE_PEERS_LINKING;
332     /* Do overlay connect */
333     prof_start_time = GNUNET_TIME_absolute_get ();
334     topology_op =
335         GNUNET_TESTBED_overlay_configure_topology (NULL, num_peers, peers,
336                                                    GNUNET_TESTBED_TOPOLOGY_ERDOS_RENYI,
337
338                                                    num_links);
339   }
340 }
341
342
343 /**
344  * Functions of this signature are called when a peer has been successfully
345  * created
346  *
347  * @param cls the closure from GNUNET_TESTBED_peer_create()
348  * @param peer the handle for the created peer; NULL on any error during
349  *          creation
350  * @param emsg NULL if peer is not NULL; else MAY contain the error description
351  */
352 static void 
353 peer_create_cb (void *cls, struct GNUNET_TESTBED_Peer *peer, const char *emsg)
354 {
355   struct DLLOperation *dll_op = cls;
356   struct GNUNET_TESTBED_Peer **peer_ptr;
357   static unsigned int created_peers;
358   unsigned int peer_cnt;
359
360   if (NULL != emsg)
361   {
362     LOG (GNUNET_ERROR_TYPE_WARNING,
363          _("Creating a peer failed. Error: %s\n"), emsg);
364     GNUNET_TESTBED_operation_done (dll_op->op);
365     GNUNET_CONTAINER_DLL_remove (dll_op_head, dll_op_tail, dll_op);
366     GNUNET_free (dll_op);
367     GNUNET_SCHEDULER_cancel (abort_task);
368     abort_task = GNUNET_SCHEDULER_add_now (&do_abort, NULL);
369     return;
370   }
371   peer_ptr = dll_op->cls;
372   GNUNET_assert (NULL == *peer_ptr);
373   *peer_ptr = peer;
374   GNUNET_TESTBED_operation_done (dll_op->op);
375   GNUNET_CONTAINER_DLL_remove (dll_op_head, dll_op_tail, dll_op);
376   GNUNET_free (dll_op);
377   if (++created_peers == num_peers)
378   {
379     prof_time = GNUNET_TIME_absolute_get_duration (prof_start_time);    
380     printf ("%u peers created successfully in %.2f seconds\n",
381             num_peers, ((double) prof_time.rel_value) / 1000.00);
382     fflush (stdout);
383     /* Now peers are to be started */
384     state = STATE_PEERS_STARTING;
385     prof_start_time = GNUNET_TIME_absolute_get ();
386     for (peer_cnt = 0; peer_cnt < num_peers; peer_cnt++)
387     {
388       dll_op = GNUNET_malloc (sizeof (struct DLLOperation));
389       dll_op->op = GNUNET_TESTBED_peer_start (dll_op, peers[peer_cnt], 
390                                               &peer_churn_cb, dll_op);
391       GNUNET_CONTAINER_DLL_insert_tail (dll_op_head, dll_op_tail, dll_op);
392     }
393   }
394 }
395
396
397 /**
398  * Function to print summary about how many overlay links we have made and how
399  * many failed
400  */
401 static void
402 print_overlay_links_summary ()
403 {
404   prof_time = GNUNET_TIME_absolute_get_duration (prof_start_time);
405   printf ("\n%u links established in %.2f seconds\n",
406           num_links, ((double) prof_time.rel_value) / 1000.00);
407   printf ("Overlay link operations have been retried %u times upon timeouts\n",
408           retry_links);
409 }
410
411
412 /**
413  * Controller event callback
414  *
415  * @param cls NULL
416  * @param event the controller event
417  */
418 static void
419 controller_event_cb (void *cls,
420                      const struct GNUNET_TESTBED_EventInformation *event)
421 {
422   struct DLLOperation *dll_op;
423   struct GNUNET_TESTBED_Operation *op;
424
425   switch (state)
426   {
427   case STATE_SLAVES_STARTING:
428     switch (event->type)
429     {
430     case GNUNET_TESTBED_ET_OPERATION_FINISHED:
431       {
432         static unsigned int slaves_started;
433         unsigned int peer_cnt;
434         
435         dll_op = event->details.operation_finished.op_cls;
436         GNUNET_CONTAINER_DLL_remove (dll_op_head, dll_op_tail, dll_op);
437         GNUNET_free (dll_op);
438         op = event->details.operation_finished.operation;
439         if (NULL != event->details.operation_finished.emsg)
440         {
441           LOG (GNUNET_ERROR_TYPE_WARNING,
442                _("An operation has failed while starting slaves\n"));
443           GNUNET_TESTBED_operation_done (op);
444           GNUNET_SCHEDULER_cancel (abort_task);
445           abort_task = GNUNET_SCHEDULER_add_now (&do_abort, NULL);
446           return;
447         }
448         GNUNET_TESTBED_operation_done (op);
449         /* Proceed to start peers */
450         if (++slaves_started == num_hosts - 1)
451         {
452           printf ("%u controllers started successfully\n", num_hosts);
453           fflush (stdout);
454           state = STATE_PEERS_CREATING;
455           prof_start_time = GNUNET_TIME_absolute_get ();
456           peers = GNUNET_malloc (sizeof (struct GNUNET_TESTBED_Peer *)
457                                  * num_peers);
458           for (peer_cnt = 0; peer_cnt < num_peers; peer_cnt++)
459           {
460             dll_op = GNUNET_malloc (sizeof (struct DLLOperation));
461             dll_op->cls = &peers[peer_cnt];
462             dll_op->op = GNUNET_TESTBED_peer_create (mc,
463                                                      hosts
464                                                      [peer_cnt % num_hosts],
465                                                      cfg,
466                                                      &peer_create_cb,
467                                                      dll_op);
468             GNUNET_CONTAINER_DLL_insert_tail (dll_op_head, dll_op_tail, dll_op);
469           }
470         }
471       }
472       break;
473     default:
474       GNUNET_assert (0);
475     }
476     break;
477   case STATE_PEERS_STARTING:
478     switch (event->type)
479     {
480     case GNUNET_TESTBED_ET_OPERATION_FINISHED:
481       /* Control reaches here when peer start fails */
482     case GNUNET_TESTBED_ET_PEER_START:
483       /* we handle peer starts in peer_churn_cb */
484       break;
485     default:
486       GNUNET_assert (0);
487     }
488     break;
489   case STATE_PEERS_LINKING:
490    switch (event->type)
491     {
492     case GNUNET_TESTBED_ET_OPERATION_FINISHED:
493       /* Control reaches here when a peer linking operation fails */
494       if (NULL != event->details.operation_finished.emsg)
495       {
496         LOG (GNUNET_ERROR_TYPE_WARNING,
497              _("An operation has failed while linking\n"));
498         printf ("F");
499         fflush (stdout);
500         retry_links++;
501         if (++cont_fails > num_cont_fails)
502         {
503           printf ("\nAborting due to very high failure rate");
504           print_overlay_links_summary ();         
505           GNUNET_SCHEDULER_cancel (abort_task);
506           abort_task = GNUNET_SCHEDULER_add_now (&do_abort, NULL);
507         }
508       }
509       break;
510     case GNUNET_TESTBED_ET_CONNECT:
511       {
512         static unsigned int established_links;
513
514         if (0 != cont_fails)
515           cont_fails--;
516         if (0 == established_links)
517           printf ("Establishing links. Please wait\n");
518         printf (".");
519         fflush (stdout);
520         if (++established_links == num_links)
521         {
522           print_overlay_links_summary ();
523           result = GNUNET_OK;
524           shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
525         }
526       }
527       break;
528     default:
529       GNUNET_assert (0);
530     }
531     break;
532   default:
533     GNUNET_assert (0);
534   }
535 }
536
537
538 /**
539  * Task to register all hosts available in the global host list
540  *
541  * @param cls NULL
542  * @param tc the scheduler task context
543  */
544 static void
545 register_hosts (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
546
547
548 /**
549  * Callback which will be called to after a host registration succeeded or failed
550  *
551  * @param cls the closure
552  * @param emsg the error message; NULL if host registration is successful
553  */
554 static void
555 host_registration_completion (void *cls, const char *emsg)
556 {
557   reg_handle = NULL;
558   if (NULL != emsg)
559   {
560     LOG (GNUNET_ERROR_TYPE_WARNING,
561          _("Host registration failed for a host. Error: %s\n"), emsg);
562     GNUNET_SCHEDULER_cancel (abort_task);
563     abort_task = GNUNET_SCHEDULER_add_now (&do_abort, NULL);
564     return;
565   }
566   register_hosts_task = GNUNET_SCHEDULER_add_now (&register_hosts, NULL);
567 }
568
569
570 /**
571  * Task to register all hosts available in the global host list
572  *
573  * @param cls NULL
574  * @param tc the scheduler task context
575  */
576 static void
577 register_hosts (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
578 {
579   struct DLLOperation *dll_op;
580   static unsigned int reg_host;
581   unsigned int slave;
582
583   register_hosts_task = GNUNET_SCHEDULER_NO_TASK;  
584   if (reg_host == num_hosts - 1)
585   {
586     LOG (GNUNET_ERROR_TYPE_DEBUG,
587          "All hosts successfully registered\n");
588     /* Start slaves */
589     state = STATE_SLAVES_STARTING;
590     for (slave = 1; slave < num_hosts; slave++)
591     {
592       dll_op = GNUNET_malloc (sizeof (struct DLLOperation));
593       dll_op->op = GNUNET_TESTBED_controller_link (dll_op,
594                                                    mc,
595                                                    hosts[slave],
596                                                    hosts[0],
597                                                    cfg,
598                                                    GNUNET_YES);
599       GNUNET_CONTAINER_DLL_insert_tail (dll_op_head, dll_op_tail, dll_op);
600     }
601     return;
602   }
603   reg_handle = GNUNET_TESTBED_register_host (mc, hosts[++reg_host],
604                                              host_registration_completion,
605                                              NULL);
606 }
607
608
609 /**
610  * Callback to signal successfull startup of the controller process
611  *
612  * @param cls the closure from GNUNET_TESTBED_controller_start()
613  * @param config the configuration with which the controller has been started;
614  *          NULL if status is not GNUNET_OK
615  * @param status GNUNET_OK if the startup is successfull; GNUNET_SYSERR if not,
616  *          GNUNET_TESTBED_controller_stop() shouldn't be called in this case
617  */
618 static void
619 status_cb (void *cls, const struct GNUNET_CONFIGURATION_Handle *config, int status)
620 {
621   GNUNET_SCHEDULER_cancel (abort_task);
622   if (GNUNET_OK != status)
623   {
624     mc_proc = NULL;
625     abort_task = GNUNET_SCHEDULER_add_now (&do_abort, NULL);
626     return;
627   }
628   event_mask = 0;
629   event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_START);
630   event_mask |= (1LL << GNUNET_TESTBED_ET_PEER_STOP);
631   event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT);
632   event_mask |= (1LL << GNUNET_TESTBED_ET_DISCONNECT);
633   event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED);
634   mc = GNUNET_TESTBED_controller_connect (config, hosts[0], event_mask,
635                                           &controller_event_cb, NULL);
636   if (NULL == mc)
637   {
638     LOG (GNUNET_ERROR_TYPE_WARNING,
639          _("Unable to connect to master controller -- Check config\n"));
640     abort_task = GNUNET_SCHEDULER_add_now (&do_abort, NULL);
641     return;
642   }
643   register_hosts_task = GNUNET_SCHEDULER_add_now (&register_hosts, NULL);
644   abort_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
645                                              &do_abort, NULL);
646 }
647
648
649 /**
650  * Main function that will be run by the scheduler.
651  *
652  * @param cls closure
653  * @param args remaining command-line arguments
654  * @param cfgfile name of the configuration file used (for saving, can be NULL!)
655  * @param config configuration
656  */
657 static void
658 run (void *cls, char *const *args, const char *cfgfile,
659      const struct GNUNET_CONFIGURATION_Handle *config)
660 {
661   unsigned int nhost;
662
663   if (NULL == args[0])
664   {
665     fprintf (stderr, _("No hosts-file specified on command line\n"));
666     return;
667   }
668   if (0 == num_peers)
669   {
670     result = GNUNET_OK;
671     return;
672   }
673   num_hosts = GNUNET_TESTBED_hosts_load_from_file (args[0], &hosts);
674   if (0 == num_hosts)
675   {
676     fprintf (stderr, _("No hosts loaded. Need atleast one host\n"));
677     return;
678   }
679   for (nhost = 0; nhost < num_hosts; nhost++)
680   {
681     if (GNUNET_YES != GNUNET_TESTBED_is_host_habitable (hosts[nhost]))
682     {
683       fprintf (stderr, _("Host %s cannot start testbed\n"),
684                GNUNET_TESTBED_host_get_hostname_ (hosts[nhost]));
685       break;
686     }
687   }
688   if (num_hosts != nhost)
689   {
690     fprintf (stderr, _("Exiting\n"));
691     shutdown_task = GNUNET_SCHEDULER_add_now (&do_shutdown, NULL);
692     return;
693   }
694   cfg = GNUNET_CONFIGURATION_dup (config);
695   mc_proc = 
696       GNUNET_TESTBED_controller_start (GNUNET_TESTBED_host_get_hostname_ 
697                                        (hosts[0]),
698                                        hosts[0],
699                                        cfg,
700                                        status_cb,
701                                        NULL);
702   abort_task =
703       GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_multiply
704                                     (GNUNET_TIME_UNIT_SECONDS, 5), &do_abort,
705                                     NULL);
706 }
707
708
709 /**
710  * Main function.
711  *
712  * @return 0 on success
713  */
714 int
715 main (int argc, char *const *argv)
716 {
717   static const struct GNUNET_GETOPT_CommandLineOption options[] = {
718     { 'p', "num-peers", "COUNT",
719       gettext_noop ("create COUNT number of peers"),
720       GNUNET_YES, &GNUNET_GETOPT_set_uint, &num_peers },
721     { 'n', "num-links", "COUNT",
722       gettext_noop ("create COUNT number of random links"),
723       GNUNET_YES, &GNUNET_GETOPT_set_uint, &num_links },
724     { 'e', "num-errors", "COUNT",
725       gettext_noop ("tolerate COUNT number of continious timeout failures"),
726       GNUNET_YES, &GNUNET_GETOPT_set_uint, &num_cont_fails },
727     GNUNET_GETOPT_OPTION_END
728   };
729   int ret;
730
731   if (GNUNET_OK != GNUNET_STRINGS_get_utf8_args (argc, argv, &argc, &argv))
732     return 2;
733   
734   result = GNUNET_SYSERR;
735   ret =
736       GNUNET_PROGRAM_run (argc, argv, "gnunet-testbed-profiler [OPTIONS] hosts-file",
737                           _("Profiler for testbed"),
738                           options, &run, NULL);
739   if (GNUNET_OK != ret)
740     return ret;
741   if (GNUNET_OK != result)
742     return 1;
743   return 0;
744 }