Pino Toscano
2014-May-05 15:05 UTC
[Libguestfs] [PATCH] test-charset-fidelity: allow to skip testing specific FSes
Allow to skip testing the filesystem "foo" if the environment variable
SKIP_TEST_CHARSET_FIDELITY_foo=1 is set. This way it possible to not
test one or more filesystems without disabling the test altogether.
---
tests/charsets/test-charset-fidelity.c | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/tests/charsets/test-charset-fidelity.c
b/tests/charsets/test-charset-fidelity.c
index c669b9d..654ea0f 100644
--- a/tests/charsets/test-charset-fidelity.c
+++ b/tests/charsets/test-charset-fidelity.c
@@ -33,6 +33,8 @@
#include "guestfs.h"
#include "guestfs-internal-frontend.h"
+static const char ourenvvar[] = "SKIP_TEST_CHARSET_FIDELITY";
+
struct filesystem {
const char *fs_name; /* Name of filesystem. */
int fs_case_insensitive; /* True if filesystem is case insensitive. */
@@ -78,7 +80,7 @@ main (int argc, char *argv[])
struct filesystem *fs;
/* Allow this test to be skipped. */
- str = getenv ("SKIP_TEST_CHARSET_FIDELITY");
+ str = getenv (ourenvvar);
if (str && STREQ (str, "1")) {
printf ("%s: test skipped because environment variable is
set.\n",
program_name);
@@ -113,6 +115,8 @@ static void
test_filesystem (guestfs_h *g, const struct filesystem *fs)
{
const char *feature[] = { fs->fs_feature, NULL };
+ char envvar[sizeof (ourenvvar) + 20];
+ char *str;
if (fs->fs_feature && !guestfs_feature_available (g, (char **)
feature)) {
printf ("skipped test of %s because %s feature not available\n",
@@ -120,6 +124,14 @@ test_filesystem (guestfs_h *g, const struct filesystem *fs)
return;
}
+ snprintf (envvar, sizeof (envvar) - 1, "%s_%s", ourenvvar,
fs->fs_name);
+ str = getenv (envvar);
+ if (str && STREQ (str, "1")) {
+ printf ("skipped test of %s because environment variable is
set\n",
+ fs->fs_name);
+ return;
+ }
+
printf ("testing charset fidelity on %s\n", fs->fs_name);
make_filesystem (g, fs);
--
1.9.0
Richard W.M. Jones
2014-May-07 09:05 UTC
Re: [Libguestfs] [PATCH] test-charset-fidelity: allow to skip testing specific FSes
On Mon, May 05, 2014 at 05:05:29PM +0200, Pino Toscano wrote:> + snprintf (envvar, sizeof (envvar) - 1, "%s_%s", ourenvvar, fs->fs_name);Is this right? I'm tempted to say it should be `sizeof envvar'. However my knowledge of C is not clear enough to say whether that would evaluate to the size of the array or the size of a pointer (8 bytes). So perhaps it's safer to use something like: const size_t len = /* computed size */; const char envvar[len]; /* ... */ snprintf (envvar, len, ...); Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-top is 'top' for virtual machines. Tiny program with many powerful monitoring features, net stats, disk stats, logging, etc. http://people.redhat.com/~rjones/virt-top
Pino Toscano
2014-May-07 13:06 UTC
Re: [Libguestfs] [PATCH] test-charset-fidelity: allow to skip testing specific FSes
On Wednesday 07 May 2014 10:05:56 Richard W.M. Jones wrote:> On Mon, May 05, 2014 at 05:05:29PM +0200, Pino Toscano wrote: > > + snprintf (envvar, sizeof (envvar) - 1, "%s_%s", ourenvvar, > > fs->fs_name); > Is this right? > > I'm tempted to say it should be `sizeof envvar'. However my knowledge > of C is not clear enough to say whether that would evaluate to the > size of the array or the size of a pointer (8 bytes).Yes, this works because envvar is a char array. (Theoretically it should be sizeof(buf)/sizeof(buf[0]), but since sizeof(char) == 1 usually then could be omitted.) The "- 1" bit is because I always forget whether the size argument in the {,v}snprint functions include the \0 at the end. There is enough space in this case anyway, so it shouldn't matter that much. -- Pino Toscano
Possibly Parallel Threads
- [PATCH 0/3] Allow environment variables to have boolean values.
- [PATCH] kinit: Add ability to mount filesystems via /etc/fstab or cmdline
- [klibc:master] fstype: Drop obsolete support for "ext4dev"
- [PATCH] fstype: Fix ext4/ext4dev probing
- buffer overflow detected in collectd using libguestfs