tests: add core API runtime benchmark

This commit is contained in:
Hauke Petersen 2018-06-14 13:25:37 +02:00
parent a027a1e608
commit e9f9905079
5 changed files with 132 additions and 6 deletions

View File

@ -0,0 +1,12 @@
include ../Makefile.tests_common
# we use thread flags in this benchmark by default, disable on demand
USEMODULE += core_thread_flags
USEMODULE += benchmark
TEST_ON_CI_WHITELIST += all
include $(RIOTBASE)/Makefile.include
test:
tests/01-run.py

View File

@ -0,0 +1,7 @@
# Measure Runtime of Selected Core API functions
This benchmark application measures the runtime of selected core API functions.
Its purpose is to provide a baseline to assess the impacts when doing changes to
core code.
This application is not complete, simply add additional runs if needed.

View File

@ -0,0 +1,83 @@
/*
* Copyright (C) 2018 Freie Universität Berlin
*
* 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 runtime of select core API functions
*
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
*
* @}
*/
#include <stdio.h>
#include "mutex.h"
#include "benchmark.h"
#include "thread.h"
#include "thread_flags.h"
#ifndef BENCH_RUNS
#define BENCH_RUNS (1000UL * 1000UL)
#endif
static mutex_t _lock;
static thread_t *t;
static thread_flags_t _flag = 0x0001;
static msg_t _msg;
static void _mutex_lockunlock(void)
{
mutex_lock(&_lock);
mutex_unlock(&_lock);
}
static void _flag_waitany(void)
{
thread_flags_set(t, _flag);
thread_flags_wait_any(_flag);
}
static void _flag_waitall(void)
{
thread_flags_set(t, _flag);
thread_flags_wait_all(_flag);
}
static void _flag_waitone(void)
{
thread_flags_set(t, _flag);
thread_flags_wait_one(_flag);
}
int main(void)
{
puts("Runtime of Selected Core API functions\n");
t = (thread_t *)sched_active_thread;
BENCHMARK_FUNC("nop loop", BENCH_RUNS, __asm__ volatile ("nop"));
puts("");
BENCHMARK_FUNC("mutex_init()", BENCH_RUNS, mutex_init(&_lock));
BENCHMARK_FUNC("mutex lock/unlock", BENCH_RUNS, _mutex_lockunlock());
puts("");
BENCHMARK_FUNC("thread_flags_set()", BENCH_RUNS, thread_flags_set(t, _flag));
BENCHMARK_FUNC("thread_flags_clear()", BENCH_RUNS, thread_flags_clear(_flag));
BENCHMARK_FUNC("thread flags set/wait any", BENCH_RUNS, _flag_waitany());
BENCHMARK_FUNC("thread flags set/wait all", BENCH_RUNS, _flag_waitall());
BENCHMARK_FUNC("thread flags set/wait one", BENCH_RUNS, _flag_waitone());
puts("");
BENCHMARK_FUNC("msg_try_receive()", BENCH_RUNS, msg_try_receive(&_msg));
BENCHMARK_FUNC("msg_avail()", BENCH_RUNS, msg_avail());
puts("\n[SUCCESS]");
return 0;
}

View File

@ -0,0 +1,24 @@
#!/usr/bin/env python3
# Copyright (C) 2018 Freie Universität Berlin
#
# 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
# The default timeout is not enough for this test on some of the slower boards
TIMEOUT = 30
def testfunc(child):
child.expect_exact('[SUCCESS]', timeout=TIMEOUT)
if __name__ == "__main__":
sys.path.append(os.path.join(os.environ['RIOTTOOLS'], 'testrunner'))
from testrunner import run
sys.exit(run(testfunc))

View File

@ -16,12 +16,12 @@ def testfunc(child):
for pin in range(0, 8): for pin in range(0, 8):
child.sendline("bench 0 {}".format(pin)) child.sendline("bench 0 {}".format(pin))
child.expect(r" *nop loop: +(\d+)us --- +(\d+\.\d+)us per call") child.expect(r" *nop loop: +(\d+)us --- +(\d+\.\d+)us per call --- +(\d+) calls per sec")
child.expect(r" *gpio_set: +(\d+)us --- +(\d+\.\d+)us per call") child.expect(r" *gpio_set: +(\d+)us --- +(\d+\.\d+)us per call --- +(\d+) calls per sec")
child.expect(r" *gpio_clear: +(\d+)us --- +(\d+\.\d+)us per call") child.expect(r" *gpio_clear: +(\d+)us --- +(\d+\.\d+)us per call --- +(\d+) calls per sec")
child.expect(r" *gpio_toggle: +(\d+)us --- +(\d+\.\d+)us per call") child.expect(r" *gpio_toggle: +(\d+)us --- +(\d+\.\d+)us per call --- +(\d+) calls per sec")
child.expect(r" *gpio_read: +(\d+)us --- +(\d+\.\d+)us per call") child.expect(r" *gpio_read: +(\d+)us --- +(\d+\.\d+)us per call --- +(\d+) calls per sec")
child.expect(r" *gpio_write: +(\d+)us --- +(\d+\.\d+)us per call") child.expect(r" *gpio_write: +(\d+)us --- +(\d+\.\d+)us per call --- +(\d+) calls per sec")
child.expect_exact(" --- DONE ---") child.expect_exact(" --- DONE ---")
child.expect_exact(">") child.expect_exact(">")