2008-08-06 18:36:30 +00:00
|
|
|
// This file is part of BOINC.
|
2005-01-20 23:22:22 +00:00
|
|
|
// http://boinc.berkeley.edu
|
2019-01-12 21:43:48 +00:00
|
|
|
// Copyright (C) 2019 University of California
|
2003-06-14 20:04:45 +00:00
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// BOINC is free software; you can redistribute it and/or modify it
|
|
|
|
// under the terms of the GNU Lesser General Public License
|
|
|
|
// as published by the Free Software Foundation,
|
|
|
|
// either version 3 of the License, or (at your option) any later version.
|
2003-06-14 20:04:45 +00:00
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// BOINC is distributed in the hope that it will be useful,
|
2005-01-20 23:22:22 +00:00
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
// See the GNU Lesser General Public License for more details.
|
2002-09-26 18:11:06 +00:00
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
|
2002-09-26 18:11:06 +00:00
|
|
|
|
2009-05-01 18:25:17 +00:00
|
|
|
// A sample validator that requires a majority of results to be
|
2006-06-09 02:33:00 +00:00
|
|
|
// bitwise identical.
|
|
|
|
// This is useful only if either
|
|
|
|
// 1) your application does no floating-point math, or
|
|
|
|
// 2) you use homogeneous redundancy
|
2014-03-20 19:38:29 +00:00
|
|
|
//
|
|
|
|
// if the --is_gzip option is used, all files are assumed to be gzipped.
|
|
|
|
// In this case, the 10-byte gzip header is skipped
|
|
|
|
// (it has stuff like a timestamp and OS code that can differ
|
|
|
|
// even if the archive contents are the same)
|
2004-07-13 12:23:47 +00:00
|
|
|
|
2005-11-21 18:34:44 +00:00
|
|
|
#include "config.h"
|
2004-04-07 06:51:42 +00:00
|
|
|
#include "util.h"
|
2003-06-14 20:03:08 +00:00
|
|
|
#include "sched_util.h"
|
2004-04-08 08:15:23 +00:00
|
|
|
#include "sched_msgs.h"
|
2004-03-17 01:26:44 +00:00
|
|
|
#include "validate_util.h"
|
2014-03-20 19:38:29 +00:00
|
|
|
#include "validate_util2.h"
|
|
|
|
#include "validator.h"
|
2004-07-13 14:18:47 +00:00
|
|
|
#include "md5_file.h"
|
2002-09-25 19:40:19 +00:00
|
|
|
|
2004-06-30 18:17:21 +00:00
|
|
|
using std::string;
|
|
|
|
using std::vector;
|
|
|
|
|
2014-03-20 19:38:29 +00:00
|
|
|
bool is_gzip = false;
|
|
|
|
// if true, files are gzipped; skip header when comparing
|
|
|
|
|
2008-05-29 20:11:43 +00:00
|
|
|
struct FILE_CKSUM_LIST {
|
2009-05-01 18:25:17 +00:00
|
|
|
vector<string> files; // list of MD5s of files
|
2008-05-29 20:11:43 +00:00
|
|
|
~FILE_CKSUM_LIST(){}
|
2004-07-13 14:18:47 +00:00
|
|
|
};
|
|
|
|
|
2016-08-16 09:06:14 +00:00
|
|
|
int validate_handler_init(int argc, char** argv) {
|
|
|
|
// handle project specific arguments here
|
|
|
|
for (int i=1; i<argc; i++) {
|
|
|
|
if (is_arg(argv[i], "is_gzip")) {
|
|
|
|
is_gzip = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void validate_handler_usage() {
|
|
|
|
// describe the project specific arguments here
|
|
|
|
fprintf(stderr,
|
|
|
|
" Custom options:\n"
|
|
|
|
" [--is_gzip] files are gzipped; skip header when comparing\n"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-05-29 20:11:43 +00:00
|
|
|
bool files_match(FILE_CKSUM_LIST& f1, FILE_CKSUM_LIST& f2) {
|
|
|
|
if (f1.files.size() != f2.files.size()) return false;
|
|
|
|
for (unsigned int i=0; i<f1.files.size(); i++) {
|
2009-05-01 18:25:17 +00:00
|
|
|
if (f1.files[i] != f2.files[i]) return false;
|
2008-05-29 20:11:43 +00:00
|
|
|
}
|
|
|
|
return true;
|
2004-07-13 14:18:47 +00:00
|
|
|
}
|
2002-09-25 19:40:19 +00:00
|
|
|
|
2008-03-13 23:35:13 +00:00
|
|
|
int init_result(RESULT& result, void*& data) {
|
2002-09-25 19:40:19 +00:00
|
|
|
int retval;
|
2008-05-29 20:11:43 +00:00
|
|
|
FILE_CKSUM_LIST* fcl = new FILE_CKSUM_LIST;
|
2012-04-19 08:47:38 +00:00
|
|
|
vector<OUTPUT_FILE_INFO> files;
|
2009-05-01 18:25:17 +00:00
|
|
|
char md5_buf[MD5_LEN];
|
|
|
|
double nbytes;
|
2002-09-25 19:40:19 +00:00
|
|
|
|
2008-05-29 21:54:18 +00:00
|
|
|
retval = get_output_file_infos(result, files);
|
2002-09-25 19:40:19 +00:00
|
|
|
if (retval) {
|
2008-02-21 21:00:58 +00:00
|
|
|
log_messages.printf(MSG_CRITICAL,
|
2015-07-23 17:11:08 +00:00
|
|
|
"[RESULT#%lu %s] check_set: can't get output filenames\n",
|
2003-08-14 00:02:15 +00:00
|
|
|
result.id, result.name
|
2004-03-17 01:26:44 +00:00
|
|
|
);
|
2015-10-28 16:23:32 +00:00
|
|
|
delete fcl;
|
2002-09-25 19:40:19 +00:00
|
|
|
return retval;
|
|
|
|
}
|
2003-08-14 00:02:15 +00:00
|
|
|
|
2008-05-29 20:11:43 +00:00
|
|
|
for (unsigned int i=0; i<files.size(); i++) {
|
2012-04-19 08:47:38 +00:00
|
|
|
OUTPUT_FILE_INFO& fi = files[i];
|
2008-06-30 16:46:05 +00:00
|
|
|
if (fi.no_validate) continue;
|
2014-03-20 19:38:29 +00:00
|
|
|
retval = md5_file(fi.path.c_str(), md5_buf, nbytes, is_gzip);
|
2008-05-29 20:11:43 +00:00
|
|
|
if (retval) {
|
2014-03-20 19:38:29 +00:00
|
|
|
if (fi.optional && retval == ERR_FOPEN) {
|
2009-05-01 18:25:17 +00:00
|
|
|
strcpy(md5_buf, "");
|
|
|
|
// indicate file is missing; not the same as md5("")
|
2008-05-29 20:11:43 +00:00
|
|
|
} else {
|
|
|
|
log_messages.printf(MSG_CRITICAL,
|
2015-07-23 17:11:08 +00:00
|
|
|
"[RESULT#%lu %s] md5_file() failed for %s: %s\n",
|
2014-03-20 19:38:29 +00:00
|
|
|
result.id, result.name, fi.path.c_str(), boincerror(retval)
|
2008-05-29 20:11:43 +00:00
|
|
|
);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
}
|
2009-05-01 18:25:17 +00:00
|
|
|
fcl->files.push_back(string(md5_buf));
|
2002-09-25 19:40:19 +00:00
|
|
|
}
|
2008-05-29 20:11:43 +00:00
|
|
|
data = (void*) fcl;
|
2003-08-14 00:02:15 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2006-06-09 23:17:05 +00:00
|
|
|
int compare_results(
|
2004-09-09 22:25:10 +00:00
|
|
|
RESULT & /*r1*/, void* data1,
|
2003-09-01 17:11:14 +00:00
|
|
|
RESULT const& /*r2*/, void* data2,
|
2006-06-09 02:33:00 +00:00
|
|
|
bool& match
|
|
|
|
) {
|
2008-05-29 20:11:43 +00:00
|
|
|
FILE_CKSUM_LIST* f1 = (FILE_CKSUM_LIST*) data1;
|
|
|
|
FILE_CKSUM_LIST* f2 = (FILE_CKSUM_LIST*) data2;
|
2003-08-14 00:02:15 +00:00
|
|
|
|
2006-06-09 23:17:05 +00:00
|
|
|
match = files_match(*f1, *f2);
|
2002-09-25 19:40:19 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2003-08-14 00:02:15 +00:00
|
|
|
|
2006-06-09 23:17:05 +00:00
|
|
|
int cleanup_result(RESULT const& /*result*/, void* data) {
|
2008-05-29 21:54:18 +00:00
|
|
|
delete (FILE_CKSUM_LIST*) data;
|
2003-08-14 00:02:15 +00:00
|
|
|
return 0;
|
|
|
|
}
|