test: Update tmpf to store data in /tmp, reformat names
Cleans up residuals from failed tests in the source tree by moving them
to /tmp. Some were annoying to remove with prefixes like 'mbox', so
change the pattern as well to include '-store'.
Change-Id: I674664a372e7e15ec4c3cd93d33318c4135f33ba
Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
diff --git a/test/copy_flash.c b/test/copy_flash.c
index 5c40b53..d39ef93 100644
--- a/test/copy_flash.c
+++ b/test/copy_flash.c
@@ -66,7 +66,7 @@
goto free;
}
- rc = tmpf_init(&tmp, "flashXXXXXX");
+ rc = tmpf_init(&tmp, "flash-store.XXXXXX");
if (rc < 0)
goto free;
diff --git a/test/erase_flash.c b/test/erase_flash.c
index 71e87b5..fa8c92c 100644
--- a/test/erase_flash.c
+++ b/test/erase_flash.c
@@ -42,7 +42,7 @@
{
int rc;
- rc = tmpf_init(&mtd, "flashXXXXXX");
+ rc = tmpf_init(&mtd, "flash-store.XXXXXX");
if (rc < 0)
return NULL;
diff --git a/test/mbox.c b/test/mbox.c
index dc049ce..6fe7277 100644
--- a/test/mbox.c
+++ b/test/mbox.c
@@ -216,13 +216,13 @@
atexit(cleanup);
- rc = tmpf_init(&test.mbox, "mboxXXXXXX");
+ rc = tmpf_init(&test.mbox, "mbox-store.XXXXXX");
assert(rc == 0);
- rc = tmpf_init(&test.flash, "flashXXXXXX");
+ rc = tmpf_init(&test.flash, "flash-store.XXXXXX");
assert(rc == 0);
- rc = tmpf_init(&test.lpc, "lpcXXXXXX");
+ rc = tmpf_init(&test.lpc, "lpc-store.XXXXXX");
assert(rc == 0);
test.context.windows.num = n_windows;
diff --git a/test/tmpf.c b/test/tmpf.c
index 285f5d5..e9cc558 100644
--- a/test/tmpf.c
+++ b/test/tmpf.c
@@ -25,9 +25,12 @@
#include "test/tmpf.h"
+static const char *tmpf_dir = "/tmp/";
+
int tmpf_init(struct tmpf *tmpf, const char *template)
{
- strncpy(tmpf->path, template, sizeof(tmpf->path) - 1);
+ strcpy(tmpf->path, tmpf_dir);
+ strncat(tmpf->path, template, sizeof(tmpf->path) - sizeof(tmpf_dir));
tmpf->fd = mkstemp(tmpf->path);
if (tmpf->fd < 0) {
diff --git a/test/tmpf.h b/test/tmpf.h
index ce47191..cb1bda4 100644
--- a/test/tmpf.h
+++ b/test/tmpf.h
@@ -27,8 +27,20 @@
char path[PATH_MAX];
};
+/**
+ * Initialise a tmpf instance for use, creating a temporary file.
+ *
+ * @tmpf: A context to initialise with the provided template
+ * @template_str: A file basename in mkstemp(3) template form
+ *
+ * Returns 0 on success, or -1 on error with errno set appropriately
+ */
int tmpf_init(struct tmpf *tmpf, const char *template_str);
+/**
+ * Destroy a tmpf instance, closing the file descriptor and removing the
+ * temporary file.
+ */
void tmpf_destroy(struct tmpf *tmpf);
#endif /* MBOX_TEST_UTILS_H */
diff --git a/test/write_flash.c b/test/write_flash.c
index ebd0fb7..6a92d4b 100644
--- a/test/write_flash.c
+++ b/test/write_flash.c
@@ -40,7 +40,7 @@
{
int rc;
- rc = tmpf_init(tmp, "flashXXXXXX");
+ rc = tmpf_init(tmp, "flash-store.XXXXXX");
if (rc < 0)
return NULL;