3
require_once("docutil.php");
4
page_head("Simple validator framework [deprecated: SimpleValidation]");
6
To create a validator using the simple framework,
7
you must supply four functions:
8
"; block_start(); echo "
9
extern int init_result(RESULT& result, void*& data);
10
"; block_end(); echo "
11
This takes a result, reads its output file(s),
12
parses them into a memory structure,
13
and returns (via the 'data' argument) a pointer to this structure.
17
<li> ERR_OPENDIR if there was a transient error,
18
e.g. the output file is on a network volume that is not available.
19
The validator will try this result again later.
20
<li> Any other return value indicates a permanent error.
21
Example: an output file is missing, or has a syntax error.
22
The result will be marked as invalid.
24
"; block_start(); echo "
25
extern int compare_results(
26
RESULT& r1, void* data1, RESULT& r2, void* data2, bool& match
28
"; block_end(); echo "
29
This takes two results and their associated memory structures.
30
It returns (via the 'match' argument) true if the two results
31
are equivalent (within the tolerances of the application).
32
"; block_start(); echo "
33
extern int cleanup_result(RESULT& r, void* data);
34
"; block_end(); echo "
35
This frees the structure pointed to by data, if it's non-NULL.
36
"; block_start(); echo "
37
extern double compute_granted_credit(WORKUNIT&, vector<RESULT>& results);
38
"; block_end(); echo "
39
Given a set of results (at least one of which is valid)
40
compute the credit to be granted to all of them.
41
Normally this function simply returns
42
<code>median_mean_credit(results)</code>.
43
If credit is <a href=tools_work.php>specified in the workunit</a>,
44
call <code>get_credit_from_wu()</code>.
46
You must link these functions with the files
47
validator.C, validate_util.C, and validate_util2.C.
48
The result is your custom validator.
51
Here's an example in which the output file
52
contains an integer and a double.
53
Two results are considered equivalent if the integer is equal
54
and the doubles differ by no more than 0.01.
56
This example uses utility functions
57
get_output_file_path() and try_fopen(),
58
which are documented <a href=backend_util.php>here</a>.
59
"; block_start(); echo "
65
int init_result(RESULT const & result, void*& data) {
71
retval = get_output_file_path(result, path);
72
if (retval) return retval;
73
retval = try_fopen(path.c_str(), f, \"r\");
74
if (retval) return retval;
75
n = fscanf(f, \"%d %f\", &i, &x);
76
if (n != 2) return ERR_XML_PARSE;
85
RESULT& r1, void* _data1, RESULT const& r2, void* _data2, bool& match
87
DATA* data1 = (DATA*)_data1;
88
DATA* data2 = (DATA*)_data2;
90
if (data1->i != data2->i) match = false;
91
if (fabs(data1->x - data2->x) > 0.01) match = false;
95
int cleanup_result(RESULT& r, void* data) {
96
if (data) delete (DATA*) data;
100
double compute_granted_credit(WORKUNIT&, vector<RESULT>& results) {
101
return median_mean_credit(results);
104
"; block_end(); echo "