1 /* Tests for loading and unloading of iconv modules.
2 Copyright (C) 2000, 2001, 2002 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Ulrich Drepper <drepper@cygnus.com>, 2000.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, write to the Free
18 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
27 /* How many load/unload operations do we do. */
28 #define TEST_ROUNDS 5000
31 enum state
{ unloaded
, loaded
};
40 #define MODULE(Name) { .name = #Name, .state = unloaded }
58 #define nmodules (sizeof (modules) / sizeof (modules[0]))
62 static const char inbuf
[] =
63 "The first step is the function to create a handle.\n"
65 " - Function: iconv_t iconv_open (const char *TOCODE, const char\n"
67 " The `iconv_open' function has to be used before starting a\n"
68 " conversion. The two parameters this function takes determine the\n"
69 " source and destination character set for the conversion and if the\n"
70 " implementation has the possibility to perform such a conversion the\n"
71 " function returns a handle.\n"
73 " If the wanted conversion is not available the function returns\n"
74 " `(iconv_t) -1'. In this case the global variable `errno' can have\n"
75 " the following values:\n"
78 " The process already has `OPEN_MAX' file descriptors open.\n"
81 " The system limit of open file is reached.\n"
84 " Not enough memory to carry out the operation.\n"
87 " The conversion from FROMCODE to TOCODE is not supported.\n"
89 " It is not possible to use the same descriptor in different threads\n"
90 " to perform independent conversions. Within the data structures\n"
91 " associated with the descriptor there is information about the\n"
92 " conversion state. This must not be messed up by using it in\n"
93 " different conversions.\n"
95 " An `iconv' descriptor is like a file descriptor as for every use a\n"
96 " new descriptor must be created. The descriptor does not stand for\n"
97 " all of the conversions from FROMSET to TOSET.\n"
99 " The GNU C library implementation of `iconv_open' has one\n"
100 " significant extension to other implementations. To ease the\n"
101 " extension of the set of available conversions the implementation\n"
102 " allows storing the necessary files with data and code in\n"
103 " arbitrarily many directories. How this extension has to be\n"
104 " written will be explained below (*note glibc iconv\n"
105 " Implementation::). Here it is only important to say that all\n"
106 " directories mentioned in the `GCONV_PATH' environment variable are\n"
107 " considered if they contain a file `gconv-modules'. These\n"
108 " directories need not necessarily be created by the system\n"
109 " administrator. In fact, this extension is introduced to help users\n"
110 " writing and using their own, new conversions. Of course this does\n"
111 " not work for security reasons in SUID binaries; in this case only\n"
112 " the system directory is considered and this normally is\n"
113 " `PREFIX/lib/gconv'. The `GCONV_PATH' environment variable is\n"
114 " examined exactly once at the first call of the `iconv_open'\n"
115 " function. Later modifications of the variable have no effect.\n";
121 size_t count
= TEST_ROUNDS
;
127 srandom (TEST_ROUNDS
);
131 int idx
= random () % nmodules
;
133 if (modules
[idx
].state
== unloaded
)
136 char *inptr
= (char *) inbuf
;
137 size_t insize
= sizeof (inbuf
) - 1;
138 char *outptr
= outbuf
;
139 size_t outsize
= sizeof (outbuf
);
141 /* Load the module and do the conversion. */
142 modules
[idx
].cd
= iconv_open ("UTF-8", modules
[idx
].name
);
144 if (modules
[idx
].cd
== (iconv_t
) -1)
146 printf ("opening of %s failed: %m\n", modules
[idx
].name
);
151 modules
[idx
].state
= loaded
;
153 /* Now a simple test. */
154 if (iconv (modules
[idx
].cd
, &inptr
, &insize
, &outptr
, &outsize
) != 0
157 printf ("conversion with %s failed\n", modules
[idx
].name
);
163 /* Unload the module. */
164 if (iconv_close (modules
[idx
].cd
) != 0)
166 printf ("closing of %s failed: %m\n", modules
[idx
].name
);
171 modules
[idx
].state
= unloaded
;
175 for (count
= 0; count
< nmodules
; ++count
)
176 if (modules
[count
].state
== loaded
&& iconv_close (modules
[count
].cd
) != 0)
178 printf ("closing of %s failed: %m\n", modules
[count
].name
);