Skip to content

Commit

Permalink
test: DAC extension API test application
Browse files Browse the repository at this point in the history
  • Loading branch information
gschorcht committed Dec 1, 2018
1 parent 9f901f0 commit de3d2b3
Show file tree
Hide file tree
Showing 5 changed files with 266 additions and 0 deletions.
11 changes: 11 additions & 0 deletions tests/extend_dac/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
include ../Makefile.tests_common

USEMODULE += extend_dac

TEST_ON_CI_WHITELIST += all

include ./Makefile.include
include $(RIOTBASE)/Makefile.include

test:
./tests/01-run.py
2 changes: 2 additions & 0 deletions tests/extend_dac/Makefile.include
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# include test specific includes
export INCLUDES += -I$(CURDIR)/include
64 changes: 64 additions & 0 deletions tests/extend_dac/include/dac_ext_conf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Copyright (C) 2018 Gunar Schorcht
* Copyright (C) 2018 Acutam Automation, LLC
*
* 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 DAC extension test list
*
* @author Gunar Schorcht <gunar@schorcht.net>
* @author Matthew Blue <matthew.blue.neuro@gmail.com>
*
* @}
*/

#ifndef DAC_EXT_CONF_H
#define DAC_EXT_CONF_H

#include <stddef.h>

#include "extend/dac.h"

#ifdef __cplusplus
extern "C" {
#endif

/**
* @brief Reference the driver structs
*
* @{
*/
extern dac_ext_driver_t tests_extend_dac_driver;
extern dac_ext_driver_t dac_ext_notsup_driver;
/** @} */

/**
* @brief DAC extension test list
*/
static const dac_ext_t dac_ext_list[] =
{
{
.driver = &tests_extend_dac_driver,
.dev = (void *)0xbeef,
},
{
.driver = &dac_ext_notsup_driver,
.dev = NULL,
},
};

#ifdef __cplusplus
}
#endif

#endif /* DAC_EXT_CONF_H */
/** @} */
141 changes: 141 additions & 0 deletions tests/extend_dac/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
/*
* Copyright (C) 2018 Gunar Schorcht
* Copyright (C) 2018 Acutam Automation, LLC
*
* 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 DAC extension test routine
*
* @author Gunar Schorcht <gunar@schorcht.net>
* @author Matthew Blue <matthew.blue.neuro@gmail.com>
* @}
*/

#include <stdio.h>

#include "extend/dac.h"
#include "periph/dac.h"

/* DAC extension test functions */
int8_t test_dac_init(void *dev, dac_t chn);
void test_dac_set(void *dev, dac_t chn, uint16_t val);
void test_dac_poweron(void *dev, dac_t chn);
void test_dac_poweroff(void *dev, dac_t chn);
unsigned int test_dac_channels(void *dev);

/* DAC extension test driver */
const dac_ext_driver_t tests_extend_dac_driver = {
.init = test_dac_init,
.set = test_dac_set,
.poweron = test_dac_poweron,
.poweroff = test_dac_poweroff,
.channels = test_dac_channels,
};

int8_t test_dac_init(void *dev, dac_t chn)
{
printf("\t%s dev 0x%04x, chn %u\n", __func__, (uint16_t)(uintptr_t)dev, chn);
return 0;
}

void test_dac_set(void *dev, dac_t chn, uint16_t val)
{
printf("\t%s dev 0x%04x, chn %u, val %u\n", __func__, (uint16_t)(uintptr_t)dev, chn, val);
}

void test_dac_poweron(void *dev, dac_t chn)
{
printf("\t%s dev 0x%04x, chn %u\n", __func__, (uint16_t)(uintptr_t)dev, chn);
}

void test_dac_poweroff(void *dev, dac_t chn)
{
printf("\t%s dev 0x%04x, chn %u\n", __func__, (uint16_t)(uintptr_t)dev, chn);
}

unsigned int test_dac_channels(void *dev)
{
printf("\t%s dev 0x%04x\n", __func__, (uint16_t)(uintptr_t)dev);
return 4;
}

int main(void)
{
puts("DAC extension test routine");
puts("\nRunning DAC functions for internal device");

uint16_t value = 1024;

unsigned int num = dac_channels(DAC_LINE(0));
printf("- Number of DAC channels: %u\n", num);

for (unsigned int chn = 0; chn < num; chn++) {
printf("- Init DAC channel %u\n", chn);
if (dac_init(DAC_LINE(chn))) {
puts("[FAILED]");
return 1;
}
printf("- Set DAC channel %u: %u\n", chn, chn * value);
dac_set(DAC_LINE(chn), chn * value);
printf("- Poweroff DAC channel %u\n", chn);
dac_poweroff(DAC_LINE(chn));
printf("- Poweron DAC channel %u\n", chn);
dac_poweron(DAC_LINE(chn));
}

puts("\nRunning DAC functions for extension test device");

num = dac_channels(DAC_EXT_LINE(0, 0));
printf("- Number of DAC channels: %u\n", num);

for (unsigned int chn = 0; chn < num; chn++) {
printf("- Init DAC channel %u\n", chn);
if (dac_init(DAC_EXT_LINE(0, chn))) {
puts("[FAILED]");
return 1;
}
printf("- Set DAC channel %u: %u\n", chn, chn * value);
dac_set(DAC_EXT_LINE(0, chn), chn * value);
printf("- Poweroff DAC channel %u\n", chn);
dac_poweroff(DAC_EXT_LINE(0, chn));
printf("- Poweron DAC channel %u\n", chn);
dac_poweron(DAC_EXT_LINE(0, chn));
}

puts("\nRunning DAC functions for extension notsup device");
puts("(they should not print output)");

for (unsigned int chn = 0; chn < num; chn++) {
printf("- notsup dac.h functions on channel %u\n", chn);
if (!dac_init(DAC_EXT_LINE(1, chn))) {
puts("[FAILED]");
return 1;
}
dac_set(DAC_EXT_LINE(1, chn), chn * value);
dac_poweroff(DAC_EXT_LINE(1, chn));
dac_poweron(DAC_EXT_LINE(1, chn));
}

puts("\nChecking that all channels in range have init error using notsup");
puts("(lack of init error implies improper redirection)");

for (unsigned int chn = 0; chn <= DAC_EXT_LINE_MASK; chn +=16) {
if (dac_init(DAC_EXT_LINE(1, chn)) >= 0) {
printf("init succeeded on channel %u\n", chn);
puts("[FAILED]");
return 1;
}
}

puts("[SUCCESS]");

return 0;
}
48 changes: 48 additions & 0 deletions tests/extend_dac/tests/01-run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/env python3

# Copyright (C) 2018 Acutam Automation, LLC
#
# 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.

import os
import sys


def testfunc(child):
child.expect_exact("DAC extension test routine")
child.expect_exact('Running DAC functions for internal device')
child.expect('- Number of DAC channels: ')
i = child.readline()
for _ in range(int(i)):
child.expect('- Init DAC channel \d+')
child.expect('- Set DAC channel \d+: \d+')
child.expect('- Poweroff DAC channel \d+')
child.expect('- Poweron DAC channel \d+')
child.expect_exact('Running DAC functions for extension test device')
child.expect('test_dac_channels dev 0xbeef')
child.expect('- Number of DAC channels: ')
i = child.readline()
for _ in range(int(4)):
child.expect('- Init DAC channel \d+')
child.expect('test_dac_init dev 0xbeef, chn \d+')
child.expect('- Set DAC channel \d+: \d+')
child.expect('test_dac_set dev 0xbeef, chn \d+, val \d+')
child.expect('- Poweroff DAC channel \d+')
child.expect('test_dac_poweroff dev 0xbeef, chn \d+')
child.expect('- Poweron DAC channel \d+')
child.expect('test_dac_poweron dev 0xbeef, chn \d+')
child.expect_exact("Running DAC functions for extension notsup device")
child.expect_exact("(they should not print output)")
for _ in range(int(i)):
child.expect('- notsup dac.h functions on channel \d+')
child.expect_exact("Checking that all channels in range have init error using notsup")
child.expect_exact("(lack of init error implies improper redirection)")
child.expect_exact("[SUCCESS]")


if __name__ == "__main__":
sys.path.append(os.path.join(os.environ['RIOTBASE'], 'dist/tools/testrunner'))
from testrunner import run
sys.exit(run(testfunc))

0 comments on commit de3d2b3

Please sign in to comment.