feat(testing): local libstorage c bindings test (#1407)

This commit is contained in:
Eric 2026-02-18 15:29:59 +11:00 committed by GitHub
parent e375223500
commit fef46aee35
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 47 additions and 46 deletions

View File

@ -63,6 +63,11 @@ jobs:
path: tests/integration/logs/
retention-days: 1
## Part 3 Tests ##
- name: Libstorage tests
if: matrix.tests == 'libstorage' || matrix.tests == 'all'
run: make -j${ncpu} testLibstorage
status:
if: always()
needs: [build]

View File

@ -85,29 +85,3 @@ jobs:
name: codecov-umbrella
token: ${{ secrets.CODECOV_TOKEN }}
verbose: true
cbinding:
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v4
with:
submodules: recursive
ref: ${{ github.event.pull_request.head.sha }}
- name: Setup Nimbus Build System
uses: ./.github/actions/nimbus-build-system
with:
os: linux
nim_version: ${{ env.nim_version }}
- name: C Binding build
run: |
make -j${ncpu} update
make -j${ncpu} libstorage
- name: C Binding test
run: |
cd examples/c
gcc -o storage storage.c -L../../build -lstorage -Wl,-rpath,../../ -pthread
LD_LIBRARY_PATH=../../build ./storage

4
.gitignore vendored
View File

@ -48,5 +48,5 @@ tests/integration/logs
data/
examples/c/data-dir
examples/c/downloaded_hello.txt
tests/cbindings/data-dir
tests/cbindings/downloaded_hello.txt

View File

@ -83,6 +83,9 @@ endif
deps \
libbacktrace \
test \
testAll \
testIntegration \
testLibstorage \
update
ifeq ($(NIM_PARAMS),)
@ -144,10 +147,23 @@ testIntegration: | build deps
echo -e $(BUILD_MSG) "build/$@" && \
$(ENV_SCRIPT) nim testIntegration $(TEST_PARAMS) $(NIM_PARAMS) --define:ws_resubscribe=240 build.nims
# Builds and runs all tests (except for Taiko L2 tests)
# Builds a C example that uses the libstorage C library and runs it
testLibstorage: | build deps
$(MAKE) $(if $(ncpu),-j$(ncpu),) libstorage
cd tests/cbindings && \
if [ "$(detected_OS)" = "Windows" ]; then \
gcc -o storage.exe storage.c -L../../build -lstorage -pthread && \
PATH=../../build:$$PATH ./storage.exe; \
else \
gcc -o storage storage.c -L../../build -lstorage -Wl,-rpath,../../ -pthread && \
LD_LIBRARY_PATH=../../build ./storage; \
fi
# Builds and runs all tests
testAll: | build deps
echo -e $(BUILD_MSG) "build/$@" && \
$(ENV_SCRIPT) nim testAll $(NIM_PARAMS) build.nims
$(MAKE) $(if $(ncpu),-j$(ncpu),) testLibstorage
# nim-libbacktrace
LIBBACKTRACE_MAKE_FLAGS := -C vendor/nim-libbacktrace --no-print-directory BUILD_CXX_LIB=0

View File

@ -67,23 +67,7 @@ This produces the shared library under `build/`.
### Run the Go example
Build the Go example:
```bash
go build -o storage-go examples/golang/storage.go
```
Export the library path:
```bash
export LD_LIBRARY_PATH=build
```
Run the example:
```bash
./storage-go
```
See https://github.com/logos-storage/logos-storage-go-bindings-example.
### Static vs Dynamic build

View File

@ -6,6 +6,19 @@
#include <unistd.h>
#include "../../library/libstorage.h"
/* Provide realpath on Windows (not available on some MSVC/MinGW setups) */
#if defined(_WIN32) || defined(_WIN64)
#include <limits.h>
#if defined(_MSC_VER)
#include <direct.h>
#define realpath(N,R) _fullpath((R),(N),_MAX_PATH)
#else
/* MinGW / other Windows gcc: map to _fullpath using PATH_MAX */
#include <stdlib.h>
#define realpath(N,R) _fullpath((R),(N),PATH_MAX)
#endif
#endif
// We need 250 as max retries mainly for the start function in CI.
// Other functions should be not need that many retries.
#define MAX_RETRIES 250

View File

@ -109,10 +109,19 @@ integration_test () {
fi
}
# outputs a libstorage test job
libstorage_test () {
job_tests="libstorage"
job_includes=""
job
}
# outputs jobs for all test types
all_tests () {
unit_test
integration_test
libstorage_test
}
# outputs jobs for the specified operating systems and all test types