Skip to content

Commit

Permalink
tests/periph_pio: Add basic PIO test
Browse files Browse the repository at this point in the history
  • Loading branch information
fabian18 committed Dec 19, 2021
1 parent f84715e commit 83af45e
Show file tree
Hide file tree
Showing 6 changed files with 155 additions and 0 deletions.
11 changes: 11 additions & 0 deletions tests/periph_pio/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Copyright (c) 2021 Otto-von-Guericke Universität Magdeburg
#
# This file is subject to the terms and conditions of the GNU Lesser
# General Public License v2.1. See the file LICENSE in the top level
# directory for more details.
#

config APPLICATION
bool
default y
depends on TEST_KCONFIG
8 changes: 8 additions & 0 deletions tests/periph_pio/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
include ../Makefile.tests_common

FEATURES_REQUIRED += periph_pio

# avoid running Kconfig by default
SHOULD_RUN_KCONFIG ?=

include $(RIOTBASE)/Makefile.include
Empty file added tests/periph_pio/Makefile.ci
Empty file.
12 changes: 12 additions & 0 deletions tests/periph_pio/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Peripheral PIO Test Application
=====================================

This application tests basic PIO functionality.
- allocation and deallocation of instruction memory
- state machine claim and release

Expected Output on Success
--------------------------

main(): This is RIOT! (Version: <INSERT VERSION HERE>)
TEST SUCCEEDED!
3 changes: 3 additions & 0 deletions tests/periph_pio/app.config.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# this file enables modules defined in Kconfig. Do not use this file for
# application configuration. This is only needed during migration.
CONFIG_MODULE_PERIPH_PIO=y
121 changes: 121 additions & 0 deletions tests/periph_pio/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
/*
* Copyright (C) 2021 Otto-von-Guericke Universität Magdeburg
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/

/**
* @ingroup tests
* @{
*
* @file
* @brief Test application for the PIO peripheral driver
*
* @author Fabian Hüßler <fabian.huessler@ovgu.de>
*
* @}
*/

#include <stddef.h>
#include "shell.h"
#include "periph_conf.h"
#include "periph/pio.h"
#define ENABLE_DEBUG 0
#include "debug.h"

#if ENABLE_DEBUG
#define DEBUG_TEST_FAILED(msg, ...) \
DEBUG("[Test PIO] %s failed at %d: " msg "\n", __func__, __LINE__, __VA_ARGS__);
#else
#define DEBUG_TEST_FAILED(msg, ...)
#endif

static int _test_pio_alloc_and_free(pio_t pio)
{
int error = 1;
pio_program_t pro;
for (int i = 0; i < PIO_INSTR_NUMOF; i++) {
pro = (pio_program_t){.location = PIO_PROGRAM_NOT_LOADED, .instr_numof = 1};
if (pio_alloc_program(pio, &pro)) {
DEBUG_TEST_FAILED("Could not allocate program at %d", i);
goto CLEAN;
}
}
if (!pio_alloc_program(pio, &pro)) {
DEBUG_TEST_FAILED("Program impossibly allocated");
goto CLEAN;
}
pio_free_program(pio, &pro);
pro.location = PIO_PROGRAM_NOT_LOADED;
if (pio_alloc_program(pio, &pro)) {
DEBUG_TEST_FAILED("Program could not be allocated after free");
goto CLEAN;
}
error = 0;
CLEAN:
for (int i = 0; i < PIO_INSTR_NUMOF; i++) {
pro = (pio_program_t){.location = i, .instr_numof = 1};
pio_free_program(pio, &pro);
}
return error;
}

static int _test_pio_sm_lock_unlock(pio_t pio)
{
int error = 1;
pio_sm_t sm;
for (pio_sm_t i = 0; i < PIO_SM_NUMOF; i++) {
if ((sm = pio_sm_lock(pio)) < 0) {
DEBUG_TEST_FAILED("Could not lock state machine %d", i);
goto CLEAN;
}
}
if (pio_sm_lock(pio) >= 0) {
DEBUG_TEST_FAILED("State machine impossibly locked");
goto CLEAN;
}
pio_sm_unlock(pio, sm);
if (sm != pio_sm_lock(pio)) {
DEBUG_TEST_FAILED("State machine could not be locked after unlock");
goto CLEAN;
}
error = 0;
CLEAN:
for (pio_sm_t i = 0; i < PIO_SM_NUMOF; i++) {
pio_sm_unlock(pio, i);
}
return error;
}

static int _test_pio_sm_program_any(void)
{
int error = 1;
pio_t pio;
pio_sm_t sm;
pio_program_t pro = {.location = PIO_PROGRAM_NOT_LOADED, .instr_numof = PIO_INSTR_NUMOF};
if (pio_alloc_program_sm_lock_any(&pio, &sm, &pro)) {
DEBUG_TEST_FAILED("Could not allocate program for any state machine");
goto CLEAN;
}
error = 0;
CLEAN:
pio_sm_unlock(pio, sm);
pio_free_program(pio, &pro);
return error;
}

int main(void)
{
int error = 0;

for (pio_t pio = 0; pio < PIO_NUMOF; pio++) {
error = _test_pio_alloc_and_free(pio) ? 1 : error;
error = _test_pio_sm_lock_unlock(pio) ? 1 : error;
}
error = _test_pio_sm_program_any() ? 1 : error;

puts(error ? "TEST FAILED!" : "TEST SUCCEEDED!");
return 0;
}

0 comments on commit 83af45e

Please sign in to comment.