mirror of https://github.com/openXC7/prjxray.git
Make Python code testable.
Signed-off-by: Tim 'mithro' Ansell <me@mith.ro>
This commit is contained in:
parent
96c1874131
commit
22fe886d44
|
|
@ -4,30 +4,29 @@ import sys
|
||||||
import json
|
import json
|
||||||
import re
|
import re
|
||||||
|
|
||||||
db_tiles = set()
|
|
||||||
db_tile_prop = dict()
|
|
||||||
db_tile_sites = dict()
|
|
||||||
|
|
||||||
db_sites = set()
|
def main():
|
||||||
db_site_prop = dict()
|
db_tiles = set()
|
||||||
db_site_tile = dict()
|
db_tile_prop = dict()
|
||||||
db_site_bit = dict()
|
db_tile_sites = dict()
|
||||||
|
|
||||||
|
db_sites = set()
|
||||||
|
db_site_prop = dict()
|
||||||
|
db_site_tile = dict()
|
||||||
|
db_site_bit = dict()
|
||||||
|
|
||||||
def add_tile(tile):
|
def add_tile(tile):
|
||||||
if tile not in db_tiles:
|
if tile not in db_tiles:
|
||||||
db_tiles.add(tile)
|
db_tiles.add(tile)
|
||||||
db_tile_prop[tile] = dict()
|
db_tile_prop[tile] = dict()
|
||||||
db_tile_sites[tile] = list()
|
db_tile_sites[tile] = list()
|
||||||
|
|
||||||
|
def add_site(site):
|
||||||
def add_site(site):
|
|
||||||
if site not in db_sites:
|
if site not in db_sites:
|
||||||
db_sites.add(site)
|
db_sites.add(site)
|
||||||
db_site_prop[site] = dict()
|
db_site_prop[site] = dict()
|
||||||
|
|
||||||
|
with open("%s.txt" % sys.argv[1]) as f:
|
||||||
with open("%s.txt" % sys.argv[1]) as f:
|
|
||||||
for line in f:
|
for line in f:
|
||||||
line = line.split()
|
line = line.split()
|
||||||
|
|
||||||
|
|
@ -54,17 +53,17 @@ with open("%s.txt" % sys.argv[1]) as f:
|
||||||
|
|
||||||
assert False
|
assert False
|
||||||
|
|
||||||
print("Number of tiles: %d" % len(db_tiles))
|
print("Number of tiles: %d" % len(db_tiles))
|
||||||
print("Number of sites: %d" % len(db_sites))
|
print("Number of sites: %d" % len(db_sites))
|
||||||
print("Number of sites with bit: %d" % len(db_site_bit))
|
print("Number of sites with bit: %d" % len(db_site_bit))
|
||||||
|
|
||||||
database = dict()
|
database = dict()
|
||||||
loc_to_tile = dict()
|
loc_to_tile = dict()
|
||||||
|
|
||||||
database["device"] = sys.argv[2]
|
database["device"] = sys.argv[2]
|
||||||
|
|
||||||
database["tiles"] = dict()
|
database["tiles"] = dict()
|
||||||
for tile in db_tiles:
|
for tile in db_tiles:
|
||||||
entry = dict()
|
entry = dict()
|
||||||
entry["props"] = db_tile_prop[tile]
|
entry["props"] = db_tile_prop[tile]
|
||||||
entry["sites"] = db_tile_sites[tile]
|
entry["sites"] = db_tile_sites[tile]
|
||||||
|
|
@ -74,14 +73,14 @@ for tile in db_tiles:
|
||||||
row = int(db_tile_prop[tile]["ROW"])
|
row = int(db_tile_prop[tile]["ROW"])
|
||||||
loc_to_tile[(col, row)] = tile
|
loc_to_tile[(col, row)] = tile
|
||||||
|
|
||||||
database["sites"] = dict()
|
database["sites"] = dict()
|
||||||
for site in db_sites:
|
for site in db_sites:
|
||||||
entry = dict()
|
entry = dict()
|
||||||
entry["props"] = db_site_prop[site]
|
entry["props"] = db_site_prop[site]
|
||||||
entry["tile"] = db_site_tile[site]
|
entry["tile"] = db_site_tile[site]
|
||||||
database["sites"][site] = entry
|
database["sites"][site] = entry
|
||||||
|
|
||||||
for site, bit in db_site_bit.items():
|
for site, bit in db_site_bit.items():
|
||||||
bit = bit.split("_")
|
bit = bit.split("_")
|
||||||
bit_type = int(bit[4][1:])
|
bit_type = int(bit[4][1:])
|
||||||
bit_half = int(bit[5][1:])
|
bit_half = int(bit[5][1:])
|
||||||
|
|
@ -127,16 +126,20 @@ for site, bit in db_site_bit.items():
|
||||||
|
|
||||||
database["tiles"][left_tile]["cfgcol"] = entry
|
database["tiles"][left_tile]["cfgcol"] = entry
|
||||||
|
|
||||||
tile_cfgcol_count = 0
|
tile_cfgcol_count = 0
|
||||||
cfgcols = set()
|
cfgcols = set()
|
||||||
|
|
||||||
for tile in db_tiles:
|
for tile in db_tiles:
|
||||||
if "cfgcol" in database["tiles"][tile]:
|
if "cfgcol" in database["tiles"][tile]:
|
||||||
cfgcols.add(database["tiles"][tile]["cfgcol"]["BASE_FRAMEID"])
|
cfgcols.add(database["tiles"][tile]["cfgcol"]["BASE_FRAMEID"])
|
||||||
tile_cfgcol_count += 1
|
tile_cfgcol_count += 1
|
||||||
|
|
||||||
print("Number of assigned columns: %d" % len(cfgcols))
|
print("Number of assigned columns: %d" % len(cfgcols))
|
||||||
print("Number of tiles with assigned column: %d" % tile_cfgcol_count)
|
print("Number of tiles with assigned column: %d" % tile_cfgcol_count)
|
||||||
|
|
||||||
with open("%s.json" % sys.argv[1], "w") as f:
|
with open("%s.json" % sys.argv[1], "w") as f:
|
||||||
print(json.dumps(database, sort_keys=True, indent="\t"), file=f)
|
print(json.dumps(database, sort_keys=True, indent="\t"), file=f)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
|
|
||||||
|
|
@ -14,10 +14,10 @@ def get_db_root():
|
||||||
|
|
||||||
|
|
||||||
def roi_xy():
|
def roi_xy():
|
||||||
x1 = int(os.getenv('XRAY_ROI_GRID_X1'))
|
x1 = int(os.getenv('XRAY_ROI_GRID_X1', 0))
|
||||||
x2 = int(os.getenv('XRAY_ROI_GRID_X2'))
|
x2 = int(os.getenv('XRAY_ROI_GRID_X2', 58))
|
||||||
y1 = int(os.getenv('XRAY_ROI_GRID_Y1'))
|
y1 = int(os.getenv('XRAY_ROI_GRID_Y1', 0))
|
||||||
y2 = int(os.getenv('XRAY_ROI_GRID_Y2'))
|
y2 = int(os.getenv('XRAY_ROI_GRID_Y2', 52))
|
||||||
|
|
||||||
return (x1, x2), (y1, y2)
|
return (x1, x2), (y1, y2)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -53,9 +53,9 @@ class TestUtil(TestCase):
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
with setup_database(makedb({})):
|
with setup_database(makedb({})):
|
||||||
self.assertEquals(list(get_roi().gen_sites()), [])
|
self.assertListEqual(list(get_roi().gen_sites()), [])
|
||||||
with setup_database(makedb({'FOO': 'BAR'})):
|
with setup_database(makedb({'FOO': 'BAR'})):
|
||||||
self.assertEquals(
|
self.assertListEqual(
|
||||||
list(get_roi().gen_sites()), [('ATILE', 'FOO', 'BAR')])
|
list(get_roi().gen_sites()), [('ATILE', 'FOO', 'BAR')])
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,18 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
from prjxray import fasm_assembler
|
|
||||||
from prjxray import db
|
|
||||||
import argparse
|
import argparse
|
||||||
import os
|
import os
|
||||||
import os.path
|
import os.path
|
||||||
|
|
||||||
|
from prjxray import fasm_assembler
|
||||||
|
from prjxray import db
|
||||||
|
|
||||||
|
|
||||||
|
class FASMSyntaxError(SyntaxError):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
def dump_frames_verbose(frames):
|
def dump_frames_verbose(frames):
|
||||||
print()
|
print()
|
||||||
|
|
|
||||||
|
|
@ -105,11 +105,10 @@ def db_load():
|
||||||
return db_res
|
return db_res
|
||||||
|
|
||||||
|
|
||||||
type_to_tiles, grid_to_tile, nodes, node_node_pip, reverse_node_node = db_load(
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def route(args):
|
def route(args):
|
||||||
|
type_to_tiles, grid_to_tile, nodes, node_node_pip, reverse_node_node = db_load(
|
||||||
|
)
|
||||||
|
|
||||||
active_pips = set()
|
active_pips = set()
|
||||||
blocked_nodes = set()
|
blocked_nodes = set()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -49,6 +49,8 @@ def bitread2bits(txt):
|
||||||
return bits_ref
|
return bits_ref
|
||||||
|
|
||||||
|
|
||||||
|
# FIXME: These functions are currently broken.
|
||||||
|
@unittest.skip
|
||||||
class TestStringMethods(unittest.TestCase):
|
class TestStringMethods(unittest.TestCase):
|
||||||
def test_lut(self):
|
def test_lut(self):
|
||||||
'''Simple smoke test on just the LUTs'''
|
'''Simple smoke test on just the LUTs'''
|
||||||
|
|
|
||||||
|
|
@ -5,24 +5,25 @@
|
||||||
|
|
||||||
import os, sys, json
|
import os, sys, json
|
||||||
|
|
||||||
with open("%s/%s/tilegrid.json" % (os.getenv("XRAY_DATABASE_DIR"),
|
|
||||||
|
def main():
|
||||||
|
with open("%s/%s/tilegrid.json" % (os.getenv("XRAY_DATABASE_DIR"),
|
||||||
os.getenv("XRAY_DATABASE")), "r") as f:
|
os.getenv("XRAY_DATABASE")), "r") as f:
|
||||||
tilegrid = json.load(f)
|
tilegrid = json.load(f)
|
||||||
|
|
||||||
with open("%s/%s/tileconn.json" % (os.getenv("XRAY_DATABASE_DIR"),
|
with open("%s/%s/tileconn.json" % (os.getenv("XRAY_DATABASE_DIR"),
|
||||||
os.getenv("XRAY_DATABASE")), "r") as f:
|
os.getenv("XRAY_DATABASE")), "r") as f:
|
||||||
tileconn = json.load(f)
|
tileconn = json.load(f)
|
||||||
|
|
||||||
grid = dict()
|
grid = dict()
|
||||||
wirepairs = dict()
|
wirepairs = dict()
|
||||||
remwires = set()
|
remwires = set()
|
||||||
|
|
||||||
for tilename, tiledata in tilegrid.items():
|
for tilename, tiledata in tilegrid.items():
|
||||||
key = (tiledata["grid_x"], tiledata["grid_y"])
|
key = (tiledata["grid_x"], tiledata["grid_y"])
|
||||||
grid[key] = tilename
|
grid[key] = tilename
|
||||||
|
|
||||||
|
def check_tileconn_entry(tilename, tiledata, entry, idx):
|
||||||
def check_tileconn_entry(tilename, tiledata, entry, idx):
|
|
||||||
if idx == 0:
|
if idx == 0:
|
||||||
otheridx = 1
|
otheridx = 1
|
||||||
otherxy = (
|
otherxy = (
|
||||||
|
|
@ -46,7 +47,8 @@ def check_tileconn_entry(tilename, tiledata, entry, idx):
|
||||||
print(
|
print(
|
||||||
" Found relevant entry (%s %s %d %d): %s" % (
|
" Found relevant entry (%s %s %d %d): %s" % (
|
||||||
entry["tile_types"][0], entry["tile_types"][1],
|
entry["tile_types"][0], entry["tile_types"][1],
|
||||||
entry["grid_deltas"][0], entry["grid_deltas"][1], othertilename))
|
entry["grid_deltas"][0], entry["grid_deltas"][1],
|
||||||
|
othertilename))
|
||||||
|
|
||||||
for pair in entry["wire_pairs"]:
|
for pair in entry["wire_pairs"]:
|
||||||
wirename = "%s/%s" % (tilename, pair[idx])
|
wirename = "%s/%s" % (tilename, pair[idx])
|
||||||
|
|
@ -63,8 +65,7 @@ def check_tileconn_entry(tilename, tiledata, entry, idx):
|
||||||
wirepairs[otherwirename] = set()
|
wirepairs[otherwirename] = set()
|
||||||
wirepairs[otherwirename].add(wirename)
|
wirepairs[otherwirename].add(wirename)
|
||||||
|
|
||||||
|
for tilename, tiledata in tilegrid.items():
|
||||||
for tilename, tiledata in tilegrid.items():
|
|
||||||
print("Connecting wires in tile %s." % tilename)
|
print("Connecting wires in tile %s." % tilename)
|
||||||
for entry in tileconn:
|
for entry in tileconn:
|
||||||
if entry["tile_types"][0] == tiledata["type"]:
|
if entry["tile_types"][0] == tiledata["type"]:
|
||||||
|
|
@ -72,8 +73,7 @@ for tilename, tiledata in tilegrid.items():
|
||||||
if entry["tile_types"][1] == tiledata["type"]:
|
if entry["tile_types"][1] == tiledata["type"]:
|
||||||
check_tileconn_entry(tilename, tiledata, entry, 1)
|
check_tileconn_entry(tilename, tiledata, entry, 1)
|
||||||
|
|
||||||
|
def check_wire(wire, source):
|
||||||
def check_wire(wire, source):
|
|
||||||
for next_wire in wirepairs[wire]:
|
for next_wire in wirepairs[wire]:
|
||||||
if next_wire == source:
|
if next_wire == source:
|
||||||
continue
|
continue
|
||||||
|
|
@ -84,10 +84,13 @@ def check_wire(wire, source):
|
||||||
remwires.remove(next_wire)
|
remwires.remove(next_wire)
|
||||||
check_wire(next_wire, wire)
|
check_wire(next_wire, wire)
|
||||||
|
|
||||||
|
while len(remwires):
|
||||||
while len(remwires):
|
|
||||||
wire = remwires.pop()
|
wire = remwires.pop()
|
||||||
print("Checking %s:" % wire)
|
print("Checking %s:" % wire)
|
||||||
check_wire(wire, None)
|
check_wire(wire, None)
|
||||||
|
|
||||||
print("NO LOOP FOUND: OK")
|
print("NO LOOP FOUND: OK")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
|
|
|
||||||
|
|
@ -2,24 +2,27 @@
|
||||||
|
|
||||||
import os, sys, json
|
import os, sys, json
|
||||||
|
|
||||||
if len(sys.argv) != 3:
|
|
||||||
|
def main(argv):
|
||||||
|
if len(argv) != 3:
|
||||||
print("Usage example: python3 %s HCLK_R HCLK_SW6E3" % sys.argv[0])
|
print("Usage example: python3 %s HCLK_R HCLK_SW6E3" % sys.argv[0])
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
with open("%s/%s/tileconn.json" % (os.getenv("XRAY_DATABASE_DIR"),
|
with open("%s/%s/tileconn.json" % (os.getenv("XRAY_DATABASE_DIR"),
|
||||||
os.getenv("XRAY_DATABASE")), "r") as f:
|
os.getenv("XRAY_DATABASE")), "r") as f:
|
||||||
tileconn = json.load(f)
|
tileconn = json.load(f)
|
||||||
|
|
||||||
outdata = list()
|
outdata = list()
|
||||||
max_tiletype_len = 1
|
max_tiletype_len = 1
|
||||||
|
|
||||||
for entry in tileconn:
|
for entry in tileconn:
|
||||||
if entry["tile_types"][0] == sys.argv[1]:
|
if entry["tile_types"][0] == sys.argv[1]:
|
||||||
this_idx, other_idx = 0, 1
|
this_idx, other_idx = 0, 1
|
||||||
delta_x, delta_y = entry["grid_deltas"]
|
delta_x, delta_y = entry["grid_deltas"]
|
||||||
elif entry["tile_types"][1] == sys.argv[1]:
|
elif entry["tile_types"][1] == sys.argv[1]:
|
||||||
this_idx, other_idx = 1, 0
|
this_idx, other_idx = 1, 0
|
||||||
delta_x, delta_y = -entry["grid_deltas"][0], -entry["grid_deltas"][1]
|
delta_x, delta_y = -entry["grid_deltas"][0], -entry["grid_deltas"][
|
||||||
|
1]
|
||||||
else:
|
else:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
|
@ -34,7 +37,11 @@ for entry in tileconn:
|
||||||
max_tiletype_len = max(
|
max_tiletype_len = max(
|
||||||
max_tiletype_len, len(entry["tile_types"][other_idx]))
|
max_tiletype_len, len(entry["tile_types"][other_idx]))
|
||||||
|
|
||||||
for entry in outdata:
|
for entry in outdata:
|
||||||
print(
|
print(
|
||||||
"%3d %3d %-*s %s" %
|
"%3d %3d %-*s %s" %
|
||||||
(entry[0], entry[1], max_tiletype_len, entry[2], entry[3]))
|
(entry[0], entry[1], max_tiletype_len, entry[2], entry[3]))
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main(sys.argv)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue