jobid generate

This commit is contained in:
Rongsong Shen 2025-11-07 18:17:34 +08:00
parent 9ff857db9f
commit f3f6a78b07
7 changed files with 187 additions and 2 deletions

View file

@ -11,6 +11,7 @@ extern void test_ht_int(void);
extern void test_error(void);
extern void test_utils(void);
extern void test_config(void);
extern void test_idgen(void);
void setUp(void) { return; }
@ -20,6 +21,7 @@ int main(int argc, char* argv[])
{
UNITY_BEGIN();
test_config();
test_idgen();
test_ht_string();
test_ht_int();
test_zarray();

View file

@ -0,0 +1,78 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unity/unity.h>
#include "idgen.h"
#include <errno.h>
static void test_idgen_invalid(void)
{
idgen_ctx_t ctx;
uint64_t idx;
// TEST_ASSERT_TRUE(0 == 1);
TEST_ASSERT_TRUE(idgen_ctx_init(NULL) == -EINVAL);
idgen_ctx_init(&ctx);
TEST_ASSERT_TRUE(idgen(&ctx, 128, 3, 1, &idx) == -EINVAL);
TEST_ASSERT_TRUE(idgen(&ctx, 32, 128, 1, &idx) == -EINVAL);
TEST_ASSERT_TRUE(idgen(&ctx, 32, 3, 0, &idx) == -EINVAL);
TEST_ASSERT_TRUE(idgen(&ctx, 32, 3, 65536, &idx) == -EINVAL);
TEST_ASSERT_TRUE(idgen(&ctx, 32, 3, 128, NULL) == -EINVAL);
idgen_ctx_fini(&ctx);
}
static void test_idgen1(void)
{
idgen_ctx_t ctx;
uint64_t idx;
int rc, i;
rc = idgen_ctx_init(&ctx);
TEST_ASSERT_TRUE(rc >= 0);
for (i = 0; i < 20; i++) {
rc = idgen(&ctx, 0x0, 0x0, 1, &idx);
TEST_ASSERT_TRUE(rc >= 0);
printf("\tidx = %lx\n", idx);
}
idgen_ctx_fini(&ctx);
}
static void test_idgen_array(void)
{
idgen_ctx_t ctx;
uint64_t idx;
int rc, i;
rc = idgen_ctx_init(&ctx);
TEST_ASSERT_TRUE(rc >= 0);
for (i = 0; i < 5; i++) {
int k;
for (k = 0; k < 5; k++) {
rc = idgen(&ctx, 0x0, 0x0, i + 1, &idx);
TEST_ASSERT_TRUE(rc >= 0);
if ( i >= 1) {
TEST_ASSERT_TRUE((idx & MAX_ARRAY_IDX) == 0);
}
printf("\tidx = %lx\n", idx);
}
}
idgen_ctx_fini(&ctx);
}
void test_idgen(void)
{
printf("\n>> idgen test\n\n");
RUN_TEST(test_idgen_invalid);
RUN_TEST(test_idgen1);
RUN_TEST(test_idgen_array);
}

View file

@ -92,10 +92,18 @@ void test_dup_threshold()
return;
}
void test_roundup(void)
{
TEST_ASSERT_TRUE(ROUNDUP(1, 3) == 8);
TEST_ASSERT_TRUE(ROUNDUP(9, 4) == 16);
TEST_ASSERT_TRUE(ROUNDUP(31, 5) == 32);
}
void test_utils(void)
{
printf("\n>> utils test\n\n");
RUN_TEST(test_timewindow_config_dup);
RUN_TEST(test_dup_threshold);
RUN_TEST(test_roundup);
}