From patchwork Tue Aug 20 15:18:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cyril Hrubis X-Patchwork-Id: 1150250 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=lists.linux.it (client-ip=213.254.12.146; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.cz Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46CZFZ4LV0z9sNk for ; Wed, 21 Aug 2019 01:18:58 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id E46A73C1D6C for ; Tue, 20 Aug 2019 17:18:55 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-4.smtp.seeweb.it (in-4.smtp.seeweb.it [IPv6:2001:4b78:1:20::4]) by picard.linux.it (Postfix) with ESMTP id CB9F93C1D00 for ; Tue, 20 Aug 2019 17:18:34 +0200 (CEST) Received: from mx1.suse.de (mx2.suse.de [195.135.220.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by in-4.smtp.seeweb.it (Postfix) with ESMTPS id E6EFC1000AC4 for ; Tue, 20 Aug 2019 17:18:27 +0200 (CEST) Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id C650BAF33 for ; Tue, 20 Aug 2019 15:18:33 +0000 (UTC) From: Cyril Hrubis To: ltp@lists.linux.it Date: Tue, 20 Aug 2019 17:18:29 +0200 Message-Id: <20190820151831.7418-4-chrubis@suse.cz> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190820151831.7418-1-chrubis@suse.cz> References: <20190820151831.7418-1-chrubis@suse.cz> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.99.2 at in-4.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.2 required=7.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, SPF_HELO_NONE,SPF_PASS autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-4.smtp.seeweb.it Subject: [LTP] [PATCH v2 3/5] kernel/uevent: Add uevent02 X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Similar to uevent01 but we create and remove a tun network card instead. Signed-off-by: Cyril Hrubis --- runtest/uevent | 1 + testcases/kernel/uevents/.gitignore | 1 + testcases/kernel/uevents/uevent02.c | 141 ++++++++++++++++++++++++++++ 3 files changed, 143 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..2c28d1810 --- /dev/null +++ b/testcases/kernel/uevents/uevent02.c @@ -0,0 +1,141 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (C) 2019 Cyril Hrubis + */ + +/* + * 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 +#include +#include +#include +#include + +#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 = 0, + .values = (const char*[]) { + "ACTION=add", + "DEVPATH=/devices/virtual/net/ltp-tun0", + "SUBSYSTEM=net", + "ITERFACE=ltp-tun0", + } + }; + + struct uevent_desc add_rx = { + .msg = "add@/devices/virtual/net/ltp-tun0/queues/rx-0", + .value_cnt = 0, + .values = (const char*[]) { + "ACTION=add", + "DEVPATH=/devices/virtual/net/ltp-tun0/queues/rx-0", + "SUBSYSTEM=queueus", + } + }; + + struct uevent_desc add_tx = { + .msg = "add@/devices/virtual/net/ltp-tun0/queues/tx-0", + .value_cnt = 0, + .values = (const char*[]) { + "ACTION=add", + "DEVPATH=/devices/virtual/net/ltp-tun0/queues/tx-0", + "SUBSYSTEM=queueus", + } + }; + + struct uevent_desc rem_rx = { + .msg = "remove@/devices/virtual/net/ltp-tun0/queues/rx-0", + .value_cnt = 0, + .values = (const char*[]) { + "ACTION=remove", + "DEVPATH=/devices/virtual/net/ltp-tun0/queues/rx-0", + "SUBSYSTEM=queueus", + } + }; + + struct uevent_desc rem_tx = { + .msg = "remove@/devices/virtual/net/ltp-tun0/queues/tx-0", + .value_cnt = 0, + .values = (const char*[]) { + "ACTION=remove", + "DEVPATH=/devices/virtual/net/ltp-tun0/queues/tx-0", + "SUBSYSTEM=queueus", + } + }; + + struct uevent_desc rem = { + .msg = "remove@/devices/virtual/net/ltp-tun0", + .value_cnt = 0, + .values = (const char*[]) { + "ACTION=remove", + "DEVPATH=/devices/virtual/net/ltp-tun0", + "SUBSYSTEM=net", + "ITERFACE=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); + } + + 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_root = 1, + .needs_drivers = (const char *const []) { + "tun", + NULL + }, +};