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

OCF Bridging #588

Closed
wants to merge 49 commits into from
Closed

OCF Bridging #588

wants to merge 49 commits into from

Conversation

Danielius1922
Copy link
Member

No description provided.

@ocf-conformance-test-tool
Copy link

🎉 Thank you for your code contribution! To guarantee the change/addition is conformant to the OCF Specification, we would like to ask you to execute OCF Conformance Testing of your change ☝️ when your work is ready to be reviewed.


ℹ️ To verify your latest change (bcb3671), label this PR with OCF Conformance Testing.

⚠️ Label is removed with every code change.

Copy link

Quality Gate Passed Quality Gate passed

Kudos, no new issues were introduced!

0 New issues
0 Security Hotspots
No data about Coverage
0.6% Duplication on New Code

See analysis details on SonarCloud

@joochlee
Copy link
Collaborator

PR #592 replaces this one

@joochlee joochlee closed this Jan 12, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Jan 12, 2024
@joochlee
Copy link
Collaborator

joochlee commented Jan 15, 2024

I don't understand why code coverage of sonarcloud is so low..
How to pass this sonarCloud test?
Should I clear all code smells and security hot spots?
=> but some error is unfixable: e.g. "Make the type of this parameter a pointer-to-const. The current type of "user_data" is "void *" ".
=> If I fix this issue, build fails.. because of type mismatch. function pointer type should be changed to fix this issues..

@Danielius1922
Copy link
Member Author

Danielius1922 commented Jan 15, 2024

I don't understand why code coverage of sonarcloud is so low.. How to pass this sonarCloud test? Should I clear all code smells and security hot spots? => but some error is unfixable: e.g. "Make the type of this parameter a pointer-to-const. The current type of "user_data" is "void *" ". => If I fix this issue, build fails.. because of type mismatch. function pointer type should be changed to fix this issues..

Yes, please try to fix the issues, we need SC to pass before we can merge. These are core files, so these need to be tested.

Ignore those type mismatch warnings, those are won't fix, I'll click those in the SC GUI (there is also usually other type of warning about that the programmer should use a concrete type instead of void*, those should be ignored as well).

For coverage, well new code needs new unit tests, no? Usually a .c file has a .cpp unittest file that tests it. So, for example you've added oc_uuid_is_nil to oc_uuid.c so you need to add unit test to api/unittest/uuidtest.cpp that tests that function. But you should probably wait until I review, because I might require a code rewrite and the tests would need to be rewritten as well. I'll try to check some files today, so you can continue your work. Right now oc_vod_map.c and oc_uiid.c look ok to me, so you can start by adding tests for new code there.

@joochlee
Copy link
Collaborator

do we need unittest for functions defined in "oc_*_internal.h" ?
It seems that it may not...

@Danielius1922
Copy link
Member Author

do we need unittest for functions defined in "oc_*_internal.h" ? It seems that it may not...

Well, it depends. Priority is to have public functions tested, so if the tests of a public function also test some internal function then it's not necessary to add separate tests for the internal function. However, sometimes it is easier to add unit tests for an internal function than setting up the tests of a parent function to hit the internal function.

@joochlee
Copy link
Collaborator

joochlee commented Jan 16, 2024

Hi, Is there any way to run specific test case ?
(for example, "ctest coreresourcetest -V" )

@Danielius1922
Copy link
Member Author

Hi, Is there any way to run specific test case ? (for example, "ctest coreresourcetest -V" )

Not sure if it is possible using ctest, but I do it by running the test binary with the --gtest_filter parameter.

For example, if you want to run CoreDevice_P from TestCoreResource then:

  1. go to your build folder and you should have apitest binary (if not, you need to rebuild your project with the CMake switch -DBUILD_TESTING=ON)
  2. run:
    ./apitest --gtest_filter="TestCoreResource.CoreDevice_P"

@joochlee
Copy link
Collaborator

Hi, Is there any way to run specific test case ? (for example, "ctest coreresourcetest -V" )

Not sure if it is possible using ctest, but I do it by running the test binary with the --gtest_filter parameter.

For example, if you want to run CoreDevice_P from TestCoreResource then:

  1. go to your build folder and you should have apitest binary (if not, you need to rebuild your project with the CMake switch -DBUILD_TESTING=ON)
  2. run:
    ./apitest --gtest_filter="TestCoreResource.CoreDevice_P"

Thank you !

@joochlee
Copy link
Collaborator

Another question.
what does "_P" and "_F" mean at the end of each test case name ??

@Danielius1922
Copy link
Member Author

Danielius1922 commented Jan 16, 2024

Another question. what does "_P" and "_F" mean at the end of each test case name ??

The use is inconsistent in the repo, but I use it like this: "_P" (positive/passing path, meaning that the tested function succeeds) and "_F" (failure path, the tested function fails)

@joochlee
Copy link
Collaborator

Another question. what does "_P" and "_F" mean at the end of each test case name ??

The use is inconsistent in the repo, but I use it like this: "_P" (positive/passing path, meaning that the tested function succeeds) and "_F" (failure path, the tested function fails)

got it, Thanks !

.gitignore Outdated Show resolved Hide resolved
.gitignore Outdated Show resolved Hide resolved
CMakeLists.txt Outdated Show resolved Hide resolved
api/oc_collection.c Outdated Show resolved Hide resolved
api/oc_collection.c Show resolved Hide resolved
include/oc_uuid.h Outdated Show resolved Hide resolved
include/oc_uuid.h Outdated Show resolved Hide resolved
port/linux/ipadapter.c Outdated Show resolved Hide resolved
@Danielius1922 Danielius1922 force-pushed the joochlee/feature/merge_bridging branch from 630b2de to 4d54fc0 Compare January 26, 2024 08:56
@@ -609,6 +630,12 @@ oc_get_next_collection_with_link(const oc_resource_t *resource,
collection = (oc_collection_t *)collection->res.next;
}

/*
* FIXED <2024/01/23> oc_get_next_collection_with_link() :
Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, seems like a bug. The original version seems to pressupose that the list of collections is ordered by device index, but this is not ensured by oc_collection_add when a new collection is added to the list.

Remove the old version and keep the fixed code.

Copy link
Collaborator

Choose a reason for hiding this comment

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

done

#include "security/oc_ael_internal.h"
#include "oc_acl.h"
#include "oc_cred.h"
#endif
Copy link
Member Author

Choose a reason for hiding this comment

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

#ifdef OC_HAS_FEATURE_BRIDGE
#include "oc_acl.h"
#include "oc_cred.h"
#ifdef OC_SECURITY
#include "security/oc_ael_internal.h"
#include "security/oc_svr_internal.h"
#endif /* OC_SECURITY*/
#endif /* OC_HAS_FEATURE_BRIDGE */

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks, it's much better!

@@ -2300,7 +2301,9 @@ oc_push_free(void)
_purge_recv_obj_list(recvs_instance);
OC_PUSH_DBG("free push receiver Resource (device: %zu)... ",
recvs_instance->resource->device);
#if 0
Copy link
Member Author

Choose a reason for hiding this comment

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

Isn't the recvs_instance->resource leaking now?

Copy link
Collaborator

@joochlee joochlee Jan 26, 2024

Choose a reason for hiding this comment

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

Probably not.
recvs_instance->resource points Push Receiver Resource (oic.r.pushreceiver) which is one of App Resources.
All App Resources are removed by oc_ri_shutdown() as you know.
so I think that letting oc_ri_shutdown() do its own job is better idea.

what do you think ?

@@ -105,6 +112,7 @@ oc_core_init(void)
#endif /* OC_DYNAMIC_ALLOCATION */
}

#ifdef OC_DYNAMIC_ALLOCATION
Copy link
Member Author

Choose a reason for hiding this comment

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

This is a leak, oc_free_string has to be called even when dynamic allocation is disabled, because oc_strings use a shared byte pool buffer and without this deallocation the buffers aren't returned to the shared pool.

Copy link
Collaborator

@joochlee joochlee Jan 26, 2024

Choose a reason for hiding this comment

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

oc_core_free_device_info_properties() are called by 2 functions : oc_core_shutdown() and oc_core_remove_device_at_index().

When OC_DYNAMIC_ALLOCATION = OFF, oc_core_remove_device_at_index() and code block calling
oc_core_remove_device_at_index() of oc_core_shutdown() are disabled.

Therefore, If I remove #ifdef OC_DYNAMIC_ALLOCATION directive, oc_core_free_device_info_properties() is used by none. so gcc complains that this function is never used...

bool
oc_core_remove_device_at_index(size_t index)
{
if (index >= g_device_count) {
Copy link
Member Author

Choose a reason for hiding this comment

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

replace with oc_core_device_is_valid

Copy link
Collaborator

Choose a reason for hiding this comment

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

done

}

#ifdef OC_SECURITY
oc_reset_device(index);
Copy link
Member Author

Choose a reason for hiding this comment

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

In some cases schedules delayed events - I see cloud deregistration and closing of TLS sessions for the device. We might be in for a nasty surprise when those events execute with a deleted device.

res = res->next;
}

oc_collections_free_per_device(index);
Copy link
Member Author

Choose a reason for hiding this comment

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

#ifdef OC_COLLECTIONS
oc_collections_free_per_device(index);
#endif /* OC_COLLECTIONS */

Copy link
Collaborator

Choose a reason for hiding this comment

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

fixed

* @return non-NULL found resource
* @return NULL no more resource or end of list
*/
oc_resource_t *oc_ri_get_app_resource_by_device(size_t device, bool reset);
Copy link
Member Author

Choose a reason for hiding this comment

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

Do oc_ri_get_app_resource_by_device and oc_ri_delete_app_resources_per_device need to be part of the public API? I don't see them used in any apps.

Copy link
Collaborator

Choose a reason for hiding this comment

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

oc_ri_get_app_resource_by_device() is used by bridge_manager module (not uploaded yet)
oc_ri_delete_app_resources_per_device() is used by oc_core_remove_device_at_index() in oc_core_res.c .

oc_resource_t *
oc_ri_get_app_resource_by_device(size_t device, bool reset)
{
static oc_resource_t *rsc;
Copy link
Member Author

Choose a reason for hiding this comment

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

I'd copy the semantics of g_query_iterator, so that we are consistent.

typedef struct {
  oc_resource_t *rsc;
#ifdef OC_COLLECTIONS
  oc_resource_t *coll_rsc;
#endif
} oc_ri_app_resource_iterator_t;

static oc_ri_app_resource_iterator_t g_app_resource_iterator;

void oc_ri_app_resource_iterator_init() {
  g_app_resource_iterator.rsc = oc_ri_get_app_resources();
#ifdef OC_COLLECTIONS
  g_app_resource_iterator.coll_rsc = oc_collection_get_collections();
#endif
}

oc_resource_t* oc_ri_app_resource_iterator_next_for_device(size_t device) {
  ...
}

We also need to mention that deleting / adding a resource (collection or non-collection) invalidates the iterator.


#ifdef OC_HAS_FEATURE_BRIDGE
oc_string_t
ecoversion; ///< Version of ecosystem that a Bridged Device belongs to.
Copy link
Member Author

Choose a reason for hiding this comment

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

Remove. I don't see this used anywhere in this PR, add it when its functionality is added.

Copy link
Collaborator

Choose a reason for hiding this comment

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

fixed

@Danielius1922
Copy link
Member Author

Renamed the feature branch to feature/ocfbridging , lets continue there and hopefully will bring the feature to master once all issues are solved.

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

Successfully merging this pull request may close these issues.

3 participants