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

Contents of /trunk/site_scons/grouptest.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6034 - (show annotations)
Wed Mar 9 00:37:57 2016 UTC (2 years, 8 months ago) by caltinay
File MIME type: text/x-python
File size: 7289 byte(s)
a few changes to GroupTest / utest:
GroupTest class now takes a name parameter that is used as (shell) function
name in utest for the test group.
By default all tests are run as before but one can now do:
./utest.sh build '-t2' escriptcpp
to only run the escript c++ unit tests.
Also tweaked a couple things so utest.sh does now work with dash.

1 ##############################################################################
2 #
3 # Copyright (c) 2003-2016 by The 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 from __future__ import print_function, division
17
18 __copyright__="""Copyright (c) 2003-2016 by The University of Queensland
19 http://www.uq.edu.au
20 Primary Business: Queensland, Australia"""
21 __license__="""Licensed under the Open Software License version 3.0
22 http://www.opensource.org/licenses/osl-3.0.php"""
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\n"
47 res=res+"\n#############################################\n"
48 res=res+"# This file is autogenerated by scons.\n"
49 res=res+"# It will be regenerated each time scons is run\n"
50 res=res+"#############################################\n\n"
51 res=res+"failed ()\n{\n echo ""Execution failed for $@""\n exit 1\n}\n"
52 res=res+"if [ $# -lt 2 ]\nthen\n echo \"Usage: $0 build_dir wrapper_options [groupname]\"\necho Runs all or a group of unit tests. Options must be a single string.\nexit 2\nfi\n"
53 res=res+'CMDSTR="getopt p:n: -- $2" #Not using -uq -o because that is GNU only\nSTR=`$CMDSTR`\nNUMPROCS=1\n'
54 if stdloc:
55 res=res+'MPITYPE=`run-escript -c | grep mpi=`\n'
56 else:
57 res=res+'MPITYPE=`%s/bin/run-escript -c | grep mpi=`\n'%prefix
58 res=res+'NUMNODES=1\n#This little complication is required because set --\n'
59 res=res+'#does not seem to like -n as the first positional parameter\n'
60 res=res+'STATE=0\nfor name in $STR\ndo \n'
61 res=res+'case $STATE in\n'
62 res=res+' 0) case $name in\n'
63 res=res+' -n) STATE=1;;\n'
64 res=res+' -p) STATE=2;;\n'
65 res=res+' --) break 2;;\n'
66 res=res+' esac;;\n'
67 res=res+' 1) if [ $name == "--" ];then break; fi; NUMNODES=$name; STATE=0;;\n'
68 res=res+' 2) if [ $name == "--" ];then break; fi; NUMPROCS=$name; STATE=0;;\n'
69 res=res+' esac\n'
70 res=res+'done\n'
71 res=res+'MPIPROD=$(($NUMPROCS * $NUMNODES))\n'
72 if not stdloc:
73 res=res+"\nexport LD_LIBRARY_PATH=%s/lib:$LD_LIBRARY_PATH\n"%prefix
74 if build_platform=='darwin':
75 res=res+"export DYLD_LIBRARY_PATH=$LD_LIBRARY_PATH:$DYLD_LIBRARY_PATH\n"
76 if stdloc:
77 res=res+"\nexport OLD_PYTHON=$PYTHONPATH\nBINRUNNER=\"run-escript -b $2\"\nPYTHONRUNNER=\"run-escript $2\"\nBATCH_ROOT=`pwd`\n"
78 res=res+"PYTHONTESTRUNNER=\"run-escript $2 $BATCH_ROOT/tools/testrunner.py\"\n"
79 else:
80 res=res+"""\nexport OLD_PYTHON={0}:$PYTHONPATH
81 BINRUNNER=\"{0}/bin/run-escript -b $2\"
82 PYTHONRUNNER=\"{0}/bin/run-escript $2\"
83 PYTHONTESTRUNNER=\"{0}/bin/run-escript $2 {0}/tools/testrunner.py\"
84 BATCH_ROOT=`pwd`\n""".format(prefix)
85 res=res+"BUILD_DIR=$1"+"/"+build_platform
86 res=res+"\nif [ ! -d $BUILD_DIR ]\nthen\n echo Can not find build directory $BUILD_DIR\n exit 2\nfi\n"
87 #res=res+"if [ $# -lt 2 ]\nthen\n echo Usage: $0 bin_run_cmd python_run_cmd\n exit 2\nfi\n"
88 return res
89 makeHeader=staticmethod(makeHeader)
90
91 def makeString(self):
92 res="%s () {\n"%self.name
93 tt="\t"
94 build_dir = self.working_dir.replace("$BATCH_ROOT", "$BUILD_DIR")
95 for d in self.mkdirs:
96 res=res+tt+"if [ ! -d "+str(d)+" ]\n"+tt+"then\n"+tt+"\tmkdir -p "+str(d)+"\n"+tt+"fi\n"
97 for v in self.evars:
98 res=res+tt+"export "+str(v[0])+"="+str(v[1])+"\n"
99 res=res+tt+"if [ ! -d "+str(self.working_dir)+" ]\n"+tt+"then\n"+tt+"\tmkdir -p "+str(self.working_dir)+"\n"+tt+"fi\n"
100 if len(self.python_dir)>0:
101 res=res+tt+"export PYTHONPATH="+self.python_dir+":$OLD_PYTHON"+"\n"+tt+"cd "+self.working_dir+"\n"
102 else:
103 res=res+tt+"export PYTHONPATH=$OLD_PYTHON"+"\n"+tt+"cd "+self.working_dir+"\n"
104 if len(self.single_process_tests) > 0:
105 res+=tt+"if [ $MPIPROD -le 1 ]; then\n"
106 #res+=tt+'if [ "$MPITYPE" == "mpi=none" ]; then\n'
107 tt+="\t"
108 for t in self.single_process_tests:
109 res=res+tt+"echo Starting "+t+"\n"+tt+"date\n"
110 skipoutputfile = ""
111 failoutputfile = ""
112 cmd = self.exec_cmd
113 exit_on_failure = " || failed %s"%t
114 if "examples" not in build_dir and "PYTHONRUNNER" in self.exec_cmd \
115 and "/tools/" not in build_dir:
116 skipoutputfile = " -skipfile={0}/{1}".format(build_dir, t.replace(".py", ".skipped"))
117 failoutputfile = " -failfile={0}/{1}".format(build_dir, t.replace(".py", ".failed"))
118 cmd = cmd.replace("PYTHONRUNNER", "PYTHONTESTRUNNER")
119 exit_on_failure = ""
120 res += "".join([tt, cmd, t, failoutputfile, skipoutputfile, exit_on_failure, "\n"])
121 res += tt+"echo Completed "+t+"\n"
122 tt="\t"
123 res+=tt+"fi\n"
124 for t in self.test_list:
125 res=res+tt+"echo Starting "+t+"\n"+tt+"date\n"
126 skipoutputfile = ""
127 failoutputfile = ""
128 cmd = self.exec_cmd
129 exit_on_failure = " || failed %s"%t
130 if "examples" not in build_dir and "PYTHONRUNNER" in self.exec_cmd \
131 and "/tools/" not in build_dir:
132 skipoutputfile = " -skipfile={0}/{1}".format(build_dir, t.replace(".py", ".skipped"))
133 failoutputfile = " -failfile={0}/{1}".format(build_dir, t.replace(".py", ".failed"))
134 cmd = cmd.replace("PYTHONRUNNER", "PYTHONTESTRUNNER")
135 exit_on_failure = ""
136 res += "".join([tt, cmd, t, failoutputfile, skipoutputfile, exit_on_failure, "\n"])
137 res += tt+"echo Completed "+t+"\n"
138 res=res+"}\n"
139 return res
140
141 def makeFooter(self):
142 res="if [ $# -gt 2 ]; then\n\teval $3\nelse\n\t"
143 res+="\n\t".join(self._allfuncs)
144 res+="\nfi\nfind $BUILD_DIR -name '*.failed' | xargs cat; find $BUILD_DIR -name '*.failed' | xargs cat | diff -q - /dev/null >/dev/null\n"
145 return res
146

  ViewVC Help
Powered by ViewVC 1.1.26