jobid generate
This commit is contained in:
parent
9ff857db9f
commit
f3f6a78b07
7 changed files with 187 additions and 2 deletions
78
src/lib/testsuite/test_idgen.c
Normal file
78
src/lib/testsuite/test_idgen.c
Normal 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);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue