void test_shared() { boost::shared_ptr<A> ip(new C); boost::shared_ptr<A> op1; boost::shared_ptr<A> op2; { std::vector<char> buffer; hpx::serialization::output_archive oarchive(buffer); oarchive << ip << ip; hpx::serialization::input_archive iarchive(buffer); iarchive >> op1; iarchive >> op2; } HPX_TEST_NEQ(op1.get(), ip.get()); HPX_TEST_NEQ(op2.get(), ip.get()); HPX_TEST_EQ(op1.get(), op2.get()); HPX_TEST_EQ(op1->foo(), std::string("C::foo")); HPX_TEST_EQ(op2->foo(), std::string("C::foo")); HPX_TEST_EQ(static_cast<C*>(op1.get())->a, 1); HPX_TEST_EQ(static_cast<C*>(op1.get())->b, 2); HPX_TEST_EQ(static_cast<C*>(op1.get())->get_c(), 3); HPX_TEST_EQ(static_cast<C*>(op2.get())->a, 1); HPX_TEST_EQ(static_cast<C*>(op2.get())->b, 2); HPX_TEST_EQ(static_cast<C*>(op2.get())->get_c(), 3); HPX_TEST_EQ(op1.use_count(), 2); }
bool test_migrate_component(hpx::id_type source, hpx::id_type target) { // create component on given locality test_client t1 = test_client::create(source); HPX_TEST_NEQ(hpx::naming::invalid_id, t1.get_gid()); // the new object should live on the source locality HPX_TEST_EQ(t1.call(), source); try { // migrate of t1 to the target test_client t2(hpx::components::migrate<test_server>( t1.get_gid(), target)); HPX_TEST_NEQ(hpx::naming::invalid_id, t2.get_gid()); // the migrated object should have the same id as before HPX_TEST_EQ(t1.get_gid(), t2.get_gid()); // the migrated object should life on the target now HPX_TEST_EQ(t2.call(), target); return true; } catch (hpx::exception const&) { return false; } }
void test_intrusive() { boost::intrusive_ptr<D> ip(new F); boost::intrusive_ptr<D> op1; boost::intrusive_ptr<D> op2; { std::vector<char> buffer; hpx::serialization::output_archive oarchive(buffer); oarchive << ip << ip; hpx::serialization::input_archive iarchive(buffer); iarchive >> op1; iarchive >> op2; } HPX_TEST_NEQ(op1.get(), ip.get()); HPX_TEST_NEQ(op2.get(), ip.get()); HPX_TEST_EQ(op1.get(), op2.get()); HPX_TEST_EQ(op1->foo(), std::string("F::foo")); HPX_TEST_EQ(op2->foo(), std::string("F::foo")); HPX_TEST_EQ(static_cast<F*>(op1.get())->a, 1); HPX_TEST_EQ(static_cast<F*>(op1.get())->b, 2); HPX_TEST_EQ(static_cast<F*>(op1.get())->get_c(), 3); HPX_TEST_EQ(static_cast<F*>(op2.get())->a, 1); HPX_TEST_EQ(static_cast<F*>(op2.get())->b, 2); HPX_TEST_EQ(static_cast<F*>(op2.get())->get_c(), 3); HPX_TEST_EQ(ip->count, 1); HPX_TEST_EQ(op1->count, 2); HPX_TEST_EQ(op2->count, 2); op1.reset(); HPX_TEST_EQ(op2->count, 1); }
int main() { std::vector<char> buffer; hpx::serialization::output_archive oarchive(buffer); oarchive << A(); B * const b1 = new D; oarchive << hpx::serialization::detail::raw_ptr(b1); oarchive << hpx::serialization::detail::raw_ptr(b1); hpx::serialization::input_archive iarchive(buffer); A a; iarchive >> a; B *b2 = 0, *b3 = 0; iarchive >> hpx::serialization::detail::raw_ptr(b2); iarchive >> hpx::serialization::detail::raw_ptr(b3); HPX_TEST_EQ(a.a, 8); HPX_TEST_NEQ(b2, b1); HPX_TEST_NEQ(b2, b3); //untracked HPX_TEST_EQ(b2->b, b1->b); delete b2; HPX_TEST_EQ(b1->b, 4711); return hpx::util::report_errors(); }
void test(hpx::id_type there) { test_client t1 = test_client::create(there); HPX_TEST_NEQ(hpx::naming::invalid_id, t1.get_id()); // the new object should live on the source locality HPX_TEST_EQ(t1.call(), there); // verify for remote component HPX_TEST_EQ(hpx::get_colocation_id(hpx::launch::sync, t1.get_id()), there); HPX_TEST_EQ(hpx::async<test_colocation_action>( hpx::colocated(t1.get_id())).get(), there); test_colocation_action act; HPX_TEST_EQ(hpx::async(act, hpx::colocated(t1.get_id())).get(), there); // verify for remote locality HPX_TEST_EQ(hpx::get_colocation_id(hpx::launch::sync, there), there); HPX_TEST_EQ(hpx::async<test_colocation_action>( hpx::colocated(there)).get(), there); HPX_TEST_EQ(hpx::async(act, hpx::colocated(there)).get(), there); }
bool test_get_ptr2(hpx::id_type id) { test_client t = test_client::create(id); HPX_TEST_NEQ(hpx::naming::invalid_id, t.get_id()); hpx::future<boost::shared_ptr<test_server> > f = hpx::get_ptr<test_server>(t.get_id()); f.wait(); bool has_exception = f.has_exception(); hpx::error_code ec; boost::shared_ptr<test_server> ptr = f.get(ec); // Intel 13 has trouble to generate correct code for if(ec) { ... } if (ec || !ptr.get()) { HPX_TEST(has_exception); return false; } HPX_TEST(!has_exception); HPX_TEST_EQ(reinterpret_cast<test_server*>(t.check_ptr()), ptr.get()); return true; }
int main(int argc, char* argv[]) { HPX_TEST_EQ_MSG(hpx::init(argc, argv), 0, "HPX main exited with non-zero status"); HPX_TEST_NEQ(std::uint32_t(-1), locality_id); HPX_TEST(on_shutdown_executed || 0 != locality_id); return hpx::util::report_errors(); }
int main(int argc, char* argv[]) { accumulator.store(0); // Initialize and run HPX HPX_TEST_EQ_MSG(hpx::init(argc, argv), 0, "HPX main exited with non-zero status"); HPX_TEST_NEQ(boost::uint32_t(-1), locality_id); HPX_TEST(on_shutdown_executed || 0 != locality_id); return hpx::util::report_errors(); }
bool test_copy_component_here(hpx::id_type id) { // create component on given locality test_client t1; t1.create(id); HPX_TEST_NEQ(hpx::naming::invalid_id, t1.get_gid()); try { // create a copy of t1 here test_client t2(hpx::components::copy<test_server>(t1.get_gid(), hpx::find_here())); HPX_TEST_NEQ(hpx::naming::invalid_id, t2.get_gid()); // the new object should life here HPX_TEST_EQ(t2.call(), hpx::find_here()); return true; } catch (hpx::exception const&) { HPX_TEST(false); } return false; }
void test_find_id_from_basename() { char const* basename = "/find_id_from_prefix_test/"; test_client t1 = test_client::create(hpx::find_here()); hpx::id_type client_id = t1.get_id(); HPX_TEST_NEQ(hpx::naming::invalid_id, client_id); // register our component with AGAS HPX_TEST((hpx::register_with_basename(basename, client_id).get())); // wait for all localities to register their component std::vector<hpx::id_type> localities = hpx::find_all_localities(); std::vector<std::size_t> sequence_nrs; std::vector<hpx::future<hpx::id_type> > ids; sequence_nrs.reserve(localities.size()); ids.reserve(localities.size()); for (hpx::id_type const& locality : localities) { std::size_t nr = hpx::naming::get_locality_id_from_id(locality); sequence_nrs.push_back(nr); ids.push_back(hpx::find_from_basename(basename, nr)); } HPX_TEST_EQ(ids.size(), sequence_nrs.size()); // retrieve all component ids std::set<hpx::id_type> component_localities; for (hpx::future<hpx::id_type>& f : ids) { hpx::id_type id = f.get(); hpx::id_type locality = test_client(id).call(); std::pair<std::set<hpx::id_type>::iterator, bool> p = component_localities.insert(locality); HPX_TEST(p.second); // every id should be unique } HPX_TEST_EQ(component_localities.size(), localities.size()); // make sure that components are on all localities for (hpx::id_type const& id : localities) { HPX_TEST(component_localities.find(id) != component_localities.end()); } }
bool test_get_ptr2(hpx::id_type id) { test_client t = test_client::create(id); HPX_TEST_NEQ(hpx::naming::invalid_id, t.get_gid()); hpx::future<boost::shared_ptr<test_server> > f = hpx::get_ptr<test_server>(t.get_gid()); hpx::error_code ec; boost::shared_ptr<test_server> ptr = f.get(ec); if (ec) return false; HPX_TEST_EQ(reinterpret_cast<test_server*>(t.check_ptr()), ptr.get()); return true; }
bool test_migrate_component_to_storage(hpx::id_type const& source, hpx::id_type const& target, hpx::components::component_storage storage, hpx::id_type::management_type t) { hpx::id_type oldid; { // create component on given locality test_client t1(source); HPX_TEST_NEQ(hpx::naming::invalid_id, t1.get_id()); // the new object should live on the source locality HPX_TEST_EQ(t1.call(), source); // remember the original id for later resurrection oldid = hpx::id_type(t1.get_id().get_gid(), t); try { // migrate of t1 to the target storage test_client t2(hpx::components::migrate_to_storage(t1, storage)); HPX_TEST_EQ(hpx::naming::invalid_id, t2.get_id()); } catch (hpx::exception const&) { return false; } HPX_TEST_EQ(storage.size(hpx::launch::sync), std::size_t(1)); // make sure all local references go out of scope if t == unmanaged } HPX_TEST_EQ(storage.size(hpx::launch::sync), std::size_t(1)); { test_client t1(hpx::components::migrate_from_storage<test_server>( oldid, target)); // the id of the newly resurrected object should be the same as the old id HPX_TEST_EQ(oldid, t1.get_id()); // the new object should now live on the target locality HPX_TEST_EQ(t1.call(), target); HPX_TEST_EQ(storage.size(hpx::launch::sync), std::size_t(0)); } return true; }
void test_storage(hpx::id_type const& here, hpx::id_type const& there) { // create a new storage instance hpx::components::component_storage storage(here); HPX_TEST_NEQ(hpx::naming::invalid_id, storage.get_id()); HPX_TEST(test_migrate_component_to_storage(here, storage, hpx::id_type::unmanaged)); HPX_TEST(test_migrate_component_to_storage(here, storage, hpx::id_type::managed)); HPX_TEST(test_migrate_component_to_storage(here, there, storage, hpx::id_type::unmanaged)); HPX_TEST(test_migrate_component_to_storage(here, there, storage, hpx::id_type::managed)); // HPX_TEST(test_migrate_component_from_storage(here, storage)); }
bool test_migrate_component_from_storage(hpx::id_type const& source, hpx::components::component_storage storage) { hpx::id_type oldid; { // create component on given locality test_client t1(source); HPX_TEST_NEQ(hpx::naming::invalid_id, t1.get_id()); // the new object should live on the source locality HPX_TEST_EQ(t1.call(), source); // remember the original id for later action invocation oldid = t1.get_id(); try { // migrate of t1 to the target storage test_client t2(hpx::components::migrate_to_storage(t1, storage)); HPX_TEST_EQ(hpx::naming::invalid_id, t2.get_id()); } catch (hpx::exception const&) { return false; } HPX_TEST_EQ(storage.size(hpx::launch::sync), std::size_t(1)); } HPX_TEST_EQ(storage.size(hpx::launch::sync), std::size_t(1)); // The object is stored in the storage now, apply an action which should // transparently bring it back. { test_client t1; t1.reset(oldid); // transparently resurrect object on the original source locality HPX_TEST_EQ(t1.call(), source); HPX_TEST_EQ(storage.size(hpx::launch::sync), std::size_t(0)); } return true; }
bool test_get_ptr1(hpx::id_type id) { test_client t = test_client::create(id); HPX_TEST_NEQ(hpx::naming::invalid_id, t.get_id()); try { hpx::future<boost::shared_ptr<test_server> > f = hpx::get_ptr<test_server>(t.get_id()); boost::shared_ptr<test_server> ptr = f.get(); HPX_TEST_EQ(reinterpret_cast<test_server*>(t.check_ptr()), ptr.get()); return true; } catch (hpx::exception const& e) { HPX_TEST_EQ(int(e.get_error()), int(hpx::bad_parameter)); } return false; }
void compare_vectors(Vector const& v1, Vector const& v2, bool must_be_equal = true) { typedef typename Vector::const_iterator const_iterator; HPX_TEST_EQ(v1.size(), v2.size()); const_iterator it1 = v1.begin(), it2 = v2.begin(); const_iterator end1 = v1.end(), end2 = v2.end(); for (/**/; it1 != end1 && it2 != end2; ++it1, ++it2) { if (must_be_equal) { HPX_TEST_EQ(*it1, *it2); } else { HPX_TEST_NEQ(*it1, *it2); } } }