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  ("ldlt", "-ldlt_rdt", "ldlt.rdt", "LDLt Decomposition: matrix->Decompose_LDLt(). Decompose matrix using LDLt Decomposition.")
29 ]
30 def short_description() : return "skyline tests (LDLt) -- cube1.txt -- polinomial order 2"
31 
32 def long_description():
33  desc = "Executes the skyline tool collecting statistics for the following steps:"
34  for rdtarg in rdtfiles_l :
35  desc = desc + '\n\t' + rdtarg[0] + ' (' + rdtarg[1] + ' ' + rdtarg [2] + ') : ' + rdtarg[3]
36  return desc
37 # ---------------------------------------------
38 
39 import sys
40 import os.path
41 import shlex, subprocess
42 import resource
43 
44 # Try to import rdt and stats modules, if available.
45 import sys
46 
47 # Variables to be defined by cmake
48 builddir="@PERFTEST_BASE_DIR@"
49 datadir="@PERFTEST_SMALL_DATA_DIR@"
50 
51 def error(message, status):
52  sys.stderr.write('ERROR (test.py): '+message+'\n')
53  sys.exit(status)
54 
55 # Setup the command line
56 def setup_cmd():
57  # Check build directory
58  if not os.path.isdir(builddir) :
59  error(builddir+' is an invalid build directory.', 5)
60  # Check run directory
61  rundir = os.path.join(builddir,'scripts','skyline_tst04')
62  if not os.path.isdir(rundir) :
63  error(rundir+' is an invalid run directory.', 1)
64  if not os.path.isdir(builddir) :
65  error(builddir+' is an invalid build directory.', 1)
66  # Check executable
67  executable=os.path.join(builddir,"progs","skyline", "skyline-perf")
68  if not os.path.isfile(executable) :
69  error(executable+' is an invalid executable file name.', 1)
70  # Check input file
71  inputfn = os.path.join(datadir,"substruct","inputs","cube1.txt")
72  if not os.path.isfile(inputfn) :
73  error(inputfn+' is an invalid input file name.', 1)
74  # Put the arguments together
75  arguments = ' -if ' + inputfn
76  arguments = arguments + ' -porder 2'
77  for rdtarg in rdtfiles_l :
78  arguments = arguments + ' ' + rdtarg[1] + ' ' + rdtarg[2]
79  # TODO: Add arguments to enforce output checking!
80  return rundir, executable+arguments
81 
82 # Limits for this test
83 # TODO: change cpu limit acording to program execution time
84 limits = { "cpu" : (resource.RLIMIT_CPU, 1000, "Max CPU user time in seconds (not wall clock time)"),
85 # "nofile": (resource.RLIMIT_NOFILE, 7, "The maximum number of open file descriptors for the current process."),
86 # "rss" : (resource.RLIMIT_RSS, 1024, "The maximum resident set size that should be made available to the process"),
87 # "fsize" : (resource.RLIMIT_FSIZE, 1, "Max size of a file which the process may create"),
88 # "data" : (resource.RLIMIT_DATA, 1024, "The maximum size (in bytes) of the process's heap"),
89 # "nproc" : (resource.RLIMIT_NPROC, 0, "The maximum number of processes the current process may create")
90  }
91 
92 # Set the rlimits of the chidren process (see limits above)
93 # TODO: Improve the handling of sandboxing limits
94 def setlimits():
95  print "Setting resource limit in child"
96  for k, v in limits.iteritems() :
97  resource.setrlimit(v[0], (v[1],v[1]))
98  #print k, " : ", v[0], " => ", v[1]
99 
100 # Sumarizes the RDT (Raw data table) files information
101 def sumarize_rdt_files(rundir) :
102  results = {}
103  for f in rdtfiles_l :
104  rdt_id = f[0] # Step name
105  rdt_fn = os.path.join(rundir,f[2]) # RDT file name
106  rdt_dsc = f[3] # Description
107  results[rdt_id] = (rdt_fn, rdt_dsc)
108  return results
109 
110 # Execute the test.
111 def run_test(ntimes):
112  rundir,cmd=setup_cmd()
113  print short_description()
114  print "CMD:",cmd
115  args = shlex.split(cmd)
116  sout = None
117  serr = None
118  for i in range(ntimes) :
119  p = subprocess.Popen(args, preexec_fn=setlimits, stdout=sout, stderr=serr, cwd=rundir)
120  p.wait()
121  if (p.returncode != 0) :
122  return p.returncode, {}
123  results = sumarize_rdt_files(rundir)
124  return 0, results
125 
def short_description()
Definition: test.py:30
def sumarize_rdt_files(rundir)
Definition: test.py:101
def setup_cmd()
Definition: test.py:56
def setlimits()
Definition: test.py:94
def error(message, status)
Definition: test.py:51
def run_test(ntimes)
Definition: test.py:111