GridLab
Grid Application Toolkit

A simple API for Grid Applications
GAT

Menu



Main Page   Alphabetical List   Compound List   File List   Compound Members   File Members  

pipe_tests.c

Go to the documentation of this file.
00001 /** @file pipe_tests.c
00002  *  Test GATEndpoint and GATPipe API's related to GATPipe_Write
00003  * 
00004  *  @date Tue Mar 30 2004
00005  * 
00006  *  @version $Header: /export/cvs-gridlab/wp-1/Codes/GATEngine/C-reference/test/simple/pipe_tests.c,v 1.4 2004/05/07 10:20:09 merzky Exp $
00007  *
00008  *  Copyright (C) Hartmut Kaiser
00009  *  This file is part of the GAT Engine.
00010  *  Contributed by Hartmut Kaiser <hartmutkaiser [at] t-online [dot] de>.
00011  *
00012  *  Use, modification and distribution is subject to the Gridlab Software
00013  *  License. (See accompanying file GLlicense.txt or copy at
00014  *  http://www.gridlab.org/GLlicense.txt)
00015  */
00016 
00017 static const char *rcsid = "$Header: /export/cvs-gridlab/wp-1/Codes/GATEngine/C-reference/test/simple/pipe_tests.c,v 1.4 2004/05/07 10:20:09 merzky Exp $";
00018 
00019 /* System Header Files */
00020 
00021 #include <limits.h>
00022 #include <stdio.h>
00023 #include <stdlib.h>
00024 #include <unistd.h>
00025 #include <sys/types.h>
00026 #include <sys/wait.h>
00027 
00028 /* GAT Header Files */
00029 
00030 #include "GAT.h"
00031 #include "GATTestUtils.h"
00032 
00033 /* Macros */
00034 #if !defined(MAX_PATH)
00035 # define MAX_PATH _POSIX_PATH_MAX
00036 #endif
00037 
00038 
00039 
00040 /* Structures, unions and enums */
00041 
00042 /* Static function prototypes */
00043 static int execute_pipe_read_client(void);
00044 static int execute_pipe_write_client(void);
00045 
00046 /* File scope variables */
00047 
00048 /* External functions */
00049 
00050 int main(int argc, const char * const argv[])
00051 {
00052   int read_pid = 0;
00053   int write_pid = 0;
00054   int status = 0;
00055   
00056   read_pid = execute_pipe_read_client();
00057   sleep(2);
00058   write_pid = execute_pipe_write_client();
00059   
00060   /* wait for the write client to terminate */
00061   waitpid(write_pid, &status, 0);
00062   
00063   /* wait for the read client to terminate */
00064   waitpid(read_pid, &status, 0);
00065   
00066   return 0;
00067 }
00068 
00069 /* static functions */
00070 static int
00071 execute_pipe_read_client(void)
00072 {
00073 #if !defined(WIN32)
00074   pid_t pid = 0;
00075   if ( (pid = fork()) < 0)
00076   {
00077     perror("fork: pipe_read_tests");
00078   }
00079   else if (0 == pid)
00080   {
00081     char exe[MAX_PATH];
00082     snprintf (exe, MAX_PATH-1, "%s/bin/tests/pipe_read_tests", getenv ("GAT_LOCATION"));
00083 
00084     if (execlp(exe, "pipe_read_tests", NULL) < 0)
00085     {
00086       perror  ("execlp: pipe_read_tests");
00087       fprintf (stderr, "expecting pipe_read_tests in $GAT_LOCATION/bin/tests/\n");
00088     }
00089   }
00090   return pid;
00091 #else
00092   return _spawnl(_P_NOWAIT, "pipe_read_tests.exe", "pipe_read_tests.exe", NULL);
00093 #endif
00094 }
00095 
00096 static int 
00097 execute_pipe_write_client(void)
00098 {
00099 #if !defined(WIN32)
00100   pid_t pid = 0;
00101   if ( (pid = fork()) < 0)
00102   {
00103     perror("fork: pipe_write_tests");
00104   }
00105   else if (0 == pid)
00106   {
00107     char exe[MAX_PATH];
00108     snprintf (exe, MAX_PATH-1, "%s/bin/tests/pipe_write_tests", getenv ("GAT_LOCATION"));
00109 
00110     if (execlp(exe, "pipe_write_tests", NULL) < 0)
00111     {
00112       perror  ("execlp: pipe_write_tests");
00113       fprintf (stderr, "expecting pipe_write_tests in $GAT_LOCATION/bin/tests/\n");
00114     }
00115   }
00116   return pid;
00117 #else
00118   return _spawnl(_P_NOWAIT, "pipe_write_tests.exe", "pipe_write_tests.exe", NULL);
00119 #endif
00120 }
00121