From patchwork Tue Dec 27 14:01:26 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: 708973 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3tnyKZ2JD2z9syB for ; Wed, 28 Dec 2016 01:04:34 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="EfZ2a1lt"; dkim-atps=neutral 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=kePX98hmXsivcOVuE7qi7M58t06kpX3 FUAMxNVv7ugVXhO215vDrGVzLrucaEHHK4lWgLmSFZd5/AM2Ecc/eZhqpx7NHdvA SGhJFdFlqnctjHXAsUQBYkl5DBYrw/9IoYpwm6d4aTikV70LJ+48PIUYJGU8fenh OW0cAiOltcbA= 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=VMelQkalnxLDfmiS/ybQjP1rWZw=; b=EfZ2a 1ltevRBrxSmougzGKlubOyWj6vnj5iBGbmMyN/NVbUrjlcjomyi9YzGJrF9Jd0xF 2H3xDEEtXgum/LRozw93rrAVSuuna5Yoku8Kbzna3DOEiu2iJcrrUy8s6kewhuEs Dfk8C7ReihPva/J/uIEp5YhDOOA0wWWjb7K+ds= Received: (qmail 79736 invoked by alias); 27 Dec 2016 14:02:22 -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 78270 invoked by uid 89); 27 Dec 2016 14:02:07 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: mail-yw0-f182.google.com X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=snqTYH2nYe0fx+/HjBQ0SwYK5vMqvE70yFCLOC0jFqE=; b=dlV2Nt0O494VhOyzr02djtvavaZj0oiA9UcdckCpF8rbiorHDMCiZiSVzDYH8+VLvj CM/g3Xa6SIsozPdaWZf945mD3iJth5Qysjk1lm02ysgOvFMrRX2wkfKLbLjAqOFuvHsn /ML9Ki+adMzOuD30YAhCiGEE/e5nflsZ9iwvRjk6pA3vd6pu2+qU9c6sGpEwrVpaNbv3 g9rYOPRSCKnsl8HV0R5nwdhNOYo/Tckt9zKOlN1IPHPM9CjgVPkhfeO11M0BW/U3TlvP GaUpc1xuGsGb6L6Iia3qumpLVFao7zquETi6Z5gdryjl5eZLybh6hpkqhapVoGBztvEQ 3apQ== X-Gm-Message-State: AIkVDXI8drXt2v6hquBgaWmL0Xj2gZ4vZCq4vJCT4UCwbREbTMoqSQ9hWcXYySmuYBtqvrL1 X-Received: by 10.13.249.7 with SMTP id j7mr24644790ywf.279.1482847315928; Tue, 27 Dec 2016 06:01:55 -0800 (PST) From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH 17/17] Add SYSV shared memory test Date: Tue, 27 Dec 2016 12:01:26 -0200 Message-Id: <1482847286-29933-18-git-send-email-adhemerval.zanella@linaro.org> In-Reply-To: <1482847286-29933-1-git-send-email-adhemerval.zanella@linaro.org> References: <1482847286-29933-1-git-send-email-adhemerval.zanella@linaro.org> 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 | 131 +++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 135 insertions(+), 1 deletion(-) create mode 100644 sysvipc/test-sysvshm.c 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..2c197cc --- /dev/null +++ b/sysvipc/test-sysvshm.c @@ -0,0 +1,131 @@ +/* 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 +#include + +#include +#include +#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 of early test failure. + Ignore error since the shm may already have being removed. */ + shmctl (shmid, IPC_RMID, 0); +} + +static void +do_prepare (int argc, char *argv[]) +{ + int fd = create_temp_file ("tst-sysvshm.", &name); + if (fd == -1) + FAIL_EXIT1 ("cannot create temporary file (errno=%d)", errno); +} + +#define PREPARE do_prepare + +/* It is not an extensive test, but rather a functional one aimed to check + correct parameter passing on kernel. */ + +#define CHECK_EQ(v, k) \ + if ((v) != (k)) \ + FAIL_EXIT1("%d != %d", v, k) + +#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 ("shmget not supported"); + FAIL_EXIT1 ("shmget failed (errno=%d)", errno); + } + + /* Get shared memory kernel information and do some sanity 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 ("shmid_ds::shm_perm::key (%d) != %d", + (int) shminfo.shm_perm.__key, (int) key); + if (shminfo.shm_perm.mode != SHM_MODE) + FAIL_EXIT1 ("shmid_ds::shm_perm::mode (%o) != %o", + shminfo.shm_perm.mode, SHM_MODE); + if (shminfo.shm_segsz != pgsz) + FAIL_EXIT1 ("shmid_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; +} + +#include