aboutsummaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorqchang <qing.chang1@huawei.com>2018-03-08 17:39:22 -0800
committerqchang <qing.chang1@huawei.com>2018-03-08 17:39:22 -0800
commit697ade6190b23c80e7f60963983786e679759393 (patch)
treedd9782d1e936b8342163b26795e23571d4b1b415 /scripts
parent71a4e2f34afa8018426f0e830050e50a1de6d375 (diff)
dmm initial commit
Change-Id: I049ee277cf4efdb83f9c2ac439365fcd421c159b Signed-off-by: qchang <qing.chang1@huawei.com>
Diffstat (limited to 'scripts')
-rw-r--r--scripts/README.md14
-rw-r--r--scripts/build.sh120
-rw-r--r--scripts/checkstyle.sh203
-rw-r--r--scripts/header.template16
-rw-r--r--scripts/header2.template16
-rw-r--r--scripts/lic.sh88
-rw-r--r--scripts/remove_header.awk63
-rw-r--r--scripts/replace_header.sh27
8 files changed, 547 insertions, 0 deletions
diff --git a/scripts/README.md b/scripts/README.md
new file mode 100644
index 0000000..d6c2bdc
--- /dev/null
+++ b/scripts/README.md
@@ -0,0 +1,14 @@
+To run checkstyle :
+./checkstyle.sh [-options]
+
+To modify license:
+./lic.sh
+
+from
+ CPUB(lwip_writev)
+ NSTACK_CAL_FUN(fdInf->ops, writev, (fdInf->rlfd, iov, iovcnt), size);
+ CPUE(lwip_writev)
+to
+ CPUB(writev)
+ NSTACK_CAL_FUN(fdInf->ops, writev, (fdInf->rlfd, iov, iovcnt), size);
+ CPUE(writev) \ No newline at end of file
diff --git a/scripts/build.sh b/scripts/build.sh
new file mode 100644
index 0000000..07bbe0c
--- /dev/null
+++ b/scripts/build.sh
@@ -0,0 +1,120 @@
+#########################################################################
+#
+# Copyright (c) 2018 Huawei Technologies Co.,Ltd.
+# 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.
+#########################################################################
+#!/bin/bash
+
+DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
+BUILD_DIR=${DIR}/../build
+LIB_PATH=${DIR}/../release/lib64
+
+#DPDK download path
+DPDK_DOWNLOAD_PATH=/root/dpdk
+
+#dpdk installation path
+DPDK_INSTALL_PATH=/root/dpdk_install/tmp
+
+#set and check the environment for Ubuntu
+#set env
+apt-get install git cmake gcc g++ automake libtool wget lsof lshw pciutils net-tools tcpdump
+
+#check env
+isInFile=$(cat /etc/default/grub | grep -c "default_hugepagesz=1G hugepagesz=1G hugepages=8")
+if [ $isInFile -eq 0 ]; then
+ echo "hugepage need to be set, set it by doing"
+ echo "1. vi /etc/default/grub "
+ echo "2. add the line GRUB_CMDLINE_LINUX_DEFAULT="default_hugepagesz=1G hugepagesz=1G hugepages=8" "
+ echo "3. perform " update-grub " "
+ echo "4. reboot"
+ exit
+else
+ echo "hugepage has been set already....."
+fi
+
+#DPDK will be having dependancy on linux headers
+apt-get install git build-essential linux-headers-`uname -r`
+
+hugepageTotal=$(cat /proc/meminfo | grep -c "HugePages_Total: 0")
+if [ $hugepageTotal -ne 0 ]; then
+ echo "HugePages_Total is zero"
+ exit
+fi
+
+hugepageFree=$(cat /proc/meminfo | grep -c "HugePages_Free: 0")
+if [ $hugepageFree -ne 0 ]; then
+ echo "HugePages_Free is zero"
+ exit
+fi
+
+hugepageSize=$(cat /proc/meminfo | grep -c "Hugepagesize: 0 kB")
+if [ $hugepageSize -ne 0 ]; then
+ echo "Hugepagesize is zero"
+ exit
+fi
+
+pdpe1gbFlag=$(cat /proc/cpuinfo | grep -c "pdpe1gb")
+if [ $pdpe1gbFlag -eq 0 ]; then
+ echo "/proc/cpuinfo doesn't include pdpe1gb to make hugepage work"
+ exit
+fi
+
+mkdir /mnt/nstackhuge -p
+mount -t hugetlbfs -o pagesize=1G none /mnt/nstackhuge/
+
+mkdir -p /var/run/ip_module/
+
+#===========build DPDK================
+if [ -d $DPDK_INSTALL_PATH ]; then
+ rm -rf $DPDK_INSTALL_PATH
+fi
+
+mkdir -p $DPDK_DOWNLOAD_PATH
+
+cd $DPDK_DOWNLOAD_PATH
+rm -rf dpdk-16.04/
+wget https://fast.dpdk.org/rel/dpdk-16.04.tar.xz
+tar xvf dpdk-16.04.tar.xz
+cd dpdk-16.04/
+
+sed -i 's!CONFIG_RTE_EXEC_ENV=.*!CONFIG_RTE_EXEC_ENV=y!1' config/common_base
+sed -i 's!CONFIG_RTE_BUILD_SHARED_LIB=.*!CONFIG_RTE_BUILD_SHARED_LIB=y!1' config/common_base
+sed -i 's!CONFIG_RTE_LIBRTE_EAL=.*!CONFIG_RTE_LIBRTE_EAL=y!1' config/common_base
+
+make install T=x86_64-native-linuxapp-gcc DESTDIR=${DPDK_INSTALL_PATH}
+cd x86_64-native-linuxapp-gcc
+make
+
+mkdir ${DPDK_INSTALL_PATH}/lib64/
+cp -r ${DPDK_INSTALL_PATH}/lib/* ${DPDK_INSTALL_PATH}/lib64/
+
+export LD_LIBRARY_PATH=$LIB_PATH
+export NSTACK_LOG_ON=DBG
+
+#===========build DMM=================
+echo "DMM build started....."
+
+cd $LIB_PATH
+rm -rf *
+
+cd ../../thirdparty/glog/glog-0.3.4/
+sudo autoreconf -ivf
+
+cd $BUILD_DIR
+rm -rf *
+cmake -D DMM_DPDK_INSTALL_DIR=$DPDK_INSTALL_PATH ..
+make -j 8
+
+#DPDK install path need to be updated below if it is changed
+sed -i 's!export DPDK_INSTALL_PATH.*!export DPDK_INSTALL_PATH="/root/dpdk_install/tmp/"!1' ../thirdparty/stackpool/release/script/nstack_var.sh
+echo "DMM build finished....." \ No newline at end of file
diff --git a/scripts/checkstyle.sh b/scripts/checkstyle.sh
new file mode 100644
index 0000000..55f4f73
--- /dev/null
+++ b/scripts/checkstyle.sh
@@ -0,0 +1,203 @@
+#########################################################################
+#
+# Copyright (c) 2018 Huawei Technologies Co.,Ltd.
+# 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.
+#########################################################################
+
+#!/bin/bash
+
+CURR_DIR=`dirname $0`
+DMM_DIR=${CURR_DIR}/..
+EXIT_CODE=0
+FIX="0"
+FULL="0"
+CHECKSTYLED_FILES=""
+UNCHECKSTYLED_FILES=""
+UNCHECK_LIST=""
+
+SHOW_HELP="1"
+FIX="0"
+FULL="0"
+CHECK="0"
+
+# user options.... -a, -c, -f
+
+while [[ $# -gt 0 ]]
+do
+key="$1"
+
+case $key in
+ -f|--fixstyle)
+ FIX="1"
+ SHOW_HELP="0"
+ shift # past argument
+ ;;
+ -c|--checkstyle)
+ CHECK="1"
+ SHOW_HELP="0"
+ shift # past argument
+ ;;
+ -a|--all)
+ FULL="1"
+ FIX="1"
+ SHOW_HELP="0"
+ shift # past argument
+ ;;
+ -h|--help)
+ shift # past argument
+ ;;
+ *) # unknown option
+ shift # past argument
+ ;;
+esac
+done
+
+if [ "${SHOW_HELP}" == "1" ] ; then
+ echo "help option:"
+ echo " -f, --fixstyle - fix coding style"
+ echo " -c, --checkstyle - check coding style"
+ echo " -a, --all - fix style including dos2unix"
+ exit
+fi
+cd ${DMM_DIR}
+
+
+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\". Checking C++ files will cause abort"
+#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\". Checking C++ files will cause abort"
+# fi
+#fi
+
+for i in ${FILELIST}; do
+ if [ -f ${i} ] && ( [ ${i: -2} == ".c" ] || [ ${i: -2} == ".h" ] ) && [[ ${i} != *"thirdparty"* ]] && [[ ${i} != *"testcode"* ]] ; then
+ #grep -q "fd.io coding-style-patch-verification: ON" ${i}
+ if [ $? == 0 ]; then
+ EXTENSION=`basename ${i} | sed 's/^\w\+.//'`
+ case ${EXTENSION} in
+ hpp|cpp|cc|hh)
+ CMD="clang-format"
+ if [ ${HAVE_CLANG_FORMAT} == 0 ]; then
+ echo "C++ file detected. Abort. (missing clang-format)"
+ exit ${EXIT_CODE}
+ fi
+ ;;
+ *)
+ CMD="indent"
+ ;;
+ esac
+ CHECKSTYLED_FILES="${CHECKSTYLED_FILES} ${i}"
+ if [ ${FIX} == 0 ]; then
+ if [ "${CMD}" == "clang-format" ]
+ then
+ clang-format ${i} > ${i}.out2
+ else
+ indent -gnu -nut ${i} -o ${i}.out1 > /dev/null 2>&1
+ indent -gnu -nut ${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 -nut -sob ${i}
+ indent -nut -sob ${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 ${DMM_DIR}${i}"
+ else
+ echo "Run indent (twice!) as shown to fix the problem:"
+ echo "indent ${DMM_DIR}${i}"
+ echo "indent ${DMM_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
+ else
+ UNCHECKSTYLED_FILES="${UNCHECKSTYLED_FILES} ${i}"
+ fi
+done
+
+if [ ${FULL} == "1" ] && [ ${FULL} == "1" ] ; then
+ for i in ${FILELIST}; do
+ #egrep -qlr $'\r'\$ ${i}
+ if [ $? == 0 ] && [[ ${i} != *"thirdparty"* ]] && [[ ${i} != *"testcode"* ]] && [[ ${i} != *"resources"* ]] && [[ ${i} != *"build"* ]] && ( [ ${i: -2} == ".c" ] || [ ${i: -2} == ".h" ] || [ ${i: -3} == ".sh" ] ); then
+ sed -e 's/\r//g' ${i} > ${i}.tmp
+ echo "dos2unix conoversion happened for ${i}"
+ mv ${i}.tmp ${i}
+ fi
+ done
+fi
+
+#delete temp files
+echo "deleting temp files generated by ${CMD}"
+
+find . -name "*~" -type f -delete
+
+if [ ${EXIT_CODE} == 0 ]; then
+ git status
+ echo "*******************************************************************"
+ echo "* DMM CHECKSTYLE SUCCESSFULLY COMPLETED"
+ echo "*******************************************************************"
+else
+ echo "*******************************************************************"
+ echo "* DMM CHECKSTYLE FAILED"
+ echo "* CONSULT FAILURE LOG ABOVE"
+ echo "* NOTE: Running 'checkstyle.sh -f' *MAY* fix the issue"
+ echo "*******************************************************************"
+fi
+cd ${CURR_DIR}
+exit ${EXIT_CODE}
diff --git a/scripts/header.template b/scripts/header.template
new file mode 100644
index 0000000..d3fe9f2
--- /dev/null
+++ b/scripts/header.template
@@ -0,0 +1,16 @@
+/*
+*
+* Copyright (c) 2018 Huawei Technologies Co.,Ltd.
+* 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.
+*/
+
diff --git a/scripts/header2.template b/scripts/header2.template
new file mode 100644
index 0000000..edf38d0
--- /dev/null
+++ b/scripts/header2.template
@@ -0,0 +1,16 @@
+#########################################################################
+#
+# Copyright (c) 2018 Huawei Technologies Co.,Ltd.
+# 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.
+#########################################################################
+
diff --git a/scripts/lic.sh b/scripts/lic.sh
new file mode 100644
index 0000000..a3c95e2
--- /dev/null
+++ b/scripts/lic.sh
@@ -0,0 +1,88 @@
+#########################################################################
+#
+# Copyright (c) 2018 Huawei Technologies Co.,Ltd.
+# 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.
+#########################################################################
+
+function remove_copyright_a {
+ printf "%s\n" 1,14d w q | ed "$1"
+}
+
+function remove_copyright_b {
+ printf "%s\n" 1,14d w q | ed "$1"
+}
+
+function add_copyright {
+ if [[ $1 == Makefile ]]; then
+ ed "$1" <<END
+0i
+/*
+ * Copyright (c) 2015 Huawei 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.
+ */
+.
+w
+q
+END
+ else
+ ed "$1" <<END
+0i
+/*
+ * Copyright (c) 2015 HUAWEI 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.
+ */
+.
+w
+q
+END
+ fi
+}
+
+shopt -s nullglob globstar
+#for file in **/*.[ch]; do
+ # ./replace_header.sh "$file"
+#done
+
+for i in $(find ./../ -type f)
+do
+ if [[ ${i} != *"thirdparty"* ]] && [[ ${i} != *"testcode"* ]] && [[ ${i} != *"resources"* ]] && [[ ${i} != *"build"* ]] ; then
+ if [ "${i: -2}" == ".c" ] || [ "${i: -2}" == ".h" ] ; then
+ ./replace_header.sh "$i" "header.template"
+ elif [[ "${i}" == *"Makefile" ]] || [ "${i: -4}" == ".txt" ] || [ "${i: -3}" == ".sh" ] ; then
+ grep -q "Apache License" ${i}
+ if [ $? != 0 ]; then
+ ./replace_header.sh "$i" "header2.template"
+ fi
+ fi
+ fi
+done
diff --git a/scripts/remove_header.awk b/scripts/remove_header.awk
new file mode 100644
index 0000000..9e83877
--- /dev/null
+++ b/scripts/remove_header.awk
@@ -0,0 +1,63 @@
+#########################################################################
+#
+# Copyright (c) 2018 Huawei Technologies Co.,Ltd.
+# 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.
+#########################################################################
+# This script removes ANSI C file header comments
+BEGIN { start = 0; incomment = 0;}
+
+{
+ if (start == 0)
+ {
+ if (incomment == 0)
+ {
+ # C++ single line comment
+ if (/^\/\//)
+ {
+ # print "single line"
+ }
+ # single line comment
+ else if (/^\/\*[^\/]*\*\/$/)
+ {
+ # print "single line"
+ }
+ # multi line comment
+ else if (/^\/\*/)
+ {
+ #print "start comment"
+ # start multi line comment
+ incomment = 1
+ }
+ else
+ {
+ # first line that is not a comment, start normal output
+ print $0;
+ start = 1;
+ }
+ }
+ else
+ {
+ # search for comment end
+ if (/\*\//)
+ {
+ #print "end comment"
+ incomment = 0;
+ }
+ }
+ }
+ else
+ {
+ # print the complete line for the rest of the file
+ print $0
+ }
+}
diff --git a/scripts/replace_header.sh b/scripts/replace_header.sh
new file mode 100644
index 0000000..3339533
--- /dev/null
+++ b/scripts/replace_header.sh
@@ -0,0 +1,27 @@
+#########################################################################
+#
+# Copyright (c) 2018 Huawei Technologies Co.,Ltd.
+# 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.
+#########################################################################
+
+#!/bin/bash
+SOURCE_DIR=`dirname $0`
+if [ $# != 2 ]; then
+ echo "Usage: replace_header.sh <file> <header.template>"
+ exit 1
+fi
+
+cat $SOURCE_DIR/$2 > $SOURCE_DIR/tmp
+cat $1 | awk -f $SOURCE_DIR/remove_header.awk >> $SOURCE_DIR/tmp
+mv $SOURCE_DIR/tmp $1
+