forked from lei.chen/myxce
Add the full call chain for host control operations from the Go API server through the C library to the controller: - schema/controller.capnp: HostControl struct + hostctrlmsg @21 in Request.body union - include/typemap.h: xce_hostctrl_t* hostctrlmsg in body union (placed after @20 clrpreasonmsg, matching capnp ordinal) - include/client.h, xceapi.h, request.h: declarations for xcecli_hostctrl, xce_hostctrl, xce_hostctrl_req - lib/client.c: xcecli_hostctrl (validate + delegate to xce_hostctrl) - lib/xceapi.c: xce_hostctrl (validate ctx state + send + wait reply) - lib/request.c: xce_hostctrl_req (validate hostname/empty/nil, accept only HOST_OPEN/HOST_CLOSE, reject HOST_TAG/UNTAG) - lib/helper.c: Request_body_hostctrlmsg cases in xce_request_body() and xce_request_msg_name() - controller/cluster.c: OPCode_hostcontrol dispatch - controller/include/cluster.h: do_hostcontrol_op declaration - controller/worker.c: do_hostcontrol_op + fix pre-existing goto-clean bug in worker_ctrl that leaked write lock and reference on HOST_OPEN/HOST_CLOSE no-op paths TDD: 8 xce_hostctrl_req validation tests (null ep, null ctrl, null/empty hostname, HOST_DO_NONE no-op, HOST_TAG/UNTAG reject, negative action reject, HOST_OPEN/CLOSE accept via xce_request). 116/116 xcelib tests pass. CGO_ENABLED=0 Go backend tests pass. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
79 lines
2.4 KiB
C
79 lines
2.4 KiB
C
#include <errno.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <unity/unity.h>
|
|
#include "request.h"
|
|
#include "xce/types.h"
|
|
|
|
/* Tests for xce_hostctrl_req() validation paths.
|
|
* We test only early-return paths (before xce_request() is called)
|
|
* since a live endpoint is not available in unit tests. */
|
|
|
|
static void test_hostctrl_req_null_ep(void)
|
|
{
|
|
xce_hostctrl_t ctrl = { .action = HOST_OPEN, .hostname = "host1" };
|
|
int rc = xce_hostctrl_req(NULL, &ctrl);
|
|
TEST_ASSERT_EQUAL_INT(-EINVAL, rc);
|
|
}
|
|
|
|
static void test_hostctrl_req_null_ctrl(void)
|
|
{
|
|
/* non-NULL dummy ep is enough; the NULL ctrl check fires first */
|
|
int rc = xce_hostctrl_req((endpoint_t*)0x1, NULL);
|
|
TEST_ASSERT_EQUAL_INT(-EINVAL, rc);
|
|
}
|
|
|
|
static void test_hostctrl_req_null_hostname(void)
|
|
{
|
|
xce_hostctrl_t ctrl = { .action = HOST_OPEN, .hostname = NULL };
|
|
int rc = xce_hostctrl_req((endpoint_t*)0x1, &ctrl);
|
|
TEST_ASSERT_EQUAL_INT(-EINVAL, rc);
|
|
}
|
|
|
|
static void test_hostctrl_req_empty_hostname(void)
|
|
{
|
|
xce_hostctrl_t ctrl = { .action = HOST_OPEN, .hostname = "" };
|
|
int rc = xce_hostctrl_req((endpoint_t*)0x1, &ctrl);
|
|
TEST_ASSERT_EQUAL_INT(-EINVAL, rc);
|
|
}
|
|
|
|
static void test_hostctrl_req_noop(void)
|
|
{
|
|
xce_hostctrl_t ctrl = { .action = HOST_DO_NONE, .hostname = "host1" };
|
|
int rc = xce_hostctrl_req((endpoint_t*)0x1, &ctrl);
|
|
TEST_ASSERT_EQUAL_INT(0, rc);
|
|
}
|
|
|
|
static void test_hostctrl_req_reject_tag(void)
|
|
{
|
|
xce_hostctrl_t ctrl = { .action = HOST_TAG, .hostname = "host1" };
|
|
int rc = xce_hostctrl_req((endpoint_t*)0x1, &ctrl);
|
|
TEST_ASSERT_EQUAL_INT(-EINVAL, rc);
|
|
}
|
|
|
|
static void test_hostctrl_req_reject_untag(void)
|
|
{
|
|
xce_hostctrl_t ctrl = { .action = HOST_UNTAG, .hostname = "host1" };
|
|
int rc = xce_hostctrl_req((endpoint_t*)0x1, &ctrl);
|
|
TEST_ASSERT_EQUAL_INT(-EINVAL, rc);
|
|
}
|
|
|
|
static void test_hostctrl_req_reject_negative_action(void)
|
|
{
|
|
xce_hostctrl_t ctrl = { .action = -1, .hostname = "host1" };
|
|
int rc = xce_hostctrl_req((endpoint_t*)0x1, &ctrl);
|
|
TEST_ASSERT_EQUAL_INT(-EINVAL, rc);
|
|
}
|
|
|
|
void test_request(void)
|
|
{
|
|
printf("\n>> host control request validation tests\n\n");
|
|
RUN_TEST(test_hostctrl_req_null_ep);
|
|
RUN_TEST(test_hostctrl_req_null_ctrl);
|
|
RUN_TEST(test_hostctrl_req_null_hostname);
|
|
RUN_TEST(test_hostctrl_req_empty_hostname);
|
|
RUN_TEST(test_hostctrl_req_noop);
|
|
RUN_TEST(test_hostctrl_req_reject_tag);
|
|
RUN_TEST(test_hostctrl_req_reject_untag);
|
|
RUN_TEST(test_hostctrl_req_reject_negative_action);
|
|
}
|