stress-tests.c revision 01bc248f42f1a056091aa3dd99ba9615ba61df6f
/*
SSSD
Stress tests
Copyright (C) Jakub Hrozek <jhrozek@redhat.com> 2009
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <signal.h>
#include <stdlib.h>
#include <talloc.h>
#include <popt.h>
#include <pwd.h>
#include <grp.h>
#include <errno.h>
#define DEFAULT_START 10
#define DEFAULT_STOP 20
#define NAME_SIZE 255
#define CHUNK 64
/* How many tests failed */
int failure_count;
/* Be chatty */
int verbose;
/*
* Look up one user. If the user is not found using getpwnam, the success
* or failure depends on enoent_fail being set.
*/
{
int ret = 0;
int error;
errno = 0;
}
}
"getpwnam failed (name: %s): errno = %d, error = %s\n",
}
return ret;
}
/*
* Look up one group. If the user is not found using getgrnam, the success
* or failure depends on enoent_fail being set.
*/
{
int ret = 0;
errno = 0;
}
}
"getgrnam failed (name %s): errno = %d, error = %s\n",
}
return ret;
}
{
if (group) {
} else {
}
}
/*
* Beware, has side-effects: changes global variable failure_count
*/
void child_handler(int signum)
{
if (ret == -1) {
perror("wait");
}
if (ret) {
if (verbose) {
"A child exited with error code %d\n",
}
}
} else ++failure_count;
}
}
{
char **out;
int idx = 0;
return ENOMEM;
}
return ENOMEM;
}
}
return EOK;
}
{
int n = 0;
int array_size = CHUNK;
int ret;
char **out;
return ENOMEM;
}
return ENOMEM;
}
if ((n++ % CHUNK) == 0) {
array_size += CHUNK;
return ENOMEM;
}
}
}
return ret;
}
return EOK;
}
{
int opt;
int pc_start=DEFAULT_START;
int pc_stop=DEFAULT_STOP;
int pc_enoent_fail=0;
int pc_groups=0;
int pc_verbosity = 0;
struct poptOption long_options[] = {
"Lookup in groups instead of users", NULL },
"The username prefix", NULL },
&pc_start, 0,
"Start value to append to prefix", NULL },
&pc_stop, 0,
"End value to append to prefix", NULL },
"Fail on not getting the requested NSS data (default: No)",
NULL },
"Be verbose", NULL },
};
/* parse the params */
switch (opt) {
case 'v':
pc_verbosity = 1;
break;
default:
return 1;
}
}
if (pc_prefix) {
if (verbose) {
perror("generate_names");
}
}
} else {
if (verbose) {
perror("read_names");
}
}
}
/* Reap the children in a handler asynchronously so we can
* somehow protect against too many processes */
/* Fire up the child processes */
idx = 0;
if (pid == -1) {
/* Try again in hope that some child has exited */
continue;
}
perror("fork");
} else if ( pid == 0 ) {
/* child */
}
}
/* Process the rest of the children here in main */
if (ret == -1) {
perror("wait");
}
if (ret) {
if (verbose) {
"A child exited with error code %d\n",
}
}
} else ++failure_count;
}
if (pc_verbosity) {
"Total tests run: %d\nPassed: %d\nFailed: %d\n",
idx,
idx - failure_count,
}
}