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

Remove string-based API usage within mbed-os #11941

Merged

Conversation

michalpasztamobica
Copy link
Contributor

Description

Summary of change

Remove internal usage of deprecated string-based APIs.
The APIs were deprecated in #11914
This is still NOT a breaking change. The existing code was updated not to use the deprecated API functions, but the deprecated functions themselves are still available.

Documentation

The documentation was updated in the deprecation PR. Wherever new API had to be added I adjusted existing documentation.


Pull request type

[] Patch update (Bug fix / Target update / Docs update / Test update / Refactor)
[x] Feature update (New feature / Functionality change / New API)
[] Major update (Breaking change E.g. Return code change / API behaviour change)

Test results

[] No Tests required for this change (E.g docs only update)
[] Covered by existing mbed-os tests (Greentea or Unittest)
[x] Tests / results supplied as part of this PR

Reviewers

@AnttiKauppila
@SeppoTakalo
@mikter
@AriParkkila


Release Notes

See #11914 for deprecation information, this PR provides SocketAddress-based APIs if they were missing after previous changes, but still does not remove the old APIs.

Summary of changes

New SocketAddress based API added to ESP8266 module, anticipating future string-based API removal.

Impact of changes

Migration actions required

@michalpasztamobica
Copy link
Contributor Author

@0xc0170 , again, I could not run all possible platforms, but at least I checked unittests and some combinations of UBLOX/K64F with different compilers. I'd be grateful for starting a CI, as the API is scatterred and some extra changes might be required.
I did change the NetworkStack.cpp file, but did not change the API, so I hope the wiced binaries do not need a rebuild.
Finally, is it possible for this PR to still make it into mbed-os-5.15?

@ciarmcom
Copy link
Member

@michalpasztamobica, thank you for your changes.
@AnttiKauppila @mikter @AriParkkila @SeppoTakalo @ARMmbed/mbed-os-wan @ARMmbed/mbed-os-ipcore @ARMmbed/mbed-os-test @ARMmbed/mbed-os-maintainers please review.

@michalpasztamobica
Copy link
Contributor Author

Pushed astyle fixes.

@@ -137,6 +137,8 @@ class ESP8266Interface : public NetworkStack, public WiFiInterface {
/** Get the internally stored IP address
* @return IP address of the interface or null if not yet connected
*/
virtual nsapi_error_t get_ip_address(SocketAddress *address);

virtual const char *get_ip_address();

Choose a reason for hiding this comment

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

Should we mark these as deprecated as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I pushed an update deprecating string-based API of ESP8266 driver. I think this is a matter of being consequent. We cannot forbid member function overloading, but at least we can give a good example.

Another thing is that users will most likely use NetworkInterface::get_default_instance() rather that consciously creating EPS8266Interface, so they should be given deprecation warnings if they use string-based APIs anyway?

Copy link

@AnttiKauppila AnttiKauppila left a comment

Choose a reason for hiding this comment

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

We might want to drop string based functions also from drivers (at least from those we have made), but that can be done later

@0xc0170
Copy link
Contributor

0xc0170 commented Nov 26, 2019

CI started

@mbed-ci
Copy link

mbed-ci commented Nov 26, 2019

Test run: FAILED

Summary: 1 of 12 test jobs failed
Build number : 1
Build artifacts

Failed test jobs:

  • jenkins-ci/mbed-os-ci_greentea-test

@michalpasztamobica
Copy link
Contributor Author

I will investigate the failure.

@michalpasztamobica
Copy link
Contributor Author

With the SocketAddress API some test cases make no sense (like empty string as hostname), so I simplified the tlssocket_connect_invalid test.

Regarding udpsocket_sendto_invalid, @kjbracey-arm , if we use a SocketAddress, set to an invalid address (SocketAddress.set_ip_address("")) what should sendto return? LWIP seems to return 0, while ism43362 returns NSAPI_ERROR_DEVICE_ERROR. I relaxed the test's expectation to accept any error code or 0 (for 0 bytes sent). Does this make sense to you?

I put the above changes into separate commits.

For DISCO_L475VG_IOT01A, I had to create a PR in wifi-ism43362 repository: ARMmbed/wifi-ism43362#65 . I am afraid we won't be able to progress here before it gets merged. @0xc0170 , can we restart CI just to see if other platforms got fixed?

For the NULCEO_F429ZI failures - I don't know what is going on. I run the tests locally and they all passed. The logs also do not indicate any particular issue...

@0xc0170
Copy link
Contributor

0xc0170 commented Nov 27, 2019

CI started

@mbed-ci
Copy link

mbed-ci commented Nov 27, 2019

Test run: FAILED

Summary: 1 of 12 test jobs failed
Build number : 2
Build artifacts

Failed test jobs:

  • jenkins-ci/mbed-os-ci_greentea-test

@michalpasztamobica
Copy link
Contributor Author

OK. The only failures left are coming from DISCO_L475VG_IOT01A. They will pass as soon as ARMmbed/wifi-ism43362#65 is reviewed and merged.

@0xc0170
Copy link
Contributor

0xc0170 commented Nov 27, 2019

OK. The only failures left are coming from DISCO_L475VG_IOT01A. They will pass as soon as ARMmbed/wifi-ism43362#65 is reviewed and merged.

If this needs an update like that, is this breaking change?

@michalpasztamobica
Copy link
Contributor Author

@AnttiKauppila , @0xc0170 I am slightly afraid that this PR might wreak havoc in the nightly tests... Not sure how many different platform use external stacks?
@0xc0170 - this PR will not break an existing application, but our tests (greentea/unittests) are now using a new stack interface, so they might get broken if an external stack is used which does not implement those functions (for example ism43362). Does that count as a "breaking change"?

@0xc0170
Copy link
Contributor

0xc0170 commented Nov 27, 2019

ARMmbed/wifi-ism43362#65

Once it's merged, lets start CI again. Set as preceding PR needed here

@0xc0170
Copy link
Contributor

0xc0170 commented Nov 27, 2019

CI restarted

@mbed-ci
Copy link

mbed-ci commented Nov 27, 2019

Test run: FAILED

Summary: 1 of 12 test jobs failed
Build number : 3
Build artifacts

Failed test jobs:

  • jenkins-ci/mbed-os-ci_greentea-test

@0xc0170
Copy link
Contributor

0xc0170 commented Nov 27, 2019

@michalpasztamobica Please can you review the failures?

@michalpasztamobica
Copy link
Contributor Author

@0xc0170 , I am working on it...

@michalpasztamobica
Copy link
Contributor Author

michalpasztamobica commented Nov 27, 2019

Root cause: wifi-ism43362 driver's socket_sendto function hangs when compiled with IAR and given an invalid SocketAddress as a parameter. I will filed an issue in wifi-ism43362 github project: ARMmbed/wifi-ism43362#66

We can however proceed with the release, because after some more thinking I decided to remove udpsocket_sendto_invalid from test suite.
The purpose of udpsocket_sendto_invalid was to check if our protections against invalid hostname (NULL ptr or empty string) are working. The "hostname+port" version did check for parameter validity.
The SocketAddress version of InternetDatagramSocket::sendto does NOT check address parameter's validity and it never did. The reason is probably that SocketAddress class has its own mechanism for checking address validity, that user should make use of.
By adjusting the existing udpsocket_sendto_invalid test I have treaded into undefined behavior territory and now the test in fact checked error handling of underlying network stacks (and found a bug in one...).

If I added SocketAddress validity checks to InternetDatagramSocket::sendto this would make this PR a breaking change, and that's not at all my goal here. Removing the test which was testing deprecated API is the right thing to do.

I added an internal JIRA to find out what is the expected behavior of InternetDatagramSocket::sendto in case the SocketAddress is invalid and test against it.

@0xc0170 , please restart the CI, unless you see some gap in my way of thinking?
@AnttiKauppila , @bulislaw , please confirm that test removal makes sense to you as well.

Updated:
* netsocket classes,
* unittests, stubs and mocks,
* greentea tests
It tested parameter checks in the now obsoleted string-based API.
@michalpasztamobica
Copy link
Contributor Author

I pushed a cleaned-up commit history and test documentation updates.

@michalpasztamobica
Copy link
Contributor Author

Is everyone OK with the removal of the test? Can we move forward with this?

Copy link
Contributor

@SeppoTakalo SeppoTakalo left a comment

Choose a reason for hiding this comment

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

I'm OK with the change.

However, I did not spot, do we still have test case where we bind() on a socket without specifying the address, just the port number?

SocketAddress port;
port.set_port(80);
socket.bind(port);  // Should not require you to specify IP address.
socket.listen();
s = socket.accept();

@michalpasztamobica
Copy link
Contributor Author

michalpasztamobica commented Nov 28, 2019

Yes. We do have TCPSOCKET_BIND_PORT and USPSOCKET_BIND_PORT.

@0xc0170
Copy link
Contributor

0xc0170 commented Nov 28, 2019

I started CI meanwhile

@mbed-ci
Copy link

mbed-ci commented Nov 28, 2019

Test run: SUCCESS

Summary: 12 of 12 test jobs passed
Build number : 4
Build artifacts

@michalpasztamobica
Copy link
Contributor Author

@AnttiKauppila , would you confirm that you're ok with the recent changes?

@michalpasztamobica
Copy link
Contributor Author

Hi @0xc0170 , just to sum up the situation, as it got a bit complex with all the CI failures:
The CI passed after removing the test. The removal is justified and approved by Antti and Seppo.
All the bugs found are being tracked elsewhere.

If there is anything more that I can do to improve this PR, please let me know :).

@0xc0170
Copy link
Contributor

0xc0170 commented Nov 28, 2019

@michalpasztamobica Thanks for the updates, keeps us all update about the progress 👍

@0xc0170 0xc0170 merged commit ffdd543 into ARMmbed:master Nov 28, 2019
@michalpasztamobica michalpasztamobica deleted the remove_internal_string_apis branch November 28, 2019 13:26
@@ -92,6 +92,41 @@ const char *PPPInterface::get_ip_address()
return NULL;
}

nsapi_error_t PPPInterface::get_ip_address(SocketAddress *address)
{
if (address) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, I didn't notice this earlier, but there's a bug in here. Should be if (!address) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for pointing this out, @kivaisan .
PR that addresses this is redy: #11975 . @0xc0170 , sorry for this disturbance, but could we merge that PR, so the release has bug free code?

The reason why this was not spotted by CI is because the tests are pending: #11878

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

Successfully merging this pull request may close these issues.

9 participants