-
Notifications
You must be signed in to change notification settings - Fork 255
508 lines (439 loc) · 14.9 KB
/
ci.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
name: ci
on:
pull_request:
branches: [ main ]
push:
branches: [ main ]
permissions:
actions: read
contents: read
security-events: write
concurrency:
group: ci-${{ github.ref }}
cancel-in-progress: true
jobs:
init:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os:
- 'ubuntu-20.04'
- 'ubuntu-latest'
steps:
- uses: actions/checkout@v3
- name: Install dependencies
run: |
sudo apt-get update -q
sudo apt-get install -y\
build-essential flex bison libjson-c-dev liblzo2-dev \
libglib2.0-dev meson ninja-build lld llvm clang
- name: Get submodule hashes version
id: get-hash
run: |
echo XEN_HASH=$(git submodule | grep xen | awk '{ print $1 }') >> $GITHUB_OUTPUT
echo LIBVMI_HASH=$(git submodule | grep libvmi | awk '{ print $1 }') >> $GITHUB_OUTPUT
- name: Cache Xen debball
id: cache-xen
uses: actions/cache@v3
with:
path: xen/dist
key: xen-${{ matrix.os }}-${{ steps.get-hash.outputs.XEN_HASH }}
- name: Create Xen debball
if: steps.cache-xen.outputs.cache-hit != 'true'
run: |
sudo apt-get install -y \
wget git bcc bin86 gawk bridge-utils iproute2 libcurl4-openssl-dev \
bzip2 libpci-dev libc6-dev linux-libc-dev zlib1g-dev libncurses5-dev \
patch libvncserver-dev libssl-dev iasl libbz2-dev e2fslibs-dev git-core \
uuid-dev ocaml libx11-dev bison flex ocaml-findlib xz-utils gettext \
libyajl-dev libpixman-1-dev libaio-dev libfdt-dev cabextract libfuse-dev \
liblzma-dev kpartx python3-dev python3-pip golang libsystemd-dev ninja-build
rm -rfv xen
git submodule update --init xen
cd xen
./configure --enable-githttp --disable-pvshim --disable-stubdom --disable-docs
make -j2 debball
cd ..
- name: Install Xen debball
run: |
sudo apt-get install -f ./xen/dist/xen-*.deb
sudo ldconfig
- name: Cache Libvmi files
id: cache-libvmi
uses: actions/cache@v3
with:
path: libvmi/dist
key: libvmi-${{ matrix.os }}-${{ steps.get-hash.outputs.LIBVMI_HASH }}
- name: Build LibVMI
if: steps.cache-libvmi.outputs.cache-hit != 'true'
run: |
rm -rfv libvmi
sudo apt-get install -y build-essential autoconf-archive automake libtool flex bison libjson-c-dev debhelper
git submodule update --init libvmi
cd libvmi
sed -i 's/--disable-kvm/--disable-kvm --disable-file --disable-bareflank --disable-examples --disable-vmifs/g' debian/rules
dpkg-buildpackage -B
mkdir dist
mv ../*.deb dist/
- name: Install LibVMI
run: |
cd libvmi/dist
sudo apt install -f ./*.deb
sudo ldconfig
cd ../..
outputs:
XEN_HASH: ${{ steps.get-hash.outputs.XEN_HASH }}
LIBVMI_HASH: ${{ steps.get-hash.outputs.LIBVMI_HASH }}
compile:
runs-on: ${{ matrix.os }}
if: ${{ github.event_name == 'pull_request' }}
needs:
- init
strategy:
matrix:
os:
- 'ubuntu-20.04'
- 'ubuntu-latest'
flags:
- ''
- '-Dbuildtype=debug -Db_lto=false'
- '-Dbuildtype=debug -Db_lto=false -Dplugin-syscalls=false'
- '-Dbuildtype=debug -Db_lto=false -Db_sanitize=address,undefined'
- '-Dbuildtype=debug -Db_lto=false -Drepl=true'
- '-Dbuildtype=debug -Db_lto=false -Dthreadsafety=true'
steps:
- uses: actions/checkout@v3
- name: Install dependencies
run: |
sudo apt-get update -q
sudo apt-get install -y \
clang llvm lld build-essential flex bison \
libjson-c-dev liblzo2-dev libglib2.0-dev meson ninja-build
sudo pip3 install ctypesgen ipython
- name: Cache Xen debball
uses: actions/cache@v3
with:
path: xen/dist
key: xen-${{ matrix.os }}-${{ needs.init.outputs.XEN_HASH }}
- name: Cache Libvmi files
uses: actions/cache@v3
with:
path: libvmi/dist
key: libvmi-${{ matrix.os }}-${{ needs.init.outputs.LIBVMI_HASH }}
- name: Install Xen debball
run: |
sudo apt-get install -f ./xen/dist/xen-*.deb
- name: Install LibVMI
run: |
cd libvmi/dist
sudo apt install -f ./*.deb
sudo ldconfig
cd ../..
- name: Compile ${{ matrix.flags }}
run: |
meson setup build --native-file llvm.ini ${{ matrix.flags }}
ninja -C build
tarbuild:
name: Build using autoconf tarball
runs-on: ${{ matrix.os }}
needs:
- init
strategy:
fail-fast: false
matrix:
os:
- 'ubuntu-20.04'
- 'ubuntu-latest'
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Install dependencies
run: |
sudo apt-get update -q
sudo apt-get install -y \
clang autoconf-archive automake \
libjson-c-dev liblzo2-dev libglib2.0-dev
sudo pip3 install ctypesgen ipython
- name: Cache Xen debball
uses: actions/cache@v3
with:
path: xen/dist
key: xen-${{ matrix.os }}-${{ needs.init.outputs.XEN_HASH }}
- name: Cache Libvmi files
uses: actions/cache@v3
with:
path: libvmi/dist
key: libvmi-${{ matrix.os }}-${{ needs.init.outputs.LIBVMI_HASH }}
- name: Install Xen debball
run: |
sudo apt-get install -f ./xen/dist/xen-*.deb
- name: Install LibVMI
run: |
cd libvmi/dist
sudo apt install -f ./*.deb
sudo ldconfig
cd ../..
- name: autoreconf
run: autoreconf -vif
- name: Compile from make dist tarball
env:
CC: clang
CXX: clang++
run: |
./configure
make -j2 dist
mkdir build && cd build
tar xvf ../drakvuf-*.tar.gz
cd *drakvuf*
./autogen.sh
./configure
make -j2
codeql-analyze:
name: Code QL Analyze
runs-on: ${{ matrix.os }}
needs:
- init
strategy:
fail-fast: false
matrix:
os:
- 'ubuntu-20.04'
- 'ubuntu-latest'
steps:
- name: Checkout repository
uses: actions/checkout@v3
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v2
with:
languages: cpp
queries: security-and-quality
- name: Install dependencies
run: |
sudo apt-get update -q
sudo apt-get install -y \
clang llvm lld build-essential libjson-c-dev \
liblzo2-dev libglib2.0-dev meson ninja-build
- name: Cache Xen debball
uses: actions/cache@v3
with:
path: xen/dist
key: xen-${{ matrix.os }}-${{ needs.init.outputs.XEN_HASH }}
- name: Cache Libvmi files
uses: actions/cache@v3
with:
path: libvmi/dist
key: libvmi-${{ matrix.os }}-${{ needs.init.outputs.LIBVMI_HASH }}
- name: Install Xen debball
run: |
sudo apt-get install -f ./xen/dist/xen-*.deb
- name: Install LibVMI
run: |
cd libvmi/dist
sudo apt install -f ./*.deb
sudo ldconfig
cd ../..
- name: Compile and install DRAKVUF
run: |
meson setup build --native-file llvm.ini
ninja -C build
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
scan-build:
runs-on: ubuntu-latest
needs:
- init
if: ${{ github.event_name == 'pull_request' }}
steps:
- uses: actions/checkout@v3
- name: Install dependencies
run: |
# Install packages
sudo apt-get update -q
sudo apt-get install -y \
clang clang-tools-15 llvm lld \
libjson-c-dev meson ninja-build
- name: Cache Xen debball
uses: actions/cache@v3
with:
path: xen/dist
key: xen-ubuntu-latest-${{ needs.init.outputs.XEN_HASH }}
- name: Cache Libvmi files
uses: actions/cache@v3
with:
path: libvmi/dist
key: libvmi-ubuntu-latest-${{ needs.init.outputs.LIBVMI_HASH }}
- name: Install Xen debball
run: |
sudo apt-get install -f ./xen/dist/xen-*.deb
- name: Install LibVMI
run: |
cd libvmi/dist
sudo apt install -f ./*.deb
sudo ldconfig
cd ../..
- name: Scan build
run: |
meson setup build --buildtype debug --native-file llvm.ini
analyze-build-15 -v --cdb build/compile_commands.json \
--status-bugs \
--disable-checker deadcode.DeadStores
cognitive-complexity:
runs-on: ubuntu-latest
needs:
- init
if: ${{ github.event_name == 'pull_request' }}
steps:
- uses: actions/checkout@v3
- name: Install dependencies
run: |
# Install packages
sudo apt-get update -q
sudo apt-get install -y \
clang clang-tools clang-tidy llvm lld \
libjson-c-dev meson ninja-build
- name: Cache Xen debball
uses: actions/cache@v3
with:
path: xen/dist
key: xen-ubuntu-latest-${{ needs.init.outputs.XEN_HASH }}
- name: Cache Libvmi files
uses: actions/cache@v3
with:
path: libvmi/dist
key: libvmi-ubuntu-latest-${{ needs.init.outputs.LIBVMI_HASH }}
- name: Install Xen debball
run: |
sudo apt-get install -f ./xen/dist/xen-*.deb
- name: Install LibVMI
run: |
cd libvmi/dist
sudo apt install -f ./*.deb
sudo ldconfig
cd ../..
- name: Calculate cognitive complexity for pr
run: |
cp scripts/complexity.sh /tmp
/tmp/complexity.sh
mv complexity.log /tmp/complexity.log
- uses: actions/checkout@v3
with:
ref: main
- name: Calculate cognitive complexity for main
run: /tmp/complexity.sh
- name: compare complexity
run: |
FUNCTIONS=$(tail -2 complexity.log | head -1 | awk '{ print $2 }')
THRESHOLD=$(tail -1 complexity.log | awk '{ print $2 }')
CURRENT_FUNCTIONS=$(tail -2 /tmp/complexity.log | head -1 | awk '{ print $2 }')
COMPLEXITY=$(tail -1 /tmp/complexity.log | awk '{ print $2 }')
if [ $CURRENT_FUNCTIONS -gt $FUNCTIONS ] || [ $COMPLEXITY -gt $THRESHOLD ]; then
echo "Please don't increase complexity of existing complex functions or introduce new ones"
echo "Showing diff of main (<) and this PR (>)"
diff complexity.log /tmp/complexity.log | egrep '>|<'
exit 1
fi
infer:
env:
CC: clang
CXX: clang++
VERSION: 1.1.0
runs-on: ubuntu-latest
needs:
- init
if: ${{ github.event_name == 'pull_request' }}
steps:
- name: Install dependencies
run: |
# Install packages
sudo apt-get update -q
sudo apt-get install -y clang libjson-c-dev meson ninja-build cmake llvm lld
sudo apt-get install -y curl libc6-dev openjdk-11-jdk-headless sqlite3 xz-utils zlib1g-dev opam
sudo apt-get clean
sudo apt-get -y autoremove
- name: free disk space
run: |
sudo systemd-run docker system prune --force --all --volumes
sudo systemd-run rm -rf \
"$AGENT_TOOLSDIRECTORY" \
/opt/* \
/usr/local/* \
/usr/share/az* \
/usr/share/dotnet \
/usr/share/gradle* \
/usr/share/miniconda \
/usr/share/swift \
/var/lib/gems \
/var/lib/mysql \
/var/lib/snapd
- name: Cache infer files
uses: actions/cache@v3
id: infer
with:
path: infer.tar.xz
key: infer
- name: get infer
if: steps.infer.outputs.cache-hit != 'true'
run: |
wget "https://github.com/facebook/infer/releases/download/v$VERSION/infer-linux64-v$VERSION.tar.xz"
mv infer-linux64-v$VERSION.tar.xz infer.tar.xz
- name: unpack infer
run: |
sudo tar -C /opt -xvf infer.tar.xz
sudo -E ln -s "/opt/infer-linux64-v$VERSION/bin/infer" /usr/bin/infer
mv infer.tar.xz /tmp
- name: Cache Xen debball
uses: actions/cache@v3
with:
path: xen/dist
key: xen-ubuntu-latest-${{ needs.init.outputs.XEN_HASH }}
- name: Cache Libvmi files
uses: actions/cache@v3
with:
path: libvmi/dist
key: libvmi-ubuntu-latest-${{ needs.init.outputs.LIBVMI_HASH }}
- name: Install Xen debball
run: |
sudo apt-get install -f ./xen/dist/xen-*.deb
- name: Install LibVMI
run: |
cd libvmi/dist
sudo apt install -f ./*.deb
sudo ldconfig
cd ../..
- uses: actions/checkout@v3
- name: run infer on pr
run: |
export PATH=/opt/infer/usr/local/bin:/opt/infer/usr/local/lib/infer/infer/bin:$PATH
printenv
which infer
git fetch origin
meson setup build --buildtype debug --native-file llvm.ini
cd build
git diff --name-only HEAD..origin/main > /tmp/index.txt
infer capture --compilation-database compile_commands.json
infer analyze --cost --bufferoverrun --changed-files-index /tmp/index.txt
mv infer-out /tmp
cp /tmp/infer-out/report.json /tmp
cp /tmp/infer-out/costs-report.json /tmp
- uses: actions/checkout@v3
with:
ref: main
- name: run infer on main
run: |
export PATH=/opt/infer/usr/local/bin:/opt/infer/usr/local/lib/infer/infer/bin:$PATH
meson setup build --buildtype debug --native-file llvm.ini
cd build
mv /tmp/infer-out .
infer capture --reactive --compilation-database compile_commands.json
infer analyze --reactive --cost --bufferoverrun --changed-files-index /tmp/index.txt
- name: check report diffs
run: |
export PATH=/opt/infer/usr/local/bin:/opt/infer/usr/local/lib/infer/infer/bin:$PATH
cd build
infer reportdiff --report-current /tmp/report.json --report-previous infer-out/report.json
jq '.' infer-out/differential/introduced.json
infer reportdiff --costs-current /tmp/costs-report.json --costs-previous infer-out/costs-report.json
jq '.' infer-out/differential/introduced.json
- name: move infer to cache path
run: mv /tmp/infer.tar.xz $GITHUB_WORKSPACE