diff options
author | 1138-4EB <1138-4EB@users.noreply.github.com> | 2019-08-16 22:07:46 +0200 |
---|---|---|
committer | tgingold <tgingold@users.noreply.github.com> | 2019-08-16 22:07:46 +0200 |
commit | d359d6deb55e5c51707c86263b090fabbc5c41b2 (patch) | |
tree | e916cb1f11ec2687bfedbd6ad02f08c3a5b068db | |
parent | c924837dd7f9164aabb37983fb036ee34a9f1e40 (diff) | |
download | ghdl-yosys-plugin-d359d6deb55e5c51707c86263b090fabbc5c41b2.tar.gz ghdl-yosys-plugin-d359d6deb55e5c51707c86263b090fabbc5c41b2.tar.bz2 ghdl-yosys-plugin-d359d6deb55e5c51707c86263b090fabbc5c41b2.zip |
Run testsuite in Travis CI with docker images (#31)
* makefile: use '--build' shortcut to build ghdl.so
* move: rename subdir 'ghdl' to 'src'
* travis: add travis config file, build script and utils script
* testsuite: do not call ghdl explicitly
* readme: update
-rw-r--r-- | .travis.yml | 5 | ||||
-rw-r--r-- | Makefile | 8 | ||||
-rw-r--r-- | README.md | 123 | ||||
-rw-r--r-- | src/Makefile.inc (renamed from ghdl/Makefile.inc) | 0 | ||||
-rw-r--r-- | src/ghdl.cc (renamed from ghdl/ghdl.cc) | 0 | ||||
-rwxr-xr-x | testsuite/issue11/testsuite.sh | 17 | ||||
-rw-r--r-- | testsuite/issue4/no_vector.vhdl (renamed from testsuite/issue4/novector.vhdl) | 0 | ||||
-rwxr-xr-x | testsuite/issue4/testsuite.sh | 11 | ||||
-rwxr-xr-x | testsuite/issue6/testsuite.sh | 3 | ||||
-rwxr-xr-x | testsuite/issue7/testsuite.sh | 9 | ||||
-rwxr-xr-x | testsuite/test-ice40hx8k/testsuite.sh | 8 | ||||
-rwxr-xr-x | testsuite/test-icestick/testsuite.sh | 20 | ||||
-rwxr-xr-x | testsuite/test-icezum/testsuite.sh | 15 | ||||
-rw-r--r-- | testsuite/testenv.sh | 16 | ||||
-rwxr-xr-x | testsuite/testsuite.sh | 14 | ||||
-rwxr-xr-x | travis.sh | 77 | ||||
-rw-r--r-- | utils.sh | 72 |
17 files changed, 275 insertions, 123 deletions
diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..9940b13 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,5 @@ +os: linux +services: docker +language: minimal +install: skip +script: ./travis.sh @@ -16,15 +16,13 @@ ALL_LDFLAGS=$(LIBGHDL_LIB) -Wl,-rpath,$(dir $(LIBGHDL_LIB)) $(LDFLAGS) ALL_CFLAGS=-fPIC -DYOSYS_ENABLE_GHDL -I$(LIBGHDL_INC) $(CFLAGS) -COMPILE=$(YOSYS_CONFIG) --exec --cxx - all: ghdl.$(SOEXT) ghdl.$(SOEXT): ghdl.o - $(COMPILE) -o $@ -shared $< $(ALL_LDFLAGS) --ldflags --ldlibs + $(YOSYS_CONFIG) --build $@ $< -shared $(ALL_LDFLAGS) -ghdl.o: ghdl/ghdl.cc - $(COMPILE) -c --cxxflags -o $@ $< $(ALL_CFLAGS) +ghdl.o: src/ghdl.cc + $(YOSYS_CONFIG) --exec --cxx -c --cxxflags -o $@ $< $(ALL_CFLAGS) clean: force $(RM) -f ghdl.$(SOEXT) ghdl.o @@ -1,90 +1,123 @@ -# ghdlsynth-beta -VHDL synthesis (based on ghdl) +# ghdlsynth-beta: VHDL synthesis (based on [ghdl](https://github.com/ghdl/ghdl) and [yosys](https://github.com/YosysHQ/yosys)) -This is experimental and work in progress! +**This is experimental and work in progress!** -TODO: Explain purpose of program. +> TODO: explain purpose of program. +> +> - What is the relationship with GHDL? Is it going to be integrated in GHDL once it is fully featured? +> - What kind of VHDL do we want to support? (GHDL fully supports the 1987, 1993, 2002 versions of the IEEE 1076 VHDL standard, and partially the latest 2008 revision, according to the website) +>- Explain expected input and outputs. +>- Create table with features of VHDL that are supported, WIP and pending. -What is the relationship with GHDL? Is it going to be integrated in GHDL once it is fully featured? +## Build as a module (shared library) -What kind of VHDL do we want to support? (GHDL fully supports the 1987, 1993, 2002 versions of the IEEE 1076 VHDL standard, and partially the latest 2008 revision, according to the website) +- Get and install [yosys](https://github.com/YosysHQ/yosys). +- Get sources, build and install [ghdl](https://github.com/ghdl/ghdl). Configure ghdl using at least `--enable-libghdl` and `--enable-synth`: -Explain expected input and outputs. - -Create table with features of VHDL that are supported, WIP and pending. - -## How to build as a module - -Get and install yosys. - -Get ghdl from github. - -Get the latest version of GNAT: -```sh -$ sudo apt-get install gnat-8 -``` - -Configure ghdl using at least `--enable-libghdl` and `--enable-synth`. -Build and install. ```sh $ ./configure --enable-libghdl --enable-synth $ make $ make install ``` -From ghdlsynth-beta: +> NOTE: GHDL must be built with the latest version of GNAT (`gnat-8`). -```sh -$ make -``` +> HINT: The default build prefix is `/usr/local`. Sudo permission might be required to install tools there. + +- Get and build ghdlsynth-beta: -Note that if ghdl has been installed in a non-standard way or in a -directory that is not in your PATH, you must give the name of the ghdl -executable: ```sh -$ make GHDL=/my/path/to/ghdl +make ``` -This generates `ghdl.so`, which can be used directly: +> HINT: If ghdl is not available in the PATH, set `GHDL` explicitly, e.g.: `make GHDL=/my/path/to/ghdl`. + +The output is a shared library (`ghdl.so` on GNU/Linux), which can be used directly: ```sh $ yosys -m ghdl.so ``` -To install the module: +To install the module, the library must be copied to `YOSYS_PREFIX/share/yosys/plugins/ghdl.so`, where `YOSYS_PREFIX` is the installation path of yosys. This can be achieved through a make target: ```sh make install ``` -## How to build as part of yosys (not recommended) +Alternatively, the shared library can be copied/installed along with ghdl: + +```sh +cp ghdl.so "$GHDL_PREFIX/lib/ghdl_yosys.so" + +yosys-config --exec mkdir -p --datdir/plugins +yosys-config --exec ln -s "$GHDL_PREFIX/lib/ghdl_yosys.so" --datdir/plugins/ghdl.so +``` + +## Build as part of yosys (not recommended) -Get and build ghdl as in the previous section. +- Get and build ghdl as in the previous section. -Get yosys. +- Get [yosys](https://github.com/YosysHQ/yosys) sources. -From ghdlsynth-beta: -Patch yosys sources using `yosys.diff` -Copy the `ghdl/` directory in `yosys/frontends` +- Get ghdlsynth-beta and: + - Patch yosys sources using `yosys.diff`. + - Copy `src/*` to `yosys/frontends/ghdl`. + - Configure yosys by adding (to) `Makefile.conf`: -### Configure yosys. -In Makefile.conf, add: ```makefile ENABLE_GHDL := 1 GHDL_DIR := <ghdl install dir> ``` -Build yosys. +- Build and install yosys. -### How to use +## Usage -Example for icestick: +Example for icestick, using ghdl, yosys, arachne-pnr and icestorm: ```sh +# Analyse VHDL sources ghdl -a leds.vhdl ghdl -a spin1.vhdl -yosys -p 'ghdl leds; synth_ice40 -blif leds.blif' + +# Synthesize the design. +# NOTE: if ghdl is built as a module, set MODULE to '-m ghdl' or '-m path/to/ghdl.so' +yosys $MODULE -p 'ghdl leds; synth_ice40 -blif leds.blif' + +# P&R arachne-pnr -d 1k -o leds.asc -p leds.pcf leds.blif + +# Generate bitstream icepack leds.asc leds.bin + +# Program FPGA +iceprog leds.bin +``` + +Alternatively, it is possible to analyze, elaborate and synthesize VHDL sources at once, instead of calling ghdl and yosys in two steps. In this example: `yosys $MODULE -p 'ghdl leds.vhdl spin1.vhdl -e leds; synth_ice40 -blif leds.blif`. + +## Docker + +Docker image [`ghdl/synth:beta`](https://cloud.docker.com/u/ghdl/repository/docker/ghdl/synth/tags) includes yosys, and the ghdl module (shared library). These can be used to synthesize designs straightaway. For example: + +```sh +docker run --rm -t \ + -v $(pwd):/src \ + -w /src \ + ghdl/synth:beta \ + yosys -m ghdl -p 'ghdl icestick/leds.vhdl icestick/blink.vhdl -e leds; synth_ice40 -blif leds.blif' +``` + +Furthermore, the snippet above can be extended in order to P&R the design with [nextpnr](https://github.com/YosysHQ/nextpnr) and generate a bitstream with [icestorm](https://github.com/cliffordwolf/icestorm) tools: + +```sh +DOCKER_CMD="$(command -v winpty) docker run --rm -it -v /$(pwd)://wrk -w //wrk" + +$DOCKER_CMD ghdl/synth:beta yosys -m ghdl -p 'ghdl leds.vhdl rotate4.vhdl -e leds; synth_ice40 -json leds.json' +$DOCKER_CMD ghdl/synth:nextpnr nextpnr-ice40 --hx1k --json leds.json --pcf leds.pcf --asc leds.asc +$DOCKER_CMD ghdl/synth:icestorm icepack leds.asc leds.bin + iceprog leds.bin ``` + +> NOTE: on GNU/Linux, it should be possible to use `iceprog` through `ghdl/synth:icestorm`. On Windows and macOS, accessing USB/COM ports of the host from containers seems not to be supported yet. Therefore, `iceprog` is required to be available on the host. diff --git a/ghdl/Makefile.inc b/src/Makefile.inc index a68e7d1..a68e7d1 100644 --- a/ghdl/Makefile.inc +++ b/src/Makefile.inc diff --git a/ghdl/ghdl.cc b/src/ghdl.cc index e92e7e9..e92e7e9 100644 --- a/ghdl/ghdl.cc +++ b/src/ghdl.cc diff --git a/testsuite/issue11/testsuite.sh b/testsuite/issue11/testsuite.sh index d0f9360..e281ee9 100755 --- a/testsuite/issue11/testsuite.sh +++ b/testsuite/issue11/testsuite.sh @@ -2,19 +2,8 @@ . ../testenv.sh -analyze test_or.vhdl -synth test_or - -analyze test_xor.vhdl -synth test_xor - -analyze test_nor.vhdl -synth test_nor - -analyze test_nand.vhdl -synth test_nand - -analyze test_xnor.vhdl -synth test_xnor +for f in or xor nor nand xnor; do + synth "test_${f}.vhdl -e test_${f}" +done clean diff --git a/testsuite/issue4/novector.vhdl b/testsuite/issue4/no_vector.vhdl index a3c2c46..a3c2c46 100644 --- a/testsuite/issue4/novector.vhdl +++ b/testsuite/issue4/no_vector.vhdl diff --git a/testsuite/issue4/testsuite.sh b/testsuite/issue4/testsuite.sh index 9eaedbc..49ead4d 100755 --- a/testsuite/issue4/testsuite.sh +++ b/testsuite/issue4/testsuite.sh @@ -2,13 +2,8 @@ . ../testenv.sh -analyze novector.vhdl -synth no_vector - -analyze counter8.vhdl -synth counter8 - -analyze vector.vhdl -synth vector +for f in no_vector counter8 vector; do + synth "${f}.vhdl -e ${f}" +done clean diff --git a/testsuite/issue6/testsuite.sh b/testsuite/issue6/testsuite.sh index 802618d..c1b6e25 100755 --- a/testsuite/issue6/testsuite.sh +++ b/testsuite/issue6/testsuite.sh @@ -2,7 +2,6 @@ . ../testenv.sh -analyze vector.vhdl -synth vector +synth 'vector.vhdl -e vector' clean diff --git a/testsuite/issue7/testsuite.sh b/testsuite/issue7/testsuite.sh index 939f28a..bdafcca 100755 --- a/testsuite/issue7/testsuite.sh +++ b/testsuite/issue7/testsuite.sh @@ -2,13 +2,10 @@ . ../testenv.sh -analyze ref.vhdl -run_yosys -q -p "ghdl vector ref; write_verilog ref.v" +run_yosys -Q -q -p "ghdl ref.vhdl -e vector ref; write_verilog ref.v" +run_yosys -Q -q -p "ghdl ref.vhdl vector.vhdl -e vector synth; write_verilog vector.v" -analyze vector.vhdl -run_yosys -q -p "ghdl vector synth; write_verilog vector.v" - -run_yosys -p ' +run_yosys -Q -p ' read_verilog ref.v rename vector ref diff --git a/testsuite/test-ice40hx8k/testsuite.sh b/testsuite/test-ice40hx8k/testsuite.sh index be1bf88..a14dcf8 100755 --- a/testsuite/test-ice40hx8k/testsuite.sh +++ b/testsuite/test-ice40hx8k/testsuite.sh @@ -2,11 +2,9 @@ . ../testenv.sh -analyze ../../ice40hx8k/leds.vhdl -analyze ../../ice40hx8k/spin1.vhdl -synth leds +src=../../ice40hx8k -analyze ../../ice40hx8k/spin2.vhdl -synth leds +synth "$src/leds.vhdl $src/spin1.vhdl -e leds" +synth "$src/leds.vhdl $src/spin2.vhdl -e leds" clean diff --git a/testsuite/test-icestick/testsuite.sh b/testsuite/test-icestick/testsuite.sh index 889f5b3..99bf9eb 100755 --- a/testsuite/test-icestick/testsuite.sh +++ b/testsuite/test-icestick/testsuite.sh @@ -4,24 +4,10 @@ src=../../icestick -analyze $src/leds.vhdl +# spin2 -files="fixed1.vhdl - fixed1.vhdl - blink.vhdl - multi1.vhdl - multi2.vhdl - spin1.vhdl - rotate1.vhdl - rotate2.vhdl - rotate3.vhdl - rotate4.vhdl -" -# spin2.vhdl - -for f in $files; do - analyze $src/$f - synth leds +for f in fixed1 blink multi1 multi2 spin1 rotate1 rotate2 rotate3 rotate4; do + synth "$src/leds.vhdl $src/${f}.vhdl -e leds" done clean diff --git a/testsuite/test-icezum/testsuite.sh b/testsuite/test-icezum/testsuite.sh index a3a71e5..3b6f620 100755 --- a/testsuite/test-icezum/testsuite.sh +++ b/testsuite/test-icezum/testsuite.sh @@ -2,16 +2,11 @@ . ../testenv.sh -analyze ../../icezum/led_on/led_on.vhdl -synth led_on +src=../../icezum -analyze ../../icezum/blink/blink.vhdl -synth blink - -analyze ../../icezum/pushbutton/pushbutton.vhdl -synth pushbutton - -analyze ../../icezum/pushbutton_and/pushbutton_and.vhdl -synth pushbutton_and +synth "$src/led_on/led_on.vhdl -e led_on" +synth "$src/blink/blink.vhdl -e blink" +synth "$src/pushbutton/pushbutton.vhdl -e pushbutton" +synth "$src/pushbutton_and/pushbutton_and.vhdl -e pushbutton_and" clean diff --git a/testsuite/testenv.sh b/testsuite/testenv.sh index 152f986..23c67e0 100644 --- a/testsuite/testenv.sh +++ b/testsuite/testenv.sh @@ -2,6 +2,8 @@ set -e +. ../../utils.sh + if [ x"$GHDL" = x ]; then GHDL=ghdl fi @@ -12,30 +14,32 @@ fi cmd () { - echo "$@" + echo "ยท $@" "$@" } run_yosys () { - cmd $YOSYS -Q "$@" + cmd $YOSYS "$@" } analyze () { - echo "analyze $@" + printf "${ANSI_BLUE}Analyze $@ $ANSI_NOCOLOR\n" cmd "$GHDL" -a $GHDL_STD_FLAGS $GHDL_FLAGS $@ } synth () { - echo "synthesize $@" - run_yosys -q -p "ghdl $@; synth_ice40 -blif out.blif" + travis_start "synth" "Synthesize $@" + run_yosys -p "ghdl $@; synth_ice40 -blif out.blif" + travis_finish "synth" } clean () { - echo "Remove work library" + travis_start "rm" "Remove work library" "$GHDL" --remove $GHDL_STD_FLAGS rm -f out.blif + travis_finish "rm" } diff --git a/testsuite/testsuite.sh b/testsuite/testsuite.sh index a2bfad8..943c66e 100755 --- a/testsuite/testsuite.sh +++ b/testsuite/testsuite.sh @@ -1,20 +1,24 @@ #!/bin/sh +cd "$(dirname $0)" +. ../utils.sh + for d in */; do if [ -f $d/testsuite.sh ]; then - echo "############ $d" + travis_start "test" "$d" "$ANSI_CYAN" cd $d if ./testsuite.sh; then - echo "OK" + printf "${ANSI_GREEN}OK$ANSI_NOCOLOR\n" else - echo "FAILED!" + printf "${ANSI_RED}FAILED!$ANSI_NOCOLOR\n" exit 1 fi cd .. + travis_finish "test" else - echo "#### Skip $d (no testsuite.sh)" + printf "${ANSI_YELLOW}Skip $d (no testsuite.sh)$ANSI_NOCOLOR\n" fi done -echo "All tests are OK" +printf "${ANSI_GREEN}All tests are OK$ANSI_NOCOLOR\n" exit 0 diff --git a/travis.sh b/travis.sh new file mode 100755 index 0000000..086f497 --- /dev/null +++ b/travis.sh @@ -0,0 +1,77 @@ +#!/bin/sh + +set -e + +cd "$(dirname $0)" +. ./utils.sh + +prefix='//opt/ghdl' + +#-- +travis_start "ghdl" "[Build] ghdl/synth:latest" "$ANSI_MAGENTA" + +case "$TRAVIS_COMMIT_MESSAGE" in + "*[stable]*") + echo "IS_STABLE" + GHDL_URL="https://github.com/ghdl/ghdl/archive/9d61a62f96dc4897dadbf88f5f4ee199d20e0f8f.tar.gz" + ;; + *) + echo "IS_MASTER" + GHDL_URL="https://codeload.github.com/ghdl/ghdl/tar.gz/master" + ;; +esac +echo "GHDL_URL: $GHDL_URL" + +docker build -t ghdl/synth:latest - <<-EOF +FROM ghdl/build:buster-mcode AS build + +RUN apt-get update -qq \ + && DEBIAN_FRONTEND=noninteractive apt-get -y install --no-install-recommends \ + ca-certificates \ + curl \ + && apt-get autoclean && apt-get clean && apt-get -y autoremove \ + && update-ca-certificates \ + && rm -rf /var/lib/apt/lists + +RUN mkdir -p ghdl && cd ghdl \ + && curl -fsSL "$GHDL_URL" | tar xzf - --strip-components=1 \ + && ./configure --prefix="$prefix" --enable-libghdl --enable-synth \ + && make all \ + && make install + +FROM ghdl/run:buster-mcode +COPY --from=build $prefix $prefix +ENV PATH $prefix/bin:\$PATH +EOF + +travis_finish "ghdl" +#-- +travis_start "ghdlsynth" "[Build] ghdl/synth:beta" "$ANSI_MAGENTA" + +docker build -t ghdl/synth:beta . -f- <<-EOF +FROM ghdl/synth:yosys-gnat AS build +COPY --from=ghdl/synth:latest $prefix $prefix +COPY . /ghdlsynth + +RUN cd /ghdlsynth \ + && export PATH=\$PATH:$prefix/bin \ + && make \ + && cp ghdl.so $prefix/lib/ghdl_yosys.so + +FROM ghdl/synth:yosys-gnat +COPY --from=build $prefix $prefix +ENV PATH $prefix/bin:\$PATH +RUN yosys-config --exec mkdir -p --datdir/plugins \ + && yosys-config --exec ln -s $prefix/lib/ghdl_yosys.so --datdir/plugins/ghdl.so +EOF + +travis_finish "ghdlsynth" +#--- +travis_start "testsuite" "[Test] testsuite" "$ANSI_MAGENTA" + +docker run --rm -t -e TRAVIS=$TRAVIS -v /$(pwd)://src -w //src -e YOSYS='yosys -m ghdl' ghdl/synth:beta bash -c "$(cat <<EOF +./testsuite/testsuite.sh +EOF +)" + +travis_finish "testsuite" diff --git a/utils.sh b/utils.sh new file mode 100644 index 0000000..9bbcb47 --- /dev/null +++ b/utils.sh @@ -0,0 +1,72 @@ +# Utils for pretty printing logs + +enable_color() { + ENABLECOLOR='-c ' + ANSI_RED="\033[31m" + ANSI_GREEN="\033[32m" + ANSI_YELLOW="\033[33m" + ANSI_BLUE="\033[34m" + ANSI_MAGENTA="\033[35m" + ANSI_CYAN="\033[36;1m" + ANSI_DARKCYAN="\033[36m" + ANSI_NOCOLOR="\033[0m" +} + +disable_color() { unset ENABLECOLOR ANSI_RED ANSI_GREEN ANSI_YELLOW ANSI_BLUE ANSI_MAGENTA ANSI_CYAN ANSI_DARKCYAN ANSI_NOCOLOR; } + +enable_color + +#-- + +print_start() { + COL="$ANSI_BLUE" + if [ "x$3" != "x" ]; then + COL="$3" + fi + printf "$COL> $2$ANSI_NOCOLOR\n" +} + +travis_start () { + print_start "$@" +} +travis_finish () { + : +} + +[ -n "$TRAVIS" ] && { + # This is a trimmed down copy of + # https://github.com/travis-ci/travis-build/blob/master/lib/travis/build/templates/header.sh + travis_time_start() { + # `date +%N` returns the date in nanoseconds. It is used as a replacement for $RANDOM, which is only available in bash. + travis_timer_id=`date +%N` + travis_start_time=$(travis_nanoseconds) + echo "travis_time:start:$travis_timer_id" + } + travis_time_finish() { + travis_end_time=$(travis_nanoseconds) + local duration=$(($travis_end_time-$travis_start_time)) + echo "travis_time:end:$travis_timer_id:start=$travis_start_time,finish=$travis_end_time,duration=$duration" + } + + if [ "$TRAVIS_OS_NAME" = "osx" ]; then + travis_nanoseconds() { + date -u '+%s000000000' + } + else + travis_nanoseconds() { + date -u '+%s%N' + } + fi + + travis_start () { + echo "travis_fold:start:$1" + travis_time_start + print_start "$@" + } + + travis_finish () { + travis_time_finish + echo "travis_fold:end:$1" + } + +} || echo "INFO: not in Travis CI" |