Skip to content

Commit

Permalink
Merge pull request #120 from garlick/valgrind
Browse files Browse the repository at this point in the history
testsuite: add valgrind coverage
  • Loading branch information
mergify[bot] authored Feb 5, 2024
2 parents b001ff3 + 1c6c38c commit 7ae1f5d
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 28 deletions.
24 changes: 5 additions & 19 deletions src/powerman/parse_tab.y
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ static Spec *makeSpec(char *name);
static Spec *findSpec(char *name);
static int matchSpec(Spec * spec, void *key);
static void destroySpec(Spec * spec);
static void _clear_current_spec(void);
static void makeScript(int com, List stmts);
static void destroyInterp(Interp *i);
static Interp *makeInterp(InterpState state, char *str);
Expand Down Expand Up @@ -365,7 +364,6 @@ int parse_config_file (char *filename)
err_exit(true, "%s", filename);

device_specs = list_create((ListDelF) destroySpec);
_clear_current_spec();

yyparse();
fclose(yyin);
Expand Down Expand Up @@ -416,27 +414,12 @@ static void destroyPreStmt(PreStmt *p)
xfree(p);
}

static void _clear_current_spec(void)
{
int i;

current_spec.name = NULL;
current_spec.plugs = NULL;
timerclear(&current_spec.timeout);
timerclear(&current_spec.ping_period);
for (i = 0; i < NUM_SCRIPTS; i++)
current_spec.prescripts[i] = NULL;
}

static Spec *_copy_current_spec(void)
{
Spec *new = (Spec *) xmalloc(sizeof(Spec));
int i;

*new = current_spec;
for (i = 0; i < NUM_SCRIPTS; i++)
new->prescripts[i] = current_spec.prescripts[i];
_clear_current_spec();
memset (&current_spec, 0, sizeof (current_spec));
return new;
}

Expand Down Expand Up @@ -548,12 +531,15 @@ static void destroyStmt(Stmt *stmt)
break;
case STMT_SETPLUGSTATE:
list_destroy(stmt->u.setplugstate.interps);
xfree (stmt->u.setplugstate.plug_name);
break;
case STMT_FOREACHNODE:
case STMT_FOREACHPLUG:
list_destroy(stmt->u.foreach.stmts);
break;
case STMT_IFON:
case STMT_IFOFF:
list_destroy(stmt->u.foreach.stmts);
list_destroy(stmt->u.ifonoff.stmts);
break;
default:
break;
Expand Down
10 changes: 6 additions & 4 deletions src/powerman/parse_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,8 @@ void conf_init(char *filename)
err_exit(false, "%s is not a regular file\n", filename);

/*
* Call yacc parser against config file. The parser calls support
* functions below and builds 'dev_devices' (devices.c),
* 'conf_cluster', 'conf_specs' (config.c), and various other
* conf_* attributes (config.c).
* Call yacc parser against config file.
* The parser builds 'dev_devices' (devices.c) and 'conf_*' (here).
*/
parse_config_file(filename);

Expand All @@ -100,8 +98,12 @@ void conf_init(char *filename)
/* finalize module */
void conf_fini(void)
{
if (conf_aliases != NULL)
list_destroy(conf_aliases);
if (conf_nodes != NULL)
hostlist_destroy(conf_nodes);
if (conf_listen != NULL)
list_destroy(conf_listen);
}

/*
Expand Down
27 changes: 23 additions & 4 deletions src/powerman/powermand.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <time.h>
#include <getopt.h>
#include <unistd.h>
#include <fcntl.h>
#include <signal.h>
#include <string.h>
#include <stdlib.h>
Expand Down Expand Up @@ -46,6 +47,8 @@ static void _noop_handler(int signum);
static void _exit_handler(int signum);
static void _select_loop(void);

static int exitpipe[2];

#define OPTIONS "c:fhd:VsY"
static const struct option longopts[] = {
{"conf", required_argument, 0, 'c'},
Expand Down Expand Up @@ -106,6 +109,11 @@ int main(int argc, char **argv)
}
}

if (pipe (exitpipe) < 0
|| fcntl (exitpipe[0], F_SETFD, O_CLOEXEC) < 0
|| fcntl (exitpipe[1], F_SETFD, O_CLOEXEC) < 0)
err_exit (true, "could not create pipe for exit signaling");

if (!config_filename)
config_filename = hsprintf("%s/%s/%s", X_SYSCONFDIR,
"powerman", "powerman.conf");
Expand Down Expand Up @@ -139,6 +147,13 @@ int main(int argc, char **argv)
/* We now have a socket at listener fd running in listen mode */
/* and a file descriptor for communicating with each device */
_select_loop();

(void)close (exitpipe[0]);
(void)close (exitpipe[1]);

cli_fini();
dev_fini();
conf_fini();
return 0;
}

Expand Down Expand Up @@ -178,10 +193,14 @@ static void _select_loop(void)

cli_pre_poll(pfd);
dev_pre_poll(pfd);
xpollfd_set(pfd, exitpipe[0], XPOLLIN);

xpoll(pfd, timerisset(&tmout) ? &tmout : NULL);
timerclear(&tmout);

if (xpollfd_revents(pfd, exitpipe[0]))
break;

/*
* Process activity on client and device fd's.
* If a device requires a timeout, for example to reconnect or
Expand All @@ -201,12 +220,12 @@ static void _noop_handler(int signum)
/* do nothing */
}

/* Wake up the select loop so it can exit and allow destructors to be called.
*/
static void _exit_handler(int signum)
{
cli_fini();
dev_fini();
conf_fini();
exit(0);
if (write (exitpipe[1], "", 1) != 1)
err_exit(true, "signal %d: could not write to exit pipe", signum);
}

/*
Expand Down
3 changes: 2 additions & 1 deletion t/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ TESTSCRIPTS = \
t0029-redfish.t \
t0030-heartbeat-stonith.t \
t0031-llnl-mcr-cluster.t \
t0032-list.t
t0032-list.t \
t0033-valgrind.t

# make check runs these TAP tests directly (both scripts and programs)
TESTS = \
Expand Down
38 changes: 38 additions & 0 deletions t/t0033-valgrind.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/sh

test_description='Test Powerman list query'

. `dirname $0`/sharness.sh

powermand=$SHARNESS_BUILD_DIRECTORY/src/powerman/powermand
powerman=$SHARNESS_BUILD_DIRECTORY/src/powerman/powerman
vpcd=$SHARNESS_BUILD_DIRECTORY/t/simulators/vpcd
vpcdev=$SHARNESS_TEST_SRCDIR/etc/vpc.dev

# Use port = 11000 + test number
# That way there won't be port conflicts with make -j
testaddr=localhost:11033

if ! valgrind --version; then
skip_all='skipping valgrind tests'
test_done
fi

test_expect_success 'create test powerman.conf' '
cat >powerman.conf <<-EOT
include "$vpcdev"
listen "$testaddr"
device "test0" "vpc" "$vpcd |&"
node "t[0-15]" "test0"
alias "a0" "t0"
EOT
'
test_expect_failure 'run powermand --stdio under valgrind' '
valgrind --tool=memcheck --leak-check=full --error-exitcode=1 \
$powermand --stdio -c powerman.conf 2>valgrind.err <<-EOT
help
EOT
'
test_done

# vi: set ft=sh

0 comments on commit 7ae1f5d

Please sign in to comment.