1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-22 07:29:01 +00:00

Moved gh_lists tests from nsock/src/ to nsock/tests/

This commit is contained in:
henri
2013-05-22 14:35:24 +00:00
parent 05ab9f5a0c
commit 8b7f91cd0f
4 changed files with 161 additions and 120 deletions

View File

@@ -83,125 +83,6 @@
} while (0) } while (0)
#ifdef GH_LIST_MAIN
int main(int argc, char *argv[]) {
gh_list lists[16];
gh_list_elem *current, *next;
int num = 0;
int ret;
int i;
for(i=0; i < 16; i++)
gh_list_init(&lists[i]);
for(num=25000; num < 50000; num++) {
for(i=0; i < 16; i++) {
gh_list_append(&lists[i], (void *)num);
}
}
for(num=24999; num >= 0; num--) {
for(i=0; i < 16; i++) {
gh_list_prepend(&lists[i], (void *)num);
}
}
for(num=0; num < 50000; num++) {
for(i=0; i < 16; i++) {
ret = (int) gh_list_pop(&lists[i]);
if (ret != num)
fatal("prepend_test: Bogus return value %d when expected %d\n", ret, num);
}
}
for(i=0; i < 16; i++) {
ret = (int) gh_list_pop(&lists[i]);
if (ret != 0)
fatal("Ret is bogus for list %d", i);
}
printf("Done with first set\n");
for(num=24999; num >= 0; num--) {
for(i=0; i < 16; i++) {
gh_list_prepend(&lists[i], (void *)num);
}
}
for(num=25000; num < 50000; num++) {
for(i=0; i < 16; i++) {
gh_list_append(&lists[i], (void *)num);
}
}
for(num=0; num < 50000; num++) {
for(i=0; i < 16; i++) {
ret = (int) gh_list_pop(&lists[i]);
if (ret != num)
fatal("prepend_test: Bogus return value %d when expected %d\n", ret, num);
}
}
printf("Done with second set\n");
for(num=25000; num < 50000; num++) {
for(i=0; i < 16; i++) {
gh_list_append(&lists[i], (void *)num);
}
}
for(num=24999; num >= 0; num--) {
for(i=0; i < 16; i++) {
gh_list_prepend(&lists[i], (void *)num);
}
}
for(num=0; num < 50000; num++) {
for(i=0; i < 16; i++) {
ret = (int) gh_list_pop(&lists[i]);
if (ret != num)
fatal("prepend_test: Bogus return value %d when expected %d\n", ret, num);
}
}
printf("Done with third set ...\n");
for(num=24999; num >= 0; num--) {
for(i=0; i < 16; i++) {
gh_list_prepend(&lists[i], (void *)num);
}
}
for(num=25000; num < 50000; num++) {
for(i=0; i < 16; i++) {
gh_list_append(&lists[i], (void *)num);
}
}
for(i=0; i < 16; i++) {
num=0;
for(current = GH_LIST_FIRST_ELEM(&lists[i]); current;
current = next) {
next = GH_LIST_ELEM_NEXT(current);
if ((int)GH_LIST_ELEM_DATA(current) != num)
fatal("Got %d when I expected %d\n", (int)GH_LIST_ELEM_DATA(current), num);
gh_list_remove_elem(&lists[i], current);
num++;
}
if (num != 50000)
fatal("Number is %d, even though %d was expected", num, 50000);
if (GH_LIST_COUNT(&lists[i]) != 0) {
fatal("List should be empty, but instead it has %d members!\n", GH_LIST_COUNT(&lists[i]));
}
}
printf("Done with fourth set, freeing buffers\n");
for(i=0; i < 16; i++) {
gh_list_free(&lists[i]);
}
}
#endif /* GH_LIST_MAIN */
static inline struct gh_list_elem *get_free_buffer(struct gh_list *list) { static inline struct gh_list_elem *get_free_buffer(struct gh_list *list) {
struct gh_list_elem *newelem; struct gh_list_elem *newelem;
int i; int i;

View File

@@ -15,7 +15,8 @@ SRC = tests_main.c \
basic.c \ basic.c \
timer.c \ timer.c \
logs.c \ logs.c \
connect.c connect.c \
ghlists.c
OBJ = $(SRC:.c=.o) OBJ = $(SRC:.c=.o)

156
nsock/tests/ghlists.c Normal file
View File

@@ -0,0 +1,156 @@
/*
* Nsock regression test suite
* Same license as nmap -- see http://nmap.org/book/man-legal.html
*/
#include "test-common.h"
#include "../src/gh_list.h"
#include <stdint.h>
#include <time.h>
#define INT2PTR(i) ((void *)(intptr_t)(i))
#define PTR2INT(p) ((intptr_t)(void *)(p))
#define LIST_COUNT 16
static int ghlist_stress(void *tdata) {
gh_list lists[LIST_COUNT];
gh_list_elem *current, *next;
int num = 0;
int ret;
int i;
for (i=0; i < LIST_COUNT; i++)
gh_list_init(&lists[i]);
for (num=25000; num < 50000; num++) {
for (i=0; i < LIST_COUNT; i++) {
gh_list_append(&lists[i], INT2PTR(num));
}
}
for (num=24999; num >= 0; num--) {
for (i=0; i < LIST_COUNT; i++) {
gh_list_prepend(&lists[i], INT2PTR(num));
}
}
for (num=0; num < 50000; num++) {
for (i=0; i < LIST_COUNT; i++) {
ret = PTR2INT(gh_list_pop(&lists[i]));
if (ret != num) {
fprintf(stderr, "prepend_test: Bogus return value %d when expected %d\n",
ret, num);
return -EINVAL;
}
}
}
for (i=0; i < LIST_COUNT; i++) {
ret = PTR2INT(gh_list_pop(&lists[i]));
if (ret != 0) {
fprintf(stderr, "Ret is bogus for list %d", i);
return -EINVAL;
}
}
for (num=24999; num >= 0; num--) {
for (i=0; i < LIST_COUNT; i++) {
gh_list_prepend(&lists[i], INT2PTR(num));
}
}
for (num=25000; num < 50000; num++) {
for (i=0; i < LIST_COUNT; i++) {
gh_list_append(&lists[i], INT2PTR(num));
}
}
for (num=0; num < 50000; num++) {
for (i=0; i < LIST_COUNT; i++) {
ret = PTR2INT(gh_list_pop(&lists[i]));
if (ret != num) {
fprintf(stderr, "prepend_test: Bogus return value %d when expected %d\n",
ret, num);
return -EINVAL;
}
}
}
for (num=25000; num < 50000; num++) {
for (i=0; i < LIST_COUNT; i++) {
gh_list_append(&lists[i], INT2PTR(num));
}
}
for (num=24999; num >= 0; num--) {
for (i=0; i < LIST_COUNT; i++) {
gh_list_prepend(&lists[i], INT2PTR(num));
}
}
for (num=0; num < 50000; num++) {
for (i=0; i < LIST_COUNT; i++) {
ret = PTR2INT(gh_list_pop(&lists[i]));
if (ret != num) {
fprintf(stderr, "prepend_test: Bogus return value %d when expected %d\n",
ret, num);
return -EINVAL;
}
}
}
for (num=24999; num >= 0; num--) {
for (i=0; i < LIST_COUNT; i++) {
gh_list_prepend(&lists[i], INT2PTR(num));
}
}
for (num=25000; num < 50000; num++) {
for (i=0; i < LIST_COUNT; i++) {
gh_list_append(&lists[i], INT2PTR(num));
}
}
for (i=0; i < LIST_COUNT; i++) {
num=0;
for (current = GH_LIST_FIRST_ELEM(&lists[i]); current;
current = next) {
int k;
next = GH_LIST_ELEM_NEXT(current);
k = PTR2INT(GH_LIST_ELEM_DATA(current));
if (k != num) {
fprintf(stderr, "Got %d when I expected %d\n", k, num);
return -EINVAL;
}
gh_list_remove_elem(&lists[i], current);
num++;
}
if (num != 50000) {
fprintf(stderr, "Number is %d, even though %d was expected", num, 50000);
return -EINVAL;
}
if (GH_LIST_COUNT(&lists[i]) != 0) {
fprintf(stderr, "List should be empty, but instead it has %d members!\n",
GH_LIST_COUNT(&lists[i]));
return -EINVAL;
}
}
for (i=0; i < LIST_COUNT; i++) {
gh_list_free(&lists[i]);
}
return 0;
}
const struct test_case TestGHLists = {
.t_name = "test nsock internal ghlists",
.t_setup = NULL,
.t_run = ghlist_stress,
.t_teardown = NULL
};

View File

@@ -20,6 +20,7 @@ extern const struct test_case TestTimer;
extern const struct test_case TestLogLevels; extern const struct test_case TestLogLevels;
extern const struct test_case TestErrLevels; extern const struct test_case TestErrLevels;
extern const struct test_case TestConnectTCP; extern const struct test_case TestConnectTCP;
extern const struct test_case TestGHLists;
static const struct test_case *TestCases[] = { static const struct test_case *TestCases[] = {
@@ -32,6 +33,8 @@ static const struct test_case *TestCases[] = {
&TestErrLevels, &TestErrLevels,
/* ---- connect.c */ /* ---- connect.c */
&TestConnectTCP, &TestConnectTCP,
/* ---- ghlists.c */
&TestGHLists,
NULL NULL
}; };