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 system("chmod -R u+w ./test-rvm.dir 2> /dev/null");
00098 assert(system("rm -fr ./test-rvm.dir") == 0);
00099 }
00100
00101 bool test_inodes(
00102 const std::string& path1,
00103 const std::string& path2,
00104 const std::string& file
00105 )
00106 {
00107 estring p1, p2;
00108 filestatus f1, f2;
00109 bool r;
00110
00111 p1 = path1;
00112 p1 += "/";
00113 p1 += file;
00114 p1 = reform_path(p1);
00115 f1.path(p1);
00116
00117 p2 = path2;
00118 p2 += "/";
00119 p2 += file;
00120 p2 = reform_path(p2);
00121 f2.path(p2);
00122
00123 r = (f1.inode() == f2.inode());
00124
00125 return(r);
00126 }
00127
00128 void test_rvm(void)
00129 {
00130 std::string local_rsync;
00131 estring adir[4];
00132 int adirc = 0;
00133
00134 local_rsync = LOCAL_RSYNC;
00135 if (local_rsync.size() == 0) {
00136 char *text[] = {
00137 "",
00138 "NOTICE: Skipping this test",
00139 "",
00140 "This test cannot be run because no local rsync binary was found during",
00141 "configuration. This also means that RVM will be compiled with no",
00142 "default value for the rsync-local-path command.",
00143 "",
00144 "To change this, run the configure script with --with-rsync=<path>,",
00145 "where <path> is the absolute path to the rsync binary.",
00146 "",
00147 0
00148 };
00149 int c;
00150
00151 for (c = 0; text[c] != 0; ++c) {
00152 std::cerr << text[c] << std::endl;
00153 }
00154 return;
00155 }
00156
00157 {
00158 char *argv[256] = { 0 };
00159 int argc = 0;
00160 bool thrown = false;
00161 subdirectory subdir;
00162 estring dir;
00163
00164 argv[argc++] = "<program>";
00165 argv[argc++] = "--timestamp";
00166 argv[argc++] = "2006-06-16.112632";
00167 argv[argc++] = "--archive";
00168
00169 cataloger.clear();
00170 archiver.clear();
00171 reporter.clear();
00172 vaulter.clear();
00173 logger.clear();
00174 config.clear();
00175
00176 config.default_file("./test-rvm.dir/file-1.conf");
00177 try {
00178 timer t;
00179
00180 t.start();
00181
00182 config.init(argc, argv);
00183 logger.init();
00184 vaulter.init();
00185 reporter.init();
00186 archiver.init();
00187 archiver.archive();
00188 cataloger.init();
00189 cataloger.catalog();
00190
00191 t.stop();
00192 reporter.set_total_time(t);
00193
00194
00195 reporter.file_report();
00196 logger.clear();
00197
00198
00199 assert(vaulter.vault() == "./test-rvm.dir/vault-1");
00200
00201 dir = vaulter.vault();
00202 dir += "/";
00203 dir += config.timestamp().str();
00204 dir += "/";
00205 dir += config.jobs()[0].generate_archive_path(check_cwd);
00206 adir[adirc++] = dir;
00207
00208
00209
00210 assert(
00211 exists(
00212 config.log_dir()
00213 + static_cast<std::string>("/")
00214 + config.timestamp().str()
00215 + static_cast<std::string>(".log")
00216 )
00217 );
00218 assert(
00219 exists(
00220 config.log_dir()
00221 + static_cast<std::string>("/")
00222 + config.timestamp().str()
00223 + static_cast<std::string>(".report")
00224 )
00225 );
00226
00227 subdir.path(dir);
00228 }
00229 catch(error e) {
00230 ERR_OUT(e);
00231 thrown = true;
00232 }
00233 catch(...) {
00234 ERR_OUT(err_unknown);
00235 assert(0);
00236 }
00237 assert(!thrown);
00238 assert(find(subdir.begin(), subdir.end(), "AUTHORS") == subdir.end());
00239 }
00240
00241 }
00242
00243 int main(int argc, char *argv[])
00244 {
00245 if (geteuid() != 0) {
00246 cleanup();
00247 setup();
00248 try {
00249 test_rvm();
00250 }
00251 catch(error e) {
00252 std::cerr << e;
00253 assert(0);
00254 }
00255 catch(...) {
00256 std::cerr << err_unknown;
00257 assert(0);
00258 }
00259 cleanup();
00260 }
00261 else {
00262 std::cerr
00263 << "NOTE: Skipping this test because I'm running as root"
00264 << std::endl;
00265 }
00266 return(0);
00267 }
00268