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 -- 64 threads"
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 
62 # Setup the command line
63 def setup_cmd():
64  # Check build directory
65  if not os.path.isdir(builddir) :
66  error(builddir+' is an invalid build directory.', 1)
67  # Check run directory
68  rundir = os.path.join(builddir,'scripts','substruct_tst04')
69  if not os.path.isdir(rundir) :
70  error(rundir+' is an invalid run directory.', 1)
71  if not os.path.isdir(builddir) :
72  error(builddir+' is an invalid build directory.', 1)
73  # Check executable
74  executable=os.path.join(builddir,"progs","substruct", "substruct-perf")
75  if not os.path.isfile(executable) :
76  error(executable+' is an invalid executable file name.', 1)
77  # Check input file
78  inputfn = os.path.join(datadir,"substruct","inputs","8andares02.txt")
79  if not os.path.isfile(inputfn) :
80  error(inputfn+' is an invalid input file name.', 1)
81  # Put the arguments together
82  arguments = ' -mp '+inputfn
83  arguments = arguments + ' -nsub 64'
84  arguments = arguments + ' -nt_a 64'
85  arguments = arguments + ' -nt_d 64'
86  arguments = arguments + ' -nt_m 64'
87  arguments = arguments + ' -nt_sm 64'
88  arguments = arguments + ' -p 1'
89  for rdtarg in rdtfiles_l :
90  arguments = arguments + ' ' + rdtarg[1] + ' ' + rdtarg[2]
91  # TODO: Add arguments to enforce output checking!
92  return rundir, executable+arguments
93 
94 # Limits for this test
95 limits = { "cpu" : (resource.RLIMIT_CPU, 38400, "Max CPU user time in seconds (not wall clock time)"),
96 # "nofile": (resource.RLIMIT_NOFILE, 7, "The maximum number of open file descriptors for the current process."),
97 # "rss" : (resource.RLIMIT_RSS, 1024, "The maximum resident set size that should be made available to the process"),
98 # "fsize" : (resource.RLIMIT_FSIZE, 1, "Max size of a file which the process may create"),
99 # "data" : (resource.RLIMIT_DATA, 1024, "The maximum size (in bytes) of the process's heap"),
100 # "nproc" : (resource.RLIMIT_NPROC, 0, "The maximum number of processes the current process may create")
101  }
102 
103 # Set the rlimits of the chidren process (see limits above)
104 # TODO: Improve the handling of sandboxing limits
105 def setlimits():
106  print "Setting resource limit in child"
107  for k, v in limits.iteritems() :
108  resource.setrlimit(v[0], (v[1],v[1]))
109  #print k, " : ", v[0], " => ", v[1]
110 
111 # Sumarizes the RDT (Raw data table) files information
112 def sumarize_rdt_files(rundir) :
113  results = {}
114  for f in rdtfiles_l :
115  rdt_id = f[0] # Step name
116  rdt_fn = os.path.join(rundir,f[2]) # RDT file name
117  rdt_dsc = f[3] # Description
118  results[rdt_id] = (rdt_fn, rdt_dsc)
119  return results
120 
121 # Execute the test.
122 def run_test(ntimes):
123  rundir,cmd=setup_cmd()
124  print short_description()
125  print "CMD:",cmd
126  args = shlex.split(cmd)
127  sout = None
128  serr = None
129  for i in range(ntimes) :
130  p = subprocess.Popen(args, preexec_fn=setlimits, stdout=sout, stderr=serr, cwd=rundir)
131  p.wait()
132  if (p.returncode != 0) :
133  return p.returncode, {}
134  results = sumarize_rdt_files(rundir)
135  return 0, results
136 
def sumarize_rdt_files(rundir)
Definition: test.py:112
def setup_cmd()
Definition: test.py:63
def error(message, status)
Definition: test.py:57
def short_description()
Definition: test.py:36
def run_test(ntimes)
Definition: test.py:122