From 8bd9047c6e76bad8f862c0a332d582c51da52322 Mon Sep 17 00:00:00 2001 From: Karthick Ariyaratnam Date: Sun, 12 May 2024 19:58:50 -0400 Subject: [PATCH] Migrate endianconv.c unit tests to new test framework (#458) This PR migrates all tests related to endianconv into new test framework as part of the parent issue https://github.com/valkey-io/valkey/issues/428. --------- Signed-off-by: Karthick Ariyaratnam Signed-off-by: Madelyn Olson Co-authored-by: Madelyn Olson Signed-off-by: adetunjii --- src/endianconv.c | 27 --------------------------- src/endianconv.h | 5 ----- src/unit/test_endianconv.c | 26 ++++++++++++++++++++++++++ src/unit/test_files.h | 3 +++ 4 files changed, 29 insertions(+), 32 deletions(-) create mode 100644 src/unit/test_endianconv.c diff --git a/src/endianconv.c b/src/endianconv.c index 212bdcb522..de91671565 100644 --- a/src/endianconv.c +++ b/src/endianconv.c @@ -100,30 +100,3 @@ uint64_t intrev64(uint64_t v) { memrev64(&v); return v; } - -#ifdef SERVER_TEST -#include - -#define UNUSED(x) (void)(x) -int endianconvTest(int argc, char *argv[], int flags) { - char buf[32]; - - UNUSED(argc); - UNUSED(argv); - UNUSED(flags); - - snprintf(buf,sizeof(buf),"ciaoroma"); - memrev16(buf); - printf("%s\n", buf); - - snprintf(buf,sizeof(buf),"ciaoroma"); - memrev32(buf); - printf("%s\n", buf); - - snprintf(buf,sizeof(buf),"ciaoroma"); - memrev64(buf); - printf("%s\n", buf); - - return 0; -} -#endif diff --git a/src/endianconv.h b/src/endianconv.h index 0a7ad2a12d..062c3f2f53 100644 --- a/src/endianconv.h +++ b/src/endianconv.h @@ -70,9 +70,4 @@ uint64_t intrev64(uint64_t v); #define htonu64(v) intrev64(v) #define ntohu64(v) intrev64(v) #endif - -#ifdef SERVER_TEST -int endianconvTest(int argc, char *argv[], int flags); -#endif - #endif diff --git a/src/unit/test_endianconv.c b/src/unit/test_endianconv.c new file mode 100644 index 0000000000..c7b683f5de --- /dev/null +++ b/src/unit/test_endianconv.c @@ -0,0 +1,26 @@ +#include + +#include "../endianconv.h" +#include "test_help.h" + +int test_endianconv(int argc, char *argv[], int flags) { + UNUSED(argc); + UNUSED(argv); + UNUSED(flags); + + char buf[32]; + + snprintf(buf,sizeof(buf),"ciaoroma"); + memrev16(buf); + TEST_ASSERT(!strcmp(buf, "icaoroma")); + + snprintf(buf,sizeof(buf),"ciaoroma"); + memrev32(buf); + TEST_ASSERT(!strcmp(buf, "oaicroma")); + + snprintf(buf,sizeof(buf),"ciaoroma"); + memrev64(buf); + TEST_ASSERT(!strcmp(buf, "amoroaic")); + + return 0; +} diff --git a/src/unit/test_files.h b/src/unit/test_files.h index 1127efd5aa..40361454e9 100644 --- a/src/unit/test_files.h +++ b/src/unit/test_files.h @@ -8,6 +8,7 @@ typedef struct unitTest { int test_crc64(int argc, char **argv, int flags); int test_crc64combine(int argc, char **argv, int flags); +int test_endianconv(int argc, char *argv[], int flags); int test_intsetValueEncodings(int argc, char **argv, int flags); int test_intsetBasicAdding(int argc, char **argv, int flags); int test_intsetLargeNumberRandomAdd(int argc, char **argv, int flags); @@ -32,6 +33,7 @@ int test_reclaimFilePageCache(int argc, char **argv, int flags); unitTest __test_crc64_c[] = {{"test_crc64", test_crc64}, {NULL, NULL}}; unitTest __test_crc64combine_c[] = {{"test_crc64combine", test_crc64combine}, {NULL, NULL}}; +unitTest __test_endianconv_c[] = {{"test_endianconv", test_endianconv}, {NULL, NULL}}; unitTest __test_intset_c[] = {{"test_intsetValueEncodings", test_intsetValueEncodings}, {"test_intsetBasicAdding", test_intsetBasicAdding}, {"test_intsetLargeNumberRandomAdd", test_intsetLargeNumberRandomAdd}, {"test_intsetUpgradeFromint16Toint32", test_intsetUpgradeFromint16Toint32}, {"test_intsetUpgradeFromint16Toint64", test_intsetUpgradeFromint16Toint64}, {"test_intsetUpgradeFromint32Toint64", test_intsetUpgradeFromint32Toint64}, {"test_intsetStressLookups", test_intsetStressLookups}, {"test_intsetStressAddDelete", test_intsetStressAddDelete}, {NULL, NULL}}; unitTest __test_kvstore_c[] = {{"test_kvstoreAdd16Keys", test_kvstoreAdd16Keys}, {"test_kvstoreIteratorRemoveAllKeysNoDeleteEmptyDict", test_kvstoreIteratorRemoveAllKeysNoDeleteEmptyDict}, {"test_kvstoreIteratorRemoveAllKeysDeleteEmptyDict", test_kvstoreIteratorRemoveAllKeysDeleteEmptyDict}, {"test_kvstoreDictIteratorRemoveAllKeysNoDeleteEmptyDict", test_kvstoreDictIteratorRemoveAllKeysNoDeleteEmptyDict}, {"test_kvstoreDictIteratorRemoveAllKeysDeleteEmptyDict", test_kvstoreDictIteratorRemoveAllKeysDeleteEmptyDict}, {NULL, NULL}}; unitTest __test_sds_c[] = {{"test_sds", test_sds}, {NULL, NULL}}; @@ -44,6 +46,7 @@ struct unitTestSuite { } unitTestSuite[] = { {"test_crc64.c", __test_crc64_c}, {"test_crc64combine.c", __test_crc64combine_c}, + {"test_endianconv.c", __test_endianconv_c}, {"test_intset.c", __test_intset_c}, {"test_kvstore.c", __test_kvstore_c}, {"test_sds.c", __test_sds_c},