diff --git a/ci/docker/ubuntu-gnu-cpp.dockerfile b/ci/docker/ubuntu-gnu-cpp.dockerfile index e5bf682cf7..40e06e9d7c 100644 --- a/ci/docker/ubuntu-gnu-cpp.dockerfile +++ b/ci/docker/ubuntu-gnu-cpp.dockerfile @@ -87,7 +87,7 @@ RUN apt-get update -y -q && \ apt-get clean && \ rm -rf /var/lib/apt/lists/* -RUN pip3 install schema +RUN pip3 install schema deepdiff FROM base as build COPY . /vt diff --git a/scripts/check_lb_data_files.sh b/scripts/check_lb_data_files.sh index 3f04f385bf..3914a5b35b 100755 --- a/scripts/check_lb_data_files.sh +++ b/scripts/check_lb_data_files.sh @@ -19,8 +19,11 @@ function run_schema_validator() { } # Use vt to generate LB Datafile -python3 "${path_to_vt_src_dir}/scripts/generate_and_validate_lb_data_file.py" \ - -g -s "${path_to_vt_src_dir}" -b "${path_to_vt_build_dir}" -i "LBData_from_lb_iter.%p.json" +if ! python3 "${path_to_vt_src_dir}/scripts/generate_and_validate_lb_data_file.py" -g \ + -b "${path_to_vt_build_dir}" -f "LBData_from_lb_iter.%p.json" +then + exit 2; +fi find . -iname "*.json" | grep -v "compile_commands" | while read f do @@ -32,6 +35,9 @@ do run_schema_validator "$f" done -# # Use vt to generate LB Datafile -# python3 "${path_to_vt_src_dir}/scripts/generate_and_validate_lb_data_file.py" \ -# -v -s "${path_to_vt_src_dir}" -b "${path_to_vt_build_dir}" -i "${path_to_vt_build_dir}/LBData_from_lb_iter.json" +# Use vt to generate LB Datafile +if ! python3 "${path_to_vt_src_dir}/scripts/generate_and_validate_lb_data_file.py" -v \ + -b "${path_to_vt_build_dir}" -f "LBData_from_lb_iter.0.json" -r "${path_to_vt_src_dir}/examples/LBDatafile_example.json" +then + exit 3; +fi diff --git a/scripts/generate_and_validate_lb_data_file.py b/scripts/generate_and_validate_lb_data_file.py index 7b0fa9b99a..086603daed 100644 --- a/scripts/generate_and_validate_lb_data_file.py +++ b/scripts/generate_and_validate_lb_data_file.py @@ -1,23 +1,43 @@ import subprocess import argparse +import json +import sys +from deepdiff import DeepDiff -def generate(vt_build, out_path): +def generate(vt_build, out_file_name): """ Runs vt lb_iter example to generate LBDatafile """ exe_path = vt_build + "/examples/collection/lb_iter" out_dir = "--vt_lb_data_dir=" + vt_build - out_file = "--vt_lb_data_file=" + out_path - + out_file = "--vt_lb_data_file=" + out_file_name + args = (exe_path, "8", "1.0", "2", "--vt_lb", "--vt_lb_interval=1", "--vt_lb_name=RotateLB", "--vt_lb_data", "--vt_lb_data_compress=false", out_dir, out_file) runner = subprocess.Popen(args, stdout=subprocess.PIPE) - runner.wait() + exit_code = runner.wait() + if exit_code != 0: + sys.exit(1) -def validate(file_to_validate, reference_file): +def validate(vt_build, file_to_validate, reference_file): """ Compares file to validate wih reference """ - + print("Comparing '" + file_to_validate + "' with reference file '" + reference_file + "'.") + + with open(vt_build + "/" + file_to_validate) as val_file, open(reference_file) as ref_file: + to_validate = json.load(val_file) + reference = json.load(ref_file) + diff = DeepDiff(to_validate, reference, report_repetition=True, math_epsilon=0.001) + is_valid = not len(diff.affected_paths) + + if not is_valid: + sys.stderr.write("Detected differences:\n") + json.dump(str(diff), sys.stderr, indent=4) + sys.stderr.write("\n") + sys.stderr.flush() + sys.exit(1) + else: + print("Comparison OK.") def main(): parser = argparse.ArgumentParser() @@ -25,18 +45,16 @@ def main(): group.add_argument("--generate", "-g", dest='generate', required=False, action='store_true') group.add_argument("--validate", "-v", dest='validate', required=False, action='store_true') - parser.add_argument("--vt-source-dir", "-s", dest='vt_source_dir', required=True) parser.add_argument("--vt-build-dir", "-b", dest='vt_build_dir', required=True) - - parser.add_argument("--inout-file", "-i", dest='inout_file', required=True) + parser.add_argument("--file-name", "-f", dest='file_name', required=True) parser.add_argument("--reference-file", "-r", dest='reference_file', required=False) args = parser.parse_args() if args.generate: - generate(args.vt_build_dir, args.inout_file) + generate(args.vt_build_dir, args.file_name) if args.validate: - validate(args.inout_file, args.reference_file) - + validate(args.vt_build_dir, args.file_name, args.reference_file) + if __name__ == '__main__': main()