myxce/src/controller/testsuite/test_join_worker_args.c
Rongsong Shen 878a42fb48
fix(xce-test-cli-ux): fix bug-1557's join maxmem default
cmd_join_worker's simulated-worker maxmem default was 64 bytes -- a
leftover from when the field was MB-scale, unfixed when maxmem became
bytes-canonical elsewhere. Now 64 * 1024 * 1024. Extracted the
argument-parsing/defaulting logic into join_worker_parse_attrs()
(join_worker_args.c), since it runs entirely before the function's
network call and is a genuine testable seam -- same precedent as
task 2.5's joblist_display.c. Verified live against a real deployed
cluster (workerlist reports MaxMem: 64.00 MB) plus a permanent 5-test
regression suite. maxswap/maxtmp have the identical stale-default bug
(logged as bug-1793) but are deliberately left unfixed here since
USAGE_JOIN_WORKER's help text currently documents their stale values
accurately -- fixing only the code would create a new docs mismatch;
a locked-in sibling-defaults test documents this for the follow-up.
1353/1353 across the full controller suite (+5), 0 regressions.

Task 2.6 of .kiro/specs/xce-test-cli-ux/tasks.md.
Requirements: 12.1

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019jaMf9QEwpugH2W9KAuc7f
2026-09-09 16:24:36 +00:00

129 lines
5 KiB
C

/* test_join_worker_args.c -- xce-test-cli-ux task 2.6 remediation
* (bug-1557 fix)
*
* Unity unit tests for join_worker_args.c's join_worker_parse_attrs(),
* extracted from test.c's cmd_join_worker() (see join_worker_args.h for the
* full extraction rationale). This is the permanent, automated regression
* guard for bug-1557 (join's stale maxmem default): review had confirmed
* the fix value/unit were already correct in cmd_join_worker, but rejected
* that task for lacking a permanent test given a genuine testable seam
* existed -- this file is that test.
*
* Standalone Unity main (this binary is its own test executable -- see
* meson.build's join_worker_args_unit_test), mirroring
* joblist_display_unit_test's/resval_typeresolve_unit_test's own pattern.
*/
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <unity/unity.h>
#include "join_worker_args.h"
#include "xce/types.h" /* hostattrs_t */
/* Requirement 12.1's actual regression guard: no -m flag given must default
* maxmem to 64 * 1024 * 1024 (64 MB expressed in the codebase's
* bytes-canonical unit) -- not the pre-bug-1557 nonsensical 64 bytes. */
static void test_join_worker_default_maxmem_is_64mb_in_bytes(void)
{
char* argv[] = { "join" };
hostattrs_t attrs;
int rc = join_worker_parse_attrs(1, argv, &attrs);
TEST_ASSERT_EQUAL_INT(0, rc);
/* This Unity build has double-precision assertions disabled -- use
* TEST_ASSERT_EQUAL_FLOAT (this file's own convention, matching
* test_listfmt_json.c/test_wal_job_rusage_fact.c) instead. 64 * 1024 *
* 1024 is an exact power of two, so the float round-trip is exact. */
TEST_ASSERT_EQUAL_FLOAT_MESSAGE(
(float)(64 * 1024 * 1024), (float)attrs.maxmem,
"join's default maxmem must be 64 * 1024 * 1024 bytes (bug-1557, "
"Requirement 12.1)");
}
/* Proves the flag-parsing itself still works after extraction, not just the
* default: -m <value> must override the default exactly. */
static void test_join_worker_dash_m_overrides_default(void)
{
char* argv[] = { "join", "-m", "12345" };
hostattrs_t attrs;
int rc = join_worker_parse_attrs(3, argv, &attrs);
TEST_ASSERT_EQUAL_INT(0, rc);
TEST_ASSERT_EQUAL_FLOAT_MESSAGE(
12345.0f, (float)attrs.maxmem,
"-m <value> must override join's default maxmem");
}
/* Fail-loud behavior (matching this file's error-handling convention
* elsewhere): an unrecognized flag must return the negative-errno error
* code, not silently succeed with a partially-parsed attrs. */
static void test_join_worker_unrecognized_flag_returns_einval(void)
{
char* argv[] = { "join", "-z", "bogus" };
hostattrs_t attrs;
int rc = join_worker_parse_attrs(3, argv, &attrs);
TEST_ASSERT_EQUAL_INT(-EINVAL, rc);
}
/* A NULL attrs pointer must also fail loud rather than crash. */
static void test_join_worker_null_attrs_returns_einval(void)
{
char* argv[] = { "join" };
int rc = join_worker_parse_attrs(1, argv, NULL);
TEST_ASSERT_EQUAL_INT(-EINVAL, rc);
}
/* Documents/locks in the CURRENT (still-buggy, unchanged-by-this-task)
* default values of maxcpus/maxswap/maxtmp -- the sibling same-class fields
* task 2.6's implementer correctly declined to touch (a separate,
* recommended follow-up bug covers them). If someone later fixes those
* fields, THIS test's assertions (specific to maxmem) must not be confused
* with assertions on those separate fields. */
static void test_join_worker_sibling_defaults_unchanged(void)
{
char* argv[] = { "join" };
hostattrs_t attrs;
int rc = join_worker_parse_attrs(1, argv, &attrs);
TEST_ASSERT_EQUAL_INT(0, rc);
TEST_ASSERT_EQUAL_INT_MESSAGE(
4, attrs.maxcpus,
"maxcpus default is unchanged by task 2.6 (bug-1557 scoped to "
"maxmem only)");
TEST_ASSERT_EQUAL_FLOAT_MESSAGE(
1024.0f, (float)attrs.maxswap,
"maxswap's still-buggy default is intentionally unchanged by task "
"2.6 -- separate follow-up bug covers it");
TEST_ASSERT_EQUAL_FLOAT_MESSAGE(
2048.0f, (float)attrs.maxtmp,
"maxtmp's still-buggy default is intentionally unchanged by task "
"2.6 -- separate follow-up bug covers it");
}
/* ------------------------------------------------------------------ */
/* Standalone Unity main (this binary is its own test executable -- see */
/* meson.build's join_worker_args_unit_test) */
/* ------------------------------------------------------------------ */
void setUp(void) { return; }
void tearDown(void) { return; }
int main(void)
{
printf("\n>> xce-test-cli-ux task 2.6 remediation: join_worker_args "
"join_worker_parse_attrs (bug-1557)\n\n");
UNITY_BEGIN();
RUN_TEST(test_join_worker_default_maxmem_is_64mb_in_bytes);
RUN_TEST(test_join_worker_dash_m_overrides_default);
RUN_TEST(test_join_worker_unrecognized_flag_returns_einval);
RUN_TEST(test_join_worker_null_attrs_returns_einval);
RUN_TEST(test_join_worker_sibling_defaults_unchanged);
return UNITY_END();
}