Commit dc6a1bf9 authored by canterburym's avatar canterburym
Browse files

Adding simple compile tests

parent e39ec40c
Pipeline #3186 passed with stages
in 1 minute and 15 seconds
import logging
from asn1tools import parse_files, compile_dict, ParseError, CompileError
from glob import glob
from pathlib import Path
from pprint import pprint
def parseASN1File (asnFile):
except ParseError as ex:
return [ex]
return []
def parseASN1Files (fileList):
if len(fileList) == 0:
logging.warning ("No files specified")
return {}
errors = {}"Parsing files...")
for f in fileList:
ex = parseASN1File(f)
if ex: (f" {f}: Failed - {ex!r}")
else: (f" {f}: OK")
errors[f] = ex
return errors
def compileASN1Files (fileList):"Compiling files...")
errors = []
d = parse_files(fileList)
for modulename, module in d.items():
# Weird fix because the compiler doesn't like RELATIVE-OID as a type
# Not sure if the on-the-wire encoding would be affected or not
# but for most checking purposes this doesn't matter
module['types']["RELATIVE-OID"] = {'type' : 'OBJECT IDENTIFIER'}
c = compile_dict(d)
except CompileError as ex: (f"Compiler error: {ex}")
except ParseError as ex: (f"Parse error: {ex}")
errors.append(ex) ("Compiled OK")
return errors
def validateASN1Files (fileList):
parseErrors = parseASN1Files(fileList)
# if len(parseErrors > 0):
# ("Abandonding compile due to parse errors")
compileErrors = compileASN1Files(fileList)
return parseErrors, compileErrors
def validateAllASN1FilesInPath (path):
globPattern = str(Path(path)) + '/*.asn1'"Searching: " + globPattern)
schemaGlob = glob(globPattern, recursive=True)
return validateASN1Files(schemaGlob)
if __name__ == '__main__':
parseErrors, compileErrors = validateAllASN1FilesInPath("./")
parseErrorCount = 0
print ("ASN.1 Parser checks:")
print ("-----------------------------")
for filename, errors in parseErrors.items():
if len(errors) > 0:
parseErrorCount += len(errors)
print (f"{filename}: {len(errors)} errors")
for error in errors:
print (" " + str(error))
print (f"{filename}: OK")
print ("-----------------------------")
print ("ASN.1 Compilation:")
print ("-----------------------------")
if len(compileErrors) > 0:
for error in compileErrors:
print (" " + str(error))
print ("Compilation OK")
print ("-----------------------------")
print (f"{parseErrorCount} parse errors, {len(compileErrors)} compile errors")
exit (parseErrorCount + len(compileErrors))
print ("Not implemented yet")
\ No newline at end of file
import logging
import asn1tools
from pathlib import Path
from pprint import pprint
ignoreReleases = {'33108' : [f'r{i}' for i in range(5, 17)],
'33128' : [] }
def prepareFile(f):
with open(f) as fh:
s =
s = s.replace("RELATIVE-OID", "OBJECT IDENTIFIER") # sigh
return s
if __name__ == '__main__':
fileList = list(Path(".").rglob("*.asn1")) + list(Path(".").rglob("*.asn"))
ignoredFiles = [file for file in fileList if[1] in ignoreReleases[[0]]]"Ignoring {len(ignoredFiles)} files")
fileList = [file for file in fileList if file not in ignoredFiles]
if len(fileList) == 0:
logging.warning ("No files specified")
print ("ASN.1 Compilation checks:")
print ("-----------------------------")"Parsing files...")
errorCount = 0
for f in fileList:
s = prepareFile(str(f))
asn1tools.compile_string(s) # this won't work for modules with IMPORTs
except asn1tools.ParseError as ex: (f" {f}: Failed - {ex!r}")
print (f" {f}: Failed - {ex!r}")
errorCount += 1
print (f" {f}: OK")
print ("-----------------------------")
print (f"Compile errors: {errorCount}")
print ("-----------------------------")
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment