Skip to content

Commit

Permalink
Multi-threaded simultaneous get_session_key test.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jakio815 committed Jan 6, 2025
1 parent dea9342 commit 8377d39
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
2 changes: 2 additions & 0 deletions tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ This directory includes unit tests and integration tests for the SST C API.

- `encrypt_buf_with_session_key_without_malloc_execution_time_test.c` : Tests the time taken from `encrypt_buf_with_session_key_without_malloc()` and `decrypt_buf_with_session_key_without_malloc()`.

- `multi_thread_get_session_key_test.c` : Tests `get_session_key()` called simultaneously by multiple threads. This test fails.

# Test Instructions

## Turn on Auth (Only Applicable to Integration Tests)
Expand Down
16 changes: 13 additions & 3 deletions tests/multi_thread_get_session_key_test.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
/**
* @file multi_thread_get_session_key_test.c
* @author your name ([email protected])
* @brief Test get_session_key() in multiple threads.
* This tests if get_session_key() can be called in multiple threads without
* mutex locks. However, this test nondeterministically fails.
* @copyright Copyright (c) 2025
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Expand All @@ -8,26 +17,27 @@
void *send_request(void *SST_ctx) {
SST_ctx_t *ctx = (SST_ctx_t *)SST_ctx;
for (int i = 0; i < 1; i++) {
// If there is no mutex_lock, this test fails.
// pthread_mutex_lock(&ctx->mutex);
session_key_list_t *s_key_list;
s_key_list = get_session_key(ctx, s_key_list);
// pthread_mutex_unlock(&ctx->mutex);
// free_session_key_list_t(s_key_list);
free_session_key_list_t(s_key_list);
}
return NULL;
}

int main(int argc, char *argv[]) {
char *config_path = argv[1];
SST_ctx_t *ctx = init_SST(config_path);

// Request one session key to just ensure got distribution key.
// Request one session key to just ensure getting the distribution key.
session_key_list_t *s_key_list = get_session_key(ctx, NULL);
sleep(2);
int num_threads = 5;
pthread_t thread[num_threads];
for (int i = 0; i < num_threads; i++) {
pthread_create(&thread[i], NULL, &send_request, (void *)ctx);
// sleep(1); // If this exits, this doesn't fail.
}
for (int i = 0; i < 100; i++) {
pthread_join(thread[i], NULL);
Expand Down

0 comments on commit 8377d39

Please sign in to comment.