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

Add test "alternatively_push_and_pop_one_frame_messages_with_jump"

This commit is contained in:
Alex Kotov 2020-12-15 16:22:05 +05:00
parent 4189552a86
commit c64e5053d4
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08
3 changed files with 95 additions and 0 deletions

1
.gitignore vendored
View file

@ -37,6 +37,7 @@
/examples/raw_receiver
/examples/raw_sender
/tests/test_main
/tests/test_alternatively_push_and_pop_one_frame_messages_with_jump
/tests/test_cons_pops_buffer_start
/tests/test_cons_reaches_queue_end
/tests/test_prod_jumps_to_buffer_start_and_pushes_too_long_message

View file

@ -10,6 +10,7 @@ lib_LIBRARIES = libshmemq.a
TESTS = \
tests/test_main \
tests/test_alternatively_push_and_pop_one_frame_messages_with_jump \
tests/test_cons_pops_buffer_start \
tests/test_cons_reaches_queue_end \
tests/test_prod_jumps_to_buffer_start_and_pushes_too_long_message \
@ -33,6 +34,10 @@ examples_raw_sender_SOURCES = \
$(libshmemq_a_SOURCES) \
examples/raw_sender.c
tests_test_alternatively_push_and_pop_one_frame_messages_with_jump_SOURCES = \
$(libshmemq_a_SOURCES) \
tests/test_alternatively_push_and_pop_one_frame_messages_with_jump.c
tests_test_main_SOURCES = \
$(libshmemq_a_SOURCES) \
tests/test_main.c

View file

@ -0,0 +1,89 @@
#include <shmemq.h>
#include <assert.h>
#include <signal.h>
#include <stdlib.h>
static const char name[] = "/foobar";
static ShmemqError error = SHMEMQ_ERROR_NONE;
static Shmemq consumer = NULL;
static Shmemq producer = NULL;
static void on_exit();
static void on_signal(int signo);
int main()
{
atexit(on_exit);
signal(SIGABRT, on_signal);
consumer = shmemq_new(name, true, &error);
assert(error == SHMEMQ_ERROR_NONE);
producer = shmemq_new(name, false, &error);
assert(error == SHMEMQ_ERROR_NONE);
for (unsigned i = 0; i < 125; ++i) {
{
const ShmemqFrame frame = shmemq_push_start(producer);
assert(frame != NULL);
*(unsigned*)frame->data = i;
shmemq_push_end(producer, sizeof(unsigned), &error);
assert(error == SHMEMQ_ERROR_NONE);
}
{
const ShmemqFrame frame = shmemq_pop_start(consumer);
assert(frame != NULL);
assert(*(unsigned*)frame->data == i);
shmemq_pop_end(consumer, &error);
assert(error == SHMEMQ_ERROR_NONE);
}
}
{
const ShmemqFrame frame = shmemq_pop_start(consumer);
assert(frame == NULL);
}
{
const ShmemqFrame frame = shmemq_push_start(producer);
assert(frame != NULL);
shmemq_push_end(producer, 77 * SHMEMQ_FRAME_SIZE, &error);
assert(error == SHMEMQ_ERROR_BUG_PUSH_END_OVERFLOW);
}
{
const ShmemqFrame frame = shmemq_push_start(producer);
assert(frame != NULL);
shmemq_push_end(producer, 76 * SHMEMQ_FRAME_SIZE, &error);
assert(error == SHMEMQ_ERROR_NONE);
}
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();
}