Merge lp://qastaging/~awe/phablet-extras/ofono-unittest-gprs-context into lp://qastaging/phablet-extras/ofono

Proposed by Tony Espy
Status: Merged
Approved by: Ricardo Salveti
Approved revision: 67
Merged at revision: 48
Proposed branch: lp://qastaging/~awe/phablet-extras/ofono-unittest-gprs-context
Merge into: lp://qastaging/phablet-extras/ofono
Diff against target: 2756 lines (+1901/-394)
20 files modified
Makefile.am (+23/-2)
drivers/rilmodem/gprs-context.c (+187/-260)
drivers/rilmodem/rilutil.c (+2/-81)
drivers/rilmodem/rilutil.h (+0/-13)
gril/gril.c (+19/-6)
gril/gril.h (+10/-8)
gril/grilreply.c (+225/-0)
gril/grilreply.h (+57/-0)
gril/grilrequest.c (+213/-0)
gril/grilrequest.h (+63/-0)
gril/grilunsol.c (+158/-0)
gril/grilunsol.h (+62/-0)
gril/grilutil.c (+47/-0)
gril/grilutil.h (+9/-5)
gril/parcel.c (+15/-19)
gril/ril_constants.h (+12/-0)
include/types.h (+10/-0)
unit/test-grilreply.c (+339/-0)
unit/test-grilrequest.c (+312/-0)
unit/test-grilunsol.c (+138/-0)
To merge this branch: bzr merge lp://qastaging/~awe/phablet-extras/ofono-unittest-gprs-context
Reviewer Review Type Date Requested Status
Ricardo Salveti (community) Approve
PS Jenkins bot continuous-integration Approve
Sergio Schvezov Needs Fixing
Review via email: mp+173558@code.qastaging.launchpad.net

Commit message

[gril/rilmodem] Re-factor gprs-context code to facilitate unit testing.

Description of the change

This branch re-factors rilmodem's gprs-context module such that all RIL message code has been moved into the lower gril base layer. This was done to allow unit testing of the RIL parcel code used by gprs-context.

Once this code has been merged, the plan is to re-factor the rest of the rilmodem code using this approach.

Tested on an un-flipped raring image running on maguro.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Tony Espy (awe) wrote :

Build failure is due to the fact that I didn't add the unit test source file... I'm working on restoring it, and should have this branch updated by end-of-day.

54. By Tony Espy

[gril] Re-work of gprsmessages based on unit testing.

55. By Tony Espy

[gril] Initial gprs-context unit tests for grilmessages.

56. By Tony Espy

[gril] Make changes for unit testing.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Sergio Schvezov (sergiusens) wrote :

I would split:
823 +static void test_invalid_setup_data_calls(void)
834 + /* Test invalid radio tech values */
847 + /* Test invalid data profile */
855 + /* Invalid APNs */
...
and so on for the other test functions into individual test cases.

Also consider the posibility of a test fixture for each of these test functions(at your discretion)
https://developer.gnome.org/glib/2.28/glib-Testing.html#g-test-add

Is it a good idea to make a free_reply (or with similar name) that would take care of freeing the complete struct and then just call that?
238 + g_strfreev(reply.dns_addresses);
239 + g_strfreev(reply.ip_addrs);
240 + g_strfreev(reply.gateways);
249 + g_free(reply.ifname);

review: Needs Fixing
Revision history for this message
Tony Espy (awe) wrote :

@Sergio

Thanks for the comments, and I agree that splitting the tests out probably makes sense.

Also per our discussion yesterday, I will split grilmessages.c into three separate files: grilrequests.c, grilreplies.c, and grilevents.c.

Finally, I also mentioned that I only added unit tests for the SETUP_DATA_CALL request. I will go ahead and add unit tests for the corresponding reply as well.

I should be able to wrap up all these changes today.

Revision history for this message
Sergio Schvezov (sergiusens) wrote :

On Fri, Jul 12, 2013 at 12:15 PM, Tony Espy <email address hidden> wrote:
> @Sergio
>
> Thanks for the comments, and I agree that splitting the tests out probably makes sense.
>
> Also per our discussion yesterday, I will split grilmessages.c into three separate files: grilrequests.c, grilreplies.c, and grilevents.c.
>
> Finally, I also mentioned that I only added unit tests for the SETUP_DATA_CALL request. I will go ahead and add unit tests for the corresponding reply as well.
>
> I should be able to wrap up all these changes today.

Sounds good to me :-)

57. By Tony Espy

[gril/rilmodem] Split grilmessages into grilrequest, grilreply, and grilunsol.

58. By Tony Espy

[rilmodem] Back out AudioSystem and Makefile.am changes made by mistake.

59. By Tony Espy

[gril] Re-factored low-level message support into type-specific modules.

60. By Tony Espy

[gril] Fixed the tracing logic, and cleaned up some minor warnings.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
61. By Tony Espy

Re-merge from trunk.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Tony Espy (awe) wrote :

Two last things need to be fixed.

First, the CI build fails due to a unit test failure. This is the test I mentioned earlier that was also failing in pbuild.

ERROR:unit/test-grilrequest.c:200:test_deactivate_data_call_valid: assertion failed: (!memcmp(rilp.data, test_data->parcel_data, test_data->parcel_size)\

Test test tries to compare wire-format parcel data ( stored in rilp.data ) to a static guchar of bytes that represent what the parcel wire format should look like.

The second issue is how the gprs-context code handles setup_data_call failures. I'm not sure if a failure callback triggers a disconnect from the core ofono code or not. If it does, then the code should be fine as is. If it doesn't, then this could potentially leave an active data call within RIL, and thus we should explicitly disconnect in this case.

Revision history for this message
Tony Espy (awe) wrote :

OK, so it appears the failure callback doesn't trigger a disconnect, so I'll modify the code to do that if the SETUP_DATA_CALL reply triggers a message validation error.

Revision history for this message
Tony Espy (awe) wrote :

I'll plan on landing the final bits over the weekend...

62. By Tony Espy

[gril/grilmodem] Ensure that data call is deactivated in invalid reply scenarios.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
63. By Tony Espy

[gril] Fix a bug in parcel_w_string() that can cause an invalid string terminator to be generated.

Revision history for this message
Tony Espy (awe) wrote :

OK, both problems are now fixed.

Data calls are properly disconnected if a reply is received from RIL that is deemed invalid by the gril code.

The unit test failure was due to a subtle bug in parcel_w_string() which could result in invalid string terminator bytes to be included due to an incorrect offset used to write the terminating utf16 0x00000.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
64. By Tony Espy

[rilmodem] Implement gprs_context_detach_shutdown().

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Ricardo Salveti (rsalveti) wrote :

127 - if (message->req != RIL_UNSOL_DATA_CALL_LIST_CHANGED) {
128 - ofono_error("ril_gprs_update_calls: invalid message received %d",
129 - message->req);
130 - return;
131 - }

Why did you remove the above? g_ril_unsol_parse_data_call_list is also not checking if the message is indeed UNSOL_DATA_CALL_LIST_CHANGED.

1017 + g_free(reply);
1611 + g_free(call);
1621 + g_free(unsol);

Not an issue, but as you're checking for call and unsol just before free, you could include the g_free call as part of the if scope.

901 +#define OFONO_EINVAL(error) do { \
902 + error->type = OFONO_ERROR_TYPE_FAILURE; \
903 + error->error = -EINVAL; \
904 +} while (0)
905 +
906 +#define OFONO_NO_ERROR(error) do { \
907 + error->type = OFONO_ERROR_TYPE_NO_ERROR; \
908 + error->error = 0; \
909 +} while (0)
910 +

These would be better if defined somewhere in a common ofono code, not just for ril.

2018 +static const struct ril_msg reply_data_call_invalid_2 = {
2019 + .buf = (gchar *) &reply_data_call_invalid_parcel1,

2052 +static const struct ril_msg reply_data_call_invalid_3 = {
2053 + .buf = (gchar *) &reply_data_call_invalid_parcel2,

2084 +static const struct ril_msg reply_data_call_invalid_4 = {
2085 + .buf = (gchar *) &reply_data_call_invalid_parcel3,

2115 +static const struct ril_msg reply_data_call_invalid_5 = {
2116 + .buf = (gchar *) &reply_data_call_invalid_parcel4,

2147 +static const struct ril_msg reply_data_call_invalid_6 = {
2148 + .buf = (gchar *) &reply_data_call_invalid_parcel5,

2176 +static const struct ril_msg reply_data_call_invalid_7 = {
2177 + .buf = (gchar *) &reply_data_call_invalid_parcel6,

Would you mind changing the test id to match the same number used by both structs? Otherwise it gets quite confusing when reading the code, as data_call_invalid_2 is part of invalid_parcel_1, instead of invalid_parcel_2 (which is a natural reading by our brain).

Other than those minor comments, code looks good (although it could technically be separated in more MRs, as we discussed).

Will now test in both mako and maguro.

review: Needs Fixing
Revision history for this message
Ricardo Salveti (rsalveti) wrote :

Tested with both mako and maguro and it seems to be all good :-)

Just minor issue I got with my maguro is that the modem can't attach anymore it seems, but don't think it's related with this MR (might be that intermittent issue we had this week).

Will test a bit more with maguro...

Would be nice if you could double check with it as well.

Revision history for this message
Ricardo Salveti (rsalveti) wrote :

Yeah, can't get my mako to attach anymore, with/without NM, and even after a clean install.

We might be having another issue somewhere in this code, which is not related with this MR.

Revision history for this message
Ricardo Salveti (rsalveti) wrote :

Argh, *maguro*.

Revision history for this message
Ricardo Salveti (rsalveti) wrote :

Ok, the issue with maguro is that it cannot attach at first, but it works after restarting ofono =\

First run, not attached:
http://paste.ubuntu.com/5917341/

Second run, attached:
http://paste.ubuntu.com/5917346/

Wonder if this is a side effect of that roaming bug you fixed (will follow up this in a bug).

Revision history for this message
Tony Espy (awe) wrote :

Question, were you testing with just this MR, or the combined MRs? As we discussed, the attach fix was split between the two MRs due to the heavy re-factoring of gprs-context.c in this MR.

I will look at your comments above, which all seem reasonable and try and update the MR later today.

I will also do some more testing to see if I can reproduce any of the issues you ran into while testing.

Note, my fix assumes that NetworkManager always sets the ConnectionManager's 'Powered' on start-up. Perhaps there's a race condition and this isn't always happening?

Revision history for this message
Ricardo Salveti (rsalveti) wrote :

Just with this MR, and without NetworkManager involved. Was just tracking the ofono state after it was properly initialized.

Revision history for this message
Tony Espy (awe) wrote :

OK, I'll plan on giving both a shake-down tomorrow after I clean up the couple of things based on your previous comment.

This code really shouldn't have effected whether GPRS attaches or not, as it only touches the gprs-context driver.

65. By Tony Espy

[gril] Moved ofono error helper #defines into <ofono/types.h>

66. By Tony Espy

[gril] Re-numbered parcel unit test data variables to match test cases.

67. By Tony Espy

[gril] Minor re-factoring in helper functions.

Revision history for this message
Tony Espy (awe) wrote :

> 127 - if (message->req != RIL_UNSOL_DATA_CALL_LIST_CHANGED) {
> 128 - ofono_error("ril_gprs_update_calls: invalid message received %d",
> 129 - message->req);
> 130 - return;
> 131 - }
>
> Why did you remove the above? g_ril_unsol_parse_data_call_list is also not
> checking if the message is indeed UNSOL_DATA_CALL_LIST_CHANGED.

I removed it because it wasn't needed. If you look at the code in gril.c that handles unsolicited messages, it's not really possible for the wrong message to be passed to a registered listener, as that's the whole purpose of registering for a particular message.

> 1017 + g_free(reply);
> 1611 + g_free(call);
> 1621 + g_free(unsol);
>
> Not an issue, but as you're checking for call and unsol just before free, you
> could include the g_free call as part of the if scope.

Done.

> 901 +#define OFONO_EINVAL(error) do { \
> 902 + error->type = OFONO_ERROR_TYPE_FAILURE; \
> 903 + error->error = -EINVAL; \
> 904 +} while (0)
> 905 +
> 906 +#define OFONO_NO_ERROR(error) do { \
> 907 + error->type = OFONO_ERROR_TYPE_NO_ERROR; \
> 908 + error->error = 0; \
> 909 +} while (0)
> 910 +
>
> These would be better if defined somewhere in a common ofono code, not just
> for ril.

Done, moved these to <ofono/type.h>.
>
> 2018 +static const struct ril_msg reply_data_call_invalid_2 = {
> 2019 + .buf = (gchar *) &reply_data_call_invalid_parcel1,
>
> 2052 +static const struct ril_msg reply_data_call_invalid_3 = {
> 2053 + .buf = (gchar *) &reply_data_call_invalid_parcel2,
>
> 2084 +static const struct ril_msg reply_data_call_invalid_4 = {
> 2085 + .buf = (gchar *) &reply_data_call_invalid_parcel3,
>
> 2115 +static const struct ril_msg reply_data_call_invalid_5 = {
> 2116 + .buf = (gchar *) &reply_data_call_invalid_parcel4,
>
> 2147 +static const struct ril_msg reply_data_call_invalid_6 = {
> 2148 + .buf = (gchar *) &reply_data_call_invalid_parcel5,
>
> 2176 +static const struct ril_msg reply_data_call_invalid_7 = {
> 2177 + .buf = (gchar *) &reply_data_call_invalid_parcel6,
>
> Would you mind changing the test id to match the same number used by both
> structs? Otherwise it gets quite confusing when reading the code, as
> data_call_invalid_2 is part of invalid_parcel_1, instead of invalid_parcel_2
> (which is a natural reading by our brain).

Yea, I thought about this an since the first test case didn't actually have parcel_data, I thought it would be weird having the first parcel data variable start with "2". Oh well, not a big deal. Re-number per your suggestion.

> Other than those minor comments, code looks good (although it could
> technically be separated in more MRs, as we discussed).
>
> Will now test in both mako and maguro.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Ricardo Salveti (rsalveti) wrote :

Good, thanks!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
The diff is not available at this time. You can reload the page or download it.

Subscribers

People subscribed via source and target branches