[C-MPI-commits] SF.net SVN: c-mpi:[138] test/cmpi-db
Status: Pre-Alpha
Brought to you by:
jmwozniak
|
From: <jmw...@us...> - 2010-05-21 15:09:16
|
Revision: 138
http://c-mpi.svn.sourceforge.net/c-mpi/?rev=138&view=rev
Author: jmwozniak
Date: 2010-05-21 15:09:09 +0000 (Fri, 21 May 2010)
Log Message:
-----------
TAGS improvements, memory leak fixes, whitespace corrections
Modified Paths:
--------------
Makefile.in
include/hashtable.h
include/klist.h
src/adts/About.txt
src/adts/hashtable.c
src/adts/klist.c
src/cmpi/cmpi.c
src/cmpi-cp/cmpi-cp.c
src/cmpi-cp/module.mk.in
test/cmpi/module.mk.in
test/cmpi-db/test-loop.zsh
Modified: Makefile.in
===================================================================
--- Makefile.in 2010-05-20 23:58:01 UTC (rev 137)
+++ Makefile.in 2010-05-21 15:09:09 UTC (rev 138)
@@ -337,8 +337,8 @@
#LIBOBJS := $(patsubst %.c,%.o, $(filter %.c,$(LIBSRC)))
#DISKSIM_OBJS := $(patsubst %.c,%.o, $(filter %.c,$(DISKSIM_SRC)))
-#TABLE_OBJS := $(KDA_OBJS) $(DENSE_OBJS)
-#CMPI_OBJS += $(TABLE_OBJS) $(MPIRPC_OBJS) $(DISKSIM_OBJS)
+CMPI_OBJS := $(TABLE_OBJS) $(MPIRPC_OBJS) $(CMPI_OBJS)
+# $(DISKSIM_OBJS)
CMPI_DEPS := $(patsubst %.o,%.d,$(CMPI_OBJS))
@@ -471,7 +471,7 @@
# Generate TAGS based on only files used by CMPI as configured:
TAGS: deps.txt
$(Q) " TAGS "
- $(E)etags $(ETAGS_FLAGS) `cat deps.txt`
+ $(E) etags $(ETAGS_FLAGS) `cat deps.txt`
# Extract all files from *.d files, format and sort:
# Formats to one file per line & extracts junk and extra files in *.d
Modified: include/hashtable.h
===================================================================
--- include/hashtable.h 2010-05-20 23:58:01 UTC (rev 137)
+++ include/hashtable.h 2010-05-21 15:09:09 UTC (rev 138)
@@ -9,29 +9,29 @@
#include <stdlib.h>
#include <stdint.h>
#include <stdbool.h>
-#include <string.h>
+#include <string.h>
#include <openssl/sha.h>
-#include <mpi_tools.h>
+#include <mpi_tools.h>
-#include "klist.h"
+#include "klist.h"
struct hashtable
{
struct klist** array;
- int capacity;
+ int capacity;
int size;
};
-// inline int quickhash_string_hash(char* key, int capacity);
-int hash_string(char* key, int capacity);
+// inline int quickhash_string_hash(char* key, int capacity);
+int hash_string(char* key, int capacity);
/**
Compress SHA-1 down to a smaller address space,
- namely, 4 bytes.
+ namely, 4 bytes.
*/
-int SHA1_mod(char* data);
+int SHA1_mod(char* data);
struct hashtable* hashtable_create(int capacity);
@@ -41,12 +41,14 @@
void hashtable_dump(char* format, struct hashtable* target);
-void hashtable_free(struct hashtable* target);
+void hashtable_free(struct hashtable* target);
+void hashtable_destroy(struct hashtable* target);
+
/**
- Simply printf all keys in each klist.
+ Simply printf all keys in each klist.
*/
-void hashtable_dumpkeys(struct hashtable* target);
+void hashtable_dumpkeys(struct hashtable* target);
#endif
Modified: include/klist.h
===================================================================
--- include/klist.h 2010-05-20 23:58:01 UTC (rev 137)
+++ include/klist.h 2010-05-21 15:09:09 UTC (rev 138)
@@ -1,44 +1,46 @@
/** Extremely simple singly-linked klist of keyed data items.
- */
+ */
#ifndef KLIST_H
#define KLIST_H
-#include <stdio.h>
-#include <stdlib.h>
+#include <stdio.h>
+#include <stdlib.h>
-#include <mpi_tools.h>
+#include <mpi_tools.h>
// Maximum size of a klist datum
-#define KLIST_MAX_DATUM 100
+#define KLIST_MAX_DATUM 100
struct klist_item
{
- char* key;
+ char* key;
void* data;
- struct klist_item* next;
-};
+ struct klist_item* next;
+};
struct klist
{
struct klist_item* head;
- struct klist_item* tail;
- int size;
+ struct klist_item* tail;
+ int size;
};
-struct klist* klist_create(void);
+struct klist* klist_create(void);
struct klist_item* klist_add(struct klist* target,
- char* key, void* data);
+ char* key, void* data);
-void klist_dump(char* format, struct klist* target);
+void klist_free(struct klist* target);
+void klist_destroy(struct klist* target);
+
+void klist_dump(char* format, struct klist* target);
+
void klist_dumpkeys(struct klist* target);
int klist_tostring(char* str, size_t size,
- char* format, struct klist* target);
+ char* format, struct klist* target);
-void klist_free(struct klist* target);
-
#endif
Modified: src/adts/About.txt
===================================================================
--- src/adts/About.txt 2010-05-20 23:58:01 UTC (rev 137)
+++ src/adts/About.txt 2010-05-21 15:09:09 UTC (rev 138)
@@ -1,6 +1,4 @@
-
-
bool _contains(target, key)
bool _matches(target, cmp, data)
DATA _search(target, key)
@@ -8,19 +6,19 @@
LIST _select_where(target, cmp, pattern)
LIST _pop_where(target, cmp, pattern)
-
+
bool _remove(target, key)
bool _erase(target, key, n) -> delete
-bool _clear(target) free all list items
-bool _clobber(target) clear the list and free the data
-bool _destroy(target) clobber and free the list
+bool _clear(target) free all list items
+bool _clobber(target) clear the list and free the data
+bool _destroy(target) clobber and free the list
void _printf(format, target) [printf]
void _fprintf(FILE, format, target) [fprintf]
void _dump(f(), target) [printf]
void _fdump(FILE, f(), target) [fprintf]
-char* _output(f, target) [static]
+char* _output(f, target) [static]
int _sprintf(s, format, target) [given]
int _snprintf(s, n, format, target) [given]
int _marshal(s, n, f(), target) [given]
Modified: src/adts/hashtable.c
===================================================================
--- src/adts/hashtable.c 2010-05-20 23:58:01 UTC (rev 137)
+++ src/adts/hashtable.c 2010-05-21 15:09:09 UTC (rev 138)
@@ -3,8 +3,8 @@
/**
* derived from an algorithm found in Aho, Sethi and Ullman's
- * {Compilers: Principles, Techniques and Tools}, published by Addison-Wesley.
- * This algorithm comes from P.J. Weinberger's C compiler.
+ * {Compilers: Principles, Techniques and Tools}, published by Addison-Wesley.
+ * This algorithm comes from P.J. Weinberger's C compiler.
*/
int
quickhash_string_hash(char* key, int table_size)
@@ -13,7 +13,7 @@
if (! key)
return -1;
-
+
while (*key)
{
h = (h << 4) + *key++;
@@ -30,49 +30,49 @@
int
hash_string(char* data, int table_size)
{
- // dump_stack();
+ // dump_stack();
int sha1 = SHA1_mod(data);
int index = sha1 % table_size;
- // printf("hash_string %s -> %i \n", data, index);
-
- return index;
+ // printf("hash_string %s -> %i \n", data, index);
+
+ return index;
}
/**
Compress SHA-1 down to a smaller address space,
- namely, 4 bytes, and make positive.
+ namely, 4 bytes, and make positive.
*/
int
SHA1_mod(char* data)
{
static unsigned char output[SHA_DIGEST_LENGTH];
- SHA1((unsigned char*) data, strlen(data), output);
-
+ SHA1((unsigned char*) data, strlen(data), output);
+
int result;
memcpy(&result, output+16, 4);
- // printf("KEY: %s %X \n", data, result);
-
- return abs(result);
+ // printf("KEY: %s %X \n", data, result);
+
+ return abs(result);
}
struct hashtable*
hashtable_create(int capacity)
{
- // NOTE_F;
-
+ // NOTE_F;
+
int i = 0;
struct hashtable *new_table = NULL;
new_table =
- (struct hashtable*) malloc(sizeof(struct hashtable));
+ (struct hashtable*) malloc(sizeof(struct hashtable));
if (! new_table)
return (NULL);
new_table->size = 0;
- new_table->capacity = capacity;
+ new_table->capacity = capacity;
new_table->array =
(struct klist**) malloc(sizeof(struct klist*) * capacity);
@@ -86,8 +86,8 @@
{
struct klist* new_klist = klist_create();
if (! new_klist)
- return NULL;
- new_table->array[i] = new_klist;
+ return NULL;
+ new_table->array[i] = new_klist;
}
return (new_table);
@@ -96,43 +96,52 @@
void
hashtable_free(struct hashtable* target)
{
- // NOTE_F;
-
- int i;
- for (i = 0; i < target->capacity; i++)
+ // NOTE_F;
+
+ for (int i = 0; i < target->capacity; i++)
klist_free(target->array[i]);
-
+
free(target->array);
free(target);
return;
}
-bool
+void
+hashtable_destroy(struct hashtable* target)
+{
+ for (int i = 0; i < target->capacity; i++)
+ klist_destroy(target->array[i]);
+
+ free(target->array);
+ free(target);
+}
+
+bool
hashtable_add(struct hashtable *table, char* key, void* data)
{
- // NOTE_F;
-
+ // NOTE_F;
+
int index = hash_string(key, table->capacity);
struct klist_item* new_item =
- klist_add(table->array[index], key, data);
-
+ klist_add(table->array[index], key, data);
+
if (! new_item)
{
printf("No new item! \n");
- return false;
+ return false;
}
- table->size++;
-
- return true;
+ table->size++;
+
+ return true;
}
/**
- @return A pointer to the matching data or NULL if not found.
+ @return A pointer to the matching data or NULL if not found.
*/
-void*
+void*
hashtable_search(struct hashtable* table, char* key)
{
struct klist_item* item = NULL;
@@ -141,24 +150,24 @@
for (item = table->array[index]->head; item;
item = item->next)
if (strcmp(key, item->key) == 0)
- return item->data;
+ return item->data;
return NULL;
}
/** format specifies the output format for the data items
- */
+ */
void
hashtable_dump(char* format, struct hashtable* target)
{
- char s[200];
+ char s[200];
int i;
printf("{\n");
for (i = 0; i < target->capacity; i++)
if (target->array[i]->size > 0)
{
klist_tostring(s, 200, "%s", target->array[i]);
- printf("%i: %s \n", i, s);
+ printf("%i: %s \n", i, s);
}
printf("}\n");
}
@@ -171,7 +180,7 @@
for (i = 0; i < target->capacity; i++)
if (target->array[i]->size)
{
- printf("%i:", i);
+ printf("%i:", i);
klist_dumpkeys(target->array[i]);
}
printf("}\n");
@@ -180,32 +189,32 @@
/** Dump klist to string a la snprintf()
size must be greater than 2.
format specifies the output format for the data items
- internally allocates O(size) memory
+ internally allocates O(size) memory
returns int greater than size if size limits are exceeded
- indicating result is garbage
+ indicating result is garbage
*/
int hashtable_tostring(char* str, size_t size,
char* format, struct hashtable* target)
{
- int error = size+1;
- char* ptr = str;
+ int error = size+1;
+ char* ptr = str;
int i;
ptr += sprintf(str, "{\n");
- char* s = (char*) malloc(sizeof(char) * size);
-
+ char* s = (char*) malloc(sizeof(char) * size);
+
for (i = 0; i < target->capacity; i++)
{
int r = klist_tostring(s, size, format, target->array[i]);
if ((ptr-str) + r + 2 < size)
ptr += sprintf(ptr, "%s\n", s);
else
- return error;
+ return error;
}
sprintf(ptr, "}\n");
free(s);
- return (ptr-str);
+ return (ptr-str);
}
/**
@@ -218,9 +227,9 @@
{
struct hashtable* table = hashtable_create(11);
- hashtable_add(table, "key1", "val1");
-
+ hashtable_add(table, "key1", "val1");
+
hashtable_dump("%s", table);
-
+
}
-#endif
+#endif
Modified: src/adts/klist.c
===================================================================
--- src/adts/klist.c 2010-05-20 23:58:01 UTC (rev 137)
+++ src/adts/klist.c 2010-05-21 15:09:09 UTC (rev 138)
@@ -1,34 +1,34 @@
#include <stdio.h>
-#include <string.h>
+#include <string.h>
-#include "klist.h"
+#include "klist.h"
extern struct klist*
klist_create()
{
- // NOTE_F;
+ // NOTE_F;
struct klist* new_klist = malloc(sizeof(struct klist));
if (! new_klist)
- return NULL;
+ return NULL;
new_klist->head = NULL;
new_klist->tail = NULL;
new_klist->size = 0;
- return new_klist;
+ return new_klist;
}
-struct klist_item*
+struct klist_item*
klist_add(struct klist* target, char* key, void* data)
{
- // NOTE_FS(key);
-
+ // NOTE_FS(key);
+
struct klist_item* new_item = malloc(sizeof(struct klist_item));
if (! new_item)
return NULL;
-
- new_item->key = key;
+
+ new_item->key = key;
new_item->data = data;
- new_item->next = NULL;
+ new_item->next = NULL;
if (target->size == 0)
{
target->head = new_item;
@@ -38,12 +38,30 @@
{
target->tail->next = new_item;
}
- target->tail = new_item;
+ target->tail = new_item;
target->size++;
- return new_item;
+ return new_item;
}
/**
+ Frees keys and values.
+*/
+void
+klist_destroy(struct klist* target)
+{
+ struct klist_item* item = target->head;
+ while (item)
+ {
+ struct klist_item* next = item->next;
+ free(item->key);
+ free(item->data);
+ free(item);
+ item = next;
+ }
+ free(target);
+}
+
+/**
@param format specifies the output format for the data items
*/
void
@@ -59,9 +77,9 @@
printf(format, item->data);
else if (strcmp(format, "%i") == 0)
printf(format, *((int*) (item->data)));
- printf(")");
+ printf(")");
if (item->next)
- printf(",");
+ printf(",");
}
printf("]\n");
}
@@ -76,7 +94,7 @@
{
printf("(%s)", item->key);
if (item->next)
- printf(",");
+ printf(",");
}
printf("]\n");
}
@@ -86,65 +104,65 @@
{
ptr += sprintf(ptr, "(%s,", item->key);
ptr += sprintf(ptr, "%s)", s);
-
+
if (item->next)
ptr += sprintf(ptr, ",");
- return ptr;
+ return ptr;
}
void klist_free(struct klist* target)
{
struct klist_item* item;
- // NOTE_F;
+ // NOTE_F;
- // klist_dumpkeys(target);
+ // klist_dumpkeys(target);
- item = target->head;
+ item = target->head;
while (item)
{
- struct klist_item* next = item->next;
+ struct klist_item* next = item->next;
free(item);
- item = next;
+ item = next;
}
- free(target);
+ free(target);
}
/** Dump klist to string a la snprintf()
size must be greater than 2.
format specifies the output format for the data items
returns int greater than size if size limits are exceeded
- indicating result is garbage
- */
+ indicating result is garbage
+ */
int klist_tostring(char* str, size_t size,
char* format, struct klist* target)
{
- int error = size+1;
- char* ptr = str;
+ int error = size+1;
+ char* ptr = str;
struct klist_item* item;
if (size <= 2)
- return error;
-
+ return error;
+
ptr += sprintf(ptr, "[");
char* s = (char*) malloc(sizeof(char)*KLIST_MAX_DATUM);
-
+
for (item = target->head; item && ptr-str < size;
- item = item->next)
+ item = item->next)
{
int r = snprintf(s, KLIST_MAX_DATUM, format, item->data);
if (r > KLIST_MAX_DATUM)
- return size+1;
+ return size+1;
if ((ptr-str) + strlen(item->key) + r + 4 < size)
- ptr = append_pair(ptr, item, s);
+ ptr = append_pair(ptr, item, s);
else
- return error;
+ return error;
}
sprintf(ptr, "]");
- free(s);
- return (ptr-str);
+ free(s);
+ return (ptr-str);
}
#ifdef DEBUG_KLIST
@@ -158,7 +176,7 @@
klist_dump("%s", L);
-
+
}
#endif
Modified: src/cmpi/cmpi.c
===================================================================
--- src/cmpi/cmpi.c 2010-05-20 23:58:01 UTC (rev 137)
+++ src/cmpi/cmpi.c 2010-05-21 15:09:09 UTC (rev 138)
@@ -107,7 +107,7 @@
Obtain pointer to requested data
@param key Locate the data for this key
@param data OUT Store data pointer here
- @return length of data
+ @return length of data, 0 if data is NULL
*/
int
cmpi_cached_retrieve(char* key, char** data)
@@ -126,7 +126,7 @@
result = found->length;
printf("length: %i\n", result);
// free(found->key);
- // free(found);
+ free(found);
}
else
{
@@ -220,7 +220,7 @@
// free(kv);
}
*/
- // lru_table_free(cmpi_cache);
+ lru_table_free(cmpi_cache);
// NOTE("free cmpi_params");
hashtable_free(cmpi_params);
}
Modified: src/cmpi-cp/cmpi-cp.c
===================================================================
--- src/cmpi-cp/cmpi-cp.c 2010-05-20 23:58:01 UTC (rev 137)
+++ src/cmpi-cp/cmpi-cp.c 2010-05-21 15:09:09 UTC (rev 138)
@@ -5,6 +5,17 @@
#include <cmpi-types.h>
+#ifdef DMALLOC
+#include <dmalloc.h>
+void setup_dmalloc()
+{
+ dmalloc_logpath = strdup("dmalloc_cmpicp.out");
+ printf("dmalloc_logpath: %s\n", dmalloc_logpath);
+}
+#else
+#define setup_malloc()
+#endif
+
char* target1;
char* target2;
@@ -120,7 +131,7 @@
int count, c;
int length;
- // printf("cmpi_cp_get()\n");
+ printf("cmpi_cp_get()\n");
// fflush(stdout);
fprintf(to_cmpi, "get %s\n", object);
Modified: src/cmpi-cp/module.mk.in
===================================================================
--- src/cmpi-cp/module.mk.in 2010-05-20 23:58:01 UTC (rev 137)
+++ src/cmpi-cp/module.mk.in 2010-05-21 15:09:09 UTC (rev 138)
@@ -4,12 +4,12 @@
DIR := src/cmpi-cp
PROGS += bin/cmpi-cp
-CMPICP_SRC += src/cmpi-cp/cmpi-cp.c
+CMPICP_SRC += src/cmpi-cp/cmpi-cp.c
CMPICP_OBJS = src/cmpi-cp/cmpi-cp.o src/cmpi/accessor.o src/mpi_tools/io_tools.o
ifneq ($(DMALLOC_LIB),)
- CMPI_CP_LIBS += -L $(DMALLOC_LIB) -l dmalloc
+ CMPICP_LIBS += -L $(DMALLOC_LIB) -l dmalloc
endif
src/cmpi-cp/cmpi-cp.o: src/cmpi-cp/cmpi-cp.c
@@ -19,4 +19,4 @@
bin/cmpi-cp: $(CMPICP_OBJS)
$(Q) " LINK $(@) "
$(E) install -d bin
- $(E) $(CC) $(CMPICP_OBJS) -o $(@)
+ $(E) $(CC) $(CMPICP_OBJS) $(CMPICP_LIBS) -o $(@)
Modified: test/cmpi/module.mk.in
===================================================================
--- test/cmpi/module.mk.in 2010-05-20 23:58:01 UTC (rev 137)
+++ test/cmpi/module.mk.in 2010-05-21 15:09:09 UTC (rev 138)
@@ -33,6 +33,7 @@
$(E) $(MPICC) $(MPE) $(<) test/cmpi/test_helpers.o src/cmpi/node.o \
$(CMPI) $(LIBS) -o $(@)
+
else
$(DIR)/test%.x: $(DIR)/test%.o $(DIR)/test_helpers.o src/cmpi/client.o $(CMPI)
Modified: test/cmpi-db/test-loop.zsh
===================================================================
--- test/cmpi-db/test-loop.zsh 2010-05-20 23:58:01 UTC (rev 137)
+++ test/cmpi-db/test-loop.zsh 2010-05-21 15:09:09 UTC (rev 138)
@@ -12,12 +12,26 @@
LOOPS=10
+cmpicp_error()
+{
+ ERR=$1
+ if [[ ${ERR} != 0 ]]
+ then
+ cat cmpi-cp.out
+ rm -v cmpi-cp.out
+ print "cmpi-cp error: ${ERR}"
+ kill ${DB_PID}
+ kill ${BOMB_PID}
+ crash "failed"
+ fi
+}
+
source tools/test-helpers.zsh
mpiexec -n ${TOTAL} bin/cmpi-db -n ${NODES} >& ${OUTPUT} &
DB_PID=${!}
-tools/timebomb.zsh ${DB_PID} $(( TOTAL*4 + LOOPS )) ${OUTPUT} $0 &
+tools/timebomb.zsh ${DB_PID} $(( TOTAL*6 + LOOPS*4 )) ${OUTPUT} $0 &
BOMB_PID=${!}
sleep ${TOTAL}
@@ -28,28 +42,18 @@
echo "DATA_${i}" > test-cp.input.data
echo "cmpi-cp insert" >>& cmpi-cp.out
bin/cmpi-cp test-cp.input.data dht://test-${i} >>& cmpi-cp.out
- if [[ $? != 0 ]]
- then
- cat cmpi-cp.out
- rm -v cmpi-cp.out
- crash "cmpi-cp error!"
- fi
+ cmpicp_error ${?}
echo "\n\ncmpi-cp retrieve" >>& cmpi-cp.out
bin/cmpi-cp dht://test-${i} test-cp.output.data >>& cmpi-cp.out
+ cmpicp_error ${?}
echo "\n read: " >>& cmpi-cp.out
cat test-cp.output.data >>& cmpi-cp.out
echo "\n" >>& cmpi-cp.out
- if [[ $? != 0 ]]
- then
- cat cmpi-cp.out
- rm -v cmpi-cp.out
- crash "cmpi-cp error!"
- fi
done
bin/cmpi-db-quit >& /dev/null
-QUIT_PROCESS=$!
+# QUIT_PROCESS=${!}
wait ${DB_PID}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|