From patchwork Wed Nov 2 19:26:53 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 80542 Delivered-To: patch@linaro.org Received: by 10.140.97.247 with SMTP id m110csp291958qge; Wed, 2 Nov 2016 12:29:42 -0700 (PDT) X-Received: by 10.98.61.152 with SMTP id x24mr9703802pfj.88.1478114982076; Wed, 02 Nov 2016 12:29:42 -0700 (PDT) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id ie7si3949336pad.127.2016.11.02.12.29.41 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 02 Nov 2016 12:29:42 -0700 (PDT) Received-SPF: pass (google.com: domain of libc-alpha-return-74328-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org; spf=pass (google.com: domain of libc-alpha-return-74328-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-74328-patch=linaro.org@sourceware.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:in-reply-to :references; q=dns; s=default; b=rnBE/Ik1U03m/ZgVMaJ8PYK71sVt4LH jEGqEBk8+yaxEnhIs57EWFYdB752szZd0OmyUj7el13jih8v3ATZORgFNS/H10Si WhAcemV3bq+4WusrewMIgW9PPhVWRrSzNf37O6jxi0gvTN0S2hBMP73ziVIfRyZg UNSQWTll7s58= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:in-reply-to :references; s=default; bh=vM0crPLF4fpQl0YG7MdLHwFGGCA=; b=a6XAK QuBXB+e7pYbIDa/SiOH/hOSb/zs4uuyr9L1yawE3iUEkR5/oDjWgLXDpQ+rrPzWc h7HMFyelR1elP+BaRNxkk+BKTxqaGQOvlf1KTsrrwN6CevqKASgc4nPPau6Ri58Q FQsyg4X8fvwFlsY0EDIFFb1IJ6BDi5COWJEyMs= Received: (qmail 65781 invoked by alias); 2 Nov 2016 19:27:28 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 65526 invoked by uid 89); 2 Nov 2016 19:27:26 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.4 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=no version=3.3.2 spammy=1130 X-HELO: mail-ua0-f177.google.com X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=Vh8D2DLf4ejLYCXS9dFW20pFBGmahLH2rpkTrGonu2E=; b=UvaCUEIwVQ4ybWQzUkexb/OUp/b0TlLrChRY0LQ/n53fOXFDXkL2gxrbFWtExljnlv EXd9ZjyDN/jhUcWPfaMBgc6jz1OOMfCahoAR6QMk+zvUCouAAJJstFG4bZsLpkrf6KBR cW30SF8amysR76FuWzYTUA7wBBgucyi2JVrRD3BN/diTvNBFfiZ/Q91e7r/hURuXaRHq syBA9ODoD0fJsEMrtKhtaD//oR17L6S1cmRhZGl45C9sBA1aEDhyWvk+7hq2QAEQK8q/ SY3RUMYEskoK2GMBg2LlfRTZPuyPI9KD2Ku7TUrCOpFoebYgtXaldgByh67seoRZzTSZ H1Bw== X-Gm-Message-State: ABUngvcFOmsuLYph5VdrqyUFNRgLk8ZF/32XJbo3EXhKEPYDDFPWTEjgvl60mdHE2Y1fmoXo X-Received: by 10.176.1.17 with SMTP id 17mr3628150uak.143.1478114840187; Wed, 02 Nov 2016 12:27:20 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH v2 16/16] Add SYSV shared memory test Date: Wed, 2 Nov 2016 17:26:53 -0200 Message-Id: <1478114813-3526-17-git-send-email-adhemerval.zanella@linaro.org> In-Reply-To: <1478114813-3526-1-git-send-email-adhemerval.zanella@linaro.org> References: <1478114813-3526-1-git-send-email-adhemerval.zanella@linaro.org> Changes from previous version: - Use __ASSUME_SYSVIPC_SYSCALL instead of __NR_syscall to issue the wired syscall or the ipc one. -- This patch adds a simple SYSV shared memory test to check for correct argument passing on kernel. The idea is neither to be an extensive testing nor to check for any specific Linux test. * sysvipc/Makefile (tests): Add test-sysvshm. * sysvipc/test-sysvshm.c: New file. --- ChangeLog | 3 ++ sysvipc/Makefile | 2 +- sysvipc/test-sysvshm.c | 130 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 134 insertions(+), 1 deletion(-) create mode 100644 sysvipc/test-sysvshm.c -- 2.7.4 diff --git a/sysvipc/Makefile b/sysvipc/Makefile index 32d64dc..daede74 100644 --- a/sysvipc/Makefile +++ b/sysvipc/Makefile @@ -30,7 +30,7 @@ routines := ftok \ semop semget semctl semtimedop \ shmat shmdt shmget shmctl -tests := test-sysvmsg test-sysvsem +tests := test-sysvmsg test-sysvsem test-sysvshm include ../Rules diff --git a/sysvipc/test-sysvshm.c b/sysvipc/test-sysvshm.c new file mode 100644 index 0000000..4f3f22e --- /dev/null +++ b/sysvipc/test-sysvshm.c @@ -0,0 +1,130 @@ +/* Basic tests for SYSV shared memory functions. + Copyright (C) 2016 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include +#include +#include +#include +#include +#include + +static void do_prepare (void); +#define PREPARE(argc, argv) do_prepare () +static int do_test (void); +#define TEST_FUNCTION do_test () + +/* This defines the `main' function and some more. */ +#include + +/* These are for the temporary file we generate. */ +static char *name; +static int shmid; + +static void +remove_shm (void) +{ + /* Enforce message queue removal in case o early test failure. + Ignore error since the msgq maybe already being removed. */ + shmctl (shmid, IPC_RMID, 0); +} + +static void +do_prepare (void) +{ + int fd = create_temp_file ("tst-sysvshm.", &name); + if (fd == -1) + FAIL_EXIT1 ("cannot create temporary file (errno=%d)", errno); +} + +#define CHECK_EQ(v, k) \ + if ((v) != (k)) \ + FAIL_EXIT1("%d != %d", v, k) + +/* It is not an extensive test, but rather a functional one aimed to check + correct parameter passing on kernel. */ + +#define SHM_MODE 0666 + +static int +do_test (void) +{ + atexit (remove_shm); + + key_t key = ftok (name, 'G'); + if (key == -1) + FAIL_EXIT1 ("ftok failed"); + + long int pgsz = sysconf (_SC_PAGESIZE); + if (pgsz == -1) + FAIL_EXIT1 ("sysconf (_SC_PAGESIZE) failed (errno = %d)", errno); + + shmid = shmget(key, pgsz, IPC_CREAT | IPC_EXCL | SHM_MODE); + if (shmid == -1) + { + if (errno == ENOSYS) + FAIL_UNSUPPORTED ("msgget not supported"); + FAIL_EXIT1 ("msgget failed (errno=%d)", errno); + } + + /* Get shared memory kernel information and do some sanitiy checks. */ + struct shmid_ds shminfo; + if (shmctl (shmid, IPC_STAT, &shminfo) == -1) + FAIL_EXIT1 ("shmctl with IPC_STAT failed (errno=%d)", errno); + + if (shminfo.shm_perm.__key != key) + FAIL_EXIT1 ("msgid_ds::msg_perm::key (%d) != %d", + (int) shminfo.shm_perm.__key, (int) key); + if (shminfo.shm_perm.mode != SHM_MODE) + FAIL_EXIT1 ("msgid_ds::shm_perm::mode (%o) != %o", + shminfo.shm_perm.mode, SHM_MODE); + if (shminfo.shm_segsz != pgsz) + FAIL_EXIT1 ("msgid_ds::shm_segsz (%lu) != %lu", + (long unsigned) shminfo.shm_segsz, pgsz); + + /* Attach on shared memory and realize some operations. */ + int *shmem = shmat (shmid, NULL, 0); + if (shmem == (void*) -1) + FAIL_EXIT1 ("shmem failed (errno=%d)", errno); + + shmem[0] = 0x55555555; + shmem[32] = 0x44444444; + shmem[64] = 0x33333333; + shmem[128] = 0x22222222; + + if (shmdt (shmem) == -1) + FAIL_EXIT1 ("shmem failed (errno=%d)", errno); + + shmem = shmat (shmid, NULL, SHM_RDONLY); + if (shmem == (void*) -1) + FAIL_EXIT1 ("shmem failed (errno=%d)", errno); + + CHECK_EQ (shmem[0], 0x55555555); + CHECK_EQ (shmem[32], 0x44444444); + CHECK_EQ (shmem[64], 0x33333333); + CHECK_EQ (shmem[128], 0x22222222); + + if (shmdt (shmem) == -1) + FAIL_EXIT1 ("shmem failed (errno=%d)", errno); + + /* Finally free up the semnaphore resource. */ + if (shmctl (shmid, IPC_RMID, 0) == -1) + FAIL_EXIT1 ("semctl failed (errno=%d)", errno); + + return 0; +}