diff --git a/apps/minimal/tests/cocotb/prepare.sh b/apps/minimal/tests/cocotb/prepare.sh index 8f9ade14c..27fb6cdee 100755 --- a/apps/minimal/tests/cocotb/prepare.sh +++ b/apps/minimal/tests/cocotb/prepare.sh @@ -1,26 +1,9 @@ #!/bin/sh -OFM_PATH=../../../../ +NDK_FPGA_PATH=../../../.. +source $NDK_FPGA_PATH/env.sh -#swbase=../../../swbase/ -swbase=git+https://github.com/CESNET/ndk-sw.git#subdirectory= +ndk_fpga_venv_prepare "venv-cocotb" -PKG_PYNFB=${swbase}pynfb/ -PKG_LIBNFBEXT_PYTHON=${swbase}ext/libnfb_ext_python/ -PKG_COCOTBEXT_OFM=$OFM_PATH/python/cocotbext/ - -# Python virtual environment -python -m venv venv-cocotb -source venv-cocotb/bin/activate - -python -m pip install cython wheel setuptools -python -m pip install pylibfdt fdt -python -m pip install scapy -python -m pip wheel -w ./cocotbwheels $PKG_PYNFB -python -m pip install --find-links ./cocotbwheels nfb -python -m pip install --find-links ./cocotbwheels $PKG_LIBNFBEXT_PYTHON -python -m pip install $PKG_COCOTBEXT_OFM - -echo "" -echo "Now activate environment with:" -echo "source venv-cocotb/bin/activate" +pip install . +#pip install "cocotbext-ofm[nfb]@$NDK_FPGA_COCOTBEXT_OFM_URL" diff --git a/apps/minimal/tests/cocotb/pyproject.toml b/apps/minimal/tests/cocotb/pyproject.toml new file mode 100644 index 000000000..e19b41831 --- /dev/null +++ b/apps/minimal/tests/cocotb/pyproject.toml @@ -0,0 +1,10 @@ +[project] +name = "cocotb-ndk-minimal-test-toplevel" +version = "0.1.0" +dependencies = [ + "cocotbext-ofm[nfb] @ ${NDK_FPGA_COCOTBEXT_OFM_URL}", +] + +[build-system] +requires = ["pdm-backend"] +build-backend = "pdm.backend" diff --git a/apps/minimal/tests/cocotb/top-level-sim.jenkinsfile b/apps/minimal/tests/cocotb/top-level-sim.jenkinsfile index 49056583a..5973d30c2 100644 --- a/apps/minimal/tests/cocotb/top-level-sim.jenkinsfile +++ b/apps/minimal/tests/cocotb/top-level-sim.jenkinsfile @@ -27,13 +27,8 @@ def CARDS = ["alveo-u200", "alveo-u55c", "vcu118", "ia-420f", "n6010", "fb2cghh" node("preklad") { cleanWs() - def swbase = "ndk-sw" checkout scm - stage("Clone required repository") { - sh "git clone https://github.com/CESNET/ndk-sw.git" - } - if (params.nightly != null && params.nightly == true) { stage("Prepare for nightly build") { sh "(cd extra/nfb-200g2ql; git checkout main)" @@ -41,17 +36,11 @@ node("preklad") { } } - sh "python3.9 -m venv venv-cocotb" - stage("Prepare environment") { sh """ - source venv-cocotb/bin/activate - python3.9 -m pip install cython wheel - python3.9 -m pip install pylibfdt fdt - python3.9 -m pip wheel -w ./cocotbwheels ${swbase}/pynfb/ - python3.9 -m pip install --find-links ./cocotbwheels nfb - python3.9 -m pip install --find-links ./cocotbwheels ${swbase}/ext/libnfb_ext_python/ - python3.9 -m pip install python/cocotbext/ + source ./env.sh + ndk_fpga_venv_prepare "venv-cocotb" + pip install apps/minimal/tests/cocotb """ } diff --git a/build/common.sh b/build/common.sh new file mode 100644 index 000000000..dfbd31109 --- /dev/null +++ b/build/common.sh @@ -0,0 +1,12 @@ +# Common functions +function ndk_fpga_venv_prepare { + if [ -z "$1" ]; then + VENV_NAME="venv-cocotb" + else + VENV_NAME="$1" + fi + + echo "Creating virtual environment '$VENV_NAME'" + python -m venv $VENV_NAME + source $VENV_NAME/bin/activate +} diff --git a/core/cocotb/prepare.sh b/core/cocotb/prepare.sh deleted file mode 100755 index 3bfb13e3b..000000000 --- a/core/cocotb/prepare.sh +++ /dev/null @@ -1,28 +0,0 @@ -#!/bin/sh -# Example script for preparing ndk-app repository to run top-level cocotb simulation -# Run it once in the build/CARD folder ! - -# Check base folder -ls ../../ndk/core/intel/cocotb/examples/cocotb_test.py > /dev/null -if [ $! ]; then - echo "Run this script in the build/CARD folder!" - exit 1 -fi - -# These commands already done on preklad machines: -# pip3 install cocotb -# pip3 install cocotb-bus -# pip3 install fdt -# git clone https://github.com/dgibson/dtc.git --branch v1.6.0 -# (cd dtc; make; cd pylibfdt; python3.9 setup.py install --user) - -# Install cocotbext-ofm and its cocotbext.axi4stream dependency -pip3 install git+https://github.com/martinspinler/cocotbext-axi4stream.git#egg=cocotbext.axi4stream -U -pip3 install git+ssh://git@gitlab.liberouter.org/ndk/cocotbext.git#egg=cocotbext-ofm -U - -# Use example test -cp ../../ndk/core/intel/cocotb/examples/cocotb_test* ./ - -# Run simulation: -# make TARGET=cocotb -echo "Now run simulation with command: make TARGET=cocotb" diff --git a/core/cocotb/requirements.txt b/core/cocotb/requirements.txt deleted file mode 100644 index d1e585656..000000000 --- a/core/cocotb/requirements.txt +++ /dev/null @@ -1,2 +0,0 @@ -git+https://github.com/martinspinler/cocotbext-axi4stream.git#egg=cocotbext.axi4stream -git+ssh://git@gitlab.liberouter.org/ndk/cocotbext-ofm.git#egg=cocotbext-ofm diff --git a/env.sh b/env.sh new file mode 100644 index 000000000..9c208165b --- /dev/null +++ b/env.sh @@ -0,0 +1,22 @@ +#!/bin/sh +if [ -z "${NDK_FPGA_PATH}" ]; then + NDK_FPGA_PATH=$(dirname "${BASH_SOURCE[0]}") +fi + +source $NDK_FPGA_PATH/build/common.sh + + +# REALPATHs are necessary for local Python packages based on PDM +NDK_FPGA_REALPATH=$(realpath $NDK_FPGA_PATH) + +# #################################################################### +# Default package paths + +# OFM extension for cocotb +export NDK_FPGA_COCOTBEXT_OFM_URL="file://${NDK_FPGA_REALPATH}/python/cocotbext/" + +# NDK software Python packages are dependencies of cocotbext-ofm[nfb] +export NDK_SW_PYTHON_URL="git+https://github.com/CESNET/ndk-sw.git#subdirectory=" +# NDK software alternative path for local ndk-sw repository +#NDK_SW_REALPATH=$(realpath $NDK_FPGA_PATH/../swbase) +#NDK_SW_PYTHON_URL="file:///$(realpath $NDK_SW_PATH)/" diff --git a/python/cocotbext/pyproject.toml b/python/cocotbext/pyproject.toml new file mode 100644 index 000000000..6a6d5993e --- /dev/null +++ b/python/cocotbext/pyproject.toml @@ -0,0 +1,23 @@ +[project] +name = "cocotbext-ofm" +version = "0.1.0" +dependencies = [ + "cocotb", + "cocotb-bus", +] + +[project.optional-dependencies] +nfb = [ + "pylibfdt", + "nfb @ ${NDK_SW_PYTHON_URL}pynfb", + "libnfb-ext-python @ ${NDK_SW_PYTHON_URL}ext/libnfb_ext_python", +] + +[build-system] +requires = [ + "pdm-backend", +] +build-backend = "pdm.backend" + +[tool.pdm.build] +includes = ["cocotbext"] diff --git a/python/cocotbext/setup.py b/python/cocotbext/setup.py index 6a7afe961..e32476360 100644 --- a/python/cocotbext/setup.py +++ b/python/cocotbext/setup.py @@ -11,7 +11,7 @@ keywords=['python'], packages=find_namespace_packages(include=["cocotbext.*"]), - install_requires=["cocotb", "cocotb-bus"], + install_requires=["cocotb", "cocotb-bus", "pylibfdt"], python_requires=">=3.5", classifiers=[ "Programming Language :: Python :: 3",