From: Amos Jeffries Date: Mon, 25 May 2020 03:15:41 +0000 (+0000) Subject: Remove obsolete membanger test (#642) X-Git-Tag: 4.15-20210522-snapshot~111 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=331cec473e2ac97221f4ea08e206ac4df245915d;p=thirdparty%2Fsquid.git Remove obsolete membanger test (#642) The binary code has major bitrot and has not built in a long time. If any of its logic is needed in future we can look at the repo history. --- diff --git a/test-suite/Makefile.am b/test-suite/Makefile.am index 5337c09e3a..a2a1d782b1 100644 --- a/test-suite/Makefile.am +++ b/test-suite/Makefile.am @@ -18,7 +18,7 @@ LDADD = \ $(COMPAT_LIB) \ $(XTRA_LIBS) -EXTRA_PROGRAMS = mem_node_test membanger splay tcp-banger2 +EXTRA_PROGRAMS = mem_node_test splay tcp-banger2 EXTRA_DIST = \ $(srcdir)/squidconf/* \ @@ -120,26 +120,6 @@ syntheticoperators_SOURCES = syntheticoperators.cc stub_libmem.cc $(DEBUG_SOURCE VirtualDeleteOperator_SOURCES = VirtualDeleteOperator.cc stub_libmem.cc $(DEBUG_SOURCE) -## membanger won't link today. Bitrot.. -##CC = gcc -##CFLAGS = -g -Wall -I../include -I../src -##OBJS = membanger.o hash.o SizeToPool.o -##LIB = -L. -lMem -##TARGLIB = libMem.a -##LIBOBJS = Mem.o \ -## Stack.o -##AR_R = /usr/bin/ar r -##RM = rm -##XTRA_LIBS = -lm -lmalloc -## -##all: membanger -## -##membanger: $(OBJS) $(TARGLIB) -## $(CC) -o membanger $(OBJS) $(LIB) -## -##$(TARGLIB): $(LIBOBJS) -## $(AR_R) $(TARGLIB) $(LIBOBJS) - squid-conf-tests: $(top_builddir)/src/squid.conf.default $(srcdir)/squidconf/* @failed=0; cfglist="$?"; rm -f $@ || $(TRUE); \ for cfg in $$cfglist ; do \ diff --git a/test-suite/hash.c b/test-suite/hash.c deleted file mode 100644 index 15d67b98ab..0000000000 --- a/test-suite/hash.c +++ /dev/null @@ -1,392 +0,0 @@ -/* - * Copyright (C) 1996-2020 The Squid Software Foundation and contributors - * - * Squid software is distributed under GPLv2+ license and includes - * contributions from numerous individuals and organizations. - * Please see the COPYING and CONTRIBUTORS files for details. - */ - -/* DEBUG: section 00 Hash Tables */ - -#include "squid.h" - -#if HAVE_UNISTD_H -#include -#endif -#if HAVE_CTYPE_H -#include -#endif -#if HAVE_STRINGS_H -#include -#endif -#if HAVE_ASSERT_H -#include -#endif - -#include "hash.h" - -#undef free -extern void my_free(char *, int, void *); - -#define free(a) my_free(__FILE__, __LINE__, a) - -extern void print_stats(); -/* - * hash_url() - Returns a well-distributed hash function for URLs. - * The best way is to sum up the last half of the string. - * Adapted from code written by Mic Bowman. -Darren - * Generates a standard deviation = 15.73 - */ -unsigned int -hash_url(const void *data, unsigned int size) -{ - const char *s = data; - unsigned int i, j, n; - j = strlen(s); - for (i = j / 2, n = 0; i < j; i++) - n ^= 271 * (unsigned) s[i]; - i = n ^ (j * 271); - return i % size; -} - -unsigned int -hash_string(const void *data, unsigned int size) -{ - const char *s = data; - unsigned int n = 0; - unsigned int j = 0; - unsigned int i = 0; - while (*s) { - j++; - n ^= 271 * (unsigned) *s++; - } - i = n ^ (j * 271); - return i % size; -} - -/* the following 4 functions were adapted from - * usr/src/lib/libc/db/hash_func.c, 4.4 BSD lite */ - -/* - * HASH FUNCTIONS - * - * Assume that we've already split the bucket to which this key hashes, - * calculate that bucket, and check that in fact we did already split it. - * - * This came from ejb's hsearch. - */ - -#define PRIME1 37 -#define PRIME2 1048583 - -/* Hash function from Chris Torek. */ -unsigned int -hash4(const void *data, unsigned int size) -{ - const char *key = data; - size_t loop; - unsigned int h; - size_t len; - -#define HASH4a h = (h << 5) - h + *key++; -#define HASH4b h = (h << 5) + h + *key++; -#define HASH4 HASH4b - - h = 0; - len = strlen(key); - loop = (len + 8 - 1) >> 3; - switch (len & (8 - 1)) { - case 0: - do { - HASH4; - /* FALLTHROUGH */ - case 7: - HASH4; - /* FALLTHROUGH */ - case 6: - HASH4; - /* FALLTHROUGH */ - case 5: - HASH4; - /* FALLTHROUGH */ - case 4: - HASH4; - /* FALLTHROUGH */ - case 3: - HASH4; - /* FALLTHROUGH */ - case 2: - HASH4; - /* FALLTHROUGH */ - case 1: - HASH4; - } while (--loop); - } - return h % size; -} - -/* - * hash_create - creates a new hash table, uses the cmp_func - * to compare keys. Returns the identification for the hash table; - * otherwise returns a negative number on error. - */ -hash_table * -hash_create(HASHCMP * cmp_func, int hash_sz, HASHHASH * hash_func) -{ - hash_table *hid = calloc(1, sizeof(hash_table)); - if (!hash_sz) - hid->size = (unsigned int) DEFAULT_HASH_SIZE; - else - hid->size = (unsigned int) hash_sz; - /* allocate and null the buckets */ - hid->buckets = calloc(hid->size, sizeof(hash_link *)); - hid->cmp = cmp_func; - hid->hash = hash_func; - hid->current_ptr = NULL; - hid->current_slot = 0; - return hid; -} - -/* - * hash_insert - inserts the given item 'item' under the given key 'k' - * into the hash table 'hid'. Returns non-zero on error; otherwise, - * returns 0 and inserts the item. - * - * It does not copy any data into the hash table, only pointers. - */ -void -hash_insert(hash_table * hid, const char *k, void *item) -{ - int i; - hash_link *new; - assert(k != NULL); - /* Add to the given hash table 'hid' */ - new = calloc(1, sizeof(hash_link)); - if (!new) { - fprintf(stderr, "calloc failed!\n"); - print_stats(); - exit(1); - } - new->item = item; - new->key = (char *) k; - i = hid->hash(k, hid->size); - new->next = hid->buckets[i]; - hid->buckets[i] = new; -} - -/* - * hash_join - joins a hash_link under its key lnk->key - * into the hash table 'hid'. - * - * It does not copy any data into the hash table, only links pointers. - */ -void -hash_join(hash_table * hid, hash_link * lnk) -{ - int i; - i = hid->hash(lnk->key, hid->size); - lnk->next = hid->buckets[i]; - hid->buckets[i] = lnk; -} - -/* - * hash_lookup - locates the item under the key 'k' in the hash table - * 'hid'. Returns a pointer to the hash bucket on success; otherwise - * returns NULL. - */ -hash_link * -hash_lookup(hash_table * hid, const void *k) -{ - hash_link *walker; - int b; - assert(k != NULL); - b = hid->hash(k, hid->size); - for (walker = hid->buckets[b]; walker != NULL; walker = walker->next) { - if ((hid->cmp) (k, walker->key) == 0) - return (walker); - assert(walker != walker->next); - } - return NULL; -} - -/* - * hash_first - returns the first item in the hash table 'hid'. - * Otherwise, returns NULL on error. - */ -hash_link * -hash_first(hash_table * hid) -{ - int i; - - for (i = 0; i < hid->size; i++) { - hid->current_slot = i; - if (hid->buckets[i] != NULL) - return (hid->current_ptr = hid->buckets[i]); - } - return NULL; -} - -/* - * hash_next - returns the next item in the hash table 'hid'. - * Otherwise, returns NULL on error or end of list. - * - * MUST call hash_first() before hash_next(). - */ -hash_link * -hash_next(hash_table * hid) -{ - int i; - - if (hid->current_ptr != NULL) { - hid->current_ptr = hid->current_ptr->next; - if (hid->current_ptr != NULL) - return (hid->current_ptr); /* next item */ - } - /* find next bucket */ - for (i = hid->current_slot + 1; i < hid->size; i++) { - hid->current_slot = i; - if (hid->buckets[i] != NULL) - return (hid->current_ptr = hid->buckets[i]); - } - return NULL; /* end of list */ -} - -int -hash_delete(hash_table * hid, const char *key) -{ - return hash_delete_link(hid, hash_lookup(hid, key)); -} - -/* - * hash_delete_link - deletes the given hash_link node from the - * hash table 'hid'. If FreeLink then free the given hash_link. - * - * On success, it returns 0 and deletes the link; otherwise, - * returns non-zero on error. - */ -int -hash_unlink(hash_table * hid, hash_link * hl, int FreeLink) -{ - hash_link *walker, *prev; - int i; - if (hl == NULL) - return -1; - i = hid->hash(hl->key, hid->size); - for (prev = NULL, walker = hid->buckets[i]; - walker != NULL; prev = walker, walker = walker->next) { - if (walker == hl) { - if (prev == NULL) { /* it's the head */ - hid->buckets[i] = walker->next; - } else { - prev->next = walker->next; /* skip it */ - } - /* fix walker state if needed */ - if (walker == hid->current_ptr) - hid->current_ptr = walker->next; - if (FreeLink) { - if (walker) { - free(walker); - } - } - return 0; - } - } - return 1; -} - -/* take link off and free link node */ -int -hash_delete_link(hash_table * hid, hash_link * hl) -{ - return (hash_unlink(hid, hl, 1)); -} - -/* take link off only */ -int -hash_remove_link(hash_table * hid, hash_link * hl) -{ - return (hash_unlink(hid, hl, 0)); -} - -/* - * hash_get_bucket - returns the head item of the bucket - * in the hash table 'hid'. Otherwise, returns NULL on error. - */ -hash_link * -hash_get_bucket(hash_table * hid, unsigned int bucket) -{ - if (bucket >= hid->size) - return NULL; - return (hid->buckets[bucket]); -} - -void -hashFreeMemory(hash_table * hid) -{ - if (hid->buckets); - free(hid->buckets); - if (hid) - free(hid); -} - -#if USE_HASH_DRIVER -/* - * hash-driver - Run with a big file as stdin to insert each line into the - * hash table, then prints the whole hash table, then deletes a random item, - * and prints the table again... - */ -int -main(void) -{ - hash_table *hid; - int i; - LOCAL_ARRAY(char, buf, BUFSIZ); - LOCAL_ARRAY(char, todelete, BUFSIZ); - hash_link *walker = NULL; - - todelete[0] = '\0'; - printf("init\n"); - - printf("creating hash table\n"); - if ((hid = hash_create(strcmp, 229, hash_string)) < 0) { - printf("hash_create error.\n"); - exit(1); - } - printf("done creating hash table: %d\n", hid); - - std::mt19937 mt; - xuniform_int_distribution<> dist(0,16); - - while (fgets(buf, BUFSIZ, stdin)) { - buf[strlen(buf) - 1] = '\0'; - printf("Inserting '%s' for item %p to hash table: %d\n", - buf, buf, hid); - hash_insert(hid, xstrdup(buf), (void *) 0x12345678); - if (dist(mt) == 0) - strcpy(todelete, buf); - } - - printf("walking hash table...\n"); - for (i = 0, walker = hash_first(hid); walker; walker = hash_next(hid)) { - printf("item %5d: key: '%s' item: %p\n", i++, walker->key, - walker->item); - } - printf("done walking hash table...\n"); - - if (todelete[0]) { - printf("deleting %s from %d\n", todelete, hid); - if (hash_delete(hid, todelete)) - printf("hash_delete error\n"); - } - printf("walking hash table...\n"); - for (i = 0, walker = hash_first(hid); walker; walker = hash_next(hid)) { - printf("item %5d: key: '%s' item: %p\n", i++, walker->key, - walker->item); - } - printf("done walking hash table...\n"); - - printf("driver finished.\n"); - exit(0); -} -#endif - diff --git a/test-suite/hash.h b/test-suite/hash.h deleted file mode 100644 index 2218e5533c..0000000000 --- a/test-suite/hash.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (C) 1996-2020 The Squid Software Foundation and contributors - * - * Squid software is distributed under GPLv2+ license and includes - * contributions from numerous individuals and organizations. - * Please see the COPYING and CONTRIBUTORS files for details. - */ - -#define DEFAULT_HASH_SIZE 7951 -extern "C" { - typedef unsigned int HASHHASH(const void *, unsigned int); - struct _hash_link { - char *key; - struct _hash_link *next; - void *item; - }; - typedef int HASHCMP(const void *, const void *); - - typedef struct _hash_link hash_link; - - struct _hash_table { - int valid; - hash_link **buckets; - HASHCMP *cmp; - HASHHASH *hash; - unsigned int size; - unsigned int current_slot; - hash_link *current_ptr; - }; - typedef struct _hash_table hash_table; - - extern int hash_links_allocated; - /* AYJ: defined by globals.h */ -//extern int store_hash_buckets; /* 0 */ -//extern hash_table *store_table; /* NULL */ - extern hash_table *hash_create(HASHCMP *, int, HASHHASH *); - extern void hash_insert(hash_table *, const char *, void *); - extern int hash_delete(hash_table *, const char *); - int hash_delete_link(hash_table *, hash_link *); - int hash_unlink(hash_table *, hash_link *, int); - void hash_join(hash_table *, hash_link *); - int hash_remove_link(hash_table *, hash_link *); - hash_link *hash_lookup(hash_table *, const void *); - hash_link *hash_first(hash_table *); - hash_link *hash_next(hash_table *); - hash_link *hash_get_bucket(hash_table *, unsigned int); - void hashFreeMemory(hash_table *); - HASHHASH hash_string; - HASHHASH hash_url; - HASHHASH hash4; - -} - diff --git a/test-suite/membanger.c b/test-suite/membanger.c deleted file mode 100644 index 0130d9aa0f..0000000000 --- a/test-suite/membanger.c +++ /dev/null @@ -1,345 +0,0 @@ -/* - * Copyright (C) 1996-2020 The Squid Software Foundation and contributors - * - * Squid software is distributed under GPLv2+ license and includes - * contributions from numerous individuals and organizations. - * Please see the COPYING and CONTRIBUTORS files for details. - */ - -#include "squid.h" -#include "hash.h" - -#if HAVE_UNISTD_H -#include -#endif -#if HAVE_CTYPE_H -#include -#endif -#if HAVE_STRINGS_H -#include -#endif - -static hash_table *mem_table = NULL; -static hash_link *mem_entry; -struct rusage myusage; - -#ifdef WITH_LIB -#include "Mem.h" -#include -extern void sizeToPoolInit(); -extern MemPool *sizeToPool(size_t size); -#endif -extern char *malloc_options; -void my_free(char *, int, void *); - -FILE *fp; -char *fn; -int initsiz; -int maxsiz; -int minchunk; -HASHCMP ptrcmp; -char mbuf[256]; -char abuf[32]; -char *p; - -int size; -void *addr; -int amt; - -int i; -int a; -int run_stats = 0; -void *my_xmalloc(size_t); -void *my_xcalloc(int, size_t); -int my_xfree(void *); - -#define xmalloc my_xmalloc -#define xcalloc my_xcalloc -#define xfree my_xfree - -int *size2id_array[2]; -int size2id_len = 0; -int size2id_alloc = 0; - -typedef struct { - char orig_ptr[32]; - void *my_ptr; -#ifdef WITH_LIB - MemPool *pool; -#endif - int size; -} memitem; - -struct { - int mallocs, frees, callocs, reallocs; -} mstat; - -memitem *mi; -void size2id(size_t, memitem *); -void badformat(); -void init_stats(), print_stats(); -void my_hash_insert(hash_table * h, const char *k, memitem * item); -static void *xmemAlloc(memitem * item); -static void xmemFree(memitem * item); - -int -ptrcmp(const void *a, const void *b) -{ - return (strcmp(a, b)); -} - -main(int argc, char **argv) -{ - char c; - extern char *optarg; - malloc_options = "A"; - a = 0; - while ((c = getopt(argc, argv, "f:i:M:l:m:r:N")) != -1) { - switch (c) { - case 'N': - mem_pools_on = 0; - break; - case 'r': - run_stats = atoi(optarg); - break; - case 'f': - fn = xstrdup(optarg); - fp = fopen(fn, "r"); - break; - case 'i': - initsiz = atoi(optarg); - break; - case 'l': - mem_max_size = atoi(optarg) * 1024 * 1024; - break; - case 'M': - maxsiz = atoi(optarg); - break; - case 'm': - minchunk = atoi(optarg); - break; - default: - fprintf(stderr, - "Usage: %s -f file -M maxsiz -i initsiz -m minchunk", argv[0]); - exit(1); - } - - } - if (!fp) { - fprintf(stderr, - "%s pummels %s\n%s . o O ( You't supply a valid tracefile.)\n", - argv[0], getenv("USER"), argv[0]); - exit(1); - } -#ifdef WITH_LIB - sizeToPoolInit(); -#endif - mem_table = hash_create(ptrcmp, 229, hash4); /* small hash table */ - init_stats(); - while (fgets(mbuf, 256, fp) != NULL) { - if (run_stats > 0 && (++a) % run_stats == 0) - print_stats(); - p = NULL; - switch (mbuf[0]) { - case 'm': /* malloc */ - p = strtok(&mbuf[2], ":"); - if (!p) - badformat(); - size = atoi(p); - p = strtok(NULL, "\n"); - if (!p) - badformat(); - mi = malloc(sizeof(memitem)); - strcpy(mi->orig_ptr, p); - mi->size = size; - size2id(size, mi); - mi->my_ptr = xmemAlloc(mi); /* (void *)xmalloc(size); */ - assert(mi->my_ptr); - my_hash_insert(mem_table, mi->orig_ptr, mi); - mstat.mallocs++; - break; - case 'c': /* calloc */ - p = strtok(&mbuf[2], ":"); - if (!p) - badformat(); - amt = atoi(p); - p = strtok(NULL, ":"); - if (!p) - badformat(); - size = atoi(p); - p = strtok(NULL, "\n"); - if (!p) - badformat(); - mi = malloc(sizeof(memitem)); - strcpy(mi->orig_ptr, p); - size2id(size, mi); - mi->size = amt * size; - mi->my_ptr = xmemAlloc(mi); /*(void *)xmalloc(amt*size); */ - assert(mi->my_ptr); - my_hash_insert(mem_table, mi->orig_ptr, mi); - mstat.callocs++; - break; - case 'r': - p = strtok(&mbuf[2], ":"); - if (!p) - badformat(); - strcpy(abuf, p); - p = strtok(NULL, ":"); - if (!p) - badformat(); - mem_entry = hash_lookup(mem_table, p); - if (mem_entry == NULL) { - fprintf(stderr, "invalid realloc (%s)!\n", p); - break; - } - mi = (memitem *) (mem_entry->item); - assert(mi->pool); - assert(mi->my_ptr); - xmemFree(mi); /* xfree(mi->my_ptr); */ - size2id(atoi(p), mi); /* we don't need it here I guess? */ - strcpy(mi->orig_ptr, abuf); - p = strtok(NULL, "\n"); - if (!p) - badformat(); - mi->my_ptr = xmemAlloc(mi); /* (char *)xmalloc(atoi(p)); */ - assert(mi->my_ptr); - mstat.reallocs++; - break; - case 'f': - p = strtok(&mbuf[2], "\n"); - mem_entry = hash_lookup(mem_table, p); - if (mem_entry == NULL) { - if (p[0] != '0') - fprintf(stderr, "invalid free (%s) at line %d!\n", p, a); - break; - } - mi = (memitem *) (mem_entry->item); - assert(mi->pool); - assert(mi->my_ptr); - xmemFree(mi); /* xfree(mi->my_ptr); */ - hash_unlink(mem_table, mem_entry, 1); - free(mi); - mstat.frees++; - break; - default: - fprintf(stderr, "%s pummels %s.bad.format\n", argv[0], fn); - exit(1); - } - - } - fclose(fp); - print_stats(); -} - -void * -my_xmalloc(size_t a) -{ - return NULL; -} - -void * -my_xcalloc(int a, size_t b) -{ - return NULL; -} - -int -my_xfree(void *p) -{ - return 0; -} -void -init_stats() -{ - -} - -void -print_stats() -{ -#ifdef WITH_LIB - memReport(stdout); -#endif - getrusage(RUSAGE_SELF, &myusage); - printf("m/c/f/r=%d/%d/%d/%d\n", mstat.mallocs, mstat.callocs, - mstat.frees, mstat.reallocs); -#if 0 - printf("types : %d\n", size2id_len); -#endif - printf("user time used : %d.%d\n", (int) myusage.ru_utime.tv_sec, - (int) myusage.ru_utime.tv_usec); - printf("system time used : %d.%d\n", (int) myusage.ru_stime.tv_sec, - (int) myusage.ru_stime.tv_usec); - printf("max resident set size : %d\n", (int) myusage.ru_maxrss); - printf("page faults : %d\n", (int) myusage.ru_majflt); -} - -void -size2id(size_t sz, memitem * mi) -{ -#ifdef WITH_LIB - mi->pool = sizeToPool(sz); - assert(mi->pool); -#endif - return; -} - -void -badformat() -{ - fprintf(stderr, "pummel.bad.format\n"); - exit(1); -} - -/* unused code, saved for parts */ -const char * -make_nam(int id, int size) -{ - const char *buf = malloc(30); /* argh */ - snprintf((char *)buf, sizeof(buf)-1, "pl:%d/%d", id, size); - return buf; -} - -void -my_hash_insert(hash_table * h, const char *k, memitem * item) -{ - memitem *l; - assert(item->pool); - assert(item->my_ptr); - hash_insert(h, k, item); -} - -static void * -xmemAlloc(memitem * item) -{ - extern MemPool *StringPool; - assert(item && item->pool); - if (StringPool == item->pool) - return memStringAlloc(item->pool, item->size); - else - return memAlloc(item->pool); -} - -static void -xmemFree(memitem * item) -{ - extern MemPool *StringPool; - assert(item && item->pool); - if (StringPool == item->pool) - return memStringFree(item->pool, item->my_ptr, item->size); - else - return memFree(item->pool, item->my_ptr); -} - -void -my_free(char *file, int line, void *ptr) -{ -#if 0 - fprintf(stderr, "{%s:%d:%p", file, line, ptr); -#endif - free(ptr); -#if 0 - fprintf(stderr, "}\n"); -#endif -} -