Skip to content

Commit

Permalink
Memfault Firmware SDK 0.31.3 (Build 474047)
Browse files Browse the repository at this point in the history
  • Loading branch information
Memfault Inc committed Jul 9, 2022
1 parent 73fab86 commit ae5b690
Show file tree
Hide file tree
Showing 13 changed files with 155 additions and 26 deletions.
69 changes: 69 additions & 0 deletions .circleci/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
FROM ubuntu:22.04

# Some details based on this Dockerfile:
# https://github.com/CircleCI-Public/cimg-base/blob/2b2cc9584c5ce2256d0781106218ff4158c790a0/22.04/Dockerfile

SHELL ["/bin/bash", "-exo", "pipefail", "-c"]

ENV DEBIAN_FRONTEND=noninteractive \
TERM=dumb \
PAGER=cat


ARG MEMFAULT_SDK_APT_DEPS="\
build-essential \
cpputest \
git \
python3.10 \
python3.10-venv\
"

# Run commands and tests as circleci user
RUN echo 'APT::Get::Assume-Yes "true";' > /etc/apt/apt.conf.d/90circleci && \
echo 'DPkg::Options "--force-confnew";' >> /etc/apt/apt.conf.d/90circleci && \
apt-get update && apt-get install -y \
locales \
sudo \
wget \
${MEMFAULT_SDK_APT_DEPS} \
&& \
locale-gen en_US.UTF-8 && \
rm -rf /var/lib/apt/lists/* && \
# create the circlci user
useradd --uid=3434 --user-group --create-home circleci && \
echo 'circleci ALL=NOPASSWD: ALL' >> /etc/sudoers.d/50-circleci && \
echo 'Defaults env_keep += "DEBIAN_FRONTEND"' >> /etc/sudoers.d/env_keep && \
sudo -u circleci mkdir /home/circleci/project && \
sudo -u circleci mkdir /home/circleci/bin

ENV PATH=/home/circleci/bin:/home/circleci/.local/bin:$PATH \
LANG=en_US.UTF-8 \
LANGUAGE=en_US:en \
LC_ALL=en_US.UTF-8

USER circleci

# Match the default CircleCI working directory
WORKDIR /home/circleci/project

# Create the virtualenv
RUN python3 -m venv ~/venv

# Install lcov and add to PATH
ARG LCOV_VERSION=1.14
ARG LCOV_SHA256SUM=14995699187440e0ae4da57fe3a64adc0a3c5cf14feab971f8db38fb7d8f071a
RUN \
cd ~ && \
wget https://github.com/linux-test-project/lcov/releases/download/v${LCOV_VERSION}/lcov-${LCOV_VERSION}.tar.gz -O ~/lcov.tar.gz && \
echo "${LCOV_SHA256SUM} ${HOME}/lcov.tar.gz" | shasum --algorithm=256 --check && \
cd ~ && tar zvxf ~/lcov.tar.gz && \
rm ~/lcov.tar.gz

ENV PATH=/home/circleci/lcov-${LCOV_VERSION}/bin:$PATH

# Auto-activate the virtualenv in the container
RUN sudo mkdir -p /circleci/ && \
sudo bash -c "echo 'source ~/venv/bin/activate' >> /circleci/.bashrc_circleci" && \
echo 'source /circleci/.bashrc_circleci' >> ~/.bashrc

ENTRYPOINT ["bash"]
23 changes: 7 additions & 16 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ version: 2.1
executors:
memfault-ci:
docker:
# TODO: create separate docker image + public Dockerfile
- image: memfault/ci:3.2.3
- image: memfault/memfault-firmware-sdk-ci:0.0.1
working_directory: ~/repo

commands:
Expand All @@ -26,7 +25,6 @@ commands:
name: Set environment variables and source virtualenv
command: |
if [ -f /circleci/.bashrc_circleci ]; then
touch .nvmrc
cat /circleci/.bashrc_circleci >> $BASH_ENV
fi
Expand All @@ -43,21 +41,9 @@ commands:
- ~/venv
key: v3-pip-dependencies-{{ checksum "requirements.txt" }}

# TODO: move into Dockerfile
lcov_install:
steps:
- run:
name: Install lcov 1.14
command: |
LCOV_SHA256SUM=14995699187440e0ae4da57fe3a64adc0a3c5cf14feab971f8db38fb7d8f071a
wget https://github.com/linux-test-project/lcov/releases/download/v1.14/lcov-1.14.tar.gz -O ~/lcov.tar.gz
echo "${LCOV_SHA256SUM} ${HOME}/lcov.tar.gz" | shasum --algorithm=256 --check
cd ~ && tar zvxf ~/lcov.tar.gz
prepare:
steps:
- checkout
- lcov_install
- virtualenv_activate
- pip_install

Expand All @@ -67,7 +53,12 @@ jobs:
executor: memfault-ci
steps:
- prepare
- run: PATH=~/lcov-1.14/bin:$PATH inv test --coverage
# run the tests with the sanitizer enabled first
- run: inv -e test --coverage
# now clean, and re-run with the sanitizer disabled- it adds extra
# branches that cannot be hit in a normal run, impacting coverage statistics
- run: git clean -dxff
- run: MEMFAULT_DISABLE_ASAN=1 inv -e test --coverage
- run: curl -s https://codecov.io/bash | bash -s -- -t ${CODECOV_TOKEN} -n ${CIRCLE_BUILD_NUM} -Z || echo 'Codecov upload failed'

workflows:
Expand Down
27 changes: 27 additions & 0 deletions .circleci/runas.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/bin/env bash

# This script can be used (on a Linux host, at least) to set up a docker
# container to be able to write on a hosted volume, by using an overlay mount
# inside the container.
#
# It requires running docker with the --priviledged flag. An example:
#
# ❯docker run --privileged --rm -i -t -v"$PWD":/hostdir memfault/memfault-firmware-sdk-ci /hostdir/.circleci/runas.sh


set -euo pipefail

BASE_DIR=/hostdir
FINAL_DIR=/memfault-firmware-sdk
USER=${USER-$(whoami)}

mkdir -p /tmp/overlay/
sudo mount -t tmpfs tmpfs /tmp/overlay
mkdir /tmp/overlay/{up,work}
sudo mkdir "$FINAL_DIR"
sudo mount -t overlay overlay \
-o lowerdir="$BASE_DIR,upperdir=/tmp/overlay/up/,workdir=/tmp/overlay/work/" \
"$FINAL_DIR"
sudo chown -R "$USER:$USER $FINAL_DIR"

exec bash
10 changes: 9 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
### Changes between Memfault SDK 0.31.3 and SDK 0.31.2 - July 8, 2022

#### :chart_with_upwards_trend: Improvements

- Support Zephyr v3.1+ by conditionally compiling out Logger v1 code, thanks to
@tejlmand for the patch!

### Changes between Memfault SDK 0.31.2 and SDK 0.31.1 - June 24, 2022

#### :chart_with_upwards_trend: Improvements

- Fixed a :bug: in the
[Zephyr port HTTP implementation](ports/zephyr/common/memfault_platform_http.c),
where a socket file descriptor was leaked. This caused every HTTP operation
after the first to fail on Zephyr platforms.
after the first to fail on Zephyr platforms. Thanks to @rerickson1 for the
fix!
- Added an update to improve the quality of stack traces when using
`MEMFAULT_ASSERT` with the TI ARM Clang Compiler

Expand Down
4 changes: 2 additions & 2 deletions VERSION
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
BUILD ID: 464682
GIT COMMIT: 5b8557d55
BUILD ID: 474047
GIT COMMIT: 74c12c38c
2 changes: 1 addition & 1 deletion components/include/memfault/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ typedef struct {
uint8_t patch;
} sMfltSdkVersion;

#define MEMFAULT_SDK_VERSION { .major = 0, .minor = 31, .patch = 2 }
#define MEMFAULT_SDK_VERSION { .major = 0, .minor = 31, .patch = 3 }

#ifdef __cplusplus
}
Expand Down
10 changes: 9 additions & 1 deletion examples/esp32/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
# Memfault for ESP32

This example application shows an integration with the ESP-IDF v3.3.5 SDK where
This example application shows an integration with the ESP-IDF v4.2.2 SDK where
a saved coredump is posted to the Memfault cloud for analysis.

If you already have an ESP-IDF project based on the v4.x or v3.x SDK, a step by
step getting started guide can be found [here](https://mflt.io/esp-tutorial).

The Memfault SDK has been tested to be compatible with these versions of
ESP-IDF:

- v3.x release series
- v4.x release series through v4.4.1

Other versions may be also be compatible but have not been verified by Memfault.

The memfault SDK hooks into the pre-existing mechanism for
[saving coredumps](https://docs.espressif.com/projects/esp-idf/en/latest/api-guides/core_dump.html).
We save the Memfault coredump data in the exact same coredump partition the
Expand Down
8 changes: 8 additions & 0 deletions ports/zephyr/common/memfault_logging.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,12 @@ static const uint32_t g_flags = IS_ENABLED(CONFIG_LOG_BACKEND_FORMAT_TIMESTAMP)

// Construct our backend API object. Might need to check how/if we want to support
// put_sync_string() & dropped().
#if !MEMFAULT_ZEPHYR_VERSION_GT(3, 1)
static void prv_log_put(const struct log_backend *const backend, struct log_msg *msg);
static void prv_log_put_sync_string(const struct log_backend *const backend,
struct log_msg_ids src_level, uint32_t timestamp,
const char *fmt, va_list ap);
#endif
static void prv_log_panic(struct log_backend const *const backend);


Expand All @@ -67,10 +69,12 @@ const struct log_backend_api log_backend_mflt_api = {
#if MEMFAULT_ZEPHYR_VERSION_GT(2, 5)
.process = IS_ENABLED(CONFIG_LOG2) ? prv_log_process : NULL,
#endif
#if !MEMFAULT_ZEPHYR_VERSION_GT(3, 1)
.put = IS_ENABLED(CONFIG_LOG_IMMEDIATE) ? NULL : prv_log_put,
.put_sync_string = IS_ENABLED(CONFIG_LOG_IMMEDIATE) ? prv_log_put_sync_string : NULL,
// Note: We don't want to clutter Memfault circular buffer with hex dumps
.put_sync_hexdump = NULL,
#endif
.panic = prv_log_panic,
.init = prv_log_init,
.dropped = IS_ENABLED(CONFIG_LOG_IMMEDIATE) ? NULL : prv_log_dropped,
Expand All @@ -89,17 +93,20 @@ static int prv_log_out(uint8_t *data, size_t length, void *ctx) {
return (int) length;
}

#if !MEMFAULT_ZEPHYR_VERSION_GT(3, 1)
static eMemfaultPlatformLogLevel prv_map_zephyr_level_to_memfault(uint32_t zephyr_level) {
// Map From To
return zephyr_level == LOG_LEVEL_ERR ? kMemfaultPlatformLogLevel_Error
: zephyr_level == LOG_LEVEL_WRN ? kMemfaultPlatformLogLevel_Warning
: zephyr_level == LOG_LEVEL_INF ? kMemfaultPlatformLogLevel_Info
: /* LOG_LEVEL_DBG */kMemfaultPlatformLogLevel_Debug;
}
#endif

// *** Below are the implementations for the Zephyr backend API ***

// Zephyr API function. I'm assuming <msg> has been validated by the time put() is called.
#if !MEMFAULT_ZEPHYR_VERSION_GT(3, 1)
static void prv_log_put(const struct log_backend *const backend, struct log_msg *msg) {
// Acquire, process (eventually calls prv_data_out()) and release the message.
log_msg_get(msg);
Expand Down Expand Up @@ -127,6 +134,7 @@ static void prv_log_put_sync_string(const struct log_backend *const backend,
eMemfaultPlatformLogLevel memfault_level = prv_map_zephyr_level_to_memfault(src_level.level);
memfault_vlog_save(memfault_level, fmt, ap);
}
#endif

static void prv_log_panic(struct log_backend const *const backend) {
log_output_flush(&s_log_output_mflt);
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ mbed-cli==1.10.1
pyftdi==0.29.4
west==0.6.2
colorama==0.4.3
fastcov==1.14
6 changes: 3 additions & 3 deletions scripts/memfault_gdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@
# Note: not using `requests` but using the built-in http.client instead, so
# there will be no additional dependencies other than Python itself.
try:
from httplib import HTTPConnection, HTTPSConnection
from Queue import Queue
from urlparse import urlparse, urlunparse
from httplib import HTTPConnection, HTTPSConnection # noqa: I251
from Queue import Queue # noqa: I251
from urlparse import urlparse, urlunparse # noqa: I251
except ImportError:
from http.client import HTTPConnection, HTTPSConnection
from queue import Queue
Expand Down
15 changes: 14 additions & 1 deletion tasks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,21 @@ def fw_sdk_unit_test(ctx, coverage=False, rule="", test_filter=None, test_dir=SD
if test_filter:
env_dict["TEST_MAKEFILE_FILTER"] = test_filter

# Unit tests currently don't reliably pass when running Make in parallel 😢
cpus = 1
# if os.getenv("CIRCLECI"):
# # getting the number of cpus available to the circleci executor from
# # within the docker container is a hassle, so bail and use 2 cpus
# cpus = 2
# else:
# cpus = len(os.sched_getaffinity(0))

with ctx.cd(test_dir):
ctx.run("make {}".format(rule), env=env_dict, pty=True)
ctx.run(
"make -j {} --output-sync=recurse {}".format(cpus, rule),
env=env_dict,
pty=True,
)


ns = Collection()
Expand Down
4 changes: 4 additions & 0 deletions tests/MakefileWorkerOverrides.mk
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@ else
COMPILER_SPECIFIC_WARNINGS += \
-Wformat-signedness

# Permit disabling the sanitizers via environment variable
ifneq ($(MEMFAULT_DISABLE_ASAN),1)
# Enable sanitizers, and crash on error (don't attempt to recover sanely) so the
# test fails on sanitizer violation
CPPUTEST_WARNINGFLAGS += \
Expand All @@ -110,6 +112,8 @@ CPPUTEST_LDFLAGS += \
-fsanitize=address \
-fsanitize=undefined \
-fno-sanitize-recover=all
endif


endif

Expand Down
2 changes: 1 addition & 1 deletion tests/scripts/filterGcov.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/bin/bash

# shellcheck disable=SC2034,SC2162,SC2086,SC2140
# NOTE: This was copied from:
# https://github.com/cpputest/cpputest/blob/master/scripts/filterGcov.sh
# It's supposed to be part of a CppUTest install but isn't part of what you get from brew :(
Expand Down

0 comments on commit ae5b690

Please sign in to comment.