Commit cb4b6cfd authored by Hanspeter Portner's avatar Hanspeter Portner

Merge commit 'd1333b32'

parents 65da7ce3 d1333b32
Pipeline #22309040 passed with stages
in 5 minutes and 23 seconds
stages:
- test
.variables_template: &variables_definition
variables:
BASE_NAME: "osc.lv2"
PKG_CONFIG_PATH: "/opt/lv2/lib/pkgconfig:/opt/${CI_BUILD_NAME}/lib/pkgconfig:/usr/lib/${CI_BUILD_NAME}/pkgconfig"
.common_template: &common_definition
<<: *variables_definition
stage: test
.build_template: &build_definition
<<: *common_definition
script:
- meson --cross-file "${CI_BUILD_NAME}" build
- ninja -C build
.test_template: &test_definition
<<: *common_definition
script:
- meson --cross-file "${CI_BUILD_NAME}" build
- ninja -C build
- cd build
- meson test --verbose --wrap "${CI_BUILD_NAME}.wrap"
.universal_linux_template: &universal_linux_definition
image: ventosus/universal-linux-gnu
<<: *test_definition
.arm_linux_template: &arm_linux_definition
image: ventosus/arm-linux-gnueabihf
<<: *test_definition
.universal_w64_template: &universal_w64_definition
image: ventosus/universal-w64-mingw32
before_script:
- ln -s /usr/lib/gcc/i686-w64-mingw32/6.3-win32/libgcc_s_sjlj-1.dll /opt/i686-w64-mingw32/lib/libgcc_s_sjlj-1.dll
<<: *test_definition
.universal_apple_template: &universal_apple_definition
image: ventosus/universal-apple-darwin
<<: *build_definition
# building in docker
x86_64-linux-gnu:
<<: *universal_linux_definition
i686-linux-gnu:
<<: *universal_linux_definition
arm-linux-gnueabihf:
<<: *arm_linux_definition
x86_64-w64-mingw32:
<<: *universal_w64_definition
i686-w64-mingw32:
<<: *universal_w64_definition
universal-apple-darwin:
<<: *universal_apple_definition
# osc.lv2 # osc.lv2
## Open Sound Control Extension for the LV2 Plugin Specification ## Open Sound Control Extension for the LV2 Plugin Specification
### Build Status
[![build status](https://gitlab.com/OpenMusicKontrollers/osc.lv2/badges/master/build.svg)](https://gitlab.com/OpenMusicKontrollers/osc.lv2/commits/master)
### Build / test
git clone https://git.open-music-kontrollers.ch/lv2/osc.lv2
cd osc.lv2
meson build
cd build
ninja -j4
ninja test
### License
Copyright (c) 2017 Hanspeter Portner (dev@open-music-kontrollers.ch)
This is free software: you can redistribute it and/or modify
it under the terms of the Artistic License 2.0 as published by
The Perl Foundation.
This source is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Artistic License 2.0 for more details.
You should have received a copy of the Artistic License 2.0
along the source as a COPYING file. If not, obtain it from
<http://www.perlfoundation.org/artistic_license_2_0>.
project('osc.lv2', 'c', default_options : [
'buildtype=release',
'warning_level=3',
'werror=true',
'b_lto=true',
'c_std=c11'])
version = run_command('cat', 'VERSION').stdout().strip()
add_project_arguments('-D_GNU_SOURCE', language : 'c')
conf_data = configuration_data()
cc = meson.get_compiler('c')
lv2_dep = dependency('lv2')
thread_dep = dependency('threads')
deps = [lv2_dep, thread_dep]
c_args = []
if host_machine.system() == 'windows'
deps += cc.find_library('ws2_32')
c_args += '-Wno-error=format'
c_args += '-Wno-error=format-extra-args'
endif
osc_test = executable('osc_test',
join_paths('test', 'osc_test.c'),
c_args : c_args,
dependencies : deps,
install : false)
test('Test', osc_test,
timeout : 240)
...@@ -20,12 +20,14 @@ ...@@ -20,12 +20,14 @@
#include <stdbool.h> #include <stdbool.h>
#include <string.h> #include <string.h>
#include <arpa/inet.h> #if !defined(_WIN32)
# include <arpa/inet.h>
# include <sys/socket.h>
# include <net/if.h>
# include <netinet/tcp.h>
# include <netdb.h>
#endif
#include <sys/types.h> #include <sys/types.h>
#include <sys/socket.h>
#include <net/if.h>
#include <netinet/tcp.h>
#include <netdb.h>
#include <fcntl.h> #include <fcntl.h>
#include <errno.h> #include <errno.h>
#include <unistd.h> #include <unistd.h>
......
...@@ -125,11 +125,14 @@ lv2_osc_writer_add_float(LV2_OSC_Writer *writer, float f) ...@@ -125,11 +125,14 @@ lv2_osc_writer_add_float(LV2_OSC_Writer *writer, float f)
static inline bool static inline bool
lv2_osc_writer_add_string(LV2_OSC_Writer *writer, const char *s) lv2_osc_writer_add_string(LV2_OSC_Writer *writer, const char *s)
{ {
const size_t padded = LV2_OSC_PADDED_SIZE(strlen(s) + 1); const size_t rawlen = strlen(s) + 1;
const size_t padded = LV2_OSC_PADDED_SIZE(rawlen);
if(lv2_osc_writer_overflow(writer, padded)) if(lv2_osc_writer_overflow(writer, padded))
return false; return false;
strncpy((char *)writer->ptr, s, padded); const uint32_t blank = 0;
memcpy(writer->ptr + padded - sizeof(uint32_t), &blank, sizeof(uint32_t));
memcpy(writer->ptr, s, rawlen);
writer->ptr += padded; writer->ptr += padded;
return true; return true;
...@@ -171,7 +174,7 @@ lv2_osc_writer_add_blob_inline(LV2_OSC_Writer *writer, int32_t len, uint8_t **bo ...@@ -171,7 +174,7 @@ lv2_osc_writer_add_blob_inline(LV2_OSC_Writer *writer, int32_t len, uint8_t **bo
return false; return false;
*body = writer->ptr; *body = writer->ptr;
memset(&writer->ptr[len], 0x0, len_padded - len); //memset(&writer->ptr[len], 0x0, len_padded - len);
writer->ptr += len_padded; writer->ptr += len_padded;
return true; return true;
...@@ -196,7 +199,7 @@ lv2_osc_writer_add_midi_inline(LV2_OSC_Writer *writer, int32_t len, uint8_t **m) ...@@ -196,7 +199,7 @@ lv2_osc_writer_add_midi_inline(LV2_OSC_Writer *writer, int32_t len, uint8_t **m)
return false; return false;
*m = writer->ptr; *m = writer->ptr;
memset(&writer->ptr[len], 0x0, 4 - len); //memset(&writer->ptr[len], 0x0, 4 - len);
writer->ptr += 4; writer->ptr += 4;
return true; return true;
...@@ -301,12 +304,15 @@ lv2_osc_writer_add_path(LV2_OSC_Writer *writer, const char *path) ...@@ -301,12 +304,15 @@ lv2_osc_writer_add_path(LV2_OSC_Writer *writer, const char *path)
static inline bool static inline bool
lv2_osc_writer_add_format(LV2_OSC_Writer *writer, const char *fmt) lv2_osc_writer_add_format(LV2_OSC_Writer *writer, const char *fmt)
{ {
const size_t padded = LV2_OSC_PADDED_SIZE(strlen(fmt) + 2); const size_t rawlen = strlen(fmt) + 1;
const size_t padded = LV2_OSC_PADDED_SIZE(rawlen + 1);
if(lv2_osc_writer_overflow(writer, padded)) if(lv2_osc_writer_overflow(writer, padded))
return false; return false;
const uint32_t blank = 0;
memcpy(writer->ptr + padded - sizeof(uint32_t), &blank, sizeof(uint32_t));
*writer->ptr++ = ','; *writer->ptr++ = ',';
strncpy((char *)writer->ptr, fmt, padded - 1); memcpy(writer->ptr, fmt, rawlen);
writer->ptr += padded - 1; writer->ptr += padded - 1;
return true; return true;
...@@ -437,7 +443,7 @@ lv2_osc_writer_packet(LV2_OSC_Writer *writer, LV2_OSC_URID *osc_urid, ...@@ -437,7 +443,7 @@ lv2_osc_writer_packet(LV2_OSC_Writer *writer, LV2_OSC_URID *osc_urid,
return false; return false;
LV2_OSC_Timetag tt; LV2_OSC_Timetag tt;
LV2_OSC_Writer_Frame bndl; LV2_OSC_Writer_Frame bndl = { .ref = 0 };
lv2_osc_timetag_get(osc_urid, &timetag->atom, &tt); lv2_osc_timetag_get(osc_urid, &timetag->atom, &tt);
if(!lv2_osc_writer_push_bundle(writer, &bndl, lv2_osc_timetag_parse(&tt))) if(!lv2_osc_writer_push_bundle(writer, &bndl, lv2_osc_timetag_parse(&tt)))
...@@ -446,7 +452,7 @@ lv2_osc_writer_packet(LV2_OSC_Writer *writer, LV2_OSC_URID *osc_urid, ...@@ -446,7 +452,7 @@ lv2_osc_writer_packet(LV2_OSC_Writer *writer, LV2_OSC_URID *osc_urid,
LV2_ATOM_TUPLE_FOREACH(items, atom) LV2_ATOM_TUPLE_FOREACH(items, atom)
{ {
const LV2_Atom_Object *obj= (const LV2_Atom_Object *)atom; const LV2_Atom_Object *obj= (const LV2_Atom_Object *)atom;
LV2_OSC_Writer_Frame itm; LV2_OSC_Writer_Frame itm = { .ref = 0 };
if( !lv2_osc_writer_push_item(writer, &itm) if( !lv2_osc_writer_push_item(writer, &itm)
|| !lv2_osc_writer_packet(writer, osc_urid, unmap, obj->atom.size, &obj->body) || !lv2_osc_writer_packet(writer, osc_urid, unmap, obj->atom.size, &obj->body)
......
CC ?= gcc
C_FLAGS ?= -I../ -Wall -Wextra -Wpedantic $(shell pkg-config --cflags lv2) \
-fprofile-arcs -ftest-coverage
all: osc_test
osc_test: osc_test.c ../osc.lv2/*.h
$(CC) -std=gnu11 -g -o $@ $< $(C_FLAGS) -lpthread
check: osc_test
./$<
gcov $<.c
clean:
rm -f osc_test *.gcov *.gc* vgcore.*
...@@ -8,26 +8,28 @@ ...@@ -8,26 +8,28 @@
#include <osc.lv2/reader.h> #include <osc.lv2/reader.h>
#include <osc.lv2/writer.h> #include <osc.lv2/writer.h>
#include <osc.lv2/forge.h> #include <osc.lv2/forge.h>
#include <osc.lv2/stream.h> #if !defined(_WIN32)
# include <osc.lv2/stream.h>
#endif
#define BUF_SIZE 0x100000 #define BUF_SIZE 0x100000
#define MAX_URIDS 512 #define MAX_URIDS 512
typedef void (*test_t)(LV2_OSC_Writer *writer); typedef void (*test_t)(LV2_OSC_Writer *writer);
typedef struct _urid_t urid_t; typedef struct _urid_t urid_t;
typedef struct _handle_t handle_t; typedef struct _app_t app_t;
struct _urid_t { struct _urid_t {
LV2_URID urid; LV2_URID urid;
char *uri; char *uri;
}; };
struct _handle_t { struct _app_t {
urid_t urids [MAX_URIDS]; urid_t urids [MAX_URIDS];
LV2_URID urid; LV2_URID urid;
}; };
static handle_t __handle; static app_t __app;
static uint8_t buf0 [BUF_SIZE]; static uint8_t buf0 [BUF_SIZE];
static uint8_t buf1 [BUF_SIZE]; static uint8_t buf1 [BUF_SIZE];
static uint8_t buf2 [BUF_SIZE]; static uint8_t buf2 [BUF_SIZE];
...@@ -134,19 +136,19 @@ const uint8_t raw_8 [] = { ...@@ -134,19 +136,19 @@ const uint8_t raw_8 [] = {
static LV2_URID static LV2_URID
_map(LV2_URID_Map_Handle instance, const char *uri) _map(LV2_URID_Map_Handle instance, const char *uri)
{ {
handle_t *handle = instance; app_t *app = instance;
urid_t *itm; urid_t *itm;
for(itm=handle->urids; itm->urid; itm++) for(itm=app->urids; itm->urid; itm++)
{ {
if(!strcmp(itm->uri, uri)) if(!strcmp(itm->uri, uri))
return itm->urid; return itm->urid;
} }
assert(handle->urid + 1 < MAX_URIDS); assert(app->urid + 1 < MAX_URIDS);
// create new // create new
itm->urid = ++handle->urid; itm->urid = ++app->urid;
itm->uri = strdup(uri); itm->uri = strdup(uri);
return itm->urid; return itm->urid;
...@@ -155,10 +157,10 @@ _map(LV2_URID_Map_Handle instance, const char *uri) ...@@ -155,10 +157,10 @@ _map(LV2_URID_Map_Handle instance, const char *uri)
static const char * static const char *
_unmap(LV2_URID_Unmap_Handle instance, LV2_URID urid) _unmap(LV2_URID_Unmap_Handle instance, LV2_URID urid)
{ {
handle_t *handle = instance; app_t *app = instance;
urid_t *itm; urid_t *itm;
for(itm=handle->urids; itm->urid; itm++) for(itm=app->urids; itm->urid; itm++)
{ {
if(itm->urid == urid) if(itm->urid == urid)
return itm->uri; return itm->uri;
...@@ -169,12 +171,12 @@ _unmap(LV2_URID_Unmap_Handle instance, LV2_URID urid) ...@@ -169,12 +171,12 @@ _unmap(LV2_URID_Unmap_Handle instance, LV2_URID urid)
} }
static LV2_URID_Map map = { static LV2_URID_Map map = {
.handle = &__handle, .handle = &__app,
.map = _map .map = _map
}; };
static LV2_URID_Unmap unmap = { static LV2_URID_Unmap unmap = {
.handle = &__handle, .handle = &__app,
.unmap = _unmap .unmap = _unmap
}; };
...@@ -197,7 +199,7 @@ _clone(LV2_OSC_Reader *reader, LV2_OSC_Writer *writer, size_t size) ...@@ -197,7 +199,7 @@ _clone(LV2_OSC_Reader *reader, LV2_OSC_Writer *writer, size_t size)
LV2_OSC_Item *itm = OSC_READER_BUNDLE_BEGIN(reader, size); LV2_OSC_Item *itm = OSC_READER_BUNDLE_BEGIN(reader, size);
assert(itm); assert(itm);
LV2_OSC_Writer_Frame frame_bndl; LV2_OSC_Writer_Frame frame_bndl = { .ref = 0 };
assert(lv2_osc_writer_push_bundle(writer, &frame_bndl, itm->timetag)); assert(lv2_osc_writer_push_bundle(writer, &frame_bndl, itm->timetag));
OSC_READER_BUNDLE_ITERATE(reader, itm) OSC_READER_BUNDLE_ITERATE(reader, itm)
...@@ -205,7 +207,7 @@ _clone(LV2_OSC_Reader *reader, LV2_OSC_Writer *writer, size_t size) ...@@ -205,7 +207,7 @@ _clone(LV2_OSC_Reader *reader, LV2_OSC_Writer *writer, size_t size)
LV2_OSC_Reader reader2; LV2_OSC_Reader reader2;
lv2_osc_reader_initialize(&reader2, itm->body, itm->size); lv2_osc_reader_initialize(&reader2, itm->body, itm->size);
LV2_OSC_Writer_Frame frame_itm; LV2_OSC_Writer_Frame frame_itm = { .ref = 0 };
assert(lv2_osc_writer_push_item(writer, &frame_itm)); assert(lv2_osc_writer_push_item(writer, &frame_itm));
_clone(&reader2, writer, itm->size); _clone(&reader2, writer, itm->size);
assert(lv2_osc_writer_pop_item(writer, &frame_itm)); assert(lv2_osc_writer_pop_item(writer, &frame_itm));
...@@ -341,7 +343,7 @@ static void ...@@ -341,7 +343,7 @@ static void
test_2_a(LV2_OSC_Writer *writer) test_2_a(LV2_OSC_Writer *writer)
{ {
assert(lv2_osc_writer_message_vararg(writer, "/ping", "hdS", assert(lv2_osc_writer_message_vararg(writer, "/ping", "hdS",
12, 3.4, "http://example.com")); (int64_t)12, (double)3.4, "http://example.com"));
_test_a(writer, raw_2, sizeof(raw_2)); _test_a(writer, raw_2, sizeof(raw_2));
} }
...@@ -373,7 +375,8 @@ test_5_a(LV2_OSC_Writer *writer) ...@@ -373,7 +375,8 @@ test_5_a(LV2_OSC_Writer *writer)
static void static void
test_6_a(LV2_OSC_Writer *writer) test_6_a(LV2_OSC_Writer *writer)
{ {
LV2_OSC_Writer_Frame frame_bndl, frame_itm; LV2_OSC_Writer_Frame frame_bndl = { .ref = 0 };
LV2_OSC_Writer_Frame frame_itm = { .ref = 0 };
assert(lv2_osc_writer_push_bundle(writer, &frame_bndl, LV2_OSC_IMMEDIATE)); assert(lv2_osc_writer_push_bundle(writer, &frame_bndl, LV2_OSC_IMMEDIATE));
{ {
...@@ -391,7 +394,8 @@ test_6_a(LV2_OSC_Writer *writer) ...@@ -391,7 +394,8 @@ test_6_a(LV2_OSC_Writer *writer)
static void static void
test_7_a(LV2_OSC_Writer *writer) test_7_a(LV2_OSC_Writer *writer)
{ {
LV2_OSC_Writer_Frame frame_bndl[2], frame_itm[2]; LV2_OSC_Writer_Frame frame_bndl[2] = { { .ref = 0 }, { .ref = 0 } };
LV2_OSC_Writer_Frame frame_itm[2] = { { .ref = 0 }, { .ref = 0 } };;
assert(lv2_osc_writer_push_bundle(writer, &frame_bndl[0], LV2_OSC_IMMEDIATE)); assert(lv2_osc_writer_push_bundle(writer, &frame_bndl[0], LV2_OSC_IMMEDIATE));
{ {
...@@ -466,6 +470,7 @@ _run_tests() ...@@ -466,6 +470,7 @@ _run_tests()
return 0; return 0;
} }
#if !defined(_WIN32)
typedef struct _item_t item_t; typedef struct _item_t item_t;
typedef struct _stash_t stash_t; typedef struct _stash_t stash_t;
...@@ -896,6 +901,7 @@ static const pair_t pairs [] = { ...@@ -896,6 +901,7 @@ static const pair_t pairs [] = {
.lossy = false .lossy = false
} }
}; };
#endif
int int
main(int argc, char **argv) main(int argc, char **argv)
...@@ -906,6 +912,7 @@ main(int argc, char **argv) ...@@ -906,6 +912,7 @@ main(int argc, char **argv)
fprintf(stdout, "running main tests:\n"); fprintf(stdout, "running main tests:\n");
assert(_run_tests() == 0); assert(_run_tests() == 0);
#if !defined(_WIN32)
for(const pair_t *pair = pairs; pair->server; pair++) for(const pair_t *pair = pairs; pair->server; pair++)
{ {
pthread_t thread_1; pthread_t thread_1;
...@@ -920,10 +927,11 @@ main(int argc, char **argv) ...@@ -920,10 +927,11 @@ main(int argc, char **argv)
assert(pthread_join(thread_1, NULL) == 0); assert(pthread_join(thread_1, NULL) == 0);
assert(pthread_join(thread_2, NULL) == 0); assert(pthread_join(thread_2, NULL) == 0);
} }
#endif
for(unsigned i=0; i<__handle.urid; i++) for(unsigned i=0; i<__app.urid; i++)
{ {
urid_t *itm = &__handle.urids[i]; urid_t *itm = &__app.urids[i];
free(itm->uri); free(itm->uri);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment