]> SALOME platform Git repositories - modules/kernel.git/blob - bin/appliskel/tests/concurrentSession/usecase_concurrent_single_appli.sh
Salome HOME
add salome_starter.py for application folder detection
[modules/kernel.git] / bin / appliskel / tests / concurrentSession / usecase_concurrent_single_appli.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 SALOME_PORT=-1
24
25 case ${OUTPUT_FOLDER} in
26     /*) ;; # OUTPUT_FOLDER is given as an absolute path
27     *) OUTPUT_FOLDER=${BASE_DIR}/${OUTPUT_FOLDER} ;; # build absolute path
28 esac
29
30 if [ "x${SALOME_APPLI_FOLDER}" == "x" ]; then
31     echo "SALOME_APPLI_FOLDER variable is not set (or empty)."
32     echo "Try to locate SALOME launcher in current directory."
33     SALOME_APPLI_FOLDER=`pwd`
34     if ! [ -f ${SALOME_APPLI_FOLDER}/salome ]; then
35         echo "Unable to locate salome command."
36         exit 1
37     fi
38 fi
39
40 start_salome() {
41     ${SALOME_APPLI_FOLDER}/salome start -t --ns-port-log=${OUTPUT_FOLDER}/session.log
42     SALOME_PORT=`cat ${OUTPUT_FOLDER}/session.log`
43     echo "SALOME is running on port" ${SALOME_PORT}
44 }
45
46 stop_salome() {
47     ${SALOME_APPLI_FOLDER}/salome shell -p ${SALOME_PORT} ${SALOME_APPLI_FOLDER}/bin/salome/killSalomeWithPort.py args:${SALOME_PORT}
48 }
49
50 run_command() {
51     WORK_DIR=`pwd` # a pushd has been done before calling this function
52     echo "Run command in folder:" ${WORK_DIR}
53     ${SALOME_APPLI_FOLDER}/salome shell -p ${SALOME_PORT} ${SALOME_APPLI_FOLDER}/bin/salome/waitContainers.py
54     ${SALOME_APPLI_FOLDER}/salome shell -p ${SALOME_PORT} ${BASE_DIR}/myscript.py args:${WORK_DIR}
55     echo "Execution terminated in folder:" ${WORK_DIR}
56 }
57
58
59 # make myscript.py
60 echo "
61 #!/usr/bin/env python
62 import os
63 import sys
64 import time
65 work_dir = sys.argv[1]
66 logfile = os.path.join(work_dir, 'myscript.log')
67 msg = 'Waiting for 3s in folder %s'%work_dir
68 time.sleep(3)
69 with open(logfile, 'w') as f:
70   f.write(msg)
71 " > ${BASE_DIR}/myscript.py
72
73 # Build output folders
74 typeset -i i=${NB_COMP}
75 while (( $i > 0 ))
76 do
77     mkdir -p ${OUTPUT_FOLDER}/execution_$i
78     let "i=i-1"
79 done
80
81 # Start execution
82 start_salome
83 typeset -i i=${NB_COMP}
84 while (( $i > 0 ))
85 do
86     pushd ${OUTPUT_FOLDER}/execution_$i > /dev/null
87     run_command &
88     popd > /dev/null
89     let "i=i-1"
90 done
91 stop_salome