Salome HOME
Merge branch 'agy/ParallelContainerLaunch'
[modules/kernel.git] / bin / appliskel / tests / concurrentSession / usecase_concurrent.sh
1 #!/bin/bash
2
3 echo "This is a script that can be run concurrently."
4 echo "It takes as single argument the number of concurrent executions:"
5 echo "Usage: " $0 "<nb_execution> <output_folder>"
6 echo
7 echo "Here is what executed code contents looks like:"
8 echo "   - do some stuff"
9 echo "   - run SALOME in terminal mode, and log port number to a file"
10 echo "   - run some scripts (Python, binary), each in a dedicated SALOME session on a specific port"
11 echo "   - do some stuff"
12 echo
13
14
15 if [ $# != 2 ]; then
16     echo "Usage:" $0 "<nb_execution> <output_folder>"
17     exit 1
18 fi
19
20 NB_COMP=$1
21 OUTPUT_FOLDER=$2
22 BASE_DIR=`pwd`
23
24 if [ "x${SALOME_APPLI_FOLDER}" == "x" ]; then
25     echo "SALOME_APPLI_FOLDER variable is not set (or empty)."
26     echo "Try to locate SALOME launcher in current directory."
27     SALOME_APPLI_FOLDER=`pwd`
28     if ! [ -f ${SALOME_APPLI_FOLDER}/salome ]; then
29         echo "Unable to locate salome command."
30         exit 1
31     fi
32 fi
33
34 run_command() {
35     WORK_DIR=`pwd` # a pushd has been done before calling this function
36     echo "Run command in folder:" ${WORK_DIR}
37     ${SALOME_APPLI_FOLDER}/salome start -t --ns-port-log=${WORK_DIR}/session.log
38     ${SALOME_APPLI_FOLDER}/salome shell -p `cat ${WORK_DIR}/session.log` ${SALOME_APPLI_FOLDER}/bin/salome/waitContainers.py
39     ${SALOME_APPLI_FOLDER}/salome shell -p `cat ${WORK_DIR}/session.log` ${BASE_DIR}/hello.py
40     ${SALOME_APPLI_FOLDER}/salome shell -p `cat ${WORK_DIR}/session.log` ${SALOME_APPLI_FOLDER}/bin/salome/killSalomeWithPort.py args:`cat ${WORK_DIR}/session.log`
41     echo "Execution terminated in folder:" ${WORK_DIR}
42 }
43
44
45 # make hello.py
46 echo "
47 #!/usr/bin/env python
48 print 'Hello\!'
49 " > ${BASE_DIR}/hello.py
50
51 # Build output folders
52 typeset -i i=${NB_COMP}
53 while (( $i > 0 ))
54 do
55     mkdir -p ${OUTPUT_FOLDER}/execution_$i
56     let "i=i-1"
57 done
58
59 # Start execution
60 typeset -i i=${NB_COMP}
61 while (( $i > 0 ))
62 do
63     pushd ${OUTPUT_FOLDER}/execution_$i > /dev/null
64     run_command &
65     popd > /dev/null
66     let "i=i-1"
67 done