Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate zmalloc.c unit tests to new test framework #459

Closed
wants to merge 31 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
37bf386
Migrate zmalloc unit tests to new test framework.
karthyuom May 7, 2024
6e4aabe
Don't try to set SO_REUSEADDR on sockets of AF_UNIX (#451)
panjf2000 May 7, 2024
e4f5705
Fix CI test failure.
karthyuom May 7, 2024
cee504a
Fix CI test failure.
karthyuom May 7, 2024
c33f89b
Migrate util.c unit tests to new test framework (#448)
karthyuom May 7, 2024
9894f5c
Update module api and variable to valkey accordingly. (#455)
Shivshankar-Reddy May 7, 2024
a099e04
Migrate kvstore.c unit tests to new test framework. (#446)
karthyuom May 7, 2024
5ca1a7a
Update server function's name to valkey (#456)
Shivshankar-Reddy May 8, 2024
3ee3a00
Fix build error for unit test (#473)
Shivshankar-Reddy May 8, 2024
1ecc097
Prevent clang-format in certain places (#468)
zuiderkwast May 8, 2024
b1dda94
Update serverpanic output based on 'extended-redis-compatibility' con…
Shivshankar-Reddy May 8, 2024
db31d8b
Remove intsettest declaration from intset.h (#471)
Shivshankar-Reddy May 8, 2024
02a0e49
Migrate cluster mode tests to normal framework (#442)
enjoy-binbin May 9, 2024
76b371f
Try fix CI failure.
karthyuom May 9, 2024
7fa8719
Fix UNUSED repetition issue in test sources (#475)
karthyuom May 9, 2024
94e44cd
[FIX] Remove redundant statement and return (#481)
arthurkiller May 9, 2024
d4196ee
[Fix] move deps from slowlog.c into slowlog.h (#465)
arthurkiller May 9, 2024
66620e4
Migrate sds.c unit tests to new test framework. (#478)
lipzhu May 9, 2024
bd134cf
Support pipe2() on *BSD (#462)
panjf2000 May 10, 2024
ca9db22
Handle role change error in `cluster setslot` when migrating the las…
PingXie May 10, 2024
b62b7c3
Migrate sha1 unit test to new framework (#470)
Shivshankar-Reddy May 10, 2024
e96d309
Try resolve conflict, add zmalloc_test.
karthyuom May 10, 2024
898cc63
Update src/unit/test_zmalloc.c
karthyuom May 13, 2024
b40a36d
Update src/unit/test_zmalloc.c
karthyuom May 13, 2024
aa39f3c
Update src/unit/test_zmalloc.c
karthyuom May 13, 2024
e466a31
Update src/unit/test_zmalloc.c
karthyuom May 13, 2024
5915107
Update src/unit/test_zmalloc.c
karthyuom May 13, 2024
d9960e4
Update src/unit/test_zmalloc.c
karthyuom May 13, 2024
5ca555b
Update src/unit/test_zmalloc.c
karthyuom May 13, 2024
7c69aa0
Update src/unit/test_zmalloc.c
karthyuom May 13, 2024
9860bd0
Remove PREFIX_SIZE debug print.
karthyuom May 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/.clang-format-ignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Don't format files copied from other sources.
lzf*
crccombine.*
crcspeed.*
mt19937-64.*
pqsort.*
setcpuaffinity.c
setproctitle.c
sha1.*
sha256.*
siphash.c
strl.c
2 changes: 1 addition & 1 deletion src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ $(ENGINE_LIB_NAME): $(ENGINE_SERVER_OBJ)

# valkey-unit-tests
$(ENGINE_UNIT_TESTS): $(ENGINE_TEST_OBJ) $(ENGINE_LIB_NAME)
$(SERVER_LD) $(ALLOW_DUPLICATE_FLAG) -o $@ $^ ../deps/fpconv/libfpconv.a $(FINAL_LIBS)
$(SERVER_LD) $(ALLOW_DUPLICATE_FLAG) -o $@ $^ ../deps/hiredis/libhiredis.a ../deps/lua/src/liblua.a ../deps/hdr_histogram/libhdrhistogram.a ../deps/fpconv/libfpconv.a $(FINAL_LIBS)

# valkey-sentinel
$(ENGINE_SENTINEL_NAME): $(SERVER_NAME)
Expand Down
24 changes: 18 additions & 6 deletions src/acl.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ user *DefaultUser; /* Global reference to the default user.
different user. */

list *UsersToLoad; /* This is a list of users found in the configuration file
that we'll need to load in the final stage of Redis
that we'll need to load in the final stage of the server
initialization, after all the modules are already
loaded. Every list element is a NULL terminated
array of SDS pointers: the first is the user name,
Expand Down Expand Up @@ -1601,10 +1601,12 @@ static int ACLSelectorCheckKey(aclSelector *selector, const char *key, int keyle
listRewind(selector->patterns,&li);

int key_flags = 0;
/* clang-format off */
if (keyspec_flags & CMD_KEY_ACCESS) key_flags |= ACL_READ_PERMISSION;
if (keyspec_flags & CMD_KEY_INSERT) key_flags |= ACL_WRITE_PERMISSION;
if (keyspec_flags & CMD_KEY_DELETE) key_flags |= ACL_WRITE_PERMISSION;
if (keyspec_flags & CMD_KEY_UPDATE) key_flags |= ACL_WRITE_PERMISSION;
/* clang-format on */

/* Test this key against every pattern. */
while((ln = listNext(&li))) {
Expand Down Expand Up @@ -1632,10 +1634,12 @@ static int ACLSelectorHasUnrestrictedKeyAccess(aclSelector *selector, int flags)
listRewind(selector->patterns,&li);

int access_flags = 0;
/* clang-format off */
if (flags & CMD_KEY_ACCESS) access_flags |= ACL_READ_PERMISSION;
if (flags & CMD_KEY_INSERT) access_flags |= ACL_WRITE_PERMISSION;
if (flags & CMD_KEY_DELETE) access_flags |= ACL_WRITE_PERMISSION;
if (flags & CMD_KEY_UPDATE) access_flags |= ACL_WRITE_PERMISSION;
/* clang-format on */

/* Test this key against every pattern. */
while((ln = listNext(&li))) {
Expand Down Expand Up @@ -2700,13 +2704,15 @@ void addACLLogEntry(client *c, int reason, int context, int argpos, sds username
if (object) {
le->object = object;
} else {
/* clang-format off */
switch(reason) {
case ACL_DENIED_CMD: le->object = sdsdup(c->cmd->fullname); break;
case ACL_DENIED_KEY: le->object = sdsdup(c->argv[argpos]->ptr); break;
case ACL_DENIED_CHANNEL: le->object = sdsdup(c->argv[argpos]->ptr); break;
case ACL_DENIED_AUTH: le->object = sdsdup(c->argv[0]->ptr); break;
default: le->object = sdsempty();
case ACL_DENIED_CMD: le->object = sdsdup(c->cmd->fullname); break;
case ACL_DENIED_KEY: le->object = sdsdup(c->argv[argpos]->ptr); break;
case ACL_DENIED_CHANNEL: le->object = sdsdup(c->argv[argpos]->ptr); break;
case ACL_DENIED_AUTH: le->object = sdsdup(c->argv[0]->ptr); break;
default: le->object = sdsempty();
}
/* clang-format on */
}

/* if we have a real client from the network, use it (could be missing on module timers) */
Expand Down Expand Up @@ -3090,24 +3096,28 @@ void aclCommand(client *c) {

addReplyBulkCString(c,"reason");
char *reasonstr;
/* clang-format off */
switch(le->reason) {
case ACL_DENIED_CMD: reasonstr="command"; break;
case ACL_DENIED_KEY: reasonstr="key"; break;
case ACL_DENIED_CHANNEL: reasonstr="channel"; break;
case ACL_DENIED_AUTH: reasonstr="auth"; break;
default: reasonstr="unknown";
}
/* clang-format on */
addReplyBulkCString(c,reasonstr);

addReplyBulkCString(c,"context");
char *ctxstr;
/* clang-format off */
switch(le->context) {
case ACL_LOG_CTX_TOPLEVEL: ctxstr="toplevel"; break;
case ACL_LOG_CTX_MULTI: ctxstr="multi"; break;
case ACL_LOG_CTX_LUA: ctxstr="lua"; break;
case ACL_LOG_CTX_MODULE: ctxstr="module"; break;
default: ctxstr="unknown";
}
/* clang-format on */
addReplyBulkCString(c,ctxstr);

addReplyBulkCString(c,"object");
Expand Down Expand Up @@ -3156,6 +3166,7 @@ void aclCommand(client *c) {

addReply(c,shared.ok);
} else if (c->argc == 2 && !strcasecmp(sub,"help")) {
/* clang-format off */
const char *help[] = {
"CAT [<category>]",
" List all commands that belong to <category>, or all command categories",
Expand Down Expand Up @@ -3185,6 +3196,7 @@ void aclCommand(client *c) {
" Return the current connection username.",
NULL
};
/* clang-format on */
addReplyHelp(c,help);
} else {
addReplySubcommandSyntaxError(c);
Expand Down
4 changes: 2 additions & 2 deletions src/anet.c
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ int anetUnixServer(char *err, char *path, mode_t perm, int backlog)
}

int type = SOCK_STREAM;
int flags = ANET_SOCKET_CLOEXEC | ANET_SOCKET_NONBLOCK | ANET_SOCKET_REUSEADDR;
int flags = ANET_SOCKET_CLOEXEC | ANET_SOCKET_NONBLOCK;
if ((s = anetCreateSocket(err,AF_LOCAL,type,0,flags)) == ANET_ERR)
return ANET_ERR;

Expand Down Expand Up @@ -745,7 +745,7 @@ int anetFdToString(int fd, char *ip, size_t ip_len, int *port, int remote) {
* and one of the use cases is O_CLOEXEC|O_NONBLOCK. */
int anetPipe(int fds[2], int read_flags, int write_flags) {
int pipe_flags = 0;
#if defined(__linux__) || defined(__FreeBSD__)
#ifdef HAVE_PIPE2
/* When possible, try to leverage pipe2() to apply flags that are common to both ends.
* There is no harm to set O_CLOEXEC to prevent fd leaks. */
pipe_flags = O_CLOEXEC | (read_flags & write_flags);
Expand Down
6 changes: 4 additions & 2 deletions src/aof.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
#include <sys/wait.h>
#include <sys/param.h>

void freeClientArgv(client *c);
off_t getAppendOnlyFileSize(sds filename, int *status);
off_t getBaseAndIncrAppendOnlyFilesSize(aofManifest *am, int *status);
int getBaseAndIncrAppendOnlyFilesNum(aofManifest *am);
Expand Down Expand Up @@ -701,7 +700,6 @@ void aofDelTempIncrAofFile(void) {
bg_unlink(aof_filepath);
sdsfree(aof_filepath);
sdsfree(aof_filename);
return;
}

/* Called after `loadDataFromDisk` when the server starts. If `server.aof_state` is
Expand Down Expand Up @@ -2035,6 +2033,7 @@ int rioWriteStreamPendingEntry(rio *r, robj *key, const char *groupname, size_t
RETRYCOUNT <count> JUSTID FORCE. */
streamID id;
streamDecodeID(rawid,&id);
/* clang-format off */
if (rioWriteBulkCount(r,'*',12) == 0) return 0;
if (rioWriteBulkString(r,"XCLAIM",6) == 0) return 0;
if (rioWriteBulkObject(r,key) == 0) return 0;
Expand All @@ -2048,6 +2047,7 @@ int rioWriteStreamPendingEntry(rio *r, robj *key, const char *groupname, size_t
if (rioWriteBulkLongLong(r,nack->delivery_count) == 0) return 0;
if (rioWriteBulkString(r,"JUSTID",6) == 0) return 0;
if (rioWriteBulkString(r,"FORCE",5) == 0) return 0;
/* clang-format on */
return 1;
}

Expand All @@ -2056,12 +2056,14 @@ int rioWriteStreamPendingEntry(rio *r, robj *key, const char *groupname, size_t
* All this in the context of the specified key and group. */
int rioWriteStreamEmptyConsumer(rio *r, robj *key, const char *groupname, size_t groupname_len, streamConsumer *consumer) {
/* XGROUP CREATECONSUMER <key> <group> <consumer> */
/* clang-format off */
if (rioWriteBulkCount(r,'*',5) == 0) return 0;
if (rioWriteBulkString(r,"XGROUP",6) == 0) return 0;
if (rioWriteBulkString(r,"CREATECONSUMER",14) == 0) return 0;
if (rioWriteBulkObject(r,key) == 0) return 0;
if (rioWriteBulkString(r,groupname,groupname_len) == 0) return 0;
if (rioWriteBulkString(r,consumer->name,sdslen(consumer->name)) == 0) return 0;
/* clang-format on */
return 1;
}

Expand Down
3 changes: 3 additions & 0 deletions src/asciilogo.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2009-2012, Salvatore Sanfilippo <antirez at gmail dot com>
* Copyright (c) 2024, Valkey contributors
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -27,6 +28,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*/

/* clang-format off */
const char *ascii_logo =
" .+^+. \n"
" .+#########+. \n"
Expand All @@ -47,3 +49,4 @@ const char *ascii_logo =
" '| |####+########+' \n"
" +#########+' \n"
" '+v+' \n\n";
/* clang-format off */
4 changes: 2 additions & 2 deletions src/cluster_legacy.c
Original file line number Diff line number Diff line change
Expand Up @@ -6320,7 +6320,7 @@ int clusterParseSetSlotCommand(client *c, int *slot_out, clusterNode **node_out,
return 1;
}

void clusterSetSlotCommand(client *c) {
void clusterCommandSetSlot(client *c) {
int slot;
int timeout_ms;
clusterNode *n;
Expand Down Expand Up @@ -6575,7 +6575,7 @@ int clusterCommandSpecial(client *c) {
/* SETSLOT 10 IMPORTING <node ID> */
/* SETSLOT 10 STABLE */
/* SETSLOT 10 NODE <node ID> */
clusterSetSlotCommand(c);
clusterCommandSetSlot(c);
} else if (!strcasecmp(c->argv[1]->ptr,"bumpepoch") && c->argc == 2) {
/* CLUSTER BUMPEPOCH */
int retval = clusterBumpConfigEpochWithoutConsensus();
Expand Down
9 changes: 9 additions & 0 deletions src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,15 @@
#define HAVE_ACCEPT4 1
#endif

/* Detect for pipe2() */
#if defined(__linux__) || \
defined(__FreeBSD__) || \
defined(OpenBSD5_7) || \
(defined(__DragonFly__) && __DragonFly_version >= 400106) || \
(defined(__NetBSD__) && (defined(NetBSD6_0) || __NetBSD_Version__ >= 600000000))
#define HAVE_PIPE2 1
#endif

#if (defined(__APPLE__) && defined(MAC_OS_10_6_DETECTED)) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined (__NetBSD__)
#define HAVE_KQUEUE 1
#endif
Expand Down
4 changes: 2 additions & 2 deletions src/crccombine.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ static void gf2_matrix_square(uint64_t *square, uint64_t *mat, uint8_t dim) {
square[n] = CRC_MULTIPLY(mat, mat[n]);
}

/* Turns out our Redis / Jones CRC cycles at this point, so we can support
/* Turns out our Jones CRC cycles at this point, so we can support
* more than 64 bits of extension if we want. Trivially. */
static uint64_t combine_cache[64][64];

Expand Down Expand Up @@ -204,7 +204,7 @@ void init_combine_cache(uint64_t poly, uint8_t dim) {
gf2_matrix_square(combine_cache[1], combine_cache[0], dim);

/* do/while to overwrite the first two layers, they are not used, but are
* re-generated in the last two layers for the Redis polynomial */
* re-generated in the last two layers for the crc polynomial */
do {
gf2_matrix_square(combine_cache[cache_num], combine_cache[cache_num + prev], dim);
prev = -1;
Expand Down
8 changes: 6 additions & 2 deletions src/db.c
Original file line number Diff line number Diff line change
Expand Up @@ -2083,7 +2083,9 @@ int getKeysUsingKeySpecs(struct serverCommand *cmd, robj **argv, int argc, int s
if (cmd->flags & CMD_MODULE || cmd->arity < 0) {
continue;
} else {
serverPanic("Redis built-in command declared keys positions not matching the arity requirements.");
serverPanic("%s built-in command declared keys positions"
" not matching the arity requirements.",
server.extended_redis_compat ? "Redis" : "Valkey");
}
}
keys[result->numkeys].pos = i;
Expand Down Expand Up @@ -2276,7 +2278,9 @@ int getKeysUsingLegacyRangeSpec(struct serverCommand *cmd, robj **argv, int argc
result->numkeys = 0;
return 0;
} else {
serverPanic("Redis built-in command declared keys positions not matching the arity requirements.");
serverPanic("%s built-in command declared keys positions"
" not matching the arity requirements.",
server.extended_redis_compat ? "Redis" : "Valkey");
}
}
keys[i].pos = j;
Expand Down
2 changes: 1 addition & 1 deletion src/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -1997,7 +1997,7 @@ void logServerInfo(void) {
robj *argv[1];
argv[0] = createStringObject("all", strlen("all"));
dict *section_dict = genInfoSectionDict(argv, 1, NULL, &all, &everything);
infostring = genRedisInfoString(section_dict, all, everything);
infostring = genValkeyInfoString(section_dict, all, everything);
if (server.cluster_enabled){
infostring = genClusterDebugString(infostring);
}
Expand Down
8 changes: 6 additions & 2 deletions src/eval.c
Original file line number Diff line number Diff line change
Expand Up @@ -675,15 +675,16 @@ void evalShaRoCommand(client *c) {

void scriptCommand(client *c) {
if (c->argc == 2 && !strcasecmp(c->argv[1]->ptr,"help")) {
/* clang-format off */
const char *help[] = {
"DEBUG (YES|SYNC|NO)",
" Set the debug mode for subsequent scripts executed.",
"EXISTS <sha1> [<sha1> ...]",
" Return information about the existence of the scripts in the script cache.",
"FLUSH [ASYNC|SYNC]",
" Flush the Lua scripts cache. Very dangerous on replicas.",
" When called without the optional mode argument, the behavior is determined by the",
" lazyfree-lazy-user-flush configuration directive. Valid modes are:",
" When called without the optional mode argument, the behavior is determined",
" by the lazyfree-lazy-user-flush configuration directive. Valid modes are:",
" * ASYNC: Asynchronously flush the scripts cache.",
" * SYNC: Synchronously flush the scripts cache.",
"KILL",
Expand All @@ -692,6 +693,7 @@ void scriptCommand(client *c) {
" Load a script into the scripts cache without executing it.",
NULL
};
/* clang-format on */
addReplyHelp(c, help);
} else if (c->argc >= 2 && !strcasecmp(c->argv[1]->ptr,"flush")) {
int async = 0;
Expand Down Expand Up @@ -1251,6 +1253,7 @@ char *ldbRedisProtocolToHuman_Double(sds *o, char *reply);
* char*) so that we can return a modified pointer, as for SDS semantics. */
char *ldbRedisProtocolToHuman(sds *o, char *reply) {
char *p = reply;
/* clang-format off */
switch(*p) {
case ':': p = ldbRedisProtocolToHuman_Int(o,reply); break;
case '$': p = ldbRedisProtocolToHuman_Bulk(o,reply); break;
Expand All @@ -1263,6 +1266,7 @@ char *ldbRedisProtocolToHuman(sds *o, char *reply) {
case '#': p = ldbRedisProtocolToHuman_Bool(o,reply); break;
case ',': p = ldbRedisProtocolToHuman_Double(o,reply); break;
}
/* clang-format on */
return p;
}

Expand Down
2 changes: 2 additions & 0 deletions src/functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,7 @@ void functionFlushCommand(client *c) {

/* FUNCTION HELP */
void functionHelpCommand(client *c) {
/* clang-format off */
const char *help[] = {
"LOAD [REPLACE] <FUNCTION CODE>",
" Create a new library with the given library name and code.",
Expand Down Expand Up @@ -864,6 +865,7 @@ void functionHelpCommand(client *c) {
" libraries with the new libraries (notice that even on this option there is a chance of failure",
" in case of functions name collision with another library).",
NULL };
/* clang-format on */
addReplyHelp(c, help);
}

Expand Down
4 changes: 0 additions & 4 deletions src/intset.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,4 @@ uint32_t intsetLen(const intset *is);
size_t intsetBlobLen(intset *is);
int intsetValidateIntegrity(const unsigned char *is, size_t size, int deep);

#ifdef SERVER_TEST
int intsetTest(int argc, char *argv[], int flags);
#endif

#endif // __INTSET_H
Loading