Browse Source

amélioration des tests

David Sniperovitch 8 years ago
parent
commit
bd556e592a
2 changed files with 55 additions and 51 deletions
  1. 29 23
      test_cocktail_02
  2. 26 28
      test_cocktail_03

+ 29 - 23
test_cocktail_02

@@ -1,11 +1,10 @@
 #!/bin/bash
 #!/bin/bash
 
 
-echo "Test 02: 2 compilations dans le même dossier, projets différents."
-echo "Les deux compilations doivent réussir"
-
-RC1=99
-RC2=99
+echo "Test 02: 2 compilations dans le même dossier, projets différents"
+echo "Les deux doivent correctement se dérouler"
 
 
+# pids conserve la liste des pids
+# retcode conserve le code retour de chaque pid une fois terminé
 handle_child() {
 handle_child() {
   local tmp=()
   local tmp=()
   for((i=0;i<${#pids[@]};++i));
   for((i=0;i<${#pids[@]};++i));
@@ -13,17 +12,7 @@ handle_child() {
     if test ! -d /proc/${pids[i]};
     if test ! -d /proc/${pids[i]};
     then
     then
       wait ${pids[i]}
       wait ${pids[i]}
-      RC0=$?
-      echo "Stopped ${pids[i]}; exit code: $RC0"
-      if test "$RC1" -eq 99;
-      then
-        RC1="$RC0"
-      else
-        if test "$RC2" -eq 99;
-        then
-          RC2="$RC0"
-        fi
-      fi
+      retcode[${pids[i]}]=$?
     else
     else
       tmp+=(${pids[i]})
       tmp+=(${pids[i]})
     fi
     fi
@@ -36,10 +25,18 @@ trap "handle_child" CHLD
 
 
 
 
 # Start background processes
 # Start background processes
-./cocktail -v -d MonDossier -p Abro2 -b 'https://pad.exegetes.eu.org/p/g.DSXI1kGFT1gjor66$Abro-REP-Tele2-Principal/export/txt' -g 'https://pad.exegetes.eu.org/p/g.DSXI1kGFT1gjor66$Abro-REP-Tele2-Garde/export/txt' &
+./cocktail -v \
+           -d MonDossier \
+           -p Abro2 \
+           -b 'https://pad.exegetes.eu.org/p/g.DSXI1kGFT1gjor66$Abro-REP-Tele2-Principal/export/txt' \
+           -g 'https://pad.exegetes.eu.org/p/g.DSXI1kGFT1gjor66$Abro-REP-Tele2-Garde/export/txt' &
 pids+=($!)
 pids+=($!)
 
 
-./cocktail -v -d MonDossier -p Abro3 -b 'https://pad.exegetes.eu.org/p/g.DSXI1kGFT1gjor66$Abro-REP-Tele2-Principal/export/txt' -g 'https://pad.exegetes.eu.org/p/g.DSXI1kGFT1gjor66$Abro-REP-Tele2-Garde/export/txt' &
+./cocktail -v \
+           -d MonDossier \
+           -p Abro3 \
+           -b 'https://pad.exegetes.eu.org/p/g.DSXI1kGFT1gjor66$Abro-REP-Tele2-Principal/export/txt' \
+           -g 'https://pad.exegetes.eu.org/p/g.DSXI1kGFT1gjor66$Abro-REP-Tele2-Garde/export/txt' &
 pids+=($!)
 pids+=($!)
 
 
 # Wait until all background processes are stopped
 # Wait until all background processes are stopped
@@ -49,14 +46,23 @@ do
   sleep 2;
   sleep 2;
 done
 done
 echo STOPPED
 echo STOPPED
-echo "RC1=$RC1 RC2=$RC2"
 
 
-if test "$RC1" -eq 0 -a "$RC2" -eq 0;
+# affichage des code retour et generation de la chaine de test
+for pid in "${!retcode[@]}"
+do
+  statusstring="$statusstring $pid=${retcode[$pid]}"
+  retcodestr="${retcodestr}${retcode[$pid]}"
+done
+echo $statusstring
+
+if test $retcodestr -eq "00" -o $retcodestr -eq "00";
 then
 then
   echo "Test réussi"
   echo "Test réussi"
+  echo "Les deux processus se sont terminés en code 0"
   exit 0
   exit 0
+else
+  echo "Test échoué."
+  echo "Les deux processus doivent se terminer en code 0"
+  exit 1
 fi
 fi
 
 
-echo "Test échoué"
-exit 1
-

+ 26 - 28
test_cocktail_03

@@ -3,9 +3,8 @@
 echo "Test 03: 2 compilations dans le même dossier, même projet."
 echo "Test 03: 2 compilations dans le même dossier, même projet."
 echo "Un des deux doit tomber en erreur"
 echo "Un des deux doit tomber en erreur"
 
 
-RC1=99
-RC2=99
-
+# pids conserve la liste des pids
+# retcode conserve le code retour de chaque pid une fois terminé
 handle_child() {
 handle_child() {
   local tmp=()
   local tmp=()
   for((i=0;i<${#pids[@]};++i));
   for((i=0;i<${#pids[@]};++i));
@@ -13,17 +12,7 @@ handle_child() {
     if test ! -d /proc/${pids[i]};
     if test ! -d /proc/${pids[i]};
     then
     then
       wait ${pids[i]}
       wait ${pids[i]}
-      RC0=$?
-      echo "Stopped ${pids[i]}; exit code: $RC0"
-      if test "$RC1" -eq 99;
-      then
-        RC1="$RC0"
-      else
-        if test "$RC2" -eq 99;
-        then
-          RC2="$RC0"
-        fi
-      fi
+      retcode[${pids[i]}]=$?
     else
     else
       tmp+=(${pids[i]})
       tmp+=(${pids[i]})
     fi
     fi
@@ -36,10 +25,18 @@ trap "handle_child" CHLD
 
 
 
 
 # Start background processes
 # Start background processes
-./cocktail -v -d MonDossier -p Abro2 -b 'https://pad.exegetes.eu.org/p/g.DSXI1kGFT1gjor66$Abro-REP-Tele2-Principal/export/txt' -g 'https://pad.exegetes.eu.org/p/g.DSXI1kGFT1gjor66$Abro-REP-Tele2-Garde/export/txt' &
+./cocktail -v \
+           -d MonDossier \
+           -p Abro2 \
+           -b 'https://pad.exegetes.eu.org/p/g.DSXI1kGFT1gjor66$Abro-REP-Tele2-Principal/export/txt' \
+           -g 'https://pad.exegetes.eu.org/p/g.DSXI1kGFT1gjor66$Abro-REP-Tele2-Garde/export/txt' &
 pids+=($!)
 pids+=($!)
 
 
-./cocktail -v -d MonDossier -p Abro2 -b 'https://pad.exegetes.eu.org/p/g.DSXI1kGFT1gjor66$Abro-REP-Tele2-Principal/export/txt' -g 'https://pad.exegetes.eu.org/p/g.DSXI1kGFT1gjor66$Abro-REP-Tele2-Garde/export/txt' &
+./cocktail -v \
+           -d MonDossier \
+           -p Abro2 \
+           -b 'https://pad.exegetes.eu.org/p/g.DSXI1kGFT1gjor66$Abro-REP-Tele2-Principal/export/txt' \
+           -g 'https://pad.exegetes.eu.org/p/g.DSXI1kGFT1gjor66$Abro-REP-Tele2-Garde/export/txt' &
 pids+=($!)
 pids+=($!)
 
 
 # Wait until all background processes are stopped
 # Wait until all background processes are stopped
@@ -49,22 +46,23 @@ do
   sleep 2;
   sleep 2;
 done
 done
 echo STOPPED
 echo STOPPED
-echo "RC1=$RC1 RC2=$RC2"
 
 
-# cocktail exits with rc 2 if error lock
-if test "$RC1" -eq 0 -a "$RC2" -eq 2;
-then
-  echo "Test réussi"
-  exit 0
-fi
+# affichage des code retour et generation de la chaine de test
+for pid in "${!retcode[@]}"
+do
+  statusstring="$statusstring $pid=${retcode[$pid]}"
+  retcodestr="${retcodestr}${retcode[$pid]}"
+done
+echo $statusstring
 
 
-# cocktail exits with rc 2 if error lock
-if test "$RC2" -eq 0 -a "$RC1" -eq 2;
+if test $retcodestr -eq "02" -o $retcodestr -eq "20";
 then
 then
   echo "Test réussi"
   echo "Test réussi"
+  echo "Un des 2 processus s'est terminé en code 0 et l'autre en code 2"
   exit 0
   exit 0
+else
+  echo "Test échoué."
+  echo "Un des 2 processus doit se terminer en code 0 et l'autre en code 2"
+  exit 1
 fi
 fi
 
 
-echo "Test échoué"
-exit 1
-