rvm 1.08

test-rvm-002.cc

Go to the documentation of this file.
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 // #define ERR_OUT(e)
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                 std::cerr << std::endl;
00180                 std::cerr << "  You should see an error message here:" << std::endl;
00181                 std::cerr << "-----------------------------------------" << std::endl;
00182                 try {
00183                         timer t;
00184 
00185                         t.start();
00186 
00187                         config.init(argc, argv);
00188                         logger.init();
00189                         vaulter.init();
00190                         reporter.init();
00191                         archiver.init();
00192                         archiver.archive();
00193                         cataloger.init();
00194                         cataloger.catalog();
00195 
00196                         t.stop();
00197                         reporter.set_total_time(t);
00198 
00199                         // reporter.print_report();
00200                         reporter.file_report();
00201                         logger.clear();
00202 
00203                         // std::cerr << "vaulter.vault() == " << vaulter.vault() << std::endl;
00204                         assert(vaulter.vault() == "./test-rvm.dir/vault-1");
00205 
00206                         dir = vaulter.vault();
00207                         dir += "/";
00208                         dir += config.timestamp().str();
00209                         dir += "/";
00210                         dir += config.jobs()[0].generate_archive_path(check_cwd);
00211                         adir[adirc++] = dir;
00212 
00213                         // std::cout << "dir = " << dir << std::endl;
00214 
00215                         assert(
00216                                 exists(
00217                                         config.log_dir()
00218                                         + static_cast<std::string>("/")
00219                                         + config.timestamp().str()
00220                                         + static_cast<std::string>(".log")
00221                                         )
00222                                 );
00223                         assert(
00224                                 exists(
00225                                         config.log_dir()
00226                                         + static_cast<std::string>("/")
00227                                         + config.timestamp().str()
00228                                         + static_cast<std::string>(".report")
00229                                         )
00230                                 );
00231 
00232                         subdir.path(dir);
00233                 }
00234                 catch(error e) {
00235                         ERR_OUT(e);
00236                         thrown = true;
00237                 }
00238                 catch(...) {
00239                         ERR_OUT(err_unknown);
00240                         assert(0);
00241                 }
00242                 std::cerr << "-----------------------------------------" << std::endl;
00243                 std::cerr << std::endl;
00244                 assert(thrown);
00245                 assert(find(subdir.begin(), subdir.end(), "AUTHORS") == subdir.end());
00246         }
00247 
00248 }
00249 
00250 int main(int argc, char const * argv[])
00251 {
00252         if (geteuid() != 0) {
00253                 cleanup();
00254                 setup();
00255                 try {
00256                         test_rvm();
00257                 }
00258                 catch(error e) {
00259                         std::cerr << e;
00260                         assert(0);
00261                 }
00262                 catch(...) {
00263                         std::cerr << err_unknown;
00264                         assert(0);
00265                 }
00266                 cleanup();
00267         }
00268         else {
00269                 std::cerr 
00270                         << "NOTE: Skipping this test because I'm running as root" 
00271                         << std::endl;
00272         }
00273         return(0);
00274 }
00275 
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines