Skip to content

Commit

Permalink
Merge pull request #464 from atsign-foundation/arduino-atlogger
Browse files Browse the repository at this point in the history
feat: Arduino atlogger
  • Loading branch information
XavierChanth authored Dec 7, 2024
2 parents dbec5d5 + b08407b commit cdc1f67
Show file tree
Hide file tree
Showing 29 changed files with 256 additions and 173 deletions.
33 changes: 18 additions & 15 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,26 @@ on:
pull_request:
branches: [trunk]

permissions: # added using https://github.com/step-security/secure-repo
permissions: # added using https://github.com/step-security/secure-repo
contents: read

jobs:
unit-tests:
runs-on: "ubuntu-latest"
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

- name: atsdk Unit CTest
- name: build atSDK
run: |
cmake -S . -B build -DATSDK_BUILD_TESTS=ON -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
cmake -S . -B build -DATSDK_BUILD_TESTS="unit"
cmake --build build --target all
ctest --test-dir build/packages/atchops/tests --output-on-failure --timeout 2
ctest --test-dir build/packages/atclient/tests --output-on-failure --timeout 2
- name: atchops Unit CTest
working-directory: build/packages/atchops/tests
run: ctest --test-dir . --output-on-failure --timeout 5

- name: atclient Unit CTest
working-directory: build/packages/atclient/tests
run: ctest --test-dir . --output-on-failure --timeout 5

functional-tests:
runs-on: "ubuntu-latest"
Expand All @@ -37,15 +42,13 @@ jobs:
- name: Install atSDK
run: |
cmake -S . -B build
cmake -S . -B build -DATSDK_BUILD_TESTS="func"
sudo cmake --build build --target install
- name: Build and Run Functional Tests
working-directory: tests/functional_tests
working-directory: build/tests/functional_tests
run: |
cmake -S . -B build
cmake --build build
ctest --test-dir build -VV --timeout 60
ctest --test-dir . -VV --timeout 90
build-examples:
runs-on: "ubuntu-latest"
Expand Down Expand Up @@ -73,19 +76,19 @@ jobs:
cmake -S . -B build -DTARGET_SRC=put_publickey.c && cmake --build build
cmake -S . -B build -DTARGET_SRC=put_selfkey.c && cmake --build build
cmake -S . -B build -DTARGET_SRC=put_sharedkey.c && cmake --build build
- name: Build events
working-directory: examples/desktop/events
run: |
cmake -S . -B build
cmake --build build
- name: Build pkam_authenticate
working-directory: examples/desktop/pkam_authenticate
run: |
cmake -S . -B build
cmake --build build
- name: Build REPL
working-directory: examples/desktop/repl
run: |
Expand All @@ -102,4 +105,4 @@ jobs:
working-directory: examples/desktop/sample_cmake_project
run: |
cmake -S . -B build -Datsdk="/usr/local/bin/cmake/atsdk"
cmake --build build
cmake --build build
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ lib/**/lib*.a

sdkconfig

Testing/

__pycache__/

.pio/
Expand Down
11 changes: 0 additions & 11 deletions .lazy.lua

This file was deleted.

2 changes: 1 addition & 1 deletion .vscode/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
*
!.gitignore
!c_cpp_properties.json
!settings.json

11 changes: 0 additions & 11 deletions .vscode/settings.json

This file was deleted.

37 changes: 33 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,26 @@
# Configurable options
set(TARGET_ESPIDF FALSE CACHE BOOL "Build for the espidf platform")
option(ATSDK_BUILD_TESTS "Build tests for atsdk" OFF)

option(ATSDK_BUILD_TESTS "Build tests for atsdk ON | \"unit\" | \"func\" " OFF)

# to avoid caching issues
if(ATSDK_BUILD_TESTS STREQUAL "func")
message("FUNCTIONAL TESTING ENABLED")
set(ATSDK_BUILD_UNIT_TESTS OFF)
set(ATSDK_BUILD_FUNCTIONAL_TESTS ON)
elseif(ATSDK_BUILD_TESTS STREQUAL "unit")
message("UNIT TESTING ENABLED")
set(ATSDK_BUILD_UNIT_TESTS ON)
set(ATSDK_BUILD_FUNCTIONAL_TESTS OFF)
elseif(ATSDK_BUILD_TESTS)
message("ALL TESTING ENABLED")
set(ATSDK_BUILD_FUNCTIONAL_TESTS ON)
set(ATSDK_BUILD_UNIT_TESTS ON)
else()
message("TESTING DISABLED")
set(ATSDK_BUILD_UNIT_TESTS OFF)
set(ATSDK_BUILD_FUNCTIONAL_TESTS OFF)
endif()

# Basic project setup
cmake_minimum_required(VERSION 3.24)
Expand Down Expand Up @@ -30,15 +50,15 @@ message(STATUS "Building atlogger")
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/packages/atlogger)

message(STATUS "Building atchops")
set(ATCHOPS_BUILD_TESTS ${ATSDK_BUILD_TESTS})
set(ATCHOPS_BUILD_TESTS ${ATSDK_BUILD_UNIT_TESTS})
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/packages/atchops)

message(STATUS "Building atclient")
set(ATCLIENT_BUILD_TESTS ${ATSDK_BUILD_TESTS})
set(ATCLIENT_BUILD_TESTS ${ATSDK_BUILD_UNIT_TESTS})
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/packages/atclient)

message(STATUS "Building atauth")
set(ATAUTH_BUILD_TESTS ${ATSDK_BUILD_TESTS})
set(ATAUTH_BUILD_TESTS ${ATSDK_BUILD_UNIT_TESTS})
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/packages/atauth)

if(NOT ESP_PLATFORM)
Expand Down Expand Up @@ -84,3 +104,12 @@ if(NOT ESP_PLATFORM)
)
endif()
endif()

if(ATSDK_BUILD_FUNCTIONAL_TESTS)
message(STATUS "Building functional tests")
add_subdirectory(${CMAKE_CURRENT_LIST_DIR}/tests/functional_tests)
endif()

if(ATSDK_BUILD_UNIT_TESTS OR ATSDK_BUILD_FUNCTIONAL_TESTS)
enable_testing()
endif()
2 changes: 2 additions & 0 deletions generators/arduino/atsdk/.clangd
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CompileFlags:
Add: [-xc++, -std=c++11]
4 changes: 0 additions & 4 deletions generators/arduino/atsdk/atsdk_atsdk.cpptemplate

This file was deleted.

26 changes: 21 additions & 5 deletions generators/arduino/atsdk/generate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -180,20 +180,32 @@ fix_rel_headers() {
}

public_headers() {
cat "$script_dir/atsdk.htemplate" >>$src_base/atsdk.h
cp $script_dir/lib/* $src_base/
for d in ${packages[@]}; do
local includes=$(
cd "$src_base/$d" &&
ls *.h
)
for f in $includes; do

echo "#include \"$d/$f\" // IWYU pragma: export" >>$src_base/atsdk.h
done
done
cp "$script_dir/atsdk_cjson.htemplate" $src_base/atsdk_cjson.h
cp "$script_dir/atsdk_cjson.ctemplate" $src_base/atsdk_cjson.c
cp "$script_dir/atsdk_atsdk.cpptemplate" $src_base/atsdk_atsdk.cpp
}

overrides() {
# logging
echo "#define ATLOGGER_OVERRIDE_LOG_FUNCTION" >>$src_base/atlogger/atlogger.h
# json
{
echo "#define ATCOMMONS_JSON_PROVIDER_CJSON"
echo "#include <atsdk_cjson.h>"
} >>$src_base/atcommons/json.h
# platform
{
echo '#define PRIu64 "llu"'
echo "#define ATCHOPS_TARGET_ARDUINO"
echo "#define ATCHOPS_MBEDTLS_VERSION_2"
} >>$src_base/atchops/platform.h
}

echo "Cleaning generated files and folders"
Expand Down Expand Up @@ -228,6 +240,9 @@ public_headers
echo "Fixing all includes to be relative"
fix_rel_headers

echo "Applying Arduino specific overrides"
overrides

echo "Done generating Arduino library"

# functions
Expand All @@ -236,6 +251,7 @@ unset clean
unset gen_src
unset public_headers
unset fix_rel_headers
unset overrides

# global variables
unset script_dir
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@

#ifndef ATSDK_ARDUINO_H
#define ATSDK_ARDUINO_H

#ifdef __cplusplus
extern "C" {
#endif

#include <ctype.h>
#define ATLOGGER_DISABLE_TIMESTAMPS
#include <ctype.h> // IWYU pragma: export

#ifdef __cplusplus
}
Expand Down
43 changes: 43 additions & 0 deletions generators/arduino/atsdk/lib/atsdk_atsdk.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// For both development and compile time
#include "atsdk.h"
#include <cstdarg>
#include <cstdio>
#include <cstdlib>

#ifdef __clang__ // For development to supress irrelevant errors
#include "../../../../packages/atlogger/include/atlogger/atlogger.h"
class DummySerial {
public:
void print(const char *);
void println(const char *);
};
extern DummySerial Serial;

#else // Actual compile time includes
#include <Arduino.h>
#endif

void atsdk_arduino_setup() {}

extern "C" {
void atlogger_log(const char *tag, const enum atlogger_logging_level level, const char *format, ...) {
atlogger_logging_level allowed_level = atlogger_get_logging_level();
if (level > allowed_level) {
return;
}

va_list args;
va_start(args, format);
if (tag != nullptr) {
Serial.print(tag);
Serial.print(" | ");
}
int len = vsnprintf(NULL, 0, format, args);
char *buf = new char[len + 1];
vsnprintf(buf, len, format, args);
Serial.print(buf);
delete[] buf;

va_end(args);
}
}
File renamed without changes.
File renamed without changes.
4 changes: 0 additions & 4 deletions packages/atchops/include/atchops/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,5 @@
#elif defined(CONFIG_IDF_TARGET_ESP32)
#define ATCHOPS_TARGET_ESPIDF

#elif defined(TARGET_PORTENTA_H7)
#define ATCHOPS_TARGET_ARDUINO
#define ATCHOPS_MBEDTLS_VERSION_2

#endif
#endif
22 changes: 16 additions & 6 deletions packages/atchops/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
option(FIRST_ATSIGN "First atSign used for all functional tests")
if(${FIRST_ATSIGN})
add_compile_definitions(FIRST_ATSIGN)
endif()

option(SECOND_ATSIGN "Second atSign for two-way atSign functional tests")
if(${SECOND_ATSIGN})
add_compile_definitions(SECOND_ATSIGN)
endif()

# loop through every .c file in this directory
file(GLOB_RECURSE files ${CMAKE_CURRENT_LIST_DIR}/test_*.c)

foreach(file ${files})
# ${filename} - without `.c`
get_filename_component(filename ${file} NAME)
string(REPLACE ".c" "" filename ${filename})
# ${filename} - without `.c`
get_filename_component(filename ${file} NAME)
string(REPLACE ".c" "" filename ${filename})

add_executable(${filename} ${file})
target_link_libraries(${filename} PRIVATE atchops atlogger)
add_test(NAME ${filename} COMMAND $<TARGET_FILE:${filename}>)
add_executable(${filename} ${file})
target_link_libraries(${filename} PRIVATE atchops atlogger)
add_test(NAME ${filename} COMMAND $<TARGET_FILE:${filename}>)
endforeach()
Loading

0 comments on commit cdc1f67

Please sign in to comment.