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

Add test "push_and_pop_one_frame_messages_without_jump"

This commit is contained in:
Alex Kotov 2020-12-15 16:06:18 +05:00
parent 65f1a89240
commit 4189552a86
Signed by: kotovalexarian
GPG key ID: 553C0EBBEB5D5F08
4 changed files with 104 additions and 1 deletions

1
.gitignore vendored
View file

@ -43,3 +43,4 @@
/tests/test_prod_jumps_to_buffer_start_and_reaches_cons
/tests/test_prod_pushes_too_long_message
/tests/test_prod_reaches_buffer_end
/tests/test_push_and_pop_one_frame_messages_without_jump

View file

@ -15,7 +15,8 @@ TESTS = \
tests/test_prod_jumps_to_buffer_start_and_pushes_too_long_message \
tests/test_prod_jumps_to_buffer_start_and_reaches_cons \
tests/test_prod_pushes_too_long_message \
tests/test_prod_reaches_buffer_end
tests/test_prod_reaches_buffer_end \
tests/test_push_and_pop_one_frame_messages_without_jump
noinst_PROGRAMS = \
$(TESTS) \
@ -59,3 +60,7 @@ tests_test_prod_pushes_too_long_message_SOURCES = \
tests_test_prod_reaches_buffer_end_SOURCES = \
$(libshmemq_a_SOURCES) \
tests/test_prod_reaches_buffer_end.c
tests_test_push_and_pop_one_frame_messages_without_jump_SOURCES = \
$(libshmemq_a_SOURCES) \
tests/test_push_and_pop_one_frame_messages_without_jump.c

View file

@ -257,6 +257,7 @@ ShmemqFrame shmemq_pop_start(const Shmemq shmemq)
return high_frame;
}
shmemq->buffer->header.read_frame_index = 0;
return low_frame;
}

View file

@ -0,0 +1,96 @@
#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 < 25; ++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);
}
for (unsigned i = 0; i < 25; ++i) {
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);
}
for (unsigned i = 25; i < 124; ++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_push_start(producer);
assert(frame == NULL);
}
for (unsigned i = 25; i < 124; ++i) {
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(producer);
assert(frame == NULL);
}
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();
}