diff --git a/README.md b/README.md index a408c8a..0787a44 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,3 @@ # 113-spring-software-testing -Labs for NYCU software testing course in 113 spring +Labs for NYCU software testing course in 113 spring/n +just branch from TA diff --git a/lab6/Makefile b/lab6/Makefile deleted file mode 100644 index bd37e34..0000000 --- a/lab6/Makefile +++ /dev/null @@ -1,14 +0,0 @@ -all: target - -llvm-pass.so: llvm-pass.so.cc - clang-14 `llvm-config-14 --cxxflags` -shared -fPIC $< -o $@ - -target: target.c llvm-pass.so - clang-14 `llvm-config-14 --cflags` -fexperimental-new-pass-manager \ - -fpass-plugin=./llvm-pass.so $< -o $@ - -run: - ./target 1 - -clean: - rm -f llvm-pass.so target \ No newline at end of file diff --git a/lab6/README.md b/lab6/README.md deleted file mode 100644 index e6c45af..0000000 --- a/lab6/README.md +++ /dev/null @@ -1,29 +0,0 @@ -# Lab6 - -## Introduction - -In this lab, you will write a llvm pass to instrument some codes to `target.c` in `llvm-pass.so.cc`. - -## Preparation (Important!!!) - -1. Sync fork your branch (e.g., `SQLab:311XXXXXX`) -2. `git checkout -b lab6` (**NOT** your student ID !!!) - -## Requirement - -Write a llvm pass to instrument some codes to `target.c` in `llvm-pass.so.cc` and satisfy following requirements. -1. (40%) Invoke debug function with the first argument is 48763 in main function. -2. (30%) Overwrite argv[1] to "hayaku... motohayaku!" before checking. -3. (30%) Overwrite argc to 48763 before checking. -You can run `validate.sh` in your local to test if you satisfy the requirements. - -Please note that you must not alter files other than `llvm-pass.so.cc`. You will get 0 points if - -1. you modify other files to achieve requirements. -2. you can't pass all CI on your PR. - -## Submission - -You need to open a pull request to your branch (e.g. 311XXXXXX, your student number) and contain the code that satisfies the abovementioned requirements. - -Moreover, please submit the URL of your PR to E3. Your submission will only be accepted when you present at both places. diff --git a/lab6/ans b/lab6/ans deleted file mode 100644 index 0d0a0d8..0000000 --- a/lab6/ans +++ /dev/null @@ -1,6 +0,0 @@ -./target 1 -deubg mode -argc = 48763 -argv[1] = hayaku... motohayaku! -Your argc is so hayaku! -Suta... basuto... sutorimu! diff --git a/lab6/llvm-pass.so.cc b/lab6/llvm-pass.so.cc deleted file mode 100644 index 6c6e17e..0000000 --- a/lab6/llvm-pass.so.cc +++ /dev/null @@ -1,34 +0,0 @@ -#include "llvm/Passes/PassPlugin.h" -#include "llvm/Passes/PassBuilder.h" -#include "llvm/IR/IRBuilder.h" - -using namespace llvm; - -struct LLVMPass : public PassInfoMixin { - PreservedAnalyses run(Module &M, ModuleAnalysisManager &MAM); -}; - -PreservedAnalyses LLVMPass::run(Module &M, ModuleAnalysisManager &MAM) { - LLVMContext &Ctx = M.getContext(); - IntegerType *Int32Ty = IntegerType::getInt32Ty(Ctx); - FunctionCallee debug_func = M.getOrInsertFunction("debug", Int32Ty); - ConstantInt *debug_arg = ConstantInt::get(Int32Ty, 48763); - - for (auto &F : M) { - errs() << "func: " << F.getName() << "\n"; - - } - return PreservedAnalyses::none(); -} - -extern "C" ::llvm::PassPluginLibraryInfo LLVM_ATTRIBUTE_WEAK -llvmGetPassPluginInfo() { - return {LLVM_PLUGIN_API_VERSION, "LLVMPass", "1.0", - [](PassBuilder &PB) { - PB.registerOptimizerLastEPCallback( - [](ModulePassManager &MPM, OptimizationLevel OL) { - MPM.addPass(LLVMPass()); - }); - }}; -} - diff --git a/lab6/target.c b/lab6/target.c deleted file mode 100644 index c13f2b7..0000000 --- a/lab6/target.c +++ /dev/null @@ -1,29 +0,0 @@ -#include -#include -#include - -void debug(int id) -{ - if (id == 48763) - printf("deubg mode\n"); - else - printf("bad id!\n"); -} - -int main(int argc, char **argv) -{ - printf("argc = %d\n", argc); - if (argc >= 2) - printf("argv[1] = %s\n", argv[1]); - else - return 0; - if (argc == 48763) - printf("Your argc is so hayaku!\n"); - else - printf("Your argc need to be modohayaku!\n"); - if (strcmp(argv[1], "hayaku... motohayaku!") == 0) - printf("Suta... basuto... sutorimu!\n"); - else - printf("You dead\n"); - return 0; -} diff --git a/lab6/validate.sh b/lab6/validate.sh deleted file mode 100755 index a6128bb..0000000 --- a/lab6/validate.sh +++ /dev/null @@ -1,43 +0,0 @@ -#!/bin/bash - -# Check for unwanted files -for file in *; do - if [[ $file != "llvm-pass.so.cc" && $file != "target.c" && $file != "Makefile" && $file != "README.md" && $file != "validate.sh" && $file != "ans" ]]; then - echo "[!] Unwanted file detected: $file." - exit 1 - fi -done - -test_path="${BASH_SOURCE[0]}" -solution_path="$(realpath .)" -tmp_dir=$(mktemp -d -t lab5-XXXXXXXXXX) -answer="" - -cd $tmp_dir - -rm -rf * -cp $solution_path/Makefile . -cp $solution_path/*.c . -cp $solution_path/*.cc . -cp $solution_path/ans . - -make -make run > out 2>&1 -result=$(diff --strip-trailing-cr ans out) -if [[ -n $result ]]; then - echo "[!] Expected: " - cat ans - echo "" - echo "[!] Actual: " - cat out - echo "" - exit 1 -else - echo "[V] Pass" -fi - -rm -rf $tmp_dir - -exit 0 - -# vim: set fenc=utf8 ff=unix et sw=2 ts=2 sts=2: