Skip to content

Commit

Permalink
fixup! Migrate device provisioning service
Browse files Browse the repository at this point in the history
  • Loading branch information
Danielius1922 committed Sep 6, 2024
1 parent f7dac75 commit f9b0d8e
Show file tree
Hide file tree
Showing 31 changed files with 4,634 additions and 103 deletions.
6 changes: 5 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
.github/
.clang-format
.clang-tidy
**/*.o
**/*.gcno
**/*.gcda
sonar-project.properties
Dockerfile.*
build/
build*/
docker/
images/
port/esp32/build/
port/esp32/esp-idf/
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/cmake-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ jobs:
- args: "-DOC_IPV4_ENABLED=ON -DOC_TCP_ENABLED=ON -DOC_PKI_ENABLED=OFF"
# cloud on (ipv4+tcp on), dynamic allocation off, push notifications off
- args: "-DOC_CLOUD_ENABLED=ON -DOC_DYNAMIC_ALLOCATION_ENABLED=OFF -DOC_PUSH_ENABLED=OFF"
# cloud on (ipv4+tcp on), collections create on, oscore off, device provisioning on
- args: "-DOC_CLOUD_ENABLED=ON -DOC_COLLECTIONS_IF_CREATE_ENABLED=ON -DOC_OSCORE_ENABLED=OFF -DPLGD_DEV_DEVICE_PROVISIONING_ENABLED=ON"
# cloud on (ipv4+tcp on), collections create on
- args: "-DOC_CLOUD_ENABLED=ON -DOC_COLLECTIONS_IF_CREATE_ENABLED=ON"
# cloud on (ipv4+tcp on), collections create on, custom message buffer size, custom message buffer pool size, custom app data buffer size, custom app data buffer pool size
- args: "-DOC_CLOUD_ENABLED=ON -DOC_COLLECTIONS_IF_CREATE_ENABLED=ON -DOC_INOUT_BUFFER_SIZE=2048 -DOC_INOUT_BUFFER_POOL=4 -DOC_APP_DATA_BUFFER_SIZE=2048 -DOC_APP_DATA_BUFFER_POOL=4"
# debug on
- args: "-DOC_DEBUG_ENABLED=ON"
# debug on, cloud on (ipv4+tcp on)
# debug on, cloud on (ipv4+tcp on), plgd time off
- args: "-DOC_CLOUD_ENABLED=ON -DPLGD_DEV_TIME_ENABLED=OFF -DOC_DEBUG_ENABLED=ON"
# secure off, tcp on
- args: "-DOC_SECURITY_ENABLED=OFF -DOC_TCP_ENABLED=ON"
Expand Down Expand Up @@ -138,7 +138,7 @@ jobs:
# install_faketime: true
uses: ./.github/workflows/unit-test-with-cfg.yml
with:
build_args: -DOC_LOG_MAXIMUM_LOG_LEVEL=INFO -DOC_CLOUD_ENABLED=ON -DOC_COLLECTIONS_IF_CREATE_ENABLED=ON -DOC_MNT_ENABLED=ON -DOC_WKCORE_ENABLED=ON -DOC_SOFTWARE_UPDATE_ENABLED=ON -DOC_DISCOVERY_RESOURCE_OBSERVABLE_ENABLED=ON -DOC_PUSH_ENABLED=ON -DOC_RESOURCE_ACCESS_IN_RFOTM_ENABLED=ON -DPLGD_DEV_TIME_ENABLED=ON -DOC_ETAG_ENABLED=ON ${{ matrix.args }}
build_args: -DOC_LOG_MAXIMUM_LOG_LEVEL=INFO -DOC_CLOUD_ENABLED=ON -DOC_COLLECTIONS_IF_CREATE_ENABLED=ON -DOC_MNT_ENABLED=ON -DOC_WKCORE_ENABLED=ON -DOC_SOFTWARE_UPDATE_ENABLED=ON -DOC_DISCOVERY_RESOURCE_OBSERVABLE_ENABLED=ON -DOC_PUSH_ENABLED=ON -DOC_RESOURCE_ACCESS_IN_RFOTM_ENABLED=ON -DPLGD_DEV_TIME_ENABLED=ON -DOC_ETAG_ENABLED=ON -DPLGD_DEV_DEVICE_PROVISIONING_ENABLED=ON -DPLGD_DEV_DEVICE_PROVISIONING_TEST_PROPERTIES_ENABLED=ON ${{ matrix.args }}
build_type: ${{ (github.event_name == 'workflow_dispatch' && inputs.build_type) || 'Debug' }}
clang: ${{ ((github.event_name == 'workflow_dispatch' && inputs.clang) || matrix.clang) || false }}
coverage: false
Expand Down
145 changes: 145 additions & 0 deletions .github/workflows/plgd-dps-test-with-cfg.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

name: Run plgd/dps tests with dps_cloud_server and a single configuration

on:
workflow_call:
inputs:
build_args:
description: build arguments forwarded to CMake in docker/apps/Dockerfile.cloud-server-debug
type: string
required: true
build_type:
type: string
required: false
default: Debug
skip:
description: Skip this run of the job
type: boolean
required: false
default: false
env:
TEST_DPS_IMAGE: ghcr.io/plgd-dev/hub/test-device-provisioning-service:latest
DPS_DOCKER_TAG: dbg

jobs:
plgd-hub-test-with-cfg:
if: ${{ !inputs.skip }}
runs-on: ubuntu-22.04
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
submodules: "true"

- name: Configure vm.mmap_rnd_bits for sanitizers
if: contains(inputs.build_args, 'OC_ASAN_ENABLED') || contains(inputs.build_args, 'OC_LSAN_ENABLED') || contains(inputs.build_args, 'OC_TSAN_ENABLED') || contains(inputs.build_args, 'OC_UBSAN_ENABLED')
run: |
sudo sysctl vm.mmap_rnd_bits
sudo sysctl -w vm.mmap_rnd_bits=28
- name: Build dps-cloudserver docker image
uses: docker/build-push-action@v5
with:
context: .
push: false
build-args: |
BUILD_ARGS=${{ inputs.build_args }}
BUILD_TYPE=${{ inputs.build_type }}
file: docker/apps/Dockerfile.dps-cloud-server
tags: ${{ env.DPS_DOCKER_TAG }}

- name: Pull device-provisioning-service tests image
run: docker pull ${{ env.TEST_DPS_IMAGE }}

- name: Prepare test environment
run: >
docker run --rm --log-driver local --network=host
-e PREPARE_ENV=true
-e RUN=false
-v /tmp/data:/data
-v /var/run/docker.sock:/var/run/docker.sock
${{ env.TEST_DPS_IMAGE }}
- name: Run dps cloud server docker image
run: >
mkdir -p "/tmp/data/coverage";
chmod -R 0777 "/tmp/data/coverage";
docker run --privileged -d --network=host --log-driver local
-v /tmp/data/certs/device:/device-provisioning-client/build/apps/pki_certs
-v /tmp/data/coverage:/data/coverage
--name dps-devsim
dps-dbg:latest
--create-conf-resource
--no-verify-ca
--cloud-observer-max-retry 10
--expiration-limit 10
--retry-configuration 5
--log-level="debug"
--wait-for-reset
dps-devsim-$(hostname)
- name: Run dps cloud server docker image for onboarding
run: >
docker run --privileged -d --network=host --log-driver local
-v /tmp/data/certs/device:/device-provisioning-client/build/apps/pki_certs
-v /tmp/data/coverage:/data/coverage
--name dps-devsim-obt
dps-dbg:latest
--create-conf-resource
--cloud-observer-max-retry 10
--expiration-limit 10
--retry-configuration 5
--log-level="debug"
dps-devsim-obt-$(hostname) ""
- name: Run device-provisioning-service tests image
run: >
docker run --rm --log-driver local --network=host --hostname=$(hostname)
-e PREPARE_ENV=false
-e RUN=true
-v /tmp/data:/data
-v /var/run/docker.sock:/var/run/docker.sock
--name dps-tests
${{ env.TEST_DPS_IMAGE }}
- name: Gather coverage data
run: |
# stop to generate .gcda files
docker stop dps-devsim
# restart to generate report from the .gcda files
docker start dps-devsim
docker exec --workdir "/device-provisioning-client/tools" dps-devsim /bin/bash -c "./collect-coverage.sh --output /data/coverage/coverage.json"
docker stop dps-devsim
# stop to generate .gcda files
docker stop dps-devsim-obt
# restart to generate report from the .gcda files
docker start dps-devsim-obt
docker exec --workdir "/device-provisioning-client/tools" dps-devsim-obt /bin/bash -c "./collect-coverage.sh --output /data/coverage/coverage-obt.json"
docker exec --workdir "/data/coverage" dps-devsim-obt /bin/bash -c 'gcovr --add-tracefile "./*json" --sonarqube --output "/data/coverage/coverage.xml" --verbose'
docker stop dps-devsim-obt
- name: Upload coverage data
uses: actions/upload-artifact@v4
with:
name: dps-client-coverage
path: /tmp/data/coverage/coverage.xml
if-no-files-found: error
retention-days: 1

- name: Collect dps cloud server logs when the test fails
if: ${{ failure() }}
run: |
docker stop dps-devsim
docker logs dps-devsim
- name: Collect dps cloud server (obt) logs when the test fails
if: ${{ failure() }}
run: |
docker stop dps-devsim-obt
docker logs dps-devsim-obt
34 changes: 34 additions & 0 deletions .github/workflows/plgd-dps-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.

name: Run plgd/hub tests with dps_cloud_server

on:
# Triggers the workflow on push or pull request events but only for the master branch
push:
# branches: [master]
# pull_request:
# branches: [master]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
inputs:
build_type:
description: "Type of the build"
type: string
default: "Debug"

jobs:
plgd-hub-test:
strategy:
fail-fast: false
matrix:
include:
- build_args: ""
uses: ./.github/workflows/plgd-dps-test-with-cfg.yml
with:
build_args: ${{ matrix.build_args }}
build_type: ${{ (github.event_name == 'workflow_dispatch' && inputs.build_type) || (matrix.build_type || 'Debug') }}
skip: ${{ matrix.skip || false }}
18 changes: 9 additions & 9 deletions .github/workflows/sonar-cloud-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ concurrency:
cancel-in-progress: ${{ github.ref_name != 'master' }}

on:
# push:
# branches:
# - master
# pull_request:
# types: [opened, synchronize, reopened]
push:
branches:
- master
pull_request:
types: [opened, synchronize, reopened]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
Expand All @@ -25,8 +25,8 @@ jobs:
fail-fast: false
matrix:
include:
# cloud (ipv4+tcp) on, collection create on, push on, rfotm on
- build_args: "-DOC_CLOUD_ENABLED=ON -DOC_COLLECTIONS_IF_CREATE_ENABLED=ON -DOC_PUSH_ENABLED=ON -DOC_RESOURCE_ACCESS_IN_RFOTM_ENABLED=ON"
# cloud (ipv4+tcp) on, collection create on, push on, rfotm on, device provisioning on
- build_args: "-DOC_CLOUD_ENABLED=ON -DOC_COLLECTIONS_IF_CREATE_ENABLED=ON -DOC_PUSH_ENABLED=ON -DOC_RESOURCE_ACCESS_IN_RFOTM_ENABLED=ON -DPLGD_DEV_DEVICE_PROVISIONING_ENABLED=ON -DPLGD_DEV_DEVICE_PROVISIONING_TEST_PROPERTIES_ENABLED=ON"
# security off, ipv4 on, collection create on, push on, max num concurrent requests=1
- build_args: "-DOC_SECURITY_ENABLED=OFF -DOC_IPV4_ENABLED=ON -DOC_COLLECTIONS_IF_CREATE_ENABLED=ON -DOC_PUSH_ENABLED=ON -DOC_DEVICE_MAX_NUM_CONCURRENT_REQUESTS=1"
# ipv6 dns on, oscore off, rep realloc on, json encoder on, introspection IDD off
Expand Down Expand Up @@ -110,7 +110,7 @@ jobs:
mkdir build && cd build
# sonar-scanner currently cannot handle multi configuration configuration (ie. compilation of the same file with different defines),
# so we enable as many features as possible so we get max. amount of code analysis
cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_VERBOSE_MAKEFILE=ON -DOC_CLOUD_ENABLED=ON -DOC_COLLECTIONS_IF_CREATE_ENABLED=ON -DOC_MNT_ENABLED=ON -DOC_WKCORE_ENABLED=ON -DOC_SOFTWARE_UPDATE_ENABLED=ON -DOC_DISCOVERY_RESOURCE_OBSERVABLE_ENABLED=ON -DOC_PUSH_ENABLED=ON -DOC_RESOURCE_ACCESS_IN_RFOTM_ENABLED=ON -DPLGD_DEV_TIME_ENABLED=ON -DOC_ETAG_ENABLED=ON -DOC_JSON_ENCODER_ENABLED=ON -DBUILD_TESTING=ON ..
cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_VERBOSE_MAKEFILE=ON -DOC_CLOUD_ENABLED=ON -DOC_COLLECTIONS_IF_CREATE_ENABLED=ON -DOC_MNT_ENABLED=ON -DOC_WKCORE_ENABLED=ON -DOC_SOFTWARE_UPDATE_ENABLED=ON -DOC_DISCOVERY_RESOURCE_OBSERVABLE_ENABLED=ON -DOC_PUSH_ENABLED=ON -DOC_RESOURCE_ACCESS_IN_RFOTM_ENABLED=ON -DPLGD_DEV_TIME_ENABLED=ON -DOC_ETAG_ENABLED=ON -DOC_JSON_ENCODER_ENABLED=ON -DPLGD_DEV_TIME_ENABLED=ON -DPLGD_DEV_DEVICE_PROVISIONING_ENABLED=ON -DBUILD_TESTING=ON ..
cd ..
# for files defined in multiple cmake targets, sonar-scanner seems to take the configuration from the first compilation of the file,
# so we force client-server target to be compiled first so we get analysis of code with both OC_CLIENT and OC_SERVER enabled
Expand Down Expand Up @@ -138,4 +138,4 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: |
sonar-scanner --define sonar.cfamily.build-wrapper-output="${{ env.BUILD_WRAPPER_OUT_DIR }}"
sonar-scanner --define sonar.cfamily.compile-commands="${{ env.BUILD_WRAPPER_OUT_DIR }}/compile_commands.json"
3 changes: 1 addition & 2 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ jobs:
fail-fast: false
matrix:
include:
- build_args:
- build_args: -DOC_OSCORE_ENABLED=OFF -DPLGD_DEV_TIME_ENABLED=ON -DPLGD_DEV_DEVICE_PROVISIONING_ENABLED=ON
- build_args: -DPLGD_DEV_TIME_ENABLED=ON -DPLGD_DEV_DEVICE_PROVISIONING_ENABLED=ON
- build_args: -DOC_DYNAMIC_ALLOCATION_ENABLED=OFF -DOC_PUSH_ENABLED=OFF -DOC_JSON_ENCODER_ENABLED=OFF -DOC_DEBUG_ENABLED=ON

runs-on: ubuntu-22.04
Expand Down
8 changes: 8 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ set(OC_DEVICE_MAX_NUM_CONCURRENT_REQUESTS "" CACHE STRING "Maximum number of mes
# plgd.dev features
set(PLGD_DEV_TIME_ENABLED OFF CACHE BOOL "Enable plgd time feature.")
set(PLGD_DEV_DEVICE_PROVISIONING_ENABLED OFF CACHE BOOL "Enable plgd's device provisioning feature.")
set(PLGD_DEV_DEVICE_PROVISIONING_TEST_PROPERTIES_ENABLED OFF CACHE BOOL "Enable plgd's device provisioning feature's test properties.")

set(OC_ASAN_ENABLED OFF CACHE BOOL "Enable address sanitizer build.")
set(OC_LSAN_ENABLED OFF CACHE BOOL "Enable leak sanitizer build.")
Expand Down Expand Up @@ -427,6 +428,13 @@ if(PLGD_DEV_DEVICE_PROVISIONING_ENABLED)
list(APPEND PUBLIC_COMPILE_DEFINITIONS "PLGD_DEV_DEVICE_PROVISIONING")
endif()

if(PLGD_DEV_DEVICE_PROVISIONING_TEST_PROPERTIES_ENABLED)
list(APPEND PRIVATE_COMPILE_DEFINITIONS "PLGD_DPS_RESOURCE_TEST_PROPERTIES")
if(BUILD_TESTING)
list(APPEND TEST_COMPILE_DEFINITIONS "PLGD_DPS_RESOURCE_TEST_PROPERTIES")
endif()
endif()

if(BUILD_TESTING)
list(APPEND PRIVATE_COMPILE_DEFINITIONS "OC_TEST")
if(BUILD_MBEDTLS)
Expand Down
3 changes: 1 addition & 2 deletions api/plgd/device-provisioning-client/plgd_dps.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,7 @@ dps_ep_session_event_handler(const oc_endpoint_t *endpoint,
DPS_DBG("dps_ep_session_event_handler cloud_state: %d", (int)state);
if (state == OC_SESSION_DISCONNECTED &&
oc_cloud_manager_is_started(cloud_ctx)) {
// TODO
// dps_cloud_observe_status(ctx);
dps_cloud_observe_status(ctx);
}
return;
}
Expand Down
3 changes: 2 additions & 1 deletion api/plgd/device-provisioning-client/plgd_dps_context.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "plgd_dps_resource_internal.h"
#include "plgd_dps_store_internal.h"

#include "api/cloud/oc_cloud_schedule_internal.h"
#include "oc_endpoint.h"
#include "oc_session_events.h"
#include "util/oc_list.h"
Expand Down Expand Up @@ -61,7 +62,7 @@ dps_context_list_add(plgd_dps_context_t *ctx)
}

void
dps_context_list_remove(plgd_dps_context_t *ctx)
dps_context_list_remove(const plgd_dps_context_t *ctx)
{
oc_list_remove(g_dps_context_list, ctx);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ void dps_context_free(plgd_dps_context_t *ctx) OC_NONNULL();
void dps_context_list_add(plgd_dps_context_t *ctx) OC_NONNULL();

/// @brief Remove from global lists of contexts
void dps_context_list_remove(plgd_dps_context_t *ctx) OC_NONNULL();
void dps_context_list_remove(const plgd_dps_context_t *ctx) OC_NONNULL();

/// @brief Check if the global lists of contexts is empty
bool dps_context_list_is_empty(void);
Expand Down
Loading

0 comments on commit f9b0d8e

Please sign in to comment.