-
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/bench_thread_yield_pingpong: initial commit
- Loading branch information
Showing
4 changed files
with
118 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,12 @@ | ||
include ../Makefile.tests_common | ||
|
||
BOARD_INSUFFICIENT_MEMORY := nucleo-f031k6 | ||
|
||
USEMODULE += 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,8 @@ | ||
# About | ||
|
||
This test measures the amount of context switches between two threads of the | ||
same priority. The result amounts to the number of thread_yield() calls in | ||
*one* thread (half the number of actual context switches). | ||
|
||
This test application intentionally duplicates code with some similar benchmark | ||
applications in order to be able to compare code sizes. |
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,77 @@ | ||
/* | ||
* Copyright (C) 2017 Kaspar Schleiser <kaspar@schleiser.de> | ||
* | ||
* 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 Context switch benchmark test application | ||
* | ||
* @author Kaspar Schleiser <kaspar@schleiser.de> | ||
* | ||
* @} | ||
*/ | ||
|
||
#include <stdio.h> | ||
|
||
#include "thread.h" | ||
#include "xtimer.h" | ||
|
||
#ifndef TEST_DURATION | ||
#define TEST_DURATION (1000000U) | ||
#endif | ||
|
||
volatile unsigned _flag = 0; | ||
static char _stack[THREAD_STACKSIZE_MAIN]; | ||
|
||
static void _timer_callback(void*arg) | ||
{ | ||
(void)arg; | ||
|
||
_flag = 1; | ||
} | ||
|
||
static void *_second_thread(void *arg) | ||
{ | ||
(void)arg; | ||
|
||
while(1) { | ||
thread_yield(); | ||
} | ||
|
||
return NULL; | ||
} | ||
|
||
int main(void) | ||
{ | ||
printf("main starting\n"); | ||
|
||
thread_create(_stack, | ||
sizeof(_stack), | ||
THREAD_PRIORITY_MAIN, | ||
THREAD_CREATE_STACKTEST, | ||
_second_thread, | ||
NULL, | ||
"second_thread"); | ||
|
||
xtimer_t timer; | ||
timer.callback = _timer_callback; | ||
|
||
uint32_t n = 0; | ||
|
||
xtimer_set(&timer, TEST_DURATION); | ||
while(!_flag) { | ||
thread_yield(); | ||
n++; | ||
} | ||
|
||
printf("{ \"result\" : %"PRIu32" }\n", n); | ||
|
||
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,21 @@ | ||
#!/usr/bin/env python3 | ||
|
||
# Copyright (C) 2018 Kaspar Schleiser <kaspar@schleiser.de> | ||
# 2017 Sebastian Meiling <s@mlng.net> | ||
# | ||
# 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(r"{ \"result\" : \d+ }") | ||
|
||
|
||
if __name__ == "__main__": | ||
sys.path.append(os.path.join(os.environ['RIOTTOOLS'], 'testrunner')) | ||
from testrunner import run | ||
sys.exit(run(testfunc)) |