Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions .github/workflows/makefile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,3 @@ jobs:
- name: Tests (except CUnit test's)
run: make test_all_except_cunit_tests

# test:
# runs-on: ubuntu-latest
#
# steps:
# - uses: actions/checkout@v3
#
# - name: Cunit
# run: git clone https://github.com/wpdk/CUnit ; cd CUnit ; make
#
# - name: Run tests ok
# run: make test_ok
#
# - name: Run all tests
# run: make test
42 changes: 42 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Release

on:
push:
tags:
- 'v*'
branches:
- master

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Make
run: |
make
mkdir -p release
cp libtrasher.a release/

- name: Create a GitHub Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
draft: false
prerelease: false

- name: Upload Release Asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }}
asset_path: ./release/libtrasher.a
asset_name: libtrasher.a
asset_content_type: application/x-archive

31 changes: 17 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ SRC = libtrasher/trasher.c
CFLAGS = -Wall -Wextra
LDFLAGS = -L. -ltrasher
LDFLAGS_CUNIT = -L. -ltrasher -lcunit
CDEBUGFLAGS = -Wall -Wextra -g
CDEBUGFLAGSFSANITIZE = -Wall -Wextra -g -fsanitize=address
CDEBUGFLAGS = -O0 -Wall -Wextra -g
CDEBUGFLAGSFSANITIZE = -O0 -Wall -Wextra -g -fsanitize=address

TEST_SRC_KO = test/test_mem_ko.c
TEST_SRC_OK = test/test_mem_ok.c
Expand Down Expand Up @@ -47,12 +47,15 @@ lib_debug: clean
ar -rc ${LIB} trasher.o
rm trasher.o


lib_debug_fsanitize: clean
${CC} -c ${SRC} ${CDEBUGFLAGSFSANITIZE} -o trasher.o
ar -rc ${LIB} trasher.o
rm trasher.o

lib_debug_valgrind: clean
${CC} -c ${SRC} ${CDEBUGFLAGS} -o trasher.o
ar -rc ${LIB} trasher.o
rm trasher.o

test: lib_debug test_ok test_simple test_mix_pools_names_ids test_memcheck_ok_fsanitize test_memcheck_ok_valgrind test_unit clean

Expand All @@ -61,53 +64,53 @@ test_all_except_cunit_tests: lib_debug test_ok test_simple test_mix_pools_names_

test_ko: lib_debug
cp libtrasher/trasher.h test/
$(CC) $(CDEBUGFLAGS) -g ${TEST_SRC_KO} -o ${TEST_BIN_KO} $(LDFLAGS)
$(CC) -DSUPPRESS_PRINT $(CDEBUGFLAGS) ${TEST_SRC_KO} -o ${TEST_BIN_KO} $(LDFLAGS)
./${TEST_BIN_KO}

test_ok: lib_debug
cp libtrasher/trasher.h test/
$(CC) $(CDEBUGFLAGS) -g ${TEST_SRC_OK} -o ${TEST_BIN_OK} $(LDFLAGS)
$(CC) -DSUPPRESS_PRINT $(CDEBUGFLAGS) ${TEST_SRC_OK} -o ${TEST_BIN_OK} $(LDFLAGS)
./${TEST_BIN_OK}

test_simple: lib_debug
cp libtrasher/trasher.h test/
$(CC) $(CDEBUGFLAGS) -g ${TEST_SRC_SIMPLE} -o ${TEST_BIN_SIMPLE} $(LDFLAGS)
$(CC) -DSUPPRESS_PRINT $(CDEBUGFLAGS) ${TEST_SRC_SIMPLE} -o ${TEST_BIN_SIMPLE} $(LDFLAGS)
./${TEST_BIN_SIMPLE}

test_mix_pools_names_ids: lib_debug
cp libtrasher/trasher.h test/
$(CC) $(CDEBUGFLAGS) -g ${TEST_SRC_MIX} -o ${TEST_BIN_MIX} $(LDFLAGS)
$(CC) -DSUPPRESS_PRINT $(CDEBUGFLAGS) ${TEST_SRC_MIX} -o ${TEST_BIN_MIX} $(LDFLAGS)
./${TEST_BIN_MIX}

test_memcheck_ok_fsanitize: lib_debug_fsanitize
cp libtrasher/trasher.h test/
$(CC) $(CDEBUGFLAGSFSANITIZE) -g ${TEST_SRC_MEM} -o ${TEST_BIN_MEM} $(LDFLAGS)
$(CC) -DSUPPRESS_PRINT $(CDEBUGFLAGSFSANITIZE) ${TEST_SRC_MEM} -o ${TEST_BIN_MEM} $(LDFLAGS)
./${TEST_BIN_MEM}

test_memcheck_ok_valgrind: lib_debug
test_memcheck_ok_valgrind: lib_debug_valgrind
cp libtrasher/trasher.h test/
$(CC) $(CDEBUGFLAGSFSANITIZE) -g ${TEST_SRC_MEM} -o ${TEST_BIN_MEM} $(LDFLAGS)
$(CC) -DSUPPRESS_PRINT $(CDEBUGFLAGS) ${TEST_SRC_MEM} -o ${TEST_BIN_MEM} $(LDFLAGS)
valgrind -s --track-origins=yes --leak-check=full ./${TEST_BIN_MEM}

# Requires CUNIT lib installed
test_unit: lib_debug
cp libtrasher/trasher.h test/
$(CC) $(CDEBUGFLAGS) -g $(TEST_SRC_UNIT) -o $(TEST_BIN_UNIT) $(LDFLAGS_CUNIT)
$(CC) -DSUPPRESS_PRINT $(CDEBUGFLAGS) $(TEST_SRC_UNIT) -o $(TEST_BIN_UNIT) $(LDFLAGS_CUNIT)
./$(TEST_BIN_UNIT)

test_unit_verbose: lib_debug
cp libtrasher/trasher.h test/
$(CC) $(CDEBUGFLAGS) -D SHOW_POOLS_STATUS -g $(TEST_SRC_UNIT) -o $(TEST_BIN_UNIT) $(LDFLAGS)
$(CC) -DSUPPRESS_PRINT $(CDEBUGFLAGS) -D SHOW_POOLS_STATUS $(TEST_SRC_UNIT) -o $(TEST_BIN_UNIT) $(LDFLAGS)
./$(TEST_BIN_UNIT)

test_free_5x: lib_debug
cp libtrasher/trasher.h test/
$(CC) $(CDEBUGFLAGS) -g $(TEST_SRC_FREE_5X) -o $(TEST_BIN_FREE_5X) $(LDFLAGS)
$(CC) -DSUPPRESS_PRINT $(CDEBUGFLAGS) $(TEST_SRC_FREE_5X) -o $(TEST_BIN_FREE_5X) $(LDFLAGS)
./${TEST_BIN_FREE_5X}

test_perf: lib
cp libtrasher/trasher.h test/
$(CC) $(CFLAGS) -g $(TEST_SRC_PERF) -o $(TEST_BIN_PERF) $(LDFLAGS)
$(CC) -DSUPPRESS_PRINT $(CFLAGS) -g $(TEST_SRC_PERF) -o $(TEST_BIN_PERF) $(LDFLAGS)
./${TEST_BIN_PERF}

clean:
Expand Down
17 changes: 12 additions & 5 deletions test/test_free_x5.c
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
#include "trasher.h"

// Power Printing macro to make pretty tests
#ifdef SUPPRESS_PRINT
#define POOL_STATUS() ((void)0)
#else
#define POOL_STATUS() pool_status()
#endif

int main() {
// Test multiple free
pool_status();
POOL_STATUS();
free_pool_all();
pool_status();
POOL_STATUS();
free_pool_all();
pool_status();
POOL_STATUS();
free_pool_all();
mem(100);
pool_status();
POOL_STATUS();
free_pool_all();
pool_status();
POOL_STATUS();
}
22 changes: 16 additions & 6 deletions test/test_mem_ko.c
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
#include <stdio.h>
#include "trasher.h"

// Power Printing macro to make pretty tests
#ifdef SUPPRESS_PRINT
#define PRINT(fmt, ...) ((void)0)
#define POOL_STATUS() ((void)0)
#else
#define PRINT(fmt, ...) printf(fmt, ##__VA_ARGS__)
#define POOL_STATUS() pool_status()
#endif


int main() {
printf("Hello World!\n\n");
PRINT("Hello World!\n\n");

size_t buffer_size = 10000;
char* buffer = mem(buffer_size);
Expand All @@ -13,7 +23,7 @@ int main() {
j++;
}

// printf("%s\n", buffer);
// PRINT("%s\n", buffer);

int* array_IDS = mem_id(33, 5);

Expand All @@ -22,12 +32,12 @@ int main() {
array_IDS[4] = 25;
array_ids_2[3] = 232;

printf("%d\n", array_ids_2[3]);
PRINT("%d\n", array_ids_2[3]);

free_id(2);

printf("array_IDS access : %d\n", array_IDS[4]);
printf("array_ids_2 : %d", array_ids_2[3]); // Memcheck Valgrind shoudl notify invalid read!
PRINT("array_IDS access : %d\n", array_IDS[4]);
PRINT("array_ids_2 : %d", array_ids_2[3]); // Memcheck Valgrind shoudl notify invalid read!

// Named Pools : Tag
int *speed_array = mem_name(20, "cars");
Expand All @@ -41,7 +51,7 @@ int main() {

free_name("cars");

pool_status();
POOL_STATUS();


free_name("cars");
Expand Down
10 changes: 9 additions & 1 deletion test/test_mem_mix_pools_names_ids.c
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
#include <stdio.h>
#include "trasher.h"

// Power Printing macro to make pretty tests
#ifdef SUPPRESS_PRINT
#define POOL_STATUS() ((void)0)
#else
#define POOL_STATUS() pool_status()
#endif


int main() {
mem_id(50, 1);
mem(100);
mem_name(200, "Buffers");
mem_id(300, 2);

pool_status();
POOL_STATUS();

return 0;
}
43 changes: 26 additions & 17 deletions test/test_mem_ok.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
#include <stdio.h>
#include "trasher.h"

// Power Printing macro to make pretty tests
#ifdef SUPPRESS_PRINT
#define PRINT(fmt, ...) ((void)0)
#define POOL_STATUS() ((void)0)
#else
#define PRINT(fmt, ...) printf(fmt, ##__VA_ARGS__)
#define POOL_STATUS() pool_status()
#endif

struct btree {
int value;
struct btree *left;
Expand All @@ -18,7 +27,7 @@ struct btree *init_btree(int value, struct btree *left, struct btree *right) {
void display_btree(struct btree *root, char* suffix) {
if (root == NULL)
return;
printf("%d %s", root->value, suffix);
PRINT("%d %s", root->value, suffix);
display_btree(root->left, " ");
display_btree(root->right, " \n");
}
Expand All @@ -27,7 +36,7 @@ int main() {

mem_id(50, 1);

printf("Test mem stupid usage\n");
PRINT("Test mem stupid usage\n");

// You should get the result of mem to do something with it
mem(10);
Expand All @@ -37,41 +46,41 @@ int main() {

mem_id(100, 1);

pool_status();
POOL_STATUS();

printf("Test mem normal usage\n");
PRINT("Test mem normal usage\n");

printf("Small Tree\n");
PRINT("Small Tree\n");
struct btree *root_small = init_btree(30, NULL, NULL);
display_btree(root_small, "\n");

printf("Big Tree Init");
PRINT("Big Tree Init");
struct btree *root = init_btree(0, init_btree(2, NULL, NULL), init_btree(42, NULL, init_btree(67, NULL, NULL)));

printf("Print B Tree\n");
PRINT("Print B Tree\n");
display_btree(root, "\n");

printf("Check pool\n");
pool_status();
PRINT("Check pool\n");
POOL_STATUS();

printf("Free btrees pool\n");
PRINT("Free btrees pool\n");
free_name("btrees");
pool_status();
printf("Create new pools, id=10, then with name=arguments\n");
POOL_STATUS();
PRINT("Create new pools, id=10, then with name=arguments\n");

mem_id(16, 10);
mem_name(64, "arguments");

printf("Re-use free pool 'btrees', with a new tree:\n");
PRINT("Re-use free pool 'btrees', with a new tree:\n");
struct btree *other_root = init_btree(5, init_btree(2, NULL, NULL), init_btree(6, NULL, NULL));
display_btree(other_root, "\n");

printf("Check pool\n");
pool_status();
PRINT("Check pool\n");
POOL_STATUS();

printf("Free all\n");
PRINT("Free all\n");

free_pool_all(); // Should close all pool functions for memory safety

printf("End Test\n");
PRINT("End Test\n");
}
9 changes: 8 additions & 1 deletion test/test_mem_simple.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
#include <stdio.h>
#include "trasher.h"

// Power Printing macro to make pretty tests
#ifdef SUPPRESS_PRINT
#define POOL_STATUS() ((void)0)
#else
#define POOL_STATUS() pool_status()
#endif

int main() {
size_t buffer_size = 10;
char* buffer = mem(buffer_size);
Expand All @@ -14,7 +21,7 @@ int main() {

mem(50);

pool_status();
POOL_STATUS();

free_pool_all();
return 0;
Expand Down
Loading