NeoPZ
test.py
Go to the documentation of this file.
1 #! /usr/bin/env python2.7
2 #***************************************************************************
3 #* Copyright (C) 2013 by Edson Borin *
4 #* edson@ic.unicamp.br *
5 #* *
6 #* This program is free software; you can redistribute it and/or modify *
7 #* it under the terms of the GNU General Public License as published by *
8 #* the Free Software Foundation; either version 2 of the License, or *
9 #* (at your option) any later version. *
10 #* *
11 #* This program is distributed in the hope that it will be useful, *
12 #* but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 #* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 #* GNU General Public License for more details. *
15 #* *
16 #* You should have received a copy of the GNU General Public License *
17 #* along with this program; if not, write to the *
18 #* Free Software Foundation, Inc., *
19 #* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
20 #**************************************************************************/
21 
22 # ---------------------------------------------
23 # Performance test module
24 
25 # List of rdt files generated by the test
26 rdtfiles_l = [
27  # short_name, option, filename, description
28  ("ass", "-ass_rdt", "ass.rdt", "Assemble: dohrstruct->Assemble(...). Assemble element matrices and decompose matrices."),
29  ("cre", "-cre_rdt", "cre.rdt", "Create: dohrstruct->Create()"),
30  ("sol", "-sol_rdt", "sol.rdt", "Solver: cg.Solve(...)"),
31  ("tot", "-tot_rdt", "tot.rdt", "Total: all the steps"),
32  ("dohrass", "-tpz_dohr_ass", "tpzdohrass.rdt", "Assemble element matrices"),
33  ("dohrdec", "-tpz_dohr_dec", "tpzdohrdec.rdt", "Decompose matrices")
34 ]
35 
36 def short_description() : return "substructure -- 8andares02.txt -- p1 -- nsub 64 -- serial"
37 
38 def long_description():
39  desc = "Execute the substruct tool collecting statistics for the following steps:"
40  for rdtarg in rdtfiles_l :
41  desc = desc + '\n\t' + rdtarg[0] + ' (' + rdtarg[1] + ' ' + rdtarg [2] + ') : ' + rdtarg[3]
42  return desc
43 # ---------------------------------------------
44 
45 import sys
46 import os.path
47 import shlex, subprocess
48 import resource
49 
50 # Try to import rdt and stats modules, if available.
51 import sys
52 
53 # Variables to be defined by cmake
54 builddir="@PERFTEST_BASE_DIR@"
55 datadir="@PERFTEST_SMALL_DATA_DIR@"
56 
57 def error(message, status):
58  sys.stderr.write('ERROR (test.py): '+message+'\n')
59  sys.exit(status)
60 
61 # Setup the command line
62 def setup_cmd():
63  # Check build directory
64  if not os.path.isdir(builddir) :
65  error(builddir+' is an invalid build directory.', 1)
66  # Check run directory
67  rundir = os.path.join(builddir,'scripts','substruct_tst03')
68  if not os.path.isdir(rundir) :
69  error(rundir+' is an invalid run directory.', 1)
70  if not os.path.isdir(builddir) :
71  error(builddir+' is an invalid build directory.', 1)
72  # Check executable
73  executable=os.path.join(builddir,"progs","substruct", "substruct-perf")
74  if not os.path.isfile(executable) :
75  error(executable+' is an invalid executable file name.', 1)
76  # Check input file
77  inputfn = os.path.join(datadir,"substruct","inputs","8andares02.txt")
78  if not os.path.isfile(inputfn) :
79  error(inputfn+' is an invalid input file name.', 1)
80  # Put the arguments together
81  arguments = ' -mp '+inputfn
82  arguments = arguments + ' -nsub 64'
83  arguments = arguments + ' -nt_a 1'
84  arguments = arguments + ' -nt_d 1'
85  arguments = arguments + ' -nt_m 1'
86  arguments = arguments + ' -nt_sm 1'
87  arguments = arguments + ' -p 1'
88  for rdtarg in rdtfiles_l :
89  arguments = arguments + ' ' + rdtarg[1] + ' ' + rdtarg[2]
90  # TODO: Add arguments to enforce output checking!
91  return rundir, executable+arguments
92 
93 # Limits for this test
94 limits = { "cpu" : (resource.RLIMIT_CPU, 38400, "Max CPU user time in seconds (not wall clock time)"),
95 # "nofile": (resource.RLIMIT_NOFILE, 7, "The maximum number of open file descriptors for the current process."),
96 # "rss" : (resource.RLIMIT_RSS, 1024, "The maximum resident set size that should be made available to the process"),
97 # "fsize" : (resource.RLIMIT_FSIZE, 1, "Max size of a file which the process may create"),
98 # "data" : (resource.RLIMIT_DATA, 1024, "The maximum size (in bytes) of the process's heap"),
99 # "nproc" : (resource.RLIMIT_NPROC, 0, "The maximum number of processes the current process may create")
100  }
101 
102 # Set the rlimits of the chidren process (see limits above)
103 # TODO: Improve the handling of sandboxing limits
104 def setlimits():
105  print "Setting resource limit in child"
106  for k, v in limits.iteritems() :
107  resource.setrlimit(v[0], (v[1],v[1]))
108  #print k, " : ", v[0], " => ", v[1]
109 
110 # Sumarizes the RDT (Raw data table) files information
111 def sumarize_rdt_files(rundir) :
112  results = {}
113  for f in rdtfiles_l :
114  rdt_id = f[0] # Step name
115  rdt_fn = os.path.join(rundir,f[2]) # RDT file name
116  rdt_dsc = f[3] # Description
117  results[rdt_id] = (rdt_fn, rdt_dsc)
118  return results
119 
120 # Execute the test.
121 def run_test(ntimes):
122  rundir,cmd=setup_cmd()
123  print short_description()
124  print "CMD:",cmd
125  args = shlex.split(cmd)
126  sout = None
127  serr = None
128  for i in range(ntimes) :
129  p = subprocess.Popen(args, preexec_fn=setlimits, stdout=sout, stderr=serr, cwd=rundir)
130  p.wait()
131  if (p.returncode != 0) :
132  return p.returncode, {}
133  results = sumarize_rdt_files(rundir)
134  return 0, results
def short_description()
Definition: test.py:36
def run_test(ntimes)
Definition: test.py:121
def sumarize_rdt_files(rundir)
Definition: test.py:111
def error(message, status)
Definition: test.py:57
def setup_cmd()
Definition: test.py:62