From 6a4118883ebbb3d16aaa6d675881873e174f4236 Mon Sep 17 00:00:00 2001 From: Philipp Schafft Date: Sat, 26 Feb 2022 09:56:14 +0000 Subject: [PATCH 1/8] Update: Require libigloo >= 0.9.1 --- configure.ac | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/configure.ac b/configure.ac index 26cb0859..58448a0a 100644 --- a/configure.ac +++ b/configure.ac @@ -140,6 +140,17 @@ AC_TYPE_UID_T dnl Checks for required libraries +dnl +dnl linigloo +dnl +PKG_CHECK_MODULES([LIBIGLOO], [igloo >= 0.9.1], [], [ + AC_MSG_ERROR([${LIBIGLOO_PKG_ERRORS}. libigloo (v0.9.0 or newer) is required.]) +]) + +CFLAGS="${CFLAGS} ${LIBIGLOO_CFLAGS}" +LIBS="${LIBS} ${LIBIGLOO_LIBS}" + + dnl dnl libxml2 dnl From e11cc390f844754fc7e410c0a2fa5283d286a097 Mon Sep 17 00:00:00 2001 From: Philipp Schafft Date: Sat, 26 Feb 2022 13:55:21 +0000 Subject: [PATCH 2/8] Feature: Create global libigloo instance --- src/global.c | 1 + src/global.h | 3 +++ src/main.c | 14 ++++++++++++++ 3 files changed, 18 insertions(+) diff --git a/src/global.c b/src/global.c index 80721ceb..87f781d4 100644 --- a/src/global.c +++ b/src/global.c @@ -27,6 +27,7 @@ #include "source.h" ice_global_t global; +igloo_ro_t igloo_instance = igloo_RO_NULL; static mutex_t _global_mutex; diff --git a/src/global.h b/src/global.h index e2f789e4..2788e73c 100644 --- a/src/global.h +++ b/src/global.h @@ -21,6 +21,8 @@ #define ICECAST_VERSION_STRING "Icecast " PACKAGE_VERSION +#include + #include "common/thread/thread.h" #include "common/avl/avl.h" #include "icecasttypes.h" @@ -46,6 +48,7 @@ typedef struct ice_global_tag } ice_global_t; extern ice_global_t global; +extern igloo_ro_t igloo_instance; void global_initialize(void); void global_shutdown(void); diff --git a/src/main.c b/src/main.c index dc66a15f..95c48294 100644 --- a/src/main.c +++ b/src/main.c @@ -45,6 +45,8 @@ #include #endif +#include + #include "common/thread/thread.h" #include "common/net/sock.h" #include "common/net/resolver.h" @@ -587,6 +589,11 @@ int main(int argc, char **argv) char pbuf[1024]; ice_config_t *config; + if (igloo_initialize(&igloo_instance) != igloo_ERROR_NONE) { + _fatal_error("FATAL: Can not initialize libigloo."); + return 1; + } + /* parse the '-c icecast.xml' option ** only, so that we can read a configfile */ @@ -597,6 +604,7 @@ int main(int argc, char **argv) if (!_start_logging_stdout()) { _fatal_error("FATAL: Could not start logging on stderr."); shutdown_subsystems(); + igloo_ro_unref(&igloo_instance); return 1; } #endif @@ -626,10 +634,12 @@ int main(int argc, char **argv) #if !defined(_WIN32) || defined(_CONSOLE) || defined(__MINGW32__) || defined(__MINGW64__) shutdown_subsystems(); #endif + igloo_ro_unref(&igloo_instance); return 1; } } else { _print_usage(); + igloo_ro_unref(&igloo_instance); return 1; } @@ -640,6 +650,7 @@ int main(int argc, char **argv) if(!_server_proc_init()) { _fatal_error("Server startup failed. Exiting"); shutdown_subsystems(); + igloo_ro_unref(&igloo_instance); return 1; } @@ -650,6 +661,7 @@ int main(int argc, char **argv) if (!_start_logging()) { _fatal_error("FATAL: Could not start logging"); shutdown_subsystems(); + igloo_ro_unref(&igloo_instance); return 1; } @@ -668,6 +680,7 @@ int main(int argc, char **argv) fprintf(stderr, "ERROR: You should not run icecast2 as root\n"); fprintf(stderr, "Use the changeowner directive in the config file\n"); shutdown_subsystems(); + igloo_ro_unref(&igloo_instance); return 1; } #endif @@ -706,6 +719,7 @@ int main(int argc, char **argv) free (pidfile); } + igloo_ro_unref(&igloo_instance); return 0; } From ac5d17cbdb046b38673b25b599f141b43cd9d78b Mon Sep 17 00:00:00 2001 From: Philipp Schafft Date: Sat, 26 Feb 2022 14:30:14 +0000 Subject: [PATCH 3/8] Cleanup: Migrated to libigloo's PRNG --- src/cfgfile.c | 12 +-- src/prng.c | 236 ++++---------------------------------------------- src/prng.h | 7 -- src/slave.c | 12 +-- src/yp.c | 5 +- 5 files changed, 27 insertions(+), 245 deletions(-) diff --git a/src/cfgfile.c b/src/cfgfile.c index 272ce316..bd286448 100644 --- a/src/cfgfile.c +++ b/src/cfgfile.c @@ -1405,18 +1405,10 @@ static void _parse_root(xmlDocPtr doc, configuration->port = 8000; if (!configuration->prng_seed) { - configuration->config_problems |= CONFIG_PROBLEM_PRNG; #ifndef _WIN32 - configuration->prng_seed = calloc(1, sizeof(prng_seed_config_t)); - if (configuration->prng_seed) { - configuration->prng_seed->filename = (char*)xmlStrdup(XMLSTR("linux")); // the linux profile is also fine on BSD. - configuration->prng_seed->type = PRNG_SEED_TYPE_PROFILE; - configuration->prng_seed->size = -1; - ICECAST_LOG_WARN("Warning, no PRNG seed configured, using default profile \"linux\"."); - } else { - ICECAST_LOG_ERROR("No PRNG seed configured and unable to add one. PRNG is insecure."); - } + ICECAST_LOG_WARN("Warning, no PRNG seed configured, falling back to libigloo defaults."); #else + configuration->config_problems |= CONFIG_PROBLEM_PRNG; ICECAST_LOG_ERROR("No PRNG seed configured and unable to add one. PRNG is insecure."); #endif } diff --git a/src/prng.c b/src/prng.c index 716f30a4..b2a80b04 100644 --- a/src/prng.c +++ b/src/prng.c @@ -28,10 +28,13 @@ #include #endif +#include + #include "common/thread/thread.h" #include "common/timing/timing.h" #include "prng.h" +#include "global.h" #include "digest.h" #include "cfgfile.h" @@ -44,46 +47,14 @@ #define SEEDING_MAX_BEFORE_RESEED 32768 static int initialized = 0; -static mutex_t digest_a_lock; -static mutex_t digest_b_lock; -static digest_t * digest_a; // protected by digest_a_lock -static digest_t * digest_b; // protected by digest_b_lock -static size_t before_reseed; // protected by digest_a_lock static void prng_initial_seed(void) { - struct { - int debian; - uint64_t t; -#ifdef HAVE_UNAME - struct utsname utsname; -#endif -#ifdef HAVE_SETUID - uid_t uid; - pid_t pid; - pid_t ppid; -#endif - } seed; #ifdef HAVE_OPENSSL char buffer[1024]; const char *filename; #endif - memset(&seed, 0, sizeof(seed)); - - seed.debian = 4; - seed.t = timing_get_time(); -#ifdef HAVE_UNAME - uname(&seed.utsname); -#endif -#ifdef HAVE_SETUID - seed.uid = getuid(); - seed.pid = getpid(); - seed.ppid = getppid(); -#endif - - prng_write(&seed, sizeof(seed)); - #ifdef HAVE_OPENSSL filename = RAND_file_name(buffer, sizeof(buffer)); if (filename) @@ -99,11 +70,11 @@ static void prng_cross_seed(void) #ifdef HAVE_OPENSSL if (RAND_bytes((unsigned char*)buffer, sizeof(buffer)) == 1) { - prng_write(buffer, sizeof(buffer)); + igloo_prng_write(igloo_instance, buffer, sizeof(buffer), -1, igloo_PRNG_FLAG_NONE); } else { ERR_get_error(); // clear error } - len = prng_read(buffer, sizeof(buffer)); + len = igloo_prng_read(igloo_instance, buffer, sizeof(buffer), igloo_PRNG_FLAG_NONE); if (len > 0) RAND_add(buffer, len, len/10.); #endif @@ -116,24 +87,20 @@ static void prng_read_seeds(prng_seed_config_t *seed, int configure_time) case PRNG_SEED_TYPE_READ_ONCE: case PRNG_SEED_TYPE_READ_WRITE: if (configure_time) - prng_read_file(seed->filename, seed->size); + igloo_prng_read_file(igloo_instance, seed->filename, seed->size, -1, igloo_PRNG_FLAG_NONE); break; case PRNG_SEED_TYPE_DEVICE: - prng_read_file(seed->filename, seed->size); + igloo_prng_read_file(igloo_instance, seed->filename, seed->size, -1, igloo_PRNG_FLAG_NONE); break; case PRNG_SEED_TYPE_STATIC: - prng_write(seed->filename, strlen(seed->filename)); + igloo_prng_write(igloo_instance, seed->filename, strlen(seed->filename), -1, igloo_PRNG_FLAG_NONE); break; case PRNG_SEED_TYPE_PROFILE: if (strcmp(seed->filename, "linux") == 0) { - if (configure_time) { - prng_read_file("/proc/sys/kernel/random/boot_id", -1); - prng_read_file("/etc/machine-id", -1); - } - prng_read_file("/proc/sys/kernel/random/uuid", -1); + igloo_prng_read_file(igloo_instance, "/proc/sys/kernel/random/uuid", -1, -1, igloo_PRNG_FLAG_NONE); } if (strcmp(seed->filename, "linux") == 0 || strcmp(seed->filename, "bsd") == 0) { - prng_read_file("/dev/urandom", 64); + igloo_prng_read_file(igloo_instance, "/dev/urandom", 64, -1, igloo_PRNG_FLAG_NONE); } break; } @@ -146,10 +113,6 @@ void prng_initialize(void) if (initialized) return; - thread_mutex_create(&digest_a_lock); - thread_mutex_create(&digest_b_lock); - digest_a = digest_new(DIGEST_ALGO_SHA3_512); - digest_b = digest_new(DIGEST_ALGO_SHA3_512); initialized = 1; prng_initial_seed(); prng_cross_seed(); @@ -160,11 +123,6 @@ void prng_shutdown(void) if (!initialized) return; - refobject_unref(digest_b); - refobject_unref(digest_a); - thread_mutex_destroy(&digest_b_lock); - thread_mutex_destroy(&digest_a_lock); - initialized = 0; } @@ -173,10 +131,10 @@ void prng_configure(ice_config_t *config) if (!initialized) return; - prng_write(config->location, strlen(config->location)); - prng_write(config->admin, strlen(config->admin)); - prng_write(config->hostname, strlen(config->hostname)); - prng_write(config, sizeof(*config)); + igloo_prng_write(igloo_instance, config->location, strlen(config->location), -1, igloo_PRNG_FLAG_NONE); + igloo_prng_write(igloo_instance, config->admin, strlen(config->admin), -1, igloo_PRNG_FLAG_NONE); + igloo_prng_write(igloo_instance, config->hostname, strlen(config->hostname), -1, igloo_PRNG_FLAG_NONE); + igloo_prng_write(igloo_instance, config, sizeof(*config), -1, igloo_PRNG_FLAG_NONE); prng_read_seeds(config->prng_seed, 1); prng_cross_seed(); } @@ -193,173 +151,9 @@ void prng_deconfigure(void) seed = config->prng_seed; while (seed) { if (seed->type == PRNG_SEED_TYPE_READ_WRITE) { - prng_write_file(seed->filename, seed->size); + igloo_prng_write_file(igloo_instance, seed->filename, seed->size, igloo_PRNG_FLAG_NONE); } seed = seed->next; } config_release_config(); } - -void prng_auto_reseed(void) -{ - int need_seeding; - ice_config_t *config; - - thread_mutex_lock(&digest_a_lock); - need_seeding = before_reseed == 0; - thread_mutex_unlock(&digest_a_lock); - - if (!need_seeding) - return; - - config = config_get_config(); - prng_read_seeds(config->prng_seed, 0); - config_release_config(); - prng_cross_seed(); -} - -void prng_write(const void *buffer, size_t len) -{ - if (!initialized) - return; - - thread_mutex_lock(&digest_a_lock); - digest_write(digest_a, buffer, len); - digest_write(digest_a, &len, sizeof(len)); - before_reseed += len * SEEDING_FACTOR; - if (before_reseed > SEEDING_MAX_BEFORE_RESEED) - before_reseed = SEEDING_MAX_BEFORE_RESEED; - thread_mutex_unlock(&digest_a_lock); -} - -static ssize_t prng_read_block(void *froma, void *buffer, size_t len) -{ - char fromb[BLOCK_LENGTH]; - - digest_write(digest_b, froma, BLOCK_LENGTH); - - if (digest_read(digest_b, fromb, sizeof(fromb)) != sizeof(fromb)) - return -1; - - refobject_unref(digest_b); - digest_b = digest_new(DIGEST_ALGO_SHA3_512); - digest_write(digest_b, fromb, sizeof(fromb)); - digest_write(digest_b, &len, sizeof(len)); - - if (len > sizeof(fromb)) - len = sizeof(fromb); - - memcpy(buffer, fromb, len); - - return len; -} - -ssize_t prng_read(void *buffer, size_t len) -{ - digest_t *copy; - char froma[BLOCK_LENGTH]; - size_t ret = 0; - ssize_t res; - - if (!initialized) - return -1; - - thread_mutex_lock(&digest_a_lock); - digest_write(digest_a, &len, sizeof(len)); - copy = digest_copy(digest_a); - if (before_reseed > len) { - before_reseed -= len; - } else { - before_reseed = 0; - } - thread_mutex_unlock(&digest_a_lock); - - if (!copy) - return -1; - - if (digest_read(copy, froma, sizeof(froma)) != sizeof(froma)) - return -1; - - refobject_unref(copy); - - thread_mutex_lock(&digest_b_lock); - while (ret < len) { - res = prng_read_block(froma, buffer + ret, len - ret); - if (res < 0) { - thread_mutex_unlock(&digest_b_lock); - return -1; - } - ret += res; - } - thread_mutex_unlock(&digest_b_lock); - - return ret; -} - -int prng_write_file(const char *filename, ssize_t len) -{ - char buffer[BLOCK_LENGTH*16]; - size_t done = 0; - FILE *file; - - if (len < 0) - len = 1024; - - file = fopen(filename, "wb"); - if (!file) - return -1; - - while (done < (size_t)len) { - size_t todo = (size_t)len < sizeof(buffer) ? (size_t)len : sizeof(buffer); - ssize_t res = prng_read(buffer, todo); - if (res < 1) { - fclose(file); - return -1; - } - - if (fwrite(buffer, 1, res, file) != (size_t)res) { - fclose(file); - return -1; - } - - done += res; - } - - fclose(file); - return 0; -} - -int prng_read_file(const char *filename, ssize_t len) -{ - char buffer[BLOCK_LENGTH*16]; - size_t done = 0; - int fh; - - if (len < 0 || len > 1048576) - len = 1048576; - -#ifdef O_CLOEXEC - fh = open(filename, O_RDONLY|O_CLOEXEC, 0); -#else - fh = open(filename, O_RDONLY, 0); -#endif - if (fh < 0) - return -1; - - while (done < (size_t)len) { - size_t todo = (size_t)len < sizeof(buffer) ? (size_t)len : sizeof(buffer); - size_t res = read(fh, buffer, todo); - - if (res < 1) { - close(fh); - return 0; - } - - prng_write(buffer, res); - - done += res; - } - - close(fh); - return 0; -} diff --git a/src/prng.h b/src/prng.h index 958d5d22..e2e9201a 100644 --- a/src/prng.h +++ b/src/prng.h @@ -15,12 +15,5 @@ void prng_initialize(void); void prng_shutdown(void); void prng_configure(ice_config_t *config); void prng_deconfigure(void); -void prng_auto_reseed(void); - -void prng_write(const void *buffer, size_t len); -ssize_t prng_read(void *buffer, size_t len); - -int prng_write_file(const char *filename, ssize_t len); -int prng_read_file(const char *filename, ssize_t len); #endif diff --git a/src/slave.c b/src/slave.c index a5ac06a4..0564eec9 100644 --- a/src/slave.c +++ b/src/slave.c @@ -38,6 +38,9 @@ #include "compat.h" #include + +#include + #include "common/thread/thread.h" #include "common/avl/avl.h" #include "common/net/sock.h" @@ -54,7 +57,6 @@ #include "logging.h" #include "source.h" #include "format.h" -#include "prng.h" #define CATMODULE "slave" @@ -313,7 +315,7 @@ static client_t *open_relay_connection (relay_t *relay, relay_config_upstream_t ICECAST_LOG_ERROR("Header read failed for %s (%s:%d%s)", relay->config->localmount, server, port, mount); break; } - prng_write(header, strlen(header)); + igloo_prng_write(igloo_instance, header, strlen(header), -1, igloo_PRNG_FLAG_NONE); parser = httpp_create_parser(); httpp_initialize (parser, NULL); if (! httpp_parse_response (parser, header, strlen(header), relay->config->localmount)) @@ -801,7 +803,7 @@ static int update_from_master(ice_config_t *config) size_t len = strlen(buf); if (!len) break; - prng_write(buf, len); + igloo_prng_write(igloo_instance, buf, len, -1, igloo_PRNG_FLAG_NONE); } while (sock_read_line(mastersock, buf, sizeof(buf))) { size_t len = strlen(buf); @@ -810,7 +812,7 @@ static int update_from_master(ice_config_t *config) if (!len) continue; - prng_write(buf, len); + igloo_prng_write(igloo_instance, buf, len, -1, igloo_PRNG_FLAG_NONE); ICECAST_LOG_DEBUG("read %d from master \"%s\"", count++, buf); xmlURIPtr parsed_uri = xmlParseURI(buf); @@ -916,7 +918,7 @@ static void *_slave_thread(void *arg) global_unlock(); thread_sleep(1000000); - prng_auto_reseed(); + igloo_prng_auto_reseed(igloo_instance, igloo_PRNG_FLAG_NONE); thread_mutex_lock(&_slave_mutex); if (slave_running == 0) { thread_mutex_unlock(&_slave_mutex); diff --git a/src/yp.c b/src/yp.c index 7248a255..106f34bf 100644 --- a/src/yp.c +++ b/src/yp.c @@ -20,6 +20,8 @@ #include #include +#include + #include "common/thread/thread.h" #include "yp.h" @@ -30,7 +32,6 @@ #include "cfgfile.h" #include "stats.h" #include "listensocket.h" -#include "prng.h" #ifdef WIN32 #define snprintf _snprintf @@ -112,7 +113,7 @@ static size_t handle_returned_header (void *ptr, size_t size, size_t nmemb, void ypdata_t *yp = stream; size_t bytes = size * nmemb; - prng_write(ptr, bytes); + igloo_prng_write(igloo_instance, ptr, bytes, -1, igloo_PRNG_FLAG_NONE); /* ICECAST_LOG_DEBUG("header from YP is \"%.*s\"", bytes, ptr); */ if (strncasecmp (ptr, "YPResponse: 1", 13) == 0) From 26b1449d19bbb7776adeee1b5f089b9b63740c11 Mon Sep 17 00:00:00 2001 From: Philipp Schafft Date: Mon, 14 Mar 2022 08:35:04 +0000 Subject: [PATCH 4/8] Cleanup: Migrated to libigloo's TAP support --- src/tests/Makefile.am | 14 +- src/tests/ctest_buffer.c | 230 +++++++++++++++++--------------- src/tests/ctest_lib.c | 84 ------------ src/tests/ctest_lib.h | 21 --- src/tests/ctest_refobject.c | 139 ++++++++++--------- src/tests/ctest_resourcematch.c | 32 +++-- src/tests/ctest_suite.c | 13 +- 7 files changed, 226 insertions(+), 307 deletions(-) delete mode 100644 src/tests/ctest_lib.c delete mode 100644 src/tests/ctest_lib.h diff --git a/src/tests/Makefile.am b/src/tests/Makefile.am index f5d03860..ea49f546 100644 --- a/src/tests/Makefile.am +++ b/src/tests/Makefile.am @@ -9,34 +9,26 @@ TEST_LOG_DRIVER = env AM_TAP_AWK='$(AWK)' $(SHELL) \ check_PROGRAMS = -# -# Helper library for TAP tests -# - -libice_ctest_la_SOURCES = tests/ctest_lib.c %reldir%/ctest_lib.h -noinst_LTLIBRARIES = libice_ctest.la - # # Test programs # ctest_suite_test_SOURCES = tests/ctest_suite.c -ctest_suite_test_LDADD = libice_ctest.la check_PROGRAMS += ctest_suite.test ctest_resourcematch_test_SOURCES = tests/ctest_resourcematch.c -ctest_resourcematch_test_LDADD = libice_ctest.la icecast-resourcematch.o +ctest_resourcematch_test_LDADD = icecast-resourcematch.o check_PROGRAMS += ctest_resourcematch.test ctest_refobject_test_SOURCES = tests/ctest_refobject.c -ctest_refobject_test_LDADD = libice_ctest.la \ +ctest_refobject_test_LDADD = \ common/thread/libicethread.la \ common/avl/libiceavl.la \ icecast-refobject.o check_PROGRAMS += ctest_refobject.test ctest_buffer_test_SOURCES = tests/ctest_buffer.c -ctest_buffer_test_LDADD = libice_ctest.la \ +ctest_buffer_test_LDADD = \ common/thread/libicethread.la \ common/avl/libiceavl.la \ icecast-refobject.o \ diff --git a/src/tests/ctest_buffer.c b/src/tests/ctest_buffer.c index 682d3e00..15e6c82a 100644 --- a/src/tests/ctest_buffer.c +++ b/src/tests/ctest_buffer.c @@ -11,23 +11,39 @@ #endif #include +#include +#include /* for EXIT_FAILURE */ +#include -#include "ctest_lib.h" +#include #include "../src/buffer.h" #include "../src/refobject.h" +static void ctest_diagnostic_printf(const char *format, ...) +{ + char buf[1024]; + va_list ap; + va_start(ap, format); + + vsnprintf(buf, sizeof(buf), format, ap); + + va_end(ap); + + igloo_tap_diagnostic(buf); +} + static void test_create_ref_unref(void) { buffer_t *a; a = buffer_new(-1, NULL, NULL, REFOBJECT_NULL); - ctest_test("buffer created", a != NULL); - ctest_test("un-referenced", refobject_unref(a) == 0); + igloo_tap_test("buffer created", a != NULL); + igloo_tap_test("un-referenced", refobject_unref(a) == 0); a = refobject_new(buffer_t); - ctest_test("buffer created", a != NULL); - ctest_test("un-referenced", refobject_unref(a) == 0); + igloo_tap_test("buffer created", a != NULL); + igloo_tap_test("un-referenced", refobject_unref(a) == 0); } @@ -38,13 +54,13 @@ static void test_name(void) const char *ret; a = buffer_new(-1, NULL, name, REFOBJECT_NULL); - ctest_test("buffer created", a != NULL); + igloo_tap_test("buffer created", a != NULL); ret = refobject_get_name(a); - ctest_test("get name", ret != NULL); - ctest_test("name match", strcmp(name, ret) == 0); + igloo_tap_test("get name", ret != NULL); + igloo_tap_test("name match", strcmp(name, ret) == 0); - ctest_test("un-referenced", refobject_unref(a) == 0); + igloo_tap_test("un-referenced", refobject_unref(a) == 0); } static void test_userdata(void) @@ -55,27 +71,27 @@ static void test_userdata(void) void *ret; a = buffer_new(-1, NULL, NULL, REFOBJECT_NULL); - ctest_test("buffer created", a != NULL); + igloo_tap_test("buffer created", a != NULL); ret = refobject_get_userdata(a); - ctest_test("get userdata", ret == NULL); - ctest_test("set userdata", refobject_set_userdata(a, userdata) == 0); + igloo_tap_test("get userdata", ret == NULL); + igloo_tap_test("set userdata", refobject_set_userdata(a, userdata) == 0); ret = refobject_get_userdata(a); - ctest_test("get userdata", ret == userdata); - ctest_test("clearing userdata", refobject_set_userdata(a, NULL) == 0); + igloo_tap_test("get userdata", ret == userdata); + igloo_tap_test("clearing userdata", refobject_set_userdata(a, NULL) == 0); ret = refobject_get_userdata(a); - ctest_test("get userdata", ret == NULL); + igloo_tap_test("get userdata", ret == NULL); - ctest_test("un-referenced", refobject_unref(a) == 0); + igloo_tap_test("un-referenced", refobject_unref(a) == 0); a = buffer_new(-1, userdata, NULL, REFOBJECT_NULL); - ctest_test("buffer created", a != NULL); - ctest_test("refobject created", !REFOBJECT_IS_NULL(a)); + igloo_tap_test("buffer created", a != NULL); + igloo_tap_test("refobject created", !REFOBJECT_IS_NULL(a)); ret = refobject_get_userdata(a); - ctest_test("get userdata", ret == userdata); - ctest_test("clearing userdata", refobject_set_userdata(a, NULL) == 0); + igloo_tap_test("get userdata", ret == userdata); + igloo_tap_test("clearing userdata", refobject_set_userdata(a, NULL) == 0); ret = refobject_get_userdata(a); - ctest_test("get userdata", ret == NULL); - ctest_test("un-referenced", refobject_unref(a) == 0); + igloo_tap_test("get userdata", ret == NULL); + igloo_tap_test("un-referenced", refobject_unref(a) == 0); } static void test_associated(void) @@ -84,14 +100,14 @@ static void test_associated(void) buffer_t *b; a = refobject_new(refobject_base_t); - ctest_test("refobject created", !REFOBJECT_IS_NULL(a)); + igloo_tap_test("refobject created", !REFOBJECT_IS_NULL(a)); b = buffer_new(-1, NULL, NULL, a); - ctest_test("buffer created with associated", !REFOBJECT_IS_NULL(b)); + igloo_tap_test("buffer created with associated", !REFOBJECT_IS_NULL(b)); - ctest_test("un-referenced (1 of 2)", refobject_unref(b) == 0); - ctest_test("un-referenced (2 of 2)", refobject_unref(a) == 0); + igloo_tap_test("un-referenced (1 of 2)", refobject_unref(b) == 0); + igloo_tap_test("un-referenced (2 of 2)", refobject_unref(a) == 0); } static void test_empty(void) @@ -103,39 +119,39 @@ static void test_empty(void) int ret; a = refobject_new(buffer_t); - ctest_test("buffer created", a != NULL); + igloo_tap_test("buffer created", a != NULL); ret = buffer_get_data(a, &data, &length); - ctest_test("got data and length from buffer", ret == 0); + igloo_tap_test("got data and length from buffer", ret == 0); if (ret == 0) { - ctest_test("data is updated", data != &data); - ctest_test("length is zero", length == 0); + igloo_tap_test("data is updated", data != &data); + igloo_tap_test("length is zero", length == 0); } data = &data; ret = buffer_get_data(a, &data, NULL); - ctest_test("got data from buffer", ret == 0); + igloo_tap_test("got data from buffer", ret == 0); if (ret == 0) { - ctest_test("data is updated", data != &data); + igloo_tap_test("data is updated", data != &data); } length = 5; ret = buffer_get_data(a, NULL, &length); - ctest_test("got length from buffer", ret == 0); + igloo_tap_test("got length from buffer", ret == 0); if (ret == 0) { - ctest_test("length is zero", length == 0); + igloo_tap_test("length is zero", length == 0); } ret = buffer_get_string(a, &string); - ctest_test("got string from buffer", ret == 0); + igloo_tap_test("got string from buffer", ret == 0); if (ret == 0) { - ctest_test("string is non-NULL", string != NULL); + igloo_tap_test("string is non-NULL", string != NULL); if (string != NULL) { - ctest_test("string is empty", *string == 0); + igloo_tap_test("string is empty", *string == 0); } } - ctest_test("un-referenced", refobject_unref(a) == 0); + igloo_tap_test("un-referenced", refobject_unref(a) == 0); } static void test_string(void) @@ -148,29 +164,29 @@ static void test_string(void) int ret; a = refobject_new(buffer_t); - ctest_test("buffer created", a != NULL); - ctest_test("pushed string", buffer_push_string(a, hw) == 0); + igloo_tap_test("buffer created", a != NULL); + igloo_tap_test("pushed string", buffer_push_string(a, hw) == 0); ret = buffer_get_string(a, &string); - ctest_test("got strong", ret == 0); + igloo_tap_test("got strong", ret == 0); if (ret == 0) { - ctest_test("string is non-NULL", string != NULL); + igloo_tap_test("string is non-NULL", string != NULL); if (string != NULL) { - ctest_test("string matches input", strcmp(string, hw) == 0); + igloo_tap_test("string matches input", strcmp(string, hw) == 0); } } - ctest_test("pushed string", buffer_push_string(a, count) == 0); + igloo_tap_test("pushed string", buffer_push_string(a, count) == 0); string = NULL; ret = buffer_get_string(a, &string); - ctest_test("got strong", ret == 0); + igloo_tap_test("got strong", ret == 0); if (ret == 0) { - ctest_test("string is non-NULL", string != NULL); + igloo_tap_test("string is non-NULL", string != NULL); if (string != NULL) { - ctest_test("string matches combined input", strcmp(string, combined) == 0); + igloo_tap_test("string matches combined input", strcmp(string, combined) == 0); } } - ctest_test("un-referenced", refobject_unref(a) == 0); + igloo_tap_test("un-referenced", refobject_unref(a) == 0); } static void test_binary(void) @@ -183,38 +199,38 @@ static void test_binary(void) const void *data; a = refobject_new(buffer_t); - ctest_test("buffer created", a != NULL); + igloo_tap_test("buffer created", a != NULL); - ctest_test("pushed data pattern a", buffer_push_data(a, pattern_a, sizeof(pattern_a)) == 0); + igloo_tap_test("pushed data pattern a", buffer_push_data(a, pattern_a, sizeof(pattern_a)) == 0); length = sizeof(pattern_a) + 42; data = &data; ret = buffer_get_data(a, &data, &length); - ctest_test("got data", ret == 0); + igloo_tap_test("got data", ret == 0); if (ret == 0) { - ctest_test("correct length was returned", length == sizeof(pattern_a)); - ctest_test("data is non-NULL", data != NULL); - ctest_test("data has been set", data != &data); + igloo_tap_test("correct length was returned", length == sizeof(pattern_a)); + igloo_tap_test("data is non-NULL", data != NULL); + igloo_tap_test("data has been set", data != &data); if (length == sizeof(pattern_a) && data != NULL && data != &data) { - ctest_test("data matches pattern", memcmp(data, pattern_a, sizeof(pattern_a)) == 0); + igloo_tap_test("data matches pattern", memcmp(data, pattern_a, sizeof(pattern_a)) == 0); } } - ctest_test("pushed data pattern b", buffer_push_data(a, pattern_b, sizeof(pattern_b)) == 0); + igloo_tap_test("pushed data pattern b", buffer_push_data(a, pattern_b, sizeof(pattern_b)) == 0); length = sizeof(pattern_a) + sizeof(pattern_b) + 42; data = &data; ret = buffer_get_data(a, &data, &length); - ctest_test("got data", ret == 0); + igloo_tap_test("got data", ret == 0); if (ret == 0) { - ctest_test("correct length was returned", length == (sizeof(pattern_a) + sizeof(pattern_b))); - ctest_test("data is non-NULL", data != NULL); - ctest_test("data has been set", data != &data); + igloo_tap_test("correct length was returned", length == (sizeof(pattern_a) + sizeof(pattern_b))); + igloo_tap_test("data is non-NULL", data != NULL); + igloo_tap_test("data has been set", data != &data); if (length == (sizeof(pattern_a) + sizeof(pattern_b)) && data != NULL && data != &data) { - ctest_test("data matches combined pattern", memcmp(data, pattern_a, sizeof(pattern_a)) == 0 && memcmp(data + sizeof(pattern_a), pattern_b, sizeof(pattern_b)) == 0); + igloo_tap_test("data matches combined pattern", memcmp(data, pattern_a, sizeof(pattern_a)) == 0 && memcmp(data + sizeof(pattern_a), pattern_b, sizeof(pattern_b)) == 0); } } - ctest_test("un-referenced", refobject_unref(a) == 0); + igloo_tap_test("un-referenced", refobject_unref(a) == 0); } static void test__compare_to_string(buffer_t *a, const char *testname, const char *pattern) @@ -223,11 +239,11 @@ static void test__compare_to_string(buffer_t *a, const char *testname, const cha int ret; ret = buffer_get_string(a, &string); - ctest_test("got strong", ret == 0); + igloo_tap_test("got strong", ret == 0); if (ret == 0) { - ctest_test("string is non-NULL", string != NULL); + igloo_tap_test("string is non-NULL", string != NULL); if (string != NULL) { - ctest_test(testname, strcmp(string, pattern) == 0); + igloo_tap_test(testname, strcmp(string, pattern) == 0); ctest_diagnostic_printf("string=\"%s\", pattern=\"%s\"", string, pattern); } } @@ -239,21 +255,21 @@ static void test_shift(void) const char *pattern = "AABBBCC"; a = refobject_new(buffer_t); - ctest_test("buffer created", a != NULL); + igloo_tap_test("buffer created", a != NULL); - ctest_test("pushed string", buffer_push_string(a, pattern) == 0); + igloo_tap_test("pushed string", buffer_push_string(a, pattern) == 0); test__compare_to_string(a, "string matches input", pattern); - ctest_test("shifted data by 0 bytes", buffer_shift(a, 0) == 0); + igloo_tap_test("shifted data by 0 bytes", buffer_shift(a, 0) == 0); test__compare_to_string(a, "string matches input (no shift happened)", pattern); - ctest_test("shifted data by 2 bytes", buffer_shift(a, 2) == 0); + igloo_tap_test("shifted data by 2 bytes", buffer_shift(a, 2) == 0); test__compare_to_string(a, "string matches shifted input", pattern + 2); - ctest_test("shifted data by 3 bytes", buffer_shift(a, 3) == 0); + igloo_tap_test("shifted data by 3 bytes", buffer_shift(a, 3) == 0); test__compare_to_string(a, "string matches shifted input", pattern + 2 + 3); - ctest_test("shifted data by 3 bytes", buffer_shift(a, 2) == 0); + igloo_tap_test("shifted data by 3 bytes", buffer_shift(a, 2) == 0); test__compare_to_string(a, "string matches shifted input", pattern + 2 + 3 + 2); - ctest_test("shifted data beyond end (42 bytes)", buffer_shift(a, 42) != 0); + igloo_tap_test("shifted data beyond end (42 bytes)", buffer_shift(a, 42) != 0); - ctest_test("un-referenced", refobject_unref(a) == 0); + igloo_tap_test("un-referenced", refobject_unref(a) == 0); } static void test_length(void) @@ -265,20 +281,20 @@ static void test_length(void) const char *match_c = ""; a = refobject_new(buffer_t); - ctest_test("buffer created", a != NULL); + igloo_tap_test("buffer created", a != NULL); - ctest_test("pushed string", buffer_push_string(a, pattern) == 0); + igloo_tap_test("pushed string", buffer_push_string(a, pattern) == 0); test__compare_to_string(a, "string matches input", pattern); - ctest_test("Set length to match pattern a", buffer_set_length(a, strlen(match_a)) == 0); + igloo_tap_test("Set length to match pattern a", buffer_set_length(a, strlen(match_a)) == 0); test__compare_to_string(a, "string matches pattern a", match_a); - ctest_test("Set length to match pattern b", buffer_set_length(a, strlen(match_b)) == 0); + igloo_tap_test("Set length to match pattern b", buffer_set_length(a, strlen(match_b)) == 0); test__compare_to_string(a, "string matches pattern a", match_b); - ctest_test("Set length to match pattern c", buffer_set_length(a, strlen(match_c)) == 0); + igloo_tap_test("Set length to match pattern c", buffer_set_length(a, strlen(match_c)) == 0); test__compare_to_string(a, "string matches pattern a", match_c); - ctest_test("Set length to match pattern a (again)", buffer_set_length(a, strlen(match_a)) != 0); + igloo_tap_test("Set length to match pattern a (again)", buffer_set_length(a, strlen(match_a)) != 0); test__compare_to_string(a, "string still matches pattern c", match_c); - ctest_test("un-referenced", refobject_unref(a) == 0); + igloo_tap_test("un-referenced", refobject_unref(a) == 0); } static void test_printf(void) @@ -291,16 +307,16 @@ static void test_printf(void) const char *match_c = ":Hello World!:<-127 >? +127?"; a = refobject_new(buffer_t); - ctest_test("buffer created", a != NULL); + igloo_tap_test("buffer created", a != NULL); - ctest_test("Set length to match pattern a", buffer_push_printf(a, ":%s:", str) == 0); + igloo_tap_test("Set length to match pattern a", buffer_push_printf(a, ":%s:", str) == 0); test__compare_to_string(a, "string matches pattern a", match_a); - ctest_test("Set length to match pattern a", buffer_push_printf(a, "<%-5i>", num) == 0); + igloo_tap_test("Set length to match pattern a", buffer_push_printf(a, "<%-5i>", num) == 0); test__compare_to_string(a, "string matches pattern b", match_b); - ctest_test("Set length to match pattern a", buffer_push_printf(a, "?%+5i?", -num) == 0); + igloo_tap_test("Set length to match pattern a", buffer_push_printf(a, "?%+5i?", -num) == 0); test__compare_to_string(a, "string matches pattern c", match_c); - ctest_test("un-referenced", refobject_unref(a) == 0); + igloo_tap_test("un-referenced", refobject_unref(a) == 0); } static void test_push_buffer(void) @@ -311,45 +327,45 @@ static void test_push_buffer(void) const char *match_a = "AABBBCCAABBBCC"; a = refobject_new(buffer_t); - ctest_test("buffer a created", a != NULL); + igloo_tap_test("buffer a created", a != NULL); b = refobject_new(buffer_t); - ctest_test("buffer b created", b != NULL); + igloo_tap_test("buffer b created", b != NULL); - ctest_test("pushed string", buffer_push_string(a, pattern) == 0); + igloo_tap_test("pushed string", buffer_push_string(a, pattern) == 0); test__compare_to_string(a, "string matches input", pattern); - ctest_test("pushed buffer a to b", buffer_push_buffer(b, a) == 0); + igloo_tap_test("pushed buffer a to b", buffer_push_buffer(b, a) == 0); test__compare_to_string(b, "string matches input", pattern); - ctest_test("pushed buffer a to b", buffer_push_buffer(b, a) == 0); + igloo_tap_test("pushed buffer a to b", buffer_push_buffer(b, a) == 0); test__compare_to_string(b, "string matches pattern a", match_a); - ctest_test("un-referenced b", refobject_unref(b) == 0); - ctest_test("un-referenced a", refobject_unref(a) == 0); + igloo_tap_test("un-referenced b", refobject_unref(b) == 0); + igloo_tap_test("un-referenced a", refobject_unref(a) == 0); } int main (void) { - ctest_init(); + igloo_tap_init(); + igloo_tap_exit_on(igloo_TAP_EXIT_ON_FIN, NULL); + igloo_tap_group_run("create-ref-unref", test_create_ref_unref); - test_create_ref_unref(); + igloo_tap_group_run("name", test_name); + igloo_tap_group_run("userdata", test_userdata); + igloo_tap_group_run("associated", test_associated); - test_name(); - test_userdata(); - test_associated(); + igloo_tap_group_run("empty", test_empty); + igloo_tap_group_run("string", test_string); + igloo_tap_group_run("binary", test_binary); - test_empty(); - test_string(); - test_binary(); + igloo_tap_group_run("shift", test_shift); + igloo_tap_group_run("length", test_length); - test_shift(); - test_length(); + igloo_tap_group_run("printf", test_printf); + igloo_tap_group_run("push_buffer", test_push_buffer); - test_printf(); - test_push_buffer(); + igloo_tap_fin(); - ctest_fin(); - - return 0; + return EXIT_FAILURE; // return failure as we should never reach this point! } diff --git a/src/tests/ctest_lib.c b/src/tests/ctest_lib.c deleted file mode 100644 index 176a7df2..00000000 --- a/src/tests/ctest_lib.c +++ /dev/null @@ -1,84 +0,0 @@ -/* Icecast - * - * This program is distributed under the GNU General Public License, version 2. - * A copy of this license is included with this source. - * - * Copyright 2018, Philipp "ph3-der-loewe" Schafft , - */ - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include -#include - -#include "ctest_lib.h" - -static size_t ctest_g_test_num; -static int ctest_g_bailed_out; - -void ctest_init(void) -{ - ctest_g_test_num = 0; - ctest_g_bailed_out = 0; -} - -void ctest_fin(void) -{ - printf("1..%zu\n", ctest_g_test_num); -} - -void ctest_test(const char *desc, int res) -{ - const char *prefix = NULL; - - if (ctest_bailed_out()) - return; - - ctest_g_test_num++; - - if (res) { - prefix = "ok"; - } else { - prefix = "not ok"; - } - - if (desc) { - printf("%s %zu %s\n", prefix, ctest_g_test_num, desc); - } else { - printf("%s %zu\n", prefix, ctest_g_test_num); - } -} - -void ctest_diagnostic(const char *line) -{ - printf("# %s\n", line); -} - -void ctest_diagnostic_printf(const char *format, ...) -{ - va_list ap; - va_start(ap, format); - - printf("# "); - vprintf(format, ap); - printf("\n"); - - va_end(ap); -} - -void ctest_bail_out(const char *reason) -{ - ctest_g_bailed_out = 1; - if (reason) { - printf("Bail out! %s\n", reason); - } else { - printf("Bail out!\n"); - } -} - -int ctest_bailed_out(void) -{ - return ctest_g_bailed_out; -} diff --git a/src/tests/ctest_lib.h b/src/tests/ctest_lib.h deleted file mode 100644 index 69eb22ab..00000000 --- a/src/tests/ctest_lib.h +++ /dev/null @@ -1,21 +0,0 @@ -/* Icecast - * - * This program is distributed under the GNU General Public License, version 2. - * A copy of this license is included with this source. - * - * Copyright 2018, Philipp "ph3-der-loewe" Schafft , - */ - -#ifndef __CTEST_LIB_H__ -#define __CTEST_LIB_H__ - -void ctest_init(void); -void ctest_fin(void); - -void ctest_test(const char *desc, int res); -void ctest_diagnostic(const char *line); -void ctest_diagnostic_printf(const char *format, ...); -void ctest_bail_out(const char *reason); -int ctest_bailed_out(void); - -#endif diff --git a/src/tests/ctest_refobject.c b/src/tests/ctest_refobject.c index 36cb292e..f507894e 100644 --- a/src/tests/ctest_refobject.c +++ b/src/tests/ctest_refobject.c @@ -11,8 +11,9 @@ #endif #include +#include /* for EXIT_FAILURE */ -#include "ctest_lib.h" +#include #include "../refobject.h" @@ -21,10 +22,10 @@ static void test_ptr(void) refobject_t a; a = REFOBJECT_NULL; - ctest_test("NULL is NULL", REFOBJECT_IS_NULL(a)); + igloo_tap_test("NULL is NULL", REFOBJECT_IS_NULL(a)); if (!REFOBJECT_IS_NULL(a)) - ctest_bailed_out(); + igloo_tap_bail_out(NULL); } static void test_create_ref_unref(void) @@ -32,11 +33,11 @@ static void test_create_ref_unref(void) refobject_base_t *a; a = refobject_new(refobject_base_t); - ctest_test("refobject created", !REFOBJECT_IS_NULL(a)); + igloo_tap_test("refobject created", !REFOBJECT_IS_NULL(a)); - ctest_test("referenced", refobject_ref(a) == 0); - ctest_test("un-referenced (1 of 2)", refobject_unref(a) == 0); - ctest_test("un-referenced (2 of 2)", refobject_unref(a) == 0); + igloo_tap_test("referenced", refobject_ref(a) == 0); + igloo_tap_test("un-referenced (1 of 2)", refobject_unref(a) == 0); + igloo_tap_test("un-referenced (2 of 2)", refobject_unref(a) == 0); } static void test_typename(void) @@ -45,13 +46,13 @@ static void test_typename(void) const char *typename; a = refobject_new(refobject_base_t); - ctest_test("refobject created", !REFOBJECT_IS_NULL(a)); + igloo_tap_test("refobject created", !REFOBJECT_IS_NULL(a)); typename = REFOBJECT_GET_TYPENAME(a); - ctest_test("got typename", typename != NULL); - ctest_test("typename matches", strcmp(typename, "refobject_base_t") == 0); + igloo_tap_test("got typename", typename != NULL); + igloo_tap_test("typename matches", strcmp(typename, "refobject_base_t") == 0); - ctest_test("un-referenced", refobject_unref(a) == 0); + igloo_tap_test("un-referenced", refobject_unref(a) == 0); } static void test_valid(void) @@ -64,15 +65,15 @@ static void test_valid(void) REFOBJECT_DEFINE_PRIVATE_TYPE(ctest_test_type_t); - ctest_test("NULL is not valid", !REFOBJECT_IS_VALID(REFOBJECT_NULL, refobject_base_t)); + igloo_tap_test("NULL is not valid", !REFOBJECT_IS_VALID(REFOBJECT_NULL, refobject_base_t)); a = refobject_new(refobject_base_t); - ctest_test("refobject created", !REFOBJECT_IS_NULL(a)); + igloo_tap_test("refobject created", !REFOBJECT_IS_NULL(a)); - ctest_test("is valid", REFOBJECT_IS_VALID(a, refobject_base_t)); - ctest_test("is valid as diffrent type", !REFOBJECT_IS_VALID(a, ctest_test_type_t)); + igloo_tap_test("is valid", REFOBJECT_IS_VALID(a, refobject_base_t)); + igloo_tap_test("is valid as diffrent type", !REFOBJECT_IS_VALID(a, ctest_test_type_t)); - ctest_test("un-referenced", refobject_unref(a) == 0); + igloo_tap_test("un-referenced", refobject_unref(a) == 0); } static void test_sizes(void) @@ -110,23 +111,23 @@ static void test_sizes(void) ); a = REFOBJECT_FROM_TYPE(refobject_new(ctest_test_type_a_t)); - ctest_test("refobject created with size=sizeof(refobject_base_t) + 1024", !REFOBJECT_IS_NULL(a)); - ctest_test("un-referenced", refobject_unref(a) == 0); + igloo_tap_test("refobject created with size=sizeof(refobject_base_t) + 1024", !REFOBJECT_IS_NULL(a)); + igloo_tap_test("un-referenced", refobject_unref(a) == 0); a = REFOBJECT_FROM_TYPE(refobject_new(ctest_test_type_b_t)); - ctest_test("refobject created with size=sizeof(refobject_base_t) + 131072", !REFOBJECT_IS_NULL(a)); - ctest_test("un-referenced", refobject_unref(a) == 0); + igloo_tap_test("refobject created with size=sizeof(refobject_base_t) + 131072", !REFOBJECT_IS_NULL(a)); + igloo_tap_test("un-referenced", refobject_unref(a) == 0); a = REFOBJECT_FROM_TYPE(refobject_new(ctest_test_type_c_t)); - ctest_test("refobject created with size=sizeof(refobject_base_t) - 1", REFOBJECT_IS_NULL(a)); + igloo_tap_test("refobject created with size=sizeof(refobject_base_t) - 1", REFOBJECT_IS_NULL(a)); if (!REFOBJECT_IS_NULL(a)) { - ctest_test("un-referenced", refobject_unref(a) == 0); + igloo_tap_test("un-referenced", refobject_unref(a) == 0); } a = REFOBJECT_FROM_TYPE(refobject_new(ctest_test_type_d_t)); - ctest_test("refobject created with size=0", REFOBJECT_IS_NULL(a)); + igloo_tap_test("refobject created with size=0", REFOBJECT_IS_NULL(a)); if (!REFOBJECT_IS_NULL(a)) { - ctest_test("un-referenced", refobject_unref(a) == 0); + igloo_tap_test("un-referenced", refobject_unref(a) == 0); } } @@ -137,13 +138,13 @@ static void test_name(void) const char *ret; a = refobject_new_ext(refobject_base_t, NULL, name, REFOBJECT_NULL); - ctest_test("refobject created", !REFOBJECT_IS_NULL(a)); + igloo_tap_test("refobject created", !REFOBJECT_IS_NULL(a)); ret = refobject_get_name(a); - ctest_test("get name", ret != NULL); - ctest_test("name match", strcmp(name, ret) == 0); + igloo_tap_test("get name", ret != NULL); + igloo_tap_test("name match", strcmp(name, ret) == 0); - ctest_test("un-referenced", refobject_unref(a) == 0); + igloo_tap_test("un-referenced", refobject_unref(a) == 0); } static void test_userdata(void) @@ -154,27 +155,27 @@ static void test_userdata(void) void *ret; a = refobject_new(refobject_base_t); - ctest_test("refobject created", !REFOBJECT_IS_NULL(a)); + igloo_tap_test("refobject created", !REFOBJECT_IS_NULL(a)); ret = refobject_get_userdata(a); - ctest_test("get userdata", ret == NULL); - ctest_test("set userdata", refobject_set_userdata(a, userdata) == 0); + igloo_tap_test("get userdata", ret == NULL); + igloo_tap_test("set userdata", refobject_set_userdata(a, userdata) == 0); ret = refobject_get_userdata(a); - ctest_test("get userdata", ret == userdata); - ctest_test("clearing userdata", refobject_set_userdata(a, NULL) == 0); + igloo_tap_test("get userdata", ret == userdata); + igloo_tap_test("clearing userdata", refobject_set_userdata(a, NULL) == 0); ret = refobject_get_userdata(a); - ctest_test("get userdata", ret == NULL); + igloo_tap_test("get userdata", ret == NULL); - ctest_test("un-referenced", refobject_unref(a) == 0); + igloo_tap_test("un-referenced", refobject_unref(a) == 0); a = refobject_new_ext(refobject_base_t, userdata, NULL, REFOBJECT_NULL); - ctest_test("refobject created", !REFOBJECT_IS_NULL(a)); + igloo_tap_test("refobject created", !REFOBJECT_IS_NULL(a)); ret = refobject_get_userdata(a); - ctest_test("get userdata", ret == userdata); - ctest_test("clearing userdata", refobject_set_userdata(a, NULL) == 0); + igloo_tap_test("get userdata", ret == userdata); + igloo_tap_test("clearing userdata", refobject_set_userdata(a, NULL) == 0); ret = refobject_get_userdata(a); - ctest_test("get userdata", ret == NULL); - ctest_test("un-referenced", refobject_unref(a) == 0); + igloo_tap_test("get userdata", ret == NULL); + igloo_tap_test("un-referenced", refobject_unref(a) == 0); } static void test_associated(void) @@ -182,13 +183,13 @@ static void test_associated(void) refobject_base_t *a, *b; a = refobject_new(refobject_base_t); - ctest_test("refobject created", !REFOBJECT_IS_NULL(a)); + igloo_tap_test("refobject created", !REFOBJECT_IS_NULL(a)); b = refobject_new_ext(refobject_base_t, NULL, NULL, a); - ctest_test("refobject created with associated", !REFOBJECT_IS_NULL(b)); + igloo_tap_test("refobject created with associated", !REFOBJECT_IS_NULL(b)); - ctest_test("un-referenced (1 of 2)", refobject_unref(b) == 0); - ctest_test("un-referenced (2 of 2)", refobject_unref(a) == 0); + igloo_tap_test("un-referenced (1 of 2)", refobject_unref(b) == 0); + igloo_tap_test("un-referenced (2 of 2)", refobject_unref(a) == 0); } static size_t test_freecb__called; @@ -211,45 +212,41 @@ static void test_freecb(void) test_freecb__called = 0; a = refobject_new(ctest_test_type_t); - ctest_test("refobject created", a != NULL); - ctest_test("un-referenced", refobject_unref(REFOBJECT_FROM_TYPE(a)) == 0); - ctest_test("freecb called", test_freecb__called == 1); + igloo_tap_test("refobject created", a != NULL); + igloo_tap_test("un-referenced", refobject_unref(REFOBJECT_FROM_TYPE(a)) == 0); + igloo_tap_test("freecb called", test_freecb__called == 1); test_freecb__called = 0; a = refobject_new(ctest_test_type_t); - ctest_test("refobject created", a != NULL); - ctest_test("referenced", refobject_ref(REFOBJECT_FROM_TYPE(a)) == 0); - ctest_test("freecb uncalled", test_freecb__called == 0); - ctest_test("un-referenced (1 of 2)", refobject_unref(REFOBJECT_FROM_TYPE(a)) == 0); - ctest_test("freecb uncalled", test_freecb__called == 0); - ctest_test("un-referenced (2 of 2)", refobject_unref(REFOBJECT_FROM_TYPE(a)) == 0); - ctest_test("freecb called", test_freecb__called == 1); + igloo_tap_test("refobject created", a != NULL); + igloo_tap_test("referenced", refobject_ref(REFOBJECT_FROM_TYPE(a)) == 0); + igloo_tap_test("freecb uncalled", test_freecb__called == 0); + igloo_tap_test("un-referenced (1 of 2)", refobject_unref(REFOBJECT_FROM_TYPE(a)) == 0); + igloo_tap_test("freecb uncalled", test_freecb__called == 0); + igloo_tap_test("un-referenced (2 of 2)", refobject_unref(REFOBJECT_FROM_TYPE(a)) == 0); + igloo_tap_test("freecb called", test_freecb__called == 1); } int main (void) { - ctest_init(); + igloo_tap_init(); + igloo_tap_exit_on(igloo_TAP_EXIT_ON_FIN|igloo_TAP_EXIT_ON_BAIL_OUT, NULL); - test_ptr(); + igloo_tap_group_run("ptr", test_ptr); - if (ctest_bailed_out()) { - ctest_fin(); - return 1; - } + igloo_tap_group_run("ref-unref", test_create_ref_unref); - test_create_ref_unref(); + igloo_tap_group_run("typename", test_typename); + igloo_tap_group_run("valid", test_valid); - test_typename(); - test_valid(); + igloo_tap_group_run("sizes", test_sizes); - test_sizes(); + igloo_tap_group_run("name", test_name); + igloo_tap_group_run("userdata", test_userdata); + igloo_tap_group_run("associated", test_associated); + igloo_tap_group_run("freecb", test_freecb); - test_name(); - test_userdata(); - test_associated(); - test_freecb(); + igloo_tap_fin(); - ctest_fin(); - - return 0; + return EXIT_FAILURE; // return failure as we should never reach this point! } diff --git a/src/tests/ctest_resourcematch.c b/src/tests/ctest_resourcematch.c index e3094269..8c3ae70d 100644 --- a/src/tests/ctest_resourcematch.c +++ b/src/tests/ctest_resourcematch.c @@ -11,12 +11,27 @@ #endif #include /* for NULL */ -#include /* for snprintf() */ +#include /* for snprintf() */ +#include /* for EXIT_FAILURE */ +#include -#include "ctest_lib.h" +#include #include "../resourcematch.h" +static void ctest_diagnostic_printf(const char *format, ...) +{ + char buf[1024]; + va_list ap; + va_start(ap, format); + + vsnprintf(buf, sizeof(buf), format, ap); + + va_end(ap); + + igloo_tap_diagnostic(buf); +} + struct test { const char *pattern; const char *string; @@ -103,16 +118,16 @@ static inline resourcematch_result_t run_test_base(const struct test *test, reso if (extract) { if (test->expected_result == RESOURCEMATCH_MATCH) { if (*extract) { - ctest_diagnostic(" got extract"); + igloo_tap_diagnostic(" got extract"); } else { - ctest_diagnostic(" got no extract"); + igloo_tap_diagnostic(" got no extract"); ok = 0; } } } snprintf(name, sizeof(name), "pattern \"%s\" and string \"%s\" %s extract", test->pattern, test->string, extract ? "with" : "without"); - ctest_test(name, test->expected_result == ret && ok); + igloo_tap_test(name, test->expected_result == ret && ok); ctest_diagnostic_printf("Expected: %s, Got: %s, Ok: %i", res2str(test->expected_result), res2str(ret), ok); @@ -165,11 +180,12 @@ int main (void) { size_t i; - ctest_init(); + igloo_tap_init(); + igloo_tap_exit_on(igloo_TAP_EXIT_ON_FIN, NULL); for (i = 0; i < (sizeof(tests)/sizeof(*tests)); i++) { run_test(&(tests[i])); } - ctest_fin(); + igloo_tap_fin(); - return 0; + return EXIT_FAILURE; // return failure as we should never reach this point! } diff --git a/src/tests/ctest_suite.c b/src/tests/ctest_suite.c index 91f75873..5e2dfeeb 100644 --- a/src/tests/ctest_suite.c +++ b/src/tests/ctest_suite.c @@ -9,12 +9,15 @@ #ifdef HAVE_CONFIG_H #include #endif +#include /* for EXIT_FAILURE */ -#include "ctest_lib.h" +#include int main (void) { - ctest_init(); - ctest_test("suite working", 1); - ctest_fin(); - return 0; + igloo_tap_init(); + igloo_tap_exit_on(igloo_TAP_EXIT_ON_FIN, NULL); + igloo_tap_test("suite working", true); + igloo_tap_fin(); + + return EXIT_FAILURE; // return failure as we should never reach this point! } From c5110c992f1b51938dbc44d9b99f066acbec993e Mon Sep 17 00:00:00 2001 From: Philipp Schafft Date: Mon, 14 Mar 2022 19:53:37 +0000 Subject: [PATCH 5/8] Cleanup: Migrated to libigloo's ro for module.[ch] --- src/client.c | 5 ++- src/connection_handle.c | 5 ++- src/global.c | 8 ++-- src/icecasttypes.h | 7 +++- src/module.c | 85 ++++++++++++++++++++++++++--------------- src/module.h | 6 ++- 6 files changed, 76 insertions(+), 40 deletions(-) diff --git a/src/client.c b/src/client.c index 35687a60..dfbc96fe 100644 --- a/src/client.c +++ b/src/client.c @@ -26,6 +26,9 @@ #include +#include "icecasttypes.h" +#include + #include "common/thread/thread.h" #include "common/avl/avl.h" #include "common/httpp/httpp.h" @@ -345,7 +348,7 @@ void client_destroy(client_t *client) if (client->free_client_data) client->free_client_data(client); - refobject_unref(client->handler_module); + igloo_ro_unref(&(client->handler_module)); free(client->handler_function); free(client->uri); free(client->username); diff --git a/src/connection_handle.c b/src/connection_handle.c index 3f87ee3e..95b3add9 100644 --- a/src/connection_handle.c +++ b/src/connection_handle.c @@ -20,6 +20,9 @@ #include #include +#include "icecasttypes.h" +#include + #include "connection_handle.h" #include "auth.h" #include "acl.h" @@ -115,7 +118,7 @@ static bool _handle_resources(client_t *client, char **uri) module_t *module = module_container_get_module(global.modulecontainer, resource->module); if (module != NULL) { - refobject_unref(client->handler_module); + igloo_ro_unref(&(client->handler_module)); client->handler_module = module; } else { ICECAST_LOG_ERROR("Module used in alias not found: %s", resource->module); diff --git a/src/global.c b/src/global.c index 87f781d4..f5960e51 100644 --- a/src/global.c +++ b/src/global.c @@ -18,11 +18,13 @@ #include +#include "icecasttypes.h" +#include + #include "common/thread/thread.h" #include "common/avl/avl.h" #include "global.h" -#include "refobject.h" #include "module.h" #include "source.h" @@ -41,14 +43,14 @@ void global_initialize(void) global.sources = 0; global.sources_legacy = 0; global.source_tree = avl_tree_new(source_compare_sources, NULL); - global.modulecontainer = refobject_new(module_container_t); + igloo_ro_new(&global.modulecontainer, module_container_t, igloo_instance); thread_mutex_create(&_global_mutex); } void global_shutdown(void) { thread_mutex_destroy(&_global_mutex); - refobject_unref(global.modulecontainer); + igloo_ro_unref(&global.modulecontainer); avl_tree_free(global.source_tree, NULL); } diff --git a/src/icecasttypes.h b/src/icecasttypes.h index 15bd7c60..adc6d48f 100644 --- a/src/icecasttypes.h +++ b/src/icecasttypes.h @@ -139,8 +139,6 @@ typedef struct refobject_base_tag refobject_base_t; typedef union __attribute__ ((__transparent_union__)) { refobject_base_t *refobject_base; buffer_t *buffer; - module_t *module; - module_container_t *module_container; reportxml_t *reportxml; reportxml_node_t *reportxml_node; reportxml_database_t *reportxml_database; @@ -154,4 +152,9 @@ typedef union __attribute__ ((__transparent_union__)) { typedef void * refobject_t; #endif +/* --- [ For libigloo ]--- */ +#define igloo_RO_APPTYPES \ + igloo_RO_TYPE(module_t) \ + igloo_RO_TYPE(module_container_t) + #endif diff --git a/src/module.c b/src/module.c index 52287f42..27fde80a 100644 --- a/src/module.c +++ b/src/module.c @@ -13,16 +13,21 @@ #include #include +#include "icecasttypes.h" +#include +#include + #include "common/thread/thread.h" #include "common/avl/avl.h" -#include "refobject.h" #include "module.h" +#include "global.h" /* for igloo_instance */ #include "cfgfile.h" /* for XMLSTR() */ struct module_tag { - refobject_base_t __base; + igloo_ro_full_t __parent; mutex_t lock; + char *name; const module_client_handler_t *client_handlers; size_t client_handlers_len; module_setup_handler_t freecb; @@ -33,49 +38,58 @@ struct module_tag { struct module_container_tag { - refobject_base_t __base; + igloo_ro_full_t __parent; mutex_t lock; avl_tree *module; }; static int compare_refobject_t_name(void *arg, void *a, void *b) { - return strcmp(refobject_get_name(a), refobject_get_name(b)); + return strcmp(((module_t*)a)->name, ((module_t*)b)->name); } -static void __module_container_free(refobject_t self, void **userdata) +static int free_ro(void * key) { - module_container_t *cont = REFOBJECT_TO_TYPE(self, module_container_t *); + igloo_ro_stub_t *stub = igloo_ro_to_type(key, igloo_ro_stub_t); + igloo_ro_unref(&stub); + return 0; +} + +static void __module_container_free(igloo_ro_t self) +{ + module_container_t *cont = igloo_ro_to_type(self, module_container_t); thread_mutex_destroy(&(cont->lock)); - avl_tree_free(cont->module, (avl_free_key_fun_type)refobject_unref); + avl_tree_free(cont->module, free_ro); } -int __module_container_new(refobject_t self, const refobject_type_t *type, va_list ap) +static igloo_error_t __module_container_new(igloo_ro_t self, const igloo_ro_type_t *type, va_list ap) { - module_container_t *ret = REFOBJECT_TO_TYPE(self, module_container_t*); + module_container_t *ret = igloo_ro_to_type(self, module_container_t); thread_mutex_create(&(ret->lock)); ret->module = avl_tree_new(compare_refobject_t_name, NULL); - return 0; + return igloo_ERROR_NONE; } -REFOBJECT_DEFINE_TYPE(module_container_t, - REFOBJECT_DEFINE_TYPE_FREE(__module_container_free), - REFOBJECT_DEFINE_TYPE_NEW(__module_container_new) +igloo_RO_PUBLIC_TYPE(module_container_t, igloo_ro_full_t, + igloo_RO_TYPEDECL_FREE(__module_container_free), + igloo_RO_TYPEDECL_NEW(__module_container_new) ); int module_container_add_module(module_container_t *self, module_t *module) { + module_t *ref; + if (!self) return -1; - if (refobject_ref(module) != 0) + if (igloo_ro_ref(module, &ref, module_t) != igloo_ERROR_NONE) return -1; thread_mutex_lock(&(self->lock)); - avl_insert(self->module, module); + avl_insert(self->module, ref); thread_mutex_unlock(&(self->lock)); return 0; @@ -93,32 +107,33 @@ int module_container_delete_module(module_container_t *self, return -1; thread_mutex_lock(&(self->lock)); - avl_delete(self->module, module, (avl_free_key_fun_type)refobject_unref); + avl_delete(self->module, module, free_ro); thread_mutex_unlock(&(self->lock)); - refobject_unref(module); + igloo_ro_unref(&module); return 0; } module_t * module_container_get_module(module_container_t *self, const char *name) { - refobject_base_t *search; - module_t *ret; + module_t *search; + module_t *result; + module_t *ret = NULL; if (!self || !name) return NULL; - search = refobject_new__new(refobject_base_t, NULL, name, NULL); + search = module_new(name, NULL, NULL, NULL); thread_mutex_lock(&(self->lock)); - if (avl_get_by_key(self->module, REFOBJECT_TO_TYPE(search, void *), (void**)&ret) != 0) { + if (avl_get_by_key(self->module, (void*)search, (void**)&result) != 0) { ret = NULL; } thread_mutex_unlock(&(self->lock)); - refobject_unref(search); - refobject_ref(ret); + igloo_ro_unref(&search); + igloo_ro_ref(result, &ret, module_t); return ret; } @@ -141,7 +156,7 @@ xmlNodePtr module_container_get_modulelist_as_xml(module_co module_t *module = avlnode->key; xmlNodePtr node = xmlNewChild(root, NULL, XMLSTR("module"), NULL); - xmlSetProp(node, XMLSTR("name"), XMLSTR(refobject_get_name(module))); + xmlSetProp(node, XMLSTR("name"), XMLSTR(module->name)); if (module->management_link_url) xmlSetProp(node, XMLSTR("management-url"), XMLSTR(module->management_link_url)); if (module->management_link_title) @@ -154,9 +169,9 @@ xmlNodePtr module_container_get_modulelist_as_xml(module_co return root; } -static void __module_free(refobject_t self, void **userdata) +static void __module_free(igloo_ro_t self) { - module_t *mod = REFOBJECT_TO_TYPE(self, module_t *); + module_t *mod = igloo_ro_to_type(self, module_t); if (mod->freecb) mod->freecb(mod, &(mod->userdata)); @@ -166,21 +181,29 @@ static void __module_free(refobject_t self, void **userdata) free(mod->management_link_url); free(mod->management_link_title); + free(mod->name); thread_mutex_destroy(&(mod->lock)); } -REFOBJECT_DEFINE_TYPE(module_t, - REFOBJECT_DEFINE_TYPE_FREE(__module_free) +igloo_RO_PUBLIC_TYPE(module_t, igloo_ro_full_t, + igloo_RO_TYPEDECL_FREE(__module_free) ); module_t * module_new(const char *name, module_setup_handler_t newcb, module_setup_handler_t freecb, void *userdata) { - module_t *ret = refobject_new__new(module_t, NULL, name, NULL); + module_t *ret; - if (!ret) + if (igloo_ro_new_raw(&ret, module_t, igloo_instance) != igloo_ERROR_NONE) return NULL; + ret->name = strdup(name); + + if (!ret->name) { + igloo_ro_unref(&ret); + return NULL; + } + thread_mutex_create(&(ret->lock)); ret->userdata = userdata; @@ -188,7 +211,7 @@ module_t * module_new(const char *name, module_setup_handler_t newc if (newcb) { if (newcb(ret, &(ret->userdata)) != 0) { - refobject_unref(ret); + igloo_ro_unref(&ret); return NULL; } } diff --git a/src/module.h b/src/module.h index 20ed3ada..72d2b04b 100644 --- a/src/module.h +++ b/src/module.h @@ -11,6 +11,8 @@ #include +#include + #include "icecasttypes.h" #include "refobject.h" @@ -22,8 +24,8 @@ typedef struct { module_client_handler_function_t cb; } module_client_handler_t; -REFOBJECT_FORWARD_TYPE(module_container_t); -REFOBJECT_FORWARD_TYPE(module_t); +igloo_RO_FORWARD_TYPE(module_container_t); +igloo_RO_FORWARD_TYPE(module_t); int module_container_add_module(module_container_t *self, module_t *module); int module_container_delete_module(module_container_t *self, const char *name); From 57cda00d9bb874d8d42f94e9987ecf0a637f0fd6 Mon Sep 17 00:00:00 2001 From: Philipp Schafft Date: Wed, 16 Mar 2022 11:30:27 +0000 Subject: [PATCH 6/8] Feature: Report libigloo version --- src/admin.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/admin.c b/src/admin.c index 72270dd7..515b3115 100644 --- a/src/admin.c +++ b/src/admin.c @@ -60,6 +60,8 @@ #include #endif +#include + #include "common/net/sock.h" #include "admin.h" @@ -1773,6 +1775,14 @@ static inline const char *get_speex_version(void) } #endif +static inline const char *get_igloo_version(void) +{ + const char *version; + if (igloo_version_get(&version, NULL, NULL, NULL) != igloo_ERROR_NONE) + return NULL; + return version; +} + static void command_version (client_t *client, source_t *source, admin_format_t response) { reportxml_t *report = client_get_reportxml("8cdfc150-094d-42f7-9c61-f9fb9a6e07e7", NULL, NULL); @@ -1792,6 +1802,7 @@ static void command_version (client_t *client, source_t *source, adm const char *compiletime; const char *runtime; } dependency_versions[] = { + {"libigloo", NULL, get_igloo_version()}, {"libxml2", LIBXML_DOTTED_VERSION, NULL}, #if defined(HAVE_OPENSSL) && defined(OPENSSL_VERSION_TEXT) {"OpenSSL", OPENSSL_VERSION_TEXT, NULL}, From e4787e228d2b05e43c522bb964e1daa3e29e7c18 Mon Sep 17 00:00:00 2001 From: Philipp Schafft Date: Wed, 16 Mar 2022 14:35:15 +0000 Subject: [PATCH 7/8] Update: Cleanup: Removed no longer used includes to common/ --- src/prng.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/prng.c b/src/prng.c index b2a80b04..b181ed90 100644 --- a/src/prng.c +++ b/src/prng.c @@ -30,9 +30,6 @@ #include -#include "common/thread/thread.h" -#include "common/timing/timing.h" - #include "prng.h" #include "global.h" #include "digest.h" From eb4d037842d96281f0ee812b2af36c4897c078bb Mon Sep 17 00:00:00 2001 From: Philipp Schafft Date: Wed, 16 Mar 2022 14:41:11 +0000 Subject: [PATCH 8/8] Cleanup: Removed unused buffer.[ch] --- src/Makefile.am | 2 - src/buffer.c | 311 -------------------------------- src/buffer.h | 193 -------------------- src/icecasttypes.h | 5 - src/tests/Makefile.am | 8 - src/tests/ctest_buffer.c | 371 --------------------------------------- 6 files changed, 890 deletions(-) delete mode 100644 src/buffer.c delete mode 100644 src/buffer.h delete mode 100644 src/tests/ctest_buffer.c diff --git a/src/Makefile.am b/src/Makefile.am index 9b161ff6..04f9bc49 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -34,7 +34,6 @@ noinst_HEADERS = \ matchfile.h \ tls.h \ refobject.h \ - buffer.h \ module.h \ reportxml.h \ reportxml_helper.h \ @@ -89,7 +88,6 @@ icecast_SOURCES = \ matchfile.c \ tls.c \ refobject.c \ - buffer.c \ module.c \ reportxml.c \ reportxml_helper.c \ diff --git a/src/buffer.c b/src/buffer.c deleted file mode 100644 index 33259993..00000000 --- a/src/buffer.c +++ /dev/null @@ -1,311 +0,0 @@ -/* Icecast - * - * This program is distributed under the GNU General Public License, version 2. - * A copy of this license is included with this source. - * - * Copyright 2018, Philipp "ph3-der-loewe" Schafft , - */ - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include -#include -#include -#include - -#include "buffer.h" -#include "refobject.h" - -struct buffer_tag { - refobject_base_t __base; - /* Buffer itself */ - void *buffer; - /* Length in bytes of buffer */ - size_t length; - /* Amount of bytes in use of the buffer. This includes offset bytes */ - size_t fill; - /* Bytes of offset at the start of the buffer */ - size_t offset; -}; - -static void __free(refobject_t self, void **userdata) -{ - buffer_t *buffer = REFOBJECT_TO_TYPE(self, buffer_t*); - - free(buffer->buffer); -} - -REFOBJECT_DEFINE_TYPE(buffer_t, - REFOBJECT_DEFINE_TYPE_FREE(__free), - REFOBJECT_DEFINE_TYPE_NEW_NOOP() - ); - -buffer_t * buffer_new(ssize_t preallocation, void *userdata, const char *name, refobject_t associated) -{ - buffer_t *buffer = refobject_new_ext(buffer_t, userdata, name, associated); - - if (!buffer) - return NULL; - - if (preallocation > 0) - buffer_preallocate(buffer, preallocation); - - return buffer; -} - -buffer_t * buffer_new_simple(void) -{ - return refobject_new(buffer_t); -} - -void buffer_preallocate(buffer_t *buffer, size_t request) -{ - void *n; - size_t newlen; - - if (!buffer) - return; - - /* Remove the offset if it makes sense to do so. */ - if (buffer->offset == buffer->fill) { - buffer->offset = 0; - buffer->fill = 0; - } else if ((2*buffer->offset) < buffer->fill || buffer->offset >= 512 || (buffer->offset > 128 && buffer->offset >= request)) { - buffer->fill -= buffer->offset; - memmove(buffer->buffer, buffer->buffer + buffer->offset, buffer->fill); - buffer->offset = 0; - } - - if (!request) - return; - - newlen = buffer->fill + request; - - if (buffer->length >= newlen) - return; - - /* Make sure we at least add 64 bytes and are 64 byte aligned */ - newlen = newlen + 64 - (newlen % 64); - - n = realloc(buffer->buffer, newlen); - - /* Just return if this failed */ - if (!n) - return; - - buffer->buffer = n; - buffer->length = newlen; -} - -int buffer_get_data(buffer_t *buffer, const void **data, size_t *length) -{ - if (!buffer) - return -1; - - if (data) { - *data = buffer->buffer + buffer->offset; - } - - if (length) { - *length = buffer->fill - buffer->offset; - } - - return 0; -} - -int buffer_get_string(buffer_t *buffer, const char **string) -{ - char *ret; - - if (!buffer || !string) - return -1; - - /* Ensure we have space for one additional byte ('\0'-termination). */ - if (buffer->length == buffer->fill) { - buffer_preallocate(buffer, 1); - if (buffer->length == buffer->fill) - return -1; - } - - /* Actually add a '\0'-termination. */ - ret = buffer->buffer; - ret[buffer->fill] = 0; - *string = ret + buffer->offset; - - return 0; -} - -int buffer_set_length(buffer_t *buffer, size_t length) -{ - if (!buffer) - return -1; - - if (length > (buffer->fill - buffer->offset)) - return -1; - - buffer->fill = length + buffer->offset; - - return 0; -} - -int buffer_shift(buffer_t *buffer, size_t amount) -{ - if (!buffer) - return -1; - - if (amount > (buffer->fill - buffer->offset)) - return -1; - - buffer->offset += amount; - - /* run cleanup */ - buffer_preallocate(buffer, 0); - - return 0; -} - -int buffer_push_data(buffer_t *buffer, const void *data, size_t length) -{ - void *buf; - int ret; - - if (!buffer) - return -1; - - if (!length) - return 0; - - if (!data) - return -1; - - ret = buffer_zerocopy_push_request(buffer, &buf, length); - if (ret != 0) - return ret; - - memcpy(buf, data, length); - - ret = buffer_zerocopy_push_complete(buffer, length); - - return ret; -} - -int buffer_push_string(buffer_t *buffer, const char *string) -{ - if (!buffer || !string) - return -1; - - return buffer_push_data(buffer, string, strlen(string)); -} - - -int buffer_push_printf(buffer_t *buffer, const char *format, ...) -{ - int ret; - va_list ap; - - if (!buffer || !format) - return -1; - - if (!*format) - return 0; - - va_start(ap, format); - ret = buffer_push_vprintf(buffer, format, ap); - va_end(ap); - - return ret; -} - -int buffer_push_vprintf(buffer_t *buffer, const char *format, va_list ap) -{ - void *buf; - int ret; - size_t length = 1024; - - if (!buffer || !format) - return -1; - - if (!*format) - return 0; - - ret = buffer_zerocopy_push_request(buffer, &buf, length); - if (ret != 0) - return ret; - - ret = vsnprintf(buf, length, format, ap); - if (ret >= 0 && (size_t)ret < length) { - return buffer_zerocopy_push_complete(buffer, ret); - } else if (ret < 0) { - /* This vsnprintf() likely does not follow POSIX. - * We don't know what length we need to asume. So asume a big one and hope for the best. */ - length = 8192; - } else { - /* Reallocate the buffer to the size reported plus one for '\0'-termination */ - length = ret + 1; - } - - /* We have not written any data yet. */ - ret = buffer_zerocopy_push_complete(buffer, 0); - if (ret != 0) - return ret; - - /* Now let's try again. */ - ret = buffer_zerocopy_push_request(buffer, &buf, length); - if (ret != 0) - return ret; - - ret = vsnprintf(buf, length, format, ap); - if (ret < 0 || (size_t)ret >= length) { - /* This still didn't work. Giving up. */ - buffer_zerocopy_push_complete(buffer, 0); - return -1; - } - - return buffer_zerocopy_push_complete(buffer, ret); -} - -int buffer_push_buffer(buffer_t *buffer, buffer_t *source) -{ - const void *data; - size_t length; - int ret; - - if (!buffer || !source) - return -1; - - ret = buffer_get_data(source, &data, &length); - if (ret != 0) - return ret; - - return buffer_push_data(buffer, data, length); -} - -int buffer_zerocopy_push_request(buffer_t *buffer, void **data, size_t request) -{ - if (!buffer || !data) - return -1; - - buffer_preallocate(buffer, request); - - if (request > (buffer->length - buffer->fill)) - return -1; - - *data = buffer->buffer + buffer->fill; - - return 0; -} - -int buffer_zerocopy_push_complete(buffer_t *buffer, size_t done) -{ - if (!buffer) - return -1; - - if (done > (buffer->length - buffer->fill)) - return -1; - - buffer->fill += done; - - return 0; -} diff --git a/src/buffer.h b/src/buffer.h deleted file mode 100644 index 661b2c6d..00000000 --- a/src/buffer.h +++ /dev/null @@ -1,193 +0,0 @@ -/* Icecast - * - * This program is distributed under the GNU General Public License, version 2. - * A copy of this license is included with this source. - * - * Copyright 2018, Philipp "ph3-der-loewe" Schafft , - */ - -/* - * This file contains the API for a refobject based buffer object. - * It can be used to store data and allows on the fly re-allocation. - */ - -#ifndef __BUFFER_H__ -#define __BUFFER_H__ - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include - -#include "icecasttypes.h" -#include "compat.h" -#include "refobject.h" - -/* About thread safety: - * This set of functions is intentinally not thread safe. - */ - -REFOBJECT_FORWARD_TYPE(buffer_t); - -/* This creates a new buffer object. - * Parameters: - * preallocation - * The number of bytes to allocate for use later on. See buffer_preallocate() for details. - * userdata, name, associated - * See refobject_new(). - */ -buffer_t * buffer_new(ssize_t preallocation, void *userdata, const char *name, refobject_t associated); - -/* Depreciated: This creates a new buffer with defaults. - * Do NOT use this. Use refobject_new(buffer_t) - * - * This is the same as: - * buffer_new(-1, NULL, NULL, REFOBJECT_NULL) - */ -buffer_t * buffer_new_simple(void); - -/* This function preallocates space for later use. - * Parameters: - * buffer - * The buffer to operate on. - * request - * Number of bytes to additionally allocate. - * Notes: - * This function is very usedful when adding a large number of smaller buffers to avoid - * internal reallocation calls happening to often. However it is not required to call - * this function before adding data to the buffer. - */ -void buffer_preallocate(buffer_t *buffer, size_t request); - -/* Gets data and length of the buffer. - * Parameters: - * buffer - * The buffer to operate on. - * data - * Pointer to the stored data. If NULL the pointer is not returned. - * length - * Pointer to the length of how many bytes are in the buffer. If NULL - * length is not returned. - */ -int buffer_get_data(buffer_t *buffer, const void **data, size_t *length); - -/* Gets data as a string. The string is '\0'-terminated. - * Parameters: - * buffery - * The buffer to operate on. - * string - * The string representing the data hold by the buffer. - */ -int buffer_get_string(buffer_t *buffer, const char **string); - -/* Sets the length of the buffer. - * Parameters: - * buffer - * The buffer to operate on. - * length - * New length of the buffer. - * Notes: - * This can only be used to reduce the size of the buffer. To add data to - * the buffer use buffer_push_*(). - * - * Calling this with length set to 0 clears the buffer but does not deallocate it. - */ -int buffer_set_length(buffer_t *buffer, size_t length); - -/* Shifts data out of the buffer. - * Parameters: - * buffer - * The buffer to operate on. - * amount - * The amount of bytes to be removed from the begin of the buffer. - * Notes: - * This function can be useful for skipping some small header. However this - * must not be used to implement a kind of ring buffer as it will result in - * poor performance caused by massive reallocations and memory copies. - */ -int buffer_shift(buffer_t *buffer, size_t amount); - -/* This pushes data to the end of the buffer. - * Parameters: - * buffer - * The buffer to operate on. - * data - * The data to push. - * length - * The length of the data to push in byte. - * Notes: - * Consider using buffer_zerocopy_*(). - */ -int buffer_push_data(buffer_t *buffer, const void *data, size_t length); - -/* This pushes a string to the end of the buffer. - * Parameters: - * buffer - * The buffer to operate on. - * string - * The string to be pushed. The tailing '\0'-termination will not be - * part of the buffer. - * Notes: - * Consider using buffer_zerocopy_*(). - */ -int buffer_push_string(buffer_t *buffer, const char *string); - -/* This pushes a formatted string to the end of the buffer. - * Parameters: - * buffer - * The buffer to operate on. - * format - * The format string as for printf() family functions. - * ... - * The parameters according to the format string. - */ -int buffer_push_printf(buffer_t *buffer, const char *format, ...); - -/* This pushes a formatted string to the end of the buffer using a va_list. - * Parameters: - * buffer - * The buffer to operate on. - * format - * The format string as for printf() family functions. - * ap - * The parameters according to the format string as va_list. - * See also: - * vprintf(3). - */ -int buffer_push_vprintf(buffer_t *buffer, const char *format, va_list ap); - -/* This pushes the content of another buffer to the end of the buffer. - * Parameters: - * buffer - * The buffer to operate on. - * source - * The buffer which's content is to be copied. - */ -int buffer_push_buffer(buffer_t *buffer, buffer_t *source); - -/* This requests for a memory buffer that can be pushed to without the need for copy. - * Parameters: - * buffer - * The buffer to operate on. - * data - * Pointer to memory that can be written and will become part of the buffer object. - * request - * Size of the memory area that is returned by data in bytes. - * Notes: - * This is the first step of the zero copy push. After the memory returned by data has been - * written (e.g. used in a call to read(2)) buffer_zerocopy_push_complete() must be called. - */ -int buffer_zerocopy_push_request(buffer_t *buffer, void **data, size_t request); - -/* This is the final step of a zero copy push. - * Parameters: - * buffer - * The buffer to operate on. - * done - * Amount of data in bytes that has actually been written into the memory area. - * May be zero to what has been requested with request. - */ -int buffer_zerocopy_push_complete(buffer_t *buffer, size_t done); - -#endif diff --git a/src/icecasttypes.h b/src/icecasttypes.h index adc6d48f..c130ab36 100644 --- a/src/icecasttypes.h +++ b/src/icecasttypes.h @@ -101,10 +101,6 @@ typedef enum { typedef struct relay_tag relay_t; -/* ---[ buffer.[ch] ]--- */ - -typedef struct buffer_tag buffer_t; - /* ---[ module.[ch] ]--- */ typedef struct module_tag module_t; @@ -138,7 +134,6 @@ typedef struct refobject_base_tag refobject_base_t; #ifdef HAVE_TYPE_ATTRIBUTE_TRANSPARENT_UNION typedef union __attribute__ ((__transparent_union__)) { refobject_base_t *refobject_base; - buffer_t *buffer; reportxml_t *reportxml; reportxml_node_t *reportxml_node; reportxml_database_t *reportxml_database; diff --git a/src/tests/Makefile.am b/src/tests/Makefile.am index ea49f546..6b382059 100644 --- a/src/tests/Makefile.am +++ b/src/tests/Makefile.am @@ -27,13 +27,5 @@ ctest_refobject_test_LDADD = \ icecast-refobject.o check_PROGRAMS += ctest_refobject.test -ctest_buffer_test_SOURCES = tests/ctest_buffer.c -ctest_buffer_test_LDADD = \ - common/thread/libicethread.la \ - common/avl/libiceavl.la \ - icecast-refobject.o \ - icecast-buffer.o -check_PROGRAMS += ctest_buffer.test - # Add all programs to TESTS TESTS = $(check_PROGRAMS) diff --git a/src/tests/ctest_buffer.c b/src/tests/ctest_buffer.c deleted file mode 100644 index 15e6c82a..00000000 --- a/src/tests/ctest_buffer.c +++ /dev/null @@ -1,371 +0,0 @@ -/* Icecast - * - * This program is distributed under the GNU General Public License, version 2. - * A copy of this license is included with this source. - * - * Copyright 2018, Philipp "ph3-der-loewe" Schafft , - */ - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include -#include -#include /* for EXIT_FAILURE */ -#include - -#include - -#include "../src/buffer.h" -#include "../src/refobject.h" - -static void ctest_diagnostic_printf(const char *format, ...) -{ - char buf[1024]; - va_list ap; - va_start(ap, format); - - vsnprintf(buf, sizeof(buf), format, ap); - - va_end(ap); - - igloo_tap_diagnostic(buf); -} - -static void test_create_ref_unref(void) -{ - buffer_t *a; - - a = buffer_new(-1, NULL, NULL, REFOBJECT_NULL); - igloo_tap_test("buffer created", a != NULL); - igloo_tap_test("un-referenced", refobject_unref(a) == 0); - - a = refobject_new(buffer_t); - igloo_tap_test("buffer created", a != NULL); - igloo_tap_test("un-referenced", refobject_unref(a) == 0); - -} - -static void test_name(void) -{ - buffer_t *a; - const char *name = "test object name"; - const char *ret; - - a = buffer_new(-1, NULL, name, REFOBJECT_NULL); - igloo_tap_test("buffer created", a != NULL); - - ret = refobject_get_name(a); - igloo_tap_test("get name", ret != NULL); - igloo_tap_test("name match", strcmp(name, ret) == 0); - - igloo_tap_test("un-referenced", refobject_unref(a) == 0); -} - -static void test_userdata(void) -{ - buffer_t *a; - int tmp = 0; - void *userdata = &tmp; - void *ret; - - a = buffer_new(-1, NULL, NULL, REFOBJECT_NULL); - igloo_tap_test("buffer created", a != NULL); - ret = refobject_get_userdata(a); - igloo_tap_test("get userdata", ret == NULL); - igloo_tap_test("set userdata", refobject_set_userdata(a, userdata) == 0); - ret = refobject_get_userdata(a); - igloo_tap_test("get userdata", ret == userdata); - igloo_tap_test("clearing userdata", refobject_set_userdata(a, NULL) == 0); - ret = refobject_get_userdata(a); - igloo_tap_test("get userdata", ret == NULL); - - igloo_tap_test("un-referenced", refobject_unref(a) == 0); - - a = buffer_new(-1, userdata, NULL, REFOBJECT_NULL); - igloo_tap_test("buffer created", a != NULL); - igloo_tap_test("refobject created", !REFOBJECT_IS_NULL(a)); - ret = refobject_get_userdata(a); - igloo_tap_test("get userdata", ret == userdata); - igloo_tap_test("clearing userdata", refobject_set_userdata(a, NULL) == 0); - ret = refobject_get_userdata(a); - igloo_tap_test("get userdata", ret == NULL); - igloo_tap_test("un-referenced", refobject_unref(a) == 0); -} - -static void test_associated(void) -{ - refobject_base_t *a; - buffer_t *b; - - a = refobject_new(refobject_base_t); - igloo_tap_test("refobject created", !REFOBJECT_IS_NULL(a)); - - - b = buffer_new(-1, NULL, NULL, a); - igloo_tap_test("buffer created with associated", !REFOBJECT_IS_NULL(b)); - - igloo_tap_test("un-referenced (1 of 2)", refobject_unref(b) == 0); - igloo_tap_test("un-referenced (2 of 2)", refobject_unref(a) == 0); -} - -static void test_empty(void) -{ - buffer_t *a; - const void *data = &data; - size_t length = 5; - const char *string; - int ret; - - a = refobject_new(buffer_t); - igloo_tap_test("buffer created", a != NULL); - - ret = buffer_get_data(a, &data, &length); - igloo_tap_test("got data and length from buffer", ret == 0); - if (ret == 0) { - igloo_tap_test("data is updated", data != &data); - igloo_tap_test("length is zero", length == 0); - } - - data = &data; - ret = buffer_get_data(a, &data, NULL); - igloo_tap_test("got data from buffer", ret == 0); - if (ret == 0) { - igloo_tap_test("data is updated", data != &data); - } - - length = 5; - ret = buffer_get_data(a, NULL, &length); - igloo_tap_test("got length from buffer", ret == 0); - if (ret == 0) { - igloo_tap_test("length is zero", length == 0); - } - - ret = buffer_get_string(a, &string); - igloo_tap_test("got string from buffer", ret == 0); - if (ret == 0) { - igloo_tap_test("string is non-NULL", string != NULL); - if (string != NULL) { - igloo_tap_test("string is empty", *string == 0); - } - } - - igloo_tap_test("un-referenced", refobject_unref(a) == 0); -} - -static void test_string(void) -{ - buffer_t *a; - const char *hw = "Hello World!"; - const char *count = "0 1 2 3 4"; - const char *combined = "Hello World!" "0 1 2 3 4"; - const char *string = NULL; - int ret; - - a = refobject_new(buffer_t); - igloo_tap_test("buffer created", a != NULL); - igloo_tap_test("pushed string", buffer_push_string(a, hw) == 0); - ret = buffer_get_string(a, &string); - igloo_tap_test("got strong", ret == 0); - if (ret == 0) { - igloo_tap_test("string is non-NULL", string != NULL); - if (string != NULL) { - igloo_tap_test("string matches input", strcmp(string, hw) == 0); - } - } - - igloo_tap_test("pushed string", buffer_push_string(a, count) == 0); - string = NULL; - ret = buffer_get_string(a, &string); - igloo_tap_test("got strong", ret == 0); - if (ret == 0) { - igloo_tap_test("string is non-NULL", string != NULL); - if (string != NULL) { - igloo_tap_test("string matches combined input", strcmp(string, combined) == 0); - } - } - - igloo_tap_test("un-referenced", refobject_unref(a) == 0); -} - -static void test_binary(void) -{ - buffer_t *a; - char pattern_a[8] = {0x01, 0x10, 0x80, 0xFF, 0x00, 0x55, 0xEE, 0xAA}; - char pattern_b[9] = {0x02, 0x03, 0xF0, 0x80, 0x0F, 0x04, 0x1A, 0x7F, 0x33}; - int ret; - size_t length; - const void *data; - - a = refobject_new(buffer_t); - igloo_tap_test("buffer created", a != NULL); - - igloo_tap_test("pushed data pattern a", buffer_push_data(a, pattern_a, sizeof(pattern_a)) == 0); - length = sizeof(pattern_a) + 42; - data = &data; - ret = buffer_get_data(a, &data, &length); - igloo_tap_test("got data", ret == 0); - if (ret == 0) { - igloo_tap_test("correct length was returned", length == sizeof(pattern_a)); - igloo_tap_test("data is non-NULL", data != NULL); - igloo_tap_test("data has been set", data != &data); - if (length == sizeof(pattern_a) && data != NULL && data != &data) { - igloo_tap_test("data matches pattern", memcmp(data, pattern_a, sizeof(pattern_a)) == 0); - } - } - - igloo_tap_test("pushed data pattern b", buffer_push_data(a, pattern_b, sizeof(pattern_b)) == 0); - length = sizeof(pattern_a) + sizeof(pattern_b) + 42; - data = &data; - ret = buffer_get_data(a, &data, &length); - igloo_tap_test("got data", ret == 0); - if (ret == 0) { - igloo_tap_test("correct length was returned", length == (sizeof(pattern_a) + sizeof(pattern_b))); - igloo_tap_test("data is non-NULL", data != NULL); - igloo_tap_test("data has been set", data != &data); - if (length == (sizeof(pattern_a) + sizeof(pattern_b)) && data != NULL && data != &data) { - igloo_tap_test("data matches combined pattern", memcmp(data, pattern_a, sizeof(pattern_a)) == 0 && memcmp(data + sizeof(pattern_a), pattern_b, sizeof(pattern_b)) == 0); - } - } - - - igloo_tap_test("un-referenced", refobject_unref(a) == 0); -} - -static void test__compare_to_string(buffer_t *a, const char *testname, const char *pattern) -{ - const char *string = NULL; - int ret; - - ret = buffer_get_string(a, &string); - igloo_tap_test("got strong", ret == 0); - if (ret == 0) { - igloo_tap_test("string is non-NULL", string != NULL); - if (string != NULL) { - igloo_tap_test(testname, strcmp(string, pattern) == 0); - ctest_diagnostic_printf("string=\"%s\", pattern=\"%s\"", string, pattern); - } - } -} - -static void test_shift(void) -{ - buffer_t *a; - const char *pattern = "AABBBCC"; - - a = refobject_new(buffer_t); - igloo_tap_test("buffer created", a != NULL); - - igloo_tap_test("pushed string", buffer_push_string(a, pattern) == 0); - test__compare_to_string(a, "string matches input", pattern); - igloo_tap_test("shifted data by 0 bytes", buffer_shift(a, 0) == 0); - test__compare_to_string(a, "string matches input (no shift happened)", pattern); - igloo_tap_test("shifted data by 2 bytes", buffer_shift(a, 2) == 0); - test__compare_to_string(a, "string matches shifted input", pattern + 2); - igloo_tap_test("shifted data by 3 bytes", buffer_shift(a, 3) == 0); - test__compare_to_string(a, "string matches shifted input", pattern + 2 + 3); - igloo_tap_test("shifted data by 3 bytes", buffer_shift(a, 2) == 0); - test__compare_to_string(a, "string matches shifted input", pattern + 2 + 3 + 2); - igloo_tap_test("shifted data beyond end (42 bytes)", buffer_shift(a, 42) != 0); - - igloo_tap_test("un-referenced", refobject_unref(a) == 0); -} - -static void test_length(void) -{ - buffer_t *a; - const char *pattern = "AABBBCC"; - const char *match_a = "AABBB"; - const char *match_b = "AABB"; - const char *match_c = ""; - - a = refobject_new(buffer_t); - igloo_tap_test("buffer created", a != NULL); - - igloo_tap_test("pushed string", buffer_push_string(a, pattern) == 0); - test__compare_to_string(a, "string matches input", pattern); - igloo_tap_test("Set length to match pattern a", buffer_set_length(a, strlen(match_a)) == 0); - test__compare_to_string(a, "string matches pattern a", match_a); - igloo_tap_test("Set length to match pattern b", buffer_set_length(a, strlen(match_b)) == 0); - test__compare_to_string(a, "string matches pattern a", match_b); - igloo_tap_test("Set length to match pattern c", buffer_set_length(a, strlen(match_c)) == 0); - test__compare_to_string(a, "string matches pattern a", match_c); - igloo_tap_test("Set length to match pattern a (again)", buffer_set_length(a, strlen(match_a)) != 0); - test__compare_to_string(a, "string still matches pattern c", match_c); - - igloo_tap_test("un-referenced", refobject_unref(a) == 0); -} - -static void test_printf(void) -{ - buffer_t *a; - const char *str = "Hello World!"; - const int num = -127; - const char *match_a = ":Hello World!:"; - const char *match_b = ":Hello World!:<-127 >"; - const char *match_c = ":Hello World!:<-127 >? +127?"; - - a = refobject_new(buffer_t); - igloo_tap_test("buffer created", a != NULL); - - igloo_tap_test("Set length to match pattern a", buffer_push_printf(a, ":%s:", str) == 0); - test__compare_to_string(a, "string matches pattern a", match_a); - igloo_tap_test("Set length to match pattern a", buffer_push_printf(a, "<%-5i>", num) == 0); - test__compare_to_string(a, "string matches pattern b", match_b); - igloo_tap_test("Set length to match pattern a", buffer_push_printf(a, "?%+5i?", -num) == 0); - test__compare_to_string(a, "string matches pattern c", match_c); - - igloo_tap_test("un-referenced", refobject_unref(a) == 0); -} - -static void test_push_buffer(void) -{ - buffer_t *a; - buffer_t *b; - const char *pattern = "AABBBCC"; - const char *match_a = "AABBBCCAABBBCC"; - - a = refobject_new(buffer_t); - igloo_tap_test("buffer a created", a != NULL); - b = refobject_new(buffer_t); - igloo_tap_test("buffer b created", b != NULL); - - igloo_tap_test("pushed string", buffer_push_string(a, pattern) == 0); - test__compare_to_string(a, "string matches input", pattern); - - igloo_tap_test("pushed buffer a to b", buffer_push_buffer(b, a) == 0); - test__compare_to_string(b, "string matches input", pattern); - - igloo_tap_test("pushed buffer a to b", buffer_push_buffer(b, a) == 0); - test__compare_to_string(b, "string matches pattern a", match_a); - - igloo_tap_test("un-referenced b", refobject_unref(b) == 0); - igloo_tap_test("un-referenced a", refobject_unref(a) == 0); -} - -int main (void) -{ - igloo_tap_init(); - igloo_tap_exit_on(igloo_TAP_EXIT_ON_FIN, NULL); - - igloo_tap_group_run("create-ref-unref", test_create_ref_unref); - - igloo_tap_group_run("name", test_name); - igloo_tap_group_run("userdata", test_userdata); - igloo_tap_group_run("associated", test_associated); - - igloo_tap_group_run("empty", test_empty); - igloo_tap_group_run("string", test_string); - igloo_tap_group_run("binary", test_binary); - - igloo_tap_group_run("shift", test_shift); - igloo_tap_group_run("length", test_length); - - igloo_tap_group_run("printf", test_printf); - igloo_tap_group_run("push_buffer", test_push_buffer); - - igloo_tap_fin(); - - return EXIT_FAILURE; // return failure as we should never reach this point! -}