From patchwork Wed Oct 21 12:57:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Yang Xu X-Patchwork-Id: 1385528 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=cn.fujitsu.com 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) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CGVsj4VWMz9sTD for ; Wed, 21 Oct 2020 23:58:17 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 1ABF33C319A for ; Wed, 21 Oct 2020 14:58:14 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-7.smtp.seeweb.it (in-7.smtp.seeweb.it [IPv6:2001:4b78:1:20::7]) by picard.linux.it (Postfix) with ESMTP id 6E1473C2474 for ; Wed, 21 Oct 2020 14:58:11 +0200 (CEST) Received: from heian.cn.fujitsu.com (mail.cn.fujitsu.com [183.91.158.132]) by in-7.smtp.seeweb.it (Postfix) with ESMTP id 2237E2009C8 for ; Wed, 21 Oct 2020 14:58:09 +0200 (CEST) X-IronPort-AV: E=Sophos;i="5.77,401,1596470400"; d="scan'208";a="100375798" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 21 Oct 2020 20:58:07 +0800 Received: from G08CNEXMBPEKD04.g08.fujitsu.local (unknown [10.167.33.201]) by cn.fujitsu.com (Postfix) with ESMTP id EBD3B48990FF; Wed, 21 Oct 2020 20:58:06 +0800 (CST) Received: from localhost.localdomain (10.167.220.84) by G08CNEXMBPEKD04.g08.fujitsu.local (10.167.33.201) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 21 Oct 2020 20:58:02 +0800 From: Yang Xu To: Date: Wed, 21 Oct 2020 20:57:51 +0800 Message-ID: <1603285074-28392-1-git-send-email-xuyang2018.jy@cn.fujitsu.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <20200722154558.GB2714@yuki.lan> References: <20200722154558.GB2714@yuki.lan> MIME-Version: 1.0 X-Originating-IP: [10.167.220.84] X-ClientProxiedBy: G08CNEXCHPEKD06.g08.fujitsu.local (10.167.33.205) To G08CNEXMBPEKD04.g08.fujitsu.local (10.167.33.201) X-yoursite-MailScanner-ID: EBD3B48990FF.A054D X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: xuyang2018.jy@cn.fujitsu.com X-Spam-Status: No, score=0.4 required=7.0 tests=KHOP_HELO_FCRDNS, SPF_HELO_NONE, SPF_NONE autolearn=disabled version=3.4.4 X-Virus-Scanned: clamav-milter 0.102.4 at in-7.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-7.smtp.seeweb.it Subject: [LTP] [PATCH v3 1/4] syscalls/msgstress: Add common file for msgstress 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: , Cc: ltp@lists.linux.it Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Copy old libmsgctl.c three functions(doreader,dowriter, fill_buffer, verify) into this common file. The reason for not putting it into lib directory because only msgstress cases use these functions. So raising them into lib level makes no sense. Signed-off-by: Yang Xu --- .../kernel/syscalls/ipc/msgstress/Makefile | 2 +- .../syscalls/ipc/msgstress/msgstress_common.c | 95 +++++++++++++++++++ .../syscalls/ipc/msgstress/msgstress_common.h | 26 +++++ 3 files changed, 122 insertions(+), 1 deletion(-) create mode 100644 testcases/kernel/syscalls/ipc/msgstress/msgstress_common.c create mode 100644 testcases/kernel/syscalls/ipc/msgstress/msgstress_common.h diff --git a/testcases/kernel/syscalls/ipc/msgstress/Makefile b/testcases/kernel/syscalls/ipc/msgstress/Makefile index b821bda01..2c8fa8e5b 100644 --- a/testcases/kernel/syscalls/ipc/msgstress/Makefile +++ b/testcases/kernel/syscalls/ipc/msgstress/Makefile @@ -6,7 +6,7 @@ top_srcdir ?= ../../../../.. LTPLIBS = ltpipc include $(top_srcdir)/include/mk/testcases.mk - +FILTER_OUT_MAKE_TARGETS := msgstress_common LTPLDLIBS += -lltpipc include $(top_srcdir)/include/mk/generic_leaf_target.mk diff --git a/testcases/kernel/syscalls/ipc/msgstress/msgstress_common.c b/testcases/kernel/syscalls/ipc/msgstress/msgstress_common.c new file mode 100644 index 000000000..3431355f6 --- /dev/null +++ b/testcases/kernel/syscalls/ipc/msgstress/msgstress_common.c @@ -0,0 +1,95 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) International Business Machines Corp., 2002 + * Copyright (c) 2013 Oracle and/or its affiliates. All Rights Reserved. + * Copyright (c) 2020 FUJITSU LIMITED. All rights reserved。 + */ + +#define TST_NO_DEFAULT_MAIN +#include "msgstress_common.h" + +int verify(char *buf, char val, int size, int child) +{ + while (size-- > 0) { + if (*buf++ != val) { + tst_res(TFAIL, "Verify error in child %d, *buf = %x, " + "val = %x, size = %d\n", child, *buf, val, + size); + return 1; + } + } + return 0; +} + +void do_reader(long key, int tid, long type, int child, int nreps) +{ + int i, size; + int id; + struct mbuffer buffer; + + id = SAFE_MSGGET(key, 0); + if (id != tid) { + tst_res(TFAIL, + "Message queue mismatch in the reader of child group" + " %d for message queue id %d\n", child, id); + return; + } + for (i = 0; i < nreps; i++) { + memset(&buffer, 0, sizeof(buffer)); + + size = SAFE_MSGRCV(id, &buffer, 100, type, 0); + if (buffer.type != type) { + tst_res(TFAIL, "Type mismatch in child %d, read #%d, " + "for message got %ld, exected %ld", + child, (i + 1), buffer.type, type); + return; + } + if (buffer.data.len + 1 != size) { + tst_res(TFAIL, "Size mismatch in child %d, read #%d, " + "for message got %d, expected %d", + child, (i + 1), buffer.data.len + 1, size); + return; + } + if (verify(buffer.data.pbytes, (key % 255), size - 1, child)) { + tst_res(TFAIL, "Verify failed in child %d read # = %d, " + "key = %lx\n", child, (i + 1), key); + return; + } + key++; + } +} + +void fill_buffer(char *buf, char val, int size) +{ + int i; + + for (i = 0; i < size; i++) + buf[i] = val; +} + +void do_writer(long key, int tid, long type, int child, int nreps) +{ + int i, size; + int id; + struct mbuffer buffer; + + id = SAFE_MSGGET(key, 0); + if (id != tid) { + tst_res(TFAIL, "Message queue mismatch in the reader of child" + " group %d for message queue id %d\n", child, id); + return; + } + + for (i = 0; i < nreps; i++) { + memset(&buffer, 0, sizeof(buffer)); + + do { + size = (lrand48() % 99); + } while (size == 0); + fill_buffer(buffer.data.pbytes, (key % 255), size); + buffer.data.len = size; + buffer.type = type; + SAFE_MSGSND(id, &buffer, size + 1, 0); + key++; + } +} diff --git a/testcases/kernel/syscalls/ipc/msgstress/msgstress_common.h b/testcases/kernel/syscalls/ipc/msgstress/msgstress_common.h new file mode 100644 index 000000000..81e2f288b --- /dev/null +++ b/testcases/kernel/syscalls/ipc/msgstress/msgstress_common.h @@ -0,0 +1,26 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2020 FUJITSU LIMITED. All rights reserved. + * Author: Yang Xu + */ + +#ifndef MSGSTRESS_COMMON_H +#define MSGSTRESS_COMMON_H + +#include +#include "tst_safe_sysv_ipc.h" +#include "tst_test.h" + +struct mbuffer { + long type; + struct { + char len; + char pbytes[99]; + } data; +}; + +void do_reader(long key, int tid, long type, int child, int nreps); +void do_writer(long key, int tid, long type, int child, int nreps); + +#endif +