From 94ba420ee398d45f2d21abe0b21edc663d45a30d Mon Sep 17 00:00:00 2001
From: Kaspar Schleiser <kaspar@schleiser.de>
Date: Fri, 15 Jun 2018 10:15:54 +0200
Subject: [PATCH] tests/bench_sched_nop: initial commit

---
 tests/bench_sched_nop/Makefile        | 10 +++++
 tests/bench_sched_nop/README.md       | 10 +++++
 tests/bench_sched_nop/main.c          | 57 +++++++++++++++++++++++++++
 tests/bench_sched_nop/tests/01-run.py | 21 ++++++++++
 4 files changed, 98 insertions(+)
 create mode 100644 tests/bench_sched_nop/Makefile
 create mode 100644 tests/bench_sched_nop/README.md
 create mode 100644 tests/bench_sched_nop/main.c
 create mode 100755 tests/bench_sched_nop/tests/01-run.py

diff --git a/tests/bench_sched_nop/Makefile b/tests/bench_sched_nop/Makefile
new file mode 100644
index 0000000000..d81df6d3c9
--- /dev/null
+++ b/tests/bench_sched_nop/Makefile
@@ -0,0 +1,10 @@
+include ../Makefile.tests_common
+
+USEMODULE += xtimer
+
+TEST_ON_CI_WHITELIST += all
+
+include $(RIOTBASE)/Makefile.include
+
+test:
+	tests/01-run.py
diff --git a/tests/bench_sched_nop/README.md b/tests/bench_sched_nop/README.md
new file mode 100644
index 0000000000..23028e4aa0
--- /dev/null
+++ b/tests/bench_sched_nop/README.md
@@ -0,0 +1,10 @@
+# About
+
+This test calls "thread_yield()" in a loop. As there is no other thread with a
+higher or same priority, this measures the raw context save / restore
+performance plus the (short) time the scheduler need to realize there's no
+other active thread.
+The result amounts to the number of thread_yield() calls per second.
+
+This test application intentionally duplicates code with some similar benchmark
+applications in order to be able to compare code sizes.
diff --git a/tests/bench_sched_nop/main.c b/tests/bench_sched_nop/main.c
new file mode 100644
index 0000000000..74126b67a4
--- /dev/null
+++ b/tests/bench_sched_nop/main.c
@@ -0,0 +1,57 @@
+/*
+ * 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       Scheduler 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 void _timer_callback(void*arg)
+{
+    (void)arg;
+
+    _flag = 1;
+}
+
+int main(void)
+{
+    printf("main starting\n");
+
+    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;
+}
diff --git a/tests/bench_sched_nop/tests/01-run.py b/tests/bench_sched_nop/tests/01-run.py
new file mode 100755
index 0000000000..3a1e733980
--- /dev/null
+++ b/tests/bench_sched_nop/tests/01-run.py
@@ -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))
-- 
GitLab