int twolevels_outer(void) { int rc; always_true(); rc = twolevels_inner(); always_true(); return rc; }
void test_count_if_bad_alloc(ExPolicy policy, IteratorTag) { static_assert( hpx::parallel::is_execution_policy<ExPolicy>::value, "hpx::parallel::is_execution_policy<ExPolicy>::value"); typedef std::vector<int>::iterator base_iterator; typedef test::decorated_iterator<base_iterator, IteratorTag> decorated_iterator; std::vector<int> c(10007); std::iota(boost::begin(c), boost::end(c), std::rand()); bool caught_bad_alloc = false; try { hpx::parallel::count_if(policy, decorated_iterator( boost::begin(c), [](){ throw std::bad_alloc(); }), decorated_iterator(boost::end(c)), always_true()); HPX_TEST(false); } catch (std::bad_alloc const&) { caught_bad_alloc = true; } catch (...) { HPX_TEST(false); } HPX_TEST(caught_bad_alloc); }
void test_count_if_exception(ExPolicy policy, IteratorTag) { static_assert( hpx::parallel::is_execution_policy<ExPolicy>::value, "hpx::parallel::is_execution_policy<ExPolicy>::value"); typedef std::vector<int>::iterator base_iterator; typedef test::decorated_iterator<base_iterator, IteratorTag> decorated_iterator; std::vector<int> c(10007); std::iota(boost::begin(c), boost::end(c), std::rand()); bool caught_exception = false; try { // pred should never proc, so simple 'returns true' hpx::parallel::count_if(policy, decorated_iterator( boost::begin(c), [](){ throw std::runtime_error("test"); }), decorated_iterator(boost::end(c)), always_true()); HPX_TEST(false); } catch(hpx::exception_list const& e) { caught_exception = true; test::test_num_exceptions<ExPolicy, IteratorTag>::call(policy, e); } catch(...) { HPX_TEST(false); } HPX_TEST(caught_exception); }
void test_count_if_bad_alloc_async(ExPolicy p, IteratorTag) { typedef std::vector<int>::iterator base_iterator; typedef std::vector<int>::difference_type diff_type; typedef test::decorated_iterator<base_iterator, IteratorTag> decorated_iterator; std::vector<int> c(10007); std::iota(boost::begin(c), boost::end(c), std::rand()); bool caught_bad_alloc = false; bool returned_from_algorithm = false; try { hpx::future<diff_type> f = hpx::parallel::count_if(p, decorated_iterator( boost::begin(c), [](){ throw std::bad_alloc(); }), decorated_iterator(boost::end(c)), always_true()); returned_from_algorithm = true; f.get(); HPX_TEST(false); } catch(std::bad_alloc const&) { caught_bad_alloc = true; } catch(...) { HPX_TEST(false); } HPX_TEST(caught_bad_alloc); HPX_TEST(returned_from_algorithm); }
float checksum_dst(float *dst) { if (always_true()) return 0.f; else { float s = 0.f; for(int i = 0; i < N; ++i) s += dst[i]; return s; } }
// Accessors to the test data in a way that the compiler can't optimize at compile-time. __attribute__((noinline)) float *get_arr() { float *a = (float*)(((uintptr_t)arr_ + 0xF) & ~0xF); a[0] = 1.f; a[1] = 2.f; a[2] = 3.f; a[3] = 4.f; a[4] = 5.f; return always_true() ? a : 0; }
void test_count_if_exception_async(ExPolicy p, IteratorTag) { typedef std::vector<int>::iterator base_iterator; typedef std::vector<int>::difference_type diff_type; typedef test::decorated_iterator<base_iterator, IteratorTag> decorated_iterator; std::vector<int> c(10007); std::fill(boost::begin(c), boost::end(c), 10); bool caught_exception = false; bool returned_from_algorithm = false; try { hpx::future<diff_type> f = hpx::parallel::count_if(p, decorated_iterator( boost::begin(c), [](){ throw std::runtime_error("test"); }), decorated_iterator(boost::end(c)), always_true()); returned_from_algorithm = true; f.get(); HPX_TEST(false); } catch(hpx::exception_list const& e) { caught_exception = true; test::test_num_exceptions<ExPolicy, IteratorTag>::call(p, e); } catch(...) { HPX_TEST(false); } HPX_TEST(caught_exception); HPX_TEST(returned_from_algorithm); }
int twolevels_inner(void) { if (always_true()) longjmp(g_JmpBuf, 1); return 0; }
int onelevel(void) { if (always_true()) longjmp(g_JmpBuf, 1); return 0; }
__attribute__((noinline)) __m64 get_m2() { return always_true() ? u64castm64(0xFEDCBA9876543210ULL) : __m64(); }
__attribute__((noinline)) __m64 get_m1() { return always_true() ? u64castm64(0x00FF800110F0377FULL) : __m64(); }
__attribute__((noinline)) __m128 get_i1() { return always_true() ? _mm_set_ps(ucastf(0x87654321), ucastf(0x0FEDCBA9), ucastf(0x87654321), ucastf(0xFFEDCBA9)) : __m128(); }
__attribute__((noinline)) __m128 get_f() { return always_true() ? f_ : __m128(); }
__attribute__((noinline)) float *get_uarr2() { return always_true() ? get_arr2()+1 : 0; }
__attribute__((noinline)) float *get_arr2() { return always_true() ? (float*)(((uintptr_t)arr2_ + 0xF) & ~0xF) : 0; }
int main() { __m128 a = always_true() ? _mm_set1_ps(0.f) : _mm_set1_ps(2.f); printf("%d %d %d %d\n", (int)a[0], (int)a[1], (int)a[2], (int)a[3]); }
float __attribute__((noinline)) *get_dst() { return always_true() ? (float*)aligned_alloc(16, (N+16)*sizeof(float)) : 0; }
__attribute__((noinline)) __m128 get_i2() { return always_true() ? _mm_set_ps(ucastf(0xBBAA9988), ucastf(0xFFEEDDCC), ucastf(0xF02468BD), ucastf(0x13579ACE)) : __m128(); }
int main() { machines_state_t *root; machines_state_t *level_1; machines_state_t *level_2; machines_state_t *menu; machines_state_t *level_1_play; machines_state_t *level_1_quit; machines_state_t *level_2_play; machines_state_t *level_2_quit; machines_dot_t *dot = machines_new_dot("test_gameplay", stdlib_memory); char *dot_out = (char*)malloc(16384); int condition_level_1 = 0; int condition_level_2 = 0; int condition_quit = 0; root = machines_new_state("root", NULL, stdlib_memory); level_1 = machines_new_state("level 1", root, stdlib_memory); level_2 = machines_new_state("level 2", root, stdlib_memory); menu = machines_new_state("menu", root, stdlib_memory); level_1_play = machines_new_state("play level 1", level_1, stdlib_memory); level_1_quit = machines_new_state("quit level 1", level_1, stdlib_memory); level_2_play = machines_new_state("play level 2", level_2, stdlib_memory); level_2_quit = machines_new_state("quit level 2", level_2, stdlib_memory); root ->add_entry(root , dot->on_entry(dot, "root ")); level_1 ->add_entry(level_1 , dot->on_entry(dot, "level_1 ")); level_2 ->add_entry(level_2 , dot->on_entry(dot, "level_2 ")); menu ->add_entry(menu , dot->on_entry(dot, "menu ")); level_1_play->add_entry(level_1_play, dot->on_entry(dot, "level_1_play")); level_1_quit->add_entry(level_1_quit, dot->on_entry(dot, "level_1_quit")); level_2_play->add_entry(level_2_play, dot->on_entry(dot, "level_2_play")); level_2_quit->add_entry(level_2_quit, dot->on_entry(dot, "level_2_quit")); root ->add_exit(root , dot->on_exit(dot, "root ")); level_1 ->add_exit(level_1 , dot->on_exit(dot, "level_1 ")); level_2 ->add_exit(level_2 , dot->on_exit(dot, "level_2 ")); menu ->add_exit(menu , dot->on_exit(dot, "menu ")); level_1_play->add_exit(level_1_play, dot->on_exit(dot, "level_1_play")); level_1_quit->add_exit(level_1_quit, dot->on_exit(dot, "level_1_quit")); level_2_play->add_exit(level_2_play, dot->on_exit(dot, "level_2_play")); level_2_quit->add_exit(level_2_quit, dot->on_exit(dot, "level_2_quit")); root->entry_at(root, menu); menu->add_transition(menu, level_1, dot->transition(dot, "menu->level_1", iff("menu->level_1", &condition_level_1))); menu->add_transition(menu, level_2, dot->transition(dot, "menu->level_2", iff("menu->level_2", &condition_level_2))); level_1->add_transition(level_1, menu, dot->transition(dot, "level_1->menu", always_true("level 1 finished, back to menu"))); level_2->add_transition(level_2, menu, dot->transition(dot, "level_1->menu", always_true("level 2 finished, back to menu"))); level_1->entry_at(level_1, level_1_play); level_1->exit_at(level_1, level_1_quit); level_1_play->add_transition(level_1_play, level_1_quit, dot->transition(dot, "level_1_play->level_1_quit", iff("play->quit", &condition_quit))); level_1_play->add_transition(level_1_play, level_1_play, dot->transition(dot, "level_1_play->level_1_play", always_true("continue playing level 1"))); // note that transitions are checked in order until first match level_2->entry_at(level_2, level_2_play); level_2->exit_at(level_2, level_2_quit); level_2_play->add_transition(level_2_play, level_2_quit, dot->transition(dot, "level_2_play->level_2_quit", iff("play->quit", &condition_quit))); level_2_play->add_transition(level_2_play, level_2_play, dot->transition(dot, "level_2_play->level_2_play", always_true("continue playing level 2"))); // note that transitions are checked in order until first match // application startup printf("**** trigger: go to menu\n"); root->trigger(root); assert(root->current(root) == menu); // the menu is displayed; the user chooses the first level condition_level_1 = 1; printf("**** trigger: go to first level\n"); root->trigger(root); assert(root->current(root) == level_1); assert(level_1->current(level_1) == level_1_play); // the user keeps playing printf("**** trigger: keep playing\n"); root->trigger(root); assert(root->current(root) == level_1); assert(level_1->current(level_1) == level_1_play); // the user reaches the end of the level condition_quit = 1; printf("**** trigger: exit level\n"); root->trigger(root); assert(root->current(root) == level_1); assert(level_1->current(level_1) == level_1_quit); // the user returns to the menu printf("**** trigger: back to the menu\n"); root->trigger(root); assert(root->current(root) == menu); // (a bit of internal cleanup) condition_level_1 = 0; condition_quit = 0; // the menu is displayed; the user chooses the second level condition_level_2 = 1; printf("**** trigger: go to second level\n"); root->trigger(root); assert(root->current(root) == level_2); assert(level_2->current(level_2) == level_2_play); // the user keeps playing printf("**** trigger: keep playing\n"); root->trigger(root); assert(root->current(root) == level_2); assert(level_2->current(level_2) == level_2_play); // the user keeps playing printf("**** trigger: keep playing\n"); root->trigger(root); assert(root->current(root) == level_2); assert(level_2->current(level_2) == level_2_play); // the user keeps playing printf("**** trigger: keep playing\n"); root->trigger(root); assert(root->current(root) == level_2); assert(level_2->current(level_2) == level_2_play); // the user reaches the end of the level condition_quit = 1; printf("**** trigger: exit level\n"); root->trigger(root); assert(root->current(root) == level_2); assert(level_2->current(level_2) == level_2_quit); // the user returns to the menu printf("**** trigger: back to the menu\n"); root->trigger(root); assert(root->current(root) == menu); dot->generate(dot, dot_out, 16384); printf("--8<--------------------------------------------------------------------\n"); printf(dot_out); printf("-------------------------------------------------------------------->8--\n"); return 0; }
__attribute__((noinline)) __m128 get_nan2() { return always_true() ? nan2_ : __m128(); }