[Sound-open-firmware] [PATCH 3/3] test: unit tests for list.h Signed-off-by: Janusz Jankowski <janusz.jankowski at linux.intel.com>

Liam Girdwood liam.r.girdwood at linux.intel.com
Mon Jun 11 20:58:30 CEST 2018


From: Janusz Jankowski <janusz.jankowski at linux.intel.com>

---
 test/cmocka/Makefile.am                  |  23 +++
 test/cmocka/src/list/list_init.c         |  70 +++++++
 test/cmocka/src/list/list_is_empty.c     |  74 ++++++++
 test/cmocka/src/list/list_item.c         |  68 +++++++
 test/cmocka/src/list/list_item_append.c  | 148 +++++++++++++++
 test/cmocka/src/list/list_item_del.c     | 221 +++++++++++++++++++++++
 test/cmocka/src/list/list_item_is_last.c | 134 ++++++++++++++
 test/cmocka/src/list/list_item_prepend.c | 147 +++++++++++++++
 8 files changed, 885 insertions(+)
 create mode 100644 test/cmocka/src/list/list_init.c
 create mode 100644 test/cmocka/src/list/list_is_empty.c
 create mode 100644 test/cmocka/src/list/list_item.c
 create mode 100644 test/cmocka/src/list/list_item_append.c
 create mode 100644 test/cmocka/src/list/list_item_del.c
 create mode 100644 test/cmocka/src/list/list_item_is_last.c
 create mode 100644 test/cmocka/src/list/list_item_prepend.c

diff --git a/test/cmocka/Makefile.am b/test/cmocka/Makefile.am
index 97890e6..565fb80 100644
--- a/test/cmocka/Makefile.am
+++ b/test/cmocka/Makefile.am
@@ -21,6 +21,29 @@ LDFLAGS := $(filter-out -nostdlib,$(LDFLAGS))
 
 LDADD = -lcmocka
 
+# list tests
+
+check_PROGRAMS += list_init
+list_init_SOURCES = src/list/list_init.c
+
+check_PROGRAMS += list_is_empty
+list_is_empty_SOURCES = src/list/list_is_empty.c
+
+check_PROGRAMS += list_item_append
+list_item_append_SOURCES = src/list/list_item_append.c
+
+check_PROGRAMS += list_item_del
+list_item_del_SOURCES = src/list/list_item_del.c
+
+check_PROGRAMS += list_item_is_last
+list_item_is_last_SOURCES = src/list/list_item_is_last.c
+
+check_PROGRAMS += list_item_prepend
+list_item_prepend_SOURCES = src/list/list_item_prepend.c
+
+check_PROGRAMS += list_item
+list_item_SOURCES = src/list/list_item.c
+
 # math/numbers tests
 
 check_PROGRAMS += gcd
diff --git a/test/cmocka/src/list/list_init.c b/test/cmocka/src/list/list_init.c
new file mode 100644
index 0000000..5bd6f3e
--- /dev/null
+++ b/test/cmocka/src/list/list_init.c
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 2018, Intel Corporation
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *   * Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ *   * Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ *   * Neither the name of the Intel Corporation nor the
+ *     names of its contributors may be used to endorse or promote products
+ *     derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Author: Janusz Jankowski <janusz.jankowski at linux.intel.com>
+ */
+
+#include <sof/list.h>
+
+#include <stdarg.h>
+#include <stddef.h>
+#include <setjmp.h>
+#include <cmocka.h>
+
+static void test_list_list_init_prev_equal_to_root(void **state)
+{
+	(void) state; /* unused */
+
+	struct list_item list = {.prev = NULL, .next = NULL};
+
+	list_init(&list);
+
+	assert_ptr_equal(&list, list.prev);
+}
+
+static void test_list_list_init_next_equal_to_root(void **state)
+{
+	(void) state; /* unused */
+
+	struct list_item list = {.prev = NULL, .next = NULL};
+
+	list_init(&list);
+
+	assert_ptr_equal(&list, list.next);
+}
+
+int main(void)
+{
+	const struct CMUnitTest tests[] = {
+		cmocka_unit_test(test_list_list_init_prev_equal_to_root),
+		cmocka_unit_test(test_list_list_init_next_equal_to_root),
+	};
+
+	cmocka_set_message_output(CM_OUTPUT_TAP);
+
+	return cmocka_run_group_tests(tests, NULL, NULL);
+}
diff --git a/test/cmocka/src/list/list_is_empty.c b/test/cmocka/src/list/list_is_empty.c
new file mode 100644
index 0000000..95aff3e
--- /dev/null
+++ b/test/cmocka/src/list/list_is_empty.c
@@ -0,0 +1,74 @@
+/*
+ * Copyright (c) 2018, Intel Corporation
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *   * Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ *   * Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ *   * Neither the name of the Intel Corporation nor the
+ *     names of its contributors may be used to endorse or promote products
+ *     derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Author: Janusz Jankowski <janusz.jankowski at linux.intel.com>
+ */
+
+#include <sof/list.h>
+
+#include <stdlib.h>
+#include <stdarg.h>
+#include <stddef.h>
+#include <setjmp.h>
+#include <cmocka.h>
+
+static void test_list_list_is_empty_when_empty_then_true(void **state)
+{
+	(void) state; /* unused */
+
+	struct list_item list;
+
+	list_init(&list);
+
+	assert_true(list_is_empty(&list));
+}
+
+static void test_list_list_is_empty_when_not_empty_then_false(void **state)
+{
+	(void) state; /* unused */
+
+	struct list_item list, item;
+
+	list_init(&list);
+	list_init(&item);
+
+	list_item_append(&item, &list);
+
+	assert_false(list_is_empty(&list));
+}
+
+int main(void)
+{
+	const struct CMUnitTest tests[] = {
+		cmocka_unit_test(test_list_list_is_empty_when_empty_then_true),
+		cmocka_unit_test(test_list_list_is_empty_when_not_empty_then_false),
+	};
+
+	cmocka_set_message_output(CM_OUTPUT_TAP);
+
+	return cmocka_run_group_tests(tests, NULL, NULL);
+}
diff --git a/test/cmocka/src/list/list_item.c b/test/cmocka/src/list/list_item.c
new file mode 100644
index 0000000..5a62f24
--- /dev/null
+++ b/test/cmocka/src/list/list_item.c
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 2018, Intel Corporation
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *   * Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ *   * Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ *   * Neither the name of the Intel Corporation nor the
+ *     names of its contributors may be used to endorse or promote products
+ *     derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Author: Janusz Jankowski <janusz.jankowski at linux.intel.com>
+ */
+
+#include <sof/list.h>
+
+#include <stdlib.h>
+#include <stdarg.h>
+#include <stddef.h>
+#include <setjmp.h>
+#include <cmocka.h>
+
+struct test_list_container {
+	void *field1;
+	struct list_item list;
+	void *field2;
+};
+
+static void test_list_list_item_when_valid_offset_then_ptr_equal(void **state)
+{
+	(void) state; /* unused */
+
+	struct test_list_container container;
+
+	list_init(&(container.list));
+
+	struct test_list_container *result_container = list_item(
+			&(container.list), struct test_list_container, list);
+
+	assert_ptr_equal(result_container, &container);
+}
+
+int main(void)
+{
+	const struct CMUnitTest tests[] = {
+		cmocka_unit_test(test_list_list_item_when_valid_offset_then_ptr_equal),
+	};
+
+	cmocka_set_message_output(CM_OUTPUT_TAP);
+
+	return cmocka_run_group_tests(tests, NULL, NULL);
+}
diff --git a/test/cmocka/src/list/list_item_append.c b/test/cmocka/src/list/list_item_append.c
new file mode 100644
index 0000000..4fd4c66
--- /dev/null
+++ b/test/cmocka/src/list/list_item_append.c
@@ -0,0 +1,148 @@
+/*
+ * Copyright (c) 2018, Intel Corporation
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *   * Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ *   * Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ *   * Neither the name of the Intel Corporation nor the
+ *     names of its contributors may be used to endorse or promote products
+ *     derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Author: Janusz Jankowski <janusz.jankowski at linux.intel.com>
+ */
+
+#include <sof/list.h>
+
+#include <stdlib.h>
+#include <stdarg.h>
+#include <stddef.h>
+#include <setjmp.h>
+#include <cmocka.h>
+
+struct test_data {
+	struct list_item *head;
+	struct list_item *tail_minus_1;
+	struct list_item *tail;
+};
+
+static int setup(void **state)
+{
+	struct test_data *data = malloc(sizeof(struct test_data));
+
+	if (data == NULL)
+		return -1;
+
+	data->head = malloc(sizeof(struct list_item));
+	data->tail_minus_1 = malloc(sizeof(struct list_item));
+	data->tail = malloc(sizeof(struct list_item));
+
+	if (data->head == NULL
+			|| data->tail_minus_1 == NULL
+			|| data->tail == NULL) {
+		free(data->head);
+		free(data->tail_minus_1);
+		free(data->tail);
+
+		free(data);
+
+		return -1;
+	}
+
+	list_init(data->head);
+	list_init(data->tail_minus_1);
+	list_init(data->tail);
+
+	list_item_append(data->tail_minus_1, data->head);
+	list_item_append(data->tail, data->head);
+
+	*state = data;
+	return 0;
+}
+
+static int teardown(void **state)
+{
+	struct test_data *data = *state;
+
+	free(data->head);
+	free(data->tail_minus_1);
+	free(data->tail);
+
+	free(data);
+	return 0;
+}
+
+static void test_list_list_item_append_head_prev_is_tail(void **state)
+{
+	struct test_data *data = *state;
+
+	assert_ptr_equal(data->head->prev, data->tail);
+}
+
+static void test_list_list_item_append_head_next_is_tail_minus_1(void **state)
+{
+	struct test_data *data = *state;
+
+	assert_ptr_equal(data->head->next, data->tail_minus_1);
+}
+
+static void test_list_list_item_append_tail_minus_1_prev_is_head(void **state)
+{
+	struct test_data *data = *state;
+
+	assert_ptr_equal(data->tail_minus_1->prev, data->head);
+}
+
+static void test_list_list_item_append_tail_minus_1_next_is_tail(void **state)
+{
+	struct test_data *data = *state;
+
+	assert_ptr_equal(data->tail_minus_1->next, data->tail);
+}
+
+static void test_list_list_item_append_tail_prev_is_tail_minus_1(void **state)
+{
+	struct test_data *data = *state;
+
+	assert_ptr_equal(data->tail->prev, data->tail_minus_1);
+}
+
+static void test_list_list_item_append_tail_next_is_head(void **state)
+{
+	struct test_data *data = *state;
+
+	assert_ptr_equal(data->tail->next, data->head);
+}
+
+int main(void)
+{
+	const struct CMUnitTest tests[] = {
+		cmocka_unit_test(test_list_list_item_append_head_prev_is_tail),
+		cmocka_unit_test(test_list_list_item_append_head_next_is_tail_minus_1),
+		cmocka_unit_test(test_list_list_item_append_tail_minus_1_prev_is_head),
+		cmocka_unit_test(test_list_list_item_append_tail_minus_1_next_is_tail),
+		cmocka_unit_test(test_list_list_item_append_tail_prev_is_tail_minus_1),
+		cmocka_unit_test(test_list_list_item_append_tail_next_is_head),
+	};
+
+	cmocka_set_message_output(CM_OUTPUT_TAP);
+
+	return cmocka_run_group_tests(tests, setup, teardown);
+}
+
diff --git a/test/cmocka/src/list/list_item_del.c b/test/cmocka/src/list/list_item_del.c
new file mode 100644
index 0000000..dfe6e6d
--- /dev/null
+++ b/test/cmocka/src/list/list_item_del.c
@@ -0,0 +1,221 @@
+/*
+ * Copyright (c) 2018, Intel Corporation
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *   * Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ *   * Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ *   * Neither the name of the Intel Corporation nor the
+ *     names of its contributors may be used to endorse or promote products
+ *     derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Author: Janusz Jankowski <janusz.jankowski at linux.intel.com>
+ */
+
+#include <sof/list.h>
+
+#include <stdlib.h>
+#include <stdarg.h>
+#include <stddef.h>
+#include <setjmp.h>
+#include <cmocka.h>
+
+struct test_data {
+	struct list_item *head;
+	struct list_item *tail_minus_1;
+	struct list_item *tail;
+};
+
+static int setup(void **state)
+{
+	struct test_data *data = malloc(sizeof(struct test_data));
+
+	if (data == NULL)
+		return -1;
+
+	data->head = malloc(sizeof(struct list_item));
+	data->tail_minus_1 = malloc(sizeof(struct list_item));
+	data->tail = malloc(sizeof(struct list_item));
+
+	if (data->head == NULL
+			|| data->tail_minus_1 == NULL
+			|| data->tail == NULL) {
+		free(data->head);
+		free(data->tail_minus_1);
+		free(data->tail);
+
+		free(data);
+
+		return -1;
+	}
+
+	list_init(data->head);
+	list_init(data->tail_minus_1);
+	list_init(data->tail);
+
+	list_item_append(data->tail_minus_1, data->head);
+	list_item_append(data->tail, data->head);
+
+	*state = data;
+	return 0;
+}
+
+static int teardown(void **state)
+{
+	struct test_data *data = *state;
+
+	free(data->head);
+	free(data->tail_minus_1);
+	free(data->tail);
+
+	free(data);
+	return 0;
+}
+
+static void test_list_list_item_del_when_delete_head_then_tail_minus_1_prev_is_tail(void **state)
+{
+	struct test_data *data = *state;
+
+	list_item_del(data->head);
+
+	assert_ptr_equal(data->tail_minus_1->prev, data->tail);
+}
+
+static void test_list_list_item_del_when_delete_head_then_tail_minus_1_next_is_tail(void **state)
+{
+	struct test_data *data = *state;
+
+	list_item_del(data->head);
+
+	assert_ptr_equal(data->tail_minus_1->next, data->tail);
+}
+
+static void test_list_list_item_del_when_delete_head_then_tail_prev_is_tail_minus_1(void **state)
+{
+	struct test_data *data = *state;
+
+	list_item_del(data->head);
+
+	assert_ptr_equal(data->tail->prev, data->tail_minus_1);
+}
+
+static void test_list_list_item_del_when_delete_head_then_tail_next_is_tail_minus_1(void **state)
+{
+	struct test_data *data = *state;
+
+	list_item_del(data->head);
+
+	assert_ptr_equal(data->tail->next, data->tail_minus_1);
+}
+
+static void test_list_list_item_del_when_delete_tail_minus_1_then_head_prev_is_tail(void **state)
+{
+	struct test_data *data = *state;
+
+	list_item_del(data->tail_minus_1);
+
+	assert_ptr_equal(data->head->prev, data->tail);
+}
+
+static void test_list_list_item_del_when_delete_tail_minus_1_then_head_next_is_tail(void **state)
+{
+	struct test_data *data = *state;
+
+	list_item_del(data->tail_minus_1);
+
+	assert_ptr_equal(data->head->next, data->tail);
+}
+
+static void test_list_list_item_del_when_delete_tail_minus_1_then_tail_prev_is_head(void **state)
+{
+	struct test_data *data = *state;
+
+	list_item_del(data->tail_minus_1);
+
+	assert_ptr_equal(data->tail->prev, data->head);
+}
+
+static void test_list_list_item_del_when_delete_tail_minus_1_then_tail_next_is_head(void **state)
+{
+	struct test_data *data = *state;
+
+	list_item_del(data->tail_minus_1);
+
+	assert_ptr_equal(data->tail->next, data->head);
+}
+
+static void test_list_list_item_del_when_delete_tail_then_head_prev_is_tail_minus_1(void **state)
+{
+	struct test_data *data = *state;
+
+	list_item_del(data->tail);
+
+	assert_ptr_equal(data->head->prev, data->tail_minus_1);
+}
+
+static void test_list_list_item_del_when_delete_tail_then_head_next_is_tail_minus_1(void **state)
+{
+	struct test_data *data = *state;
+
+	list_item_del(data->tail);
+
+	assert_ptr_equal(data->head->next, data->tail_minus_1);
+}
+
+static void test_list_list_item_del_when_delete_tail_then_tail_minus_1_prev_is_head(void **state)
+{
+	struct test_data *data = *state;
+
+	list_item_del(data->tail);
+
+	assert_ptr_equal(data->tail_minus_1->prev, data->head);
+}
+
+static void test_list_list_item_del_when_delete_tail_then_tail_minus_1_next_is_head(void **state)
+{
+	struct test_data *data = *state;
+
+	list_item_del(data->tail);
+
+	assert_ptr_equal(data->tail_minus_1->next, data->head);
+}
+
+int main(void)
+{
+	const struct CMUnitTest tests[] = {
+		cmocka_unit_test_setup_teardown(test_list_list_item_del_when_delete_head_then_tail_minus_1_prev_is_tail, setup, teardown),
+		cmocka_unit_test_setup_teardown(test_list_list_item_del_when_delete_head_then_tail_minus_1_next_is_tail, setup, teardown),
+		cmocka_unit_test_setup_teardown(test_list_list_item_del_when_delete_head_then_tail_prev_is_tail_minus_1, setup, teardown),
+		cmocka_unit_test_setup_teardown(test_list_list_item_del_when_delete_head_then_tail_next_is_tail_minus_1, setup, teardown),
+
+		cmocka_unit_test_setup_teardown(test_list_list_item_del_when_delete_tail_minus_1_then_head_prev_is_tail, setup, teardown),
+		cmocka_unit_test_setup_teardown(test_list_list_item_del_when_delete_tail_minus_1_then_head_next_is_tail, setup, teardown),
+		cmocka_unit_test_setup_teardown(test_list_list_item_del_when_delete_tail_minus_1_then_tail_prev_is_head, setup, teardown),
+		cmocka_unit_test_setup_teardown(test_list_list_item_del_when_delete_tail_minus_1_then_tail_next_is_head, setup, teardown),
+
+		cmocka_unit_test_setup_teardown(test_list_list_item_del_when_delete_tail_then_head_prev_is_tail_minus_1, setup, teardown),
+		cmocka_unit_test_setup_teardown(test_list_list_item_del_when_delete_tail_then_head_next_is_tail_minus_1, setup, teardown),
+		cmocka_unit_test_setup_teardown(test_list_list_item_del_when_delete_tail_then_tail_minus_1_prev_is_head, setup, teardown),
+		cmocka_unit_test_setup_teardown(test_list_list_item_del_when_delete_tail_then_tail_minus_1_next_is_head, setup, teardown),
+	};
+
+	cmocka_set_message_output(CM_OUTPUT_TAP);
+
+	return cmocka_run_group_tests(tests, NULL, NULL);
+}
diff --git a/test/cmocka/src/list/list_item_is_last.c b/test/cmocka/src/list/list_item_is_last.c
new file mode 100644
index 0000000..2e6bd0f
--- /dev/null
+++ b/test/cmocka/src/list/list_item_is_last.c
@@ -0,0 +1,134 @@
+/*
+ * Copyright (c) 2018, Intel Corporation
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *   * Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ *   * Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ *   * Neither the name of the Intel Corporation nor the
+ *     names of its contributors may be used to endorse or promote products
+ *     derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Author: Janusz Jankowski <janusz.jankowski at linux.intel.com>
+ */
+
+#include <sof/list.h>
+
+#include <stdlib.h>
+#include <stdarg.h>
+#include <stddef.h>
+#include <setjmp.h>
+#include <cmocka.h>
+
+struct test_data {
+	struct list_item *head;
+	struct list_item *tail_minus_1;
+	struct list_item *tail;
+};
+
+static int setup(void **state)
+{
+	struct test_data *data = malloc(sizeof(struct test_data));
+
+	if (data == NULL)
+		return -1;
+
+	data->head = malloc(sizeof(struct list_item));
+	data->tail_minus_1 = malloc(sizeof(struct list_item));
+	data->tail = malloc(sizeof(struct list_item));
+
+	if (data->head == NULL
+			|| data->tail_minus_1 == NULL
+			|| data->tail == NULL) {
+		free(data->head);
+		free(data->tail_minus_1);
+		free(data->tail);
+
+		free(data);
+
+		return -1;
+	}
+
+	list_init(data->head);
+	list_init(data->tail_minus_1);
+	list_init(data->tail);
+
+	list_item_append(data->tail_minus_1, data->head);
+	list_item_append(data->tail, data->head);
+
+	*state = data;
+	return 0;
+}
+
+static int teardown(void **state)
+{
+	struct test_data *data = *state;
+
+	free(data->head);
+	free(data->tail_minus_1);
+	free(data->tail);
+
+	free(data);
+	return 0;
+}
+
+static void test_list_list_item_is_last_when_head_then_false(void **state)
+{
+	struct test_data *data = *state;
+
+	assert_false(list_item_is_last(data->head, data->head));
+}
+
+static void test_list_list_item_is_last_when_tail_minus_1_then_false(void **state)
+{
+	struct test_data *data = *state;
+
+	assert_false(list_item_is_last(data->tail_minus_1, data->head));
+}
+
+static void test_list_list_item_is_last_when_tail_then_true(void **state)
+{
+	struct test_data *data = *state;
+
+	assert_true(list_item_is_last(data->tail, data->head));
+}
+
+static void test_list_list_item_is_last_when_not_in_list_then_false(void **state)
+{
+	struct list_item other_list;
+	struct test_data *data = *state;
+
+	list_init(&other_list);
+
+	assert_false(list_item_is_last(&other_list, data->head));
+}
+
+int main(void)
+{
+	const struct CMUnitTest tests[] = {
+		cmocka_unit_test(test_list_list_item_is_last_when_head_then_false),
+		cmocka_unit_test(test_list_list_item_is_last_when_tail_minus_1_then_false),
+		cmocka_unit_test(test_list_list_item_is_last_when_tail_then_true),
+		cmocka_unit_test(test_list_list_item_is_last_when_not_in_list_then_false),
+	};
+
+	cmocka_set_message_output(CM_OUTPUT_TAP);
+
+	return cmocka_run_group_tests(tests, setup, teardown);
+}
diff --git a/test/cmocka/src/list/list_item_prepend.c b/test/cmocka/src/list/list_item_prepend.c
new file mode 100644
index 0000000..75c1e76
--- /dev/null
+++ b/test/cmocka/src/list/list_item_prepend.c
@@ -0,0 +1,147 @@
+/*
+ * Copyright (c) 2018, Intel Corporation
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *   * Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ *   * Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ *   * Neither the name of the Intel Corporation nor the
+ *     names of its contributors may be used to endorse or promote products
+ *     derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ * Author: Janusz Jankowski <janusz.jankowski at linux.intel.com>
+ */
+
+#include <sof/list.h>
+
+#include <stdlib.h>
+#include <stdarg.h>
+#include <stddef.h>
+#include <setjmp.h>
+#include <cmocka.h>
+
+struct test_data {
+	struct list_item *head;
+	struct list_item *tail_minus_1;
+	struct list_item *tail;
+};
+
+static int setup(void **state)
+{
+	struct test_data *data = malloc(sizeof(struct test_data));
+
+	if (data == NULL)
+		return -1;
+
+	data->head = malloc(sizeof(struct list_item));
+	data->tail_minus_1 = malloc(sizeof(struct list_item));
+	data->tail = malloc(sizeof(struct list_item));
+
+	if (data->head == NULL
+			|| data->tail_minus_1 == NULL
+			|| data->tail == NULL) {
+		free(data->head);
+		free(data->tail_minus_1);
+		free(data->tail);
+
+		free(data);
+
+		return -1;
+	}
+
+	list_init(data->head);
+	list_init(data->tail_minus_1);
+	list_init(data->tail);
+
+	list_item_prepend(data->tail, data->head);
+	list_item_prepend(data->tail_minus_1, data->head);
+
+	*state = data;
+	return 0;
+}
+
+static int teardown(void **state)
+{
+	struct test_data *data = *state;
+
+	free(data->head);
+	free(data->tail_minus_1);
+	free(data->tail);
+
+	free(data);
+	return 0;
+}
+
+static void test_list_list_item_prepend_head_prev_is_tail(void **state)
+{
+	struct test_data *data = *state;
+
+	assert_ptr_equal(data->head->prev, data->tail);
+}
+
+static void test_list_list_item_prepend_head_next_is_tail_minus_1(void **state)
+{
+	struct test_data *data = *state;
+
+	assert_ptr_equal(data->head->next, data->tail_minus_1);
+}
+
+static void test_list_list_item_prepend_tail_minus_1_prev_is_head(void **state)
+{
+	struct test_data *data = *state;
+
+	assert_ptr_equal(data->tail_minus_1->prev, data->head);
+}
+
+static void test_list_list_item_prepend_tail_minus_1_next_is_tail(void **state)
+{
+	struct test_data *data = *state;
+
+	assert_ptr_equal(data->tail_minus_1->next, data->tail);
+}
+
+static void test_list_list_item_prepend_tail_prev_is_tail_minus_1(void **state)
+{
+	struct test_data *data = *state;
+
+	assert_ptr_equal(data->tail->prev, data->tail_minus_1);
+}
+
+static void test_list_list_item_prepend_tail_next_is_head(void **state)
+{
+	struct test_data *data = *state;
+
+	assert_ptr_equal(data->tail->next, data->head);
+}
+
+int main(void)
+{
+	const struct CMUnitTest tests[] = {
+		cmocka_unit_test(test_list_list_item_prepend_head_prev_is_tail),
+		cmocka_unit_test(test_list_list_item_prepend_head_next_is_tail_minus_1),
+		cmocka_unit_test(test_list_list_item_prepend_tail_minus_1_prev_is_head),
+		cmocka_unit_test(test_list_list_item_prepend_tail_minus_1_next_is_tail),
+		cmocka_unit_test(test_list_list_item_prepend_tail_prev_is_tail_minus_1),
+		cmocka_unit_test(test_list_list_item_prepend_tail_next_is_head),
+	};
+
+	cmocka_set_message_output(CM_OUTPUT_TAP);
+
+	return cmocka_run_group_tests(tests, setup, teardown);
+}
-- 
2.17.0



More information about the Sound-open-firmware mailing list