use nix build & meson & zlog
This commit is contained in:
parent
0123623742
commit
346768a144
60 changed files with 13739 additions and 0 deletions
35
src/lib/testsuite/test.c
Normal file
35
src/lib/testsuite/test.c
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "unity.h"
|
||||
|
||||
extern void test_xstrings(void);
|
||||
extern void test_zarray(void);
|
||||
extern void test_ht_string(void);
|
||||
extern void test_ht_int(void);
|
||||
extern void test_error(void);
|
||||
extern void test_utils(void);
|
||||
|
||||
void setUp(void)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
void tearDown(void)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
UNITY_BEGIN();
|
||||
test_ht_string();
|
||||
test_ht_int();
|
||||
test_zarray();
|
||||
test_xstrings();
|
||||
test_error();
|
||||
test_utils();
|
||||
|
||||
return UNITY_END();
|
||||
}
|
||||
44
src/lib/testsuite/test_error.c
Normal file
44
src/lib/testsuite/test_error.c
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "xce/errnox.h"
|
||||
#include "unity.h"
|
||||
#include "utils.h"
|
||||
|
||||
static void test_error_setget(void) {
|
||||
int myerrno =1;
|
||||
ectx_t *e;
|
||||
|
||||
SET_ERROR(myerrno);
|
||||
e = get_ectx();
|
||||
|
||||
TEST_ASSERT_TRUE(e != NULL);
|
||||
TEST_ASSERT_TRUE(errno == myerrno);
|
||||
TEST_ASSERT_TRUE(e->file != NULL);
|
||||
TEST_ASSERT_TRUE(e->func != NULL);
|
||||
TEST_ASSERT_TRUE(strcmp(e->file, __FILE__) == 0);
|
||||
TEST_ASSERT_TRUE(strcmp(e->func, __func__) == 0);
|
||||
}
|
||||
|
||||
#if 0
|
||||
static void test_strerror_r(void) {
|
||||
char errmsg1[256];
|
||||
char errmsg2[256];
|
||||
int errors[] ={ENOENT, EINVAL, E_XCE_BAD_JOB, E_XCE_BAD_WORKER, 0};
|
||||
int i;
|
||||
|
||||
for(i = 0; errors[i] != 0; i ++) {
|
||||
strerror_r(errors[i], errmsg1, sizeof(errmsg1));
|
||||
xce_strerror_r(errors[i], errmsg2, sizeof(errmsg2));
|
||||
TEST_ASSERT_TRUE(strcmp(errmsg1, errmsg2) == 0);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
void test_error(void) {
|
||||
printf("\n>> error test\n\n");
|
||||
|
||||
RUN_TEST(test_error_setget);
|
||||
#if 0
|
||||
RUN_TEST(test_strerror_r);
|
||||
#endif
|
||||
}
|
||||
50
src/lib/testsuite/test_htab.c
Normal file
50
src/lib/testsuite/test_htab.c
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "unity.h"
|
||||
#include "htab.h"
|
||||
|
||||
static htab_t htab;
|
||||
static char *s = "Hello,world";
|
||||
|
||||
static void test_ht_add_string(void) {
|
||||
hent_t *e = NULL;
|
||||
|
||||
e = ht_add(&(htab), (void *)s);
|
||||
TEST_ASSERT_NOT_NULL(e);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void test_ht_get_string(void) {
|
||||
hent_t *e = NULL;
|
||||
|
||||
e = ht_get(&htab, (void *)s);
|
||||
TEST_ASSERT_NOT_NULL(e);
|
||||
|
||||
TEST_ASSERT_TRUE(0 == strcmp(e->key, s));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void test_ht_del_string(void) {
|
||||
hent_t *e = NULL;
|
||||
|
||||
ht_del(&htab, (void *)s);
|
||||
|
||||
e = ht_get(&htab, (void *)s);
|
||||
TEST_ASSERT_TRUE( e == NULL);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void test_ht_string(void) {
|
||||
printf("\n>> htab test string\n\n");
|
||||
|
||||
ht_init(&htab, 13, string_hash_key);
|
||||
|
||||
RUN_TEST(test_ht_add_string);
|
||||
RUN_TEST(test_ht_get_string);
|
||||
RUN_TEST(test_ht_del_string);
|
||||
}
|
||||
52
src/lib/testsuite/test_htab_int.c
Normal file
52
src/lib/testsuite/test_htab_int.c
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "unity.h"
|
||||
#include "htab.h"
|
||||
|
||||
static htab_t htab;
|
||||
|
||||
uint64_t key = (uint64_t)0xfabcde6666666666;
|
||||
|
||||
static void test_ht_add_string(void) {
|
||||
hent_t *e = NULL;
|
||||
|
||||
e = ht_add(&(htab), (void *)key);
|
||||
TEST_ASSERT_NOT_NULL(e);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void test_ht_get_string(void) {
|
||||
hent_t *e = NULL;
|
||||
|
||||
e = ht_get(&htab, (void *)key);
|
||||
TEST_ASSERT_NOT_NULL(e);
|
||||
|
||||
TEST_ASSERT_TRUE((uint64_t)e->key == (uint64_t)key);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void test_ht_del_string(void) {
|
||||
hent_t *e = NULL;
|
||||
|
||||
ht_del(&htab, (void *)key);
|
||||
|
||||
e = ht_get(&htab, (void *)key);
|
||||
TEST_ASSERT_TRUE( e == NULL);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void test_ht_int(void) {
|
||||
printf("\n>> htab test int\n\n");
|
||||
|
||||
ht_init(&htab, 13, int_hash_key);
|
||||
|
||||
RUN_TEST(test_ht_add_string);
|
||||
RUN_TEST(test_ht_get_string);
|
||||
RUN_TEST(test_ht_del_string);
|
||||
}
|
||||
105
src/lib/testsuite/test_utils.c
Normal file
105
src/lib/testsuite/test_utils.c
Normal file
|
|
@ -0,0 +1,105 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "unity.h"
|
||||
#include "utils.h"
|
||||
#include "xce/types.h"
|
||||
|
||||
static void test_timewindow_config_dup()
|
||||
{
|
||||
/* clang-format off */
|
||||
xce_timewindow_config_t win1 = {
|
||||
.nsegs = 2,
|
||||
.segs = (xce_timewindow_seg_config_t*[]) {
|
||||
&(xce_timewindow_seg_config_t) {
|
||||
.tz = "GMT-8",
|
||||
.open = &(xce_timewindow_time_t) {
|
||||
.day = 0,
|
||||
.hour = 9,
|
||||
.min = 0 },
|
||||
.close = &(xce_timewindow_time_t) {
|
||||
.day = 0,
|
||||
.hour = 17,
|
||||
.min = 59 } },
|
||||
&(xce_timewindow_seg_config_t) {
|
||||
.tz = "GMT-8",
|
||||
.open = &(xce_timewindow_time_t) {
|
||||
.day = 5,
|
||||
.hour = 21,
|
||||
.min = 0 },
|
||||
.close = &(xce_timewindow_time_t) {
|
||||
.day = 7,
|
||||
.hour = 20,
|
||||
.min = 59 } } }
|
||||
};
|
||||
/* clang-format on */
|
||||
xce_timewindow_config_t* win2 = NULL;
|
||||
|
||||
win2 = dup_timewindow_config(&win1);
|
||||
|
||||
TEST_ASSERT_TRUE(win2 != NULL);
|
||||
TEST_ASSERT_TRUE(win2->nsegs == 2);
|
||||
TEST_ASSERT_TRUE((strcmp(win2->segs[0]->tz, "GMT-8") == 0));
|
||||
TEST_ASSERT_TRUE(win2->segs[0]->open->day == 0);
|
||||
TEST_ASSERT_TRUE(win2->segs[0]->open->hour == 9);
|
||||
TEST_ASSERT_TRUE(win2->segs[0]->open->min == 0);
|
||||
TEST_ASSERT_TRUE(win2->segs[0]->close->day == 0);
|
||||
TEST_ASSERT_TRUE(win2->segs[0]->close->hour == 17);
|
||||
TEST_ASSERT_TRUE(win2->segs[0]->close->min == 59);
|
||||
|
||||
TEST_ASSERT_TRUE((strcmp(win2->segs[1]->tz, "GMT-8") == 0));
|
||||
TEST_ASSERT_TRUE(win2->segs[1]->open->day == 5);
|
||||
TEST_ASSERT_TRUE(win2->segs[1]->open->hour == 21);
|
||||
TEST_ASSERT_TRUE(win2->segs[1]->open->min == 0);
|
||||
TEST_ASSERT_TRUE(win2->segs[1]->close->day == 7);
|
||||
TEST_ASSERT_TRUE(win2->segs[1]->close->hour == 20);
|
||||
TEST_ASSERT_TRUE(win2->segs[1]->close->min == 59);
|
||||
|
||||
free_timewindow_config(win2);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
void test_dup_threshold()
|
||||
{
|
||||
/* clang-format off */
|
||||
xce_res_threshold_t* threshold[2] = {
|
||||
&(xce_res_threshold_t) {
|
||||
.name = "r15s",
|
||||
.sched = 1.0,
|
||||
.stop = 5.0 },
|
||||
&(xce_res_threshold_t) {
|
||||
.name = "r1m",
|
||||
.sched = 0.9,
|
||||
.stop = 4.5 }
|
||||
};
|
||||
/* clang-format on */
|
||||
xce_res_threshold_t** threshold2 = NULL;
|
||||
|
||||
threshold2 = dup_resource_thresholds(threshold, 2);
|
||||
|
||||
TEST_ASSERT_TRUE(threshold2 != NULL);
|
||||
|
||||
TEST_ASSERT_TRUE(strcmp(threshold[0]->name, threshold2[0]->name) == 0);
|
||||
TEST_ASSERT_TRUE(strcmp(threshold[1]->name, threshold2[1]->name) == 0);
|
||||
TEST_ASSERT_TRUE(float_equal(threshold[0]->sched,
|
||||
threshold2[0]->sched));
|
||||
TEST_ASSERT_TRUE(float_equal(threshold[0]->stop,
|
||||
threshold2[0]->stop));
|
||||
TEST_ASSERT_TRUE(float_equal(threshold[1]->sched,
|
||||
threshold2[1]->sched));
|
||||
TEST_ASSERT_TRUE(float_equal(threshold[1]->stop,
|
||||
threshold2[1]->stop));
|
||||
|
||||
free_resource_thresholds(threshold2, 2);
|
||||
return;
|
||||
}
|
||||
|
||||
void test_utils(void)
|
||||
{
|
||||
printf("\n>> utils test\n\n");
|
||||
|
||||
RUN_TEST(test_timewindow_config_dup);
|
||||
RUN_TEST(test_dup_threshold);
|
||||
}
|
||||
128
src/lib/testsuite/test_xstring.c
Normal file
128
src/lib/testsuite/test_xstring.c
Normal file
|
|
@ -0,0 +1,128 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "objmgr.h"
|
||||
#include "unity.h"
|
||||
#include "xstring.h"
|
||||
|
||||
void test_xstring_create(void)
|
||||
{
|
||||
objmgr_t mgr;
|
||||
char* s1 = "Hello,world";
|
||||
char* s2 = NULL;
|
||||
int rc = 0;
|
||||
myobj_t* obj;
|
||||
|
||||
objmgr_init(&mgr);
|
||||
register_xstring(&mgr,4,4);
|
||||
TEST_ASSERT_EQUAL(1, mgr.types.count);
|
||||
|
||||
s2 = create_obj_by_typename(&mgr, "xstring", s1);
|
||||
TEST_ASSERT_NOT_NULL(s2);
|
||||
obj = TO_MYOBJ(s2);
|
||||
TEST_ASSERT_EQUAL(1, XSTRING_OBJ_TYPE_STRINGS(obj).count);
|
||||
|
||||
rc = strcmp(s1, s2);
|
||||
TEST_ASSERT_EQUAL(0, rc);
|
||||
|
||||
objmgr_fini(&mgr);
|
||||
}
|
||||
|
||||
void test_xstring_ref(void)
|
||||
{
|
||||
objmgr_t mgr;
|
||||
char* s1 = NULL;
|
||||
char* s2 = NULL;
|
||||
myobj_t* obj;
|
||||
|
||||
objmgr_init(&mgr);
|
||||
register_xstring(&mgr,4,4);
|
||||
TEST_ASSERT_EQUAL(1, mgr.types.count);
|
||||
|
||||
s1 = create_obj_by_typename(&mgr, "xstring",
|
||||
"Hello,world");
|
||||
TEST_ASSERT_NOT_NULL(s1);
|
||||
|
||||
obj = TO_MYOBJ(s1);
|
||||
TEST_ASSERT_EQUAL(1, XSTRING_OBJ_TYPE_STRINGS(obj).count);
|
||||
|
||||
s2 = (char*)obj_ref(s1, OBJREF_READ);
|
||||
TEST_ASSERT_EQUAL(s1, s2);
|
||||
|
||||
TEST_ASSERT_EQUAL(2, obj->nref);
|
||||
objmgr_fini(&mgr);
|
||||
}
|
||||
|
||||
void test_xstring_deref(void)
|
||||
{
|
||||
objmgr_t mgr;
|
||||
char* s1 = "Hello,world";
|
||||
char* s2 = NULL;
|
||||
int rc = 0;
|
||||
myobj_t* obj;
|
||||
|
||||
objmgr_init(&mgr);
|
||||
register_xstring(&mgr,4,4);
|
||||
TEST_ASSERT_EQUAL(1, mgr.types.count);
|
||||
|
||||
s2 = create_obj_by_typename(&mgr, "xstring", s1);
|
||||
TEST_ASSERT_NOT_NULL(s2);
|
||||
|
||||
rc = strcmp(s1, s2);
|
||||
|
||||
TEST_ASSERT_EQUAL(0, rc);
|
||||
if (rc == 0) {
|
||||
objtype_t *typeval;
|
||||
|
||||
obj = TO_MYOBJ(s2);
|
||||
typeval = obj->type;
|
||||
|
||||
obj_deref(s2);
|
||||
|
||||
TEST_ASSERT_EQUAL(0, XSTRING_TYPE_STRINGS(typeval).count);
|
||||
}
|
||||
|
||||
objmgr_fini(&mgr);
|
||||
}
|
||||
|
||||
void test_xstring_share(void)
|
||||
{
|
||||
objmgr_t mgr;
|
||||
char* s1 = "Hello,world";
|
||||
char* s2 = NULL;
|
||||
char* s3 = NULL;
|
||||
int rc = 0;
|
||||
|
||||
objmgr_init(&mgr);
|
||||
register_xstring(&mgr,4,4);
|
||||
TEST_ASSERT_EQUAL(1, mgr.types.count);
|
||||
|
||||
s2 = create_obj_by_typename(&mgr, "xstring", s1);
|
||||
TEST_ASSERT_NOT_NULL(s2);
|
||||
|
||||
rc = strcmp(s1, s2);
|
||||
|
||||
TEST_ASSERT_EQUAL(0, rc);
|
||||
s3 = create_obj_by_typename(&mgr, "xstring", s1);
|
||||
TEST_ASSERT_EQUAL(s2, s3);
|
||||
if (1) {
|
||||
myobj_t* obj;
|
||||
|
||||
obj = TO_MYOBJ(s3);
|
||||
TEST_ASSERT_EQUAL(2, obj->nref);
|
||||
}
|
||||
|
||||
objmgr_fini(&mgr);
|
||||
}
|
||||
|
||||
void test_xstrings(void)
|
||||
{
|
||||
printf("\n>> xstring test\n\n");
|
||||
RUN_TEST(test_xstring_create);
|
||||
RUN_TEST(test_xstring_ref);
|
||||
RUN_TEST(test_xstring_deref);
|
||||
RUN_TEST(test_xstring_share);
|
||||
|
||||
return;
|
||||
}
|
||||
102
src/lib/testsuite/test_zarray.c
Normal file
102
src/lib/testsuite/test_zarray.c
Normal file
|
|
@ -0,0 +1,102 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "unity.h"
|
||||
#include "zarray.h"
|
||||
|
||||
static void test_zarray_create(void) {
|
||||
zarray_t array;
|
||||
|
||||
zarray_init(&array, 8, NULL);
|
||||
|
||||
TEST_ASSERT_EQUAL(0,array.count);
|
||||
TEST_ASSERT_NULL(array.data);
|
||||
}
|
||||
|
||||
static void test_zarray_store(void) {
|
||||
zarray_t array;
|
||||
int idx;
|
||||
char *s1 = "hello";
|
||||
char *s2 = NULL;
|
||||
|
||||
zarray_init(&array, 8, NULL);
|
||||
idx = zarray_store(&array, (void *)s1);
|
||||
TEST_ASSERT_TRUE(idx >= 0);
|
||||
s2 = (char *)zarray_get(&array, idx);
|
||||
TEST_ASSERT_NOT_NULL(s2);
|
||||
TEST_ASSERT_EQUAL(0, strcmp(s1, s2));
|
||||
|
||||
zarray_fini(&(array));
|
||||
}
|
||||
|
||||
static void test_zarray_del(void) {
|
||||
zarray_t array;
|
||||
int idx;
|
||||
char *s1 = "hello";
|
||||
|
||||
zarray_init(&array, 8, NULL);
|
||||
idx = zarray_store(&array, (void *)s1);
|
||||
TEST_ASSERT_TRUE(idx >= 0);
|
||||
TEST_ASSERT_TRUE(array.count == 1);
|
||||
zarray_del(&array, idx);
|
||||
TEST_ASSERT_TRUE(zarray_get(&array, idx) == NULL);
|
||||
TEST_ASSERT_TRUE(array.count == 0);
|
||||
|
||||
zarray_fini(&array);
|
||||
}
|
||||
|
||||
static void test_zarray_put(void) {
|
||||
zarray_t array;
|
||||
int idx;
|
||||
char *s1 = "hello";
|
||||
char *s2 = "test";
|
||||
|
||||
zarray_init(&array, 8, NULL);
|
||||
idx = zarray_store(&array, (void *)s1);
|
||||
TEST_ASSERT_TRUE(idx >= 0);
|
||||
TEST_ASSERT_TRUE(array.count == 1);
|
||||
TEST_ASSERT_TRUE(zarray_get(&array, idx) != NULL);
|
||||
|
||||
TEST_ASSERT_TRUE(strcmp((char *)zarray_get(&array, idx), s1) == 0);
|
||||
|
||||
zarray_put(&array, idx, (void *)s2);
|
||||
TEST_ASSERT_TRUE(zarray_get(&array, idx) != NULL);
|
||||
TEST_ASSERT_TRUE(strcmp((char *)zarray_get(&array, idx), s2) == 0);
|
||||
|
||||
zarray_fini(&array);
|
||||
}
|
||||
|
||||
static int sum_(void *arg1, void *arg2) {
|
||||
int *pv = (int *)arg1;
|
||||
int x = (int)((long)arg2);
|
||||
|
||||
(*pv) += x;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void test_zarray_iter(void) {
|
||||
zarray_t array;
|
||||
int i;
|
||||
int val = 0;
|
||||
|
||||
zarray_init(&array, 10, NULL);
|
||||
for(i = 0; i < 10; i ++) {
|
||||
zarray_store(&array, (void *)(long)i);
|
||||
}
|
||||
|
||||
zarray_iter(&array, (zarray_iter_fn_t)sum_, &val);
|
||||
|
||||
TEST_ASSERT_TRUE(val == 45);
|
||||
|
||||
zarray_fini(&(array));
|
||||
}
|
||||
void test_zarray(void) {
|
||||
printf("\n>> zarray test\n\n");
|
||||
|
||||
RUN_TEST(test_zarray_create);
|
||||
RUN_TEST(test_zarray_store);
|
||||
RUN_TEST(test_zarray_del);
|
||||
RUN_TEST(test_zarray_put);
|
||||
RUN_TEST(test_zarray_iter);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue