static void nasa_osal_test_002_003_teardown(void) { if (qid != 0) { (void) OS_QueueDelete(qid); } if (tid != 0) { (void) OS_TaskWait(tid); } }
static void nasa_osal_test_002_003_execute(void) { uint32 tid; unsigned i; /* [2.3.1] Creataing a queue with depth 4 and message size 20.*/ test_set_step(1); { int32 err; err = OS_QueueCreate(&qid, "test queue", 4, MESSAGE_SIZE, 0); test_assert(err == OS_SUCCESS, "queue creation failed"); } /* [2.3.2] Creating the writer task.*/ test_set_step(2); { int32 err; err = OS_TaskCreate(&tid, "writer task", test_task_writer, (uint32 *)wa_test1, sizeof wa_test1, TASKS_BASE_PRIORITY, 0); test_assert(err == OS_SUCCESS, "writer task creation failed"); } /* [2.3.3] Reading messages from the writer task.*/ test_set_step(3); { for (i = 0; i < WRITER_NUM_MESSAGES; i++) { int32 err; char data[MESSAGE_SIZE]; uint32 copied; err = OS_QueueGet(qid, data, MESSAGE_SIZE, &copied, OS_Milli2Ticks(200)); test_assert(err == OS_SUCCESS, "timed out"); test_assert(strncmp(data, "Hello World", sizeof (data)) == 0, "wrong message"); } } /* [2.3.4] Waiting for task termination then checking for errors.*/ test_set_step(4); { (void) OS_TaskWait(tid); tid = 0; test_assert_sequence("", "queue write errors occurred"); } }
static void test_001_001_execute(void) { /* [1.1.1] OS_TaskCreate() is invoked with task_id set to NULL, an error is expected.*/ test_set_step(1); { int32 err; err = OS_TaskCreate(NULL, /* Error.*/ "failing task", test_task1, (uint32 *)wa_test1, sizeof wa_test1, TASKS_BASE_PRIORITY, 0); test_assert(err == OS_INVALID_POINTER, "NULL not detected"); test_assert_sequence("", "task executed"); } /* [1.1.2] OS_TaskCreate() is invoked with task_name set to NULL, an error is expected.*/ test_set_step(2); { int32 err; uint32 tid; err = OS_TaskCreate(&tid, NULL, /* Error.*/ test_task1, (uint32 *)wa_test1, sizeof wa_test1, TASKS_BASE_PRIORITY, 0); test_assert(err == OS_INVALID_POINTER, "NULL not detected"); test_assert_sequence("", "task executed"); } /* [1.1.3] OS_TaskCreate() is invoked with stack_pointer set to NULL, an error is expected.*/ test_set_step(3); { int32 err; uint32 tid; err = OS_TaskCreate(&tid, "failing task", test_task1, (uint32 *)NULL, /* Error.*/ sizeof wa_test1, TASKS_BASE_PRIORITY, 0); test_assert(err == OS_INVALID_POINTER, "NULL not detected"); test_assert_sequence("", "task executed"); } /* [1.1.4] OS_TaskCreate() is invoked with a very long task name, an error is expected.*/ test_set_step(4); { int32 err; uint32 tid; err = OS_TaskCreate(&tid, "this is a very very long task name", /* Error.*/ test_task1, (uint32 *)wa_test1, sizeof wa_test1, TASKS_BASE_PRIORITY, 0); test_assert(err == OS_ERR_NAME_TOO_LONG, "name limit not detected"); test_assert_sequence("", "task executed"); } /* [1.1.5] OS_TaskCreate() is invoked with priority below and above allowed range, an error is expected.*/ test_set_step(5); { int32 err; uint32 tid; err = OS_TaskCreate(&tid, "failing task", test_task1, (uint32 *)wa_test1, sizeof wa_test1, 0, /* Error.*/ 0); test_assert(err == OS_ERR_INVALID_PRIORITY, "priority error not detected"); test_assert_sequence("", "task executed"); err = OS_TaskCreate(&tid, "failing task", test_task1, (uint32 *)wa_test1, sizeof wa_test1, 256, /* Error.*/ 0); test_assert(err == OS_ERR_INVALID_PRIORITY, "priority error not detected"); test_assert_sequence("", "task executed"); } /* [1.1.6] OS_TaskCreate() is invoked with a stack size below minimum, an error is expected.*/ test_set_step(6); { int32 err; uint32 tid; err = OS_TaskCreate(&tid, "failing task", test_task1, (uint32 *)wa_test1, 16, /* Error.*/ TASKS_BASE_PRIORITY, 0); test_assert(err == OS_INVALID_INT_NUM, "stack insufficient size not detected"); test_assert_sequence("", "task executed"); } /* [1.1.7] OS_TaskCreate() is invoked twice with duplicated name and then duplicated stack, an error is expected in both cases.*/ test_set_step(7); { int32 err; uint32 tid; err = OS_TaskCreate(&tid, "running task", test_task1, (uint32 *)wa_test1, sizeof wa_test1, TASKS_BASE_PRIORITY, 0); test_assert(err == OS_SUCCESS, "task creation failed"); err = OS_TaskCreate(&tid, "running task", test_task2, (uint32 *)wa_test2, sizeof wa_test2, TASKS_BASE_PRIORITY, 0); test_assert(err == OS_ERR_NAME_TAKEN, "name conflict not detected"); err = OS_TaskCreate(&tid, "conflicting task", test_task1, (uint32 *)wa_test1, sizeof wa_test1, TASKS_BASE_PRIORITY, 0); test_assert(err == OS_ERR_NO_FREE_IDS, "stack conflict not detected"); err = OS_TaskWait(tid); test_assert(err == OS_SUCCESS, "wait failed"); test_assert_sequence("A", "task not executed"); err = OS_TaskCreate(&tid, "running task", test_task1, (uint32 *)wa_test1, sizeof wa_test1, TASKS_BASE_PRIORITY, 0); test_assert(err == OS_SUCCESS, "task creation failed"); err = OS_TaskWait(tid); test_assert(err == OS_SUCCESS, "wait failed"); test_assert_sequence("A", "task not executed"); } }