2005-01-20 23:22:22 +00:00
|
|
|
// Berkeley Open Infrastructure for Network Computing
|
|
|
|
// http://boinc.berkeley.edu
|
|
|
|
// Copyright (C) 2005 University of California
|
2003-06-14 20:04:45 +00:00
|
|
|
//
|
2005-01-20 23:22:22 +00:00
|
|
|
// This 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 2.1 of the License, or (at your option) any later version.
|
2003-06-14 20:04:45 +00:00
|
|
|
//
|
2005-01-20 23:22:22 +00:00
|
|
|
// This software is distributed in the hope that it will be useful,
|
|
|
|
// 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
|
|
|
//
|
2005-01-20 23:22:22 +00:00
|
|
|
// To view the GNU Lesser General Public License visit
|
|
|
|
// http://www.gnu.org/copyleft/lesser.html
|
|
|
|
// or write to the Free Software Foundation, Inc.,
|
2007-10-09 11:35:47 +00:00
|
|
|
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2002-09-26 18:11:06 +00:00
|
|
|
|
2004-07-13 12:23:47 +00:00
|
|
|
// A sample validator that grants credit if the majority of results are
|
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 {
|
|
|
|
string md5sum;
|
2004-07-13 14:18:47 +00:00
|
|
|
|
2008-05-29 20:11:43 +00:00
|
|
|
FILE_CKSUM(string& filedata) {
|
|
|
|
md5sum = md5_string(filedata);
|
2004-07-13 14:18:47 +00:00
|
|
|
}
|
2008-05-29 20:11:43 +00:00
|
|
|
~FILE_CKSUM(){}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct FILE_CKSUM_LIST {
|
|
|
|
vector<FILE_CKSUM> files;
|
|
|
|
~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++) {
|
|
|
|
if (f1.files[i].md5sum != f2.files[i].md5sum) return false;
|
|
|
|
}
|
|
|
|
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;
|
|
|
|
vector<FILE_INFO> files;
|
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,
|
2008-05-29 20:11:43 +00:00
|
|
|
"[RESULT#%d %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
|
|
|
|
2004-07-13 14:18:47 +00:00
|
|
|
string filedata;
|
2008-05-29 20:11:43 +00:00
|
|
|
for (unsigned int i=0; i<files.size(); i++) {
|
|
|
|
FILE_INFO& fi = files[i];
|
|
|
|
retval = read_file_string(fi.path.c_str(), filedata);
|
|
|
|
if (retval) {
|
|
|
|
if (fi.optional) {
|
|
|
|
filedata = "";
|
|
|
|
} else {
|
|
|
|
log_messages.printf(MSG_CRITICAL,
|
|
|
|
"[RESULT#%d %s] Couldn't open %s\n",
|
|
|
|
result.id, result.name, fi.path.c_str()
|
|
|
|
);
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
FILE_CKSUM fc(filedata);
|
|
|
|
fcl->files.push_back(fc);
|
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;
|
|
|
|
}
|
|
|
|
|
2007-01-30 18:19:30 +00:00
|
|
|
double compute_granted_credit(WORKUNIT& wu, vector<RESULT>& results) {
|
|
|
|
return median_mean_credit(wu, results);
|
2007-01-23 21:37:27 +00:00
|
|
|
}
|
|
|
|
|
2005-01-02 18:29:53 +00:00
|
|
|
const char *BOINC_RCSID_7ab2b7189c = "$Id$";
|