Пример #1
0
void tests_assert_uart_receive_avr(avr_t *avr,
			       unsigned long run_usec,
			       const char *expected,
			       char uart) {
	struct output_buffer buf;
	init_output_buffer(&buf);

	avr_irq_register_notify(avr_io_getirq(avr, AVR_IOCTL_UART_GETIRQ(uart), UART_IRQ_OUTPUT),
				buf_output_cb, &buf);
	enum tests_finish_reason reason = tests_run_test(avr, run_usec);
	if (reason == LJR_CYCLE_TIMER) {
		if (strcmp(buf.str, expected) == 0) {
			_fail(NULL, 0, "Simulation did not finish within %lu simulated usec. "
			     "UART output is correct and complete.", run_usec);
		}
		_fail(NULL, 0, "Simulation did not finish within %lu simulated usec. "
		     "UART output so far: \"%s\"", run_usec, buf.str);
	}
	if (strcmp(buf.str, expected) != 0)
		_fail(NULL, 0, "UART outputs differ: expected \"%s\", got \"%s\"", expected, buf.str);
}
Пример #2
0
/**
* Run a test directly with specified user. Attempts to load preferences
* with specified username and if successful, tries to get a test with
* specified testname and when found, runs the test and quits.
*
* This is run only when program is called with two input parameters
* using switch -u for username and -t for testname.
*
* @param user User whose preferences is to be loaded
* @param testname Name of the user's test to load
*
* @return TRUE if user and testname was found, FALSE if either is missing or not found
*/
gboolean run_user_test(gchar* user, gchar* testname) {
	user_preference* prefs = NULL;
	gboolean rval = FALSE;
	
	if(!user || !testname) return rval;

	// Load preferences for this user
	if((prefs = load_preferences(user))) {
	
		// Get test and when found run it
		testcase* test = preference_get_test(prefs,testname);
		if(test) {
			g_print("Running test \"%s\" to %s (with %d files)\n",
					test->name,test->URL,g_hash_table_size(test->files));
				
			// Init
			tests_initialize(test);
		
			// Run
			if(tests_run_test(prefs->username,test)) 
				g_print("Test %s completed with failures.\n",test->name);
			else g_print("Test %s complete\n",test->name);
		
			// REset
			tests_reset(test);
			rval = TRUE;
		}
		// Test not found
		else {
			rval = FALSE;
			g_print("Test \"%s\" not found\n",testname);
		}
		destroy_preferences();
	}
	else rval = FALSE;
	
	return rval;
}
Пример #3
0
int tests_init_and_run_test(const char *elfname, unsigned long run_usec) {
	avr_t *avr = tests_init_avr(elfname);
	return tests_run_test(avr, run_usec);
}
Пример #4
0
/** 
* Test selection part of UI. Lists tests for this user
* and awaits for selection. Runs test if it is found and
* asks whether to rerun test or to quit or to return to main.
*
* @param user username to use for loading preferences
*
* @return TRUE if preferences were found and loaded
*/
gboolean run_test_selection(gchar* user) {

	user_preference* prefs = NULL;
	gchar* temp = (gchar*)g_try_malloc(TEMPLEN);
	gboolean rval = TRUE;

	// Load preferences for this user
	if((prefs = load_preferences(user))) {
		
		g_print("%d test%s loaded for %s:\n",
			g_sequence_get_length(prefs->tests),
			g_sequence_get_length(prefs->tests) > 1 ? "s " : "",
			prefs->username);
	
		gboolean loop = TRUE, rerun = FALSE;
		gchar tnumber = '\0';
	
		// Run main loop for test selection
		while(loop) {
			gint idx = 0;
			GSequenceIter* iter = NULL;
			
			// If rerun of test was not selected print list of tests
			if(!rerun) { 
				g_print("id\tname\tfiles\turl\n");
				g_print("-------------------------------------------------------------------------------\n");
			
				// Go through list of tests
				for(iter = g_sequence_get_begin_iter(prefs->tests); 
					!g_sequence_iter_is_end(iter) ; 
					iter = g_sequence_iter_next(iter))
				{
					testcase* t = (testcase*)g_sequence_get(iter);
					
					// Is a test, print details
					if(t) {
						g_print(" %d\t%s\t%d\t%s\n",idx+1,t->name,g_hash_table_size(t->files),t->URL);
						idx++;
					}
				}
	
				g_print("\nSelect test id to run, q to quit, u to return to user selection: ");
				
				// get a char
				tnumber = getc(stdin);
		
				// Consume newline markers
				if(tnumber != '\n') temp = fgets(temp,TEMPLEN,stdin);
			}
			
			// Test rerun was selected
			else {
				g_print("Starting rerun of test %d\n",g_ascii_digit_value(tnumber));
				rerun = FALSE;
			}

			// If input is a digit between [1...amount of tests]
			if(g_ascii_isdigit(tnumber) && 
				g_ascii_digit_value(tnumber) <= g_sequence_get_length(prefs->tests) &&
				g_ascii_digit_value(tnumber) > 0) {
			
				// Set default parser
				set_parser(prefs->parser);
			
				// Get iterator to at position in testlist
				GSequenceIter* testpos = g_sequence_get_iter_at_pos(prefs->tests,
					g_ascii_digit_value(tnumber)-1);
				
				// Get test
				testcase* test = (testcase*)g_sequence_get(testpos);
			
				g_print("Running test %c:\"%s\" to %s (with %d files)\n",
					tnumber,test->name,test->URL,g_hash_table_size(test->files));
				
				// Initialize
				tests_initialize(test);
			
				// Run
				if(tests_run_test(prefs->username,test)) 
					g_print("Test %s completed with failures.\n",test->name);
				else g_print("Test %s complete\n",test->name);
			
				// Clear and reset test
				tests_reset(test);
				
				g_print("Redo test (r) or quit (q) or go to main (m) or return to user selection (u): ");
				
				// Get char 
				gchar response = getc(stdin);
			
				switch (response) {
					case 'r':
						rerun = TRUE;
						break;
					case 'q':
						loop = FALSE;
						break;
					case 'm':
						g_print("\n\n");
						break;
					case 'u':
						loop = FALSE;
						rval = FALSE;
						break;
					default:
						g_print("Invalid selection. Return to main.\n");
						rerun = FALSE;
						break;
				} // switch
				// Consume newline markers
				if(response != '\n') temp = fgets(temp,TEMPLEN,stdin);
			} // if
			else if(tnumber == 'q') loop = FALSE;
			else if(tnumber == 'u') {
				loop = FALSE;
				rval = FALSE;
			}
			else g_print("Invalid test id (%d)\n",g_ascii_digit_value(tnumber));
			iter = NULL;
		} // while
		destroy_preferences();
	} // if
	else {
		g_print("Preferences for user \"%s\" were not found\n",user);
		rval = FALSE;
	}
	
	g_free(temp);
	
	return rval;
}