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;
|
|
|
|
|
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) {}
|
2006-06-09 23:17:05 +00:00
|
|
|
~FILE_CACHE(){}
|
2004-07-13 14:18:47 +00:00
|
|
|
|
|
|
|
string const md5sum() const {
|
|
|
|
if (_md5sum.empty()) {
|
|
|
|
_md5sum = md5_string(filedata);
|
|
|
|
}
|
|
|
|
return _md5sum;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2006-06-09 23:17:05 +00:00
|
|
|
bool files_match(FILE_CACHE const& f1, FILE_CACHE const& f2) {
|
2006-06-09 02:33:00 +00:00
|
|
|
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 23:17:05 +00:00
|
|
|
int init_result(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;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
) {
|
|
|
|
FILE_CACHE const* f1 = (FILE_CACHE*) data1;
|
|
|
|
FILE_CACHE const* f2 = (FILE_CACHE*) 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) {
|
2006-06-09 02:33:00 +00:00
|
|
|
delete (FILE_CACHE*) 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$";
|