mirror of
https://git.openafs.org/openafs.git
synced 2025-01-18 06:50:12 +00:00
tests: Introduce afstest_*_path()
Currently, several of our tests contain logic to locate files (via srcdir or objdir), based on the C_TAP_SOURCE/BUILD environment variables. This logic is duplicated in several places, so consolidate the code into a couple of new functions: afstest_src_path and afstest_obj_path. Update all callers to use these new functions. Change-Id: I67a5e5d7f8fd7a1edb55a45e52d877ac41f9a2ea Reviewed-on: https://gerrit.openafs.org/14319 Reviewed-by: Michael Meffie <mmeffie@sinenomine.net> Reviewed-by: Cheyenne Wills <cwills@sinenomine.net> Reviewed-by: Benjamin Kaduk <kaduk@mit.edu> Tested-by: BuildBot <buildbot@rampaginggeek.com>
This commit is contained in:
parent
d16a0f8d16
commit
40d6644264
@ -126,14 +126,7 @@ int main(int argc, char **argv)
|
||||
|
||||
keyfile = afstest_asprintf("%s/KeyFile", dirname);
|
||||
|
||||
/* Work out the path to our KeyFile. If the test harness hasn't set
|
||||
* the C_TAP_SOURCE environment variable, then assume it is in our CWD */
|
||||
if (getenv("C_TAP_SOURCE") == NULL) {
|
||||
keyfilesrc = strdup("KeyFile");
|
||||
} else {
|
||||
if (asprintf(&keyfilesrc, "%s/auth/KeyFile", getenv("C_TAP_SOURCE")) == -1)
|
||||
goto out;
|
||||
}
|
||||
keyfilesrc = afstest_src_path("tests/auth/KeyFile");
|
||||
|
||||
/* First, copy in a known keyfile */
|
||||
code = copy(keyfilesrc, keyfile);
|
||||
|
@ -5,7 +5,7 @@ abs_top_builddir=@abs_top_builddir@
|
||||
include @TOP_OBJDIR@/src/config/Makefile.config
|
||||
include @TOP_OBJDIR@/src/config/Makefile.pthread
|
||||
|
||||
MODULE_CFLAGS = -I$(TOP_OBJDIR)
|
||||
MODULE_CFLAGS = -I$(TOP_OBJDIR) -I$(srcdir)/../common/
|
||||
|
||||
LIBS = $(abs_top_builddir)/tests/common/libafstest_common.la \
|
||||
$(abs_top_builddir)/src/cmd/liboafs_cmd.la \
|
||||
|
@ -34,6 +34,7 @@
|
||||
#include <afs/cmd.h>
|
||||
|
||||
#include <tests/tap/basic.h>
|
||||
#include "common.h"
|
||||
|
||||
enum cmdOptions {
|
||||
copt_flag = 0,
|
||||
@ -361,19 +362,10 @@ main(int argc, char **argv)
|
||||
cmd_FreeArgv(tv);
|
||||
|
||||
/* Now, try adding a configuration file into the mix */
|
||||
if (getenv("C_TAP_SOURCE") == NULL)
|
||||
path = strdup("test1.conf");
|
||||
else {
|
||||
if (asprintf(&path, "%s/cmd/test1.conf", getenv("C_TAP_SOURCE")) < 0)
|
||||
path = NULL;
|
||||
}
|
||||
if (path != NULL) {
|
||||
cmd_SetCommandName("test");
|
||||
code = cmd_OpenConfigFile(path);
|
||||
is_int(0, code, "cmd_OpenConfigFile succeeds");
|
||||
} else {
|
||||
skip("no memory to build config file path");
|
||||
}
|
||||
path = afstest_src_path("tests/cmd/test1.conf");
|
||||
cmd_SetCommandName("test");
|
||||
code = cmd_OpenConfigFile(path);
|
||||
is_int(0, code, "cmd_OpenConfigFile succeeds");
|
||||
|
||||
code = cmd_ParseLine("-first 1", tv, &tc, 100);
|
||||
is_int(0, code, "cmd_ParseLine succeeds");
|
||||
|
@ -6,7 +6,7 @@ include @TOP_OBJDIR@/src/config/Makefile.libtool
|
||||
|
||||
MODULE_CFLAGS=-I$(TOP_OBJDIR)
|
||||
|
||||
LT_objs = config.lo misc.lo network.lo rxkad.lo servers.lo ubik.lo
|
||||
LT_objs = config.lo files.lo misc.lo network.lo rxkad.lo servers.lo ubik.lo
|
||||
LT_libs = $(LIB_rfc3961) $(LIB_roken)
|
||||
LT_deps = $(top_builddir)/tests/tap/libafstest_tap.la \
|
||||
$(top_builddir)/src/util/liboafs_util.la
|
||||
|
@ -30,6 +30,11 @@ extern char *afstest_mkdtemp(char *template);
|
||||
struct afsconf_dir;
|
||||
extern int afstest_AddDESKeyFile(struct afsconf_dir *dir);
|
||||
|
||||
/* files.c */
|
||||
|
||||
extern char *afstest_src_path(char *path);
|
||||
extern char *afstest_obj_path(char *path);
|
||||
|
||||
/* rxkad.c */
|
||||
|
||||
extern struct rx_securityClass
|
||||
|
76
tests/common/files.c
Normal file
76
tests/common/files.c
Normal file
@ -0,0 +1,76 @@
|
||||
/*
|
||||
* Copyright (c) 2020 Sine Nomine Associates. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR `AS IS'' AND ANY EXPRESS OR
|
||||
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/*!
|
||||
* Common file-related functions for test programs
|
||||
*/
|
||||
|
||||
#include <afsconfig.h>
|
||||
#include <afs/param.h>
|
||||
#include <roken.h>
|
||||
|
||||
#include <afs/opr.h>
|
||||
#include <afs/afsutil.h>
|
||||
|
||||
#include <tests/tap/basic.h>
|
||||
|
||||
#include "common.h"
|
||||
|
||||
static char *
|
||||
path_from_tdir(char *env_var, char *filename)
|
||||
{
|
||||
char *tdir;
|
||||
|
||||
/* C_TAP_SOURCE/C_TAP_BUILD in the env points to 'tests/' in the
|
||||
* srcdir/objdir. */
|
||||
|
||||
tdir = getenv(env_var);
|
||||
if (tdir == NULL) {
|
||||
/*
|
||||
* If C_TAP_SOURCE/C_TAP_BUILD isn't set, we assume we're running from
|
||||
* the same cwd as one of the test programs (e.g. 'tests/foo/'). So to
|
||||
* get to 'tests/', just go up one level.
|
||||
*/
|
||||
tdir = "..";
|
||||
}
|
||||
|
||||
/*
|
||||
* The given 'filename' is specified relative to the top srcdir/objdir.
|
||||
* Since 'tdir' points to 'tests/', go up one level before following
|
||||
* 'filename'.
|
||||
*/
|
||||
return afstest_asprintf("%s/../%s", tdir, filename);
|
||||
}
|
||||
|
||||
char *
|
||||
afstest_src_path(char *path)
|
||||
{
|
||||
return path_from_tdir("C_TAP_SOURCE", path);
|
||||
}
|
||||
|
||||
char *
|
||||
afstest_obj_path(char *path)
|
||||
{
|
||||
return path_from_tdir("C_TAP_BUILD", path);
|
||||
}
|
@ -31,15 +31,10 @@ afstest_StartVLServer(char *dirname, pid_t *serverPid)
|
||||
exit(1);
|
||||
/* Argggggghhhhh */
|
||||
} else if (pid == 0) {
|
||||
char *binPath, *logPath, *dbPath, *build;
|
||||
char *binPath, *logPath, *dbPath;
|
||||
|
||||
/* Child */
|
||||
build = getenv("C_TAP_BUILD");
|
||||
|
||||
if (build == NULL)
|
||||
build = "..";
|
||||
|
||||
binPath = afstest_asprintf("%s/../src/tvlserver/vlserver", build);
|
||||
binPath = afstest_obj_path("src/tvlserver/vlserver");
|
||||
logPath = afstest_asprintf("%s/VLLog", dirname);
|
||||
dbPath = afstest_asprintf("%s/vldb", dirname);
|
||||
|
||||
|
@ -63,21 +63,14 @@ TestListAddrs(struct ubik_client *client, char *dirname)
|
||||
}
|
||||
pid = fork();
|
||||
if (pid == 0) {
|
||||
char *build, *binPath;
|
||||
char *vos;
|
||||
|
||||
dup2(outpipe[1], STDOUT_FILENO); /* Redirect stdout into pipe */
|
||||
close(outpipe[0]);
|
||||
close(outpipe[1]);
|
||||
|
||||
build = getenv("C_TAP_BUILD");
|
||||
if (build == NULL)
|
||||
build = "..";
|
||||
|
||||
if (asprintf(&binPath, "%s/../src/volser/vos", build) < 0) {
|
||||
fprintf(stderr, "Out of memory building vos arguments\n");
|
||||
exit(1);
|
||||
}
|
||||
execl(binPath, "vos",
|
||||
vos = afstest_obj_path("src/volser/vos");
|
||||
execl(vos, "vos",
|
||||
"listaddrs", "-config", dirname, "-noauth", "-noresolve", NULL);
|
||||
exit(1);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user