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
|
2008-08-06 18:36:30 +00:00
|
|
|
// Copyright (C) 2008 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
|
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"
|
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;
|
|
|
|
|
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
|
|
|
};
|
|
|
|
|
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,
|
2013-06-19 17:15:08 +00:00
|
|
|
"[RESULT#%u %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
|
|
|
);
|
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;
|
2009-05-01 18:25:17 +00:00
|
|
|
retval = md5_file(fi.path.c_str(), md5_buf, nbytes);
|
2008-05-29 20:11:43 +00:00
|
|
|
if (retval) {
|
|
|
|
if (fi.optional) {
|
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,
|
2013-06-19 17:15:08 +00:00
|
|
|
"[RESULT#%u %s] Couldn't open %s\n",
|
2008-05-29 20:11:43 +00:00
|
|
|
result.id, result.name, fi.path.c_str()
|
|
|
|
);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2005-01-02 18:29:53 +00:00
|
|
|
const char *BOINC_RCSID_7ab2b7189c = "$Id$";
|