From patchwork Tue Jan 4 08:18:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrea Cervesato X-Patchwork-Id: 1575079 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=suse.com header.i=@suse.com header.a=rsa-sha256 header.s=susede1 header.b=b2wm4iro; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) 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=) 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 bilbo.ozlabs.org (Postfix) with ESMTPS id 4JSlsr0z1hz9sRR for ; Tue, 4 Jan 2022 19:20:16 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id CEDF83C903B for ; Tue, 4 Jan 2022 09:20:13 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-3.smtp.seeweb.it (in-3.smtp.seeweb.it [IPv6:2001:4b78:1:20::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 74A573C910D for ; Tue, 4 Jan 2022 09:18:46 +0100 (CET) Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by in-3.smtp.seeweb.it (Postfix) with ESMTPS id CD9541A008A7 for ; Tue, 4 Jan 2022 09:18:45 +0100 (CET) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 841BC1F398; Tue, 4 Jan 2022 08:18:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1641284325; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XjjMpYIlb+Gv0Bh4vxWmd7YcXiYPDMHR25S6IA+GqIU=; b=b2wm4iro1EhlkQ2Y14j92KJDF0j47rG4xMqLdps/Uctz7KBl5O/GRx92U51LfhLK7ovFvf jZ87R5ZY/TflX2JByWVh1HLXIm5OCgfrA81LkHO/HLV+C11aL0k782TNtv5Sd/TdkelIeJ t4rf8312IFs8sIe7Qf/9VEZvCZEQzvU= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 38D4213AB9; Tue, 4 Jan 2022 08:18:45 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 8IL7CeUC1GGeZwAAMHmgww (envelope-from ); Tue, 04 Jan 2022 08:18:45 +0000 To: ltp@lists.linux.it Date: Tue, 4 Jan 2022 09:18:35 +0100 Message-Id: <20220104081836.22827-10-andrea.cervesato@suse.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220104081836.22827-1-andrea.cervesato@suse.com> References: <20220104081836.22827-1-andrea.cervesato@suse.com> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.102.4 at in-3.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-3.smtp.seeweb.it Subject: [LTP] [PATCH v1 09/10] Add wqueue08 new test 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: , X-Patchwork-Original-From: Andrea Cervesato via ltp From: Andrea Cervesato Reply-To: Andrea Cervesato Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" This test checks if KEYCTL_WATCH_KEY event is recognized by watch queue Signed-off-by: Andrea Cervesato --- testcases/kernel/watchqueue/wqueue08.c | 83 ++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 testcases/kernel/watchqueue/wqueue08.c diff --git a/testcases/kernel/watchqueue/wqueue08.c b/testcases/kernel/watchqueue/wqueue08.c new file mode 100644 index 000000000..202cc0274 --- /dev/null +++ b/testcases/kernel/watchqueue/wqueue08.c @@ -0,0 +1,83 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (C) 2021 Andrea Cervesato + */ + +/*\ + * [Description] + * + * Test if key watch removal is correctly recognized by watch queue. + */ + +#define _FCNTL_H + +#include "tst_test.h" +#include "lapi/keyctl.h" +#include "common.h" + +static int *keep_polling; + +static struct watch_notification_filter meta_filter = { + .nr_filters = 1, + .__reserved = 0, + .filters = { + [0] = { + .type = WATCH_TYPE_META, + .subtype_filter[0] = UINT_MAX, + }, + }, +}; + +static void saw_watch_removal(struct watch_notification *n, size_t len, unsigned int wtype) +{ + if (wtype != WATCH_TYPE_META) + return; + + if (n->subtype == WATCH_META_REMOVAL_NOTIFICATION) + tst_res(TPASS, "Meta removal notification received"); + else + tst_res(TFAIL, "Event not recognized"); +} + +static void setup(void) +{ + keep_polling = SAFE_MMAP(NULL, sizeof(int), PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANONYMOUS, -1, 0); +} + +static void cleanup(void) +{ + *keep_polling = 0; + SAFE_MUNMAP(keep_polling, sizeof(int)); +} + +static void run(void) +{ + int fd; + int pid; + key_serial_t key; + + fd = wqueue_watch(256, &meta_filter); + key = wqueue_add_key(fd); + + *keep_polling = 1; + + pid = SAFE_FORK(); + if (pid > 0) { + wqueue_consumer(fd, keep_polling, saw_watch_removal); + return; + } + + /* if watch_id = -1 key is removed from the watch queue */ + safe_keyctl(KEYCTL_WATCH_KEY, key, fd, -1); + + *keep_polling = 0; + + SAFE_CLOSE(fd); +} + +static struct tst_test test = { + .setup = setup, + .cleanup = cleanup, + .test_all = run, + .forks_child = 1 +};