Skip to content

Conversation

MechanicV1
Copy link
Contributor

Added unit tests for ble_gq library

@MechanicV1 MechanicV1 requested review from a team as code owners August 25, 2025 10:24
@github-actions
Copy link

You can find the documentation preview for this PR here.

uint16_t conn_handle = 0x0C4;

ble_evt.header.evt_id = BLE_GAP_EVT_DISCONNECTED;
ble_evt.evt.gap_evt.conn_handle = 0x0C4;
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: I would consider defining 0x0C4 somewhere and then reusing the definition in all the different occurrences, rather than hardcoding the value.

@eivindj-nordic eivindj-nordic added this to the v0.9.0 milestone Aug 27, 2025
@lemrey
Copy link
Contributor

lemrey commented Sep 8, 2025

No milestone required for tests

@lemrey lemrey removed this from the v0.9.0 milestone Sep 8, 2025
Comment on lines 252 to 303
for (int i = 0; i < ble_gq.max_conns; i++) {
ble_gq.conn_handles[i] = i + 1;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

We should not alter the ble_gq ourselves. Perhaps register up to max_conns handlers successfully, then see that the next fails?

Comment on lines 295 to 296
sys_slist_init(&ble_gq.req_queue[0]);
sys_slist_append(&ble_gq.req_queue[0], &req.node);
Copy link
Contributor

Choose a reason for hiding this comment

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

There should be another way to append these than by altering the struct with slist. Use ble_gq_item_add()?

@MechanicV1 MechanicV1 force-pushed the ble_gq_unittest branch 3 times, most recently from 54395ef to 651a388 Compare October 10, 2025 06:46
Added unit tests for ble_gq library

Signed-off-by: Nirmal Krishna <[email protected]>
Co-authored-by: Andreas Moltumyr <[email protected]>
TEST_ASSERT_EQUAL(NRF_ERROR_INVALID_STATE, glob_error);
}

void test_ble_gq_item_add_req_gatt_write(void)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
void test_ble_gq_item_add_req_gatt_write(void)
void test_ble_gq_item_add_req_gattc_write_error_resources(void)

Copy link
Contributor

@eivindj-nordic eivindj-nordic Oct 21, 2025

Choose a reason for hiding this comment

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

there are more cases like this. When not having a error at the end, we expect it to test a successful case. In this (and the other) case it is not, as the handler is called with an error.

TEST_ASSERT_EQUAL(NRF_ERROR_RESOURCES, glob_error);
}

void test_ble_gq_item_add_req_srv_discovery(void)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
void test_ble_gq_item_add_req_srv_discovery(void)
void test_ble_gq_item_add_req_srv_discovery_timeout(void)

ble_gq.conn_handles[0] = 0;

__cmock_sd_ble_gattc_write_ExpectAndReturn(conn_handle, &req.gattc_write, NRF_ERROR_BUSY);
__cmock_sd_ble_gattc_write_IgnoreAndReturn(NRF_ERROR_RESOURCES);
Copy link
Contributor

@eivindj-nordic eivindj-nordic Oct 21, 2025

Choose a reason for hiding this comment

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

I don't see any test where the second call returns success, and we check glob_error for NRF_SUCCESS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants