commit 54cbea4cb5594e5d3a8875dc640996d2e12baded
parent d216e2d395bdd4d5be1fc0dc0aae1482d20eefe7
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Thu, 7 Dec 2017 14:08:36 +0100
Test the device API
Diffstat:
4 files changed, 113 insertions(+), 1 deletion(-)
diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt
@@ -95,6 +95,8 @@ if(NOT NO_TEST)
build_test(${_name})
register_test(${_name} ${_name})
endfunction()
+
+ new_test(test_sdis_device)
endif()
################################################################################
diff --git a/src/sdis_device.c b/src/sdis_device.c
@@ -47,7 +47,7 @@ sdis_device_create
struct logger* log = NULL;
struct sdis_device* dev = NULL;
struct mem_allocator* allocator = NULL;
- res_T res = RES_BAD_ARG;
+ res_T res = RES_OK;
if(nthreads_hint == 0 || !out_dev) {
res = RES_BAD_ARG;
diff --git a/src/test_sdis_device.c b/src/test_sdis_device.c
@@ -0,0 +1,77 @@
+/* Copyright (C) |Meso|Star> 2016-2017 (contact@meso-star.com)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#include "sdis.h"
+#include "test_sdis_utils.h"
+
+#include <rsys/logger.h>
+
+static INLINE void
+log_stream(const char* msg, void* ctx)
+{
+ ASSERT(msg);
+ (void) msg, (void) ctx;
+ printf("%s\n", msg);
+}
+
+int
+main(int argc, char** argv)
+{
+ struct logger logger;
+ struct mem_allocator allocator;
+ struct sdis_device* dev;
+ (void)argc, (void)argv;
+
+ CHK(sdis_device_create(NULL, NULL, 0, 0, NULL) == RES_BAD_ARG);
+ CHK(sdis_device_create(NULL, NULL, 0, 0, &dev) == RES_BAD_ARG);
+ CHK(sdis_device_create(NULL, NULL, 1, 0, &dev) == RES_OK);
+ CHK(sdis_device_ref_get(NULL) == RES_BAD_ARG);
+ CHK(sdis_device_ref_get(dev) == RES_OK);
+ CHK(sdis_device_ref_put(NULL) == RES_BAD_ARG);
+ CHK(sdis_device_ref_put(dev) == RES_OK);
+ CHK(sdis_device_ref_put(dev) == RES_OK);
+
+ CHK(mem_init_proxy_allocator(&allocator, &mem_default_allocator) == RES_OK);
+
+ CHK(MEM_ALLOCATED_SIZE(&allocator) == 0);
+ CHK(sdis_device_create(NULL, &allocator, 1, 0, NULL) == RES_BAD_ARG);
+ CHK(sdis_device_create(NULL, &allocator, 1, 0, &dev) == RES_OK);
+ CHK(sdis_device_ref_put(dev) == RES_OK);
+ CHK(MEM_ALLOCATED_SIZE(&allocator) == 0);
+
+ CHK(logger_init(&allocator, &logger) == RES_OK);
+ logger_set_stream(&logger, LOG_OUTPUT, log_stream, NULL);
+ logger_set_stream(&logger, LOG_ERROR, log_stream, NULL);
+ logger_set_stream(&logger, LOG_WARNING, log_stream, NULL);
+
+ CHK(sdis_device_create(&logger, NULL, 1, 0, NULL) == RES_BAD_ARG);
+ CHK(sdis_device_create(&logger, NULL, 1, 0, &dev) == RES_OK);
+ CHK(sdis_device_ref_put(dev) == RES_OK);
+
+ CHK(sdis_device_create(&logger, &allocator, 1, 0, NULL) == RES_BAD_ARG);
+ CHK(sdis_device_create(&logger, &allocator, 1, 0, &dev) == RES_OK);
+ CHK(sdis_device_ref_put(dev) == RES_OK);
+
+ CHK(sdis_device_create
+ (&logger, &allocator, SDIS_NTHREADS_DEFAULT, 0, &dev) == RES_OK);
+ CHK(sdis_device_ref_put(dev) == RES_OK);
+
+ logger_release(&logger);
+ check_memory_allocator(&allocator);
+ mem_shutdown_proxy_allocator(&allocator);
+ CHK(mem_allocated_size() == 0);
+ return 0;
+}
+
diff --git a/src/test_sdis_utils.h b/src/test_sdis_utils.h
@@ -0,0 +1,33 @@
+/* Copyright (C) |Meso|Star> 2016-2017 (contact@meso-star.com)
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#ifndef TEST_SDIS_UTILS_H
+#define TEST_SDIS_UTILS_H
+
+#include <rsys/mem_allocator.h>
+#include <stdio.h>
+
+static INLINE void
+check_memory_allocator(struct mem_allocator* allocator)
+{
+ if(MEM_ALLOCATED_SIZE(allocator)) {
+ char dump[128];
+ MEM_DUMP(allocator, dump, sizeof(dump));
+ fprintf(stderr, "%s\n", dump);
+ FATAL("Memory leaks.\n");
+ }
+}
+
+#endif /* TEST_SDIS_UTILS_H */