Normalize sds test mechanism together with some compile warnings. (#7854)
This commit is contained in:
parent
8aa083bd28
commit
c2e5546071
@ -362,10 +362,6 @@ lcov:
|
||||
@geninfo -o redis.info .
|
||||
@genhtml --legend -o lcov-html redis.info
|
||||
|
||||
test-sds: sds.c sds.h
|
||||
$(REDIS_CC) sds.c zmalloc.c -DSDS_TEST_MAIN $(FINAL_LIBS) -o /tmp/sds_test
|
||||
/tmp/sds_test
|
||||
|
||||
.PHONY: lcov
|
||||
|
||||
bench: $(REDIS_BENCHMARK_NAME)
|
||||
|
19
src/sds.c
19
src/sds.c
@ -1121,13 +1121,16 @@ void *sds_malloc(size_t size) { return s_malloc(size); }
|
||||
void *sds_realloc(void *ptr, size_t size) { return s_realloc(ptr,size); }
|
||||
void sds_free(void *ptr) { s_free(ptr); }
|
||||
|
||||
#if defined(SDS_TEST_MAIN)
|
||||
#ifdef REDIS_TEST
|
||||
#include <stdio.h>
|
||||
#include "testhelp.h"
|
||||
#include "limits.h"
|
||||
|
||||
#define UNUSED(x) (void)(x)
|
||||
int sdsTest(void) {
|
||||
int sdsTest(int argc, char **argv) {
|
||||
UNUSED(argc);
|
||||
UNUSED(argv);
|
||||
|
||||
{
|
||||
sds x = sdsnew("foo"), y;
|
||||
|
||||
@ -1254,7 +1257,8 @@ int sdsTest(void) {
|
||||
{
|
||||
unsigned int oldfree;
|
||||
char *p;
|
||||
int step = 10, j, i;
|
||||
int i;
|
||||
size_t step = 10, j;
|
||||
|
||||
sdsfree(x);
|
||||
sdsfree(y);
|
||||
@ -1264,7 +1268,7 @@ int sdsTest(void) {
|
||||
/* Run the test a few times in order to hit the first two
|
||||
* SDS header types. */
|
||||
for (i = 0; i < 10; i++) {
|
||||
int oldlen = sdslen(x);
|
||||
size_t oldlen = sdslen(x);
|
||||
x = sdsMakeRoomFor(x,step);
|
||||
int type = x[-1]&SDS_TYPE_MASK;
|
||||
|
||||
@ -1272,6 +1276,7 @@ int sdsTest(void) {
|
||||
if (type != SDS_TYPE_5) {
|
||||
test_cond("sdsMakeRoomFor() free", sdsavail(x) >= step);
|
||||
oldfree = sdsavail(x);
|
||||
UNUSED(oldfree);
|
||||
}
|
||||
p = x+oldlen;
|
||||
for (j = 0; j < step; j++) {
|
||||
@ -1290,9 +1295,3 @@ int sdsTest(void) {
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef SDS_TEST_MAIN
|
||||
int main(void) {
|
||||
return sdsTest();
|
||||
}
|
||||
#endif
|
||||
|
@ -5247,6 +5247,8 @@ int main(int argc, char **argv) {
|
||||
return crc64Test(argc, argv);
|
||||
} else if (!strcasecmp(argv[2], "zmalloc")) {
|
||||
return zmalloc_test(argc, argv);
|
||||
} else if (!strcasecmp(argv[2], "sds")) {
|
||||
return sdsTest(argc, argv);
|
||||
}
|
||||
|
||||
return -1; /* test not found */
|
||||
|
Loading…
x
Reference in New Issue
Block a user