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