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`
This commit is contained in:
committed by
GitHub
parent
50e7fb92c8
commit
47377439dd
+10
-16
@@ -72,7 +72,7 @@ static void tt_thread_body(void* context) {
|
||||
tt_assert(context);
|
||||
Thread* thread = context;
|
||||
|
||||
// store thread instance to thread local storage
|
||||
// Store thread instance to thread local storage
|
||||
tt_assert(pvTaskGetThreadLocalStoragePointer(NULL, 0) == NULL);
|
||||
vTaskSetThreadLocalStoragePointer(NULL, 0, thread);
|
||||
|
||||
@@ -80,19 +80,23 @@ static void tt_thread_body(void* context) {
|
||||
tt_thread_set_state(thread, ThreadStateRunning);
|
||||
|
||||
thread->ret = thread->callback(thread->context);
|
||||
TT_LOG_I(TAG, "thread returned: %s", thread->name ?: "[no name]");
|
||||
|
||||
tt_assert(thread->state == ThreadStateRunning);
|
||||
|
||||
if (thread->is_static) {
|
||||
TT_LOG_I(
|
||||
TAG,
|
||||
"%s service thread TCB memory will not be reclaimed",
|
||||
"%s static task memory will not be reclaimed",
|
||||
thread->name ? thread->name : "<unnamed service>"
|
||||
);
|
||||
}
|
||||
|
||||
tt_thread_set_state(thread, ThreadStateStopped);
|
||||
|
||||
vTaskSetThreadLocalStoragePointer(NULL, 0, NULL);
|
||||
thread->task_handle = NULL;
|
||||
|
||||
vTaskDelete(NULL);
|
||||
tt_thread_catch();
|
||||
}
|
||||
@@ -114,7 +118,7 @@ Thread* tt_thread_alloc() {
|
||||
tt_thread_set_appid(thread, "unknown");
|
||||
}
|
||||
} else {
|
||||
// if scheduler is not started, we are starting driver thread
|
||||
// If scheduler is not started, we are starting driver thread
|
||||
tt_thread_set_appid(thread, "driver");
|
||||
}
|
||||
|
||||
@@ -250,28 +254,18 @@ void tt_thread_start(Thread* thread) {
|
||||
#else
|
||||
TT_LOG_E(TAG, "static tasks are not supported by current FreeRTOS config/platform - creating regular one");
|
||||
BaseType_t ret = xTaskCreate(
|
||||
tt_thread_body, thread->name, stack, thread, priority, &thread->task_handle
|
||||
tt_thread_body, thread->name, stack, thread, priority, &(thread->task_handle)
|
||||
);
|
||||
tt_check(ret == pdPASS);
|
||||
#endif
|
||||
} else {
|
||||
BaseType_t ret = xTaskCreate(
|
||||
tt_thread_body, thread->name, stack, thread, priority, &thread->task_handle
|
||||
tt_thread_body, thread->name, stack, thread, priority, &(thread->task_handle)
|
||||
);
|
||||
tt_check(ret == pdPASS);
|
||||
}
|
||||
|
||||
tt_check(thread->task_handle);
|
||||
}
|
||||
|
||||
void tt_thread_cleanup_tcb_event(TaskHandle_t task) {
|
||||
Thread* thread = pvTaskGetThreadLocalStoragePointer(task, 0);
|
||||
if (thread) {
|
||||
// clear thread local storage
|
||||
vTaskSetThreadLocalStoragePointer(task, 0, NULL);
|
||||
tt_assert(thread->task_handle == task);
|
||||
thread->task_handle = NULL;
|
||||
}
|
||||
tt_check(thread->state == ThreadStateStopped || thread->task_handle);
|
||||
}
|
||||
|
||||
bool tt_thread_join(Thread* thread) {
|
||||
|
||||
@@ -197,26 +197,6 @@ bool tt_thread_join(Thread* thread);
|
||||
*/
|
||||
ThreadId tt_thread_get_id(Thread* thread);
|
||||
|
||||
/** Enable heap tracing
|
||||
*
|
||||
* @param thread Thread instance
|
||||
*/
|
||||
void tt_thread_enable_heap_trace(Thread* thread);
|
||||
|
||||
/** Disable heap tracing
|
||||
*
|
||||
* @param thread Thread instance
|
||||
*/
|
||||
void tt_thread_disable_heap_trace(Thread* thread);
|
||||
|
||||
/** Get thread heap size
|
||||
*
|
||||
* @param thread Thread instance
|
||||
*
|
||||
* @return size in bytes
|
||||
*/
|
||||
size_t tt_thread_get_heap_size(Thread* thread);
|
||||
|
||||
/** Get thread return code
|
||||
*
|
||||
* @param thread Thread instance
|
||||
@@ -276,33 +256,6 @@ const char* tt_thread_get_appid(ThreadId thread_id);
|
||||
*/
|
||||
uint32_t tt_thread_get_stack_space(ThreadId thread_id);
|
||||
|
||||
/** Get STDOUT callback for thead
|
||||
*
|
||||
* @return STDOUT callback
|
||||
*/
|
||||
ThreadStdoutWriteCallback tt_thread_get_stdout_callback();
|
||||
|
||||
/** Set STDOUT callback for thread
|
||||
*
|
||||
* @param callback callback or NULL to clear
|
||||
*/
|
||||
void tt_thread_set_stdout_callback(ThreadStdoutWriteCallback callback);
|
||||
|
||||
/** Write data to buffered STDOUT
|
||||
*
|
||||
* @param data input data
|
||||
* @param size input data size
|
||||
*
|
||||
* @return size_t written data size
|
||||
*/
|
||||
size_t tt_thread_stdout_write(const char* data, size_t size);
|
||||
|
||||
/** Flush data to STDOUT
|
||||
*
|
||||
* @return int32_t error code
|
||||
*/
|
||||
int32_t tt_thread_stdout_flush();
|
||||
|
||||
/** Suspend thread
|
||||
*
|
||||
* @param thread_id thread id
|
||||
|
||||
Reference in New Issue
Block a user