Skip to content

Commit

Permalink
migrate sha1 test to test framework
Browse files Browse the repository at this point in the history
Signed-off-by: Shivshankar-Reddy <[email protected]>
  • Loading branch information
Shivshankar-Reddy committed May 8, 2024
1 parent 315b757 commit 9e13084
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 34 deletions.
32 changes: 1 addition & 31 deletions src/sha1.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,34 +206,4 @@ void SHA1Final(unsigned char digest[20], SHA1_CTX* context)
memset(context, '\0', sizeof(*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
/* ================ end of sha1.c ================ */
3 changes: 0 additions & 3 deletions src/sha1.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions src/unit/test_files.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ unitTest __test_crc64_c[] = {{"test_crc64", test_crc64}, {NULL, NULL}};
unitTest __test_crc64combine_c[] = {{"test_crc64combine", test_crc64combine}, {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_sha1_c[] = {{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 {
Expand All @@ -42,5 +43,6 @@ struct unitTestSuite {
{"test_crc64combine.c", __test_crc64combine_c},
{"test_intset.c", __test_intset_c},
{"test_kvstore.c", __test_kvstore_c},
{"test_sha1.c", __test_sha1_c},
{"test_util.c", __test_util_c},
};
29 changes: 29 additions & 0 deletions src/unit/test_sha1.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#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];
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;
}

0 comments on commit 9e13084

Please sign in to comment.