testcase/ta_tc: Add tc for task_manager_set_termination_cb
If resource deallocation callback is registered, resources will be released when requested to terminate the task.
#include <tinyara/config.h>
#include <stdio.h>
#include <string.h>
+#include <stdlib.h>
#include <unistd.h>
#include <stdbool.h>
#include <sys/types.h>
@@ -39,6 +40,8 @@ static bool flag;
static task_info_t *sample_info;
static task_info_list_t *group_list_info;
static task_info_list_t *sample_list_info;
+static int *addr;
+static int *addr2;
static void test_handler(int sig, tm_msg_t *info)
{
@@ -47,6 +50,12 @@ static void test_handler(int sig, tm_msg_t *info)
flag = true;
}
+void free_handler(void)
+{
+ free(addr);
+ free(addr2);
+}
+
int tm_sample_main(int argc, char *argv[])
{
int ret;
@@ -134,6 +143,28 @@ static void utc_task_manager_set_handler_p(void)
TC_SUCCESS_RESULT();
}
+static void utc_task_manager_set_termination_cb_n(void)
+{
+ int ret;
+ ret = task_manager_set_termination_cb(NULL);
+ TC_ASSERT_EQ("task_manager_set_termination_cb_n", ret, TM_INVALID_PARAM);
+
+ TC_SUCCESS_RESULT();
+}
+
+static void utc_task_manager_set_termination_cb_p(void)
+{
+ int ret;
+ /* No meaningful malloc for testing resource collection handler */
+ addr = (int *)malloc(123);
+ addr2 = (int *)malloc(456);
+
+ ret = task_manager_set_termination_cb(free_handler);
+ TC_ASSERT_EQ("task_manager_set_termination_cb_p", ret, OK);
+
+ TC_SUCCESS_RESULT();
+}
+
static void utc_task_manager_unicast_n(void)
{
int ret;
@@ -371,6 +402,9 @@ int utc_task_manager_main(int argc, char *argv[])
utc_task_manager_set_handler_n();
utc_task_manager_set_handler_p();
+ utc_task_manager_set_termination_cb_n();
+ utc_task_manager_set_termination_cb_p();
+
utc_task_manager_unicast_n();
utc_task_manager_unicast_p();
