Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 7 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
lib_xassert change log
======================

UNRELEASED
----------

* ADDED: Support for building and testing on XS and VX architectures.
* ADDED: C assertion tests while retaining XC compatibility tests on XS.
* CHANGED: Use lib_basix for portable trap, printing and timer support.

5.0.0
-----

Expand Down
79 changes: 62 additions & 17 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// This file relates to internal XMOS infrastructure and should be ignored by external users

@Library('xmos_jenkins_shared_library@v0.51.1') _
@Library('xmos_jenkins_shared_library@v0.52.0') _

getApproval()
pipeline {
Expand All @@ -9,9 +9,14 @@ pipeline {

parameters {
string(
name: 'TOOLS_VERSION',
name: 'TOOLS_VERSION_XS',
defaultValue: '15.3.1',
description: 'XTC tools version'
description: 'XS XTC tools version'
)
string(
name: 'TOOLS_VERSION_VX',
defaultValue: '-j --repo arch_vx_slipgate -b master -a XTC 131',
description: 'VX XTC tools version'
)
string(
name: 'XMOSDOC_VERSION',
Expand Down Expand Up @@ -54,44 +59,85 @@ pipeline {
}
}

stage('Examples build') {
stage('Build XS') {
steps {
dir("${REPO_NAME}/examples") {
xcoreBuild()
xcoreBuild(
toolsVersion: params.TOOLS_VERSION_XS,
buildDir: 'build-xs',
cmakeOpts: '-DAPP_HW_TARGET=XK-EVK-XU316'
)
}
}
}

stage('Repo checks') {
stage('Test XS') {
steps {
warnError("Repo checks failed") {
runRepoChecks("${WORKSPACE}/${REPO_NAME}")
dir("${REPO_NAME}/tests") {
xcoreBuild(
toolsVersion: params.TOOLS_VERSION_XS,
buildDir: 'build-xs',
cmakeOpts: '-DAPP_HW_TARGET=XK-EVK-XU316 -DXASSERT_BUILD_XC_TESTS=ON',
archiveBins: false
)
withTools(params.TOOLS_VERSION_XS) {
createVenv(reqFile: 'requirements.txt')
withVenv {
runPytest()
}
}
}
}
}

stage('Doc build') {
stage('Build VX') {
steps {
dir(REPO_NAME) {
buildDocs()
dir("${REPO_NAME}/examples") {
xcoreBuild(
toolsVersion: params.TOOLS_VERSION_VX,
buildDir: 'build-vx',
cmakeOpts: '-DAPP_HW_TARGET=XK-EVK-XU416'
)
}
}
}

stage('Tests') {
stage('Test VX') {
steps {
dir("${REPO_NAME}/tests") {
withTools(params.TOOLS_VERSION) {
createVenv(reqFile: "requirements.txt")
sh "find . -name '*.xe' -delete"
xcoreBuild(
toolsVersion: params.TOOLS_VERSION_VX,
buildDir: 'build-vx',
cmakeOpts: '-DAPP_HW_TARGET=XK-EVK-XU416 -DXASSERT_BUILD_XC_TESTS=OFF',
archiveBins: false
)
withTools(params.TOOLS_VERSION_VX) {
createVenv(reqFile: 'requirements.txt')
withVenv {
xcoreBuild(archiveBins: false)
sh "pytest -n auto --junitxml=pytest_result.xml"
runPytest()
}
}
}
}
}

stage('Repo checks') {
steps {
warnError("Repo checks failed") {
runRepoChecks("${WORKSPACE}/${REPO_NAME}")
}
}
}

stage('Doc build') {
steps {
dir(REPO_NAME) {
buildDocs()
}
}
}

stage("Archive sandbox") {
steps {
archiveSandbox(REPO_NAME)
Expand All @@ -116,4 +162,3 @@ pipeline {
}
} // stages
} // pipeline

7 changes: 4 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Summary

This library provides a lightweight and flexible replacement for the standard C header ``assert.h``.

The assertions in this library can be be enabled/disabled and configured as to how much information
The assertions in this library can be enabled or disabled and configured to control how much information
they show. This configuration can be per `xassert unit` (i.e. for sets of files).

********
Expand All @@ -28,6 +28,8 @@ Features
* Low memory usage
* Ability to enable or disable various features via compile time defines
* Timing assertion system to check that code executes within a specified time limit
* Support for XS and VX architectures
* C and C++ support, with XC compatibility on XS

************
Known issues
Expand All @@ -53,7 +55,7 @@ Required tools
Required libraries (dependencies)
*********************************

* None
* `lib_basix <https://www.github.com/xmos/lib_basix>`_ (https://www.github.com/xmos/lib_basix)

*************************
Related application notes
Expand All @@ -67,4 +69,3 @@ Support

This package is supported by XMOS Ltd. Issues can be raised against the software at
`www.xmos.com/support <https://www.xmos.com/support>`_ or using GitHub `issues <https://github.com/xmos/lib_xassert/issues>`_.

4 changes: 4 additions & 0 deletions doc/exclude_patterns.inc
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# The following patterns are to be excluded from the documentation build

examples
tests
.pytest_cache
**CHANGELOG.rst
**LICENSE.rst
4 changes: 3 additions & 1 deletion examples/app_assert/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ cmake_minimum_required(VERSION 3.21)
include($ENV{XMOS_CMAKE_PATH}/xcommon.cmake)
project(app_assert)

set(APP_HW_TARGET XK-EVK-XU316)
if(NOT DEFINED APP_HW_TARGET)
set(APP_HW_TARGET XK-EVK-XU316)
endif()

include(${CMAKE_CURRENT_LIST_DIR}/../deps.cmake)

Expand Down
4 changes: 3 additions & 1 deletion examples/app_fail/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ cmake_minimum_required(VERSION 3.21)
include($ENV{XMOS_CMAKE_PATH}/xcommon.cmake)
project(app_fail)

set(APP_HW_TARGET XK-EVK-XU316)
if(NOT DEFINED APP_HW_TARGET)
set(APP_HW_TARGET XK-EVK-XU316)
endif()

include(${CMAKE_CURRENT_LIST_DIR}/../deps.cmake)

Expand Down
4 changes: 3 additions & 1 deletion examples/app_timed_block/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ cmake_minimum_required(VERSION 3.21)
include($ENV{XMOS_CMAKE_PATH}/xcommon.cmake)
project(app_timed_block)

set(APP_HW_TARGET XK-EVK-XU316)
if(NOT DEFINED APP_HW_TARGET)
set(APP_HW_TARGET XK-EVK-XU316)
endif()

include(${CMAKE_CURRENT_LIST_DIR}/../deps.cmake)

Expand Down
4 changes: 3 additions & 1 deletion examples/app_timed_loop/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ cmake_minimum_required(VERSION 3.21)
include($ENV{XMOS_CMAKE_PATH}/xcommon.cmake)
project(app_timed_loop)

set(APP_HW_TARGET XK-EVK-XU316)
if(NOT DEFINED APP_HW_TARGET)
set(APP_HW_TARGET XK-EVK-XU316)
endif()

include(${CMAKE_CURRENT_LIST_DIR}/../deps.cmake)

Expand Down
2 changes: 1 addition & 1 deletion examples/app_timed_loop/src/fn_no_assert.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

#include <xs1.h>
#include <xassert.h>
#include <print.h>
#include <basix/print.h>
#include <xcore/hwtimer.h>

void fn_no_assert()
Expand Down
4 changes: 3 additions & 1 deletion examples/app_timing_loop_exception/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ cmake_minimum_required(VERSION 3.21)
include($ENV{XMOS_CMAKE_PATH}/xcommon.cmake)
project(app_timing_loop_exception)

set(APP_HW_TARGET XK-EVK-XU316)
if(NOT DEFINED APP_HW_TARGET)
set(APP_HW_TARGET XK-EVK-XU316)
endif()

include(${CMAKE_CURRENT_LIST_DIR}/../deps.cmake)

Expand Down
4 changes: 3 additions & 1 deletion examples/app_unreachable/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ cmake_minimum_required(VERSION 3.21)
include($ENV{XMOS_CMAKE_PATH}/xcommon.cmake)
project(app_upreachable)

set(APP_HW_TARGET XK-EVK-XU316)
if(NOT DEFINED APP_HW_TARGET)
set(APP_HW_TARGET XK-EVK-XU316)
endif()

include(${CMAKE_CURRENT_LIST_DIR}/../deps.cmake)

Expand Down
29 changes: 13 additions & 16 deletions lib_xassert/api/xassert.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
#define XASSERT_ENABLE_LINE_NUMBERS 0
#endif

#include <basix/architecture.h>

#define XASSERT_JOIN0(x,y) x ## y
#define XASSERT_JOIN(x,y) XASSERT_JOIN0(x,y)

Expand Down Expand Up @@ -71,7 +73,7 @@
#endif

#if XASSERT_ENABLE_DEBUG0
#include "print.h"
#include <basix/print.h>
#if XASSERT_ENABLE_TIMING_ASSERTIONS0
#include <stdio.h>
#endif
Expand All @@ -98,37 +100,37 @@
# if XASSERT_ENABLE_DEBUG0
# define xassert(e) do { if (!(e)) {\
printstr(#e); xassert_print_line; \
__builtin_trap();} \
basix_trap();} \
} while(0)
# else
# define xassert(e) do { if (!(e)) __builtin_trap();} while(0)
# define xassert(e) do { if (!(e)) basix_trap();} while(0)
# endif
#else
# define xassert(e) // disabled
#endif

#if XASSERT_ENABLE_ASSERTIONS0
# if XASSERT_ENABLE_DEBUG0
# define unreachable(msg) do { printstr(msg); xassert_print_line; __builtin_trap();} while(0)
# define unreachable(msg) do { printstr(msg); xassert_print_line; basix_trap();} while(0)
# else
# define unreachable(msg) do { __builtin_trap();} while(0)
# define unreachable(msg) do { basix_trap();} while(0)
# endif
#else
# define unreachable(msg) do { __builtin_unreachable();} while(0)
#endif

#if XASSERT_ENABLE_DEBUG0
# define fail(msg) do { printstr(msg); xassert_print_line; __builtin_trap();} while(0)
# define fail(msg) do { printstr(msg); xassert_print_line; basix_trap();} while(0)
# define fail_timing(tag, actual, limit, file, line) do { printstr("Timing failed for: "); \
printf("%s", (const char *) tag); \
fflush(stdout); \
printstr("\nΔt = "); printint(actual); printstr(" ticks ("); printint((actual) * 10); printstr(" ns), "); \
printstr("limit = "); printint(limit); printstr(" ticks ("); printint((limit) * 10); printstr(" ns) "); \
xassert_timing_print_line(file, line); __builtin_trap();\
xassert_timing_print_line(file, line); basix_trap();\
Comment on lines 124 to +129
} while(0)
#else
# define fail(msg) do { __builtin_trap();} while(0)
# define fail_timing(tag, actual, limit, file, line) do { __builtin_trap();} while(0)
# define fail(msg) do { basix_trap();} while(0)
# define fail_timing(tag, actual, limit, file, line) do { basix_trap();} while(0)
#endif

/* UNUSED() works for variables and references */
Expand Down Expand Up @@ -173,8 +175,6 @@ extern "C" {

#if XASSERT_ENABLE_TIMING_ASSERTIONS0

#include <xs1.h>

#ifdef __XC__
# define UNSAFE unsafe
#else
Expand Down Expand Up @@ -207,9 +207,7 @@ typedef struct {

static inline unsigned get_time(void)
{
unsigned time;
asm volatile("gettime %0" : "=r"(time));
return time;
return basix_time_now();
}

static timing_block_t timing_blocks[XASSERT_MAX_TIMING_BLOCKS];
Expand Down Expand Up @@ -310,8 +308,7 @@ static inline void timing_loop_impl(const char *tag, unsigned min_freq_hz, const
return;
}

//unsigned interval = XS1_TIMER_HZ / min_freq_hz;
unsigned interval = (XS1_TIMER_HZ + min_freq_hz - 1) / min_freq_hz; // rounds up
unsigned interval = (BASIX_TIMER_HZ + min_freq_hz - 1) / min_freq_hz; // rounds up

for (int i = head; i != tail; i = CIRCULAR_INC(i))
{
Expand Down
2 changes: 1 addition & 1 deletion lib_xassert/lib_build_info.cmake
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
set(LIB_NAME lib_xassert)
set(LIB_VERSION 5.0.0)
set(LIB_INCLUDES api)
set(LIB_DEPENDENT_MODULES "")
set(LIB_DEPENDENT_MODULES "lib_basix(0.1.0)")
set(LIB_OPTIONAL_HEADERS debug_conf.h xassert_conf.h)

set(LIB_COMPILER_FLAGS -Wall
Expand Down
23 changes: 16 additions & 7 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,22 @@ cmake_minimum_required(VERSION 3.21)
include($ENV{XMOS_CMAKE_PATH}/xcommon.cmake)
project(lib_xassert_tests)

add_subdirectory(assert_test)
add_subdirectory(assert_test_unit)
add_subdirectory(fail_test)
option(XASSERT_BUILD_XC_TESTS "Build XC compatibility tests" ON)

add_subdirectory(assert_c_test)
add_subdirectory(assert_unit_c_test)
add_subdirectory(fail_c_test)
add_subdirectory(unreachable_c_test)
add_subdirectory(timing_block_c_test)
add_subdirectory(timing_block_test)
add_subdirectory(timing_debug_c_test)
add_subdirectory(timing_debug_test)
add_subdirectory(timing_loop_c_test)
add_subdirectory(timing_loop_test)
add_subdirectory(unreachable_test)

if(XASSERT_BUILD_XC_TESTS)
add_subdirectory(assert_test)
add_subdirectory(assert_test_unit)
add_subdirectory(fail_test)
add_subdirectory(timing_block_test)
add_subdirectory(timing_debug_test)
add_subdirectory(timing_loop_test)
add_subdirectory(unreachable_test)
endif()
2 changes: 2 additions & 0 deletions tests/assert_c_test.expect
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
0
Unhandled exception: ECALL, data: 0x00000000

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ive observed xrun and xsim produce different outputs?

Loading