2 Unix SMB/CIFS implementation.
4 Stress test for parallel NSS & libwbclient calls.
6 Copyright (C) Ralph Wuerthner 2018
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
30 #include <sys/types.h>
45 static void *query_nss_thread(void *ptr
)
47 struct thread_state
*state
= ptr
;
50 struct passwd pwd
, *result
;
52 while (time(NULL
) < state
->timeout
) {
53 rc
= getpwnam_r(state
->username
,
58 if (rc
!= 0 || result
== NULL
) {
59 pthread_mutex_lock(&state
->lock
);
61 pthread_mutex_unlock(&state
->lock
);
63 "getpwnam_r failed with rc='%s' result=%p\n",
68 state
->nss_loop_count
++;
69 pthread_mutex_lock(&state
->lock
);
71 pthread_mutex_unlock(&state
->lock
);
74 pthread_mutex_unlock(&state
->lock
);
79 static void *query_wbc_thread(void *ptr
)
81 struct thread_state
*state
= ptr
;
85 while (time(NULL
) < state
->timeout
) {
86 wbc_status
= wbcGetpwnam(state
->username
, &ppwd
);
87 if (!WBC_ERROR_IS_OK(wbc_status
)) {
88 pthread_mutex_lock(&state
->lock
);
90 pthread_mutex_unlock(&state
->lock
);
92 "wbcGetpwnam failed with %s\n",
93 wbcErrorString(wbc_status
));
97 state
->wbc_loop_count
++;
98 pthread_mutex_lock(&state
->lock
);
100 pthread_mutex_unlock(&state
->lock
);
103 pthread_mutex_unlock(&state
->lock
);
108 int main(int argc
, char *argv
[])
111 struct thread_state state
;
112 pthread_t threads
[2];
115 fprintf(stderr
,"%s: missing domain user\n", argv
[0]);
119 state
.username
= argv
[1];
120 state
.timeout
= time(NULL
) + RUNTIME
;
121 rc
= pthread_mutex_init(&state
.lock
, NULL
);
124 "pthread_mutex_init failed: %s\n",
129 state
.nss_loop_count
= 0;
130 state
.wbc_loop_count
= 0;
132 printf("query domain user '%s'\n", state
.username
);
134 /* create query threads */
135 rc
= pthread_create(&threads
[0], NULL
, query_nss_thread
, &state
);
138 "creating NSS thread failed: %s\n",
142 rc
= pthread_create(&threads
[1], NULL
, query_wbc_thread
, &state
);
145 "creating libwbclient thread failed: %s\n",
150 /* wait for query threads to terminate */
151 for (n
= 0; n
< 2; n
++) {
152 rc
= pthread_join(threads
[n
], NULL
);
155 "joining query thread %i failed: %s\n",
162 fprintf(state
.fail
? stderr
: stdout
,
163 "test %s with %i NSS and %i libwbclient calls\n",
164 state
.fail
? "failed" : "passed",
165 state
.nss_loop_count
,
166 state
.wbc_loop_count
);