From: glenrendes Date: Fri, 10 May 2019 08:21:02 +0000 (+0200) Subject: some cleanup, still buggy X-Git-Url: https://git.reasoningtechnology.com/style/static/%7Bstyle.link%7D?a=commitdiff_plain;h=c5cc338ceb6ecdfffcd69dc0d29979e7d916ba86;p=subu some cleanup, still buggy --- diff --git a/module/da/doc/acc_usermanual.txt b/module/da/doc/acc_usermanual.txt index 25db81d..9824353 100644 --- a/module/da/doc/acc_usermanual.txt +++ b/module/da/doc/acc_usermanual.txt @@ -1,6 +1,9 @@ Explanation of process for using accounting code. - First, acc_open(&acc_live_channels, mode); ---acc_NULL or acc_SELF only, decide whether to track memory allocation for channels themselves + First, + AccChannel acc_live_channels; needs to be declared at global scope in the CLI file. + acc_open(&acc_live_channels, mode); needs to be called in main. + ---acc_NULL or acc_SELF only, decide whether to track memory allocation for channels themselves To begin an accounting channel, declare an Acc_channel and initialize it by passing a pointer to it into acc_open. You will also need to pass in a Mode. diff --git a/module/da/include/acc.h b/module/da/include/acc.h index 867cee9..5369191 100644 --- a/module/da/include/acc.h +++ b/module/da/include/acc.h @@ -1,6 +1,9 @@ #ifndef ACC_LIB_H #define ACC_LIB_H +#define malloc crash_and_burn_malloc +#define free crash_and_burn_free + typedef struct AccChannel_struct AccChannel; typedef struct Da_struct Da; // Da_struct defined in da.lib.h diff --git a/module/da/include/da.h b/module/da/include/da.h deleted file mode 100644 index e9cc718..0000000 --- a/module/da/include/da.h +++ /dev/null @@ -1,73 +0,0 @@ -#ifndef DA_LIB_H -#define DA_LIB_H -#include -#include -#include -#include - -typedef struct AccChannel_struct AccChannel; // AccChannel_struct defined in acc.lib.h -typedef struct Da_struct Da; - -struct Da_struct{ - char *base; - char *end; // one byte/one element off the end of the array - size_t size; // size >= (end - base) + 1; - size_t element_size; - AccChannel *channel; -}; - -// constructors / destructors -// - Da *da_init(Da *dap, size_t element_size, AccChannel *channel);//calls da_malloc for base pointer - void da_free(Da *dap); - void da_rewind(Da *dap); - void da_rebase(Da *dap, char *old_base, void *pta); - char *da_expand(Da *dap); - bool da_boundq(Da *dap); - void da_erase(Da *dap); - -// status / attributes -// - bool da_is_empty(Da *dap); - bool da_equal(Da *da_0, Da *da_1); - size_t da_length(Da *dap); - bool da_length_equal(Da *dap0, Da *dap1); - -// accessing -// - char *da_index(Da *dap, size_t i); - char *da_push(Da *dap, void *element); - bool da_pop(Da *dap, void *element); - -// iteration, f is given a pointer to an element and a pointer to the closure - bool da_endq(Da *dap, void *pt); - bool da_right_bound(Da *dap, void *pt); - void da_foreach(Da *dap, void f(void *, void *), void *closure); //used to be da_map - bool da_exists(Da *dap, bool f(void *, void*), void *closure); - bool da_all(Da *dap, bool f(void *, void*), void *closure); - -// elements are pointers -// would be better if exists returned NULL or a pointer to the existing element- - void *da_pts_exists(Da *dap, void *test_element); - void da_pts_free_all(Da *dap); // calls free on all elements - void da_pts_nullify(Da *dap, void **ept); // sets *ept to NULL, pops all NULLs from top of stack - -// elements are integers - void da_ints_print(Da *dap, char *sep); - bool da_integer_repeats(Da *dap); - int da_integer_sum(Da *dap); - -// the array itself is a string -// careful if you add a null terminator it will become part of the da_string, affects iteration etc. - char *da_string_input(Da *dap, FILE *file); - void da_string_push(Da *dap0, char *string); - void da_cat(Da *dap_base, Da *dap_cat); - -// when the array holds pointers to C strings - void da_strings_print(Da *dap, char *sep); - bool da_strings_exists(Da *string_arrp, char *test_string); - void da_strings_set_insert(Da *string_arrp, char *proffered_string, void destruct(void *)); - void da_strings_set_union(Da *string_arrp, Da *proffered_string_arrp, void destruct(void *)); - -#endif - diff --git a/module/da/lib/libda.a b/module/da/lib/libda.a deleted file mode 100644 index b53b22e..0000000 Binary files a/module/da/lib/libda.a and /dev/null differ diff --git a/module/da/src/acc.lib.c b/module/da/src/acc.lib.c index 95f62f6..5e956c2 100644 --- a/module/da/src/acc.lib.c +++ b/module/da/src/acc.lib.c @@ -9,6 +9,8 @@ dynamic memory accounting #include "da.lib.h" #include "acc.lib.h" +#undef malloc +#undef free //----------------------------------------------------------------- //function definitions for accounting @@ -30,7 +32,7 @@ AccChannel *acc_open(AccChannel *channel, Mode mode){//acc init return channel; } else if( acc_live_channels.mode == acc_SELF ){//accounting tracks itself - channel = (AccChannel *)acc_malloc(sizeof(AccChannel), &acc_live_channels); + //channel = acc_malloc(sizeof(AccChannel), &acc_live_channels); Da os; Da sf; channel->outstanding_malloc = da_init(&os, sizeof(void *), NULL); channel->spurious_free = da_init(&sf, sizeof(void *), NULL); @@ -63,14 +65,14 @@ void acc_free(void *pt, AccChannel *channel){ } static void count_balance(void *element, void *closure){ int *counter = (int *)closure; - if( (void *)element ) (*counter)++; + if( element ) (*counter)++; } static void acc_rep_helper_BALANCE(AccChannel *channel){ int count = 0; da_foreach((Da *)channel->outstanding_malloc, count_balance, &count); printf("There are %d outstanding allocations.\n", count); - count = 0; - da_foreach((Da *)channel->spurious_free, count_balance, &count); + int count1 = 0; + da_foreach((Da *)channel->spurious_free, count_balance, &count1); printf("There are %d spurious frees.\n", count); } static void print_pointer(void *element, void *closure){ @@ -80,7 +82,7 @@ static void acc_rep_helper_FULL(AccChannel *channel){ int count = 0; da_foreach((Da *)channel->outstanding_malloc, count_balance, &count); printf("There are %d outstanding mallocs.\n", count); - if( count < 10 ){ + if( 0 < count && count < 10 ){ printf("The outstanding allocated pointers are: "); da_foreach((Da *)channel->outstanding_malloc, print_pointer, NULL); printf(".\n"); @@ -88,7 +90,7 @@ static void acc_rep_helper_FULL(AccChannel *channel){ count = 0; da_foreach((Da *)channel->spurious_free, count_balance, &count); printf("There are %d spurious frees.\n", count); - if( count < 10 ){ + if( 0 < count && count < 10 ){ printf("The spuriously freed pointers are: "); da_foreach((Da *)channel->outstanding_malloc, print_pointer, NULL); printf(".\n"); @@ -96,13 +98,13 @@ static void acc_rep_helper_FULL(AccChannel *channel){ } AccChannel *acc_report(AccChannel *channel){ if( channel->mode == acc_NULL ){ - printf("Accounting mode is NULL."); + printf("Accounting mode is NULL.\n"); return channel; } if( channel->mode == acc_BALANCE ){ printf("Accounting mode is BALANCE.\n"); if( da_is_empty((Da *)(channel->outstanding_malloc)) && da_is_empty((Da *)(channel->spurious_free)) ){ - printf("This channel is in balance."); + printf("This channel is in balance.\n"); } else{ printf("This channel is out of balance.\n"); @@ -113,7 +115,7 @@ AccChannel *acc_report(AccChannel *channel){ if( channel->mode == acc_FULL ){ printf("Accounting mode is FULL.\n"); if( da_is_empty((Da *)(channel->outstanding_malloc)) && da_is_empty((Da *)(channel->spurious_free)) ){ - printf("This channel is in balance."); + printf("This channel is in balance.\n"); } else{ printf("This channel is out of balance.\n"); @@ -124,7 +126,7 @@ AccChannel *acc_report(AccChannel *channel){ if( channel->mode == acc_SELF ){ printf("Accounting mode is SELF.\n"); if( da_is_empty((Da *)(channel->outstanding_malloc)) && da_is_empty((Da *)(channel->spurious_free)) ){ - printf("There are no open channels."); + printf("There are no open channels.\n"); } else { printf("The accounting code is out of balance.\n"); diff --git a/module/da/src/acc.lib.h b/module/da/src/acc.lib.h index 867cee9..5369191 100644 --- a/module/da/src/acc.lib.h +++ b/module/da/src/acc.lib.h @@ -1,6 +1,9 @@ #ifndef ACC_LIB_H #define ACC_LIB_H +#define malloc crash_and_burn_malloc +#define free crash_and_burn_free + typedef struct AccChannel_struct AccChannel; typedef struct Da_struct Da; // Da_struct defined in da.lib.h diff --git a/module/da/src/da.lib.c b/module/da/src/da.lib.c index f043357..768a0a8 100644 --- a/module/da/src/da.lib.c +++ b/module/da/src/da.lib.c @@ -143,7 +143,7 @@ void da_foreach(Da *dap, void f(void *, void *), void *closure){ //---> should return the element pointer, same for da_pts_exists static bool da_quantifier(bool complement, Da *dap, bool pred(void *, void*), void *closure){ char *pt = dap->base; - bool result = false; + bool result = !complement; while( (complement? !result : result) && (pt != dap->end) ){ result = pred(pt, closure); pt += dap->element_size; diff --git a/module/da/src/da.lib.h b/module/da/src/da.lib.h index e9cc718..3611064 100644 --- a/module/da/src/da.lib.h +++ b/module/da/src/da.lib.h @@ -13,7 +13,7 @@ struct Da_struct{ char *end; // one byte/one element off the end of the array size_t size; // size >= (end - base) + 1; size_t element_size; - AccChannel *channel; + AccChannel *channel;//assign during init, set to NULL during free }; // constructors / destructors diff --git a/module/da/test/src/test_da.cli.c b/module/da/test/src/test_da.cli.c index 696d43e..1b87cae 100644 --- a/module/da/test/src/test_da.cli.c +++ b/module/da/test/src/test_da.cli.c @@ -3,14 +3,13 @@ #include #include "test_da.lib.h" #include +#include -Da heap_acc; -Da extra_frees; -bool accounting = false; +AccChannel acc_live_channels; int main(){ - ACCOUNT; - // enumeration of tests + acc_open(&acc_live_channels, acc_SELF); + // enumeration of tests typedef bool (*test_fun)(); test_fun tests[] = { @@ -26,20 +25,20 @@ int main(){ test_da_strings_exists_0, test_da_rebase_0, test_da_boundq_0, - test_da_map_0, - test_da_present_0, + test_da_foreach_0, + //test_da_present_0, test_da_exists_0, test_da_exists_1, test_da_all_0, - test_da_alloc_0, + test_da_init_0, test_da_free_0, - test_da_empty_0, + test_da_is_empty_0, test_da_length_0, - test_da_push_row_0, - test_da_erase_0, - test_da_longer_0, - test_da_longest_0, - da_result_accounting, + // test_da_push_row_0, + // test_da_erase_0, + // test_da_longer_0, + // test_da_longest_0, + test_da_accounting_0, NULL}; char *test_names[] = { @@ -55,20 +54,20 @@ int main(){ "test_da_strings_exists_0", "test_da_rebase_0", "test_da_boundq_0", - "test_da_map_0", - "test_da_present_0", + "test_da_foreach_0", + //"test_da_present_0", "test_da_exists_0", "test_da_exists_1", "test_da_all_0", - "test_da_alloc_0", + "test_da_init_0", "test_da_free_0", - "test_da_empty_0", + "test_da_is_empty_0", "test_da_length_0", - "test_da_push_row_0", - "test_da_erase_0", - "test_da_longer_0", - "test_da_longest_0", - "da_result_accounting", + //"test_da_push_row_0", + //"test_da_erase_0", + //"test_da_longer_0", + //"test_da_longest_0", + "test_da_accounting_0", NULL}; // call tests bool da_0_passed = true; @@ -88,7 +87,7 @@ int main(){ tfp++; tnp++; } - + acc_report(&acc_live_channels); // summarize results if( passed == 0 && failed == 0) printf("no tests ran\n"); @@ -99,7 +98,6 @@ int main(){ else printf("failed %u of %u tests\n", failed, passed + failed); - CLOSE_ACC; - if( passed == 0 || failed != 0 ) return 1; + if( passed == 0 || failed != 0 ) return 1; return 0; } diff --git a/module/da/test/src/test_da.lib.c b/module/da/test/src/test_da.lib.c index 6e9bad6..453fb45 100644 --- a/module/da/test/src/test_da.lib.c +++ b/module/da/test/src/test_da.lib.c @@ -7,13 +7,15 @@ Tests for Da. #include #include #include +#include #include "test_da.lib.h" + // tests push bool test_da_push_0(){ Da da; - da_alloc(&da, sizeof(int)); // leaves room for 4 ints + da_init(&da, sizeof(int), NULL); // leaves room for 4 ints int i = 0; int *pt = (int *)da.base; // will double, 4 -> 8, then double 8 -> 16 @@ -41,7 +43,7 @@ bool test_da_push_0(){ // tests manual expansion bool test_da_expand_0(){ Da da; - da_alloc(&da, sizeof(int)); // leaves room for 4 ints + da_init(&da, sizeof(int), NULL); // leaves room for 4 ints int i = 0; int *pt = (int *)da.base; // will double, 4 -> 8, then double 8 -> 16 @@ -82,7 +84,7 @@ bool test_da_string_input_0(){ } Da da; - da_alloc(&da, sizeof(char)); + da_init(&da, sizeof(char), NULL); da_string_input(&da, file); bool flag0 = !strcmp(da.base, "this is a test"); @@ -111,7 +113,7 @@ bool test_da_string_input_0(){ bool test_da_pop_0(){ Da da; - da_alloc(&da, sizeof(int)); + da_init(&da, sizeof(int), NULL); int i = 5; da_push(&da, &i); @@ -133,8 +135,8 @@ bool test_da_pop_0(){ bool test_da_cat_0(){ Da da0, da1; - da_alloc(&da0, sizeof(int)); - da_alloc(&da1, sizeof(int)); + da_init(&da0, sizeof(int), NULL); + da_init(&da1, sizeof(int), NULL); int i = 5; while(i < 8){ @@ -171,8 +173,8 @@ bool test_da_cat_0(){ bool test_da_cat_1(){ Da dar0; Da dar1; - da_alloc(&dar0, sizeof(int)); - da_alloc(&dar1, sizeof(int)); + da_init(&dar0, sizeof(int), NULL); + da_init(&dar1, sizeof(int), NULL); int n = 2; { int m = 0; @@ -206,7 +208,7 @@ bool test_da_cat_1(){ bool test_da_rewind_0(){ int i = 10; Da dar; - da_alloc(&dar, sizeof(int)); + da_init(&dar, sizeof(int), NULL); while(i < 18){ da_push(&dar, &i); ++i; @@ -227,7 +229,7 @@ bool test_da_rewind_0(){ bool test_da_index_0(){ Da dar; Da *dar_pt = &dar; - da_alloc(dar_pt, sizeof(int)); + da_init(dar_pt, sizeof(int), NULL); bool flag[4]; @@ -254,7 +256,7 @@ bool test_da_index_0(){ bool test_da_free_elements_0(){ Da dar; Da *dar_pt = &dar; - da_alloc(dar_pt, sizeof(int*)); + da_init(dar_pt, sizeof(int*), NULL); int i = 3; int *i_pt = &i; @@ -273,7 +275,7 @@ bool test_da_free_elements_0(){ bool test_da_strings_exists_0(){ Da dar; Da *dar_pt = &dar; - da_alloc(dar_pt, sizeof(char *)); + da_init(dar_pt, sizeof(char *), NULL); //fill dar with strings char *string0 = "nope"; @@ -307,9 +309,9 @@ bool test_da_strings_exists_0(){ //tests rebase bool test_da_rebase_0(){ Da dar; - da_alloc(&dar,sizeof(char)); + da_init(&dar,sizeof(char), NULL); - char **el_pt = (char **)MALLOC(4*(sizeof(char*))); + char **el_pt = (char **)acc_malloc(4*(sizeof(char*)), NULL); {//push "temp" into dar, leave with pointer to last element int i = 0; char arr[4] = {'t','e','m','p'}; @@ -353,7 +355,7 @@ bool test_da_rebase_0(){ } } da_free(&dar); - FREE(el_pt); + acc_free(el_pt, NULL); return flag1 && flag2 && flag3 && result; } @@ -362,7 +364,7 @@ bool test_da_rebase_0(){ strcpy(a, "zsdf"); Da da; Da *da_pt = &da; - da_alloc(da_pt, sizeof(char *)); + da_init(da_pt, sizeof(char *)); da_push(da_pt, a); ... FREE(*(char *)da_index(da_pt, 0)); @@ -372,7 +374,7 @@ bool test_da_rebase_0(){ //tests da_boundq bool test_da_boundq_0(){ Da dar; - da_alloc(&dar,sizeof(char)); + da_init(&dar,sizeof(char), NULL); bool flag[5]; {//pushes onto dar and tests no runoff @@ -404,14 +406,14 @@ bool test_da_boundq_0(){ return result; } -//tests map -static void test_da_map_0_helper(void *pt, void *closure){ +//tests foreach +static void test_da_foreach_0_helper(void *pt, void *closure){ int *n = (int *)closure; *n += *(int *)pt; } -bool test_da_map_0(){ +bool test_da_foreach_0(){ Da dar; - da_alloc(&dar,sizeof(int)); + da_init(&dar, sizeof(int), NULL); {//pushes onto dar int arr[4] = {5,6,7,8}; @@ -425,38 +427,38 @@ bool test_da_map_0(){ int n = 0; int *closure = &n; - da_map(&dar, test_da_map_0_helper, (int *)closure); + da_foreach(&dar, test_da_foreach_0_helper, (int *)closure); //rename to da_foreach bool result = n == (5+6+7+8); da_free(&dar); return result; } - +/* //tests da_present bool test_da_present_0(){ int dar_size = 0; - Da **dar = MALLOC(3 * sizeof(Da *)); + Da **dar = acc_malloc(3 * sizeof(Da *), NULL); Da dap_0; Da *dap_0_pt = &dap_0; - da_alloc(dap_0_pt,sizeof(int)); + da_init(dap_0_pt,sizeof(int), NULL); Da dap_1; Da *dap_1_pt = &dap_1; - da_alloc(dap_1_pt,sizeof(char)); + da_init(dap_1_pt,sizeof(char), NULL); dar[dar_size] = dap_0_pt; dar_size++; dar[dar_size] = dap_1_pt; dar_size++; Da dap_2; Da *dap_2_pt = &dap_2; - da_alloc(dap_2_pt,sizeof(char *)); + da_init(dap_2_pt,sizeof(char *), NULL); dar[dar_size] = dap_2_pt; dar_size++; - /* + Da ; Da *matrix = ; - da_alloc(dar, sizeof(Dap *)); - */ + da_init(dar, sizeof(Dap *)); + typedef struct{ Da *da; bool found; @@ -483,13 +485,14 @@ bool test_da_present_0(){ bool result = flag[0] && flag[1] && flag[2] && flag[3]; da_free(dap_0_pt); da_free(dap_1_pt); da_free(dap_2_pt); - FREE(dar); + acc_free(dar, NULL); return result; } +*/ //tests for da_exists and all -bool test_exists(void *pt, void *closure){ +static bool test_exists_helper(void *pt, void *closure){ bool result = *(int*)pt == *(int *)closure; return result; } @@ -498,7 +501,7 @@ bool test_exists(void *pt, void *closure){ bool test_da_exists_0(){ Da dar; Da *dar_pt = &dar; - da_alloc(dar_pt, sizeof(int)); + da_init(dar_pt, sizeof(int), NULL); int n[5] = {5,6,7,8,9}; @@ -518,7 +521,7 @@ bool test_da_exists_0(){ int j = 0; while(j < 5){ int *n_pt = n+j; - flag[j] = da_exists(dar_pt, test_exists, n_pt); + flag[j] = da_exists(dar_pt, test_exists_helper, n_pt); j++; } } @@ -534,7 +537,7 @@ bool test_da_exists_0(){ int j = 0; while(j < 5){ int *n_pt = n+j; - flag[j] = da_exists(dar_pt, test_exists, n_pt); + flag[j] = da_exists(dar_pt, test_exists_helper, n_pt); j++; } } @@ -546,7 +549,7 @@ bool test_da_exists_0(){ bool test_da_exists_1(){//tests that expansion doesn't change results Da dar; Da *dar_pt = &dar; - da_alloc(dar_pt, sizeof(int)); + da_init(dar_pt, sizeof(int), NULL); int n[8] = {20,21,22,23,24,25,26,27}; @@ -566,7 +569,7 @@ bool test_da_exists_1(){//tests that expansion doesn't change results int j = 0; while(j < 8){ int *n_pt = n+j; - flag[j] = da_exists(dar_pt, test_exists, n_pt); + flag[j] = da_exists(dar_pt, test_exists_helper, n_pt); j++; } } @@ -586,7 +589,7 @@ bool test_da_exists_1(){//tests that expansion doesn't change results int j = 0; while(j < 8){ int *n_pt = n+j; - flag[j] = da_exists(dar_pt, test_exists, n_pt); + flag[j] = da_exists(dar_pt, test_exists_helper, n_pt); j++; } } @@ -604,7 +607,7 @@ bool test_da_exists_1(){//tests that expansion doesn't change results bool test_da_all_0(){ Da dar; Da *dar_pt = &dar; - da_alloc(dar_pt, sizeof(int)); + da_init(dar_pt, sizeof(int), NULL); int n = 5; int *n_pt = &n; @@ -615,23 +618,24 @@ bool test_da_all_0(){ da_push(dar_pt, n_pt); //tests da_all is true - bool flag1 = da_all(dar_pt, test_exists, n_pt); + bool flag1 = da_all(dar_pt, test_exists_helper, n_pt); da_pop(dar_pt, NULL); n = 6; //tests da_all is false - bool flag2 = !da_all(dar_pt, test_exists, n_pt); + bool flag2 = !da_all(dar_pt, test_exists_helper, n_pt); da_free(dar_pt); + return flag1 && flag2; } -//tests da_alloc -bool test_da_alloc_0(){ - Da da0; Da *da0_pt = &da0; da_alloc(da0_pt, sizeof(char)); - Da da1; Da *da1_pt = &da1; da_alloc(da1_pt, sizeof(int)); - Da da2; Da *da2_pt = &da2; da_alloc(da2_pt, sizeof(char *)); +//tests da_init +bool test_da_init_0(){ + Da da0; Da *da0_pt = &da0; da_init(da0_pt, sizeof(char), NULL); + Da da1; Da *da1_pt = &da1; da_init(da1_pt, sizeof(int), NULL); + Da da2; Da *da2_pt = &da2; da_init(da2_pt, sizeof(char *), NULL); bool flag[6]; //check that da is allocated as array of 4 chars @@ -659,17 +663,17 @@ bool test_da_alloc_0(){ bool test_da_free_0(){ Da da; Da *da_pt = &da; - da_alloc(da_pt, sizeof(int)); + da_init(da_pt, sizeof(int), NULL); //store location of da Da *keep = da_pt; Da *save = da_pt; - //FREE da + //acc_free da da_free(da_pt); //re-allocate memory to dew da of chars - da_alloc(keep, sizeof(char)); + da_init(keep, sizeof(char), NULL); //test that same memory is properly re-allocated bool flag1 = keep == save; @@ -678,19 +682,19 @@ bool test_da_free_0(){ return flag1 && flag2; } -//tests da_empty -bool test_da_empty_0(){ +//tests da_is_empty +bool test_da_is_empty_0(){ int i = 6; Da da; Da *da_pt = &da; - da_alloc(da_pt, sizeof(int)); + da_init(da_pt, sizeof(int), NULL); while(i < 11){ da_push(da_pt, &i); ++i; } - bool flag1 = !da_empty(da_pt); + bool flag1 = !da_is_empty(da_pt); da_rewind(da_pt); - bool flag2 = da_empty(da_pt); + bool flag2 = da_is_empty(da_pt); da_free(da_pt); return flag1 && flag2; } @@ -700,7 +704,7 @@ bool test_da_length_0(){ int i = 1; Da da; Da *da_pt = &da; - da_alloc(da_pt, sizeof(int)); + da_init(da_pt, sizeof(int), NULL); //test da_length, even pushing past expansions bool result = true; @@ -714,15 +718,16 @@ bool test_da_length_0(){ return result; } +/* //------------------------------------------------ // Matrix function tests //tests da_push_row bool test_da_push_row_0(){ - Da dama; da_alloc(&dama, sizeof(Da)); Da *damp = &dama; - Da row0; da_alloc(&row0, sizeof(int)); da_push_row(damp, &row0); - Da row1; da_alloc(&row1, sizeof(int)); da_push_row(damp, &row1); - Da row2; da_alloc(&row2, sizeof(int)); da_push_row(damp, &row2); + Da dama; da_init(&dama, sizeof(Da), NULL); Da *damp = &dama; + Da row0; da_init(&row0, sizeof(int), NULL); da_push_row(damp, &row0); + Da row1; da_init(&row1, sizeof(int), NULL); da_push_row(damp, &row1); + Da row2; da_init(&row2, sizeof(int), NULL); da_push_row(damp, &row2); bool flag0 = da_equal(&row0, (Da *)(damp->base)); bool flag1 = da_equal(&row1, (Da *)(damp->base + damp->element_size)); @@ -741,21 +746,21 @@ bool test_da_push_row_0(){ //tests da_erase bool test_da_erase_0(){ - Da dama; da_alloc(&dama, sizeof(Da)); Da *damp = &dama; - Da row0; da_alloc(&row0, sizeof(int)); da_push_row(damp, &row0); - Da row1; da_alloc(&row1, sizeof(int)); da_push_row(damp, &row1); - Da row2; da_alloc(&row2, sizeof(int)); da_push_row(damp, &row2); + Da dama; da_init(&dama, sizeof(Da), NULL); Da *damp = &dama; + Da row0; da_init(&row0, sizeof(int), NULL); da_push_row(damp, &row0); + Da row1; da_init(&row1, sizeof(int), NULL); da_push_row(damp, &row1); + Da row2; da_init(&row2, sizeof(int), NULL); da_push_row(damp, &row2); //store location of da Da *keep = damp; Da *save = damp; - //FREE da + //free da da_free_elements(damp); da_erase(damp); //re-allocate memory to dew da of chars - da_alloc(keep, sizeof(char)); + da_init(keep, sizeof(char), NULL); //test that same memory is properly re-allocated bool flag1 = keep == save; @@ -767,9 +772,9 @@ bool test_da_erase_0(){ //tests da_longer bool test_da_longer_0(){ - Da dama; Da *damp = &dama; da_alloc(damp, sizeof(Da)); + Da dama; Da *damp = &dama; da_init(damp, sizeof(Da), NULL); - Da row0; Da *r0 = &row0; da_alloc(r0, sizeof(int)); + Da row0; Da *r0 = &row0; da_init(r0, sizeof(int), NULL); {//fills first row with 4 integers int i = 10; while(i<14){ @@ -779,7 +784,7 @@ bool test_da_longer_0(){ } da_push_row(damp, r0); - Da row1; Da *r1 = &row1; da_alloc(r1, sizeof(int)); + Da row1; Da *r1 = &row1; da_init(r1, sizeof(int), NULL); {//fills second row with 4 different integers int i = 20; while(i<24){ @@ -789,7 +794,7 @@ bool test_da_longer_0(){ } da_push_row(damp, r1); - Da row2; Da *r2 = &row2; da_alloc(r2, sizeof(int)); + Da row2; Da *r2 = &row2; da_init(r2, sizeof(int), NULL); {//fills third row with 6 integers int i = 30; while(i<36){ @@ -823,9 +828,9 @@ bool test_da_longer_0(){ //tests da_longest bool test_da_longest_0(){ - Da dama; Da *damp = &dama; da_alloc(damp, sizeof(Da)); + Da dama; Da *damp = &dama; da_init(damp, sizeof(Da), NULL); - Da row0; Da *r0 = &row0; da_alloc(r0, sizeof(int)); + Da row0; Da *r0 = &row0; da_init(r0, sizeof(int), NULL); {//fills first row with 4 integers int i = 10; while(i<14){ @@ -835,7 +840,7 @@ bool test_da_longest_0(){ } da_push_row(damp, r0); - Da row1; Da *r1 = &row1; da_alloc(r1, sizeof(int)); + Da row1; Da *r1 = &row1; da_init(r1, sizeof(int), NULL); {//fills second row with 4 different integers int i = 20; while(i<24){ @@ -845,7 +850,7 @@ bool test_da_longest_0(){ } da_push_row(damp, r1); - Da row2; Da *r2 = &row2; da_alloc(r2, sizeof(int)); + Da row2; Da *r2 = &row2; da_init(r2, sizeof(int), NULL); {//fills third row with 6 integers int i = 30; while(i<36){ @@ -865,15 +870,36 @@ bool test_da_longest_0(){ da_erase(damp); return flag; } +*/ + +bool test_da_accounting_0(){ + AccChannel acc0; + AccChannel *acc0_pt = acc_open(&acc0, acc_NULL); + + //Da da0; + //Da *dap = &da0; + //da_init(dap, sizeof(int), acc0_pt); + + printf("Outstanding Malloc: %d\n", (int)(acc0_pt->outstanding_malloc)); + printf("Spurious Free: %d\n", (int)(acc0_pt->spurious_free)); + acc_report(acc0_pt); + + //da_free(dap); + //acc_close(acc0_pt); + + //acc_close(acc0_pt); + bool result = true; + return result; +} -/* +/*need to update list Functions --da_alloc +-da_init -da_free -da_rewind --da_empty +-da_is_empty -da_length -da_rebase -da_expand @@ -883,7 +909,7 @@ bool test_da_longest_0(){ -da_push -da_pop da_endq --da_map +-da_foreach da_free_elements da_ints_print da_integer_repeats @@ -936,14 +962,14 @@ test_da_free_elements_0 test_da_strings_exists_0 test_da_rebase_0 test_da_boundq_0 -test_da_map_0 +test_da_foreach_0 test_da_present_0 test_da_exists_0 test_da_exists_1 test_da_all_0 -test_da_alloc_0 +test_da_init_0 test_da_free_0 -test_da_empty_0 +test_da_is_empty_0 test_da_length_0 //matrix diff --git a/module/da/test/src/test_da.lib.h b/module/da/test/src/test_da.lib.h index 9a7c33a..958dd38 100644 --- a/module/da/test/src/test_da.lib.h +++ b/module/da/test/src/test_da.lib.h @@ -13,18 +13,19 @@ bool test_da_free_elements_0(); bool test_da_strings_exists_0(); bool test_da_rebase_0(); bool test_da_boundq_0(); -bool test_da_map_0(); +bool test_da_foreach_0(); bool test_da_present_0(); bool test_da_exists_0(); bool test_da_exists_1(); bool test_da_all_0(); -bool test_da_alloc_0(); +bool test_da_init_0(); bool test_da_free_0(); -bool test_da_empty_0(); +bool test_da_is_empty_0(); bool test_da_length_0(); -bool test_da_push_row_0(); -bool test_da_erase_0(); -bool test_da_longer_0(); -bool test_da_longest_0(); +//bool test_da_push_row_0(); +//bool test_da_erase_0(); +//bool test_da_longer_0(); +//bool test_da_longest_0(); +bool test_da_accounting_0(); #endif