From owner-svn-src-all@FreeBSD.ORG Tue Jan 5 17:13:21 2010 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 12CBC1065676; Tue, 5 Jan 2010 17:13:21 +0000 (UTC) (envelope-from yanefbsd@gmail.com) Received: from mail-yw0-f197.google.com (mail-yw0-f197.google.com [209.85.211.197]) by mx1.freebsd.org (Postfix) with ESMTP id 8D2228FC0C; Tue, 5 Jan 2010 17:13:20 +0000 (UTC) Received: by ywh35 with SMTP id 35so7761527ywh.7 for ; Tue, 05 Jan 2010 09:13:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:references:message-id:from:to :in-reply-to:content-type:content-transfer-encoding:x-mailer :mime-version:subject:date:cc; bh=k3bimljpP8/EnSHhT/2WnfAntxnQMjdju44btgez6Ms=; b=hTWu5Yq96FDv00Uq8ancJgMjbWAKhG09iT2C86KTyCEN66TxZ7rIlBkLjmqdFZQ8sT rVclq4E4XDbO7/Lup+GqoXHVlCz02HNzjgcpsYnyiXLyTnJYJ4hsTFq5m9L+Rqdb9Q9/ 0xEHgvErPKmeCmQknB9zyUmqQr5+7r3vlcjps= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=references:message-id:from:to:in-reply-to:content-type :content-transfer-encoding:x-mailer:mime-version:subject:date:cc; b=u+nIGG7Yw8XGJmxLlaF7QleiEjTk8XEQtMNTIdrrq1CUbBBINlkVSG6o2R2dXVDpgS VKEJMK8Df/w9PpOqFsFz4/nRno80xMu/GfRRxqRDUWqs1MLxq/uYkY/z0zgSxeyTWr21 v7Su/UGKk+9NTq907jNR1qb7LpLocm8K+ll7M= Received: by 10.150.106.19 with SMTP id e19mr20882149ybc.323.1262711593955; Tue, 05 Jan 2010 09:13:13 -0800 (PST) Received: from ?10.68.43.79? ([166.205.5.36]) by mx.google.com with ESMTPS id 4sm6701595ywi.27.2010.01.05.09.13.11 (version=TLSv1/SSLv3 cipher=RC4-MD5); Tue, 05 Jan 2010 09:13:12 -0800 (PST) References: <201001051234.o05CYDlR096994@svn.freebsd.org> Message-Id: <80B3618B-57A9-4524-B4E1-0955DF291344@gmail.com> From: Garrett Cooper To: David Xu In-Reply-To: <201001051234.o05CYDlR096994@svn.freebsd.org> Content-Type: text/plain; charset=us-ascii; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit X-Mailer: iPhone Mail (7D11) Mime-Version: 1.0 (iPhone Mail 7D11) Date: Tue, 5 Jan 2010 10:12:50 -0700 Cc: "svn-src-head@freebsd.org" , "svn-src-all@freebsd.org" , "src-committers@freebsd.org" Subject: Re: svn commit: r201575 - head/tools/regression/posixsem2 X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 05 Jan 2010 17:13:21 -0000 Sent from my iPhone On Jan 5, 2010, at 5:34 AM, David Xu wrote: > Author: davidxu > Date: Tue Jan 5 12:34:13 2010 > New Revision: 201575 > URL: http://svn.freebsd.org/changeset/base/201575 > > Log: > Add test code for POSIX semaphore implementation. > > Added: > head/tools/regression/posixsem2/ > head/tools/regression/posixsem2/Makefile (contents, props changed) > head/tools/regression/posixsem2/semtest.c (contents, props changed) > > Added: head/tools/regression/posixsem2/Makefile > === > === > === > ===================================================================== > --- /dev/null 00:00:00 1970 (empty, because file is newly added) > +++ head/tools/regression/posixsem2/Makefile Tue Jan 5 12:34:13 > 2010 (r201575) > @@ -0,0 +1,9 @@ > +# $FreeBSD$ > + > +PROG= semtest > +SRCS= semtest.c > +NO_MAN= > + > +WARNS?= 3 > + > +.include > > Added: head/tools/regression/posixsem2/semtest.c > === > === > === > ===================================================================== > --- /dev/null 00:00:00 1970 (empty, because file is newly added) > +++ head/tools/regression/posixsem2/semtest.c Tue Jan 5 12:34:13 > 2010 (r201575) > @@ -0,0 +1,101 @@ > +/* $FreeBSD$ */ > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +#define SEM_NAME "/semtst" > + > +int test_unnamed(void); > +int test_named(void); > + > +int > +test_unnamed(void) > +{ > + sem_t *s; > + pid_t pid; > + int status; > + > + printf("testing unnamed process-shared semaphore\n"); > + s = (sem_t *)mmap(NULL, sizeof(sem_t), PROT_READ|PROT_WRITE, > MAP_ANON|MAP_SHARED, > + -1, 0); > + if (s == MAP_FAILED) > + err(1, "mmap failed"); > + if (sem_init(s, 1, 0)) > + err(2, "sem_init failed"); > + if ((pid = fork()) == 0) { > + printf("child: sem_wait()\n"); > + if (sem_wait(s)) > + err(3, "sem_wait failed"); > + printf("child: sem_wait() returned\n"); > + exit(0); > + } else { > + sleep(1); > + printf("parent: sem_post()\n"); > + if (sem_post(s)) > + err(4, "sem_post failed"); > + waitpid(pid, &status, 0); Same as below... > + if (WIFEXITED(status) && WEXITSTATUS(status) == 0) > + printf("OK.\n"); > + else > + printf("Failure."); > + } > + return (0); > +} > + > +int > +test_named(void) > +{ > + sem_t *s, *s2; > + pid_t pid; > + int status; > + > + printf("testing named process-shared semaphore\n"); > + sem_unlink(SEM_NAME); > + s = sem_open(SEM_NAME, O_CREAT, 0777); > + if (s == SEM_FAILED) > + err(1, "sem_open failed"); > + s2 = sem_open(SEM_NAME, O_CREAT, 0777); > + if (s2 == SEM_FAILED) > + err(2, "second sem_open call failed"); > + if (s != s2) > + err(3, "two sem_open calls for same semaphore do not returm > same address."); > + if (sem_close(s2)) > + err(4, "sem_close failed"); > + if ((pid = fork()) == 0) { > + printf("child: sem_wait()\n"); > + if (sem_wait(s)) > + err(5, "sem_wait failed"); > + printf("child: sem_wait() returned\n"); > + exit(0); > + } else { > + sleep(1); > + printf("parent: sem_post()\n"); > + if (sem_post(s)) > + err(6, "sem_post failed"); > + waitpid(pid, &status, 0); waitpid can fail and the status reported could be completely bogus. Maybe this should be the first branch condition (check for == 0) in the if-statement below? > + if (WIFEXITED(status) && WEXITSTATUS(status) == 0) > + printf("OK.\n"); > + else > + printf("Failure."); > + } > + > + if (sem_close(s)) > + err(7, "sem_close failed"); > + > + return (0); > +} > + > +int > +main(void) > +{ > + test_unnamed(); > + test_named(); > + return (0); > +}