Skip to content

Commit

Permalink
test: remove bad alignement reading in archver
Browse files Browse the repository at this point in the history
  • Loading branch information
quesnel committed Jan 23, 2025
1 parent 059c01e commit 8706255
Showing 1 changed file with 0 additions and 211 deletions.
211 changes: 0 additions & 211 deletions lib/test/public-api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3443,46 +3443,6 @@ int main()
}
};

// "memory"_test = [] {
// {
// irt::g_alloc_fn = global_alloc;
// irt::g_free_fn = global_free;

//
// irt::simulation sim(irt::simulation_memory_requirement(256));

// }

// fmt::print("memory: {}/{}\n",
// global_allocator.allocation_number,
// global_deallocator.free_number);

// expect(global_allocator.allocation_size > 0);
// expect(global_allocator.allocation_number ==
// global_deallocator.free_number);

// irt::g_alloc_fn = nullptr;
// irt::g_free_fn = nullptr;

// irt::g_alloc_fn = irt::malloc_wrapper;
// irt::g_free_fn = irt::free_wrapper;
// };

// "null_memory"_test = [] {
// auto old = std::exchange(irt::on_error_callback, nullptr);

// irt::g_alloc_fn = null_alloc;
// irt::g_free_fn = null_free;

//
// irt::simulation sim(irt::simulation_memory_requirement(256));

// irt::g_alloc_fn = irt::malloc_wrapper;
// irt::g_free_fn = irt::free_wrapper;

// std::exchange(irt::on_error_callback, old);
// };

"external_source"_test = [] {
std::error_code ec;
std::stringstream ofs_b;
Expand Down Expand Up @@ -3529,179 +3489,8 @@ int main()
expect(eq(f->tell(), 8 + 4 + 2 + 1));
expect(eq(f->length(), 256));

irt::u8 a_w = f->data[0];
irt::u16 b_w = *(reinterpret_cast<irt::u16*>(&f->data[1]));
irt::u32 c_w = *(reinterpret_cast<irt::u32*>(&f->data[3]));
irt::u64 d_w = *(reinterpret_cast<irt::u64*>(&f->data[7]));

expect(eq(a, a_w));
expect(eq(b, b_w));
expect(eq(c, c_w));
expect(eq(d, d_w));

f->rewind();

assert(f->tell() == 0);
};

"binary-file-io"_test = [] {
std::error_code ec;
auto file_path = std::filesystem::temp_directory_path(ec);

file_path /= "irritator.txt";

{
auto f = irt::file::open(file_path.string().c_str(),
irt::open_mode::write);
expect(!!f);
expect(f->length() == 0);

irt::u8 a = 0xfe;
irt::u16 b = 0xfedc;
irt::u32 c = 0xfedcba98;
irt::u64 d = 0xfedcba9876543210;

expect(!!f->write(a));
expect(!!f->write(b));
expect(!!f->write(c));
expect(!!f->write(d));

expect(f->tell() == 15);
}

{
auto f =
irt::file::open(file_path.string().c_str(), irt::open_mode::read);
expect(!!f);
expect(f->length() == 15);

irt::u8 a = 0xfe;
irt::u16 b = 0xfedc;
irt::u32 c = 0xfedcba98;
irt::u64 d = 0xfedcba9876543210;
irt::u8 a_w = 0;
irt::u16 b_w = 0;
irt::u32 c_w = 0;
irt::u64 d_w = 0;

expect(!!f->read(a_w));
expect(!!f->read(b_w));
expect(!!f->read(c_w));
expect(!!f->read(d_w));

expect(a == a_w);
expect(b == b_w);
expect(c == c_w);
expect(d == d_w);

expect(f->tell() == 15);

f->rewind();

expect(f->tell() == 0);
}

std::filesystem::remove(file_path, ec);
};

"memory"_test = [] {
auto mem = irt::memory::make(2040, irt::open_mode::write);
expect(mem.has_value());

expect(mem->write(0x00112233));
expect(mem->write(0x44556677));
expect(eq(mem->data.ssize(), 2040));
expect(eq(mem->pos, 8));

mem->rewind();

irt::u32 a, b;
expect(mem->read(a));
expect(mem->read(b));

expect(a == 0x00112233);
expect(b == 0x44556677);
};

// "modeling-copy"_test = [] {
// irt::modeling mod;
// irt::modeling_initializer mod_init;
//
// mod.init(mod_init);
// mod.fill_internal_components();
//
// auto& main_compo = mod.components.alloc();
// main_compo.name.assign("New component");
// main_compo.type = irt::component_type::none;
//
// auto& main_tree = mod.tree_nodes.alloc(
// mod.components.get_id(main_compo),
// irt::undefined<irt::child_id>());
// mod.head = mod.tree_nodes.get_id(main_tree);
//
// irt::simple_component* lotka = nullptr;
// while (mod.components.next(lotka))
// if (lotka->type == irt::component_type::qss1_lotka_volterra)
// break;
//
// expect(lotka != nullptr);
//
// auto lotka_id = mod.components.get_id(*lotka);
//
// for (int i = 0; i < 2; ++i) {
// irt::tree_node_id a;
// mod.make_tree_from(*lotka, &a);
//
// auto& child_a = main_compo.children.alloc(lotka_id);
// auto& tree = mod.tree_nodes.get(a);
// tree.id_in_parent = main_compo.children.get_id(child_a);
// tree.tree.set_id(&tree);
// tree.tree.parent_to(main_tree.tree);
// }
//
// irt::simulation sim;
// irt::modeling_to_simulation cache;
//
// expect(mod.can_export_to(cache, sim) == true);
// !!expect(mod.export_to(cache, sim));
// expect(sim.models.ssize() == 2 * lotka->children.ssize());
// };

"archive"_test = [] {
irt::vector<irt::u8> data;
{
auto m = irt::memory::make(256 * 8, irt::open_mode::write);
expect(m.has_value()) << fatal;

irt::simulation sim(
irt::simulation_memory_requirement(1024 * 1024 * 8));
irt::binary_archiver bin;

(void)sim.alloc<irt::qss1_sum_2>();
(void)sim.alloc<irt::qss1_integrator>();
(void)sim.alloc<irt::qss1_multiplier>();

expect(!!bin.simulation_save(sim, *m));

data.resize(static_cast<int>(m->pos));
std::copy_n(m->data.data(), m->pos, data.data());
}

expect(data.size() > 0);

{
auto m = irt::memory::make(data.size(), irt::open_mode::read);
expect(m.has_value()) << fatal;
irt::simulation sim(
irt::simulation_memory_requirement(1024 * 1024 * 8));
irt::binary_archiver bin;

std::copy_n(data.data(), data.size(), m->data.data());
m->pos = 0;

expect(!!bin.simulation_load(sim, *m));
expect(sim.models.size() == 3u);
expect(sim.hsms.size() == 0u);
}
};
}

0 comments on commit 8706255

Please sign in to comment.