buildOnVM.sh 9.03 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#!/bin/bash

function usage {
    echo "OAI VM Build Check script"
    echo "   Original Author: Raphael Defosseux"
    echo "   Requirements:"
    echo "     -- uvtool uvtool-libvirt apt-cacher"
    echo "     -- xenial image already synced"
    echo "   Default:"
    echo "     -- eNB with USRP"
    echo ""
    echo "Usage:"
    echo "------"
    echo "    buildOnVM.sh [OPTIONS]"
    echo ""
    echo "Options:"
    echo "--------"
    echo "    --workspace #### OR -ws ####"
19
    echo "    Specify the workspace."
20
21
22
    echo ""
    echo "    --variant enb-usrp   OR -v1"
    echo "    --variant basic-sim  OR -v2"
Raphael Defosseux's avatar
Raphael Defosseux committed
23
    echo "    --variant phy-sim    OR -v3"
24
25
26
27
28
    echo "    --variant cppcheck   OR -v4"
    echo "    Specify the variant to build."
    echo ""
    echo "    --keep-vm-alive OR -k"
    echo "    Keep the VM alive after the build."
29
30
31
32
33
34
35
36
37
38
39
40
    echo ""
    echo "    --help OR -h"
    echo "    Print this help message."
    echo ""
}

function variant_usage {
    echo "OAI VM Build Check script"
    echo "   Original Author: Raphael Defosseux"
    echo ""
    echo "    --variant enb-usrp   OR -v1"
    echo "    --variant basic-sim  OR -v2"
Raphael Defosseux's avatar
Raphael Defosseux committed
41
    echo "    --variant phy-sim    OR -v3"
42
    echo "    --variant cppcheck   OR -v4"
43
44
45
    echo ""
}

46
if [ $# -lt 1 ] || [ $# -gt 5 ]
47
48
49
50
51
52
53
54
55
56
57
58
59
then
    echo "Syntax Error: not the correct number of arguments"
    echo ""
    usage
    exit 1
fi

VM_NAME=ci-enb-usrp
ARCHIVES_LOC=enb_usrp
LOG_PATTERN=.Rel14.txt
NB_PATTERN_FILES=4
BUILD_OPTIONS="--eNB -w USRP"
BUILD_EXTRA_OPTIONS="--cflags_processor \"-mssse3 -msse4.1 -mavx2\""
60
KEEP_VM_ALIVE=0
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76

while [[ $# -gt 0 ]]
do
key="$1"

case $key in
    -h|--help)
    shift
    usage
    exit 0
    ;;
    -ws|--workspace)
    JENKINS_WKSP="$2"
    shift
    shift
    ;;
77
78
79
80
    -k|--keep-vm-alive)
    KEEP_VM_ALIVE=1
    shift
    ;;
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
    -v1)
    VM_NAME=ci-enb-usrp
    ARCHIVES_LOC=enb_usrp
    LOG_PATTERN=.Rel14.txt
    NB_PATTERN_FILES=4
    BUILD_OPTIONS="--eNB -w USRP"
    BUILD_EXTRA_OPTIONS="--cflags_processor \"-mssse3 -msse4.1 -mavx2\""
    shift
    ;;
    -v2)
    VM_NAME=ci-basic-sim
    ARCHIVES_LOC=basic_sim
    LOG_PATTERN=basic_simulator
    NB_PATTERN_FILES=2
    BUILD_OPTIONS="--basic-simulator"
    BUILD_EXTRA_OPTIONS="--cflags_processor \"-mssse3 -msse4.1 -mavx2\""
    shift
    ;;
Raphael Defosseux's avatar
Raphael Defosseux committed
99
100
101
102
103
104
105
106
107
    -v3)
    VM_NAME=ci-phy-sim
    ARCHIVES_LOC=phy_sim
    LOG_PATTERN=.Rel14.txt
    NB_PATTERN_FILES=3
    BUILD_OPTIONS="--phy_simulators"
    BUILD_EXTRA_OPTIONS="--cflags_processor \"-mssse3 -msse4.1 -mavx2\""
    shift
    ;;
108
109
110
111
112
113
114
115
116
    -v4)
    VM_NAME=ci-cppcheck
    ARCHIVES_LOC=cppcheck
    LOG_PATTERN=cppcheck.xml
    NB_PATTERN_FILES=1
    BUILD_OPTIONS="--enable=warning --force --xml --xml-version=2"
    BUILD_EXTRA_OPTIONS=""
    shift
    ;;
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
    --variant)
    variant="$2"
    case $variant in
        enb-usrp)
        VM_NAME=ci-enb-usrp
        ARCHIVES_LOC=enb_usrp
        LOG_PATTERN=.Rel14.txt
        NB_PATTERN_FILES=4
        BUILD_OPTIONS="--eNB -w USRP"
        BUILD_EXTRA_OPTIONS="--cflags_processor \"-mssse3 -msse4.1 -mavx2\""
        ;;
        basic-sim)
        VM_NAME=ci-basic-sim
        ARCHIVES_LOC=basic_sim
        LOG_PATTERN=basic_simulator
        NB_PATTERN_FILES=2
        BUILD_OPTIONS="--basic-simulator"
        BUILD_EXTRA_OPTIONS="--cflags_processor \"-mssse3 -msse4.1 -mavx2\""
        ;;
Raphael Defosseux's avatar
Raphael Defosseux committed
136
137
138
139
140
141
142
143
        phy-sim)
        VM_NAME=ci-phy-sim
        ARCHIVES_LOC=phy_sim
        LOG_PATTERN=.Rel14.txt
        NB_PATTERN_FILES=3
        BUILD_OPTIONS="--phy_simulators"
        BUILD_EXTRA_OPTIONS="--cflags_processor \"-mssse3 -msse4.1 -mavx2\""
        ;;
144
145
146
147
148
149
150
151
        cppcheck)
        VM_NAME=ci-cppcheck
        ARCHIVES_LOC=cppcheck
        LOG_PATTERN=cppcheck.xml
        NB_PATTERN_FILES=1
        BUILD_OPTIONS="--enable=warning --force --xml --xml-version=2"
        BUILD_EXTRA_OPTIONS=""
        ;;
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
        *)
        echo ""
        echo "Syntax Error: Invalid Variant option -> $variant"
        echo ""
        variant_usage
        exit 1
    esac
    shift
    shift
    ;;
    *)
    echo "Syntax Error: unknown option: $key"
    echo ""
    usage
    exit 1
esac
done

if [ ! -f $JENKINS_WKSP/localZip.zip ]
then
    echo "Missing localZip.zip file!"
    exit 1
fi
if [ ! -f /etc/apt/apt.conf.d/01proxy ]
then
    echo "Missing /etc/apt/apt.conf.d/01proxy file!"
    echo "Is apt-cacher installed and configured?"
    exit 1
fi

VM_CMDS=${VM_NAME}_cmds.txt
ARCHIVES_LOC=${JENKINS_WKSP}/archives/${ARCHIVES_LOC}

echo "VM_NAME             = $VM_NAME"
echo "VM_CMD_FILE         = $VM_CMDS"
echo "JENKINS_WKSP        = $JENKINS_WKSP"
echo "ARCHIVES_LOC        = $ARCHIVES_LOC"
echo "BUILD_OPTIONS       = $BUILD_OPTIONS"
echo "BUILD_EXTRA_OPTIONS = $BUILD_EXTRA_OPTIONS"

echo "############################################################"
echo "Creating VM ($VM_NAME) on Ubuntu Cloud Image base"
echo "############################################################"
195
uvt-kvm create $VM_NAME release=xenial --memory 2048 --cpu 4 --unsafe-caching --template ci-scripts/template-host.xml
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
echo "Waiting for VM to be started"
uvt-kvm wait $VM_NAME --insecure

VM_IP_ADDR=`uvt-kvm ip $VM_NAME`
echo "$VM_NAME has for IP addr = $VM_IP_ADDR"

echo "############################################################"
echo "Copying GIT repo into VM ($VM_NAME)" 
echo "############################################################"
scp -o StrictHostKeyChecking=no localZip.zip ubuntu@$VM_IP_ADDR:/home/ubuntu
scp -o StrictHostKeyChecking=no /etc/apt/apt.conf.d/01proxy ubuntu@$VM_IP_ADDR:/home/ubuntu

echo "############################################################"
echo "Running install and build script on VM ($VM_NAME)"
echo "############################################################"
echo "sudo cp 01proxy /etc/apt/apt.conf.d/" > $VM_CMDS
212
213
214
215
216
217
218
219
220
if [ "$VM_NAME" == "ci-cppcheck" ]
then
    echo "echo \"sudo apt-get --yes --quiet install zip cppcheck \"" >> $VM_CMDS
    echo "sudo apt-get update > zip-install.txt 2>&1" >> $VM_CMDS
    echo "sudo apt-get --yes install zip cppcheck >> zip-install.txt 2>&1" >> $VM_CMDS
else
    echo "echo \"sudo apt-get --yes --quiet install zip subversion libboost-dev \"" >> $VM_CMDS
    echo "sudo apt-get --yes install zip subversion libboost-dev > zip-install.txt 2>&1" >> $VM_CMDS
fi
221
222
223
224
echo "mkdir tmp" >> $VM_CMDS
echo "cd tmp" >> $VM_CMDS
echo "echo \"unzip -qq ../localZip.zip\"" >> $VM_CMDS
echo "unzip -qq ../localZip.zip" >> $VM_CMDS
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
if [ "$VM_NAME" == "ci-cppcheck" ]
then
    echo "mkdir cmake_targets/log" >> $VM_CMDS
    echo "cp /home/ubuntu/zip-install.txt cmake_targets/log" >> $VM_CMDS
    echo "echo \"cppcheck $BUILD_OPTIONS . \"" >> $VM_CMDS
    echo "cppcheck $BUILD_OPTIONS . 2> cmake_targets/log/cppcheck.xml 1> cmake_targets/log/cppcheck_build.txt" >> $VM_CMDS
else
    echo "echo \"source oaienv\"" >> $VM_CMDS
    echo "source oaienv" >> $VM_CMDS
    echo "cd cmake_targets/" >> $VM_CMDS
    echo "mkdir log" >> $VM_CMDS
    echo "cp /home/ubuntu/zip-install.txt log" >> $VM_CMDS
    echo "echo \"./build_oai -I $BUILD_OPTIONS \"" >> $VM_CMDS
    echo "./build_oai -I $BUILD_OPTIONS $BUILD_EXTRA_OPTIONS > log/install-build.txt 2>&1" >> $VM_CMDS
fi
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
ssh -o StrictHostKeyChecking=no ubuntu@$VM_IP_ADDR < $VM_CMDS

echo "############################################################"
echo "Creating a tmp folder to store results and artifacts"
echo "############################################################"
if [ ! -d $JENKINS_WKSP/archives ]
then
    mkdir $JENKINS_WKSP/archives
fi

if [ ! -d $ARCHIVES_LOC ]
then
    mkdir $ARCHIVES_LOC
fi

scp -o StrictHostKeyChecking=no ubuntu@$VM_IP_ADDR:/home/ubuntu/tmp/cmake_targets/log/*.txt $ARCHIVES_LOC
256
257
258
259
if [ "$VM_NAME" == "ci-cppcheck" ]
then
    scp -o StrictHostKeyChecking=no ubuntu@$VM_IP_ADDR:/home/ubuntu/tmp/cmake_targets/log/*.xml $ARCHIVES_LOC
fi
260

261
262
263
264
265
266
267
268
if [ $KEEP_VM_ALIVE -eq 0 ]
then
    echo "############################################################"
    echo "Destroying VM"
    echo "############################################################"
    uvt-kvm destroy $VM_NAME
    ssh-keygen -R $VM_IP_ADDR
fi
269
270
271
272
273
274
rm -f $VM_CMDS

echo "############################################################"
echo "Checking build status" 
echo "############################################################"

275
LOG_FILES=`ls $ARCHIVES_LOC/*.txt $ARCHIVES_LOC/*.xml`
276
277
278
279
280
281
282
283
284
285
286
287
288
289
STATUS=0
NB_FOUND_FILES=0

for FULLFILE in $LOG_FILES 
do
    if [[ $FULLFILE == *"$LOG_PATTERN"* ]]
    then
        filename=$(basename -- "$FULLFILE")
        if [ "$LOG_PATTERN" == ".Rel14.txt" ]
        then
            PASS_PATTERN=`echo $filename | sed -e "s#$LOG_PATTERN##"`
        fi
        if [ "$LOG_PATTERN" == "basic_simulator" ]
        then
290
            PASS_PATTERN="lte-"
291
        fi
292
293
294
295
296
297
298
        if [ "$LOG_PATTERN" == "cppcheck.xml" ]
        then
            PASS_PATTERN="results version"
            LOCAL_STAT=`egrep -c "$PASS_PATTERN" $FULLFILE`
        else
            LOCAL_STAT=`egrep -c "Built target $PASS_PATTERN" $FULLFILE`
        fi
299
300
301
302
303
304
305
        if [ $LOCAL_STAT -eq 0 ]; then STATUS=-1; fi
        NB_FOUND_FILES=$((NB_FOUND_FILES + 1))
    fi
done

if [ $NB_PATTERN_FILES -ne $NB_FOUND_FILES ]; then STATUS=-1; fi

Raphael Defosseux's avatar
Raphael Defosseux committed
306
307
308
309
310
311
if [ $STATUS -eq 0 ]
then
    echo "STATUS seems OK"
else
    echo "STATUS failed?"
fi
312
exit $STATUS