Esempio n. 1
0
TEST(UsartIO_DMA, OpenWhenDeviceNotOpenedMallocFail)
{
	int 												ret;
	struct file 								file = {0};
	struct msp_factory 					msp = {0};
	struct UARTEX_HandleTypeDef huartex = {0};
	struct uart_device 					udev = 
		{ 
			.dev = { .name = "UART2", .number = 2, },
			.msp = &msp,
			.rbuf_size = 13, 
			.tbuf_size = 17, 
		};
	
	udev.testdata = &huartex;
	huartex.testdata = &udev;															// 
	msp.testdata = &udev;
	
	msp.create_uartex_handle_by_port = mock_huartex_create_success;			// create uartex handle
	huartex.ops.init = mock_uartex_init_success;					// init uart (hardware)
	huartex.ops.deinit = mock_uartex_deinit_success;			// deinit uart	
	huartex.ops.recv = mock_uartex_recv_success;					// start recv 
		
	countdown = 4;
	UnityMalloc_MakeMallocFailAfterCount(0);
	ret = UART_IO_Open(&udev.dev, &file);
	TEST_ASSERT_EQUAL(4, countdown);											// nothing should be called	
	TEST_ASSERT_EQUAL(-ENOMEM, ret);											// return ENOMEM
	assert_device_and_file_intact(&udev, &file);

	countdown = 4;
	UnityMalloc_MakeMallocFailAfterCount(1);
	ret = UART_IO_Open(&udev.dev, &file);
	TEST_ASSERT_EQUAL(4, countdown);											// nothing should be called	
	TEST_ASSERT_EQUAL(-ENOMEM, ret);											// return ENOMEM
	assert_device_and_file_intact(&udev, &file);		
	
	countdown = 4;
	UnityMalloc_MakeMallocFailAfterCount(2);
	ret = UART_IO_Open(&udev.dev, &file);
	TEST_ASSERT_EQUAL(4, countdown);											// nothing should be called	
	TEST_ASSERT_EQUAL(-ENOMEM, ret);											// return ENOMEM
	assert_device_and_file_intact(&udev, &file);	
	
	countdown = 4;
	UnityMalloc_MakeMallocFailAfterCount(3);
	ret = UART_IO_Open(&udev.dev, &file);
	TEST_ASSERT_EQUAL(4, countdown);											// nothing should be called	
	TEST_ASSERT_EQUAL(-ENOMEM, ret);											// return ENOMEM
	assert_device_and_file_intact(&udev, &file);	
}
Esempio n. 2
0
TEST(UnityFixture, ForceMallocFail)
{
    void* m;
    void* mfails;
    UnityMalloc_MakeMallocFailAfterCount(1);
    m = malloc(10);
    CHECK(m);
    mfails = malloc(10);
    TEST_ASSERT_POINTERS_EQUAL(0, mfails);
    free(m);
}