1 /*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26
27 /*
28 * check_domain_mt.c
29 * This program starts multiple threads to call mapid_check_domain()
30 * and test its thread-safety.
31 *
32 * Return value:
33 * On success, it returns 0; on error, it returns 1.
34 *
35 * Usage:
36 * ./check_domain_mt
37 */
38
39 #include <stdio.h>
40 #include <pthread.h>
41 #include <nfs/mapid.h>
42
43 #define FIFTY_CHARS "x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x.x."
44 #define TWOHUNDRED_CHARS FIFTY_CHARS FIFTY_CHARS FIFTY_CHARS FIFTY_CHARS
45
46 typedef struct domain_check {
47 char *str;
48 int ret;
49 } domain_check_t;
50
51 domain_check_t data[] = {
52 { "helloworld", 1},
53 { "hello.world", 1},
54 { "HELLO.WORLD", 1},
55 { "hello-world.1234", 1},
56 { TWOHUNDRED_CHARS FIFTY_CHARS"12345", 1},
57 { "hello world", 0},
58 { "hello@world", 0},
59 { "1234.world", 1},
60 { "hello.worl-", 0},
61 { "hello.world ", 0},
62 { TWOHUNDRED_CHARS FIFTY_CHARS"123456", -1},
63 { "", 0}
64 };
65
66 #define NTHREADS (sizeof (data) / sizeof (domain_check_t))
67
68 void *check_domain(void *arg);
69
70 int
71 main()
72 {
73 pthread_t threads[NTHREADS+1];
74 int ids[NTHREADS+1];
75 char *p;
76 int i;
77 int status;
78 int *p_status = &status;
79
80 /* start threads */
81 for (i = 1; i <= NTHREADS; i++) {
82 ids[i] = i;
83 if (pthread_create(&threads[i], NULL, check_domain, &ids[i])) {
84 fprintf(stderr, "failed to start thread %d\n", i);
85 perror("pthread_create");
86 exit(1);
87 }
88 }
89
90 /* check threads' exit statuses */
91 for (i = 1; i <= NTHREADS; i++) {
92 if (pthread_join(threads[i], (void **)&ids[i])) {
93 fprintf(stderr, "failed to get thread %d status\n", i);
94 perror("pthread_join");
95 exit(1);
96 }
97
98 if (ids[i]) {
99 fprintf(stderr, "thread %d terminated abnormally\n");
100 exit(1);
101 }
102 }
103
104 exit(0);
105 }
106
107 void *
108 check_domain(void *arg) {
109 int id = *((int *)arg);
110
111 if (mapid_stdchk_domain(data[id-1].str) != data[id-1].ret) {
112 fprintf(stderr,
113 "mapid_stdchk_domain() failed in thread %d\n", id);
114 pthread_exit((void *)1);
115 }
116
117 pthread_exit((void *)0);
118 }