Skip to content

Commit 24ff7f1

Browse files
Merge pull request #45 from Reim-developer/dev
Added test FFI suite & implement this to CI
2 parents aaadde5 + aad3765 commit 24ff7f1

5 files changed

Lines changed: 73 additions & 18 deletions

File tree

.github/workflows/linux_dev.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ jobs:
5050
run: |
5151
make backend-test
5252
53+
- name: Frontend + Backend FFI Test
54+
shell: bash
55+
run: |
56+
make tests-ffi
57+
5358
- name: Build Lazyboard
5459
shell: bash
5560
run: |

Makefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: build
1+
.PHONY: build tests-ffi
22

33
scripts_folder = scripts
44

@@ -32,4 +32,7 @@ stable-push:
3232

3333
build_options ?= none
3434
deploy-linux:
35-
@$(MAKE) -C $(scripts_folder) deploy-linux build_options="$(build_options)"
35+
@$(MAKE) -C $(scripts_folder) deploy-linux build_options="$(build_options)"
36+
37+
tests-ffi:
38+
@$(MAKE) -C tests-ffi tests

tests-ffi/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
test:
1+
tests:
22
@./tests.sh

tests-ffi/config.cxx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,12 @@ extern "C" WriteConfigStatus raw_write_default_config();
2424
void gen_config_test() {
2525
auto status = raw_write_default_config();
2626

27-
cout << static_cast<int>(status) << "\n";
27+
assert(status != WriteConfigStatus::WRITE_FILE_FAILED);
28+
assert(status != WriteConfigStatus::CREATE_FILE_FAILED);
29+
assert(status != WriteConfigStatus::CREATE_DIR_FAILED);
30+
assert(status != WriteConfigStatus::GET_DATA_LOCAL_FAILED);
31+
assert(status != WriteConfigStatus::TOML_TO_STRING_FAILED);
32+
assert(status == WriteConfigStatus::OK);
2833
}
2934

3035
int main() {
@@ -33,7 +38,6 @@ int main() {
3338
raw_free_c_str(raw_result);
3439

3540
gen_config_test();
36-
cout << result << "\n";
3741
assert(!result.empty());
3842

3943
return 0;

tests-ffi/tests.sh

Lines changed: 56 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,66 @@
11
#!/usr/bin/bash
2+
set -e
23

3-
function main() {
4-
local clang_cxx="clang++"
5-
local build_dir="build"
6-
local static_lib="../src/back_end/target/debug/libback_end.a"
7-
local config_test="config.cxx"
4+
function check() {
5+
local required_tool=$1
6+
7+
if ! command -v >/dev/null 2>&1; then
8+
echo "$required_tool not found in system"
9+
exit
10+
fi
11+
}
812

13+
function build_backend() {
14+
local backend_dir="src/back_end"
15+
local tests_ffi_dir="tests-ffi"
16+
local cargo="cargo"
17+
18+
check "$cargo"
919
cd ..
10-
cd "src/back_end" || exit 1
11-
cargo build
20+
if [ ! -d "$backend_dir" ]; then
21+
echo "$backend_dir not found"
22+
exit 1
23+
fi
24+
25+
cd "$backend_dir" || exit 1
26+
$cargo build
1227
cd ../..
13-
cd "tests-ffi" || exit 1
14-
15-
if [ ! -d "$build_dir" ]; then
28+
cd "$tests_ffi_dir" || exit 1
29+
}
30+
31+
function run_ffi_test() {
32+
local clang_cxx="clang++"
33+
local static_lib_path="../src/back_end/target/debug/libback_end.a"
34+
local build_dir="build"
35+
check "$clang_cxx"
36+
37+
echo -e "\e[0;32m[+] Build backend:\e[0;37m"
38+
build_backend
39+
echo -e "\e[0;32m[+] Build done\e[0;37m"
40+
41+
if [ ! -d "$build_dir" ]; then
1642
mkdir -p "$build_dir"
17-
fi
43+
fi
44+
45+
for file in *.cxx; do
46+
file_name=$(basename "$file")
1847

19-
$clang_cxx "$config_test" "$static_lib" -o "$build_dir/config_test"
20-
./"$build_dir/config_test"
48+
$clang_cxx "$file" "$static_lib_path" -o "$build_dir/$file_name"
49+
echo
50+
echo -e "\e[0;32m[+] Test for $file_name:\e[0;37m"
51+
./"$build_dir/$file_name"
52+
53+
echo -e "\e[0;32m[+] Test for $file_name success with status code: $?\e[0;37m"
54+
55+
for _ in {1..25}; do
56+
printf "_"
57+
done
58+
echo
59+
done
60+
}
61+
62+
function main() {
63+
run_ffi_test
2164
}
2265

2366
main

0 commit comments

Comments
 (0)