tests: fix error reporting
PATCH 1/3 tests: fix error reporting
The testbench was not reporting errors properly.
With this patch, "1" is returned to the shell if the test failed (instead of returning "0" unconditionally). Textual reporting is also fixed.
In case of compilation without some parsing support, returning error (i.e 1) is the expected behaviour.
---
0 files changed
tests/nft-parsing-test.c +48 -39
@@ -50,23 +50,23 @@ static void print_detail_error(char *a, char *b)if (k <0 ) k =0 ; -fprintf (stderr,"from file: " ); +printf ("\nfrom file: " );for (i = k; i < from +10 ; i++) -fprintf (stderr,"%c" , a[i]); +printf ("%c" , a[i]); -fprintf (stderr,"\nfrom snprintf: " ); +printf ("\nfrom snprintf: " );for (i = k; i < from +10 ; i++) -fprintf (stderr,"%c" , b[i]); +printf ("%c" , b[i]);/* Don't look twice below this comment ;-) */ -fprintf (stderr,"\n " ); +printf ("\n " );for (i = k; i < from +10 ; i++) {if (i == from) -fprintf (stderr,"^" ); +printf ("^" );else -fprintf (stderr," " ); +printf (" " ); } -fprintf (stderr,"\n" ); +printf ("\n" ); } }
@@ -144,8 +144,7 @@ static int compare_test(uint32_t type, void *input, const char *filename)if (strncmp (orig, out,strlen (out)) ==0 )return 0 ; -printf ("validating %s: " , filename); -printf ("\033[31mFAILED\e[0m\n" ); + errno =EBADMSG ;print_detail_error (orig, out);return -1 ; }
@@ -177,7 +176,7 @@ static int test_json(const char *filename)if (nft_table_parse (t,NFT_TABLE_PARSE_JSON , json) ==0 ) ret =compare_test (TEST_JSON_TABLE , t, filename);else - goto failparsing; + ret =-1 ;nft_table_free (t); }
@@ -187,7 +186,7 @@ static int test_json(const char *filename)if (nft_chain_parse (c,NFT_CHAIN_PARSE_JSON , json) ==0 ) ret =compare_test (TEST_JSON_CHAIN , c, filename);else - goto failparsing; + ret =-1 ;nft_chain_free (c); }
@@ -197,7 +196,7 @@ static int test_json(const char *filename)if (nft_rule_parse (r,NFT_RULE_PARSE_JSON , json) ==0 ) ret =compare_test (TEST_JSON_RULE , r, filename);else - goto failparsing; + ret =-1 ;nft_rule_free (r); }
@@ -207,7 +206,7 @@ static int test_json(const char *filename)if (nft_set_parse (s,NFT_SET_PARSE_JSON , json) ==0 ) ret =compare_test (TEST_JSON_SET , s, filename);else - goto failparsing; + ret =-1 ;nft_set_free (s); }
@@ -216,13 +215,6 @@ static int test_json(const char *filename)free (json);json_decref (root);return ret; - -failparsing: -printf ("parsing %s: " , filename); -printf ("\033[31mFAILED\e[0m (%s)\n" ,strerror (errno)); -free (json); -json_decref (root); -return -1 ;#else errno =EOPNOTSUPP ;return -1 ;
@@ -245,12 +237,16 @@ static int test_xml(const char *filename) tree =mxmlLoadFile (NULL , fp,MXML_NO_CALLBACK );fclose (fp); -if (tree ==NULL ) +if (tree ==NULL ) { +printf ("Unable to build XML tree." );return -1 ; + } xml =mxmlSaveAllocString (tree,MXML_NO_CALLBACK ); -if (xml ==NULL ) +if (xml ==NULL ) { +printf ("Unable to save alloc string from XML tree." );return -1 ; + }/* Check what parsing should be done */ if (strcmp (tree->value.opaque,"table" ) ==0 ) {
@@ -259,7 +255,7 @@ static int test_xml(const char *filename)if (nft_table_parse (t,NFT_TABLE_PARSE_XML , xml) ==0 ) ret =compare_test (TEST_XML_TABLE , t, filename);else - goto failparsing; + ret =-1 ;nft_table_free (t); }
@@ -269,7 +265,7 @@ static int test_xml(const char *filename)if (nft_chain_parse (c,NFT_CHAIN_PARSE_XML , xml) ==0 ) ret =compare_test (TEST_XML_CHAIN , c, filename);else - goto failparsing; + ret =-1 ;nft_chain_free (c); }
@@ -279,7 +275,7 @@ static int test_xml(const char *filename)if (nft_rule_parse (r,NFT_RULE_PARSE_XML , xml) ==0 ) ret =compare_test (TEST_XML_RULE , r, filename);else - goto failparsing; + ret =-1 ;nft_rule_free (r); }
@@ -289,18 +285,14 @@ static int test_xml(const char *filename)if (nft_set_parse (s,NFT_SET_PARSE_XML , xml) ==0 ) ret =compare_test (TEST_XML_SET , s, filename);else - goto failparsing; + ret =-1 ; nft_set_free(s); } } +free (xml);return ret; - -failparsing: -printf ("parsing %s: " , filename); -printf ("\033[31mFAILED\e[0m (%s)\n" ,strerror (errno)); -return -1 ;#else errno =EOPNOTSUPP ;return -1 ;
@@ -309,6 +301,7 @@ failparsing:int main (int argc,char *argv[]) { +int exit_code =0 , ret;DIR *d;struct dirent *dent;char path[PATH_MAX ];
@@ -334,19 +327,35 @@ int main(int argc, char *argv[])snprintf (path,sizeof (path),"%s/%s" , argv[1 ], dent->d_name);if (strcmp (&dent->d_name[len-4 ],".xml" ) ==0 ) { -if (test_xml (path) ==0 ) { -printf ("parsing and validating %s: " , path); + +printf ("parsing and validating %s: " , path); + +if ((ret =test_xml (path)) ==0 )printf ("\033[32mOK\e[0m\n" ); - } +else +printf ("\033[31mFAILED\e[0m (%s)\n" , +strerror (errno)); + + exit_code += ret; }if (strcmp (&dent->d_name[len-5 ],".json" ) ==0 ) { -if (test_json (path) ==0 ) { -printf ("parsing and validating %s: " , path); + +printf ("parsing and validating %s: " , path); + +if ((ret =test_json (path)) ==0 )printf ("\033[32mOK\e[0m\n" ); - } +else +printf ("\033[31mFAILED\e[0m (%s)\n" , +strerror (errno)); + + exit_code += ret; } }closedir (d); -return 0 ; + +if (exit_code ==0 ) +exit (EXIT_SUCCESS ); +else +exit (EXIT_FAILURE ); }
PATCH 2/3 table: json: fix json style
Be consistent in JSON style.
---
0 files changed
src/table.c +1 -1
@@ -349,7 +349,7 @@ EXPORT_SYMBOL(nft_table_parse);static int nft_table_snprintf_json (char *buf,size_t size,struct nft_table *t) {return snprintf (buf, size, -"{\"table\" : {" +"{ \"table\" : {" "\"name\" : \"%s\"," "\"family\" : \"%s\"," "\"flags\" : %d"
tests/jsonfiles/01-table.json +1 -1
@@ -1 +1 @@ -{"table" : {"name" : "filter","family" : "ip","flags" : 0}} +{ "table" : {"name" : "filter","family" : "ip","flags" : 0}}
tests/jsonfiles/02-table.json +1 -1
@@ -1 +1 @@ -{"table" : {"name" : "filter2","family" : "ip6","flags" : 0}} +{ "table" : {"name" : "filter2","family" : "ip6","flags" : 0}}
Pablo Neira Ayuso
maintainerRe: [libnftables PATCH 2/3] table: json: fix json style
Quoted 1 line · Arturo Borrero Gonzalez
Be consistent in JSON style.
I prefer if you rewiew the entire output and you perform all this consistency fixes in one patch.
The description should what policy you have following to fix the style.
Re: [libnftables PATCH 2/3] table: json: fix json style
In reply to Arturo Borrero GonzalezQuoted 3 lines · On Mon, 30 Sep 2013 17:05:57 +0200 Arturo Borrero Gonzalez…
Be consistent in JSON style.
Signed-off-by Arturo Borrero Gonzalez <[email protected]>
All the effort to format and add whitespace in JSON is not that important since it is intended to be parsed by something, and parsers ignore it. Many applications just use as little whitespace as possible to reduce size of output!
Pablo Neira Ayuso
maintainerRe: [libnftables PATCH 2/3] table: json: fix json style
Quoted 11 lines · Stephen Hemminger
Quoted 3 lines · On Mon, 30 Sep 2013 17:05:57 +0200 Arturo Borrero Gonzalez…
Be consistent in JSON style.
Signed-off-by Arturo Borrero Gonzalez <[email protected]>All the effort to format and add whitespace in JSON is not that important since it is intended to be parsed by something, and parsers ignore it. Many applications just use as little whitespace as possible to reduce size of output!
Thanks Stephen, we'll stick to using as little whitespace as possible.
Moreover, there are tools and functions (included in libjansson) to make this human friendly, in case anyone needs it.
Re: [libnftables PATCH 2/3] table: json: fix json style
Quoted 13 lines · Pablo Neira Ayuso
Quoted 11 lines · Stephen Hemminger
Quoted 3 lines · On Mon, 30 Sep 2013 17:05:57 +0200 Arturo Borrero Gonzalez…
Be consistent in JSON style.
Signed-off-by Arturo Borrero Gonzalez <[email protected]>All the effort to format and add whitespace in JSON is not that important since it is intended to be parsed by something, and parsers ignore it. Many applications just use as little whitespace as possible to reduce size of output!
Quoted 4 lines
Thanks Stephen, we'll stick to using as little whitespace as possible.
Moreover, there are tools and functions (included in libjansson) to make this human friendly, in case anyone needs it.
I also don't care so much about the format, actually (white spaces or not..). I just tried to give some consistency.
{ \"rule\":
{ \"chain\":
{ \"set\":
{\"table\" :
I did not notice other inconsistencies in order to make a patch fixing all of them. Maybe Alvaro knows others.
Signature · 5 lines
Arturo Borrero González -- To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Pablo Neira Ayuso
maintainerRe: [libnftables PATCH 2/3] table: json: fix json style
Quoted 19 lines · Arturo Borrero Gonzalez
Quoted 13 lines · Pablo Neira Ayuso
Quoted 11 lines · Stephen Hemminger
Quoted 3 lines · On Mon, 30 Sep 2013 17:05:57 +0200 Arturo Borrero Gonzalez…
Be consistent in JSON style.
Signed-off-by Arturo Borrero Gonzalez <[email protected]>All the effort to format and add whitespace in JSON is not that important since it is intended to be parsed by something, and parsers ignore it. Many applications just use as little whitespace as possible to reduce size of output!
Quoted 4 lines
Thanks Stephen, we'll stick to using as little whitespace as possible.
Moreover, there are tools and functions (included in libjansson) to make this human friendly, in case anyone needs it.
Quoted 7 lines
I also don't care so much about the format, actually (white spaces or not..). I just tried to give some consistency.
{ \"rule\":
{ \"chain\":
{ \"set\":
{\"table\" :
For consistency, please send me a patch to remove the spaces. Thanks!
PATCH 3/3 src: add low-level ruleset API
In reply to Arturo Borrero GonzalezThis patch adds a low level ruleset API for libnftables.
---
0 files changed
include/libnftables/Makefile.am +2 -1
@@ -2,4 +2,5 @@ pkginclude_HEADERS = table.h \ chain.h \ rule.h \ expr.h \ - set.h + set.h \ + ruleset.h
include/libnftables/ruleset.h new file +45 -0
45 lines not on this page · raw message
src/Makefile.am +1 -0
@@ -10,6 +10,7 @@ libnftables_la_SOURCES = utils.c \ rule.c \ set.c \ set_elem.c \ + ruleset.c \ mxml.c \ jansson.c \ expr.c \
src/chain.c +1 -1
@@ -506,7 +506,7 @@ static inline int nft_str2hooknum(int family, const char *hook) }#ifdef JSON_PARSING -static int nft_jansson_parse_chain (struct nft_chain *c,json_t *tree) +int nft_jansson_parse_chain (struct nft_chain *c,json_t *tree) {json_t *root;uint64_t uval64;
src/internal.h +8 -0
@@ -71,6 +71,14 @@ int nft_jansson_data_reg_parse(json_t *root, const char *tag, union nft_data_reg *data_reg);struct nft_set_elem ;int nft_set_elem_json_parse (struct nft_set_elem *e,json_t *root); +struct nft_table ; +int nft_jansson_parse_table (struct nft_table *t,json_t *tree); +struct nft_chain ; +int nft_jansson_parse_chain (struct nft_chain *c,json_t *tree); +struct nft_rule ; +int nft_jansson_parse_rule (struct nft_rule *r,json_t *tree); +struct nft_set ; +int nft_jansson_parse_set (struct nft_set *s,json_t *tree);#endif const char *nft_family2str (uint32_t family);
src/libnftables.map +9 -0
@@ -168,5 +168,14 @@ global: nft_set_elems_iter_next; nft_set_elems_iter_destroy; + nft_ruleset_alloc; + nft_ruleset_free; + nft_ruleset_attr_is_set; + nft_ruleset_attr_unset; + nft_ruleset_attr_set; + nft_ruleset_attr_get; + nft_ruleset_parse; + nft_ruleset_snprintf; + local: *; };
src/rule.c +1 -1
@@ -470,7 +470,7 @@ int nft_rule_nlmsg_parse(const struct nlmsghdr *nlh, struct nft_rule *r)EXPORT_SYMBOL (nft_rule_nlmsg_parse);#ifdef JSON_PARSING -static int nft_jansson_parse_rule (struct nft_rule *r,json_t *tree) +int nft_jansson_parse_rule (struct nft_rule *r,json_t *tree) {json_t *root, *array;struct nft_rule_expr *e;
src/ruleset.c new file +813 -0
813 lines not on this page · raw message
src/set.c +1 -1
@@ -304,7 +304,7 @@ int nft_set_nlmsg_parse(const struct nlmsghdr *nlh, struct nft_set *s)EXPORT_SYMBOL (nft_set_nlmsg_parse);#ifdef JSON_PARSING -static int nft_jansson_parse_set (struct nft_set *s,json_t *tree) +int nft_jansson_parse_set (struct nft_set *s,json_t *tree) {json_t *root, *array, *json_elem;uint32_t uval32;
src/table.c +1 -1
@@ -272,7 +272,7 @@ static int nft_table_xml_parse(struct nft_table *t, const char *xml) }#ifdef JSON_PARSING -static int nft_jansson_parse_table (struct nft_table *t,json_t *tree) +int nft_jansson_parse_table (struct nft_table *t,json_t *tree) {json_t *root;uint32_t flags;
tests/jsonfiles/64-ruleset.json new file +1 -0
@@ -0,0 +1,2 @@ +{ "nftables": [{ "table" : {"name" : "filter","family" : "ip","flags" : 0}},{ "table" : {"name" : "filter2","family" : "ip6","flags" : 0}},{ "chain": {"name": "input","handle": 1,"bytes": 10681449,"packets": 16216,"family": "ip","table": "filter","use": 0,"type": "filter","hooknum": "input","prio": 0,"policy": "accept"}},{ "chain": {"name": "forward","handle": 2,"bytes": 0,"packets": 0,"family": "ip","table": "filter","use": 0,"type": "filter","hooknum": "forward","prio": 0,"policy": "accept"}},{ "chain": {"name": "output","handle": 3,"bytes": 2375830,"packets": 15184,"family": "ip","table": "filter","use": 0,"type": "filter","hooknum": "output","prio": 0,"policy": "accept"}},{ "chain": {"name": "chain1","handle": 4,"bytes": 0,"packets": 0,"family": "ip","table": "filter","use": 0}},{ "se
t": { "name": "set0","table": "filter","flags": 3,"family": "ip","key_type": 12,"key_len": 2}},{ "rule": { "family" : "ip", "table" : "filter", "chain" : "output", "handle" : 6,"flags" : 0,
"expr" : [ { "type" : "payload", "dreg" : 1, "offset" : 16, "len" : 4, "base" : "link"}, { "type" : "cmp", "sreg" : 1, "op" : "eq", "cmpdata" : {"data_reg": { "type" : "value", "len" : 4, "data0" : "0x0100a8c0"}}}, { "type" : "counter", "pkts" : 0, "bytes" : 0}, { "type" : "immediate", "dreg" : 0, "immediatedata" : {"data_reg": {"type" : "verdict", "verdict" : "drop"}}}]}},{ "rule": { "family" : "ip", "table" : "filter", "chain" : "output", "handle" : 9,"flags" : 0, "expr" : [ { "type" : "payload", "dreg" : 1, "offset" : 9, "len" : 1, "base" : "link"}, { "type" : "cmp", "sreg" : 1, "op" : "eq", "cmpdata" : {"data_reg": { "type" : "value", "len" : 1, "data0" : "0x00000006"}}}, { "type" : "payload", "dreg" : 1, "offset" : 2, "len" : 2, "base" : "link"}, { "type" : "cmp", "sreg" : 1, "op"
: "eq", "cmpdata" : {"data_reg": { "type" : "value", "len" : 2, "data0" : "0x00001600"}}}, { "type" : "counter", "pkts" : 0, "bytes" : 0}]}},{ "rule": { "family" : "ip", "table" : "filter",
"chain" : "output", "handle" : 10,"flags" : 0, "expr" : [ { "type" : "payload", "dreg" : 1, "offset" : 16, "len" : 4, "base" : "link"}, { "type" : "cmp", "sreg" : 1, "op" : "eq", "cmpdata" : {"data_reg": { "type" : "value", "len" : 4, "data0" : "0x0100a8c0"}}}, { "type" : "counter", "pkts" : 0, "bytes" : 0}]}},{ "rule": { "family" : "ip", "table" : "filter", "chain" : "output", "handle" : 11,"flags" : 0, "expr" : [ { "type" : "payload", "dreg" : 1, "offset" : 16, "len" : 4, "base" : "link"}, { "type" : "cmp", "sreg" : 1, "op" : "eq", "cmpdata" : {"data_reg": { "type" : "value", "len" : 4, "data0" : "0x0100a8c0"}}}, { "type" : "counter", "pkts" : 0, "bytes" : 0}, { "type" : "immediate", "dreg" : 0, "immediatedata" : {"data_reg": {"type" : "verdict", "verdict" : "drop"}}}]}}]}
+
tests/nft-parsing-test.c +45 -2
125 lines not on this page · raw message
tests/xmlfiles/75-ruleset.xml new file +1 -0
@@ -0,0 +1 @@ +<nftables><table><name>filter</name><family>ip</family><flags>0</flags></table><table><name>filter2</name><family>ip</family><flags>0</flags></table><chain><name>input</name><handle>1</handle><bytes>0</bytes><packets>0</packets><table>filter</table><family>ip</family></chain><chain><name>output</name><handle>3</handle><bytes>0</bytes><packets>0</packets><table>filter</table><family>ip</family></chain><set><family>ip</family><table>filter</table><name>set0</name><flags>3</flags><key_type>12</key_type><key_len>2</key_len><data_type>0</data_type><data_len>0</data_len><set_elem><flags>0</flags><key><data_reg type="value"><len>2</len><data0>0x00001900</data0></data_reg></key></set_elem><set_elem><flags>0</flags><key><data_reg type="value"><len>2</len><data0>0x00001600</data0></data_reg></key><
/set_elem></set><set><family>ip</family><table>filter</table><name>set1</name><flags>3</flags><key_type>12</key_type><key_len>2</key_len><data_type>0</data_type><data_len>0</data_len><set_el
em><flags>0</flags><key><data_reg type="value"><len>2</len><data0>0x0000c800</data0></data_reg></key></set_elem><set_elem><flags>0</flags><key><data_reg type="value"><len>2</len><data0>0x00006300</data0></data_reg></key></set_elem></set><set><family>ip</family><table>filter</table><name>set2</name><flags>3</flags><key_type>12</key_type><key_len>2</key_len><data_type>0</data_type><data_len>0</data_len><set_elem><flags>0</flags><key><data_reg type="value"><len>2</len><data0>0x0000c800</data0></data_reg></key></set_elem><set_elem><flags>0</flags><key><data_reg type="value"><len>2</len><data0>0x00006300</data0></data_reg></key></set_elem></set><rule><family>ip</family><table>filter</table><chain>input</chain><handle>2</handle><flags>0</flags><expr type="payload"><dreg>1</dreg><offset>9</offse t><len>1</len><base>network</base></expr><expr type="cmp"><sreg>1</sreg><op>eq</op><cmpdata><data_reg type="value"><len>1</len><data0>0x00000006</data0></data_reg></cmpdata></expr><expr type
="payload"><dreg>1</dreg><offset>2</offset><len>2</len><base>transport</base></expr><expr type="lookup"><set>set0</set><sreg>1</sreg><dreg>0</dreg></expr><expr type="immediate"><dreg>0</dreg><immediatedata><data_reg type="verdict"><verdict>accept</verdict></data_reg></immediatedata></expr></rule><rule><family>ip</family><table>filter</table><chain>output</chain><handle>4</handle><flags>0</flags><expr type="payload"><dreg>1</dreg><offset>9</offset><len>1</len><base>network</base></expr><expr type="cmp"><sreg>1</sreg><op>eq</op><cmpdata><data_reg type="value"><len>1</len><data0>0x00000006</data0></data_reg></cmpdata></expr><expr type="payload"><dreg>1</dreg><offset>2</offset><len>2</len><base>transport</base></expr><expr type="lookup"><set>set1</set><sreg>1</sreg><dreg>0</dreg></expr><expr type="payload"><dreg>1</dreg><offset>16</offset><len>4</len><base>network</base></expr><expr type="cmp"><sreg>1</sreg><op>eq</op><cmpdata><data_reg type="value"><len>4</len><data0>0x01010101
</data0></data_reg></cmpdata></expr></rule><rule><family>ip</family><table>filter</table><chain>output</chain><handle>5</handle><flags>0</flags><expr type="payload"><dreg>1</dreg><offset>9</offset><len>1</len><base>network</base></expr><expr type="cmp"><sreg>1</sreg><op>eq</op><cmpdata><data_reg type="value"><len>1</len><data0>0x00000006</data0></data_reg></cmpdata></expr><expr type="payload"><dreg>1</dreg><offset>2</offset><len>2</len><base>transport</base></expr><expr type="lookup"><set>set2</set><sreg>1</sreg><dreg>0</dreg></expr><expr type="payload"><dreg>1</dreg><offset>16</offset><len>4</len><base>network</base></expr><expr type="cmp"><sreg>1</sreg><op>eq</op><cmpdata><data_reg type="value"><len>4</len><data0>0x01010101</data0></data_reg></cmpdata></expr><expr type="counter"><pkts>0 </pkts><bytes>0</bytes></expr><expr type="meta"><dreg>1</dreg><key>oif</key></expr><expr type="cmp"><sreg>1</sreg><op>eq</op><cmpdata><data_reg type="value"><len>4</len><data0>0x00000004</da
ta0></data_reg></cmpdata></expr></rule></nftables>
Pablo Neira Ayuso
maintainerRe: [libnftables PATCH 3/3] src: add low-level ruleset API
Quoted 1 line · Arturo Borrero Gonzalez
This patch adds a low level ruleset API for libnftables.
I cannot apply this patch, it depends on 1/3 :-(
I think this work should have come in first place, we've been working on it for quite some time. The improvements for the test infrastructure are not so important, that's test infrastructure code after all.
Pablo Neira Ayuso
maintainerQuoted 4 lines · Arturo Borrero Gonzalez
The testbench was not reporting errors properly.
With this patch, "1" is returned to the shell if the test failed (instead of returning "0" unconditionally). Textual reporting is also fixed.
How is it broken?
IIRC the error reporting provides some rudimentary cursor to indicate where the problem happens. I think this patch breaks it.
Quoted 30 lines
In case of compilation without some parsing support, returning error (i.e 1) is the expected behaviour.
Signed-off-by Arturo Borrero Gonzalez <[email protected]>---
0 files changedtests/nft-parsing-test.c +5
-5@@ -50,23 +50,23 @@ static void print_detail_error(char *a, char *b)if (k <0 ) k =0 ; -fprintf (stderr,"from file: " ); +printf ("\nfrom file: " );for (i = k; i < from +10 ; i++) -fprintf (stderr,"%c" , a[i]); +printf ("%c" , a[i]); -fprintf (stderr,"\nfrom snprintf: " ); +printf ("\nfrom snprintf: " );for (i = k; i < from +10 ; i++) -fprintf (stderr,"%c" , b[i]); +printf ("%c" , b[i]);/* Don't look twice below this comment ;-) */ -fprintf (stderr,"\n " ); +printf ("\n " );
tests/nft-parsing-test.c static void print_detail_error(char *a, char *b) · line 69
Quoted 10 lines
tests/nft-parsing-test.c +3
-3for (i = k; i < from +10 ; i++) {if (i == from) -fprintf (stderr,"^" ); +printf ("^" );else -fprintf (stderr," " ); +printf (" " ); } -fprintf (stderr,"\n" ); +printf ("\n" );
Is this chunk really needed? If so, it has to come in a separated patch including reason why.
Quoted 186 lines
tests/nft-parsing-test.c +40
-32} }@@ -144,8 +144,7 @@ static int compare_test(uint32_t type, void *input, const char *filename)if (strncmp (orig, out,strlen (out)) ==0 )return 0 ; -printf ("validating %s: " , filename); -printf ("\033[31mFAILED\e[0m\n" ); + errno =EBADMSG ;print_detail_error (orig, out);return -1 ; }@@ -177,7 +176,7 @@ static int test_json(const char *filename)if (nft_table_parse (t,NFT_TABLE_PARSE_JSON , json) ==0 ) ret =compare_test (TEST_JSON_TABLE , t, filename);else - goto failparsing; + ret =-1 ;nft_table_free (t); }@@ -187,7 +186,7 @@ static int test_json(const char *filename)if (nft_chain_parse (c,NFT_CHAIN_PARSE_JSON , json) ==0 ) ret =compare_test (TEST_JSON_CHAIN , c, filename);else - goto failparsing; + ret =-1 ;nft_chain_free (c); }@@ -197,7 +196,7 @@ static int test_json(const char *filename)if (nft_rule_parse (r,NFT_RULE_PARSE_JSON , json) ==0 ) ret =compare_test (TEST_JSON_RULE , r, filename);else - goto failparsing; + ret =-1 ;nft_rule_free (r); }@@ -207,7 +206,7 @@ static int test_json(const char *filename)if (nft_set_parse (s,NFT_SET_PARSE_JSON , json) ==0 ) ret =compare_test (TEST_JSON_SET , s, filename);else - goto failparsing; + ret =-1 ;nft_set_free (s); }@@ -216,13 +215,6 @@ static int test_json(const char *filename)free (json);json_decref (root);return ret; - -failparsing: -printf ("parsing %s: " , filename); -printf ("\033[31mFAILED\e[0m (%s)\n" ,strerror (errno)); -free (json); -json_decref (root); -return -1 ;#else errno =EOPNOTSUPP ;return -1 ;@@ -245,12 +237,16 @@ static int test_xml(const char *filename) tree =mxmlLoadFile (NULL , fp,MXML_NO_CALLBACK );fclose (fp); -if (tree ==NULL ) +if (tree ==NULL ) { +printf ("Unable to build XML tree." );return -1 ; + } xml =mxmlSaveAllocString (tree,MXML_NO_CALLBACK ); -if (xml ==NULL ) +if (xml ==NULL ) { +printf ("Unable to save alloc string from XML tree." );return -1 ; + }/* Check what parsing should be done */ if (strcmp (tree->value.opaque,"table" ) ==0 ) {@@ -259,7 +255,7 @@ static int test_xml(const char *filename)if (nft_table_parse (t,NFT_TABLE_PARSE_XML , xml) ==0 ) ret =compare_test (TEST_XML_TABLE , t, filename);else - goto failparsing; + ret =-1 ;nft_table_free (t); }@@ -269,7 +265,7 @@ static int test_xml(const char *filename)if (nft_chain_parse (c,NFT_CHAIN_PARSE_XML , xml) ==0 ) ret =compare_test (TEST_XML_CHAIN , c, filename);else - goto failparsing; + ret =-1 ;nft_chain_free (c); }@@ -279,7 +275,7 @@ static int test_xml(const char *filename)if (nft_rule_parse (r,NFT_RULE_PARSE_XML , xml) ==0 ) ret =compare_test (TEST_XML_RULE , r, filename);else - goto failparsing; + ret =-1 ;nft_rule_free (r); }@@ -289,18 +285,14 @@ static int test_xml(const char *filename)if (nft_set_parse (s,NFT_SET_PARSE_XML , xml) ==0 ) ret =compare_test (TEST_XML_SET , s, filename);else - goto failparsing; + ret =-1 ; nft_set_free(s); } } +free (xml);return ret; - -failparsing: -printf ("parsing %s: " , filename); -printf ("\033[31mFAILED\e[0m (%s)\n" ,strerror (errno)); -return -1 ;#else errno =EOPNOTSUPP ;return -1 ;@@ -309,6 +301,7 @@ failparsing:int main (int argc,char *argv[]) { +int exit_code =0 , ret;DIR *d;struct dirent *dent;char path[PATH_MAX ];@@ -334,19 +327,35 @@ int main(int argc, char *argv[])snprintf (path,sizeof (path),"%s/%s" , argv[1 ], dent->d_name);if (strcmp (&dent->d_name[len-4 ],".xml" ) ==0 ) { -if (test_xml (path) ==0 ) { -printf ("parsing and validating %s: " , path); + +printf ("parsing and validating %s: " , path); + +if ((ret =test_xml (path)) ==0 )printf ("\033[32mOK\e[0m\n" ); - } +else +printf ("\033[31mFAILED\e[0m (%s)\n" , +strerror (errno)); + + exit_code += ret; }if (strcmp (&dent->d_name[len-5 ],".json" ) ==0 ) { -if (test_json (path) ==0 ) { -printf ("parsing and validating %s: " , path); + +printf ("parsing and validating %s: " , path); + +if ((ret =test_json (path)) ==0 )printf ("\033[32mOK\e[0m\n" ); - } +else +printf ("\033[31mFAILED\e[0m (%s)\n" , +strerror (errno)); + + exit_code += ret; } }closedir (d); -return 0 ; + +if (exit_code ==0 ) +exit (EXIT_SUCCESS ); +else +exit (EXIT_FAILURE ); } --To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 10 lines · Pablo Neira Ayuso
Quoted 4 lines · Arturo Borrero Gonzalez
The testbench was not reporting errors properly.
With this patch, "1" is returned to the shell if the test failed (instead of returning "0" unconditionally). Textual reporting is also fixed.
How is it broken?
IIRC the error reporting provides some rudimentary cursor to indicate where the problem happens. I think this patch breaks it.
I don't see where the break happens. Could you give me some hints?
For me, the cursor works as expected.
Signature · 5 lines
Arturo Borrero González -- To unsubscribe from this list: send the line "unsubscribe netfilter-devel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Pablo Neira Ayuso
maintainerQuoted 7 lines · Arturo Borrero Gonzalez
Quoted 6 lines · Pablo Neira Ayuso
Quoted 4 lines · Arturo Borrero Gonzalez
The testbench was not reporting errors properly.
With this patch, "1" is returned to the shell if the test failed (instead of returning "0" unconditionally). Textual reporting is also fixed.
Quoted 8 lines
Quoted 4 lines
How is it broken?
IIRC the error reporting provides some rudimentary cursor to indicate where the problem happens. I think this patch breaks it.
I don't see where the break happens. Could you give me some hints?
For me, the cursor works as expected.
This patch includes changes for different things, please split it in chunks including the corresponding description. Thanks.