Skip to content

Commit 37cdc54

Browse files
pb8ozulinx86
authored andcommitted
test: rework test_error_code to not need a separate initrd image
Add the source of the binary since it was missing, and include it in our rootfs images. This avoids the need for a separate initrd image. Signed-off-by: Pablo Barbáchano <pablob@amazon.com>
1 parent fa43105 commit 37cdc54

File tree

3 files changed

+38
-9
lines changed

3 files changed

+38
-9
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#include <assert.h>
2+
#include <fcntl.h>
3+
#include <stdio.h>
4+
#include <sys/mman.h>
5+
#include <sys/mount.h>
6+
7+
/*
8+
* We try to trigger ENOSYS by mapping a file into memory and then tries to
9+
* load the content from an offset in the file bigger than its length into a
10+
* register asm volatile ("ldr %0, [%1], 4" : "=r" (ret), "+r" (buf));
11+
*/
12+
13+
int main()
14+
{
15+
int ret, fd;
16+
char *buf;
17+
18+
// Assume /dev is mounted
19+
fprintf(stderr, "open /dev/mem\n");
20+
fd = open("/dev/mem", O_RDWR);
21+
assert(fd > 0);
22+
23+
buf = mmap(NULL, 65536, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0xf0000);
24+
assert(buf != MAP_FAILED);
25+
26+
fprintf(stderr, "try to ldr\n");
27+
asm volatile("ldr %0, [%1], 4" : "=r" (ret), "+r" (buf));
28+
29+
fprintf(stderr, "success\n");
30+
return 0;
31+
}

resources/rebuild.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,9 @@ BIN=overlay/usr/local/bin
167167
compile_and_install $BIN/init.c $BIN/init
168168
compile_and_install $BIN/fillmem.c $BIN/fillmem
169169
compile_and_install $BIN/readmem.c $BIN/readmem
170+
if [ $ARCH == "aarch64" ]; then
171+
compile_and_install $BIN/devmemread.c $BIN/devmemread
172+
fi
170173

171174
# build_rootfs ubuntu-18.04 bionic
172175
# build_rootfs ubuntu-20.04 focal

tests/integration_tests/functional/test_error_code.py

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,32 +14,27 @@
1414
reason="The error code returned on aarch64 will not be returned on x86 "
1515
"under the same conditions.",
1616
)
17-
def test_enosys_error_code(uvm_plain, artifact_dir):
17+
def test_enosys_error_code(uvm_plain):
1818
"""
1919
Test that ENOSYS error is caught and firecracker exits gracefully.
2020
"""
21-
# On aarch64 we trigger this error by adding to initrd a C program that
21+
# On aarch64 we trigger this error by running a C program that
2222
# maps a file into memory and then tries to load the content from an
2323
# offset in the file bigger than its length into a register asm volatile
2424
# ("ldr %0, [%1], 4" : "=r" (ret), "+r" (buf));
2525
vm = uvm_plain
26-
vm.jailer.daemonize = False
2726
vm.spawn()
2827
vm.memory_monitor = None
29-
30-
vm.initrd_file = artifact_dir / "initrd_enosys.img"
3128
vm.basic_config(
32-
add_root_device=False,
3329
vcpu_count=1,
34-
boot_args="console=ttyS0 reboot=k panic=1 pci=off",
35-
use_initrd=True,
30+
boot_args="reboot=k panic=1 pci=off init=/usr/local/bin/devmemread",
3631
)
3732
vm.start()
3833

3934
# Check if FC process is closed
4035
wait_process_termination(vm.jailer_clone_pid)
4136

4237
vm.check_log_message(
43-
"Received ENOSYS error because KVM failed to" " emulate an instruction."
38+
"Received ENOSYS error because KVM failed to emulate an instruction."
4439
)
4540
vm.check_log_message("Vmm is stopping.")

0 commit comments

Comments
 (0)