Skip to content

Commit

Permalink
Add checkDictionaryUpdate.py script and its tests
Browse files Browse the repository at this point in the history
  • Loading branch information
makortel committed Jul 23, 2024
1 parent cfe793c commit 444d6a3
Show file tree
Hide file tree
Showing 7 changed files with 136 additions and 0 deletions.
53 changes: 53 additions & 0 deletions Utilities/ReleaseScripts/scripts/checkDictionaryUpdate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/env python3

import sys
import json
import argparse

# exit codes
NO_CHANGES = 0
DATAFORMATS_CHANGED = 40
POLICY_VIOLATION = 41

def policyChecks(document):
"""Check policies on dictionary definitions. Return True if checks are fine."""
# Contents to be added later
return True

def updatePolicyChecks(reference, update):
"""Check policies on dictionary updates. Return True if checks are fine."""
# Contents to be added later
return True

def main(args):
with open(args.baseline) as f:
baseline = json.load(f)

if args.pr is not None:
with open(args.pr) as f:
pr = json.load(f)
pc1 = policyChecks(pr)
if baseline != pr:
pc2 = updatePolicyChecks(baseline, pr)
if not (pc1 and pc2):
return POLICY_VIOLATION

print("Changes in persistable data formats")
return DATAFORMATS_CHANGED
if not pc1:
return POLICY_VIOLATION
else:
if not policyChecks(baseline):
return POLICY_VIOLATION

return NO_CHANGES

if __name__ == "__main__":
parser = argparse.ArgumentParser(description=f"Check dictionary policies of the JSON output of edmDumpClassVersion. If one JSON document is given (--baseline; e.g. in IBs), only the dictionary definition policy checks are done. If two JSON documents are given (--baseline and --pr; e.g. in PR tests), the dictionary definition policy checks are done on the --pr document, and, in addition, if any persistable data formats are changed, additional checks are done to ensure the dictionary update is done properly. Exits with {NO_CHANGES} if there are no changes to persistent data formats. Exits with {DATAFORMATS_CHANGED} if persistent data formats are changed, and the update complies with data format policies. Exits with {POLICY_VIOLATION} if some data format policy is violated. Other exit codes (e.g. 1, 2) denote some failure in the script itself.")

parser.add_argument("--baseline", required=True, type=str, help="JSON file for baseline")
parser.add_argument("--pr", type=str, help="JSON file for baseline+PR")
parser.add_argument("--transientDataFormatPackage", action="store_true", help="The JSON files are for a package that can have only transient data formats")

args = parser.parse_args()
sys.exit(main(args))
2 changes: 2 additions & 0 deletions Utilities/ReleaseScripts/test/BuildFile.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@
</test>
<bin name="test-valgrind-memleak" file="test-valgrind-memleak.cpp"/>
</ifrelease>

<test name="TestUtilitiesReleaseScriptsCheckDictionaryUpdate" command="run_checkDictionaryUpdate.sh"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"edm::Wrapper<edmtest::reflection::IntObject>": {
"checksum": 536952283,
"version": 4
},
"edmtest::reflection::IntObject": {
"checksum": 427917710,
"version": 3
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"edm::Wrapper<edmtest::reflection::IntObject>": {
"checksum": 536952283,
"version": 4
},
"edmtest::reflection::IntObject": {
"checksum": 427917710,
"version": 3
},
"edmtest::reflection::Another": {
"checksum": 427917711,
"version": 3
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"edmtest::reflection::IntObject": {
"checksum": 427917710,
"version": 3
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"edm::Wrapper<edmtest::reflection::IntObject>": {
"checksum": 536952283,
"version": 4
},
"edmtest::reflection::IntObject": {
"checksum": 3848242946,
"version": 4
}
}
41 changes: 41 additions & 0 deletions Utilities/ReleaseScripts/test/run_checkDictionaryUpdate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash

# possible exit codes
SUCCESS=0
FAILURE="fail"
DATAFORMATS_CHANGED=40
POLICY_VIOLATION=41

function die { echo Failure $1: status $2 ; exit $2 ; }
function checkExitCode {
if [ "$1" == "$FAILURE" ]; then
if [[ "$2" = @("$SUCCESS"|"$DATAFORMATS_CHANGES"|"$POLICY_VIOLATIONS") ]]; then
echo "checkDictionaryUpdate.py $3: expected failure exit code, got $2"
exit 1
fi
elif [ "$1" != "$2" ]; then
echo "checkDictionaryUpdate.py $3: expected exit code $1, got $2"
exit 1
fi
}

JSONPATH=${SCRAM_TEST_PATH}/checkDictionaryUpdate

checkDictionaryUpdate.py --baseline ${JSONPATH}/dumpClassVersion_baseline.json || die "checkDictionaryUpdate.py baseline" $?
checkDictionaryUpdate.py --baseline ${JSONPATH}/dumpClassVersion_baseline.json --pr ${JSONPATH}/dumpClassVersion_baseline.json || die "checkDictionaryUpdate.py baseline baseline" $?

checkDictionaryUpdate.py
RET=$?
checkExitCode ${FAILURE} $RET ""

checkDictionaryUpdate.py --baseline ${JSONPATH}/dumpClassVersion_baseline.json --pr ${JSONPATH}/dumpClassVersion_versionUpdate.json
RET=$?
checkExitCode ${DATAFORMATS_CHANGED} $RET "baseline versionUpdate"

checkDictionaryUpdate.py --baseline ${JSONPATH}/dumpClassVersion_baseline.json --pr ${JSONPATH}/dumpClassVersion_newClass.json
RET=$?
checkExitCode ${DATAFORMATS_CHANGED} $RET "baseline newClass"

checkDictionaryUpdate.py --baseline ${JSONPATH}/dumpClassVersion_baseline.json --pr ${JSONPATH}/dumpClassVersion_removeClass.json
RET=$?
checkExitCode ${DATAFORMATS_CHANGED} $RET "baseline removeClass"

0 comments on commit 444d6a3

Please sign in to comment.