IOT-1868 [C++ layer] Make OCPlatform start and stop reliably
authorWay Vadhanasin <wayvad@microsoft.com>
Tue, 7 Mar 2017 00:09:50 +0000 (16:09 -0800)
committerDan Mihai <Daniel.Mihai@microsoft.com>
Thu, 9 Mar 2017 15:09:26 +0000 (15:09 +0000)
commit656e46dc35baa8b6bf89912bf23b60e9f39885ae
tree780cb5ce577db44c4459cde14897b896f89aa413
parentf0c792a3c34467e7719849d2e6b39d8c03bb1313
IOT-1868 [C++ layer] Make OCPlatform start and stop reliably

This change adds reference count to OCPlatform's static start and
stop functions and synchronizes them. It does the following:

1. Ensures that calls to the "C" APIs OCInit and OCStop are balanced.
2. Maintains backward compatibility by introducing new PlatformConfig
   constructor and deprecate the old ones.
3. Updates the existing unit tests and samples.

Because this change allows the framework to stop properly, it exposes
some existing IoTivity leaks in Jenkins (Valgrind validation). Thus
the following leaks are fixed in this change to allow successful
Jenkins runs:

1. caipadapter.c: endpoint cache leak in UDP (no issue for TCP).
- https://build.iotivity.org/ci/job/iotivity-verify-unit_tests/
10907/valgrindResult/pid=24498,0x3fe

2. psinterface.c: CBOR buffer leaks in CreateResetProfile.
- https://build.iotivity.org/ci/job/iotivity-verify-unit_tests/
10922/valgrindResult/pid=2316,0x3ad

3. ocstack.c & securityResourceManager.cpp: persistent storage buffer
leaks as a result of restarting and switching OCPlatform
configuration after shutdown (e.g., between tests).
https://build.iotivity.org/ci/job/iotivity-verify-unit_tests/
10922/valgrindResult/pid=2316,0x3ad

4. OCRepresentationEncodingTest.cpp: representation value leaks.
- https://build.iotivity.org/ci/job/iotivity-verify-unit_tests/
10922/valgrindResult/pid=2316,0x3a9

5. runtest.py: change Valgrind callstack size from the default value
of 12 to 24 so that the test name is visible in the report. Helpful
for reproducibility.

Change-Id: I79406f2cf4282efbb29a69c14e42aae928f54bae
Signed-off-by: Way Vadhanasin <wayvad@microsoft.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/17685
Tested-by: jenkins-iotivity <jenkins@iotivity.org>
Reviewed-by: Dan Mihai <Daniel.Mihai@microsoft.com>
38 files changed:
resource/csdk/connectivity/src/ip_adapter/caipadapter.c
resource/csdk/security/src/psinterface.c
resource/csdk/security/unittest/securityresourcemanager.cpp
resource/csdk/stack/src/ocstack.c
resource/examples/devicediscoveryclient.cpp
resource/examples/devicediscoveryserver.cpp
resource/examples/directpairingclient.cpp
resource/examples/fridgeclient.cpp
resource/examples/fridgeserver.cpp
resource/examples/garageclient.cpp
resource/examples/garageserver.cpp
resource/examples/groupclient.cpp
resource/examples/groupserver.cpp
resource/examples/lightserver.cpp
resource/examples/mediaserver.cpp
resource/examples/presenceclient.cpp
resource/examples/presenceserver.cpp
resource/examples/rdclient.cpp
resource/examples/roomclient.cpp
resource/examples/roomserver.cpp
resource/examples/simpleclient.cpp
resource/examples/simpleclientHQ.cpp
resource/examples/simpleclientserver.cpp
resource/examples/simpleserver.cpp
resource/examples/threadingsample.cpp
resource/examples/winuiclient.cpp
resource/examples/winuiclient.h
resource/examples/winuiclientgui.cpp
resource/include/OCApi.h
resource/include/OCPlatform.h
resource/include/OCPlatform_impl.h
resource/include/WrapperFactory.h
resource/src/InProcClientWrapper.cpp
resource/src/InProcServerWrapper.cpp
resource/src/OCPlatform_impl.cpp
resource/unittests/OCPlatformTest.cpp
resource/unittests/OCRepresentationEncodingTest.cpp
tools/scons/RunTest.py