Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ea8960c

Browse files
committedJan 7, 2020
test:improve coverage of brick
Signed-off-by: hanen mizouni <hanen.mizouni@outscale.com>
1 parent a99f224 commit ea8960c

File tree

3 files changed

+189
-8
lines changed

3 files changed

+189
-8
lines changed
 

‎src/brick-int.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ struct pg_brick *pg_brick_decref(struct pg_brick *brick,
207207
int pg_brick_reset(struct pg_brick *brick, struct pg_error **errp);
208208

209209
/* testing */
210-
uint32_t pg_brick_links_count_get(const struct pg_brick *brick,
210+
int pg_brick_links_count_get(const struct pg_brick *brick,
211211
const struct pg_brick *target,
212212
struct pg_error **errp);
213213
int64_t pg_brick_refcount(const struct pg_brick *brick);

‎src/brick.c

+4-3
Original file line numberDiff line numberDiff line change
@@ -321,17 +321,17 @@ static uint16_t count_side(const struct pg_brick_side *side,
321321
* @param errp a return pointer for an error message
322322
* @return the total number of link from the brick to the target
323323
*/
324-
uint32_t pg_brick_links_count_get(const struct pg_brick *brick,
324+
int pg_brick_links_count_get(const struct pg_brick *brick,
325325
const struct pg_brick *target,
326326
struct pg_error **errp)
327327
{
328-
uint32_t count = 0;
328+
int count = 0;
329329
enum pg_side i;
330330
const struct pg_brick_side *side;
331331

332332
if (!brick) {
333333
*errp = pg_error_new("brick is NULL");
334-
return 0;
334+
return -1;
335335
}
336336

337337
if (brick->type == PG_MULTIPOLE) {
@@ -349,6 +349,7 @@ uint32_t pg_brick_links_count_get(const struct pg_brick *brick,
349349
if (side->edge.link && side->edge.link == target)
350350
++count;
351351
} else {
352+
*errp = pg_error_new("brick config type is unknown");
352353
return -1;
353354
}
354355

‎tests/core/test-core.c

+184-4
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,52 @@ static void test_brick_core_simple_lifecycle(void)
3030
{
3131
struct pg_error *error = NULL;
3232
struct pg_brick *brick;
33-
struct pg_brick_config *config = pg_brick_config_new("mybrick", 2, 2,
34-
PG_MULTIPOLE);
33+
struct pg_brick_config *config = pg_brick_config_new("mybrick", 2, 2, PG_MULTIPOLE);
34+
struct pg_brick_config *config1 = pg_brick_config_new("mybrick", 2, 2, PG_MONOPOLE);
35+
struct pg_brick_config *config2 = pg_brick_config_new("mybrick", UINT16_MAX, UINT16_MAX, PG_MULTIPOLE);
36+
37+
brick = pg_brick_new("nop", config1, &error);
38+
g_assert(!brick);
39+
g_assert(error);
40+
g_assert(error->message);
41+
g_assert_cmpstr(error->message, ==, "A 'PG_MONOPOLE' cannot have more than one neibour per side");
42+
pg_error_free(error);
43+
error = NULL;
44+
45+
brick = pg_brick_new("nop", config2, &error);
46+
g_assert(!brick);
47+
g_assert(error);
48+
g_assert(error->message);
49+
g_assert_cmpstr(error->message, ==, "A 'PG_MULTIPOLE' cannot have more than 65535 edge on PG_WEST_SIDE");
50+
pg_error_free(error);
51+
error = NULL;
52+
53+
brick = pg_brick_new(NULL, NULL, &error);
54+
g_assert(!brick);
55+
g_assert(error);
56+
g_assert(error->message);
57+
g_assert_cmpstr(error->message, ==, "Brick config not set");
58+
pg_error_free(error);
59+
error = NULL;
60+
61+
brick = pg_brick_new(NULL, config, &error);
62+
g_assert(!brick);
63+
g_assert(error);
64+
g_assert(error->message);
65+
g_assert_cmpstr(error->message, ==, "Brick name not set");
66+
pg_error_free(error);
67+
error = NULL;
68+
69+
pg_brick_decref(brick, &error);
70+
g_assert(error);
71+
g_assert(error->message);
72+
g_assert_cmpstr(error->message, ==, "NULL brick");
73+
pg_error_free(error);error = NULL;
74+
75+
g_assert(pg_brick_reset(brick,&error) < 0);
76+
g_assert(error);
77+
pg_error_free(error);
78+
error = NULL;
3579

3680
brick = pg_brick_new("foo", config, &error);
3781
g_assert(!brick);
@@ -44,9 +88,11 @@ static void test_brick_core_simple_lifecycle(void)
4488
brick = pg_brick_new("nop", config, &error);
4589
g_assert(brick);
4690
g_assert(!error);
91+
printf("brick refcount is %ld\n",brick->refcount);
4792

4893
pg_brick_decref(brick, &error);
4994
g_assert(!error);
95+
printf("brick refcount is %ld\n",brick->refcount);
5096

5197
brick = pg_brick_decref(NULL, &error);
5298
g_assert(!brick);
@@ -107,6 +153,11 @@ static void test_brick_core_link(void)
107153
g_assert(middle_brick);
108154
g_assert(!error);
109155

156+
g_assert(pg_brick_reset(middle_brick,&error)!=0);
157+
g_assert(error);
158+
pg_error_free(error);
159+
error = NULL;
160+
110161
east_brick = pg_brick_new("nop", config, &error);
111162
g_assert(east_brick);
112163
g_assert(!error);
@@ -180,6 +231,22 @@ static void test_brick_core_unlink_edge(void)
180231
g_assert(ret == 0);
181232
g_assert(!error);
182233

234+
ret = pg_brick_link(west_brick, west_brick, &error);
235+
g_assert(ret == -1);
236+
g_assert(error);
237+
g_assert(error->message);
238+
g_assert_cmpstr(error->message, ==, "Can not link a brick to itself");
239+
pg_error_free(error);
240+
error = NULL;
241+
242+
ret = pg_brick_link(NULL, west_brick, &error);
243+
g_assert(ret == -1);
244+
g_assert(error);
245+
g_assert(error->message);
246+
g_assert_cmpstr(error->message, ==, "Node is not valid");
247+
pg_error_free(error);
248+
error = NULL;
249+
183250
ret = pg_brick_link(middle_brick, east_brick, &error);
184251
g_assert(ret == 0);
185252
g_assert(!error);
@@ -199,6 +266,14 @@ static void test_brick_core_unlink_edge(void)
199266
g_assert(error);
200267
pg_error_free(error);
201268
error = NULL;
269+
g_assert(pg_brick_unlink_edge(east_brick, NULL, &error) == -1);
270+
g_assert(error);
271+
pg_error_free(error);
272+
error = NULL;
273+
g_assert(pg_brick_unlink_edge(NULL, west_brick, &error) == -1);
274+
g_assert(error);
275+
pg_error_free(error);
276+
error = NULL;
202277

203278
g_assert(!pg_brick_unlink_edge(west_brick, middle_brick, &error));
204279
refcount = pg_brick_refcount(west_brick);
@@ -628,9 +703,19 @@ static void test_brick_sanity_check_expected(struct pg_brick *brick,
628703

629704
static void test_brick_core_verify_multiple_link(void)
630705
{
631-
struct pg_brick *west_brick, *middle_brick, *east_brick;
706+
struct pg_brick *west_brick, *middle_brick, *east_brick,
707+
*west_brick1, *middle_brick1, *east_brick1,
708+
*west_brick2, *middle_brick2, *east_brick2,
709+
*west_brick3, *middle_brick3, *east_brick3;
710+
632711
struct pg_brick_config *config = pg_brick_config_new("mybrick", 4, 4,
633712
PG_MULTIPOLE);
713+
struct pg_brick_config *config1 = pg_brick_config_new("mybrick", 1, 1,
714+
PG_DIPOLE);
715+
struct pg_brick_config *config2 = pg_brick_config_new("mybrick", 1, 1,
716+
PG_MONOPOLE);
717+
struct pg_brick_config *config3 = pg_brick_config_new("mybrick", 1, 1,
718+
4);
634719
uint32_t links_count;
635720
struct pg_error *error = NULL;
636721

@@ -641,6 +726,27 @@ static void test_brick_core_verify_multiple_link(void)
641726
east_brick = pg_brick_new("nop", config, &error);
642727
g_assert(!error);
643728

729+
west_brick1 = pg_brick_new("nop", config1, &error);
730+
g_assert(!error);
731+
middle_brick1 = pg_brick_new("nop", config1, &error);
732+
g_assert(!error);
733+
east_brick1 = pg_brick_new("nop", config1, &error);
734+
g_assert(!error);
735+
736+
west_brick2 = pg_brick_new("nop", config2, &error);
737+
g_assert(!error);
738+
middle_brick2 = pg_brick_new("nop", config2, &error);
739+
g_assert(!error);
740+
east_brick2 = pg_brick_new("nop", config2, &error);
741+
g_assert(!error);
742+
743+
west_brick3 = pg_brick_new("nop", config3, &error);
744+
g_assert(!error);
745+
middle_brick3 = pg_brick_new("nop", config3, &error);
746+
g_assert(!error);
747+
east_brick3 = pg_brick_new("nop", config3, &error);
748+
g_assert(!error);
749+
644750
/* create a few links */
645751
pg_brick_link(west_brick, middle_brick, &error);
646752
g_assert(!error);
@@ -652,13 +758,61 @@ static void test_brick_core_verify_multiple_link(void)
652758
g_assert(!error);
653759
pg_brick_link(middle_brick, east_brick, &error);
654760
g_assert(!error);
761+
pg_brick_link(middle_brick1, east_brick1, &error);
762+
g_assert(!error);
763+
pg_brick_link(middle_brick2, east_brick2, &error);
764+
g_assert(!error);
765+
766+
pg_brick_link(middle_brick1, west_brick1, &error);
767+
g_assert(error);
768+
pg_error_free(error);
769+
error = NULL;
770+
771+
pg_brick_link(middle_brick2, west_brick2, &error);
772+
g_assert(error);
773+
pg_error_free(error);
774+
error = NULL;
655775

776+
pg_brick_link(middle_brick3, west_brick3, &error);
777+
g_assert(error);
778+
pg_error_free(error);
779+
error = NULL;
780+
781+
pg_brick_link(west_brick3, middle_brick3, &error);
782+
g_assert(error);
783+
pg_error_free(error);
784+
error = NULL;
785+
656786
/* sanity checks */
657787
test_brick_sanity_check(west_brick);
658788
test_brick_sanity_check(middle_brick);
659789
test_brick_sanity_check(east_brick);
660790

661-
/* check the link count */
791+
/* check the link count */
792+
links_count = pg_brick_links_count_get(NULL, west_brick, &error);
793+
g_assert(error);
794+
g_assert(links_count == (uint32_t) -1);
795+
g_assert(error->message);
796+
g_assert_cmpstr(error->message, ==, "brick is NULL");
797+
pg_error_free(error);
798+
error = NULL;
799+
800+
links_count = pg_brick_links_count_get(middle_brick3, west_brick3, &error);
801+
g_assert(error);
802+
g_assert(links_count == (uint32_t)-1);
803+
g_assert(error->message);
804+
g_assert_cmpstr(error->message, ==, "brick config type is unknown");
805+
pg_error_free(error);
806+
error = NULL;
807+
808+
links_count = pg_brick_links_count_get(east_brick3, west_brick3, &error);
809+
g_assert(error);
810+
g_assert(links_count == (uint32_t)-1);
811+
g_assert(error->message);
812+
g_assert_cmpstr(error->message, ==, "brick config type is unknown");
813+
pg_error_free(error);
814+
error = NULL;
815+
662816
links_count = pg_brick_links_count_get(west_brick, west_brick, &error);
663817
g_assert(!error);
664818
g_assert(links_count == 0);
@@ -694,6 +848,22 @@ static void test_brick_core_verify_multiple_link(void)
694848
g_assert(!error);
695849
g_assert(links_count == 3);
696850

851+
links_count = pg_brick_links_count_get(middle_brick1,east_brick1, &error);
852+
g_assert(!error);
853+
g_assert(links_count == 1);
854+
855+
links_count = pg_brick_links_count_get(middle_brick2, east_brick2, &error);
856+
g_assert(!error);
857+
g_assert(links_count == 1);
858+
859+
links_count = pg_brick_links_count_get(west_brick2, middle_brick2, &error);
860+
g_assert(!error);
861+
g_assert(links_count == 0);
862+
863+
links_count = pg_brick_links_count_get(east_brick1, east_brick1, &error);
864+
g_assert(!error);
865+
g_assert(links_count == 0);
866+
697867
/* unlink the west brick */
698868
pg_brick_unlink(west_brick, &error);
699869

@@ -821,13 +991,23 @@ static void test_brick_core_verify_re_link(void)
821991
test_brick_sanity_check_expected(f, 1, 1);
822992
test_brick_sanity_check_expected(a, 1, 0);
823993

994+
pg_brick_chained_links(&e,v,NULL);
995+
g_assert(e);
996+
pg_error_free(e);
997+
e = NULL;
998+
824999
/* Unlink f */
8251000
pg_brick_unlink(f, &e);
8261001
g_assert(!e);
8271002
test_brick_sanity_check_expected(v, 0, 0);
8281003
test_brick_sanity_check_expected(f, 0, 0);
8291004
test_brick_sanity_check_expected(a, 0, 0);
8301005

1006+
pg_brick_unlink(NULL, &e);
1007+
g_assert(e);
1008+
pg_error_free(e);
1009+
e = NULL;
1010+
8311011
/* Link v and s */
8321012
pg_brick_link(v, s, &e);
8331013
g_assert(!e);

0 commit comments

Comments
 (0)
Please sign in to comment.