Add -v option parsing to regress tests, currently a no-op.

This will be used by a "check-verbose" target in the future.
This commit is contained in:
Todd C. Miller
2022-03-02 11:09:51 -07:00
parent dda14cb57a
commit 43cc80d795
26 changed files with 438 additions and 122 deletions

View File

@@ -36,27 +36,40 @@ sudo_dso_public int main(int argc, char *argv[]);
static void
usage(void)
{
fprintf(stderr, "usage: %s inputfile\n", getprogname());
fprintf(stderr, "usage: %s [-v] inputfile\n", getprogname());
exit(EXIT_FAILURE);
}
int
main(int argc, char *argv[])
{
int ch, lineno = 0, which = 0;
char *line, lines[2][2048];
const char *infile;
size_t len;
FILE *fp;
char *line, lines[2][2048];
int lineno = 0;
int which = 0;
initprogname(argc > 0 ? argv[0] : "check_wrap");
if (argc != 2)
while ((ch = getopt(argc, argv, "v")) != -1) {
switch (ch) {
case 'v':
/* ignored */
break;
default:
usage();
}
}
argc -= optind;
argv += optind;
fp = fopen(argv[1], "r");
if (argc != 1)
usage();
infile = argv[0];
fp = fopen(infile, "r");
if (fp == NULL)
sudo_fatalx("unable to open %s", argv[1]);
sudo_fatalx("unable to open %s", infile);
/*
* Each test record consists of a log entry on one line and a list of
@@ -89,8 +102,9 @@ main(int argc, char *argv[])
} else {
len = maxlen = sudo_strtonum(cp, 0, INT_MAX, &errstr);
}
if (errstr != NULL)
sudo_fatalx("%s: invalid length on line %d\n", argv[1], lineno);
if (errstr != NULL) {
sudo_fatalx("%s: invalid length on line %d\n", infile, lineno);
}
while (len <= maxlen) {
if (len == 0)
printf("# word wrap disabled\n");
@@ -104,5 +118,5 @@ main(int argc, char *argv[])
which = !which;
}
exit(0);
return EXIT_SUCCESS;
}

View File

@@ -141,5 +141,5 @@ main(int argc, char *argv[])
printf("%s: %d tests run, %d errors, %d%% success rate\n",
getprogname(), ntests, errors, (ntests - errors) * 100 / ntests);
}
exit(errors);
return errors;
}

View File

@@ -38,25 +38,38 @@ int
main(int argc, char *argv[])
{
int dfd = -1, ttyin_fd = -1, ttyout_fd = -1, ttyin_ok_fd = -1;
int i, tests = 0, errors = 0;
int ch, i, ntests = 0, errors = 0;
void *passprompt_regex = NULL;
initprogname(argc > 0 ? argv[0] : "check_iolog_filter");
while ((ch = getopt(argc, argv, "v")) != -1) {
switch (ch) {
case 'v':
/* ignore */
break;
default:
fprintf(stderr, "usage: %s [-v] iolog_dir ...\n", getprogname());
return EXIT_FAILURE;
}
}
argc -= optind;
argv += optind;
passprompt_regex = iolog_pwfilt_alloc();
if (passprompt_regex == NULL)
sudo_fatalx("unable to allocate memory");
if (!iolog_pwfilt_add(passprompt_regex, "(?i)password[: ]*"))
exit(1);
for (i = 1; i < argc; i++) {
for (i = 0; i < argc; i++) {
struct iolog_file iolog_timing = { true };
struct timing_closure timing;
const char *logdir = argv[i];
char tbuf[8192], fbuf[8192];
ssize_t nread;
tests++;
ntests++;
/* I/O logs consist of multiple files in a directory. */
dfd = open(logdir, O_RDONLY);
@@ -180,11 +193,11 @@ next:
}
iolog_pwfilt_free(passprompt_regex);
if (tests != 0) {
printf("%s: %d test%s run, %d errors, %d%% success rate\n",
getprogname(), tests, tests == 1 ? "" : "s", errors,
(tests - errors) * 100 / tests);
if (ntests != 0) {
printf("iolog_filter: %d test%s run, %d errors, %d%% success rate\n",
ntests, ntests == 1 ? "" : "s", errors,
(ntests - errors) * 100 / ntests);
}
exit(errors);
return errors;
}

View File

@@ -171,7 +171,7 @@ int
main(int argc, char *argv[])
{
struct json_object root;
int ch, i, tests = 0, errors = 0;
int ch, i, ntests = 0, errors = 0;
bool cat = false;
initprogname(argc > 0 ? argv[0] : "check_iolog_json");
@@ -200,7 +200,7 @@ main(int argc, char *argv[])
FILE *infp = NULL;
FILE *outfp = NULL;
tests++;
ntests++;
if (!sudo_json_init(&json, 4, false, true)) {
errors++;
@@ -255,11 +255,11 @@ next:
fclose(outfp);
}
if (tests != 0) {
if (ntests != 0) {
printf("iolog_json: %d test%s run, %d errors, %d%% success rate\n",
tests, tests == 1 ? "" : "s", errors,
(tests - errors) * 100 / tests);
ntests, ntests == 1 ? "" : "s", errors,
(ntests - errors) * 100 / ntests);
}
exit(errors);
return errors;
}

View File

@@ -67,25 +67,38 @@ main(int argc, char *argv[])
{
char testdir[] = "mkpath.XXXXXX";
char *rmargs[] = { "rm", "-rf", NULL, NULL };
int status, tests = 0, errors = 0;
int ch, status, ntests = 0, errors = 0;
initprogname(argc > 0 ? argv[0] : "check_iolog_mkpath");
while ((ch = getopt(argc, argv, "v")) != -1) {
switch (ch) {
case 'v':
/* ignore */
break;
default:
fprintf(stderr, "usage: %s [-v]\n", getprogname());
return EXIT_FAILURE;
}
}
argc -= optind;
argv += optind;
if (mkdtemp(testdir) == NULL)
sudo_fatal("unable to create test dir");
rmargs[2] = testdir;
test_iolog_mkpath(testdir, &tests, &errors);
test_iolog_mkpath(testdir, &ntests, &errors);
if (tests != 0) {
if (ntests != 0) {
printf("iolog_mkpath: %d test%s run, %d errors, %d%% success rate\n",
tests, tests == 1 ? "" : "s", errors,
(tests - errors) * 100 / tests);
ntests, ntests == 1 ? "" : "s", errors,
(ntests - errors) * 100 / ntests);
}
/* Clean up (avoid running via shell) */
execvp("rm", rmargs);
wait(&status);
exit(errors);
return errors;
}

View File

@@ -180,18 +180,29 @@ main(int argc, char *argv[])
char line[2048];
char *file_in = NULL, *file_out = NULL;
char *dir_in = NULL, *dir_out = NULL;
int state = 0;
int errors = 0;
int tests = 0;
int ch, state = 0, errors = 0, ntests = 0;
initprogname(argc > 0 ? argv[0] : "check_iolog_path");
if (argc != 2)
while ((ch = getopt(argc, argv, "v")) != -1) {
switch (ch) {
case 'v':
/* ignore */
break;
default:
fprintf(stderr, "usage: %s [-v] data\n", getprogname());
return EXIT_FAILURE;
}
}
argc -= optind;
argv += optind;
if (argc != 1)
usage();
fp = fopen(argv[1], "r");
fp = fopen(argv[0], "r");
if (fp == NULL)
sudo_fatalx("unable to open %s", argv[1]);
sudo_fatalx("unable to open %s", argv[0]);
/*
* Input consists of 12 lines:
@@ -262,7 +273,7 @@ main(int argc, char *argv[])
break;
case 11:
errors += do_check(dir_in, file_in, dir_out, file_out);
tests++;
ntests++;
reset_escape_data(&escape_data);
break;
default:
@@ -271,11 +282,11 @@ main(int argc, char *argv[])
state = (state + 1) % MAX_STATE;
}
if (tests != 0) {
if (ntests != 0) {
printf("iolog_path: %d test%s run, %d errors, %d%% success rate\n",
tests, tests == 1 ? "" : "s", errors,
(tests - errors) * 100 / tests);
ntests, ntests == 1 ? "" : "s", errors,
(ntests - errors) * 100 / ntests);
}
exit(errors);
return errors;
}

View File

@@ -130,19 +130,32 @@ test_adjust_delay(int *ntests, int *nerrors)
int
main(int argc, char *argv[])
{
int tests = 0, errors = 0;
int ch, ntests = 0, errors = 0;
initprogname(argc > 0 ? argv[0] : "check_iolog_timing");
test_parse_delay(&tests, &errors);
while ((ch = getopt(argc, argv, "v")) != -1) {
switch (ch) {
case 'v':
/* ignore */
break;
default:
fprintf(stderr, "usage: %s [-v]\n", getprogname());
return EXIT_FAILURE;
}
}
argc -= optind;
argv += optind;
test_adjust_delay(&tests, &errors);
test_parse_delay(&ntests, &errors);
if (tests != 0) {
test_adjust_delay(&ntests, &errors);
if (ntests != 0) {
printf("iolog_timing: %d test%s run, %d errors, %d%% success rate\n",
tests, tests == 1 ? "" : "s", errors,
(tests - errors) * 100 / tests);
ntests, ntests == 1 ? "" : "s", errors,
(ntests - errors) * 100 / ntests);
}
exit(errors);
return errors;
}

View File

@@ -39,9 +39,22 @@ sudo_dso_public int main(int argc, char *argv[]);
int
main(int argc, char *argv[])
{
int fds[2], flag, maxfd, minfd, errors = 0, ntests = 0;
int ch, fds[2], flag, maxfd, minfd, errors = 0, ntests = 0;
initprogname(argc > 0 ? argv[0] : "closefrom_test");
while ((ch = getopt(argc, argv, "v")) != -1) {
switch (ch) {
case 'v':
/* ignore */
break;
default:
fprintf(stderr, "usage: %s [-v]\n", getprogname());
return EXIT_FAILURE;
}
}
argc -= optind;
argv += optind;
/* We use pipe() because it doesn't rely on the filesystem. */
ntests++;
if (pipe(fds) == -1) {
@@ -103,5 +116,5 @@ done:
printf("%s: %d tests run, %d errors, %d%% success rate\n",
getprogname(), ntests, errors, (ntests - errors) * 100 / ntests);
}
exit(errors);
return errors;
}

View File

@@ -25,14 +25,27 @@ main(int argc, char *argv[])
{
FILE *fp = stdin;
char pattern[1024], string[1024], flagstr[1024];
int errors = 0, tests = 0, flags, got, want;
int ch, errors = 0, ntests = 0, flags, got, want;
initprogname(argc > 0 ? argv[0] : "fnm_test");
if (argc > 1) {
if ((fp = fopen(argv[1], "r")) == NULL) {
perror(argv[1]);
exit(EXIT_FAILURE);
while ((ch = getopt(argc, argv, "v")) != -1) {
switch (ch) {
case 'v':
/* ignore */
break;
default:
fprintf(stderr, "usage: %s [-v]\n", getprogname());
return EXIT_FAILURE;
}
}
argc -= optind;
argv += optind;
if (argc > 0) {
if ((fp = fopen(argv[0], "r")) == NULL) {
perror(argv[0]);
return EXIT_FAILURE;
}
}
@@ -66,13 +79,13 @@ main(int argc, char *argv[])
pattern, string, flags, want, got);
errors++;
}
tests++;
ntests++;
}
}
if (tests != 0) {
if (ntests != 0) {
printf("fnmatch: %d test%s run, %d errors, %d%% success rate\n",
tests, tests == 1 ? "" : "s", errors,
(tests - errors) * 100 / tests);
ntests, ntests == 1 ? "" : "s", errors,
(ntests - errors) * 100 / ntests);
}
exit(errors);
return errors;
}

View File

@@ -154,9 +154,23 @@ main(int argc, char *argv[])
{
size_t buflen = 0;
char *buf = NULL;
int ch;
initprogname(argc > 0 ? argv[0] : "getdelim_test");
while ((ch = getopt(argc, argv, "v")) != -1) {
switch (ch) {
case 'v':
/* ignore */
break;
default:
fprintf(stderr, "usage: %s [-v]\n", getprogname());
return EXIT_FAILURE;
}
}
argc -= optind;
argv += optind;
runtests(&buf, &buflen);
/* XXX - redo tests with preallocated buffer filled with junk */
@@ -164,5 +178,5 @@ main(int argc, char *argv[])
printf("%s: %d tests run, %d errors, %d%% success rate\n",
getprogname(), ntests, errors, (ntests - errors) * 100 / ntests);
}
exit(errors);
return errors;
}

View File

@@ -48,16 +48,26 @@ main(int argc, char *argv[])
char *username = NULL;
GETGROUPS_T *groups = NULL;
struct passwd *pw;
int i, ngroups;
int ch, i, ngroups;
gid_t basegid;
initprogname(argc > 0 ? argv[0] : "getgids");
if (getopt(argc, argv, "") != -1) {
fprintf(stderr, "usage: %s [user]\n", getprogname());
while ((ch = getopt(argc, argv, "v")) != -1) {
switch (ch) {
case 'v':
/* ignore */
break;
default:
fprintf(stderr, "usage: %s [-v] [user]\n", getprogname());
return EXIT_FAILURE;
}
if (argc > 1)
username = argv[1];
}
argc -= optind;
argv += optind;
if (argc > 0)
username = argv[0];
if (username != NULL) {
if ((pw = getpwnam(username)) == NULL)

View File

@@ -48,11 +48,25 @@ main(int argc, char *argv[])
struct passwd *pw;
struct group *grp;
char *username;
int i, j, ntests = 0;
int ch, i, j, ntests = 0;
int ngroups;
gid_t basegid;
initprogname(argc > 0 ? argv[0] : "getgrouplist_test");
while ((ch = getopt(argc, argv, "v")) != -1) {
switch (ch) {
case 'v':
/* ignore */
break;
default:
fprintf(stderr, "usage: %s [-v]\n", getprogname());
return EXIT_FAILURE;
}
}
argc -= optind;
argv += optind;
if ((pw = getpwuid(0)) == NULL)
sudo_fatal_nodebug("getpwuid(0)");
basegid = pw->pw_gid;
@@ -96,5 +110,5 @@ main(int argc, char *argv[])
getprogname(), ntests, errors, (ntests - errors) * 100 / ntests);
}
#endif /* HAVE_GETGROUPLIST_2 */
exit(errors);
return errors;
}

View File

@@ -36,16 +36,29 @@ main(int argc, char **argv)
{
FILE *fp = stdin;
char buf[2048], *cp, *ep;
int errors = 0, tests = 0, lineno;
int ch, errors = 0, ntests = 0, lineno;
struct gl_entry entry;
size_t len;
initprogname(argc > 0 ? argv[0] : "globtest");
if (argc > 1) {
if ((fp = fopen(argv[1], "r")) == NULL) {
perror(argv[1]);
exit(EXIT_FAILURE);
while ((ch = getopt(argc, argv, "v")) != -1) {
switch (ch) {
case 'v':
/* ignore */
break;
default:
fprintf(stderr, "usage: %s [-v]\n", getprogname());
return EXIT_FAILURE;
}
}
argc -= optind;
argv += optind;
if (argc > 0) {
if ((fp = fopen(argv[0], "r")) == NULL) {
perror(argv[0]);
return EXIT_FAILURE;
}
}
@@ -68,7 +81,7 @@ main(int argc, char **argv)
if (buf[len - 1] != '\n') {
fprintf(stderr,
"globtest: missing newline at EOF\n");
exit(EXIT_FAILURE);
return EXIT_FAILURE;
}
buf[--len] = '\0';
}
@@ -79,7 +92,7 @@ main(int argc, char **argv)
/* check previous pattern */
if (entry.pattern[0]) {
errors += test_glob(&entry);
tests++;
ntests++;
}
/* start new entry */
@@ -87,14 +100,14 @@ main(int argc, char **argv)
fprintf(stderr,
"globtest: invalid entry on line %d\n",
lineno);
exit(EXIT_FAILURE);
return EXIT_FAILURE;
}
len = cp - buf - 1;
if (len >= sizeof(entry.pattern)) {
fprintf(stderr,
"globtest: pattern too big on line %d\n",
lineno);
exit(EXIT_FAILURE);
return EXIT_FAILURE;
}
memcpy(entry.pattern, buf + 1, len);
entry.pattern[len] = '\0';
@@ -104,14 +117,14 @@ main(int argc, char **argv)
fprintf(stderr,
"globtest: invalid entry on line %d\n",
lineno);
exit(EXIT_FAILURE);
return EXIT_FAILURE;
}
ep = strchr(cp, '>');
if (ep == NULL) {
fprintf(stderr,
"globtest: invalid entry on line %d\n",
lineno);
exit(EXIT_FAILURE);
return EXIT_FAILURE;
}
*ep = '\0';
entry.flags = 0;
@@ -138,7 +151,7 @@ main(int argc, char **argv)
fprintf(stderr,
"globtest: invalid flags on line %d\n",
lineno);
exit(EXIT_FAILURE);
return EXIT_FAILURE;
}
}
entry.nresults = 0;
@@ -147,27 +160,27 @@ main(int argc, char **argv)
if (!entry.pattern[0]) {
fprintf(stderr, "globtest: missing entry on line %d\n",
lineno);
exit(EXIT_FAILURE);
return EXIT_FAILURE;
}
if (entry.nresults + 1 > MAX_RESULTS) {
fprintf(stderr,
"globtest: too many results for %s, max %d\n",
entry.pattern, MAX_RESULTS);
exit(EXIT_FAILURE);
return EXIT_FAILURE;
}
entry.results[entry.nresults++] = strdup(buf);
}
if (entry.pattern[0]) {
errors += test_glob(&entry); /* test last pattern */
tests++;
ntests++;
}
if (tests != 0) {
if (ntests != 0) {
printf("glob: %d test%s run, %d errors, %d%% success rate\n",
tests, tests == 1 ? "" : "s", errors,
(tests - errors) * 100 / tests);
ntests, ntests == 1 ? "" : "s", errors,
(ntests - errors) * 100 / ntests);
}
exit(errors);
return errors;
}
int test_glob(struct gl_entry *entry)
@@ -179,7 +192,7 @@ int test_glob(struct gl_entry *entry)
if (glob(entry->pattern, entry->flags, NULL, &gl) != 0) {
fprintf(stderr, "glob failed: %s: %s\n", entry->pattern,
strerror(errno));
exit(EXIT_FAILURE);
return 1;
}
for (ap = gl.gl_pathv; *ap != NULL; ap++)

View File

@@ -15,6 +15,7 @@
#include <errno.h>
#include <limits.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
@@ -132,10 +133,23 @@ main(int argc, char *argv[])
char *p;
size_t clen;
long pg;
int i;
int ch, i;
initprogname(argc > 0 ? argv[0] : "mktemp_test");
while ((ch = getopt(argc, argv, "v")) != -1) {
switch (ch) {
case 'v':
/* ignore */
break;
default:
fprintf(stderr, "usage: %s [-v]\n", getprogname());
return EXIT_FAILURE;
}
}
argc -= optind;
argv += optind;
pg = sysconf(_SC_PAGESIZE);
if (getcwd(cwd, sizeof cwd - 1) == NULL)
sudo_fatal("getcwd");

View File

@@ -69,14 +69,28 @@ main(int argc, char *argv[])
{
GETGROUPS_T *gidlist = NULL;
int i, j, errors = 0, ntests = 0;
int ngids;
int ch, ngids;
initprogname(argc > 0 ? argv[0] : "parse_gids_test");
while ((ch = getopt(argc, argv, "v")) != -1) {
switch (ch) {
case 'v':
/* ignore */
break;
default:
fprintf(stderr, "usage: %s [-v]\n", getprogname());
return EXIT_FAILURE;
}
}
argc -= optind;
argv += optind;
for (i = 0; test_data[i].gids != NULL; i++) {
free(gidlist);
ngids = sudo_parse_gids(test_data[i].gids, test_data[i].baseptr, &gidlist);
if (ngids == -1)
exit(EXIT_FAILURE); /* out of memory? */
sudo_fatal_nodebug("sudo_parse_gids");
ntests++;
if (ngids != test_data[i].ngids) {
sudo_warnx_nodebug("test #%d: expected %d gids, got %d",
@@ -101,5 +115,5 @@ main(int argc, char *argv[])
printf("%s: %d tests run, %d errors, %d%% success rate\n",
getprogname(), ntests, errors, (ntests - errors) * 100 / ntests);
}
exit(errors);
return errors;
}

View File

@@ -36,17 +36,31 @@ int
main(int argc, char *argv[])
{
char *progbase = "progname_test";
int ch;
if (argc > 0)
progbase = sudo_basename(argv[0]);
initprogname(progbase);
while ((ch = getopt(argc, argv, "v")) != -1) {
switch (ch) {
case 'v':
/* ignore */
break;
default:
fprintf(stderr, "usage: %s [-v]\n", progbase);
return EXIT_FAILURE;
}
}
argc -= optind;
argv += optind;
/* Make sure getprogname() matches basename of argv[0]. */
if (strcmp(getprogname(), progbase) != 0) {
printf("%s: FAIL: incorrect program name \"%s\"\n",
progbase, getprogname());
exit(EXIT_FAILURE);
return EXIT_FAILURE;
}
exit(EXIT_SUCCESS);
return EXIT_SUCCESS;
}

View File

@@ -288,11 +288,23 @@ void init_sigrt(void)
int
main(int argc, char *argv[])
{
int errors = 0;
int ntests = 0;
int ch, errors = 0, ntests = 0;
initprogname(argc > 0 ? argv[0] : "strsig_test");
while ((ch = getopt(argc, argv, "v")) != -1) {
switch (ch) {
case 'v':
/* ignore */
break;
default:
fprintf(stderr, "usage: %s [-v]\n", getprogname());
return EXIT_FAILURE;
}
}
argc -= optind;
argv += optind;
init_sigrt();
errors += test_sig2str(&ntests);
errors += test_str2sig(&ntests);
@@ -302,5 +314,5 @@ main(int argc, char *argv[])
getprogname(), ntests, errors, (ntests - errors) * 100 / ntests);
}
exit(errors);
return errors;
}

View File

@@ -62,10 +62,24 @@ int
main(int argc, char *argv[])
{
const char *cp, *ep, *input_end;
int i, j, errors = 0, ntests = 0;
int ch, i, j, errors = 0, ntests = 0;
size_t len;
initprogname(argc > 0 ? argv[0] : "strsplit_test");
while ((ch = getopt(argc, argv, "v")) != -1) {
switch (ch) {
case 'v':
/* ignore */
break;
default:
fprintf(stderr, "usage: %s [-v]\n", getprogname());
return EXIT_FAILURE;
}
}
argc -= optind;
argv += optind;
for (i = 0; test_data[i].input != NULL; i++) {
input_end = test_data[i].input + test_data[i].input_len;
cp = sudo_strsplit(test_data[i].input, input_end, " \t", &ep);

View File

@@ -61,12 +61,24 @@ int
main(int argc, char *argv[])
{
struct strtobool_data *d;
int errors = 0;
int ntests = 0;
int value;
int errors = 0, ntests = 0;
int ch, value;
initprogname(argc > 0 ? argv[0] : "strtobool_test");
while ((ch = getopt(argc, argv, "v")) != -1) {
switch (ch) {
case 'v':
/* ignore */
break;
default:
fprintf(stderr, "usage: %s [-v]\n", getprogname());
return EXIT_FAILURE;
}
}
argc -= optind;
argv += optind;
for (d = strtobool_data; d->bool_str != NULL; d++) {
ntests++;
value = sudo_strtobool(d->bool_str);

View File

@@ -56,15 +56,27 @@ static struct strtoidx_data {
int
main(int argc, char *argv[])
{
int ch, errors = 0, ntests = 0;
struct strtoidx_data *d;
const char *errstr;
char *ep;
int errors = 0;
int ntests = 0;
id_t value;
initprogname(argc > 0 ? argv[0] : "strtoid_test");
while ((ch = getopt(argc, argv, "v")) != -1) {
switch (ch) {
case 'v':
/* ignore */
break;
default:
fprintf(stderr, "usage: %s [-v]\n", getprogname());
return EXIT_FAILURE;
}
}
argc -= optind;
argv += optind;
for (d = strtoidx_data; d->idstr != NULL; d++) {
ntests++;
errstr = "some error";

View File

@@ -47,12 +47,24 @@ main(int argc, char *argv[])
{
struct strtomode_data *d;
const char *errstr;
int errors = 0;
int ntests = 0;
int ch, errors = 0, ntests = 0;
mode_t mode;
initprogname(argc > 0 ? argv[0] : "strtomode_test");
while ((ch = getopt(argc, argv, "v")) != -1) {
switch (ch) {
case 'v':
/* ignore */
break;
default:
fprintf(stderr, "usage: %s [-v]\n", getprogname());
return EXIT_FAILURE;
}
}
argc -= optind;
argv += optind;
for (d = strtomode_data; d->mode_str != NULL; d++) {
ntests++;
errstr = "some error";

View File

@@ -78,14 +78,26 @@ static struct strtonum_data {
int
main(int argc, char *argv[])
{
int ch, errors = 0, ntests = 0;
struct strtonum_data *d;
const char *errstr;
int errors = 0;
int ntests = 0;
long long value;
initprogname(argc > 0 ? argv[0] : "strtonum_test");
while ((ch = getopt(argc, argv, "v")) != -1) {
switch (ch) {
case 'v':
/* ignore */
break;
default:
fprintf(stderr, "usage: %s [-v]\n", getprogname());
return EXIT_FAILURE;
}
}
argc -= optind;
argv += optind;
for (d = strtonum_data; d->str != NULL; d++) {
ntests++;
errstr = "some error";

View File

@@ -37,6 +37,13 @@ sudo_dso_public int main(int argc, char *argv[]);
# define GROUP_SOURCE_ADAPTIVE GROUP_SOURCE_DYNAMIC
#endif
static void
usage(void)
{
fprintf(stderr, "usage: %s [-v] conf_file\n", getprogname());
exit(EXIT_FAILURE);
}
/*
* Simple test driver for sudo_conf().
* Parses the given configuration file and dumps the resulting
@@ -45,17 +52,31 @@ sudo_dso_public int main(int argc, char *argv[]);
int
main(int argc, char *argv[])
{
int ch;
initprogname(argc > 0 ? argv[0] : "conf_test");
if (argc != 2) {
fprintf(stderr, "usage: %s conf_file\n", getprogname());
exit(EXIT_FAILURE);
while ((ch = getopt(argc, argv, "v")) != -1) {
switch (ch) {
case 'v':
/* ignore */
break;
default:
usage();
}
}
argc -= optind;
argv += optind;
if (argc != 1)
usage();
sudo_conf_clear_paths();
if (sudo_conf_read(argv[1], SUDO_CONF_ALL) == -1)
exit(EXIT_FAILURE);
if (sudo_conf_read(argv[0], SUDO_CONF_ALL) == -1)
return EXIT_FAILURE;
sudo_conf_dump();
exit(EXIT_SUCCESS);
return EXIT_SUCCESS;
}
static void

View File

@@ -39,11 +39,25 @@ main(int argc, char *argv[])
unsigned int lineno = 0;
size_t linesize = 0;
char *line = NULL;
int ch;
initprogname(argc > 0 ? argv[0] : "parseln_test");
while ((ch = getopt(argc, argv, "v")) != -1) {
switch (ch) {
case 'v':
/* ignore */
break;
default:
fprintf(stderr, "usage: %s [-v]\n", getprogname());
return EXIT_FAILURE;
}
}
argc -= optind;
argv += optind;
while (sudo_parseln(&line, &linesize, &lineno, stdin, 0) != -1)
printf("%6u\t%s\n", lineno, line);
free(line);
exit(EXIT_SUCCESS);
return EXIT_SUCCESS;
}

View File

@@ -51,11 +51,23 @@ main(int argc, char *argv[])
struct test_data d1, d2, d3;
struct test_data *hltq;
struct test_data_list tq;
int errors = 0;
int ntests = 0;
int ch, errors = 0, ntests = 0;
initprogname(argc > 0 ? argv[0] : "hltq_test");
while ((ch = getopt(argc, argv, "v")) != -1) {
switch (ch) {
case 'v':
/* ignore */
break;
default:
fprintf(stderr, "usage: %s [-v]\n", getprogname());
return EXIT_FAILURE;
}
}
argc -= optind;
argv += optind;
/*
* Initialize three data elements and concatenate them in order.
*/

View File

@@ -51,15 +51,27 @@ struct uuid {
int
main(int argc, char *argv[])
{
int ch, errors = 0, ntests = 0;
union {
struct uuid id;
unsigned char u8[16];
} uuid;
int errors = 0;
int ntests = 0;
initprogname(argc > 0 ? argv[0] : "uuid_test");
while ((ch = getopt(argc, argv, "v")) != -1) {
switch (ch) {
case 'v':
/* ignore */
break;
default:
fprintf(stderr, "usage: %s [-v]\n", getprogname());
return EXIT_FAILURE;
}
}
argc -= optind;
argv += optind;
/* Do 16 passes. */
for (ntests = 0; ntests < 16; ntests++) {
sudo_uuid_create(uuid.u8);
@@ -88,5 +100,5 @@ main(int argc, char *argv[])
printf("%s: %d tests run, %d errors, %d%% success rate\n",
getprogname(), ntests, errors, (ntests - errors) * 100 / ntests);
}
return 0;
return errors;
}