Compare commits
No commits in common. "7fb13f2439394b807fee160fbdbf7c20f89ca18b" and "cfc98e01379d233d5fe169e46e86585be1d4f867" have entirely different histories.
7fb13f2439
...
cfc98e0137
27
compile
27
compile
@ -21,16 +21,9 @@ LIBFLAGS="-fPIC -shared"
|
||||
INCLUDE="\
|
||||
$(find src -type d | xargs -I{} echo -n "-I{} ") \
|
||||
"
|
||||
TEST_INCLUDE="\
|
||||
$(find tests -type d | xargs -I{} echo -n "-I{} ") \
|
||||
"
|
||||
SRC="\
|
||||
$(find src -type f -name "*.c" | xargs -I{} echo -n "{} ") \
|
||||
"
|
||||
TEST_SRC="\
|
||||
$(find tests -type f -name "*.c" | xargs -I{} echo -n "{} ") \
|
||||
"
|
||||
|
||||
if [[ $BUILD_TYPE == "release" ]]; then
|
||||
CFLAGS+="-O3"
|
||||
else
|
||||
@ -38,29 +31,9 @@ else
|
||||
fi
|
||||
|
||||
OUT="libwapp.so"
|
||||
TEST_OUT="./wapptest"
|
||||
|
||||
# Compile tests
|
||||
if [[ $(echo $TEST_SRC | xargs) != "" ]]; then
|
||||
(set -x ; $CC $CFLAGS $INCLUDE $TEST_INCLUDE $SRC $TEST_SRC -o $TEST_OUT)
|
||||
fi
|
||||
|
||||
# Run tests and exit on failure
|
||||
if [[ -f $TEST_OUT ]]; then
|
||||
$TEST_OUT
|
||||
STATUS="$?"
|
||||
|
||||
rm $TEST_OUT
|
||||
|
||||
if [[ $STATUS != "0" ]]; then
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# Compile library
|
||||
(set -x ; $CC $CFLAGS $LIBFLAGS $INCLUDE $SRC -o $OUT)
|
||||
|
||||
# Compile test.c if it exists
|
||||
if [[ -f ./test.c ]]; then
|
||||
(set -x ; $CC $CFLAGS $INCLUDE $SRC ./test.c -o test)
|
||||
fi
|
||||
|
@ -1,7 +1,6 @@
|
||||
#ifndef PLATFORM_H
|
||||
#define PLATFORM_H
|
||||
|
||||
// clang-format off
|
||||
#if defined(__ANDROID__)
|
||||
#define WAPP_PLATFORM_ANDROID
|
||||
#define WAPP_PLATFORM_POSIX
|
||||
@ -24,7 +23,8 @@
|
||||
#elif defined(__bsdi__)
|
||||
#define WAPP_PLATFORM_BSD
|
||||
#define WAPP_PLATFORM_POSIX
|
||||
#elif defined(__linux__) || defined(linux) || defined(__linux) || defined(__gnu_linux__)
|
||||
#elif defined(__linux__) || defined(linux) || defined(__linux) || \
|
||||
defined(__gnu_linux__)
|
||||
#define WAPP_PLATFORM_LINUX
|
||||
#define WAPP_PLATFORM_POSIX
|
||||
#elif defined(__GNU__) || defined(__gnu_hurd__)
|
||||
@ -58,6 +58,5 @@
|
||||
#else
|
||||
#error "Unrecognised platform"
|
||||
#endif
|
||||
// clang-format on
|
||||
|
||||
#endif // !PLATFORM_H
|
||||
|
@ -1,48 +0,0 @@
|
||||
#ifndef TERM_COLOUR_H
|
||||
#define TERM_COLOUR_H
|
||||
|
||||
#include "platform.h"
|
||||
|
||||
// clang-format off
|
||||
#if defined(WAPP_PLATFORM_WINDOWS)
|
||||
#define TERM_COLOUR_CLEAR ""
|
||||
#define TERM_COLOUR_BOLD ""
|
||||
#define TERM_COLOUR_FG_BLACK ""
|
||||
#define TERM_COLOUR_FG_RED ""
|
||||
#define TERM_COLOUR_FG_GREEN ""
|
||||
#define TERM_COLOUR_FG_YELLOW ""
|
||||
#define TERM_COLOUR_FG_BLUE ""
|
||||
#define TERM_COLOUR_FG_MAGENTA ""
|
||||
#define TERM_COLOUR_FG_CYAN ""
|
||||
#define TERM_COLOUR_FG_WHITE ""
|
||||
#define TERM_COLOUR_FG_BR_BLACK ""
|
||||
#define TERM_COLOUR_FG_BR_RED ""
|
||||
#define TERM_COLOUR_FG_BR_GREEN ""
|
||||
#define TERM_COLOUR_FG_BR_YELLOW ""
|
||||
#define TERM_COLOUR_FG_BR_BLUE ""
|
||||
#define TERM_COLOUR_FG_BR_MAGENTA ""
|
||||
#define TERM_COLOUR_FG_BR_CYAN ""
|
||||
#define TERM_COLOUR_FG_BR_WHITE ""
|
||||
#elif defined(WAPP_PLATFORM_POSIX)
|
||||
#define TERM_COLOUR_CLEAR "\033[0m"
|
||||
#define TERM_COLOUR_BOLD "\033[1m"
|
||||
#define TERM_COLOUR_FG_BLACK "\033[30m"
|
||||
#define TERM_COLOUR_FG_RED "\033[31m"
|
||||
#define TERM_COLOUR_FG_GREEN "\033[32m"
|
||||
#define TERM_COLOUR_FG_YELLOW "\033[33m"
|
||||
#define TERM_COLOUR_FG_BLUE "\033[34m"
|
||||
#define TERM_COLOUR_FG_MAGENTA "\033[35m"
|
||||
#define TERM_COLOUR_FG_CYAN "\033[36m"
|
||||
#define TERM_COLOUR_FG_WHITE "\033[37m"
|
||||
#define TERM_COLOUR_FG_BR_BLACK "\033[90m"
|
||||
#define TERM_COLOUR_FG_BR_RED "\033[91m"
|
||||
#define TERM_COLOUR_FG_BR_GREEN "\033[92m"
|
||||
#define TERM_COLOUR_FG_BR_YELLOW "\033[93m"
|
||||
#define TERM_COLOUR_FG_BR_BLUE "\033[94m"
|
||||
#define TERM_COLOUR_FG_BR_MAGENTA "\033[95m"
|
||||
#define TERM_COLOUR_FG_BR_CYAN "\033[96m"
|
||||
#define TERM_COLOUR_FG_BR_WHITE "\033[97m"
|
||||
#endif
|
||||
// clang-format on
|
||||
|
||||
#endif // !TERM_COLOUR_H
|
@ -1,48 +0,0 @@
|
||||
#include "tester.h"
|
||||
#include "aliases.h"
|
||||
#include "termcolour/termcolour.h"
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
internal void print_test_result(TestFuncResult result);
|
||||
|
||||
void run_tests(TestFunc *func1, ...) {
|
||||
printf("\n");
|
||||
|
||||
print_test_result(func1());
|
||||
|
||||
va_list args;
|
||||
va_start(args, func1);
|
||||
|
||||
TestFunc *func = NULL;
|
||||
|
||||
while ((func = va_arg(args, TestFunc *))) {
|
||||
TestFuncResult result = func();
|
||||
print_test_result(result);
|
||||
|
||||
if (!result.success) {
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
va_end(args);
|
||||
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
internal void print_test_result(TestFuncResult result) {
|
||||
const char *colour;
|
||||
const char *result_text;
|
||||
|
||||
if (result.success) {
|
||||
colour = TERM_COLOUR_FG_BR_GREEN;
|
||||
result_text = "PASSED";
|
||||
} else {
|
||||
colour = TERM_COLOUR_FG_BR_RED;
|
||||
result_text = "FAILED";
|
||||
}
|
||||
|
||||
printf("[%s%s%s%s] %s\n", colour, TERM_COLOUR_BOLD, result_text,
|
||||
TERM_COLOUR_CLEAR, result.name);
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
#ifndef TESTER_H
|
||||
#define TESTER_H
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif // __cplusplus
|
||||
|
||||
#define TEST_RESULT(BOOL) ((TestFuncResult){.name = __func__, .success = BOOL})
|
||||
|
||||
typedef struct test_func_result TestFuncResult;
|
||||
struct test_func_result {
|
||||
const char *name;
|
||||
bool success;
|
||||
};
|
||||
|
||||
typedef TestFuncResult(TestFunc)(void);
|
||||
|
||||
void run_tests(TestFunc *func1, ...);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif // __cplusplus
|
||||
|
||||
#endif // !TESTER_H
|
@ -1,59 +0,0 @@
|
||||
#include "test_arena.h"
|
||||
#include "aliases.h"
|
||||
#include "mem_arena.h"
|
||||
#include "mem_utils.h"
|
||||
#include "tester.h"
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define ARENA_CAPACITY 1024
|
||||
|
||||
internal Arena *arena = NULL;
|
||||
internal u64 count = 20;
|
||||
internal i32 *array = NULL;
|
||||
|
||||
TestFuncResult test_arena_init(void) {
|
||||
bool result = wapp_mem_arena_init(&arena, ARENA_CAPACITY,
|
||||
WAPP_MEM_ALLOC_RESERVE, false);
|
||||
|
||||
return TEST_RESULT(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_arena_alloc_succeeds_when_within_capacity(void) {
|
||||
array = wapp_mem_arena_alloc(arena, count * sizeof(i32));
|
||||
bool result = array != NULL;
|
||||
|
||||
for (u64 i = 0; i < count; ++i) {
|
||||
array[i] = i * 10;
|
||||
}
|
||||
|
||||
return TEST_RESULT(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_arena_alloc_fails_when_over_capacity(void) {
|
||||
u8 *bytes = wapp_mem_arena_alloc(arena, ARENA_CAPACITY * 2);
|
||||
bool result = bytes == NULL;
|
||||
|
||||
return TEST_RESULT(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_arena_clear(void) {
|
||||
wapp_mem_arena_clear(arena);
|
||||
bool result = true;
|
||||
|
||||
for (u64 i = 0; i < count; ++i) {
|
||||
if (array[i] != 0) {
|
||||
result = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return TEST_RESULT(result);
|
||||
}
|
||||
|
||||
TestFuncResult test_arena_destroy(void) {
|
||||
wapp_mem_arena_destroy(&arena);
|
||||
bool result = arena == NULL;
|
||||
|
||||
return TEST_RESULT(result);
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
#ifndef TEST_ARENA_H
|
||||
#define TEST_ARENA_H
|
||||
|
||||
#include "tester.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif // __cplusplus
|
||||
|
||||
TestFuncResult test_arena_init(void);
|
||||
TestFuncResult test_arena_alloc_succeeds_when_within_capacity(void);
|
||||
TestFuncResult test_arena_alloc_fails_when_over_capacity(void);
|
||||
TestFuncResult test_arena_clear(void);
|
||||
TestFuncResult test_arena_destroy(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif // __cplusplus
|
||||
|
||||
#endif // !TEST_ARENA_H
|
@ -1,11 +0,0 @@
|
||||
#include "test_arena.h"
|
||||
#include "tester.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(void) {
|
||||
run_tests(test_arena_init, test_arena_alloc_succeeds_when_within_capacity,
|
||||
test_arena_alloc_fails_when_over_capacity, test_arena_clear,
|
||||
test_arena_destroy);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
Loading…
Reference in New Issue
Block a user