Ken Van Hoeylandt 47377439dd
Implement unit testing (#30)
- Create `test` and `tactility-core-tests` subprojects
- Created tests for `thread.c`
- Fixed issue with thread cleanup (see what I did there? :P)
- Removed functions from `thread.h` that did not exist anymore
- Updated `ideas.md`
2024-02-02 00:12:36 +01:00

59 lines
1.2 KiB
C++

#define DOCTEST_CONFIG_IMPLEMENT
#include "doctest.h"
#include <cassert>
#include "FreeRTOS.h"
#include "task.h"
typedef struct {
int argc;
char** argv;
int result;
} TestTaskData;
void test_task(void* parameter) {
auto* data = (TestTaskData*)parameter;
doctest::Context context;
context.applyCommandLine(data->argc, data->argv);
// overrides
context.setOption("no-breaks", true); // don't break in the debugger when assertions fail
data->result = context.run();
if (context.shouldExit()) { // important - query flags (and --exit) rely on the user doing this
vTaskEndScheduler();
}
vTaskDelete(NULL);
}
int main(int argc, char** argv) {
TestTaskData data = {
.argc = argc,
.argv = argv,
.result = 0
};
BaseType_t task_result = xTaskCreate(
test_task,
"test_task",
8192,
&data,
1,
NULL
);
assert(task_result == pdPASS);
vTaskStartScheduler();
}
extern "C" {
// Required for FreeRTOS
void vAssertCalled(unsigned long line, const char* const file) {
__assert_fail("assert failed", file, line, "");
}
}