Skip to content

Commit ee91121

Browse files
committed
Added documentation to the test file and updated README so users can easily extend the test suite if so desired. Also renamed the test file from testCHENEY.c -> cheney.c and updated the Makefile and README links accordingly. Was also able to remove the library section in the Makefile and cleanup some test names as well as fixing a small description error about atomic data in the README.
1 parent 4752601 commit ee91121

File tree

3 files changed

+55
-48
lines changed

3 files changed

+55
-48
lines changed

Makefile

+4-8
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,12 @@ CC = gcc
44
CFLAGS = -Wall -O3
55
# includes (header file locations)
66
INCLUDES = -I/include/ -Iinclude/
7-
# libraries (library file location)
8-
LFLAGS = -L/lib/
9-
# libraries to link
10-
LIBS = -lm
11-
# all the files to include in the generated .tar
7+
# all the files to include in the generated .tar (core project files)
128
TAR_FILES = include/*.h src/*.c test/*.c LICENSE.txt Makefile README.md
139
# name of generated tar
1410
TAR_NAME = cheney
15-
# garbage collection table driven tests executable
16-
TEST_DEPS = include/cheney.h src/cheney.c test/testCHENEY.c
11+
# garbage collection table driven testing executable dependencies
12+
TEST_DEPS = include/cheney.h src/cheney.c test/cheney.c
1713
# auto-generate the object files
1814
TEST_OBJS = $(TEST_DEPS:.c=.o)
1915
# define the executable file
@@ -40,6 +36,6 @@ tar:
4036
\tar -cvf $(TAR_NAME).tar $(TAR_FILES)
4137

4238
$(TEST): $(TEST_OBJS)
43-
$(CC) $(CFLAGS) $(INCLUDES) -o $(TEST) $(TEST_OBJS) $(LFLAGS) $(LIBS)
39+
$(CC) $(CFLAGS) $(INCLUDES) -o $(TEST) $(TEST_OBJS)
4440
./$(TEST)
4541
\rm -f *.o *~ src/*.o src/*~ include/*.o include/*~ test/*.o test/*~ $(TEST)

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
[![LICENSE](https://img.shields.io/badge/LICENSE-MIT-green.svg)](https://github.com/rrozansk/Cheney-GC/blob/master/LICENSE.txt) [![RELEASES](https://img.shields.io/badge/Releases-current-green.svg)](https://github.com/rrozansk/Cheney-GC/releases)
44

5-
An [implementation](https://github.com/rrozansk/Cheney-GC/blob/master/src/cheney.c) of [Cheney](https://en.wikipedia.org/wiki/Cheney%27s_algorithm) style garbage collection allowing the allocation of [cons cells](https://en.wikipedia.org/wiki/Cons). These cells are capable of storing pointers to other cells, NULL, or atomic data (represented as a [tagged pointer](https://en.wikipedia.org/wiki/Tagged_pointer)). This allows the storage of any other data type's pointer or even possibly encoding the information itself directly into a pointer.
5+
An [implementation](https://github.com/rrozansk/Cheney-GC/blob/master/src/cheney.c#L1) of [Cheney](https://en.wikipedia.org/wiki/Cheney%27s_algorithm) style garbage collection allowing the allocation of [cons cells](https://en.wikipedia.org/wiki/Cons). These cells are capable of storing pointers to other cells or atomic data (represented as a [tagged pointer](https://en.wikipedia.org/wiki/Tagged_pointer) or NULL). This allows the storage of any other data type's pointer or even possibly encoding the information itself directly into a pointer.
66

77
Furthermore, the heap has been encapsulated into a structure allowing multiple garbage collected heaps to exist simultaneously. Ultimately, this allows clean interaction through a well defined API. However, this could be useful for other reasons, one of which may be to maintain different memory pools if computing on threads. It is also possible, if permitted, for the heap to expand dynamically. Dynamic expansion can only happen when a collection fails in reclaiming memory or through the exposed 'resize' API call. For a more thorough explanation of all the libraries capabilities and exposed API's see the [documentation](https://github.com/rrozansk/Cheney-GC/blob/master/include/cheney.h#L6).
88

9-
Finally, table driven testing is deployed to ensure correctness and compatability while allowing expansion of test cases with minimal effort. A Makefile is included to help automate and run the [tests](https://github.com/rrozansk/Cheney-GC/blob/master/test/testCHENEY.c) using the commands listed below. If any test fails, or the program exits abnormally, then the implementation is not compatible with the choosen system.
9+
Finally, table driven testing is deployed to ensure correctness and compatability while allowing expansion of test cases with minimal effort. A Makefile is included to help automate and run the [test suite](https://github.com/rrozansk/Cheney-GC/blob/master/test/cheney.c#L6) using the commands listed below. If any test fails or the program exits abnormally then the implementation is not compatible with the choosen system. Following the link above will lead you to directions for adding your own tests to the suite if so desired.
1010

1111
## Prerequisites
1212
- gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3 or equivalent C compiler

test/testCHENEY.c test/cheney.c

+49-38
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,18 @@
11
/******************************************************************************
2-
* FILE: testCHENEY.c *
2+
* FILE: cheney.c *
33
* AUTHOR: Ryan Rozanski *
44
* CREATED: 10/31/17 *
5-
* EDITED: 11/14/17 *
6-
* INFO: Test file for implementation of the interface located in cheney.h *
5+
* EDITED: 12/28/17 *
6+
* INFO: Table driven testing for the interface located at cheney.h. *
7+
* Extending the test suite is possible if so desired and can be *
8+
* done with minimal effort. First, it requires defining a new test. *
9+
* A test is just a function which takes no arguments and returns a *
10+
* 'testResult_t' type as defined below. Second, an entry must be *
11+
* added to the table. A table entry is an array literal containing *
12+
* two items. Index zero contains the name of test function just *
13+
* written. Index one contains a short string description to print *
14+
* when ran which identifies the specific test. Third, and finally, *
15+
* the integer value of 'TOTAL_TESTS' must be incremeted by one. *
716
* *
817
******************************************************************************/
918

@@ -36,15 +45,16 @@ unsigned long custom_expander(unsigned long size) { return size + 20; }
3645
* T E S T S *
3746
* *
3847
******************************************************************************/
39-
testResult_t MakeHeapOddCells() {
40-
return make_heap(9) ? PASS : FAIL;
41-
}
48+
testResult_t MakeFreeHeapOddCells() {
49+
heap_t *heap = make_heap(9);
50+
if(!heap) { return FAIL; }
4251

43-
testResult_t MakeHeapEvenCells() {
44-
return make_heap(8) ? PASS : FAIL;
52+
free_heap(&heap);
53+
54+
return !heap ? PASS : FAIL;
4555
}
4656

47-
testResult_t FreeHeapDefault() {
57+
testResult_t MakeFreeHeapEvenCells() {
4858
heap_t *heap = make_heap(8);
4959
if(!heap) { return FAIL; }
5060

@@ -63,7 +73,7 @@ testResult_t GetDynamicDefault() {
6373
return !dynamic ? PASS : FAIL;
6474
}
6575

66-
testResult_t SetDynamicOn() {
76+
testResult_t SetGetDynamicOn() {
6777
heap_t *heap = make_heap(8);
6878
if(!heap) { return FAIL; }
6979

@@ -74,7 +84,7 @@ testResult_t SetDynamicOn() {
7484
return dynamic ? PASS : FAIL;
7585
}
7686

77-
testResult_t SetDynamicOnOff() {
87+
testResult_t SetGetDynamicOnOff() {
7888
heap_t *heap = make_heap(8);
7989
if(!heap) { return FAIL; }
8090

@@ -97,7 +107,7 @@ testResult_t GetDefaultExpander() {
97107
return !expander ? PASS : FAIL;
98108
}
99109

100-
testResult_t SetCustomExpander() {
110+
testResult_t SetGetCustomExpander() {
101111
heap_t *heap = make_heap(8);
102112
if(!heap) { return FAIL; }
103113

@@ -119,7 +129,7 @@ testResult_t GetDefaultRoot() {
119129
return !root ? PASS : FAIL;
120130
}
121131

122-
testResult_t SetCustomRoot() {
132+
testResult_t SetGetCustomRoot() {
123133
heap_t *heap = make_heap(8);
124134
if(!heap) { return FAIL; }
125135

@@ -142,7 +152,7 @@ testResult_t EmptyCollections() {
142152
return PASS;
143153
}
144154

145-
testResult_t HeapSizeDefault() {
155+
testResult_t HeapSize() {
146156
heap_t *heap = make_heap(8);
147157
if(!heap) { return FAIL; }
148158

@@ -152,7 +162,7 @@ testResult_t HeapSizeDefault() {
152162
return size == 8 ? PASS : FAIL;
153163
}
154164

155-
testResult_t HeapSemiSizeDefault() {
165+
testResult_t HeapSemiSize() {
156166
heap_t *heap = make_heap(8);
157167
if(!heap) { return FAIL; }
158168

@@ -162,7 +172,7 @@ testResult_t HeapSemiSizeDefault() {
162172
return size == 4 ? PASS : FAIL;
163173
}
164174

165-
testResult_t HeapSemiUsedDefault() {
175+
testResult_t HeapSemiUsed() {
166176
heap_t *heap = make_heap(8);
167177
if(!heap) { return FAIL; }
168178

@@ -172,7 +182,7 @@ testResult_t HeapSemiUsedDefault() {
172182
return size == 0 ? PASS : FAIL;
173183
}
174184

175-
testResult_t HeapSemiLeftDefault() {
185+
testResult_t HeapSemiLeft() {
176186
heap_t *heap = make_heap(8);
177187
if(!heap) { return FAIL; }
178188

@@ -182,24 +192,26 @@ testResult_t HeapSemiLeftDefault() {
182192
return size == 4 ? PASS : FAIL;
183193
}
184194

185-
testResult_t HeapResizeSmallerDefault() {
195+
testResult_t HeapResizeSmaller() {
186196
heap_t *heap = make_heap(8);
187197
if(!heap) { return FAIL; }
188198

189199
int successful = resize(heap, 4);
200+
int size = heap_size(heap);
190201
free_heap(&heap);
191202

192-
return successful ? PASS : FAIL;
203+
return successful && size == 4 ? PASS : FAIL;
193204
}
194205

195-
testResult_t HeapResizeLallerDefault() {
206+
testResult_t HeapResizeLarger() {
196207
heap_t *heap = make_heap(8);
197208
if(!heap) { return FAIL; }
198209

199210
int successful = resize(heap, 16);
211+
int size = heap_size(heap);
200212
free_heap(&heap);
201213

202-
return successful ? PASS : FAIL;
214+
return successful && size == 16 ? PASS : FAIL;
203215
}
204216

205217
testResult_t EmptyCellAllocation() {
@@ -344,7 +356,7 @@ testResult_t CorrectAmountCollected() {
344356
return (semi_used(heap) == 1 && semi_left(heap) == 4) ? PASS : FAIL;
345357
}
346358

347-
testResult_t StaticHeapAllocationFailure() {
359+
testResult_t StaticHeapCellAllocationFailure() {
348360
heap_t *heap = make_heap(8); // non-dynamic by default
349361
if(!heap) { return FAIL; }
350362

@@ -531,26 +543,25 @@ testResult_t DynamicHeapOnOff() {
531543
******************************************************************************/
532544
#define FUNCTION 0 // function ptr @idx 0
533545
#define NAME 1 // test name @idx 1
534-
#define TOTAL_TESTS 38 // # tests in array
546+
#define TOTAL_TESTS 37 // # tests in array/table
535547

536548
void *TESTS[TOTAL_TESTS][2] = {
537-
{ MakeHeapOddCells, "MakeHeapOddCells" },
538-
{ MakeHeapEvenCells, "MakeHeapEvenCell" },
539-
{ FreeHeapDefault, "FreeHeapDefault" },
549+
{ MakeFreeHeapOddCells, "MakeFreeHeapOddCells" },
550+
{ MakeFreeHeapEvenCells, "MakeFreeHeapEvenCells" },
540551
{ GetDynamicDefault, "GetDynamicDefault" },
541-
{ SetDynamicOn, "SetDynamicOn" },
542-
{ SetDynamicOnOff, "SetDynamicOnOff" },
543-
{ GetDefaultExpander, "GetDefaultExpand" },
544-
{ SetCustomExpander, "SetCustomExpande" },
552+
{ SetGetDynamicOn, "SetGetDynamicOn" },
553+
{ SetGetDynamicOnOff, "SetGetDynamicOnOff" },
554+
{ GetDefaultExpander, "GetDefaultExpander" },
555+
{ SetGetCustomExpander, "SetGetCustomExpander" },
545556
{ GetDefaultRoot, "GetDefaultRoot" },
546-
{ SetCustomRoot, "SetCustomRoot" },
557+
{ SetGetCustomRoot, "SetGetCustomRoot" },
547558
{ EmptyCollections, "EmptyCollections" },
548-
{ HeapSizeDefault, "HeapSizeDefault" },
549-
{ HeapSemiSizeDefault, "HeapSemiSizeDefault" },
550-
{ HeapSemiUsedDefault, "HeapSemiUsedDefault" },
551-
{ HeapSemiLeftDefault, "HeapSemiLeftDefault" },
552-
{ HeapResizeSmallerDefault, "HeapResizeSmallerDefault" },
553-
{ HeapResizeLallerDefault, "HeapResizeLallerDefault" },
559+
{ HeapSize, "HeapSize" },
560+
{ HeapSemiSize, "HeapSemiSize" },
561+
{ HeapSemiUsed, "HeapSemiUsed" },
562+
{ HeapSemiLeft, "HeapSemiLeft" },
563+
{ HeapResizeSmaller, "HeapResizeSmaller" },
564+
{ HeapResizeLarger, "HeapResizeLarger" },
554565
{ EmptyCellAllocation, "EmptyCellAllocation" },
555566
{ InitializedCellAllocation, "InitializedCellAllocation" },
556567
{ CellFirstFieldGetter, "CellFirstFieldGetter" },
@@ -564,7 +575,7 @@ void *TESTS[TOTAL_TESTS][2] = {
564575
{ CellDataFail, "CellDataFail" },
565576
{ CellDataNull, "CellDataNull" },
566577
{ CorrectAmountCollected, "CorrectAmountCollected" },
567-
{ StaticHeapAllocationFailure, "StaticHeapAllocationFailure" },
578+
{ StaticHeapCellAllocationFailure, "StaticHeapCellAllocationFailure" },
568579
{ DynamicHeapDefaultExpand, "DynamicHeapDefaultExpand" },
569580
{ DynamicHeapCustomExpand, "DynamicHeapCustomExpand" },
570581
{ SafeRootedObjects, "SafeRootedObjects" },

0 commit comments

Comments
 (0)