2018-12-29 20:05:58 +01:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
|
|
from os import environ, getcwd, chdir
|
|
|
|
|
import json
|
|
|
|
|
from tempfile import TemporaryDirectory
|
|
|
|
|
from contextlib import contextmanager
|
|
|
|
|
from unittest import TestCase, main
|
|
|
|
|
|
|
|
|
|
# Setup location of database file to a relative term so it can be generated
|
|
|
|
|
# in the current subdirectory, which will be a temporary one, to allow concurent
|
|
|
|
|
# testing.
|
|
|
|
|
environ['XRAY_DATABASE_ROOT'] = '.'
|
2020-01-15 17:34:33 +01:00
|
|
|
environ['XRAY_PART'] = './'
|
2018-12-29 20:05:58 +01:00
|
|
|
|
|
|
|
|
from prjxray.util import get_roi
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@contextmanager
|
|
|
|
|
def setup_database(contents):
|
|
|
|
|
with TemporaryDirectory() as d:
|
|
|
|
|
olddir = getcwd()
|
|
|
|
|
chdir(d)
|
|
|
|
|
e = None
|
|
|
|
|
with open('tilegrid.json', 'w') as fd:
|
|
|
|
|
json.dump(contents, fd)
|
|
|
|
|
try:
|
|
|
|
|
yield
|
|
|
|
|
except Exception as ereal:
|
|
|
|
|
e = ereal
|
|
|
|
|
chdir(olddir)
|
|
|
|
|
if e is not None:
|
|
|
|
|
raise e
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestUtil(TestCase):
|
|
|
|
|
def test_get_roi_gen_sites(self):
|
|
|
|
|
makedb = lambda sites: {
|
|
|
|
|
"ATILE": {
|
|
|
|
|
"bits": {
|
|
|
|
|
"CLB_IO_CLK": {
|
|
|
|
|
"baseaddr": "0x00400F00",
|
|
|
|
|
"frames": 28,
|
|
|
|
|
"height": 2,
|
|
|
|
|
"offset": 0,
|
|
|
|
|
"words": 2
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
"grid_x": 10,
|
|
|
|
|
"grid_y": 10,
|
|
|
|
|
"segment": "ASEGMENT",
|
|
|
|
|
"segment_type": "bram0_l",
|
|
|
|
|
"sites": sites,
|
2020-03-24 20:27:26 +01:00
|
|
|
"prohibited_sites": [],
|
2018-12-29 20:05:58 +01:00
|
|
|
"type": "BRAM_INT_INTERFACE_L"
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
with setup_database(makedb({})):
|
2019-01-11 04:47:55 +01:00
|
|
|
self.assertListEqual(list(get_roi().gen_sites()), [])
|
2018-12-29 20:05:58 +01:00
|
|
|
with setup_database(makedb({'FOO': 'BAR'})):
|
2019-01-11 04:47:55 +01:00
|
|
|
self.assertListEqual(
|
2018-12-29 20:05:58 +01:00
|
|
|
list(get_roi().gen_sites()), [('ATILE', 'FOO', 'BAR')])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
main()
|