use nix build & meson & zlog

This commit is contained in:
Rongsong Shen 2025-11-03 18:19:59 +08:00
parent 0123623742
commit 346768a144
60 changed files with 13739 additions and 0 deletions

View 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);
}