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