diff options
author | aqua <aqua@iserlohn-fortress.net> | 2024-03-08 17:24:49 +0200 |
---|---|---|
committer | aqua <aqua@iserlohn-fortress.net> | 2024-03-08 22:00:07 +0200 |
commit | 20b97ea7c0dbbdc13800e12ff5c86c00c4a342ec (patch) | |
tree | 473281e5fc8b256827ce1a678573444e1aa5f669 /src/sched/test_taskqueue.cc | |
parent | Generate src/conf.h (diff) | |
download | kernel-20b97ea7c0dbbdc13800e12ff5c86c00c4a342ec.tar.xz |
Bazel build
Diffstat (limited to 'src/sched/test_taskqueue.cc')
-rw-r--r-- | src/sched/test_taskqueue.cc | 122 |
1 files changed, 0 insertions, 122 deletions
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(); -} |