forked from lei.chen/myxce
149 lines
4.4 KiB
C
149 lines
4.4 KiB
C
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <unity/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_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_extract_bits(void) {
|
|
uint64_t id = 0xfefefefeffff;
|
|
|
|
TEST_ASSERT_TRUE(EXTRACT_BITS(id, 0, 4) == 0xf);
|
|
TEST_ASSERT_TRUE(EXTRACT_BITS(id, 16, 4) == 0xe);
|
|
TEST_ASSERT_TRUE(EXTRACT_BITS(id, 16, 8) == 0xfe);
|
|
TEST_ASSERT_TRUE(EXTRACT_BITS(id, 20, 12) == 0xfef);
|
|
TEST_ASSERT_TRUE(EXTRACT_BITS(id, 44, 4) == 0xf);
|
|
TEST_ASSERT_TRUE(EXTRACT_BITS(id, 40, 8) == 0xfe);
|
|
}
|
|
|
|
static void do_parse_jobid_test(uint64_t jobid) {
|
|
uint64_t jobid2;
|
|
int rc;
|
|
char buf[256];
|
|
|
|
rc = fmt_jobid(buf, sizeof(buf), jobid);
|
|
printf("\t\tCheck jobid %s\n", buf);
|
|
|
|
TEST_ASSERT_TRUE(rc > 0);
|
|
rc = parse_jobid(&jobid2, buf);
|
|
TEST_ASSERT_TRUE(rc >= 0);
|
|
TEST_ASSERT_TRUE(jobid == jobid2);
|
|
}
|
|
|
|
void test_parse_jobid1(void) {
|
|
uint64_t jobid = 0x400691c2fd498003;
|
|
|
|
do_parse_jobid_test(jobid);
|
|
}
|
|
|
|
void test_parse_jobid2(void) {
|
|
uint64_t jobid = 0x691d3c1d00013;
|
|
|
|
do_parse_jobid_test(jobid);
|
|
}
|
|
|
|
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);
|
|
RUN_TEST(test_extract_bits);
|
|
RUN_TEST(test_parse_jobid1);
|
|
RUN_TEST(test_parse_jobid2);
|
|
}
|