commit 71a2fc0b49c6b592d18f6f98653a820cc2e4374c
parent 34c1c727ec92536180074f3a83a1804e76c1e079
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Wed, 8 Jun 2016 16:35:29 +0200
Test the s2d_device API
Diffstat:
3 files changed, 133 insertions(+), 1 deletion(-)
diff --git a/cmake/CMakeLists.txt b/cmake/CMakeLists.txt
@@ -116,7 +116,7 @@ if(NOT NO_TEST)
register_test(${_name} ${_name})
endfunction()
- #new_test(test_s2d_device)
+ new_test(test_s2d_device)
endif(NOT NO_TEST)
################################################################################
diff --git a/src/test_s2d_device.c b/src/test_s2d_device.c
@@ -0,0 +1,85 @@
+/* Copyright (C) |Meso|Star> 2016 (contact@meso-star.com)
+ *
+ * This software is governed by the CeCILL license under French law and
+ * abiding by the rules of distribution of free software. You can use,
+ * modify and/or redistribute the software under the terms of the CeCILL
+ * license as circulated by CEA, CNRS and INRIA at the following URL
+ * "http://www.cecill.info".
+ *
+ * As a counterpart to the access to the source code and rights to copy,
+ * modify and redistribute granted by the license, users are provided only
+ * with a limited warranty and the software's author, the holder of the
+ * economic rights, and the successive licensors have only limited
+ * liability.
+ *
+ * In this respect, the user's attention is drawn to the risks associated
+ * with loading, using, modifying and/or developing or reproducing the
+ * software by the user in light of its specific status of free software,
+ * that may mean that it is complicated to manipulate, and that also
+ * therefore means that it is reserved for developers and experienced
+ * professionals having in-depth computer knowledge. Users are therefore
+ * encouraged to load and test the software's suitability as regards their
+ * requirements in conditions enabling the security of their systems and/or
+ * data to be ensured and, more generally, to use and operate it in the
+ * same conditions as regards security.
+ *
+ * The fact that you are presently reading this means that you have had
+ * knowledge of the CeCILL license and that you accept its terms. */
+
+#include "s2d.h"
+#include "test_s2d_utils.h"
+#include <rsys/logger.h>
+
+static 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 s2d_device* dev;
+ (void)argc, (void)argv;
+
+ CHECK(s2d_device_create(NULL, NULL, 0, NULL), RES_BAD_ARG);
+ CHECK(s2d_device_create(NULL, NULL, 0, &dev), RES_OK);
+
+ CHECK(s2d_device_ref_get(NULL), RES_BAD_ARG);
+ CHECK(s2d_device_ref_get(dev), RES_OK);
+ CHECK(s2d_device_ref_put(NULL), RES_BAD_ARG);
+ CHECK(s2d_device_ref_put(dev), RES_OK);
+ CHECK(s2d_device_ref_put(dev), RES_OK);
+
+ mem_init_proxy_allocator(&allocator, &mem_default_allocator);
+
+ CHECK(MEM_ALLOCATED_SIZE(&allocator), 0);
+ CHECK(s2d_device_create(NULL, &allocator, 0, NULL), RES_BAD_ARG);
+ CHECK(s2d_device_create(NULL, &allocator, 0, &dev), RES_OK);
+ CHECK(s2d_device_ref_put(dev), RES_OK);
+ CHECK(MEM_ALLOCATED_SIZE(&allocator), 0);
+
+ CHECK(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);
+
+ CHECK(s2d_device_create(&logger, NULL, 0, NULL), RES_BAD_ARG);
+ CHECK(s2d_device_create(&logger, NULL, 0, &dev), RES_OK);
+ CHECK(s2d_device_ref_put(dev), RES_OK);
+
+ CHECK(s2d_device_create(&logger, &allocator, 0, NULL), RES_BAD_ARG);
+ CHECK(s2d_device_create(&logger, &allocator, 0, &dev), RES_OK);
+ CHECK(s2d_device_ref_put(dev), RES_OK);
+
+ logger_release(&logger);
+ check_memory_allocator(&allocator);
+ mem_shutdown_proxy_allocator(&allocator);
+ CHECK(mem_allocated_size(), 0);
+ return 0;
+}
+
diff --git a/src/test_s2d_utils.h b/src/test_s2d_utils.h
@@ -0,0 +1,47 @@
+/* Copyright (C) |Meso|Star> 2016 (contact@meso-star.com)
+ *
+ * This software is governed by the CeCILL license under French law and
+ * abiding by the rules of distribution of free software. You can use,
+ * modify and/or redistribute the software under the terms of the CeCILL
+ * license as circulated by CEA, CNRS and INRIA at the following URL
+ * "http://www.cecill.info".
+ *
+ * As a counterpart to the access to the source code and rights to copy,
+ * modify and redistribute granted by the license, users are provided only
+ * with a limited warranty and the software's author, the holder of the
+ * economic rights, and the successive licensors have only limited
+ * liability.
+ *
+ * In this respect, the user's attention is drawn to the risks associated
+ * with loading, using, modifying and/or developing or reproducing the
+ * software by the user in light of its specific status of free software,
+ * that may mean that it is complicated to manipulate, and that also
+ * therefore means that it is reserved for developers and experienced
+ * professionals having in-depth computer knowledge. Users are therefore
+ * encouraged to load and test the software's suitability as regards their
+ * requirements in conditions enabling the security of their systems and/or
+ * data to be ensured and, more generally, to use and operate it in the
+ * same conditions as regards security.
+ *
+ * The fact that you are presently reading this means that you have had
+ * knowledge of the CeCILL license and that you accept its terms. */
+
+#ifndef S2D_UTILS_H
+#define S2D_UTILS_H
+
+#include <rsys/mem_allocator.h>
+#include <stdio.h>
+
+static void
+check_memory_allocator(struct mem_allocator* allocator)
+{
+ if(MEM_ALLOCATED_SIZE(allocator)) {
+ char dump[512];
+ MEM_DUMP(allocator, dump, sizeof(dump)/sizeof(char));
+ fprintf(stderr, "%s\n", dump);
+ FATAL("Memory leaks\n");
+ }
+}
+
+#endif /* S2D_UTILS_H */
+