Skip to content

Commit

Permalink
Get initial test binary building with USE_SSL=1
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-grunder committed Jun 23, 2024
1 parent a638c73 commit 193bfc8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 112 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ $(OBJ_DIR)/%.o: $(TEST_DIR)/%.c | $(OBJ_DIR)
$(CC) -std=c99 $(REAL_CFLAGS) -I$(INCLUDE_DIR) -MMD -MP -c $< -o $@

$(TEST_DIR)/%: $(OBJ_DIR)/%.o $(STLIBNAME)
$(CC) -o $@ $< $(STLIBNAME) $(LDFLAGS)
$(CC) -o $@ $< $(STLIBNAME) $(LDFLAGS) $(SSL_LDLAGS) $(TEST_LDFLAGS)

$(OBJ_DIR):
mkdir -p $(OBJ_DIR)
Expand Down
123 changes: 12 additions & 111 deletions tests/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -878,6 +878,18 @@ static void test_free_null(void) {
test_cond(reply == NULL);
}

/* Wrap malloc to abort on failure so OOM checks don't make the test logic
* harder to follow. */
static void *vk_malloc_safe(size_t size) {
void *ptr = vk_malloc(size);
if (ptr == NULL) {
fprintf(stderr, "Error: Out of memory\n");
exit(-1);
}

return ptr;
}

static void *vk_malloc_fail(size_t size) {
(void)size;
return NULL;
Expand Down Expand Up @@ -1434,18 +1446,6 @@ static void test_invalid_timeout_errors(struct config config) {
valkeyFree(c);
}

/* Wrap malloc to abort on failure so OOM checks don't make the test logic
* harder to follow. */
void *vk_malloc_safe(size_t size) {
void *ptr = vk_malloc(size);
if (ptr == NULL) {
fprintf(stderr, "Error: Out of memory\n");
exit(-1);
}

return ptr;
}

static void test_throughput(struct config config) {
valkeyContext *c = do_connect(config);
valkeyReply **replies;
Expand Down Expand Up @@ -1535,105 +1535,6 @@ static void test_throughput(struct config config) {
disconnect(c, 0);
}

// static long __test_callback_flags = 0;
// static void __test_callback(valkeyContext *c, void *privdata) {
// ((void)c);
// /* Shift to detect execution order */
// __test_callback_flags <<= 8;
// __test_callback_flags |= (long)privdata;
// }
//
// static void __test_reply_callback(valkeyContext *c, valkeyReply *reply, void *privdata) {
// ((void)c);
// /* Shift to detect execution order */
// __test_callback_flags <<= 8;
// __test_callback_flags |= (long)privdata;
// if (reply) freeReplyObject(reply);
// }
//
// static valkeyContext *__connect_nonblock() {
// /* Reset callback flags */
// __test_callback_flags = 0;
// return valkeyConnectNonBlock("127.0.0.1", port, NULL);
// }
//
// static void test_nonblocking_connection() {
// valkeyContext *c;
// int wdone = 0;
//
// test("Calls command callback when command is issued: ");
// c = __connect_nonblock();
// valkeySetCommandCallback(c,__test_callback,(void*)1);
// valkeyCommand(c,"PING");
// test_cond(__test_callback_flags == 1);
// valkeyFree(c);
//
// test("Calls disconnect callback on valkeyDisconnect: ");
// c = __connect_nonblock();
// valkeySetDisconnectCallback(c,__test_callback,(void*)2);
// valkeyDisconnect(c);
// test_cond(__test_callback_flags == 2);
// valkeyFree(c);
//
// test("Calls disconnect callback and free callback on valkeyFree: ");
// c = __connect_nonblock();
// valkeySetDisconnectCallback(c,__test_callback,(void*)2);
// valkeySetFreeCallback(c,__test_callback,(void*)4);
// valkeyFree(c);
// test_cond(__test_callback_flags == ((2 << 8) | 4));
//
// test("valkeyBufferWrite against empty write buffer: ");
// c = __connect_nonblock();
// test_cond(valkeyBufferWrite(c,&wdone) == VALKEY_OK && wdone == 1);
// valkeyFree(c);
//
// test("valkeyBufferWrite against not yet connected fd: ");
// c = __connect_nonblock();
// valkeyCommand(c,"PING");
// test_cond(valkeyBufferWrite(c,NULL) == VALKEY_ERR &&
// strncmp(c->error,"write:",6) == 0);
// valkeyFree(c);
//
// test("valkeyBufferWrite against closed fd: ");
// c = __connect_nonblock();
// valkeyCommand(c,"PING");
// valkeyDisconnect(c);
// test_cond(valkeyBufferWrite(c,NULL) == VALKEY_ERR &&
// strncmp(c->error,"write:",6) == 0);
// valkeyFree(c);
//
// test("Process callbacks in the right sequence: ");
// c = __connect_nonblock();
// valkeyCommandWithCallback(c,__test_reply_callback,(void*)1,"PING");
// valkeyCommandWithCallback(c,__test_reply_callback,(void*)2,"PING");
// valkeyCommandWithCallback(c,__test_reply_callback,(void*)3,"PING");
//
// /* Write output buffer */
// wdone = 0;
// while(!wdone) {
// usleep(500);
// valkeyBufferWrite(c,&wdone);
// }
//
// /* Read until at least one callback is executed (the 3 replies will
// * arrive in a single packet, causing all callbacks to be executed in
// * a single pass). */
// while(__test_callback_flags == 0) {
// assert(valkeyBufferRead(c) == VALKEY_OK);
// valkeyProcessCallbacks(c);
// }
// test_cond(__test_callback_flags == 0x010203);
// valkeyFree(c);
//
// test("valkeyDisconnect executes pending callbacks with NULL reply: ");
// c = __connect_nonblock();
// valkeySetDisconnectCallback(c,__test_callback,(void*)1);
// valkeyCommandWithCallback(c,__test_reply_callback,(void*)2,"PING");
// valkeyDisconnect(c);
// test_cond(__test_callback_flags == 0x0201);
// valkeyFree(c);
// }

#ifdef VALKEY_TEST_ASYNC

#pragma GCC diagnostic ignored "-Woverlength-strings" /* required on gcc 4.8.x due to assert statements */
Expand Down

0 comments on commit 193bfc8

Please sign in to comment.