Skip to content
Permalink
Browse files

tests: usb: Add more USB DC tests and refactor names

Add more tests covering almost all DC API with invalid parameters.

Signed-off-by: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
  • Loading branch information...
finikorg authored and nashif committed Mar 27, 2019
1 parent cf349df commit 1178042cf452fb7cd340041876a0e7eb00617a82
Showing with 66 additions and 23 deletions.
  1. +66 −23 tests/subsys/usb/device/src/main.c
@@ -17,6 +17,7 @@

#define ENDP_BULK_IN 0x81

#define VALID_EP ENDP_BULK_IN
#define INVALID_EP 0x20

static const struct dev_common_descriptor {
@@ -139,68 +140,110 @@ static int device_init(void)
return ret;
}

static void test_device_setup(void)
static void test_usb_setup(void)
{
zassert_equal(device_init(), TC_PASS, "init failed");
}

static void test_device_disable(void)
static void test_usb_disable(void)
{
zassert_equal(usb_disable(), TC_PASS, "usb_disable() failed");
}

static void test_device_deconfig(void)
static void test_usb_deconfig(void)
{
zassert_equal(usb_deconfig(), TC_PASS, "usb_deconfig() failed");
}

static void test_device_dc_api(void)
/* Test USB Device Cotnroller API */
static void test_usb_dc_api(void)
{
zassert_not_equal(usb_dc_ep_mps(INVALID_EP), TC_PASS,
"Invalid test usb_dc_ep_mps(INVALID_EP) failed");

/* Control endpoins are configured */
zassert_equal(usb_dc_ep_mps(0x0), 64,
"usb_dc_ep_mps(0x00) failed");
zassert_equal(usb_dc_ep_mps(0x80), 64,
"usb_dc_ep_mps(0x80) failed");

/* Bulk EP is not configured yet */
zassert_equal(usb_dc_ep_mps(ENDP_BULK_IN), 0,
"usb_dc_ep_mps(ENDP_BULK_IN) failed");
"usb_dc_ep_mps(ENDP_BULK_IN) not configured");

zassert_equal(usb_dc_set_address(0x01), TC_PASS,
"usb_dc_set_address(0x01) (not attached) failed");
"usb_dc_set_address(0x01)");
}

static void test_device_dc_api_invalid(void)
/* Test USB Device Cotnroller API for invalid parameters */
static void test_usb_dc_api_invalid(void)
{
size_t size;
u8_t byte;

/* Set stall to invalid EP */
zassert_not_equal(usb_dc_ep_set_stall(INVALID_EP), TC_PASS,
"usb_dc_ep_set_stall(INVALID_EP)");

/* Set stall to invalid EP */
zassert_not_equal(usb_dc_ep_clear_stall(INVALID_EP), TC_PASS,
"usb_dc_ep_set_stall(INVALID_EP)");

/* Check if the selected endpoint is stalled */
zassert_not_equal(usb_dc_ep_is_stalled(INVALID_EP, &byte), TC_PASS,
"usb_dc_ep_is_stalled(INVALID_EP, stalled)");
zassert_not_equal(usb_dc_ep_is_stalled(VALID_EP, NULL), TC_PASS,
"usb_dc_ep_is_stalled(VALID_EP, NULL)");

/* Halt invalid EP */
zassert_not_equal(usb_dc_ep_halt(INVALID_EP), TC_PASS,
"usb_dc_ep_halt(INVALID_EP)");

/* Enable invalid EP */
zassert_not_equal(usb_dc_ep_enable(INVALID_EP), TC_PASS,
"usb_dc_ep_enable(INVALID_EP)");

/* Disable invalid EP */
zassert_not_equal(usb_dc_ep_disable(INVALID_EP), TC_PASS,
"usb_dc_ep_disable(INVALID_EP)");

/* Flush invalid EP */
zassert_not_equal(usb_dc_ep_flush(INVALID_EP), TC_PASS,
"usb_dc_ep_flush(INVALID_EP)");

/* Set callback to invalid EP */
zassert_not_equal(usb_dc_ep_set_callback(INVALID_EP, NULL), TC_PASS,
"usb_dc_ep_set_callback(INVALID_EP, NULL)");

/* Read invalid EP */
zassert_not_equal(usb_read(INVALID_EP, &byte, sizeof(byte), &size),
TC_PASS, "usb_read(INVALID_EP)");

/* Write to invalid EP */
zassert_not_equal(usb_write(INVALID_EP, &byte, sizeof(byte), &size),
TC_PASS, "usb_write(INVALID_EP)");
zassert_not_equal(usb_dc_ep_write(INVALID_EP, &byte, sizeof(byte),
&size),
TC_PASS, "usb_dc_ep_write(INVALID_EP)");

/* Read invalid EP */
zassert_not_equal(usb_dc_ep_read(INVALID_EP, &byte, sizeof(byte),
&size),
TC_PASS, "usb_dc_ep_read(INVALID_EP)");
zassert_not_equal(usb_dc_ep_read_wait(INVALID_EP, &byte, sizeof(byte),
&size),
TC_PASS, "usb_dc_ep_read_wait(INVALID_EP)");
zassert_not_equal(usb_dc_ep_read_continue(INVALID_EP), TC_PASS,
"usb_dc_ep_read_continue(INVALID_EP)");

/* Get endpoint max packet size for invalid EP */
zassert_not_equal(usb_dc_ep_mps(INVALID_EP), TC_PASS,
"usb_dc_ep_mps(INVALID_EP)");
}

/*test case main entry*/
void test_main(void)
{
ztest_test_suite(test_device,
/* Should return TC_PASS if not enabled yet */
ztest_unit_test(test_device_disable),
ztest_unit_test(test_device_setup),
ztest_unit_test(test_device_dc_api),
ztest_unit_test(test_device_dc_api_invalid),
ztest_unit_test(test_device_deconfig),
ztest_unit_test(test_device_disable));
/* Test API for not USB attached state */
ztest_unit_test(test_usb_dc_api_invalid),
ztest_unit_test(test_usb_disable),
ztest_unit_test(test_usb_setup),
ztest_unit_test(test_usb_dc_api),
ztest_unit_test(test_usb_dc_api_invalid),
ztest_unit_test(test_usb_deconfig),
ztest_unit_test(test_usb_disable));

ztest_run_test_suite(test_device);
}

0 comments on commit 1178042

Please sign in to comment.
You can’t perform that action at this time.