mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-22 08:53:29 +00:00
Add syscall test framwork from gvisor
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
8e199f46ef
commit
e2f3932cb8
1
regression/.gitignore
vendored
Normal file
1
regression/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
build/
|
@ -1,47 +1,45 @@
|
||||
MAKEFLAGS += --no-builtin-rules # Prevent the implicit rules from compiling ".c" or ".s" files automatically.
|
||||
APPS := ../apps
|
||||
BUILD_DIR := ./build
|
||||
INITRAMFS := ./initramfs
|
||||
MKFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST)))
|
||||
CUR_DIR := $(patsubst %/,%,$(dir $(MKFILE_PATH)))
|
||||
BUILD_DIR := $(CUR_DIR)/build
|
||||
INITRAMFS := $(BUILD_DIR)/initramfs
|
||||
RAMDISK := $(BUILD_DIR)/ramdisk.cpio
|
||||
SHELL := /bin/bash
|
||||
|
||||
ifneq (, $(wildcard $(APPS)/. ))
|
||||
APPS_DIRS := $(shell find $(APPS) -type d 2>/dev/null | sed 's/ /\\ /g' | sed 's/:/\\:/g' || true)
|
||||
APPS_FILES := $(shell find $(APPS) -type f 2>/dev/null | sed 's/ /\\ /g' | sed 's/:/\\:/g' || true)
|
||||
endif
|
||||
|
||||
ifneq (, $(wildcard $(INITRAMFS)/. ))
|
||||
INITRAMFS_DIRS := $(shell find $(INITRAMFS) -type d 2>/dev/null | sed 's/ /\\ /g' | sed 's/:/\\:/g' || true)
|
||||
INITRAMFS_FILES := $(shell find $(INITRAMFS) -type f 2>/dev/null | sed 's/ /\\ /g' | sed 's/:/\\:/g' || true)
|
||||
endif
|
||||
|
||||
.PHONY: all clean
|
||||
|
||||
.PHONY: all clean prepare_libs copy_special_files
|
||||
all: build
|
||||
|
||||
all: $(RAMDISK)
|
||||
|
||||
$(INITRAMFS): $(APPS) $(APPS_DIRS) $(APPS_FILES)
|
||||
$(INITRAMFS):
|
||||
@rm -rf $@ && mkdir -p $@
|
||||
# Copy Apps
|
||||
@cp -a $(APPS)/* $@
|
||||
@cd $@ && find . \( -name "*.s" -o -name "*.c" -o -name "Makefile" -o -name "README.md" \) -delete
|
||||
# Mkdir folders
|
||||
@# Mkdir necessary folders
|
||||
@mkdir -p $@/tmp
|
||||
@mkdir -p $@/test
|
||||
@mkdir -p $@/opt
|
||||
@mkdir -p $@/lib64
|
||||
@mkdir -p $@/lib/x86_64-linux-gnu
|
||||
# Copy libs
|
||||
@# Copy necessary libs
|
||||
@cp -L /lib64/ld-linux-x86-64.so.2 $@/lib64
|
||||
@cp -L /lib/x86_64-linux-gnu/libc.so.6 $@/lib/x86_64-linux-gnu
|
||||
@cp -L /lib/x86_64-linux-gnu/libstdc++.so.6 $@/lib/x86_64-linux-gnu
|
||||
@cp -L /lib/x86_64-linux-gnu/libm.so.6 $@/lib/x86_64-linux-gnu
|
||||
@cp -L /lib/x86_64-linux-gnu/libgcc_s.so.1 $@/lib/x86_64-linux-gnu
|
||||
@cp -L /lib/x86_64-linux-gnu/libpthread.so.0 $@/lib/x86_64-linux-gnu
|
||||
@# Copy from apps
|
||||
@make --no-print-directory -C apps
|
||||
ifeq ($(ENABLE_SYSCALL_TEST), 1)
|
||||
@# Copy syscall test suite
|
||||
@make --no-print-directory -C syscall_test
|
||||
endif
|
||||
|
||||
$(RAMDISK): $(INITRAMFS) $(INITRAMFS_DIRS) $(INITRAMFS_FILES)
|
||||
@echo "Generating the ramdisk image..."
|
||||
@rm -rf $(BUILD_DIR) && mkdir -p $(BUILD_DIR)
|
||||
@./mkinitramfs $(INITRAMFS) $@
|
||||
@(cd $(INITRAMFS); find . | cpio -o -H newc) > $@
|
||||
|
||||
build: $(RAMDISK)
|
||||
|
||||
clean:
|
||||
@rm -rf $(INITRAMFS) $(BUILD_DIR)
|
||||
@rm -rf $(BUILD_DIR)
|
12
regression/apps/Makefile
Normal file
12
regression/apps/Makefile
Normal file
@ -0,0 +1,12 @@
|
||||
MAKEFLAGS += --no-builtin-rules # Prevent the implicit rules from compiling ".c" or ".s" files automatically.
|
||||
MKFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST)))
|
||||
CUR_DIR := $(patsubst %/,%,$(dir $(MKFILE_PATH)))
|
||||
INITRAMFS ?= $(CUR_DIR)/../build/initramfs
|
||||
|
||||
.PHONY: all
|
||||
|
||||
all: build
|
||||
|
||||
build:
|
||||
@cp -a $(CUR_DIR)/* $(INITRAMFS)
|
||||
@cd $(INITRAMFS) && find . \( -name "*.s" -o -name "*.c" -o -name "Makefile" -o -name "README.md" \) -delete
|
@ -1,15 +0,0 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
if [ $# -ne 2 ]; then
|
||||
echo "Usage: mkinitramfs <dir> <cpio>"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -d "$1" ]; then
|
||||
echo "Creating $2 from $1"
|
||||
(cd "$1"; find . | cpio -o -H newc) > "$2"
|
||||
else
|
||||
echo "The first argument must be a directory"
|
||||
exit 1
|
||||
fi
|
43
regression/syscall_test/Makefile
Normal file
43
regression/syscall_test/Makefile
Normal file
@ -0,0 +1,43 @@
|
||||
TESTS ?= open_test read_test
|
||||
|
||||
MKFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST)))
|
||||
CUR_DIR := $(patsubst %/,%,$(dir $(MKFILE_PATH)))
|
||||
BUILD_DIR := $(CUR_DIR)/../build
|
||||
SRC_DIR := $(BUILD_DIR)/gvisor_src
|
||||
BIN_DIR := $(BUILD_DIR)/syscall_test_bins
|
||||
INITRAMFS ?= $(CUR_DIR)/../build/initramfs
|
||||
TARGET_DIR := $(INITRAMFS)/opt/syscall_test
|
||||
RUN_BASH := $(CUR_DIR)/run_syscall_test.sh
|
||||
BLOCK_LIST := $(CUR_DIR)/blocklists
|
||||
|
||||
.PHONY: all clean
|
||||
|
||||
all: $(TESTS)
|
||||
|
||||
$(SRC_DIR):
|
||||
@if ! type bazel > /dev/null; then \
|
||||
echo "bazel is not installed, please run $(CUR_DIR)/install_bazel.sh with sudo permission to install it."; \
|
||||
exit 1 ; \
|
||||
fi
|
||||
@rm -rf $@ && mkdir -p $@
|
||||
@cd $@ && git clone -b 20200921.0 https://github.com/jinzhao-dev/gvisor.git .
|
||||
|
||||
$(BIN_DIR): $(SRC_DIR)
|
||||
@rm -rf $@ && mkdir -p $@
|
||||
@cd $(SRC_DIR) && bazel build --test_tag_filters=native //test/syscalls/...
|
||||
@cp $(SRC_DIR)/bazel-bin/test/syscalls/linux/*_test $@
|
||||
|
||||
$(TARGET_DIR): $(RUN_BASH) $(BLOCK_LIST) $(BIN_DIR)
|
||||
@rm -rf $@ && mkdir -p $@
|
||||
@# Prepare tests dir for test binaries
|
||||
@mkdir $@/tests
|
||||
@# Copy blocklists
|
||||
@cp -rf $(BLOCK_LIST) $@
|
||||
@# Copy bash script
|
||||
@cp -f $(RUN_BASH) $@
|
||||
|
||||
$(TESTS): $(TARGET_DIR)
|
||||
@cp -f $(BIN_DIR)/$@ $(TARGET_DIR)/tests
|
||||
|
||||
clean:
|
||||
@rm -rf $(BIN_DIR) $(TARGET_DIR)
|
15
regression/syscall_test/blocklists/open_test
Normal file
15
regression/syscall_test/blocklists/open_test
Normal file
@ -0,0 +1,15 @@
|
||||
OpenTest.AppendConcurrentWrite
|
||||
OpenTest.CanTruncateReadOnly
|
||||
OpenTest.CanTruncateWithStrangePermissions
|
||||
OpenTest.CanTruncateReadOnlyNoWritePermission_NoRandomSave
|
||||
OpenTest.CanTruncateWriteOnlyNoReadPermission_NoRandomSave
|
||||
OpenTest.FileNotDirectory
|
||||
OpenTest.MustCreateExisting
|
||||
OpenTest.NameTooLong
|
||||
OpenTest.Null
|
||||
OpenTest.OTrunc
|
||||
OpenTest.OTruncAndReadOnlyDir
|
||||
OpenTest.OpenNoFollowStillFollowsLinksInPath
|
||||
OpenTest.OpenNonDirectoryWithTrailingSlash
|
||||
OpenTest.SymlinkRecurse
|
||||
OpenTest.Truncate
|
2
regression/syscall_test/blocklists/read_test
Normal file
2
regression/syscall_test/blocklists/read_test
Normal file
@ -0,0 +1,2 @@
|
||||
ReadTest.EofAfterRead
|
||||
ReadTest.ZeroBuffer
|
17
regression/syscall_test/install_bazel.sh
Executable file
17
regression/syscall_test/install_bazel.sh
Executable file
@ -0,0 +1,17 @@
|
||||
#! /bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
if type bazel > /dev/null; then
|
||||
echo "Bazel has been installed already"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
apt update && apt install curl gnupg -y
|
||||
curl -fsSL https://bazel.build/bazel-release.pub.gpg | gpg --dearmor > bazel.gpg
|
||||
mv bazel.gpg /etc/apt/trusted.gpg.d/
|
||||
|
||||
echo 'deb [arch=amd64] https://storage.googleapis.com/bazel-apt stable jdk1.8' | tee /etc/apt/sources.list.d/bazel.list
|
||||
apt update && apt install bazel=5.4.0 -y
|
||||
|
||||
echo "Bazel is installed successfully"
|
60
regression/syscall_test/run_syscall_test.sh
Executable file
60
regression/syscall_test/run_syscall_test.sh
Executable file
@ -0,0 +1,60 @@
|
||||
#!/bin/sh
|
||||
|
||||
SCRIPT_DIR=$(dirname "$0")
|
||||
TEST_BIN_DIR=$SCRIPT_DIR/tests
|
||||
BLOCKLIST_DIR=$SCRIPT_DIR/blocklists
|
||||
FAIL_CASES=$SCRIPT_DIR/fail_cases
|
||||
BLOCK=""
|
||||
TESTS=0
|
||||
PASSED_TESTS=0
|
||||
RESULT=0
|
||||
GREEN='\033[0;32m'
|
||||
RED='\033[0;31m'
|
||||
NC='\033[0m'
|
||||
|
||||
get_blocklist_subtests(){
|
||||
if [ -f $BLOCKLIST_DIR/$1 ]; then
|
||||
BLOCK=$(sed ':a;N;$!ba;s/\n/:/g' $BLOCKLIST_DIR/$1)
|
||||
return 0
|
||||
else
|
||||
BLOCK=""
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
run_one_test(){
|
||||
echo -e "Run Test Case: $1"
|
||||
ret=0
|
||||
if [ -f $TEST_BIN_DIR/$1 ]; then
|
||||
get_blocklist_subtests $1
|
||||
$TEST_BIN_DIR/$1 --gtest_filter=-$BLOCK
|
||||
ret=$?
|
||||
else
|
||||
echo -e "Warning: $1 test does not exit"
|
||||
ret=1
|
||||
fi
|
||||
echo ""
|
||||
return $ret
|
||||
}
|
||||
|
||||
rm -f $FAIL_CASES && touch $FAIL_CASES
|
||||
|
||||
for syscall_test in $(find $TEST_BIN_DIR/. -name \*_test) ; do
|
||||
test_name=$(basename "$syscall_test")
|
||||
run_one_test $test_name
|
||||
if [ $? -eq 0 ] && PASSED_TESTS=$((PASSED_TESTS+1));then
|
||||
TESTS=$((TESTS+1))
|
||||
else
|
||||
echo -e "$test_name" >> $FAIL_CASES
|
||||
TESTS=$((TESTS+1))
|
||||
fi
|
||||
done
|
||||
|
||||
echo -e "$GREEN$PASSED_TESTS$NC of $GREEN$TESTS$NC test cases are passed."
|
||||
[ $PASSED_TESTS -ne $TESTS ] && RESULT=1
|
||||
if [ $TESTS != $PASSED_TESTS ]; then
|
||||
echo -e "The $RED$(($TESTS-$PASSED_TESTS))$NC failed test cases in this run are as follows:"
|
||||
cat $FAIL_CASES
|
||||
fi
|
||||
|
||||
exit $RESULT
|
Reference in New Issue
Block a user