Imported Upstream version 16.04
[deb_dpdk.git] / scripts / validate-abi.sh
1 #!/bin/sh
2 #   BSD LICENSE
3 #
4 #   Copyright(c) 2015 Neil Horman. All rights reserved.
5 #   All rights reserved.
6 #
7 #   Redistribution and use in source and binary forms, with or without
8 #   modification, are permitted provided that the following conditions
9 #   are met:
10 #
11 #     * Redistributions of source code must retain the above copyright
12 #       notice, this list of conditions and the following disclaimer.
13 #     * Redistributions in binary form must reproduce the above copyright
14 #       notice, this list of conditions and the following disclaimer in
15 #       the documentation and/or other materials provided with the
16 #       distribution.
17 #
18 #   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 #   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 #   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 #   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 #   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 #   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 #   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 #   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 #   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 #   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 #   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
30 TAG1=$1
31 TAG2=$2
32 TARGET=$3
33 ABI_DIR=`mktemp -d -p /tmp ABI.XXXXXX`
34
35 usage() {
36         echo "$0 <REV1> <REV2> <TARGET>"
37 }
38
39 log() {
40         local level=$1
41         shift
42         echo "$*"
43 }
44
45 validate_tags() {
46
47         if [ -z "$HASH1" ]
48         then
49                 echo "invalid revision: $TAG1"
50                 return
51         fi
52         if [ -z "$HASH2" ]
53         then
54                 echo "invalid revision: $TAG2"
55                 return
56         fi
57 }
58
59 validate_args() {
60         if [ -z "$TAG1" ]
61         then
62                 echo "Must Specify REV1"
63                 return
64         fi
65         if [ -z "$TAG2" ]
66         then
67                 echo "Must Specify REV2"
68                 return
69         fi
70         if [ -z "$TARGET" ]
71         then
72                 echo "Must Specify a build target"
73         fi
74 }
75
76
77 cleanup_and_exit() {
78         rm -rf $ABI_DIR
79         git checkout $CURRENT_BRANCH
80         exit $1
81 }
82
83 # Make sure we configure SHARED libraries
84 # Also turn off IGB and KNI as those require kernel headers to build
85 fixup_config() {
86         sed -i -e"$ a\CONFIG_RTE_BUILD_SHARED_LIB=y" config/defconfig_$TARGET
87         sed -i -e"$ a\CONFIG_RTE_NEXT_ABI=n" config/defconfig_$TARGET
88         sed -i -e"$ a\CONFIG_RTE_EAL_IGB_UIO=n" config/defconfig_$TARGET
89         sed -i -e"$ a\CONFIG_RTE_LIBRTE_KNI=n" config/defconfig_$TARGET
90         sed -i -e"$ a\CONFIG_RTE_KNI_KMOD=n" config/defconfig_$TARGET
91 }
92
93 ###########################################
94 #START
95 ############################################
96
97 #trap on ctrl-c to clean up
98 trap cleanup_and_exit SIGINT
99
100 #Save the current branch
101 CURRENT_BRANCH=`git branch | grep \* | cut -d' ' -f2`
102
103 if [ -z "$CURRENT_BRANCH" ]
104 then
105         CURRENT_BRANCH=`git log --pretty=format:%H HEAD~1..HEAD`
106 fi
107
108 if [ -n "$VERBOSE" ]
109 then
110         export VERBOSE=/dev/stdout
111 else
112         export VERBOSE=/dev/null
113 fi
114
115 # Validate that we have all the arguments we need
116 res=$(validate_args)
117 if [ -n "$res" ]
118 then
119         echo $res
120         usage
121         cleanup_and_exit 1
122 fi
123
124 HASH1=$(git show -s --format=%H "$TAG1" -- 2> /dev/null | tail -1)
125 HASH2=$(git show -s --format=%H "$TAG2" -- 2> /dev/null | tail -1)
126
127 # Make sure our tags exist
128 res=$(validate_tags)
129 if [ -n "$res" ]
130 then
131         echo $res
132         cleanup_and_exit 1
133 fi
134
135 # Make hashes available in output for non-local reference
136 TAG1="$TAG1 ($HASH1)"
137 TAG2="$TAG2 ($HASH2)"
138
139 ABICHECK=`which abi-compliance-checker 2>/dev/null`
140 if [ $? -ne 0 ]
141 then
142         log "INFO" "Cant find abi-compliance-checker utility"
143         cleanup_and_exit 1
144 fi
145
146 ABIDUMP=`which abi-dumper 2>/dev/null`
147 if [ $? -ne 0 ]
148 then
149         log "INFO" "Cant find abi-dumper utility"
150         cleanup_and_exit 1
151 fi
152
153 log "INFO" "We're going to check and make sure that applications built"
154 log "INFO" "against DPDK DSOs from version $TAG1 will still run when executed"
155 log "INFO" "against DPDK DSOs built from version $TAG2."
156 log "INFO" ""
157
158 # Check to make sure we have a clean tree
159 git status | grep -q clean
160 if [ $? -ne 0 ]
161 then
162         log "WARN" "Working directory not clean, aborting"
163         cleanup_and_exit 1
164 fi
165
166 # Move to the root of the git tree
167 cd $(dirname $0)/..
168
169 log "INFO" "Checking out version $TAG1 of the dpdk"
170 # Move to the old version of the tree
171 git checkout $HASH1
172
173 fixup_config
174
175 # Checking abi compliance relies on using the dwarf information in
176 # The shared objects.  Thats only included in the DSO's if we build
177 # with -g
178 export EXTRA_CFLAGS="$EXTRA_CFLAGS -g"
179 export EXTRA_LDFLAGS="$EXTRA_LDFLAGS -g"
180
181 # Now configure the build
182 log "INFO" "Configuring DPDK $TAG1"
183 make config T=$TARGET O=$TARGET > $VERBOSE 2>&1
184
185 log "INFO" "Building DPDK $TAG1. This might take a moment"
186 make O=$TARGET > $VERBOSE 2>&1
187
188 if [ $? -ne 0 ]
189 then
190         log "INFO" "THE BUILD FAILED.  ABORTING"
191         cleanup_and_exit 1
192 fi
193
194 # Move to the lib directory
195 cd $TARGET/lib
196 log "INFO" "COLLECTING ABI INFORMATION FOR $TAG1"
197 for i in `ls *.so`
198 do
199         $ABIDUMP $i -o $ABI_DIR/$i-ABI-0.dump -lver $HASH1
200 done
201 cd ../..
202
203 # Now clean the tree, checkout the second tag, and rebuild
204 git clean -f -d
205 git reset --hard
206 # Move to the new version of the tree
207 log "INFO" "Checking out version $TAG2 of the dpdk"
208 git checkout $HASH2
209
210 fixup_config
211
212 # Now configure the build
213 log "INFO" "Configuring DPDK $TAG2"
214 make config T=$TARGET O=$TARGET > $VERBOSE 2>&1
215
216 log "INFO" "Building DPDK $TAG2. This might take a moment"
217 make O=$TARGET > $VERBOSE 2>&1
218
219 if [ $? -ne 0 ]
220 then
221         log "INFO" "THE BUILD FAILED.  ABORTING"
222         cleanup_and_exit 1
223 fi
224
225 cd $TARGET/lib
226 log "INFO" "COLLECTING ABI INFORMATION FOR $TAG2"
227 for i in `ls *.so`
228 do
229         $ABIDUMP $i -o $ABI_DIR/$i-ABI-1.dump -lver $HASH2
230 done
231 cd ../..
232
233 # Start comparison of ABI dumps
234 for i in `ls $ABI_DIR/*-1.dump`
235 do
236         NEWNAME=`basename $i`
237         OLDNAME=`basename $i | sed -e"s/1.dump/0.dump/"`
238         LIBNAME=`basename $i | sed -e"s/-ABI-1.dump//"`
239
240         if [ ! -f $ABI_DIR/$OLDNAME ]
241         then
242                 log "INFO" "$OLDNAME DOES NOT EXIST IN $TAG1. SKIPPING..."
243         fi
244
245         #compare the abi dumps
246         $ABICHECK -l $LIBNAME -old $ABI_DIR/$OLDNAME -new $ABI_DIR/$NEWNAME
247 done
248
249 git reset --hard
250 log "INFO" "ABI CHECK COMPLETE.  REPORTS ARE IN compat_report directory"
251 cleanup_and_exit 0