Skip to content

Commit

Permalink
unified/test: Fix issues affecting LIFO object test application
Browse files Browse the repository at this point in the history
Revises the test to account for changes in LIFO object behavior
in the unified kernel.

Note: A LIFO object shouldn't really be used to try and pass
data items between two different threads in an ordered manner,
as this test is doing. Ordered behavior should only be expected
when a single thread is adding and removing items from a LIFO.
A LIFO is typically used to pass data items between different
threads when ordering doesn't matter -- for example, when using the
LIFO to implement a shared pool of data items that can be allocated
and returned by a bunch of threads. (A LIFO object is more efficient
than a FIFO object for implementing this kind of pool.)

Change-Id: Ic4cbd8b8368477e72c1bf0bca35600b78f963933
Signed-off-by: Allan Stephens <[email protected]>
  • Loading branch information
ajstephens committed Oct 11, 2016
1 parent 8472a63 commit f0d6c03
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 13 deletions.
45 changes: 33 additions & 12 deletions tests/kernel/test_lifo/src/lifo.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ int fiberLifoWaitTest(void)

/* The task is waiting on an empty LIFO. Wake it up. */
nano_fiber_lifo_put(&test_lifo, &lifoItem[3]);
nano_fiber_lifo_put(&test_lifo, &lifoItem[2]);
nano_fiber_lifo_put(&test_lifo, &lifoItem[1]);

/*
Expand Down Expand Up @@ -321,6 +322,31 @@ static void fiberEntry(int arg1, int arg2)
int taskLifoWaitTest(void)
{
void *data; /* ptr to data retrieved from LIFO */
int i;

#ifdef CONFIG_KERNEL_V2
/*
* the first item sent by the fiber is given directly to the waiting
* task, which then ceases waiting (but doesn't get to execute yet);
* the two remaining items then get queued internally by the LIFO,
* and are later retrieved by the task in LIFO order
*/

int expected_item[3] = { 3, 1, 2 };
#else
/*
* all 3 items sent by the fiber are queued internally by the LIFO,
* while the task is busy waiting; when the task finally gets to run
* it retrieves all of the items in LIFO order
*
* note that the items would be received in a different order
* if a fiber was waiting on the FIFO!; in this case, the first
* item would be given directly to the fiber, and only the two
* remaining items would be queued internally by the LIFO
*/

int expected_item[3] = { 1, 2, 3 };
#endif

/* Wait on <taskWaitSem> in case fiber's print message blocked */
nano_fiber_sem_take(&taskWaitSem, TICKS_UNLIMITED);
Expand All @@ -345,22 +371,17 @@ int taskLifoWaitTest(void)
return TC_FAIL;
}

/* The LIFO is empty. This time the task will wait for the item. */
/* The LIFO is empty. This time the task will wait for the 3 items. */

TC_PRINT("Task waiting on an empty LIFO\n");
data = nano_task_lifo_get(&test_lifo, TICKS_UNLIMITED);
if (data != (void *) &lifoItem[1]) {
TC_ERROR(" *** nano_task_lifo_get()/nano_fiber_lifo_put() failure\n");
return TC_FAIL;
}

data = nano_task_lifo_get(&test_lifo, TICKS_UNLIMITED);
if (data != (void *) &lifoItem[3]) {
TC_ERROR(" *** nano_task_lifo_get()/nano_fiber_lifo_put() failure\n");
return TC_FAIL;
for (i = 0; i < 3; i++) {
data = nano_task_lifo_get(&test_lifo, TICKS_UNLIMITED);
if (data != (void *) &lifoItem[expected_item[i]]) {
TC_ERROR(" *** nano_task_lifo_get()/nano_fiber_lifo_put() failure\n");
return TC_FAIL;
}
}


/* Waiting on an empty LIFO passed for both fiber and task. */

return TC_PASS;
Expand Down
2 changes: 1 addition & 1 deletion tests/kernel/test_lifo/testcase.ini
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
[test]
tags = core
tags = core unified_capable

0 comments on commit f0d6c03

Please sign in to comment.