Salome HOME
Merge multi-study removal branch.
[modules/kernel.git] / bin / appliskel / tests / concurrentSession / usecase_concurrent.sh
1 #!/bin/bash
2
3 # Copyright (C) 2015-2016  CEA/DEN, EDF R&D, OPEN CASCADE
4 #
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 2.1 of the License, or (at your option) any later version.
9 #
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 # Lesser General Public License for more details.
14 #
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with this library; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
18 #
19 # See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 #
21
22 echo "This is a script that can be run concurrently."
23 echo "It takes as single argument the number of concurrent executions:"
24 echo "Usage: " $0 "<nb_execution> <output_folder>"
25 echo
26 echo "Here is what executed code contents looks like:"
27 echo "   - do some stuff"
28 echo "   - run SALOME in terminal mode, and log port number to a file"
29 echo "   - run some scripts (Python, binary), each in a dedicated SALOME session on a specific port"
30 echo "   - do some stuff"
31 echo
32
33
34 if [ $# != 2 ]; then
35     echo "Usage:" $0 "<nb_execution> <output_folder>"
36     exit 1
37 fi
38
39 NB_COMP=$1
40 OUTPUT_FOLDER=$2
41 BASE_DIR=`pwd`
42
43 if [ "x${SALOME_APPLI_FOLDER}" == "x" ]; then
44     echo "SALOME_APPLI_FOLDER variable is not set (or empty)."
45     echo "Try to locate SALOME launcher in current directory."
46     SALOME_APPLI_FOLDER=`pwd`
47     if ! [ -f ${SALOME_APPLI_FOLDER}/salome ]; then
48         echo "Unable to locate salome command."
49         exit 1
50     fi
51 fi
52
53 run_command() {
54     WORK_DIR=`pwd` # a pushd has been done before calling this function
55     echo "Run command in folder:" ${WORK_DIR}
56     ${SALOME_APPLI_FOLDER}/salome start -t --ns-port-log=${WORK_DIR}/session.log
57     ${SALOME_APPLI_FOLDER}/salome shell -p `cat ${WORK_DIR}/session.log` ${SALOME_APPLI_FOLDER}/bin/salome/waitContainers.py
58     ${SALOME_APPLI_FOLDER}/salome shell -p `cat ${WORK_DIR}/session.log` ${BASE_DIR}/hello.py
59     ${SALOME_APPLI_FOLDER}/salome shell -p `cat ${WORK_DIR}/session.log` ${SALOME_APPLI_FOLDER}/bin/salome/killSalomeWithPort.py args:`cat ${WORK_DIR}/session.log`
60     echo "Execution terminated in folder:" ${WORK_DIR}
61 }
62
63
64 # make hello.py
65 echo "
66 #!/usr/bin/env python
67 print 'Hello\!'
68 " > ${BASE_DIR}/hello.py
69
70 # Build output folders
71 typeset -i i=${NB_COMP}
72 while (( $i > 0 ))
73 do
74     mkdir -p ${OUTPUT_FOLDER}/execution_$i
75     let "i=i-1"
76 done
77
78 # Start execution
79 typeset -i i=${NB_COMP}
80 while (( $i > 0 ))
81 do
82     pushd ${OUTPUT_FOLDER}/execution_$i > /dev/null
83     run_command &
84     popd > /dev/null
85     let "i=i-1"
86 done