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