Skip to content

Commit

Permalink
add c example in CI, add blosc2 tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fangq committed Sep 15, 2022
1 parent a5c072d commit b1b0ad7
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 11 deletions.
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ script:
fi
- ${MAKE} -C src lib
- ${MAKE} -C src dll
- ${MAKE} -C example/c all
- LD_LIBRARY_PATH=lib example/c/testzmat
- if [ "$TRAVIS_OS_NAME" = "linux" ]; then
${MAKE} -C src oct;
octave-cli --eval "addpath(pwd);cd test;run_zmat_test";
Expand Down
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ LIBNAME=lib$(PKGNAME)
MEXNAME=zipmat
VERSION=0.9.9
SOURCE=src
EXAMPLE=example/c

all: mex oct lib dll
all: mex oct lib dll example

lib:
-$(MAKE) -C $(SOURCE) lib
Expand All @@ -20,9 +21,12 @@ mex:
-$(MAKE) -C $(SOURCE) mex
oct:
-$(MAKE) -C $(SOURCE) oct
example: lib
-$(MAKE) -C $(EXAMPLE) all
clean:
-rm -rf $(LIBNAME).* $(MEXNAME).mex*
-$(MAKE) -C $(SOURCE) clean
-$(MAKE) -C $(EXAMPLE) clean

.DEFAULT_GOAL := mex

2 changes: 1 addition & 1 deletion example/c/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
all:
$(CC) -g -Wall -pedantic testzmat.c -o testzmat -DNO_LZMA -DNO_LZ4 -I../../include -L../../lib -lzmat -lz
$(CC) -g -Wall -pedantic testzmat.c -o testzmat -I../../include -L../../lib -lzmat -lz -lpthread
clean:
-rm -f testzmat
18 changes: 9 additions & 9 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ HAVE_BLOSC2?=yes

MEX=mex
AR=$(CC)
ECHO := echo
ECHO :=echo
SYMBLINK :=ln -s

BINARY:=zipmat
OUTPUT_DIR=$(ZMATDIR)
Expand Down Expand Up @@ -109,23 +110,18 @@ endif
ifeq ($(MAKECMDGOALS),dll)
AR :=$(CC)
OUTPUTFLAG :=-o
BINARY :=libzmat.so
BINARY :=libzmat.so.1
OUTPUT_DIR :=$(LIBDIR)
LINKOPT +=-lz

ifeq ($(findstring Darwin,$(PLATFORM)), Darwin)
ARFLAGS :=-shared -Wl,-install_name,$(BINARY).1 -lz
ARFLAGS :=-shared -Wl,-install_name,$(BINARY) -lz
else
ARFLAGS :=-shared -Wl,-soname,$(BINARY).1 -lz
ARFLAGS :=-shared -Wl,-soname,$(BINARY) -lz
endif
endif

ifeq ($(MAKECMDGOALS),dll)
BINARY :=libzmat.so
endif

dll: CPPOPT +=$(DLLFLAG)
#dll: AR :=gcc
dll: ARFLAGS ?=-shared -Wl,-soname,$(BINARY).1
dll: LINKOPT +=$(LDFLAGS)
dll: AROUTPUT :=-o
Expand Down Expand Up @@ -155,6 +151,7 @@ OBJS := $(addsuffix $(OBJSUFFIX), $(FILES))

all dll lib mex oct: $(OUTPUT_DIR)/$(BINARY)

dll: linkdll
blosc:
@if [ $(HAVE_BLOSC2) = "yes" ]; then\
$(MAKE) -C blosc2 all;\
Expand All @@ -163,6 +160,9 @@ blosc:
makedirs:
@if test ! -d $(OUTPUT_DIR); then $(MKDIR) $(OUTPUT_DIR); fi

linkdll: makedirs
-$(SYMBLINK) $(BINARY) $(basename $(OUTPUT_DIR)/$(BINARY))

makedocdir:
@if test ! -d $(DOCDIR); then $(MKDIR) $(DOCDIR); fi

Expand Down
17 changes: 17 additions & 0 deletions test/run_zmat_test.m
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ function run_zmat_test(tests)
test_zmat('lzip (scalar)', 'lzip', single(89.8901), [76 90 73 80 0 20 0 93 177 210 100 7 58 15 255 255 252 63 0 0 133 75 237 40 4 0 0 0 0 0 0 0]);
test_zmat('lz4 (scalar)', 'lz4', 2.71828, [128 144 247 170 149 9 191 5 64]);
test_zmat('lz4hc (scalar)', 'lz4hc', 0.0, [128 0 0 0 0 0 0 0 0]);
test_zmat('blosc2blosclz (scalar)', 'base64', zmat(uint8(201),1,'blosc2blosclz'), 'BQEHAQEAAAABAAAAIQAAAAAAAAAAAAAAAAAAAAAAAADJ', 'level', 2);
test_zmat('blosc2lz4 (scalar)', 'base64', zmat(single(202),1,'blosc2lz4'), 'BQEHBAQAAAAEAAAAJAAAAAAAAAAAAQEAAAAAAAAAAAAAAEpD', 'level', 2);
test_zmat('blosc2lz4hc (scalar)', 'base64', zmat(uint32(58392),1,'blosc2lz4hc'), 'BQEHBAQAAAAEAAAAJAAAAAAAAAAAAQIAAAAAAAAAAAAY5AAA', 'level', 2);
test_zmat('blosc2zlib (scalar)', 'base64', zmat(2.2,1,'blosc2zlib'), 'BQEHCAgAAAAIAAAAKAAAAAAAAAAAAQQAAAAAAAAAAACamZmZmZkBQA==', 'level', 2);
test_zmat('blosc2zstd (scalar)', 'base64', zmat(logical(0.1),1,'blosc2zstd'), 'BQEHAQEAAAABAAAAIQAAAAAAAAAAAAUAAAAAAAAAAAAB', 'level', 2);
test_zmat('base64 (scalar)', 'base64', uint8(100), [90 65 61 61 10]);

test_zmat('zlib (array)', 'zlib', uint8([1,2,3]), [120 156 99 100 98 6 0 0 13 0 7]);
Expand All @@ -54,6 +59,11 @@ function run_zmat_test(tests)
test_zmat('lzip (array)', 'lzip', uint8(reshape(1:(2*3*4), [3,2,4])), [76 90 73 80 0 20 0 0 128 157 97 211 13 93 174 25 62 219 132 40 29 52 41 93 234 35 61 128 60 72 152 87 41 88 255 253 203 224 0 163 16 142 146 24 0 0 0 0 0 0 0]);
test_zmat('lz4 (array)', 'lz4', [1], [128 0 0 0 0 0 0 240 63]);
test_zmat('lz4hc (array)', 'lz4hc', 'test zmat', [144 116 101 115 116 32 122 109 97 116]);
test_zmat('blosc2blosclz (array)', 'base64', zmat(uint8(magic(2)),1,'blosc2blosclz'), 'BQEHAQQAAAAEAAAAJAAAAAAAAAAAAAAAAAAAAAAAAAABBAMC', 'level', 3);
test_zmat('blosc2lz4 (array)', 'base64', zmat(uint16(magic(3)),1,'blosc2lz4'), 'BQEHAhIAAAASAAAAMgAAAAAAAAAAAQEAAAAAAAAAAAAIAAMABAABAAUACQAGAAcAAgA=', 'level', 3);
test_zmat('blosc2lz4hc (array)', 'base64', zmat([1.1,2.1,3.1],1,'blosc2lz4hc'), 'BQEHCBgAAAAYAAAAOAAAAAAAAAAAAQIAAAAAAAAAAACamZmZmZnxP83MzMzMzABAzczMzMzMCEA=', 'level', 3);
test_zmat('blosc2zlib (array)', 'base64', zmat(uint8(reshape(1:(2*3*4), [3,2,4])),1,'blosc2zlib'), 'BQEHARgAAAAYAAAAOAAAAAAAAAAAAAQAAAAAAAAAAAABAgMEBQYHCAkKCwwNDg8QERITFBUWFxg=', 'level', 3);
test_zmat('blosc2zstd (array)', 'base64', zmat(uint8(ones(2,3,4)),1,'blosc2zstd'), 'BQEHARgAAAAYAAAAOAAAAAAAAAAAAAUAAAAAAAAAAAABAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQE=', 'level', 3);
test_zmat('base64 (array)', 'base64', ['test';'zmat'], [100 72 112 108 98 88 78 104 100 72 81 61 10]);

test_zmat('zlib (level=9)', 'zlib', 55, [120 218 99 96 0 130 6 111 7 0 2 94 1 12], 'level', -9);
Expand All @@ -63,6 +73,12 @@ function run_zmat_test(tests)
test_zmat('lzip (level)', 'lzip', logical([1,2,3,4]), [76 90 73 80 0 20 0 0 232 190 92 247 255 255 224 0 128 0 153 211 38 246 4 0 0 0 0 0 0 0],'level', -9);
test_zmat('lz4 (level)', 'lz4', 'random data', [176 114 97 110 100 111 109 32 100 97 116 97],'level', -9);
test_zmat('lz4hc (level)', 'lz4hc', 1.2, [128 51 51 51 51 51 51 243 63],'level', -9);
test_zmat('blosc2blosclz (typesize=2)', 'base64', zmat(uint32(magic(4)),1,'blosc2blosclz','typesize',2), 'BQEFAkAAAABAAAAATAAAAAAAAAAAAQAAAAAAAAAAAAAkAAAAIAAAABAABQAJAAQAAgALAAcADgADAAoABgAPAA0ACAAMAAEAAAAAAA==', 'level', 3);
test_zmat('blosc2blosclz (typesize=4)', 'base64', zmat(uint32(magic(4)),1,'blosc2blosclz','typesize',4), 'BQEXBEAAAABAAAAAYAAAAAAAAAAAAQAAAAAAAAAAAAAQAAAABQAAAAkAAAAEAAAAAgAAAAsAAAAHAAAADgAAAAMAAAAKAAAABgAAAA8AAAANAAAACAAAAAwAAAABAAAA', 'level', 3);
test_zmat('blosc2blosclz (typesize=8)', 'base64', zmat(uint32(magic(4)),1,'blosc2blosclz','typesize',8), 'BQEXCEAAAABAAAAAYAAAAAAAAAAAAQAAAAAAAAAAAAAQAAAABQAAAAkAAAAEAAAAAgAAAAsAAAAHAAAADgAAAAMAAAAKAAAABgAAAA8AAAANAAAACAAAAAwAAAABAAAA', 'level', 3);
test_zmat('blosc2zstd (typesize=2)', 'base64', zmat(single(magic(4)),1,'blosc2zstd','typesize',2), 'BQGXAkAAAABAAAAAYAAAAAAAAAAAAQUAAAAAAAAAAAAAAIBBAACgQAAAEEEAAIBAAAAAQAAAMEEAAOBAAABgQQAAQEAAACBBAADAQAAAcEEAAFBBAAAAQQAAQEEAAIA/', 'level', 3);
test_zmat('blosc2zstd (typesize=4)', 'base64', zmat(single(magic(4)),1,'blosc2zstd','typesize',4), 'BQGVBEAAAABAAAAAVQAAAAAAAAAAAQUAAAAAAAAAAAAkAAAALQAAACi1L/0gQCUBAOAAAICgEIAAMOBgQCDAcFAAQIBBQEFAQEFBQUE/AgByQxMBFg==', 'level', 3);
test_zmat('blosc2zstd (typesize=8)', 'base64', zmat(single(magic(4)),1,'blosc2zstd','typesize',8), 'BQGXCEAAAABAAAAAYAAAAAAAAAAAAQUAAAAAAAAAAAAAAIBBAACgQAAAEEEAAIBAAAAAQAAAMEEAAOBAAABgQQAAQEAAACBBAADAQAAAcEEAAFBBAAAAQQAAQEEAAIA/', 'level', 3);
test_zmat('base64 (trailing newline)', 'base64', uint8(100), 'ZA==', 'level', 2);
test_zmat('base64 (all newline)', 'base64', ones(7,1), 'AAAAAAAA8D8AAAAAAADwPwAAAAAAAPA/AAAAAAAA8D8AAAAAAADwPwAAAAAAAPA/AAAAAAAA8D8=', 'level', 3);
end
Expand All @@ -89,5 +105,6 @@ function run_zmat_test(tests)
test_zmat('unsupported input (string)', 'zlib', string(sprintf('zmat\ntest')), 'input must be a char, non-complex numeric or logical vector or N-D array');
end
test_zmat('zlib wrong input format', 'zlib', [1, 2, 3, 4], [], 'level', 0, 'status', -3);
test_zmat('blosc2zstd wrong input format', 'blosc2zstd', [1, 2, 3, 4], [], 'level', 0, 'status', -11);
end

0 comments on commit b1b0ad7

Please sign in to comment.