c9d50fdaabde47d71208d9374d78bde2f6fa1cde
[openafs.git] / src / lwp / test / test.c
1 /*
2 ****************************************************************************
3 *        Copyright IBM Corporation 1988, 1989 - All Rights Reserved        *
4 *                                                                          *
5 * Permission to use, copy, modify, and distribute this software and its    *
6 * documentation for any purpose and without fee is hereby granted,         *
7 * provided that the above copyright notice appear in all copies and        *
8 * that both that copyright notice and this permission notice appear in     *
9 * supporting documentation, and that the name of IBM not be used in        *
10 * advertising or publicity pertaining to distribution of the software      *
11 * without specific, written prior permission.                              *
12 *                                                                          *
13 * IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL *
14 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL IBM *
15 * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY      *
16 * DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER  *
17 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING   *
18 * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.    *
19 ****************************************************************************
20 */
21
22 #include <stdio.h>
23 #include <sys/time.h>
24 #include <potpourri.h>
25 #include "lwp.h"
26
27 char semaphore;
28
29 int OtherProcess()
30     {
31     for(;;)
32         {
33         LWP_SignalProcess(&semaphore);
34         }
35     }
36
37 main(argc, argv)
38 int argc; char *argv[];
39     {
40     struct timeval t1, t2;
41     int pid, otherpid;
42     register int i,  count, x;
43     char *waitarray[2];
44     static char c[] = "OtherProcess";
45     
46     count = atoi(argv[1]);
47
48     assert(LWP_InitializeProcessSupport(0, &pid) == LWP_SUCCESS);
49     assert(LWP_CreateProcess(OtherProcess,4096,0, 0, c, &otherpid) == LWP_SUCCESS);
50
51     waitarray[0] = &semaphore;
52     waitarray[1] = 0;
53     gettimeofday(&t1, NULL);
54     for (i = 0; i < count; i++)
55         {
56         LWP_MwaitProcess(1, waitarray, 1);
57         }
58     gettimeofday(&t2, NULL);
59
60     x = (t2.tv_sec -t1.tv_sec)*1000000 + (t2.tv_usec - t1.tv_usec);
61     printf("%d milliseconds for %d MWaits (%f usec per Mwait and Signal)\n", x/1000, count, (float)(x/count));
62     }