From c5cd139bd5a29d6f47b160b995ceda448f986484 Mon Sep 17 00:00:00 2001 From: Pawel Dziepak Date: Fri, 6 Dec 2013 17:08:12 +0100 Subject: [PATCH] Add test infrastructure and a single thread test for spsc_queue Signed-off-by: Pawel Dziepak --- .gitignore | 5 ++++ Makefile.am | 2 +- configure.ac | 1 + test/Makefile.am | 14 +++++++++ test/spsc_queue_s.c | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 test/Makefile.am create mode 100644 test/spsc_queue_s.c diff --git a/.gitignore b/.gitignore index 1ab2e5e..70a3d0d 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,10 @@ *.[ao] *.l[ao] *.swp +*.log +*.trs + +/test/spsc_queue_s /aclocal.m4 /autom4te.cache/ @@ -21,3 +25,4 @@ Makefile Makefile.in /missing /stamp-h1 +test-driver diff --git a/Makefile.am b/Makefile.am index b9ab1dc..00b199f 100644 --- a/Makefile.am +++ b/Makefile.am @@ -3,4 +3,4 @@ # Copyright (C) 2013 Paweł Dziepak ACLOCAL_AMFLAGS = -I m4 -SUBDIRS = src +SUBDIRS = src test diff --git a/configure.ac b/configure.ac index a1fb0e4..ce236c0 100644 --- a/configure.ac +++ b/configure.ac @@ -51,6 +51,7 @@ fi AC_CONFIG_FILES([ Makefile src/Makefile + test/Makefile ]) AC_OUTPUT diff --git a/test/Makefile.am b/test/Makefile.am new file mode 100644 index 0000000..2be54bd --- /dev/null +++ b/test/Makefile.am @@ -0,0 +1,14 @@ +# libnbds +# +# Copyright (C) 2013 Paweł Dziepak + +AUTOMAKE_OPTIONS = 1.4 foreign + +AM_CFLAGS = -Wall -Wextra -Werror -pedantic --std=gnu99 -I../src +LDADD = ../src/libnbds.la + +TESTS = spsc_queue_s + +check_PROGRAMS = $(TESTS) + +spsc_queue_s_SOURCES = spsc_queue_s.c diff --git a/test/spsc_queue_s.c b/test/spsc_queue_s.c new file mode 100644 index 0000000..d830bc7 --- /dev/null +++ b/test/spsc_queue_s.c @@ -0,0 +1,83 @@ +/* + libnbds + Copyright (C) 2013 Paweł Dziepak + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include + +#include "spsc_queue.h" + +struct spsc_queue queue; + +int main(int argc, char** argv) +{ + uintptr_t i; + int error; + + (void)argc; + (void)argv; + + error = spsc_queue_init(&queue); + if (error) + return 1; + + if (spsc_queue_dequeue(&queue)) + return 1; + + for (i = 1; i < 1024u; i++) { + error = spsc_queue_enqueue(&queue, (void*)i); + if (error) + return 1; + } + + for (i = 1; i < 1024u; i++) { + if ((uintptr_t)spsc_queue_dequeue(&queue) != i) + return 1; + } + + if (spsc_queue_dequeue(&queue)) + return 1; + + for (i = 1; i < 1024u; i++) { + spsc_queue_enqueue(&queue, (void*)i); + if ((uintptr_t)spsc_queue_dequeue(&queue) != i) + return 1; + } + + if (spsc_queue_dequeue(&queue)) + return 1; + + spsc_queue_destroy(&queue); + error = spsc_queue_init(&queue); + if (error) + return 1; + + for (i = 1; i < 1024u; i++) { + error = spsc_queue_enqueue(&queue, (void*)i); + if (error) + return 1; + } + + spsc_queue_destroy(&queue); + error = spsc_queue_init(&queue); + if (error) + return 1; + + if (spsc_queue_dequeue(&queue)) + return 1; + + spsc_queue_destroy(&queue); +} -- 2.11.4.GIT