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 4"
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_tst03')
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  inputfn = os.path.join(datadir,"substruct","inputs","cube1.txt")
75  if not os.path.isfile(inputfn) :
76  error(inputfn+' is an invalid input file name.', 1)
77  # Put the arguments together
78  arguments = ' -if ' + inputfn
79  arguments = arguments + ' -porder 4'
80  for rdtarg in rdtfiles_l :
81  arguments = arguments + ' ' + rdtarg[1] + ' ' + rdtarg[2]
82  # TODO: Add arguments to enforce output checking!
83  return rundir, executable+arguments
84 
85 # Limits for this test
86 # TODO: change cpu limit acording to program execution time
87 limits = { "cpu" : (resource.RLIMIT_CPU, 1000, "Max CPU user time in seconds (not wall clock time)"),
88 # "nofile": (resource.RLIMIT_NOFILE, 7, "The maximum number of open file descriptors for the current process."),
89 # "rss" : (resource.RLIMIT_RSS, 1024, "The maximum resident set size that should be made available to the process"),
90 # "fsize" : (resource.RLIMIT_FSIZE, 1, "Max size of a file which the process may create"),
91 # "data" : (resource.RLIMIT_DATA, 1024, "The maximum size (in bytes) of the process's heap"),
92 # "nproc" : (resource.RLIMIT_NPROC, 0, "The maximum number of processes the current process may create")
93  }
94 
95 # Set the rlimits of the chidren process (see limits above)
96 # TODO: Improve the handling of sandboxing limits
97 def setlimits():
98  print "Setting resource limit in child"
99  for k, v in limits.iteritems() :
100  resource.setrlimit(v[0], (v[1],v[1]))
101  #print k, " : ", v[0], " => ", v[1]
102 
103 # Sumarizes the RDT (Raw data table) files information
104 def sumarize_rdt_files(rundir) :
105  results = {}
106  for f in rdtfiles_l :
107  rdt_id = f[0] # Step name
108  rdt_fn = os.path.join(rundir,f[2]) # RDT file name
109  rdt_dsc = f[3] # Description
110  results[rdt_id] = (rdt_fn, rdt_dsc)
111  return results
112 
113 # Execute the test.
114 def run_test(ntimes):
115  rundir,cmd=setup_cmd()
116  print short_description()
117  print "CMD:",cmd
118  args = shlex.split(cmd)
119  sout = None
120  serr = None
121  for i in range(ntimes) :
122  p = subprocess.Popen(args, preexec_fn=setlimits, stdout=sout, stderr=serr, cwd=rundir)
123  p.wait()
124  if (p.returncode != 0) :
125  return p.returncode, {}
126  results = sumarize_rdt_files(rundir)
127  return 0, results
def setlimits()
Definition: test.py:97
def run_test(ntimes)
Definition: test.py:114
def setup_cmd()
Definition: test.py:59
def error(message, status)
Definition: test.py:54
def short_description()
Definition: test.py:33
def sumarize_rdt_files(rundir)
Definition: test.py:104