1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-10-28 03:27:58 +03:00

Add a "should" alongside "not" to the test utilities. When a "should" command

fails, the test will carry on but will issue a warning. The harness detects
such warnings from tests and marks tests that passed with warnings with a
special status.
This commit is contained in:
Petr Rockai 2010-04-30 14:33:39 +00:00
parent aaa2e0468f
commit d6b9d2cbc3
3 changed files with 29 additions and 8 deletions

View File

@ -62,6 +62,7 @@ check_local: init.sh
bin/not: $(srcdir)/not.c .bin-dir-stamp
$(CC) -o bin/not $<
ln -sf not bin/should
bin/harness: $(srcdir)/harness.c .bin-dir-stamp
$(CC) -o bin/harness $<

View File

@ -15,6 +15,7 @@ struct stats {
int nfailed;
int nskipped;
int npassed;
int nwarned;
int status[MAX];
};
@ -29,6 +30,7 @@ int die = 0;
#define PASSED 0
#define SKIPPED 1
#define FAILED 2
#define WARNED 3
void handler( int s ) {
signal( s, SIG_DFL );
@ -59,13 +61,20 @@ void drain() {
exit(205);
memcpy(readbuf + readbuf_used, buf, sz);
readbuf_used += sz;
readbuf[readbuf_used] = 0;
}
}
void passed(int i, char *f) {
++ s.npassed;
s.status[i] = PASSED;
printf("passed.\n");
if (strstr(readbuf, "TEST WARNING")) {
++s.nwarned;
s.status[i] = WARNED;
printf("warnings\n");
} else {
++ s.npassed;
s.status[i] = PASSED;
printf("passed.\n");
}
}
void skipped(int i, char *f) {
@ -140,7 +149,7 @@ int main(int argc, char **argv) {
exit(1);
}
s.nfailed = s.npassed = s.nskipped = 0;
s.nwarned = s.nfailed = s.npassed = s.nskipped = 0;
char *config = getenv("LVM_TEST_CONFIG"),
*config_debug;
@ -178,8 +187,9 @@ int main(int argc, char **argv) {
}
}
printf("\n## %d tests: %d OK, %d failed, %d skipped\n",
s.npassed + s.nfailed + s.nskipped, s.npassed, s.nfailed, s.nskipped);
printf("\n## %d tests: %d OK, %d warnings, %d failures; %d skipped\n",
s.nwarned + s.npassed + s.nfailed + s.nskipped,
s.npassed, s.nwarned, s.nfailed, s.nskipped);
/* print out a summary */
if (s.nfailed || s.nskipped) {

View File

@ -4,6 +4,16 @@
#include <sys/types.h>
#include <sys/wait.h>
int finished(const char *cmd, int status) {
if (!strcmp(cmd, "not"))
return !status;
if (!strcmp(cmd, "should")) {
fprintf(stderr, "TEST WARNING: Ignoring command failure.\n");
return 0;
}
return 6;
}
int main(int args, char **argv) {
pid_t pid;
int status;
@ -32,8 +42,8 @@ int main(int args, char **argv) {
/* did not exit correctly */
return FAILURE;
}
/* return the opposite */
return !WEXITSTATUS(status);
return finished(argv[0], WEXITSTATUS(status));
}
/* not accessible */
return FAILURE;