-
Notifications
You must be signed in to change notification settings - Fork 110
Adding changes to run go test on dev environment #169
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| ## How to execute and clean up unit-tests in sonic-mgmt-common: | ||
| * `make -f makefile.test`: to execute all unit tests | ||
| * `make -f makefile.test clean`: clean up all the generated build artifacts | ||
| * `make -f makefile.test container`: build the test container image. The file `container` contains the container image information | ||
|
|
||
| ## How to build unit-test container with customer | ||
| Note, it is best to `make -f makefile.test clean` before running a test with a customized library. | ||
|
|
||
| ### With a new LIBYANG version in ../../target/debs/bullseye/ | ||
| * `LIBYANG=1.0.74 make -f makefile.test` | ||
| ### With a LIBYANG 1.0.75 in the user home directory | ||
| * `LIBYANG=1.0.74 SONIC_TARGET_DEBS=~ make -f makefile.test` | ||
| ### With a sonic_yang_models in the user home directory | ||
| * `SONIC_TARGET_WHL=~ make -f makefile.test` | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| TOPDIR := $(abspath .) | ||
|
|
||
| .PHONY: test | ||
|
|
||
| LIBYANG_VER ?= 1.0.73 | ||
| LIBYANG_DEBS := libyang_$(LIBYANG_VER)_amd64.deb \ | ||
| libyang-dev_$(LIBYANG_VER)_amd64.deb \ | ||
| libyang-dbgsym_$(LIBYANG_VER)_amd64.deb \ | ||
| libyang-cpp_$(LIBYANG_VER)_amd64.deb | ||
|
|
||
| YANG_MODELS := sonic_yang_models-1.0-py3-none-any.whl | ||
|
|
||
| SONIC_WS ?= $(TOPDIR)/../.. | ||
| SONIC_TARGET_DEBS ?= $(SONIC_WS)/target/debs/bookworm/ | ||
| SONIC_TARGET_WHL ?= $(SONIC_WS)/target/python-wheels/bookworm/ | ||
|
|
||
| CONTAINER_IMG = sonic-mgmt-common-test:$(USER) | ||
|
|
||
| DOCKER_RUN := docker run -it -v $(TOPDIR):$(TOPDIR):rw -v $(SONIC_WS):$(SONIC_WS):rw \ | ||
| -e no_proxy=$(no_proxy) \ | ||
| -e http_proxy=$(http_proxy) \ | ||
| -e https_proxy=$(https_proxy) \ | ||
| -e ftp_proxy=$(ftp_proxy) \ | ||
| $(CONTAINER_IMG) | ||
|
|
||
| test: container | ||
| $(DOCKER_RUN) bash -c "cd $(TOPDIR) && ./run_test.sh && exit 0" | ||
|
|
||
| dev: container | ||
| $(DOCKER_RUN) bash | ||
|
|
||
| container: $(addprefix test/bookworm/, $(LIBYANG_DEBS)) \ | ||
| test/bookworm/$(YANG_MODELS) | ||
| docker build --build-arg no_proxy=$(no_proxy) \ | ||
| --build-arg http_proxy=$(http_proxy) \ | ||
| --build-arg https_proxy=$(https_proxy) \ | ||
| --build-arg ftp_proxy=$(ftp_proxy) \ | ||
| -t $(CONTAINER_IMG) \ | ||
| test/bookworm | ||
| docker inspect $(CONTAINER_IMG) > $@ | ||
|
|
||
| test/bookworm/libyang%$(LIBYANG_VER)_amd64.deb: $(SONIC_TARGET_DEBS)/libyang%$(LIBYANG_VER)_amd64.deb | ||
| cp $< $(@D) | ||
|
|
||
| test/bookworm/$(YANG_MODELS): $(SONIC_TARGET_WHL)/$(YANG_MODELS) | ||
| cp $< $(@D) | ||
|
|
||
| clean: | ||
| rm -f container | ||
| rm -f test/bookworm/libyang*.deb | ||
| rm -f test/bookworm/$(YANG_MODELS) | ||
|
|
||
| for id in $(shell docker ps -a -q --filter ancestor=$(CONTAINER_IMG) --format="{{.ID}}"); do \ | ||
| docker rm $$id; \ | ||
| done | ||
| docker image rm $(CONTAINER_IMG) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,10 +5,15 @@ | |
| # or glob patterns of basenames (like sonic-telemetry*.yang) can be specified. | ||
| # Other sonic yangs referred by these will also be copied. | ||
| # | ||
|
|
||
| ifneq ($(SONIC_YANG_IMPORTS),) | ||
| SONICYANG_IMPORTS = $(shell echo $(SONIC_YANG_IMPORTS)) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What values will be passed through SONIC_YANG_IMPORTS variable?? I don't see any usage.. Also, |
||
| endif | ||
|
|
||
| SONICYANG_IMPORTS += sonic-sflow.yang | ||
| SONICYANG_IMPORTS += sonic-interface.yang | ||
| SONICYANG_IMPORTS += sonic-port.yang | ||
| SONICYANG_IMPORTS += sonic-portchannel.yang | ||
| SONICYANG_IMPORTS += sonic-mclag.yang | ||
| SONICYANG_IMPORTS += sonic-types.yang | ||
| SONICYANG_IMPORTS += sonic-vrf.yang | ||
| SONICYANG_IMPORTS += sonic-vrf.yang | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| #!/bin/bash -x | ||
|
|
||
| # Run sanity tests for sonic-mgmt-common. | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this to run tests locally on the development server? If yes please explore the |
||
| # Assumes sonic-mgmt-common is already compiled and all dependencies | ||
| # are installed. | ||
|
|
||
| STATUS=0 | ||
| DEBDIR=$(realpath debian/sonic-mgmt-common) | ||
|
|
||
| OUTPUT_DIR=./ | ||
| DETAILED_COV=n | ||
| SKIP_BUILD=n | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't see DETAILED_COV and SKIP_BUILD used anywhere. Is this an incomplete script? |
||
| while getopts 'dhto:' opt; do | ||
| case "$opt" in | ||
| t) | ||
| echo "Running test only" | ||
| SKIP_BUILD=y | ||
| ;; | ||
| o) | ||
| echo "Coverage HTML directory" | ||
| OUTPUT_DIR="$OPTARG" | ||
| ;; | ||
| d) | ||
| DETAILED_COV=y | ||
| ;; | ||
| ?|h) | ||
| echo "Usage: $(basename $0) [-t] [-d] [-o dir]" | ||
| exit 100 | ||
| ;; | ||
| esac | ||
| done | ||
|
|
||
| # build debian packages | ||
| INCLUDE_TEST_MODELS=y dpkg-buildpackage -rfakeroot -us -uc -b -j$(nproc) | ||
| if [ "$?" -ne "0" ];then | ||
| echo "Error!!! Compilation failed" | ||
| exit 1 | ||
| fi | ||
|
|
||
| function generate_html_report() { | ||
| /usr/local/go/bin/go tool cover -html=$1 -o ${OUTPUT_DIR}/$1.html | ||
| } | ||
|
|
||
| redis_ready=$(ps aux | grep -ie "redis-server" | grep -ie bin) | ||
| if [ -z "$redis_ready" ]; then | ||
| sudo service redis-server start | ||
| echo "Starting redis-server status: $?" | ||
| else | ||
| echo "redis-server already started: $redis_ready" | ||
| fi | ||
|
|
||
| # Update unixsocket path in database_config.json | ||
| tools/test/dbconfig.py -o ${PWD}/build/tests/database_config.json | ||
| export DB_CONFIG_PATH=${PWD}/build/tests/database_config.json | ||
|
|
||
| # Run CVL tests | ||
| pushd build/tests/cvl | ||
| CVL_SCHEMA_PATH=testdata/schema \ | ||
| ./cvl.test -test.v -alsologtostderr -test.coverprofile coverage.cvl || STATUS=1 | ||
| generate_html_report coverage.cvl | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. All these coverage files will be generated under repo root, right? I don't think there is any cleanup step. Better to use some subdirectory under build directory as OUTPUT_DIR |
||
| popd | ||
|
|
||
| # Run translib tests | ||
| pushd build/tests/translib | ||
| export CVL_SCHEMA_PATH=${DEBDIR}/usr/sbin/schema | ||
| export YANG_MODELS_PATH=${DEBDIR}/usr/models/yang | ||
| ./db.test -test.v -alsologtostderr -test.coverprofile coverage.db || STATUS=2 | ||
| generate_html_report coverage.db | ||
|
|
||
| # Populates test data in essential tables like PORT, DEVICE_METADATA, SWITCH_TABLE, USER_TABLE etc. | ||
| ${PWD}/../../../tools/test/dbinit.py --overwrite | ||
|
|
||
| ./translib.test -test.v -alsologtostderr -test.coverprofile coverage.translib || STATUS=3 | ||
| generate_html_report coverage.translib | ||
|
|
||
| ./testapp.test -test.v -alsologtostderr -test.coverprofile coverage.transformer || STATUS=4 | ||
| ./transformer.test -test.v -alsologtostderr -test.coverprofile coverage.transformer || STATUS=5 | ||
| generate_html_report coverage.transformer | ||
| popd | ||
| exit ${STATUS} | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you move this script to test or tools/test directory? |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| FROM sonicdev-microsoft.azurecr.io:443/sonic-slave-bookworm:latest | ||
|
|
||
| RUN apt-get -y update | ||
| RUN apt-get install -y redis-server | ||
| RUN sed -ri 's/^# unixsocket/unixsocket/' /etc/redis/redis.conf | ||
| RUN sed -ri 's/^unixsocketperm .../unixsocketperm 777/' /etc/redis/redis.conf | ||
| RUN sed -ri 's/redis-server.sock/redis.sock/' /etc/redis/redis.conf | ||
|
|
||
| ARG LIBYANG_VER=1.0.73 | ||
| COPY libyang*${LIBYANG_VER}*.deb /tmp/ | ||
| RUN dpkg -i /tmp/libyang*${LIBYANG_VER}*.deb | ||
|
|
||
| COPY sonic_yang_models-1.0-py3-none-any.whl /tmp/ | ||
| RUN pip3 install /tmp/sonic_yang_models-1.0-py3-none-any.whl |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible generate all outputs under build directory?