tests/cb_mux: initial benchmark routine
This commit is contained in:
parent
c767cdd0bb
commit
7a95463649
11
tests/cb_mux_bench/Makefile
Normal file
11
tests/cb_mux_bench/Makefile
Normal file
@ -0,0 +1,11 @@
|
||||
include ../Makefile.tests_common
|
||||
|
||||
USEMODULE += cb_mux \
|
||||
xtimer
|
||||
|
||||
TEST_ON_CI_WHITELIST += all
|
||||
|
||||
include $(RIOTBASE)/Makefile.include
|
||||
|
||||
test:
|
||||
./tests/01-run.py
|
||||
90
tests/cb_mux_bench/main.c
Normal file
90
tests/cb_mux_bench/main.c
Normal file
@ -0,0 +1,90 @@
|
||||
/*
|
||||
* 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 cb_mux benchmark application
|
||||
*
|
||||
* @author Matthew Blue <matthew.blue.neuro@gmail.com>
|
||||
* @}
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include "cb_mux.h"
|
||||
#include "xtimer.h"
|
||||
|
||||
/* Number of entries in the cb_mux list */
|
||||
#define NUM_ENTRIES (20U)
|
||||
|
||||
/* Fail if us greater than threshold */
|
||||
#define FAIL_THRESH (200UL)
|
||||
|
||||
/* Head of cb_mux list */
|
||||
cb_mux_t *cb_mux_head;
|
||||
|
||||
/* cb_mux list entries */
|
||||
cb_mux_t entries[NUM_ENTRIES];
|
||||
|
||||
/* Timing */
|
||||
unsigned long time_prev, time_curr;
|
||||
|
||||
void cb(void *arg)
|
||||
{
|
||||
(void)arg;
|
||||
time_curr = xtimer_now_usec();
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
unsigned long xtimer_delay, time_diff;
|
||||
uint8_t num;
|
||||
cb_mux_t *entry;
|
||||
|
||||
puts("cb_mux benchmark application");
|
||||
|
||||
/* Delay due to fetching timer with xtimer */
|
||||
time_prev = xtimer_now_usec();
|
||||
xtimer_delay = time_prev - xtimer_now_usec();
|
||||
|
||||
/* Test for worst case: finding last entry */
|
||||
entries[NUM_ENTRIES - 1].cbid = 1;
|
||||
|
||||
printf("Populating cb_mux list with %u items\n", NUM_ENTRIES);
|
||||
|
||||
for (num = 0; num < NUM_ENTRIES; num++) {
|
||||
entries[num].cb = cb;
|
||||
cb_mux_add(&cb_mux_head, &(entries[num]));
|
||||
}
|
||||
|
||||
puts("Finding the last list entry");
|
||||
|
||||
time_prev = xtimer_now_usec();
|
||||
|
||||
entry = cb_mux_find_cbid(cb_mux_head, 1);
|
||||
entry->cb(entry->arg);
|
||||
|
||||
time_diff = time_curr - time_prev - xtimer_delay;
|
||||
|
||||
printf("List walk time: %lu us\n", time_diff);
|
||||
|
||||
if (time_diff > FAIL_THRESH) {
|
||||
printf("Walk time greater than threshold of %lu us\n", FAIL_THRESH);
|
||||
puts("[FAILURE]");
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
printf("Walk time less than threshold of %lu us\n", FAIL_THRESH);
|
||||
puts("[SUCCESS]");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
25
tests/cb_mux_bench/tests/01-run.py
Executable file
25
tests/cb_mux_bench/tests/01-run.py
Executable file
@ -0,0 +1,25 @@
|
||||
#!/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("cb_mux benchmark application")
|
||||
child.expect(u"Populating cb_mux list with \d+ items")
|
||||
child.expect_exact("Finding the last list entry")
|
||||
child.expect(u"List walk time: \d+ us")
|
||||
child.expect(u"Walk time less than threshold of \d+ us")
|
||||
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))
|
||||
Loading…
x
Reference in New Issue
Block a user