Add test "prod_pushes_too_long_message"

This commit is contained in:
Alex Kotov 2020-12-15 13:55:22 +05:00
parent 19dff0680d
commit 65f1a89240
Signed by: kotovalexarian
GPG Key ID: 553C0EBBEB5D5F08
4 changed files with 75 additions and 4 deletions

1
.gitignore vendored
View File

@ -41,4 +41,5 @@
/tests/test_cons_reaches_queue_end
/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

View File

@ -14,6 +14,7 @@ TESTS = \
tests/test_cons_reaches_queue_end \
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
noinst_PROGRAMS = \
@ -51,6 +52,10 @@ tests_test_prod_jumps_to_buffer_start_and_reaches_cons_SOURCES = \
$(libshmemq_a_SOURCES) \
tests/test_prod_jumps_to_buffer_start_and_reaches_cons.c
tests_test_prod_pushes_too_long_message_SOURCES = \
$(libshmemq_a_SOURCES) \
tests/test_prod_pushes_too_long_message.c
tests_test_prod_reaches_buffer_end_SOURCES = \
$(libshmemq_a_SOURCES) \
tests/test_prod_reaches_buffer_end.c

View File

@ -222,10 +222,13 @@ void shmemq_push_end(
frame->header.message_frames_count;
if (
shmemq->buffer->header.write_frame_index <
shmemq->buffer->header.read_frame_index &&
new_write_frame_index >=
shmemq->buffer->header.read_frame_index
new_write_frame_index >
shmemq->buffer->header.frames_count || (
shmemq->buffer->header.write_frame_index <
shmemq->buffer->header.read_frame_index &&
new_write_frame_index >=
shmemq->buffer->header.read_frame_index
)
) {
if (error_ptr) *error_ptr = SHMEMQ_ERROR_BUG_PUSH_END_OVERFLOW;
return;

View File

@ -0,0 +1,62 @@
#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 < 99; ++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);
shmemq_push_end(producer, 9, &error);
assert(error == SHMEMQ_ERROR_BUG_PUSH_END_OVERFLOW);
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();
}