Skip to content

Commit

Permalink
feat: refine periph timer tests
Browse files Browse the repository at this point in the history
  • Loading branch information
smlng committed Oct 10, 2019
1 parent 1fe5aa7 commit bce597d
Show file tree
Hide file tree
Showing 11 changed files with 221 additions and 210 deletions.
6 changes: 6 additions & 0 deletions dist/robotframework/res/philip.keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,9 @@ PHILIP Log Stats
[Documentation] Write PHiLIP statistics to log and print on console
${stats}= PHILIP Stats
Log ${stats}

PHILIP Trace GPIO ${pin}
[Documentation] Enable tracing for a gpio debug pin
API Call Should Succeed PHiLIP.Write Reg gpio[${pin}].mode.init 0
API Call Should Succeed PHiLIP.Write Reg gpio[${pin}].mode.io_type 3
API Call Should Succeed PHiLIP.Execute Changes
File renamed without changes.
File renamed without changes.
109 changes: 63 additions & 46 deletions tests/periph_timer_cli/main.c → tests/periph_timer/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#define CB_LOW_STR "cb_low"

static mutex_t cb_mutex;
static gpio_t debug_pins[TIMER_NUMOF];

static inline int _get_num(const char *str, uint32_t* val)
{
Expand Down Expand Up @@ -123,35 +124,15 @@ void cb_low(void *arg, int channel)
mutex_unlock(&cb_mutex);
}

int cmd_timer_bench_read(int argc, char **argv)
{
uint32_t dev, repeat_cnt = 0;

if (_check_param(argc, argv, &dev, 4, 4,
"dev repeat_cnt gpio_port gpio_pin") != RESULT_OK) {
return -1;
}

gpio_t pin = _get_pin(argv[3], argv[4]);

gpio_toggle(pin);

for (uint32_t i = 0; i < repeat_cnt; i++) {
timer_read(dev);
}

gpio_toggle(pin);

return _print_cmd_result("cmd_timer_read_bench", true, 0, false);
}
/* API calls */

int cmd_timer_init(int argc, char **argv)
{
uint32_t dev, freq = 0;
uint32_t dev = 0;
uint32_t freq = 0;

if (_check_param(argc, argv, &dev, 5, 5, "dev freq cb gpio_port gpio_pin")
!= RESULT_OK) {
return -1;
if (_check_param(argc, argv, &dev, 3, 3, "dev freq cb") != RESULT_OK) {
return RESULT_ERROR;
}

if (_get_num(argv[2], &freq) != RESULT_OK) {
Expand All @@ -178,11 +159,7 @@ int cmd_timer_init(int argc, char **argv)
return -3;
}

gpio_t pin = _get_pin(argv[4], argv[5]);

gpio_init(pin, GPIO_OUT);

int res = timer_init(dev, freq, cb, (void*)(intptr_t)pin);
int res = timer_init(dev, freq, cb, (void*)(intptr_t)debug_pins[dev]);

return _print_cmd_result("timer_init", res == 0, res, true);
}
Expand All @@ -192,8 +169,8 @@ int _timer_set(int argc, char **argv, bool absolute)
int res;
uint32_t dev = 0;

if (_check_param(argc, argv, &dev, 5, 5,
"dev channel ticks gpio_port gpio_pin") != RESULT_OK) {
if (_check_param(argc, argv, &dev, 3, 3,
"dev channel ticks") != RESULT_OK) {
return -1;
}

Expand All @@ -204,16 +181,15 @@ int _timer_set(int argc, char **argv, bool absolute)
PARSE_ERROR;
}

gpio_t pin = _get_pin(argv[4], argv[5]);
gpio_t pin = debug_pins[dev];

mutex_lock(&cb_mutex);

gpio_toggle(pin);
if (absolute) {
gpio_toggle(pin);
res = timer_set_absolute(dev, chan, timeout);
}
else {
gpio_toggle(pin);
res = timer_set(dev, chan, timeout);
}

Expand All @@ -228,21 +204,22 @@ int _timer_set(int argc, char **argv, bool absolute)
int cmd_timer_set(int argc, char **argv)
{
int res = _timer_set(argc, argv, false);
return _print_cmd_result("timer_set", res == 1, res, true);
return _print_cmd_result("timer_set", (res == 0), res, true);
}

int cmd_timer_set_absolute(int argc, char **argv)
{
int res = _timer_set(argc, argv, true);
return _print_cmd_result("timer_set_absolute", res == 1, res, true);
return _print_cmd_result("timer_set_absolute", (res == 0), res, true);
}

int cmd_timer_clear(int argc, char **argv)
{
uint32_t dev, chan = 0;
uint32_t dev = 0;
uint32_t chan = 0;

if (_check_param(argc, argv, &dev, 2, 2, "dev channel") != RESULT_OK) {
return -1;
return RESULT_ERROR;
}

if (_get_num(argv[2], &chan) != RESULT_OK) {
Expand All @@ -251,15 +228,15 @@ int cmd_timer_clear(int argc, char **argv)

int res = timer_clear(dev, chan);

return _print_cmd_result("timer_clear", res == 1, res, true);
return _print_cmd_result("timer_clear", (res == 0), res, true);
}

int cmd_timer_read(int argc, char **argv)
{
uint32_t dev = 0;

if (_check_param(argc, argv, &dev, 1, 1, "dev") != RESULT_OK) {
return -1;
return RESULT_ERROR;
}

printf("Success: timer_read(): [%u]\n", timer_read(dev));
Expand All @@ -271,7 +248,7 @@ int cmd_timer_start(int argc, char **argv)
uint32_t dev = 0;

if (_check_param(argc, argv, &dev, 1, 1, "dev") != RESULT_OK) {
return -1;
return RESULT_ERROR;
}

timer_start(dev);
Expand All @@ -283,13 +260,52 @@ int cmd_timer_stop(int argc, char **argv)
uint32_t dev = 0;

if (_check_param(argc, argv, &dev, 1, 1, "dev") != RESULT_OK) {
return -1;
return RESULT_ERROR;
}

timer_stop(dev);
return _print_cmd_result("timer_stop", true, 0, false);
}

/* helper calls (non-API) */

int cmd_timer_debug_pin(int argc, char **argv)
{
uint32_t dev = 0;

if (_check_param(argc, argv, &dev, 3, 3, "dev gpio_port gpio_pin") != RESULT_OK) {
return RESULT_ERROR;
}
/* parse and init debug pin */
gpio_t pin = _get_pin(argv[2], argv[3]);
debug_pins[dev] = pin;
gpio_init(pin, GPIO_OUT);

return _print_cmd_result("timer_debug_pin", true, 0, false);
}

int cmd_timer_bench_read(int argc, char **argv)
{
uint32_t dev = 0;
uint32_t repeat_cnt = 0;

if (_check_param(argc, argv, &dev, 2, 2, "dev repeat_cnt") != RESULT_OK) {
return RESULT_ERROR;
}

gpio_t pin = debug_pins[dev];

gpio_toggle(pin);

for (uint32_t i = 0; i < repeat_cnt; i++) {
timer_read(dev);
}

gpio_toggle(pin);

return _print_cmd_result("cmd_timer_read_bench", true, 0, false);
}

int cmd_get_metadata(int argc, char **argv)
{
(void)argv;
Expand All @@ -301,16 +317,17 @@ int cmd_get_metadata(int argc, char **argv)
}

static const shell_command_t shell_commands[] = {
{ "timer_read_bench", "execute multiple reads to determine overhead",
cmd_timer_bench_read },
{ "timer_init", "init_timer", cmd_timer_init },
{ "timer_init", "Initialize timer device", cmd_timer_init },
{ "timer_set", "set timer to relative value", cmd_timer_set },
{ "timer_set_absolute", "set timer to absolute value",
cmd_timer_set_absolute },
{ "timer_clear", "clear timer", cmd_timer_clear },
{ "timer_read", "read timer", cmd_timer_read },
{ "timer_start", "start timer", cmd_timer_start },
{ "timer_stop", "stop timer", cmd_timer_stop },
{ "timer_debug_pin", "config debug pin", cmd_timer_debug_pin },
{ "timer_read_bench", "execute multiple reads to determine overhead",
cmd_timer_bench_read },
{ "get_metadata", "Get the metadata of the test firmware",
cmd_get_metadata },
{ NULL, NULL, NULL }
Expand Down
36 changes: 36 additions & 0 deletions tests/periph_timer/tests/01__periph_timer_base.robot
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
*** Settings ***
Documentation Verify basic functionality of the Periph Timer API.
# reset application and check DUT has correct firmware, skip all tests on error
Suite Setup Run Keywords PHiLIP.DUT Reset
... API Firmware Should Match
# reset application before running any test
Test Setup Run Keywords PHiLIP.DUT Reset
... API Sync Shell

# import libs and keywords
Resource api_shell.keywords.txt
Resource periph_timer.keywords.txt

# add default tags to all tests
Force Tags periph_timer

*** Test Cases ***
Timer Init Should Succeed
[Documentation] Verify timer_init return code
API Call Should Succeed Timer Init freq=%{PERIPH_TIMER_HZ}

Timer Read Should Succeed
[Documentation] Verify timer_read returns a value
API Call Should Succeed Timer Init freq=%{PERIPH_TIMER_HZ}
API Call Should Succeed Timer Read

Timer Clear Should Succeed
[Documentation] Verify timer_clear return code
API Call Should Succeed Timer Init freq=%{PERIPH_TIMER_HZ}
API Call Should Succeed Timer Clear

Timer Set Should Succeed
[Documentation] Verify timer_set return code
API Call Should Succeed Timer Init freq=%{PERIPH_TIMER_HZ}
API Call Should Succeed Timer Set ticks=${10000}
27 changes: 27 additions & 0 deletions tests/periph_timer/tests/02__periph_timer_extra.robot
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
*** Settings ***
Documentation Extended functionality checks of the Periph Timer API.
# reset application and check DUT has correct firmware, skip all tests on error
Suite Setup Run Keywords PHiLIP.DUT Reset
... API Firmware Should Match
# reset application before running any test
Test Setup Run Keywords PHiLIP.DUT Reset
... API Sync Shell

# import libs and keywords
Resource api_shell.keywords.txt
Resource periph_timer.keywords.txt

# add default tags to all tests
Force Tags periph_timer

*** Test Cases ***
Timer Values Should Differ
[Documentation] Verify timer values are different on consecutive reads
API Call Should Succeed Timer Debug Pin dev=0 port=%{DEBUG0_PORT} pin=%{DEBUG0_PIN}
API Call Should Succeed Timer Init freq=%{PERIPH_TIMER_HZ}
API Call Should Succeed Timer Read
${t1}= API Get Last Result As Integer
API Call Should Succeed Timer Read
${t2}= API Get Last Result As Integer
Should Be True ${t2} != ${t1}
26 changes: 26 additions & 0 deletions tests/periph_timer/tests/03__periph_timer_set_delays.robot
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
*** Settings ***
Documentation Evaluate Delays for numerous timer_set values.
# reset application and check DUT has correct firmware, skip all tests on error
Suite Setup Run Keywords PHiLIP.DUT Reset
... API Firmware Should Match
# reset application before running any test
Test Setup Run Keywords PHiLIP.DUT Reset
... PHILIP Reset
... API Sync Shell
# set test template for data driver tests
Test Template Measure Timer Set Delay
# import libs and keywords
Resource api_shell.keywords.txt
Resource periph_timer.keywords.txt

# add default tags to all tests
Force Tags periph_timer

*** Test Cases *** TICKS
Measure Delay of 100 Ticks ${100}
Measure Delay of 200 Ticks ${200}
Measure Delay of 1000 Ticks ${1000}
Measure Delay of 2000 Ticks ${2000}
Measure Delay of 10000 Ticks ${10000}
Measure Delay of 20000 Ticks ${20000}
File renamed without changes.
19 changes: 19 additions & 0 deletions tests/periph_timer/tests/periph_timer.keywords.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
*** Settings ***
Library PeriphTimer port=%{PORT} baudrate=%{BAUD} timeout=${%{CMD_TIMEOUT}} connect_wait=${%{CONNECT_WAIT}}

Resource api_shell.keywords.txt
Resource philip.keywords.txt

*** Keywords ***
Measure Timer Set Delay
[Documentation] Evaluates delay between timer_set and entering
... the timer ISR callback (measured by PHiLIP)
[Arguments] ${ticks}
PHILIP Trace GPIO 0
API Call Should Succeed Timer Debug Pin dev=0 port=%{DEBUG0_PORT} pin=%{DEBUG0_PIN}
API Call Should Succeed Timer Init freq=%{PERIPH_TIMER_HZ}
API Call Should Succeed Timer Set dev=0 chan=0 ticks=${ticks}
API Call Should Succeed PHiLIP.Read Trace
${trace}= Set Variable ${RESULT['data']}
${delay}= Evaluate ${trace}[-1][time] - ${trace}[-2][time]
Log Many ${ticks} ${delay}
Loading

0 comments on commit bce597d

Please sign in to comment.