Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/npf/npftest Add two new command line options to hel...



details:   https://anonhg.NetBSD.org/src/rev/29357e5377b3
branches:  trunk
changeset: 781514:29357e5377b3
user:      martin <martin%NetBSD.org@localhost>
date:      Wed Sep 12 08:47:14 2012 +0000

description:
Add two new command line options to help integration into ATF:
-L lists the available test cases, -T executes a single named test.

diffstat:

 usr.sbin/npf/npftest/npftest.c |  85 ++++++++++++++++++++++++++++++++---------
 1 files changed, 66 insertions(+), 19 deletions(-)

diffs (155 lines):

diff -r f306f12b08cb -r 29357e5377b3 usr.sbin/npf/npftest/npftest.c
--- a/usr.sbin/npf/npftest/npftest.c    Wed Sep 12 02:00:51 2012 +0000
+++ b/usr.sbin/npf/npftest/npftest.c    Wed Sep 12 08:47:14 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: npftest.c,v 1.6 2012/08/21 20:52:11 rmind Exp $        */
+/*     $NetBSD: npftest.c,v 1.7 2012/09/12 08:47:14 martin Exp $       */
 
 /*
  * NPF testing framework.
@@ -29,19 +29,37 @@
 static void
 usage(void)
 {
-       printf("usage: %s: [ -q | -v ] [ -c <config> ] "
-           "[ -i <interface> ] < -b | -t | -s file >\n"
+       printf("usage:\n"
+           "  %s [ -q | -v ] [ -c <config> ] "
+               "[ -i <interface> ] < -b | -t | -s file >\n"
+           "  %s -T <testname> -c <config>\n"
+           "  %s -L\n"
+           "where:\n"
            "\t-b: benchmark\n"
            "\t-t: regression test\n"
+           "\t-T <testname>: specific test\n"
            "\t-s <file>: pcap stream\n"
            "\t-c <config>: NPF configuration file\n"
            "\t-i <interface>: primary interface\n"
+           "\t-L: list testnames and description for -T\n"
            "\t-q: quiet mode\n"
            "\t-v: verbose mode\n",
-           getprogname());
+           getprogname(), getprogname(), getprogname());
        exit(EXIT_FAILURE);
 }
 
+static void
+describe_tests(void)
+{
+       printf( "nbuf\tbasic npf mbuf handling\n"
+               "processor\tncode processing\n"
+               "table\ttable handling\n"
+               "state\tstate handling and processing\n"
+               "rule\trule processing\n"
+               "nat\tNAT rule processing\n");
+       exit(EXIT_SUCCESS);
+}
+
 static bool
 result(const char *testcase, bool ok)
 {
@@ -119,13 +137,15 @@
 int
 main(int argc, char **argv)
 {
-       bool benchmark, test, ok, fail;
-       char *config, *interface, *stream;
+       bool benchmark, test, ok, fail, tname_matched;
+       char *config, *interface, *stream, *testname;
        int idx = -1, ch;
 
        benchmark = false;
        test = false;
 
+       tname_matched = false;
+       testname = NULL;
        config = NULL;
        interface = NULL;
        stream = NULL;
@@ -133,7 +153,7 @@
        verbose = false;
        quiet = false;
 
-       while ((ch = getopt(argc, argv, "bqvc:i:s:t")) != -1) {
+       while ((ch = getopt(argc, argv, "bqvc:i:s:tT:L")) != -1) {
                switch (ch) {
                case 'b':
                        benchmark = true;
@@ -156,6 +176,12 @@
                case 't':
                        test = true;
                        break;
+               case 'T':
+                       test = true;
+                       testname = optarg;
+                       break;
+               case 'L':
+                       describe_tests();
                default:
                        usage();
                }
@@ -189,25 +215,43 @@
        fail = false;
 
        if (test) {
-               ok = rumpns_npf_nbuf_test(verbose);
-               fail |= result("nbuf", ok);
+               if (!testname || strcmp("nbuf", testname) == 0) {
+                       ok = rumpns_npf_nbuf_test(verbose);
+                       fail |= result("nbuf", ok);
+                       tname_matched = true;
+               }
 
-               ok = rumpns_npf_processor_test(verbose);
-               fail |= result("processor", ok);
+               if (!testname || strcmp("processor", testname) == 0) {
+                       ok = rumpns_npf_processor_test(verbose);
+                       fail |= result("processor", ok);
+                       tname_matched = true;
+               }
 
-               ok = rumpns_npf_table_test(verbose);
-               fail |= result("table", ok);
+               if (!testname || strcmp("table", testname) == 0) {
+                       ok = rumpns_npf_table_test(verbose);
+                       fail |= result("table", ok);
+                       tname_matched = true;
+               }
 
-               ok = rumpns_npf_state_test(verbose);
-               fail |= result("state", ok);
+               if (!testname || strcmp("state", testname) == 0) {
+                       ok = rumpns_npf_state_test(verbose);
+                       fail |= result("state", ok);
+                       tname_matched = true;
+               }
        }
 
        if (test && config) {
-               ok = rumpns_npf_rule_test(verbose);
-               fail |= result("rule", ok);
+               if (!testname || strcmp("rule", testname) == 0) {
+                       ok = rumpns_npf_rule_test(verbose);
+                       fail |= result("rule", ok);
+                       tname_matched = true;
+               }
 
-               ok = rumpns_npf_nat_test(verbose);
-               fail |= result("nat", ok);
+               if (!testname || strcmp("nat", testname) == 0) {
+                       ok = rumpns_npf_nat_test(verbose);
+                       fail |= result("nat", ok);
+                       tname_matched = true;
+               }
        }
 
        if (stream) {
@@ -216,5 +260,8 @@
 
        rump_unschedule();
 
+       if (testname && !tname_matched)
+               errx(EXIT_FAILURE, "test \"%s\" unknown", testname);
+
        return fail ? EXIT_FAILURE : EXIT_SUCCESS;
 }



Home | Main Index | Thread Index | Old Index