Beispiel #1
0
/**
 * \b test2_thread_func
 *
 * Entry point for test thread 2.
 *
 * @param[in] param Unused (optional thread entry parameter)
 *
 * @return None
 */
static void test2_thread_func (uint32_t param)
{
    uint8_t status, msg;

    /* Compiler warnings */
    param = param;

    /*
     * Wait on queue1 with timeout. We are expecting to be woken up
     * by the main thread while blocking.
     */
    status = atomQueueGet(&queue1, (5 * SYSTEM_TICKS_PER_SEC), &msg);
    if (status != ATOM_ERR_DELETED)
    {
        ATOMLOG (_STR("Test2 thread woke without deletion (%d)\n"), status);
    }
    else
    {
        /* We were woken due to deletion as expected, set g_result to notify success */
        g_result = 1;
    }

    /* Wait forever */
    while (1)
    {
        atomTimerDelay (SYSTEM_TICKS_PER_SEC);
    }
}
Beispiel #2
0
/**
 * \b test_thread_func
 *
 * Entry point for test threads.
 *
 * @param[in] param Thread ID (0-2)
 *
 * @return None
 */
static void test_thread_func (uint32_t param)
{
    uint8_t status;
    uint8_t msg;
    int thread_id;

    /* Pull out the passed thread ID */
    thread_id = (int)param;

    /*
     * Wait on queue1 with timeout. We are expecting to be woken up
     * by the main thread while blocking.
     */
    status = atomQueueGet(&queue1, (5 * SYSTEM_TICKS_PER_SEC), &msg);
    if (status != ATOM_ERR_DELETED) {
        ATOMLOG (_STR("Test1 thread woke without deletion (%d)\n"), status);
    } else {
        /* We were woken due to deletion as expected, set pass_flag to notify success */
        pass_flag[thread_id] = TRUE;
    }

    /* Wait forever */
    while (1) {
        atomTimerDelay (SYSTEM_TICKS_PER_SEC);
    }
}
Beispiel #3
0
/**
 * \b test1_thread_func
 *
 * Entry point for test thread 1.
 *
 * @param[in] param Unused (optional thread entry parameter)
 *
 * @return None
 */
static void test1_thread_func (uint32_t param)
{
    uint32_t msg;
    int num_entries, count, failures;

    /* Compiler warnings */
    param = param;

    /* Default to no errors */
    failures = 0;

    /*
     * Loop receiving messages until we have received the number of
     * values in the test array.
     */
    num_entries = sizeof(test_values) / sizeof(test_values[0]);
    for (count = 0; count < num_entries; count++)
    {
        /* Receive a value from the queue */
        if (atomQueueGet (&queue1, 0, (uint8_t *)&msg) != ATOM_OK)
        {
            ATOMLOG (_STR("Failed get\n"));
            failures++;
        }

        /* Check that we received the expected value */
        else if (msg != test_values[count])
        {
            ATOMLOG (_STR("Val%d\n"), count);
            failures++;
        }
    }

    /*
     * Set g_result to indicate success if we had no failures.
     * Thread-protection is not required on g_result because it
     * is only ever set by this thread.
     */
    if (failures == 0)
    {
        /* No failures */
        g_result = 1;
    }

    /* Wait forever */
    while (1)
    {
        atomTimerDelay (SYSTEM_TICKS_PER_SEC);
    }
}
Beispiel #4
0
/**
 * \b test_thread_func
 *
 * Entry point for test thread. The same thread entry point is used for all
 * four test threads, with the thread number/ID (1-4) passed as the entry
 * point parameter.
 *
 * @param[in] param Thread number (1,2,3,4)
 *
 * @return None
 */
static void test_thread_func (uint32_t param)
{
    uint8_t thread_id;
    uint8_t msg;

    /* Thread ID is passed through the function parameter */
    thread_id = (uint8_t)param;

    /*
     * Wait for a message to appear on queue1. At creation of all test
     * threads the queue is empty, so all four threads will block here.
     */
    if (atomQueueGet (&queue1, 0, &msg) != ATOM_OK)
    {
        ATOMLOG (_STR("Get fail\n"));
    }
    else
    {
        /*
         * Store our thread ID in the array using the current
         * wake_cnt order. The threads are woken with large
         * pauses between, which provides protection for this
         * global data. This allows us to test queues without
         * assuming a working implementation of a mutex (or
         * similar protection mechanism).
         */
        wake_order[wake_cnt++] = thread_id;

    }

    /* Loop forever */
    while (1)
    {
        atomTimerDelay (SYSTEM_TICKS_PER_SEC);
    }
}
Beispiel #5
0
/**
 * \b test_start
 *
 * Start queue test.
 *
 * This tests basic operation of queues.
 *
 * Messages are posted to and received from the queue and checked
 * against expected values. To ensure correct ordering, queue posts
 * and receives are done in blocks of different amounts, such that
 * there will already be different numbers of messages in the queue
 * whenever messages are posted and received.
 *
 * We test using 4-byte messages.
 *
 * @retval Number of failures
 */
uint32_t test_start (void)
{
    int failures, tx_count, rx_count;
    uint32_t msg;

    /* Default to zero failures */
    failures = 0;

    /* Create test queue */
    if (atomQueueCreate (&queue1, (uint8_t *)&queue1_storage[0], sizeof(queue1_storage[0]), QUEUE_ENTRIES) != ATOM_OK)
    {
        ATOMLOG (_STR("Error creating test queue\n"));
        failures++;
    }

    else
    {
        /* Reset tx/rx counts */
        tx_count = rx_count = 0;

        /* Post 2 messages to the queue */
        for (; tx_count < 2; tx_count++)
        {
            msg = test_values[tx_count];
            if (atomQueuePut (&queue1, 0, (uint8_t *)&msg) != ATOM_OK)
            {
                ATOMLOG (_STR("Failed post\n"));
                failures++;
            }
        }

        /* Receive 1 message from the queue */
        for (; rx_count < 2; rx_count++)
        {
            if (atomQueueGet (&queue1, 0, (uint8_t *)&msg) != ATOM_OK)
            {
                ATOMLOG (_STR("Failed get\n"));
                failures++;
            }
            else if (msg != test_values[rx_count])
            {
                ATOMLOG (_STR("Val%d\n"), rx_count);
                failures++;
            }
        }

        /* Post 3 messages to the queue */
        for (; tx_count < 5; tx_count++)
        {
            msg = test_values[tx_count];
            if (atomQueuePut (&queue1, 0, (uint8_t *)&msg) != ATOM_OK)
            {
                ATOMLOG (_STR("Failed post\n"));
                failures++;
            }
        }

        /* Receive 2 messages from the queue */
        for (; rx_count < 3; rx_count++)
        {
            if (atomQueueGet (&queue1, 0, (uint8_t *)&msg) != ATOM_OK)
            {
                ATOMLOG (_STR("Failed get\n"));
                failures++;
            }
            else if (msg != test_values[rx_count])
            {
                ATOMLOG (_STR("Val%d\n"), rx_count);
                failures++;
            }
        }

        /* Post 5 messages to the queue */
        for (; tx_count < 10; tx_count++)
        {
            msg = test_values[tx_count];
            if (atomQueuePut (&queue1, 0, (uint8_t *)&msg) != ATOM_OK)
            {
                ATOMLOG (_STR("Failed post\n"));
                failures++;
            }
        }

        /* Receive 3 messages from the queue */
        for (; rx_count < 6; rx_count++)
        {
            if (atomQueueGet (&queue1, 0, (uint8_t *)&msg) != ATOM_OK)
            {
                ATOMLOG (_STR("Failed get\n"));
                failures++;
            }
            else if (msg != test_values[rx_count])
            {
                ATOMLOG (_STR("Val%d\n"), rx_count);
                failures++;
            }
        }

        /* Post 2 messages to the queue */
        for (; tx_count < 12; tx_count++)
        {
            msg = test_values[tx_count];
            if (atomQueuePut (&queue1, 0, (uint8_t *)&msg) != ATOM_OK)
            {
                ATOMLOG (_STR("Failed post\n"));
                failures++;
            }
        }

        /* Receive 6 messages from the queue */
        for (; rx_count < 12; rx_count++)
        {
            if (atomQueueGet (&queue1, 0, (uint8_t *)&msg) != ATOM_OK)
            {
                ATOMLOG (_STR("Failed get\n"));
                failures++;
            }
            else if (msg != test_values[rx_count])
            {
                ATOMLOG (_STR("Val%d\n"), rx_count);
                failures++;
            }
        }
    }

    /* Quit */
    return failures;
}