7 #include "include/types.h"
8 #include "common/code_environment.h"
9 #include "global/global_context.h"
10 #include "global/global_init.h"
11 #include "include/msgr.h"
12 #include "gtest/gtest.h"
13 #include "auth/Crypto.h"
14 #include "common/ceph_crypto.h"
17 void *init_crypto(void *p
) {
18 ceph::crypto::init(g_ceph_context
);
22 // Tests for a race condition in libnss when calling crypto_init
23 // multiple times simultaneously from different threads.
24 TEST(CRYPTO_INIT
, NSS_RACE
) {
25 std::vector
<const char*> args
;
26 auto cct
= global_init(NULL
, args
, CEPH_ENTITY_TYPE_CLIENT
,
27 CODE_ENVIRONMENT_UTILITY
,
28 CINIT_FLAG_NO_DEFAULT_CONFIG_FILE
);
29 // Most reliably reproduced with more threads than cores.
30 long n_thread
= sysconf(_SC_NPROCESSORS_ONLN
) * 2;
31 pthread_t
*ts
= (pthread_t
*)malloc(n_thread
* sizeof(pthread_t
));
33 for (i
= 0; i
< n_thread
; i
++) {
34 pthread_create(&ts
[i
], NULL
, init_crypto
, NULL
);
36 for (i
= 0; i
< n_thread
; i
++) {
39 pthread_join(ts
[i
], &p
);
46 int main(int argc
, char **argv
) {
47 ::testing::InitGoogleTest(&argc
, argv
);
48 return RUN_ALL_TESTS();