示例#1
0
/**
 * \brief Run SDRAMC driver unit tests.
 */
int main(void)
{
	const usart_serial_options_t usart_serial_options = {
		.baudrate = CONF_TEST_BAUDRATE,
		.paritytype = CONF_TEST_PARITY
	};

	/* Initialize the system clock and board */
	sysclk_init();
	board_init();

	/* Enable the debug uart */
	sysclk_enable_peripheral_clock(CONSOLE_UART_ID);
	stdio_serial_init(CONF_TEST_UART, &usart_serial_options);

#if defined(__GNUC__)
	setbuf(stdout, NULL);
#endif

	/* Define all the test cases */
	DEFINE_TEST_CASE(sdramc_test, NULL, run_sdramc_test, NULL,
			"SDRAMC read/write test");

	/* Put test case addresses in an array */
	DEFINE_TEST_ARRAY(sdramc_tests) = {
		&sdramc_test
	};

	/* Define the test suite */
	DEFINE_TEST_SUITE(sdramc_suite, sdramc_tests,
			"SAM SDRAMC driver test suite");

	/* Run all tests in the test suite */
	test_suite_run(&sdramc_suite);

	while (1) {
		/* Busy-wait forever. */
	}
}
/**
 * \brief Run MCP980X driver unit tests
 */
int main(void)
{
	const usart_serial_options_t usart_serial_options = {
		.baudrate   = CONF_TEST_BAUDRATE,
		.paritytype = CONF_TEST_PARITY
	};

	sysclk_init();
	board_init();

	sysclk_enable_peripheral_clock(CONSOLE_UART_ID);
	stdio_serial_init(CONF_TEST_USART, &usart_serial_options);

	/* Set up SysTick Timer for 1 msec interrupts. */
	if (SysTick_Config(sysclk_get_cpu_hz() / 1000)) {
		/* Capture error. */
		while (1) {
		}
	}

	/* Define all the test cases */
	DEFINE_TEST_CASE(mcp980x_test, NULL, run_mcp980x_test, NULL,
		"Init TWI, read temperature values returned by MCP980X and check them.");

	/* Put test case addresses in an array */
	DEFINE_TEST_ARRAY(mcp980x_tests) = {
		&mcp980x_test,
	};

	/* Define the test suite */
	DEFINE_TEST_SUITE(mcp980x_suite, mcp980x_tests, "SAM MCP980X test suite");

	/* Run all tests in the test suite */
	test_suite_run(&mcp980x_suite);

	while (1) {
		/* Busy-wait forever. */
	}
}
示例#3
0
/**
 * \brief Run EEPROM emulator unit tests
 *
 * Initializes the system and serial output, then sets up the
 * EEPROM emulator unit test suite and runs it.
 */
int main(void)
{
	system_init();
	cdc_uart_init();

	/* Define Test Cases */
	DEFINE_TEST_CASE(eeprom_init_test, NULL,
			run_eeprom_init_test, NULL,
			"Testing EEPROM emulator initialization");

	DEFINE_TEST_CASE(eeprom_buffer_read_write_test,
			setup_eeprom_buffer_read_write_test,
			run_eeprom_buffer_read_write_test, NULL,
			"Testing EEPROM buffer read/write functionality");

	DEFINE_TEST_CASE(eeprom_page_read_write_test,
			setup_eeprom_page_read_write_test,
			run_eeprom_page_read_write_test, NULL,
			"Testing EEPROM page read/write functionality");

	/* Put test case addresses in an array */
	DEFINE_TEST_ARRAY(eeprom_tests) = {
		&eeprom_init_test,
		&eeprom_buffer_read_write_test,
		&eeprom_page_read_write_test,
	};

	/* Define the test suite */
	DEFINE_TEST_SUITE(eeprom_test_suite, eeprom_tests,
			"SAM EEPROM emulator service test suite");

	/* Run all tests in the suite*/
	test_suite_run(&eeprom_test_suite);

	while (true) {
		/* Intentionally left empty */
	}
}
示例#4
0
/**
 * \brief Run GLOC driver unit tests.
 */
int main(void)
{
	sysclk_init();
	board_init();

	const usart_serial_options_t usart_serial_options = {
		.baudrate = CONF_TEST_BAUDRATE,
		.charlength = CONF_TEST_CHARLENGTH,
		.paritytype = CONF_TEST_PARITY,
		.stopbits = CONF_TEST_STOPBITS
	};

	stdio_serial_init(CONF_TEST_USART, &usart_serial_options);

	/* Initialize the GLOC module */
	gloc_init(&dev_inst, GLOC);
	/* Enable the GLOC module. */
	gloc_enable(&dev_inst);

	/* Define all the test cases. */
	DEFINE_TEST_CASE(gloc_4inputs_xor_test, NULL, run_gloc_4inputs_xor_test,
			NULL, "SAM GLOC LUT 4 Inputs XOR Test");

	/* Put test case addresses in an array. */
	DEFINE_TEST_ARRAY(gloc_tests) = {
		&gloc_4inputs_xor_test,
	};

	/* Define the test suite. */
	DEFINE_TEST_SUITE(gloc_suite, gloc_tests, "SAM GLOC driver test suite");

	/* Run all tests in the test suite. */
	test_suite_run(&gloc_suite);

	while (1) {
		/* Busy-wait forever. */
	}
}
示例#5
0
/**
 * \brief Run GMAC driver unit tests.
 */
int main(void)
{
	const usart_serial_options_t usart_serial_options = {
		.baudrate = CONF_TEST_BAUDRATE,
		.paritytype = CONF_TEST_PARITY
	};

	/* Initialize the system clock and board */
	sysclk_init();
	board_init();

	/* Enable the debug uart */
	sysclk_enable_peripheral_clock(CONSOLE_UART_ID);
	stdio_serial_init(CONF_TEST_USART, &usart_serial_options);

	/* Define all the test cases */
	DEFINE_TEST_CASE(gmac_link_test, NULL, run_gmac_link_test, NULL,
			"GMAC link test");

	/* Define all the test cases */
	DEFINE_TEST_CASE(gmac_rw_test, NULL, run_gmac_read_write_test, NULL,
			"GMAC read/write test");

	/* Put test case addresses in an array */
	DEFINE_TEST_ARRAY(gmac_tests) = {
	&gmac_link_test,
	&gmac_rw_test};

	/* Define the test suite */
	DEFINE_TEST_SUITE(gmac_suite, gmac_tests, "SAM GMAC driver test suite");

	/* Run all tests in the test suite */
	test_suite_run(&gmac_suite);

	while (1) {
		/* Busy-wait forever */
	}
}
示例#6
0
/**
 * \brief Run DMAC driver unit tests.
 */
int main(void)
{
	const usart_serial_options_t uart_serial_options = {
		.baudrate = CONF_TEST_BAUDRATE,
		.paritytype = CONF_TEST_PARITY
	};

	/* Initialize the system. */
	sysclk_init();
	board_init();

	/* Configure console UART. */
	sysclk_enable_peripheral_clock(CONSOLE_UART_ID);
	stdio_serial_init(CONF_TEST_UART, &uart_serial_options);

	/* Define all the test cases */
	DEFINE_TEST_CASE(single_buf_xfer_test, NULL, run_single_buf_xfer_test,
			NULL, "Test DMA single buffer transfer");

	DEFINE_TEST_CASE(multi_buf_xfer_test, NULL, run_multi_buf_xfer_test,
			NULL, "Test DMA multiple buffer transfer");

	/* Put test case addresses in an array */
	DEFINE_TEST_ARRAY(dmac_tests) = {
		&single_buf_xfer_test,
		&multi_buf_xfer_test,
	};

	/* Define the test suite */
	DEFINE_TEST_SUITE(dmac_suite, dmac_tests, "SAM DMAC driver test suite");

	/* Run all tests in the test suite */
	test_suite_run(&dmac_suite);

	while (1) {
		/* Busy-wait forever */
	}
}
示例#7
0
/**
 * \brief Run WDT driver unit tests.
 */
int main(void)
{
	const usart_serial_options_t usart_serial_options = {
		.baudrate = CONF_TEST_BAUDRATE,
		.charlength = CONF_TEST_CHARLENGTH,
		.paritytype = CONF_TEST_PARITY,
		.stopbits = CONF_TEST_STOPBITS
	};

	sysclk_init();
	board_init();
	stdio_serial_init(CONF_TEST_USART, &usart_serial_options);

	/* Configure systick for 1 ms */
	if (SysTick_Config(sysclk_get_cpu_hz() / 1000)) {
		/* Systick configuration error */
		while (1);
	}

	/* Define all the test cases */
	DEFINE_TEST_CASE(wdt_test_all, NULL, run_wdt_test_all, NULL,
			"Test watchdog all.");

	/* Put test case addresses in an array */
	DEFINE_TEST_ARRAY(wdt_tests) = {
		&wdt_test_all
	};

	/* Define the test suite */
	DEFINE_TEST_SUITE(wdt_suite, wdt_tests, "SAM4L WDT driver test suite");

	/* Run all tests in the test suite */
	test_suite_run(&wdt_suite);

	while (1) {
		/* Busy-wait forever. */
	}
}
示例#8
0
/**
 * \brief Run External Interrupt unit tests
 *
 * Initializes the system and serial output, then sets up the
 * External Interrupt unit test suite and runs it.
 */
int main(void)
{
	system_init();
	delay_init();
	cdc_uart_init();

	/* Define Test Cases */
	DEFINE_TEST_CASE(extint_polled_mode_test,
			setup_extint_polled_mode_test,
			run_extint_polled_mode_test,
			cleanup_extint_polled_mode_test,
			"Testing external interrupt by polling");

	DEFINE_TEST_CASE(extint_callback_mode_test,
			setup_extint_callback_mode_test,
			run_extint_callback_mode_test,
			cleanup_extint_callback_mode_test,
			"Testing external interrupt using callback");

	/* Put test case addresses in an array */
	DEFINE_TEST_ARRAY(extint_tests) = {
		&extint_polled_mode_test,
		&extint_callback_mode_test,
	};

	/* Define the test suite */
	DEFINE_TEST_SUITE(extint_test_suite, extint_tests,
			"SAM D20/D21 External Interrupt driver test suite");

	/* Run all tests in the suite*/
	test_suite_run(&extint_test_suite);

	while (true) {
		/* Intentionally left empty */
	}
}
示例#9
0
文件: unit_tests.c 项目: marekr/asf
/**
 * \brief Run ABDAC driver unit tests.
 */
int main(void)
{
	const usart_serial_options_t usart_serial_options = {
		.baudrate = CONF_TEST_BAUDRATE,
		.charlength = CONF_TEST_CHARLENGTH,
		.paritytype = CONF_TEST_PARITY,
		.stopbits = CONF_TEST_STOPBITS
	};

	sysclk_init();
	board_init();
	stdio_serial_init(CONF_TEST_USART, &usart_serial_options);

	/* Define all the test cases. */
	DEFINE_TEST_CASE(abdac_init_test, NULL, run_abdac_init_test, NULL,
			"SAM ABDAC initialization test.");
	DEFINE_TEST_CASE(abdac_interrupt_test, NULL, run_abdac_interrupt_test,
			NULL, "SAM ABDAC interrupt test.");

	/* Put test case addresses in an array. */
	DEFINE_TEST_ARRAY(abdac_tests) = {
		&abdac_init_test,
		&abdac_interrupt_test,
	};

	/* Define the test suite. */
	DEFINE_TEST_SUITE(abdac_suite, abdac_tests,
			"SAM ABDAC driver test suite");

	/* Run all tests in the test suite. */
	test_suite_run(&abdac_suite);

	while (1) {
		/* Busy-wait forever. */
	}
}
示例#10
0
void main_cdc_set_dtr(bool b_enable)
{
	if (b_enable) {
		DEFINE_TEST_CASE(tal_reset_test, NULL, run_tal_reset_test,
				NULL, "AVR2025_MAC - TAL Reset request");
		DEFINE_TEST_CASE(tal_pib_set_test, NULL,
				run_tal_pib_set_test, NULL,
				"AVR2025_MAC - TAL PIB Set test");

		/* Put test case addresses in an array. */
		DEFINE_TEST_ARRAY(tal_tests) = {
			&tal_reset_test,
			&tal_pib_set_test
		};

		/* Define the test suite. */
		DEFINE_TEST_SUITE(tal_suite, tal_tests,
				"AVR2025_MAC - TAL unit test suite");

		/* Run all tests in the test suite. */
		test_suite_run(&tal_suite);
	} else {
	}
}
void main_cdc_set_dtr(bool b_enable)
{
	if (b_enable) {
		DEFINE_TEST_CASE(nlme_reset_test, NULL, run_nlme_reset_test,
				NULL, "NWK Reset request");
		DEFINE_TEST_CASE(nlme_auto_discovery_test, NULL,
				run_nlme_auto_discovery_test, NULL,
				"NWK DISCOVERY test (this covers all ASF drivers/services used");

		/* Put test case addresses in an array. */
		DEFINE_TEST_ARRAY(nwk_tests) = {
			&nlme_reset_test,
			&nlme_auto_discovery_test
		};

		/* Define the test suite. */
		DEFINE_TEST_SUITE(nwk_suite, nwk_tests,
				"NWK unit test suite");

		/* Run all tests in the test suite. */
		test_suite_run(&nwk_suite);
	} else {
	}
}
示例#12
0
void main_cdc_set_dtr(bool b_enable)
{
	if (b_enable) {
		DEFINE_TEST_CASE(wpan_reset_test, NULL, run_wpan_reset_test,
				NULL, "AVR2025_MAC - MAC Reset request");
		DEFINE_TEST_CASE(wpan_scan_test, NULL,
				run_wpan_scan_test, NULL,
				"AVR2025_MAC - MAC Scan test (this covers all ASF drivers/services used)");

		/* Put test case addresses in an array. */
		DEFINE_TEST_ARRAY(wpan_tests) = {
			&wpan_reset_test,
			&wpan_scan_test
		};

		/* Define the test suite. */
		DEFINE_TEST_SUITE(wpan_suite, wpan_tests,
				"AVR2025_MAC - MAC unit test suite");

		/* Run all tests in the test suite. */
		test_suite_run(&wpan_suite);
	} else {
	}
}
示例#13
0
/**
 * \internal
 * \brief This test sends a packet from the master, and checks
 * that the sending happens without errors. Master is megaRF device and the slave 
 * is on board EEPROM.Configuring EEPROM as slave is not required.
 * \param test Current test case.
 */
static void run_twi_master_send_test(const struct test_case *test)
{
	status_code_t master_status;
	volatile uint64_t delay=0;
	
	// Package to send
	twi_package_t packet = {
		.addr[0]         = (uint8_t) SLAVE_MEM_ADDR, /* TWI slave memory
		                                         * address data */
		.addr_length  = (uint8_t)SLAVE_MEM_ADDR_LENGTH, /* TWI slave
		                                                 * memory
		                                                 * address data
		                                                 * size */
		.chip         = TWI_SLAVE_ADDR, /* TWI slave bus address */
		.buffer       = (void *)test_pattern, /* transfer data source
		                                       * buffer */
		.length       = PATTERN_TEST_LENGTH /* transfer data size
				                            * (bytes) */
    };

	/* TWI master initialization options. */
	twi_master_options_t m_options = {
		.speed      = TWI_SPEED,
		.chip  = TWI_SLAVE_ADDR,
		
	};
	m_options.baud_reg = TWI_CLOCK_RATE(sysclk_get_cpu_hz(), m_options.speed);

	// Initialize TWI_MASTER
	sysclk_enable_peripheral_clock(TWI_MASTER);
	twi_master_init(TWI_MASTER, &m_options);

	// Send package to slave
	master_status = twi_master_write(TWI_MASTER, &packet);
        
    /* Write completion time for EEPROM */
	for(delay=0;delay<10000;delay++);

	test_assert_true(test, master_status == STATUS_OK,
			"Master write not ok");
}

/**
 * \internal
 * \brief This test requests previously sent packet to be sent from the slave,
 * and checks that the correct packet is received by the master. Master is 
 * megaRF device and the slave is on board EEPROM.Configuring EEPROM as slave 
 * is not required.
 * \param test Current test case.
 */
static void run_twi_master_recv_test(const struct test_case *test)
{
	uint8_t i = 0;
	uint8_t recv_pattern[PATTERN_TEST_LENGTH] = {0};

	// Package to send
	twi_package_t packet = {
		.addr[0]         = (uint8_t) SLAVE_MEM_ADDR, /* TWI slave memory
		                                         * address data */
		.addr_length  = (uint8_t)SLAVE_MEM_ADDR_LENGTH, /* TWI slave
		                                                 * memory
		                                                 * address data
		                                                 * size */
		.chip        = TWI_SLAVE_ADDR,
		.buffer      = (void *)recv_pattern,
		.length      = PATTERN_TEST_LENGTH,
	};
	
	/* TWI master initialization options. */
	twi_master_options_t m_options = {
		.speed      = TWI_SPEED,
		.chip  = TWI_SLAVE_ADDR,
		
	};
	m_options.baud_reg = TWI_CLOCK_RATE(sysclk_get_cpu_hz(), m_options.speed);

	// Initialize TWI_MASTER
	sysclk_enable_peripheral_clock(TWI_MASTER);
	twi_master_init(TWI_MASTER, &m_options);

	// Send package to slave
	twi_master_read(TWI_MASTER, &packet);

	for (i = 0; i < PATTERN_TEST_LENGTH; i++) {
		test_assert_true(test, recv_pattern[i] == test_pattern[i],
				"Wrong twi data[%d] received, %d != %d", i,
				recv_pattern[i],
				test_pattern[i]);
	}
}

//@}

/**
 * \brief Run TWI unit tests
 *
 * Initializes the clock system, board and serial output, then sets up the
 * TWI unit test suite and runs it.
 */
int main(void)
{
	const usart_serial_options_t usart_serial_options = {
		.baudrate   = CONF_TEST_BAUDRATE,
		.charlength = CONF_TEST_CHARLENGTH,
		.paritytype = CONF_TEST_PARITY,
		.stopbits   = CONF_TEST_STOPBITS,
	};

	sysclk_init();
	board_init();
	stdio_serial_init(CONF_TEST_USART, &usart_serial_options);

	// Define single ended conversion test cases
	DEFINE_TEST_CASE(twi_master_send_test, NULL,
			run_twi_master_send_test, NULL,
			"Sending packet from master test");
	DEFINE_TEST_CASE(twi_master_recv_test, NULL,
			run_twi_master_recv_test, NULL,
			"Receiving packet from slave test");

	// Put test case addresses in an array
	DEFINE_TEST_ARRAY(twi_tests) = {
		&twi_master_send_test,
		&twi_master_recv_test,
	};

	// Define the test suite
	DEFINE_TEST_SUITE(twi_suite, twi_tests,
			"MEGARF TWI driver test suite");

	// Run all tests in the suite
	test_suite_run(&twi_suite);

	while (1) {
		// Intentionally left empty.
	}
}
示例#14
0
/**
 * \brief This function runs a SHA204 Read test on all four devices.
 *
 * This test wakes up the devices, reads their TWI addresses from
 * their Config zone, and sends them back to sleep. The test fails if
 * there are communication failures or the TWI addresses do not match.
 *
 * \param test current test case
 */
static void test_all_devices(const struct test_case *test)
{
	test_assert_true(test, success, "Previous test failed.");
	success = false;
	
	uint8_t sha204_status;
	uint8_t i;
	uint8_t twi_address;
	uint8_t twi_address_retrieved = 0;
	uint8_t command[READ_COUNT];
	uint8_t response[READ_4_RSP_SIZE];
	
	sha204_status = sha204p_wakeup();
	test_assert_true(test, sha204_status == SHA204_SUCCESS, "Sending Wakeup token failed.");

	// Address 16 holds the TWI address.
	struct sha204_read_parameters args = 
			{.tx_buffer = command, .rx_buffer = response, .zone = SHA204_ZONE_CONFIG, .address = 16};
	
	// Read TWI address from all four devices that are mounted on the Security Xplained extension board.
	for (i = 0; i < SHA204_DEVICE_COUNT; i++) {
		twi_address = sha204_i2c_address(i);
		sha204p_set_device_id(twi_address);

		memset(response, 0, sizeof(response));
		success = false;
		sha204_status = sha204m_read(&args);
		if (sha204_status != SHA204_SUCCESS)
			break;
		twi_address_retrieved = args.rx_buffer[SHA204_BUFFER_POS_DATA] & 0xFE;
		if (twi_address_retrieved != twi_address)
			break;

		sha204_status = sha204p_sleep();
		if (sha204_status != SHA204_SUCCESS)
			break;

		success = true;
	}
	// Sleep remaining devices in case one of them failed.
	for (; i < SHA204_DEVICE_COUNT; i++) {
		twi_address = sha204_i2c_address(i);
		sha204p_set_device_id(twi_address);
		sha204p_sleep();
	}	
	test_assert_true(test, sha204_status == SHA204_SUCCESS, "Communication error.");
	test_assert_true(test, twi_address_retrieved == twi_address, "TWI address does not match.");

	success = true;
}


//! \name Unit test configuration
//@{
/**
 * \def CONF_TEST_USART
 * \brief USART to redirect STDIO to
 */
/**
 * \def CONF_TEST_BAUDRATE
 * \brief Baudrate of USART
 */
/**
 * \def CONF_TEST_CHARLENGTH
 * \brief Character length (bits) of USART
 */
/**
 * \def CONF_TEST_PARITY
 * \brief Parity mode of USART
 */
/**
 * \def CONF_TEST_STOPBITS
 * \brief Stop bit configuration of USART
 */
//@}

/**
 * \brief This function runs ATSHA204 component unit tests.
 */
int main (void)
{
	const usart_serial_options_t usart_serial_options =
	{
		.baudrate     = CONF_TEST_BAUDRATE,
		.charlength   = CONF_TEST_CHARLENGTH,
		.paritytype   = CONF_TEST_PARITY,
		.stopbits     = CONF_TEST_STOPBITS,
	};

	sysclk_init();
	board_init();
	pmic_init();
	sleepmgr_init();
	stdio_serial_init(CONF_TEST_USART, &usart_serial_options);

	// Enable low level interrupts
	pmic_enable_level(PMIC_LVL_LOW);

	// Enable interrupt requests
	cpu_irq_enable();

	// Define all the test cases
	DEFINE_TEST_CASE(sha204_test1, NULL, test_sha204_wakeup, NULL,
			"Testing Wakeup / Sleep");

	DEFINE_TEST_CASE(sha204_test2, NULL, test_all_devices, NULL,
			"Testing all devices");

	// Put test case addresses in an array
	DEFINE_TEST_ARRAY(sha204_tests) = {
		&sha204_test1,
		&sha204_test2
	};

	// Define the test suite
	DEFINE_TEST_SUITE(sha204_suite, sha204_tests,
			"XMEGA ATSHA204 component test suite");

	// Run all tests in the test suite
	test_suite_run(&sha204_suite);

	while (1) {
		// Loop for infinity
	}
}
示例#15
0
/**
 * \brief Run BPM driver unit tests.
 */
int main(void)
{
	struct ast_config ast_conf;

	const usart_serial_options_t usart_serial_options = {
		.baudrate = CONF_TEST_BAUDRATE,
		.charlength = CONF_TEST_CHARLENGTH,
		.paritytype = CONF_TEST_PARITY,
		.stopbits = CONF_TEST_STOPBITS
	};

	sysclk_init();
	board_init();
	stdio_serial_init(CONF_TEST_USART, &usart_serial_options);

	/* Initialize AST for all tests */
	/* Enable osc32 oscillator*/
	if (!osc_is_ready(OSC_ID_OSC32)) {
		osc_enable(OSC_ID_OSC32);
		osc_wait_ready(OSC_ID_OSC32);
	}

	/* Enable the AST. */
	ast_enable(AST);

	ast_conf.mode = AST_COUNTER_MODE;
	ast_conf.osc_type = AST_OSC_32KHZ;
	ast_conf.psel = AST_PSEL_32KHZ_1HZ;
	ast_conf.counter = 0;
	ast_set_config(AST, &ast_conf);

	/* Set periodic 0 to interrupt after 1/16 second in counter mode. */
	ast_clear_interrupt_flag(AST, AST_INTERRUPT_PER);
	ast_write_periodic0_value(AST, AST_PSEL_32KHZ_1HZ - 2);

	ast_set_callback(AST, AST_INTERRUPT_PER, ast_per_callback,
		AST_PER_IRQn, 1);

	ast_enable_wakeup(AST, AST_WAKEUP_PER);

	/* AST can wakeup the device */
	bpm_enable_wakeup_source(BPM, (1 << BPM_BKUPWEN_AST));
	/**
	 * Retain I/O lines after wakeup from backup.
	 * Disable to undo the previous retention state then enable.
	 */
	bpm_disable_io_retention(BPM);
	bpm_enable_io_retention(BPM);
	/* Enable fast wakeup */
	bpm_enable_fast_wakeup(BPM);

	/* Define all the test cases. */
	DEFINE_TEST_CASE(backup_test, NULL, run_backup_test, NULL,
			"Backup Power Manager, Backup mode & wakeup.");
	DEFINE_TEST_CASE(ps_test, NULL, run_ps_test, NULL,
			"Backup Power Manager, Power Scaling.");
	DEFINE_TEST_CASE(ret_test, NULL, run_ret_test, NULL,
			"Backup Power Manager, Retention mode & wakeup.");
	DEFINE_TEST_CASE(wait_test, NULL, run_wait_test, NULL,
			"Backup Power Manager, Wait mode & wakeup.");
	DEFINE_TEST_CASE(sleep_3_test, NULL, run_sleep_3_test, NULL,
			"Backup Power Manager, Sleep mode 3 & wakeup.");
	DEFINE_TEST_CASE(sleep_2_test, NULL, run_sleep_2_test, NULL,
			"Backup Power Manager, Sleep mode 2 & wakeup.");
	DEFINE_TEST_CASE(sleep_1_test, NULL, run_sleep_1_test, NULL,
			"Backup Power Manager, Sleep mode 1 & wakeup.");
	DEFINE_TEST_CASE(sleep_0_test, NULL, run_sleep_0_test, NULL,
			"Backup Power Manager, Sleep mode 0 & wakeup.");

	/* Put test case addresses in an array. */
	DEFINE_TEST_ARRAY(bpm_tests) = {
			&backup_test,
			&ps_test,
			&ret_test,
			&wait_test,
			&sleep_3_test,
			&sleep_2_test,
			&sleep_1_test,
			&sleep_0_test,
			};

	/* Define the test suite. */
	DEFINE_TEST_SUITE(bpm_suite, bpm_tests, "SAM BPM driver test suite");

	/* Run all tests in the test suite. */
	test_suite_run(&bpm_suite);

	/* Disable the AST */
	ast_disable(AST);

	while (1) {
		/* Busy-wait forever. */
	}
}
示例#16
0
/**
 * \brief Run gfx_mono unit tests
 */
int main (void)
{
	const usart_serial_options_t usart_serial_options = {
		.baudrate   = CONF_TEST_BAUDRATE,
		.charlength = CONF_TEST_CHARLENGTH,
		.paritytype = CONF_TEST_PARITY,
		.stopbits   = CONF_TEST_STOPBITS,
	};

	sysclk_init();
	board_init();
	gfx_mono_init();

	stdio_serial_init(CONF_TEST_USART, &usart_serial_options);


	// Define all the test cases
	DEFINE_TEST_CASE(clear_display_test, NULL, run_clear_display_test, NULL,
			"Clear display test");
	DEFINE_TEST_CASE(set_display_test, NULL, run_set_display_test, NULL,
			"Set display test");
	DEFINE_TEST_CASE(draw_rectangles_test, NULL, run_draw_rectangles_test,
			NULL, "Draw filled rectangles test");
	DEFINE_TEST_CASE(draw_filled_rectangle_test, NULL,
			run_draw_filled_rectangle_test, NULL,
			"Draw filled rectangle in one page test");
	DEFINE_TEST_CASE(draw_rectangle_two_pages_test, NULL,
			run_draw_rectangle_two_pages_test, NULL,
			"Draw filled rectangle in two pages test");
	DEFINE_TEST_CASE(draw_rectangle_outline_test, NULL,
			run_draw_rectangle_outline_test, NULL, 
			"Draw rectangle outline test");
	DEFINE_TEST_CASE(draw_filled_circle_test, NULL,
			run_draw_filled_circle_test, NULL, "Draw filled circle test");
	DEFINE_TEST_CASE(draw_circle_outline_test, NULL,
			run_draw_circle_outline_test, NULL, "Draw circle outline test");
	DEFINE_TEST_CASE(draw_vertical_line_test, NULL, 
			run_draw_vertical_line_test, NULL, "Draw vertical line test");
	DEFINE_TEST_CASE(draw_horizontal_line_test, NULL,
			run_draw_horizontal_line_test, NULL, "Draw horizontal line test");
	DEFINE_TEST_CASE(draw_diagonal_line_test, NULL,
			run_draw_diagonal_line_test, NULL,
			"Draw a line between two points test");
	DEFINE_TEST_CASE(draw_flash_bitmap_test, NULL, run_draw_flash_bitmap_test,
			NULL, "Draw bitmap stored in FLASH test");
	DEFINE_TEST_CASE(draw_ram_bitmap_test, NULL, run_draw_ram_bitmap_test,
			NULL, "Draw bitmap stored in RAM test");

	// Put test case addresses in an array
	DEFINE_TEST_ARRAY(gfx_mono_tests) = {
			&clear_display_test,
			&set_display_test,
			&draw_rectangles_test,
			&draw_filled_rectangle_test,
			&draw_rectangle_two_pages_test,
			&draw_rectangle_outline_test,
			&draw_filled_circle_test,
			&draw_circle_outline_test,
			&draw_horizontal_line_test,
			&draw_vertical_line_test,
			&draw_diagonal_line_test,
			&draw_flash_bitmap_test,
			&draw_ram_bitmap_test,
	};

	// Define the test suite
	DEFINE_TEST_SUITE(gfx_mono_suite, gfx_mono_tests, "gfx_mono test suite");

	// Set up the test data pointer and run all tests in the suite
	test_suite_run(&gfx_mono_suite);

	while (1) {
		/* Intentionally left empty. */
	}
}
示例#17
0
/**
 * \brief Run usb device msc unit tests
 *
 * Initializes the clock system, board and serial output, then sets up the
 * usb unit test suite and runs it.
 */
int main(void)
{
#if !SAM0
	const usart_serial_options_t usart_serial_options = {
		.baudrate   = CONF_TEST_BAUDRATE,
		.charlength = CONF_TEST_CHARLENGTH,
		.paritytype = CONF_TEST_PARITY,
		.stopbits   = CONF_TEST_STOPBITS,
	};
#else
	struct usart_config usart_conf;
#endif

	irq_initialize_vectors();
	cpu_irq_enable();

#if !SAM0
	sysclk_init();
	board_init();
#else
	system_init();
#endif
	// Initialize the sleep manager
	sleepmgr_init();

#if !SAM0
	stdio_serial_init(CONF_TEST_USART, &usart_serial_options);
#else
	/* Configure USART for unit test output */
	usart_get_config_defaults(&usart_conf);
	usart_conf.mux_setting = CONF_STDIO_MUX_SETTING;
	usart_conf.pinmux_pad0 = CONF_STDIO_PINMUX_PAD0;
	usart_conf.pinmux_pad1 = CONF_STDIO_PINMUX_PAD1;
	usart_conf.pinmux_pad2 = CONF_STDIO_PINMUX_PAD2;
	usart_conf.pinmux_pad3 = CONF_STDIO_PINMUX_PAD3;
	usart_conf.baudrate    = CONF_STDIO_BAUDRATE;
	usart_conf.generator_source = GCLK_GENERATOR_3;

	stdio_serial_init(&cdc_uart_module, CONF_STDIO_USART, &usart_conf);
	usart_enable(&cdc_uart_module);
#endif

	// Define all the timestamp to date test cases
	DEFINE_TEST_CASE(usb_msc_test, NULL,
			run_usb_msc_test, NULL,
			"USB Device msc enumeration test");
	DEFINE_TEST_CASE(usb_msc_read_test, NULL,
			run_usb_msc_read_test, NULL,
			"USB MSC read access test");
	DEFINE_TEST_CASE(usb_vbus_test, NULL,
			run_usb_vbus_test, NULL,
			"USB vbus event test");
	DEFINE_TEST_CASE(usb_resume_test, NULL,
			run_usb_resume_test, NULL,
			"USB resume event test");
	DEFINE_TEST_CASE(usb_suspend_test, NULL,
			run_usb_suspend_test, NULL,
			"USB suspend event test");
	DEFINE_TEST_CASE(usb_sof_test, NULL,
			run_usb_sof_test, NULL,
			"USB sof event test");

	// Put test case addresses in an array
	DEFINE_TEST_ARRAY(usb_msc_tests) = {
		&usb_msc_test,
		&usb_msc_read_test,
		&usb_vbus_test,
		&usb_resume_test,
		&usb_suspend_test,
		&usb_sof_test,
	};

	// Define the test suite
	DEFINE_TEST_SUITE(usb_msc_suite, usb_msc_tests,
			"Common usb MSC service with test suite");

	// The unit test prints message via UART which does not support deep sleep mode.
#if SAM
	sleepmgr_lock_mode(SLEEPMGR_ACTIVE);
#else
	sleepmgr_lock_mode(SLEEPMGR_IDLE);
#endif

	// Run all tests in the suite
	test_suite_run(&usb_msc_suite);

	while (1) {
		// Intentionally left empty.
	}
}
示例#18
0
/* ! \brief Set up and run the test suite */
int main(void)
{
	const usart_serial_options_t usart_serial_options = {
		.baudrate     = CONF_TEST_BAUDRATE,
		.charlength   = CONF_TEST_CHARLENGTH,
		.paritytype   = CONF_TEST_PARITY,
		.stopbits     = CONF_TEST_STOPBITS,
	};

	sysclk_init();
	board_init();
	pmic_init();
	sleepmgr_init();
	stdio_serial_init(CONF_TEST_USART, &usart_serial_options);

	/* Enable low level interrupts */
	pmic_enable_level(PMIC_LVL_LOW);

	/* Enable interrupt requests */
	cpu_irq_enable();

	DEFINE_TEST_CASE(memory_copy_burst_length_test,
			NULL, run_edma_memory_copy_burst_length_test, NULL,
			"Memory copy and burst lengths");

	DEFINE_TEST_CASE(standard_config_interface_test,
			NULL, run_edma_standard_config_interface_test, NULL,
			"Write and read conf param for stdCH");

	DEFINE_TEST_CASE(peripheral_config_interface_test,
			NULL, run_edma_peripheral_config_interface_test, NULL,
			"Write and read conf param for perCH");

	DEFINE_TEST_CASE(trigger_callback_test,
			NULL, run_edma_triggered_with_callback, NULL,
			"External trigger and EDMA callback");

	DEFINE_TEST_CASE(error_handling_test,
			NULL, run_edma_error_handling_test, NULL,
			"Error handling by the module");

	DEFINE_TEST_CASE(search_and_double_buffer_test,
			NULL, run_edma_search_dbuf_test, NULL,
			"SEARCH and DOUBLE BUFFER modes");

	DEFINE_TEST_ARRAY(edma_tests) = {
		&memory_copy_burst_length_test,
		&standard_config_interface_test,
		&peripheral_config_interface_test,
		&trigger_callback_test,
		&error_handling_test,
		&search_and_double_buffer_test
	};

	DEFINE_TEST_SUITE(edma_suite,
			edma_tests,
			"XMEGA EDMA driver test suite");

	test_suite_run(&edma_suite);

	while (1) {
		/* Intentionally left empty */
	}
}
示例#19
0
/**
 * \brief Test ADCIFE in Differential mode.
 *
 * \param test Current test case.
 */
static void run_adcife_diff_test(const struct test_case *test)
{
	uint32_t timeout = ADC_NUM_OF_ATTEMPTS;
	bool conversion_timeout = false;

	struct adc_seq_config adc_seq_cfg = {
		/* Select Vref for shift cycle */
		.zoomrange = ADC_ZOOMRANGE_0,
		/* Pad Ground */
		.muxneg = ADC_MUXNEG_1,
		/* Scaled Vcc, Vcc/10 */
		.muxpos = ADC_MUXPOS_2,
		/* Enables the internal voltage sources */
		.internal = ADC_INTERNAL_3,
		/* Disables the ADC gain error reduction */
		.gcomp = ADC_GCOMP_DIS,
		/* Disables the HWLA mode */
		.hwla = ADC_HWLA_DIS,
		/* 12-bits resolution */
		.res = ADC_RES_12_BIT,
		/* Enables the differential mode */
		.bipolar = ADC_BIPOLAR_DIFFERENTIAL
	};
	struct adc_ch_config adc_ch_cfg = {
		.seq_cfg = &adc_seq_cfg,
		/* Internal Timer Max Counter */
		.internal_timer_max_count = 60,
		/* Window monitor mode is off */
		.window_mode = 0,
		.low_threshold = 0,
		.high_threshold = 0,
	};

	adc_ch_set_config(&g_adc_inst, &adc_ch_cfg);
	adc_configure_trigger(&g_adc_inst, ADC_TRIG_CON);
	adc_configure_gain(&g_adc_inst, ADC_GAIN_1X);
	while (!((adc_get_status(&g_adc_inst) & ADCIFE_SR_SEOC) ==
			ADCIFE_SR_SEOC)) {
		if (!timeout--) {
			conversion_timeout = true;
		}
	}

	test_assert_true(test, conversion_timeout == false, "ADCIFE Differential conversion timeout");

	/* Because selected channel is positive input, then in differential mode
	 * the output conversion result will = 2047 + (Vin/Vref)*2047.
	 */
	test_assert_true(test, adc_get_last_conv_value(&g_adc_inst) > 2047,
			"ADCIFE Differential test failed");
}

/**
 * \brief Test ADCIFE in internal timer trigger mode,
 *        which also tests interrupt driven conversions.
 *
 * \param test Current test case.
 */
static void run_adcife_itimer_trig_test(const struct test_case *test)
{
	struct adc_seq_config adc_seq_cfg = {
		/* Select Vref for shift cycle */
		.zoomrange = ADC_ZOOMRANGE_0,
		/* Pad Ground */
		.muxneg = ADC_MUXNEG_1,
		/* Scaled Vcc, Vcc/10 */
		.muxpos = ADC_MUXPOS_2,
		/* Enables the internal voltage sources */
		.internal = ADC_INTERNAL_3,
		/* Disables the ADC gain error reduction */
		.gcomp = ADC_GCOMP_DIS,
		/* Disables the HWLA mode */
		.hwla = ADC_HWLA_DIS,
		/* 12-bits resolution */
		.res = ADC_RES_12_BIT,
		/* Enables the single-ended mode */
		.bipolar = ADC_BIPOLAR_SINGLEENDED
	};
	struct adc_ch_config adc_ch_cfg = {
		.seq_cfg = &adc_seq_cfg,
		/* Internal Timer Max Counter */
		.internal_timer_max_count = 60,
		/* Window monitor mode is off */
		.window_mode = 0,
		.low_threshold = 0,
		.high_threshold = 0,
	};

	adc_ch_set_config(&g_adc_inst, &adc_ch_cfg);
	adc_set_callback(&g_adc_inst, ADC_SEQ_SEOC, adcife_set_conv_flag,
			ADCIFE_IRQn, 1);
	adc_configure_trigger(&g_adc_inst, ADC_TRIG_INTL_TIMER);
	adc_configure_gain(&g_adc_inst, ADC_GAIN_1X);
	adc_configure_itimer_period(&g_adc_inst,
			adc_ch_cfg.internal_timer_max_count);
	adc_start_itimer(&g_adc_inst);
	delay_ms(100);

	test_assert_true(test, g_uc_condone_flag == 1,
			"ADCIFE Internal Timer trigger test failed");
}

/* When VDDANA is in MIN value = 2.4V, the equivalent voltage value is
 * (2400 * 255) / ((1 << 10) - 1) = 598mv. The relative digital value is
 * 598 * 4095 / 1000 = 2449. */
#define DAC_INTERNAL_MIN_VALUE          2449
/* When VDDANA is in MAX value = 3.6V the equivalent voltage value is
 * (3600 * 255) / ((1 << 10) - 1) = 897mv. The relative digital value is
 * 897 * 4095 / 1000 = 3673. */
#define DAC_INTERNAL_MAX_VALUE          3673
/* When VCC is in MIN value = 1.6V, the equivalent voltage value is
 * 1600 / 10 = 160mv. The relative digital value is
 * 160 * 4095 / 1000 = 434. */
#define VCC_SCALED_MIN_VALUE            434
/* When VCC is in MAX value = 3.6V, the equivalent voltage value is
 * 3600 / 10 = 360mv. The relative digital value is
 * 360 * 4095 / 1000 = 1474. */
#define VCC_SCALED_MAX_VALUE            1474

/**
 * \brief Test ADCIFE in multiple channel mode.
 *
 * \param test Current test case.
 */
static void run_adcife_multichannel_test(const struct test_case *test)
{
	start_dac();

	adc_pdca_set_config(&g_adc_pdca_cfg);
	pdca_channel_set_callback(CONFIG_ADC_PDCA_RX_CHANNEL, pdca_transfer_done,
			PDCA_0_IRQn, 1, PDCA_IER_TRC);
	adc_configure_trigger(&g_adc_inst, ADC_TRIG_CON);
	adc_configure_gain(&g_adc_inst, ADC_GAIN_1X);

	delay_ms(100);

	/* The DAC output voltage value is 823mv, so the equivalent ADC value should be
	 * 4095 * 823 / 1000 = 3370. The scaled VCC output voltage is 330mv, so the
	 * equivalent ADC value should be 4095 * 330 / 1000 =  1351. */
	test_assert_true(test,
			((DAC_INTERNAL_MIN_VALUE < g_adc_sample_data[0] < DAC_INTERNAL_MAX_VALUE)
			&& (VCC_SCALED_MIN_VALUE < g_adc_sample_data[1] < VCC_SCALED_MAX_VALUE)),
			"ADCIFE Multichannel test failed");
}

/**
 * \brief Test ADCIFE in window monitor mode.
 *
 * \param test Current test case.
 */
static void run_adcife_wm_test(const struct test_case *test)
{
	struct adc_seq_config adc_seq_cfg = {
		/* Select Vref for shift cycle */
		.zoomrange = ADC_ZOOMRANGE_0,
		/* Pad Ground */
		.muxneg = ADC_MUXNEG_1,
		/* Scaled Vcc, Vcc/10 */
		.muxpos = ADC_MUXPOS_2,
		/* Enables the internal voltage sources */
		.internal = ADC_INTERNAL_3,
		/* Disables the ADC gain error reduction */
		.gcomp = ADC_GCOMP_DIS,
		/* Disables the HWLA mode */
		.hwla = ADC_HWLA_DIS,
		/* 12-bits resolution */
		.res = ADC_RES_12_BIT,
		/* Enables the single-ended mode */
		.bipolar = ADC_BIPOLAR_SINGLEENDED
	};
	struct adc_ch_config adc_ch_cfg = {
		.seq_cfg = &adc_seq_cfg,
		/* Internal Timer Max Counter */
		.internal_timer_max_count = 60,
		/* Window monitor mode is off */
		.window_mode = ADC_WM_MODE_3,
		/*  The equivalent voltage value is 205 * 1000 / 4095 = 50mv. */
		.low_threshold = 205,
		/*  The equivalent voltage value is 2050 * 1000 / 4095 = 500mv. */
		.high_threshold = 2050,
	};

	adc_ch_set_config(&g_adc_inst, &adc_ch_cfg);
	adc_configure_trigger(&g_adc_inst, ADC_TRIG_CON);
	adc_configure_gain(&g_adc_inst, ADC_GAIN_1X);

	adc_set_callback(&g_adc_inst, ADC_WINDOW_MONITOR, adcife_set_wm_flag,
			ADCIFE_IRQn, 1);
	delay_ms(100);
	test_assert_true(test, g_uc_enter_win_flag == 1,
			"ADCIFE Inside Window Mode test failed");

	/* The teseted channel voltage is outside window */
	adc_disable(&g_adc_inst);
	g_uc_enter_win_flag = 0;
	adc_seq_cfg.muxpos = ADC_MUXPOS_3;
	adc_ch_set_config(&g_adc_inst, &adc_ch_cfg);
	adc_configure_trigger(&g_adc_inst, ADC_TRIG_CON);
	adc_configure_gain(&g_adc_inst, ADC_GAIN_1X);
	adc_enable_interrupt(&g_adc_inst, ADC_WINDOW_MONITOR);

	delay_ms(100);
	test_assert_true(test, g_uc_enter_win_flag == 0,
			"ADCIFE Outside Window Mode test failed");
}

/**
 * \brief Run ADCIFE driver unit tests.
 */
int main(void)
{
	const usart_serial_options_t usart_serial_options = {
		.baudrate = CONF_TEST_BAUDRATE,
		.charlength = CONF_TEST_CHARLENGTH,
		.paritytype = CONF_TEST_PARITY,
		.stopbits = CONF_TEST_STOPBITS
	};

	/* Initialize the system clock and board */
	sysclk_init();
	board_init();

	/* Enable the debug uart */
	stdio_serial_init(CONF_TEST_USART, &usart_serial_options);

#if defined(__GNUC__)
	setbuf(stdout, NULL);
#endif

	/* Define all the test cases */
	DEFINE_TEST_CASE(adcife_init_test, NULL, run_adcife_init_test, NULL,
			"ADCIFE Initialize test");
	DEFINE_TEST_CASE(adcife_diff_test, NULL, run_adcife_diff_test, NULL,
			"ADCIFE Differential test");
	DEFINE_TEST_CASE(adcife_itmer_trig_test, NULL, run_adcife_itimer_trig_test,
			NULL, "ADCIFE Internal Timer trigger test");
	DEFINE_TEST_CASE(adcife_multichannel_test, NULL, run_adcife_multichannel_test, NULL,
			"ADCIFE Multichannel test");
	DEFINE_TEST_CASE(adcife_wm_test, NULL, run_adcife_wm_test,
			NULL, "ADCIFE Window Monitor Mode test");

	/* Put test case addresses in an array */
	DEFINE_TEST_ARRAY(adcife_tests) = {
	&adcife_init_test,
	&adcife_diff_test,
	&adcife_itmer_trig_test,
	&adcife_multichannel_test,
	&adcife_wm_test,
	};

	/* Define the test suite */
	DEFINE_TEST_SUITE(adcife_suite, adcife_tests,
			"SAM ADCIFE driver test suite");

	/* Run all tests in the test suite */
	test_suite_run(&adcife_suite);

	while (1) {
		/* Busy-wait forever. */
	}
}
示例#20
0
/** Unit test to check that the gyroscope works correctly on the Inertial
 *  One board using the Sensor Platform library.
 *
 *  \param test  Pointer to the unit test case instance
 */
static void run_sensor_gyro_test(const struct test_case *test)
{
	sensor_t gyro;
	sensor_data_t gyro_data = { .scaled = true };
	
	configure_sensor_platform();
	
	sensor_attach(&gyro, SENSOR_TYPE_GYROSCOPE, 0, 0);	
	test_assert_false(test, gyro.err, "Error attaching to gyroscope");
	
	delay_ms(50);
	
	for (uint8_t i = 0; i < 10; i++) {	
		test_assert_true(test, sensor_get_rotation(&gyro, &gyro_data),
				"Gyroscope read failed");
		test_assert_false(test, gyro.err,
				"Gyroscope internal error");
				
		delay_ms(2);
	}	
}

/** Unit test to check that the accelerometer works correctly on the Inertial
 *  One board using the Sensor Platform library.
 *
 *  \param test  Pointer to the unit test case instance
 */
static void run_sensor_accel_test(const struct test_case *test)
{
	sensor_t accel;
	sensor_data_t accel_data = { .scaled = true };
	
	configure_sensor_platform();
	
	sensor_attach(&accel, SENSOR_TYPE_ACCELEROMETER, 0, 0);
	test_assert_false(test, accel.err, "Error attaching to accelerometer");
	
	delay_ms(50);
	
	for (uint8_t i = 0; i < 10; i++) {
		vector3_t accel_data_vect;
		
		test_assert_true(test, sensor_get_acceleration(&accel, &accel_data),
				"Accelerometer read failed");
		test_assert_false(test, accel.err,
				"Accelerometer internal error");
		
		accel_data_vect.x = accel_data.axis.x;
		accel_data_vect.y = accel_data.axis.y;
		accel_data_vect.z = accel_data.axis.z;
		
		scalar_t accel_mag = vector3_magnitude(&accel_data_vect);
		
		test_assert_true(test,
				(accel_mag > (1000 - 300)) && (accel_mag < (1000 + 300)),
				"Accelerometer returned value not close to 1000 milli-g: %i",
				(uint16_t)accel_mag);
				
		delay_ms(2);
	}	
}

/** Unit test to check that the compass works correctly on the Inertial
 *  One board using the Sensor Platform library.
 *
 *  \param test  Pointer to the unit test case instance
 */
static void run_sensor_compass_test(const struct test_case *test)
{
	sensor_t compass;
	sensor_data_t compass_data = { .scaled = true };
	
	configure_sensor_platform();
	
	sensor_attach(&compass, SENSOR_TYPE_COMPASS, 0, 0);
	test_assert_false(test, compass.err, "Error attaching to magnetometer");
	
	delay_ms(50);
	
	for (uint8_t i = 0; i < 10; i++) {
		vector3_t compass_data_vect;
		
		test_assert_true(test, sensor_get_heading(&compass, &compass_data),
				"Compass read failed");
		test_assert_false(test, compass.err,
				"Compass internal error");
		
		compass_data_vect.x = compass_data.heading.direction;
		compass_data_vect.y = compass_data.heading.inclination;
		compass_data_vect.z = compass_data.heading.strength;
		
		scalar_t compass_mag = vector3_magnitude(&compass_data_vect);
		
		test_assert_false(test, (compass_mag == 0),
				"Compass returned zero data");		
		
		delay_ms(2);
	}	
}

/** Unit test to check that the gyroscope internal temperature sensor works 
 *  correctly on the Inertial One board using the Sensor Platform library.
 *
 *  \param test  Pointer to the unit test case instance
 */
static void run_sensor_temp_test(const struct test_case *test)
{
	sensor_t gyro;
	sensor_data_t temp_data = { .scaled = true };
	
	configure_sensor_platform();
	
	sensor_attach(&gyro, SENSOR_TYPE_GYROSCOPE, 0, 0);
	test_assert_false(test, gyro.err, "Error attaching to gyroscope");
	
	delay_ms(50);
	
	for (uint8_t i = 0; i < 10; i++) {	
		test_assert_true(test, sensor_get_temperature(&gyro, &temp_data),
				"Gyroscope temperature read failed");
		test_assert_false(test, gyro.err,
				"Gyroscope internal error");
		
		test_assert_false(test, ((int16_t)temp_data.temperature.value == 0),
				"Gyroscope returned zero temperature data");

		test_assert_false(test, ((int16_t)temp_data.temperature.value > 40),
				"Gyroscope returned too high temperature data: %d",
				(int16_t)temp_data.temperature.value);

		delay_ms(2);
	}
}

int main(void)
{
	// Initialize the board and all the peripheral required
	sysclk_init();
	board_init();
	stdio_serial_init(CONF_TEST_USART, &usart_serial_options);

#if XMEGA
	pmic_init();
	sleepmgr_init();
#endif

	DEFINE_TEST_CASE(sensor_init_test, NULL, run_sensor_init_test,
			NULL, "Test sensor initialization");

	DEFINE_TEST_CASE(sensor_gyro_test, NULL, run_sensor_gyro_test,
			NULL, "Test gyroscope read");

	DEFINE_TEST_CASE(sensor_accel_test, NULL, run_sensor_accel_test,
			NULL, "Test accelerometer read");
	
	DEFINE_TEST_CASE(sensor_compass_test, NULL, run_sensor_compass_test,
			NULL, "Test compass read");

	DEFINE_TEST_CASE(sensor_temp_test, NULL, run_sensor_temp_test,
			NULL, "Test temperature read");
				
	DEFINE_TEST_ARRAY(sensor_tests) = {
		&sensor_init_test,
		&sensor_gyro_test,
		&sensor_accel_test,
		&sensor_compass_test,
		&sensor_temp_test
	};

	DEFINE_TEST_SUITE(sensor_suite,
			sensor_tests, "Common sensor plarform test suite");

	test_suite_run(&sensor_suite);

	while (1) {
		/* Intentionally left blank */
	}
}
示例#21
0
/**
 * \brief Run QDEC unit tests
 *
 * Initializes the clock system, board and serial output, then sets up the
 * QDEC unit test suite and runs it.
 */
int main(void)
{
	const usart_serial_options_t usart_serial_options = {
		.baudrate   = CONF_TEST_BAUDRATE,
		.charlength = CONF_TEST_CHARLENGTH,
		.paritytype = CONF_TEST_PARITY,
		.stopbits   = CONF_TEST_STOPBITS,
	};
	sysclk_init();
	board_init();
	sleepmgr_init();

	main_delay_init();

	stdio_serial_init(CONF_TEST_USART, &usart_serial_options);

	DEFINE_TEST_CASE(qdec_common_mode, NULL,
			run_qdec_common_mode, NULL,
			"QDEC Common mode Test");
#if XMEGA_E
	DEFINE_TEST_CASE(qdec_rotary_mode, NULL,
			run_qdec_rotary_mode, NULL,
			"QDEC Rotary mode Test");
#endif
	DEFINE_TEST_CASE(qdec_index1_mode, NULL,
			run_qdec_index1_mode, NULL,
			"QDEC Index (step 1) mode Test");
	DEFINE_TEST_CASE(qdec_index2_mode, NULL,
			run_qdec_index2_mode, NULL,
			"QDEC Index (step 2) mode Test");
	DEFINE_TEST_CASE(qdec_index3_mode, NULL,
			run_qdec_index3_mode, NULL,
			"QDEC Index (step 3) mode Test");
	DEFINE_TEST_CASE(qdec_index4_mode, NULL,
			run_qdec_index4_mode, NULL,
			"QDEC Index (step 4) mode Test");
	DEFINE_TEST_CASE(qdec_freq1_mode, NULL,
			run_qdec_freq1_mode, NULL,
			"QDEC Frequency mode Test1");
	DEFINE_TEST_CASE(qdec_freq2_mode, NULL,
			run_qdec_freq2_mode, NULL,
			"QDEC Frequency mode Test2");
	DEFINE_TEST_CASE(qdec_freq3_mode, NULL,
			run_qdec_freq3_mode, NULL,
			"QDEC Frequency mode Test3");

	/* Put test case addresses in an array */
	DEFINE_TEST_ARRAY(qdec_tests) = {
		&qdec_common_mode,
#if XMEGA_E
		&qdec_rotary_mode,
#endif
		&qdec_index1_mode,
		&qdec_index2_mode,
		&qdec_index3_mode,
		&qdec_index4_mode,
		&qdec_freq1_mode,
		&qdec_freq2_mode,
		&qdec_freq3_mode,
	};

	/* Define the test suite */
	DEFINE_TEST_SUITE(qdec_suite, qdec_tests,
			"XMEGA QDEC driver test suite");

	/* Run all tests in the suite */
	test_suite_run(&qdec_suite);

	while (1) {
		/* Intentionally left empty. */
	}
}
示例#22
0
/**
 * \internal
 * \brief Test for I2C master transfer.
 *
 * First test transfer function with stop.
 * write to slave, read from slave and then compare the data.
 * the slave send out the data it received,
 * so master write and read data should be the same.
 *
 * Then test transfer function without stop.
 * write to slave, then use i2c_master_send_stop to complete writing,
 * read from slave, compare the data.
 * finally, use function with stop to complete the transfer.
 *
 * \param test Current test case.
 */
static void run_i2c_master_transfer_test(const struct test_case *test)
{
	uint32_t timeout_cycles = 1000;
	uint32_t i;
	bool status = true;
	uint8_t read_buffer[DATA_LENGTH] = {0};
	struct i2c_master_packet packet = {
		.address     = SLAVE_ADDRESS,
		.data_length = DATA_LENGTH,
		.data        = write_buffer,
		.ten_bit_address = false,
		.high_speed      = false,
		.hs_master_code  = 0x0,
	};
	/* with stop function: master transfer test */
	/* wait the master write to complete */
	do {
		timeout_cycles--;
		if (i2c_master_write_packet_wait(&i2c_master_instance, &packet) ==
			STATUS_OK) {
			break;
		}
	} while (timeout_cycles > 0);
	test_assert_true(test, timeout_cycles > 0,
			"i2c master write failed");
	
	/* wait the master read to complete */
	packet.data = read_buffer;
	timeout_cycles = 1000;
	do {
		timeout_cycles--;
		if (i2c_master_read_packet_wait(&i2c_master_instance, &packet) ==
			STATUS_OK) {
			break;
		}
	} while (timeout_cycles > 0);
	test_assert_true(test, timeout_cycles > 0,
			"i2c master read failed");
	
		/* Compare the sent and the received */
	for (i = 0; i < DATA_LENGTH; i++) {
		if (read_buffer[i] != write_buffer[i]) {
			status = false;
			break;
		}
	}
	test_assert_true(test, status == true,
			"i2c master transfer comparsion failed");
	/* with stop function master transfer test end */
	
	/* without stop function: master transfer test*/
	/* wait the master write to finish */
	packet.data = write_buffer;
	timeout_cycles = 1000;
	do {

		timeout_cycles--;
		if (i2c_master_write_packet_wait_no_stop(&i2c_master_instance, &packet) ==
		STATUS_OK) {
			break;
		}
	} while (timeout_cycles > 0);
	test_assert_true(test, timeout_cycles > 0,
	"i2c master write without stop failed");
	
	/* use i2c_master_send_stop to complete master writing */
	i2c_master_send_stop(&i2c_master_instance);
	
	/* wait the master read to finish */
	packet.data = read_buffer;
	timeout_cycles = 1000;
	do {
		timeout_cycles--;
		if (i2c_master_read_packet_wait_no_stop(&i2c_master_instance, &packet) ==
		STATUS_OK) {
			break;
		}
	} while (timeout_cycles > 0);
	test_assert_true(test, timeout_cycles > 0,
	"i2c master read without stop failed");
	
	/* Compare the sent and the received */
	for (i = 0; i < DATA_LENGTH; i++) {
		if (read_buffer[i] != write_buffer[i]) {
			status = false;
			break;
		}
	}
	test_assert_true(test, status == true,
	"i2c master transfer without stop comparsion failed");
	
	/* use i2c_master_write_packet_wait to complete the transfer */
	packet.data = write_buffer;
	do {
		timeout_cycles--;
		if (i2c_master_write_packet_wait(&i2c_master_instance, &packet) ==
		STATUS_OK) {
			break;
		}
	} while (timeout_cycles > 0);
	test_assert_true(test, timeout_cycles > 0,
	"i2c master write with repeated start failed");
	
	/* without stop function: master transfer test end*/
}

/**
 * \internal
 * \brief Test full speed mode master transfer.
 *
 * test function with stop in full speed mode.
 * \param test Current test case.
 */
static void run_i2c_full_speed_test(const struct test_case *test)
{
	enum status_code status;
	struct i2c_master_config config_i2c_master;
	
	/* init i2c master in full speed mode*/
	i2c_master_get_config_defaults(&config_i2c_master);
	config_i2c_master.buffer_timeout = 10000;
	config_i2c_master.baud_rate = I2C_MASTER_BAUD_RATE_400KHZ;
	i2c_master_disable(&i2c_master_instance);
	status = i2c_master_init(&i2c_master_instance, SERCOM2, &config_i2c_master);
		/* Check for successful initialization */
	test_assert_true(test, status == STATUS_OK,
			"I2C master fast-mode initialization failed");
	i2c_master_enable(&i2c_master_instance);

	uint32_t timeout_cycles = 1000;
	uint32_t i;
	bool status1 = true;
	struct i2c_master_packet packet = {
		.address     = SLAVE_ADDRESS,
		.data_length = DATA_LENGTH,
		.data        = write_buffer,
		.ten_bit_address = false,
		.high_speed      = false,
		.hs_master_code  = 0x0,
	};
	
	 uint8_t read_buffer[DATA_LENGTH] = {0};
	
	/* wait master write complete */	 
	do {
		timeout_cycles--;
		if (i2c_master_write_packet_wait(&i2c_master_instance, &packet) ==
			STATUS_OK) {
			break;
		}
	} while (timeout_cycles > 0);
	test_assert_true(test, timeout_cycles > 0,
			"i2c master write failed");
	
	/* wait master read complete */
	packet.data = read_buffer;
	timeout_cycles = 1000;
	do {
		timeout_cycles--;
		if (i2c_master_read_packet_wait(&i2c_master_instance, &packet) ==
			STATUS_OK) {
			break;
		}
	} while (timeout_cycles > 0);
	test_assert_true(test, timeout_cycles > 0,
			"i2c master read failed");
	
		/* Compare the sent and the received */
	for (i = 0; i < DATA_LENGTH; i++) {
		if (read_buffer[i] != write_buffer[i]) {
			status1 = false;
			break;
		}
	}
	test_assert_true(test, status1 == true,
			"i2c master transfer comparsion failed");
}

	
/**
 * \brief Run I2C master unit tests
 *
 * Initializes the system and serial output, then sets up the
 * I2C master unit test suite and runs it.
 */
int main(void)
{
	system_init();
	cdc_uart_init();

	/* Define Test Cases */
	DEFINE_TEST_CASE(i2c_init_test,
			NULL,
			run_i2c_init_test,
			NULL,
			"Testing I2C Initialization");

	DEFINE_TEST_CASE(i2c_master_transfer_test,
			NULL,
			run_i2c_master_transfer_test,
			NULL,
			"Testing I2C master data transfer");

	DEFINE_TEST_CASE(i2c_full_speed_test,
			NULL,
			run_i2c_full_speed_test,
			NULL,
			"Testing I2C change speed transfer");

	/* Put test case addresses in an array */
	DEFINE_TEST_ARRAY(i2c_tests) = {
		&i2c_init_test,
		&i2c_master_transfer_test,
		&i2c_full_speed_test,

	};

	/* Define the test suite */
	DEFINE_TEST_SUITE(i2c_test_suite, i2c_tests,
			"SAM I2C driver test suite");

	/* Run all tests in the suite*/
	test_suite_run(&i2c_test_suite);

	while (true) {
		/* Intentionally left empty */
	}
}
示例#23
0
/**
 * \brief Run usb device cdc unit tests
 *
 * Initializes the clock system, board and serial output, then sets up the
 * usb unit test suite and runs it.
 */
int main(void)
{
    const usart_serial_options_t usart_serial_options = {
        .baudrate   = CONF_TEST_BAUDRATE,
        .charlength = CONF_TEST_CHARLENGTH,
        .paritytype = CONF_TEST_PARITY,
        .stopbits   = CONF_TEST_STOPBITS,
    };

    sysclk_init();
    irq_initialize_vectors();
    cpu_irq_enable();

    // Initialize the sleep manager
    sleepmgr_init();

    board_init();
    stdio_serial_init(CONF_TEST_USART, &usart_serial_options);

    // Define all the timestamp to date test cases
    DEFINE_TEST_CASE(usb_cdc_test, NULL,
                     run_usb_cdc_test, NULL,
                     "USB Device cdc enumeration test");
    DEFINE_TEST_CASE(usb_cdc_config_test, NULL,
                     run_usb_cdc_config_test, NULL,
                     "USB CDC configuration test");
    DEFINE_TEST_CASE(usb_vbus_test, NULL,
                     run_usb_vbus_test, NULL,
                     "USB vbus event test");
    DEFINE_TEST_CASE(usb_resume_test, NULL,
                     run_usb_resume_test, NULL,
                     "USB resume event test");
    DEFINE_TEST_CASE(usb_suspend_test, NULL,
                     run_usb_suspend_test, NULL,
                     "USB suspend event test");
    DEFINE_TEST_CASE(usb_sof_test, NULL,
                     run_usb_sof_test, NULL,
                     "USB sof event test");

    // Put test case addresses in an array
    DEFINE_TEST_ARRAY(usb_cdc_tests) = {
        &usb_cdc_test,
        &usb_cdc_config_test,
        &usb_vbus_test,
        &usb_resume_test,
        &usb_suspend_test,
        &usb_sof_test,
    };

    // Define the test suite
    DEFINE_TEST_SUITE(usb_cdc_suite, usb_cdc_tests,
                      "Common usb CDC service with test suite");

    // The unit test prints message via UART which does not support deep sleep mode.
#if SAM
    sleepmgr_lock_mode(SLEEPMGR_ACTIVE);
#else
    sleepmgr_lock_mode(SLEEPMGR_IDLE);
#endif

    // Run all tests in the suite
    test_suite_run(&usb_cdc_suite);

    while (1) {
        // Intentionally left empty.
    }
}
示例#24
0
/**
 * \internal
 * \brief Test conversion of first date to timestamp
 *
 * This test checks that conversion of the first date in UNIX time date results
 * in timestamp 0.
 *
 * \param test Current test case.
 */
static void run_date_to_timestamp_0_test(const struct test_case *test)
{
	uint32_t expected = 0;
	uint32_t actual;

	struct calendar_date testvar = {
		.second = 0,
		.minute = 0,
		.hour = 0,
		.date = 0,
		.month = 0,
		.year = 1970
		};
	actual = calendar_date_to_timestamp(&testvar);
	test_assert_true(test, actual == expected,
			"Date January 1st 1970, 00:00:00, %d != %d",
			actual, expected);
}

/**
 * \internal
 * \brief Test conversion of a date with invalid time to timestamp
 *
 * This test checks that conversion of a date with 83 seconds results in
 * timestamp 0.
 *
 * \param test Current test case.
 */
static void run_erronous_time_to_timestamp_test(const struct test_case *test)
{
	uint32_t expected = 0;
	uint32_t actual;

	struct calendar_date testvar = {
		.second = 83,
		.minute = 12,
		.hour = 11,
		.date = 21,
		.month = 4,
		.year = 1983
		};

	actual = calendar_date_to_timestamp(&testvar);
	test_assert_true(test, actual == expected,
			"Wrong date May 12th 1983, 11:12:83, %d != %d",
			actual, expected);
}

/**
 * \internal
 * \brief Test conversion of a date with invalid day to timestamp
 *
 * This test checks that conversion of February 29th in a year that is not
 * a leap year results in timestamp 0.
 *
 * \param test Current test case.
 */
static void run_erronous_date_to_timestamp_test(const struct test_case *test)
{
	uint32_t expected = 0;
	uint32_t actual;

	struct calendar_date testvar = {
		.second = 53,
		.minute = 1,
		.hour = 15,
		.date = 28,
		.month = 1,
		.year = 1983
		};

	actual = calendar_date_to_timestamp(&testvar);
	test_assert_true(test, actual == expected,
			"Wrong date February 29th 1983, 15:01:53, %d != %d",
			actual, expected);
}

/**
 * \internal
 * \brief Test conversion of a date in a leap year to timestamp
 *
 * This test checks that conversion of February 29th in a year that is a leap
 * year results in the correct timestamp.
 *
 * \param test Current test case.
 */
static void run_leap_year_date_to_timestamp_test(const struct test_case *test)
{
	uint32_t expected = 1204245932;
	uint32_t actual;

	struct calendar_date testvar = {
		.second = 32,
		.minute = 45,
		.hour = 0,
		.date = 28,
		.month = 1,
		.year = 2008
		};

	actual = calendar_date_to_timestamp(&testvar);
	test_assert_true(test, actual == expected,
			"Date February 29th 2008, 00:45:32, %d != %d",
			actual, expected);
}

/**
 * \internal
 * \brief Test conversion of a normal date to timestamp
 *
 * This test checks that conversion of a normal date results in the correct
 * timestamp.
 *
 * \param test Current test case.
 */
static void run_date_to_timestamp_test(const struct test_case *test)
{
	uint32_t expected = 479258400;
	uint32_t actual;

	struct calendar_date testvar = {
		.second = 0,
		.minute = 20,
		.hour = 23,
		.date = 8,
		.month = 2,
		.year = 1985
		};

	actual = calendar_date_to_timestamp(&testvar);
	test_assert_true(test, actual == expected,
			"Date March 9th 1985, 23:20:00, %d != %d",
			actual, expected);
}

/**
 * \internal
 * \brief Test conversion of a date before 1970 to timestamp 0
 *
 * This test checks that conversion of a date before epoch year 1970 results in
 * timestamp 0.
 *
 * \param test Current test case.
 */
static void run_date_1855_to_timestamp_test(const struct test_case *test)
{
	uint32_t expected = 0;
	uint32_t actual;

	struct calendar_date testvar = {
		.second = 7,
		.minute = 14,
		.hour = 3,
		.date = 18,
		.month = 0,
		.year = 1855
		};

	actual = calendar_date_to_timestamp(&testvar);
	test_assert_true(test, actual == expected,
			"Date January 19th 1855, 03:14:07, %d != %d",
			actual, expected);
}

/**
 * \internal
 * \brief Test conversion of a date after 2106 to timestamp 0
 *
 * This test checks that conversion of a date after overflow year 2106 results
 * in timestamp 0.
 *
 * \param test Current test case.
 */
static void run_date_2107_to_timestamp_test(const struct test_case *test)
{
	uint32_t expected = 0;
	uint32_t actual;

	struct calendar_date testvar = {
		.second = 7,
		.minute = 14,
		.hour = 3,
		.date = 18,
		.month = 0,
		.year = 2107
		};

	actual = calendar_date_to_timestamp(&testvar);
	test_assert_true(test, actual == expected,
			"Date January 19th 2107, 03:14:07, %d != %d",
			actual, expected);
}

/**
* \internal
 * \brief Test computation of time between dates in the same year
 *
 * This test checks that computing time between dates in the same year returns
 * the expected duration.
 *
 * \param test Current test case.
 */
static void run_time_between_dates_same_year_test(const struct test_case *test)
{
	struct calendar_date expected;
	struct calendar_date actual;
	uint32_t testvar_start;
	uint32_t testvar_end;

	struct calendar_date testcal_end;
	struct calendar_date testcal_start;

	expected.second = 8;
	expected.minute = 10;
	expected.hour = 22;
	expected.date = 15;
	expected.month = 1;
	expected.year = 0;

	testvar_start = 1306329300;
	testvar_end = 1310383508;
	calendar_timestamp_to_date(testvar_start, &testcal_start);
	calendar_timestamp_to_date(testvar_end, &testcal_end);

	calendar_time_between_dates(&testcal_end, &testcal_start, &actual);

	test_assert_true(test, actual.second == expected.second,
			"Second mismatch %d != %d", actual.second, expected.second);
	test_assert_true(test, actual.minute == expected.minute,
			"Minute mismatch %d != %d", actual.minute, expected.minute);
	test_assert_true(test, actual.hour == expected.hour,
			"Hour mismatch %d != %d", actual.hour, expected.hour);
	test_assert_true(test, actual.date == expected.date,
			"Date mismatch %d != %d", actual.date, expected.date);
	test_assert_true(test, actual.month == expected.month,
			"Month mismatch %d != %d", actual.month, expected.month);
	test_assert_true(test, actual.year == expected.year,
			"Year mismatch %d != %d", actual.year, expected.year);
}

/**
* \internal
 * \brief Test computation of time between dates in the different years
 *
 * This test checks that computing time between dates in the different years,
 * but less than one year apart results in the expected duration.
 *
 * \param test Current test case.
 */
static void run_time_between_dates_diff_year_test(const struct test_case *test)
{
	struct calendar_date expected;
	struct calendar_date actual;
	uint32_t testvar_start;
	uint32_t testvar_end;

	struct calendar_date testcal_end;
	struct calendar_date testcal_start;

	expected.second = 8;
	expected.minute = 10;
	expected.hour = 22;
	expected.date = 16;
	expected.month = 10;
	expected.year = 0;

	testvar_start = 1274793300;
	testvar_end = 1302521108;

	calendar_timestamp_to_date(testvar_start, &testcal_start);
	calendar_timestamp_to_date(testvar_end, &testcal_end);

	calendar_time_between_dates(&testcal_end, &testcal_start, &actual);

	test_assert_true(test, actual.second == expected.second,
			"Second mismatch %d != %d", actual.second, expected.second);
	test_assert_true(test, actual.minute == expected.minute,
			"Minute mismatch %d != %d", actual.minute, expected.minute);
	test_assert_true(test, actual.hour == expected.hour,
			"Hour mismatch %d != %d", actual.hour, expected.hour);
	test_assert_true(test, actual.date == expected.date,
			"Date mismatch %d != %d", actual.date, expected.date);
	test_assert_true(test, actual.month == expected.month,
			"Month mismatch %d != %d", actual.month, expected.month);
	test_assert_true(test, actual.year == expected.year,
			"Year mismatch %d != %d", actual.year, expected.year);
}

/**
* \internal
 * \brief Test computation of time between dates in the same leap year
 *
 * This test checks that computing time between dates in the same leap year
 * results the expected duration.
 *
 * \param test Current test case.
 */
static void run_time_between_dates_leap_year_test(const struct test_case *test)
{
	struct calendar_date expected;
	struct calendar_date actual;
	uint32_t testvar_start;
	uint32_t testvar_end;

	struct calendar_date testcal_end;
	struct calendar_date testcal_start;

	expected.second = 8;
	expected.minute = 3;
	expected.hour = 19;
	expected.date = 16;
	expected.month = 1;
	expected.year = 0;

	testvar_start = 1203956520;
	testvar_end = 1207913108;
	calendar_timestamp_to_date(testvar_start, &testcal_start);
	calendar_timestamp_to_date(testvar_end, &testcal_end);

	calendar_time_between_dates(&testcal_end, &testcal_start, &actual);

	test_assert_true(test, actual.second == expected.second,
			"Second mismatch %d != %d", actual.second, expected.second);
	test_assert_true(test, actual.minute == expected.minute,
			"Minute mismatch %d != %d", actual.minute, expected.minute);
	test_assert_true(test, actual.hour == expected.hour,
			"Hour mismatch %d != %d", actual.hour, expected.hour);
	test_assert_true(test, actual.date == expected.date,
			"Date mismatch %d != %d", actual.date, expected.date);
	test_assert_true(test, actual.month == expected.month,
			"Month mismatch %d != %d", actual.month, expected.month);
	test_assert_true(test, actual.year == expected.year,
			"Year mismatch %d != %d", actual.year, expected.year);
}

/**
* \internal
 * \brief Test computation of time between dates several years apart
 *
 * This test checks that computing time between dates several years apart
 * results in the expected duration.
 *
 * \param test Current test case.
 */
static void run_time_between_dates_years_test(const struct test_case *test)
{
	struct calendar_date expected;
	struct calendar_date actual;
	uint32_t testvar_start;
	uint32_t testvar_end;

	struct calendar_date testcal_end;
	struct calendar_date testcal_start;

	expected.second = 8;
	expected.minute = 5;
	expected.hour = 12;
	expected.date = 12;
	expected.month = 3;
	expected.year = 26;

	testvar_start = 479258400;
	testvar_end = 1308741908;
	calendar_timestamp_to_date(testvar_start, &testcal_start);
	calendar_timestamp_to_date(testvar_end, &testcal_end);

	calendar_time_between_dates(&testcal_end, &testcal_start, &actual);

	test_assert_true(test, actual.second == expected.second,
			"Second mismatch %d != %d", actual.second, expected.second);
	test_assert_true(test, actual.minute == expected.minute,
			"Minute mismatch %d != %d", actual.minute, expected.minute);
	test_assert_true(test, actual.hour == expected.hour,
			"Hour mismatch %d != %d", actual.hour, expected.hour);
	test_assert_true(test, actual.date == expected.date,
			"Date mismatch %d != %d", actual.date, expected.date);
	test_assert_true(test, actual.month == expected.month,
			"Month mismatch %d != %d", actual.month, expected.month);
	test_assert_true(test, actual.year == expected.year,
			"Year mismatch %d != %d", actual.year, expected.year);
}

/**
* \internal
 * \brief Test computation of time between dates several years apart
 *
 * This test checks that computing time between dates several years apart
 * results in the expected duration.
 *
 * \param test Current test case.
 */
static void run_time_between_dates_years2_test(const struct test_case *test)
{
	struct calendar_date expected;
	struct calendar_date actual;
	uint32_t testvar_start;
	uint32_t testvar_end;

	struct calendar_date testcal_end;
	struct calendar_date testcal_start;

	expected.second = 16;
	expected.minute = 11;
	expected.hour = 8;
	expected.date = 11;
	expected.month = 6;
	expected.year = 20;

	testvar_start = 288109292;
	testvar_end = 935879568;
	calendar_timestamp_to_date(testvar_start, &testcal_start);
	calendar_timestamp_to_date(testvar_end, &testcal_end);

	calendar_time_between_dates(&testcal_end, &testcal_start, &actual);

	test_assert_true(test, actual.second == expected.second,
			"Second mismatch %d != %d", actual.second, expected.second);
	test_assert_true(test, actual.minute == expected.minute,
			"Minute mismatch %d != %d", actual.minute, expected.minute);
	test_assert_true(test, actual.hour == expected.hour,
			"Hour mismatch %d != %d", actual.hour, expected.hour);
	test_assert_true(test, actual.date == expected.date,
			"Date mismatch %d != %d", actual.date, expected.date);
	test_assert_true(test, actual.month == expected.month,
			"Month mismatch %d != %d", actual.month, expected.month);
	test_assert_true(test, actual.year == expected.year,
			"Year mismatch %d != %d", actual.year, expected.year);
}

/**
* \internal
 * \brief Test computation of time between dates with end before start
 *
 * This test checks that computing time between dates several years apart
 * where end date is earlier than start date results in the expected duration.
 *
 * \param test Current test case.
 */
static void run_time_between_dates_exchanged_test(const struct test_case *test)
{
	struct calendar_date expected;
	struct calendar_date actual;
	uint32_t testvar_start;
	uint32_t testvar_end;

	struct calendar_date testcal_end;
	struct calendar_date testcal_start;

	expected.second = 16;
	expected.minute = 11;
	expected.hour = 8;
	expected.date = 11;
	expected.month = 6;
	expected.year = 20;

	testvar_start = 935879568;
	testvar_end = 288109292;

	calendar_timestamp_to_date(testvar_start, &testcal_start);
	calendar_timestamp_to_date(testvar_end, &testcal_end);

	calendar_time_between_dates(&testcal_end, &testcal_start, &actual);

	test_assert_true(test, actual.second == expected.second,
			"Second mismatch %d != %d", actual.second, expected.second);
	test_assert_true(test, actual.minute == expected.minute,
			"Minute mismatch %d != %d", actual.minute, expected.minute);
	test_assert_true(test, actual.hour == expected.hour,
			"Hour mismatch %d != %d", actual.hour, expected.hour);
	test_assert_true(test, actual.date == expected.date,
			"Date mismatch %d != %d", actual.date, expected.date);
	test_assert_true(test, actual.month == expected.month,
			"Month mismatch %d != %d", actual.month, expected.month);
	test_assert_true(test, actual.year == expected.year,
			"Year mismatch %d != %d", actual.year, expected.year);
}

/**
 * \internal
 * \brief Test adding one second to a normal date
 *
 * This test checks that incrementing a normal date with one second gives
 * the correct result.
 *
 * \param test Current test case.
 */
static void run_add_second_to_normal_date_test(const struct test_case *test)
{
	struct calendar_date actual;
	struct calendar_date expected;

	// Add one second to a normal date
	actual.second = 45;
	actual.minute = 19;
	actual.hour = 22;
	actual.date = 12;
	actual.month = 2;
	actual.year = 2001;

	expected.second = 46;
	expected.minute = 19;
	expected.hour = 22;
	expected.date = 12;
	expected.month = 2;
	expected.year = 2001;

	calendar_add_second_to_date(&actual);
	test_assert_true(test, actual.second == expected.second,
			"Second mismatch %d != %d", actual.second, expected.second);
	test_assert_true(test, actual.minute == expected.minute,
			"Minute mismatch %d != %d", actual.minute, expected.minute);
	test_assert_true(test, actual.hour == expected.hour,
			"Hour mismatch %d != %d", actual.hour, expected.hour);
	test_assert_true(test, actual.date == expected.date,
			"Date mismatch %d != %d", actual.date, expected.date);
	test_assert_true(test, actual.month == expected.month,
			"Month mismatch %d != %d", actual.month, expected.month);
	test_assert_true(test, actual.year == expected.year,
			"Year mismatch %d != %d", actual.year, expected.year);
}

/**
 * \internal
 * \brief Test adding one second to the end of a day
 *
 * This test checks that incrementing the end of a day with one second gives
 * the correct result.
 *
 * \param test Current test case.
 */
static void run_add_second_to_end_of_day_test(const struct test_case *test)
{
	struct calendar_date actual;
	struct calendar_date expected;

	actual.second = 59;
	actual.minute = 59;
	actual.hour = 23;
	actual.date = 11;
	actual.month = 8;
	actual.year = 2005;

	expected.second = 0;
	expected.minute = 0;
	expected.hour = 0;
	expected.date = 12;
	expected.month = 8;
	expected.year = 2005;

	calendar_add_second_to_date(&actual);
	test_assert_true(test, actual.second == expected.second,
			"Second mismatch %d != %d", actual.second, expected.second);
	test_assert_true(test, actual.minute == expected.minute,
			"Minute mismatch %d != %d", actual.minute, expected.minute);
	test_assert_true(test, actual.hour == expected.hour,
			"Hour mismatch %d != %d", actual.hour, expected.hour);
	test_assert_true(test, actual.date == expected.date,
			"Date mismatch %d != %d", actual.date, expected.date);
	test_assert_true(test, actual.month == expected.month,
			"Month mismatch %d != %d", actual.month, expected.month);
	test_assert_true(test, actual.year == expected.year,
			"Year mismatch %d != %d", actual.year, expected.year);
}

/**
 * \internal
 * \brief Test adding one second to the 28th of February, normal year
 *
 * This test checks that incrementing the end of February 28th in a year
 * that is not a leap year with one second results in March 1st.
 *
 * \param test Current test case.
 */
static void run_add_second_to_end_feb_test(const struct test_case *test)
{
	struct calendar_date actual;
	struct calendar_date expected;

	actual.second = 59;
	actual.minute = 59;
	actual.hour = 23;
	actual.date = 27;
	actual.month = 1;
	actual.year = 2011;

	expected.second = 0;
	expected.minute = 0;
	expected.hour = 0;
	expected.date = 0;
	expected.month = 2;
	expected.year = 2011;

	calendar_add_second_to_date(&actual);
	test_assert_true(test, actual.second == expected.second,
			"Second mismatch %d != %d", actual.second, expected.second);
	test_assert_true(test, actual.minute == expected.minute,
			"Minute mismatch %d != %d", actual.minute, expected.minute);
	test_assert_true(test, actual.hour == expected.hour,
			"Hour mismatch %d != %d", actual.hour, expected.hour);
	test_assert_true(test, actual.date == expected.date,
			"Date mismatch %d != %d", actual.date, expected.date);
	test_assert_true(test, actual.month == expected.month,
			"Month mismatch %d != %d", actual.month, expected.month);
	test_assert_true(test, actual.year == expected.year,
			"Year mismatch %d != %d", actual.year, expected.year);
}

/**
 * \internal
 * \brief Test adding one second to the 28th of February, leap year
 *
 * This test checks that incrementing the end of February 28th in a year
 * that is not a leap year with one second results in February 29th.
 *
 * \param test Current test case.
 */
static void run_add_second_to_leap_year_feb_test(const struct test_case *test)
{
	struct calendar_date actual;
	struct calendar_date expected;

	actual.second = 59;
	actual.minute = 59;
	actual.hour = 23;
	actual.date = 27;
	actual.month = 1;
	actual.year = 2008;

	expected.second = 0;
	expected.minute = 0;
	expected.hour = 0;
	expected.date = 28;
	expected.month = 1;
	expected.year = 2008;

	calendar_add_second_to_date(&actual);
	test_assert_true(test, actual.second == expected.second,
			"Second mismatch %d != %d", actual.second, expected.second);
	test_assert_true(test, actual.minute == expected.minute,
			"Minute mismatch %d != %d", actual.minute, expected.minute);
	test_assert_true(test, actual.hour == expected.hour,
			"Hour mismatch %d != %d", actual.hour, expected.hour);
	test_assert_true(test, actual.date == expected.date,
			"Date mismatch %d != %d", actual.date, expected.date);
	test_assert_true(test, actual.month == expected.month,
			"Month mismatch %d != %d", actual.month, expected.month);
	test_assert_true(test, actual.year == expected.year,
			"Year mismatch %d != %d", actual.year, expected.year);
}

/**
 * \internal
 * \brief Test adding one second to the end of February, leap year
 *
 * This test checks that incrementing the end of February 29th in a year
 * that is a leap year with one second results in March 1st.
 *
 * \param test Current test case.
 */
static void run_add_second_to_leap_year_feb2_test(const struct test_case *test)
{
	struct calendar_date actual;
	struct calendar_date expected;

	actual.second = 59;
	actual.minute = 59;
	actual.hour = 23;
	actual.date = 28;
	actual.month = 1;
	actual.year = 2008;

	expected.second = 0;
	expected.minute = 0;
	expected.hour = 0;
	expected.date = 0;
	expected.month = 2;
	expected.year = 2008;

	calendar_add_second_to_date(&actual);
	test_assert_true(test, actual.second == expected.second,
			"Second mismatch %d != %d", actual.second, expected.second);
	test_assert_true(test, actual.minute == expected.minute,
			"Minute mismatch %d != %d", actual.minute, expected.minute);
	test_assert_true(test, actual.hour == expected.hour,
			"Hour mismatch %d != %d", actual.hour, expected.hour);
	test_assert_true(test, actual.date == expected.date,
			"Date mismatch %d != %d", actual.date, expected.date);
	test_assert_true(test, actual.month == expected.month,
			"Month mismatch %d != %d", actual.month, expected.month);
	test_assert_true(test, actual.year == expected.year,
			"Year mismatch %d != %d", actual.year, expected.year);
}

/**
 * \internal
 * \brief Test adding one second to the end of a year
 *
 * This test checks that incrementing the end of a day year results in
 * start of a new year.
 *
 * \param test Current test case.
 */
static void run_add_second_to_end_of_year_test(const struct test_case *test)
{
	struct calendar_date actual;
	struct calendar_date expected;

	actual.second = 59;
	actual.minute = 59;
	actual.hour = 23;
	actual.date = 30;
	actual.month = 11;
	actual.year = 1993;

	expected.second = 0;
	expected.minute = 0;
	expected.hour = 0;
	expected.date = 0;
	expected.month = 0;
	expected.year = 1994;

	calendar_add_second_to_date(&actual);
	test_assert_true(test, actual.second == expected.second,
			"Second mismatch %d != %d", actual.second, expected.second);
	test_assert_true(test, actual.minute == expected.minute,
			"Minute mismatch %d != %d", actual.minute, expected.minute);
	test_assert_true(test, actual.hour == expected.hour,
			"Hour mismatch %d != %d", actual.hour, expected.hour);
	test_assert_true(test, actual.date == expected.date,
			"Date mismatch %d != %d", actual.date, expected.date);
	test_assert_true(test, actual.month == expected.month,
			"Month mismatch %d != %d", actual.month, expected.month);
	test_assert_true(test, actual.year == expected.year,
			"Year mismatch %d != %d", actual.year, expected.year);
}
//@}

/**
 * \brief Run calendar service unit tests
 *
 * Initializes the clock system, board and serial output, then sets up the
 * calendar unit test suite and runs it.
 */
int main(void)
{

	const usart_serial_options_t usart_serial_options = {
		.baudrate   = CONF_TEST_BAUDRATE,
		.charlength = CONF_TEST_CHARLENGTH,
		.paritytype = CONF_TEST_PARITY,
		.stopbits   = CONF_TEST_STOPBITS,
	};
	sysclk_init();
	board_init();
	stdio_serial_init(CONF_TEST_USART, &usart_serial_options);

	// Define all the timestamp to date test cases
	DEFINE_TEST_CASE(timestamp_to_normal_date_test, NULL,
			run_timestamp_to_normal_date_test, NULL,
			"Stamp to normal date test");
	DEFINE_TEST_CASE(timestamp_0_to_date_test, NULL,
			run_timestamp_0_to_date_test, NULL, "Stamp 0 to date test");
	DEFINE_TEST_CASE(timestamp_to_leap_year_date_test, NULL,
			run_timestamp_to_leap_year_date_test, NULL,
			"Stamp to leap year date test");
	DEFINE_TEST_CASE(timestamp_to_leap_year_date2_test, NULL,
			run_timestamp_to_leap_year_date2_test, NULL,
			"Stamp to leap year date2 test");

	// Define all the date to timestamp test cases
	DEFINE_TEST_CASE(date_to_timestamp_0_test, NULL,
			run_date_to_timestamp_0_test, NULL, "Date to stamp 0 test");
	DEFINE_TEST_CASE(erronous_time_to_timestamp_test, NULL,
			run_erronous_time_to_timestamp_test, NULL,
			"Erronous time to stamp test");
	DEFINE_TEST_CASE(erronous_date_to_timestamp_test, NULL,
			run_erronous_date_to_timestamp_test, NULL,
			"Erronous date to stamp test");
	DEFINE_TEST_CASE(leap_year_date_to_timestamp_test, NULL,
			run_leap_year_date_to_timestamp_test, NULL,
			"Leap year date to stamp test");
	DEFINE_TEST_CASE(date_to_timestamp_test, NULL,
			run_date_to_timestamp_test, NULL, "Date to stamp test");
	DEFINE_TEST_CASE(date_1855_to_timestamp_test, NULL,
			run_date_1855_to_timestamp_test, NULL, "1855 date to stamp test");
	DEFINE_TEST_CASE(date_2107_to_timestamp_test, NULL,
			run_date_2107_to_timestamp_test, NULL, "2107 date to stamp test");

	// Define all the time between dates test cases
	DEFINE_TEST_CASE(time_between_dates_same_year_test, NULL,
			run_time_between_dates_same_year_test, NULL,
			"Time between dates in same year test");
	DEFINE_TEST_CASE(time_between_dates_diff_year_test, NULL,
			run_time_between_dates_diff_year_test, NULL,
			"Time between dates in different years test");
	DEFINE_TEST_CASE(time_between_dates_leap_year_test, NULL,
			run_time_between_dates_leap_year_test, NULL,
			"Time between dates in leap year test");
	DEFINE_TEST_CASE(time_between_dates_years_test, NULL,
			run_time_between_dates_years_test, NULL,
			"Time between dates several years apart test");
	DEFINE_TEST_CASE(time_between_dates_years2_test, NULL,
			run_time_between_dates_years2_test, NULL,
			"Time between dates several years apart test2");
	DEFINE_TEST_CASE(time_between_dates_exchanged_test, NULL,
			run_time_between_dates_exchanged_test, NULL,
			"Time between dates with end before start test");

			// Define all the add second to date test cases
	DEFINE_TEST_CASE(add_second_to_normal_date_test, NULL,
			run_add_second_to_normal_date_test, NULL,
			"Add second to normal date test");
	DEFINE_TEST_CASE(add_second_to_end_of_day_test, NULL,
			run_add_second_to_end_of_day_test, NULL,
			"Add second to end of day test");
	DEFINE_TEST_CASE(add_second_to_end_feb_test, NULL,
			run_add_second_to_end_feb_test, NULL,
			"Add second to 28th of February, normal year test");
	DEFINE_TEST_CASE(add_second_to_leap_year_feb_test, NULL,
			run_add_second_to_leap_year_feb_test, NULL,
			"Add second to 28th of February, leap year test");
	DEFINE_TEST_CASE(add_second_to_leap_year_feb2_test, NULL,
			run_add_second_to_leap_year_feb2_test, NULL,
			"Add second to 29th of February, leap year test");
	DEFINE_TEST_CASE(add_second_to_end_of_year_test, NULL,
			run_add_second_to_end_of_year_test, NULL,
			"Add second to end of year test");

	// Put test case addresses in an array
	DEFINE_TEST_ARRAY(calendar_tests) = {
		&timestamp_to_normal_date_test,
		&timestamp_0_to_date_test,
		&timestamp_to_leap_year_date_test,
		&timestamp_to_leap_year_date2_test,
		&date_to_timestamp_0_test,
		&erronous_time_to_timestamp_test,
		&erronous_date_to_timestamp_test,
		&leap_year_date_to_timestamp_test,
		&date_to_timestamp_test,
		&date_1855_to_timestamp_test,
		&date_2107_to_timestamp_test,
		&time_between_dates_same_year_test,
		&time_between_dates_diff_year_test,
		&time_between_dates_leap_year_test,
		&time_between_dates_years_test,
		&time_between_dates_years2_test,
		&time_between_dates_exchanged_test,
		&add_second_to_normal_date_test,
		&add_second_to_end_of_day_test,
		&add_second_to_end_feb_test,
		&add_second_to_leap_year_feb_test,
		&add_second_to_leap_year_feb2_test,
		&add_second_to_end_of_year_test,
	};

	// Define the test suite
	DEFINE_TEST_SUITE(calendar_suite, calendar_tests,
			"Common calendar service with test suite");

	// Run all tests in the suite
	test_suite_run(&calendar_suite);

	while (1) {
		// Intentionally left empty.
	}
}
示例#25
0
/**
 * \internal
 * \brief This test sends a packet from the master, and checks
 * that the sending happens without errors.
 *
 * \param test Current test case.
 */
static void run_twi_master_send_test(
		const struct test_case *test)
{
	status_code_t master_status;
	// Package to send
	twi_package_t packet = {
		// No address or command
		.addr_length = 0,
		// issue to slave
		.chip        = TWI_SLAVE_ADDR,
		.buffer      = (void *)test_pattern,
		.length      = PATTERN_TEST_LENGTH,
		// Wait if bus is busy
		.no_wait     = false
	};

	// TWI master options
	twi_options_t m_options = {
		.speed = TWI_SPEED,
		.chip  = TWI_MASTER_ADDR,
		.speed_reg = TWI_BAUD(sysclk_get_cpu_hz(), TWI_SPEED)
	};

	irq_initialize_vectors();

	// Initialize TWI_MASTER
	sysclk_enable_peripheral_clock(&TWI_MASTER);
	twi_master_init(&TWI_MASTER, &m_options);
	twi_master_enable(&TWI_MASTER);

	// Initialize TWI_SLAVE
	sysclk_enable_peripheral_clock(&TWI_SLAVE);
	TWI_SlaveInitializeDriver(&slave, &TWI_SLAVE, *slave_process);
	TWI_SlaveInitializeModule(&slave, TWI_SLAVE_ADDR,
			TWI_SLAVE_INTLVL_MED_gc);

	cpu_irq_enable();

	// Send package to slave
	master_status = twi_master_write(&TWI_MASTER, &packet);

	test_assert_true(test, master_status == STATUS_OK,
			"Master write not ok");
}

/**
 * \internal
 * \brief This test sends a packet from the master to the slave,
 * and checks that the correct packet is received.
 *
 * \param test Current test case.
 */
static void run_twi_slave_recv_test(
		const struct test_case *test)
{
	uint8_t i = 0;

	// Package to send
	twi_package_t packet = {
		// No address or command to issue to slave
		.addr_length = 0,
		.chip        = TWI_SLAVE_ADDR,
		.buffer      = (void *)test_pattern,
		.length      = PATTERN_TEST_LENGTH,
		// Wait if bus is busy
		.no_wait      = false
	};

	// TWI master options
	twi_options_t m_options = {
		.speed = TWI_SPEED,
		.chip  = TWI_MASTER_ADDR,
		.speed_reg = TWI_BAUD(sysclk_get_cpu_hz(), TWI_SPEED)
	};

	irq_initialize_vectors();

	// Initialize TWI_MASTER
	sysclk_enable_peripheral_clock(&TWI_MASTER);
	twi_master_init(&TWI_MASTER, &m_options);
	twi_master_enable(&TWI_MASTER);

	// Initialize TWI_SLAVE
	for (i = 0; i < TWIS_SEND_BUFFER_SIZE; i++) {
		slave.receivedData[i] = 0;
	}
	sysclk_enable_peripheral_clock(&TWI_SLAVE);
	TWI_SlaveInitializeDriver(&slave, &TWI_SLAVE, *slave_process);
	TWI_SlaveInitializeModule(&slave, TWI_SLAVE_ADDR,
			TWI_SLAVE_INTLVL_MED_gc);

	cpu_irq_enable();

	// Send package to slave
	twi_master_write(&TWI_MASTER, &packet);

	// Wait for slave to receive packet and check that packet is correct
	do {} while (slave.result != TWIS_RESULT_OK);
	for (i = 0; i < PATTERN_TEST_LENGTH; i++) {
		test_assert_true(test, slave.receivedData[i] == test_pattern[i],
				"Wrong data[%d] received, %d != %d", i,
				slave.receivedData[i],
				test_pattern[i]);
	}
}

/**
 * \internal
 * \brief This test requests a packet to be sent from the slave,
 * and checks that the correct packet is received by the master.
 *
 * \param test Current test case.
 */
static void run_twi_master_recv_test(const struct test_case *test)
{
	uint8_t i = 0;
	uint8_t recv_pattern[TWIS_SEND_BUFFER_SIZE] = {0};

	// Package to send
	twi_package_t packet = {
		// No address or command to issue to slave
		.addr_length = 0,
		.chip        = TWI_SLAVE_ADDR,
		.buffer      = (void *)recv_pattern,
		// Wait if bus is busy
		.length      = PATTERN_TEST_LENGTH,
		.no_wait     = false
	};
	// TWI master options
	twi_options_t m_options = {
		.speed = TWI_SPEED,
		.chip  = TWI_MASTER_ADDR,
		.speed_reg = TWI_BAUD(sysclk_get_cpu_hz(), TWI_SPEED)
	};

	// Data for slave to send, same as test_pattern
	slave.sendData[0] = 0x55;
	slave.sendData[1] = 0xA5;
	slave.sendData[2] = 0x5A;
	slave.sendData[3] = 0x77;
	slave.sendData[4] = 0x99;

	irq_initialize_vectors();

	// Initialize TWI_MASTER
	sysclk_enable_peripheral_clock(&TWI_MASTER);
	twi_master_init(&TWI_MASTER, &m_options);
	twi_master_enable(&TWI_MASTER);

	// Initialize TWI_SLAVE
	for (i = 0; i < TWIS_SEND_BUFFER_SIZE; i++) {
		slave.receivedData[i] = 0;
	}
	sysclk_enable_peripheral_clock(&TWI_SLAVE);
	TWI_SlaveInitializeDriver(&slave, &TWI_SLAVE, *slave_process);
	TWI_SlaveInitializeModule(&slave, TWI_SLAVE_ADDR,
			TWI_SLAVE_INTLVL_MED_gc);

	cpu_irq_enable();

	// Send package to slave
	twi_master_read(&TWI_MASTER, &packet);

	// Wait for slave to send packet
	do {} while (slave.result != TWIS_RESULT_OK);

	for (i = 0; i < PATTERN_TEST_LENGTH; i++) {
		test_assert_true(test, recv_pattern[i] == test_pattern[i],
				"Wrong data[%d] received, %d != %d", i,
				recv_pattern[i],
				test_pattern[i]);
	}
}

//@}

/**
 * \brief Run TWI unit tests
 *
 * Initializes the clock system, board and serial output, then sets up the
 * TWI unit test suite and runs it.
 */
int main(void)
{
	const usart_serial_options_t usart_serial_options = {
		.baudrate   = CONF_TEST_BAUDRATE,
		.charlength = CONF_TEST_CHARLENGTH,
		.paritytype = CONF_TEST_PARITY,
		.stopbits   = CONF_TEST_STOPBITS,
	};

	sysclk_init();
	board_init();
	stdio_serial_init(CONF_TEST_USART, &usart_serial_options);

	// Use the internal pullups for SDA and SCL
	TWI_MASTER_PORT.PIN0CTRL = PORT_OPC_WIREDANDPULL_gc;
	TWI_MASTER_PORT.PIN1CTRL = PORT_OPC_WIREDANDPULL_gc;

	// Define single ended conversion test cases
	DEFINE_TEST_CASE(twi_master_send_test, NULL,
			run_twi_master_send_test, NULL,
			"Sending packet from master test");
	DEFINE_TEST_CASE(twi_slave_recv_test, NULL,
			run_twi_slave_recv_test, NULL,
			"Receiving packet from master test");
	DEFINE_TEST_CASE(twi_master_recv_test, NULL,
			run_twi_master_recv_test, NULL,
			"Receiving packet from slave test");

	// Put test case addresses in an array
	DEFINE_TEST_ARRAY(twi_tests) = {
		&twi_master_send_test,
		&twi_slave_recv_test,
		&twi_master_recv_test,
	};

	// Define the test suite
	DEFINE_TEST_SUITE(twi_suite, twi_tests,
			"XMEGA TWI driver test suite");

	// Run all tests in the suite
	test_suite_run(&twi_suite);

	while (1) {
		// Intentionally left empty.
	}
}
示例#26
0
/* ! \brief Set up and run the test suite */
int main(void)
{
	const usart_serial_options_t usart_serial_options = {
		.baudrate     = CONF_TEST_BAUDRATE,
		.charlength   = CONF_TEST_CHARLENGTH,
		.paritytype   = CONF_TEST_PARITY,
		.stopbits     = CONF_TEST_STOPBITS,
	};

	sysclk_init();
	board_init();
	pmic_init();
	sleepmgr_init();
	stdio_serial_init(CONF_TEST_USART, &usart_serial_options);

	/* Enable low level interrupts */
	pmic_enable_level(PMIC_LVL_LOW);

	/* Enable interrupt requests */
	cpu_irq_enable();

	DEFINE_TEST_CASE(memory_copy_burst_length_test, NULL,
			run_dma_memory_copy_burst_length_test,
			NULL, "Memory copy and burst lengths");

	DEFINE_TEST_CASE(direction_test, NULL, run_dma_direction_test,
			NULL, "Copy directions");

	DEFINE_TEST_CASE(config_interface_test, NULL,
			run_dma_config_interface_test, NULL,
			"Write and read configuration parameters");

	DEFINE_TEST_CASE(trigger_callback_test, NULL,
			run_dma_triggered_with_callback, NULL,
			"External trigger and DMA callback");

	DEFINE_TEST_CASE(error_handling_test, NULL,
			run_dma_error_handling_test, NULL,
			"Error handling by the module");

	DEFINE_TEST_CASE(double_buffering_test, NULL,
			run_dma_double_buffering_test,
			NULL, "Double buffering");

	DEFINE_TEST_ARRAY(dma_tests) = {
		&memory_copy_burst_length_test,
		&direction_test,
		&config_interface_test,
		&trigger_callback_test,
		&error_handling_test,
		&double_buffering_test
	};

	DEFINE_TEST_SUITE(dma_suite, dma_tests, "XMEGA DMA driver test suite");

	test_suite_run(&dma_suite);

	while (1) {
		/* Intentionally left empty */
	}
}
示例#27
0
/**
 * \internal
 * \brief Test capture and compare
 *
 * This test uses TC module 0 as a PWM generator (compare function).
 * TC module 1 will be set to capture the signal from TC module 0 to test the capture
 * functionality.
 *
 * \param test Current test case.
 */
static void run_16bit_capture_and_compare_test(const struct test_case *test)
{
	test_assert_true(test,
			tc_init_success == true,
			"TC initialization failed, skipping test");

	test_assert_true(test,
			callback_function_entered == 1,
			"The callback test has failed, skipping test");

	/* Configure 16-bit TC module for PWM generation */
	tc_reset(&tc_test0_module);
	tc_get_config_defaults(&tc_test0_config);
	tc_test0_config.wave_generation  = TC_WAVE_GENERATION_MATCH_PWM;
	tc_test0_config.counter_16_bit.compare_capture_channel[TC_COMPARE_CAPTURE_CHANNEL_0]  = 0x03FF;
	tc_test0_config.counter_16_bit.compare_capture_channel[TC_COMPARE_CAPTURE_CHANNEL_1]  = 0x01FF;

	/* Calculate the theoretical PWM frequency & duty */
	uint32_t frequency_output, duty_output;
	frequency_output = system_clock_source_get_hz(SYSTEM_CLOCK_SOURCE_OSC8M)/ (0x03FF+1);

	/* This value is depend on the WaveGeneration Mode */
	duty_output = (uint32_t)(tc_test0_config.counter_16_bit.compare_capture_channel[TC_COMPARE_CAPTURE_CHANNEL_1]) * 100 \
					/ tc_test0_config.counter_16_bit.compare_capture_channel[TC_COMPARE_CAPTURE_CHANNEL_0];

	tc_test0_config.pwm_channel[TC_COMPARE_CAPTURE_CHANNEL_1].enabled = true;
	tc_test0_config.pwm_channel[TC_COMPARE_CAPTURE_CHANNEL_1].pin_out = CONF_TEST_PIN_OUT;
	tc_test0_config.pwm_channel[TC_COMPARE_CAPTURE_CHANNEL_1].pin_mux = CONF_TEST_PIN_MUX;
	tc_init(&tc_test0_module, CONF_TEST_TC0, &tc_test0_config);

	tc_register_callback(&tc_test0_module, tc_callback_function, TC_CALLBACK_CC_CHANNEL0);
	tc_enable_callback(&tc_test0_module, TC_CALLBACK_CC_CHANNEL0);

	/* Configure 16-bit TC module for capture */
	tc_reset(&tc_test1_module);
	tc_get_config_defaults(&tc_test1_config);
	tc_test1_config.clock_prescaler              = TC_CLOCK_PRESCALER_DIV1;
	tc_test1_config.enable_capture_on_channel[CONF_CAPTURE_CHAN_0] = true;
	tc_test1_config.enable_capture_on_channel[CONF_CAPTURE_CHAN_1] = true;

	tc_init(&tc_test1_module, CONF_TEST_TC1, &tc_test1_config);

	struct tc_events tc_events = { .on_event_perform_action = true,
								.event_action = TC_EVENT_ACTION_PPW,};

	tc_enable_events(&tc_test1_module, &tc_events);

	/* Configure external interrupt controller */
	struct extint_chan_conf extint_chan_config;
	extint_chan_config.gpio_pin            = CONF_EIC_PIN;
	extint_chan_config.gpio_pin_mux        = CONF_EIC_MUX;
	extint_chan_config.gpio_pin_pull       = EXTINT_PULL_UP;
	extint_chan_config.wake_if_sleeping    = false;
	extint_chan_config.filter_input_signal = false;
	extint_chan_config.detection_criteria  = EXTINT_DETECT_HIGH;
	extint_chan_set_config(0, &extint_chan_config);

	/* Configure external interrupt module to be event generator */
	struct extint_events extint_event_conf;
	extint_event_conf.generate_event_on_detect[0] = true;
	extint_enable_events(&extint_event_conf);

	/* Configure event system */
	struct events_resource event_res;

	/* Configure channel */
	struct events_config config;
	events_get_config_defaults(&config);
	config.generator      = CONF_EVENT_GENERATOR_ID;
	config.edge_detect    = EVENTS_EDGE_DETECT_NONE;
	config.path           = EVENTS_PATH_ASYNCHRONOUS;
	events_allocate(&event_res, &config);

	/* Configure user */
	events_attach_user(&event_res, CONF_EVENT_USED_ID);

	/* Enable TC modules */
	tc_enable(&tc_test1_module);
	tc_enable(&tc_test0_module);

	uint16_t period_after_capture = 0;
	uint16_t pulse_width_after_capture = 0;
	uint32_t capture_frequency = 0;
	uint32_t capture_duty = 0;


	while (callback_function_entered < 4) {
		period_after_capture = tc_get_capture_value(&tc_test1_module,
				TC_COMPARE_CAPTURE_CHANNEL_0);
		pulse_width_after_capture = tc_get_capture_value(&tc_test1_module,
				TC_COMPARE_CAPTURE_CHANNEL_1);
	}

	if(period_after_capture != 0) {
		capture_frequency = system_clock_source_get_hz(SYSTEM_CLOCK_SOURCE_OSC8M)/ period_after_capture;
		capture_duty = (uint32_t)(pulse_width_after_capture) * 100 / period_after_capture;
	}

	test_assert_true(test,
			(capture_frequency <= (frequency_output * (100 + CONF_TEST_TOLERANCE) / 100)) && \
			(capture_frequency >= (frequency_output * (100 - CONF_TEST_TOLERANCE) / 100)) && \
			(capture_duty <= (duty_output * (100 + CONF_TEST_TOLERANCE) / 100)) && \
			(capture_duty >= (duty_output * (100 - CONF_TEST_TOLERANCE) / 100)) \
			,"The result of Capture is wrong, captured frequency: %ldHz, captured duty: %ld%%",
			capture_frequency,
			capture_duty
			);
}

/**
 * \brief Initialize the USART for unit test
 *
 * Initializes the SERCOM USART used for sending the unit test status to the
 * computer via the EDBG CDC gateway.
 */
static void cdc_uart_init(void)
{
	struct usart_config usart_conf;

	/* Configure USART for unit test output */
	usart_get_config_defaults(&usart_conf);
	usart_conf.mux_setting = CONF_STDIO_MUX_SETTING;
	usart_conf.pinmux_pad0 = CONF_STDIO_PINMUX_PAD0;
	usart_conf.pinmux_pad1 = CONF_STDIO_PINMUX_PAD1;
	usart_conf.pinmux_pad2 = CONF_STDIO_PINMUX_PAD2;
	usart_conf.pinmux_pad3 = CONF_STDIO_PINMUX_PAD3;
	usart_conf.baudrate    = CONF_STDIO_BAUDRATE;

	stdio_serial_init(&cdc_uart_module, CONF_STDIO_USART, &usart_conf);
	usart_enable(&cdc_uart_module);
}

/**
 * \brief Run TC unit tests
 *
 * Initializes the system and serial output, then sets up the TC unit test
 * suite and runs it.
 */
int main(void)
{
	system_init();
	cdc_uart_init();

	/* Define Test Cases */
	DEFINE_TEST_CASE(init_test, NULL,
			run_init_test, NULL,
			"Initialize tc_xmodules");

	DEFINE_TEST_CASE(basic_functionality_test, NULL,
			run_basic_functionality_test, NULL,
			"test start stop and getters and setters");

	DEFINE_TEST_CASE(callback_test, NULL,
			run_callback_test, NULL,
			"test callback API");

	DEFINE_TEST_CASE(reset_32bit_master_test, NULL,
			run_reset_32bit_master_test, NULL,
			"Setup, reset and reinitialize TC modules of a 32-bit TC");


	DEFINE_TEST_CASE(capture_and_compare_test, NULL,
			run_16bit_capture_and_compare_test, NULL,
			"Test capture and compare");

	/* Put test case addresses in an array */
	DEFINE_TEST_ARRAY(tc_tests) = {
		&init_test,
		&basic_functionality_test,
		&callback_test,
		&reset_32bit_master_test,
		&capture_and_compare_test,
	};

	/* Define the test suite */
	DEFINE_TEST_SUITE(tc_suite, tc_tests,
			"SAM TC driver test suite");

	/* Run all tests in the suite*/
	test_suite_run(&tc_suite);

	tc_reset(&tc_test0_module);
	tc_reset(&tc_test1_module);

	while (true) {
		/* Intentionally left empty */
	}
}
示例#28
0
/**
 * \brief Run usb host core unit tests
 *
 * Initializes the clock system, board and serial output, then sets up the
 * usb unit test suite and runs it.
 */
int main(void)
{
#if SAMD21
	system_init();
	delay_init();
	cdc_uart_init();
#else
	const usart_serial_options_t usart_serial_options = {
		.baudrate   = CONF_TEST_BAUDRATE,
		.charlength = CONF_TEST_CHARLENGTH,
		.paritytype = CONF_TEST_PARITY,
		.stopbits   = CONF_TEST_STOPBITS,
	};

	sysclk_init();
	board_init();
	delay_init(sysclk_get_cpu_hz());
	stdio_serial_init(CONF_TEST_USART, &usart_serial_options);
#endif

	irq_initialize_vectors();
	cpu_irq_enable();

	// Initialize the sleep manager
	sleepmgr_init();

	// Define all the timestamp to date test cases

	DEFINE_TEST_CASE(usb_test_start, NULL, run_test_start_uhc, NULL, "Start host stack");
	DEFINE_TEST_CASE(usb_test_stop, NULL, run_test_stop_uhc, NULL, "Stop host stack");

	DEFINE_TEST_CASE(usb_test_1 , NULL, run_test_enum_fail ,
		NULL, "1  - Attach and no response");
	DEFINE_TEST_CASE(usb_test_2 , NULL, run_test_enum_fail ,
		NULL, "2  - Disable endpoint 0 after first setup packet");
	DEFINE_TEST_CASE(usb_test_3 , NULL, run_test_disconnection ,
		NULL, "3  - Detach after first setup packet");
	DEFINE_TEST_CASE(usb_test_4 , NULL, run_test_disconnection ,
		NULL, "4  - No response data (NACK IN) after first setup packet");
	DEFINE_TEST_CASE(usb_test_5 , NULL, run_test_disconnection ,
		NULL, "5  - Detach after IN data phase of first setup request");
	DEFINE_TEST_CASE(usb_test_6 , NULL, run_test_enum_fail ,
		NULL, "6  - Wrong value in first setup request get descriptor");
	DEFINE_TEST_CASE(usb_test_7 , NULL, run_test_disconnection ,
		NULL, "7  - Detach before reset");
	DEFINE_TEST_CASE(usb_test_8 , NULL, run_test_disconnection ,
		NULL, "8  - Detach during reset after first setup request get descriptor");
	DEFINE_TEST_CASE(usb_test_9 , NULL, run_test_disconnection ,
		NULL, "9  - Detach after reset after first setup request get descriptor");
	DEFINE_TEST_CASE(usb_test_10, NULL, run_test_disconnection,
		NULL, "10 - No send ZLP (NAK IN) after second setup packet (set address)");
	DEFINE_TEST_CASE(usb_test_11, NULL, run_test_enum_fail,
		NULL, "11 - Wrong value in first setup request get configuration 0");
	DEFINE_TEST_CASE(usb_test_12, NULL, run_test_enum_fail,
		NULL, "12 - Wrong transfer value in second setup request get configuration 0");
	DEFINE_TEST_CASE(usb_test_13, NULL, run_test_enum_overcurrent,
		NULL, "13 - Too high power consumption in setup request get configuration 0");
	DEFINE_TEST_CASE(usb_test_14, NULL, run_test_enum_unsupported,
		NULL, "14 - No supported interface (interface subclass not possible)");
#ifndef TST_15_DIS
	DEFINE_TEST_CASE(usb_test_15, NULL, run_test_enum_hardwarelimit,
		NULL, "15 - HID mouse with too large endpoint size (hardware limit)");
#endif
	DEFINE_TEST_CASE(usb_test_16, NULL, run_test_enum_fail,
		NULL, "16 - Stall SET CONFIGURATION (Note SELF/300mA is tested)");
	DEFINE_TEST_CASE(usb_test_17ls, NULL, run_test_enum_success_ls,
		NULL, "17 - Regular LS enumeration");
	DEFINE_TEST_CASE(usb_test_17fs, NULL, run_test_enum_success_fs,
		NULL, "17 - Regular FS enumeration");
	DEFINE_TEST_CASE(usb_test_17hs, NULL, run_test_enum_success_hs,
		NULL, "17 - Regular HS enumeration");
	DEFINE_TEST_CASE(usb_test_18, NULL, run_test_downstream,
		NULL, "18 - Regular downstream (from Host)");
	DEFINE_TEST_CASE(usb_test_19, NULL, run_test_downstream_disconnection,
		NULL, "19 - Regular disconnection during downstream (from Host)");
	DEFINE_TEST_CASE(usb_test_20ls, NULL, run_test_upstream_ls,
		NULL, "20 - Regular upstream (from Device)");
	DEFINE_TEST_CASE(usb_test_20fs, NULL, run_test_upstream_fs,
		NULL, "20 - Regular upstream (from Device)");
	DEFINE_TEST_CASE(usb_test_20hs, NULL, run_test_upstream_hs,
		NULL, "20 - Regular upstream (from Device)");
	DEFINE_TEST_CASE(usb_test_21, NULL, run_test_disconnection_in_suspend,
		NULL, "21 - Regular disconnection during USB suspend mode");

	// Put test case addresses in an array
	DEFINE_TEST_ARRAY(usb_host_tests_host) = {
		&usb_test_start,
		// Low speed tests
		&usb_test_1 ,
		&usb_test_2 ,
		&usb_test_3 ,
		&usb_test_4 ,
		&usb_test_5 ,
		&usb_test_6 ,
		&usb_test_7 ,
		&usb_test_8 ,
		&usb_test_9 ,
		&usb_test_10,
		&usb_test_11,
		&usb_test_12,
		&usb_test_13,
		&usb_test_14,
#ifndef TST_15_DIS
		&usb_test_15,
#endif
		&usb_test_16,
		&usb_test_17ls,
#ifndef TST_18_DIS
		&usb_test_18,
#endif
		&usb_test_19,
		&usb_test_20ls,
		&usb_test_21,
		// Full speed tests
		&usb_test_1 ,
		&usb_test_2 ,
		&usb_test_3 ,
		&usb_test_4 ,
		&usb_test_5 ,
		&usb_test_6 ,
		&usb_test_7 ,
		&usb_test_8 ,
		&usb_test_9 ,
		&usb_test_10,
		&usb_test_11,
		&usb_test_12,
		&usb_test_13,
		&usb_test_14,
#ifndef TST_15_DIS
		&usb_test_15,
#endif
		&usb_test_16,
		&usb_test_17fs,
#ifndef TST_18_DIS
		&usb_test_18,
#endif
		&usb_test_19,
		&usb_test_20fs,
		&usb_test_21,
		// High speed tests
		&usb_test_1 ,
		&usb_test_2 ,
		&usb_test_3 ,
		&usb_test_4 ,
		&usb_test_5 ,
		&usb_test_6 ,
		&usb_test_7 ,
		&usb_test_8 ,
		&usb_test_9 ,
		&usb_test_10,
		&usb_test_11,
		&usb_test_12,
		&usb_test_13,
		&usb_test_14,
#ifndef TST_15_DIS
		&usb_test_15,
#endif
		&usb_test_16,
#ifndef USB_HOST_HS_SUPPORT
		&usb_test_17fs,
#else
		&usb_test_17hs,
#endif
#ifndef TST_18_DIS
		&usb_test_18,
#endif
		&usb_test_19,
#ifndef USB_HOST_HS_SUPPORT
		&usb_test_20fs,
#else
		&usb_test_20hs,
#endif
		&usb_test_21,
		&usb_test_stop,
	};

	// Define the test suite
	DEFINE_TEST_SUITE(usb_host_suite_host, usb_host_tests_host,
			"Common usb host service test suite");

	// The unit test prints message via UART which does not support deep sleep mode.
#if SAM
	sleepmgr_lock_mode(SLEEPMGR_ACTIVE);
#else
	sleepmgr_lock_mode(SLEEPMGR_IDLE);
#endif

	// Run all tests in the suite
	test_suite_run(&usb_host_suite_host);
	while (1) {
		// Intentionally left empty.
	}
}
void run_MLX90614_tests(void) {
	/* Define Test Cases */
	DEFINE_TEST_CASE(test_MLX90614_init,
					NULL,
					run_test_MLX90614_init,
					NULL,
					"Testing MLX90614 I2C initialization");
	DEFINE_TEST_CASE(test_MLX90614_read,
					NULL,
					run_test_MLX90614_read,
					NULL,
					"Testing MLX90614 I2C read functionality");
	DEFINE_TEST_CASE(test_MLX90614_read2ByteValue,
					NULL,
					run_test_MLX90614_read2ByteValue,
					NULL,
					"Testing MLX90614 read 2 byte value functionality");
	DEFINE_TEST_CASE(test_MLX90614_readRawIRData,
					NULL,
					run_test_MLX90614_readRawIRData,
					NULL,
					"Testing MLX90614 read raw IR data functionality");
	DEFINE_TEST_CASE(test_MLX90614_dataToTemp,
					NULL,
					run_test_MLX90614_dataToTemp,
					NULL,
					"Testing MLX90614 data to temperature conversion functionality");
	DEFINE_TEST_CASE(test_MLX90614_readTempC,
					NULL,
					run_test_MLX90614_readTempC,
					NULL,
					"Testing MLX90614 Celsius read temperature functionality");
	DEFINE_TEST_CASE(test_MLX90614_getAddress,
					NULL,
					run_test_MLX90614_getAddress,
					NULL,
					"Testing MLX90614 get address functionality");
	DEFINE_TEST_CASE(test_write_MLX90614_eeprom,
					NULL,
					run_test_write_MLX90614_eeprom,
					NULL,
					"Testing MLX90614 EEPROM write functionality");
	DEFINE_TEST_CASE(test_MLX90614_setAddress,
					NULL,
					run_test_MLX90614_setAddress,
					NULL,
					"Testing MLX90614 set address functionality");
	
	/* Put test case addresses in an array */
	DEFINE_TEST_ARRAY(i2c_tests) = {
		&test_MLX90614_init,
		&test_MLX90614_read,
		&test_MLX90614_read2ByteValue,
		&test_MLX90614_readRawIRData,
		&test_MLX90614_dataToTemp,
		&test_MLX90614_readTempC,
		&test_MLX90614_getAddress,
		&test_write_MLX90614_eeprom,
		&test_MLX90614_setAddress
	};

	/* Define the test suite */
	DEFINE_TEST_SUITE(i2c_test_suite, i2c_tests, "MLX90614 test suite");

	/* Run all tests in the suite*/
	test_suite_run(&i2c_test_suite);
}