Testing memcmp and memcpy from TF-A libc
Removing previously used c-picker based tests and fully testing memcmp
and memcpy functions from the TF-A libc by linking them directly to the
test binary.
Change-Id: Ic343094603a563beda43ccda737d0e6f89f254e4
Signed-off-by: Imre Kis <imre.kis@arm.com>
diff --git a/tests/lib/libc/memcmp.yml b/tests/lib/libc/memcmp.yml
deleted file mode 100644
index ce76156..0000000
--- a/tests/lib/libc/memcmp.yml
+++ /dev/null
@@ -1,12 +0,0 @@
-#
-# Copyright (c) 2019, Arm Limited. All rights reserved.
-#
-# SPDX-License-Identifier: BSD-3-Clause
-#
-
-elements:
-- file: lib/libc/memcmp.c
- type: include
-- file: lib/libc/memcmp.c
- type: function
- name: memcmp
diff --git a/tests/lib/libc/memcpy.yml b/tests/lib/libc/memcpy.yml
deleted file mode 100644
index f03c736..0000000
--- a/tests/lib/libc/memcpy.yml
+++ /dev/null
@@ -1,12 +0,0 @@
-#
-# Copyright (c) 2019, Arm Limited. All rights reserved.
-#
-# SPDX-License-Identifier: BSD-3-Clause
-#
-
-elements:
-- file: lib/libc/memcpy.c
- type: include
-- file: lib/libc/memcpy.c
- type: function
- name: memcpy
diff --git a/tests/lib/libc/test_libc.cmake b/tests/lib/libc/test_libc.cmake
index 8feee29..88a7712 100644
--- a/tests/lib/libc/test_libc.cmake
+++ b/tests/lib/libc/test_libc.cmake
@@ -1,5 +1,5 @@
#
-# Copyright (c) 2019, Arm Limited. All rights reserved.
+# Copyright (c) 2019-2020, Arm Limited. All rights reserved.
#
# SPDX-License-Identifier: BSD-3-Clause
#
@@ -9,8 +9,8 @@
unit_test_add_suite(
NAME memcmp
SOURCES
+ ${TF_A_PATH}/lib/libc/memcmp.c
${CMAKE_CURRENT_LIST_DIR}/test_memcmp.cpp
- ${CMAKE_CURRENT_LIST_DIR}/memcmp.yml
INCLUDE_DIRECTORIES
${TF_A_PATH}/include
${TF_A_PATH}/include/lib/libc/aarch64/
@@ -19,8 +19,8 @@
unit_test_add_suite(
NAME memcpy
SOURCES
+ ${TF_A_PATH}/lib/libc/memcpy.c
${CMAKE_CURRENT_LIST_DIR}/test_memcpy.cpp
- ${CMAKE_CURRENT_LIST_DIR}/memcpy.yml
INCLUDE_DIRECTORIES
${TF_A_PATH}/include
${TF_A_PATH}/include/lib/libc/aarch64/
diff --git a/tests/lib/libc/test_memcmp.cpp b/tests/lib/libc/test_memcmp.cpp
index b4eb293..c644bec 100644
--- a/tests/lib/libc/test_memcmp.cpp
+++ b/tests/lib/libc/test_memcmp.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2019, Arm Limited. All rights reserved.
+ * Copyright (c) 2019-2020, Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
@@ -9,10 +9,54 @@
#include "lib/libc/string.h"
}
-TEST_GROUP(memcmp) {
+#define BUFFER_SIZE (16)
+TEST_GROUP(memcmp) {
+ TEST_SETUP() {
+ for (int i = 0; i < BUFFER_SIZE; i++) {
+ buffer1[i] = 0;
+ buffer2[i] = 0;
+ }
+ }
+
+ uint8_t buffer1[BUFFER_SIZE];
+ uint8_t buffer2[BUFFER_SIZE];
};
-TEST(memcmp, empty) {
- LONGS_EQUAL(0, memcmp(NULL, NULL, 0))
+TEST(memcmp, zero_length) {
+ LONGS_EQUAL(0, memcmp(buffer1, buffer2, 0));
+}
+
+TEST(memcmp, same) {
+ LONGS_EQUAL(0, memcmp(buffer1, buffer2, sizeof(buffer1)));
+}
+
+TEST(memcmp, first_diff_positive) {
+ buffer1[0] = 1;
+ LONGS_EQUAL(1, memcmp(buffer1, buffer2, sizeof(buffer1)));
+}
+
+TEST(memcmp, first_diff_negative) {
+ buffer2[0] = 1;
+ LONGS_EQUAL(-1, memcmp(buffer1, buffer2, sizeof(buffer1)));
+}
+
+TEST(memcmp, second_diff_positive) {
+ buffer1[1] = 1;
+ LONGS_EQUAL(1, memcmp(buffer1, buffer2, sizeof(buffer1)));
+}
+
+TEST(memcmp, second_diff_negative) {
+ buffer2[1] = 1;
+ LONGS_EQUAL(-1, memcmp(buffer1, buffer2, sizeof(buffer1)));
+}
+
+TEST(memcmp, last_diff_positive) {
+ buffer1[sizeof(buffer1) - 1] = 1;
+ LONGS_EQUAL(1, memcmp(buffer1, buffer2, sizeof(buffer1)));
+}
+
+TEST(memcmp, last_diff_negative) {
+ buffer2[sizeof(buffer2) - 1] = 1;
+ LONGS_EQUAL(-1, memcmp(buffer1, buffer2, sizeof(buffer1)));
}
diff --git a/tests/lib/libc/test_memcpy.cpp b/tests/lib/libc/test_memcpy.cpp
index 64f02c2..3e436ef 100644
--- a/tests/lib/libc/test_memcpy.cpp
+++ b/tests/lib/libc/test_memcpy.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2019, Arm Limited. All rights reserved.
+ * Copyright (c) 2019-2020, Arm Limited. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
@@ -9,10 +9,26 @@
#include "lib/libc/string.h"
}
-TEST_GROUP(memcpy) {
+#define BUFFER_SIZE (16)
+TEST_GROUP(memcpy) {
+ TEST_SETUP() {
+ for (int i = 0; i < BUFFER_SIZE; i++) {
+ dst[i] = 0;
+ src[i] = 0;
+ }
+ }
+
+ uint8_t dst[BUFFER_SIZE];
+ uint8_t src[BUFFER_SIZE];
};
-TEST(memcpy, empty) {
- LONGS_EQUAL(0, memcpy(NULL, NULL, 0))
+TEST(memcpy, zero_length) {
+ POINTERS_EQUAL(dst, memcpy(dst, src, 0));
+ MEMCMP_EQUAL(src, dst, sizeof(dst));
+}
+
+TEST(memcpy, copy_all) {
+ POINTERS_EQUAL(dst, memcpy(dst, src, sizeof(dst)));
+ MEMCMP_EQUAL(src, dst, sizeof(dst));
}