aboutsummaryrefslogtreecommitdiff
path: root/src/sched
diff options
context:
space:
mode:
authoraqua <aqua@iserlohn-fortress.net>2024-03-08 17:24:49 +0200
committeraqua <aqua@iserlohn-fortress.net>2024-03-08 22:00:07 +0200
commit20b97ea7c0dbbdc13800e12ff5c86c00c4a342ec (patch)
tree473281e5fc8b256827ce1a678573444e1aa5f669 /src/sched
parentGenerate src/conf.h (diff)
downloadkernel-20b97ea7c0dbbdc13800e12ff5c86c00c4a342ec.tar.xz
Bazel build
Diffstat (limited to 'src/sched')
-rw-r--r--src/sched/roundrobin.cpp21
-rw-r--r--src/sched/test_roundrobin.cc50
-rw-r--r--src/sched/test_taskqueue.cc122
3 files changed, 0 insertions, 193 deletions
diff --git a/src/sched/roundrobin.cpp b/src/sched/roundrobin.cpp
deleted file mode 100644
index c3d6cb6..0000000
--- a/src/sched/roundrobin.cpp
+++ /dev/null
@@ -1,21 +0,0 @@
-#include "../sched.hpp"
-
-/// Each task is run for a time quantum or the remainder of its cpu burst
-Task *
-RoundRobinQueue::next(int slice)
-{
- if (head == nullptr) return nullptr;
- if (head->node->burst <= 0) {
- delete head->node;
- remove(head->node);
- return next(slice);
- }
-
- auto *it = head;
- it->node->burst -= slice;
- if (head->next) head = head->next;
- it->next = nullptr;
- tail->next = it;
- tail = it;
- return it->node;
-}
diff --git a/src/sched/test_roundrobin.cc b/src/sched/test_roundrobin.cc
deleted file mode 100644
index 89f60bf..0000000
--- a/src/sched/test_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);
-}
diff --git a/src/sched/test_taskqueue.cc b/src/sched/test_taskqueue.cc
deleted file mode 100644
index 217c44d..0000000
--- a/src/sched/test_taskqueue.cc
+++ /dev/null
@@ -1,122 +0,0 @@
-#include <gtest/gtest.h>
-
-#include "../sched.hpp"
-
-struct DebugQueue : public Queue<Task> {
-public:
- void
- expect_ordered() const
- {
- int id = 1;
- for (auto *it = head; it != nullptr; it = it->next) {
- // std::cout << it->node->name << std::endl;
- EXPECT_EQ(it->node->id, id++);
- }
- }
-};
-
-TEST(taskqueue, insert)
-{
- DebugQueue queue;
- auto *p1 = new Task{"P1", 1, 1, 10};
- queue.insert(p1);
- queue.insert(new Task{"P2", 2, 1, 10});
- queue.insert(new Task{"P3", 3, 1, 10});
- auto *p4 = new Task{"P4", 4, 1, 10};
- queue.insert(p4);
- queue.expect_ordered();
-
- EXPECT_EQ(queue.head->node, p1);
- EXPECT_EQ(queue.tail->node, p4);
-}
-
-TEST(taskqueue, removeHead)
-{
- DebugQueue queue;
- auto *p0 = new Task{"P0", 0, 1, 10};
- queue.insert(p0);
- auto *p1 = new Task{"P1", 1, 1, 10};
- queue.insert(p1);
- queue.insert(new Task{"P2", 2, 1, 10});
- queue.insert(new Task{"P3", 3, 1, 10});
- auto *p4 = new Task{"P4", 4, 1, 10};
- queue.insert(p4);
- queue.remove(p0);
- delete p0;
-
- EXPECT_EQ(queue.head->node, p1);
- EXPECT_EQ(queue.tail->node, p4);
- queue.expect_ordered();
-}
-
-TEST(taskqueue, removeTail)
-{
- DebugQueue queue;
- auto *p1 = new Task{"P1", 1, 1, 10};
- queue.insert(p1);
- queue.insert(new Task{"P2", 2, 1, 10});
- queue.insert(new Task{"P3", 3, 1, 10});
- auto *p4 = new Task{"P4", 4, 1, 10};
- queue.insert(p4);
- auto *p5 = new Task{"P5", 5, 1, 10};
- queue.insert(p5);
- EXPECT_EQ(queue.head->node, p1);
- EXPECT_EQ(queue.tail->node, p5);
-
- queue.remove(p5);
- delete p5;
-
- EXPECT_EQ(queue.head->node, p1);
- EXPECT_EQ(queue.tail->node, p4);
- queue.expect_ordered();
-}
-
-TEST(taskqueue, removeLast)
-{
- DebugQueue queue;
-
- auto *p0 = new Task{"P0", 0, 1, 10};
- queue.insert(p0);
- EXPECT_EQ(queue.head->node, p0);
- EXPECT_EQ(queue.tail->node, p0);
-
- queue.remove(p0);
- delete p0;
-
- EXPECT_EQ(queue.head, nullptr);
- EXPECT_EQ(queue.tail, nullptr);
-}
-
-TEST(taskqueue, removeNullptr)
-{
- DebugQueue queue;
- queue.insert(new Task{"P1", 1, 1, 10});
- queue.insert(new Task{"P2", 2, 1, 10});
- queue.insert(new Task{"P3", 3, 1, 10});
- queue.insert(new Task{"P4", 4, 1, 10});
- queue.remove(nullptr);
- queue.expect_ordered();
-}
-
-TEST(taskqueue, remove)
-{
- DebugQueue queue;
- auto *p1 = new Task{"P1", 1, 1, 10};
- queue.insert(p1);
- queue.insert(new Task{"P2", 2, 1, 10});
- auto *p0 = new Task{"P0", 0, 1, 10};
- queue.insert(p0);
- queue.insert(new Task{"P3", 3, 1, 10});
- auto *p4 = new Task{"P4", 4, 1, 10};
- queue.insert(p4);
-
- EXPECT_EQ(queue.head->node, p1);
- EXPECT_EQ(queue.tail->node, p4);
-
- queue.remove(p0);
- delete p0;
-
- EXPECT_EQ(queue.head->node, p1);
- EXPECT_EQ(queue.tail->node, p4);
- queue.expect_ordered();
-}