Repository navigation
423 lines (382 loc) · 19.9 KB
/
Copy pathtest-opencvsharp.yml
File metadata and controls
423 lines (382 loc) · 19.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
name: Test-OpenCvSharp
on:
push:
branches: [ feature/docker ]
paths: [ '.github/workflows/test-opencvsharp.yml' ]
workflow_dispatch:
jobs:
build:
name: Build Test
runs-on: ${{ matrix.runs-on }}
defaults:
run:
shell: bash
strategy:
matrix:
include:
- { os: ubuntu.22.04, arch: x64, runs-on: ubuntu-22.04 }
- { os: ubuntu.22.04, arch: arm64, runs-on: ubuntu-22.04-arm }
- { os: win, arch: x64, runs-on: windows-2022 }
- { os: win, arch: x86, runs-on: windows-2022 }
- { os: win, arch: arm64, runs-on: windows-11-arm }
- { os: osx, arch: x64, runs-on: macos-13 }
- { os: osx, arch: arm64, runs-on: macos-14 }
- { os: centos.7, arch: x64, runs-on: ubuntu-22.04, image: oraclelinux:7 }
- { os: centos.7, arch: arm64, runs-on: ubuntu-22.04-arm, image: oraclelinux:7 }
- { os: rhel.8, arch: x64, runs-on: ubuntu-22.04, image: oraclelinux:8 }
- { os: rhel.8, arch: arm64, runs-on: ubuntu-22.04-arm, image: oraclelinux:8 }
- { os: alpine.3.22, arch: x64, runs-on: ubuntu-22.04, image: alpine:3.22 }
- { os: alpine.3.22, arch: arm64, runs-on: ubuntu-22.04-arm, image: alpine:3.22 }
- { os: android, arch: arm64, runs-on: ubuntu-24.04 }
- { os: android, arch: x64, runs-on: ubuntu-24.04 }
steps:
- name: Download OpenCvSharp Artifacts
env:
GH_TOKEN: ${{ github.token }}
run: |
echo "Fetching lastest run of opencvsharp.yml on branch ${{ github.ref_name }}"
RUN_ID=$(gh run list -R ${{ github.repository }} --workflow=opencvsharp.yml --branch=${{ github.ref_name }} --status=success --limit=1 --json databaseId | jq -r '.[0].databaseId')
echo "Latest opencvsharp run ID: $RUN_ID"
echo "Downloading artifact 'opencvsharp-${{ matrix.os }}-${{ matrix.arch }}' from run ${RUN_ID}"
gh run download -R ${{ github.repository }} $RUN_ID --name opencvsharp-${{ matrix.os }}-${{ matrix.arch }} --dir opencvsharp
echo "::group::OpenCvSharp Artifacts"
ls -lR opencvsharp
echo "::endgroup::"
- name: Create test.c
run: |
mkdir -p test
cat > test/test.c <<'EOF'
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <assert.h>
typedef long long uint64;
typedef int ExceptionStatus;
typedef struct { double val[4]; } MyCvScalar;
typedef struct cv_Mat cv_Mat;
#define CV_8UC3 16 /* 8-bit unsigned, 3 channels */
#define IMWRITE_JPEG_QUALITY 1
#define IMWRITE_WEBP_QUALITY 64
/* core */
extern uint64 core_Mat_sizeof(void);
extern ExceptionStatus core_Mat_new3(int rows,int cols,int type, MyCvScalar scalar, cv_Mat **returnValue);
extern ExceptionStatus core_Mat_delete(cv_Mat *self);
/* imgcodecs */
extern ExceptionStatus imgcodecs_imwrite(const char *filename, cv_Mat *img, int *params,int paramsLength,int *returnValue);
extern ExceptionStatus imgcodecs_imread (const char *filename,int flags, cv_Mat **returnValue);
static void CHECK_OK(ExceptionStatus st, const char *msg)
{
if(st != 0) { fprintf(stderr,"%s failed: %d\n", msg, st); exit(st); }
}
static void CHECK_BOOL(int ok, const char *msg)
{
if(!ok) { fprintf(stderr,"%s returned false\n", msg); exit(1); }
}
int main(void)
{
printf("sizeof(Mat) reported by native = %llu\n",
(unsigned long long)core_Mat_sizeof());
cv_Mat *img = NULL;
MyCvScalar black = {0};
CHECK_OK(core_Mat_new3(256, 256, CV_8UC3, black, &img), "core_Mat_new3");
unsigned char *data = NULL;
extern ExceptionStatus core_Mat_data(cv_Mat *self, unsigned char **returnValue);
CHECK_OK(core_Mat_data(img, &data), "core_Mat_data");
for(int y = 0; y < 256; ++y)
{
for(int x = 0; x < 256; ++x)
{
unsigned char *pix = data + (y*256 + x)*3;
pix[0] = (unsigned char)x;
pix[1] = (unsigned char)y;
pix[2] = 128;
}
}
int ok = 0;
CHECK_OK(imgcodecs_imwrite("test.png", img, NULL, 0, &ok), "imwrite PNG");
CHECK_BOOL(ok, "imwrite PNG");
printf("Image saved as test.png\n");
cv_Mat *img2 = NULL;
CHECK_OK(imgcodecs_imread("test.png", /*flags=*/1, &img2), "imread PNG");
printf("Image loaded from test.png\n");
int jpegParams[2] = { IMWRITE_JPEG_QUALITY, 90 };
CHECK_OK(imgcodecs_imwrite("test.jpg", img2,
jpegParams, 2, &ok), "imwrite JPG");
CHECK_BOOL(ok, "imwrite JPG");
printf("Image saved as test.jpg at quality: 90\n");
int webpParams[2] = { IMWRITE_WEBP_QUALITY, 90 };
CHECK_OK(imgcodecs_imwrite("test.webp", img2,
webpParams, 2, &ok), "imwrite WEBP");
CHECK_BOOL(ok, "imwrite WEBP");
printf("Image saved as test.webp at quality: 90\n");
core_Mat_delete(img);
core_Mat_delete(img2);
return 0;
}
EOF
cat test/test.c
- name: Setup MSVC(Windows only)
uses: ilammy/msvc-dev-cmd@v1
if: startsWith(matrix.os, 'win')
with:
arch: ${{ matrix.arch }}
- name: Pull Docker Image
if: matrix.image != ''
run: |
docker pull ${{ matrix.image }}
- name: Start Docker Container
if: matrix.image != ''
run: |
docker run -d --name builder -v "$PWD":${{ github.workspace }} -w ${{ github.workspace }} ${{ matrix.image }} tail -f /dev/null
- name: Install Dependencies in Docker Container
if: matrix.image != ''
run: |
if [[ "${{ matrix.os }}" == "centos.7" || "${{ matrix.os }}" =~ "rhel." ]]; then
script=$(
cat <<'EOS'
set -eux
yum install -y gcc
EOS
)
elif [[ "${{ matrix.os }}" =~ ^alpine ]]; then
script=$(
cat <<'EOS'
set -eux
apk add --no-cache gcc musl-dev
EOS
)
fi
echo "Executing script in Docker container: $script"
docker exec builder /bin/sh -c "$script"
- name: Build Test
run: |
script=$(
cat <<'EOS'
set -eux
cd test
if [[ "${{ runner.os }}" == Windows ]]; then
export MSYS2_ARG_CONV_EXCL="*"
cl /nologo /EHsc test.c ../opencvsharp/lib/OpenCvSharpExtern.lib /link /OUT:test.exe
elif [[ "${{ matrix.os }}" =~ ^osx ]]; then
gcc test.c -L../opencvsharp/lib -lOpenCvSharpExtern -Wl,-rpath,@loader_path -o test.exe
elif [[ "${{ matrix.os }}" == "centos.7" ]]; then
gcc -std=c99 test.c -L../opencvsharp/lib -lOpenCvSharpExtern -Wl,-rpath,'$ORIGIN' -o test.exe
elif [[ "${{ matrix.os }}" == "android" ]]; then
API=24
if [[ "${{ matrix.arch }}" == "arm64" ]]; then
CLANG=aarch64-linux-android${API}-clang
elif [[ "${{ matrix.arch }}" == "x64" ]]; then
CLANG=x86_64-linux-android${API}-clang
else
echo "Unsupported architecture for Android: ${{ matrix.arch }}"
exit 1
fi
$ANDROID_NDK/toolchains/llvm/prebuilt/linux-x86_64/bin/$CLANG test.c -L../opencvsharp/lib -lOpenCvSharpExtern -Wl,-rpath,'$ORIGIN' -o test.exe
else
gcc test.c -L../opencvsharp/lib -lOpenCvSharpExtern -Wl,-rpath,'$ORIGIN' -o test.exe
fi
ls -lR
EOS
)
if [[ "${{ matrix.image }}" == "" ]]; then
bash -c "$script"
else
docker exec builder /bin/sh -c "$script"
fi
- name: Copy opencvsharp/lib to test
run: |
cp -r opencvsharp/lib/* test
- name: Upload Artifacts
uses: actions/upload-artifact@v4
with:
name: test-${{ matrix.os }}-${{ matrix.arch }}
path: test
android-x64-test:
name: Android x64 Test
runs-on: ubuntu-24.04
needs: build
steps:
- name: Download Artifacts
uses: actions/download-artifact@v4
with:
name: test-android-x64
path: test
- name: chmod+x
run: chmod +x test/test.exe
- name: Enable KVM group perms
run: |
echo 'KERNEL=="kvm", GROUP="kvm", MODE="0666", OPTIONS+="static_node=kvm"' | sudo tee /etc/udev/rules.d/99-kvm4all.rules
sudo udevadm control --reload-rules
sudo udevadm trigger --name-match=kvm
- name: Run Test on Android
uses: reactivecircus/android-emulator-runner@v2
with:
api-level: 28
arch: x86_64
target: google_apis
script: |
adb push -a test /data/local/tmp/
adb shell 'cd /data/local/tmp/test && ./test.exe'
raw-test:
name: Raw Test
runs-on: ${{ matrix.runs-on }}
defaults:
run:
shell: bash
needs: build
strategy:
matrix:
include:
- { os: centos.7, arch: x64, runs-on: ubuntu-22.04 }
- { os: centos.7, arch: x64, runs-on: ubuntu-24.04 }
- { os: centos.7, arch: arm64, runs-on: ubuntu-22.04-arm }
- { os: centos.7, arch: arm64, runs-on: ubuntu-24.04-arm }
- { os: rhel.8, arch: x64, runs-on: ubuntu-22.04 }
- { os: rhel.8, arch: x64, runs-on: ubuntu-24.04 }
- { os: rhel.8, arch: arm64, runs-on: ubuntu-22.04-arm }
- { os: rhel.8, arch: arm64, runs-on: ubuntu-24.04-arm }
- { os: ubuntu.22.04, arch: x64, runs-on: ubuntu-22.04 }
- { os: ubuntu.22.04, arch: x64, runs-on: ubuntu-24.04 }
- { os: ubuntu.22.04, arch: arm64, runs-on: ubuntu-22.04-arm }
- { os: ubuntu.22.04, arch: arm64, runs-on: ubuntu-24.04-arm }
- { os: osx, arch: x64, runs-on: macos-13 }
- { os: osx, arch: arm64, runs-on: macos-14 }
- { os: osx, arch: arm64, runs-on: macos-15 }
- { os: win, arch: x64, runs-on: windows-2022 }
- { os: win, arch: x64, runs-on: windows-2025 }
- { os: win, arch: x86, runs-on: windows-2022 }
- { os: win, arch: x86, runs-on: windows-2025 }
- { os: win, arch: arm64, runs-on: windows-11-arm }
steps:
- name: Download Artifacts
uses: actions/download-artifact@v4
with:
name: test-${{ matrix.os }}-${{ matrix.arch }}
path: test
- name: Run Tests
continue-on-error: ${{ matrix.expect-fails || false }}
run: |
chmod +x test/test.exe
cd test && ls
if [[ ${{ matrix.os }} =~ ^osx ]]; then
otool -L ./test.exe
./test.exe
elif [[ ${{ matrix.os }} =~ win ]]; then
./test.exe
else
ldd ./test.exe
./test.exe
fi
docker-test:
name: Docker Test
runs-on: ${{ matrix.runs-on }}
defaults:
run:
shell: bash
needs: raw-test
strategy:
matrix:
include:
# centos:7 is glibc 2.17, compiled with gcc 4.8.5
# supports centos.7+, rhel.7+, debian:8+(glibc 2.19), ubuntu:14.04+(glibc 2.19)
- { os: centos.7, arch: x64, runs-on: ubuntu-22.04, image: centos:7 }
- { os: centos.7, arch: x64, runs-on: ubuntu-22.04, image: oraclelinux:8 }
- { os: centos.7, arch: x64, runs-on: ubuntu-22.04, image: oraclelinux:9 }
- { os: centos.7, arch: x64, runs-on: ubuntu-22.04, image: debian:8 }
- { os: centos.7, arch: x64, runs-on: ubuntu-22.04, image: debian:9 }
- { os: centos.7, arch: x64, runs-on: ubuntu-22.04, image: debian:10 }
- { os: centos.7, arch: x64, runs-on: ubuntu-22.04, image: debian:11 }
- { os: centos.7, arch: x64, runs-on: ubuntu-22.04, image: debian:12 }
- { os: centos.7, arch: x64, runs-on: ubuntu-22.04, image: ubuntu:14.04 }
- { os: centos.7, arch: x64, runs-on: ubuntu-22.04, image: ubuntu:16.04 }
- { os: centos.7, arch: x64, runs-on: ubuntu-22.04, image: ubuntu:18.04 }
- { os: centos.7, arch: x64, runs-on: ubuntu-22.04, image: ubuntu:20.04 }
- { os: centos.7, arch: x64, runs-on: ubuntu-22.04, image: ubuntu:22.04 }
- { os: centos.7, arch: x64, runs-on: ubuntu-22.04, image: ubuntu:24.04 }
- { os: centos.7, arch: arm64, runs-on: ubuntu-22.04-arm, image: centos:7 }
- { os: centos.7, arch: arm64, runs-on: ubuntu-22.04-arm, image: oraclelinux:8 }
- { os: centos.7, arch: arm64, runs-on: ubuntu-22.04-arm, image: oraclelinux:9 }
- { os: centos.7, arch: arm64, runs-on: ubuntu-22.04-arm, image: debian:9 }
- { os: centos.7, arch: arm64, runs-on: ubuntu-22.04-arm, image: debian:10 }
- { os: centos.7, arch: arm64, runs-on: ubuntu-22.04-arm, image: debian:11 }
- { os: centos.7, arch: arm64, runs-on: ubuntu-22.04-arm, image: debian:12 }
- { os: centos.7, arch: arm64, runs-on: ubuntu-22.04-arm, image: ubuntu:14.04 }
- { os: centos.7, arch: arm64, runs-on: ubuntu-22.04-arm, image: ubuntu:16.04 }
- { os: centos.7, arch: arm64, runs-on: ubuntu-22.04-arm, image: ubuntu:18.04 }
- { os: centos.7, arch: arm64, runs-on: ubuntu-22.04-arm, image: ubuntu:20.04 }
- { os: centos.7, arch: arm64, runs-on: ubuntu-22.04-arm, image: ubuntu:22.04 }
- { os: centos.7, arch: arm64, runs-on: ubuntu-22.04-arm, image: ubuntu:24.04 }
# rhel.8 is glibc 2.28, compiled with gcc 8.5.0
# supports rhel.8+, debian:10+(glibc 2.28), ubuntu:20.04+(glibc 2.31)
# these images will fails
- { os: rhel.8, arch: x64, runs-on: ubuntu-22.04, image: centos:7, expect-fails: true }
- { os: rhel.8, arch: x64, runs-on: ubuntu-22.04, image: debian:9, expect-fails: true }
- { os: rhel.8, arch: x64, runs-on: ubuntu-22.04, image: ubuntu:18.04, expect-fails: true }
- { os: rhel.8, arch: arm64, runs-on: ubuntu-22.04-arm, image: centos:7, expect-fails: true }
- { os: rhel.8, arch: arm64, runs-on: ubuntu-22.04-arm, image: debian:9, expect-fails: true }
- { os: rhel.8, arch: arm64, runs-on: ubuntu-22.04-arm, image: ubuntu:18.04, expect-fails: true }
- { os: rhel.8, arch: x64, runs-on: ubuntu-22.04, image: oraclelinux:8 }
- { os: rhel.8, arch: x64, runs-on: ubuntu-22.04, image: oraclelinux:9 }
- { os: rhel.8, arch: x64, runs-on: ubuntu-22.04, image: debian:10 }
- { os: rhel.8, arch: x64, runs-on: ubuntu-22.04, image: debian:11 }
- { os: rhel.8, arch: x64, runs-on: ubuntu-22.04, image: debian:12 }
- { os: rhel.8, arch: x64, runs-on: ubuntu-22.04, image: ubuntu:20.04 }
- { os: rhel.8, arch: x64, runs-on: ubuntu-22.04, image: ubuntu:22.04 }
- { os: rhel.8, arch: x64, runs-on: ubuntu-22.04, image: ubuntu:24.04 }
- { os: rhel.8, arch: arm64, runs-on: ubuntu-22.04-arm, image: oraclelinux:8 }
- { os: rhel.8, arch: arm64, runs-on: ubuntu-22.04-arm, image: oraclelinux:9 }
- { os: rhel.8, arch: arm64, runs-on: ubuntu-22.04-arm, image: debian:10 }
- { os: rhel.8, arch: arm64, runs-on: ubuntu-22.04-arm, image: debian:11 }
- { os: rhel.8, arch: arm64, runs-on: ubuntu-22.04-arm, image: debian:12 }
- { os: rhel.8, arch: arm64, runs-on: ubuntu-22.04-arm, image: ubuntu:20.04 }
- { os: rhel.8, arch: arm64, runs-on: ubuntu-22.04-arm, image: ubuntu:22.04 }
- { os: rhel.8, arch: arm64, runs-on: ubuntu-22.04-arm, image: ubuntu:24.04 }
# ubuntu 22.04 is glibc 2.35, compiled with gcc 11.2.0
# supports ubuntu:22.04+, debian:11+(glibc 2.31), ubuntu:20.04+(glibc 2.31)
# these images will fails
- { os: ubuntu.22.04, arch: x64, runs-on: ubuntu-22.04, image: oraclelinux:8, expect-fails: true }
- { os: ubuntu.22.04, arch: x64, runs-on: ubuntu-22.04, image: debian:11, expect-fails: true }
- { os: ubuntu.22.04, arch: x64, runs-on: ubuntu-22.04, image: ubuntu:20.04, expect-fails: true }
- { os: ubuntu.22.04, arch: arm64, runs-on: ubuntu-22.04-arm, image: oraclelinux:8, expect-fails: true }
- { os: ubuntu.22.04, arch: arm64, runs-on: ubuntu-22.04-arm, image: debian:11, expect-fails: true }
- { os: ubuntu.22.04, arch: arm64, runs-on: ubuntu-22.04-arm, image: ubuntu:20.04, expect-fails: true }
- { os: ubuntu.22.04, arch: x64, runs-on: ubuntu-22.04, image: oraclelinux:9 }
- { os: ubuntu.22.04, arch: x64, runs-on: ubuntu-22.04, image: debian:12 }
- { os: ubuntu.22.04, arch: x64, runs-on: ubuntu-22.04, image: ubuntu:22.04 }
- { os: ubuntu.22.04, arch: x64, runs-on: ubuntu-22.04, image: ubuntu:24.04 }
- { os: ubuntu.22.04, arch: arm64, runs-on: ubuntu-22.04-arm, image: oraclelinux:9 }
- { os: ubuntu.22.04, arch: arm64, runs-on: ubuntu-22.04-arm, image: debian:12 }
- { os: ubuntu.22.04, arch: arm64, runs-on: ubuntu-22.04-arm, image: ubuntu:22.04 }
- { os: ubuntu.22.04, arch: arm64, runs-on: ubuntu-22.04-arm, image: ubuntu:24.04 }
# alpine 3.22 is musl-libc 1.2.5, compiled with gcc 14.2.0
# should supports alpine:3.13+(musl-libc 1.2.2)
- { os: alpine.3.22, arch: x64, runs-on: ubuntu-22.04, image: alpine:3.12, expect-fails: true } # musl-libc 1.1.24
- { os: alpine.3.22, arch: x64, runs-on: ubuntu-22.04, image: alpine:3.13 } # musl-libc 1.2.2
- { os: alpine.3.22, arch: x64, runs-on: ubuntu-22.04, image: alpine:3.16 } # musl-libc 1.2.3
- { os: alpine.3.22, arch: x64, runs-on: ubuntu-22.04, image: alpine:3.18 } # musl-libc 1.2.4
- { os: alpine.3.22, arch: x64, runs-on: ubuntu-22.04, image: alpine:3.19 } # musl-libc 1.2.4_git20230717
- { os: alpine.3.22, arch: x64, runs-on: ubuntu-22.04, image: alpine:3.20 } # musl-libc 1.2.5
- { os: alpine.3.22, arch: x64, runs-on: ubuntu-22.04, image: alpine:3.22 }
- { os: alpine.3.22, arch: x64, runs-on: ubuntu-22.04, image: alpine:edge }
- { os: alpine.3.22, arch: arm64, runs-on: ubuntu-22.04-arm, image: alpine:3.12, expect-fails: true }
- { os: alpine.3.22, arch: arm64, runs-on: ubuntu-22.04-arm, image: alpine:3.13 }
- { os: alpine.3.22, arch: arm64, runs-on: ubuntu-22.04-arm, image: alpine:3.16 }
- { os: alpine.3.22, arch: arm64, runs-on: ubuntu-22.04-arm, image: alpine:3.18 }
- { os: alpine.3.22, arch: arm64, runs-on: ubuntu-22.04-arm, image: alpine:3.19 }
- { os: alpine.3.22, arch: arm64, runs-on: ubuntu-22.04-arm, image: alpine:3.20 }
- { os: alpine.3.22, arch: arm64, runs-on: ubuntu-22.04-arm, image: alpine:3.22 }
- { os: alpine.3.22, arch: arm64, runs-on: ubuntu-22.04-arm, image: alpine:edge }
steps:
- name: Download Artifacts
uses: actions/download-artifact@v4
with:
name: test-${{ matrix.os }}-${{ matrix.arch }}
path: test
- name: Start Docker Container
run: |
docker run -d --name runner -v "$PWD":${{ github.workspace }} -w ${{ github.workspace }} ${{ matrix.image }} tail -f /dev/null
- name: Run Tests
continue-on-error: ${{ matrix.expect-fails || false }}
run: |
chmod +x test/test.exe
docker exec runner /bin/sh -c "cd test && ls && ldd ./test.exe && ./test.exe"