summaryrefslogtreecommitdiffstats
path: root/src/test/crypto_init.cc
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 18:24:20 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 18:24:20 +0000
commit483eb2f56657e8e7f419ab1a4fab8dce9ade8609 (patch)
treee5d88d25d870d5dedacb6bbdbe2a966086a0a5cf /src/test/crypto_init.cc
parentInitial commit. (diff)
downloadceph-483eb2f56657e8e7f419ab1a4fab8dce9ade8609.tar.xz
ceph-483eb2f56657e8e7f419ab1a4fab8dce9ade8609.zip
Adding upstream version 14.2.21.upstream/14.2.21upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/test/crypto_init.cc')
-rw-r--r--src/test/crypto_init.cc49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/test/crypto_init.cc b/src/test/crypto_init.cc
new file mode 100644
index 00000000..781175eb
--- /dev/null
+++ b/src/test/crypto_init.cc
@@ -0,0 +1,49 @@
+#include <errno.h>
+#include <time.h>
+#include <pthread.h>
+#include <unistd.h>
+#include <vector>
+
+#include "include/types.h"
+#include "common/code_environment.h"
+#include "global/global_context.h"
+#include "global/global_init.h"
+#include "include/msgr.h"
+#include "gtest/gtest.h"
+#include "auth/Crypto.h"
+#include "common/ceph_crypto.h"
+
+#ifdef USE_NSS
+void *init_crypto(void *p) {
+ ceph::crypto::init(g_ceph_context);
+ return NULL;
+}
+
+// Tests for a race condition in libnss when calling crypto_init
+// multiple times simultaneously from different threads.
+TEST(CRYPTO_INIT, NSS_RACE) {
+ std::vector<const char*> args;
+ auto cct = global_init(NULL, args, CEPH_ENTITY_TYPE_CLIENT,
+ CODE_ENVIRONMENT_UTILITY,
+ CINIT_FLAG_NO_DEFAULT_CONFIG_FILE);
+ // Most reliably reproduced with more threads than cores.
+ long n_thread = sysconf(_SC_NPROCESSORS_ONLN) * 2;
+ pthread_t *ts = (pthread_t*)malloc(n_thread * sizeof(pthread_t));
+ int i;
+ for (i = 0; i < n_thread; i++) {
+ pthread_create(&ts[i], NULL, init_crypto, NULL);
+ }
+ for (i = 0; i < n_thread; i++) {
+ int k;
+ void *p = (void*)&k;
+ pthread_join(ts[i], &p);
+ }
+ free(ts);
+}
+
+#endif
+
+int main(int argc, char **argv) {
+ ::testing::InitGoogleTest(&argc, argv);
+ return RUN_ALL_TESTS();
+}