Skip to content
Snippets Groups Projects
Commit b9d8f931 authored by Kaspar Schleiser's avatar Kaspar Schleiser
Browse files

tests/bench_msg_pingpong: initial commit

parent e91e0a78
No related branches found
No related tags found
No related merge requests found
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
# About
This test will measure the amount of messages that could be sent from one
thread to another during an interval of one second. The result amounts to the
number of messages sent, which is half the number of context switches incurred
through sending the messages.
This test application intentionally duplicates code with some similar benchmark
applications in order to be able to compare code sizes.
/*
* 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 Measure messages send per second
*
* @author Kaspar Schleiser <kaspar@schleiser.de>
*
* @}
*/
#include <stdio.h>
#include "thread.h"
#include "msg.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;
msg_t test;
while(1) {
msg_receive(&test);
}
return NULL;
}
int main(void)
{
printf("main starting\n");
kernel_pid_t other = thread_create(_stack,
sizeof(_stack),
(THREAD_PRIORITY_MAIN - 1),
THREAD_CREATE_STACKTEST,
_second_thread,
NULL,
"second_thread");
xtimer_t timer;
timer.callback = _timer_callback;
msg_t test;
uint32_t n = 0;
xtimer_set(&timer, TEST_DURATION);
while(!_flag) {
msg_send(&test, other);
n++;
}
printf("{ \"result\" : %"PRIu32" }\n", n);
return 0;
}
#!/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))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment