public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Clemens Famulla-Conrad <cfamullaconrad@suse.de>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v3 3/5] kernel/uevent: Add uevent02
Date: Mon, 26 Aug 2019 17:55:29 +0200	[thread overview]
Message-ID: <1566834929.15851.13.camel@suse.de> (raw)
In-Reply-To: <20190826140124.24681-4-chrubis@suse.cz>

Reviewed-by: Clemens Famulla-Conrad <cfamullaconrad@suse.de>

On Mon, 2019-08-26 at 16:01 +0200, Cyril Hrubis wrote:
> Similar to uevent01 but we create and remove a tun network card
> instead.
> 
> Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
> ---
>  runtest/uevent                      |   1 +
>  testcases/kernel/uevents/.gitignore |   1 +
>  testcases/kernel/uevents/uevent02.c | 143
> ++++++++++++++++++++++++++++
>  3 files changed, 145 insertions(+)
>  create mode 100644 testcases/kernel/uevents/uevent02.c
> 
> diff --git a/runtest/uevent b/runtest/uevent
> index e9cdf26b8..30b1114a4 100644
> --- a/runtest/uevent
> +++ b/runtest/uevent
> @@ -1 +1,2 @@
>  uevent01 uevent01
> +uevent02 uevent02
> diff --git a/testcases/kernel/uevents/.gitignore
> b/testcases/kernel/uevents/.gitignore
> index 53d0b546a..0afc95534 100644
> --- a/testcases/kernel/uevents/.gitignore
> +++ b/testcases/kernel/uevents/.gitignore
> @@ -1 +1,2 @@
>  uevent01
> +uevent02
> diff --git a/testcases/kernel/uevents/uevent02.c
> b/testcases/kernel/uevents/uevent02.c
> new file mode 100644
> index 000000000..b94748c51
> --- /dev/null
> +++ b/testcases/kernel/uevents/uevent02.c
> @@ -0,0 +1,143 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Copyright (C) 2019 Cyril Hrubis <chrubis@suse.cz>
> + */
> +
> +/*
> + * Very simple uevent netlink socket test.
> + *
> + * We fork a child that listens for a kernel events while parents
> creates and
> + * removes a tun network device which should produce two several add
> and remove
> + * events.
> + */
> +
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <sys/wait.h>
> +#include <linux/if.h>
> +#include <linux/if_tun.h>
> +
> +#include "tst_test.h"
> +
> +#include "uevent.h"
> +
> +#define TUN_PATH "/dev/net/tun"
> +
> +static void generate_tun_uevents(void)
> +{
> +	int fd = SAFE_OPEN(TUN_PATH, O_RDWR);
> +
> +	struct ifreq ifr = {
> +		.ifr_flags = IFF_TUN,
> +		.ifr_name = "ltp-tun0",
> +	};
> +
> +	SAFE_IOCTL(fd, TUNSETIFF, (void*)&ifr);
> +
> +	SAFE_IOCTL(fd, TUNSETPERSIST, 0);
> +
> +	SAFE_CLOSE(fd);
> +}
> +
> +static void verify_uevent(void)
> +{
> +	int pid, fd;
> +
> +	struct uevent_desc add = {
> +		.msg = "add@/devices/virtual/net/ltp-tun0",
> +		.value_cnt = 4,
> +		.values = (const char*[]) {
> +			"ACTION=add",
> +			"DEVPATH=/devices/virtual/net/ltp-tun0",
> +			"SUBSYSTEM=net",
> +			"INTERFACE=ltp-tun0",
> +		}
> +	};
> +
> +	struct uevent_desc add_rx = {
> +		.msg = "add@/devices/virtual/net/ltp-tun0/queues/rx-
> 0",
> +		.value_cnt = 3,
> +		.values = (const char*[]) {
> +			"ACTION=add",
> +			"DEVPATH=/devices/virtual/net/ltp-
> tun0/queues/rx-0",
> +			"SUBSYSTEM=queues",
> +		}
> +	};
> +
> +	struct uevent_desc add_tx = {
> +		.msg = "add@/devices/virtual/net/ltp-tun0/queues/tx-
> 0",
> +		.value_cnt = 3,
> +		.values = (const char*[]) {
> +			"ACTION=add",
> +			"DEVPATH=/devices/virtual/net/ltp-
> tun0/queues/tx-0",
> +			"SUBSYSTEM=queues",
> +		}
> +	};
> +
> +	struct uevent_desc rem_rx = {
> +		.msg = "remove@/devices/virtual/net/ltp-
> tun0/queues/rx-0",
> +		.value_cnt = 3,
> +		.values = (const char*[]) {
> +			"ACTION=remove",
> +			"DEVPATH=/devices/virtual/net/ltp-
> tun0/queues/rx-0",
> +			"SUBSYSTEM=queues",
> +		}
> +	};
> +
> +	struct uevent_desc rem_tx = {
> +		.msg = "remove@/devices/virtual/net/ltp-
> tun0/queues/tx-0",
> +		.value_cnt = 3,
> +		.values = (const char*[]) {
> +			"ACTION=remove",
> +			"DEVPATH=/devices/virtual/net/ltp-
> tun0/queues/tx-0",
> +			"SUBSYSTEM=queues",
> +		}
> +	};
> +
> +	struct uevent_desc rem = {
> +		.msg = "remove@/devices/virtual/net/ltp-tun0",
> +		.value_cnt = 4,
> +		.values = (const char*[]) {
> +			"ACTION=remove",
> +			"DEVPATH=/devices/virtual/net/ltp-tun0",
> +			"SUBSYSTEM=net",
> +			"INTERFACE=ltp-tun0",
> +		}
> +	};
> +
> +	const struct uevent_desc *const uevents[] = {
> +		&add,
> +		&add_rx,
> +		&add_tx,
> +		&rem_rx,
> +		&rem_tx,
> +		&rem,
> +		NULL
> +	};
> +
> +	pid = SAFE_FORK();
> +	if (!pid) {
> +		fd = open_uevent_netlink();
> +		TST_CHECKPOINT_WAKE(0);
> +		wait_for_uevents(fd, uevents);
> +		exit(0);
> +	}
> +
> +	TST_CHECKPOINT_WAIT(0);
> +
> +	generate_tun_uevents();
> +
> +	wait_for_pid(pid);
> +}
> +
> +static struct tst_test test = {
> +	.test_all = verify_uevent,
> +	.forks_child = 1,
> +	.needs_tmpdir = 1,
> +	.needs_checkpoints = 1,
> +	.needs_drivers = (const char *const []) {
> +		"tun",
> +		NULL
> +	},
> +	.needs_root = 1
> +};
> -- 
> 2.21.0
> 
> 

  reply	other threads:[~2019-08-26 15:55 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-26 14:01 [LTP] [PATCH v3 0/5] Add basic test for uevent netlink socket Cyril Hrubis
2019-08-26 14:01 ` [LTP] [PATCH v3 1/5] lib/tst_device: Export more functions Cyril Hrubis
2019-08-26 15:57   ` Clemens Famulla-Conrad
2019-09-02 13:02     ` Cyril Hrubis
2019-08-26 14:01 ` [LTP] [PATCH v3 2/5] kernel/uevent: Add uevent01 Cyril Hrubis
2019-08-26 15:57   ` Clemens Famulla-Conrad
2019-08-26 14:01 ` [LTP] [PATCH v3 3/5] kernel/uevent: Add uevent02 Cyril Hrubis
2019-08-26 15:55   ` Clemens Famulla-Conrad [this message]
2019-08-26 14:01 ` [LTP] [PATCH v3 4/5] libs/libltpuinput: Add uinput library Cyril Hrubis
2019-08-26 15:55   ` Clemens Famulla-Conrad
2019-08-26 14:01 ` [LTP] [PATCH v3 5/5] kernel/uevent: Add uevent03 Cyril Hrubis
2019-08-26 15:52   ` Clemens Famulla-Conrad
2019-08-26 15:59 ` [LTP] [PATCH v3 0/5] Add basic test for uevent netlink socket Clemens Famulla-Conrad

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1566834929.15851.13.camel@suse.de \
    --to=cfamullaconrad@suse.de \
    --cc=ltp@lists.linux.it \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox