Пример #1
0
int
main(int argc, char **argv) {
	sg_log_init("libstatgrab-test", "SGTEST_LOG_PROPERTIES", argc ? argv[0] : NULL);
	sg_init(1);

	if( 0 != get_params( opt_def, argc, argv ) ) {
		help(argv[0]);
		return 1;
	}

	if( opt_def[OPT_HLP].optarg.b ) {
		help(argv[0]);
		return 0;
	}
	else if( opt_def[OPT_LIST].optarg.b ) {
		print_testable_functions(0);
		return 0;
	}
	else if( opt_def[OPT_RUN].optarg.str ) {
		size_t *test_routines = NULL;
		size_t entries = funcnames_to_indices(opt_def[OPT_RUN].optarg.str, &test_routines, 0);
		int errors = 0;

		if( 0 == entries ) {
			die( ESRCH, "no functions to test" );
			return 255;
		}

		while( opt_def[OPT_NLOOPS].optarg.u-- > 0 ) {
			size_t func_rel_idx;

			for( func_rel_idx = 0; func_rel_idx < entries; ++func_rel_idx ) {
				mark_func(test_routines[func_rel_idx]);
				if( !run_func( test_routines[func_rel_idx], 0 ) ) {
					done_func(test_routines[func_rel_idx], 0);
					++errors;
				}
				else {
					done_func(test_routines[func_rel_idx], 1);
				}
			}
		}

		(void)report_testable_functions(0);
		free(test_routines);

		return errors;
	}

	help(argv[0]);
	return 1;
}
Пример #2
0
static void icuwidthcb(ICUDriver *icup) {
	last_len_received[0] = ((float)icuGetWidthX(icup) / ((float)TIMER_FREQ / 1000.0));
	float len = last_len_received[0] - pulse_start;
	const float len_set = (pulse_end - pulse_start);

	if (len > len_set) {
		if (len < (len_set * 1.2)) {
			len = len_set;
		} else {
			// Too long pulse. Most likely something is wrong.
			len = -1.0;
		}
	} else if (len < 0.0) {
		if ((len + pulse_start) > (pulse_start * 0.8)) {
			len = 0.0;
		} else {
			// Too short pulse. Most likely something is wrong.
			len = -1.0;
		}
	}

	if (len >= 0.0) {
		if (use_median_filter) {
			float c = (len * 2.0 - len_set) / len_set;
			static float c1 = 0.5;
			static float c2 = 0.5;
			float med = utils_middle_of_3(c, c1, c2);

			c2 = c1;
			c1 = c;

			servo_pos[0] = med;
		} else {
			servo_pos[0] = (len * 2.0 - len_set) / len_set;
		}

		last_update_time = chVTGetSystemTime();

		if (done_func) {
			done_func();
		}
	}
}
Пример #3
0
void *
threadfunc(void *parm)
{
	int rc, success;
	size_t func_idx = *((size_t *)parm);

	rc = pthread_mutex_lock(&mutex);
	prove_libcall("pthread_mutex_lock", rc);

	++test_counter;

	while (!conditionMet) {
		TRACE_LOG( "multi_threaded", "Thread blocked" );
		rc = pthread_cond_wait(&cond, &mutex);
		prove_libcall("pthread_cond_wait", rc);
	}

	if( !opt_def[OPT_SEQ].optarg.b ) {
		rc = pthread_mutex_unlock(&mutex);
		prove_libcall("pthread_mutex_unlock", rc);
	}

	success = run_func( func_idx, 0 );

	if( !opt_def[OPT_SEQ].optarg.b ) {
		rc = pthread_mutex_lock(&mutex);
		prove_libcall("pthread_mutex_lock", rc);
	}

	done_func(func_idx, success);

	rc = pthread_mutex_unlock(&mutex);
	prove_libcall("pthread_mutex_unlock", rc);

	pthread_cond_signal(&cond);

	return NULL;
}