Migrate sha1 unit test to new framework (#470)
This migrates unit tests related to sha1 to new framework, ref: #428. --------- Signed-off-by: Shivshankar-Reddy <shiva.sheri.github@gmail.com> Signed-off-by: Madelyn Olson <madelyneolson@gmail.com> Co-authored-by: Madelyn Olson <madelyneolson@gmail.com>
This commit is contained in:
parent
138a7d9846
commit
e242799867
@ -6932,7 +6932,6 @@ struct serverTest {
|
||||
{"ziplist", ziplistTest},
|
||||
{"quicklist", quicklistTest},
|
||||
{"zipmap", zipmapTest},
|
||||
{"sha1test", sha1Test},
|
||||
{"endianconv", endianconvTest},
|
||||
{"zmalloc", zmalloc_test},
|
||||
{"dict", dictTest},
|
||||
|
30
src/sha1.c
30
src/sha1.c
@ -207,33 +207,3 @@ void SHA1Final(unsigned char digest[20], SHA1_CTX* context)
|
||||
memset(&finalcount, '\0', sizeof(finalcount));
|
||||
}
|
||||
/* ================ end of sha1.c ================ */
|
||||
|
||||
#ifdef SERVER_TEST
|
||||
#define BUFSIZE 4096
|
||||
|
||||
#define UNUSED(x) (void)(x)
|
||||
int sha1Test(int argc, char **argv, int flags)
|
||||
{
|
||||
SHA1_CTX ctx;
|
||||
unsigned char hash[20], buf[BUFSIZE];
|
||||
int i;
|
||||
|
||||
UNUSED(argc);
|
||||
UNUSED(argv);
|
||||
UNUSED(flags);
|
||||
|
||||
for(i=0;i<BUFSIZE;i++)
|
||||
buf[i] = i;
|
||||
|
||||
SHA1Init(&ctx);
|
||||
for(i=0;i<1000;i++)
|
||||
SHA1Update(&ctx, buf, BUFSIZE);
|
||||
SHA1Final(hash, &ctx);
|
||||
|
||||
printf("SHA1=");
|
||||
for(i=0;i<20;i++)
|
||||
printf("%02x", hash[i]);
|
||||
printf("\n");
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
@ -21,7 +21,4 @@ void SHA1Init(SHA1_CTX* context);
|
||||
__attribute__((noinline)) void SHA1Update(SHA1_CTX* context, const unsigned char* data, uint32_t len);
|
||||
void SHA1Final(unsigned char digest[20], SHA1_CTX* context);
|
||||
|
||||
#ifdef SERVER_TEST
|
||||
int sha1Test(int argc, char **argv, int flags);
|
||||
#endif
|
||||
#endif
|
||||
|
@ -22,6 +22,7 @@ int test_kvstoreIteratorRemoveAllKeysDeleteEmptyDict(int argc, char **argv, int
|
||||
int test_kvstoreDictIteratorRemoveAllKeysNoDeleteEmptyDict(int argc, char **argv, int flags);
|
||||
int test_kvstoreDictIteratorRemoveAllKeysDeleteEmptyDict(int argc, char **argv, int flags);
|
||||
int test_sds(int argc, char **argv, int flags);
|
||||
int test_sha1(int argc, char **argv, int flags);
|
||||
int test_string2ll(int argc, char **argv, int flags);
|
||||
int test_string2l(int argc, char **argv, int flags);
|
||||
int test_ll2string(int argc, char **argv, int flags);
|
||||
@ -34,6 +35,7 @@ unitTest __test_crc64combine_c[] = {{"test_crc64combine", test_crc64combine}, {N
|
||||
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}};
|
||||
unitTest __test_sha1_c[] = {{"test_sha1", test_sha1}, {NULL, NULL}};
|
||||
unitTest __test_util_c[] = {{"test_string2ll", test_string2ll}, {"test_string2l", test_string2l}, {"test_ll2string", test_ll2string}, {"test_ld2string", test_ld2string}, {"test_fixedpoint_d2string", test_fixedpoint_d2string}, {"test_reclaimFilePageCache", test_reclaimFilePageCache}, {NULL, NULL}};
|
||||
|
||||
struct unitTestSuite {
|
||||
@ -45,5 +47,6 @@ struct unitTestSuite {
|
||||
{"test_intset.c", __test_intset_c},
|
||||
{"test_kvstore.c", __test_kvstore_c},
|
||||
{"test_sds.c", __test_sds_c},
|
||||
{"test_sha1.c", __test_sha1_c},
|
||||
{"test_util.c", __test_util_c},
|
||||
};
|
||||
|
27
src/unit/test_sha1.c
Normal file
27
src/unit/test_sha1.c
Normal file
@ -0,0 +1,27 @@
|
||||
#include "../sha1.c"
|
||||
#include "test_help.h"
|
||||
|
||||
#define BUFSIZE 4096
|
||||
|
||||
int test_sha1(int argc, char **argv, int flags) {
|
||||
SHA1_CTX ctx;
|
||||
unsigned char hash[20], buf[BUFSIZE];
|
||||
unsigned char expected[20] = {0x15, 0xdd, 0x99, 0xa1, 0x99, 0x1e, 0x0b, 0x38,
|
||||
0x26, 0xfe, 0xde, 0x3d, 0xef, 0xfc, 0x1f, 0xeb, 0xa4, 0x22, 0x78, 0xe6};
|
||||
int i;
|
||||
|
||||
UNUSED(argc);
|
||||
UNUSED(argv);
|
||||
UNUSED(flags);
|
||||
|
||||
for(i=0;i<BUFSIZE;i++)
|
||||
buf[i] = i;
|
||||
|
||||
SHA1Init(&ctx);
|
||||
for(i=0;i<1000;i++)
|
||||
SHA1Update(&ctx, buf, BUFSIZE);
|
||||
SHA1Final(hash, &ctx);
|
||||
|
||||
TEST_ASSERT(memcmp(hash, expected, 20) == 0);
|
||||
return 0;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user