void test_lagopus_pipeline_stage_destroy_null(void) { lagopus_pipeline_stage_t stage = NULL; /* call func. */ lagopus_pipeline_stage_destroy(NULL); lagopus_pipeline_stage_destroy(&stage); }
void test_lagopus_pipeline_stage_create_already_exists(void) { lagopus_result_t ret = LAGOPUS_RESULT_ANY_FAILURES; lagopus_pipeline_stage_t stage1 = NULL; lagopus_pipeline_stage_t stage2 = NULL; size_t nthd = 1; /* set data */ ret = lagopus_pipeline_stage_create(&stage1, 0, "lagopus_pipeline_stage_create", nthd, sizeof(void *), 1024, pipeline_pre_pause, pipeline_sched, pipeline_setup, pipeline_fetch, pipeline_main, pipeline_throw, pipeline_shutdown, pipeline_finalize, pipeline_freeup); TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_OK, ret, "lagopus_pipeline_stage_create error."); TEST_ASSERT_NOT_EQUAL_MESSAGE(NULL, stage1, "stage is NULL."); /* call func. */ ret = lagopus_pipeline_stage_create(&stage2, 0, "lagopus_pipeline_stage_create", nthd, sizeof(void *), 1024, pipeline_pre_pause, pipeline_sched, pipeline_setup, pipeline_fetch, pipeline_main, pipeline_throw, pipeline_shutdown, pipeline_finalize, pipeline_freeup); TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_ALREADY_EXISTS, ret, "not already exists."); TEST_ASSERT_EQUAL_MESSAGE(NULL, stage2, "stage is NULL."); /* after. */ lagopus_pipeline_stage_destroy(&stage1); lagopus_pipeline_stage_destroy(&stage2); }
void test_lagopus_pipeline_stage_shutdown_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); ret = lagopus_pipeline_stage_shutdown(&stage, SHUTDOWN_GRACEFULLY); TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_OK, ret, "lagopus_pipeline_stage_shutdown(normal) error."); do_stop = true; ret = lagopus_pipeline_stage_wait(&stage, PWAIT_TIME_OUT); TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_OK, ret, "lagopus_pipeline_stage_wait error."); /* call func (double call). */ ret = lagopus_pipeline_stage_shutdown(&stage, SHUTDOWN_GRACEFULLY); TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_INVALID_STATE_TRANSITION, ret, "lagopus_pipeline_stage_shutdown(double call) error."); /* after. */ lagopus_pipeline_stage_destroy(&stage); }
void test_lagopus_pipeline_stage_shutdown_wait_normal_func_null(void) { lagopus_result_t ret = LAGOPUS_RESULT_ANY_FAILURES; uint64_t counter[PIPELINE_FUNC_MAX] = {0, 0, 0, 1, 1, 1, 0, 0, 0, 0}; 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, NULL, NULL, pipeline_freeup); /* call func. */ ret = lagopus_pipeline_stage_shutdown(&stage, SHUTDOWN_GRACEFULLY); TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_OK, ret, "lagopus_pipeline_stage_shutdown(normal) error."); do_stop = true; ret = lagopus_pipeline_stage_wait(&stage, PWAIT_TIME_OUT); TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_OK, ret, "lagopus_pipeline_stage_wait error."); TEST_ASSERT_COUNTER(true, counter, "counter error."); /* after. */ lagopus_pipeline_stage_destroy(&stage); }
void test_lagopus_pipeline_stage_start_normal_m(void) { lagopus_result_t ret = LAGOPUS_RESULT_ANY_FAILURES; uint64_t counter[PIPELINE_FUNC_MAX] = {0, 0, 0, 0, 1, 0, 0, 0, 0, 0}; lagopus_pipeline_stage_t stage = NULL; pipeline_stage_create_start(&stage, pipeline_pre_pause, pipeline_sched, pipeline_setup, NULL, pipeline_main, NULL, pipeline_shutdown, pipeline_finalize, pipeline_freeup); TEST_ASSERT_COUNTER(true, counter, "counter 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); }
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_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_schedule_maintenance_invalid_state_transition( 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); /* call func (invalid state transition). */ ret = lagopus_pipeline_stage_schedule_maintenance(&stage, pipeline_maint, NULL); TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_INVALID_STATE_TRANSITION, ret, "lagopus_pipeline_stage_schedule_maintenance" "(invalid state transition) error."); /* after. */ do_stop = true; lagopus_pipeline_stage_destroy(&stage); }
void test_lagopus_pipeline_stage_cancel_janitor_normal(void) { uint64_t counter[PIPELINE_FUNC_MAX] = {0, 0, 0, 1, 1, 1, 0, 0, 0, 0}; 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 (normal). */ lagopus_pipeline_stage_cancel_janitor(&stage); TEST_ASSERT_COUNTER(true, counter, "counter error."); /* after. */ do_stop = true; lagopus_pipeline_stage_destroy(&stage); }
void test_lagopus_pipeline_stage_destroy_double_call(void) { 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); lagopus_pipeline_stage_destroy(&stage); /* call func (double call). */ lagopus_pipeline_stage_destroy(&stage); }
void test_lagopus_pipeline_stage_shutdown_null(void) { lagopus_result_t ret = LAGOPUS_RESULT_ANY_FAILURES; lagopus_pipeline_stage_t stage = NULL; ret = lagopus_pipeline_stage_shutdown(NULL, SHUTDOWN_GRACEFULLY); TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_INVALID_ARGS, ret, "lagopus_pipeline_stage_shutdown(null) error."); ret = lagopus_pipeline_stage_shutdown(&stage, SHUTDOWN_GRACEFULLY); TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_INVALID_ARGS, ret, "lagopus_pipeline_stage_shutdown(null) error."); /* after. */ lagopus_pipeline_stage_destroy(&stage); }
void test_lagopus_pipeline_stage_create_destroy_normal(void) { uint64_t counter[PIPELINE_FUNC_MAX] = {0, 0, 0, 0, 0, 0, 0, 0, 1, 0}; lagopus_pipeline_stage_t stage = NULL; pipeline_stage_create(&stage, pipeline_pre_pause, pipeline_sched, pipeline_setup, pipeline_fetch, pipeline_main, pipeline_throw, pipeline_shutdown, pipeline_finalize, pipeline_freeup); lagopus_pipeline_stage_destroy(&stage); TEST_ASSERT_COUNTER(true, counter, "counter error."); }
void test_lagopus_pipeline_stage_find_normal(void) { lagopus_result_t ret = LAGOPUS_RESULT_ANY_FAILURES; lagopus_pipeline_stage_t stage = NULL; lagopus_pipeline_stage_t ret_stage1 = NULL; lagopus_pipeline_stage_t ret_stage2 = 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 (normal - found). */ ret = lagopus_pipeline_stage_find("lagopus_pipeline_stage_create", &ret_stage1); TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_OK, ret, "lagopus_pipeline_stage_find(normal - found) error."); TEST_ASSERT_NOT_EQUAL_MESSAGE(NULL, ret_stage1, "ret_stage is NULL."); /* call func (normal - not found). */ ret = lagopus_pipeline_stage_find("test_not_found", &ret_stage2); TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_NOT_FOUND, ret, "lagopus_pipeline_stage_find(normal- not found) " "error."); TEST_ASSERT_EQUAL_MESSAGE(NULL, ret_stage2, "ret_stage is not NULL."); /* after. */ do_stop = true; lagopus_pipeline_stage_destroy(&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; }
void test_lagopus_pipeline_stage_create_invalid_args(void) { lagopus_result_t ret = LAGOPUS_RESULT_ANY_FAILURES; lagopus_pipeline_stage_t stage = NULL; size_t nthd = 1; ret = lagopus_pipeline_stage_create(NULL, 0, "test_error", nthd, sizeof(void *), 1024, pipeline_pre_pause, pipeline_sched, pipeline_setup, pipeline_fetch, pipeline_main, pipeline_throw, pipeline_shutdown, pipeline_finalize, pipeline_freeup); TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_INVALID_ARGS, ret, "not invalid args."); ret = lagopus_pipeline_stage_create(&stage, 0, "", nthd, sizeof(void *), 1024, pipeline_pre_pause, pipeline_sched, pipeline_setup, pipeline_fetch, pipeline_main, pipeline_throw, pipeline_shutdown, pipeline_finalize, pipeline_freeup); TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_INVALID_ARGS, ret, "not invalid args."); ret = lagopus_pipeline_stage_create(&stage, 0, "test_error", nthd, 0, 1024, pipeline_pre_pause, pipeline_sched, pipeline_setup, pipeline_fetch, pipeline_main, pipeline_throw, pipeline_shutdown, pipeline_finalize, pipeline_freeup); TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_INVALID_ARGS, ret, "not invalid args."); ret = lagopus_pipeline_stage_create(&stage, 0, "test_error", nthd, sizeof(void *), 0, pipeline_pre_pause, pipeline_sched, pipeline_setup, pipeline_fetch, pipeline_main, pipeline_throw, pipeline_shutdown, pipeline_finalize, pipeline_freeup); TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_INVALID_ARGS, ret, "not invalid args."); ret = lagopus_pipeline_stage_create(&stage, 0, "test_error", nthd, sizeof(void *), 1024, pipeline_pre_pause, NULL, pipeline_setup, pipeline_fetch, pipeline_main, pipeline_throw, pipeline_shutdown, pipeline_finalize, pipeline_freeup); TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_INVALID_ARGS, ret, "not invalid args."); ret = lagopus_pipeline_stage_create(&stage, 0, "test_error", nthd, sizeof(void *), 1024, pipeline_pre_pause, pipeline_sched, pipeline_setup, pipeline_fetch, NULL, pipeline_throw, pipeline_shutdown, pipeline_finalize, pipeline_freeup); TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_INVALID_ARGS, ret, "not invalid args."); ret = lagopus_pipeline_stage_create(&stage, 0, "test_error", nthd, sizeof(void *), 1024, pipeline_pre_pause, pipeline_sched, pipeline_setup, NULL, NULL, pipeline_throw, pipeline_shutdown, pipeline_finalize, pipeline_freeup); TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_INVALID_ARGS, ret, "not invalid args."); ret = lagopus_pipeline_stage_create(&stage, 0, "test_error", nthd, sizeof(void *), 1024, pipeline_pre_pause, pipeline_sched, pipeline_setup, pipeline_fetch, NULL, NULL, pipeline_shutdown, pipeline_finalize, pipeline_freeup); TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_INVALID_ARGS, ret, "not invalid args."); ret = lagopus_pipeline_stage_create(&stage, 0, "test_error", nthd, sizeof(void *), 1024, pipeline_pre_pause, pipeline_sched, pipeline_setup, NULL, NULL, NULL, pipeline_shutdown, pipeline_finalize, pipeline_freeup); TEST_ASSERT_EQUAL_MESSAGE(LAGOPUS_RESULT_INVALID_ARGS, ret, "not invalid args."); /* after. */ lagopus_pipeline_stage_destroy(&stage); }