pass pend reason back to controller

This commit is contained in:
Rongsong Shen 2025-12-23 15:29:26 +08:00
parent cd0bca3138
commit 5560ae91da
16 changed files with 349 additions and 123 deletions

View file

@ -47,14 +47,14 @@ static void test_ordq_get(void)
return;
}
static int test_skip(void* data, va_list ap)
static int test_match(void* data, va_list ap)
{
int val = (int)(long)data;
return (val % 2 != 0);
return (val % 2 == 0);
}
static void test_ordq_get_skip(void)
static void test_ordq_get_match(void)
{
int rc;
ordq_t q;
@ -73,7 +73,7 @@ static void test_ordq_get_skip(void)
j = 0;
nc = 0;
for (i = 0; i < 5; i++) {
it = ordq_get(&q, test_skip);
it = ordq_get(&q, test_match);
if (it == NULL) {
break;
@ -125,14 +125,14 @@ static void test_ordq_peek(void)
return;
}
static int test_skip2(void* data, va_list ap)
static int test_match2(void* data, va_list ap)
{
int val = (int)(long)data;
return (val % 3 != 0);
return (val % 3 == 0);
}
static void test_ordq_peek_skip(void)
static void test_ordq_peek_match(void)
{
int rc;
ordq_t q;
@ -150,7 +150,7 @@ static void test_ordq_peek_skip(void)
for (i = 0; i < 8; i++) {
it = ordq_peek(
&q, test_skip2); /* ordq_peek() will not remove item from q */
&q, test_match2); /* ordq_peek() will not remove item from q */
TEST_ASSERT_TRUE((it != NULL) && ((int)(long)it->data == val[4]));
}
@ -160,12 +160,42 @@ static void test_ordq_peek_skip(void)
return;
}
static void test_ordq_del(void)
{
int rc;
ordq_t q;
ordq_item_t* it;
int keys[8] = { 9, 8, 1, 4, 7, 2, 6, 2 };
int i;
int count;
rc = ordq_init(&q, NULL, (ordq_cmp_fn_t)long_cmp);
TEST_ASSERT_TRUE(rc >= 0);
for (i = 0; i < 8; i++) {
ordq_put(&q, (void*)(long)(keys[i]));
}
count = ordq_del(&q, test_match2);
TEST_ASSERT_TRUE(count == 2);
while ((it = ordq_get(&q, NULL)) != NULL) {
TEST_ASSERT_TRUE((int)(long)it->data % 3 != 0);
free(it);
}
ordq_fini(&q);
return;
}
void test_ordq(void)
{
printf("\n>> ordq test\n\n");
RUN_TEST(test_ordq_get);
RUN_TEST(test_ordq_peek);
RUN_TEST(test_ordq_get_skip);
RUN_TEST(test_ordq_peek_skip);
RUN_TEST(test_ordq_get_match);
RUN_TEST(test_ordq_peek_match);
RUN_TEST(test_ordq_del);
}