mirror of
https://git.openafs.org/openafs.git
synced 2025-01-18 15:00:12 +00:00
tests: Introduce afstest_asprintf
Add a thin wrapper around asprintf, called afstest_asprintf (and afstest_vasprintf), which does its own error checking. This just helps makes tests a little less cluttered when needing to construct strings. Adapt all asprintf callers in 'tests' to use the wrapper. Change-Id: I6c4ae5b72af827e2c4c66ecfc57f152855b1d401 Reviewed-on: https://gerrit.openafs.org/14620 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
405001be72
commit
d16a0f8d16
@ -124,8 +124,7 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
dirname = afstest_BuildTestConfig();
|
dirname = afstest_BuildTestConfig();
|
||||||
|
|
||||||
if (asprintf(&keyfile, "%s/KeyFile", dirname) == -1)
|
keyfile = afstest_asprintf("%s/KeyFile", dirname);
|
||||||
goto out;
|
|
||||||
|
|
||||||
/* Work out the path to our KeyFile. If the test harness hasn't set
|
/* 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 */
|
* the C_TAP_SOURCE environment variable, then assume it is in our CWD */
|
||||||
|
@ -43,7 +43,7 @@ main(int argc, char **argv)
|
|||||||
afsconf_Close(dir);
|
afsconf_Close(dir);
|
||||||
|
|
||||||
/* Copy out the resulting keyfile into our homedirectory */
|
/* Copy out the resulting keyfile into our homedirectory */
|
||||||
opr_Verify(asprintf(&keyfile, "%s/KeyFile", dirname) > 0);
|
keyfile = afstest_asprintf("%s/KeyFile", dirname);
|
||||||
in = open(keyfile, O_RDONLY);
|
in = open(keyfile, O_RDONLY);
|
||||||
out = open("KeyFile", O_WRONLY | O_CREAT, 0644);
|
out = open("KeyFile", O_WRONLY | O_CREAT, 0644);
|
||||||
|
|
||||||
|
@ -60,3 +60,6 @@ extern void afstest_SkipTestsIfServerRunning(char *name);
|
|||||||
|
|
||||||
/* misc.c */
|
/* misc.c */
|
||||||
extern char *afstest_GetProgname(char **argv);
|
extern char *afstest_GetProgname(char **argv);
|
||||||
|
extern char *afstest_vasprintf(const char *fmt, va_list ap);
|
||||||
|
extern char *afstest_asprintf(const char *fmt, ...)
|
||||||
|
AFS_ATTRIBUTE_FORMAT(__printf__, 1, 2);
|
||||||
|
@ -43,8 +43,7 @@ openConfigFile(char *dirname, char *filename) {
|
|||||||
char *path = NULL;
|
char *path = NULL;
|
||||||
FILE *file;
|
FILE *file;
|
||||||
|
|
||||||
if (asprintf(&path, "%s/%s", dirname, filename) == -1)
|
path = afstest_asprintf("%s/%s", dirname, filename);
|
||||||
return NULL;
|
|
||||||
|
|
||||||
file = fopen(path, "w");
|
file = fopen(path, "w");
|
||||||
free(path);
|
free(path);
|
||||||
@ -55,10 +54,9 @@ static void
|
|||||||
unlinkConfigFile(char *dirname, char *filename) {
|
unlinkConfigFile(char *dirname, char *filename) {
|
||||||
char *path;
|
char *path;
|
||||||
|
|
||||||
if (asprintf(&path, "%s/%s", dirname, filename) != -1) {
|
path = afstest_asprintf("%s/%s", dirname, filename);
|
||||||
unlink(path);
|
unlink(path);
|
||||||
free(path);
|
free(path);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
@ -103,8 +101,7 @@ afstest_BuildTestConfig(void) {
|
|||||||
char hostname[255];
|
char hostname[255];
|
||||||
struct in_addr iaddr;
|
struct in_addr iaddr;
|
||||||
|
|
||||||
if (asprintf(&dir, "%s/afs_XXXXXX", gettmpdir()) == -1)
|
dir = afstest_asprintf("%s/afs_XXXXXX", gettmpdir());
|
||||||
goto fail;
|
|
||||||
|
|
||||||
if (afstest_mkdtemp(dir) == NULL)
|
if (afstest_mkdtemp(dir) == NULL)
|
||||||
goto fail;
|
goto fail;
|
||||||
|
@ -29,6 +29,7 @@
|
|||||||
#include <afsconfig.h>
|
#include <afsconfig.h>
|
||||||
#include <afs/param.h>
|
#include <afs/param.h>
|
||||||
#include <roken.h>
|
#include <roken.h>
|
||||||
|
#include <tests/tap/basic.h>
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
|
||||||
@ -46,3 +47,24 @@ afstest_GetProgname(char **argv)
|
|||||||
}
|
}
|
||||||
return argv[0];
|
return argv[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *
|
||||||
|
afstest_vasprintf(const char *fmt, va_list ap)
|
||||||
|
{
|
||||||
|
char *str;
|
||||||
|
if (vasprintf(&str, fmt, ap) < 0) {
|
||||||
|
sysbail("vasprintf");
|
||||||
|
}
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
char *
|
||||||
|
afstest_asprintf(const char *fmt, ...)
|
||||||
|
{
|
||||||
|
char *str;
|
||||||
|
va_list ap;
|
||||||
|
va_start(ap, fmt);
|
||||||
|
str = afstest_vasprintf(fmt, ap);
|
||||||
|
va_end(ap);
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
@ -39,12 +39,10 @@ afstest_StartVLServer(char *dirname, pid_t *serverPid)
|
|||||||
if (build == NULL)
|
if (build == NULL)
|
||||||
build = "..";
|
build = "..";
|
||||||
|
|
||||||
if (asprintf(&binPath, "%s/../src/tvlserver/vlserver", build) < 0 ||
|
binPath = afstest_asprintf("%s/../src/tvlserver/vlserver", build);
|
||||||
asprintf(&logPath, "%s/VLLog", dirname) < 0 ||
|
logPath = afstest_asprintf("%s/VLLog", dirname);
|
||||||
asprintf(&dbPath, "%s/vldb", dirname) < 0) {
|
dbPath = afstest_asprintf("%s/vldb", dirname);
|
||||||
fprintf(stderr, "Out of memory building vlserver arguments\n");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
execl(binPath, "vlserver",
|
execl(binPath, "vlserver",
|
||||||
"-logfile", logPath, "-database", dbPath, "-config", dirname, NULL);
|
"-logfile", logPath, "-database", dbPath, "-config", dirname, NULL);
|
||||||
fprintf(stderr, "Running %s failed\n", binPath);
|
fprintf(stderr, "Running %s failed\n", binPath);
|
||||||
|
Loading…
Reference in New Issue
Block a user