diff options
author | Pablo Neira Ayuso <pablo@netfilter.org> | 2008-11-23 15:24:13 +0100 |
---|---|---|
committer | Pablo Neira Ayuso <pablo@netfilter.org> | 2008-11-23 15:24:13 +0100 |
commit | 0f94ee526d87d0e02a742dc22af959e873ce22e2 (patch) | |
tree | 82e6f86b62249b86f3846937f4eadee87889cdae /qa | |
parent | 87a0dfec43336ed957a414a1cb5e02239e04a9b8 (diff) |
qa: add test file to check for missing indirect function calls
This patch adds a rudimentary test file to check for possible unset
indirect function calls. This automated test should be run after
adding a new attribute.
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
Diffstat (limited to 'qa')
-rw-r--r-- | qa/Makefile.am | 7 | ||||
-rw-r--r-- | qa/test_api.c | 102 |
2 files changed, 109 insertions, 0 deletions
diff --git a/qa/Makefile.am b/qa/Makefile.am new file mode 100644 index 0000000..6a9471b --- /dev/null +++ b/qa/Makefile.am @@ -0,0 +1,7 @@ +include $(top_srcdir)/Make_global.am + +check_PROGRAMS = test_api + +test_api_SOURCES = test_api.c +test_api_LDADD = ../src/libnetfilter_conntrack.la +test_api_LDFLAGS = -dynamic -ldl diff --git a/qa/test_api.c b/qa/test_api.c new file mode 100644 index 0000000..eda9d49 --- /dev/null +++ b/qa/test_api.c @@ -0,0 +1,102 @@ +/* + * Run this after adding a new attribute to the nf_conntrack object + */ + +#include <stdio.h> +#include <stdlib.h> +#include <sys/wait.h> +#include <errno.h> + +#include <libnetfilter_conntrack/libnetfilter_conntrack.h> + +/* + * this file contains a test to check the set/get/copy/cmp APIs. + */ + +static eval_sigterm(int status) +{ + switch(WTERMSIG(status)) { + case SIGSEGV: + printf("received SIGSEV\n"); + break; + case 0: + printf("OK\n", WTERMSIG(status)); + break; + default: + printf("exited with signal: %d\n", WTERMSIG(status)); + break; + } +} + +int main() +{ + int ret, i; + struct nfct_handle *h; + struct nf_conntrack *ct, *tmp; + char data[32]; + int status; + + /* initialize fake data for testing purposes */ + for (i=0; i<sizeof(data); i++) + data[i] = 0x01; + + ct = nfct_new(); + if (!ct) { + perror("nfct_new"); + return 0; + } + tmp = nfct_new(); + if (!tmp) { + perror("nfct_new"); + return 0; + } + + printf("== test set API ==\n"); + ret = fork(); + if (ret == 0) { + for (i=0; i<ATTR_MAX; i++) + nfct_set_attr(ct, i, data); + exit(0); + } else { + wait(&status); + eval_sigterm(status); + } + + for (i=0; i<ATTR_MAX; i++) + nfct_set_attr(ct, i, data); + + printf("== test get API ==\n"); + ret = fork(); + if (ret == 0) { + for (i=0; i<ATTR_MAX; i++) + nfct_get_attr(ct, i); + exit(0); + } else { + wait(&status); + eval_sigterm(status); + } + + printf("== test copy API ==\n"); + ret = fork(); + if (ret == 0) { + for (i=0; i<ATTR_MAX; i++) + nfct_copy_attr(tmp, ct, i); + exit(0); + } else { + wait(&status); + eval_sigterm(status); + } + + printf("== test cmp API ==\n"); + ret = fork(); + if (ret == 0) { + nfct_cmp(tmp, ct, NFCT_CMP_ALL); + exit(0); + } else { + wait(&status); + eval_sigterm(status); + } + + nfct_destroy(ct); + nfct_destroy(tmp); +} |