diff --git a/.gitignore b/.gitignore index b2cbada466..78314d9213 100644 --- a/.gitignore +++ b/.gitignore @@ -153,6 +153,7 @@ sched/trickle_credit sched/trickle_deadline sched/trickle_echo sched/update_stats +sched/validator_test sched/wu_check tools/cancel_jobs tools/create_work diff --git a/sched/makefile_validator_test b/sched/makefile_validator_test index 796ede1272..da88ddfe44 100644 --- a/sched/makefile_validator_test +++ b/sched/makefile_validator_test @@ -5,7 +5,8 @@ VALIDATOR_SRC = sample_bitwise_validator.cpp # where libmysqlclient is -MYSQL_LIB_DIR = /usr/lib64/mysql +MYSQL_LIB := $(shell mysql_config --libs) +MYSQL_INC := $(shell mysql_config --include) -validator_test: validator_test.cpp $(VALIDATOR_SRC) - g++ -g -I.. -I../lib -I../db -o validator_test validator_test.cpp $(VALIDATOR_SRC) validate_util.o -L . -lsched -L ../lib -lboinc -L $(MYSQL_LIB_DIR) -lmysqlclient +validator_test: validator_test.cpp $(VALIDATOR_SRC) makefile_validator_test + g++ -g -I.. -I../lib -I../db $(MYSQL_INC) -o validator_test validator_test.cpp $(VALIDATOR_SRC) validate_util.o -L . -lsched -L ../lib -lboinc $(MYSQL_LIB) diff --git a/sched/sample_bitwise_validator.cpp b/sched/sample_bitwise_validator.cpp index b9c465102c..9afeaec991 100644 --- a/sched/sample_bitwise_validator.cpp +++ b/sched/sample_bitwise_validator.cpp @@ -38,7 +38,6 @@ using std::string; using std::vector; -bool first = true; bool is_gzip = false; // if true, files are gzipped; skip header when comparing @@ -47,6 +46,25 @@ struct FILE_CKSUM_LIST { ~FILE_CKSUM_LIST(){} }; +int validate_handler_init(int argc, char** argv) { + // handle project specific arguments here + for (int i=1; i init_script, compare_script; // first element is script path, other elements are args -void parse_cmdline() { - for (int i=1; i paths; int retval; retval = get_output_file_paths(result, paths); @@ -127,14 +138,6 @@ int compare_results(RESULT& r1, void*, RESULT const& r2, void*, bool& match) { unsigned int i, j; char buf[256]; - if (first) { - parse_cmdline(); - first = false; - } - if (!compare_script.size()) { - match = true; - return 0; - } vector paths1, paths2; int retval; retval = get_output_file_paths(r1, paths1); diff --git a/sched/validate_util.h b/sched/validate_util.h index 6a00cf39ff..74795bba15 100644 --- a/sched/validate_util.h +++ b/sched/validate_util.h @@ -53,5 +53,8 @@ extern bool standalone; // used by validator_test. extern void remove_random_from_filename(const char* in, char* out); +extern int validate_handler_init(int argc, char** argv); +extern void validate_handler_usage(); + #endif diff --git a/sched/validator.cpp b/sched/validator.cpp index 92c88a478c..69fe0bd0f3 100644 --- a/sched/validator.cpp +++ b/sched/validator.cpp @@ -772,6 +772,40 @@ int main_loop() { return 0; } +void usage(char* name) { + fprintf(stderr, + "This program is a 'validator'; it handles completed tasks.\n" + "Normally it is run as a daemon from config.xml.\n" + "See: https://boinc.berkeley.edu/trac/wiki/BackendPrograms\n\n" + ); + + fprintf(stderr, "usage: %s [options]\n" + " Options:\n" + " --app name Process tasks for the given application\n" + " [--one_pass_N_WU N] Validate at most N WUs, then exit\n" + " [--one_pass] Make one pass through WU table, then exit\n" + " [--dry_run] Don't update db, just write logs (for debugging)\n" + " [--mod n i] Process only WUs with (id mod n) == i\n" + " [--max_wu_id n] Process only WUs with id <= n\n" + " [--min_wu_id n] Process only WUs with id >= n\n" + " [--max_granted_credit X] Grant no more than this amount of credit to a result\n" + " [--grant_claimed_credit] Grant the claimed credit, regardless of what other results for this workunit claimed\n" + " [--update_credited_job] Add record to credited_job table after granting credit\n" + " [--credit_from_wu] Credit is specified in WU XML\n" + " [--credit_from_runtime X] Grant credit based on runtime (max X seconds)and estimated FLOPS\n" + " [--no_credit] Don't grant credit\n" + " [--sleep_interval n] Set sleep-interval to n\n" + " [--wu_id n] Process WU with given ID\n" + " [-d level|--debug_level n] Set log verbosity level\n" + " [-h|--help] Print this usage information and exit\n" + " [-v|--version] Print version information and exit\n" + "\n", + name + ); + validate_handler_usage(); + +} + // For use by project-supplied routines check_set() and check_pair() // int debug_level=0; @@ -779,30 +813,9 @@ int debug_level=0; int main(int argc, char** argv) { int i, retval; - const char *usage = - "\nUsage: %s --app [OPTIONS]\n" - "Start validator for application \n\n" - "Optional arguments:\n" - " --one_pass_N_WU N Validate at most N WUs, then exit\n" - " --one_pass Make one pass through WU table, then exit\n" - " --dry_run Don't update db, just write logs (for debugging)\n" - " --mod n i Process only WUs with (id mod n) == i\n" - " --max_wu_id n Process only WUs with id <= n\n" - " --min_wu_id n Process only WUs with id >= n\n" - " --max_granted_credit X Grant no more than this amount of credit to a result\n" - " --update_credited_job Add record to credited_job table after granting credit\n" - " --credit_from_wu Credit is specified in WU XML\n" - " --credit_from_runtime X Grant credit based on runtime (max X seconds)and estimated FLOPS\n" - " --no_credit Don't grant credit\n" - " --sleep_interval n Set sleep-interval to n\n" - " --wu_id n Process WU with given ID\n" - " -d n, --debug_level n Set log verbosity level, 1-4\n" - " -h | --help Show this\n" - " -v | --version Show version information\n"; - if (argc > 1) { if (is_arg(argv[1], "h") || is_arg(argv[1], "help")) { - printf (usage, argv[0] ); + usage(argv[0]); exit(0); } else if (is_arg(argv[1], "v") || is_arg(argv[1], "version")) { printf("%s\n", SVN_VERSION); @@ -812,6 +825,7 @@ int main(int argc, char** argv) { check_stop_daemons(); + int j=1; for (i=1; i +#include "svn_version.h" +#include "sched_util_basic.h" #include "validate_util.h" #include "validate_util2.h" -int g_argc; -char **g_argv; - void usage(char* prog) { fprintf(stderr, - "usage: %s file1 file2\n", prog + "This program is a test validator; \n" + "You can test your custom handler with this\n" ); - exit(1); + fprintf(stderr, "usage: %s [options] file1 file2\n" + " Options:\n" + " [-h|--help] Print this usage information and exit\n" + " [-v|--version] Print version information and exit\n" + " file1 Path to file to be compared (must be second to last)\n" + " file2 Path to file to be compared (must be last)\n" + "\n", + prog); + validate_handler_usage(); } int get_output_file_info(RESULT r, OUTPUT_FILE_INFO& fi) { @@ -47,18 +55,34 @@ int get_output_file_info(RESULT r, OUTPUT_FILE_INFO& fi) { } int main(int argc, char** argv) { - if (argc != 3) { + int retval; + + if (argc > 1) { + if (is_arg(argv[1], "h") || is_arg(argv[1], "help")) { usage(argv[0]); + exit(0); + } else if (is_arg(argv[1], "v") || is_arg(argv[1], "version")) { + printf("%s\n", SVN_VERSION); + exit(0); + } } + if (argc < 3) { + usage(argv[0]); + exit(0); + } + + retval = validate_handler_init(argc, argv); + if (retval) exit(1); + void* data1, *data2; RESULT r1, r2; bool match; standalone = true; - sprintf(r1.xml_doc_in, "%s", argv[1]); - sprintf(r2.xml_doc_in, "%s", argv[2]); - int retval; + sprintf(r1.xml_doc_in, "%s", argv[argc-2]); + sprintf(r2.xml_doc_in, "%s", argv[argc-1]); + retval = init_result(r1, data1); if (retval) { fprintf(stderr, "init_result(r1) returned %d\n", retval);