use librtti for worker/queue/resource

This commit is contained in:
Rongsong Shen 2026-02-25 16:56:42 +08:00
parent 532c68e6e1
commit 2ee87d4ee6
23 changed files with 1078 additions and 396 deletions

View file

@ -25,6 +25,8 @@ extern void test_resreq(void);
extern void test_bitset(void);
extern void test_kv(void);
extern void test_jobobj(void);
extern void test_qobj(void);
extern void test_wobj(void);
void setUp(void) { return; }
@ -119,6 +121,8 @@ int main(int argc, char* argv[])
TEST(test_bitset);
TEST(test_kv);
TEST(test_jobobj);
TEST(test_wobj);
TEST(test_qobj);
return UNITY_END();
}

View file

@ -272,7 +272,7 @@ static void test_job_create(void)
&& (j2->submit->mintasks == 1) && (j2->submit->maxtasks == 5)
&& (j2->submit->user_group == NULL));
destroy(j2);
dereference(j2);
job_obj_fini();
xstring_table_fini();

View file

@ -10,7 +10,10 @@
static void test_kv_int_create()
{
var tab = makeInstance(&kvtab_int64_type, 31, NULL);
kv_params_t params
= { .nslots = 32, .keyops = &int_key_ops, .datakiller = NULL };
var tab = makeInstance(&kvtab_type, &params);
TEST_ASSERT_TRUE(tab != NULL);
@ -19,7 +22,9 @@ static void test_kv_int_create()
static void test_kv_int1()
{
var tab = makeInstance(&kvtab_int64_type, 31, NULL);
kv_params_t params
= { .nslots = 32, .keyops = &int_key_ops, .datakiller = NULL };
var tab = makeInstance(&kvtab_type, &params);
int i;
int rc;
@ -71,7 +76,9 @@ static void my_free(void* p)
static void test_kv_int2()
{
var tab = makeInstance(&kvtab_int64_type, 31, my_free);
kv_params_t params
= { .nslots = 32, .keyops = &int_key_ops, .datakiller = my_free };
var tab = makeInstance(&kvtab_type, &params);
int i;
int rc;
char buf[128];
@ -105,7 +112,9 @@ static void test_kv_int2()
static void test_kv_string1()
{
var tab = makeInstance(&kvtab_string_type, 31, NULL);
kv_params_t params
= { .nslots = 32, .keyops = &string_key_ops, .datakiller = NULL };
var tab = makeInstance(&kvtab_type, &params);
int i;
int rc;
char buf[64];
@ -153,7 +162,9 @@ static void test_kv_string1()
static void test_kv_string_create()
{
var tab = makeInstance(&kvtab_string_type, 31, NULL);
kv_params_t params
= { .nslots = 32, .keyops = &string_key_ops, .datakiller = NULL };
var tab = makeInstance(&kvtab_type, &params);
TEST_ASSERT_TRUE(tab != NULL);

View file

@ -0,0 +1,35 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unity/unity.h>
#include "qobj.h"
#include "utils.h"
#include "xstring.h"
static void test_queue_create(void)
{
int rc;
xce_queue_t q1 = { 0 };
xce_queue_t* q = NULL;
rc = xstring_table_init(32);
TEST_ASSERT_TRUE(rc >= 0);
q = makeQueue(&q1);
TEST_ASSERT_TRUE(q != NULL);
destroy(q);
xstring_table_fini();
}
void test_qobj(void)
{
printf("\n>> queue obj test\n\n");
RUN_TEST(test_queue_create);
}

View file

@ -0,0 +1,51 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unity/unity.h>
#include "utils.h"
#include "wobj.h"
#include "xstring.h"
static void test_worker_create(void)
{
int rc;
hostattrs_t attrs1 = { .hosttype = "LINUX64",
.hostmodel = "linux-gnu-x86_64",
.cpufactor = 100.0,
.maxcpus = 5,
.maxmem = 65536.0,
.maxswap = 65536.0,
.maxtmp = 0.0,
.ndisks = 2 };
xce_worker_t w1 = {
.name = "worker1",
.attrs = &attrs1,
};
xce_worker_t* w = NULL;
rc = xstring_table_init(32);
TEST_ASSERT_TRUE(rc >= 0);
w = makeWorker(&w1);
TEST_ASSERT_TRUE(w != NULL);
TEST_ASSERT_TRUE(EQUAL_STRING(w->name, w1.name)
&& EQUAL_STRING(w->attrs->hosttype, attrs1.hosttype)
&& EQUAL_STRING(w->attrs->hostmodel, attrs1.hostmodel)
&& (w->attrs->cpufactor == attrs1.cpufactor)
&& (w->attrs->maxcpus == attrs1.maxcpus));
dereference(w);
xstring_table_fini();
}
void test_wobj(void)
{
printf("\n>> worker obj test\n\n");
RUN_TEST(test_worker_create);
}

View file

@ -9,7 +9,8 @@
static void test_zarray_create()
{
var a = makeInstance(&xzarray_type, 4, NULL);
xzarray_params_t params = { .delta = 4, .datakiller = NULL };
var a = makeInstance(&xzarray_type, &params);
TEST_ASSERT_TRUE(a != NULL);
@ -18,10 +19,11 @@ static void test_zarray_create()
static void test_zarray_store()
{
var a = makeInstance(&xzarray_type, 4, NULL);
int idx;
int rc;
char* p = NULL;
xzarray_params_t params = { .delta = 4, .datakiller = NULL };
var a = makeInstance(&xzarray_type, &params);
int idx;
int rc;
char* p = NULL;
TEST_ASSERT_TRUE(a != NULL);
@ -39,9 +41,10 @@ static void test_zarray_store()
static void test_zarray_put()
{
var a = makeInstance(&xzarray_type, 4, NULL);
int rc, idx = 10;
char* p;
xzarray_params_t params = { .delta = 4, .datakiller = NULL };
var a = makeInstance(&xzarray_type, &params);
int rc, idx = 10;
char* p;
TEST_ASSERT_TRUE(a != NULL);
@ -58,13 +61,14 @@ static void test_zarray_put()
static void test_zarray_put_get_vec()
{
var a = makeInstance(&xzarray_type, 4, NULL);
int idxs[5] = { 1, 3, 5, 7, 9 };
void* vals[5] = { (void*)(long)2, (void*)(long)4, (void*)(long)6,
(void*)(long)8, (void*)(long)10 };
void* vals1[5];
int i;
int rc;
xzarray_params_t params = { .delta = 4, .datakiller = NULL };
var a = makeInstance(&xzarray_type, &params);
int idxs[5] = { 1, 3, 5, 7, 9 };
void* vals[5] = { (void*)(long)2, (void*)(long)4, (void*)(long)6,
(void*)(long)8, (void*)(long)10 };
void* vals1[5];
int i;
int rc;
TEST_ASSERT_TRUE(a != NULL);
@ -83,12 +87,13 @@ static void test_zarray_put_get_vec()
static void test_zarray_iter()
{
var a = makeInstance(&xzarray_type, 4, NULL);
int idxs[5] = { 1, 3, 5, 7, 9 };
int vals[5] = { 2, 4, 6, 8, 10 };
int i;
iterator_t it;
int rc;
xzarray_params_t params = { .delta = 4, .datakiller = NULL };
var a = makeInstance(&xzarray_type, &params);
int idxs[5] = { 1, 3, 5, 7, 9 };
int vals[5] = { 2, 4, 6, 8, 10 };
int i;
iterator_t it;
int rc;
TEST_ASSERT_TRUE(a != NULL);
@ -131,11 +136,12 @@ static void my_killer(void* p)
static void test_zarray_clear()
{
var a = makeInstance(&xzarray_type, 4, my_killer);
char* s = strdup("Hello");
char* d = NULL;
int idx = 31;
int rc;
xzarray_params_t params = { .delta = 4, .datakiller = my_killer };
var a = makeInstance(&xzarray_type, &params);
char* s = strdup("Hello");
char* d = NULL;
int idx = 31;
int rc;
TEST_ASSERT_TRUE(a != NULL);