00001 #include "config.h"
00002
00003 #ifdef HAVE_SYS_TYPES_H
00004 #include <sys/types.h>
00005 #endif
00006 #ifdef HAVE_UNISTD_H
00007 #include <unistd.h>
00008 #endif
00009
00010 #include <iostream>
00011 #include <string>
00012 #include <fstream>
00013 #include <iomanip>
00014 #include <string>
00015 #include <cassert>
00016 #include <algorithm>
00017
00018 #include "asserts.h"
00019 #include "error.h"
00020 #include "fs.h"
00021 #include "rconfig.h"
00022 #include "logger.h"
00023 #include "vaulter.h"
00024 #include "archiver.h"
00025 #include "cataloger.h"
00026 #include "reporter.h"
00027 #include "test-fs-cwd.h"
00028
00029 #define ERR_OUT(e) std::cerr << e
00030
00031
00032 bool make_dir(const std::string& path)
00033 {
00034 bool thrown;
00035 bool value;
00036
00037 thrown = false;
00038 try {
00039 mk_dir(path);
00040 }
00041 catch(...) {
00042 thrown = true;
00043 }
00044
00045 value = (thrown == false);
00046
00047 return(value);
00048 }
00049
00050 void setup(void)
00051 {
00052 std::ofstream out;
00053
00054 assert(make_dir("./test-rvm.dir"));
00055 assert(make_dir("./test-rvm.dir/vault-1"));
00056 assert(make_dir("./test-rvm.dir/vault-1/2006-06-16.112632"));
00057 assert(make_dir("./test-rvm.dir/vault-1/2006-06-16.112632/test-job"));
00058 assert(make_dir("./test-rvm.dir/log.dir"));
00059 assert(make_dir("./test-rvm.dir/catalog.dir"));
00060 assert(chmod("./test-rvm.dir/vault-1/2006-06-16.112632",00500) == 0);
00061 assert(chmod("./test-rvm.dir/vault-1/2006-06-16.112632/test-job",00500) == 0);
00062
00063 out.open("./test-rvm.dir/file-1.conf");
00064 assert(out.is_open());
00065 out << "link-catalog-dir ./test-rvm.dir/catalog.dir" << std::endl;
00066 out << "log-dir ./test-rvm.dir/log.dir" << std::endl;
00067 out << "logging-level rsync" << std::endl;
00068 out << "error-logging-level rsync" << std::endl;
00069 out << "rsync-local-path " << LOCAL_RSYNC << std::endl;
00070 out << "rsync-parallel 1" << std::endl;
00071 out << "timestamp-resolution second" << std::endl;
00072 out << "vault ./test-rvm.dir/vault-*" << std::endl;
00073 out << "vault-overflow-behavior quit" << std::endl;
00074 out << "vault-overflow-blocks 0" << std::endl;
00075 out << "vault-overflow-inodes 0" << std::endl;
00076 out << "vault-selection-behavior round-robin" << std::endl;
00077 out << "<job>" << std::endl;
00078 out << " jobname test-job" << std::endl;
00079 out << " archive-path jobname/permutation" << std::endl;
00080 out << " path " << check_cwd << "/" << std::endl;
00081 out << " rsync-connection-type local" << std::endl;
00082 out << " rsync-hardlink true" << std::endl;
00083 out << " <rsync-options>" << std::endl;
00084 out << " -a -v --progress --stats" << std::endl;
00085 out << " --exclude '/.svn/'" << std::endl;
00086 out << " --exclude '/.deps/'" << std::endl;
00087 out << " --exclude '/autom4te.cache/'" << std::endl;
00088 out << " --exclude '/test-rvm.dir/'" << std::endl;
00089 out << " </rsync-options>" << std::endl;
00090 out << " rsync-retry-count 3" << std::endl;
00091 out << "</job>" << std::endl;
00092 out.close();
00093 }
00094
00095 void cleanup(void)
00096 {
00097 int r;
00098
00099 r = system("chmod -R u+w ./test-rvm.dir 2> /dev/null");
00100 assert(system("rm -fr ./test-rvm.dir") == 0);
00101 }
00102
00103 bool test_inodes(
00104 const std::string& path1,
00105 const std::string& path2,
00106 const std::string& file
00107 )
00108 {
00109 estring p1, p2;
00110 filestatus f1, f2;
00111 bool r;
00112
00113 p1 = path1;
00114 p1 += "/";
00115 p1 += file;
00116 p1 = reform_path(p1);
00117 f1.path(p1);
00118
00119 p2 = path2;
00120 p2 += "/";
00121 p2 += file;
00122 p2 = reform_path(p2);
00123 f2.path(p2);
00124
00125 r = (f1.inode() == f2.inode());
00126
00127 return(r);
00128 }
00129
00130 void test_rvm(void)
00131 {
00132 std::string local_rsync;
00133 estring adir[4];
00134 int adirc = 0;
00135
00136 local_rsync = LOCAL_RSYNC;
00137 if (local_rsync.size() == 0) {
00138 char const * text[] = {
00139 "",
00140 "NOTICE: Skipping this test",
00141 "",
00142 "This test cannot be run because no local rsync binary was found during",
00143 "configuration. This also means that RVM will be compiled with no",
00144 "default value for the rsync-local-path command.",
00145 "",
00146 "To change this, run the configure script with --with-rsync=<path>,",
00147 "where <path> is the absolute path to the rsync binary.",
00148 "",
00149 0
00150 };
00151 int c;
00152
00153 for (c = 0; text[c] != 0; ++c) {
00154 std::cerr << text[c] << std::endl;
00155 }
00156 return;
00157 }
00158
00159 {
00160 char const * argv[256] = { 0 };
00161 int argc = 0;
00162 bool thrown = false;
00163 subdirectory subdir;
00164 estring dir;
00165
00166 argv[argc++] = "<program>";
00167 argv[argc++] = "--timestamp";
00168 argv[argc++] = "2006-06-16.112632";
00169 argv[argc++] = "--archive";
00170
00171 cataloger.clear();
00172 archiver.clear();
00173 reporter.clear();
00174 vaulter.clear();
00175 logger.clear();
00176 config.clear();
00177
00178 config.default_file("./test-rvm.dir/file-1.conf");
00179 try {
00180 timer t;
00181
00182 t.start();
00183
00184 config.init(argc, argv);
00185 logger.init();
00186 vaulter.init();
00187 reporter.init();
00188 archiver.init();
00189 archiver.archive();
00190 cataloger.init();
00191 cataloger.catalog();
00192
00193 t.stop();
00194 reporter.set_total_time(t);
00195
00196
00197 reporter.file_report();
00198 logger.clear();
00199
00200
00201 assert(vaulter.vault() == "./test-rvm.dir/vault-1");
00202
00203 dir = vaulter.vault();
00204 dir += "/";
00205 dir += config.timestamp().str();
00206 dir += "/";
00207 dir += config.jobs()[0].generate_archive_path(check_cwd);
00208 adir[adirc++] = dir;
00209
00210
00211
00212 assert(
00213 exists(
00214 config.log_dir()
00215 + static_cast<std::string>("/")
00216 + config.timestamp().str()
00217 + static_cast<std::string>(".log")
00218 )
00219 );
00220 assert(
00221 exists(
00222 config.log_dir()
00223 + static_cast<std::string>("/")
00224 + config.timestamp().str()
00225 + static_cast<std::string>(".report")
00226 )
00227 );
00228
00229 subdir.path(dir);
00230 }
00231 catch(error e) {
00232 ERR_OUT(e);
00233 thrown = true;
00234 }
00235 catch(...) {
00236 ERR_OUT(err_unknown);
00237 assert(0);
00238 }
00239 assert(!thrown);
00240 assert(find(subdir.begin(), subdir.end(), "AUTHORS") == subdir.end());
00241 }
00242
00243 }
00244
00245 int main(int argc, char const * argv[])
00246 {
00247 if (geteuid() != 0) {
00248 cleanup();
00249 setup();
00250 try {
00251 test_rvm();
00252 }
00253 catch(error e) {
00254 std::cerr << e;
00255 assert(0);
00256 }
00257 catch(...) {
00258 std::cerr << err_unknown;
00259 assert(0);
00260 }
00261 cleanup();
00262 }
00263 else {
00264 std::cerr
00265 << "NOTE: Skipping this test because I'm running as root"
00266 << std::endl;
00267 }
00268 return(0);
00269 }
00270