Skip to content

Commit

Permalink
New run-tests program
Browse files Browse the repository at this point in the history
Replace the old run-tests shell script with a C program, which
gives much cleaner output, runs faster, and allows us to do more
with the conditional capabilities.

The capabilites are tested for with cap_* conditionals in the
tests.conf files. At present we have cap_root and cap_affinity.
Capabilties can be negated with ! (eg !cap_root).

Also, add a couple of tests for the new testsuite, and update the
README to match.

Tests are now run in a new working-dir, rather than copying the
entire test tree. PATH is set to the test's base directory, so that
any library programs are available.

Signed-off-by: Jeremy Kerr <[email protected]>
  • Loading branch information
jk-ozlabs committed Feb 14, 2008
1 parent 6a904b6 commit a2d78e9
Show file tree
Hide file tree
Showing 24 changed files with 2,900 additions and 211 deletions.
19 changes: 16 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,26 @@
# along with this program; if not, write to the Free Software
# Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

all:
cd tests && make all
cd benchmarks && make all
CC=gcc
CFLAGS=-Wall -Werror -g -O2
LDFLAGS=

all: tests benchmarks

.PHONY: tests benchmarks

tests benchmarks: bin/run-tests
$(MAKE) -C $@ all


bin/run-tests: bin/talloc/talloc.o bin/run-tests.o bin/capabilities.o bin/test.o
$(LINK.o) -o $@ $^

clean:
cd tests && make clean
cd benchmarks && make clean
rm -f bin/capabilities bin/run-tests
rm -f bin/*.o

check: clean all
./run-tests
26 changes: 19 additions & 7 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ See the COPYING file for the full text of the GNU General Public License.

Running:

* ./run-tests
* bin/run-tests
- to run all tests
* ./run-tests <test-dir>
* bin/run-tests <test-dir>
- run all tests in <test-dir>
* ./run-tests <test-file>
* bin/run-tests <test-file>
- run a single test file

* The -c option will cause the test suite to continue on failures
Expand Down Expand Up @@ -46,13 +46,25 @@ Writing tests:

where options may be one or more of:
expected_rc=<rc> # expect a rc of <rc> instead of 0
disabled=1 # disable the test
needs_root=1 # disable the test if run by a non-root user
signal=<signum> # expect the test be be killed by <signum>
disabled # disable the test

you can also make tests conditionally run if various capabilities are
available on the system at run-time. These are specicied by cap_* options.
At present, we have the following capabilities:
cap_root # run the test if uid==0
cap_affinity # run the test only on affinity-enabled hardware

Capabilities can be inverted, using the '!' character. For example,
the option "!cap_root" will run the test only if uid!=0.

for example, from the testsuite's own test.conf:
01-fail: expected_rc=1
02-root: needs_root=1
03-skip: disabled=1
02-root: cap_root
03-skip: disabled
06-cap: cap_never
07-nocap: !cap_always
08-signal: signal=15

If a test is not listed in test.conf (or there is no test.conf), then
the default options will be used.
Expand Down
132 changes: 132 additions & 0 deletions bin/capabilities.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
/*
* Testsuite for the Linux SPU filesystem
*
* Copyright (C) IBM Corporation, 2008
*
* Author: Jeremy Kerr <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/


#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <sys/types.h>
#include <sys/stat.h>

static int cap_always(void)
{
return 1;
}

static int cap_never(void)
{
return 0;
}

static int cap_root(void)
{
return getuid() == 0;
}

static int cap_affinity(void)
{
struct stat statbuf;

/* test to see if we have NUMA nodes in /sys */
return stat("/sys/devices/system/node", &statbuf) == 0;
}

struct capability {
const char *name;
int (*fn)(void);
int value;
int valid;
};

static struct capability caps[] = {
{
.name = "always",
.fn = cap_always
},
{
.name = "never",
.fn = cap_never
},
{
.name = "root",
.fn = cap_root
},
{
.name = "affinity",
.fn = cap_affinity
},
{
.name = NULL
}
};

static int __cap_available(struct capability *cap)
{
if (!cap->valid) {
cap->value = cap->fn();
cap->valid = 1;
}

return cap->value;
}

int cap_available(const char *name)
{
struct capability *cap;

for (cap = caps; cap->name; cap++) {
if (!strcmp(cap->name, name))
return __cap_available(cap);
}

return 0;
}

#if 0

void print_all_caps(void)
{
struct capability *cap;

for (cap = caps; cap->name; cap++)
printf("%s=%d\n", cap->name, get_capability(cap));
}

int print_cap(const char *name)
{
struct capability *cap;

for (cap = caps; cap->name; cap++) {
if (!strcasecmp(cap->name, name)) {
printf("%s=%d\n", cap->name, get_capability(cap));
return 0;
}
}

fprintf(stderr, "No such capability '%s'\n", name);
return -1;
}

#endif

28 changes: 28 additions & 0 deletions bin/capabilities.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Testsuite for the Linux SPU filesystem
*
* Copyright (C) IBM Corporation, 2008
*
* Author: Jeremy Kerr <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

#ifndef _CAPABILITIES_H
#define _CAPABILITIES_H

int cap_available(const char *name);

#endif /* _CAPABILITIES_H */
Loading

0 comments on commit a2d78e9

Please sign in to comment.