rvm  1.11
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
test-rvm-002.cc
Go to the documentation of this file.
1 #include "config.h"
2 
3 #ifdef HAVE_SYS_TYPES_H
4 #include <sys/types.h>
5 #endif
6 #ifdef HAVE_UNISTD_H
7 #include <unistd.h>
8 #endif
9 
10 #include <iostream>
11 #include <string>
12 #include <fstream>
13 #include <iomanip>
14 #include <string>
15 #include <cassert>
16 #include <algorithm>
17 
18 #include "asserts.h"
19 #include "error.h"
20 #include "fs.h"
21 #include "rconfig.h"
22 #include "logger.h"
23 #include "vaulter.h"
24 #include "archiver.h"
25 #include "cataloger.h"
26 #include "reporter.h"
27 #include "test-fs-cwd.h"
28 
29 #define ERR_OUT(e) std::cerr << e
30 // #define ERR_OUT(e)
31 
32 bool make_dir(const std::string& path)
33 {
34  bool thrown;
35  bool value;
36 
37  thrown = false;
38  try {
39  mk_dir(path);
40  }
41  catch(...) {
42  thrown = true;
43  }
44 
45  value = (thrown == false);
46 
47  return(value);
48 }
49 
50 void setup(void)
51 {
52  std::ofstream out;
53 
54  assert(make_dir("./test-rvm.dir"));
55  assert(make_dir("./test-rvm.dir/vault-1"));
56  assert(make_dir("./test-rvm.dir/vault-1/2006-06-16.112632"));
57  assert(make_dir("./test-rvm.dir/vault-1/2006-06-16.112632/test-job"));
58  assert(make_dir("./test-rvm.dir/log.dir"));
59  assert(make_dir("./test-rvm.dir/catalog.dir"));
60  assert(chmod("./test-rvm.dir/vault-1/2006-06-16.112632",00500) == 0);
61  assert(chmod("./test-rvm.dir/vault-1/2006-06-16.112632/test-job",00500) == 0);
62 
63  out.open("./test-rvm.dir/file-1.conf");
64  assert(out.is_open());
65  out << "link-catalog-dir ./test-rvm.dir/catalog.dir" << std::endl;
66  out << "log-dir ./test-rvm.dir/log.dir" << std::endl;
67  out << "logging-level rsync" << std::endl;
68  out << "error-logging-level rsync" << std::endl;
69  out << "rsync-local-path " << LOCAL_RSYNC << std::endl;
70  out << "rsync-parallel 1" << std::endl;
71  out << "timestamp-resolution second" << std::endl;
72  out << "vault ./test-rvm.dir/vault-*" << std::endl;
73  out << "vault-overflow-behavior quit" << std::endl;
74  out << "vault-overflow-blocks 0" << std::endl;
75  out << "vault-overflow-inodes 0" << std::endl;
76  out << "vault-selection-behavior round-robin" << std::endl;
77  out << "<job>" << std::endl;
78  out << " jobname test-job" << std::endl;
79  out << " archive-path jobname/permutation" << std::endl;
80  out << " path " << check_cwd << "/" << std::endl;
81  out << " rsync-connection-type local" << std::endl;
82  out << " rsync-hardlink true" << std::endl;
83  out << " <rsync-options>" << std::endl;
84  out << " -a -v --progress --stats" << std::endl;
85  out << " --exclude '/.svn/'" << std::endl;
86  out << " --exclude '/.deps/'" << std::endl;
87  out << " --exclude '/autom4te.cache/'" << std::endl;
88  out << " --exclude '/test-rvm.dir/'" << std::endl;
89  out << " </rsync-options>" << std::endl;
90  out << " rsync-retry-count 3" << std::endl;
91  out << "</job>" << std::endl;
92  out.close();
93 }
94 
95 void cleanup(void)
96 {
97  int r;
98 
99  r = system("chmod -R u+w ./test-rvm.dir 2> /dev/null");
100  assert(system("rm -fr ./test-rvm.dir") == 0);
101 }
102 
104  const std::string& path1,
105  const std::string& path2,
106  const std::string& file
107  )
108 {
109  estring p1, p2;
110  filestatus f1, f2;
111  bool r;
112 
113  p1 = path1;
114  p1 += "/";
115  p1 += file;
116  p1 = reform_path(p1);
117  f1.path(p1);
118 
119  p2 = path2;
120  p2 += "/";
121  p2 += file;
122  p2 = reform_path(p2);
123  f2.path(p2);
124 
125  r = (f1.inode() == f2.inode());
126 
127  return(r);
128 }
129 
130 void test_rvm(void)
131 {
132  std::string local_rsync;
133  estring adir[4];
134  int adirc = 0;
135 
136  local_rsync = LOCAL_RSYNC;
137  if (local_rsync.size() == 0) {
138  char const * text[] = {
139  "",
140  "NOTICE: Skipping this test",
141  "",
142  "This test cannot be run because no local rsync binary was found during",
143  "configuration. This also means that RVM will be compiled with no",
144  "default value for the rsync-local-path command.",
145  "",
146  "To change this, run the configure script with --with-rsync=<path>,",
147  "where <path> is the absolute path to the rsync binary.",
148  "",
149  0
150  };
151  int c;
152 
153  for (c = 0; text[c] != 0; ++c) {
154  std::cerr << text[c] << std::endl;
155  }
156  return;
157  }
158 
159  {
160  char const * argv[256] = { 0 };
161  int argc = 0;
162  bool thrown = false;
163  subdirectory subdir;
164  estring dir;
165 
166  argv[argc++] = "<program>";
167  argv[argc++] = "--timestamp";
168  argv[argc++] = "2006-06-16.112632";
169  argv[argc++] = "--archive";
170 
171  cataloger.clear();
172  archiver.clear();
173  reporter.clear();
174  vaulter.clear();
175  logger.clear();
176  config.clear();
177 
178  config.default_file("./test-rvm.dir/file-1.conf");
179  std::cerr << std::endl;
180  std::cerr << " You should see an error message here:" << std::endl;
181  std::cerr << "-----------------------------------------" << std::endl;
182  try {
183  timer t;
184 
185  t.start();
186 
187  config.init(argc, argv);
188  logger.init();
189  vaulter.init();
190  reporter.init();
191  archiver.init();
192  archiver.archive();
193  cataloger.init();
194  cataloger.catalog();
195 
196  t.stop();
198 
199  // reporter.print_report();
201  logger.clear();
202 
203  // std::cerr << "vaulter.vault() == " << vaulter.vault() << std::endl;
204  assert(vaulter.vault() == "./test-rvm.dir/vault-1");
205 
206  dir = vaulter.vault();
207  dir += "/";
208  dir += config.timestamp().str();
209  dir += "/";
210  dir += config.jobs()[0].generate_archive_path(check_cwd);
211  adir[adirc++] = dir;
212 
213  // std::cout << "dir = " << dir << std::endl;
214 
215  assert(
216  exists(
217  config.log_dir()
218  + static_cast<std::string>("/")
219  + config.timestamp().str()
220  + static_cast<std::string>(".log")
221  )
222  );
223  assert(
224  exists(
225  config.log_dir()
226  + static_cast<std::string>("/")
227  + config.timestamp().str()
228  + static_cast<std::string>(".report")
229  )
230  );
231 
232  subdir.path(dir);
233  }
234  catch(error e) {
235  ERR_OUT(e);
236  thrown = true;
237  }
238  catch(...) {
240  assert(0);
241  }
242  std::cerr << "-----------------------------------------" << std::endl;
243  std::cerr << std::endl;
244  assert(thrown);
245  assert(find(subdir.begin(), subdir.end(), "AUTHORS") == subdir.end());
246  }
247 
248 }
249 
250 int main(int argc, char const * argv[])
251 {
252  if (geteuid() != 0) {
253  cleanup();
254  setup();
255  try {
256  test_rvm();
257  }
258  catch(error e) {
259  std::cerr << e;
260  assert(0);
261  }
262  catch(...) {
263  std::cerr << err_unknown;
264  assert(0);
265  }
266  cleanup();
267  }
268  else {
269  std::cerr
270  << "NOTE: Skipping this test because I'm running as root"
271  << std::endl;
272  }
273  return(0);
274 }
275 
void init(int argc, char const *argv[])
Initialize the configuration manager from rvm's command line options.
Definition: rconfig.cc:1218
std::string reform_path(const std::string &a_path)
Reformat a path to remove double slashes.
Definition: fs.cc:205
bool test_inodes(const std::string &path1, const std::string &path2, const std::string &file)
void mk_dir(const std::string &a_path)
Create a directory.
Definition: fs.cc:599
void clear(void)
Clear the vault manager.
Definition: vaulter.cc:30
log_manager logger
The global log manager.
Definition: logger.cc:138
void path(const std::string a_path)
Retrieve information about a pathname.
Definition: fs.cc:824
void init(void)
Initialize the vault manager.
Definition: vaulter.cc:40
An extended string class.
Definition: estring.h:52
void clear(void)
Clear the archive manager and clear the job list.
Definition: archiver.cc:1067
void catalog(void)
Create or update the catalog.
Definition: cataloger.cc:77
void clear(void)
Reset the catalog manager.
Definition: cataloger.cc:30
void default_file(const std::string &a_path)
Set the default configuration filename.
Definition: rconfig.cc:1484
const class timestamp & timestamp(void) const
Return the timestamp of this instance of rvm.
Definition: rconfig.cc:1505
const std::string & log_dir(void) const
Return the log-dir path.
Definition: rconfig.cc:1523
const inode_type inode(void) const
Return the file inode.
Definition: fs.cc:952
#define LOCAL_RSYNC
Definition: config.h:151
archive_manager archiver
The global archive manager.
Definition: archiver.cc:1536
#define err_unknown
Definition: error.h:114
void set_total_time(const timer &a_class)
Report the overall RVM time.
Definition: reporter.cc:960
void clear(void)
Reset configuration to default settings.
Definition: rconfig.cc:1171
void clear(void)
Clear all values.
Definition: reporter.cc:952
report_manager reporter
The global report manager.
Definition: reporter.cc:1124
bool exists(const std::string &a_path)
Return true if the file or directory exists.
Definition: fs.cc:385
void file_report(void)
Save report to a file.
Definition: reporter.cc:998
void start(void)
Start (or restart) the timer.
Definition: timer.cc:137
An error class.
Definition: error.h:72
catalog_manager cataloger
The global catalog manager.
Definition: cataloger.cc:135
const type & path(const std::string a_path, const std::string a_filter="*")
Return a vector of strings of a list of files in a subdirectory.
Definition: fs.cc:1361
const std::string vault(void) const
Return the path to the selected vault.
Definition: vaulter.cc:291
int main(int argc, char const *argv[])
void clear(void)
Clear the log manager.
Definition: logger.cc:32
void init(void)
Initialize the log manager.
Definition: logger.cc:42
configuration_manager config
The global configuration manager instance.
Definition: rconfig.cc:3364
Retrieve information about a file or directory.
Definition: fs.h:122
void init(void)
Initialize the catalog manager.
Definition: cataloger.cc:36
#define ERR_OUT(e)
Definition: test-rvm-002.cc:29
void init(void)
Initialize the archive manager.
Definition: archiver.cc:1078
void cleanup(void)
Definition: test-rvm-002.cc:95
const jobs_type & jobs(void) const
Return a list of jobs.
Definition: rconfig.cc:1667
const std::string str(void) const
Generate a string.
Definition: tstamp.cc:387
bool make_dir(const std::string &path)
Definition: test-rvm-002.cc:32
void archive(void)
Archive jobs.
Definition: archiver.cc:1235
const char * check_cwd
void stop(void)
Stop the timer.
Definition: timer.cc:143
Retrieve a list of files in a subdirectory that match a given wildcard filename.
Definition: fs.h:273
void test_rvm(void)
void init(void)
Initialize.
Definition: reporter.cc:937
void setup(void)
Definition: test-rvm-002.cc:50
Used as a stopwatch.
Definition: timer.h:29
vault_manager vaulter
The global vault manager.
Definition: vaulter.cc:772