master - tests: make unit testing usable again
Gitweb: http://git.fedorahosted.org/git/?p=lvm2.git;a=commitdiff;h=1fb8d746d62aa14c5ed18bb917b5b0d447d436ae Commit: 1fb8d746d62aa14c5ed18bb917b5b0d447d436ae Parent: ec647f1d431214264aaa396b6d0ba8e97738f00b Author: Zdenek Kabelac <[email protected]> AuthorDate: Fri Nov 27 10:54:57 2015 +0100 Committer: Zdenek Kabelac <[email protected]> CommitterDate: Fri Nov 27 11:22:21 2015 +0100
tests: make unit testing usable again
Make unit tests usable/compilable with newer header files. Add 'initial' dmlist_t for list tests.
More will come...
--- test/unit/Makefile.in | 13 +++++++++++-- test/unit/bitset_t.c | 6 +----- test/unit/config_t.c | 6 +----- test/unit/dmlist_t.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ test/unit/matcher_t.c | 17 +---------------- test/unit/run.c | 33 ++++++++++++++++++++------------- test/unit/string_t.c | 7 +------ test/unit/units.h | 32 ++++++++++++++++++++++++++++++++ 8 files changed, 116 insertions(+), 47 deletions(-)
test/unit/Makefile.in +11 -2
@@ -15,7 +15,15 @@ top_srcdir = @top_srcdir@ top_builddir = @top_builddir@ VPATH = $(srcdir) -UNITS = bitset_t.c matcher_t.c config_t.c string_t.c run.c +UNITS = \ + bitset_t.c\ + config_t.c\ + dmlist_t.c\ + matcher_t.c\ + string_t.c\ + run.c + +include $(top_builddir)/make.tmpl ifeq ($(MAKECMDGOALS),distclean) SOURCES = $(UNITS)
@@ -26,13 +34,14 @@ SOURCES = $(UNITS) TARGETS = run endif -include $(top_builddir)/make.tmpl ifeq ("$(TESTING)", "yes") LDLIBS += -ldevmapper @CUNIT_LIBS@ CFLAGS += @CUNIT_CFLAGS@ check: unit +$(TARGETS): $(OBJECTS) + unit: $(TARGETS) @echo Running unit tests LD_LIBRARY_PATH=$(top_builddir)/libdm ./$(TARGETS)
test/unit/bitset_t.c +1 -5
@@ -12,11 +12,7 @@* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "libdevmapper.h" -#include <CUnit/CUnit.h> - -int bitset_init (void ); -int bitset_fini (void ); +#include "units.h" enum {NR_BITS =137
test/unit/config_t.c +1 -5
@@ -12,11 +12,7 @@* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "libdevmapper.h" -#include <CUnit/CUnit.h> - -int config_init (void ); -int config_fini (void ); +#include "units.h" static struct dm_pool *mem;
test/unit/dmlist_t.c new file +49 -0
49 lines not on this page · raw message
test/unit/matcher_t.c +1 -16
@@ -13,24 +13,10 @@* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "libdevmapper.h" -#include "log.h" +#include "units.h" -#include <stdio.h> -#include <ctype.h> -#include <string.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <unistd.h> -#include <fcntl.h> -#include <sys/mman.h> - -#include <CUnit/CUnit.h> #include "matcher_data.h" -int regex_init (void ); -int regex_fini (void ); -static struct dm_pool *mem =NULL ;int regex_init (void ) {
@@ -82,4 +68,3 @@ CU_TestInfo regex_list[] = { { (char*)"matching", test_matching }, CU_TEST_INFO_NULL }; -
test/unit/run.c +20 -13
@@ -1,29 +1,36 @@ -#include <CUnit/CUnit.h> +#include "units.h" #include <CUnit/Basic.h> -#define DECL (n) \ - extern CU_TestInfo n ## _list[]; \ - int n ## _init(void); \ - int n ## _fini(void); -#define USE (n) { (char*) #n, n##_init, n##_fini, n##_list } +#include <stdio.h> +#include <stdlib.h> -DECL (bitset); -DECL (regex); -DECL (config); -DECL (string); +/* Setup SuiteInfo struct in a compatible way across different CUnit versions */ +/* old version of CUnit has used char* for .pName, so using cast here */ +#define USE (n) { \ + .pName = (char*) #n, \ + .pInitFunc = n##_init, \ + .pCleanupFunc = n##_fini, \ + .pTests = n##_list }CU_SuiteInfo suites[] = {USE (bitset), -USE (regex),USE (config), +USE (dmlist), +USE (regex),USE (string),CU_SUITE_INFO_NULL };int main (int argc,char **argv) { -CU_initialize_registry (); +if (CU_initialize_registry () !=CUE_SUCCESS ) { +printf ("Initialization of Test Registry failed.\n" ); +return CU_get_error (); + } +CU_register_suites (suites);CU_basic_set_mode (CU_BRM_VERBOSE );CU_basic_run_tests (); -return CU_get_number_of_failures () !=0 ; +CU_cleanup_registry (); + +return (CU_get_number_of_failures () !=0 ); }
test/unit/string_t.c +1 -6
@@ -12,16 +12,11 @@* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include "libdevmapper.h" +#include "units.h" #include <stdio.h> #include <string.h> -#include <CUnit/CUnit.h> - -int string_init (void ); -int string_fini (void ); -static struct dm_pool *mem =NULL ;int string_init (void )
test/unit/units.h new file +32 -0
@@ -0,0 +1,32 @@ +/* +* Copyright (C) 2015 Red Hat, Inc. All rights reserved. +* +* This file is part of LVM2. +* +* This copyrighted material is made available to anyone wishing to use, +* modify, copy, or redistribute it subject to the terms and conditions +* of the GNU General Public License v.2. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software Foundation, +* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +#ifndef _UNITS_H +#define _UNITS_H + +#include "libdevmapper.h" +#include <CUnit/CUnit.h> + +#define DECL (n) \ + extern CU_TestInfo n ## _list[];\ + int n ## _init(void); \ + int n ## _fini(void); + +DECL (bitset); +DECL (config); +DECL (dmlist); +DECL (regex); +DECL (string); + +#endif