script_validator: make scripts optional.

You need to supply at least one (init or compare)
but you don't have to supply both.
This commit is contained in:
David Anderson 2020-08-01 16:00:10 -07:00
parent b68edc9589
commit 95819ed368
1 changed files with 16 additions and 14 deletions

View File

@ -1,6 +1,6 @@
// This file is part of BOINC. // This file is part of BOINC.
// http://boinc.berkeley.edu // http://boinc.berkeley.edu
// Copyright (C) 2014 University of California // Copyright (C) 2020 University of California
// //
// BOINC is free software; you can redistribute it and/or modify it // BOINC is free software; you can redistribute it and/or modify it
// under the terms of the GNU Lesser General Public License // under the terms of the GNU Lesser General Public License
@ -22,6 +22,8 @@
// --init_script "scriptname arg1 ... argn" // --init_script "scriptname arg1 ... argn"
// --compare_script "scriptname arg1 ... argn" // --compare_script "scriptname arg1 ... argn"
// //
// You must specify at least one.
//
// The init script checks the validity of a result, // The init script checks the validity of a result,
// e.g. that the output files have the proper format. // e.g. that the output files have the proper format.
// It returns zero if the files are valid // It returns zero if the files are valid
@ -76,9 +78,9 @@ int validate_handler_init(int argc, char** argv) {
} }
} }
if (!init_script.size() || !compare_script.size()) { if (init_script.empty() && compare_script.empty()) {
log_messages.printf(MSG_CRITICAL, log_messages.printf(MSG_CRITICAL,
"init_script and/or compare_script names are missing from command line\n" "command line must specify init_script or compare_script\n"
); );
return 1; return 1;
} }
@ -100,21 +102,21 @@ void validate_handler_usage() {
} }
int init_result(RESULT& result, void*&) { int init_result(RESULT& result, void*&) {
if (init_script.empty()) {
return 0;
}
unsigned int i, j; unsigned int i, j;
char buf[256]; char buf[256];
vector<string> paths; vector<string> paths;
int retval; int retval;
retval = get_output_file_paths(result, paths); retval = get_output_file_paths(result, paths);
if (retval) { if (retval) {
fprintf(stderr, "get_output_file_paths() returned %d\n", retval); fprintf(stderr, "get_output_file_paths() returned %d\n", retval);
return retval; return retval;
} }
if (init_script.size() == 0) {
fprintf(stderr, "init_result() failed: init_script parameter was not specified\n");
return 1;
}
char cmd[4096]; char cmd[4096];
sprintf(cmd, "../bin/%s", init_script[0].c_str()); sprintf(cmd, "../bin/%s", init_script[0].c_str());
@ -141,11 +143,16 @@ int init_result(RESULT& result, void*&) {
} }
int compare_results(RESULT& r1, void*, RESULT const& r2, void*, bool& match) { int compare_results(RESULT& r1, void*, RESULT const& r2, void*, bool& match) {
if (compare_script.empty()) {
match = true;
return 0;
}
unsigned int i, j; unsigned int i, j;
char buf[256]; char buf[256];
vector<string> paths1, paths2; vector<string> paths1, paths2;
int retval; int retval;
retval = get_output_file_paths(r1, paths1); retval = get_output_file_paths(r1, paths1);
if (retval) { if (retval) {
fprintf(stderr, "get_output_file_paths() returned %d\n", retval); fprintf(stderr, "get_output_file_paths() returned %d\n", retval);
@ -157,11 +164,6 @@ int compare_results(RESULT& r1, void*, RESULT const& r2, void*, bool& match) {
return retval; return retval;
} }
if (compare_script.size() == 0) {
fprintf(stderr, "compare_results() failed: compare_script parameter was not specified\n");
return 1;
}
char cmd[4096]; char cmd[4096];
sprintf(cmd, "../bin/%s", compare_script[0].c_str()); sprintf(cmd, "../bin/%s", compare_script[0].c_str());
for (i=1; i<compare_script.size(); i++) { for (i=1; i<compare_script.size(); i++) {