Skip to content

Commit

Permalink
Migrate endianconv.c unit tests to new test framework (#458)
Browse files Browse the repository at this point in the history
This PR migrates all tests related to endianconv into new test framework
as part of the parent issue #428.

---------

Signed-off-by: Karthick Ariyaratnam <karthyuom@gmail.com>
Signed-off-by: Madelyn Olson <madelyneolson@gmail.com>
Co-authored-by: Madelyn Olson <madelyneolson@gmail.com>
  • Loading branch information
karthyuom and madolson committed May 12, 2024
1 parent dca1722 commit c7ad9fe
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 32 deletions.
27 changes: 0 additions & 27 deletions src/endianconv.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,30 +100,3 @@ uint64_t intrev64(uint64_t v) {
memrev64(&v);
return v;
}

#ifdef SERVER_TEST
#include <stdio.h>

#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
5 changes: 0 additions & 5 deletions src/endianconv.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
26 changes: 26 additions & 0 deletions src/unit/test_endianconv.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <string.h>

#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;
}
3 changes: 3 additions & 0 deletions src/unit/test_files.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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}};
Expand All @@ -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},
Expand Down

0 comments on commit c7ad9fe

Please sign in to comment.