#!/usr/bin/env python3
"""

This script extracts the top module cells and their corresponding parameters
from json files produced by Yosys.
The return code of this script is used to check if the output is equivalent.
"""

import sys
import json

parameters = ["IOSTANDARD", "DRIVE", "SLEW", "IN_TERM"]

def read_cells(json_file):
    with open(json_file) as f:
        data = json.load(f)
    f.close()
    cells = data['modules']['top']['cells']
    cells_parameters = dict()
    for cell, opts in cells.items():
        attributes = opts['parameters']
        if len(attributes.keys()):
            if any([x in parameters for x in attributes.keys()]):
                cells_parameters[cell] = attributes
    return cells_parameters


def main():
    if len(sys.argv) < 3:
        print("Incorrect number of arguments")
        exit(1)
    cells1 = read_cells(sys.argv[1])
    cells2 = read_cells(sys.argv[2])
    if cells1 == cells2:
        exit(0)
    else:
        print(json.dumps(cells1, indent=4))
        print("VS")
        print(json.dumps(cells2, indent=4))
        exit(1)

if __name__ == "__main__":
    main()

#!/usr/bin/env python3
"""

This script extracts the top module cells and their corresponding parameters
from json files produced by Yosys.
The return code of this script is used to check if the output is equivalent.
"""

import sys
import json
import argparse

parameters = ["IOSTANDARD", "DRIVE", "SLEW", "IN_TERM"]

def read_cells(json_file):
    with open(json_file) as f:
        data = json.load(f)
    f.close()
    cells = data['modules']['top']['cells']
    cells_parameters = dict()
    for cell, opts in cells.items():
        attributes = opts['parameters']
        if len(attributes.keys()):
            if any([x in parameters for x in attributes.keys()]):
                cells_parameters[cell] = attributes
    return cells_parameters


def main(args):
    cells = read_cells(args.json)
    if args.update:
        with open(args.golden, 'w') as f:
            json.dump(cells, f)
    else:
        with open(args.golden) as f:
            cells_golden = json.load(f)
            if cells == cells_golden:
                exit(0)
            else:
                print(json.dumps(cells, indent=4))
                print("VS")
                print(json.dumps(cells_golden, indent=4))
                exit(1)
    f.close()

if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument('--json', help = 'JSON to compare', required = True)
    parser.add_argument('--golden', help = 'Golden JSON file', required = True)
    parser.add_argument('--update', action = 'store_true', help = 'Update golden reference')
    args = parser.parse_args()
    main(args)

Refactor test output comparison script
XDC: Refactor test output comparison script

Signed-off-by: Tomasz Michalak <a2fdaa543b4cc5e3d6cd8672ec412c0eb393b86e@antmicro.com>
