void for_each_tests(std::vector<hpx::id_type> &localities) { std::size_t const length = 12; { hpx::partitioned_vector<T> v; hpx::parallel::for_each(hpx::parallel::execution::seq, v.begin(), v.end(), pfo()); hpx::parallel::for_each(hpx::parallel::execution::par, v.begin(), v.end(), pfo()); hpx::parallel::for_each( hpx::parallel::execution::seq(hpx::parallel::execution::task), v.begin(), v.end(), pfo()).get(); hpx::parallel::for_each( hpx::parallel::execution::par(hpx::parallel::execution::task), v.begin(), v.end(), pfo()).get(); } { hpx::partitioned_vector<T> v(length, T(0),hpx::container_layout(localities)); test_for_each(hpx::parallel::execution::seq, v, T(0)); test_for_each(hpx::parallel::execution::par, v, T(1)); test_for_each_async( hpx::parallel::execution::seq(hpx::parallel::execution::task), v, T(2)); test_for_each_async( hpx::parallel::execution::par(hpx::parallel::execution::task), v, T(3)); } }
TEST(semaphore, one_semaphore_few_threads) { // Preparation // Counts how many threads completed int counter = 0; // Counts how many signals sent int signalled = 0; // Semaphore itself ecl::semaphore entry_semaphore; ecl::semaphore exit_semaphore; auto single_thread = [&counter, &entry_semaphore, &exit_semaphore]() { std::cout << "entry wait!" << std::endl; bool ret; while ((ret = entry_semaphore.try_wait()) == false) { std::this_thread::yield(); } counter++; exit_semaphore.signal(); }; std::array< std::thread, threads_count > threads; // Test itself // Start threads test_for_each(threads, [&single_thread](auto &thread) { thread = std::thread(single_thread); }); // Let thread wait on semaphore test_delay(20); // Threads are started and should wait for orders CHECK_EQUAL(0, counter); // Unblock threads one by one test_for_each(threads, [&](auto &thread) { (void) thread; // We don't need this entry_semaphore.signal(); signalled++; bool ret; while ((ret = exit_semaphore.try_wait()) == false) { std::this_thread::yield(); } CHECK_EQUAL(signalled, counter); // Check that only one thread is finished }); // Wait for threads to finish test_for_each(threads, [](auto &thread) { thread.join(); }); }
int main(int argc, char* argv[]) { int status = 0; bool testAll = false; if (testAll) { status += test_rotatedString(); status += test_threeWayPartition(); status += test_slicingProblem(); status += test_charString(); status += test_fibmemo(); status += test_for_each(); status += BoggleBoard::unit_test(); status += Sum123::unit_test(); status += RandModN::unit_test(); status += BinLink::unit_test(); status += test_NlightBulbs(100); status += test_Kadane(); status += test_interleaveInPlace(); } status += test_uniqueCharSubString(); status += test_macro(); status += test_bitvector(); //getchar(); // modify commnad window properties while waiting for input return status; }
int main () { test_for_each(); test_count_if(); test_accumulate(); return 0; }
int main() { test_for_each(); test_out(); test_cast_to_char(); test_cast_from_char(); test_operators(); return EXIT_SUCCESS; }
int init_module(void) { START_TESTS("BIB-Session"); INIT_CALL_END(init(), simple_bib(), end(), "Single BIB"); INIT_CALL_END(init(), simple_session(), end(), "Single Session"); INIT_CALL_END(init(), test_clean_old_sessions(), end(), "Session cleansing."); INIT_CALL_END(init(), test_address_filtering(), end(), "Address-dependent filtering."); INIT_CALL_END(init(), test_for_each(), end(), "for-each function."); END_TESTS; }
TEST(semaphore, multiple_threads) { // Preparation // Object associated with a thread struct test_object { ecl::semaphore semaphore; std::thread thread; volatile bool flag; }; std::array< test_object, threads_count > objs; auto single_thread = [](auto *obj) { obj->semaphore.wait(); obj->flag = true; // Rise a flag only if semaphore signaled }; // Test itself // Start threads test_for_each(objs, [&single_thread](auto &obj) { obj.flag = false; obj.thread = std::thread(single_thread, &obj); }); // Let them wait on semaphore test_delay(100); // Threads are started and should wait for orders test_for_each(objs, [](auto &obj) { CHECK(!obj.flag); } ); // Unblock threads test_for_each(objs, [](auto &obj) { obj.semaphore.signal(); }); // Let threads do the work test_delay(50); // Check that work is done test_for_each(objs, [](auto &obj) { CHECK(obj.flag); }); // Wait for threads to finish test_for_each(objs, [](auto &obj) { obj.thread.join(); }); }
int main(void) { test_creation(); test_finding(); test_inserting(); test_inserting_and_finding(); test_that_keys_are_copied(); test_for_each(); test_increasing(); return 0; }