Commit 5c67a920 authored by Luke Mewburn's avatar Luke Mewburn
Browse files

testing: use common asn_config.json (part 1)

Implement common asn_config.json to be used by various checks.
Contents of asn_config.json is a JSON object with fields:
  asn_files	Dict with key as filename.asn and value as object
		with various optional fields:
		dependencies: List of filenames to dependencies.

Refactor compile checks in compileAllTargets() to use asn_config.json
instead of asn_compile_targets.json (list of lists).

Format asn_config.json with jq -S (sorted keys).
parent 07b80793
Loading
Loading
Loading
Loading

testing/asn_compile_targets.json

deleted100644 → 0
+0 −19
Original line number Diff line number Diff line
[
    ["./33128/r15/TS33128Payloads.asn"],
    ["./33128/r16/TS33128Payloads.asn"],
    ["./33128/r16/TS33128IdentityAssociation.asn"],
    ["./33128/r17/TS33128Payloads.asn"],
    ["./33128/r17/TS33128IdentityAssociation.asn"],
    [
        "./33128/r18/TS33128Payloads.asn",
        "./testing/dependencies/asn/IPAccessPDU.asn",
        "./testing/dependencies/asn/stubs/LI-PS-PDU.asn"
    ],
    ["./33128/r18/TS33128IdentityAssociation.asn"],
    [
        "./33128/r19/TS33128Payloads.asn",
        "./testing/dependencies/asn/IPAccessPDU.asn",
        "./testing/dependencies/asn/stubs/LI-PS-PDU.asn"
    ],
    ["./33128/r19/TS33128IdentityAssociation.asn"]
]
+23 −0
Original line number Diff line number Diff line
{
  "asn_files": {
    "33128/r15/TS33128Payloads.asn": {},
    "33128/r16/TS33128IdentityAssociation.asn": {},
    "33128/r16/TS33128Payloads.asn": {},
    "33128/r17/TS33128IdentityAssociation.asn": {},
    "33128/r17/TS33128Payloads.asn": {},
    "33128/r18/TS33128IdentityAssociation.asn": {},
    "33128/r18/TS33128Payloads.asn": {
      "dependencies": [
        "testing/dependencies/asn/IPAccessPDU.asn",
        "testing/dependencies/asn/stubs/LI-PS-PDU.asn"
      ]
    },
    "33128/r19/TS33128IdentityAssociation.asn": {},
    "33128/r19/TS33128Payloads.asn": {
      "dependencies": [
        "testing/dependencies/asn/IPAccessPDU.asn",
        "testing/dependencies/asn/stubs/LI-PS-PDU.asn"
      ]
    }
  }
}
+16 −13
Original line number Diff line number Diff line
@@ -69,11 +69,12 @@ def syntaxCheckASN(fileList):
    return results


def compileAllTargets(compileTargets):
def compileAllTargets(asnFiles):
    """
    Attempts to compile a set of compile targets using the pycrate ASN1 tools

    :param compileTargets: list of compile targets, each of which is a list of filenames
    :param asnFiles: dict; key is filename, value is dict with optional keys:
      dependencies, list of dependencies.
    :returns: A dict of outcome against the first filename of each compile target. Return code and message are included for failures.

    For each compile target (list of filenames) the first filename is assumed
@@ -88,24 +89,23 @@ def compileAllTargets(compileTargets):
    we can't use it.
    """
    results = {}
    for target in compileTargets:
        firstTarget = target[0]
        logging.debug(f"Compiling {firstTarget}")
    for target, config in asnFiles.items():
        logging.debug(f"Compiling {target}")
        try:
            fileTexts = []
            fileNames = []
            fileNames = [target]
            fileNames.extend(config.get("dependencies", []))
            GLOBAL.clear()
            for filename in target:
            for filename in fileNames:
                pFile = Path(filename)
                fileTexts.append(pFile.read_text())
                fileNames.append(filename)
                logging.debug(f"  Loading {filename}")
            compile_text(fileTexts, filenames=fileNames)
            results[str(firstTarget)] = {
            results[str(target)] = {
                "ok": True,
            }
        except Exception as ex:
            results[str(firstTarget)] = {"ok": False, "code": -1, "message": f"{ex!r}"}
            results[str(target)] = {"ok": False, "code": -1, "message": f"{ex!r}"}
            continue
    return results

@@ -156,6 +156,9 @@ if __name__ == "__main__":
        )
        change_path_to_unix = True

    logging.info("Loading asn_config.json")
    asnConfig = json.loads(Path("testing/asn_config.json").read_text())

    logging.info("Searching for ASN.1 files")
    fileList = list(Path(".").rglob("*.asn1")) + list(Path(".").rglob("*.asn"))
    logging.info(f"{len(fileList)} ASN.1 files found")
@@ -190,10 +193,10 @@ if __name__ == "__main__":
        exit(-1)

    logging.info("Getting compile targets")
    compileTargets = json.loads(Path("testing/asn_compile_targets.json").read_text())
    logging.info(f"{len(compileTargets)} compile targets found")
    asnFiles = asnConfig["asn_files"]
    logging.info(f"{len(asnFiles)} compile targets found")

    compileResults = compileAllTargets(compileTargets)
    compileResults = compileAllTargets(asnFiles)
    if processResults(compileResults, "Compiling") > 0:
        exit(1)