void test_lagopus_pipeline_stage_start_null(void) { lagopus_result_t ret = LAGOPUS_RESULT_ANY_FAILURES; lagopus_pipeline_stage_t stage = NULL; /* call func. */ ret = lagopus_pipeline_stage_start(NULL); TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_INVALID_ARGS, ret, "lagopus_pipeline_stage_start(null) error."); ret = lagopus_pipeline_stage_start(&stage); TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_INVALID_ARGS, ret, "lagopus_pipeline_stage_start(null) error."); }
void test_lagopus_pipeline_stage_start_double_call(void) { lagopus_result_t ret = LAGOPUS_RESULT_ANY_FAILURES; lagopus_pipeline_stage_t stage = NULL; /* create data. */ pipeline_stage_create_start(&stage, pipeline_pre_pause, pipeline_sched, pipeline_setup, pipeline_fetch, pipeline_main, pipeline_throw, pipeline_shutdown, pipeline_finalize, pipeline_freeup); /* call func (double call) */ ret = lagopus_pipeline_stage_start(&stage); TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_INVALID_STATE_TRANSITION, ret, "lagopus_pipeline_stage_start(double call) error."); ret = lagopus_pipeline_stage_shutdown(&stage, SHUTDOWN_GRACEFULLY); TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_OK, ret, "lagopus_pipeline_stage_shutdown error."); /* after. */ do_stop = true; lagopus_pipeline_stage_destroy(&stage); }
void test_lagopus_pipeline_stage_setup_invalid_state(void) { lagopus_result_t ret = LAGOPUS_RESULT_ANY_FAILURES; lagopus_pipeline_stage_t stage = NULL; /* create data. */ pipeline_stage_create(&stage, pipeline_pre_pause, pipeline_sched, pipeline_setup, pipeline_fetch, pipeline_main, pipeline_throw, pipeline_shutdown, pipeline_finalize, pipeline_freeup); ret = lagopus_pipeline_stage_start(&stage); TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_OK, ret, "lagopus_pipeline_stage_start error."); /* call func. (state is STAGE_STATE_STARTED) */ ret = lagopus_pipeline_stage_setup(&stage); TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_INVALID_STATE_TRANSITION, ret, "not invalid state."); /* after. */ lagopus_pipeline_stage_destroy(&stage); }
static void pipeline_stage_create_start(lagopus_pipeline_stage_t *sptr, lagopus_pipeline_stage_pre_pause_proc_t pre_pause_proc, lagopus_pipeline_stage_sched_proc_t sched_proc, lagopus_pipeline_stage_setup_proc_t setup_proc, lagopus_pipeline_stage_fetch_proc_t fetch_proc, lagopus_pipeline_stage_main_proc_t main_proc, lagopus_pipeline_stage_throw_proc_t throw_proc, lagopus_pipeline_stage_shutdown_proc_t shutdown_proc, lagopus_pipeline_stage_finalize_proc_t finalize_proc, lagopus_pipeline_stage_freeup_proc_t freeup_proc) { lagopus_result_t ret = LAGOPUS_RESULT_ANY_FAILURES; pipeline_stage_create(sptr, pre_pause_proc, sched_proc, setup_proc, fetch_proc, main_proc, throw_proc, shutdown_proc, finalize_proc, freeup_proc); ret = lagopus_pipeline_stage_start(sptr); TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_OK, ret, "lagopus_pipeline_stage_start error."); SLEEP; ret = global_state_set(GLOBAL_STATE_STARTED); TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_OK, ret, "global_state_set error."); SLEEP; }
void test_lagopus_pipeline_stage_start_invalid_object(void) { lagopus_result_t ret = LAGOPUS_RESULT_ANY_FAILURES; lagopus_pipeline_stage_t stage = stage_alloc(); /* call func (invalid object) */ ret = lagopus_pipeline_stage_start(&stage); TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_INVALID_OBJECT, ret, "lagopus_pipeline_stage_start(invalid object) error."); /* after. */ free(stage); }
int main(int argc, const char *const argv[]) { lagopus_result_t st = LAGOPUS_RESULT_ANY_FAILURES; lagopus_pipeline_stage_t s = NULL; size_t nthd = 1; (void)argc; if (IS_VALID_STRING(argv[1]) == true) { size_t tmp; if (lagopus_str_parse_uint64(argv[1], &tmp) == LAGOPUS_RESULT_OK && tmp > 0LL) { nthd = tmp; } } fprintf(stdout, "Creating... "); st = lagopus_pipeline_stage_create(&s, 0, "a_test", nthd, sizeof(void *), 1024, s_pre_pause, s_sched, s_setup, s_fetch, s_main, s_throw, s_shutdown, s_finalize, s_freeup); if (st == LAGOPUS_RESULT_OK) { fprintf(stdout, "Created.\n"); fprintf(stdout, "Setting up... "); st = lagopus_pipeline_stage_setup(&s); if (st == LAGOPUS_RESULT_OK) { fprintf(stdout, "Set up.\n"); fprintf(stdout, "Starting... "); st = lagopus_pipeline_stage_start(&s); if (st == LAGOPUS_RESULT_OK) { fprintf(stdout, "Started.\n"); fprintf(stdout, "Opening the front door... "); st = global_state_set(GLOBAL_STATE_STARTED); if (st == LAGOPUS_RESULT_OK) { char buf[1024]; char *cmd = NULL; fprintf(stdout, "The front door is open.\n"); fprintf(stdout, "> "); while (fgets(buf, sizeof(buf), stdin) != NULL && st == LAGOPUS_RESULT_OK) { (void)lagopus_str_trim_right(buf, "\r\n\t ", &cmd); if (strcasecmp(cmd, "pause") == 0 || strcasecmp(cmd, "spause") == 0) { fprintf(stdout, "Pausing... "); if ((st = lagopus_pipeline_stage_pause(&s, -1LL)) == LAGOPUS_RESULT_OK) { if (strcasecmp(cmd, "spause") == 0) { s_set(0LL); } fprintf(stdout, "Paused " PF64(u) "\n", s_get()); } else { fprintf(stdout, "Failure.\n"); } } else if (strcasecmp(cmd, "resume") == 0) { fprintf(stdout, "Resuming... "); if ((st = lagopus_pipeline_stage_resume(&s)) == LAGOPUS_RESULT_OK) { fprintf(stdout, "Resumed.\n"); } else { fprintf(stdout, "Failure.\n"); } } else if (strcasecmp(cmd, "get") == 0) { fprintf(stdout, PF64(u) "\n", s_get()); } free((void *)cmd); cmd = NULL; fprintf(stdout, "> "); } fprintf(stdout, "\nDone.\n"); fprintf(stdout, "Shutting down... "); st = lagopus_pipeline_stage_shutdown(&s, SHUTDOWN_GRACEFULLY); if (st == LAGOPUS_RESULT_OK) { fprintf(stdout, "Shutdown accepted... "); sleep(1); s_do_stop = true; fprintf(stdout, "Waiting shutdown... "); st = lagopus_pipeline_stage_wait(&s, -1LL); if (st == LAGOPUS_RESULT_OK) { fprintf(stdout, "OK, Shutdown.\n"); } } } } } } fflush(stdout); if (st != LAGOPUS_RESULT_OK) { lagopus_perror(st); } fprintf(stdout, "Destroying... "); lagopus_pipeline_stage_destroy(&s); fprintf(stdout, "Destroyed.\n"); return (st == LAGOPUS_RESULT_OK) ? 0 : 1; }
int main(int argc, const char *const argv[]) { lagopus_result_t st = LAGOPUS_RESULT_ANY_FAILURES; test_stage_t t = NULL; size_t tmp; size_t nthd = 1; size_t c_max = 1000LL * 1000LL * 100LL; size_t mod = 0; lagopus_chrono_t t_begin; lagopus_chrono_t t_end; lagopus_chrono_t t_total; (void)argc; WHAT_TIME_IS_IT_NOW_IN_NSEC(t_begin); if (IS_VALID_STRING(argv[1]) == true) { if (lagopus_str_parse_uint64(argv[1], &tmp) == LAGOPUS_RESULT_OK && tmp > 0LL) { nthd = tmp; } if (IS_VALID_STRING(argv[2]) == true) { if (lagopus_str_parse_uint64(argv[2], &tmp) == LAGOPUS_RESULT_OK && tmp > 0LL) { c_max = tmp; } if (IS_VALID_STRING(argv[3]) == true) { if (lagopus_str_parse_uint64(argv[3], &tmp) == LAGOPUS_RESULT_OK) { mod = tmp; } } } } st = lagopus_pipeline_stage_create((lagopus_pipeline_stage_t *)&t, sizeof(*t), "a_test", nthd, sizeof(void *), 1024, s_pre_pause, s_sched, s_setup, /* s_fetch, */ NULL, s_main, /* s_throw, */ NULL, s_shutdown, s_finalize, s_freeup); if (st == LAGOPUS_RESULT_OK) { t->m_n_max_count = c_max; t->m_mod = mod; st = lagopus_pipeline_stage_setup((lagopus_pipeline_stage_t *)&t); if (st == LAGOPUS_RESULT_OK) { st = lagopus_pipeline_stage_start((lagopus_pipeline_stage_t *)&t); if (st == LAGOPUS_RESULT_OK) { WHAT_TIME_IS_IT_NOW_IN_NSEC(t_begin); st = global_state_set(GLOBAL_STATE_STARTED); if (st == LAGOPUS_RESULT_OK) { sleep(1); st = lagopus_pipeline_stage_shutdown((lagopus_pipeline_stage_t *)&t, SHUTDOWN_GRACEFULLY); if (st == LAGOPUS_RESULT_OK) { st = lagopus_pipeline_stage_wait((lagopus_pipeline_stage_t *)&t, -1LL); } } } } } WHAT_TIME_IS_IT_NOW_IN_NSEC(t_end); t_total = t_end - t_begin; if (st != LAGOPUS_RESULT_OK) { lagopus_perror(st); } fprintf(stdout, "total %f sec.\n\n" "single thd throughput: %f Mops/s\n" "total throuput: %f Mops/s\n\n" "%f nsec/op\n", (double)t_total / 1000.0 / 1000.0 / 1000.0, (double)c_max / (double)t_total * 1000.0, (double)c_max * (double)nthd / (double)t_total * 1000.0, (double)t_total / (double)c_max); return (st == LAGOPUS_RESULT_OK) ? 0 : 1; }