Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coverage #515

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Coverage #515

wants to merge 2 commits into from

Conversation

outscale-hmi
Copy link
Contributor

No description provided.

@outscale-mgo
Copy link
Contributor

Can one of the admins verify this patch?

Copy link
Contributor

@outscale-mgo outscale-mgo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code is pretty much okay.
Can you reorganise your patches, this PR should contain 4 patches:
2 for the coverage, 1 for the brick modification, and one for moving antispoof define to a public header


/* add NDP_MAX adresses */
for (int i = 0; i < 150; i++) {
pg_ip_from_str(ip, "2001:db8:2000:aff0::"+i);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"string" + i
will overflow here, and is UB.

@@ -44,9 +88,11 @@ static void test_brick_core_simple_lifecycle(void)
brick = pg_brick_new("nop", config, &error);
g_assert(brick);
g_assert(!error);
printf("brick refcount is %ld\n",brick->refcount);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no don't add printf please, g_assert the refcount is a good idea though

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ping ?


pg_brick_decref(brick, &error);
g_assert(!error);
printf("brick refcount is %ld\n",brick->refcount);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

src/brick-int.h Outdated
@@ -207,7 +207,7 @@ struct pg_brick *pg_brick_decref(struct pg_brick *brick,
int pg_brick_reset(struct pg_brick *brick, struct pg_error **errp);

/* testing */
uint32_t pg_brick_links_count_get(const struct pg_brick *brick,
int pg_brick_links_count_get(const struct pg_brick *brick,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this change brick and had nothing to do with coverage, as sure it should be in a different patch

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^ this is still valid
Especially for brick which is use everywhere in packetgraph, change in brick deserver a separate commit

src/brick.c Outdated
@@ -321,17 +321,17 @@ static uint16_t count_side(const struct pg_brick_side *side,
* @param errp a return pointer for an error message
* @return the total number of link from the brick to the target
*/
uint32_t pg_brick_links_count_get(const struct pg_brick *brick,
int pg_brick_links_count_get(const struct pg_brick *brick,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same for this one

@@ -21,6 +21,9 @@
#include <packetgraph/common.h>
#include <packetgraph/errors.h>

#define PG_ARP_MAX 100
#define PG_NPD_MAX 100
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as this change the brick and not the coverage(and add public define), is should be in another patch

@@ -828,6 +828,11 @@ static void test_brick_core_verify_re_link(void)
test_brick_sanity_check_expected(f, 0, 0);
test_brick_sanity_check_expected(a, 0, 0);

pg_brick_unlink(NULL, &e);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't seems related to antispoof, maybe it was for the other patch ?

@outscale-hmi outscale-hmi force-pushed the coverage branch 4 times, most recently from a58042e to ea8960c Compare January 7, 2020 14:00
@@ -208,8 +208,8 @@ int pg_brick_reset(struct pg_brick *brick, struct pg_error **errp);

/* testing */
uint32_t pg_brick_links_count_get(const struct pg_brick *brick,
const struct pg_brick *target,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this change is useful

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is just to remove the extra white space

/* pkt3 with Next header : UDP (17)
*
* */
static unsigned char pkt3[86];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think static is needed

} else {
g_assert(pg_antispoof_arp_add(antispoof, i, &error));
g_assert(error);
pg_error_free(error);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really think those 3 lines of code could be re-factorise into a macro
(in src/utils/errors.h)

#define PG_CHECK_HAVE_ERROR(error) do {\
g_assert(error);\
pg_error_free(error);\
error = NULL;\
} while (0);

PG_CHECK_HAVE_ERROR is a bad name, but I'm not good at naming

} else {
g_assert(pg_antispoof_arp_add(antispoof, i, &error));
g_assert(error);
pg_error_free(error);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so you could use the macro here

@@ -265,8 +316,7 @@ static void test_antispoof_generic(const unsigned char **pkts,
pg_brick_unlink(antispoof, &error);
g_assert(!error);
pg_brick_destroy(antispoof);
antispoof = pg_antispoof_new("antispoof", PG_WEST_SIDE,
&inside_mac, &error);
antispoof = pg_antispoof_new("antispoof", PG_WEST_SIDE, &inside_mac, &error);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you need to call pg_brick_destroy on antispoof again.

pg_antispoof_ndp_add(antispoof, ip, &error);
g_assert(!error);

/* remove adresse */
g_assert(pg_antispoof_ndp_del(antispoof,ip,&error) == 0);
g_assert(!error);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indentation ?

src/brick-int.h Outdated
@@ -207,7 +207,7 @@ struct pg_brick *pg_brick_decref(struct pg_brick *brick,
int pg_brick_reset(struct pg_brick *brick, struct pg_error **errp);

/* testing */
uint32_t pg_brick_links_count_get(const struct pg_brick *brick,
int pg_brick_links_count_get(const struct pg_brick *brick,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

^ this is still valid
Especially for brick which is use everywhere in packetgraph, change in brick deserver a separate commit

PG_MULTIPOLE);
struct pg_brick_config *config = pg_brick_config_new("mybrick", 2, 2, PG_MULTIPOLE);
struct pg_brick_config *config1 = pg_brick_config_new("mybrick", 2, 2, PG_MONOPOLE);
struct pg_brick_config *config2 = pg_brick_config_new("mybrick", UINT16_MAX, UINT16_MAX, PG_MULTIPOLE);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think config need to be free, it doesn't seems you free the configs

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -44,9 +88,11 @@ static void test_brick_core_simple_lifecycle(void)
brick = pg_brick_new("nop", config, &error);
g_assert(brick);
g_assert(!error);
printf("brick refcount is %ld\n",brick->refcount);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ping ?

middle_brick3 = pg_brick_new("nop", config3, &error);
g_assert(!error);
east_brick3 = pg_brick_new("nop", config3, &error);
g_assert(!error);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you destroy those brick, you you either need to call pg_brick_ptrptr_destroy at the end of the function or creating the variable using pg_cleanup(pg_brick_ptrptr_destroy)
example:

pg_cleanup(pg_brick_ptrptr_destroy) struct pg_brick_config *config =
pg_brick_config_new("mybrick", 2, 2, PG_MULTIPOLE);

also

pg_cleanup(pg_brick_ptrptr_destroy)

is kind of ugly, so maybe we can create a macro

#define pg_autobrick pg_cleanup(pg_brick_ptrptr_destroy)

@outscale-hmi outscale-hmi force-pushed the coverage branch 8 times, most recently from bee977d to cc9fa12 Compare January 13, 2020 16:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants