Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions api/fs/fat.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ namespace fs
return "Invalid fat type";
}

bool is_valid() const noexcept override { return initialized_; };

uint64_t block_size() const noexcept override
{ return device.block_size(); }
/// ----------------------------------------------------- ///
Expand Down Expand Up @@ -111,6 +113,8 @@ namespace fs

// initialize filesystem by providing base sector
void init(const void* base_sector);
bool initialized_{false};

// return a list of entries from directory entries at @sector
typedef delegate<void(error_t, Dirvec_ptr)> on_internal_ls_func;
void int_ls(uint32_t sector, Dirvec_ptr, on_internal_ls_func) const;
Expand Down
3 changes: 3 additions & 0 deletions api/fs/filesystem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ namespace fs {
/** Returns the name of this filesystem */
virtual std::string name() const = 0;

/** Tells us is the filesystem is ok */
virtual bool is_valid() const noexcept { return false; };

/** Returns the block size of this filesystem */
virtual uint64_t block_size() const = 0;

Expand Down
2 changes: 1 addition & 1 deletion api/hal/detail/machine.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ namespace os::detail {
}

template <typename T>
void remove(int i) {
void remove(size_t i) {
auto& vec = get_vector<T>();
if(UNLIKELY(vec.size() < i))
throw Machine_access_error{"Requested machine part not found: " + std::to_string(i)};
Expand Down
19 changes: 19 additions & 0 deletions api/net/addr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,19 @@ union Addr {
bool operator<=(const Addr& other) const noexcept
{ return (*this < other or *this == other); }


bool operator==(const net::ip4::Addr& other) const noexcept
{ return ip4_.addr == other; }

bool operator!=(const net::ip4::Addr& other) const noexcept
{ return ip4_.addr != other; }

bool operator==(const net::ip6::Addr& other) const noexcept
{ return ip6_ == other; }

bool operator!=(const net::ip6::Addr& other) const noexcept
{ return ip6_ != other; }

private:
struct {
uint64_t big;
Expand All @@ -135,4 +148,10 @@ union Addr {

static_assert(sizeof(Addr) == sizeof(ip6::Addr));

inline bool operator==(const ip4::Addr& lhs, const Addr& rhs) noexcept { return rhs == lhs; }
inline bool operator!=(const ip4::Addr& lhs, const Addr& rhs) noexcept { return !(lhs == rhs); }

inline bool operator==(const ip6::Addr& lhs, const Addr& rhs) noexcept { return rhs == lhs; }
inline bool operator!=(const ip6::Addr& lhs, const Addr& rhs) noexcept { return !(lhs == rhs); }

}
30 changes: 30 additions & 0 deletions api/net/inet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -535,4 +535,34 @@ namespace net {
};
}

namespace net::ip4 {
inline bool operator==(const net::ip4::Addr& lhs, const net::Inet& rhs) noexcept {
return lhs == rhs.ip_addr();
}
inline bool operator==(const net::Inet& lhs, const net::ip4::Addr& rhs) noexcept {
return lhs.ip_addr() == rhs;
}
inline bool operator!=(const net::ip4::Addr& lhs, const net::Inet& rhs) noexcept {
return !(lhs == rhs);
}
inline bool operator!=(const net::Inet& lhs, const net::ip4::Addr& rhs) noexcept {
return !(lhs == rhs);
}
} // namespace net::ip4

namespace net::ip6 {
inline bool operator==(const net::ip6::Addr& lhs, const net::Inet& rhs) noexcept {
return lhs == rhs.ip6_addr();
}
inline bool operator==(const net::Inet& lhs, const net::ip6::Addr& rhs) noexcept {
return lhs.ip6_addr() == rhs;
}
inline bool operator!=(const net::ip6::Addr& lhs, const net::Inet& rhs) noexcept {
return !(lhs == rhs);
}
inline bool operator!=(const net::Inet& lhs, const net::ip6::Addr& rhs) noexcept {
return !(lhs == rhs);
}
} // namespace net::ip6

#endif
3 changes: 2 additions & 1 deletion api/net/router.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,9 @@ namespace net {
bytes_fwd{Statman::get().get_or_create(Stat::UINT64, "router.bytes_fwd").get_uint64()}
{
INFO("Router", "Router created with %lu routes", tbl.size());
for(auto& route : routing_table_)
for([[maybe_unused]] auto& route : routing_table_) {
INFO2("%s", route.to_string().c_str());
}
}

void set_routing_table(Routing_table tbl) {
Expand Down
4 changes: 2 additions & 2 deletions api/util/statman.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class Stat {
void make_counter() noexcept { m_bits &= ~GAUGE_BIT; }
void make_gauge() noexcept { m_bits |= GAUGE_BIT; }

const char* name() const noexcept { return name_; }
const std::string name() const noexcept { return name_; }
bool unused() const noexcept { return name_[0] == 0; }

const float& get_float() const;
Expand Down Expand Up @@ -116,7 +116,7 @@ class Statman {
// retrieve stat based on address from stats counter: &stat.get_xxx()
Stat& get(const Stat* addr);
// if you know the name of a statistic already
Stat& get_by_name(const char* name);
Stat& get_by_name(std::string_view name);
// retrieve stat or create if it doesnt exists
Stat& get_or_create(const Stat::Stat_type type, const std::string& name);
// free/delete stat based on address from stats counter
Expand Down
4 changes: 2 additions & 2 deletions deps/lest/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
}:
stdenv.mkDerivation rec {
pname = "lest";
version = "1.36.0";
version = "1.37.0";

meta = {
description = "A tiny C++11 test framework – lest errors escape testing.";
Expand All @@ -15,7 +15,7 @@ stdenv.mkDerivation rec {
src = fetchGit {
url = "https://github.com/martinmoene/lest.git";
ref = "refs/tags/v${version}";
rev = "57197f32f2c7d3f3d3664a9010d3ff181a40f6ca";
rev = "fe1996f438ab8d1611c0324a156f9130ed971e9f";
};

cmakeBuildType = "Debug";
Expand Down
1 change: 1 addition & 0 deletions src/fs/fat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ namespace fs
this->lba_base, this->lba_size, this->lba_size * 512);

// on_init callback
initialized_ = true;
on_init(no_error, *this);
})
);
Expand Down
6 changes: 3 additions & 3 deletions src/util/statman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,15 +111,15 @@ Stat& Statman::get(const Stat* st)
throw std::out_of_range("Not a valid stat in this statman instance");
}

Stat& Statman::get_by_name(const char* name)
Stat& Statman::get_by_name(const std::string_view name)
{
#ifdef INCLUDEOS_SMP_ENABLE
std::lock_guard<Spinlock> lock(this->stlock);
#endif
for (auto& stat : this->m_stats)
{
if (stat.unused() == false) {
if (strncmp(stat.name(), name, Stat::MAX_NAME_LEN) == 0)
if (stat.name() == name)
return stat;
}
}
Expand All @@ -129,7 +129,7 @@ Stat& Statman::get_by_name(const char* name)
Stat& Statman::get_or_create(const Stat::Stat_type type, const std::string& name)
{
try {
auto& stat = get_by_name(name.c_str());
auto& stat = get_by_name(name);
if(type == stat.type())
return stat;
}
Expand Down
2 changes: 1 addition & 1 deletion test/integration/kernel/exception/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def is_good(line):
if (counter == expected):
vm.exit(0, "All tests passed")

vm.on_output("\\x15\\x07\\t\*\*\*\* PANIC \*\*\*\*", is_good)
vm.on_output("\\x15\\x07\\t\\*\\*\\*\\* PANIC \\*\\*\\*\\*", is_good)
vm.on_output("Divide-by-zero Error", is_good)

vm.on_output("__cpu_exception", is_good)
Expand Down
2 changes: 1 addition & 1 deletion test/integration/kernel/smp/service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void Service::start()
printf("CPU %i active \n", i);
SMP::global_unlock();

SMP::add_task([i]{
SMP::add_task([]{
// NOTE: We can't call printf here as it's not SMP safe

// Test regular malloc
Expand Down
2 changes: 2 additions & 0 deletions test/integration/memory/paging/service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -414,13 +414,15 @@ int main()
auto pml3 = __pml4->page_dir(__pml4->entry(magic_loc));
auto pml2 = pml3->page_dir(pml3->entry(magic_loc));
auto pml1 = pml2->page_dir(pml2->entry(magic_loc));
(void) pml1;

// Write-protect
if (magic->reboots == 0) {

pml3 = __pml4->page_dir(__pml4->entry(mapped.lin));
pml2 = pml3->page_dir(pml3->entry(mapped.lin));
pml1 = pml2->page_dir(pml2->entry(mapped.lin));
(void) pml1;

protected_page[magic->i] = 'a';
mem::protect_range((uint64_t)protected_page, mem::Access::read);
Expand Down
2 changes: 1 addition & 1 deletion test/integration/net/dns/service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ void Service::start()
[] (net::Inet& inet)
{
const ip4::Addr level3{4, 2, 2, 1};
const ip4::Addr google{8, 8, 8, 8};
//const ip4::Addr google{8, 8, 8, 8};

static std::vector<Name_request> requests {
// Having these here fails the test in some cases. A timing issue or a bug?
Expand Down
2 changes: 1 addition & 1 deletion test/misc/lest_util/nic_mock.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class Nic_mock : public hw::Nic {
transmit_to_physical_(std::move(pkt));
}

void transmit(net::Packet_ptr pkt)
void transmit(net::Packet_ptr pkt) // FIXME: this function is logging but not doing anything
{
NIC_INFO("transimtting packet");
//tx_queue_.emplace_back(std::move(ptr));
Expand Down
5 changes: 5 additions & 0 deletions test/unit/fs/unit_fat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ CASE("Initialize FAT fs")
[&lest_env] (auto err, File_system& fs)
{
EXPECT(!err);
EXPECT(fs.is_valid() == true);

// EXPECT(fs.name() == "FAT32"); // FIXME: test fails
Dirent dirent = fs.stat("/");
EXPECT(dirent.is_valid() == true);
});
}

Expand Down
9 changes: 5 additions & 4 deletions test/unit/fs/unit_fs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,19 @@

using namespace fs;

CASE("Initialize mock FS")
CASE("Initialize invalid FS")
{
fs::MemDisk memdisk {0, 0};
fs::Disk disk { memdisk };

EXPECT(disk.empty());
EXPECT(disk.device_id() >= 0);
EXPECT(disk.name().size() > 1); // name0
disk.init_fs(
[&] (fs::error_t error, fs::File_system& fs)
{
EXPECT(error != fs::no_error);
(void) fs;
EXPECT(error != fs::no_error); // expecting failure
});

}
5 changes: 4 additions & 1 deletion test/unit/fs/vfs_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class Person {
public:
explicit Person(std::string name, int age) : name_ {name}, age_ {age} {};
bool isBjarne() const { return (name_ == "Bjarne") ? true : false; }
bool isAdult() const { return (age_ >= 18) ? true : false; }
private:
std::string name_;
int age_;
Expand Down Expand Up @@ -75,7 +76,9 @@ CASE("VFS entries can contain arbitrary objects")
EXPECT(info == "Person");
Person bjarne = e.obj<Person>();
EXPECT(bjarne.isBjarne() == true);
EXPECT(bjarne.isAdult() == true);
EXPECT_THROWS(e.obj<std::string>());

// constness is checked
const Person q {"Dennis", 70};
fs::VFS_entry f(q, "inspiration", "duh^2");
Expand Down Expand Up @@ -110,7 +113,7 @@ CASE("VFS can mount entries in a tree")
EXPECT(fs::VFS::root().child_count() == 3);

// get mounted objects of correct type
char our_char;
[[maybe_unused]] char our_char;
EXPECT_THROWS(auto dir = fs::get<fs::Dirent>("/mnt/chars/c"));
EXPECT_NO_THROW(our_char = fs::get<char>("/mnt/chars/c"));
}
4 changes: 2 additions & 2 deletions test/unit/memory/alloc/buddy_alloc_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ CASE("mem::buddy random ordered allocation then deallocation"){
int highest_i = 0;
void* highest = nullptr;

for (int i = 0; i < addresses.size(); i++) {
for (size_t i = 0; i < addresses.size(); i++) {
if (addresses.at(i) > highest) {
highest = addresses.at(i);
highest_i = i;
Expand All @@ -198,7 +198,7 @@ CASE("mem::buddy random ordered allocation then deallocation"){
EXPECT(computed_use >= alloc.bytes_used());

// Deallocate
for (int i = 0; i < addresses.size(); i++) {
for (size_t i = 0; i < addresses.size(); i++) {
auto addr = addresses.at(i);
auto sz = sizes.at(i);
if (addr) EXPECT(sz) ;
Expand Down
7 changes: 4 additions & 3 deletions test/unit/memory/alloc/pmr_alloc_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,9 @@ CASE("pmr::Pmr_pool usage") {
for (auto i : test::random)
numbers.push_back(i);

for (auto i = 0; i < numbers.size(); i++)
for (size_t i = 0; i < numbers.size(); i++) {
EXPECT(numbers.at(i) == test::random.at(i));
}

EXPECT(res->allocatable() <= sub_free - 1000);

Expand Down Expand Up @@ -305,7 +306,7 @@ CASE("pmr::on_non_full event") {
event_fired = false;
EXPECT(not event_fired);

for (int i = 2; i < pool_cap / 2; i++) {
for (size_t i = 2; i < pool_cap / 2; i++) {
numbers.push_back(i);
}

Expand Down Expand Up @@ -356,7 +357,7 @@ CASE("pmr::on_avail event") {
event_fired = false;
EXPECT(not event_fired);

for (int i = 2; i < 40_KiB; i++) {
for (size_t i = 2; i < 40_KiB; i++) {
numbers.push_back(i);
}

Expand Down
Loading