diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a1431d6..ea061a6 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -2,9 +2,7 @@ name: Rap-booting and testing on: push: - branches: [ "main" ] pull_request: - branches: [ "main" ] env: CARGO_TERM_COLOR: always @@ -21,22 +19,11 @@ jobs: - name: Code Formatting Check run: cd rap && cargo fmt --check - - name: Set up Python - uses: actions/setup-python@v5 - with: - python-version: '3.x' - - - name: Install ninja - run: | - pip install ninja - - name: Build RAP - run: | - chmod +x ./install.sh - ./install.sh + run: ./install.sh + + - run: sudo apt install colorized-logs -y # Insall ansi2txt - name: Check test cases - run: cd tests && cargo +nightly-2024-10-12 rap -F -M + run: cd tests && ./batch.sh -F -M - - name: Check rap - run: cd rap && cargo +nightly-2024-10-12 rap -F -M diff --git a/.gitignore b/.gitignore index 18823b8..87d2dde 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ .vscode/ target/ Cargo.lock +rap.txt diff --git a/install.sh b/install.sh index 0fc6360..65ee1bb 100755 --- a/install.sh +++ b/install.sh @@ -2,87 +2,6 @@ set -e -# Define color variables -BLUE='\033[0;34m' -GREEN='\033[0;32m' -NC='\033[0m' # No Color +cargo install --path rap -cd rap && cargo clean - -case "$SHELL" in - *zsh) - printf "Detecting shell context success: running on %bZsh%b.\n" "${BLUE}" "${NC}" - export SHELL_CONFIG=~/.zshrc - ;; - *bash) - printf "Detecting shell context success: running on %bBash%b.\n" "${BLUE}" "${NC}" - export SHELL_CONFIG=~/.bashrc - ;; - *) - printf "%bDetecting shell context failed.%b\n" "${RED}" "${NC}" - exit 1 - ;; -esac - -# Set the library path to be added -#LIBRARY_PATH="$HOME/.rustup/toolchains/nightly-2023-10-05-x86_64-unknown-linux-gnu/lib" -toolchain_date="nightly-2024-10-12" -toolchain_file="rust-toolchain.toml" -if [ ! -f "$toolchain_file" ]; then - printf "%bError: %s does not exist.%b\n" "${RED}" "$toolchain_file" "${NC}" - exit 1 -fi - -if ! rustup toolchain install "$toolchain_date" --profile minimal --component rustc-dev,rust-src,llvm-tools-preview; then - printf "%bError: Failed to install toolchain %s.%b\n" "${RED}" "$toolchain_date" "${NC}" - exit 1 -fi - -os_type=$(uname -s) -arch_type=$(uname -m) - -if [ "$os_type" = "Linux" ]; then - # Update the channel field in rust-toolchain.toml - toolchain="$toolchain_date-x86_64-unknown-linux-gnu" - toolchain_lib="$HOME/.rustup/toolchains/$toolchain/lib" - printf "%bDetected OS: Linux. Setting toolchain to %s%b\n" "${BLUE}" "$toolchain" "${NC}" - sed -i.bak "s/^channel = \".*\"/channel = \"$toolchain\"/" "$toolchain_file" - - if ! grep -q "LD_LIBRARY_PATH.*$toolchain_lib" "$SHELL_CONFIG"; then - if grep -q "LD_LIBRARY_PATH" "$SHELL_CONFIG"; then - export LD_LIBRARY_PATH="$toolchain_lib:$LD_LIBRARY_PATH" - sed -i '/LD_LIBRARY_PATH/d' "$SHELL_CONFIG" - printf "%bOld LD_LIBRARY_PATH definition has been removed from %s.%b\n" "${GREEN}" "$SHELL_CONFIG" "${NC}" - else - export LD_LIBRARY_PATH="$toolchain_lib" - fi - echo "export LD_LIBRARY_PATH=\"${LD_LIBRARY_PATH}\"" >> "$SHELL_CONFIG" - printf "%bEnvironment variables have been successfully written to %s.%b\n" "${GREEN}" "$SHELL_CONFIG" "${NC}" - fi -elif [ "$os_type" = "Darwin" ]; then - if [ "$arch_type" = "x86_64" ]; then - toolchain="$toolchain_date-x86_64-apple-darwin" - toolchain_lib="$HOME/.rustup/toolchain/$toolchain/lib" - else - toolchain="$toolchain_date-aarch64-apple-darwin" - toolchain_lib="$HOME/.rustup/toolchain/$toolchain/lib" - fi - printf "%bDetected OS: macOS. Setting toolchain to %s%b\n" "${BLUE}" "$toolchain" "${NC}" - sed -i.bak "s/^channel = \".*\"/channel = \"$toolchain\"/" "$toolchain_file" - - if ! grep -q "DYLD_LIBRARY_PATH.*$toolchain_lib" "$SHELL_CONFIG"; then - if grep -q "DYLD_LIBRARY_PATH" "$SHELL_CONFIG"; then - export DYLD_LIBRARY_PATH="$toolchain_lib:$DYLD_LIBRARY_PATH" - sed -i '/DYLD_LIBRARY_PATH/d' "$SHELL_CONFIG" - printf "%bOld DYLD_LIBRARY_PATH definition has been removed from %s.%b\n" "${GREEN}" "$SHELL_CONFIG" "${NC}" - else - export DYLD_LIBRARY_PATH="$toolchain_lib" - fi - echo "export DYLD_LIBRARY_PATH=\"${DYLD_LIBRARY_PATH}\"" >> "$SHELL_CONFIG" - printf "%bEnvironment variables have been successfully written to %s.%b\n" "${GREEN}" "$SHELL_CONFIG" "${NC}" - fi -fi - -cargo install --path . - -printf "%bTo apply the changes, you may need to run: %bsource %s%b\n" "${GREEN}" "${BLUE}" "$SHELL_CONFIG" "${NC}" +cargo rap -help diff --git a/rap/rust-toolchain.toml b/rust-toolchain.toml similarity index 100% rename from rap/rust-toolchain.toml rename to rust-toolchain.toml diff --git a/tests/CI_leak/batch.sh b/tests/CI_leak/batch.sh deleted file mode 100755 index 73dee7f..0000000 --- a/tests/CI_leak/batch.sh +++ /dev/null @@ -1,35 +0,0 @@ -#!/bin/bash -#该脚本在目录下为每个Cargo项目执行相同的命令直到报错 - -if [ $# -eq 0 ]; then - #脚本无参数时执行cargo clean - #Example: batch.sh - cmd="cargo clean" -else - #脚本有参数时按照给定参数执行cargo命令 - #Example: batch.sh -uaf - cmd="cargo rap $@" -fi - -# 查找并编译当前目录下的所有 Rust 项目 -find . -type f -name "Cargo.toml" | while read -r cargo_file; do - # 获取 Cargo.toml 文件所在的目录 - project_dir=$(dirname "$cargo_file") - - echo "Processing project in: $project_dir" - - # 切换到项目目录 - pushd "$project_dir" > /dev/null - - $cmd - if [ $? -ne 0 ]; then - # 如果命令失败,打印错误信息并退出循环 - echo "Error: '$cmd' failed in $project_dir" - popd > /dev/null - exit 1 - fi - - # 返回原始目录 - popd > /dev/null -done - diff --git a/tests/CI_uaf/batch.sh b/tests/CI_uaf/batch.sh deleted file mode 100755 index 73dee7f..0000000 --- a/tests/CI_uaf/batch.sh +++ /dev/null @@ -1,35 +0,0 @@ -#!/bin/bash -#该脚本在目录下为每个Cargo项目执行相同的命令直到报错 - -if [ $# -eq 0 ]; then - #脚本无参数时执行cargo clean - #Example: batch.sh - cmd="cargo clean" -else - #脚本有参数时按照给定参数执行cargo命令 - #Example: batch.sh -uaf - cmd="cargo rap $@" -fi - -# 查找并编译当前目录下的所有 Rust 项目 -find . -type f -name "Cargo.toml" | while read -r cargo_file; do - # 获取 Cargo.toml 文件所在的目录 - project_dir=$(dirname "$cargo_file") - - echo "Processing project in: $project_dir" - - # 切换到项目目录 - pushd "$project_dir" > /dev/null - - $cmd - if [ $? -ne 0 ]; then - # 如果命令失败,打印错误信息并退出循环 - echo "Error: '$cmd' failed in $project_dir" - popd > /dev/null - exit 1 - fi - - # 返回原始目录 - popd > /dev/null -done - diff --git a/tests/batch.sh b/tests/batch.sh index 0ccc0ba..eb6ba99 100755 --- a/tests/batch.sh +++ b/tests/batch.sh @@ -1,35 +1,40 @@ #!/bin/bash #该脚本在目录下为每个Cargo项目执行相同的命令直到报错 -if [ $# -eq 0 ]; then +# All arguments passed to this script are forwarded to cargo rap + +cur=$(pwd) + +# 查找并编译当前目录下的所有 Rust 项目 +find support -type f -name "Cargo.toml" | while read -r cargo_file; do + # 获取 Cargo.toml 文件所在的目录 + project_dir=$(dirname "$cargo_file") + + echo "Processing project in: $project_dir" + + # 切换到项目目录 + pushd "$project_dir" >/dev/null + + if [ $# -eq 0 ]; then #脚本无参数时执行cargo clean #Example: batch.sh cmd="cargo clean" -else + $cmd + else #脚本有参数时按照给定参数执行cargo命令 #Example: batch.sh rap -uaf - cmd="cargo $@" -fi + cmd="cargo rap $@" + $cmd 2>&1 | tee $cur/rap.txt | ansi2txt | grep 'RAP|WARN|' && echo -e "\033[32m$project_dir pass\033[0m" + fi -# 查找并编译当前目录下的所有 Rust 项目 -find . -type f -name "Cargo.toml" | while read -r cargo_file; do - # 获取 Cargo.toml 文件所在的目录 - project_dir=$(dirname "$cargo_file") - - echo "Processing project in: $project_dir" - - # 切换到项目目录 - pushd "$project_dir" > /dev/null - - $cmd - if [ $? -ne 0 ]; then - # 如果命令失败,打印错误信息并退出循环 - echo "Error: '$cmd' failed in $project_dir" - popd > /dev/null - exit 1 - fi - - # 返回原始目录 - popd > /dev/null -done + if [ $? -ne 0 ]; then + # 如果命令失败,打印错误信息并退出循环 + echo -e "Error: '$cmd' failed in $project_dir \nRAP output:" + cat $cur/rap.txt + popd >/dev/null + exit 1 + fi + # 返回原始目录 + popd >/dev/null +done diff --git a/tests/CI_leak/leak_min/Cargo.toml b/tests/support/leak/leak_min/Cargo.toml similarity index 100% rename from tests/CI_leak/leak_min/Cargo.toml rename to tests/support/leak/leak_min/Cargo.toml diff --git a/tests/CI_leak/leak_min/src/main.rs b/tests/support/leak/leak_min/src/main.rs similarity index 100% rename from tests/CI_leak/leak_min/src/main.rs rename to tests/support/leak/leak_min/src/main.rs diff --git a/tests/CI_leak/leak_proxy/Cargo.toml b/tests/support/leak/leak_proxy/Cargo.toml similarity index 100% rename from tests/CI_leak/leak_proxy/Cargo.toml rename to tests/support/leak/leak_proxy/Cargo.toml diff --git a/tests/CI_leak/leak_proxy/src/main.rs b/tests/support/leak/leak_proxy/src/main.rs similarity index 100% rename from tests/CI_leak/leak_proxy/src/main.rs rename to tests/support/leak/leak_proxy/src/main.rs diff --git a/tests/CI_uaf/dangling_min/Cargo.toml b/tests/support/uaf/dangling_min/Cargo.toml similarity index 100% rename from tests/CI_uaf/dangling_min/Cargo.toml rename to tests/support/uaf/dangling_min/Cargo.toml diff --git a/tests/CI_uaf/dangling_min/src/main.rs b/tests/support/uaf/dangling_min/src/main.rs similarity index 100% rename from tests/CI_uaf/dangling_min/src/main.rs rename to tests/support/uaf/dangling_min/src/main.rs diff --git a/tests/CI_uaf/uaf_drop/Cargo.toml b/tests/support/uaf/uaf_drop/Cargo.toml similarity index 100% rename from tests/CI_uaf/uaf_drop/Cargo.toml rename to tests/support/uaf/uaf_drop/Cargo.toml diff --git a/tests/CI_uaf/uaf_drop/src/main.rs b/tests/support/uaf/uaf_drop/src/main.rs similarity index 100% rename from tests/CI_uaf/uaf_drop/src/main.rs rename to tests/support/uaf/uaf_drop/src/main.rs diff --git a/tests/CI_uaf/uaf_drop2/Cargo.toml b/tests/support/uaf/uaf_drop2/Cargo.toml similarity index 100% rename from tests/CI_uaf/uaf_drop2/Cargo.toml rename to tests/support/uaf/uaf_drop2/Cargo.toml diff --git a/tests/CI_uaf/uaf_drop2/src/main.rs b/tests/support/uaf/uaf_drop2/src/main.rs similarity index 100% rename from tests/CI_uaf/uaf_drop2/src/main.rs rename to tests/support/uaf/uaf_drop2/src/main.rs diff --git a/tests/CI_uaf/uaf_drop_in_palce/Cargo.toml b/tests/support/uaf/uaf_drop_in_palce/Cargo.toml similarity index 100% rename from tests/CI_uaf/uaf_drop_in_palce/Cargo.toml rename to tests/support/uaf/uaf_drop_in_palce/Cargo.toml diff --git a/tests/CI_uaf/uaf_drop_in_palce/src/main.rs b/tests/support/uaf/uaf_drop_in_palce/src/main.rs similarity index 100% rename from tests/CI_uaf/uaf_drop_in_palce/src/main.rs rename to tests/support/uaf/uaf_drop_in_palce/src/main.rs diff --git a/tests/CI_uaf/uaf_lifetime/Cargo.toml b/tests/support/uaf/uaf_lifetime/Cargo.toml similarity index 100% rename from tests/CI_uaf/uaf_lifetime/Cargo.toml rename to tests/support/uaf/uaf_lifetime/Cargo.toml diff --git a/tests/CI_uaf/uaf_lifetime/src/main.rs b/tests/support/uaf/uaf_lifetime/src/main.rs similarity index 100% rename from tests/CI_uaf/uaf_lifetime/src/main.rs rename to tests/support/uaf/uaf_lifetime/src/main.rs diff --git a/tests/CI_uaf/uaf_small/Cargo.toml b/tests/support/uaf/uaf_small/Cargo.toml similarity index 100% rename from tests/CI_uaf/uaf_small/Cargo.toml rename to tests/support/uaf/uaf_small/Cargo.toml diff --git a/tests/CI_uaf/uaf_small/src/main.rs b/tests/support/uaf/uaf_small/src/main.rs similarity index 100% rename from tests/CI_uaf/uaf_small/src/main.rs rename to tests/support/uaf/uaf_small/src/main.rs diff --git a/tests/CI_uaf/df_min/Cargo.toml b/tests/todo/df_min/Cargo.toml similarity index 100% rename from tests/CI_uaf/df_min/Cargo.toml rename to tests/todo/df_min/Cargo.toml diff --git a/tests/CI_uaf/df_min/src/main.rs b/tests/todo/df_min/src/main.rs similarity index 100% rename from tests/CI_uaf/df_min/src/main.rs rename to tests/todo/df_min/src/main.rs