Skip to content

Commit c5ba7aa

Browse files
authored
Improve CI (#133)
* run qemu tests * only test supporter archs * use ccache * compile with the shared / static flags to compile libafl qemu code. * fix tests
1 parent 13a023a commit c5ba7aa

5 files changed

Lines changed: 133 additions & 4 deletions

File tree

.github/actions/apt/action.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: apt
2+
description: Base packages for Linux jobs
3+
4+
runs:
5+
using: composite
6+
steps:
7+
- name: Enable apt source repositories
8+
shell: bash
9+
run: |
10+
sudo sed -i 's/^Types: deb$/Types: deb deb-src/' /etc/apt/sources.list.d/ubuntu.sources
11+
sudo sed -i 's/^# deb-src/deb-src/' /etc/apt/sources.list
12+
sudo apt-get update
13+
14+
- name: Install QEMU build dependencies
15+
shell: bash
16+
run: |
17+
sudo apt-get build-dep -y qemu
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: setup-llvm
2+
description: Setup LLVM
3+
4+
inputs:
5+
version:
6+
description: LLVM version to install
7+
required: false
8+
default: "22"
9+
10+
runs:
11+
using: composite
12+
steps:
13+
- name: Install LLVM ${{ inputs.version }}
14+
shell: bash
15+
run: |
16+
wget https://apt.llvm.org/llvm.sh
17+
chmod +x llvm.sh
18+
sudo ./llvm.sh "${{ inputs.version }}" all
19+
20+
- name: Export LLVM env
21+
shell: bash
22+
run: |
23+
{
24+
echo "/usr/lib/llvm-${{ inputs.version }}/bin"
25+
} >> "$GITHUB_PATH"
26+
27+
{
28+
echo "LLVM_CONFIG=llvm-config-${{ inputs.version }}"
29+
echo "LLVM_CONFIG_PATH=/usr/lib/llvm-${{ inputs.version }}/bin/llvm-config"
30+
echo "LIBCLANG_PATH=/usr/lib/llvm-${{ inputs.version }}/lib"
31+
} >> "$GITHUB_ENV"
32+
33+
- name: Symlink ASM headers
34+
shell: bash
35+
run: |
36+
if [ ! -e /usr/include/asm ]; then
37+
sudo ln -s /usr/include/asm-generic /usr/include/asm
38+
fi

.github/workflows/build_and_test.yaml

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,83 @@ on:
99

1010
env:
1111
CARGO_TERM_COLOR: always
12+
QEMU_TARGETS: |-
13+
x86_64-softmmu,x86_64-linux-user
14+
i386-softmmu,i386-linux-user
15+
arm-softmmu,arm-linux-user
16+
aarch64-softmmu,aarch64-linux-user
17+
mipsel-softmmu,mipsel-linux-user
18+
mips-softmmu,mips-linux-user
19+
ppc-softmmu,ppc-linux-user
20+
riscv32-softmmu,riscv32-linux-user
21+
riscv64-softmmu,riscv64-linux-user
22+
hexagon-linux-user
1223
1324
concurrency:
1425
group: ${{ github.workflow }}-${{ github.ref }}
1526
cancel-in-progress: true
1627

1728
jobs:
1829
build:
30+
name: build (${{ matrix.name }})
1931
runs-on: ubuntu-24.04
20-
container: registry.gitlab.com/qemu-project/qemu/qemu/ubuntu2204:latest
32+
strategy:
33+
fail-fast: false
34+
matrix:
35+
include:
36+
# QEMU binary builds + tests
37+
- name: gcc
38+
cc: gcc
39+
cxx: g++
40+
llvm: ""
41+
configure_extra: ""
42+
test: true
43+
- name: clang-22
44+
cc: clang
45+
cxx: clang++
46+
llvm: "22"
47+
configure_extra: ""
48+
test: true
49+
50+
# LibAFL QEMU builds
51+
- name: gcc-static-lib
52+
cc: gcc
53+
cxx: g++
54+
llvm: ""
55+
configure_extra: "--as-static-lib"
56+
test: false
57+
- name: gcc-shared-lib
58+
cc: gcc
59+
cxx: g++
60+
llvm: ""
61+
configure_extra: "--as-shared-lib"
62+
test: false
2163
steps:
2264
- uses: actions/checkout@v4
2365
- name: check submodules
2466
run: |
2567
git config --global --add safe.directory "$GITHUB_WORKSPACE"
2668
git submodule status
69+
- name: Install QEMU dependencies
70+
uses: ./.github/actions/apt
71+
- name: Install LLVM
72+
if: ${{ matrix.llvm != '' }}
73+
uses: ./.github/actions/setup-llvm
74+
with:
75+
version: ${{ matrix.llvm }}
76+
- name: Setup ccache
77+
uses: hendrikmuhs/ccache-action@v1.2
78+
with:
79+
key: ${{ matrix.name }}
80+
max-size: 2G
2781
- name: Build QEMU
28-
run: mkdir -p build && cd build && ../configure --enable-werror --disable-docs --enable-fdt=system && make -j $(expr $(nproc) + 1)
82+
run: |
83+
targets=$(echo "$QEMU_TARGETS" | paste -sd,)
84+
mkdir -p build && cd build
85+
../configure --cc="ccache ${{ matrix.cc }}" --cxx="ccache ${{ matrix.cxx }}" \
86+
--target-list="$targets" ${{ matrix.configure_extra }} \
87+
--enable-werror --disable-docs --enable-fdt=system
88+
make -j $(expr $(nproc) + 1)
89+
- name: Test QEMU
90+
if: ${{ matrix.test }}
91+
run: make -C build check

accel/tcg/translator.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,10 @@ void translator_loop(CPUState *cpu, TranslationBlock *tb, int *max_insns,
185185
libafl_gen_cur_pc = db->pc_next;
186186
libafl_qemu_breakpoint_run(libafl_gen_cur_pc);
187187

188+
int saved_record_start = db->record_start;
189+
int saved_record_len = db->record_len;
190+
bool backdoor_triggered = false;
191+
188192
// 0x0f, 0x3a, 0xf2, 0x44
189193
uint8_t backdoor = translator_ldub(cpu_env(cpu), db, db->pc_next);
190194
if (backdoor == 0x0f) {
@@ -197,10 +201,12 @@ void translator_loop(CPUState *cpu, TranslationBlock *tb, int *max_insns,
197201
libafl_qemu_hook_backdoor_run(db->pc_next);
198202

199203
db->pc_next += 4;
204+
backdoor_triggered = true;
200205
goto post_translate_insn;
201206
} else if (backdoor == 0x66) {
202207
// First update pc_next to restart at next instruction
203208
db->pc_next += 4;
209+
backdoor_triggered = true;
204210

205211
TCGv_i64 tmp0 = tcg_constant_i64(db->pc_next);
206212
gen_helper_libafl_qemu_handle_custom_insn(tcg_env, tmp0, tcg_constant_i32(LIBAFL_CUSTOM_INSN_LIBAFL));
@@ -209,6 +215,12 @@ void translator_loop(CPUState *cpu, TranslationBlock *tb, int *max_insns,
209215
}
210216
}
211217

218+
if (!backdoor_triggered) {
219+
// backdoor not triggered, restore record as it was before
220+
db->record_start = saved_record_start;
221+
db->record_len = saved_record_len;
222+
}
223+
212224
//// --- End LibAFL code ---
213225

214226
/*

tests/qtest/libqtest.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,7 +1041,6 @@ static bool qtest_qom_has_concrete_type(const char *parent_typename,
10411041
QObject *qobj;
10421042
QString *qstr;
10431043
QDict *devinfo;
1044-
int idx;
10451044

10461045
if (!list) {
10471046
QDict *resp;
@@ -1066,7 +1065,7 @@ static bool qtest_qom_has_concrete_type(const char *parent_typename,
10661065
}
10671066
}
10681067

1069-
for (p = qlist_first(list), idx = 0; p; p = qlist_next(p), idx++) {
1068+
for (p = qlist_first(list); p; p = qlist_next(p)) {
10701069
devinfo = qobject_to(QDict, qlist_entry_obj(p));
10711070
g_assert(devinfo);
10721071

0 commit comments

Comments
 (0)