/[escript]/release/5.2/site_scons/grouptest.py
ViewVC logotype

Contents of /release/5.2/site_scons/grouptest.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6692 - (show annotations)
Mon Jun 25 02:31:06 2018 UTC (2 years, 10 months ago) by jfenwick
File MIME type: text/x-python
File size: 6213 byte(s)
Fix

1 ##############################################################################
2 #
3 # Copyright (c) 2003-2018 by The University of Queensland
4 # http://www.uq.edu.au
5 #
6 # Primary Business: Queensland, Australia
7 # Licensed under the Apache License, version 2.0
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Development until 2012 by Earth Systems Science Computational Center (ESSCC)
11 # Development 2012-2013 by School of Earth Sciences
12 # Development from 2014 by Centre for Geoscience Computing (GeoComp)
13 #
14 ##############################################################################
15
16 from __future__ import print_function, division
17
18 __copyright__="""Copyright (c) 2003-2018 by The University of Queensland
19 http://www.uq.edu.au
20 Primary Business: Queensland, Australia"""
21 __license__="""Licensed under the Apache License, version 2.0
22 http://www.apache.org/licenses/LICENSE-2.0"""
23 __url__="https://launchpad.net/escript-finley"
24
25
26
27 class GroupTest(object):
28 _allfuncs = []
29
30 def __init__(self, name, exec_cmd, evars, python_dir, working_dir, test_list, single_process_tests=[]):
31 self.name=name
32 self.python_dir=python_dir
33 self.working_dir=working_dir
34 self.test_list=test_list
35 self.exec_cmd=exec_cmd
36 self.evars=evars
37 self.mkdirs=[]
38 self.single_process_tests=single_process_tests
39 self._allfuncs.append(name)
40
41 def makeDir(self,dirname):
42 self.mkdirs.append(dirname)
43
44 #stdloc means that the files are in standard locations so don't use prefix
45 def makeHeader(build_platform, prefix, stdloc):
46 res="""#!/bin/sh
47 #############################################
48 # This file is autogenerated by scons.
49 # It will be regenerated each time scons is run
50 #############################################
51
52 failed () {
53 echo "Execution failed for $@"
54 exit 1
55 }
56
57 if [ $# -lt 2 ]; then
58 echo "Usage: $0 build_dir wrapper_options [groupname]"
59 echo Runs all or a group of unit tests. Options must be a single string.
60 exit 2
61 fi
62
63 case "$1" in
64 /*) ;;
65 *) echo "build_dir needs to be an absolute path"; exit 4;;
66 esac
67
68 NUMPROCS=1
69 NUMNODES=1
70 while getopts ':n:p:' option $2
71 do
72 case "$option" in
73 "n") NUMNODES=$OPTARG ;;
74 "p") NUMPROCS=$OPTARG ;;
75 esac
76 done
77 MPIPROD=$(($NUMPROCS * $NUMNODES))
78 """
79 res+="BUILD_DIR=$1"+"/"+build_platform
80 res+="\nif [ ! -d $BUILD_DIR ]\nthen\n echo Can not find build directory $BUILD_DIR\n exit 2\nfi\n"
81 if stdloc:
82 res+="""MPITYPE=`run-escript -c | grep mpi=`
83 export OLD_PYTHON=$PYTHONPATH
84 BATCH_ROOT=`pwd`
85 BINRUNNER="run-escript -b $2"
86 PYTHONRUNNER="run-escript $2"
87 PYTHONTESTRUNNER="run-escript $2 $BATCH_ROOT/tools/testrunner.py"
88 """
89 else:
90 res+="""MPITYPE=`{0}/bin/run-escript -c | grep mpi=`
91 BATCH_ROOT=`pwd`
92 export LD_LIBRARY_PATH={0}/lib:$LD_LIBRARY_PATH
93 export OLD_PYTHON={0}:$PYTHONPATH
94 BINRUNNER="{0}/bin/run-escript -b $2"
95 PYTHONRUNNER="{0}/bin/run-escript $2"
96 PYTHONTESTRUNNER="{0}/bin/run-escript $2 {0}/tools/testrunner.py"
97 """.format(prefix)
98 if build_platform=='darwin':
99 res+="export DYLD_LIBRARY_PATH=$LD_LIBRARY_PATH:$DYLD_LIBRARY_PATH\n"
100 return res
101 makeHeader=staticmethod(makeHeader)
102
103 def makeString(self):
104 res="%s () {\n"%self.name
105 tt="\t"
106 build_dir = self.working_dir.replace("$BATCH_ROOT", "$BUILD_DIR")
107 for d in self.mkdirs:
108 res=res+tt+"if [ ! -d "+str(d)+" ]\n"+tt+"then\n"+tt+"\tmkdir -p "+str(d)+"\n"+tt+"fi\n"
109 for v in self.evars:
110 res=res+tt+"export "+str(v[0])+"="+str(v[1])+"\n"
111 res=res+tt+"if [ ! -d "+str(self.working_dir)+" ]\n"+tt+"then\n"+tt+"\tmkdir -p "+str(self.working_dir)+"\n"+tt+"fi\n"
112 if len(self.python_dir)>0:
113 res=res+tt+"export PYTHONPATH="+self.python_dir+":$OLD_PYTHON"+"\n"+tt+"cd "+self.working_dir+"\n"
114 else:
115 res=res+tt+"export PYTHONPATH=$OLD_PYTHON"+"\n"+tt+"cd "+self.working_dir+"\n"
116 if len(self.single_process_tests) > 0:
117 res+=tt+"if [ $MPIPROD -le 1 ]; then\n"
118 #res+=tt+'if [ "$MPITYPE" == "mpi=none" ]; then\n'
119 tt+="\t"
120 for t in self.single_process_tests:
121 res=res+tt+"echo Starting "+t+"\n"+tt+"date\n"
122 skipoutputfile = ""
123 failoutputfile = ""
124 cmd = self.exec_cmd
125 exit_on_failure = " || failed %s"%t
126 if "examples" not in build_dir and "PYTHONRUNNER" in self.exec_cmd \
127 and "/tools/" not in build_dir:
128 skipoutputfile = " -skipfile={0}/{1}".format(build_dir, t.replace(".py", ".skipped"))
129 failoutputfile = " -failfile={0}/{1}".format(build_dir, t.replace(".py", ".failed"))
130 cmd = cmd.replace("PYTHONRUNNER", "PYTHONTESTRUNNER")
131 res += "".join([tt, cmd, t, failoutputfile, skipoutputfile, exit_on_failure, "\n"])
132 res += tt+"echo Completed "+t+"\n"
133 tt="\t"
134 res+=tt+"fi\n"
135 for t in self.test_list:
136 res=res+tt+"echo Starting "+t+"\n"+tt+"date\n"
137 skipoutputfile = ""
138 failoutputfile = ""
139 cmd = self.exec_cmd
140 exit_on_failure = " || failed %s"%t
141 if "examples" not in build_dir and "PYTHONRUNNER" in self.exec_cmd \
142 and "/tools/" not in build_dir:
143 skipoutputfile = " -skipfile={0}/{1}".format(build_dir, t.replace(".py", ".skipped"))
144 failoutputfile = " -failfile={0}/{1}".format(build_dir, t.replace(".py", ".failed"))
145 cmd = cmd.replace("PYTHONRUNNER", "PYTHONTESTRUNNER")
146 res += "".join([tt, cmd, t, failoutputfile, skipoutputfile, exit_on_failure, "\n"])
147 res += tt+"echo Completed "+t+"\n"
148 res=res+"}\n"
149 return res
150
151 def makeFooter(self):
152 res="if [ $# -gt 2 ]; then\n\teval $3\nelse\n\t"
153 res+="\n\t".join(self._allfuncs)
154 res+="\nfi\nfind $BUILD_DIR -name '*.failed' | xargs cat; find $BUILD_DIR -name '*.failed' | xargs cat | diff -q - /dev/null >/dev/null\n"
155 return res
156

  ViewVC Help
Powered by ViewVC 1.1.26