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

Link to system mbedtls #356

Merged
merged 3 commits into from
Jan 31, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update github workflows
- Allow compilation will clang
- Make tests that use CMake to build configurable, so they can be
built in such a way that they preinstall mbedTLS and then use the
preinstalled libraries.
  • Loading branch information
Danielius1922 committed Jan 31, 2023
commit f735d3db7a93a2671e633040a9ba7ad307fa8379
17 changes: 16 additions & 1 deletion .github/workflows/cmake-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@ on:

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
inputs:
clang:
description: "Compile using clang"
required: false
type: boolean
default: false
install_mbedtls:
description: "Install mbedTLS and use it for the build"
required: false
type: boolean
default: false

jobs:
cmake_linux:
Expand Down Expand Up @@ -52,7 +63,9 @@ jobs:
with:
build_args: ${{ matrix.args }}
build_type: Debug
clang: ${{ github.event_name == 'workflow_dispatch' && inputs.clang }}
coverage: false
install_mbedtls: ${{ github.event_name == 'workflow_dispatch' && inputs.install_mbedtls }}

cmake_linux_sanitized:
strategy:
Expand All @@ -71,6 +84,8 @@ jobs:
# - args: -DOC_MSAN_ENABLED=ON
uses: ./.github/workflows/unit-test-with-cfg.yml
with:
build_args: "-DOC_CLOUD_ENABLED=ON -DOC_COLLECTIONS_IF_CREATE_ENABLED=ON -DOC_MNT_ENABLED=ON -DOC_WKCORE_ENABLED=ON -DOC_SOFTWARE_UPDATE_ENABLED=ON -DOC_PUSH_ENABLED=ON -DOC_RESOURCE_ACCESS_IN_RFOTM_ENABLED=ON ${{ matrix.args }}"
build_args: -DOC_CLOUD_ENABLED=ON -DOC_COLLECTIONS_IF_CREATE_ENABLED=ON -DOC_MNT_ENABLED=ON -DOC_WKCORE_ENABLED=ON -DOC_SOFTWARE_UPDATE_ENABLED=ON -DOC_PUSH_ENABLED=ON -DOC_RESOURCE_ACCESS_IN_RFOTM_ENABLED=ON ${{ matrix.args }}
build_type: Debug
clang: ${{ github.event_name == 'workflow_dispatch' && inputs.clang }}
coverage: false
install_mbedtls: ${{ github.event_name == 'workflow_dispatch' && inputs.install_mbedtls }}
39 changes: 19 additions & 20 deletions .github/workflows/cmake-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ on:
pull_request:
branches: [master]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

jobs:
build:
name: ${{ matrix.config.name }}
Expand Down Expand Up @@ -185,23 +188,19 @@ jobs:
run: |
set(ENV{NINJA_STATUS} "[%f/%t %o/sec] ")

if ("${{ runner.os }}" STREQUAL "Windows" AND NOT "x${{ matrix.config.environment_script }}" STREQUAL "x")
file(STRINGS environment_script_output.txt output_lines)
foreach(line IN LISTS output_lines)
if (line MATCHES "^([a-zA-Z0-9_-]+)=(.*)$")
set(ENV{${CMAKE_MATCH_1}} "${CMAKE_MATCH_2}")
endif()
endforeach()
endif()

if (NOT result EQUAL 0)
message(STATUS "${output}")
endif()

execute_process(
COMMAND ${{ steps.cmake_and_ninja.outputs.cmake_dir }}/ctest --verbose --label-regex "oc-unittest"
RESULT_VARIABLE result
)
if (NOT result EQUAL 0)
message(FATAL_ERROR "Bad exit status")
endif()
if ("${{ runner.os }}" STREQUAL "Windows" AND NOT "x${{ matrix.config.environment_script }}" STREQUAL "x")
file(STRINGS environment_script_output.txt output_lines)
foreach(line IN LISTS output_lines)
if (line MATCHES "^([a-zA-Z0-9_-]+)=(.*)$")
set(ENV{${CMAKE_MATCH_1}} "${CMAKE_MATCH_2}")
endif()
endforeach()
endif()

execute_process(
COMMAND ${{ steps.cmake_and_ninja.outputs.cmake_dir }}/ctest --verbose --label-regex "oc-unittest"
RESULT_VARIABLE result
)
if (NOT result EQUAL 0)
message(FATAL_ERROR "Bad exit status")
endif()
3 changes: 3 additions & 0 deletions .github/workflows/sonar-cloud-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ on:
pull_request:
types: [opened, synchronize, reopened]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

jobs:
unit-tests:
strategy:
Expand Down
33 changes: 29 additions & 4 deletions .github/workflows/unit-test-with-cfg.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,18 @@ on:
type: string
required: false
default: Debug
clang:
type: boolean
required: false
default: false
coverage:
type: boolean
required: false
default: false
install_mbedtls:
type: boolean
required: false
default: false
jobs:
unit-test-with-cfg:
runs-on: ubuntu-22.04
Expand All @@ -29,11 +37,28 @@ jobs:
with:
submodules: "true"

- name: CMake flags
id: cmake_flags
if: ${{ inputs.clang }}
run: |
echo compiler='-DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang' >> $GITHUB_OUTPUT

- name: Install mbedTLS
if: ${{ inputs.install_mbedtls }}
run: |
mkdir build_mbedtls && cd build_mbedtls
cmake -DCMAKE_VERBOSE_MAKEFILE=ON -DCMAKE_BUILD_TYPE=${{ inputs.build_type }} ${{ steps.cmake_flags.outputs.compiler }} ${{ inputs.build_args }} -DBUILD_TESTING=OFF ..
OC_SECURITY_ENABLED=$(cmake -LA -N . | grep OC_SECURITY_ENABLED | cut -d "=" -f2)
if [ "${OC_SECURITY_ENABLED}" = "ON" ]; then
make mbedtls mbedx509 mbedcrypto
cd deps/mbedtls
sudo make install
fi

- name: Build unit tests
run: |
mkdir build
cd build
cmake -DCMAKE_VERBOSE_MAKEFILE=ON -DCMAKE_BUILD_TYPE=${{ inputs.build_type }} ${{ inputs.build_args }} -DBUILD_TESTING=ON ..
mkdir build && cd build
cmake -DCMAKE_VERBOSE_MAKEFILE=ON -DCMAKE_BUILD_TYPE=${{ inputs.build_type }} ${{ steps.cmake_flags.outputs.compiler }} ${{ inputs.build_args }} ${{ inputs.install_mbedtls && '-DBUILD_MBEDTLS=OFF' || '' }} -DBUILD_TESTING=ON ..
make oc-unittests

- name: Run unit tests
Expand All @@ -45,7 +70,7 @@ jobs:
if: ${{ inputs.coverage }}
id: coverage
run: |
SUFFIX=`echo "-DCMAKE_BUILD_TYPE=${{ inputs.build_type }} ${{ inputs.build_args }} -DBUILD_TESTING=ON" | sha1sum | cut -f 1 -d ' '`
SUFFIX=`echo "-DCMAKE_BUILD_TYPE=${{ inputs.build_type }} ${{ steps.cmake_flags.outputs.compiler }} ${{ inputs.build_args }} -DBUILD_TESTING=ON" | sha1sum | cut -f 1 -d ' '`
echo "filename=coverage-unix-${SUFFIX}.json" >> $GITHUB_OUTPUT

- name: Collect coverage data
Expand Down
8 changes: 4 additions & 4 deletions api/oc_endpoint.c
Original file line number Diff line number Diff line change
Expand Up @@ -345,17 +345,17 @@ oc_parse_ipv6_address(const char *address, size_t len, oc_endpoint_t *endpoint)
int i = addr_idx - 1;
addr_idx = OC_IPV6_ADDRLEN - 1;
while (i >= split) {
#ifdef __GNUC__
#if defined(__GNUC__) && !defined(__clang__)
// GCC thinks that addr has size=4 instead of size=16 and complains about
// overflow
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wstringop-overflow"
#endif // __GNUC__
#endif // __GNUC__ && !__clang__
addr[addr_idx] = addr[i];
addr[i] = 0;
#ifdef __GNUC__
#if defined(__GNUC__) && !defined(__clang__)
#pragma GCC diagnostic pop
#endif // __GNUC__
#endif // __GNUC__ && !__clang__
i--;
addr_idx--;
}
Expand Down
2 changes: 1 addition & 1 deletion api/oc_enums.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,4 @@ oc_str_to_enum_locn(oc_string_t locn_str, bool *oc_defined)
}
}
return locn;
}
}
20 changes: 11 additions & 9 deletions api/oc_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ oc_main_init(const oc_handler_t *handler)
if (!drop_commands) {
oc_abort("Insufficient memory");
}
#endif
#endif /* OC_DYNAMIC_ALLOCATION */

#ifdef OC_SECURITY
ret = oc_tls_init_context();
Expand All @@ -291,7 +291,7 @@ oc_main_init(const oc_handler_t *handler)

#ifdef OC_SECURITY
oc_sec_create_svr();
#endif
#endif /* OC_SECURITY */

#ifdef OC_SOFTWARE_UPDATE
oc_swupdate_init();
Expand Down Expand Up @@ -320,7 +320,7 @@ oc_main_init(const oc_handler_t *handler)
OC_DBG("oc_main_init(): loading sdi");
oc_sec_load_sdi(device);
}
#endif
#endif /* OC_SECURITY */

#if defined(OC_CLIENT) && defined(OC_SERVER) && defined(OC_CLOUD)
// initialize cloud after load pstat
Expand All @@ -332,7 +332,7 @@ oc_main_init(const oc_handler_t *handler)
// initialize after cloud because their can be registered to cloud.
if (app_callbacks->register_resources)
app_callbacks->register_resources();
#endif
#endif /* OC_SERVER */

OC_DBG("oc_main: stack initialized");

Expand All @@ -341,7 +341,7 @@ oc_main_init(const oc_handler_t *handler)
#ifdef OC_CLIENT
if (app_callbacks->requests_entry)
app_callbacks->requests_entry();
#endif
#endif /* OC_CLIENT */

return 0;

Expand All @@ -350,7 +350,7 @@ oc_main_init(const oc_handler_t *handler)
#ifdef OC_DYNAMIC_ALLOCATION
free(drop_commands);
drop_commands = NULL;
#endif
#endif /* OC_DYNAMIC_ALLOCATION */
return ret;
}

Expand Down Expand Up @@ -382,7 +382,7 @@ oc_main_shutdown(void)

#ifdef OC_HAS_FEATURE_PUSH
oc_push_free();
#endif
#endif /* OC_HAS_FEATURE_PUSH */

oc_ri_shutdown();

Expand All @@ -409,9 +409,9 @@ oc_main_shutdown(void)
#ifdef OC_DYNAMIC_ALLOCATION
free(drop_commands);
drop_commands = NULL;
#else
#else /* !OC_DYNAMIC_ALLOCATION */
memset(drop_commands, 0, sizeof(bool) * OC_MAX_NUM_DEVICES);
#endif
#endif /* OC_DYNAMIC_ALLOCATION */

app_callbacks = NULL;

Expand All @@ -437,9 +437,11 @@ _oc_signal_event_loop(void)
void
oc_set_drop_commands(size_t device, bool drop)
{
#ifdef OC_DYNAMIC_ALLOCATION
if (drop_commands == NULL) {
return;
}
#endif /* OC_DYNAMIC_ALLOCATION */
drop_commands[device] = drop;
}

Expand Down
13 changes: 7 additions & 6 deletions messaging/coap/coap.c
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ coap_serialize_signal_options(void *packet, uint8_t *option_array)
}

if (option) {
OC_DBG("-Done serializing at %p----", option);
OC_DBG("-Done serializing at %p----", (void *)option);
}

return option_length;
Expand All @@ -399,7 +399,7 @@ coap_serialize_options(void *packet, uint8_t *option_array, bool inner,

#ifdef OC_DEBUG
if (option) {
OC_DBG("Serializing options at %p", option);
OC_DBG("Serializing options at %p", (void *)option);
} else {
OC_DBG("Calculating size of options");
}
Expand Down Expand Up @@ -528,7 +528,7 @@ coap_serialize_options(void *packet, uint8_t *option_array, bool inner,
}

if (option) {
OC_DBG("-Done serializing at %p----", option);
OC_DBG("-Done serializing at %p----", (void *)option);
}

return option_length;
Expand Down Expand Up @@ -1099,7 +1099,7 @@ coap_oscore_serialize_message(void *packet, uint8_t *buffer, bool inner,
bool outer, bool oscore)
{
if (!packet || !buffer) {
OC_ERR("packet: %p or buffer: %p is NULL", packet, buffer);
OC_ERR("packet: %p or buffer: %p is NULL", packet, (void *)buffer);
return 0;
}

Expand Down Expand Up @@ -1164,14 +1164,15 @@ coap_oscore_serialize_message(void *packet, uint8_t *buffer, bool inner,
goto exit;
}

OC_DBG("-Serializing MID %u to %p", coap_pkt->mid, coap_pkt->buffer);
OC_DBG("-Serializing MID %u to %p", coap_pkt->mid,
(void *)coap_pkt->buffer);
coap_udp_set_header_fields(coap_pkt);
}
}

/* empty packet, dont need to do more stuff */
if (outer && !coap_pkt->code) {
OC_DBG("Done serializing empty message at %p-", coap_pkt->buffer);
OC_DBG("Done serializing empty message at %p-", (void *)coap_pkt->buffer);
return token_location;
} else if (outer) {
if (oscore) {
Expand Down
6 changes: 3 additions & 3 deletions messaging/coap/coap_signal.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
*
****************************************************************************/

#ifndef COAP_SIGANAL_H
#define COAP_SIGANAL_H
#ifndef COAP_SIGNAL_H
#define COAP_SIGNAL_H

#include "oc_endpoint.h"

Expand Down Expand Up @@ -79,4 +79,4 @@ int coap_signal_set_bad_csm(void *packet, uint16_t opt);
}
#endif

#endif /* COAP_SIGANAL_H */
#endif /* COAP_SIGNAL_H */
10 changes: 7 additions & 3 deletions python/oc_python.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,17 @@ struct py_cb_struct
*/
struct py_cb_struct my_CBFunctions;

#if 0

/**
* Function to return response strings
*
*/

static inline char *
stringFromResponse(int code)
{
static char *strings[] = { "STATUS_OK",
"STATUS_CREATED"
"STATUS_CREATED",
"STATUS_CHANGED",
"STATUS_DELETED",
"STATUS_NOT_MODIFIED",
Expand All @@ -134,10 +135,13 @@ stringFromResponse(int code)
"STATUS_PROXYING_NOT_SUPPORTED",
"__NUM_STATUS_CODES__",
"IGNORE",
"PING_TIMEOUT" };
"PING_TIMEOUT",
"OC_REQUEST_TIMEOUT" };
return strings[code];
}

#endif

void
install_changedCB(changedCB changedCB)
{
Expand Down