SheafSystem  0.0.0.0
create_test_data.cc
1 
2 //
3 // Copyright (c) 2014 Limit Point Systems, Inc.
4 //
5 // Licensed under the Apache License, Version 2.0 (the "License");
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17 
19 
20 #include "SheafSystem/lps_environment.h"
21 #include "SheafSystem/std_iostream.h"
22 #include "SheafSystem/std_string.h"
23 #include "SheafSystem/std_unistd.h"
24 #include <sys/wait.h>
25 
26 void exec_test_case(string xfile);
27 
28 void re_exec(int argc, char* argv[]);
29 
30 int main(int argc, char* argv[])
31 {
32  //re_exec(argc, argv);
33 
34  exec_test_case("./test_case_3d.t");
35  exec_test_case("./test_case_3d_irregular.t");
36  exec_test_case("./test_case_2d.t");
37 
38 }
39 
40 void exec_test_case(string xfile)
41 {
42  int status;
43 
44  // Get a child process.
45  int pid = fork();
46 
47  if(pid < 0)
48  {
49  // Fork failed.
50  perror(xfile.c_str());
51  exit(1);
52  }
53 
54  if(pid == 0)
55  {
56  // This is the child process
57 
58  cout << "Attempting to execute \"" << xfile << "\"" << endl;
59 
60  if(execlp(xfile.c_str(), (char*)0) == -1)
61  {
62  perror(xfile.c_str());
63  exit(1);
64  }
65  }
66  while(wait(&status) != pid)
67  ; // Dont't delete this ';'
68 }
69 
70 void re_exec(int argc, char* argv[])
71 {
72  static const char* env_name = "__HAVE_SET_ENV_SO_LD_LIBRARY_PATH_WORKS__";
73 
74  if(getenv(env_name) == NULL)
75  {
76  setenv(env_name, "yes", 1);
77  setenv("LD_LIBRARY_PATH", LD_LIBRARY_PATH, 1);
78  setenv("CLASSPATH", CLASSPATH, 1);
79 
80  if(execvp(argv[0], argv))
81  {
82  perror(argv[0]);
83  exit(1);
84  }
85  }
86 }