Deleted Added
full compact
29c29
< __FBSDID("$FreeBSD: head/tools/regression/lib/libc/nss/test-getrpc.c 291363 2015-11-26 08:58:13Z ngie $");
---
> __FBSDID("$FreeBSD: head/lib/libc/tests/nss/getrpc_test.c 292323 2015-12-16 08:09:03Z ngie $");
33d32
< #include <assert.h>
39a39,41
>
> #include <atf-c.h>
>
50,52d51
< static int debug = 0;
< static enum test_methods method = TEST_BUILD_SNAPSHOT;
<
84,85c83,84
< assert(dest != NULL);
< assert(src != NULL);
---
> ATF_REQUIRE(dest != NULL);
> ATF_REQUIRE(src != NULL);
94c93
< assert(dest->r_name != NULL);
---
> ATF_REQUIRE(dest->r_name != NULL);
104,106c103,104
< dest->r_aliases = (char **)malloc((aliases_num+1) * (sizeof(char *)));
< assert(dest->r_aliases != NULL);
< memset(dest->r_aliases, 0, (aliases_num+1) * (sizeof(char *)));
---
> dest->r_aliases = calloc(1, (aliases_num + 1) * sizeof(char *));
> ATF_REQUIRE(dest->r_aliases != NULL);
110c108
< assert(dest->r_aliases[cp - src->r_aliases] != NULL);
---
> ATF_REQUIRE(dest->r_aliases[cp - src->r_aliases] != NULL);
120c118
< assert(rpc != NULL);
---
> ATF_REQUIRE(rpc != NULL);
160c158
< if ((debug) && (mdata == NULL)) {
---
> if (mdata == NULL) {
207,208c205
< if (debug)
< printf("1 line read from snapshot:\n%s\n", line);
---
> printf("1 line read from snapshot:\n%s\n", line);
214c211
< while ( (s = strsep(&ps, " ")) != NULL) {
---
> while ((s = strsep(&ps, " ")) != NULL) {
216c213
< case 0:
---
> case 0:
218c215
< assert(rpc->r_name != NULL);
---
> ATF_REQUIRE(rpc->r_name != NULL);
221,226c218,223
< case 1:
< rpc->r_number = (int)strtol(s, &ts, 10);
< if (*ts != '\0') {
< free(rpc->r_name);
< return (-1);
< }
---
> case 1:
> rpc->r_number = (int)strtol(s, &ts, 10);
> if (*ts != '\0') {
> free(rpc->r_name);
> return (-1);
> }
229,232c226,229
< default:
< if (sl == NULL) {
< if (strcmp(s, "(null)") == 0)
< return (0);
---
> default:
> if (sl == NULL) {
> if (strcmp(s, "(null)") == 0)
> return (0);
234,235c231,232
< sl = sl_init();
< assert(sl != NULL);
---
> sl = sl_init();
> ATF_REQUIRE(sl != NULL);
237,242c234
< if (strcmp(s, "noaliases") != 0) {
< ts = strdup(s);
< assert(ts != NULL);
< sl_add(sl, ts);
< }
< } else {
---
> if (strcmp(s, "noaliases") != 0) {
244c236
< assert(ts != NULL);
---
> ATF_REQUIRE(ts != NULL);
246a239,243
> } else {
> ts = strdup(s);
> ATF_REQUIRE(ts != NULL);
> sl_add(sl, ts);
> }
248,249c245,246
< };
< ++i;
---
> }
> i++;
297,300d293
< if (debug) {
< printf("testing correctness with the following data:\n");
< dump_rpcent(rpc);
< }
301a295,297
> printf("testing correctness with the following data:\n");
> dump_rpcent(rpc);
>
314,315c310
< if (debug)
< printf("correct\n");
---
> printf("correct\n");
319,320c314
< if (debug)
< printf("incorrect\n");
---
> printf("incorrect\n");
344,347c338,339
< if (debug) {
< printf("testing getrpcbyname() with the following data:\n");
< dump_rpcent(rpc_model);
< }
---
> printf("testing getrpcbyname() with the following data:\n");
> dump_rpcent(rpc_model);
370,371c362
< if (debug)
< printf("ok\n");
---
> printf("ok\n");
375,376c366
< if (debug)
< printf("not ok\n");
---
> printf("not ok\n");
386,389c376,377
< if (debug) {
< printf("testing getrpcbyport() with the following data...\n");
< dump_rpcent(rpc_model);
< }
---
> printf("testing getrpcbyport() with the following data...\n");
> dump_rpcent(rpc_model);
392,396c380,383
< if ((rpcent_test_correctness(rpc, NULL) != 0) ||
< ((compare_rpcent(rpc, rpc_model, NULL) != 0) &&
< (rpcent_check_ambiguity((struct rpcent_test_data *)mdata, rpc)
< != 0))) {
< if (debug)
---
> if (rpcent_test_correctness(rpc, NULL) != 0 ||
> (compare_rpcent(rpc, rpc_model, NULL) != 0 &&
> rpcent_check_ambiguity((struct rpcent_test_data *)mdata, rpc)
> != 0)) {
398c385
< return (-1);
---
> return (-1);
400d386
< if (debug)
402c388
< return (0);
---
> return (0);
409,410c395,399
< /* Only correctness can be checked when doing 1-pass test for
< * getrpcent(). */
---
>
> /*
> * Only correctness can be checked when doing 1-pass test for
> * getrpcent().
> */
414,422d402
< static void
< usage(void)
< {
< (void)fprintf(stderr,
< "Usage: %s -nve2 [-d] [-s <file>]\n",
< getprogname());
< exit(1);
< }
<
424c404
< main(int argc, char **argv)
---
> run_tests(const char *snapshot_file, enum test_methods method)
427d406
< char *snapshot_file;
429d407
< int c;
431,458d408
< if (argc < 2)
< usage();
<
< snapshot_file = NULL;
< while ((c = getopt(argc, argv, "nve2ds:")) != -1)
< switch (c) {
< case 'd':
< debug++;
< break;
< case 'n':
< method = TEST_GETRPCBYNAME;
< break;
< case 'v':
< method = TEST_GETRPCBYNUMBER;
< break;
< case 'e':
< method = TEST_GETRPCENT;
< break;
< case '2':
< method = TEST_GETRPCENT_2PASS;
< break;
< case 's':
< snapshot_file = strdup(optarg);
< break;
< default:
< usage();
< }
<
466,468c416,417
< if (debug)
< printf("can't access the file %s\n",
< snapshot_file);
---
> printf("can't access the file %s\n",
> snapshot_file);
528c477
< };
---
> }
533c482
< free(snapshot_file);
---
>
535a485,560
>
> #define SNAPSHOT_FILE "snapshot_rpc"
>
> ATF_TC_WITHOUT_HEAD(build_snapshot);
> ATF_TC_BODY(build_snapshot, tc)
> {
>
> ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_BUILD_SNAPSHOT) == 0);
> }
>
> ATF_TC_WITHOUT_HEAD(getrpcbyname);
> ATF_TC_BODY(getrpcbyname, tc)
> {
>
> ATF_REQUIRE(run_tests(NULL, TEST_GETRPCBYNAME) == 0);
> }
>
> ATF_TC_WITHOUT_HEAD(getrpcbyname_with_snapshot);
> ATF_TC_BODY(getrpcbyname_with_snapshot, tc)
> {
>
> ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_BUILD_SNAPSHOT) == 0);
> ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_GETRPCBYNAME) == 0);
> }
>
> ATF_TC_WITHOUT_HEAD(getrpcbynumber);
> ATF_TC_BODY(getrpcbynumber, tc)
> {
>
> ATF_REQUIRE(run_tests(NULL, TEST_GETRPCBYNUMBER) == 0);
> }
>
> ATF_TC_WITHOUT_HEAD(getrpcbynumber_with_snapshot);
> ATF_TC_BODY(getrpcbynumber_with_snapshot, tc)
> {
>
> ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_BUILD_SNAPSHOT) == 0);
> ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_GETRPCBYNUMBER) == 0);
> }
>
> ATF_TC_WITHOUT_HEAD(getrpcbyent);
> ATF_TC_BODY(getrpcbyent, tc)
> {
>
> ATF_REQUIRE(run_tests(NULL, TEST_GETRPCENT) == 0);
> }
>
> ATF_TC_WITHOUT_HEAD(getrpcbyent_with_snapshot);
> ATF_TC_BODY(getrpcbyent_with_snapshot, tc)
> {
>
> ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_BUILD_SNAPSHOT) == 0);
> ATF_REQUIRE(run_tests(SNAPSHOT_FILE, TEST_GETRPCENT) == 0);
> }
>
> ATF_TC_WITHOUT_HEAD(getrpcbyent_with_two_pass);
> ATF_TC_BODY(getrpcbyent_with_two_pass, tc)
> {
>
> ATF_REQUIRE(run_tests(NULL, TEST_GETRPCENT_2PASS) == 0);
> }
>
> ATF_TP_ADD_TCS(tp)
> {
>
> ATF_TP_ADD_TC(tp, build_snapshot);
> ATF_TP_ADD_TC(tp, getrpcbyname);
> ATF_TP_ADD_TC(tp, getrpcbyname_with_snapshot);
> ATF_TP_ADD_TC(tp, getrpcbynumber);
> ATF_TP_ADD_TC(tp, getrpcbynumber_with_snapshot);
> ATF_TP_ADD_TC(tp, getrpcbyent);
> ATF_TP_ADD_TC(tp, getrpcbyent_with_snapshot);
> ATF_TP_ADD_TC(tp, getrpcbyent_with_two_pass);
>
> return (atf_no_error());
> }