Skip to content

Commit fef46ae

Browse files
authored
feat(testing): local libstorage c bindings test (#1407)
1 parent e375223 commit fef46ae

File tree

8 files changed

+47
-46
lines changed

8 files changed

+47
-46
lines changed

.github/workflows/ci-reusable.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,11 @@ jobs:
6363
path: tests/integration/logs/
6464
retention-days: 1
6565

66+
## Part 3 Tests ##
67+
- name: Libstorage tests
68+
if: matrix.tests == 'libstorage' || matrix.tests == 'all'
69+
run: make -j${ncpu} testLibstorage
70+
6671
status:
6772
if: always()
6873
needs: [build]

.github/workflows/ci.yml

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -85,29 +85,3 @@ jobs:
8585
name: codecov-umbrella
8686
token: ${{ secrets.CODECOV_TOKEN }}
8787
verbose: true
88-
89-
cbinding:
90-
runs-on: ubuntu-latest
91-
steps:
92-
- name: Checkout sources
93-
uses: actions/checkout@v4
94-
with:
95-
submodules: recursive
96-
ref: ${{ github.event.pull_request.head.sha }}
97-
98-
- name: Setup Nimbus Build System
99-
uses: ./.github/actions/nimbus-build-system
100-
with:
101-
os: linux
102-
nim_version: ${{ env.nim_version }}
103-
104-
- name: C Binding build
105-
run: |
106-
make -j${ncpu} update
107-
make -j${ncpu} libstorage
108-
109-
- name: C Binding test
110-
run: |
111-
cd examples/c
112-
gcc -o storage storage.c -L../../build -lstorage -Wl,-rpath,../../ -pthread
113-
LD_LIBRARY_PATH=../../build ./storage

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,5 @@ tests/integration/logs
4848

4949
data/
5050

51-
examples/c/data-dir
52-
examples/c/downloaded_hello.txt
51+
tests/cbindings/data-dir
52+
tests/cbindings/downloaded_hello.txt

Makefile

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ endif
8383
deps \
8484
libbacktrace \
8585
test \
86+
testAll \
87+
testIntegration \
88+
testLibstorage \
8689
update
8790

8891
ifeq ($(NIM_PARAMS),)
@@ -144,10 +147,23 @@ testIntegration: | build deps
144147
echo -e $(BUILD_MSG) "build/$@" && \
145148
$(ENV_SCRIPT) nim testIntegration $(TEST_PARAMS) $(NIM_PARAMS) --define:ws_resubscribe=240 build.nims
146149

147-
# Builds and runs all tests (except for Taiko L2 tests)
150+
# Builds a C example that uses the libstorage C library and runs it
151+
testLibstorage: | build deps
152+
$(MAKE) $(if $(ncpu),-j$(ncpu),) libstorage
153+
cd tests/cbindings && \
154+
if [ "$(detected_OS)" = "Windows" ]; then \
155+
gcc -o storage.exe storage.c -L../../build -lstorage -pthread && \
156+
PATH=../../build:$$PATH ./storage.exe; \
157+
else \
158+
gcc -o storage storage.c -L../../build -lstorage -Wl,-rpath,../../ -pthread && \
159+
LD_LIBRARY_PATH=../../build ./storage; \
160+
fi
161+
162+
# Builds and runs all tests
148163
testAll: | build deps
149164
echo -e $(BUILD_MSG) "build/$@" && \
150165
$(ENV_SCRIPT) nim testAll $(NIM_PARAMS) build.nims
166+
$(MAKE) $(if $(ncpu),-j$(ncpu),) testLibstorage
151167

152168
# nim-libbacktrace
153169
LIBBACKTRACE_MAKE_FLAGS := -C vendor/nim-libbacktrace --no-print-directory BUILD_CXX_LIB=0

README.md

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -67,23 +67,7 @@ This produces the shared library under `build/`.
6767

6868
### Run the Go example
6969

70-
Build the Go example:
71-
72-
```bash
73-
go build -o storage-go examples/golang/storage.go
74-
```
75-
76-
Export the library path:
77-
78-
```bash
79-
export LD_LIBRARY_PATH=build
80-
```
81-
82-
Run the example:
83-
84-
```bash
85-
./storage-go
86-
```
70+
See https://github.com/logos-storage/logos-storage-go-bindings-example.
8771

8872
### Static vs Dynamic build
8973

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,19 @@
66
#include <unistd.h>
77
#include "../../library/libstorage.h"
88

9+
/* Provide realpath on Windows (not available on some MSVC/MinGW setups) */
10+
#if defined(_WIN32) || defined(_WIN64)
11+
#include <limits.h>
12+
#if defined(_MSC_VER)
13+
#include <direct.h>
14+
#define realpath(N,R) _fullpath((R),(N),_MAX_PATH)
15+
#else
16+
/* MinGW / other Windows gcc: map to _fullpath using PATH_MAX */
17+
#include <stdlib.h>
18+
#define realpath(N,R) _fullpath((R),(N),PATH_MAX)
19+
#endif
20+
#endif
21+
922
// We need 250 as max retries mainly for the start function in CI.
1023
// Other functions should be not need that many retries.
1124
#define MAX_RETRIES 250

tools/scripts/ci-job-matrix.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,19 @@ integration_test () {
109109
fi
110110
}
111111

112+
113+
# outputs a libstorage test job
114+
libstorage_test () {
115+
job_tests="libstorage"
116+
job_includes=""
117+
job
118+
}
119+
112120
# outputs jobs for all test types
113121
all_tests () {
114122
unit_test
115123
integration_test
124+
libstorage_test
116125
}
117126

118127
# outputs jobs for the specified operating systems and all test types

0 commit comments

Comments
 (0)