Skip to content

Commit

Permalink
#2291: Add script for comparing the generate LBDatafile with the refe…
Browse files Browse the repository at this point in the history
…rence
  • Loading branch information
thearusable authored and cwschilly committed Sep 20, 2024
1 parent 54825ca commit 2220a40
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 18 deletions.
2 changes: 1 addition & 1 deletion ci/docker/ubuntu-gnu-cpp.dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 11 additions & 5 deletions scripts/check_lb_data_files.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
42 changes: 30 additions & 12 deletions scripts/generate_and_validate_lb_data_file.py
Original file line number Diff line number Diff line change
@@ -1,42 +1,60 @@
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()
group = parser.add_mutually_exclusive_group(required=True)
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()

0 comments on commit 2220a40

Please sign in to comment.