From b41ce4df69c42a1e84882e845bf73c82edad6b9d Mon Sep 17 00:00:00 2001 From: Brian Christiansen <brian@schedmd.com> Date: Tue, 9 Jan 2018 12:23:29 -0700 Subject: [PATCH] Update unit test to check for assert slurmdb_pack_assoc_usage() will assert with a NULL usage ptr. --- .../pack_assoc_rec_with_usage-test.c | 42 +++++++++++++++++-- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/testsuite/slurm_unit/common/slurmdb_pack/pack_assoc_rec_with_usage-test.c b/testsuite/slurm_unit/common/slurmdb_pack/pack_assoc_rec_with_usage-test.c index 391f937141a..829a3ab35c5 100644 --- a/testsuite/slurm_unit/common/slurmdb_pack/pack_assoc_rec_with_usage-test.c +++ b/testsuite/slurm_unit/common/slurmdb_pack/pack_assoc_rec_with_usage-test.c @@ -9,6 +9,34 @@ #include "src/common/list.h" #include "src/common/pack.h" +#ifndef NDEBUG +START_TEST(pack_null_usage) +{ + int rc; + uint32_t x; + + slurmdb_assoc_rec_t *assoc_rec = xmalloc(sizeof(slurmdb_assoc_rec_t)); + assoc_rec->usage = NULL; + + Buf buf = init_buf(1024); + + pack32(22, buf); + set_buf_offset(buf, 0); + + slurmdb_assoc_rec_t *acr; + + /* Should assert */ + slurmdb_pack_assoc_rec_with_usage((void *)assoc_rec, 0, buf); + unpack32(&x, buf); + rc = slurmdb_unpack_assoc_rec_with_usage((void **)&acr, 0, buf); + ck_assert_int_eq(rc, SLURM_ERROR); + ck_assert(x == 22); + free_buf(buf); + slurmdb_destroy_assoc_rec(assoc_rec); +} +END_TEST +#endif + START_TEST(invalid_protocol) { int rc; @@ -193,11 +221,17 @@ END_TEST * TEST SUITE * ****************************************************************************/ -Suite* suite(void) +Suite* suite(SRunner *sr) { Suite* s = suite_create("Pack slurmdb_assoc_rec_t"); TCase* tc_core = tcase_create("Pack slurmdb_assoc_rec_t"); tcase_add_test(tc_core, invalid_protocol); + +#ifndef NDEBUG + if (srunner_fork_status(sr) != CK_NOFORK) + tcase_add_test_raise_signal(tc_core, pack_null_usage, SIGABRT); +#endif + tcase_add_test(tc_core, pack_1702_assoc_rec); suite_add_tcase(s, tc_core); return s; @@ -210,9 +244,9 @@ Suite* suite(void) int main(void) { int number_failed; - SRunner* sr = srunner_create(suite()); - - srunner_set_fork_status(sr, CK_NOFORK); + SRunner* sr = srunner_create(NULL); + //srunner_set_fork_status(sr, CK_NOFORK); + srunner_add_suite(sr, suite(sr)); srunner_run_all(sr, CK_VERBOSE); //srunner_run_all(sr, CK_NORMAL); -- GitLab