diff mbox series

[bpf-next,v2,07/10] selftests: xsk: Add test UNALIGNED_INV_DESC_4K1_FRAME_SIZE

Message ID 20230329180502.1884307-8-kal.conley@dectris.com (mailing list archive)
State New
Headers show
Series [bpf-next,v2,01/10] selftests: xsk: Add xskxceiver.h dependency to Makefile | expand

Commit Message

Kal Cutter Conley March 29, 2023, 6:04 p.m. UTC
Add unaligned descriptor test for frame size of 4001. Using an odd frame
size ensures that the end of the UMEM is not near a page boundary. This
allows testing descriptors that staddle the end of the UMEM but not a
page.

This test used to fail without the previous commit ("xsk: Add check for
unaligned descriptors that overrun UMEM").

Signed-off-by: Kal Conley <kal.conley@dectris.com>
---
 tools/testing/selftests/bpf/xskxceiver.c | 25 ++++++++++++++++++++++++
 tools/testing/selftests/bpf/xskxceiver.h |  1 +
 2 files changed, 26 insertions(+)

Comments

Magnus Karlsson April 3, 2023, 12:25 p.m. UTC | #1
On Wed, 29 Mar 2023 at 20:12, Kal Conley <kal.conley@dectris.com> wrote:
>
> Add unaligned descriptor test for frame size of 4001. Using an odd frame
> size ensures that the end of the UMEM is not near a page boundary. This
> allows testing descriptors that staddle the end of the UMEM but not a

nit: straddle

> page.
>
> This test used to fail without the previous commit ("xsk: Add check for
> unaligned descriptors that overrun UMEM").
>
> Signed-off-by: Kal Conley <kal.conley@dectris.com>
> ---
>  tools/testing/selftests/bpf/xskxceiver.c | 25 ++++++++++++++++++++++++
>  tools/testing/selftests/bpf/xskxceiver.h |  1 +
>  2 files changed, 26 insertions(+)
>
> diff --git a/tools/testing/selftests/bpf/xskxceiver.c b/tools/testing/selftests/bpf/xskxceiver.c
> index 1a4bdd5aa78c..9b9efd0e0a4c 100644
> --- a/tools/testing/selftests/bpf/xskxceiver.c
> +++ b/tools/testing/selftests/bpf/xskxceiver.c
> @@ -69,6 +69,7 @@
>   */
>
>  #define _GNU_SOURCE
> +#include <assert.h>
>  #include <fcntl.h>
>  #include <errno.h>
>  #include <getopt.h>
> @@ -1876,6 +1877,30 @@ static void run_pkt_test(struct test_spec *test, enum test_mode mode, enum test_
>                 test->ifobj_rx->umem->unaligned_mode = true;
>                 testapp_invalid_desc(test);
>                 break;
> +       case TEST_TYPE_UNALIGNED_INV_DESC_4K1_FRAME:
> +               if (!hugepages_present(test->ifobj_tx)) {
> +                       ksft_test_result_skip("No 2M huge pages present.\n");
> +                       return;
> +               }
> +               test_spec_set_name(test, "UNALIGNED_INV_DESC_4K1_FRAME_SIZE");
> +               /* Odd frame size so the UMEM doesn't end near a page boundary. */
> +               test->ifobj_tx->umem->frame_size = 4001;
> +               test->ifobj_rx->umem->frame_size = 4001;
> +               test->ifobj_tx->umem->unaligned_mode = true;
> +               test->ifobj_rx->umem->unaligned_mode = true;
> +               /* This test exists to test descriptors that staddle the end of

nit: straddle

> +                * the UMEM but not a page.
> +                */
> +               {
> +                       u64 umem_size = test->ifobj_tx->umem->num_frames *
> +                                       test->ifobj_tx->umem->frame_size;
> +                       u64 page_size = sysconf(_SC_PAGESIZE);
> +
> +                       assert(umem_size % page_size > PKT_SIZE);
> +                       assert(umem_size % page_size < page_size - PKT_SIZE);
> +               }
> +               testapp_invalid_desc(test);

Please put this code in a function that you call. Declare your local
variables in the beginning of that function.

> +               break;
>         case TEST_TYPE_UNALIGNED:
>                 if (!testapp_unaligned(test))
>                         return;
> diff --git a/tools/testing/selftests/bpf/xskxceiver.h b/tools/testing/selftests/bpf/xskxceiver.h
> index cc24ab72f3ff..919327807a4e 100644
> --- a/tools/testing/selftests/bpf/xskxceiver.h
> +++ b/tools/testing/selftests/bpf/xskxceiver.h
> @@ -78,6 +78,7 @@ enum test_type {
>         TEST_TYPE_ALIGNED_INV_DESC,
>         TEST_TYPE_ALIGNED_INV_DESC_2K_FRAME,
>         TEST_TYPE_UNALIGNED_INV_DESC,
> +       TEST_TYPE_UNALIGNED_INV_DESC_4K1_FRAME,
>         TEST_TYPE_HEADROOM,
>         TEST_TYPE_TEARDOWN,
>         TEST_TYPE_BIDI,
> --
> 2.39.2
>
diff mbox series

Patch

diff --git a/tools/testing/selftests/bpf/xskxceiver.c b/tools/testing/selftests/bpf/xskxceiver.c
index 1a4bdd5aa78c..9b9efd0e0a4c 100644
--- a/tools/testing/selftests/bpf/xskxceiver.c
+++ b/tools/testing/selftests/bpf/xskxceiver.c
@@ -69,6 +69,7 @@ 
  */
 
 #define _GNU_SOURCE
+#include <assert.h>
 #include <fcntl.h>
 #include <errno.h>
 #include <getopt.h>
@@ -1876,6 +1877,30 @@  static void run_pkt_test(struct test_spec *test, enum test_mode mode, enum test_
 		test->ifobj_rx->umem->unaligned_mode = true;
 		testapp_invalid_desc(test);
 		break;
+	case TEST_TYPE_UNALIGNED_INV_DESC_4K1_FRAME:
+		if (!hugepages_present(test->ifobj_tx)) {
+			ksft_test_result_skip("No 2M huge pages present.\n");
+			return;
+		}
+		test_spec_set_name(test, "UNALIGNED_INV_DESC_4K1_FRAME_SIZE");
+		/* Odd frame size so the UMEM doesn't end near a page boundary. */
+		test->ifobj_tx->umem->frame_size = 4001;
+		test->ifobj_rx->umem->frame_size = 4001;
+		test->ifobj_tx->umem->unaligned_mode = true;
+		test->ifobj_rx->umem->unaligned_mode = true;
+		/* This test exists to test descriptors that staddle the end of
+		 * the UMEM but not a page.
+		 */
+		{
+			u64 umem_size = test->ifobj_tx->umem->num_frames *
+					test->ifobj_tx->umem->frame_size;
+			u64 page_size = sysconf(_SC_PAGESIZE);
+
+			assert(umem_size % page_size > PKT_SIZE);
+			assert(umem_size % page_size < page_size - PKT_SIZE);
+		}
+		testapp_invalid_desc(test);
+		break;
 	case TEST_TYPE_UNALIGNED:
 		if (!testapp_unaligned(test))
 			return;
diff --git a/tools/testing/selftests/bpf/xskxceiver.h b/tools/testing/selftests/bpf/xskxceiver.h
index cc24ab72f3ff..919327807a4e 100644
--- a/tools/testing/selftests/bpf/xskxceiver.h
+++ b/tools/testing/selftests/bpf/xskxceiver.h
@@ -78,6 +78,7 @@  enum test_type {
 	TEST_TYPE_ALIGNED_INV_DESC,
 	TEST_TYPE_ALIGNED_INV_DESC_2K_FRAME,
 	TEST_TYPE_UNALIGNED_INV_DESC,
+	TEST_TYPE_UNALIGNED_INV_DESC_4K1_FRAME,
 	TEST_TYPE_HEADROOM,
 	TEST_TYPE_TEARDOWN,
 	TEST_TYPE_BIDI,