Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

redfishpower: fix memleaks and test under valgrind #169

Merged
merged 4 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/redfishpower/redfishpower.c
Original file line number Diff line number Diff line change
Expand Up @@ -369,12 +369,12 @@ static struct powermsg *powermsg_create(CURLM *mh,
static void powermsg_destroy(struct powermsg *pm)
{
if (pm) {
if (pm->cmd)
xfree(pm->cmd);
if (pm->url)
xfree(pm->url);
if (pm->postdata)
xfree(pm->postdata);
xfree(pm->cmd);
xfree(pm->hostname);
xfree(pm->plugname);
xfree(pm->parent);
xfree(pm->url);
xfree(pm->postdata);
free(pm->output);
if (!test_mode && pm->eh) {
CURLMcode mc;
Expand Down Expand Up @@ -1659,7 +1659,7 @@ static void init_redfishpower(char *argv[])

if (!(waitcmds = zlistx_new()))
err_exit(true, "zlistx_new");
zlistx_set_destructor(delayedcmds, cleanup_powermsg);
zlistx_set_destructor(waitcmds, cleanup_powermsg);

if (!(test_fail_power_cmd_hosts = hostlist_create(NULL)))
err_exit(true, "hostlist_create error");
Expand Down
50 changes: 50 additions & 0 deletions t/t0034-redfishpower.t
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,56 @@ test_expect_success 'stop powerman daemon (parents3Lbad)' '
wait
'

#
# valgrind
#

if valgrind --version; then
test_set_prereq HAVE_VALGRIND
fi

# test input largely follows Cray EX chassis
test_expect_success HAVE_VALGRIND 'create redfishpower test input' '
cat >redfishpower.in <<-EOT
auth USER:PASS
setheader Content-Type:application/json
setplugs Enclosure 0
setplugs Perif[0-7],Blade[0-7] 0 Enclosure
setplugs Node[0-1] [1-2] Blade0
setplugs Node[2-3] [3-4] Blade1
setplugs Node[4-5] [5-6] Blade2
setplugs Node[6-7] [7-8] Blade3
setplugs Node[8-9] [9-10] Blade4
setplugs Node[10-11] [11-12] Blade5
setplugs Node[12-13] [13-14] Blade6
setplugs Node[14-15] [15-16] Blade7
setpath Enclosure,Perif[0-7],Blade[0-7] stat redfish/v1/Chassis/{{plug}}
setpath Enclosure,Perif[0-7],Blade[0-7] on redfish/v1/Chassis/{{plug}}/Actions/Chassis.Reset {\"ResetType\":\"On\"}
setpath Enclosure,Perif[0-7],Blade[0-7] off redfish/v1/Chassis/{{plug}}/Actions/Chassis.Reset {\"ResetType\":\"ForceOff\"}
setpath Node[0-15] stat redfish/v1/Systems/Node0
setpath Node[0-15] on redfish/v1/Systems/Node0/Actions/ComputerSystem.Reset {\"ResetType\":\"On\"}
setpath Node[0-15] off redfish/v1/Systems/Node0/Actions/ComputerSystem.Reset {\"ResetType\":\"ForceOff\"}
settimeout 60
stat
stat Enclosure,Perif[0-7],Blade[0-7],Node[0-15]
on Enclosure,Perif[0-7],Blade[0-7],Node[0-15]
on Enclosure
on Perif[0-7],Blade[0-7]
on Node[0-15]
stat
stat Enclosure,Perif[0-7],Blade[0-7],Node[0-15]
off Node[0-15]
off Perif[0-7],Blade[0-7]
off Enclosure
EOT
'

test_expect_success HAVE_VALGRIND 'run redfishpower under valgrind' '
cat redfishpower.in | valgrind --tool=memcheck --leak-check=full \
--error-exitcode=1 --gen-suppressions=all \
$redfishdir/redfishpower -h cmm0,t[0-15] --test-mode
'

test_done

# vi: set ft=sh
Loading