예제 #1
0
static int xrun_recovery(snd_pcm_t *handle, int err)
{
    if (err == -EPIPE) {
        err = snd_pcm_prepare(handle);
    }

    if (err < 0) {
        db_warn("Can't recovery from underrun, prepare failed: %s\n", snd_strerror(err));
    }
    else if (err == -ESTRPIPE) {
        while ((err = snd_pcm_resume(handle)) == -EAGAIN) {
            sleep(1);

            if (err < 0) {
                err = snd_pcm_prepare(handle);
            }
            if (err < 0) {
                db_warn("Can't recovery from suspend, prepare failed: %s\n", snd_strerror(err));
            }
        }

        return 0;
    }

    return err;
}
예제 #2
0
/* C entry.
 *
 * \param argc the number of arguments.
 * \param argv the arguments.
 *
 * DO NOT CHANGES THE NAME OF PARAMETERS, otherwise your program will get 
 * a compile error if you are using INIT_CMD_PIPE macro.
 */
int main(int argc, char *argv[])
{
    char buf[128];
    char device_node_path[256];
    char call_number[128];
    int single_level;
    int setup_delay;
    int call_time;
    
    /* init cmd pipe after local variable declaration */
    INIT_CMD_PIPE();

    init_script(atoi(argv[2]));
    
    db_msg("2g tester\n");

    if(script_fetch("2g","device_node",(int*)device_node_path,sizeof(device_node_path)/4)){

        db_warn("2gtester:can't fetch device_node,set to /dev/ttyUSB0\n");
        strcpy(device_node_path,"/dev/ttyUSB0");

    }
    db_msg("device_node=%s\n",device_node_path);
    if(script_fetch("2g","call_number",(int*)call_number,sizeof(call_number)/4)){

        db_warn("2gtester:can't fetch call_number,set to 10086\n");
        strcpy(call_number,"10086");

    }
    if(script_fetch("2g","setup_delay",&setup_delay,1)){

        db_warn("2gtester:can't fetch setup_delay,set to 5s\n");
        setup_delay=5;

    }
    
    if(script_fetch("2g","call_time",&call_time,1)){

        db_warn("2gtester:can't fetch call_time,set to 30s\n");
        call_time=30;

    }

    single_level=setup_2g_device(device_node_path,setup_delay);

    if(single_level==0)
    {
        SEND_CMD_PIPE_FAIL_EX("can't get single level");
        return -1;
    }
    db_msg("single level=%d\n",single_level);
    sprintf(buf,"single level=%d dB\n",single_level);
    SEND_CMD_PIPE_OK_EX(buf);

    //make a telephone call with the specified number
    //return: 0 means ok; -1 means fail;
    if(call_number_2g_device(call_number))
    {
        SEND_CMD_PIPE_FAIL_EX("can't make a call!");
        return -1;
    }
    //call time delay,you can speak th each other in this time
    sleep(call_time);
    //
    hangup_2g_device();
    /* send OK to core if test OK, otherwise send FAIL
     * by using SEND_CMD_PIPE_FAIL().
     */
    SEND_CMD_PIPE_OK_EX("test done");

    return 0;
}
예제 #3
0
static void *sound_play(void *args)
{
    char path[256];
    int samplerate;
    int err;
    snd_pcm_t *playback_handle;
    snd_pcm_hw_params_t *hw_params;
    FILE *fp;

    db_msg("prepare play sound...\n");
    if (script_fetch("hdmi", "sound_file", (int *)path, sizeof(path) / 4)) {
        db_warn("unknown sound file, use default\n");
        strcpy(path, "/dragonboard/data/test48000.pcm");
    }
    if (script_fetch("hdmi", "samplerate", &samplerate, 1)) {
        db_warn("unknown samplerate, use default #48000\n");
        samplerate = 48000;
    }
    db_msg("samplerate #%d\n", samplerate);

    err = snd_pcm_open(&playback_handle, "hw:1,0", SND_PCM_STREAM_PLAYBACK, 0);
    if (err < 0) {
        db_error("cannot open audio device (%s)\n", snd_strerror(err));
        pthread_exit((void *)-1);
    }

    err = snd_pcm_hw_params_malloc(&hw_params);
    if (err < 0) {
        db_error("cannot allocate hardware parameter structure (%s)\n", snd_strerror(err));
        pthread_exit((void *)-1);
    }

    err = snd_pcm_hw_params_any(playback_handle, hw_params);
    if (err < 0) {
        db_error("cannot initialize hardware parameter structure (%s)\n", snd_strerror(err));
        pthread_exit((void *)-1);
    }

    err = snd_pcm_hw_params_set_access(playback_handle, hw_params, SND_PCM_ACCESS_RW_INTERLEAVED);
    if (err < 0) {
        db_error("cannot allocate hardware parameter structure (%s)\n", snd_strerror(err));
        pthread_exit((void *)-1);
    }

    err = snd_pcm_hw_params_set_format(playback_handle, hw_params, SND_PCM_FORMAT_S16_LE);
    if (err < 0) {
        db_error("cannot allocate hardware parameter structure (%s)\n", snd_strerror(err));
        pthread_exit((void *)-1);
    }

    err = snd_pcm_hw_params_set_rate(playback_handle, hw_params, samplerate, 0);
    if (err < 0) {
        db_error("cannot set sample rate (%s)\n", snd_strerror(err));
        pthread_exit((void *)-1);
    }

    err = snd_pcm_hw_params_set_channels(playback_handle, hw_params, 2);
    if (err < 0) {
        db_error("cannot set channel count (%s), err = %d\n", snd_strerror(err), err);
        pthread_exit((void *)-1);
    }

    err = snd_pcm_hw_params(playback_handle, hw_params);
    if (err < 0) {
        db_error("cannot set parameters (%s)\n", snd_strerror(err));
        pthread_exit((void *)-1);
    }

    snd_pcm_hw_params_free(hw_params);

    db_msg("open test pcm file: %s\n", path);
    fp = fopen(path, "r");
    if (fp == NULL) {
        db_error("cannot open test pcm file(%s)\n", strerror(errno));
        pthread_exit((void *)-1);
    }

    db_msg("play it...\n");
    while (1) {
        while (!feof(fp)) {
            if (sound_play_stop) {
                goto out;
            }

            err = fread(buf, 1, BUF_LEN, fp);
            if (err < 0) {
                db_warn("read test pcm failed(%s)\n", strerror(errno));
            }

            err = snd_pcm_writei(playback_handle, buf, BUF_LEN/4);
            if (err < 0) {
                err = xrun_recovery(playback_handle, err);
                if (err < 0) {
                    db_warn("write error: %s\n", snd_strerror(err));
                }
            }

            if (err == -EBADFD) {
                db_warn("PCM is not in the right state (SND_PCM_STATE_PREPARED or SND_PCM_STATE_RUNNING)\n");
            }
            if (err == -EPIPE) {
                db_warn("an underrun occurred\n");
            }
            if (err == -ESTRPIPE) {
                db_warn("a suspend event occurred (stream is suspended and waiting for an application recovery)\n");
            }

            if (feof(fp)) {
                fseek(fp, 0L, SEEK_SET);
            }
        }
    }

out:
    db_msg("play end...\n");
    fclose(fp);
    snd_pcm_close(playback_handle);
    pthread_exit(0);
}
예제 #4
0
/* C entry.
 *
 * \param argc the number of arguments.
 * \param argv the arguments.
 *
 * DO NOT CHANGES THE NAME OF PARAMETERS, otherwise your program will get 
 * a compile error if you are using INIT_CMD_PIPE macro.
 */
int main(int argc, char *argv[])
{
	char device_node_path[256];
	int setup_delay;
	int call_time;
	int loop_ctl_pipe_fd;
	int loop_mode_flag = 1;
	int ret = -1;

	/* init cmd pipe after local variable declaration */
	INIT_CMD_PIPE();

	init_script(atoi(argv[2]));
	db_msg("2glooptester\n");
	if(script_fetch("loop","device_node",(int*)device_node_path,sizeof(device_node_path)/4)){
		db_warn("2glooptester:can't fetch device_node,set to /dev/ttyUSB0\n");
		strcpy(device_node_path,"/dev/ttyUSB0");
	}
	db_msg("device_node=%s\n",device_node_path);

	if(script_fetch("loop","setup_delay",&setup_delay,1)){
		db_warn("2glooptester:can't fetch setup_delay,set to 5s\n");
		setup_delay=5;
	}

	if(script_fetch("loop","call_time",&call_time,1)){
		db_warn("2glooptester:can't fetch call_time,set to 30s\n");
		call_time=30;
	}
/*	single_level=setup_device(device_node_path,setup_delay);
	if(single_level==0)
	{
		SEND_CMD_PIPE_FAIL_EX("can't get single level");
		return -1;
	}*/
	
	loop_ctl_pipe_fd = open(LOOP_CTL_PIPE_NAME,O_RDONLY ,0); 					
	if(loop_ctl_pipe_fd==NULL){
		printf("2glooptester:fail to open loop_ctl_pipe\n");
	}
	setup_device(device_node_path,setup_delay);
LOOP_TEST:
	if(enter_loop_mode()){ 
		SEND_CMD_PIPE_FAIL_EX("failed:loop\n");
		return 0;
	}
	if(loop_test()){
		SEND_CMD_PIPE_FAIL_EX("failed:sound_loop\n");
		return 0;
	}
	SEND_CMD_PIPE_OK();

	//call time delay,you can speak th each other in this time
//	sleep(call_time);
//	exit_loop_mode();
	/* send OK to core if test OK, otherwise send FAIL
	 * by using SEND_CMD_PIPE_FAIL().
	 */
	SEND_CMD_PIPE_OK_EX("test done");
	while(1){
		db_msg("get loop_ctl_pipe\n");
		ret = read(loop_ctl_pipe_fd,&loop_mode_flag,sizeof(loop_mode_flag));
		if(ret == -1){
			db_msg("no data avlaible\n");
		}
		db_msg("loop mode ON \n");
		if(!loop_mode_flag){
				db_msg("exit_loop_mode\n");
				exit_loop_mode();
				break;
		}
		sleep(1);
	}
	while(1){
		ret = read(loop_ctl_pipe_fd,&loop_mode_flag,sizeof(loop_mode_flag));
		if(ret == -1){
			db_msg("no data avlaible\n");
		}
		db_msg("loop mode OFF \n");
		sleep(2);
		if(loop_mode_flag)
			goto LOOP_TEST;
	}
	close(loop_ctl_pipe_fd);
	return 0;
}
예제 #5
0
int main(int argc, char *argv[])
{
    int script_shmid;
    int ret;
    char **args;
    char binary[16] = "launcher";
    pid_t launcher_pid;
    char buffer[128];
    FILE *from_child;
    char *test_case_id_s;
    int test_case_id;
    char *result_s;
    int result;
    struct item_data it_data;
    char *exdata;
    int exdata_len;

    /* init script and view */
    db_msg("core: parse script %s...\n", SCRIPT_NAME);
    script_shmid = parse_script(SCRIPT_NAME);
    if (script_shmid == -1) {
        db_error("core: parse script failed\n");
        return -1;
    }

    db_msg("core: init script...\n");
    ret = init_script(script_shmid);
    if (ret) {
        db_error("core: init script failed(%d)\n", ret);
        return -1;
    }

    db_msg("core: init view...\n");
    ret = init_view();
    if (ret) {
        db_error("core: init view failed(%d)\n", ret);
        return -1;
    }

    /* parse and draw all test cases to view */
    db_msg("core: parse test case from script...\n");
    ret = parse_testcase();
    if (ret < 0) {
        db_error("core: parse all test case from script failed(%d)\n", ret);
        return -1;
    }
    else if (ret == 0) {
        db_warn("core: NO TEST CASE to be run\n");
        return -1;
    }

    db_msg("core: draw test case to view...\n");
    ret = draw_testcases();
    if (ret) {
        db_error("core: draw all test cases to view failed(%d)\n", ret);
        return -1;
    }
    view_sync();

    /* create named pipe */
    unlink(CMD_PIPE_NAME);
    if (mkfifo(CMD_PIPE_NAME, S_IFIFO | 0666) == -1) {
        db_error("core: mkfifo error(%s)\n", strerror(errno));
        return -1;
    }

    /* fork launcher process */
    db_msg("core: fork launcher process...\n");
    args = malloc(sizeof(char *) * 6);
    args[0] = binary;
    args[1] = malloc(10);
    sprintf(args[1], "%d", DRAGONBOARD_VERSION);
    args[2] = malloc(10);
    sprintf(args[2], "%d", script_shmid);
    args[3] = malloc(10);
    sprintf(args[3], "%d", total_testcases);
    args[4] = malloc(10);
    sprintf(args[4], "%d", base_info_shmid);
    args[5] = NULL;

    launcher_pid = fork();
    if (launcher_pid < 0) {
        db_error("core: fork launcher process failed(%s)\n", strerror(errno));
    }
    else if (launcher_pid == 0) {
        execvp(binary, args);
        db_error("core: can't run %s(%s)\n", binary, strerror(errno));
        _exit(-1);
    }

    /* listening to child process */
    db_msg("core: listening to child process, starting...\n");
    from_child = fopen(CMD_PIPE_NAME, "r");
    while (1) {
        if (fgets(buffer, sizeof(buffer), from_child) == NULL) {
            continue;
        }

        db_dump("core: command from child: %s", buffer);

        /* test completion */
        test_case_id_s = strtok(buffer, " \n");
        db_dump("test case id #%s\n", test_case_id_s);
        if (strcmp(buffer, TEST_COMPLETION) == 0)
            break;

        if (test_case_id_s == NULL)
            continue;
        test_case_id = atoi(test_case_id_s);

        result_s = strtok(NULL, " \n");
        db_dump("result: %s\n", result_s);
        if (result_s == NULL)
            continue;
        result = atoi(result_s);

        exdata = strtok(NULL, "\n");

        db_dump("%s TEST %s\n", base_info[test_case_id].name, 
                (result == 0) ? "OK" : "Fail");

        /* update view item */
        memset(&it_data, 0, sizeof(struct item_data));
        strncpy(it_data.name, base_info[test_case_id].name, 32);
        strncpy(it_data.display_name, base_info[test_case_id].display_name, 64);
        it_data.category = base_info[test_case_id].category;
        it_data.status = result;
        if (exdata) {
            /* trim space */
            while (*exdata == ' ' || *exdata == '\t')
                exdata++;
            exdata_len = strlen(exdata);
            exdata_len--;
            while (exdata >= 0 && (exdata[exdata_len] == ' ' || 
                   exdata[exdata_len] == '\t'))
                exdata_len--;

            if (exdata_len > 0) {
                exdata[++exdata_len] = '\0';
                db_dump("extra data len #%d: %s\n", exdata_len, exdata);
                strncpy(it_data.exdata, exdata, 64);
            }
        }
        view_update_item(test_case_id, &it_data);
    }
    fclose(from_child);

    db_msg("core: listening to child process, stoping...\n");

    deparse_testcase();
    exit_view();
    deinit_script();
    deparse_script(script_shmid);

    return 0;
}
예제 #6
0
int main(int argc, char *argv[])
{
	unsigned int args[4] = {0};
	int test_status = 0; // 1: sucessed
	int dev_status = 0;  // 1: opended
	int retry = 0;
	int flags = 0;
	int ret;
	pthread_t tid;
    disp_output_type output_type;
	int hdmi_status;
	int mic_activated;
	INIT_CMD_PIPE();

	init_script(atoi(argv[2]));

	disp = open("/dev/disp", O_RDWR);
	if (disp == -1) {
		db_error("tvtester: open /dev/disp failed(%s)\n", strerror(errno));
		goto err;
	}

	if(script_fetch("mic", "activated", &mic_activated,1))
	{
		mic_activated = 0;
	}
	/* test main loop */
	while (1)
	{
		args[0] = 1;
		output_type = getCurrentOutputType();
		hdmi_status = isHdmiPluged();
		if (hdmi_status != 1)
		{
			if (retry < 3) 
			{
				retry++;
				sleep(1);
				continue;
			}
			
			if (test_status == 1)
			{
				sleep(1);
				db_warn("TV: HPD!\n");
				continue;
			}

			if(DISP_OUTPUT_TYPE_NONE == output_type)
			{
				db_warn("then open tv\n");
				args[0] = 0;
				args[1] = output_type;
				//ret = ioctl(disp, DISP_CMD_TV_SET_MODE, args);
				ret = 0;
				if (ret < 0) 
				{
					db_error("tvtester: set tv output mode failed(%d)\n", ret);
					goto err;
				}
				//init_layer(tv_format);
				if(dev_status == 0)
				{
					//ret = ioctl(disp, DISP_CMD_TV_ON, args);
					ret = 0;
					if (ret < 0) 
					{
						db_error("tvtester: open tv failed(%d)\n", ret);
						goto err;
					}
					dev_status = 1;
				}
			}
			else if(DISP_OUTPUT_TYPE_TV == output_type)
			{
				dev_status = 1;
			}
			else
			{
				db_error("other display device runing! ,output_type[%d]\n", output_type);
				sleep(3);
				continue;
			}

			db_warn("tvtester: mic_activated[%d]\n", mic_activated);
			if(!mic_activated)
			{
				// create sound play thread
				sound_play_stop = 0;
				ret = pthread_create(&tid, NULL, sound_play, NULL);
				if (ret != 0) 
				{
					db_error("tvtester: create sound play thread failed\n");
					//ioctl(disp, DISP_CMD_TV_OFF, args);
					goto err;
				}
				mic_activated = 1;
			}
			test_status = 1;
			SEND_CMD_PIPE_OK();
		}
		else
		{
			void *retval;  
			//db_warn("tvtester: output_type[%d] is not tv!\n", output_type);

			// reset retry to 0      
			retry = 0;
			        
			if (flags < 3)
			{   
				flags++;        
				sleep(1);        
				continue;        
			}
			
			test_status = 0;
			
			if((dev_status == 1) || (output_type == DISP_OUTPUT_TYPE_TV))
			{
				args[0] = 0;
				//ret = ioctl(disp, DISP_CMD_TV_OFF, args);
				ret = 0;
			    if (ret < 0) 
			    {
				    db_error("tvtester: close tv failed(%d)\n", ret);
			    }
				dev_status = 0;
			}
			
			if(mic_activated)
			{
				// end sound play thread 
				sound_play_stop = 1;
				db_msg("tvtester: waiting for sound play thread finish...\n");
				if (pthread_join(tid, &retval)) 
				{  
					db_error("tvtester: can't join with sound play thread\n"); 
				}        
				db_msg("tvtester: sound play thread exit code #%d\n", (int)retval);
				mic_activated = 0;
			}
		}

		// sleep 1 second
		sleep(1);
	}

err:
	SEND_CMD_PIPE_FAIL();
	//exit_layer();
	close(disp);
	deinit_script();
	return -1;
}
예제 #7
0
int main(int argc, char *argv[])
{
    char dev_path[64];
    int fd;
    int x=0;
    int y=0;
    int z=0;
    struct input_event event;
    char buf[64];
    char class_path[256];
    int ret;
    
    INIT_CMD_PIPE();

	if(sensor_get_class_path(class_path,argv[4]) < 0) {
		db_error("can't get the sensor class path\n");
        goto err;	
	}

	ret=sprintf(buf,"%d",1);
	if(0!=set_sysfs_input_attr(class_path,"enable",buf,ret)){
	  	db_warn("can't set sensor enable!!! (%s)\n", strerror(errno));
	}
	  
    fd=open_input_device(argv[4]);
    if (fd== -1) {
            db_error("can't open %s(%s)\n",argv[4], strerror(errno));
            goto err;
    }
    /*
    strncpy(dev_path, "/dev/input/event2", 64);

        fd= open(dev_path, O_RDONLY);
        if (fd== -1) {
            db_error("can't open %s(%s)\n", dev_path, strerror(errno));
            goto err;
        }
    */    
        while(1){
        	ret = read(fd, &event, sizeof(event));
        	if(ret==-1){
        		db_error("can't read %s(%s)\n", dev_path, strerror(errno));
        		goto err;
        		}
       if (event.type == EV_ABS) {

			  	switch (event.code) {
		 	   	case ABS_X:
				    x =event.value;
             	  //db_msg("senser data is: x=%d\n",x);
                         break;
				case ABS_Y:
					y =event.value;
                  // db_msg("senser date is: y=%d\n",y);
					break;				
				case ABS_Z:
					z =event.value;
                 //   db_msg("senser date is:z=%d\n",z);
					break;		
					}
				sprintf(buf,"(%d,%d,%d)",x,y,z);
			  //db_msg("senser data is:x=%d,y=%d,z=%d\n",x,y,z);
				SEND_CMD_PIPE_OK_EX(buf);
                }
        	
       sleep(1);

    }
     close(fd);
err:
    SEND_CMD_PIPE_FAIL();
    EXIT_CMD_PIPE();
    return 0;
}