static aligned_t update(void *arg) { stencil_t *points = ((update_args_t *)arg)->points; size_t i = ((update_args_t *)arg)->i; size_t j = ((update_args_t *)arg)->j; size_t this_stage = ((update_args_t *)arg)->stage; size_t step = ((update_args_t *)arg)->step; size_t next_stage_id = next_stage(this_stage); // Perform local work perform_local_work(); aligned_t **prev = points->stage[prev_stage(this_stage)]; aligned_t sum = *(NORTH(prev, i, j)) + *(WEST(prev, i, j)) + *(HERE(prev, i, j)) + *(EAST(prev, i, j)) + *(SOUTH(prev, i, j)); // Empty the next stage for this index qthread_empty(&points->stage[next_stage_id][i][j]); // Update this point qthread_writeEF_const(&points->stage[this_stage][i][j], sum/NUM_NEIGHBORS); if (step < num_timesteps) { // Spawn next stage update_args_t args = {points, i, j, next_stage_id, step+1}; #ifdef BOUNDARY_SYNC qthread_fork_copyargs_precond(update, &args, sizeof(update_args_t), NULL, NUM_NEIGHBORS, NEIGHBORS(points->stage[this_stage],i,j)); #else if (i == 1) { // North edge if (j == 1) // West edge: EAST & SOUTH qthread_fork_copyargs_precond(update, &args, sizeof(update_args_t), NULL, 2, EAST(points->stage[this_stage],i,j), SOUTH(points->stage[this_stage],i,j)); else if (j == points->M-2) // East edge: WEST & SOUTH qthread_fork_copyargs_precond(update, &args, sizeof(update_args_t), NULL, 2, WEST(points->stage[this_stage],i,j), SOUTH(points->stage[this_stage],i,j)); else // Interior: WEST & EAST & SOUTH qthread_fork_copyargs_precond(update, &args, sizeof(update_args_t), NULL, 3, WEST(points->stage[this_stage],i,j), EAST(points->stage[this_stage],i,j), SOUTH(points->stage[this_stage],i,j)); } else if (i == points->N-2) { // South edge if (j == 1) // West edge: NORTH & EAST qthread_fork_copyargs_precond(update, &args, sizeof(update_args_t), NULL, 2, NORTH(points->stage[this_stage],i,j), EAST(points->stage[this_stage],i,j)); else if (j == points->M-2) // East edge: NORTH & WEST qthread_fork_copyargs_precond(update, &args, sizeof(update_args_t), NULL, 2, NORTH(points->stage[this_stage],i,j), WEST(points->stage[this_stage],i,j)); else // Interior: NORTH & WEST & EAST qthread_fork_copyargs_precond(update, &args, sizeof(update_args_t), NULL, 3, NORTH(points->stage[this_stage],i,j), WEST(points->stage[this_stage],i,j), EAST(points->stage[this_stage],i,j)); } else { // Interior if (j == 1) // West edge: NORTH & EAST & SOUTH qthread_fork_copyargs_precond(update, &args, sizeof(update_args_t), NULL, 3 , NORTH(points->stage[this_stage],i,j), EAST(points->stage[this_stage],i,j), SOUTH(points->stage[this_stage],i,j)); else if (j == points->M-2) // East edge: NORTH & WEST & SOUTH qthread_fork_copyargs_precond(update, &args, sizeof(update_args_t), NULL, 3, NORTH(points->stage[this_stage],i,j), WEST(points->stage[this_stage],i,j), SOUTH(points->stage[this_stage],i,j)); else // Interior: ALL qthread_fork_copyargs_precond(update, &args, sizeof(update_args_t), NULL, 4, NORTH(points->stage[this_stage],i,j), EAST(points->stage[this_stage],i,j), WEST(points->stage[this_stage],i,j), SOUTH(points->stage[this_stage],i,j)); } #endif } else qt_feb_barrier_enter(points->barrier); return 0; }
void testHTTP() { // Create the mock request. Mock_env env; env.swimmer->sink() << "GET /print('Hello') HTTP/1.0"; // perform the stage. std::unique_ptr<logjam::Stage> next_stage( new logjamd::Stage_pre()); next_stage = logjam::safe_execute_stage(next_stage, *(env.swimmer)); // Test the next stage. TEST_ASSERT(next_stage != nullptr); TEST_ASSERT(next_stage->name().compare("HTTP-Adapter") == 0); }
void testBSON() { // Create the mock request. Mock_env env; env.swimmer->sink() << "BSON\n"; // perform the stage. std::unique_ptr<logjam::Stage> next_stage( new logjamd::Stage_pre()); next_stage = logjam::safe_execute_stage(next_stage, *(env.swimmer)); // Test the next stage. TEST_ASSERT(next_stage != nullptr); TEST_ASSERT(next_stage->name().compare("Authentication") == 0); }
void testUnknown() { // Create the mock request. Mock_env env; env.swimmer->sink() << "rtmp "; // perform the stage. std::unique_ptr<logjam::Stage> next_stage( new logjamd::Stage_pre()); next_stage = logjam::safe_execute_stage(next_stage, *(env.swimmer)); // Test the result. std::string expected("{\"message\":\"Unknown mode: rtmp\", \"stage\":\"Pre-connection\", \"success\":0}"); std::ostringstream oss; oss << env.swimmer->source().rdbuf(); TEST_ASSERT(oss.str().compare(expected) == 0); TEST_ASSERT(next_stage == NULL); }