12946d4b83055ed6071252676f1b4ff0534fd4d8
[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 <TAG1> <TAG2> <TARGET>"
37 }
38
39 log() {
40         local level=$1
41         shift
42         echo "$*"
43 }
44
45 validate_tags() {
46         git tag -l | grep -q "$TAG1"
47         if [ $? -ne 0 ]
48         then
49                 echo "$TAG1 is invalid"
50                 return
51         fi
52         git tag -l | grep -q "$TAG2"
53         if [ $? -ne 0 ]
54         then
55                 echo "$TAG2 is invalid"
56                 return
57         fi
58 }
59
60 validate_args() {
61         if [ -z "$TAG1" ]
62         then
63                 echo "Must Specify TAG1"
64                 return
65         fi
66         if [ -z "$TAG2" ]
67         then
68                 echo "Must Specify TAG2"
69                 return
70         fi
71         if [ -z "$TARGET" ]
72         then
73                 echo "Must Specify a build target"
74         fi
75 }
76
77
78 cleanup_and_exit() {
79         rm -rf $ABI_DIR
80         git checkout $CURRENT_BRANCH
81         exit $1
82 }
83
84 # Make sure we configure SHARED libraries
85 # Also turn off IGB and KNI as those require kernel headers to build
86 fixup_config() {
87         sed -i -e"$ a\CONFIG_RTE_BUILD_SHARED_LIB=y" config/defconfig_$TARGET
88         sed -i -e"$ a\CONFIG_RTE_NEXT_ABI=n" config/defconfig_$TARGET
89         sed -i -e"$ a\CONFIG_RTE_EAL_IGB_UIO=n" config/defconfig_$TARGET
90         sed -i -e"$ a\CONFIG_RTE_LIBRTE_KNI=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 # Make sure our tags exist
125 res=$(validate_tags)
126 if [ -n "$res" ]
127 then
128         echo $res
129         cleanup_and_exit 1
130 fi
131
132 ABICHECK=`which abi-compliance-checker 2>/dev/null`
133 if [ $? -ne 0 ]
134 then
135         log "INFO" "Cant find abi-compliance-checker utility"
136         cleanup_and_exit 1
137 fi
138
139 ABIDUMP=`which abi-dumper 2>/dev/null`
140 if [ $? -ne 0 ]
141 then
142         log "INFO" "Cant find abi-dumper utility"
143         cleanup_and_exit 1
144 fi
145
146 log "INFO" "We're going to check and make sure that applications built"
147 log "INFO" "against DPDK DSOs from tag $TAG1 will still run when executed"
148 log "INFO" "against DPDK DSOs built from tag $TAG2."
149 log "INFO" ""
150
151 # Check to make sure we have a clean tree
152 git status | grep -q clean
153 if [ $? -ne 0 ]
154 then
155         log "WARN" "Working directory not clean, aborting"
156         cleanup_and_exit 1
157 fi
158
159 # Move to the root of the git tree
160 cd $(dirname $0)/..
161
162 log "INFO" "Checking out version $TAG1 of the dpdk"
163 # Move to the old version of the tree
164 git checkout $TAG1
165
166 fixup_config
167
168 # Checking abi compliance relies on using the dwarf information in
169 # The shared objects.  Thats only included in the DSO's if we build
170 # with -g
171 export EXTRA_CFLAGS="$EXTRA_CFLAGS -g"
172 export EXTRA_LDFLAGS="$EXTRA_LDFLAGS -g"
173
174 # Now configure the build
175 log "INFO" "Configuring DPDK $TAG1"
176 make config T=$TARGET O=$TARGET > $VERBOSE 2>&1
177
178 log "INFO" "Building DPDK $TAG1. This might take a moment"
179 make O=$TARGET > $VERBOSE 2>&1
180
181 if [ $? -ne 0 ]
182 then
183         log "INFO" "THE BUILD FAILED.  ABORTING"
184         cleanup_and_exit 1
185 fi
186
187 # Move to the lib directory
188 cd $TARGET/lib
189 log "INFO" "COLLECTING ABI INFORMATION FOR $TAG1"
190 for i in `ls *.so`
191 do
192         $ABIDUMP $i -o $ABI_DIR/$i-ABI-0.dump -lver $TAG1
193 done
194 cd ../..
195
196 # Now clean the tree, checkout the second tag, and rebuild
197 git clean -f -d
198 git reset --hard
199 # Move to the new version of the tree
200 log "INFO" "Checking out version $TAG2 of the dpdk"
201 git checkout $TAG2
202
203 fixup_config
204
205 # Now configure the build
206 log "INFO" "Configuring DPDK $TAG2"
207 make config T=$TARGET O=$TARGET > $VERBOSE 2>&1
208
209 log "INFO" "Building DPDK $TAG2. This might take a moment"
210 make O=$TARGET > $VERBOSE 2>&1
211
212 if [ $? -ne 0 ]
213 then
214         log "INFO" "THE BUILD FAILED.  ABORTING"
215         cleanup_and_exit 1
216 fi
217
218 cd $TARGET/lib
219 log "INFO" "COLLECTING ABI INFORMATION FOR $TAG2"
220 for i in `ls *.so`
221 do
222         $ABIDUMP $i -o $ABI_DIR/$i-ABI-1.dump -lver $TAG2
223 done
224 cd ../..
225
226 # Start comparison of ABI dumps
227 for i in `ls $ABI_DIR/*-1.dump`
228 do
229         NEWNAME=`basename $i`
230         OLDNAME=`basename $i | sed -e"s/1.dump/0.dump/"`
231         LIBNAME=`basename $i | sed -e"s/-ABI-1.dump//"`
232
233         if [ ! -f $ABI_DIR/$OLDNAME ]
234         then
235                 log "INFO" "$OLDNAME DOES NOT EXIST IN $TAG1. SKIPPING..."
236         fi
237
238         #compare the abi dumps
239         $ABICHECK -l $LIBNAME -old $ABI_DIR/$OLDNAME -new $ABI_DIR/$NEWNAME
240 done
241
242 git reset --hard
243 log "INFO" "ABI CHECK COMPLETE.  REPORTS ARE IN compat_report directory"
244 cleanup_and_exit 0