Exemple #1
0
static void tc_pthread_pthread_sigmask(void)
{
	int ret_chk;
	pid_t pid = getpid();

	sigset_t st_newmask;
	sigset_t st_oldmask;
	sigset_t st_pendmask;
	struct timespec st_timespec;
	struct sigaction st_act;
	struct sigaction st_oact;

	g_sig_handle = false;

	st_timespec.tv_sec = SEC_5;
	st_timespec.tv_nsec = 0;

	memset(&st_act, 0, sizeof(st_act));
	st_act.sa_handler = sigmask_handler;

	ret_chk = sigaction(SIGQUIT, &st_act, &st_oact);
	TC_ASSERT_EQ("signaction", ret_chk, OK);

	sigemptyset(&st_newmask);
	sigaddset(&st_newmask, SIGQUIT);

	ret_chk = pthread_sigmask(SIG_BLOCK, &st_newmask, &st_oldmask);
	TC_ASSERT_GEQ("pthread_sigmask", ret_chk, 0);

	nanosleep(&st_timespec, NULL);

	kill(pid, SIGQUIT);
	/* to call the handler function for verifying the sigpromask */
	ret_chk = pthread_sigmask(SIG_SETMASK, &st_oldmask, NULL);
	TC_ASSERT_GEQ("pthread_sigmask", ret_chk, 0);

	st_timespec.tv_sec = 1;

	nanosleep(&st_timespec, NULL);

	ret_chk = pthread_sigmask(SIG_UNBLOCK, &st_oldmask, NULL);
	TC_ASSERT_GEQ("pthread_sigmask", ret_chk, 0);

	ret_chk = sigpending(&st_pendmask);
	TC_ASSERT_GEQ("sigpending", ret_chk, 0);

	nanosleep(&st_timespec, NULL);
	TC_ASSERT("pthread_sigmask", g_sig_handle);

	ret_chk = sigaction(SIGQUIT, &st_oact, NULL);
	TC_ASSERT_EQ("signaction", ret_chk, OK);

	TC_SUCCESS_RESULT();
}
Exemple #2
0
void tc_fs_procfs_main(void)
{
	int ret;

	ret = mount(NULL, PROC_MOUNTPOINT, "procfs", 0, NULL);
	TC_ASSERT("mount", ret == OK || errno == EEXIST);

	ret = read_dir_entries(PROC_MOUNTPOINT);
	TC_ASSERT_EQ("read_dir_entries", ret, OK);

	TC_SUCCESS_RESULT();
}
Exemple #3
0
/**
* @fn                   :tc_pthread_pthread_timed_wait
* @brief                :function shall block on a condition variable.
* @Scenario             :function is called with mutex locked by the calling thread or undefined behavior results.
* API's covered         :pthread_create, pthread_join, pthread_mutex_init, pthread_mutex_destroy, pthread_cond_init, pthread_cond_destroy, pthread_cond_timedwait
* Preconditions         :none
* Postconditions        :none
* @return               :void
 */
static void tc_pthread_pthread_timed_wait(void)
{
	int ret_chk;
	pthread_t waiter;
	pthread_attr_t attr;
	struct sched_param sparam;
	void *result;
	int prio_max;

	/* Initialize the mutex */
	g_bpthreadcallback = false;
	ret_chk = pthread_mutex_init(&g_mutex_timedwait, NULL);
	TC_ASSERT_EQ("pthread_mutex_init", ret_chk, OK);

	/* Initialize the condition variable */

	ret_chk = pthread_cond_init(&cond, NULL);
	TC_ASSERT_EQ("pthread_cond_init", ret_chk, OK);

	/* Start the waiter thread at higher priority */

	ret_chk = pthread_attr_init(&attr);
	TC_ASSERT_EQ("pthread_attr_init", ret_chk, OK);

	prio_max = sched_get_priority_max(SCHED_FIFO);
	ret_chk = sched_getparam(getpid(), &sparam);
	if (ret_chk != OK) {
		sparam.sched_priority = PTHREAD_DEFAULT_PRIORITY;
	}

	sparam.sched_priority = (prio_max + sparam.sched_priority) / 2;
	ret_chk = pthread_attr_setschedparam(&attr, &sparam);
	TC_ASSERT_EQ("pthread_attr_setschedparam", ret_chk, OK);

	ret_chk = pthread_create(&waiter, &attr, thread_waiter, NULL);
	TC_ASSERT_EQ("pthread_create", ret_chk, OK);

	TC_ASSERT("pthread_create", g_bpthreadcallback);

	ret_chk = pthread_join(waiter, &result);
	TC_ASSERT_EQ("pthread_join", ret_chk, OK);

	TC_SUCCESS_RESULT();
}
Exemple #4
0
/**
* @fn                   :tc_pthread_pthread_cancel_setcancelstate
* @brief                :set  cancelability state and type and sends a cancellation request to a thread
* @Scenario             :The pthread_setcancelstate() sets the cancelability state of the calling
*                        thread to the value given in state. The pthread_cancel() function sends a cancellation request to the thread thread.
*                        Whether and when the target thread reacts to the cancellation request depends
*                        on two attributes that are under the control of that thread:
*                        its cancelability state and type
* API's covered         :pthread_setcancelstate, pthread_cancel
* Preconditions         :none
* Postconditions        :none
* @return               :void
*/
static void tc_pthread_pthread_cancel_setcancelstate(void)
{
	int ret_chk;
	g_bpthreadcallback = false;

	ret_chk = pthread_create(&g_thread1, NULL, cancel_state_func, NULL);
	TC_ASSERT_EQ_CLEANUP("pthread_create", ret_chk, OK, pthread_detach(g_thread1));

	sleep(SEC_1);
	/* this cancel request goes to pending if cancel is disabled */
	ret_chk = pthread_cancel(g_thread1);
	TC_ASSERT_EQ_CLEANUP("pthread_cancel", ret_chk, OK, pthread_detach(g_thread1));

	sleep(SEC_3);
	TC_ASSERT("pthread_cancel", g_bpthreadcallback);

	ret_chk = pthread_detach(g_thread1);
	TC_ASSERT_EQ("pthread_detach", ret_chk, OK);

	TC_SUCCESS_RESULT();
}
void exit_handler(void *info)
{
	if (strncmp((char *)info, EXIT_CB_CHECK_STR, strlen(EXIT_CB_CHECK_STR) + 1) != 0) {
		TC_ASSERT("task_manager_set_exit_cb", false);
	}
}
tc_result_t pdc_make_ussd_request()
{
    tc_result_t tc_result = TC_RESULT_OK;
    cn_error_code_t result = 0;
    cn_message_t *msg_p = NULL;
    cn_uint32_t size = 0;

    /* Enable pdc checking */
    \
    g_tf_pdc_check_enabled = TRUE;
    \

    /* Create and initialize an ussd request struct: */
    /*************************************************/
    cn_ussd_info_t ussd_info;
    memset(&ussd_info, 0, sizeof(cn_ussd_info_t));
    ussd_info.type = 0xFF; /* Not used value in cn_request_ussd call */
    ussd_info.received_type = 0xFF; /* Not used value in cn_request_ussd call */
    ussd_info.length = 4;
    ussd_info.dcs = 42;
    ussd_info.sat_initiated = true;
    ussd_info.me_initiated = false;
    memmove(ussd_info.ussd_string, "USSD", 4);

    /* Prepare struct to be used for retrieving ussd call data */
    /***********************************************************/
    mal_ss_ussd_data *actual_mal_ussd_p = (mal_ss_ussd_data *) calloc(1, sizeof(*actual_mal_ussd_p));
    g_mal_request_data_p = actual_mal_ussd_p;

    /* Send CN_REQUEST_USSD */
    result = cn_request_ussd(g_context_p, &ussd_info, (cn_client_tag_t) 77);

    /* ECC should be skipped as it is no voicecall */
    /* FDN should be skipped as it is sat-initiated */

    /* Wait for select to finish, then check that a request for call control availability has been sent: */
    WAIT_FOR_SELECT_TO_FINISH();
    TC_ASSERT(SIM_SERVICE_TYPE_CALL_CONTROL == g_ste_uicc_get_service_availability__sim_service_type);


    /* Generate callback from ste_uicc_get_service_availability */
    /************************************************************/
    ste_uicc_get_service_availability_response_t ust_response;
    memset(&ust_response, 0, sizeof(ste_uicc_get_service_availability_response_t));
    ust_response.service_availability = STE_UICC_SERVICE_AVAILABLE;
    ust_response.uicc_status_code = STE_UICC_STATUS_CODE_OK;
    sim_client_callback(STE_UICC_CAUSE_REQ_GET_SERVICE_AVAILABILITY, (uintptr_t)g_sim_client_tag_p, &ust_response, NULL);

    /* Check that a request to ste_cat_call_control has been sent: */
    TC_ASSERT(1 == g_ste_cat_call_control__int);

    /* Generate callback from ste_cat_call_control, replacing the USSD string */
    /**************************************************************************/
    char *cc_number_p = "USSR";
    uint8_t new_dcs = 41;
    ste_cat_call_control_response_t sat_cc_response;
    memset(&sat_cc_response, 0, sizeof(ste_cat_call_control_response_t));
    sat_cc_response.cc_result = STE_CAT_CC_ALLOWED_WITH_MODIFICATIONS;
    sat_cc_response.cc_info.cc_type = STE_CAT_CC_USSD;
    sat_cc_response.cc_info.cc_data.ussd_p = calloc(1, sizeof(ste_cat_cc_ussd_t));
    sat_cc_response.cc_info.cc_data.ussd_p->ussd_data.dcs = new_dcs;
    sat_cc_response.cc_info.cc_data.ussd_p->ussd_data.dialled_string_p = calloc(1, sizeof(ste_sim_string_t));
    sat_cc_response.cc_info.cc_data.ussd_p->ussd_data.dialled_string_p->text_coding = STE_SIM_ASCII8;
    sat_cc_response.cc_info.cc_data.ussd_p->ussd_data.dialled_string_p->no_of_bytes = strlen(cc_number_p);
    sat_cc_response.cc_info.cc_data.ussd_p->ussd_data.dialled_string_p->str_p = calloc(1, strlen(cc_number_p) + 1);
    memmove(sat_cc_response.cc_info.cc_data.ussd_p->ussd_data.dialled_string_p->str_p, cc_number_p, strlen(cc_number_p));

    sim_client_callback(STE_CAT_CAUSE_SIM_EC_CALL_CONTROL, (uintptr_t)g_sim_client_tag_p, &sat_cc_response, NULL);

    /* Free the memory allocated for the response */
    free(sat_cc_response.cc_info.cc_data.ussd_p->ussd_data.dialled_string_p->str_p);
    free(sat_cc_response.cc_info.cc_data.ussd_p->ussd_data.dialled_string_p);
    free(sat_cc_response.cc_info.cc_data.ussd_p);

    /* Generate callback from MAL, indicating that the USSD command has been performed */
    /***********************************************************************************/
    call_event_callback(MAL_SS_GSM_USSD_SEND_RESP, NULL, MAL_SUCCESS, g_mal_client_tag_p);

    /* Receive response and verify validity */
    /****************************************/
    WAIT_FOR_MESSAGE(g_request_fd);
    result = cn_message_receive(g_request_fd, &size, &msg_p);

    if (CN_SUCCESS != result) {
        CN_LOG_E("pdc_make_ss_request failed!");
        SET_TC_RESULT_AND_GOTO_EXIT(TC_RESULT_FAILED);
    }

    /* Check USSD parameters used to call SIM */
    TC_ASSERT(strlen(cc_number_p) == actual_mal_ussd_p->length);
    TC_ASSERT(new_dcs == actual_mal_ussd_p->dcs);
    TC_ASSERT(memcmp(cc_number_p, g_ussd_string, strlen(cc_number_p)) == 0);

    /* Check USSD call response */
    TC_ASSERT(CN_RESPONSE_USSD == msg_p->type);
    TC_ASSERT(CN_SUCCESS == msg_p->error_code);
    TC_ASSERT((cn_client_tag_t) 77 == msg_p->client_tag);

exit:
    free(msg_p);
    free(actual_mal_ussd_p);
    g_tf_pdc_check_enabled = FALSE; /* Reset pdc check enablement */
    return tc_result;
}
tc_result_t pdc_make_ss_request_negative_2()
{
    tc_result_t tc_result = TC_RESULT_OK;
    cn_error_code_t result = 0;
    cn_message_t *msg_p = NULL;
    cn_uint32_t size = 0;

    /* Enable pdc checking */
    \
    g_tf_pdc_check_enabled = TRUE;
    \

    /* Make struct containing data to the call: */
    cn_call_forward_info_t call_forward_info;
    memset(&call_forward_info, 0, sizeof(cn_call_forward_info_t));

    /* Call cn_request_query_call_forward, starting the sequence */
    /***********************************************/
    result = cn_request_query_call_forward(g_context_p, &call_forward_info, (cn_client_tag_t) 45);

    if (CN_SUCCESS != result) {
        CN_LOG_E("pdc_make_ss_request failed! Response = %d", result);
        SET_TC_RESULT_AND_GOTO_EXIT(TC_RESULT_FAILED);
    }

    /* FDN availability will be requested first (ECC skipped as it is no voice call.
     * Wait for select to finish, then check variables: */
    WAIT_FOR_SELECT_TO_FINISH();
    TC_ASSERT(SIM_SERVICE_TYPE_FDN == g_ste_uicc_get_service_availability__sim_service_type);

    /* Generate callback from ste_uicc_get_service_availability */
    /************************************************************/
    ste_uicc_get_service_availability_response_t ust_response;
    memset(&ust_response, 0, sizeof(ste_uicc_get_service_availability_response_t));
    ust_response.service_availability = STE_UICC_SERVICE_NOT_AVAILABLE;
    ust_response.uicc_status_code = STE_UICC_STATUS_CODE_OK;
    sim_client_callback(STE_UICC_CAUSE_REQ_GET_SERVICE_AVAILABILITY, (uintptr_t)g_sim_client_tag_p, &ust_response, NULL);

    /* Check that a request for call control availability has been sent: */
    TC_ASSERT(SIM_SERVICE_TYPE_CALL_CONTROL == g_ste_uicc_get_service_availability__sim_service_type);

    /* Generate callback from ste_uicc_get_service_availability */
    /************************************************************/
    /* NB! The same response struct is used as when FDN requested information from UST file. */
    ust_response.service_availability = STE_UICC_SERVICE_AVAILABLE;
    sim_client_callback(STE_UICC_CAUSE_REQ_GET_SERVICE_AVAILABILITY, (uintptr_t)g_sim_client_tag_p, &ust_response, NULL);

    /* Check that a request to ste_cat_call_control has been sent: */
    TC_ASSERT(1 == g_ste_cat_call_control__int);

    /* Generate callback from ste_cat_call_control, replacing the USSD string */
    /**************************************************************************/
    cn_uint8_t new_ton = STE_SIM_TON_UNKNOWN;
    cn_uint8_t new_npi = STE_SIM_NPI_UNKNOWN;

    char *cc_number_p = "*#21**0*8#";

    ste_cat_call_control_response_t sat_cc_response;
    memset(&sat_cc_response, 0, sizeof(ste_cat_call_control_response_t));
    sat_cc_response.cc_result = STE_CAT_CC_ALLOWED_WITH_MODIFICATIONS;
    sat_cc_response.cc_info.cc_type = STE_CAT_CC_SS;
    sat_cc_response.cc_info.cc_data.ss_p = calloc(1, sizeof(ste_cat_cc_ss_t));
    sat_cc_response.cc_info.cc_data.ss_p->address.ton = new_ton;
    sat_cc_response.cc_info.cc_data.ss_p->address.npi = new_npi;

    sat_cc_response.cc_info.cc_data.ss_p->address.dialled_string_p = calloc(1, sizeof(ste_sim_string_t));
    sat_cc_response.cc_info.cc_data.ss_p->address.dialled_string_p->text_coding = STE_SIM_ASCII8;
    sat_cc_response.cc_info.cc_data.ss_p->address.dialled_string_p->no_of_characters = strlen(cc_number_p);
    sat_cc_response.cc_info.cc_data.ss_p->address.dialled_string_p->text_p = calloc(1, strlen(cc_number_p) + 1);
    memmove(sat_cc_response.cc_info.cc_data.ss_p->address.dialled_string_p->text_p, cc_number_p, strlen(cc_number_p));

    sim_client_callback(STE_CAT_CAUSE_SIM_EC_CALL_CONTROL, (uintptr_t)g_sim_client_tag_p, &sat_cc_response, NULL);

    /* Free the memory allocated for the response */
    free(sat_cc_response.cc_info.cc_data.ss_p->address.dialled_string_p->text_p);
    free(sat_cc_response.cc_info.cc_data.ss_p->address.dialled_string_p);
    free(sat_cc_response.cc_info.cc_data.ss_p);

    /* Check that a request to ste_cat_call_control has been sent: */
    //TC_ASSERT(g_mal_ss_query_forward_status == 2); /* 2 = reason interrogation, i.e. query */

    /* Generate callback from mal_ss_query_call_forward ()*/
    /**************************************************/
    mal_ss_service_response service_response;
    memset(&service_response, 0, sizeof(mal_ss_service_response));
    mal_ss_call_fwd_info call_fwd_response;
    memset(&call_fwd_response, 0, sizeof(mal_ss_call_fwd_info));
    service_response.call_forward_info = &call_fwd_response;


    call_event_callback(CN_RESPONSE_QUERY_CALL_FORWARD, &service_response, MAL_NOT_SUPPORTED, g_mal_client_tag_p);

    /* Receive response and verify validity */
    /****************************************/
    WAIT_FOR_MESSAGE(g_request_fd);
    result = cn_message_receive(g_request_fd, &size, &msg_p);

    if (CN_SUCCESS != result) {
        CN_LOG_E("pdc_make_ss_request failed!");
        SET_TC_RESULT_AND_GOTO_EXIT(TC_RESULT_FAILED);
    }

exit:
    free(msg_p);
    g_tf_pdc_check_enabled = FALSE; /* Reset pdc check enablement */
    return tc_result;
}
Exemple #8
0
static void utc_spi_transfer_n(void)
{
	TC_ASSERT("iotbus_spi_transfer_buf", 0);
}
Exemple #9
0
/**
* @fn                   :tc_pthread_pthread_mutex_lock_unlock_trylock
* @brief                :The mutex object referenced by mutex is locked/unlocked by calling
*                        pthread_mutex_lock/pthread_mutex_unlock
* @Scenario             :The mutex object referenced by mutex is locked/unlocked by calling
*                        pthread_mutex_lock/pthread_mutex_unlock
* API's covered         :pthread_mutex_lock, pthread_mutex_unlock
* Preconditions         :pthread_mutex_init
* Postconditions        :pthread_mutex_destroy
* @return               :void
*/
static void tc_pthread_pthread_mutex_lock_unlock_trylock(void)
{
	int ret_chk;
	pthread_mutexattr_t attr;
	pthread_mutexattr_init(&attr);
	pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);

	pthread_mutex_init(&g_mutex, NULL);
	ret_chk = pthread_mutex_lock(&g_mutex);
	TC_ASSERT_EQ("pthread_mutex_lock", ret_chk, OK);

	ret_chk = pthread_mutex_trylock(&g_mutex);
	TC_ASSERT_EQ_CLEANUP("pthread_mutex_trylock", ret_chk, EBUSY, pthread_mutex_unlock(&g_mutex));

	ret_chk = pthread_mutex_unlock(&g_mutex);
	TC_ASSERT_EQ("pthread_mutex_unlock", ret_chk, OK);

	ret_chk = pthread_mutex_trylock(&g_mutex);
	TC_ASSERT_EQ("pthread_mutex_trylock", ret_chk, OK);

	ret_chk = pthread_mutex_unlock(&g_mutex);
	TC_ASSERT_EQ("pthread_mutex_unlock", ret_chk, OK);

	pthread_mutex_destroy(&g_mutex);

	sleep(SEC_2);

	/* initalize mutex with PTHREAD_MUTEX_RECURSIVE attribute */
	pthread_mutex_init(&g_mutex, &attr);

	ret_chk = pthread_mutex_lock(&g_mutex);
	TC_ASSERT_EQ("pthread_mutex_lock", ret_chk, OK);

	ret_chk = pthread_mutex_lock(&g_mutex);
	TC_ASSERT_EQ("pthread_mutex_lock", ret_chk, OK);

	ret_chk = pthread_mutex_unlock(&g_mutex);
	TC_ASSERT_EQ("pthread_mutex_unlock", ret_chk, OK);

	ret_chk = pthread_mutex_unlock(&g_mutex);
	TC_ASSERT_EQ("pthread_mutex_unlock", ret_chk, OK);

	/* mutex_lock mutex_unlock check through multi threads */
	g_mutex_cnt = 0;
	ret_chk = pthread_mutex_init(&g_mutex, NULL);
	TC_ASSERT_EQ("pthread_mutex_init", ret_chk, OK);

	ret_chk = pthread_create(&g_thread1, NULL, &thread_mutex, NULL);
	TC_ASSERT_EQ("pthread_create", ret_chk, OK);

	ret_chk = pthread_create(&g_thread2, NULL, &thread_mutex, NULL);
	TC_ASSERT_EQ("pthread_create", ret_chk, OK);

	pthread_join(g_thread1, NULL);
	pthread_join(g_thread2, NULL);

	TC_ASSERT("pthread_mutex_lock_unlock", g_bpthreadcallback);

	pthread_mutex_destroy(&g_mutex);

	TC_SUCCESS_RESULT();
}