1
0
Fork 0
mirror of https://github.com/tailix/libshmemq.git synced 2024-11-20 11:08:35 -05:00

Cleanup after tests

This commit is contained in:
Alex Kotov 2020-12-15 12:49:38 +05:00
parent c1294fd878
commit 19dff0680d
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08
6 changed files with 153 additions and 41 deletions

View file

@ -1,15 +1,22 @@
#include <shmemq.h> #include <shmemq.h>
#include <assert.h> #include <assert.h>
#include <signal.h>
#include <stdlib.h>
static const char name[] = "/foobar"; static const char name[] = "/foobar";
static ShmemqError error = SHMEMQ_ERROR_NONE;
static Shmemq consumer = NULL; static Shmemq consumer = NULL;
static Shmemq producer = NULL; static Shmemq producer = NULL;
static void on_exit();
static void on_signal(int signo);
int main() int main()
{ {
ShmemqError error; atexit(on_exit);
signal(SIGABRT, on_signal);
consumer = shmemq_new(name, true, &error); consumer = shmemq_new(name, true, &error);
assert(error == SHMEMQ_ERROR_NONE); assert(error == SHMEMQ_ERROR_NONE);
@ -22,11 +29,23 @@ int main()
shmemq_pop_end(consumer, &error); shmemq_pop_end(consumer, &error);
assert(error == SHMEMQ_ERROR_BUG_POP_END_ON_EMPTY_QUEUE); assert(error == SHMEMQ_ERROR_BUG_POP_END_ON_EMPTY_QUEUE);
SHMEMQ_DELETE(consumer, &error);
assert(error == SHMEMQ_ERROR_NONE);
SHMEMQ_DELETE(producer, &error);
assert(error == SHMEMQ_ERROR_NONE);
return 0; return 0;
} }
void on_exit()
{
if (consumer) {
SHMEMQ_DELETE(consumer, &error);
assert(error == SHMEMQ_ERROR_NONE);
}
if (producer) {
SHMEMQ_DELETE(producer, &error);
assert(error == SHMEMQ_ERROR_NONE);
}
}
void on_signal(const int signo __attribute__((unused)))
{
on_exit();
}

View file

@ -1,15 +1,22 @@
#include <shmemq.h> #include <shmemq.h>
#include <assert.h> #include <assert.h>
#include <signal.h>
#include <stdlib.h>
static const char name[] = "/foobar"; static const char name[] = "/foobar";
static ShmemqError error = SHMEMQ_ERROR_NONE;
static Shmemq consumer = NULL; static Shmemq consumer = NULL;
static Shmemq producer = NULL; static Shmemq producer = NULL;
static void on_exit();
static void on_signal(int signo);
int main() int main()
{ {
ShmemqError error; atexit(on_exit);
signal(SIGABRT, on_signal);
consumer = shmemq_new(name, true, &error); consumer = shmemq_new(name, true, &error);
assert(error == SHMEMQ_ERROR_NONE); assert(error == SHMEMQ_ERROR_NONE);
@ -42,11 +49,23 @@ int main()
shmemq_pop_end(consumer, &error); shmemq_pop_end(consumer, &error);
assert(error == SHMEMQ_ERROR_BUG_POP_END_ON_EMPTY_QUEUE); assert(error == SHMEMQ_ERROR_BUG_POP_END_ON_EMPTY_QUEUE);
SHMEMQ_DELETE(consumer, &error);
assert(error == SHMEMQ_ERROR_NONE);
SHMEMQ_DELETE(producer, &error);
assert(error == SHMEMQ_ERROR_NONE);
return 0; return 0;
} }
void on_exit()
{
if (consumer) {
SHMEMQ_DELETE(consumer, &error);
assert(error == SHMEMQ_ERROR_NONE);
}
if (producer) {
SHMEMQ_DELETE(producer, &error);
assert(error == SHMEMQ_ERROR_NONE);
}
}
void on_signal(const int signo __attribute__((unused)))
{
on_exit();
}

View file

@ -1,19 +1,26 @@
#include <shmemq.h> #include <shmemq.h>
#include <assert.h> #include <assert.h>
#include <signal.h>
#include <stdlib.h>
#include <string.h> #include <string.h>
#include <sys/mman.h> #include <sys/mman.h>
static const char name[] = "/foobar"; static const char name[] = "/foobar";
static const char hello_world_str[] = "Hello, World!"; static const char hello_world_str[] = "Hello, World!";
static ShmemqError error = SHMEMQ_ERROR_NONE;
static struct Shmemq consumer_shmemq;
static Shmemq producer_shmemq = NULL; static Shmemq producer_shmemq = NULL;
static void on_exit();
static void on_signal(int signo);
int main() int main()
{ {
ShmemqError error; atexit(on_exit);
signal(SIGABRT, on_signal);
struct Shmemq consumer_shmemq;
memset(&consumer_shmemq, 0, sizeof(consumer_shmemq)); memset(&consumer_shmemq, 0, sizeof(consumer_shmemq));
shmemq_init(&consumer_shmemq, name, true, &error); shmemq_init(&consumer_shmemq, name, true, &error);
@ -165,11 +172,21 @@ int main()
shmemq_pop_end(&consumer_shmemq, &error); shmemq_pop_end(&consumer_shmemq, &error);
assert(error == SHMEMQ_ERROR_BUG_POP_END_ON_EMPTY_QUEUE); assert(error == SHMEMQ_ERROR_BUG_POP_END_ON_EMPTY_QUEUE);
return 0;
}
void on_exit()
{
shmemq_finish(&consumer_shmemq, &error); shmemq_finish(&consumer_shmemq, &error);
assert(error == SHMEMQ_ERROR_NONE); assert(error == SHMEMQ_ERROR_NONE);
SHMEMQ_DELETE(producer_shmemq, &error); if (producer_shmemq) {
assert(error == SHMEMQ_ERROR_NONE); SHMEMQ_DELETE(producer_shmemq, &error);
assert(error == SHMEMQ_ERROR_NONE);
return 0; }
}
void on_signal(const int signo __attribute__((unused)))
{
on_exit();
} }

View file

@ -1,15 +1,22 @@
#include <shmemq.h> #include <shmemq.h>
#include <assert.h> #include <assert.h>
#include <signal.h>
#include <stdlib.h>
static const char name[] = "/foobar"; static const char name[] = "/foobar";
static ShmemqError error = SHMEMQ_ERROR_NONE;
static Shmemq consumer = NULL; static Shmemq consumer = NULL;
static Shmemq producer = NULL; static Shmemq producer = NULL;
static void on_exit();
static void on_signal(int signo);
int main() int main()
{ {
ShmemqError error; atexit(on_exit);
signal(SIGABRT, on_signal);
consumer = shmemq_new(name, true, &error); consumer = shmemq_new(name, true, &error);
assert(error == SHMEMQ_ERROR_NONE); assert(error == SHMEMQ_ERROR_NONE);
@ -53,11 +60,23 @@ int main()
shmemq_push_end(producer, 9, &error); shmemq_push_end(producer, 9, &error);
assert(error == SHMEMQ_ERROR_BUG_PUSH_END_OVERFLOW); assert(error == SHMEMQ_ERROR_BUG_PUSH_END_OVERFLOW);
SHMEMQ_DELETE(consumer, &error);
assert(error == SHMEMQ_ERROR_NONE);
SHMEMQ_DELETE(producer, &error);
assert(error == SHMEMQ_ERROR_NONE);
return 0; return 0;
} }
void on_exit()
{
if (consumer) {
SHMEMQ_DELETE(consumer, &error);
assert(error == SHMEMQ_ERROR_NONE);
}
if (producer) {
SHMEMQ_DELETE(producer, &error);
assert(error == SHMEMQ_ERROR_NONE);
}
}
void on_signal(const int signo __attribute__((unused)))
{
on_exit();
}

View file

@ -1,15 +1,22 @@
#include <shmemq.h> #include <shmemq.h>
#include <assert.h> #include <assert.h>
#include <signal.h>
#include <stdlib.h>
static const char name[] = "/foobar"; static const char name[] = "/foobar";
static ShmemqError error = SHMEMQ_ERROR_NONE;
static Shmemq consumer = NULL; static Shmemq consumer = NULL;
static Shmemq producer = NULL; static Shmemq producer = NULL;
static void on_exit();
static void on_signal(int signo);
int main() int main()
{ {
ShmemqError error; atexit(on_exit);
signal(SIGABRT, on_signal);
consumer = shmemq_new(name, true, &error); consumer = shmemq_new(name, true, &error);
assert(error == SHMEMQ_ERROR_NONE); assert(error == SHMEMQ_ERROR_NONE);
@ -52,11 +59,23 @@ int main()
shmemq_push_end(producer, sizeof(unsigned), &error); shmemq_push_end(producer, sizeof(unsigned), &error);
assert(error == SHMEMQ_ERROR_BUG_PUSH_END_ON_FULL_QUEUE); assert(error == SHMEMQ_ERROR_BUG_PUSH_END_ON_FULL_QUEUE);
SHMEMQ_DELETE(consumer, &error);
assert(error == SHMEMQ_ERROR_NONE);
SHMEMQ_DELETE(producer, &error);
assert(error == SHMEMQ_ERROR_NONE);
return 0; return 0;
} }
void on_exit()
{
if (consumer) {
SHMEMQ_DELETE(consumer, &error);
assert(error == SHMEMQ_ERROR_NONE);
}
if (producer) {
SHMEMQ_DELETE(producer, &error);
assert(error == SHMEMQ_ERROR_NONE);
}
}
void on_signal(const int signo __attribute__((unused)))
{
on_exit();
}

View file

@ -1,15 +1,22 @@
#include <shmemq.h> #include <shmemq.h>
#include <assert.h> #include <assert.h>
#include <signal.h>
#include <stdlib.h>
static const char name[] = "/foobar"; static const char name[] = "/foobar";
static ShmemqError error = SHMEMQ_ERROR_NONE;
static Shmemq consumer = NULL; static Shmemq consumer = NULL;
static Shmemq producer = NULL; static Shmemq producer = NULL;
static void on_exit();
static void on_signal(int signo);
int main() int main()
{ {
ShmemqError error; atexit(on_exit);
signal(SIGABRT, on_signal);
consumer = shmemq_new(name, true, &error); consumer = shmemq_new(name, true, &error);
assert(error == SHMEMQ_ERROR_NONE); assert(error == SHMEMQ_ERROR_NONE);
@ -32,11 +39,23 @@ int main()
shmemq_push_end(producer, sizeof(unsigned), &error); shmemq_push_end(producer, sizeof(unsigned), &error);
assert(error == SHMEMQ_ERROR_BUG_PUSH_END_ON_FULL_QUEUE); assert(error == SHMEMQ_ERROR_BUG_PUSH_END_ON_FULL_QUEUE);
SHMEMQ_DELETE(consumer, &error);
assert(error == SHMEMQ_ERROR_NONE);
SHMEMQ_DELETE(producer, &error);
assert(error == SHMEMQ_ERROR_NONE);
return 0; return 0;
} }
void on_exit()
{
if (consumer) {
SHMEMQ_DELETE(consumer, &error);
assert(error == SHMEMQ_ERROR_NONE);
}
if (producer) {
SHMEMQ_DELETE(producer, &error);
assert(error == SHMEMQ_ERROR_NONE);
}
}
void on_signal(const int signo __attribute__((unused)))
{
on_exit();
}