[v2,3/5] test-ipmi-hiomap: Add write-one-byte test
diff mbox series

Message ID 20190408060541.11246-3-hegdevasant@linux.vnet.ibm.com
State Accepted
Delegated to: Vasant Hegde
Headers show
Series
  • [v2,1/5] libflash/ipmi-hiomap: Fix blocks count issue
Related show

Commit Message

Vasant Hegde April 8, 2019, 6:05 a.m. UTC
Add test case to write:
  - 1 byte
  - 1 block and 1 byte data

Cc: Andrew Jeffery <andrew@aj.id.au>
Cc: skiboot-stable@lists.ozlabs.org
Signed-off-by: Vasant Hegde <hegdevasant@linux.vnet.ibm.com>
---
 libflash/test/test-ipmi-hiomap.c | 38 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)

Comments

Andrew Jeffery April 9, 2019, 12:55 a.m. UTC | #1
On Mon, 8 Apr 2019, at 15:36, Vasant Hegde wrote:
> Add test case to write:
>   - 1 byte
>   - 1 block and 1 byte data
> 
> Cc: Andrew Jeffery <andrew@aj.id.au>
> Cc: skiboot-stable@lists.ozlabs.org
> Signed-off-by: Vasant Hegde <hegdevasant@linux.vnet.ibm.com>
> ---
>  libflash/test/test-ipmi-hiomap.c | 38 ++++++++++++++++++++++++++++++++++++++
>  1 file changed, 38 insertions(+)
> 
> diff --git a/libflash/test/test-ipmi-hiomap.c b/libflash/test/test-ipmi-hiomap.c
> index bf31a0e72..b8f24a9b0 100644
> --- a/libflash/test/test-ipmi-hiomap.c
> +++ b/libflash/test/test-ipmi-hiomap.c
> @@ -1061,6 +1061,23 @@ static void test_hiomap_protocol_write_one_block(void)
>  	scenario_exit();
>  }
>  
> +static void test_hiomap_protocol_write_one_byte(void)
> +{
> +	struct blocklevel_device *bl;
> +	uint8_t *buf;
> +	size_t len;
> +
> +	scenario_enter(scenario_hiomap_protocol_write_one_block);
> +	assert(!ipmi_hiomap_init(&bl));
> +	len = 1;
> +	buf = calloc(1, len);

At least using calloc gives a consistent pattern :)

Reviewed-by: Andrew Jeffery <andrew@aj.id.au>

> +	assert(buf);
> +	assert(!bl->write(bl, 0, buf, len));
> +	free(buf);
> +	ipmi_hiomap_exit(bl);
> +	scenario_exit();
> +}
> +
>  static const struct scenario_event
>  scenario_hiomap_protocol_write_two_blocks[] = {
>  	{ .type = scenario_event_p, .p = &hiomap_ack_call, },
> @@ -1128,6 +1145,25 @@ static void test_hiomap_protocol_write_two_blocks(void)
>  	scenario_exit();
>  }
>  
> +static void test_hiomap_protocol_write_1block_1byte(void)
> +{
> +	struct blocklevel_device *bl;
> +	struct ipmi_hiomap *ctx;
> +	uint8_t *buf;
> +	size_t len;
> +
> +	scenario_enter(scenario_hiomap_protocol_write_two_blocks);
> +	assert(!ipmi_hiomap_init(&bl));
> +	ctx = container_of(bl, struct ipmi_hiomap, bl);
> +	len =  (1 << ctx->block_size_shift) + 1;
> +	buf = calloc(1, len);
> +	assert(buf);
> +	assert(!bl->write(bl, 0, buf, len));
> +	free(buf);
> +	ipmi_hiomap_exit(bl);
> +	scenario_exit();
> +}
> +
>  static const struct scenario_event
>  scenario_hiomap_protocol_write_one_block_twice[] = {
>  	{ .type = scenario_event_p, .p = &hiomap_ack_call, },
> @@ -3079,7 +3115,9 @@ struct test_case test_cases[] = {
>  	TEST_CASE(test_hiomap_protocol_event_before_read),
>  	TEST_CASE(test_hiomap_protocol_event_during_read),
>  	TEST_CASE(test_hiomap_protocol_write_one_block),
> +	TEST_CASE(test_hiomap_protocol_write_one_byte),
>  	TEST_CASE(test_hiomap_protocol_write_two_blocks),
> +	TEST_CASE(test_hiomap_protocol_write_1block_1byte),
>  	TEST_CASE(test_hiomap_protocol_write_one_block_twice),
>  	TEST_CASE(test_hiomap_protocol_event_before_write),
>  	TEST_CASE(test_hiomap_protocol_event_during_write),
> -- 
> 2.14.3
> 
>

Patch
diff mbox series

diff --git a/libflash/test/test-ipmi-hiomap.c b/libflash/test/test-ipmi-hiomap.c
index bf31a0e72..b8f24a9b0 100644
--- a/libflash/test/test-ipmi-hiomap.c
+++ b/libflash/test/test-ipmi-hiomap.c
@@ -1061,6 +1061,23 @@  static void test_hiomap_protocol_write_one_block(void)
 	scenario_exit();
 }
 
+static void test_hiomap_protocol_write_one_byte(void)
+{
+	struct blocklevel_device *bl;
+	uint8_t *buf;
+	size_t len;
+
+	scenario_enter(scenario_hiomap_protocol_write_one_block);
+	assert(!ipmi_hiomap_init(&bl));
+	len = 1;
+	buf = calloc(1, len);
+	assert(buf);
+	assert(!bl->write(bl, 0, buf, len));
+	free(buf);
+	ipmi_hiomap_exit(bl);
+	scenario_exit();
+}
+
 static const struct scenario_event
 scenario_hiomap_protocol_write_two_blocks[] = {
 	{ .type = scenario_event_p, .p = &hiomap_ack_call, },
@@ -1128,6 +1145,25 @@  static void test_hiomap_protocol_write_two_blocks(void)
 	scenario_exit();
 }
 
+static void test_hiomap_protocol_write_1block_1byte(void)
+{
+	struct blocklevel_device *bl;
+	struct ipmi_hiomap *ctx;
+	uint8_t *buf;
+	size_t len;
+
+	scenario_enter(scenario_hiomap_protocol_write_two_blocks);
+	assert(!ipmi_hiomap_init(&bl));
+	ctx = container_of(bl, struct ipmi_hiomap, bl);
+	len =  (1 << ctx->block_size_shift) + 1;
+	buf = calloc(1, len);
+	assert(buf);
+	assert(!bl->write(bl, 0, buf, len));
+	free(buf);
+	ipmi_hiomap_exit(bl);
+	scenario_exit();
+}
+
 static const struct scenario_event
 scenario_hiomap_protocol_write_one_block_twice[] = {
 	{ .type = scenario_event_p, .p = &hiomap_ack_call, },
@@ -3079,7 +3115,9 @@  struct test_case test_cases[] = {
 	TEST_CASE(test_hiomap_protocol_event_before_read),
 	TEST_CASE(test_hiomap_protocol_event_during_read),
 	TEST_CASE(test_hiomap_protocol_write_one_block),
+	TEST_CASE(test_hiomap_protocol_write_one_byte),
 	TEST_CASE(test_hiomap_protocol_write_two_blocks),
+	TEST_CASE(test_hiomap_protocol_write_1block_1byte),
 	TEST_CASE(test_hiomap_protocol_write_one_block_twice),
 	TEST_CASE(test_hiomap_protocol_event_before_write),
 	TEST_CASE(test_hiomap_protocol_event_during_write),