2018-12-29 20:05:58 +01:00
|
|
|
#!/usr/bin/env python3
|
2020-04-16 10:31:33 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
#
|
|
|
|
|
# Copyright (C) 2017-2020 The Project X-Ray Authors.
|
|
|
|
|
#
|
|
|
|
|
# Use of this source code is governed by a ISC-style
|
|
|
|
|
# license that can be found in the LICENSE file or at
|
|
|
|
|
# https://opensource.org/licenses/ISC
|
|
|
|
|
#
|
|
|
|
|
# SPDX-License-Identifier: ISC
|
2018-12-29 20:05:58 +01:00
|
|
|
|
2021-01-09 21:11:45 +01:00
|
|
|
from os import environ, getcwd, chdir, mkdir, environ
|
2018-12-29 20:05:58 +01:00
|
|
|
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'] = '.'
|
2021-01-09 21:11:45 +01:00
|
|
|
environ['XRAY_PART'] = 'xc7a200tffg1156-1'
|
2018-12-29 20:05:58 +01:00
|
|
|
|
2020-07-15 21:26:47 +02:00
|
|
|
from prjxray.util import get_roi, get_db_root
|
|
|
|
|
from prjxray.overlay import Overlay
|
|
|
|
|
from prjxray.grid_types import GridLoc
|
2018-12-29 20:05:58 +01:00
|
|
|
|
2020-07-15 21:54:27 +02:00
|
|
|
|
2018-12-29 20:05:58 +01:00
|
|
|
@contextmanager
|
|
|
|
|
def setup_database(contents):
|
|
|
|
|
with TemporaryDirectory() as d:
|
|
|
|
|
olddir = getcwd()
|
|
|
|
|
chdir(d)
|
2021-01-09 21:11:45 +01:00
|
|
|
mkdir('xc7a200t')
|
|
|
|
|
mkdir('mapping')
|
|
|
|
|
environ['XRAY_DATABASE_ROOT'] = d
|
2018-12-29 20:05:58 +01:00
|
|
|
e = None
|
2021-01-09 21:11:45 +01:00
|
|
|
with open('xc7a200t/tilegrid.json', 'w') as fd:
|
2018-12-29 20:05:58 +01:00
|
|
|
json.dump(contents, fd)
|
2021-01-09 21:11:45 +01:00
|
|
|
# Create some dummy data
|
|
|
|
|
with open('mapping/devices.yaml', 'w') as fd:
|
|
|
|
|
json.dump({'xc7a200t': {'fabric': "xc7a200t"}}, fd)
|
|
|
|
|
with open('mapping/parts.yaml', 'w') as fd:
|
|
|
|
|
json.dump({'xc7a200tffg1156-1': {"device": "xc7a200t"}}, fd)
|
|
|
|
|
|
2018-12-29 20:05:58 +01:00
|
|
|
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')])
|
|
|
|
|
|
2020-07-15 21:26:47 +02:00
|
|
|
def test_in_roi_overlay(self):
|
|
|
|
|
region_dict = {}
|
|
|
|
|
region_dict['pr1'] = (10, 58, 0, 51)
|
|
|
|
|
region_dict['pr2'] = (10, 58, 52, 103)
|
2020-07-15 21:54:27 +02:00
|
|
|
overlay = Overlay(region_dict)
|
2020-07-15 21:26:47 +02:00
|
|
|
self.assertFalse(overlay.tile_in_roi(GridLoc(18, 50)))
|
|
|
|
|
self.assertFalse(overlay.tile_in_roi(GridLoc(18, 84)))
|
|
|
|
|
self.assertTrue(overlay.tile_in_roi(GridLoc(8, 50)))
|
|
|
|
|
self.assertTrue(overlay.tile_in_roi(GridLoc(18, 112)))
|
|
|
|
|
self.assertTrue(overlay.tile_in_roi(GridLoc(80, 40)))
|
2018-12-29 20:05:58 +01:00
|
|
|
|
2020-07-15 21:54:27 +02:00
|
|
|
|
2018-12-29 20:05:58 +01:00
|
|
|
if __name__ == '__main__':
|
|
|
|
|
main()
|