diff --git a/.github/workflows/linux_dev.yml b/.github/workflows/linux_dev.yml index 1d3cc5a..2b5ba71 100644 --- a/.github/workflows/linux_dev.yml +++ b/.github/workflows/linux_dev.yml @@ -50,6 +50,11 @@ jobs: run: | make backend-test + - name: Frontend + Backend FFI Test + shell: bash + run: | + make tests-ffi + - name: Build Lazyboard shell: bash run: | diff --git a/Makefile b/Makefile index 165337c..9c6acde 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -.PHONY: build +.PHONY: build tests-ffi scripts_folder = scripts @@ -32,4 +32,7 @@ stable-push: build_options ?= none deploy-linux: - @$(MAKE) -C $(scripts_folder) deploy-linux build_options="$(build_options)" \ No newline at end of file + @$(MAKE) -C $(scripts_folder) deploy-linux build_options="$(build_options)" + +tests-ffi: + @$(MAKE) -C tests-ffi tests \ No newline at end of file diff --git a/tests-ffi/Makefile b/tests-ffi/Makefile index 979ba57..d85825c 100644 --- a/tests-ffi/Makefile +++ b/tests-ffi/Makefile @@ -1,2 +1,2 @@ -test: +tests: @./tests.sh \ No newline at end of file diff --git a/tests-ffi/config.cxx b/tests-ffi/config.cxx index 60dc504..0184d46 100644 --- a/tests-ffi/config.cxx +++ b/tests-ffi/config.cxx @@ -24,7 +24,12 @@ extern "C" WriteConfigStatus raw_write_default_config(); void gen_config_test() { auto status = raw_write_default_config(); - cout << static_cast(status) << "\n"; + assert(status != WriteConfigStatus::WRITE_FILE_FAILED); + assert(status != WriteConfigStatus::CREATE_FILE_FAILED); + assert(status != WriteConfigStatus::CREATE_DIR_FAILED); + assert(status != WriteConfigStatus::GET_DATA_LOCAL_FAILED); + assert(status != WriteConfigStatus::TOML_TO_STRING_FAILED); + assert(status == WriteConfigStatus::OK); } int main() { @@ -33,7 +38,6 @@ int main() { raw_free_c_str(raw_result); gen_config_test(); - cout << result << "\n"; assert(!result.empty()); return 0; diff --git a/tests-ffi/tests.sh b/tests-ffi/tests.sh index 64f70ac..08dee4d 100755 --- a/tests-ffi/tests.sh +++ b/tests-ffi/tests.sh @@ -1,23 +1,66 @@ #!/usr/bin/bash +set -e -function main() { - local clang_cxx="clang++" - local build_dir="build" - local static_lib="../src/back_end/target/debug/libback_end.a" - local config_test="config.cxx" +function check() { + local required_tool=$1 + + if ! command -v >/dev/null 2>&1; then + echo "$required_tool not found in system" + exit + fi +} +function build_backend() { + local backend_dir="src/back_end" + local tests_ffi_dir="tests-ffi" + local cargo="cargo" + + check "$cargo" cd .. - cd "src/back_end" || exit 1 - cargo build + if [ ! -d "$backend_dir" ]; then + echo "$backend_dir not found" + exit 1 + fi + + cd "$backend_dir" || exit 1 + $cargo build cd ../.. - cd "tests-ffi" || exit 1 - - if [ ! -d "$build_dir" ]; then + cd "$tests_ffi_dir" || exit 1 +} + +function run_ffi_test() { + local clang_cxx="clang++" + local static_lib_path="../src/back_end/target/debug/libback_end.a" + local build_dir="build" + check "$clang_cxx" + + echo -e "\e[0;32m[+] Build backend:\e[0;37m" + build_backend + echo -e "\e[0;32m[+] Build done\e[0;37m" + + if [ ! -d "$build_dir" ]; then mkdir -p "$build_dir" - fi + fi + + for file in *.cxx; do + file_name=$(basename "$file") - $clang_cxx "$config_test" "$static_lib" -o "$build_dir/config_test" - ./"$build_dir/config_test" + $clang_cxx "$file" "$static_lib_path" -o "$build_dir/$file_name" + echo + echo -e "\e[0;32m[+] Test for $file_name:\e[0;37m" + ./"$build_dir/$file_name" + + echo -e "\e[0;32m[+] Test for $file_name success with status code: $?\e[0;37m" + + for _ in {1..25}; do + printf "_" + done + echo + done +} + +function main() { + run_ffi_test } main \ No newline at end of file