1
0
mirror of git://sourceware.org/git/lvm2.git synced 2025-01-02 01:18:26 +03:00

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...
This commit is contained in:
Zdenek Kabelac 2015-11-27 10:54:57 +01:00
parent ec647f1d43
commit 1fb8d746d6
8 changed files with 116 additions and 47 deletions

View File

@ -15,7 +15,15 @@ top_srcdir = @top_srcdir@
top_builddir = @top_builddir@ top_builddir = @top_builddir@
VPATH = $(srcdir) 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) ifeq ($(MAKECMDGOALS),distclean)
SOURCES = $(UNITS) SOURCES = $(UNITS)
@ -26,13 +34,14 @@ SOURCES = $(UNITS)
TARGETS = run TARGETS = run
endif endif
include $(top_builddir)/make.tmpl
ifeq ("$(TESTING)", "yes") ifeq ("$(TESTING)", "yes")
LDLIBS += -ldevmapper @CUNIT_LIBS@ LDLIBS += -ldevmapper @CUNIT_LIBS@
CFLAGS += @CUNIT_CFLAGS@ CFLAGS += @CUNIT_CFLAGS@
check: unit check: unit
$(TARGETS): $(OBJECTS)
unit: $(TARGETS) unit: $(TARGETS)
@echo Running unit tests @echo Running unit tests
LD_LIBRARY_PATH=$(top_builddir)/libdm ./$(TARGETS) LD_LIBRARY_PATH=$(top_builddir)/libdm ./$(TARGETS)

View File

@ -12,11 +12,7 @@
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#include "libdevmapper.h" #include "units.h"
#include <CUnit/CUnit.h>
int bitset_init(void);
int bitset_fini(void);
enum { enum {
NR_BITS = 137 NR_BITS = 137

View File

@ -12,11 +12,7 @@
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#include "libdevmapper.h" #include "units.h"
#include <CUnit/CUnit.h>
int config_init(void);
int config_fini(void);
static struct dm_pool *mem; static struct dm_pool *mem;

49
test/unit/dmlist_t.c Normal file
View File

@ -0,0 +1,49 @@
/*
* 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
*/
#include "units.h"
int dmlist_init(void)
{
return 0;
}
int dmlist_fini(void)
{
return 0;
}
static void test_dmlist_splice(void)
{
struct dm_list a[10];
struct dm_list list1;
struct dm_list list2;
unsigned i;
dm_list_init(&list1);
dm_list_init(&list2);
for (i = 0; i < DM_ARRAY_SIZE(a); i++)
dm_list_add(&list1, &a[i]);
dm_list_splice(&list2, &list1);
CU_ASSERT_EQUAL(dm_list_size(&list1), 0);
CU_ASSERT_EQUAL(dm_list_size(&list2), 10);
}
CU_TestInfo dmlist_list[] = {
{ (char*)"dmlist_splice", test_dmlist_splice },
//{ (char*)"dmlist", test_strncpy },
CU_TEST_INFO_NULL
};

View File

@ -13,24 +13,10 @@
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#include "libdevmapper.h" #include "units.h"
#include "log.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" #include "matcher_data.h"
int regex_init(void);
int regex_fini(void);
static struct dm_pool *mem = NULL; static struct dm_pool *mem = NULL;
int regex_init(void) { int regex_init(void) {
@ -82,4 +68,3 @@ CU_TestInfo regex_list[] = {
{ (char*)"matching", test_matching }, { (char*)"matching", test_matching },
CU_TEST_INFO_NULL CU_TEST_INFO_NULL
}; };

View File

@ -1,29 +1,36 @@
#include <CUnit/CUnit.h> #include "units.h"
#include <CUnit/Basic.h> #include <CUnit/Basic.h>
#define DECL(n) \ #include <stdio.h>
extern CU_TestInfo n ## _list[]; \ #include <stdlib.h>
int n ## _init(void); \
int n ## _fini(void);
#define USE(n) { (char*) #n, n##_init, n##_fini, n##_list }
DECL(bitset); /* Setup SuiteInfo struct in a compatible way across different CUnit versions */
DECL(regex); /* old version of CUnit has used char* for .pName, so using cast here */
DECL(config); #define USE(n) { \
DECL(string); .pName = (char*) #n, \
.pInitFunc = n##_init, \
.pCleanupFunc = n##_fini, \
.pTests = n##_list }
CU_SuiteInfo suites[] = { CU_SuiteInfo suites[] = {
USE(bitset), USE(bitset),
USE(regex),
USE(config), USE(config),
USE(dmlist),
USE(regex),
USE(string), USE(string),
CU_SUITE_INFO_NULL CU_SUITE_INFO_NULL
}; };
int main(int argc, char **argv) { 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_register_suites(suites);
CU_basic_set_mode(CU_BRM_VERBOSE); CU_basic_set_mode(CU_BRM_VERBOSE);
CU_basic_run_tests(); CU_basic_run_tests();
return CU_get_number_of_failures() != 0; CU_cleanup_registry();
return (CU_get_number_of_failures() != 0);
} }

View File

@ -12,16 +12,11 @@
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/ */
#include "libdevmapper.h" #include "units.h"
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <CUnit/CUnit.h>
int string_init(void);
int string_fini(void);
static struct dm_pool *mem = NULL; static struct dm_pool *mem = NULL;
int string_init(void) int string_init(void)

32
test/unit/units.h Normal file
View File

@ -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