summaryrefslogtreecommitdiff
path: root/i/simulotron
diff options
context:
space:
mode:
authorhaller2005-12-18 18:16:33 +0000
committerhaller2005-12-18 18:16:33 +0000
commit97eb9088f51c5547c8ab864a62faedd55689b355 (patch)
tree38ff0dab189a36cd13465ccd231ec0fc99a69739 /i/simulotron
parent777c03e4048e20f3d66bc8d72932658fc9dc08cc (diff)
* Fin de conversion des test des threads vers les fork (désolé Tb)
Diffstat (limited to 'i/simulotron')
-rw-r--r--i/simulotron/src/gs/Makefile.incl.am3
-rw-r--r--i/simulotron/src/gs/test_gs.cc58
2 files changed, 35 insertions, 26 deletions
diff --git a/i/simulotron/src/gs/Makefile.incl.am b/i/simulotron/src/gs/Makefile.incl.am
index e3f0026..503e676 100644
--- a/i/simulotron/src/gs/Makefile.incl.am
+++ b/i/simulotron/src/gs/Makefile.incl.am
@@ -6,6 +6,3 @@ check_PROGRAMS += test_gs
test_gs_SOURCES = gs/test_gs.cc $(gs_message_S) \
$(gs_transmitter_S) \
$(socket_S)
-
-test_gs_LDADD = -lpthread
-test_gs_CXXFLAGS = -W -Wall -g -pthread
diff --git a/i/simulotron/src/gs/test_gs.cc b/i/simulotron/src/gs/test_gs.cc
index 5367a3d..5920a9c 100644
--- a/i/simulotron/src/gs/test_gs.cc
+++ b/i/simulotron/src/gs/test_gs.cc
@@ -32,6 +32,7 @@
#include <iostream>
#include <stdexcept>
+#include <sys/wait.h>
// Adress useful
Address adr;
@@ -50,28 +51,45 @@ short s2;
long l1 = 465676;
long l2;
-//threads
-pthread_t threadId;
-void * retour;
-int stateTh;
-
-void * testGSServ(void * CaSertARien);
-void * testGSClient(void * CaSertARien);
+int testGSServer(SocketServer & sockServ);
+void testGSClient(int pauseMode);
int main(void)
{
+ //pauseMode pour debbuger le fork
+ int pauseMode = 0;
+ int pid;
+ //retour des test
+ int resultClient, resultServer;
// Création de la socket serveur;
SocketServer sockServ(Address(4242));
// Mise en écoute du socket serveur
sockServ.listen(12);
- // On crée le thread du client
- int ret;
- ret = pthread_create(& threadId, NULL, testGSClient, NULL);
- if(ret != 0)
+ // On crée le fork du client
+ pid = fork();
+ if (pid == 0) // processus fils
+ testGSClient(pauseMode);
+ else //processus père
+ resultServer = testGSServer(sockServ);
+
+ // On analyse les résultats
+ wait(&resultClient);
+ if (!(WIFEXITED(resultClient) && WEXITSTATUS(resultClient) == 0))
{
- std::cout << "CHIER: Echec thread client" << std::endl;
- return EXIT_FAILURE;
+ std::cerr << "ECHEC: Problème coté client" << std::endl;
+ exit (-1);
}
+ if (resultServer != 0)
+ {
+ std::cerr << "ECHEC: Problème coté serveur" << std::endl;
+ exit (-1);
+ }
+
+ return 0;
+}
+
+int testGSServer(SocketServer & sockServ)
+{
// Acceptation d'une connection
SocketClient sockFork(sockServ);
// Création du transmitter
@@ -178,16 +196,10 @@ int main(void)
<< std::endl;
return 1;
}
- //On attend le thread client
- pthread_join(threadId, &retour);
- stateTh = (int) retour;
- if(stateTh == 0)
- return 0;
- else
- return 1;
+ return 0;
}
-void * testGSClient(void * CaSertARien)
+void testGSClient(int pauseMode)
{
try
{
@@ -220,7 +232,7 @@ void * testGSClient(void * CaSertARien)
{
std::cout << "CHIER !! Une exception a été lancé coté client!!" << std::endl;
std::cout << chier.what() << std::endl;
- return (void *) 1;
+ exit (1);
}
- return (void *) 0;
+ exit (0);
}