From a367ae69ae563dbfddae88eb9b8432ea2e4eb29d Mon Sep 17 00:00:00 2001 From: Lukas Chrostowski Date: Mon, 11 Dec 2023 17:05:42 -0800 Subject: [PATCH] codecov, pytest for all PCells --- .github/workflows/run-layout-tests.yml | 42 +++++++++++++++ klayout/EBeam/__init__.py | 5 +- .../pymacros/tests/test_All_Library_Cells.py | 53 +++++++++++++++++++ klayout/EBeam/test.py | 5 -- 4 files changed, 98 insertions(+), 7 deletions(-) create mode 100644 .github/workflows/run-layout-tests.yml create mode 100644 klayout/EBeam/pymacros/tests/test_All_Library_Cells.py delete mode 100644 klayout/EBeam/test.py diff --git a/.github/workflows/run-layout-tests.yml b/.github/workflows/run-layout-tests.yml new file mode 100644 index 00000000..630941a9 --- /dev/null +++ b/.github/workflows/run-layout-tests.yml @@ -0,0 +1,42 @@ +name: Run SiEPIC-Tool Layout tests + +on: + workflow_dispatch: + push: + paths: + - '**' + branches: + - '**' + pull_request: + branches: + - main + - master + + +jobs: + test_layouts: + runs-on: ubuntu-latest + + steps: + - name: checkout repo content + uses: actions/checkout@v3 + + # can also specify python version if needed + - name: setup python + uses: actions/setup-python@v4 + + - name: install python packages + run: | + python -m pip install --upgrade pip + pip install klayout numpy scipy pytest pytest-cov SiEPIC + + - name: Test with pytest + run: pytest --cov=klayout/siepic_ebeam_pdk klayout/siepic_ebeam_pdk/pymacros/tests/tests_All_Library_Cells.py --cov-report=xml + + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v3 + with: + token: ${{ secrets.CODECOV_TOKEN }} + files: ./coverage.xml + fail_ci_if_error: true + diff --git a/klayout/EBeam/__init__.py b/klayout/EBeam/__init__.py index 057a2e34..6e9d19ca 100644 --- a/klayout/EBeam/__init__.py +++ b/klayout/EBeam/__init__.py @@ -2,8 +2,9 @@ # Load the KLayout technology, when running in Script mode import pya, os -tech = pya.Technology().create_technology('EBeam') -tech.load(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'EBeam.lyt')) +if not pya.Technology().has_technology('EBeam'): + tech = pya.Technology().create_technology('EBeam') + tech.load(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'EBeam.lyt')) # then import all the technology modules from . import pymacros diff --git a/klayout/EBeam/pymacros/tests/test_All_Library_Cells.py b/klayout/EBeam/pymacros/tests/test_All_Library_Cells.py new file mode 100644 index 00000000..7b7461d5 --- /dev/null +++ b/klayout/EBeam/pymacros/tests/test_All_Library_Cells.py @@ -0,0 +1,53 @@ +# $description: Unit testing: all EBeam libraries' cells +# $show-in-menu +# $group-name: Examples_EBeam +# $menu-path: siepic_menu.exlayout.end +# Unit testing for all library layout fixed cells and PCells + +tech_name = 'EBeam' + +import pya # klayout +import os, sys +import SiEPIC +from SiEPIC._globals import Python_Env +print('KLayout running in mode: %s' % Python_Env) +from SiEPIC.utils.layout import new_layout, floorplan +from SiEPIC.utils import load_klayout_technology +from SiEPIC.scripts import instantiate_all_library_cells, zoom_out, export_layout + +def test_all_library_cells(): + + if Python_Env == 'Script': + # Load the PDK from a folder, e.g, GitHub, when running externally from the KLayout Application + import sys + path = os.path.dirname(os.path.realpath(__file__)) + sys.path.insert(0,os.path.abspath(os.path.join(path, '../../..'))) + import siepic_ebeam_pdk + + + # Create a new layout + topcell, ly = new_layout(tech_name, "UnitTesting", GUI=True, overwrite = True) + + # Instantiate all cells + instantiate_all_library_cells(topcell) + + ''' + # Save the layout + path_out = os.path.dirname(os.path.realpath(__file__)) + ly.write(os.path.join(path_out,'a.gds')) + export_layout(topcell, path_out,'a_static',format='oas') + print('done') + ''' + + # Check if there are any errors + for cell_id in topcell.called_cells(): + c = ly.cell(cell_id) + error_shapes = c.shapes(ly.error_layer()) + for error in error_shapes.each(): + raise Exception('Error in cell: %s, %s' % (c.name, error.text)) + if c.is_empty() or c.bbox().area() == 0: + raise Exception('Empty cell: %s' % c.name) + + +if __name__ == "__main__": + test_all_library_cells() diff --git a/klayout/EBeam/test.py b/klayout/EBeam/test.py deleted file mode 100644 index 7b7549a4..00000000 --- a/klayout/EBeam/test.py +++ /dev/null @@ -1,5 +0,0 @@ -print('test') - -def t(): - print('test.t') -