aboutsummaryrefslogtreecommitdiff
path: root/src/tst/roundrobin.cc
diff options
context:
space:
mode:
authoraqua <aqua@iserlohn-fortress.net>2023-03-05 14:38:54 +0200
committeraqua <aqua@iserlohn-fortress.net>2023-03-05 14:38:54 +0200
commit787c1a6016dd2fdb51f20fcb5ca0ac5e461892d6 (patch)
tree7db9f5102adc3d50ca85a8175ce67465256b8908 /src/tst/roundrobin.cc
parentAdd TARGETBIN and TARGETLIB rules (diff)
downloadkernel-787c1a6016dd2fdb51f20fcb5ca0ac5e461892d6.tar.xz
Move all tests next to the code they're testingHEADmaster
Diffstat (limited to 'src/tst/roundrobin.cc')
-rw-r--r--src/tst/roundrobin.cc50
1 files changed, 0 insertions, 50 deletions
diff --git a/src/tst/roundrobin.cc b/src/tst/roundrobin.cc
deleted file mode 100644
index 1431788..0000000
--- a/src/tst/roundrobin.cc
+++ /dev/null
@@ -1,50 +0,0 @@
-#include <chrono>
-#include <gtest/gtest.h>
-#include <iomanip>
-#include <iostream>
-#include <valgrind/valgrind.h>
-
-#include "../sched/roundrobin.cpp"
-
-void
-run(Task *task, int slice)
-{
- std::cout << "Running task " << task->name << " id=" << std::setw(2) << task->id << " prio=" << std::setw(2)
- << task->priority << " burst=" << std::setw(2) << task->burst << " slice=" << slice << " ";
-}
-
-struct DebugRoundRobinQueue : public RoundRobinQueue {
-public:
- void
- print() const
- {
- for (auto *it = head; it != nullptr; it = it->next) {
- std::cout << it->node->name << '(' << std::setw(2) << it->node->burst << ") ";
- }
- std::cout << std::endl;
- }
-};
-
-TEST(roundrobin, RoundRobinQueue)
-{
- DebugRoundRobinQueue queue;
- queue.insert(new Task{"P1", 1, 1, 50});
- queue.insert(new Task{"P2", 2, 1, 40});
- queue.insert(new Task{"P3", 3, 1, 50});
- queue.insert(new Task{"P4", 4, 1, 40});
-
- const auto begin = std::chrono::system_clock::now();
- for (auto *t = queue.next(10); t != nullptr; t = queue.next(10)) {
- run(t, 10);
- queue.print();
- }
- const auto end = std::chrono::system_clock::now();
- const auto duration = std::chrono::duration_cast<std::chrono::microseconds>(end - begin).count();
-
- std::cout << "Completed in (us): " << duration << std::endl;
- // test should complete in 250us unless running on valgrind
- if (!RUNNING_ON_VALGRIND) EXPECT_LE(duration, 250);
-
- EXPECT_EQ(queue.head, nullptr);
- EXPECT_EQ(queue.tail, nullptr);
-}