|
Packit Service |
360c39 |
#include <check.h>
|
|
Packit Service |
360c39 |
#include <libgfs2.h>
|
|
Packit Service |
360c39 |
#include <rgrp.h> /* Private header libgfs2/rgrp.h for convenience */
|
|
Packit Service |
360c39 |
|
|
Packit Service |
360c39 |
// TODO: Remove this when the extern is removed from libgfs2
|
|
Packit Service |
360c39 |
void print_it(const char *label, const char *fmt, const char *fmt2, ...) {}
|
|
Packit Service |
360c39 |
|
|
Packit Service |
360c39 |
static lgfs2_rgrps_t mockup_rgrp(void)
|
|
Packit Service |
360c39 |
{
|
|
Packit Service |
360c39 |
struct gfs2_sbd *sdp;
|
|
Packit Service |
360c39 |
lgfs2_rgrps_t rgs;
|
|
Packit Service |
360c39 |
unsigned i;
|
|
Packit Service |
360c39 |
uint64_t addr;
|
|
Packit Service |
360c39 |
struct gfs2_rindex ri = {0};
|
|
Packit Service |
360c39 |
lgfs2_rgrp_t rg;
|
|
Packit Service |
360c39 |
uint32_t rgsize = (1024 << 20) / 4096;
|
|
Packit Service |
360c39 |
|
|
Packit Service |
360c39 |
sdp = calloc(1, sizeof(*sdp));
|
|
Packit Service |
360c39 |
fail_unless(sdp != NULL);
|
|
Packit Service |
360c39 |
|
|
Packit Service |
360c39 |
sdp->device.length = rgsize + 20;
|
|
Packit Service |
360c39 |
sdp->device_fd = -1;
|
|
Packit Service |
360c39 |
sdp->bsize = sdp->sd_sb.sb_bsize = 4096;
|
|
Packit Service |
360c39 |
compute_constants(sdp);
|
|
Packit Service |
360c39 |
|
|
Packit Service |
360c39 |
rgs = lgfs2_rgrps_init(sdp, 0, 0);
|
|
Packit Service |
360c39 |
fail_unless(rgs != NULL);
|
|
Packit Service |
360c39 |
|
|
Packit Service |
360c39 |
lgfs2_rgrps_plan(rgs, sdp->device.length - 16, rgsize);
|
|
Packit Service |
360c39 |
|
|
Packit Service |
360c39 |
addr = lgfs2_rindex_entry_new(rgs, &ri, 16, rgsize);
|
|
Packit Service |
360c39 |
ck_assert(addr != 0);
|
|
Packit Service |
360c39 |
|
|
Packit Service |
360c39 |
rg = lgfs2_rgrps_append(rgs, &ri, 0);
|
|
Packit Service |
360c39 |
fail_unless(rg != NULL);
|
|
Packit Service |
360c39 |
|
|
Packit Service |
360c39 |
for (i = 0; i < rg->ri.ri_length; i++) {
|
|
Packit Service |
360c39 |
rg->bits[i].bi_bh = bget(sdp, rg->ri.ri_addr + i);
|
|
Packit Service |
360c39 |
fail_unless(rg->bits[i].bi_bh != NULL);
|
|
Packit Service |
360c39 |
}
|
|
Packit Service |
360c39 |
return rgs;
|
|
Packit Service |
360c39 |
}
|
|
Packit Service |
360c39 |
|
|
Packit Service |
360c39 |
START_TEST(test_mockup_rgrp)
|
|
Packit Service |
360c39 |
{
|
|
Packit Service |
360c39 |
lgfs2_rgrps_t rgs = mockup_rgrp();
|
|
Packit Service |
360c39 |
fail_unless(rgs != NULL);
|
|
Packit Service |
360c39 |
}
|
|
Packit Service |
360c39 |
END_TEST
|
|
Packit Service |
360c39 |
|
|
Packit Service |
360c39 |
START_TEST(test_rbm_find_good)
|
|
Packit Service |
360c39 |
{
|
|
Packit Service |
360c39 |
uint32_t minext;
|
|
Packit Service |
360c39 |
struct lgfs2_rbm rbm = {0};
|
|
Packit Service |
360c39 |
lgfs2_rgrps_t rgs = mockup_rgrp();
|
|
Packit Service |
360c39 |
rbm.rgd = lgfs2_rgrp_first(rgs);
|
|
Packit Service |
360c39 |
|
|
Packit Service |
360c39 |
/* Check that extent sizes up to the whole rg can be found */
|
|
Packit Service |
360c39 |
for (minext = 1; minext <= rbm.rgd->ri.ri_data; minext++) {
|
|
Packit Service |
360c39 |
int err;
|
|
Packit Service |
360c39 |
uint64_t addr;
|
|
Packit Service |
360c39 |
|
|
Packit Service |
360c39 |
rbm.offset = rbm.bii = 0;
|
|
Packit Service |
360c39 |
|
|
Packit Service |
360c39 |
err = lgfs2_rbm_find(&rbm, GFS2_BLKST_FREE, &minext);
|
|
Packit Service |
360c39 |
ck_assert_int_eq(err, 0);
|
|
Packit Service |
360c39 |
|
|
Packit Service |
360c39 |
addr = lgfs2_rbm_to_block(&rbm;;
|
|
Packit Service |
360c39 |
fail_unless(addr == rbm.rgd->ri.ri_data0);
|
|
Packit Service |
360c39 |
}
|
|
Packit Service |
360c39 |
}
|
|
Packit Service |
360c39 |
END_TEST
|
|
Packit Service |
360c39 |
|
|
Packit Service |
360c39 |
START_TEST(test_rbm_find_bad)
|
|
Packit Service |
360c39 |
{
|
|
Packit Service |
360c39 |
int err;
|
|
Packit Service |
360c39 |
uint32_t minext;
|
|
Packit Service |
360c39 |
struct lgfs2_rbm rbm = {0};
|
|
Packit Service |
360c39 |
lgfs2_rgrps_t rgs = mockup_rgrp();
|
|
Packit Service |
360c39 |
|
|
Packit Service |
360c39 |
rbm.rgd = lgfs2_rgrp_first(rgs);
|
|
Packit Service |
360c39 |
minext = rbm.rgd->ri.ri_data + 1;
|
|
Packit Service |
360c39 |
|
|
Packit Service |
360c39 |
err = lgfs2_rbm_find(&rbm, GFS2_BLKST_FREE, &minext);
|
|
Packit Service |
360c39 |
ck_assert_int_eq(err, 1);
|
|
Packit Service |
360c39 |
}
|
|
Packit Service |
360c39 |
END_TEST
|
|
Packit Service |
360c39 |
|
|
Packit Service |
360c39 |
START_TEST(test_rbm_find_lastblock)
|
|
Packit Service |
360c39 |
{
|
|
Packit Service |
360c39 |
int err;
|
|
Packit Service |
360c39 |
unsigned i;
|
|
Packit Service |
360c39 |
uint64_t addr;
|
|
Packit Service |
360c39 |
uint32_t minext = 1; /* Only looking for one block */
|
|
Packit Service |
360c39 |
struct lgfs2_rbm rbm = {0};
|
|
Packit Service |
360c39 |
lgfs2_rgrp_t rg;
|
|
Packit Service |
360c39 |
lgfs2_rgrps_t rgs = mockup_rgrp();
|
|
Packit Service |
360c39 |
|
|
Packit Service |
360c39 |
rbm.rgd = rg = lgfs2_rgrp_first(rgs);
|
|
Packit Service |
360c39 |
|
|
Packit Service |
360c39 |
/* Flag all blocks as allocated... */
|
|
Packit Service |
360c39 |
for (i = 0; i < rg->ri.ri_length; i++)
|
|
Packit Service |
360c39 |
memset(rg->bits[i].bi_bh->b_data, 0xff, rgs->sdp->bsize);
|
|
Packit Service |
360c39 |
|
|
Packit Service |
360c39 |
/* ...except the final one */
|
|
Packit Service |
360c39 |
err = gfs2_set_bitmap(rg, rg->ri.ri_data0 + rg->ri.ri_data - 1, GFS2_BLKST_FREE);
|
|
Packit Service |
360c39 |
ck_assert_int_eq(err, 0);
|
|
Packit Service |
360c39 |
|
|
Packit Service |
360c39 |
err = lgfs2_rbm_find(&rbm, GFS2_BLKST_FREE, &minext);
|
|
Packit Service |
360c39 |
ck_assert_int_eq(err, 0);
|
|
Packit Service |
360c39 |
|
|
Packit Service |
360c39 |
addr = lgfs2_rbm_to_block(&rbm;;
|
|
Packit Service |
360c39 |
fail_unless(addr == (rg->ri.ri_data0 + rg->ri.ri_data - 1));
|
|
Packit Service |
360c39 |
}
|
|
Packit Service |
360c39 |
END_TEST
|
|
Packit Service |
360c39 |
|
|
Packit Service |
360c39 |
static Suite * libgfs2_suite(void)
|
|
Packit Service |
360c39 |
{
|
|
Packit Service |
360c39 |
|
|
Packit Service |
360c39 |
Suite *s = suite_create("libgfs2");
|
|
Packit Service |
360c39 |
|
|
Packit Service |
360c39 |
TCase *tc_rgrp = tcase_create("rgrp");
|
|
Packit Service |
360c39 |
|
|
Packit Service |
360c39 |
tcase_add_test(tc_rgrp, test_mockup_rgrp);
|
|
Packit Service |
360c39 |
tcase_add_test(tc_rgrp, test_rbm_find_good);
|
|
Packit Service |
360c39 |
tcase_add_test(tc_rgrp, test_rbm_find_bad);
|
|
Packit Service |
360c39 |
tcase_add_test(tc_rgrp, test_rbm_find_lastblock);
|
|
Packit Service |
360c39 |
tcase_set_timeout(tc_rgrp, 0);
|
|
Packit Service |
360c39 |
suite_add_tcase(s, tc_rgrp);
|
|
Packit Service |
360c39 |
|
|
Packit Service |
360c39 |
return s;
|
|
Packit Service |
360c39 |
}
|
|
Packit Service |
360c39 |
|
|
Packit Service |
360c39 |
int main(void)
|
|
Packit Service |
360c39 |
{
|
|
Packit Service |
360c39 |
int failures;
|
|
Packit Service |
360c39 |
Suite *s = libgfs2_suite();
|
|
Packit Service |
360c39 |
SRunner *sr = srunner_create(s);
|
|
Packit Service |
360c39 |
srunner_run_all(sr, CK_NORMAL);
|
|
Packit Service |
360c39 |
failures = srunner_ntests_failed(sr);
|
|
Packit Service |
360c39 |
srunner_free(sr);
|
|
Packit Service |
360c39 |
return failures ? EXIT_FAILURE : EXIT_SUCCESS;
|
|
Packit Service |
360c39 |
}
|