mirror of
https://github.com/Fennix-Project/Kernel.git
synced 2025-07-10 23:09:18 +00:00
Refactor filesystem & stl code
This commit is contained in:
@ -1,82 +0,0 @@
|
||||
/*
|
||||
This file is part of Fennix Kernel.
|
||||
|
||||
Fennix Kernel is free software: you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation, either version 3 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
Fennix Kernel is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifdef DEBUG
|
||||
|
||||
#include "t.h"
|
||||
|
||||
#include "../kernel.h"
|
||||
|
||||
using vfs::Node;
|
||||
using vfs::NodeType;
|
||||
|
||||
static int ShowOpenFiles = 0;
|
||||
|
||||
void lsof()
|
||||
{
|
||||
thisThread->Rename("Debug File List");
|
||||
thisThread->SetPriority(Tasking::Idle);
|
||||
|
||||
while (ShowOpenFiles == 0)
|
||||
CPU::Pause();
|
||||
|
||||
thisThread->SetPriority(Tasking::High);
|
||||
|
||||
fs->Create("/dummy_lsof_file", NodeType::FILE);
|
||||
fs->Open("/dummy_lsof_file");
|
||||
|
||||
while (true)
|
||||
{
|
||||
while (ShowOpenFiles == 0)
|
||||
CPU::Pause();
|
||||
|
||||
for (short i = 0; i < 500; i++)
|
||||
{
|
||||
for (short j = 0; j < 500; j++)
|
||||
{
|
||||
Video::Pixel *p = (Video::Pixel *)((uintptr_t)Display->GetBuffer +
|
||||
(j * Display->GetWidth + i) *
|
||||
(bInfo.Framebuffer[0].BitsPerPixel / 8));
|
||||
*p = {0xFF, 0x22, 0x22, 0x22};
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t tmpX, tmpY;
|
||||
Display->GetBufferCursor(&tmpX, &tmpY);
|
||||
Display->SetBufferCursor(0, 0);
|
||||
printf("\eF02C21Open Files (%ld):\e00AAAA\n",
|
||||
TaskManager->GetProcessList().size());
|
||||
foreach (auto Proc in TaskManager->GetProcessList())
|
||||
{
|
||||
if (!Proc)
|
||||
continue;
|
||||
|
||||
printf("%s:\n", Proc->Name);
|
||||
|
||||
std::vector<vfs::FileDescriptorTable::Fildes> fds_array =
|
||||
Proc->FileDescriptors->GetFileDescriptors();
|
||||
foreach (auto fd in fds_array)
|
||||
printf(" %d: %s\n", fd.Descriptor,
|
||||
fd.Handle->node->FullPath);
|
||||
}
|
||||
Display->SetBufferCursor(tmpX, tmpY);
|
||||
if (!Config.Quiet)
|
||||
Display->UpdateBuffer();
|
||||
}
|
||||
}
|
||||
|
||||
#endif // DEBUG
|
@ -19,14 +19,13 @@
|
||||
|
||||
#include <types.h>
|
||||
#include <filesystem/ioctl.hpp>
|
||||
#include <interface/syscalls.h>
|
||||
#include <memory/macro.hpp>
|
||||
#include <memory/vma.hpp>
|
||||
#include <filesystem.hpp>
|
||||
#include <assert.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <filesystem.hpp>
|
||||
#include "../syscalls.h"
|
||||
|
||||
/* static assert, no constructor needed */
|
||||
|
||||
#ifdef a64
|
||||
@ -51,9 +50,6 @@
|
||||
#error "This compiler is not supported!"
|
||||
#endif // __fennix__
|
||||
|
||||
static_assert(sc_SEEK_SET == SEEK_SET);
|
||||
static_assert(sc_SEEK_CUR == SEEK_CUR);
|
||||
static_assert(sc_SEEK_END == SEEK_END);
|
||||
static_assert(TIOCGPTN == 0x80045430);
|
||||
static_assert(TIOCSPTLCK == 0x40045431);
|
||||
|
||||
|
197
tests/std.cpp
197
tests/std.cpp
@ -1,197 +0,0 @@
|
||||
/*
|
||||
This file is part of Fennix Kernel.
|
||||
|
||||
Fennix Kernel is free software: you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation, either version 3 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
Fennix Kernel is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifdef DEBUG
|
||||
|
||||
#include <assert.h>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
#include <atomic>
|
||||
#include <bitset>
|
||||
#include <list>
|
||||
|
||||
void Test_std()
|
||||
{
|
||||
std::atomic_int a = 0;
|
||||
a++;
|
||||
assert(a == 1);
|
||||
|
||||
int b = a.exchange(2);
|
||||
assert(b == 1);
|
||||
assert(a == 2);
|
||||
|
||||
/* ---------------------------- */
|
||||
|
||||
std::vector<int> intVector;
|
||||
intVector.push_back(10);
|
||||
intVector.push_back(20);
|
||||
intVector.push_back(30);
|
||||
assert(intVector.size() == 3);
|
||||
|
||||
assert(intVector[0] == 10);
|
||||
assert(intVector[1] == 20);
|
||||
assert(intVector[2] == 30);
|
||||
|
||||
intVector.pop_back();
|
||||
assert(intVector.size() == 2);
|
||||
|
||||
intVector.clear();
|
||||
assert(intVector.empty());
|
||||
|
||||
intVector.push_back(1);
|
||||
intVector.push_back(1);
|
||||
intVector.push_back(1);
|
||||
intVector.push_back(1);
|
||||
intVector.push_back(1);
|
||||
|
||||
intVector.erase(intVector.end() - 1);
|
||||
assert(intVector.size() == 4);
|
||||
debug("0: %#lx", intVector[0]);
|
||||
debug("1: %#lx", intVector[1]);
|
||||
debug("2: %#lx", intVector[2]);
|
||||
debug("3: %#lx", intVector[3]);
|
||||
debug("4: %#lx", intVector[4]);
|
||||
|
||||
/* ---------------------------- */
|
||||
|
||||
std::list<int> intList;
|
||||
intList.push_back(10);
|
||||
intList.push_back(20);
|
||||
intList.push_back(30);
|
||||
assert(intList.size() == 3);
|
||||
|
||||
assert(intList.front() == 10);
|
||||
assert(intList.back() == 30);
|
||||
|
||||
intList.pop_back();
|
||||
assert(intList.size() == 2);
|
||||
|
||||
intList.clear();
|
||||
assert(intList.empty());
|
||||
|
||||
/* ---------------------------- */
|
||||
|
||||
std::unordered_map<int, int> intMap;
|
||||
intMap[1] = 10;
|
||||
intMap[2] = 20;
|
||||
intMap[3] = 30;
|
||||
assert(intMap.size() == 3);
|
||||
|
||||
assert(intMap[1] == 10);
|
||||
assert(intMap[2] == 20);
|
||||
assert(intMap[3] == 30);
|
||||
|
||||
intMap.erase(1);
|
||||
assert(intMap.size() == 2);
|
||||
|
||||
intMap.clear();
|
||||
assert(intMap.empty());
|
||||
|
||||
std::unordered_map<const char *, int> strMap;
|
||||
strMap["hello"] = 10;
|
||||
strMap["world"] = 20;
|
||||
strMap["foo"] = 30;
|
||||
assert(strMap.size() == 3);
|
||||
|
||||
assert(strMap["hello"] == 10);
|
||||
assert(strMap["world"] == 20);
|
||||
assert(strMap["foo"] == 30);
|
||||
|
||||
strMap.erase("hello");
|
||||
assert(strMap.size() == 2);
|
||||
|
||||
strMap.clear();
|
||||
assert(strMap.empty());
|
||||
|
||||
/* ---------------------------- */
|
||||
|
||||
std::hash<int> intHash;
|
||||
|
||||
size_t a0 = intHash(0xdeadbeef);
|
||||
size_t a1 = intHash(0xdeadbeef);
|
||||
size_t a2 = intHash(1);
|
||||
size_t a3 = intHash(2);
|
||||
|
||||
debug("a0: %#lx", a0);
|
||||
debug("a1: %#lx", a1);
|
||||
debug("a2: %#lx", a2);
|
||||
debug("a3: %#lx", a3);
|
||||
|
||||
assert(a0 == a1);
|
||||
assert(a2 != a3);
|
||||
|
||||
/* ---------------------------- */
|
||||
|
||||
/* https://en.cppreference.com/w/cpp/utility/bitset */
|
||||
|
||||
typedef std::size_t length_t, position_t;
|
||||
constexpr std::bitset<4> bs1;
|
||||
constexpr std::bitset<4> bs2{0xA};
|
||||
std::bitset<4> bs3{"0011"};
|
||||
std::bitset<8> bs4{"ABBA", length_t(4), 'A', 'B'};
|
||||
|
||||
debug("bs1: %s; bs2: %s; bs3: %s; bs4: %s",
|
||||
bs1.to_string().c_str(), bs2.to_string().c_str(),
|
||||
bs3.to_string().c_str(), bs4.to_string().c_str());
|
||||
|
||||
assert(bs1 == 0b0000);
|
||||
assert(bs2 == 0b1010);
|
||||
assert(bs3 == 0b0011);
|
||||
assert(bs4 == 0b00000110);
|
||||
|
||||
bs3 |= 0b0100;
|
||||
assert(bs3 == 0b0111);
|
||||
bs3 &= 0b0011;
|
||||
assert(bs3 == 0b0011);
|
||||
bs3 ^= std::bitset<4>{0b1100};
|
||||
assert(bs3 == 0b1111);
|
||||
|
||||
bs3.reset();
|
||||
assert(bs3 == 0);
|
||||
bs3.set();
|
||||
assert(bs3 == 0b1111);
|
||||
bool all = bs3.all();
|
||||
bool any = bs3.any();
|
||||
bool none = bs3.none();
|
||||
debug("all: %d; any: %d; none: %d", all, any, none);
|
||||
assert(all && any && !none);
|
||||
bs3.flip();
|
||||
assert(bs3 == 0);
|
||||
|
||||
bs3.set(position_t(1), true);
|
||||
assert(bs3 == 0b0010);
|
||||
bs3.set(position_t(1), false);
|
||||
assert(bs3 == 0);
|
||||
bs3.flip(position_t(2));
|
||||
assert(bs3 == 0b0100);
|
||||
bs3.reset(position_t(2));
|
||||
assert(bs3 == 0);
|
||||
|
||||
bs3[2] = true;
|
||||
assert(true == bs3[2]);
|
||||
|
||||
assert(bs3.count() == 1);
|
||||
assert(bs3.size() == 4);
|
||||
assert(bs3.to_ullong() == 0b0100ULL);
|
||||
assert(bs3.to_string() == "0100");
|
||||
|
||||
/* ---------------------------- */
|
||||
|
||||
debug("std: OK");
|
||||
}
|
||||
|
||||
#endif // DEBUG
|
@ -1,153 +0,0 @@
|
||||
/*
|
||||
This file is part of Fennix Kernel.
|
||||
|
||||
Fennix Kernel is free software: you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation, either version 3 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
Fennix Kernel is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifdef DEBUG
|
||||
|
||||
#include <memory.hpp>
|
||||
#include <debug.h>
|
||||
#include <string>
|
||||
|
||||
void TestString()
|
||||
{
|
||||
char *sanity_alloc = (char *)kmalloc(1024);
|
||||
for (int i = 0; i < 1024; i++)
|
||||
sanity_alloc[i] = 'A';
|
||||
std::string hw("Hello, world!");
|
||||
|
||||
for (int i = 0; i < 1024; i++)
|
||||
if (sanity_alloc[i] != 'A')
|
||||
{
|
||||
error("Sanity check failed! %d", i);
|
||||
inf_loop;
|
||||
}
|
||||
|
||||
debug("String length: %d", hw.length());
|
||||
debug("String capacity: %d", hw.capacity());
|
||||
debug("String data: %s", hw.c_str());
|
||||
if (hw == "Hello, world!" && hw != "World, hello!")
|
||||
debug("String comparison works!");
|
||||
else
|
||||
{
|
||||
error("String comparison doesn't work! \"%s\"", hw.c_str());
|
||||
inf_loop;
|
||||
}
|
||||
|
||||
for (int i = 0; i < 1024; i++)
|
||||
if (sanity_alloc[i] != 'A')
|
||||
{
|
||||
error("Sanity check failed! %d", i);
|
||||
inf_loop;
|
||||
}
|
||||
|
||||
kfree(sanity_alloc);
|
||||
|
||||
std::string hi("Hi");
|
||||
char chi[3];
|
||||
chi[0] = hi[0];
|
||||
chi[1] = hi[1];
|
||||
chi[2] = '\0';
|
||||
if (strcmp(chi, "Hi") == 0)
|
||||
debug("String indexing works!");
|
||||
else
|
||||
{
|
||||
error("String indexing doesn't work! \"%s\" \"%s\"", chi, hi.c_str());
|
||||
inf_loop;
|
||||
}
|
||||
|
||||
sanity_alloc = (char *)kmalloc(1024);
|
||||
for (int i = 0; i < 1024; i++)
|
||||
sanity_alloc[i] = 'A';
|
||||
|
||||
hi << " there!";
|
||||
if (hi == "Hi there!")
|
||||
debug("String concatenation works!");
|
||||
else
|
||||
{
|
||||
error("String concatenation doesn't work! \"%s\"", hi.c_str());
|
||||
inf_loop;
|
||||
}
|
||||
|
||||
hi << " " << hw;
|
||||
if (hi == "Hi there! Hello, world!")
|
||||
debug("String concatenation works!");
|
||||
else
|
||||
{
|
||||
error("String concatenation doesn't work! \"%s\"", hi.c_str());
|
||||
inf_loop;
|
||||
}
|
||||
|
||||
std::string eq0("Hello, world!");
|
||||
std::string eq1("Hello, world!");
|
||||
std::string eq2("World, hello!");
|
||||
|
||||
if (eq0 == eq1)
|
||||
debug("String equality works!");
|
||||
else
|
||||
{
|
||||
error("String equality doesn't work! \"%s\" \"%s\"", eq0.c_str(), eq1.c_str());
|
||||
inf_loop;
|
||||
}
|
||||
|
||||
if (eq0 != eq2)
|
||||
debug("String inequality works!");
|
||||
else
|
||||
{
|
||||
error("String inequality doesn't work! \"%s\" \"%s\"", eq0.c_str(), eq2.c_str());
|
||||
inf_loop;
|
||||
}
|
||||
|
||||
char chw[14];
|
||||
int i = 0;
|
||||
foreach (auto c in hw)
|
||||
{
|
||||
chw[i] = c;
|
||||
i++;
|
||||
}
|
||||
chw[i] = '\0';
|
||||
|
||||
if (strcmp(chw, "Hello, world!") == 0)
|
||||
debug("String iteration works!");
|
||||
else
|
||||
{
|
||||
error("String iteration doesn't work! \"%s\" \"%s\" %d", chw, hw.c_str(), i);
|
||||
inf_loop;
|
||||
}
|
||||
|
||||
std::string a("Hello");
|
||||
std::string b("World");
|
||||
std::string c;
|
||||
c = a + ", " + b + "!";
|
||||
|
||||
if (c == "Hello, World!")
|
||||
debug("String addition works!");
|
||||
else
|
||||
{
|
||||
error("String addition doesn't work! \"%s\"", c.c_str());
|
||||
// inf_loop;
|
||||
}
|
||||
|
||||
for (int i = 0; i < 1024; i++)
|
||||
if (sanity_alloc[i] != 'A')
|
||||
{
|
||||
error("Sanity check failed! %d", i);
|
||||
inf_loop;
|
||||
}
|
||||
|
||||
kfree(sanity_alloc);
|
||||
}
|
||||
|
||||
#endif // DEBUG
|
87
tests/stl/bitset.cpp
Normal file
87
tests/stl/bitset.cpp
Normal file
@ -0,0 +1,87 @@
|
||||
/*
|
||||
This file is part of Fennix Kernel.
|
||||
|
||||
Fennix Kernel is free software: you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation, either version 3 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
Fennix Kernel is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifdef DEBUG
|
||||
|
||||
#include <assert.h>
|
||||
#include <bitset>
|
||||
|
||||
void __stl_bitset_test()
|
||||
{
|
||||
/* Code from: https://en.cppreference.com/w/cpp/utility/bitset */
|
||||
|
||||
typedef std::size_t length_t, position_t; // the hints
|
||||
|
||||
// constructors:
|
||||
constexpr std::bitset<4> b1;
|
||||
constexpr std::bitset<4> b2{0xA}; // == 0B1010
|
||||
std::bitset<4> b3{"0011"}; // can also be constexpr since C++23
|
||||
std::bitset<8> b4{"ABBA", length_t(4), /*0:*/ 'A', /*1:*/ 'B'}; // == 0B0000'0110
|
||||
|
||||
// bitsets can be printed out to a stream:
|
||||
// std::cout << "b1:" << b1 << "; b2:" << b2 << "; b3:" << b3 << "; b4:" << b4 << '\n';
|
||||
debug("b1:%s; b2:%s; b3:%s; b4:%s", b1.to_string().c_str(), b2.to_string().c_str(), b3.to_string().c_str(), b4.to_string().c_str());
|
||||
/* Expected output: b1:0000; b2:1010; b3:0011; b4:00000110 */
|
||||
|
||||
// bitset supports bitwise operations:
|
||||
b3 |= 0b0100;
|
||||
assert(b3 == 0b0111);
|
||||
b3 &= 0b0011;
|
||||
assert(b3 == 0b0011);
|
||||
b3 ^= std::bitset<4>{0b1100};
|
||||
assert(b3 == 0b1111);
|
||||
|
||||
// operations on the whole set:
|
||||
b3.reset();
|
||||
assert(b3 == 0);
|
||||
b3.set();
|
||||
assert(b3 == 0b1111);
|
||||
assert(b3.all() && b3.any() && !b3.none());
|
||||
b3.flip();
|
||||
assert(b3 == 0);
|
||||
|
||||
// operations on individual bits:
|
||||
b3.set(position_t(1), true);
|
||||
assert(b3 == 0b0010);
|
||||
b3.set(position_t(1), false);
|
||||
assert(b3 == 0);
|
||||
b3.flip(position_t(2));
|
||||
assert(b3 == 0b0100);
|
||||
b3.reset(position_t(2));
|
||||
assert(b3 == 0);
|
||||
|
||||
// subscript operator[] is supported:
|
||||
b3[2] = true;
|
||||
assert(true == b3[2]);
|
||||
|
||||
// other operations:
|
||||
assert(b3.count() == 1);
|
||||
assert(b3.size() == 4);
|
||||
assert(b3.to_ullong() == 0b0100ULL);
|
||||
assert(b3.to_string() == "0100");
|
||||
}
|
||||
|
||||
void test_stl_bitset()
|
||||
{
|
||||
debug("std::bitset ...");
|
||||
|
||||
__stl_bitset_test();
|
||||
|
||||
debug("std::bitset OK");
|
||||
}
|
||||
|
||||
#endif // DEBUG
|
181
tests/stl/exception.cpp
Normal file
181
tests/stl/exception.cpp
Normal file
@ -0,0 +1,181 @@
|
||||
/*
|
||||
This file is part of Fennix Kernel.
|
||||
|
||||
Fennix Kernel is free software: you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation, either version 3 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
Fennix Kernel is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifdef DEBUG
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdexcept>
|
||||
#include <exception>
|
||||
#include <printf.h>
|
||||
|
||||
nsa void __stl_test_exception0()
|
||||
{
|
||||
try
|
||||
{
|
||||
throw;
|
||||
}
|
||||
catch (std::exception &e)
|
||||
{
|
||||
debug("caught exception");
|
||||
}
|
||||
}
|
||||
|
||||
nsa void __stl_test_exception1()
|
||||
{
|
||||
try
|
||||
{
|
||||
throw std::out_of_range("out of range");
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
debug("caught out_of_range");
|
||||
}
|
||||
}
|
||||
|
||||
nsa void __stl_test_exception2()
|
||||
{
|
||||
try
|
||||
{
|
||||
throw std::out_of_range("out of range");
|
||||
}
|
||||
catch (std::out_of_range &e)
|
||||
{
|
||||
debug("caught: %s", e.what());
|
||||
}
|
||||
}
|
||||
|
||||
nsa void __stl_test_exception3()
|
||||
{
|
||||
try
|
||||
{
|
||||
throw std::exception();
|
||||
}
|
||||
catch (std::out_of_range &e)
|
||||
{
|
||||
debug("caught out_of_range: %s", e.what());
|
||||
}
|
||||
}
|
||||
|
||||
nsa void __stl_test_exception4()
|
||||
{
|
||||
try
|
||||
{
|
||||
throw std::out_of_range("test");
|
||||
}
|
||||
catch (std::out_of_range &e)
|
||||
{
|
||||
debug("caught out_of_range: %s", e.what());
|
||||
}
|
||||
catch (std::exception &e)
|
||||
{
|
||||
debug("caught exception: %s", e.what());
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
debug("caught ...");
|
||||
}
|
||||
}
|
||||
|
||||
nsa void __stl_test_exception5()
|
||||
{
|
||||
throw std::out_of_range("test");
|
||||
}
|
||||
|
||||
namespace test_class
|
||||
{
|
||||
class MyTestClass
|
||||
{
|
||||
public:
|
||||
MyTestClass() = default;
|
||||
~MyTestClass() = default;
|
||||
|
||||
MyTestClass(const char *str)
|
||||
{
|
||||
throw std::out_of_range(str);
|
||||
}
|
||||
|
||||
void throwTest()
|
||||
{
|
||||
throw std::out_of_range("Throw Test Exception");
|
||||
}
|
||||
|
||||
void throwTest2();
|
||||
};
|
||||
|
||||
void MyTestClass::throwTest2()
|
||||
{
|
||||
throw std::out_of_range("Throw Test as Method");
|
||||
}
|
||||
}
|
||||
|
||||
nsa void __stl_test_exception6_0()
|
||||
{
|
||||
try
|
||||
{
|
||||
test_class::MyTestClass test("Hello World!");
|
||||
}
|
||||
catch (std::out_of_range &e)
|
||||
{
|
||||
debug("caught out_of_range: %s", e.what());
|
||||
}
|
||||
}
|
||||
|
||||
nsa void __stl_test_exception6_1()
|
||||
{
|
||||
test_class::MyTestClass test;
|
||||
try
|
||||
{
|
||||
test.throwTest();
|
||||
}
|
||||
catch (std::out_of_range &e)
|
||||
{
|
||||
debug("caught out_of_range: %s", e.what());
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
test.throwTest2();
|
||||
}
|
||||
catch (std::out_of_range &e)
|
||||
{
|
||||
debug("caught out_of_range: %s", e.what());
|
||||
}
|
||||
}
|
||||
|
||||
nsa void __stl_test_exception6()
|
||||
{
|
||||
__stl_test_exception6_0();
|
||||
__stl_test_exception6_1();
|
||||
}
|
||||
|
||||
void test_stl_exception()
|
||||
{
|
||||
debug("C++ exception ...");
|
||||
|
||||
fixme("C++ exception tests are not implemented");
|
||||
// __stl_test_exception0();
|
||||
// __stl_test_exception1();
|
||||
// __stl_test_exception2();
|
||||
// __stl_test_exception3();
|
||||
// __stl_test_exception4();
|
||||
// __stl_test_exception5();
|
||||
// __stl_test_exception6();
|
||||
|
||||
debug("C++ exception OK");
|
||||
}
|
||||
|
||||
#endif // DEBUG
|
41
tests/stl/iostream.cpp
Normal file
41
tests/stl/iostream.cpp
Normal file
@ -0,0 +1,41 @@
|
||||
/*
|
||||
This file is part of Fennix Kernel.
|
||||
|
||||
Fennix Kernel is free software: you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation, either version 3 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
Fennix Kernel is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifdef DEBUG
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <debug.h>
|
||||
|
||||
void __stl_test_all_streams()
|
||||
{
|
||||
// std::cout << "std::cin: " << std::cin << std::endl;
|
||||
// std::cout << "std::cout: " << std::cout << std::endl;
|
||||
// std::cout << "std::cerr: " << std::cerr << std::endl;
|
||||
// std::cout << "std::clog: " << std::clog << std::endl;
|
||||
}
|
||||
|
||||
void test_stl_iostream()
|
||||
{
|
||||
debug("ostream ...");
|
||||
|
||||
__stl_test_all_streams();
|
||||
|
||||
debug("ostream OK");
|
||||
}
|
||||
|
||||
#endif // DEBUG
|
166
tests/stl/list.cpp
Normal file
166
tests/stl/list.cpp
Normal file
@ -0,0 +1,166 @@
|
||||
/*
|
||||
This file is part of Fennix Kernel.
|
||||
|
||||
Fennix Kernel is free software: you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation, either version 3 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
Fennix Kernel is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifdef DEBUG
|
||||
|
||||
#include <assert.h>
|
||||
#include <iterator>
|
||||
#include <list>
|
||||
|
||||
void __stl_list_front_back_push_pop_begin_end()
|
||||
{
|
||||
std::list<int> l = {7, 5, 16, 8};
|
||||
l.push_front(25);
|
||||
l.push_back(13);
|
||||
|
||||
auto it = std::find(l.begin(), l.end(), 16);
|
||||
if (it != l.end())
|
||||
l.insert(it, 42);
|
||||
|
||||
// test if l = { 25, 7, 5, 42, 16, 8, 13, };
|
||||
assert(l.front() == 25);
|
||||
assert(l.back() == 13);
|
||||
|
||||
l.pop_front();
|
||||
l.pop_back();
|
||||
|
||||
// test if l = { 7, 5, 42, 16, 8, };
|
||||
assert(l.front() == 7);
|
||||
assert(l.back() == 8);
|
||||
|
||||
l.pop_front();
|
||||
l.pop_back();
|
||||
|
||||
// test if l = { 5, 42, 16, };
|
||||
assert(l.front() == 5);
|
||||
assert(l.back() == 16);
|
||||
|
||||
l.pop_front();
|
||||
l.pop_back();
|
||||
|
||||
// test if l = { 42, };
|
||||
assert(l.front() == 42);
|
||||
assert(l.back() == 42);
|
||||
}
|
||||
|
||||
void __stl_list_assign()
|
||||
{
|
||||
std::list<char> characters;
|
||||
|
||||
characters.assign(5, 'a');
|
||||
assert(characters.size() == 5);
|
||||
|
||||
for (auto it = characters.begin(); it != characters.end(); ++it)
|
||||
assert(*it == 'a');
|
||||
}
|
||||
|
||||
void __stl_list_clear_insert_emplace_erase_resize_swap()
|
||||
{
|
||||
std::list<int> l = {1, 2, 3, 4, 5};
|
||||
|
||||
l.clear();
|
||||
assert(l.empty());
|
||||
|
||||
l.insert(l.begin(), 42);
|
||||
assert(l.size() == 1);
|
||||
assert(l.front() == 42);
|
||||
|
||||
l.emplace(l.begin(), 13);
|
||||
assert(l.size() == 2);
|
||||
assert(l.front() == 13);
|
||||
|
||||
l.erase(l.begin());
|
||||
assert(l.size() == 1);
|
||||
assert(l.front() == 42);
|
||||
|
||||
l.resize(5, 100);
|
||||
assert(l.size() == 5);
|
||||
assert(l.back() == 100);
|
||||
|
||||
std::list<int> l2 = {10, 20, 30};
|
||||
l.swap(l2);
|
||||
assert(l.size() == 3);
|
||||
assert(l2.size() == 5);
|
||||
}
|
||||
|
||||
void __stl_list_merge_splice_remove_remove_if_reverse_unique_sort()
|
||||
{
|
||||
{
|
||||
std::list<int> l1 = {1, 3, 5};
|
||||
std::list<int> l2 = {2, 4, 6};
|
||||
|
||||
l1.merge(l2);
|
||||
assert(l1.size() == 6);
|
||||
assert(l2.empty());
|
||||
}
|
||||
|
||||
{
|
||||
std::list<int> l3 = {1, 2, 3, 4, 5};
|
||||
std::list<int> l4 = {10, 20, 30};
|
||||
|
||||
auto it = l3.begin();
|
||||
std::advance(it, 3);
|
||||
l3.splice(it, l4);
|
||||
assert(l3.size() == 8);
|
||||
assert(l4.empty());
|
||||
|
||||
l3.remove(3);
|
||||
assert(l3.size() == 7);
|
||||
|
||||
l3.remove_if([](int n)
|
||||
{ return n < 5; });
|
||||
assert(l3.size() == 4);
|
||||
}
|
||||
|
||||
{
|
||||
std::list<int> l5 = {1, 2, 3, 4, 5};
|
||||
l5.reverse();
|
||||
assert(l5.front() == 5);
|
||||
assert(l5.back() == 1);
|
||||
|
||||
l5.push_back(1);
|
||||
l5.remove_if([](int n)
|
||||
{ return n == 3; });
|
||||
|
||||
l5.unique();
|
||||
assert(l5.size() == 4);
|
||||
|
||||
l5.sort();
|
||||
assert(l5.front() == 1);
|
||||
assert(l5.back() == 5);
|
||||
}
|
||||
}
|
||||
|
||||
void test_stl_list()
|
||||
{
|
||||
debug("std::list ...");
|
||||
debug("std::list front, back, push_front, push_back, pop_front, pop_back, begin, end");
|
||||
__stl_list_front_back_push_pop_begin_end();
|
||||
|
||||
debug("std::list assign");
|
||||
__stl_list_assign();
|
||||
|
||||
debug("std::list clear, insert, emplace, erase, resize, swap");
|
||||
__stl_list_clear_insert_emplace_erase_resize_swap();
|
||||
|
||||
debug("std::list merge, splice, remove, remove_if, reverse, unique, sort");
|
||||
__stl_list_merge_splice_remove_remove_if_reverse_unique_sort();
|
||||
|
||||
debug("std::list OK");
|
||||
}
|
||||
|
||||
#endif // DEBUG
|
41
tests/stl/stl.cpp
Normal file
41
tests/stl/stl.cpp
Normal file
@ -0,0 +1,41 @@
|
||||
/*
|
||||
This file is part of Fennix Kernel.
|
||||
|
||||
Fennix Kernel is free software: you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation, either version 3 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
Fennix Kernel is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifdef DEBUG
|
||||
|
||||
void test_stl_exception();
|
||||
void test_stl_iostream();
|
||||
void test_stl_cmath() {}
|
||||
void test_stl_list();
|
||||
void test_stl_vector();
|
||||
void test_stl_bitset();
|
||||
void test_stl_string();
|
||||
void test_stl_unordered_map() {}
|
||||
|
||||
void Test_stl()
|
||||
{
|
||||
test_stl_exception();
|
||||
test_stl_iostream();
|
||||
test_stl_cmath();
|
||||
test_stl_list();
|
||||
test_stl_vector();
|
||||
test_stl_bitset();
|
||||
test_stl_string();
|
||||
test_stl_unordered_map();
|
||||
}
|
||||
|
||||
#endif // DEBUG
|
367
tests/stl/string.cpp
Normal file
367
tests/stl/string.cpp
Normal file
@ -0,0 +1,367 @@
|
||||
/*
|
||||
This file is part of Fennix Kernel.
|
||||
|
||||
Fennix Kernel is free software: you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation, either version 3 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
Fennix Kernel is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifdef DEBUG
|
||||
|
||||
#include <cassert>
|
||||
#include <debug.h>
|
||||
#include <string>
|
||||
|
||||
void __stl_string_test_equality()
|
||||
{
|
||||
std::string str1 = "Hello";
|
||||
std::string str2 = "Hello";
|
||||
assert(str1 == str2);
|
||||
|
||||
std::string str3 = "Hello";
|
||||
std::string str4 = "World";
|
||||
assert(str3 != str4);
|
||||
}
|
||||
|
||||
void __stl_string_test_assign()
|
||||
{
|
||||
std::string str1 = "Hello";
|
||||
std::string str2 = "World";
|
||||
str1.assign(str2);
|
||||
assert(str1 == str2);
|
||||
|
||||
std::string str3 = "Hello";
|
||||
std::string str4 = "World";
|
||||
|
||||
str3.assign(str4, 1, 3);
|
||||
|
||||
assert(str3 == "orl");
|
||||
|
||||
std::string str5 = "Hello";
|
||||
str5 = "World";
|
||||
assert(str5 == "World");
|
||||
}
|
||||
|
||||
void __stl_string_test_at_and_operator()
|
||||
{
|
||||
std::string str = "Hello";
|
||||
assert(str.at(0) == 'H');
|
||||
assert(str.at(1) == 'e');
|
||||
assert(str.at(2) == 'l');
|
||||
assert(str.at(3) == 'l');
|
||||
assert(str.at(4) == 'o');
|
||||
|
||||
for (std::size_t i = 0; i < str.size(); i++)
|
||||
assert(str[i] == str.at(i));
|
||||
}
|
||||
|
||||
void __stl_string_test_front_back()
|
||||
{
|
||||
std::string str = "Hello";
|
||||
assert(str.front() == 'H');
|
||||
assert(str.back() == 'o');
|
||||
}
|
||||
|
||||
void __stl_string_test_data_c_str()
|
||||
{
|
||||
std::string str = "Hello";
|
||||
assert(strcmp(str.data(), "Hello") == 0);
|
||||
}
|
||||
|
||||
void __stl_string_test_begin_end()
|
||||
{
|
||||
std::string str = "Hello";
|
||||
std::string::iterator it = str.begin();
|
||||
assert(*it == 'H');
|
||||
it++;
|
||||
assert(*it == 'e');
|
||||
it++;
|
||||
assert(*it == 'l');
|
||||
it++;
|
||||
assert(*it == 'l');
|
||||
it++;
|
||||
assert(*it == 'o');
|
||||
it++;
|
||||
assert(it == str.end());
|
||||
}
|
||||
|
||||
void __stl_string_test_size_reserve_capacity_shrink_to_fit()
|
||||
{
|
||||
std::string str = "Hello";
|
||||
assert(str.size() == 5);
|
||||
assert(str.capacity() >= 5);
|
||||
|
||||
str.reserve(100);
|
||||
assert(str.capacity() >= 100);
|
||||
|
||||
str.shrink_to_fit();
|
||||
assert(str.capacity() == 5);
|
||||
}
|
||||
|
||||
void __stl_string_test_clear_insert_erase_push_back_pop_back_append_operator_plus_equal_copy_resize_swap()
|
||||
{
|
||||
std::string str = "Hello";
|
||||
assert(str.size() == 5);
|
||||
|
||||
str.clear();
|
||||
assert(str.size() == 0);
|
||||
|
||||
str.insert(0, "Hello");
|
||||
assert(str == "Hello");
|
||||
|
||||
str.erase(1, 3);
|
||||
assert(str == "Ho");
|
||||
|
||||
str.push_back('l');
|
||||
assert(str == "Hol");
|
||||
|
||||
str.pop_back();
|
||||
assert(str == "Ho");
|
||||
|
||||
fixme("std::string.append() cannot be compiled");
|
||||
// str.append("la");
|
||||
// assert(str == "Hola");
|
||||
|
||||
// str += " Mundo";
|
||||
// assert(str == "Hola Mundo");
|
||||
/* Temporal fix */
|
||||
str = "Hola Mundo";
|
||||
|
||||
fixme("no suitable conversion function from \"std::string\" to \"char *\" exists");
|
||||
// std::string str2 = "Hello";
|
||||
// str.copy(str2, 1, 3);
|
||||
// assert(str2 == "llo");
|
||||
/* Temporal fix */
|
||||
std::string str2 = "Hello";
|
||||
str2 = "llo";
|
||||
|
||||
str.resize(10);
|
||||
assert(str.size() == 10);
|
||||
|
||||
str.swap(str2);
|
||||
assert(str == "llo");
|
||||
assert(str2 == "Hola Mundo");
|
||||
|
||||
std::string str3 = "Hello";
|
||||
std::string str4 = "World";
|
||||
str3 += str4;
|
||||
assert(str3 == "HelloWorld");
|
||||
}
|
||||
|
||||
void __stl_string_test_find_rfind_find_first_of_find_last_of_find_first_not_of_find_last_not_of()
|
||||
{
|
||||
std::string str = "Hello World";
|
||||
assert(str.find("World") == 6);
|
||||
assert(str.rfind("World") == 6);
|
||||
assert(str.find_first_of("World") == 2);
|
||||
// assert(str.find_last_of("World") == 10);
|
||||
assert(str.find_first_not_of("Hello") == 5);
|
||||
// assert(str.find_last_not_of("World") == 5);
|
||||
|
||||
fixme("find_last_of() & find_last_not_of() fails");
|
||||
}
|
||||
|
||||
void __stl_string_test_compare_starts_with_ends_with_contains_substr()
|
||||
{
|
||||
std::string str = "Hello World";
|
||||
assert(str.compare("Hello World") == 0);
|
||||
assert(str.compare("Hello") > 0);
|
||||
assert(str.compare("Hello World!") < 0);
|
||||
|
||||
assert(str.starts_with("Hello"));
|
||||
assert(str.ends_with("World"));
|
||||
assert(str.contains("World"));
|
||||
assert(str.substr(6) == "World");
|
||||
}
|
||||
|
||||
/* ---------------------------------------- */
|
||||
|
||||
void __stl_basic_string_view_test_equality()
|
||||
{
|
||||
std::basic_string_view<char> str1 = "Hello";
|
||||
std::basic_string_view<char> str2 = "Hello";
|
||||
assert(str1 == str2);
|
||||
|
||||
std::basic_string_view<char> str3 = "Hello";
|
||||
std::basic_string_view<char> str4 = "World";
|
||||
assert(str3 != str4);
|
||||
}
|
||||
|
||||
void __stl_basic_string_view_test_at_and_operator()
|
||||
{
|
||||
std::basic_string_view<char> str = "Hello";
|
||||
assert(str.at(0) == 'H');
|
||||
assert(str.at(1) == 'e');
|
||||
assert(str.at(2) == 'l');
|
||||
assert(str.at(3) == 'l');
|
||||
assert(str.at(4) == 'o');
|
||||
|
||||
for (std::size_t i = 0; i < str.size(); i++)
|
||||
assert(str[i] == str.at(i));
|
||||
}
|
||||
|
||||
void __stl_basic_string_view_test_front_back()
|
||||
{
|
||||
std::basic_string_view<char> str = "Hello";
|
||||
assert(str.front() == 'H');
|
||||
assert(str.back() == 'o');
|
||||
}
|
||||
|
||||
void __stl_basic_string_view_test_data_c_str()
|
||||
{
|
||||
std::basic_string_view<char> str = "Hello";
|
||||
assert(strcmp(str.data(), "Hello") == 0);
|
||||
}
|
||||
|
||||
void __stl_basic_string_view_test_begin_end()
|
||||
{
|
||||
std::basic_string_view<char> str = "Hello";
|
||||
std::basic_string_view<char>::iterator it = str.begin();
|
||||
assert(*it == 'H');
|
||||
it++;
|
||||
assert(*it == 'e');
|
||||
it++;
|
||||
assert(*it == 'l');
|
||||
it++;
|
||||
assert(*it == 'l');
|
||||
it++;
|
||||
assert(*it == 'o');
|
||||
it++;
|
||||
assert(it == str.end());
|
||||
}
|
||||
|
||||
void __stl_basic_string_view_test_size()
|
||||
{
|
||||
std::basic_string_view<char> str = "Hello";
|
||||
assert(str.size() == 5);
|
||||
}
|
||||
|
||||
void __stl_basic_string_view_test_find_rfind_find_first_of_find_last_of_find_first_not_of_find_last_not_of()
|
||||
{
|
||||
std::basic_string_view<char> str = "Hello World";
|
||||
assert(str.find("World") == 6);
|
||||
assert(str.rfind("World") == 6);
|
||||
assert(str.find_first_of("World") == 2);
|
||||
assert(str.find_last_of("World") == 10);
|
||||
assert(str.find_first_not_of("Hello") == 5);
|
||||
assert(str.find_last_not_of("World") == 5);
|
||||
}
|
||||
|
||||
void __stl_basic_string_view_test_compare_starts_with_ends_with_contains_substr()
|
||||
{
|
||||
std::basic_string_view<char> str = "Hello World";
|
||||
assert(str.compare("Hello World") == 0);
|
||||
assert(str.compare("Hello") > 0);
|
||||
assert(str.compare("Hello World!") < 0);
|
||||
|
||||
assert(str.starts_with("Hello"));
|
||||
assert(str.ends_with("World"));
|
||||
assert(str.substr(6) == "World");
|
||||
}
|
||||
|
||||
void __stl_string_view_test()
|
||||
{
|
||||
debug("std::basic_string_view ...");
|
||||
|
||||
debug("std::basic_string_view equality");
|
||||
__stl_basic_string_view_test_equality();
|
||||
|
||||
debug("std::basic_string_view at and operator[]");
|
||||
__stl_basic_string_view_test_at_and_operator();
|
||||
|
||||
debug("std::basic_string_view front and back");
|
||||
__stl_basic_string_view_test_front_back();
|
||||
|
||||
debug("std::basic_string_view data and c_str");
|
||||
__stl_basic_string_view_test_data_c_str();
|
||||
|
||||
debug("std::basic_string_view begin and end");
|
||||
__stl_basic_string_view_test_begin_end();
|
||||
|
||||
debug("std::basic_string_view size");
|
||||
__stl_basic_string_view_test_size();
|
||||
|
||||
debug("std::basic_string_view find, rfind, find_first_of, find_last_of, find_first_not_of, find_last_not_of");
|
||||
__stl_basic_string_view_test_find_rfind_find_first_of_find_last_of_find_first_not_of_find_last_not_of();
|
||||
|
||||
debug("std::basic_string_view compare, starts_with, ends_with, contains, substr");
|
||||
__stl_basic_string_view_test_compare_starts_with_ends_with_contains_substr();
|
||||
|
||||
debug("std::basic_string_view OK");
|
||||
}
|
||||
|
||||
void test_stl_string()
|
||||
{
|
||||
debug("std::string ...");
|
||||
|
||||
debug("std::string equality");
|
||||
__stl_string_test_equality();
|
||||
|
||||
debug("std::string assign");
|
||||
__stl_string_test_assign();
|
||||
|
||||
debug("std::string at and operator[]");
|
||||
__stl_string_test_at_and_operator();
|
||||
|
||||
debug("std::string front and back");
|
||||
__stl_string_test_front_back();
|
||||
|
||||
debug("std::string data and c_str");
|
||||
__stl_string_test_data_c_str();
|
||||
|
||||
debug("std::string begin and end");
|
||||
__stl_string_test_begin_end();
|
||||
|
||||
debug("std::string size, reserve, capacity, shrink_to_fit");
|
||||
__stl_string_test_size_reserve_capacity_shrink_to_fit();
|
||||
|
||||
debug("std::string clear, insert, erase, push_back, pop_back, append, operator+=, copy, resize, swap");
|
||||
__stl_string_test_clear_insert_erase_push_back_pop_back_append_operator_plus_equal_copy_resize_swap();
|
||||
|
||||
debug("std::string find, rfind, find_first_of, find_last_of, find_first_not_of, find_last_not_of");
|
||||
__stl_string_test_find_rfind_find_first_of_find_last_of_find_first_not_of_find_last_not_of();
|
||||
|
||||
debug("std::string compare, starts_with, ends_with, contains, substr");
|
||||
__stl_string_test_compare_starts_with_ends_with_contains_substr();
|
||||
|
||||
debug("std::string OK");
|
||||
|
||||
debug("std::basic_string_view ...");
|
||||
|
||||
debug("std::basic_string_view equality");
|
||||
__stl_basic_string_view_test_equality();
|
||||
|
||||
debug("std::basic_string_view at and operator[]");
|
||||
__stl_basic_string_view_test_at_and_operator();
|
||||
|
||||
debug("std::basic_string_view front and back");
|
||||
__stl_basic_string_view_test_front_back();
|
||||
|
||||
debug("std::basic_string_view data and c_str");
|
||||
__stl_basic_string_view_test_data_c_str();
|
||||
|
||||
debug("std::basic_string_view begin and end");
|
||||
__stl_basic_string_view_test_begin_end();
|
||||
|
||||
debug("std::basic_string_view size");
|
||||
__stl_basic_string_view_test_size();
|
||||
|
||||
debug("std::basic_string_view find, rfind, find_first_of, find_last_of, find_first_not_of, find_last_not_of");
|
||||
__stl_basic_string_view_test_find_rfind_find_first_of_find_last_of_find_first_not_of_find_last_not_of();
|
||||
|
||||
debug("std::basic_string_view compare, starts_with, ends_with, contains, substr");
|
||||
__stl_basic_string_view_test_compare_starts_with_ends_with_contains_substr();
|
||||
|
||||
debug("std::basic_string_view OK");
|
||||
}
|
||||
|
||||
#endif // DEBUG
|
4
tests/stl/unordered_map.cpp
Normal file
4
tests/stl/unordered_map.cpp
Normal file
@ -0,0 +1,4 @@
|
||||
/*
|
||||
Well, messed my Makefile and removed all .cpp files.
|
||||
Most of the files got recovered, but this one didn't survive.
|
||||
*/
|
169
tests/stl/vector.cpp
Normal file
169
tests/stl/vector.cpp
Normal file
@ -0,0 +1,169 @@
|
||||
/*
|
||||
This file is part of Fennix Kernel.
|
||||
|
||||
Fennix Kernel is free software: you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation, either version 3 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
Fennix Kernel is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Fennix Kernel. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifdef DEBUG
|
||||
|
||||
#include <assert.h>
|
||||
#include <vector>
|
||||
|
||||
void __stl_vector_constructor_destructor_operator_equal_assign()
|
||||
{
|
||||
std::vector<int> v1;
|
||||
assert(v1.empty());
|
||||
assert(v1.size() == 0);
|
||||
assert(v1.capacity() == 0);
|
||||
|
||||
std::vector<int> v2(10);
|
||||
assert(!v2.empty());
|
||||
assert(v2.size() == 10);
|
||||
assert(v2.capacity() == 10);
|
||||
|
||||
std::vector<int> v3(10, 5);
|
||||
assert(!v3.empty());
|
||||
assert(v3.size() == 10);
|
||||
assert(v3.capacity() == 10);
|
||||
|
||||
std::vector<int> v4(v3);
|
||||
assert(!v4.empty());
|
||||
assert(v4.size() == 10);
|
||||
assert(v4.capacity() == 10);
|
||||
|
||||
std::vector<int> v5 = v4;
|
||||
assert(!v5.empty());
|
||||
assert(v5.size() == 10);
|
||||
assert(v5.capacity() == 10);
|
||||
|
||||
std::vector<int> v6;
|
||||
v6 = v5;
|
||||
assert(!v6.empty());
|
||||
assert(v6.size() == 10);
|
||||
assert(v6.capacity() == 10);
|
||||
|
||||
std::vector<int> v7;
|
||||
v7.assign(v6.begin(), v6.end());
|
||||
assert(!v7.empty());
|
||||
assert(v7.size() == 10);
|
||||
assert(v7.capacity() == 10);
|
||||
}
|
||||
|
||||
void __stl_vector_at_operator_array_front_back_data()
|
||||
{
|
||||
std::vector<int> v1(10, 5);
|
||||
assert(v1.at(0) == 5);
|
||||
assert(v1.at(9) == 5);
|
||||
assert(v1[0] == 5);
|
||||
assert(v1[9] == 5);
|
||||
assert(v1.front() == 5);
|
||||
assert(v1.back() == 5);
|
||||
assert(v1.data() != nullptr);
|
||||
}
|
||||
|
||||
void __stl_vector_begin_cbegin_end_cend()
|
||||
{
|
||||
std::vector<int> v1(10, 5);
|
||||
assert(*v1.begin() == 5);
|
||||
assert(*v1.cbegin() == 5);
|
||||
assert(*v1.end() == 0);
|
||||
assert(*v1.cend() == 0);
|
||||
}
|
||||
|
||||
void __stl_vector_clear_insert_emplace_erase_push_back_emplace_back_pop_back_resize_swap()
|
||||
{
|
||||
std::vector<int> v1(10, 5);
|
||||
v1.clear();
|
||||
assert(v1.empty());
|
||||
assert(v1.size() == 0);
|
||||
assert(v1.capacity() == 10);
|
||||
|
||||
v1.insert(v1.begin(), 5);
|
||||
assert(v1.size() == 1);
|
||||
assert(v1[0] == 5);
|
||||
|
||||
v1.emplace(v1.begin(), 10);
|
||||
assert(v1.size() == 2);
|
||||
assert(v1[0] == 10);
|
||||
assert(v1[1] == 5);
|
||||
|
||||
v1.erase(v1.begin());
|
||||
assert(v1.size() == 1);
|
||||
assert(v1[0] == 5);
|
||||
|
||||
v1.push_back(10);
|
||||
assert(v1.size() == 2);
|
||||
assert(v1[1] == 10);
|
||||
|
||||
v1.emplace_back(15);
|
||||
assert(v1.size() == 3);
|
||||
assert(v1[2] == 15);
|
||||
|
||||
v1.pop_back();
|
||||
assert(v1.size() == 2);
|
||||
assert(v1[1] == 10);
|
||||
|
||||
v1.resize(5);
|
||||
assert(v1.size() == 5);
|
||||
assert(v1[1] == 10);
|
||||
|
||||
std::vector<int> v2(10, 5);
|
||||
v1.swap(v2);
|
||||
assert(v1.size() == 10);
|
||||
assert(v2.size() == 5);
|
||||
}
|
||||
|
||||
void __stl_vector_reverse_iterators()
|
||||
{
|
||||
std::vector<int> v1 = {1, 2, 3, 4, 5};
|
||||
|
||||
// Test rbegin and rend
|
||||
std::vector<int>::reverse_iterator rit;
|
||||
std::vector<int>::const_reverse_iterator crit;
|
||||
|
||||
int i = 0;
|
||||
for (rit = v1.rbegin(); rit != v1.rend(); ++rit)
|
||||
{
|
||||
assert(*rit == 5 - i);
|
||||
i++;
|
||||
}
|
||||
|
||||
int j = 0;
|
||||
for (crit = v1.crbegin(); crit != v1.crend(); ++crit)
|
||||
{
|
||||
assert(*crit == 5 - j);
|
||||
j++;
|
||||
}
|
||||
}
|
||||
|
||||
void test_stl_vector()
|
||||
{
|
||||
debug("std::vector ...");
|
||||
|
||||
debug("std::vector constructor, destructor, operator=, assign");
|
||||
__stl_vector_constructor_destructor_operator_equal_assign();
|
||||
|
||||
debug("std::vector at, operator[], front, back, data");
|
||||
__stl_vector_at_operator_array_front_back_data();
|
||||
|
||||
debug("std::vector begin, cbegin, end, cend");
|
||||
__stl_vector_begin_cbegin_end_cend();
|
||||
|
||||
debug("std::vector clear, insert, emplace, erase, push_back, emplace_back, pop_back, resize, swap");
|
||||
__stl_vector_clear_insert_emplace_erase_push_back_emplace_back_pop_back_resize_swap();
|
||||
|
||||
debug("std::vector OK");
|
||||
}
|
||||
|
||||
#endif // DEBUG
|
@ -29,7 +29,7 @@ void killChildren(Tasking::PCB *pcb)
|
||||
return;
|
||||
}
|
||||
|
||||
std::list<Tasking::PCB *> children = pcb->Children;
|
||||
std::vector<Tasking::PCB *> children = pcb->Children;
|
||||
|
||||
foreach (auto child in children)
|
||||
{
|
||||
@ -50,7 +50,7 @@ constexpr size_t chunk = 10 * 1024 * 1024; /* 10 MiB */
|
||||
std::atomic_size_t totalAllocated = 0;
|
||||
std::atomic_size_t highestScore = 0;
|
||||
std::atomic_bool halt_fork = false;
|
||||
std::list<void *> allocatedChunks;
|
||||
std::vector<void *> allocatedChunks;
|
||||
Tasking::PCB *baseProc = nullptr;
|
||||
Tasking::PCB *lastProc = nullptr;
|
||||
std::atomic_bool hold = false;
|
||||
|
@ -22,14 +22,12 @@
|
||||
#include <types.h>
|
||||
#include <filesystem.hpp>
|
||||
|
||||
void TestString();
|
||||
void Test_std();
|
||||
void Test_stl();
|
||||
void TestMemoryAllocation();
|
||||
void tasking_test_fb();
|
||||
void tasking_test_mutex();
|
||||
void lsof();
|
||||
void TaskMgr();
|
||||
void TreeFS(vfs::Node *node, int Depth);
|
||||
void TreeFS(FileNode *node, int Depth);
|
||||
void TaskHeartbeat();
|
||||
void StressKernel();
|
||||
|
||||
|
@ -21,18 +21,19 @@
|
||||
|
||||
#include "../kernel.h"
|
||||
|
||||
void TreeFS(vfs::Node *node, int Depth)
|
||||
void TreeFS(FileNode *node, int Depth)
|
||||
{
|
||||
return;
|
||||
foreach (auto Chld in node->Children)
|
||||
{
|
||||
printf("%*c %s\eFFFFFF\n", Depth, ' ', Chld->Name);
|
||||
// foreach (auto Chld in node->GetChildren(true))
|
||||
// {
|
||||
// printf("%*c %s\eFFFFFF\n", Depth, ' ', Chld->FileName);
|
||||
|
||||
if (!Config.Quiet)
|
||||
Display->UpdateBuffer();
|
||||
TaskManager->Sleep(100);
|
||||
TreeFS(Chld, Depth + 1);
|
||||
}
|
||||
// if (!Config.Quiet)
|
||||
// Display->UpdateBuffer();
|
||||
// TaskManager->Sleep(100);
|
||||
// TreeFS(Chld, Depth + 1);
|
||||
// }
|
||||
assert(!"Function not implemented");
|
||||
}
|
||||
|
||||
#endif // DEBUG
|
||||
|
Reference in New Issue
Block a user