-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests/cb_mux: initial benchmark routine
- Loading branch information
Matthew Blue
committed
May 28, 2018
1 parent
c767cdd
commit 4c3edb2
Showing
3 changed files
with
126 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <[email protected]> | ||
* @} | ||
*/ | ||
|
||
#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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)) |