/[escript]/trunk/site_scons/grouptest.py
ViewVC logotype

Contents of /trunk/site_scons/grouptest.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5523 - (show annotations)
Wed Mar 11 01:04:43 2015 UTC (4 years, 1 month ago) by sshaw
File MIME type: text/x-python
File size: 6025 byte(s)
adding ommitted and import cat from command

1 ##############################################################################
2 #
3 # Copyright (c) 2003-2015 by University of Queensland
4 # http://www.uq.edu.au
5 #
6 # Primary Business: Queensland, Australia
7 # Licensed under the Open Software License version 3.0
8 # http://www.opensource.org/licenses/osl-3.0.php
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 __copyright__="""Copyright (c) 2003-2015 by University of Queensland
17 http://www.uq.edu.au
18 Primary Business: Queensland, Australia"""
19 __license__="""Licensed under the Open Software License version 3.0
20 http://www.opensource.org/licenses/osl-3.0.php"""
21 __url__="https://launchpad.net/escript-finley"
22
23
24
25 class GroupTest(object):
26 def __init__(self, exec_cmd, evars, python_dir, working_dir, test_list, single_processor_only=False):
27 self.python_dir=python_dir
28 self.working_dir=working_dir
29 self.test_list=test_list
30 self.exec_cmd=exec_cmd
31 self.evars=evars
32 self.mkdirs=[]
33 self.single_processor_only=single_processor_only
34
35 def makeDir(self,dirname):
36 self.mkdirs.append(dirname)
37
38 #stdloc means that the files are in standard locations so don't use prefix
39 def makeHeader(build_platform, prefix, stdloc):
40 res="#!/bin/bash\n"
41 res=res+"\n#############################################\n"
42 res=res+"# This file is autogenerated by scons.\n"
43 res=res+"# It will be regenerated each time scons is run\n"
44 res=res+"#############################################\n\n"
45 res=res+"function failed()\n{\n echo ""Execution failed for $@""\n exit 1\n}\n"
46 res=res+"if [ $# -ne 2 ]\nthen\n echo Usage: $0 build_dir wrapper_options\necho Runs all unit tests. Options must be a single string.\nexit 2\nfi\n"
47 res=res+'CMDSTR="getopt p:n: -- $2" #Not using -uq -o because that is GNU only\nSTR=`$CMDSTR`\nNUMPROCS=1\n'
48 if stdloc:
49 res=res+'MPITYPE=`run-escript -c | grep mpi=`\n'
50 else:
51 res=res+'MPITYPE=`%s/bin/run-escript -c | grep mpi=`\n'%prefix
52 res=res+'NUMNODES=1\n#This little complication is required because set --\n'
53 res=res+'#does not seem to like -n as the first positional parameter\n'
54 res=res+'STATE=0\nfor name in $STR\ndo \n'
55 res=res+'case $STATE in\n'
56 res=res+' 0) case $name in\n'
57 res=res+' -n) STATE=1;;\n'
58 res=res+' -p) STATE=2;;\n'
59 res=res+' --) break 2;;\n'
60 res=res+' esac;;\n'
61 res=res+' 1) if [ $name == "--" ];then break; fi; NUMNODES=$name; STATE=0;;\n'
62 res=res+' 2) if [ $name == "--" ];then break; fi; NUMPROCS=$name; STATE=0;;\n'
63 res=res+' esac\n'
64 res=res+'done\n'
65 res=res+'let MPIPROD="$NUMPROCS * $NUMNODES"\n'
66 if not stdloc:
67 res=res+"\nexport LD_LIBRARY_PATH=%s/lib:$LD_LIBRARY_PATH\n"%prefix
68 if build_platform=='darwin':
69 res=res+"export DYLD_LIBRARY_PATH=$LD_LIBRARY_PATH:$DYLD_LIBRARY_PATH\n"
70 if stdloc:
71 res=res+"\nexport OLD_PYTHON=$PYTHONPATH\nBINRUNNER=\"run-escript -b $2\"\nPYTHONRUNNER=\"run-escript $2\"\nBATCH_ROOT=`pwd`\n"
72 else:
73 res=res+"""\nexport OLD_PYTHON={0}:$PYTHONPATH
74 BINRUNNER=\"{0}/bin/run-escript -b $2\"
75 PYTHONRUNNER=\"{0}/bin/run-escript $2\"
76 PYTHONTESTRUNNER=\"{0}/bin/run-escript $2 {0}/tools/testrunner.py\"
77 BATCH_ROOT=`pwd`\n""".format(prefix)
78 res=res+"BUILD_DIR=$1"+"/"+build_platform
79 res=res+"\nif [ ! -d $BUILD_DIR ]\nthen\n echo Can not find build directory $BUILD_DIR\n exit 2\nfi\n"
80 #res=res+"if [ $# -lt 2 ]\nthen\n echo Usage: $0 bin_run_cmd python_run_cmd\n exit 2\nfi\n"
81 return res
82 makeHeader=staticmethod(makeHeader)
83
84 def makeString(self):
85 res=""
86 build_dir = self.working_dir.replace("$BATCH_ROOT", "$BUILD_DIR")
87 if self.single_processor_only:
88 res+="#if [ $MPIPROD -le 1 ]; then\n"
89 res+='if [ "$MPITYPE" == "mpi=none" ]; then\n'
90 tt="\t"
91 else:
92 tt=""
93 for d in self.mkdirs:
94 res=res+tt+"if [ ! -d "+str(d)+" ]\n"+tt+"then\n"+tt+"\tmkdir -p "+str(d)+"\n"+tt+"fi\n"
95 for v in self.evars:
96 res=res+tt+"export "+str(v[0])+"="+str(v[1])+"\n"
97 res=res+tt+"if [ ! -d "+str(self.working_dir)+" ]\n"+tt+"then\n"+tt+"\tmkdir -p "+str(self.working_dir)+"\n"+tt+"fi\n"
98 if len(self.python_dir)>0:
99 res=res+tt+"export PYTHONPATH="+self.python_dir+":$OLD_PYTHON"+"\n"+tt+"cd "+self.working_dir+"\n"
100 else:
101 res=res+tt+"export PYTHONPATH=$OLD_PYTHON"+"\n"+tt+"cd "+self.working_dir+"\n"
102 for t in self.test_list:
103 res=res+tt+"echo Starting "+t+"\ndate\n"
104 skipoutputfile = ""
105 failoutputfile = ""
106 cmd = self.exec_cmd
107 exit_on_failure = " || failed %s"%t
108 if "examples" not in build_dir and "PYTHONRUNNER" in self.exec_cmd \
109 and "/tools/" not in build_dir:
110 skipoutputfile = " -skipfile={0}/{1}".format(build_dir, t.replace(".py", ".skipped"))
111 failoutputfile = " -failfile={0}/{1}".format(build_dir, t.replace(".py", ".failed"))
112 cmd = cmd.replace("PYTHONRUNNER", "PYTHONTESTRUNNER")
113 exit_on_failure = ""
114 res += "".join([tt, cmd, t, failoutputfile, skipoutputfile, exit_on_failure, "\n"])
115 res += tt+"echo Completed "+t+"\n"
116 if self.single_processor_only:
117 res+="fi\n"
118 res=res+"\n"
119 return res
120
121 def makeFooter(self):
122 return "find $BUILD_DIR -name '*.failed' | xargs cat; find $BUILD_DIR -name '*.failed' | xargs cat | diff -q - /dev/null 2>/dev/null"

  ViewVC Help
Powered by ViewVC 1.1.26