Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/linux_dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: build
.PHONY: build tests-ffi

scripts_folder = scripts

Expand Down Expand Up @@ -32,4 +32,7 @@ stable-push:

build_options ?= none
deploy-linux:
@$(MAKE) -C $(scripts_folder) deploy-linux build_options="$(build_options)"
@$(MAKE) -C $(scripts_folder) deploy-linux build_options="$(build_options)"

tests-ffi:
@$(MAKE) -C tests-ffi tests
2 changes: 1 addition & 1 deletion tests-ffi/Makefile
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
test:
tests:
@./tests.sh
8 changes: 6 additions & 2 deletions tests-ffi/config.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ extern "C" WriteConfigStatus raw_write_default_config();
void gen_config_test() {
auto status = raw_write_default_config();

cout << static_cast<int>(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() {
Expand All @@ -33,7 +38,6 @@ int main() {
raw_free_c_str(raw_result);

gen_config_test();
cout << result << "\n";
assert(!result.empty());

return 0;
Expand Down
69 changes: 56 additions & 13 deletions tests-ffi/tests.sh
Original file line number Diff line number Diff line change
@@ -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