Exemplo n.º 1
0
expr replace_visitor::visit(expr const & e) {
    check_system("expression replacer");
    bool shared = false;
    if (is_shared(e)) {
        shared = true;
        auto it = m_cache.find(e);
        if (it != m_cache.end())
            return it->second;
    }

    switch (e.kind()) {
    case expr_kind::Sort:      return save_result(e, visit_sort(e), shared);
    case expr_kind::Macro:     return save_result(e, visit_macro(e), shared);
    case expr_kind::Constant:  return save_result(e, visit_constant(e), shared);
    case expr_kind::Var:       return save_result(e, visit_var(e), shared);
    case expr_kind::Meta:      return save_result(e, visit_meta(e), shared);
    case expr_kind::Local:     return save_result(e, visit_local(e), shared);
    case expr_kind::App:       return save_result(e, visit_app(e), shared);
    case expr_kind::Lambda:    return save_result(e, visit_lambda(e), shared);
    case expr_kind::Pi:        return save_result(e, visit_pi(e), shared);
    case expr_kind::Let:       return save_result(e, visit_let(e), shared);
    }

    lean_unreachable(); // LCOV_EXCL_LINE
}
Exemplo n.º 2
0
    expr visit(expr const & e) {
        switch (e.kind()) {
        case expr_kind::Sort:  case expr_kind::Constant:
        case expr_kind::Var:   case expr_kind::Meta:
        case expr_kind::Local:
            return e;
        default:
            break;
        }

        check_system("unfold macros");
        auto it = m_cache.find(e);
        if (it != m_cache.end())
            return it->second;

        switch (e.kind()) {
        case expr_kind::Sort:  case expr_kind::Constant:
        case expr_kind::Var:   case expr_kind::Meta:
        case expr_kind::Local:
            lean_unreachable();
        case expr_kind::Macro:
            return save_result(e, visit_macro(e));
        case expr_kind::App:
            return save_result(e, visit_app(e));
        case expr_kind::Lambda: case expr_kind::Pi:
            return save_result(e, visit_binding(e));
        }
        lean_unreachable();
    }
Exemplo n.º 3
0
int test_bcamera_start(void)
{
	volatile int  rtn = RL_FAIL;
	char lib_full_name[60] = { 0 };
	char prop[PROPERTY_VALUE_MAX] = { 0 };
	int is_show = 0;

	LOGD("enter");

	ui_clear_rows(0,20); 


	property_get("ro.board.platform", prop, NULL);
	sprintf(lib_full_name, "%scamera.%s.so", LIBRARY_PATH, prop);
	LOGD("mmitest %s",lib_full_name);
	sprd_handle_camera_dl = dlopen(lib_full_name,RTLD_NOW);
	if(sprd_handle_camera_dl == NULL){
		LOGD("fail dlopen");
		rtn = RL_FAIL;
		goto go_end;
	}

	
	typedef int (*pf_eng_tst_camera_init)(int32_t camera_id);

	pf_eng_tst_camera_init eng_tst_camera_init = (pf_eng_tst_camera_init)dlsym(sprd_handle_camera_dl,"eng_tst_camera_init" );

	if(eng_tst_camera_init){
		if(eng_tst_camera_init(0)){   //init back camera and start preview
			LOGE(" fail to call eng_test_camera_init");
		}
	}else{
		LOGE("fail to find eng_test_camera_init()");
		rtn = RL_FAIL;
		goto go_end;
	}

	flashlightSetValue(17);

	rtn = ui_handle_button(TEXT_PASS,NULL,TEXT_FAIL);//, TEXT_GOBACK

	flashlightSetValue(16);

	typedef void (*pf_eng_tst_camera_deinit)(void);
	pf_eng_tst_camera_deinit eng_tst_camera_deinit = (pf_eng_tst_camera_deinit)dlsym(sprd_handle_camera_dl,"eng_tst_camera_deinit" );
	if(eng_tst_camera_deinit){
		eng_tst_camera_deinit();   //init back camera and start preview
	}else{
		LOGE("fail to find eng_test_camera_close");
	}

go_end:
  
	save_result(CASE_TEST_BCAMERA,rtn);
	save_result(CASE_TEST_FLASH,rtn);
	return rtn;
}
Exemplo n.º 4
0
// Generate more empty grids of puzzles found in simulating process
// Their number of empty grids >= limit_empty-norm
// So the odds of finding a puzzle with limit_empty number of empty grids
// recursively by removing numbers from them are fairly high.
void generate(int n_empty){
  int i,j,k; 
  int row,col; 
  int generate_tmp[SIZE][SIZE][2]; 

  if(max_empty>=limit_empty){
    save_result(sudoku);
    return;
  }

  for(i=0; i<SIZE; ++i){ 
    for(j=0; j<SIZE; ++j){ 
      generate_tmp[i][j][1]=sudoku[i][j]; 
      generate_tmp[i][j][0]=EMPTY; 
    } 
  }
  
  for(i=0; i<=SIZE/2; ++i){ 
    for(j=0; j<SIZE && !(i==SIZE/2&&j==SIZE/2+1); ++j){ 
      if(generate_tmp[i][j][1]!=EMPTY){
	// remove numbers from (i,j) and (SIZE-1-i,SIZE-i-j)
	k=0;
	sudoku[i][j]=generate_tmp[i][j][k]; 
	sudoku[SIZE-1-i][SIZE-1-j]=generate_tmp[SIZE-1-i][SIZE-1-j][k]; 	  
	find_solution(); 
	if(n_ans==1){  
	  // Recursively generate more
	  if(i!=SIZE/2||j!=SIZE/2){
	    if(n_empty+2>max_empty)
	      max_empty=n_empty+2;
	    generate(n_empty+2);
	  }
	  else {
	    if(n_empty+1>max_empty)
	      max_empty=n_empty+1;
	    generate(n_empty+1);
	  }
	  if(max_empty>=limit_empty){
	    save_result(sudoku);
	    return;
	  }
	}
	k=1;
	sudoku[i][j]=generate_tmp[i][j][k]; 
	sudoku[SIZE-1-i][SIZE-1-j]=generate_tmp[SIZE-1-i][SIZE-1-j][k];
      }
    } 
  }
}
Exemplo n.º 5
0
void check_win_draw_joker2()
{
    RINFO.status=INROOM_STOP;
    send_msg(-1, "双方战平,再接再厉。");
    kill_msg(-1);
    save_result(0);
}
Exemplo n.º 6
0
int test_gps_start(void)
{
	int ret;
	pthread_t t1;
	int row = 2;

	ui_fill_locked();
	ui_show_title(MENU_TEST_GPS);
	ui_set_color(CL_WHITE);
	row = ui_show_text(row, 0, TEXT_WAIT_TIPS);
	gr_flip();

	ret = gpsOpen();
	if( ret < 0){
		LOGD("gps open failed ret = %d",ret);
		return -1;
	}
	gOpenTime=time(NULL);
	thread_run = 1;
	pthread_create(&t1, NULL, (void*)processThread_show, NULL);
	usleep(10*1000);
	ret = ui_handle_button(TEXT_PASS,NULL,TEXT_FAIL);//, TEXT_GOBACK
	thread_run = 0;
	pthread_join(t1,NULL);
	gpsStop();
	sleep(1);
	gpsClose();

	save_result(CASE_TEST_GPS,ret);
	return ret;
}
Exemplo n.º 7
0
int main(int argc, char **argv) {
	FILE *f = fopen(INPUT_FILE, "r");
	if (f == NULL) {
		printf("Failed to open input file: %s\n", strerror(errno));
		goto exit;
	}

	int size = 0;
	while (!feof(f)) {
		if (size > MAX_SIZE) {
			printf("Too much numbers\n");
			break;
		}
		if (fscanf(f, "%d", &(array[size])) <= 0) {
			break;
		}
		size++;
	}
	printf("Read %d numbers\n", size);

	int num_of_threads = 8; //omp_get_num_threads();
	omp_set_num_threads(num_of_threads);

	printf("Sorting numbers with %d threads\n", num_of_threads);
	sort_parallel(array, 0, size, num_of_threads);
	sort_serial(array, 0, size);

	save_result(array, size);

	fclose(f);

exit:
	return 0;
}
Exemplo n.º 8
0
double get_syscall_elapse(sc_state_t *state) {
	struct timespec st, ed;
	unsigned long elapse;
	int loopcnt, loop = 20;
	int index = loop >> 2;
	int iter, iteration = get_iteration();

	result_t *r = (result_t *)malloc(sizeof(result_t) * loop);
	loopcnt = loop;


	while(loopcnt --) {

		if(state->prepare) {
			state->prepare(state);
		}

		iter = iteration;
		clock_gettime(CLOCK_REALTIME, &st);
		while(iter--) {
			state->bench(state);
		};
		clock_gettime(CLOCK_REALTIME, &ed);
		elapse = get_total_us(&st, &ed);
		save_result(r, loopcnt, elapse, iteration);
		if(state->cooldown)
			state->cooldown(state);
	}

	qsort(r, loop, sizeof(result_t ), cmp_result);
	double latency = get_latency(r[index].elapse, r[index].iter);
	return latency;
}
Exemplo n.º 9
0
static void wireless_noise(RESULT * result, RESULT * arg1)
{
    char *dev = R2S(arg1);
    if (check_socket() != 0)
	return;

    save_result(result, dev, KEY_NOISE, get_stats(dev, KEY_NOISE));
}
Exemplo n.º 10
0
static void wireless_bitrate(RESULT * result, RESULT * arg1)
{
    char *dev = R2S(arg1);
    if (check_socket() != 0)
	return;

    save_result(result, dev, KEY_BIT_RATE, get_bitrate(dev, KEY_BIT_RATE));
}
Exemplo n.º 11
0
static void wireless_sec_mode(RESULT * result, RESULT * arg1)
{
    char *dev = R2S(arg1);
    if (check_socket() != 0)
	return;

    save_result(result, dev, KEY_SEC_MODE, get_sec_mode(dev, KEY_SEC_MODE));
}
Exemplo n.º 12
0
static void wireless_protocol(RESULT * result, RESULT * arg1)
{
    char *dev = R2S(arg1);
    if (check_socket() != 0)
	return;

    save_result(result, dev, KEY_PROTO, get_ifname(NULL, dev));
}
Exemplo n.º 13
0
static void wireless_frequency(RESULT * result, RESULT * arg1)
{
    char *dev = R2S(arg1);
    if (check_socket() != 0)
	return;

    save_result(result, dev, KEY_FREQUENCY, get_frequency(dev, KEY_FREQUENCY));
}
Exemplo n.º 14
0
static void wireless_level(RESULT * result, RESULT * arg1)
{
    char *dev = R2S(arg1);
    if (check_socket() != 0)
	return;

    save_result(result, dev, KEY_LEVEL, get_stats(dev, KEY_LEVEL));
}
Exemplo n.º 15
0
static void wireless_quality(RESULT * result, RESULT * arg1)
{
    char *dev = R2S(arg1);
    if (check_socket() != 0)
	return;

    save_result(result, dev, KEY_QUALITY, get_stats(dev, KEY_QUALITY));
}
Exemplo n.º 16
0
static void wireless_sensitivity(RESULT * result, RESULT * arg1)
{
    char *dev = R2S(arg1);
    if (check_socket() != 0)
	return;

    save_result(result, dev, KEY_SENS, get_sens(dev, KEY_SENS));
}
Exemplo n.º 17
0
static void wireless_essid(RESULT * result, RESULT * arg1)
{
    char *dev = R2S(arg1);
    if (check_socket() != 0)
	return;

    save_result(result, dev, KEY_ESSID, get_essid(dev, KEY_ESSID));
}
Exemplo n.º 18
0
void run_benchmark(struct parameters p) {
	

	init_benchmark(p);

	benchmark.mapping_size = getpagesize() * MAPPING_SIZE;
	benchmark.free_space = benchmark.mapping_size;
	benchmark.max_deallocs = p.max_allocs;

	benchmark.allocs_size = 0;

	benchmark.allocs_number = 0;
	benchmark.deallocs_number = 0;
	benchmark.runs = 0;

	benchmark.alloc_time = 0;

	int previous_allocs = 0;
	int previous_deallocs = 0;

	bool alloc_result;

	while(true) {
		benchmark.runs++;

		clock_t start_time = clock();

		alloc_result = run_allocations(p);

		clock_t end_time = clock();
		benchmark.alloc_time += end_time - start_time;

		if(!alloc_result && (benchmark.max_deallocs == 0 || !p.deallocate_after_fail))
			break;
		int old_max_deallocs = benchmark.max_deallocs;
		run_deallocations(p);
		if(DO_PRINT)
      printf("Allocs: %d | Deallocs: %d | ",
		benchmark.allocs_number - previous_allocs,
		benchmark.deallocs_number - previous_deallocs);
		if(DO_PRINT)
      printf("Running diference: %d | Max deallocs: %d\n",
		benchmark.allocs_number - benchmark.deallocs_number, old_max_deallocs);
		previous_allocs = benchmark.allocs_number;
		previous_deallocs = benchmark.deallocs_number;
	}

	save_result(p);

	if(DO_PRINT) {
    printf("TEST STOPPED\n");
  	printf("FULL DEALLOCATION\n");
  }
	run_full_deallocation();

}
Exemplo n.º 19
0
int test_gps_pretest(void)
{
	int ret;
	if(sPreTest >= 1)
		ret= RL_PASS;
	else
		ret= RL_FAIL;

	save_result(CASE_TEST_GPS,ret);
	return ret;
}
Exemplo n.º 20
0
void check_win_badwin_joker2(int mode)
{
    RINFO.status=INROOM_STOP;
    if (mode == JOKER2_WIN_BY_DECISIVE)
        send_msg(-1, "杀手一方取得大胜!");
    else if (mode == JOKER2_WIN_BY_MARGIN)
        send_msg(-1, "杀手一方取得小胜!");
    else if (mode == JOKER2_WIN_BY_ERROR)
        send_msg(-1, "警察掉线,杀手胜利。");
    kill_msg(-1);
    save_result(0);
}
Exemplo n.º 21
0
/* Create a puzzle with as many empty grids as possible
   by randomly assigning empty grids' positions.*/ 
void create(){ 
  int i,j,k;
  int tmp[SIZE][SIZE][2]; 
  int index_cnt; 
  int n_empty; 
  int s_time;

  //printf("Current biggest number of empty grids.\n");
  for(i=0; i<SIZE; ++i){ 
    for(j=0; j<SIZE; ++j){ 
      tmp[i][j][1]=sudoku[i][j]; 
      tmp[i][j][0]=EMPTY; 
    } 
  }
  for(s_time=0; s_time<S_TIME; ++s_time){
    n_empty=0;
    for(i=0; i<=SIZE/2; ++i){ 
      for(j=0; j<SIZE && !(i==SIZE/2&&j==SIZE/2+1); ++j){ 
	// P(rand_01(m,n)=0)=m/n
	// So expectancy of the number of empty grids 
	// will be max_empty+1
	k=rand_01(max_empty+1,SIZE*SIZE);
	if(i!=SIZE/2||j!=SIZE/2) 
	  n_empty+=2-2*k; 
	else 
	  n_empty+=1-k; 
	sudoku[i][j]=tmp[i][j][k]; 
	sudoku[SIZE-1-i][SIZE-1-j]=tmp[SIZE-1-i][SIZE-1-j][k]; 
      } 
    }
    if(n_empty>=limit_empty-norm && n_empty<=limit_empty && n_empty<54){ 
      find_solution(); 
      if(n_ans==1){
	if(n_empty>max_empty){
	  max_empty=n_empty;
	}
	if(max_empty>=limit_empty){
	  save_result(sudoku);
	  return;
	}
	generate(empty(sudoku));
      } 
    } 
  }

  //printf("DONE\n");  
  for(i=0; i<SIZE; ++i){ 
    for(j=0; j<SIZE; ++j){ 
      sudoku[i][j]=tmp[i][j][1];
    } 
  }
} 
Exemplo n.º 22
0
 expr apply(expr const & a) {
     bool sh = false;
     if (is_shared(a)) {
         auto r = m_cache.find(a.raw());
         if (r != m_cache.end())
             return r->second;
         sh = true;
     }
     switch (a.kind()) {
     case expr_kind::Var: case expr_kind::Constant: case expr_kind::Type: case expr_kind::Value:
         return save_result(a, copy(a), sh);
     case expr_kind::App: {
         buffer<expr> new_args;
         for (expr const & old_arg : args(a))
             new_args.push_back(apply(old_arg));
         return save_result(a, mk_app(new_args), sh);
     }
     case expr_kind::HEq:      return save_result(a, mk_heq(apply(heq_lhs(a)), apply(heq_rhs(a))), sh);
     case expr_kind::Pair:     return save_result(a, mk_pair(apply(pair_first(a)), apply(pair_second(a)), apply(pair_type(a))), sh);
     case expr_kind::Proj:     return save_result(a, mk_proj(proj_first(a), apply(proj_arg(a))), sh);
     case expr_kind::Lambda:   return save_result(a, mk_lambda(abst_name(a), apply(abst_domain(a)), apply(abst_body(a))), sh);
     case expr_kind::Pi:       return save_result(a, mk_pi(abst_name(a), apply(abst_domain(a)), apply(abst_body(a))), sh);
     case expr_kind::Sigma:    return save_result(a, mk_sigma(abst_name(a), apply(abst_domain(a)), apply(abst_body(a))), sh);
     case expr_kind::Let:      return save_result(a, mk_let(let_name(a), apply(let_type(a)), apply(let_value(a)), apply(let_body(a))), sh);
     case expr_kind::MetaVar:
         return save_result(a,
                            update_metavar(a, [&](local_entry const & e) -> local_entry {
                                    if (e.is_inst())
                                        return mk_inst(e.s(), apply(e.v()));
                                    else
                                        return e;
                                }),
                            sh);
     }
     lean_unreachable(); // LCOV_EXCL_LINE
 }
Exemplo n.º 23
0
void translator_initSingleQuery(){
    if(!buf_result){
        buf_result = (bufor) malloc(sizeof(_bufor));
        buf_where = (bufor) malloc(sizeof(_bufor));
        buf_seq_result = (bufor) malloc(sizeof(_bufor));
        buf_seq_let = (bufor) malloc(sizeof(_bufor));
        bufReset(buf_result);
        bufReset(buf_where);
        bufReset(buf_seq_result);
        bufReset(buf_seq_let);

    }else{
        save_result();
        bufAppendS(buf_result, "\n,\n");
    }
    bufAppendS(buf_result, "for $tablet in .//tablet\n");
    bufReset(buf_where);
    bufReset(buf_seq_result);
    bufReset(buf_seq_let);
}
Exemplo n.º 24
0
int test_otg_start(void)
{
    int cur_row=2;
    int ret;
    pthread_t t1;

    ui_fill_locked();
    ui_show_title(MENU_TEST_OTG);
    ui_set_color(CL_WHITE);
    ui_show_text(cur_row, 0, OTG_TEST_START);
    gr_flip();

    thread_run=1;
    pthread_create(&t1, NULL, (void*)otg_check_thread, NULL);
    usleep(10*1000);
    ret = ui_handle_button(TEXT_PASS, NULL,TEXT_FAIL);
    thread_run=0;
    pthread_join(t1, NULL);
    save_result(CASE_TEST_OTG,ret);
    return ret;
}
Exemplo n.º 25
0
static void backup( const std::string &origin_path )
{
   std::string s( origin_path );

   if ( s[s.size()-1] == '/' )
      s.resize( s.size() - 1 );

   NodeAttr na;
   if ( na.stat( s.c_str( ) ) )
   {
      NodeAttr oldAttr;
      auto succ = getLastStore( s, &oldAttr );
      BackupFs bd( na, s, succ?&oldAttr:nullptr );
      RunMt( &bd );
      if ( store_hash_set( false ) )
         save_result( bd );
   }
   else
   {
      std::cerr << "Can't stat " << s;
   }
}
Exemplo n.º 26
0
    expr apply(expr const & e, unsigned offset) {
        bool shared = false;
        if (m_use_cache && is_shared(e)) {
            if (auto r = m_cache->find(e, offset))
                return *r;
            shared = true;
        }
        check_interrupted();
        check_memory("replace");

        if (optional<expr> r = m_f(e, offset)) {
            return save_result(e, offset, *r, shared);
        } else {
            switch (e.kind()) {
            case expr_kind::Constant: case expr_kind::Sort: case expr_kind::Var:
                return save_result(e, offset, e, shared);
            case expr_kind::Meta:     case expr_kind::Local: {
                expr new_t = apply(mlocal_type(e), offset);
                return save_result(e, offset, update_mlocal(e, new_t), shared);
            }
            case expr_kind::App: {
                expr new_f = apply(app_fn(e), offset);
                expr new_a = apply(app_arg(e), offset);
                return save_result(e, offset, update_app(e, new_f, new_a), shared);
            }
            case expr_kind::Pi: case expr_kind::Lambda: {
                expr new_d = apply(binding_domain(e), offset);
                expr new_b = apply(binding_body(e), offset+1);
                return save_result(e, offset, update_binding(e, new_d, new_b), shared);
            }
            case expr_kind::Macro: {
                buffer<expr> new_args;
                unsigned nargs = macro_num_args(e);
                for (unsigned i = 0; i < nargs; i++)
                    new_args.push_back(apply(macro_arg(e, i), offset));
                return save_result(e, offset, update_macro(e, new_args.size(), new_args.data()), shared);
            }}
            lean_unreachable();
        }
    }
Exemplo n.º 27
0
char *translator_getResult(){
    save_result();
    if(buf_result!=NULL)
        return buf_result->buf;
    return "";
}
Exemplo n.º 28
0
int main_file(Parameter *pParam)
{
	char *file_list = pParam->image_list;//"/home/sean/Pictures/calib_test1/dir.txt";

	Size boardSize(8,6);
	Size imageSize;
	int   flags = CV_CALIB_FIX_ASPECT_RATIO;
	float squareSize = pParam->square_size;
	float aspectRatio = 1.f;
	Mat cameraMatrix;
	Mat distCoeffs;
	int result = 0;

	// read frames from data file
	vector<vector<Point2f> > imagePointsSet;
	vector<Point2f> imagePoints;
	vector<string>  fileNames;

	fileNames.clear();
	imagePointsSet.clear();

	getFileName(file_list, fileNames);

	for(unsigned int i = 0; i < fileNames.size(); i++)
	{
		Mat framecv;
		int found = 0;

		framecv = imread(fileNames[i].c_str(), 0);

		if(framecv.cols <= 0 || framecv.rows <= 0 || framecv.data == NULL )
		{
			printf("finish chess board detection \n");
			break;
		}

		imagePoints.clear();
		imageSize.width = framecv.cols;
		imageSize.height = framecv.rows;

		found = findChessboardCorners(
						framecv,
						boardSize,
						imagePoints,
						CV_CALIB_CB_ADAPTIVE_THRESH | CV_CALIB_CB_FAST_CHECK | CV_CALIB_CB_NORMALIZE_IMAGE);

		if(found)
		{
			cornerSubPix(
					framecv,
					imagePoints,
					Size(11,11),
					Size(-1,-1),
					TermCriteria( CV_TERMCRIT_EPS+CV_TERMCRIT_ITER, 30, 0.1 ));

			if(found)
			{
				drawChessboardCorners( framecv, boardSize, Mat(imagePoints), found);
				imshow("framecv_xx", framecv);
				waitKey(10);
			}

			imagePointsSet.push_back(imagePoints);

		}

	}


	// calibrate cameras
	if(1)
    {
	    vector<Mat> rvecs, tvecs;
	    vector<float> reprojErrs;
	    double totalAvgErr = 0;

	    result = runCalibration(imagePointsSet, imageSize, boardSize, CHESSBOARD, squareSize,
                   aspectRatio, flags, cameraMatrix, distCoeffs,
                   rvecs, tvecs, reprojErrs, totalAvgErr);
    }

	// test calibrate
	if(1)
	{
        Mat view, rview, map1, map2;
        int i;
        Size imageSize2;

        imageSize2.width  = 2 * imageSize.width;
        imageSize2.height = 2 * imageSize.height;

        initUndistortRectifyMap(cameraMatrix,
        						distCoeffs,
								Mat(),
                                getOptimalNewCameraMatrix(cameraMatrix, distCoeffs, imageSize, 1, imageSize, 0),
                                imageSize, CV_16SC2, map1, map2);


        for(i = 0; i < fileNames.size(); i++)
        {
        	view = imread(fileNames[i].c_str());
        	remap(view, rview, map1, map2, INTER_LINEAR);

        	imshow("rview", rview);
        	waitKey(0);
        }
	}

	// save
	if(result == 0 )
	{
		save_result(pParam->output_path, cameraMatrix, distCoeffs);
	}

}
Exemplo n.º 29
0
int test_key_start(void)
{
	int ret;
	struct timespec ntime;
	ntime.tv_sec= time(NULL)+KEY_TIMEOUT;
	ntime.tv_nsec=0;
	int menu_count=0;
	int key = -1;
	int test_cnt = sizeof(test_key_info) / sizeof(struct test_key);
	int i = 0;
	int cur_row = 2;
	int count = 0;

	LOGD("mmitest start");
	ui_fill_locked();
	ui_show_title(MENU_TEST_KEY);

	ui_set_color(CL_GREEN);
	cur_row=ui_show_text(cur_row, 0, TEXT_KEY_ILLUSTRATE);

	for(i = 0; i < test_cnt; i++) {
		test_key_info[i].done = 0;
	}
	for(;;) {
		cur_row = 4;
		for(i = 0; i < test_cnt; i++) {
			if(test_key_info[i].done) {
				ui_set_color(CL_GREEN);
			} else {
				ui_set_color(CL_RED);
			}
			cur_row = ui_show_text(cur_row, 0, test_key_info[i].name);
		}
		gr_flip();
		if((count >= test_cnt)) break;
		if(key==ETIMEDOUT) break;
		key = ui_wait_key(&ntime);
		LOGD("mmitest key = %d",key);
		for(i = 0; i < test_cnt; i++) {
			if((test_key_info[i].key == key)
				&&(test_key_info[i].done == 0))	{
				test_key_info[i].done = 1;
				count++;
			}
		}
		LOGD("mmitest count=%d",count);

	}

	LOGD("mmitest key over");

	if(key==ETIMEDOUT){
		ui_set_color(CL_RED);
		ui_show_text(cur_row+2, 0, TEXT_TEST_FAIL);
		gr_flip();
		sleep(1);
		ret=RL_FAIL;
	}else{
		ui_set_color(CL_GREEN);
		ui_show_text(cur_row+2, 0, TEXT_TEST_PASS);
		gr_flip();
		sleep(1);
		ret=RL_PASS;
	}
	save_result(CASE_TEST_KEY,ret);
	return ret;
}
Exemplo n.º 30
0
/* This function runs in a thread, starts the Calc_Threads and waits on their end
 * (all Calc_Threads have set isFinished["their thread number"] = true).
 * It also waits on a signal (isRunning = false) from the "Stop/Close" Button, and
 * freed than the memory and sets "canClose = true" to signalise the OnBnClickedCancel function
 * that memory has been freen and the dialog can be closed now. */
UINT CCalculate::Control_Thread(LPVOID pParam)
{
	//CCalculate *p_test = reinterpret_cast<CCalculate*>(pParam);

	
	bool allFinished = false;
	myThreadId = 0;						//set the myThreadId for the calc_threads to 0
	position = 0;						//set position in memsave back to 0

	double start_sec, start_mill, end_sec, end_mill;
	struct _timeb start_t, end_t;

	
	_ftime_s(&start_t);					//save start time

	//allocate memory
	memsave = (char(*)[NHX]) malloc(sizeof(memsave) * (pi_digits) * (NHX));
	if(memsave == NULL)
	{
		isError = true;				//dialog can be closed
		AfxMessageBox(_T("Error: Cannot allocale memory!"), MB_ICONERROR);
		return 1;
	}

	int t_id[MAX_CPU];
	// start as many calc_threads as logical cpus found
	for(int i = 0; i < num_cpu; i++)
	{
		t_id[i] = i;
		AfxBeginThread(CCalculate::Calc_Threads, reinterpret_cast<LPVOID>(&t_id[i]), THREAD_PRIORITY_NORMAL, 0, 0, NULL);
		isFinished[i] = false;
	}

	//leave loop only if ALL threads have finished, OR user stops operation
	while((!allFinished) && isRunning)
	{
		allFinished = true;
		for(int i = 0; i < num_cpu; i++)
		{
			if(!isFinished[i])
				allFinished = false;
		}
		/*progressBar->SetPos(position);*/
		Sleep(1000);
	}
		
	if(!isRunning)						//user stoped operation, exit function
	{
		free(memsave);					//freed memory
		canClose = true;				//allow to close dialog
		return 0;
	}


	_ftime_s(&end_t);					//save end time


	start_sec = (double) start_t.time;
	start_mill = (double) start_t.millitm;
	end_sec = (double) end_t.time;
	end_mill = (double) end_t.millitm;
	diff = (end_sec + (end_mill / 1000)) - (start_sec + (start_mill / 1000));

	//save result from memory to disk
	save_result();
	//freed allocated memory
	free(memsave);


	CString fin;
	fin.Format(_T("Calculated %i digits of Pi in %.3lf sec"), pi_digits, diff);
	AfxMessageBox(fin, MB_ICONINFORMATION);
	//AfxMessageBox(fin , MB_ICONINFORMATION);

	//save time needed for calculation
	CString temp_calc_time;
	temp_calc_time.Format(_T("%.3lf"), diff);
	MyLoader::setCalcTime(timelist_position, temp_calc_time);
	MyLoader::save_all();

	canClose = true;					//allow to close dialog
	return 0;
}