From 6f6ea23e7114520fe25245effd4120294841f3a2 Mon Sep 17 00:00:00 2001 From: Pavel Kotucek Date: Mon, 29 Apr 2019 15:58:24 +0200 Subject: Docker build improvements Added small changes to create dev docker image. Fixed checkstyle. Change-Id: I0ea1a0bad114578903073526fa12b84702072e3a Signed-off-by: Pavel Kotucek --- scripts/Dockerfile | 30 ++++++++ scripts/checkstyle.sh | 143 ++++++++++++++++++++++++++++++++++++ scripts/docker.sh | 32 ++++++++ scripts/fix-coding-style.el | 173 ++++++++++++++++++++++++++++++++++++++++++++ scripts/run_test.sh | 46 ++++++++++++ 5 files changed, 424 insertions(+) create mode 100644 scripts/Dockerfile create mode 100755 scripts/checkstyle.sh create mode 100755 scripts/docker.sh create mode 100755 scripts/fix-coding-style.el create mode 100755 scripts/run_test.sh (limited to 'scripts') diff --git a/scripts/Dockerfile b/scripts/Dockerfile new file mode 100644 index 0000000..b07382c --- /dev/null +++ b/scripts/Dockerfile @@ -0,0 +1,30 @@ +FROM ubuntu:18.04 + +# Layer0: Prepare sweetcomb environement by installing sysrepo, netopeer2 & vpp +# Layer1: Install vpp +# Layer2: Install sweetcomb + +#Layer 0 +RUN mkdir -p /opt/dev && apt-get update &&\ + apt-get install -y build-essential sudo +COPY . /opt/dev +WORKDIR /opt/dev +RUN make install-dep && make install-dep-extra +RUN rm -rf /opt/dev/* + +#Layer1 +RUN apt-get install -y \ + sudo curl \ + inetutils-ping \ + && curl -s https://packagecloud.io/install/repositories/fdio/1904/script.deb.sh | sudo bash \ + && apt-get -y --force-yes install vpp libvppinfra* vpp-plugin-* vpp-dev + +RUN apt-get update; \ + apt-get install -y clang-format python3-pip; \ + pip3 install pexpect pyroute2 psutil; + +#Layer2 +COPY . /root/src/sweetcomb +WORKDIR /root/src/sweetcomb + +RUN make install-dep && make build-scvpp && make build-plugins \ No newline at end of file diff --git a/scripts/checkstyle.sh b/scripts/checkstyle.sh new file mode 100755 index 0000000..6091725 --- /dev/null +++ b/scripts/checkstyle.sh @@ -0,0 +1,143 @@ +#!/bin/bash + +# Copyright (c) 2015 Cisco and/or its affiliates. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at: +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +SWEETCOMB_DIR="./" +EXIT_CODE=0 +FIX="0" +FULL="0" +CHECKSTYLED_FILES="" +UNCHECKSTYLED_FILES="" + +# If the user provides --fix, then actually fix things +while true; do + case ${1} in + --fix) + FIX="1" + ;; + --full) + FULL="1" + ;; + esac + shift || break +done + +if [ "${FULL}" == "1" ]; then + FILELIST=$(git ls-tree -r HEAD --name-only) +else + FILELIST=$((git diff HEAD~1.. --name-only; git ls-files -m ) | sort -u) +fi + +# Check to make sure we have indent. Exit if we don't with an error message, +# but don't *fail*. +command -v indent > /dev/null +if [ $? != 0 ]; then + echo "Cound not find required command \"indent\". Checkstyle aborted" + exit ${EXIT_CODE} +fi +indent --version + +# Check to make sure we have clang-format. Exit if we don't with an error +# message, but don't *fail*. +HAVE_CLANG_FORMAT=0 +command -v clang-format > /dev/null +if [ $? != 0 ]; then + echo "Could not find command \"clang-format\"." +else + clang-format --version + x=$(echo "" | clang-format 2>&1) + if [[ "$x" == "" ]]; then + HAVE_CLANG_FORMAT=1 + else + echo "Output produced while formatting empty file (expected empty string):" + echo "$x" + echo "Could not find working \"clang-format\"." + fi +fi + +git status +for i in ${FILELIST}; do + if [ -f ${i} ] && [ ${i} != "scripts/checkstyle.sh" ] && [ ${i} != "scripts/fix-coding-style.el" ]; then + EXTENSION=`basename ${i} | sed 's/^\w\+.//'` + case ${EXTENSION} in + hpp|cpp|cc|hh|c|h) + CMD="clang-format" + if [ ${HAVE_CLANG_FORMAT} == 0 ]; then + echo "C++ file detected. Abort, missing clang-format" + exit ${EXIT_CODE} + fi + ;; + *) + CMD="indent" + continue + ;; + esac + CHECKSTYLED_FILES="${CHECKSTYLED_FILES} ${i}" + if [ ${FIX} == 0 ]; then + if [ "${CMD}" == "clang-format" ] + then + clang-format ${i} > ${i}.out2 + else + indent ${i} -o ${i}.out1 > /dev/null 2>&1 + indent ${i}.out1 -o ${i}.out2 > /dev/null 2>&1 + fi + # Remove trailing whitespace + sed -i -e 's/[[:space:]]*$//' ${i}.out2 + diff -q ${i} ${i}.out2 + else + if [ "${CMD}" == "clang-format" ]; then + clang-format -i ${i} > /dev/null 2>&1 + else + indent ${i} + indent ${i} + fi + # Remove trailing whitespace + sed -i -e 's/[[:space:]]*$//' ${i} + fi + if [ $? != 0 ]; then + EXIT_CODE=1 + echo + echo "Checkstyle failed for ${i}." + if [ "${CMD}" == "clang-format" ]; then + echo "Run clang-format as shown to fix the problem:" + echo "clang-format -i ${SWEETCOMB_DIR}${i}" + else + echo "Run indent (twice!) as shown to fix the problem:" + echo "indent ${SWEETCOMB_DIR}${i}" + echo "indent ${SWEETCOMB_DIR}${i}" + fi + fi + if [ -f ${i}.out1 ]; then + rm ${i}.out1 + fi + if [ -f ${i}.out2 ]; then + rm ${i}.out2 + fi + else + UNCHECKSTYLED_FILES="${UNCHECKSTYLED_FILES} ${i}" + fi +done + +if [ ${EXIT_CODE} == 0 ]; then + echo "*******************************************************************" + echo "* SWEETCOMB CHECKSTYLE SUCCESSFULLY COMPLETED" + echo "*******************************************************************" +else + echo "*******************************************************************" + echo "* SWEETCOMB CHECKSTYLE FAILED" + echo "* CONSULT FAILURE LOG ABOVE" + echo "* NOTE: Running 'scripts/checkstyle.sh --fix' *MAY* fix the issue" + echo "*******************************************************************" +fi +exit ${EXIT_CODE} \ No newline at end of file diff --git a/scripts/docker.sh b/scripts/docker.sh new file mode 100755 index 0000000..3d211e3 --- /dev/null +++ b/scripts/docker.sh @@ -0,0 +1,32 @@ +#!/bin/bash + +# Copyright (c) 2019 PANTHEON.tech. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at: +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +IMAGE="sweetcomb_img" +CONTAINER="sweetcomb" + +echo "Remove previous container and image" +FIND=`docker container ls -a | grep ${CONTAINER}` +if [ -n "${FIND}" ]; then + docker stop ${CONTAINER} + docker rm ${CONTAINER} -f +fi +FIND=`docker images | grep ${IMAGE}` +if [ -n "${FIND}" ]; then + docker rmi ${IMAGE} -f +fi + +echo "Rebuild image and start container" +docker build -t ${IMAGE} -f ./scripts/Dockerfile . \ No newline at end of file diff --git a/scripts/fix-coding-style.el b/scripts/fix-coding-style.el new file mode 100755 index 0000000..2eb1c9e --- /dev/null +++ b/scripts/fix-coding-style.el @@ -0,0 +1,173 @@ +#!/usr/bin/emacs --script + +;;; Copyright (c) 2016 Cisco and/or its affiliates. +;;; Licensed under the Apache License, Version 2.0 (the "License"); +;;; you may not use this file except in compliance with the License. +;;; You may obtain a copy of the License at: +;;; +;;; http://www.apache.org/licenses/LICENSE-2.0 +;;; +;;; Unless required by applicable law or agreed to in writing, software +;;; distributed under the License is distributed on an "AS IS" BASIS, +;;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +;;; See the License for the specific language governing permissions and +;;; limitations under the License. + +;; Insert style boilerplate if it's not already there +;; +;; Breaking the string in half keeps emacs +;; from trying to interpret the local variable +;; settings e.g. when it reads the lisp source code + +(defun insert-style-boilerplate () (interactive) + (save-excursion + (goto-char (point-min)) + (if (eq nil (search-forward "coding-style-patch-verification" + (point-max) t)) + (let ((junk 0)) (goto-char (point-max)) + (insert " +/* + * fd.io coding-style-patch-verification: ON + * + * Local Var" "iables: + * eval: (c-set-style \"gnu\") + * End: + */"))))) + +;; (cons xxx ) means insert xxx at the head of +;; Build a sorted list of *INDENT-OFF* lines, by searching +;; backwards. The initial (setq indent-offset-list nil) +;; results in (cdr ) nil, which makes it a proper list + +(defun find-indent-offs () (interactive) + (save-excursion + (if (boundp 'indent-offset-list) + (makunbound 'indent-offset-list)) + (setq indent-offset-list nil) + (goto-char (point-max)) + (while (search-backward "*INDENT-OFF*" (point-min) t) + (move-beginning-of-line nil) + (setq indent-offset-list (cons (point) indent-offset-list)) + (previous-line)))) + +;; Insert indent-off ... indent-on brackets around +;; a certain xxx_foreach macro, etc. which "indent" +;; completely screws up. Doesn't handle nesting, of which there +;; are few examples (fortunately). + +(defun fix-initializer (what) (interactive) + (find-indent-offs) + (save-excursion + (goto-char (point-min)) + (while (search-forward-regexp what (point-max) t) + (move-beginning-of-line nil) + (previous-line) + (let ((index 0)(pointval 0)) + (while (and (< pointval (point))(elt indent-offset-list index)) + (setq pointval (elt indent-offset-list index)) + (setq index (1+ index))) + (if (not (eq pointval (point))) + (let ((junk 0)) + (next-line) + (open-line 1) + (c-indent-line-or-region) + (insert "/* *INDENT-OFF* */") + (search-forward "{") + (backward-char) + (forward-sexp) + (move-end-of-line nil) + (newline 1) + (c-indent-line-or-region) + (insert "/* *INDENT-ON* */") + (find-indent-offs)) + (search-forward "*INDENT-ON*")))))) + +(defun fix-pool-foreach () (interactive) + (fix-initializer "pool_foreach *(")) + +(defun fix-pool-foreach-index () (interactive) + (fix-initializer "pool_foreach_index *(")) + +(defun fix-hash-foreach () (interactive) + (fix-initializer "hash_foreach *(")) + +(defun fix-hash-foreach-pair () (interactive) + (fix-initializer "hash_foreach_pair *(")) + +(defun fix-hash-foreach-mem () (interactive) + (fix-initializer "hash_foreach_mem *(")) + +(defun fix-clib-fifo-foreach () (interactive) + (fix-initializer "clib_fifo_foreach *(")) + +(defun fix-clib-bitmap-foreach () (interactive) + (fix-initializer "clib_bitmap_foreach *(")) + +(defun fix-foreach-ip-interface-address () (interactive) + (fix-initializer "foreach_ip_interface_address *(")) + +(defun fix-vlib-register-thread () (interactive) + (fix-initializer "VLIB_REGISTER_THREAD *(")) + +(defun fix-vlib-cli-command () (interactive) + (fix-initializer "VLIB_CLI_COMMAND *(")) + +(defun fix-vlib-register-node () (interactive) + (fix-initializer "VLIB_REGISTER_NODE *(")) + +(defun fix-reply-macro2 () (interactive) + (fix-initializer "REPLY_MACRO2 *(")) + +(defun fix-vnet-device-class () (interactive) + (fix-initializer "VNET_DEVICE_CLASS *(")) + +(defun fix-vnet-hw-interface-class () (interactive) + (fix-initializer "VNET_HW_INTERFACE_CLASS *(")) + +(defun fix-clib-packed () (interactive) + (fix-initializer "CLIB_PACKED *(")) +(defun fix-vl-api-packed () (interactive) + (fix-initializer "VL_API_PACKED *(")) + +;; Driver routine which runs the set of functions +;; defined above, as well as the bottom boilerplate function + +(defun fd-io-styleify () (interactive) + (fix-pool-foreach) + (fix-pool-foreach-index) + (fix-hash-foreach) + (fix-hash-foreach-pair) + (fix-hash-foreach-mem) + (fix-foreach-ip-interface-address) + (fix-clib-fifo-foreach) + (fix-clib-bitmap-foreach) + (fix-vlib-register-thread) + (fix-vlib-cli-command) + (fix-vlib-register-node) + (fix-reply-macro2) + (fix-vnet-device-class) + (fix-vnet-hw-interface-class) + (fix-clib-packed) + (fix-vl-api-packed) + (insert-style-boilerplate) + (if (boundp 'indent-offset-list) + (makunbound 'indent-offset-list))) + +;; When run as a script, this sexp +;; walks the list of files supplied on the command line. +;; +;; (elt argv index) returns nil if you M-x eval-buffer +;; or M-x load-file the file, so we won't accidentally +;; evaluate (save-buffers-kill-emacs)... + +(let ((file-index 0)) + (if (elt argv file-index) + (while (elt argv file-index) + (find-file (elt argv file-index)) + (fd-io-styleify) + (message "Done %s..." (elt argv file-index)) + (setq file-index (1+ file-index)))) + (if (> file-index 0) + (let ((junk 0)) + (message "Save and quit...") + (save-buffers-kill-emacs t)))) diff --git a/scripts/run_test.sh b/scripts/run_test.sh new file mode 100755 index 0000000..ca6c6b6 --- /dev/null +++ b/scripts/run_test.sh @@ -0,0 +1,46 @@ +#!/bin/bash + +# Copyright (c) 2019 PANTHEON.tech. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at: +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +IMAGE="sweetcomb_img" +CONTAINER="sweetcomb_test" + +FIND=`docker container ls -a | grep ${CONTAINER}` +if [ -n "${FIND}" ]; then + echo "Remove previous test container" + docker stop ${CONTAINER} > /dev/null + docker rm ${CONTAINER} -f > /dev/null +fi + +FIND=`docker images | grep ${IMAGE}` +if [ -z "${FIND}" ]; then + ./scripts/docker.sh +fi + +echo "Start container" +docker run -id --privileged --name ${CONTAINER} ${IMAGE} +docker cp . ${CONTAINER}:/root/src/sweetcomb +docker exec -it ${CONTAINER} bash -c " + cd /root/src/sweetcomb && + make build-scvpp && + make build-plugins" +if [ "$?" == 0 ]; then + echo "Run tests" + docker exec -it ${CONTAINER} bash -c " + echo -e \"0000\n0000\" | passwd + mkdir /var/log/vpp" +fi + +docker exec -it ${CONTAINER} bash -c "/root/src/sweetcomb/test/run_test.py" \ No newline at end of file -- cgit 1.2.3-korg