tests: remove event loop from command test

This effectively reverts

  commit 39c77fe586
  Author: Michal Prívozník <mprivozn@redhat.com>
  Date:   Wed Jan 16 11:58:00 2013 +0100

    Introduce event loop to commandtest

because nothing in the current test suite needs this
event loop.

Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
Daniel P. Berrangé 2020-01-17 10:52:46 +00:00
parent 194382c183
commit abab604e30
3 changed files with 28 additions and 87 deletions

View File

@ -1,7 +1,7 @@
ARG:--readfd ARG:--readfd
ARG:3
ARG:--readfd
ARG:5 ARG:5
ARG:--readfd
ARG:7
ENV:DISPLAY=:0.0 ENV:DISPLAY=:0.0
ENV:HOME=/home/test ENV:HOME=/home/test
ENV:HOSTNAME=test ENV:HOSTNAME=test
@ -13,8 +13,8 @@ ENV:USER=test
FD:0 FD:0
FD:1 FD:1
FD:2 FD:2
FD:3
FD:5 FD:5
FD:7
DAEMON:no DAEMON:no
CWD:/tmp CWD:/tmp
UMASK:0022 UMASK:0022

View File

@ -9,8 +9,8 @@ ENV:USER=test
FD:0 FD:0
FD:1 FD:1
FD:2 FD:2
FD:3
FD:5 FD:5
FD:7
DAEMON:no DAEMON:no
CWD:/tmp CWD:/tmp
UMASK:0022 UMASK:0022

View File

@ -39,15 +39,6 @@
#define VIR_FROM_THIS VIR_FROM_NONE #define VIR_FROM_THIS VIR_FROM_NONE
typedef struct _virCommandTestData virCommandTestData;
typedef virCommandTestData *virCommandTestDataPtr;
struct _virCommandTestData {
virMutex lock;
virThread thread;
bool quit;
bool running;
};
#ifdef WIN32 #ifdef WIN32
int int
@ -204,8 +195,13 @@ static int test3(const void *unused G_GNUC_UNUSED)
int newfd1 = dup(STDERR_FILENO); int newfd1 = dup(STDERR_FILENO);
int newfd2 = dup(STDERR_FILENO); int newfd2 = dup(STDERR_FILENO);
int newfd3 = dup(STDERR_FILENO); int newfd3 = dup(STDERR_FILENO);
struct stat before, after;
int ret = -1; int ret = -1;
if (fstat(newfd3, &before) < 0) {
perror("fstat");
goto cleanup;
}
virCommandPassFD(cmd, newfd1, 0); virCommandPassFD(cmd, newfd1, 0);
virCommandPassFD(cmd, newfd3, virCommandPassFD(cmd, newfd3,
VIR_COMMAND_PASS_FD_CLOSE_PARENT); VIR_COMMAND_PASS_FD_CLOSE_PARENT);
@ -216,12 +212,28 @@ static int test3(const void *unused G_GNUC_UNUSED)
} }
if (fcntl(newfd1, F_GETFL) < 0 || if (fcntl(newfd1, F_GETFL) < 0 ||
fcntl(newfd2, F_GETFL) < 0 || fcntl(newfd2, F_GETFL) < 0) {
fcntl(newfd3, F_GETFL) >= 0) { puts("fds 1/2 were not open");
puts("fds in wrong state");
goto cleanup; goto cleanup;
} }
/* We expect newfd3 to be closed, but the
* fd might have already been reused by
* the event loop. So if it is open, we
* check if it matches the stat info we
* got earlier
*/
if (fcntl(newfd3, F_GETFL) >= 0 &&
fstat(newfd3, &after) >= 0) {
if (before.st_ino == after.st_ino &&
before.st_dev == after.st_dev &&
before.st_mode == after.st_mode) {
puts("fd 3 should not be open");
goto cleanup;
}
}
ret = checkoutput("test3", NULL); ret = checkoutput("test3", NULL);
cleanup: cleanup:
@ -1241,43 +1253,12 @@ static int test27(const void *unused G_GNUC_UNUSED)
return ret; return ret;
} }
static void virCommandThreadWorker(void *opaque)
{
virCommandTestDataPtr test = opaque;
virMutexLock(&test->lock);
while (!test->quit) {
virMutexUnlock(&test->lock);
if (virEventRunDefaultImpl() < 0) {
test->quit = true;
break;
}
virMutexLock(&test->lock);
}
test->running = false;
virMutexUnlock(&test->lock);
return;
}
static void
virCommandTestFreeTimer(int timer G_GNUC_UNUSED,
void *opaque G_GNUC_UNUSED)
{
/* nothing to be done here */
}
static int static int
mymain(void) mymain(void)
{ {
int ret = 0; int ret = 0;
int fd; int fd;
virCommandTestDataPtr test = NULL;
int timer = -1;
int virinitret; int virinitret;
if (chdir("/tmp") < 0) if (chdir("/tmp") < 0)
@ -1336,28 +1317,6 @@ mymain(void)
if (virinitret < 0) if (virinitret < 0)
return EXIT_FAILURE; return EXIT_FAILURE;
virEventRegisterDefaultImpl();
if (VIR_ALLOC(test) < 0)
goto cleanup;
if (virMutexInit(&test->lock) < 0) {
printf("Unable to init mutex: %d\n", errno);
goto cleanup;
}
virMutexLock(&test->lock);
if (virThreadCreate(&test->thread,
true,
virCommandThreadWorker,
test) < 0) {
virMutexUnlock(&test->lock);
goto cleanup;
}
test->running = true;
virMutexUnlock(&test->lock);
environ = (char **)newenv; environ = (char **)newenv;
# define DO_TEST(NAME) \ # define DO_TEST(NAME) \
@ -1393,24 +1352,6 @@ mymain(void)
DO_TEST(test26); DO_TEST(test26);
DO_TEST(test27); DO_TEST(test27);
virMutexLock(&test->lock);
if (test->running) {
test->quit = true;
/* HACK: Add a dummy timeout to break event loop */
timer = virEventAddTimeout(0, virCommandTestFreeTimer, NULL, NULL);
}
virMutexUnlock(&test->lock);
cleanup:
if (test->running)
virThreadJoin(&test->thread);
if (timer != -1)
virEventRemoveTimeout(timer);
virMutexDestroy(&test->lock);
VIR_FREE(test);
return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
} }