Files
TencentOS-tiny/test/suit_robin.c
daishengdong d0b8d0675e add ring queue/message queue/mail queue, binary heap/priority queue/priority message queue/priority mail queue
1. remove the old msg queue and queue:
i. msg queue is not a common and reusable/flexible component(need user to config the msg pool size and this componet can only be used by tos_queue)
ii. tos_queue can only deliver the pointer message(cannot do a memory buffer deliver)

2. add ring queue(tos_ring_q) componet
rinq queue can be reused by tos_chr_fifi/tos_msg_q/tos_mail_q as the foundational data container

3. add message queue(tos_msg_q)
a little like the old queue mechanism, supply the capability to deliver a pointer message

4. add mail queue(tos_mail_q)
supply the capability to deliver a memory buffer

5. add binary heap(tos_bin_heap)
the basement componet to implement priority queue

6. add priority queue(tos_prio_q)
can be reused by the priority message/mail queue  as the foundational data container.

7. add priority message queue(tos_prio_msg_q)
a message(pointer) deliver mechanism, supply the capability of delivering the message with priority(message with higher priority comes faster to the pender than with lower)

8. add priority mail queue(tos_prio_mail_q)
a mail(memory buffer) deliver mechanism, supply the capability of delivering the mail with priority(mail with higher priority comes faster to the pender than with lower)
2019-10-28 15:50:46 +08:00

79 lines
1.9 KiB
C

#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include "test/test.h"
#include "greatest/greatest.h"
#if TOS_CFG_ROUND_ROBIN_EN > 0u
SUITE(suit_robin);
static const k_timeslice_t test_robin_timeslice_00 = 10;
static const k_timeslice_t test_robin_timeslice_01 = 20;
static uint64_t test_robin_counter_00 = 1;
static uint64_t test_robin_counter_01 = 1;
static void test_robin_task_00_entry(void *arg)
{
while (K_TRUE) {
++test_robin_counter_00;
}
}
static void test_robin_task_01_entry(void *arg)
{
while (K_TRUE) {
++test_robin_counter_01;
}
}
TEST test_robin(void)
{
k_err_t err;
double r_c, r_t;
int test_count = 0;
const double deviation = 0.1;
tos_robin_default_timeslice_config((k_timeslice_t)500u);
err = tos_task_create(&test_task_00, "test_task_00", test_robin_task_00_entry,
NULL, k_curr_task->prio + 1,
test_task_stack_00, sizeof(test_task_stack_00),
test_robin_timeslice_00);
ASSERT_EQ(err, K_ERR_NONE);
err = tos_task_create(&test_task_01, "test_task_01", test_robin_task_01_entry,
NULL, k_curr_task->prio + 1,
test_task_stack_01, sizeof(test_task_stack_01),
test_robin_timeslice_01);
ASSERT_EQ(err, K_ERR_NONE);
r_t = test_robin_timeslice_01 / test_robin_timeslice_00;
while (test_count++ < 5) {
tos_task_delay(1000);
r_c = (double)test_robin_counter_01 / test_robin_counter_00;
if (r_t > r_c) {
ASSERT(r_t - r_c <= deviation);
} else {
ASSERT(r_c - r_t <= deviation);
}
}
err = tos_task_destroy(&test_task_00);
ASSERT_EQ(err, K_ERR_NONE);
err = tos_task_destroy(&test_task_01);
ASSERT_EQ(err, K_ERR_NONE);
PASS();
}
SUITE(suit_robin)
{
RUN_TEST(test_robin);
}
#endif