1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2024-12-07 11:13:41 +02:00
FFmpeg/tests/refcmp-metadata.awk
Marton Balint 80e997b081 fate/filter-refcmp-*: make refcmp_metadata fail on empty or truncated input
On empty input the awk script was always successful which caused the
filter-refcmp tests to always succeed.

Also fix the command lines for refcmp_metadata compare function because it
needs auto conversion filters, and update reference of test
filter-refcmp-psnr-rgb because it was missed in
a7fc78c1a6 but was never noticed due to the
original issue...

Signed-off-by: Marton Balint <cus@passwd.hu>
2022-04-10 20:12:23 +02:00

68 lines
1.9 KiB
Awk

# Compare metadata filter output containing float value strings to reference
# output data. Returns the whole reference data if delta of each value is below
# threshold, else returns the whole input data.
function abs(val) {
return ((val < 0.0) ? -val : val);
}
function max(val1, val2) {
return ((val1 >= val2) ? val1 : val2);
}
function is_numeric_str(str) {
return (str ~ /^[+-]?[0-9]*\.?[0-9]+$/);
}
BEGIN {
FS = "=";
# check for "fuzz" (threshold) program parameter, else use default
if (fuzz <= 0.0) {
fuzz = 0.1;
}
# check for "ref" (reference file) program parameter
if (ref) {
ref_nr = 0;
while ((getline line < ref) > 0) {
ref_nr++;
ref_lines[ref_nr] = line;
if (split(line, fields) == 2 && is_numeric_str(fields[2])) {
ref_keys[ref_nr] = fields[1];
ref_vals[ref_nr] = fields[2] + 0; # convert to number
}
}
close(ref);
}
delta_max = 0;
result = (ref ? 1 : 0);
}
{
cmp_lines[NR] = $0;
if (NF == 2 && is_numeric_str($2) && ref_vals[NR]) {
val = $2 + 0; # convert to number
delta = abs((val / ref_vals[NR]) - 1);
delta_max = max(delta_max, delta);
result = result && ($1 == ref_keys[NR]) && (delta <= fuzz);
} else {
result = result && ($0 == ref_lines[NR]);
}
}
END {
result = result && (NR == ref_nr);
if (result) {
for (i = 1; i <= ref_nr; i++)
print ref_lines[i];
} else {
for (i = 1; i <= NR; i++)
print cmp_lines[i];
if (NR == 0)
print "[refcmp] no input" > "/dev/stderr";
else if (NR != ref_nr)
print "[refcmp] lines: " NR " != " ref_nr > "/dev/stderr";
if (delta_max >= fuzz)
print "[refcmp] delta_max: " delta_max " >= " fuzz > "/dev/stderr";
}
}