diff options
Diffstat (limited to 'qa/test_api.c')
-rw-r--r-- | qa/test_api.c | 102 |
1 files changed, 102 insertions, 0 deletions
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); +} |