bldc/tests/test_heap_alloc.c

78 lines
1.8 KiB
C
Raw Normal View History

#include <stdlib.h>
#include <stdio.h>
#include "heap.h"
#include "symrepr.h"
#define GC_STACK_SIZE 256
int main(int argc, char **argv) {
(void)argc;
(void)argv;
int res = 1;
lbm_cons_t *heap_storage = NULL;
unsigned int heap_size = 1024 * 1024;
uint32_t cell;
res = lbm_symrepr_init();
if (!res) {
printf("Error initializing symrepr\n");
return 0;
}
printf("Initialized symrepr: OK\n");
lbm_uint *memory = NULL;
lbm_uint *bitmap = NULL;
memory = malloc(sizeof(lbm_uint) * LBM_MEMORY_SIZE_14K);
if (memory == NULL) return 0;
bitmap = malloc(sizeof(lbm_uint) * LBM_MEMORY_BITMAP_SIZE_14K);
if (bitmap == NULL) return 0;
res = lbm_memory_init(memory, LBM_MEMORY_SIZE_14K,
bitmap, LBM_MEMORY_BITMAP_SIZE_14K);
heap_storage = (lbm_cons_t*)malloc(sizeof(lbm_cons_t) * heap_size);
if (heap_storage == NULL) {
return 0;
}
res = lbm_heap_init(heap_storage,heap_size, GC_STACK_SIZE);
if (!res) {
printf("Error initializing heap\n");
return 0;
}
printf("Initialized heap: OK\n");
for (unsigned int i = 0; i < heap_size; i ++) {
Squashed 'lispBM/lispBM/' changes from 6a448aa3..c097f5c6 c097f5c6 cleaning pass and refactoring 5384d522 refactoring application experiment 087ede4e refactor: readability, clearity and in some places - to a small degree - correctness 89575d8b small change to one event test ba6e7fa7 logged change 16ac6bd1 logged change 089468b3 removing make-env. in-env in the interest of keeping core language small f18015f7 Merge branch 'master' of github.com:svenssonjoel/lispbm 5b19dfda simplification and readability refactoring. 8c492889 Update gotchas.md 754221b9 Update gotchas.md a0931bac bump version e49071dc Changed behavior closure application to zero args. Application of a continuation (call-cc) with 0 args still uses the old approach where 0 args is equivalent to application to nil 35f495f3 mini tweak readme fdd01ff1 update README b21a3fa7 Update gotchas.md 92d9f561 update gotchas 0d708de7 bugfix in incremental reader and addition of a gotchas.md file for edge-case behaviors d9a38456 updated lbmref with take and drop 86b1cc1b take, drop, change to make-env returned result ea29f5ec added take and drop as built-in primitives and change to result env for make-env 55a5b1f5 added some tests and a small amount of doc e2d2f745 tweaks bccdee1f make-env and in-env 3a03232a added make-env and in-env for library-encapsulation e5b5ba66 mini tweak dce87812 removed extra ; 190b4d9e mini tweak 6864fa32 fix repl after removal of reading_done callback ea3aba39 removed reading_done_callback and made the nonsense default variants for all remaining callback 427cb37c bugfix read-program, tightening up, cleaning 119d9fd3 refactoring and tightening up 10573404 cleaning and readability 63b750b5 small tweaks d44c8bdc bug fix related to row numbers in error messages while doing incremental read. Now more precise. d0125bd1 refactoring for readability. setjmp/longjmp for escape from deeply nested errors. git-subtree-dir: lispBM/lispBM git-subtree-split: c097f5c66bd539442a48d41a66da1c657af502a1
2023-05-21 23:17:23 -07:00
cell = lbm_heap_allocate_cell(LBM_TYPE_CONS, ENC_SYM_NIL, ENC_SYM_NIL);
if (!lbm_is_ptr(cell)) {
printf("Error allocating cell %d\n", i);
return 0;
}
}
printf("Allocated %d heap cells: OK\n", heap_size);
for (int i = 0; i < 34; i ++) {
Squashed 'lispBM/lispBM/' changes from 6a448aa3..c097f5c6 c097f5c6 cleaning pass and refactoring 5384d522 refactoring application experiment 087ede4e refactor: readability, clearity and in some places - to a small degree - correctness 89575d8b small change to one event test ba6e7fa7 logged change 16ac6bd1 logged change 089468b3 removing make-env. in-env in the interest of keeping core language small f18015f7 Merge branch 'master' of github.com:svenssonjoel/lispbm 5b19dfda simplification and readability refactoring. 8c492889 Update gotchas.md 754221b9 Update gotchas.md a0931bac bump version e49071dc Changed behavior closure application to zero args. Application of a continuation (call-cc) with 0 args still uses the old approach where 0 args is equivalent to application to nil 35f495f3 mini tweak readme fdd01ff1 update README b21a3fa7 Update gotchas.md 92d9f561 update gotchas 0d708de7 bugfix in incremental reader and addition of a gotchas.md file for edge-case behaviors d9a38456 updated lbmref with take and drop 86b1cc1b take, drop, change to make-env returned result ea29f5ec added take and drop as built-in primitives and change to result env for make-env 55a5b1f5 added some tests and a small amount of doc e2d2f745 tweaks bccdee1f make-env and in-env 3a03232a added make-env and in-env for library-encapsulation e5b5ba66 mini tweak dce87812 removed extra ; 190b4d9e mini tweak 6864fa32 fix repl after removal of reading_done callback ea3aba39 removed reading_done_callback and made the nonsense default variants for all remaining callback 427cb37c bugfix read-program, tightening up, cleaning 119d9fd3 refactoring and tightening up 10573404 cleaning and readability 63b750b5 small tweaks d44c8bdc bug fix related to row numbers in error messages while doing incremental read. Now more precise. d0125bd1 refactoring for readability. setjmp/longjmp for escape from deeply nested errors. git-subtree-dir: lispBM/lispBM git-subtree-split: c097f5c66bd539442a48d41a66da1c657af502a1
2023-05-21 23:17:23 -07:00
cell = lbm_heap_allocate_cell(LBM_TYPE_CONS, ENC_SYM_NIL, ENC_SYM_NIL);
if (lbm_is_ptr(cell)) {
printf("Error allocation succeeded on empty heap\n");
return 0;
Squashed 'lispBM/lispBM/' changes from 6199703d..43ebce71 43ebce71 Fix formatting int print.c and constants that default to float/double fa220f0b update gc statistics collection a small bit 25b20686 fix get_heap_state 783d774e Arrays of 64bit values passes the associated tests. More tests are needed though ff40d02f working on 64bit arrays. more testing needed 204bea39 CMP as a macro instead of 8 different functions 44bb152d added a set of math extensions grabbed from Benjamin's bldc repo 9c34b4cd added string extensions from benjamins bldc repo b4370155 merge in changes on master into dev64bit c129344b fixed masking bug in fundamentals ed3ab5be closed down ome warnings when building 64bit d46564c9 expanded functionality of type-of to cover 64bit types and preparations for arrays of 64bit values f7cb5538 added more 64bit functionality to fundamentals and a tiny amount of tests 4dafbe6c added decoders for 64bit values 63026a8a added 64bit value literals 8c1f0f0f made GC aware of lbm_memory allocated values 17148ada 64 bit values allocated on lbm_memory on 32 bit version 4445e5a8 sketch of encoders for 64 bit values f636e64d suffix for the lisp size of int and uint are now i and u instead of i28 and u28 840723ca preparations and planning for 64bit types in both 32 and 64 bit versions. 13675dda 64bit up and running. but there are many TODOs 033bfd9a small fixes following bug hunt f5c984de fix bug in representation of important masks and constants d40b2437 Merge branch 'master' into dev64bit 06f9603f Merge branch 'master' into dev64bit 69950ba1 32 bit tests are ok 46b6fa28 Merge branch 'master' into dev64bit b9e2c993 work in progress 8dff9b4d work in progress a241aded work in progress 4738e0da update year in lbm_types ca469923 made it possible to run the same tests as on the 32 bit version on the 64 bit code 85acec30 small tweaks tp create_ctx, use correct type bf0286a7 Merge branch 'master' into dev64bit 824e1634 Merge branch 'master' into dev64bit 04a97f17 lots of testing needed ea862cce a bunch of changes in preparation for 64bit compatibility. git-subtree-dir: lispBM/lispBM git-subtree-split: 43ebce71a281f4a158b8d2dec3fc537c26766ec3
2022-03-25 07:47:05 -07:00
} else if (lbm_type_of(cell) != LBM_TYPE_SYMBOL ||
lbm_dec_sym(cell) != SYM_MERROR) {
printf("Error Incorrect return value at cell allocation on full heap\n");
return 0;
}
}
printf("HEAP allocation when full test: OK\n");
return 1;
}