libshmemq/tests/test_cons_pops_buffer_start.c

52 lines
1017 B
C
Raw Normal View History

2020-12-14 18:50:53 +00:00
#include <shmemq.h>
#include <assert.h>
2020-12-15 07:49:38 +00:00
#include <signal.h>
#include <stdlib.h>
2020-12-14 18:50:53 +00:00
static const char name[] = "/foobar";
2020-12-15 07:49:38 +00:00
static ShmemqError error = SHMEMQ_ERROR_NONE;
2020-12-15 07:22:52 +00:00
static Shmemq consumer = NULL;
static Shmemq producer = NULL;
2020-12-15 07:49:38 +00:00
static void on_exit();
static void on_signal(int signo);
2020-12-14 18:50:53 +00:00
int main()
{
2020-12-15 07:49:38 +00:00
atexit(on_exit);
signal(SIGABRT, on_signal);
2020-12-14 18:50:53 +00:00
2020-12-15 07:22:52 +00:00
consumer = shmemq_new(name, true, &error);
2020-12-14 18:50:53 +00:00
assert(error == SHMEMQ_ERROR_NONE);
2020-12-15 07:22:52 +00:00
producer = shmemq_new(name, false, &error);
2020-12-14 18:50:53 +00:00
assert(error == SHMEMQ_ERROR_NONE);
assert(shmemq_pop_start(consumer) == NULL);
shmemq_pop_end(consumer, &error);
assert(error == SHMEMQ_ERROR_BUG_POP_END_ON_EMPTY_QUEUE);
2020-12-15 07:49:38 +00:00
return 0;
}
2020-12-14 18:50:53 +00:00
2020-12-15 07:49:38 +00:00
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);
}
}
2020-12-14 18:50:53 +00:00
2020-12-15 07:49:38 +00:00
void on_signal(const int signo __attribute__((unused)))
{
on_exit();
2020-12-14 18:50:53 +00:00
}