From c5cc338ceb6ecdfffcd69dc0d29979e7d916ba86 Mon Sep 17 00:00:00 2001 From: glenrendes Date: Fri, 10 May 2019 10:21:02 +0200 Subject: [PATCH] some cleanup, still buggy --- module/da/doc/acc_usermanual.txt | 5 +- module/da/include/acc.h | 3 + module/da/include/da.h | 73 ------------ module/da/lib/libda.a | Bin 37848 -> 0 bytes module/da/src/acc.lib.c | 22 ++-- module/da/src/acc.lib.h | 3 + module/da/src/da.lib.c | 2 +- module/da/src/da.lib.h | 2 +- module/da/test/src/test_da.cli.c | 50 ++++----- module/da/test/src/test_da.lib.c | 186 ++++++++++++++++++------------- module/da/test/src/test_da.lib.h | 15 +-- 11 files changed, 162 insertions(+), 199 deletions(-) delete mode 100644 module/da/include/da.h delete mode 100644 module/da/lib/libda.a 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 b53b22e0e32d34dc4c065ce131f0843de29abfaa..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 37848 zcmeHw3w&Hvwf8xh?8)SvG<~FLTBc9>%%kr&DKusJf>Nlq(2`7&$piBuGgDdwiV1KV zW3>U)g82|XMM13>A0Sf1Se1uY1z(qnsFe#|u;8s0FS%0aU2E;N&g|Kp0blp?`+mP~ z|B^Xp|MzKfubox)?G#NHIHYwK)_IdGJGPvn}m&L%{9A`M}X24|5y-5?Fm8oJ`0 zO;_VtTeL3H(H+}M1>I$CeG?2QUWp~d$6E89wmbAu5MywaXoD6V#ZJkiw-2(??g+rtz(gRiN zj)b*Pfuivaq=?3Vw#8r(AfZu^Xe0&#qY?1E!H8(Qv#qN$0RmNb+#vFN&=`(6*lrc= zZ4DJ&+=02@RxO0?x^UUDCG+{Sx~gh%6=2m17cN{%J-0q*U+t!K8LkW6S0~q5?Id!7 zI!@Js#CZ*!);MFF(ayF||BIo%SGq&}*B|PS-yRxJSQuJXdnkTc=s@k=4`cSx0Al@* zzl51k|IyGu?V(VA5tKjuHsxCaNH?(U_WmtJc=qzoky|Sms42R6IDX0BS;L9z65{(t zeDOA^PXA-yC`wy~hiK-n(Q=m#OIk7?zFf!mA z*y7?zf6>8RNxpcz_B8bzw3O<7I&@&s7tWkHBXu9BJ>CCU=)fwZdI&$LrIOglION;? zj(lQj-z!DX65!+bNicK7iH+B0rcjk&p~g$nj17f~-+b$x42Ej-jb!gzdR9$9FV>s} z3rM=sr~=czO@(j%yXpOnA<5L6sJ(U=HYN?wvQ#x0dHGV9VaSy=MSUY~yv3A-I5skO zd+1%~Y6u!Ift8#k_(bVhQh@xyH^Jv1@#W*tDLj=K@ustg|86Q@W0fbmJ$=6aNqsko zKF1sVUMm=mw4EqZ8w_RiFiqRgXgKYaYT7Y4kc`oM!j*Q0K_MelpE}NEt&yHcFbx0G zn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Channel *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 -- 2.20.1