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.,
|
|
|
|
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 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;
|
|
|
|
|
2006-06-09 02:33:00 +00:00
|
|
|
class FILE_CACHE {
|
2004-07-13 14:18:47 +00:00
|
|
|
mutable string _md5sum;
|
|
|
|
public:
|
|
|
|
const string filedata;
|
|
|
|
|
2006-06-09 02:33:00 +00:00
|
|
|
FILE_CACHE(string const& filedata0) : filedata(filedata0) {}
|
2004-07-13 14:18:47 +00:00
|
|
|
|
|
|
|
string const md5sum() const {
|
|
|
|
if (_md5sum.empty()) {
|
|
|
|
_md5sum = md5_string(filedata);
|
|
|
|
}
|
|
|
|
return _md5sum;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2006-06-09 02:33:00 +00:00
|
|
|
bool operator ==(FILE_CACHE const& f1, FILE_CACHE const& f2) {
|
|
|
|
return (f1.md5sum() == f2.md5sum() && f1.filedata == f2.filedata);
|
2004-07-13 14:18:47 +00:00
|
|
|
}
|
2002-09-25 19:40:19 +00:00
|
|
|
|
2003-08-14 00:02:15 +00:00
|
|
|
// read file into memory
|
2004-03-17 01:26:44 +00:00
|
|
|
//
|
2006-06-09 02:33:00 +00:00
|
|
|
int init_result_read_file(RESULT const & result, void*& data) {
|
2002-09-25 19:40:19 +00:00
|
|
|
int retval;
|
2003-08-14 00:02:15 +00:00
|
|
|
string path;
|
2002-09-25 19:40:19 +00:00
|
|
|
|
2003-08-14 00:02:15 +00:00
|
|
|
retval = get_output_file_path(result, path);
|
2002-09-25 19:40:19 +00:00
|
|
|
if (retval) {
|
2003-08-07 21:40:17 +00:00
|
|
|
log_messages.printf(
|
2005-09-26 23:28:48 +00:00
|
|
|
SCHED_MSG_LOG::MSG_CRITICAL,
|
2003-08-14 00:02:15 +00:00
|
|
|
"[RESULT#%d %s] check_set: can't get output filename\n",
|
|
|
|
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;
|
|
|
|
retval = read_file_string(path.c_str(), filedata);
|
2002-09-25 19:40:19 +00:00
|
|
|
if (retval) {
|
2003-08-07 21:40:17 +00:00
|
|
|
log_messages.printf(
|
2005-09-26 23:28:48 +00:00
|
|
|
SCHED_MSG_LOG::MSG_CRITICAL,
|
2003-08-14 00:02:15 +00:00
|
|
|
"[RESULT#%d %s] Couldn't open %s\n",
|
|
|
|
result.id, result.name, path.c_str()
|
2004-03-17 01:26:44 +00:00
|
|
|
);
|
2002-09-25 19:40:19 +00:00
|
|
|
return retval;
|
|
|
|
}
|
2006-06-09 02:33:00 +00:00
|
|
|
data = (void*) new FILE_CACHE(filedata);
|
2003-08-14 00:02:15 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-09-01 17:11:14 +00:00
|
|
|
int check_pair_initialized_identical(
|
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
|
|
|
|
) {
|
|
|
|
FILE_CACHE const* f1 = (FILE_CACHE*) data1;
|
|
|
|
FILE_CACHE const* f2 = (FILE_CACHE*) data2;
|
2003-08-14 00:02:15 +00:00
|
|
|
|
2004-07-13 14:18:47 +00:00
|
|
|
match = (*f1 == *f2);
|
2002-09-25 19:40:19 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2003-08-14 00:02:15 +00:00
|
|
|
|
2003-09-01 17:11:14 +00:00
|
|
|
int cleanup_result_string(RESULT const& /*result*/, void* data) {
|
2006-06-09 02:33:00 +00:00
|
|
|
delete (FILE_CACHE*) data;
|
2003-08-14 00:02:15 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// See if there's a strict majority under equality.
|
|
|
|
//
|
2004-09-09 22:25:10 +00:00
|
|
|
int check_set(
|
2005-09-01 17:28:29 +00:00
|
|
|
vector<RESULT>& results, WORKUNIT& wu, int& canonicalid, double& credit,
|
2004-09-09 22:25:10 +00:00
|
|
|
bool& retry
|
|
|
|
) {
|
|
|
|
retry = false;
|
2005-09-01 17:28:29 +00:00
|
|
|
return generic_check_set(
|
2003-09-01 17:11:14 +00:00
|
|
|
results, canonicalid, credit,
|
|
|
|
init_result_read_file,
|
|
|
|
check_pair_initialized_identical,
|
2005-09-01 17:28:29 +00:00
|
|
|
cleanup_result_string,
|
|
|
|
wu.min_quorum/2+1
|
2003-09-01 17:11:14 +00:00
|
|
|
);
|
2003-08-14 00:02:15 +00:00
|
|
|
}
|
|
|
|
|
2006-06-09 02:33:00 +00:00
|
|
|
int check_pair(RESULT & r1, RESULT const& r2, bool& retry) {
|
2004-09-09 22:25:10 +00:00
|
|
|
retry = false;
|
|
|
|
int retval = generic_check_pair(
|
|
|
|
r1, r2,
|
2003-09-01 17:11:14 +00:00
|
|
|
init_result_read_file,
|
|
|
|
check_pair_initialized_identical,
|
|
|
|
cleanup_result_string
|
|
|
|
);
|
2004-09-09 22:25:10 +00:00
|
|
|
return retval;
|
2003-08-14 00:02:15 +00:00
|
|
|
}
|
|
|
|
|
2005-01-02 18:29:53 +00:00
|
|
|
const char *BOINC_RCSID_7ab2b7189c = "$Id$";
|