/* 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 #include #include #include #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 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 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(); }