11#! /bin/bash
2- # Run GNU SMACK tests in QEMU with SMACK-enabled kernel
2+ # Run GNU SMACK/ROOTFS tests in QEMU with SMACK-enabled kernel
33# Usage: run-gnu-tests-smack-ci.sh [GNU_DIR] [OUTPUT_DIR]
44# spell-checker:ignore rootfs zstd unzstd cpio newc nographic smackfs devtmpfs tmpfs poweroff libm libgcc libpthread libdl librt sysfs rwxat setuidgid
55set -e
66
77SCRIPT_DIR=" $( cd " $( dirname " $0 " ) " && pwd) "
88REPO_DIR=" $( dirname " $SCRIPT_DIR " ) "
99GNU_DIR=" ${1:- $REPO_DIR / ../ gnu} "
10- OUTPUT_DIR=" ${2:- $REPO_DIR / target/ smack -test-results} "
11- SMACK_DIR =" $REPO_DIR /target/smack -test"
10+ OUTPUT_DIR=" ${2:- $REPO_DIR / target/ qemu -test-results} "
11+ QEMU_DIR =" $REPO_DIR /target/qemu -test"
1212
13- echo " Setting up SMACK test environment..."
14- rm -rf " $SMACK_DIR "
15- mkdir -p " $SMACK_DIR " /{rootfs/{bin,lib64,proc,sys,dev,tmp,etc,gnu},kernel}
13+ echo " Setting up SMACK/ROOTFS test environment..."
14+ rm -rf " $QEMU_DIR "
15+ mkdir -p " $QEMU_DIR " /{rootfs/{bin,lib64,proc,sys,dev,tmp,etc,gnu},kernel}
1616
1717# Download Arch Linux kernel (has SMACK built-in)
1818if [ ! -f /tmp/arch-vmlinuz ]; then
@@ -24,31 +24,31 @@ if [ ! -f /tmp/arch-vmlinuz ]; then
2424 mv " /tmp/$VMLINUZ_PATH " /tmp/arch-vmlinuz
2525 rm -rf /tmp/usr /tmp/arch-kernel.pkg.tar /tmp/arch-kernel.pkg.tar.zst
2626fi
27- cp /tmp/arch-vmlinuz " $SMACK_DIR /kernel/vmlinuz"
27+ cp /tmp/arch-vmlinuz " $QEMU_DIR /kernel/vmlinuz"
2828
2929# Setup busybox
3030BUSYBOX=/tmp/busybox
3131[ -f " $BUSYBOX " ] || curl -sL -o " $BUSYBOX " https://busybox.net/downloads/binaries/1.35.0-x86_64-linux-musl/busybox
3232chmod +x " $BUSYBOX "
33- cp " $BUSYBOX " " $SMACK_DIR /rootfs/bin/"
34- (cd " $SMACK_DIR /rootfs/bin" && " $BUSYBOX " --list | xargs -I{} ln -sf busybox {} 2> /dev/null)
33+ cp " $BUSYBOX " " $QEMU_DIR /rootfs/bin/"
34+ (cd " $QEMU_DIR /rootfs/bin" && " $BUSYBOX " --list | xargs -I{} ln -sf busybox {} 2> /dev/null)
3535
3636# Copy required libraries
3737for lib in ld-linux-x86-64.so.2 libc.so.6 libm.so.6 libgcc_s.so.1 libpthread.so.0 libdl.so.2 librt.so.1; do
3838 path=$( ldconfig -p | grep " $lib " | head -1 | awk ' {print $NF}' )
39- [ -n " $path " ] && [ -f " $path " ] && cp -L " $path " " $SMACK_DIR /rootfs/lib64/" 2> /dev/null || true
39+ [ -n " $path " ] && [ -f " $path " ] && cp -L " $path " " $QEMU_DIR /rootfs/lib64/" 2> /dev/null || true
4040done
4141
4242# Create minimal config files
43- echo -e " root:x:0:0:root:/root:/bin/sh\nnobody:x:65534:65534:nobody:/nonexistent:/bin/sh" > " $SMACK_DIR /rootfs/etc/passwd"
44- echo -e " root:x:0:\nnobody:x:65534:" > " $SMACK_DIR /rootfs/etc/group"
45- touch " $SMACK_DIR /rootfs/etc/mtab"
43+ echo -e " root:x:0:0:root:/root:/bin/sh\nnobody:x:65534:65534:nobody:/nonexistent:/bin/sh" > " $QEMU_DIR /rootfs/etc/passwd"
44+ echo -e " root:x:0:\nnobody:x:65534:" > " $QEMU_DIR /rootfs/etc/group"
45+ touch " $QEMU_DIR /rootfs/etc/mtab"
4646
4747# Copy GNU tests
48- cp -r " $GNU_DIR /tests" " $SMACK_DIR /rootfs/gnu/"
48+ cp -r " $GNU_DIR /tests" " $QEMU_DIR /rootfs/gnu/"
4949
5050# Create init script
51- cat > " $SMACK_DIR /rootfs/init" << 'INIT '
51+ cat > " $QEMU_DIR /rootfs/init" << 'INIT '
5252#!/bin/sh
5353mount -t proc proc /proc
5454mount -t sysfs sys /sys
7373echo "EXIT:$?"
7474poweroff -f
7575INIT
76- chmod +x " $SMACK_DIR /rootfs/init"
76+ chmod +x " $QEMU_DIR /rootfs/init"
7777
78- # Build utilities with SMACK support
79- echo " Building utilities with SMACK support ..."
80- cargo build --release --manifest-path=" $REPO_DIR /Cargo.toml" --package uu_id --features uu_id/smack --package uu_ls --features uu_ls/smack --package uu_mkdir --features uu_mkdir/smack --package uu_mkfifo --features uu_mkfifo/smack --package uu_mknod --features uu_mknod/smack
78+ # Build utilities for SMACK/ROOTFS tests
79+ echo " Building utilities for SMACK/ROOTFS tests ..."
80+ cargo build --release --manifest-path=" $REPO_DIR /Cargo.toml" --package uu_id --features uu_id/smack --package uu_ls --features uu_ls/smack --package uu_mkdir --features uu_mkdir/smack --package uu_mkfifo --features uu_mkfifo/smack --package uu_mknod --features uu_mknod/smack --package uu_df
8181
82- # Find SMACK tests
83- SMACK_TESTS =$( grep -l ' require_smack_' -r " $GNU_DIR /tests/" 2> /dev/null || true)
84- [ -z " $SMACK_TESTS " ] && { echo " No SMACK tests found" ; exit 0; }
82+ # Find SMACK tests and tests requiring rootfs in mtab (only available in QEMU environment)
83+ QEMU_TESTS =$( grep -l -E ' require_smack_|rootfs in mtab ' -r " $GNU_DIR /tests/" 2> /dev/null | sort -u || true)
84+ [ -z " $QEMU_TESTS " ] && { echo " No SMACK/ROOTFS tests found" ; exit 0; }
8585
86- echo " Found $( echo " $SMACK_TESTS " | wc -l) SMACK tests"
86+ echo " Found $( echo " $QEMU_TESTS " | wc -l) SMACK/ROOTFS tests"
8787
8888# Create output directory
8989rm -rf " $OUTPUT_DIR "
9090mkdir -p " $OUTPUT_DIR "
9191
9292# Run each test
93- for TEST_PATH in $SMACK_TESTS ; do
93+ for TEST_PATH in $QEMU_TESTS ; do
9494 TEST_REL=" ${TEST_PATH# " $GNU_DIR " / tests/ } "
9595 TEST_DIR=$( dirname " $TEST_REL " )
9696 TEST_NAME=$( basename " $TEST_REL " .sh)
@@ -104,12 +104,12 @@ for TEST_PATH in $SMACK_TESTS; do
104104 fi
105105
106106 # Create working copy
107- WORK=" /tmp/smack -test-$$ "
107+ WORK=" /tmp/qemu -test-$$ "
108108 rm -rf " $WORK " " $WORK .gz"
109- cp -a " $SMACK_DIR /rootfs" " $WORK "
109+ cp -a " $QEMU_DIR /rootfs" " $WORK "
110110
111- # Copy built utilities with SMACK support
112- for U in id ls mkdir mkfifo mknod; do
111+ # Copy built utilities for SMACK/ROOTFS tests
112+ for U in id ls mkdir mkfifo mknod df ; do
113113 rm -f " $WORK /bin/$U "
114114 cp " $REPO_DIR /target/release/$U " " $WORK /bin/$U "
115115 done
@@ -126,7 +126,7 @@ for TEST_PATH in $SMACK_TESTS; do
126126 (cd " $WORK " && find . | cpio -o -H newc 2> /dev/null | gzip > " $WORK .gz" )
127127
128128 OUTPUT=$( timeout 120 qemu-system-x86_64 \
129- -kernel " $SMACK_DIR /kernel/vmlinuz" \
129+ -kernel " $QEMU_DIR /kernel/vmlinuz" \
130130 -initrd " $WORK .gz" \
131131 -append " console=ttyS0 quiet panic=-1 security=smack lsm=smack" \
132132 -nographic -m 256M -no-reboot 2>&1 ) || true
0 commit comments