1
0
mirror of git://sourceware.org/git/lvm2.git synced 2024-12-21 13:34:40 +03:00

tests: unit test for mirror status

This commit is contained in:
Zdenek Kabelac 2015-11-30 20:54:52 +01:00
parent fa87979004
commit c717ea5fc0
4 changed files with 77 additions and 2 deletions

View File

@ -1,4 +1,4 @@
# Copyright (C) 2011-2013 Red Hat, Inc. All rights reserved.
# Copyright (C) 2011-2015 Red Hat, Inc. All rights reserved.
#
# This file is part of LVM2.
#
@ -19,6 +19,7 @@ UNITS = \
bitset_t.c\
config_t.c\
dmlist_t.c\
dmstatus_t.c\
matcher_t.c\
string_t.c\
run.c
@ -40,7 +41,7 @@ CFLAGS += @CUNIT_CFLAGS@
check: unit
$(TARGETS): $(OBJECTS)
$(TARGETS): $(OBJECTS) $(top_builddir)/libdm/libdevmapper.$(LIB_SUFFIX)
unit: $(TARGETS)
@echo Running unit tests

72
test/unit/dmstatus_t.c Normal file
View File

@ -0,0 +1,72 @@
/*
* 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"
static struct dm_pool *_mem;
int dmstatus_init(void)
{
_mem = dm_pool_create("dmstatus test", 1024);
return (_mem == NULL);
}
int dmstatus_fini(void)
{
dm_pool_destroy(_mem);
return 0;
}
static void _test_mirror_status(void)
{
struct dm_status_mirror *s = NULL;
CU_ASSERT(dm_get_status_mirror(_mem,
"2 253:1 253:2 80/81 1 AD 3 disk 253:0 A",
&s));
if (s) {
CU_ASSERT_EQUAL(s->total_regions, 81);
CU_ASSERT_EQUAL(s->insync_regions, 80);
CU_ASSERT_EQUAL(s->dev_count, 2);
CU_ASSERT_EQUAL(s->devs[0].health, 'A');
CU_ASSERT_EQUAL(s->devs[0].major, 253);
CU_ASSERT_EQUAL(s->devs[0].minor, 1);
CU_ASSERT_EQUAL(s->devs[1].health, 'D');
CU_ASSERT_EQUAL(s->devs[1].major, 253);
CU_ASSERT_EQUAL(s->devs[1].minor, 2);
CU_ASSERT_EQUAL(s->log_count, 1);
CU_ASSERT_EQUAL(s->logs[0].major, 253);
CU_ASSERT_EQUAL(s->logs[0].minor, 0);
CU_ASSERT_EQUAL(s->logs[0].health, 'A');
CU_ASSERT(!strcmp(s->log_type, "disk"));
}
CU_ASSERT(dm_get_status_mirror(_mem,
"4 253:1 253:2 253:3 253:4 10/10 1 ADFF 1 core",
&s));
if (s) {
CU_ASSERT_EQUAL(s->total_regions, 10);
CU_ASSERT_EQUAL(s->insync_regions, 10);
CU_ASSERT_EQUAL(s->dev_count, 4);
CU_ASSERT_EQUAL(s->devs[3].minor, 4);
CU_ASSERT_EQUAL(s->devs[3].health, 'F');
CU_ASSERT_EQUAL(s->log_count, 0);
CU_ASSERT(!strcmp(s->log_type, "core"));
}
}
CU_TestInfo dmstatus_list[] = {
{ (char*)"mirror_status", _test_mirror_status },
CU_TEST_INFO_NULL
};

View File

@ -16,6 +16,7 @@ CU_SuiteInfo suites[] = {
USE(bitset),
USE(config),
USE(dmlist),
USE(dmstatus),
USE(regex),
USE(string),
CU_SUITE_INFO_NULL

View File

@ -26,6 +26,7 @@
DECL(bitset);
DECL(config);
DECL(dmlist);
DECL(dmstatus);
DECL(regex);
DECL(string);