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