void test_lagopus_pipeline_stage_setup_double_call(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_setup(&stage); TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_OK, ret, "lagopus_pipeline_stage_setup error."); /* call func. (double call) */ ret = lagopus_pipeline_stage_setup(&stage); TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_OK, ret, "double call error."); /* after. */ lagopus_pipeline_stage_destroy(&stage); }
void test_lagopus_pipeline_stage_setup_invalid_args(void) { lagopus_result_t ret = LAGOPUS_RESULT_ANY_FAILURES; lagopus_pipeline_stage_t stage = NULL; /* call func (stage is NUlL). */ ret = lagopus_pipeline_stage_setup(&stage); TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_INVALID_ARGS, ret, "not invalid args."); /* call func (arg is NUlL). */ ret = lagopus_pipeline_stage_setup(NULL); TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_INVALID_ARGS, ret, "not invalid args."); }
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); }
void test_lagopus_pipeline_stage_setup_normal(void) { lagopus_result_t ret = LAGOPUS_RESULT_ANY_FAILURES; uint64_t counter[PIPELINE_FUNC_MAX] = {0, 0, 1, 0, 0, 0, 0, 0, 0, 0}; 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); /* call func. */ ret = lagopus_pipeline_stage_setup(&stage); TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_OK, ret, "lagopus_pipeline_stage_setup(nomal) error."); TEST_ASSERT_COUNTER(true, counter, "counter error."); /* after. */ lagopus_pipeline_stage_destroy(&stage); }
void test_lagopus_pipeline_stage_setup_invalid_object(void) { lagopus_result_t ret = LAGOPUS_RESULT_ANY_FAILURES; lagopus_pipeline_stage_t stage = stage_alloc(); /* call func. */ ret = lagopus_pipeline_stage_setup(&stage); TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_INVALID_OBJECT, ret, "not invalid object."); /* afetr. */ 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; }