rambrain
performanceTestsWrapper.cpp
Go to the documentation of this file.
1 /* rambrain - a dynamical physical memory extender
2  * Copyright (C) 2015 M. Imgrund, A. Arth
3  * mimgrund (at) mpifr-bonn.mpg.de
4  * arth (at) usm.uni-muenchen.de
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 3 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, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #include <sys/types.h>
21 #include <sys/stat.h>
22 #include <unistd.h>
23 
24 #include "tester.h"
25 #include "performanceTestClasses.h"
26 
27 using namespace std;
28 
37 int main ( int argc, char **argv )
38 {
39  cout << "Wrapper for performance tests called" << endl;
40 
41  // Repetitions overwritten by first parameter (optional)
42  unsigned int repetitions = 10;
43  if ( argc > 1 ) {
44  if ( ! strcmp ( argv[1], "help" ) || ! strcmp ( argv[1], "list" ) ) {
46  return 0;
47  } else {
48  repetitions = atoi ( argv[1] );
49  }
50  }
51 
52  // Specialize which test cases to run
53  if ( argc > 2 ) {
54  int i = 2;
55  if ( ! strcmp ( argv[i], "true" ) ) {
57  cout << "Setting display plots to true" << endl;
58  ++ i;
59  } else if ( ! strcmp ( argv[i], "false" ) ) {
60  cout << "Setting display plots to false" << endl;
62  ++ i;
63  }
64 
65  bool enable;
66  if ( ! strcmp ( argv[i], "+" ) ) {
68  enable = true;
69  ++ i;
70  } else if ( ! strcmp ( argv[i], "-" ) ) {
71  // All tests are on by default
72  enable = false;
73  ++ i;
74  } else {
75  cerr << argv[i] << " not supported as " << i << " parameter, expected true/false or +/-" << endl;
76  return 1;
77  }
78 
79  for ( ; i < argc; ++i ) {
80  performanceTest<>::enableTest ( argv[i], enable );
81  }
82  }
83 
84  // Go to the proper directory
85  char exe[1024];
86  int ret;
87  ret = readlink ( "/proc/self/exe", exe, sizeof ( exe ) - 1 );
88  if ( ret != -1 ) {
89  exe[ret] = '\0';
90 
91  int n = 0;
92  string file ( exe );
93  for ( auto it = file.crbegin(); it != file.crend(); it++, n++ ) {
94  if ( ( *it ) == '/' ) {
95  break;
96  }
97  }
98  string path = file.substr ( 0, file.length() - n );
99  int success = chdir ( path.c_str() );
100  if ( ! success ) {
101  cout << "Changed working directory to " << path << endl;
102  } else {
103  cerr << "Could not chdir to " << path << ". Aborting." << endl;
104  return 2;
105  }
106  } else {
107  cerr << "Could not read executable path, aborting" << endl;
108  return 4;
109  }
110 
111  // Check if the performance test output directory exists
112  struct stat st = {0};
113  if ( stat ( "performancetests", &st ) == -1 ) {
114  int success = mkdir ( "performancetests", 0777 );
115  if ( ! success ) {
116  cout << "Created performancetests subdirectory for outputs" << endl;
117  } else {
118  cerr << "Could not create subdirectory performancetests, aborting." << endl;
119  return 3;
120  }
121  }
122 
123  // Change directory to subdir
124  int success = chdir ( "performancetests" );
125  if ( ! success ) {
126  cout << "Changed working directory to subdirectory performancetests" << endl;
127  } else {
128  cerr << "Could not chdir to subdirectory performancetests. Aborting." << endl;
129  return 2;
130  }
131 
132  cout << endl;
133 
134 
135  // Eventually make changes to test parameters of allocated test classes if desired
136 
137  // Run tests
139  performanceTest<>::runRegisteredTests ( repetitions, "../" );
140 
141  cout << endl << endl << "All tests done, exiting..." << endl;
142  return 0;
143 }
Derived performance test classes which take parameter types as template arguments.
STL namespace.
int main(int argc, char **argv)
Provides a wrapper binary to run performance tests and scan through respective parameter spaces...