mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-09-09 17:24:53 +00:00
tests: eventtest: Open code virtTestResult
These event tests aren't run synchronously, so there isn't an obvious function to pass to virtTestRun. Instead, open code roughly what virtTestResult did before: printing an error message if a test failed.
This commit is contained in:
parent
64cc686d79
commit
ae8755370f
@ -63,6 +63,41 @@ enum {
|
|||||||
EV_ERROR_DATA,
|
EV_ERROR_DATA,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct testEventResultData {
|
||||||
|
bool failed;
|
||||||
|
const char *msg;
|
||||||
|
};
|
||||||
|
|
||||||
|
static int
|
||||||
|
testEventResultCallback(const void *opaque)
|
||||||
|
{
|
||||||
|
const struct testEventResultData *data = opaque;
|
||||||
|
|
||||||
|
if (data->failed && data->msg)
|
||||||
|
fprintf(stderr, "%s", data->msg);
|
||||||
|
return data->failed;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
ATTRIBUTE_FMT_PRINTF(3, 4)
|
||||||
|
testEventReport(const char *name, bool failed, const char *msg, ...)
|
||||||
|
{
|
||||||
|
va_list vargs;
|
||||||
|
va_start(vargs, msg);
|
||||||
|
char *str = NULL;
|
||||||
|
struct testEventResultData data;
|
||||||
|
|
||||||
|
if (msg && virVasprintfQuiet(&str, msg, vargs) != 0)
|
||||||
|
failed = true;
|
||||||
|
|
||||||
|
data.failed = failed;
|
||||||
|
data.msg = str;
|
||||||
|
virtTestRun(name, testEventResultCallback, &data);
|
||||||
|
|
||||||
|
va_end(vargs);
|
||||||
|
VIR_FREE(str);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
testPipeReader(int watch, int fd, int events, void *data)
|
testPipeReader(int watch, int fd, int events, void *data)
|
||||||
{
|
{
|
||||||
@ -148,13 +183,13 @@ verifyFired(const char *name, int handle, int timer)
|
|||||||
for (i = 0; i < NUM_FDS; i++) {
|
for (i = 0; i < NUM_FDS; i++) {
|
||||||
if (handles[i].fired) {
|
if (handles[i].fired) {
|
||||||
if (i != handle) {
|
if (i != handle) {
|
||||||
virtTestResult(name, 1,
|
testEventReport(name, 1,
|
||||||
"Handle %zu fired, but expected %d\n", i,
|
"Handle %zu fired, but expected %d\n", i,
|
||||||
handle);
|
handle);
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
} else {
|
} else {
|
||||||
if (handles[i].error != EV_ERROR_NONE) {
|
if (handles[i].error != EV_ERROR_NONE) {
|
||||||
virtTestResult(name, 1,
|
testEventReport(name, 1,
|
||||||
"Handle %zu fired, but had error %d\n", i,
|
"Handle %zu fired, but had error %d\n", i,
|
||||||
handles[i].error);
|
handles[i].error);
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
@ -163,7 +198,7 @@ verifyFired(const char *name, int handle, int timer)
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (i == handle) {
|
if (i == handle) {
|
||||||
virtTestResult(name, 1,
|
testEventReport(name, 1,
|
||||||
"Handle %d should have fired, but didn't\n",
|
"Handle %d should have fired, but didn't\n",
|
||||||
handle);
|
handle);
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
@ -171,7 +206,7 @@ verifyFired(const char *name, int handle, int timer)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (handleFired != 1 && handle != -1) {
|
if (handleFired != 1 && handle != -1) {
|
||||||
virtTestResult(name, 1,
|
testEventReport(name, 1,
|
||||||
"Something weird happened, expecting handle %d\n",
|
"Something weird happened, expecting handle %d\n",
|
||||||
handle);
|
handle);
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
@ -181,12 +216,12 @@ verifyFired(const char *name, int handle, int timer)
|
|||||||
for (i = 0; i < NUM_TIME; i++) {
|
for (i = 0; i < NUM_TIME; i++) {
|
||||||
if (timers[i].fired) {
|
if (timers[i].fired) {
|
||||||
if (i != timer) {
|
if (i != timer) {
|
||||||
virtTestResult(name, 1,
|
testEventReport(name, 1,
|
||||||
"Timer %zu fired, but expected %d\n", i, timer);
|
"Timer %zu fired, but expected %d\n", i, timer);
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
} else {
|
} else {
|
||||||
if (timers[i].error != EV_ERROR_NONE) {
|
if (timers[i].error != EV_ERROR_NONE) {
|
||||||
virtTestResult(name, 1,
|
testEventReport(name, 1,
|
||||||
"Timer %zu fired, but had error %d\n", i,
|
"Timer %zu fired, but had error %d\n", i,
|
||||||
timers[i].error);
|
timers[i].error);
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
@ -195,7 +230,7 @@ verifyFired(const char *name, int handle, int timer)
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (i == timer) {
|
if (i == timer) {
|
||||||
virtTestResult(name, 1,
|
testEventReport(name, 1,
|
||||||
"Timer %d should have fired, but didn't\n",
|
"Timer %d should have fired, but didn't\n",
|
||||||
timer);
|
timer);
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
@ -203,7 +238,7 @@ verifyFired(const char *name, int handle, int timer)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (timerFired != 1 && timer != -1) {
|
if (timerFired != 1 && timer != -1) {
|
||||||
virtTestResult(name, 1,
|
testEventReport(name, 1,
|
||||||
"Something weird happened, expecting timer %d\n",
|
"Something weird happened, expecting timer %d\n",
|
||||||
timer);
|
timer);
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
@ -234,14 +269,14 @@ finishJob(const char *name, int handle, int timer)
|
|||||||
rc = pthread_cond_timedwait(&eventThreadJobCond, &eventThreadMutex,
|
rc = pthread_cond_timedwait(&eventThreadJobCond, &eventThreadMutex,
|
||||||
&waitTime);
|
&waitTime);
|
||||||
if (rc != 0) {
|
if (rc != 0) {
|
||||||
virtTestResult(name, 1, "Timed out waiting for pipe event\n");
|
testEventReport(name, 1, "Timed out waiting for pipe event\n");
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (verifyFired(name, handle, timer) != EXIT_SUCCESS)
|
if (verifyFired(name, handle, timer) != EXIT_SUCCESS)
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
|
|
||||||
virtTestResult(name, 0, NULL);
|
testEventReport(name, 0, NULL);
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user