posixtestsuite/0040755000000000000000000000000010515625275012704 5ustar rootrootposixtestsuite/NEWS0100644000000000000000000000622310247730754013404 0ustar rootrootRELEASE DATES: --------------- -June 03, 2005 Version 1.5.1 Released PTS-1.5.1 has a plenty of AIO interface test additions and bug-fixes by Sebastien Decugis. Also there are a lot of bug fixes by other people. Thanks to Sebastien Decugis and other people for continued support and contributions. This release has been tested on glibc-2.3.3 and kernel 2.6.10 with libposix-aio-0.3. The test result for this release can be found here: http://posixtest.sourceforge.net/testpass/PTS_1.5.1-2.6.10-PAIO_ia32.htm -December 17, 2004 Version 1.5.0 Released A much anticipated release with plenty of interface test additions and bug-fixes. Added AIO test suite by Laurent Vivier. Special thanks to Sebastien Decugis and Ulrich Drepper for continued support and contributions. Also exciting news about OSDL and Bull integrating PTS into OSDL's Scalable Test Platform (STP). -July 06, 2004 Version 1.4.3 Released Here goes posixtest-1.3. Besides many bug fixes, this release includes new pthread test cases (conformance, functional, stress) by Sebastien Decugis and Abhijeet Bisain. Special thanks goes to people who made contributions. And we are glad that PTS is helping kernel, library and application developers and OSDs on their POSIX related work. Please see the release page for downloads and more information. -May 27, 2004 Version 1.4.2 Released Posixtestsuite-1.4.2 adds several pthread test cases by Sebastien Decugis. Also there are a lot of bug fixes by Ulrich Drepper and other people. This suite has been run on latest glibc and linux kernel 2.6.5. All the failed cases has been analyzed. Please see the release page for downloads and more information. -May 01, 2004 Version 1.4.1 Released posixtestsuite-1.4.1 fixes a bunch of bugs in 1.4.0 version. This release has been tested on glibc-2004-04-29 cvs pull (NPTL enabled) and linux-2.6.5-mm6 kernel.It is noted that "POSIX Message Queues" has been integrated into linux kernel and glibc. Please see the release page for downloads and more information. The test result for this release can be found here: test results - PTS 1.4.1, Kernel 2.6.5-mm6, ia32 . -April 15, 2004 Version 1.4.0 Released POSIX Test Suite 1.4.0 includes more pthread conformance test cases. Now we have test cases covering almost all pthread APIs. Conformance test cases for options like CPT, TCT, TMR are also added. There are also a lot of bug fixes made from the previous 1.3.0 version (thanks for Ulrich Drepper's patches and to everyone who made contributions). Please see the release page for downloads and more information. -March 11, 2004 Test Pass Results - (CVS pull 3-04-04) POSIX Test Suite test pass results available for [CVS pull 3-04-04, Kernel 2.6.1, libc-2004-02-15 and message queue 4.17 patch on IA64 platform]. The results can be found here: test results - cvs 3-04-04, Kernel 2.6.1, ia64 . -March 1, 2004 Test Pass Results - (CVS pull 2-20-04) POSIX Test Suite test pass results available for [CVS pull 2-20-04, Kernel 2.6.1, libc-2004-02-01 and message queue 4.17 patch on IA32 platform]. We are currently in the process of setting up a main test results page, but until then, the results can be found here: test results - cvs 2-20-04, Kernel 2.6.1 . posixtestsuite/ChangeLog0100644000000000000000000001526310515115011014440 0ustar rootroot10-19-2005 1.5.2 Release - Code cleanups by Sebastien Decugis - Add a patch for cleaner build in cross environment from Joseph S. Myers - Add a patch to _POSIX_CPUTIME and_POSIX_THREAD_CPUTIME handling from Joseph S. Myers - Make the aio_read/write tests concerningthe offset maximum return PTS_UNTESTED by Sebastien Decugis - A patch from Randy.Dunlap to fix shm conformance uninitialzedvariables - A patch from Randy.Dunlap to fix 2 pthread conformance problems - The patches for sem_post_5_1 and sem_post_8_1 from Yi Xu - A patch for sem_close_1_1 from Yi Xu - A patch from Randy.Dunlap for sem_lock to increase BUF_SIZE to prevent segment fault. 06-03-2005 1.5.1 Release - conformance/interfaces/aio_* and conformance/interface/lio_listio: add new cases and bug fixes by Sebastien Decugis. - add execute.sh by B. Thangaraju. 01-05-2005 1.5.0 Release 07-05-2004 1.4.3 Release 07-05-2004 adam.li@intel.com - functional/schedule/1-1.c 1-2.c: New case by Abhijeet Bisain. - stress/threads/pthread_cond_timedwait/stress1.c stress2.c: New case by Sebastien Decugis. 07-01-2004 adam.li@intel.com - pthread_attr_setschedparam/1-3.c 1-4.c: Add test cases by Abhijeet Bisain. - stress/threads/assertions.xml, stress/threads/pthread_cond_timedwait/: New case by Sebastien Decugis 06-29-2004 adam.li@intel.com - pthread_attr_setinheritsched/2-3.c, 2-4.c - functional/threads/condvar/, README: Add test cases by Abhijeet Bisain. 06-28-2004 adam.li@intel.com - stress/threads/pthread_mutex_init/, pthread_mutex_lock/, pthread_cond_init/: Add stress/scalability cases by Sebastien Decugis 06-22-2004 adam.li@intel.com - pthread_cond_destroy/speculative/4-1.c, pthread_mutex_destroy/ speculative/4-2.c, pthread_exit/3-1.c: Add new test case by Abhijeet Bisain 06-15-2004 adam.li@intel.com - pthread_cond_init/1-2.c, 2-2.c,4-1.c 4-2.c: Add test case by Sebastien Decugis. - pthread_cancel/2-2.c, 2-3.c, 3-3.c: Add test case by Abhijeet Bisain. 06-11-2004 adam.li@intel.com - pthread_cond_signal: Add Sebastien DECUGIS's patch 06-07-2004 adam.li@intel.com - locate-test: Remove -printf argument for 'find' for POSIX conformant. - Makefile: Remove --defined-only option for 'nm' for POSIX conformant. - sched_yield/1-1.c: Fix warning on 64-bit system. - pthread_attr_setstacksize/1-1.c, pthread_attr_getstacksize/1-1.c: Remove the output. 06-04-2004 adam.li@intel.com - pthread_attr_getschedparam, pthread_attr_setschedparam: Add new case by Abhijeet Bisain. - pthread_attr_s(g)etschedpolicy: Fix. Misuse perror. 06-02-2004 adam.li@intel.com - clock_getres/7-1.c,8-1.c: Fix incorrect output, compile warning. 05-27-2004 adam.li@intel.com - sigaction/21-1.c: Fix. Add missing posixtest.h - pthread_rwlock_trylock/3-1.c: Moved to speculative. 05-27-2004 1.4.2 Release 05-24-2004 adam.li@intel.com - mmap/13-1.c: Fix. mmap() will update st_atime(). - sigaction/9-1.c: Fix. Select not block. - strftime/1-1.c: Fix. %B judgement is not correct. - mmap/32-1.c: Fix. Change the scenario. 05-20-2004 adam.li@intel.com - sched_yield/1-1.c: Fix. Incorrect thread return status. - Add test case by Sebastien Decugis(sebastien.decugis@ext.bull.net) pthread_mutex_unlock/5-1.c, 5-2.c - pthread_mutexattr_settype/coverage.txt: Fix. - behavior/signal.h/18-1.c,19-1.c,20-1.c,21-1.c: Fix struct stack_t, struct siginfo_t. 05-13-2004 adam.li@intel.com - Add case pthread_mutex_init/5-1.c, pthread_mutex_init/speculative/5-2.c, pthread_mutex_lock/3-1.c, 4-1.c, 5-1.c by Sebastien Decugis(sebastien.decugis@ext.bull.net) - sem_post/8-1.c: Fix. Will leave Zombie process if fail. 05-10-2004 adam.li@intel.com - Apply Ulrich Drepper's patch: sem_post/8-1.c: Add error check and clean up code pthread_attr_getstackaddr/1-1.c: Fix printf format. pthread_attr_setstack/2-1.c, pthread_attr_setstackaddr/2-1.c, pthread_attr_setstacksize/2-1.c: define _GNU_SOURCE correctly. 05-09-2004 adam.li@intle.com - Add cases pthread_mutex_init/1-2.c, 3-2.c, 5-3.c by Sebastien Decugis(sebastien.decugis@ext.bull.net) 05-01-2004 1.4.1 Release 04-30-2004 adam.li@intel.com - sigqueue/12-1.c: Use setuid() instead of seteuid() - sigqueue/3-1.c: Same as above. - shm_open/40-1.c: Remove it. This case cannot exit cleanly, leaving zombie processes. - shm_open/33-1.c: Remove. Improper scenario. - shm_open/23-1.c: Rewrite the test scenario. - pthread_attr_setinheritsched/2-2.c: Bug fix - pthread_attr_setinheritsched/5-1.c: Remove. Not correct. - pthread_attr_setscope/5-1.c: Return PTS_UNTESTED - sched_setparam/23-6.c: Fix the case. It was untested before. - sched_setscheduler/17-5.c: make -1 as a invalid policy. - sched_setscheduler/20-1.c: Fix. It was untested before. 04-29-2004 adam.li@intel.com - add mq_timedsend/16-1.c: Use CLOCK_REALTIME - timer_getoverrun/2-3.c: Fix bug. It can pass on glibc now. 04-23-2004 adam.li@intel.com - add mmap/11-4.c mmap/11-5.c - mmap/11-2.c mmap/11-3.c: Misunderstand the spec. Fix. 04-22-2004 adam.li@intel.com - pthread_mutexattr_settype/2-1.c: Bug fix 04-20-2004 adam.li@intel.com - mmap/24-2.c 11-2.c 11-3.c: Bug fix 04-04-2004 1.4.0 Release - Add test cases to implement tags: CS, CPT, TCT. - Bug fix from Ulrich Drepper. - Tested on Linux kernel 2.6, and fixed bugs exposed. 04-30-2003 1.0.0 Release - Complete signals suite - Complete process scheduling suite - Snapshot of threads tests (most of the non-tag associated APIs) - Bug fixes in all areas (including adding "_POSIX_C_SOURCE=200112L" to the Makefile to make the actual test suite POSIX compliant) - Added QUICK-START document to top-level dir rolla.n.selbak REMOVE-THIS AT intel DOT com 03-21-2003 0.9.0 Release - More timers bug fixes - Complete semaphores suite (including bug fixes) - snapshot of signals tests (including bug fixes) - Complete message queues suite - Snapshot of threads tests (most of the non-tag associated APIs) - framework bug fixes. Added the ./run_tests script. rolla.n.selbak REMOVE-THIS AT intel DOT com 02-10-2003 0.2.0 Release - timers bug fixes - snapshot of semaphores tests - snapshot of signals tests - snapshot of threads tests - framework can build/run functional/stress tests julie.n.fleischer REMOVE-THIS AT intel DOT com 12-16-2002 0.1.0 Release - timers tests for TMR and CS tags (for timers) julie.n.fleischer REMOVE-THIS AT intel DOT com posixtestsuite/exec-func.sh0100644000000000000000000000021610432220573015077 0ustar rootroot#!/usr/bin/env bash for d in $(./locate-test --frun); do echo "Testing $d" pushd $d >/dev/null ./run.sh popd >/dev/null done posixtestsuite/Makefile0100644000000000000000000001306410432031157014331 0ustar rootroot# Copyright (c) 2002, Intel Corporation. All rights reserved. # Created by: inaky.perez-gonzalez REMOVE-THIS AT intel DOT com # This file is licensed under the GPL license. For the full content # of this license, see the COPYING file at the top level of this # source tree. # # Kind of a little bit bastardized automakefile ... This is the # temporary glue to hold it all together; once our needs change or we # need something more advanced, we'll implement it. # # So far, I understand Make is not the best language, but I felt lazy # today and wanted to use the default rules of automake [did I alredy # mentioned I am bastardizing it?]. # # Ok, I don't use Automake any more # # Added patch from dank REMOVE-THIS AT kegel DOT com # # Added tests timeout from Sebastien Decugis (http://nptl.bullopensource.org) # Expiration delay is 240 seconds TIMEOUT_VAL = 240 # The following value is the shell return value of a timedout application. # with the bash shell, the ret val of a killed application is 128 + signum # and under Linux, SIGALRM=14, so we have (Linux+bash) 142. TIMEOUT_RET = $(shell cat $(top_builddir)/t0.val) top_builddir = . LOGFILE = $(top_builddir)/logfile LDFLAGS := $(shell cat LDFLAGS | grep -v \^\#) RUN_TESTS := $(shell $(top_builddir)/locate-test \ --execs $(top_builddir)/$(POSIX_TARGET)) BUILD_TESTS := $(shell $(top_builddir)/locate-test \ --buildable $(top_builddir)/$(POSIX_TARGET)) FUNCTIONAL_MAKE := $(shell $(top_builddir)/locate-test --fmake) FUNCTIONAL_RUN := $(shell $(top_builddir)/locate-test --frun) STRESS_MAKE := $(shell $(top_builddir)/locate-test --smake) STRESS_RUN := $(shell $(top_builddir)/locate-test --srun) PWD := $(shell pwd) TIMEOUT = $(top_builddir)/t0 $(TIMEOUT_VAL) all: build-tests run-tests build-tests: $(BUILD_TESTS:.c=.test) run-tests: $(RUN_TESTS:.test=.run-test) functional-tests: functional-make functional-run stress-tests: stress-make stress-run tests-pretty: $(MAKE) all | column -t -s: CFLAGS = -g -O2 -Wall -Werror -D_POSIX_C_SOURCE=200112L # add -std=c99, -std=gnu99 if compiler supports it (gcc-2.95.3 does not). check_gcc = $(shell if $(CC) $(1) -S -o /dev/null -xc /dev/null > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi) CFLAGS += $(call check_gcc,-std=c99,) CFLAGS += $(call check_gcc,-std=gnu99,) INCLUDE = -Iinclude # FIXME: exaust cmd line length clean: @rm -f $(LOGFILE) # Timeout helper files @rm -f $(top_builddir)/t0{,.val} # Built runnable tests @find $(top_builddir) -iname \*.test | xargs -n 40 rm -f {} @find $(top_builddir) -iname \*~ -o -iname \*.o | xargs -n 40 rm -f {} @$(foreach DIR,$(FUNCTIONAL_MAKE),make -C $(DIR) clean >> /dev/null 2>&1;) >> /dev/null 2>&1 # Rule to run a build test # If the .o doesn't export main, then we don't need to link .PRECIOUS: %.test %.test: %.o @COMPLOG=$(LOGFILE).$$$$; \ [ -f $< ] || exit 0; \ { nm -g $< | grep -q " T main"; } || \ { echo "$(@:.test=): link: SKIP" | tee -a $(LOGFILE) && exit 0; }; \ if $(CC) $(CFLAGS) $< -o $@ $(LDFLAGS) > $$COMPLOG 2>&1; \ then \ echo "$(@:.test=): link: PASS" | tee -a $(LOGFILE); \ else \ ( \ echo "$(@:.test=): link: FAILED. Linker output: "; \ cat $$COMPLOG; \ ) >> $(LOGFILE); \ echo "$(@:.test=): link: FAILED "; \ fi; \ rm -f $$COMPLOG; # Rule to run an executable test # If it is only a build test, then the binary exist, so we don't need to run .PHONY: %.run-test %.run-test: %.test $(top_builddir)/t0 $(top_builddir)/t0.val @COMPLOG=$(LOGFILE).$$$$; \ [ -f $< ] || exit 0; \ $(TIMEOUT) $< > $$COMPLOG 2>&1; \ RESULT=$$?; \ if [ $$RESULT -eq 1 ]; \ then \ MSG="FAILED"; \ fi; \ if [ $$RESULT -eq 2 ]; \ then \ MSG="UNRESOLVED"; \ fi; \ if [ $$RESULT -eq 4 ]; \ then \ MSG="UNSUPPORTED"; \ fi; \ if [ $$RESULT -eq 5 ]; \ then \ MSG="UNTESTED"; \ fi; \ if [ $$RESULT -eq $(TIMEOUT_RET) ]; \ then \ MSG="HUNG"; \ fi; \ if [ $$RESULT -gt 5 -a $$RESULT -ne $(TIMEOUT_RET) ]; \ then \ MSG="INTERRUPTED"; \ fi; \ if [ $$RESULT -eq 0 ]; \ then \ echo "$(@:.run-test=): execution: PASS" | tee -a $(LOGFILE); \ else \ ( \ echo "$(@:.run-test=): execution: $$MSG: Output: "; \ cat $$COMPLOG; \ ) >> $(LOGFILE); \ echo "$(@:.run-test=): execution: $$MSG "; \ fi; \ rm -f $$COMPLOG; $(top_builddir)/t0: $(top_builddir)/t0.c @echo Building timeout helper files; \ $(CC) -O2 -o $@ $< $(top_builddir)/t0.val: $(top_builddir)/t0 echo `$(top_builddir)/t0 0; echo $$?` > $(top_builddir)/t0.val %.run-test: %.sh $(top_builddir)/t0 $(top_builddir)/t0.val @COMPLOG=$(LOGFILE).$$$$; \ chmod +x $<; \ $(TIMEOUT) $< > $$COMPLOG 2>&1; \ RESULT=$$?; \ if [ $$RESULT -eq 0 ]; \ then \ echo "$(@:.run-test=): execution: PASS" | tee -a $(LOGFILE);\ else \ ( \ echo "$(@:.run-test=): execution: FAILED: Output: ";\ cat $$COMPLOG; \ ) >> $(LOGFILE); \ echo "$(@:.run-test=): execution: FAILED "; \ fi; \ rm -f $$COMPLOG; .PRECIOUS: %.o %.o: %.c @COMPLOG=$(LOGFILE).$$$$; \ if $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@ $(LDFLAGS) > $$COMPLOG 2>&1; \ then \ echo "$(@:.o=): build: PASS" | tee -a $(LOGFILE); \ else \ ( \ echo "$(@:.o=): build: FAILED: Compiler output: "; \ cat $$COMPLOG; \ ) >> $(LOGFILE); \ echo "$(@:.o=): build: FAILED "; \ fi; \ rm -f $$COMPLOG; # Functional/Stress test build and execution functional-make: $(foreach DIR,$(FUNCTIONAL_MAKE),make -C $(DIR);) .PHONY: $(FUNCTIONAL_RUN) functional-run: $(FUNCTIONAL_RUN) $(FUNCTIONAL_RUN): cd $@; ./run.sh cd $(PWD) stress-make: $(foreach DIR,$(STRESS_MAKE),make -C $(DIR);) .PHONY: $(STRESS_RUN) stress-run: $(STRESS_RUN) $(STRESS_RUN): cd $@; ./run.sh cd $(PWD) posixtestsuite/locate-test0100755000000000000000000000646310336125315015053 0ustar rootroot#! /bin/sh # Copyright (c) 2002, Intel Corporation. All rights reserved. # Created by: inaky.perez-gonzalez REMOVE-THIS AT intel DOT com # This file is licensed under the GPL license. For the full content # of this license, see the COPYING file at the top level of this # source tree. # Added FreeBSD compatibility changes by Craig Rodrigues usage() { cat <&2; usage 1>&2; exit 1; ;; *) break 2; ;; esac done # Need the DIRECTORY arg ... if [ -z "$1" ] then echo "Error: no root directory specified" 1>&2 usage 1>&2; exit 1; fi # Simple version right now, just locate all: WHERE="$1" # Force something .c or .sh # Avoid .o, backups # IF --execs, force it has no "-buildonly" # If --buildable, remove the .sh files find "$WHERE" -type f \ \( \ \( -name "[0-9]*-*.c" -o -name "[0-9]*-[0-9]*.sh" \) \ ! -name \*.o ! -name \*~ \ \) \ $buildable $execs \ | if [ $print_execs -eq 1 ] then sed 's/\.\(sh\|c\)$/.test/' else cat fi posixtestsuite/AUTHORS0100644000000000000000000000055607577745177014001 0ustar rootrootgeoffrey.r.gustafson REMOVE-THIS AT intel DOT com inaky.perez-gonzalez REMOVE-THIS AT intel DOT com julie.n.fleischer REMOVE-THIS AT intel DOT com majid.awad REMOVE-THIS AT intel DOT com rolla.n.selbak REMOVE-THIS AT intel DOT com rusty.lynch REMOVE-THIS AT intel DOT com salwan.searty REMOVE-THIS AT intel DOT com sunyi REMOVE-THIS AT users DOT sourceforge DOT net posixtestsuite/conformance/0040755000000000000000000000000010515625156015174 5ustar rootrootposixtestsuite/conformance/definitions/0040755000000000000000000000000010515625156017507 5ustar rootrootposixtestsuite/conformance/definitions/unistd_h/0040755000000000000000000000000010515625156021324 5ustar rootrootposixtestsuite/conformance/definitions/unistd_h/1-1.c0100644000000000000000000000076607662736704022007 0ustar rootroot /* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * * Test that the function below is defined: * int fsync(int fildes); */ #include typedef int (*fsync_test)(int fildes); int dummyfcn (void) { fsync_test dummyvar; dummyvar = fsync; return 0; } posixtestsuite/conformance/definitions/unistd_h/assertions.xml0100644000000000000000000000045510167251605024236 0ustar rootroot The function below is defined: int fsync(int fildes); The function below is defined: int ftruncate(int fildes, off_t length); posixtestsuite/conformance/definitions/unistd_h/2-1.c0100644000000000000000000000110610167251605021757 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * * Based on original code by Julie N Fleischer. * * Test that the function below is defined: * int ftruncate(int fildes, off_t length); */ #include #include typedef int (*ftruncate_test)(int fildes, off_t length); int dummyfcn (void) { ftruncate_test dummyvar; dummyvar = ftruncate; return 0; } posixtestsuite/conformance/definitions/aio_h/0040755000000000000000000000000010515625153020563 5ustar rootrootposixtestsuite/conformance/definitions/aio_h/4-1.c0100644000000000000000000000140210247607106021222 0ustar rootroot/* * Copyright (c) 2004, Bull SA. All rights reserved. * Created by: Laurent.Vivier@bull.net * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ #include int (*dummy0)(int, struct aiocb *) = aio_cancel; int (*dummy1)(const struct aiocb *) = aio_error; int (*dummy2)(int, struct aiocb *) = aio_fsync; int (*dummy3)(struct aiocb *) = aio_read; ssize_t (*dummy4)(struct aiocb *) = aio_return; int (*dummy5)(const struct aiocb *const[], int, const struct timespec *) = aio_suspend; int (*dummy6)(struct aiocb *) = aio_write; int (*dummy7)(int, struct aiocb *const [], int, struct sigevent *restrict) = lio_listio; int main() { return 0; } posixtestsuite/conformance/definitions/aio_h/1-1.c0100644000000000000000000000050010247607106021215 0ustar rootroot/* * Copyright (c) 2004, Bull SA. All rights reserved. * Created by: Laurent.Vivier@bull.net * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* test if aio.h exists and can be included */ #include posixtestsuite/conformance/definitions/aio_h/1-2.c0100644000000000000000000000052710247607106021227 0ustar rootroot/* * Copyright (c) 2004, Bull SA. All rights reserved. * Created by: Laurent.Vivier@bull.net * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* test if struct aiocb is defined in */ #include struct aiocb dummy; posixtestsuite/conformance/definitions/aio_h/assertions.xml0100644000000000000000000000233210160256050023464 0ustar rootroot An AIO control block structure aiocb is used in many asynchronous I/O functions. It is defined in <aio.h> The AIO control block structure aiocb has following members: int aio_fildes off_t aio_offset volatile void* aio_buf size_t aio_nbytes int aio_reqprio struct sigevent aio_sigevent int aio_lio_opcode The header <aio.h> shakk include following constants: AIO_ALLDONE AIO_CANCELED AIO_NOTCANCELED LIO_NOP LIO_NOWAIT LIO_READ LIO_WAIT LIO_WRITE The header <aio.h> shall defines following functions or macros: int aio_cancel(int, struct aiocb *); int aio_error(const struct aiocb *); int aio_fsync(int, struct aiocb *); int aio_read(struct aiocb *); ssize_t aio_return(struct aiocb *); int aio_suspend(const struct aiocb *const[], int, const struct timespec *); int aio_write(struct aiocb *); int lio_listio(int, struct aiocb *restrict const[restrict], int, struct sigevent *restrict); posixtestsuite/conformance/definitions/aio_h/2-1.c0100644000000000000000000000103410247607106021221 0ustar rootroot/* * Copyright (c) 2004, Bull SA. All rights reserved. * Created by: Laurent.Vivier@bull.net * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* test if aio.h exists and can be included */ #include int main(void) { struct aiocb aiocb; struct sigevent sigevent; aiocb.aio_fildes = -1; aiocb.aio_offset = -1; aiocb.aio_buf = NULL; aiocb.aio_nbytes = 0; aiocb.aio_sigevent = sigevent; aiocb.aio_reqprio = -1; } posixtestsuite/conformance/definitions/aio_h/3-1.c0100644000000000000000000000101110247607106021215 0ustar rootroot/* * Copyright (c) 2004, Bull SA. All rights reserved. * Created by: Laurent.Vivier@bull.net * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* test if aio.h exists and can be included */ #include int dummy0 = AIO_ALLDONE; int dummy1 = AIO_CANCELED; int dummy2 = AIO_NOTCANCELED; int dummy3 = LIO_NOP; int dummy4 = LIO_NOWAIT; int dummy5 = LIO_READ; int dummy6 = LIO_WAIT; int dummy7 = LIO_WRITE; posixtestsuite/conformance/definitions/sys/0040755000000000000000000000000010515625155020324 5ustar rootrootposixtestsuite/conformance/definitions/sys/mman_h/0040755000000000000000000000000010515625155021563 5ustar rootrootposixtestsuite/conformance/definitions/sys/mman_h/2-4.c0100644000000000000000000000111007652173745022232 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that the header defines the PROT_NONE protection option. * * @pt:MF * @pt:SHM * @pt:ADV */ #include #ifndef PROT_NONE #error PROT_NONE not defined #endif posixtestsuite/conformance/definitions/sys/mman_h/2-2.c0100644000000000000000000000111307652173745022233 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that the header defines the PROT_WRITE protection option. * * @pt:MF * @pt:SHM * @pt:ADV */ #include #ifndef PROT_WRITE #error PROT_WRITE not defined #endif posixtestsuite/conformance/definitions/sys/mman_h/15-1.c0100644000000000000000000000121707652173745022323 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that the function: * int msync(void *, size_t, int) * is declared. * * @pt:MF * @pt:SIO */ #include typedef int (*msync_test)(void *, size_t, int); int dummyfcn (void) { msync_test dummyvar; dummyvar = msync; return 0; } posixtestsuite/conformance/definitions/sys/mman_h/17-1.c0100644000000000000000000000117207652173745022325 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that the function: * int munlockall(void) * is declared. * * @pt:ML */ #include typedef int (*munlockall_test)(void); int dummyfcn (void) { munlockall_test dummyvar; dummyvar = munlockall; return 0; } posixtestsuite/conformance/definitions/sys/mman_h/19-1.c0100644000000000000000000000124507652173745022330 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that the function: * int posix_madvise(void *, size_t, int) * is declared. * * @pt:ADV */ #include typedef int (*posix_madvise_test)(void *, size_t, int); int dummyfcn (void) { posix_madvise_test dummyvar; dummyvar = posix_madvise; return 0; } posixtestsuite/conformance/definitions/sys/mman_h/5-1.c0100644000000000000000000000111207652173745022234 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that the header defines the MCL_CURRENT symbolic constant for * mlockall(). * * @pt:ML */ #include #ifndef MCL_CURRENT #error MCL_CURRENT not defined #endif posixtestsuite/conformance/definitions/sys/mman_h/7-3.c0100644000000000000000000000113407652173745022244 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that the header defines the POSIX_MADV_RANDOM symbolic value. * * @pt:ADV * @pt:MF * @pt:SHM */ #include #ifndef POSIX_MADV_RANDOM #error POSIX_MADV_RANDOM not defined #endif posixtestsuite/conformance/definitions/sys/mman_h/24-1.c0100644000000000000000000000121307652173745022317 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that the function: * int shm_unlink(const char *) * is declared. * * @pt:SHM */ #include typedef int (*shm_unlink_test)(const char *); int dummyfcn (void) { shm_unlink_test dummyvar; dummyvar = shm_unlink; return 0; } posixtestsuite/conformance/definitions/sys/mman_h/4-1.c0100644000000000000000000000110007652173745022230 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that the header defines the MS_ASYNC flag option for msync(). * * @pt:MF * @pt:SIO */ #include #ifndef MS_ASYNC #error MS_ASYNC not defined #endif posixtestsuite/conformance/definitions/sys/mman_h/22-1.c0100644000000000000000000000130707652173745022321 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that the function: * int posix_typed_mem_open(const char *, int, int) * is declared. * * @pt:TYM */ #include typedef int (*posix_typed_mem_open_test)(const char *, int, int); int dummyfcn (void) { posix_typed_mem_open_test dummyvar; dummyvar = posix_typed_mem_open; return 0; } posixtestsuite/conformance/definitions/sys/mman_h/14-1.c0100644000000000000000000000122107652173745022315 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that the function: * int mprotect(void *, size_t, int) * is declared. * * @pt:MPR */ #include typedef int (*mprotect_test)(void *, size_t, int); int dummyfcn (void) { mprotect_test dummyvar; dummyvar = mprotect; return 0; } posixtestsuite/conformance/definitions/sys/mman_h/5-2.c0100644000000000000000000000110607652173745022240 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that the header defines the MCL_FUTURE symbolic constant for * mlockall(). * * @pt:ML */ #include #ifndef MCL_FUTURE #error MCL_FUTURE not defined #endif posixtestsuite/conformance/definitions/sys/mman_h/18-1.c0100644000000000000000000000122407652173745022324 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that the function: * int munmap(void *, size_t) * is declared. * * @pt:MF * @pt:SHM * @pt:TYM */ #include typedef int (*munmap_test)(void *, size_t); int dummyfcn (void) { munmap_test dummyvar; dummyvar = munmap; return 0; } posixtestsuite/conformance/definitions/sys/mman_h/12-1.c0100644000000000000000000000116007652173745022315 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that the function: * int mlockall(int) * is declared. * * @pt:ML */ #include typedef int (*mlockall_test)(int); int dummyfcn (void) { mlockall_test dummyvar; dummyvar = mlockall; return 0; } posixtestsuite/conformance/definitions/sys/mman_h/1-1.c0100644000000000000000000000160307652173744022234 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that the sys/mman.h header file exists when the implementation supports * at least one of the following options: * MF * SHM * ML * MPR * TYM * SIO * ADV */ #include #if defined(_POSIX_ADVISORY_INFO) || defined(_POSIX_MAPPED_FILES) || \ defined(_POSIX_MEMLOCK) || defined(_POSIX_MEMORY_PROTECTION) || \ defined(_POSIX_SHARED_MEMORY_OBJECTS) || \ defined(_POSIX_SYNCHRONIZED_IO) || defined(_POSIX_TYPED_MEMORY_OBJECTS) #include #endif posixtestsuite/conformance/definitions/sys/mman_h/9-1.c0100644000000000000000000000101507652173745022242 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that mode_t type is defined as described in sys/types.h. */ #include mode_t this_type_should_exist; posixtestsuite/conformance/definitions/sys/mman_h/20-1.c0100644000000000000000000000152107652173745022315 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that the function: * int posix_mem_offset(const void *restrict, size_t, off_t *restrict, * size_t *restrict, int *restrict) * is declared. * * @pt:TYM */ #include typedef int (*posix_mem_offset_test)(const void *restrict, size_t, off_t *restrict, size_t *restrict, int *restrict); int dummyfcn (void) { posix_mem_offset_test dummyvar; dummyvar = posix_mem_offset; return 0; } posixtestsuite/conformance/definitions/sys/mman_h/11-1.c0100644000000000000000000000120607652173745022315 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that the function: * int mlock(const void *, size_t) * is declared. * * @pt:MR */ #include typedef int (*mlock_test)(const void *, size_t); int dummyfcn (void) { mlock_test dummyvar; dummyvar = mlock; return 0; } posixtestsuite/conformance/definitions/sys/mman_h/8-3.c0100644000000000000000000000121007652173745022240 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that the header defines the POSIX_TYPED_MEM_MAP_ALLOCATABLE flag for * posix_typed_mem_open()(). * * @pt:TYM */ #include #ifndef POSIX_TYPED_MEM_MAP_ALLOCATABLE #error POSIX_TYPED_MEM_MAP_ALLOCATABLE not defined #endif posixtestsuite/conformance/definitions/sys/mman_h/23-1.c0100644000000000000000000000123507652173745022322 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that the function: * int shm_open(const char *, int, mode_t) * is declared. * * @pt:SHM */ #include typedef int (*shm_open_test)(const char *, int, mode_t); int dummyfcn (void) { shm_open_test dummyvar; dummyvar = shm_open; return 0; } posixtestsuite/conformance/definitions/sys/mman_h/6-1.c0100644000000000000000000000107707652173745022247 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that the header defines the MAP_FAILED symbolic constant. * * @pt:MF * @pt:SHM */ #include #ifndef MAP_FAILED #error MAP_FAILED not defined #endif posixtestsuite/conformance/definitions/sys/mman_h/4-3.c0100644000000000000000000000111707652173745022242 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that the header defines the MS_INVALIDATE flag option for msync(). * * @pt:MF * @pt:SIO */ #include #ifndef MS_INVALIDATE #error MS_INVALIDATE not defined #endif posixtestsuite/conformance/definitions/sys/mman_h/10-1.c0100644000000000000000000000130107652173745022310 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that the header declares struct posix_typed_mem_info with at least the * following member: * size_t posix_tmi_length * * @pt:TYM */ #include struct posix_typed_mem_info this_type_should_exist, t; int dummyfcn(void) { size_t sz = 0; t.posix_tmi_length = sz; return 0; } posixtestsuite/conformance/definitions/sys/mman_h/13-1.c0100644000000000000000000000127407652173745022324 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that the function: * void *mmap(void *, size_t, int, int, int, off_t) * is declared. * * @pt:MF * @pt:SHM * @pt:TYM */ #include typedef void* (*mmap_test)(void *, size_t, int, int, int, off_t); int dummyfcn (void) { mmap_test dummyvar; dummyvar = mmap; return 0; } posixtestsuite/conformance/definitions/sys/mman_h/8-2.c0100644000000000000000000000121007652173745022237 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that the header defines the POSIX_TYPED_MEM_ALLOCATE_CONTIG flag for * posix_typed_mem_open()(). * * @pt:TYM */ #include #ifndef POSIX_TYPED_MEM_ALLOCATE_CONTIG #error POSIX_TYPED_MEM_ALLOCATE_CONTIG not defined #endif posixtestsuite/conformance/definitions/sys/mman_h/3-2.c0100644000000000000000000000107507652173745022243 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that the header defines the MAP_PRIVATE flag option. * * @pt:MF * @pt:SHM */ #include #ifndef MAP_PRIVATE #error MAP_PRIVATE not defined #endif posixtestsuite/conformance/definitions/sys/mman_h/7-4.c0100644000000000000000000000114207652173745022244 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that the header defines the POSIX_MADV_WILLNEED symbolic value. * * @pt:ADV * @pt:MF * @pt:SHM */ #include #ifndef POSIX_MADV_WILLNEED #error POSIX_MADV_WILLNEED not defined #endif posixtestsuite/conformance/definitions/sys/mman_h/7-1.c0100644000000000000000000000113407652173745022242 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that the header defines the POSIX_MADV_NORMAL symbolic value. * * @pt:ADV * @pt:MF * @pt:SHM */ #include #ifndef POSIX_MADV_NORMAL #error POSIX_MADV_NORMAL not defined #endif posixtestsuite/conformance/definitions/sys/mman_h/assertions.xml0100644000000000000000000001060610504452010024461 0ustar rootroot The sys/mman.h header file exists if the implementation supports at least one of the following options: MF SHM ML MPR TYM SIO ADV The header defines the following protection options: PROT_READ PROT_WRITE PROT_EXEC PROT_NONE The header defines the following flag options: MAP_SHARED MAP_PRIVATE MAP_FIXED The header defines the following flag options for msync(): MS_ASYNC MS_SYNC MS_INVALIDATE The header defines the following flag options for mlockall(): MCL_CURRENT MCL_FUTURE The header defines the following symbolic constant: MAP_FAILED The header defines the following symbolic values: POSIX_MADV_NORMAL POSIX_MADV_SEQUENTIAL POSIX_MADV_RANDOM POSIX_MADV_WILLNEED POSIX_MADV_DONTNEED The header defines the following flags for posix_typed_mem_open(): POSIX_TYPED_MEM_ALLOCATE POSIX_TYPED_MEM_ALLOCATE_CONTIG POSIX_TYPED_MEM_MAP_ALLOCATABLE The mode_t, off_t, and size_t types shall be defined as described in sys/types.h The sys/mman.h header shall define the structure posix_typed_mem_info, which includes at least the following member: size_t posix_tmi_length This function is defined: int mlock(const void *, size_t) This function is defined: int mlockall(int) This function is defined: void *mmap(void *, size_t, int, int, int, off_t) This function is defined: int mprotect(void *, size_t, int) This function is defined: int msync(void *, size_t, int) This function is defined: int munlock(const void *, size_t) This function is defined: int munlockall(void) This function is defined: int munmap(void *, size_t) This function is defined: int posix_madvise(void *, size_t, int) This function is defined: int posix_mem_offset(const void *restrict, size_t, off_t *restrict, size_t *restrict, int *restrict) This function is defined: int posix_typed_mem_get_info(int, struct posix_typed_mem_info *) This function is defined: int posix_typed_mem_open(const char *, int, int) This function is defined: int shm_open(const char *, int, mode_t) This function is defined: int shm_unlink(const char *) posixtestsuite/conformance/definitions/sys/mman_h/21-1.c0100644000000000000000000000135707652173745022325 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that the function: * int posix_typed_mem_get_info(int, struct posix_typed_mem_info *) * is declared. * * @pt:TYM */ #include typedef int (*posix_typed_mem_get_info_test)(int, struct posix_typed_mem_info *); int dummyfcn (void) { posix_typed_mem_get_info_test dummyvar; dummyvar = posix_typed_mem_get_info; return 0; } posixtestsuite/conformance/definitions/sys/mman_h/coverage.txt0100644000000000000000000000077207652173745024135 0ustar rootroot This document explains why certain assertions were not tested. Assertions not listed here should be covered by the tests in this directory. Assertions Tested ? Remarks 1 YES 2 YES 3 YES 4 YES 5 YES 6 YES 7 YES 8 YES 9 YES 10 YES 11 YES 12 YES 13 YES 14 YES 15 YES 16 YES 17 YES 18 YES 19 YES 20 YES 21 YES 22 YES 23 YES 24 YES posixtestsuite/conformance/definitions/sys/mman_h/3-3.c0100644000000000000000000000106707652173745022245 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that the header defines the MAP_FIXED flag option. * * @pt:MF * @pt:SHM */ #include #ifndef MAP_FIXED #error MAP_FIXED not defined #endif posixtestsuite/conformance/definitions/sys/mman_h/9-3.c0100644000000000000000000000101507652173745022244 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that size_t type is defined as described in sys/types.h. */ #include size_t this_type_should_exist; posixtestsuite/conformance/definitions/sys/mman_h/8-1.c0100644000000000000000000000116307652173745022245 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that the header defines the POSIX_TYPED_MEM_ALLOCATE flag for * posix_typed_mem_open()(). * * @pt:TYM */ #include #ifndef POSIX_TYPED_MEM_ALLOCATE #error POSIX_TYPED_MEM_ALLOCATE not defined #endif posixtestsuite/conformance/definitions/sys/mman_h/7-5.c0100644000000000000000000000114207652173745022245 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that the header defines the POSIX_MADV_DONTNEED symbolic value. * * @pt:ADV * @pt:MF * @pt:SHM */ #include #ifndef POSIX_MADV_DONTNEED #error POSIX_MADV_DONTNEED not defined #endif posixtestsuite/conformance/definitions/sys/mman_h/7-2.c0100644000000000000000000000115007652173745022241 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that the header defines the POSIX_MADV_SEQUENTIAL symbolic value. * * @pt:ADV * @pt:MF * @pt:SHM */ #include #ifndef POSIX_MADV_SEQUENTIAL #error POSIX_MADV_SEQUENTIAL not defined #endif posixtestsuite/conformance/definitions/sys/mman_h/4-2.c0100644000000000000000000000107507652173745022244 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that the header defines the MS_SYNC flag option for msync(). * * @pt:MF * @pt:SIO */ #include #ifndef MS_SYNC #error MS_SYNC not defined #endif posixtestsuite/conformance/definitions/sys/mman_h/16-1.c0100644000000000000000000000121607652173745022323 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that the function: * int munlock(const void *, size_t) * is declared. * * @pt:MR */ #include typedef int (*munlock_test)(const void *, size_t); int dummyfcn (void) { munlock_test dummyvar; dummyvar = munlock; return 0; } posixtestsuite/conformance/definitions/sys/mman_h/2-3.c0100644000000000000000000000111007652173745022231 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that the header defines the PROT_EXEC protection option. * * @pt:MF * @pt:SHM * @pt:ADV */ #include #ifndef PROT_EXEC #error PROT_EXEC not defined #endif posixtestsuite/conformance/definitions/sys/mman_h/2-1.c0100644000000000000000000000111107652173745022230 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that the header defines the PROT_READ protection option. * * @pt:MF * @pt:SHM * @pt:ADV */ #include #ifndef PROT_READ #error PROT_READ not defined #endif posixtestsuite/conformance/definitions/sys/mman_h/3-1.c0100644000000000000000000000107207652173745022237 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that the header defines the MAP_SHARED flag option. * * @pt:MF * @pt:SHM */ #include #ifndef MAP_SHARED #error MAP_SHARED not defined #endif posixtestsuite/conformance/definitions/sys/mman_h/9-2.c0100644000000000000000000000101307652173745022241 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that off_t type is defined as described in sys/types.h. */ #include off_t this_type_should_exist; posixtestsuite/conformance/definitions/sys/shm_h/0040755000000000000000000000000010515625156021423 5ustar rootrootposixtestsuite/conformance/definitions/sys/shm_h/2-2.c0100644000000000000000000000103407652174054022066 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that the header define the SHM_RND symbolic constant. */ #include #ifndef SHM_RND #error SHM_RND not defined #endif posixtestsuite/conformance/definitions/sys/shm_h/5-1.c0100644000000000000000000000134107652174054022071 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that the shmatt_t type is an unsigned integer that must be able to * store values at least as large than unsigned short. */ #include #include /* The minimun acceptable value for USHRT_MAX */ #define MIN_USHRT_MAX 65535 shmatt_t tmin = 0; shmatt_t tmax = USHRT_MAX; shmatt_t tminmax = MIN_USHRT_MAX; posixtestsuite/conformance/definitions/sys/shm_h/12-3.c0100644000000000000000000000120207652174054022145 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that the function: * key_t ftok(const char *, int) * from sys/ipc.h is declared. */ #include typedef key_t (*ftok_test)(const char *, int); int dummyfcn (void) { ftok_test dummyvar; dummyvar = ftok; return 0; } posixtestsuite/conformance/definitions/sys/shm_h/7-3.c0100644000000000000000000000101207652174054022070 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that key_t type is defined as described in sys/types.h. */ #include key_t this_type_should_exist; posixtestsuite/conformance/definitions/sys/shm_h/12-2.c0100644000000000000000000000102107652174054022143 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that the stuct ipc_perm from sys/ipc.h is defined. */ #include struct ipc_perm this_type_should_exist; posixtestsuite/conformance/definitions/sys/shm_h/4-1.c0100644000000000000000000000101707652174054022070 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that the header define the shmatt_t type through typedef. */ #include shmatt_t this_type_should_exist; posixtestsuite/conformance/definitions/sys/shm_h/12-1.c0100644000000000000000000000174007652174053022151 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that all of the folowing symbolic constants from sys/ipc.h are defined: * IPC_CREAT * IPC_EXCL * IPC_NOWAIT * IPC_PRIVATE * IPC_RMID * IPC_SET * IPC_STAT */ #include #ifndef IPC_CREAT #error IPC_CREAT not defined #endif #ifndef IPC_EXCL #error IPC_EXCL not defined #endif #ifndef IPC_NOWAIT #error IPC_NOWAIT not defined #endif #ifndef IPC_PRIVATE #error IPC_PRIVATE not defined #endif #ifndef IPC_RMID #error IPC_RMID not defined #endif #ifndef IPC_SET #error IPC_SET not defined #endif #ifndef IPC_STAT #error IPC_STAT not defined #endif posixtestsuite/conformance/definitions/sys/shm_h/1-1.c0100644000000000000000000000073207652174047022072 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that the sys/shm.h header file exists. */ #include posixtestsuite/conformance/definitions/sys/shm_h/9-1.c0100644000000000000000000000121207652174054022072 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that the function: * int shmctl(int, int, struct shmid_ds *) * is declared. */ #include typedef int (*shmctl_test)(int, int, struct shmid_ds *); int dummyfcn (void) { shmctl_test dummyvar; dummyvar = shmctl; return 0; } posixtestsuite/conformance/definitions/sys/shm_h/11-1.c0100644000000000000000000000117007652174051022143 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that the function: * int shmget(key_t, size_t, int) * is declared. */ #include typedef int (*shmget_test)(key_t, size_t, int); int dummyfcn (void) { shmget_test dummyvar; dummyvar = shmget; return 0; } posixtestsuite/conformance/definitions/sys/shm_h/6-1.c0100644000000000000000000000206310504726520022063 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that the header declares struct shmid_ds with the members below, at a * minimum: * struct ipc_perm shm_perm * size_t shm_segsz * pid_t shm_lpid * pid_t shm_cpid * shmatt_t shm_nattch * time_t shm_atime * time_t shm_dtime * time_t shm_ctime */ #include struct shmid_ds this_type_should_exist, t; int dummyfcn(void) { struct ipc_perm perm = {0}; size_t sz = 0; pid_t lpid = 0, cpid = 0; shmatt_t nattch = 0; time_t atime = 0, dtime = 0, ctime = 0; t.shm_perm = perm; t.shm_segsz = sz; t.shm_lpid = lpid; t.shm_cpid = cpid; t.shm_nattch = nattch; t.shm_atime = atime; t.shm_dtime = dtime; t.shm_ctime = ctime; return 0; } posixtestsuite/conformance/definitions/sys/shm_h/10-1.c0100644000000000000000000000115007652174051022140 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that the function: * int shmdt(const void *) * is declared. */ #include typedef int (*shmdt_test)(const void *); int dummyfcn (void) { shmdt_test dummyvar; dummyvar = shmdt; return 0; } posixtestsuite/conformance/definitions/sys/shm_h/7-4.c0100644000000000000000000000101407652174054022073 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that size_t type is defined as described in sys/types.h. */ #include size_t this_type_should_exist; posixtestsuite/conformance/definitions/sys/shm_h/7-1.c0100644000000000000000000000101207652174054022066 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that pid_t type is defined as described in sys/types.h. */ #include pid_t this_type_should_exist; posixtestsuite/conformance/definitions/sys/shm_h/assertions.xml0100644000000000000000000000404610504452010024321 0ustar rootroot The sys/shm.h header file exists The header define the following symbolic constants: - SHM_RDONLY - SHM_RND The header define the following symbolic value: - SHMLBA The header define the following type through typedef: - shmatt_t The shmatt_t type is an unsigned integer that must be able to store values at least as large than unsigned short. The header declares struct shmid_ds with the members below, at a minimum: struct ipc_perm shm_perm size_t shm_segsz pid_t shm_lpid pid_t shm_cpid shmatt_t shm_nattach time_t shm_atime time_t shm_dtime time_t shm_ctime The pid_t, time_t, key_t, and size_t types shall be defined as described in sys/types.h This function is defined: void *shmat(int, const void *, int) This function is defined: int shmctl(int, int, struct shmid_ds *) This function is defined: int shmdt(const void *) This function is defined: int shmget(key_t, size_t, int) All of the symbols from sys/ipc.h are defined when the sys/shm.h header is included posixtestsuite/conformance/definitions/sys/shm_h/coverage.txt0100644000000000000000000000052307652174054023760 0ustar rootroot This document explains why certain assertions were not tested. Assertions not listed here should be covered by the tests in this directory. Assertions Tested ? Remarks 1 YES 2 YES 3 YES 4 YES 5 YES 6 YES 7 YES 8 YES 9 YES 10 YES 11 YES 12 YES posixtestsuite/conformance/definitions/sys/shm_h/8-1.c0100644000000000000000000000120007652174054022066 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that the function: * void *shmat(int, const void *, int) * is declared. */ #include typedef void* (*shmat_test)(int, const void *, int); int dummyfcn (void) { shmat_test dummyvar; dummyvar = shmat; return 0; } posixtestsuite/conformance/definitions/sys/shm_h/7-2.c0100644000000000000000000000101407652174054022071 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that time_t type is defined as described in sys/types.h. */ #include time_t this_type_should_exist; posixtestsuite/conformance/definitions/sys/shm_h/2-1.c0100644000000000000000000000104507652174054022067 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that the header define the SHM_RDONLY symbolic constant. */ #include #ifndef SHM_RDONLY #error SHM_RDONLY not defined #endif posixtestsuite/conformance/definitions/sys/shm_h/3-1.c0100644000000000000000000000102607652174054022067 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that the header define the SHMLBA symbolic value. */ #include #ifndef SHMLBA #error SHMLBA not defined #endif posixtestsuite/conformance/definitions/signal_h/0040755000000000000000000000000010515625155021272 5ustar rootrootposixtestsuite/conformance/definitions/signal_h/22-11.c0100644000000000000000000000020507555627117022104 0ustar rootroot /* Test that the FPE_FLTDIV macro is defined. */ #include #ifndef FPE_FLTDIV #error FPE_FLTDIV not defined #endif posixtestsuite/conformance/definitions/signal_h/22-40.c0100644000000000000000000000017707555627117022116 0ustar rootroot /* Test that the SI_MESGQ macro is defined. */ #include #ifndef SI_MESGQ #error SI_MESGQ not defined #endif posixtestsuite/conformance/definitions/signal_h/2-4.c0100644000000000000000000000014107552722520021732 0ustar rootroot /* Test the definition of SIG_IGN. */ #include void (*dummy) (int) = SIG_IGN; posixtestsuite/conformance/definitions/signal_h/37-1.c0100644000000000000000000000035707556056717022044 0ustar rootroot /* Test that the function: int siginterrupt(int, int); is declared. */ #include typedef int (*siginterrupt_test)(int, int); int dummyfcn (void) { siginterrupt_test dummyvar; dummyvar = siginterrupt; return 0; } posixtestsuite/conformance/definitions/signal_h/33-1.c0100644000000000000000000000035707556056716022037 0ustar rootroot /* Test that the function: int sigemptyset(sigset_t *); is declared. */ #include typedef int (*sigemptyset_test)(sigset_t *); int dummyfcn (void) { sigemptyset_test dummyvar; dummyvar = sigemptyset; return 0; } posixtestsuite/conformance/definitions/signal_h/2-2.c0100644000000000000000000000014107552722520021730 0ustar rootroot /* Test the definition of SIG_ERR. */ #include void (*dummy) (int) = SIG_ERR; posixtestsuite/conformance/definitions/signal_h/22-2.c0100644000000000000000000000020507555627117022024 0ustar rootroot /* Test that the ILL_ILLOPN macro is defined. */ #include #ifndef ILL_ILLOPN #error ILL_ILLOPN not defined #endif posixtestsuite/conformance/definitions/signal_h/22-3.c0100644000000000000000000000020507555627117022025 0ustar rootroot /* Test that the ILL_ILLADR macro is defined. */ #include #ifndef ILL_ILLADR #error ILL_ILLADR not defined #endif posixtestsuite/conformance/definitions/signal_h/15-1.c0100644000000000000000000000056407555624640022033 0ustar rootroot /* Test the definition of sigaction. */ #include struct sigaction this_type_should_exist, t; extern void signal_handler (int); sigset_t *set; int flags; extern void signal_action(int, siginfo_t *, void *); int dummyfcn (void) { t.sa_handler = signal_handler; set = &t.sa_mask; flags = t.sa_flags; t.sa_sigaction = signal_action; return 0; } posixtestsuite/conformance/definitions/signal_h/17-1.c0100644000000000000000000000013107555624640022023 0ustar rootroot /* Test the definition of ucontext_t. */ #include ucontext_t dummy; posixtestsuite/conformance/definitions/signal_h/19-1.c0100644000000000000000000000034310053067720022015 0ustar rootroot /* Test the definition of stack_t. */ #include stack_t this_type_should_exist, t; void *sp; size_t size; int flags; int dummyfcn (void) { sp = t.ss_sp; size = t.ss_size; flags = t.ss_flags; return 0; } posixtestsuite/conformance/definitions/signal_h/5-1.c0100644000000000000000000000012007555571235021737 0ustar rootroot /* Test the definition of pid_t. */ #include pid_t dummy; posixtestsuite/conformance/definitions/signal_h/34-1.c0100644000000000000000000000035307556056716022034 0ustar rootroot /* Test that the function: int sigfillset(sigset_t *); is declared. */ #include typedef int (*sigfillset_test)(sigset_t *); int dummyfcn (void) { sigfillset_test dummyvar; dummyvar = sigfillset; return 0; } posixtestsuite/conformance/definitions/signal_h/45-1.c0100644000000000000000000000037507557606350022036 0ustar rootroot /* Test that the function: void (*sigset(int, void (*)(int)))(int); is declared. */ #include typedef void (*(*sigset_test)(int, void (*)(int)))(int); int dummyfcn (void) { sigset_test dummyvar; dummyvar = sigset; return 0; } posixtestsuite/conformance/definitions/signal_h/30-1.c0100644000000000000000000000036107556056716022027 0ustar rootroot /* Test that the function: int sigaddset(sigset_t *, int); is declared. */ #include typedef int (*sigaddset_test)(sigset_t *, int); int dummyfcn (void) { sigaddset_test dummyvar; dummyvar = sigaddset; return 0; } posixtestsuite/conformance/definitions/signal_h/22-7.c0100644000000000000000000000020507555627117022031 0ustar rootroot /* Test that the ILL_COPROC macro is defined. */ #include #ifndef ILL_COPROC #error ILL_COPROC not defined #endif posixtestsuite/conformance/definitions/signal_h/22-6.c0100644000000000000000000000020507555627117022030 0ustar rootroot /* Test that the ILL_PRVREG macro is defined. */ #include #ifndef ILL_PRVREG #error ILL_PRVREG not defined #endif posixtestsuite/conformance/definitions/signal_h/50-1.c0100644000000000000000000000030107556060605022013 0ustar rootroot /* Test that inclusion of signal.h makes visible all symbols in time.h. NOTE - THIS TEST CASE IS NOT COMPLETE. NEEDS TO GROW MUCH LARGER. */ #include struct tm *mytime; posixtestsuite/conformance/definitions/signal_h/24-1.c0100644000000000000000000000035207556056716022032 0ustar rootroot /* Test that the function: int kill(pid_t, int); is declared. */ #include #include typedef int (*kill_test)(pid_t, int); int dummyfcn (void) { kill_test dummyvar; dummyvar = kill; return 0; } posixtestsuite/conformance/definitions/signal_h/4-1.c0100644000000000000000000000012307555571235021741 0ustar rootroot /* Test the definition of sigset_t. */ #include sigset_t dummy; posixtestsuite/conformance/definitions/signal_h/22-23.c0100644000000000000000000000020507555627117022107 0ustar rootroot /* Test that the TRAP_TRACE macro is defined. */ #include #ifndef TRAP_TRACE #error TRAP_TRACE not defined #endif posixtestsuite/conformance/definitions/signal_h/22-39.c0100644000000000000000000000020507555627117022116 0ustar rootroot /* Test that the SI_ASYNCIO macro is defined. */ #include #ifndef SI_ASYNCIO #error SI_ASYNCIO not defined #endif posixtestsuite/conformance/definitions/signal_h/22-1.c0100644000000000000000000000020507555627117022023 0ustar rootroot /* Test that the ILL_ILLOPC macro is defined. */ #include #ifndef ILL_ILLOPC #error ILL_ILLOPC not defined #endif posixtestsuite/conformance/definitions/signal_h/22-38.c0100644000000000000000000000017707555627117022125 0ustar rootroot /* Test that the SI_TIMER macro is defined. */ #include #ifndef SI_TIMER #error SI_TIMER not defined #endif posixtestsuite/conformance/definitions/signal_h/22-18.c0100644000000000000000000000021007555627117022107 0ustar rootroot /* Test that the SEGV_ACCERR macro is defined. */ #include #ifndef SEGV_ACCERR #error SEGV_ACCERR not defined #endif posixtestsuite/conformance/definitions/signal_h/14-1.c0100644000000000000000000000130307555571235022023 0ustar rootroot /* Test that the signals below are supported. */ #include int dummy1 = SIGABRT; int dummy2 = SIGALRM; int dummy3 = SIGBUS; int dummy4 = SIGCHLD; int dummy5 = SIGCONT; int dummy6 = SIGFPE; int dummy7 = SIGHUP; int dummy8 = SIGILL; int dummy9 = SIGINT; int dummy10 = SIGKILL; int dummy11 = SIGPIPE; int dummy12 = SIGQUIT; int dummy13 = SIGSEGV; int dummy14 = SIGSTOP; int dummy15 = SIGTERM; int dummy16 = SIGTSTP; int dummy17 = SIGTTIN; int dummy18 = SIGTTOU; int dummy19 = SIGUSR1; int dummy20 = SIGUSR2; int dummy21 = SIGPOLL; int dummy22 = SIGPROF; int dummy23 = SIGSYS; int dummy24 = SIGTRAP; int dummy25 = SIGURG; int dummy26 = SIGVTALRM; int dummy27 = SIGXCPU; int dummy28 = SIGXFSZ; posixtestsuite/conformance/definitions/signal_h/22-30.c0100644000000000000000000000017407555627117022112 0ustar rootroot /* Test that the POLL_IN macro is defined. */ #include #ifndef POLL_IN #error POLL_IN not defined #endif posixtestsuite/conformance/definitions/signal_h/18-1.c0100644000000000000000000000013110053067720022007 0ustar rootroot /* Test the definition of ucontext_t. */ #include ucontext_t dummy; posixtestsuite/conformance/definitions/signal_h/make22tests0100755000000000000000000000102707555627164023375 0ustar rootroot#!/bin/sh # Make the tests for assertion 22. # Not named *.sh because then it would be executed during build time. declare -i i i=1 for sigmacro in `cat sigmacrolist.txt` do echo " /*" >> 22-$i.c 2>&1 echo " Test that the $sigmacro macro is defined." >> 22-$i.c 2>&1 echo " */" >> 22-$i.c 2>&1 echo "" >> 22-$i.c 2>&1 echo "#include " >> 22-$i.c 2>&1 echo "" >> 22-$i.c 2>&1 echo "#ifndef $sigmacro" >> 22-$i.c 2>&1 echo "#error $sigmacro not defined" >> 22-$i.c 2>&1 echo "#endif" >> 22-$i.c 2>&1 i=$i+1 done posixtestsuite/conformance/definitions/signal_h/22-15.c0100644000000000000000000000020507555627117022110 0ustar rootroot /* Test that the FPE_FLTINV macro is defined. */ #include #ifndef FPE_FLTINV #error FPE_FLTINV not defined #endif posixtestsuite/conformance/definitions/signal_h/42-1.c0100644000000000000000000000052607557606350022031 0ustar rootroot /* Test that the function: int sigprocmask(int, const sigset_t *restrict, sigset_t *restrict); is declared. Removed restrict keyword from typedef. */ #include typedef int (*sigprocmask_test)(int, const sigset_t *, sigset_t *); int dummyfcn (void) { sigprocmask_test dummyvar; dummyvar = sigprocmask; return 0; } posixtestsuite/conformance/definitions/signal_h/1-1.c0100644000000000000000000000015007552722520021726 0ustar rootroot /* Test the existence of the signal.h file and that it can be included. */ #include posixtestsuite/conformance/definitions/signal_h/20-1.c0100644000000000000000000000032210350313751022000 0ustar rootroot /* Test the definition of sigstack. */ #include struct sigstack this_type_should_exist, t; int onstack; void *sp; int dummyfcn (void) { sp = t.ss_sp; onstack = t.ss_onstack; return 0; } posixtestsuite/conformance/definitions/signal_h/22-32.c0100644000000000000000000000017707555627117022117 0ustar rootroot /* Test that the POLL_MSG macro is defined. */ #include #ifndef POLL_MSG #error POLL_MSG not defined #endif posixtestsuite/conformance/definitions/signal_h/22-25.c0100644000000000000000000000020507555627117022111 0ustar rootroot /* Test that the CLD_KILLED macro is defined. */ #include #ifndef CLD_KILLED #error CLD_KILLED not defined #endif posixtestsuite/conformance/definitions/signal_h/22-31.c0100644000000000000000000000017707555627117022116 0ustar rootroot /* Test that the POLL_OUT macro is defined. */ #include #ifndef POLL_OUT #error POLL_OUT not defined #endif posixtestsuite/conformance/definitions/signal_h/48-1.c0100644000000000000000000000043107556060605022026 0ustar rootroot /* Test that the function: int sigwait(const sigset_t *restrict, int *restrict); is declared. */ #include typedef int (*sigwait_test)(const sigset_t *restrict, int *restrict); int dummyfcn (void) { sigwait_test dummyvar; dummyvar = sigwait; return 0; } posixtestsuite/conformance/definitions/signal_h/22-13.c0100644000000000000000000000020507555627117022106 0ustar rootroot /* Test that the FPE_FLTUND macro is defined. */ #include #ifndef FPE_FLTUND #error FPE_FLTUND not defined #endif posixtestsuite/conformance/definitions/signal_h/22-26.c0100644000000000000000000000020507555627117022112 0ustar rootroot /* Test that the CLD_DUMPED macro is defined. */ #include #ifndef CLD_DUMPED #error CLD_DUMPED not defined #endif posixtestsuite/conformance/definitions/signal_h/44-1.c0100644000000000000000000000032507556056717022035 0ustar rootroot /* Test that the function: int sigrelse(int); is declared. */ #include typedef int (*sigrelse_test)(int); int dummyfcn (void) { sigrelse_test dummyvar; dummyvar = sigrelse; return 0; } posixtestsuite/conformance/definitions/signal_h/22-33.c0100644000000000000000000000017707555627117022120 0ustar rootroot /* Test that the POLL_ERR macro is defined. */ #include #ifndef POLL_ERR #error POLL_ERR not defined #endif posixtestsuite/conformance/definitions/signal_h/49-1.c0100644000000000000000000000046507557317454022046 0ustar rootroot /* Test that the function: int sigwaitinfo(const sigset_t *restrict, siginfo_t *restrict); is declared. */ #include typedef int (*sigwaitinfo_test)(const sigset_t *restrict, siginfo_t *restrict); int dummyfcn (void) { sigwaitinfo_test dummyvar; dummyvar = sigwaitinfo; return 0; } posixtestsuite/conformance/definitions/signal_h/46-1.c0100644000000000000000000000036707556056717022045 0ustar rootroot /* Test that the function: int sigsuspend(const sigset_t *); is declared. */ #include typedef int (*sigsuspend_test)(const sigset_t *); int dummyfcn (void) { sigsuspend_test dummyvar; dummyvar = sigsuspend; return 0; } posixtestsuite/conformance/definitions/signal_h/29-1.c0100644000000000000000000000056107557606350022035 0ustar rootroot /* Test that the function: int sigaction(int, const struct sigaction *restrict, struct sigaction *restrict); is declared. Removed restrict keyword from typedef. */ #include typedef int (*sigaction_test)(int, const struct sigaction *, struct sigaction *); int dummyfcn (void) { sigaction_test dummyvar; dummyvar = sigaction; return 0; } posixtestsuite/conformance/definitions/signal_h/22-37.c0100644000000000000000000000017707555627117022124 0ustar rootroot /* Test that the SI_QUEUE macro is defined. */ #include #ifndef SI_QUEUE #error SI_QUEUE not defined #endif posixtestsuite/conformance/definitions/signal_h/23-1.c0100644000000000000000000000042507557606350022026 0ustar rootroot /* @pt:XSI Test that the function: void (*bsd_signal(int, void (*)(int)))(int); is declared. */ #include typedef void (*(*bsd_signal_test)(int, void (*)(int)))(int); int dummyfcn (void) { bsd_signal_test dummyvar; dummyvar=bsd_signal; return 0; } posixtestsuite/conformance/definitions/signal_h/22-20.c0100644000000000000000000000020507555627117022104 0ustar rootroot /* Test that the BUS_ADRERR macro is defined. */ #include #ifndef BUS_ADRERR #error BUS_ADRERR not defined #endif posixtestsuite/conformance/definitions/signal_h/22-29.c0100644000000000000000000000021607555627117022117 0ustar rootroot /* Test that the CLD_CONTINUED macro is defined. */ #include #ifndef CLD_CONTINUED #error CLD_CONTINUED not defined #endif posixtestsuite/conformance/definitions/signal_h/sigmacrolist.txt0100644000000000000000000000065107555627164024546 0ustar rootrootILL_ILLOPC ILL_ILLOPN ILL_ILLADR ILL_ILLTRP ILL_PRVOPC ILL_PRVREG ILL_COPROC ILL_BADSTK FPE_INTDIV FPE_INTOVF FPE_FLTDIV FPE_FLTOVF FPE_FLTUND FPE_FLTRES FPE_FLTINV FPE_FLTSUB SEGV_MAPERR SEGV_ACCERR BUS_ADRALN BUS_ADRERR BUS_OBJERR TRAP_BRKPT TRAP_TRACE CLD_EXITED CLD_KILLED CLD_DUMPED CLD_TRAPPED CLD_STOPPED CLD_CONTINUED POLL_IN POLL_OUT POLL_MSG POLL_ERR POLL_PRI POLL_HUP SI_USER SI_QUEUE SI_TIMER SI_ASYNCIO SI_MESGQ posixtestsuite/conformance/definitions/signal_h/22-34.c0100644000000000000000000000017707555627117022121 0ustar rootroot /* Test that the POLL_PRI macro is defined. */ #include #ifndef POLL_PRI #error POLL_PRI not defined #endif posixtestsuite/conformance/definitions/signal_h/28-1.c0100644000000000000000000000031107556056716022031 0ustar rootroot /* Test that the function: int raise(int); is declared. */ #include typedef int (*raise_test)(int); int dummyfcn (void) { raise_test dummyvar; dummyvar = raise; return 0; } posixtestsuite/conformance/definitions/signal_h/13-1.c0100644000000000000000000000143307555571235022026 0ustar rootroot /* Test that 0 is reserved for the null signal. This test must be executed. */ #include #include int main() { if ( (0 == SIGABRT) || (0 == SIGALRM) || (0 == SIGBUS) || (0 == SIGCHLD) || (0 == SIGCONT) || (0 == SIGFPE) || (0 == SIGHUP) || (0 == SIGILL) || (0 == SIGINT) || (0 == SIGKILL) || (0 == SIGPIPE) || (0 == SIGQUIT) || (0 == SIGSEGV) || (0 == SIGSTOP) || (0 == SIGTERM) || (0 == SIGTSTP) || (0 == SIGTTIN) || (0 == SIGTTOU) || (0 == SIGUSR1) || (0 == SIGUSR2) || (0 == SIGPOLL) || (0 == SIGPROF) || (0 == SIGSYS) || (0 == SIGTRAP) || (0 == SIGURG) || (0 == SIGVTALRM) || (0 == SIGXCPU) || (0 == SIGXFSZ) ) { printf("Test FAILED\n"); return -1; } else { printf("Test PASSED\n"); return 0; } } posixtestsuite/conformance/definitions/signal_h/22-9.c0100644000000000000000000000020507555627117022033 0ustar rootroot /* Test that the FPE_INTDIV macro is defined. */ #include #ifndef FPE_INTDIV #error FPE_INTDIV not defined #endif posixtestsuite/conformance/definitions/signal_h/39-1.c0100644000000000000000000000037507557606350022041 0ustar rootroot /* Test that the function: void (*signal(int, void (*)(int)))(int); is declared. */ #include typedef void (*(*signal_test)(int, void (*)(int)))(int); int dummyfcn (void) { signal_test dummyvar; dummyvar = signal; return 0; } posixtestsuite/conformance/definitions/signal_h/22-8.c0100644000000000000000000000020507555627117022032 0ustar rootroot /* Test that the ILL_BADSTK macro is defined. */ #include #ifndef ILL_BADSTK #error ILL_BADSTK not defined #endif posixtestsuite/conformance/definitions/signal_h/22-21.c0100644000000000000000000000020507555627117022105 0ustar rootroot /* Test that the BUS_OBJERR macro is defined. */ #include #ifndef BUS_OBJERR #error BUS_OBJERR not defined #endif posixtestsuite/conformance/definitions/signal_h/22-35.c0100644000000000000000000000017707555627117022122 0ustar rootroot /* Test that the POLL_HUP macro is defined. */ #include #ifndef POLL_HUP #error POLL_HUP not defined #endif posixtestsuite/conformance/definitions/signal_h/43-1.c0100644000000000000000000000044207556056717022034 0ustar rootroot /* Test that the function: int sigqueue(pid_t, int, const union sigval); is declared. */ #include #include typedef int (*sigqueue_test)(pid_t, int, const union sigval); int dummyfcn (void) { sigqueue_test dummyvar; dummyvar = sigqueue; return 0; } posixtestsuite/conformance/definitions/signal_h/26-1.c0100644000000000000000000000037307556056716022037 0ustar rootroot /* Test that the function: int pthread_kill(pthread_t, int); is declared. */ #include typedef int (*pthread_kill_test)(pthread_t, int); int dummyfcn (void) { pthread_kill_test dummyvar; dummyvar = pthread_kill; return 0; } posixtestsuite/conformance/definitions/signal_h/assertions.xml0100644000000000000000000002144310117555063024205 0ustar rootroot The signal.h header file exists The signal.h header defines the symbols SIG_DFL, SIG_ERR, SIG_HOLD and SIG_IGN as 'void (*) int'. The signal.h header defines sig_atomic_t. The signal.h header defines sigset_t. The sys/types.h header defines pid_t. The signal.h header defines a structure named sigevent which has at least: int sigev_notify int sigev_signo union sigval sigev_value void(*)(union sigval) sigev_notify_function (pthread_attr_t *) sigev_notify_attributes For sigev_notify (assertion 6), the following values are defined: SIGEV_NONE SIGEV_SIGNAL SIGEV_THREAD The sigval union (assertion 6) is defined as: int sival_int void *sival_ptr The signal.h header declares SIGRTMIN and SIGRTMAX. These are macros that evaluate to integer expressions for the minimum and maximum signal numbers reserved for realtime signals. The range SIGRTMIN-SIGRTMAX doesn't overlap pre-defined signals (see below). The SIGRTMIN-SIGRTMAX range includes at least {RTSIG_MAX} signal numbers. Realtime signal behavior may or may not be supported for non-realtime signals. This is defined by the implementation. The value 0 is not used in any signals, but is reserved as the null signal. The following signals are always (on all implementations) supported: SIGABRT SIGALRM SIGBUS SIGCHLD SIGCONT SIGFPE SIGHUP SIGILL SIGINT SIGKILL SIGPIPE SIGQUIT SIGSEGV SIGSTOP SIGTERM SIGTSTP SIGTTIN SIGTTOU SIGUSR1 SIGUSR2 SIGPOLL SIGPROF SIGSYS SIGTRAP SIGURG SIGVTALRM SIGXCPU SIGXFSZ The signal.h header declares the struct sigaction which has, at a minimum, the following members: void (*sa_handler)(int) sigset_t sa_mask int sa_flags void (*)(int, siginfo_t *, void *) sa_sigaction The constants below are declared: SA_NOCLDSTOP SIG_BLOCK SIG_UNBLOCK SIG_SETMASK SA_ONSTACK SA_RESETHAND SA_RESTART SA_SIGINFO SA_NOCLDWAIT SA_NODEFER SS_ONSTACK SS_DISABLE MINSIGSTKSZ SIGSTKSZ The ucontext.h header shall define ucontext_t. The ucontext.h header shall define mcontext_t. The signal.h header defines the structure stack_t which includes the following, at a minimum: void *ss_sp size_t ss_size int ss_flags The signal.h header defines the structure sigstack which includes the following, at a minimum: int ss_onstack void *ss_sp The signal.h header defines the structure siginfo_t which includes the following, at a minimum: int si_signo int si_errno int si_code pid_t si_pid uid_t si_uid void *si_addr int si_status long si_band union sigval si_value The following macros are defined: ILL_ILLOPC ILL_ILLOPN ILL_ILLADR ILL_ILLTRP ILL_PRVOPC ILL_PRVREG ILL_COPROC ILL_BADSTK FPE_INTDIV FPE_INTOVF FPE_FLTDIV FPE_FLTOVF FPE_FLTUND FPE_FLTRES FPE_FLTINV FPE_FLTSUB SEGV_MAPERR SEGV_ACCERR BUS_ADRALN BUS_ADRERR BUS_OBJERR TRAP_BRKPT TRAP_TRACE CLD_EXITED CLD_KILLED CLD_DUMPED CLD_TRAPPED CLD_STOPPED CLD_CONTINUED POLL_IN POLL_OUT POLL_MSG POLL_ERR POLL_PRI POLL_HUP SI_USER SI_QUEUE SI_TIMER SI_ASYNCIO SI_MESGQ The function below is declared: void (*bsd_signal(int, void (*)(int)))(int); The function below is declared: int kill(pid_t, int); The function below is declared: int killpg(pid_t, int); The function below is declared: int pthread_kill(pthread_t, int); The function below is declared: int pthread_sigmask(int, const sigset_t *, sigset_t *); The function below is declared: int raise(int); The function below is declared: int sigaction(int, const struct sigaction *restrict, struct sigaction *restrict); The function below is declared: int sigaddset(sigset_t *, int); The function below is declared: int sigaltstack(const stack_t *restrict, stack_t *restrict); The function below is declared: int sigdelset(sigset_t *, int); The function below is declared: int sigemptyset(sigset_t *); The function below is declared: int sigfillset(sigset_t *); The function below is declared: int sighold(int); The function below is declared: int sigignore(int); The function below is declared: int siginterrupt(int, int); The function below is declared: int sigismember(const sigset_t *, int); The function below is declared: void (*signal(int, void (*)(int)))(int); The function below is declared: int sigpause(int); The function below is declared: int sigpending(sigset_t *); The function below is declared: int sigprocmask(int, const sigset_t *restrict, sigset_t *restrict); The function below is declared: int sigqueue(pid_t, int, const union sigval); The function below is declared: int sigrelse(int); The function below is declared: void (*sigset(int, void (*)(int)))(int); The function below is declared: int sigsuspend(const sigset_t *); The function below is declared: int sigtimedwait(const sigset_t *restrict, siginfo_t *restrict, const struct timespec *restrict); The function below is declared: int sigwait(const sigset_t *restrict, int *restrict); The function below is declared: int sigwaitinfo(const sigset_t *restrict, siginfo_t *restrict); Inclusion of the signal.h header may make visible all symbols from the time.h header. posixtestsuite/conformance/definitions/signal_h/22-19.c0100644000000000000000000000020507555627117022114 0ustar rootroot /* Test that the BUS_ADRALN macro is defined. */ #include #ifndef BUS_ADRALN #error BUS_ADRALN not defined #endif posixtestsuite/conformance/definitions/signal_h/21-1.c0100644000000000000000000000072510053067720022012 0ustar rootroot /* Test the definition of siginfo_t. */ #include #include siginfo_t this_type_should_exist, t; int tsigno; int terrno; int tcode; pid_t tpid; uid_t tuid; void *taddr; int tstatus; long tband; union sigval tvalue; int dummyfcn (void) { tsigno = t.si_signo; terrno = t.si_errno; tcode = t.si_code; tpid = t.si_pid; tuid = t.si_uid; taddr = t.si_addr; tstatus = t.si_status; tband = t.si_band; tvalue = t.si_value; return 0; } posixtestsuite/conformance/definitions/signal_h/22-10.c0100644000000000000000000000020507555627117022103 0ustar rootroot /* Test that the FPE_INTOVF macro is defined. */ #include #ifndef FPE_INTOVF #error FPE_INTOVF not defined #endif posixtestsuite/conformance/definitions/signal_h/25-1.c0100644000000000000000000000036207556056716022034 0ustar rootroot /* Test that the function: int killpg(pid_t, int); is declared. */ #include #include typedef int (*killpg_test)(pid_t, int); int dummyfcn (void) { killpg_test dummyvar; dummyvar = killpg; return 0; } posixtestsuite/conformance/definitions/signal_h/coverage.txt0100644000000000000000000000062007560600072023616 0ustar rootrootThis document explains why certain assertions were not tested. Assertions not listed here should be covered by the tests in this directory. 6 through 12 - Did not test RTS assertions. 50 - This test case needs to be much larger. Other items I am currently investigating (as of 10/28/02): The assertions: 19 21 45 fail on the system I am testing on. These appear to be valid header file failures. posixtestsuite/conformance/definitions/signal_h/22-12.c0100644000000000000000000000020507555627117022105 0ustar rootroot /* Test that the FPE_FLTOVF macro is defined. */ #include #ifndef FPE_FLTOVF #error FPE_FLTOVF not defined #endif posixtestsuite/conformance/definitions/signal_h/22-4.c0100644000000000000000000000020507555627117022026 0ustar rootroot /* Test that the ILL_ILLTRP macro is defined. */ #include #ifndef ILL_ILLTRP #error ILL_ILLTRP not defined #endif posixtestsuite/conformance/definitions/signal_h/22-5.c0100644000000000000000000000020507555627117022027 0ustar rootroot /* Test that the ILL_PRVOPC macro is defined. */ #include #ifndef ILL_PRVOPC #error ILL_PRVOPC not defined #endif posixtestsuite/conformance/definitions/signal_h/22-24.c0100644000000000000000000000020507555627117022110 0ustar rootroot /* Test that the CLD_EXITED macro is defined. */ #include #ifndef CLD_EXITED #error CLD_EXITED not defined #endif posixtestsuite/conformance/definitions/signal_h/22-14.c0100644000000000000000000000020507555627117022107 0ustar rootroot /* Test that the FPE_FLTRES macro is defined. */ #include #ifndef FPE_FLTRES #error FPE_FLTRES not defined #endif posixtestsuite/conformance/definitions/signal_h/22-22.c0100644000000000000000000000020507555627117022106 0ustar rootroot /* Test that the TRAP_BRKPT macro is defined. */ #include #ifndef TRAP_BRKPT #error TRAP_BRKPT not defined #endif posixtestsuite/conformance/definitions/signal_h/22-28.c0100644000000000000000000000021007555627117022110 0ustar rootroot /* Test that the CLD_STOPPED macro is defined. */ #include #ifndef CLD_STOPPED #error CLD_STOPPED not defined #endif posixtestsuite/conformance/definitions/signal_h/41-1.c0100644000000000000000000000036607556056717022037 0ustar rootroot /* @:pt:CX Test that the function: int sigpending(sigset_t *); is declared. */ #include typedef int (*sigpending_test)(sigset_t *); int dummyfcn (void) { sigpending_test dummyvar; dummyvar = sigpending; return 0; } posixtestsuite/conformance/definitions/signal_h/35-1.c0100644000000000000000000000033507556056717022036 0ustar rootroot /* @:pt:XSI Test that the function: int sighold(int); is declared. */ #include typedef int (*sighold_test)(int); int dummyfcn (void) { sighold_test dummyvar; dummyvar = sighold; return 0; } posixtestsuite/conformance/definitions/signal_h/22-36.c0100644000000000000000000000017407555627117022120 0ustar rootroot /* Test that the SI_USER macro is defined. */ #include #ifndef SI_USER #error SI_USER not defined #endif posixtestsuite/conformance/definitions/signal_h/16-1.c0100644000000000000000000000067007555624640022032 0ustar rootroot /* Test that the constants below are supported. */ #include int dummy1 = SA_NOCLDSTOP; int dummy2 = SIG_BLOCK; int dummy3 = SIG_UNBLOCK; int dummy4 = SIG_SETMASK; int dummy5 = SA_ONSTACK; int dummy6 = SA_RESETHAND; int dummy7 = SA_RESTART; int dummy8 = SA_SIGINFO; int dummy9 = SA_NOCLDWAIT; int dummy10 = SA_NODEFER; int dummy11 = SS_ONSTACK; int dummy12 = SS_DISABLE; int dummy13 = MINSIGSTKSZ; int dummy14 = SIGSTKSZ; posixtestsuite/conformance/definitions/signal_h/32-1.c0100644000000000000000000000036107556056716022031 0ustar rootroot /* Test that the function: int sigdelset(sigset_t *, int); is declared. */ #include typedef int (*sigdelset_test)(sigset_t *, int); int dummyfcn (void) { sigdelset_test dummyvar; dummyvar = sigdelset; return 0; } posixtestsuite/conformance/definitions/signal_h/38-1.c0100644000000000000000000000040507556056717022037 0ustar rootroot /* Test that the function: int sigismember(const sigset_t *, int); is declared. */ #include typedef int (*sigismember_test)(const sigset_t *, int); int dummyfcn (void) { sigismember_test dummyvar; dummyvar = sigismember; return 0; } posixtestsuite/conformance/definitions/signal_h/22-16.c0100644000000000000000000000020507555627117022111 0ustar rootroot /* Test that the FPE_FLTSUB macro is defined. */ #include #ifndef FPE_FLTSUB #error FPE_FLTSUB not defined #endif posixtestsuite/conformance/definitions/signal_h/2-3.c0100644000000000000000000000015707552722520021740 0ustar rootroot /* @pt:CX Test the definition of SIG_HOLD. */ #include void (*dummy) (int) = SIG_HOLD; posixtestsuite/conformance/definitions/signal_h/22-27.c0100644000000000000000000000021007555627117022107 0ustar rootroot /* Test that the CLD_TRAPPED macro is defined. */ #include #ifndef CLD_TRAPPED #error CLD_TRAPPED not defined #endif posixtestsuite/conformance/definitions/signal_h/2-1.c0100644000000000000000000000014107552722520021727 0ustar rootroot /* Test the definition of SIG_DFL. */ #include void (*dummy) (int) = SIG_DFL; posixtestsuite/conformance/definitions/signal_h/36-1.c0100644000000000000000000000034507556056717022040 0ustar rootroot /* @:pt:XSI Test that the function: int sigignore(int); is declared. */ #include typedef int (*sigignore_test)(int); int dummyfcn (void) { sigignore_test dummyvar; dummyvar = sigignore; return 0; } posixtestsuite/conformance/definitions/signal_h/31-1.c0100644000000000000000000000051307557606350022023 0ustar rootroot /* Test that the function: int sigaltstack(const stack_t *restrict, stack_t *restrict); is declared. Removed restrict keyword from typedef. */ #include typedef int (*sigaltstack_test)(const stack_t *, stack_t *); int dummyfcn (void) { sigaltstack_test dummyvar; dummyvar = sigaltstack; return 0; } posixtestsuite/conformance/definitions/signal_h/40-1.c0100644000000000000000000000034107556056717022027 0ustar rootroot /* @:pt:XSI Test that the function: int sigpause(int); is declared. */ #include typedef int (*sigpause_test)(int); int dummyfcn (void) { sigpause_test dummyvar; dummyvar = sigpause; return 0; } posixtestsuite/conformance/definitions/signal_h/3-1.c0100644000000000000000000000013307555571235021741 0ustar rootroot /* Test the definition of sig_atomic_t. */ #include sig_atomic_t dummy; posixtestsuite/conformance/definitions/signal_h/27-1.c0100644000000000000000000000045507556057014022031 0ustar rootroot /* Test that the function: int pthread_sigmask(int, const sigset_t *, sigset_t *); is declared. */ #include typedef int (*pthread_sigmask_test)(int, const sigset_t *, sigset_t *); int dummyfcn (void) { pthread_sigmask_test dummyvar; dummyvar = pthread_sigmask; return 0; } posixtestsuite/conformance/definitions/signal_h/47-1.c0100644000000000000000000000061407556060605022030 0ustar rootroot /* @pt:RTS Test that the function: int sigtimedwait(const sigset_t *restrict, siginfo_t *restrict, const struct timespec *restrict); is declared. */ #include typedef int (*sigtimedwait_test)(const sigset_t *restrict, siginfo_t *restrict, const struct timespec *restrict); int dummyfcn (void) { sigtimedwait_test dummyvar; dummyvar = sigtimedwait; return 0; } posixtestsuite/conformance/definitions/signal_h/22-17.c0100644000000000000000000000021007555627117022106 0ustar rootroot /* Test that the SEGV_MAPERR macro is defined. */ #include #ifndef SEGV_MAPERR #error SEGV_MAPERR not defined #endif posixtestsuite/conformance/definitions/errno_h/0040755000000000000000000000000010515625153021140 5ustar rootrootposixtestsuite/conformance/definitions/errno_h/4-1.c0100644000000000000000000000452507567063132021616 0ustar rootroot/* *errno.h shall give positive values for the *error number symbolic constants *author:ysun@lnxw.com */ #include #include #define PTP_PASS 0 #define PTP_FAIL 1 #define PTP_UNRESOLVED 2 #define PTP_NOTINUSE 3 #define PTP_UNSUPPORTED 4 #define PTP_UNTESTED 5 #define PTP_UNINITIATED 6 #define PTP_NORESULT 7 struct unique { int value; char *name; } sym[] = {{E2BIG,"E2BIG"},{EACCES,"EACCES"}, {EADDRINUSE,"EADDRINUSE"}, {EADDRNOTAVAIL,"EADDRNOTAVAIL"}, {EAFNOSUPPORT,"EAFNOSUPPORT"}, {EAGAIN,"EAGAIN"}, {EALREADY,"EALREADY"}, {EBADF,"EBADF"}, {EBADMSG,"EBADMSG"},{EBUSY,"EBUSY"}, {ECANCELED,"ECANCELED"},{ECHILD,"ECHILD"}, {ECONNABORTED,"ECONNABORTED"}, {ECONNREFUSED,"ECONNREFUSED"}, {ECONNRESET,"ECONNRESET"},{EDEADLK,"EDEADLK"}, {EDESTADDRREQ,"EDESTADDRREQ"},{EDOM,"EDOM"}, {EDQUOT,"EDQUOT"},{EEXIST,"EEXIST"}, {EFAULT,"EFAULT"},{EFBIG,"EFBIG"}, {EHOSTUNREACH,"EHOSTUNREACH"}, {EIDRM,"EIDRM"},{EILSEQ,"EILSEQ"}, {EINPROGRESS,"EINPROGRESS"}, {EINTR,"EINTR"},{EINVAL,"EINVAL"}, {EIO,"EIO"},{EISCONN,"EISCONN"}, {EISDIR,"EISDIR"},{ELOOP,"ELOOP"}, {EMFILE,"EMFILE"},{EMLINK,"EMLINK"}, {EMSGSIZE,"EMSGSIZE"},{EMULTIHOP,"EMULTIHOP"}, {ENAMETOOLONG,"ENAMETOOLONG"}, {ENETDOWN,"ENETDOWN"}, {ENETRESET,"ENETRESET"},{ENETUNREACH,"ENETUNREACH"}, {ENFILE,"ENFILE"},{ENOBUFS,"ENOBUFS"}, {ENODATA,"ENODATA"},{ENODEV,"ENODEV"}, {ENOENT,"ENOENT"},{ENOEXEC,"ENOEXEC"}, {ENOLCK,"ENOLCK"},{ENOLINK,"ENOLINK"}, {ENOMEM,"ENOMEM"},{ENOMSG,"ENOMSG"}, {ENOPROTOOPT,"ENOPROTOOPT"},{ENOSPC,"ENOSPC"}, {ENOSR,"ENOSR"},{ENOSTR,"ENOSTR"}, {ENOSYS,"ENOSYS"},{ENOTCONN,"ENOTCONN"}, {ENOTDIR,"ENOTDIR"},{ENOTEMPTY,"ENOTEMPTY"}, {ENOTSOCK,"ENOTSOCK"},{ENOTSUP,"ENOTSUP"}, {ENOTTY,"ENOTTY"},{ENXIO,"ENXIO"}, {EOPNOTSUPP,"EOPNOTSUPP"},{EOVERFLOW,"EOVERFLOW"}, {EPERM,"EPERM"},{EPIPE,"EPIPE"},{EPROTO,"EPROTO"}, {EPROTONOSUPPORT,"EPROTONOSUPPORT"}, {EPROTOTYPE,"EPROTOTYPE"}, {ERANGE,"ERANGE"},{EROFS,"EROFS"}, {EWOULDBLOCK,"EWOULDBLOCK"},{EXDEV,"EXDEV"}, {0,0} }; int main() { struct unique *tst=sym; int ret = PTP_PASS; while(tst->name){ if (tst->value < 0){ printf("Value of symbol %s is less than zero\n",tst->name); ret = PTP_FAIL; } tst++; } return ret; } posixtestsuite/conformance/definitions/errno_h/1-1.c0100644000000000000000000000014407567063132021604 0ustar rootroot/* * This test tests if error.h is exist and useble *author:ysun@lnxw.com */ #include posixtestsuite/conformance/definitions/errno_h/3-2.c0100644000000000000000000000650607567063132021617 0ustar rootroot/* * The most of error symbles shall have unique value * I try to test every symble in a loop. There * are two kind symbles, one have unique value, the others * can have same value with certain other symbles * Author:ysun@lnxw.com */ #include #include #include #define PTP_PASS 0 #define PTP_FAIL 1 #define PTP_UNRESOLVED 2 #define PTP_NOTINUSE 3 #define PTP_UNSUPPORTED 4 #define PTP_UNTESTED 5 #define PTP_UNINITIATED 6 #define PTP_NORESULT 7 struct unique { int value; char *name; int duplicate; } sym[] = {{E2BIG,"E2BIG",E2BIG},{EACCES,"EACCES",EACCES}, {EADDRINUSE,"EADDRINUSE",EADDRINUSE}, {EADDRNOTAVAIL,"EADDRNOTAVAIL",EADDRNOTAVAIL}, {EAFNOSUPPORT,"EAFNOSUPPORT",EAFNOSUPPORT}, {EAGAIN,"EAGAIN",EWOULDBLOCK}, {EALREADY,"EALREADY",EALREADY}, {EBADF,"EBADF",EBADF}, {EBADMSG,"EBADMSG",EBADMSG},{EBUSY,"EBUSY",EBUSY}, {ECANCELED,"ECANCELED",ECANCELED},{ECHILD,"ECHILD",ECHILD}, {ECONNABORTED,"ECONNABORTED",ECONNABORTED}, {ECONNREFUSED,"ECONNREFUSED",ECONNREFUSED}, {ECONNRESET,"ECONNRESET",ECONNRESET},{EDEADLK,"EDEADLK",EDEADLK,}, {EDESTADDRREQ,"EDESTADDRREQ",EDESTADDRREQ},{EDOM,"EDOM",EDOM}, {EDQUOT,"EDQUOT",EDQUOT},{EEXIST,"EEXIST",EEXIST}, {EFAULT,"EFAULT",EFAULT},{EFBIG,"EFBIG",EFBIG}, {EHOSTUNREACH,"EHOSTUNREACH",EHOSTUNREACH}, {EIDRM,"EIDRM",EIDRM},{EILSEQ,"EILSEQ",EILSEQ}, {EINPROGRESS,"EINPROGRESS",EINPROGRESS}, {EINTR,"EINTR",EINTR},{EINVAL,"EINVAL",EINVAL}, {EIO,"EIO",EIO},{EISCONN,"EISCONN",EISCONN}, {EISDIR,"EISDIR",EISDIR},{ELOOP,"ELOOP",ELOOP}, {EMFILE,"EMFILE",EMFILE},{EMLINK,"EMLINK",EMLINK}, {EMSGSIZE,"EMSGSIZE",EMSGSIZE},{EMULTIHOP,"EMULTIHOP",EMULTIHOP}, {ENAMETOOLONG,"ENAMETOOLONG",ENAMETOOLONG}, {ENETDOWN,"ENETDOWN",ENETDOWN}, {ENETRESET,"ENETRESET",ENETRESET},{ENETUNREACH,"ENETUNREACH",ENETUNREACH}, {ENFILE,"ENFILE",ENFILE},{ENOBUFS,"ENOBUFS",ENOBUFS}, {ENODATA,"ENODATA",ENODATA},{ENODEV,"ENODEV",ENODEV}, {ENOENT,"ENOENT",ENOENT},{ENOEXEC,"ENOEXEC",ENOEXEC}, {ENOLCK,"ENOLCK",ENOLCK},{ENOLINK,"ENOLINK",ENOLINK}, {ENOMEM,"ENOMEM",ENOMEM},{ENOMSG,"ENOMSG",ENOMSG}, {ENOPROTOOPT,"ENOPROTOOPT",ENOPROTOOPT},{ENOSPC,"ENOSPC",ENOSPC}, {ENOSR,"ENOSR",ENOSR},{ENOSTR,"ENOSTR",ENOSTR}, {ENOSYS,"ENOSYS",ENOSYS},{ENOTCONN,"ENOTCONN",ENOTCONN}, {ENOTDIR,"ENOTDIR",ENOTDIR},{ENOTEMPTY,"ENOTEMPTY",ENOTEMPTY}, {ENOTSOCK,"ENOTSOCK",ENOTSOCK},{ENOTSUP,"ENOTSUP",ENOTSUP}, {ENOTTY,"ENOTTY",ENOTTY},{ENXIO,"ENXIO",ENXIO}, {EOPNOTSUPP,"EOPNOTSUPP",EOPNOTSUPP},{EOVERFLOW,"EOVERFLOW",EOVERFLOW}, {EPERM,"EPERM",EPERM},{EPIPE,"EPIPE",EPIPE},{EPROTO,"EPROTO",EPROTO}, {EPROTONOSUPPORT,"EPROTONOSUPPORT",EPROTONOSUPPORT}, {EPROTOTYPE,"EPROTOTYPE",EPROTOTYPE}, {ERANGE,"ERANGE",ERANGE},{EROFS,"EROFS",EROFS}, {EWOULDBLOCK,"EWOULDBLOCK",EAGAIN},{EXDEV,"EXDEV",EXDEV}, {0,0,0} }; int main() { struct unique *tst; int i,ret = PTP_PASS; tst = sym; while (tst->name) { for(i = 0; sym[i].name; i++) { if (tst->value == sym[i].value && tst->duplicate != sym[i].value && strcmp(tst->name,sym[i].name)) {//In case EAGAIN is not equal to EWOULDBLOCK,compare the name printf("%s has a duplicate value with %s\n", tst->name,sym[i].name); ret = PTP_FAIL; } } tst++; } return ret; } posixtestsuite/conformance/definitions/errno_h/assertions.xml0100644000000000000000000000554510117555045024062 0ustar rootroot The errno.h header file exists. The errno.h header shall provide a declaration for errno All values listed in this section shall be unique integer constant expressions with type int suitable for use in #if preprocessing directives. [E2BIG] [EACCES] [EADDRINUSE] [EADDRNOTAVAIL] [EAFNOSUPPORT] [EAGAIN] [EALREADY] [EBADF] [EBADMSG] [EBUSY] [ECANCELED] [ECHILD] [ECONNABORTED] [ECONNREFUSED] [ECONNRESET] [EDEADLK] [EDESTADDRREQ] [EDOM] [EDQUOT] [EEXIST] [EFAULT] [EFBIG] [EHOSTUNREACH] [EIDRM] [EILSEQ] [EINPROGRESS] [EINTR] [EINVAL] [EIO] [EISCONN] [EISDIR] [ELOOP] [EMFILE] [EMLINK] [EMSGSIZE] [EMULTIHOP] [ENAMETOOLONG] [ENETDOWN] [ENETRESET] [ENETUNREACH] [ENFILE] [ENOBUFS] [ENODATA] [ENODEV] [ENOENT] [ENOEXEC] [ENOLCK] [ENOLINK] [ENOMEM] [ENOMSG] [ENOPROTOOPT] [ENOSPC] [ENOSR] [ENOSTR] [ENOSYS] [ENOTCONN] [ENOTDIR] [ENOTEMPTY] [ENOTSOCK] [ENOTSUP] [ENOTTY] [ENXIO] [EOPNOTSUPP] [EOVERFLOW] [EPERM] [EPIPE] [EPROTO] [EPROTONOSUPPORT] [EPROTOTYPE] [ERANGE] [EROFS] [ESPIPE] [ESRCH] [ESTALE] [ETIME] [ETIMEDOUT] [ETXTBSY] [EWOULDBLOCK] [EXDEV] errno.h shall give positive values for the following symbolic constants [E2BIG] [EACCES] [EADDRINUSE] [EADDRNOTAVAIL] [EAFNOSUPPORT] [EAGAIN] [ELREADY] [EBADF] [EBADMSG] [EBUSY] [ECANCELED] [ECHILD] [ECONNABORTED] [ECONNREFUSED] [ECONNRESET] [EDEADLK] [EDESTADDRREQ] [EDOM] [EDQUOT] [EEXIST] [EFAULT] [EFBIG] [EHOSTUNREACH] [EIDRM] [EILSEQ] [EINPROGRESS] [EINTR] [EINVAL] [EIO] [EISCONN] [EISDIR] [ELOOP] [EMFILE] [EMLINK] [EMSGSIZE] [EMULTIHOP] [ENAMETOOLONG] [ENETDOWN] [ENETRESET] [ENETUNREACH] [ENFILE] [ENOBUFS] [ENODATA] [ENODEV] [ENOENT] [ENOEXEC] [ENOLCK] [ENOLINK] [ENOMEM] [ENOMSG] [ENOPROTOOPT] [ENOSPC] [ENOSR] [ENOSTR] [ENOSYS] [ENOTCONN] [ENOTDIR] [ENOTEMPTY] [ENOTSOCK] [ENOTSUP] [ENOTTY] [ENXIO] [EOPNOTSUPP] [EOVERFLOW] [EPERM] [EPIPE] [EPROTO] [EPROTONOSUPPORT] [EPROTOTYPE] [ERANGE] [EROFS] [ESPIPE] [ESRCH] [ESTALE] [ETIME] [ETIMEDOUT] [ETXTBSY] [EWOULDBLOCK] [EXDEV] posixtestsuite/conformance/definitions/errno_h/2-1.c0100644000000000000000000000027507631644612021612 0ustar rootroot/* *The header shall provide a *declaration for errno *author:ysun@lnxw.com */ #include int errno_test; int dummyfcn (void) { errno_test = errno; return 0; } posixtestsuite/conformance/definitions/errno_h/3-1.c0100644000000000000000000000362107567063132021611 0ustar rootroot/* *Following symbles need to be defined in errno.h *author:ysun@lnxw.com */ #include int dummy1 = E2BIG; int dummy2 = EACCES; int dummy3 = EADDRINUSE ; int dummy4 = EADDRNOTAVAIL; int dummy5 = EAFNOSUPPORT; int dummy6 = EAGAIN; int dummy7 = EALREADY; int dummy8 = EBADF; int dummy9 = EBADMSG; int dummy10 = EBUSY; int dummy11 = ECANCELED; int dummy12 = ECHILD; int dummy13 = ECONNABORTED; int dummy14 = ECONNREFUSED; int dummy15 = ECONNRESET; int dummy16 = EDEADLK; int dummy17 = EDESTADDRREQ; int dummy18 = EDOM; int dummy19 = EDQUOT; int dummy20 = EEXIST; int dummy21 = EFAULT; int dummy22 = EFBIG; int dummy23 = EHOSTUNREACH; int dummy24 = EIDRM; int dummy25 = EILSEQ; int dummy26 = EINPROGRESS; int dummy27 = EINTR; int dummy28 = EINVAL; int dummy29 = EIO; int dummy30 = EISCONN; int dummy31 = EISDIR; int dummy32 = ELOOP; int dummy33 = EMFILE; int dummy34 = EMLINK; int dummy35 = EMSGSIZE; int dummy36 = EMULTIHOP; int dummy37 = ENAMETOOLONG; int dummy38 = ENETDOWN; int dummy39 = ENETRESET; int dummy40 = ENETUNREACH; int dummy41 = ENFILE; int dummy42 = ENOBUFS; int dummy43 = ENODATA; int dummy44 = ENODEV; int dummy45 = ENOENT; int dummy46 = ENOEXEC; int dummy47 = ENOLCK; int dummy48 = ENOLINK; int dummy49 = ENOMEM; int dummy50 = ENOMSG; int dummy51 = ENOPROTOOPT; int dummy52 = ENOSPC; int dummy53 = ENOSR; int dummy54 = ENOSTR; int dummy55 = ENOSYS; int dummy56 = ENOTCONN; int dummy57 = ENOTDIR; int dummy58 = ENOTEMPTY; int dummy59 = ENOTSOCK; int dummy60 = ENOTSUP; int dummy61 = ENOTTY; int dummy62 = ENXIO; int dummy63 = EOPNOTSUPP; int dummy64 = EOVERFLOW; int dummy65 = EPERM; int dummy66 = EPIPE; int dummy67 = EPROTO; int dummy68 = EPROTONOSUPPORT; int dummy69 = EPROTOTYPE; int dummy70 = ERANGE; int dummy71 = EROFS; int dummy72 = ESPIPE; int dummy73 = ESRCH; int dummy74 = ESTALE; int dummy75 = ETIME; int dummy76 = ETIMEDOUT; int dummy77 = ETXTBSY; int dummy78 = EWOULDBLOCK; int dummy79 = EXDEV; posixtestsuite/conformance/definitions/pthread_h/0040755000000000000000000000000010515625154021443 5ustar rootrootposixtestsuite/conformance/definitions/pthread_h/2-2.c0100644000000000000000000000240110504726520022076 0ustar rootroot /* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test the following symbols are defined by pthread.h */ #include /* BAR */ #ifndef PTHREAD_BARRIER_SERIAL_THREAD #error PTHREAD_BARRIER_SERIAL_THREAD not defined #endif /* XSI */ #ifndef PTHREAD_MUTEX_DEFAULT #error PTHREAD_MUTEX_DEFAULT not defined #endif /* XSI */ #ifndef PTHREAD_MUTEX_ERRORCHECK #error PTHREAD_MUTEX_ERRORCHECK not defined #endif /* XSI */ #ifndef PTHREAD_MUTEX_NORMAL #error PTHREAD_MUTEX_NORMAL not defined #endif /* XSI */ #ifndef PTHREAD_MUTEX_RECURSIVE #error PTHREAD_MUTEX_RECURSIVE not defined #endif /* TPP|TPI */ #ifndef PTHREAD_PRIO_INHERIT #error PTHREAD_PRIO_INHERIT not defined #endif /* TPP|TPI */ #ifndef PTHREAD_PRIO_NONE #error PTHREAD_PRIO_NONE not defined #endif /* TPP|TPI */ #ifndef PTHREAD_PRIO_PROTECT #error PTHREAD_PRIO_PROTECT not defined #endif /* TPS */ #ifndef PTHREAD_SCOPE_PROCESS #error PTHREAD_SCOPE_PROCESS not defined #endif /* TPS */ #ifndef PTHREAD_SCOPE_SYSTEM #error PTHREAD_SCOPE_SYSTEM not defined #endif posixtestsuite/conformance/definitions/pthread_h/3-8.c0100644000000000000000000000056207605127533022122 0ustar rootroot /* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test pthread_mutexattr_t */ #include pthread_mutexattr_t dummy; posixtestsuite/conformance/definitions/pthread_h/15-1.c0100644000000000000000000000074007606365616022203 0ustar rootroot /* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test this function is defined: int pthread_mutex_destroy(pthread_mutex_t *); */ #include pthread_mutex_t a; void dummy_func () { pthread_mutex_destroy(&a); return; } posixtestsuite/conformance/definitions/pthread_h/3-13.c0100644000000000000000000000053607605127533022177 0ustar rootroot /* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test pthread_t */ #include pthread_t dummy; posixtestsuite/conformance/definitions/pthread_h/17-1.c0100644000000000000000000000074007606365617022206 0ustar rootroot /* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test this function is defined: int pthread_mutex_trylock(pthread_mutex_t *); */ #include pthread_mutex_t a; void dummy_func () { pthread_mutex_trylock(&a); return; } posixtestsuite/conformance/definitions/pthread_h/19-1.c0100644000000000000000000000075207606365617022213 0ustar rootroot /* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test this function is defined: int pthread_mutexattr_init(pthread_mutexattr_t *); */ #include pthread_mutexattr_t a; void dummy_func () { pthread_mutexattr_init(&a); return; } posixtestsuite/conformance/definitions/pthread_h/3-12.c0100644000000000000000000000056607605127533022201 0ustar rootroot /* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test pthread_spinlock_t SPI */ #include pthread_spinlock_t dummy; posixtestsuite/conformance/definitions/pthread_h/3-10.c0100644000000000000000000000055407605127533022174 0ustar rootroot /* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test pthread_rwlock_t */ #include pthread_rwlock_t dummy; posixtestsuite/conformance/definitions/pthread_h/5-1.c0100644000000000000000000000066007605434236022115 0ustar rootroot /* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test this function is defined: void pthread_exit(void *); */ #include void dummy_func () { pthread_exit(NULL); return; } posixtestsuite/conformance/definitions/pthread_h/3-5.c0100644000000000000000000000056007605127533022115 0ustar rootroot /* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test pthread_condattr_t */ #include pthread_condattr_t dummy; posixtestsuite/conformance/definitions/pthread_h/4-1.c0100644000000000000000000000116410175474433022113 0ustar rootroot /* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test this function is defined: pthread_create(pthread_t *restrict, const pthread_attr_t *restrict, void *(*)(void *), void *restrict); */ #include void * thread_function(void * arg) { return NULL; } void dummy_func() { pthread_t a_thread; pthread_create(&a_thread, NULL, thread_function, NULL); return; } posixtestsuite/conformance/definitions/pthread_h/14-1.c0100644000000000000000000000101607606365613022174 0ustar rootroot /* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test this function is defined: int pthread_mutex_init(pthread_mutex_t *restrict, const pthread_mutexattr_t *restrict); */ #include pthread_mutex_t a; void dummy_func () { pthread_mutex_init(&a, NULL); return; } posixtestsuite/conformance/definitions/pthread_h/18-1.c0100644000000000000000000000073607606365617022214 0ustar rootroot /* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test this function is defined: int pthread_mutex_unlock(pthread_mutex_t *); */ #include pthread_mutex_t a; void dummy_func () { pthread_mutex_unlock(&a); return; } posixtestsuite/conformance/definitions/pthread_h/3-9.c0100644000000000000000000000055007605127533022120 0ustar rootroot /* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test pthread_once_t */ #include pthread_once_t dummy; posixtestsuite/conformance/definitions/pthread_h/12-1.c0100644000000000000000000000102607605434236022170 0ustar rootroot /* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test this function is defined: int pthread_attr_getdetachstate(const pthread_attr_t *, int *); */ #include pthread_attr_t a; int *detachstate; void dummy_func () { pthread_attr_getdetachstate(&a, detachstate); return; } posixtestsuite/conformance/definitions/pthread_h/1-1.c0100644000000000000000000000056607574236575022131 0ustar rootroot /* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test the header file pthread.h exists and can be included */ #include posixtestsuite/conformance/definitions/pthread_h/9-1.c0100644000000000000000000000070107605434236022115 0ustar rootroot /* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test this function is defined: int pthread_detach(pthread_t); */ #include pthread_t a; void dummy_func () { pthread_detach(a); return; } posixtestsuite/conformance/definitions/pthread_h/20-1.c0100644000000000000000000000076007606365617022202 0ustar rootroot /* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test this function is defined: int pthread_mutexattr_destroy(pthread_mutexattr_t *); */ #include pthread_mutexattr_t a; void dummy_func () { pthread_mutexattr_destroy(&a); return; } posixtestsuite/conformance/definitions/pthread_h/3-6.c0100644000000000000000000000054407605127533022120 0ustar rootroot /* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test pthread_key_t */ #include pthread_key_t dummy; posixtestsuite/conformance/definitions/pthread_h/11-1.c0100644000000000000000000000073207605434236022172 0ustar rootroot /* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test this function is defined: int pthread_attr_destroy(pthread_attr_t *); */ #include pthread_attr_t a; void dummy_func () { pthread_attr_destroy(&a); return; } posixtestsuite/conformance/definitions/pthread_h/6-1.c0100644000000000000000000000072110504726520022104 0ustar rootroot /* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test this function is defined: pthread_t pthread_self(void); */ #include void dummy_func () { pthread_t ptid = pthread_self(); if (ptid == 0) return; } posixtestsuite/conformance/definitions/pthread_h/13-1.c0100644000000000000000000000101607605434236022170 0ustar rootroot /* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test this function is defined: int pthread_attr_setdetachstate(const pthread_attr_t *, int); */ #include pthread_attr_t a; void dummy_func () { pthread_attr_setdetachstate(&a, PTHREAD_CREATE_DETACHED); return; } posixtestsuite/conformance/definitions/pthread_h/3-2.c0100644000000000000000000000056107605127533022113 0ustar rootroot /* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test pthread_barrier_t BAR */ #include pthread_barrier_t dummy; posixtestsuite/conformance/definitions/pthread_h/7-1.c0100644000000000000000000000073507627232442022121 0ustar rootroot /* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test this function is defined: int pthread_equal(pthread_t, pthread_t); */ #include pthread_t a,b; int tmp; void dummy_func () { tmp = pthread_equal(a,b); return; } posixtestsuite/conformance/definitions/pthread_h/assertions.xml0100644000000000000000000001036207606365620024364 0ustar rootroot The pthread.h file exists and can be included. pthread.h header shall define the following symbols PTHREAD_BARRIER_SERIAL_THREAD BAR PTHREAD_CANCEL_ASYNCHRONOUS PTHREAD_CANCEL_ENABLE PTHREAD_CANCEL_DEFERRED PTHREAD_CANCEL_DISABLE PTHREAD_CANCELED PTHREAD_COND_INITIALIZER PTHREAD_CREATE_DETACHED PTHREAD_CREATE_JOINABLE PTHREAD_EXPLICIT_SCHED PTHREAD_INHERIT_SCHED PTHREAD_MUTEX_DEFAULT XSI PTHREAD_MUTEX_ERRORCHECK XSI PTHREAD_MUTEX_INITIALIZER PTHREAD_MUTEX_NORMAL XSI PTHREAD_MUTEX_RECURSIVE XSI PTHREAD_ONCE_INIT PTHREAD_PRIO_INHERIT TPP|TPI PTHREAD_PRIO_NONE TPP|TPI PTHREAD_PRIO_PROTECT TPP|TPI PTHREAD_PROCESS_SHARED PTHREAD_PROCESS_PRIVATE PTHREAD_SCOPE_PROCESS TPS PTHREAD_SCOPE_SYSTEM TPS Type 'pthread_attr_t' shall be defined as described in sys/types.h Type 'pthread_barrier_t' shall be defined as described in sys/types.h Type 'pthread_barrierattr_t' shall be defined as described in sys/types.h Type 'pthread_cond_t' shall be defined as described in sys/types.h Type 'pthread_condattr_t' shall be defined as described in sys/types.h Type 'pthread_key_t' shall be defined as described in sys/types.h Type 'pthread_mutex_t' shall be defined as described in sys/types.h Type 'pthread_mutexattr_t' shall be defined as described in sys/types.h Type 'pthread_once_t' shall be defined as described in sys/types.h Type 'pthread_rwlock_t' shall be defined as described in sys/types.h Type 'pthread_rwlockattr_t' shall be defined as described in sys/types.h Type 'pthread_spinlock_t' shall be defined as described in sys/types.h Type 'pthread_t' shall be defined as described in sys/types.h This function is defined: pthread_create(pthread_t *restrict, const pthread_attr_t *restrict, void *(*)(void *), void *restrict); This function is defined: void pthread_exit(void *); This function is defined: pthread_t pthread_self(void); This function is defined: int pthread_equal(pthread_t, pthread_t); This function is defined: int pthread_join(pthread_t, void **); This function is defined: int pthread_detach(pthread_t); This function is defined: int pthread_attr_init(pthread_attr_t *); This function is defined: int pthread_attr_destroy(pthread_attr_t *); This function is defined: int pthread_attr_getdetachstate(const pthread_attr_t *, int *); This function is defined: int pthread_attr_setdetachstate(pthread_attr_t *, int); This function is defined: int pthread_mutex_init(pthread_mutex_t *restrict, const pthread_mutexattr_t *restrict); This function is defined: int pthread_mutex_destroy(pthread_mutex_t *); This function is defined: int pthread_mutex_lock(pthread_mutex_t *); This function is defined: int pthread_mutex_trylock(pthread_mutex_t *); This function is defined: int pthread_mutex_unlock(pthread_mutex_t *); This function is defined: int pthread_mutexattr_init(pthread_mutexattr_t *); This function is defined: int pthread_mutexattr_destroy(pthread_mutexattr_t *); posixtestsuite/conformance/definitions/pthread_h/coverage.txt0100644000000000000000000000077207606365621024011 0ustar rootrootThis document defines the coverage for conformance/definitions/pthread_h testing Assertion # Covered? Notes 1 YES 2 YES The symbols with tags associated with them usually fail on my implementaion of linux (e.g. BAR, XSI, etc.) 3 YES #2,3,10,11,12 fail on my implemention of linux #2 and 3 with BAR tag, #12 with SPI tag, and #11 and 12 with no tag. 4 YES 5 YES 6 YES 7 YES 8 YES 9 YES 10 YES 11 YES 12 YES 13 YES 14 YES 15 YES 16 YES 17 YES 18 YES 19 YES 20 YES posixtestsuite/conformance/definitions/pthread_h/3-3.c0100644000000000000000000000057307605127533022117 0ustar rootroot /* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test pthread_barrierattr_t BAR */ #include pthread_barrierattr_t dummy; posixtestsuite/conformance/definitions/pthread_h/8-1.c0100644000000000000000000000071307605434236022117 0ustar rootroot /* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test this function is defined: int pthread_join(pthread_t, void **); */ #include pthread_t a; void dummy_func () { pthread_join(a,NULL); return; } posixtestsuite/conformance/definitions/pthread_h/10.c0100644000000000000000000000072407605434236022034 0ustar rootroot /* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test this function is defined: int pthread_attr_init(pthread_attr_t *); */ #include pthread_attr_t a; void dummy_func () { pthread_attr_init(&a); return; } posixtestsuite/conformance/definitions/pthread_h/3-4.c0100644000000000000000000000055007605127533022113 0ustar rootroot /* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test pthread_cond_t */ #include pthread_cond_t dummy; posixtestsuite/conformance/definitions/pthread_h/16-1.c0100644000000000000000000000073207606365617022206 0ustar rootroot /* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test this function is defined: int pthread_mutex_lock(pthread_mutex_t *); */ #include pthread_mutex_t a; void dummy_func () { pthread_mutex_lock(&a); return; } posixtestsuite/conformance/definitions/pthread_h/3-7.c0100644000000000000000000000055207605127533022120 0ustar rootroot /* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test pthread_mutex_t */ #include pthread_mutex_t dummy; posixtestsuite/conformance/definitions/pthread_h/2-1.c0100644000000000000000000000274607605127431022115 0ustar rootroot /* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test the following symbols are defined by pthread.h */ #include #ifndef PTHREAD_CANCEL_ASYNCHRONOUS #error PTHREAD_CANCEL_ASYNCHRONOUS not defined #endif #ifndef PTHREAD_CANCEL_ENABLE #error PTHREAD_CANCEL_ENABLE not defined #endif #ifndef PTHREAD_CANCEL_DEFERRED #error PTHREAD_CANCEL_DEFERRED not defined #endif #ifndef PTHREAD_CANCEL_DISABLE #error PTHREAD_CANCEL_DISABLE not defined #endif #ifndef PTHREAD_CANCELED #error PTHREAD_CANCELED not defined #endif #ifndef PTHREAD_COND_INITIALIZER #error PTHREAD_COND_INTIALIZER not defined #endif #ifndef PTHREAD_CREATE_DETACHED #error PTHREAD_CREATE_DETACHED not defined #endif #ifndef PTHREAD_CREATE_JOINABLE #error PTHREAD_CREATE_JOINABLE not defined #endif #ifndef PTHREAD_EXPLICIT_SCHED #error PTHREAD_EXPLICIT_SCHED not defined #endif #ifndef PTHREAD_INHERIT_SCHED #error PTHREAD_INHERIT_SCHED not defined #endif #ifndef PTHREAD_MUTEX_INITIALIZER #error PTHREAD_MUTEX_INITIALIZED not defined #endif #ifndef PTHREAD_ONCE_INIT #error PTHREAD_ONCE_INIT not defined #endif #ifndef PTHREAD_PROCESS_SHARED #error PTHREAD_PROCESS_SHARED not defined #endif #ifndef PTHREAD_PROCESS_PRIVATE #error PTHREAD_PROCESS_PRIVATE not defined #endif posixtestsuite/conformance/definitions/pthread_h/3-1.c0100644000000000000000000000054607605127533022115 0ustar rootroot /* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test pthread_attr_t */ #include pthread_attr_t dummy; posixtestsuite/conformance/definitions/pthread_h/3-11.c0100644000000000000000000000056407605127533022176 0ustar rootroot /* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test pthread_rwlockattr_t */ #include pthread_rwlockattr_t dummy; posixtestsuite/conformance/definitions/mqueue_h/0040755000000000000000000000000010515625153021314 5ustar rootrootposixtestsuite/conformance/definitions/mqueue_h/5-1.c0100644000000000000000000000044310175473542021765 0ustar rootroot/* Test for the existance and valid prototype of the mq_open function as specified on line 9687 of the Base Definitions document */ #include #include "posixtest.h" #include int main() { fprintf(stderr, "Test not implemented!\n"); return PTS_UNTESTED; } posixtestsuite/conformance/definitions/mqueue_h/4-1.c0100644000000000000000000000044110175473542021762 0ustar rootroot#include #include "posixtest.h" #include /* Test for the existance and valid prototype of the mq_notify function as specified on line 9686 of the Base Definitions document */ int main() { fprintf(stderr, "Test not implemented!\n"); return PTS_UNTESTED; } posixtestsuite/conformance/definitions/mqueue_h/1-1.c0100644000000000000000000000043210175473542021757 0ustar rootroot/* Test for the existance and valid format of the mq_attr structure as specified on line 9678 of the Base Definitions document */ #include #include "posixtest.h" #include int main() { fprintf(stderr, "Not Implemented!\n"); return PTS_UNTESTED; } posixtestsuite/conformance/definitions/mqueue_h/9-1.c0100644000000000000000000000046210175473542021772 0ustar rootroot/* Test for the existance and valid prototype of the mq_timedreceive function as specified on line 9692 of the Base Definitions document */ #include #include "posixtest.h" #include int main() { fprintf(stderr, "Test not implemented!\n"); return PTS_UNTESTED; } posixtestsuite/conformance/definitions/mqueue_h/11-1.c0100644000000000000000000000043710175473542022045 0ustar rootroot/* Test for the existance and valid prototype of the mq_unlink function as specified on line 9696 of the Base Definitions document */ #include #include "posixtest.h" #include int main() { fprintf(stderr, "Test not implemented!\n"); return PTS_UNTESTED; } posixtestsuite/conformance/definitions/mqueue_h/6-1.c0100644000000000000000000000044610175473542021771 0ustar rootroot/* Test for the existance and valid prototype of the mq_receive function as specified on line 9688 of the Base Definitions document */ #include #include "posixtest.h" #include int main() { fprintf(stderr, "Test not implemented!\n"); return PTS_UNTESTED; } posixtestsuite/conformance/definitions/mqueue_h/10-1.c0100644000000000000000000000045010175473542022037 0ustar rootroot/* Test for the existance and valid prototype of the mq_timedsend function as specified on line 9694 of the Base Definitions document */ #include #include "posixtest.h" #include int main() { fprintf(stderr, "Test not implemented!\n"); return PTS_UNTESTED; } posixtestsuite/conformance/definitions/mqueue_h/7-1.c0100644000000000000000000000044310175473542021767 0ustar rootroot/* Test for the existance and valid prototype of the mq_send function as specified on line 9689 of the Base Definitions document */ #include #include "posixtest.h" #include int main() { fprintf(stderr, "Test not implemented!\n"); return PTS_UNTESTED; } posixtestsuite/conformance/definitions/mqueue_h/assertions.xml0100644000000000000000000000164107555101205024224 0ustar rootroot A valid mq_attr structure is defined. A valid mq_close function is defined. A valid mq_getattr function is defined. A valid mq_notify function is defined. A valid mq_open function is defined. A valid mq_receive function is defined. A valid mq_send function is defined. A valid mq_setattr function is defined. A valid mq_timedreceive function is defined. A valid mq_timedsend function is defined. posixtestsuite/conformance/definitions/mqueue_h/8-1.c0100644000000000000000000000044710175473542021774 0ustar rootroot/* Test for the existance and valid prototype of the mq_setattr function as specified on line 9690 of the Base Definitions document */ #include #include "posixtest.h" #include int main() { fprintf(stderr, "Test not implemented!\n"); return PTS_UNTESTED; } posixtestsuite/conformance/definitions/mqueue_h/2-1.c0100644000000000000000000000044510175473542021764 0ustar rootroot/* Test for the existance and valid prototype of the mq_close function as specified on line 9684 of the Base Definitions document */ #include #include "posixtest.h" #include int main() { fprintf(stderr, "Test not implemented!\n"); return PTS_UNTESTED; } posixtestsuite/conformance/definitions/mqueue_h/3-1.c0100644000000000000000000000045210175473542021763 0ustar rootroot#include #include "posixtest.h" #include /* Test for the existance and valid prototype of the mq_getattr function as specified on line 9685 of the Base Definitions document */ int main() { fprintf(stderr, "Test not implemented!\n"); return PTS_UNTESTED; } posixtestsuite/conformance/definitions/sched_h/0040755000000000000000000000000010515625154021102 5ustar rootrootposixtestsuite/conformance/definitions/sched_h/15-1.c0100644000000000000000000000136107643271123021630 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * * Test that the function: * int sched_rr_get_interval(pid_t, struct timespec *); * is declared. */ #include #include #include typedef int (*sched_rr_get_interval_test) (pid_t, struct timespec *); int dummyfcn(void) { sched_rr_get_interval_test dummyvar; dummyvar = sched_rr_get_interval; return 0; } posixtestsuite/conformance/definitions/sched_h/17-1.c0100644000000000000000000000135707643271123021637 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * * Test that the function: * int sched_setscheduler(pid_t, int, const struct sched_param *); * is declared. */ #include #include typedef int (*sched_setscheduler_test) (pid_t, int, const struct sched_param *); int dummyfcn(void) { sched_setscheduler_test dummyvar; dummyvar = sched_setscheduler; return 0; } posixtestsuite/conformance/definitions/sched_h/19-1.c0100644000000000000000000000123007643271123021627 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * * Test that inclusion of sched.h makes visible all symbols in time.h. * * NOTE - THIS TEST CASE IS NOT COMPLETE. NEEDS TO GROW MUCH LARGER * see posixtestsuite / conformance / definitions / signal_h / 50-1.c */ #include struct tm *mytime; posixtestsuite/conformance/definitions/sched_h/4-1.c0100644000000000000000000000174707643271123021556 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * * Test that when _POSIX_THREAD_SPORADIC_SERVER is defined, * sched_param structure includes the following: * int sched_ss_low_priority * struct timespec sched_ss_repl_period * struct timespec sched_ss_init_budget * int sched_ss_max_repl */ #include #include #ifdef _POSIX_THREAD_SPORADIC_SERVER struct sched_param s; int dummyfcn(void) { struct timespec ss_repl_period, ss_init_budget; s.sched_ss_low_priority = 0; ss_repl_period = s.sched_ss_repl_period; ss_init_budget = s.sched_ss_init_budget; s.sched_ss_max_repl = 0; return 0; } #endif posixtestsuite/conformance/definitions/sched_h/14-1.c0100644000000000000000000000125507643271123021631 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * * Test that the function: * int sched_getscheduler(pid_t); * is declared. */ #include #include typedef int (*sched_getscheduler_test) (pid_t); int dummyfcn(void) { sched_getscheduler_test dummyvar; dummyvar = sched_getscheduler; return 0; } posixtestsuite/conformance/definitions/sched_h/18-1.c0100644000000000000000000000117007643271123021631 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * * Test that the function: * int sched_yield(void); * is declared. */ #include typedef int (*sched_yield_test) (void); int dummyfcn(void) { sched_yield_test dummyvar; dummyvar = sched_yield; return 0; } posixtestsuite/conformance/definitions/sched_h/12-1.c0100644000000000000000000000124207643271123021623 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * * Test that the function: * int sched_get_priority_min(int); * is declared. */ #include typedef int (*sched_get_priority_min_test) (int); int dummyfcn(void) { sched_get_priority_min_test dummyvar; dummyvar = sched_get_priority_min; return 0; } posixtestsuite/conformance/definitions/sched_h/1-1.c0100644000000000000000000000076407643271123021551 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * * Test the existence of the sched.h file and that it can be included. */ #include posixtestsuite/conformance/definitions/sched_h/11-1.c0100644000000000000000000000124207643271123021622 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * * Test that the function: * int sched_get_priority_max(int); * is declared. */ #include typedef int (*sched_get_priority_max_test) (int); int dummyfcn(void) { sched_get_priority_max_test dummyvar; dummyvar = sched_get_priority_max; return 0; } posixtestsuite/conformance/definitions/sched_h/8-3.c0100644000000000000000000000105307643271123021552 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * * @pt:SS * @pt:TSP * Test that SCHED_SPORADIC is defined */ #include #ifndef SCHED_SPORADIC #error SCHED_SPORADIC not defined #endif posixtestsuite/conformance/definitions/sched_h/10-1.c0100644000000000000000000000234107643271123021622 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * * The policies symbols shall have unique value * I try to test every symbol in a loop. */ #include #include #include #include #include "posixtest.h" struct unique { int value; char *name; } sym[] = { { SCHED_FIFO, "SCHED_FIFO" }, { SCHED_RR, "SCHED_RR" }, #if defined(_POSIX_SPORADIC_SERVER) || defined(_POSIX_THREAD_SPORADIC_SERVER) { SCHED_SPORADIC,"SCHED_SPORADIC" }, #endif { SCHED_OTHER, "SCHED_OTHER" }, { 0, 0 } }; int main() { struct unique *tst; int i, ret = PTS_PASS; tst = sym; while (tst->name) { for (i = 0; sym[i].name; i++) { if (tst->value == sym[i].value && strcmp(tst->name, sym[i].name)) { printf("%s has a duplicate value with %s\n", tst->name, sym[i].name); ret = PTS_FAIL; } } tst++; } return ret; } posixtestsuite/conformance/definitions/sched_h/13-1.c0100644000000000000000000000131107643271123021621 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * * Test that the function: * int sched_getparam(pid_t, struct sched_param *); * is declared. */ #include #include typedef int (*sched_getparam_test) (pid_t, struct sched_param *); int dummyfcn(void) { sched_getparam_test dummyvar; dummyvar = sched_getparam; return 0; } posixtestsuite/conformance/definitions/sched_h/8-2.c0100644000000000000000000000100407643271123021545 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * * Test that SCHED_RR is defined */ #include #ifndef SCHED_RR #error SCHED_RR not defined #endif posixtestsuite/conformance/definitions/sched_h/assertions.xml0100644000000000000000000000676510504452007024022 0ustar rootroot The sched.h header file exists The sched.h header defines the structure sched_param which includes the following, at a minimum: int sched_priority When _POSIX_SPORADIC_SERVER is defined, the structure sched_param shall also include the following: int sched_ss_low_priority struct timespec sched_ss_repl_period struct timespec sched_ss_init_budget int sched_ss_max_repl When _POSIX_THREAD_SPORADIC_SERVER is defined, the structure sched_param shall also includes the following: int sched_ss_low_priority struct timespec sched_ss_repl_period struct timespec sched_ss_init_budget int sched_ss_max_repl Each process is controlled by an associated scheduling policy and priority Associated with each policy is a priority range Each policy definition specifies the minimum priority range for that policy The symbolic constants below are defining the four standard policies: SCHED_FIFO SCHED_RR SCHED_SPORADIC (SS, TSP) SCHED_OTHER Other policies may be defined by the implementation. The symbolic constants defined below have all distinct values SCHED_FIFO SCHED_RR SCHED_SPORADIC (SS, TSP) SCHED_OTHER This function is defined: int sched_get_priority_max(int); This function is defined: int sched_get_priority_min(int); This function is defined: int sched_getparam(pid_t, struct sched_param *); This function is defined: int sched_getscheduler(pid_t); This function is defined: int sched_rr_get_interval(pid_t, struct timespec *); This function is defined: int sched_setparam(pid_t, const struct sched_param *); This function is defined: int sched_setscheduler(pid_t, int, const struct sched_param *); This function is defined: int sched_yield(void); Inclusion of the sched.h header may make visible all symbols from the time.h header. posixtestsuite/conformance/definitions/sched_h/coverage.txt0100644000000000000000000000130707631607423023440 0ustar rootroot This document explains why certain assertions were not tested. Assertions not listed here should be covered by the tests in this directory. Assertions Tested ? Remarks 1 YES 2 YES 3 YES 4 YES 5 NO implementation defined on where are the scheduling policy and priority stored 6 NO implementation defined on how to get the priority range 7 NO implementation defined on how to get the minimum priority range for a policy 8 YES 9 NO implementation defined on how to get the other policies 10 YES 11 YES 12 YES 13 YES 14 YES 15 YES 16 YES 17 YES 18 YES 19 NO NOT COMPLETE posixtestsuite/conformance/definitions/sched_h/8-1.c0100644000000000000000000000101207643271123021543 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * * Test that SCHED_FIFO is defined */ #include #ifndef SCHED_FIFO #error SCHED_FIFO not defined #endif posixtestsuite/conformance/definitions/sched_h/16-1.c0100644000000000000000000000132507643271123021631 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * * Test that the function: * int sched_setparam(pid_t, const struct sched_param *); * is declared. */ #include #include typedef int (*sched_setparam_test) (pid_t, const struct sched_param *); int dummyfcn(void) { sched_setparam_test dummyvar; dummyvar = sched_setparam; return 0; } posixtestsuite/conformance/definitions/sched_h/8-4.c0100644000000000000000000000101507643271123021551 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * * Test that SCHED_OTHER is defined */ #include #ifndef SCHED_OTHER #error SCHED_OTHER not defined #endif posixtestsuite/conformance/definitions/sched_h/2-1.c0100644000000000000000000000117207643271123021544 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * * Test that sched_param structure is declared and includes at a minimum: * int sched_priority */ #include struct sched_param this_type_should_exist, s; int dummyfcn(void) { s.sched_priority = 0; return 0; } posixtestsuite/conformance/definitions/sched_h/3-1.c0100644000000000000000000000173107643271123021546 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * * Test that when _POSIX_SPORADIC_SERVER is defined, sched_param structure * includes the following: * int sched_ss_low_priority * struct timespec sched_ss_repl_period * struct timespec sched_ss_init_budget * int sched_ss_max_repl */ #include #include #ifdef _POSIX_SPORADIC_SERVER struct sched_param s; int dummyfcn(void) { struct timespec ss_repl_period, ss_init_budget; s.sched_ss_low_priority = 0; ss_repl_period = s.sched_ss_repl_period; ss_init_budget = s.sched_ss_init_budget; s.sched_ss_max_repl = 0; return 0; } #endif posixtestsuite/conformance/definitions/time_h/0040755000000000000000000000000010515625156020754 5ustar rootrootposixtestsuite/conformance/definitions/time_h/33-1.c0100644000000000000000000000120507566255232021504 0ustar rootroot /* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. @pt:TMR Test that the function: int timer_settime(timer_t, int, const struct itimerspec *, struct itimerspec *); is declared. */ #include typedef int (*timer_settime_test)(timer_t, int, const struct itimerspec *, struct itimerspec *); int dummyfcn (void) { timer_settime_test dummyvar; dummyvar = timer_settime; return 0; } posixtestsuite/conformance/definitions/time_h/6-2.c0100644000000000000000000000064607566255232021435 0ustar rootroot /* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. @pt:TMR Test that TIMER_ABSTIME is defined */ #include #ifndef TIMER_ABSTIME #error TIMER_ABSTIME not defined #endif posixtestsuite/conformance/definitions/time_h/15-1.c0100644000000000000000000000111207566255232021501 0ustar rootroot /* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. @pt:TMR Test that the function: int clock_settime(clockid_t, const struct timespec *); is declared. */ #include typedef int (*clock_settime_test)(clockid_t, const struct timespec *); int dummyfcn (void) { clock_settime_test dummyvar; dummyvar = clock_settime; return 0; } posixtestsuite/conformance/definitions/time_h/17-1.c0100644000000000000000000000103607566255232021510 0ustar rootroot /* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. @pt:TSF Test that the function: char *ctime_r(const time_t *, char *); is declared. */ #include typedef char *(*ctime_r_test)(const time_t *, char *); int dummyfcn (void) { ctime_r_test dummyvar; dummyvar = ctime_r; return 0; } posixtestsuite/conformance/definitions/time_h/19-1.c0100644000000000000000000000102407566255232021507 0ustar rootroot /* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. @pt:XSI Test that the function: struct tm *getdate(const char *); is declared. */ #include typedef struct tm *(*getdate_test)(const char *); int dummyfcn (void) { getdate_test dummyvar; dummyvar = getdate; return 0; } posixtestsuite/conformance/definitions/time_h/5-1.c0100644000000000000000000000103007566255232021417 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that itimerspec structure is declared. */ #include struct itimerspec this_type_should_exist, t; int dummyfcn(void) { struct timespec interval; struct timespec value; interval = t.it_interval; value = t.it_value; return 0; } posixtestsuite/conformance/definitions/time_h/34-1.c0100644000000000000000000000074607566255232021516 0ustar rootroot /* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test that the function: void tzset(void); is declared. */ #include typedef void (*tzset_test)(void); int dummyfcn (void) { tzset_test dummyvar; dummyvar = tzset; return 0; } posixtestsuite/conformance/definitions/time_h/7-3.c0100644000000000000000000000055307566255232021434 0ustar rootroot /* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test that time_t is defined. */ #include time_t dummy; posixtestsuite/conformance/definitions/time_h/30-1.c0100644000000000000000000000102107566255232021475 0ustar rootroot /* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. @pt:TMR Test that the function: int timer_delete(timer_t); is declared. */ #include typedef int (*timer_delete_test)(timer_t); int dummyfcn (void) { timer_delete_test dummyvar; dummyvar = timer_delete; return 0; } posixtestsuite/conformance/definitions/time_h/24-1.c0100644000000000000000000000077407566255232021516 0ustar rootroot /* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test that the function: time_t mktime(struct tm *); is declared. */ #include typedef time_t (*mktime_test)(struct tm *); int dummyfcn (void) { mktime_test dummyvar; dummyvar = mktime; return 0; } posixtestsuite/conformance/definitions/time_h/4-1.c0100644000000000000000000000075607566255232021434 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that timespec structure is declared. */ #include struct timespec this_type_should_exist, t; int dummyfcn(void) { time_t sec; long nsec; sec = t.tv_sec; nsec = t.tv_nsec; return 0; } posixtestsuite/conformance/definitions/time_h/22-1.c0100644000000000000000000000102607566255232021503 0ustar rootroot /* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test that the function: struct tm *localtime(const time_t *); is declared. */ #include typedef struct tm *(*localtime_test)(const time_t *); int dummyfcn (void) { localtime_test dummyvar; dummyvar = localtime; return 0; } posixtestsuite/conformance/definitions/time_h/14-1.c0100644000000000000000000000121107566255232021500 0ustar rootroot /* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. @pt:CS Test that the function: int clock_nanosleep(clockid_t, int, const struct timespec *, struct timespec *); is declared. */ #include typedef int (*clock_nanosleep_test)(clockid_t, int, const struct timespec *, struct timespec *); int dummyfcn (void) { clock_nanosleep_test dummyvar; dummyvar = clock_nanosleep; return 0; } posixtestsuite/conformance/definitions/time_h/18-1.c0100644000000000000000000000101207566255232021503 0ustar rootroot /* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test that the function: double difftime(time_t, time_t); is declared. */ #include typedef double (*difftime_test)(time_t, time_t); int dummyfcn (void) { difftime_test dummyvar; dummyvar = difftime; return 0; } posixtestsuite/conformance/definitions/time_h/12-1.c0100644000000000000000000000107207566255232021503 0ustar rootroot /* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. @pt:TMR Test that the function: int clock_getres(clockid_t, struct timespec *); is declared. */ #include typedef int (*clock_getres_test)(clockid_t, struct timespec *); int dummyfcn (void) { clock_getres_test dummyvar; dummyvar = clock_getres; return 0; } posixtestsuite/conformance/definitions/time_h/1-1.c0100644000000000000000000000057707566255232021432 0ustar rootroot /* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test the existence of the time.h file and that it can be included. */ #include posixtestsuite/conformance/definitions/time_h/9-1.c0100644000000000000000000000105407566255232021431 0ustar rootroot /* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. @pt:TSF Test that the function: char *asctime_r(const struct tm *, char *); is declared. */ #include typedef char *(*asctime_r_test)(const struct tm *, char *); int dummyfcn (void) { asctime_r_test dummyvar; dummyvar = asctime_r; return 0; } posixtestsuite/conformance/definitions/time_h/20-1.c0100644000000000000000000000101207566255232021474 0ustar rootroot /* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test that the function: struct tm *gmtime(const time_t *); is declared. */ #include typedef struct tm *(*gmtime_test)(const time_t *); int dummyfcn (void) { gmtime_test dummyvar; dummyvar = gmtime; return 0; } posixtestsuite/conformance/definitions/time_h/29-1.c0100644000000000000000000000112107566255232021506 0ustar rootroot /* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. @pt:TMR Test that the function: int timer_create(clockid_t, struct sigevent *, timer_t *); is declared. */ #include typedef int (*timer_create_test)(clockid_t, struct sigevent *, timer_t *); int dummyfcn (void) { timer_create_test dummyvar; dummyvar = timer_create; return 0; } posixtestsuite/conformance/definitions/time_h/11-1.c0100644000000000000000000000110207566255232021474 0ustar rootroot /* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. @pt:CPT Test that the function: int clock_getcpuclockid(pid_t, clockid_t *); is declared. */ #include typedef int (*clock_getcpuclockid_test)(pid_t, clockid_t *); int dummyfcn (void) { clock_getcpuclockid_test dummyvar; dummyvar = clock_getcpuclockid; return 0; } posixtestsuite/conformance/definitions/time_h/23-1.c0100644000000000000000000000110307566255232021500 0ustar rootroot /* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. @pt:TSF Test that the function: struct tm *localtime_r(const time_t *, struct tm *); is declared. */ #include typedef struct tm *(*localtime_r_test)(const time_t *, struct tm *); int dummyfcn (void) { localtime_r_test dummyvar; dummyvar = localtime_r; return 0; } posixtestsuite/conformance/definitions/time_h/6-1.c0100644000000000000000000000065107566255232021430 0ustar rootroot /* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. @pt:TMR Test that CLOCK_REALTIME is defined */ #include #ifndef CLOCK_REALTIME #error CLOCK_REALTIME not defined #endif posixtestsuite/conformance/definitions/time_h/35-3.c0100644000000000000000000000074210341621706021501 0ustar rootroot /* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. @pt:CX Test that tzname is declared. */ #include #include /* Include for printf */ #include int dummyfcn (void) { printf("%s\n",tzname[0]); return 0; } posixtestsuite/conformance/definitions/time_h/10-1.c0100644000000000000000000000075407566255232021507 0ustar rootroot /* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test that the function: clock_t clock(void); is declared. */ #include typedef clock_t (*clock_test)(void); int dummyfcn (void) { clock_test dummyvar; dummyvar = clock; return 0; } posixtestsuite/conformance/definitions/time_h/28-1.c0100644000000000000000000000075607566255232021522 0ustar rootroot /* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test that the function: time_t time(time_t *); is declared. */ #include typedef time_t (*time_test)(time_t *); int dummyfcn (void) { time_test dummyvar; dummyvar = time; return 0; } posixtestsuite/conformance/definitions/time_h/13-1.c0100644000000000000000000000107607566255232021510 0ustar rootroot /* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. @pt:TMR Test that the function: int clock_gettime(clockid_t, struct timespec *); is declared. */ #include typedef int (*clock_gettime_test)(clockid_t, struct timespec *); int dummyfcn (void) { clock_gettime_test dummyvar; dummyvar = clock_gettime; return 0; } posixtestsuite/conformance/definitions/time_h/3-2.c0100644000000000000000000000063707566255232021432 0ustar rootroot /* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test that CLOCKS_PER_SEC is defined */ #include #ifndef CLOCKS_PER_SEC #error CLOCKS_PER_SEC not defined #endif posixtestsuite/conformance/definitions/time_h/6-3.c0100644000000000000000000000066607566255232021440 0ustar rootroot /* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. @pt:TMR @pt:MON Test that CLOCK_MONOTONIC is defined */ #include #ifndef CLOCK_MONOTONIC #error CLOCK_MONOTONIC not defined #endif posixtestsuite/conformance/definitions/time_h/7-4.c0100644000000000000000000000056107566255232021434 0ustar rootroot /* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test that clockid_t is defined. */ #include clockid_t dummy; posixtestsuite/conformance/definitions/time_h/26-1.c0100644000000000000000000000111407566255232021505 0ustar rootroot /* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test that the function: size_t strftime(char *, size_t, const char *, const struct tm *); is declared. */ #include typedef size_t (*strftime_test)(char *, size_t, const char *, const struct tm *); int dummyfcn (void) { strftime_test dummyvar; dummyvar = strftime; return 0; } posixtestsuite/conformance/definitions/time_h/7-1.c0100644000000000000000000000055507566255232021434 0ustar rootroot /* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test that clock_t is defined. */ #include clock_t dummy; posixtestsuite/conformance/definitions/time_h/assertions.xml0100644000000000000000000001314507566251544023701 0ustar rootroot The time.h file exists. The time.h header declares struct tm with the members below, at a minimum: tm_sec tm_min tm_hour tm_mday tm_mon tm_year tm_wday tm_yday tm_isdst The time.h header defines the symbolic names below: NULL CLOCKS_PER_SEC CLOCK_PROCESS_CPUTIME_ID (TMR,CPT) CLOCK_THREAD_CPUTIME_ID (TMR,TCT) The time.h header declares struct timespec with the members below, at a minimum: time_t tv_sec long tv_nsec The time.h header declares struct itimerspec with the members below, at a minimum: struct timespec it_interval struct timespec it_value The manifest constants below are defined: CLOCK_REALTIME TIMER_ABSTIME CLOCK_MONOTONIC (@pt:MON) sys/types.h shall define clock_t, size_t, time_t, clockid_t (@pt:TMR), and timer_t (@pt:TMR). The function below is defined: char *asctime(const struct tm *); The function below is defined: char *asctime_r(const struct tm *restrict, char *restrict); The function below is defined: clock_t clock(void); The function below is defined: int clock_getcpuclockid(pid_t, clockid_t *); The function below is defined: int clock_getres(clockid_t, struct timespec *); The function below is defined: int clock_gettime(clockid_t, struct timespec *); The function below is defined: int clock_nanosleep(clockid_t, int, const struct timespec *, struct timespec *); The function below is defined: int clock_settime(clockid_t, const struct timespec *); The function below is defined: char *ctime(const time_t *); The function below is defined: char *ctime_r(const time_t *, char *); The function below is defined: double difftime(time_t, time_t); The function below is defined: struct tm *getdate(const char *); The function below is defined: struct tm *gmtime(const time_t *); The function below is defined: struct tm *gmtime_r(const time_t *restrict, struct tm *restrict); The function below is defined: struct tm *localtime(const time_t *); The function below is defined: struct tm *localtime_r(const time_t *restrict, struct tm *restrict); The function below is defined: time_t mktime(struct tm *); The function below is defined: int nanosleep(const struct timespec *, struct timespec *); The function below is defined: size_t strftime(char *restrict, size_t, const char *restrict, const struct tm *restrict); The function below is defined: char *strptime(const char *restrict, const char *restrict, struct tm *restrict); The function below is defined: time_t time(time_t *); The function below is defined: int timer_create(clockid_t, struct sigevent *restrict, timer_t *restrict); The function below is defined: int timer_delete(timer_t); The function below is defined: int timer_gettime(timer_t, struct itimerspec *); The function below is defined: int timer_getoverrun(timer_t); The function below is defined: int timer_settime(timer_t, int, const struct itimerspec *restrict, struct itimerspec *restrict); The function below is defined: void tzset(void); The variables below are declared: extern int daylight; (@pt:XSI) extern long timezone; extern char *tzname[]; (@pt:CX) posixtestsuite/conformance/definitions/time_h/21-1.c0100644000000000000000000000106707566255232021507 0ustar rootroot /* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. @pt:TSF Test that the function: struct tm *gmtime_r(const time_t *, struct tm *); is declared. */ #include typedef struct tm *(*gmtime_r_test)(const time_t *, struct tm *); int dummyfcn (void) { gmtime_r_test dummyvar; dummyvar = gmtime_r; return 0; } posixtestsuite/conformance/definitions/time_h/25-1.c0100644000000000000000000000111307566255232021503 0ustar rootroot /* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. @pt:TMR Test that the function: int nanosleep(const struct timespec *, struct timespec *); is declared. */ #include typedef int (*nanosleep_test)(const struct timespec *, struct timespec *); int dummyfcn (void) { nanosleep_test dummyvar; dummyvar = nanosleep; return 0; } posixtestsuite/conformance/definitions/time_h/coverage.txt0100644000000000000000000000145407561544732023320 0ustar rootrootThis document defines the coverage for conformance/definitions/time_h testing Assertion # Covered? 1 YES 2 YES 3 YES 4 YES - Assigns uninitialized values, but works. 5 YES - Assigns uninitialized values, but works. 6 YES - 6.3 fails on current test impl. b/c no MON implemented 7 YES - 7.1 fails on my impl -- BUG? 8 YES 9 YES 10 YES 11 YES - Fails on current test impl b/c no CPT implemented 12 YES 13 YES 14 YES - Fails on current test impl b/c no CS implemented 15 YES 16 YES 17 YES 18 YES 19 YES - Fails on current test impl b/c no XSI implemented 20 YES 21 YES 22 YES 23 YES 24 YES 25 YES 26 YES 27 YES - Fails on current test impl b/c no XSI implemented 28 YES 29 YES 30 YES 31 YES 32 YES 33 YES 34 YES 35 YES - Not 100% sure that I declared the vars correctly in 35-3 posixtestsuite/conformance/definitions/time_h/3-3.c0100644000000000000000000000072107566255232021425 0ustar rootroot /* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. @pt:TMR @pt:CPT Test that CLOCK_PROCESS_CPUTIME_ID is defined */ #include #ifndef CLOCK_PROCESS_CPUTIME_ID #error CLOCK_PROCESS_CPUTIME_ID not defined #endif posixtestsuite/conformance/definitions/time_h/8-1.c0100644000000000000000000000101207566255232021422 0ustar rootroot /* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test that the function: char *asctime(const struct tm *); is declared. */ #include typedef char *(*asctime_test)(const struct tm *); int dummyfcn (void) { asctime_test dummyvar; dummyvar = asctime; return 0; } posixtestsuite/conformance/definitions/time_h/35-2.c0100644000000000000000000000063707566255232021517 0ustar rootroot /* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test that timezone is declared. */ #include int dummyfcn (void) { long dummy; dummy = timezone; return 0; } posixtestsuite/conformance/definitions/time_h/7-5.c0100644000000000000000000000055507566255232021440 0ustar rootroot /* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test that timer_t is defined. */ #include timer_t dummy; posixtestsuite/conformance/definitions/time_h/3-4.c0100644000000000000000000000071607566255232021432 0ustar rootroot /* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. @pt:TMR @pt:TCT Test that CLOCK_THREAD_CPUTIME_ID is defined */ #include #ifndef CLOCK_THREAD_CPUTIME_ID #error CLOCK_THREAD_CPUTIME_ID not defined #endif posixtestsuite/conformance/definitions/time_h/7-2.c0100644000000000000000000000055307566255232021433 0ustar rootroot /* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test that size_t is defined. */ #include size_t dummy; posixtestsuite/conformance/definitions/time_h/35-1.c0100644000000000000000000000065107566255232021512 0ustar rootroot /* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. @pt:XSI Test that daylight is declared. */ #include int dummyfcn (void) { int dummy; dummy = daylight; return 0; } posixtestsuite/conformance/definitions/time_h/16-1.c0100644000000000000000000000077507566255232021520 0ustar rootroot /* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test that the function: char *ctime(const time_t *); is declared. */ #include typedef char *(*ctime_test)(const time_t *); int dummyfcn (void) { ctime_test dummyvar; dummyvar = ctime; return 0; } posixtestsuite/conformance/definitions/time_h/32-1.c0100644000000000000000000000104107566255232021501 0ustar rootroot /* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. @pt:TMR Test that the function: int timer_getoverrun(timer_t); is declared. */ #include typedef int (*timer_getoverrun_test)(timer_t); int dummyfcn (void) { timer_getoverrun_test dummyvar; dummyvar = timer_getoverrun; return 0; } posixtestsuite/conformance/definitions/time_h/2-1.c0100644000000000000000000000112707566255232021423 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that tm structure is declared. */ #include struct tm this_type_should_exist, t; int dummyfcn(void) { int week, year, dst; t.tm_sec = 0; t.tm_min = 10; t.tm_hour = 17; t.tm_mday = 1; t.tm_mon = 11; t.tm_year = 102; week = t.tm_wday; year = t.tm_yday; dst = t.tm_isdst; return 0; } posixtestsuite/conformance/definitions/time_h/31-1.c0100644000000000000000000000107707566255232021511 0ustar rootroot /* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. @pt:TMR Test that the function: int timer_gettime(timer_t, struct itimerspec *); is declared. */ #include typedef int (*timer_gettime_test)(timer_t, struct itimerspec *); int dummyfcn (void) { timer_gettime_test dummyvar; dummyvar = timer_gettime; return 0; } posixtestsuite/conformance/definitions/time_h/3-1.c0100644000000000000000000000060107566255232021420 0ustar rootroot /* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test that NULL is defined */ #include #ifndef NULL #error NULL not defined #endif posixtestsuite/conformance/definitions/time_h/27-1.c0100644000000000000000000000110507566255232021506 0ustar rootroot /* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. @pt:XSI Test that the function: char *strptime(const char *, const char *, struct tm *); is declared. */ #include typedef char *(*strptime_test)(const char *, const char *, struct tm *); int dummyfcn (void) { strptime_test dummyvar; dummyvar = strptime; return 0; } posixtestsuite/conformance/interfaces/0040755000000000000000000000000010515625271017315 5ustar rootrootposixtestsuite/conformance/interfaces/mq_getattr/0040755000000000000000000000000010515625170021462 5ustar rootrootposixtestsuite/conformance/interfaces/mq_getattr/2-2.c0100644000000000000000000000377310014305271022124 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: crystal.xiong REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * mq_getattr() test plan: * mq_getattr gets mq_flags value, which is set by mq_setattr. * * 2/17/2004 call mq_close and mq_unlink before exit to release mq * resources * */ #include #include #include #include #include #include #include #include "posixtest.h" #define TEST "2-2" #define FUNCTION "mq_getattr" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " #define NAMESIZE 50 #define MQFLAGS O_NONBLOCK int main() { char mqname[NAMESIZE]; mqd_t mqdes; struct mq_attr mqstat, nmqstat; int unresolved = 0; int failure = 0; sprintf(mqname, "/" FUNCTION "_" TEST "_%d", getpid()); mqdes = mq_open(mqname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, NULL); if (mqdes == (mqd_t)-1) { perror(ERROR_PREFIX "mq_open()"); return PTS_UNRESOLVED; } memset(&mqstat,0,sizeof(mqstat)); memset(&nmqstat,0,sizeof(nmqstat)); if (mq_getattr(mqdes, &mqstat) == -1) { perror(ERROR_PREFIX "mq_getattr"); unresolved = 1; } mqstat.mq_flags |= MQFLAGS; if (mq_setattr(mqdes, &mqstat, NULL) == -1) { perror(ERROR_PREFIX "mq_setattr"); failure = 1; } if (mq_getattr(mqdes, &nmqstat) != 0) { perror(ERROR_PREFIX "mq_getattr"); unresolved = 1; } if (nmqstat.mq_flags != mqstat.mq_flags) { printf("FAIL: mq_getattr didn't get the correct mq_flags " "set by mq_setattr \n"); failure = 1; } mq_close(mqdes); mq_unlink(mqname); if (failure == 1) { printf("Test FAILED\n"); return PTS_FAIL; } if (unresolved == 1) { printf("Test UNRESOLVED\n"); return PTS_UNRESOLVED; } printf("Test PASSED \n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/mq_getattr/speculative/0040755000000000000000000000000010515625170024006 5ustar rootrootposixtestsuite/conformance/interfaces/mq_getattr/speculative/7-1.c0100644000000000000000000000277007663234204024465 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: crystal.xiong REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * mq_getattr() test plan: * Test if mqdes argument is not a valid message queue descriptor, * mq_getattr() function may fail with EBADF, and the function will * return a value of -1. * Since this is a "may" assertion either option will be a pass. */ #include #include #include #include #include #include #include #include #include "posixtest.h" #define TEST "7-1" #define FUNCTION "mq_getattr" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " #define NAMESIZE 50 int main() { char mqname[NAMESIZE]; mqd_t mqdes; struct mq_attr mqstat; sprintf(mqname, "/" FUNCTION "_" TEST "_%d", getpid()); mqdes = mq_open(mqname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, 0); if (mqdes == (mqd_t)-1) { perror(ERROR_PREFIX "mq_open()"); return PTS_UNRESOLVED; } mqdes = mqdes + 1; memset(&mqstat,0,sizeof(mqstat)); if (mq_getattr(mqdes, &mqstat) == -1) { if (EBADF != errno) { printf("fcn returned -1, but errno != EBADF \n"); printf("Test FAILED \n"); return PTS_FAIL; } } else { printf("fcn returned success\n"); return PTS_PASS; } printf("fcn returned -1 and errno == EBADF\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/mq_getattr/4-1.c0100644000000000000000000000377210014305315022123 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: crystal.xiong REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * mq_getattr test plan: * mq_getattr gets mq_curmsgs value, which will be returned as * the number of the message currently on the queue. * */ #include #include #include #include #include #include #include #include "posixtest.h" #define TEST "4-1" #define FUNCTION "mq_getattr" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " #define NAMESIZE 50 #define MSG_NUM 5 #define MSGSIZE 50 #define MAXMSG 40 int main() { char mqname[NAMESIZE]; const char *msgptr = "test message"; mqd_t mqdes; struct mq_attr mqstat; int i; int unresolved=0, failure=0; sprintf(mqname, "/" FUNCTION "_" TEST "_%d", getpid()); memset(&mqstat,0,sizeof(mqstat)); mqstat.mq_msgsize = MSGSIZE; mqstat.mq_maxmsg = MAXMSG; mqdes = mq_open(mqname, O_CREAT |O_RDWR, S_IRUSR | S_IWUSR, &mqstat); if (mqdes == (mqd_t)-1) { perror(ERROR_PREFIX "mq_open()"); return PTS_UNRESOLVED; } for (i = 0; i < MSG_NUM; i++) { if (mq_send(mqdes, msgptr, strlen(msgptr), 1) == -1) { perror(ERROR_PREFIX "mq_send()"); unresolved = 1; } } memset(&mqstat,0,sizeof(mqstat)); if (mq_getattr(mqdes, &mqstat) != 0) { perror(ERROR_PREFIX "mq_getattr"); unresolved = 1; } else { if (mqstat.mq_curmsgs != MSG_NUM) { printf("mq_getattr didn't get the correct " "mq_curmsgs \n"); failure = 1; } } mq_close(mqdes); mq_unlink(mqname); if (failure==1) { printf("Test FAILED\n"); return PTS_FAIL; } if (unresolved==1) { printf("Test UNRESOLVED\n"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/mq_getattr/1-1.sh0100755000000000000000000000102207634242012022305 0ustar rootroot#!/bin/sh # Copyright (c) 2003, Intel Corporation. All rights reserved. # Created by: crystal.xiong REMOVE-THIS AT intel DOT com # This file is licensed under the GPL license. For the full content # of this license, see the COPYING file at the top level of this # source tree. # mq_getattr will get status infomation and attributes of message queue. # The result will return in mqstat argument. # This is tested implicitly via assertion 2,3,4. echo "Tested implicitly via assertion 2,3,4. See output for status" exit 0 posixtestsuite/conformance/interfaces/mq_getattr/assertions.xml0100644000000000000000000000217407663233621024405 0ustar rootroot mq_getattr will get status infomation and attributes of message queue. The result will return in mqstat argument. mq_getattr gets mq_flags value, which is set when message queue was opened and can be modified by mq_setattr calls. mq_getattr gets mq_maxmsg, mq_msgsize value, which will be returned when message queue was opened. mq_getattr gets mq_curmsgs value, which will be returned as the number of the message currently on the queue. mq_getattr will return 0 on success. mq_getattr shall return -1 and set errno to indicate the error. mq_getattr may fail with EBADF if the mqdes is not a valid message message queue descriptor. posixtestsuite/conformance/interfaces/mq_getattr/coverage.txt0100644000000000000000000000020407634246357024025 0ustar rootrootThis document defines the coverage for the mq_getattr function: Assertion Tested? 1 YES 2 YES 3 YES 4 YES 5 YES 6 YES 7 YES posixtestsuite/conformance/interfaces/mq_getattr/5-1.sh0100755000000000000000000000067707634246005022336 0ustar rootroot#!/bin/sh # Copyright (c) 2003, Intel Corporation. All rights reserved. # Created by: crystal.xiong REMOVE-THIS AT intel DOT com # This file is licensed under the GPL license. For the full content # of this license, see the COPYING file at the top level of this # source tree. # mq_getattr() return 0 on success. # This is tested implicitly via assertion 2,3,4. echo "Tested implicitly via assertion 2,3,4. See output for status" exit 0 posixtestsuite/conformance/interfaces/mq_getattr/2-1.c0100644000000000000000000000411610035502476022124 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: crystal.xiong REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * mq_getattr() test plan: * mq_getattr gets mq_flags which is set when message queue * was opened. * * 3/27/2003 Fixed a bug pointed out by Krzysztof Benedyczak. * mq_getattr returns ALL flags not only those set by * mq_setattr. So there should not be setting using * "mqstat.mq_flags == MQFLAGS, so change to * "!(mqstat.mq_flags & MQFLAGS)". * * 2/17/2004 call mq_close and mq_unlink before exit to release mq * resources */ #include #include #include #include #include #include #include #include "posixtest.h" #define TEST "2-1" #define FUNCTION "mq_getattr" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " #define NAMESIZE 50 #define MQFLAGS O_NONBLOCK int main() { char mqname[NAMESIZE]; mqd_t mqdes; struct mq_attr mqstat; int unresolved = 0; int failure = 0; sprintf(mqname, "/" FUNCTION "_" TEST "_%d", getpid()); mqdes = mq_open(mqname, O_CREAT | O_RDWR | MQFLAGS, S_IRUSR | S_IWUSR, NULL); if (mqdes == (mqd_t)-1) { perror(ERROR_PREFIX "mq_open()"); return PTS_UNRESOLVED; } memset(&mqstat,0,sizeof(mqstat)); if (mq_getattr(mqdes, &mqstat) != 0) { perror(ERROR_PREFIX "mq_getattr"); unresolved = 1; } mq_close(mqdes); if (mq_unlink(mqname) != 0) { perror(ERROR_PREFIX "mq_unlink()"); return PTS_UNRESOLVED; } if (!(mqstat.mq_flags & MQFLAGS)) { printf("FAIL: mq_getattr didn't get the correct " "mq_flags set by mq_open\n"); failure = 1; } if (failure == 1) { printf("Test FAILED\n"); return PTS_FAIL; } if (unresolved == 1) { printf("Test UNRESOLVED\n"); return PTS_UNRESOLVED; } printf("Test PASSED \n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/mq_getattr/6-1.sh0100755000000000000000000000077407634246061022337 0ustar rootroot#!/bin/sh # Copyright (c) 2003, Intel Corporation. All rights reserved. # Created by: crystal.xiong REMOVE-THIS AT intel DOT com # This file is licensed under the GPL license. For the full content # of this license, see the COPYING file at the top level of this # source tree. # If mq_getattr() is not sucessful, the function will return -1 # and set errno to indicate the error. # This is tested implicitly via assertion 7. echo "Tested implicitly via assertion 7. See output for status" exit 0 posixtestsuite/conformance/interfaces/mq_getattr/3-1.c0100644000000000000000000000367010014305271022120 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: crystal.xiong REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * mq_getattr() test plan: * mq_getattr gets mq_maxmsg, mq_msgsize, which are set when message queue * was opened. * * 2/17/2004 call mq_close and mq_unlink before exit to release mq * resources * */ #include #include #include #include #include #include #include #include "posixtest.h" #define TEST "3-1" #define FUNCTION "mq_getattr" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " #define NAMESIZE 50 #define MAXMSG 40 #define MSGSIZE 50 int main() { char mqname[NAMESIZE]; mqd_t mqdes; struct mq_attr mqstat, nmqstat; int unresolved = 0; int failure = 0; sprintf(mqname, "/" FUNCTION "_" TEST "_%d", getpid()); memset(&mqstat,0,sizeof(mqstat)); mqstat.mq_msgsize = MSGSIZE; mqstat.mq_maxmsg = MAXMSG; mqdes = mq_open(mqname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, &mqstat); if (mqdes == (mqd_t)-1) { perror(ERROR_PREFIX "mq_open()"); return PTS_UNRESOLVED; } memset(&nmqstat,0,sizeof(nmqstat)); if (mq_getattr(mqdes, &nmqstat) != 0) { perror(ERROR_PREFIX "mq_getattr"); unresolved = 1; } if ((mqstat.mq_maxmsg != nmqstat.mq_maxmsg) || (mqstat.mq_msgsize != nmqstat.mq_msgsize)) { printf("FAIL: mq_getattr didn't get the correct mq_maxmsg, " "mq_msgsize set by mq_open\n"); failure = 1; } mq_close(mqdes); mq_unlink(mqname); if (failure == 1) { printf("Test FAILED\n"); return PTS_FAIL; } if (unresolved == 1) { printf("Test UNRESOLVED\n"); return PTS_UNRESOLVED; } printf("Test PASSED \n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_barrierattr_setpshared/0040755000000000000000000000000010515625201025560 5ustar rootrootposixtestsuite/conformance/interfaces/pthread_barrierattr_setpshared/3-1.sh0100755000000000000000000000074210033204322026407 0ustar rootroot#!/bin/sh # Copyright (c) 2002, Intel Corporation. All rights reserved. # This file is licensed under the GPL license. For the full content # of this license, see the COPYING file at the top level of this # source tree. # Upon successful completion, these functions shall return zero; # otherwise, an error number shall be returned to indicate the error. # This is tested implicitly via assertion 1. echo "Tested implicitly via assertion 1. See output for status" exit 0 posixtestsuite/conformance/interfaces/pthread_barrierattr_setpshared/1-1.c0100644000000000000000000000406207705336100026225 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * * pthread_barrierattr_setpshared() * * The pthread_barrierattr_setpshared( ) function shall * set the process-shared attribute in an initialized attributes object referenced by attr. */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include "posixtest.h" int main() { /* Make sure there is process-shared capability. */ #ifndef PTHREAD_PROCESS_SHARED fprintf(stderr,"process-shared attribute is not available for testing\n"); return PTS_UNSUPPORTED; #endif pthread_barrierattr_t ba; int pshared = PTHREAD_PROCESS_SHARED; int pshared2 = PTHREAD_PROCESS_PRIVATE; int rc; /* Initialize a barrier attributes object */ if(pthread_barrierattr_init(&ba) != 0) { printf("Error at pthread_barrierattr_init()\n"); return PTS_UNRESOLVED; } /* Set pshared to PTHREAD_PROCESS_SHARED */ rc = pthread_barrierattr_setpshared(&ba, pshared); if(rc != 0) { printf("Test FAILED: Error at pthread_barrierattr_setpshared()\n"); return PTS_FAIL; } if(pthread_barrierattr_getpshared(&ba, &pshared) != 0) { printf("Error at pthread_barrierattr_getpshared()\n"); return PTS_FAIL; } if(pshared != PTHREAD_PROCESS_SHARED) { printf("Test FAILED: Got error shared attribute value %d\n", pshared); return PTS_FAIL; } /* Set pshared to PTHREAD_PROCESS_SHARED */ rc = pthread_barrierattr_setpshared(&ba, pshared2); if(rc != 0) { printf("Test FAILED: Error at pthread_barrierattr_setpshared()\n"); return PTS_FAIL; } if(pthread_barrierattr_getpshared(&ba, &pshared2) != 0) { printf("Error at pthread_barrierattr_getpshared()\n"); return PTS_FAIL; } if(pshared2 != PTHREAD_PROCESS_PRIVATE) { printf("Test FAILED: Got error shared attribute value %d\n", pshared); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_barrierattr_setpshared/assertions.xml0100644000000000000000000000144607705336100030502 0ustar rootroot The pthread_barrierattr_setpshared( ) function shall set the process-shared attribute in an initialized attributes object referenced by attr. The pthread_barrierattr_setpshared( ) function may fail if: [EINVAL] The new value specified for the process-shared attribute is not one of the legal values PTHREAD_PROCESS_SHARED or PTHREAD_PROCESS_PRIVATE. These functions shall not return an error code of [EINTR]. If successful, the pthread_barrierattr_setpshared( ) function shall return zero; otherwise, an error number shall be returned to indicate the error. posixtestsuite/conformance/interfaces/pthread_barrierattr_setpshared/coverage.txt0100644000000000000000000000020607705336100030113 0ustar rootrootThis document defines the coverage for the pthread_barrierattr_setpshared() function: Assertion Tested? 1 YES 2 YES 3 YES NOTE: posixtestsuite/conformance/interfaces/pthread_barrierattr_setpshared/2-1.c0100644000000000000000000000306107705336100026224 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * * pthread_barrierattr_setpshared() * * The pthread_barrierattr_setpshared( ) function may fail if: * [EINVAL] The new value specified for the process-shared attribute is not one of * the legal values PTHREAD_PROCESS_SHARED or PTHREAD_PROCESS_PRIVATE. * This case will always pass */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include "posixtest.h" int main() { /* Make sure there is process-shared capability. */ #ifndef PTHREAD_PROCESS_SHARED fprintf(stderr,"process-shared attribute is not available for testing\n"); return PTS_UNSUPPORTED; #endif pthread_barrierattr_t ba; int pshared = PTHREAD_PROCESS_PRIVATE + 1; int rc; /* Set pshared to an invalid value */ if(pshared == PTHREAD_PROCESS_SHARED) { pshared += 1; } /* Initialize a barrier attributes object */ if(pthread_barrierattr_init(&ba) != 0) { printf("Error at pthread_barrierattr_init()\n"); return PTS_UNRESOLVED; } /* Set process-shared attribute to an invalid value */ rc = pthread_barrierattr_setpshared(&ba, pshared); if(rc == EINVAL) printf("Test PASSED\n"); else { printf("Get return code: %d, %s\n", rc, strerror(rc)); printf("Test PASSED: Note*: Expected EINVAL, but standard says 'may' fail.\n"); } return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_sigmask/0040755000000000000000000000000010515625227022463 5ustar rootrootposixtestsuite/conformance/interfaces/pthread_sigmask/15-1.c0100644000000000000000000000126507636242421023214 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: salwan.searty REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Simply, if pthread_sigmask returns a 0 here, test passes. */ #define _XOPEN_SOURCE 600 #include #include #include "posixtest.h" int main() { sigset_t set; sigaddset (&set, SIGABRT); if (pthread_sigmask(SIG_SETMASK, &set, NULL) != 0) { perror("pthread_sigmask failed -- returned -- test aborted"); return PTS_FAIL; } printf("pthread_sigmask passed\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_sigmask/5-1.c0100644000000000000000000000737310204075240023125 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: salwan.searty REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. The resulting set shall be the the signal set pointed to by set Steps: 1. Have main create a new thread and wait for its termination. 2. Inside the new thread, set up the signal mask such that it contains only SIGABRT (by passing SIG_SETMASK value to pthread_sigmask) 4. Raise SIGABRT, and make sure that the handler associated with it wasn't executed, otherwise fail. 5. Also make sure that SIGABRT is pending, otherwise fail. * patch * 5b. Change mask to SIGUSR1 and check that the handler is called. This means that SIG_SETMASK removed the old signal from the set. * /patch * 6. Pass one of three return codes to the main() function: - A value of -1 if SIGABRT wasn't found pending or causes the handler to be executed. - A value of 0 if SIGABRT was in fact pending and the handler wasn't executed. - A value of 1 incase of any UNRESOLVED situation such as an unexpected function failure. */ #include #include #include #include "posixtest.h" int handler_called = 0; void handler( int signo ) { handler_called = 1; } void *a_thread_func() { struct sigaction act; sigset_t blocked_set, pending_set; sigemptyset( &blocked_set ); sigaddset( &blocked_set, SIGABRT ); act.sa_handler = handler; act.sa_flags = 0; sigemptyset( &act.sa_mask ); if ( sigaction( SIGABRT, &act, 0 ) == -1 ) { perror( "Unexpected error while attempting to setup test " "pre-conditions" ); pthread_exit( ( void* ) 1 ); } if ( pthread_sigmask( SIG_SETMASK, &blocked_set, NULL ) == -1 ) { perror( "Unexpected error while attempting to use pthread_sigmask.\n" ); pthread_exit( ( void* ) 1 ); } if ( raise( SIGABRT ) == -1 ) { perror( "Unexpected error while attempting to setup test " "pre-conditions" ); pthread_exit( ( void* ) 1 ); } if ( handler_called ) { printf( "FAIL: Signal was not blocked\n" ); pthread_exit( ( void* ) - 1 ); } if ( sigpending( &pending_set ) == -1 ) { perror( "Unexpected error while attempting to use sigpending\n" ); pthread_exit( ( void* ) 1 ); } if ( sigismember( &pending_set, SIGABRT ) == -1 ) { perror( "Unexpected error while attempting to use sigismember.\n" ); pthread_exit( ( void* ) - 1 ); } if ( sigismember( &pending_set, SIGABRT ) != 1 ) { perror( "FAIL: sigismember did not return 1\n" ); pthread_exit( ( void* ) 1 ); } sigemptyset( &blocked_set ); sigaddset( &blocked_set, SIGUSR1 ); if ( pthread_sigmask( SIG_SETMASK, &blocked_set, NULL ) == -1 ) { perror( "Unexpected error while attempting to use pthread_sigmask.\n" ); pthread_exit( ( void* ) 1 ); } sched_yield(); if ( !handler_called ) { printf( "FAIL: Old signal was not removed from mask.\n" ); pthread_exit( ( void* ) - 1 ); } pthread_exit( ( void* ) 0 ); return NULL; } int main() { int * thread_return_value; pthread_t new_thread; if ( pthread_create( &new_thread, NULL, a_thread_func, NULL ) != 0 ) { perror( "Error creating new thread\n" ); return PTS_UNRESOLVED; } if ( pthread_join( new_thread, ( void* ) & thread_return_value ) != 0 ) { perror( "Error in pthread_join()\n" ); return PTS_UNRESOLVED; } if ( ( long ) thread_return_value != 0 ) { if ( ( long ) thread_return_value == 1 ) { printf ( "Test UNRESOLVED\n" ); return PTS_UNRESOLVED; } else if ( ( long ) thread_return_value == -1 ) { printf ( "Test FAILED\n" ); return PTS_FAIL; } else { printf ( "Test UNRESOLVED\n" ); return PTS_UNRESOLVED; } } printf( "Test PASSED\n" ); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_sigmask/4-1.c0100644000000000000000000000725407647616561023152 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: salwan.searty REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. The resulting set shall be the union of the current set and the signal set pointed to by set, if the value of the argument how is SIG_BLOCK. Steps: 1. Have main create a new thread and wait for its termination. 2. Inside the new thread, set up the signal mask such that it contains only SIGABRT. 3. Also inside the new thread, using the SIG_BLOCK as the value to pthread_sigmask's first parameter, add SIGALRM. Now both signals should be in the signal mask of the new thread. 4. Raise both signals make sure that the handler associated with these signals wasn't executed. 5. Also make sure that both signals are pending. 6. Pass one of three return codes to the main() function: - A value of -1 if one of the two signals wasn't found pending or causes the handler to be executed. - A value of 0 if both signals were infact pending and the handler wasn't executed. - A value of 1 incase of any UNRESOLVED situation such as an unexpected function failure. */ #include #include #include #include "posixtest.h" int handler_called = 0; void handler(int signo) { handler_called = 1; } void *a_thread_func() { struct sigaction act; sigset_t blocked_set1, blocked_set2, pending_set; sigemptyset(&blocked_set1); sigemptyset(&blocked_set2); sigaddset(&blocked_set1, SIGABRT); sigaddset(&blocked_set2, SIGALRM); act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); if (sigaction(SIGABRT, &act, 0) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); pthread_exit((void*)1); } if (sigaction(SIGALRM, &act, 0) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); pthread_exit((void*)1); } if (pthread_sigmask(SIG_SETMASK, &blocked_set1, NULL) == -1) { perror("Unexpected error while attempting to use pthread_sigmask.\n"); pthread_exit((void*)1); } if (pthread_sigmask(SIG_BLOCK, &blocked_set2, NULL) == -1) { perror("Unexpected error while attempting to use pthread_sigmask.\n"); pthread_exit((void*)1); } if ((raise(SIGABRT) == -1) | (raise(SIGALRM) == -1)) { perror("Unexpected error while attempting to setup test " "pre-conditions"); pthread_exit((void*)1); } if (handler_called) { printf("FAIL: Signal was not blocked\n"); pthread_exit((void*)-1); } if (sigpending(&pending_set) == -1) { perror("Unexpected error while attempting to use sigpending\n"); pthread_exit((void*)1); } if ((sigismember(&pending_set, SIGABRT) != 1) | (sigismember(&pending_set, SIGALRM) != 1)) { perror("FAIL: sigismember did not return 1\n"); pthread_exit((void*)-1); } pthread_exit((void*)0); return NULL; } int main() { int *thread_return_value; pthread_t new_thread; if (pthread_create(&new_thread, NULL, a_thread_func, NULL) != 0) { perror("Error creating new thread\n"); return PTS_UNRESOLVED; } if (pthread_join(new_thread, (void*)&thread_return_value) != 0) { perror("Error in pthread_join()\n"); return PTS_UNRESOLVED; } if ((long)thread_return_value != 0) { if ((long)thread_return_value == 1) { printf ("Test UNRESOLVED\n"); return PTS_UNRESOLVED; } else if ((long)thread_return_value == -1) { printf ("Test FAILED\n"); return PTS_FAIL; } else { printf ("Test UNRESOLVED\n"); return PTS_UNRESOLVED; } } return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_sigmask/14-1.c0100644000000000000000000000372510200172717023205 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: salwan.searty REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Steps: 1. Call pthread_sigmask with correct parameter, and check that 0 is returned. */ #include #include #include #include #include #include "posixtest.h" void *a_thread_func() { sigset_t actl; /* printf("SIG_SETMASK=%d\n", SIG_SETMASK); printf("SIG_BLOCK=%d\n", SIG_BLOCK); printf("SIG_UNBLOCK=%d\n", SIG_UNBLOCK); printf("r=%d\n", r); */ sigemptyset(&actl); sigaddset(&actl, SIGABRT); if (pthread_sigmask(SIG_SETMASK, &actl, NULL) != 0) { perror("pthread_sigmask() did not return 0\n"); pthread_exit((void*)-1); } printf("PASS: pthread_sigmask returned 0.\n"); pthread_exit((void*)0); /* To please some compilers */ return NULL; } int main() { int *thread_return_value; pthread_t new_thread; if (pthread_create(&new_thread, NULL, a_thread_func, NULL) != 0) { perror("Error creating new thread\n"); return PTS_UNRESOLVED; } if (pthread_join(new_thread, (void*)&thread_return_value) != 0) { perror("Error in pthread_join()\n"); return PTS_UNRESOLVED; } if ((long)thread_return_value != 0) { if ((long)thread_return_value == 1) { printf ("Test UNRESOLVED\n"); return PTS_UNRESOLVED; } else if ((long)thread_return_value == -1) { printf ("Test FAILED\n"); return PTS_FAIL; } else { printf ("Test UNRESOLVED\n"); return PTS_UNRESOLVED; } } return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_sigmask/18-1.c0100644000000000000000000001776010310244750023214 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertion: * * The function does not return EINTR * The steps are: * -> kill a thread which calls pthread_sigmask * -> check that EINTR is never returned */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /********************************************************************************************/ /****************************** standard includes *****************************************/ /********************************************************************************************/ #include #include #include #include #include #include #include #include #include /********************************************************************************************/ /****************************** Test framework *****************************************/ /********************************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /********************************************************************************************/ /********************************** Configuration ******************************************/ /********************************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif #define WITH_SYNCHRO /********************************************************************************************/ /*********************************** Test cases *****************************************/ /********************************************************************************************/ char do_it = 1; unsigned long count_ope = 0; #ifdef WITH_SYNCHRO sem_t semsig1; sem_t semsig2; unsigned long count_sig = 0; #endif sigset_t usersigs; typedef struct { int sig; #ifdef WITH_SYNCHRO sem_t *sem; #endif } thestruct; /* the following function keeps on sending the signal to the process */ void * sendsig ( void * arg ) { thestruct * thearg = ( thestruct * ) arg; int ret; pid_t process; process = getpid(); /* We block the signals SIGUSR1 and SIGUSR2 for this THREAD */ ret = pthread_sigmask( SIG_BLOCK, &usersigs, NULL ); if ( ret != 0 ) { UNRESOLVED( ret, "Unable to block SIGUSR1 and SIGUSR2 in signal thread" ); } while ( do_it ) { #ifdef WITH_SYNCHRO if ( ( ret = sem_wait( thearg->sem ) ) ) { UNRESOLVED( errno, "Sem_wait in sendsig" ); } count_sig++; #endif ret = kill( process, thearg->sig ); if ( ret != 0 ) { UNRESOLVED( errno, "Kill in sendsig" ); } } return NULL; } /* Next are the signal handlers. */ /* This one is registered for signal SIGUSR1 */ void sighdl1( int sig ) { #ifdef WITH_SYNCHRO if ( sem_post( &semsig1 ) ) { UNRESOLVED( errno, "Sem_post in signal handler 1" ); } #endif } /* This one is registered for signal SIGUSR2 */ void sighdl2( int sig ) { #ifdef WITH_SYNCHRO if ( sem_post( &semsig2 ) ) { UNRESOLVED( errno, "Sem_post in signal handler 2" ); } #endif } int init_ctl; /* Init function */ void initializer( void ) { init_ctl++; return ; } /* Test function -- calls pthread_sigmask() and checks that EINTR is never returned. */ void * test( void * arg ) { int ret = 0; sigset_t set; int i, j=0; int signals[] = { SIGBUS, SIGKILL, SIGABRT, SIGCHLD, SIGHUP }; #define NSIG (sizeof(signals)/sizeof(int)) int operation[] = {SIG_SETMASK, SIG_BLOCK, SIG_UNBLOCK}; ret = sigemptyset( &set ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to initialize signal set" ); } /* We don't block the signals SIGUSR1 and SIGUSR2 for this THREAD */ ret = pthread_sigmask( SIG_UNBLOCK, &usersigs, NULL ); if ( ret != 0 ) { UNRESOLVED( ret, "Unable to unblock SIGUSR1 and SIGUSR2 in worker thread" ); } while ( do_it ) { count_ope++; for ( i = 0; i < 3; i++ ) { j++; j %= 2 * NSIG; if ( j >= NSIG ) ret = sigdelset( &set, signals[ j - NSIG ] ); else ret = sigaddset( &set, signals[ j ] ); if ( ret != 0 ) { UNRESOLVED( errno, "Failed to initialize signal set" ); } ret = pthread_sigmask( operation[ i ], &set, NULL ); if ( ret == EINTR ) { FAILED( "pthread_sigmask returned EINTR" ); } if ( ret != 0 ) { UNRESOLVED( ret, "Failed to initialize signal set" ); } } } return NULL; } /* Main function */ int main ( int argc, char * argv[] ) { int ret; pthread_t th_work, th_sig1, th_sig2; thestruct arg1, arg2; struct sigaction sa; /* Initialize output routine */ output_init(); /* We need to register the signal handlers for the PROCESS */ sigemptyset ( &sa.sa_mask ); sa.sa_flags = 0; sa.sa_handler = sighdl1; if ( ( ret = sigaction ( SIGUSR1, &sa, NULL ) ) ) { UNRESOLVED( ret, "Unable to register signal handler1" ); } sa.sa_handler = sighdl2; if ( ( ret = sigaction ( SIGUSR2, &sa, NULL ) ) ) { UNRESOLVED( ret, "Unable to register signal handler2" ); } /* We prepare a signal set which includes SIGUSR1 and SIGUSR2 */ sigemptyset( &usersigs ); ret = sigaddset( &usersigs, SIGUSR1 ); ret |= sigaddset( &usersigs, SIGUSR2 ); if ( ret != 0 ) { UNRESOLVED( ret, "Unable to add SIGUSR1 or 2 to a signal set" ); } /* We now block the signals SIGUSR1 and SIGUSR2 for this THREAD */ ret = pthread_sigmask( SIG_BLOCK, &usersigs, NULL ); if ( ret != 0 ) { UNRESOLVED( ret, "Unable to block SIGUSR1 and SIGUSR2 in main thread" ); } #ifdef WITH_SYNCHRO if ( sem_init( &semsig1, 0, 1 ) ) { UNRESOLVED( errno, "Semsig1 init" ); } if ( sem_init( &semsig2, 0, 1 ) ) { UNRESOLVED( errno, "Semsig2 init" ); } #endif if ( ( ret = pthread_create( &th_work, NULL, test, NULL ) ) ) { UNRESOLVED( ret, "Worker thread creation failed" ); } arg1.sig = SIGUSR1; arg2.sig = SIGUSR2; #ifdef WITH_SYNCHRO arg1.sem = &semsig1; arg2.sem = &semsig2; #endif if ( ( ret = pthread_create( &th_sig1, NULL, sendsig, ( void * ) & arg1 ) ) ) { UNRESOLVED( ret, "Signal 1 sender thread creation failed" ); } if ( ( ret = pthread_create( &th_sig2, NULL, sendsig, ( void * ) & arg2 ) ) ) { UNRESOLVED( ret, "Signal 2 sender thread creation failed" ); } /* Let's wait for a while now */ sleep( 1 ); /* Now stop the threads and join them */ do { do_it = 0; } while ( do_it ); if ( ( ret = pthread_join( th_sig1, NULL ) ) ) { UNRESOLVED( ret, "Signal 1 sender thread join failed" ); } if ( ( ret = pthread_join( th_sig2, NULL ) ) ) { UNRESOLVED( ret, "Signal 2 sender thread join failed" ); } if ( ( ret = pthread_join( th_work, NULL ) ) ) { UNRESOLVED( ret, "Worker thread join failed" ); } #if VERBOSE > 0 output( "Test executed successfully.\n" ); output( " %d operations.\n", count_ope ); #ifdef WITH_SYNCHRO output( " %d signals were sent meanwhile.\n", count_sig ); #endif #endif PASSED; } posixtestsuite/conformance/interfaces/pthread_sigmask/12-1.c0100644000000000000000000000715610153044545023211 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: salwan.searty REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Steps: 1. Set the signal mask to only having SIGABRT. 2. Call pthread_sigmask again, this time with a randomly generated value of how that is checked to make sure it does not equal any of the three defined values of how which are SIG_SETMASK, SIG_BLOCK, or SIG_UNBLOCK. This should cause pthread_sigmask() to return -1. For the second parameter in the pthread_sigmask() function, use a set which contains SIGABRT and SIGALRM. 3. Now verify using the is_changed() function that the only signal that is still in the signal mask is SIGABRT. Neither SIGALRM nor any other signal should be in the signal mask of the process. */ #include #include #include #include #include #include "posixtest.h" #define NUMSIGNALS 26 int is_changed(sigset_t set, int sig) { int i; int siglist[] = {SIGABRT, SIGALRM, SIGBUS, SIGCHLD, SIGCONT, SIGFPE, SIGHUP, SIGILL, SIGINT, SIGPIPE, SIGQUIT, SIGSEGV, SIGTERM, SIGTSTP, SIGTTIN, SIGTTOU, SIGUSR1, SIGUSR2, SIGPOLL, SIGPROF, SIGSYS, SIGTRAP, SIGURG, SIGVTALRM, SIGXCPU, SIGXFSZ }; if (sigismember(&set, sig) != 1) { return 1; } for (i=0; i #include #include #include #include "posixtest.h" int handler_called = 0; int pthread_sigmask_return_val = 1; /* some value that's not a 1 or 0 */ void handler(int signo) { handler_called = 1; if (pthread_sigmask_return_val != 1) { printf("FAIL: pthread_sigmask() returned before signal was delivered.\n"); exit(PTS_FAIL); } } void *a_thread_func() { struct sigaction act; sigset_t blocked_set1; sigemptyset(&blocked_set1); sigaddset(&blocked_set1, SIGABRT); act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); if (sigaction(SIGABRT, &act, 0) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); pthread_exit((void*)1); } if (pthread_sigmask(SIG_SETMASK, &blocked_set1, NULL) == -1) { perror("Unexpected error while attempting to use pthread_sigmask.\n"); pthread_exit((void*)1); } if ((raise(SIGABRT) == -1)) { perror("Unexpected error while attempting to setup test " "pre-conditions"); pthread_exit((void*)1); } pthread_sigmask_return_val = pthread_sigmask(SIG_UNBLOCK, &blocked_set1, NULL); if (pthread_sigmask_return_val != 0) { perror("Unexpected error while attempting to use pthread_sigmask.\n"); pthread_exit((void*)1); } if (handler_called != 1) { perror("Handler wasn't called, implying signal was not delivered.\n"); pthread_exit((void*)1); } printf("Test PASSED: signal was delivered before the call to pthread_sigmask returned.\n"); pthread_exit((void*)0); /* To please some compilers */ return NULL; } int main() { int *thread_return_value; pthread_t new_thread; if (pthread_create(&new_thread, NULL, a_thread_func, NULL) != 0) { perror("Error creating new thread\n"); return PTS_UNRESOLVED; } if (pthread_join(new_thread, (void*)&thread_return_value) != 0) { perror("Error in pthread_join()\n"); return PTS_UNRESOLVED; } if ((long)thread_return_value != 0) { if ((long)thread_return_value == 1) { printf ("Test UNRESOLVED\n"); return PTS_UNRESOLVED; } else if ((long)thread_return_value == -1) { printf ("Test FAILED\n"); return PTS_FAIL; } else { printf ("Test UNRESOLVED\n"); return PTS_UNRESOLVED; } } return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_sigmask/testfrmw.c0100644000000000000000000000407210204075240024467 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * * This file is a wrapper to use the tests from the NPTL Test & Trace Project * with either the Linux Test Project or the Open POSIX Test Suite. * The following function are defined: * void output_init() * void output_fini() * void output(char * string, ...) * * The are used to output informative text (as a printf). */ #include #include /* We use a mutex to avoid conflicts in traces */ static pthread_mutex_t m_trace = PTHREAD_MUTEX_INITIALIZER; /*****************************************************************************************/ /******************************* stdout module *****************************************/ /*****************************************************************************************/ /* The following functions will output to stdout */ #if (1) void output_init() { /* do nothing */ return; } void output( char * string, ... ) { va_list ap; char *ts="[??:??:??]"; struct tm * now; time_t nw; pthread_mutex_lock(&m_trace); nw = time(NULL); now = localtime(&nw); if (now == NULL) printf(ts); else printf("[%2.2d:%2.2d:%2.2d]", now->tm_hour, now->tm_min, now->tm_sec); va_start( ap, string); vprintf(string, ap); va_end(ap); pthread_mutex_unlock(&m_trace); } void output_fini() { /*do nothing */ return; } #endif posixtestsuite/conformance/interfaces/pthread_sigmask/8-3.c0100644000000000000000000000507510153044545023136 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: salwan.searty REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Steps: 1. Add only SIGABRT to the signal mask. 2. Make a call such as this: pthread_sigmask(SIG_UNBLOCK, NULL, &oactl). At this point, we have obtained the signal mask in oactl. 3. Now call is_changed to make sure that SIGABRT is still in oactl, and that no other signal in the set is in oactl. */ #include #include #include #include "posixtest.h" #define NUMSIGNALS 26 int is_changed(sigset_t set, int sig) { int i; int siglist[] = {SIGABRT, SIGALRM, SIGBUS, SIGCHLD, SIGCONT, SIGFPE, SIGHUP, SIGILL, SIGINT, SIGPIPE, SIGQUIT, SIGSEGV, SIGTERM, SIGTSTP, SIGTTIN, SIGTTOU, SIGUSR1, SIGUSR2, SIGPOLL, SIGPROF, SIGSYS, SIGTRAP, SIGURG, SIGVTALRM, SIGXCPU, SIGXFSZ }; if (sigismember(&set, sig) != 1) { return 1; } for (i=0; i #include #include #include "posixtest.h" int handler_called = 0; void handler(int signo) { handler_called = 1; } void *a_thread_func() { struct sigaction act; sigset_t set1, set2, pending_set; sigemptyset(&set1); sigaddset(&set1, SIGABRT); sigaddset(&set1, SIGALRM); sigemptyset(&set2); sigaddset(&set2, SIGALRM); act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); if (sigaction(SIGABRT, &act, 0) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); pthread_exit((void*)1); } if (sigaction(SIGALRM, &act, 0) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); pthread_exit((void*)1); } if (pthread_sigmask(SIG_SETMASK, &set1, NULL) == -1) { perror("Unexpected error while attempting to use pthread_sigmask.\n"); pthread_exit((void*)1); } if (pthread_sigmask(SIG_UNBLOCK, &set2, NULL) == -1) { perror("Unexpected error while attempting to use pthread_sigmask.\n"); pthread_exit((void*)1); } if (raise(SIGALRM) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); pthread_exit((void*)1); } if (!handler_called) { printf("FAIL: Handler was not called for even though signal was removed from the signal mask\n"); pthread_exit((void*)-1); } handler_called = 0; if (raise(SIGABRT) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); pthread_exit((void*)1); } if (handler_called) { printf("FAIL: Hanlder was called for even though signal should have been in the signal mask\n"); pthread_exit((void*)-1); } if (sigpending(&pending_set) == -1) { perror("Unexpected error while attempting to use sigpending\n"); pthread_exit((void*)1); } if (sigismember(&pending_set, SIGABRT) != 1) { perror("FAIL: sigismember did not return 1\n"); pthread_exit((void*)-1); } if (sigismember(&pending_set, SIGALRM) != 0) { perror("FAIL: sigismember did not return 0\n"); pthread_exit((void*)-1); } pthread_exit((void*)0); return NULL; } int main() { int *thread_return_value; pthread_t new_thread; if (pthread_create(&new_thread, NULL, a_thread_func, NULL) != 0) { perror("Error creating new thread\n"); return PTS_UNRESOLVED; } if (pthread_join(new_thread, (void*)&thread_return_value) != 0) { perror("Error in pthread_join()\n"); return PTS_UNRESOLVED; } if ((long)thread_return_value != 0) { if ((long)thread_return_value == 1) { printf ("Test UNRESOLVED\n"); return PTS_UNRESOLVED; } else if ((long)thread_return_value == -1) { printf ("Test FAILED\n"); return PTS_FAIL; } else { printf ("Test UNRESOLVED\n"); return PTS_UNRESOLVED; } } return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_sigmask/10-1.c0100644000000000000000000000461510200171326023173 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: salwan.searty REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Attempt to add SIGKILL and SIGSTOP to the process's signal mask and verify that: - They do not get added. - pthread_sigmask() does not return -1. */ #include #include #include #include "posixtest.h" void *a_thread_func() { sigset_t set1, set2; int pthread_sigmask_return_val = 1; sigemptyset(&set1); sigemptyset(&set2); sigaddset(&set1, SIGKILL); sigaddset(&set1, SIGSTOP); pthread_sigmask_return_val = pthread_sigmask(SIG_SETMASK, &set1, NULL); pthread_sigmask(SIG_SETMASK, NULL, &set2); if (sigismember(&set2, SIGKILL)) { printf("FAIL: SIGKILL was added to the signal mask\n"); pthread_exit((void*)-1); } if (sigismember(&set2, SIGSTOP)) { printf("FAIL: SIGSTOP was added to the signal mask\n"); pthread_exit((void*)-1); } if (pthread_sigmask_return_val != 0) { printf("FAIL: pthread_sigmask returned %d. System should be able to enforce blocking un-ignorable signals without causing pthread_sigmask() to return an error.\n", pthread_sigmask_return_val); pthread_exit((void*)-1); } printf("Test PASSED\n"); pthread_exit((void*)0); /* To please some compilers */ return NULL; } int main() { int *thread_return_value; pthread_t new_thread; if (pthread_create(&new_thread, NULL, a_thread_func, NULL) != 0) { perror("Error creating new thread\n"); return PTS_UNRESOLVED; } if (pthread_join(new_thread, (void*)&thread_return_value) != 0) { perror("Error in pthread_join()\n"); return PTS_UNRESOLVED; } if ((long)thread_return_value != 0) { if ((long)thread_return_value == 1) { printf ("Test UNRESOLVED\n"); return PTS_UNRESOLVED; } else if ((long)thread_return_value == -1) { printf ("Test FAILED\n"); return PTS_FAIL; } else { printf ("Test UNRESOLVED\n"); return PTS_UNRESOLVED; } } return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_sigmask/8-2.c0100644000000000000000000000507710153044545023137 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: salwan.searty REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Steps: 1. Add only SIGABRT to the signal mask. 2. Make a call such as this: pthread_sigmask(SIG_SETMASK, NULL, &oactl). At this point, we have obtained the signal mask in oactl. 3. Now call is_changed to make sure that SIGABRT is still in oactl, and that no other signal in the set is in oactl. */ #include #include #include #include "posixtest.h" #define NUMSIGNALS 26 int is_changed(sigset_t set, int sig) { int i; int siglist[] = {SIGABRT, SIGALRM, SIGBUS, SIGCHLD, SIGCONT, SIGFPE, SIGHUP, SIGILL, SIGINT, SIGPIPE, SIGQUIT, SIGSEGV, SIGTERM, SIGTSTP, SIGTTIN, SIGTTOU, SIGUSR1, SIGUSR2, SIGPOLL, SIGPROF, SIGSYS, SIGTRAP, SIGURG, SIGVTALRM, SIGXCPU, SIGXFSZ }; if (sigismember(&set, sig) != 1) { return 1; } for (i=0; i #include #include #include "posixtest.h" #define NUMSIGNALS 26 void *a_thread_func() { sigset_t oactl, tempset; int i, j, test_failed = 0; int siglist[] = {SIGABRT, SIGALRM, SIGBUS, SIGCHLD, SIGCONT, SIGFPE, SIGHUP, SIGILL, SIGINT, SIGPIPE, SIGQUIT, SIGSEGV, SIGTERM, SIGTSTP, SIGTTIN, SIGTTOU, SIGUSR1, SIGUSR2, SIGPOLL, SIGPROF, SIGSYS, SIGTRAP, SIGURG, SIGVTALRM, SIGXCPU, SIGXFSZ }; for ( i = 0; i < NUMSIGNALS; i++ ) { sigemptyset( &oactl ); sigemptyset( &tempset ); sigaddset( &tempset, siglist[ i ] ); pthread_sigmask( SIG_BLOCK, &tempset, &oactl ); if ( i > 0 ) { for ( j = 0; j < i; j++ ) { if ( sigismember( &oactl, siglist[ j ] ) != 1 ) { test_failed = 1; } } for ( j = i + 1; j < NUMSIGNALS; j++ ) { if ( sigismember( &oactl, siglist[ j ] ) != 0 ) { test_failed = 1; } } } } if ( test_failed != 0 ) { printf( "Old set is invalid.\n" ); pthread_exit( ( void* ) - 1 ); } printf( "Test PASSED: oactl did contain all signals that were added to the signal mask.\n" ); pthread_exit( ( void* ) 0 ); /* To please some compilers */ return NULL; } int main() { int * thread_return_value; pthread_t new_thread; if ( pthread_create( &new_thread, NULL, a_thread_func, NULL ) != 0 ) { perror( "Error creating new thread\n" ); return PTS_UNRESOLVED; } if ( pthread_join( new_thread, ( void* ) & thread_return_value ) != 0 ) { perror( "Error in pthread_join()\n" ); return PTS_UNRESOLVED; } if ( ( long ) thread_return_value != 0 ) { if ( ( long ) thread_return_value == 1 ) { printf ( "Test UNRESOLVED\n" ); return PTS_UNRESOLVED; } else if ( ( long ) thread_return_value == -1 ) { printf ( "Test FAILED\n" ); return PTS_FAIL; } else { printf ( "Test UNRESOLVED\n" ); return PTS_UNRESOLVED; } } return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_sigmask/assertions.xml0100644000000000000000000000775607636242421025414 0ustar rootroot pthread_sigmask( ) function is used to examine or change (or both) the calling thread's signal mask, independent of the number of threads the process contains. The function shall be equivalent to sigprocmask( ), but with the ability to be used in a thread of a multi-threaded process. The sigprocmask( ) function is used to examine or change (or both) the signal mask of the calling thread of a single-threaded process. The argument set points to a set of signals to be used to change the currently blocked set, unless the argument is a null pointer. The resulting set shall be the union of the current set and the signal set pointed to by set, if the value of the argument how is SIG_BLOCK. The resulting set shall be the signal set pointed to by set, if the value of the argument how is SIG_SETMASK The resulting set shall be the intersection of the current set and the complement of the signal set pointed to by set, if the value of the argument how is SIG_UNBLOCK The previous mask shall be stored in the location pointed to by oset, if the argument oset is not a null pointer. The value of the argument how is not significant and the process's signal mask shall be unchanged, and thus the call can be used to enquire about currently blocked signals, if the argument set is a null pointer. After the call to sigprocmask(), if there are any pending unblocked signals, at least one of those signals shall be delivered before the call to sigprocmask() returns. The system shall not allow the blocking of signals which cannot be ignored, and shall not cause an error to be indicated. If any of the SIGFPE, SIGILL, SIGSEGV, or SIGBUS signals are generated while they are blocked, and the signal was not generated by the kill(), sigqueue() or raise()functions, the result is undefined. The thread's signal mask shall not be changed, if sigprocmask( ) fails. In a multi-threaded process, the use of the sigprocmask( ) function is unspecified. pthread_sigmask( ) shall return 0, Upon successful completion; otherwise, it shall return the corresponding error number. sigprocmask( ) shall return 0, Upon successful completion; otherwise, it shall return -1 and errno shall be set to indicate the error, and the process' signal mask shall be unchanged. An errno value of [EINVAL] shall be returned and the pthreadsigmask() function shall fail, if the value of the how argument is not equal to one of the defined values. An errno value of [EINVAL] shall be returned and the sigprocmask() function shall fail, if the value of the how argument is not equal to one of the defined values. An error code of [EINTR] shall not be returned by the pthread_sigmask( ) function. posixtestsuite/conformance/interfaces/pthread_sigmask/coverage.txt0100644000000000000000000000160607636242421025020 0ustar rootrootThis document defines the coverage for function pthread_sigmask(). The functions pthread_sigmask() and sigprocmask() are equivalent functions, but pthread_sigmask() should also work in a multi-threaded process. The tests in this section are similar in n nature to the tests for the sigprocmask() function, but calls will be made from threads that belong to multi-threaded processes instead of single-threaded processes. Assertion Covered? 1 IMPLICITLY tested by assertions 1-18 2 WON'T test. Pertains only to sigprocmask(). 3 IMPLICITLY tested by assertions 4-6 4 YES 5 YES 6 YES 7 YES 8 YES 9 YES 10 YES 11 WON'T test, because POSIX does not define behavior in this case. 12 YES 13 WON'T test, because POSIX does not define behavior in this case. 14 YES 15 WON'T test, pertains only to sigprocmask() 16 YES 17 WON'T test, pertains only to sigprocmask() 18 NO, won't test for now. posixtestsuite/conformance/interfaces/pthread_sigmask/testfrmw.h0100644000000000000000000000456410204075240024502 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * * This file is a wrapper to use the tests from the NPTL Test & Trace Project * with either the Linux Test Project or the Open POSIX Test Suite. * The following macros are defined here: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate without calling one of those macros. * * */ #include "posixtest.h" #include /* for the strerror() routine */ #ifdef __GNUC__ /* We are using GCC */ #define UNRESOLVED(x, s) \ { output("Test %s unresolved: got %i (%s) on line %i (%s)\n", __FILE__, x, strerror(x), __LINE__, s); \ output_fini(); \ exit(PTS_UNRESOLVED); } #define FAILED(s) \ { output("Test %s FAILED: %s\n", __FILE__, s); \ output_fini(); \ exit(PTS_FAIL); } #define PASSED \ output_fini(); \ exit(PTS_PASS); #define UNTESTED(s) \ { output("File %s cannot test: %s\n", __FILE__, s); \ output_fini(); \ exit(PTS_UNTESTED); \ } #else /* not using GCC */ #define UNRESOLVED(x, s) \ { output("Test unresolved: got %i (%s) on line %i (%s)\n", x, strerror(x), __LINE__, s); \ output_fini(); \ exit(PTS_UNRESOLVED); } #define FAILED(s) \ { output("Test FAILED: %s\n", s); \ output_fini(); \ exit(PTS_FAIL); } #define PASSED \ output_fini(); \ exit(PTS_PASS); #define UNTESTED(s) \ { output("Unable to test: %s\n", s); \ output_fini(); \ exit(PTS_UNTESTED); \ } #endif posixtestsuite/conformance/interfaces/pthread_sigmask/8-1.c0100644000000000000000000000507010153044545023127 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: salwan.searty REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Steps: 1. Add only SIGABRT to the signal mask. 2. Make a call such as this: pthread_sigmask(SIG_BLOCK, NULL, &oactl). At this point, we have obtained the signal mask in oactl. 3. Now call is_changed to make sure that SIGABRT is still in oactl, and that no other signal in the set is in oactl. */ #include #include #include #include "posixtest.h" #define NUMSIGNALS 26 int is_changed(sigset_t set, int sig) { int i; int siglist[] = {SIGABRT, SIGALRM, SIGBUS, SIGCHLD, SIGCONT, SIGFPE, SIGHUP, SIGILL, SIGINT, SIGPIPE, SIGQUIT, SIGSEGV, SIGTERM, SIGTSTP, SIGTTIN, SIGTTOU, SIGUSR1, SIGUSR2, SIGPOLL, SIGPROF, SIGSYS, SIGTRAP, SIGURG, SIGVTALRM, SIGXCPU, SIGXFSZ }; if (sigismember(&set, sig) != 1) { return 1; } for (i=0; i #include #include #include #include #include "posixtest.h" int get_rand() { int r; r=rand(); if ((r == SIG_BLOCK) || (r == SIG_SETMASK) || (r == SIG_UNBLOCK)) { r = get_rand(); } return r; } void *a_thread_func() { int r=get_rand(); sigset_t actl; /* printf("SIG_SETMASK=%d\n", SIG_SETMASK); printf("SIG_BLOCK=%d\n", SIG_BLOCK); printf("SIG_UNBLOCK=%d\n", SIG_UNBLOCK); printf("r=%d\n", r); */ sigemptyset(&actl); sigaddset(&actl, SIGABRT); if (pthread_sigmask(r, &actl, NULL) != EINVAL) { perror("pthread_sigmask() did not fail even though invalid how parameter was passed to it.\n"); pthread_exit((void*)-1); } printf("PASS: pthread_sigmask returned the correct error value.\n"); pthread_exit((void*)0); /* To please some compilers */ return NULL; } int main() { int *thread_return_value; pthread_t new_thread; if (pthread_create(&new_thread, NULL, a_thread_func, NULL) != 0) { perror("Error creating new thread\n"); return PTS_UNRESOLVED; } if (pthread_join(new_thread, (void*)&thread_return_value) != 0) { perror("Error in pthread_join()\n"); return PTS_UNRESOLVED; } if ((long)thread_return_value != 0) { if ((long)thread_return_value == 1) { printf ("Test UNRESOLVED\n"); return PTS_UNRESOLVED; } else if ((long)thread_return_value == -1) { printf ("Test FAILED\n"); return PTS_FAIL; } else { printf ("Test UNRESOLVED\n"); return PTS_UNRESOLVED; } } return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_key_create/0040755000000000000000000000000010515625215023135 5ustar rootrootposixtestsuite/conformance/interfaces/pthread_key_create/speculative/0040755000000000000000000000000010515625215025461 5ustar rootrootposixtestsuite/conformance/interfaces/pthread_key_create/speculative/5-1.c0100644000000000000000000000346507711576133026144 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: bing.wei.liu REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_key_create() * * If successful, the pthread_key_create() function shall store the newly created key value * at *key and shall return zero. Otherwise, an error number shall be returned to indicate * an error: * * [EAGAIN] - the system lacked the necessary resources to create another thread_specific * data key, or the system imposed limit on the total number of keys per process * [PTHREAD_KEYS_MAX] has been exceeded. * * [ENOMEM] - insufficient memory exists to create the key. * * TESTING [EAGAIN] * * Steps: * 1. Define an array of keys * 2. Use pthread_key_create() and create those keys * 3. Verify that you can set and get specific values for those keys without errors. * */ #include #include #include #include #include #include #include "posixtest.h" int NUM_OF_KEYS = PTHREAD_KEYS_MAX; static pthread_key_t keys[5]; int main() { int i, rc; for(i = 0;i<=NUM_OF_KEYS;i++) { rc = pthread_key_create(&keys[i], NULL); if(i == NUM_OF_KEYS) { if(rc != EAGAIN) { printf("Test FAILED: Expected EAGAIN when exceeded the limit of keys in a single process, but got: %d\n", rc); return PTS_FAIL; } } if(rc != 0) { if(rc != EAGAIN) { printf("Error: pthread_key_create() failed\n"); return PTS_UNRESOLVED; } else { printf("Test FAILED: EAGAIN was returned before the key limit was exceeded\n"); return PTS_FAIL; } } } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_key_create/1-1.c0100644000000000000000000000363010033204322023561 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: bing.wei.liu REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_key_create() * * shall create a thread-specific data key visible to all threaads in the process. Key values * provided by pthread_key_create() are opaque objects used to locate thread-specific data. * Although the same key value may be used by different threads, the values bound to the key * by pthread_setspecific() are maintained on a per-thread basis and persist for the life of * the calling thread. * * Steps: * 1. Define an array of keys * 2. Use pthread_key_create() and create those keys * 3. Verify that you can set and get specific values for those keys without errors. * */ #include #include #include #include #include "posixtest.h" #define NUM_OF_KEYS 10 #define KEY_VALUE 0 pthread_key_t keys[NUM_OF_KEYS]; int main() { int i; void* rc; for(i = 0;i #include #include #include #include "posixtest.h" #define NUM_OF_THREADS 10 #define KEY_VALUE 1000 pthread_key_t keys[NUM_OF_THREADS]; int i; /* Thread function that sets the key to KEY_VALUE */ void *a_thread_func() { /* Set the key to KEY_VALUE */ if(pthread_setspecific(keys[i], (void *)(KEY_VALUE)) != 0) { printf("Error: pthread_setspecific() failed\n"); pthread_exit((void*)PTS_FAIL); } pthread_exit(0); } int main() { pthread_t new_th; void *value_ptr; /* Create a key */ for(i = 0;i The function int pthread_key_create(pthread_key_t *key, void (*destructor(void*)); shall create a thread-specific data key visible to all threaads in the process. Key values provided by pthread_key_create() are opaque objects used to locate thread-specific data. Although the same key value may be used by different threads, the values bound to the key by pthread_setspecific() are maintained on a per-thread basis and persist for the life of the calling thread. Upon key creation, the value NULL shall be associated with the new key in all active threads. Upon thread creation, the value NULL shall be associated with all defined keys in the new thread. An optional destructor function may be associated with each key value. At thread exit, if a key value has a non-NULL destructor pointer, and the thread has a non-NULL value associated with that key, the value of the key is set to NULL, and then the function pointed to is called with the previously associated value as its sole argument. The order of destructor calls is unspecified if more than one destructor exists for a thread when it exits. If, after all the destructors have been called for all non-NULL values with associated destructors, there are still some non-NULL values with associated destructors, then the process is repeated. If, after at least (PTHREAD_DESTRUCTOR_ITERATIONS) iterations of destructor calls for outstanding non-NULL values, there are still some non-NULL values with associated destructors, implemenations may stop calling destructors or they may continue calling destructors until no non-NULL values with associated destructors exist, even though this might result in an infinite loop. If successful, the pthread_key_create() function shall store the newly created key value at *key and shall return zero. Otherwise, an error number shall be returned to indicate an error: It shall fail if: [EAGAIN] - the system lacked the necessary resources to create another thread_specific data key, or the system imposed limit on the total number of keys per process [PTHREAD_KEYS_MAX] has been exceeded. [ENOMEM] - insufficient memory exists to create the key. it shall not return [EINTR]. posixtestsuite/conformance/interfaces/pthread_key_create/coverage.txt0100644000000000000000000000024107711575362025476 0ustar rootrootThis document defines the coverage for the pthread_key_create function: Assertion Tested? 1 YES 2 YES 3 YES 4 NO *Will not test 5 NO *Will not test NOTE: posixtestsuite/conformance/interfaces/pthread_key_create/2-1.c0100644000000000000000000000243607711575362023615 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: bing.wei.liu REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_key_create() * * Upon key creation, the value NULL shall be associated with the new key in all active threads. * Upon thread creation, the value NULL shall be associated with all defined keys in the new * thread. * * Steps: * 1. Create a key * 2. Verify that the default value is NULL * */ #include #include #include #include #include "posixtest.h" int main() { pthread_key_t key; void* rc; /* Verify that the value associated with "key" in a new thread is NULL */ rc = pthread_getspecific(key); if(rc != NULL) { printf("Test FAILED\n"); return PTS_FAIL; } if(pthread_key_create(&key, NULL) != 0) { printf("Error: pthread_key_create() failed\n"); return PTS_UNRESOLVED; } else { /* Verify that the value associated with "key" after it is newly created is * NULL */ rc = pthread_getspecific(key); if(rc != NULL) { printf("Test FAILED\n"); return PTS_FAIL; } } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_key_create/3-1.c0100644000000000000000000000441007711575362023610 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: bing.wei.liu REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_key_create() * * An optional destructor function may be associated with each key value. At thread exit, if * a key value has a non-NULL destructor pointer, and the thread has a non-NULL value associated * with that key, the value of the key is set to NULL, and then the function pointed to is called * with the previously associated value as its sole argument. The order of destructor calls is * unspecified if more than one destructor exists for a thread when it exits. * * Steps: * 1. Define an array of keys * 2. Use pthread_key_create() and create those keys * 3. Verify that you can set and get specific values for those keys without errors. * */ #include #include #include #include #include "posixtest.h" #define KEY_VALUE 1000 pthread_key_t key; int dest_cnt; /* Destructor funciton */ void dest_func(void *p) { dest_cnt++; } /* Thread function */ void *a_thread_func() { /* Set the value of the key to a value */ if(pthread_setspecific(key, (void *)(KEY_VALUE)) != 0) { printf("Error: pthread_setspecific() failed\n"); pthread_exit((void*) PTS_UNRESOLVED); } /* The thread ends here, the destructor for the key should now be called after this */ pthread_exit(0); } int main() { pthread_t new_th; /* Inialize the destructor flag */ dest_cnt = 0; /* Create a key with a destructor function */ if(pthread_key_create(&key, dest_func) != 0) { printf("Error: pthread_key_create() failed\n"); pthread_exit((void*) PTS_UNRESOLVED); } /* Create a thread */ if(pthread_create(&new_th, NULL, a_thread_func, NULL) != 0) { perror("Error creating thread\n"); return PTS_UNRESOLVED; } /* Wait for the thread's return */ if(pthread_join(new_th, NULL) != 0) { perror("Error in pthread_join()\n"); return PTS_UNRESOLVED; } /* Check if the destructor was called */ if(dest_cnt == 0) { printf("Test FAILED: Destructor not called\n"); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/clock_getres/0040755000000000000000000000000010515625161021757 5ustar rootrootposixtestsuite/conformance/interfaces/clock_getres/6-2.c0100644000000000000000000000327607575165555022456 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that clock_getres() sets errno=EINVAL for a variety of * invalid clock_ids. * * The following invalid clock_ids will be used: * - Boundary values for integers (TBD if clock_id is an integer) * MIN INT = INT32_MIN * MAX INT = INT32_MAX * MIN INT - 1 = 2147483647 (this is what gcc will set to) * MAX INT + 1 = -2147483647 (this is what gcc will set to) * unassigned value = -1073743192 (ex. of what gcc will set to) * unassigned value = 1073743192 (ex. of what gcc will set to) * -1 * 17 (currently not = to any clock) * */ #include #include #include #include #include "posixtest.h" #define NUMINVALIDTESTS 8 int main(int argc, char *argv[]) { struct timespec res; int invalid_tests[NUMINVALIDTESTS] = { INT32_MIN, INT32_MAX, 2147483647, -2147483647, -1073743192, 1073743192, -1, 17}; int i; int failure = 0; for (i = 0; i < NUMINVALIDTESTS; i++) { printf("clock_getres(%d, &res);\n", invalid_tests[i]); if (clock_getres(invalid_tests[i], &res) == -1) { if (EINVAL != errno) { printf("errno != EINVAL\n"); failure = 1; } } else { printf("clock_getres() != -1\n"); failure = 1; } } if (failure) { printf("At least one test FAILED -- see above\n"); return PTS_FAIL; } else { printf("All tests PASSED\n"); return PTS_PASS; } printf("This code should not be executed.\n"); return PTS_UNRESOLVED; } posixtestsuite/conformance/interfaces/clock_getres/5-1.c0100644000000000000000000000131607575165555022445 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that clock_getres() returns -1 on failure. */ #include #include #include "posixtest.h" #define INVALIDCLOCKID 99999 int main(int argc, char *argv[]) { struct timespec res; if (clock_getres(INVALIDCLOCKID, &res) == -1) { printf("Test PASSED\n"); return PTS_PASS; } else { printf("Test FAILED\n"); return PTS_FAIL; } printf("This code should not be executed\n"); return PTS_UNRESOLVED; } posixtestsuite/conformance/interfaces/clock_getres/1-1.c0100644000000000000000000000215307631756245022434 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that clock_getres() returns the resolution of clock_id in res. * * The clock chosen for this test is CLOCK_REALTIME. */ #include #include #include "posixtest.h" #define LARGENUM 100000 int main(int argc, char *argv[]) { struct timespec res; /* Initialize res to a number much larger than the resolution * could possibly be */ res.tv_sec = LARGENUM; res.tv_nsec = LARGENUM; if (clock_getres(CLOCK_REALTIME, &res) == 0) { if (res.tv_sec != LARGENUM) { //assume initialized #ifdef DEBUG printf("Resolution is %d sec %d nsec\n", (int) res.tv_sec, (int) res.tv_nsec); #endif printf("Test PASSED\n"); return PTS_PASS; } else { printf("clock_getres() success, but res not filled\n"); } } else { printf("clock_getres() failed\n"); } printf("Test FAILED\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/clock_getres/6-1.c0100644000000000000000000000152707575165555022452 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that clock_getres() sets errno=EINVAL if clock_id does not * refer to a known clock. */ #include #include #include #include "posixtest.h" #define INVALIDCLOCKID 99999 int main(int argc, char *argv[]) { struct timespec res; if (clock_getres(INVALIDCLOCKID, &res) == -1) { if (EINVAL == errno) { printf("Test PASSED\n"); return PTS_PASS; } else { printf("errno != EINVAL\n"); return PTS_FAIL; } } else { printf("clock_getres() did not return -1\n"); return PTS_UNRESOLVED; } return PTS_UNRESOLVED; } posixtestsuite/conformance/interfaces/clock_getres/7-1.c0100644000000000000000000000253110470232723022423 0ustar rootroot/* * Copyright (c) 2004, Intel Corporation. All rights reserved. * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * author: adam li * Test that clock_getres() returns the resolution of clock_id in res. * * The clock chosen for this test is CLOCK_PROCESS_CPUTIME_ID. */ #define _XOPEN_SOURCE 600 #include #include #include #include "posixtest.h" #define LARGENUM 100000 int main(int argc, char *argv[]) { #if _POSIX_CPUTIME != -1 struct timespec res; if (sysconf(_SC_CPUTIME) == -1) { printf("_POSIX_CPUTIME not supported\n"); return PTS_UNSUPPORTED; } /* Initialize res to a number much larger than the resolution * could possibly be */ res.tv_sec = LARGENUM; res.tv_nsec = LARGENUM; if (clock_getres(CLOCK_PROCESS_CPUTIME_ID, &res) == 0) { if (res.tv_sec != LARGENUM) { //assume initialized #ifdef DEBUG printf("Resolution is %d sec %d nsec\n", (int) res.tv_sec, (int) res.tv_nsec); #endif printf("Test PASSED\n"); return PTS_PASS; } else { printf("clock_getres() success, but res not filled\n"); } } else { printf("clock_getres() failed\n"); } printf("Test FAILED\n"); return PTS_FAIL; #else printf("_POSIX_CPUTIME not supported\n"); return PTS_UNSUPPORTED; #endif } posixtestsuite/conformance/interfaces/clock_getres/assertions.xml0100644000000000000000000000376610035176761024710 0ustar rootroot clock_getres() returns the resolution of clock clock_id in res if res != NULL clock_getres() supports a clock_id of CLOCK_REALTIME clock_getres() supports a clock_id of CLOCK_MONOTONIC (if pt:MON) clock_getres() returns 0 on success clock_getres returns -1 on failure clock_getres() sets errno=EINVAL if clock_id does not refer to a known clock CPT If _POSIX_CPUTIME is defined, implementations shall support clock ID values obtained by invoking clock_getcpuclockid( ), which represent the CPU-time clock of a given process. Implementations shall also support the special clockid_t value CLOCK_PROCESS_CPUTIME_ID, which represents the CPU-time clock of the calling process when invoking one of the clock_*( ) or timer_*( ) functions. For these clock IDs, the values returned by clock_gettime( ) and specified by clock_settime( ) represent the amount of execution time of the process associated with the clock. If _POSIX_THREAD_CPUTIME is defined, implementations shall support clock ID values obtained by invoking pthread_getcpuclockid( ), which represent the CPU-time clock of a given thread. Implementations shall also support the special clockid_t value CLOCK_THREAD_CPUTIME_ID, which represents the CPU-time clock of the calling thread when invoking one of the clock_*( ) or timer_*( ) functions. For these clock IDs, the values returned by clock_gettime( ) and specified by clock_settime( ) shall represent the amount of execution time of the thread associated with the clock. posixtestsuite/conformance/interfaces/clock_getres/coverage.txt0100644000000000000000000000023010035203006024266 0ustar rootrootThis document defines the coverage for testing the clock_getres() function. Assertion Covered? 1 YES 2 YES 3 YES 4 YES 5 YES 6 YES 7 YES 8 YES posixtestsuite/conformance/interfaces/clock_getres/8-1.c0100644000000000000000000000256310470232723022431 0ustar rootroot/* * Copyright (c) 2004, Intel Corporation. All rights reserved. * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * author: adam li * Test that clock_getres() returns the resolution of clock_id in res. * * The clock chosen for this test is CLOCK_THREAD_CPUTIME_ID. */ #define _XOPEN_SOURCE 600 #include #include #include #include "posixtest.h" #define LARGENUM 100000 int main(int argc, char *argv[]) { #if _POSIX_THREAD_CPUTIME != -1 struct timespec res; if (sysconf(_SC_THREAD_CPUTIME) == -1) { printf("_POSIX_THREAD_CPUTIME not supported\n"); return PTS_UNSUPPORTED; } /* Initialize res to a number much larger than the resolution * could possibly be */ res.tv_sec = LARGENUM; res.tv_nsec = LARGENUM; if (clock_getres(CLOCK_THREAD_CPUTIME_ID, &res) == 0) { if (res.tv_sec != LARGENUM) { //assume initialized #ifdef DEBUG printf("Resolution is %d sec %d nsec\n", (int) res.tv_sec, (int) res.tv_nsec); #endif printf("Test PASSED\n"); return PTS_PASS; } else { printf("clock_getres() success, but res not filled\n"); } } else { printf("clock_getres() failed\n"); } printf("Test FAILED\n"); return PTS_FAIL; #else printf("_POSIX_THREAD_CPUTIME not supported\n"); return PTS_UNSUPPORTED; #endif } posixtestsuite/conformance/interfaces/clock_getres/2-1.sh0100755000000000000000000000073407566256357022641 0ustar rootroot#!/bin/sh # Copyright (c) 2002, Intel Corporation. All rights reserved. # Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com # This file is licensed under the GPL license. For the full content # of this license, see the COPYING file at the top level of this # source tree. # Test that clock_getres() supports a clock_id of CLOCK_REALTIME. # # This is tested implicitly via assertion 1. echo "Tested implicitly via assertion 1. See output for status." exit 0 posixtestsuite/conformance/interfaces/clock_getres/4-1.sh0100755000000000000000000000071307566256357022640 0ustar rootroot#!/bin/sh # Copyright (c) 2002, Intel Corporation. All rights reserved. # Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com # This file is licensed under the GPL license. For the full content # of this license, see the COPYING file at the top level of this # source tree. # Test that clock_getres() returns 0 on success. # # This is tested implicitly via assertion 1. echo "Tested implicitly via assertion 1. See output for status." exit 0 posixtestsuite/conformance/interfaces/clock_getres/3-1.c0100644000000000000000000000271107631756245022436 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * pt:MON * Test that clock_getres() supports a clock_id of CLOCK_MONOTONIC if * pt:MON. */ #include #include #include "posixtest.h" #define LARGENUM 100000 int main(int argc, char *argv[]) { #ifdef CLOCK_MONOTONIC struct timespec res; /* Initialize res to a number much larger than the resolution * could possibly be */ res.tv_sec = LARGENUM; res.tv_nsec = LARGENUM; if (clock_getres(CLOCK_MONOTONIC, &res) == 0) { if (res.tv_sec != LARGENUM) { //assume initialized #ifdef DEBUG printf("Resolution is %d sec %d nsec\n", (int) res.tv_sec, (int) res.tv_nsec); #endif printf("Test PASSED\n"); return PTS_PASS; } else { printf("clock_getres() success, but res not filled\n"); } } else { printf("clock_getres() failed\n"); } printf("Test FAILED\n"); return PTS_FAIL; #else printf("CLOCK_MONOTONIC unsupported\n"); return PTS_UNSUPPORTED; #endif } posixtestsuite/conformance/interfaces/mktime/0040755000000000000000000000000010515625166020606 5ustar rootrootposixtestsuite/conformance/interfaces/mktime/1-1.c0100644000000000000000000000171207705565563021261 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: majid.awad REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * * * This test case shall return PASS on converting the broken down July 4th 2001 * into a time since the Epoch, which is the same encoding as of the value * returned by time(), otherwise it fails with -1. */ #include #include #include "posixtest.h" struct tm tm_ptr; time_t tps; int main(void) { /* Break down July 4th, 2001 */ tm_ptr.tm_year = 2001 - 1900; tm_ptr.tm_mon = 7 - 1; tm_ptr.tm_mday = 4; tm_ptr.tm_hour = 0; tm_ptr.tm_min = 0; tm_ptr.tm_sec = 1; tm_ptr.tm_isdst = -1; tps = mktime(&tm_ptr); if (tps != -1){ printf("%s", ctime(&tps)); puts("TEST PASSED"); return PTS_PASS; } else { puts("TEST FAILED"); return PTS_FAIL; } } posixtestsuite/conformance/interfaces/mktime/assertions.xml0100644000000000000000000000044707705565563023537 0ustar rootroot This test case shall return PASS on converting the broken down July 4th 2001 into a time since the Epoch, which is the same encoding as of the value returned by time(), otherwise it fails with -1. posixtestsuite/conformance/interfaces/mktime/coverage.txt0100644000000000000000000000013307710061740023127 0ustar rootrootThis file defines the coverage for the mktime() function testing. Assertion Status 1 YES posixtestsuite/conformance/interfaces/mq_timedreceive/0040755000000000000000000000000010515625173022460 5ustar rootrootposixtestsuite/conformance/interfaces/mq_timedreceive/15-1.c0100644000000000000000000000434407635554641023223 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: crystal.xiong REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * mq_timedreceive test plan: * mq_timedreceive will return EMSGSIZE when msg_len is less than the * message size attribute of the message queue. */ #include #include #include #include #include #include #include #include #include #include "posixtest.h" #define TEST "15-1" #define FUNCTION "mq_timedreceive" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " #define NAMESIZE 50 #define BUFFER 20 int main() { char mqname[NAMESIZE], msgrv[BUFFER]; const char *msgptr = "test message"; mqd_t mqdes; int prio = 1; struct mq_attr mqstat; struct timespec ts; int unresolved = 0, failure = 0; sprintf(mqname, "/" FUNCTION "_" TEST "_%d", getpid()); memset(&mqstat,0,sizeof(mqstat)); mqstat.mq_msgsize = BUFFER + 1; mqstat.mq_maxmsg = BUFFER + 1; mqdes = mq_open(mqname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, &mqstat); if (mqdes == (mqd_t)-1) { perror(ERROR_PREFIX "mq_open"); unresolved = 1; } if (mq_send(mqdes, msgptr, strlen(msgptr), prio) != 0) { perror(ERROR_PREFIX "mq_send"); unresolved = 1; } ts.tv_sec = time(NULL) + 1; ts.tv_nsec = 0; if (mq_timedreceive(mqdes, msgrv, BUFFER, NULL, &ts) > 0) { printf("FAIL: mq_timedreceive succeed unexpectly\n"); failure = 1; } else { if (EMSGSIZE != errno) { printf("errno != EMSGSIZE \n"); failure = 1; } } if (mq_close(mqdes) != 0) { perror(ERROR_PREFIX "mq_close"); unresolved = 1; } if (mq_unlink(mqname) != 0) { perror(ERROR_PREFIX "mq_unlink"); unresolved = 1; } if (failure==1) { printf("Test FAILED\n"); return PTS_FAIL; } if (unresolved==1) { printf("Test UNRESOLVED\n"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/mq_timedreceive/17-1.c0100644000000000000000000000401507634324276023216 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: crystal.xiong REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * mq_timedreceive() test plan: * mq_timedreceive() will fail with EINVAL if message queue is * empty and nanoseconds field value of abs_timeout is less than 0. * */ #include #include #include #include #include #include #include #include #include #include #include #include "posixtest.h" #define TEST "17-1" #define FUNCTION "mq_timedreceive" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " #define NAMESIZE 50 #define BUFFER 40 int main() { char mqname[NAMESIZE], msgrv[BUFFER]; mqd_t mqdes; struct timespec ts; struct mq_attr attr; int unresolved = 0, failure = 0; sprintf(mqname, "/" FUNCTION "_" TEST "_%d", getpid()); attr.mq_msgsize = BUFFER; attr.mq_maxmsg = BUFFER; mqdes = mq_open(mqname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, &attr); if (mqdes == (mqd_t)-1) { perror(ERROR_PREFIX "mq_open"); unresolved = 1; } ts.tv_sec = time(NULL) + 1; ts.tv_nsec = -1; if (mq_timedreceive(mqdes, msgrv, BUFFER, NULL, &ts) == -1) { if (EINVAL != errno) { printf("errno != EINVAL \n"); failure = 1; } } else { printf("FAIL: mq_timedreceive() succeed unexpectly \n"); failure = 1; } if (mq_close(mqdes) != 0) { perror(ERROR_PREFIX "mq_close"); unresolved = 1; } if (mq_unlink(mqname) != 0) { perror(ERROR_PREFIX "mq_unlink"); unresolved = 1; } if (failure==1) { printf("Test FAILED\n"); return PTS_FAIL; } if (unresolved==1) { printf("Test UNRESOLVED\n"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/mq_timedreceive/5-1.c0100644000000000000000000000534207635554423023137 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: crystal.xiong REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * mq_timedreceive() test plan: * Test that if the message queue is empty and O_NONBLOCK is not set, * mq_timedreceive() will block until a message is enqueued on the * message queue. * * NOTE: This test makes some assumptions and has some potential race * conditions, but seems the best way to test for now. */ #include #include #include #include #include #include #include #include #include #include #include #include "posixtest.h" #define TEST "5-1" #define FUNCTION "mq_timedreceive" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " #define NAMESIZE 50 #define BUFFER 40 int main() { char mqname[NAMESIZE], msgrv[BUFFER]; const char *msgptr = "test message "; mqd_t mqdes; int prio = 1; int pid; struct timespec ts; struct mq_attr attr; int unresolved = 0, failure = 0; sprintf(mqname, "/" FUNCTION "_" TEST "_%d", getpid()); attr.mq_msgsize = BUFFER; attr.mq_maxmsg = BUFFER; mqdes = mq_open(mqname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, &attr); if (mqdes == (mqd_t)-1) { perror(ERROR_PREFIX "mq_open"); unresolved = 1; } if ((pid = fork()) != 0) { /* Parent process */ int status; ts.tv_sec = INT32_MAX; ts.tv_nsec = 0; if (mq_timedreceive(mqdes, msgrv, BUFFER, NULL, &ts) > 0) { wait(&status); if (WEXITSTATUS(status)) { printf("mq_send error \n"); unresolved = 1; } } else { printf("mq_timedreceive didn't block on waiting \n"); wait(NULL); /* wait for child to exit */ perror(ERROR_PREFIX "mq_timedreceive"); failure = 1; } if (mq_close(mqdes) != 0) { perror(ERROR_PREFIX "mq_close"); unresolved = 1; } if (mq_unlink(mqname) != 0) { perror(ERROR_PREFIX "mq_unlink"); unresolved = 1; } if (failure==1) { printf("Test FAILED\n"); return PTS_FAIL; } if (unresolved==1) { printf("Test UNRESOLVED\n"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } else { /* Child Process */ sleep(2); /* sleep 2 seconds, assume that parent will block on waiting then */ if (mq_send(mqdes, msgptr, strlen(msgptr), prio) == -1) { perror(ERROR_PREFIX "mq_send"); return PTS_UNRESOLVED; } return 0; } return PTS_UNRESOLVED; } posixtestsuite/conformance/interfaces/mq_timedreceive/17-2.c0100644000000000000000000000406007634324276023217 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: crystal.xiong REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * mq_timedreceive() test plan: * mq_timedreceive() will fail with EINVAL if message queue is * empty and nanoseconds field value of abs_timeout greater than * or equal to 1000 million. * */ #include #include #include #include #include #include #include #include #include #include #include #include "posixtest.h" #define TEST "17-2" #define FUNCTION "mq_timedreceive" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " #define NAMESIZE 50 #define BUFFER 40 int main() { char mqname[NAMESIZE], msgrv[BUFFER]; mqd_t mqdes; struct timespec ts; struct mq_attr attr; int unresolved = 0, failure = 0; sprintf(mqname, "/" FUNCTION "_" TEST "_%d", getpid()); attr.mq_msgsize = BUFFER; attr.mq_maxmsg = BUFFER; mqdes = mq_open(mqname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, &attr); if (mqdes == (mqd_t)-1) { perror(ERROR_PREFIX "mq_open"); unresolved = 1; } ts.tv_sec = time(NULL) + 1; ts.tv_nsec = 1000000000; if (mq_timedreceive(mqdes, msgrv, BUFFER, NULL, &ts) == -1) { if (EINVAL != errno) { printf("errno != EINVAL \n"); failure = 1; } } else { printf("FAIL: mq_timedreceive() succeed unexpectly \n"); failure = 1; } if (mq_close(mqdes) != 0) { perror(ERROR_PREFIX "mq_close"); unresolved = 1; } if (mq_unlink(mqname) != 0) { perror(ERROR_PREFIX "mq_unlink"); unresolved = 1; } if (failure==1) { printf("Test FAILED\n"); return PTS_FAIL; } if (unresolved==1) { printf("Test UNRESOLVED\n"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/mq_timedreceive/speculative/0040755000000000000000000000000010515625173025004 5ustar rootrootposixtestsuite/conformance/interfaces/mq_timedreceive/speculative/10-2.c0100644000000000000000000000421410336125321025514 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: crystal.xiong REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * mq_timedreceive test plan: * If message can be removed from message queue immediately, the validity * of timout need not be checked. * * This is a speculative test because if abs_timeout _is_ checked for * validity, it is not a failure. */ #include #include #include #include #include #include #include #include #include "posixtest.h" #define TEST "10-2" #define FUNCTION "mq_timedreceive" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " #define NAMESIZE 50 #define BUFFER 40 int main() { char mqname[NAMESIZE], msgrv[BUFFER]; const char *msgptr = "test message"; mqd_t mqdes; unsigned rvprio, sdprio = 1; struct timespec ts; struct mq_attr attr; int unresolved = 0; sprintf(mqname, "/" FUNCTION "_" TEST "_%d", getpid()); attr.mq_msgsize = BUFFER; attr.mq_maxmsg = BUFFER; mqdes = mq_open(mqname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, &attr); if (mqdes == (mqd_t)-1) { perror(ERROR_PREFIX "mq_open"); unresolved = 1; } if (mq_send(mqdes, msgptr, strlen(msgptr), sdprio) != 0) { perror(ERROR_PREFIX "mq_send"); unresolved = 1; } ts.tv_sec = time(NULL) + 1; ts.tv_nsec = -1; if (mq_timedreceive(mqdes, msgrv, BUFFER, &rvprio, &ts) == -1) { printf("mq_timedreceive() did fail on invalid abs_time\n"); } else { printf("mq_timedreceive() did not fail on invalid abs_time\n"); } if (mq_close(mqdes) != 0) { perror(ERROR_PREFIX "mq_close"); unresolved = 1; } if (mq_unlink(mqname) != 0) { perror(ERROR_PREFIX "mq_unlink"); unresolved = 1; } if (unresolved==1) { printf("Test UNRESOLVED\n"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/mq_timedreceive/14-1.c0100644000000000000000000000401607634324276023214 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: crystal.xiong REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * mq_timedreceive() test plan: * mq_timedreceive() will fail with EBADF, if mqdes is not a valid message * message queue descriptor. */ #include #include #include #include #include #include #include #include #include #include #include "posixtest.h" #define TEST "14-1" #define FUNCTION "mq_timedreceive" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " #define NAMESIZE 50 #define BUFFER 40 int main() { char mqname[NAMESIZE]; mqd_t mqdes; char msgrv[BUFFER]; struct timespec ts; struct mq_attr attr; int unresolved = 0, failure = 0; sprintf(mqname, "/" FUNCTION "_" TEST "_%d", getpid()); attr.mq_msgsize = BUFFER; attr.mq_maxmsg = BUFFER; mqdes = mq_open(mqname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, &attr); if (mqdes == (mqd_t)-1) { perror(ERROR_PREFIX "mq_open()"); unresolved = 1; } mqdes = mqdes + 1; ts.tv_sec = time(NULL) + 1; ts.tv_nsec = 0; if (mq_timedreceive(mqdes, msgrv, BUFFER, NULL, &ts) == -1) { if (EBADF != errno) { printf("errno != EBADF \n"); failure = 1; } } else { printf("mq_timedreceive() succeed unexpectly \n"); failure = 1; } if (mq_close(mqdes - 1) != 0) { perror(ERROR_PREFIX "mq_close()"); unresolved=1; } if (mq_unlink(mqname) != 0) { perror(ERROR_PREFIX "mq_unlink()"); unresolved=1; } if (failure==1) { printf("Test FAILED\n"); return PTS_FAIL; } if (unresolved==1) { printf("Test UNRESOLVED\n"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/mq_timedreceive/5-2.c0100644000000000000000000000526407635270533023140 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: crystal.xiong REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * mq_timedreceive() test plan: * Test that if the message queue is empty and O_NONBLOCK is not set, * mq_timedreceive() will block until timeout expires. * */ #include #include #include #include #include #include #include #include #include #include #include "posixtest.h" #define TEST "5-2" #define FUNCTION "mq_timedreceive" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " #define NAMESIZE 50 #define BUFFER 40 #define TIMEOUT 3 int blocking = 0; void exit_handler(int signo) { printf("FAIL: the case is blocking, exit anyway \n"); blocking = 1; return; } int main() { char mqname[NAMESIZE], msgrv[BUFFER]; mqd_t mqdes; struct timespec ts; time_t oldtime, newtime; struct mq_attr attr; pid_t pid; int unresolved = 0, failure = 0; sprintf(mqname, "/" FUNCTION "_" TEST "_%d", getpid()); attr.mq_msgsize = BUFFER; attr.mq_maxmsg = BUFFER; mqdes = mq_open(mqname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, &attr); if (mqdes == (mqd_t)-1) { perror(ERROR_PREFIX "mq_open"); unresolved = 1; } if ((pid = fork()) != 0) { /* Parent process */ struct sigaction act; act.sa_handler=exit_handler; act.sa_flags=0; sigemptyset(&act.sa_mask); sigaction(SIGABRT, &act, 0); ts.tv_sec = time(NULL) + TIMEOUT; ts.tv_nsec = 0; oldtime = time(NULL); mq_timedreceive(mqdes, msgrv, BUFFER, NULL, &ts); newtime = time(NULL); if ((newtime - oldtime) < TIMEOUT) { printf("FAIL: mq_timedreceive didn't block until timout expires\n"); failure = 1; } /* Parent is not blocking, let child abort */ kill(pid, SIGABRT); if (mq_close(mqdes) != 0) { perror(ERROR_PREFIX "mq_close"); unresolved = 1; } if (mq_unlink(mqname) != 0) { perror(ERROR_PREFIX "mq_unlink"); unresolved = 1; } if (failure==1 || blocking==1) { printf("Test FAILED\n"); return PTS_FAIL; } if (unresolved==1) { printf("Test UNRESOLVED\n"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } else { sleep(TIMEOUT + 3); /* Parent is probably blocking send a signal to let it abort */ kill(getppid(), SIGABRT); return 0; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/mq_timedreceive/16-1.sh0100755000000000000000000000075007633331012023373 0ustar rootroot#!/bin/sh # Copyright (c) 2003, Intel Corporation. All rights reserved. # Created by: crystal.xiong REMOVE-THIS AT intel DOT com # This file is licensed under the GPL license. For the full content # of this license, see the COPYING file at the top level of this # source tree. # mq_timedreceive() will fail with EINTR if mq_receive() is interrupted by a signal. # This is tested implicitly via assertion 5. echo "Tested implicitly via assertion 5. See output for status" exit 0 posixtestsuite/conformance/interfaces/mq_timedreceive/18-1.c0100644000000000000000000000534007635273115023215 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: crystal.xiong REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * mq_timedreceive() test plan: * mq_timedreceive() will fail with ETIMEDOUT when O_NONBLOCK is not * set and no message arrived before the timout expired. * */ #include #include #include #include #include #include #include #include #include #include #include #include "posixtest.h" #define TEST "18-1" #define FUNCTION "mq_timedreceive" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " #define NAMESIZE 50 #define BUFFER 40 #define TIMEOUT 3 int blocking = 0; void exit_handler(int signo) { printf("FAIL: the case is blocking, exit anyway \n"); blocking = 1; return; } int main() { char mqname[NAMESIZE], msgrv[BUFFER]; mqd_t mqdes; struct timespec ts; pid_t pid; struct mq_attr attr; int unresolved = 0, failure = 0; sprintf(mqname, "/" FUNCTION "_" TEST "_%d", getpid()); attr.mq_msgsize = BUFFER; attr.mq_maxmsg = BUFFER; mqdes = mq_open(mqname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, &attr); if (mqdes == (mqd_t)-1) { perror(ERROR_PREFIX "mq_open"); unresolved = 1; } if ((pid = fork()) != 0) { /* Parent process */ struct sigaction act; act.sa_handler=exit_handler; act.sa_flags=0; sigemptyset(&act.sa_mask); sigaction(SIGABRT, &act, 0); ts.tv_sec = time(NULL) + TIMEOUT; ts.tv_nsec = 0; if (mq_timedreceive(mqdes, msgrv, BUFFER, NULL, &ts) == -1) { if (ETIMEDOUT != errno) { printf("errno != ETIMEDOUT \n"); failure = 1; } } else { printf("FAIL: mq_timedreceive() succeed unexpectly \n"); failure = 1; } /* parent is not blocking on mq_timedreceive, kill child */ kill(pid, SIGABRT); if (mq_close(mqdes) != 0) { perror(ERROR_PREFIX "mq_close"); unresolved = 1; } if (mq_unlink(mqname) != 0) { perror(ERROR_PREFIX "mq_unlink"); unresolved = 1; } if (failure==1 || blocking==1) { printf("Test FAILED\n"); return PTS_FAIL; } if (unresolved==1) { printf("Test UNRESOLVED\n"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } else { sleep(TIMEOUT + 3); /* Parent is probably blocking, send a signal to let it abort */ kill(getppid(), SIGABRT); return 0; } } posixtestsuite/conformance/interfaces/mq_timedreceive/1-1.c0100644000000000000000000000616110336125321023112 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: crystal.xiong REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * mq_timedreceive test plan: * mq_timedreceive will receive the oldest of the highest priority messages * from the message queue. The selected message will be removed from the * queue and copied to the buffer pointed by the msg_ptr argument. */ #include #include #include #include #include #include #include #include #include "posixtest.h" #define TEST "1-1" #define FUNCTION "mq_timedreceive" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " #define NAMESIZE 50 #define BUFFER 40 int main() { char mqname[NAMESIZE], msgrv1[BUFFER], msgrv2[BUFFER]; const char *msgptr1 = "test message 1"; const char *msgptr2 = "test message 2"; mqd_t mqdes; unsigned rvprio, sdprio1 = 1, sdprio2 = 2; struct timespec ts; struct mq_attr attr; int unresolved = 0, failure = 0; sprintf(mqname, "/" FUNCTION "_" TEST "_%d", getpid()); attr.mq_msgsize = BUFFER; attr.mq_maxmsg = BUFFER; mqdes = mq_open(mqname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, &attr); if (mqdes == (mqd_t)-1) { perror(ERROR_PREFIX "mq_open"); unresolved = 1; } if (mq_send(mqdes, msgptr1, strlen(msgptr1), sdprio1) != 0) { perror(ERROR_PREFIX "mq_send"); unresolved = 1; } if (mq_send(mqdes, msgptr2, strlen(msgptr2), sdprio2) != 0) { perror(ERROR_PREFIX "mq_send"); unresolved = 1; } ts.tv_sec = time(NULL) + 1; ts.tv_nsec = 0; if (mq_timedreceive(mqdes, msgrv1, BUFFER, &rvprio, &ts) == -1) { perror(ERROR_PREFIX "mq_timedreceive"); failure = 1; } if (strncmp(msgptr2, msgrv1, strlen(msgptr2)) != 0) { printf("FAIL: mq_timedreceive didn't receive the highest priority message\n"); failure = 1; } if (rvprio != sdprio2) { printf("FAIL: receive priority %d != send priority %d \n", rvprio, sdprio2); failure = 1; } ts.tv_sec = time(NULL) + 1; ts.tv_nsec = 0; if (mq_timedreceive(mqdes, msgrv2, BUFFER, &rvprio, &ts) == -1) { perror(ERROR_PREFIX "mq_timedreceive"); failure = 1; } if (strncmp(msgptr1, msgrv2, strlen(msgptr1)) != 0) { printf("FAIL: mq_timedreceive didn't receive the correct message\n"); failure = 1; } if (rvprio != sdprio1) { printf("FAIL: receive priority %d != send priority %d \n", rvprio, sdprio1); failure = 1; } if (mq_close(mqdes) != 0) { perror(ERROR_PREFIX "mq_close"); unresolved = 1; } if (mq_unlink(mqname) != 0) { perror(ERROR_PREFIX "mq_unlink"); unresolved = 1; } if (failure==1) { printf("Test FAILED\n"); return PTS_FAIL; } if (unresolved==1) { printf("Test UNRESOLVED\n"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/mq_timedreceive/10-2.c0100644000000000000000000000467410506741142023206 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * adam.li@intel.com */ /* * If the message can be removed from the message queue immedietely, * the operation will never fail and the validity of abs_timeout * need not be checked. * Test Steps: * 1. Set the abs_timeout to be invalid, when there is message * than can be removed from the message queue immediately. * 2. The validity of abs_timeout will not be checked. */ #include #include #include #include #include #include #include #include #include #include "posixtest.h" #define TEST "10-1" #define FUNCTION "mq_timedreceive" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " #define NAMESIZE 50 #define BUFFER 40 int main() { char mqname[NAMESIZE], msgrv[BUFFER]; const char *msgptr = "test message"; mqd_t mqdes; unsigned int rvprio; int sdprio = 1; struct timespec ts; struct mq_attr attr; int unresolved = 0, failure = 0; sprintf(mqname, "/" FUNCTION "_" TEST "_%d", getpid()); attr.mq_msgsize = BUFFER; attr.mq_maxmsg = BUFFER; mqdes = mq_open(mqname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, &attr); if (mqdes == (mqd_t)-1) { perror(ERROR_PREFIX "mq_open"); unresolved = 1; } if (mq_send(mqdes, msgptr, strlen(msgptr), sdprio) != 0) { perror(ERROR_PREFIX "mq_send"); unresolved = 1; } sleep(1); /* wait for a while */ ts.tv_sec = time(NULL) -1; /* No wait */ ts.tv_nsec = -1; /* Invalid */ if (mq_timedreceive(mqdes, msgrv, BUFFER, &rvprio, &ts) == -1) { if (errno == EINVAL) printf("FAIL: the validity of abs_timeout " "is checked\n"); else perror("Unexpected error at mq_timedreceive"); failure = 1; } if (mq_close(mqdes) != 0) { perror(ERROR_PREFIX "mq_close"); unresolved = 1; } if (mq_unlink(mqname) != 0) { perror(ERROR_PREFIX "mq_unlink"); unresolved = 1; } if (failure==1) { printf("Test FAILED\n"); return PTS_FAIL; } if (unresolved==1) { printf("Test UNRESOLVED\n"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/mq_timedreceive/11-1.c0100644000000000000000000000567507634324276023225 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: crystal.xiong REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * mq_timedreceive test plan: * On success, mq_timedreceive will return the length of the selected message * and the message will be removed from the queue. * step: * 1. send two messages to the message queue * 2. call mq_timedreceive() twice, if the two received messages are the same, * which means the first mq_timedreceive does not remove the message from * the queue, the test will fail. Otherwise, the test will pass. */ #include #include #include #include #include #include #include #include #include "posixtest.h" #define TEST "11-1" #define FUNCTION "mq_timedreceive" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " #define NAMESIZE 50 #define BUFFER 40 int main() { char mqname[NAMESIZE], msgrv1[BUFFER], msgrv2[BUFFER]; const char *msgptr1 = "test message1"; const char *msgptr2 = "test message2 with differnet length"; mqd_t mqdes; int prio1 = 1, prio2 = 2; struct timespec ts; struct mq_attr attr; int unresolved = 0, failure = 0; sprintf(mqname, "/" FUNCTION "_" TEST "_%d", getpid()); attr.mq_msgsize = BUFFER; attr.mq_maxmsg = BUFFER; mqdes = mq_open(mqname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, &attr); if (mqdes == (mqd_t)-1) { perror(ERROR_PREFIX "mq_open"); unresolved = 1; } if (mq_send(mqdes, msgptr1, strlen(msgptr1), prio1) != 0) { perror(ERROR_PREFIX "mq_send"); unresolved = 1; } if (mq_send(mqdes, msgptr2, strlen(msgptr2), prio2) != 0) { perror(ERROR_PREFIX "mq_send"); unresolved = 1; } ts.tv_sec = time(NULL) + 1; ts.tv_nsec = 0; if (mq_timedreceive(mqdes, msgrv1, BUFFER, NULL, &ts) != strlen(msgptr2)) { printf("FAIL: mq_timedreceive didn't return the selected message size correctly \n"); failure = 1; } if (mq_timedreceive(mqdes, msgrv2, BUFFER, NULL, &ts) != strlen(msgptr1)) { printf("FAIL: mq_timedreceive didn't return the selected message size correctly \n"); failure = 1; } if (!strcmp(msgrv1,msgrv2)) { printf("FAIL: mq_timedreceive received the same message twice\n"); failure = 1; } if (mq_close(mqdes) != 0) { perror(ERROR_PREFIX "mq_close"); unresolved = 1; } if (mq_unlink(mqname) != 0) { perror(ERROR_PREFIX "mq_unlink"); unresolved = 1; } if (failure==1) { printf("Test FAILED\n"); return PTS_FAIL; } if (unresolved==1) { printf("Test UNRESOLVED\n"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/mq_timedreceive/10-1.c0100644000000000000000000000411710336125321023171 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: crystal.xiong REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * mq_timedreceive test plan: * If message can be removed from message queue immediately, * mq_timedreceive will never fail with a timeout. */ #include #include #include #include #include #include #include #include #include "posixtest.h" #define TEST "10-1" #define FUNCTION "mq_timedreceive" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " #define NAMESIZE 50 #define BUFFER 40 int main() { char mqname[NAMESIZE], msgrv[BUFFER]; const char *msgptr = "test message"; mqd_t mqdes; unsigned rvprio, sdprio = 1; struct timespec ts; struct mq_attr attr; int unresolved = 0, failure = 0; sprintf(mqname, "/" FUNCTION "_" TEST "_%d", getpid()); attr.mq_msgsize = BUFFER; attr.mq_maxmsg = BUFFER; mqdes = mq_open(mqname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, &attr); if (mqdes == (mqd_t)-1) { perror(ERROR_PREFIX "mq_open"); unresolved = 1; } if (mq_send(mqdes, msgptr, strlen(msgptr), sdprio) != 0) { perror(ERROR_PREFIX "mq_send"); unresolved = 1; } ts.tv_sec = time(NULL) - 1; ts.tv_nsec = 0; if (mq_timedreceive(mqdes, msgrv, BUFFER, &rvprio, &ts) == -1) { perror("FAIL: mq_receive fails unexpectly \n"); failure = 1; } if (mq_close(mqdes) != 0) { perror(ERROR_PREFIX "mq_close"); unresolved = 1; } if (mq_unlink(mqname) != 0) { perror(ERROR_PREFIX "mq_unlink"); unresolved = 1; } if (failure==1) { printf("Test FAILED\n"); return PTS_FAIL; } if (unresolved==1) { printf("Test UNRESOLVED\n"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/mq_timedreceive/13-1.c0100644000000000000000000000377307634324276023224 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: crystal.xiong REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * mq_timedreceive() test plan: * mq_timedreceive() will fail with EAGAIN, if message queue is empty and * O_NONBLOCK is set in the message queue, */ #include #include #include #include #include #include #include #include #include #include #include "posixtest.h" #define TEST "13-1" #define FUNCTION "mq_timedreceive" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " #define NAMESIZE 50 #define BUFFER 40 int main() { char mqname[NAMESIZE], msgrv[BUFFER]; mqd_t mqdes; struct timespec ts; struct mq_attr attr; int unresolved = 0, failure = 0; sprintf(mqname, "/" FUNCTION "_" TEST "_%d", getpid()); attr.mq_msgsize = BUFFER; attr.mq_maxmsg = BUFFER; mqdes = mq_open(mqname, O_CREAT | O_NONBLOCK | O_RDWR, S_IRUSR | S_IWUSR, &attr); if (mqdes == (mqd_t)-1) { perror(ERROR_PREFIX "mq_open"); unresolved = 1; } ts.tv_sec = time(NULL) + 1; ts.tv_nsec = 0; if (mq_timedreceive(mqdes, msgrv, BUFFER, NULL, &ts) == -1) { if (EAGAIN != errno) { printf("errno != EAGAIN \n"); failure = 1; } } else { printf("mq_timedreceive() succeed unexpectly\n"); failure = 1; } if (mq_close(mqdes) != 0) { perror(ERROR_PREFIX "mq_close"); unresolved = 1; } if (mq_unlink(mqname) != 0) { perror(ERROR_PREFIX "mq_unlink"); unresolved = 1; } if (failure==1) { printf("Test FAILED\n"); return PTS_FAIL; } if (unresolved==1) { printf("Test UNRESOLVED\n"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/mq_timedreceive/18-2.c0100644000000000000000000000534407635273037023225 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: crystal.xiong REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * mq_timedreceive() test plan: * Test that if abs_timeout has already passed the time * at the time mq_timedreceive() called, the timeout will expire. * mq_timedreceive() will return with ETIMEDOUT. * */ #include #include #include #include #include #include #include #include #include #include #include #include "posixtest.h" #define TEST "18-2" #define FUNCTION "mq_timedreceive" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " #define NAMESIZE 50 #define BUFFER 40 #define TIMEOUT 3 int blocking = 0; void exit_handler(int signo) { printf("FAIL: the case is blocking, exit anyway \n"); blocking = 1; return; } int main() { char mqname[NAMESIZE], msgrv[BUFFER]; mqd_t mqdes; struct timespec ts; struct mq_attr attr; pid_t pid; int unresolved = 0, failure = 0; sprintf(mqname, "/" FUNCTION "_" TEST "_%d", getpid()); attr.mq_msgsize = BUFFER; attr.mq_maxmsg = BUFFER; mqdes = mq_open(mqname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, &attr); if (mqdes == (mqd_t)-1) { perror(ERROR_PREFIX "mq_open"); unresolved = 1; } if ((pid = fork()) != 0) { /* Parent process */ struct sigaction act; act.sa_handler=exit_handler; act.sa_flags=0; sigemptyset(&act.sa_mask); sigaction(SIGABRT, &act, 0); ts.tv_sec = time(NULL) - TIMEOUT; ts.tv_nsec = 0; if (mq_timedreceive(mqdes, msgrv, BUFFER, NULL, &ts) != -1) { printf("FAIL: mq_timedreceive succeed unexpectely\n"); failure = 1; } else { if (errno != ETIMEDOUT) { printf("errno != ETIMEDOUT\n"); failure = 1; } } /* Parent is not blocking, let child abort */ kill(pid, SIGABRT); if (mq_close(mqdes) != 0) { perror(ERROR_PREFIX "mq_close"); unresolved = 1; } if (mq_unlink(mqname) != 0) { perror(ERROR_PREFIX "mq_unlink"); unresolved = 1; } if (failure==1 || blocking==1) { printf("Test FAILED\n"); return PTS_FAIL; } if (unresolved==1) { printf("Test UNRESOLVED\n"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } else { sleep(TIMEOUT + 3); /* Parent is probably blocking send a signal to let it abort */ kill(getppid(), SIGABRT); return 0; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/mq_timedreceive/17-3.c0100644000000000000000000000405007634324276023217 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: crystal.xiong REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * mq_timedreceive() test plan: * mq_timedreceive() will fail with EINVAL if message queue is * empty and nanoseconds field value of abs_timeout greater than * 1000 million. * */ #include #include #include #include #include #include #include #include #include #include #include #include "posixtest.h" #define TEST "17-3" #define FUNCTION "mq_timedreceive" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " #define NAMESIZE 50 #define BUFFER 40 int main() { char mqname[NAMESIZE], msgrv[BUFFER]; mqd_t mqdes; struct timespec ts; struct mq_attr attr; int unresolved = 0, failure = 0; sprintf(mqname, "/" FUNCTION "_" TEST "_%d", getpid()); attr.mq_msgsize = BUFFER; attr.mq_maxmsg = BUFFER; mqdes = mq_open(mqname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, &attr); if (mqdes == (mqd_t)-1) { perror(ERROR_PREFIX "mq_open"); unresolved = 1; } ts.tv_sec = time(NULL) + 1; ts.tv_nsec = 1000000000 + 1; if (mq_timedreceive(mqdes, msgrv, BUFFER, NULL, &ts) == -1) { if (EINVAL != errno) { printf("errno != EINVAL \n"); failure = 1; } } else { printf("FAIL: mq_timedreceive() succeed unexpectly \n"); failure = 1; } if (mq_close(mqdes) != 0) { perror(ERROR_PREFIX "mq_close"); unresolved = 1; } if (mq_unlink(mqname) != 0) { perror(ERROR_PREFIX "mq_unlink"); unresolved = 1; } if (failure==1) { printf("Test FAILED\n"); return PTS_FAIL; } if (unresolved==1) { printf("Test UNRESOLVED\n"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/mq_timedreceive/7-1.c0100644000000000000000000000366507634324276023147 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: crystal.xiong REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * mq_timedreceive() test plan: * If message queue is empty and O_NONBLOCK is set in the message queue, * no message will be removed from the queue, mq_timedreceive will return an * error. */ #include #include #include #include #include #include #include #include #include #include "posixtest.h" #define TEST "7-1" #define FUNCTION "mq_timedreceive" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " #define NAMESIZE 50 #define BUFFER 40 int main() { char mqname[NAMESIZE], msgrv[BUFFER]; mqd_t mqdes; struct timespec ts; struct mq_attr attr; int unresolved = 0, failure = 0; sprintf(mqname, "/" FUNCTION "_" TEST "_%d", getpid()); attr.mq_msgsize = BUFFER; attr.mq_maxmsg = BUFFER; mqdes = mq_open(mqname, O_CREAT | O_NONBLOCK | O_RDWR, S_IRUSR | S_IWUSR, &attr); if (mqdes == (mqd_t)-1) { perror(ERROR_PREFIX "mq_open"); unresolved = 1; } ts.tv_sec = time(NULL) + 1; ts.tv_nsec = 0; if (mq_timedreceive(mqdes, msgrv, BUFFER, NULL, &ts) != -1) { printf("mq_timedreceive succeed unexpectly \n"); failure = 1; } if (mq_close(mqdes) != 0) { perror(ERROR_PREFIX "mq_close"); unresolved = 1; } if (mq_unlink(mqname) != 0) { perror(ERROR_PREFIX "mq_unlink"); unresolved = 1; } if (failure==1) { printf("Test FAILED\n"); return PTS_FAIL; } if (unresolved==1) { printf("Test UNRESOLVED\n"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/mq_timedreceive/assertions.xml0100644000000000000000000001065607635273151025405 0ustar rootroot mq_timedreceive() receive the oldest of the highest priority message(s) from the message queue specified by mqdes. The selected message will be removed from the queue and copied to the buffer pointed to by the msg_ptr argument. mq_timedreceive() will fail and return an error if the size of the buffer in bytes, specified by the msg_len argument, is less than the mq_msgsize attribute of the message queue. if msg_len is greater than SSIZE_MAX, the result is implementation-defined. If msg_prio is not NULL, the priority of the selected message will be stored in the location referenced by msg_prio. If the specified message queue is empty and O_NONBLOCK is not set, then mq_timedreceive() will block until a message is enqueued on the message queue or until a signal interrupts mq_timedreceive() or until the time specified by abs_timeout expires. abs_timeout refers to the absolute time at which the timeout will expire (current time meets or exceeds that time). If there are more than one thread waiting to receive a message when a message arrives at an empty queue and the Priority Scheduling option is supported, then the thread with highest priority that has been waiting the longest will receive the message. If Priority Scheduling option is not supported, then it is unspecified which waiting thread is able to receive the message. If the specified message queue is empty and O_NONBLOCK is set, no message will be removed from the queue, and mq_timedreceive() will return an error. If Timers option is supported, then abs_timeout is based on CLOCK_REALTIME. Otherwise, the timeout is based on the system clock (time() function). The timeout has the same resolution as the clock it is based on. If the message can be removed from the message queue immedietely, the operation will never fail and the validity of abs_timeout need not be checked. mq_timedreceive() will return the length of the selected message in bytes and the message will be removed from the queue on success. mq_timedreceive() will return -1 on failure, no message will be removed from the queue, and the errno will be set. mq_timedreceive() will return EAGAIN if O_NONBLOCK is set and the message queue is empty. mq_timedreceive() will return EBADF if mqdes is not a valid message queue descriptor open for reading. mq_timedreceive() will return EMSGSIZE if the specified buffer size, msg_len, is less than the message size attribute of the message queue. mq_timedreceive() will return EINTR if it is interrupted by a signal mq_timedreceive() will return EINVAL if the process or thread have blocked, and abs_timeout had a tv_nsec field less than zero or greater than or equal to 1000 million. mq_timedreceive() will return ETIMEDOUT if O_NONBLOCK was not set when open the message queue, and no message arrived on the queue before the timeout expired. If abs_timeout has already passed the time at the time mq_timedreceive() called, the timeout shall expire too. mq_timedreceive() will return EBADMSG if the implementation has detected a data corruption problem with the message. posixtestsuite/conformance/interfaces/mq_timedreceive/coverage.txt0100644000000000000000000000045110025533101024772 0ustar rootrootThis document defines the coverage for the mq_timedreceive function: Assertion Tested? 1 YES 2 YES 3 NO - implementation-defined, won't test. 4 YES 5 YES 6 NO - won't test. 7 YES 8 YES 9 NO 10 YES 11 YES 12 YES 13 YES 14 YES 15 YES 16 YES 17 YES 18 YES 19 NO - won't test posixtestsuite/conformance/interfaces/mq_timedreceive/5-3.c0100644000000000000000000000525207635554567023152 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: crystal.xiong REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * mq_timedreceive() test plan: * Test that if the message queue is empty and O_NONBLOCK is not set, * mq_timedreceive() will block until mq_timedreceive() is interrupted by a * signal. * * NOTE: This test makes some assumptions and has some potential race * conditions, but seems the best way to test for now. */ #include #include #include #include #include #include #include #include #include #include #include #include "posixtest.h" #define TEST "5-3" #define FUNCTION "mq_timedreceive" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " #define NAMESIZE 50 #define BUFFER 40 void stopreceive(int signo) { return; } int main() { char mqname[NAMESIZE], msgrv[BUFFER]; mqd_t mqdes; int pid; struct mq_attr attr; struct timespec ts; int unresolved = 0, failure = 0; sprintf(mqname, "/" FUNCTION "_" TEST "_%d", getpid()); attr.mq_msgsize = BUFFER; attr.mq_maxmsg = BUFFER; mqdes = mq_open(mqname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, &attr); if (mqdes == (mqd_t)-1) { perror(ERROR_PREFIX "mq_open"); unresolved = 1; } if ((pid = fork()) != 0) { /* Parent process */ struct sigaction act; act.sa_handler = stopreceive; act.sa_flags = 0; sigemptyset(&act.sa_mask); sigaction(SIGABRT, &act, 0); ts.tv_sec = INT32_MAX; ts.tv_nsec = 0; if (mq_timedreceive(mqdes, msgrv, BUFFER, NULL, &ts) == -1) { wait(NULL); if (EINTR != errno) { printf("errno != EINTR \n"); failure = 1; } } else { wait(NULL); printf("mq_timedreceive() succeed unexpectly \n"); failure = 1; } if (mq_close(mqdes) != 0) { perror("mq_close() did not return success"); unresolved=1; } if (mq_unlink(mqname) != 0) { perror("mq_unlink() did not return success"); unresolved=1; } if (failure==1) { printf("Test FAILED\n"); return PTS_FAIL; } if (unresolved==1) { printf("Test UNRESOLVED\n"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } else { /* Child Process */ sleep(1); /* give time to parent to set up handler */ /* send signal to parent */ kill(getppid(), SIGABRT); } } posixtestsuite/conformance/interfaces/mq_timedreceive/8-1.c0100644000000000000000000000555110025532737023133 0ustar rootroot/* * Copyright (c) 2003 - 2004, Intel Corporation. All rights reserved. * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * adam.li@intel.com */ /* * If Timers option is supported, then abs_timeout is based on * CLOCK_REALTIME. * Otherwise, the timeout is based on the system clock (time() function). */ #include #include #include #include #include #include #include #include #include #include #include "posixtest.h" #define TEST "8-1" #define FUNCTION "mq_timedreceive" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " #define NAMESIZE 50 #define BUFFER 40 #define TIMEOUT 3 int blocking = 0; void exit_handler(int signo) { printf("FAIL: the case is blocking, exit anyway \n"); blocking = 1; return; } int main() { char mqname[NAMESIZE], msgrv[BUFFER]; mqd_t mqdes; struct timespec ts; time_t oldtime, newtime; struct mq_attr attr; pid_t pid; int unresolved = 0, failure = 0; sprintf(mqname, "/" FUNCTION "_" TEST "_%d", getpid()); attr.mq_msgsize = BUFFER; attr.mq_maxmsg = BUFFER; mqdes = mq_open(mqname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, &attr); if (mqdes == (mqd_t)-1) { perror(ERROR_PREFIX "mq_open"); unresolved = 1; } if ((pid = fork()) != 0) { /* Parent process */ struct sigaction act; act.sa_handler=exit_handler; act.sa_flags=0; sigemptyset(&act.sa_mask); sigaction(SIGABRT, &act, 0); #ifdef _POSIX_TIMERS printf("Using CLOCK_REALTIME\n"); clock_gettime(CLOCK_REALTIME, &ts); oldtime = ts.tv_sec; ts.tv_sec = ts.tv_sec + TIMEOUT; #else ts.tv_sec = time(NULL) + TIMEOUT; oldtime = time(NULL); #endif ts.tv_nsec = 0; mq_timedreceive(mqdes, msgrv, BUFFER, NULL, &ts); #ifdef _POSIX_TIMERS clock_gettime(CLOCK_REALTIME, &ts); newtime = ts.tv_sec; #else newtime = time(NULL); #endif if ((newtime - oldtime) < TIMEOUT) { printf("FAIL: mq_timedreceive didn't block until timout expires\n"); failure = 1; } /* Parent is not blocking, let child abort */ kill(pid, SIGABRT); wait(NULL); if (mq_close(mqdes) != 0) { perror(ERROR_PREFIX "mq_close"); unresolved = 1; } if (mq_unlink(mqname) != 0) { perror(ERROR_PREFIX "mq_unlink"); unresolved = 1; } if (failure==1 || blocking==1) { printf("Test FAILED\n"); return PTS_FAIL; } if (unresolved==1) { printf("Test UNRESOLVED\n"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } else { sleep(TIMEOUT + 3); /* Parent is probably blocking send a signal to let it abort */ kill(getppid(), SIGABRT); return 0; } } posixtestsuite/conformance/interfaces/mq_timedreceive/2-1.c0100644000000000000000000000414707633331012023117 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: crystal.xiong REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * mq_timedreceive test plan: * If the buffer size is less than the mq_msgsize attribute, the function * will fail and return an error. */ #include #include #include #include #include #include #include #include #include "posixtest.h" #define TEST "2-1" #define FUNCTION "mq_timedreceive" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " #define NAMESIZE 50 #define BUFFER 20 int main() { char mqname[NAMESIZE], msgrv[BUFFER]; const char *msgptr = "test message"; mqd_t mqdes; int prio = 1; struct mq_attr mqstat; struct timespec ts; int unresolved = 0, failure = 0; sprintf(mqname, "/" FUNCTION "_" TEST "_%d", getpid()); memset(&mqstat,0,sizeof(mqstat)); mqstat.mq_msgsize = BUFFER + 1; mqstat.mq_maxmsg = BUFFER + 1; mqdes = mq_open(mqname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, &mqstat); if (mqdes == (mqd_t)-1) { perror(ERROR_PREFIX "mq_open"); unresolved = 1; } if (mq_send(mqdes, msgptr, strlen(msgptr), prio) != 0) { perror(ERROR_PREFIX "mq_send"); unresolved = 1; } ts.tv_sec = time(NULL) + 1; ts.tv_nsec = 0; if (mq_timedreceive(mqdes, msgrv, BUFFER, NULL, &ts) > 0) { printf("FAIL: mq_timedreceive succeed unexpectly \n"); failure = 1; } if (mq_close(mqdes) != 0) { perror(ERROR_PREFIX "mq_close"); unresolved = 1; } if (mq_unlink(mqname) != 0) { perror(ERROR_PREFIX "mq_unlink"); unresolved = 1; } if (failure==1) { printf("Test FAILED\n"); return PTS_FAIL; } if (unresolved==1) { printf("Test UNRESOLVED\n"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/mq_timedreceive/4-1.sh0100755000000000000000000000102307633331012023302 0ustar rootroot#!/bin/sh # Copyright (c) 2003, Intel Corporation. All rights reserved. # Created by: crystal.xiong REMOVE-THIS AT intel DOT com # This file is licensed under the GPL license. For the full content # of this license, see the COPYING file at the top level of this # source tree. # Test if the msg_prio is not NULL, the priority of the selected # message will be stored in the location pointed by msg_prio. # This is tested implicitly via assertion 1. echo "Tested implicitly via assertion 1. See output for status" exit 0 posixtestsuite/conformance/interfaces/mq_timedreceive/12-1.sh0100755000000000000000000000104007633331012023360 0ustar rootroot#!/bin/sh # Copyright (c) 2003, Intel Corporation. All rights reserved. # Created by: crystal.xiong REMOVE-THIS AT intel DOT com # This file is licensed under the GPL license. For the full content # of this license, see the COPYING file at the top level of this # source tree. # Test on failure, no message will be removed from the queue, # the funcion will return a value of -1. # This is tested implicitly via assertion 13,14,15,16,17,18,19 echo "Tested implicitly via assertion 13,14,15,16,17,18,19. See output for status" exit 0 posixtestsuite/conformance/interfaces/fork/0040755000000000000000000000000010515625164020257 5ustar rootrootposixtestsuite/conformance/interfaces/fork/17-1.c0100644000000000000000000001131010171003333020763 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertion: * * For the SCHED_FIFO and SCHED_RR scheduling policies, * the child process inherits the policy and priority * settings of the parent process during a fork() function. * The steps are: * -> Change the parent's scheduling policy and parameter * -> fork * -> check the child inherited the same policy. * The test fails if the child does not inherit the parent's values. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /********************************************************************************************/ /****************************** standard includes *****************************************/ /********************************************************************************************/ #include #include #include #include #include #include #include #include #include /********************************************************************************************/ /****************************** Test framework *****************************************/ /********************************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /********************************************************************************************/ /********************************** Configuration ******************************************/ /********************************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif #define POLICY SCHED_RR /********************************************************************************************/ /*********************************** Test case *****************************************/ /********************************************************************************************/ /* The main test function. */ int main( int argc, char * argv[] ) { int ret, param, status; pid_t child, ctl; struct sched_param sp; /* Initialize output */ output_init(); /* Change process policy and parameters */ sp.sched_priority = param = sched_get_priority_max( POLICY ); if ( sp.sched_priority == -1 ) { UNRESOLVED( errno, "Failed to get max priority value" ); } ret = sched_setscheduler( 0, POLICY, &sp ); if ( ret == -1 ) { UNRESOLVED( errno, "Failed to change process scheduling policy" ); } /* Create the child */ child = fork(); if ( child == ( pid_t ) - 1 ) { UNRESOLVED( errno, "Failed to fork" ); } /* child */ if ( child == ( pid_t ) 0 ) { /* Check the scheduling policy */ ret = sched_getscheduler( 0 ); if ( ret == -1 ) { UNRESOLVED( errno, "Failed to read scheduling policy in child" ); } if ( ret != POLICY ) { FAILED( "The scheduling policy was not inherited" ); } ret = sched_getparam( 0, &sp ); if ( ret != 0 ) { UNRESOLVED( errno, "Failed to read scheduling parameter in child" ); } if ( sp.sched_priority != param ) { FAILED( "The scheduling parameter was not inherited" ); } /* We're done */ exit( PTS_PASS ); } /* Parent joins the child */ ctl = waitpid( child, &status, 0 ); if ( ctl != child ) { UNRESOLVED( errno, "Waitpid returned the wrong PID" ); } if ( ( !WIFEXITED( status ) ) || ( WEXITSTATUS( status ) != PTS_PASS ) ) { FAILED( "Child exited abnormally" ); } /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/fork/19-1.c0100644000000000000000000001264110171003333020775 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertion: * * The opened message queue descriptors are copied to the child process and * refer to the same object. * The steps are: * -> Open a message queue descriptor. * -> Send a message to this descriptor. * -> fork * -> check if that the child's message count for this descriptor is 1. * The test fails if the child reports 0 message count * or if it fails to read the descriptor. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /********************************************************************************************/ /****************************** standard includes *****************************************/ /********************************************************************************************/ #include #include #include #include #include #include #include #include #include #include /********************************************************************************************/ /****************************** Test framework *****************************************/ /********************************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /********************************************************************************************/ /********************************** Configuration ******************************************/ /********************************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif /********************************************************************************************/ /*********************************** Test case *****************************************/ /********************************************************************************************/ /* The main test function. */ int main( int argc, char * argv[] ) { int ret, status; pid_t child, ctl; mqd_t mq; char rcv[ 20 ]; struct mq_attr mqa; /* Initialize output */ output_init(); /* Create a message queue descriptor */ mqa.mq_maxmsg = 2; mqa.mq_msgsize = 20; mq = mq_open( "/fork_19_1_mq" , O_RDWR | O_CREAT | O_NONBLOCK , S_IRUSR | S_IWUSR , &mqa ); if ( mq == ( mqd_t ) - 1 ) { UNRESOLVED( errno, "Failed to create the message queue descriptor" ); } /* Send 1 message to this message queue */ ret = mq_send( mq, "I'm your father...", 19, 0 ); if ( ret != 0 ) { UNRESOLVED( errno, "Failed to send the message" ); } /* Check the message has been queued */ ret = mq_getattr( mq, &mqa ); if ( ret != 0 ) { UNRESOLVED( errno, "Failed to get message queue attributes" ); } if ( mqa.mq_curmsgs != 1 ) { UNRESOLVED( -1, "The queue information does not show the new message" ); } /* Create the child */ child = fork(); if ( child == ( pid_t ) - 1 ) { UNRESOLVED( errno, "Failed to fork" ); } /* child */ if ( child == ( pid_t ) 0 ) { ret = mq_getattr( mq, &mqa ); if ( ret != 0 ) { FAILED( "Failed to get message queue attributes in child" ); } if ( mqa.mq_curmsgs != 1 ) { FAILED( "The queue information does not show the message in child" ); } /* Now, receive the message */ ret = mq_receive( mq, rcv, 20, NULL ); if ( ret != 19 ) /* expected message size */ { UNRESOLVED( errno, "Failed to receive the message" ); } #if VERBOSE > 0 output( "Received message: %s\n", rcv ); #endif /* We're done */ exit( PTS_PASS ); } /* Parent joins the child */ ctl = waitpid( child, &status, 0 ); if ( ctl != child ) { UNRESOLVED( errno, "Waitpid returned the wrong PID" ); } if ( ( !WIFEXITED( status ) ) || ( WEXITSTATUS( status ) != PTS_PASS ) ) { FAILED( "Child exited abnormally" ); } /* Check the message has been unqueued */ ret = mq_getattr( mq, &mqa ); if ( ret != 0 ) { UNRESOLVED( errno, "Failed to get message queue attributes the 2nd time" ); } if ( mqa.mq_curmsgs != 0 ) { FAILED( "The message received in child was not dequeued." ); } /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/fork/17-2.c0100644000000000000000000001131210171003333020766 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertion: * * For the SCHED_FIFO and SCHED_RR scheduling policies, * the child process inherits the policy and priority * settings of the parent process during a fork() function. * The steps are: * -> Change the parent's scheduling policy and parameter * -> fork * -> check the child inherited the same policy. * The test fails if the child does not inherit the parent's values. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /********************************************************************************************/ /****************************** standard includes *****************************************/ /********************************************************************************************/ #include #include #include #include #include #include #include #include #include /********************************************************************************************/ /****************************** Test framework *****************************************/ /********************************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /********************************************************************************************/ /********************************** Configuration ******************************************/ /********************************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif #define POLICY SCHED_FIFO /********************************************************************************************/ /*********************************** Test case *****************************************/ /********************************************************************************************/ /* The main test function. */ int main( int argc, char * argv[] ) { int ret, param, status; pid_t child, ctl; struct sched_param sp; /* Initialize output */ output_init(); /* Change process policy and parameters */ sp.sched_priority = param = sched_get_priority_max( POLICY ); if ( sp.sched_priority == -1 ) { UNRESOLVED( errno, "Failed to get max priority value" ); } ret = sched_setscheduler( 0, POLICY, &sp ); if ( ret == -1 ) { UNRESOLVED( errno, "Failed to change process scheduling policy" ); } /* Create the child */ child = fork(); if ( child == ( pid_t ) - 1 ) { UNRESOLVED( errno, "Failed to fork" ); } /* child */ if ( child == ( pid_t ) 0 ) { /* Check the scheduling policy */ ret = sched_getscheduler( 0 ); if ( ret == -1 ) { UNRESOLVED( errno, "Failed to read scheduling policy in child" ); } if ( ret != POLICY ) { FAILED( "The scheduling policy was not inherited" ); } ret = sched_getparam( 0, &sp ); if ( ret != 0 ) { UNRESOLVED( errno, "Failed to read scheduling parameter in child" ); } if ( sp.sched_priority != param ) { FAILED( "The scheduling parameter was not inherited" ); } /* We're done */ exit( PTS_PASS ); } /* Parent joins the child */ ctl = waitpid( child, &status, 0 ); if ( ctl != child ) { UNRESOLVED( errno, "Waitpid returned the wrong PID" ); } if ( ( !WIFEXITED( status ) ) || ( WEXITSTATUS( status ) != PTS_PASS ) ) { FAILED( "Child exited abnormally" ); } /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/fork/4-1.c0100644000000000000000000000756310171003333020716 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertion: * * The parent process ID of the child is the process ID of the parent (caller of fork()) * The steps are: * -> create a child * -> check its parent process ID is the PID of its parent. * The test fails if the IDs differ. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /********************************************************************************************/ /****************************** standard includes *****************************************/ /********************************************************************************************/ #include #include #include #include #include #include #include #include /********************************************************************************************/ /****************************** Test framework *****************************************/ /********************************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /********************************************************************************************/ /********************************** Configuration ******************************************/ /********************************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif /********************************************************************************************/ /*********************************** Test case *****************************************/ /********************************************************************************************/ /* The main test function. */ int main(int argc, char * argv[]) { int status; pid_t child, ctl; /* Initialize output */ output_init(); /* Get parent process ID */ ctl = getpid(); /* Create the child */ child = fork(); if (child == (pid_t) -1) { UNRESOLVED(errno, "Failed to fork"); } /* child */ if (child == (pid_t) 0) { /* Check the parent process ID */ if (ctl != getppid()) { FAILED("The parent process ID is not the PID of the parent"); } /* We're done */ exit(PTS_PASS); } /* Parent joins the child */ ctl = waitpid(child, &status, 0); if (ctl != child) { UNRESOLVED(errno, "Waitpid returned the wrong PID"); } if ((!WIFEXITED(status)) || (WEXITSTATUS(status) != PTS_PASS)) { UNRESOLVED(status, "Child exited abnormally"); } /* Test passed */ #if VERBOSE > 0 output("Test passed\n"); #endif PASSED; } posixtestsuite/conformance/interfaces/fork/22-1.c0100644000000000000000000001317510171003333020772 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertion: * * The CPU-time clock of the new process/ new process's thread is initialized to 0. * The steps are: * -> compute until the parent process CPU-time clock is greater than 1 sec. * -> fork * -> check the child process process CPU time and thread CPU time clocks. * The test fails if any of these clocks are > 1sec. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /********************************************************************************************/ /****************************** standard includes *****************************************/ /********************************************************************************************/ #include #include #include #include #include #include #include #include #include /********************************************************************************************/ /****************************** Test framework *****************************************/ /********************************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /********************************************************************************************/ /********************************** Configuration ******************************************/ /********************************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif /********************************************************************************************/ /*********************************** Test case *****************************************/ /********************************************************************************************/ /* The main test function. */ int main( int argc, char * argv[] ) { int ret, status; pid_t child, ctl; long ctp, ctt; clockid_t clp, clt; struct timespec tp; /* Initialize output */ output_init(); ctp = sysconf( _SC_CPUTIME ); ctt = sysconf( _SC_THREAD_CPUTIME ); if ( ( ctp == -1 ) && ( ctt == -1 ) ) { UNTESTED( "The testcase needs CPUTIME or THREAD_CPUTIME support" ); } #if VERBOSE > 0 output( "System abilities:\n" ); output( " _POSIX_CPUTIME : %ld\n", ctp ); output( " _POSIX_THREAD_CPUTIME : %ld\n", ctt ); #endif if ( ctp > 0 ) { ret = clock_getcpuclockid( 0, &clp ); if ( ret != 0 ) { UNRESOLVED( ret, "Unable to get cpu-time clock id of the process" ); } do { ret = clock_gettime( clp, &tp ); if ( ret != 0 ) { UNRESOLVED( errno, "Failed to read CPU time clock" ); } } while ( tp.tv_sec < 1 ); } if ( ctt > 0 ) { ret = pthread_getcpuclockid( pthread_self(), &clt ); if ( ret != 0 ) { UNRESOLVED( ret, "Unable to get cpu-time clock id of the thread" ); } do { ret = clock_gettime( clt, &tp ); if ( ret != 0 ) { UNRESOLVED( errno, "Failed to read thread CPU time clock" ); } } while ( tp.tv_sec < 1 ); } /* Create the child */ child = fork(); if ( child == ( pid_t ) - 1 ) { UNRESOLVED( errno, "Failed to fork" ); } /* child */ if ( child == ( pid_t ) 0 ) { if ( ctp > 0 ) { ret = clock_getcpuclockid( 0, &clp ); if ( ret != 0 ) { UNRESOLVED( ret, "Unable to get cpu-time clock id of the process" ); } ret = clock_gettime( clp, &tp ); if ( ret != 0 ) { UNRESOLVED( errno, "Failed to read CPU time clock" ); } if ( tp.tv_sec > 0 ) { FAILED( "The process CPU-time clock was not reset in child\n" ); } } if ( ctt > 0 ) { ret = pthread_getcpuclockid( pthread_self(), &clt ); if ( ret != 0 ) { UNRESOLVED( ret, "Unable to get cpu-time clock id of the thread" ); } ret = clock_gettime( clt, &tp ); if ( ret != 0 ) { UNRESOLVED( errno, "Failed to read thread CPU time clock" ); } if ( tp.tv_sec > 0 ) { FAILED( "The thread CPU-time clock was not reset in child\n" ); } } /* We're done */ exit( PTS_PASS ); } /* Parent joins the child */ ctl = waitpid( child, &status, 0 ); if ( ctl != child ) { UNRESOLVED( errno, "Waitpid returned the wrong PID" ); } if ( ( !WIFEXITED( status ) ) || ( WEXITSTATUS( status ) != PTS_PASS ) ) { FAILED( "Child exited abnormally" ); } /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/fork/14-1.c0100644000000000000000000001304410171003333020766 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertion: * * Opened semaphores are inherited in the child process.. * The steps are: * -> Open 2 named semaphores, then unlink one. * -> fork * -> The child tries and posts both semaphores, then terminates. * -> The parent waits for the child, then check the semaphores were posted * The test fails if any semaphore has not been posted in the child. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /********************************************************************************************/ /****************************** standard includes *****************************************/ /********************************************************************************************/ #include #include #include #include #include #include #include #include #include #include /********************************************************************************************/ /****************************** Test framework *****************************************/ /********************************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /********************************************************************************************/ /********************************** Configuration ******************************************/ /********************************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif /********************************************************************************************/ /*********************************** Test case *****************************************/ /********************************************************************************************/ /* The main test function. */ int main( int argc, char * argv[] ) { int ret, status; pid_t child, ctl; sem_t * sem_linked, *sem_unlinked; /* Initialize output */ output_init(); sem_linked = sem_open( "/fork_14_1a", O_CREAT, O_RDWR, 0 ); if ( sem_linked == SEM_FAILED ) { UNRESOLVED( errno, "Failed to create the named semaphore" ); } sem_unlinked = sem_open( "/fork_14_1b", O_CREAT, O_RDWR, 0 ); if ( sem_unlinked == SEM_FAILED ) { UNRESOLVED( errno, "Failed to create the named semaphore" ); } ret = sem_unlink( "/fork_14_1b" ); if ( ret != 0 ) { UNRESOLVED( errno, "Failed to unlink the semaphore" ); } /* Create the child */ child = fork(); if ( child == ( pid_t ) - 1 ) { UNRESOLVED( errno, "Failed to fork" ); } /* child */ if ( child == ( pid_t ) 0 ) { do { ret = sem_post( sem_linked ); } while ( ( ret != 0 ) && ( errno == EINTR ) ); if ( ret != 0 ) { UNRESOLVED( errno, "Failed to post semaphore A" ); } do { ret = sem_post( sem_unlinked ); } while ( ( ret != 0 ) && ( errno == EINTR ) ); if ( ret != 0 ) { UNRESOLVED( errno, "Failed to post semaphore B" ); } /* We're done */ exit( PTS_PASS ); } /* Parent joins the child */ ctl = waitpid( child, &status, 0 ); if ( ctl != child ) { UNRESOLVED( errno, "Waitpid returned the wrong PID" ); } if ( ( !WIFEXITED( status ) ) || ( WEXITSTATUS( status ) != PTS_PASS ) ) { FAILED( "Child exited abnormally" ); } /* Check both semaphores have been posted */ do { ret = sem_trywait( sem_linked ); } while ( ( ret != 0 ) && ( errno == EINTR ) ); if ( ret != 0 ) { if ( errno == EAGAIN ) { FAILED( "Child did not inherit the semaphore A" ); } else { UNRESOLVED( errno, "sem_trywait failed" ); } } do { ret = sem_trywait( sem_unlinked ); } while ( ( ret != 0 ) && ( errno == EINTR ) ); if ( ret != 0 ) { if ( errno == EAGAIN ) { FAILED( "Child did not inherit the semaphore B" ); } else { UNRESOLVED( errno, "sem_trywait failed" ); } } ret = sem_unlink( "/fork_14_1a" ); if ( ret != 0 ) { UNRESOLVED( errno, "Failed to unlink semaphore A" ); } ret = sem_close( sem_linked ); if ( ret != 0 ) { UNRESOLVED( errno, "Failed to close semaphore A" ); } ret = sem_close( sem_unlinked ); if ( ret != 0 ) { UNRESOLVED( errno, "Failed to close semaphore B" ); } /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/fork/18-1.c0100644000000000000000000001176610171003333021003 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertion: * * The per-process timers are not inherited. * The steps are: * -> Create a per-process timer * -> fork * -> check if the timer exists in child. * The test fails if the timer expires in child (timer signal is delivered). */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /********************************************************************************************/ /****************************** standard includes *****************************************/ /********************************************************************************************/ #include #include #include #include #include #include #include #include #include #include /********************************************************************************************/ /****************************** Test framework *****************************************/ /********************************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /********************************************************************************************/ /********************************** Configuration ******************************************/ /********************************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif /********************************************************************************************/ /*********************************** Test case *****************************************/ /********************************************************************************************/ /* Global control value */ int notified; /* Notification routine */ void notification( union sigval sv ) { if ( sv.sival_int != SIGUSR1 ) { output( "Got signal %d, expected %d\n", sv.sival_int, SIGUSR1 ); UNRESOLVED( 1, "Unexpected notification" ); } notified = ( int ) getpid(); } /* The main test function. */ int main( int argc, char * argv[] ) { int ret, status; pid_t child, ctl; timer_t tmr; struct sigevent se; struct itimerspec it; /* Initialize output */ output_init(); notified = 0; /* Create the timer */ se.sigev_notify = SIGEV_THREAD; se.sigev_signo = 0; se.sigev_value.sival_int = SIGUSR1; se.sigev_notify_function = ¬ification; se.sigev_notify_attributes = NULL; /* default detached thread */ ret = timer_create( CLOCK_REALTIME, &se, &tmr ); if ( ret != 0 ) { UNRESOLVED( errno, "Failed to create a timer" ); } /* Arm the timer */ it.it_interval.tv_nsec = 0; it.it_interval.tv_sec = 0; it.it_value.tv_sec = 0; it.it_value.tv_nsec = 500000000; /* 0.5 sec */ ret = timer_settime( tmr, 0, &it, NULL ); /* Create the child */ child = fork(); if ( child == ( pid_t ) - 1 ) { UNRESOLVED( errno, "Failed to fork" ); } /* child */ if ( child == ( pid_t ) 0 ) { sleep( 1 ); if ( notified != 0 ) { if ( notified == ( int ) getpid() ) { FAILED( "Per-Process Timer was inherited in child" ); } else { output( "Notification occured before the child forked" ); } } /* We're done */ exit( PTS_PASS ); } /* Parent joins the child */ ctl = waitpid( child, &status, 0 ); if ( ctl != child ) { UNRESOLVED( errno, "Waitpid returned the wrong PID" ); } if ( ( !WIFEXITED( status ) ) || ( WEXITSTATUS( status ) != PTS_PASS ) ) { FAILED( "Child exited abnormally" ); } if ( notified != ( int ) getpid() ) { output( "Notified value: %d\n", notified ); UNRESOLVED( -1, "No notification occured -- per process timers do not work?" ); } /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/fork/12-1.c0100644000000000000000000001476710171003333021001 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertion: * * The child process is created with no pending signal * The steps are: * -> block SIGUSR1 and SIGUSR2 * -> send those signals and wait they are pending * -> fork * -> check the signals are blocked but not pending in the new process. * The test fails if the signals are pending or if * they are not blocked (this counters assertion 2). */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /********************************************************************************************/ /****************************** standard includes *****************************************/ /********************************************************************************************/ #include #include #include #include #include #include #include #include #include /********************************************************************************************/ /****************************** Test framework *****************************************/ /********************************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /********************************************************************************************/ /********************************** Configuration ******************************************/ /********************************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif /********************************************************************************************/ /*********************************** Test case *****************************************/ /********************************************************************************************/ /* The main test function. */ int main( int argc, char * argv[] ) { int ret, status; pid_t child, ctl; sigset_t mask, pending; /* Initialize output */ output_init(); /* block SIGUSR1 and SIGUSR2 */ ret = sigemptyset( &mask ); if ( ret != 0 ) { UNRESOLVED( errno, "Failed to initialize signal set" ); } ret = sigaddset( &mask, SIGUSR1 ); if ( ret != 0 ) { UNRESOLVED( errno, "Failed to add SIGUSR1 to signal set" ); } ret = sigaddset( &mask, SIGUSR2 ); if ( ret != 0 ) { UNRESOLVED( errno, "Failed to add SIGUSR2 to signal set" ); } ret = sigprocmask( SIG_BLOCK, &mask, NULL ); if ( ret != 0 ) { UNRESOLVED( errno, "Sigprocmask failed" ); } /* Make the signals pending */ ret = kill( getpid(), SIGUSR1 ); if ( ret != 0 ) { UNRESOLVED( errno, "failed to kill with SIGUSR1" ); } ret = kill( getpid(), SIGUSR2 ); if ( ret != 0 ) { UNRESOLVED( errno, "failed to kill with SIGUSR2" ); } do { ret = sigpending( &pending ); if ( ret != 0 ) { UNRESOLVED( errno, "failed to examine pending signal set" ); } ret = sigismember( &pending, SIGUSR1 ); if ( ret < 0 ) { UNRESOLVED( errno, "Unable to check signal USR1 presence" ); } if ( ret == 1 ) { ret = sigismember( &pending, SIGUSR2 ); if ( ret < 0 ) { UNRESOLVED( errno, "Unable to check signal USR2 presence" ); } } } while ( ret != 1 ); #if VERBOSE > 0 output( "SIGUSR1 and SIGUSR2 are pending, we can fork\n" ); #endif /* Create the child */ child = fork(); if ( child == ( pid_t ) - 1 ) { UNRESOLVED( errno, "Failed to fork" ); } /* child */ if ( child == ( pid_t ) 0 ) { /* Examine the current blocked signal set. USR1 & USR2 shall be present */ ret = sigprocmask( 0, NULL, &mask ); if ( ret != 0 ) { UNRESOLVED( errno, "Sigprocmask failed in child" ); } ret = sigismember( &mask, SIGUSR1 ); if ( ret < 0 ) { UNRESOLVED( errno, "Unable to check signal USR1 presence" ); } if ( ret == 0 ) { FAILED( "The new process does not mask SIGUSR1 as its parent" ); } ret = sigismember( &mask, SIGUSR2 ); if ( ret < 0 ) { UNRESOLVED( errno, "Unable to check signal USR2 presence" ); } if ( ret == 0 ) { FAILED( "The new process does not mask SIGUSR2 as its parent" ); } #if VERBOSE > 0 output( "SIGUSR1 and SIGUSR2 are blocked in child\n" ); #endif /* Examine pending signals */ ret = sigpending( &pending ); if ( ret != 0 ) { UNRESOLVED( errno, "failed to examine pending signal set in child" ); } ret = sigismember( &pending, SIGUSR1 ); if ( ret < 0 ) { UNRESOLVED( errno, "Unable to check signal USR1 presence" ); } if ( ret != 0 ) { FAILED( "The new process was created with SIGUSR1 pending" ); } ret = sigismember( &pending, SIGUSR2 ); if ( ret < 0 ) { UNRESOLVED( errno, "Unable to check signal USR2 presence" ); } if ( ret != 0 ) { FAILED( "The new process was created with SIGUSR2 pending" ); } #if VERBOSE > 0 output( "SIGUSR1 and SIGUSR2 are not pending in child\n" ); #endif /* We're done */ exit( PTS_PASS ); } /* Parent joins the child */ ctl = waitpid( child, &status, 0 ); if ( ctl != child ) { UNRESOLVED( errno, "Waitpid returned the wrong PID" ); } if ( ( !WIFEXITED( status ) ) || ( WEXITSTATUS( status ) != PTS_PASS ) ) { FAILED( "Child exited abnormally" ); } /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/fork/1-1.c0100644000000000000000000001321110171003333020676 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertion: * * fork() creates a new process. * The steps are: * -> create a new process * -> the parent and the child sleep 1 sec (check concurrent execution) * -> the child posts a semaphore, the parents waits for thsi semaphore * (check the child really executes) * -> join and check that total execution time is < 2 sec. * The test fails if the duration is > 2 seconds or if semaphore is not posted. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /********************************************************************************************/ /****************************** standard includes *****************************************/ /********************************************************************************************/ #include #include #include #include #include #include #include #include #include #include #include /********************************************************************************************/ /****************************** Test framework *****************************************/ /********************************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /********************************************************************************************/ /********************************** Configuration ******************************************/ /********************************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif #define SEM_NAME "/semfork1_1" /********************************************************************************************/ /*********************************** Test case *****************************************/ /********************************************************************************************/ /* The main test function. */ int main(int argc, char * argv[]) { int ret, status; pid_t child, ctl; sem_t *sem; struct timespec tsini, tsfin; /* Initialize output */ output_init(); /* read current time */ ret = clock_gettime(CLOCK_REALTIME, &tsini); if (ret != 0) { UNRESOLVED(errno, "Unable to read CLOCK_REALTIME clock"); } /* Set temporary value in tsfin for semaphore timeout */ tsfin.tv_sec = tsini.tv_sec + 3; tsfin.tv_nsec = tsini.tv_nsec; /* Create the child */ child = fork(); if (child == (pid_t) -1) { UNRESOLVED(errno, "Failed to fork"); } /* Open the semaphore */ sem = sem_open(SEM_NAME, O_CREAT, O_RDWR, 0); if (sem == (sem_t *)SEM_FAILED) { UNRESOLVED(errno, "Failed to open the semaphore"); } /* sleep 1 second */ sleep(1); /* child posts the semaphore and terminates */ if (child == (pid_t) 0) { do { ret = sem_post(sem); } while ((ret == -1) && (errno == EINTR)); if (ret != 0) { UNRESOLVED(errno, "Failed to post the semaphore"); } ret = sem_close(sem); if (ret != 0) { UNRESOLVED(errno, "Failed to close the semaphore"); } /* The child stops here */ exit(0); } /* Parent waits for the semaphore */ do { ret = sem_timedwait(sem, &tsfin); } while ((ret != 0) && (errno == EINTR)); if (ret != 0) { if (errno == ETIMEDOUT) { FAILED("The new process does not execute"); } UNRESOLVED(errno, "Failed to wait for the semaphore"); } /* We don't need the semaphore anymore */ ret = sem_unlink(SEM_NAME); if (ret != 0) { UNRESOLVED(errno, "Unable to unlink the semaphore"); } ret = sem_close(sem); if (ret != 0) { UNRESOLVED(errno, "Failed to close the semaphore"); } /* Parent joins the child */ ctl = waitpid(child, &status, 0); if (ctl != child) { UNRESOLVED(errno, "Waitpid returned the wrong PID"); } if ((!WIFEXITED(status)) || (WEXITSTATUS(status) != 0)) { UNRESOLVED(status, "Child exited abnormally"); } /* Check the global duration */ ret = clock_gettime(CLOCK_REALTIME, &tsfin); if (ret != 0) { UNRESOLVED(errno, "Unable to read CLOCK_REALTIME clock"); } if (tsfin.tv_nsec < tsini.tv_nsec) tsfin.tv_sec -= 1; status = tsfin.tv_sec - tsini.tv_sec; if (status >= 2) { /* the operation was more than 2 secs long */ FAILED("the processes did not execute concurrently"); } /* Test passed */ #if VERBOSE > 0 output("Test passed\n"); #endif PASSED; } posixtestsuite/conformance/interfaces/fork/9-1.c0100644000000000000000000001002010171003333020701 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertion: * * The time left until an alarm clock is triggered is reset to zero, * and the alarm, if any, is canceled * The steps are: * -> Trig an alarm * -> fork * -> Check the alarm is not running in the child process. * -> join the child * The test fails if the child has a pending alarm. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /********************************************************************************************/ /****************************** standard includes *****************************************/ /********************************************************************************************/ #include #include #include #include #include #include #include #include /********************************************************************************************/ /****************************** Test framework *****************************************/ /********************************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /********************************************************************************************/ /********************************** Configuration ******************************************/ /********************************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif /********************************************************************************************/ /*********************************** Test case *****************************************/ /********************************************************************************************/ /* The main test function. */ int main( int argc, char * argv[] ) { int ret, status; pid_t child, ctl; /* Initialize output */ output_init(); /* Set the alarm pending */ alarm( 10 ); /* Check the alarm() behavior */ ret = alarm( 10 ); if ( ret == 0 ) { FAILED( "the alarm() routine does not behave as expected" ); } /* Create the child */ child = fork(); if ( child == ( pid_t ) - 1 ) { UNRESOLVED( errno, "Failed to fork" ); } /* child */ if ( child == ( pid_t ) 0 ) { ret = alarm( 10 ); if ( ret != 0 ) { FAILED( "The child alarm pending was not reset." ); } /* We're done */ exit( PTS_PASS ); } /* Parent joins the child */ ctl = waitpid( child, &status, 0 ); if ( ctl != child ) { UNRESOLVED( errno, "Waitpid returned the wrong PID" ); } if ( ( !WIFEXITED( status ) ) || ( WEXITSTATUS( status ) != PTS_PASS ) ) { FAILED( "Child exited abnormally" ); } alarm( 0 ); /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/fork/testfrmw.c0100644000000000000000000000407210171003333022260 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * * This file is a wrapper to use the tests from the NPTL Test & Trace Project * with either the Linux Test Project or the Open POSIX Test Suite. * The following function are defined: * void output_init() * void output_fini() * void output(char * string, ...) * * The are used to output informative text (as a printf). */ #include #include /* We use a mutex to avoid conflicts in traces */ static pthread_mutex_t m_trace = PTHREAD_MUTEX_INITIALIZER; /*****************************************************************************************/ /******************************* stdout module *****************************************/ /*****************************************************************************************/ /* The following functions will output to stdout */ #if (1) void output_init() { /* do nothing */ return; } void output( char * string, ... ) { va_list ap; char *ts="[??:??:??]"; struct tm * now; time_t nw; pthread_mutex_lock(&m_trace); nw = time(NULL); now = localtime(&nw); if (now == NULL) printf(ts); else printf("[%2.2d:%2.2d:%2.2d]", now->tm_hour, now->tm_min, now->tm_sec); va_start( ap, string); vprintf(string, ap); va_end(ap); pthread_mutex_unlock(&m_trace); } void output_fini() { /*do nothing */ return; } #endif posixtestsuite/conformance/interfaces/fork/11-1.c0100644000000000000000000001073010171003333020762 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertion: * * The file locks are not inherited by the child process. * The steps are: * -> lock stdout * -> fork * -> child creates a thread * -> child thread trylock stdout * -> join the child * The test fails if the child thread cannot lock the file * -- this would mean the child process got stdout file lock ownership. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /********************************************************************************************/ /****************************** standard includes *****************************************/ /********************************************************************************************/ #include #include #include #include #include #include #include #include /********************************************************************************************/ /****************************** Test framework *****************************************/ /********************************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /********************************************************************************************/ /********************************** Configuration ******************************************/ /********************************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif /********************************************************************************************/ /*********************************** Test case *****************************************/ /********************************************************************************************/ /* Thread function */ void * threaded( void * arg ) { int ret; ret = ftrylockfile( stdout ); if ( ret != 0 ) { FAILED( "The child process is owning the file lock." ); } #if VERBOSE > 1 output( "The file lock was not inherited in the child process\n" ); #endif return NULL; } /* The main test function. */ int main( int argc, char * argv[] ) { int ret, status; pid_t child, ctl; pthread_t ch; /* Initialize output */ output_init(); /* lock the stdout file */ flockfile( stdout ); /* Create the child */ child = fork(); if ( child == ( pid_t ) - 1 ) { UNRESOLVED( errno, "Failed to fork" ); } /* child */ if ( child == ( pid_t ) 0 ) { ret = pthread_create( &ch, NULL, threaded, NULL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to create a thread" ); } ret = pthread_join( ch, NULL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to join the thread" ); } /* We're done */ exit( PTS_PASS ); } /* Parent sleeps for a while to create contension in case the file lock is inherited */ sleep( 1 ); funlockfile( stdout ); /* Parent joins the child */ ctl = waitpid( child, &status, 0 ); if ( ctl != child ) { UNRESOLVED( errno, "Waitpid returned the wrong PID" ); } if ( ( !WIFEXITED( status ) ) || ( WEXITSTATUS( status ) != PTS_PASS ) ) { FAILED( "Child exited abnormally" ); } /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/fork/6-1.c0100644000000000000000000001146010171003333020707 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertion: * * The opened directory streams are copied to the child process. * Positionning information may be shared between both processes. * The steps are: * -> Open the current directory, * -> Count the directory entries, then rewind. * -> create a child * -> The child counts the directory entries. * The test fails if the directory is read in the parent and not in the child. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /********************************************************************************************/ /****************************** standard includes *****************************************/ /********************************************************************************************/ #include #include #include #include #include #include #include #include #include /********************************************************************************************/ /****************************** Test framework *****************************************/ /********************************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /********************************************************************************************/ /********************************** Configuration ******************************************/ /********************************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif /********************************************************************************************/ /*********************************** Test case *****************************************/ /********************************************************************************************/ int count( DIR * thedir ) { int counter = 0; struct dirent *dp; rewinddir( thedir ); /* Count the directory entries */ do { dp = readdir( thedir ); if ( dp != NULL ) counter++; } while ( dp != NULL ); return counter; } /* The main test function. */ int main( int argc, char * argv[] ) { int ret, status; pid_t child, ctl; int counted; /* the '.' directory pointers */ DIR *dotdir; /* Initialize output */ output_init(); /* Open the directory */ dotdir = opendir( "." ); if ( dotdir == NULL ) { UNRESOLVED( errno, "opendir failed" ); } /* Count entries */ counted = count( dotdir ); #if VERBOSE > 0 output( "Found %d entries in current dir\n", counted ); #endif /* Create the child */ child = fork(); if ( child == ( pid_t ) - 1 ) { UNRESOLVED( errno, "Failed to fork" ); } /* child */ if ( child == ( pid_t ) 0 ) { /* Count in child process */ counted = count( dotdir ); #if VERBOSE > 0 output( "Found %d entries in current dir from child\n", counted ); #endif ret = closedir( dotdir ); if ( ret != 0 ) { UNRESOLVED( errno, "Failed to close dir in child" ); } /* We're done */ exit( PTS_PASS ); } /* Parent joins the child */ ctl = waitpid( child, &status, 0 ); if ( ctl != child ) { UNRESOLVED( errno, "Waitpid returned the wrong PID" ); } if ( ( !WIFEXITED( status ) ) || ( WEXITSTATUS( status ) != PTS_PASS ) ) { FAILED( "Child exited abnormally -- dir stream not copied?" ); } /* close the directory stream */ ret = closedir( dotdir ); if ( ret != 0 ) { UNRESOLVED( errno, "Failed to closedir in parent" ); } /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/fork/messcat_src.txt0100644000000000000000000000171510171003333023311 0ustar rootroot$ Copyright (c) 2004, Bull S.A.. All rights reserved. $ Created by: Sebastien Decugis $ $ This program is free software; you can redistribute it and/or modify it $ under the terms of version 2 of the GNU General Public License as $ published by the Free Software Foundation. $ $ This program is distributed in the hope that it would be useful, but $ WITHOUT ANY WARRANTY; without even the implied warranty of $ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. $ $ You should have received a copy of the GNU General Public License along $ with this program; if not, write the Free Software Foundation, Inc., 59 $ Temple Place - Suite 330, Boston MA 02111-1307, USA. $ $ $ This file is part of the 7-1.c test case for the fork() routine. $set 1 Message set for OPTS fork test case, English language 1 This is the first message 2 And this is the second $set 2 Message set for OPTS fork test case, French language 1 Voici le premier message 2 Et voilà le second posixtestsuite/conformance/interfaces/fork/13-1.c0100644000000000000000000001253010171003333020764 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertion: * * Interval timers are reset in the child process. * The steps are: * -> create an interval timer in the parent process * -> fork * -> check the timer has been cleared in child. * The test fails if the timer is running in the child. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /* The interval timers are an XSI feature */ #ifndef WITHOUT_XOPEN #define _XOPEN_SOURCE 600 #endif /********************************************************************************************/ /****************************** standard includes *****************************************/ /********************************************************************************************/ #include #include #include #include #include #include #include #include #include /********************************************************************************************/ /****************************** Test framework *****************************************/ /********************************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /********************************************************************************************/ /********************************** Configuration ******************************************/ /********************************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif /********************************************************************************************/ /*********************************** Test case *****************************************/ /********************************************************************************************/ #ifndef WITHOUT_XOPEN /* The main test function. */ int main( int argc, char * argv[] ) { int ret, status; pid_t child, ctl; struct itimerval it; /* Initialize output */ output_init(); /* Create the interval timer */ it.it_interval.tv_sec = 15; it.it_interval.tv_usec = 0; it.it_value.tv_sec = 10; it.it_value.tv_usec = 0; ret = setitimer( ITIMER_REAL, &it, NULL ); if ( ret != 0 ) { UNRESOLVED( errno, "Failed to set interval timer for ITIMER_REAL" ); } ret = setitimer( ITIMER_VIRTUAL, &it, NULL ); if ( ret != 0 ) { UNRESOLVED( errno, "Failed to set interval timer for ITIMER_VIRTUAL" ); } ret = setitimer( ITIMER_PROF, &it, NULL ); if ( ret != 0 ) { UNRESOLVED( errno, "Failed to set interval timer for ITIMER_PROF" ); } #if VERBOSE > 0 output( "All interval timers are set.\n" ); #endif /* Create the child */ child = fork(); if ( child == ( pid_t ) - 1 ) { UNRESOLVED( errno, "Failed to fork" ); } /* child */ if ( child == ( pid_t ) 0 ) { /* Check we get the correct information: timer is reset */ ret = getitimer( ITIMER_REAL, &it ); if ( ret != 0 ) { UNRESOLVED( errno, "Failed to read ITIMER_REAL in child" ); } if ( it.it_value.tv_sec != 0 ) { FAILED( "Timer ITIMER_REAL was not reset in child" ); } ret = getitimer( ITIMER_VIRTUAL, &it ); if ( ret != 0 ) { UNRESOLVED( errno, "Failed to read ITIMER_VIRTUAL in child" ); } if ( it.it_value.tv_sec != 0 ) { FAILED( "Timer ITIMER_VIRTUAL was not reset in child" ); } ret = getitimer( ITIMER_PROF, &it ); if ( ret != 0 ) { UNRESOLVED( errno, "Failed to read ITIMER_PROF in child" ); } if ( it.it_value.tv_sec != 0 ) { FAILED( "Timer ITIMER_PROF was not reset in child" ); } /* We're done */ exit( PTS_PASS ); } /* Parent joins the child */ ctl = waitpid( child, &status, 0 ); if ( ctl != child ) { UNRESOLVED( errno, "Waitpid returned the wrong PID" ); } if ( ( !WIFEXITED( status ) ) || ( WEXITSTATUS( status ) != PTS_PASS ) ) { FAILED( "Child exited abnormally" ); } /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } #else /* WITHOUT_XOPEN */ int main( int argc, char * argv[] ) { output_init(); UNTESTED( "This testcase requires XSI features" ); } #endif posixtestsuite/conformance/interfaces/fork/7-1.c0100644000000000000000000001275510171003333020720 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertion: * * The child process gets a copy of the parent message catalog descriptor. * The steps are: * -> Create a message catalog file from the "messcat_src.txt" file * -> Open this catalog * -> fork * -> Check that the child can read from the message catalog. * The test fails if the message catalog is read in the parent and not in the child. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /********************************************************************************************/ /****************************** standard includes *****************************************/ /********************************************************************************************/ #include #include #include #include #include #include #include #include #include /********************************************************************************************/ /****************************** Test framework *****************************************/ /********************************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /********************************************************************************************/ /********************************** Configuration ******************************************/ /********************************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif #define PATH_OFFSET "conformance/interfaces/fork/" /********************************************************************************************/ /*********************************** Test case *****************************************/ /********************************************************************************************/ void read_catalog( nl_catd cat, char * who ) { char * msg = NULL; int i, j; errno = 0; #if VERBOSE > 0 output( "Reading the message catalog from %s...\n", who ); #endif for ( i = 1; i <= 2; i++ ) { for ( j = 1; j <= 2; j++ ) { msg = catgets( cat, i, j, "not found" ); if ( errno != 0 ) { UNRESOLVED( errno, "catgets returned an error" ); } #if VERBOSE > 1 output( "set %i msg %i: %s\n", i, j, msg ); #endif } } #if VERBOSE > 0 output( "Message catalog read successfully in %s\n", who ); #endif } /* The main test function. */ int main( int argc, char * argv[] ) { int ret, status; pid_t child, ctl; nl_catd messcat; /* Initialize output */ output_init(); /* Generate the message catalog file from the text sourcefile */ if ( system( NULL ) ) { ret = system( "gencat mess.cat " PATH_OFFSET "messcat_src.txt" ); if ( ret != 0 ) { output( "Unable to find messcat_src.txt in standard directory %s\n", PATH_OFFSET ); output( "Trying local dir\n" ); ret = system( "gencat mess.cat messcat_src.txt" ); if ( ret != 0 ) { output( "Could not find the source file for message catalog.\n" \ "You may need to execute gencat yourself.\n" ); } } } /* Try opening the message catalog file */ messcat = catopen( "./mess.cat", 0 ); if ( messcat == ( nl_catd ) - 1 ) { UNRESOLVED( errno, "Could not open ./mess.cat. You may need to do a gencat before executing this testcase" ); } /* Read the message catalog */ read_catalog( messcat, "parent" ); /* Create the child */ child = fork(); if ( child == ( pid_t ) - 1 ) { UNRESOLVED( errno, "Failed to fork" ); } /* child */ if ( child == ( pid_t ) 0 ) { read_catalog( messcat, "child" ); /* We're done */ exit( PTS_PASS ); } /* Parent joins the child */ ctl = waitpid( child, &status, 0 ); if ( ctl != child ) { UNRESOLVED( errno, "Waitpid returned the wrong PID" ); } if ( ( !WIFEXITED( status ) ) || ( WEXITSTATUS( status ) != PTS_PASS ) ) { FAILED( "Child exited abnormally" ); } /* We can now clean up the message catalog file */ ret = catclose( messcat ); if ( ret != 0 ) { UNRESOLVED( errno, "Failed to close the message catalog" ); } /* Try removing the message catalog file */ system( "rm -f mess.cat" ); /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/fork/assertions.xml0100644000000000000000000000753110164301736023172 0ustar rootroot fork() creates a new process. The new process is a copy of the original process -- unless specified otherwise below. The new process' ID does not match any existing process or group ID. The parent process ID (ppid) of the child process is the process ID (pid) of the parent process (caller of fork()). The opened file descriptors are copied to the child process and refer to the same object. The opened directory streams are copied to the child process. Positioning information may be shared between both processes. The child process gets a copy of the parent message catalog descriptor. tms_utime, tms_stime, tms_cutime, and tms_cstime values are set to 0 in the child process. The time left until an alarm clock signal is reset to zero, and the alarm, if any, is canceled. semadj values are cleared. The file locks are not inherited by the child process. The child process is created with no pending signals. Interval timers are reset in the child process. The opened semaphores are inherited in the child process. The child process does not inherit memory locks set by the parent process with mlock or mlockall. Memory mappings created in the parent are retained in the child process. If the mapping is MAP_PRIVATE, any modification done after the fork() is visible only to the process doing the modification. For the SCHED_RR and SCHED_FIFO scheduling policies, the child process inherits the policy and priority settings of the parent process during the fork() execution. The per-process timers are not inherited. The opened message queue descriptors are copied to the child process and refer to the same object. Asynchronous IO operations are not inherited by the child. The new process has only one thread. The CPU-time clocks of the new process/ new process' thread are initialized to 0. fork() returns 0 to the child and the child PID to the parent process when succesful. fork() returns -1, errno is set to EAGAIN, and no child process is created if the system lacks a resource to create the new process or CHILD_MAX process are already running. posixtestsuite/conformance/interfaces/fork/21-1.c0100644000000000000000000001175710171003333020775 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertion: * * The new process has only one thread. * The steps are: * -> create a thread. * -> fork * -> Check that the thread is not running in the new process image. * The test fails if the thread is executing in the child process. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /********************************************************************************************/ /****************************** standard includes *****************************************/ /********************************************************************************************/ #include #include #include #include #include #include #include #include #include #include /********************************************************************************************/ /****************************** Test framework *****************************************/ /********************************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /********************************************************************************************/ /********************************** Configuration ******************************************/ /********************************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif /********************************************************************************************/ /*********************************** Test case *****************************************/ /********************************************************************************************/ sem_t * sem; /* Thread function */ void * threaded( void * arg ) { int ret = 0; do { ret = sem_wait( sem ); } while ( ( ret != 0 ) && ( errno == EINTR ) ); if ( ret != 0 ) { UNRESOLVED( errno, "failed to wait for the semaphore in child" ); } if ( *( pid_t * ) arg != getpid() ) { FAILED( "The thread is executing in the child process" ); } return NULL; } /* The main test function. */ int main( int argc, char * argv[] ) { int ret, status; pid_t child, ctl; pthread_t th; /* Initialize output */ output_init(); ctl = getpid(); /* Initialize the semaphore */ sem = sem_open( "/fork_21_1", O_CREAT, O_RDWR, 0 ); if ( sem == ( sem_t * ) SEM_FAILED ) { UNRESOLVED( errno, "Failed to open the semaphore" ); } sem_unlink( "/fork_21_1" ); /* Create thread */ ret = pthread_create( &th, NULL, threaded, &ctl ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to create the thread" ); } /* Create the child */ child = fork(); if ( child == ( pid_t ) - 1 ) { UNRESOLVED( errno, "Failed to fork" ); } /* We post the semaphore twice */ do { ret = sem_post( sem ); } while ( ( ret != 0 ) && ( errno == EINTR ) ); if ( ret != 0 ) { UNRESOLVED( errno, "Failed to post the semaphore" ); } /* child */ if ( child == ( pid_t ) 0 ) { /* sleep a little while to let the thread execute in case it exists */ sleep( 1 ); /* We're done */ exit( PTS_PASS ); } /* Parent joins the child */ ctl = waitpid( child, &status, 0 ); if ( ctl != child ) { UNRESOLVED( errno, "Waitpid returned the wrong PID" ); } if ( ( !WIFEXITED( status ) ) || ( WEXITSTATUS( status ) != PTS_PASS ) ) { FAILED( "Child exited abnormally" ); } /* Destroy everything */ ret = sem_close( sem ); if ( ret != 0 ) { UNRESOLVED( errno, "Failed to close the semaphore" ); } ret = pthread_join( th, NULL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to join the thread in parent" ); } /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/fork/testfrmw.h0100644000000000000000000000456410171003333022273 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * * This file is a wrapper to use the tests from the NPTL Test & Trace Project * with either the Linux Test Project or the Open POSIX Test Suite. * The following macros are defined here: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate without calling one of those macros. * * */ #include "posixtest.h" #include /* for the strerror() routine */ #ifdef __GNUC__ /* We are using GCC */ #define UNRESOLVED(x, s) \ { output("Test %s unresolved: got %i (%s) on line %i (%s)\n", __FILE__, x, strerror(x), __LINE__, s); \ output_fini(); \ exit(PTS_UNRESOLVED); } #define FAILED(s) \ { output("Test %s FAILED: %s\n", __FILE__, s); \ output_fini(); \ exit(PTS_FAIL); } #define PASSED \ output_fini(); \ exit(PTS_PASS); #define UNTESTED(s) \ { output("File %s cannot test: %s\n", __FILE__, s); \ output_fini(); \ exit(PTS_UNTESTED); \ } #else /* not using GCC */ #define UNRESOLVED(x, s) \ { output("Test unresolved: got %i (%s) on line %i (%s)\n", x, strerror(x), __LINE__, s); \ output_fini(); \ exit(PTS_UNRESOLVED); } #define FAILED(s) \ { output("Test FAILED: %s\n", s); \ output_fini(); \ exit(PTS_FAIL); } #define PASSED \ output_fini(); \ exit(PTS_PASS); #define UNTESTED(s) \ { output("Unable to test: %s\n", s); \ output_fini(); \ exit(PTS_UNTESTED); \ } #endif posixtestsuite/conformance/interfaces/fork/8-1.c0100644000000000000000000001407410171003333020715 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertion: * * tms_{,c}{u,s}time values are set to 0 in the child process. * The steps are: * -> Work for 1 second and save the tms information * -> fork * -> Check that the child has tms values less than the saved tms. * -> join the child process * -> check tms_c{u,s}time are not 0 anymore. * The test fails if one of the described checking fails. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /********************************************************************************************/ /****************************** standard includes *****************************************/ /********************************************************************************************/ #include #include #include #include #include #include #include #include #include /********************************************************************************************/ /****************************** Test framework *****************************************/ /********************************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /********************************************************************************************/ /********************************** Configuration ******************************************/ /********************************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif /********************************************************************************************/ /*********************************** Test case *****************************************/ /********************************************************************************************/ /* The main test function. */ int main( int argc, char * argv[] ) { int status; pid_t child, ctl; clock_t st_time, cur_time; struct tms ini_tms, parent_tms, child_tms; /* Initialize output */ output_init(); /* Initialize first times */ st_time = times( &ini_tms ); if ( st_time == ( clock_t ) - 1 ) { UNRESOLVED( errno, "times failed" ); } if ( ( ini_tms.tms_cutime != 0 ) || ( ini_tms.tms_cstime != 0 ) ) { FAILED( "The process is created with non-zero tms_cutime or tms_cstime" ); } #if VERBOSE > 1 output( "Starting loop...\n" ); #endif /* Busy loop for some times */ do { cur_time = times( &parent_tms ); if ( cur_time == ( clock_t ) - 1 ) { UNRESOLVED( errno, "times failed" ); } } while ( ( cur_time - st_time ) < sysconf( _SC_CLK_TCK ) ); #if VERBOSE > 1 output( "Busy loop terminated\n" ); output( " Real time: %ld, User Time %ld, System Time %ld, Ticks per sec %ld\n", ( long ) ( cur_time - st_time ), ( long ) ( parent_tms.tms_utime - ini_tms.tms_utime ), ( long ) ( parent_tms.tms_stime - ini_tms.tms_stime ), sysconf( _SC_CLK_TCK ) ); #endif /* Create the child */ child = fork(); if ( child == ( pid_t ) - 1 ) { UNRESOLVED( errno, "Failed to fork" ); } /* child */ if ( child == ( pid_t ) 0 ) { cur_time = times( &child_tms ); if ( cur_time == ( clock_t ) - 1 ) { UNRESOLVED( errno, "times failed" ); } if ( child_tms.tms_utime + child_tms.tms_stime >= sysconf( _SC_CLK_TCK ) ) { FAILED( "The tms struct was not reset during fork() operation" ); } do { cur_time = times( &child_tms ); if ( cur_time == ( clock_t ) - 1 ) { UNRESOLVED( errno, "times failed" ); } } while ( ( child_tms.tms_utime + child_tms.tms_stime ) <= 0 ); /* We're done */ exit( PTS_PASS ); } /* Parent joins the child */ ctl = waitpid( child, &status, 0 ); if ( ctl != child ) { UNRESOLVED( errno, "Waitpid returned the wrong PID" ) ; } if ( ( !WIFEXITED( status ) ) || ( WEXITSTATUS( status ) != PTS_PASS ) ) { FAILED( "Child exited abnormally" ) ; } /* Check the children times were reported as expected */ cur_time = times( &parent_tms ); #if VERBOSE > 1 output( "Child joined\n" ); output( " Real time: %ld,\n" " User Time %ld, System Time %ld,\n" " Child User Time %ld, Child System Time %ld\n", ( long ) ( cur_time - st_time ), ( long ) ( parent_tms.tms_utime - ini_tms.tms_utime ), ( long ) ( parent_tms.tms_stime - ini_tms.tms_stime ), ( long ) ( parent_tms.tms_cutime - ini_tms.tms_cutime ), ( long ) ( parent_tms.tms_cstime - ini_tms.tms_cstime ) ); #endif if ( cur_time == ( clock_t ) - 1 ) { UNRESOLVED( errno, "times failed" ); } if ( ( parent_tms.tms_cutime == 0 ) && ( parent_tms.tms_cstime == 0 ) ) { FAILED( "The process is created with non-zero tms_cutime or tms_cstime" ); } /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/fork/16-1.c0100644000000000000000000001471510171003333020776 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertion: * * Memory mappings created in the parent are retained in the child process. * If the mapping is MAP_PRIVATE, any modification done after the fork() * is visible only to the process doing the modification. * The steps are: * -> create two shared memory segments. * -> mmap both segment, one is MAP_SHARED and the other MAP_PRIVATE. * -> Write some data into the segment. * -> fork * -> The child checks that the data is visible in the segments, then modifies it. * -> child terminates * -> The parent checks that the modifications are visible only in the MAP_SHARED segment. * The test fails if one of the check is not verified. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /********************************************************************************************/ /****************************** standard includes *****************************************/ /********************************************************************************************/ #include #include #include #include #include #include #include #include #include #include #include #include /********************************************************************************************/ /****************************** Test framework *****************************************/ /********************************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /********************************************************************************************/ /********************************** Configuration ******************************************/ /********************************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif /********************************************************************************************/ /*********************************** Test case *****************************************/ /********************************************************************************************/ /* The main test function. */ int main( int argc, char * argv[] ) { int ret, status; pid_t child, ctl; int fd_s, fd_ns; void *buf_s, *buf_ns; /* Initialize output */ output_init(); /* Create the shared memory segment */ fd_s = shm_open( "/fork_16_1s", O_CREAT | O_RDWR, S_IRUSR | S_IWUSR ); if ( fd_s == -1 ) { UNRESOLVED( errno, "Failed to open shared memory segment" ); } fd_ns = shm_open( "/fork_16_1ns", O_CREAT | O_RDWR, S_IRUSR | S_IWUSR ); if ( fd_ns == -1 ) { UNRESOLVED( errno, "Failed to open shared memory segment" ); } /* Size the memory segment to 1 page size. */ ret = ftruncate( fd_s, sysconf( _SC_PAGESIZE ) ); if ( ret != 0 ) { UNRESOLVED( errno, "Failed to size the shared memory segment" ); } ret = ftruncate( fd_ns, sysconf( _SC_PAGESIZE ) ); if ( ret != 0 ) { UNRESOLVED( errno, "Failed to size the shared memory segment" ); } /* Map these sengments in the process memory space */ buf_s = mmap( NULL, sysconf( _SC_PAGESIZE ), PROT_READ | PROT_WRITE, MAP_SHARED, fd_s, 0 ); if ( buf_s == MAP_FAILED ) { UNRESOLVED( errno, "Failed to mmap the shared memory segment" ); } buf_ns = mmap( NULL, sysconf( _SC_PAGESIZE ), PROT_READ | PROT_WRITE, MAP_PRIVATE, fd_ns, 0 ); if ( buf_ns == MAP_FAILED ) { UNRESOLVED( errno, "Failed to mmap the shared memory segment in MAP_PRIVATE mode" ); } /* Write some data into the buffers */ *( long * ) buf_ns = 123456L; *( long * ) buf_s = 654321L; /* Create the child */ child = fork(); if ( child == ( pid_t ) - 1 ) { UNRESOLVED( errno, "Failed to fork" ); } /* child */ if ( child == ( pid_t ) 0 ) { /* Check the values are read -- so that the mappings were inherited */ if ( ( *( long * ) buf_ns != 123456L ) || ( *( long * ) buf_s != 654321L ) ) { output( "Read values: %ld, %ld\n", *( long * ) buf_ns, *( long * ) buf_s ); FAILED( "The memory mappings were not inherited by the child process" ); } /* Now modify the values */ *( long * ) buf_ns = 100000L; *( long * ) buf_s = 200000L; /* We're done */ exit( PTS_PASS ); } /* Parent joins the child */ ctl = waitpid( child, &status, 0 ); if ( ctl != child ) { UNRESOLVED( errno, "Waitpid returned the wrong PID" ); } if ( ( !WIFEXITED( status ) ) || ( WEXITSTATUS( status ) != PTS_PASS ) ) { FAILED( "Child exited abnormally" ); } /* Check that only the MAP_SHARED segment modification is visible */ if ( ( *( long * ) buf_ns != 123456L ) || ( *( long * ) buf_s != 200000L ) ) { output( "Read values: %ld, %ld\n", *( long * ) buf_ns, *( long * ) buf_s ); FAILED( "The memory mappings were not inherited by the child process" ); } /* Free resources (everything will be removed at destruction time) */ ret = shm_unlink( "/fork_16_1ns" ); if ( ret != 0 ) { UNRESOLVED( errno, "Failed to unlink the shared memory segment" ); } ret = shm_unlink( "/fork_16_1s" ); if ( ret != 0 ) { UNRESOLVED( errno, "Failed to unlink the shared memory segment" ); } /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/fork/2-1.c0100644000000000000000000001621510171003333020706 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertion: * * The new process is a copy of the original one -- with few exceptions. * The steps are: * -> set up some data in process memory space * -> create a new process * -> check in this new process that the memory space was copied. * * We check that: * -> a structure object is copied. * -> a malloc'ed memory block is copied and can be freed in child. * -> the environment is copied * -> signal handlers are copied * The test fails if a difference is detected. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /* We can use XSI features in case it is allowed */ #ifndef WITHOUT_XOPEN #define _XOPEN_SOURCE 600 #endif /********************************************************************************************/ /****************************** standard includes *****************************************/ /********************************************************************************************/ #include #include #include #include #include #include #include #include #include /********************************************************************************************/ /****************************** Test framework *****************************************/ /********************************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /********************************************************************************************/ /********************************** Configuration ******************************************/ /********************************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif /********************************************************************************************/ /*********************************** Test case *****************************************/ /********************************************************************************************/ void handler( int sig ) { /* this won't be used */ output( "Sig %d received\n", sig ); return ; } /* The main test function. */ int main( int argc, char * argv[] ) { int ret, status; pid_t child, ctl; /* structure for structure test */ struct _thestruct { char one ; short two; int three; void * four; } mystruct = {1, 2, 3, ( void * ) 4}; /* pointer for malloc'ed memory */ void * malloced; /* Structure for signal handler test */ struct sigaction sa_ori, sa_child; /* Initialize output */ output_init(); /* Initialize the memory pointer */ malloced = ( void * ) malloc( sysconf( _SC_PAGESIZE ) ); if ( malloced == NULL ) { UNRESOLVED( errno, "Unable to alloc memory" ); } *( double * ) malloced = 2.3; /* Initialize an environment variable */ ret = setenv( "OPTS_FORK_TC", "2-1.c", 1 ); if ( ret != 0 ) { UNRESOLVED( errno, "Failed to set the environment variable" ); } /* Initialize the signal handler */ sa_ori.sa_handler = handler; ret = sigemptyset( &sa_ori.sa_mask ); if ( ret != 0 ) { UNRESOLVED( errno, "sigemptyset failed" ); } ret = sigaddset( &sa_ori.sa_mask, SIGUSR2 ); if ( ret != 0 ) { UNRESOLVED( errno, "sigaddset failed" ); } sa_ori.sa_flags = SA_NOCLDSTOP; ret = sigaction( SIGUSR1, &sa_ori, NULL ); if ( ret != 0 ) { UNRESOLVED( errno, "Failed to set the signal handler" ); } /* Create the child */ child = fork(); if ( child == ( pid_t ) - 1 ) { UNRESOLVED( errno, "Failed to fork" ); } /* child */ if ( child == ( pid_t ) 0 ) { /* Check the struct was copied */ if ( ( mystruct.one != 1 ) || ( mystruct.two != 2 ) || ( mystruct.three != 3 ) || ( mystruct.four != ( void * ) 4 ) ) { FAILED( "The struct data was not copied to the child process" ); } /* Check the malloc'ed memory is copied */ if ( *( double * ) malloced != 2.3 ) { FAILED( "Malloc'd block not copied in child process" ); } /* Free the memory -- this should suceed */ free( malloced ); /* Check the env variable */ if ( strncmp( "2-1.c", getenv( "OPTS_FORK_TC" ), 6 ) != 0 ) { FAILED( "The environment is not copied to the child" ); } /* Check the signal handler stuff */ ret = sigaction( SIGUSR1, NULL, &sa_child ); if ( ret != 0 ) { UNRESOLVED( errno, "Failed to read sigaction information in child" ); } if ( sa_child.sa_handler != handler ) { FAILED( "The child signal handler function is different from the parent's" ); } ret = sigismember( &sa_child.sa_mask, SIGUSR2 ); if ( ret == 0 ) { FAILED( "The child signal handler mask is different from the parent's" ); } if ( ret != 1 ) { UNRESOLVED( errno, "Unexpected return code from sigismember" ); } if ( ( ( sa_child.sa_flags & SA_NOCLDSTOP ) != SA_NOCLDSTOP ) #ifndef WITHOUT_XOPEN || ( ( sa_child.sa_flags & SA_ONSTACK ) != 0 ) || ( ( sa_child.sa_flags & SA_RESETHAND ) != 0 ) || ( ( sa_child.sa_flags & SA_RESTART ) != 0 ) || ( ( sa_child.sa_flags & SA_SIGINFO ) != 0 ) || ( ( sa_child.sa_flags & SA_NOCLDWAIT ) != 0 ) || ( ( sa_child.sa_flags & SA_NODEFER ) != 0 ) #endif ) { FAILED( "The sigaction flags are different in the child" ); } /* The child stops here */ exit( PTS_PASS ); } /* Parent joins the child */ ctl = waitpid( child, &status, 0 ); if ( ctl != child ) { UNRESOLVED( errno, "Waitpid returned the wrong PID" ); } if ( !WIFEXITED( status ) ) { UNRESOLVED( status, "Child exited abnormally" ); } if ( WEXITSTATUS( status ) == PTS_PASS ) { /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } if ( WEXITSTATUS( status ) == PTS_FAIL ) { /* Test failed */ FAILED( "Test failed in child\n" ); } /* Otherwise we've an unexpected return code */ UNRESOLVED( WEXITSTATUS( status ), "Child returned an unexpected error code" ); } posixtestsuite/conformance/interfaces/fork/3-1.c0100644000000000000000000001026210171003333020703 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertion: * * The new process' ID does not match any existing process or group ID. * The steps are: * -> create a child; then terminate this child. * -> check that no other process or group has the same ID. * The test fails if another object shares the same ID. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /********************************************************************************************/ /****************************** standard includes *****************************************/ /********************************************************************************************/ #include #include #include #include #include #include #include #include #include /********************************************************************************************/ /****************************** Test framework *****************************************/ /********************************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /********************************************************************************************/ /********************************** Configuration ******************************************/ /********************************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif /********************************************************************************************/ /*********************************** Test case *****************************************/ /********************************************************************************************/ /* The main test function. */ int main(int argc, char * argv[]) { int ret, status; pid_t child, ctl; /* Initialize output */ output_init(); /* Create the child */ child = fork(); if (child == (pid_t) -1) { UNRESOLVED(errno, "Failed to fork"); } /* child */ if (child == (pid_t) 0) { /* The child stops immediatly */ exit(PTS_PASS); } /* Parent joins the child */ ctl = waitpid(child, &status, 0); if (ctl != child) { UNRESOLVED(errno, "Waitpid returned the wrong PID"); } if ((!WIFEXITED(status)) || (WEXITSTATUS(status) != PTS_PASS)) { UNRESOLVED(status, "Child exited abnormally"); } ret = kill(child, 0); if ((ret == 0) || (errno != ESRCH)) { output("Kill returned %d (%d: %s)\n", ret, errno, strerror(errno)); FAILED("Another process with the same PID as the child exists"); } ret = kill((pid_t) (0 - (int)child), 0); if ((ret == 0) || (errno != ESRCH)) { output("Kill returned %d (%d: %s)\n", ret, errno, strerror(errno)); FAILED("A process group with the same PID as the child exists"); } /* Test passed */ #if VERBOSE > 0 output("Test passed\n"); #endif PASSED; } posixtestsuite/conformance/interfaces/pthread_barrier_init/0040755000000000000000000000000010515625201023466 5ustar rootrootposixtestsuite/conformance/interfaces/pthread_barrier_init/4-1.c0100644000000000000000000000654307705067042024152 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * * pthread_barrier_init() * * The pthread_barrier_init( ) function may fail if: * [EBUSY] The implementation has detected an attempt to reinitialize a barrier while it is * in use (for example, while being used in a pthread_barrier_wait( ) call) by * another thread. * * NOTE: This case will always pass. * * Steps: * 1. Main initialize barrier with count 2 * 2. Main create a child thread * 3. Child thread call pthread_barrier_wait(), should block * 4. Main call pthread_barrier_init() */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include #include "posixtest.h" static pthread_barrier_t barrier; static int thread_state; #define NOT_CREATED_THREAD 1 #define ENTERED_THREAD 2 #define EXITING_THREAD 3 /* child thread */ static void* fn_chld(void *arg) { int rc = 0; pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL); thread_state = ENTERED_THREAD; printf("thread: barrier wait\n"); rc = pthread_barrier_wait(&barrier); if(rc != 0 && rc != PTHREAD_BARRIER_SERIAL_THREAD) { printf("Error: thread: pthread_barrier_wait() got unexpected " "return code : %d\n" , rc); exit(PTS_UNRESOLVED); } else if(rc == PTHREAD_BARRIER_SERIAL_THREAD) { printf("thread: got PTHREAD_BARRIER_SERIAL_THREAD\n"); } thread_state = EXITING_THREAD; pthread_exit(0); return NULL; } void sig_handler() { printf("Interrupted by SIGALRM\n"); printf("Test PASSED: main blocked on barrier init\n"); exit(PTS_PASS); } int main() { int cnt = 0; int rc; pthread_t child_thread; struct sigaction act; /* Set up main thread to handle SIGALRM */ act.sa_flags = 0; act.sa_handler = sig_handler; sigfillset(&act.sa_mask); sigaction(SIGALRM, &act, 0); printf("main: Initialize barrier with count = 2\n"); if(pthread_barrier_init(&barrier, NULL, 2) != 0) { printf("main: Error at pthread_barrier_init()\n"); return PTS_UNRESOLVED; } printf("main: create child thread\n"); thread_state = NOT_CREATED_THREAD; if(pthread_create(&child_thread, NULL, fn_chld, NULL) != 0) { printf("main: Error at pthread_create()\n"); return PTS_UNRESOLVED; } /* Expect the child to block*/ cnt = 0; do{ sleep(1); }while (thread_state !=EXITING_THREAD && cnt++ < 2); if(thread_state == EXITING_THREAD) { /* child thread did not block */ printf("Test FAILED: child thread did not block on " "pthread_barrier_wait()\n"); exit(PTS_FAIL); } else if(thread_state != ENTERED_THREAD) { printf("Unexpected thread state\n"); exit(PTS_UNRESOLVED); } /* Just in case main gets in a blocked state, send me a SIGALRM after 2 secs */ alarm(2); printf("main: reinitilize barrier while thread is blocking on it\n"); rc = pthread_barrier_init(&barrier, NULL, 2); if(rc == EBUSY) { printf("main: pthread_barrier_init() correctly got EBUSY"); printf("Test PASSED\n"); } else { printf("main: got return code: %d, %s\n", rc, strerror(rc)); printf("Test PASSED: Note*: Expected EBUSY, but standard says 'may' fail.\n"); } /* Cancel thread in case it is still blocked */ pthread_cancel(child_thread); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_barrier_init/1-1.c0100644000000000000000000000415207705067042024141 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * * pthread_barrier_init() * * * The pthread_barrier_init( ) function shall allocate any resources * required to use the barrier referenced by barrier and shall initialize * the barrier with attributes referenced by attr. If attr is NULL, * the default barrier attributes shall be used; * the effect is the same as passing the address of a default barrier attributes object. * */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include #include "posixtest.h" #define COUNT 1 static pthread_barrier_t barrier; int main() { int rc; pthread_barrierattr_t ba; /* Intilized barrier with NULL attribute, check that this can be done. */ rc = pthread_barrier_init(&barrier, NULL, COUNT); if(rc !=0) { printf("Test FAILED: Error at pthread_barrier_init() " "return code %d, %s\n", rc, strerror(rc)); return PTS_FAIL; } /* Cleanup */ if(pthread_barrier_destroy(&barrier) != 0) { printf("Error at pthread_barrier_destroy() " " return code: %d, %s\n", rc, strerror(rc)); return PTS_UNRESOLVED; } /* Initialize a barrier attribute object */ if(pthread_barrierattr_init(&ba) != 0) { printf("Error at pthread_barrierattr_init()\n"); return PTS_UNRESOLVED; } /* Initialize barrier with this barrier attribute object */ rc = pthread_barrier_init(&barrier, &ba, COUNT); if(rc != 0) { printf("Test FAILED: Error at 2nd pthread_barrier_init() " "return code %d, %s\n", rc, strerror(rc)); return PTS_FAIL; } /* Cleanup */ if(pthread_barrierattr_destroy(&ba) != 0) { printf("Error at pthread_barrierattr_destroy()\n"); return PTS_UNRESOLVED; } if(pthread_barrier_destroy(&barrier) != 0) { printf("Error at pthread_barrier_destroy() " " return code: %d, %s\n", rc, strerror(rc)); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_barrier_init/assertions.xml0100644000000000000000000000255707705067042026422 0ustar rootroot The pthread_barrier_init( ) function shall allocate any resources required to use the barrier referenced by barrier and shall initialize the barrier with attributes referenced by attr. If attr is NULL, the default barrier attributes shall be used; the effect is the same as passing the address of a default barrier attributes object. Upon successful completion, these functions shall return zero; otherwise, an error number shall be returned to indicate the error. The pthread_barrier_init( ) function shall fail if: [EAGAIN] The system lacks the necessary resources to initialize another barrier. [EINVAL] The value specified by count is equal to zero. [ENOMEM] Insufficient memory exists to initialize the barrier. The pthread_barrier_init( ) function may fail if: [EBUSY] The implementation has detected an attempt to reinitialize a barrier while it is in use (for example, while being used in a pthread_barrier_wait( ) call) by another thread. [EINVAL] The value specified by attr is invalid. These functions shall not return an error code of [EINTR]. posixtestsuite/conformance/interfaces/pthread_barrier_init/coverage.txt0100644000000000000000000000020507705067042026026 0ustar rootrootThis document defines the coverage for the pthread_barrier_init() function: Assertion Tested? 1 YES 2 YES 3 YES 4 YES NOTE: posixtestsuite/conformance/interfaces/pthread_barrier_init/2-1.sh0100755000000000000000000000074107705067042024335 0ustar rootroot#!/bin/sh # Copyright (c) 2002, Intel Corporation. All rights reserved. # This file is licensed under the GPL license. For the full content # of this license, see the COPYING file at the top level of this # source tree. # Upon successful completion, these functions shall return zero; # otherwise, an error number shall be returned to indicate the error. # This is tested implicitly via assertion 1. echo "Tested implicitly via assertion 1. See output for status" exit 0 posixtestsuite/conformance/interfaces/pthread_barrier_init/3-1.c0100644000000000000000000000175207705067042024146 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * * pthread_barrier_init() * * * The pthread_barrier_init( ) function shall fail if: * [EINVAL] The value specified by count is equal to zero. * */ #define COUNT 0 #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include #include "posixtest.h" int main() { int rc; pthread_barrier_t barrier; /* Intilized barrier with count 0 (it should return EINVAL) */ rc = pthread_barrier_init(&barrier, NULL, COUNT); if(rc != EINVAL) { printf("Test FAILED: pthread_barrier_init() does not return EINVAL when intializing a barrier with count=0," " return code %d, %s\n", rc, strerror(rc)); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_mutex_destroy/0040755000000000000000000000000010515625216023736 5ustar rootrootposixtestsuite/conformance/interfaces/pthread_mutex_destroy/2-2.c0100644000000000000000000001472210123763027024403 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertion: * * pthread_mutex_init() can be used to re-initialize a destroyed mutex. * The steps are: * -> Initialize a mutex with a given attribute. * -> Destroy the mutex * -> Initialize again the mutex with another attribute. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /* We need the XSI extention for the mutex attributes */ #ifndef WITHOUT_XOPEN #define _XOPEN_SOURCE 600 #endif /********************************************************************************************/ /****************************** standard includes *****************************************/ /********************************************************************************************/ #include #include #include #include #include /********************************************************************************************/ /****************************** Test framework *****************************************/ /********************************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /********************************************************************************************/ /********************************** Configuration ******************************************/ /********************************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif /********************************************************************************************/ /*********************************** Test case *****************************************/ /********************************************************************************************/ #ifndef WITHOUT_XOPEN struct _scenar { int m_type; /* Mutex type to use */ int m_pshared; /* 0: mutex is process-private (default) ~ !0: mutex is process-shared, if supported */ char * descr; /* Case description */ } scenarii[] = { {PTHREAD_MUTEX_DEFAULT, 0, "Default mutex"} ,{PTHREAD_MUTEX_NORMAL, 0, "Normal mutex"} ,{PTHREAD_MUTEX_ERRORCHECK, 0, "Errorcheck mutex"} ,{PTHREAD_MUTEX_RECURSIVE, 0, "Recursive mutex"} ,{PTHREAD_MUTEX_DEFAULT, 1, "Pshared mutex"} ,{PTHREAD_MUTEX_NORMAL, 1, "Pshared Normal mutex"} ,{PTHREAD_MUTEX_ERRORCHECK, 1, "Pshared Errorcheck mutex"} ,{PTHREAD_MUTEX_RECURSIVE, 1, "Pshared Recursive mutex"} }; #define NSCENAR (sizeof(scenarii)/sizeof(scenarii[0])) /* Main function */ int main (int argc, char * argv[]) { int ret; int i,j; pthread_mutex_t mtx; pthread_mutexattr_t ma[NSCENAR + 1]; pthread_mutexattr_t *pma[NSCENAR + 2]; long pshared; /* Initialize output routine */ output_init(); /* System abilities */ pshared = sysconf(_SC_THREAD_PROCESS_SHARED); /* Initialize the mutex attributes objects */ for (i=0; i 0) && (scenarii[i].m_pshared != 0)) { ret = pthread_mutexattr_setpshared(&ma[i], PTHREAD_PROCESS_SHARED); if (ret != 0) { UNRESOLVED(ret, "[parent] Unable to set the mutex process-shared"); } } } /* Default mutexattr object */ ret = pthread_mutexattr_init(&ma[i]); if (ret != 0) { UNRESOLVED(ret, "[parent] Unable to initialize the mutex attribute object"); } /* Initialize the pointer array */ for (i=0; i 0 output("Attributes are ready, proceed to the test\n"); #endif for (i=0; i 1 char * nul="NULL"; char * def ="Default"; char * stri; char * strj; if (i 0 output("Test passed; destroying the test data\n"); #endif for (i=0; i #include #include #include "posixtest.h" pthread_mutex_t mutex; int main() { int rc; /* Initialize mutex with the default mutex attributes */ if((rc=pthread_mutex_init(&mutex, NULL)) != 0) { fprintf(stderr,"Fail to initialize mutex, rc=%d\n",rc); return PTS_UNRESOLVED; } /* Lock mutex */ if((rc=pthread_mutex_lock(&mutex)) != 0) { fprintf(stderr,"Error at pthread_mutex_lock(), rc=%d\n",rc); return PTS_UNRESOLVED; } sleep(1); /* Unlock */ if((rc=pthread_mutex_unlock(&mutex)) != 0) { fprintf(stderr,"Error at pthread_mutex_unlock(), rc=%d\n",rc); return PTS_UNRESOLVED; } /* Destroy mutex after it is unlocked */ if((rc=pthread_mutex_destroy(&mutex)) != 0) { fprintf(stderr,"Fail to destroy mutex after being unlocked, rc=%d\n",rc); printf("Test FAILED\n"); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_mutex_destroy/speculative/0040755000000000000000000000000010515625216026262 5ustar rootrootposixtestsuite/conformance/interfaces/pthread_mutex_destroy/speculative/4-2.c0100644000000000000000000000237710065776714026750 0ustar rootroot/* * Copyright (c) 2004, QUALCOMM Inc. All rights reserved. * Created by: abisain REMOVE-THIS AT qualcomm DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that when a pthread_mutex_destroy is called on a * locked mutex, it fails and returns EBUSY * Steps: * 1. Create a mutex * 2. Lock the mutex * 3. Try to destroy the mutex * 4. Check that this may fail with EBUSY */ #include #include #include #include #include #include "posixtest.h" #define TEST "4-2" #define FUNCTION "pthread_mutex_destroy" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " int main() { pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; int rc = 0; /* Lock the mutex */ rc = pthread_mutex_lock(&mutex); if(rc != 0) { perror(ERROR_PREFIX "pthread_mutex_lock\n"); exit(PTS_UNRESOLVED); } /* Try to destroy the locked mutex */ rc = pthread_mutex_destroy(&mutex); if(rc != EBUSY) { printf(ERROR_PREFIX "Test PASS: Expected %d(EBUSY) got %d, " "though the standard states 'may' fail\n", EBUSY, rc); exit(PTS_PASS); } printf("Test PASS\n"); exit(PTS_PASS); } posixtestsuite/conformance/interfaces/pthread_mutex_destroy/5-2.c0100644000000000000000000001433210123763027024403 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertion: * * It is safe to destroy an initialized unlocked mutex. * The steps are: * -> Initialize a mutex with a given attribute. * -> Lock the mutex * -> unlock the mutex * -> Destroy the mutex -- this shall return 0. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /* We need the XSI extention for the mutex attributes */ #ifndef WITHOUT_XOPEN #define _XOPEN_SOURCE 600 #endif /********************************************************************************************/ /****************************** standard includes *****************************************/ /********************************************************************************************/ #include #include #include #include #include /********************************************************************************************/ /****************************** Test framework *****************************************/ /********************************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /********************************************************************************************/ /********************************** Configuration ******************************************/ /********************************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif /********************************************************************************************/ /*********************************** Test case *****************************************/ /********************************************************************************************/ #ifndef WITHOUT_XOPEN struct _scenar { int m_type; /* Mutex type to use */ int m_pshared; /* 0: mutex is process-private (default) ~ !0: mutex is process-shared, if supported */ char * descr; /* Case description */ } scenarii[] = { {PTHREAD_MUTEX_DEFAULT, 0, "Default mutex"} ,{PTHREAD_MUTEX_NORMAL, 0, "Normal mutex"} ,{PTHREAD_MUTEX_ERRORCHECK, 0, "Errorcheck mutex"} ,{PTHREAD_MUTEX_RECURSIVE, 0, "Recursive mutex"} ,{PTHREAD_MUTEX_DEFAULT, 1, "Pshared mutex"} ,{PTHREAD_MUTEX_NORMAL, 1, "Pshared Normal mutex"} ,{PTHREAD_MUTEX_ERRORCHECK, 1, "Pshared Errorcheck mutex"} ,{PTHREAD_MUTEX_RECURSIVE, 1, "Pshared Recursive mutex"} }; #define NSCENAR (sizeof(scenarii)/sizeof(scenarii[0])) /* Main function */ int main (int argc, char * argv[]) { int ret; int i; pthread_mutex_t mtx; pthread_mutexattr_t ma[NSCENAR + 1]; pthread_mutexattr_t *pma[NSCENAR + 2]; long pshared; /* Initialize output routine */ output_init(); /* System abilities */ pshared = sysconf(_SC_THREAD_PROCESS_SHARED); /* Initialize the mutex attributes objects */ for (i=0; i 0) && (scenarii[i].m_pshared != 0)) { ret = pthread_mutexattr_setpshared(&ma[i], PTHREAD_PROCESS_SHARED); if (ret != 0) { UNRESOLVED(ret, "[parent] Unable to set the mutex process-shared"); } } } /* Default mutexattr object */ ret = pthread_mutexattr_init(&ma[i]); if (ret != 0) { UNRESOLVED(ret, "[parent] Unable to initialize the mutex attribute object"); } /* Initialize the pointer array */ for (i=0; i 0 output("Attributes are ready, proceed to the test\n"); #endif for (i=0; i 1 char * nul="NULL"; char * def ="Default"; char * stri; if (i 0 output("Test passed; destroying the test data\n"); #endif for (i=0; i #include #include "posixtest.h" pthread_mutex_t mutex1, mutex2; pthread_mutex_t mutex3 = PTHREAD_MUTEX_INITIALIZER; int main() { pthread_mutexattr_t mta; int rc; /* Initialize a mutex attributes object */ if((rc=pthread_mutexattr_init(&mta)) != 0) { fprintf(stderr,"Error at pthread_mutexattr_init(), rc=%d\n",rc); return PTS_UNRESOLVED; } /* Initialize mutex1 with the default mutex attributes */ if((rc=pthread_mutex_init(&mutex1,&mta)) != 0) { fprintf(stderr,"Fail to initialize mutex1, rc=%d\n",rc); return PTS_UNRESOLVED; } /* Initialize mutex2 with NULL attributes */ if((rc=pthread_mutex_init(&mutex2,NULL)) != 0) { fprintf(stderr,"Fail to initialize mutex2, rc=%d\n",rc); return PTS_UNRESOLVED; } /* Destroy the mutex attributes object */ if((rc=pthread_mutexattr_destroy(&mta)) != 0) { fprintf(stderr,"Error at pthread_mutexattr_destroy(), rc=%d\n",rc); return PTS_UNRESOLVED; } /* Destroy mutex1 */ if((rc=pthread_mutex_destroy(&mutex1)) != 0) { fprintf(stderr,"Fail to destroy mutex1, rc=%d\n",rc); printf("Test FAILED\n"); return PTS_FAIL; } /* Destroy mutex2 */ if((rc=pthread_mutex_destroy(&mutex2)) != 0) { fprintf(stderr,"Fail to destroy mutex2, rc=%d\n",rc); printf("Test FAILED\n"); return PTS_FAIL; } /* Destroy mutex3 */ if((rc=pthread_mutex_destroy(&mutex3)) != 0) { fprintf(stderr,"Fail to destroy mutex3, rc=%d\n",rc); printf("Test FAILED\n"); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_mutex_destroy/testfrmw.c0100644000000000000000000000407210123763027025753 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * * This file is a wrapper to use the tests from the NPTL Test & Trace Project * with either the Linux Test Project or the Open POSIX Test Suite. * The following function are defined: * void output_init() * void output_fini() * void output(char * string, ...) * * The are used to output informative text (as a printf). */ #include #include /* We use a mutex to avoid conflicts in traces */ static pthread_mutex_t m_trace = PTHREAD_MUTEX_INITIALIZER; /*****************************************************************************************/ /******************************* stdout module *****************************************/ /*****************************************************************************************/ /* The following functions will output to stdout */ #if (1) void output_init() { /* do nothing */ return; } void output( char * string, ... ) { va_list ap; char *ts="[??:??:??]"; struct tm * now; time_t nw; pthread_mutex_lock(&m_trace); nw = time(NULL); now = localtime(&nw); if (now == NULL) printf(ts); else printf("[%2.2d:%2.2d:%2.2d]", now->tm_hour, now->tm_min, now->tm_sec); va_start( ap, string); vprintf(string, ap); va_end(ap); pthread_mutex_unlock(&m_trace); } void output_fini() { /*do nothing */ return; } #endif posixtestsuite/conformance/interfaces/pthread_mutex_destroy/assertions.xml0100644000000000000000000000220407653641125026653 0ustar rootroot The function int pthread_mutex_destroy(pthread_mutex_t *mutex); destroys the mutex referenced by 'mutex'; the mutex object now becomes becomes uninitialized. An implementation may cause pthread_mutex_destroy() to set the object referenced by 'mutex' to an invalid value. A destroyed mutex object can be reinitialized using pthread_mutex_init(); the results of referencing the object after it has been destroyed are undefined. Upon success, it returns a 0; pthread_mutex_destroy() may fail if: -[EBUSY] The implementation has detected an attempt to destory the object referenced by 'mutex' while it is locked or referenced. -[EINVAL] The value specified by 'mutex' is invalid. It shall not return [EINTR] It shall be safe to destroy an initialized mutex that is unlocked. posixtestsuite/conformance/interfaces/pthread_mutex_destroy/coverage.txt0100644000000000000000000000050110065776714026275 0ustar rootrootThis document defines the coverage for the pthread_mutex_destroy function: Assertion Tested? 1 YES 2 YES 3 YES 4 NO ** Keeping in mind it 'may' fail and not 'shall' fail, so it will always return PASS, but will return a PASS and print out a warning if it fails. ** EBUSY is tested 5 YES NOTE: posixtestsuite/conformance/interfaces/pthread_mutex_destroy/testfrmw.h0100644000000000000000000000456410123763027025766 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * * This file is a wrapper to use the tests from the NPTL Test & Trace Project * with either the Linux Test Project or the Open POSIX Test Suite. * The following macros are defined here: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate without calling one of those macros. * * */ #include "posixtest.h" #include /* for the strerror() routine */ #ifdef __GNUC__ /* We are using GCC */ #define UNRESOLVED(x, s) \ { output("Test %s unresolved: got %i (%s) on line %i (%s)\n", __FILE__, x, strerror(x), __LINE__, s); \ output_fini(); \ exit(PTS_UNRESOLVED); } #define FAILED(s) \ { output("Test %s FAILED: %s\n", __FILE__, s); \ output_fini(); \ exit(PTS_FAIL); } #define PASSED \ output_fini(); \ exit(PTS_PASS); #define UNTESTED(s) \ { output("File %s cannot test: %s\n", __FILE__, s); \ output_fini(); \ exit(PTS_UNTESTED); \ } #else /* not using GCC */ #define UNRESOLVED(x, s) \ { output("Test unresolved: got %i (%s) on line %i (%s)\n", x, strerror(x), __LINE__, s); \ output_fini(); \ exit(PTS_UNRESOLVED); } #define FAILED(s) \ { output("Test FAILED: %s\n", s); \ output_fini(); \ exit(PTS_FAIL); } #define PASSED \ output_fini(); \ exit(PTS_PASS); #define UNTESTED(s) \ { output("Unable to test: %s\n", s); \ output_fini(); \ exit(PTS_UNTESTED); \ } #endif posixtestsuite/conformance/interfaces/pthread_mutex_destroy/2-1.c0100644000000000000000000000210307615442014024372 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: bing.wei.liu REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test pthread_mutex_destroy() that * a destroyed mutex object can be reinitialized using pthread_mutex_init() * */ #include #include #include "posixtest.h" int main() { pthread_mutex_t mutex; /* Initialize a mutex attributes object */ if(pthread_mutex_init(&mutex,NULL) != 0) { fprintf(stderr,"Cannot initialize mutex object\n"); return PTS_UNRESOLVED; } /* Destroy the mutex attributes object */ if(pthread_mutex_destroy(&mutex) != 0) { fprintf(stderr,"Cannot destroy the mutex object\n"); return PTS_UNRESOLVED; } /* Initialize the mutex attributes object again. This shouldn't result in an error. */ if(pthread_mutex_init(&mutex,NULL) != 0) { printf("Test FAILED\n"); return PTS_FAIL; } else { printf("Test PASSED\n"); return PTS_PASS; } } posixtestsuite/conformance/interfaces/pthread_mutex_destroy/3-1.c0100644000000000000000000000221710112574617024402 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: bing.wei.liu REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_mutex_destroy() * Upon succesful completion, it shall return a 0 * */ #include #include #include #include "posixtest.h" int main() { pthread_mutex_t mutex; int rc; /* Initialize a mutex object */ if((rc=pthread_mutex_init(&mutex,NULL)) != 0) { fprintf(stderr,"Fail to initialize mutex, rc=%d\n",rc); return PTS_UNRESOLVED; } if((rc=pthread_mutex_destroy(&mutex)) == 0) { printf("Test PASSED\n"); return PTS_PASS; } /* The following error codes are possible, but against assertion 5 */ else if(rc == EBUSY) { fprintf(stderr,"Detected an attempt to destroy a mutex in use\n"); } else if(rc == EINVAL) { fprintf(stderr,"The value specified by 'mutex' is invalid\n"); } /* Any other returned value means the test failed */ else { printf("Test FAILED (error: %i)\n", rc); } return PTS_FAIL; } posixtestsuite/conformance/interfaces/pthread_rwlockattr_destroy/0040755000000000000000000000000010515625225024770 5ustar rootrootposixtestsuite/conformance/interfaces/pthread_rwlockattr_destroy/3-1.sh0100755000000000000000000000062007670163332025626 0ustar rootroot#!/bin/sh # Copyright (c) 2002, Intel Corporation. All rights reserved. # This file is licensed under the GPL license. For the full content # of this license, see the COPYING file at the top level of this # source tree. # Test pthread_rwlockattr_destroy returns 0 on success. # This is tested implicitly via assertion 1. echo "Tested implicitly via assertion 1. See output for status" exit 0 posixtestsuite/conformance/interfaces/pthread_rwlockattr_destroy/1-1.c0100644000000000000000000000214407670163332025434 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_rwlockattr_destroy() * shall destroy a read write attributes object. * * Steps: * 1. Initialize a pthread_rwlockattr_t object using pthread_rwlockattr_init() * 2. Destroy the attributes object using pthread_rwlockattr_destroy() * */ #define _XOPEN_SOURCE 600 #include #include #include #include "posixtest.h" int main() { pthread_rwlockattr_t rwla; int rc; /* Initialize a rwlock attributes object */ rc = pthread_rwlockattr_init(&rwla); if(rc != 0) { printf("Error at pthread_rwlockattr_init(), error code: %d\n", rc); return PTS_UNRESOLVED; } /* Destroy the rwlock attributes object */ rc = pthread_rwlockattr_destroy(&rwla); if(rc != 0) { printf("Error at pthread_rwlockattr_destroy(), error code: %d\n", rc); printf("Test FAILED\n"); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_rwlockattr_destroy/assertions.xml0100644000000000000000000000124307670163332027705 0ustar rootroot The function int pthread_rwlockattr_destroy(pthread_rwlockattr_t *attr) destroys a read write attributes objects. A destroyed 'attr' attributes object can be reinitialized using pthread_rwlockattr_init(); If success, it returns 0. An error number may be returned if: [EINVAL] The value specified by 'attr' is invalid This function shall not return an error ecode of [EINTR] posixtestsuite/conformance/interfaces/pthread_rwlockattr_destroy/coverage.txt0100644000000000000000000000020407670163332027321 0ustar rootrootThis document defines the coverage for the pthread_mutexattr_destroy function: Assertion Tested? 1 YES 2 YES 3 YES 4 NO Note: posixtestsuite/conformance/interfaces/pthread_rwlockattr_destroy/2-1.c0100644000000000000000000000270607670163332025441 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test pthread_rwlockattr_destroy() * A destroyed 'attr' attributes object can be reinitialized using * pthread_rwlockattr_init() * * Steps: * 1. Initialize a pthread_rwlockattr_t object using pthread_rwlockattr_init() * 2. Destroy that initialized attribute using pthread_rwlockattr_destroy() * 3. Initialize the pthread_rwlockattr_t object again. This should not result * in any error. * */ #define _XOPEN_SOURCE 600 #include #include #include #include "posixtest.h" int main() { pthread_rwlockattr_t rwla; int rc = 0; /* Initialize a rwlock attributes object */ rc = pthread_rwlockattr_init(&rwla); if(rc != 0) { printf("Cannot initialize rwlock attributes object\n"); return PTS_UNRESOLVED; } /* Destroy the rwlock attributes object */ rc = pthread_rwlockattr_destroy(&rwla); if(rc != 0) { printf("Cannot destroy the rwlock attributes object, error code: %d\n", rc); return PTS_UNRESOLVED; } /* Initialize the rwlock attributes object again. This shouldn't result in an error. */ rc = pthread_rwlockattr_init(&rwla); if(rc != 0) { printf("Test FAILED, with error: %d\n", rc); return PTS_FAIL; } else { printf("Test PASSED\n"); return PTS_PASS; } } posixtestsuite/conformance/interfaces/pthread_cond_destroy/0040755000000000000000000000000010515625203023513 5ustar rootrootposixtestsuite/conformance/interfaces/pthread_cond_destroy/speculative/0040755000000000000000000000000010515625204026040 5ustar rootrootposixtestsuite/conformance/interfaces/pthread_cond_destroy/speculative/4-1.c0100644000000000000000000000412210065776713026515 0ustar rootroot/* * Copyright (c) 2004, QUALCOMM Inc. All rights reserved. * Created by: abisain REMOVE-THIS AT qualcomm DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that when pthread_cond_destroy() * is called on a cond that some thread is waiting, then it returns * EBUSY * Steps: * 1. Create a condvar * 2. Create a thread and make it wait on the condvar * 3. Try to destroy the cond var in main * 4. Check that pthread_cond_destroy returns EBUSY */ #include #include #include #include #include #include "posixtest.h" #define TEST "4-1" #define FUNCTION "pthread_cond_destroy" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " /* cond used by the two threads */ pthread_cond_t cond = PTHREAD_COND_INITIALIZER; /* cond used by the two threads */ pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; void * thread(void *tmp) { int rc = 0; /* acquire the mutex */ rc = pthread_mutex_lock(&mutex); if(rc != 0) { printf(ERROR_PREFIX "pthread_mutex_lock\n"); exit(PTS_UNRESOLVED); } /* Wait on the cond var. This will not return, as nobody signals*/ rc = pthread_cond_wait(&cond, &mutex); if(rc != 0) { printf(ERROR_PREFIX "pthread_cond_wait\n"); exit(PTS_UNRESOLVED); } rc = pthread_mutex_unlock(&mutex); if(rc != 0) { printf(ERROR_PREFIX "pthread_mutex_unlock\n"); exit(PTS_UNRESOLVED); } return NULL; } int main() { pthread_t low_id; int rc = 0; /* Create a new thread with default attributes */ rc = pthread_create(&low_id, NULL, thread, NULL); if(rc != 0) { printf(ERROR_PREFIX "pthread_create\n"); exit(PTS_UNRESOLVED); } /* Let the other thread run */ sleep(2); /* Try to destroy the cond var. This should return an error */ rc = pthread_cond_destroy(&cond); if(rc != EBUSY) { printf(ERROR_PREFIX "Test PASS: Expected %d(EBUSY) got %d, " "though the standard states 'may' fail\n", EBUSY, rc); exit(PTS_PASS); } printf("Test PASS\n"); exit(PTS_PASS); } posixtestsuite/conformance/interfaces/pthread_cond_destroy/1-1.c0100644000000000000000000000374107650710010024154 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: bing.wei.liu REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_cond_destroy() * shall destroy the condition variable referenced by 'cond'; * the condition variable object in effect becomes uninitialized. * */ #include #include #include "posixtest.h" pthread_cond_t cond1, cond2; pthread_cond_t cond3 = PTHREAD_COND_INITIALIZER; int main() { pthread_condattr_t condattr; int rc; /* Initialize a condition variable attribute object */ if((rc=pthread_condattr_init(&condattr)) != 0) { fprintf(stderr,"Error at pthread_condattr_init(), rc=%d\n",rc); return PTS_UNRESOLVED; } /* Initialize cond1 with the default condition variable attribute */ if((rc=pthread_cond_init(&cond1,&condattr)) != 0) { fprintf(stderr,"Fail to initialize cond1, rc=%d\n",rc); return PTS_UNRESOLVED; } /* Initialize cond2 with NULL attributes */ if((rc=pthread_cond_init(&cond2,NULL)) != 0) { fprintf(stderr,"Fail to initialize cond2, rc=%d\n",rc); return PTS_UNRESOLVED; } /* Destroy the condition variable attribute object */ if((rc=pthread_condattr_destroy(&condattr)) != 0) { fprintf(stderr,"Error at pthread_condattr_destroy(), rc=%d\n",rc); return PTS_UNRESOLVED; } /* Destroy cond1 */ if((rc=pthread_cond_destroy(&cond1)) != 0) { fprintf(stderr,"Fail to destroy cond1, rc=%d\n",rc); printf("Test FAILED\n"); return PTS_FAIL; } /* Destroy cond2 */ if((rc=pthread_cond_destroy(&cond2)) != 0) { fprintf(stderr,"Fail to destroy cond2, rc=%d\n",rc); printf("Test FAILED\n"); return PTS_FAIL; } /* Destroy cond3 */ if((rc=pthread_cond_destroy(&cond3)) != 0) { fprintf(stderr,"Fail to destroy cond3, rc=%d\n",rc); printf("Test FAILED\n"); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_cond_destroy/testfrmw.c0100644000000000000000000000407210112373232025525 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * * This file is a wrapper to use the tests from the NPTL Test & Trace Project * with either the Linux Test Project or the Open POSIX Test Suite. * The following function are defined: * void output_init() * void output_fini() * void output(char * string, ...) * * The are used to output informative text (as a printf). */ #include #include /* We use a mutex to avoid conflicts in traces */ static pthread_mutex_t m_trace = PTHREAD_MUTEX_INITIALIZER; /*****************************************************************************************/ /******************************* stdout module *****************************************/ /*****************************************************************************************/ /* The following functions will output to stdout */ #if (1) void output_init() { /* do nothing */ return; } void output( char * string, ... ) { va_list ap; char *ts="[??:??:??]"; struct tm * now; time_t nw; pthread_mutex_lock(&m_trace); nw = time(NULL); now = localtime(&nw); if (now == NULL) printf(ts); else printf("[%2.2d:%2.2d:%2.2d]", now->tm_hour, now->tm_min, now->tm_sec); va_start( ap, string); vprintf(string, ap); va_end(ap); pthread_mutex_unlock(&m_trace); } void output_fini() { /*do nothing */ return; } #endif posixtestsuite/conformance/interfaces/pthread_cond_destroy/assertions.xml0100644000000000000000000000270407625366147026450 0ustar rootroot The function int pthread_cond_destroy(pthread_cond_t *cond); shall destroy the given condition variable specified by cond; the object becomes, in effect, uninitialized. An implementation may cause pthread_cond_destroy() to set the object referenced by cond to an invalid value. A destroyed condition variable object can be reinitialized using pthread_cond_init(); the results of otherwise referencing the object after it has been destroyed are undefined. It shall be safe to destroy an initialized condition variable upon which no threads are currently blocked. Attempting to destroy a condition variable upon which other threads are currently blocked results in undefined behavior. If successful, the pthread_cond_destroy() function shall return zero; The pthread_cond_destroy() function may fail if: [EBUSY] The implementation has detected an attempt to destroy the object referenced by cond while it is referenced (for example, while being used in a pthread_cond_wait() or pthread_cond_timedwait( )) by another thread. [EINVAL] The value specified by cond is invalid. The function shall not return an error code of [EINTR]. posixtestsuite/conformance/interfaces/pthread_cond_destroy/coverage.txt0100644000000000000000000000047110065776703026062 0ustar rootrootThis document defines the coverage for the pthread_cond_destroy function: Assertion Tested? 1 YES 2 YES 3 YES 4 NO * When it specifies it 'may' fail and not 'shall' fail, it will always return PASS, but will return a PASS and print out a warning if it fails. * EBUSY is tested NOTE: posixtestsuite/conformance/interfaces/pthread_cond_destroy/testfrmw.h0100644000000000000000000000456410112373233025541 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * * This file is a wrapper to use the tests from the NPTL Test & Trace Project * with either the Linux Test Project or the Open POSIX Test Suite. * The following macros are defined here: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate without calling one of those macros. * * */ #include "posixtest.h" #include /* for the strerror() routine */ #ifdef __GNUC__ /* We are using GCC */ #define UNRESOLVED(x, s) \ { output("Test %s unresolved: got %i (%s) on line %i (%s)\n", __FILE__, x, strerror(x), __LINE__, s); \ output_fini(); \ exit(PTS_UNRESOLVED); } #define FAILED(s) \ { output("Test %s FAILED: %s\n", __FILE__, s); \ output_fini(); \ exit(PTS_FAIL); } #define PASSED \ output_fini(); \ exit(PTS_PASS); #define UNTESTED(s) \ { output("File %s cannot test: %s\n", __FILE__, s); \ output_fini(); \ exit(PTS_UNTESTED); \ } #else /* not using GCC */ #define UNRESOLVED(x, s) \ { output("Test unresolved: got %i (%s) on line %i (%s)\n", x, strerror(x), __LINE__, s); \ output_fini(); \ exit(PTS_UNRESOLVED); } #define FAILED(s) \ { output("Test FAILED: %s\n", s); \ output_fini(); \ exit(PTS_FAIL); } #define PASSED \ output_fini(); \ exit(PTS_PASS); #define UNTESTED(s) \ { output("Unable to test: %s\n", s); \ output_fini(); \ exit(PTS_UNTESTED); \ } #endif posixtestsuite/conformance/interfaces/pthread_cond_destroy/2-1.c0100644000000000000000000005055610112373232024161 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertion: * * It is safe to destroy a condition variable when no thread is blocked on it. * The steps are: * -> Some threads are waiting on a condition variable. * -> A thread broadcasts and destroys immediatly the condvar, * then corrupts the memory of the condvar. * * The test fails if it hangs or if an error is returned, either * in the wait routines or in the destroy routine. * */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /* We need the XSI extention for the mutex attributes */ #ifndef WITHOUT_XOPEN #define _XOPEN_SOURCE 600 #endif /********************************************************************************************/ /****************************** standard includes *****************************************/ /********************************************************************************************/ #include #include #include #include #include #include #include #include #include #include #include /********************************************************************************************/ /****************************** Test framework *****************************************/ /********************************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ #define UNRESOLVED_KILLALL(error, text, Tchild) { \ if (td->fork) \ { \ int _nch; \ for (_nch=0; _nchfork) \ { \ int _nch; \ for (_nch=0; _nchmtx1); if (ret != 0) { UNRESOLVED(ret, "Failed to lock mutex in child"); } /* increment count */ td->count1++; timed=td->count1 & 1; if (timed) { /* get current time if we are a timedwait */ ret = clock_gettime(td->cid, &ts); if (ret != 0) { UNRESOLVED(errno, "Unable to read clock"); } ts.tv_sec += TIMEOUT; } do { /* Wait while the predicate is false */ if (timed) ret = pthread_cond_timedwait(&td->cnd, &td->mtx1, &ts); else ret = pthread_cond_wait(&td->cnd, &td->mtx1); } while ((ret == 0) && (td->predicate1==0)); if ((ret != 0) && (td->predicate1 != 0)) { output("Wakening the cond failed with error %i (%s)\n", ret, strerror(ret)); FAILED("Destroying the cond var while threads were awaken but inside wait routine failed."); } if (ret != 0) { UNRESOLVED(ret, "Failed to wait for the cond"); } td->count1--; /* unlock the mutex */ ret = pthread_mutex_unlock(&td->mtx1); if (ret != 0) { UNRESOLVED(ret, "Failed to unlock the mutex."); } /* Second pass */ /* lock the mutex */ ret = pthread_mutex_lock(&td->mtx2); if (ret != 0) { UNRESOLVED(ret, "Failed to lock mutex in child"); } /* increment count */ td->count2++; timed=td->count2 & 1; if (timed) { /* get current time if we are a timedwait */ ret = clock_gettime(td->cid, &ts); if (ret != 0) { UNRESOLVED(errno, "Unable to read clock"); } ts.tv_sec += TIMEOUT; } do { /* Wait while the predicate is false */ if (timed) ret = pthread_cond_timedwait(&td->cnd, &td->mtx2, &ts); else ret = pthread_cond_wait(&td->cnd, &td->mtx2); } while ((ret == 0) && (td->predicate2==0)); if ((ret != 0) && (td->predicate2 != 0)) { output("Wakening the cond failed with error %i (%s)\n", ret, strerror(ret)); FAILED("Destroying the cond var while threads were awaken but inside wait routine failed."); } if (ret != 0) { UNRESOLVED(ret, "Failed to wait for the cond"); } /* unlock the mutex */ ret = pthread_mutex_unlock(&td->mtx2); if (ret != 0) { UNRESOLVED(ret, "Failed to unlock the mutex."); } return NULL; } /* Timeout thread */ void * timer(void * arg) { pid_t *pchildren = (pid_t *)arg; unsigned int to = TIMEOUT; do { to = sleep(to); } while (to>0); FAILED_KILLALL("Test failed (hang)", pchildren); return NULL; /* For compiler */ } /* main function */ int main (int argc, char * argv[]) { int ret; pthread_mutexattr_t ma; pthread_condattr_t ca; int scenar; long pshared, monotonic, cs, mf; pid_t p_child[NTHREADS]; pthread_t t_child[NTHREADS]; int ch; pid_t pid; int status; pthread_t t_timer; testdata_t alternativ; output_init(); /* check the system abilities */ pshared = sysconf(_SC_THREAD_PROCESS_SHARED); cs = sysconf(_SC_CLOCK_SELECTION); monotonic = sysconf(_SC_MONOTONIC_CLOCK); mf =sysconf(_SC_MAPPED_FILES); #if VERBOSE > 0 output("Test starting\n"); output("System abilities:\n"); output(" TPS : %li\n", pshared); output(" CS : %li\n", cs); output(" MON : %li\n", monotonic); output(" MF : %li\n", mf); if ((mf < 0) || (pshared < 0)) output("Process-shared attributes won't be tested\n"); if ((cs < 0) || (monotonic < 0)) output("Alternative clock won't be tested\n"); #endif /* We are not interested in testing the clock if we have no other clock available.. */ if (monotonic < 0) cs = -1; #ifndef USE_ALTCLK if (cs > 0) output("Implementation supports the MONOTONIC CLOCK but option is disabled in test.\n"); #endif /********** * Allocate space for the testdata structure */ if (mf < 0) { /* Cannot mmap a file, we use an alternative method */ td = &alternativ; pshared = -1; /* We won't do this testing anyway */ #if VERBOSE > 0 output("Testdata allocated in the process memory.\n"); #endif } else { /* We will place the test data in a mmaped file */ char filename[] = "/tmp/cond_destroy-XXXXXX"; size_t sz, ps; void * mmaped; int fd; char * tmp; /* We now create the temp files */ fd = mkstemp(filename); if (fd == -1) { UNRESOLVED(errno, "Temporary file could not be created"); } /* and make sure the file will be deleted when closed */ unlink(filename); #if VERBOSE > 1 output("Temp file created (%s).\n", filename); #endif ps = (size_t)sysconf(_SC_PAGESIZE); sz= ((sizeof(testdata_t) / ps) + 1) * ps; /* # pages needed to store the testdata */ tmp = calloc( 1 , sz); if (tmp == NULL) { UNRESOLVED(errno, "Memory allocation failed"); } /* Write the data to the file. */ if (write (fd, tmp, sz) != (ssize_t) sz) { UNRESOLVED(sz, "Writting to the file failed"); } free(tmp); /* Now we can map the file in memory */ mmaped = mmap(NULL, sz, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); if (mmaped == MAP_FAILED) { UNRESOLVED(errno, "mmap failed"); } td = (testdata_t *) mmaped; /* Our datatest structure is now in shared memory */ #if VERBOSE > 1 output("Testdata allocated in shared memory (%ib).\n", sizeof(testdata_t)); #endif } /* Do the test for each test scenario */ for (scenar=0; scenar < NSCENAR; scenar++) { /* set / reset everything */ td->fork=0; ret = pthread_mutexattr_init(&ma); if (ret != 0) { UNRESOLVED(ret, "[parent] Unable to initialize the mutex attribute object"); } ret = pthread_condattr_init(&ca); if (ret != 0) { UNRESOLVED(ret, "[parent] Unable to initialize the cond attribute object"); } #ifndef WITHOUT_XOPEN /* Set the mutex type */ ret = pthread_mutexattr_settype(&ma, scenarii[scenar].m_type); if (ret != 0) { UNRESOLVED(ret, "[parent] Unable to set mutex type"); } #endif /* Set the pshared attributes, if supported */ if ((pshared > 0) && (scenarii[scenar].mc_pshared != 0)) { ret = pthread_mutexattr_setpshared(&ma, PTHREAD_PROCESS_SHARED); if (ret != 0) { UNRESOLVED(ret, "[parent] Unable to set the mutex process-shared"); } ret = pthread_condattr_setpshared(&ca, PTHREAD_PROCESS_SHARED); if (ret != 0) { UNRESOLVED(ret, "[parent] Unable to set the cond var process-shared"); } } /* Set the alternative clock, if supported */ #ifdef USE_ALTCLK if ((cs > 0) && (scenarii[scenar].c_clock != 0)) { ret = pthread_condattr_setclock(&ca, CLOCK_MONOTONIC); if (ret != 0) { UNRESOLVED(ret, "[parent] Unable to set the monotonic clock for the cond"); } } ret = pthread_condattr_getclock(&ca, &td->cid); if (ret != 0) { UNRESOLVED(ret, "Unable to get clock from cond attr"); } #else td->cid = CLOCK_REALTIME; #endif /* Tell whether the test will be across processes */ if ((pshared > 0) && (scenarii[scenar].fork != 0)) { td->fork = 1; } /* Proceed to testing */ /* initialize the mutex */ ret = pthread_mutex_init(&td->mtx1, &ma); if (ret != 0) { UNRESOLVED(ret, "Mutex init failed"); } ret = pthread_mutex_init(&td->mtx2, &ma); if (ret != 0) { UNRESOLVED(ret, "Mutex init failed"); } ret = pthread_mutex_lock(&td->mtx2); if (ret != 0) { UNRESOLVED(ret, "Mutex lock failed"); } /* initialize the condvar */ ret = pthread_cond_init(&td->cnd, &ca); if (ret != 0) { UNRESOLVED(ret, "Cond init failed"); } #if VERBOSE > 2 output("[parent] Starting 1st pass of test %s\n", scenarii[scenar].descr); #endif td->count1=0; td->count2=0; td->predicate1=0; td->predicate2=0; /* Create all the children */ for (ch=0; ch < NTHREADS; ch++) { if (td->fork==0) { ret = pthread_create(&t_child[ch], NULL, child, NULL); if (ret != 0) { UNRESOLVED(ret, "Failed to create a child thread"); } } else { p_child[ch]=fork(); if (p_child[ch] == -1) { ret = errno; for (--ch; ch>=0; ch--) kill(p_child[ch], SIGKILL); UNRESOLVED(ret, "Failed to create a child process"); } if (p_child[ch] == 0) /* We are the child */ { child(NULL); exit(0); } } } #if VERBOSE > 4 output("[parent] All children are running\n"); #endif /* Make sure all children are waiting */ ret = pthread_mutex_lock(&td->mtx1); if (ret != 0) { UNRESOLVED_KILLALL(ret, "Failed to lock mutex", p_child); } ch = td->count1; while (ch < NTHREADS) { ret = pthread_mutex_unlock(&td->mtx1); if (ret != 0) { UNRESOLVED_KILLALL(ret, "Failed to unlock mutex",p_child); } sched_yield(); ret = pthread_mutex_lock(&td->mtx1); if (ret != 0) { UNRESOLVED_KILLALL(ret, "Failed to lock mutex",p_child); } ch = td->count1; } #if VERBOSE > 4 output("[parent] All children are waiting\n"); #endif /* create the timeout thread */ ret = pthread_create(&t_timer, NULL, timer, p_child); if (ret != 0) { UNRESOLVED_KILLALL(ret, "Unable to create timer thread",p_child); } /* Wakeup the children */ td->predicate1=1; ret = pthread_cond_broadcast(&td->cnd); if (ret != 0) { UNRESOLVED_KILLALL(ret, "Failed to signal the condition.", p_child); } ret = pthread_mutex_unlock(&td->mtx1); if (ret != 0) { UNRESOLVED_KILLALL(ret, "Failed to unlock mutex",p_child); } /* Destroy the condvar (this must be safe) */ ret = pthread_cond_destroy(&td->cnd); if (ret != 0) { FAILED_KILLALL("Unable to destroy the cond while no thread is blocked inside", p_child); } /* Reuse the cond memory */ memset(&td->cnd, 0xFF, sizeof(pthread_cond_t)); #if VERBOSE > 4 output("[parent] Condition was broadcasted, and condvar destroyed.\n"); #endif /* Make sure all children have exited the first wait */ ret = pthread_mutex_lock(&td->mtx1); if (ret != 0) { UNRESOLVED_KILLALL(ret, "Failed to lock mutex",p_child); } ch = td->count1; while (ch > 0) { ret = pthread_mutex_unlock(&td->mtx1); if (ret != 0) { UNRESOLVED_KILLALL(ret, "Failed to unlock mutex",p_child); } sched_yield(); ret = pthread_mutex_lock(&td->mtx1); if (ret != 0) { UNRESOLVED_KILLALL(ret, "Failed to lock mutex",p_child); } ch = td->count1; } ret = pthread_mutex_unlock(&td->mtx1); if (ret != 0) { UNRESOLVED_KILLALL(ret, "Failed to unlock mutex",p_child); } /* Go toward the 2nd pass */ /* Now, all children are waiting to lock the 2nd mutex, which we own here. */ /* reinitialize the condvar */ ret = pthread_cond_init(&td->cnd, &ca); if (ret != 0) { UNRESOLVED(ret, "Cond init failed"); } #if VERBOSE > 2 output("[parent] Starting 2nd pass of test %s\n", scenarii[scenar].descr); #endif /* Make sure all children are waiting */ ch = td->count2; while (ch < NTHREADS) { ret = pthread_mutex_unlock(&td->mtx2); if (ret != 0) { UNRESOLVED_KILLALL(ret, "Failed to unlock mutex",p_child); } sched_yield(); ret = pthread_mutex_lock(&td->mtx2); if (ret != 0) { UNRESOLVED_KILLALL(ret, "Failed to lock mutex",p_child); } ch = td->count2; } #if VERBOSE > 4 output("[parent] All children are waiting\n"); #endif /* Wakeup the children */ td->predicate2=1; ret = pthread_cond_broadcast(&td->cnd); if (ret != 0) { UNRESOLVED_KILLALL(ret, "Failed to signal the condition.", p_child); } /* Allow the children to terminate */ ret = pthread_mutex_unlock(&td->mtx2); if (ret != 0) { UNRESOLVED_KILLALL(ret, "Failed to unlock mutex",p_child); } /* Destroy the condvar (this must be safe) */ ret = pthread_cond_destroy(&td->cnd); if (ret != 0) { FAILED_KILLALL("Unable to destroy the cond while no thread is blocked inside", p_child); } /* Reuse the cond memory */ memset(&td->cnd, 0x00, sizeof(pthread_cond_t)); #if VERBOSE > 4 output("[parent] Condition was broadcasted, and condvar destroyed.\n"); #endif #if VERBOSE > 4 output("[parent] Joining the children\n"); #endif /* join the children */ for (ch=(NTHREADS - 1); ch >= 0 ; ch--) { if (td->fork==0) { ret = pthread_join(t_child[ch], NULL); if (ret != 0) { UNRESOLVED(ret, "Failed to join a child thread"); } } else { pid = waitpid(p_child[ch], &status, 0); if (pid != p_child[ch]) { ret = errno; output("Waitpid failed (expected: %i, got: %i)\n", p_child[ch], pid); for (; ch>=0; ch--) { kill(p_child[ch], SIGKILL); } UNRESOLVED(ret, "Waitpid failed"); } if (WIFEXITED(status)) { /* the child should return only failed or unresolved or passed */ if (ret != PTS_FAIL) ret |= WEXITSTATUS(status); } } } if (ret != 0) { output_fini(); exit(ret); } #if VERBOSE > 4 output("[parent] All children terminated\n"); #endif /* cancel the timeout thread */ ret = pthread_cancel(t_timer); if (ret != 0) { /* Strange error here... the thread cannot be terminated (app would be killed) */ UNRESOLVED(ret, "Failed to cancel the timeout handler"); } /* join the timeout thread */ ret = pthread_join(t_timer, NULL); if (ret != 0) { UNRESOLVED(ret, "Failed to join the timeout handler"); } /* Destroy the datas */ ret = pthread_cond_destroy(&td->cnd); if (ret != 0) { UNRESOLVED(ret, "Failed to destroy the condvar"); } ret = pthread_mutex_destroy(&td->mtx1); if (ret != 0) { UNRESOLVED(ret, "Failed to destroy the mutex"); } ret = pthread_mutex_destroy(&td->mtx2); if (ret != 0) { UNRESOLVED(ret, "Failed to destroy the mutex"); } /* Destroy the attributes */ ret = pthread_condattr_destroy(&ca); if (ret != 0) { UNRESOLVED(ret, "Failed to destroy the cond var attribute object"); } ret = pthread_mutexattr_destroy(&ma); if (ret != 0) { UNRESOLVED(ret, "Failed to destroy the mutex attribute object"); } } /* exit */ PASSED; } posixtestsuite/conformance/interfaces/pthread_cond_destroy/3-1.c0100644000000000000000000000223410110077513024151 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: bing.wei.liu REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_cond_destroy() * Upon succesful completion, it shall return a 0 * */ #include #include #include #include "posixtest.h" int main() { pthread_cond_t cond; int rc; /* Initialize a cond object */ if((rc=pthread_cond_init(&cond,NULL)) != 0) { fprintf(stderr,"Fail to initialize cond, rc=%d\n",rc); return PTS_UNRESOLVED; } if((rc=pthread_cond_destroy(&cond)) == 0) { printf("Test PASSED\n"); return PTS_PASS; } /* Check if returned values are tolerable */ else if(rc == EBUSY) { fprintf(stderr,"Detected an attempt to destroy a cond in use\n"); return PTS_FAIL; } else if(rc == EINVAL) { fprintf(stderr,"The value specified by 'cond' is invalid\n"); return PTS_FAIL; } /* Any other returned value means the test failed */ else { printf("Test FAILED (error %i unexpected)\n", rc); return PTS_FAIL; } } posixtestsuite/conformance/interfaces/pthread_attr_getschedparam/0040755000000000000000000000000010515625177024672 5ustar rootrootposixtestsuite/conformance/interfaces/pthread_attr_getschedparam/1-1.c0100644000000000000000000000530010060042626025312 0ustar rootroot/* * Copyright (c) 2004, QUALCOMM Inc. All rights reserved. * Created by: abisain REMOVE-THIS AT qualcomm DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test pthread_attr_getschedparam() * * Steps: * 1. Initialize a pthread_attr_t object using pthread_attr_init() * 2. Call pthread_attr_setschedpolicy with policy parameter * 3. Call pthread_attr_setschedparam with a sched param parameter * 4. Call pthread_attr_getschedparam to get the sched param * */ #include #include #include #include "posixtest.h" #define TEST "1-1" #define FUNCTION "pthread_attr_getschedparam" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " #define FIFOPOLICY SCHED_FIFO #define RRPOLICY SCHED_RR #define OTHERPOLICY SCHED_OTHER int verify_param(pthread_attr_t *attr, int priority) { int rc; struct sched_param param; rc = pthread_attr_getschedparam(attr, ¶m); if(rc != 0) { printf(ERROR_PREFIX "pthread_attr_getschedparam\n"); exit(PTS_UNRESOLVED); } if(priority != param.sched_priority) { printf(ERROR_PREFIX "got wrong sched param\n"); exit(PTS_FAIL); } return 0; } int main() { int rc=0; pthread_attr_t attr; struct sched_param param; int priority; rc = pthread_attr_init(&attr); if(rc != 0) { printf(ERROR_PREFIX "pthread_attr_init\n"); exit(PTS_UNRESOLVED); } rc = pthread_attr_setschedpolicy(&attr, FIFOPOLICY); if(rc != 0) { printf(ERROR_PREFIX "pthread_attr_setschedpolicy\n"); exit(PTS_UNRESOLVED); } priority = sched_get_priority_max(FIFOPOLICY); if(priority == -1) { printf(ERROR_PREFIX "sched_get_priority_max\n"); exit(PTS_UNRESOLVED); } param.sched_priority = priority; rc = pthread_attr_setschedparam(&attr, ¶m); if(rc != 0) { printf(ERROR_PREFIX "pthread_attr_setschedparam\n"); exit(PTS_UNRESOLVED); } verify_param(&attr, priority); rc = pthread_attr_setschedpolicy(&attr, RRPOLICY); if(rc != 0) { printf(ERROR_PREFIX "pthread_attr_setschedpolicy\n"); exit(PTS_UNRESOLVED); } priority = sched_get_priority_max(RRPOLICY); if(priority == -1) { printf(ERROR_PREFIX "sched_get_priority_max\n"); exit(PTS_UNRESOLVED); } param.sched_priority = priority; rc = pthread_attr_setschedparam(&attr, ¶m); if(rc != 0) { printf(ERROR_PREFIX "pthread_attr_setschedparam\n"); exit(PTS_UNRESOLVED); } verify_param(&attr, priority); rc = pthread_attr_destroy(&attr); if(rc != 0) { printf(ERROR_PREFIX "pthread_attr_destroy\n"); exit(PTS_UNRESOLVED); } printf("Test PASS\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_attr_getschedparam/assertions.xml0100644000000000000000000000105007621010702027561 0ustar rootroot The function int pthread_attr_getschedparam(const pthread_attr_t *restrict attr, contst struct sched_param *restrict param); gets the scheduling parameter attributes in the 'attr' argument. The contents of the 'param' structure are defined in sched.h. For the SCHED_FIFO and SCHED_RR policies, the only required member of 'param' is 'sched_priority'. If success, it returns 0; posixtestsuite/conformance/interfaces/pthread_attr_getschedparam/coverage.txt0100644000000000000000000000017010060042626027204 0ustar rootrootThis document defines the coverage for the pthread_attr_getschedparam function: Assertion Tested? 1 YES 2 YES NOTE: posixtestsuite/conformance/interfaces/pthread_attr_getschedparam/2-1.sh0100755000000000000000000000070510060042626025512 0ustar rootroot #!/bin/sh # Copyright (c) 2004, QUALCOMM Inc. All rights reserved. # Created by: abisain REMOVE-THIS AT qualcomm DOT com # This file is licensed under the GPL license. For the full content # of this license, see the COPYING file at the top level of this # source tree. # Test pthread_attr_getschedparam returns 0 on success. # This is tested implicitly via assertion 1. echo "Tested implicitly via assertion 1. See output for status" exit 0 posixtestsuite/conformance/interfaces/pthread_cond_wait/0040755000000000000000000000000010515625207022772 5ustar rootrootposixtestsuite/conformance/interfaces/pthread_cond_wait/2-2.c0100644000000000000000000004256610110655117023442 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertion: * * When the function returns successfully, everything is as if * the thread had locked the mutex. * * The steps are: * -> For each mutex type; * -> with and without process-shared primitive if this is supported; * -> with different clocks if this is supported, * -> Initialize a condvar and a mutex. * -> Create a new thread (or process for process-shared condvars & mutex) * -> The new thread (process) locks the mutex, then waits for the condition . * -> The parent thread (process) then locks the mutex, ensures that the child is waiting, * then signals the condition; and checks the child does not leave the wait function. * -> The parent unlocks the mutex then joins the child. * -> The child checks that it owns the mutex; then it leaves. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /* We need the XSI extention for the mutex attributes and the mkstemp() routine */ #ifndef WITHOUT_XOPEN #define _XOPEN_SOURCE 600 #endif /********************************************************************************************/ /****************************** standard includes *****************************************/ /********************************************************************************************/ #include #include #include #include #include #include #include #include #include /********************************************************************************************/ /****************************** Test framework *****************************************/ /********************************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /********************************************************************************************/ /********************************** Configuration ******************************************/ /********************************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif #ifndef WITHOUT_ALTCLK #define USE_ALTCLK /* make tests with MONOTONIC CLOCK if supported */ #endif /********************************************************************************************/ /*********************************** Test case *****************************************/ /********************************************************************************************/ #ifndef WITHOUT_XOPEN typedef struct { pthread_mutex_t mtx; pthread_cond_t cnd; clockid_t cid; /* Clock id used by the cond var */ int type; /* Mutex type */ int ctrl; /* checkpoints */ int bool; /* Boolean predicate for the condition */ int status; /* error code */ } testdata_t; struct _scenar { int m_type; /* Mutex type to use */ int mc_pshared; /* 0: mutex and cond are process-private (default) ~ !0: Both are process-shared, if supported */ int c_clock; /* 0: cond uses the default clock. ~ !0: Cond uses monotonic clock, if supported. */ int fork; /* 0: Test between threads. ~ !0: Test across processes, if supported (mmap) */ char * descr; /* Case description */ } scenarii[] = { {PTHREAD_MUTEX_DEFAULT, 0, 0, 0, "Default mutex"} ,{PTHREAD_MUTEX_NORMAL, 0, 0, 0, "Normal mutex"} ,{PTHREAD_MUTEX_ERRORCHECK, 0, 0, 0, "Errorcheck mutex"} ,{PTHREAD_MUTEX_RECURSIVE, 0, 0, 0, "Recursive mutex"} ,{PTHREAD_MUTEX_DEFAULT, 1, 0, 0, "PShared default mutex"} ,{PTHREAD_MUTEX_NORMAL, 1, 0, 0, "Pshared normal mutex"} ,{PTHREAD_MUTEX_ERRORCHECK, 1, 0, 0, "Pshared errorcheck mutex"} ,{PTHREAD_MUTEX_RECURSIVE, 1, 0, 0, "Pshared recursive mutex"} ,{PTHREAD_MUTEX_DEFAULT, 1, 0, 1, "Pshared default mutex across processes"} ,{PTHREAD_MUTEX_NORMAL, 1, 0, 1, "Pshared normal mutex across processes"} ,{PTHREAD_MUTEX_ERRORCHECK, 1, 0, 1, "Pshared errorcheck mutex across processes"} ,{PTHREAD_MUTEX_RECURSIVE, 1, 0, 1, "Pshared recursive mutex across processes"} #ifdef USE_ALTCLK ,{PTHREAD_MUTEX_DEFAULT, 1, 1, 1, "Pshared default mutex and alt clock condvar across processes"} ,{PTHREAD_MUTEX_NORMAL, 1, 1, 1, "Pshared normal mutex and alt clock condvar across processes"} ,{PTHREAD_MUTEX_ERRORCHECK, 1, 1, 1, "Pshared errorcheck mutex and alt clock condvar across processes"} ,{PTHREAD_MUTEX_RECURSIVE, 1, 1, 1, "Pshared recursive mutex and alt clock condvar across processes"} ,{PTHREAD_MUTEX_DEFAULT, 0, 1, 0, "Default mutex and alt clock condvar"} ,{PTHREAD_MUTEX_NORMAL, 0, 1, 0, "Normal mutex and alt clock condvar"} ,{PTHREAD_MUTEX_ERRORCHECK, 0, 1, 0, "Errorcheck mutex and alt clock condvar"} ,{PTHREAD_MUTEX_RECURSIVE, 0, 1, 0, "Recursive mutex and alt clock condvar"} ,{PTHREAD_MUTEX_DEFAULT, 1, 1, 0, "PShared default mutex and alt clock condvar"} ,{PTHREAD_MUTEX_NORMAL, 1, 1, 0, "Pshared normal mutex and alt clock condvar"} ,{PTHREAD_MUTEX_ERRORCHECK, 1, 1, 0, "Pshared errorcheck mutex and alt clock condvar"} ,{PTHREAD_MUTEX_RECURSIVE, 1, 1, 0, "Pshared recursive mutex and alt clock condvar"} #endif }; void * tf(void * arg) { int ret=0; testdata_t * td = (testdata_t *)arg; /* Lock the mutex */ ret = pthread_mutex_lock(&(td->mtx)); if (ret != 0) { td->status = ret; UNRESOLVED(ret, "[child] Unable to lock the mutex"); } /* Tell the parent the mutex is locked */ td->ctrl = 1; /* Enter the wait */ do { ret = pthread_cond_wait(&(td->cnd), &(td->mtx)); td->ctrl = 2; } while ((ret == 0) && (td->bool == 0)); td->ctrl = 3; if (ret != 0) { td->status = ret; UNRESOLVED(ret, "[child] Cond wait returned an error"); } /* Make sure we are owning the mutex */ ret = pthread_mutex_trylock(&(td->mtx)); if (td->type == PTHREAD_MUTEX_RECURSIVE) { #if VERBOSE > 1 output("[child] Recursive mutex. Test if we are able to re-lock.\n"); #endif if (ret != 0) { td->status = ret; FAILED("[child] Unable to relock the recursive mutex"); } ret = pthread_mutex_unlock(&(td->mtx)); if (ret != 0) { td->status = ret; UNRESOLVED(ret, "[child] Failed to unlock the mutex"); } } else /* This was not a recursive mutex; the call must have failed */ { if (ret == 0) { td->status = -1; FAILED("[child] Thread did not owned the mutex after the wait return."); } if (ret != EBUSY) { td-> status = ret; UNRESOLVED(ret, "[child] Mutex trylock did not return EBUSY"); } #if VERBOSE > 1 output("[child] The mutex was busy (normal).\n"); #endif } ret = pthread_mutex_unlock(&(td->mtx)); if (ret != 0) { td->status=ret; output("[child] Got error %i: %s\n", ret, strerror(ret)); FAILED("[child] Failed to unlock the mutex - owned by another thread?"); } td->ctrl = 4; return NULL; } int main(int argc, char * argv[]) { int ret, i; pthread_mutexattr_t ma; pthread_condattr_t ca; testdata_t * td; testdata_t alternativ; int do_fork; pid_t child_pr=0, chkpid; int status; pthread_t child_th; long pshared, monotonic, cs, mf; output_init(); pshared = sysconf(_SC_THREAD_PROCESS_SHARED); cs = sysconf(_SC_CLOCK_SELECTION); monotonic = sysconf(_SC_MONOTONIC_CLOCK); mf =sysconf(_SC_MAPPED_FILES); #if VERBOSE > 0 output("Test starting\n"); output("System abilities:\n"); output(" TPS : %li\n", pshared); output(" CS : %li\n", cs); output(" MON : %li\n", monotonic); output(" MF : %li\n", mf); if ((mf < 0) || (pshared < 0)) output("Process-shared attributes won't be tested\n"); if ((cs < 0) || (monotonic < 0)) output("Alternative clock won't be tested\n"); #endif /* We are not interested in testing the clock if we have no other clock available.. */ if (monotonic < 0) cs = -1; #ifndef USE_ALTCLK if (cs > 0) output("Implementation supports the MONOTONIC CLOCK but option is disabled in test.\n"); #endif /********** * Allocate space for the testdata structure */ if (mf < 0) { /* Cannot mmap a file, we use an alternative method */ td = &alternativ; pshared = -1; /* We won't do this testing anyway */ #if VERBOSE > 0 output("Testdata allocated in the process memory.\n"); #endif } else { /* We will place the test data in a mmaped file */ char filename[] = "/tmp/cond_wait_2-2-XXXXXX"; size_t sz; void * mmaped; int fd; char * tmp; /* We now create the temp files */ fd = mkstemp(filename); if (fd == -1) { UNRESOLVED(errno, "Temporary file could not be created"); } /* and make sure the file will be deleted when closed */ unlink(filename); #if VERBOSE > 1 output("Temp file created (%s).\n", filename); #endif sz= (size_t)sysconf(_SC_PAGESIZE); tmp = calloc(1, sz); if (tmp == NULL) { UNRESOLVED(errno, "Memory allocation failed"); } /* Write the data to the file. */ if (write (fd, tmp, sz) != (ssize_t) sz) { UNRESOLVED(sz, "Writting to the file failed"); } free(tmp); /* Now we can map the file in memory */ mmaped = mmap(NULL, sz, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); if (mmaped == MAP_FAILED) { UNRESOLVED(errno, "mmap failed"); } td = (testdata_t *) mmaped; /* Our datatest structure is now in shared memory */ #if VERBOSE > 1 output("Testdata allocated in shared memory.\n"); #endif } /********** * For each test scenario, initialize the attributes and other variables. */ for ( i=0; i< (sizeof(scenarii) / sizeof(scenarii[0])); i++) { #if VERBOSE > 1 output("[parent] Preparing attributes for: %s\n", scenarii[i].descr); #endif /* set / reset everything */ do_fork=0; ret = pthread_mutexattr_init(&ma); if (ret != 0) { UNRESOLVED(ret, "[parent] Unable to initialize the mutex attribute object"); } ret = pthread_condattr_init(&ca); if (ret != 0) { UNRESOLVED(ret, "[parent] Unable to initialize the cond attribute object"); } /* Set the mutex type */ ret = pthread_mutexattr_settype(&ma, scenarii[i].m_type); if (ret != 0) { UNRESOLVED(ret, "[parent] Unable to set mutex type"); } #if VERBOSE > 1 output("[parent] Mutex type : %i\n", scenarii[i].m_type); #endif /* Set the pshared attributes, if supported */ if ((pshared > 0) && (scenarii[i].mc_pshared != 0)) { ret = pthread_mutexattr_setpshared(&ma, PTHREAD_PROCESS_SHARED); if (ret != 0) { UNRESOLVED(ret, "[parent] Unable to set the mutex process-shared"); } ret = pthread_condattr_setpshared(&ca, PTHREAD_PROCESS_SHARED); if (ret != 0) { UNRESOLVED(ret, "[parent] Unable to set the cond var process-shared"); } #if VERBOSE > 1 output("[parent] Mutex & cond are process-shared\n"); #endif } #if VERBOSE > 1 else { output("[parent] Mutex & cond are process-private\n"); } #endif /* Set the alternative clock, if supported */ #ifdef USE_ALTCLK if ((cs > 0) && (scenarii[i].c_clock != 0)) { ret = pthread_condattr_setclock(&ca, CLOCK_MONOTONIC); if (ret != 0) { UNRESOLVED(ret, "[parent] Unable to set the monotonic clock for the cond"); } #if VERBOSE > 1 output("[parent] Cond uses the Monotonic clock\n"); #endif } #if VERBOSE > 1 else { output("[parent] Cond uses the default clock\n"); } #endif #endif /* Tell whether the test will be across processes */ if ((pshared > 0) && (scenarii[i].fork != 0)) { do_fork = 1; #if VERBOSE > 1 output("[parent] Child will be a new process\n"); #endif } #if VERBOSE > 1 else { output("[parent] Child will be a new thread\n"); } #endif /********** * Initialize the testdata_t structure with the previously defined attributes */ /* Initialize the mutex */ ret = pthread_mutex_init(&(td->mtx), &ma); if (ret != 0) { UNRESOLVED(ret, "[parent] Mutex init failed"); } /* initialize the condvar */ ret = pthread_cond_init(&(td->cnd), &ca); if (ret != 0) { UNRESOLVED(ret, "[parent] Cond init failed"); } /* Initialize the other datas from the test structure */ #ifdef USE_ALTCLK ret = pthread_condattr_getclock(&ca, &(td->cid)); if (ret != 0) { UNRESOLVED(ret, "[parent] Unable to read cond clock attribute"); } #else td->cid = CLOCK_REALTIME; #endif ret = pthread_mutexattr_gettype(&ma, &(td->type)); if (ret != 0) { UNRESOLVED(ret, "[parent] Unable to read mutex type attribute"); } td->ctrl=0; td->bool=0; td->status=0; /********** * Proceed to the actual testing */ /* Create the child */ if (do_fork != 0) { /* We are testing across two processes */ child_pr = fork(); if (child_pr == -1) { UNRESOLVED(errno, "[parent] Fork failed"); } if (child_pr == 0) { #if VERBOSE > 1 output("[child] Child process starting...\n"); #endif if (tf((void *)td) != NULL) { UNRESOLVED( -1, "[child] Got an unexpected return value from test function"); } else { /* We cannot use the PASSED macro here since it would terminate the output */ exit (0); } } /* Only the parent process goes further */ } else /* do_fork == 0 */ { /* We are testing across two threads */ ret = pthread_create(&child_th, NULL, tf, td); if (ret != 0) { UNRESOLVED(ret, "[parent] Unable to create the child thread."); } } /* Note: in case of an error, the child process will be alive for 10 sec then exit. */ /* Child is now running and will enter the timedwait */ /* We are waiting for this; and we have to monitor the status value as well. */ ret = pthread_mutex_lock(&(td->mtx)); if (ret != 0) { UNRESOLVED(ret, "[parent] Unable to lock the mutex"); } while ((td->ctrl == 0) && (td->status == 0)) { ret = pthread_mutex_unlock(&(td->mtx)); if (ret != 0) { UNRESOLVED(ret, "[parent] Unable to unlock the mutex"); } sched_yield(); ret = pthread_mutex_lock(&(td->mtx)); if (ret != 0) { UNRESOLVED(ret, "[parent] Unable to lock the mutex"); } } if ((td->ctrl == 2) && (td->status == 0)) /* Spurious wakeups hapenned */ { output("Spurious wake ups have happened. Maybe pthread_cond_wait is broken?\n"); td->ctrl = 1; } if (td->ctrl == 1)/* The child is inside the cond wait */ { ret = pthread_cond_signal(&(td->cnd)); if (ret != 0) { UNRESOLVED(ret, "[parent] Unable to signal the condition"); } /* Let the child leave the wait function if something is broken */ usleep(100); if (td->ctrl != 1) { FAILED("[parent] Child went out from pthread_cond_wait without locking the mutex"); } /* Allow the child to continue */ td->bool=1; } /* Let the child do its checking */ ret = pthread_mutex_unlock(&(td->mtx)); if (ret != 0) { UNRESOLVED(ret, "[parent] Unable to unlock the mutex"); } /* Wait for the child to terminate */ if (do_fork != 0) { /* We were testing across two processes */ chkpid = waitpid(child_pr, &status, 0); if (chkpid != child_pr) { output("Expected pid: %i. Got %i\n", (int)child_pr, (int)chkpid); UNRESOLVED(errno, "Waitpid failed"); } if (WIFSIGNALED(status)) { output("Child process killed with signal %d\n",WTERMSIG(status)); UNRESOLVED( td->status , "Child process was killed"); } if (WIFEXITED(status)) { ret = WEXITSTATUS(status); } else { UNRESOLVED( td->status, "Child process was neither killed nor exited"); } if (ret != 0) { exit(ret); /* Output has already been closed in child */ } } else /* child was a thread */ { ret = pthread_join(child_th, NULL); if (ret != 0) { UNRESOLVED(ret, "[parent] Unable to join the thread"); } } /********** * Destroy the data */ ret = pthread_cond_destroy(&(td->cnd)); if (ret != 0) { UNRESOLVED(ret, "Failed to destroy the cond var"); } ret = pthread_mutex_destroy(&(td->mtx)); if (ret != 0) { UNRESOLVED(ret, "Failed to destroy the mutex"); } ret = pthread_condattr_destroy(&ca); if (ret != 0) { UNRESOLVED(ret, "Failed to destroy the cond var attribute object"); } ret = pthread_mutexattr_destroy(&ma); if (ret != 0) { UNRESOLVED(ret, "Failed to destroy the mutex attribute object"); } } /* Proceed to the next scenario */ #if VERBOSE > 0 output("Test passed\n"); #endif PASSED; } #else /* WITHOUT_XOPEN */ int main(int argc, char * argv[]) { output_init(); UNTESTED("This test requires XSI features"); } #endif posixtestsuite/conformance/interfaces/pthread_cond_wait/4-1.c0100644000000000000000000002153610336125321023434 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertion: * The function does not return an error code of EINTR * The steps are: * * -> Create a thread which wait in a condition for a small time. * -> Another thread will signal this condition from time to time. * -> Another thread which loops on sending a signal to the first thread. * */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /********************************************************************************************/ /****************************** standard includes *****************************************/ /********************************************************************************************/ #include #include #include #include #include #include #include #include #include /********************************************************************************************/ /****************************** Test framework *****************************************/ /********************************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /********************************************************************************************/ /********************************** Configuration ******************************************/ /********************************************************************************************/ #define WITH_SYNCHRO #ifndef VERBOSE #define VERBOSE 2 #endif #define INTERVAL (700) /* ns, frequency (actually, period) for the condition signaling */ /********************************************************************************************/ /*********************************** Test case *****************************************/ /********************************************************************************************/ char do_it=1; char woken=0; unsigned long count_cnd_sig=0, count_cnd_wup=0; #ifdef WITH_SYNCHRO sem_t semsig1; sem_t semsig2; unsigned long count_sig=0; #endif sigset_t usersigs; typedef struct { int sig; #ifdef WITH_SYNCHRO sem_t *sem; #endif } thestruct; struct { pthread_mutex_t mtx; pthread_cond_t cnd; } data; /* the following function keeps on sending the signal to the process */ void * sendsig (void * arg) { thestruct *thearg = (thestruct *) arg; int ret; pid_t process; process=getpid(); /* We block the signals SIGUSR1 and SIGUSR2 for this THREAD */ ret = pthread_sigmask(SIG_BLOCK, &usersigs, NULL); if (ret != 0) { UNRESOLVED(ret, "Unable to block SIGUSR1 and SIGUSR2 in signal thread"); } while (do_it) { #ifdef WITH_SYNCHRO if ((ret = sem_wait(thearg->sem))) { UNRESOLVED(errno, "Sem_wait in sendsig"); } count_sig++; #endif ret = kill(process, thearg->sig); if (ret != 0) { UNRESOLVED(errno, "Kill in sendsig"); } } return NULL; } /* Next are the signal handlers. */ /* This one is registered for signal SIGUSR1 */ void sighdl1(int sig) { #ifdef WITH_SYNCHRO if (sem_post(&semsig1)) { UNRESOLVED(errno, "Sem_post in signal handler 1"); } #endif } /* This one is registered for signal SIGUSR2 */ void sighdl2(int sig) { #ifdef WITH_SYNCHRO if (sem_post(&semsig2)) { UNRESOLVED(errno, "Sem_post in signal handler 2"); } #endif } /* The following function will wait on the cond * it does check that no error code of EINTR is returned */ void * waiter(void * arg) { int ret; /* We don't block the signals SIGUSR1 and SIGUSR2 for this THREAD */ ret = pthread_sigmask(SIG_UNBLOCK, &usersigs, NULL); if (ret != 0) { UNRESOLVED(ret, "Unable to unblock SIGUSR1 and SIGUSR2 in worker thread"); } ret = pthread_mutex_lock(&(data.mtx)); if (ret != 0) { UNRESOLVED(ret, "Unable to lock mutex in waiter thread"); } do { ret = pthread_cond_wait(&(data.cnd),&(data.mtx)); count_cnd_wup++; } while ((ret == 0) && (do_it != 0)); if (ret == EINTR) { FAILED("pthread_cond_wait returned EINTR"); } if (ret != 0) { UNRESOLVED(ret, "pthread_cond_wait returned an unexpected error"); } woken++; ret = pthread_mutex_unlock(&(data.mtx)); if (ret != 0) { UNRESOLVED(ret, "Unable to unlock mutex in waiter thread"); } return NULL; } /* The next function will signal the condition at periodic interval */ void * worker (void * arg) { int ret=0; struct timespec ts, tsrem; /* We block the signals SIGUSR1 and SIGUSR2 for this THREAD */ ret = pthread_sigmask(SIG_BLOCK, &usersigs, NULL); if (ret != 0) { UNRESOLVED(ret, "Unable to block SIGUSR1 and SIGUSR2 in signal thread"); } ts.tv_sec=0; ts.tv_nsec= INTERVAL; while (ts.tv_nsec >= 1000000000) { ts.tv_nsec -= 1000000000; ts.tv_sec +=1; } while (woken == 0) { tsrem.tv_sec = ts.tv_sec; tsrem.tv_nsec = ts.tv_nsec; do { ret = nanosleep(&tsrem, &tsrem); } while ((ret != 0) && (errno == EINTR)); ret = pthread_cond_signal(&(data.cnd)); if (ret != 0) { UNRESOLVED(ret, "Failed to signal the condition"); } count_cnd_sig++; } return NULL; } /* Main function */ int main (int argc, char * argv[]) { int ret; pthread_t th_waiter, th_worker, th_sig1, th_sig2; thestruct arg1, arg2; struct sigaction sa; output_init(); /* We need to register the signal handlers for the PROCESS */ sigemptyset (&sa.sa_mask); sa.sa_flags = 0; sa.sa_handler = sighdl1; if ((ret = sigaction (SIGUSR1, &sa, NULL))) { UNRESOLVED(ret, "Unable to register signal handler1"); } sa.sa_handler = sighdl2; if ((ret = sigaction (SIGUSR2, &sa, NULL))) { UNRESOLVED(ret, "Unable to register signal handler2"); } /* We prepare a signal set which includes SIGUSR1 and SIGUSR2 */ sigemptyset(&usersigs); ret = sigaddset(&usersigs, SIGUSR1); ret |= sigaddset(&usersigs, SIGUSR2); if (ret != 0) { UNRESOLVED(ret, "Unable to add SIGUSR1 or 2 to a signal set"); } /* We now block the signals SIGUSR1 and SIGUSR2 for this THREAD */ ret = pthread_sigmask(SIG_BLOCK, &usersigs, NULL); if (ret != 0) { UNRESOLVED(ret, "Unable to block SIGUSR1 and SIGUSR2 in main thread"); } #ifdef WITH_SYNCHRO if (sem_init(&semsig1, 0, 1)) { UNRESOLVED(errno, "Semsig1 init"); } if (sem_init(&semsig2, 0, 1)) { UNRESOLVED(errno, "Semsig2 init"); } #endif if ((ret = pthread_create(&th_waiter, NULL, waiter, NULL))) { UNRESOLVED(ret, "Waiter thread creation failed"); } if ((ret = pthread_create(&th_worker, NULL, worker, NULL))) { UNRESOLVED(ret, "Worker thread creation failed"); } arg1.sig = SIGUSR1; arg2.sig = SIGUSR2; #ifdef WITH_SYNCHRO arg1.sem = &semsig1; arg2.sem = &semsig2; #endif if ((ret = pthread_create(&th_sig1, NULL, sendsig, (void *)&arg1))) { UNRESOLVED(ret, "Signal 1 sender thread creation failed"); } if ((ret = pthread_create(&th_sig2, NULL, sendsig, (void *)&arg2))) { UNRESOLVED(ret, "Signal 2 sender thread creation failed"); } /* Let's wait for a while now */ sleep(1); /* Now stop the threads and join them */ do { do_it=0; } while (do_it); if ((ret = pthread_join(th_sig1, NULL))) { UNRESOLVED(ret, "Signal 1 sender thread join failed"); } if ((ret = pthread_join(th_sig2, NULL))) { UNRESOLVED(ret, "Signal 2 sender thread join failed"); } if ((ret = pthread_join(th_waiter, NULL))) { UNRESOLVED(ret, "Waiter thread join failed"); } if ((ret = pthread_join(th_worker, NULL))) { UNRESOLVED(ret, "Worker thread join failed"); } #if VERBOSE > 0 output("Test executed successfully.\n"); output(" Condition was signaled %d times.\n", count_cnd_sig); output(" pthread_cond_wait exited %d times.\n", count_cnd_wup); #ifdef WITH_SYNCHRO output(" %d signals were sent meanwhile.\n", count_sig); #endif #endif PASSED; } posixtestsuite/conformance/interfaces/pthread_cond_wait/1-1.c0100644000000000000000000000544007712274420023436 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: bing.wei.liu REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_cond_wait() * shall block on a condition variable. It shall be called with mutex locked * by the calling thread or undefined behavior results. */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include "posixtest.h" struct testdata { pthread_mutex_t mutex; pthread_cond_t cond; } td; pthread_t thread1; int t1_start = 0; int signaled = 0; /* Alarm handler */ void alarm_handler(int signo) { printf("Error: failed to wakeup thread\n"); pthread_cancel(thread1); exit(PTS_UNRESOLVED); } void *t1_func(void *arg) { int rc; if (pthread_mutex_lock(&td.mutex) != 0) { fprintf(stderr,"Thread1 failed to acquire mutex\n"); exit(PTS_UNRESOLVED); } fprintf(stderr,"Thread1 started\n"); t1_start = 1; /* let main thread continue */ fprintf(stderr,"Thread1 is waiting for the cond\n"); rc = pthread_cond_wait(&td.cond, &td.mutex); if (rc != 0) { fprintf(stderr,"pthread_cond_wait return %d\n", rc); exit(PTS_UNRESOLVED); } fprintf(stderr,"Thread1 wakened\n"); if (signaled == 0) { fprintf(stderr,"Thread1 did not block on the cond at all\n"); printf("Test FAILED\n"); exit(PTS_FAIL); } pthread_mutex_unlock(&td.mutex); return NULL; } int main() { struct sigaction act; if (pthread_mutex_init(&td.mutex, NULL) != 0) { fprintf(stderr,"Fail to initialize mutex\n"); return PTS_UNRESOLVED; } if (pthread_cond_init(&td.cond, NULL) != 0) { fprintf(stderr,"Fail to initialize cond\n"); return PTS_UNRESOLVED; } if (pthread_create(&thread1, NULL, t1_func, NULL) != 0) { fprintf(stderr,"Fail to create thread 1\n"); return PTS_UNRESOLVED; } while(!t1_start) /* wait for thread1 started */ usleep(100); /* acquire the mutex released by pthread_cond_wait() within thread 1 */ if (pthread_mutex_lock(&td.mutex) != 0) { fprintf(stderr,"Main: Fail to acquire mutex\n"); return PTS_UNRESOLVED; } if (pthread_mutex_unlock(&td.mutex) != 0) { fprintf(stderr,"Main: Fail to release mutex\n"); return PTS_UNRESOLVED; } sleep(2); /* Setup alarm handler */ act.sa_handler=alarm_handler; act.sa_flags=0; sigemptyset(&act.sa_mask); sigaction(SIGALRM, &act, 0); alarm(5); fprintf(stderr,"Time to wake up thread1 by signaling a condition\n"); signaled = 1; if (pthread_cond_signal(&td.cond) != 0) { fprintf(stderr,"Main: Fail to signal cond\n"); return PTS_UNRESOLVED; } pthread_join(thread1, NULL); printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_cond_wait/testfrmw.c0100644000000000000000000000407210106633571025010 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * * This file is a wrapper to use the tests from the NPTL Test & Trace Project * with either the Linux Test Project or the Open POSIX Test Suite. * The following function are defined: * void output_init() * void output_fini() * void output(char * string, ...) * * The are used to output informative text (as a printf). */ #include #include /* We use a mutex to avoid conflicts in traces */ static pthread_mutex_t m_trace = PTHREAD_MUTEX_INITIALIZER; /*****************************************************************************************/ /******************************* stdout module *****************************************/ /*****************************************************************************************/ /* The following functions will output to stdout */ #if (1) void output_init() { /* do nothing */ return; } void output( char * string, ... ) { va_list ap; char *ts="[??:??:??]"; struct tm * now; time_t nw; pthread_mutex_lock(&m_trace); nw = time(NULL); now = localtime(&nw); if (now == NULL) printf(ts); else printf("[%2.2d:%2.2d:%2.2d]", now->tm_hour, now->tm_min, now->tm_sec); va_start( ap, string); vprintf(string, ap); va_end(ap); pthread_mutex_unlock(&m_trace); } void output_fini() { /*do nothing */ return; } #endif posixtestsuite/conformance/interfaces/pthread_cond_wait/assertions.xml0100644000000000000000000000220010117555064025676 0ustar rootroot The function int pthread_cond_wait(pthread_cond_t *restrict cond, pthread_mutex_t *restrict mutex); shall block on a condition variable. It shall be called with mutex locked by the calling thread or undefined behavior results. Upon successful return, the mutex shall have been locked and shall be owned by the calling thread. Upon successful completion, a value of zero shall be returned; The pthread_cond_wait() function may fail if: [EINVAL] The value specified by cond, mutex,or abstime is invalid. [EINVAL] Different mutexes were supplied for concurrent pthread_cond_timedwait() or pthread_cond_wait() operations on the same condition variable. [EPERM] The mutex was not owned by the current thread at the time of the call. These functions shall not return an error code of [EINTR]. posixtestsuite/conformance/interfaces/pthread_cond_wait/coverage.txt0100644000000000000000000000044007650736075025335 0ustar rootrootThis document defines the coverage for the pthread_cond_wait function: Assertion Tested? 1 YES 2 YES 3 YES 4 NO * When it specifies it 'may' fail and not 'shall' fail, it will always return PASS, but will return a PASS and print out a warning if it fails. NOTE: posixtestsuite/conformance/interfaces/pthread_cond_wait/testfrmw.h0100644000000000000000000000456410106633571025023 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * * This file is a wrapper to use the tests from the NPTL Test & Trace Project * with either the Linux Test Project or the Open POSIX Test Suite. * The following macros are defined here: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate without calling one of those macros. * * */ #include "posixtest.h" #include /* for the strerror() routine */ #ifdef __GNUC__ /* We are using GCC */ #define UNRESOLVED(x, s) \ { output("Test %s unresolved: got %i (%s) on line %i (%s)\n", __FILE__, x, strerror(x), __LINE__, s); \ output_fini(); \ exit(PTS_UNRESOLVED); } #define FAILED(s) \ { output("Test %s FAILED: %s\n", __FILE__, s); \ output_fini(); \ exit(PTS_FAIL); } #define PASSED \ output_fini(); \ exit(PTS_PASS); #define UNTESTED(s) \ { output("File %s cannot test: %s\n", __FILE__, s); \ output_fini(); \ exit(PTS_UNTESTED); \ } #else /* not using GCC */ #define UNRESOLVED(x, s) \ { output("Test unresolved: got %i (%s) on line %i (%s)\n", x, strerror(x), __LINE__, s); \ output_fini(); \ exit(PTS_UNRESOLVED); } #define FAILED(s) \ { output("Test FAILED: %s\n", s); \ output_fini(); \ exit(PTS_FAIL); } #define PASSED \ output_fini(); \ exit(PTS_PASS); #define UNTESTED(s) \ { output("Unable to test: %s\n", s); \ output_fini(); \ exit(PTS_UNTESTED); \ } #endif posixtestsuite/conformance/interfaces/pthread_cond_wait/2-3.c0100644000000000000000000002775110110655117023442 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertion: * * This function is a cancelation point: when cancelability * is PTHREAD_CANCEL_DEFERRED and a cancel request arrives, the thread * must relock the mutex before the first (if any) clean up handler is called. * The steps are: * -> Create a thread * -> this thread locks a mutex then waits for a condition * -> cancel the thread * -> the cancelation handler will test if the thread owns the mutex. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /* We need the XSI extention for the mutex attributes */ #ifndef WITHOUT_XOPEN #define _XOPEN_SOURCE 600 #endif /********************************************************************************************/ /****************************** standard includes *****************************************/ /********************************************************************************************/ #include #include #include #include #include #include #include #include /********************************************************************************************/ /****************************** Test framework *****************************************/ /********************************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /********************************************************************************************/ /********************************** Configuration ******************************************/ /********************************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif #ifndef WITHOUT_ALTCLK #define USE_ALTCLK /* make tests with MONOTONIC CLOCK if supported */ #endif /********************************************************************************************/ /*********************************** Test case *****************************************/ /********************************************************************************************/ struct { pthread_mutex_t mtx; pthread_cond_t cnd; int type; sem_t semA; sem_t semB; int bool; } data; /**** First handler that will be poped * This one works only with recursive mutexes */ void clnp1 (void * arg) { int ret; if (data.type == PTHREAD_MUTEX_RECURSIVE) { ret = pthread_mutex_trylock(&(data.mtx)); if (ret != 0) { FAILED("Unable to double-lock a recursive mutex in clean-up handler 1"); } ret = pthread_mutex_unlock(&(data.mtx)); if (ret != 0) { UNRESOLVED(ret, "Unable to unlock double-locked recursive mutex in clean-up handler 1"); } } return; } /**** Second handler * This one will trigger an action in main thread, while we are owning the mutex */ void clnp2 (void * arg) { int ret; do { ret = sem_post(&(data.semA)); } while ((ret != 0) && (errno == EINTR)); if (ret != 0) { UNRESOLVED(errno, "Sem post failed in cleanup handler 2"); } do { ret = sem_wait(&(data.semB)); } while ((ret != 0) && (errno == EINTR)); if (ret != 0) { UNRESOLVED(errno, "Sem wait failed in cleanup handler 2"); } return; } /**** Third handler * Will actually unlock the mutex, then try to unlock second time to check an error is returned */ void clnp3 (void * arg) { int ret; ret = pthread_mutex_unlock(&(data.mtx)); if (ret != 0) { UNRESOLVED(ret, "Unable to unlock mutex in clean-up handler 3"); } if ((data.type == PTHREAD_MUTEX_ERRORCHECK) || (data.type == PTHREAD_MUTEX_RECURSIVE)) { ret = pthread_mutex_unlock(&(data.mtx)); if (ret == 0) { UNRESOLVED(ret, "Was able to unlock unlocked mutex in clean-up handler 3"); } } return; } /**** Thread function * This function will lock the mutex, then install the cleanup handlers * and wait for the cond. At this point it will be canceled. */ void * threaded (void * arg) { int ret; ret= pthread_mutex_lock(&(data.mtx)); if (ret != 0) { UNRESOLVED(ret, "Failed to lock the mutex in thread"); } /* Tell the main thread we got the lock */ do { ret = sem_post(&(data.semA)); } while ((ret != 0) && (errno == EINTR)); if (ret != 0) { UNRESOLVED(errno, "Sem post failed in cleanup handler 2"); } pthread_cleanup_push ( clnp3, NULL); pthread_cleanup_push ( clnp2, NULL); pthread_cleanup_push ( clnp1, NULL); do { ret = pthread_cond_wait(&(data.cnd), &(data.mtx)); } while ((ret == 0) && (data.bool == 0)); if (ret != 0) { UNRESOLVED(ret , "Wait failed"); } /* We will exit even if the error is timedwait */ /* If we are here, the thread was not canceled */ FAILED("The thread has not been canceled"); pthread_cleanup_pop(0); pthread_cleanup_pop(0); pthread_cleanup_pop(1); return NULL; } int main(int argc, char * argv[]) { int ret, i; void * rc; pthread_mutexattr_t ma; pthread_condattr_t ca; pthread_t th; long altclk_ok, pshared_ok; struct { char altclk; /* Want to use alternative clock */ char pshared; /* Want to use process-shared primitives */ int type; /* mutex type */ char * descr; /* Description of the case */ } scenar[] = { {0, 0, PTHREAD_MUTEX_NORMAL, "Normal mutex" } #ifdef USE_ALTCLK ,{1, 0, PTHREAD_MUTEX_NORMAL, "Normal mutex + altclock cond" } ,{1, 1, PTHREAD_MUTEX_NORMAL, "PShared mutex + altclock cond" } #endif ,{0, 1, PTHREAD_MUTEX_NORMAL, "Pshared mutex" } #ifndef WITHOUT_XOPEN ,{0, 0, PTHREAD_MUTEX_ERRORCHECK, "Errorcheck mutex" } ,{0, 0, PTHREAD_MUTEX_RECURSIVE , "Recursive mutex" } #ifdef USE_ALTCLK ,{1, 0, PTHREAD_MUTEX_RECURSIVE , "Recursive mutex + altclock cond" } ,{1, 0, PTHREAD_MUTEX_ERRORCHECK, "Errorcheck mutex + altclock cond" } ,{1, 1, PTHREAD_MUTEX_RECURSIVE , "Recursive pshared mutex + altclock cond" } ,{1, 1, PTHREAD_MUTEX_ERRORCHECK, "Errorcheck pshared mutex + altclock cond" } #endif ,{0, 1, PTHREAD_MUTEX_RECURSIVE , "Recursive pshared mutex" } ,{0, 1, PTHREAD_MUTEX_ERRORCHECK, "Errorcheck pshared mutex" } #endif }; output_init(); /* Initialize the constants */ altclk_ok = sysconf(_SC_CLOCK_SELECTION); if (altclk_ok > 0) altclk_ok = sysconf(_SC_MONOTONIC_CLOCK); #ifndef USE_ALTCLK if (altclk_ok > 0) output("Implementation supports the MONOTONIC CLOCK but option is disabled in test.\n"); #endif pshared_ok = sysconf(_SC_THREAD_PROCESS_SHARED); #if VERBOSE > 0 output("Test starting\n"); output(" Process-shared primitive %s be tested\n", (pshared_ok>0)?"will":"won't"); output(" Alternative clock for cond %s be tested\n", (altclk_ok>0)?"will":"won't"); #endif ret = sem_init(&(data.semA), 0, 0); if (ret != 0) { UNRESOLVED(errno, "Unable to init sem A"); } ret = sem_init(&(data.semB), 0, 0); if (ret != 0) { UNRESOLVED(errno, "Unable to init sem B"); } for (i=0; i< (sizeof(scenar) / sizeof(scenar[0])); i++) { #if VERBOSE > 1 output("Starting test for %s\n", scenar[i].descr); #endif /* Initialize the data structure */ ret = pthread_mutexattr_init(&ma); if (ret != 0) { UNRESOLVED(ret, "Mutex attribute object init failed"); } ret = pthread_mutexattr_settype(&ma, scenar[i].type); if (ret != 0) { UNRESOLVED(ret, "Unable to set mutex type"); } if ((pshared_ok > 0) && (scenar[i].pshared != 0)) { ret = pthread_mutexattr_setpshared(&ma, PTHREAD_PROCESS_SHARED); if (ret != 0) { UNRESOLVED(ret, "Unable to set mutex process-shared"); } } ret = pthread_condattr_init(&ca); if (ret != 0) { UNRESOLVED(ret, "Cond attribute object init failed"); } if ((pshared_ok > 0) && (scenar[i].pshared != 0)) { ret = pthread_condattr_setpshared(&ca, PTHREAD_PROCESS_SHARED); if (ret != 0) { UNRESOLVED(ret, "Unable to set cond process-shared"); } } #ifdef USE_ALTCLK if ((altclk_ok > 0) && (scenar[i].altclk != 0)) { ret = pthread_condattr_setclock(&ca, CLOCK_MONOTONIC); if (ret != 0) { UNRESOLVED(ret, "Unable to set alternative (monotonic) clock for cond"); } } #endif ret = pthread_mutex_init(&(data.mtx), &ma); if (ret != 0) { UNRESOLVED(ret, "Unable to init mutex"); } ret = pthread_cond_init(&(data.cnd), &ca); if (ret != 0) { UNRESOLVED(ret, "Unable to initialize condvar"); } ret = pthread_mutexattr_gettype(&ma, &(data.type)); if (ret != 0) { UNRESOLVED(ret, "Unable to get type from mutex attr"); } data.bool = 0; /** Data is ready, create the thread */ #if VERBOSE > 1 output("Initialization OK, starting thread\n"); #endif ret = pthread_create(&th, NULL, threaded, NULL); if (ret != 0) { UNRESOLVED(ret, "Thread creation failed"); } /** Wait for the thread to be waiting */ do { ret = sem_wait(&(data.semA)); } while ((ret != 0) && (errno == EINTR)); if (ret != 0) { UNRESOLVED(errno, "Sem wait failed in main"); } ret = pthread_mutex_lock(&(data.mtx)); if (ret != 0) { UNRESOLVED(ret, "Unable to lock mutex in main"); } data.bool = 1; /** Cancel the thread */ ret = pthread_cancel(th); if (ret != 0) { UNRESOLVED(ret, "Thread cancelation failed"); } sched_yield(); #ifndef WITHOUT_XOPEN usleep(100); #endif ret = pthread_mutex_unlock(&(data.mtx)); if (ret != 0) { UNRESOLVED(ret, "Unable to unlock mutex in main"); } /** Wait for the thread to be executing second cleanup handler */ do { ret = sem_wait(&(data.semA)); } while ((ret != 0) && (errno == EINTR)); if (ret != 0) { UNRESOLVED(errno, "Sem wait failed in main"); } /** Here the child should own the mutex, we check this */ ret = pthread_mutex_trylock(&(data.mtx)); if (ret == 0) { FAILED("The child did not own the mutex inside the cleanup handler"); } /** Let the cleanups go on */ do { ret = sem_post(&(data.semB)); } while ((ret != 0) && (errno == EINTR)); if (ret != 0) { UNRESOLVED(errno, "Sem post failed in main"); } /** Join the thread */ ret = pthread_join(th, &rc); if (ret != 0) { UNRESOLVED(ret, "Unable to join the thread"); } if (rc != PTHREAD_CANCELED) { FAILED("thread was not canceled"); } #if VERBOSE > 1 output("Test passed for %s\n\n", scenar[i].descr); #endif /* Destroy datas */ ret = pthread_cond_destroy(&(data.cnd)); if (ret != 0) { UNRESOLVED(ret, "Cond destroy failed"); } ret = pthread_mutex_destroy(&(data.mtx)); if (ret != 0) { UNRESOLVED(ret, "Mutex destroy failed"); } ret = pthread_condattr_destroy(&ca); if (ret != 0) { UNRESOLVED(ret, "Cond attribute destroy failed"); } ret = pthread_mutexattr_destroy(&ma); if (ret != 0) { UNRESOLVED(ret, "Mutex attr destroy failed"); } } /* Proceed to next case */ ret = sem_destroy(&(data.semA)); if (ret != 0) { UNRESOLVED(errno, "Sem destroy failed"); } ret = sem_destroy(&(data.semB)); if (ret != 0) { UNRESOLVED(errno, "Sem destroy failed"); } PASSED; } posixtestsuite/conformance/interfaces/pthread_cond_wait/2-1.c0100644000000000000000000000625207712274420023441 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: bing.wei.liu REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_cond_wait() * Upon successful return, the mutex shall have been locked and shall be owned * by the calling thread. */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include "posixtest.h" struct testdata { pthread_mutex_t mutex; pthread_cond_t cond; } td; pthread_t thread1; int t1_start = 0; int signaled = 0; /* Alarm handler */ void alarm_handler(int signo) { printf("Error: failed to wakeup thread\n"); pthread_cancel(thread1); exit(PTS_UNRESOLVED); } void *t1_func(void *arg) { int rc; if (pthread_mutex_lock(&td.mutex) != 0) { fprintf(stderr,"Thread1 failed to acquire the mutex\n"); exit(PTS_UNRESOLVED); } fprintf(stderr,"Thread1 started\n"); t1_start = 1; /* let main thread continue */ fprintf(stderr,"Thread1 is waiting for the cond\n"); rc = pthread_cond_wait(&td.cond, &td.mutex); if(rc != 0) { fprintf(stderr,"pthread_cond_wait return %d\n", rc); exit(PTS_UNRESOLVED); } fprintf(stderr,"Thread1 wakened\n"); if(signaled == 0) { fprintf(stderr,"Thread1 did not block on the cond at all\n"); exit(PTS_UNRESOLVED); } if (pthread_mutex_trylock(&td.mutex) == 0) { fprintf(stderr,"Thread1 should not be able to lock the mutex again\n"); printf("Test FAILED\n"); exit(PTS_FAIL); } fprintf(stderr,"Thread1 failed to trylock the mutex (as expected)\n"); if (pthread_mutex_unlock(&td.mutex) != 0) { fprintf(stderr,"Thread1 failed to release the mutex\n"); printf("Test FAILED\n"); exit(PTS_FAIL); } fprintf(stderr,"Thread1 released the mutex\n"); return NULL; } int main() { struct sigaction act; if (pthread_mutex_init(&td.mutex, NULL) != 0) { fprintf(stderr,"Fail to initialize mutex\n"); return PTS_UNRESOLVED; } if (pthread_cond_init(&td.cond, NULL) != 0) { fprintf(stderr,"Fail to initialize cond\n"); return PTS_UNRESOLVED; } if (pthread_create(&thread1, NULL, t1_func, NULL) != 0) { fprintf(stderr,"Fail to create thread 1\n"); return PTS_UNRESOLVED; } while(!t1_start) /* wait for thread1 started */ usleep(100); /* acquire the mutex released by pthread_cond_wait() within thread 1 */ if (pthread_mutex_lock(&td.mutex) != 0) { fprintf(stderr,"Main failed to acquire mutex\n"); return PTS_UNRESOLVED; } if (pthread_mutex_unlock(&td.mutex) != 0) { fprintf(stderr,"Main failed to release mutex\n"); return PTS_UNRESOLVED; } sleep(1); /* Setup alarm handler */ act.sa_handler=alarm_handler; act.sa_flags=0; sigemptyset(&act.sa_mask); sigaction(SIGALRM, &act, 0); alarm(5); fprintf(stderr,"Time to wake up thread1 by signaling a condition\n"); signaled = 1; if (pthread_cond_signal(&td.cond) != 0) { fprintf(stderr,"Main failed to signal the condition\n"); return PTS_UNRESOLVED; } pthread_join(thread1, NULL); printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_cond_wait/3-1.c0100644000000000000000000000534107712274420023440 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: bing.wei.liu REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_cond_wait() * Upon successful completion, a value of zero shall be returned. */ #include #include #include #include #include #include #include "posixtest.h" struct testdata { pthread_mutex_t mutex; pthread_cond_t cond; } td; pthread_t thread1; int t1_start = 0; int signaled = 0; /* Alarm handler */ void alarm_handler(int signo) { printf("Error: failed to wakeup thread\n"); pthread_cancel(thread1); exit(PTS_UNRESOLVED); } void *t1_func(void *arg) { int rc; if (pthread_mutex_lock(&td.mutex) != 0) { fprintf(stderr,"Thread1 failed to acquire the mutex\n"); exit(PTS_UNRESOLVED); } fprintf(stderr,"Thread1 started\n"); t1_start = 1; /* let main thread continue */ fprintf(stderr,"Thread1 is waiting for the cond\n"); rc = pthread_cond_wait(&td.cond, &td.mutex); if(rc != 0) { if (rc == EINVAL) { fprintf(stderr,"pthread_cond_wait returns EINVAL\n"); exit(PTS_UNRESOLVED); } else if (rc == EPERM) { fprintf(stderr,"pthread_cond_wait returns EPERM\n"); exit(PTS_UNRESOLVED); } fprintf(stderr,"pthread_cond_wait returns %d\n", rc); exit(PTS_UNRESOLVED); } if(signaled == 0) { fprintf(stderr,"Thread1 waked up before being notified\n"); exit(PTS_UNRESOLVED); } fprintf(stderr,"Thread1 wakened up and got returned value 0\n"); if (pthread_mutex_unlock(&td.mutex) != 0) { fprintf(stderr,"Thread1 failed to release the mutex\n"); exit(PTS_UNRESOLVED); } fprintf(stderr,"Thread1 released the mutex\n"); return NULL; } int main() { struct sigaction act; if (pthread_mutex_init(&td.mutex, NULL) != 0) { fprintf(stderr,"Fail to initialize mutex\n"); return PTS_UNRESOLVED; } if (pthread_cond_init(&td.cond, NULL) != 0) { fprintf(stderr,"Fail to initialize cond\n"); return PTS_UNRESOLVED; } if (pthread_create(&thread1, NULL, t1_func, NULL) != 0) { fprintf(stderr,"Fail to create thread 1\n"); return PTS_UNRESOLVED; } sleep(2); /* Setup alarm handler */ act.sa_handler=alarm_handler; act.sa_flags=0; sigemptyset(&act.sa_mask); sigaction(SIGALRM, &act, 0); alarm(5); fprintf(stderr,"To wake up thread1 by broadcasting its waited condition\n"); signaled = 1; if (pthread_cond_broadcast(&td.cond) != 0) { fprintf(stderr,"Main failed to broadcast the condition\n"); return PTS_UNRESOLVED; } pthread_join(thread1, NULL); printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_spin_destroy/0040755000000000000000000000000010515625227023547 5ustar rootrootposixtestsuite/conformance/interfaces/pthread_spin_destroy/1-1.c0100644000000000000000000000330707703061243024206 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * * Test pthread_spin_destroy(pthread_spinlock_t * lock) * * pthread_spin_destroy( ) function shall destroy the spin lock * referenced by lock and release any resources used by the lock. * * Steps: * 1. Initialize a pthread_spinlock_t object 'spinlock' with * pthread_spin_init() * 2. Main thread lock 'spinlock', should get the lock * 3. Main thread unlock 'spinlock' * 4. Main thread destroy the 'spinlock' */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include "posixtest.h" static pthread_spinlock_t spinlock; int main() { int rc = 0; printf("main: initialize spin lock\n"); if(pthread_spin_init(&spinlock, PTHREAD_PROCESS_PRIVATE) != 0) { printf("main: Error at pthread_spin_init()\n"); return PTS_UNRESOLVED; } printf("main: attempt spin lock\n"); /* We should get the lock */ if(pthread_spin_lock(&spinlock) != 0) { printf("Unresolved: main cannot get spin lock when no one owns the lock\n"); return PTS_UNRESOLVED; } printf("main: acquired spin lock\n"); printf("main: unlock spin lock\n"); if(pthread_spin_unlock(&spinlock) != 0) { printf("main: Error at pthread_spin_unlock()\n"); return PTS_UNRESOLVED; } printf("main: destroy spin lock\n"); rc = pthread_spin_destroy(&spinlock); if(rc != 0) { printf("Test FAILED: Error at pthread_spin_destroy()" "Return code : %d\n", rc); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_spin_destroy/assertions.xml0100644000000000000000000000146210117555067026465 0ustar rootroot pthread_spin_destroy( ) function shall destroy the spin lock referenced by lock and release any resources used by the lock. Upon successful completion, these functions shall return zero; otherwise, an error number shall be returned to indicate the error. The functions may fail if: [EBUSY] The implementation has detected an attempt to initialize or destroy a spin lock while it is in use (for example, while being used in a pthread_spin_lock( ) call) by another thread. [EINVAL] The value specified by lock is invalid. These functions shall not return an error code of EINTR. posixtestsuite/conformance/interfaces/pthread_spin_destroy/coverage.txt0100644000000000000000000000017307703061243026076 0ustar rootrootThis document defines the coverage for the pthread_spin_destroy() function: Assertion Tested? 1 YES 2 YES 3 YES NOTE: posixtestsuite/conformance/interfaces/pthread_spin_destroy/2-1.sh0100755000000000000000000000074107703061243024401 0ustar rootroot#!/bin/sh # Copyright (c) 2002, Intel Corporation. All rights reserved. # This file is licensed under the GPL license. For the full content # of this license, see the COPYING file at the top level of this # source tree. # Upon successful completion, these functions shall return zero; # otherwise, an error number shall be returned to indicate the error. # This is tested implicitly via assertion 1. echo "Tested implicitly via assertion 1. See output for status" exit 0 posixtestsuite/conformance/interfaces/pthread_spin_destroy/3-1.c0100644000000000000000000000415207703061243024207 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test pthread_spin_destroy(pthread_spinlock_t *lock) may fail if: * * [EBUSY] The implementation has detected an attempt to * initialize or destroy a spin lock while it is in use * (for example, while being used in a pthread_spin_lock( ) * call) by another thread. * * Note: This test will always pass * * Steps: * 1. Initialize a pthread_spinlock_t object 'spinlock' with * pthread_spin_init() * 2. Main thread lock 'spinlock', should get the lock * 3. Create a child thread. The thread call pthread_spin_destroy() */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include #include "posixtest.h" static pthread_spinlock_t spinlock; static void* fn_chld(void *arg) { int rc = 0; printf("child: destroy spin lock\n"); rc = pthread_spin_destroy(&spinlock); if(rc == EBUSY) { printf("child: correctly got EBUSY\n"); printf("Test PASSED\n"); } else { printf("child: got return code %d, %s\n", rc, strerror(rc)); printf("Test PASSED: *Note: Did not return EBUSY when destroying a spinlock already in use, but standard says 'may' fail\n"); } exit(PTS_PASS); } int main() { pthread_t child_thread; if(pthread_spin_init(&spinlock, PTHREAD_PROCESS_PRIVATE) != 0) { printf("main: Error at pthread_spin_init()\n"); return PTS_UNRESOLVED; } printf("main: attempt spin lock\n"); /* We should get the lock */ if(pthread_spin_lock(&spinlock) != 0) { printf("main cannot get spin lock when no one owns the lock\n"); return PTS_UNRESOLVED; } printf("main: acquired spin lock\n"); printf("main: create thread\n"); if(pthread_create(&child_thread, NULL, fn_chld, NULL) != 0) { printf("main: Error creating child thread\n"); return PTS_UNRESOLVED; } /* Wait for thread to end execution */ pthread_join(child_thread, NULL); return PTS_PASS; } posixtestsuite/conformance/interfaces/aio_suspend/0040755000000000000000000000000010515625160021623 5ustar rootrootposixtestsuite/conformance/interfaces/aio_suspend/5-1.c0100644000000000000000000000135210247562115022271 0ustar rootroot/* * Copyright (c) 2004, Bull SA. All rights reserved. * Created by: Laurent.Vivier@bull.net * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * assertion: * * If the monotonic clock option is supported, the clock that shall be * used to measure this time interval shall be CLOCK_MONOTONIC clock. * * method: * * UNTESTED */ #define _XOPEN_SOURCE 600 #include #include #include #include #include "posixtest.h" int main() { #if _POSIX_ASYNCHRONOUS_IO != 200112L exit(PTS_UNSUPPORTED); #endif #if _POSIX_MONOTONIC_CLOCK == 0 exit(PTS_UNSUPPORTED); #endif return PTS_UNTESTED; } posixtestsuite/conformance/interfaces/aio_suspend/4-1.c0100644000000000000000000001251010247562115022266 0ustar rootroot/* * Copyright (c) 2004, Bull SA. All rights reserved. * Created by: Laurent.Vivier@bull.net * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * assertion: * * On a timeout exit, aio_suspend shall return with an error. * * method: Testing for a non NULL timeout * * - write to a file * - submit a list of read requests * - check that the selected request has not completed * - suspend on selected request * - check that the suspend timed out * - check return code and errno * */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include "posixtest.h" #define TNAME "aio_suspend/4-1.c" #define NUM_AIOCBS 10 #define BUF_SIZE 1024*1024 #define WAIT_FOR_AIOCB 6 int received_selected = 0; int received_all = 0; void sigrt1_handler(int signum, siginfo_t *info, void *context) { if (info->si_value.sival_int == WAIT_FOR_AIOCB) received_selected = 1; } void sigrt2_handler(int signum, siginfo_t *info, void *context) { received_all = 1; } int main () { char tmpfname[256]; int fd; struct aiocb **aiocbs; struct aiocb *plist[2]; char *bufs; struct sigaction action; struct sigevent event; struct timespec ts = {0, 10000000}; /* 10 ms */ int errors = 0; int ret; int err; int i; #if _POSIX_ASYNCHRONOUS_IO != 200112L exit(PTS_UNSUPPORTED); #endif snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_aio_suspend_4_1_%d", getpid()); unlink(tmpfname); fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL, S_IRUSR | S_IWUSR); if (fd == -1) { printf(TNAME " Error at open(): %s\n", strerror(errno)); exit(PTS_UNRESOLVED); } unlink(tmpfname); bufs = (char *) malloc (NUM_AIOCBS*BUF_SIZE); if (bufs == NULL) { printf (TNAME " Error at malloc(): %s\n", strerror (errno)); close (fd); exit(PTS_UNRESOLVED); } if (write (fd, bufs, NUM_AIOCBS*BUF_SIZE) != (NUM_AIOCBS*BUF_SIZE)) { printf(TNAME " Error at write(): %s\n", strerror(errno)); free (bufs); close (fd); exit(PTS_UNRESOLVED); } aiocbs = (struct aiocb**)malloc(sizeof(struct aiocb *) * NUM_AIOCBS); /* Queue up a bunch of aio reads */ for (i = 0; i < NUM_AIOCBS; i++) { aiocbs[i] = (struct aiocb*)malloc(sizeof(struct aiocb)); memset(aiocbs[i], 0, sizeof(struct aiocb)); aiocbs[i]->aio_fildes = fd; aiocbs[i]->aio_offset = i * BUF_SIZE; aiocbs[i]->aio_buf = &bufs[i*BUF_SIZE]; aiocbs[i]->aio_nbytes = BUF_SIZE; aiocbs[i]->aio_lio_opcode = LIO_READ; /* Use SIRTMIN+1 for individual completions */ aiocbs[i]->aio_sigevent.sigev_notify = SIGEV_SIGNAL; aiocbs[i]->aio_sigevent.sigev_signo = SIGRTMIN+1; aiocbs[i]->aio_sigevent.sigev_value.sival_int = i; } /* Use SIGRTMIN+2 for list completion */ event.sigev_notify = SIGEV_SIGNAL; event.sigev_signo = SIGRTMIN+2; event.sigev_value.sival_ptr = NULL; /* Setup handler for individual operation completion */ action.sa_sigaction = sigrt1_handler; sigemptyset(&action.sa_mask); action.sa_flags = SA_SIGINFO|SA_RESTART; sigaction(SIGRTMIN+1, &action, NULL); /* Setup handler for list completion */ action.sa_sigaction = sigrt2_handler; sigemptyset(&action.sa_mask); action.sa_flags = SA_SIGINFO|SA_RESTART; sigaction(SIGRTMIN+2, &action, NULL); /* Setup suspend list */ plist[0] = NULL; plist[1] = aiocbs[WAIT_FOR_AIOCB]; /* Submit request list */ ret = lio_listio(LIO_NOWAIT, aiocbs, NUM_AIOCBS, &event); if (ret) { printf(TNAME " Error at lio_listio() %d: %s\n", errno, strerror(errno)); for (i=0; i #include #include #include #include #include #include "posixtest.h" #define TNAME "aio_suspend/1-1.c" #define NUM_AIOCBS 10 #define BUF_SIZE 1024*1024 #define WAIT_FOR_AIOCB 6 int received_selected = 0; int received_all = 0; void sigrt1_handler(int signum, siginfo_t *info, void *context) { if (info->si_value.sival_int == WAIT_FOR_AIOCB) received_selected = 1; } void sigrt2_handler(int signum, siginfo_t *info, void *context) { received_all = 1; } int main () { char tmpfname[256]; int fd; struct aiocb **aiocbs; struct aiocb *plist[2]; char *bufs; struct sigaction action; struct sigevent event; int errors = 0; int ret; int err; int i; #if _POSIX_ASYNCHRONOUS_IO != 200112L exit(PTS_UNSUPPORTED); #endif snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_aio_suspend_1_1_%d", getpid()); unlink(tmpfname); fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL, S_IRUSR | S_IWUSR); if (fd == -1) { printf(TNAME " Error at open(): %s\n", strerror(errno)); exit(PTS_UNRESOLVED); } unlink(tmpfname); bufs = (char *) malloc (NUM_AIOCBS*BUF_SIZE); if (bufs == NULL) { printf (TNAME " Error at malloc(): %s\n", strerror (errno)); close (fd); exit(PTS_UNRESOLVED); } if (write (fd, bufs, NUM_AIOCBS*BUF_SIZE) != (NUM_AIOCBS*BUF_SIZE)) { printf(TNAME " Error at write(): %s\n", strerror(errno)); free (bufs); close (fd); exit(PTS_UNRESOLVED); } aiocbs = (struct aiocb**)malloc(sizeof(struct aiocb *) * NUM_AIOCBS); /* Queue up a bunch of aio reads */ for (i = 0; i < NUM_AIOCBS; i++) { aiocbs[i] = (struct aiocb*)malloc(sizeof(struct aiocb)); memset(aiocbs[i], 0, sizeof(struct aiocb)); aiocbs[i]->aio_fildes = fd; aiocbs[i]->aio_offset = i * BUF_SIZE; aiocbs[i]->aio_buf = &bufs[i*BUF_SIZE]; aiocbs[i]->aio_nbytes = BUF_SIZE; aiocbs[i]->aio_lio_opcode = LIO_READ; /* Use SIRTMIN+1 for individual completions */ aiocbs[i]->aio_sigevent.sigev_notify = SIGEV_SIGNAL; aiocbs[i]->aio_sigevent.sigev_signo = SIGRTMIN+1; aiocbs[i]->aio_sigevent.sigev_value.sival_int = i; } /* Use SIGRTMIN+2 for list completion */ event.sigev_notify = SIGEV_SIGNAL; event.sigev_signo = SIGRTMIN+2; event.sigev_value.sival_ptr = NULL; /* Setup handler for individual operation completion */ action.sa_sigaction = sigrt1_handler; sigemptyset(&action.sa_mask); action.sa_flags = SA_SIGINFO|SA_RESTART; sigaction(SIGRTMIN+1, &action, NULL); /* Setup handler for list completion */ action.sa_sigaction = sigrt2_handler; sigemptyset(&action.sa_mask); action.sa_flags = SA_SIGINFO|SA_RESTART; sigaction(SIGRTMIN+2, &action, NULL); /* Setup suspend list */ plist[0] = NULL; plist[1] = aiocbs[WAIT_FOR_AIOCB]; /* Submit request list */ ret = lio_listio(LIO_NOWAIT, aiocbs, NUM_AIOCBS, &event); if (ret) { printf(TNAME " Error at lio_listio() %d: %s\n", errno, strerror(errno)); for (i=0; i #include #include #include #include #include #include "posixtest.h" #define TNAME "aio_suspend/9-1.c" #define NUM_AIOCBS 10 #define BUF_SIZE 1024*1024 #define WAIT_FOR_AIOCB 6 int received_selected = 0; int received_all = 0; void sigrt1_handler(int signum, siginfo_t *info, void *context) { if (info->si_value.sival_int == WAIT_FOR_AIOCB) received_selected = 1; } void sigrt2_handler(int signum, siginfo_t *info, void *context) { received_all = 1; } int main () { char tmpfname[256]; int fd; struct aiocb **aiocbs; struct aiocb *plist[2]; char *bufs; struct sigaction action; struct sigevent event; struct timespec ts = {0, 10000000}; /* 10 ms */ int errors = 0; int ret; int err; int i; #if _POSIX_ASYNCHRONOUS_IO != 200112L exit(PTS_UNSUPPORTED); #endif snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_aio_suspend_9_1_%d", getpid()); unlink(tmpfname); fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL, S_IRUSR | S_IWUSR); if (fd == -1) { printf(TNAME " Error at open(): %s\n", strerror(errno)); exit(PTS_UNRESOLVED); } unlink(tmpfname); bufs = (char *) malloc (NUM_AIOCBS*BUF_SIZE); if (bufs == NULL) { printf (TNAME " Error at malloc(): %s\n", strerror (errno)); close (fd); exit(PTS_UNRESOLVED); } if (write (fd, bufs, NUM_AIOCBS*BUF_SIZE) != (NUM_AIOCBS*BUF_SIZE)) { printf(TNAME " Error at write(): %s\n", strerror(errno)); free (bufs); close (fd); exit(PTS_UNRESOLVED); } aiocbs = (struct aiocb**)malloc(sizeof(struct aiocb *) * NUM_AIOCBS); /* Queue up a bunch of aio reads */ for (i = 0; i < NUM_AIOCBS; i++) { aiocbs[i] = (struct aiocb*)malloc(sizeof(struct aiocb)); memset(aiocbs[i], 0, sizeof(struct aiocb)); aiocbs[i]->aio_fildes = fd; aiocbs[i]->aio_offset = i * BUF_SIZE; aiocbs[i]->aio_buf = &bufs[i*BUF_SIZE]; aiocbs[i]->aio_nbytes = BUF_SIZE; aiocbs[i]->aio_lio_opcode = LIO_READ; /* Use SIRTMIN+1 for individual completions */ aiocbs[i]->aio_sigevent.sigev_notify = SIGEV_SIGNAL; aiocbs[i]->aio_sigevent.sigev_signo = SIGRTMIN+1; aiocbs[i]->aio_sigevent.sigev_value.sival_int = i; } /* Use SIGRTMIN+2 for list completion */ event.sigev_notify = SIGEV_SIGNAL; event.sigev_signo = SIGRTMIN+2; event.sigev_value.sival_ptr = NULL; /* Setup handler for individual operation completion */ action.sa_sigaction = sigrt1_handler; sigemptyset(&action.sa_mask); action.sa_flags = SA_SIGINFO|SA_RESTART; sigaction(SIGRTMIN+1, &action, NULL); /* Setup handler for list completion */ action.sa_sigaction = sigrt2_handler; sigemptyset(&action.sa_mask); action.sa_flags = SA_SIGINFO|SA_RESTART; sigaction(SIGRTMIN+2, &action, NULL); /* Setup suspend list */ plist[0] = NULL; plist[1] = aiocbs[WAIT_FOR_AIOCB]; /* Submit request list */ ret = lio_listio(LIO_NOWAIT, aiocbs, NUM_AIOCBS, &event); if (ret) { printf(TNAME " Error at lio_listio() %d: %s\n", errno, strerror(errno)); for (i=0; i #include #include #include #include #include #include "posixtest.h" #define TNAME "aio_suspend/6-1.c" #define NUM_AIOCBS 10 #define BUF_SIZE 1024*1024 #define WAIT_FOR_AIOCB 6 int received_selected = 0; int received_all = 0; void sigrt1_handler(int signum, siginfo_t *info, void *context) { if (info->si_value.sival_int == WAIT_FOR_AIOCB) received_selected = 1; } void sigrt2_handler(int signum, siginfo_t *info, void *context) { received_all = 1; } int main () { char tmpfname[256]; int fd; struct aiocb **aiocbs; struct aiocb *plist[2]; char *bufs; struct sigaction action; struct sigevent event; int errors = 0; int ret; int err; int i; #if _POSIX_ASYNCHRONOUS_IO != 200112L exit(PTS_UNSUPPORTED); #endif snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_aio_suspend_6_1_%d", getpid()); unlink(tmpfname); fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL, S_IRUSR | S_IWUSR); if (fd == -1) { printf(TNAME " Error at open(): %s\n", strerror(errno)); exit(PTS_UNRESOLVED); } unlink(tmpfname); bufs = (char *) malloc (NUM_AIOCBS*BUF_SIZE); if (bufs == NULL) { printf (TNAME " Error at malloc(): %s\n", strerror (errno)); close (fd); exit(PTS_UNRESOLVED); } if (write (fd, bufs, NUM_AIOCBS*BUF_SIZE) != (NUM_AIOCBS*BUF_SIZE)) { printf(TNAME " Error at write(): %s\n", strerror(errno)); free (bufs); close (fd); exit(PTS_UNRESOLVED); } aiocbs = (struct aiocb**)malloc(sizeof(struct aiocb *) * NUM_AIOCBS); /* Queue up a bunch of aio reads */ for (i = 0; i < NUM_AIOCBS; i++) { aiocbs[i] = (struct aiocb*)malloc(sizeof(struct aiocb)); memset(aiocbs[i], 0, sizeof(struct aiocb)); aiocbs[i]->aio_fildes = fd; aiocbs[i]->aio_offset = i * BUF_SIZE; aiocbs[i]->aio_buf = &bufs[i*BUF_SIZE]; aiocbs[i]->aio_nbytes = BUF_SIZE; aiocbs[i]->aio_lio_opcode = LIO_READ; /* Use SIRTMIN+1 for individual completions */ aiocbs[i]->aio_sigevent.sigev_notify = SIGEV_SIGNAL; aiocbs[i]->aio_sigevent.sigev_signo = SIGRTMIN+1; aiocbs[i]->aio_sigevent.sigev_value.sival_int = i; } /* Use SIGRTMIN+2 for list completion */ event.sigev_notify = SIGEV_SIGNAL; event.sigev_signo = SIGRTMIN+2; event.sigev_value.sival_ptr = NULL; /* Setup handler for individual operation completion */ action.sa_sigaction = sigrt1_handler; sigemptyset(&action.sa_mask); action.sa_flags = SA_SIGINFO|SA_RESTART; sigaction(SIGRTMIN+1, &action, NULL); /* Setup handler for list completion */ action.sa_sigaction = sigrt2_handler; sigemptyset(&action.sa_mask); action.sa_flags = SA_SIGINFO|SA_RESTART; sigaction(SIGRTMIN+2, &action, NULL); /* Setup suspend list */ plist[0] = NULL; plist[1] = aiocbs[WAIT_FOR_AIOCB]; /* Submit request list */ ret = lio_listio(LIO_NOWAIT, aiocbs, NUM_AIOCBS, &event); if (ret) { printf(TNAME " Error at lio_listio() %d: %s\n", errno, strerror(errno)); for (i=0; i #include #include #include #include #include #include "posixtest.h" #define TNAME "aio_suspend/7-1.c" #define NUM_AIOCBS 10 #define BUF_SIZE 1024*1024 #define WAIT_FOR_AIOCB 6 int received_selected = 0; int received_all = 0; void sigrt1_handler(int signum, siginfo_t *info, void *context) { if (info->si_value.sival_int == WAIT_FOR_AIOCB) received_selected = 1; } void sigrt2_handler(int signum, siginfo_t *info, void *context) { received_all = 1; } int main () { char tmpfname[256]; int fd; struct aiocb **aiocbs; struct aiocb *plist[2]; char *bufs; struct sigaction action; struct sigevent event; struct timespec ts = {0, 10000000}; /* 10 ms */ int errors = 0; int ret; int err; int i; #if _POSIX_ASYNCHRONOUS_IO != 200112L exit(PTS_UNSUPPORTED); #endif snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_aio_suspend_7_1_%d", getpid()); unlink(tmpfname); fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL, S_IRUSR | S_IWUSR); if (fd == -1) { printf(TNAME " Error at open(): %s\n", strerror(errno)); exit(PTS_UNRESOLVED); } unlink(tmpfname); bufs = (char *) malloc (NUM_AIOCBS*BUF_SIZE); if (bufs == NULL) { printf (TNAME " Error at malloc(): %s\n", strerror (errno)); close (fd); exit(PTS_UNRESOLVED); } if (write (fd, bufs, NUM_AIOCBS*BUF_SIZE) != (NUM_AIOCBS*BUF_SIZE)) { printf(TNAME " Error at write(): %s\n", strerror(errno)); free (bufs); close (fd); exit(PTS_UNRESOLVED); } aiocbs = (struct aiocb**)malloc(sizeof(struct aiocb *) * NUM_AIOCBS); /* Queue up a bunch of aio reads */ for (i = 0; i < NUM_AIOCBS; i++) { aiocbs[i] = (struct aiocb*)malloc(sizeof(struct aiocb)); memset(aiocbs[i], 0, sizeof(struct aiocb)); aiocbs[i]->aio_fildes = fd; aiocbs[i]->aio_offset = i * BUF_SIZE; aiocbs[i]->aio_buf = &bufs[i*BUF_SIZE]; aiocbs[i]->aio_nbytes = BUF_SIZE; aiocbs[i]->aio_lio_opcode = LIO_READ; /* Use SIRTMIN+1 for individual completions */ aiocbs[i]->aio_sigevent.sigev_notify = SIGEV_SIGNAL; aiocbs[i]->aio_sigevent.sigev_signo = SIGRTMIN+1; aiocbs[i]->aio_sigevent.sigev_value.sival_int = i; } /* Use SIGRTMIN+2 for list completion */ event.sigev_notify = SIGEV_SIGNAL; event.sigev_signo = SIGRTMIN+2; event.sigev_value.sival_ptr = NULL; /* Setup handler for individual operation completion */ action.sa_sigaction = sigrt1_handler; sigemptyset(&action.sa_mask); action.sa_flags = SA_SIGINFO|SA_RESTART; sigaction(SIGRTMIN+1, &action, NULL); /* Setup handler for list completion */ action.sa_sigaction = sigrt2_handler; sigemptyset(&action.sa_mask); action.sa_flags = SA_SIGINFO|SA_RESTART; sigaction(SIGRTMIN+2, &action, NULL); /* Setup suspend list */ plist[0] = NULL; plist[1] = aiocbs[WAIT_FOR_AIOCB]; /* Submit request list */ ret = lio_listio(LIO_NOWAIT, aiocbs, NUM_AIOCBS, &event); if (ret) { printf(TNAME " Error at lio_listio() %d: %s\n", errno, strerror(errno)); for (i=0; i The aio_suspend() function shall suspend the calling thread until at least one of the asynchronous I/O operations referenced by the list argument has completed, until a signal interrupts the function, or, if timeout is not NULL, until the time interval specified by timeout has passed. If any of the aiocb structures in the list correspond to a completed AIO, the aio_suspend() shall return without suspending. The list array may contain NULL pointers which are ignored. On a timeout exit, aio_suspend shall return with an error. If the monotonic clock option is supported, the clock that shall be used to measure this time interval shall be CLOCK_MONOTONIC clock. aio_supend() shall return zero after one or more AIO operations have completed. aio_suspend() shall return the value -1 and set errno to indicate error if it returns before at least one AIO operation have completed. The application may determine which AIO completed by scanning operations using aio_error() and aio_return(). aio_suspend() shall fail if: [EAGAIN] No AIO indicated in the list completed before timeout aio_suspend() shall fail if: [EINTR] A signal interrupted aio_suspend(). posixtestsuite/conformance/interfaces/aio_suspend/coverage.txt0100644000000000000000000000023710245504306024154 0ustar rootrootthis file defines the coverage for the aio_suspend() function testing. Assertion Covered? 1 YES 2 NO 3 YES 4 YES 5 NO 6 YES 7 YES 8 YES 9 YES 10 NO posixtestsuite/conformance/interfaces/aio_suspend/8-1.c0100644000000000000000000001255110247562115022277 0ustar rootroot/* * Copyright (c) 2004, Bull SA. All rights reserved. * Created by: Laurent.Vivier@bull.net * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * assertion: * * The aio_suspend() function shall suspend the calling thread until at * least one of the asynchronous I/O operations referenced by the list * argument has completed, until a signal interrupts the function, or, * if timeout is not NULL, until the time interval specified by timeout * has passed. * * method: Testing for a NULL timeout * * - write to a file * - submit a list of read requests * - check that the selected request has not completed * - suspend on selected request * - check that the selected request has completed using aio_error and * aio_return * */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include "posixtest.h" #define TNAME "aio_suspend/8-1.c" #define NUM_AIOCBS 10 #define BUF_SIZE 1024*1024 #define WAIT_FOR_AIOCB 6 int received_selected = 0; int received_all = 0; void sigrt1_handler(int signum, siginfo_t *info, void *context) { if (info->si_value.sival_int == WAIT_FOR_AIOCB) received_selected = 1; } void sigrt2_handler(int signum, siginfo_t *info, void *context) { received_all = 1; } int main () { char tmpfname[256]; int fd; struct aiocb **aiocbs; struct aiocb *plist[2]; char *bufs; struct sigaction action; struct sigevent event; int errors = 0; int ret; int err; int i; #if _POSIX_ASYNCHRONOUS_IO != 200112L exit(PTS_UNSUPPORTED); #endif snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_aio_suspend_8_1_%d", getpid()); unlink(tmpfname); fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL, S_IRUSR | S_IWUSR); if (fd == -1) { printf(TNAME " Error at open(): %s\n", strerror(errno)); exit(PTS_UNRESOLVED); } unlink(tmpfname); bufs = (char *) malloc (NUM_AIOCBS*BUF_SIZE); if (bufs == NULL) { printf (TNAME " Error at malloc(): %s\n", strerror (errno)); close (fd); exit(PTS_UNRESOLVED); } if (write (fd, bufs, NUM_AIOCBS*BUF_SIZE) != (NUM_AIOCBS*BUF_SIZE)) { printf(TNAME " Error at write(): %s\n", strerror(errno)); free (bufs); close (fd); exit(PTS_UNRESOLVED); } aiocbs = (struct aiocb**)malloc(sizeof(struct aiocb *) * NUM_AIOCBS); /* Queue up a bunch of aio reads */ for (i = 0; i < NUM_AIOCBS; i++) { aiocbs[i] = (struct aiocb*)malloc(sizeof(struct aiocb)); memset(aiocbs[i], 0, sizeof(struct aiocb)); aiocbs[i]->aio_fildes = fd; aiocbs[i]->aio_offset = i * BUF_SIZE; aiocbs[i]->aio_buf = &bufs[i*BUF_SIZE]; aiocbs[i]->aio_nbytes = BUF_SIZE; aiocbs[i]->aio_lio_opcode = LIO_READ; /* Use SIRTMIN+1 for individual completions */ aiocbs[i]->aio_sigevent.sigev_notify = SIGEV_SIGNAL; aiocbs[i]->aio_sigevent.sigev_signo = SIGRTMIN+1; aiocbs[i]->aio_sigevent.sigev_value.sival_int = i; } /* Use SIGRTMIN+2 for list completion */ event.sigev_notify = SIGEV_SIGNAL; event.sigev_signo = SIGRTMIN+2; event.sigev_value.sival_ptr = NULL; /* Setup handler for individual operation completion */ action.sa_sigaction = sigrt1_handler; sigemptyset(&action.sa_mask); action.sa_flags = SA_SIGINFO|SA_RESTART; sigaction(SIGRTMIN+1, &action, NULL); /* Setup handler for list completion */ action.sa_sigaction = sigrt2_handler; sigemptyset(&action.sa_mask); action.sa_flags = SA_SIGINFO|SA_RESTART; sigaction(SIGRTMIN+2, &action, NULL); /* Setup suspend list */ plist[0] = NULL; plist[1] = aiocbs[WAIT_FOR_AIOCB]; /* Submit request list */ ret = lio_listio(LIO_NOWAIT, aiocbs, NUM_AIOCBS, &event); if (ret) { printf(TNAME " Error at lio_listio() %d: %s\n", errno, strerror(errno)); for (i=0; i #include #include #include "posixtest.h" int main() { #if _POSIX_ASYNCHRONOUS_IO != 200112L exit(PTS_UNSUPPORTED); #endif return PTS_UNTESTED; } posixtestsuite/conformance/interfaces/aio_suspend/3-1.c0100644000000000000000000000370310247562115022271 0ustar rootroot/* * Copyright (c) 2004, Bull SA. All rights reserved. * Created by: Laurent.Vivier@bull.net * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * assertion: * * The list array may contain NULL pointers which are ignored. * * method: * * - submit a bunch of aio_write * - prepare suspend list with NULL pointers * - call aio_suspend with this list * */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include #include #include #include "posixtest.h" #define TNAME "aio_suspend/2-1.c" #define NENT 8 #define NAIOCB 3 int main() { char tmpfname[256]; #define BUF_SIZE 1024 char buf[BUF_SIZE]; int fd; struct aiocb aiocb[NAIOCB]; const struct aiocb *list[NENT]; int i; #if _POSIX_ASYNCHRONOUS_IO != 200112L exit(PTS_UNSUPPORTED); #endif snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_aio_suspend_2_1_%d", getpid()); unlink(tmpfname); fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL, S_IRUSR | S_IWUSR); if (fd == -1) { printf(TNAME " Error at open(): %s\n", strerror(errno)); exit(PTS_UNRESOLVED); } unlink(tmpfname); for (i = 0; i < NAIOCB; i++) { memset(&aiocb[i], 0, sizeof(struct aiocb)); aiocb[i].aio_fildes = fd; aiocb[i].aio_buf = buf; aiocb[i].aio_offset = i * BUF_SIZE; aiocb[i].aio_nbytes = BUF_SIZE; if (aio_write(&aiocb[i]) == -1) { printf(TNAME " Error at aio_write(): %s\n", strerror(errno)); exit(PTS_FAIL); } } list[0] = NULL; list[2] = &aiocb[0]; list[3] = NULL; list[4] = NULL; list[5] = &aiocb[1]; list[6] = &aiocb[2]; list[7] = NULL; if (aio_suspend(list, NENT, NULL) != 0) { printf(TNAME " Error at aio_suspend(): %s\n", strerror(errno)); exit(PTS_FAIL); } close(fd); printf ("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_rwlock_destroy/0040755000000000000000000000000010515625223024073 5ustar rootrootposixtestsuite/conformance/interfaces/pthread_rwlock_destroy/1-1.c0100644000000000000000000000213107670220431024527 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * * The function shall destroy the read-write lock object referenced by rwlock * and release any resources used by the lock. * * Note: This case does not test the resources used by the lock has been released. *Steps: * Loop for COUNT times: * 1. Initialize a read-write lock * 2. Destroy it. Should get not error. */ #define _XOPEN_SOURCE 600 #include #include #include "posixtest.h" #define COUNT 1000 int main() { pthread_rwlock_t rwlock; int cnt = 0; int rc = 0; while(cnt++ < COUNT) { if(pthread_rwlock_init(&rwlock, NULL) != 0) { printf("Error at pthread_rwlock_init()\n"); return PTS_UNRESOLVED; } rc = pthread_rwlock_destroy(&rwlock); if(rc != 0) { printf("Test FAILED: at %d-th pthread_rwlock_destroy(), with Error code=%d\n", cnt, rc); return PTS_FAIL; } } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_rwlock_destroy/assertions.xml0100644000000000000000000000141607670220431027006 0ustar rootroot pthread_rwlock_destroy( ) function shall destroy the read-write lock object referenced by rwlock and release any resources used by the lock. If successful, the pthread_rwlock_destroy( ) return zero; otherwise, an error number shall be returned to indicate the error. If not successful, pthread_rwlock_destroy( ) function may fail if: [EBUSY] The implementation has detected an attempt to destroy the object referenced by rwlock while it is locked. [EINVAL] The value specified by rwlock is invalid. Shall not return an error code of [EINTR] posixtestsuite/conformance/interfaces/pthread_rwlock_destroy/coverage.txt0100644000000000000000000000023407670220431026423 0ustar rootrootThis document defines the coverage for the pthread_rwlock_destroy function: Assertion Tested? 1 YES 2 YES 3 YES ** Tested EBUSY, but not EINVAL, NOTE: posixtestsuite/conformance/interfaces/pthread_rwlock_destroy/2-1.sh0100644000000000000000000000061507733710271024733 0ustar rootroot#!/bin/sh # Copyright (c) 2002, Intel Corporation. All rights reserved. # This file is licensed under the GPL license. For the full content # of this license, see the COPYING file at the top level of this # source tree. # Test pthread_rwlock_destroy returns 0 on success. # This is tested implicitly via assertion 1. echo "Tested implicitly via assertion 1. See output for status" exit 0 posixtestsuite/conformance/interfaces/pthread_rwlock_destroy/3-1.c0100644000000000000000000000256307710100411024530 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * * * pthread_rwlock_destroy( ) function may fail if: * [EBUSY] The implementation has detected an attempt to destroy the object referenced * by rwlock while it is locked. * *Steps: * 1. Initialize a read-write lock. * 2. Lock it. * 3. Attempt to destroy it while it is still locked. */ #define _XOPEN_SOURCE 600 #include #include #include #include "posixtest.h" int main() { pthread_rwlock_t rwlock; int rc; if(pthread_rwlock_init(&rwlock, NULL) != 0) { printf("Error at pthread_rwlock_init()\n"); return PTS_UNRESOLVED; } if(pthread_rwlock_rdlock(&rwlock) != 0) { printf("Error at pthread_rwlock_rdlock()\n"); return PTS_UNRESOLVED; } /* Attempt to destroy an already locked rwlock */ rc = pthread_rwlock_destroy(&rwlock); if(rc == EBUSY) { printf("Test PASSED\n"); return PTS_PASS; } else if (rc == 0) { printf("Test PASSED: Note*: pthread_rwlock_destroy() returned 0 instead of EBUSY, but standard specifies _may_ fail\n"); return PTS_PASS; } else { printf("Test FAILED: Error at pthread_rwlock_destroy(), should return 0 or EBUSY, but returns %d\n", rc); return PTS_FAIL; } } posixtestsuite/conformance/interfaces/pthread_barrierattr_init/0040755000000000000000000000000010515625201024361 5ustar rootrootposixtestsuite/conformance/interfaces/pthread_barrierattr_init/3-1.sh0100755000000000000000000000073707705045337025241 0ustar rootroot#!/bin/sh # Copyright (c) 2002, Intel Corporation. All rights reserved. # This file is licensed under the GPL license. For the full content # of this license, see the COPYING file at the top level of this # source tree. # Upon successful completion, this function shall return zero; # otherwise, an error number shall be returned to indicate the error. # This is tested implicitly via assertion 1. echo "Tested implicitly via assertion 1. See output for status" exit 0 posixtestsuite/conformance/interfaces/pthread_barrierattr_init/1-1.c0100644000000000000000000000303307705045337025034 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * * pthread_barrierattr_init() * * The pthread_barrierattr_init( ) function shall initialize a barrier attributes * object attr with the default value for all of the attributes defined * by the implementation. * */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include #include "posixtest.h" int main() { int rc; pthread_barrierattr_t ba; int pshared; /* Initialize the barrier attribute object */ rc = pthread_barrierattr_init(&ba); if(rc != 0) { printf("Test FAILED: Error while initialize attribute object\n"); return PTS_FAIL; } /* Get the pshared value of the initialized barrierattr object */ if(pthread_barrierattr_getpshared(&ba, &pshared) != 0) { printf("Error at pthread_barrierattr_getpshared()\n"); return PTS_UNRESOLVED; } /* The default should be PTHREAD_PROCESS_PRIVATE */ if(pshared != PTHREAD_PROCESS_PRIVATE) { printf("Test FAILED: The process shared attribute was not set to " "default value\n"); return PTS_FAIL; } /* Cleanup */ rc = pthread_barrierattr_destroy(&ba); if(rc != 0) { printf("Error at pthread_barrierattr_destroy() " "return code: %d, %s", rc, strerror(rc)); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_barrierattr_init/assertions.xml0100644000000000000000000000164007705045337027310 0ustar rootroot The pthread_barrierattr_init( ) function shall initialize a barrier attributes object attr with the default value for all of the attributes defined by the implementation. After a barrier attributes object has been used to initialize one or more barriers, any function affecting the attributes object (including destruction) shall not affect any previously initialized barrier. If successful, it shall return zero; otherwise, an error number shall be returned to indicate the error. The pthread_barrierattr_init( ) function shall fail if: [ENOMEM] Insufficient memory exists to initialize the barrier attributes object. This function shall not return an error code of [EINTR]. posixtestsuite/conformance/interfaces/pthread_barrierattr_init/coverage.txt0100644000000000000000000000020007705045337026717 0ustar rootrootThis document defines the coverage for the pthread_barrierattr_init() function: Assertion Tested? 1 YES 2 YES 3 YES NOTE: posixtestsuite/conformance/interfaces/pthread_barrierattr_init/2-1.c0100644000000000000000000000405407705045337025041 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * * pthread_barrierattr_init() * * After a barrier attributes object has been used to initialize one or more barriers * any function affecting the attributes object (including destruction) shall not * affect any previously initialized barrier. * */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include #include "posixtest.h" #define BARRIER_NUM 100 int main() { int rc; pthread_barrierattr_t ba; pthread_barrier_t barriers [BARRIER_NUM]; int cnt; /* Initialize the barrier attribute object */ rc = pthread_barrierattr_init(&ba); if(rc != 0) { printf("Test FAILED: Error while initialize attribute object\n"); return PTS_FAIL; } /* Initialize BARRIER_NUM barrier objects, with count==1 */ for(cnt = 0; cnt < BARRIER_NUM; cnt++) { if(pthread_barrier_init(&barriers[cnt], &ba, 1) != 0) { printf("Error at %dth initialization\n", cnt); return PTS_UNRESOLVED; } } /* Destroy barrier attribute object */ rc = pthread_barrierattr_destroy(&ba); if(rc != 0) { printf("Error at pthread_barrierattr_destroy() " "return code: %d, %s", rc, strerror(rc)); return PTS_UNRESOLVED; } /* Check that pthread_barrier_wait can still be performed, even after the attributes * object has been destroyed */ for(cnt = 0; cnt < BARRIER_NUM; cnt++) { rc = pthread_barrier_wait(&barriers[cnt]); if(rc != 0 && rc != PTHREAD_BARRIER_SERIAL_THREAD) { printf("Test Fail: Error at %dth wait, %s\n", cnt, strerror(rc)); return PTS_FAIL; } } /* Cleanup */ for(cnt = 0; cnt < BARRIER_NUM; cnt++) { rc = pthread_barrier_destroy(&barriers[cnt]); if(rc != 0) { printf("Error at %dth destruction, %s\n", cnt, strerror(rc)); return PTS_UNRESOLVED; } } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/shm_open/0040755000000000000000000000000010515625240021121 5ustar rootrootposixtestsuite/conformance/interfaces/shm_open/35-1.sh0100755000000000000000000000037307660126752022060 0ustar rootroot#! /bin/sh # # Test that the shm_open() function sets errno = EEXIST if O_CREAT and O_EXCL # are set and the named shared memory object already exists. # # This is tested implicitly via assertion 22. echo "Tested implicitly via assertion 22." exit 0 posixtestsuite/conformance/interfaces/shm_open/37-1.c0100644000000000000000000000334710021041452021645 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that the shm_open() function sets errno = EINVAL if the shm_open() * operation is not supported for the given name. * * The supported names are implementation-defined, so the test is done for * several differents names. The test pass for a given name if shm_open make no * error or set errno to EINVAL. */ #include #include #include #include #include #include "posixtest.h" char *shm_name[] = { /* char which are in portable character set but not in portable filename character set */ "$#\n@\t\a,~}", /* char which are not in portable character set (accentuated char and c cedilla) */ "éêîôçà", /* some file or directory which should exist */ "..", "/", "//", "/abc", NULL}; int main() { int fd, i=0, result = PTS_PASS; while(shm_name[i]) { fflush(stderr); printf("Name: '%s'\n", shm_name[i]); fflush(stdout); fd = shm_open(shm_name[i], O_RDWR | O_CREAT, 0); if(fd == -1 && errno == EINVAL) { printf(" OK: errno == EINVAL\n"); } else if(fd != -1) { printf(" OK: open with success.\n"); } else { perror(" Unexpected error"); result = PTS_FAIL; } shm_unlink(shm_name[i]); i++; } if(result == PTS_PASS) printf("Test PASSED\n"); else printf("Test FAILED\n"); return result; } posixtestsuite/conformance/interfaces/shm_open/26-2.c0100644000000000000000000000626307700512247021663 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that the owner is unchanged when O_TRUNC is set, the shared memory * object exists and it is successfully opened O_RDWR. * * In most case this test will be unresolved if not run by root. * Steps: * 1. Create a shared memory object. * 2. Set a non zero size for this object (to force the modification of the * object when it will be reopen with O_TRUNC set). * 3. Set his effective user id to an other user id which is not root. * 4. Call shm_open with O_TRUNC set. * 5. Check that the owner is unchanged. */ /* getpwent() is part of XSI option */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include #include #include "posixtest.h" #define BUF_SIZE 8 #define SHM_NAME "posixtest_26-2" int main(){ int fd; struct stat stat_buf; struct passwd *pw; uid_t old_uid; gid_t old_gid; umask(0); fd = shm_open(SHM_NAME, O_RDWR|O_CREAT, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH); if(fd == -1) { perror("An error occurs when calling shm_open()"); return PTS_UNRESOLVED; } if(ftruncate(fd, BUF_SIZE) != 0) { perror("An error occurs when calling ftruncate()"); shm_unlink(SHM_NAME); return PTS_UNRESOLVED; } if(fstat(fd, &stat_buf) != 0) { perror("An error occurs when calling fstat()"); shm_unlink(SHM_NAME); return PTS_UNRESOLVED; } old_uid = stat_buf.st_uid; old_gid = stat_buf.st_gid; /* search for the first user which is non root and which is not the current user */ while((pw = getpwent()) != NULL) if(strcmp(pw->pw_name, "root") && pw->pw_uid != getuid()) break; if(pw == NULL) { printf("There is no other user than current and root.\n"); shm_unlink(SHM_NAME); return PTS_UNRESOLVED; } if(seteuid(pw->pw_uid) != 0) { if(errno == EPERM) { printf("You don't have permission to change your UID.\nTry to rerun this test as root.\n"); } else { perror("An error occurs when calling seteuid()"); } shm_unlink(SHM_NAME); return PTS_UNRESOLVED; } printf("Testing with user '%s' (uid: %i)\n", pw->pw_name, pw->pw_uid); fd = shm_open(SHM_NAME, O_RDWR|O_TRUNC, 0); if(fd == -1) { perror("An error occurs when calling shm_open()"); seteuid(getuid()); shm_unlink(SHM_NAME); return PTS_UNRESOLVED; } if(fstat(fd, &stat_buf) != 0) { perror("An error occurs when calling fstat()"); seteuid(getuid()); shm_unlink(SHM_NAME); return PTS_UNRESOLVED; } seteuid(getuid()); shm_unlink(SHM_NAME); if(stat_buf.st_uid == old_uid && stat_buf.st_gid == old_gid) { printf("Test PASSED\n"); return PTS_PASS; } if(stat_buf.st_uid != old_uid) printf("The user ID has changed.\n"); if(stat_buf.st_gid != old_gid) printf("The group ID has changed.\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/shm_open/15-1.c0100644000000000000000000000325207660126751021661 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that the shared memory object is created if the shared memory object * does not exists and the O_CREAT flags is set. * * Steps: * 1. Ensure that the shared memory object does not exists using shm_unlink. * 2. Call shm_open() with O_CREAT flags set. * 3. Check that the shared memory object exists now using fstat. */ #include #include #include #include #include #include #include "posixtest.h" #define SHM_NAME "posixtest_15-1" int main(){ int fd, result; struct stat stat_buf; result = shm_unlink(SHM_NAME); if(result != 0 && errno != ENOENT) { /* The shared memory object exist and shm_unlink can not remove it. */ perror("An error occurs when calling shm_unlink()"); return PTS_UNRESOLVED; } fd = shm_open(SHM_NAME, O_RDONLY|O_CREAT, S_IRUSR|S_IWUSR); if(fd == -1) { perror("An error occurs when calling shm_open()"); return PTS_UNRESOLVED; } result = fstat(fd, &stat_buf); if(result == 0) { printf("Test PASSED\n"); shm_unlink(SHM_NAME); return PTS_PASS; } else if(result == -1 && errno == EBADF) { printf("The shared memory object was no created.\n"); shm_unlink(SHM_NAME); return PTS_FAIL; } perror("fstat"); shm_unlink(SHM_NAME); return PTS_FAIL; } posixtestsuite/conformance/interfaces/shm_open/17-1.c0100644000000000000000000000315007660126751021660 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that the goup ID of the shared memory object is set to the effective * group ID of the process when the shared memory object does not exists and * the O_CREAT flags is set. * * The test use fstat to check the flag. */ #include #include #include #include #include #include #include "posixtest.h" #define SHM_NAME "posixtest_17-1" int main(){ int fd, result; struct stat stat_buf; result = shm_unlink(SHM_NAME); if(result != 0 && errno != ENOENT) { /* The shared memory object exist and shm_unlink can not remove it. */ perror("An error occurs when calling shm_unlink()"); return PTS_UNRESOLVED; } fd = shm_open(SHM_NAME, O_RDONLY|O_CREAT, S_IRUSR|S_IWUSR); if(fd == -1) { perror("An error occurs when calling shm_open()"); return PTS_UNRESOLVED; } result = fstat(fd, &stat_buf); if(result != 0) { perror("An error occurs when calling fstat()"); shm_unlink(SHM_NAME); return PTS_UNRESOLVED; } shm_unlink(SHM_NAME); if(stat_buf.st_gid == getegid()){ printf("Test PASSED\n"); return PTS_PASS; } printf("shm_open() does not set the user ID to the effective user ID of the process.\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/shm_open/19-1.c0100644000000000000000000000163707660450567021677 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Will not test the effect of calling shm_open() when the shared memory object * does not exists, the O_CREAT flags is set, and bits in mode other than the * file permission bits are set. It is unspecified. */ #include #include "posixtest.h" int main() { printf("Will not test the effect of calling shm_open() when the shared memory object\ndoes not exists, the O_CREAT flags is set, and bits in mode other than the\nfile permission bits are set. It is unspecified.\n"); return PTS_UNTESTED; } posixtestsuite/conformance/interfaces/shm_open/20-2.c0100644000000000000000000000335707660126751021664 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that shm_open open the shared memory object for writing when calling * shm_open with O_RDWR even if the mode don't set write permission. * * The test use ftruncate to check the object is open for writing. */ /* ftruncate was formerly an XOPEN extension. We define _XOPEN_SOURCE here to avoid warning if the implementation does not program ftruncate as a base interface */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include "posixtest.h" #define BUF_SIZE 8 #define SHM_NAME "posixtest_20-2" int main() { int fd, result; result = shm_unlink(SHM_NAME); if(result != 0 && errno != ENOENT) { /* The shared memory object exist and shm_unlink can not remove it. */ perror("An error occurs when calling shm_unlink()"); return PTS_UNRESOLVED; } fd = shm_open(SHM_NAME, O_RDWR|O_CREAT, 0); if(fd == -1) { perror("An error occurs when calling shm_open()"); return PTS_UNRESOLVED; } result = ftruncate(fd, BUF_SIZE); if(result == 0){ printf("Test PASSED\n"); shm_unlink(SHM_NAME); return PTS_PASS; } else if(result == -1 && errno == EINVAL) { printf("The shared memory object is not opened for writing.\n"); shm_unlink(SHM_NAME); return PTS_FAIL; } perror("ftruncate"); shm_unlink(SHM_NAME); return PTS_FAIL; } posixtestsuite/conformance/interfaces/shm_open/5-1.c0100644000000000000000000000532210015266040021560 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that when name begins with the slash character, then processes calling * shm_open() with the same value of name refer to the same shared memory * object, as long as that name has not been removed. * * Steps: * 1. Create a child process. * (The child process) * 2. Open a shared memory file O_RDWR with a name beginning with slash. * 3. Write a string in the file. * (The father) * 2. Open a shared memory file O_RDONLY with the same name. * 3. Read into the file. * 4. Check that it obtain the right string. */ /* ftruncate was formerly an XOPEN extension. We define _XOPEN_SOURCE here to avoid warning if the implementation does not program ftruncate as a base interface */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include #include #include #include #include "posixtest.h" #define BUF_SIZE 8 #define SHM_NAME "/posixtest_5-1" char str[BUF_SIZE] = "qwerty"; int child_process() { int fd; char *buf; fd = shm_open(SHM_NAME, O_RDWR|O_CREAT, S_IRUSR|S_IWUSR); if(fd == -1) { perror("An error occurs when calling shm_open()"); kill(getppid(), SIGUSR1); return PTS_UNRESOLVED; } if(ftruncate(fd, BUF_SIZE) != 0) { perror("An error occurs when calling ftruncate()"); kill(getppid(), SIGUSR1); return PTS_UNRESOLVED; } buf = mmap(NULL, BUF_SIZE, PROT_WRITE, MAP_SHARED, fd, 0); if( buf == MAP_FAILED) { perror("An error occurs when calling mmap()"); kill(getppid(), SIGUSR1); return PTS_UNRESOLVED; } strcpy(buf, str); return PTS_PASS; } int main() { int fd, child_pid; char *buf; child_pid = fork(); if(child_pid == -1) { perror("An error occurs when calling fork()"); return PTS_UNRESOLVED; } else if(child_pid == 0) { return child_process(); } wait(NULL); fd = shm_open(SHM_NAME, O_RDONLY, S_IRUSR|S_IWUSR); if(fd == -1) { perror("An error occurs when calling shm_open()"); return PTS_UNRESOLVED; } buf = mmap(NULL, BUF_SIZE, PROT_READ, MAP_SHARED, fd, 0); if( buf == MAP_FAILED) { perror("An error occurs when calling mmap()"); return PTS_UNRESOLVED; } shm_unlink(SHM_NAME); if(strcmp(buf, str) == 0) { printf("Test PASSED\n"); return PTS_PASS; } printf("Test FAILED\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/shm_open/34-1.c0100644000000000000000000000420010033204325021632 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that the shm_open() function sets errno = EACCES if O_TRUNC is * specified and write permission is denied */ /* FIXME : ambiguite de la spec */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include #include #include #include "posixtest.h" #define SHM_NAME "posixtest_34-1" /** Set the euid of this process to a non-root uid */ int set_nonroot() { struct passwd *pw; setpwent(); /* search for the first user which is non root */ while((pw = getpwent()) != NULL) if(strcmp(pw->pw_name, "root")) break; endpwent(); if(pw == NULL) { printf("There is no other user than current and root.\n"); return 1; } if(seteuid(pw->pw_uid) != 0) { if(errno == EPERM) { printf("You don't have permission to change your UID.\n"); return 1; } perror("An error occurs when calling seteuid()"); return 1; } printf("Testing with user '%s' (uid: %d)\n", pw->pw_name, (int)geteuid()); return 0; } int main() { int fd; /* This test should be run under standard user permissions */ if (getuid() == 0) { if (set_nonroot() != 0) { printf("Cannot run this test as non-root user\n"); return PTS_UNTESTED; } } fd = shm_open(SHM_NAME, O_RDWR|O_CREAT, S_IRUSR); if(fd == -1) { perror("An error occurs when calling shm_open()"); return PTS_UNRESOLVED; } fd = shm_open(SHM_NAME, O_RDWR | O_TRUNC, 0); if(fd == -1 && errno == EACCES) { printf("Test PASSED\n"); shm_unlink(SHM_NAME); return PTS_PASS; } else if(fd != -1) { printf("shm_open success.\n"); shm_unlink(SHM_NAME); return PTS_FAIL; } perror("shm_open"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/shm_open/28-2.c0100644000000000000000000000457007660126752021673 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that the state of the shared memory object, including all data * associated with the shared memory object, persists until all mapping * references are gone even if the shared memory object is unlinked and there * is no open reference anymore. * * Steps: * 1. Create a shared memory object, map it and write a string in it. * 2. Close the file descriptor and unlink the object. * 3. Check that the previously written string is always in the mapped memory. */ /* ftruncate was formerly an XOPEN extension. We define _XOPEN_SOURCE here to avoid warning if the implementation does not program ftruncate as a base interface */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include #include "posixtest.h" #define BUF_SIZE 8 #define SHM_NAME "posixtest_28-2" int main() { int fd; char str[BUF_SIZE] = "qwerty"; char *buf; fd = shm_open(SHM_NAME, O_RDWR|O_CREAT, S_IRUSR|S_IWUSR); if(fd == -1) { perror("An error occurs when calling shm_open()"); return PTS_UNRESOLVED; } if(ftruncate(fd, BUF_SIZE) != 0) { perror("An error occurs when calling ftruncate()"); shm_unlink(SHM_NAME); return PTS_UNRESOLVED; } buf = mmap(NULL, BUF_SIZE, PROT_WRITE|PROT_READ, MAP_SHARED, fd, 0); if( buf == MAP_FAILED) { perror("An error occurs when calling mmap()"); shm_unlink(SHM_NAME); return PTS_UNRESOLVED; } strcpy(buf, str); if(close(fd) != 0) { perror("An error occurs when calling close()"); shm_unlink(SHM_NAME); return PTS_UNRESOLVED; } if(shm_unlink(SHM_NAME) !=0) { perror("An error occurs when calling shm_unlink()"); return PTS_UNRESOLVED; } /* Now, SHM_NAME is unlinked and there are no more open references on it but a mapping reference remain */ if(strcmp(buf, str) == 0) { printf("Test PASSED\n"); return PTS_PASS; } printf("The content of the shared memory object was removed.\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/shm_open/14-1.sh0100755000000000000000000000032007660126751022044 0ustar rootroot#! /bin/sh # # Test that the file is open for write acces when the applications specify # the value of O_RDWR. # # This is tested implicitly via assertion 1. echo "Tested implicitly via assertion 1." exit 0 posixtestsuite/conformance/interfaces/shm_open/24-1.c0100644000000000000000000000133507660450567021666 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Will not test the result of shm_open() when O_EXCL is set and O_CREAT is not * set because it is undefined. */ #include #include "posixtest.h" int main() { printf("Will not test the result of shm_open() when O_EXCL is set and O_CREAT is not\nset because it is undefined.\n"); return PTS_UNTESTED; } posixtestsuite/conformance/interfaces/shm_open/22-1.c0100644000000000000000000000234107660126751021655 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that shm_open() fails if the shared memory object exist and O_EXCL and * O_CREAT are set. */ #include #include #include #include #include #include #include "posixtest.h" #define SHM_NAME "posixtest_22-1" int main(){ int fd; /* Create the shared memory object */ fd = shm_open(SHM_NAME, O_RDONLY|O_CREAT, S_IRUSR|S_IWUSR); if(fd == -1) { perror("An error occurs when calling shm_open()"); return PTS_UNRESOLVED; } fd = shm_open(SHM_NAME, O_RDONLY|O_CREAT|O_EXCL, S_IRUSR|S_IWUSR); if(fd == -1 && errno == EEXIST) { printf("Test PASSED\n"); shm_unlink(SHM_NAME); return PTS_PASS; } else if(fd != -1) { printf("Test FAILED\n"); shm_unlink(SHM_NAME); return PTS_FAIL; } perror("shm_open"); shm_unlink(SHM_NAME); return PTS_FAIL; } posixtestsuite/conformance/interfaces/shm_open/18-1.c0100644000000000000000000000500007660126751021655 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that the permission bits of the shared memory object are set to the * value of the mode argument except those set in the file mode creation mask * of the process when the shared memory object does not exists and the O_CREAT * flags is set. * * Steps: * 1. Set umask to UMASK_FLAGS. * 2. Ensure that the shared memory object does not exist. * 3. Call shm_open with mode MOD_FLAGS. * 4. Get the stat of the opened file. * 5. Check that the permissions flags are right. */ #include #include #include #include #include #include #include "posixtest.h" #define SHM_NAME "posixtest_18-1" /* execution bits is undefined */ #define MOD_FLAGS (S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH) /* -w?rw?r-? */ #define UMASK_FLAGS (S_IRGRP | S_IWOTH) /* --?r-?-w? */ #define ALL_MOD_FLAGS (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | \ S_IROTH | S_IWOTH) /* rw?rw?rw? */ int main(){ int fd, result; struct stat stat_buf; umask(UMASK_FLAGS); result = shm_unlink(SHM_NAME); if(result != 0 && errno != ENOENT) { /* The shared memory object exist and shm_unlink can not remove it. */ perror("An error occurs when calling shm_unlink()"); return PTS_UNRESOLVED; } fd = shm_open(SHM_NAME, O_RDONLY|O_CREAT, MOD_FLAGS); if(fd == -1) { perror("An error occurs when calling shm_open()"); return PTS_UNRESOLVED; } result = fstat(fd, &stat_buf); if(result != 0) { perror("An error occurs when calling fstat()"); shm_unlink(SHM_NAME); return PTS_UNRESOLVED; } shm_unlink(SHM_NAME); /* Check the permissions flags. * Permissions flags are right when the permissions bits of * stat_buf.st_mode are set if and only if the same bits of MOD_FLAGS * are set and thoses of UMASK_FLAGS are not, i.e.: * ALL_MOD_FLAGS & (stat_buf.st_mode ^ (MOD_FLAGS & ~UMASK_FLAGS)) == 0 */ if( !(ALL_MOD_FLAGS & (stat_buf.st_mode ^ (MOD_FLAGS & ~UMASK_FLAGS))) ) { printf("Test PASSED\n"); return PTS_PASS; } printf("shm_open() does not set the rights permissions.\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/shm_open/42-1.c0100644000000000000000000000144107700305471021650 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that the shm_open() function sets errno = ENOSPC if there is * insufficient space for the creation of the new shared memory object. */ #include #include "posixtest.h" int main() { printf("Will not test that the shm_open() function sets errno to ENOSPC if there is\ninsufficient space for the creation of the new shared memory object.\n"); return PTS_UNTESTED; } posixtestsuite/conformance/interfaces/shm_open/12-1.c0100644000000000000000000000173007660450567021662 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Will not test the behavior of implementation when an application does not * specify exactly one of the first two values (access modes) below in the * value of oflag: * O_RDONLY * O_RDWR * * Often O_RDONLY == 0 and O_RDWR == 2^n, so when both values are specified, * the result is the same than when only O_RDWR is set. */ #include #include "posixtest.h" int main() { printf("Will not test the behavior of implementation when an application does not\nspecify exactly one of two values: O_RDONLY and O_RDWR.\n"); return PTS_UNTESTED; } posixtestsuite/conformance/interfaces/shm_open/1-1.c0100644000000000000000000000437107660126751021577 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that the shm_open() function establish a connection between a shared * memory object and a file descriptor. * * Step: * 1. Create a file a shared memory object using shm_open(). * 2. Write in the file referenced by the file descriptor return by * shm_open(). * 3. Reopen the file with shm_open(). * 4. Read in the file. * The test pass if it read what it was previously written. */ /* ftruncate was formerly an XOPEN extension. We define _XOPEN_SOURCE here to avoid warning if the implementation does not program ftruncate as a base interface */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include "posixtest.h" #define BUF_SIZE 8 #define SHM_NAME "posixtest_1-1" int main() { int fd; char str[BUF_SIZE] = "qwerty"; char *buf; fd = shm_open(SHM_NAME, O_RDWR|O_CREAT, S_IRUSR|S_IWUSR); if(fd == -1) { perror("An error occurs when calling shm_open()"); return PTS_UNRESOLVED; } if(ftruncate(fd, BUF_SIZE) != 0) { perror("An error occurs when calling ftruncate()"); shm_unlink(SHM_NAME); return PTS_UNRESOLVED; } buf = mmap(NULL, BUF_SIZE, PROT_WRITE, MAP_SHARED, fd, 0); if( buf == MAP_FAILED) { perror("An error occurs when calling mmap()"); shm_unlink(SHM_NAME); return PTS_UNRESOLVED; } strcpy(buf, str); fd = shm_open(SHM_NAME, O_RDONLY, S_IRUSR|S_IWUSR); if(fd == -1) { perror("An error occurs when calling shm_open()"); shm_unlink(SHM_NAME); return PTS_UNRESOLVED; } buf = mmap(NULL, BUF_SIZE, PROT_READ, MAP_SHARED, fd, 0); if( buf == MAP_FAILED) { perror("An error occurs when calling mmap()"); shm_unlink(SHM_NAME); return PTS_UNRESOLVED; } shm_unlink(SHM_NAME); if(strcmp(buf, str) == 0) { printf("Test PASSED\n"); return PTS_PASS; } printf("Test FAILED\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/shm_open/9-1.c0100644000000000000000000000130107660450567021602 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Will not test that the open file description is new (and therefore the file * descriptor does not share it with any other processes). */ #include #include "posixtest.h" int main() { printf("Will not test that the open file description is new.\n"); return PTS_UNTESTED; } posixtestsuite/conformance/interfaces/shm_open/20-1.c0100644000000000000000000000337507660126751021663 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that shm_open does not open the shared memory object for writing when * calling shm_open with O_RDONLY even if the mode set write permission. * * The test use ftruncate to check the object is not open for writing. */ /* ftruncate was formerly an XOPEN extension. We define _XOPEN_SOURCE here to avoid warning if the implementation does not program ftruncate as a base interface */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include "posixtest.h" #define BUF_SIZE 8 #define SHM_NAME "posixtest_20-1" int main() { int fd, result; result = shm_unlink(SHM_NAME); if(result != 0 && errno != ENOENT) { /* The shared memory object exist and shm_unlink can not remove it. */ perror("An error occurs when calling shm_unlink()"); return PTS_UNRESOLVED; } fd = shm_open(SHM_NAME, O_RDONLY|O_CREAT, S_IRUSR); if(fd == -1) { perror("An error occurs when calling shm_open()"); return PTS_UNRESOLVED; } result = ftruncate(fd, BUF_SIZE); if(result == -1 && errno == EINVAL) { printf("Test PASSED\n"); shm_unlink(SHM_NAME); return PTS_PASS; } else if(result == 0){ printf("The shared memory object is opened for writing.\n"); shm_unlink(SHM_NAME); return PTS_FAIL; } perror("ftruncate"); shm_unlink(SHM_NAME); return PTS_FAIL; } posixtestsuite/conformance/interfaces/shm_open/28-3.c0100644000000000000000000000527607660126752021700 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that the state of the shared memory object, including all data * associated with the shared memory object, persists until all open references * are gone even if the shared memory object is unlinked and there * is no mapping reference anymore. * * Steps: * 1. Create a shared memory object, map it and write a string in it. * 2. Unmap the memory and unlink the shared memory object. * 3. Remap the shared memory object. * 4. Check that the previously written string is always in the memory. */ /* ftruncate was formerly an XOPEN extension. We define _XOPEN_SOURCE here to avoid warning if the implementation does not program ftruncate as a base interface */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include #include "posixtest.h" #define BUF_SIZE 8 #define SHM_NAME "posixtest_28-3" int main() { int fd; char str[BUF_SIZE] = "qwerty"; char *buf; fd = shm_open(SHM_NAME, O_RDWR|O_CREAT, S_IRUSR|S_IWUSR); if(fd == -1) { perror("An error occurs when calling shm_open()"); return PTS_UNRESOLVED; } if(ftruncate(fd, BUF_SIZE) != 0) { perror("An error occurs when calling ftruncate()"); shm_unlink(SHM_NAME); return PTS_UNRESOLVED; } buf = mmap(NULL, BUF_SIZE, PROT_WRITE, MAP_SHARED, fd, 0); if( buf == MAP_FAILED) { perror("An error occurs when calling mmap()"); shm_unlink(SHM_NAME); return PTS_UNRESOLVED; } strcpy(buf, str); if(munmap(buf, BUF_SIZE) != 0) { perror("An error occurs when calling munmap()"); shm_unlink(SHM_NAME); return PTS_UNRESOLVED; } if(shm_unlink(SHM_NAME) !=0) { perror("An error occurs when calling shm_unlink()"); return PTS_UNRESOLVED; } /* Now, SHM_NAME is unlinked and there are no more mapping references on it but an open reference remain */ buf = mmap(NULL, BUF_SIZE, PROT_READ, MAP_SHARED, fd, 0); if( buf == MAP_FAILED && errno == EBADF) { printf("The shared memory object was removed.\n"); return PTS_FAIL; } else if(buf == MAP_FAILED) { perror("An error occurs when calling mmap()"); return PTS_UNRESOLVED; } if(strcmp(buf, str) == 0) { printf("Test PASSED\n"); return PTS_PASS; } printf("The content of the shared memory object was removed.\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/shm_open/39-2.c0100644000000000000000000000301207664657711021673 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that the shm_open() function sets errno = ENAMETOOLONG if the length * of the name argument exceeds {PATH_MAX} (including the terminating null). * * The used name follow the scheme: * aaaaaa/aaaaaa/aaaaaa/aaa ... */ #include #include #include #include #include #include #include #include #include "posixtest.h" /* Ensure that each component length is short enough */ #define COMPONENT_SIZE _POSIX_NAME_MAX int main() { int fd, i, path_max; char *shm_name; path_max = pathconf("/", _PC_PATH_MAX); if(path_max == -1) { perror("An error occurs when calling pathconf()"); return PTS_UNRESOLVED; } shm_name = malloc(path_max+1); for(i=0; i #include "posixtest.h" int main() { printf("Will not test whether the name and shared memory object state remain valid\nafter a system reboot. It is unspecified.\n"); return PTS_UNTESTED; } posixtestsuite/conformance/interfaces/shm_open/11-1.c0100644000000000000000000000230007660126751021646 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that the FD_CLOEXEC file descriptor flag associated with the new file * descriptor is set * * The test use fstat to check the flag. */ #include #include #include #include #include "posixtest.h" #define SHM_NAME "posixtest_11-1" int main(){ int fd, flags; fd = shm_open(SHM_NAME, O_RDONLY|O_CREAT, S_IRUSR|S_IWUSR); if(fd == -1) { perror("An error occurs when calling shm_open()"); return PTS_UNRESOLVED; } flags = fcntl(fd, F_GETFD); if(flags == -1) { perror("An error occurs when calling fcntl()"); shm_unlink(SHM_NAME); return PTS_UNRESOLVED; } shm_unlink(SHM_NAME); if(flags & FD_CLOEXEC){ printf("Test PASSED\n"); return PTS_PASS; } printf("shm_open() does not set the FD_CLOEXEC flags.\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/shm_open/23-1.c0100644000000000000000000000734410044410241021642 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that the check for the existence of the shared memory object and the * creation of the object if it does not exist is atomic with respect to other * processes executing shm_open() naming the same shared memory object with * O_EXCL and O_CREAT set. * * This test launch NPROCESS processes which all try to open NLOOP shared * memory objects. If an unexpected error occurs or if the number of created * objects is not NLOOP, the test failed. In other case the test is unresolved. */ /* ftruncate was formerly an XOPEN extension. We define _XOPEN_SOURCE here to avoid warning if the implementation does not program ftruncate as a base interface */ /* adam.li: 2004-04-30: Rewrite the test case. The idea is that with O_CREAT and O_EXCL specified, to shm_open() a object can only success once, although multiple processes might open with the same name at the same time. */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include #include #include #include #include "posixtest.h" #define NAME_SIZE 20 #define SHM_NAME "/posixtest_23-1_%d" /* The processes communicate by a shared memory object */ #define SHM_RESULT_NAME "/result_23-1" #define NPROCESS 1000 /* Number of concurrent processes */ #define NLOOP 1000 /* Number of shared memory object */ char name[NAME_SIZE]; int *create_cnt; sem_t *sem; int child_func(void) { int i, fd; struct timespec ts = {.tv_sec = 0, .tv_nsec = 0}; int msec = 0; sleep(1); srand(time(NULL)); for(i=0; i 0); for(i=0; i #include "posixtest.h" int main() { printf("Will not test the effect of a name which does not begin with the slash\ncharacter because it is implementation-defined.\n"); return PTS_UNTESTED; } posixtestsuite/conformance/interfaces/shm_open/13-2.sh0100755000000000000000000000032107660126751022045 0ustar rootroot#! /bin/sh # # Test that the file is open for read acces when the applications specify # the value of O_RDONLY. # # This is tested implicitly via assertion 1. echo "Tested implicitly via assertion 1." exit 0 posixtestsuite/conformance/interfaces/shm_open/10-1.c0100644000000000000000000000122507660450567021657 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Will not test whether the file offset is set because it is unspecified. */ #include #include "posixtest.h" int main() { printf("Will not test whether the file offset is set because it is unspecified.\n"); return PTS_UNTESTED; } posixtestsuite/conformance/interfaces/shm_open/28-1.c0100644000000000000000000000556107660126752021673 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that the state of the shared memory object, including all data * associated with the shared memory object, persists until the shared memory * object is unlinked even if all other references are gone. * * Steps: * 1. Create a shared memory object, map it and write a string in it. * 2. Unmap the memory and close the file descriptor. * 3. Reopen the shared memory object and remap it. * 4. Check that the previously written string is always in the memory. */ /* ftruncate was formerly an XOPEN extension. We define _XOPEN_SOURCE here to avoid warning if the implementation does not program ftruncate as a base interface */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include #include "posixtest.h" #define BUF_SIZE 8 #define SHM_NAME "posixtest_28-1" int main() { int fd; char str[BUF_SIZE] = "qwerty"; char *buf; fd = shm_open(SHM_NAME, O_RDWR|O_CREAT, S_IRUSR|S_IWUSR); if(fd == -1) { perror("An error occurs when calling shm_open()"); return PTS_UNRESOLVED; } if(ftruncate(fd, BUF_SIZE) != 0) { perror("An error occurs when calling ftruncate()"); shm_unlink(SHM_NAME); return PTS_UNRESOLVED; } buf = mmap(NULL, BUF_SIZE, PROT_WRITE, MAP_SHARED, fd, 0); if( buf == MAP_FAILED) { perror("An error occurs when calling mmap()"); shm_unlink(SHM_NAME); return PTS_UNRESOLVED; } strcpy(buf, str); if(munmap(buf, BUF_SIZE) != 0) { perror("An error occurs when calling munmap()"); shm_unlink(SHM_NAME); return PTS_UNRESOLVED; } if(close(fd) != 0) { perror("An error occurs when calling close()"); shm_unlink(SHM_NAME); return PTS_UNRESOLVED; } /* Now, there are no more reference on SHM_NAME but it is not unlink */ fd = shm_open(SHM_NAME, O_RDONLY, S_IRUSR|S_IWUSR); if(fd == -1 && errno == ENOENT) { printf("The name of the shared memory object was removed.\n"); return PTS_FAIL; } else if(fd == -1) { perror("An error occurs when calling shm_open()"); shm_unlink(SHM_NAME); return PTS_UNRESOLVED; } buf = mmap(NULL, BUF_SIZE, PROT_READ, MAP_SHARED, fd, 0); if( buf == MAP_FAILED) { perror("An error occurs when calling mmap()"); shm_unlink(SHM_NAME); return PTS_UNRESOLVED; } if(strcmp(buf, str) == 0) { printf("Test PASSED\n"); shm_unlink(SHM_NAME); return PTS_PASS; } printf("The content of the shared memory object was removed.\n"); shm_unlink(SHM_NAME); return PTS_FAIL; } posixtestsuite/conformance/interfaces/shm_open/14-2.c0100644000000000000000000000422507660126751021662 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that the file is open for read acces when the applications specify * the value of O_RDWR. * * Step: * 1. Create a file a shared memory object using shm_open(). * 2. Write in the file referenced by the file descriptor return by * shm_open(). * 3. Reopen the file with shm_open() and O_RDWR set. * 4. Read in the file. * The test pass if it read what it was previously written. */ /* ftruncate was formerly an XOPEN extension. We define _XOPEN_SOURCE here to avoid warning if the implementation does not program ftruncate as a base interface */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include "posixtest.h" #define BUF_SIZE 8 #define SHM_NAME "posixtest_14-2" int main() { int fd; char str[BUF_SIZE] = "qwerty"; char *buf; fd = shm_open(SHM_NAME, O_RDWR|O_CREAT, S_IRUSR|S_IWUSR); if(fd == -1) { perror("An error occurs when calling shm_open()"); return PTS_UNRESOLVED; } if(ftruncate(fd, BUF_SIZE) != 0) { perror("An error occurs when calling ftruncate()"); return PTS_UNRESOLVED; } buf = mmap(NULL, BUF_SIZE, PROT_WRITE, MAP_SHARED, fd, 0); if( buf == MAP_FAILED) { perror("An error occurs when calling mmap()"); return PTS_UNRESOLVED; } strcpy(buf, str); fd = shm_open(SHM_NAME, O_RDWR, S_IRUSR|S_IWUSR); if(fd == -1) { perror("An error occurs when calling shm_open()"); return PTS_UNRESOLVED; } buf = mmap(NULL, BUF_SIZE, PROT_READ, MAP_SHARED, fd, 0); if( buf == MAP_FAILED) { perror("An error occurs when calling mmap()"); return PTS_UNRESOLVED; } shm_unlink(SHM_NAME); if(strcmp(buf, str) == 0) { printf("Test PASSED\n"); return PTS_PASS; } printf("Test FAILED\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/shm_open/13-1.c0100644000000000000000000000276007660126751021662 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that the file is not open for write access when the applications * specify the value of O_RDONLY. * * The test uses ftruncate to check that the file is not open for write access. */ /* ftruncate was formerly an XOPEN extension. We define _XOPEN_SOURCE here to avoid warning if the implementation does not program ftruncate as a base interface */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include "posixtest.h" #define SHM_NAME "posixtest_13-1" #define BUF_SIZE 8 int main(){ int fd, result; fd = shm_open(SHM_NAME, O_RDONLY|O_CREAT, S_IRUSR|S_IWUSR); if(fd == -1) { perror("An error occurs when calling shm_open()"); return PTS_UNRESOLVED; } result = ftruncate(fd, BUF_SIZE); if(result == -1 && errno == EINVAL) { printf("Test PASSED\n"); shm_unlink(SHM_NAME); return PTS_PASS; } else if(result == 0){ printf("The file is open for write acces.\n"); shm_unlink(SHM_NAME); return PTS_FAIL; } perror("ftruncate"); shm_unlink(SHM_NAME); return PTS_FAIL; } posixtestsuite/conformance/interfaces/shm_open/39-1.c0100644000000000000000000000254107664657635021705 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that the shm_open() function sets errno = ENAMETOOLONG if the length * of a pathname component is longer than {NAME_MAX} (not including the * terminating null). */ #include #include #include #include #include #include #include #include "posixtest.h" int main() { int fd, i; long name_max; char *shm_name; name_max = pathconf("/", _PC_NAME_MAX); if(name_max == -1) { perror("An error occurs when calling pathconf()"); return PTS_UNRESOLVED; } shm_name = malloc(name_max+3); shm_name[0] = '/'; for(i=1; i #include #include #include #include #include #include "posixtest.h" #define BUF_SIZE 8 #define SHM_NAME "posixtest_20-3" int main() { int fd, result; void *ptr; result = shm_unlink(SHM_NAME); if(result != 0 && errno != ENOENT) { /* The shared memory object exist and shm_unlink can not remove it. */ perror("An error occurs when calling shm_unlink()"); return PTS_UNRESOLVED; } fd = shm_open(SHM_NAME, O_RDWR|O_CREAT, 0); if(fd == -1) { perror("An error occurs when calling shm_open()"); return PTS_UNRESOLVED; } if(ftruncate(fd, BUF_SIZE) != 0) { perror("An error occurs when calling ftruncate()"); shm_unlink(SHM_NAME); return PTS_UNRESOLVED; } ptr = mmap(NULL, BUF_SIZE, PROT_NONE, MAP_SHARED, fd, 0); if( ptr != MAP_FAILED) { printf("Test PASSED\n"); shm_unlink(SHM_NAME); return PTS_PASS; } else if(errno == EACCES){ printf("The shared memory object is not opened for reading.\n"); shm_unlink(SHM_NAME); return PTS_FAIL; } perror("mmap"); shm_unlink(SHM_NAME); return PTS_FAIL; } posixtestsuite/conformance/interfaces/shm_open/26-1.c0100644000000000000000000000341307660126751021662 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that the mode is unchanged when O_TRUNC is set, the shared memory * object exists and it is successfully opened O_RDWR. * * Steps: * 1. Create a shared memory object. * 2. Call shm_open with O_TRUNC and O_RDWR set and with differents permission * mode. * 3. Check that the mode is unchanged. */ #include #include #include #include #include "posixtest.h" #define SHM_NAME "posixtest_26-1" #define CREATION_MODE S_IRUSR|S_IWUSR #define OPEN_MODE S_IRGRP int main(){ int fd; struct stat stat_buf; mode_t old_mode; fd = shm_open(SHM_NAME, O_RDWR|O_CREAT, CREATION_MODE); if(fd == -1) { perror("An error occurs when calling shm_open()"); return PTS_UNRESOLVED; } if(fstat(fd, &stat_buf) != 0) { perror("An error occurs when calling fstat()"); shm_unlink(SHM_NAME); return PTS_UNRESOLVED; } old_mode = stat_buf.st_mode; fd = shm_open(SHM_NAME, O_RDWR|O_TRUNC, OPEN_MODE); if(fd == -1) { perror("An error occurs when calling shm_open()"); shm_unlink(SHM_NAME); return PTS_UNRESOLVED; } if(fstat(fd, &stat_buf) != 0) { perror("An error occurs when calling fstat()"); shm_unlink(SHM_NAME); return PTS_UNRESOLVED; } shm_unlink(SHM_NAME); if(stat_buf.st_mode == old_mode) { printf("Test PASSED\n"); return PTS_PASS; } printf("The mode has changed.\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/shm_open/7-1.c0100644000000000000000000000143507660450567021610 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Will not test the interpretation of slash characters other than the leading * slash character in name because it is implementation-defined. */ #include #include "posixtest.h" int main() { printf("Will not test the interpretation of slash characters other than the leading\nslash character in name because it is implementation-defined.\n"); return PTS_UNTESTED; } posixtestsuite/conformance/interfaces/shm_open/assertions.xml0100644000000000000000000002232407660126752024050 0ustar rootroot The shm_open() function shall establish a connection between a shared memory object and a file descriptor The shm_open() function shall create an open file description that refers to the shared memory object and a file descriptor that refers to that open file description It is unspecified whether the name appears in the file system and is visible to other functions that take pathnames as arguments The name argument conforms to the construction rules for a pathname. If name begins with the slash character, then processes calling shm_open() with the same value of name refer to the same shared memory object, as long as that name has not been removed If name does not begin with the slash character, the effect is implementation-defined The interpretation of slash characters other than the leading slash character in name is implementation-defined If successful, shm_open() shall return a file descriptor for the shared memory object that is the lowest numbered file descriptor not currently open for that process The open file description is new, and therefore the file descriptor does not share it with any other processes It is unspecified whether the file offset is set. The FD_CLOEXEC file descriptor flag associated with the new file descriptor is set Applications specify exactly one of the first two values (access modes) below in the value of oflag: O_RDONLY O_RDWR When the applications specify the value of O_RDONLY, the file is open for read acces only When the applications specify the value of O_RDWR, the file is open for both read and write acces If the shared memory object does not exists and the O_CREAT flags is set, the shared memory object is created If the shared memory object does not exists and the O_CREAT flags is set, the user ID of the shared memory object shall be set to the effective user ID of the process If the shared memory object does not exists and the O_CREAT flags is set, the group ID of the shared memory object is set to a system default group ID or to the effective group ID of the process If the shared memory object does not exists and the O_CREAT flags is set, the permission bits of the shared memory object shall be set to the value of the mode argument except those set in the file mode creation mask of the process If the shared memory object does not exists, the O_CREAT flags is set, and bits in mode other than the file permission bits are set, the effect is unspecified If the shared memory object does not exists and the O_CREAT flags is set, the mode argument does not affect whether the shared memory object is opened for reading, for writing, or for both When created, the shared memory object has a size of zero. If O_EXCL and O_CREAT are set, shm_open() fails if the shared memory object exist The check for the existence of the shared memory object and the creation of the object if it does not exist is atomic with respect to other processes executing shm_open() naming the same shared memory object with O_EXCL and O_CREAT set If O_EXCL is set and O_CREAT is not set, the result is undefined If O_TRUNC is set, the shared memory object exists and it is successfully opened O_RDWR, the object shall be truncated to zero length If O_TRUNC is set, the shared memory object exists and it is successfully opened O_RDWR, the mode and owner shall be unchanged by this function call The result of using O_TRUNC with O_RDONLY is undefined When a shared memory object is created, the state of the shared memory object, including all data associated with the shared memory object, persists until the shared memory object is unlinked and all other references are gone It is unspecified whether the name and shared memory object state remain valid after a system reboot Upon successful completion, the shm_open() function shall return a non-negative integer representing the lowest numbered unused file descriptor Upon unsuccessful completion, the shm_open() function shall return -1 The shm_open() function sets errno = EACCES if the shared memory object exists and the permissions specified by oflag are denied The shm_open() function sets errno = EACCES if the shared memory object does not exist and permission to create the shared memory object is denied The shm_open() function sets errno = EACCES if O_TRUNC is specified and write permission is denied The shm_open() function sets errno = EEXIST if O_CREAT and O_EXCL are set and the named shared memory object already exists The shm_open() function sets errno = EINTR if the shm_open() operation was interrupted by a signal The shm_open() function sets errno = EINVAL if the shm_open() operation is not supported for the given name The shm_open() function sets errno = EMFILE if too many file descriptors are currently in use by this process The shm_open() function sets errno = ENAMETOOLONG if the length of the name argument exceeds {PATH_MAX} or a pathname component is longer than {NAME_MAX} The shm_open() function sets errno = ENFILE if too many shared memory objects are currently open in the system The shm_open() function sets errno = ENOENT if O_CREAT is not set and the named shared memory object does not exist The shm_open() function sets errno = ENOSPC if there is insufficient space for the creation of the new shared memory object posixtestsuite/conformance/interfaces/shm_open/21-1.c0100644000000000000000000000275507660126751021665 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that the shared memory object has a size of zero when created. * * The test use fstat to get the size of shared memory object. */ #include #include #include #include #include #include #include "posixtest.h" #define SHM_NAME "posixtest_21-1" int main(){ int fd, result; struct stat stat_buf; result = shm_unlink(SHM_NAME); if(result != 0 && errno != ENOENT) { /* The shared memory object exist and shm_unlink can not remove it. */ perror("An error occurs when calling shm_unlink()"); return PTS_UNRESOLVED; } fd = shm_open(SHM_NAME, O_RDONLY|O_CREAT, S_IRUSR|S_IWUSR); if(fd == -1) { perror("An error occurs when calling shm_open()"); return PTS_UNRESOLVED; } result = fstat(fd, &stat_buf); if(result != 0) { perror("An error occurs when calling fstat()"); shm_unlink(SHM_NAME); return PTS_UNRESOLVED; } shm_unlink(SHM_NAME); if(stat_buf.st_size == 0) { printf("Test PASSED\n"); return PTS_PASS; } printf("The shared memory object has not a size of zero.\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/shm_open/25-1.c0100644000000000000000000000372107660126751021663 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that the object is truncated to zero length when O_TRUNC is set, the * shared memory object exists and it is successfully opened O_RDWR. * * Steps: * 1. Create a shared memory object and set it to a non zero size. * 2. Call shm_open with O_TRUNC and O_RDWR set. * 3. Check that the shared memory object is zero length using fstat. */ /* ftruncate was formerly an XOPEN extension. We define _XOPEN_SOURCE here to avoid warning if the implementation does not program ftruncate as a base interface */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include "posixtest.h" #define SHM_NAME "posixtest_25-1" #define SHM_SZ 16 int main(){ int fd; struct stat stat_buf; /* Create the shared memory object */ fd = shm_open(SHM_NAME, O_RDWR|O_CREAT, S_IRUSR|S_IWUSR); if(fd == -1) { perror("An error occurs when calling shm_open()"); return PTS_UNRESOLVED; } if(ftruncate(fd, SHM_SZ) == -1) { perror("An error occurs when calling ftruncate()"); return PTS_UNRESOLVED; } fd = shm_open(SHM_NAME, O_RDWR|O_TRUNC, S_IRUSR|S_IWUSR); if(fd == -1) { perror("An error occurs when calling shm_open()"); shm_unlink(SHM_NAME); return PTS_UNRESOLVED; } if(fstat(fd, &stat_buf) != 0) { perror("An error occurs when calling fstat()"); shm_unlink(SHM_NAME); return PTS_UNRESOLVED; } shm_unlink(SHM_NAME); if(stat_buf.st_size == 0) { printf("Test PASSED\n"); return PTS_PASS; } printf("The shared memory object is not zero length.\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/shm_open/coverage.txt0100644000000000000000000000232510044366621023456 0ustar rootrootThis document explains why certain assertions were not tested. Assertions not listed here should be covered by the tests in this directory. Assertions Tested ? Remarks 1 YES 2 YES Implementation of file description not specified. 3 YES Unspecified. 4 YES 5 YES 6 YES Implementation defined. 7 YES Implementation defined. 8 YES 9 YES Implementation of file description not specified. 10 YES Unspecified. 11 YES 12 YES No error specified. 13 YES 14 YES 15 YES 16 YES 17 YES 18 YES 19 YES Unspecified. 20 YES 21 YES 22 YES 23 YES The test never pass. For a conforming implementation, the test is unresolved. 24 YES Undefined. 25 YES 26 YES 27 YES Undefined. 28 YES 29 YES Unspecified, need to reboot. 30 YES 31 YES 32 YES 33 NO Not easy to test. It is somewhat implementation specific. 34 YES 35 YES 36 YES 37 YES 38 YES 39 YES 40 NO Cannot find a proper way to test. 41 YES 42 YES posixtestsuite/conformance/interfaces/shm_open/30-1.sh0100755000000000000000000000037407660126752022054 0ustar rootroot#! /bin/sh # # Test that shm_open() returns a non-negative integer representing the # lowest numbered unused file descriptor upon successful completion. # # This is tested implicitly via assertion 8. echo "Tested implicitly via assertion 8." exit 0 posixtestsuite/conformance/interfaces/shm_open/8-1.c0100644000000000000000000000313307660126752021602 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that shm_open() return a file descriptor for the shared memory object * that is the lowest numbered file descriptor not currently open for that * process * * Steps: * 1. Open a temporary file. * 2. Open a shared memory object. * 3. Check that the file descriptor number of the shared memory object * follows the one of the temporary file. * It assume that no file descriptor are closed before getting the two file * descriptors. */ /* mkstemp is an XOPEN extension. */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include "posixtest.h" #define SHM_NAME "posixtest_8-1" int main() { int fd1, fd2; char path[25] = "/tmp/posixtestXXXXXX"; fd1 = mkstemp(path); if(fd1 == -1) { perror("An error occurs when calling mkstemp()"); return PTS_UNRESOLVED; } fd2 = shm_open(SHM_NAME, O_RDWR | O_CREAT, S_IRUSR|S_IWUSR); if(fd2 == -1) { perror("An error occurs when calling shm_open()"); unlink(path); return PTS_UNRESOLVED; } unlink(path); shm_unlink(SHM_NAME); if(fd2 == (fd1+1)) { printf("Test PASSED\n"); return PTS_PASS; } printf("Test FAILED\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/shm_open/41-1.c0100644000000000000000000000230407660126752021656 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that the shm_open() function sets errno = ENOENT if O_CREAT is not set * and the named shared memory object does not exist. */ #include #include #include #include #include #include "posixtest.h" #define SHM_NAME "posixtest_41-1" int main() { int fd, result; result = shm_unlink(SHM_NAME); if(result != 0 && errno != ENOENT) { /* The shared memory object exist and shm_unlink can not remove it. */ perror("An error occurs when calling shm_unlink()"); return PTS_UNRESOLVED; } fd = shm_open(SHM_NAME, O_RDONLY, S_IRUSR); if(fd == -1 && errno == ENOENT) { printf("Test PASSED\n"); return PTS_PASS; } else if(fd != -1) { printf("shm_open() success.\n"); return PTS_FAIL; } perror("Unexpected error"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/shm_open/16-1.c0100644000000000000000000000314707660126751021665 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that the user ID of the shared memory object is set to the effective * user ID of the process when the shared memory object does not exists and the * O_CREAT flags is set. * * The test use fstat to check the flag. */ #include #include #include #include #include #include #include "posixtest.h" #define SHM_NAME "posixtest_16-1" int main(){ int fd, result; struct stat stat_buf; result = shm_unlink(SHM_NAME); if(result != 0 && errno != ENOENT) { /* The shared memory object exist and shm_unlink can not remove it. */ perror("An error occurs when calling shm_unlink()"); return PTS_UNRESOLVED; } fd = shm_open(SHM_NAME, O_RDONLY|O_CREAT, S_IRUSR|S_IWUSR); if(fd == -1) { perror("An error occurs when calling shm_open()"); return PTS_UNRESOLVED; } result = fstat(fd, &stat_buf); if(result != 0) { perror("An error occurs when calling fstat()"); shm_unlink(SHM_NAME); return PTS_UNRESOLVED; } shm_unlink(SHM_NAME); if(stat_buf.st_uid == geteuid()){ printf("Test PASSED\n"); return PTS_PASS; } printf("shm_open() does not set the user ID to the effective user ID of the process.\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/shm_open/32-1.c0100644000000000000000000000430510033204325021636 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that the shm_open() function sets errno = EACCES if the shared memory * object exists and the permissions specified by oflag are denied * * Create a shared memory object with no read or write permission and try to * open it. */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include #include #include #include "posixtest.h" #define SHM_NAME "posixtest_32-1" /** Set the euid of this process to a non-root uid */ int set_nonroot() { struct passwd *pw; setpwent(); /* search for the first user which is non root */ while((pw = getpwent()) != NULL) if(strcmp(pw->pw_name, "root")) break; endpwent(); if(pw == NULL) { printf("There is no other user than current and root.\n"); return 1; } if(seteuid(pw->pw_uid) != 0) { if(errno == EPERM) { printf("You don't have permission to change your UID.\n"); return 1; } perror("An error occurs when calling seteuid()"); return 1; } printf("Testing with user '%s' (uid: %d)\n", pw->pw_name, (int)geteuid()); return 0; } int main() { int fd; /* This test should be run under standard user permissions */ if (getuid() == 0) { if (set_nonroot() != 0) { printf("Cannot run this test as non-root user\n"); return PTS_UNTESTED; } } fd = shm_open(SHM_NAME, O_RDWR|O_CREAT, 0); if(fd == -1) { perror("An error occurs when calling shm_open()"); return PTS_UNRESOLVED; } fd = shm_open(SHM_NAME, O_RDWR, 0); if(fd == -1 && errno == EACCES) { printf("Test PASSED\n"); shm_unlink(SHM_NAME); return PTS_PASS; } else if(fd != -1) { printf("shm_open success.\n"); shm_unlink(SHM_NAME); return PTS_FAIL; } perror("shm_open"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/shm_open/38-1.c0100644000000000000000000000175607660126752021676 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that the shm_open() function sets errno = EMFILE if too many file * descriptors are currently in use by this process. */ #include #include #include #include #include #include "posixtest.h" #define SHM_NAME "posixtest_38-1" int main() { int fd = 0, count = 0; while(fd != -1) { fd = shm_open(SHM_NAME, O_RDWR|O_CREAT, S_IRUSR|S_IWUSR); count++; } if(errno == EMFILE) { shm_unlink(SHM_NAME); printf("Test PASSED: %i files open.\n", count); return PTS_PASS; } perror("shm_open"); shm_unlink(SHM_NAME); return PTS_FAIL; } posixtestsuite/conformance/interfaces/shm_open/2-1.c0100644000000000000000000000156307660450567021605 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Will not test that the shm_open() function create an open file description * that refers to the shared memory object and a file descriptor that refers to * that open file description. */ #include #include "posixtest.h" int main() { printf("Will not test that the shm_open() function create an open file description\nthat refers to the shared memory object and a file descriptor that refers to\nthat open file description."); return PTS_UNTESTED; } posixtestsuite/conformance/interfaces/shm_open/36-1.c0100644000000000000000000000142207660126752021662 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that the shm_open() function sets errno = EINTR if the operation was * interrupted by a signal. * * This is very difficult to test for a non blocking function. */ #include #include "posixtest.h" int main(){ printf("It is very difficult to test that the shm_open() function sets errno = EINTR\nwhen it is interrupted by a signal.\n"); return PTS_UNTESTED; } posixtestsuite/conformance/interfaces/shm_open/4-1.sh0100755000000000000000000000030307660126752021765 0ustar rootroot#! /bin/sh # # Test that the name argument conforms to the construction rules for a # pathname. # # This is tested implicitly via assertion 39. echo "Tested implicitly via assertion 39." exit 0 posixtestsuite/conformance/interfaces/shm_open/3-1.c0100644000000000000000000000147107660450567021604 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Will not test whether the name appears in the file system and is visible to * other functions that take pathnames as arguments because it is unspecified. */ #include #include "posixtest.h" int main() { printf("Will not test whether the name appears in the file system and is visible to\nother functions that take pathnames as arguments because it is unspecified.\n"); return PTS_UNTESTED; } posixtestsuite/conformance/interfaces/shm_open/27-1.c0100644000000000000000000000127607660450567021675 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Will not test the result of shm_open() when using O_TRUNC with O_RDONLY. * It is undefined. */ #include #include "posixtest.h" int main() { printf("Will not test the result of shm_open() when using O_TRUNC with O_RDONLY.\nIt is undefined.\n"); return PTS_UNTESTED; } posixtestsuite/conformance/interfaces/sigemptyset/0040755000000000000000000000000010515625264021674 5ustar rootrootposixtestsuite/conformance/interfaces/sigemptyset/1-1.c0100644000000000000000000000251707645116025022340 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: salwan.searty REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Make sure that none of the signals listed in this array below are found in "signalset" after sigemptyset() is called on it. */ #include #include #include #include "posixtest.h" #define NUMSIGNALS 28 int main() { int siglist[] = { SIGABRT, SIGALRM, SIGBUS, SIGCHLD, SIGCONT, SIGFPE, SIGHUP, SIGILL, SIGINT, SIGKILL, SIGPIPE, SIGQUIT, SIGSEGV, SIGSTOP, SIGTERM, SIGTSTP, SIGTTIN, SIGTTOU, SIGUSR1, SIGUSR2, SIGPOLL, SIGPROF, SIGSYS, SIGTRAP, SIGURG, SIGVTALRM, SIGXCPU, SIGXFSZ }; sigset_t signalset; int i, test_failed=0; if (sigemptyset(&signalset) == -1) { perror("sigemptyset failed -- test aborted"); return -1; } for (i=NUMSIGNALS-1; i>=0; i--) { if (sigismember(&signalset, siglist[i]) == 1) { #ifdef DEBUG printf("sigemptyset did not clear set of signal %s\n", siglist[i]); #endif test_failed=1; } } if (test_failed == 1) { return PTS_FAIL; } printf("sigemptyset passed\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/sigemptyset/assertions.xml0100644000000000000000000000077207616567635024632 0ustar rootroot sigemptyset() initializes the signal set pointed to by set, such that all signals defined in IEEE Std 1003.1-2001 are excluded from the set. sigemptyset() returns 0 upon successful completion sigemptyset() returns -1 and sets errno to indicate the error in case of unsuccessful completion. posixtestsuite/conformance/interfaces/sigemptyset/coverage.txt0100644000000000000000000000041107613567673024237 0ustar rootrootThis document defines the coverage for function sigemptyset(). Assertion Covered? 1 YES 2 YES 3 WON'T WON'T TEST 3-1 - Not possible to make sigemptyset() fail at will to return a -1. POSIX spec doesn't mention how to cause sigemptyset() to fail when called. posixtestsuite/conformance/interfaces/sigemptyset/2-1.c0100644000000000000000000000115307616567635022353 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: salwan.searty REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Simply, if sigemptyset returns a 0 here, test passes. */ #include #include #include "posixtest.h" int main() { sigset_t signalset; if ((int)sigemptyset(&signalset) != 0) { perror("sigemptyset failed -- returned -- test aborted"); return PTS_FAIL; } printf("sigemptyset passed\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/mq_notify/0040755000000000000000000000000010515625170021320 5ustar rootrootposixtestsuite/conformance/interfaces/mq_notify/5-1.c0100644000000000000000000000620710035502477021771 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: crystal.xiong REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * mq_notify() test plan: * If a process has registered for notification of message arrival * at a message queue, while some thread is blocked in mq_receive * waiting to receive a message, the arriving message should satisfy * the appropriate mq_receive(). In this case, no notification will * be sent. * NOTE: The test makes some assumptions and has some potential race * conditions, but seems the best way to test for now. * * 3/28/2003 Fix a bug mentioned by Michal Wronski, pass mq_attr struct * to the mq_open(). * * 4/11/2003 change sa_flags from SA_RESTART to 0 to avoid compile * error. * * 2/17/2004 call mq_close and mq_unlink before exit to release mq * resources */ #include #include #include #include #include #include #include #include "posixtest.h" #define TEST "5-1" #define FUNCTION "mq_notify" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " #define NAMESIZE 50 #define MSG_SIZE 40 #define BUFFER 40 int enter_handler = 0; void msg_handler() { enter_handler = 1; } void mqclean(mqd_t queue, const char *qname) { mq_close(queue); mq_unlink(qname); } int main() { char mqname[NAMESIZE]; mqd_t mqdes; const char s_msg_ptr[MSG_SIZE] = "test message \n"; char r_msg_ptr[MSG_SIZE]; struct sigevent notification; struct sigaction sa; unsigned int prio = 1; int pid; struct mq_attr attr; sprintf(mqname, "/" FUNCTION "_" TEST "_%d", getpid()); attr.mq_msgsize = BUFFER; attr.mq_maxmsg = BUFFER; mqdes = mq_open(mqname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, &attr); if (mqdes == (mqd_t)-1) { perror(ERROR_PREFIX "mq_open"); mqclean(mqdes, mqname); return PTS_UNRESOLVED; } pid = fork(); if (pid == -1) { perror(ERROR_PREFIX "fork"); mqclean(mqdes, mqname); return PTS_UNRESOLVED; } if (pid == 0) { /* child process */ mq_receive(mqdes, r_msg_ptr, MSG_SIZE, NULL); return 0; } else { /* parent process */ sleep(2); /* after 2 seconds, assume that child with block on mq_receive. */ notification.sigev_notify = SIGEV_SIGNAL; notification.sigev_signo = SIGUSR1; sa.sa_handler = msg_handler; sa.sa_flags = 0; sigaction(SIGUSR1, &sa, NULL); if (mq_notify(mqdes, ¬ification) != 0) { perror(ERROR_PREFIX "mq_notify"); return PTS_UNRESOLVED; } if (mq_send(mqdes, s_msg_ptr, MSG_SIZE, prio) == -1) { perror(ERROR_PREFIX "mq_send"); return PTS_UNRESOLVED; } sleep(1); if (mq_unlink(mqname) != 0) { perror(ERROR_PREFIX "mq_unlink"); return PTS_UNRESOLVED; } if (enter_handler) { printf("Test FAILED \n"); return PTS_FAIL; } printf("Test PASSED \n"); mqclean(mqdes, mqname); return PTS_PASS; } } posixtestsuite/conformance/interfaces/mq_notify/7-1.sh0100755000000000000000000000076707631654412022200 0ustar rootroot#!/bin/sh # Copyright (c) 2003, Intel Corporation. All rights reserved. # Created by: crystal.xiong REMOVE-THIS AT intel DOT com # This file is licensed under the GPL license. For the full content # of this license, see the COPYING file at the top level of this # source tree. # Test if mq_notify fails, it will return a value of -1 and set # errno to indicate the error. # This is tested implicitly via assertion 8,9. echo "Tested implicitly via assertion 8,9. See output for status" exit 0 posixtestsuite/conformance/interfaces/mq_notify/4-1.c0100644000000000000000000000435010035502477021765 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: crystal.xiong REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * mq_notify() test plan: * If the notification is sent to the registered process, its registration * will be removed, then, the message queue will be available for * next registration. * * 4/11/2003 change sa_flags from SA_RESTART to 0 to avoid compile * error. * * 2/17/2004 call mq_close and mq_unlink before exit to release mq * resources */ #include #include #include #include #include #include #include #include "posixtest.h" #define TEST "4-1" #define FUNCTION "mq_notify" #define MSG_SIZE 50 #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " int enter_handler = 0; void msg_handler() { enter_handler = 1; } void mqclean(mqd_t queue, const char *qname) { mq_close(queue); mq_unlink(qname); } int main() { char mqname[50]; mqd_t mqdes; const char s_msg_ptr[MSG_SIZE] = "test message \n"; struct sigevent notification; struct sigaction sa; unsigned int prio = 1; sprintf(mqname, "/" FUNCTION "_" TEST "_%d", getpid()); mqdes = mq_open(mqname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, 0); if (mqdes == (mqd_t)-1) { perror(ERROR_PREFIX "mq_open"); return PTS_UNRESOLVED; } notification.sigev_notify = SIGEV_SIGNAL; notification.sigev_signo = SIGUSR1; sa.sa_handler = msg_handler; sa.sa_flags = 0; sigaction(SIGUSR1, &sa, NULL); if (mq_notify(mqdes, ¬ification) != 0) { perror(ERROR_PREFIX "mq_notify"); mqclean(mqdes, mqname); return PTS_UNRESOLVED; } if (mq_send(mqdes, s_msg_ptr, MSG_SIZE, prio) == -1) { perror(ERROR_PREFIX "mq_send"); mqclean(mqdes, mqname); return PTS_UNRESOLVED; } if (!enter_handler) { perror(ERROR_PREFIX "mq_notify"); mqclean(mqdes, mqname); return PTS_UNRESOLVED; } if (mq_notify(mqdes, ¬ification) != 0) { printf("Test FAILED \n"); mqclean(mqdes, mqname); return PTS_FAIL; } else { printf("Test PASSED \n"); mqclean(mqdes, mqname); return PTS_PASS; } } posixtestsuite/conformance/interfaces/mq_notify/1-1.c0100644000000000000000000000433010035502477021760 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: crystal.xiong REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * mq_notify() test plan: * If the argument notification is not NULL, it will register the * calling process to be notified of message arrival at an empty * message queue. The notification will be sent to the process when * the message queue transitions from empty to non-empty. * * 4/11/2003 change sa_flags from SA_RESTART to 0 to avoid compile * error. * * 2/17/2004 call mq_close and mq_unlink before exit to release mq * resources */ #include #include #include #include #include #include #include #include "posixtest.h" #define TEST "1-1" #define FUNCTION "mq_notify" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " #define NAMESIZE 50 #define MSG_SIZE 50 int enter_handler = 0; void msg_handler() { enter_handler = 1; } void mqclean(mqd_t queue, const char *qname) { mq_close(queue); mq_unlink(qname); } int main() { char mqname[NAMESIZE]; mqd_t mqdes; const char s_msg_ptr[MSG_SIZE] = "test message \n"; struct sigevent notification; struct sigaction sa; unsigned int prio = 1; sprintf(mqname, "/" FUNCTION "_" TEST "_%d", getpid()); mqdes = mq_open(mqname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, 0); if (mqdes == (mqd_t)-1) { perror(ERROR_PREFIX "mq_open"); return PTS_UNRESOLVED; } notification.sigev_notify = SIGEV_SIGNAL; notification.sigev_signo = SIGUSR1; sa.sa_handler = msg_handler; sa.sa_flags = 0; sigaction(SIGUSR1, &sa, NULL); if (mq_notify(mqdes, ¬ification) != 0) { printf("Test FAILED \n"); mqclean(mqdes, mqname); return PTS_FAIL; } if (mq_send(mqdes, s_msg_ptr, MSG_SIZE, prio) == -1) { perror(ERROR_PREFIX "mq_send"); mqclean(mqdes, mqname); return PTS_UNRESOLVED; } sleep(1); if (!enter_handler) { printf("Test FAILED \n"); mqclean(mqdes, mqname); return PTS_FAIL; } else { printf("Test PASSED \n"); mqclean(mqdes, mqname); return PTS_PASS; } } posixtestsuite/conformance/interfaces/mq_notify/9-1.c0100644000000000000000000000401110014300743021751 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: crystal.xiong REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * mq_notify() test plan: * mq_notify will fail with EBUSY if a process is already registered for * notification by the message queue. * * 2/17/2004 call mq_close and mq_unlink before exit to release mq * resources */ #include #include #include #include #include #include #include #include #include "posixtest.h" #define TEST "9-1" #define FUNCTION "mq_notify" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " #define NAMESIZE 50 void mqclean(mqd_t queue, const char *qname) { mq_close(queue); mq_unlink(qname); } int main() { char mqname[NAMESIZE]; mqd_t mqdes; struct sigevent notification; int pid; int status; sprintf(mqname, "/" FUNCTION "_" TEST "_%d", getpid()); mqdes = mq_open(mqname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, 0); if (mqdes == (mqd_t)-1) { perror(ERROR_PREFIX "mq_open"); return PTS_UNRESOLVED; } notification.sigev_notify = SIGEV_SIGNAL; notification.sigev_signo = SIGUSR1; if (mq_notify(mqdes, ¬ification) != 0) { printf("Test FAILED \n"); mqclean(mqdes, mqname); return PTS_FAIL; } pid = fork(); if (pid == -1) { perror(ERROR_PREFIX "fork"); mqclean(mqdes, mqname); return PTS_UNRESOLVED; } if (pid == 0) { //child process if (mq_notify(mqdes, ¬ification) == -1) { if (EBUSY == errno) { printf("Test PASSED \n"); return PTS_PASS; } else { printf("errno != EBUSY \n"); printf("Test FAILED \n"); return PTS_FAIL; } } else { printf("Test FAILED \n"); return PTS_FAIL; } } else { //parent process wait(&status); mqclean(mqdes, mqname); return status; } } posixtestsuite/conformance/interfaces/mq_notify/assertions.xml0100644000000000000000000000373507632146204024243 0ustar rootroot If notification is not NULL, this function will register the calling proces to be notified of message arrival. The notification will be sent to the process when the message queue transit from empty to non-empty. Only one process may be registerd for notification of message arrival at any time, other process attempts to register for that message queue shall fail. If notification is NULL and the process is currently registered for notification by the specified message queue, the existing registration shall be removed. If the notification is sent to the registered process, its registration shall be removed. The message queue shall be available for next registration. If a process is registered for notification of message arrival at a message queue and some thread is blocked in mq_receive() waiting to receive a message, the arriving message shall satisfy the appropriate mq_receive(). The resulting behavior is as if the message queue remains empty, no notification shall be sent. If mq_notify is successful, it will return a value of zero. If mq_notify is not successful, it will return a value of -1 and set errno to indicate the error. mq_notify will fail with EBADF if mqdes argument is not a valid messsage queue descriptor. mq_notify will fail with EBUSY if a process is already registered for notification by the message queue. posixtestsuite/conformance/interfaces/mq_notify/coverage.txt0100644000000000000000000000022107631346526023656 0ustar rootrootThis document defines the coverage for the mq_notify function: Assertion Tested? 1 YES 2 YES 3 YES 4 YES 5 YES 6 YES 7 YES 8 YES 9 YES posixtestsuite/conformance/interfaces/mq_notify/8-1.c0100644000000000000000000000336310035502477021774 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: crystal.xiong REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * mq_notify() test plan: * mq_notify() will fail with EBADF if the mqdes argument is not a * valid message queue descriptor. * * 2/17/2004 call mq_close and mq_unlink before exit to release mq * resources */ #include #include #include #include #include #include #include #include #include "posixtest.h" #define TEST "8-1" #define FUNCTION "mq_notify" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " #define NAMESIZE 50 void mqclean(mqd_t queue, const char *qname) { mq_close(queue); mq_unlink(qname); } int main() { char mqname[NAMESIZE]; mqd_t mqdes; struct sigevent notification; sprintf(mqname, "/" FUNCTION "_" TEST "_%d", getpid()); mqdes = mq_open(mqname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, 0); if (mqdes == (mqd_t)-1) { perror(ERROR_PREFIX "mq_open()"); return PTS_UNRESOLVED; } mqdes = mqdes + 1; if (mq_unlink(mqname) != 0) { perror(ERROR_PREFIX "mq_unlink()"); return PTS_UNRESOLVED; } notification.sigev_notify = SIGEV_SIGNAL; notification.sigev_signo = SIGUSR1; if (mq_notify(mqdes, ¬ification) == -1) { if (EBADF == errno) { printf("Test PASSED \n"); mqclean(mqdes, mqname); return PTS_PASS; } else { printf("errno != EBADF \n"); mqclean(mqdes, mqname); printf("Test FAILED \n"); return PTS_FAIL; } } else { printf("Test FAILED \n"); mqclean(mqdes, mqname); return PTS_FAIL; } } posixtestsuite/conformance/interfaces/mq_notify/2-1.c0100644000000000000000000000377310014300743021760 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: crystal.xiong REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * mq_notify() test plan: * Only one process may be registerd for notification by a message queue. * If the calling process or other process has already registered for the * notification, subsequent attempts to register for that message queue * will fail. * * 2/17/2004 call mq_close and mq_unlink before exit to release mq * resources */ #include #include #include #include #include #include #include #include "posixtest.h" #define TEST "2-1" #define FUNCTION "mq_notify" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " #define NAMESIZE 50 void mqclean(mqd_t queue, const char *qname) { mq_close(queue); mq_unlink(qname); } int main() { char mqname[NAMESIZE]; mqd_t mqdes; struct sigevent notification; int pid; int status; sprintf(mqname, "/" FUNCTION "_" TEST "_%d", getpid()); mqdes = mq_open(mqname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, 0); if (mqdes == (mqd_t)-1) { perror(ERROR_PREFIX "mq_open"); return PTS_UNRESOLVED; } notification.sigev_notify = SIGEV_SIGNAL; notification.sigev_signo = SIGUSR1; if (mq_notify(mqdes, ¬ification) != 0) { printf("Test FAILED \n"); mqclean(mqdes, mqname); return PTS_FAIL; } pid = fork(); if (pid == -1) { perror(ERROR_PREFIX "fork"); mqclean(mqdes, mqname); return PTS_UNRESOLVED; } if (pid == 0) { /* child process */ if (mq_notify(mqdes, ¬ification) != -1) { printf("Test FAILED \n"); return PTS_FAIL; } else { printf("Test PASSED \n"); return PTS_PASS; } } else { /* parent process */ wait(&status); mqclean(mqdes, mqname); return status; } } posixtestsuite/conformance/interfaces/mq_notify/6-1.sh0100755000000000000000000000073007631654412022165 0ustar rootroot#!/bin/sh # Copyright (c) 2003, Intel Corporation. All rights reserved. # Created by: crystal.xiong REMOVE-THIS AT intel DOT com # This file is licensed under the GPL license. For the full content # of this license, see the COPYING file at the top level of this # source tree. # Test if mq_notify is success, mq_notify will return a value of 0. # This is tested implicitly via assertion 1. echo "Tested implicitly via assertion 1. See output for status" exit 0 posixtestsuite/conformance/interfaces/mq_notify/3-1.c0100644000000000000000000000506310035502477021766 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: crystal.xiong REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * mq_notify() test plan: * If the notification is NULL and the process is currently registered * for notification by the specified message queue, the existing registration * will be removed. * * 4/11/2003 change sa_flags from SA_RESTART to 0 to avoid compile * error. * * 2/17/2004 call mq_close and mq_unlink before exit to release mq * resources */ #include #include #include #include #include #include #include #include "posixtest.h" #define TEST "3-1" #define FUNCTION "mq_notify" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " #define MSG_SIZE 50 #define NAMESIZE 50 int enter_handler = 0; void msg_handler() { enter_handler = 1; } void mqclean(mqd_t queue, const char *qname) { mq_close(queue); mq_unlink(qname); } int main() { char mqname[NAMESIZE]; mqd_t mqdes; const char s_msg_ptr[MSG_SIZE] = "test message \n"; struct sigevent notification; struct sigaction sa; unsigned int prio = 1; sprintf(mqname, "/" FUNCTION "_" TEST "_%d", getpid()); mqdes = mq_open(mqname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, 0); if (mqdes == (mqd_t)-1) { perror(ERROR_PREFIX "mq_open"); return PTS_UNRESOLVED; } notification.sigev_notify = SIGEV_SIGNAL; notification.sigev_signo = SIGUSR1; sa.sa_handler = msg_handler; sa.sa_flags = 0; sigaction(SIGUSR1, &sa, NULL); if (mq_notify(mqdes, ¬ification) != 0) { perror(ERROR_PREFIX "mq_notify"); mqclean(mqdes, mqname); return PTS_UNRESOLVED; } if (mq_notify(mqdes, NULL) != 0 ) { printf("Test FAILED \n"); mqclean(mqdes, mqname); return PTS_FAIL; } if (mq_send(mqdes, s_msg_ptr, MSG_SIZE, prio) == -1) { perror(ERROR_PREFIX "mq_send"); mqclean(mqdes, mqname); return PTS_UNRESOLVED; } sleep(1); if (mq_unlink(mqname) != 0) { perror(ERROR_PREFIX "mq_unlink"); return PTS_UNRESOLVED; } if (!enter_handler) { printf("Test PASSED \n"); mqclean(mqdes, mqname); return PTS_PASS; } else { printf("Test FAILED \n"); mqclean(mqdes, mqname); return PTS_FAIL; } } posixtestsuite/conformance/interfaces/pthread_self/0040755000000000000000000000000010515625226021755 5ustar rootrootposixtestsuite/conformance/interfaces/pthread_self/1-1.c0100644000000000000000000000351510155330275022415 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_self() * * Shall return the thread ID of the calling thread. No errors are defined. * * Steps: * 1. Create a new thread. * 2. The function that the thread calls will call pthread_self() and store * the return value (which is the thread ID of the thread calling it) into * a global variable. * 3. Call pthread_equal and verify that the thread IDs are the same. * 4. Verify that the new thread ID is not the same as main thread ID. * */ #include #include #include "posixtest.h" pthread_t new_th2; /* Global thread to hold the value of when pthread_self returns from the thread function. */ void *a_thread_func() { new_th2=pthread_self(); pthread_exit(0); return NULL; } int main() { pthread_t new_th1; /* Create a new thread. */ if(pthread_create(&new_th1, NULL, a_thread_func, NULL) != 0) { perror("Error creating thread\n"); return PTS_UNRESOLVED; } /* Wait for thread to return */ if(pthread_join(new_th1, NULL) != 0) { perror("Error in pthread_join()\n"); return PTS_UNRESOLVED; } /* Call pthread_equal() and pass to it the new thread ID in both * parameters. It should return a non-zero value, indicating that * both thread IDs are equal, and therefore refer to the same * thread. */ if(pthread_equal(new_th1, new_th2) == 0) { printf("Test FAILED\n"); return PTS_FAIL; } if (pthread_equal(new_th1, pthread_self()) != 0) { printf("Test FAILED -- 2 threads have the same ID\n"); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_self/assertions.xml0100644000000000000000000000032407621017363024666 0ustar rootroot The function pthread_t pthread_self(void) returns the thread ID of the calling thread. No errors are defined. posixtestsuite/conformance/interfaces/pthread_self/coverage.txt0100644000000000000000000000014507610657654024322 0ustar rootrootThis document defines the coverage for the pthread_self() function: Assertion Tested? 1 YES NOTE: posixtestsuite/conformance/interfaces/pthread_mutexattr_getprioceiling/0040755000000000000000000000000010515625221026140 5ustar rootrootposixtestsuite/conformance/interfaces/pthread_mutexattr_getprioceiling/1-1.c0100644000000000000000000000355007644422736026621 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: bing.wei.liu REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_mutexattr_getprioceiling() * * Gets the priority ceiling attribute of a mutexattr object (which was prev. created * by the function pthread_mutexattr_init()). * * Steps:i * 1. Initialize a pthread_mutexattr_t object with pthread_mutexattr_init() * 2. Call pthread_mutexattr_getprioceiling() to obtain the prioceiling. * */ #include #include #include #include "posixtest.h" int main() { /* Make sure there is prioceiling capability. */ /* #ifndef _POSIX_PRIORITY_SCHEDULING fprintf(stderr,"prioceiling attribute is not available for testing\n"); return PTS_UNRESOLVED; #endif */ pthread_mutexattr_t mta; int prioceiling, max_prio, min_prio; /* Initialize a mutex attributes object */ if(pthread_mutexattr_init(&mta) != 0) { perror("Error at pthread_mutexattr_init()\n"); return PTS_UNRESOLVED; } /* Get the prioceiling mutex attr. */ if(pthread_mutexattr_getprioceiling(&mta, &prioceiling) != 0) { fprintf(stderr,"Error obtaining the attribute process-shared\n"); return PTS_UNRESOLVED; } /* Get the max and min prio according to SCHED_FIFO (posix scheduling policy) */ max_prio = sched_get_priority_max(SCHED_FIFO); min_prio = sched_get_priority_min(SCHED_FIFO); /* Make sure that prioceiling is withing the legal SCHED_FIFO boundries. */ if((prioceiling < min_prio) || (prioceiling > max_prio)) { printf("Test FAILED: Default prioceiling %d is not compliant with SCHED_FIFO boundry. \n", prioceiling); return PTS_FAIL; } printf("Test PASSED: Prioceiling %d\n", prioceiling); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_mutexattr_getprioceiling/1-2.c0100644000000000000000000000433107644427623026620 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: bing.wei.liu REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_mutexattr_getprioceiling() * * Gets the priority ceiling attribute of a mutexattr object (which was prev. created * by the function pthread_mutexattr_init()). * * Steps: * 1. Initialize a pthread_mutexattr_t object with pthread_mutexattr_init() * 2. Get the min and max boundries for SCHED_FIFO of what prioceiling can be. * 3. In a for loop, go through each valid SCHED_FIFO value, set the prioceiling, then * get the prio ceiling. These should always be the same. If not, fail the test. * */ #include #include #include #include "posixtest.h" int main() { /* Make sure there is prioceiling capability. */ /* #ifndef _POSIX_PRIORITY_SCHEDULING fprintf(stderr,"prioceiling attribute is not available for testing\n"); return PTS_UNRESOLVED; #endif */ pthread_mutexattr_t mta; int prioceiling, max_prio, min_prio, i; /* Initialize a mutex attributes object */ if(pthread_mutexattr_init(&mta) != 0) { perror("Error at pthread_mutexattr_init()\n"); return PTS_UNRESOLVED; } /* Get the max and min prio according to SCHED_FIFO (posix scheduling policy) */ max_prio = sched_get_priority_max(SCHED_FIFO); min_prio = sched_get_priority_min(SCHED_FIFO); for(i=min_prio;(i The function int pthread_mutexattr_getprioceiling(const pthread_mutexattr_t *restrict attr, int *restrict prioceiling); Gets the priority ceiling attribute of a mutexattr object (which was prev. created by the function pthread_mutexattr_init()). Upon success, it returns 0, and stores the value of the prioceiling in 'prioceiling'. It MAY fail if: [EINVAL] - 'attr' or 'prioceiling' is invalid. [EPERM] - The caller doesn't have the privilege to perform the operation. Shall not return an error code of [EINTR] posixtestsuite/conformance/interfaces/pthread_mutexattr_getprioceiling/coverage.txt0100644000000000000000000000023007656311671030501 0ustar rootrootThis document defines the coverage for the pthread_mutexattr_getprioceiling function: Assertion Tested? 1 YES 2 YES 3 NO. Only test [EINVAL] NOTE: posixtestsuite/conformance/interfaces/pthread_mutexattr_getprioceiling/2-1.sh0100755000000000000000000000075407644427623027020 0ustar rootroot#!/bin/sh # Copyright (c) 2002, Intel Corporation. All rights reserved. # Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com # This file is licensed under the GPL license. For the full content # of this license, see the COPYING file at the top level of this # source tree. # Upon success, it returns 0, and stores the value of the prioceiling in 'prioceiling'. # This is tested implicitly via assertion 1. echo "Tested implicitly via assertion 1. See output for status" exit 0 posixtestsuite/conformance/interfaces/pthread_mutexattr_getprioceiling/3-1.c0100644000000000000000000000255107657772055026631 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: bing.wei.liu REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_mutexattr_getprioceiling() * * It MAY fail if: * * [EINVAL] - 'attr' or 'prioceiling' is invalid. * [EPERM] - The caller doesn't have the privilege to perform the operation. * * This function shall not return an error code of [EINTR] * * Steps: * 1. Call pthread_mutexattr_getprioceiling() to obtain the prioceiling for an * uninitialized pthread_mutexattr_t object. * */ #include #include #include #include #include "posixtest.h" int main() { int prioceiling, ret; pthread_mutexattr_t mta; /* Get the prioceiling of an unintialized mutex attr. */ if((ret=pthread_mutexattr_getprioceiling(&mta, &prioceiling)) == 0) { printf("Test PASSED: *Note: Returned 0 instead of EINVAL when passed an uninitialized mutex attribute object to pthread_mutexattr_getprioceiling, but standard says 'may' fail.\n"); return PTS_PASS; }else if(ret != EINVAL) { printf("Test FAILED: Invalid return code %d. Expected EINVAL or 0.\n", ret); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/sem_open/0040755000000000000000000000000010515625235021122 5ustar rootrootposixtestsuite/conformance/interfaces/sem_open/cln.sh0100755000000000000000000000026207576236540022244 0ustar rootroot rm -f /tmp/mysem >/dev/null 2>&1 rm -f /tmp/sem_open* >/dev/null 2>&1 rm -f a.out for sem_id in `ipcs -s | awk '{print $2}'` ; do ipcrm sem $sem_id > /dev/null 2>&1 done posixtestsuite/conformance/interfaces/sem_open/2-2.c0100644000000000000000000000220407636705223021567 0ustar rootroot/* Copyright (c) 2002-2003, Intel Corporation. All rights reserved. Created by: majid.awad REMOVE-THIS AT intel DOT com This file is licensed under the GPL license. For the full content of this license, see the COPYING file at the top level of this source tree. */ /* This test case checks for the existence of the semaphore and the creation of the semaphore if it does not exist. */ #include #include #include #include #include #include #include #include "posixtest.h" #define TEST "2-2" #define FUNCTION "sem_open" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " int main() { sem_t *mysemp; char semname[50]; sprintf(semname, "/" FUNCTION "_" TEST "_%d", getpid()); mysemp = sem_open(semname, O_CREAT|O_EXCL, 0777, 1); if ( mysemp == SEM_FAILED || mysemp == NULL) { perror(ERROR_PREFIX "sem_open"); return PTS_UNRESOLVED; } if (errno != EEXIST ) { puts("TEST PASSED"); sem_unlink(semname); sem_close(mysemp); return PTS_PASS; } else { puts("TEST FAILED"); return PTS_FAIL; } } posixtestsuite/conformance/interfaces/sem_open/15-1.c0100644000000000000000000001055110207560454021647 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertion: * * If a process calls sem_open several times with the same name, * the same adress must be returned as long as the semaphore * has not been unlinked or closed as many times as opened. * The steps are: * -> Create a semaphore with sem_open * -> call sem_open several times with the same name. * -> Check that the same address is returned for the semaphore. * The test fails if a different address is returned. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /******************************************************************************/ /*************************** standard includes ********************************/ /******************************************************************************/ #include #include #include #include #include #include #include #include #include /******************************************************************************/ /*************************** Test framework *******************************/ /******************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int * (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /******************************************************************************/ /**************************** Configuration ***********************************/ /******************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif /******************************************************************************/ /*************************** Test case ***********************************/ /******************************************************************************/ /* The main test function. */ int main( int argc, char * argv[] ) { int ret, i; char * name = "/sem_open_15_1"; sem_t * sems[ 4 ]; /* Initialize output */ output_init(); /* Initialize all semaphores */ for ( i = 0; i < 4; i++ ) { sems[ i ] = sem_open( name, O_CREAT, 0777, 1 ); if ( sems[ i ] == SEM_FAILED ) { UNRESOLVED( errno, "Failed to sem_open" ); } } /* Check all calls returned the same @ */ for ( i = 0; i < 3; i++ ) { if ( sems[ i ] != sems[ i + 1 ] ) { FAILED( "sem_open returned a different address" ); } /* Close some semaphores */ ret = sem_close( sems[ i ] ); if ( ret != 0 ) { UNRESOLVED( errno, "Failed to sem_close" ); } } /* Now, reopen, we should still get the same address */ for ( i = 0; i < 3; i++ ) { sems[ i ] = sem_open( name, O_CREAT, 0777, 1 ); if ( sems[ i ] == SEM_FAILED ) { UNRESOLVED( errno, "Failed to sem_open" ); } } /* Check all calls returned the same @ */ for ( i = 0; i < 3; i++ ) { if ( sems[ i ] != sems[ i + 1 ] ) { FAILED( "sem_open returned a different address" ); } } /* Close all semaphores */ for ( i = 0; i < 4; i++ ) { ret = sem_close( sems[ i ] ); if ( ret != 0 ) { UNRESOLVED( errno, "Failed to sem_close" ); } } sem_unlink( name ); /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/sem_open/5-1.c0100644000000000000000000000215410206410704021555 0ustar rootroot/* Copyright (c) 2002-2003, Intel Corporation. All rights reserved. Created by: majid.awad REMOVE-THIS AT intel DOT com This file is licensed under the GPL license. For the full content of this license, see the COPYING file at the top level of this source tree. */ /* open_sem test case that attempts to open a new semaphore, with the maximum VALUE allowed. */ #include #include #include #include #include #include #include #include #include "posixtest.h" #define TEST "5-1" #define FUNCTION "sem_open" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " int main() { sem_t *mysemp; char semname[50]; int counter = SEM_VALUE_MAX; if (counter >= INT_MAX) { return PTS_PASS; } sprintf(semname, "/" FUNCTION "_" TEST "_%d", getpid()); ++counter; mysemp = sem_open(semname, O_CREAT, 0444, counter); if (( mysemp == SEM_FAILED) && ( errno == EINVAL )) { puts("TEST PASSED"); sem_unlink(semname); return PTS_PASS; } else { puts("TEST FAILED"); return PTS_FAIL; } } posixtestsuite/conformance/interfaces/sem_open/4-1.c0100644000000000000000000000245407636705223021577 0ustar rootroot/* Copyright (c) 2002-2003, Intel Corporation. All rights reserved. Created by: majid.awad REMOVE-THIS AT intel DOT com This file is licensed under the GPL license. For the full content of this license, see the COPYING file at the top level of this source tree. */ /* open_sem test case that attempts to open a new semaphore, close the semaphore and then open and existing semaphore, which should fail when both O_CREAT and O_EXCL name exist during the opening of a Semaphore. Fail to open is a Pass for this test. */ #include #include #include #include #include #include #include #include "posixtest.h" #define TEST "4-1" #define FUNCTION "sem_open" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " int main() { sem_t *mysemp; char semname[50]; sprintf(semname, "/" FUNCTION "_" TEST "_%d", getpid()); /*Trying to open the first Sem */ mysemp = sem_open(semname, O_CREAT, 0444, 1); sem_close(mysemp); /* Opening the same existance SEM */ mysemp = sem_open(semname, O_CREAT|O_EXCL, 0444, 1); if ((mysemp == SEM_FAILED ) && ( errno == EEXIST)) { puts("TEST PASSED"); sem_unlink(semname); return PTS_PASS; } else { puts("TEST FAILED"); return PTS_FAIL; } } posixtestsuite/conformance/interfaces/sem_open/1-3.c0100644000000000000000000000244407636705223021575 0ustar rootroot/* Copyright (c) 2002-2003, Intel Corporation. All rights reserved. Created by: majid.awad REMOVE-THIS AT intel DOT com This file is licensed under the GPL license. For the full content of this license, see the COPYING file at the top level of this source tree. */ /* sem_open test case that attempts to open a new semaphoree, and then lock it with sem_wait. Making sure the semaphore is locked. */ #include #include #include #include #include #include #include #include "posixtest.h" #define TEST "1-3" #define FUNCTION "sem_open" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " int main() { sem_t *mysemp; char semname[50]; int lock_status; sprintf(semname, "/" FUNCTION "_" TEST "_%d", getpid()); mysemp = sem_open(semname, O_CREAT, 0777, 1); if( mysemp == SEM_FAILED || mysemp == NULL ) { perror(ERROR_PREFIX "sem_open"); return PTS_UNRESOLVED; } lock_status = sem_wait(mysemp); /* Checking if sem_wait has a value returned. From sem_open */ if (lock_status == 0) { puts("TEST PASSED"); sem_close(mysemp); sem_unlink(semname); return PTS_PASS; } else { puts("TEST FAILED"); return PTS_FAIL; } } posixtestsuite/conformance/interfaces/sem_open/1-1.c0100644000000000000000000000204307636705222021565 0ustar rootroot/* Copyright (c) 2002-2003, Intel Corporation. All rights reserved. Created by: majid.awad REMOVE-THIS AT intel DOT com This file is licensed under the GPL license. For the full content of this license, see the COPYING file at the top level of this source tree. */ /* sem_open test case that attempts to open a new semaphoree, close the semaphore and verify that open_sem returns 0. */ #include #include #include #include #include #include #include #include "posixtest.h" #define TEST "1-1" #define FUNCTION "sem_open" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " int main() { sem_t *mysemp; char semname[50]; sprintf(semname, "/" FUNCTION "_" TEST "_%d", getpid()); mysemp = sem_open(semname, O_CREAT, 0777, 1); if (( mysemp == SEM_FAILED ) || (mysemp == NULL )) { puts("TEST FAILED"); return PTS_FAIL; } else { puts("TEST PASSED"); sem_close(mysemp); sem_unlink(semname); return PTS_PASS; } } posixtestsuite/conformance/interfaces/sem_open/testfrmw.c0100644000000000000000000000407210207560470023136 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * * This file is a wrapper to use the tests from the NPTL Test & Trace Project * with either the Linux Test Project or the Open POSIX Test Suite. * The following function are defined: * void output_init() * void output_fini() * void output(char * string, ...) * * The are used to output informative text (as a printf). */ #include #include /* We use a mutex to avoid conflicts in traces */ static pthread_mutex_t m_trace = PTHREAD_MUTEX_INITIALIZER; /*****************************************************************************************/ /******************************* stdout module *****************************************/ /*****************************************************************************************/ /* The following functions will output to stdout */ #if (1) void output_init() { /* do nothing */ return; } void output( char * string, ... ) { va_list ap; char *ts="[??:??:??]"; struct tm * now; time_t nw; pthread_mutex_lock(&m_trace); nw = time(NULL); now = localtime(&nw); if (now == NULL) printf(ts); else printf("[%2.2d:%2.2d:%2.2d]", now->tm_hour, now->tm_min, now->tm_sec); va_start( ap, string); vprintf(string, ap); va_end(ap); pthread_mutex_unlock(&m_trace); } void output_fini() { /*do nothing */ return; } #endif posixtestsuite/conformance/interfaces/sem_open/6-1.c0100644000000000000000000000172110206407604021562 0ustar rootroot/* Copyright (c) 2002-2003, Intel Corporation. All rights reserved. Created by: majid.awad REMOVE-THIS AT intel DOT com This file is licensed under the GPL license. For the full content of this license, see the COPYING file at the top level of this source tree. */ /* sem_open test case attempts to create a named SEM that doesn't exist. */ #include #include #include #include #include #include #include #include "posixtest.h" #define TEST "6-1" #define FUNCTION "sem_open" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " int main() { sem_t *mysemp; char semname[50]; sprintf(semname, "/" FUNCTION "_" TEST "_%d", getpid()); mysemp = sem_open(semname, 0); if ((mysemp == SEM_FAILED ) && ( errno == ENOENT )) { puts("TEST PASSED"); sem_unlink(semname); return PTS_PASS; } else { puts("TEST FAILED"); return PTS_FAIL; } } posixtestsuite/conformance/interfaces/sem_open/10-1.c0100644000000000000000000000322007636705223021644 0ustar rootroot/* Copyright (c) 2002-2003, Intel Corporation. All rights reserved. Created by: majid.awad REMOVE-THIS AT intel DOT com This file is licensed under the GPL license. For the full content of this license, see the COPYING file at the top level of this source tree. */ /* sem_open test case that attempts to open a new semaphore, call sem_wait, then try to re-create the same semaphore, which have no effect when you try to open a semaphore that already exist. */ #include #include #include #include #include #include #include #include "posixtest.h" #define TEST "10-1" #define FUNCTION "sem_open" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " int main() { sem_t *mysemp; char semname[50]; int val; sprintf(semname, "/" FUNCTION "_" TEST "_%d", getpid()); mysemp = sem_open(semname, O_CREAT, 0777, 5); if ( mysemp == SEM_FAILED ) { perror(ERROR_PREFIX "sem_open"); return PTS_UNRESOLVED; } if (sem_wait(mysemp) == -1 ) { perror(ERROR_PREFIX "sem_close"); return PTS_UNRESOLVED; } mysemp = sem_open(semname, O_CREAT, 0777, 1); if ( mysemp == SEM_FAILED ) { perror(ERROR_PREFIX "sem_open"); return PTS_UNRESOLVED; } if( sem_getvalue(mysemp, &val) == -1 ) { perror(ERROR_PREFIX "sem_getvalue"); return PTS_UNRESOLVED; } if (val != 4 ) { puts("TEST FAILED: second call of sem_open took place"); sem_unlink(semname); return PTS_FAIL; } else { puts("TEST PASSED"); sem_close(mysemp); sem_unlink(semname); return PTS_PASS; } } posixtestsuite/conformance/interfaces/sem_open/1-2.c0100644000000000000000000000206107636705222021566 0ustar rootroot/* Copyright (c) 2002-2003, Intel Corporation. All rights reserved. Created by: majid.awad REMOVE-THIS AT intel DOT com This file is licensed under the GPL license. For the full content of this license, see the COPYING file at the top level of this source tree. */ /* sem_open test case that attempts to open a new semaphoree, and the return value is not NULL */ #include #include #include #include #include #include #include #include "posixtest.h" #define TEST "1-2" #define FUNCTION "sem_open" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " int main() { sem_t *mysemp; char semname[50]; sprintf(semname, "/" FUNCTION "_" TEST "_%d", getpid()); mysemp = sem_open(semname, O_CREAT, 0777, 1); /* Checking if mysemp has a value returned. From sem_open */ if ( &mysemp != NULL) { puts("TEST PASSED"); sem_close(mysemp); sem_unlink(semname); return PTS_PASS; } else { puts("TEST FAILED"); return PTS_FAIL; } } posixtestsuite/conformance/interfaces/sem_open/assertions.xml0100644000000000000000000000545110207560470024035 0ustar rootroot sem_open test cases make sure that it establish connection between the Semaphore and the process. There are checks for return values of the address, increament, decrement, and close. sem_open attempts to open an existing semaphore, which it should fail when both O_CREAT and O_EXCL name exist during the opening of a Semaphore. errno return EACCESS: sem_open exist and the permissions of Oflag are denied. errno return EEXIST: sem_open exist and O_CREAT and O_EXCL are set. errno return EINVAL: Create a semaphore with a value of SEM_VALUE_MAX. errno return ENOENT: O_CREAT is not set and the semaphore doesn't exist. errno return ENAMETOOLONG: This test case tries to creat a named semaphore that is longer than max limit. After sem_open() is called, the process can use the sem_t address returned to reference teh semaphore in calls to sem_wait(), sem_trywait(), sem_post(), and sem_close(). Until sem_close(), _exit(), or exec*() is called, the semaphore can be used in the process. If O_CREAT is set and a semaphore already exists, O_CREAT has no effect. If O_CREAT flag is used, sem_open has two additional args: mode_t which sets the permission bits and unsigned value which sets the initial value of the semaphore. The initial value for the semaphore should be less than or equal to SEM_VALUE_MAX. Any other initial value is invalid. The effective user ID of the process == the user ID of the semaphore. The system default group ID of the effective group ID of the process == the group ID of the semaphore. After sem_open has created semaphore "name", other process can use "name" to connect to that semaphore. If a process calls sem_open several times with the same name, the same adress must be returned as long as the semaphore has not been unlinked or closed as many times as opened. posixtestsuite/conformance/interfaces/sem_open/coverage.txt0100644000000000000000000000164307663254072023466 0ustar rootroot Will not test the following error values of the semaphores because it is unknown to me of how to return these values. -- EMFILE: Too many semaphore descriptors or file descriptors are currently in use by this process. -- ENFILE: Too many semaphores are currently open in the system. -- ENOSPC: Threis insufficient space for the creation of the new names semaphore. -- assertion 7: not tested. -- assertion 8: is tested in the areas of sem_wait, sem_trywait, sem_post, and sem_close. -- assertion 9: is mainly tested in all test casses by calling sem_close. -- assertion 11: is all covered in many area's of the semaphore suite, that permission bits is set and checked, and the value is also set and checked. -- assertion 12: is mainly tests in sem_open as the maximum value and the minimum value has been tested, but not the greater than SEM_VALUE_MAX. -- assertion 13: Not tested. -- assertion 14: Not tested. posixtestsuite/conformance/interfaces/sem_open/testfrmw.h0100644000000000000000000000456410207560470023151 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * * This file is a wrapper to use the tests from the NPTL Test & Trace Project * with either the Linux Test Project or the Open POSIX Test Suite. * The following macros are defined here: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate without calling one of those macros. * * */ #include "posixtest.h" #include /* for the strerror() routine */ #ifdef __GNUC__ /* We are using GCC */ #define UNRESOLVED(x, s) \ { output("Test %s unresolved: got %i (%s) on line %i (%s)\n", __FILE__, x, strerror(x), __LINE__, s); \ output_fini(); \ exit(PTS_UNRESOLVED); } #define FAILED(s) \ { output("Test %s FAILED: %s\n", __FILE__, s); \ output_fini(); \ exit(PTS_FAIL); } #define PASSED \ output_fini(); \ exit(PTS_PASS); #define UNTESTED(s) \ { output("File %s cannot test: %s\n", __FILE__, s); \ output_fini(); \ exit(PTS_UNTESTED); \ } #else /* not using GCC */ #define UNRESOLVED(x, s) \ { output("Test unresolved: got %i (%s) on line %i (%s)\n", x, strerror(x), __LINE__, s); \ output_fini(); \ exit(PTS_UNRESOLVED); } #define FAILED(s) \ { output("Test FAILED: %s\n", s); \ output_fini(); \ exit(PTS_FAIL); } #define PASSED \ output_fini(); \ exit(PTS_PASS); #define UNTESTED(s) \ { output("Unable to test: %s\n", s); \ output_fini(); \ exit(PTS_UNTESTED); \ } #endif posixtestsuite/conformance/interfaces/sem_open/2-1.c0100644000000000000000000000263007636705223021571 0ustar rootroot/* Copyright (c) 2002-2003, Intel Corporation. All rights reserved. Created by: majid.awad REMOVE-THIS AT intel DOT com This file is licensed under the GPL license. For the full content of this license, see the COPYING file at the top level of this source tree. */ /* sem_open test case that attempts to open a new semaphore, close the semaphore and then open and existing semaphore, which should fail when both O_CREAT and O_EXCL name exist during the opening of a Semaphore. Fail to open is a Pass for this test. */ #include #include #include #include #include #include #include #include "posixtest.h" #define TEST "2-1" #define FUNCTION "sem_open" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " int main() { sem_t *mysemp; char semname[50]; sprintf(semname, "/" FUNCTION "_" TEST "_%d", getpid()); mysemp = sem_open(semname, O_CREAT, 0777, 0); if ( mysemp == SEM_FAILED ) { perror(ERROR_PREFIX "sem_open"); return PTS_UNRESOLVED; } if (sem_close(mysemp) == -1 ) { perror(ERROR_PREFIX "sem_close"); return PTS_UNRESOLVED; } mysemp = sem_open(semname, O_CREAT|O_EXCL, 0777, 1); if (( mysemp == SEM_FAILED ) && ( errno == EEXIST) ) { puts("TEST PASSED"); sem_unlink(semname); return PTS_PASS; } else { puts("TEST FAILED"); return PTS_FAIL; } } posixtestsuite/conformance/interfaces/sem_open/1-4.c0100644000000000000000000000237607636705223021602 0ustar rootroot/* Copyright (c) 2002-2003, Intel Corporation. All rights reserved. Created by: majid.awad REMOVE-THIS AT intel DOT com This file is licensed under the GPL license. For the full content of this license, see the COPYING file at the top level of this source tree. */ /* sem_open test case that attempts to open a new semaphoree, and then try to un-lock it with sem_post. Making sure the semaphore is not locked. */ #include #include #include #include #include #include #include #include "posixtest.h" #define TEST "1-4" #define FUNCTION "sem_open" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " int main() { sem_t *mysemp; char semname[20]; sprintf(semname, "/" FUNCTION "_" TEST "_%d", getpid()); mysemp = sem_open(semname, O_CREAT, 0777, 1); if( mysemp == SEM_FAILED || mysemp == NULL ) { perror(ERROR_PREFIX "sem_open"); return PTS_UNRESOLVED; } /* Checking if mysemp has a value returned. From sem_open */ if ( sem_post(mysemp) == 0 ) { puts("TEST PASSED"); sem_close(mysemp); sem_unlink(semname); return PTS_PASS; } else { puts("TEST FAILED"); return PTS_FAIL; } } posixtestsuite/conformance/interfaces/sem_open/3-1.c0100644000000000000000000000422510033204324021551 0ustar rootroot/* Copyright (c) 2002-2003, Intel Corporation. All rights reserved. Created by: majid.awad REMOVE-THIS AT intel DOT com This file is licensed under the GPL license. For the full content of this license, see the COPYING file at the top level of this source tree. */ /* open_sem test case that attempts to open a new semaphore with read permissions, close it, then create the same semaphore with write permissions which should come up with denial access. */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include #include #include #include "posixtest.h" #define TEST "3-1" #define FUNCTION "sem_open" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " /** Set the euid of this process to a non-root uid */ int set_nonroot() { struct passwd *pw; setpwent(); /* search for the first user which is non root */ while((pw = getpwent()) != NULL) if(strcmp(pw->pw_name, "root")) break; endpwent(); if(pw == NULL) { printf("There is no other user than current and root.\n"); return 1; } if(seteuid(pw->pw_uid) != 0) { if(errno == EPERM) { printf("You don't have permission to change your UID.\n"); return 1; } perror("An error occurs when calling seteuid()"); return 1; } printf("Testing with user '%s' (uid: %d)\n", pw->pw_name, (int)geteuid()); return 0; } int main() { sem_t *mysemp; char semname[50]; if (getuid() == 0) { if (set_nonroot() != 0) { printf("Cannot run this test as non-root user\n"); return PTS_UNTESTED; } } sprintf(semname, "/" FUNCTION "_" TEST "_%d", getpid()); /*Trying to open the first Sem with read mode */ mysemp = sem_open(semname, O_CREAT, 0444, 1); /* Opening the same existance SEM with write mode */ mysemp = sem_open(semname, O_CREAT, 0222 , 1); if ( mysemp != SEM_FAILED ) { perror(ERROR_PREFIX "sem_open"); return PTS_UNRESOLVED; } if (errno == EACCES ) { puts("TEST PASSED"); sem_unlink(semname); return PTS_PASS; } else { puts("TEST FAILED"); return PTS_FAIL; } } posixtestsuite/conformance/interfaces/pthread_cond_init/0040755000000000000000000000000010515625205022767 5ustar rootrootposixtestsuite/conformance/interfaces/pthread_cond_init/2-2.c0100644000000000000000000004714310063535404023440 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertion: * * If attr is NULL, the effect is the same as passing the address * of a default condition variable attributes object. * The steps are: * -> Create two cond vars, one with NULL attribute and * the other with a default attribute. * -> Compare those two cond vars: * -> If the Clock Selection option and the Timers option are supported, * do both condvars use the same clock? * (steps to do the comparison: * - test whether the system supports the CS option * - get the clock_id of the default cond attr * - wait for the two conditions with a timeout of 3 days (for exemple) * - set_time the clock_id at a later time than the timeout. * - if the set_time fails, consider the feature as passed (how to test?) * - if the set_time succeeds, check whether both conds have the same behavior. * ) */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /********************************************************************************************/ /****************************** standard includes *****************************************/ /********************************************************************************************/ #include #include #include #include #include #include #include /* we need the clock_settime routine */ /********************************************************************************************/ /****************************** Test framework *****************************************/ /********************************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /********************************************************************************************/ /********************************** Configuration ******************************************/ /********************************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif /********************************************************************************************/ /*********************************** Test case *****************************************/ /********************************************************************************************/ typedef struct { pthread_mutex_t * pmtx; pthread_cond_t * pcnd; struct timespec * timeout; unsigned short ctrl; int rc; } datatest_t; #define FLAG_TIMEDOUT (1 << 15) /* Will be set if the function exited with a timeout error */ #define FLAG_AWAKEN (1 << 14) /* Will be set if the function exited with no error and the next flag was set */ #define FLAG_CONDWAKE (1 << 13) /* the boolean associated with the condition */ #define FLAG_INWAIT (1 << 12) /* Child thread got the mutex locked */ #define MASK_COUNTER ((1 << 12) - 1) /* Those bits are reserved for a counter value */ datatest_t dtN; /* Data structure for the Null attribute condvar */ datatest_t dtI; /* Data structure for the Initializer condvar */ /**** * test_timeout * This function will receive a datatest_t argument. * It will lock the mutex, then mark the control value. * and enter a cond timedwait with the argument timeout. */ void * test_timeout(void * arg) { int ret; unsigned short cnt = 0; datatest_t * dt = (datatest_t *)arg; /* lock the test mutex */ ret = pthread_mutex_lock(dt->pmtx); if (ret != 0) { UNRESOLVED(ret, "Unable to lock mutex in test_timeout"); } /* Signal the parent thread that we are ready to wait */ dt->ctrl |= FLAG_INWAIT; /* Enter the timed wait */ do { dt->rc = pthread_cond_timedwait(dt->pcnd, dt->pmtx, dt->timeout); cnt = dt->ctrl & MASK_COUNTER; cnt++; cnt &= MASK_COUNTER; dt->ctrl &= ~MASK_COUNTER; dt->ctrl += cnt; } while ((dt->rc == 0) && ((dt->ctrl & FLAG_CONDWAKE) == 0)); /* Set the flags */ if (dt->rc == 0) { dt->ctrl |= FLAG_AWAKEN; } if (dt->rc == ETIMEDOUT) { dt->ctrl |= FLAG_TIMEDOUT; } /* Unlock the mutex and exit */ ret = pthread_mutex_unlock(dt->pmtx); if (ret != 0) { UNRESOLVED(ret, "Unable to unlock the test mutex in test_timeout"); } return NULL; } /**** * do_cs_test * This function will take care of the clock testing. */ pthread_cond_t cndI = PTHREAD_COND_INITIALIZER; int do_cs_test(void) { int ret; int result=0; pthread_mutex_t mtxN, mtxI; pthread_cond_t cndN; pthread_condattr_t ca; pthread_t thN, thD; struct timespec ts, timeout; clockid_t cid; /* The 3 next data aim to minimize the impact on the * system time, when the monotonic clock is supported */ long monotonic_clk; struct timespec diff; char sens=0; /* We are going to initialize the cond vars and the mutexes */ dtN.pmtx = &mtxN; dtI.pmtx = &mtxI; dtN.pcnd = &cndN; dtI.pcnd = &cndI; ret = pthread_mutex_init(&mtxI, NULL); if (ret != 0) { UNRESOLVED(ret, "Unable to initialize a default mutex"); } ret = pthread_mutex_init(&mtxN, NULL); if (ret != 0) { UNRESOLVED(ret, "Unable to initialize a default mutex"); } ret = pthread_condattr_init(&ca); if (ret != 0) { UNRESOLVED(ret, "Unable to initialize cond attribute object"); } #if 0 /* Test if the testcase is valid: change the clock from the "NULL" cond var */ pthread_condattr_setclock(&ca, CLOCK_MONOTONIC); ret = pthread_cond_init(&cndN, &ca); pthread_condattr_setclock(&ca, CLOCK_REALTIME); #else ret = pthread_cond_init(&cndN, NULL); #endif if (ret != 0) { UNRESOLVED(ret, "Unable to initialize the NULL attribute conditional variable."); } dtI.ctrl = 0; dtN.ctrl = 0; dtI.rc = 0; dtN.rc = 0; #if VERBOSE > 1 output("Data initialized successfully for CS test.\n"); #endif monotonic_clk = sysconf(_SC_MONOTONIC_CLOCK); #if VERBOSE > 1 output("Sysconf for monotonix clock: %li\n", monotonic_clk); #endif /* Get the default clock ID */ ret = pthread_condattr_getclock(&ca, &cid); if (ret != 0) { UNRESOLVED(ret, "Unable to get clockid from the default cond attribute object"); } /* Check whether we can set the system clock */ /* Backup the current monotonic time if available */ if (monotonic_clk != -1L) { ret = clock_gettime(CLOCK_MONOTONIC, &diff); if (ret != 0) { output("Clock_gettime(CLOCK_MONOTONIC) failed when the system claims to support this option\n"); monotonic_clk = -1L; } } ret = clock_gettime(cid, &ts); if (ret != 0) { UNRESOLVED(errno, "Unable to get clock time"); } ret = clock_settime(cid, &ts); if (ret != 0) { #if VERBOSE > 1 output("clock_settime failed (%s)\n", strerror(errno)); output("We cannot test if both cond uses the same clock then...\n"); #endif UNTESTED("Was unable to set the default clock time. Need more privileges?"); } else /* We can do the test */ { #if VERBOSE > 1 output("clock_settime succeeded\n"); #endif if (monotonic_clk != -1L) { #if VERBOSE > 2 output("Monotonic clock : %10i.%09li\n", diff.tv_sec, diff.tv_nsec); output("Default clock : %10i.%09li\n", ts.tv_sec, ts.tv_nsec); #endif /* Save the decay between default clock and clock MONOTONIC */ if (diff.tv_sec > ts.tv_sec) { sens = -1; /* monotonic was bigger than system */ if (diff.tv_nsec < ts.tv_nsec) { diff.tv_nsec += 1000000000 - ts.tv_nsec; diff.tv_sec -= 1 + ts.tv_sec; } else { diff.tv_nsec -= ts.tv_nsec; diff.tv_sec -= ts.tv_sec; } } else { if (diff.tv_sec == ts.tv_sec) { diff.tv_sec = 0; if (diff.tv_nsec > ts.tv_nsec) { sens = -1; diff.tv_nsec -= ts.tv_nsec; } else { sens = 1; /* Default clock was bigger than monotonic */ diff.tv_nsec = ts.tv_nsec - diff.tv_nsec; } } else /* ts.tv_sec > diff.tv_sec */ { sens = 1; if (ts.tv_nsec < diff.tv_nsec) { diff.tv_nsec = 1000000000 + ts.tv_nsec - diff.tv_nsec; diff.tv_sec = ts.tv_sec - (1 + diff.tv_sec); } else { diff.tv_nsec = ts.tv_nsec - diff.tv_nsec; diff.tv_sec = ts.tv_sec - diff.tv_sec; } } } #if VERBOSE > 2 output("Computed diff : %10i.%09li\n", diff.tv_sec, diff.tv_nsec); output("With monotonic %s than default\n", sens>0?"smaller":"bigger"); #endif } /* Prepare the timeout parameters */ timeout.tv_nsec = 0; timeout.tv_sec = ts.tv_sec + 260000; /* About 3 days later */ dtN.timeout = &timeout; dtI.timeout = &timeout; /* create the threads */ ret = pthread_create(&thD, NULL, test_timeout, &dtI); if (ret != 0) { UNRESOLVED(ret, "Unable to create a thread"); } ret = pthread_create(&thN, NULL, test_timeout, &dtN); if (ret != 0) { UNRESOLVED(ret, "Unable to create a thread"); } /* Lock the two mutex and make sure the threads are in wait */ ret = pthread_mutex_lock(&mtxN); if (ret != 0) { UNRESOLVED(ret, "Unable to lock a mutex"); } while ((dtN.ctrl & FLAG_INWAIT) == 0) { ret = pthread_mutex_unlock(&mtxN); if (ret != 0) { UNRESOLVED(ret, "Unable to unlock a mutex"); } sched_yield(); ret = pthread_mutex_lock(&mtxN); if (ret != 0) { UNRESOLVED(ret, "Unable to lock a mutex"); } } ret = pthread_mutex_lock(&mtxI); if (ret != 0) { UNRESOLVED(ret, "Unable to lock a mutex"); } while ((dtI.ctrl & FLAG_INWAIT) == 0) { ret = pthread_mutex_unlock(&mtxI); if (ret != 0) { UNRESOLVED(ret, "Unable to unlock a mutex"); } sched_yield(); ret = pthread_mutex_lock(&mtxI); if (ret != 0) { UNRESOLVED(ret, "Unable to lock a mutex"); } } /* Now both threads are in the timed wait */ #if VERBOSE > 1 output("Two threads are created and waiting.\n"); output("About to change the default clock value.\n"); #endif /* We re-read the default clock time, to introduce minimal error on the clock */ ret = clock_gettime(cid, &ts); if (ret != 0) { UNRESOLVED(errno, "Unable to get clock time"); } ts.tv_sec += 604800; /* Exactly 1 week forth */ /* We set the clock to a date after the timeout parameter */ ret = clock_settime(cid, &ts); if (ret != 0) { UNRESOLVED(errno, "Unable to set clock time (again)"); } /* unlock the two mutex */ ret = pthread_mutex_unlock(&mtxI); if (ret != 0) { UNRESOLVED(ret, "Unable to unlock a mutex"); } ret = pthread_mutex_unlock(&mtxN); if (ret != 0) { UNRESOLVED(ret, "Unable to unlock a mutex"); } /* Let the others threads run */ sched_yield(); #if VERBOSE > 1 output("Checking that both threads have timedout...\n"); #endif /* Relock the mutexs */ ret = pthread_mutex_lock(&mtxN); if (ret != 0) { UNRESOLVED(ret, "Unable to lock a mutex"); } ret = pthread_mutex_lock(&mtxI); if (ret != 0) { UNRESOLVED(ret, "Unable to lock a mutex"); } /* Check whether the thread has timedout */ if (dtI.rc == 0) { #if VERBOSE > 0 output("The thread was not woken when the clock was changed so as the timeout expired\n"); output("Going to simulate this POSIX behavior...\n"); #endif ret = pthread_cond_signal(&cndN); if (ret != 0) { UNRESOLVED(ret, "Unable to signal the Null attribute condition"); } ret = pthread_cond_signal(&cndI); if (ret != 0) { UNRESOLVED(ret, "Unable to signal the Default attribute condition"); } /* The threads will now report a spurious wake up ... */ /* We give the threads another chance to timeout */ /* unlock the two mutex */ ret = pthread_mutex_unlock(&mtxI); if (ret != 0) { UNRESOLVED(ret, "Unable to unlock a mutex"); } ret = pthread_mutex_unlock(&mtxN); if (ret != 0) { UNRESOLVED(ret, "Unable to unlock a mutex"); } /* Let the others threads run */ sched_yield(); #if VERBOSE > 1 output("Rechecking that both threads have timedout...\n"); #endif /* Relock the mutexs */ ret = pthread_mutex_lock(&mtxN); if (ret != 0) { UNRESOLVED(ret, "Unable to lock a mutex"); } ret = pthread_mutex_lock(&mtxI); if (ret != 0) { UNRESOLVED(ret, "Unable to lock a mutex"); } } /* Process the Null condvar */ if ((dtN.ctrl & FLAG_TIMEDOUT) != 0) { #if VERBOSE > 1 output("Null attribute cond var timed out\n"); #endif /* Join the thread */ ret = pthread_join(thN, NULL); if (ret != 0) { UNRESOLVED(ret, "Join thread failed"); } /* Unlock the mutex */ ret = pthread_mutex_unlock(&mtxN); if (ret != 0) { UNRESOLVED(ret, "Unable to unlock a mutex"); } } else { #if VERBOSE > 1 output("Null attribute cond var did not time out\n"); #endif /* Signal the condition */ dtN.ctrl |= FLAG_CONDWAKE; ret = pthread_cond_signal(&cndN); if (ret != 0) { UNRESOLVED(ret, "Unable to signal the Null attribute condition"); } /* Unlock the mutex and join the thread */ ret = pthread_mutex_unlock(&mtxN); if (ret != 0) { UNRESOLVED(ret, "Unable to unlock a mutex"); } /* Join the thread */ ret = pthread_join(thN, NULL); if (ret != 0) { UNRESOLVED(ret, "Join thread failed"); } } /* Process the Default condvar */ if ((dtI.ctrl & FLAG_TIMEDOUT) != 0) { #if VERBOSE > 1 output("Default attribute cond var timed out\n"); #endif /* Join the thread */ ret = pthread_join(thD, NULL); if (ret != 0) { UNRESOLVED(ret, "Join thread failed"); } /* Unlock the mutex */ ret = pthread_mutex_unlock(&mtxI); if (ret != 0) { UNRESOLVED(ret, "Unable to unlock a mutex"); } } else { #if VERBOSE > 1 output("Default attribute cond var did not time out\n"); #endif /* Signal the condition */ dtI.ctrl |= FLAG_CONDWAKE; ret = pthread_cond_signal(&cndI); if (ret != 0) { UNRESOLVED(ret, "Unable to signal the Default attribute condition"); } /* Unlock the mutex and join the thread */ ret = pthread_mutex_unlock(&mtxI); if (ret != 0) { UNRESOLVED(ret, "Unable to unlock a mutex"); } /* Join the thread */ ret = pthread_join(thD, NULL); if (ret != 0) { UNRESOLVED(ret, "Join thread failed"); } } /* Set the system time back to its value */ if (monotonic_clk == -1L) /* Monotonic is not supported */ { ret = clock_gettime(cid, &ts); if (ret != 0) { UNRESOLVED(errno, "Unable to get clock time"); } ts.tv_sec -= 604800; /* Exactly 1 week back */ /* We set the clock to a date after the timeout parameter */ ret = clock_settime(cid, &ts); if (ret != 0) { UNRESOLVED(errno, "Unable to set clock time (3rd time)"); } #if VERBOSE > 1 output("Default clock was set back\n"); #endif } else { /* Read the monotonic time */ ret = clock_gettime(CLOCK_MONOTONIC, &ts); if (ret != 0) { UNRESOLVED(errno, "Unable to get monotonic clock time"); } /* Apply the difference back */ if (sens > 0) /* monotonic was smaller than system => we must add the diff value */ { ts.tv_sec += diff.tv_sec; ts.tv_nsec += diff.tv_nsec; if (ts.tv_nsec >= 1000000000) { ts.tv_nsec -= 1000000000; ts.tv_sec += 1; } } else /* monotonic was bigger than system => we must remove the diff value */ { ts.tv_sec -= diff.tv_sec; if (ts.tv_nsec < diff.tv_nsec) { ts.tv_sec -= 1; ts.tv_nsec += 1000000000 - diff.tv_nsec; } else { ts.tv_nsec -= diff.tv_nsec; } } /* We set the clock to a date after the timeout parameter */ ret = clock_settime(cid, &ts); if (ret != 0) { UNRESOLVED(errno, "Unable to set clock time (3rd time)"); } #if VERBOSE > 1 output("Default clock was set back using monotonic clock as a reference\n"); #endif } /* Compare the two cond vars */ #if VERBOSE > 2 output("Default attribute cond var timedwait return value: %d\n", dtI.rc); output("Default attribute cond var exited with a timeout : %s\n", (dtI.ctrl & FLAG_TIMEDOUT)?"yes":"no"); output("Default attribute cond var had to be signaled : %s\n", (dtI.ctrl & FLAG_CONDWAKE)?"yes":"no"); output("Default attribute cond var exited as signaled : %s\n", (dtI.ctrl & FLAG_AWAKEN)?"yes":"no"); output("Default attribute cond var spurious wakeups : %d\n", (dtI.ctrl & MASK_COUNTER) - 1); output(" Null attribute cond var timedwait return value: %d\n", dtN.rc); output(" Null attribute cond var exited with a timeout : %s\n", (dtN.ctrl & FLAG_TIMEDOUT)?"yes":"no"); output(" Null attribute cond var had to be signaled : %s\n", (dtN.ctrl & FLAG_CONDWAKE)?"yes":"no"); output(" Null attribute cond var exited as signaled : %s\n", (dtN.ctrl & FLAG_AWAKEN)?"yes":"no"); output(" Null attribute cond var spurious wakeups : %d\n", (dtN.ctrl & MASK_COUNTER) - 1); #endif if ((dtN.ctrl == dtI.ctrl) && (dtN.rc == dtI.rc)) { result = 0; #if VERBOSE > 1 output("The two cond vars behaved exactly in the same maneer\n"); #endif } else { if ((dtN.ctrl & FLAG_TIMEDOUT) != (dtI.ctrl & FLAG_TIMEDOUT)) { result += 1; /* The test has failed */ } else { if (dtN.rc != dtI.rc) { output("Error codes were different: N:%d D:%d\n",dtN.rc, dtI.rc); UNRESOLVED(dtN.rc>dtI.rc?dtN.rc:dtI.rc, "Different error codes?"); } if ((dtN.ctrl & FLAG_AWAKEN) == (dtI.ctrl & FLAG_AWAKEN)) { /* The number of spurious wakeups is different */ output("Different spurious wakeups: N:%d D:%d\n", (dtN.ctrl & MASK_COUNTER) - 1, (dtI.ctrl & MASK_COUNTER) - 1); result = 0; /* We don't consider this as a fail case */ } } } } /* We can cleanup things now */ ret = pthread_cond_destroy(&cndN); if (ret != 0) { UNRESOLVED(ret, "Cond destroy failed"); } ret = pthread_condattr_destroy(&ca); if (ret != 0) { UNRESOLVED(ret, "Cond attr destroy failed"); } ret = pthread_mutex_destroy(&mtxN); if (ret != 0) { UNRESOLVED(ret, "Mutex destroy failed"); } ret = pthread_mutex_destroy(&mtxI); if (ret != 0) { UNRESOLVED(ret, "Mutex destroy failed"); } return result; } /**** * Main function */ int main(int argc, char * argv[]) { long opt_TMR, opt_CS; int ret=0; output_init(); #if VERBOSE > 1 output("Test starting...\n"); #endif opt_TMR=sysconf(_SC_TIMERS); opt_CS =sysconf(_SC_CLOCK_SELECTION); #if VERBOSE > 1 output("Timers option : %li\n", opt_TMR); output("Clock Selection option : %li\n", opt_CS); #endif if ((opt_TMR != -1L) && (opt_CS != -1L)) { #if VERBOSE > 0 output("Starting clock test\n"); #endif ret = do_cs_test(); } else { UNTESTED("This test requires unsupported features"); } if (ret != 0) { FAILED("The cond vars use different clocks."); } PASSED; } posixtestsuite/conformance/interfaces/pthread_cond_init/4-1.c0100644000000000000000000001615410063535404023437 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * * This sample test aims to check the following assertion: * The function fails and returns ENOMEM if there is not enough memory. * The steps are: * * Fork * * New process sets its memory resource limit to a minimum value, then * -> Allocate all the available memory * -> call pthread_cond_init() * -> free the memory * -> Checks that pthread_cond_init() returned 0 or ENOMEM. * * Parent process waits for the child. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /* We need the setrlimit() function from X/OPEN standard */ #ifndef WITHOUT_XOPEN #define _XOPEN_SOURCE 600 /********************************************************************************************/ /****************************** standard includes *****************************************/ /********************************************************************************************/ #include #include #include #include #include #include #include #include #include /********************************************************************************************/ /****************************** Test framework *****************************************/ /********************************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /********************************************************************************************/ /********************************** Configuration ******************************************/ /********************************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif /********************************************************************************************/ /*********************************** Test case *****************************************/ /********************************************************************************************/ int main(int argc, char * argv[]) { pid_t child; pthread_cond_t cnd; pthread_condattr_t ca[4]; pthread_condattr_t *pca[5]; int ret=0; int i; int retini[5] = {-1,-1,-1,-1,-1}; int retdtr[5]= {-1,-1,-1,-1,-1}; void * ptr, *ptr_prev=NULL; int sz = 0; struct rlimit rl; int status=0; output_init(); child = fork(); if (child == (pid_t)-1) { UNRESOLVED(errno, "Fork failed"); } if (child != 0) /* We are the father */ { if (child != waitpid(child, &status, 0)) { UNRESOLVED(errno, "Waitpid failed"); } if (WIFSIGNALED(status)) { UNRESOLVED(WTERMSIG(status), "The child process was killed."); } if (WIFEXITED(status)) return WEXITSTATUS(status); UNRESOLVED(0, "Child process neither returned nor was killed."); } /* Only the child goes further */ /* We initialize the different cond attributes */ for (i=0; (i<4) && (ret == 0); i++) { pca[i] = &ca[i]; ret = pthread_condattr_init(pca[i]); } if (ret) { UNRESOLVED(ret, "Cond attribute init failed"); } pca[4] = (pthread_condattr_t *) NULL; ret = pthread_condattr_setpshared(pca[0], PTHREAD_PROCESS_SHARED); if (ret != 0) { UNRESOLVED(ret, "Cond attribute PSHARED failed"); } ret = pthread_condattr_setpshared(pca[1], PTHREAD_PROCESS_SHARED); if (ret != 0) { UNRESOLVED(ret, "Cond attribute PSHARED failed"); } if (sysconf(_SC_MONOTONIC_CLOCK) > 0) { ret = pthread_condattr_setclock(pca[1], CLOCK_MONOTONIC); if (ret != 0) { UNRESOLVED(ret, "Cond set monotonic clock failed"); } ret = pthread_condattr_setclock(pca[2], CLOCK_MONOTONIC); if (ret != 0) { UNRESOLVED(ret, "Cond set monotonic clock failed"); } } sz = sysconf(_SC_PAGESIZE); /* Limit the process memory to a small value (64Mb for example). */ rl.rlim_max=1024*1024*64; rl.rlim_cur=1024*1024*64; if ((ret = setrlimit(RLIMIT_AS, &rl))) { UNRESOLVED(ret, "Memory limitation failed"); } #if VERBOSE > 1 output("Ready to take over memory. Page size is %d\n", sz); #endif /* Allocate all available memory */ while (1) { ptr = malloc( sz ); /* Allocate one page of memory */ if (ptr == NULL) break; #if VERBOSE > 1 ret++; #endif *(void **)ptr = ptr_prev; /* Write into the allocated page */ ptr_prev = ptr; } #if VERBOSE > 1 output("%d pages were allocated before failure\n", ret); ret = 0; #endif while (1) { ptr = malloc( sizeof(void*) ); /* Allocate every remaining bits of memory */ if (ptr == NULL) break; #if VERBOSE > 1 ret++; #endif *(void **)ptr = ptr_prev; /* Keep track of allocated memory */ ptr_prev = ptr; } #if VERBOSE > 1 output("%d additional spaces were allocated before failure\n", ret); ret = 0; #endif if (errno != ENOMEM) UNRESOLVED(errno, "Memory not full"); /* Now that memory is full, we try to initialize a cond */ for (i=0; i<5; i++) { retini[i] = pthread_cond_init(&cnd, pca[i]); if (!retini[i]) /* If cond has been initialized, we destroy it */ retdtr[i] = pthread_cond_destroy(&cnd); } /* We can now free the memory */ while (ptr_prev != NULL) { ptr = ptr_prev; ptr_prev = *(void **)ptr; free(ptr); } #if VERBOSE > 1 output("Memory is released\n"); #endif for (i=0; i<4; i++) pthread_condattr_destroy(pca[i]); for (i=0; i<5; i++) { if (retini[i] != 0 && retini[i] !=ENOMEM) { FAILED("Cond init returned a wrong error code when no memory was left"); } if (retini[i] == 0) { #if VERBOSE > 0 output("Cond (%i) initialization succeeded when memory is full\n", i); #endif if (retdtr[i] != 0) { UNRESOLVED( retdtr[i], "Cond destroy failed for a cond inilialized under full memory"); } } #if VERBOSE > 0 else { output("Cond (%i) initialization failed with ENOMEM\n", i); } #endif } PASSED; } #else /* WITHOUT_XOPEN */ int main(int argc, char * argv[]) { output_init(); UNTESTED("This test requires XSI features"); } #endif posixtestsuite/conformance/interfaces/pthread_cond_init/1-3.c0100644000000000000000000006203710110655113023430 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertion: * * If attr is NULL, the effect is the same as passing the address * of a default condition variable attributes object. * The steps are: * -> Create two cond vars, one with NULL attribute and * the other with a default attribute. * -> Compare those two cond vars: * -> If the Thread Process-shared Synchronization is supported, * does both condvars have the same behavior across * different process? (Beware of the spurious wakeups). * (Steps to achieve this goal: * - Have the two cond vars created in shared memory. * - The associated mutex are process-shared and in shared memory also. * - Fork * - One thread in parent process and one thread in child process * wait for the cond. * - Broadcast the cond from the parent process; * then sleep for a while and check if the child process was awaken. * - Do the same with the other condvar; then compare the result. * ) */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /* We need the XSI extention for the mkstemp() routine * - we could rewrite this test without this routine... */ #ifndef WITHOUT_XOPEN #define _XOPEN_SOURCE 600 #endif /********************************************************************************************/ /****************************** standard includes *****************************************/ /********************************************************************************************/ #include #include #include #include #include #include #include #include #include #include #include /********************************************************************************************/ /****************************** Test framework *****************************************/ /********************************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /********************************************************************************************/ /********************************** Configuration ******************************************/ /********************************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif /********************************************************************************************/ /*********************************** Test case *****************************************/ /********************************************************************************************/ #ifndef WITHOUT_XOPEN /* The data shared between both processes */ typedef struct { pthread_mutex_t mtxN; /* Mutex for Null attr condvar */ pthread_mutex_t mtxD; /* Mutex for Default attr condvar */ pthread_mutex_t mtxP; /* Mutex for Pshared condvar */ pthread_cond_t cndN; pthread_cond_t cndD; pthread_cond_t cndP; int cntrN; int cntrD; int cntrP; char bool; sem_t semA; sem_t semB; int result; pid_t child; } globaldata_t; /* The data shared between the threads in the child process */ typedef struct { pthread_mutex_t * pmtx; pthread_cond_t * pcnd; int * pcntr; char * pbool; sem_t * psem; pthread_t *pth; } datatest_t; /* The data shared with the signal handlers in the child process */ struct { sem_t * psem; pthread_t th[3]; } sigdata; /**** * The child threads signal handler. * */ void childsighdl(int sig) { int ret=0; ret = sem_post(sigdata.psem); if (ret != 0) { UNRESOLVED(errno, "[child] Unable to post semaphore in thread signal handler"); } } /**** * The child main signal handler * */ void mainsighdl(int sig) { /* We assume this signal handler is never called before the sigdata structure is initialized */ int ret = 0; ret = pthread_kill(sigdata.th[0], SIGUSR2); if (ret != 0) { UNRESOLVED(ret, "[child] Unable to kill a child thread"); } ret = pthread_kill(sigdata.th[1], SIGUSR2); if (ret != 0) { UNRESOLVED(ret, "[child] Unable to kill a child thread"); } ret = pthread_kill(sigdata.th[2], SIGUSR2); if (ret != 0) { UNRESOLVED(ret, "[child] Unable to kill a child thread"); } } /**** * child_process_th * Child process's thread function * */ void * child_process_th(void * arg) { int ret=0; datatest_t * dt = (datatest_t *) arg; struct sigaction sa; /* Register into the signal data structure */ *(dt->pth) = pthread_self(); /* Set the signal action and mask for the child thread: Will call childsighdl when SIGUSR2 is received. */ sigemptyset (&sa.sa_mask); sa.sa_flags = 0; sa.sa_handler = childsighdl; ret = sigaction (SIGUSR2, &sa, NULL); if (ret != 0) { UNRESOLVED(ret, "[child] Unable to register action for SIGUSR2"); } /* Any signal other than SIGUSR2 is blocked. */ sigfillset(&sa.sa_mask); sigdelset(&sa.sa_mask, SIGUSR2); ret = pthread_sigmask (SIG_SETMASK, &sa.sa_mask, NULL); if (ret != 0) { UNRESOLVED(ret, "[child] Unable to set signal mask in child thread"); } /* lock the mutex */ ret = pthread_mutex_lock(dt->pmtx); if (ret != 0) { UNRESOLVED(ret, "[child][th] Unable to lock mutex."); } /* We can now let the parent thread start its work */ do { ret = sem_post(dt->psem); } while ((ret != 0) && (errno == EINTR)); if (ret != 0) { UNRESOLVED(ret, "[child] Unable to post semaphore"); } /* Now, do the actual test: wait for the cond */ do { *(dt->pcntr) += 1; ret = pthread_cond_wait(dt->pcnd, dt->pmtx); *(dt->pcntr) += 1; } while ((ret == 0) && (*(dt->pbool) == 0)); if (ret != 0) { #if VERBOSE > 1 output("[child][thr] Unable to wait for the cond: %d - %s", ret, strerror(ret) ); #endif *(dt->pcntr) = 0; /* this will signal the parent thread that an error happened */ } /* unlock the mutex */ ret = pthread_mutex_unlock(dt->pmtx); if (ret != 0) { UNRESOLVED(ret, "[child][th] Unable to unlock mutex."); } return NULL; } /**** * child_process * Child process main thread * This function is called in the child process just after the fork. */ int child_process(globaldata_t * gd) { int ret; datatest_t dtN, dtD, dtP; pthread_t thN, thD, thP; struct sigaction sa; /* Initialize the datatest structures for the sub threads */ dtN.pmtx = &(gd->mtxN); dtN.pcnd = &(gd->cndN); dtN.pcntr = &(gd->cntrN); dtN.pbool = &(gd->bool); dtN.psem = &(gd->semA); dtN.pth = &(sigdata.th[0]); dtD.pmtx = &(gd->mtxD); dtD.pcnd = &(gd->cndD); dtD.pcntr = &(gd->cntrD); dtD.pbool = &(gd->bool); dtD.psem = &(gd->semA); dtD.pth = &(sigdata.th[1]); dtP.pmtx = &(gd->mtxP); dtP.pcnd = &(gd->cndP); dtP.pcntr = &(gd->cntrP); dtP.pbool = &(gd->bool); dtP.psem = &(gd->semA); dtP.pth = &(sigdata.th[2]); sigdata.psem = &(gd->semA); /* Register the signal handler: mainsighdl will be called when this thread receives SIGUSR1 */ sigemptyset (&sa.sa_mask); sigaddset(&sa.sa_mask, SIGUSR2); sa.sa_flags = 0; sa.sa_handler = mainsighdl; ret = sigaction (SIGUSR1, &sa, NULL); if (ret != 0) { UNRESOLVED(ret, "[child] Unable to register action for SIGUSR1"); } /* Set this thread's signal mask: we only accept SIGUSR1 */ sigfillset (&sa.sa_mask); sigdelset(&sa.sa_mask, SIGUSR1); ret = pthread_sigmask (SIG_SETMASK, &sa.sa_mask, NULL); if (ret != 0) { UNRESOLVED(ret, "[child] Unable to set signal mask in child main thread"); } /* We start the test threads */ ret = pthread_create(&thN, NULL, child_process_th, &dtN); if (ret != 0) { UNRESOLVED(ret, "[child] Unable to create thread N"); } ret = pthread_create(&thD, NULL, child_process_th, &dtD); if (ret != 0) { UNRESOLVED(ret, "[child] Unable to create thread D"); } ret = pthread_create(&thP, NULL, child_process_th, &dtP); if (ret != 0) { UNRESOLVED(ret, "[child] Unable to create thread P"); } /* We wait for the parent process to let us signal the conditions */ do { ret = sem_wait(&(gd->semB)); } while ((ret != 0) && (errno == EINTR)); if (ret != 0) { UNRESOLVED(errno, "[child] Unable to wait for semaphore B"); } /* Now signal both conditions. Changing the boolean was carried on by the parent */ ret = pthread_cond_signal(&(gd->cndN)); if (ret != 0) { UNRESOLVED(ret, "[child] Unable to signal cond N"); } ret = pthread_cond_signal(&(gd->cndD)); if (ret != 0) { UNRESOLVED(ret, "[child] Unable to signal cond D"); } ret = pthread_cond_signal(&(gd->cndP)); if (ret != 0) { UNRESOLVED(ret, "[child] Unable to signal cond P"); } /* Nothing more to do until the threads terminate */ ret = pthread_join(thN, NULL); if (ret != 0) { UNRESOLVED(ret, "[child] Unable to join the thread N"); } ret = pthread_join(thD, NULL); if (ret != 0) { UNRESOLVED(ret, "[child] Unable to join the thread D"); } ret = pthread_join(thP, NULL); if (ret != 0) { UNRESOLVED(ret, "[child] Unable to join the thread P"); } return 0; } /**** * parent_process * This function is called in the parent process just after the fork. * Don't call the UNRESOLVED macro here as it would orphan the child thread! * Instead, the macro LOC_URSLVD(x, s) is provided. The usage is the same. */ #define LOC_URSLVD(x,s) \ { \ output("UNRESOLVED:\n Got error %d - %s\n with message %s\n", x, strerror(x), s); \ gd->bool = 1; \ ret = sem_post(&(gd->semB)); \ if (ret != 0) \ { \ kill(gd->child, SIGKILL); \ /* If the call fails, this probably means the process is already dead */ \ } \ return x; \ } int parent_process(globaldata_t * gd) { int ret, tmp, i; /* Wait for the child to be ready */ ret = sem_wait(&(gd->semA)); if (ret != 0) { LOC_URSLVD(errno,"[parent] Unable to wait for sem A (1)"); } ret = sem_wait(&(gd->semA)); if (ret != 0) { LOC_URSLVD(errno,"[parent] Unable to wait for sem A (2)"); } ret = sem_wait(&(gd->semA)); if (ret != 0) { LOC_URSLVD(errno,"[parent] Unable to wait for sem A (3)"); } #if VERBOSE > 1 output("[parent] Threads are ready...\n"); #endif /* Now let the threads either enter the wait or exit if an error occured */ ret = pthread_mutex_lock(&(gd->mtxN)); if (ret != 0) { LOC_URSLVD(ret,"[parent] Unable to lock mutex N"); } ret = pthread_mutex_lock(&(gd->mtxD)); if (ret != 0) { LOC_URSLVD(ret,"[parent] Unable to lock mutex D"); } ret = pthread_mutex_lock(&(gd->mtxP)); if (ret != 0) { LOC_URSLVD(ret,"[parent] Unable to lock mutex P"); } if (gd->cntrP == 0) { /* There was an unexpected error */ LOC_URSLVD(0,"[parent] The pshared condvar reported an error"); } /* Check the threads status */ if ((gd->cntrN == 0) && (gd->cntrD == 0)) /* Both threads got an error */ { /* the test has passed */ gd->result = 0; } if ((gd->cntrN == 0) && (gd->cntrD != 0)) /* thread N got an error */ { /* the test has failed */ gd->result = gd->cntrD; } if ((gd->cntrN != 0) && (gd->cntrD == 0)) /* thread D got an error */ { /* the test has failed */ gd->result = gd->cntrN; } if ((gd->cntrN != 0) && (gd->cntrD != 0)) /* Neither thread got an error - we can test further */ { #if VERBOSE > 1 output("[parent] Both threads are waiting for the condition right now.\n"); #endif /* We can unlock the mutexs so the threads can go out from pthread_cond_wait */ ret = pthread_mutex_unlock(&(gd->mtxN)); if (ret != 0) { LOC_URSLVD(ret,"[parent] Unable to unlock mutex N"); } ret = pthread_mutex_unlock(&(gd->mtxD)); if (ret != 0) { LOC_URSLVD(ret,"[parent] Unable to unlock mutex D"); } ret = pthread_mutex_unlock(&(gd->mtxP)); if (ret != 0) { LOC_URSLVD(ret,"[parent] Unable to unlock mutex P"); } for (i=0; i<100; i++) { /* We try to signal the conditions */ tmp = pthread_cond_signal(&(gd->cndN)); ret = pthread_cond_signal(&(gd->cndD)); if (ret != tmp) { LOC_URSLVD(ret>tmp?ret:tmp, "[parent] Signaling the conditions give different error codes"); } #if VERBOSE > 1 if (i==0) { output("[parent] Signaling the condition returned %d for both condvar\n", ret); } #endif ret = pthread_cond_signal(&(gd->cndP)); if (ret != 0) { LOC_URSLVD(ret, "[parent] Signaling the pshared condition failed"); } /* Make sure the child process's threads were scheduled */ /* We kill it and wait for both threads to have the signal handled. This will mean the threads were scheduled */ ret = kill(gd->child, SIGUSR1); if (ret != 0) { LOC_URSLVD(errno, "[parent] Killing child thread with USR1 failed"); } ret = sem_wait(&(gd->semA)); if (ret != 0) { LOC_URSLVD(errno,"[parent] Unable to wait for sem A (4)"); } ret = sem_wait(&(gd->semA)); if (ret != 0) { LOC_URSLVD(errno,"[parent] Unable to wait for sem A (5)"); } ret = sem_wait(&(gd->semA)); if (ret != 0) { LOC_URSLVD(errno,"[parent] Unable to wait for sem A (6)"); } sched_yield(); /* We try to broadcast the conditions */ tmp = pthread_cond_broadcast(&(gd->cndN)); ret = pthread_cond_broadcast(&(gd->cndD)); if (ret != tmp) { LOC_URSLVD(ret>tmp?ret:tmp, "[parent] Broadcasting the conditions give different error codes"); } #if VERBOSE > 1 if (i==0) { output("[parent] Broadcasting the condition returned %d for both condvar\n", tmp); } #endif ret = pthread_cond_broadcast(&(gd->cndP)); if (ret != 0) { LOC_URSLVD(ret, "[parent] Broadcasting the pshared conditions failed"); } /* Make sure the child process's threads were scheduled */ /* We kill it and wait for both threads to have the signal handled. This will mean the threads were scheduled */ ret = kill(gd->child, SIGUSR1); if (ret != 0) { LOC_URSLVD(errno, "[parent] Killing child thread with USR1 failed"); } ret = sem_wait(&(gd->semA)); if (ret != 0) { LOC_URSLVD(errno,"[parent] Unable to wait for sem A (7)"); } ret = sem_wait(&(gd->semA)); if (ret != 0) { LOC_URSLVD(errno,"[parent] Unable to wait for sem A (8)"); } ret = sem_wait(&(gd->semA)); if (ret != 0) { LOC_URSLVD(errno,"[parent] Unable to wait for sem A (9)"); } sched_yield(); } /* Now we relock the mutexes */ ret = pthread_mutex_lock(&(gd->mtxN)); if (ret != 0) { LOC_URSLVD(ret,"[parent] Unable to lock mutex N"); } ret = pthread_mutex_lock(&(gd->mtxD)); if (ret != 0) { LOC_URSLVD(ret,"[parent] Unable to lock mutex D"); } ret = pthread_mutex_lock(&(gd->mtxP)); if (ret != 0) { LOC_URSLVD(ret,"[parent] Unable to lock mutex P"); } /* We compare the counters values */ if (gd->cntrP == 0) { LOC_URSLVD(0, "[parent] The pshared condvar failed"); } if ((gd->cntrN == 0) && (gd->cntrD == 0)) { #if VERBOSE > 1 output("[parent] Both cond wait have failed\n"); #endif gd->result = 0; /* The test has passed */ } if ((gd->cntrN == 0) && (gd->cntrD != 0)) { #if VERBOSE > 1 output("[parent] cond wait has failed for N\n"); #endif gd->result = gd->cntrD; /* The test has failed */ } if ((gd->cntrN != 0) && (gd->cntrD == 0)) { #if VERBOSE > 1 output("[parent] cond wait has failed for D\n"); #endif gd->result = gd->cntrN; /* The test has failed */ } if ((gd->cntrN != 0) && (gd->cntrD != 0)) /* None of the condwait returned an error */ { if (((gd->cntrN & 1) != 1) || ((gd->cntrD & 1) != 1)) { output("N:%d D:%d\n",gd->cntrN,gd->cntrD); LOC_URSLVD((gd->cntrN & 1)?gd->cntrD:gd->cntrN,"[parent] Even counter - pshared mutex failure"); } gd->result = 0; #if VERBOSE > 1 output("[parent] Reports:\n"); output("[parent] Process-shared condvar was awaken : %i times (reference)\n", gd->cntrP >> 1); output("[parent] Null attribute condvar was awaken : %i times\n", gd->cntrN >> 1); output("[parent] Default attr. condvar was awaken : %i times\n", gd->cntrD >> 1); #endif if ((gd->cntrN == gd->cntrP) && (gd->cntrD != gd->cntrP)) { #if VERBOSE > 1 output("[parent] Null condvar seems to be process-shared while Default condvar seems not\n"); #endif gd->result = gd->cntrD; } if ((gd->cntrN != gd->cntrP) && (gd->cntrD == gd->cntrP)) { #if VERBOSE > 1 output("[parent] Default condvar seems to be process-shared while Null condvar seems not\n"); #endif gd->result = gd->cntrN; } } } #if VERBOSE > 1 output("[parent] Threads tests are finished, about to stop them...\n"); #endif gd->bool = 1; /* the threads can now terminate */ ret = pthread_mutex_unlock(&(gd->mtxN)); if (ret != 0) { LOC_URSLVD(ret,"[parent] Unable to unlock mutex N"); } ret = pthread_mutex_unlock(&(gd->mtxD)); if (ret != 0) { LOC_URSLVD(ret,"[parent] Unable to unlock mutex D"); } ret = pthread_mutex_unlock(&(gd->mtxP)); if (ret != 0) { LOC_URSLVD(ret,"[parent] Unable to unlock mutex P"); } /* Let the child thread terminate */ ret = sem_post(&(gd->semB)); if (ret != 0) { LOC_URSLVD(errno, "[parent] Failed to post the semaphore B"); } return 0; } /**** * do_tps_test * This function will take care of testing the condvars * when shared between processes. */ int do_tps_test(void) { int ret=0; globaldata_t * gd; pthread_condattr_t ca; pthread_mutexattr_t ma; pid_t wrc, child; size_t sz; char filename[] = "/tmp/cond_init_1-3-XXXXXX"; void * mmaped; char * tmp; int fd; int status; int rc2; /* We now create the temp files */ fd = mkstemp(filename); if (fd == -1) { UNRESOLVED(errno, "Temporary file could not be created"); } /* and make sure the file will be deleted when closed */ unlink(filename); #if VERBOSE > 1 output("Temp file created (%s).\n", filename); #endif sz= (size_t)sysconf(_SC_PAGESIZE); tmp = calloc(1, sz); if (tmp == NULL) { UNRESOLVED(errno, "Memory allocation failed"); } /* Write the data to the file. */ if (write (fd, tmp, sz) != (ssize_t) sz) { UNRESOLVED(sz, "Writting to the file failed"); } free(tmp); /* Now we can map the file in memory */ mmaped = mmap(NULL, sz, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); if (mmaped == MAP_FAILED) { UNRESOLVED(errno, "mmap failed"); } gd = (globaldata_t *) mmaped; /* Our datatest structure is now in shared memory */ #if VERBOSE > 1 output("Shared memory created successfully.\n"); output("Initializing data...\n"); #endif /* Initialize the objects attributes */ ret = pthread_mutexattr_init(&ma); if (ret != 0) { UNRESOLVED(ret, "Unable to initialize mutex attribute object"); } ret = pthread_condattr_init(&ca); if (ret != 0) { UNRESOLVED(ret, "Unable to initialize condvar attribute object"); } ret = pthread_mutexattr_setpshared(&ma, PTHREAD_PROCESS_SHARED); if (ret != 0) { UNRESOLVED(ret, "Unable to set the mutex attribute as process shared"); } /* Initialize the synchronization objects */ ret = pthread_mutex_init(&(gd->mtxN), &ma); if (ret != 0) { UNRESOLVED(ret, "Unable to initialize the mutex N in shared memory"); } ret = pthread_mutex_init(&(gd->mtxD), &ma); if (ret != 0) { UNRESOLVED(ret, "Unable to initialize the mutex D in shared memory"); } ret = pthread_mutex_init(&(gd->mtxP), &ma); if (ret != 0) { UNRESOLVED(ret, "Unable to initialize the mutex P in shared memory"); } /* we don't need the mutex attribute object anymore */ ret = pthread_mutexattr_destroy(&ma); if (ret != 0) { UNRESOLVED(ret, "Unable to destroy the mutex attribute object"); } /* Now we'll initialize the cond vars */ ret = pthread_cond_init(&(gd->cndN), NULL); if (ret != 0) { UNRESOLVED(ret, "Unable to initialize the Null attribute condvar"); } ret = pthread_cond_init(&(gd->cndD), &ca); if (ret != 0) { UNRESOLVED(ret, "Unable to initialize the Default attribute condvar"); } ret = pthread_condattr_setpshared(&ca, PTHREAD_PROCESS_SHARED); if (ret != 0) { UNRESOLVED(ret, "Unable to set the cond attribute as process shared"); } ret = pthread_cond_init(&(gd->cndP), &ca); if (ret != 0) { UNRESOLVED(ret, "Unable to initialize the Pshared condvar"); } ret = pthread_condattr_destroy(&ca); if (ret != 0) { UNRESOLVED(ret, "Unable to destroy the condvar attribute object"); } /* We initialize the other values in the test structure */ gd->cntrN = 0; gd->cntrD = 0; gd->cntrP = 0; gd->bool = 0; gd->result = 0; ret = sem_init(&(gd->semA), 1, 0); if (ret != 0) { UNRESOLVED(errno, "Unable to initialize semaphore A"); } ret = sem_init(&(gd->semB), 1, 0); if (ret != 0) { UNRESOLVED(errno, "Unable to initialize semaphore B"); } /* Initializations are OK */ #if VERBOSE > 1 output("All initializations OK, proceed to the test (fork).\n"); #endif child = fork(); if (child == -1) { UNRESOLVED(errno, "Fork failed"); } if (child == 0) { /* We are the child */ ret = child_process(gd); #if VERBOSE > 1 output("[child] Test function returned %d.\n", ret); #endif exit(ret); } /* We are the parent */ gd->child = child; rc2 = parent_process(gd); #if VERBOSE > 1 output("[parent] Test function returned %d.\n", rc2); #endif /* In any case we must wait for the child */ wrc = waitpid(child, &status, 0); if (wrc != child) { output("Expected pid: %i. Got %i\n", (int)child, (int)wrc); UNRESOLVED(errno, "Waitpid failed"); } if (WIFSIGNALED(status)) { output("Child process killed with signal %d\n",WTERMSIG(status)); UNRESOLVED( rc2 , "Child process was killed"); } if (WIFEXITED(status)) { ret = WEXITSTATUS(status); } else { UNRESOLVED( rc2, "Child process was neither killed nor exited"); } #if VERBOSE > 1 output("[parent] Successfully waited for child process.\n"); #endif /* The return value from the parent is in 'rc2' and * 'ret' contains the child return code. * The test status is in gd->result */ if (rc2 != 0) { UNRESOLVED(ret, "Parent process failed"); } if (ret != 0) { UNRESOLVED(ret, "Child process failed"); } #if VERBOSE > 1 output("Destroying the data.\n"); #endif /* We can now destroy all the datas */ ret = sem_destroy(&(gd->semB)); if (ret != 0) { UNRESOLVED(errno, "Unable to destroy the semaphore B"); } ret = sem_destroy(&(gd->semA)); if (ret != 0) { UNRESOLVED(errno, "Unable to destroy the semaphore A"); } ret = pthread_cond_destroy(&(gd->cndP)); if (ret != 0) { UNRESOLVED(ret, "Unable to destroy the P condvar"); } ret = pthread_cond_destroy(&(gd->cndD)); if (ret != 0) { UNRESOLVED(ret, "Unable to destroy the D condvar"); } ret = pthread_cond_destroy(&(gd->cndN)); if (ret != 0) { UNRESOLVED(ret, "Unable to destroy the N condvar"); } ret = pthread_mutex_destroy(&(gd->mtxP)); if (ret != 0) { UNRESOLVED(ret, "Unable to destroy the P mutex"); } ret = pthread_mutex_destroy(&(gd->mtxD)); if (ret != 0) { UNRESOLVED(ret, "Unable to destroy the D mutex"); } ret = pthread_mutex_destroy(&(gd->mtxN)); if (ret != 0) { UNRESOLVED(ret, "Unable to destroy the N mutex"); } rc2 = gd->result; #if VERBOSE > 1 output("Unmapping shared memory.\n"); #endif ret = munmap(mmaped, sz); if (ret != 0) { UNRESOLVED(errno, "Memory unmapping failed"); } return rc2; } /**** * Main function * This one is responsible for executing the previous functions * according to the supported features. */ int main(int argc, char * argv[]) { long opt_TPS, opt_MF; int ret=0; output_init(); #if VERBOSE > 1 output("Test starting...\n"); #endif opt_MF =sysconf(_SC_MAPPED_FILES); opt_TPS=sysconf(_SC_THREAD_PROCESS_SHARED); #if VERBOSE > 1 output("Memory Mapped Files option : %li\n", opt_MF); output("Thread Process-shared Synchronization option: %li\n", opt_TPS); #endif if ((opt_TPS != -1L) && (opt_MF != -1L)) { #if VERBOSE > 0 output("Starting process test\n"); #endif ret = do_tps_test(); } else { UNTESTED("This test requires unsupported features"); } if (ret != 0) { FAILED("The cond vars behave differently across processes."); } #if VERBOSE > 1 output("Test terminated successfully\n"); #endif PASSED; } #else /* WITHOUT_XOPEN */ int main(int argc, char * argv[]) { output_init(); UNTESTED("This test requires XSI features"); } #endif posixtestsuite/conformance/interfaces/pthread_cond_init/1-1.c0100644000000000000000000000307507650707666023455 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: bing.wei.liu REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_cond_init() * shall initialize the condition variable referenced by cond with attributes * referenced by attr. If attr is NULL, the default condition variable attributes * shall be used; the effect is the same as passing the address of a default * condition variable attributes object. * NOTE: There is no direct way to judge if two condition variables are equal, * so this test does not cover the statement in the last sentence. * */ #include #include #include "posixtest.h" int main() { pthread_condattr_t condattr; pthread_cond_t cond1, cond2; int rc; /* Initialize a condition variable attributes object */ if((rc=pthread_condattr_init(&condattr)) != 0) { fprintf(stderr,"Error at pthread_condattr_init(), rc=%d\n",rc); return PTS_UNRESOLVED; } /* Initialize cond1 with the default condition variable attributes */ if((rc=pthread_cond_init(&cond1,&condattr)) != 0) { fprintf(stderr,"Fail to initialize cond1, rc=%d\n",rc); printf("Test FAILED\n"); return PTS_FAIL; } /* Initialize cond2 with NULL attributes */ if((rc=pthread_cond_init(&cond2,NULL)) != 0) { fprintf(stderr,"Fail to initialize cond2, rc=%d\n",rc); printf("Test FAILED\n"); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_cond_init/testfrmw.c0100644000000000000000000000343610063535404025010 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * * This file is a wrapper to use the tests from the NPTL Test & Trace Project * with either the Linux Test Project or the Open POSIX Test Suite. * The following function are defined: * void output_init() * void output_fini() * void output(char * string, ...) * * The are used to output informative text (as a printf). */ /* We use a mutex to avoid conflicts in traces */ static pthread_mutex_t m_trace = PTHREAD_MUTEX_INITIALIZER; /*****************************************************************************************/ /******************************* stdout module *****************************************/ /*****************************************************************************************/ /* The following functions will output to stdout */ #if (1) void output_init() { /* do nothing */ return; } void output( char * string, ... ) { va_list ap; pthread_mutex_lock(&m_trace); va_start( ap, string); vprintf(string, ap); va_end(ap); pthread_mutex_unlock(&m_trace); } void output_fini() { /*do nothing */ return; } #endif posixtestsuite/conformance/interfaces/pthread_cond_init/1-2.c0100644000000000000000000004745310063535404023443 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertion: * * If attr is NULL, the effect is the same as passing the address * of a default condition variable attributes object. * The steps are: * -> Create two cond vars, one with NULL attribute and * the other with a default attribute. * -> Compare those two cond vars: * -> If the Clock Selection option and the Timers option are supported, * do both condvars use the same clock? * (steps to do the comparison: * - test whether the system supports the CS option * - get the clock_id of the default cond attr * - wait for the two conditions with a timeout of 3 days (for exemple) * - set_time the clock_id at a later time than the timeout. * - if the set_time fails, consider the feature as passed (how to test?) * - if the set_time succeeds, check whether both conds have the same behavior. * ) */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /********************************************************************************************/ /****************************** standard includes *****************************************/ /********************************************************************************************/ #include #include #include #include #include #include #include /* we need the clock_settime routine */ /********************************************************************************************/ /****************************** Test framework *****************************************/ /********************************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /********************************************************************************************/ /********************************** Configuration ******************************************/ /********************************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif /********************************************************************************************/ /*********************************** Test case *****************************************/ /********************************************************************************************/ typedef struct { pthread_mutex_t * pmtx; pthread_cond_t * pcnd; struct timespec * timeout; unsigned short ctrl; int rc; } datatest_t; #define FLAG_TIMEDOUT (1 << 15) /* Will be set if the function exited with a timeout error */ #define FLAG_AWAKEN (1 << 14) /* Will be set if the function exited with no error and the next flag was set */ #define FLAG_CONDWAKE (1 << 13) /* the boolean associated with the condition */ #define FLAG_INWAIT (1 << 12) /* Child thread got the mutex locked */ #define MASK_COUNTER ((1 << 12) - 1) /* Those bits are reserved for a counter value */ datatest_t dtN; /* Data structure for the Null attribute condvar */ datatest_t dtD; /* Data structure for the Default attribute condvar */ /**** * test_timeout * This function will receive a datatest_t argument. * It will lock the mutex, then mark the control value. * and enter a cond timedwait with the argument timeout. */ void * test_timeout(void * arg) { int ret; unsigned short cnt = 0; datatest_t * dt = (datatest_t *)arg; /* lock the test mutex */ ret = pthread_mutex_lock(dt->pmtx); if (ret != 0) { UNRESOLVED(ret, "Unable to lock mutex in test_timeout"); } /* Signal the parent thread that we are ready to wait */ dt->ctrl |= FLAG_INWAIT; /* Enter the timed wait */ do { dt->rc = pthread_cond_timedwait(dt->pcnd, dt->pmtx, dt->timeout); cnt = dt->ctrl & MASK_COUNTER; cnt++; cnt &= MASK_COUNTER; dt->ctrl &= ~MASK_COUNTER; dt->ctrl += cnt; } while ((dt->rc == 0) && ((dt->ctrl & FLAG_CONDWAKE) == 0)); /* Set the flags */ if (dt->rc == 0) { dt->ctrl |= FLAG_AWAKEN; } if (dt->rc == ETIMEDOUT) { dt->ctrl |= FLAG_TIMEDOUT; } /* Unlock the mutex and exit */ ret = pthread_mutex_unlock(dt->pmtx); if (ret != 0) { UNRESOLVED(ret, "Unable to unlock the test mutex in test_timeout"); } return NULL; } /**** * do_cs_test * This function will take care of the clock testing. */ int do_cs_test(void) { int ret; int result=0; pthread_condattr_t ca; pthread_mutex_t mtxN, mtxD; pthread_cond_t cndN, cndD; pthread_t thN, thD; struct timespec ts, timeout; clockid_t cid; /* The 3 next data aim to minimize the impact on the * system time, when the monotonic clock is supported */ long monotonic_clk; struct timespec diff; char sens=0; /* We are going to initialize the cond vars and the mutexes */ dtN.pmtx = &mtxN; dtD.pmtx = &mtxD; dtN.pcnd = &cndN; dtD.pcnd = &cndD; ret = pthread_mutex_init(&mtxD, NULL); if (ret != 0) { UNRESOLVED(ret, "Unable to initialize a default mutex"); } ret = pthread_mutex_init(&mtxN, NULL); if (ret != 0) { UNRESOLVED(ret, "Unable to initialize a default mutex"); } ret = pthread_condattr_init(&ca); if (ret != 0) { UNRESOLVED(ret, "Unable to initialize cond attribute object"); } ret = pthread_cond_init(&cndD, &ca); if (ret != 0) { UNRESOLVED(ret, "Unable to initialize the default attribute conditional variable."); } #if 0 /* Test if the testcase is valid: change the clock from the "NULL" cond var */ pthread_condattr_setclock(&ca, CLOCK_MONOTONIC); ret = pthread_cond_init(&cndN, &ca); pthread_condattr_setclock(&ca, CLOCK_REALTIME); #else ret = pthread_cond_init(&cndN, NULL); #endif if (ret != 0) { UNRESOLVED(ret, "Unable to initialize the NULL attribute conditional variable."); } dtD.ctrl = 0; dtN.ctrl = 0; dtD.rc = 0; dtN.rc = 0; #if VERBOSE > 1 output("Data initialized successfully for CS test.\n"); #endif monotonic_clk = sysconf(_SC_MONOTONIC_CLOCK); #if VERBOSE > 1 output("Sysconf for monotonix clock: %li\n", monotonic_clk); #endif /* Get the default clock ID */ ret = pthread_condattr_getclock(&ca, &cid); if (ret != 0) { UNRESOLVED(ret, "Unable to get clockid from the default cond attribute object"); } /* Check whether we can set the system clock */ /* Backup the current monotonic time if available */ if (monotonic_clk != -1L) { ret = clock_gettime(CLOCK_MONOTONIC, &diff); if (ret != 0) { output("Clock_gettime(CLOCK_MONOTONIC) failed when the system claims to support this option\n"); monotonic_clk = -1L; } } ret = clock_gettime(cid, &ts); if (ret != 0) { UNRESOLVED(errno, "Unable to get clock time"); } ret = clock_settime(cid, &ts); if (ret != 0) { #if VERBOSE > 1 output("clock_settime failed (%s)\n", strerror(errno)); output("We cannot test if both cond uses the same clock then...\n"); #endif UNTESTED("Was unable to set the default clock time. Need more privileges?"); } else /* We can do the test */ { #if VERBOSE > 1 output("clock_settime succeeded\n"); #endif if (monotonic_clk != -1L) { #if VERBOSE > 2 output("Monotonic clock : %10i.%09li\n", diff.tv_sec, diff.tv_nsec); output("Default clock : %10i.%09li\n", ts.tv_sec, ts.tv_nsec); #endif /* Save the decay between default clock and clock MONOTONIC */ if (diff.tv_sec > ts.tv_sec) { sens = -1; /* monotonic was bigger than system */ if (diff.tv_nsec < ts.tv_nsec) { diff.tv_nsec += 1000000000 - ts.tv_nsec; diff.tv_sec -= 1 + ts.tv_sec; } else { diff.tv_nsec -= ts.tv_nsec; diff.tv_sec -= ts.tv_sec; } } else { if (diff.tv_sec == ts.tv_sec) { diff.tv_sec = 0; if (diff.tv_nsec > ts.tv_nsec) { sens = -1; diff.tv_nsec -= ts.tv_nsec; } else { sens = 1; /* Default clock was bigger than monotonic */ diff.tv_nsec = ts.tv_nsec - diff.tv_nsec; } } else /* ts.tv_sec > diff.tv_sec */ { sens = 1; if (ts.tv_nsec < diff.tv_nsec) { diff.tv_nsec = 1000000000 + ts.tv_nsec - diff.tv_nsec; diff.tv_sec = ts.tv_sec - (1 + diff.tv_sec); } else { diff.tv_nsec = ts.tv_nsec - diff.tv_nsec; diff.tv_sec = ts.tv_sec - diff.tv_sec; } } } #if VERBOSE > 2 output("Computed diff : %10i.%09li\n", diff.tv_sec, diff.tv_nsec); output("With monotonic %s than default\n", sens>0?"smaller":"bigger"); #endif } /* Prepare the timeout parameters */ timeout.tv_nsec = 0; timeout.tv_sec = ts.tv_sec + 260000; /* About 3 days later */ dtN.timeout = &timeout; dtD.timeout = &timeout; /* create the threads */ ret = pthread_create(&thD, NULL, test_timeout, &dtD); if (ret != 0) { UNRESOLVED(ret, "Unable to create a thread"); } ret = pthread_create(&thN, NULL, test_timeout, &dtN); if (ret != 0) { UNRESOLVED(ret, "Unable to create a thread"); } /* Lock the two mutex and make sure the threads are in wait */ ret = pthread_mutex_lock(&mtxN); if (ret != 0) { UNRESOLVED(ret, "Unable to lock a mutex"); } while ((dtN.ctrl & FLAG_INWAIT) == 0) { ret = pthread_mutex_unlock(&mtxN); if (ret != 0) { UNRESOLVED(ret, "Unable to unlock a mutex"); } sched_yield(); ret = pthread_mutex_lock(&mtxN); if (ret != 0) { UNRESOLVED(ret, "Unable to lock a mutex"); } } ret = pthread_mutex_lock(&mtxD); if (ret != 0) { UNRESOLVED(ret, "Unable to lock a mutex"); } while ((dtD.ctrl & FLAG_INWAIT) == 0) { ret = pthread_mutex_unlock(&mtxD); if (ret != 0) { UNRESOLVED(ret, "Unable to unlock a mutex"); } sched_yield(); ret = pthread_mutex_lock(&mtxD); if (ret != 0) { UNRESOLVED(ret, "Unable to lock a mutex"); } } /* Now both threads are in the timed wait */ #if VERBOSE > 1 output("Two threads are created and waiting.\n"); output("About to change the default clock value.\n"); #endif /* We re-read the default clock time, to introduce minimal error on the clock */ ret = clock_gettime(cid, &ts); if (ret != 0) { UNRESOLVED(errno, "Unable to get clock time"); } ts.tv_sec += 604800; /* Exactly 1 week forth */ /* We set the clock to a date after the timeout parameter */ ret = clock_settime(cid, &ts); if (ret != 0) { UNRESOLVED(errno, "Unable to set clock time (again)"); } /* unlock the two mutex */ ret = pthread_mutex_unlock(&mtxD); if (ret != 0) { UNRESOLVED(ret, "Unable to unlock a mutex"); } ret = pthread_mutex_unlock(&mtxN); if (ret != 0) { UNRESOLVED(ret, "Unable to unlock a mutex"); } /* Let the others threads run */ sched_yield(); #if VERBOSE > 1 output("Checking that both threads have timedout...\n"); #endif /* Relock the mutexs */ ret = pthread_mutex_lock(&mtxN); if (ret != 0) { UNRESOLVED(ret, "Unable to lock a mutex"); } ret = pthread_mutex_lock(&mtxD); if (ret != 0) { UNRESOLVED(ret, "Unable to lock a mutex"); } /* Check whether the thread has timedout */ if (dtD.rc == 0) { #if VERBOSE > 0 output("The thread was not woken when the clock was changed so as the timeout expired\n"); output("Going to simulate this POSIX behavior...\n"); #endif ret = pthread_cond_signal(&cndN); if (ret != 0) { UNRESOLVED(ret, "Unable to signal the Null attribute condition"); } ret = pthread_cond_signal(&cndD); if (ret != 0) { UNRESOLVED(ret, "Unable to signal the Default attribute condition"); } /* The threads will now report a spurious wake up ... */ /* We give the threads another chance to timeout */ /* unlock the two mutex */ ret = pthread_mutex_unlock(&mtxD); if (ret != 0) { UNRESOLVED(ret, "Unable to unlock a mutex"); } ret = pthread_mutex_unlock(&mtxN); if (ret != 0) { UNRESOLVED(ret, "Unable to unlock a mutex"); } /* Let the others threads run */ sched_yield(); #if VERBOSE > 1 output("Rechecking that both threads have timedout...\n"); #endif /* Relock the mutexs */ ret = pthread_mutex_lock(&mtxN); if (ret != 0) { UNRESOLVED(ret, "Unable to lock a mutex"); } ret = pthread_mutex_lock(&mtxD); if (ret != 0) { UNRESOLVED(ret, "Unable to lock a mutex"); } } /* Process the Null condvar */ if ((dtN.ctrl & FLAG_TIMEDOUT) != 0) { #if VERBOSE > 1 output("Null attribute cond var timed out\n"); #endif /* Join the thread */ ret = pthread_join(thN, NULL); if (ret != 0) { UNRESOLVED(ret, "Join thread failed"); } /* Unlock the mutex */ ret = pthread_mutex_unlock(&mtxN); if (ret != 0) { UNRESOLVED(ret, "Unable to unlock a mutex"); } } else { #if VERBOSE > 1 output("Null attribute cond var did not time out\n"); #endif /* Signal the condition */ dtN.ctrl |= FLAG_CONDWAKE; ret = pthread_cond_signal(&cndN); if (ret != 0) { UNRESOLVED(ret, "Unable to signal the Null attribute condition"); } /* Unlock the mutex and join the thread */ ret = pthread_mutex_unlock(&mtxN); if (ret != 0) { UNRESOLVED(ret, "Unable to unlock a mutex"); } /* Join the thread */ ret = pthread_join(thN, NULL); if (ret != 0) { UNRESOLVED(ret, "Join thread failed"); } } /* Process the Default condvar */ if ((dtD.ctrl & FLAG_TIMEDOUT) != 0) { #if VERBOSE > 1 output("Default attribute cond var timed out\n"); #endif /* Join the thread */ ret = pthread_join(thD, NULL); if (ret != 0) { UNRESOLVED(ret, "Join thread failed"); } /* Unlock the mutex */ ret = pthread_mutex_unlock(&mtxD); if (ret != 0) { UNRESOLVED(ret, "Unable to unlock a mutex"); } } else { #if VERBOSE > 1 output("Default attribute cond var did not time out\n"); #endif /* Signal the condition */ dtD.ctrl |= FLAG_CONDWAKE; ret = pthread_cond_signal(&cndD); if (ret != 0) { UNRESOLVED(ret, "Unable to signal the Default attribute condition"); } /* Unlock the mutex and join the thread */ ret = pthread_mutex_unlock(&mtxD); if (ret != 0) { UNRESOLVED(ret, "Unable to unlock a mutex"); } /* Join the thread */ ret = pthread_join(thD, NULL); if (ret != 0) { UNRESOLVED(ret, "Join thread failed"); } } /* Set the system time back to its value */ if (monotonic_clk == -1L) /* Monotonic is not supported */ { ret = clock_gettime(cid, &ts); if (ret != 0) { UNRESOLVED(errno, "Unable to get clock time"); } ts.tv_sec -= 604800; /* Exactly 1 week back */ /* We set the clock to a date after the timeout parameter */ ret = clock_settime(cid, &ts); if (ret != 0) { UNRESOLVED(errno, "Unable to set clock time (3rd time)"); } #if VERBOSE > 1 output("Default clock was set back\n"); #endif } else { /* Read the monotonic time */ ret = clock_gettime(CLOCK_MONOTONIC, &ts); if (ret != 0) { UNRESOLVED(errno, "Unable to get monotonic clock time"); } /* Apply the difference back */ if (sens > 0) /* monotonic was smaller than system => we must add the diff value */ { ts.tv_sec += diff.tv_sec; ts.tv_nsec += diff.tv_nsec; if (ts.tv_nsec >= 1000000000) { ts.tv_nsec -= 1000000000; ts.tv_sec += 1; } } else /* monotonic was bigger than system => we must remove the diff value */ { ts.tv_sec -= diff.tv_sec; if (ts.tv_nsec < diff.tv_nsec) { ts.tv_sec -= 1; ts.tv_nsec += 1000000000 - diff.tv_nsec; } else { ts.tv_nsec -= diff.tv_nsec; } } /* We set the clock to a date after the timeout parameter */ ret = clock_settime(cid, &ts); if (ret != 0) { UNRESOLVED(errno, "Unable to set clock time (3rd time)"); } #if VERBOSE > 1 output("Default clock was set back using monotonic clock as a reference\n"); #endif } /* Compare the two cond vars */ #if VERBOSE > 2 output("Default attribute cond var timedwait return value: %d\n", dtD.rc); output("Default attribute cond var exited with a timeout : %s\n", (dtD.ctrl & FLAG_TIMEDOUT)?"yes":"no"); output("Default attribute cond var had to be signaled : %s\n", (dtD.ctrl & FLAG_CONDWAKE)?"yes":"no"); output("Default attribute cond var exited as signaled : %s\n", (dtD.ctrl & FLAG_AWAKEN)?"yes":"no"); output("Default attribute cond var spurious wakeups : %d\n", (dtD.ctrl & MASK_COUNTER) - 1); output(" Null attribute cond var timedwait return value: %d\n", dtN.rc); output(" Null attribute cond var exited with a timeout : %s\n", (dtN.ctrl & FLAG_TIMEDOUT)?"yes":"no"); output(" Null attribute cond var had to be signaled : %s\n", (dtN.ctrl & FLAG_CONDWAKE)?"yes":"no"); output(" Null attribute cond var exited as signaled : %s\n", (dtN.ctrl & FLAG_AWAKEN)?"yes":"no"); output(" Null attribute cond var spurious wakeups : %d\n", (dtN.ctrl & MASK_COUNTER) - 1); #endif if ((dtN.ctrl == dtD.ctrl) && (dtN.rc == dtD.rc)) { result = 0; #if VERBOSE > 1 output("The two cond vars behaved exactly in the same maneer\n"); #endif } else { if ((dtN.ctrl & FLAG_TIMEDOUT) != (dtD.ctrl & FLAG_TIMEDOUT)) { result += 1; /* The test has failed */ } else { if (dtN.rc != dtD.rc) { output("Error codes were different: N:%d D:%d\n",dtN.rc, dtD.rc); UNRESOLVED(dtN.rc>dtD.rc?dtN.rc:dtD.rc, "Different error codes?"); } if ((dtN.ctrl & FLAG_AWAKEN) == (dtD.ctrl & FLAG_AWAKEN)) { /* The number of spurious wakeups is different */ output("Different spurious wakeups: N:%d D:%d\n", (dtN.ctrl & MASK_COUNTER) - 1, (dtD.ctrl & MASK_COUNTER) - 1); result = 0; /* We don't consider this as a fail case */ } } } } /* We can cleanup things now */ ret = pthread_cond_destroy(&cndN); if (ret != 0) { UNRESOLVED(ret, "Cond destroy failed"); } ret = pthread_cond_destroy(&cndD); if (ret != 0) { UNRESOLVED(ret, "Cond destroy failed"); } ret = pthread_condattr_destroy(&ca); if (ret != 0) { UNRESOLVED(ret, "Cond attr destroy failed"); } ret = pthread_mutex_destroy(&mtxN); if (ret != 0) { UNRESOLVED(ret, "Mutex destroy failed"); } ret = pthread_mutex_destroy(&mtxD); if (ret != 0) { UNRESOLVED(ret, "Mutex destroy failed"); } return result; } /**** * Main function */ int main(int argc, char * argv[]) { long opt_TMR, opt_CS; int ret=0; output_init(); #if VERBOSE > 1 output("Test starting...\n"); #endif opt_TMR=sysconf(_SC_TIMERS); opt_CS =sysconf(_SC_CLOCK_SELECTION); #if VERBOSE > 1 output("Timers option : %li\n", opt_TMR); output("Clock Selection option : %li\n", opt_CS); #endif if ((opt_TMR != -1L) && (opt_CS != -1L)) { #if VERBOSE > 0 output("Starting clock test\n"); #endif ret = do_cs_test(); } else { UNTESTED("This test requires unsupported features"); } if (ret != 0) { FAILED("The cond vars use different clocks."); } PASSED; } posixtestsuite/conformance/interfaces/pthread_cond_init/assertions.xml0100644000000000000000000000345407625366027025722 0ustar rootroot The function int pthread_cond_init(pthread_cond_t *restrict cond, const pthread_condattr_t *restrict attr); shall initialize the condition variable referenced by cond with attributes referenced by attr.If attr is NULL, the default condition variable attributes shall be used; the effect is the same as passing the address of a default condition variable attributes object. Upon successful initialization, the state of the condition variable shall become initialized. In cases where default condition variable attributes are appropriate, the macro PTHREAD_COND_INITIALIZER can be used to initialize condition variables that are statically allocated. The effect shall be equivalent to dynamic initialization by a call to pthread_cond_init() with parameter attr specified as NULL, except that no error checks are performed. If successful, the pthread_cond_init() function shall return zero; The pthread_cond_init() function shall fail if: [EAGAIN] The system lacked the necessary resources (other than memory) to initialize another condition variable. [ENOMEM] Insufficient memory exists to initialize the condition variable. The pthread_cond_init() function may fail if: [EBUSY] The implementation has detected an attempt to reinitialize the object referenced by cond, a previously initialized, but not yet destroyed, condition variable. [EINVAL] The value specified by attr is invalid. The function shall not return an error code of [EINTR]. posixtestsuite/conformance/interfaces/pthread_cond_init/coverage.txt0100644000000000000000000000052707650707666025346 0ustar rootrootThis document defines the coverage for the pthread_cond_init function: Assertion Tested? 1 YES 2 YES 3 YES 4 NO * Looking for a way to produce the error conditions * When it specifies it 'may' fail and not 'shall' fail, it will always return PASS, but will return a PASS and print out a warning if it fails. NOTE: posixtestsuite/conformance/interfaces/pthread_cond_init/testfrmw.h0100644000000000000000000000456210063535404025016 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * * This file is a wrapper to use the tests from the NPTL Test & Trace Project * with either the Linux Test Project or the Open POSIX Test Suite. * The following macros are defined here: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate without calling one of those macros. * * */ #include "posixtest.h" #include /* for the strerror() routine */ #ifdef __GNUC__ /* We are using GCC */ #define UNRESOLVED(x, s) \ { output("Test %s unresolved: got %i (%s) on line %i (%s)\n", __FILE__, x, strerror(x), __LINE__, s); \ output_fini(); \ exit(PTS_UNRESOLVED); } #define FAILED(s) \ { output("Test %s FAILED: %s\n", __FILE__, s); \ output_fini(); \ exit(PTS_FAIL); } #define PASSED \ output_fini(); \ exit(PTS_PASS); #define UNTESTED(s) \ { output("File %s cannot test: %s\n", __FILE__, s); \ output_fini(); \ exit(PTS_UNTESTED); \ } #else /* not using GCC */ #define UNRESOLVED(x, s) \ { output("Test unresolved: got %i (%s) on line %i (%s)\n", x, strerror(x), __LINE__, s); \ output_fini(); \ exit(PTS_UNRESOLVED); } #define FAILED(s) \ { output("Test FAILED: %s\n", s); \ output_fini(); \ exit(PTS_FAIL); } #define PASSED \ output_fini(); \ exit(PTS_PASS); #define UNTESTED(s) \ { output("Unable to test: %s\n", s); \ output_fini(); \ exit(PTS_UNTESTED); \ } #endif posixtestsuite/conformance/interfaces/pthread_cond_init/4-2.c0100644000000000000000000002050010063535404023426 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * * This sample test aims to check the following assertion: * The function does not return an error code of EINTR * The steps are: * * -> Create a thread which loops on pthread_cond_init and pthread_cond_destroy * operations. * -> Create another thread which loops on sending a signal to the first thread. * * */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /********************************************************************************************/ /****************************** standard includes *****************************************/ /********************************************************************************************/ #include #include #include #include #include #include #include #include /********************************************************************************************/ /****************************** Test framework *****************************************/ /********************************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /********************************************************************************************/ /********************************** Configuration ******************************************/ /********************************************************************************************/ #define WITH_SYNCHRO #ifndef VERBOSE #define VERBOSE 2 #endif /********************************************************************************************/ /*********************************** Test case *****************************************/ /********************************************************************************************/ char do_it=1; unsigned long count_ope=0; pthread_mutex_t count_protect = PTHREAD_MUTEX_INITIALIZER; #ifdef WITH_SYNCHRO sem_t semsig1; sem_t semsig2; unsigned long count_sig=0; #endif sem_t semsync; typedef struct { pthread_t *thr; int sig; #ifdef WITH_SYNCHRO sem_t *sem; #endif } thestruct; /* the following function keeps on sending the signal to the thread pointed by arg * If WITH_SYNCHRO is defined, the target thread has a handler for the signal */ void * sendsig (void * arg) { thestruct *thearg = (thestruct *) arg; int ret; while (do_it) { #ifdef WITH_SYNCHRO if ((ret = sem_wait(thearg->sem))) { UNRESOLVED(errno, "Sem_wait in sendsig"); } count_sig++; #endif if ((ret = pthread_kill (*(thearg->thr), thearg->sig))) { UNRESOLVED(ret, "Pthread_kill in sendsig"); } } return NULL; } /* Next are the signal handlers. */ void sighdl1(int sig) { #ifdef WITH_SYNCHRO if (sem_post(&semsig1)) { UNRESOLVED(errno, "Sem_post in signal handler 1"); } #endif } void sighdl2(int sig) { #ifdef WITH_SYNCHRO if (sem_post(&semsig2)) { UNRESOLVED(errno, "Sem_post in signal handler 2"); } #endif } /* The following function loops on init/destroy some condvars (with different attributes) * it does check that no error code of EINTR is returned */ void * threaded(void * arg) { pthread_condattr_t ca[4], *pca[5]; pthread_cond_t c[5]; int i; int ret; /* We need to register the signal handlers */ struct sigaction sa; sigemptyset (&sa.sa_mask); sa.sa_flags = 0; sa.sa_handler = sighdl1; if ((ret = sigaction (SIGUSR1, &sa, NULL))) { UNRESOLVED(ret, "Unable to register signal handler1"); } sa.sa_handler = sighdl2; if ((ret = sigaction (SIGUSR2, &sa, NULL))) { UNRESOLVED(ret, "Unable to register signal handler2"); } /* Initialize the different cond attributes */ pca[4]=NULL; for (i=0; i<4; i++) { pca[i]=&ca[i]; if ((ret = pthread_condattr_init(pca[i]))) { UNRESOLVED(ret, "pthread_condattr_init"); } } ret = pthread_condattr_setpshared(pca[0], PTHREAD_PROCESS_SHARED); if (ret != 0) { UNRESOLVED(ret, "Cond attribute PSHARED failed"); } ret = pthread_condattr_setpshared(pca[1], PTHREAD_PROCESS_SHARED); if (ret != 0) { UNRESOLVED(ret, "Cond attribute PSHARED failed"); } #if VERBOSE >1 output("PShared condvar attributes initialized\n"); #endif if (sysconf(_SC_MONOTONIC_CLOCK) > 0) { ret = pthread_condattr_setclock(pca[1], CLOCK_MONOTONIC); if (ret != 0) { UNRESOLVED(ret, "Cond set monotonic clock failed"); } ret = pthread_condattr_setclock(pca[2], CLOCK_MONOTONIC); if (ret != 0) { UNRESOLVED(ret, "Cond set monotonic clock failed"); } #if VERBOSE >1 output("Alternative clock condvar attributes initialized\n"); #endif } /* We are ready to proceed */ while (do_it) { for (i=0; i<5; i++) { ret = pthread_cond_init(&c[i], pca[i]); if (ret == EINTR) { FAILED("pthread_cond_init returned EINTR"); } if (ret != 0) { UNRESOLVED(ret, "pthread_cond_init failed"); } ret = pthread_cond_destroy(&c[i]); if (ret == EINTR) { FAILED("pthread_cond_destroy returned EINTR"); } if (ret != 0) { UNRESOLVED(ret, "pthread_cond_destroy failed"); } pthread_mutex_lock(&count_protect); count_ope++; pthread_mutex_unlock(&count_protect); } } /* Now we can destroy the mutex attributes objects */ for (i=0; i<4; i++) { if ((ret = pthread_condattr_destroy(pca[i]))) { UNRESOLVED(ret, "pthread_condattr_init"); } } do { ret = sem_wait(&semsync); } while (ret && (errno == EINTR)); if (ret) { UNRESOLVED(errno, "Could not wait for sig senders termination"); } return NULL; } /* Main function */ int main (int argc, char * argv[]) { int ret; pthread_t th_work, th_sig1, th_sig2; thestruct arg1, arg2; output_init(); #ifdef WITH_SYNCHRO if (sem_init(&semsig1, 0, 1)) { UNRESOLVED(errno, "Semsig1 init"); } if (sem_init(&semsig2, 0, 1)) { UNRESOLVED(errno, "Semsig2 init"); } #endif if (sem_init(&semsync, 0, 0)) { UNRESOLVED(errno, "semsync init"); } if ((ret = pthread_create(&th_work, NULL, threaded, NULL))) { UNRESOLVED(ret, "Worker thread creation failed"); } arg1.thr = &th_work; arg2.thr = &th_work; arg1.sig = SIGUSR1; arg2.sig = SIGUSR2; #ifdef WITH_SYNCHRO arg1.sem = &semsig1; arg2.sem = &semsig2; #endif if ((ret = pthread_create(&th_sig1, NULL, sendsig, (void *)&arg1))) { UNRESOLVED(ret, "Signal 1 sender thread creation failed"); } if ((ret = pthread_create(&th_sig2, NULL, sendsig, (void *)&arg2))) { UNRESOLVED(ret, "Signal 2 sender thread creation failed"); } /* Let's wait for a while now */ sleep(1); /* Now stop the threads and join them */ do { do_it=0; } while (do_it); if ((ret = pthread_join(th_sig1, NULL))) { UNRESOLVED(ret, "Signal 1 sender thread join failed"); } if ((ret = pthread_join(th_sig2, NULL))) { UNRESOLVED(ret, "Signal 2 sender thread join failed"); } if (sem_post(&semsync)) { UNRESOLVED(errno, "could not post semsync"); } if ((ret = pthread_join(th_work, NULL))) { UNRESOLVED(ret, "Worker thread join failed"); } #if VERBOSE > 0 output("Test executed successfully.\n"); output(" %d condvars initialization and destruction were done.\n", count_ope); #ifdef WITH_SYNCHRO output(" %d signals were sent meanwhile.\n", count_sig); #endif #endif PASSED; } posixtestsuite/conformance/interfaces/pthread_cond_init/2-1.c0100644000000000000000000000114207650707666023447 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: bing.wei.liu REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that the macro PTHREAD_COND_INITIALIZER can be used to intiailize * condition variables that are statically allocated. * */ #include #include #include #include "posixtest.h" pthread_cond_t cond = PTHREAD_COND_INITIALIZER; int main() { printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_cond_init/3-1.c0100644000000000000000000000263707650707666023462 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: bing.wei.liu REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_cond_init() * Upon succesful completion, it shall return a 0 * */ #include #include #include #include "posixtest.h" int main() { pthread_condattr_t condattr; pthread_cond_t cond; int rc; /* Initialize a cond attributes object */ if((rc=pthread_condattr_init(&condattr)) != 0) { fprintf(stderr,"Error at pthread_condattr_init(), rc=%d\n",rc); return PTS_UNRESOLVED; } /* Initialize a cond object with the default cond attributes */ if((rc=pthread_cond_init(&cond,&condattr)) == 0) { printf("Test PASSED\n"); return PTS_PASS; } /* Check if returned values are tolerable */ else if(rc == ENOMEM) { fprintf(stderr,"Insufficient memory to initialize the cond\n"); return PTS_UNRESOLVED; } else if(rc == EAGAIN) { fprintf(stderr,"Lack of the necessary resources to initilize the cond\n"); return PTS_UNRESOLVED; } else if(rc == EBUSY) { fprintf(stderr,"Detected an attemp to reinitilize a previously initilized cond\n"); return PTS_UNRESOLVED; } /* Any other returned value means the test failed */ else { printf("Test FAILED\n"); return PTS_FAIL; } } posixtestsuite/conformance/interfaces/pthread_condattr_destroy/0040755000000000000000000000000010515625207024412 5ustar rootrootposixtestsuite/conformance/interfaces/pthread_condattr_destroy/4-1.c0100644000000000000000000000216707650707554025076 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: bing.wei.liu REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test pthread_condattr_destroy() * If it fails, an error number shall be returned to indicate the error: * [EINVAL] The value specified by 'attr' is invalid * * Steps: * Try to destroy a NULL condition variable attributes object using pthread_condattr_destroy(). * If it returns EINVAL, the test passes. * */ #include #include #include #include "posixtest.h" int main() { pthread_condattr_t *condattr=NULL; int rc; /* Try to destroy a NULL condition variable attributes object using pthread_condattr_destroy() * It should return EINVAL */ if((rc=pthread_condattr_destroy(condattr)) == EINVAL) { printf("Test PASSED\n"); return PTS_PASS; } else { printf("Test PASSED: *NOTE: Expect %d(EINVAL), but return %d, though standard states 'may' fail\n", EINVAL, rc); return PTS_PASS; } } posixtestsuite/conformance/interfaces/pthread_condattr_destroy/1-1.c0100644000000000000000000000222707650707554025070 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: bing.wei.liu REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_condattr_destroy() * shall destroy a condition variable attributes object. * * Steps: * 1. Initialize a pthread_condattr_t object using pthread_condattr_init() * 2. Destroy the attributes object using pthread_condattr_destroy() * */ #include #include #include #include "posixtest.h" int main() { pthread_condattr_t condattr; int rc; /* Initialize a condition variable attributes object */ if((rc=pthread_condattr_init(&condattr)) != 0) { fprintf(stderr,"Cannot initialize condition variable attributes object\n"); return PTS_UNRESOLVED; } /* Destroy the condition variable attributes object */ if(pthread_condattr_destroy(&condattr) != 0) { fprintf(stderr,"Error at pthread_condattr_destroy(), rc=%d\n", rc); printf("Test FAILED\n"); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_condattr_destroy/assertions.xml0100644000000000000000000000162310117555064027326 0ustar rootroot The function int pthread_condattr_destroy(pthread_condattr_t *attr); shall destroy a condition variable attributes object; the object becomes, in effect, uninitialized. An implementation may cause pthread_condattr_destroy() to set the object referenced by attr to an invalid value. A destroyed attr attributes object can be reinitialized using pthread_condattr_init(); the results of otherwise referencing the object after it has been destroyed are undefined. If successful, it shall return zero; The pthread_condattr_destroy() function may fail if: [EINVAL] The value specified by attr is invalid. posixtestsuite/conformance/interfaces/pthread_condattr_destroy/coverage.txt0100644000000000000000000000052707650707554026763 0ustar rootrootThis document defines the coverage for the pthread_condattr_destroy function: Assertion Tested? 1 YES 2 YES 3 YES 4 YES ** Keeping in mind it 'may' fail and not 'shall' fail, so it will always return PASS, but will return a PASS and print out a warning if it fails. NOTE: posixtestsuite/conformance/interfaces/pthread_condattr_destroy/2-1.c0100644000000000000000000000307307650707554025071 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: bing.wei.liu REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test pthread_condattr_destroy() * A destroyed 'attr' attributes object can be reinitialized using * pthread_condattr_init(); the results of otherwise referencing the * object after it has been destroyed are undefined. * * Steps: * 1. Initialize a pthread_condattr_t object using pthread_condattr_init() * 2. Destroy that initialized attribute using pthread_condattr_destroy() * 3. Initialize the pthread_condattr_t object again. This should not result * in any error. * */ #include #include #include #include "posixtest.h" int main() { pthread_condattr_t condattr; /* Initialize a condition variable attributes object */ if(pthread_condattr_init(&condattr) != 0) { fprintf(stderr,"Cannot initialize condition variable attributes object\n"); return PTS_UNRESOLVED; } /* Destroy the condition variable attributes object */ if(pthread_condattr_destroy(&condattr) != 0) { fprintf(stderr,"Cannot destroy the condition variable attributes object\n"); return PTS_UNRESOLVED; } /* Initialize the condition variable attributes object again. This shouldn't result in an error. */ if(pthread_condattr_init(&condattr) != 0) { printf("Test FAILED\n"); return PTS_FAIL; } else { printf("Test PASSED\n"); return PTS_PASS; } } posixtestsuite/conformance/interfaces/pthread_condattr_destroy/3-1.c0100644000000000000000000000222007650707554025063 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: bing.wei.liu REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test pthread_condattr_destroy() * Upon successful completion, pthread_condattr_destroy() shall * return a value of 0. * * Steps: * 1. Initialize a pthread_condattr_t object using pthread_condattr_init() * 2. Destroy that initialized attribute using pthread_condattr_destroy(). * This should return 0; * */ #include #include #include #include "posixtest.h" int main() { pthread_condattr_t condattr; /* Initialize a condition variable attributes object */ if(pthread_condattr_init(&condattr) != 0) { fprintf(stderr,"Cannot initialize condition variable attributes object\n"); return PTS_UNRESOLVED; } /* Destroy the condition variable attributes object */ if(pthread_condattr_destroy(&condattr) != 0) { printf("Test FAILED\n"); return PTS_FAIL; } else { printf("Test PASSED\n"); return PTS_PASS; } } posixtestsuite/conformance/interfaces/pthread_attr_getstacksize/0040755000000000000000000000000010515625177024563 5ustar rootrootposixtestsuite/conformance/interfaces/pthread_attr_getstacksize/1-1.c0100644000000000000000000000422110061223267025207 0ustar rootroot/* * Copyright (c) 2004, Intel Corporation. All rights reserved. * Created by: crystal.xiong REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test pthread_attr_getstacksize() * * Steps: * 1. Initialize pthread_attr_t object (attr) * 2. set the stacksize to attr * 3. get the stacksize */ #include #include #include #include #include #include #include #include #include "posixtest.h" #define TEST "1-1" #define FUNCTION "pthread_attr_getstacksize" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " int main() { pthread_attr_t attr; size_t stack_size; size_t ssize; void *saddr; int rc; /* Initialize attr */ rc = pthread_attr_init(&attr); if( rc != 0) { perror(ERROR_PREFIX "pthread_attr_init"); exit(PTS_UNRESOLVED); } /* Get the default stack_addr and stack_size value */ rc = pthread_attr_getstacksize(&attr, &stack_size); if( rc != 0) { perror(ERROR_PREFIX "pthread_attr_getstacksize"); exit(PTS_UNRESOLVED); } /* printf("stack_size = %lu\n", stack_size); */ stack_size = PTHREAD_STACK_MIN; if (posix_memalign (&saddr, sysconf(_SC_PAGE_SIZE), stack_size) != 0) { perror (ERROR_PREFIX "out of memory while " "allocating the stack memory"); exit(PTS_UNRESOLVED); } /* printf("stack_size = %lu\n", stack_size); */ rc = pthread_attr_setstacksize(&attr, stack_size); if (rc != 0 ) { perror(ERROR_PREFIX "pthread_attr_setstacksize"); exit(PTS_UNRESOLVED); } rc = pthread_attr_getstacksize(&attr, &ssize); if (rc != 0 ) { perror(ERROR_PREFIX "pthread_attr_getstacksize"); exit(PTS_UNRESOLVED); } /* printf("ssize = %lu\n", ssize); */ rc = pthread_attr_destroy(&attr); if(rc != 0) { perror(ERROR_PREFIX "pthread_attr_destroy"); exit(PTS_UNRESOLVED); } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_attr_getstacksize/assertions.xml0100644000000000000000000000064010031752412027456 0ustar rootroot The pthread_attr_getstacksize() shall get the thread creation stacksize attributes stacksize in the attr ojbect. If success, it returns zero. Shall not return an error code of [EINTR] posixtestsuite/conformance/interfaces/pthread_attr_getstacksize/coverage.txt0100644000000000000000000000021010031752412027067 0ustar rootrootThis document defines the coverage for the pthread_attr_getstacksize function: Assertion Tested? 1 YES 2 YES 3 won't test Note: posixtestsuite/conformance/interfaces/pthread_attr_getstacksize/2-1.sh0100755000000000000000000000071010031752412025376 0ustar rootroot #!/bin/sh # Copyright (c) 2004, Intel Corporation. All rights reserved. # Created by: crystal.xiong REMOVE-THIS AT intel DOT com # This file is licensed under the GPL license. For the full content # of this license, see the COPYING file at the top level of this # source tree. # Test pthread_attr_getstack returns 0 on success. # This is tested implicitly via assertion 1. echo "Tested implicitly via assertion 1. See output for status" exit 0 posixtestsuite/conformance/interfaces/pthread_mutex_trylock/0040755000000000000000000000000010515625220023727 5ustar rootrootposixtestsuite/conformance/interfaces/pthread_mutex_trylock/4-1.c0100644000000000000000000000233107621016157024377 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: bing.wei.liu REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_mutex_trylock() * Upon failure, it shall return: * -[EBUSY] The mutex could not be acquired because it was already locked. * Steps: * -- Initilize a mutex object * -- Lock the mutex using pthread_mutex_lock() * -- Try to lock the mutex using pthread_mutex_trylock() and expect EBUSY * */ #include #include #include #include "posixtest.h" pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; int main() { int rc; if((rc=pthread_mutex_lock(&mutex))!=0) { fprintf(stderr,"Error at pthread_mutex_lock(), rc=%d\n",rc); return PTS_UNRESOLVED; } rc = pthread_mutex_trylock(&mutex); if(rc!=EBUSY) { fprintf(stderr,"Expected %d(EBUSY), got %d\n",EBUSY,rc); printf("Test FAILED\n"); return PTS_FAIL; } pthread_mutex_unlock(&mutex); pthread_mutex_destroy(&mutex); printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_mutex_trylock/1-1.c0100644000000000000000000000513107621016157024375 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: bing.wei.liu REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_mutex_trylock() * is equivalent to pthread_mutex_lock() except that if the mutex object * referenced by 'mutex' is currently locked (by any thread, including the * current thread), the call shall return immediately. * Steps: * -- Initilize a mutex object * -- Create a secondary thread and have it lock the mutex * -- Within the main thread, try to lock the mutex using pthread_mutex_trylock() and EBUSY is expected * -- Have the secondary thread unlock the mutex * -- Within the main thread, try to lock the mutex again and expect a successful locking. * */ #include #include #include #include #include "posixtest.h" void *func(void *parm); pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; int t1_start=0; int t1_pause=1; int main() { int i, rc; pthread_t t1; /* Create a secondary thread and wait until it has locked the mutex */ pthread_create(&t1, NULL, func, NULL); while(!t1_start) sleep(1); /* Trylock the mutex and expect it returns EBUSY */ rc = pthread_mutex_trylock(&mutex); if(rc!=EBUSY) { fprintf(stderr,"Expected %d(EBUSY), got %d\n",EBUSY,rc); printf("Test FAILED\n"); return PTS_FAIL; } /* Allow the secondary thread to go ahead */ t1_pause=0; /* Trylock the mutex for N times */ for(i=0; i<5; i++) { rc = pthread_mutex_trylock(&mutex); if(rc==0) { pthread_mutex_unlock(&mutex); break; } else if(rc==EBUSY) { sleep(1); continue; } else { fprintf(stderr,"Unexpected error code(%d) for pthread_mutex_lock()\n", rc); return PTS_UNRESOLVED; } } /* Clean up */ pthread_join(t1, NULL); pthread_mutex_destroy(&mutex); if(i>=5) { fprintf(stderr,"Have tried %d times but failed to get the mutex\n", i); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } void *func(void *parm) { int rc; if((rc=pthread_mutex_lock(&mutex))!=0) { fprintf(stderr,"Error at pthread_mutex_lock(), rc=%d\n",rc); pthread_exit((void*)PTS_UNRESOLVED); } t1_start=1; while(t1_pause) sleep(1); if((rc=pthread_mutex_unlock(&mutex))!=0) { fprintf(stderr,"Error at pthread_mutex_unlock(), rc=%d\n",rc); pthread_exit((void*)PTS_UNRESOLVED); } pthread_exit(0); return (void*)(0); } posixtestsuite/conformance/interfaces/pthread_mutex_trylock/testfrmw.c0100644000000000000000000000407210123572052025745 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * * This file is a wrapper to use the tests from the NPTL Test & Trace Project * with either the Linux Test Project or the Open POSIX Test Suite. * The following function are defined: * void output_init() * void output_fini() * void output(char * string, ...) * * The are used to output informative text (as a printf). */ #include #include /* We use a mutex to avoid conflicts in traces */ static pthread_mutex_t m_trace = PTHREAD_MUTEX_INITIALIZER; /*****************************************************************************************/ /******************************* stdout module *****************************************/ /*****************************************************************************************/ /* The following functions will output to stdout */ #if (1) void output_init() { /* do nothing */ return; } void output( char * string, ... ) { va_list ap; char *ts="[??:??:??]"; struct tm * now; time_t nw; pthread_mutex_lock(&m_trace); nw = time(NULL); now = localtime(&nw); if (now == NULL) printf(ts); else printf("[%2.2d:%2.2d:%2.2d]", now->tm_hour, now->tm_min, now->tm_sec); va_start( ap, string); vprintf(string, ap); va_end(ap); pthread_mutex_unlock(&m_trace); } void output_fini() { /*do nothing */ return; } #endif posixtestsuite/conformance/interfaces/pthread_mutex_trylock/4-3.c0100644000000000000000000002455410123571761024412 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertion: * * The function does not return EINTR * The steps are: * -> A thread is killed several times while calling pthread_mutex_trylock * -> check that EINTR is never returned */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /* We need the XSI extention for the mutex attributes and the mkstemp() routine */ #ifndef WITHOUT_XOPEN #define _XOPEN_SOURCE 600 #endif /********************************************************************************************/ /****************************** standard includes *****************************************/ /********************************************************************************************/ #include #include #include #include #include #include #include #include /********************************************************************************************/ /****************************** Test framework *****************************************/ /********************************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /********************************************************************************************/ /********************************** Configuration ******************************************/ /********************************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif #define WITH_SYNCHRO /********************************************************************************************/ /*********************************** Test case *****************************************/ /********************************************************************************************/ struct _scenar { int m_type; /* Mutex type to use */ int m_pshared; /* 0: mutex is process-private (default) ~ !0: mutex is process-shared, if supported */ char * descr; /* Case description */ } scenarii[] = { {PTHREAD_MUTEX_DEFAULT, 0, "Default mutex"} #ifndef WITHOUT_XOPEN ,{PTHREAD_MUTEX_NORMAL, 0, "Normal mutex"} ,{PTHREAD_MUTEX_ERRORCHECK, 0, "Errorcheck mutex"} ,{PTHREAD_MUTEX_RECURSIVE, 0, "Recursive mutex"} #endif ,{PTHREAD_MUTEX_DEFAULT, 1, "Pshared mutex"} #ifndef WITHOUT_XOPEN ,{PTHREAD_MUTEX_NORMAL, 1, "Pshared Normal mutex"} ,{PTHREAD_MUTEX_ERRORCHECK, 1, "Pshared Errorcheck mutex"} ,{PTHREAD_MUTEX_RECURSIVE, 1, "Pshared Recursive mutex"} #endif }; #define NSCENAR (sizeof(scenarii)/sizeof(scenarii[0])) char do_it=1; char woken=0; unsigned long count_ope=0; #ifdef WITH_SYNCHRO sem_t semsig1; sem_t semsig2; unsigned long count_sig=0; #endif sigset_t usersigs; typedef struct { int sig; #ifdef WITH_SYNCHRO sem_t *sem; #endif } thestruct; /* the following function keeps on sending the signal to the process */ void * sendsig (void * arg) { thestruct *thearg = (thestruct *) arg; int ret; pid_t process; process=getpid(); /* We block the signals SIGUSR1 and SIGUSR2 for this THREAD */ ret = pthread_sigmask(SIG_BLOCK, &usersigs, NULL); if (ret != 0) { UNRESOLVED(ret, "Unable to block SIGUSR1 and SIGUSR2 in signal thread"); } while (do_it) { #ifdef WITH_SYNCHRO if ((ret = sem_wait(thearg->sem))) { UNRESOLVED(errno, "Sem_wait in sendsig"); } count_sig++; #endif ret = kill(process, thearg->sig); if (ret != 0) { UNRESOLVED(errno, "Kill in sendsig"); } } return NULL; } /* Next are the signal handlers. */ /* This one is registered for signal SIGUSR1 */ void sighdl1(int sig) { #ifdef WITH_SYNCHRO if (sem_post(&semsig1)) { UNRESOLVED(errno, "Sem_post in signal handler 1"); } #endif } /* This one is registered for signal SIGUSR2 */ void sighdl2(int sig) { #ifdef WITH_SYNCHRO if (sem_post(&semsig2)) { UNRESOLVED(errno, "Sem_post in signal handler 2"); } #endif } /* Test function -- This one calls pthread_mutex_trylock and check that no EINTR is returned. */ void * test(void * arg) { int ret=0; int i; long pshared; pthread_mutex_t mtx[NSCENAR+2]; pthread_mutexattr_t ma[NSCENAR+1]; /* We don't block the signals SIGUSR1 and SIGUSR2 for this THREAD */ ret = pthread_sigmask(SIG_UNBLOCK, &usersigs, NULL); if (ret != 0) { UNRESOLVED(ret, "Unable to unblock SIGUSR1 and SIGUSR2 in worker thread"); } /* System abilities */ pshared = sysconf(_SC_THREAD_PROCESS_SHARED); /* Initialize the mutex objects according to the scenarii */ for (i=0; i 0) && (scenarii[i].m_pshared != 0)) { ret = pthread_mutexattr_setpshared(&ma[i], PTHREAD_PROCESS_SHARED); if (ret != 0) { UNRESOLVED(ret, "[parent] Unable to set the mutex process-shared"); } } /* Initialize the mutex */ ret = pthread_mutex_init(&mtx[i], &ma[i]); if (ret != 0) { UNRESOLVED(ret, "[parent] Mutex init failed"); } } /* Default mutexattr object */ ret = pthread_mutexattr_init(&ma[i]); if (ret != 0) { UNRESOLVED(ret, "[parent] Unable to initialize the mutex attribute object"); } ret = pthread_mutex_init(&mtx[i], &ma[i]); if (ret != 0) { UNRESOLVED(ret, "[parent] Mutex init failed"); } /* Default mutex */ ret = pthread_mutex_init(&mtx[i+1], NULL); if (ret != 0) { UNRESOLVED(ret, "[parent] Mutex init failed"); } /* do the real testing */ while (do_it) { count_ope++; ret = pthread_mutex_trylock(&mtx[count_ope % (NSCENAR+2)]); if (ret == EINTR) { FAILED("EINTR was returned"); } if (ret != 0) { UNRESOLVED(ret, "1st trylock failed"); } ret = pthread_mutex_trylock(&mtx[count_ope % (NSCENAR+2)]); if (ret == EINTR) { FAILED("EINTR was returned"); } if (ret == 0) { ret = pthread_mutex_unlock(&mtx[count_ope % (NSCENAR+2)]); if (ret != 0) { UNRESOLVED(ret, "Unlocking the mutex failed"); } ret = EBUSY; } if (ret != EBUSY) { UNRESOLVED(ret, "Unexpected error was returned."); } ret = pthread_mutex_unlock(&mtx[count_ope % (NSCENAR+2)]); if (ret != 0) { UNRESOLVED(ret, "Failed to unlock the mutex"); } } /* Destroy everything */ for (i=0; i <= NSCENAR; i++) { ret = pthread_mutex_destroy(&mtx[i]); if (ret != 0) { UNRESOLVED(ret, "Failed to destroy the mutex"); } ret = pthread_mutexattr_destroy(&ma[i]); if (ret != 0) { UNRESOLVED(ret, "Failed to destroy the mutex attr object"); } } ret = pthread_mutex_destroy(&mtx[i]); if (ret != 0) { UNRESOLVED(ret, "Failed to destroy the mutex"); } return NULL; } /* Main function */ int main (int argc, char * argv[]) { int ret; pthread_t th_work, th_sig1, th_sig2; thestruct arg1, arg2; struct sigaction sa; /* Initialize output routine */ output_init(); /* We need to register the signal handlers for the PROCESS */ sigemptyset (&sa.sa_mask); sa.sa_flags = 0; sa.sa_handler = sighdl1; if ((ret = sigaction (SIGUSR1, &sa, NULL))) { UNRESOLVED(ret, "Unable to register signal handler1"); } sa.sa_handler = sighdl2; if ((ret = sigaction (SIGUSR2, &sa, NULL))) { UNRESOLVED(ret, "Unable to register signal handler2"); } /* We prepare a signal set which includes SIGUSR1 and SIGUSR2 */ sigemptyset(&usersigs); ret = sigaddset(&usersigs, SIGUSR1); ret |= sigaddset(&usersigs, SIGUSR2); if (ret != 0) { UNRESOLVED(ret, "Unable to add SIGUSR1 or 2 to a signal set"); } /* We now block the signals SIGUSR1 and SIGUSR2 for this THREAD */ ret = pthread_sigmask(SIG_BLOCK, &usersigs, NULL); if (ret != 0) { UNRESOLVED(ret, "Unable to block SIGUSR1 and SIGUSR2 in main thread"); } #ifdef WITH_SYNCHRO if (sem_init(&semsig1, 0, 1)) { UNRESOLVED(errno, "Semsig1 init"); } if (sem_init(&semsig2, 0, 1)) { UNRESOLVED(errno, "Semsig2 init"); } #endif if ((ret = pthread_create(&th_work, NULL, test, NULL))) { UNRESOLVED(ret, "Worker thread creation failed"); } arg1.sig = SIGUSR1; arg2.sig = SIGUSR2; #ifdef WITH_SYNCHRO arg1.sem = &semsig1; arg2.sem = &semsig2; #endif if ((ret = pthread_create(&th_sig1, NULL, sendsig, (void *)&arg1))) { UNRESOLVED(ret, "Signal 1 sender thread creation failed"); } if ((ret = pthread_create(&th_sig2, NULL, sendsig, (void *)&arg2))) { UNRESOLVED(ret, "Signal 2 sender thread creation failed"); } /* Let's wait for a while now */ sleep(1); /* Now stop the threads and join them */ do { do_it=0; } while (do_it); if ((ret = pthread_join(th_sig1, NULL))) { UNRESOLVED(ret, "Signal 1 sender thread join failed"); } if ((ret = pthread_join(th_sig2, NULL))) { UNRESOLVED(ret, "Signal 2 sender thread join failed"); } if ((ret = pthread_join(th_work, NULL))) { UNRESOLVED(ret, "Worker thread join failed"); } #if VERBOSE > 0 output("Test executed successfully.\n"); output(" %d mutex locks.\n", count_ope); #ifdef WITH_SYNCHRO output(" %d signals were sent meanwhile.\n", count_sig); #endif #endif PASSED; } posixtestsuite/conformance/interfaces/pthread_mutex_trylock/1-2.c0100644000000000000000000003013110310264253024363 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertion: * * The pthread_mutex_trylock() function locks the mutex object * when it is unlocked. * The steps are: * * -> For each kind of mutex, * -> trylock the mutex. It shall suceed. * -> trylock the mutex again. It shall fail (except in case of recursive mutex). * -> create a new child (either thread or process) * -> the new child trylock the mutex. It shall fail. * -> undo everything. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /* We need the XSI extention for the mutex attributes and the mkstemp() routine */ #ifndef WITHOUT_XOPEN #define _XOPEN_SOURCE 600 #endif /********************************************************************************************/ /****************************** standard includes *****************************************/ /********************************************************************************************/ #include #include #include #include #include #include #include #include #include /********************************************************************************************/ /****************************** Test framework *****************************************/ /********************************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /********************************************************************************************/ /********************************** Configuration ******************************************/ /********************************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif /********************************************************************************************/ /*********************************** Test case *****************************************/ /********************************************************************************************/ typedef struct { pthread_mutex_t mtx; int status; /* error code */ } testdata_t; struct _scenar { int m_type; /* Mutex type to use */ int m_pshared; /* 0: mutex is process-private (default) ~ !0: mutex is process-shared, if supported */ int fork; /* 0: Test between threads. ~ !0: Test across processes, if supported (mmap) */ char * descr; /* Case description */ } scenarii[] = { {PTHREAD_MUTEX_DEFAULT, 0, 0, "Default mutex"} #ifndef WITHOUT_XOPEN ,{PTHREAD_MUTEX_NORMAL, 0, 0, "Normal mutex"} ,{PTHREAD_MUTEX_ERRORCHECK, 0, 0, "Errorcheck mutex"} ,{PTHREAD_MUTEX_RECURSIVE, 0, 0, "Recursive mutex"} #endif ,{PTHREAD_MUTEX_DEFAULT, 1, 0, "Pshared mutex"} #ifndef WITHOUT_XOPEN ,{PTHREAD_MUTEX_NORMAL, 1, 0, "Pshared Normal mutex"} ,{PTHREAD_MUTEX_ERRORCHECK, 1, 0, "Pshared Errorcheck mutex"} ,{PTHREAD_MUTEX_RECURSIVE, 1, 0, "Pshared Recursive mutex"} #endif ,{PTHREAD_MUTEX_DEFAULT, 1, 1, "Pshared mutex across processes"} #ifndef WITHOUT_XOPEN ,{PTHREAD_MUTEX_NORMAL, 1, 1, "Pshared Normal mutex across processes"} ,{PTHREAD_MUTEX_ERRORCHECK, 1, 1, "Pshared Errorcheck mutex across processes"} ,{PTHREAD_MUTEX_RECURSIVE, 1, 1, "Pshared Recursive mutex across processes"} #endif }; #define NSCENAR (sizeof(scenarii)/sizeof(scenarii[0])) /* The test function will only perform a trylock operation then return. */ void * tf(void * arg) { testdata_t * td = (testdata_t *)arg; td->status = pthread_mutex_trylock(&(td->mtx)); if (td->status == 0) { int ret; ret = pthread_mutex_unlock(&(td->mtx)); if (ret != 0) { UNRESOLVED(ret, "Failed to unlock a locked semaphore"); } } return NULL; } /* Main entry point. */ int main(int argc, char * argv[]) { int ret; int sc; pthread_mutexattr_t ma; testdata_t * td; testdata_t alternativ; int do_fork; pid_t child_pr=0, chkpid; int status; pthread_t child_th; long pshared, mf; /* Initialize output */ output_init(); /* Test system abilities */ pshared = sysconf(_SC_THREAD_PROCESS_SHARED); mf =sysconf(_SC_MAPPED_FILES); #if VERBOSE > 0 output("Test starting\n"); output("System abilities:\n"); output(" TSH : %li\n", pshared); output(" MF : %li\n", mf); if ((mf < 0) || (pshared < 0)) output("Process-shared attributes won't be tested\n"); #endif #ifdef WITHOUT_XOPEN #if VERBOSE > 0 output("As XSI extension is disabled, we won't test the feature across process\n"); #endif mf = -1; #endif /********** * Allocate space for the testdata structure */ if (mf < 0) { /* Cannot mmap a file (or not interested in this), we use an alternative method */ td = &alternativ; pshared = -1; /* We won't do this testing anyway */ #if VERBOSE > 0 output("Testdata allocated in the process memory.\n"); #endif } #ifndef WITHOUT_XOPEN else { /* We will place the test data in a mmaped file */ char filename[] = "/tmp/mutex_trylock_1-2-XXXXXX"; size_t sz; void * mmaped; int fd; char * tmp; /* We now create the temp files */ fd = mkstemp(filename); if (fd == -1) { UNRESOLVED(errno, "Temporary file could not be created"); } /* and make sure the file will be deleted when closed */ unlink(filename); #if VERBOSE > 1 output("Temp file created (%s).\n", filename); #endif sz= (size_t)sysconf(_SC_PAGESIZE); tmp = calloc(1, sz); if (tmp == NULL) { UNRESOLVED(errno, "Memory allocation failed"); } /* Write the data to the file. */ if (write (fd, tmp, sz) != (ssize_t) sz) { UNRESOLVED(sz, "Writting to the file failed"); } free(tmp); /* Now we can map the file in memory */ mmaped = mmap(NULL, sz, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); if (mmaped == MAP_FAILED) { UNRESOLVED(errno, "mmap failed"); } td = (testdata_t *) mmaped; /* Our datatest structure is now in shared memory */ #if VERBOSE > 1 output("Testdata allocated in shared memory.\n"); #endif } #endif /********** * For each test scenario, initialize the attributes and other variables. * Do the whole thing for each time to test. */ for ( sc=0; sc < NSCENAR ; sc++) { #if VERBOSE > 1 output("[parent] Preparing attributes for: %s\n", scenarii[sc].descr); #endif /* set / reset everything */ do_fork=0; ret = pthread_mutexattr_init(&ma); if (ret != 0) { UNRESOLVED(ret, "[parent] Unable to initialize the mutex attribute object"); } #ifndef WITHOUT_XOPEN /* Set the mutex type */ ret = pthread_mutexattr_settype(&ma, scenarii[sc].m_type); if (ret != 0) { UNRESOLVED(ret, "[parent] Unable to set mutex type"); } #if VERBOSE > 1 output("[parent] Mutex type : %i\n", scenarii[sc].m_type); #endif #endif /* Set the pshared attributes, if supported */ if ((pshared > 0) && (scenarii[sc].m_pshared != 0)) { ret = pthread_mutexattr_setpshared(&ma, PTHREAD_PROCESS_SHARED); if (ret != 0) { UNRESOLVED(ret, "[parent] Unable to set the mutex process-shared"); } #if VERBOSE > 1 output("[parent] Mutex is process-shared\n"); #endif } #if VERBOSE > 1 else { output("[parent] Mutex is process-private\n"); } #endif /* Tell whether the test will be across processes */ if ((pshared > 0) && (scenarii[sc].fork != 0)) { do_fork = 1; #if VERBOSE > 1 output("[parent] Child will be a new process\n"); #endif } #if VERBOSE > 1 else { output("[parent] Child will be a new thread\n"); } #endif /********** * Initialize the testdata_t structure with the previously defined attributes */ /* Initialize the mutex */ ret = pthread_mutex_init(&(td->mtx), &ma); if (ret != 0) { UNRESOLVED(ret, "[parent] Mutex init failed"); } /* Initialize the other datas from the test structure */ td->status=0; /********** * Proceed to the actual testing */ /* Trylock the mutex twice before creating children */ ret = pthread_mutex_trylock(&(td->mtx)); if (ret != 0) { UNRESOLVED(ret, "[parent] Unable to trylock the mutex"); } ret = pthread_mutex_trylock(&(td->mtx)); #ifndef WITHOUT_XOPEN if (scenarii[sc].m_type == PTHREAD_MUTEX_RECURSIVE) { if (ret != 0) { UNRESOLVED(ret, "Failed to pthread_mutex_trylock() twice a recursive mutex"); } /* Unlock once so the count is "1" */ ret = pthread_mutex_unlock(&(td->mtx)); if (ret != 0) { UNRESOLVED(ret, "Failed to unlock the mutex"); } } else #endif if (ret == 0) { FAILED("Main was able to pthread_mutex_trylock() twice without error"); } /* Create the children */ if (do_fork != 0) { /* We are testing across processes */ child_pr = fork(); if (child_pr == -1) { UNRESOLVED(errno, "[parent] Fork failed"); } if (child_pr == 0) { #if VERBOSE > 3 output("[child] Child process is starting...\n"); #endif if (tf((void *)td) != NULL) { UNRESOLVED( -1, "[child] Got an unexpected return value from test function"); } else { /* We cannot use the PASSED macro here since it would terminate the output */ exit (0); } } /* Only the parent process goes further */ } else /* do_fork == 0 */ { /* We are testing across two threads */ ret = pthread_create(&child_th, NULL, tf, td); if (ret != 0) { UNRESOLVED(ret, "[parent] Unable to create the child thread."); } } /* Wait for the child to terminate */ if (do_fork != 0) { /* We were testing across processes */ ret = 0; chkpid = waitpid(child_pr, &status, 0); if (chkpid != child_pr) { output("Expected pid: %i. Got %i\n", (int)child_pr, (int)chkpid); UNRESOLVED(errno, "Waitpid failed"); } if (WIFSIGNALED(status)) { output("Child process killed with signal %d\n",WTERMSIG(status)); UNRESOLVED( -1 , "Child process was killed"); } if (WIFEXITED(status)) { ret = WEXITSTATUS(status); } else { UNRESOLVED( -1, "Child process was neither killed nor exited"); } if (ret != 0) { exit(ret); /* Output has already been closed in child */ } } else /* child was a thread */ { ret = pthread_join(child_th, NULL); if (ret != 0) { UNRESOLVED(ret, "[parent] Unable to join the thread"); } } /* Check the child status */ if (td->status != EBUSY) { output("Unexpected return value: %d (%s)\n", td->status, strerror(td->status)); FAILED("pthread_mutex_trylock() did not return EBUSY in the child"); } /* Unlock the mutex */ ret= pthread_mutex_unlock(&(td->mtx)); if (ret != 0) { UNRESOLVED(ret, "Failed to unlock the mutex"); } /********** * Destroy the data */ ret = pthread_mutex_destroy(&(td->mtx)); if (ret != 0) { UNRESOLVED(ret, "Failed to destroy the mutex"); } ret = pthread_mutexattr_destroy(&ma); if (ret != 0) { UNRESOLVED(ret, "Failed to destroy the mutex attribute object"); } } /* Proceed to the next scenario */ #if VERBOSE > 0 output("Test passed\n"); #endif PASSED; } posixtestsuite/conformance/interfaces/pthread_mutex_trylock/assertions.xml0100644000000000000000000000237507621016157026656 0ustar rootroot The function int pthread_mutex_trylock(pthread_mutex_t *mutex); is equivalent to pthread_mutex_lock() except that if the mutex object referenced by 'mutex' is currently locked (by any thread, including the current thread), the call returns immediately. If the mutex type is PTHREAD_MUTEX_RECURSIVE and the mutex is currently owned by the calling thread, the mutex lock count shall be incremented by one and the pthread_mutex_trylock() function immediately returns success. It returns 0 if a lock on the mutex object referenced by 'mutex' is acquired. Upon failure, it shall return: -[EINVAL] The mutex was created with the protocol attribute PTHREAD_PRIO_PROTECT and the calling thread's priority is higher than the mutex's current priority calling. -[EBUSY] The mutex could not be acquired because it was already locked. It may fail if: -[EINVAL] 'mutex' does not refer to an initialized mutex object It shall not return [EINTR]. posixtestsuite/conformance/interfaces/pthread_mutex_trylock/coverage.txt0100644000000000000000000000101007622322730026255 0ustar rootrootThis document defines the coverage for the pthread_mutex_trylock function: Assertion Tested? 1 YES 2 NO * PTHREAD_MUTEX_RECURSIVE is a new XSI feature, which may not be available in pthread implementations 3 YES 4 YES * EINVAL and EAGAIN are relevant to low-priority mutex attributes, which cannot be tested by now * When it specifies it 'may' fail and not 'shall' fail, it will always return PASS, but will return a PASS and print out a warning if it fails. NOTE: posixtestsuite/conformance/interfaces/pthread_mutex_trylock/testfrmw.h0100644000000000000000000000456410123572052025760 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * * This file is a wrapper to use the tests from the NPTL Test & Trace Project * with either the Linux Test Project or the Open POSIX Test Suite. * The following macros are defined here: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate without calling one of those macros. * * */ #include "posixtest.h" #include /* for the strerror() routine */ #ifdef __GNUC__ /* We are using GCC */ #define UNRESOLVED(x, s) \ { output("Test %s unresolved: got %i (%s) on line %i (%s)\n", __FILE__, x, strerror(x), __LINE__, s); \ output_fini(); \ exit(PTS_UNRESOLVED); } #define FAILED(s) \ { output("Test %s FAILED: %s\n", __FILE__, s); \ output_fini(); \ exit(PTS_FAIL); } #define PASSED \ output_fini(); \ exit(PTS_PASS); #define UNTESTED(s) \ { output("File %s cannot test: %s\n", __FILE__, s); \ output_fini(); \ exit(PTS_UNTESTED); \ } #else /* not using GCC */ #define UNRESOLVED(x, s) \ { output("Test unresolved: got %i (%s) on line %i (%s)\n", x, strerror(x), __LINE__, s); \ output_fini(); \ exit(PTS_UNRESOLVED); } #define FAILED(s) \ { output("Test FAILED: %s\n", s); \ output_fini(); \ exit(PTS_FAIL); } #define PASSED \ output_fini(); \ exit(PTS_PASS); #define UNTESTED(s) \ { output("Unable to test: %s\n", s); \ output_fini(); \ exit(PTS_UNTESTED); \ } #endif posixtestsuite/conformance/interfaces/pthread_mutex_trylock/4-2.c0100644000000000000000000002704110310244154024372 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertion: * * If the mutex was already locked, the call returns EBUSY immediatly. * The steps are: * -> Set a timeout. * -> For each kind of mutex, * -> Lock the mutex. * -> create a new child (either thread or process) * -> the new child trylock the mutex. It shall fail. * -> undo everything. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /* We need the XSI extention for the mutex attributes and the mkstemp() routine */ #ifndef WITHOUT_XOPEN #define _XOPEN_SOURCE 600 #endif /********************************************************************************************/ /****************************** standard includes *****************************************/ /********************************************************************************************/ #include #include #include #include #include #include #include #include #include /********************************************************************************************/ /****************************** Test framework *****************************************/ /********************************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /********************************************************************************************/ /********************************** Configuration ******************************************/ /********************************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif /********************************************************************************************/ /*********************************** Test case *****************************************/ /********************************************************************************************/ typedef struct { pthread_mutex_t mtx; int status; /* error code */ } testdata_t; struct _scenar { int m_type; /* Mutex type to use */ int m_pshared; /* 0: mutex is process-private (default) ~ !0: mutex is process-shared, if supported */ int fork; /* 0: Test between threads. ~ !0: Test across processes, if supported (mmap) */ char * descr; /* Case description */ } scenarii[] = { {PTHREAD_MUTEX_DEFAULT, 0, 0, "Default mutex"} #ifndef WITHOUT_XOPEN ,{PTHREAD_MUTEX_NORMAL, 0, 0, "Normal mutex"} ,{PTHREAD_MUTEX_ERRORCHECK, 0, 0, "Errorcheck mutex"} ,{PTHREAD_MUTEX_RECURSIVE, 0, 0, "Recursive mutex"} #endif ,{PTHREAD_MUTEX_DEFAULT, 1, 0, "Pshared mutex"} #ifndef WITHOUT_XOPEN ,{PTHREAD_MUTEX_NORMAL, 1, 0, "Pshared Normal mutex"} ,{PTHREAD_MUTEX_ERRORCHECK, 1, 0, "Pshared Errorcheck mutex"} ,{PTHREAD_MUTEX_RECURSIVE, 1, 0, "Pshared Recursive mutex"} #endif ,{PTHREAD_MUTEX_DEFAULT, 1, 1, "Pshared mutex across processes"} #ifndef WITHOUT_XOPEN ,{PTHREAD_MUTEX_NORMAL, 1, 1, "Pshared Normal mutex across processes"} ,{PTHREAD_MUTEX_ERRORCHECK, 1, 1, "Pshared Errorcheck mutex across processes"} ,{PTHREAD_MUTEX_RECURSIVE, 1, 1, "Pshared Recursive mutex across processes"} #endif }; #define NSCENAR (sizeof(scenarii)/sizeof(scenarii[0])) /* The test function will only perform a trylock operation then return. */ void * tf(void * arg) { testdata_t * td = (testdata_t *)arg; td->status = pthread_mutex_trylock(&(td->mtx)); if (td->status == 0) { int ret; ret = pthread_mutex_unlock(&(td->mtx)); if (ret != 0) { UNRESOLVED(ret, "Failed to unlock a locked semaphore"); } } return NULL; } /* Main entry point. */ int main(int argc, char * argv[]) { int ret; int sc; pthread_mutexattr_t ma; testdata_t * td; testdata_t alternativ; int do_fork; pid_t child_pr=0, chkpid; int status; pthread_t child_th; long pshared, mf; /* Initialize output */ output_init(); /* Initialize the timeout */ alarm(30); /* Test system abilities */ pshared = sysconf(_SC_THREAD_PROCESS_SHARED); mf =sysconf(_SC_MAPPED_FILES); #if VERBOSE > 0 output("Test starting\n"); output("System abilities:\n"); output(" TSH : %li\n", pshared); output(" MF : %li\n", mf); if ((mf < 0) || (pshared < 0)) output("Process-shared attributes won't be tested\n"); #endif #ifdef WITHOUT_XOPEN #if VERBOSE > 0 output("As XSI extension is disabled, we won't test the feature across process\n"); #endif mf = -1; #endif /********** * Allocate space for the testdata structure */ if (mf < 0) { /* Cannot mmap a file (or not interested in this), we use an alternative method */ td = &alternativ; pshared = -1; /* We won't do this testing anyway */ #if VERBOSE > 0 output("Testdata allocated in the process memory.\n"); #endif } #ifndef WITHOUT_XOPEN else { /* We will place the test data in a mmaped file */ char filename[] = "/tmp/mutex_trylock_4-2-XXXXXX"; size_t sz; void * mmaped; int fd; char * tmp; /* We now create the temp files */ fd = mkstemp(filename); if (fd == -1) { UNRESOLVED(errno, "Temporary file could not be created"); } /* and make sure the file will be deleted when closed */ unlink(filename); #if VERBOSE > 1 output("Temp file created (%s).\n", filename); #endif sz= (size_t)sysconf(_SC_PAGESIZE); tmp = calloc(1, sz); if (tmp == NULL) { UNRESOLVED(errno, "Memory allocation failed"); } /* Write the data to the file. */ if (write (fd, tmp, sz) != (ssize_t) sz) { UNRESOLVED(sz, "Writting to the file failed"); } free(tmp); /* Now we can map the file in memory */ mmaped = mmap(NULL, sz, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); if (mmaped == MAP_FAILED) { UNRESOLVED(errno, "mmap failed"); } td = (testdata_t *) mmaped; /* Our datatest structure is now in shared memory */ #if VERBOSE > 1 output("Testdata allocated in shared memory.\n"); #endif } #endif /********** * For each test scenario, initialize the attributes and other variables. * Do the whole thing for each time to test. */ for ( sc=0; sc < NSCENAR ; sc++) { #if VERBOSE > 1 output("[parent] Preparing attributes for: %s\n", scenarii[sc].descr); #endif /* set / reset everything */ do_fork=0; ret = pthread_mutexattr_init(&ma); if (ret != 0) { UNRESOLVED(ret, "[parent] Unable to initialize the mutex attribute object"); } #ifndef WITHOUT_XOPEN /* Set the mutex type */ ret = pthread_mutexattr_settype(&ma, scenarii[sc].m_type); if (ret != 0) { UNRESOLVED(ret, "[parent] Unable to set mutex type"); } #if VERBOSE > 1 output("[parent] Mutex type : %i\n", scenarii[sc].m_type); #endif #endif /* Set the pshared attributes, if supported */ if ((pshared > 0) && (scenarii[sc].m_pshared != 0)) { ret = pthread_mutexattr_setpshared(&ma, PTHREAD_PROCESS_SHARED); if (ret != 0) { UNRESOLVED(ret, "[parent] Unable to set the mutex process-shared"); } #if VERBOSE > 1 output("[parent] Mutex is process-shared\n"); #endif } #if VERBOSE > 1 else { output("[parent] Mutex is process-private\n"); } #endif /* Tell whether the test will be across processes */ if ((pshared > 0) && (scenarii[sc].fork != 0)) { do_fork = 1; #if VERBOSE > 1 output("[parent] Child will be a new process\n"); #endif } #if VERBOSE > 1 else { output("[parent] Child will be a new thread\n"); } #endif /********** * Initialize the testdata_t structure with the previously defined attributes */ /* Initialize the mutex */ ret = pthread_mutex_init(&(td->mtx), &ma); if (ret != 0) { UNRESOLVED(ret, "[parent] Mutex init failed"); } /* Initialize the other datas from the test structure */ td->status=0; /********** * Proceed to the actual testing */ /* Trylock the mutex twice before creating children */ ret = pthread_mutex_lock(&(td->mtx)); if (ret != 0) { UNRESOLVED(ret, "[parent] Unable to lock the mutex"); } /* Create the children */ if (do_fork != 0) { /* We are testing across processes */ child_pr = fork(); if (child_pr == -1) { UNRESOLVED(errno, "[parent] Fork failed"); } if (child_pr == 0) { #if VERBOSE > 3 output("[child] Child process is starting...\n"); #endif if (tf((void *)td) != NULL) { UNRESOLVED( -1, "[child] Got an unexpected return value from test function"); } else { /* We cannot use the PASSED macro here since it would terminate the output */ exit (0); } } /* Only the parent process goes further */ } else /* do_fork == 0 */ { /* We are testing across two threads */ ret = pthread_create(&child_th, NULL, tf, td); if (ret != 0) { UNRESOLVED(ret, "[parent] Unable to create the child thread."); } } /* Wait for the child to terminate */ if (do_fork != 0) { /* We were testing across processes */ ret = 0; chkpid = waitpid(child_pr, &status, 0); if (chkpid != child_pr) { output("Expected pid: %i. Got %i\n", (int)child_pr, (int)chkpid); UNRESOLVED(errno, "Waitpid failed"); } if (WIFSIGNALED(status)) { output("Child process killed with signal %d\n",WTERMSIG(status)); UNRESOLVED( -1 , "Child process was killed"); } if (WIFEXITED(status)) { ret = WEXITSTATUS(status); } else { UNRESOLVED( -1, "Child process was neither killed nor exited"); } if (ret != 0) { exit(ret); /* Output has already been closed in child */ } } else /* child was a thread */ { ret = pthread_join(child_th, NULL); if (ret != 0) { UNRESOLVED(ret, "[parent] Unable to join the thread"); } } /* Check the child status */ if (td->status != EBUSY) { output("Unexpected return value: %d (%s)\n", td->status, strerror(td->status)); FAILED("pthread_mutex_trylock() did not return EBUSY in the child"); } /* Unlock the mutex */ ret= pthread_mutex_unlock(&(td->mtx)); if (ret != 0) { UNRESOLVED(ret, "Failed to unlock the mutex"); } /********** * Destroy the data */ ret = pthread_mutex_destroy(&(td->mtx)); if (ret != 0) { UNRESOLVED(ret, "Failed to destroy the mutex"); } ret = pthread_mutexattr_destroy(&ma); if (ret != 0) { UNRESOLVED(ret, "Failed to destroy the mutex attribute object"); } } /* Proceed to the next scenario */ #if VERBOSE > 0 output("Test passed\n"); #endif PASSED; } posixtestsuite/conformance/interfaces/pthread_mutex_trylock/2-1.c0100644000000000000000000002716510310243753024402 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertion: * * If the mutex is of type PTHREAD_MUTEX_RECURSIVE, * and the calling thread already owns the mutex, * the call is successful (the lock count is incremented). * The steps are: * * -> trylock the mutex. It shall suceed. * -> trylock the mutex again. It shall suceed again * -> unlock once * -> create a new child (either thread or process) * -> the new child trylock the mutex. It shall fail. * -> Unlock. It shall succeed. * -> Unlock again. It shall fail. * -> undo everything. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /* We need the XSI extention for the mutex attributes and the mkstemp() routine */ #ifndef WITHOUT_XOPEN #define _XOPEN_SOURCE 600 #endif /********************************************************************************************/ /****************************** standard includes *****************************************/ /********************************************************************************************/ #include #include #include #include #include #include #include #include #include /********************************************************************************************/ /****************************** Test framework *****************************************/ /********************************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /********************************************************************************************/ /********************************** Configuration ******************************************/ /********************************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif /********************************************************************************************/ /*********************************** Test case *****************************************/ /********************************************************************************************/ #ifndef WITHOUT_XOPEN typedef struct { pthread_mutex_t mtx; int status; /* error code */ } testdata_t; struct _scenar { int m_type; /* Mutex type to use */ int m_pshared; /* 0: mutex is process-private (default) ~ !0: mutex is process-shared, if supported */ int fork; /* 0: Test between threads. ~ !0: Test across processes, if supported (mmap) */ char * descr; /* Case description */ } scenarii[] = { {PTHREAD_MUTEX_RECURSIVE, 0, 0, "Recursive mutex"} ,{PTHREAD_MUTEX_RECURSIVE, 1, 0, "Pshared Recursive mutex"} ,{PTHREAD_MUTEX_RECURSIVE, 1, 1, "Pshared Recursive mutex across processes"} }; #define NSCENAR (sizeof(scenarii)/sizeof(scenarii[0])) /* The test function will only perform a trylock operation then return. */ void * tf(void * arg) { testdata_t * td = (testdata_t *)arg; td->status = pthread_mutex_trylock(&(td->mtx)); if (td->status == 0) { int ret; ret = pthread_mutex_unlock(&(td->mtx)); if (ret != 0) { UNRESOLVED(ret, "Failed to unlock a locked semaphore"); } } return NULL; } /* Main entry point. */ int main(int argc, char * argv[]) { int ret; int sc; pthread_mutexattr_t ma; testdata_t * td; testdata_t alternativ; int do_fork; pid_t child_pr=0, chkpid; int status; pthread_t child_th; long pshared, mf; /* Initialize output */ output_init(); /* Test system abilities */ pshared = sysconf(_SC_THREAD_PROCESS_SHARED); mf =sysconf(_SC_MAPPED_FILES); #if VERBOSE > 0 output("Test starting\n"); output("System abilities:\n"); output(" TSH : %li\n", pshared); output(" MF : %li\n", mf); if ((mf < 0) || (pshared < 0)) output("Process-shared attributes won't be tested\n"); #endif /********** * Allocate space for the testdata structure */ if (mf < 0) { /* Cannot mmap a file (or not interested in this), we use an alternative method */ td = &alternativ; pshared = -1; /* We won't do this testing anyway */ #if VERBOSE > 0 output("Testdata allocated in the process memory.\n"); #endif } else { /* We will place the test data in a mmaped file */ char filename[] = "/tmp/mutex_trylock_2-1-XXXXXX"; size_t sz; void * mmaped; int fd; char * tmp; /* We now create the temp files */ fd = mkstemp(filename); if (fd == -1) { UNRESOLVED(errno, "Temporary file could not be created"); } /* and make sure the file will be deleted when closed */ unlink(filename); #if VERBOSE > 1 output("Temp file created (%s).\n", filename); #endif sz= (size_t)sysconf(_SC_PAGESIZE); tmp = calloc(1, sz); if (tmp == NULL) { UNRESOLVED(errno, "Memory allocation failed"); } /* Write the data to the file. */ if (write (fd, tmp, sz) != (ssize_t) sz) { UNRESOLVED(sz, "Writting to the file failed"); } free(tmp); /* Now we can map the file in memory */ mmaped = mmap(NULL, sz, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); if (mmaped == MAP_FAILED) { UNRESOLVED(errno, "mmap failed"); } td = (testdata_t *) mmaped; /* Our datatest structure is now in shared memory */ #if VERBOSE > 1 output("Testdata allocated in shared memory.\n"); #endif } /********** * For each test scenario, initialize the attributes and other variables. * Do the whole thing for each time to test. */ for ( sc=0; sc < NSCENAR ; sc++) { #if VERBOSE > 1 output("[parent] Preparing attributes for: %s\n", scenarii[sc].descr); #endif /* set / reset everything */ do_fork=0; ret = pthread_mutexattr_init(&ma); if (ret != 0) { UNRESOLVED(ret, "[parent] Unable to initialize the mutex attribute object"); } /* Set the mutex type */ ret = pthread_mutexattr_settype(&ma, scenarii[sc].m_type); if (ret != 0) { UNRESOLVED(ret, "[parent] Unable to set mutex type"); } #if VERBOSE > 1 output("[parent] Mutex type : %i\n", scenarii[sc].m_type); #endif /* Set the pshared attributes, if supported */ if ((pshared > 0) && (scenarii[sc].m_pshared != 0)) { ret = pthread_mutexattr_setpshared(&ma, PTHREAD_PROCESS_SHARED); if (ret != 0) { UNRESOLVED(ret, "[parent] Unable to set the mutex process-shared"); } #if VERBOSE > 1 output("[parent] Mutex is process-shared\n"); #endif } #if VERBOSE > 1 else { output("[parent] Mutex is process-private\n"); } #endif /* Tell whether the test will be across processes */ if ((pshared > 0) && (scenarii[sc].fork != 0)) { do_fork = 1; #if VERBOSE > 1 output("[parent] Child will be a new process\n"); #endif } #if VERBOSE > 1 else { output("[parent] Child will be a new thread\n"); } #endif /********** * Initialize the testdata_t structure with the previously defined attributes */ /* Initialize the mutex */ ret = pthread_mutex_init(&(td->mtx), &ma); if (ret != 0) { UNRESOLVED(ret, "[parent] Mutex init failed"); } /* Initialize the other datas from the test structure */ td->status=0; /********** * Proceed to the actual testing */ /* Trylock the mutex twice before creating children */ ret = pthread_mutex_trylock(&(td->mtx)); if (ret != 0) { UNRESOLVED(ret, "[parent] Unable to trylock the mutex"); } ret = pthread_mutex_trylock(&(td->mtx)); if (scenarii[sc].m_type == PTHREAD_MUTEX_RECURSIVE) { if (ret != 0) { FAILED("Failed to pthread_mutex_trylock() twice a recursive mutex"); } /* Unlock once so the count is "1" */ ret = pthread_mutex_unlock(&(td->mtx)); if (ret != 0) { UNRESOLVED(ret, "Failed to unlock the mutex"); } } else if (ret == 0) { UNRESOLVED(-1, "Main was able to pthread_mutex_trylock() twice without error"); } /* Create the children */ if (do_fork != 0) { /* We are testing across processes */ child_pr = fork(); if (child_pr == -1) { UNRESOLVED(errno, "[parent] Fork failed"); } if (child_pr == 0) { #if VERBOSE > 3 output("[child] Child process is starting...\n"); #endif if (tf((void *)td) != NULL) { UNRESOLVED( -1, "[child] Got an unexpected return value from test function"); } else { /* We cannot use the PASSED macro here since it would terminate the output */ exit (0); } } /* Only the parent process goes further */ } else /* do_fork == 0 */ { /* We are testing across two threads */ ret = pthread_create(&child_th, NULL, tf, td); if (ret != 0) { UNRESOLVED(ret, "[parent] Unable to create the child thread."); } } /* Wait for the child to terminate */ if (do_fork != 0) { /* We were testing across processes */ ret = 0; chkpid = waitpid(child_pr, &status, 0); if (chkpid != child_pr) { output("Expected pid: %i. Got %i\n", (int)child_pr, (int)chkpid); UNRESOLVED(errno, "Waitpid failed"); } if (WIFSIGNALED(status)) { output("Child process killed with signal %d\n",WTERMSIG(status)); UNRESOLVED( -1 , "Child process was killed"); } if (WIFEXITED(status)) { ret = WEXITSTATUS(status); } else { UNRESOLVED( -1, "Child process was neither killed nor exited"); } if (ret != 0) { exit(ret); /* Output has already been closed in child */ } } else /* child was a thread */ { ret = pthread_join(child_th, NULL); if (ret != 0) { UNRESOLVED(ret, "[parent] Unable to join the thread"); } } /* Check the child status */ if (td->status != EBUSY) { output("Unexpected return value: %d (%s)\n", td->status, strerror(td->status)); FAILED("pthread_mutex_trylock() did not return EBUSY in the child"); } /* Unlock the mutex */ ret= pthread_mutex_unlock(&(td->mtx)); if (ret != 0) { FAILED("Failed to unlock the mutex -- count is broken?"); } ret= pthread_mutex_unlock(&(td->mtx)); if (ret == 0) { FAILED("Was able to unlock once more the mutex -- count is broken?"); } /********** * Destroy the data */ ret = pthread_mutex_destroy(&(td->mtx)); if (ret != 0) { UNRESOLVED(ret, "Failed to destroy the mutex"); } ret = pthread_mutexattr_destroy(&ma); if (ret != 0) { UNRESOLVED(ret, "Failed to destroy the mutex attribute object"); } } /* Proceed to the next scenario */ #if VERBOSE > 0 output("Test passed\n"); #endif PASSED; } #else /* WITHOUT_XOPEN */ int main(int argc, char * argv[]) { output_init(); UNTESTED("This test requires XSI features"); } #endif posixtestsuite/conformance/interfaces/pthread_mutex_trylock/3-1.c0100644000000000000000000000257310111404414024367 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: bing.wei.liu REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_mutex_trylock() * Upon succesful completion, it shall return a 0 * */ #include #include #include #include "posixtest.h" int main() { pthread_mutex_t mutex; int rc; /* Initialize a mutex object with the default mutex attributes */ if((rc=pthread_mutex_init(&mutex,NULL)) != 0) { fprintf(stderr,"Error at pthread_mutex_init(), rc=%d\n",rc); return PTS_UNRESOLVED; } /* Try to lock the mutex using pthread_mutex_trylock() */ if((rc=pthread_mutex_trylock(&mutex)) == 0) { pthread_mutex_unlock(&mutex); printf("Test PASSED\n"); return PTS_PASS; } /* Check if returned values are tolerable */ /* PATCH: since we are using the mutex properly,*/ /* errors are NOT tolerable here */ else if(rc == EBUSY) { fprintf(stderr,"The mutex was already locked\n"); } else if(rc == EINVAL) { fprintf(stderr,"Invalid mutex object\n"); } else if(rc == EAGAIN) { fprintf(stderr,"The maximum number of recursive locks has been exceeded\n"); } /* Any other returned value means the test failed */ printf("Test FAILED\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/pthread_cancel/0040755000000000000000000000000010515625202022243 5ustar rootrootposixtestsuite/conformance/interfaces/pthread_cancel/2-2.c0100644000000000000000000000447310063541675022725 0ustar rootroot/* * Copyright (c) 2004, QUALCOMM Inc. All rights reserved. * Created by: abisain REMOVE-THIS AT qualcomm DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test pthread_cancel() * * Any destructors for thread_specific data will be called * * Steps: * 1. Create a new thread. * 2. Create a thread specific object in the thread with a destructor * 3. Call pthread_cancel on the thread. * 4. Make sure that the destructor was called * */ #include #include #include #include #include "posixtest.h" #define TEST "2-2" #define FUNCTION "pthread_cancel" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " int cleanup_flag = 0; int sem = 0; /* manual semaphore */ void destructor(void *tmp) { cleanup_flag = 1; } /* Thread's function. */ void *a_thread_func(void *tmp) { pthread_key_t key; int value = 1; int rc = 0; /* To enable thread immediate cancelation, since the default * is PTHREAD_CANCEL_DEFERRED. */ rc = pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL); if (rc != 0) { printf(ERROR_PREFIX "pthread_setcanceltype\n"); exit(PTS_UNRESOLVED); } rc = pthread_key_create(&key, destructor); if (rc != 0) { printf(ERROR_PREFIX "pthread_key_create\n"); exit(PTS_UNRESOLVED); } rc = pthread_setspecific(key, &value); if (rc != 0) { printf(ERROR_PREFIX "pthread_setspecific\n"); exit(PTS_UNRESOLVED); } /* Tell main that the key is created */ sem = 1; /* Sleep forever */ while(1) sleep(5); return NULL; } int main() { pthread_t new_th; int rc = 0; sem = 0; /* Create a new thread. */ rc = pthread_create(&new_th, NULL, a_thread_func, NULL); if(rc != 0) { printf(ERROR_PREFIX "pthread_create\n"); exit(PTS_UNRESOLVED); } /* Wait for the thread to be ready */ while(sem == 0) sleep(1); /* Cancel the thread. */ rc = pthread_cancel(new_th); if(rc != 0) { printf(ERROR_PREFIX "pthread_cancel\n"); exit(PTS_UNRESOLVED); } /* Delay enough so that the destructor must have been called */ sleep(5); if(cleanup_flag != 1) { printf(ERROR_PREFIX "Test FAIL: Destructor was not executed.\n"); exit(PTS_FAIL); } printf("Test PASS\n"); exit(PTS_PASS); } posixtestsuite/conformance/interfaces/pthread_cancel/5-1.c0100644000000000000000000000303407626776061022731 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test pthread_cancel * It may return an error number of: * -[ESRCH] No thread could be found corresponding to that thread ID * It shall not return an error code of [EINTR] * * STEPS: * 1. Create a thread * 2. Wait 'till the thread has ended execution * 3. Send a cancel request to the thread (which isn't existing anymore) * 3. It should return an error code of [ESRCH], else test fails. * */ #include #include #include #include "posixtest.h" void *a_thread_func() { pthread_exit(0); return NULL; } int main() { pthread_t new_th; int ret; /* Create a new thread. */ if(pthread_create(&new_th, NULL, a_thread_func, NULL) != 0) { perror("Error creating thread\n"); return PTS_UNRESOLVED; } /* Wait for thread to finish execution. */ pthread_join(new_th, NULL); /* Try and cancel thread. It should return an error because it * already is canceled and doesn't exist anymore. */ ret=pthread_cancel(new_th); if(ret != 0) { if(ret == ESRCH) { printf("Test PASSED\n"); return PTS_PASS; } printf("Test FAILED: Returned error code other than [ESRCH]\n"); return PTS_FAIL; } printf("Test PASSED: *NOTE: Returned 0 on error, though standard states 'may' fail.\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_cancel/4-1.c0100644000000000000000000000264207626776061022734 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test pthread_cancel * Upon successful completion will return a 0. * * STEPS: * 1. Create a thread * 2. Cancel that thread * 3. If pthread_cancel does not return [ESRCH] then it should return 0 */ #include #include #include #include #include "posixtest.h" int sem; /* Manual semaphore */ void *a_thread_func() { pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL); /* Indicate to main() that the thread has been created. */ sem=1; while(1) sleep(1); pthread_exit(0); return NULL; } int main() { pthread_t new_th; int ret; sem=0; /* Create a new thread. */ if(pthread_create(&new_th, NULL, a_thread_func, NULL) != 0) { perror("Error creating thread\n"); return PTS_UNRESOLVED; } /* Make sure thread is created before we cancel it. */ while(sem==0) sleep(1); /* Send cancel request to thread */ ret=pthread_cancel(new_th); if(ret != 0) { if(ret == ESRCH) { perror("Could not cancel thread\n"); return PTS_UNRESOLVED; } else { printf("Test FAILED\n"); return PTS_FAIL; } } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_cancel/5-2.c0100644000000000000000000001726710207110113022710 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertion: * * The function does not return EINTR * The steps are: * -> kill a thread which calls pthread_cancel * -> check that EINTR is never returned */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /********************************************************************************************/ /****************************** standard includes *****************************************/ /********************************************************************************************/ #include #include #include #include #include #include #include #include #include /********************************************************************************************/ /****************************** Test framework *****************************************/ /********************************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /********************************************************************************************/ /********************************** Configuration ******************************************/ /********************************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif #define WITH_SYNCHRO /********************************************************************************************/ /*********************************** Test cases *****************************************/ /********************************************************************************************/ char do_it = 1; unsigned long count_ope = 0; #ifdef WITH_SYNCHRO sem_t semsig1; sem_t semsig2; unsigned long count_sig = 0; #endif sigset_t usersigs; typedef struct { int sig; #ifdef WITH_SYNCHRO sem_t *sem; #endif } thestruct; /* the following function keeps on sending the signal to the process */ void * sendsig ( void * arg ) { thestruct * thearg = ( thestruct * ) arg; int ret; pid_t process; process = getpid(); /* We block the signals SIGUSR1 and SIGUSR2 for this THREAD */ ret = pthread_sigmask( SIG_BLOCK, &usersigs, NULL ); if ( ret != 0 ) { UNRESOLVED( ret, "Unable to block SIGUSR1 and SIGUSR2 in signal thread" ); } while ( do_it ) { #ifdef WITH_SYNCHRO if ( ( ret = sem_wait( thearg->sem ) ) ) { UNRESOLVED( errno, "Sem_wait in sendsig" ); } count_sig++; #endif ret = kill( process, thearg->sig ); if ( ret != 0 ) { UNRESOLVED( errno, "Kill in sendsig" ); } } return NULL; } /* Next are the signal handlers. */ /* This one is registered for signal SIGUSR1 */ void sighdl1( int sig ) { #ifdef WITH_SYNCHRO if ( sem_post( &semsig1 ) ) { UNRESOLVED( errno, "Sem_post in signal handler 1" ); } #endif } /* This one is registered for signal SIGUSR2 */ void sighdl2( int sig ) { #ifdef WITH_SYNCHRO if ( sem_post( &semsig2 ) ) { UNRESOLVED( errno, "Sem_post in signal handler 2" ); } #endif } /* Init function */ void * testth( void * arg ) { while ( do_it ) sched_yield(); return NULL; } /* Test function -- calls pthread_kill() and checks that EINTR is never returned. */ void * test( void * arg ) { int ret = 0; pthread_t test_ch; ret = pthread_create( &test_ch, NULL, testth, NULL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to create a thread" ); } /* We don't block the signals SIGUSR1 and SIGUSR2 for this THREAD */ ret = pthread_sigmask( SIG_UNBLOCK, &usersigs, NULL ); if ( ret != 0 ) { UNRESOLVED( ret, "Unable to unblock SIGUSR1 and SIGUSR2 in worker thread" ); } while ( do_it ) { count_ope++; ret = pthread_cancel( test_ch ); if ( ret == EINTR ) { FAILED( "pthread_self returned EINTR" ); } if ( ret != 0 ) { UNRESOLVED( ret, "pthread_self returned an unexpected error" ); } } ret = pthread_join( test_ch, NULL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to join the canceled thread" ); } return NULL; } /* Main function */ int main ( int argc, char * argv[] ) { int ret; pthread_t th_work, th_sig1, th_sig2; thestruct arg1, arg2; struct sigaction sa; /* Initialize output routine */ output_init(); /* We need to register the signal handlers for the PROCESS */ sigemptyset ( &sa.sa_mask ); sa.sa_flags = 0; sa.sa_handler = sighdl1; if ( ( ret = sigaction ( SIGUSR1, &sa, NULL ) ) ) { UNRESOLVED( ret, "Unable to register signal handler1" ); } sa.sa_handler = sighdl2; if ( ( ret = sigaction ( SIGUSR2, &sa, NULL ) ) ) { UNRESOLVED( ret, "Unable to register signal handler2" ); } /* We prepare a signal set which includes SIGUSR1 and SIGUSR2 */ sigemptyset( &usersigs ); ret = sigaddset( &usersigs, SIGUSR1 ); ret |= sigaddset( &usersigs, SIGUSR2 ); if ( ret != 0 ) { UNRESOLVED( ret, "Unable to add SIGUSR1 or 2 to a signal set" ); } /* We now block the signals SIGUSR1 and SIGUSR2 for this THREAD */ ret = pthread_sigmask( SIG_BLOCK, &usersigs, NULL ); if ( ret != 0 ) { UNRESOLVED( ret, "Unable to block SIGUSR1 and SIGUSR2 in main thread" ); } #ifdef WITH_SYNCHRO if ( sem_init( &semsig1, 0, 1 ) ) { UNRESOLVED( errno, "Semsig1 init" ); } if ( sem_init( &semsig2, 0, 1 ) ) { UNRESOLVED( errno, "Semsig2 init" ); } #endif if ( ( ret = pthread_create( &th_work, NULL, test, NULL ) ) ) { UNRESOLVED( ret, "Worker thread creation failed" ); } arg1.sig = SIGUSR1; arg2.sig = SIGUSR2; #ifdef WITH_SYNCHRO arg1.sem = &semsig1; arg2.sem = &semsig2; #endif if ( ( ret = pthread_create( &th_sig1, NULL, sendsig, ( void * ) & arg1 ) ) ) { UNRESOLVED( ret, "Signal 1 sender thread creation failed" ); } if ( ( ret = pthread_create( &th_sig2, NULL, sendsig, ( void * ) & arg2 ) ) ) { UNRESOLVED( ret, "Signal 2 sender thread creation failed" ); } /* Let's wait for a while now */ sleep( 1 ); /* Now stop the threads and join them */ do { do_it = 0; } while ( do_it ); if ( ( ret = pthread_join( th_sig1, NULL ) ) ) { UNRESOLVED( ret, "Signal 1 sender thread join failed" ); } if ( ( ret = pthread_join( th_sig2, NULL ) ) ) { UNRESOLVED( ret, "Signal 2 sender thread join failed" ); } if ( ( ret = pthread_join( th_work, NULL ) ) ) { UNRESOLVED( ret, "Worker thread join failed" ); } #if VERBOSE > 0 output( "Test executed successfully.\n" ); output( " %d operations.\n", count_ope ); #ifdef WITH_SYNCHRO output( " %d signals were sent meanwhile.\n", count_sig ); #endif #endif PASSED; } posixtestsuite/conformance/interfaces/pthread_cancel/1-3.c0100644000000000000000000001076207633434501022721 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test pthread_cancel * Shall request that 'thread' shall be canceled. The target thread's * cancelability state and type determines when the cancelation takes * effect. * * Test when a thread is PTHREAD_CANCEL_ENABLE and PTHREAD_CANCEL_DEFERRED * * STEPS: * 1. Setup a mutex and lock it in main() * 2. Create a thread. * 3. In the thread function, set the type to PTHREAD_CANCEL_DEFERRED and state to * PTHREAD_CANCEL_ENABLE. * 4. Setup a cleanup handler for the thread. * 5. Make the thread block on the locked mutex * 6. Send out a thread cancel request to the new thread, and unlock the mutex allowing the * thread to continue execution. * 7. If the cancel request was honored immediately, the * cleanup handler would have been executed, setting the cleanup_flag to -1, making the * test fail. * 8. If not, the thread will continue execution, pop the cleanup handler, set the cleanup * flag to 1, and call the cancelation point pthread_testcancel(). The test will pass. * 9. If the thread did not cancel at the cancelation point like it was supposed to, the thread * will continue execution and set the cleanup_flag to -2, failing the test. */ #include #include #include #include #include "posixtest.h" # define INTHREAD 0 /* Control going to or is already for Thread */ # define INMAIN 1 /* Control going to or is already for Main */ int sem1; /* Manual semaphore */ int cleanup_flag; /* Flag to indicate the thread's cleanup handler was called */ pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; /* Mutex */ /* Cleanup function that the thread executes when it is canceled. So if * cleanup_flag is 1, it means that the thread was canceled. */ void a_cleanup_func() { cleanup_flag=-1; return; } /* Function that the thread executes upon its creation */ void *a_thread_func() { pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL); pthread_cleanup_push(a_cleanup_func,NULL); /* Indicate to main() that the thread has been created. */ sem1=INMAIN; /* Lock the mutex. It should have already been locked in main, so the thread * should block. */ if(pthread_mutex_lock(&mutex) != 0) { perror("Error in pthread_mutex_lock()\n"); pthread_exit((void*)PTS_UNRESOLVED); return (void*)PTS_UNRESOLVED; } /* Should get here if the cancel request was deffered. */ pthread_cleanup_pop(0); cleanup_flag=1; /* Cancelation point. Cancel request should not be honored here. */ pthread_testcancel(); /* Should not get here if the cancel request was honored at the cancelation point * pthread_testcancel(). */ cleanup_flag=-2; pthread_exit(0); return NULL; } int main() { pthread_t new_th; /* Initializing values */ sem1=INTHREAD; cleanup_flag=0; /* Lock the mutex */ if(pthread_mutex_lock(&mutex) != 0) { perror("Error in pthread_mutex_lock()\n"); return PTS_UNRESOLVED; } /* Create a new thread. */ if(pthread_create(&new_th, NULL, a_thread_func, NULL) != 0) { perror("Error creating thread\n"); return PTS_UNRESOLVED; } /* Make sure thread is created before we cancel it. (wait for * a_thread_func() to set sem1=INMAIN.) */ while(sem1==INTHREAD) sleep(1); /* Send cancel request to the thread. */ if(pthread_cancel(new_th) != 0) { printf("Test FAILED: Couldn't cancel thread\n"); return PTS_FAIL; } /* Cancel request has been sent, unlock the mutex */ if(pthread_mutex_unlock(&mutex) != 0) { perror("Error in pthread_mutex_unlock()\n"); return PTS_UNRESOLVED; } /* Wait 'till the thread has been canceled or has ended execution. */ if(pthread_join(new_th, NULL) != 0) { perror("Error in pthread_join()\n"); return PTS_UNRESOLVED; } /* This means that the cleanup function wasn't called, so the cancel * request was not honord immediately like it should have been. */ if(cleanup_flag == -1) { printf("Test FAILED: Cancel request was not deferred.\n"); return PTS_FAIL; } if(cleanup_flag == -2) { printf("Test FAILED: (1) Cancel request not honored at cancelation point pthread_testcancel() OR (2) pthread_testcancel() not treated as a cancelation point.\n"); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_cancel/1-1.c0100644000000000000000000000645607626776060022737 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test pthread_cancel * Shall request that 'thread' shall be canceled. The target thread's * cancelability state and type determines when the cancelation takes * effect. * * Test when a thread is PTHREAD_CANCEL_ENABLE and PTHREAD_CANCEL_ASYNCHRONOUS * * STEPS: * 1. Create a thread. * 2. In the thread function, set the set and type to * PTHREAD_CANCEL_ENABLE and PTHREAD_CANCEL_ASYNCHRONOUS * 3. Setup a cleanup handler for the thread. * 4. Send out a thread cancel request to the new thread * 5. If the cancel request was honored immediately and correctly, the * cleanup handler would have been executed, and the test will pass. * 6. If not, the thread will wait for 10 seconds before it exits itself, * and the test will fail. */ #include #include #include #include #include "posixtest.h" # define INTHREAD 0 /* Control going to or is already for Thread */ # define INMAIN 1 /* Control going to or is already for Main */ int sem1; /* Manual semaphore */ int cleanup_flag; /* Cleanup function that the thread executes when it is canceled. So if * cleanup_flag is -1, it means that the thread was canceled. */ void a_cleanup_func() { cleanup_flag=1; return; } /* Function that the thread executes upon its creation */ void *a_thread_func() { pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL); pthread_cleanup_push(a_cleanup_func,NULL); /* Indicate to main() that the thread has been created. */ sem1=INMAIN; /* Wait until main() has sent out a cancel request, meaning until it * sets sem1==0 */ while(sem1==1) sleep(1); /* Give thread 10 seconds to time out. If the cancel request was not * honored until now, the test will fail. */ sleep(10); /* Shouldn't get here if the cancel request was honored immediately * like it should have been. */ cleanup_flag=-1; pthread_cleanup_pop(0); pthread_exit(0); return NULL; } int main() { pthread_t new_th; /* Initializing values */ sem1=INTHREAD; cleanup_flag=0; /* Create a new thread. */ if(pthread_create(&new_th, NULL, a_thread_func, NULL) != 0) { perror("Error creating thread\n"); return PTS_UNRESOLVED; } /* Make sure thread is created before we cancel it. (wait for * a_thread_func() to set sem1=1.) */ while(sem1==INTHREAD) sleep(1); if(pthread_cancel(new_th) != 0) { printf("Test FAILED: Couldn't cancel thread\n"); return PTS_FAIL; } /* Indicate to the thread function that the thread cancel request * has been sent to it. */ sem1=INTHREAD; /* Wait for thread to return. (i.e. either canceled correctly and * called the cleanup function, or timed out after 10 seconds. */ while(cleanup_flag==INTHREAD) sleep(1); /* This means that the cleanup function wasn't called, so the cancel * request was not honord immediately like it should have been. */ if(cleanup_flag < 0) { printf("Test FAILED: Cancel request timed out\n"); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_cancel/testfrmw.c0100644000000000000000000000407210207110113024246 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * * This file is a wrapper to use the tests from the NPTL Test & Trace Project * with either the Linux Test Project or the Open POSIX Test Suite. * The following function are defined: * void output_init() * void output_fini() * void output(char * string, ...) * * The are used to output informative text (as a printf). */ #include #include /* We use a mutex to avoid conflicts in traces */ static pthread_mutex_t m_trace = PTHREAD_MUTEX_INITIALIZER; /*****************************************************************************************/ /******************************* stdout module *****************************************/ /*****************************************************************************************/ /* The following functions will output to stdout */ #if (1) void output_init() { /* do nothing */ return; } void output( char * string, ... ) { va_list ap; char *ts="[??:??:??]"; struct tm * now; time_t nw; pthread_mutex_lock(&m_trace); nw = time(NULL); now = localtime(&nw); if (now == NULL) printf(ts); else printf("[%2.2d:%2.2d:%2.2d]", now->tm_hour, now->tm_min, now->tm_sec); va_start( ap, string); vprintf(string, ap); va_end(ap); pthread_mutex_unlock(&m_trace); } void output_fini() { /*do nothing */ return; } #endif posixtestsuite/conformance/interfaces/pthread_cancel/1-2.c0100644000000000000000000000621607627243312022720 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test pthread_cancel * Shall request that 'thread' shall be canceled. The target thread's * cancelability state and type determines when the cancelation takes * effect. * * Test when a thread is PTHREAD_CANCEL_DISABLE * * STEPS: * 1. Create a thread. * 2. In the thread function, set the state to * PTHREAD_CANCEL_DISABLE * 3. Setup a cleanup handler for the thread. * 4. Send out a thread cancel request to the new thread * 5. If the cancel request was honored, the cleanup handler would have * been executed and the test will fail. * 6. If not, the thread will continue until the end of execution and exit * correctly, therefore passing the test. */ #include #include #include #include #include "posixtest.h" # define INTHREAD 0 /* Control going to or is already for Thread */ # define INMAIN 1 /* Control going to or is already for Main */ int sem1; /* Manual semaphore */ int cleanup_flag; /* Cleanup function that the thread executes when it is canceled. So if * cleanup_flag is -1, it means that the thread was canceled, meaning * the test will fail. */ void a_cleanup_func() { cleanup_flag=-1; return; } /* Function that the thread executes upon its creation */ void *a_thread_func() { pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL); pthread_cleanup_push(a_cleanup_func,NULL); /* Indicate to main() that the thread has been created. */ sem1=INMAIN; /* Wait until main() has sent out a cancel request, meaning until it * sets sem1==INMAIN. Sleeping for 3 secs. to give time for the * cancel request to be sent and processed. */ while(sem1==INMAIN) sleep(1); /* Should reach here if the thread correctly ignores the cancel * request. */ pthread_cleanup_pop(0); cleanup_flag=1; pthread_exit(0); return NULL; } int main() { pthread_t new_th; /* Initializing values */ sem1=INTHREAD; cleanup_flag=0; /* Create a new thread. */ if(pthread_create(&new_th, NULL, a_thread_func, NULL) != 0) { perror("Error creating thread\n"); return PTS_UNRESOLVED; } /* Make sure thread is created before we cancel it. (wait for * a_thread_func() to set sem1=1.) */ while(sem1==INTHREAD) sleep(1); if(pthread_cancel(new_th) != 0) { perror("Error sending cancel request\n"); return PTS_UNRESOLVED; } /* Indicate to the thread function that the thread cancel request * has been sent to it. */ sem1=INTHREAD; /* Wait for thread to return. (i.e. either canceled incorrectly and * called the cleanup function, or exited normally at the end of * thread execution like it should do. */ while(cleanup_flag==0) sleep(1); /* This means that the cleanup function was called, meaning the * thread was canceled rather than ignored the cancel request. */ if(cleanup_flag <= 0) { printf("Test FAILED\n"); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_cancel/assertions.xml0100644000000000000000000000237207622322521025163 0ustar rootroot The function int pthread_cancel(pthread_t thread); sends a request that 'thread' shall be canceled. The target thread's cancelability state and type determines when/if the cancelation takes effect. When the cancelation request is honored, the cancelation cleanup handlers for 'thread' are called. When the last cancelation cleanup handler returns, the thread-specific data destructer functions will be called for 'thread'. When the last destructer function returns, 'thread' then terminates. NOTE: Still trying to find a good way to test the second paragraph of assertion #2. The cancelation processing in the target thread will run asynchronously with respect to the calling thread returning from pthread_cancel(); If success, it returns a 0; It may return an error number if: -[ESRCH] No thread could be found corresponding to that thread ID It will not return [EINTR] posixtestsuite/conformance/interfaces/pthread_cancel/coverage.txt0100644000000000000000000000111207633434601024577 0ustar rootrootThis document defines the coverage for the pthread_cancel function: Assertion Tested? 1 YES 2 YES ** Difficult to test and assert that date destructors have been called (read assertions.xml file for more). 3 YES 4 YES 5 YES ** Keeping in mind it 'may' fail and not 'shall' fail, so it will always return PASS, but will return a PASS and print out a warning if it fails. NOTE: In a lot of these test, I didn't make use of semaphores or mutexes, but rather manually created my own. This is because I was taking into account different implementations. posixtestsuite/conformance/interfaces/pthread_cancel/testfrmw.h0100644000000000000000000000456410207110113024261 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * * This file is a wrapper to use the tests from the NPTL Test & Trace Project * with either the Linux Test Project or the Open POSIX Test Suite. * The following macros are defined here: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate without calling one of those macros. * * */ #include "posixtest.h" #include /* for the strerror() routine */ #ifdef __GNUC__ /* We are using GCC */ #define UNRESOLVED(x, s) \ { output("Test %s unresolved: got %i (%s) on line %i (%s)\n", __FILE__, x, strerror(x), __LINE__, s); \ output_fini(); \ exit(PTS_UNRESOLVED); } #define FAILED(s) \ { output("Test %s FAILED: %s\n", __FILE__, s); \ output_fini(); \ exit(PTS_FAIL); } #define PASSED \ output_fini(); \ exit(PTS_PASS); #define UNTESTED(s) \ { output("File %s cannot test: %s\n", __FILE__, s); \ output_fini(); \ exit(PTS_UNTESTED); \ } #else /* not using GCC */ #define UNRESOLVED(x, s) \ { output("Test unresolved: got %i (%s) on line %i (%s)\n", x, strerror(x), __LINE__, s); \ output_fini(); \ exit(PTS_UNRESOLVED); } #define FAILED(s) \ { output("Test FAILED: %s\n", s); \ output_fini(); \ exit(PTS_FAIL); } #define PASSED \ output_fini(); \ exit(PTS_PASS); #define UNTESTED(s) \ { output("Unable to test: %s\n", s); \ output_fini(); \ exit(PTS_UNTESTED); \ } #endif posixtestsuite/conformance/interfaces/pthread_cancel/2-3.c0100644000000000000000000000626210063541675022724 0ustar rootroot/* * Copyright (c) 2004, QUALCOMM Inc. All rights reserved. * Created by: abisain REMOVE-THIS AT qualcomm DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test pthread_cancel() * * Any destructors for thread_specific data will be called after * all cleanup handlers return * * Steps: * 1. Create a new thread. * 2. Create a thread specific object in the thread with a destructor * 3. Add a cleanup function in the thread * 4. Call pthread_cancel on the thread. * 5. Make sure that the destructor was called after the cleanup handler * */ #include #include #include #include #include "posixtest.h" #define TEST "2-3" #define FUNCTION "pthread_cancel" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " int cleanup_flag = 0; int destructor_flag = 0; int sem = 0; /* manual semaphore */ struct timespec destructor_time, cleanup_time; /* Destructor for the Thread Specific Data */ void destructor(void *tmp) { clock_gettime(CLOCK_REALTIME, &destructor_time); destructor_flag = 1; } /* Cleanup Handler for the Thread */ void cleanup_function() { clock_gettime(CLOCK_REALTIME, &cleanup_time); cleanup_flag = 1; } /* Thread's function. */ void *a_thread_func(void *tmp) { pthread_key_t key; int value = 1; int rc = 0; /* To enable thread immediate cancelation, since the default * is PTHREAD_CANCEL_DEFERRED. */ rc = pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL); if (rc != 0) { printf(ERROR_PREFIX "pthread_setcanceltype\n"); exit(PTS_UNRESOLVED); } rc = pthread_key_create(&key, destructor); if (rc != 0) { printf(ERROR_PREFIX "pthread_key_create\n"); exit(PTS_UNRESOLVED); } rc = pthread_setspecific(key, &value); if (rc != 0) { printf(ERROR_PREFIX "pthread_setspecific\n"); exit(PTS_UNRESOLVED); } pthread_cleanup_push(cleanup_function, NULL); /* Tell main that the key is created */ sem = 1; /* Sleep forever */ while(1) sleep(5); pthread_cleanup_pop(0); return NULL; } int main() { pthread_t new_th; int rc = 0; double diff; sem = 0; /* Create a new thread. */ rc = pthread_create(&new_th, NULL, a_thread_func, NULL); if(rc != 0) { printf(ERROR_PREFIX "pthread_create\n"); exit(PTS_UNRESOLVED); } /* Wait for the thread to be ready */ while(sem == 0) sleep(1); /* Cancel the thread. */ rc = pthread_cancel(new_th); if(rc != 0) { printf(ERROR_PREFIX "pthread_cancel\n"); exit(PTS_UNRESOLVED); } /* Delay enough so that the destructor must have been called */ sleep(5); if(cleanup_flag != 1) { printf(ERROR_PREFIX "Test FAIL: Cleanup handler was not executed.\n"); exit(PTS_FAIL); } if(destructor_flag != 1) { printf(ERROR_PREFIX "Test FAIL: Destructor was not executed.\n"); exit(PTS_FAIL); } diff = destructor_time.tv_sec - cleanup_time.tv_sec; diff += (double)(destructor_time.tv_nsec - cleanup_time.tv_nsec)/1000000000.0; if(diff < 0) { printf(ERROR_PREFIX "Test FAIL: Destructor called before Cleanup Handler\n"); exit(PTS_FAIL); } printf("Test PASS\n"); exit(PTS_PASS); } posixtestsuite/conformance/interfaces/pthread_cancel/2-1.c0100644000000000000000000000543007626776061022730 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test pthread_cancel * When the cancelation is acted on, the cancelation cleanup handlers for * 'thread' shall be called. * * STEPS: * 1. Create a thread * 2. In the thread function, push a cleanup function onto the stack * 3. Cancel the thread. The cleanup function should be automatically * executed, else the test will fail. */ #include #include #include #include #include "posixtest.h" int sem; /* Manual semaphore */ int cleanup_flag; /* Made global so that the cleanup function can manipulate the value as well. */ /* A cleanup function that sets the cleanup_flag to 1, meaning that the * cleanup function was reached. */ void a_cleanup_func() { cleanup_flag=1; sem=0; return; } /* A thread function called at the creation of the thread. It will push * the cleanup function onto it's stack, then go into a continuous 'while' * loop, never reaching the cleanup_pop function. So the only way the cleanup * function can be called is when the thread is canceled and all the cleanup * functions are supposed to be popped. */ void *a_thread_func() { /* To enable thread immediate cancelation, since the default * is PTHREAD_CANCEL_DEFERRED. */ pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL); pthread_cleanup_push(a_cleanup_func,NULL); sem=1; while(sem==1) sleep(1); sleep(5); sem=0; /* Should never be reached, but is required to be in the code * since pthread_cleanup_push is in the code. Else a compile error * will result. */ pthread_cleanup_pop(0); perror("Operation timed out, thread could not be canceled\n"); pthread_exit(0); return NULL; } int main() { pthread_t new_th; int i; /* Initializing the cleanup flag. */ cleanup_flag=0; sem=0; /* Create a new thread. */ if(pthread_create(&new_th, NULL, a_thread_func, NULL) != 0) { perror("Error creating thread\n"); return PTS_UNRESOLVED; } /* Make sure thread is created before we cancel it. */ while(sem==0) sleep(1); if(pthread_cancel(new_th) != 0) { printf("Error canceling thread\n"); return PTS_FAIL; } i=0; while(sem==1) { sleep(1); if(i==10) { printf("Test FAILED: Timed out while waiting for cancelation cleanup handlers to execute\n"); return PTS_FAIL; } i++; } /* If the cleanup function was not reached by calling the * pthread_cancel function, then the test fails. */ if(cleanup_flag != 1) { printf("Test FAILED: Could not cancel thread\n"); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_cancel/3-1.c0100644000000000000000000001005610063541675022717 0ustar rootroot/* * Copyright (c) 2004, QUALCOMM Inc. All rights reserved. * Created by: abisain REMOVE-THIS AT qualcomm DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test pthread_cancel * When the cancelation is acted on, the cancelation cleanup handlers for * 'thread' shall be called "asynchronously" * * STEPS: * 1. Change main thread to a real-time thread with a high priority * 1. Create a lower priority thread * 2. In the thread function, push a cleanup function onto the stack * 3. Cancel the thread from main and get timestamp, then block. * 4. The cleanup function should be automatically * executed, else the test will fail. */ #include #include #include #include #include #include "posixtest.h" #include #define TEST "3-1" #define FUNCTION "pthread_cancel" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " #define FIFOPOLICY SCHED_FIFO #define MAIN_PRIORITY 30 #define TIMEOUT_IN_SECS 10 /* Manual semaphore */ int sem; /* Made global so that the cleanup function * can manipulate the value as well. */ int cleanup_flag; struct timespec main_time, cleanup_time; /* A cleanup function that sets the cleanup_flag to 1, meaning that the * cleanup function was reached. */ void a_cleanup_func() { clock_gettime(CLOCK_REALTIME, &cleanup_time); cleanup_flag = 1; sem = 0; return; } /* A thread function called at the creation of the thread. It will push * the cleanup function onto it's stack, then go into a continuous 'while' * loop, never reaching the cleanup_pop function. So the only way the cleanup * function can be called is when the thread is canceled and all the cleanup * functions are supposed to be popped. */ void *a_thread_func() { int rc = 0; /* To enable thread immediate cancelation, since the default * is PTHREAD_CANCEL_DEFERRED. */ rc = pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL); if(rc != 0) { printf(ERROR_PREFIX "pthread_setcanceltype\n"); exit(PTS_UNRESOLVED); } pthread_cleanup_push(a_cleanup_func, NULL); sem=1; while(sem == 1) sleep(1); sleep(5); sem=0; /* Should never be reached, but is required to be in the code * since pthread_cleanup_push is in the code. Else a compile error * will result. */ pthread_cleanup_pop(0); pthread_exit(0); return NULL; } int main() { pthread_t new_th; int i; double diff ; struct sched_param param; int rc = 0; /* Initializing the cleanup flag. */ cleanup_flag = 0; sem = 0; param.sched_priority = MAIN_PRIORITY; /* Increase priority of main, so the new thread doesn't get to run */ rc = pthread_setschedparam(pthread_self(), FIFOPOLICY, ¶m); if(rc != 0) { printf(ERROR_PREFIX "pthread_setschedparam\n"); exit(PTS_UNRESOLVED); } /* Create a new thread. */ rc = pthread_create(&new_th, NULL, a_thread_func, NULL); if(rc != 0) { printf(ERROR_PREFIX "pthread_create\n"); return PTS_UNRESOLVED; } /* Make sure thread is created and executed before we cancel it. */ while(sem == 0) sleep(1); rc = pthread_cancel(new_th); if(rc != 0) { printf(ERROR_PREFIX "pthread_cancel\n"); exit(PTS_FAIL); } /* Get the time after canceling the thread */ clock_gettime(CLOCK_REALTIME, &main_time); i = 0; while(sem == 1) { sleep(1); if(i == TIMEOUT_IN_SECS) { printf(ERROR_PREFIX "Cleanup handler was not called\n"); exit(PTS_FAIL); } i++; } /* If the cleanup function was not reached by calling the * pthread_cancel function, then the test fails. */ if(cleanup_flag != 1) { printf(ERROR_PREFIX "Cleanup handler was not called\n"); exit(PTS_FAIL); } diff = cleanup_time.tv_sec - main_time.tv_sec; diff += (double)(cleanup_time.tv_nsec - main_time.tv_nsec)/1000000000.0; if(diff < 0) { printf(ERROR_PREFIX "Cleanup function was called before main continued\n"); exit(PTS_FAIL); } printf("Test PASS\n"); exit(PTS_PASS); } posixtestsuite/conformance/interfaces/pthread_barrier_destroy/0040755000000000000000000000000010515625201024214 5ustar rootrootposixtestsuite/conformance/interfaces/pthread_barrier_destroy/3-1.sh0100755000000000000000000000074107705073032025060 0ustar rootroot#!/bin/sh # Copyright (c) 2002, Intel Corporation. All rights reserved. # This file is licensed under the GPL license. For the full content # of this license, see the COPYING file at the top level of this # source tree. # Upon successful completion, these functions shall return zero; # otherwise, an error number shall be returned to indicate the error. # This is tested implicitly via assertion 1. echo "Tested implicitly via assertion 1. See output for status" exit 0 posixtestsuite/conformance/interfaces/pthread_barrier_destroy/1-1.c0100644000000000000000000000227407705073032024666 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * * pthread_barrier_destroy() * * * The pthread_barrier_destroy( ) function shall destroy the barrier * referenced by barrier and release any resources used by the barrier. * * Steps: * 1. Main initialize barrier with count 2 * 2. Main destroy the barrier * 3. Repeat step 1,2 for N times */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include "posixtest.h" static pthread_barrier_t barrier; #define LOOP_NUM 5 int main() { int cnt; int rc; for(cnt = 0; cnt < LOOP_NUM; cnt++) { if(pthread_barrier_init(&barrier, NULL, 2) != 0) { printf("Test FAILED: Error at pthread_barrier_init()\n"); return PTS_FAIL; } rc = pthread_barrier_destroy(&barrier); if(rc != 0) { printf("Test FAILED: Error at pthread_barrier_destroy() " " return code: %d, %s\n", rc, strerror(rc)); return PTS_FAIL; } } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_barrier_destroy/assertions.xml0100644000000000000000000000151707705073032027137 0ustar rootroot The pthread_barrier_destroy( ) function shall destroy the barrier referenced by barrier and release any resources used by the barrier. The pthread_barrier_destroy( ) function may fail if: [EBUSY] The implementation has detected an attempt to destroy a barrier while it is in use (for example, while being used in a pthread_barrier_wait( ) call) by another thread. [EINVAL] The value specified by barrier is invalid. Upon successful completion, these functions shall return zero; otherwise, an error number shall be returned to indicate the error. These functions shall not return an error code of EINTR. posixtestsuite/conformance/interfaces/pthread_barrier_destroy/coverage.txt0100644000000000000000000000017707705073032026560 0ustar rootrootThis document defines the coverage for the pthread_barrier_destroy() function: Assertion Tested? 1 YES 2 YES 3 YES NOTE: posixtestsuite/conformance/interfaces/pthread_barrier_destroy/2-1.c0100644000000000000000000000574607705073032024676 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * * pthread_barrier_destroy() * * The pthread_barrier_destroy( ) function may fail if: * [EBUSY] The implementation has detected an attempt to destroy a barrier while it is in * use (for example, while being used in a pthread_barrier_wait( ) call) by another * thread. * * Note: This case will always PASS * * Steps: * 1. Main initialize barrier with count 2 * 2. Main create a child thread * 3. Child thread call pthread_barrier_wait(), should block * 4. Main call pthread_barrier_destroy(), while child is blocking on the barrier */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include #include "posixtest.h" static pthread_barrier_t barrier; static int thread_state; #define NOT_CREATED_THREAD 1 #define ENTERED_THREAD 2 #define EXITING_THREAD 3 static void* fn_chld(void *arg) { int rc = 0; pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL); thread_state = ENTERED_THREAD; /* Child should block here */ printf("child: barrier wait\n"); rc = pthread_barrier_wait(&barrier); if(rc != 0 && rc != PTHREAD_BARRIER_SERIAL_THREAD) { printf("Error: child: pthread_barrier_wait() get unexpected " "return code : %d\n" , rc); exit(PTS_UNRESOLVED); } else if(rc == PTHREAD_BARRIER_SERIAL_THREAD) { printf("child: get PTHREAD_BARRIER_SERIAL_THREAD\n"); } thread_state = EXITING_THREAD; pthread_exit(0); return NULL; } int main() { int cnt = 0; int rc; pthread_t child_thread; printf("main: Initialize barrier with count = 2\n"); if(pthread_barrier_init(&barrier, NULL, 2) != 0) { printf("main: Error at pthread_barrier_init()\n"); return PTS_UNRESOLVED; } printf("main: create child thread\n"); thread_state = NOT_CREATED_THREAD; if(pthread_create(&child_thread, NULL, fn_chld, NULL) != 0) { printf("main: Error at pthread_create()\n"); return PTS_UNRESOLVED; } /* Expect the child to block*/ cnt = 0; do{ sleep(1); }while (thread_state !=EXITING_THREAD && cnt++ < 2); if(thread_state == EXITING_THREAD) { /* child thread did not block */ printf("Test FAILED: child thread did not block on " "pthread_barrier_wait()\n"); exit(PTS_FAIL); } else if(thread_state != ENTERED_THREAD) { printf("Unexpected thread state\n"); exit(PTS_UNRESOLVED); } printf("main: destroy barrier while child is waiting\n"); rc = pthread_barrier_destroy(&barrier); if(rc == EBUSY) { printf("main: correctly got EBUSY\n"); printf("Test PASSED\n"); } else { printf("main: got return code: %d, %s\n", rc, strerror(rc)); printf("Test PASSED: Note*: Expected EBUSY, but standard says 'may' fail.\n"); } /* Cleanup (cancel thread in case it is still blocking */ pthread_cancel(child_thread); return PTS_PASS; } posixtestsuite/conformance/interfaces/sched_setscheduler/0040755000000000000000000000000010515625233023153 5ustar rootrootposixtestsuite/conformance/interfaces/sched_setscheduler/8-1.sh0100755000000000000000000000061307652173250024021 0ustar rootroot#! /bin/sh # # Test that the sched_setscheduler() function is considered successful when it # succeeds in setting the scheduling policy and scheduling parameters of the # process specified by pid to the values specified by policy and the structure # pointed to by param, respectively. # # This is tested implicitly via assertions 1 and 4. echo "Tested implicitly via assertions 1 and 4." exit 0posixtestsuite/conformance/interfaces/sched_setscheduler/19-2.c0100644000000000000000000000322210234132770023700 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * * Test that sched_setscheduler() sets errno == EINVAL when the * sched_ss_low_priority member is not within the inclusive priority range for * the sporadic server policy. * * @pt:SS */ #include #include #include #include "posixtest.h" #if defined(_POSIX_SPORADIC_SERVER)&&(_POSIX_SPORADIC_SERVER != -1) int main(){ int invalid_priority, result; struct sched_param param; invalid_priority = sched_get_priority_max(SCHED_SPORADIC); if(invalid_priority == -1){ perror("An error occurs when calling sched_get_priority_max()"); return PTS_UNRESOLVED; } /* set an invalid priority */ invalid_priority++; param.sched_ss_low_priority = invalid_priority; result = sched_setscheduler(0, SCHED_SPORADIC, ¶m); if(result == -1 && errno == EINVAL){ printf("Test PASSED\n"); return PTS_PASS; } else if(result != -1) { printf("The returned code is not -1.\n"); return PTS_FAIL; } else if(errno == EPERM) { printf("This process does not have the permission to set its own scheduling policy.\nTry to launch this test as root.\n"); return PTS_UNRESOLVED; } else { perror("Unknow error"); return PTS_FAIL; } } #else int main() { printf("Does not support SS (SPORADIC SERVER)\n"); return PTS_UNSUPPORTED; } #endif posixtestsuite/conformance/interfaces/sched_setscheduler/17-7.c0100644000000000000000000000570707652173247023733 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * * Test that the policy and scheduling parameters remain unchanged when no * process can be found corresponding to that specified by pid. * * The test create a child process which exit immediately and call * sched_setscheduler with the pid of defunct child. * Steps: * 1. Get the old policy and priority. * 2. Create a child process which exit immediately. * 3. Wait for child to exit. * 4. Call sched_setscheduler with the pid of defunct child. * 5. Check that the policy and priority have not changed. */ #include #include #include #include #include #include #include "posixtest.h" int main(){ int max_priority, old_priority, old_policy, new_policy, policy; int child_pid, stat_loc; struct sched_param param; if(sched_getparam(getpid(), ¶m) == -1) { perror("An error occurs when calling sched_getparam()"); return PTS_UNRESOLVED; } old_priority = param.sched_priority; old_policy = sched_getscheduler(getpid()); if(old_policy == -1) { perror("An error occurs when calling sched_getscheduler()"); return PTS_UNRESOLVED; } /* Make sure that policy != old_policy */ policy = old_policy == SCHED_FIFO ? SCHED_RR : SCHED_FIFO; /* Make sure that param.sched_priority != old_priority */ max_priority = sched_get_priority_max(policy); param.sched_priority = (old_priority == max_priority) ? sched_get_priority_min(policy) : max_priority; /* Create a child process which exit immediately */ child_pid = fork(); if(child_pid == -1){ perror("An error occurs when calling fork()"); return PTS_UNRESOLVED; } else if (child_pid == 0){ exit(0); } /* Wait for the child process to exit */ if(wait(&stat_loc) == -1){ perror("An error occurs when calling wait()"); return PTS_UNRESOLVED; } /* Assume the pid is not yet reatributed to an other process */ sched_setscheduler(child_pid, policy, ¶m); if(sched_getparam(getpid(), ¶m) != 0) { perror("An error occurs when calling sched_getparam()"); return PTS_UNRESOLVED; } new_policy = sched_getscheduler(getpid()); if(new_policy == -1) { perror("An error occurs when calling sched_getscheduler()"); return PTS_UNRESOLVED; } if(old_policy == new_policy && old_priority == param.sched_priority) { printf("Test PASSED\n"); return PTS_PASS; } if(param.sched_priority != old_priority) { printf("The param has changed\n"); } if(new_policy != old_policy) { printf("The policy has changed\n"); } return PTS_FAIL; } posixtestsuite/conformance/interfaces/sched_setscheduler/22-2.c0100644000000000000000000000477007656204776023727 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that the underlying kernel-scheduled entities for the process * contention scope threads that are created after this call completes inherit * their scheduling parameters from the process. */ #include #include #include #include #include #include "posixtest.h" void * runner(void * arg) { while(1) sleep(1); return NULL; } int main() { int new_priority, max_priority, policy, result; struct sched_param param; pthread_t tid; pthread_attr_t attr; if(sched_getparam(getpid(), ¶m) != 0){ perror("An error occurs when calling sched_getparam()"); pthread_exit((void*)-1); } /* Make sure new_priority != old_priority */ max_priority = sched_get_priority_max(SCHED_FIFO); new_priority = (param.sched_priority == max_priority) ? sched_get_priority_min(SCHED_FIFO) : max_priority; param.sched_priority = new_priority; if(sched_setscheduler(getpid(), SCHED_FIFO, ¶m) != 0){ if(errno == EPERM) { printf("This process does not have the permission to set its own scheduling policy.\nTry to launch this test as root.\n"); return PTS_UNRESOLVED; } perror("An error occurs when calling sched_setscheduler()"); return PTS_UNRESOLVED; } if(pthread_attr_init(&attr) != 0) { printf("An error occurs when calling pthread_attr_init()"); return PTS_UNRESOLVED; } result = pthread_attr_setscope(&attr, PTHREAD_SCOPE_PROCESS); if(result == ENOTSUP) { printf("Process contention scope threads are not supported.\n"); return PTS_UNSUPPORTED; } else if(result != 0) { printf("An error occurs when calling pthread_attr_setscope()"); return PTS_UNRESOLVED; } if(pthread_create(&tid, &attr, runner, NULL) != 0) { printf("An error occurs when calling pthread_create()"); return PTS_UNRESOLVED; } if(pthread_getschedparam(tid , &policy, ¶m) != 0) { printf("An error occurs when calling pthread_getschedparam()"); return PTS_UNRESOLVED; } pthread_cancel(tid); if(param.sched_priority == new_priority){ printf("Test PASSED\n"); return PTS_PASS; } printf("The thread does not inherit the right param.\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sched_setscheduler/15-1.c0100644000000000000000000000440407656204776023722 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that the underlying kernel-scheduled entities for the process * contention scope threads have their scheduling policy changed to the * value specified in param. */ #include #include #include #include #include #include "posixtest.h" void * runner(void * arg) { while(1) sleep(1); return NULL; } int main() { int new_policy, policy, result; struct sched_param param; pthread_t tid; pthread_attr_t attr; /* Make sure new policy != old policy */ new_policy = (sched_getscheduler(getpid()) == SCHED_FIFO) ? SCHED_RR : SCHED_FIFO; if(pthread_attr_init(&attr) != 0) { printf("An error occurs when calling pthread_attr_init()"); return PTS_UNRESOLVED; } result = pthread_attr_setscope(&attr, PTHREAD_SCOPE_PROCESS); if(result == ENOTSUP) { printf("Process contention scope threads are not supported.\n"); return PTS_UNSUPPORTED; } else if(result != 0) { printf("An error occurs when calling pthread_attr_setscope()"); return PTS_UNRESOLVED; } if(pthread_create(&tid, &attr, runner, NULL) != 0) { printf("An error occurs when calling pthread_create()"); return PTS_UNRESOLVED; } param.sched_priority = sched_get_priority_min(new_policy); if(sched_setscheduler(getpid(), new_policy, ¶m) != 0){ if(errno == EPERM) { printf("This process does not have the permission to set its own scheduling policy.\nTry to launch this test as root.\n"); return PTS_UNRESOLVED; } perror("An error occurs when calling sched_setscheduler()"); return PTS_UNRESOLVED; } if(pthread_getschedparam(tid , &policy, ¶m) != 0) { printf("An error occurs when calling pthread_getschedparam()"); return PTS_UNRESOLVED; } pthread_cancel(tid); if(policy == new_policy){ printf("Test PASSED\n"); return PTS_PASS; } printf("sched_setscheduler() does not set the right policy.\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sched_setscheduler/17-1.c0100644000000000000000000000560610234132770023705 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * * Test that the policy and scheduling parameters remain unchanged when the * sched_priority member is not within the inclusive priority range for the * scheduling policy. * * Test is done for all policy defined in the spec into a loop. * Steps (into loop): * 1. Get the old policy and priority. * 2. Call sched_setscheduler with invalid args. * 3. Check that the policy and priority have not changed. */ #include #include #include #include #include "posixtest.h" struct unique { int value; char *name; } sym[] = { { SCHED_FIFO, "SCHED_FIFO" }, { SCHED_RR, "SCHED_RR" }, #if defined(_POSIX_SPORADIC_SERVER)&&(_POSIX_SPORADIC_SERVER != -1) || defined(_POSIX_THREAD_SPORADIC_SERVER)&&(_POSIX_THREAD_SPORADIC_SERVER != -1) { SCHED_SPORADIC,"SCHED_SPORADIC" }, #endif { SCHED_OTHER, "SCHED_OTHER" }, { 0, 0 } }; int main(){ int policy, invalid_priority, result = PTS_PASS; int old_priority, old_policy, new_policy; struct sched_param param; struct unique *tst; tst = sym; while (tst->name) { policy = tst->value; fflush(stderr); printf("Policy: %s\n", tst->name); fflush(stdout); if(sched_getparam(getpid(), ¶m) != 0) { perror("An error occurs when calling sched_getparam()"); return PTS_UNRESOLVED; } old_priority = param.sched_priority; old_policy = sched_getscheduler(getpid()); if(old_policy == -1) { perror("An error occurs when calling sched_getscheduler()"); return PTS_UNRESOLVED; } invalid_priority = sched_get_priority_max(policy); if(invalid_priority == -1){ perror("An error occurs when calling sched_get_priority_max()"); return PTS_UNRESOLVED; } /* set an invalid priority */ invalid_priority++; param.sched_priority = invalid_priority; sched_setscheduler(0, policy, ¶m); if(sched_getparam(getpid(), ¶m) != 0) { perror("An error occurs when calling sched_getparam()"); return PTS_UNRESOLVED; } new_policy = sched_getscheduler(getpid()); if(new_policy == -1) { perror("An error occurs when calling sched_getscheduler()"); return PTS_UNRESOLVED; } if(old_policy == new_policy && old_priority == param.sched_priority) { printf(" OK\n"); } else { if(param.sched_priority != old_priority) { printf(" The param has changed\n"); } if(new_policy != old_policy) { printf(" The policy has changed\n"); } result = PTS_FAIL; } tst++; } if(result == PTS_PASS) { printf("Test PASSED\n"); } return result; } posixtestsuite/conformance/interfaces/sched_setscheduler/19-1.c0100644000000000000000000000424110234132770023701 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * * Test that sched_setscheduler() sets errno == EINVAL when the sched_priority * member is not within the inclusive priority range for the scheduling policy. * * Test is done for all policy defined in the spec into a loop. */ #include #include #include #include #include "posixtest.h" struct unique { int value; char *name; } sym[] = { { SCHED_FIFO, "SCHED_FIFO" }, { SCHED_RR, "SCHED_RR" }, #if defined(_POSIX_SPORADIC_SERVER)&&(_POSIX_SPORADIC_SERVER != -1) || defined(_POSIX_THREAD_SPORADIC_SERVER)&&(_POSIX_THREAD_SPORADIC_SERVER != -1) { SCHED_SPORADIC,"SCHED_SPORADIC" }, #endif { SCHED_OTHER, "SCHED_OTHER" }, { 0, 0 } }; int main(){ int policy, invalid_priority, tmp, result = PTS_PASS; struct sched_param param; struct unique *tst; tst = sym; while (tst->name) { policy = tst->value; fflush(stderr); printf("Policy: %s\n", tst->name); fflush(stdout); invalid_priority = sched_get_priority_max(policy); if(invalid_priority == -1){ perror("An error occurs when calling sched_get_priority_max()"); return PTS_UNRESOLVED; } /* set an invalid priority */ invalid_priority++; param.sched_priority = invalid_priority; tmp = sched_setscheduler(0, policy, ¶m); if(tmp == -1 && errno == EINVAL) { printf(" OK\n"); } else if(tmp != -1) { printf(" The returned code is not -1.\n"); result = PTS_FAIL; } else if(errno == EPERM) { printf(" This process does not have the permission to set its own scheduling policy.\n Try to launch this test as root.\n"); if(result != PTS_FAIL) { result = PTS_UNRESOLVED; } } else { perror(" Unknow error"); result = PTS_FAIL; } tst++; } if(result == PTS_PASS) { printf("Test PASSED\n"); } return result; } posixtestsuite/conformance/interfaces/sched_setscheduler/5-1.c0100644000000000000000000000156207660450107023625 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Will not test the condition under which one process has the appropriate * privilege to change the scheduling parameters of another process because * they are implementation-defined. */ #include #include "posixtest.h" int main() { printf("Will not test the condition under which one process has the appropriate\nprivilege to change the scheduling parameters of another process because \nthey are implementation-defined.\n"); return PTS_UNTESTED; } posixtestsuite/conformance/interfaces/sched_setscheduler/17-2.c0100644000000000000000000000457110234132770023706 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * * Test that the policy and scheduling parameters remain unchanged when the * sched_ss_low_priority member is not within the inclusive priority range for * the sporadic server policy. * * Steps: * 1. Get the old policy and priority. * 2. Call sched_setscheduler with invalid args. * 3. Check that the policy and priority have not changed. * * @pt:SS */ #include #include #include #include #include "posixtest.h" #if defined(_POSIX_SPORADIC_SERVER)&&(_POSIX_SPORADIC_SERVER != -1) int main(){ int invalid_priority; int old_priority, old_policy, new_policy; struct sched_param param; if(sched_getparam(getpid(), ¶m) != 0) { perror("An error occurs when calling sched_getparam()"); return PTS_UNRESOLVED; } old_priority = param.sched_priority; old_policy = sched_getscheduler(getpid()); if(old_policy == -1) { perror("An error occurs when calling sched_getscheduler()"); return PTS_UNRESOLVED; } invalid_priority = sched_get_priority_max(SCHED_SPORADIC); if(invalid_priority == -1){ perror("An error occurs when calling sched_get_priority_max()"); return PTS_UNRESOLVED; } /* set an invalid priority */ invalid_priority++; param.sched_ss_low_priority = invalid_priority; sched_setscheduler(0, SCHED_SPORADIC, ¶m); if(sched_getparam(getpid(), ¶m) != 0) { perror("An error occurs when calling sched_getparam()"); return PTS_UNRESOLVED; } new_policy = sched_getscheduler(getpid()); if(new_policy == -1) { perror("An error occurs when calling sched_getscheduler()"); return PTS_UNRESOLVED; } if(old_policy == new_policy && old_priority == param.sched_priority) { printf("Test PASSED\n"); return PTS_PASS; } if(param.sched_priority != old_priority) { printf("The param has changed\n"); } if(new_policy != old_policy) { printf("The policy has changed\n"); } return PTS_FAIL; } #else int main() { printf("Does not support SS (SPORADIC SERVER)\n"); return PTS_UNSUPPORTED; } #endif posixtestsuite/conformance/interfaces/sched_setscheduler/4-1.c0100644000000000000000000000463007657666421023641 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * * Test that the scheduling policy and scheduling parameters are set for * the calling process when pid == 0. */ #include #include #include #include #include "posixtest.h" int main(){ int result, new_priority, old_priority, max_prio; int old_policy, new_policy, test_policy; struct sched_param param; if(sched_getparam(getpid(), ¶m) != 0) { perror("An error occurs when calling sched_getparam()"); return PTS_UNRESOLVED; } old_policy = sched_getscheduler(getpid()); if(old_policy == -1) { perror("An error occurs when calling sched_getscheduler()"); return PTS_UNRESOLVED; } /* Make sure new_policy != old_policy */ new_policy = (old_policy == SCHED_FIFO) ? SCHED_RR : SCHED_FIFO; /* Make sure new_priority != old_priority */ max_prio = sched_get_priority_max(new_policy); old_priority = param.sched_priority; new_priority = (old_priority == max_prio) ? (param.sched_priority = sched_get_priority_min(new_policy)) : (param.sched_priority = max_prio); result = sched_setscheduler(0, new_policy, ¶m); if(sched_getparam(getpid(), ¶m) != 0){ perror("An error occurs when calling sched_getparam()"); return PTS_UNRESOLVED; } test_policy = sched_getscheduler(getpid()); if(test_policy == -1) { perror("An error occurs when calling sched_getscheduler()"); return PTS_UNRESOLVED; } if(result != -1 && param.sched_priority == new_priority && test_policy == new_policy) { printf("Test PASSED\n"); return PTS_PASS; } else if(result != -1 && (param.sched_priority == old_priority || test_policy == old_policy)) { if(param.sched_priority == old_priority) { printf("The param does not change\n"); } if(test_policy == old_policy) { printf("The policy does not change\n"); } return PTS_FAIL; } else if(result == -1 && errno == EPERM) { printf("The process have not permission to change its own policy.\nTry to launch this test as root.\n"); return PTS_UNRESOLVED; } perror("Unknow error"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sched_setscheduler/17-6.c0100644000000000000000000000537707652173246023734 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * * Test that the policy and scheduling parameters remain unchanged when the * requesting process does not have permission to set the scheduling parameters * for the specified process, or does not have the appropriate privilege to * invoke sched_setscheduler(). * * Atempt to change the policy of the process whose ID is 1 which is generally * belongs to root. This test can not be run by root. * Steps: * 1. Get the old policy and priority. * 2. Call sched_setscheduler with pid arg == 1. * 3. Check that the policy and priority have not changed. */ #include #include #include #include #include "posixtest.h" int main(){ int max_priority, old_priority, old_policy, new_policy, policy; struct sched_param param; /* We assume process Number 1 is created by root */ /* and can only be accessed by root */ /* This test should be run under standard user permissions */ if (getuid() == 0) { puts("Run this test case as a Regular User, but not ROOT"); return PTS_UNTESTED; } if(sched_getparam(getpid(), ¶m) == -1) { perror("An error occurs when calling sched_getparam()"); return PTS_UNRESOLVED; } old_priority = param.sched_priority; old_policy = sched_getscheduler(getpid()); if(old_policy == -1) { perror("An error occurs when calling sched_getscheduler()"); return PTS_UNRESOLVED; } /* Make sure that policy != old_policy */ policy = old_policy == SCHED_FIFO ? SCHED_RR : SCHED_FIFO; /* Make sure that param.sched_priority != old_priority */ max_priority = sched_get_priority_max(policy); param.sched_priority = (old_priority == max_priority) ? sched_get_priority_min(policy) : max_priority; sched_setscheduler(1, policy, ¶m); if(sched_getparam(getpid(), ¶m) != 0) { perror("An error occurs when calling sched_getparam()"); return PTS_UNRESOLVED; } new_policy = sched_getscheduler(getpid()); if(new_policy == -1) { perror("An error occurs when calling sched_getscheduler()"); return PTS_UNRESOLVED; } if(old_policy == new_policy && old_priority == param.sched_priority) { printf("Test PASSED\n"); return PTS_PASS; } if(param.sched_priority != old_priority) { printf("The param has changed\n"); } if(new_policy != old_policy) { printf("The policy has changed\n"); } return PTS_FAIL; } posixtestsuite/conformance/interfaces/sched_setscheduler/22-1.c0100644000000000000000000000463307656204776023724 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that the underlying kernel-scheduled entities for the process * contention scope threads that are created after this call completes inherit * their scheduling policy from the process. */ #include #include #include #include #include #include "posixtest.h" void * runner(void * arg) { while(1) sleep(1); return NULL; } int main() { int new_policy, policy, result; struct sched_param param; pthread_t tid; pthread_attr_t attr; if(sched_getparam(getpid(), ¶m) != 0){ perror("An error occurs when calling sched_getparam()"); pthread_exit((void*)-1); } /* Make sure new policy != old policy */ new_policy = (sched_getscheduler(getpid()) == SCHED_FIFO) ? SCHED_RR : SCHED_FIFO; param.sched_priority = sched_get_priority_min(new_policy); if(sched_setscheduler(getpid(), new_policy, ¶m) != 0){ if(errno == EPERM) { printf("This process does not have the permission to set its own scheduling policy.\nTry to launch this test as root.\n"); return PTS_UNRESOLVED; } perror("An error occurs when calling sched_setscheduler()"); return PTS_UNRESOLVED; } if(pthread_attr_init(&attr) != 0) { printf("An error occurs when calling pthread_attr_init()"); return PTS_UNRESOLVED; } result = pthread_attr_setscope(&attr, PTHREAD_SCOPE_PROCESS); if(result == ENOTSUP) { printf("Process contention scope threads are not supported.\n"); return PTS_UNSUPPORTED; } else if(result != 0) { printf("An error occurs when calling pthread_attr_setscope()"); return PTS_UNRESOLVED; } if(pthread_create(&tid, &attr, runner, NULL) != 0) { printf("An error occurs when calling pthread_create()"); return PTS_UNRESOLVED; } if(pthread_getschedparam(tid , &policy, ¶m) != 0) { printf("An error occurs when calling pthread_getschedparam()"); return PTS_UNRESOLVED; } pthread_cancel(tid); if(policy == new_policy){ printf("Test PASSED\n"); return PTS_PASS; } printf("The thread does not inherit the right policy.\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sched_setscheduler/14-1.c0100644000000000000000000000144307660450107023703 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Will not test that the underlying kernel-scheduled entities for the system * contention scope threads are not be affected by this function. */ #include #include "posixtest.h" int main() { printf("Will not test that the underlying kernel-scheduled entities for the system\ncontention scope threads are not be affected by sched_setscheduler().\n"); return PTS_UNTESTED; } posixtestsuite/conformance/interfaces/sched_setscheduler/3-1.sh0100755000000000000000000000045607652173247024027 0ustar rootroot#! /bin/sh # # Test that the scheduling policy and scheduling parameters are set for the # process whose process ID is equal to pid when such a process exists and the # the calling process has permission. # # This is tested implicitly via assertion 1. echo "Tested implicitly via assertion 1." exit 0posixtestsuite/conformance/interfaces/sched_setscheduler/12-1.c0100644000000000000000000000137707776521003023711 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Will not test that sched_setscheduler have no effect on the scheduling of * threads with system scheduling contention scope. */ #include #include "posixtest.h" int main() { printf("Will not test that sched_setscheduler have no effect on the scheduling of\n threads with system scheduling contention scope.\n"); return PTS_UNTESTED; } posixtestsuite/conformance/interfaces/sched_setscheduler/1-1.c0100644000000000000000000000502710234132770023613 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * * Test that sched_setscheduler() sets the scheduling policy and scheduling * parameters of the process specified by pid to policy and the parameters * specified in the sched_param structure pointed to by param, respectively. * * For all policy describe in the spec, the test will check the policy and the * param of the process after the call of sched_setscheduler. */ #include #include #include #include #include "posixtest.h" struct unique { int value; char *name; } sym[] = { { SCHED_FIFO, "SCHED_FIFO" }, { SCHED_RR, "SCHED_RR" }, #if defined(_POSIX_SPORADIC_SERVER)&&(_POSIX_SPORADIC_SERVER != -1) || defined(_POSIX_THREAD_SPORADIC_SERVER)&&(_POSIX_THREAD_SPORADIC_SERVER != -1) { SCHED_SPORADIC,"SCHED_SPORADIC" }, #endif { SCHED_OTHER, "SCHED_OTHER" }, { 0, 0 } }; int main(int argc, char **argv) { int tmp, policy, priority, result = PTS_PASS; struct sched_param param; struct unique *tst; tst = sym; while (tst->name) { fflush(stderr); printf("Policy: %s\n", tst->name); fflush(stdout); policy = tst->value; priority = ( sched_get_priority_min(policy) + sched_get_priority_max(policy) ) / 2; param.sched_priority = priority; tmp = sched_setscheduler(getpid(), policy, ¶m); if(tmp == -1 || errno != 0) { if(errno == EPERM){ printf(" The process do not have permission to change its own scheduler\n Try to run this test as root.\n"); } else { printf(" Error calling sched_setscheduler() for %s policy\n", tst->name); } if(result != PTS_FAIL) result = PTS_UNRESOLVED; tst++; continue; } if(sched_getparam(getpid(), ¶m) != 0) { perror("Error calling sched_getparam()"); return PTS_UNRESOLVED; } if(policy != sched_getscheduler(getpid())){ printf(" sched_setscheduler() does not set the policy to %s.\n", tst->name); result = PTS_FAIL; } if(priority != param.sched_priority) { printf(" sched_setscheduler() does not set the right param for %s policy.\n", tst->name); result = PTS_FAIL; } tst++; } if(result == PTS_PASS) printf("Test PASSED\n"); return result; } posixtestsuite/conformance/interfaces/sched_setscheduler/9-1.c0100644000000000000000000000157207656204776023650 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that the sched_ss_repl_period and sched_ss_init_budget members of the * param argument represent the time parameters to be used by the sporadic * server scheduling policy for the target process. * * @pt:SS */ #include #include #include "posixtest.h" #ifdef _POSIX_SPORADIC_SERVER int main() { printf("Not yet tested.\n"); return PTS_UNTESTED; } #else int main() { printf("Does not support SS (SPORADIC SERVER)\n"); return PTS_UNSUPPORTED; } #endif posixtestsuite/conformance/interfaces/sched_setscheduler/20-1.c0100644000000000000000000000457110044453562023703 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * * Test that sched_setscheduler() sets errno == EPERM when the requesting * process does not have permission to set the scheduling parameters for the * specified process, or does not have the appropriate privilege to invoke * sched_setscheduler(). * * Atempt to change the policy of the process whose ID is 1 which is generally * belongs to root. This test can not be run by root. */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include #include "posixtest.h" /** Set the euid of this process to a non-root uid */ int set_nonroot() { struct passwd *pw; setpwent(); /* search for the first user which is non root */ while((pw = getpwent()) != NULL) if(strcmp(pw->pw_name, "root")) break; endpwent(); if(pw == NULL) { printf("There is no other user than current and root.\n"); return 1; } if(setuid(pw->pw_uid) != 0) { if(errno == EPERM) { printf("You don't have permission to change your UID.\n"); return 1; } perror("An error occurs when calling seteuid()"); return 1; } printf("Testing with user '%s' (euid: %d)(uid: %d)\n", pw->pw_name, (int)geteuid(), (int)getuid()); return 0; } int main(){ int result; struct sched_param param; /* We assume process Number 1 is created by root */ /* and can only be accessed by root */ /* This test should be run under standard user permissions */ if (getuid() == 0) { if (set_nonroot() != 0) { printf("Cannot run this test as non-root user\n"); return PTS_UNTESTED; } } param.sched_priority = sched_get_priority_max(SCHED_FIFO); result = sched_setscheduler(1, SCHED_FIFO, ¶m); if(result == -1 && errno == EPERM) { printf("Test PASSED\n"); return PTS_PASS; } else if(errno != EPERM) { perror("errno is not EPERM"); return PTS_FAIL; } else { printf("The returned code is not -1.\n"); return PTS_FAIL; } } posixtestsuite/conformance/interfaces/sched_setscheduler/11-1.c0100644000000000000000000000165007656204776023716 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that the sched_ss_low_priority, sched_ss_repl_period, and * sched_ss_init_budget members of the param argument have no effect on the * scheduling behavior if the scheduling policy of the target process is either * SCHED_FIFO or SCHED_RR. * * @pt:SS */ #include #include #include "posixtest.h" #ifdef _POSIX_SPORADIC_SERVER int main() { printf("Not yet tested.\n"); return PTS_UNTESTED; } #else int main() { printf("Does not support SS (SPORADIC SERVER)\n"); return PTS_UNSUPPORTED; } #endif posixtestsuite/conformance/interfaces/sched_setscheduler/6-1.c0100644000000000000000000000150607660450107023624 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Will not test that implementations may require that the requesting process * have permission to set its own scheduling parameters or those of another * process. */ #include #include "posixtest.h" int main() { printf("Will not test that implementations may require that the requesting process\nhave permission to set its own scheduling parameters or those of another\nprocess.\n"); return PTS_UNTESTED; } posixtestsuite/conformance/interfaces/sched_setscheduler/19-3.c0100644000000000000000000000342110234132770023702 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * * Test that sched_setscheduler() sets errno == EINVAL when the * sched_ss_repl_period is not greater than or equal to the * sched_ss_init_budget member. * * @pt:SS */ #include #include #include #include #include "posixtest.h" #if defined(_POSIX_SPORADIC_SERVER)&&(_POSIX_SPORADIC_SERVER != -1) int main(){ int policy, result; struct sched_param param; if(sched_getparam(0, ¶m) != 0) { perror("An error occurs when calling sched_getparam()"); return PTS_UNRESOLVED; } /* set a sched_ss_repl_period lower than the sched_ss_init_budget */ param.sched_ss_repl_period.tv_sec = 1; param.sched_ss_repl_period.tv_nsec = 0; param.sched_ss_init_budget.tv_sec = 2; param.sched_ss_init_budget.tv_nsec = 0; param.sched_priority = sched_get_priority_max(SCHED_SPORADIC); result = sched_setscheduler(0, SCHED_SPORADIC, ¶m); if(result == -1 && errno == EINVAL){ printf("Test PASSED\n"); return PTS_PASS; } else if(result != -1) { printf("The returned code is not -1.\n"); return PTS_FAIL; } else if(errno == EPERM) { printf("This process does not have the permission to set its own scheduling policy.\nTry to launch this test as root.\n"); return PTS_UNRESOLVED; } perror("Unknow error"); return PTS_FAIL; } #else int main() { printf("Does not support SS (SPORADIC SERVER)\n"); return PTS_UNSUPPORTED; } #endif posixtestsuite/conformance/interfaces/sched_setscheduler/10-1.c0100644000000000000000000000161307656204776023714 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that the sched_ss_max_repl member of the param argument represent the * maximum number of replenishments that are allowed to be pending * simultaneously for the process scheduled under the SCHED_SPORADIC policy. * * @pt:SS */ #include #include #include "posixtest.h" #ifdef _POSIX_SPORADIC_SERVER int main() { printf("Not yet tested.\n"); return PTS_UNTESTED; } #else int main() { printf("Does not support SS (SPORADIC SERVER)\n"); return PTS_UNSUPPORTED; } #endif posixtestsuite/conformance/interfaces/sched_setscheduler/13-1.c0100644000000000000000000000130207660450107023674 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Will not test that the threads scheduling policy and associated parameters * are not affected. */ #include #include "posixtest.h" int main() { printf("Will not test that the threads scheduling policy and associated parameters\nare not affected.\n"); return PTS_UNTESTED; } posixtestsuite/conformance/interfaces/sched_setscheduler/17-5.c0100644000000000000000000000441510053271774023715 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * * Test that the policy and scheduling parameters remain unchanged when the * policy value is not defined in the sched.h header. * * The test attempt to set the policy to a very improbable value. * Steps: * 1. Get the old policy and priority. * 2. Call sched_setscheduler with invalid args. * 3. Check that the policy and priority have not changed. */ #include #include #include #include #include "posixtest.h" int main(){ int old_priority, old_policy, new_policy; struct sched_param param; int invalid_policy; invalid_policy = 0; /* Linux does not treat minus value as invalid for policy */ while(invalid_policy == SCHED_OTHER || invalid_policy == SCHED_FIFO || invalid_policy == SCHED_RR) invalid_policy++; if(sched_getparam(getpid(), ¶m) == -1) { perror("An error occurs when calling sched_getparam()"); return PTS_UNRESOLVED; } old_priority = param.sched_priority; old_policy = sched_getscheduler(getpid()); if(old_policy == -1) { perror("An error occurs when calling sched_getscheduler()"); return PTS_UNRESOLVED; } sched_setscheduler(0, invalid_policy, ¶m); if(errno == 0) { printf("No error occurs, could %i be a valid value for the scheduling policy ???\n", invalid_policy); return PTS_UNRESOLVED; } if(sched_getparam(getpid(), ¶m) != 0) { perror("An error occurs when calling sched_getparam()"); return PTS_UNRESOLVED; } new_policy = sched_getscheduler(getpid()); if(new_policy == -1) { perror("An error occurs when calling sched_getscheduler()"); return PTS_UNRESOLVED; } if(old_policy == new_policy && old_priority == param.sched_priority) { printf("Test PASSED\n"); return PTS_PASS; } if(param.sched_priority != old_priority) { printf("The param has changed\n"); } if(new_policy != old_policy) { printf("The policy has changed\n"); } return PTS_FAIL; } posixtestsuite/conformance/interfaces/sched_setscheduler/17-3.c0100644000000000000000000000460210234132770023702 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * * Test that the policy and scheduling parameters remain unchanged when the * sched_ss_repl_period is not greater than or equal to the * sched_ss_init_budget member. * * Steps: * 1. Get the old policy and priority. * 2. Call sched_setscheduler with invalid args. * 3. Check that the policy and priority have not changed. * * @pt:SS */ #include #include #include #include #include "posixtest.h" #if defined(_POSIX_SPORADIC_SERVER)&&(_POSIX_SPORADIC_SERVER != -1) int main(){ int policy, result; int old_priority, old_policy, new_policy; struct sched_param param; if(sched_getparam(getpid(), ¶m) != 0) { perror("An error occurs when calling sched_getparam()"); return PTS_UNRESOLVED; } old_priority = param.sched_priority; old_policy = sched_getscheduler(getpid()); if(old_policy == -1) { perror("An error occurs when calling sched_getscheduler()"); return PTS_UNRESOLVED; } /* set a sched_ss_repl_period lower than the sched_ss_init_budget */ param.sched_ss_repl_period.tv_sec = 1; param.sched_ss_repl_period.tv_nsec = 0; param.sched_ss_init_budget.tv_sec = 2; param.sched_ss_init_budget.tv_nsec = 0; param.sched_priority = sched_get_priority_max(SCHED_SPORADIC); result = sched_setscheduler(0, SCHED_SPORADIC, ¶m); if(sched_getparam(getpid(), ¶m) != 0) { perror("An error occurs when calling sched_getparam()"); return PTS_UNRESOLVED; } new_policy = sched_getscheduler(getpid()); if(new_policy == -1) { perror("An error occurs when calling sched_getscheduler()"); return PTS_UNRESOLVED; } if(old_policy == new_policy && old_priority == param.sched_priority) { printf("Test PASSED\n"); return PTS_PASS; } if(param.sched_priority != old_priority) { printf("The param has changed\n"); } if(new_policy != old_policy) { printf("The policy has changed\n"); } return PTS_FAIL; } #else int main() { printf("Does not support SS (SPORADIC SERVER)\n"); return PTS_UNSUPPORTED; } #endif posixtestsuite/conformance/interfaces/sched_setscheduler/7-1.c0100644000000000000000000000164407660450107023630 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Will not test if implementation-defined restrictions apply as to the * appropriate privileges required to set a process' own scheduling policy, or * another process' scheduling policy, to a particular value. */ #include #include "posixtest.h" int main() { printf("Will not test if implementation-defined restrictions apply as to the\nappropriate privileges required to set a process' own scheduling policy, or\nanother process' scheduling policy, to a particular value.\n"); return PTS_UNTESTED; } posixtestsuite/conformance/interfaces/sched_setscheduler/assertions.xml0100644000000000000000000001367510117555070026077 0ustar rootroot sched_setscheduler() sets the scheduling policy and scheduling parameters of the process specified by pid to policy and the parameters specified in the sched_param structure pointed to by param, respectively If pid is negative, the behavior of sched_setscheduler() is unspecified If a process specified by pid exists, and if the calling process has permission, the scheduling policy and scheduling parameters shall be set for the process whose process ID is equal to pid If pid is zero, the scheduling policy and scheduling parameters shall be set for the calling process The condition under which one process has the appropriate privilege to change the scheduling parameters of another process are implementation-defined Implementations may require that the requesting process have permission to set its own scheduling parameters or those of another process Implementation-defined restrictions may apply as to the appropriate privileges required to set a process' own scheduling policy, or another process' scheduling policy, to a particular value The sched_setscheduler() function shall be considered successful if it succeeds in setting the scheduling policy and scheduling parameters of the process specified by pid to the values specified by policy and the structure pointed to by param, respectively The sched_ss_repl_period and sched_ss_init_budget members of the param argument shall represent the time parameters used by the sporadic server scheduling policy for the target process The sched_ss_max_repl member of the param argument shall represent the maximum number of replenishments that are allowed to be pending simultaneously for the process scheduled under this scheduling policy If the scheduling policy specified by policy is either SCHED_FIFO or SCHED_RR, the sched_ss_low_priority, sched_ss_repl_period, and sched_ss_init_budget members of the param argument shall have no effect on the scheduling behavior For threads with system scheduling contention scope, this function shall have no effect on their scheduling For threads with process scheduling contention scope, the threads' scheduling policy and associated parameters shall not be affected The underlying kernel-scheduled entities for the system contention scope threads shall not be affected by this function The underlying kernel-scheduled entities for the process contention scope threads shall have their scheduling policy and associated scheduling parameters changed to the values specified in policy and param, respectively Upon successful completion, the function shall return the former scheduling policy of the specified process If the sched_setscheduler() function fails to complete successfully, the policy and scheduling parameters shall remain unchanged If the sched_setscheduler() function fails to complete successfully, the function shall return a value of -1 The sched_setscheduler() function shall return EINVAL if the value of the policy parameter is invalid, or one or more of the parameters contained in param is outside the valid range for the specified scheduling policy The sched_setscheduler() function shall return EPERM if the requesting process does not have permission to set either or both of the scheduling parameters or the scheduling policy of the specified process The sched_setscheduler() function shall return ESRCH if no process can be found corresponding to that specified by pid Kernel-scheduled entities for use by process contention scope threads that are created after this call completes shall inherit their scheduling policy and associated scheduling parameters from the process posixtestsuite/conformance/interfaces/sched_setscheduler/21-1.c0100644000000000000000000000361107656203652023706 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * * Test that sched_setscheduler() sets errno == ESRCH when no process can be * found corresponding to that specified by pid. * * The test create a child process which exit immediately and call * sched_setscheduler with the pid of defunct child. */ #include #include #include #include #include #include #include "posixtest.h" int main(){ int result, child_pid, stat_loc; struct sched_param param; param.sched_priority = sched_get_priority_max(SCHED_FIFO); /* Create a child process which exit immediately */ child_pid = fork(); if(child_pid == -1){ perror("An error occurs when calling fork()"); return PTS_UNRESOLVED; } else if (child_pid == 0){ exit(0); } /* Wait for the child process to exit */ if(wait(&stat_loc) == -1){ perror("An error occurs when calling wait()"); return PTS_UNRESOLVED; } /* Assume the pid is not yet reatributed to an other process */ result = sched_setscheduler(child_pid, SCHED_FIFO, ¶m); if(result == -1 && errno == ESRCH) { printf("Test PASSED\n"); return PTS_PASS; } else if(result != -1) { printf("The returned code is not -1.\n"); return PTS_FAIL; } else if (errno == EPERM) { printf("This process does not have the permission to invoke sched_setscheduler().\nTry to launch this test as root.\n"); return PTS_UNRESOLVED; } else { perror("errno is not ESRCH"); return PTS_FAIL; } } posixtestsuite/conformance/interfaces/sched_setscheduler/coverage.txt0100644000000000000000000000107107660450107025506 0ustar rootrootThis document explains why certain assertions were not tested. Assertions not listed here should be covered by the tests in this directory. Assertions Tested ? Remarks 1 YES 2 YES Behavior unspecified 3 YES 4 YES 5 YES Implementation-defined 6 YES may assertion 7 YES Implementation-defined 8 YES 9 YES 10 YES 11 YES 12 YES 13 YES 14 YES 15 YES 16 YES 17 YES 18 YES 19 YES 20 YES 21 YES 22 YESposixtestsuite/conformance/interfaces/sched_setscheduler/17-4.c0100644000000000000000000000456510234132770023713 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * * Test that the policy and scheduling parameters remain unchanged when * the sched_ss_max_repl is not within the inclusive range [1,SS_REPL_MAX] * * Test with a sched_ss_max_repl value of 0. * Steps: * 1. Get the old policy and priority. * 2. Call sched_setscheduler with invalid args. * 3. Check that the policy and priority have not changed. * * @pt:SS */ #include #include #include #include #include "posixtest.h" #if defined(_POSIX_SPORADIC_SERVER)&&(_POSIX_SPORADIC_SERVER != -1) int main(){ int max_priority, old_priority, old_policy, new_policy; struct sched_param param; if(sched_getparam(getpid(), ¶m) == -1) { perror("An error occurs when calling sched_getparam()"); return PTS_UNRESOLVED; } old_priority = param.sched_priority; old_policy = sched_getscheduler(getpid()); if(old_policy == -1) { perror("An error occurs when calling sched_getscheduler()"); return PTS_UNRESOLVED; } /* Make sure that param.sched_priority != old_priority */ max_priority = sched_get_priority_max(SCHED_SPORADIC); param.sched_priority = (old_priority == max_priority) ? sched_get_priority_min(SCHED_SPORADIC) : max_priority; param.sched_ss_max_repl = 0; sched_setscheduler(0, SCHED_SPORADIC, ¶m); if(sched_getparam(getpid(), ¶m) != 0) { perror("An error occurs when calling sched_getparam()"); return PTS_UNRESOLVED; } new_policy = sched_getscheduler(getpid()); if(new_policy == -1) { perror("An error occurs when calling sched_getscheduler()"); return PTS_UNRESOLVED; } if(old_policy == new_policy && old_priority == param.sched_priority) { printf("Test PASSED\n"); return PTS_PASS; } if(param.sched_priority != old_priority) { printf("The param has changed\n"); return PTS_FAIL; } if(new_policy != old_policy) { printf("The policy has changed\n"); return PTS_FAIL; } } #else int main() { printf("Does not support SS (SPORADIC SERVER)\n"); return PTS_UNSUPPORTED; } #endif posixtestsuite/conformance/interfaces/sched_setscheduler/18-1.sh0100755000000000000000000000036007652173247024107 0ustar rootroot#! /bin/sh # # Test that sched_setscheduler() function return a value of -1 when it fails to # complete successfully. # # This is tested implicitly via assertions 19, 20 and 21. echo "Tested implicitly via assertions 19, 20 and 21." exit 0posixtestsuite/conformance/interfaces/sched_setscheduler/15-2.c0100644000000000000000000000475007656204776023727 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that the underlying kernel-scheduled entities for the process * contention scope threads have their scheduling parameters changed to the * value specified in param. */ #include #include #include #include #include #include "posixtest.h" void * runner(void * arg) { while(1) sleep(1); return NULL; } int main() { int new_priority, max_priority, policy, result; struct sched_param param; pthread_t tid; pthread_attr_t attr; if(sched_getparam(getpid(), ¶m) != 0){ perror("An error occurs when calling sched_getparam()"); pthread_exit((void*)-1); } /* Make sure new_priority != old priority */ max_priority = sched_get_priority_max(SCHED_FIFO); new_priority = (param.sched_priority == max_priority) ? sched_get_priority_min(SCHED_FIFO) : max_priority; if(pthread_attr_init(&attr) != 0) { printf("An error occurs when calling pthread_attr_init()"); return PTS_UNRESOLVED; } result = pthread_attr_setscope(&attr, PTHREAD_SCOPE_PROCESS); if(result == ENOTSUP) { printf("Process contention scope threads are not supported.\n"); return PTS_UNSUPPORTED; } else if(result != 0) { printf("An error occurs when calling pthread_attr_setscope()"); return PTS_UNRESOLVED; } if(pthread_create(&tid, &attr, runner, NULL) != 0) { printf("An error occurs when calling pthread_create()"); return PTS_UNRESOLVED; } param.sched_priority = new_priority; if(sched_setscheduler(getpid(), SCHED_FIFO, ¶m) != 0){ if(errno == EPERM) { printf("This process does not have the permission to set its own scheduling policy.\nTry to launch this test as root.\n"); return PTS_UNRESOLVED; } perror("An error occurs when calling sched_setscheduler()"); return PTS_UNRESOLVED; } if(pthread_getschedparam(tid , &policy, ¶m) != 0) { printf("An error occurs when calling pthread_getschedparam()"); return PTS_UNRESOLVED; } pthread_cancel(tid); if(param.sched_priority == new_priority){ printf("Test PASSED\n"); return PTS_PASS; } printf("sched_setscheduler() does not set the right param.\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sched_setscheduler/16-1.c0100644000000000000000000000304007656203652023706 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * * Test that the function return the former scheduling policy of the specified * process upon successful completion. * * Steps: * 1. Get the old policy. * 2. Set a new policy. * 3. Check that sched_setscheduler return the old policy. */ #include #include #include #include #include "posixtest.h" int main(){ int result, old_policy, new_policy; struct sched_param param; old_policy = sched_getscheduler(getpid()); if(old_policy == -1) { perror("An error occurs when calling sched_getscheduler()"); return PTS_UNRESOLVED; } /* Make sure new_policy != old_policy */ new_policy = (old_policy == SCHED_FIFO) ? SCHED_RR : SCHED_FIFO; param.sched_priority = sched_get_priority_max(new_policy); result = sched_setscheduler(0, new_policy, ¶m); if(result == old_policy){ printf("Test PASSED\n"); return PTS_PASS; } else if(result == -1 && errno == EPERM) { printf("The process have not permission to change its own policy.\nTry to launch this test as root.\n"); return PTS_UNRESOLVED; } printf("Returned code == %i.\n", result); perror("Unknow error"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sched_setscheduler/19-5.c0100644000000000000000000000411207656203652023716 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * * Test that sched_setscheduler() sets errno == EINVAL when the policy value is * not defined in the sched.h header. * * Assume that the header does not defined a scheduling policy with a value * of -1. (It is more coherent with the specificationS of sched_getscheduler * and sched_setscheduler for which the result code -1 indicate an error.) * If no error occurs whith -1, the test will run sched_setscheduler with the * very improbable policy value INVALID_POLICY. */ #include #include #include #include #include "posixtest.h" /* There is no chance that a scheduling policy has such a value */ #define INVALID_POLICY -27367 int main(){ int result; struct sched_param param; param.sched_priority = 0; result = sched_setscheduler(0, -1, ¶m); if(result == -1 && errno == EINVAL){ printf("Test PASSED\n"); return PTS_PASS; } else if(errno == EPERM){ printf("This process does not have the permission to set its own scheduling policy.\nTry to launch this test as root.\n"); return PTS_UNRESOLVED; } else if(errno == 0) { printf("No error occurs, check if -1 a valid value for the scheduling policy.\n"); } else { perror("Unknow error"); return PTS_FAIL; } printf("Testing with very improbable policy value %i:\n", INVALID_POLICY); result = sched_setscheduler(0, INVALID_POLICY, ¶m); if(result == -1 && errno == EINVAL){ printf("Test PASSED with policy value %i\n", INVALID_POLICY); return PTS_PASS; } else if(errno == 0) { printf("No error occurs, could %i be a valid value for the scheduling policy ???\n", INVALID_POLICY); return PTS_UNRESOLVED; } else { perror("Unknow error"); return PTS_FAIL; } } posixtestsuite/conformance/interfaces/sched_setscheduler/2-1.c0100644000000000000000000000131707660450107023620 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Will not test the behavior of sched_setscheduler() when pid is negative * because it is unspecified. */ #include #include "posixtest.h" int main() { printf("Will not test the behavior of sched_setscheduler() when pid is negative\n because it is unspecified.\n"); return PTS_UNTESTED; } posixtestsuite/conformance/interfaces/sched_setscheduler/19-4.c0100644000000000000000000000463310234132770023711 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * * Test that sched_setscheduler() sets errno == EINVAL when * the sched_ss_max_repl is not within the inclusive range [1,SS_REPL_MAX] * * Test the values 0 and SS_REPL_MAX+1. * * @pt:SS */ #include #include #include #include #include "posixtest.h" #if defined(_POSIX_SPORADIC_SERVER)&&(_POSIX_SPORADIC_SERVER != -1) int main(){ int policy, result; int result_code = PTS_PASS; struct sched_param param; if(sched_getparam(0, ¶m) == -1) { perror("An error occurs when calling sched_getparam()"); return PTS_UNRESOLVED; } param.sched_priority = sched_get_priority_max(SCHED_SPORADIC); /* test when sched_ss_max_repl < 1 */ param.sched_ss_max_repl = 0; result = sched_setscheduler(0, SCHED_SPORADIC, ¶m); if(result != -1) { printf("The returned code is not -1 when sched_ss_max_repl < 1.\n"); result_code = PTS_FAIL; } else if(errno == EPERM) { printf("This process does not have the permission to set its own scheduling policy.\nTry to launch this test as root.\n"); result_code = PTS_UNRESOLVED; } else if(errno != EINVAL) { perror("Unknow error when testing sched_ss_max_repl < 1"); result_code = PTS_FAIL; } /* test when sched_ss_max_repl > SS_REPL_MAX */ param.sched_ss_max_repl = SS_REPL_MAX+1; result = sched_setscheduler(0, SCHED_SPORADIC, ¶m); if(result == -1 && errno == EINVAL) { if(result_code == PTS_PASS){ printf("Test PASSED\n"); } return result_code; } else if(result != -1) { printf("The returned code is not -1 when sched_ss_max_repl > SS_REPL_MAX.\n"); return PTS_FAIL; } else if(errno == EPERM) { if(result_code == PTS_FAIL){ printf("This process does not have the permission to set its own scheduling parameter.\nTry to launch this test as root.\n"); return PTS_FAIL; } return PTS_UNRESOLVED; } else { perror("Unknow error when testing sched_ss_max_repl > SS_REPL_MAX"); return PTS_FAIL; } } #else int main() { printf("Does not support SS (SPORADIC SERVER)\n"); return PTS_UNSUPPORTED; } #endif posixtestsuite/conformance/interfaces/sem_init/0040755000000000000000000000000010515625235021124 5ustar rootrootposixtestsuite/conformance/interfaces/sem_init/2-2.c0100644000000000000000000000235210336125321021557 0ustar rootroot/* Copyright (c) 2003, Intel Corporation. All rights reserved. Created by: majid.awad REMOVE-THIS AT intel DOT com This file is licensed under the GPL license. For the full content of this license, see the COPYING file at the top level of this source tree. */ /* * unamed semaphore is used in subsequent of sem_post. */ #include #include #include #include #include #include #include #include "posixtest.h" #define TEST "2-1" #define FUNCTION "sem_init" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " int main () { sem_t mysemp; int val; if ( sem_init (&mysemp, 0, 0) == -1 ) { perror(ERROR_PREFIX "sem_init"); return PTS_UNRESOLVED; } if (sem_post(&mysemp) == -1 ) { perror(ERROR_PREFIX "trywait"); return PTS_UNRESOLVED; } if( sem_getvalue(&mysemp, &val) < 0 ) { perror(ERROR_PREFIX "sem_getvalue"); return PTS_UNRESOLVED; } if (val == 1 ) { puts("TEST PASSED"); sem_destroy(&mysemp); return PTS_PASS; } else { puts("TEST FAILED"); return PTS_FAIL; } } posixtestsuite/conformance/interfaces/sem_init/5-1.c0100644000000000000000000000165407631451356021603 0ustar rootroot/* Copyright (c) 2003, Intel Corporation. All rights reserved. Created by: majid.awad REMOVE-THIS AT intel DOT com This file is licensed under the GPL license. For the full content of this license, see the COPYING file at the top level of this source tree. */ /* * un-successful unamed semaphore initialization return -1, otherwise zero * on successful completion. */ #include #include #include #include #include #include #include #include "posixtest.h" #define TEST "5-1" #define FUNCTION "sem_init" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " int main () { sem_t mysemp; if ( sem_init (&mysemp, 0, 1) == -1 ) { puts("TEST FAILED"); return PTS_FAIL; } else { puts("TEST PASSED"); sem_destroy(&mysemp); return PTS_PASS; } } posixtestsuite/conformance/interfaces/sem_init/5-2.c0100644000000000000000000000163207631451357021601 0ustar rootroot/* Copyright (c) 2003, Intel Corporation. All rights reserved. Created by: majid.awad REMOVE-THIS AT intel DOT com This file is licensed under the GPL license. For the full content of this license, see the COPYING file at the top level of this source tree. */ /* * successful unamed semaphore initialization return zero * on successful completion. */ #include #include #include #include #include #include #include #include "posixtest.h" #define TEST "5-2" #define FUNCTION "sem_init" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " int main () { sem_t mysemp; if ( sem_init (&mysemp, 0, 1) == 0 ) { puts("TEST PASSED"); sem_destroy(&mysemp); return PTS_PASS; } else { puts("TEST FAILED"); return PTS_FAIL; } } posixtestsuite/conformance/interfaces/sem_init/1-1.c0100644000000000000000000000223310336125321021553 0ustar rootroot/* Copyright (c) 2003, Intel Corporation. All rights reserved. Created by: majid.awad REMOVE-THIS AT intel DOT com This file is licensed under the GPL license. For the full content of this license, see the COPYING file at the top level of this source tree. */ /* The following test case initializes an unnamed semaphore with a value of 1, and then check the value of the semaphore. */ #include #include #include #include #include #include #include #include "posixtest.h" #define TEST "1-1" #define FUNCTION "sem_init" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " int main () { sem_t mysemp; int sts; int val; sts = sem_init(&mysemp, 0, 1); if( sem_getvalue(&mysemp, &val) == -1 ) { perror(ERROR_PREFIX "sem_getvalue"); return PTS_UNRESOLVED; } if (( sts == -1 ) && ( val != 1)) { puts("TEST FAILED"); return PTS_FAIL; } else { puts("TEST PASSED"); sem_destroy(&mysemp); return PTS_PASS; } } posixtestsuite/conformance/interfaces/sem_init/testfrmw.c0100644000000000000000000000407210211342376023136 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * * This file is a wrapper to use the tests from the NPTL Test & Trace Project * with either the Linux Test Project or the Open POSIX Test Suite. * The following function are defined: * void output_init() * void output_fini() * void output(char * string, ...) * * The are used to output informative text (as a printf). */ #include #include /* We use a mutex to avoid conflicts in traces */ static pthread_mutex_t m_trace = PTHREAD_MUTEX_INITIALIZER; /*****************************************************************************************/ /******************************* stdout module *****************************************/ /*****************************************************************************************/ /* The following functions will output to stdout */ #if (1) void output_init() { /* do nothing */ return; } void output( char * string, ... ) { va_list ap; char *ts="[??:??:??]"; struct tm * now; time_t nw; pthread_mutex_lock(&m_trace); nw = time(NULL); now = localtime(&nw); if (now == NULL) printf(ts); else printf("[%2.2d:%2.2d:%2.2d]", now->tm_hour, now->tm_min, now->tm_sec); va_start( ap, string); vprintf(string, ap); va_end(ap); pthread_mutex_unlock(&m_trace); } void output_fini() { /*do nothing */ return; } #endif posixtestsuite/conformance/interfaces/sem_init/6-1.c0100644000000000000000000000173510211342376021571 0ustar rootroot/* Copyright (c) 2003, Intel Corporation. All rights reserved. Created by: majid.awad REMOVE-THIS AT intel DOT com This file is licensed under the GPL license. For the full content of this license, see the COPYING file at the top level of this source tree. */ /* sem_init shall fail if the valueargument exceeds SEM_VALUE_MAX. */ #include #include #include #include #include #include #include #include "posixtest.h" #include #define TEST "6-1" #define FUNCTION "sem_init" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " int main() { sem_t mysemp; int counter = SEM_VALUE_MAX; if (SEM_VALUE_MAX >= INT_MAX) { puts("Test skipped"); return PTS_PASS; } ++counter; sem_init (&mysemp, 0, counter); if ( errno == EINVAL ) { puts("TEST PASSED"); return PTS_PASS; } else { puts("TEST FAILED"); return PTS_FAIL; } } posixtestsuite/conformance/interfaces/sem_init/3-2.c0100644000000000000000000001217310211342376021565 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertion: * * If pshared is non-zero, any process that can access the semaphore can use it. * The steps are: * -> Create a shared memory segment and mmap it. * -> sem_init a semaphore placed in this segment, with pshared != 0 and val=0 * -> fork. * -> child process post the semaphore then exit * -> parent process waits for the semaphore. * The test fails if it hangs */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /******************************************************************************/ /*************************** standard includes ********************************/ /******************************************************************************/ #include #include #include #include #include #include #include #include #include #include #include #include #include /******************************************************************************/ /*************************** Test framework *******************************/ /******************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int * (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /******************************************************************************/ /**************************** Configuration ***********************************/ /******************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif /******************************************************************************/ /*************************** Test case ***********************************/ /******************************************************************************/ /* The main test function. */ int main( int argc, char * argv[] ) { int ret, status; pid_t child, ctl; int fd; void *buf; sem_t * sem; /* Initialize output */ output_init(); /* Create the shared memory segment */ fd = shm_open( "/sem_init_3-2", O_CREAT | O_RDWR, S_IRUSR | S_IWUSR ); if ( fd == -1 ) { UNRESOLVED( errno, "Failed to open shared memory segment" ); } /* Size the memory segment to 1 page size. */ ret = ftruncate( fd, sysconf( _SC_PAGESIZE ) ); if ( ret != 0 ) { UNRESOLVED( errno, "Failed to size the shared memory segment" ); } /* Map these sengments in the process memory space */ buf = mmap( NULL, sysconf( _SC_PAGESIZE ), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0 ); if ( buf == MAP_FAILED ) { UNRESOLVED( errno, "Failed to mmap the shared memory segment" ); } sem = ( sem_t * ) buf; /* Initialize the semaphore */ ret = sem_init( sem, 1, 0 ); if ( ret != 0 ) { UNRESOLVED( errno, "Failed to init the semaphore" ); } /* Create the child */ child = fork(); if ( child == ( pid_t ) - 1 ) { UNRESOLVED( errno, "Failed to fork" ); } /* child */ if ( child == ( pid_t ) 0 ) { /* Post the sempahore */ ret = sem_post( sem ); if ( ret != 0 ) { UNRESOLVED( errno, "Failed to post the semaphore" ); } /* We're done */ exit( PTS_PASS ); } /* Wait the sempahore */ do { ret = sem_wait( sem ); } while ( ( ret != 0 ) && ( errno == EINTR ) ); if ( ret != 0 ) { UNRESOLVED( errno, "Failed to wait for the semaphore" ); } /* Parent joins the child */ ctl = waitpid( child, &status, 0 ); if ( ctl != child ) { UNRESOLVED( errno, "Waitpid returned the wrong PID" ); } if ( ( !WIFEXITED( status ) ) || ( WEXITSTATUS( status ) != PTS_PASS ) ) { FAILED( "Child exited abnormally" ); } /* Clean things */ ret = sem_destroy( sem ); if ( ret != 0 ) { UNRESOLVED( errno, "Failed to destroy the semaphore" ); } ret = shm_unlink( "/sem_init_3-2" ); if ( ret != 0 ) { UNRESOLVED( errno, "Failed to unlink shared memory" ); } /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/sem_init/7-1.c0100644000000000000000000001011510211342376021562 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertion: * * sem_init returns -1 and sets errno to ENOSPC if the system lacks a resource * or SEM_NSEMS_MAX has been reached. * The steps are: * -> Try and sem_init SEM_NSEMS_MAX semaphores. * -> Try and sem_init an additional semaphore. * The test fails if the last creation does not return an error. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /******************************************************************************/ /*************************** standard includes ********************************/ /******************************************************************************/ #include #include #include #include #include #include #include #include /******************************************************************************/ /*************************** Test framework *******************************/ /******************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int * (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /******************************************************************************/ /**************************** Configuration ***********************************/ /******************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif /******************************************************************************/ /*************************** Test case ***********************************/ /******************************************************************************/ /* The main test function. */ int main( int argc, char * argv[] ) { int ret, i; sem_t *sems; sem_t sem_last; long max; /* Initialize output */ output_init(); max = sysconf( _SC_SEM_NSEMS_MAX ); if ( max <= 0 ) { output( "sysconf( _SC_SEM_NSEMS_MAX ) = %ld\n", max ); UNTESTED( "There is no constraint on SEM_NSEMS_MAX" ); } sems = ( sem_t * ) calloc( max, sizeof( sem_t ) ); if ( sems == NULL ) { UNRESOLVED( errno, "Failed to alloc space" ); } for ( i = 0; i < max; i++ ) { ret = sem_init( &sems[ i ], 0, 0 ); if ( ret != 0 ) { output( "sem_init failed to initialize the %d nth semaphore.\n", i ); output( "Tryed to initialize %ld.\n", max ); output( "Error is %d: %s\n", errno, strerror( errno ) ); for ( ; i > 0; i-- ) sem_destroy( &sems[ i - 1 ] ); free( sems ); PASSED; } } ret = sem_init( &sem_last, 0, 1 ); if ( ret == 0 ) { FAILED( "We were able to sem_init more than SEM_NSEMS_MAX semaphores" ); } if ( errno != ENOSPC ) { output( "Error is %d: %s\n", errno, strerror( errno ) ); } for ( i = 0; i < max; i++ ) sem_destroy( &sems[ i ] ); free( sems ); /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/sem_init/assertions.xml0100644000000000000000000000371707636705222024052 0ustar rootroot sem_init test case make sure that it establish initialize the unnamed semaphore referred by sem. sem_init is used in subsequence of sem_wait, sem_trywait, sem_post, sem_destroy, and the semaphore should be usable until the its destroyed. The semaphore is shared between processes when the pshared value is non-zero. The semaphore is shared between threads of process when the pshared value is zero. any thread in this process can us sem for performing sem_wait, sem_trywait, ... sem_init should initialize the semaphore in sem, otherwise it shall return -1 and set to errno. EINVAL: the value argument exceeds SEM_VALUE_MAX ENOSPC: a resouce required to initialize the semaphroe has been exhausted, or number of sems {SEM_NSEMS_MAX} has been reached. EPERM: the process lacks the appropriate privilage to initialize the semaphore. Only sem can be used for performing synchronization. The result of referring to copies of sem in calls to sem_wait, sem_post, sem_trywait and sem_destroy is undefined. When teh pshared argument is zero, then the semaphore is shared between the threads of the process, and not by the threads other than those created in the same process. (Undefined). Attempting to initialize an already initialized semaphore results in undefined behavior. posixtestsuite/conformance/interfaces/sem_init/coverage.txt0100644000000000000000000000102107636705222023454 0ustar rootroot -- assertion 4: Not tested. Help needed! -- assertion 7: Not tested. I couldn't find a way to exhaust the system in order to satisfy this test case. -- assertion 8: Not tested. I couldn't figure out how to make this test case to happen. In NPTL, the semaphore creator has to be root, and the semaphore is created in /dev/shm file system. Any other user can't create under that file system. -- assertion 9: Won't test. Undefined. -- assertion 10: Won't test. Undefined. -- assertion 11: Won't test. Undefined. posixtestsuite/conformance/interfaces/sem_init/testfrmw.h0100644000000000000000000000456410211342376023151 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * * This file is a wrapper to use the tests from the NPTL Test & Trace Project * with either the Linux Test Project or the Open POSIX Test Suite. * The following macros are defined here: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate without calling one of those macros. * * */ #include "posixtest.h" #include /* for the strerror() routine */ #ifdef __GNUC__ /* We are using GCC */ #define UNRESOLVED(x, s) \ { output("Test %s unresolved: got %i (%s) on line %i (%s)\n", __FILE__, x, strerror(x), __LINE__, s); \ output_fini(); \ exit(PTS_UNRESOLVED); } #define FAILED(s) \ { output("Test %s FAILED: %s\n", __FILE__, s); \ output_fini(); \ exit(PTS_FAIL); } #define PASSED \ output_fini(); \ exit(PTS_PASS); #define UNTESTED(s) \ { output("File %s cannot test: %s\n", __FILE__, s); \ output_fini(); \ exit(PTS_UNTESTED); \ } #else /* not using GCC */ #define UNRESOLVED(x, s) \ { output("Test unresolved: got %i (%s) on line %i (%s)\n", x, strerror(x), __LINE__, s); \ output_fini(); \ exit(PTS_UNRESOLVED); } #define FAILED(s) \ { output("Test FAILED: %s\n", s); \ output_fini(); \ exit(PTS_FAIL); } #define PASSED \ output_fini(); \ exit(PTS_PASS); #define UNTESTED(s) \ { output("Unable to test: %s\n", s); \ output_fini(); \ exit(PTS_UNTESTED); \ } #endif posixtestsuite/conformance/interfaces/sem_init/3-3.c0100644000000000000000000001236110211342376021565 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertion: * * If pshared is non-zero, any process that can access the semaphore can use it. * The steps are: * -> Create a shared memory segment and mmap it. * -> sem_init a semaphore placed in this segment, with pshared != 0 and val=0 * -> fork. * -> child process post the semaphore then exit * -> parent process waits for the child then check the semaphore has been increased * The test fails if the semaphore count did not change. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /******************************************************************************/ /*************************** standard includes ********************************/ /******************************************************************************/ #include #include #include #include #include #include #include #include #include #include #include #include #include /******************************************************************************/ /*************************** Test framework *******************************/ /******************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int * (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /******************************************************************************/ /**************************** Configuration ***********************************/ /******************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif /******************************************************************************/ /*************************** Test case ***********************************/ /******************************************************************************/ /* The main test function. */ int main( int argc, char * argv[] ) { int ret, status; pid_t child, ctl; int fd; void *buf; sem_t * sem; /* Initialize output */ output_init(); /* Create the shared memory segment */ fd = shm_open( "/sem_init_3-2", O_CREAT | O_RDWR, S_IRUSR | S_IWUSR ); if ( fd == -1 ) { UNRESOLVED( errno, "Failed to open shared memory segment" ); } /* Size the memory segment to 1 page size. */ ret = ftruncate( fd, sysconf( _SC_PAGESIZE ) ); if ( ret != 0 ) { UNRESOLVED( errno, "Failed to size the shared memory segment" ); } /* Map these sengments in the process memory space */ buf = mmap( NULL, sysconf( _SC_PAGESIZE ), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0 ); if ( buf == MAP_FAILED ) { UNRESOLVED( errno, "Failed to mmap the shared memory segment" ); } sem = ( sem_t * ) buf; /* Initialize the semaphore */ ret = sem_init( sem, 1, 0 ); if ( ret != 0 ) { UNRESOLVED( errno, "Failed to init the semaphore" ); } /* Create the child */ child = fork(); if ( child == ( pid_t ) - 1 ) { UNRESOLVED( errno, "Failed to fork" ); } /* child */ if ( child == ( pid_t ) 0 ) { /* Post the sempahore */ ret = sem_post( sem ); if ( ret != 0 ) { UNRESOLVED( errno, "Failed to post the semaphore" ); } /* We're done */ exit( PTS_PASS ); } /* Parent joins the child */ ctl = waitpid( child, &status, 0 ); if ( ctl != child ) { UNRESOLVED( errno, "Waitpid returned the wrong PID" ); } if ( ( !WIFEXITED( status ) ) || ( WEXITSTATUS( status ) != PTS_PASS ) ) { FAILED( "Child exited abnormally" ); } /* Check semaphore count */ ret = sem_getvalue( sem , &status ); if ( ret != 0 ) { UNRESOLVED( errno, "Failed to get semaphore count" ); } if ( status != 1 ) { FAILED( "The semaphore count was not increased in other process" ); } /* Clean things */ ret = sem_destroy( sem ); if ( ret != 0 ) { UNRESOLVED( errno, "Failed to destroy the semaphore" ); } ret = shm_unlink( "/sem_init_3-2" ); if ( ret != 0 ) { UNRESOLVED( errno, "Failed to unlink shared memory" ); } /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/sem_init/2-1.c0100644000000000000000000000235510336125321021561 0ustar rootroot/* Copyright (c) 2003, Intel Corporation. All rights reserved. Created by: majid.awad REMOVE-THIS AT intel DOT com This file is licensed under the GPL license. For the full content of this license, see the COPYING file at the top level of this source tree. */ /* * unamed semaphore is used in subsequent of sem_wait. */ #include #include #include #include #include #include #include #include "posixtest.h" #define TEST "2-1" #define FUNCTION "sem_init" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " int main () { sem_t mysemp; int val; if ( sem_init (&mysemp, 0, 1) == -1 ) { perror(ERROR_PREFIX "sem_init"); return PTS_UNRESOLVED; } if (sem_trywait(&mysemp) == -1 ) { perror(ERROR_PREFIX "trywait"); return PTS_UNRESOLVED; } if( sem_getvalue(&mysemp, &val) < 0 ) { perror(ERROR_PREFIX "sem_getvalue"); return PTS_UNRESOLVED; } if (val <= 0 ) { puts("TEST PASSED"); sem_destroy(&mysemp); return PTS_PASS; } else { puts("TEST FAILED"); return PTS_FAIL; } } posixtestsuite/conformance/interfaces/sem_init/3-1.c0100644000000000000000000000367410215336120021564 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: majid.awad REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * This test case illustrate the semaphore is shared between processes when * pshared value is non-zero. */ #include #include #include #include #include #include #include #include #include "posixtest.h" #define TEST "3-1" #define FUNCTION "sem_init" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " sem_t psem, csem; int n; int main() { pthread_t prod, cons; void *producer(void *); void *consumer(void *); long cnt = 3; n = 0; if (sem_init(&csem, 0, 0) < 0) { perror("sem_init"); return PTS_UNRESOLVED; } if (sem_init(&psem, 0, 1) < 0) { perror("sem_init"); return PTS_UNRESOLVED; } if (pthread_create(&prod, NULL, producer, (void *)cnt) != 0) { perror("pthread_create"); return PTS_UNRESOLVED; } if (pthread_create(&cons, NULL, consumer, (void *)cnt) != 0) { perror("pthread_create"); return PTS_UNRESOLVED; } if (( pthread_join(prod, NULL) == 0) && ( pthread_join(cons, NULL) == 0)) { puts("TEST PASS"); pthread_exit(NULL); sem_destroy(&psem); sem_destroy(&csem); return PTS_PASS; } else { puts("TEST FAILED"); return PTS_FAIL; } } void * producer(void *arg) { int i, cnt; cnt = (long)arg; for (i=0; i #include #include "posixtest.h" int main() { pthread_condattr_t condattr; clockid_t clockid; int rc; /* Initialize a cond attributes object */ if((rc=pthread_condattr_init(&condattr)) != 0) { fprintf(stderr,"Error at pthread_condattr_init(), rc=%d\n",rc); printf("Test FAILED\n"); return PTS_FAIL; } rc = pthread_condattr_getclock(&condattr, &clockid); if(rc != 0) { printf("Test FAILED: Could not get the clock attribute\n"); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_condattr_getclock/1-2.c0100644000000000000000000000243407675673344025201 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: bing.wei.liu REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_condattr_getclock() * shall get the 'clock' attribute of a condattr object. * * Steps: * 1. Initialize a pthread_condattr_t object * 2. Set the clock attribute to CLOCK_REALTIME * 3. Get the clock attribute * 4. Check that it was successful * */ # define _XOPEN_SOURCE 600 #include #include #include "posixtest.h" int main() { pthread_condattr_t condattr; clockid_t clockid; int rc; /* Initialize a cond attributes object */ if((rc=pthread_condattr_init(&condattr)) != 0) { fprintf(stderr,"Error at pthread_condattr_init(), rc=%d\n",rc); printf("Test FAILED\n"); return PTS_FAIL; } rc = pthread_condattr_setclock(&condattr, CLOCK_REALTIME); if(rc != 0) { perror("Error: Could not set clock to CLOCK_REALTIME\n"); return PTS_UNRESOLVED; } rc = pthread_condattr_getclock(&condattr, &clockid); if(rc != 0) { printf("Test FAILED: Could not get the clock attribute\n"); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_condattr_getclock/assertions.xml0100644000000000000000000000105610117555064027430 0ustar rootroot The function int pthread_condattr_getclock(pthread_condattr_t *restrict attr, clockid_t *restrict clock_id); shall get the 'clock' attribute from an attributes object referenced by 'attr'. It will store the value of the clock attribute into clock_id and return 0. It returns 0 upon success, and an error code if it fails: It may fail if: [EINVAL] - the 'attr' value is invalid posixtestsuite/conformance/interfaces/pthread_condattr_getclock/coverage.txt0100644000000000000000000000016707675673344027073 0ustar rootrootThis document defines the coverage for the pthread_condattr_getclock function: Assertion Tested? 1 YES 2 YES NOTE: posixtestsuite/conformance/interfaces/pthread_condattr_getclock/2-1.sh0100755000000000000000000000111607675673344025370 0ustar rootroot#!/bin/sh # Copyright (c) 2002, Intel Corporation. All rights reserved. # Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com # This file is licensed under the GPL license. For the full content # of this license, see the COPYING file at the top level of this # source tree. # Test pthread_condattr_getclock() returns 0 upon success, and fails with an error number # is returned if: # It may fail if: # - [EINVAL] The value specified by 'attr' is invalid. # This is tested implicitly via assertion 1. echo "Tested implicitly via assertion 1. See output for status" exit 0 posixtestsuite/conformance/interfaces/sem_wait/0040755000000000000000000000000010515625237021127 5ustar rootrootposixtestsuite/conformance/interfaces/sem_wait/cln.sh0100755000000000000000000000025607613367576022260 0ustar rootroot rm -f /tmp/mysem >/dev/null 2>&1 rm -f /tmp/sem_* >/dev/null 2>&1 rm -f a.out for sem_id in `ipcs -s | awk '{print $2}'` ; do ipcrm sem $sem_id > /dev/null 2>&1 done posixtestsuite/conformance/interfaces/sem_wait/5-1.c0100644000000000000000000000233007636705225021576 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: majid.awad REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * errno return EAGAIN: The semaphore can't be immediately locked by * sem_trywait when its already locked. */ #include #include #include #include #include #include #include "posixtest.h" #define TEST "5-1" #define FUNCTION "sem_trywait" #define ERROR_PREFIX "unexpected errno: " FUNCTION " " TEST ": " int main() { sem_t *mysemp; char semname[20]; sprintf(semname, "/" FUNCTION "_" TEST "_%d", getpid()); /* Initial value of Semaphore is 0 Locked */ mysemp = sem_open(semname, O_CREAT, 0777, 0); if( mysemp == SEM_FAILED || mysemp == NULL ) { perror(ERROR_PREFIX "sem_open"); return PTS_UNRESOLVED; } /* Lock Semaphore by sem_trywait*/ if (( sem_trywait(mysemp) == -1) && ( errno == EAGAIN) ) { puts("TEST PASSED"); sem_close(mysemp); sem_unlink(semname); return PTS_PASS; } else { puts("TEST FAILED: ERROR IS NOT EAGAIN"); return PTS_FAIL; } } posixtestsuite/conformance/interfaces/sem_wait/12-1.c0100644000000000000000000000230507636705225021656 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: majid.awad REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * sem_trywait shall try to lock the locked semaphore and decrement * the semaphore value by one. */ #include #include #include #include #include #include #include "posixtest.h" #define TEST "12-1" #define FUNCTION "sem_trywait" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " int main() { sem_t *mysemp; char semname[20]; sprintf(semname, "/" FUNCTION "_" TEST "_%d", getpid()); /* Initial value of Semaphore is 1 */ mysemp = sem_open(semname, O_CREAT, 0777, 0); if( mysemp == SEM_FAILED || mysemp == NULL ) { perror(ERROR_PREFIX "sem_open"); return PTS_UNRESOLVED; } /* Try to Lock Semaphore by sem_trywait*/ if( sem_trywait(mysemp) == -1 ) { puts("TEST PASSED"); sem_unlink(semname); sem_close(mysemp); return PTS_PASS; } else { puts("TEST FAILED: Semaphore locked when it shouldn't"); return PTS_FAIL; } } posixtestsuite/conformance/interfaces/sem_wait/1-1.c0100644000000000000000000000265007636705225021577 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: majid.awad REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * sem_wait shall lock the unlocked semaphore and decrement the semaphore * value by one. */ #include #include #include #include #include #include #include "posixtest.h" #define TEST "1-1" #define FUNCTION "sem_wait" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " int main() { sem_t *mysemp; char semname[20]; int val; sprintf(semname, "/" FUNCTION "_" TEST "_%d", getpid()); /* Initial value of Semaphore is 1 */ mysemp = sem_open(semname, O_CREAT, 0777, 1); if( mysemp == SEM_FAILED || mysemp == NULL ) { perror(ERROR_PREFIX "sem_open"); return PTS_UNRESOLVED; } /* Lock Semaphore */ if( sem_wait(mysemp) == -1 ) { perror(ERROR_PREFIX "sem_wait"); return PTS_UNRESOLVED; } /* Value of Semaphore */ if( sem_getvalue(mysemp, &val) == -1 ) { perror(ERROR_PREFIX "sem_getvalue"); return PTS_UNRESOLVED; /* Checking if the value of the Semaphore decremented by one */ } else if( val == 0 ) { puts("TEST PASSED"); sem_close(mysemp); sem_unlink(semname); return PTS_PASS; } else { puts("TEST FAILED"); return PTS_FAIL; } } posixtestsuite/conformance/interfaces/sem_wait/testfrmw.c0100644000000000000000000000407210211627501023133 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * * This file is a wrapper to use the tests from the NPTL Test & Trace Project * with either the Linux Test Project or the Open POSIX Test Suite. * The following function are defined: * void output_init() * void output_fini() * void output(char * string, ...) * * The are used to output informative text (as a printf). */ #include #include /* We use a mutex to avoid conflicts in traces */ static pthread_mutex_t m_trace = PTHREAD_MUTEX_INITIALIZER; /*****************************************************************************************/ /******************************* stdout module *****************************************/ /*****************************************************************************************/ /* The following functions will output to stdout */ #if (1) void output_init() { /* do nothing */ return; } void output( char * string, ... ) { va_list ap; char *ts="[??:??:??]"; struct tm * now; time_t nw; pthread_mutex_lock(&m_trace); nw = time(NULL); now = localtime(&nw); if (now == NULL) printf(ts); else printf("[%2.2d:%2.2d:%2.2d]", now->tm_hour, now->tm_min, now->tm_sec); va_start( ap, string); vprintf(string, ap); va_end(ap); pthread_mutex_unlock(&m_trace); } void output_fini() { /*do nothing */ return; } #endif posixtestsuite/conformance/interfaces/sem_wait/11-1.c0100644000000000000000000000271007636705225021655 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: majid.awad REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * sem_trywait shall try to lock the unlocked semaphore and decrement * the semaphore value by one. */ #include #include #include #include #include #include #include "posixtest.h" #define TEST "11-1" #define FUNCTION "sem_trywait" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " int main() { sem_t *mysemp; char semname[20]; int val; sprintf(semname, "/" FUNCTION "_" TEST "_%d", getpid()); /* Initial value of Semaphore is 1 */ mysemp = sem_open(semname, O_CREAT, 0777, 1); if( mysemp == SEM_FAILED || mysemp == NULL ) { perror(ERROR_PREFIX "sem_open"); return PTS_UNRESOLVED; } /* Lock Semaphore by sem_trywait*/ if( sem_trywait(mysemp) == -1 ) { perror(ERROR_PREFIX "sem_wait"); return PTS_UNRESOLVED; } /* Value of Semaphore */ if( sem_getvalue(mysemp, &val) == -1 ) { perror(ERROR_PREFIX "sem_getvalue"); return PTS_UNRESOLVED; /* Checking if the value of the Semaphore decremented by one */ } else if( val == 0 ) { puts("TEST PASSED"); sem_unlink(semname); sem_close(mysemp); return PTS_PASS; } else { puts("TEST FAILED"); return PTS_FAIL; } } posixtestsuite/conformance/interfaces/sem_wait/13-1.c0100644000000000000000000001140610211627501021640 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertion: * * If the semaphore count is 0, the call blocks until the semphore can be * locked or the operation is interrupted by a signal. * The steps are: * -> Initialize a semaphore to 0 count * -> Register a signal handler for SIGALRM which post the semaphore * -> save current time * -> set an alarm to 1 second * -> sem_wait * -> Verify either errno is EINTR or no error occured. * -> Verify 1 sec has elapsed. * The test fails if the call did not block. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /******************************************************************************/ /*************************** standard includes ********************************/ /******************************************************************************/ #include #include #include #include #include #include #include #include #include /******************************************************************************/ /*************************** Test framework *******************************/ /******************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int * (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /******************************************************************************/ /**************************** Configuration ***********************************/ /******************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif /******************************************************************************/ /*************************** Test case ***********************************/ /******************************************************************************/ sem_t sem; void handler( int sig ) { int ret; ret = sem_post( &sem ); if ( ret != 0 ) { UNRESOLVED( errno, "Failed to post semaphore" ); } } /* The main test function. */ int main( int argc, char * argv[] ) { int ret; struct timespec ts_ref, ts_fin; struct sigaction sa; /* Initialize output */ output_init(); /* Initialize semaphore */ ret = sem_init( &sem, 0, 0 ); if ( ret != 0 ) { UNRESOLVED( errno, "Failed to init semaphore" ); } /* Register signal handler */ sa.sa_flags = 0; sa.sa_handler = handler; ret = sigemptyset( &sa.sa_mask ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to empty signal set" ); } sigaction( SIGALRM, &sa, 0 ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to set signal handler" ); } /* Save current time */ ret = clock_gettime( CLOCK_REALTIME, &ts_ref ); if ( ret != 0 ) { UNRESOLVED( errno, "Unable to read clock" ); } /* Alarm */ alarm( 1 ); /* Wait for the semaphore */ ret = sem_wait( &sem ); if ( ( ret != 0 ) && ( errno != EINTR ) ) { UNRESOLVED( errno, "Failed to wait for the semaphore" ); } /* Check that 1 second has really elapsed */ ret = clock_gettime( CLOCK_REALTIME, &ts_fin ); if ( ret != 0 ) { UNRESOLVED( errno, "Unable to read clock" ); } if ( ( ( ts_fin.tv_sec - ts_ref.tv_sec ) * 1000000000 ) + ( ts_fin.tv_nsec - ts_ref.tv_nsec ) < 1000000000 ) { output( "Ts: %d.%9.9d -> %d.%9.9d\n", ts_ref.tv_sec, ts_ref.tv_nsec, ts_fin.tv_sec, ts_fin.tv_nsec ); FAILED( "The sem_wait call did not block" ); } /* Destroy the semaphore */ ret = sem_destroy( &sem ); if ( ret != 0 ) { UNRESOLVED( errno, "Failed to sem_destroy" ); } /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/sem_wait/1-2.c0100644000000000000000000000277407636705225021607 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: majid.awad REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * Keep calling sem_wait until the sempahore is locked. That is * decrementing the semaphore value by one until its zero or locked. */ #include #include #include #include #include #include #include #include "posixtest.h" #define TEST "2-1" #define FUNCTION "sem_wait" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " int main() { sem_t *mysemp; char semname[20]; int value = 10; int val; sprintf(semname, "/" FUNCTION "_" TEST "_%d", getpid()); /* Initial value of Semaphore is 10 */ mysemp = sem_open(semname, O_CREAT, 0777, value); if( mysemp == SEM_FAILED || mysemp == NULL ) { perror(ERROR_PREFIX "sem_open"); return PTS_UNRESOLVED; } while (value) { // checking the value if zero yet. if( sem_wait(mysemp) == -1 ) { perror(ERROR_PREFIX "sem_getvalue"); return PTS_UNRESOLVED; } else { value--; } } if( sem_getvalue(mysemp, &val) == -1 ) { perror(ERROR_PREFIX "sem_getvalue"); return PTS_UNRESOLVED; } else if( val == 0 ) { puts("TEST PASSED"); sem_unlink(semname); sem_close(mysemp); return PTS_PASS; } else { puts("TEST FAILED: Semaphore is not locked"); return PTS_FAIL; } } posixtestsuite/conformance/interfaces/sem_wait/7-1.c0100644000000000000000000000514407636705225021606 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: majid.awad REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* sem_wait hangs when it tries to lock a locked semaphore, and then killed * by sending a kill signal. */ #include #include #include #include #include #include #include #include #include "posixtest.h" #define TEST "7-1" #define FUNCTION "sem_wait" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " #define CHILDPASS 1 #define CHILDFAIL 0 void handler(int signo) { printf("In handler\n"); } int main() { sem_t *mysemp; char semname[20]; int pid, status; sprintf(semname, "/" FUNCTION "_" TEST "_%d", getpid()); mysemp = sem_open(semname, O_CREAT, 0, 1); if( mysemp == SEM_FAILED || mysemp == NULL ) { perror(ERROR_PREFIX "sem_open"); return PTS_UNRESOLVED; } if( sem_wait(mysemp) == -1 ) { perror(ERROR_PREFIX "sem_wait"); return PTS_UNRESOLVED; } pid = fork(); if (pid == 0) { // child create the semaphore. struct sigaction act; act.sa_handler=handler; act.sa_flags=0; if (sigemptyset(&act.sa_mask) == -1) { perror("Error calling sigemptyset\n"); return CHILDFAIL; } if (sigaction(SIGABRT, &act, 0) == -1) { perror("Error calling sigaction\n"); return CHILDFAIL; } sem_wait(mysemp); if (errno == EINTR) { printf("Test PASSED\n"); return (CHILDPASS); } puts("TEST FAILED: errno != EINTR"); return (CHILDFAIL); } else { // parent to send a signal to child int i; sleep(1); status = kill(pid,SIGABRT); // send signal to child if (wait(&i) == -1) { perror("Error waiting for child to exit\n"); return PTS_UNRESOLVED; } if (!WEXITSTATUS(i)) { return PTS_FAIL; } puts("TEST PASSED"); sem_unlink(semname); return PTS_PASS; } return PTS_UNRESOLVED; } posixtestsuite/conformance/interfaces/sem_wait/assertions.xml0100644000000000000000000000334410211627501024031 0ustar rootroot sem_wait will lock the unlocked semaphore and decrement the semaphore value by one. sem_wait: This test case verifies that the semaphore shall remain locked until the sem_post is executed and return successfully. sem_wait hangs when it tries to lock a locked semaphore, and then killed by sending a kill signal (SIGKILL). errno return EAGAIN: The semaphore can't be immediately locked by sem_trywait when its already locked. errno return EINVAL: the semaphore argument doesn't not refer to a valid semaphore errno return EINTR: a signal interrupted the waiting semaphore. errno return EDEADLK: sem_wait/trywait will fail if a deadlock condition is detected. sem_wait/trywait return 0 on success and -1 of failure. sem_trywait shall try to lock the unlocked semaphore and decrement the semaphore value by one. sem_trywait shall fail to lock a locked semaphore and try to decrement the semaphore value by one. If the semaphore count is 0, the call blocks until the semphore can be locked or the operation is interrupted by a signal. posixtestsuite/conformance/interfaces/sem_wait/coverage.txt0100644000000000000000000000051207663255077023471 0ustar rootroot Will not test the following error values of the semaphores because it is unknown to me of how to return these values. -- EDEADLK: A deadlock condition was detected. -- assertion 6: not tested. -- assertion 9: is being covered in the other sem_wait cases. TODO: Help create a test case for the EDEADLK ERROR code. ~ posixtestsuite/conformance/interfaces/sem_wait/testfrmw.h0100644000000000000000000000456410211627501023146 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * * This file is a wrapper to use the tests from the NPTL Test & Trace Project * with either the Linux Test Project or the Open POSIX Test Suite. * The following macros are defined here: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate without calling one of those macros. * * */ #include "posixtest.h" #include /* for the strerror() routine */ #ifdef __GNUC__ /* We are using GCC */ #define UNRESOLVED(x, s) \ { output("Test %s unresolved: got %i (%s) on line %i (%s)\n", __FILE__, x, strerror(x), __LINE__, s); \ output_fini(); \ exit(PTS_UNRESOLVED); } #define FAILED(s) \ { output("Test %s FAILED: %s\n", __FILE__, s); \ output_fini(); \ exit(PTS_FAIL); } #define PASSED \ output_fini(); \ exit(PTS_PASS); #define UNTESTED(s) \ { output("File %s cannot test: %s\n", __FILE__, s); \ output_fini(); \ exit(PTS_UNTESTED); \ } #else /* not using GCC */ #define UNRESOLVED(x, s) \ { output("Test unresolved: got %i (%s) on line %i (%s)\n", x, strerror(x), __LINE__, s); \ output_fini(); \ exit(PTS_UNRESOLVED); } #define FAILED(s) \ { output("Test FAILED: %s\n", s); \ output_fini(); \ exit(PTS_FAIL); } #define PASSED \ output_fini(); \ exit(PTS_PASS); #define UNTESTED(s) \ { output("Unable to test: %s\n", s); \ output_fini(); \ exit(PTS_UNTESTED); \ } #endif posixtestsuite/conformance/interfaces/sem_wait/3-1.c0100644000000000000000000000315610336125322021564 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: majid.awad REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* This test case verifies that the semaphore shall be locked until the * sem_post is executed and returns successfully. * Lines: 39056-39057 */ #include #include #include #include #include #include #include #include "posixtest.h" #define TEST "3-1" #define FUNCTION "sem_wait" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " int main() { sem_t *mysemp; char semname[20]; int val; sprintf(semname, "/" FUNCTION "_" TEST "_%d", getpid()); mysemp = sem_open(semname, O_CREAT, 0, 1); if( mysemp == SEM_FAILED || mysemp == NULL ) { perror(ERROR_PREFIX "sem_open"); return PTS_UNRESOLVED; } if( sem_wait(mysemp) == -1 ) { perror(ERROR_PREFIX "sem_wait"); return PTS_UNRESOLVED; } if( sem_post(mysemp) == -1 ) { perror(ERROR_PREFIX "sem_post"); return PTS_UNRESOLVED; } if( sem_getvalue(mysemp, &val) < 0 ) { perror(ERROR_PREFIX "sem_getvalue"); return PTS_UNRESOLVED; } if (val == 1 ) { puts("TEST PASSED"); sem_unlink(semname); sem_close(mysemp); return PTS_PASS; } else { puts("TEST FAILED"); return PTS_FAIL; } } posixtestsuite/conformance/interfaces/sigpause/0040755000000000000000000000000010515625265021140 5ustar rootrootposixtestsuite/conformance/interfaces/sigpause/4-1.c0100644000000000000000000000240207731215115021573 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: salwan.searty REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. This program verifies that sigpause() returns -1 and sets errno to EINVAL if passed an invalid signal number. */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include "posixtest.h" #define SIGTOTEST SIGABRT int main() { int return_value = 0; int result; return_value = sigpause(-1); if (return_value == -1) { if (errno == EINVAL) { printf ("Test PASSED: sigpause returned -1 and set errno to EINVAL\n"); result = 0; } else { printf ("Test FAILED: sigpause did not set errno to EINVAL\n"); result = 1; } } else { printf ("Test FAILED: sigpause did not return -1\n"); if (errno == EINVAL) { printf ("Test FAILED: sigpause did not set errno to EINVAL\n"); } result = 1; } if(result == 2) { return PTS_UNRESOLVED; } if(result == 1) { return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/sigpause/1-1.c0100644000000000000000000000344007640734004021575 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: salwan.searty REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. This program verifies that sigpause() removes sig from the signal mask. Steps: 1. From the main() function, create a new thread. Give the new thread a a second to set up for receiving a signal, and to suspend itself using sigpause(). 2. Have main() send the signal indicated by SIGTOTEST to the new thread, using pthread_kill(). After doing this, give the new thread a second to get to the signal handler. 3. In the main() thread, if the handler_called variable wasn't set to 1, then the test has failed, else it passed. */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include "posixtest.h" #define SIGTOTEST SIGABRT int handler_called = 0; void handler() { printf("signal was called\n"); handler_called = 1; return; } void *a_thread_func() { struct sigaction act; act.sa_flags = 0; act.sa_handler = handler; sigemptyset(&act.sa_mask); sigaction(SIGTOTEST, &act, 0); sighold(SIGTOTEST); sigpause(SIGTOTEST); return NULL; } int main() { pthread_t new_th; if(pthread_create(&new_th, NULL, a_thread_func, NULL) != 0) { perror("Error creating thread\n"); return PTS_UNRESOLVED; } sleep(1); if(pthread_kill(new_th, SIGTOTEST) != 0) { printf("Test UNRESOLVED: Couldn't send signal to thread\n"); return PTS_UNRESOLVED; } sleep(1); if(handler_called != 1) { printf("Test FAILED: signal wasn't removed from signal mask\n"); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/sigpause/1-2.c0100644000000000000000000000403107640734004021573 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: salwan.searty REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. This program verifies that sigpause() suspends the calling process until it receives a signal. Steps: 1. From the main() function, create a new thread. Give the new thread a a second to set up for receiving a signal, and to suspend itself using sigpause(). 2. For about ten seconds, keep checking from main() that the "returned" variable hasn't been set yet. If it has, that means that sigpause returned even before a signal was sent to it, thus FAIL the test. 3. After the ten seconds, send the new thread a signal using pthread_kill, and verify that "returned" has now been set to 1, meaning that the sigpause returned from suspension. */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include "posixtest.h" #define SIGTOTEST SIGABRT int returned = 0; void handler() { printf("signal was called\n"); return; } void *a_thread_func() { struct sigaction act; act.sa_flags = 0; act.sa_handler = handler; sigemptyset(&act.sa_mask); sigaction(SIGTOTEST, &act, 0); sigpause(SIGTOTEST); returned = 1; return NULL; } int main() { pthread_t new_th; int i; if(pthread_create(&new_th, NULL, a_thread_func, NULL) != 0) { perror("Error creating thread\n"); return PTS_UNRESOLVED; } for (i=0; i<10; i++) { sleep(1); if (returned == 1) { printf ("Test FAILED: sigpause returned before it received a signal\n"); return PTS_FAIL; } } if(pthread_kill(new_th, SIGTOTEST) != 0) { printf("Test UNRESOLVED: Couldn't send signal to thread\n"); return PTS_UNRESOLVED; } sleep(1); if(returned != 1) { printf("Test FAILED: signal was sent, but sigpause never returned.\n"); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/sigpause/assertions.xml0100644000000000000000000000147607640734004024056 0ustar rootroot The sigpause() function shall remove sig from the signal mask of the calling process and suspend the calling process until it receives a signal The sigpause() function shall restore the signal mask of the calling process to its original state before it returns. Execution shall be suspended by sigpause() function until a signal is received, after which it shall return -1 and set errno to [EINTR]. If the sig argument is an illegal signal number, then errno will be set to [EINVAL]. posixtestsuite/conformance/interfaces/sigpause/coverage.txt0100644000000000000000000000015507640734004023467 0ustar rootrootThis document defines the coverage for function sigpause(). Assertion Covered? 1 YES 2 YES 3 YES 4 YES posixtestsuite/conformance/interfaces/sigpause/2-1.c0100644000000000000000000000572507640734004021606 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: salwan.searty REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. This program verifies that sigpause() restores sig to the signal mask before returning. Steps: 1. From the main() function, create a new thread. Give the new thread a a second to set up for receiving a signal, add SIGTOTEST to its signal mask and to suspend itself using sigpause(SIGTOTEST). 2. Have main() send the signal indicated by SIGTOTEST to the new thread, using pthread_kill(), and using the concept of semaphores, have the main() 3. Once the new thread returns from sigpause, have the new thread raise SIGTOTEST. At this point, SIGTOTEST should be restored to the signal mask, so the signal handler should not be called yet, and the signal should be pending. If it is not, set the variable return_value to 1, indicating a test failure. 4. Now, from the new thread, set sem back to INMAIN to allow main to continue running. 5. The PTS exit code that main() will return with will depend on the value of return_value: PTS_UNRESOLVED if return value is 2 PTS_PASS if return value is 0 PTS_FAIL if return value is 1 */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include "posixtest.h" #define SIGTOTEST SIGABRT #define INMAIN 0 #define INTHREAD 1 int handler_called = 0; int return_value = 2; int sem = INMAIN; void handler() { printf("signal was called\n"); handler_called = 1; return; } void *a_thread_func() { struct sigaction act; sigset_t pendingset; act.sa_flags = 0; act.sa_handler = handler; sigemptyset(&act.sa_mask); sigaction(SIGTOTEST, &act, 0); sighold(SIGTOTEST); if ((sigpause(SIGTOTEST) != -1) || (errno != EINTR)) { printf ("Test UNRESOLVED: sigpause didn't return -1 and/or didn't set errno correctly."); return_value = 2; return NULL; } sleep(1); raise (SIGTOTEST); sigpending(&pendingset); if (sigismember(&pendingset, SIGTOTEST) == 1) { printf("Test PASSED: signal mask was restored when sigpause returned."); return_value = 0; } sem = INMAIN; return NULL; } int main() { pthread_t new_th; if(pthread_create(&new_th, NULL, a_thread_func, NULL) != 0) { perror("Error creating thread\n"); return PTS_UNRESOLVED; } sleep(1); if(pthread_kill(new_th, SIGTOTEST) != 0) { printf("Test UNRESOLVED: Couldn't send signal to thread\n"); return PTS_UNRESOLVED; } sem = INTHREAD; while (sem == INTHREAD) sleep(1); if(handler_called != 1) { printf("Test UNRESOLVED: signal wasn't removed from signal mask\n"); return PTS_UNRESOLVED; } if (return_value != 0) { if (return_value == 1) return PTS_FAIL; if (return_value == 2) return PTS_UNRESOLVED; return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/sigpause/3-1.c0100644000000000000000000000425607640734004021605 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: salwan.searty REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. This program verifies that sigpause() returns -1 and sets errno to EINTR when it returns. Steps: 1. From the main() function, create a new thread. Give the new thread a a second to set up for receiving a signal, and to suspend itself using sigpause(). 2. From the main() thread, send signal to new thread to make sigpause return. 3. Verify that sigpause returns -1 and sets errno to EINTR. */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include "posixtest.h" #define SIGTOTEST SIGABRT #define INTHREAD 0 #define INMAIN 1 int result = 2; int sem = INMAIN; void handler() { printf("signal was called\n"); return; } void *a_thread_func() { int return_value = 0; struct sigaction act; act.sa_flags = 0; act.sa_handler = handler; sigemptyset(&act.sa_mask); sigaction(SIGTOTEST, &act, 0); return_value = sigpause(SIGTOTEST); if (return_value == -1) { if (errno == EINTR) { printf ("Test PASSED: sigpause returned -1 and set errno to EINTR\n"); result = 0; } else { printf ("Test FAILED: sigpause did not set errno to EINTR\n"); result = 1; } } else { if (errno == EINTR) { printf ("Test FAILED: sigpause did not return -1\n"); } printf ("Test FAILED: sigpause did not set errno to EINTR\n"); printf ("Test FAILED: sigpause did not return -1\n"); result = 1; } sem = INMAIN; return NULL; } int main() { pthread_t new_th; if(pthread_create(&new_th, NULL, a_thread_func, NULL) != 0) { perror("Error creating thread\n"); return PTS_UNRESOLVED; } sleep(1); if(pthread_kill(new_th, SIGTOTEST) != 0) { printf("Test UNRESOLVED: Couldn't send signal to thread\n"); return PTS_UNRESOLVED; } sem = INTHREAD; while (sem == INTHREAD) sleep(1); if(result == 2) { return PTS_UNRESOLVED; } if(result == 1) { return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/sched_getparam/0040755000000000000000000000000010515625231022257 5ustar rootrootposixtestsuite/conformance/interfaces/sched_getparam/speculative/0040755000000000000000000000000010515625231024603 5ustar rootrootposixtestsuite/conformance/interfaces/sched_getparam/speculative/7-1.c0100644000000000000000000000222207643301444025253 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * * Test if sched_getparam() sets errno == EFAULT or EINVAL if param points to * NULL. * * This behavior is not specified in the specs, so this test is speculative. */ #include #include #include #include "posixtest.h" int main(int argc, char **argv) { int result = -1; result = sched_getparam( 0, NULL); if(result == -1 && errno == EFAULT) { printf("sched_getparam() sets errno == EFAULT when param argument points to NULL\n"); return PTS_PASS; } if(result == -1 && errno == EINVAL) { printf("sched_getparam() sets errno == EINVAL when param argument points to NULL\n"); return PTS_PASS; } printf("sched_getparam() return %i and sets errno == %i.\n", result, errno); return PTS_UNRESOLVED; } posixtestsuite/conformance/interfaces/sched_getparam/4-1.c0100644000000000000000000000316007643301441022723 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * * Test that sched_getparam() returns -1 on failure. * * The test create a child process which exit immediately and call * sched_getparam with the pid of defunct child. */ #include #include #include #include #include #include #include "posixtest.h" int main(int argc, char **argv) { struct sched_param param; int result = -1, child_pid; int stat_loc; /* Create a child process which exit immediately */ child_pid = fork(); if(child_pid == -1){ perror("An error occurs when calling fork()"); return PTS_UNRESOLVED; } else if (child_pid == 0){ exit(0); } /* Wait for the child process to exit */ if(wait(&stat_loc) == -1){ perror("An error occurs when calling wait()"); return PTS_UNRESOLVED; } /* Assume the pid is not yet reatributed to an other process */ result = sched_getparam(child_pid, ¶m); if(result == -1 && errno == ESRCH) { printf("Test PASSED\n"); return PTS_PASS; } if(result != -1) { printf("returned code is not -1.\n"); return PTS_FAIL; } if(errno != ESRCH ) { perror("errno is not ESRCH"); return PTS_FAIL; } else { perror("Unresolved test error"); return PTS_UNRESOLVED; } } posixtestsuite/conformance/interfaces/sched_getparam/1-1.c0100644000000000000000000000243707652175522022737 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * * Test that sched_getparam() function return the scheduling parameters of a * process specified by pid in the sched_param structure pointed to by param. */ #include #include #include #include #include "posixtest.h" int main(int argc, char **argv) { struct sched_param param; int result = -1; param.sched_priority = -1; result = sched_getparam(getpid(), ¶m); if(result == 0 && param.sched_priority != -1 && errno == 0) { printf("Test PASSED\n"); return PTS_PASS; } else if(result != 0) { printf("Return code is not zero.\n"); return PTS_FAIL; } else if(errno != 0) { perror("Unexpected error"); return PTS_FAIL; } else if(param.sched_priority == -1) { printf("The 'sched_priority' member does not change.\n"); return PTS_FAIL; } printf("This code should not be executed.\n"); return PTS_UNRESOLVED; } posixtestsuite/conformance/interfaces/sched_getparam/6-1.c0100644000000000000000000000464410061224577022737 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * * Test that sched_getparam() sets errno == EPERM if the requesting process * does not have permission. */ /* adam.li@intel.com - 2004-05-21 * * On Linux, e.g, the kernel makes no check on user permission to call this * API. So basically we don't know on what condition a system should return * EPERM. It is implementation defined. */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include #include "posixtest.h" /** Set the euid of this process to a non-root uid */ int set_nonroot() { struct passwd *pw; setpwent(); /* search for the first user which is non root */ while((pw = getpwent()) != NULL) if(strcmp(pw->pw_name, "root")) break; endpwent(); if(pw == NULL) { printf("There is no other user than current and root.\n"); return 1; } if(setuid(pw->pw_uid) != 0) { if(errno == EPERM) { printf("You don't have permission to change your UID.\n"); return 1; } perror("An error occurs when calling seteuid()"); return 1; } printf("Testing with user '%s' (euid: %d)(uid: %d)\n", pw->pw_name, (int)geteuid(), (int)getuid()); return 0; } int main(int argc, char **argv) { struct sched_param param; int result = -1; /* We assume process Number 1 is created by root */ /* and can only be accessed by root */ /* This test should be run under standard user permissions */ if (getuid() == 0) { if (set_nonroot() != 0) { printf("Cannot run this test as non-root user\n"); return PTS_UNTESTED; } } result = sched_getparam( 1, ¶m); if(result == -1 && errno == EPERM) { printf("Test PASSED\n"); return PTS_PASS; } if(result == 0) { printf("The function sched_getparam has successed.\n"); return PTS_FAIL; } if(errno != EPERM ) { perror("errno is not EPERM: The system allows a non-root" "user to use sched_getparam()"); return PTS_UNRESOLVED; } else { perror("Unresolved test error"); return PTS_UNRESOLVED; } } posixtestsuite/conformance/interfaces/sched_getparam/assertions.xml0100644000000000000000000000227707643301442025203 0ustar rootroot The sched_getparam() function shall return the scheduling parameters of a process specified by pid in the sched_param structure pointed to by param. When pid = 0, the scheduling parameters are returned for the calling process sched_getparam() returns 0 on success sched_getparam() returns -1 on failure sched_getparam() sets errno == ESRCH if the pid cannot be found sched_getparam() sets errno == EPERM if the requesting process does not have permission sched_getparam() sets errno == EFAULT or EINVAL if param points to NULL posixtestsuite/conformance/interfaces/sched_getparam/coverage.txt0100644000000000000000000000073507643301442024620 0ustar rootrootThis document explains why certain assertions were not tested. Assertions not listed here should be covered by the tests in this directory. Assertions Tested ? Remarks 1 YES Can priority be negative ? 2 YES 3 YES 4 YES Assume that a pid is not reatributed immediately 5 YES 6 YES (Has root always uid 0 ? Process pid 1 always belongs to root ?) 7 YES speculative test, not in the spec ! posixtestsuite/conformance/interfaces/sched_getparam/5-1.sh0100755000000000000000000000027207643301441023120 0ustar rootroot#! /bin/sh # # Test that sched_getparam() sets errno == ESRCH if the pid cannot be found. # This is tested implicitly via assertion 4. echo "Tested implicitly via assertion 4." exit 0 posixtestsuite/conformance/interfaces/sched_getparam/2-1.c0100644000000000000000000000226707643301441022730 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * * Test that the scheduling parameters are returned for the calling process * when pid = 0. */ #include #include #include #include #include "posixtest.h" int main(int argc, char **argv) { struct sched_param param0; struct sched_param param1; int result0; int result1; param0.sched_priority = -1; param1.sched_priority = -1; result0 = sched_getparam(0, ¶m0); result1 = sched_getparam(getpid(), ¶m1); if(result0 == result1 && param0.sched_priority == param1.sched_priority && errno == 0) { printf("Test PASSED\n"); return PTS_PASS; } else { printf("Different results between pid == 0 and pid == getpid().\n"); return PTS_FAIL; } printf("This code should not be executed.\n"); return PTS_UNRESOLVED; } posixtestsuite/conformance/interfaces/sched_getparam/3-1.c0100644000000000000000000000216007652175522022732 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * * Test that sched_getparam() returns 0 on success */ #include #include #include #include "posixtest.h" int main(int argc, char **argv) { struct sched_param param; int result = -1; param.sched_priority = -1; result = sched_getparam(0, ¶m); if(result == 0 && param.sched_priority != -1 && errno == 0) { printf("Test PASSED\n"); return PTS_PASS; } if(errno != 0 ) { perror("Unexpected error"); return PTS_FAIL; } if(result != 0) { printf("returned code is not zero.\n"); return PTS_FAIL; } else { perror("Unresolved test error"); return PTS_UNRESOLVED; } printf("This code should not be executed.\n"); return PTS_UNRESOLVED; } posixtestsuite/conformance/interfaces/pthread_barrierattr_destroy/0040755000000000000000000000000010515625201025107 5ustar rootrootposixtestsuite/conformance/interfaces/pthread_barrierattr_destroy/1-1.c0100644000000000000000000000244007705060312025551 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * * pthread_barrierattr_destroy() * * The pthread_barrierattr_destroy( ) function shall destroy a barrier * attributes object. A destroyed attr attributes object can be reinitialized * */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include #include "posixtest.h" int main() { int rc; pthread_barrierattr_t ba; /* Initialize a barrier attribute object */ if(pthread_barrierattr_init(&ba) != 0) { printf("Error at pthread_barrierattr_init()\n"); return PTS_UNRESOLVED; } /* Destroy barrier attribute object */ rc = pthread_barrierattr_destroy(&ba); if(rc != 0) { printf("Test FAILED: Error at pthread_barrierattr_destroy() " "return code: %d, %s", rc, strerror(rc)); return PTS_FAIL; } /* Re-initialize the barrier attribute object */ rc = pthread_barrierattr_init(&ba); if(rc != 0) { printf("Test FAILED: Error while re-initializing barrier attribute object\n"); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_barrierattr_destroy/assertions.xml0100644000000000000000000000100407705060312030016 0ustar rootroot The pthread_barrierattr_destroy( ) function shall destroy a barrier attributes object. A destroyed attr attributes object can be reinitialized using pthread_barrierattr_init( ); The pthread_barrierattr_destroy( ) function may fail if: [EINVAL] The value specified by attr is invalid. These functions shall not return an error code of [EINTR]. posixtestsuite/conformance/interfaces/pthread_barrierattr_destroy/coverage.txt0100644000000000000000000000017407705060312027445 0ustar rootrootThis document defines the coverage for the pthread_barrierattr_destroy() function: Assertion Tested? 1 YES 2 YES NOTE: posixtestsuite/conformance/interfaces/pthread_barrierattr_destroy/2-1.sh0100755000000000000000000000073707705060312025754 0ustar rootroot#!/bin/sh # Copyright (c) 2002, Intel Corporation. All rights reserved. # This file is licensed under the GPL license. For the full content # of this license, see the COPYING file at the top level of this # source tree. # Upon successful completion, this function shall return zero; # otherwise, an error number shall be returned to indicate the error. # This is tested implicitly via assertion 1. echo "Tested implicitly via assertion 1. See output for status" exit 0 posixtestsuite/conformance/interfaces/mq_unlink/0040755000000000000000000000000010515625175021315 5ustar rootrootposixtestsuite/conformance/interfaces/mq_unlink/2-2.c0100644000000000000000000001314610035502500021742 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: crystal.xiong REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * mq_unlink() test plan: * If one or more process have the message queue open, destruction of the * message queue will be postponed until all reference to the message queue * have been closed. At this time, call to mq_open() with O_CREAT flag may fail * until the message queue is actually removed. * Steps: * 1. Create 2 pipes to communicate with parent and child processes. * 2. Parent uses mq_open to create a new mq and tell child to open it using pipe. * 3. Child open the mq and tell Parent, so mq has 2 reference now. * 4. Parent mq_unlink the mq and tell Child to close this mq. * 5. Child close the mq and tell parent. * 6. Parent recreate the mq using mq_open, if the mq is actually removed, this operation * will succeed, if not, it may fail. */ #include #include #include #include #include #include #include #include #include "posixtest.h" #define PIPE_READ 0 #define PIPE_WRITE 1 #define TEST "2-2" #define FUNCTION "mq_unlink" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " int parent_process(char *mqname, int read_pipe, int write_pipe, int child_pid); int child_process(char *mqname, int read_pipe, int write_pipe); int send_receive(int read_pipe, int write_pipe, char send, char *reply); int main() { char mqname[50]; pid_t pid; int to_parent[2]; int to_child[2]; int rval; struct sigaction sa; sa.sa_handler = SIG_IGN; sa.sa_flags = 0; sigemptyset(&sa.sa_mask); sigaction(SIGCHLD, &sa, NULL); sprintf(mqname, "/" FUNCTION "_" TEST "_%d", getpid()); rval = pipe(to_parent); if (rval == -1) { perror(ERROR_PREFIX "fd[0]"); return PTS_UNRESOLVED; } rval = pipe(to_child); if (rval == -1) { perror(ERROR_PREFIX "fd[1]"); return PTS_UNRESOLVED; } pid = fork(); if (pid == -1) { perror(ERROR_PREFIX "fork"); return PTS_UNRESOLVED; } if (pid == 0) { //child process close(to_parent[PIPE_READ]); close(to_child[PIPE_WRITE]); return child_process(mqname, to_child[PIPE_READ], to_parent[PIPE_WRITE]); } else { //parent process close(to_parent[PIPE_WRITE]); close(to_child[PIPE_READ]); return parent_process(mqname, to_parent[PIPE_READ], to_child[PIPE_WRITE], pid); } } int parent_process(char *mqname, int read_pipe, int write_pipe, int child_pid) { mqd_t mqdes; char reply; int rval; mqdes = mq_open(mqname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, 0); if (mqdes == (mqd_t)-1) { perror(ERROR_PREFIX "mq_open"); return PTS_UNRESOLVED; } // Tell child a message queue has been opened. rval = send_receive(read_pipe, write_pipe, 'a', &reply); if (rval) { return rval; } if (reply != 'b') { printf(ERROR_PREFIX "send_receive: " "expected a 'b'\n"); return PTS_UNRESOLVED; } if (mq_unlink(mqname) == 0) { rval = send_receive(read_pipe, write_pipe, 'c', &reply); if (rval) { return rval; } if (reply != 'd') { printf(ERROR_PREFIX "send_receive: " "expected a 'd'\n"); return PTS_UNRESOLVED; } if (mq_open(mqname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, 0) != -1) { if (mq_unlink(mqname) != 0) { perror(ERROR_PREFIX "mq_unlink(2)"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } else { printf("mq_open may fail until the message queue is actually removed \n"); printf("Test PASSED\n"); return PTS_PASS; } } printf(ERROR_PREFIX "mq_unlink\n"); return PTS_UNRESOLVED; } int child_process(char *mqname, int read_pipe, int write_pipe) { mqd_t mqdes; int rval; char reply; rval = send_receive(read_pipe, write_pipe, 0, &reply); if (rval) { return rval; } if (reply != 'a') { printf(ERROR_PREFIX "send_receive: " "expected an 'a'"); return PTS_UNRESOLVED; } mqdes = mq_open(mqname, O_RDWR, 0, 0); if (mqdes == (mqd_t)-1) { perror(ERROR_PREFIX "mq_open"); return PTS_UNRESOLVED; } rval = send_receive(read_pipe, write_pipe, 'b', &reply); if (rval) { return rval; } if (reply != 'c') { printf(ERROR_PREFIX "send_receive: " "expected a 'c'\n"); return PTS_UNRESOLVED; } if (mq_close(mqdes) == -1) { perror(ERROR_PREFIX "mq_close"); return PTS_UNRESOLVED; } rval = send_receive(read_pipe, write_pipe, 'd', NULL); if (rval) { return rval; } return 0; } int send_receive(int read_pipe, int write_pipe, char send, char *reply) { ssize_t bytes; if (send) { bytes = write(write_pipe, &send, 1); if (bytes == -1) { perror(ERROR_PREFIX "write fd[1]"); return PTS_UNRESOLVED; } } if (reply) { bytes = read(read_pipe, reply, 1); if (bytes == -1) { perror(ERROR_PREFIX "read fd[0]"); return PTS_UNRESOLVED; } else if (bytes == 0) { printf(ERROR_PREFIX "read: EOF\n"); return PTS_UNRESOLVED; } } return 0; } posixtestsuite/conformance/interfaces/mq_unlink/speculative/0040755000000000000000000000000010515625175023641 5ustar rootrootposixtestsuite/conformance/interfaces/mq_unlink/speculative/7-2.c0100644000000000000000000000161610014104437024276 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: crystal.xiong REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * mq_unlink() test plan: * mq_unlink() fails with ENOENT, if the named message queue does not * exist. * */ #include #include #include #include #include #include #include #include #include "posixtest.h" #define TEST "7-2" #define FUNCTION "mq_unlink" int main() { char mqname[50]; // sprintf(mqname, FUNCTION "_" TEST "_%d", getpid()); mq_unlink(mqname); if (ENOENT == errno) { printf("Test PASSED\n"); return PTS_PASS; } else { printf("Test FAILED, error is %s\n", strerror(errno)); return PTS_FAIL; } } posixtestsuite/conformance/interfaces/mq_unlink/3-1.sh0100755000000000000000000000067307631654020022153 0ustar rootroot#!/bin/sh # Copyright (c) 2003, Intel Corporation. All rights reserved. # Created by: crystal.xiong REMOVE-THIS AT intel DOT com # This file is licensed under the GPL license. For the full content # of this license, see the COPYING file at the top level of this # source tree. # Test mq_unlink returns 0 on success. # This is tested implicitly via assertion 1. echo "Tested implicitly via assertion 1. See output for status" exit 0 posixtestsuite/conformance/interfaces/mq_unlink/1-1.c0100644000000000000000000000264207631653650021764 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: crystal.xiong REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * mq_unlink() test plan: * mq_unlink() will remove the message queue named by the pathname name * and return 0 on success. After the success call to mq_unlink() with name, * a call to mq_open() with name will fail if the flag O_CREAT is not set. * */ #include #include #include #include #include #include #include "posixtest.h" #define TEST "1-1" #define FUNCTION "mq_unlink" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " #define NAMESIZE 50 int main() { char mqname[NAMESIZE]; mqd_t mqdes; sprintf(mqname, "/" FUNCTION "_" TEST "_%d", getpid()); mqdes = mq_open(mqname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, 0); if (mqdes == (mqd_t)-1) { perror(ERROR_PREFIX "mq_open"); return PTS_UNRESOLVED; } if (mq_unlink(mqname) == 0) { if (mq_open(mqname, O_RDWR, S_IRUSR | S_IWUSR, 0) == -1) { printf("Test PASSED\n"); return PTS_PASS; } else { printf("mq_open succeed unexpectly \n"); return PTS_FAIL; } } else { perror(ERROR_PREFIX "mq_unlink"); printf("Test FAILED\n"); return PTS_FAIL; } return PTS_UNRESOLVED; } posixtestsuite/conformance/interfaces/mq_unlink/7-1.c0100644000000000000000000000150710035502500021744 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: crystal.xiong REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * mq_unlink() test plan: * mq_unlink() fails with ENOENT, if the named message queue does not * exist. * */ #include #include #include #include #include #include #include #include "posixtest.h" #define TEST "7-1" #define FUNCTION "mq_unlink" int main() { char mqname[50] = "/something-which-does-not-exit"; mq_unlink(mqname); if (ENOENT == errno) { printf("Test PASSED\n"); return PTS_PASS; } else { printf("Test FAILED\n"); return PTS_FAIL; } } posixtestsuite/conformance/interfaces/mq_unlink/assertions.xml0100644000000000000000000000306207631346747024241 0ustar rootroot mq_unlink() function will remove the message queue named by the pathname name. After a successful call to mq_unlink() with name, mq_open() with name will fail if the flag O_CREAT is not set. Destruction of the message queue will be postponed until all references to the message queue have been closed. So calls to mq_open() to recreate the message queue may fail until all the message queue is actually removed. However, mq_unlink() call need not block untill all the references have been closed, it may return immediately. If mq_unlink() is successful, it will return a value of zero. If mq_unlink() is not successful, the named message queue will be unchanged by this function call, and the function will return a value of -1 and set errno to indicate the error. mq_unlink() fails with EACCES if permission is denied to unlink the named message queue. mq_unlink() fails with ENAMETOOLONG if the length of the name argument exceeds {PATH_MAX} or a pathname component is longer than {NAME_MAX}. mq_unlink() fails with ENOENT if the named message queue does not exist. posixtestsuite/conformance/interfaces/mq_unlink/coverage.txt0100644000000000000000000000022007632106276023642 0ustar rootrootThis document defines the coverage for the mq_unlink function: Assertion Tested? 1 YES 2 YES 3 YES 4 YES 5 NO - won't test 6 YES 7 YES posixtestsuite/conformance/interfaces/mq_unlink/2-3.c0100644000000000000000000000132407631653026021760 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: crystal.xiong REMOVE-THIS AT intel DOT com:wq * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * If one or more process have the message queue open, * mq_unlink() may block until all the referneces have been closed. * NOTE: It is difficult to detect such instance. so won't test. */ #include #include "posixtest.h" int main() { printf("Difficult to detect whether mq_unlink will block until all the reference have been closed\n"); printf("for this instance. Will not be tested.\n"); return PTS_UNTESTED; } posixtestsuite/conformance/interfaces/mq_unlink/2-1.c0100644000000000000000000001260110035502500021734 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: crystal.xiong REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * mq_unlink() test plan: * If one or more process have the message queue open, destruction of the * message queue will be postponed until all reference to the message queue * have been closed. At this time, call to mq_open() with O_CREAT flag may fail * until the message queue is actually removed. * Steps: * 1. Create 2 pipes to communicate with parent and child processes. * 2. Parent uses mq_open to create a new mq and tell child to open it using pipe. * 3. Child open the mq and tell parent, so mq has 2 reference now. * 4. Parent want to mq_unlink the mq, since Child does not close the mq, * mq_unlink will postpone. At this time, if using mq_open to create * a new mq with the same name, mq_open may fail. * * 3/27/2003 Fixed a bug pointed by Krzysztof Benedyczak and * Gregoire Pichon. mq_open may fail in this case. Not * must fail. */ #include #include #include #include #include #include #include #include #include "posixtest.h" #define PIPE_READ 0 #define PIPE_WRITE 1 #define TEST "2-1" #define FUNCTION "mq_unlink" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " #define NAMESIZE 50 int parent_process(char *mqname, int read_pipe, int write_pipe, int child_pid); int child_process(char *mqname, int read_pipe, int write_pipe); int send_receive(int read_pipe, int write_pipe, char send, char *reply); int main() { char mqname[NAMESIZE]; pid_t pid; int to_parent[2]; int to_child[2]; int rval; struct sigaction sa; sa.sa_handler = SIG_IGN; sa.sa_flags = 0; sigemptyset(&sa.sa_mask); sigaction(SIGCHLD, &sa, NULL); sprintf(mqname, "/" FUNCTION "_" TEST "_%d", getpid()); rval = pipe(to_parent); if (rval == -1) { perror(ERROR_PREFIX "fd[0]"); return PTS_UNRESOLVED; } rval = pipe(to_child); if (rval == -1) { perror(ERROR_PREFIX "fd[1]"); return PTS_UNRESOLVED; } pid = fork(); if (pid == -1) { perror(ERROR_PREFIX "fork"); return PTS_UNRESOLVED; } if (pid == 0) { //child process close(to_parent[PIPE_READ]); close(to_child[PIPE_WRITE]); return child_process(mqname, to_child[PIPE_READ], to_parent[PIPE_WRITE]); } else { //parent process close(to_parent[PIPE_WRITE]); close(to_child[PIPE_READ]); return parent_process(mqname, to_parent[PIPE_READ], to_child[PIPE_WRITE], pid); } } int parent_process(char *mqname, int read_pipe, int write_pipe, int child_pid) { mqd_t mqdes; char reply; int rval; mqdes = mq_open(mqname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, 0); if (mqdes == (mqd_t)-1) { perror(ERROR_PREFIX "mq_open"); return PTS_UNRESOLVED; } // Tell child a message queue has been opened. rval = send_receive(read_pipe, write_pipe, 'a', &reply); if (rval) { return rval; } if (reply != 'b') { printf(ERROR_PREFIX "send_receive: " "expected a 'b'"); return PTS_UNRESOLVED; } if (mq_unlink(mqname) == 0) { if (mq_open(mqname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, 0) == -1) { printf("mq_open to recreate the message mqueue may fail until all references to the message queue have been closed, or until the message queue is actually removed. \n"); printf("Test PASSED\n"); return PTS_PASS; } else { if (mq_unlink(mqname) != 0) { printf(ERROR_PREFIX "mq_unlink(2)"); return PTS_UNRESOLVED; } printf("mq_open to recreate the message mqueue may succeed even if the references to the message queue have not been closed or the message queue is not actually removed. \n"); printf("Test PASSED\n"); return PTS_PASS; } } printf(ERROR_PREFIX "mq_unlink \n"); return PTS_UNRESOLVED; } int child_process(char *mqname, int read_pipe, int write_pipe) { mqd_t mqdes; int rval; char reply; rval = send_receive(read_pipe, write_pipe, 0, &reply); if (rval) { return rval; } if (reply != 'a') { printf(ERROR_PREFIX "send_receive: " "expected an 'a'\n"); return PTS_UNRESOLVED; } mqdes = mq_open(mqname, O_RDWR, 0, 0); if (mqdes == (mqd_t)-1) { perror(ERROR_PREFIX "mq_open"); return PTS_UNRESOLVED; } rval = send_receive(read_pipe, write_pipe, 'b', NULL); return 0; } int send_receive(int read_pipe, int write_pipe, char send, char *reply) { ssize_t bytes; if (send) { bytes = write(write_pipe, &send, 1); if (bytes == -1) { perror(ERROR_PREFIX "write fd[1]"); return PTS_UNRESOLVED; } } if (reply) { bytes = read(read_pipe, reply, 1); if (bytes == -1) { perror(ERROR_PREFIX "read fd[0]"); return PTS_UNRESOLVED; } else if (bytes == 0) { printf(ERROR_PREFIX "read: EOF \n"); return PTS_UNRESOLVED; } } return 0; } posixtestsuite/conformance/interfaces/mq_unlink/4-1.sh0100755000000000000000000000102607631653324022153 0ustar rootroot#!/bin/sh # Copyright (c) 2003, Intel Corporation. All rights reserved. # Created by: crystal.xiong REMOVE-THIS AT intel DOT com # This file is licensed under the GPL license. For the full content # of this license, see the COPYING file at the top level of this # source tree. # Test mq_unlink returns -1 on failure and set errno to indicate the # error, named message queue will be unchanged. # This is tested implicitly via assertion 5, 6, 7. echo "Tested implicitly via assertion 5, 6, 7. See output for status" exit 0 posixtestsuite/conformance/interfaces/pthread_attr_getinheritsched/0040755000000000000000000000000010515625176025233 5ustar rootrootposixtestsuite/conformance/interfaces/pthread_attr_getinheritsched/1-1.c0100644000000000000000000000426010025746466025676 0ustar rootroot/* * Copyright (c) 2004, Intel Corporation. All rights reserved. * Created by: crystal.xiong REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test pthread_attr_getinheritsched() * * Steps: * 1. Initialize a pthread_attr_t object using pthread_attr_init() * 2. Call pthread_attr_setinheritsched with inheritsched parameter * 3. Call pthread_attr_getinheritsched to get the inheritsched * */ #include #include #include #include "posixtest.h" #define TEST "1-1" #define FUNCTION "pthread_attr_getinheritsched" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " #define EXPLICIT PTHREAD_EXPLICIT_SCHED #define INHERIT PTHREAD_INHERIT_SCHED int verify_inheritsched(pthread_attr_t *attr, int schedtype) { int rc; int inheritsched; rc = pthread_attr_getinheritsched(attr, &inheritsched); if( rc != 0) { perror(ERROR_PREFIX "pthread_attr_getinheritsched"); exit(PTS_UNRESOLVED); } switch(schedtype) { case INHERIT: if (inheritsched != INHERIT) { perror(ERROR_PREFIX "got wrong inheritsched param"); exit(PTS_FAIL); } break; case EXPLICIT: if (inheritsched != EXPLICIT) { perror(ERROR_PREFIX "got wrong inheritsched param"); exit(PTS_FAIL); } break; } return 0; } int main() { int rc=0; pthread_attr_t attr; rc = pthread_attr_init(&attr); if( rc != 0) { perror(ERROR_PREFIX "pthread_attr_init"); exit(PTS_UNRESOLVED); } rc = pthread_attr_setinheritsched(&attr, INHERIT); if( rc != 0) { perror(ERROR_PREFIX "pthread_attr_setinheritsched"); exit(PTS_UNRESOLVED); } verify_inheritsched(&attr, INHERIT); rc = pthread_attr_setinheritsched(&attr, EXPLICIT); if( rc != 0) { perror(ERROR_PREFIX "pthread_attr_setinheritsched"); exit(PTS_UNRESOLVED); } verify_inheritsched(&attr, EXPLICIT); rc = pthread_attr_destroy(&attr); if( rc != 0) { perror(ERROR_PREFIX "pthread_attr_destroy"); exit(PTS_UNRESOLVED); } printf("Test PASS\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_attr_getinheritsched/assertions.xml0100644000000000000000000000077410027762020030140 0ustar rootroot pthread_attr_getinheritsched shall get the inheritsched attribute in the attr argument. PTHREAD_INHERIT_SCHED and PTHREAD_EXPLICIT_SCHED are valid value. If succesful, the pthread_attr_getinheritsched shall return zero. If fail, the pthread_attr_getinheritsched shall return an error number. posixtestsuite/conformance/interfaces/pthread_attr_getinheritsched/coverage.txt0100644000000000000000000000021010025746466027557 0ustar rootrootThis document defines the coverage for the pthread_attr_getinheritsched function: Assertion Tested? 1 YES 2 YES 3 won't test NOTE: posixtestsuite/conformance/interfaces/pthread_attr_getinheritsched/2-1.sh0100755000000000000000000000071710025746466026075 0ustar rootroot #!/bin/sh # Copyright (c) 2004, Intel Corporation. All rights reserved. # Created by: crystal.xiong REMOVE-THIS AT intel DOT com # This file is licensed under the GPL license. For the full content # of this license, see the COPYING file at the top level of this # source tree. # Test pthread_attr_getinheritsched returns 0 on success. # This is tested implicitly via assertion 1. echo "Tested implicitly via assertion 1. See output for status" exit 0 posixtestsuite/conformance/interfaces/pthread_barrier_wait/0040755000000000000000000000000010515625201023467 5ustar rootrootposixtestsuite/conformance/interfaces/pthread_barrier_wait/1-1.c0100644000000000000000000000753707705352300024146 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * * pthread_barrier_wait() * * The pthread_barrier_wait( ) function shall synchronize participating threads * at the barrier referenced by barrier. The calling thread shall block * until the required number of threads have called pthread_barrier_wait( ) * specifying the barrier. * * Steps: * 1. Main initialize barrier with count 2 * 2. Main create a child thread * 3. Child thread call pthread_barrier_wait(), should block * 4. Main call pthread_barrier_wait(), child and main should all return * from pthread_barrier_wait() */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include "posixtest.h" static pthread_barrier_t barrier; static int thread_state; #define NOT_CREATED_THREAD 1 #define ENTERED_THREAD 2 #define EXITING_THREAD 3 static void* fn_chld(void *arg) { int rc = 0; thread_state = ENTERED_THREAD; printf("child: barrier wait\n"); rc = pthread_barrier_wait(&barrier); if(rc != 0 && rc != PTHREAD_BARRIER_SERIAL_THREAD) { printf("Test FAILED: child: pthread_barrier_wait() got unexpected " "return code : %d\n" , rc); exit(PTS_FAIL); } else if(rc == PTHREAD_BARRIER_SERIAL_THREAD) { printf("child: get PTHREAD_BARRIER_SERIAL_THREAD\n"); } thread_state = EXITING_THREAD; pthread_exit(0); return NULL; } void sig_handler() { printf("Interrupted by SIGALRM\n"); printf("Test FAILED: main blocked on barrier wait\n"); exit(PTS_FAIL); } int main() { int cnt = 0; int rc; pthread_t child_thread; struct sigaction act; /* Set up main thread to handle SIGALRM */ act.sa_flags = 0; act.sa_handler = sig_handler; sigfillset(&act.sa_mask); sigaction(SIGALRM, &act, 0); printf("Initialize barrier with count = 2\n"); if(pthread_barrier_init(&barrier, NULL, 2) != 0) { printf("main: Error at pthread_barrier_init()\n"); return PTS_UNRESOLVED; } printf("main: create child thread\n"); thread_state = NOT_CREATED_THREAD; if(pthread_create(&child_thread, NULL, fn_chld, NULL) != 0) { printf("main: Error at pthread_create()\n"); return PTS_UNRESOLVED; } /* Expect the child to block*/ cnt = 0; do{ sleep(1); }while (thread_state !=EXITING_THREAD && cnt++ < 2); if(thread_state == EXITING_THREAD) { /* child thread did not block */ printf("Test FAILED: child thread did not block on " "pthread_barrier_wait()\n"); exit(PTS_FAIL); } else if(thread_state != ENTERED_THREAD) { printf("Unexpected thread state: %d\n", thread_state); exit(PTS_UNRESOLVED); } printf("main: call barrier wait\n"); /* we should not block here, but just in case we do */ alarm(2); rc = pthread_barrier_wait(&barrier); if(rc != 0 && rc != PTHREAD_BARRIER_SERIAL_THREAD) { printf("Test FAILED: main: pthread_barrier_wait() get unexpected " "return code : %d\n" , rc); exit(PTS_FAIL); } else if(rc == PTHREAD_BARRIER_SERIAL_THREAD) { printf("main: got PTHREAD_BARRIER_SERIAL_THREAD\n"); } /* We expected the child returned from barrier wait */ cnt = 1; do{ sleep(1); }while (thread_state != EXITING_THREAD && cnt++ < 3); if(thread_state == ENTERED_THREAD) { printf("Test FAILED: child thread still blocked on " "barrier wait\n"); return PTS_FAIL; } else if(thread_state != EXITING_THREAD) { printf("main: Unexpected thread state: %d\n", thread_state); return PTS_UNRESOLVED; } if(pthread_join(child_thread, NULL) != 0) { printf("main: Error at pthread_join()\n"); exit(PTS_UNRESOLVED); } if(pthread_barrier_destroy(&barrier) != 0) { printf("Error at pthread_barrier_destroy()"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_barrier_wait/6-1.c0100644000000000000000000000316707705352300024146 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * * pthread_barrier_wait() * * The pthread_barrier_wait( ) function may fail if: * [EINVAL] The value specified by barrier does not refer to an initialized barrier object. * * This case will always pass. */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include #include "posixtest.h" int rc; void sig_handler() { printf("main: blocked on barrier wait with an un-initializied barrier object.\n"); printf("Test PASSED: Note*: Expected EINVAL when calling this funtion with an un-initialized barrier object, but standard says 'may' fail.\n"); exit(PTS_PASS); } int main() { pthread_barrier_t barrier; struct sigaction act; /* Set up main thread to handle SIGALRM */ act.sa_flags = 0; act.sa_handler = sig_handler; sigfillset(&act.sa_mask); sigaction(SIGALRM, &act, 0); /* Intialize return code */ rc = 1; /* Call pthread_barrier_wait while refering to an un-initialized barrier object */ /* Just in case we are blocked, send a SIGALRM after 2 sec. */ alarm(2); rc = pthread_barrier_wait(&barrier); if(rc == EINVAL) { printf("Test PASSED\n"); } else { printf("return code : %d, %s\n" , rc, strerror(rc)); printf("Test PASSED: Note*: Expected EINVAL when calling this funtion with an un-initialized barrier object, but standard says 'may' fail.\n"); } return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_barrier_wait/3-2.c0100644000000000000000000001054707705352300024144 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * * pthread_barrier_wait() * * If a signal is delivered to a thread blocked on a barrier.. * otherwise, the thread shall continue as normal from the completed barrier wait. Until * the thread in the signal handler returns from it, it is unspecified whether other threads may * proceed past the barrier once they have all reached it. * * Steps: * 1. Main initialize barrier with count 2 * 2. Main create a child thread * 3. Child thread call pthread_barrier_wait(), should block * 4. While child thread is blocking, send SIGUSR1 to child * 5. While child thread is in the signal handler, main thread call pthread_barrier_wait() * 6. After return from the signal handler, the child thread should continue as normal */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include #include "posixtest.h" static pthread_barrier_t barrier; static int thread_state; static int sig_rcvd; static int barrier_waited; #define NOT_CREATED_THREAD 1 #define ENTERED_THREAD 2 #define EXITING_THREAD 3 void sig_handler() { struct timespec ts; sig_rcvd = 1; printf("thread: interrupted by SIGUSR1\n"); ts.tv_sec = 1; ts.tv_nsec = 0; while(barrier_waited != 1) { nanosleep(&ts, NULL); } } static void* fn_chld(void *arg) { int rc = 0; struct sigaction act; thread_state = ENTERED_THREAD; /* Set up thread to handle SIGUSR1 */ act.sa_flags = 0; act.sa_handler = sig_handler; sigfillset(&act.sa_mask); sigaction(SIGUSR1, &act, 0); printf("thread: call barrier wait\n"); rc = pthread_barrier_wait(&barrier); if(rc != 0 && rc != PTHREAD_BARRIER_SERIAL_THREAD) { printf("Test FAILED: child: pthread_barrier_wait() got unexpected " "return code : %d\n" , rc); exit(PTS_FAIL); } else if(rc == PTHREAD_BARRIER_SERIAL_THREAD) printf("thread: got PTHREAD_BARRIER_SERIAL_THREAD\n"); thread_state = EXITING_THREAD; pthread_exit(0); return NULL; } int main() { int cnt = 0; int rc; pthread_t child_thread; sig_rcvd = 0; barrier_waited = 0; printf("Initialize barrier with count = 2\n"); if(pthread_barrier_init(&barrier, NULL, 2) != 0) { printf("main: Error at pthread_barrier_init()\n"); return PTS_UNRESOLVED; } printf("main: create child thread\n"); thread_state = NOT_CREATED_THREAD; if(pthread_create(&child_thread, NULL, fn_chld, NULL) != 0) { printf("main: Error at pthread_create()\n"); return PTS_UNRESOLVED; } /* Expect the child to block*/ cnt = 0; do{ sleep(1); }while (thread_state !=EXITING_THREAD && cnt++ < 2); if(thread_state == EXITING_THREAD) { /* child thread did not block */ printf("Test FAILED: child thread did not block on " "pthread_barrier_wait()\n"); exit(PTS_FAIL); } else if(thread_state != ENTERED_THREAD) { printf("Unexpected thread state\n"); exit(PTS_UNRESOLVED); } printf("main: send SIGUSR1 to child thread\n"); if(pthread_kill(child_thread, SIGUSR1) != 0) { printf("main: Error at pthread_kill()\n"); exit(PTS_UNRESOLVED); } /* Wait for thread to receive the signal */ while(sig_rcvd != 1) { sleep(1); } printf("main: call barrier wait\n"); rc = pthread_barrier_wait(&barrier); if(rc != 0 && rc != PTHREAD_BARRIER_SERIAL_THREAD) { printf("Test FAILED: main: pthread_barrier_wait() got unexpected " "return code : %d\n" , rc); exit(PTS_FAIL); } else if(rc == PTHREAD_BARRIER_SERIAL_THREAD) printf("main: got PTHREAD_BARRIER_SERIAL_THREAD\n"); barrier_waited = 1; /* We expected the child returned from barrier wait */ cnt = 0; do{ sleep(1); }while (thread_state != EXITING_THREAD && cnt++ < 3); if(thread_state == ENTERED_THREAD) { printf("Test FAILED: child thread still blocked on " "barrier wait\n"); return PTS_FAIL; } else if(thread_state != EXITING_THREAD) { printf("main: Unexpected thread state\n"); return PTS_UNRESOLVED; } if(pthread_join(child_thread, NULL) != 0) { printf("main: Error at pthread_join()\n"); exit(PTS_UNRESOLVED); } if(pthread_barrier_destroy(&barrier) != 0) { printf("Error at pthread_barrier_destroy()"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_barrier_wait/assertions.xml0100644000000000000000000000453207705352300026410 0ustar rootroot The pthread_barrier_wait( ) function shall synchronize participating threads at the barrier referenced by barrier. The calling thread shall block until the required number of threads have called pthread_barrier_wait( ) specifying the barrier. When the required number of threads have called pthread_barrier_wait( ) specifying the barrier, the constant PTHREAD_BARRIER_SERIAL_THREAD shall be returned to one unspecified thread and zero shall be returned to each of the remaining threads. At this point, the barrier shall be reset to the state it had as a result of the most recent pthread_barrier_init( ) function that referenced it. If a signal is delivered to a thread blocked on a barrier, upon return from the signal handler the thread shall resume waiting at the barrier if the barrier wait has not completed (that is, if the required number of threads have not arrived at the barrier during the execution of the signal handler); otherwise, the thread shall continue as normal from the completed barrier wait. Until the thread in the signal handler returns from it, it is unspecified whether other threads may proceed past the barrier once they have all reached it. A thread that has blocked on a barrier shall not prevent any unblocked thread that is eligible to use the same processing resources from eventually making forward progress in its execution. Eligibility for processing resources shall be determined by the scheduling policy. Upon successful completion, the pthread_barrier_wait( ) function shall return PTHREAD_BARRIER_SERIAL_THREAD for a single (arbitrary) thread synchronized at the barrier and zero for each of the other threads. Otherwise, an error number shall be returned to indicate the error. The pthread_barrier_wait( ) function may fail if: [EINVAL] The value specified by barrier does not refer to an initialized barrier object. These functions shall not return an error code of EINTR. posixtestsuite/conformance/interfaces/pthread_barrier_wait/coverage.txt0100644000000000000000000000022507705352300026023 0ustar rootrootThis document defines the coverage for the pthread_barrier_wait() function: Assertion Tested? 1 YES 2 YES 3 YES 4 YES 5 YES 6 YES NOTE: posixtestsuite/conformance/interfaces/pthread_barrier_wait/5-1.sh0100755000000000000000000000116507705352300024334 0ustar rootroot#!/bin/sh # Copyright (c) 2002, Intel Corporation. All rights reserved. # This file is licensed under the GPL license. For the full content # of this license, see the COPYING file at the top level of this # source tree. # Upon successful completion, the pthread_barrier_wait( ) function shall return # PTHREAD_BARRIER_SERIAL_THREAD for a single (arbitrary) thread synchronized at the # barrier and zero for each of the other threads. Otherwise, # an error number shall be returned to indicate the error. # This is tested implicitly via assertion 1. echo "Tested implicitly via assertion 1. See output for status" exit 0 posixtestsuite/conformance/interfaces/pthread_barrier_wait/2-1.c0100644000000000000000000000624507705352300024142 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * * pthread_barrier_wait() * * When the required number of threads have called pthread_barrier_wait( ) * specifying the barrier, the constant PTHREAD_BARRIER_SERIAL_THREAD shall * be returned to one unspecified thread and zero shall be returned * to each of the remaining threads. At this point, the barrier shall * be reset to the state it had as a result of the most recent * pthread_barrier_init( ) function that referenced it. * * Steps: * 1. Main thread do the following for LOOP_NUM times * 2. In each loop, Main thread initialize barrier, with count set to THREAD_NUM * 3. Main create THREAD_NUM threads * 4. Each thread will call pthread_barrier_wait() * 5. When the last thread calls pthread_barrier_wait, only one thread will * get PTHREAD_BARRIER_SERIAL_THREAD, all the other threads should get zero * 6. This holds true for every loop. * */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include "posixtest.h" #define THREAD_NUM 5 #define LOOP_NUM 3 static pthread_barrier_t barrier; static int serial; static int normal_rt; static void* fn_chld(void *arg) { int rc = 0; int thread_num = *(int*)arg; printf("child[%d]: barrier wait\n", thread_num); rc = pthread_barrier_wait(&barrier); if(rc != 0 && rc != PTHREAD_BARRIER_SERIAL_THREAD) { printf("Test FAILED: child[%d]: pthread_barrier_wait() get unexpected " "return code : %d\n" , thread_num, rc); exit(PTS_FAIL); } else if(rc == PTHREAD_BARRIER_SERIAL_THREAD) { serial++; printf("child[%d]: get PTHREAD_BARRIER_SERIAL_THREAD\n", thread_num); } else { normal_rt++; } pthread_exit(0); return NULL; } int main() { pthread_t child_threads[THREAD_NUM]; int cnt; int loop; printf("Initialize barrier with count = %d\n", THREAD_NUM); if(pthread_barrier_init(&barrier, NULL, THREAD_NUM) != 0) { printf("main: Error at pthread_barrier_init()\n"); return PTS_UNRESOLVED; } for(loop = 0; loop < LOOP_NUM; loop++) { serial = 0; normal_rt = 0; printf("\n-Loop %d-\n", loop); printf("main: create %d child threads\n", THREAD_NUM); for(cnt = 0; cnt < THREAD_NUM; cnt++) { if(pthread_create(&child_threads[cnt], NULL, fn_chld, &cnt) != 0) { printf("main: Error at %dth pthread_create()\n", cnt); return PTS_UNRESOLVED; } } printf("main: wait for child threads to end\n"); for(cnt = 0; cnt < THREAD_NUM; cnt++) { if(pthread_join(child_threads[cnt], NULL) != 0) { printf("main: Error at %dth pthread_join()\n", cnt); exit(PTS_UNRESOLVED); } } if(serial != 1 || (serial + normal_rt) != THREAD_NUM ) { printf("Test FAILED: On %d loop, PTHREAD_BARRIER_SERIAL_THREAD " "should be returned to one unspecified thread\n", loop); return PTS_FAIL; } } if(pthread_barrier_destroy(&barrier) != 0) { printf("Error at pthread_barrier_destroy()"); return PTS_UNRESOLVED; } printf("\nTest PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_barrier_wait/4-1.sh0100755000000000000000000000116307705352300024331 0ustar rootroot#!/bin/sh # Copyright (c) 2002, Intel Corporation. All rights reserved. # This file is licensed under the GPL license. For the full content # of this license, see the COPYING file at the top level of this # source tree. # A thread that has blocked on a barrier shall not prevent any unblocked # thread that is eligible to use the same processing resources from # eventually making forward progress in its execution. # Eligibility for processing resources shall be determined by the scheduling policy. # This is tested implicitly via assertion 1. echo "Tested implicitly via assertion 1. See output for status" exit 0 posixtestsuite/conformance/interfaces/pthread_barrier_wait/3-1.c0100644000000000000000000001145207705352300024137 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * * pthread_barrier_wait() * * If a signal is delivered to a thread blocked on a barrier, upon return * from the signal handler the thread shall resume waiting at the barrier * if the barrier wait has not completed (that is, if the * required number of threads have not arrived at the barrier * during the execution of the signal handler); * * Steps: * 1. Main initialize barrier with count 2 * 2. Main create a child thread * 3. Child thread call pthread_barrier_wait(), should block * 4. While child thread is blocking, send SIGUSR1 to child * 5. The signal handler did nothing just print a messge * 6. After return from the signal handler, child should resume blocking * 7. Main call pthread_barrier_wait(), child and main should all return * from pthread_barrier_wait() */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include "posixtest.h" static pthread_barrier_t barrier; static int thread_state; static int sig_rcvd; #define NOT_CREATED_THREAD 1 #define ENTERED_THREAD 2 #define EXITING_THREAD 3 void sig_handler() { sig_rcvd = 1; printf("thread: interrupted by SIGUSR1\n"); } static void* fn_chld(void *arg) { int rc = 0; struct sigaction act; thread_state = ENTERED_THREAD; /* Set up thread to handle SIGUSR1 */ act.sa_flags = 0; act.sa_handler = sig_handler; sigfillset(&act.sa_mask); sigaction(SIGUSR1, &act, 0); printf("thread: call barrier wait\n"); rc = pthread_barrier_wait(&barrier); if(rc != 0 && rc != PTHREAD_BARRIER_SERIAL_THREAD) { printf("Test FAILED: child: pthread_barrier_wait() got unexpected " "return code : %d\n" , rc); exit(PTS_FAIL); } else if(rc == PTHREAD_BARRIER_SERIAL_THREAD) printf("thread: get PTHREAD_BARRIER_SERIAL_THREAD\n"); thread_state = EXITING_THREAD; pthread_exit(0); return NULL; } int main() { int cnt = 0; int rc; pthread_t child_thread; sig_rcvd = 0; printf("Initialize barrier with count = 2\n"); if(pthread_barrier_init(&barrier, NULL, 2) != 0) { printf("main: Error at pthread_barrier_init()\n"); return PTS_UNRESOLVED; } printf("main: create child thread\n"); thread_state = NOT_CREATED_THREAD; if(pthread_create(&child_thread, NULL, fn_chld, NULL) != 0) { printf("main: Error at pthread_create()\n"); return PTS_UNRESOLVED; } /* Expect the child to block*/ cnt = 0; do{ sleep(1); }while (thread_state !=EXITING_THREAD && cnt++ < 2); if(thread_state == EXITING_THREAD) { /* child thread did not block */ printf("Test FAILED: child thread did not block on " "pthread_barrier_wait()\n"); exit(PTS_FAIL); } else if(thread_state != ENTERED_THREAD) { printf("Unexpected thread state: %d\n", thread_state); exit(PTS_UNRESOLVED); } printf("main: send SIGUSR1 to child thread\n"); if(pthread_kill(child_thread, SIGUSR1) != 0) { printf("main: Error at pthread_kill()\n"); exit(PTS_UNRESOLVED); } /* Expect the child to continue blocking */ cnt = 0; do{ sleep(1); }while (thread_state !=EXITING_THREAD && cnt++ < 2); if(sig_rcvd != 1) { printf("child did not handle SIGUSR1\n"); exit(PTS_UNRESOLVED); } if(thread_state == EXITING_THREAD) { /* child thread did not block */ printf("Test FAILED: child thread should still block on " "pthread_barrier_wait() when interrupted by signal\n"); exit(PTS_FAIL); } else if(thread_state != ENTERED_THREAD) { printf("Unexpected thread state: %d\n", thread_state); exit(PTS_UNRESOLVED); } printf("main: thread continued blocking after handling SIGUSR1\n"); printf("main: call barrier wait\n"); rc = pthread_barrier_wait(&barrier); if(rc != 0 && rc != PTHREAD_BARRIER_SERIAL_THREAD) { printf("Test FAILED: main: pthread_barrier_wait() got unexpected " "return code : %d\n" , rc); exit(PTS_FAIL); } else if(rc == PTHREAD_BARRIER_SERIAL_THREAD) printf("main: get PTHREAD_BARRIER_SERIAL_THREAD\n"); /* We expected the child returned from barrier wait */ cnt = 0; do{ sleep(1); }while (thread_state != EXITING_THREAD && cnt++ < 3); if(thread_state == ENTERED_THREAD) { printf("Test FAILED: child thread still blocked on " "barrier wait\n"); return PTS_FAIL; } else if(thread_state != EXITING_THREAD) { printf("main: Unexpected thread state: %d\n", thread_state); return PTS_UNRESOLVED; } if(pthread_join(child_thread, NULL) != 0) { printf("main: Error at pthread_join()\n"); exit(PTS_UNRESOLVED); } if(pthread_barrier_destroy(&barrier) != 0) { printf("Error at pthread_barrier_destroy()"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/difftime/0040755000000000000000000000000010515625163021104 5ustar rootrootposixtestsuite/conformance/interfaces/difftime/1-1.c0100644000000000000000000000152707710055111021541 0ustar rootroot/* * Copyright (c) 2002-3, Intel Corporation. All rights reserved. * Created by: salwan.searty REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test that the difftime function shall return the difference between two calendar times. */ #define WAIT_DURATION 1 #include #include #include #include #include "posixtest.h" int main() { time_t time1, time0; double time_diff; time_diff = 0; time0 = time(NULL); sleep(WAIT_DURATION); time1 = time(NULL); time_diff = difftime(time1, time0); if (time_diff != WAIT_DURATION) { perror("Test FAILED: difftime did not return the correct value\n"); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/difftime/assertions.xml0100644000000000000000000000060607710055111024010 0ustar rootroot The difftime ( ) function shall compute the difference between two calendar times (as returned by time( )): time1. time0. The difftime ( ) function shall return the difference expressed in seconds as a type double. posixtestsuite/conformance/interfaces/difftime/coverage.txt0100644000000000000000000000014407710055111023425 0ustar rootrootThis file defines the coverage for the difftime() function testing. Assertion Status 1 YES 2 YES posixtestsuite/conformance/interfaces/difftime/2-1.sh0100755000000000000000000000066607710055111021740 0ustar rootroot#!/bin/sh # Copyright (c) 2002, Intel Corporation. All rights reserved. # This file is licensed under the GPL license. For the full content # of this license, see the COPYING file at the top level of this # source tree. #The difftime ( ) function shall return the difference expressed in seconds as a type double. # This is tested implicitly via assertion 1. echo "Tested implicitly via assertion 1. See output for status" exit 0 posixtestsuite/conformance/interfaces/lio_listio/0040755000000000000000000000000010515625166021466 5ustar rootrootposixtestsuite/conformance/interfaces/lio_listio/15-1.c0100644000000000000000000000747410247562116022223 0ustar rootroot/* * Copyright (c) 2004, Bull SA. All rights reserved. * Created by: Laurent.Vivier@bull.net * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * assertion: * * The error statuses returned are identical to those returned as the * result of an aio_read() or aio_write(). * * method: * * - open a file * - submit a list of requests to lio_listio * - check that the error and return codes are consistent * */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include "posixtest.h" #define TNAME "lio_listio/15-1.c" #define NUM_AIOCBS 10 #define BUF_SIZE 1024 int num_received = 0; int received_all = 0; void sigrt1_handler(int signum, siginfo_t *info, void *context) { num_received++; } void sigrt2_handler(int signum, siginfo_t *info, void *context) { received_all = 1; } int main() { char tmpfname[256]; int fd; struct aiocb *aiocbs[NUM_AIOCBS]; char *bufs; struct sigaction action; struct sigevent event; int errors = 0; int ret; int err; int i; #if _POSIX_ASYNCHRONOUS_IO != 200112L exit(PTS_UNSUPPORTED); #endif snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_lio_listio_15_1_%d", getpid()); unlink(tmpfname); fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL, S_IRUSR | S_IWUSR); if (fd == -1) { printf(TNAME " Error at open(): %s\n", strerror(errno)); exit(PTS_UNRESOLVED); } unlink(tmpfname); bufs = (char *) malloc (NUM_AIOCBS*BUF_SIZE); if (bufs == NULL) { printf (TNAME " Error at malloc(): %s\n", strerror (errno)); close (fd); exit(PTS_UNRESOLVED); } /* Queue up a bunch of aio writes */ for (i = 0; i < NUM_AIOCBS; i++) { aiocbs[i] = (struct aiocb *)malloc(sizeof(struct aiocb)); memset(aiocbs[i], 0, sizeof(struct aiocb)); aiocbs[i]->aio_fildes = fd; aiocbs[i]->aio_offset = 0; aiocbs[i]->aio_buf = &bufs[i*BUF_SIZE]; aiocbs[i]->aio_nbytes = BUF_SIZE; if (i > 3) aiocbs[i]->aio_lio_opcode = LIO_READ; else aiocbs[i]->aio_lio_opcode = LIO_WRITE; /* Use SIRTMIN+1 for individual completions */ aiocbs[i]->aio_sigevent.sigev_notify = SIGEV_SIGNAL; aiocbs[i]->aio_sigevent.sigev_signo = SIGRTMIN+1; aiocbs[i]->aio_sigevent.sigev_value.sival_int = i; } /* Use SIGRTMIN+2 for list completion */ event.sigev_notify = SIGEV_SIGNAL; event.sigev_signo = SIGRTMIN+2; event.sigev_value.sival_ptr = NULL; /* Setup handler for individual operation completion */ action.sa_sigaction = sigrt1_handler; sigemptyset(&action.sa_mask); action.sa_flags = SA_SIGINFO|SA_RESTART; sigaction(SIGRTMIN+1, &action, NULL); /* Setup handler for list completion */ action.sa_sigaction = sigrt2_handler; sigemptyset(&action.sa_mask); action.sa_flags = SA_SIGINFO|SA_RESTART; sigaction(SIGRTMIN+2, &action, NULL); /* Submit request list */ ret = lio_listio(LIO_NOWAIT, aiocbs, NUM_AIOCBS, &event); if (ret != 0) { printf(TNAME " Error lio_listio() returned %d (%s)\n", errno, strerror(errno)); for (i=0; i #include #include #include "posixtest.h" int main() { #if _POSIX_ASYNCHRONOUS_IO != 200112L exit(PTS_UNSUPPORTED); #endif return PTS_UNTESTED; } posixtestsuite/conformance/interfaces/lio_listio/19-1.c0100644000000000000000000000072410247562116022216 0ustar rootroot/* * Copyright (c) 2004, Bull SA. All rights reserved. * Created by: Laurent.Vivier@bull.net * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ #define _XOPEN_SOURCE 600 #include #include #include #include "posixtest.h" int main() { #if _POSIX_ASYNCHRONOUS_IO != 200112L exit(PTS_UNSUPPORTED); #endif return PTS_UNTESTED; } posixtestsuite/conformance/interfaces/lio_listio/5-1.c0100644000000000000000000000602310247562116022127 0ustar rootroot/* * Copyright (c) 2004, Bull SA. All rights reserved. * Created by: Laurent.Vivier@bull.net * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * assertion: * * supported operation for aio_lio_opcode shall be one of LIO_READ, * LIO_WRITE or LIO_NOP. * * method: * * - Open a file for writing * - submit a list using valid opcodes to lio_listio * - Check that no error occurs * - Submit a list with invalid opcodes to lio_listio * - Check that lio_listio returns an error * */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include #include #include #include "posixtest.h" #define NUM_AIOCBS 3 #define BUF_SIZE 1024 #define TNAME "lio_listio/5-1.c" int main() { char tmpfname[256]; int fd; struct aiocb *aiocbs[NUM_AIOCBS]; char buf[BUF_SIZE]; int errors = 0; int ret; int err; int i; #if _POSIX_ASYNCHRONOUS_IO != 200112L exit(PTS_UNSUPPORTED); #endif snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_lio_listio_4_1_%d", getpid()); unlink(tmpfname); fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL, S_IRUSR | S_IWUSR); if (fd == -1) { printf(TNAME " Error at open(): %s\n", strerror(errno)); exit(PTS_UNRESOLVED); } unlink(tmpfname); /* Queue valid lio_opcode requests */ for (i=0; iaio_fildes = fd; aiocbs[i]->aio_offset = 0; aiocbs[i]->aio_buf = buf; aiocbs[i]->aio_nbytes = BUF_SIZE; if (i == 0) aiocbs[i]->aio_lio_opcode = LIO_WRITE; else if (i == 1) aiocbs[i]->aio_lio_opcode = LIO_READ; else aiocbs[i]->aio_lio_opcode = LIO_NOP; } /* Submit request list */ ret = lio_listio(LIO_WAIT, aiocbs, NUM_AIOCBS, NULL); if (ret) { printf(TNAME " lio_listio() does not accept valid opcodes\n"); for (i=0; iaio_lio_opcode = -1; if (lio_listio(LIO_WAIT, aiocbs, 1, NULL) != -1) { printf(TNAME " lio_listio() accepts invalid opcode\n"); for (i=0; i #include #include #include "posixtest.h" int main() { #if _POSIX_ASYNCHRONOUS_IO != 200112L exit(PTS_UNSUPPORTED); #endif return PTS_UNTESTED; } posixtestsuite/conformance/interfaces/lio_listio/4-1.c0100644000000000000000000000777110247562116022141 0ustar rootroot/* * Copyright (c) 2004, Bull SA. All rights reserved. * Created by: Laurent.Vivier@bull.net * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * assertion: * * The list array may contain NULL elements which shall be ignored. * * method: * * - Open a file for writing * - Create an lio list with NULL elements * - submit list to lio_listio * - Check that NULL elements are ignored * */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include "posixtest.h" #define TNAME "lio_listio/4-1.c" #define NUM_AIOCBS 10 #define BUF_SIZE 1024 int num_received = 0; int received_all = 0; void sigrt1_handler(int signum, siginfo_t *info, void *context) { num_received++; } void sigrt2_handler(int signum, siginfo_t *info, void *context) { received_all = 1; } int main() { char tmpfname[256]; int fd; struct aiocb *aiocbs[NUM_AIOCBS]; char *bufs; struct sigaction action; struct sigevent event; int errors = 0; int ret; int err; int i; #if _POSIX_ASYNCHRONOUS_IO != 200112L exit(PTS_UNSUPPORTED); #endif snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_lio_listio_4_1_%d", getpid()); unlink(tmpfname); fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL, S_IRUSR | S_IWUSR); if (fd == -1) { printf(TNAME " Error at open(): %s\n", strerror(errno)); exit(PTS_UNRESOLVED); } unlink(tmpfname); bufs = (char *) malloc (NUM_AIOCBS*BUF_SIZE); if (bufs == NULL) { printf (TNAME " Error at malloc(): %s\n", strerror (errno)); close (fd); exit(PTS_UNRESOLVED); } /* Put NULL elements in list */ for (i=0; iaio_fildes = fd; aiocbs[i]->aio_offset = 0; aiocbs[i]->aio_buf = &bufs[i*BUF_SIZE]; aiocbs[i]->aio_nbytes = BUF_SIZE; aiocbs[i]->aio_lio_opcode = LIO_WRITE; /* Use SIRTMIN+1 for individual completions */ aiocbs[i]->aio_sigevent.sigev_notify = SIGEV_SIGNAL; aiocbs[i]->aio_sigevent.sigev_signo = SIGRTMIN+1; aiocbs[i]->aio_sigevent.sigev_value.sival_int = i; } /* Use SIGRTMIN+2 for list completion */ event.sigev_notify = SIGEV_SIGNAL; event.sigev_signo = SIGRTMIN+2; event.sigev_value.sival_ptr = NULL; /* Setup handler for individual operation completion */ action.sa_sigaction = sigrt1_handler; sigemptyset(&action.sa_mask); action.sa_flags = SA_SIGINFO|SA_RESTART; sigaction(SIGRTMIN+1, &action, NULL); /* Setup handler for list completion */ action.sa_sigaction = sigrt2_handler; sigemptyset(&action.sa_mask); action.sa_flags = SA_SIGINFO|SA_RESTART; sigaction(SIGRTMIN+2, &action, NULL); /* Submit request list */ ret = lio_listio(LIO_NOWAIT, aiocbs, NUM_AIOCBS, &event); if (ret) { printf(TNAME " Error at lio_listio() %d: %s\n", errno, strerror(errno)); for (i=1; i #include #include #include "posixtest.h" int main() { #if _POSIX_ASYNCHRONOUS_IO != 200112L exit(PTS_UNSUPPORTED); #endif return PTS_UNTESTED; } posixtestsuite/conformance/interfaces/lio_listio/14-1.c0100644000000000000000000000746210247562116022217 0ustar rootroot/* * Copyright (c) 2004, Bull SA. All rights reserved. * Created by: Laurent.Vivier@bull.net * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * assertion: * * Failure of an individual request does not prevend completion of any * other individual request. * * method: * * - open a file for writing * - submit a list with an invalid aiocb to lio_listio in LIO_NOWAIT mode * - check that the good requests do not fail * */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include "posixtest.h" #define TNAME "lio_listio/14-1.c" #define NUM_AIOCBS 10 #define BUF_SIZE 1024 int num_received = 0; int received_all = 0; void sigrt1_handler(int signum, siginfo_t *info, void *context) { num_received++; } void sigrt2_handler(int signum, siginfo_t *info, void *context) { received_all = 1; } int main() { char tmpfname[256]; int fd; struct aiocb *aiocbs[NUM_AIOCBS]; char *bufs; struct sigaction action; struct sigevent event; int errors = 0; int ret; int err; int i; #if _POSIX_ASYNCHRONOUS_IO != 200112L exit(PTS_UNSUPPORTED); #endif snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_lio_listio_14_1_%d", getpid()); unlink(tmpfname); fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL, S_IRUSR | S_IWUSR); if (fd == -1) { printf(TNAME " Error at open(): %s\n", strerror(errno)); exit(PTS_UNRESOLVED); } unlink(tmpfname); bufs = (char *) malloc (NUM_AIOCBS*BUF_SIZE); if (bufs == NULL) { printf (TNAME " Error at malloc(): %s\n", strerror (errno)); close (fd); exit(PTS_UNRESOLVED); } /* Queue up a bunch of aio writes */ for (i = 0; i < NUM_AIOCBS; i++) { aiocbs[i] = (struct aiocb *)malloc(sizeof(struct aiocb)); memset(aiocbs[i], 0, sizeof(struct aiocb)); if (i == 2) aiocbs[i]->aio_fildes = -1; else aiocbs[i]->aio_fildes = fd; aiocbs[i]->aio_offset = 0; aiocbs[i]->aio_buf = &bufs[i*BUF_SIZE]; aiocbs[i]->aio_nbytes = BUF_SIZE; aiocbs[i]->aio_lio_opcode = LIO_WRITE; /* Use SIRTMIN+1 for individual completions */ aiocbs[i]->aio_sigevent.sigev_notify = SIGEV_SIGNAL; aiocbs[i]->aio_sigevent.sigev_signo = SIGRTMIN+1; aiocbs[i]->aio_sigevent.sigev_value.sival_int = i; } /* Use SIGRTMIN+2 for list completion */ event.sigev_notify = SIGEV_SIGNAL; event.sigev_signo = SIGRTMIN+2; event.sigev_value.sival_ptr = NULL; /* Setup handler for individual operation completion */ action.sa_sigaction = sigrt1_handler; sigemptyset(&action.sa_mask); action.sa_flags = SA_SIGINFO|SA_RESTART; sigaction(SIGRTMIN+1, &action, NULL); /* Setup handler for list completion */ action.sa_sigaction = sigrt2_handler; sigemptyset(&action.sa_mask); action.sa_flags = SA_SIGINFO|SA_RESTART; sigaction(SIGRTMIN+2, &action, NULL); /* Submit request list */ ret = lio_listio(LIO_NOWAIT, aiocbs, NUM_AIOCBS, &event); if (ret != 0) { printf(TNAME " Error lio_listio() %s\n", strerror(errno)); for (i=0; i #include #include #include #include #include #include "posixtest.h" #define TNAME "lio_listio/18-1.c" #define NUM_AIOCBS 1 #define BUF_SIZE 1024 int main() { char tmpfname[256]; int fd; struct aiocb *aiocbs[NUM_AIOCBS]; char *bufs; int ret; #if _POSIX_ASYNCHRONOUS_IO != 200112L exit(PTS_UNSUPPORTED); #endif snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_lio_listio_18_1_%d", getpid()); unlink(tmpfname); fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL, S_IRUSR | S_IWUSR); if (fd == -1) { printf(TNAME " Error at open(): %s\n", strerror(errno)); exit(PTS_UNRESOLVED); } unlink(tmpfname); bufs = (char *) malloc (NUM_AIOCBS*BUF_SIZE); if (bufs == NULL) { printf (TNAME " Error at malloc(): %s\n", strerror (errno)); close (fd); exit(PTS_UNRESOLVED); } aiocbs[0] = (struct aiocb *)malloc(sizeof(struct aiocb)); memset(aiocbs[0], 0, sizeof(struct aiocb)); aiocbs[0]->aio_fildes = fd; aiocbs[0]->aio_offset = 0; aiocbs[0]->aio_buf = bufs; aiocbs[0]->aio_nbytes = BUF_SIZE; aiocbs[0]->aio_lio_opcode = LIO_WRITE; /* Submit request list */ ret = lio_listio(-1, aiocbs, NUM_AIOCBS, NULL); if (ret != -1) { printf(TNAME " Error lio_listio() should have returned -1: %d\n", ret); free (aiocbs[0]); free (bufs); close (fd); exit (PTS_FAIL); } if (errno != EINVAL) { printf(TNAME " Error lio_listio() should have set errno to EINVAL: %d (%s)\n", errno, strerror(errno)); free (aiocbs[0]); free (bufs); close (fd); exit (PTS_FAIL); } free (aiocbs[0]); free (bufs); close (fd); printf (TNAME " PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/lio_listio/12-1.c0100644000000000000000000000474510247562116022216 0ustar rootroot/* * Copyright (c) 2004, Bull SA. All rights reserved. * Created by: Laurent.Vivier@bull.net * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * assertion: * * if mode is LIO_WAIT, lio_listio() shall return the value zero when * all I/O has completed successfully. * * method: * * - open a file for writing * - submit a list of writes to lio_listio in LIO_WAIT mode * - check that lio_listio returns 0 upon completion * */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include "posixtest.h" #define TNAME "lio_listio/12-1.c" #define NUM_AIOCBS 10 #define BUF_SIZE 1024 int main() { char tmpfname[256]; int fd; struct aiocb *aiocbs[NUM_AIOCBS]; char *bufs; int errors = 0; int ret; int err; int i; #if _POSIX_ASYNCHRONOUS_IO != 200112L exit(PTS_UNSUPPORTED); #endif snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_lio_listio_12_1_%d", getpid()); unlink(tmpfname); fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL, S_IRUSR | S_IWUSR); if (fd == -1) { printf(TNAME " Error at open(): %s\n", strerror(errno)); exit(PTS_UNRESOLVED); } unlink(tmpfname); bufs = (char *) malloc (NUM_AIOCBS*BUF_SIZE); if (bufs == NULL) { printf (TNAME " Error at malloc(): %s\n", strerror (errno)); close (fd); exit(PTS_UNRESOLVED); } /* Queue up a bunch of aio writes */ for (i = 0; i < NUM_AIOCBS; i++) { aiocbs[i] = (struct aiocb *)malloc(sizeof(struct aiocb)); memset(aiocbs[i], 0, sizeof(struct aiocb)); aiocbs[i]->aio_fildes = fd; aiocbs[i]->aio_offset = 0; aiocbs[i]->aio_buf = &bufs[i*BUF_SIZE]; aiocbs[i]->aio_nbytes = BUF_SIZE; aiocbs[i]->aio_lio_opcode = LIO_WRITE; } /* Submit request list */ ret = lio_listio(LIO_WAIT, aiocbs, NUM_AIOCBS, NULL); if (ret) { printf(TNAME " Error at lio_listio() %d: %s\n", errno, strerror(errno)); for (i=0; i #include #include #include #include #include #include "posixtest.h" #define TNAME "lio_listio/1-1.c" #define NUM_AIOCBS 10 #define BUF_SIZE 1024*1024 int received_selected = 0; int received_all = 0; void sigrt1_handler(int signum, siginfo_t *info, void *context) { received_selected = info->si_value.sival_int; } void sigrt2_handler(int signum, siginfo_t *info, void *context) { received_all = 1; } int main() { char tmpfname[256]; int fd; struct aiocb **aiocbs; char *bufs; struct sigaction action; struct sigevent event; int errors = 0; int ret; int err; int i; #if _POSIX_ASYNCHRONOUS_IO != 200112L exit(PTS_UNSUPPORTED); #endif snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_lio_listio_1_1_%d", getpid()); unlink(tmpfname); fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL, S_IRUSR | S_IWUSR); if (fd == -1) { printf(TNAME " Error at open(): %s\n", strerror(errno)); exit(PTS_UNRESOLVED); } unlink(tmpfname); bufs = (char *) malloc (NUM_AIOCBS*BUF_SIZE); if (bufs == NULL) { printf (TNAME " Error at malloc(): %s\n", strerror (errno)); close (fd); exit(PTS_UNRESOLVED); } aiocbs = (struct aiocb**)malloc(sizeof(struct aiocb *) * NUM_AIOCBS); /* Queue up a bunch of aio writes */ for (i = 0; i < NUM_AIOCBS; i++) { aiocbs[i] = (struct aiocb *)malloc(sizeof(struct aiocb)); memset(aiocbs[i], 0, sizeof(struct aiocb)); aiocbs[i]->aio_fildes = fd; aiocbs[i]->aio_offset = 0; aiocbs[i]->aio_buf = &bufs[i*BUF_SIZE]; aiocbs[i]->aio_nbytes = BUF_SIZE; aiocbs[i]->aio_lio_opcode = LIO_WRITE; /* Use SIRTMIN+1 for individual completions */ aiocbs[i]->aio_sigevent.sigev_notify = SIGEV_SIGNAL; aiocbs[i]->aio_sigevent.sigev_signo = SIGRTMIN+1; aiocbs[i]->aio_sigevent.sigev_value.sival_int = i; } /* Use SIGRTMIN+2 for list completion */ event.sigev_notify = SIGEV_SIGNAL; event.sigev_signo = SIGRTMIN+2; event.sigev_value.sival_ptr = NULL; /* Setup handler for individual operation completion */ action.sa_sigaction = sigrt1_handler; sigemptyset(&action.sa_mask); action.sa_flags = SA_SIGINFO|SA_RESTART; sigaction(SIGRTMIN+1, &action, NULL); /* Setup handler for list completion */ action.sa_sigaction = sigrt2_handler; sigemptyset(&action.sa_mask); action.sa_flags = SA_SIGINFO|SA_RESTART; sigaction(SIGRTMIN+2, &action, NULL); /* Submit request list */ ret = lio_listio(LIO_WAIT, aiocbs, NUM_AIOCBS, &event); if (ret) { printf(TNAME " Error at lio_listio() %d: %s\n", errno, strerror(errno)); for (i=0; i #include #include #include #include #include #include #include #include #include "posixtest.h" #define TNAME "lio_listio/9-1.c" int main() { char tmpfname[256]; #define BUF_SIZE 512 unsigned char buf[BUF_SIZE]; unsigned char check[BUF_SIZE]; int fd; struct aiocb aiocb; struct aiocb *list[1]; int err; int ret; int i; #if _POSIX_ASYNCHRONOUS_IO != 200112L exit(PTS_UNSUPPORTED); #endif snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_lio_listio_9_1_%d", getpid()); unlink(tmpfname); fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL, S_IRUSR | S_IWUSR); if (fd == -1) { printf(TNAME " Error at open(): %s\n", strerror(errno)); exit(PTS_UNRESOLVED); } unlink(tmpfname); for (i = 0; i < BUF_SIZE; i++) buf[i] = i; memset(&aiocb, 0, sizeof(struct aiocb)); aiocb.aio_fildes = fd; aiocb.aio_buf = buf; aiocb.aio_nbytes = BUF_SIZE; aiocb.aio_lio_opcode = LIO_WRITE; list[0] = &aiocb; if (lio_listio(LIO_WAIT, list, 1, NULL) == -1) { printf(TNAME " Error at lio_listio(): %s\n", strerror(errno)); exit(PTS_FAIL); } /* Check return values */ err = aio_error(&aiocb); ret = aio_return(&aiocb); if (err != 0) { printf(TNAME " Error at aio_error(): %s\n", strerror(errno)); close(fd); exit(PTS_FAIL); } if (ret != BUF_SIZE) { printf(TNAME " Error at aio_return(): %d\n", ret); close(fd); exit(PTS_FAIL); } memset(check, 0xaa, BUF_SIZE); if (read(fd, check, BUF_SIZE) != BUF_SIZE) { printf(TNAME " Error at read(): %s\n", strerror(errno)); close(fd); exit(PTS_UNRESOLVED); } /* check it */ for (i = 0; i < BUF_SIZE; i++) { if (buf[i] != check[i]) { printf(TNAME " read values are corrupted\n"); exit(PTS_FAIL); } } close(fd); printf ("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/lio_listio/20-1.c0100644000000000000000000000072410247562116022206 0ustar rootroot/* * Copyright (c) 2004, Bull SA. All rights reserved. * Created by: Laurent.Vivier@bull.net * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ #define _XOPEN_SOURCE 600 #include #include #include #include "posixtest.h" int main() { #if _POSIX_ASYNCHRONOUS_IO != 200112L exit(PTS_UNSUPPORTED); #endif return PTS_UNTESTED; } posixtestsuite/conformance/interfaces/lio_listio/11-1.c0100644000000000000000000000754110247562116022212 0ustar rootroot/* * Copyright (c) 2004, Bull SA. All rights reserved. * Created by: Laurent.Vivier@bull.net * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * assertion: * * if mode is LIO_NOWAIT, lio_listio() shall return the value -1 and set * errno to indicate error if the operation is not succesfully queued. * * method: * * - open a file for writing * - submit a list with invalid opcodes to lio_listio in LIO_NOWAIT mode * - check that lio_listio returns -1 * */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include "posixtest.h" #define TNAME "lio_listio/11-1.c" #define NUM_AIOCBS 10 #define BUF_SIZE 1024 int received_selected = 0; int received_all = 0; void sigrt1_handler(int signum, siginfo_t *info, void *context) { received_selected = info->si_value.sival_int; } void sigrt2_handler(int signum, siginfo_t *info, void *context) { received_all = 1; } int main() { char tmpfname[256]; int fd; struct aiocb *aiocbs[NUM_AIOCBS]; char *bufs; struct sigaction action; struct sigevent event; int errors = 0; int ret; int err; int i; #if _POSIX_ASYNCHRONOUS_IO != 200112L exit(PTS_UNSUPPORTED); #endif snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_lio_listio_11_1_%d", getpid()); unlink(tmpfname); fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL, S_IRUSR | S_IWUSR); if (fd == -1) { printf(TNAME " Error at open(): %s\n", strerror(errno)); exit(PTS_UNRESOLVED); } unlink(tmpfname); bufs = (char *) malloc (NUM_AIOCBS*BUF_SIZE); if (bufs == NULL) { printf (TNAME " Error at malloc(): %s\n", strerror (errno)); close (fd); exit(PTS_UNRESOLVED); } /* Queue up a bunch of aio writes */ for (i = 0; i < NUM_AIOCBS; i++) { aiocbs[i] = (struct aiocb *)malloc(sizeof(struct aiocb)); memset(aiocbs[i], 0, sizeof(struct aiocb)); aiocbs[i]->aio_fildes = fd; aiocbs[i]->aio_offset = 0; aiocbs[i]->aio_buf = &bufs[i*BUF_SIZE]; aiocbs[i]->aio_nbytes = BUF_SIZE; if (i == 2) aiocbs[i]->aio_lio_opcode = -1; else aiocbs[i]->aio_lio_opcode = LIO_WRITE; /* Use SIRTMIN+1 for individual completions */ aiocbs[i]->aio_sigevent.sigev_notify = SIGEV_SIGNAL; aiocbs[i]->aio_sigevent.sigev_signo = SIGRTMIN+1; aiocbs[i]->aio_sigevent.sigev_value.sival_int = i; } /* Use SIGRTMIN+2 for list completion */ event.sigev_notify = SIGEV_SIGNAL; event.sigev_signo = SIGRTMIN+2; event.sigev_value.sival_ptr = NULL; /* Setup handler for individual operation completion */ action.sa_sigaction = sigrt1_handler; sigemptyset(&action.sa_mask); action.sa_flags = SA_SIGINFO|SA_RESTART; sigaction(SIGRTMIN+1, &action, NULL); /* Setup handler for list completion */ action.sa_sigaction = sigrt2_handler; sigemptyset(&action.sa_mask); action.sa_flags = SA_SIGINFO|SA_RESTART; sigaction(SIGRTMIN+2, &action, NULL); /* Submit request list */ ret = lio_listio(LIO_NOWAIT, aiocbs, NUM_AIOCBS, &event); if (ret == 0) { printf(TNAME " Error lio_listio() should have returned -1\n"); for (i=0; i #include #include #include "posixtest.h" int main() { #if _POSIX_ASYNCHRONOUS_IO != 200112L exit(PTS_UNSUPPORTED); #endif return PTS_UNTESTED; } posixtestsuite/conformance/interfaces/lio_listio/6-1.c0100644000000000000000000000205210247562116022126 0ustar rootroot/* * Copyright (c) 2004, Bull SA. All rights reserved. * Created by: Laurent.Vivier@bull.net * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * assertion: * * LIO_READ, LIO_WRITE and LIO_NOP are defined in <aio.h>. * * method: * * - Check opcodes are defined when including aio.h * */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include #include #include #include "posixtest.h" #define TNAME "lio_listio/6-1.c" int main() { #if _POSIX_ASYNCHRONOUS_IO != 200112L exit(PTS_UNSUPPORTED); #endif #ifndef LIO_READ printf(TNAME " LIO_READ not defined\n"); exit(PTS_FAIL); #endif #ifndef LIO_WRITE printf(TNAME " LIO_WRITE not defined\n"); exit(PTS_FAIL); #endif #ifndef LIO_WRITE printf(TNAME " LIO_WRITE not defined\n"); exit(PTS_FAIL); #endif printf ("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/lio_listio/10-1.c0100644000000000000000000000711710247562116022210 0ustar rootroot/* * Copyright (c) 2004, Bull SA. All rights reserved. * Created by: Laurent.Vivier@bull.net * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * assertion: * * if mode is LIO_NOWAIT, lio_listio() shall return the value zero if * operation is successfuly queued. * * method: * * - open a file for writing * - submit a list of writes to lio_listio in LIO_NOWAIT mode * - check that lio_listio returns 0 and operations complete successfully * */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include "posixtest.h" #define TNAME "lio_listio/10-1.c" #define NUM_AIOCBS 10 #define BUF_SIZE 1024 int received_selected = 0; int received_all = 0; void sigrt1_handler(int signum, siginfo_t *info, void *context) { received_selected = info->si_value.sival_int; } void sigrt2_handler(int signum, siginfo_t *info, void *context) { received_all = 1; } int main() { char tmpfname[256]; int fd; struct aiocb *aiocbs[NUM_AIOCBS]; char *bufs; struct sigaction action; struct sigevent event; int errors = 0; int ret; int err; int i; #if _POSIX_ASYNCHRONOUS_IO != 200112L exit(PTS_UNSUPPORTED); #endif snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_lio_listio_10_1_%d", getpid()); unlink(tmpfname); fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL, S_IRUSR | S_IWUSR); if (fd == -1) { printf(TNAME " Error at open(): %s\n", strerror(errno)); exit(PTS_UNRESOLVED); } unlink(tmpfname); bufs = (char *) malloc (NUM_AIOCBS*BUF_SIZE); if (bufs == NULL) { printf (TNAME " Error at malloc(): %s\n", strerror (errno)); close (fd); exit(PTS_UNRESOLVED); } /* Queue up a bunch of aio writes */ for (i = 0; i < NUM_AIOCBS; i++) { aiocbs[i] = (struct aiocb *)malloc(sizeof(struct aiocb)); memset(aiocbs[i], 0, sizeof(struct aiocb)); aiocbs[i]->aio_fildes = fd; aiocbs[i]->aio_offset = 0; aiocbs[i]->aio_buf = &bufs[i*BUF_SIZE]; aiocbs[i]->aio_nbytes = BUF_SIZE; aiocbs[i]->aio_lio_opcode = LIO_WRITE; /* Use SIRTMIN+1 for individual completions */ aiocbs[i]->aio_sigevent.sigev_notify = SIGEV_SIGNAL; aiocbs[i]->aio_sigevent.sigev_signo = SIGRTMIN+1; aiocbs[i]->aio_sigevent.sigev_value.sival_int = i; } /* Use SIGRTMIN+2 for list completion */ event.sigev_notify = SIGEV_SIGNAL; event.sigev_signo = SIGRTMIN+2; event.sigev_value.sival_ptr = NULL; /* Setup handler for individual operation completion */ action.sa_sigaction = sigrt1_handler; sigemptyset(&action.sa_mask); action.sa_flags = SA_SIGINFO|SA_RESTART; sigaction(SIGRTMIN+1, &action, NULL); /* Setup handler for list completion */ action.sa_sigaction = sigrt2_handler; sigemptyset(&action.sa_mask); action.sa_flags = SA_SIGINFO|SA_RESTART; sigaction(SIGRTMIN+2, &action, NULL); /* Submit request list */ ret = lio_listio(LIO_NOWAIT, aiocbs, NUM_AIOCBS, &event); if (ret) { printf(TNAME " Error at lio_listio() %d: %s\n", errno, strerror(errno)); for (i=0; i #include #include #include #include #include #include "posixtest.h" #define TNAME "lio_listio/13-1.c" #define NUM_AIOCBS 10 #define BUF_SIZE 1024 int main() { char tmpfname[256]; int fd; struct aiocb *aiocbs[NUM_AIOCBS]; char *bufs; int errors = 0; int ret; int err; int i; #if _POSIX_ASYNCHRONOUS_IO != 200112L exit(PTS_UNSUPPORTED); #endif snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_lio_listio_13_1_%d", getpid()); unlink(tmpfname); fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL, S_IRUSR | S_IWUSR); if (fd == -1) { printf(TNAME " Error at open(): %s\n", strerror(errno)); exit(PTS_UNRESOLVED); } unlink(tmpfname); bufs = (char *) malloc (NUM_AIOCBS*BUF_SIZE); if (bufs == NULL) { printf (TNAME " Error at malloc(): %s\n", strerror (errno)); close (fd); exit(PTS_UNRESOLVED); } /* Queue up a bunch of aio writes */ for (i = 0; i < NUM_AIOCBS; i++) { aiocbs[i] = (struct aiocb *)malloc(sizeof(struct aiocb)); memset(aiocbs[i], 0, sizeof(struct aiocb)); aiocbs[i]->aio_fildes = fd; aiocbs[i]->aio_offset = 0; aiocbs[i]->aio_buf = &bufs[i*BUF_SIZE]; aiocbs[i]->aio_nbytes = BUF_SIZE; if (i == 2) aiocbs[i]->aio_lio_opcode = -1; else aiocbs[i]->aio_lio_opcode = LIO_WRITE; } /* Submit request list */ ret = lio_listio(LIO_WAIT, aiocbs, NUM_AIOCBS, NULL); if (ret == 0) { printf(TNAME " Error lio_listio() should have returned -1\n"); for (i=0; i #include #include #include #include #include #include #include #include #include "posixtest.h" #define TNAME "lio_listio/7-1.c" #define NUM_AIOCBS 10 #define BUF_SIZE 1024 int num_received = 0; int received_all = 0; void sigrt1_handler(int signum, siginfo_t *info, void *context) { num_received++; } void sigrt2_handler(int signum, siginfo_t *info, void *context) { received_all = 1; } int main() { char tmpfname[256]; int fd; struct aiocb *aiocbs[NUM_AIOCBS]; char *bufs; struct sigaction action; struct sigevent event; int errors = 0; int ret; int err; int i; #if _POSIX_ASYNCHRONOUS_IO != 200112L exit(PTS_UNSUPPORTED); #endif snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_lio_listio_4_1_%d", getpid()); unlink(tmpfname); fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL, S_IRUSR | S_IWUSR); if (fd == -1) { printf(TNAME " Error at open(): %s\n", strerror(errno)); exit(PTS_UNRESOLVED); } unlink(tmpfname); bufs = (char *) malloc (NUM_AIOCBS*BUF_SIZE); if (bufs == NULL) { printf (TNAME " Error at malloc(): %s\n", strerror (errno)); close (fd); exit(PTS_UNRESOLVED); } /* Queue up a bunch of aio writes */ for (i=0; iaio_fildes = fd; aiocbs[i]->aio_offset = 0; aiocbs[i]->aio_buf = &bufs[i*BUF_SIZE]; aiocbs[i]->aio_nbytes = BUF_SIZE; if ((i == 1) || (i == 7)) aiocbs[i]->aio_lio_opcode = LIO_NOP; else aiocbs[i]->aio_lio_opcode = LIO_WRITE; /* Use SIRTMIN+1 for individual completions */ aiocbs[i]->aio_sigevent.sigev_notify = SIGEV_SIGNAL; aiocbs[i]->aio_sigevent.sigev_signo = SIGRTMIN+1; aiocbs[i]->aio_sigevent.sigev_value.sival_int = i; } /* Use SIGRTMIN+2 for list completion */ event.sigev_notify = SIGEV_SIGNAL; event.sigev_signo = SIGRTMIN+2; event.sigev_value.sival_ptr = NULL; /* Setup handler for individual operation completion */ action.sa_sigaction = sigrt1_handler; sigemptyset(&action.sa_mask); action.sa_flags = SA_SIGINFO|SA_RESTART; sigaction(SIGRTMIN+1, &action, NULL); /* Setup handler for list completion */ action.sa_sigaction = sigrt2_handler; sigemptyset(&action.sa_mask); action.sa_flags = SA_SIGINFO|SA_RESTART; sigaction(SIGRTMIN+2, &action, NULL); /* Submit request list */ ret = lio_listio(LIO_NOWAIT, aiocbs, NUM_AIOCBS, &event); if (ret) { printf(TNAME " Error at lio_listio() %d: %s\n", errno, strerror(errno)); for (i=1; i If mode is LIO_WAIT, lio_listio() shall wait until all I/O is complete and the sig argument shall be ignored. If mode is LIO_NOWAIT, lio_listio() shall return immediately. If mode is LIO_NOWAIT, and sig is not NULL, asynchronous notification shall occurs when all I/O operations complete. The list array may contain NULL elements which shall be ignored. supported operation for aio_lio_opcode shall be one of LIO_READ, LIO_WRITE or LIO_NOP. LIO_READ, LIO_WRITE and LIO_NOP are defined in <aio.h>. LIO_NOP causes the entry to be ignored. LIO_READ causes the entry to be submited as if by a call to aio_read(). LIO_WRITE causes the entry to be submited as if by a call to aio_write(). if mode is LIO_NOWAIT, lio_listio() shall return the value zero if operation is successfuly queued. if mode is LIO_NOWAIT, lio_listio() shall return the value -1 and set errno to indicate error if the operation is not succesfully queued. if mode is LIO_WAIT, lio_listio() shall return the value zero when all I/O has completed successfully. if mode is LIO_WAIT, lio_listio() shall return the value -1 and set errno to indicate error if all operation has not successfully completed. Failure of an individual request does not prevend completion of any other individual request. The error statuses returned are identical to those returned as the result of an aio_read() or aio_write(). lio_listio() shall fail if: [EAGAIN] The resource necessary to queue all the I/O request were not available. lio_listio() shall fail if: [EAGAIN] the number of entries indicated by nent would cause the system-wide limit {AIO_MAX} to be exceeded. lio_listio() shall fail if: [EINVAL] mode is not LIO_NOWAIT or LIO_WAIT, or nent is greater than {AIO_LISTIO_MAX} [EINTR] A signal was delivered while waiting for all I/O requests to complete during an LIO_WAIT operation. if lio_listio() fails with an error other than [EAGAIN], [EINTR] or [EIO] no operations from the list shall be initiated. The error status of the operation shall be: [EAGAIN] The requested I/O was not queued due to resource limitations. The error status of the operation shall be: [ECANCELED] The requested I/O was canceled before the I/O completed due to an explicit aio_cancel() request. The error status of the operation shall be: [EFBIG] aio_lio_opcode is LIO_WRITE, aio_nbytes is greater than 0, and aio_offset is before the EOF and is greater or equal to the offset maximum associated with aio_fildes. The error status of the operation shall be: [EINPROGRESS] The requested I/O is in progress The error status of the operation shall be: [EOVERFLOW] aio_lio_opcode is LIO_READ, aio_nbytes is greater than 0, and aio_offset is before the EOF and is greater or equal to the offset maximum associated with aio_fildes. posixtestsuite/conformance/interfaces/lio_listio/21-1.c0100644000000000000000000000072410247562116022207 0ustar rootroot/* * Copyright (c) 2004, Bull SA. All rights reserved. * Created by: Laurent.Vivier@bull.net * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ #define _XOPEN_SOURCE 600 #include #include #include #include "posixtest.h" int main() { #if _POSIX_ASYNCHRONOUS_IO != 200112L exit(PTS_UNSUPPORTED); #endif return PTS_UNTESTED; } posixtestsuite/conformance/interfaces/lio_listio/25-1.c0100644000000000000000000000072410247562116022213 0ustar rootroot/* * Copyright (c) 2004, Bull SA. All rights reserved. * Created by: Laurent.Vivier@bull.net * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ #define _XOPEN_SOURCE 600 #include #include #include #include "posixtest.h" int main() { #if _POSIX_ASYNCHRONOUS_IO != 200112L exit(PTS_UNSUPPORTED); #endif return PTS_UNTESTED; } posixtestsuite/conformance/interfaces/lio_listio/coverage.txt0100644000000000000000000000042010245504306024003 0ustar rootrootthis file defines the coverage for the lio_listio() function testing. Assertion Covered? 1 YES 2 YES 3 YES 4 YES 5 YES 6 YES 7 YES 8 YES 9 YES 10 YES 11 YES 12 YES 13 YES 14 YES 15 YES 16 NO 17 NO 18 YES 19 NO 20 NO 21 NO 22 NO 23 NO 24 NO 25 NO posixtestsuite/conformance/interfaces/lio_listio/8-1.c0100644000000000000000000000455110247562116022136 0ustar rootroot/* * Copyright (c) 2004, Bull SA. All rights reserved. * Created by: Laurent.Vivier@bull.net * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * assertion: * * LIO_READ causes the entry to be submited as if by a call to aio_read(). * * method: * * - open a file * - write data * - submit read request to lio_listio * - check data is read correctly * */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include #include #include #include "posixtest.h" #define TNAME "lio_listio/8-1.c" int main() { char tmpfname[256]; #define BUF_SIZE 512 unsigned char buf[BUF_SIZE]; unsigned char check[BUF_SIZE]; int fd; struct aiocb aiocb; struct aiocb *list[1]; int i; int err; int ret; #if _POSIX_ASYNCHRONOUS_IO != 200112L exit(PTS_UNSUPPORTED); #endif snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_lio_listio_8_1_%d", getpid()); unlink(tmpfname); fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL, S_IRUSR | S_IWUSR); if (fd == -1) { printf(TNAME " Error at open(): %s\n", strerror(errno)); exit(PTS_UNRESOLVED); } unlink(tmpfname); for (i = 0; i < BUF_SIZE; i++) buf[i] = i; if (write(fd, buf, BUF_SIZE) != BUF_SIZE) { printf(TNAME " Error at write(): %s\n", strerror(errno)); exit(PTS_UNRESOLVED); } memset(check, 0xaa, BUF_SIZE); memset(&aiocb, 0, sizeof(struct aiocb)); aiocb.aio_fildes = fd; aiocb.aio_buf = check; aiocb.aio_nbytes = BUF_SIZE; aiocb.aio_lio_opcode = LIO_READ; list[0] = &aiocb; if (lio_listio(LIO_WAIT, list, 1, NULL) == -1) { printf(TNAME " Error at lio_listio(): %s\n", strerror(errno)); close(fd); exit(PTS_FAIL); } /* Check return values */ err = aio_error(&aiocb); ret = aio_return(&aiocb); if (err != 0) { printf(TNAME " Error at aio_error(): %s\n", strerror(errno)); close(fd); exit(PTS_FAIL); } if (ret != BUF_SIZE) { printf(TNAME " Error at aio_return(): %d\n", ret); close(fd); exit(PTS_FAIL); } /* check it */ for (i = 0; i < BUF_SIZE; i++) { if (buf[i] != check[i]) { printf(TNAME " read values are corrupted\n"); exit(PTS_FAIL); } } close(fd); printf ("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/lio_listio/16-1.c0100644000000000000000000000120310247562116022204 0ustar rootroot/* * Copyright (c) 2004, Bull SA. All rights reserved. * Created by: Laurent.Vivier@bull.net * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * assertion: * * lio_listio() shall fail if: * [EAGAIN] The resource necessary to queue all the I/O request were not * available. * * method: * * UNTESTED * */ #define _XOPEN_SOURCE 600 #include #include #include #include "posixtest.h" int main() { #if _POSIX_ASYNCHRONOUS_IO != 200112L exit(PTS_UNSUPPORTED); #endif return PTS_UNTESTED; } posixtestsuite/conformance/interfaces/lio_listio/2-1.c0100644000000000000000000000762510247562116022135 0ustar rootroot/* * Copyright (c) 2004, Bull SA. All rights reserved. * Created by: Laurent.Vivier@bull.net * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * assertion: * * If mode is LIO_NOWAIT, lio_listio() shall return immediately. * * method: * * - open a file for writing * - submit a list of writes to lio_listio in LIO_NOWAIT mode * - check that upon return some I/Os are still running * */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include "posixtest.h" #define TNAME "lio_listio/2-1.c" #define NUM_AIOCBS 10 #define BUF_SIZE 1024 int received_selected = 0; int received_all = 0; void sigrt1_handler(int signum, siginfo_t *info, void *context) { received_selected = info->si_value.sival_int; } void sigrt2_handler(int signum, siginfo_t *info, void *context) { received_all = 1; } int main() { char tmpfname[256]; int fd; struct aiocb *aiocbs[NUM_AIOCBS]; char *bufs; struct sigaction action; struct sigevent event; int errors = 0; int ret; int err; int i; #if _POSIX_ASYNCHRONOUS_IO != 200112L exit(PTS_UNSUPPORTED); #endif snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_lio_listio_2_1_%d", getpid()); unlink(tmpfname); fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL, S_IRUSR | S_IWUSR); if (fd == -1) { printf(TNAME " Error at open(): %s\n", strerror(errno)); exit(PTS_UNRESOLVED); } unlink(tmpfname); bufs = (char *) malloc (NUM_AIOCBS*BUF_SIZE); if (bufs == NULL) { printf (TNAME " Error at malloc(): %s\n", strerror (errno)); close (fd); exit(PTS_UNRESOLVED); } /* Queue up a bunch of aio writes */ for (i = 0; i < NUM_AIOCBS; i++) { aiocbs[i] = (struct aiocb *)malloc(sizeof(struct aiocb)); memset(aiocbs[i], 0, sizeof(struct aiocb)); aiocbs[i]->aio_fildes = fd; aiocbs[i]->aio_offset = 0; aiocbs[i]->aio_buf = &bufs[i*BUF_SIZE]; aiocbs[i]->aio_nbytes = BUF_SIZE; aiocbs[i]->aio_lio_opcode = LIO_WRITE; /* Use SIRTMIN+1 for individual completions */ aiocbs[i]->aio_sigevent.sigev_notify = SIGEV_SIGNAL; aiocbs[i]->aio_sigevent.sigev_signo = SIGRTMIN+1; aiocbs[i]->aio_sigevent.sigev_value.sival_int = i; } /* Use SIGRTMIN+2 for list completion */ event.sigev_notify = SIGEV_SIGNAL; event.sigev_signo = SIGRTMIN+2; event.sigev_value.sival_ptr = NULL; /* Setup handler for individual operation completion */ action.sa_sigaction = sigrt1_handler; sigemptyset(&action.sa_mask); action.sa_flags = SA_SIGINFO|SA_RESTART; sigaction(SIGRTMIN+1, &action, NULL); /* Setup handler for list completion */ action.sa_sigaction = sigrt2_handler; sigemptyset(&action.sa_mask); action.sa_flags = SA_SIGINFO|SA_RESTART; sigaction(SIGRTMIN+2, &action, NULL); /* Submit request list */ ret = lio_listio(LIO_NOWAIT, aiocbs, NUM_AIOCBS, &event); if (ret) { printf(TNAME " Error at lio_listio() %d: %s\n", errno, strerror(errno)); for (i=0; i #include #include #include #include #include #include "posixtest.h" #define TNAME "lio_listio/3-1.c" #define NUM_AIOCBS 10 #define BUF_SIZE 1024 int received_selected = 0; int received_all = 0; void sigrt1_handler(int signum, siginfo_t *info, void *context) { received_selected = info->si_value.sival_int; } void sigrt2_handler(int signum, siginfo_t *info, void *context) { received_all = 1; } int main() { char tmpfname[256]; int fd; struct aiocb *aiocbs[NUM_AIOCBS]; char *bufs; struct sigaction action; struct sigevent event; int errors = 0; int ret; int err; int i; #if _POSIX_ASYNCHRONOUS_IO != 200112L exit(PTS_UNSUPPORTED); #endif snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_lio_listio_3_1_%d", getpid()); unlink(tmpfname); fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL, S_IRUSR | S_IWUSR); if (fd == -1) { printf(TNAME " Error at open(): %s\n", strerror(errno)); exit(PTS_UNRESOLVED); } unlink(tmpfname); bufs = (char *) malloc (NUM_AIOCBS*BUF_SIZE); if (bufs == NULL) { printf (TNAME " Error at malloc(): %s\n", strerror (errno)); close (fd); exit(PTS_UNRESOLVED); } /* Queue up a bunch of aio writes */ for (i = 0; i < NUM_AIOCBS; i++) { aiocbs[i] = (struct aiocb *)malloc(sizeof(struct aiocb)); memset(aiocbs[i], 0, sizeof(struct aiocb)); aiocbs[i]->aio_fildes = fd; aiocbs[i]->aio_offset = 0; aiocbs[i]->aio_buf = &bufs[i*BUF_SIZE]; aiocbs[i]->aio_nbytes = BUF_SIZE; aiocbs[i]->aio_lio_opcode = LIO_WRITE; /* Use SIRTMIN+1 for individual completions */ aiocbs[i]->aio_sigevent.sigev_notify = SIGEV_SIGNAL; aiocbs[i]->aio_sigevent.sigev_signo = SIGRTMIN+1; aiocbs[i]->aio_sigevent.sigev_value.sival_int = i; } /* Use SIGRTMIN+2 for list completion */ event.sigev_notify = SIGEV_SIGNAL; event.sigev_signo = SIGRTMIN+2; event.sigev_value.sival_ptr = NULL; /* Setup handler for individual operation completion */ action.sa_sigaction = sigrt1_handler; sigemptyset(&action.sa_mask); action.sa_flags = SA_SIGINFO|SA_RESTART; sigaction(SIGRTMIN+1, &action, NULL); /* Setup handler for list completion */ action.sa_sigaction = sigrt2_handler; sigemptyset(&action.sa_mask); action.sa_flags = SA_SIGINFO|SA_RESTART; sigaction(SIGRTMIN+2, &action, NULL); /* Submit request list */ ret = lio_listio(LIO_NOWAIT, aiocbs, NUM_AIOCBS, &event); if (ret) { printf(TNAME " Error at lio_listio() %d: %s\n", errno, strerror(errno)); for (i=0; i/dev/null 2>&1 rm -f a.out >/dev/null 2>&1 for sem_id in `ipcs -s | awk '{print $2}'` ; do ipcrm sem $sem_id > /dev/null 2>&1 done posixtestsuite/conformance/interfaces/sem_close/1-1.c0100644000000000000000000000213410514634236021725 0ustar rootroot/* Copyright (c) 2002, Intel Corporation. All rights reserved. Created by: majid.awad REMOVE-THIS AT intel DOT com This file is licensed under the GPL license. For the full content of this license, see the COPYING file at the top level of this source tree. */ /* sem_close test case that attempts to close an open semaphore, close the semaphore and verify that close_sem returns 0. */ #include #include #include #include #include #include #include #include "posixtest.h" #define TEST "1-1" #define FUNCTION "sem_close" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " int main() { sem_t *mysemp; char semname[20]; sprintf(semname, "/" FUNCTION "_" TEST "_%d", getpid()); mysemp = sem_open(semname, O_CREAT, 0700, 1) ; if (mysemp == SEM_FAILED) { perror(ERROR_PREFIX "sem_open"); return PTS_UNRESOLVED; } if ((sem_close(mysemp)) == 0) { puts("TEST PASSED"); sem_unlink(semname); return PTS_PASS; } else { puts("TEST FAILED"); return PTS_FAIL; } } posixtestsuite/conformance/interfaces/sem_close/testfrmw.c0100644000000000000000000000407210213060035023267 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * * This file is a wrapper to use the tests from the NPTL Test & Trace Project * with either the Linux Test Project or the Open POSIX Test Suite. * The following function are defined: * void output_init() * void output_fini() * void output(char * string, ...) * * The are used to output informative text (as a printf). */ #include #include /* We use a mutex to avoid conflicts in traces */ static pthread_mutex_t m_trace = PTHREAD_MUTEX_INITIALIZER; /*****************************************************************************************/ /******************************* stdout module *****************************************/ /*****************************************************************************************/ /* The following functions will output to stdout */ #if (1) void output_init() { /* do nothing */ return; } void output( char * string, ... ) { va_list ap; char *ts="[??:??:??]"; struct tm * now; time_t nw; pthread_mutex_lock(&m_trace); nw = time(NULL); now = localtime(&nw); if (now == NULL) printf(ts); else printf("[%2.2d:%2.2d:%2.2d]", now->tm_hour, now->tm_min, now->tm_sec); va_start( ap, string); vprintf(string, ap); va_end(ap); pthread_mutex_unlock(&m_trace); } void output_fini() { /*do nothing */ return; } #endif posixtestsuite/conformance/interfaces/sem_close/3-2.c0100644000000000000000000001124410213060034021713 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertion: * * If sem_unlink has not been called after sem_open for this semaphore, * the function has no effect on the semaphore. * The steps are: * -> open a semaphore with a value of 2. * -> wait the semaphore (now value = 1) * -> close the semaphore. * -> open the semaphore again (with dummy value = 3) * -> check the value is 1. * -> close the semaphore. * -> unlink the semaphore. * The test fails if the semaphore value is not 1 after semaphore is reopened. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /******************************************************************************/ /*************************** standard includes ********************************/ /******************************************************************************/ #include #include #include #include #include #include #include #include #include /******************************************************************************/ /*************************** Test framework *******************************/ /******************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int * (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /******************************************************************************/ /**************************** Configuration ***********************************/ /******************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif #define SEM_NAME "/sem_close_3_2" /******************************************************************************/ /*************************** Test case ***********************************/ /******************************************************************************/ /* The main test function. */ int main( int argc, char * argv[] ) { int ret, value; sem_t * sem; /* Initialize output */ output_init(); /* Create the semaphore */ sem = sem_open( SEM_NAME, O_CREAT | O_EXCL, 0777, 2 ); if ( ( sem == SEM_FAILED ) && ( errno == EEXIST ) ) { sem_unlink( SEM_NAME ); sem = sem_open( SEM_NAME, O_CREAT | O_EXCL, 0777, 2 ); } if ( sem == SEM_FAILED ) { UNRESOLVED( errno, "Failed to create the semaphore" ); } /* Use the semaphore to change its value. */ do { ret = sem_wait( sem ); } while ( ( ret != 0 ) && ( errno == EINTR ) ); if ( ret != 0 ) { UNRESOLVED( errno, "Failed to wait for the semaphore" ); } /* Here, count is 1. Now, close the semaphore */ ret = sem_close( sem ); if ( ret != 0 ) { UNRESOLVED( errno, "Failed to close the semaphore" ); } /* Open the semaphore again */ sem = sem_open( SEM_NAME, O_CREAT, 0777, 3 ); if ( sem == SEM_FAILED ) { UNRESOLVED( errno, "Failed to re-open the semaphore" ); } /* Check current semaphore count */ ret = sem_getvalue( sem, &value ); if ( ret != 0 ) { UNRESOLVED( errno, "Failed to get semaphore value" ); } if ( value != 1 ) { output( "Got value: %d\n", value ); FAILED( "The semaphore count has changed after sem_close" ); } /* Now, we can destroy all */ ret = sem_close( sem ); if ( ret != 0 ) { UNRESOLVED( errno, "Failed to close the semaphore" ); } ret = sem_unlink( SEM_NAME ); if ( ret != 0 ) { UNRESOLVED( errno, "Failed to unlink the semaphore" ); } /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/sem_close/assertions.xml0100644000000000000000000000122610211622273024170 0ustar rootroot sem_close will return zero after successful completion. sem_close will deallocate system resources allocated by sem_open for the same semaphore. sem_close will have no effect on the state of the semaphore if sem_unlink has not been called on this semaphore. Calling sem_close with an invalid semaphore descriptor may result in a sem_close returning -1 and errno being set to EINVAL. posixtestsuite/conformance/interfaces/sem_close/coverage.txt0100644000000000000000000000033507663253372023631 0ustar rootroot assertion 4: TEST WAS REMOVED: based on the Austin Group mailing list traffic "That implemntation is not required to detect invalid parameters". May be some one else could figure out a way to write a test case for it. posixtestsuite/conformance/interfaces/sem_close/testfrmw.h0100644000000000000000000000456410213060035023302 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * * This file is a wrapper to use the tests from the NPTL Test & Trace Project * with either the Linux Test Project or the Open POSIX Test Suite. * The following macros are defined here: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate without calling one of those macros. * * */ #include "posixtest.h" #include /* for the strerror() routine */ #ifdef __GNUC__ /* We are using GCC */ #define UNRESOLVED(x, s) \ { output("Test %s unresolved: got %i (%s) on line %i (%s)\n", __FILE__, x, strerror(x), __LINE__, s); \ output_fini(); \ exit(PTS_UNRESOLVED); } #define FAILED(s) \ { output("Test %s FAILED: %s\n", __FILE__, s); \ output_fini(); \ exit(PTS_FAIL); } #define PASSED \ output_fini(); \ exit(PTS_PASS); #define UNTESTED(s) \ { output("File %s cannot test: %s\n", __FILE__, s); \ output_fini(); \ exit(PTS_UNTESTED); \ } #else /* not using GCC */ #define UNRESOLVED(x, s) \ { output("Test unresolved: got %i (%s) on line %i (%s)\n", x, strerror(x), __LINE__, s); \ output_fini(); \ exit(PTS_UNRESOLVED); } #define FAILED(s) \ { output("Test FAILED: %s\n", s); \ output_fini(); \ exit(PTS_FAIL); } #define PASSED \ output_fini(); \ exit(PTS_PASS); #define UNTESTED(s) \ { output("Unable to test: %s\n", s); \ output_fini(); \ exit(PTS_UNTESTED); \ } #endif posixtestsuite/conformance/interfaces/sem_close/2-1.c0100644000000000000000000000253207631241476021736 0ustar rootroot/* Copyright (c) 2002, Intel Corporation. All rights reserved. Created by: majid.awad REMOVE-THIS AT intel DOT com This file is licensed under the GPL license. For the full content of this license, see the COPYING file at the top level of this source tree. */ /* This case verifies that sem_close deallocate resources, and then the semaphore is available for reuse. */ #include #include #include #include #include #include #include #include "posixtest.h" #define TEST "2-1" #define FUNCTION "sem_close" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " int main() { sem_t *mysemp; char semname[20]; sprintf(semname, "/" FUNCTION "_" TEST "_%d", getpid()); mysemp = sem_open(semname, O_CREAT, 0777, 1); if (mysemp == SEM_FAILED ) { perror(ERROR_PREFIX "sem_open"); return PTS_UNRESOLVED; } /* Deallocate mysemp */ if ((sem_close(mysemp)) == -1) { return PTS_UNRESOLVED; } /* Make mysemp available for reuse */ mysemp = sem_open(semname, O_CREAT, 0777, 1); if (mysemp == SEM_FAILED ) { perror(ERROR_PREFIX "sem_open"); return PTS_UNRESOLVED; } if ((sem_close(mysemp)) == 0) { puts("TEST PASSED"); sem_unlink(semname); return PTS_PASS; } else { puts("TEST FAILED"); return PTS_FAIL; } } posixtestsuite/conformance/interfaces/sem_close/3-1.c0100644000000000000000000000223507631241476021737 0ustar rootroot/* Copyright (c) 2002, Intel Corporation. All rights reserved. Created by: majid.awad REMOVE-THIS AT intel DOT com This file is licensed under the GPL license. For the full content of this license, see the COPYING file at the top level of this source tree. */ /* sem_close will have no effect on the state of the semaphore if sem_unlink has been unsuccessful. */ #include #include #include #include #include #include #include #include "posixtest.h" #define TEST "3-1" #define FUNCTION "sem_close" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " int main() { sem_t *mysemp; char semname[20]; sprintf(semname, "/" FUNCTION "_" TEST "_%d", getpid()); mysemp = sem_open(semname, O_CREAT, 0444, 1) ; if (mysemp == SEM_FAILED) { perror(ERROR_PREFIX "sem_open"); return PTS_UNRESOLVED; } if ((sem_unlink(semname)) == 0) { if ( sem_close(mysemp) == -1) { perror(ERROR_PREFIX "sem_close"); return PTS_UNRESOLVED; } puts("TEST PASSED"); return PTS_PASS; } else { puts("TEST FAILED"); return PTS_FAIL; } } posixtestsuite/conformance/interfaces/pthread_once/0040755000000000000000000000000010515625223021745 5ustar rootrootposixtestsuite/conformance/interfaces/pthread_once/4-1.c0100644000000000000000000000070407617615307022423 0ustar rootroot /* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test pthread_once() *The constant PTHREAD_ONCE_INIT is defined in the pthread.h header. */ #include pthread_once_t dummy = PTHREAD_ONCE_INIT; posixtestsuite/conformance/interfaces/pthread_once/1-3.c0100644000000000000000000001101610172711774022413 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertion: * * Subsequent calls with the same once_control do not call init routine. * The steps are: * -> Create several threads * -> each call pthread_once * -> check the init_routine executed once * The test fails if the init_routine has not been called or has * been called several times. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /********************************************************************************************/ /****************************** standard includes *****************************************/ /********************************************************************************************/ #include #include #include #include #include #include /********************************************************************************************/ /****************************** Test framework *****************************************/ /********************************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /********************************************************************************************/ /********************************** Configuration ******************************************/ /********************************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif #define NTHREADS 30 /********************************************************************************************/ /*********************************** Test case *****************************************/ /********************************************************************************************/ int control; pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER; void my_init( void ) { int ret = 0; ret = pthread_mutex_lock( &mtx ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to lock mutex in initializer" ); } control++; ret = pthread_mutex_unlock( &mtx ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to unlock mutex in initializer" ); } return ; } /* Thread function */ void * threaded ( void * arg ) { int ret; ret = pthread_once( arg, my_init ); if ( ret != 0 ) { UNRESOLVED( ret, "pthread_once failed" ); } return NULL; } /* The main test function. */ int main( int argc, char * argv[] ) { int ret, i; pthread_once_t myctl = PTHREAD_ONCE_INIT; pthread_t th[ NTHREADS ]; /* Initialize output */ output_init(); control = 0; /* Create the children */ for ( i = 0; i < NTHREADS; i++ ) { ret = pthread_create( &th[ i ], NULL, threaded, &myctl ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to create a thread" ); } } /* Then join */ for ( i = 0; i < NTHREADS; i++ ) { ret = pthread_join( th[ i ], NULL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to join a thread" ); } } /* Fetch the memory */ ret = pthread_mutex_lock( &mtx ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to lock mutex in initializer" ); } if ( control != 1 ) { output( "Control: %d\n", control ); FAILED( "The initializer function did not execute once" ); } ret = pthread_mutex_unlock( &mtx ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to unlock mutex in initializer" ); } PASSED; } posixtestsuite/conformance/interfaces/pthread_once/1-1.c0100644000000000000000000000315107620035101022375 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_once() * * Dynamic package installation. Tihe first call to pthread_once() by any * thread in a process, with a given 'once_control', shall call the * 'init_routine' with no arguments. Subsequent calls of pthread_once() * with the same once_control shall not call the 'init_routine'. The * 'once_control' paramter shall determine whether the associated * initialization routine has been called. * * STEPS: * 1.Initialize a pthread_once object * 2.Call pthread_once passing it this object * 3.Call pthread_once again, this time, it shouldn't execute the function * passed to it. If it does, the test fails. */ #include #include #include "posixtest.h" /* Keeps track of how many times the init function has been called. */ int init_flag; /* The init function that pthread_once calls */ void *an_init_func() { init_flag++; return NULL; } int main() { pthread_once_t once_control = PTHREAD_ONCE_INIT; init_flag=0; /* Call pthread_once, passing it the once_control */ pthread_once(&once_control, (void*)an_init_func); /* Call pthread_once again. The init function should not be * called. */ pthread_once(&once_control, (void*)an_init_func); if(init_flag != 1) { printf("Test FAILED\n"); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_once/testfrmw.c0100644000000000000000000000407210172711774023772 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * * This file is a wrapper to use the tests from the NPTL Test & Trace Project * with either the Linux Test Project or the Open POSIX Test Suite. * The following function are defined: * void output_init() * void output_fini() * void output(char * string, ...) * * The are used to output informative text (as a printf). */ #include #include /* We use a mutex to avoid conflicts in traces */ static pthread_mutex_t m_trace = PTHREAD_MUTEX_INITIALIZER; /*****************************************************************************************/ /******************************* stdout module *****************************************/ /*****************************************************************************************/ /* The following functions will output to stdout */ #if (1) void output_init() { /* do nothing */ return; } void output( char * string, ... ) { va_list ap; char *ts="[??:??:??]"; struct tm * now; time_t nw; pthread_mutex_lock(&m_trace); nw = time(NULL); now = localtime(&nw); if (now == NULL) printf(ts); else printf("[%2.2d:%2.2d:%2.2d]", now->tm_hour, now->tm_min, now->tm_sec); va_start( ap, string); vprintf(string, ap); va_end(ap); pthread_mutex_unlock(&m_trace); } void output_fini() { /*do nothing */ return; } #endif posixtestsuite/conformance/interfaces/pthread_once/6-1.c0100644000000000000000000001745410172711774022432 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertion: * * The function does not return EINTR * The steps are: * -> kill a thread which calls pthread_once * -> check that EINTR is never returned */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /********************************************************************************************/ /****************************** standard includes *****************************************/ /********************************************************************************************/ #include #include #include #include #include #include #include #include #include /********************************************************************************************/ /****************************** Test framework *****************************************/ /********************************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /********************************************************************************************/ /********************************** Configuration ******************************************/ /********************************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif #define WITH_SYNCHRO /********************************************************************************************/ /*********************************** Test cases *****************************************/ /********************************************************************************************/ char do_it = 1; unsigned long count_ope = 0; #ifdef WITH_SYNCHRO sem_t semsig1; sem_t semsig2; unsigned long count_sig = 0; #endif sigset_t usersigs; typedef struct { int sig; #ifdef WITH_SYNCHRO sem_t *sem; #endif } thestruct; /* the following function keeps on sending the signal to the process */ void * sendsig ( void * arg ) { thestruct * thearg = ( thestruct * ) arg; int ret; pid_t process; process = getpid(); /* We block the signals SIGUSR1 and SIGUSR2 for this THREAD */ ret = pthread_sigmask( SIG_BLOCK, &usersigs, NULL ); if ( ret != 0 ) { UNRESOLVED( ret, "Unable to block SIGUSR1 and SIGUSR2 in signal thread" ); } while ( do_it ) { #ifdef WITH_SYNCHRO if ( ( ret = sem_wait( thearg->sem ) ) ) { UNRESOLVED( errno, "Sem_wait in sendsig" ); } count_sig++; #endif ret = kill( process, thearg->sig ); if ( ret != 0 ) { UNRESOLVED( errno, "Kill in sendsig" ); } } return NULL; } /* Next are the signal handlers. */ /* This one is registered for signal SIGUSR1 */ void sighdl1( int sig ) { #ifdef WITH_SYNCHRO if ( sem_post( &semsig1 ) ) { UNRESOLVED( errno, "Sem_post in signal handler 1" ); } #endif } /* This one is registered for signal SIGUSR2 */ void sighdl2( int sig ) { #ifdef WITH_SYNCHRO if ( sem_post( &semsig2 ) ) { UNRESOLVED( errno, "Sem_post in signal handler 2" ); } #endif } int init_ctl; /* Init function */ void initializer( void ) { init_ctl++; return ; } /* Test function -- calls pthread_equal() and checks that EINTR is never returned. */ void * test( void * arg ) { int ret = 0; pthread_once_t once_ctl; /* We don't block the signals SIGUSR1 and SIGUSR2 for this THREAD */ ret = pthread_sigmask( SIG_UNBLOCK, &usersigs, NULL ); if ( ret != 0 ) { UNRESOLVED( ret, "Unable to unblock SIGUSR1 and SIGUSR2 in worker thread" ); } while ( do_it ) { count_ope++; once_ctl = PTHREAD_ONCE_INIT; init_ctl = 0; ret = pthread_once( &once_ctl, initializer ); if ( ret == EINTR ) { FAILED( "pthread_once returned EINTR" ); } if ( ret != 0 ) { UNRESOLVED( ret, "pthread_once failed" ); } ret = pthread_once( &once_ctl, initializer ); if ( ret == EINTR ) { FAILED( "pthread_once returned EINTR" ); } if ( ret != 0 ) { UNRESOLVED( ret, "pthread_once failed" ); } if ( init_ctl != 1 ) { output( "init_ctl:%d\n", init_ctl ); FAILED( "The initializer did not execute as expected" ); } } return NULL; } /* Main function */ int main ( int argc, char * argv[] ) { int ret; pthread_t th_work, th_sig1, th_sig2; thestruct arg1, arg2; struct sigaction sa; /* Initialize output routine */ output_init(); /* We need to register the signal handlers for the PROCESS */ sigemptyset ( &sa.sa_mask ); sa.sa_flags = 0; sa.sa_handler = sighdl1; if ( ( ret = sigaction ( SIGUSR1, &sa, NULL ) ) ) { UNRESOLVED( ret, "Unable to register signal handler1" ); } sa.sa_handler = sighdl2; if ( ( ret = sigaction ( SIGUSR2, &sa, NULL ) ) ) { UNRESOLVED( ret, "Unable to register signal handler2" ); } /* We prepare a signal set which includes SIGUSR1 and SIGUSR2 */ sigemptyset( &usersigs ); ret = sigaddset( &usersigs, SIGUSR1 ); ret |= sigaddset( &usersigs, SIGUSR2 ); if ( ret != 0 ) { UNRESOLVED( ret, "Unable to add SIGUSR1 or 2 to a signal set" ); } /* We now block the signals SIGUSR1 and SIGUSR2 for this THREAD */ ret = pthread_sigmask( SIG_BLOCK, &usersigs, NULL ); if ( ret != 0 ) { UNRESOLVED( ret, "Unable to block SIGUSR1 and SIGUSR2 in main thread" ); } #ifdef WITH_SYNCHRO if ( sem_init( &semsig1, 0, 1 ) ) { UNRESOLVED( errno, "Semsig1 init" ); } if ( sem_init( &semsig2, 0, 1 ) ) { UNRESOLVED( errno, "Semsig2 init" ); } #endif if ( ( ret = pthread_create( &th_work, NULL, test, NULL ) ) ) { UNRESOLVED( ret, "Worker thread creation failed" ); } arg1.sig = SIGUSR1; arg2.sig = SIGUSR2; #ifdef WITH_SYNCHRO arg1.sem = &semsig1; arg2.sem = &semsig2; #endif if ( ( ret = pthread_create( &th_sig1, NULL, sendsig, ( void * ) & arg1 ) ) ) { UNRESOLVED( ret, "Signal 1 sender thread creation failed" ); } if ( ( ret = pthread_create( &th_sig2, NULL, sendsig, ( void * ) & arg2 ) ) ) { UNRESOLVED( ret, "Signal 2 sender thread creation failed" ); } /* Let's wait for a while now */ sleep( 1 ); /* Now stop the threads and join them */ do { do_it = 0; } while ( do_it ); if ( ( ret = pthread_join( th_sig1, NULL ) ) ) { UNRESOLVED( ret, "Signal 1 sender thread join failed" ); } if ( ( ret = pthread_join( th_sig2, NULL ) ) ) { UNRESOLVED( ret, "Signal 2 sender thread join failed" ); } if ( ( ret = pthread_join( th_work, NULL ) ) ) { UNRESOLVED( ret, "Worker thread join failed" ); } #if VERBOSE > 0 output( "Test executed successfully.\n" ); output( " %d initializations.\n", count_ope ); #ifdef WITH_SYNCHRO output( " %d signals were sent meanwhile.\n", count_sig ); #endif #endif PASSED; } posixtestsuite/conformance/interfaces/pthread_once/1-2.c0100644000000000000000000000666710172711774022432 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertion: * * In a process, the first call to pthread_once with a given once_control * calls the init routine. * The steps are: * -> call pthread_once * -> check the init_routine executed * The test fails if the init_routine has not been called after pthread_once * has returned. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /********************************************************************************************/ /****************************** standard includes *****************************************/ /********************************************************************************************/ #include #include #include #include #include #include /********************************************************************************************/ /****************************** Test framework *****************************************/ /********************************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /********************************************************************************************/ /********************************** Configuration ******************************************/ /********************************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif /********************************************************************************************/ /*********************************** Test case *****************************************/ /********************************************************************************************/ int control; void my_init( void ) { control = 1; return ; } /* The main test function. */ int main( int argc, char * argv[] ) { int ret; pthread_once_t myctl = PTHREAD_ONCE_INIT; /* Initialize output */ output_init(); control = 0; /* Call the initializer */ ret = pthread_once( &myctl, my_init ); if ( ret != 0 ) { UNRESOLVED( ret, "pthread_once failed" ); } if ( control != 1 ) { FAILED( "The initializer function did not execute" ); } PASSED; } posixtestsuite/conformance/interfaces/pthread_once/assertions.xml0100644000000000000000000000300007622322765024661 0ustar rootroot The function int pthread_once(pthread_once_t *once_control, void (*init_routine) (void)); The first call to pthread_once() by any thread in a process, with a given 'once_control', shall call the 'init_routine' with no arguments. Subsequent calls of pthread_once() with the same once_control shall not call the 'init_routine'. The 'once_control' paramter shall determine whether the associated initialization routine has been called. On return from pthread_once(), 'init_routine' shall have completed. The pthread_once() function is not a cancelation point. But if 'init_routine' is a cancelation point and is canceled, the effect on 'once_control' shall be as if pthread_once() was never called. The constant PTHREAD_ONCE_INIT is defined in the pthread.h header. The behavior of pthread_once() is undefined if 'once_control' has automatic storage duration or is not initialized by PTHREAD_ONCE_INIT. Upon success, it returns a 0; Upon failure, it may return an error number: -[EINVAL] If either 'once_control' or 'init_routine' is invalid It shall not return [EINTR] posixtestsuite/conformance/interfaces/pthread_once/coverage.txt0100644000000000000000000000044607622322765024314 0ustar rootrootThis document defines the coverage for the pthread_once function: Assertion Tested? 1 YES 2 NO 3 YES 4 YES 5 NO 6 NO ** Keeping in mind it 'may' fail and not 'shall' fail, so it will always return PASS, but will return a PASS and print out a warning if it fails. NOTE: posixtestsuite/conformance/interfaces/pthread_once/testfrmw.h0100644000000000000000000000456410172711774024005 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * * This file is a wrapper to use the tests from the NPTL Test & Trace Project * with either the Linux Test Project or the Open POSIX Test Suite. * The following macros are defined here: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate without calling one of those macros. * * */ #include "posixtest.h" #include /* for the strerror() routine */ #ifdef __GNUC__ /* We are using GCC */ #define UNRESOLVED(x, s) \ { output("Test %s unresolved: got %i (%s) on line %i (%s)\n", __FILE__, x, strerror(x), __LINE__, s); \ output_fini(); \ exit(PTS_UNRESOLVED); } #define FAILED(s) \ { output("Test %s FAILED: %s\n", __FILE__, s); \ output_fini(); \ exit(PTS_FAIL); } #define PASSED \ output_fini(); \ exit(PTS_PASS); #define UNTESTED(s) \ { output("File %s cannot test: %s\n", __FILE__, s); \ output_fini(); \ exit(PTS_UNTESTED); \ } #else /* not using GCC */ #define UNRESOLVED(x, s) \ { output("Test unresolved: got %i (%s) on line %i (%s)\n", x, strerror(x), __LINE__, s); \ output_fini(); \ exit(PTS_UNRESOLVED); } #define FAILED(s) \ { output("Test FAILED: %s\n", s); \ output_fini(); \ exit(PTS_FAIL); } #define PASSED \ output_fini(); \ exit(PTS_PASS); #define UNTESTED(s) \ { output("Unable to test: %s\n", s); \ output_fini(); \ exit(PTS_UNTESTED); \ } #endif posixtestsuite/conformance/interfaces/pthread_once/2-1.c0100644000000000000000000000670210172711774022420 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertion: * * pthread_once returns only when init routine has completed. * The steps are: * -> call pthread_once (the init routine lasts for 1 second) * -> check the init_routine executed * The test fails if the init_routine has not been completed when pthread_once * returns. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /********************************************************************************************/ /****************************** standard includes *****************************************/ /********************************************************************************************/ #include #include #include #include #include #include /********************************************************************************************/ /****************************** Test framework *****************************************/ /********************************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /********************************************************************************************/ /********************************** Configuration ******************************************/ /********************************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif /********************************************************************************************/ /*********************************** Test case *****************************************/ /********************************************************************************************/ int control; void my_init( void ) { sleep( 1 ); control = 1; return ; } /* The main test function. */ int main( int argc, char * argv[] ) { int ret; pthread_once_t myctl = PTHREAD_ONCE_INIT; /* Initialize output */ output_init(); control = 0; /* Call the initializer */ ret = pthread_once( &myctl, my_init ); if ( ret != 0 ) { UNRESOLVED( ret, "pthread_once failed" ); } if ( control != 1 ) { FAILED( "The initializer function did not execute" ); } PASSED; } posixtestsuite/conformance/interfaces/pthread_once/3-1.c0100644000000000000000000000611307621017306022410 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * * Test pthread_once() * * The pthread_once() function is not a cancelation point. However if * 'init_routine'is a cancelation point and is canceled, the effect on * 'once_control' shall be as if pthread_once() was never called. * * STEPS: * 1. Create a cancelable thread. * 2. In the thread routine, call pthread_once using a global pthread_once_t * object. * 3. Cancel the thread during the pthread_once init function * 4. Call pthread_once again with the same pthread once_t object * 5. This should call the pthread_once init function. If not, the test fails. */ #include #include #include #include "posixtest.h" /* Global pthread_once_t object */ pthread_once_t once_control; /* Keeps track of how many times the init function has been called. */ int init_flag; /* The init function that pthread_once calls */ void *an_init_func() { /* Indicate to main() that the init function has been reached */ init_flag=1; /* Stay in a continuous loop until the thread that called * this function gets canceled */ sleep(10); /* The thread could not be canceled, timeout after 10 secs */ perror("Init function timed out (10 secs), thread could not be canceled\n"); init_flag=-1; return NULL; } /* Thread function */ void *a_thread_func() { /* Make the thread cancelable immediately */ pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL); pthread_once(&once_control, (void*)an_init_func); return NULL; } /* 2nd init function used by the 2nd call of pthread_once */ void *an_init_func2() { /* Indicate to main() that this init function has been reached */ init_flag=1; return NULL; } int main() { pthread_t new_th; once_control = PTHREAD_ONCE_INIT; init_flag=0; /* Create a thread that will execute the first call to pthread_once() */ if(pthread_create(&new_th, NULL, a_thread_func, NULL) != 0) { perror("Error creating thread\n"); return PTS_UNRESOLVED; } /* Wait until the init function is reached to cancel the thread */ while(init_flag==0) sleep(1); /* Send cancel request to the thread*/ if(pthread_cancel(new_th) != 0) { perror("Could send cancel request to thread\n"); return PTS_UNRESOLVED; } /* Wait until the thread is canceled */ pthread_join(new_th, NULL); /* If the thread could not be canceled and timed out, send * an error */ if (init_flag == -1) { perror("Error: could not cancel thread\n"); return PTS_UNRESOLVED; } init_flag=0; /* Should be able to call pthread_once() again with the same * pthread_once_t object. */ pthread_once(&once_control, (void*)an_init_func2); /* If the init function from the 2nd call to pthread_once() was not * reached, the test fails. */ if(init_flag != 1) { printf("Test FAILED\n: %d", init_flag); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/sem_unlink/0040755000000000000000000000000010515625236021462 5ustar rootrootposixtestsuite/conformance/interfaces/sem_unlink/cln.sh0100755000000000000000000000025607616075644022607 0ustar rootroot rm -f /tmp/mysem >/dev/null 2>&1 rm -f /tmp/sem_* >/dev/null 2>&1 rm -f a.out for sem_id in `ipcs -s | awk '{print $2}'` ; do ipcrm sem $sem_id > /dev/null 2>&1 done posixtestsuite/conformance/interfaces/sem_unlink/2-2.c0100644000000000000000000001437610336125321022125 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertion: * * Destruction of the semaphore is postponed until all processes which were using * the semaphore have called sem_close, _exit or exec. * The steps are: * -> Create a named semaphore with value = 0. * -> create 3 processes. Each call sem_wait, then sem_post, then sem_close/_exit/exec * -> the main process unlinks the semaphore, the posts it and close it. * -> Check all child processes have returned successfully. * The test fails if a semaphore operation returns an error in one of the children. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /******************************************************************************/ /*************************** standard includes ********************************/ /******************************************************************************/ #include #include #include #include #include #include #include #include #include #include /******************************************************************************/ /*************************** Test framework *******************************/ /******************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int * (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /******************************************************************************/ /**************************** Configuration ***********************************/ /******************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif #define SEM_NAME "/sem_unlink_9_1" /******************************************************************************/ /*************************** Test case ***********************************/ /******************************************************************************/ /* Operations common to all processes on the semaphore*/ sem_t * common() { int ret; sem_t * sem; /* Reconnect to the semaphore */ sem = sem_open( SEM_NAME, 0 ); if ( sem == SEM_FAILED ) { UNRESOLVED( errno, "Failed to reconnect the semaphore" ); } /* block until the semaphore is posted */ do { ret = sem_wait( sem ); } while ( ( ret != 0 ) && ( errno == EINTR ) ); if ( ret != 0 ) { FAILED( "Waiting for the semaphore failed" ); } /* spend some time... */ sched_yield(); sched_yield(); sched_yield(); /* Post the semaphore back */ ret = sem_post( sem ); if ( ret != 0 ) { FAILED( "Failed to post the semaphore" ); } return sem; } /* The main test function. */ int main( int argc, char * argv[] ) { int ret, status; pid_t p1, p2, p3, ctl; sem_t * sem; /* Initialize output */ output_init(); /* Create the semaphore */ sem = sem_open( SEM_NAME, O_CREAT | O_EXCL, 0777, 0 ); if ( ( sem == SEM_FAILED ) && ( errno == EEXIST ) ) { sem_unlink( SEM_NAME ); sem = sem_open( SEM_NAME, O_CREAT | O_EXCL, 0777, 0 ); } if ( sem == SEM_FAILED ) { UNRESOLVED( errno, "Failed to create the semaphore" ); } /* fork 3 times */ p1 = fork(); if ( p1 == ( pid_t ) - 1 ) { UNRESOLVED( errno, "Failed to fork" ); } if ( p1 == ( pid_t ) 0 ) /* child */ { sem = common(); ret = sem_close( sem ); if ( ret != 0 ) { FAILED( "Failed to sem_close in child" ); } exit( 0 ); } p2 = fork(); if ( p2 == ( pid_t ) - 1 ) { UNRESOLVED( errno, "Failed to fork" ); } if ( p2 == ( pid_t ) 0 ) /* child */ { sem = common(); _exit( 0 ); } p3 = fork(); if ( p3 == ( pid_t ) - 1 ) { UNRESOLVED( errno, "Failed to fork" ); } if ( p3 == ( pid_t ) 0 ) /* child */ { sem = common(); ret = execl( "/bin/ls", "ls", NULL ); UNRESOLVED( errno, "Failed to exec" ); } /* Let all processes start and wait for the semaphore */ sleep( 1 ); /* Unlink */ ret = sem_unlink( SEM_NAME ); if ( ret != 0 ) { UNRESOLVED( errno, "Failed to unlink the semaphore" ); } /* Post the semaphore */ ret = sem_post( sem ); if ( ret != 0 ) { UNRESOLVED( errno, "Failed to post the semaphore" ); } /* and close it in this process */ ret = sem_close( sem ); if ( ret != 0 ) { UNRESOLVED( errno, "Failed to close the semaphore" ); } /* Wait all processes */ ctl = waitpid( p1, &status, 0 ); if ( ctl != p1 ) { UNRESOLVED( errno, "Waitpid returned the wrong PID" ); } if ( ( !WIFEXITED( status ) ) || ( WEXITSTATUS( status ) != 0 ) ) { FAILED( "Child 'sem_close' exited abnormally" ); } ctl = waitpid( p2, &status, 0 ); if ( ctl != p2 ) { UNRESOLVED( errno, "Waitpid returned the wrong PID" ); } if ( ( !WIFEXITED( status ) ) || ( WEXITSTATUS( status ) != 0 ) ) { FAILED( "Child '_exit' exited abnormally" ); } ctl = waitpid( p3, &status, 0 ); if ( ctl != p3 ) { UNRESOLVED( errno, "Waitpid returned the wrong PID" ); } if ( ( !WIFEXITED( status ) ) || ( WEXITSTATUS( status ) != 0 ) ) { FAILED( "Child 'exec' exited abnormally" ); } /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/sem_unlink/5-1.c0100644000000000000000000001320010213570235022112 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertion: * * sem_unlink will return -1 and set errno to ENAMETOOLONG when the semaphore * name length is greater than PATH_MAX or a component length is greater than * NAME_MAX. * The steps are: * -> If PATH_MAX is positive, * -> create a semaphore with a name bigger than PATH_MAX. * -> if the creation succeeds, try to unlink. It should fail. * -> If NAME_MAX is positive, do similar test. * The test fails if the ENAMETOOLONG is not returned. * It also FAILS if this error is returned, as it means we can create a semaphore * which cannot be removed. * So actually, if the creation succeeds, the test fails :)) */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /******************************************************************************/ /*************************** standard includes ********************************/ /******************************************************************************/ #include #include #include #include #include #include #include #include #include /******************************************************************************/ /*************************** Test framework *******************************/ /******************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int * (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /******************************************************************************/ /**************************** Configuration ***********************************/ /******************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif #define SEM_NAME "/sem_unlink_5_1" /******************************************************************************/ /*************************** Test case ***********************************/ /******************************************************************************/ /* The main test function. */ int main( int argc, char * argv[] ) { int ret, error; sem_t * sem; long PATH_MAX, NAME_MAX; char * sem_name; /* Initialize output */ output_init(); /* Get PATH_MAX value */ PATH_MAX = pathconf( "/", _PC_PATH_MAX ); #if VERBOSE > 0 output( "PATH_MAX: %ld\n", PATH_MAX ); #endif if ( PATH_MAX > 0 ) { /* create a semaphore with a name longer than PATH_MAX */ sem_name = calloc( PATH_MAX + 1, sizeof( char ) ); if ( sem_name == NULL ) { UNRESOLVED( errno, "Failed to allocate space for the semaphore name" ); } /* the space was allocated */ sem_name[ 0 ] = '/'; sem_name[ PATH_MAX ] = '\0'; memset( sem_name + 1, 'P', PATH_MAX - 1 ); /* Create the semaphore */ sem = sem_open( sem_name, O_CREAT, 0777, 1 ); if ( sem != SEM_FAILED ) { ret = sem_unlink( sem_name ); error = errno; free( sem_name ); if ( ret == 0 ) { FAILED( "The function did not return ENAMETOOLONG as expected" ); } else { output( "Error was %d: %s\n", error, strerror( error ) ); FAILED( "Unable to unlink a semaphore which we just created" ); } } #if VERBOSE > 0 else { output( "Creation of the semaphore failed with error %d: %s\n", errno, strerror( errno ) ); } #endif } /* Get NAME_MAX value */ NAME_MAX = pathconf( "/", _PC_NAME_MAX ); #if VERBOSE > 0 output( "NAME_MAX: %ld\n", NAME_MAX ); #endif if ( NAME_MAX > 0 ) { /* create a semaphore with a name longer than NAME_MAX */ sem_name = calloc( NAME_MAX + 2, sizeof( char ) ); if ( sem_name == NULL ) { UNRESOLVED( errno, "Failed to allocate space for the semaphore name" ); } /* the space was allocated */ sem_name[ 0 ] = '/'; sem_name[ NAME_MAX + 1 ] = '\0'; memset( sem_name + 1, 'N', NAME_MAX ); /* Create the semaphore */ sem = sem_open( sem_name, O_CREAT , 0777, 1 ); if ( sem != SEM_FAILED ) { ret = sem_unlink( sem_name ); error = errno; free( sem_name ); if ( ret == 0 ) { FAILED( "The function did not return ENAMETOOLONG as expected" ); } else { output( "Error was %d: %s\n", error, strerror( error ) ); FAILED( "Unable to unlink a semaphore which we just created" ); } } #if VERBOSE > 0 else { output( "Creation of the semaphore failed with error %d: %s\n", errno, strerror( errno ) ); } #endif } /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/sem_unlink/4-1.c0100644000000000000000000000152107636705224022131 0ustar rootroot/* Copyright (c) 2003, Intel Corporation. All rights reserved. Created by: majid.awad REMOVE-THIS AT intel DOT com This file is licensed under the GPL license. For the full content of this license, see the COPYING file at the top level of this source tree. */ /* * Trying to unlink a semaphore which it doesn't exist. It give an ERROR: * ENOENT. */ #include #include #include #include #include #include #include "posixtest.h" #define TEST "4-1" #define FUNCTION "sem_unlink" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " int main() { char semname[20]; sem_unlink(semname); if (errno == ENOENT) { puts("TEST PASSED"); return PTS_PASS; } else { puts("TEST FAILED: semaphore does exist"); return PTS_FAIL; } } posixtestsuite/conformance/interfaces/sem_unlink/1-1.c0100644000000000000000000000217007636705224022127 0ustar rootroot/* Copyright (c) 2003, Intel Corporation. All rights reserved. Created by: majid.awad REMOVE-THIS AT intel DOT com This file is licensed under the GPL license. For the full content of this license, see the COPYING file at the top level of this source tree. */ /* * sem_wait shall lock the unlocked semaphore and decrement the semaphore * value by one. */ #include #include #include #include #include #include #include "posixtest.h" #define TEST "1-1" #define FUNCTION "sem_unlink" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " int main() { sem_t *mysemp; char semname[20]; sprintf(semname, "/" FUNCTION "_" TEST "_%d", getpid()); /* Initial value of Semaphore is 1 */ mysemp = sem_open(semname, O_CREAT,0,1); if( mysemp == SEM_FAILED || mysemp == NULL ) { perror(ERROR_PREFIX "sem_open"); return PTS_UNRESOLVED; } if ( sem_unlink(semname) == -1) { puts("TEST FAILED: Couldn't remove the named semaphore"); return PTS_FAIL; } else { puts("TEST PASSED"); sem_close(mysemp); return PTS_PASS; } } posixtestsuite/conformance/interfaces/sem_unlink/9-1.c0100644000000000000000000001143610213570235022127 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertion: * * When the semaphore is referenced by other processes, the function has * no effect on the state of the semaphore. * The steps are: * -> Create a named semaphore * -> create a thread which waits on the semaphore * -> unlink the semaphore * -> check the thread did not return * -> post the semaphore * -> check the thread returned * -> close the semaphore * The test fails if the semaphore state is changed by sem_unlink. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /******************************************************************************/ /*************************** standard includes ********************************/ /******************************************************************************/ #include #include #include #include #include #include #include #include #include /******************************************************************************/ /*************************** Test framework *******************************/ /******************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int * (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /******************************************************************************/ /**************************** Configuration ***********************************/ /******************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif #define SEM_NAME "/sem_unlink_9_1" /******************************************************************************/ /*************************** Test case ***********************************/ /******************************************************************************/ int thread_state = 0; void * threaded ( void * arg ) { int ret; thread_state = 1; do { ret = sem_wait( arg ); } while ( ( ret != 0 ) && ( errno == EINTR ) ); if ( ret != 0 ) { UNRESOLVED( errno, "Failed to wait for the semaphore" ); } thread_state = 2; return NULL; } /* The main test function. */ int main( int argc, char * argv[] ) { int ret; pthread_t child; sem_t * sem; /* Initialize output */ output_init(); /* Create the semaphore */ sem = sem_open( SEM_NAME, O_CREAT | O_EXCL, 0777, 0 ); if ( ( sem == SEM_FAILED ) && ( errno == EEXIST ) ) { sem_unlink( SEM_NAME ); sem = sem_open( SEM_NAME, O_CREAT | O_EXCL, 0777, 0 ); } if ( sem == SEM_FAILED ) { UNRESOLVED( errno, "Failed to create the semaphore" ); } /* Create the child */ ret = pthread_create( &child, NULL, threaded, sem ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to create the thread" ); } /* Wait for the child to be waiting. */ while ( thread_state != 1 ) { sched_yield(); } /* Unlink */ ret = sem_unlink( SEM_NAME ); if ( ret != 0 ) { UNRESOLVED( errno, "Failed to unlink the semaphore" ); } /* Check the semaphore state did not change. */ sleep( 1 ); if ( thread_state != 1 ) { FAILED( "sem_unlink made sem_wait thread return" ); } /* Post the semaphore */ ret = sem_post( sem ); if ( ret != 0 ) { UNRESOLVED( errno, "Failed to post the semaphore" ); } /* Join the thread */ ret = pthread_join( child, NULL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to join the thread" ); } /* Now, we can destroy all */ ret = sem_close( sem ); if ( ret != 0 ) { UNRESOLVED( errno, "Failed to close the semaphore" ); } /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/sem_unlink/testfrmw.c0100644000000000000000000000407210213570235023472 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * * This file is a wrapper to use the tests from the NPTL Test & Trace Project * with either the Linux Test Project or the Open POSIX Test Suite. * The following function are defined: * void output_init() * void output_fini() * void output(char * string, ...) * * The are used to output informative text (as a printf). */ #include #include /* We use a mutex to avoid conflicts in traces */ static pthread_mutex_t m_trace = PTHREAD_MUTEX_INITIALIZER; /*****************************************************************************************/ /******************************* stdout module *****************************************/ /*****************************************************************************************/ /* The following functions will output to stdout */ #if (1) void output_init() { /* do nothing */ return; } void output( char * string, ... ) { va_list ap; char *ts="[??:??:??]"; struct tm * now; time_t nw; pthread_mutex_lock(&m_trace); nw = time(NULL); now = localtime(&nw); if (now == NULL) printf(ts); else printf("[%2.2d:%2.2d:%2.2d]", now->tm_hour, now->tm_min, now->tm_sec); va_start( ap, string); vprintf(string, ap); va_end(ap); pthread_mutex_unlock(&m_trace); } void output_fini() { /*do nothing */ return; } #endif posixtestsuite/conformance/interfaces/sem_unlink/6-1.c0100644000000000000000000001166110213570235022124 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertion: * * A call to sem_open with the same name refers to a new semaphore, once * sem_unlink has been called. * The steps are: * -> open a semaphore * -> unlink * -> try to reconnect (should fail) * -> open with O_CREATE * -> check the semaphore are different */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /******************************************************************************/ /*************************** standard includes ********************************/ /******************************************************************************/ #include #include #include #include #include #include #include #include #include /******************************************************************************/ /*************************** Test framework *******************************/ /******************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int * (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /******************************************************************************/ /**************************** Configuration ***********************************/ /******************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif #define SEM_NAME "/sem_unlink_6_1" /******************************************************************************/ /*************************** Test case ***********************************/ /******************************************************************************/ /* The main test function. */ int main( int argc, char * argv[] ) { int ret, value; sem_t * sem1, * sem2; /* Initialize output */ output_init(); /* Create the semaphore */ sem1 = sem_open( SEM_NAME, O_CREAT | O_EXCL, 0777, 1 ); if ( ( sem1 == SEM_FAILED ) && ( errno == EEXIST ) ) { sem_unlink( SEM_NAME ); sem1 = sem_open( SEM_NAME, O_CREAT | O_EXCL, 0777, 1 ); } if ( sem1 == SEM_FAILED ) { UNRESOLVED( errno, "Failed to create the semaphore" ); } /* Unlink */ ret = sem_unlink( SEM_NAME ); if ( ret != 0 ) { UNRESOLVED( errno, "Failed to unlink the semaphore" ); } /* Try reconnect */ sem2 = sem_open( SEM_NAME, 0 ); if ( sem2 != SEM_FAILED ) { FAILED( "Reconnecting the unlinked semaphore did not failed" ); } if ( errno != ENOENT ) { output( "Error %d: %s\n", errno, strerror( errno ) ); FAILED( "Reconnecting the unlinked semaphore failed with a wrong error" ); } /* Reopen the semaphore */ sem2 = sem_open( SEM_NAME, O_CREAT | O_EXCL, 0777, 3 ); if ( sem2 == SEM_FAILED ) { output( "Gor error %d: %s\n", errno, strerror( errno ) ); FAILED( "Failed to recreate the semaphore" ); } /* Check the semaphore have different values */ ret = sem_getvalue( sem1, &value ); if ( ret != 0 ) { UNRESOLVED( errno, "Failed to read sem1 value" ); } if ( value != 1 ) { output( "Read: %d\n", value ); FAILED( "Semaphore value is not as expected" ); } ret = sem_getvalue( sem2, &value ); if ( ret != 0 ) { UNRESOLVED( errno, "Failed to read sem1 value" ); } if ( value != 3 ) { output( "Read: %d\n", value ); FAILED( "Semaphore value is not as expected" ); } /* Unlink */ ret = sem_unlink( SEM_NAME ); if ( ret != 0 ) { UNRESOLVED( errno, "Failed to unlink the semaphore" ); } /* close both */ ret = sem_close( sem1 ); if ( ret != 0 ) { UNRESOLVED( errno, "Failed to close the semaphore" ); } ret = sem_close( sem2 ); if ( ret != 0 ) { UNRESOLVED( errno, "Failed to close the semaphore" ); } /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/sem_unlink/7-1.c0100644000000000000000000001051010213570235022115 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertion: * * sem_unlink does not block. * The steps are: * -> open a semaphore * -> create a thread which blocks on the semaphore * -> call sem_unlink * -> clean up * The test fails when it hangs on sem_unlink. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /******************************************************************************/ /*************************** standard includes ********************************/ /******************************************************************************/ #include #include #include #include #include #include #include #include #include /******************************************************************************/ /*************************** Test framework *******************************/ /******************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int * (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /******************************************************************************/ /**************************** Configuration ***********************************/ /******************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif #define SEM_NAME "/sem_unlink_7_1" /******************************************************************************/ /*************************** Test case ***********************************/ /******************************************************************************/ void * threaded ( void * arg ) { int ret = 0; do { ret = sem_wait( arg ); } while ( ( ret != 0 ) && ( errno == EINTR ) ); if ( ret != 0 ) { UNRESOLVED( errno, "Failed to wait for the semaphore" ); } return NULL; } /* The main test function. */ int main( int argc, char * argv[] ) { int ret; pthread_t thread; sem_t * sem; /* Initialize output */ output_init(); /* Create the semaphore */ sem = sem_open( SEM_NAME, O_CREAT | O_EXCL, 0777, 1 ); if ( ( sem == SEM_FAILED ) && ( errno == EEXIST ) ) { sem_unlink( SEM_NAME ); sem = sem_open( SEM_NAME, O_CREAT | O_EXCL, 0777, 1 ); } if ( sem == SEM_FAILED ) { UNRESOLVED( errno, "Failed to create the semaphore" ); } /* Create the child thread */ ret = pthread_create( &thread, NULL, threaded, sem ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to create the thread" ); } /* Let some time for the thread to block */ sleep( 1 ); /* Unlink */ ret = sem_unlink( SEM_NAME ); if ( ret != 0 ) { UNRESOLVED( errno, "Failed to unlink the semaphore" ); } /* Now, we're success */ ret = sem_post( sem ); if ( ret != 0 ) { UNRESOLVED( errno, "Failed to post the semaphore" ); } /* Join the thread */ ret = pthread_join( thread, NULL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to join the thread" ); } /* close */ ret = sem_close( sem ); if ( ret != 0 ) { UNRESOLVED( errno, "Failed to close the semaphore" ); } /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/sem_unlink/assertions.xml0100644000000000000000000000270010213570235024363 0ustar rootroot sem_unlink shall remove the created named semaphore and return zero on success. Destruction of the semaphore is postponed until all process which were using the semaphore have called sem_close, _exit or exec. The function returns -1 and sets errno to EACCESS when the process has insufficient priviledge to unlink the semaphore. ERROR: ENOENT: Trying to unlink a named semaphore which doesn't exist. ERROR: ENAMETOOLONG: The semaphore name length is greater than PATH_MAX or a patch component length is greater than NAME_MAX. Calls to sem_open to recreate/reconnect the semaphore actually refer to a new semaphore after sem_unlink has been called. Calls to sem_unlink are not blocking. Calls to sem_unlink should return 0 on success and -1 on failure. When the semaphore is referenced by other processes, the function has no effect on the state of the semaphore. posixtestsuite/conformance/interfaces/sem_unlink/coverage.txt0100644000000000000000000000025707663254757024037 0ustar rootroot -- assertion 3: not tested. -- assertion 5: not tested. -- assertion 6: Not tested. -- assertion 7: Not tested. -- assertion 8: is being tested in the sem_unlink test cases. posixtestsuite/conformance/interfaces/sem_unlink/testfrmw.h0100644000000000000000000000456410213570235023505 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * * This file is a wrapper to use the tests from the NPTL Test & Trace Project * with either the Linux Test Project or the Open POSIX Test Suite. * The following macros are defined here: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate without calling one of those macros. * * */ #include "posixtest.h" #include /* for the strerror() routine */ #ifdef __GNUC__ /* We are using GCC */ #define UNRESOLVED(x, s) \ { output("Test %s unresolved: got %i (%s) on line %i (%s)\n", __FILE__, x, strerror(x), __LINE__, s); \ output_fini(); \ exit(PTS_UNRESOLVED); } #define FAILED(s) \ { output("Test %s FAILED: %s\n", __FILE__, s); \ output_fini(); \ exit(PTS_FAIL); } #define PASSED \ output_fini(); \ exit(PTS_PASS); #define UNTESTED(s) \ { output("File %s cannot test: %s\n", __FILE__, s); \ output_fini(); \ exit(PTS_UNTESTED); \ } #else /* not using GCC */ #define UNRESOLVED(x, s) \ { output("Test unresolved: got %i (%s) on line %i (%s)\n", x, strerror(x), __LINE__, s); \ output_fini(); \ exit(PTS_UNRESOLVED); } #define FAILED(s) \ { output("Test FAILED: %s\n", s); \ output_fini(); \ exit(PTS_FAIL); } #define PASSED \ output_fini(); \ exit(PTS_PASS); #define UNTESTED(s) \ { output("Unable to test: %s\n", s); \ output_fini(); \ exit(PTS_UNTESTED); \ } #endif posixtestsuite/conformance/interfaces/sem_unlink/4-2.c0100644000000000000000000000660110213570235022121 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertion: * * sem_unlink will return -1 and set errno to ENOENT when the named semaphore * does not exist. * The steps are: * -> Unlink once to make sure this name does not exist. Ignore the error. * -> Unlink again and check that ENOENT is returned * The test fails if the error is not ENOENT, or there is no error. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /******************************************************************************/ /*************************** standard includes ********************************/ /******************************************************************************/ #include #include #include #include #include #include #include #include /******************************************************************************/ /*************************** Test framework *******************************/ /******************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int * (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /******************************************************************************/ /**************************** Configuration ***********************************/ /******************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif #define SEM_NAME "/sem_unlink_4_2" /******************************************************************************/ /*************************** Test case ***********************************/ /******************************************************************************/ /* The main test function. */ int main( int argc, char * argv[] ) { int ret; /* Initialize output */ output_init(); ( void ) sem_unlink( SEM_NAME ); ret = sem_unlink( SEM_NAME ); if ( ret != -1 ) { FAILED( "sem_unlink did not return -1" ); } if ( errno != ENOENT ) { output( "Error %d: %s\n", errno, strerror( errno ) ); FAILED( "The error was not ENOENT" ); } /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/sem_unlink/2-1.c0100644000000000000000000000232707636705224022134 0ustar rootroot/* Copyright (c) 2003, Intel Corporation. All rights reserved. Created by: majid.awad REMOVE-THIS AT intel DOT com This file is licensed under the GPL license. For the full content of this license, see the COPYING file at the top level of this source tree. */ /* * this test case verifies that the named semaphore has been removed after * calling sem_unlink. */ #include #include #include #include #include #include #include "posixtest.h" #define TEST "2-1" #define FUNCTION "sem_unlink" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " int main() { sem_t *mysemp; char semname[20]; sprintf(semname, "/" FUNCTION "_" TEST "_%d", getpid()); /* Initial value of Semaphore is 1 */ mysemp = sem_open(semname, O_CREAT,0,1); if( mysemp == SEM_FAILED || mysemp == NULL ) { perror(ERROR_PREFIX "sem_open"); return PTS_UNRESOLVED; } if ( sem_unlink(semname) == 0 ) { if ((sem_wait (mysemp)) == -1) { puts("TEST FAILED: Couldn't remove named semaphore"); return PTS_FAIL; } else { puts("TEST PASSED"); sem_close(mysemp); return PTS_PASS; } } puts("TEST FAILED"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sem_unlink/3-1.c0100644000000000000000000001345310213570235022122 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertion: * * sem_unlink will return -1 and set errno to EACCESS if the process has not * priviledge to unlink the sem. * The steps are: * -> open a semaphore with 0744 mask * -> fork * -> change child uid * -> child attempts to unlink the semaphore. It should fail. * -> join the child * -> sem_unlink (should be OK) * The test fails if the child process is able to unlink the semaphore. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /* Some of the routines are XSI extensions */ #define _XOPEN_SOURCE 600 /******************************************************************************/ /*************************** standard includes ********************************/ /******************************************************************************/ #include #include #include #include #include #include #include #include #include #include #include /******************************************************************************/ /*************************** Test framework *******************************/ /******************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int * (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /******************************************************************************/ /**************************** Configuration ***********************************/ /******************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif #define SEM_NAME "/sem_unlink_3_1" /******************************************************************************/ /*************************** Test case ***********************************/ /******************************************************************************/ /* Set the euid of this process to a non-root uid */ /* (from ../sem_open/3-1.c) */ int set_nonroot() { struct passwd * pw; setpwent(); /* search for the first user which is non root */ while ( ( pw = getpwent() ) != NULL ) if ( strcmp( pw->pw_name, "root" ) ) break; endpwent(); if ( pw == NULL ) { output( "There is no other user than current and root.\n" ); return 1; } if ( seteuid( pw->pw_uid ) != 0 ) { if ( errno == EPERM ) { output( "You don't have permission to change your UID.\n" ); return 1; } perror( "An error occurs when calling seteuid()" ); return 1; } output( "Testing with user '%s' (uid: %d)\n", pw->pw_name, ( int ) geteuid() ); return 0; } /* The main test function. */ int main( int argc, char * argv[] ) { int ret, status; pid_t ch, ctl; sem_t * sem; /* Initialize output */ output_init(); /* Create the semaphore */ sem = sem_open( SEM_NAME, O_CREAT | O_EXCL, 0744, 1 ); if ( ( sem == SEM_FAILED ) && ( errno == EEXIST ) ) { sem_unlink( SEM_NAME ); sem = sem_open( SEM_NAME, O_CREAT | O_EXCL, 0744, 1 ); } if ( sem == SEM_FAILED ) { UNRESOLVED( errno, "Failed to create the semaphore" ); } /* fork */ ch = fork(); if ( ch == ( pid_t ) - 1 ) { UNRESOLVED( errno, "Failed to fork" ); } if ( ch == ( pid_t ) 0 ) /* child */ { /* connect to the semaphore */ sem = sem_open( SEM_NAME, 0 ); if ( sem == SEM_FAILED ) { output( "Failed to connect to the semaphore, error %d: %s\n", errno, strerror( errno ) ); exit( 1 ); } /* change euid */ ret = set_nonroot(); if ( ret ) { output( "Changing euid failed\n" ); exit ( 1 ); } /* try and unlink, it should fail */ ret = sem_unlink( SEM_NAME ); if ( ret == 0 ) { output( "sem_unlink did not fail in child" ); exit( 2 ); } if ( errno != EACCES ) { output( "sem_unlink failed with unexpected error %d: %s\n", errno, strerror( errno ) ); exit( 2 ); } /* Ok, child is done. */ exit( 0 ); } /* Parent waits for the child to finish */ ctl = waitpid( ch, &status, 0 ); if ( ctl != ch ) { UNRESOLVED( errno, "Waitpid returned the wrong PID" ); } if ( !WIFEXITED( status ) ) { FAILED( "Child exited abnormally" ); } if ( WEXITSTATUS( status ) == 1 ) { UNRESOLVED( 0, "An error occured in child" ); } if ( WEXITSTATUS( status ) == 2 ) { FAILED( "Test failed in child" ); } if ( WEXITSTATUS( status ) != 0 ) { UNRESOLVED( 0, "Unexpected return value from child" ); } /* Unlink */ ret = sem_unlink( SEM_NAME ); if ( ret != 0 ) { UNRESOLVED( errno, "Failed to unlink the semaphore" ); } /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/pthread_rwlock_wrlock/0040755000000000000000000000000010515625225023705 5ustar rootrootposixtestsuite/conformance/interfaces/pthread_rwlock_wrlock/1-1.c0100644000000000000000000001221707671436352024361 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test pthread_rwlock_wrlock(pthread_rwlock_t *rwlock) * * The function shall apply a write lock to the read-write lock referenced by * 'rwlock'. The calling thread acquires the write lock if no other thread * (reader or writer) holds the read-write lock 'rwlock'. Otherwise, the thread * shall block until it can acquire the lock. * * Steps: * 1. Initialize a pthread_rwlock_t object 'rwlock' with pthread_rwlock_init() * 2. Main thread lock 'rwlock' for reading with pthread_rwlock_rdlock() * 3. Create a child thread, the thread lock 'rwlock' for writing, shall block * 4. Main thread unlock 'rwlock', child thread should get the write lock * 5. Main thread lock 'rwlock' for writing * 6. Create child thread to lock 'rwlock' for writing, should block * 7. Main thread unlock 'rwlock' * 8. Child got the lock */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include "posixtest.h" static pthread_rwlock_t rwlock; static int thread_state; /* thread_state indicates child thread state: 1: not in child thread yet; 2: just enter child thread ; 3: just before child thread exit; */ #define NOT_CREATED_THREAD 1 #define ENTERED_THREAD 2 #define EXITING_THREAD 3 static void* fn_wr(void *arg) { thread_state = ENTERED_THREAD; int rc; printf("thread: attempt write lock\n"); rc = pthread_rwlock_wrlock(&rwlock); if(rc == 0) { printf("thread: acquired write lock\n"); printf("thread: unlock write lock\n"); if(pthread_rwlock_unlock(&rwlock) != 0) { printf("thread1: Error at pthread_rwlock_unlock()\n"); exit(PTS_UNRESOLVED); } } else { printf("Test FAILED: Error in pthread_rwlock_wrlock(), error code: %d\n", rc); exit(PTS_FAIL); } thread_state = EXITING_THREAD; pthread_exit(0); return NULL; } int main() { int cnt = 0; pthread_t thread1, thread2; if(pthread_rwlock_init(&rwlock, NULL) != 0) { printf("Error at pthread_rwlock_init()\n"); return PTS_UNRESOLVED; } printf("main: attempt read lock\n"); /* We have no lock, this read lock should succeed */ if(pthread_rwlock_rdlock(&rwlock) != 0) { printf("Error at pthread_rwlock_rdlock()\n"); return PTS_UNRESOLVED; } printf("main: acquired read lock\n"); thread_state = NOT_CREATED_THREAD; printf("main: create thread1\n"); if(pthread_create(&thread1, NULL, fn_wr, NULL) != 0) { printf("Error creating thread1\n"); return PTS_UNRESOLVED; } /* If the shared data is not altered by child after 3 seconds, we regard it as blocked */ cnt = 0; do{ sleep(1); }while (thread_state !=EXITING_THREAD && cnt++ < 3); if(thread_state == EXITING_THREAD) { /* the child thread did not block */ printf("Test FAILED: The thread1 did not block\n"); exit(PTS_FAIL); } else if(thread_state != ENTERED_THREAD) { /* for some reason the child thread did not start*/ printf("Child thread in unexpected state\n"); exit(PTS_UNRESOLVED); } printf("main: unlock read lock\n"); if(pthread_rwlock_unlock(&rwlock) != 0) { printf("Error releasing read lock\n"); exit(PTS_UNRESOLVED); } /* If the shared data is not altered by child after 3 seconds, we regard it as blocked */ /* thread1 should get the write lock */ cnt = 0; do{ sleep(1); }while (thread_state !=EXITING_THREAD && cnt++ < 3); if(thread_state == ENTERED_THREAD) { /* the child thread should get the lock */ printf("Test FAILEd: thread1 did not get the write lock\n"); exit(PTS_FAIL); } else if(thread_state != EXITING_THREAD) { /* for some reason the child does not start*/ printf("Child thread1 in unexpected state %d\n", thread_state); exit(PTS_UNRESOLVED); } if(pthread_join(thread1, NULL) != 0) { printf("Error joining thread1\n"); exit(PTS_UNRESOLVED); } printf("main: attempt write lock\n"); if(pthread_rwlock_wrlock(&rwlock) != 0) { printf("Test FAILED: main: Error geting write lock\n"); return PTS_FAIL; } printf("main: acquired write lock\n"); thread_state = NOT_CREATED_THREAD; cnt = 0; printf("main: create thread2\n"); if(pthread_create(&thread2, NULL, fn_wr, NULL) != 0) { printf("main: Error creating thread2\n"); return PTS_UNRESOLVED; } /* Thread2 should block */ do{ sleep(1); }while (thread_state !=EXITING_THREAD && cnt++ < 3); if(thread_state == EXITING_THREAD) { printf("Test FAILED: thread2 should have block\n"); exit(PTS_FAIL); } else if(thread_state != ENTERED_THREAD) { printf("thread2 in unexpected state %d\n", thread_state); exit(PTS_UNRESOLVED); } printf("main: unlock write lock\n"); if(pthread_rwlock_unlock(&rwlock) != 0) { printf("main: Error at releasing write lock\n"); exit(PTS_UNRESOLVED); } if(pthread_join(thread2, NULL) != 0) { printf("main: Error joining thread2\n"); exit(PTS_UNRESOLVED); } if(pthread_rwlock_destroy(&rwlock) != 0) { printf("Error at pthread_rwlockattr_destroy()\n"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_rwlock_wrlock/assertions.xml0100644000000000000000000000175607671436352026641 0ustar rootroot pthread_rwlock_wrlock( ) function shall apply a write lock to the read-write lock referenced by rwlock. The calling thread acquires the write lock if no other thread (reader or writer) holds the read-write lock rwlock. Otherwise, the thread shall block until it can acquire the lock If a signal is delivered to a thread waiting for a read-write lock for writing, upon return from the signal handler the thread resumes waiting for the read-write lock for writing as if it was not interrupted. If successful, the pthread_rwlock_wrlock( ) function shall return zero; otherwise, an error number shall be returned to indicate the error. It may fail if: [EDEADLK] The current thread already owns the rwlock for writing or reading. Shall not return an error code of [EINTR]. posixtestsuite/conformance/interfaces/pthread_rwlock_wrlock/coverage.txt0100644000000000000000000000017407671436352026252 0ustar rootrootThis document defines the coverage for the pthread_rwlock_wrlock() function: Assertion Tested? 1 YES 2 YES 3 YES NOTE: posixtestsuite/conformance/interfaces/pthread_rwlock_wrlock/2-1.c0100644000000000000000000001171607671436352024365 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test pthread_rwlock_wrlock(pthread_rwlock_t * rwlock) * * If a signal is delivered to a thread waiting for a read-write lock for writing, upon * return from the signal handler the thread resumes waiting for the read-write lock for * writing as if it was not interrupted. * * Steps: * 1. main thread create read-write lock 'rwlock', and lock it for writing * 2. main thread create a thread sig_thread, the thread is set to handle SIGUSR1 * 3. sig_thread try to lock 'rwlock' for writing but blocked * 4. main thread send SIGUSR1 to sig_thread via pthread_kill, while sig_thread is blocking * 5. test that thread handler is called * 6. check that when thread handler returns, sig_thread resume block * 7. main thread unlock 'rwlock', sig_thread should get the lock */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include "posixtest.h" static pthread_t sig_thread; static pthread_rwlock_t rwlock; /* thread_state indicates child thread state: 1: not in child thread yet; 2: just enter child thread ; 3: just before child thread exit; */ #define NOT_CREATED_THREAD 1 #define ENTERED_THREAD 2 #define EXITING_THREAD 3 static int thread_state; static int handler_called; static void sig_handler() { if(pthread_equal(pthread_self(), sig_thread)) { printf("sig_handler: handled signal SIGUSR1\n"); handler_called = 1; } else { printf("signal was not handled by sig_thread\n"); exit(PTS_UNRESOLVED); } } static void * th_fn(void *arg) { struct sigaction act; int rc = 0; /* Set up signal handler for SIGUSR1 */ act.sa_flags = 0; act.sa_handler = sig_handler; /* block all the signal while handling SIGUSR1 */ sigfillset(&act.sa_mask); sigaction(SIGUSR1, &act, NULL); thread_state = ENTERED_THREAD; printf("sig_thread: attempt write lock\n"); rc = pthread_rwlock_wrlock(&rwlock); if(rc != 0) { printf("Test FAILED: sig_thread: Error at pthread_rwlock_wrlock(), error code:%d\n", rc); exit(PTS_FAIL); } printf("sig_thread: acquired write lock\n"); printf("sig_thread: unlock write lock\n"); if(pthread_rwlock_unlock(&rwlock) != 0) { printf("sig_thread: Error at pthread_rwlock_unlock()\n"); exit(PTS_UNRESOLVED); } thread_state = EXITING_THREAD; pthread_exit(0); return NULL; } int main() { int cnt; int rc = 0; handler_called=0; if(pthread_rwlock_init(&rwlock, NULL) != 0) { printf("Error at pthread_rwlock_init()\n"); return PTS_UNRESOLVED; } printf("main: attempt write lock\n"); rc = pthread_rwlock_wrlock(&rwlock); if(rc != 0) { printf("main: Error at pthread_rwlock_wrlock(), error code:%d\n", rc); return PTS_UNRESOLVED; } thread_state = NOT_CREATED_THREAD; if(pthread_create(&sig_thread, NULL, th_fn, NULL) != 0) { printf("Error at pthread_create()\n"); return PTS_UNRESOLVED; } /* wait at most 3 seconds for sig_thread to block*/ cnt = 0; do{ sleep(1); }while(thread_state != EXITING_THREAD && cnt++ < 3); if(thread_state == EXITING_THREAD) { /* the sig_thread is not blocking*/ printf("Test FAILED: the thread should block when getting write lock\n"); exit(PTS_FAIL); } else if(thread_state != ENTERED_THREAD) { printf("sig_thread in unexpected state %d\n", thread_state); exit(PTS_UNRESOLVED); } /* sig_thread is blocking */ printf("main: fire SIGUSR1 to sig_thread\n"); if(pthread_kill(sig_thread, SIGUSR1) != 0) { printf("Error at pthread_kill()\n"); exit(PTS_UNRESOLVED); } /* wait at most 3 seconds for the singal to be handled */ cnt = 0; do{ sleep(1); }while(handler_called == 0 && cnt++ < 3); if(handler_called != 1) { printf("The signal handler did not get called.\n"); exit(PTS_UNRESOLVED); } /* sig_thread resume to block? */ cnt = 0; do{ sleep(1); }while(thread_state != EXITING_THREAD && cnt++ < 3); if(thread_state == 3) { printf("Test FAILED: upon return from signal handler, sig_thread does not resume to wait\n"); exit(PTS_FAIL); } printf("sig_thread: correctly still blocking after signal handler returns\n"); printf("main: unlock write lock\n"); if(pthread_rwlock_unlock(&rwlock) != 0) { printf("main: Error releasing write lock\n"); exit(PTS_UNRESOLVED); } /* sig_thread should get write lock */ cnt = 0; do{ sleep(1); }while(thread_state != EXITING_THREAD && cnt++ < 3); if(thread_state != EXITING_THREAD) { /* sig_thread does not unblock */ printf("Test FAILED: sig_thread should get the write lock and exit\n"); exit(PTS_FAIL); } if(pthread_join(sig_thread, NULL) != 0) { printf("Error at pthread_join()\n"); exit(PTS_UNRESOLVED); } if(pthread_rwlock_destroy(&rwlock) != 0) { printf("pthread_rwlock_destroy()\n"); exit(PTS_UNRESOLVED); } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_rwlock_wrlock/3-1.c0100644000000000000000000000435307671436352024365 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test pthread_rwlock_wrlock(pthread_rwlock_t *rwlock) * * It may fail if: * [EDEADLK] The current thread already owns the rwlock for writing or reading. * * Steps: * 1. Create and initialize an rwlock * 2. Perform a write lock via pthread_rwlock_wrlock() * 3. Perform a write lock _again_ with pthread_rwlock_wrlock without first unlocking rwlock() * 4. Test if returns EDEADLK or not. Note the standard states "may" fail, so the test always * passes even if 0 is returned. * */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include "posixtest.h" int main() { static pthread_rwlock_t rwlock; int rc; if(pthread_rwlock_init(&rwlock, NULL) != 0) { printf("Error at pthread_rwlock_init()\n"); return PTS_UNRESOLVED; } /* Attempt to write lock rwlock, it should return successfully */ printf("main: attempt write lock\n"); if(pthread_rwlock_wrlock(&rwlock) != 0) { printf("Error at pthread_rwlock_wrlock()\n"); return PTS_UNRESOLVED; } printf("main: acquired write lock\n"); /* Now attempt to write lock again without first unlocking rwlock. It may return * EDEADLK, but it may also return successfully. */ printf("main: attempt write lock\n"); rc = pthread_rwlock_wrlock(&rwlock); /* Clean up before we test the return value of pthread_rwlock_wrlock() */ if(pthread_rwlock_unlock(&rwlock) != 0) { printf("Error releasing write lock\n"); exit(PTS_UNRESOLVED); } if(pthread_rwlock_destroy(&rwlock) != 0) { printf("Error at pthread_rwlock_destroy()\n"); return PTS_UNRESOLVED; } if(rc != 0) { if(rc == EDEADLK) { printf("main: correctly got EDEADLK\n"); printf("Test PASSED\n"); return PTS_PASS; } else { printf("Test FAILED: Incorrect return code %d\n", rc); return PTS_FAIL; } } printf("main: acquired write lock\n"); printf("main: unlock write lock\n"); printf("Test PASSED: Note*: Returned 0 instead of EDEADLK, but standard specified _may_ fail.\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/sigtimedwait/0040755000000000000000000000000010515625267022014 5ustar rootrootposixtestsuite/conformance/interfaces/sigtimedwait/5-1.c0100644000000000000000000000526207653271534022467 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: salwan.searty REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test that sigtimedwait() returns -1 upon unsuccessful completion. NOTE: This program has commented out areas. The commented out functionality sets a timer in case sigtimedwait() never returns, to help the program from hanging. To make this program runnable on a typical system, I've commented out the timer functionality by default. However, if you do have a timers implementation on your system, then it is recommened that you uncomment the timers-related lines of code in this program. Steps: 1. Register signal TIMERSIGNAL with the handler myhandler (2.)Create and set a timer that expires in TIMERSEC seconds incase sigtimedwait() never returns. 3. Call sigtimedwait() to wait for non-pending signal SIGTOTEST for SIGTIMEDWAITSEC seconds. 4. Verify that sigtimedwait() returns a -1. */ #define _XOPEN_SOURCE 600 #define _XOPEN_REALTIME 1 #define TIMERSIGNAL SIGUSR1 #define SIGTOTEST SIGUSR2 #define TIMERSEC 2 #define SIGTIMEDWAITSEC 0 #include #include #include #include #include #include #include "posixtest.h" void myhandler (int signo) { printf("Test FAILED: %d seconds have elapsed and sigtimedwait() has not yet returned.\n", TIMERSEC); exit (PTS_FAIL); } int main() { struct sigaction act; sigset_t selectset; struct timespec ts; /* struct sigevent ev; timer_t tid; struct itimerspec its; its.it_interval.tv_sec = 0; its.it_interval.tv_nsec = 0; its.it_value.tv_sec = TIMERSEC; its.it_value.tv_nsec = 0; ev.sigev_notify = SIGEV_SIGNAL; ev.sigev_signo = TIMERSIGNAL; */ act.sa_flags=0; act.sa_handler=myhandler; sigemptyset(&act.sa_mask); sigaction(TIMERSIGNAL, &act, 0); sigemptyset(&selectset); sigaddset(&selectset, SIGTOTEST); ts.tv_sec=SIGTIMEDWAITSEC; ts.tv_nsec=0; /* if (timer_create(CLOCK_REALTIME, &ev, &tid) != 0) { perror("timer_create() did not return success\n"); return PTS_UNRESOLVED; } if (timer_settime(tid, 0, &its, NULL) != 0) { perror("timer_settime() did not return success\n"); return PTS_UNRESOLVED; } */ if (sigtimedwait(&selectset, NULL, &ts) != -1) { printf ("Test FAILED: sigtimedwait() did not return with an error\n"); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/sigtimedwait/4-1.c0100644000000000000000000000307507653271534022466 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: salwan.searty REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that the sigtimedwait() function shall return the selected signal number upon success. Steps: 1. Register signal SIGTOTEST with the handler myhandler 2. Block SIGTOTEST from the process 3. Raise the signal, causing it to be pending 4. Call sigtimedwait() and verify that it returns the signal SIGTOTEST. */ #define _XOPEN_SOURCE 600 #define _XOPEN_REALTIME 1 #define SIGTOTEST SIGUSR1 #include #include #include #include #include #include "posixtest.h" void myhandler (int signo) { printf("Inside handler\n"); } int main() { struct sigaction act; sigset_t pendingset, selectset; struct timespec ts; act.sa_flags=0; act.sa_handler=myhandler; ts.tv_sec=0; ts.tv_nsec=0; sigemptyset(&pendingset); sigemptyset(&selectset); sigaddset(&selectset, SIGTOTEST); sigemptyset(&act.sa_mask); sigaction(SIGTOTEST, &act, 0); sighold(SIGTOTEST); raise(SIGTOTEST); sigpending(&pendingset); if (sigismember(&pendingset, SIGTOTEST) != 1) { perror("SIGTOTEST is not pending\n"); return PTS_UNRESOLVED; } if (sigtimedwait(&selectset, NULL, &ts) != SIGTOTEST) { perror("Call to sigtimedwait() failed\n"); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/sigtimedwait/1-1.c0100644000000000000000000000646407653271533022467 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: salwan.searty REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that if the signal specified by set does not become pending, the sigtimedwait() function shall wait for the time interval specified in the timespec structure referenced by timeout. NOTE: This program has commented out areas. The commented out functionality sets a timer in case sigtimedwait() never returns, to help the program from hanging. To make this program runnable on a typical system, I've commented out the timer functionality by default. However, if you do have a timers implementation on your system, then it is recommened that you uncomment the timers-related lines of code in this program. Steps: 1. Register signal TIMERSIGNAL with the handler myhandler (2.)Create and set a timer that expires in TIMERSEC seconds incase sigtimedwait() never returns. 3. Obtain time1. 4. Call sigtimedwait() to wait for signal SIGTOTEST that will never be pending 5. Obtain time2, and find the difference between time2 and time1. 6. Verify that (time2-time1) is equal to SIGTIMEDWAITSEC within a reasonable error margin. */ #define _XOPEN_SOURCE 600 #define _XOPEN_REALTIME 1 #define TIMERSIGNAL SIGUSR1 #define SIGTOTEST SIGUSR2 #define TIMERSEC 2 #define SIGTIMEDWAITSEC 1 #define ERRORMARGIN 0.01 #include #include #include #include #include #include #include "posixtest.h" void myhandler (int signo) { printf("Test FAILED: %d seconds have elapsed and sigtimedwait() has not yet returned.\n", TIMERSEC); exit (PTS_FAIL); } int main() { struct sigaction act; time_t time1, time2; double time_elapsed; sigset_t selectset; struct timespec ts; /* struct sigevent ev; timer_t tid; struct itimerspec its; its.it_interval.tv_sec = 0; its.it_interval.tv_nsec = 0; its.it_value.tv_sec = TIMERSEC; its.it_value.tv_nsec = 0; ev.sigev_notify = SIGEV_SIGNAL; ev.sigev_signo = TIMERSIGNAL; */ act.sa_flags=0; act.sa_handler=myhandler; sigemptyset(&act.sa_mask); sigaction(TIMERSIGNAL, &act, 0); sigemptyset(&selectset); sigaddset(&selectset, SIGTOTEST); ts.tv_sec=SIGTIMEDWAITSEC; ts.tv_nsec=0; /* if (timer_create(CLOCK_REALTIME, &ev, &tid) != 0) { perror("timer_create() did not return success\n"); return PTS_UNRESOLVED; } if (timer_settime(tid, 0, &its, NULL) != 0) { perror("timer_settime() did not return success\n"); return PTS_UNRESOLVED; } */ time1 = time(NULL); if (sigtimedwait(&selectset, NULL, &ts) != -1) { perror("sigtimedwait() did not return -1 even though signal was not pending\n"); return PTS_UNRESOLVED; } time2 = time(NULL); time_elapsed = difftime (time2, time1); if ((time_elapsed > SIGTIMEDWAITSEC+ERRORMARGIN) || (time_elapsed < SIGTIMEDWAITSEC-ERRORMARGIN)) { printf ("Test FAILED: sigtimedwait() did not return in the required time\n"); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/sigtimedwait/6-1.c0100644000000000000000000000560407653271535022471 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: salwan.searty REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test that sigtimedwait() sets errno to [EAGAIN] if no signal specified by set was generated within the specified timeout period. NOTE: This program has commented out areas. The commented out functionality sets a timer in case sigtimedwait() never returns, to help the program from hanging. To make this program runnable on a typical system, I've commented out the timer functionality by default. However, if you do have a timers implementation on your system, then it is recommened that you uncomment the timers-related lines of code in this program. Steps: 1. Register signal TIMERSIGNAL with the handler myhandler (2.)Create and set a timer that expires in TIMERSEC seconds incase sigtimedwait() never returns. 3. Call sigtimedwait() to wait for non-pending signal SIGTOTEST for SIGTIMEDWAITSEC seconds. 4. Verify that sigtimedwait() sets errno to [EAGAIN]. */ #define _XOPEN_SOURCE 600 #define _XOPEN_REALTIME 1 #define TIMERSIGNAL SIGUSR1 #define SIGTOTEST SIGUSR2 #define TIMERSEC 2 #define SIGTIMEDWAITSEC 1 #include #include #include #include #include #include #include #include "posixtest.h" void myhandler (int signo) { printf("Test FAILED: %d seconds have elapsed and sigtimedwait() has not yet returned.\n", TIMERSEC); exit (PTS_FAIL); } int main() { struct sigaction act; sigset_t selectset; struct timespec ts; /* struct sigevent ev; timer_t tid; struct itimerspec its; its.it_interval.tv_sec = 0; its.it_interval.tv_nsec = 0; its.it_value.tv_sec = TIMERSEC; its.it_value.tv_nsec = 0; ev.sigev_notify = SIGEV_SIGNAL; ev.sigev_signo = TIMERSIGNAL; */ act.sa_flags=0; act.sa_handler=myhandler; sigemptyset(&act.sa_mask); sigaction(TIMERSIGNAL, &act, 0); sigemptyset(&selectset); sigaddset(&selectset, SIGTOTEST); ts.tv_sec=SIGTIMEDWAITSEC; ts.tv_nsec=0; /* if (timer_create(CLOCK_REALTIME, &ev, &tid) != 0) { perror("timer_create() did not return success\n"); return PTS_UNRESOLVED; } if (timer_settime(tid, 0, &its, NULL) != 0) { perror("timer_settime() did not return success\n"); return PTS_UNRESOLVED; } */ if (sigtimedwait(&selectset, NULL, &ts) != -1) { printf ("Test UNRESOLVED: sigtimedwait() did not return -1\n"); return PTS_UNRESOLVED; } if (errno != EAGAIN) { printf ("Test FAILED: sigtimedwait() did set errno to EAGAIN\n"); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/sigtimedwait/assertions.xml0100644000000000000000000000231307653271535024730 0ustar rootroot sigtimedwait( ) shall wait for the time interval specified in the timespec structure referenced by timeout, if none of the signals specified by set are pending, sigtimedwait( ) shall return immediately with an error, if the timespec structure pointed to by timeout is7 zero-valued and if none of the signals specified by set are pending. The CLOCK_MONOTONIC clock shall be used to measure the time interval specified by the timeout argument, if the Monotonic Clock option is supported. sigtimedwait( ) shall return the selected signal number, upon successful completion sigtimedwait() shall return a value of -1 upon unsuccessful completion. sigtimedwait() shall set errno to [EAGAIN] if no signal specified by set was generated within the specified timeout period. posixtestsuite/conformance/interfaces/sigtimedwait/coverage.txt0100644000000000000000000000026207653271625024351 0ustar rootrootThis file defines the coverage for the sigtimedwait() function testing. Assertion Status 1 DONE 2 DONE 3 Implicitly tested via tests 1, 2, 4, and 5. 4 DONE 5 DONE 6 DONE posixtestsuite/conformance/interfaces/sigtimedwait/2-1.c0100644000000000000000000000645707653271534022473 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: salwan.searty REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that if the signal specified by set does not become pending, and the timespec structure pointed to by timeout is zero-valued, the sigtimedwait() function shall return immediately with an error. NOTE: This program has commented out areas. The commented out functionality sets a timer in case sigtimedwait() never returns, to help the program from hanging. To make this program runnable on a typical system, I've commented out the timer functionality by default. However, if you do have a timers implementation on your system, then it is recommened that you uncomment the timers-related lines of code in this program. Steps: 1. Register signal TIMERSIGNAL with the handler myhandler (2.)Create and set a timer that expires in TIMERSEC seconds incase sigtimedwait() never returns. 3. Obtain time1. 4. Call sigtimedwait() to wait for non-pending signal SIGTOTEST for SIGTIMEDWAITSEC seconds. 5. Obtain time2, and find the difference between time2 and time1. 6. Verify that (time2-time1) is equal to SIGTIMEDWAITSEC within a reasonable error margin. */ #define _XOPEN_SOURCE 600 #define _XOPEN_REALTIME 1 #define TIMERSIGNAL SIGUSR1 #define SIGTOTEST SIGUSR2 #define TIMERSEC 2 #define SIGTIMEDWAITSEC 0 #define ERRORMARGIN 0.01 #include #include #include #include #include #include #include "posixtest.h" void myhandler (int signo) { printf("Test FAILED: %d seconds have elapsed and sigtimedwait() has not yet returned.\n", TIMERSEC); exit (PTS_FAIL); } int main() { struct sigaction act; time_t time1, time2; double time_elapsed; sigset_t selectset; struct timespec ts; /* struct sigevent ev; timer_t tid; struct itimerspec its; its.it_interval.tv_sec = 0; its.it_interval.tv_nsec = 0; its.it_value.tv_sec = TIMERSEC; its.it_value.tv_nsec = 0; ev.sigev_notify = SIGEV_SIGNAL; ev.sigev_signo = TIMERSIGNAL; */ act.sa_flags=0; act.sa_handler=myhandler; sigemptyset(&act.sa_mask); sigaction(TIMERSIGNAL, &act, 0); sigemptyset(&selectset); sigaddset(&selectset, SIGTOTEST); ts.tv_sec=SIGTIMEDWAITSEC; ts.tv_nsec=0; /* if (timer_create(CLOCK_REALTIME, &ev, &tid) != 0) { perror("timer_create() did not return success\n"); return PTS_UNRESOLVED; } if (timer_settime(tid, 0, &its, NULL) != 0) { perror("timer_settime() did not return success\n"); return PTS_UNRESOLVED; } */ time1 = time(NULL); if (sigtimedwait(&selectset, NULL, &ts) != -1) { printf ("Test FAILED: sigtimedwait() did not return with an error\n"); return PTS_FAIL; } time2 = time(NULL); time_elapsed = difftime (time2, time1); if ((time_elapsed > SIGTIMEDWAITSEC+ERRORMARGIN) || (time_elapsed < SIGTIMEDWAITSEC-ERRORMARGIN)) { printf ("Test FAILED: sigtimedwait() did not return immediately\n"); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/mq_send/0040755000000000000000000000000010515625172020743 5ustar rootrootposixtestsuite/conformance/interfaces/mq_send/11-2.c0100644000000000000000000000322710035502500021452 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * Test that mq_send() returns errno == EBADF if mqdes is not open for * writing. */ #include #include #include #include #include #include #include #include #include "posixtest.h" #define NAMESIZE 50 #define MSGSTR "0123456789" int main() { char qname[NAMESIZE]; const char *msgptr = MSGSTR; mqd_t queue; int unresolved=0, failure=0; sprintf(qname, "/mq_send_11-2_%d", getpid()); queue = mq_open(qname, O_CREAT | O_RDONLY, S_IRUSR | S_IWUSR, NULL); if (queue == (mqd_t)-1) { perror("mq_open() did not return success"); return PTS_UNRESOLVED; } if (mq_send(queue, msgptr, strlen(msgptr), 1) != -1) { printf("mq_send() did not return -1 on invalid queue\n"); failure=1; } if (errno != EBADF) { printf("errno != EBADF\n"); failure = 1; } if (mq_close(queue) != 0) { perror("mq_close() did not return success"); unresolved=1; } if (mq_unlink(qname) != 0) { perror("mq_unlink() did not return success"); unresolved=1; } if (failure==1) { printf("Test FAILED\n"); return PTS_FAIL; } if (unresolved==1) { printf("Test UNRESOLVED\n"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/mq_send/5-1.c0100644000000000000000000000661410336125321021405 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * Test that if the message queue is full and O_NONBLOCK is not set, mq_send() * will block until it can place the message in the queue. * * Test by sending messages in a child process until the message queue is full. * At this point, the child should be blocking on sending. Then, have the * parent receive the message and return pass when the next message is sent * to the message queue. * * 3/13/03 - Added fix from Gregoire Pichon for specifying an attr * with a mq_maxmsg >= BUFFER. * */ #include #include #include #include #include #include #include #include #include #include #include #include #include "posixtest.h" #define NAMESIZE 50 #define MSGSTR "0123456789" #define BUFFER 40 #define MAXMSG 5 char gqname[NAMESIZE]; mqd_t gqueue; /* * This handler is just used to catch the signal and stop sleep (so the * parent knows the child is still busy sending signals). */ void stopsleep_handler(int signo) { return; } int main() { int pid; char msgrcd[BUFFER]; const char *msgptr = MSGSTR; struct mq_attr attr; int unresolved=0; unsigned pri; sprintf(gqname, "/mq_send_5-1_%d", getpid()); attr.mq_msgsize = BUFFER; attr.mq_maxmsg = MAXMSG; gqueue = mq_open(gqname, O_CREAT |O_RDWR, S_IRUSR | S_IWUSR, &attr); if (gqueue == (mqd_t)-1) { perror("mq_open() did not return success"); return PTS_UNRESOLVED; } if ((pid = fork()) == 0) { /* child here */ int i; sleep(1); // give parent time to set up handler for (i=0; i #include #include #include #include #include #include #include #include "posixtest.h" #define NAMESIZE 50 #define MSGSTR "0123456789" int main() { char qname[NAMESIZE]; const char *msgptr = MSGSTR; mqd_t queue; int unresolved=0, failure=0; sprintf(qname, "/mq_send_4-1_%d", getpid()); queue = mq_open(qname, O_CREAT |O_RDWR, S_IRUSR | S_IWUSR, NULL); if (queue == (mqd_t)-1) { perror("mq_open() did not return success"); return PTS_UNRESOLVED; } if (mq_send(queue, msgptr, strlen(msgptr), MQ_PRIO_MAX+1) == 0) { printf("mq_send() returned success with pri > MQ_PRIO_MAX\n"); failure=1; } if (mq_close(queue) != 0) { perror("mq_close() did not return success"); unresolved=1; } if (mq_unlink(qname) != 0) { perror("mq_unlink() did not return success"); unresolved=1; } if (failure==1) { printf("Test FAILED\n"); return PTS_FAIL; } if (unresolved==1) { printf("Test UNRESOLVED\n"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/mq_send/14-1.c0100644000000000000000000000362210035502500021453 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * Test that EMSGSIZE is returned if msg_len is not <= mq_attr->mq_msgsize. */ #include #include #include #include #include #include #include #include #include #include "posixtest.h" #define NAMESIZE 50 #define MSGSTR "01234567890123456789" #define NUMINVALID 3 static long messagesize[NUMINVALID] = { 19, 2, 1 }; int main() { char qname[NAMESIZE]; const char *msgptr = MSGSTR; mqd_t queue; int unresolved=0, failure=0, i; struct mq_attr attr; sprintf(qname, "/mq_send_14-1_%d", getpid()); for (i=0; i #include #include #include #include #include #include #include #include #include #include #include #include "posixtest.h" #define NAMESIZE 50 #define MSGSTR "0123456789" #define BUFFER 40 #define MAXMSG 5 #define CHILDPASS 1 #define CHILDFAIL 0 char gqname[NAMESIZE]; mqd_t gqueue; /* * This handler is just used to catch the signal and stop sleep (so the * parent knows the child is still busy sending signals). */ void justreturn_handler(int signo) { return; } int main() { int pid; const char *msgptr = MSGSTR; struct mq_attr attr; struct sigaction act; sprintf(gqname, "/mq_send_5-2_%d", getpid()); attr.mq_msgsize = BUFFER; attr.mq_maxmsg = MAXMSG; gqueue = mq_open(gqname, O_CREAT |O_RDWR, S_IRUSR | S_IWUSR, &attr); if (gqueue == (mqd_t)-1) { perror("mq_open() did not return success"); return PTS_UNRESOLVED; } /* parent and child use justreturn_handler to just return out of * situations -- parent uses to stop it's sleep and wait again for * the child; child uses to stop its mq_send */ act.sa_handler=justreturn_handler; act.sa_flags=0; sigemptyset(&act.sa_mask); sigaction(SIGABRT, &act, 0); if ((pid = fork()) == 0) { /* child here */ int i; sleep(1); // give parent time to set up handler for (i=0; i #include #include #include #include #include #include #include #include #include #include #include #include "posixtest.h" #define NAMESIZE 50 #define MSGSTR "0123456789" #define BUFFER 40 #define MAXMSG 5 #define CHILDPASS 1 #define CHILDFAIL 0 char gqname[NAMESIZE]; mqd_t gqueue; /* * This handler is just used to catch the signal and stop sleep (so the * parent knows the child is still busy sending signals). */ void justreturn_handler(int signo) { return; } int main() { int pid; const char *msgptr = MSGSTR; struct mq_attr attr; struct sigaction act; sprintf(gqname, "/mq_send_12-1_%d", getpid()); attr.mq_maxmsg = MAXMSG; attr.mq_msgsize = BUFFER; gqueue = mq_open(gqname, O_CREAT |O_RDWR, S_IRUSR | S_IWUSR, &attr); if (gqueue == (mqd_t)-1) { perror("mq_open() did not return success"); return PTS_UNRESOLVED; } /* parent and child use justreturn_handler to just return out of * situations -- parent uses to stop it's sleep and wait again for * the child; child uses to stop its mq_send */ act.sa_handler=justreturn_handler; act.sa_flags=0; sigemptyset(&act.sa_mask); sigaction(SIGABRT, &act, 0); if ((pid = fork()) == 0) { /* child here */ int i; sleep(1); // give parent time to set up handler for (i=0; i= BUFFER. */ #include #include #include #include #include #include #include #include "posixtest.h" #define NAMESIZE 50 #define MSGSTR "0123456789" #define BUFFER 40 #define MAXMSG 10 int main() { char qname[NAMESIZE], msgrcd[BUFFER]; const char *msgptr = MSGSTR; mqd_t queue; struct mq_attr attr; int unresolved=0, failure=0; unsigned pri; sprintf(qname, "/mq_send_1-1_%d", getpid()); attr.mq_msgsize = BUFFER; attr.mq_maxmsg = MAXMSG; queue = mq_open(qname, O_CREAT |O_RDWR, S_IRUSR | S_IWUSR, &attr); if (queue == (mqd_t)-1) { perror("mq_open() did not return success"); return PTS_UNRESOLVED; } if (mq_send(queue, msgptr, strlen(msgptr), 1) != 0) { perror("mq_send() did not return success"); failure=1; } if (mq_receive(queue, msgrcd, BUFFER, &pri) == -1) { perror("mq_receive() returned failure"); failure=1; } if (strncmp(msgptr, msgrcd, strlen(msgptr)) != 0) { printf("FAIL: sent %s received %s\n", msgptr, msgrcd); failure = 1; } if (mq_close(queue) != 0) { perror("mq_close() did not return success"); unresolved=1; } if (mq_unlink(qname) != 0) { perror("mq_unlink() did not return success"); unresolved=1; } if (failure==1) { printf("Test FAILED\n"); return PTS_FAIL; } if (unresolved==1) { printf("Test UNRESOLVED\n"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/mq_send/9-1.c0100644000000000000000000000455210336125321021410 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * Test that mq_send() returns -1 on failure, no message is queued, and * errno is set. * The failure case chosen is an invalid message queue descriptor. * * 3/13/03 - Added fix from Gregoire Pichon for specifying an attr * with a mq_maxmsg >= BUFFER. */ #include #include #include #include #include #include #include #include #include "posixtest.h" #define NAMESIZE 50 #define MSGSTR "0123456789" #define BUFFER 40 #define MAXMSG 10 int main() { char qname[NAMESIZE], msgrcd[BUFFER]; const char *msgptr = MSGSTR; mqd_t queue; struct mq_attr attr; int unresolved=0, failure=0; unsigned pri; sprintf(qname, "/mq_send_9-1_%d", getpid()); attr.mq_msgsize = BUFFER; attr.mq_maxmsg = MAXMSG; queue = mq_open(qname, O_CREAT |O_RDWR | O_NONBLOCK, S_IRUSR | S_IWUSR, &attr); if (queue == (mqd_t)-1) { perror("mq_open() did not return success"); return PTS_UNRESOLVED; } // Verify mq_send() returns -1 if (mq_send(queue+1, msgptr, strlen(msgptr), 1) != -1) { printf("mq_send() did not return -1 on invalid queue\n"); failure=1; } // Verify errno is set if (errno != EBADF) { printf("errno was not set on invalid queue\n"); failure = 1; } // Verify message was not queued (cannot be received) if (mq_receive(queue, msgrcd, BUFFER, &pri) != -1) { if (strcmp(msgptr, msgrcd) == 0) { printf("Message ended up being sent\n"); failure = 1; } else { printf("Error with mq_receive()\n"); unresolved = 1; } } if (mq_close(queue) != 0) { perror("mq_close() did not return success"); unresolved=1; } if (mq_unlink(qname) != 0) { perror("mq_unlink() did not return success"); unresolved=1; } if (failure==1) { printf("Test FAILED\n"); return PTS_FAIL; } if (unresolved==1) { printf("Test UNRESOLVED\n"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/mq_send/11-1.c0100644000000000000000000000324610035502500021452 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * Test that mq_send() returns errno == EBADF if mqdes is not a valid * message queue descriptor. */ #include #include #include #include #include #include #include #include #include "posixtest.h" #define NAMESIZE 50 #define MSGSTR "0123456789" int main() { char qname[NAMESIZE]; const char *msgptr = MSGSTR; mqd_t queue; int unresolved=0, failure=0; sprintf(qname, "/mq_send_11-1_%d", getpid()); queue = mq_open(qname, O_CREAT |O_RDWR, S_IRUSR | S_IWUSR, NULL); if (queue == (mqd_t)-1) { perror("mq_open() did not return success"); return PTS_UNRESOLVED; } if (mq_send(queue+1, msgptr, strlen(msgptr), 1) != -1) { printf("mq_send() did not return -1 on invalid queue\n"); failure=1; } if (errno != EBADF) { printf("errno != EBADF\n"); failure = 1; } if (mq_close(queue) != 0) { perror("mq_close() did not return success"); unresolved=1; } if (mq_unlink(qname) != 0) { perror("mq_unlink() did not return success"); unresolved=1; } if (failure==1) { printf("Test FAILED\n"); return PTS_FAIL; } if (unresolved==1) { printf("Test UNRESOLVED\n"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/mq_send/6-1.c0100644000000000000000000000134207631437105021411 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: geoffrey.r.gustafson REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * Since the implementation of the order in which items are placed into * a message queue is undetermined unless Priority Scheduling is enabled, * this test will not be written right now. It needs priority scheduling * to complete. */ #include #include "posixtest.h" int main() { printf("Priority Scheduling needed to make a reliable test case\n"); printf("for this instance. Will not be tested.\n"); return PTS_UNTESTED; } posixtestsuite/conformance/interfaces/mq_send/4-3.c0100644000000000000000000000404710336125321021404 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * Test that msg_prio can be equal to MQ_PRIO_MAX-1. * * 3/13/03 - Added fix from Gregoire Pichon for specifying an attr * with a mq_maxmsg >= BUFFER. * */ #include #include #include #include #include #include #include #include #include "posixtest.h" #define NAMESIZE 50 #define MSGSTR "0123456789" #define BUFFER 40 #define MAXMSG 10 int main() { char qname[NAMESIZE], msgrcd[BUFFER]; const char *msgptr = MSGSTR; mqd_t queue; struct mq_attr attr; int unresolved=0, failure=0; unsigned pri; sprintf(qname, "/mq_send_4-3_%d", getpid()); attr.mq_msgsize = BUFFER; attr.mq_maxmsg = MAXMSG; queue = mq_open(qname, O_CREAT |O_RDWR, S_IRUSR | S_IWUSR, &attr); if (queue == (mqd_t)-1) { perror("mq_open() did not return success"); return PTS_UNRESOLVED; } if (mq_send(queue, msgptr, strlen(msgptr), MQ_PRIO_MAX-1) != 0) { perror("mq_send() did not return success"); failure=1; } if (mq_receive(queue, msgrcd, BUFFER, &pri) == -1) { perror("mq_receive() returned failure"); failure=1; } if (strncmp(msgptr, msgrcd, strlen(msgptr)) != 0) { printf("FAIL: sent %s received %s\n", msgptr, msgrcd); failure = 1; } if (mq_close(queue) != 0) { perror("mq_close() did not return success"); unresolved=1; } if (mq_unlink(qname) != 0) { perror("mq_unlink() did not return success"); unresolved=1; } if (failure==1) { printf("Test FAILED\n"); return PTS_FAIL; } if (unresolved==1) { printf("Test UNRESOLVED\n"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/mq_send/10-1.c0100644000000000000000000000375710035502500021460 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * Test that if O_NONBLOCK is set and the message queue is full, mq_send() * will set errno == EAGAIN (subset of 7-1.c). */ #include #include #include #include #include #include #include #include #include #include "posixtest.h" #define NAMESIZE 50 #define MESSAGESIZE 50 #define BUFFER 40 #define MAXMSG 10 int main() { char qname[NAMESIZE]; char msgptr[MESSAGESIZE]; mqd_t queue; struct mq_attr attr; int unresolved=0, failure=0, i, maxreached=0; sprintf(qname, "/mq_send_10-1_%d", getpid()); attr.mq_maxmsg = MAXMSG; attr.mq_msgsize = BUFFER; queue = mq_open(qname, O_CREAT | O_RDWR | O_NONBLOCK, S_IRUSR | S_IWUSR, &attr); if (queue == (mqd_t)-1) { perror("mq_open() did not return success"); return PTS_UNRESOLVED; } for (i=0; i= MQ_PRIO_MAX or < 0 (<0 N/A * for an unsigned, so not tested). */ #include #include #include #include #include #include #include #include #include #include "posixtest.h" #define NAMESIZE 50 #define MSGSTR "0123456789" #define NUMINVALID 3 static unsigned invalidpri[NUMINVALID] = { MQ_PRIO_MAX, MQ_PRIO_MAX+1, MQ_PRIO_MAX+5 }; int main() { char qname[NAMESIZE]; const char *msgptr = MSGSTR; mqd_t queue; int unresolved=0, failure=0, i; sprintf(qname, "/mq_send_13-1_%d", getpid()); queue = mq_open(qname, O_CREAT |O_RDWR, S_IRUSR | S_IWUSR, NULL); if (queue == (mqd_t)-1) { perror("mq_open() did not return success"); return PTS_UNRESOLVED; } for (i=0; i= BUFFER. */ #include #include #include #include #include #include #include #include "posixtest.h" #define NAMESIZE 50 #define MSG1 "1234567890" #define PRI1 10 #define MSG2 "234567890" #define PRI2 8 #define MSG3 "34567890" #define PRI3 6 #define MSG4 "4567890" #define PRI4 6 #define MSG5 "567890" #define PRI5 1 #define BUFFER 40 #define MAXMSG 10 int main() { char qname[NAMESIZE], msgrcd[BUFFER]; const char *msgptr1 = MSG1; const char *msgptr2 = MSG2; const char *msgptr3 = MSG3; const char *msgptr4 = MSG4; const char *msgptr5 = MSG5; mqd_t queue; struct mq_attr attr; int unresolved=0, failure=0; unsigned pri; sprintf(qname, "/mq_send_3-2_%d", getpid()); attr.mq_msgsize = BUFFER; attr.mq_maxmsg = MAXMSG; queue = mq_open(qname, O_CREAT |O_RDWR, S_IRUSR | S_IWUSR, &attr); if (queue == (mqd_t)-1) { perror("mq_open() did not return success"); return PTS_UNRESOLVED; } if (mq_send(queue, msgptr3, strlen(msgptr3), PRI3) != 0) { perror("mq_send() did not return success"); printf("error sending %s\n", msgptr3); failure=1; } if (mq_send(queue, msgptr1, strlen(msgptr1), PRI1) != 0) { perror("mq_send() did not return success"); printf("error sending %s\n", msgptr1); failure=1; } if (mq_send(queue, msgptr4, strlen(msgptr4), PRI4) != 0) { perror("mq_send() did not return success"); printf("error sending %s\n", msgptr4); failure=1; } if (mq_send(queue, msgptr2, strlen(msgptr2), PRI2) != 0) { perror("mq_send() did not return success"); printf("error sending %s\n", msgptr2); failure=1; } if (mq_send(queue, msgptr5, strlen(msgptr5), PRI5) != 0) { perror("mq_send() did not return success"); printf("error sending %s\n", msgptr5); failure=1; } if (mq_receive(queue, msgrcd, BUFFER, &pri) == -1) { perror("mq_receive() returned failure"); unresolved=1; } if (strncmp(msgptr1, msgrcd, strlen(msgptr1)) != 0) { printf("FAIL: sent %s received %s\n", msgptr1, msgrcd); failure = 1; } if (mq_receive(queue, msgrcd, BUFFER, &pri) == -1) { perror("mq_receive() returned failure"); unresolved=1; } if (strncmp(msgptr2, msgrcd, strlen(msgptr2)) != 0) { printf("FAIL: sent %s received %s\n", msgptr2, msgrcd); failure = 1; } if (mq_receive(queue, msgrcd, BUFFER, &pri) == -1) { perror("mq_receive() returned failure"); unresolved=1; } if (strncmp(msgptr3, msgrcd, strlen(msgptr3)) != 0) { printf("FAIL: sent %s received %s\n", msgptr3, msgrcd); failure = 1; } if (mq_receive(queue, msgrcd, BUFFER, &pri) == -1) { perror("mq_receive() returned failure"); unresolved=1; } if (strncmp(msgptr4, msgrcd, strlen(msgptr4)) != 0) { printf("FAIL: sent %s received %s\n", msgptr4, msgrcd); failure = 1; } if (mq_receive(queue, msgrcd, BUFFER, &pri) == -1) { perror("mq_receive() returned failure"); unresolved=1; } if (strncmp(msgptr5, msgrcd, strlen(msgptr5)) != 0) { printf("FAIL: sent %s received %s\n", msgptr5, msgrcd); failure = 1; } if (mq_close(queue) != 0) { perror("mq_close() did not return success"); unresolved=1; } if (mq_unlink(qname) != 0) { perror("mq_unlink() did not return success"); unresolved=1; } if (failure==1) { printf("Test FAILED\n"); return PTS_FAIL; } if (unresolved==1) { printf("Test UNRESOLVED\n"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/mq_send/7-1.c0100644000000000000000000000533510336125321021406 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * Test that if O_NONBLOCK is set and the message queue is full, mq_send() * will just return an error message and the message will not be queued. * * Test by sending messages with increasing priority number until a failure * is received. Then test that the message just sent (highest priority) is * not the one received. * * 3/13/03 - Added fix from Gregoire Pichon for specifying an attr * with a mq_maxmsg >= BUFFER. * */ #include #include #include #include #include #include #include #include #include #include #include "posixtest.h" #define NAMESIZE 50 #define MESSAGESIZE 50 #define MSGSTR "0123456789" #define BUFFER 40 #define MAXMSG 10 // send should end after MAXMSG int main() { char qname[NAMESIZE], msgrcd[BUFFER]; char msgptr[MESSAGESIZE]; mqd_t queue; struct mq_attr attr; int unresolved=0, failure=0, spri=1, i, maxreached=0; unsigned pri; sprintf(qname, "/mq_send_7-1_%d", getpid()); attr.mq_msgsize = BUFFER; attr.mq_maxmsg = MAXMSG; queue = mq_open(qname, O_CREAT | O_RDWR | O_NONBLOCK, S_IRUSR | S_IWUSR, &attr); if (queue == (mqd_t)-1) { perror("mq_open() did not return success"); return PTS_UNRESOLVED; } for (i=0; i mq_send() places the message msg_ptr points to into message queue mqdes mq_send() will fail if msg_len, the message length, is not less than or equal to mq_attr->mq_msgsize. mq_send() will insert the message into the message queue according to msg_prio (if the message queue is not full): - Larger msg_prio values mean the message is inserted before those with lower values. - For messages with equal msg_prio values, the message is inserted after those. msg_prio must be less than MQ_PRIO_MAX If the message queue pointed to by msg_ptr is full and O_NONBLOCK is not set, then mq_send() will block until it can place the message in the queue or until a signal interrupts mq_send(). If there are greater than one threads which are waiting to place a message in the message queue, the thread which will be able to place its message when space is available is the one with the greatest priority that has been waiting the longest if Priority Scheduling is supported. If not, then it is unspecified which thread is able to place its message. If the message queue pointed to by msg_ptr is full and O_NONBLOCK is set, then mq_send() will just return an error and the message will not be queued. mq_send() will return 0 on success. mq_send() will return -1 on failure, no message will be queued, and errno will be set. mq_send() will return EAGAIN if O_NONBLOCK is set and the message queue is full mq_send() will return EBADF if mqdes is not a valid message queue descriptor that is also open for writing mq_send() will return EINTR if it is interrupted by a signal mq_send() will return EINVAL if msg_prio wasn't in the valid range mq_send() will return EMSGSIZE if msg_len is greater than the message queues message size attribute posixtestsuite/conformance/interfaces/mq_send/coverage.txt0100644000000000000000000000036307631437106023301 0ustar rootrootThis document defines the coverage for the mq_send() function. ASSERTION COVERED? 1 YES 2 YES 3 YES 4 YES 5 YES 6 WON'T - will not test as needs Priority Scheduling to finish 7 YES 8 YES 9 YES 10 YES 11 YES 12 YES 13 YES 14 YES posixtestsuite/conformance/interfaces/mq_send/8-1.c0100644000000000000000000000376110336125321021410 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * Test that mq_send() returns 0 on success. * * 3/13/03 - Added fix from Gregoire Pichon for specifying an attr * with a mq_maxmsg >= BUFFER. * */ #include #include #include #include #include #include #include #include "posixtest.h" #define NAMESIZE 50 #define MSGSTR "0123456789" #define BUFFER 40 #define MAXMSG 10 int main() { char qname[NAMESIZE], msgrcd[BUFFER]; const char *msgptr = MSGSTR; mqd_t queue; struct mq_attr attr; int unresolved=0, ret; unsigned pri; sprintf(qname, "/mq_send_8-1_%d", getpid()); attr.mq_msgsize = BUFFER; attr.mq_maxmsg = MAXMSG; queue = mq_open(qname, O_CREAT |O_RDWR, S_IRUSR | S_IWUSR, &attr); if (queue == (mqd_t)-1) { perror("mq_open() did not return success"); return PTS_UNRESOLVED; } ret = mq_send(queue, msgptr, strlen(msgptr), 1); if (mq_receive(queue, msgrcd, BUFFER, &pri) == -1) { perror("mq_receive() returned failure"); unresolved=1; } if (strncmp(msgptr, msgrcd, strlen(msgptr)) != 0) { printf("send was unsuccessful: sent %s received %s\n", msgptr, msgrcd); unresolved = 1; } if (mq_close(queue) != 0) { perror("mq_close() did not return success"); unresolved=1; } if (mq_unlink(qname) != 0) { perror("mq_unlink() did not return success"); unresolved=1; } if (unresolved==1) { printf("Test UNRESOLVED\n"); return PTS_UNRESOLVED; } if (ret != 0) { printf("mq_send() did not return 0 on success\n"); printf("Test FAILED\n"); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/mq_send/4-2.c0100644000000000000000000000307510035502500021375 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * Test that msg_prio cannot be equal to MQ_PRIO_MAX. */ #include #include #include #include #include #include #include #include #include "posixtest.h" #define NAMESIZE 50 #define MSGSTR "0123456789" int main() { char qname[NAMESIZE]; const char *msgptr = MSGSTR; mqd_t queue; int unresolved=0, failure=0; sprintf(qname, "/mq_send_4-2_%d", getpid()); queue = mq_open(qname, O_CREAT |O_RDWR, S_IRUSR | S_IWUSR, NULL); if (queue == (mqd_t)-1) { perror("mq_open() did not return success"); return PTS_UNRESOLVED; } if (mq_send(queue, msgptr, strlen(msgptr), MQ_PRIO_MAX) == 0) { printf("mq_send() returned success with pri = MQ_PRIO_MAX\n"); failure=1; } if (mq_close(queue) != 0) { perror("mq_close() did not return success"); unresolved=1; } if (mq_unlink(qname) != 0) { perror("mq_unlink() did not return success"); unresolved=1; } if (failure==1) { printf("Test FAILED\n"); return PTS_FAIL; } if (unresolved==1) { printf("Test UNRESOLVED\n"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/mq_send/2-1.c0100644000000000000000000000326710035502500021375 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * Test that mq_send() will fail if msg_len is not <= mq_attr->mq_msgsize. */ #include #include #include #include #include #include #include #include "posixtest.h" #define NAMESIZE 50 #define MSGSTR "01234567890123456789" #define MSGSIZE 10 // < strlen(MSGSTR) int main() { char qname[NAMESIZE]; const char *msgptr = MSGSTR; mqd_t queue; int unresolved=0, failure=0; struct mq_attr attr; sprintf(qname, "/mq_send_2-1_%d", getpid()); attr.mq_msgsize = MSGSIZE; attr.mq_maxmsg = MSGSIZE; queue = mq_open(qname, O_CREAT |O_RDWR, S_IRUSR | S_IWUSR, &attr); if (queue == (mqd_t)-1) { perror("mq_open() did not return success"); return PTS_UNRESOLVED; } if (mq_send(queue, msgptr, strlen(msgptr), 1) == 0) { printf("mq_send() returned success when msg_len>=mq_msgsize\n"); failure=1; } if (mq_close(queue) != 0) { perror("mq_close() did not return success"); unresolved=1; } if (mq_unlink(qname) != 0) { perror("mq_unlink() did not return success"); unresolved=1; } if (failure==1) { printf("Test FAILED\n"); return PTS_FAIL; } if (unresolved==1) { printf("Test UNRESOLVED\n"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/mq_send/3-1.c0100644000000000000000000001013110336125321021370 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * Test that mq_send() inserts messages into the message queue according * to the priority given. * Test by inserting multiple messages into the queue not in priority order. * Ensure messages are received in priority order. * * 3/13/03 - Added fix from Gregoire Pichon for specifying an attr * with a mq_maxmsg >= BUFFER. */ #include #include #include #include #include #include #include #include "posixtest.h" #define NAMESIZE 50 #define MSG1 "1234567890" #define PRI1 10 #define MSG2 "234567890" #define PRI2 8 #define MSG3 "34567890" #define PRI3 6 #define MSG4 "4567890" #define PRI4 2 #define MSG5 "567890" #define PRI5 1 #define BUFFER 40 #define MAXMSG 10 int main() { char qname[NAMESIZE], msgrcd[BUFFER]; const char *msgptr1 = MSG1; const char *msgptr2 = MSG2; const char *msgptr3 = MSG3; const char *msgptr4 = MSG4; const char *msgptr5 = MSG5; mqd_t queue; struct mq_attr attr; int unresolved=0, failure=0; unsigned pri; sprintf(qname, "/mq_send_3-1_%d", getpid()); attr.mq_msgsize = BUFFER; attr.mq_maxmsg = MAXMSG; queue = mq_open(qname, O_CREAT |O_RDWR, S_IRUSR | S_IWUSR, &attr); if (queue == (mqd_t)-1) { perror("mq_open() did not return success"); return PTS_UNRESOLVED; } if (mq_send(queue, msgptr3, strlen(msgptr3), PRI3) != 0) { perror("mq_send() did not return success"); failure=1; } if (mq_send(queue, msgptr1, strlen(msgptr1), PRI1) != 0) { perror("mq_send() did not return success"); failure=1; } if (mq_send(queue, msgptr4, strlen(msgptr4), PRI4) != 0) { perror("mq_send() did not return success"); failure=1; } if (mq_send(queue, msgptr2, strlen(msgptr2), PRI2) != 0) { perror("mq_send() did not return success"); failure=1; } if (mq_send(queue, msgptr5, strlen(msgptr5), PRI5) != 0) { perror("mq_send() did not return success"); failure=1; } if (mq_receive(queue, msgrcd, BUFFER, &pri) == -1) { perror("mq_receive() returned failure"); failure=1; } if (strncmp(msgptr1, msgrcd, strlen(msgptr1)) != 0) { printf("FAIL: expected %s received %s\n", msgptr1, msgrcd); failure = 1; } if (mq_receive(queue, msgrcd, BUFFER, &pri) == -1) { perror("mq_receive() returned failure"); failure=1; } if (strncmp(msgptr2, msgrcd, strlen(msgptr2)) != 0) { printf("FAIL: expected %s received %s\n", msgptr2, msgrcd); failure = 1; } if (mq_receive(queue, msgrcd, BUFFER, &pri) == -1) { perror("mq_receive() returned failure"); failure=1; } if (strncmp(msgptr3, msgrcd, strlen(msgptr3)) != 0) { printf("FAIL: expected %s received %s\n", msgptr3, msgrcd); failure = 1; } if (mq_receive(queue, msgrcd, BUFFER, &pri) == -1) { perror("mq_receive() returned failure"); failure=1; } if (strncmp(msgptr4, msgrcd, strlen(msgptr4)) != 0) { printf("FAIL: expected %s received %s\n", msgptr4, msgrcd); failure = 1; } if (mq_receive(queue, msgrcd, BUFFER, &pri) == -1) { perror("mq_receive() returned failure"); failure=1; } if (strncmp(msgptr5, msgrcd, strlen(msgptr5)) != 0) { printf("FAIL: expected %s received %s\n", msgptr5, msgrcd); failure = 1; } if (mq_close(queue) != 0) { perror("mq_close() did not return success"); unresolved=1; } if (mq_unlink(qname) != 0) { perror("mq_unlink() did not return success"); unresolved=1; } if (failure==1) { printf("Test FAILED\n"); return PTS_FAIL; } if (unresolved==1) { printf("Test UNRESOLVED\n"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/signal/0040755000000000000000000000000010515625265020575 5ustar rootrootposixtestsuite/conformance/interfaces/signal/5-1.c0100644000000000000000000000275407641703463021253 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: salwan.searty REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. This program tests the assertion that the signal function shall return the function name of the last signal handler that was associated with sig. How this program tests this assertion is by setting up handlers SIGUSR1_handler and SIGUSR2_handler for signals SIGUSR1 and SIGUSR2 respectively. A third call to signal() is made regarding signal SIGUSR1. If this call returns anything but SIGUSR1_handler, fail the test, otherwise the test passes. */ #include #include #include #include "posixtest.h" void SIGUSR1_handler(int signo) { printf("do nothing useful\n"); } void SIGUSR2_handler(int signo) { printf("do nothing useful\n"); } int main() { if (signal(SIGUSR1, SIGUSR1_handler) == SIG_ERR) { perror("Unexpected error while using signal()"); return PTS_UNRESOLVED; } if (signal(SIGUSR2, SIGUSR2_handler) == SIG_ERR) { perror("Unexpected error while using signal()"); return PTS_UNRESOLVED; } if (signal(SIGUSR1,SIG_IGN) != SIGUSR1_handler) { printf("signal did not return the last handler that was associated with SIGUSR1\n"); return PTS_FAIL; } return PTS_PASS; } posixtestsuite/conformance/interfaces/signal/1-1.c0100644000000000000000000000273307641703463021244 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: salwan.searty REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. This program tests the assertion that the default handling of the signal shall occur if the value of the func parameter is SIG_DFL. How this program tests this assertion by setting up a handler "myhandler" for SIGCHLD. Then another call to signal() is made about SIGCHLD, this time with SIG_DFL as the value of the func parameter. The default action for SIGCHLD is to be ignored, so unless myhandler gets called when SIGCHLD is raised, the test passess, otherwise returns failure. */ #include #include #include #include "posixtest.h" int handler_called = 0; void myhandler(int signo) { printf("SIGCHLD called. Inside handler\n"); handler_called = 1; } int main() { if (signal(SIGCHLD, myhandler) == SIG_ERR) { perror("Unexpected error while using signal()"); return PTS_UNRESOLVED; } if (signal(SIGCHLD,SIG_DFL) != myhandler) { perror("Unexpected error while using signal()"); return PTS_UNRESOLVED; } raise(SIGCHLD); if (handler_called == 1) { printf("Test FAILED: handler was called even though default was expected\n"); return PTS_FAIL; } return PTS_PASS; } posixtestsuite/conformance/interfaces/signal/6-1.c0100644000000000000000000000205707641703463021250 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: salwan.searty REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. This program tests the assertion that signal() shall return SIG_ERR and set errno to a positive value if an invalid signal number was passed to it. */ #include #include #include #include #include "posixtest.h" void myhandler(int signo) { printf("handler does nothing useful.\n"); } int main() { errno = -1; if (signal(-1, myhandler) != SIG_ERR) { printf("Test FAILED: signal() didn't return SIG_ERR even though invalid signal number was passed to it\n"); return PTS_FAIL; } if (errno <= 0) { printf("Test FAILED: errno wasn't set to a positive number even though invalid signal number was passed to the signal() function\n"); return PTS_FAIL; } return PTS_PASS; } posixtestsuite/conformance/interfaces/signal/7-1.c0100644000000000000000000000206607641703463021251 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: salwan.searty REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. This program tests the assertion that signal() shall return SIG_ERR and set errno to a positive value if an invalid signal number was passed to it. */ #include #include #include #include #include "posixtest.h" void myhandler(int signo) { printf("handler does nothing useful.\n"); } int main() { errno = -1; if (signal(SIGKILL, myhandler) != SIG_ERR) { printf("Test FAILED: signal() didn't return SIG_ERR even though a non-catchable signal was passed to it\n"); return PTS_FAIL; } if (errno <= 0) { printf("Test FAILED: errno wasn't set to a positive number even though a non-catchable signal was passed to the signal() function\n"); return PTS_FAIL; } return PTS_PASS; } posixtestsuite/conformance/interfaces/signal/assertions.xml0100644000000000000000000000235707641703463023520 0ustar rootroot Default handling for that signal shall occur, if the value of func is SIG_DFL. The signal shall be ingnored if the value of func is SIG_IGN. When a signal occurs, and func points to a function, the equivalent of: (*func)(sig); is executed. If and when the signal handler returns, the program shall resume execution at the point it was interrupted. If the handler is called, signal() shall return the value of func of the last call to signal() that pertains to the specified signal sig. The signal( ) function shall return SIG_ERR, and set errno to EINVAL if the sig argument passed to signal() is not a valid signal number if an attempt is made to catch a signal that cannot be caught or ignore a signal that cannot be ignored. posixtestsuite/conformance/interfaces/signal/coverage.txt0100644000000000000000000000023307641703463023127 0ustar rootrootThis document defines the coverage for function signal(). Assertion Covered? 1 YES 2 YES 3 YES 4 IMPLICITLY tested by all tests. 5 YES 6 YES 7 YES posixtestsuite/conformance/interfaces/signal/2-1.c0100644000000000000000000000266607641703463021252 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: salwan.searty REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. This program tests the assertion that the signal shall be ignored if the value of the func parameter is SIG_IGN. How this program tests this assertion is by setting up a handler "myhandler" for SIGCHLD. Then another call to signal() is made about SIGCHLD, this time with SIG_IGN as the value of the func parameter. SIGCHLD should be ignored now, so unless myhandler gets called when SIGCHLD is raised, the test passes, otherwise returns failure. */ #include #include #include #include "posixtest.h" int handler_called = 0; void myhandler(int signo) { printf("SIGCHLD called. Inside handler\n"); handler_called = 1; } int main() { if (signal(SIGCHLD, myhandler) == SIG_ERR) { perror("Unexpected error while using signal()"); return PTS_UNRESOLVED; } if (signal(SIGCHLD,SIG_IGN) != myhandler) { perror("Unexpected error while using signal()"); return PTS_UNRESOLVED; } raise(SIGCHLD); if (handler_called == 1) { printf("Test FAILED: handler was called even though default was expected\n"); return PTS_FAIL; } return PTS_PASS; } posixtestsuite/conformance/interfaces/signal/3-1.c0100644000000000000000000000220607641703463021241 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: salwan.searty REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. This program tests the assertion that the signal shall be ignored if the value of the func parameter is SIG_IGN. How this program tests this assertion is by setting up a handler "myhandler" for SIGCHLD, and then raising that signal. If the handler_called variable is anything but 1, then fail, otherwise pass. */ #include #include #include #include "posixtest.h" int handler_called = 0; void myhandler(int signo) { printf("SIGCHLD called. Inside handler\n"); handler_called = 1; } int main() { if (signal(SIGCHLD, myhandler) == SIG_ERR) { perror("Unexpected error while using signal()"); return PTS_UNRESOLVED; } raise(SIGCHLD); if (handler_called != 1) { printf("Test FAILED: handler was called even though default was expected\n"); return PTS_FAIL; } return PTS_PASS; } posixtestsuite/conformance/interfaces/raise/0040755000000000000000000000000010515625231020414 5ustar rootrootposixtestsuite/conformance/interfaces/raise/4-1.c0100644000000000000000000000314607616603013021064 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Assertion 4 - that raise() is equivalent to kill(getpid(), sig); is * essentially tested implicitly via assertion 1. * This test is the reverse test case: Test assertion 1, but replace * raise() with kill(getpid(), sig). It should pass if assertion 1 * passes. * 1) Set up a signal handler for the signal that says we have caught the * signal. * 2) Call kill(getpid(), ) * 3) If signal handler was called, test passed. * This test is only performed on one signal. All other signals are * considered to be in the same equivalence class. */ #include #include #include #include #include #include "posixtest.h" #define SIGTOTEST SIGABRT void handler(int signo) { printf("Caught signal being tested!\n"); printf("Test PASSED\n"); exit(0); } int main() { struct sigaction act; act.sa_handler=handler; act.sa_flags=0; if (sigemptyset(&act.sa_mask) == -1) { perror("Error calling sigemptyset\n"); return PTS_UNRESOLVED; } if (sigaction(SIGTOTEST, &act, 0) == -1) { perror("Error calling sigaction\n"); return PTS_UNRESOLVED; } if (kill(getpid(), SIGTOTEST) != 0) { printf("Could not call kill\n"); return PTS_UNRESOLVED; } printf("Should have exited from signal handler\n"); printf("Test FAILED\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/raise/1-1.c0100644000000000000000000000256207616603013021062 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that the raise() function shall send the signal * to the executing process. * 1) Set up a signal handler for the signal that says we have caught the * signal. * 2) Raise the signal. * 3) If signal handler was called, test passed. * This test is only performed on one signal. All other signals are * considered to be in the same equivalence class. */ #include #include #include #include "posixtest.h" #define SIGTOTEST SIGABRT void handler(int signo) { printf("Caught signal being tested!\n"); printf("Test PASSED\n"); exit(0); } int main() { struct sigaction act; act.sa_handler=handler; act.sa_flags=0; if (sigemptyset(&act.sa_mask) == -1) { perror("Error calling sigemptyset\n"); return PTS_UNRESOLVED; } if (sigaction(SIGTOTEST, &act, 0) == -1) { perror("Error calling sigaction\n"); return PTS_UNRESOLVED; } if (raise(SIGTOTEST) != 0) { printf("Could not raise signal being tested\n"); return PTS_FAIL; } printf("Should have exited from signal handler\n"); printf("Test FAILED\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/raise/6-1.c0100644000000000000000000000134507616603013021065 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that the raise() function sends a non-zero value on * unsuccessful completion. * 1) Raise an invalid signal. * 2) Verify a non-zero value is returned. */ #include #include #include #include #include "posixtest.h" int main() { if (raise(10000) == 0) { printf("Incorrectly returned 0\n"); printf("Test FAILED\n"); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/raise/1-2.c0100644000000000000000000000522110204137612021050 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that the raise() function shall send the signal * to the executing process when the executing process is a child * process. * 1) Set up a signal handler for a signal in the parent process. * This handler returns failure if called. * 2) Fork a child process. * 2) In the child process: * 3) Set up a signal handler for the same signal as in the parent process. * This handler returns success if called. * 4) Raise the signal. * 5) If signal handler was called, return 1 (so WEXITSTATUS can test * for success). * 6) In parent, if 1 was received, test passed. * This test is only performed on one signal. All other signals are * considered to be in the same equivalence class. */ #include #include #include #include #include #include #include "posixtest.h" #define SIGTOTEST SIGABRT void parenthandler(int signo) { printf("Caught signal from parent!\n"); exit(-1); } void childhandler(int signo) { printf("Caught signal from child!\n"); exit(0); } int main() { struct sigaction parentact; parentact.sa_handler=parenthandler; parentact.sa_flags=0; if (sigemptyset(&parentact.sa_mask) == -1) { perror("Error calling sigemptyset\n"); return PTS_UNRESOLVED; } if (sigaction(SIGTOTEST, &parentact, 0) == -1) { perror("Error calling sigaction\n"); return PTS_UNRESOLVED; } if (fork() == 0) { /* child here */ struct sigaction childact; childact.sa_handler=childhandler; childact.sa_flags=0; if (sigemptyset(&childact.sa_mask) == -1) { perror("Error calling sigemptyset\n"); return PTS_UNRESOLVED; } if (sigaction(SIGTOTEST, &childact, 0) == -1) { perror("Error calling sigaction\n"); return PTS_UNRESOLVED; } if (raise(SIGTOTEST) != 0) { printf("Could not raise signal being tested\n"); return PTS_FAIL; } printf("Should have exited from signal handler\n"); return PTS_FAIL; } else { /* parent here */ int i; if (wait(&i) == -1) { perror("Error waiting for child to exit\n"); return PTS_UNRESOLVED; } if (!WEXITSTATUS(i)) { printf("Child exited normally\n"); printf("Test PASSED\n"); return PTS_PASS; } else { printf("Child did not exit normally.\n"); printf("Test FAILED\n"); return PTS_FAIL; } } printf("Should not make it here.\n"); return PTS_UNRESOLVED; } posixtestsuite/conformance/interfaces/raise/7-1.c0100644000000000000000000000155607616603013021072 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that the raise() sets errno to indicate the error on * unsuccessful completion. * 1) Raise an invalid signal. * 2) Verify a non-zero value is returned. * 3) Verify errno is set to EINVAL. */ #include #include #include #include #include "posixtest.h" int main() { if (raise(10000) == 0) { printf("Incorrectly returned 0\n"); printf("Test FAILED\n"); return PTS_FAIL; } if (EINVAL == errno) { printf("Test PASSED\n"); return PTS_PASS; } else { printf("errno not correctly set\n"); return PTS_FAIL; } } posixtestsuite/conformance/interfaces/raise/assertions.xml0100644000000000000000000000251210202150617023317 0ustar rootroot The raise() function sends signal sig to the thread or process currently executing. If the signal causes a signal handler to be called, the raise() function will wait for the signal handler to return before it returns. If the implementation supports Threads, then raise() is equivalent to: pthread_kill(pthread_self(), sig); If the implementation does not support threads, then raise() is equivalent to: kill(getpid(), sig); Upon successful completion, raise() returns 0. Upon unsuccessful completion, raise() returns a non-zero value. Upon unsuccessful completion, raise() sets errno to indicate the error. The only defined value of errno for raise() is EINVAL if the value of the sig argument is an invalid signal number. Multiple assertions tested. posixtestsuite/conformance/interfaces/raise/10000-1.c0100644000000000000000000000554407616603013021365 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * General API test of the raise() function. * Test calling raise with the following values: * - MINIMUM valid (in this case SIGABRT signal) * - MAXIMUM valid (in this case SIGXFSZ signal) * Item with POSIX default action as T - SIGALRM * Item with POSIX default action as A - (done - SIGABRT) * Item with POSIX default action as I - SIGCHLD * Item with POSIX default action as S - SIGTSTP * Item with POSIX default action as C - SIGCONT * * Error conditions: * Boundary values for int * MIN INT = INT32_MIN * MAX INT = INT32_MAX * MIN INT - 1 = 2147483647 (this is what gcc will set to) * MAX INT + 1 = -2147483647 (this is what gcc will set to) * unassigned value = -1073743192 (ex. of what gcc will set to) * unassigned value = 1073743192 (ex. of what gcc will set to) * * Steps: * 1) Set up signal handlers for all valid signals * 2) Call all valid signals and verify they are received. * 3) Call all invalid signals and verify raise() returns 0 and sets * errno to EINVAL. * * Note: This test case maps to multiple assertions: 1, 2 (implicitly), * 5, 6, 7, so it was given a large number as a file name. */ #include #include #include #include #include #include "posixtest.h" #define NUMVALIDTESTS 6 #define NUMINVALIDTESTS 6 static int valid_tests[NUMVALIDTESTS] = { SIGABRT, SIGXFSZ, SIGALRM, SIGCHLD, SIGTSTP, SIGCONT }; static int invalid_tests[NUMINVALIDTESTS] = { INT32_MIN, INT32_MAX, 2147483647, -2147483647, -1073743192, 1073743192 }; void handler(int signo) { printf("Caught signal being tested!\n"); } int main() { int i; int failure = 0; struct sigaction act; act.sa_handler=handler; act.sa_flags=0; if (sigemptyset(&act.sa_mask) == -1) { perror("Error calling sigemptyset\n"); return PTS_UNRESOLVED; } for (i = 0; i < NUMVALIDTESTS; i++) { if (sigaction(valid_tests[i], &act, 0) == -1) { perror("Error calling sigaction\n"); return PTS_UNRESOLVED; } } for (i = 0; i < NUMVALIDTESTS; i++) { if (raise(valid_tests[i]) != 0) { printf("Could not raise signal being tested\n"); failure = 1; } } for (i = 0; i < NUMINVALIDTESTS; i++) { if (raise(invalid_tests[i]) == 0) { printf("Received success raising an invalid signal\n"); failure = 1; } else { if (EINVAL == errno) { printf("errno correctly set\n"); } else { printf("errno not correctly set\n"); failure = 1; } } } if (failure) { printf("At least one test FAILED -- see above\n"); return PTS_FAIL; } else { printf("All tests PASSED\n"); return PTS_PASS; } } posixtestsuite/conformance/interfaces/raise/coverage.txt0100644000000000000000000000065607616603013022756 0ustar rootrootThe current coverage of this suite is limited to testing raise() on processes. The threads items that could be added later are: - Test assertion 1 for threads. - Test assertion 3. This document defines the coverage for function raise(). Assertion Covered? 1 YES, only covering processes, not threads 2 YES 3 WON'T test for now since it is specific to threads 4 YES 5 IMPLICITLY tested by testing assertion 1 6 YES 7 YES posixtestsuite/conformance/interfaces/raise/2-1.c0100644000000000000000000000367107616603013021065 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that the the raise() function does not return until after the * signal handler it calls returns. * This test is only performed on one signal. All other signals are * considered to be in the same equivalence class. */ #include #include #include #include #include #include "posixtest.h" #define SIGTOTEST SIGABRT /* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Declare a global variable to keep track of where we were. */ #define BEFOREHANDLER 1 #define INHANDLER 2 #define LEAVINGHANDLER 3 int globalStatus = BEFOREHANDLER; void handler(int signo) { globalStatus = INHANDLER; printf("Caught signal being tested!\n"); printf("Sleeping...\n"); sleep(2); globalStatus = LEAVINGHANDLER; } int main() { struct sigaction act; act.sa_handler=handler; act.sa_flags=0; if (sigemptyset(&act.sa_mask) == -1) { perror("Error calling sigemptyset\n"); return PTS_UNRESOLVED; } if (sigaction(SIGTOTEST, &act, 0) == -1) { perror("Error calling sigaction\n"); return PTS_UNRESOLVED; } if (raise(SIGTOTEST) != 0) { printf("Could not raise signal being tested\n"); return PTS_FAIL; } if ( (INHANDLER == globalStatus) || (BEFOREHANDLER == globalStatus) ) { printf("Test FAILED\n"); return PTS_FAIL; } if (LEAVINGHANDLER == globalStatus) { printf ("Test PASSED\n"); return PTS_PASS; } printf("Should not reach here\n"); return PTS_UNRESOLVED; } posixtestsuite/conformance/interfaces/sighold/0040755000000000000000000000000010515625265020751 5ustar rootrootposixtestsuite/conformance/interfaces/sighold/3-4.sh0100755000000000000000000000063007631516123021604 0ustar rootroot#!/bin/sh # Copyright (c) 2003, Intel Corporation. All rights reserved. # Created by: salwan.searty REMOVE-THIS AT intel DOT com # This file is licensed under the GPL license. For the full content # of this license, see the COPYING file at the top level of this # source tree. # # # Test various methods of passing invalid signals to sighold(). # conformance/interfaces/sighold/3-core-buildonly.test 4 posixtestsuite/conformance/interfaces/sighold/3-3.sh0100755000000000000000000000063007631516123021603 0ustar rootroot#!/bin/sh # Copyright (c) 2003, Intel Corporation. All rights reserved. # Created by: salwan.searty REMOVE-THIS AT intel DOT com # This file is licensed under the GPL license. For the full content # of this license, see the COPYING file at the top level of this # source tree. # # # Test various methods of passing invalid signals to sighold(). # conformance/interfaces/sighold/3-core-buildonly.test 3 posixtestsuite/conformance/interfaces/sighold/3-1.sh0100755000000000000000000000062607631516123021606 0ustar rootroot#!/bin/sh # Copyright (c) 2003, Intel Corporation. All rights reserved. # Created by: salwan.searty REMOVE-THIS AT intel DOT com # This file is licensed under the GPL license. For the full content # of this license, see the COPYING file at the top level of this # source tree. # # Test various methods of adding invalid signals to sighold(). # conformance/interfaces/sighold/3-core-buildonly.test 1 posixtestsuite/conformance/interfaces/sighold/1-1.c0100644000000000000000000000260407633460671021417 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: salwan.searty REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Steps: 1. Set up a handler for signal SIGABRT, such that it is called if signal is ever raised. 2. Call sighold on that SIGABRT. 3. Raise a SIGABRT and verify that the signal handler was not called. */ #define _XOPEN_SOURCE 600 #include #include #include #include "posixtest.h" int handler_called = 0; void handler(int signo) { handler_called = 1; } int main() { struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); if (sigaction(SIGABRT, &act, 0) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (sighold(SIGABRT) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (raise(SIGABRT) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } sleep(1); if (handler_called) { printf("FAIL: Signal was not blocked\n"); return PTS_FAIL; } printf("Test PASSED: signal was blocked\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/sighold/3-2.sh0100755000000000000000000000063107631516123021603 0ustar rootroot#!/bin/sh # Copyright (c) 2003, Intel Corporation. All rights reserved. # Created by: salwan.searty REMOVE-THIS AT intel DOT com # This file is licensed under the GPL license. For the full content # of this license, see the COPYING file at the top level of this # source tree. # # # Test various methods of passing invalid signals to sighold(). # conformance/interfaces/sighold/3-core-buildonly.test 2 posixtestsuite/conformance/interfaces/sighold/3-core-buildonly.c0100644000000000000000000000434207656062151024205 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: salwan.searty REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Testing passing an invalid signals to sighold(). After sighold is called on an invalid signal, sighold() should return -1 and set errno to EINVAL The invalid signal passed to sighold() depends on the argument passed to this program. There are currently 4 invalid signals. */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include "posixtest.h" jmp_buf sig11_recover; void sig11_handler(int sig); int main(int argc, char *argv[]) { int signo, TEST_RETURN; struct sigaction sa, osa; if (argc < 2) { printf("Usage: %s [1|2|3|4]\n", argv[0]); return PTS_UNRESOLVED; } /* Various error conditions */ switch (argv[1][0]) { case '1': signo=-1; break; case '2': signo=-10000; break; case '3': signo=INT32_MIN+1; break; case '4': signo=INT32_MIN; break; default: printf("Usage: %s [1|2|3|4]\n", argv[0]); return PTS_UNRESOLVED; } /* special sig11 case */ sa.sa_handler = &sig11_handler; sigemptyset(&sa.sa_mask); sa.sa_flags = 0; sigaction(SIGSEGV, NULL, &osa); sigaction(SIGSEGV, &sa, NULL); if (setjmp(sig11_recover)) { errno = EINVAL; TEST_RETURN=-2; } else { TEST_RETURN=sighold(signo); } sigaction(SIGSEGV, &osa, NULL); if (TEST_RETURN == -1) { if (EINVAL == errno) { printf ("errno set to EINVAL\n"); return PTS_PASS; } else { printf ("errno not set to EINVAL\n"); return PTS_FAIL; } } if (TEST_RETURN == -2) { printf ("test received SIGSEGV\n"); return PTS_UNRESOLVED; } printf("sighold did not return -1\n"); return PTS_FAIL; } /****************************************************************** * sig11_handler() - our segfault recover hack ******************************************************************/ void sig11_handler(int sig) { longjmp(sig11_recover, 1); } posixtestsuite/conformance/interfaces/sighold/assertions.xml0100644000000000000000000000075307631516123023664 0ustar rootroot The sighold () function adds a signal sig to the signal mask of the calling process. sighold will return 0 upon successful completion. If the function is passed an illegal signal number, then errno will be set to [EINVAL], and sighold() will return -1. posixtestsuite/conformance/interfaces/sighold/coverage.txt0100644000000000000000000000014407631516123023276 0ustar rootrootThis document defines the coverage for function sighold(). Assertion Covered? 1 YES 2 YES 3 YES posixtestsuite/conformance/interfaces/sighold/2-1.c0100644000000000000000000000114407631516123021406 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: salwan.searty REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Simply, if sighold returns a 0 here, test passes. */ #define _XOPEN_SOURCE 600 #include #include #include "posixtest.h" int main() { if ((int)sighold(SIGABRT) != 0) { perror("sighold failed -- returned -- test aborted"); return PTS_UNRESOLVED; } printf("sighold passed\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_attr_destroy/0040755000000000000000000000000010515625176023553 5ustar rootrootposixtestsuite/conformance/interfaces/pthread_attr_destroy/1-1.c0100644000000000000000000000432407636750514024222 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_attr_destroy() * shall destory a thread attributes object. An implementation may cause * pthread_attr_destroy() to set 'attr' to an implementation-defined invalid * value. * * Steps: * 1. Initialize a pthread_attr_t object using pthread_attr_init() * 2. Destroy that initialized attribute using pthread_attr_destroy() * 3. Using pthread_attr_create(), pass to it the destroyed attribute. It * should return the error EINVAL, the value specified by 'attr' is * is invalid. * */ #include #include #include #include "posixtest.h" void *a_thread_func() { pthread_exit(0); return NULL; } int main() { pthread_t new_th; pthread_attr_t new_attr; int ret; /* Initialize attribute */ if(pthread_attr_init(&new_attr) != 0) { perror("Cannot initialize attribute object\n"); return PTS_UNRESOLVED; } /* Destroy attribute */ if(pthread_attr_destroy(&new_attr) != 0) { perror("Cannot destroy the attribute object\n"); return PTS_UNRESOLVED; } /* Creating a thread, passing to it the destroyed attribute, should * result in an error value of EINVAL (invalid 'attr' value). */ ret=pthread_create(&new_th, &new_attr, a_thread_func, NULL); if(ret==EINVAL) { printf("Test PASSED\n"); return PTS_PASS; } else if((ret != 0) && ((ret == EPERM) || (ret == EAGAIN))) { perror("Error created a new thread\n"); return PTS_UNRESOLVED; } else if(ret==0) { printf("Test PASSED: NOTE*: Though returned 0 when creating a thread with a destroyed attribute, this behavior is compliant with garbage-in-garbage-out. \n"); return PTS_PASS; } else { printf("Test FAILED: (1) Incorrect return code from pthread_create(); %d not EINVAL or (2) Error in pthread_create()'s behavior in returning error codes \n", ret); return PTS_FAIL; } } posixtestsuite/conformance/interfaces/pthread_attr_destroy/assertions.xml0100644000000000000000000000122207621010443026446 0ustar rootroot The function int pthread_attr_destroy(pthread_attr_t *attr) destorys a thread attributes object. An implementation may cause pthread_attr_destroy() to set 'attr' to an implementation-defined invalid value. A destroyed 'attr' attributes object can be reinitialized using pthread_attr_init(); undefined results referencing the object after it has been destroyed. If success, pthread_attr_destroy() shall return a 0. posixtestsuite/conformance/interfaces/pthread_attr_destroy/coverage.txt0100644000000000000000000000057307607416050026106 0ustar rootrootThis document defines the coverage for the pthread_attr_destroy function: Assertion Tested? 1 YES *Fails on the implementation of threads that I'm working on. 2 YES 3 YES Note: pthread_attr_destroy leaves a lot up to the implementation of threads that you are testing on. For instance, on the implementation that I'm working on, pthread_attr_destroy() does nothing. posixtestsuite/conformance/interfaces/pthread_attr_destroy/2-1.c0100644000000000000000000000253007607416050024210 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * A destroyed 'attr' attributes object can be reinitialized using * pthread_attr_init(); the results of otherwise referencing the object * after it has been destroyed are undefined. * * Steps: * 1. Initialize a pthread_attr_t object using pthread_attr_init() * 2. Destroy that initialized attribute using pthread_attr_destroy() * 3. Initialize the pthread_attr_t object again. This should not result * in an error. * */ #include #include #include #include "posixtest.h" int main() { pthread_attr_t new_attr; /* Initialize attribute */ if(pthread_attr_init(&new_attr) != 0) { perror("Cannot initialize attribute object\n"); return PTS_UNRESOLVED; } /* Destroy attribute */ if(pthread_attr_destroy(&new_attr) != 0) { perror("Cannot destroy the attribute object\n"); return PTS_UNRESOLVED; } /* Initialize attribute. This shouldn't result in an error. */ if(pthread_attr_init(&new_attr) != 0) { printf("Test FAILED\n"); return PTS_FAIL; } else { printf("Test PASSED\n"); return PTS_PASS; } } posixtestsuite/conformance/interfaces/pthread_attr_destroy/3-1.c0100644000000000000000000000176307607416050024220 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Upon successful completion, pthread_attr_destroy() shall return a value of 0. * * Steps: * 1. Initialize a pthread_attr_t object using pthread_attr_init() * 2. Destroy that initialized attribute using pthread_attr_destroy(). * This should return 0; * */ #include #include #include #include "posixtest.h" int main() { pthread_attr_t new_attr; /* Initialize attribute */ if(pthread_attr_init(&new_attr) != 0) { perror("Cannot initialize attribute object\n"); return PTS_UNRESOLVED; } /* Destroy attribute */ if(pthread_attr_destroy(&new_attr) != 0) { printf("Test FAILED\n"); return PTS_FAIL; } else { printf("Test PASSED\n"); return PTS_PASS; } } posixtestsuite/conformance/interfaces/aio_return/0040755000000000000000000000000010515625160021461 5ustar rootrootposixtestsuite/conformance/interfaces/aio_return/4-1.c0100644000000000000000000000425210247562115022130 0ustar rootroot/* * Copyright (c) 2004, Bull SA. All rights reserved. * Created by: Laurent.Vivier@bull.net * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * assertion: * * aio_return() may fail with [EINVAL] * If the aiocbp does not refer to an operation whose return status * has not yet been retrieved. * * method: * * - Open a file * - fill in an aiocb for writing * - call aio_write usign this aiocb * - fill in a new aiocb * - call aio_return with this last aiocb */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include "posixtest.h" #define TNAME "aio_return/4-1.c" int main() { char tmpfname[256]; #define BUF_SIZE 111 char buf[BUF_SIZE]; int fd; struct aiocb aiocb; struct aiocb aiocb2; int retval; #if _POSIX_ASYNCHRONOUS_IO != 200112L exit(PTS_UNSUPPORTED); #endif snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_aio_return_2_1_%d", getpid()); unlink(tmpfname); fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL, S_IRUSR | S_IWUSR); if (fd == -1) { printf(TNAME " Error at open(): %s\n", strerror(errno)); exit(PTS_UNRESOLVED); } unlink(tmpfname); memset(buf, 0xaa, BUF_SIZE); memset(&aiocb, 0, sizeof(struct aiocb)); aiocb.aio_fildes = fd; aiocb.aio_buf = buf; aiocb.aio_nbytes = BUF_SIZE; if (aio_write(&aiocb) == -1) { printf(TNAME " Error at aio_write(): %s\n", strerror(errno)); exit(PTS_FAIL); } close(fd); do { retval = aio_error( &aiocb); if (retval == -1) { printf(TNAME " Error at aio_error(): %s\n", strerror(errno)); exit(PTS_FAIL); } } while (retval == EINPROGRESS); aiocb2.aio_fildes = fd; aiocb2.aio_buf = buf; aiocb2.aio_nbytes = BUF_SIZE; retval = aio_return(&aiocb2); if (retval != -1) { printf(TNAME " aio_return() should fail\n"); exit(PTS_FAIL); } retval = aio_return(&aiocb); if (retval != BUF_SIZE) { printf(TNAME " Error at aio_return(): %d, %s\n", retval, strerror(errno)); exit(PTS_FAIL); } close(fd); printf ("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/aio_return/1-1.c0100644000000000000000000000365510247562115022133 0ustar rootroot/* * Copyright (c) 2004, Bull SA. All rights reserved. * Created by: Laurent.Vivier@bull.net * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * assertion: * * aio_return() shall return the status associated with aiocbp. * * method: * * - open a file * - fill in an aiocb for writing * - call aio_write using this aiocb * - call aio_return to get the aiocb status (number of bytes written) * */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include #include #include #include "posixtest.h" #define TNAME "aio_return/1-1.c" int main() { char tmpfname[256]; #define BUF_SIZE 111 char buf[BUF_SIZE]; int fd; struct aiocb aiocb; int retval; #if _POSIX_ASYNCHRONOUS_IO != 200112L exit(PTS_UNSUPPORTED); #endif snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_aio_return_1_1_%d", getpid()); unlink(tmpfname); fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL, S_IRUSR | S_IWUSR); if (fd == -1) { printf(TNAME " Error at open(): %s\n", strerror(errno)); exit(PTS_UNRESOLVED); } unlink(tmpfname); memset(buf, 0xaa, BUF_SIZE); memset(&aiocb, 0, sizeof(struct aiocb)); aiocb.aio_fildes = fd; aiocb.aio_buf = buf; aiocb.aio_nbytes = BUF_SIZE; if (aio_write(&aiocb) == -1) { printf(TNAME " Error at aio_write(): %s\n", strerror(errno)); exit(PTS_FAIL); } close(fd); do { retval = aio_error( &aiocb); if (retval == -1) { printf(TNAME " Error at aio_error(): %s\n", strerror(errno)); exit(PTS_FAIL); } } while (retval == EINPROGRESS); retval = aio_return(&aiocb); if (retval != BUF_SIZE) { printf(TNAME " Error at aio_return(): %s\n", strerror(errno)); exit(PTS_FAIL); } printf ("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/aio_return/3-2.c0100644000000000000000000000431410247562115022127 0ustar rootroot/* * Copyright (c) 2004, Bull SA. All rights reserved. * Created by: Laurent.Vivier@bull.net * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * assertion: * * If the aiocbp is used to submit another asynchronous operation, * then aio_return may be successfully used to retrieve the return status. * * method: * * - open a file * - fill in an aiocb for writing * - call aio_write using this aiocb * - call aio_return to get the aiocb status (number of bytes written) * - call aio_return again, return status should be -1 */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include #include #include #include "posixtest.h" #define TNAME "aio_return/3-2.c" int main() { char tmpfname[256]; #define BUF_SIZE 4096 char buf[BUF_SIZE]; int fd; struct aiocb aiocb; int retval; #if _POSIX_ASYNCHRONOUS_IO != 200112L exit(PTS_UNSUPPORTED); #endif snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_aio_return_3_2_%d", getpid()); unlink(tmpfname); fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL, S_IRUSR | S_IWUSR); if (fd == -1) { printf(TNAME " Error at open(): %s\n", strerror(errno)); exit(PTS_UNRESOLVED); } unlink(tmpfname); memset(buf, 0xaa, BUF_SIZE); memset(&aiocb, 0, sizeof(struct aiocb)); aiocb.aio_fildes = fd; aiocb.aio_buf = buf; aiocb.aio_nbytes = BUF_SIZE; if (aio_write(&aiocb) == -1) { printf(TNAME " Error at aio_write(): %s\n", strerror(errno)); exit(PTS_FAIL); } do { retval = aio_error( &aiocb); if (retval == -1) { printf(TNAME " Error at aio_error(): %s\n", strerror(errno)); exit(PTS_FAIL); } } while (retval == EINPROGRESS); retval = aio_return(&aiocb); if (retval != BUF_SIZE) { printf(TNAME " Error at aio_return(): %d, %s\n", retval, strerror(errno)); exit(PTS_FAIL); } retval = aio_return(&aiocb); if ( (retval != -1) && (errno != EINVAL) ) { printf(TNAME " aio_return() should fail\n"); exit(PTS_FAIL); } close(fd); printf ("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/aio_return/assertions.xml0100644000000000000000000000125710245504305024374 0ustar rootroot aio_return() shall return the status associated with aiocbp. aio_return() may be called exactly once to retrieve the return status. If the aiocbp is used to submit another asynchronous operation, then aio_return may be successfully used to retrieve the return status. aio_return() may fail with EINVAL]: if the aiocbp does not refer to an operation whose return status has not yet been retrieved. posixtestsuite/conformance/interfaces/aio_return/coverage.txt0100644000000000000000000000016610245504305024012 0ustar rootrootthis file defines the coverage for the aio_return() function testing. Assertion Covered? 1 YES 2 YES 3 YES 4 YES posixtestsuite/conformance/interfaces/aio_return/2-1.c0100644000000000000000000000411610247562115022125 0ustar rootroot/* * Copyright (c) 2004, Bull SA. All rights reserved. * Created by: Laurent.Vivier@bull.net * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * assertion: * * aio_return() may be called exactly once to retrieve the return status. * * method: * * - open a file * - fill in an aiocb for writing * - call aio_write using this aiocb * - call aio_return to get the aiocb status (number of bytes written) * - call aio_return again, return status should be -1 */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include "posixtest.h" #define TNAME "aio_return/2-1.c" int main() { char tmpfname[256]; #define BUF_SIZE 111 char buf[BUF_SIZE]; int fd; struct aiocb aiocb; int retval; #if _POSIX_ASYNCHRONOUS_IO != 200112L exit(PTS_UNSUPPORTED); #endif snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_aio_return_2_1_%d", getpid()); unlink(tmpfname); fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL, S_IRUSR | S_IWUSR); if (fd == -1) { printf(TNAME " Error at open(): %s\n", strerror(errno)); exit(PTS_UNRESOLVED); } unlink(tmpfname); memset(buf, 0xaa, BUF_SIZE); memset(&aiocb, 0, sizeof(struct aiocb)); aiocb.aio_fildes = fd; aiocb.aio_buf = buf; aiocb.aio_nbytes = BUF_SIZE; if (aio_write(&aiocb) == -1) { printf(TNAME " Error at aio_write(): %s\n", strerror(errno)); exit(PTS_FAIL); } close(fd); do { retval = aio_error( &aiocb); if (retval == -1) { printf(TNAME " Error at aio_error(): %s\n", strerror(errno)); exit(PTS_FAIL); } } while (retval == EINPROGRESS); retval = aio_return(&aiocb); if (retval != BUF_SIZE) { printf(TNAME " Error at aio_return(): %s\n", strerror(errno)); exit(PTS_FAIL); } retval = aio_return(&aiocb); if (retval != -1) { printf(TNAME " Second call to aio_return() should return -1 : %d\n", retval); exit(PTS_FAIL); } printf ("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/aio_return/3-1.c0100644000000000000000000000535610247562115022135 0ustar rootroot/* * Copyright (c) 2004, Bull SA. All rights reserved. * Created by: Laurent.Vivier@bull.net * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * assertion: * * If the aiocbp is used to submit another asynchronous operation, * then aio_return may be successfully used to retrieve the return status. * * method: * * - open a file * - fill in an aiocb for writing * - call aio_write using this aiocb * - call aio_return to get the aiocb status (number of bytes written) * - reuse the aiocb for writing * - call aio_write using this aiocb * - call aio_return to get the aiocb status (number of bytes written) */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include #include #include #include "posixtest.h" #define TNAME "aio_return/3-1.c" int main() { char tmpfname[256]; #define BUF_SIZE 4096 char buf[BUF_SIZE]; int fd; struct aiocb aiocb; int retval; #if _POSIX_ASYNCHRONOUS_IO != 200112L exit(PTS_UNSUPPORTED); #endif snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_aio_return_3_1_%d", getpid()); unlink(tmpfname); fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL, S_IRUSR | S_IWUSR); if (fd == -1) { printf(TNAME " Error at open(): %s\n", strerror(errno)); exit(PTS_UNRESOLVED); } unlink(tmpfname); memset(buf, 0xaa, BUF_SIZE); memset(&aiocb, 0, sizeof(struct aiocb)); aiocb.aio_fildes = fd; aiocb.aio_buf = buf; aiocb.aio_nbytes = BUF_SIZE; if (aio_write(&aiocb) == -1) { printf(TNAME " Error at aio_write(): %s\n", strerror(errno)); exit(PTS_FAIL); } do { retval = aio_error( &aiocb); if (retval == -1) { printf(TNAME " Error at aio_error(): %s\n", strerror(errno)); exit(PTS_FAIL); } } while (retval == EINPROGRESS); retval = aio_return(&aiocb); if (retval != BUF_SIZE) { printf(TNAME " Error at aio_return(): %d, %s\n", retval, strerror(errno)); exit(PTS_FAIL); } memset(&aiocb, 0, sizeof(struct aiocb)); aiocb.aio_fildes = fd; aiocb.aio_buf = buf; aiocb.aio_nbytes = BUF_SIZE/2; if (aio_write(&aiocb) == -1) { printf(TNAME " Error at aio_write(): %s\n", strerror(errno)); exit(PTS_FAIL); } do { retval = aio_error( &aiocb); if (retval == -1) { printf(TNAME " Error at aio_error(): %s\n", strerror(errno)); exit(PTS_FAIL); } } while (retval == EINPROGRESS); close(fd); retval = aio_return(&aiocb); if (retval != BUF_SIZE / 2) { printf(TNAME " Error at aio_return(): %d, %s\n", retval, strerror(errno)); exit(PTS_FAIL); } printf ("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/sigpending/0040755000000000000000000000000010515625265021447 5ustar rootrootposixtestsuite/conformance/interfaces/sigpending/1-3.c0100644000000000000000000000711307616613375022121 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that the sigpending() function stores the set of signals that * are blocked from delivery when there are signals blocked both * in the main function and in the signal handler. * 1) Block two signals from delivery to main process. * 2) Block three signals from delivery to a signal handler. * 3) Raise the signal to get into that signal handler. * From the signal handler: * 4) Raise one blocked signal in the signal handler. * 5) Raise one blocked signal in the main process. * 5) Verify that the two signals raised are shown via sigpending. * 6) Verify the three signals not raised are not shown. */ /* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Signal handler uses exit() to leave so that the signals are not executed. */ #include #include #include #include "posixtest.h" void handler(int signo) { sigset_t pendingset; if (sigemptyset(&pendingset) == -1) { printf("Could not call sigemptyset()\n"); exit(-1); } if (raise(SIGALRM) != 0) { printf("Could not raise SIGALRM\n"); exit(-1); } if (raise(SIGCONT) != 0) { printf("Could not raise SIGCONT\n"); exit(-1); } if (sigpending(&pendingset) == -1) { printf("Error calling sigpending()\n"); exit(-1); } if ( (sigismember(&pendingset, SIGALRM) == 1) && (sigismember(&pendingset, SIGCONT) == 1) ) { printf("All pending signals found\n"); if ( (sigismember(&pendingset, SIGHUP) == 0) && (sigismember(&pendingset, SIGABRT) == 0) && (sigismember(&pendingset, SIGUSR1) == 0) ) { printf("Unsent signals not found\n"); printf("Test PASSED\n"); exit(0); } else { printf("Error with unsent signals\n"); printf("Test FAILED\n"); exit(-1); } } else { printf("Error with send signals\n"); printf("Test FAILED\n"); exit(-1); } } int main() { sigset_t blockset; sigset_t prevset; struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; if ( (sigemptyset(&blockset) == -1) || (sigemptyset(&prevset) == -1) || (sigemptyset(&act.sa_mask) == -1) ) { printf("Could not call sigemptyset()\n"); return PTS_UNRESOLVED; } if ( (sigaddset(&blockset, SIGALRM) == -1) || (sigaddset(&blockset, SIGHUP) == -1) ) { perror("Error calling sigaddset()\n"); return PTS_UNRESOLVED; } if (sigprocmask(SIG_SETMASK, &blockset, &prevset) == -1) { printf("Could not call sigprocmask()\n"); return PTS_UNRESOLVED; } if ( (sigaddset(&act.sa_mask, SIGCONT) == -1) || (sigaddset(&act.sa_mask, SIGABRT) == -1) || (sigaddset(&act.sa_mask, SIGUSR1) == -1) ) { perror("Error calling sigaddset()\n"); return PTS_UNRESOLVED; } if (sigaction(SIGTTOU, &act, 0) == -1) { perror("Could not call sigaction()"); return PTS_UNRESOLVED; } if (raise(SIGTTOU) == -1) { perror("Could not raise SIGTTOU"); return PTS_UNRESOLVED; } printf("This code should not be reachable\n"); return PTS_UNRESOLVED; } posixtestsuite/conformance/interfaces/sigpending/1-1.c0100644000000000000000000000375607616602665022130 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that the sigpending() function stores the set of signals that * are blocked from delivery. Steps are: * 1) Block three signals from delivery. * 2) Raise two of those signals. * 3) Verify that the two signals raised are shown via sigpending. * 4) Verify the one signal not raised is not shown. */ #include #include #include "posixtest.h" int main() { sigset_t blockset; sigset_t prevset; sigset_t pendingset; if ( (sigemptyset(&blockset) == -1) || (sigemptyset(&prevset) == -1) || (sigemptyset(&pendingset) == -1) ) { printf("Could not call sigemptyset()\n"); return PTS_UNRESOLVED; } if ( (sigaddset(&blockset, SIGALRM) == -1) || (sigaddset(&blockset, SIGHUP) == -1) || (sigaddset(&blockset, SIGQUIT) == -1) ) { perror("Error calling sigaddset()\n"); return PTS_UNRESOLVED; } if (sigprocmask(SIG_SETMASK, &blockset, &prevset) == -1) { printf("Could not call sigprocmask()\n"); return PTS_UNRESOLVED; } if (raise(SIGALRM) != 0) { printf("Could not raise SIGALRM\n"); return PTS_UNRESOLVED; } if (raise(SIGQUIT) != 0) { printf("Could not raise SIGQUIT\n"); return PTS_UNRESOLVED; } if (sigpending(&pendingset) == -1) { printf("Error calling sigpending()\n"); return PTS_UNRESOLVED; } if (sigismember(&pendingset, SIGALRM) == 1) { if (sigismember(&pendingset, SIGQUIT) == 1) { printf("All pending signals found\n"); if (sigismember(&pendingset, SIGHUP) == 0) { printf("Unsent signals not found.\n"); printf("Test PASSED\n"); return PTS_PASS; } else { printf("Error with unsent signals\n"); printf("Test FAILED\n"); return PTS_FAIL; } } } printf("Not all pending signals found\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sigpending/1-2.c0100644000000000000000000000571707616620603022120 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that the sigpending() function stores the set of signals that * are blocked from delivery to a signal handler function. Steps are: * 1) Block three signals from delivery to a signal handler. * 2) Raise the signal to get into that signal handler. * From the signal handler: * 3) Raise two of the blocked signals. * 4) Verify that the two signals raised are shown via sigpending. * 5) Verify the one signal not raised is not shown. */ /* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * The handler raises the two blocked signals and verifies they are * shown via sigpending(). * It uses exit() to leave so that the signals are not executed. */ #include #include #include #include "posixtest.h" void handler(int signo) { sigset_t pendingset; if (sigemptyset(&pendingset) == -1) { printf("Could not call sigemptyset()\n"); exit(-1); } if (raise(SIGCONT) != 0) { printf("Could not raise SIGCONT\n"); exit(-1); } if (raise(SIGUSR1) != 0) { printf("Could not raise SIGUSR1\n"); exit(-1); } if (sigpending(&pendingset) == -1) { printf("Error calling sigpending()\n"); exit(-1); } if (sigismember(&pendingset, SIGCONT) == 1) { if (sigismember(&pendingset, SIGUSR1) == 1) { printf("All pending signals found\n"); if (sigismember(&pendingset, SIGHUP) == 0) { printf("Unsent signals not found.\n"); printf("Test PASSED\n"); exit(0); } else { printf("Error with unsent signals\n"); printf("Test FAILED\n"); exit(-1); } } else { printf("Not all pending signals found\n"); exit(-1); } } else { printf("Not all pending signals found\n"); exit(-1); } } int main() { struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; if (sigemptyset(&act.sa_mask) == -1) { printf("Could not call sigemptyset()\n"); return PTS_UNRESOLVED; } if ( (sigaddset(&act.sa_mask, SIGCONT) == -1) || (sigaddset(&act.sa_mask, SIGHUP) == -1) || (sigaddset(&act.sa_mask, SIGUSR1) == -1) ) { perror("Error calling sigaddset()\n"); return PTS_UNRESOLVED; } if (sigaction(SIGTTOU, &act, 0) == -1) { perror("Could not call sigaction()"); return PTS_UNRESOLVED; } if (raise(SIGTTOU) == -1) { perror("Could not raise SIGTTOU"); return PTS_UNRESOLVED; } printf("This code should not be reachable\n"); return PTS_UNRESOLVED; } posixtestsuite/conformance/interfaces/sigpending/assertions.xml0100644000000000000000000000103307616602665024364 0ustar rootroot sigpending() stores the set of signals blocked from delivery to the calling thread and that are pending on the process or calling thread in set. sigpending() returns 0 on success. sigpending() returns -1 when not successful. It also sets errno to indicate the error. [There is no value of errno defined for sigpending.] posixtestsuite/conformance/interfaces/sigpending/coverage.txt0100644000000000000000000000040607616615147024006 0ustar rootrootThis document defines the coverage for function sigpending(). Assertion Covered? 1 YES 2 YES 3 WON'T WON'T TEST 3-1 - Not possible to make sigfillset() fail at will to return a -1. POSIX spec doesn't mention how to cause sigfillset() to fail when called. posixtestsuite/conformance/interfaces/sigpending/2-1.c0100644000000000000000000000313607616602665022121 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that the sigpending() function returns 0 on successful completion. * 1) Block one signal from delivery. * 2) Raise that signal. * 3) Call sigpending and verify it returns 0. * 4) Verify the signal raised is shown. */ #include #include #include "posixtest.h" int main() { sigset_t blockset; sigset_t prevset; sigset_t pendingset; if ( (sigemptyset(&blockset) == -1) || (sigemptyset(&prevset) == -1) || (sigemptyset(&pendingset) == -1) ) { printf("Could not call sigemptyset()\n"); return PTS_UNRESOLVED; } if (sigaddset(&blockset, SIGALRM) == -1) { perror("Error calling sigaddset()\n"); return PTS_UNRESOLVED; } if (sigprocmask(SIG_SETMASK, &blockset, &prevset) == -1) { printf("Could not call sigprocmask()\n"); return PTS_UNRESOLVED; } if (raise(SIGALRM) != 0) { printf("Could not raise SIGALRM\n"); return PTS_UNRESOLVED; } if (sigpending(&pendingset) == 0) { if (sigismember(&pendingset, SIGALRM) == 1) { printf("sigpending returned 0 when successful\n"); printf("Test PASSED\n"); return PTS_PASS; } else { printf("sigpending returned 0 when unsuccessful\n"); printf("Test FAILED\n"); return PTS_FAIL; } } else { printf("sigpending did not return 0\n"); printf("Test FAILED\n"); return PTS_FAIL; } return PTS_UNRESOLVED; } posixtestsuite/conformance/interfaces/sigdelset/0040755000000000000000000000000010515625264021302 5ustar rootrootposixtestsuite/conformance/interfaces/sigdelset/4-3.sh0100755000000000000000000000064207616567526022161 0ustar rootroot#!/bin/sh # Copyright (c) 2002, Intel Corporation. All rights reserved. # Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com # This file is licensed under the GPL license. For the full content # of this license, see the COPYING file at the top level of this # source tree. # # # Test various methods of removing invalid signals to sigaddset(). # conformance/interfaces/sigdelset/4-core-buildonly.test 3 posixtestsuite/conformance/interfaces/sigdelset/4-4.sh0100755000000000000000000000064207616567526022162 0ustar rootroot#!/bin/sh # Copyright (c) 2002, Intel Corporation. All rights reserved. # Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com # This file is licensed under the GPL license. For the full content # of this license, see the COPYING file at the top level of this # source tree. # # # Test various methods of removing invalid signals to sigaddset(). # conformance/interfaces/sigdelset/4-core-buildonly.test 4 posixtestsuite/conformance/interfaces/sigdelset/1-3.c0100644000000000000000000000222707616567526021764 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test the error condition of calling sigdelset() to delete a signal not there. Test steps: 1) Initialize an empty signal set. 2) Verify the SIGCHLD signal is not in the empty signal set. 3) Attempt to remove the SIGCHLD signal from the signal set. 4) Verify the SIGCHLD signal is still not in the signal set. */ #include #include #include "posixtest.h" int main(int argc, char *argv[]) { sigset_t signalset; if (sigemptyset(&signalset) == -1) { perror("sigemptyset failed -- test aborted"); return PTS_UNRESOLVED; } if (sigismember(&signalset, SIGCHLD) == 1) { perror("SIGCHLD is already a member of signal set"); return PTS_UNRESOLVED; } sigdelset(&signalset, SIGCHLD); if (sigismember(&signalset, SIGCHLD) == 0) { printf("Test PASSED\n"); return PTS_PASS; } else { printf("Test FAILED\n"); return PTS_FAIL; } } posixtestsuite/conformance/interfaces/sigdelset/4-core-buildonly.c0100644000000000000000000000350007617612715024537 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Testing sending invalid signals to sigdelset(). After invalid signal sent, sigdelset() should return -1 and set errno to indicate the error. Test steps: 1) Initialize a full signal set. 2) Remove the invalid signal from the full signal set. 3) Verify that -1 is returned, the invalid signal is not a member of the signal set, and errno is set to indicate the error. */ #include #include #include #include #include "posixtest.h" int main(int argc, char *argv[]) { sigset_t signalset; int signo; if (sigfillset(&signalset) == -1) { perror("sigemptyset failed -- test aborted"); return PTS_UNRESOLVED; } if (argc < 2) { printf("Usage: %s [1|2|3|4]\n", argv[0]); return PTS_UNRESOLVED; } /* Various error conditions */ switch (argv[1][0]) { case '1': signo=-1; break; case '2': signo=-10000; break; case '3': signo=INT32_MIN + 1; break; case '4': signo=INT32_MIN; break; default: printf("Usage: %s [1|2|3|4]\n", argv[0]); return -1; } if (sigdelset(&signalset, signo) == -1) { if (EINVAL == errno) { printf ("errno set to EINVAL\n"); if ((sigismember(&signalset, signo) == 0) || sigismember(&signalset, signo) == -1) { printf("signal was not removed\n"); return PTS_PASS; } else { printf("possible error in sigismember\n"); return PTS_UNRESOLVED; } } else { printf ("errno not set to EINVAL\n"); return PTS_FAIL; } } printf("sigdelset did not return -1\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sigdelset/1-1.sh0100755000000000000000000000105107616567526022147 0ustar rootroot#!/bin/sh # Copyright (c) 2002, Intel Corporation. All rights reserved. # Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com # This file is licensed under the GPL license. For the full content # of this license, see the COPYING file at the top level of this # source tree. # # # Test that sigdelset() will remove signo from the set signal set. # This test initializes an empty signal set first. # # Calling 1-core-buildonly.test with a 0 parameter initializes to an # empty set. conformance/interfaces/sigdelset/1-core-buildonly.test 0 posixtestsuite/conformance/interfaces/sigdelset/assertions.xml0100644000000000000000000000140207616567526024226 0ustar rootroot sigdelset() deletes signal signo from signal set set. The results are undefined if an object does not call sigemptyset() or sigfillset() before calling sigdelset(). sigdelset() returns 0 on success. sigdelset() returns -1 when not successful. It also sets errno to indicate the error. If the signo argument is not a valid signal number or is an unsupported signal number, the sigdelset() function will fail with error EINVAL. posixtestsuite/conformance/interfaces/sigdelset/coverage.txt0100644000000000000000000000025607616615026023641 0ustar rootrootThis document defines the coverage for function sigdelset(). Assertion Covered? 1 YES 2 YES 3 IMPLICITLY tested by assertion 1 4 YES 5 IMPLICITLY tested by assertion 4 posixtestsuite/conformance/interfaces/sigdelset/4-2.sh0100755000000000000000000000064207616567526022160 0ustar rootroot#!/bin/sh # Copyright (c) 2002, Intel Corporation. All rights reserved. # Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com # This file is licensed under the GPL license. For the full content # of this license, see the COPYING file at the top level of this # source tree. # # # Test various methods of removing invalid signals to sigaddset(). # conformance/interfaces/sigdelset/4-core-buildonly.test 2 posixtestsuite/conformance/interfaces/sigdelset/2-1.c0100644000000000000000000000152707616567526021765 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test that the results are undefined if sigdelset() is called without first calling sigemptyset() or sigfillset(). Any results are acceptable; however, the system should not crash, hang, or do something equally as harmful. */ #include #include #include "posixtest.h" int main(int argc, char *argv[]) { sigset_t signalset; if (sigdelset(&signalset, SIGALRM) == 0) { printf("sigdelset returned 0\n"); } else { printf("sigdelset() did not return 0\n"); } /* * If we made it here, the test case passes. */ return PTS_PASS; } posixtestsuite/conformance/interfaces/sigdelset/1-4.c0100644000000000000000000000236407616567526021767 0ustar rootroot/* Test the error condition of calling sigdelset() twice for the same signo. Test steps: 1) Initialize an empty signal set. 2) Add the SIGALRM signal to the empty signal set and verify. 3) Remove the SIGALRM signal from the signal set and verify removed. 4) Attempt to remove again and verify signal is still removed. */ #include #include #include "posixtest.h" int main(int argc, char *argv[]) { sigset_t signalset; if (sigemptyset(&signalset) == -1) { perror("sigemptyset failed -- test aborted"); return PTS_UNRESOLVED; } if (sigaddset(&signalset, SIGALRM) == 0) { if (sigismember(&signalset, SIGALRM) == 0) { printf("sigaddset returned, sigismember failed\n"); return PTS_UNRESOLVED; } } else { printf("sigaddset did not successfully add signal\n"); return PTS_UNRESOLVED; } if (sigdelset(&signalset, SIGALRM) == 0) { if (sigismember(&signalset, SIGALRM) == 1) { printf("Signal is still in signal set.\n"); return PTS_FAIL; } } else { printf("sigdelset() failed\n"); return PTS_FAIL; } sigdelset(&signalset, SIGALRM); if (sigismember(&signalset, SIGALRM) == 0) { printf("Test PASSED\n"); return PTS_PASS; } else { printf("Test FAILED\n"); return PTS_FAIL; } } posixtestsuite/conformance/interfaces/sigdelset/1-core-buildonly.c0100644000000000000000000000353307616567526024552 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test that sigdelset() will remove signo to the set signal set. Test steps: 1) Initialize an empty or full signal set. --> if argv[1] = 0, empty --> if argv[1] = 1, full 2) Add the SIGALRM signal to the empty signal set. 3) Verify that SIGALRM is a member of the signal set. 4) Remove the SIGALRM signal from the signal set. 5) Verify that SIGALRM is not a member of the signal set. */ #include #include #include "posixtest.h" int main(int argc, char *argv[]) { sigset_t signalset; if (argc < 2) { printf("Usage: %s [0|1]\n", argv[0]); return PTS_UNRESOLVED; } if ('0' == argv[1][0]) { if (sigemptyset(&signalset) == -1) { perror("sigemptyset failed -- test aborted"); return PTS_UNRESOLVED; } } else if ('1' == argv[1][0]) { if (sigfillset(&signalset) == -1) { perror("sigfillset failed -- test aborted"); return PTS_UNRESOLVED; } } else { printf("Usage: %s [0|1]\n", argv[0]); return PTS_UNRESOLVED; } if (sigaddset(&signalset, SIGALRM) == 0) { if (sigismember(&signalset, SIGALRM) == 0) { printf("sigaddset returned, sigismember failed\n"); return PTS_UNRESOLVED; } } else { printf("sigaddset did not successfully add signal\n"); return PTS_UNRESOLVED; } if (sigdelset(&signalset, SIGALRM) == 0) { if (sigismember(&signalset, SIGALRM) == 0) { printf("sigdelset successfully removed signal\n"); return PTS_PASS; } else { printf("Signal is still in signal set.\n"); return PTS_FAIL; } } else { printf("sigdelset() failed\n"); return PTS_FAIL; } } posixtestsuite/conformance/interfaces/sigdelset/4-1.sh0100755000000000000000000000064207616567526022157 0ustar rootroot#!/bin/sh # Copyright (c) 2002, Intel Corporation. All rights reserved. # Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com # This file is licensed under the GPL license. For the full content # of this license, see the COPYING file at the top level of this # source tree. # # # Test various methods of removing invalid signals to sigaddset(). # conformance/interfaces/sigdelset/4-core-buildonly.test 1 posixtestsuite/conformance/interfaces/sigdelset/1-2.sh0100755000000000000000000000104607616567526022154 0ustar rootroot#!/bin/sh # Copyright (c) 2002, Intel Corporation. All rights reserved. # Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com # This file is licensed under the GPL license. For the full content # of this license, see the COPYING file at the top level of this # source tree. # # # Test that sigdelset() will remove signo from the set signal set. # This test initializes a full signal set first. # # Calling 1-core-buildonly.test with a 1 parameter initializes to an # full set. conformance/interfaces/sigdelset/1-core-buildonly.test 1 posixtestsuite/conformance/interfaces/timer_getoverrun/0040755000000000000000000000000010515625271022715 5ustar rootrootposixtestsuite/conformance/interfaces/timer_getoverrun/2-2.c0100644000000000000000000000512310015323621023344 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * * Test that timer_getoverrun() returns the number of overruns that * have happened due to signals being sent from a timer. Test with * timer seconds in nanoseconds. * * Steps (testing with just one overrun): * - Block signal SIGCONT (SIGCONT used so test will not terminate) * - Set up a timer to send SIGCONT on expiration with an interval * of INTERVALNSEC nanoseconds. * - Wait for that timer to expire EXPECTEDIVERRUNS+1 times (wait VALUENSEC + * (EXPECTEDIVERRUNS)*INTERVALNSEC). * - Call timer_getoverrun() and ensure EXPECTEDOVERRUNS was returned. * [First signal made it. All others were overruns.] */ #include #include #include #include #include "posixtest.h" #define VALUENSEC 2000000 #define INTERVALNSEC 5000000 #define EXPECTEDOVERRUNS 75 int main() { sigset_t set; struct sigevent ev; timer_t tid; struct itimerspec its; struct timespec ts; int overruns; if (sigemptyset(&set) != 0) { perror("sigemptyset() did not return success\n"); return PTS_UNRESOLVED; } if (sigaddset(&set, SIGCONT) != 0) { perror("sigaddset() did not return success\n"); return PTS_UNRESOLVED; } if (sigprocmask(SIG_SETMASK, &set, NULL) != 0) { perror("sigprocmask() did not return success\n"); return PTS_UNRESOLVED; } ev.sigev_notify = SIGEV_SIGNAL; ev.sigev_signo = SIGCONT; /* * create first timer */ if (timer_create(CLOCK_REALTIME, &ev, &tid) != 0) { perror("timer_create() did not return success\n"); return PTS_UNRESOLVED; } its.it_interval.tv_sec = 0; its.it_interval.tv_nsec = INTERVALNSEC; its.it_value.tv_sec = 0; its.it_value.tv_nsec = VALUENSEC; if (timer_settime(tid, 0, &its, NULL) != 0) { perror("timer_settime() did not return success\n"); return PTS_UNRESOLVED; } ts.tv_nsec = VALUENSEC + ((EXPECTEDOVERRUNS)*INTERVALNSEC); ts.tv_sec = 0; if (nanosleep(&ts, NULL) != 0) { perror("nanosleep() did not return success\n"); return PTS_UNRESOLVED; } if (sigprocmask(SIG_UNBLOCK, &set, NULL) != 0) { perror("sigprocmask() did not return success\n"); return PTS_UNRESOLVED; } overruns = timer_getoverrun(tid); if (overruns > EXPECTEDOVERRUNS - 5) { printf("Test PASSED\n"); return PTS_PASS; } else { printf("FAIL: %d overruns sent; expected %d\n", overruns, EXPECTEDOVERRUNS); return PTS_FAIL; } } posixtestsuite/conformance/interfaces/timer_getoverrun/speculative/0040755000000000000000000000000010515625271025241 5ustar rootrootposixtestsuite/conformance/interfaces/timer_getoverrun/speculative/6-2.c0100644000000000000000000000263707663176632025732 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * * Test to see if timer_getoverrun() returns -1 and sets errno==EINVAL when * trying to call timer_getoverrun on a timer that has been deleted or not. * Since this assertion is a "may," either option is a pass. * * For this test, signal SIGCONT will be used, clock CLOCK_REALTIME * will be used. */ #include #include #include #include #include #include #include "posixtest.h" #define TIMERSEC 3 int main(int argc, char *argv[]) { struct sigevent ev; timer_t tid; ev.sigev_notify = SIGEV_SIGNAL; ev.sigev_signo = SIGCONT; if (timer_create(CLOCK_REALTIME, &ev, &tid) != 0) { perror("timer_create() did not return success\n"); return PTS_UNRESOLVED; } if (timer_delete(tid) != 0) { perror("timer_delete() did not return success\n"); return PTS_UNRESOLVED; } if (timer_getoverrun(tid) == -1) { if (errno==EINVAL) { printf("fcn returned -1 and set errno=EINVAL\n"); return PTS_PASS; } else { printf("fcn returned -1 but errno!=EINVAL\n"); printf("Test FAILED\n"); return PTS_FAIL; } } printf("fcn did not return -1\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/timer_getoverrun/speculative/6-1.c0100644000000000000000000000165210021017163025674 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * * Test to see if timer_getoverrun() sets errno=EINVAL if no timers have been * created yet or not. Since this is a "may" assertion, either way is * a pass. */ #include #include #include #include "posixtest.h" #define BOGUSTID 9999 int main(int argc, char *argv[]) { timer_t tid; tid = (timer_t) BOGUSTID; if (timer_getoverrun(tid) == -1) { if (EINVAL == errno) { printf("fcn returned -1 and errno=EINVAL\n"); return PTS_PASS; } else { printf("fcn returned -1, but errno!=EINVAL\n"); printf("Test FAILED\n"); return PTS_FAIL; } } printf("fcn did not return -1\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/timer_getoverrun/speculative/6-3.c0100644000000000000000000000240407663176632025723 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * * Test to see if timer_getoverrun() sets errno = EINVAL for timerid != a * timer ID created via timer_create(). [Try to set timerid to a timer ID * created + 1.] * Since this assertion is a "may," either option is a pass. * * For this test, signal SIGCONT will be used, clock CLOCK_REALTIME * will be used. */ #include #include #include #include #include "posixtest.h" int main(int argc, char *argv[]) { struct sigevent ev; timer_t tid; ev.sigev_notify = SIGEV_SIGNAL; ev.sigev_signo = SIGCONT; if (timer_create(CLOCK_REALTIME, &ev, &tid) != 0) { perror("timer_create() did not return success\n"); return PTS_UNRESOLVED; } if (timer_getoverrun(tid+1) == -1) { if (EINVAL == errno) { printf("fcn returned -1 and errno==EINVAL\n"); return PTS_PASS; } else { printf("fcn returned -1 but errno!=EINVAL\n"); printf("Test FAILED\n"); return PTS_FAIL; } } printf("fcn did not return -1\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/timer_getoverrun/1-1.c0100644000000000000000000000545607570737662023405 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * * Test that only a single timer expiration signal can be sent to * the process at a time. * * - Block signal SIGTOTEST. * - Set up a repeating timer to expire with signal SIGTOTEST. * - Sleep for enough time for > 2 signals to be sent. * - After the signals are unblocked, ensure only one signal is sent. */ #include #include #include #include #include #include "posixtest.h" #define SIGTOTEST SIGALRM #define TIMERVAL 2 #define TIMERINTERVAL 3 int madeit = 0; void handler(int signo) { madeit++; if (madeit > 1) { printf(">1 signal made it through\n"); exit(PTS_FAIL); } } int main() { struct sigevent ev; struct sigaction act; timer_t tid; struct itimerspec its; int overruns; sigset_t set; ev.sigev_notify = SIGEV_SIGNAL; ev.sigev_signo = SIGTOTEST; act.sa_handler=handler; act.sa_flags=0; /* * set up handler for SIGTOTEST */ if (sigemptyset(&act.sa_mask) != 0) { perror("sigemptyset() did not return success\n"); return PTS_UNRESOLVED; } if (sigaction(SIGTOTEST, &act, 0) != 0) { perror("sigaction() did not return success\n"); return PTS_UNRESOLVED; } /* * set up timer to send SIGTOTEST */ if (timer_create(CLOCK_REALTIME, &ev, &tid) != 0) { perror("timer_create() did not return success\n"); return PTS_UNRESOLVED; } its.it_interval.tv_sec = TIMERINTERVAL; its.it_interval.tv_nsec = 0; its.it_value.tv_sec = TIMERVAL; its.it_value.tv_nsec = 0; if (timer_settime(tid, 0, &its, NULL) != 0) { perror("timer_settime() did not return success\n"); return PTS_UNRESOLVED; } /* * block signal SIGTOTEST */ if (sigemptyset(&set) != 0) { perror("sigemptyset() did not return success\n"); return PTS_UNRESOLVED; } if (sigaddset(&set, SIGTOTEST) != 0) { perror("sigaddset() did not return success\n"); return PTS_UNRESOLVED; } if (sigprocmask(SIG_SETMASK, &set, NULL) != 0) { perror("sigprocmask() did not return success\n"); return PTS_UNRESOLVED; } if (sleep(2*TIMERINTERVAL + TIMERVAL) != 0) { perror("Could not sleep for correct amount of time\n"); return PTS_UNRESOLVED; } if (sigprocmask(SIG_UNBLOCK, &set, NULL) != 0) { perror("sigprocmask() did not return success\n"); return PTS_UNRESOLVED; } overruns = timer_getoverrun(tid); printf("Total overruns: %d\n", overruns); if (1 == madeit) { printf("Test PASSED\n"); return PTS_PASS; } else { printf("FAIL: %d signals sent\n", madeit); return PTS_FAIL; } printf("UNRESOLVED: This code should not be executed.\n"); return PTS_UNRESOLVED; } posixtestsuite/conformance/interfaces/timer_getoverrun/assertions.xml0100644000000000000000000000265707663215321025641 0ustar rootroot Only one signal that is sent as the result of a timer expiring can be sent to the timer's process at a time. So, if a signal of that timer is still pending, and the timer expires again, no signal is queued, and a timer overrun occurs. timer_getoverrun() returns the number of overruns that have happened due to signals being sent from a timer. It can be run after the timer expiration signal is finally delivered or accepted. The overrun count == the number of _extra_ timer expirations that happened after the most recent signal delivered/accepted was generated and before it was delivered/accepted. timer_getoverrun() can only return a value up to but not including {DELAYTIMER_MAX}. If the number of overruns > {DELAYTIMER_MAX}, timer_getoverrun() returns {DELAYTIMER_MAX}. timer_getoverrun() returns the overrun count on success. timer_getoverrun() returns -1 on failure if timerid is not a valid timer ID, timer_getoverrun() may sets errno == EINVAL posixtestsuite/conformance/interfaces/timer_getoverrun/coverage.txt0100644000000000000000000000054607570767273025273 0ustar rootrootThis document defines the coverage for function timer_getoverrun(). Assertion Covered? 1 YES 2 YES 3 WON'T 4 YES 5 YES WON'T TEST 3-1 - This test does not appear to be possible to test in a reasonable amount of time (= a few minutes) due to the large size of DELAYTIMER_MAX. [Note to self: DELAYTIMER_MAX is defined in limits.h.] posixtestsuite/conformance/interfaces/timer_getoverrun/5-1.sh0100755000000000000000000000072107570767273023573 0ustar rootroot#!/bin/sh # Copyright (c) 2002, Intel Corporation. All rights reserved. # Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com # This file is licensed under the GPL license. For the full content # of this license, see the COPYING file at the top level of this # source tree. # # Test that timer_getoverrun() returns -1 on failure. # # This is tested implicitly via assertion 6. echo "Tested implicitly via assertion 6. Sett output for status." exit 0 posixtestsuite/conformance/interfaces/timer_getoverrun/2-3.c0100644000000000000000000001150010044153502023342 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Copyright (c) 2002, Jim Houston. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * Patched by: jim.houston REMOVE-THIS AT attbi DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * * Test that timer_getoverrun() returns the number of overruns that * have happened due to signals being sent from a timer. Test with * timer seconds in smallest possible increments. * * valuensec = clock resolution * intervalnsec = 2*valuensec * expectedoverruns = (1,000,000,000 - valuensec) MOD intervalnsec * * Steps (testing with just one overrun): * - Block signal SIGCONT (SIGCONT used so test will not terminate) * - Set up a timer to send SIGCONT on expiration with an interval * of intervalnsec nanoseconds. * - Wait for that timer to expire expectedoverruns+1 times * (Sleep for valuensec + (expectedoverruns)*intervalnsec). * - Call timer_getoverrun() and ensure expectedoverruns was returned. * [First signal made it. All others were overruns.] * * 12/17/02 - Added Jim Houston's patch. There is a chance that additional * timer expires can happen before the overrun count is gotten, so this * test stops the timer before that can happen. * * 04/29/2004 - adam.li * - Add test for RTS option * - It seems disalarm the timer before calling timer_getoverun() will discard * previous overrun (when testing on libc-2004-04-29 * - Make itvalue = 1 sec. */ #include #include #include #include #include "posixtest.h" int main() { #ifndef _POSIX_REALTIME_SIGNALS printf("_POSIX_REALTIME_SIGNALS is not defined\n"); return PTS_UNTESTED; #endif sigset_t set; struct sigevent ev; timer_t tid; struct itimerspec its; struct timespec tssleep, tsres; int overruns; int valuensec, intervalnsec, expectedoverruns; int fudge; if (sigemptyset(&set) != 0) { perror("sigemptyset() did not return success\n"); return PTS_UNRESOLVED; } if (sigaddset(&set, SIGCONT) != 0) { perror("sigaddset() did not return success\n"); return PTS_UNRESOLVED; } if (sigprocmask(SIG_SETMASK, &set, NULL) != 0) { perror("sigprocmask() did not return success\n"); return PTS_UNRESOLVED; } ev.sigev_notify = SIGEV_SIGNAL; ev.sigev_signo = SIGCONT; /* * create first timer */ if (timer_create(CLOCK_REALTIME, &ev, &tid) != 0) { perror("timer_create() did not return success\n"); return PTS_UNRESOLVED; } if (clock_getres(CLOCK_REALTIME, &tsres) != 0) { perror("clock_gettime() did not return success\n"); return PTS_UNRESOLVED; } if (tsres.tv_sec != 0) { printf("Clock resolution in seconds, not nsecs. Exiting.\n"); return PTS_UNRESOLVED; } valuensec = tsres.tv_nsec; intervalnsec = 2*valuensec; //expectedoverruns = (1000000000 - valuensec) / intervalnsec; expectedoverruns = 1000000000 / intervalnsec - 1; printf("value = %d sec, interval = %d nsec, " "expected overruns = %d\n", 1, intervalnsec, expectedoverruns); its.it_interval.tv_sec = 0; its.it_interval.tv_nsec = intervalnsec; its.it_value.tv_sec = 1; its.it_value.tv_nsec = 0; //its.it_value.tv_sec = 0; //its.it_value.tv_nsec = valuensec; if (timer_settime(tid, 0, &its, NULL) != 0) { perror("timer_settime() did not return success\n"); return PTS_UNRESOLVED; } //tssleep.tv_nsec = valuensec + (expectedoverruns*intervalnsec); tssleep.tv_nsec = 0; tssleep.tv_sec = 2; if (nanosleep(&tssleep, NULL) != 0) { perror("nanosleep() did not return success\n"); return PTS_UNRESOLVED; } /* * Since the overrun count is only meaningful with respect * to a particular timer expiry disable the timer before * un-blocking the signal. This ensures that there is only * one expiry and it should have a meaningful overrun count. */ //its.it_interval.tv_sec = 0; //its.it_interval.tv_nsec = 0; //its.it_value.tv_sec = 0; //its.it_value.tv_nsec = 0; //if (timer_settime(tid, 0, &its, NULL) != 0) { // perror("timer_settime() did not return success\n"); // return PTS_UNRESOLVED; //} if (sigprocmask(SIG_UNBLOCK, &set, NULL) != 0) { perror("sigprocmask() did not return success\n"); return PTS_UNRESOLVED; } overruns = timer_getoverrun(tid); printf("%d overruns occurred\n", overruns); /* * Depending on the clock resolution we may have a few * extra expiries after the nanosleep completes so do * a range check. */ fudge = expectedoverruns/100; if (overruns >= expectedoverruns && overruns < expectedoverruns+fudge) { printf("Test PASSED\n"); return PTS_PASS; } else { printf("FAIL: %d overruns sent; expected %d\n", overruns, expectedoverruns); return PTS_FAIL; } printf("UNRESOLVED: This code should not be executed.\n"); return PTS_UNRESOLVED; } posixtestsuite/conformance/interfaces/timer_getoverrun/2-1.c0100644000000000000000000000460710015100541023343 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * * Test that timer_getoverrun() returns the number of overruns that * have happened due to signals being sent from a timer. * * Steps (testing with just one overrun): * - Block signal SIGCONT (SIGCONT used so test will not terminate) * - Set up a timer to send SIGCONT on expiration with an interval * of INTERVALSEC. * - Wait for that timer to expire twice (wait VALUESEC + INTERVALSEC). * - Call timer_getoverrun() and ensure 1 (EXPECTEDOVERRUNS) was returned. * [First signal made it. Second signal was the overrun.] */ #include #include #include #include #include "posixtest.h" #define VALUESEC 3 #define INTERVALSEC 4 #define EXPECTEDOVERRUNS 2 int main() { sigset_t set; struct sigevent ev; timer_t tid; struct itimerspec its; int overruns; if (sigemptyset(&set) != 0) { perror("sigemptyset() did not return success\n"); return PTS_UNRESOLVED; } if (sigaddset(&set, SIGCONT) != 0) { perror("sigaddset() did not return success\n"); return PTS_UNRESOLVED; } if (sigprocmask(SIG_SETMASK, &set, NULL) != 0) { perror("sigprocmask() did not return success\n"); return PTS_UNRESOLVED; } ev.sigev_notify = SIGEV_SIGNAL; ev.sigev_signo = SIGCONT; /* * create first timer */ if (timer_create(CLOCK_REALTIME, &ev, &tid) != 0) { perror("timer_create() did not return success\n"); return PTS_UNRESOLVED; } its.it_interval.tv_sec = INTERVALSEC; its.it_interval.tv_nsec = 0; its.it_value.tv_sec = VALUESEC; its.it_value.tv_nsec = 0; if (timer_settime(tid, 0, &its, NULL) != 0) { perror("timer_settime() did not return success\n"); return PTS_UNRESOLVED; } sleep(VALUESEC+2*INTERVALSEC+1); if (sigprocmask(SIG_UNBLOCK, &set, NULL) != 0) { perror("sigprocmask() did not return success\n"); return PTS_UNRESOLVED; } overruns = timer_getoverrun(tid); if (EXPECTEDOVERRUNS == overruns) { printf("Test PASSED\n"); return PTS_PASS; } else { printf("FAIL: %d overruns sent; expected %d\n", overruns, EXPECTEDOVERRUNS); return PTS_FAIL; } printf("UNRESOLVED: This code should not be executed.\n"); return PTS_UNRESOLVED; } posixtestsuite/conformance/interfaces/timer_getoverrun/4-1.sh0100755000000000000000000000074007570767273023573 0ustar rootroot#!/bin/sh # Copyright (c) 2002, Intel Corporation. All rights reserved. # Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com # This file is licensed under the GPL license. For the full content # of this license, see the COPYING file at the top level of this # source tree. # # Test that timer_getoverrun() returns the overrun count on success. # # This is tested implicitly via assertion 2. echo "Tested implicitly via assertion 2. Sett output for status." exit 0 posixtestsuite/conformance/interfaces/timer_getoverrun/3-1.c0100644000000000000000000000144610341622360023354 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * * Test that timer_getoverrun() can only return a value up to but * not including {DELAYTIMER_MAX}. * - adam.li 2004-04-29 Make the output as HEX. * - s.decugis 2005-11-25 Changed return value to UNTESTED. */ #include #include #include #include #include "posixtest.h" int main() { long delaytimer_max = sysconf(_SC_DELAYTIMER_MAX); printf("Cannot be tested as DELAYTIMER_MAX is too large.\n"); printf("DELAYTIMER_MAX is %lx\n", delaytimer_max); return PTS_UNTESTED; } posixtestsuite/conformance/interfaces/pthread_spin_init/0040755000000000000000000000000010515625230023013 5ustar rootrootposixtestsuite/conformance/interfaces/pthread_spin_init/2-2.c0100644000000000000000000001130507703057114023461 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * * Test pthread_spin_init(pthread_spinlock_t *lock, int pshared) * * If the Thread Process-Shared Synchronization option is supported * and the value of pshared is PTHREAD_PROCESS_PRIVATE, or if the option * is not supported, the spin lock shall only be operated upon by threads created * within the same process as the thread that initialized the spin lock. * If threads of different processed attempt to operation on such a spin * lock, the behavior is undefined. * * NOTE: This case will always PASS * * steps: * 1. Create a piece of shared memory object, create a spin lock 'spinlock' and * set the PTHREAD_PROCESS_PRIVATE attribute. * 2. Parent map the shared memory to its memory space, put 'spinlock' into it; * 3. Parent get the spin lock; * 4. Fork to create child * 5. Child map the shared memory to its memory space; * 6. Child call pthread_spin_trylock() * 7. Main unlock * 8. Child call pthread_spin_trylock() */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include #include #include #include "posixtest.h" struct shmstruct{ pthread_spinlock_t spinlock; int data; } *spinlock_data; int main() { int pshared; /* Make sure there is process-shared capability. */ #ifdef PTHREAD_PROCESS_PRIVATE pshared = PTHREAD_PROCESS_PRIVATE; #else pshared = -1; #endif char shm_name[] = "tmp_pthread_spinlock_init"; int shm_fd; int pid; int rc; /* Create shared object */ shm_unlink(shm_name); shm_fd = shm_open(shm_name, O_RDWR|O_CREAT|O_EXCL, S_IRUSR|S_IWUSR); if(shm_fd == -1) { perror("Error at shm_open()"); return PTS_UNRESOLVED; } if(ftruncate(shm_fd, sizeof(struct shmstruct)) != 0) { perror("Error at ftruncate()"); shm_unlink(shm_name); return PTS_UNRESOLVED; } /* Map the shared memory object to parent's memory */ spinlock_data = mmap(NULL, sizeof(struct shmstruct), PROT_READ|PROT_WRITE, MAP_SHARED, shm_fd, 0); if(spinlock_data == MAP_FAILED) { perror("Error at first mmap()"); shm_unlink(shm_name); return PTS_UNRESOLVED; } if((pthread_spin_init(&(spinlock_data->spinlock), pshared)) != 0) { printf("Test FAILED: Error at pthread_rwlock_init()\n"); return PTS_FAIL; } printf("main: attempt spin lock\n"); if((pthread_spin_lock(&(spinlock_data->spinlock))) != 0) { printf("Error at pthread_spin_lock()\n"); return PTS_UNRESOLVED; } printf("main: acquired spin lock\n"); /* Initialized spinlock data */ spinlock_data->data = 0; pid = fork(); if(pid == -1) { perror("Error at fork()"); return PTS_UNRESOLVED; } else if(pid > 0) { /* Parent */ /* wait until child writes to spinlock data */ while(spinlock_data->data != 1) sleep(1); printf("main: unlock spin lock\n"); if(pthread_spin_unlock(&(spinlock_data->spinlock)) != 0) { printf("main: error at pthread_spin_unlock()\n"); return PTS_UNRESOLVED; } /* Tell child that parent unlocked the spin lock */ spinlock_data->data = 2; /* Wait until child ends */ wait(NULL); if((shm_unlink(shm_name)) != 0) { perror("Error at shm_unlink()"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } else { /* Child */ /* Map the shared object to child's memory */ spinlock_data = mmap(NULL, sizeof(struct shmstruct), PROT_READ|PROT_WRITE, MAP_SHARED, shm_fd, 0); if(spinlock_data == MAP_FAILED) { perror("child : Error at mmap()"); return PTS_UNRESOLVED; } printf("child: attempt spin lock\n"); rc = pthread_spin_trylock(&(spinlock_data->spinlock)); if( rc != EBUSY) printf("child: get return code %d, %s\n", rc, strerror(rc)); else printf("child: correctly got EBUSY\n"); /* Tell parent it can unlock now */ spinlock_data->data = 1; while(spinlock_data->data != 2) sleep(1); printf("child: attempt spin lock\n"); rc = pthread_spin_trylock(&(spinlock_data->spinlock)); if(rc == 0) printf("child: acquired spin lock\n"); else printf("child: get return code %d, %s\n", rc, strerror(rc)); printf("child: unlock spin lock\n"); if(pthread_spin_unlock(&(spinlock_data->spinlock)) != 0) { printf("Child: error at pthread_spin_unlock()\n"); return PTS_UNRESOLVED; } if(pthread_spin_destroy(&(spinlock_data->spinlock)) != 0) { printf("Child: error at pthread_spin_destroy()\n"); return PTS_UNRESOLVED; } } } posixtestsuite/conformance/interfaces/pthread_spin_init/4-1.c0100644000000000000000000000461007703057114023463 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * * Test pthread_spin_init(pthread_spinlock_t * lock, int pshared) * * These functions may fail if: * [EBUSY] The implementation has detected an attempt to initialize or destroy a spin * lock while it is in use (for example, while being used in a pthread_spin_lock( ) * call) by another thread. * * Note: This case will always pass. * * Steps: * 1. Initialize a pthread_spinlock_t object 'spinlock' with * pthread_spin_init() * 2. Main thread lock 'spinlock', should get the lock * 3. Main create a child thread * 4. Child thread initialize the spin lock when main holds the lock */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include #include "posixtest.h" static pthread_spinlock_t spinlock; static int pshared; static void* fn_chld(void* arg) { int rc; /* child: initialize a spin lock being locked by main thread */ printf("child: attempt initialize spin lock\n"); rc = pthread_spin_init(&spinlock, pshared); if(rc == EBUSY) printf("child: correctly got EBUSY\n"); else { printf("child: got return code %d, %s\n", rc, strerror(rc)); printf("Test PASSED: *Note: Did not return EBUSY when initializing a spinlock already in use, but standard says 'may' fail\n"); } exit(PTS_PASS); } int main() { int rc = 0; pthread_t child_thread; #ifdef PTHREAD_PROCESS_PRIVATE pshared = PTHREAD_PROCESS_PRIVATE; #else pshared = -1; #endif printf("main: initialize spin lock\n"); rc = pthread_spin_init(&spinlock, pshared); if(rc != 0) { printf("Test FAILED: Error at pthread_spin_init()\n"); return PTS_FAIL; } printf("main: attempt spin lock\n"); /* We should get the lock */ if(pthread_spin_lock(&spinlock) != 0) { printf("Error: main cannot get spin lock when no one owns the lock\n"); return PTS_UNRESOLVED; } printf("main: acquired spin lock\n"); printf("main: create thread\n"); if(pthread_create(&child_thread, NULL, fn_chld, NULL) != 0) { printf("main: Error creating child thread\n"); return PTS_UNRESOLVED; } /* Wait for thread to end execution */ pthread_join(child_thread, NULL); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_spin_init/3-1.sh0100755000000000000000000000074507703057114023662 0ustar rootroot#!/bin/sh # Copyright (c) 2002, Intel Corporation. All rights reserved. # This file is licensed under the GPL license. For the full content # of this license, see the COPYING file at the top level of this # source tree. # Upon successful completion, pthread_spin_init() shall return zero; # otherwise, an error number shall be returned to indicate the error. # This is tested implicitly via assertion 1. echo "Tested implicitly via assertion 1. See output for status" exit 0 posixtestsuite/conformance/interfaces/pthread_spin_init/1-1.c0100644000000000000000000000331607703057114023462 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * * Test pthread_spin_init(pthread_spinlock_t * lock, int pshared) * * pthread_spin_init() shall allocate any resources required to use * the spin lock referenced by 'lock' and initialize the lock to an * unlocked state. * * Steps: * 1. Initialize a pthread_spinlock_t object 'spinlock' with * pthread_spin_init() * 2. Main thread lock 'spinlock', should get the lock * 3. Main thread unlock 'spinlock' * 4. Main thread destroy the 'spinlock' */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include "posixtest.h" static pthread_spinlock_t spinlock; int main() { int rc = 0; int pshared; #ifdef PTHREAD_PROCESS_PRIVATE pshared = PTHREAD_PROCESS_PRIVATE; #else pshared = -1; #endif rc = pthread_spin_init(&spinlock, pshared); if(rc != 0) { printf("Test FAILED: Error at pthread_spin_init(): %d\n", rc); return PTS_FAIL; } printf("main: attempt spin lock\n"); /* We should get the lock */ if(pthread_spin_lock(&spinlock) != 0) { perror("Error: main cannot get spin lock when no one owns the lock\n"); return PTS_UNRESOLVED; } printf("main: acquired spin lock\n"); if(pthread_spin_unlock(&spinlock) != 0) { perror("main: Error at pthread_spin_unlock()\n"); return PTS_UNRESOLVED; } rc = pthread_spin_destroy(&spinlock); if(rc != 0) { printf("Error at pthread_spin_destroy(): %d\n", rc); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_spin_init/assertions.xml0100644000000000000000000000353110117555067025736 0ustar rootroot The function int pthread_spin_init(pthread_spinlock_t *lock, int pshared); shall allocate any resources required to use the spin lock referenced by lock and initialize the lock to an unlocked state. If the Thread Process-Shared Synchronization option is supported and the value of pshared is PTHREAD_PROCESS_SHARED, the implementation shall permit the spin lock to be operated upon by any thread that has access to the memory where the spin lock is allocated, even if it is allocated in memory that is shared by multiple processes. If the Thread Process-Shared Synchronization option is supported and the value of pshared is PTHREAD_PROCESS_PRIVATE, or if the option is not supported, the spin lock shall only be operated upon by threads created within the same process as the thread that initialized the spinlock. If threads of differing processes attempt to operate on such a spin lock, the behavior is undefined. Upon successful completion, these functions shall return zero; otherwise, an error number shall be returned to indicate the error. This function may fail if: -[EBUSY] The implementation has detected an attempt to initialize or destroy a spin lock while it is in use (for example, while being used in a pthread_spin_lock( ) by another thread. -[EINVAL] The value specified by lock is invalid. It shall fail if: -[EAGAIN] The system lacks the necessary resources to initialize another spin lock. -[ENOMEM] Insufficient memory exists to initialize the lock. These functions shall not return an error code of EINTR. posixtestsuite/conformance/interfaces/pthread_spin_init/coverage.txt0100644000000000000000000000020007703057114025341 0ustar rootrootThis document defines the coverage for the pthread_spin_init() function: Assertion Tested? 1 YES 2 YES 3 YES 4 YES NOTE: posixtestsuite/conformance/interfaces/pthread_spin_init/2-1.c0100644000000000000000000001142207703057114023460 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * * Test pthread_spin_init(pthread_spinlock_t *lock, int pshared) * * If the Thread Process-Shared Synchronization option is supported and * the value of pshared is PTHREAD_PROCESS_SHARED, the implementation shall * permit the spin lock to be opreated upon by any thread that has access * to the memory where the spin lock is allocated, even if it is allocated * in memory that is shared by multiple processes. * * steps: * 1. Create a piece of shared memory object, create a spin lock 'spinlock' and * set the PTHREAD_PROCESS_SHARED attribute. * 2. Parent map the shared memory to its memory space, put 'spinlock' into it; * 3. Parent get the spin lock; * 4. Fork to create child * 5. Child map the shared memory to its memory space; * 6. Child call pthread_spin_trylock(), should fail with EBUSY */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include #include "posixtest.h" struct shmstruct{ pthread_spinlock_t spinlock; int data; } *spinlock_data; int main() { /* Make sure there is process-shared capability. */ #ifndef PTHREAD_PROCESS_SHARED fprintf(stderr,"process-shared attribute is not available for testing\n"); return PTS_UNSUPPORTED; #endif int pshared = PTHREAD_PROCESS_SHARED; char shm_name[] = "tmp_pthread_spinlock_getpshared"; int shm_fd; int pid; /* Create shared object */ shm_unlink(shm_name); shm_fd = shm_open(shm_name, O_RDWR|O_CREAT|O_EXCL, S_IRUSR|S_IWUSR); if(shm_fd == -1) { perror("Error at shm_open()"); return PTS_UNRESOLVED; } if(ftruncate(shm_fd, sizeof(struct shmstruct)) != 0) { perror("Error at ftruncate()"); shm_unlink(shm_name); return PTS_UNRESOLVED; } /* Map the shared memory object to parent's memory */ spinlock_data = mmap(NULL, sizeof(struct shmstruct), PROT_READ|PROT_WRITE, MAP_SHARED, shm_fd, 0); if(spinlock_data == MAP_FAILED) { perror("Error at first mmap()"); shm_unlink(shm_name); return PTS_UNRESOLVED; } /* Initialize spinlock */ if((pthread_spin_init(&(spinlock_data->spinlock), pshared)) != 0) { printf("Test FAILED: Error at pthread_rwlock_init()\n"); return PTS_FAIL; } printf("main: attempt spin lock\n"); if((pthread_spin_lock(&(spinlock_data->spinlock))) != 0) { printf("Error at pthread_spin_lock()\n"); return PTS_UNRESOLVED; } printf("main: acquired spin lock\n"); /* Initialize spinlock data */ spinlock_data->data = 0; /* Fork a child process */ pid = fork(); if(pid == -1) { perror("Error at fork()"); return PTS_UNRESOLVED; } else if(pid > 0) { /* Parent */ /* wait until child writes to spinlock data */ while(spinlock_data->data != 1) sleep(1); printf("main: unlock spin lock\n"); if(pthread_spin_unlock(&(spinlock_data->spinlock)) != 0) { printf("Parent: error at pthread_spin_unlock()\n"); return PTS_UNRESOLVED; } /* Tell child that parent unlocked the spin lock */ spinlock_data->data = 2; /* Wait until child ends */ wait(NULL); if((shm_unlink(shm_name)) != 0) { perror("Error at shm_unlink()"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } else { /* Child */ /* Map the shared object to child's memory */ spinlock_data = mmap(NULL, sizeof(struct shmstruct), PROT_READ|PROT_WRITE, MAP_SHARED, shm_fd, 0); if(spinlock_data == MAP_FAILED) { perror("child : Error at mmap()"); return PTS_UNRESOLVED; } printf("child: attempt spin lock\n"); if((pthread_spin_trylock(&(spinlock_data->spinlock))) != EBUSY) { printf("Test FAILED: Child expects EBUSY\n"); return PTS_FAIL; } printf("child: correctly got EBUSY\n"); /* Tell parent it can unlock now */ spinlock_data->data = 1; /* Wait for parent to unlock spinlock */ while(spinlock_data->data != 2) sleep(1); /* Child tries to get spin lock after parent unlock, * it should get the lock. */ printf("child: attempt spin lock\n"); if((pthread_spin_trylock(&(spinlock_data->spinlock))) != 0) { printf("Test FAILED: Child should get the lock\n"); return PTS_FAIL; } printf("child: acquired spin lock\n"); printf("child: unlock spin lock\n"); if(pthread_spin_unlock(&(spinlock_data->spinlock)) != 0) { printf("Child: error at pthread_spin_unlock()\n"); return PTS_UNRESOLVED; } if(pthread_spin_destroy(&(spinlock_data->spinlock)) != 0) { printf("Child: error at pthread_spin_destroy()\n"); return PTS_UNRESOLVED; } } } posixtestsuite/conformance/interfaces/kill/0040755000000000000000000000000010515625165020252 5ustar rootrootposixtestsuite/conformance/interfaces/kill/2-2.c0100644000000000000000000000375207651277370020732 0ustar rootroot#include #include #include #include #include #include #include "posixtest.h" /* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that when the null signal is sent to kill(), error checking is * still performed. * 1) Send a signal to generate an ESRCH error. * ==> Send a signal to PID 999999 * 2) Verify ESRCH error received and kill() returned -1. * 3) Send a signal to generate an EPERM error. * ==> Set UID to 1 and send a signal to init (pid = 1) * 4) Verify EPERM error received and kill() returned -1. * * Note: These tests make the assumptions that: * - They will be running as root. * - The PID 999999 can never exist. * - The UID 1 is available for assignment and cannot sent * signals to root. * *** I need to check to see if these assumptions are always valid. */ int main() { int failure = 0; /* * ESRCH */ if (-1 == kill(999999, 0)) { if (ESRCH == errno) { printf("ESRCH error received\n"); } else { printf("kill() failed on ESRCH errno not set correctly\n"); failure = 1; } } else { printf("kill() did not fail on ESRCH\n"); failure = 1; } /* * EPERM */ setuid(1); /* this is added incase user is root. If user is normal user, then it has no effect on the tests*/ if (-1 == kill(1, 0)) { if (EPERM == errno) { printf("EPERM error received\n"); } else { printf("kill() failed on EPERM errno not set correctly\n"); failure = 1; } } else { printf("kill() did not fail on EPERM\n"); failure = 1; } if (failure) { printf("At least one test FAILED -- see output for status\n"); return PTS_FAIL; } else { printf("All tests PASSED\n"); return PTS_PASS; } } posixtestsuite/conformance/interfaces/kill/1-1.c0100644000000000000000000000266407631704637020730 0ustar rootroot/* * Copyright (c) 2002-3, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that the kill() function shall send signal sig to the process * specified by pid. * 1) Set up a signal handler for the signal that says we have caught the * signal. * 2) Call kill on the current process with the signal. * 3) If signal handler was called, test passed. * This test is only performed on one signal. All other signals are * considered to be in the same equivalence class. */ #define SIGTOTEST SIGABRT #include #include #include #include #include "posixtest.h" void handler(int signo) { printf("Caught signal being tested!\n"); printf("Test PASSED\n"); exit(0); } int main() { struct sigaction act; act.sa_handler=handler; act.sa_flags=0; if (sigemptyset(&act.sa_mask) == -1) { perror("Error calling sigemptyset\n"); return PTS_UNRESOLVED; } if (sigaction(SIGTOTEST, &act, 0) == -1) { perror("Error calling sigaction\n"); return PTS_UNRESOLVED; } if (kill(getpid(), SIGTOTEST) != 0) { printf("Could not raise signal being tested\n"); return PTS_UNRESOLVED; } printf("Should have exited from signal handler\n"); printf("Test FAILED\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/kill/1-2.c0100644000000000000000000000474407645362726020736 0ustar rootroot#include #include #include #include #include #include "posixtest.h" /* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that the kill() function shall send signal sig to the process * specified by pid when the process specified by pid is not the calling * process. * 1) Fork a child process. * 2) In the parent process, call kill with signal SIGTOTEST for the * pid of the child. * In the child, * 3) Wait for signal SIGTOTEST. * 4) Return 1 if SIGTOTEST is found. Return 0 otherwise. * 5) In the parent, return success if 1 was returned from child. * * This test is only performed on one signal. All other signals are * considered to be in the same equivalence class. * * This test makes the assumption that 1 second of sleeping on the part * of the parent is enough to give the child time to start waiting for * the parent's signal. If that is not the case, this test will fail. */ #define SIGTOTEST SIGUSR1 void myhandler (int signo) { exit(1); } int main() { int pid; int sig; sigset_t set; if (sigemptyset(&set) == -1) { perror("Error calling sigemptyset\n"); return PTS_UNRESOLVED; } if (sigaddset(&set, SIGTOTEST) == -1) { perror("Error calling sigaddset\n"); return PTS_UNRESOLVED; } if ((pid = fork()) == 0) { /* child here */ struct sigaction act; act.sa_handler=myhandler; act.sa_flags=0; sigemptyset(&act.sa_mask); sigaction(SIGTOTEST, &act, 0); if (0 != sigwait(&set, &sig)) { printf("Sigwait did not return 0. Possible problem with sigwait function\n"); return 0; /* FAIL */ } if (sig != SIGTOTEST) return 0; /* FAIL */ return 1; } else { /* parent here */ int i; sleep(1); if (kill(pid, SIGTOTEST) != 0) { printf("Could not raise signal being tested\n"); return PTS_UNRESOLVED; } if (wait(&i) == -1) { perror("Error waiting for child to exit\n"); return PTS_UNRESOLVED; } if (WEXITSTATUS(i)) { printf("Child exited normally\n"); printf("Test PASSED\n"); return PTS_PASS; } else { printf("Child did not exit normally.\n"); printf("Test FAILED\n"); return PTS_FAIL; } } printf("Should have exited from parent\n"); printf("Test FAILED\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/kill/assertions.xml0100644000000000000000000000711707631704641023173 0ustar rootroot The kill function sends a signal (sig) to a process or group of processes (pid). If sig is 0 (null signal), only error checking (such as to check the validity of pid) is performed. No signal is sent. If the real or effective user ID of the sending process does not match the real or saved set-user-ID of the receiving process (pid), the kill function will fail with errno set to EPERM. For pid > 0, sig is sent to process ID pid. For pid == 0, sig is sent to all processes (except an unspecified set of system processes) where process group ID == process group ID of sender. The sending process must also have permission to send a signal to the receiving process. For pid == -1, sig is sent to all processes (except an unspecified set of system processes). The sending process must have permission to send signal sig to the receiving process. For pid below 0 and != -1, sig is sent to all processes (except an unspecified set of system processes) where process group ID == absolute value of pid. The sending process must have permission to send signal sig to the receiving process. If it turns out that sig should be sent to the sending process (based on pid's value), then it (or at least one pending unblocked signal) will be sent to the sending thread before the kill() returns. However, if one of these is the case: - sig is blocked for the calling thread - another thread has sign unblocked - another thread is waiting in a sigwait() function for sig it will not be sent. If SIGCONT is being sent to a process that happens to be a member of the same session as the sending process, then the user ID tests described in assertion 3 won't be applied. It is allowed for an implementation to impose further restrictions on the sending of signals (for extended security controls), including restrictions on the null signal. A particular example is to deny the existence of some or all of the processes specified by the pid parameter. If the process has permission to sent sig to at least one of the processes specified by pid, then kill() is successful. When kill() is successful, it returns 0. When kill() is not successful, it returns -1 and sets errno to indicate the type of error. The kill() function sets errno to EINVAL if the value of the sig argument is an invalid or unsupported signal number. The kill() function sets errno to EPERM if the process does not have permission to send the signal to at least one receiving process. The kill() function sets errno to ESRCH if not one process or process group can be found corresponding to the pid parameter. posixtestsuite/conformance/interfaces/kill/coverage.txt0100644000000000000000000000137107616615303022606 0ustar rootrootThis file defines the coverage for the kill() function testing. Assertion Status 1 DONE 2 DONE - Open questions on assumptions 3 DONE - Note: This has a bug. The child doesn't die; it sits in constant wait. TBD how to fix (I tried adding another layer, but can't figure out how to kill the child without killing everything, so nothing is checked in.) 4 IMPLICITLY tested by assertion 1 5 NOT STARTED 6 NOT STARTED 7 NOT STARTED 8 NOT STARTED 9 NOT STARTED 10 WON'T test. This assertion cannot really be tested; however, it is listed as an FYI for the tester in that the assertion may cause some items which could be perceived as failures to actually be passes. 11 NOT STARTED 12 NOT STARTED 13 NOT STARTED 14 NOT STARTED 15 NOT STARTED posixtestsuite/conformance/interfaces/kill/2-1.c0100644000000000000000000000146107631704640020715 0ustar rootroot#include #include #include #include #include "posixtest.h" /* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that if the signal is the null signal (0), no signal is sent. * 1) Call kill on the current process with the null signal. * 2) If process is still functional after kill() is called, consider * the test a pass (most likely no signal was sent). */ int main() { if (kill(getpid(), 0) != 0) { printf("Could not call kill with sig = 0\n"); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/kill/3-1.c0100644000000000000000000000204307651300152020703 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: salwan.searty REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. This program tests the assertion that if the user id of the sending process doesn't match the user id of the receiving process (pid), then the kill function will fail with errno set to EPERM. */ #include #include #include #include #include #include #include "posixtest.h" int main() { setuid(1); /* this is added incase user is root. If user is normal user, then it has no effect on the tests*/ if (kill(1, 0) != -1) { printf("Test FAILED: kill() succeeded even though this program's user id did not match the recieving process's user id\n"); return PTS_FAIL; } if (EPERM != errno) { printf("Test FAILED: EPERM error not received\n"); return PTS_FAIL; } return PTS_PASS; } posixtestsuite/conformance/interfaces/getpid/0040755000000000000000000000000010515625164020572 5ustar rootrootposixtestsuite/conformance/interfaces/getpid/1-1.c0100644000000000000000000001541410153372361021232 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertion: * * getpid() always returns the process ID of the calling thread/process. * The steps are: * * -> create two threads and check they get the same getpid() return value. * -> create two processes and check they get different getpid() return value. * -> check that the child process getpid() return value matchs the fork() return value in the parent process. * The test fails if any of the previous checks is not verified. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /* We need the XSI extention for the mutex attributes and the mkstemp() routine */ #ifndef WITHOUT_XOPEN #define _XOPEN_SOURCE 600 #endif /********************************************************************************************/ /****************************** standard includes *****************************************/ /********************************************************************************************/ #include #include #include #include #include #include #include #include #include /********************************************************************************************/ /****************************** Test framework *****************************************/ /********************************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /********************************************************************************************/ /********************************** Configuration ******************************************/ /********************************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif /********************************************************************************************/ /*********************************** Test case *****************************************/ /********************************************************************************************/ #ifndef WITHOUT_XOPEN pid_t * sharedpid; /* This will be executed by the child process */ void child(void) { *sharedpid=getpid(); exit(0); } /* This will be executed by the child thread */ void * threaded(void * arg) { *(pid_t *)arg = getpid(); return NULL; } /* The main test function. */ int main(int argc, char * argv[]) { int ret, status; long mf; /* Is memory mapping supported? */ pid_t mypid, hispid, ctlpid; pthread_t child_thread; /* Initialize output */ output_init(); /* Get self PID */ mypid=getpid(); #if VERBOSE > 1 output("Main pid: %d\n", mypid); #endif /* Get a child thread PID */ ret = pthread_create(&child_thread, NULL, threaded, &hispid); if (ret != 0) { UNRESOLVED(ret, "Thread creation failed"); } ret = pthread_join(child_thread, NULL); if (ret != 0) { UNRESOLVED(ret, "Thread join failed"); } #if VERBOSE > 1 output("Thread pid: %d\n", hispid); #endif /* Compare threads PIDs */ if (mypid != hispid) { FAILED("Child thread got a different return value from getpid()\n"); } /* Test system abilities */ mf =sysconf(_SC_MAPPED_FILES); #if VERBOSE > 0 output("Test starting\n"); output("System abilities:\n"); output(" MF : %li\n", mf); if (mf <= 0) output("Unable to test without shared data\n"); #endif /* We need MF support for the process-cross testing */ if (mf > 0) { /* We will place the child pid in a mmaped file */ char filename[] = "/tmp/getpid-1-XXXXXX"; void * mmaped; int fd; /* We now create the temp files */ fd = mkstemp(filename); if (fd == -1) { UNRESOLVED(errno, "Temporary file could not be created"); } /* and make sure the file will be deleted when closed */ unlink(filename); #if VERBOSE > 1 output("Temp file created (%s).\n", filename); #endif /* Fill the file up to 1 pagesize */ ret = ftruncate(fd, sysconf(_SC_PAGESIZE)); if (ret != 0) { UNRESOLVED(errno, "ftruncate operation failed"); } /* Now we can map the file in memory */ mmaped = mmap(NULL, sysconf(_SC_PAGESIZE), PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); if (mmaped == MAP_FAILED) { UNRESOLVED(errno, "mmap failed"); } /* Set the sharedpid pointer to this mmaped area */ sharedpid = (pid_t *) mmaped; /* Our data is now in shared memory */ #if VERBOSE > 1 output("Shared memory is ready.\n"); #endif /* Okay, let's create the child process */ hispid=fork(); if (hispid == (pid_t)-1) { UNRESOLVED(errno, "Fork failed"); } /* Child process : */ if (hispid == (pid_t)0) child(); /* Otherwise, we're the parent */ ctlpid = waitpid(hispid, &status, 0); if (ctlpid != hispid) { UNRESOLVED(errno, "waitpid waited for the wrong process"); } if (!WIFEXITED(status) || WEXITSTATUS(status)) { UNRESOLVED(status, "The child process did not terminate as expected"); } #if VERBOSE > 1 output("Child process pid: %d\n", hispid); #endif /* Check the child pid is the same as fork returned */ if (hispid != *sharedpid) { FAILED("getpid() in the child returned a different value than fork() in the parent"); } /* Check the child pid is different than the parent pid */ if (hispid == mypid) { FAILED("Both child and parent getpid() return values are equal"); } } #if VERBOSE > 0 output("Test passed\n"); #endif PASSED; } #else /* WITHOUT_XOPEN */ int main(int argc, char * argv[]) { output_init(); UNTESTED("This test requires XSI features"); } #endif posixtestsuite/conformance/interfaces/getpid/testfrmw.c0100644000000000000000000000407210160044245022600 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * * This file is a wrapper to use the tests from the NPTL Test & Trace Project * with either the Linux Test Project or the Open POSIX Test Suite. * The following function are defined: * void output_init() * void output_fini() * void output(char * string, ...) * * The are used to output informative text (as a printf). */ #include #include /* We use a mutex to avoid conflicts in traces */ static pthread_mutex_t m_trace = PTHREAD_MUTEX_INITIALIZER; /*****************************************************************************************/ /******************************* stdout module *****************************************/ /*****************************************************************************************/ /* The following functions will output to stdout */ #if (1) void output_init() { /* do nothing */ return; } void output( char * string, ... ) { va_list ap; char *ts="[??:??:??]"; struct tm * now; time_t nw; pthread_mutex_lock(&m_trace); nw = time(NULL); now = localtime(&nw); if (now == NULL) printf(ts); else printf("[%2.2d:%2.2d:%2.2d]", now->tm_hour, now->tm_min, now->tm_sec); va_start( ap, string); vprintf(string, ap); va_end(ap); pthread_mutex_unlock(&m_trace); } void output_fini() { /*do nothing */ return; } #endif posixtestsuite/conformance/interfaces/getpid/assertions.xml0100644000000000000000000000024210153372361023475 0ustar rootroot getpid() always returns the process ID of the calling thread/process. posixtestsuite/conformance/interfaces/getpid/coverage.txt0100644000000000000000000000015610153372361023121 0ustar rootrootThis file defines the coverage for the getpid() function testing. Assertion Status 1 YES posixtestsuite/conformance/interfaces/getpid/testfrmw.h0100644000000000000000000000456410160044245022613 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * * This file is a wrapper to use the tests from the NPTL Test & Trace Project * with either the Linux Test Project or the Open POSIX Test Suite. * The following macros are defined here: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate without calling one of those macros. * * */ #include "posixtest.h" #include /* for the strerror() routine */ #ifdef __GNUC__ /* We are using GCC */ #define UNRESOLVED(x, s) \ { output("Test %s unresolved: got %i (%s) on line %i (%s)\n", __FILE__, x, strerror(x), __LINE__, s); \ output_fini(); \ exit(PTS_UNRESOLVED); } #define FAILED(s) \ { output("Test %s FAILED: %s\n", __FILE__, s); \ output_fini(); \ exit(PTS_FAIL); } #define PASSED \ output_fini(); \ exit(PTS_PASS); #define UNTESTED(s) \ { output("File %s cannot test: %s\n", __FILE__, s); \ output_fini(); \ exit(PTS_UNTESTED); \ } #else /* not using GCC */ #define UNRESOLVED(x, s) \ { output("Test unresolved: got %i (%s) on line %i (%s)\n", x, strerror(x), __LINE__, s); \ output_fini(); \ exit(PTS_UNRESOLVED); } #define FAILED(s) \ { output("Test FAILED: %s\n", s); \ output_fini(); \ exit(PTS_FAIL); } #define PASSED \ output_fini(); \ exit(PTS_PASS); #define UNTESTED(s) \ { output("Unable to test: %s\n", s); \ output_fini(); \ exit(PTS_UNTESTED); \ } #endif posixtestsuite/conformance/interfaces/mlockall/0040755000000000000000000000000010515625166021116 5ustar rootrootposixtestsuite/conformance/interfaces/mlockall/speculative/0040755000000000000000000000000010515625166023442 5ustar rootrootposixtestsuite/conformance/interfaces/mlockall/speculative/15-1.c0100644000000000000000000000367310350034476024172 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that the mlockall() function set errno = EPERM if the calling process * does not have the appropriate privilege to perform the requested operation * * It is a may assertion. */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include #include "posixtest.h" /** Set the euid of this process to a non-root uid */ int set_nonroot() { struct passwd *pw; setpwent(); /* search for the first user which is non root */ while((pw = getpwent()) != NULL) if(strcmp(pw->pw_name, "root")) break; endpwent(); if(pw == NULL) { printf("There is no other user than current and root.\n"); return 1; } if(seteuid(pw->pw_uid) != 0) { if(errno == EPERM) { printf("You don't have permission to change your UID.\n"); return 1; } perror("An error occurs when calling seteuid()"); return 1; } printf("Testing with user '%s' (uid: %d)\n", pw->pw_name, (int)geteuid()); return 0; } int main() { int result; /* This test should be run under standard user permissions */ if (getuid() == 0) { if (set_nonroot() != 0) { printf("Cannot run this test as non-root user\n"); return PTS_UNTESTED; } } result = mlockall(MCL_CURRENT); if(result == -1 && errno == EPERM) { printf("Test PASSED\n"); return PTS_PASS; } else if(result == 0) { printf("You have the right to call mlockall\n"); return PTS_UNRESOLVED; } else { perror("Unexpected error"); return PTS_UNRESOLVED; } } posixtestsuite/conformance/interfaces/mlockall/7-1.sh0100755000000000000000000000031307700551114021744 0ustar rootroot#! /bin/sh # # Test that the appropriate privilege is required to lock process memory with # mlockall() # # This is tested implicitly via assertion 15. echo "Tested implicitly via assertion 15." exit 0 posixtestsuite/conformance/interfaces/mlockall/13-2.c0100644000000000000000000000164207700551114021635 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that the mlockall() function set errno = EINVAL if the flags argument * includes unimplemented flags. */ #include #include #include #include "posixtest.h" int main() { int result; result = mlockall(~(MCL_CURRENT|MCL_FUTURE)); if(result == -1 && errno == EINVAL) { printf("Test PASSED\n"); return PTS_PASS; } else if(result != -1) { printf("mlockall() return %i instead of -1.\n", result); return PTS_FAIL; } else { perror("Unexpected error"); return PTS_FAIL; } } posixtestsuite/conformance/interfaces/mlockall/3-6.c0100644000000000000000000000444007700764651021573 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that mlockall lock the shared memory pages currently mapped into the * address space of the process when MCL_CURRENT is set. * * This test use msync to check that the page is locked. */ /* ftruncate was formerly an XOPEN extension. We define _XOPEN_SOURCE here to avoid warning if the implementation does not program ftruncate as a base interface */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include "posixtest.h" #define BUF_SIZE 8 #define SHM_NAME "/posixtest_3-6" int main() { void *page_ptr; size_t page_size; int result, fd; void *foo; page_size = sysconf(_SC_PAGESIZE); if(errno) { perror("An error occurs when calling sysconf()"); return PTS_UNRESOLVED; } fd = shm_open(SHM_NAME, O_RDWR|O_CREAT, S_IRUSR|S_IWUSR); if(fd == -1) { perror("An error occurs when calling shm_open()"); return PTS_UNRESOLVED; } if(ftruncate(fd, BUF_SIZE) != 0) { perror("An error occurs when calling ftruncate()"); shm_unlink(SHM_NAME); return PTS_UNRESOLVED; } foo = mmap(NULL, BUF_SIZE, PROT_WRITE, MAP_SHARED, fd, 0); if( foo == MAP_FAILED) { perror("An error occurs when calling mmap()"); shm_unlink(SHM_NAME); return PTS_UNRESOLVED; } if(mlockall(MCL_CURRENT) == -1) { if(errno == EPERM){ printf("You don't have permission to lock your address space.\nTry to rerun this test as root.\n"); } else { perror("An error occurs when calling mlockall()"); } return PTS_UNRESOLVED; } page_ptr = (void*) ( (long)foo - ((long)foo % page_size) ); result = msync(page_ptr, page_size, MS_SYNC|MS_INVALIDATE); if(result == -1 && errno == EBUSY) { printf("Test PASSED\n"); return PTS_PASS; } else if(result == 0) { printf("The shared memory pages of the process are not locked.\n"); return PTS_FAIL; } perror("Unexpected error"); return PTS_UNRESOLVED; } posixtestsuite/conformance/interfaces/mlockall/9-1.sh0100755000000000000000000000031207700551114021745 0ustar rootroot#! /bin/sh # # Test that the mlockall() function return -1 upon unsuccessful completion. # # This is tested implicitly via assertions 12 to 15. echo "Tested implicitly via assertions 12 to 15." exit 0 posixtestsuite/conformance/interfaces/mlockall/13-1.c0100644000000000000000000000156507700551114021640 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that the mlockall() function set errno = EINVAL if the flags argument * is zero. */ #include #include #include #include "posixtest.h" int main() { int result; result = mlockall(0); if(result == -1 && errno == EINVAL) { printf("Test PASSED\n"); return PTS_PASS; } else if(result != -1) { printf("mlockall() return %i instead of -1.\n", result); return PTS_FAIL; } else { perror("Unexpected error"); return PTS_FAIL; } } posixtestsuite/conformance/interfaces/mlockall/assertions.xml0100644000000000000000000000722207700551114024023 0ustar rootroot The mlockall() function shall cause all of the pages mapped by the address space of a process to be memory-resident until unlocked or until the process exits or execs another process image The flags argument is constructed from the bitwise-inclusive OR of one or more of the folowing symbolic constants, defined in sys/mman.h: MCL_CURRENT MCL_FUTURE When the MCL_CURRENT flag is set, mlockall lock all of the pages currently mapped into the address space of the process When the MCL_FUTURE flag is set, mlockall lock all of the pages that become mapped into the address space of the process in the future, when those mappings are established If MCL_FUTURE is specified, and the automatic locking of future mappings eventually causes the amount of locked memory to exceed the amount of available physical memory or any other implementation-defined limit, the behavior is implementation-defined. The manner in which the implementation informs the application of these situations is also implementation-defined Upon successful return from the mlockall() function that specifies MCL_CURRENT, all currently mapped pages of the process' address space shall be memory-resident and locked The appropriate privilege is required to lock process memory with mlockall() Upon successful completion, the mlockall() function shall return a value of zero Upon unsuccessful completion, the mlockall() function shall return a value of -1 Upon unsuccessful completion, no additional memory shall be locked The effect of failure of mlockall() on previously existing locks in the address space is unspecified The mlockall() function shall set errno = EAGAIN if some or all of the memory identified by the operation could not be locked when the call was made The mlockall() function shall set errno = EINVAL if the flags argument is zero, or includes unimplemented flags The mlockall() function may set errno = ENOMEM if locking all of the pages currently mapped into the address space of the process would exceed an implementation-defined limit on the amount of memory that the process may lock The mlockall() function may set errno = EPERM if the calling process does not have the appropriate privilege to perform the requested operation posixtestsuite/conformance/interfaces/mlockall/coverage.txt0100644000000000000000000000074707700551114023450 0ustar rootrootThis document explains why certain assertions were not tested. Assertions not listed here should be covered by the tests in this directory. Assertions Tested ? Remarks 1 NO 2 YES 3 NO Only page mapped by mmap() are tested 4 NO 5 NO Implementation-defined 6 NO 7 YES 8 YES 9 YES 10 NO 11 NO Unspecified 12 NO 13 YES 14 YES May assertion 15 YES May assertion posixtestsuite/conformance/interfaces/mlockall/8-1.c0100644000000000000000000000177207700551114021564 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that mlockall return a value of zero upon successful completion. * */ #include #include #include #include "posixtest.h" int main() { int result; result = mlockall(MCL_CURRENT); if(result == 0 && errno == 0){ printf("Test PASSED\n"); return PTS_PASS; } else if(errno == 0) { printf("mlockall did not return a value of zero\n"); return PTS_FAIL; } else if(errno == EPERM) { printf("You don't have permission to lock your address space.\nTry to rerun this test as root.\n"); return PTS_UNRESOLVED; } perror("Unexpected error"); return PTS_UNRESOLVED; } posixtestsuite/conformance/interfaces/mlockall/3-7.c0100644000000000000000000000354207700764651021576 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that mlockall lock the mapped files pages currently mapped into the * address space of the process when MCL_CURRENT is set. * * This test use msync to check that the page is locked. */ #include #include #include #include #include #include "posixtest.h" int main() { void *page_ptr; size_t page_size; int result, fd; void *foo; page_size = sysconf(_SC_PAGESIZE); if(errno) { perror("An error occurs when calling sysconf()"); return PTS_UNRESOLVED; } fd = open("conformance/interfaces/mlockall/3-7.c", O_RDONLY); if(fd == -1) { perror("An error occurs when calling open()"); return PTS_UNRESOLVED; } foo = mmap(NULL, page_size, PROT_READ, MAP_SHARED, fd, 0); if(foo == MAP_FAILED) { perror("An error occurs when calling mmap()"); return PTS_UNRESOLVED; } if(mlockall(MCL_CURRENT) == -1) { if(errno == EPERM){ printf("You don't have permission to lock your address space.\nTry to rerun this test as root.\n"); } else { perror("An error occurs when calling mlockall()"); } return PTS_UNRESOLVED; } page_ptr = (void*) ( (long)foo - ((long)foo % page_size) ); result = msync(page_ptr, page_size, MS_SYNC|MS_INVALIDATE); if(result == -1 && errno == EBUSY) { printf("Test PASSED\n"); return PTS_PASS; } else if(result == 0) { printf("The mapped files pages of the process are not locked.\n"); return PTS_FAIL; } perror("Unexpected error"); return PTS_UNRESOLVED; } posixtestsuite/conformance/interfaces/mlockall/2-1.sh0100755000000000000000000000050007700551114021735 0ustar rootroot#! /bin/sh # # Test that the mlockall() checks that the flags argument is constructed from # the bitwise-inclusive OR of one or more of the folowing symbolic constants, # defined in sys/mman.h: # MCL_CURRENT # MCL_FUTURE # # This is tested implicitly via assertion 13. echo "Tested implicitly via assertion 13." exit 0 posixtestsuite/conformance/interfaces/mq_receive/0040755000000000000000000000000010515625172021434 5ustar rootrootposixtestsuite/conformance/interfaces/mq_receive/11-2.c0100644000000000000000000000356407634302715022170 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: crystal.xiong REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * mq_receive() test plan: * mq_receive() will fail with EBADF, if message queue * is not open for reading. */ #include #include #include #include #include #include #include #include #include #include "posixtest.h" #define TEST "11-2" #define FUNCTION "mq_receive" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " #define NAMESIZE 50 #define BUFFER 40 int main() { char mqname[NAMESIZE]; mqd_t mqdes; char msgrv[BUFFER]; struct mq_attr attr; int unresolved = 0, failure = 0; sprintf(mqname, "/" FUNCTION "_" TEST "_%d", getpid()); attr.mq_msgsize = BUFFER; attr.mq_maxmsg = BUFFER; mqdes = mq_open(mqname, O_CREAT | O_WRONLY, S_IRUSR | S_IWUSR, &attr); if (mqdes == (mqd_t)-1) { perror(ERROR_PREFIX "mq_open()"); unresolved = 1; } if (mq_receive(mqdes, msgrv, BUFFER, NULL) == -1) { if (EBADF != errno) { printf("errno != EBADF \n"); failure = 1; } } else { printf("mq_receive() succeed unexpectly \n"); failure = 1; } if (mq_close(mqdes) != 0) { perror(ERROR_PREFIX "mq_close"); unresolved=1; } if (mq_unlink(mqname) != 0) { perror(ERROR_PREFIX "mq_unlink()"); unresolved=1; } if (failure==1) { printf("Test FAILED\n"); return PTS_FAIL; } if (unresolved==1) { printf("Test UNRESOLVED\n"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/mq_receive/5-1.c0100644000000000000000000000525107641063626022110 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: crystal.xiong REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * mq_receive() test plan: * Test that if the message queue is empty and O_NONBLOCK is not set, * mq_receive() will block until a message is enqueued on the message queue * or until mq_receive() is interrupted by a signal. * * NOTE: This test makes some assumptions and has some potential race * conditions, but seems the best way to test for now. * * 3/28/2003 Fix a bug mentioned by Michal Wronski, pass mq_attr struct * to the mq_open(). */ #include #include #include #include #include #include #include #include #include #include "posixtest.h" #define TEST "5-1" #define FUNCTION "mq_receive" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " #define NAMESIZE 50 #define BUFFER 40 int main() { char mqname[NAMESIZE], msgrv[BUFFER]; const char *msgptr = "test message "; mqd_t mqdes; int prio = 1; int pid; struct mq_attr attr; int unresolved = 0, failure = 0; sprintf(mqname, "/" FUNCTION "_" TEST "_%d", getpid()); attr.mq_msgsize = BUFFER; attr.mq_maxmsg = BUFFER; mqdes = mq_open(mqname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, &attr); if (mqdes == (mqd_t)-1) { perror(ERROR_PREFIX "mq_open"); unresolved = 1; } if ((pid = fork()) != 0) { /* Parent process */ int status; if (mq_receive(mqdes, msgrv, BUFFER, NULL) > 0) { wait(&status); if (status) { printf("mq_send error \n"); unresolved = 1; } } else { wait(NULL); /* wait for child to exit */ perror(ERROR_PREFIX "mq_receive"); failure = 1; } if (mq_close(mqdes) != 0) { perror(ERROR_PREFIX "mq_close"); unresolved = 1; } if (mq_unlink(mqname) != 0) { perror(ERROR_PREFIX "mq_unlink"); unresolved = 1; } if (failure==1) { printf("Test FAILED\n"); return PTS_FAIL; } if (unresolved==1) { printf("Test UNRESOLVED\n"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } else { /* Child Process */ sleep(2); /* sleep 2 seconds, assume that child will block on waiting then */ if (mq_send(mqdes, msgptr, strlen(msgptr), prio) == -1) { perror(ERROR_PREFIX "mq_send"); return PTS_UNRESOLVED; } return 0; } return PTS_UNRESOLVED; } posixtestsuite/conformance/interfaces/mq_receive/12-1.c0100644000000000000000000000416307632257760022173 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: crystal.xiong REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * mq_receive test plan: * mq_receive will return EMSGSIZE when msg_len is less than the * message size attribute of the message queue. */ #include #include #include #include #include #include #include #include #include "posixtest.h" #define TEST "12-1" #define FUNCTION "mq_receive" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " #define NAMESIZE 50 #define BUFFER 20 int main() { char mqname[NAMESIZE], msgrv[BUFFER]; const char *msgptr = "test message"; mqd_t mqdes; int prio = 1; struct mq_attr mqstat; int unresolved = 0, failure = 0; sprintf(mqname, "/" FUNCTION "_" TEST "_%d", getpid()); memset(&mqstat,0,sizeof(mqstat)); mqstat.mq_msgsize = BUFFER + 1; mqstat.mq_maxmsg = BUFFER + 1; mqdes = mq_open(mqname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, &mqstat); if (mqdes == (mqd_t)-1) { perror(ERROR_PREFIX "mq_open"); unresolved = 1; } if (mq_send(mqdes, msgptr, strlen(msgptr), prio) != 0) { perror(ERROR_PREFIX "mq_send"); unresolved = 1; } if (mq_receive(mqdes, msgrv, BUFFER, NULL) == 0) { printf("FAIL: mq_receive succeed unexpectly\n"); failure = 1; } else { if (EMSGSIZE != errno) { printf("errno != EMSGSIZE \n"); failure = 1; } } if (mq_close(mqdes) != 0) { perror(ERROR_PREFIX "mq_close"); unresolved = 1; } if (mq_unlink(mqname) != 0) { perror(ERROR_PREFIX "mq_unlink"); unresolved = 1; } if (failure==1) { printf("Test FAILED\n"); return PTS_FAIL; } if (unresolved==1) { printf("Test UNRESOLVED\n"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/mq_receive/1-1.c0100644000000000000000000000567410336125320022076 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: crystal.xiong REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * mq_receive test plan: * mq_receive will receive the oldest of the highest priority messages * from the message queue. The selected message will be removed from the * queue and copied to the buffer pointed by the msg_ptr argument. */ #include #include #include #include #include #include #include #include "posixtest.h" #define TEST "1-1" #define FUNCTION "mq_receive" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " #define NAMESIZE 50 #define BUFFER 40 int main() { char mqname[NAMESIZE], msgrv1[BUFFER], msgrv2[BUFFER]; const char *msgptr1 = "test message 1"; const char *msgptr2 = "test message 2"; mqd_t mqdes; unsigned rvprio; int sdprio1 = 1, sdprio2 = 2; struct mq_attr attr; int unresolved = 0, failure = 0; sprintf(mqname, "/" FUNCTION "_" TEST "_%d", getpid()); attr.mq_msgsize = BUFFER; attr.mq_maxmsg = BUFFER; mqdes = mq_open(mqname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, &attr); if (mqdes == (mqd_t)-1) { perror(ERROR_PREFIX "mq_open"); unresolved = 1; } if (mq_send(mqdes, msgptr1, strlen(msgptr1), sdprio1) != 0) { perror(ERROR_PREFIX "mq_send"); unresolved = 1; } if (mq_send(mqdes, msgptr2, strlen(msgptr2), sdprio2) != 0) { perror(ERROR_PREFIX "mq_send"); unresolved = 1; } if (mq_receive(mqdes, msgrv1, BUFFER, &rvprio) == -1) { perror(ERROR_PREFIX "mq_receive"); failure = 1; } if (strncmp(msgptr2, msgrv1, strlen(msgptr2)) != 0) { printf("FAIL: mq_receive didn't receive the highest priority message\n"); failure = 1; } if (rvprio != sdprio2) { printf("FAIL: receive priority %d != send priority %d \n", rvprio, sdprio2); failure = 1; } if (mq_receive(mqdes, msgrv2, BUFFER, &rvprio) == -1) { perror(ERROR_PREFIX "mq_receive"); failure = 1; } if (strncmp(msgptr1, msgrv2, strlen(msgptr1)) != 0) { printf("FAIL: mq_receive didn't receive the correct message\n"); failure = 1; } if (rvprio != sdprio1) { printf("FAIL: receive priority %d != send priority %d \n", rvprio, sdprio1); failure = 1; } if (mq_close(mqdes) != 0) { perror(ERROR_PREFIX "mq_close"); unresolved = 1; } if (mq_unlink(mqname) != 0) { perror(ERROR_PREFIX "mq_unlink"); unresolved = 1; } if (failure==1) { printf("Test FAILED\n"); return PTS_FAIL; } if (unresolved==1) { printf("Test UNRESOLVED\n"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/mq_receive/9-1.sh0100755000000000000000000000101607632103001022260 0ustar rootroot#!/bin/sh # Copyright (c) 2003, Intel Corporation. All rights reserved. # Created by: crystal.xiong REMOVE-THIS AT intel DOT com # This file is licensed under the GPL license. For the full content # of this license, see the COPYING file at the top level of this # source tree. # Test on failure, no message will be removed from the queue, # the funcion will return a value of -1. # This is tested implicitly via assertion 10,11,12,13 echo "Tested implicitly via assertion 10,11,12,13. See output for status" exit 0 posixtestsuite/conformance/interfaces/mq_receive/11-1.c0100644000000000000000000000363207634302715022163 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: crystal.xiong REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * mq_receive() test plan: * mq_receive() will fail with EBADF, if mqdes is not a valid message * message queue descriptor. */ #include #include #include #include #include #include #include #include #include #include "posixtest.h" #define TEST "11-1" #define FUNCTION "mq_receive" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " #define NAMESIZE 50 #define BUFFER 40 int main() { char mqname[NAMESIZE]; mqd_t mqdes; char msgrv[BUFFER]; struct mq_attr attr; int unresolved = 0, failure = 0; sprintf(mqname, "/" FUNCTION "_" TEST "_%d", getpid()); attr.mq_msgsize = BUFFER; attr.mq_maxmsg = BUFFER; mqdes = mq_open(mqname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, &attr); if (mqdes == (mqd_t)-1) { perror(ERROR_PREFIX "mq_open()"); unresolved = 1; } mqdes = mqdes + 1; if (mq_receive(mqdes, msgrv, BUFFER, NULL) == -1) { if (EBADF != errno) { printf("errno != EBADF \n"); failure = 1; } } else { printf("mq_receive() succeed unexpectly \n"); failure = 1; } if (mq_close(mqdes - 1) != 0) { perror(ERROR_PREFIX "mq_close()"); unresolved=1; } if (mq_unlink(mqname) != 0) { perror(ERROR_PREFIX "mq_unlink()"); unresolved=1; } if (failure==1) { printf("Test FAILED\n"); return PTS_FAIL; } if (unresolved==1) { printf("Test UNRESOLVED\n"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/mq_receive/10-1.c0100644000000000000000000000361107634302715022157 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: crystal.xiong REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * mq_receive() test plan: * mq_receive() will fail with EAGAIN, if message queue is empty and * O_NONBLOCK is set in the message queue, */ #include #include #include #include #include #include #include #include #include #include "posixtest.h" #define TEST "10-1" #define FUNCTION "mq_receive" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " #define NAMESIZE 50 #define BUFFER 40 int main() { char mqname[NAMESIZE], msgrv[BUFFER]; mqd_t mqdes; struct mq_attr attr; int unresolved = 0, failure = 0; sprintf(mqname, "/" FUNCTION "_" TEST "_%d", getpid()); attr.mq_msgsize = BUFFER; attr.mq_maxmsg = BUFFER; mqdes = mq_open(mqname, O_CREAT | O_NONBLOCK | O_RDWR, S_IRUSR | S_IWUSR, &attr); if (mqdes == (mqd_t)-1) { perror(ERROR_PREFIX "mq_open"); unresolved = 1; } if (mq_receive(mqdes, msgrv, BUFFER, NULL) == -1) { if (EAGAIN != errno) { printf("errno != EAGAIN \n"); failure = 1; } } else { printf("mq_receive() succeed unexpectly\n"); failure = 1; } if (mq_close(mqdes) != 0) { perror(ERROR_PREFIX "mq_close"); unresolved = 1; } if (mq_unlink(mqname) != 0) { perror(ERROR_PREFIX "mq_unlink"); unresolved = 1; } if (failure==1) { printf("Test FAILED\n"); return PTS_FAIL; } if (unresolved==1) { printf("Test UNRESOLVED\n"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/mq_receive/13-1.c0100644000000000000000000000464310035502477022164 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: crystal.xiong REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * mq_receive() test plan: * mq_receive() will fail with EINTR if mq_receive() is interrupted by a signal. * */ #include #include #include #include #include #include #include #include #include #include #include #include "posixtest.h" #define TEST "13-1" #define FUNCTION "mq_receive" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " #define NAMESIZE 50 #define BUFFER 40 void stopreceive(int signo) { return; } int main() { char mqname[NAMESIZE], msgrv[BUFFER]; mqd_t mqdes; int pid; struct mq_attr attr; int unresolved = 0, failure = 0; sprintf(mqname, "/" FUNCTION "_" TEST "_%d", getpid()); attr.mq_msgsize = BUFFER; attr.mq_maxmsg = BUFFER; mqdes = mq_open(mqname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, &attr); if (mqdes == (mqd_t)-1) { perror(ERROR_PREFIX "mq_open"); unresolved = 1; } if ((pid = fork()) != 0) { /* Parent process */ struct sigaction act; act.sa_handler = stopreceive; act.sa_flags = 0; sigemptyset(&act.sa_mask); sigaction(SIGABRT, &act, 0); if (mq_receive(mqdes, msgrv, BUFFER, NULL) == -1) { wait(NULL); if (EINTR != errno) { printf("errno != EINVAL \n"); failure = 1; } } else { wait(NULL); printf("mq_receive() succeed unexpectly \n"); failure = 1; } if (mq_close(mqdes) != 0) { perror("mq_close() did not return success"); unresolved=1; } if (mq_unlink(mqname) != 0) { perror("mq_unlink() did not return success"); unresolved=1; } if (failure==1) { printf("Test FAILED\n"); return PTS_FAIL; } if (unresolved==1) { printf("Test UNRESOLVED\n"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } else { /* Child Process */ sleep(2); /* give time to parent to set up handler */ /* send signal to parent */ kill(getppid(), SIGABRT); } return PTS_UNRESOLVED; } posixtestsuite/conformance/interfaces/mq_receive/7-1.c0100644000000000000000000000350107634302715022103 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: crystal.xiong REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * mq_receive() test plan: * If message queue is empty and O_NONBLOCK is set in the message queue, * no message will be removed from the queue, mq_receive will return an * error. */ #include #include #include #include #include #include #include #include #include "posixtest.h" #define TEST "7-1" #define FUNCTION "mq_receive" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " #define NAMESIZE 50 #define BUFFER 40 int main() { char mqname[NAMESIZE], msgrv[BUFFER]; mqd_t mqdes; struct mq_attr attr; int unresolved = 0, failure = 0; sprintf(mqname, "/" FUNCTION "_" TEST "_%d", getpid()); attr.mq_msgsize = BUFFER; attr.mq_maxmsg = BUFFER; mqdes = mq_open(mqname, O_CREAT | O_NONBLOCK | O_RDWR, S_IRUSR | S_IWUSR, &attr); if (mqdes == (mqd_t)-1) { perror(ERROR_PREFIX "mq_open"); unresolved = 1; } if (mq_receive(mqdes, msgrv, BUFFER, NULL) != -1) { printf("mq_receive succeed unexpectly \n"); failure = 1; } if (mq_close(mqdes) != 0) { perror(ERROR_PREFIX "mq_close"); unresolved = 1; } if (mq_unlink(mqname) != 0) { perror(ERROR_PREFIX "mq_unlink"); unresolved = 1; } if (failure==1) { printf("Test FAILED\n"); return PTS_FAIL; } if (unresolved==1) { printf("Test UNRESOLVED\n"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/mq_receive/assertions.xml0100644000000000000000000000577107633255741024367 0ustar rootroot mq_receive() receive the oldest of the highest priority message(s) from the message queue specified by mqdes. The selected message will be removed from the queue and copied to the buffer pointed to by the msg_ptr argument. mq_receive() will fail and return an error if the size of the buffer in bytes, specified by the msg_len argument, is less than the mq_msgsize attribute of the message queue. if msg_len is greater than SSIZE_MAX, the result is implementation-defined. If msg_prio is not NULL, the priority of the selected message will be stored in the location referenced by msg_prio. If the specified message queue is empty and O_NONBLOCK is not set, then mq_receive() will block until a message is enqueued on the message queue or until a signal interrupts mq_receive(). If there are more than one thread waiting to receive a message when a message arrives at an empty queue and the Priority Scheduling option is supported, then the thread with highest priority that has been waiting the longest will receive the message. If Priority Scheduling option is not supported, then it is unspecified which waiting thread is able to receive the message. If the specified message queue is empty and O_NONBLOCK is set, no message will be removed from the queue, and mq_receive() will return an error. mq_receive() will return the length of the selected message in bytes and the message will be removed from the queue on success. mq_receive() will return -1 on failure, nomessage will be removed from the queue, and the errno will be set. mq_receive() will return EAGAIN if O_NONBLOCK is set and the message queue is empty. mq_receive() will return EBADF if mqdes is not a valid message queue descriptor open for reading. mq_receive() will return EMSGSIZE if the specified buffer size, msg_len, is less than the message size attribute of the message queue. mq_receive() will return EINTR if it is interrupted by a signal mq_receive() will return EBADMSG if the implementation has detected a data corruption problem with the message. posixtestsuite/conformance/interfaces/mq_receive/coverage.txt0100644000000000000000000000037407633307416023776 0ustar rootrootThis document defines the coverage for the mq_receive function: Assertion Tested? 1 YES 2 YES 3 NO - implementation-defined, won't test. 4 YES 5 YES 6 NO - won't test. 7 YES 8 YES 9 YES 10 YES 11 YES 12 YES 13 YES 14 NO - won't test. posixtestsuite/conformance/interfaces/mq_receive/8-1.c0100644000000000000000000000545407634302715022115 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: crystal.xiong REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * mq_receive test plan: * On success, mq_receive will return the length of the selected message * and the message will be removed from the queue. * step: * 1. send two messages to the message queue * 2. call mq_receive() twice, if the two received messages are the same, * which means the first mq_receive does not remove the message from * the queue, the test will fail. Otherwise, the test will pass. */ #include #include #include #include #include #include #include #include "posixtest.h" #define TEST "8-1" #define FUNCTION "mq_receive" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " #define NAMESIZE 50 #define BUFFER 40 int main() { char mqname[NAMESIZE], msgrv1[BUFFER], msgrv2[BUFFER]; const char *msgptr1 = "test message1"; const char *msgptr2 = "test message2 with differnet length"; mqd_t mqdes; int prio1 = 1, prio2 = 2; struct mq_attr attr; int unresolved = 0, failure = 0; sprintf(mqname, "/" FUNCTION "_" TEST "_%d", getpid()); attr.mq_msgsize = BUFFER; attr.mq_maxmsg = BUFFER; mqdes = mq_open(mqname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, &attr); if (mqdes == (mqd_t)-1) { perror(ERROR_PREFIX "mq_open"); unresolved = 1; } if (mq_send(mqdes, msgptr1, strlen(msgptr1), prio1) != 0) { perror(ERROR_PREFIX "mq_send"); unresolved = 1; } if (mq_send(mqdes, msgptr2, strlen(msgptr2), prio2) != 0) { perror(ERROR_PREFIX "mq_send"); unresolved = 1; } if (mq_receive(mqdes, msgrv1, BUFFER, NULL) != strlen(msgptr2)) { printf("FAIL: mq_receive didn't return the selected message size correctly \n"); failure = 1; } if (mq_receive(mqdes, msgrv2, BUFFER, NULL) != strlen(msgptr1)) { printf("FAIL: mq_receive didn't return the selected message size correctly \n"); failure = 1; } if (!strcmp(msgrv1,msgrv2)) { printf("FAIL: mq_receive received the same message twice\n"); failure = 1; } if (mq_close(mqdes) != 0) { perror(ERROR_PREFIX "mq_close"); unresolved = 1; } if (mq_unlink(mqname) != 0) { perror(ERROR_PREFIX "mq_unlink"); unresolved = 1; } if (failure==1) { printf("Test FAILED\n"); return PTS_FAIL; } if (unresolved==1) { printf("Test UNRESOLVED\n"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/mq_receive/2-1.c0100644000000000000000000000377207632257760022117 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: crystal.xiong REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * mq_receive test plan: * If the buffer size is less than the mq_msgsize attribute, the function * will fail and return an error. */ #include #include #include #include #include #include #include #include "posixtest.h" #define TEST "2-1" #define FUNCTION "mq_receive" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " #define NAMESIZE 50 #define BUFFER 20 int main() { char mqname[NAMESIZE], msgrv[BUFFER]; const char *msgptr = "test message"; mqd_t mqdes; int prio = 1; struct mq_attr mqstat; int unresolved = 0, failure = 0; sprintf(mqname, "/" FUNCTION "_" TEST "_%d", getpid()); memset(&mqstat,0,sizeof(mqstat)); mqstat.mq_msgsize = BUFFER + 1; mqstat.mq_maxmsg = BUFFER + 1; mqdes = mq_open(mqname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, &mqstat); if (mqdes == (mqd_t)-1) { perror(ERROR_PREFIX "mq_open"); unresolved = 1; } if (mq_send(mqdes, msgptr, strlen(msgptr), prio) != 0) { perror(ERROR_PREFIX "mq_send"); unresolved = 1; } if (mq_receive(mqdes, msgrv, BUFFER, NULL) > 0) { printf("FAIL: mq_receive succeed unexpectly \n"); failure = 1; } if (mq_close(mqdes) != 0) { perror(ERROR_PREFIX "mq_close"); unresolved = 1; } if (mq_unlink(mqname) != 0) { perror(ERROR_PREFIX "mq_unlink"); unresolved = 1; } if (failure==1) { printf("Test FAILED\n"); return PTS_FAIL; } if (unresolved==1) { printf("Test UNRESOLVED\n"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/mq_receive/4-1.sh0100755000000000000000000000102307632103241022257 0ustar rootroot#!/bin/sh # Copyright (c) 2003, Intel Corporation. All rights reserved. # Created by: crystal.xiong REMOVE-THIS AT intel DOT com # This file is licensed under the GPL license. For the full content # of this license, see the COPYING file at the top level of this # source tree. # Test if the msg_prio is not NULL, the priority of the selected # message will be stored in the location pointed by msg_prio. # This is tested implicitly via assertion 1. echo "Tested implicitly via assertion 1. See output for status" exit 0 posixtestsuite/conformance/interfaces/pthread_condattr_setclock/0040755000000000000000000000000010515625210024522 5ustar rootrootposixtestsuite/conformance/interfaces/pthread_condattr_setclock/1-3.c0100644000000000000000000000317010470232724025170 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: bing.wei.liu REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_condattr_setclock() * * If it is called with a clock_id argument that refers to a CPU-time clock, the call * shall fail. * * Steps: * 1. Initialize a pthread_condattr_t object * 2. Get the cpu clock id * 3. Call pthread_condattr_setclock passing this clock id to it * 4. It should fail. * */ # define _XOPEN_SOURCE 600 #include #include #include #include #include #include "posixtest.h" int main() { #if _POSIX_CPUTIME == -1 printf("_POSIX_CPUTIME unsupported\n"); return PTS_UNSUPPORTED; #endif pthread_condattr_t condattr; clockid_t clockid; int rc; if (sysconf(_SC_CPUTIME) == -1) { printf("_POSIX_CPUTIME unsupported\n"); return PTS_UNSUPPORTED; } /* Initialize a cond attributes object */ if((rc=pthread_condattr_init(&condattr)) != 0) { fprintf(stderr,"Error at pthread_condattr_init(), rc=%d\n",rc); printf("Test FAILED\n"); return PTS_FAIL; } /* Get the cpu clock id */ if (clock_getcpuclockid(getpid(), &clockid) != 0) { printf("clock_getcpuclockid() failed\n"); return PTS_FAIL; } rc = pthread_condattr_setclock(&condattr, clockid); if(rc != EINVAL) { printf("Test FAILED: Expected EINVAL when passing a cpu clock id, instead it returned: %d \n", rc); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_condattr_setclock/1-1.c0100644000000000000000000000216307675665122025206 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: bing.wei.liu REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_condattr_setclock() * shall set the 'clock' attribute in an initialized attributes object referenced by * 'attr'. * * Steps: * 1. Initialize a pthread_condattr_t object * 2. Set the clock to CLOCK_REALTIME * 3. Check that it was set successfully * */ # define _XOPEN_SOURCE 600 #include #include #include "posixtest.h" int main() { pthread_condattr_t condattr; int rc; /* Initialize a cond attributes object */ if((rc=pthread_condattr_init(&condattr)) != 0) { fprintf(stderr,"Error at pthread_condattr_init(), rc=%d\n",rc); printf("Test FAILED\n"); return PTS_FAIL; } rc = pthread_condattr_setclock(&condattr, CLOCK_REALTIME); if(rc != 0) { printf("Test FAILED: Could not set clock to CLOCK_REALTIME\n"); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_condattr_setclock/1-2.c0100644000000000000000000000276607675665122025220 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: bing.wei.liu REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_condattr_setclock() * shall set the 'clock' attribute in an initialized attributes object referenced by * 'attr'. * * Steps: * 1. Initialize a pthread_condattr_t object * 2. Set the clock to CLOCK_MONOTONIC (if the kernel has that capability) * 3. Check that it was set successfully * * *FIX-ME: Need to find a better check on whether the kernel supports CLOCK_MONOTONIC * clocks or not. * */ # define _XOPEN_SOURCE 600 #include #include #include #include "posixtest.h" int main() { pthread_condattr_t condattr; struct timespec ts; int rc; /* Check whether kernel supports CLOCK_MONOTONIC */ rc = clock_getres(CLOCK_MONOTONIC, &ts); if(rc != 0) { printf("UNSUPPORTED: CLOCK_MONOTONIC is unsupported\n"); return PTS_UNSUPPORTED; } /* Initialize a cond attributes object */ if((rc=pthread_condattr_init(&condattr)) != 0) { fprintf(stderr,"Error at pthread_condattr_init(), rc=%d\n",rc); printf("Test FAILED\n"); return PTS_FAIL; } rc = pthread_condattr_setclock(&condattr, CLOCK_MONOTONIC); if(rc != 0) { printf("Test FAILED: Could not set clock to CLOCK_MONOTONIC\n"); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_condattr_setclock/assertions.xml0100644000000000000000000000121510117555065027442 0ustar rootroot The function int pthread_condattr_setclock(pthread_condattr_t *attr, clockid_t clock_id); shall set the 'clock' attribute in an initialized attributes object referenced by 'attr'. If it is called with a clock_id argument that refers to a CPU-time clock, the call shall fail. It returns 0 upon success, and an error code if it fails: It may fail if: [EINVAL] - the 'attr' value is invalid [EINVAL] - 'clock_id' doesn't refer to a known clock or is a CPU-time clock. posixtestsuite/conformance/interfaces/pthread_condattr_setclock/coverage.txt0100644000000000000000000000016707675655333027105 0ustar rootrootThis document defines the coverage for the pthread_condattr_setclock function: Assertion Tested? 1 YES 2 YES NOTE: posixtestsuite/conformance/interfaces/pthread_condattr_setclock/2-1.c0100644000000000000000000000246407675665122025213 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: bing.wei.liu REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_condattr_setclock() * It returns 0 upon success, and an error code if it fails: * * It may fail if: * * [EINVAL] - the 'attr' value is invalid * [EINVAL] - 'clock_id' doesn't refer to a known clock or is a CPU-time clock. * * Steps: * 1. Initialize a pthread_condattr_t object * 2. Set the clock to an invalid value * 3. It should fail * */ # define _XOPEN_SOURCE 600 #include #include #include #include "posixtest.h" #define INVALID_CLOCKID -100 int main() { pthread_condattr_t condattr; int rc; /* Initialize a cond attributes object */ if((rc=pthread_condattr_init(&condattr)) != 0) { fprintf(stderr,"Error at pthread_condattr_init(), rc=%d\n",rc); printf("Test FAILED\n"); return PTS_FAIL; } rc = pthread_condattr_setclock(&condattr, INVALID_CLOCKID); if(rc != EINVAL) { printf("Test PASSED: *NOTE: Test passed while passing an invalid clockid, but the standard says 'may' fail\n"); return PTS_PASS; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_condattr_init/0040755000000000000000000000000010515625210023656 5ustar rootrootposixtestsuite/conformance/interfaces/pthread_condattr_init/1-1.c0100644000000000000000000000326107650707441024334 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: bing.wei.liu REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_condattr_init() * shall initialize a condition variable attribute object 'attr' with the default * value for all of the attributes defined by the implementation. * Steps: * 1. Initialize a pthread_condattr_t object with pthread_condattr_init() * 2. Call pthread_condattr_getpshared() to check if the process-shared * attribute is set as the default value PTHREAD_PROCESS_PRIVATE. * */ #include #include #include "posixtest.h" int main() { pthread_condattr_t condattr; int rc; #ifdef PTHREAD_PROCESS_SHARED int pshared; #endif /* Initialize a cond attributes object */ if((rc=pthread_condattr_init(&condattr)) != 0) { fprintf(stderr,"Error at pthread_condattr_init(), rc=%d\n",rc); printf("Test FAILED\n"); return PTS_FAIL; } #ifdef PTHREAD_PROCESS_SHARED /* If the symbol {PTHREAD_PROCESS_SHARED} is defined, the attribute * process-shared should be provided and its default value should be * PTHREAD_PROCESS_PRIVATE */ if(pthread_condattr_getpshared(&condattr, &pshared) != 0) { fprintf(stderr,"Error obtaining the attribute process-shared\n"); return PTS_UNRESOLVED; } if(pshared == PTHREAD_PROCESS_PRIVATE) { printf("Test PASSED\n"); return PTS_PASS; } else { printf("Test FAILED\n"); return PTS_FAIL; } #endif fprintf(stderr,"process-shared attribute is not available for testing\n"); return PTS_UNRESOLVED; } posixtestsuite/conformance/interfaces/pthread_condattr_init/assertions.xml0100644000000000000000000000166210117555065026604 0ustar rootroot The function int pthread_condattr_init(pthread_condattr_t *attr); shall initialize a condition variable attributes object attr with the default value for all of the attributes defined by the implementation. After a condition variable attributes object has been used to initialize one or more condition variables, any function affecting the attributes object (including destruction) shall not affect any previously initialized condition variables. If successful, it shall return zero; The pthread_condattr_init() function shall fail if: [ENOMEM] Insufficient memory exists to initialize the condition variable attributes object. posixtestsuite/conformance/interfaces/pthread_condattr_init/coverage.txt0100644000000000000000000000044407650707441026226 0ustar rootrootThis document defines the coverage for the pthread_condattr_init function: Assertion Tested? 1 YES 2 NO *Looking for a way to judge if initialized condition variables are affected. 3 YES 4 NO * Looking for a way to produce the error conditions NOTE: posixtestsuite/conformance/interfaces/pthread_condattr_init/3-1.c0100644000000000000000000000231307650707441024333 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: bing.wei.liu REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_condattr_init() * Upon successful completion, pthread_condattr_init() shall return a value of 0. * Steps: * 1. Initialize a pthread_condattr_t object with pthread_condattr_init() * 2. ENOMEM is the only error it returns, so if it doesn't return that error, * the return number should be 0. */ #include #include #include #include "posixtest.h" int main() { pthread_condattr_t condattr; int rc; /* Initialize a condition variable attributes object */ if((rc=pthread_condattr_init(&condattr)) == 0) { printf("Test PASSED\n"); return PTS_PASS; } /* Insufficient memory exists to initialize the condition variable attributes object */ else if(rc == ENOMEM) { fprintf(stderr,"pthread_condattr_init() returns ENOMEM\n"); return PTS_UNRESOLVED; } /* Any other returned value means the test failed */ else { printf("Test FAILED\n"); return PTS_FAIL; } } posixtestsuite/conformance/interfaces/fsync/0040755000000000000000000000000010515625164020440 5ustar rootrootposixtestsuite/conformance/interfaces/fsync/5-1.c0100644000000000000000000000160707730426451021112 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * The fsync( ) function shall fail if: * [EBADF] The fildes argument is not a valid descriptor. * */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include #include #include #include "posixtest.h" int main() { int fd; /* -1 is an invalid fd */ fd = -1; if (fsync(fd) == -1 && errno == EBADF) { printf("Got EBADF when fd=-1\n"); printf("Test PASSED\n"); exit(PTS_PASS); } else { printf("Test FAILED: Expect EBADF, get: %s\n", strerror(errno)); exit(PTS_FAIL); } } posixtestsuite/conformance/interfaces/fsync/4-1.c0100644000000000000000000000324407730426451021110 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Upon successful completion, fsync( ) shall return 0. * Otherwise, .1 shall be returned and errno set * to indicate the error. If the fsync( ) function fails. * * 1. Create a regular file; * 2. Write a few bytes to the file, call fsycn(), should return 0; * */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include #include #include #include "posixtest.h" #define TNAME "fsync/4-1.c" int main() { char tmpfname[256]; char* data; int total_size = 1024; int fd; snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_fsync_4_1_%d", getpid()); unlink(tmpfname); fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL, S_IRUSR | S_IWUSR); if (fd == -1) { printf(TNAME " Error at open(): %s\n", strerror(errno)); exit(PTS_UNRESOLVED); } /* Make sure the file is removed when it is closed */ unlink(tmpfname); data = (char *) malloc(total_size); memset(data, 'a', total_size); if (write(fd, data, total_size) != total_size) { printf(TNAME "Error at write(): %s\n", strerror(errno)); free(data); exit(PTS_UNRESOLVED); } free(data); if (fsync(fd) == -1) { printf(TNAME "Error at fsync(): %s\n", strerror(errno)); exit(PTS_FAIL); } close(fd); printf ("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/fsync/7-1.c0100644000000000000000000000236207730426451021113 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * * The fsync( ) function shall fail if: * [EINVAL] The fildes argument does not refer to a file * on which this operation is possible. * * Test Step: * 1. Create a pipe; * 2. fsync on the pipe, should fail with EINVAL; * */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include #include #include #include "posixtest.h" #define TNAME "fsync/7-1.c" int main() { int fd[2]; if (pipe(fd) == -1) { printf(TNAME " Test UNRESOLVED: Error at pipe: %s\n", strerror(errno)); exit(PTS_UNRESOLVED); } if (fsync(fd[1]) == -1 && errno == EINVAL) { printf("Got EINVAL when fsync on pipe\n"); printf("Test PASSED\n"); close(fd[0]); close(fd[1]); exit(PTS_PASS); } else { printf(TNAME " Test Fail: Expect EINVAL, get: %s\n", strerror(errno)); close(fd[0]); close(fd[1]); exit(PTS_FAIL); } } posixtestsuite/conformance/interfaces/fsync/assertions.xml0100644000000000000000000000417507730426451023363 0ustar rootroot The fsync( ) function shall request that all data for the open file descriptor named by fildes is to be transferred to the storage device associated with the file described by fildes in an implementation-defined manner. The fsync( ) function shall not return until the system has completed that action or until an error is detected. SIO If _POSIX_SYNCHRONIZED_IO is defined, the fsync( ) function shall force all currently queuee I/O operations associated with the file indicated by file descriptor fildes to the synchronized I/O completion state. All I/O operations shall be completed as defined for synchronized I/O file integrity completion. Upon successful completion, fsync( ) shall return 0. Otherwise, .1 shall be returned and errno set to indicate the error. If the fsync( ) function fails, outstanding I/O operations are not guaranteed to have been completed. The fsync( ) function shall fail if: [EBADF] The fildes argument is not a valid descriptor. The fsync( ) function shall fail if: [EINTR] The fsync( ) function was interrupted by a signal. The fsync( ) function shall fail if: [EINVAL] The fildes argument does not refer to a file on which this operation is possible. The fsync( ) function shall fail if: [EIO] An I/O error occurred while reading from or writing to the file system. In the event that any of the queued I/O operations fail, fsync( ) shall return the error conditions defined for read( ) and write( ). posixtestsuite/conformance/interfaces/fsync/coverage.txt0100644000000000000000000000154607730426451023002 0ustar rootrootThis document defines the coverage for the fsync() function: Assertion Tested? 1 NO 2 NO 3 NO ** Synchronized I/O 4 YES 5 YES 6 NO 7 YES 8 NO: ** Not sure how to generate an I/O error 9 NO: ** Synchronized I/O NOTE: Assertion 1 is hard to test. Here cited the specification: It is reasonable to assert that the key aspects of fsync( ) are unreasonable to test in a test suite. That does not make the function any less valuable, just more difficult to test. A formal conformance test should probably force a system crash (power shutdown) during the test for this condition, but it needs to be done in such a way that automated testing does not require this to be done except when a formal record of the results is being made. It would also not be unreasonable to omit testing for fsync( ), allowing it to be treated as a quality-of-implementation issue. posixtestsuite/conformance/interfaces/pthread_attr_setscope/0040755000000000000000000000000010515625200023673 5ustar rootrootposixtestsuite/conformance/interfaces/pthread_attr_setscope/5-1.c0100644000000000000000000000262110044434055024342 0ustar rootroot/* * Copyright (c) 2004, Intel Corporation. All rights reserved. * Created by: crystal.xiong REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test pthread_attr_setscope() * * Steps: * 1. Initialize a pthread_attr_t object using pthread_attr_init() * 2. Call pthread_attr_setscope with unsupported scope * parameter * */ #include #include #include #include #include "posixtest.h" #define TEST "5-1" #define FUNCTION "pthread_attr_setscope" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " /* What is the unsupported value of scope paramter? */ #define UNSUPSCOPE -1 int main() { if (1) { printf("Untested for now, cannot find a unsupported inheritsched value\n"); return PTS_UNTESTED; } int rc=0; pthread_attr_t attr; rc = pthread_attr_init(&attr); if (rc != 0) { printf(ERROR_PREFIX "pthread_attr_init\n"); exit(PTS_UNRESOLVED); } rc = pthread_attr_setscope(&attr, UNSUPSCOPE); if ((rc != ENOTSUP)) { printf(ERROR_PREFIX "pthread_attr_setscope\n"); exit(PTS_UNRESOLVED); } rc = pthread_attr_destroy(&attr); if( rc != 0) { printf(ERROR_PREFIX "pthread_attr_destroy\n"); exit(PTS_UNRESOLVED); } printf("Test PASS\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_attr_setscope/4-1.c0100644000000000000000000000233710030002513024326 0ustar rootroot/* * Copyright (c) 2004, Intel Corporation. All rights reserved. * Created by: crystal.xiong REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test pthread_attr_setscope() * * Steps: * 1. Initialize a pthread_attr_t object using pthread_attr_init() * 2. Call pthread_attr_setscope with unsupported scope * parameter * */ #include #include #include #include #include "posixtest.h" #define TEST "4-1" #define FUNCTION "pthread_attr_setscope" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " #define INVALIDSCOPE 999 int main() { int rc=0; pthread_attr_t attr; rc = pthread_attr_init(&attr); if (rc != 0) { perror(ERROR_PREFIX "pthread_attr_init"); exit(PTS_UNRESOLVED); } rc = pthread_attr_setscope(&attr, INVALIDSCOPE); if ((rc != EINVAL)) { perror(ERROR_PREFIX "pthread_attr_setscope"); exit(PTS_FAIL); } rc = pthread_attr_destroy(&attr); if( rc != 0) { perror(ERROR_PREFIX "pthread_attr_destroy"); exit(PTS_UNRESOLVED); } printf("Test PASS\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_attr_setscope/3-1.sh0100755000000000000000000000071010030002513024511 0ustar rootroot #!/bin/sh # Copyright (c) 2004, Intel Corporation. All rights reserved. # Created by: crystal.xiong REMOVE-THIS AT intel DOT com # This file is licensed under the GPL license. For the full content # of this license, see the COPYING file at the top level of this # source tree. # Test pthread_attr_setscope returns 0 on success. # This is tested implicitly via assertion 1. echo "Tested implicitly via assertion 1. See output for status" exit 0 posixtestsuite/conformance/interfaces/pthread_attr_setscope/1-1.c0100644000000000000000000000403210030775550024337 0ustar rootroot/* * Copyright (c) 2004, Intel Corporation. All rights reserved. * Created by: crystal.xiong REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test pthread_attr_setscope() * * Steps: * 1. Initialize pthread_attr_t object (attr) * 2. sets the contentionscope to attr * 3. create a thread with the attr * 4. Get the contentionscope value in the created thread */ #include #include #include #include #include #include "posixtest.h" #define TEST "1-1" #define FUNCTION "pthread_attr_setscope" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " #define CONSCOPE PTHREAD_SCOPE_SYSTEM void *thread_func() { pthread_exit(0); return NULL; } int main() { pthread_t new_th; pthread_attr_t attr; int cscope; int rc; /* Initialize attr */ rc = pthread_attr_init(&attr); if( rc != 0) { perror(ERROR_PREFIX "pthread_attr_init"); exit(PTS_UNRESOLVED); } rc = pthread_attr_setscope(&attr, CONSCOPE); if (rc != 0 ) { perror(ERROR_PREFIX "PTHREAD_SCOPE_SYSTEM is not supported"); exit(PTS_UNRESOLVED); } rc = pthread_create(&new_th, &attr, thread_func, NULL); if (rc !=0 ) { perror(ERROR_PREFIX "pthread_create"); exit(PTS_UNRESOLVED); } rc = pthread_attr_getscope(&attr, &cscope); if (rc != 0 ) { perror(ERROR_PREFIX "pthread_attr_getscope"); exit(PTS_UNRESOLVED); } if (cscope != CONSCOPE) { fprintf(stderr, ERROR_PREFIX "The contentionscope is not " "correct \n"); exit(PTS_FAIL); } rc = pthread_join(new_th, NULL); if(rc != 0) { perror(ERROR_PREFIX "pthread_join"); exit(PTS_UNRESOLVED); } rc = pthread_attr_destroy(&attr); if(rc != 0) { perror(ERROR_PREFIX "pthread_attr_destroy"); exit(PTS_UNRESOLVED); } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_attr_setscope/assertions.xml0100644000000000000000000000202410030002513026566 0ustar rootroot pthread_attr_setscope shall set the contentionscope attribute in the attr object. The contentionscope attribute may have the values PTHREAD_SCOPE_SYSTEM, signifying system scheduling contention scope, or PTHREAD_SCOPE_PROCESS, signifying process scheduling contention scope. If successful, pthread_attr_setscope functions return zero. If fail, an error number shall be returned to indicate the error. [EINVAL] The value of contentionscope is not valid. If fail, an error number shall be returned to indicate the error. [ENOTSUP] An attempt was made to set the attribute to an unsupported value. Shall not return an error code of [EINTR] posixtestsuite/conformance/interfaces/pthread_attr_setscope/coverage.txt0100644000000000000000000000030510044434055026225 0ustar rootrootThis document defines the coverage for the pthread_attr_setscope function: Assertion Tested? 1 YES 2 NO 3 YES 4 YES 5 NO. Incorrect test -- What's the unsupported value? 6 Won't test NOTE: posixtestsuite/conformance/interfaces/gmtime/0040755000000000000000000000000010515625164020600 5ustar rootrootposixtestsuite/conformance/interfaces/gmtime/1-1.c0100644000000000000000000000456510202410565021237 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: majid.awad REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * * * The names in the broken-down tm structure should correspond to its values. * */ #include #include #include int main () { struct tm *tm_ptr; time_t the_time; int total_years; (void) time(&the_time); tm_ptr = gmtime(&the_time); printf("Raw time is %ld \n", the_time); printf("gmtime gives:\n"); /* Checking the seconds */ if ((tm_ptr->tm_sec >= 0) && (tm_ptr->tm_sec < 60 )) { printf("sec %02d\n", tm_ptr->tm_sec); } else { puts("Test FAILED: seconds"); return PTS_FAIL; } /* Checking the Minutes */ if ((tm_ptr->tm_min >= 0) && (tm_ptr->tm_min <= 59 )) { printf("min %02d\n", tm_ptr->tm_min); } else { puts("Test FAILED: minutes"); return PTS_FAIL; } /* Checking the Hour */ if ((tm_ptr->tm_hour >= 0) && (tm_ptr->tm_hour <= 23 )) { printf("hour %02d\n", tm_ptr->tm_hour); } else { puts("Test FAILED: hour"); return PTS_FAIL; } /* Checking the Month Day */ if ((tm_ptr->tm_mday >= 1) && (tm_ptr->tm_mday <= 31 )) { printf("mday %02d\n", tm_ptr->tm_mday); } else { puts("Test FAILED: mday"); return PTS_FAIL; } /* Checking the Month */ if ((tm_ptr->tm_mon >= 0) && (tm_ptr->tm_mon <= 11 )) { printf("mon %02d\n", tm_ptr->tm_mon); } else { puts("Test FAILED: mon"); return PTS_FAIL; } /* Checking the Year */ total_years = (tm_ptr->tm_year + 1900); if (total_years >= 1900) { printf("year %d\n", total_years); } else { printf("year %d\n", total_years); puts("Test FAILED: year"); return PTS_FAIL; } /* Checking the Day of week */ if ((tm_ptr->tm_wday >= 0) && (tm_ptr->tm_wday <= 6 )) { printf("wday %02d\n", tm_ptr->tm_wday); } else { puts("Test FAILED: wday"); return PTS_FAIL; } /* Checking the Day in year */ if ((tm_ptr->tm_yday >= 0) && (tm_ptr->tm_yday <= 365 )) { printf("yday %02d\n", tm_ptr->tm_yday); } else { puts("Test FAILED: yday"); return PTS_FAIL; } /* Checking the DTS */ if ((tm_ptr->tm_isdst >= -1) && (tm_ptr->tm_isdst <= 1 )) { printf("isdst %02d\n", tm_ptr->tm_isdst); } else { puts("Test FAILED: isdst"); return PTS_FAIL; } puts("Test PASSED"); return PTS_PASS; } posixtestsuite/conformance/interfaces/gmtime/assertions.xml0100644000000000000000000000045107710056122023504 0ustar rootroot The names in the broken-down tm structure should correspond to its values. The gmtime function shall return a pointer to a struct tm. posixtestsuite/conformance/interfaces/gmtime/coverage.txt0100644000000000000000000000014207710056122023121 0ustar rootrootThis file defines the coverage for the gmtime() function testing. Assertion Status 1 YES 2 YES posixtestsuite/conformance/interfaces/gmtime/2-1.c0100644000000000000000000000122207710056122021230 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: majid.awad REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * * * The gmtime function shall return a pointer to struct tm. * */ #include #include #include int main () { struct tm *tm_ptr; time_t the_time; (void) time(&the_time); tm_ptr = NULL; tm_ptr = gmtime(&the_time); if (tm_ptr != NULL) { puts("Test PASSED"); return PTS_PASS; } else { puts("Test FAILED"); return PTS_FAIL; } } posixtestsuite/conformance/interfaces/killpg/0040755000000000000000000000000010515625165020601 5ustar rootrootposixtestsuite/conformance/interfaces/killpg/5-1.c0100644000000000000000000000167107646627463021267 0ustar rootroot/* * Copyright (c) 2002-3, Intel Corporation. All rights reserved. * Created by: salwan.searty REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that the killpg() function shall return -1 on failure. */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include "posixtest.h" void handler(int signo) { printf("Caught signal being tested!\n"); printf("Test PASSED\n"); exit(0); } int main() { int pgrp; if ((pgrp = getpgrp()) == -1) { printf("Could not get process group number\n"); return PTS_UNRESOLVED; } if (killpg(pgrp, -1) != -1) { printf("Test FAILED: killpg did not return -1 even though it was passed an invalid signal number."); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/killpg/4-1.c0100644000000000000000000000140707646627463021263 0ustar rootroot/* * Copyright (c) 2002-3, Intel Corporation. All rights reserved. * Created by: salwan.searty REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that the killpg() function shall return 0 upon success. */ #define _XOPEN_SOURCE 600 #include #include #include #include #include "posixtest.h" int main() { int pgrp; if ((pgrp = getpgrp()) == -1) { printf("Could not get process group number\n"); return PTS_UNRESOLVED; } if (killpg(pgrp, 0) != 0) { printf("killpg did not return success.\n"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/killpg/1-1.c0100644000000000000000000000276107646627462021263 0ustar rootroot/* * Copyright (c) 2002-3, Intel Corporation. All rights reserved. * Created by: salwan.searty REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that the killpg() function shall send signal sig to the process group specified by prgp. Steps: * 1. Set up a signal handler for the signal that says we have caught the * signal. * 2. Call killpg on the current process group id, raising the signal. * 3. If signal handler was called, test passed. */ #define _XOPEN_SOURCE 600 #define SIGTOTEST SIGCHLD #include #include #include #include #include "posixtest.h" void handler(int signo) { printf("Caught signal being tested!\n"); printf("Test PASSED\n"); exit(0); } int main() { int pgrp; struct sigaction act; act.sa_handler=handler; act.sa_flags=0; if (sigemptyset(&act.sa_mask) == -1) { perror("Error calling sigemptyset\n"); return PTS_UNRESOLVED; } if (sigaction(SIGTOTEST, &act, 0) == -1) { perror("Error calling sigaction\n"); return PTS_UNRESOLVED; } if ((pgrp = getpgrp()) == -1) { printf("Could not get process group number\n"); return PTS_UNRESOLVED; } if (killpg(pgrp, SIGTOTEST) != 0) { printf("Could not raise signal being tested\n"); return PTS_UNRESOLVED; } printf("Should have exited from signal handler\n"); printf("Test FAILED\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/killpg/6-1.c0100644000000000000000000000200607646627463021261 0ustar rootroot/* * Copyright (c) 2002-3, Intel Corporation. All rights reserved. * Created by: salwan.searty REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that the killpg() function shall set errno to EINVAL if it is passed an invalid signal number */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include "posixtest.h" int main() { int pgrp; if ((pgrp = getpgrp()) == -1) { printf("Could not get process group number\n"); return PTS_UNRESOLVED; } if (killpg(pgrp, -1) != -1) { printf("killpg did not return -1 even though it was passed an invalid signal number."); return PTS_UNRESOLVED; } if (errno != EINVAL) { printf("killpg did not set errno to EINVAL even though it was passed an invalid signal number."); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/killpg/1-2.c0100644000000000000000000000400207645105435021240 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: salwan.searty REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Steps: * 1) Fork a child process. * 2) In the parent process, call killpg with signal SIGTOTEST for the * process group id of the child. Have the parent ignore such a signal * incase the process group id of the parent is the same as process * group id of the child. * In the child, * 3) Wait for signal SIGTOTEST. * 4) Return 1 if SIGTOTEST is found. Return 0 otherwise. * 5) In the parent, return success if 1 was returned from child. * */ #define _XOPEN_SOURCE 600 #define SIGTOTEST SIGUSR1 #include #include #include #include #include #include "posixtest.h" void myhandler (int signo) { exit(1); } int main() { int child_pid, child_pgid; if ((child_pid = fork()) == 0) { /* child here */ struct sigaction act; act.sa_handler=myhandler; act.sa_flags=0; sigemptyset(&act.sa_mask); sigaction(SIGTOTEST, &act, 0); /* change child's process group id */ setpgrp(); sigpause(SIGABRT); return 0; } else { /* parent here */ int i; sigignore(SIGTOTEST); sleep(1); if ((child_pgid = getpgid(child_pid)) == -1) { printf("Could not get pgid of child\n"); return PTS_UNRESOLVED; } if (killpg(child_pgid, SIGTOTEST) != 0) { printf("Could not raise signal being tested\n"); return PTS_UNRESOLVED; } if (wait(&i) == -1) { perror("Error waiting for child to exit\n"); return PTS_UNRESOLVED; } if (WEXITSTATUS(i)) { printf("Child exited normally\n"); printf("Test PASSED\n"); return PTS_PASS; } else { printf("Child did not exit normally.\n"); printf("Test FAILED\n"); return PTS_FAIL; } } printf("Should have exited from parent\n"); printf("Test FAILED\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/killpg/assertions.xml0100644000000000000000000000235307633753443023525 0ustar rootroot The killpg () function sends the signal sig to the process group pgrp. killpg(pgrp, sig) is equivalent to kill(-pgrp, sig), when pgrp is greater than 1, The behavior of killpg ( ) is undefined if pgrp is less than or equal to 1. killpg returns 0 upon successful completion. killpg returns -1, upon unsuccessful completion. errno shall be set to EINVAL, when tThe value of the sig argument is an invalid or unsupported signal number. errno shall be set to EPERM, when the process does not have permission to send the signal to any receiving process. errno shall be set to ESRCH, when no process or process group can be found corresponding to that specified by pid. posixtestsuite/conformance/interfaces/killpg/coverage.txt0100644000000000000000000000046307633753443023145 0ustar rootrootThis file defines the coverage for the kill() function testing. Assertion Status 1 YES 2 YES 3 WON'T test, since behavior is undefined. 4 YES 5 YES 6 YES 7 WON'T test, since too risky to test without knowing what user id's are defined on each of the platforms that these tests may be run on. 8 YES posixtestsuite/conformance/interfaces/killpg/8-1.c0100644000000000000000000000162207646627463021266 0ustar rootroot/* * Copyright (c) 2002-3, Intel Corporation. All rights reserved. * Created by: salwan.searty REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that the killpg() function shall set errno to ESRCH if it is passed an invalid process group number */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include "posixtest.h" int main() { if (killpg(999999, 0) != -1) { printf("killpg did not return -1 even though it was passed an invalid process group id."); return PTS_UNRESOLVED; } if (errno != ESRCH) { printf("killpg did not set errno to ESRCH even though it was passed an invalid signal number."); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/killpg/2-1.c0100644000000000000000000000126307646627463021261 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: salwan.searty REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Call killpg on the current process with 0 as the signal number. If killpg returns success, then we pass. */ #define _XOPEN_SOURCE 600 #include #include #include #include #include "posixtest.h" int main() { if (killpg(getpgrp(), 0) != 0) { printf("Could not call killpg with sig = 0\n"); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/strftime/0040755000000000000000000000000010515625270021151 5ustar rootrootposixtestsuite/conformance/interfaces/strftime/1-1.c0100644000000000000000000002420110350315414021600 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: majid.awad REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * * * This test case will cover all the conversion specifiers that are supported * in strftime(). */ #include #include #include #include #include #include "posixtest.h" int main () { /* current time */ time_t t = time(NULL); struct tm* local_t = localtime(&t); char text[256]; int result; setlocale(LC_TIME, ""); strftime(text, 256, nl_langinfo (D_T_FMT), local_t); printf("STRING IS: %s\n\n", text); /* use format controls to print the various date/time components. */ result = strftime(text, 256, "%a", local_t); printf("a Bytes %i %s ", result, text); if ( result != 3 ) { puts("Test Failed: \%a doesn't equal at least 3 bytes"); return PTS_FAIL; } else { puts("PASS"); } result = strftime(text, 256, "%A", local_t); printf("A Bytes %i %s ", result, text); if ( result <= 5 ) { puts("Test Failed: \%A doesn't equal to 6 bytes"); return PTS_FAIL; } else { puts ("PASS"); } result = strftime(text, 256 , "%b", local_t); printf("b Bytes %i %s ", result, text); if ( result != 3 ) { puts("Test Failed: \%b doesn't equal to 3 bytes"); return PTS_FAIL; } else { puts ("PASS"); } result = strftime(text, 256, "%B", local_t); printf("B Bytes %i %s ", result, text); if ( result < 3 ) { puts("Test Failed: \%B is less than3 bytes"); return PTS_FAIL; } else { puts ("PASS"); } /* This section has been commented for known bug in gcc: * * result = strftime(text, 256, "%c", local_t); * printf("c Bytes %i %s ", result, text); * if ( result <= 30 ) { * puts("Test Failed: \%c doesn't equal at least 30 bytes"); * } else { * puts ("PASS"); * } */ result = strftime(text, 256, "%C", local_t); printf("C Bytes %i %s ", result, text); if ( result != 2 ) { puts("Test Failed: \%C doesn't equal at least 2 bytes"); return PTS_FAIL; } else { puts ("PASS"); } result = strftime(text, 256, "%d", local_t); printf("d Bytes %i %s ", result, text); if ( result != 2 ) { puts("Test Failed: \%d doesn't equal at least 2 bytes"); return PTS_FAIL; } else { puts ("PASS"); } /* This section has been commented for known bug in gcc: * * result = strftime(text, 256, "%D", local_t); * printf("D Bytes %i %s ", result, text); * if ( result != 8 ) { * puts("Test Failed: \%D doesn't equal at least 2 bytes"); * return PTS_FAIL; * } else { * puts ("PASS"); * } */ result = strftime(text, 256, "%e", local_t); printf("e Bytes %i %s ", result, text); if ( result != 2 ) { puts("Test Failed: \%e doesn't equal at least 2 bytes"); return PTS_FAIL; } else { puts ("PASS"); } result = strftime(text, 256, "%F", local_t); printf("F Bytes %i %s ", result, text); if ( result != 10 ) { puts("Test Failed: \%F doesn't equal at least 10 bytes"); return PTS_FAIL; } else { puts ("PASS"); } result = strftime(text, 256, "%H", local_t); printf("H Bytes %i %s ", result, text); if ( result != 2 ) { puts("Test Failed: \%H doesn't equal at least 2 bytes"); return PTS_FAIL; } else { puts ("PASS"); } /* This section has been commented for known bug in gcc: * * result = strftime(text, 256, "%g", local_t); * printf("g Bytes %i %s ", result, text); * if ( result != 2 ) { * puts("Test Failed: \%g doesn't equal at least 2 bytes"); * return PTS_FAIL; * } else { * puts ("PASS"); * } */ result = strftime(text, 256, "%G", local_t); printf("G Bytes %i %s ", result, text); if ( result != 4 ) { puts("Test Failed: \%G doesn't equal at least 4 bytes"); return PTS_FAIL; } else { puts ("PASS"); } result = strftime(text, 256, "%h", local_t); printf("h Bytes %i %s ", result, text); if ( result != 3 ) { puts("Test Failed: \%h doesn't equal at least 3 bytes"); return PTS_FAIL; } else { puts ("PASS"); } result = strftime(text, 256, "%I", local_t); printf("I Bytes %i %s ", result, text); if ( result != 2 ) { puts("Test Failed: \%I doesn't equal at least 2 bytes"); return PTS_FAIL; } else { puts ("PASS"); } result = strftime(text, 256, "%j", local_t); printf("j Bytes %i %s ", result, text); if ( result != 3 ) { puts("Test Failed: \%j doesn't equal at least 3 bytes"); return PTS_FAIL; } else { puts ("PASS"); } result = strftime(text, 256, "%m", local_t); printf("m Bytes %i %s ", result, text); if ( result != 2 ) { puts("Test Failed: \%m doesn't equal at least 2 bytes"); return PTS_FAIL; } else { puts ("PASS"); } result = strftime(text, 256, "%M", local_t); printf("M Bytes %i %s ", result, text); if ( result != 2 ) { puts("Test Failed: \%M doesn't equal at least 2 bytes"); return PTS_FAIL; } else { puts ("PASS"); } result = strftime(text, 256, "%n", local_t); printf("n Bytes %i %s ", result, text); if ( result != 1 ) { puts("Test Failed: \%n doesn't equal at least 1 bytes"); return PTS_FAIL; } else { puts ("PASS"); } result = strftime(text, 256, "%p", local_t); printf("p Bytes %i %s ", result, text); if ( result != 2 ) { puts("Test Failed: \%p doesn't equal at least 2 bytes"); return PTS_FAIL; } else { puts ("PASS"); } result = strftime(text, 256, "%r", local_t); printf("r Bytes %i %s ", result, text); if ( result != 11 ) { puts("Test Failed: \%r doesn't equal at least 11 bytes"); return PTS_FAIL; } else { puts ("PASS"); } result = strftime(text, 256, "%R", local_t); printf("R Bytes %i %s ", result, text); if ( result != 5 ) { puts("Test Failed: \%R doesn't equal at least 5 bytes"); return PTS_FAIL; } else { puts ("PASS"); } result = strftime(text, 256, "%S", local_t); printf("S Bytes %i %s ", result, text); if ( result != 2 ) { puts("Test Failed: \%S doesn't equal at least 2 bytes"); return PTS_FAIL; } else { puts ("PASS"); } result = strftime(text, 256, "%t", local_t); printf("t Bytes %i %s ", result, text); if ( result != 1 ) { puts("Test Failed: \%t doesn't equal at least 1 bytes"); return PTS_FAIL; } else { puts ("PASS"); } result = strftime(text, 256, "%T", local_t); printf("T Bytes %i %s ", result, text); if ( result != 8 ) { puts("Test Failed: \%T doesn't equal at least 8 bytes"); return PTS_FAIL; } else { puts ("PASS"); } result = strftime(text, 256, "%u", local_t); printf("u Bytes %i %s ", result, text); if ( result != 1 ) { puts("Test Failed: \%u doesn't equal at least 1 bytes"); return PTS_FAIL; } else { puts ("PASS"); } result = strftime(text, 256, "%U", local_t); printf("U Bytes %i %s ", result, text); if ( result != 2 ) { puts("Test Failed: \%U doesn't equal at least 2 bytes"); return PTS_FAIL; } else { puts ("PASS"); } result = strftime(text, 256, "%V", local_t); printf("V Bytes %i %s ", result, text); if ( result != 2 ) { puts("Test Failed: \%V doesn't equal at least 2 bytes"); return PTS_FAIL; } else { puts ("PASS"); } result = strftime(text, 256, "%w", local_t); printf("w Bytes %i %s ", result, text); if ( result != 1 ) { puts("Test Failed: \%w doesn't equal at least 1 bytes"); return PTS_FAIL; } else { puts ("PASS"); } result = strftime(text, 256, "%W", local_t); printf("W Bytes %i %s ", result, text); if ( result != 2 ) { puts("Test Failed: \%W doesn't equal at least 2 bytes"); return PTS_FAIL; } else { puts ("PASS"); } /* This section has been commented for known bug in gcc: * * result = strftime(text, 256, "%x", local_t); * printf("x Bytes %i %s ", result, text); * if ( result != 10 ) { * puts("Test Failed: \%x doesn't equal at least 10 bytes"); * return PTS_FAIL; * } else { * puts ("PASS"); * } */ result = strftime(text, 256, "%X", local_t); printf("X Bytes %i %s ", result, text); if ( result < 8 ) { puts("Test Failed: \%X doesn't equal at least 8 bytes"); return PTS_FAIL; } else { puts ("PASS"); } /* This section has been commented for known bug in gcc: * * result = strftime(text, 256, "%y", local_t); * printf("y Bytes %i %s ", result, text); * if ( result != 2 ) { * puts("Test Failed: \%y doesn't equal at least 2 bytes"); * return PTS_FAIL; * } else { * puts ("PASS"); * } */ result = strftime(text, 256, "%Y", local_t); printf("Y Bytes %i %s ", result, text); if ( result != 4 ) { puts("Test Failed: \%Y doesn't equal at least 4 bytes"); return PTS_FAIL; } else { puts ("PASS"); } result = strftime(text, 256, "%z", local_t); printf("z Bytes %i %s ", result, text); if ( result != 5 ) { puts("Test Failed: \%z doesn't equal at least 5 bytes"); return PTS_FAIL; } else { puts ("PASS"); } //result = strftime(text, 256, "%Z", local_t); //printf("Z Bytes %i %s ", result, text); //if ( result != 3 ) { // puts("Test Failed: \%Z doesn't equal at least 3 bytes"); // return PTS_FAIL; // } else { // puts ("PASS"); // } printf("\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/strftime/assertions.xml0100644000000000000000000000117610117555071024066 0ustar rootroot This test case will cover all the conversion specifiers that are supported in strftime(). It covers the conversions specifiers that can be modified by the E or O indicate that an alternative format or specification should be used rather than the one normally used by the unmodified conversion specifier (1-1.c). strftime shall return the number of bytes placed into the array. Otherwise, it should return 0. posixtestsuite/conformance/interfaces/strftime/coverage.txt0100644000000000000000000000144207705565564023523 0ustar rootroot I have commented some of the conversions specifications because there is a bug in gcc that complains about them. Here is a log file of the output: conformance/interfaces/strftime/1-1: build: FAILED: Compiler output: cc1: warnings being treated as errors conformance/interfaces/strftime/1-1.c: In function `main': conformance/interfaces/strftime/1-1.c:67: warning: `%c' yields only last 2 digits of year in some locales conformance/interfaces/strftime/1-1.c:95: warning: `%D' yields only last 2 digits of year conformance/interfaces/strftime/1-1.c:132: warning: `%g' yields only last 2 digits of year conformance/interfaces/strftime/1-1.c:312: warning: `%x' yields only last 2 digits of year in some locales conformance/interfaces/strftime/1-1.c:330: warning: `%y' yields only last 2 digits of year posixtestsuite/conformance/interfaces/strftime/2-1.c0100644000000000000000000001374007705565564021636 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: majid.awad REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * * * Modified by the E or O indicate that an alternative format or * specification should be used rather than the one normally used by the * unmodified conversion specifier (1-1.c). */ #include #include #include #include #include #include "posixtest.h" int main () { /* current time */ time_t t = time(NULL); struct tm* local_t = localtime(&t); char text[20]; int result; setlocale(LC_TIME, ""); strftime(text, 256, nl_langinfo (D_T_FMT), local_t); printf("STRING IS: %s\n\n", text); /* use format controls to print the various date/time components. */ /* This section has been commented for known bug in gcc: * result = strftime(text, 256, "%Ec", local_t); * printf("Ec Bytes %i %s ", result, text); * if ( result != 31 ) { * puts("Test Failed: \%Ec doesn't equal at least 31 bytes"); * return PTS_FAIL; * } else { * puts("PASS"); * } */ result = strftime(text, 256, "%EC", local_t); printf("EC Bytes %i %s ", result, text); if ( result != 2 ) { puts("Test Failed: \%EC doesn't equal to 2 bytes"); return PTS_FAIL; } else { puts ("PASS"); } /* This section has been commented for known bug in gcc: * result = strftime(text, 256 , "%Ex", local_t); * printf("Ex Bytes %i %s ", result, text); * if ( result != 10 ) { * puts("Test Failed: \%Ex doesn't equal to 10 bytes"); * return PTS_FAIL; * } else { * puts ("PASS"); * } */ result = strftime(text, 256, "%EX", local_t); printf("EX Bytes %i %s ", result, text); if ( result <= 3 ) { puts("Test Failed: \%EX doesn't equal to 3 bytes"); return PTS_FAIL; } else { puts ("PASS"); } /* This section has been commented for known bug in gcc: * result = strftime(text, 256, "%Ey", local_t); * printf("Ey Bytes %i %s ", result, text); * if ( result != 2 ) { * puts("Test Failed: \%Ey doesn't equal at least 2 bytes"); * return PTS_FAIL; * } else { * puts ("PASS"); * } */ result = strftime(text, 256, "%EY", local_t); printf("EY Bytes %i %s ", result, text); if ( result != 4 ) { puts("Test Failed: \%EY doesn't equal at least 4 bytes"); return PTS_FAIL; } else { puts ("PASS"); } result = strftime(text, 256, "%Od", local_t); printf("Od Bytes %i %s ", result, text); if ( result != 2 ) { puts("Test Failed: \%Od doesn't equal at least 2 bytes"); return PTS_FAIL; } else { puts ("PASS"); } result = strftime(text, 256, "%Oe", local_t); printf("Oe Bytes %i %s ", result, text); if ( result != 2 ) { puts("Test Failed: \%Oe doesn't equal at least 2 bytes"); return PTS_FAIL; } else { puts ("PASS"); } result = strftime(text, 256, "%OH", local_t); printf("OH Bytes %i %s ", result, text); if ( result != 2 ) { puts("Test Failed: \%OH doesn't equal at least 2 bytes"); return PTS_FAIL; } else { puts ("PASS"); } result = strftime(text, 256, "%OI", local_t); printf("OI Bytes %i %s ", result, text); if ( result != 2 ) { puts("Test Failed: \%OI doesn't equal at least 2 bytes"); return PTS_FAIL; } else { puts ("PASS"); } result = strftime(text, 256, "%Om", local_t); printf("Om Bytes %i %s ", result, text); if ( result != 2 ) { puts("Test Failed: \%Om doesn't equal at least 2 bytes"); return PTS_FAIL; } else { puts ("PASS"); } result = strftime(text, 256, "%OM", local_t); printf("OM Bytes %i %s ", result, text); if ( result != 2 ) { puts("Test Failed: \%OM doesn't equal at least 2 bytes"); return PTS_FAIL; } else { puts ("PASS"); } result = strftime(text, 256, "%OS", local_t); printf("OS Bytes %i %s ", result, text); if ( result != 2 ) { puts("Test Failed: \%OS doesn't equal at least 2 bytes"); return PTS_FAIL; } else { puts ("PASS"); } result = strftime(text, 256, "%Ou", local_t); printf("Ou Bytes %i %s ", result, text); if ( result != 1 ) { puts("Test Failed: \%Ou doesn't equal at least 1 bytes"); return PTS_FAIL; } else { puts ("PASS"); } result = strftime(text, 256, "%OU", local_t); printf("OU Bytes %i %s ", result, text); if ( result != 2 ) { puts("Test Failed: \%OU doesn't equal at least 2 bytes"); return PTS_FAIL; } else { puts ("PASS"); } result = strftime(text, 256, "%OV", local_t); printf("OV Bytes %i %s ", result, text); if ( result != 2 ) { puts("Test Failed: \%OV doesn't equal at least 2 bytes"); return PTS_FAIL; } else { puts ("PASS"); } result = strftime(text, 256, "%Ow", local_t); printf("Ow Bytes %i %s ", result, text); if ( result != 1 ) { puts("Test Failed: \%Ow doesn't equal at least 1 bytes"); return PTS_FAIL; } else { puts ("PASS"); } result = strftime(text, 256, "%OW", local_t); printf("OW Bytes %i %s ", result, text); if ( result != 2 ) { puts("Test Failed: \%OW doesn't equal at least 2 bytes"); return PTS_FAIL; } else { puts ("PASS"); } /* This section has been commented for known bug in gcc: * result = strftime(text, 256, "%Oy", local_t); * printf("Oy Bytes %i %s ", result, text); * if ( result != 2 ) { * puts("Test Failed: \%Oy doesn't equal at least 2 bytes"); * return PTS_FAIL; * } else { * puts ("PASS"); * } */ printf("\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/strftime/3-1.c0100644000000000000000000000147107705565564021635 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: majid.awad REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * * * strftime shall return the number of bytes placed into the array. * Otherwise, it should return 0. */ #include #include #include "posixtest.h" int main() { struct tm *tm_ptr; time_t the_time; char buf[256]; int result; (void) time(&the_time); tm_ptr = localtime(&the_time); result = strftime(buf, 256, "%A %d %B, %I:%S %p", tm_ptr); if (result != 0) { printf("strftime gives: %s\n", buf); puts ("PASS"); return PTS_PASS; } else { puts ("FAIL"); return PTS_FAIL; } } posixtestsuite/conformance/interfaces/pthread_spin_unlock/0040755000000000000000000000000010515625230023343 5ustar rootrootposixtestsuite/conformance/interfaces/pthread_spin_unlock/1-1.c0100644000000000000000000000634407703351176024023 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * * Test pthread_spin_unlock(pthread_spinlock_t *lock) * * The function shall release the spin lock referenced by 'lock' which * was locked via the pthread_spin_lock() or pthread_spin_trylock(). * * Steps: * 1. Initialize a pthread_spinlock_t object 'spinlock' with * pthread_spin_init() * 2. Main thread lock 'spinlock' with pthread_spin_lock(), should get the lock * 3. Main thread unlock 'spinlock' * 4. Create a child thread. The thread try to lock 'spinlock', with * pthread_spin_trylock(), should get the lock. * 5. Child thread unlock * 6. Main thread lock 'spinlock', using pthread_spin_trylock(), should get * lock * 7. Main thread unlock 'spinlock' */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include "posixtest.h" static pthread_spinlock_t spinlock; volatile static int thread_state; #define NOT_CREATED_THREAD 1 #define ENTERED_THREAD 2 #define EXITING_THREAD 3 static void* fn_chld(void *arg) { int rc = 0; thread_state = ENTERED_THREAD; printf("thread: attempt trylock\n"); rc = pthread_spin_trylock(&spinlock); if(rc != 0) { printf("Test FAILED: thread failed to get spin lock," "Error code:%d\n" , rc); exit(PTS_FAIL); } printf("thread: acquired spin lock\n"); printf("thread: unlock spin lock\n"); if(pthread_spin_unlock(&spinlock)) { printf("thread: Error at pthread_spin_unlock()\n"); exit(PTS_FAIL); } thread_state = EXITING_THREAD; pthread_exit(0); return NULL; } int main() { int rc; pthread_t child_thread; if(pthread_spin_init(&spinlock, PTHREAD_PROCESS_PRIVATE) != 0) { printf("main: Error at pthread_spin_init()\n"); return PTS_UNRESOLVED; } printf("main: attempt spin lock\n"); /* We should get the lock */ if(pthread_spin_lock(&spinlock) != 0) { printf("main: cannot get spin lock when no one owns the lock\n"); return PTS_UNRESOLVED; } printf("main: acquired spin lock\n"); printf("main: unlock spin lock\n"); rc = pthread_spin_unlock(&spinlock); if(rc != 0) { printf("main: Error at pthread_spin_unlock()\n"); return PTS_FAIL; } thread_state = NOT_CREATED_THREAD; printf("main: create thread\n"); if(pthread_create(&child_thread, NULL, fn_chld, NULL) != 0) { printf("main: Error creating thread\n"); return PTS_UNRESOLVED; } /* Wait for thread to end execution */ if(pthread_join(child_thread, NULL) != 0) { printf("main: Error at pthread_join()\n"); return PTS_UNRESOLVED; } printf("main: try to lock again when thread unlocked\n"); if(pthread_spin_trylock(&spinlock) != 0) { printf("main: Should get spin lock\n"); return PTS_FAIL; } printf("main: acquired spin lock\n"); printf("main: unlock spin lock\n"); if(pthread_spin_unlock(&spinlock) != 0) { printf("Test FAILED: main: Error at pthread_spin_unlock()\n"); return PTS_FAIL; } if(pthread_spin_destroy(&spinlock) != 0) { printf("Error at pthread_spin_destroy()"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_spin_unlock/1-2.c0100644000000000000000000000737707703351176024033 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * * Test pthread_spin_unlock(pthread_spinlock_t *lock) * * The function shall release the spin lock referenced by 'lock' which * was locked via the pthread_spin_lock() or pthread_spin_trylock(). * * CAUTION: If setting the priority of the process running this case * higher than other process in the system, the system might become * unresponsive. The child will spin on the spinlock, no other process * can interupt it. * * Steps: * 1. Initialize a pthread_spinlock_t object 'spinlock' with * pthread_spin_init() * 2. Main thread lock 'spinlock', should get the lock * 3. Create a child thread. The thread lock 'spinlock' with pthread_spin_lock() * should spin on the lock. * 4. Main thread unlock 'spinlock' * 5. Child thread should get 'spinlock' */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include "posixtest.h" static pthread_spinlock_t spinlock; volatile static int thread_state; #define NOT_CREATED_THREAD 1 #define ENTERED_THREAD 2 #define EXITING_THREAD 3 static void* fn_chld(void *arg) { int rc = 0; thread_state = ENTERED_THREAD; printf("thread: attempt spin lock\n"); rc = pthread_spin_lock(&spinlock); if(rc != 0) { printf("Test FAILED: thread failed to get spin lock error code:%d\n" , rc); exit(PTS_FAIL); } printf("thread: acquired spin lock\n"); sleep(1); printf("thread: unlock spin lock\n"); if(pthread_spin_unlock(&spinlock)) { printf("Test FAILED: Error at pthread_spin_unlock()\n"); exit(PTS_FAIL); } thread_state = EXITING_THREAD; pthread_exit(0); return NULL; } int main() { int cnt = 0; pthread_t child_thread; if(pthread_spin_init(&spinlock, PTHREAD_PROCESS_PRIVATE) != 0) { printf("main: Error at pthread_spin_init()\n"); return PTS_UNRESOLVED; } printf("main: attempt spin lock\n"); /* We should get the lock */ if(pthread_spin_lock(&spinlock) != 0) { printf("Error: main cannot get spin lock when no one owns the lock\n"); return PTS_UNRESOLVED; } printf("main: acquired spin lock\n"); thread_state = NOT_CREATED_THREAD; printf("main: create thread\n"); if(pthread_create(&child_thread, NULL, fn_chld, NULL) != 0) { printf("main: Error creating child thread\n"); return PTS_UNRESOLVED; } cnt = 0; /* Expect the child thread to spin on spin lock */ do{ sleep(1); }while (thread_state != EXITING_THREAD && cnt++ < 3); if(thread_state == EXITING_THREAD) { printf("Test FAILED: child thread did not spin on spin lock when other thread holds the lock\n"); return PTS_FAIL; } else if(thread_state != ENTERED_THREAD) { printf("main: Unexpected thread state %d\n", thread_state); return PTS_UNRESOLVED; } printf("main: unlock spin lock\n"); if(pthread_spin_unlock(&spinlock) != 0) { printf("Test FAILED: main: Error at pthread_spin_unlock()\n"); return PTS_FAIL; } /* We expected the child get the spin lock and exit */ cnt = 0; do{ sleep(1); }while (thread_state != EXITING_THREAD && cnt++ < 3); if(thread_state == ENTERED_THREAD) { printf("Test FAILED: child thread did not get spin lock\n"); return PTS_FAIL; } else if(thread_state != EXITING_THREAD) { printf("main: Unexpected thread state %d\n", thread_state); return PTS_UNRESOLVED; } if(pthread_join(child_thread, NULL) != 0) { printf("main: Error at pthread_join()\n"); return PTS_UNRESOLVED; } if(pthread_spin_destroy(&spinlock) != 0) { printf("Error at pthread_spin_destroy()"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_spin_unlock/assertions.xml0100644000000000000000000000136307703351176026271 0ustar rootroot The pthread_spin_unlock( ) function shall release the spin lock referenced by lock which was locked via the pthread_spin_lock( ) or pthread_spin_trylock( ) functions. Upon successful completion, the pthread_spin_unlock( ) function shall return zero; otherwise, an error number shall be returned to indicate the error. The pthread_spin_unlock( ) function may fail if: [EINVAL] An invalid argument was specified. [EPERM] The calling thread does not hold the lock. These functions shall not return an error code of EINTR. posixtestsuite/conformance/interfaces/pthread_spin_unlock/coverage.txt0100644000000000000000000000023007703351176025701 0ustar rootrootThis document defines the coverage for the pthread_spin_unlock() function: Assertion Tested? 1 YES 2 YES 3 YES "May" assertion, always pass NOTE: posixtestsuite/conformance/interfaces/pthread_spin_unlock/2-1.sh0100755000000000000000000000074407703351176024215 0ustar rootroot#!/bin/sh # Copyright (c) 2002, Intel Corporation. All rights reserved. # This file is licensed under the GPL license. For the full content # of this license, see the COPYING file at the top level of this # source tree. #If successful, the pthread_spin_unlock( ) function shall return zero; otherwise, an error number #shall be returned to indicate the error. # This is tested implicitly via assertion 1. echo "Tested implicitly via assertion 1. See output for status" exit 0 posixtestsuite/conformance/interfaces/pthread_spin_unlock/3-1.c0100644000000000000000000000600207703351176024014 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * * Test pthread_spin_unlock(pthread_spinlock_t *lock) * * This case will always PASS. * * The functions may fail if: * The pthread_spin_unlock( ) function may fail if: * [EPERM] The calling thread does not hold the lock. * * Steps: * 1. Create a thread that will initialize and lock a spinlock * 2. Main will try to unlock the spinlock (it doesn't hold the lock) * 3. Check the return code to see if it returns [EPERM]. * * Note: This test will always pass since the standard specifies 'may' fail. * */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include "posixtest.h" static pthread_spinlock_t spinlock; volatile static int sem; #define INTHREAD 0 #define INMAIN 1 static void* fn_chld(void *arg) { int rc = 0; /* Initialize spin lock */ if(pthread_spin_init(&spinlock, PTHREAD_PROCESS_PRIVATE) != 0) { printf("main: Error at pthread_spin_init()\n"); exit(PTS_UNRESOLVED); } /* Lock the spinlock */ printf("thread: attempt spin lock\n"); rc = pthread_spin_lock(&spinlock); if(rc != 0) { printf("Error: thread failed to get spin lock error code:%d\n" , rc); exit(PTS_UNRESOLVED); } printf("thread: acquired spin lock\n"); /* Wait for main to try and unlock this spinlock */ sem = INMAIN; while(sem == INMAIN) sleep(1); /* Cleanup just in case */ pthread_spin_unlock(&spinlock); if(pthread_spin_destroy(&spinlock) != 0) { printf("Error at pthread_spin_destroy()"); exit(PTS_UNRESOLVED); } pthread_exit(0); return NULL; } int main() { int rc; pthread_t child_thread; sem = INTHREAD; /* Create a thread that will initialize and lock a spinlock */ printf("main: create thread\n"); if(pthread_create(&child_thread, NULL, fn_chld, NULL) != 0) { printf("main: Error creating thread\n"); return PTS_UNRESOLVED; } /* Wait for thread to lock the spinlock */ while(sem == INTHREAD) sleep(1); printf("main: attempt to unlock a spinlock that we don't own\n"); rc = pthread_spin_unlock(&spinlock); if(rc != 0) { printf("main: Error at pthread_spin_unlock()\n"); return PTS_FAIL; } /* Tell thread that we're done attempting to unlock the spinlock */ sem = INTHREAD; /* Wait for thread to end execution */ if(pthread_join(child_thread, NULL) != 0) { printf("main: Error at pthread_join()\n"); return PTS_UNRESOLVED; } /* Test to see the return code of pthread_spin_unlock */ if( rc == EPERM) { printf("main: correctly got EPERM when unlocking a spinlock we didn't have permission to unlock\n"); printf("Test PASSED\n"); } else { printf("main: got return code :%d\n", rc); printf("Test PASSED: *Note: Did not return EPERM when unlocking a spinlock it does not have a lock on, but standard says 'may' fail\n"); } return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_attr_getstackaddr/0040755000000000000000000000000010515625177024523 5ustar rootrootposixtestsuite/conformance/interfaces/pthread_attr_getstackaddr/assertions.xml0100644000000000000000000000003310215313044027410 0ustar rootroot posixtestsuite/conformance/interfaces/pthread_attr_getstackaddr/coverage.txt0100644000000000000000000000021010031772315027033 0ustar rootrootThis document defines the coverage for the pthread_attr_getstackaddr function: Assertion Tested? 1 YES 2 YES 3 won't test Note: posixtestsuite/conformance/interfaces/ctime/0040755000000000000000000000000010515625163020416 5ustar rootrootposixtestsuite/conformance/interfaces/ctime/1-1.c0100644000000000000000000000145507710054310021053 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: majid.awad REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * * * This test case checks if the return value of the ctime call is * not NULL after converting the time value to a date and time string. */ #include #include #include "posixtest.h" int main() { time_t current_time; char * result; time(¤t_time); result = ctime(¤t_time); if (result == NULL) { puts ("Test FAILED: returned NULL"); return PTS_FAIL; } else { printf("converted date and time is: %s\n", ctime(¤t_time)); printf("Test PASSED\n"); return PTS_PASS; } } posixtestsuite/conformance/interfaces/ctime/assertions.xml0100644000000000000000000000030407705565563023342 0ustar rootroot The ctime function return value is not NULL after converting the time value to a date and time string. posixtestsuite/conformance/interfaces/ctime/coverage.txt0100644000000000000000000000013207710054310022734 0ustar rootrootThis file defines the coverage for the ctime() function testing. Assertion Status 1 YES posixtestsuite/conformance/interfaces/shm_unlink/0040755000000000000000000000000010515625240021460 5ustar rootrootposixtestsuite/conformance/interfaces/shm_unlink/5-1.c0100644000000000000000000000254507660655704022150 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that the reuse of the name subsequently causes shm_open() to * create a new shared memory object if O_CREAT is set even if the object * continues to exist after the last shm_unlink(), */ #include #include #include #include #include #include "posixtest.h" #define SHM_NAME "posixtest_5-1" int main() { int fd; fd = shm_open(SHM_NAME, O_RDWR|O_CREAT, S_IRUSR|S_IWUSR); if(fd == -1) { perror("An error occurs when calling shm_open()"); return PTS_UNRESOLVED; } if(shm_unlink(SHM_NAME) != 0 ) { perror("An error occurs when calling shm_unlink()"); return PTS_UNRESOLVED; } fd = shm_open(SHM_NAME, O_RDWR|O_CREAT|O_EXCL, S_IRUSR|S_IWUSR); if (fd == -1 && errno == EEXIST) { printf("shm_open() can not create a new object.\n"); return PTS_FAIL; } else if(fd == -1) { perror("shm_open"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); shm_unlink(SHM_NAME); return PTS_PASS; } posixtestsuite/conformance/interfaces/shm_unlink/7-1.sh0100755000000000000000000000031207660655704022333 0ustar rootroot#! /bin/sh # # Test that the shm_unlink() function return -1 upon unsuccessful completion. # # This is tested implicitly via assertions 9 to 11. echo "Tested implicitly via assertions 9 to 11." exit 0 posixtestsuite/conformance/interfaces/shm_unlink/1-1.c0100644000000000000000000000264307657710515022141 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that the shm_unlink() function remove the name of the shared memory * object named by the string pointed to by name. */ #include #include #include #include #include #include #include "posixtest.h" #define SHM_NAME "posixtest_1-1" int main() { int fd; fd = shm_open(SHM_NAME, O_RDWR|O_CREAT, S_IRUSR|S_IWUSR); if(fd == -1) { perror("An error occurs when calling shm_open()"); return PTS_UNRESOLVED; } if(close(fd) != 0) { perror("An error occurs when calling close()"); shm_unlink(SHM_NAME); return PTS_UNRESOLVED; } if(shm_unlink(SHM_NAME) != 0 ) { perror("An error occurs when calling shm_unlink()"); return PTS_UNRESOLVED; } fd = shm_open(SHM_NAME, O_RDONLY, 0); if(fd == -1 && errno == ENOENT) { printf("Test PASSED\n"); return PTS_PASS; } else if (fd == -1) { perror("shm_open"); return PTS_UNRESOLVED; } printf("The name of shared memory object was not removed.\n"); shm_unlink(SHM_NAME); return PTS_FAIL; } posixtestsuite/conformance/interfaces/shm_unlink/9-1.c0100644000000000000000000000437707657710515022157 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that shm_unlink() sets errno = EACCES if permission is denied to unlink * the named shared memory object. * * Steps: * 1. Create a shared memory object. * 2. Set his effective user id to an other user id which is not root. * 3. Try to unlink the name. * If it fail: set the effective user id to real user id and unlink. * In most case this test will be unresolved if not run by root. */ /* getpwent() is part of XSI option */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include #include #include "posixtest.h" #define SHM_NAME "posixtest_9-1" int main() { int fd, result; struct passwd *pw; fd = shm_open(SHM_NAME, O_RDWR|O_CREAT, S_IRUSR|S_IWUSR); if(fd == -1) { perror("An error occurs when calling shm_open()"); return PTS_UNRESOLVED; } /* search for the first user which is non root and which is not the current user */ while((pw = getpwent()) != NULL) if(strcmp(pw->pw_name, "root") && pw->pw_uid != getuid()) break; if(pw == NULL) { printf("There is no other user than current and root.\n"); return PTS_UNRESOLVED; } if(seteuid(pw->pw_uid) != 0) { if(errno == EPERM) { printf("You don't have permission to change your UID.\nTry to rerun this test as root.\n"); return PTS_UNRESOLVED; } perror("An error occurs when calling seteuid()"); return PTS_UNRESOLVED; } printf("Testing with user '%s' (uid: %i)\n", pw->pw_name, pw->pw_uid); result = shm_unlink(SHM_NAME); if(result == -1&& errno == EACCES) { printf("Test PASSED\n"); seteuid(getuid()); shm_unlink(SHM_NAME); return PTS_PASS; } else if(result == -1) { perror("Unexpected error"); seteuid(getuid()); shm_unlink(SHM_NAME); return PTS_FAIL; } printf("shm_unlink() success.\n"); return PTS_UNRESOLVED; } posixtestsuite/conformance/interfaces/shm_unlink/10-2.c0100644000000000000000000000275307664662050022222 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that the shm_unlink() function sets errno = ENAMETOOLONG if the length * of the name argument exceeds {PATH_MAX} (including the terminating null). * * The used name follow the scheme: * aaaaaa/aaaaaa/aaaaaa/aaa ... */ #include #include #include #include #include #include #include #include #include "posixtest.h" /* Ensure that each component length is short enough */ #define COMPONENT_SIZE _POSIX_NAME_MAX int main() { int result, i, path_max; char *shm_name; path_max = pathconf("/", _PC_PATH_MAX); if(path_max == -1) { perror("An error occurs when calling pathconf()"); return PTS_UNRESOLVED; } shm_name = malloc(path_max+1); for(i=0; i #include #include #include "posixtest.h" #define SHM_NAME "posixtest_11-1" int main() { int result; /* Ensure that the name SHM_NAME is removed */ shm_unlink(SHM_NAME); result = shm_unlink(SHM_NAME); if(result == -1 && errno == ENOENT) { printf("Test PASSED\n"); return PTS_PASS; } else if (result == -1) { perror("Unexpected error"); return PTS_UNRESOLVED; } printf("shm_unlink() success."); return PTS_FAIL; } posixtestsuite/conformance/interfaces/shm_unlink/6-1.c0100644000000000000000000000171207657710515022142 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that the shm_unlink() function returns zero upon successful completion. */ #include #include #include #include #include "posixtest.h" #define SHM_NAME "posixtest_6-1" int main() { int fd; fd = shm_open(SHM_NAME, O_RDWR|O_CREAT, S_IRUSR|S_IWUSR); if(fd == -1) { perror("An error occurs when calling shm_open()"); return PTS_UNRESOLVED; } if(shm_unlink(SHM_NAME) == 0 ) { printf("Test PASSED\n"); return PTS_PASS; } else { perror("shm_unlink() does not return zero"); return PTS_FAIL; } } posixtestsuite/conformance/interfaces/shm_unlink/10-1.c0100644000000000000000000000233207664662050022212 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that the shm_unlink() function sets errno = ENAMETOOLONG if the length * of a pathname component is longer than {NAME_MAX} (not including the * terminating null). */ #include #include #include #include #include #include #include "posixtest.h" int main() { int result, i; long name_max; char *shm_name; name_max = pathconf("/", _PC_NAME_MAX); shm_name = malloc(name_max+3); shm_name[0] = '/'; for(i=1; i The shm_unlink() function shall remove the name of the shared memory object named by the string pointed to by name If one or more references to the shared memory object exist when the object is unlinked, the name shall be removed before shm_unlink() returns If one or more references to the shared memory object exist when the object is unlinked, the removal of the memory object contents shall be postponed until all open and map references to the shared memory object have been removed Even if the object continues to exist after the last shm_unlink(), reuse of the name shall subsequently cause shm_open() to fail if O_CREAT is not set Even if the object continues to exist after the last shm_unlink(), reuse of the name shall subsequently cause shm_open() to create a new shared memory object if O_CREAT is set Upon successful completion, the shm_unlink() function shall return zero Upon unsuccessful completion, the shm_unlink() function shall return -1 If -1 is returned, the named shared memory object shall not be changed by this function call The shm_unlink() function sets errno = EACCES if permission is denied to unlink the named shared memory object The shm_unlink() function sets errno = ENAMETOOLONG if the length of the name argument exceeds PATH_MAX or a pathname component is longer than NAME_MAX The shm_unlink() function sets errno = ENOENT if the named shared memory object does not exist posixtestsuite/conformance/interfaces/shm_unlink/coverage.txt0100644000000000000000000000050307657710515024024 0ustar rootrootThis document explains why certain assertions were not tested. Assertions not listed here should be covered by the tests in this directory. Assertions Tested ? Remarks 1 YES 2 YES 3 YES 4 YES 5 YES 6 YES 7 YES 8 YES 9 YES 10 YES 11 YES posixtestsuite/conformance/interfaces/shm_unlink/8-1.c0100644000000000000000000000554707657710515022156 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that the named shared memory object is not changed by this function * call when the process does not have permission to unlink the name. * * Steps: * 1. Create a shared memory object. * 2. Set his effective user id to an other user id which is not root. * 3. Try to unlink the name. * If it fail: set the effective user id to real user id and unlink. * In most case this test will be unresolved if not run by root. */ /* getpwent() is part of XSI option */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include #include #include "posixtest.h" #define SHM_NAME "posixtest_9-1" #define BUF_SIZE 8 int main() { int fd, result; struct passwd *pw; struct stat stat_before, stat_after; fd = shm_open(SHM_NAME, O_RDWR|O_CREAT, S_IRUSR|S_IWUSR); if(fd == -1) { perror("An error occurs when calling shm_open()"); return PTS_UNRESOLVED; } if(ftruncate(fd, BUF_SIZE) != 0) { perror("An error occurs when calling ftruncate()"); shm_unlink(SHM_NAME); return PTS_UNRESOLVED; } if(fstat(fd, &stat_before) != 0) { perror("An error occurs when calling fstat()"); shm_unlink(SHM_NAME); return PTS_UNRESOLVED; } /* search for the first user which is non root and which is not the current user */ while((pw = getpwent()) != NULL) if(strcmp(pw->pw_name, "root") && pw->pw_uid != getuid()) break; if(pw == NULL) { printf("There is no other user than current and root.\n"); return PTS_UNRESOLVED; } if(seteuid(pw->pw_uid) != 0) { if(errno == EPERM) { printf("You don't have permission to change your UID.\nTry to rerun this test as root.\n"); return PTS_UNRESOLVED; } perror("An error occurs when calling seteuid()"); return PTS_UNRESOLVED; } printf("Testing with user '%s' (uid: %i)\n", pw->pw_name, pw->pw_uid); result = shm_unlink(SHM_NAME); if(result == 0) { printf("shm_unlink() success.\n"); return PTS_UNRESOLVED; } seteuid(getuid()); if(fstat(fd, &stat_after) != 0) { perror("An error occurs when calling fstat()"); shm_unlink(SHM_NAME); return PTS_UNRESOLVED; } if(stat_after.st_uid != stat_before.st_uid || stat_after.st_gid != stat_before.st_gid || stat_after.st_size != stat_before.st_size || stat_after.st_mode != stat_before.st_mode) { printf("The shared memory object has changed.\n"); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/shm_unlink/2-1.c0100644000000000000000000000246307657710515022142 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that the name is removed before shm_unlink() returns even if one or * more references to the shared memory object exist when the object is * unlinked. */ #include #include #include #include #include #include "posixtest.h" #define SHM_NAME "posixtest_2-1" int main() { int fd; fd = shm_open(SHM_NAME, O_RDWR|O_CREAT, S_IRUSR|S_IWUSR); if(fd == -1) { perror("An error occurs when calling shm_open()"); return PTS_UNRESOLVED; } if(shm_unlink(SHM_NAME) != 0 ) { perror("An error occurs when calling shm_unlink()"); return PTS_UNRESOLVED; } fd = shm_open(SHM_NAME, O_RDONLY, 0); if(fd == -1 && errno == ENOENT) { printf("Test PASSED\n"); return PTS_PASS; } else if (fd == -1) { perror("shm_open"); return PTS_UNRESOLVED; } printf("The name of shared memory object was not removed.\n"); shm_unlink(SHM_NAME); return PTS_FAIL; } posixtestsuite/conformance/interfaces/shm_unlink/4-1.sh0100755000000000000000000000044107660655704022333 0ustar rootroot#! /bin/sh # # Test that the reuse of the name subsequently causes shm_open() to fail # if O_CREAT is not set even if the object continues to exist after the last # shm_unlink() # # This is tested implicitly via assertions 1 and 2. echo "Tested implicitly via assertions 1 and 2." exit 0 posixtestsuite/conformance/interfaces/shm_unlink/3-1.c0100644000000000000000000000345707677005207022144 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that the removal of the memory object contents is postponed until all * open and map references to the shared memory object have been removed. */ /* ftruncate was formerly an XOPEN extension. We define _XOPEN_SOURCE here to avoid warning if the implementation does not program ftruncate as a base interface */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include #include "posixtest.h" #define BUF_SIZE 8 #define SHM_NAME "posixtest_3-1" int main() { int fd; char *buf; fd = shm_open(SHM_NAME, O_RDWR|O_CREAT, S_IRUSR|S_IWUSR); if(fd == -1) { perror("An error occurs when calling shm_open()"); return PTS_UNRESOLVED; } if(ftruncate(fd, BUF_SIZE) != 0) { perror("An error occurs when calling ftruncate()"); shm_unlink(SHM_NAME); return PTS_UNRESOLVED; } if(shm_unlink(SHM_NAME) != 0) { perror("An error occurs when calling shm_unlink()"); return PTS_UNRESOLVED; } /* Now, SHM_NAME is unlinked but there are open references on it */ buf = mmap(NULL, BUF_SIZE, PROT_READ, MAP_SHARED, fd, 0); if( buf == MAP_FAILED && errno == EBADF) { printf("The shared memory object was removed.\n"); return PTS_FAIL; } else if(buf == MAP_FAILED) { perror("An error occurs when calling mmap()"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/sched_yield/0040755000000000000000000000000010515625234021570 5ustar rootrootposixtestsuite/conformance/interfaces/sched_yield/3-1.sh0100755000000000000000000000032707643304270022430 0ustar rootroot#! /bin/sh # Test that sched_yield() returns -1 on failure. # # The function shall always succeed, so nothing can be done for this test. echo "Nothing to do for this test, the function shall always succeed." exit 0posixtestsuite/conformance/interfaces/sched_yield/1-1.c0100644000000000000000000001417310061221463022225 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * * Test that the running thread relinquish the processor until it again becomes * the head of its thread list. * * Steps: * 1. Set the policy to SCHED_FIFO. * 2. Launch as many processes as number CPU minus 1. These processses set * their priority to the max and block all but 1 processor. * 3. Launch a thread which increase a counter in a infinite loop. * 4. Launch a thread which call sched_yield() and check that the counter has * changed since the call. */ #define LINUX #ifdef LINUX #define _GNU_SOURCE #endif #include #include #include #include #include #include #include #include #include "posixtest.h" #ifdef BSD # include # include # include #endif #ifdef HPUX # include # include #endif #define LOOP 1000 /* Shall be >= 1 */ volatile int nb_call = 0; /* Get the number of CPUs */ int get_ncpu() { int ncpu = -1; /* This syscall is not POSIX but it should work on many system */ #ifdef _SC_NPROCESSORS_ONLN ncpu = sysconf(_SC_NPROCESSORS_ONLN); #else # ifdef BSD int mib[2]; size_t len = sizeof(ncpu); mib[0] = CTL_HW; mib[1] = HW_NCPU; sysctl(mib, 2, &ncpu, &len, NULL, 0); # else # ifdef HPUX struct pst_dynamic psd; pstat_getdynamic(&psd, sizeof(psd), 1, 0); ncpu = (int)psd.psd_proc_cnt; # endif /* HPUX */ # endif /* BSD */ #endif /* _SC_NPROCESSORS_ONLN */ return ncpu; } #ifdef LINUX int set_process_affinity(int cpu) { int retval = -1; cpu_set_t cpu_mask; CPU_ZERO(&cpu_mask); if (cpu >= 0 && cpu <= CPU_SETSIZE) { CPU_SET(cpu, &cpu_mask); } else { fprintf (stderr, "Wrong cpu id: %d\n", cpu); return -1; } //#ifndef P2_SCHED_SETAFFINITY retval = sched_setaffinity(0, sizeof(cpu_mask), &cpu_mask); //#else // retval = sched_setaffinity(0, &cpu_mask); //#endif if (retval == -1) perror("Error at sched_setaffinity()"); return retval; } int set_thread_affinity(int cpu) { int retval = -1; cpu_set_t cpu_mask; CPU_ZERO(&cpu_mask); if (cpu >= 0 && cpu <= CPU_SETSIZE) { CPU_SET(cpu, &cpu_mask); } else { fprintf (stderr, "Wrong cpu id: %d\n", cpu); return -1; } //#ifndef P2_PTHREAD_SETAFFINITY retval = pthread_setaffinity_np(pthread_self(), sizeof(cpu_mask), &cpu_mask); //#else // retval = pthread_setaffinity_np(pthread_self(), &cpu_mask); //#endif if (retval != 0) fprintf (stderr, "Error at pthread_setaffinity_np():\n"); return retval; } #endif void * runner(void * arg) { int i=0, nc; long result = 0; #ifdef LINUX set_thread_affinity(*(int *)arg); fprintf(stderr, "%ld bind to cpu: %d\n", pthread_self(), *(int*)arg); #endif for(;i The sched_yield() function shall force the running thread to relinquish the processor until it again becomes the head of its thread list. sched_yield() returns 0 on success sched_yield() returns -1 on failure posixtestsuite/conformance/interfaces/sched_yield/coverage.txt0100644000000000000000000000037607643304270024131 0ustar rootrootThis document explains why certain assertions were not tested. Assertions not listed here should be covered by the tests in this directory. Assertions Tested ? Remarks 1 YES 2 YES 3 YES The function shall always succeed.posixtestsuite/conformance/interfaces/sched_yield/2-1.c0100644000000000000000000000124507643304270022234 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * * Test that sched_yield() return 0 upon success. */ #include #include #include "posixtest.h" int main() { if(sched_yield() == 0) { printf("Test PASSED\n"); return PTS_PASS; } printf("sched_yield() does not return 0.\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/clock_settime/0040755000000000000000000000000010515625163022142 5ustar rootrootposixtestsuite/conformance/interfaces/clock_settime/17-1.c0100644000000000000000000000205507575170274022704 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * * Test that clock_settime() sets errno to EINVAL if clock_id does not * specify a known clock. * * The date chosen is Nov 12, 2002 ~11:13am (date when test was first * written). */ #include #include #include #include "posixtest.h" #define TESTTIME 1037128358 #define BOGUSCLOCKID 9999 int main(int argc, char *argv[]) { struct timespec tpset; tpset.tv_sec = TESTTIME; tpset.tv_nsec = 0; if (clock_settime(BOGUSCLOCKID, &tpset) == -1) { if (EINVAL == errno) { printf("Test PASSED\n"); return PTS_PASS; } else { printf("errno != EINVAL\n"); return PTS_FAIL; } } else { printf("clock_settime() did not return -1\n"); return PTS_UNRESOLVED; } printf("This test should not be executed.\n"); return PTS_UNRESOLVED; } posixtestsuite/conformance/interfaces/clock_settime/19-1.c0100644000000000000000000000431410021017161022655 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * * Test that clock_settime() sets errno=EINVAL if tp has a nsec value < 0 or * >= 1000 million. * * Test calling clock_settime() with the following tp.tv_nsec values: * MIN INT = INT32_MIN * MAX INT = INT32_MAX * MIN INT - 1 = 2147483647 (this is what gcc will set to) * MAX INT + 1 = -2147483647 (this is what gcc will set to) * unassigned value = -1073743192 (ex. of what gcc will set to) * unassigned value = 1073743192 (ex. of what gcc will set to) * -1 * 1000000000 * 1000000001 * * The clock_id CLOCK_REALTIME is used. */ #include #include #include #include #include #include "posixtest.h" #include "helpers.h" #define NUMINVALIDTESTS 9 static int invalid_tests[NUMINVALIDTESTS] = { INT32_MIN, INT32_MAX, 2147483647, -2147483647, -1073743192, 1073743192, -1, 1000000000, 1000000001 }; int main(int argc, char *argv[]) { struct timespec tsset, tscurrent, tsreset; int i; int failure = 0; /* Check that we're root...can't call clock_settime with CLOCK_REALTIME otherwise */ if(getuid() != 0) { printf("Run this test as ROOT, not as a Regular User\n"); return PTS_UNTESTED; } if (clock_gettime(CLOCK_REALTIME, &tscurrent) != 0) { printf("clock_gettime() did not return success\n"); return PTS_UNRESOLVED; } getBeforeTime(&tsreset); for (i = 0; i < NUMINVALIDTESTS; i++) { tsset.tv_sec = tscurrent.tv_sec; tsset.tv_nsec = invalid_tests[i]; printf("Test %d sec %d nsec\n", (int) tsset.tv_sec, (int) tsset.tv_nsec); if (clock_settime(CLOCK_REALTIME, &tsset) == -1) { if (EINVAL != errno) { printf("errno != EINVAL\n"); failure = 1; } } else { printf("clock_settime() did not return -1\n"); failure = 1; } } setBackTime(tsreset); if (failure) { printf("At least one test FAILED -- see above\n"); return PTS_FAIL; } else { printf("All tests PASSED\n"); return PTS_PASS; } return PTS_UNRESOLVED; } posixtestsuite/conformance/interfaces/clock_settime/5-1.c0100644000000000000000000000636110021017161022574 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * * Test that if clock_settime() changes the value for CLOCK_REALTIME, * then any relative timers still expire when the time interval * has elapsed. [Test where clock_settime() sets the clock _back_ in time.] * * Steps: * - set a timer to expire in TIMERSEC * - set the clock back CLOCKOFFSET seconds * - nanosleep for TIMERSEC+SLEEPDELTA seconds -> timer should expire * - determine if the time remaining in nanosleep ~= SLEEPDELTA * * signal SIGTOTEST is used. */ #include #include #include #include #include #include "posixtest.h" #include "helpers.h" #define TIMERSEC 5 #define CLOCKOFFSET 4 #define SLEEPDELTA 3 #define ACCEPTABLEDELTA 1 #define SHORTTIME 1 #define SIGTOTEST SIGALRM void handler(int signo) { printf("Caught signal\n"); } int main(int argc, char *argv[]) { struct sigevent ev; struct sigaction act; struct timespec tsclock, ts, tsleft, tsreset; struct itimerspec its; timer_t tid; sigset_t set; /* Check that we're root...can't call clock_settime with CLOCK_REALTIME otherwise */ if(getuid() != 0) { printf("Run this test as ROOT, not as a Regular User\n"); return PTS_UNTESTED; } /* * set up sigevent for timer * set up signal set for sigwait * set up sigaction to catch signal */ ev.sigev_notify = SIGEV_SIGNAL; ev.sigev_signo = SIGTOTEST; act.sa_handler=handler; act.sa_flags=0; if ( (sigemptyset(&set) != 0) || (sigemptyset(&act.sa_mask) != 0) ) { perror("sigemptyset() was not successful\n"); return PTS_UNRESOLVED; } if (sigaddset(&set, SIGTOTEST) != 0) { perror("sigaddset() was not successful\n"); return PTS_UNRESOLVED; } if (sigaction(SIGTOTEST, &act, 0) != 0) { perror("sigaction() was not successful\n"); return PTS_UNRESOLVED; } if (timer_create(CLOCK_REALTIME, &ev, &tid) != 0) { perror("timer_create() did not return success\n"); return PTS_UNRESOLVED; } its.it_interval.tv_sec = 0; its.it_interval.tv_nsec = 0; its.it_value.tv_sec = TIMERSEC; its.it_value.tv_nsec = 0; if (timer_settime(tid, 0, &its, NULL) != 0) { perror("timer_settime() did not return success\n"); return PTS_UNRESOLVED; } if (clock_gettime(CLOCK_REALTIME, &tsclock) != 0) { printf("clock_gettime() did not return success\n"); return PTS_UNRESOLVED; } tsclock.tv_sec -= CLOCKOFFSET; getBeforeTime(&tsreset); if (clock_settime(CLOCK_REALTIME, &tsclock) != 0) { printf("clock_settime() was not successful\n"); return PTS_UNRESOLVED; } ts.tv_sec=TIMERSEC+SLEEPDELTA; ts.tv_nsec=0; if (nanosleep(&ts, &tsleft) != -1) { printf("nanosleep() not interrupted\n"); return PTS_FAIL; } if ( abs(tsleft.tv_sec-SLEEPDELTA) <= ACCEPTABLEDELTA) { printf("Test PASSED\n"); tsreset.tv_sec += TIMERSEC; setBackTime(tsreset); return PTS_PASS; } else { printf("Timer did not last for correct amount of time\n"); printf("timer: %d != correct %d\n", (int) ts.tv_sec- (int) tsleft.tv_sec, TIMERSEC); return PTS_FAIL; } return PTS_UNRESOLVED; } posixtestsuite/conformance/interfaces/clock_settime/17-2.c0100644000000000000000000000341407575170274022705 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * * Error condition API test for the clock_id parameter of the * clock_settime() function. * * Test calling clock_settime() with the following clock_id values: * MIN INT = INT32_MIN * MAX INT = INT32_MAX * MIN INT - 1 = 2147483647 (this is what gcc will set to) * MAX INT + 1 = -2147483647 (this is what gcc will set to) * unassigned value = -1073743192 (ex. of what gcc will set to) * unassigned value = 1073743192 (ex. of what gcc will set to) * -1 * 17 (currently not = to any clock) * * The date chosen is Nov 12, 2002 ~11:13am (date when test was first * written). */ #include #include #include #include #include "posixtest.h" #define TESTTIME 1037128358 #define NUMINVALIDTESTS 8 static int invalid_tests[NUMINVALIDTESTS] = { INT32_MIN, INT32_MAX, 2147483647, -2147483647, -1073743192, 1073743192, -1, 17 }; int main(int argc, char *argv[]) { struct timespec tpset; int i; int failure = 0; tpset.tv_sec = TESTTIME; tpset.tv_nsec = 0; for (i = 0; i < NUMINVALIDTESTS; i++) { if (clock_settime(invalid_tests[i], &tpset) == -1) { if (EINVAL != errno) { printf("errno != EINVAL\n"); failure = 1; } } else { printf("clock_settime() did not return -1\n"); failure = 1; } } if (failure) { printf("At least one test FAILED -- see above\n"); return PTS_FAIL; } else { printf("All tests PASSED\n"); return PTS_PASS; } printf("This code should not be executed.\n"); return PTS_UNRESOLVED; } posixtestsuite/conformance/interfaces/clock_settime/speculative/0040755000000000000000000000000010515625163024466 5ustar rootrootposixtestsuite/conformance/interfaces/clock_settime/speculative/4-4.c0100644000000000000000000000700407606620340025133 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * * Note: This test is not based on the POSIX spec, but is a speculation * about behavior for an assertion where the POSIX spec does not make a * statement about the behavior in either case. * * Test that if clock_settime() changes the value for CLOCK_REALTIME, * a repeating absolute timer uses this new value for expires. * * Document whether expirations which have already happened happen again or * not. * * Steps: * - get time T0 * - create/enable a timer to expire at T1 = T0 + TIMERINTERVAL and repeat * at interval TIMERINTERVAL * - sleep for time TIMERINTERVAL+ADDITIONALEXPIRES*TIMERINTERAL (must do * in a loop to catch all expires) * - set time backward to T0 * - sleep for time TIMERINTERVAL and ensure timer expires (2X) * * signal SIGTOTEST is used. */ #include #include #include #include #include #include "posixtest.h" #include "../helpers.h" #define TIMERINTERVAL 5 #define ADDITIONALEXPIRES 2 #define ADDITIONALDELTA 1 #define SIGTOTEST SIGALRM int caught = 0; void handler(int signo) { printf("Caught signal\n"); caught++; } int main(int argc, char *argv[]) { struct sigevent ev; struct sigaction act; struct timespec tpT0, tpclock, tsreset; struct itimerspec its; timer_t tid; int i, flags = 0, nocaught = 0; /* * set up sigevent for timer * set up sigaction to catch signal */ ev.sigev_notify = SIGEV_SIGNAL; ev.sigev_signo = SIGTOTEST; act.sa_handler=handler; act.sa_flags=0; if (sigemptyset(&act.sa_mask) != 0) { perror("sigemptyset() was not successful\n"); return PTS_UNRESOLVED; } if (sigaction(SIGTOTEST, &act, 0) != 0) { perror("sigaction() was not successful\n"); return PTS_UNRESOLVED; } if (clock_gettime(CLOCK_REALTIME, &tpT0) != 0) { perror("clock_gettime() was not successful\n"); return PTS_UNRESOLVED; } if (timer_create(CLOCK_REALTIME, &ev, &tid) != 0) { perror("timer_create() did not return success\n"); return PTS_UNRESOLVED; } flags |= TIMER_ABSTIME; its.it_interval.tv_sec = TIMERINTERVAL; its.it_interval.tv_nsec = 0; its.it_value.tv_sec = tpT0.tv_sec + TIMERINTERVAL; its.it_value.tv_nsec = tpT0.tv_nsec; if (timer_settime(tid, flags, &its, NULL) != 0) { perror("timer_settime() did not return success\n"); return PTS_UNRESOLVED; } sleep(TIMERINTERVAL); for (i = 0; i < ADDITIONALEXPIRES; i++) { sleep(TIMERINTERVAL); } tpclock.tv_sec = tpT0.tv_sec; tpclock.tv_nsec = tpT0.tv_nsec; getBeforeTime(&tsreset); if (clock_settime(CLOCK_REALTIME, &tpclock) != 0) { printf("clock_settime() was not successful\n"); return PTS_UNRESOLVED; } caught = 0; sleep(TIMERINTERVAL+ADDITIONALDELTA); if (caught == 1) { printf("Caught the first signal\n"); } else { printf("FAIL: Didn't catch timer after TIMERINTERVAL.\n"); nocaught = 1; } sleep(TIMERINTERVAL+ADDITIONALDELTA); if (caught >= 2) { printf("Caught another signal\n"); } else { printf("Caught %d < 2 signals\n", caught); nocaught = 1; } if (nocaught) { printf("Implementation does not repeat signals on clock reset\n"); } else { printf("Implementation does repeat signals on clock reset\n"); } // If we finish, pass tsreset.tv_sec += 2*(TIMERINTERVAL+ADDITIONALDELTA); setBackTime(tsreset); return PTS_PASS; } posixtestsuite/conformance/interfaces/clock_settime/speculative/4-3.c0100644000000000000000000000702307623007673025142 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * * Test that if clock_settime() changes the value for CLOCK_REALTIME, * an absolute timer which would now have expired in the past * will expire immediately (with no error). * Test with a repeating absolute timer and set the clock forward past * > 1 expirations of that timer. * * Steps: * - get time T0 * - create/enable a timer to expire at T1 = T0 + TIMEROFFSET and repeat * at interval TIMERINTERVAL * - set time forward to T1 + EXPECTEDOVERRUNS*TIMERINTERVAL * - ensure that timer has expired with no error * - ensure that the overrun count is EXPECTEDOVERRUNS * * Note: The POSIX spec is unclear what exactly the overrun count * should be in this case. It is only speculation that it == * EXPECTEDOVERRUNS. Either way passes. * Information based on discussions with: * benjamin.thery REMOVE-THIS AT bull DOT net * george REMOVE-THIS AT mvista DOT com * * signal SIGTOTEST is used. */ #include #include #include #include #include #include "posixtest.h" #include "../helpers.h" #define TIMEROFFSET 3 #define TIMERINTERVAL 5 #define EXPECTEDOVERRUNS 3 #define SHORTTIME 1 #define SIGTOTEST SIGALRM int caught = 0; void handler(int signo) { printf("Caught signal\n"); caught++; } int main(int argc, char *argv[]) { struct sigevent ev; struct sigaction act; struct timespec tpT0, tpclock, tpreset; struct itimerspec its; timer_t tid; int flags = 0, overruns; /* * set up sigevent for timer * set up sigaction to catch signal */ ev.sigev_notify = SIGEV_SIGNAL; ev.sigev_signo = SIGTOTEST; act.sa_handler=handler; act.sa_flags=0; if (sigemptyset(&act.sa_mask) != 0) { perror("sigemptyset() was not successful\n"); return PTS_UNRESOLVED; } if (sigaction(SIGTOTEST, &act, 0) != 0) { perror("sigaction() was not successful\n"); return PTS_UNRESOLVED; } if (clock_gettime(CLOCK_REALTIME, &tpT0) != 0) { perror("clock_gettime() was not successful\n"); return PTS_UNRESOLVED; } if (timer_create(CLOCK_REALTIME, &ev, &tid) != 0) { perror("timer_create() did not return success\n"); return PTS_UNRESOLVED; } flags |= TIMER_ABSTIME; its.it_interval.tv_sec = TIMERINTERVAL; its.it_interval.tv_nsec = 0; its.it_value.tv_sec = tpT0.tv_sec + TIMEROFFSET; its.it_value.tv_nsec = tpT0.tv_nsec; if (timer_settime(tid, flags, &its, NULL) != 0) { perror("timer_settime() did not return success\n"); return PTS_UNRESOLVED; } tpclock.tv_sec = its.it_value.tv_sec + EXPECTEDOVERRUNS*TIMERINTERVAL; tpclock.tv_nsec = its.it_value.tv_nsec; getBeforeTime(&tpreset); if (clock_settime(CLOCK_REALTIME, &tpclock) != 0) { printf("clock_settime() was not successful\n"); return PTS_UNRESOLVED; } sleep(SHORTTIME); overruns = timer_getoverrun(tid); if (overruns == EXPECTEDOVERRUNS) { printf("Overrun count == # of repeating timer expirys\n"); } else { printf("Overrun count =%d, not # of repeating timer expirys\n", overruns); } tpreset.tv_sec += SHORTTIME; setBackTime(tpreset); if (caught == 1) { printf("Caught the correct number of signals\n"); } else { printf("FAIL: Caught %d signals, not 1\n", caught); printf("Test FAILED\n"); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/clock_settime/4-1.c0100644000000000000000000000664310056771274022622 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * * Test that if clock_settime() changes the value for CLOCK_REALTIME, * then any absolute timers will use the new time for expiration. * * Steps: * - get time T0 * - create/enable a timer to expire at T1 = T0 + TIMEROFFSET * - sleep SLEEPTIME seconds (SLEEPTIME should be < TIMEROFFSET, * but > ACCEPTABLEDELTA) * - set time back to T0 * - wait for the timer to expire * - get time T2 * - ensure that: T2 >= T1 and (T2-T1) <= ACCEPTABLEDELTA * * signal SIGTOTEST is used. * * adam.li: I think should check that (abs(T2-T1) <= ACCEPTABLEDELTA) * 2004-04-30 */ #include #include #include #include #include "posixtest.h" #include "helpers.h" // SLEEPTIME < TIMEROFFSET // SLEEPTIME > ACCEPTABLEDELTA #define SLEEPTIME 3 #define TIMEROFFSET 9 #define ACCEPTABLEDELTA 1 #define SIGTOTEST SIGALRM int main(int argc, char *argv[]) { struct sigevent ev; struct timespec tpT0, tpT2, tpreset; struct itimerspec its; timer_t tid; int delta; int sig; sigset_t set; int flags = 0; /* Check that we're root...can't call clock_settime with CLOCK_REALTIME otherwise */ if(getuid() != 0) { printf("Run this test as ROOT, not as a Regular User\n"); return PTS_UNTESTED; } /* * set up sigevent for timer * set up signal set for sigwait */ ev.sigev_notify = SIGEV_SIGNAL; ev.sigev_signo = SIGTOTEST; if (sigemptyset(&set) != 0) { perror("sigemptyset() was not successful\n"); return PTS_UNRESOLVED; } if (sigaddset(&set, SIGTOTEST) != 0) { perror("sigaddset() was not successful\n"); return PTS_UNRESOLVED; } if (sigprocmask(SIG_BLOCK, &set, NULL) == -1) { perror("sigprocmask() failed\n"); return PTS_UNRESOLVED; } if (clock_gettime(CLOCK_REALTIME, &tpT0) != 0) { perror("clock_gettime() was not successful\n"); return PTS_UNRESOLVED; } if (timer_create(CLOCK_REALTIME, &ev, &tid) != 0) { perror("timer_create() did not return success\n"); return PTS_UNRESOLVED; } flags |= TIMER_ABSTIME; its.it_interval.tv_sec = 0; its.it_interval.tv_nsec = 0; its.it_value.tv_sec = tpT0.tv_sec + TIMEROFFSET; its.it_value.tv_nsec = tpT0.tv_nsec; if (timer_settime(tid, flags, &its, NULL) != 0) { perror("timer_settime() did not return success\n"); return PTS_UNRESOLVED; } sleep(SLEEPTIME); getBeforeTime(&tpreset); if (clock_settime(CLOCK_REALTIME, &tpT0) != 0) { perror("clock_settime() was not successful"); return PTS_UNRESOLVED; } if (sigwait(&set, &sig) == -1) { perror("sigwait() was not successful\n"); return PTS_UNRESOLVED; } if (clock_gettime(CLOCK_REALTIME, &tpT2) != 0) { printf("clock_gettime() was not successful\n"); return PTS_UNRESOLVED; } delta = tpT2.tv_sec - its.it_value.tv_sec; // add back time waited to reset value and reset time tpreset.tv_sec += tpT2.tv_sec - tpT0.tv_sec; setBackTime(tpreset); printf("delta: %d\n", delta); if ( (delta <= ACCEPTABLEDELTA) && (delta >= 0) ) { printf("Test PASSED\n"); return PTS_PASS; } else { printf("FAIL: Ended %d, not %d\n", (int) tpT2.tv_sec, (int) its.it_value.tv_sec); return PTS_FAIL; } printf("This code should not be executed.\n"); return PTS_UNRESOLVED; } posixtestsuite/conformance/interfaces/clock_settime/5-2.c0100644000000000000000000000644210021017161022575 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * * Test that if clock_settime() changes the value for CLOCK_REALTIME, * then any relative timers still expire when the time interval * has elapsed. [Test where clock_settime() sets timer forward in time.] * * Steps: * - set a timer to expire in TIMERSEC * - set the clock forward CLOCKOFFSET seconds * - nanosleep for TIMERSEC+SLEEPDELTA seconds -> timer should expire * - determine if the time remaining in nanosleep ~= SLEEPDELTA * * signal SIGTOTEST is used. */ #include #include #include #include #include #include "posixtest.h" #include "helpers.h" #define TIMERSEC 5 #define CLOCKOFFSET 4 #define SLEEPDELTA 3 #define ACCEPTABLEDELTA 1 #define SHORTTIME 1 #define SIGTOTEST SIGALRM void handler(int signo) { printf("Caught signal\n"); } int main(int argc, char *argv[]) { struct sigevent ev; struct sigaction act; struct timespec tsclock, ts, tsleft, tsreset; struct itimerspec its; timer_t tid; sigset_t set; /* Check that we're root...can't call clock_settime with CLOCK_REALTIME otherwise */ if(getuid() != 0) { printf("Run this test as ROOT, not as a Regular User\n"); return PTS_UNTESTED; } /* * set up sigevent for timer * set up signal set for sigwait * set up sigaction to catch signal */ ev.sigev_notify = SIGEV_SIGNAL; ev.sigev_signo = SIGTOTEST; act.sa_handler=handler; act.sa_flags=0; if ( (sigemptyset(&set) != 0) || (sigemptyset(&act.sa_mask) != 0) ) { perror("sigemptyset() was not successful\n"); return PTS_UNRESOLVED; } if (sigaddset(&set, SIGTOTEST) != 0) { perror("sigaddset() was not successful\n"); return PTS_UNRESOLVED; } if (sigaction(SIGTOTEST, &act, 0) != 0) { perror("sigaction() was not successful\n"); return PTS_UNRESOLVED; } if (timer_create(CLOCK_REALTIME, &ev, &tid) != 0) { perror("timer_create() did not return success\n"); return PTS_UNRESOLVED; } its.it_interval.tv_sec = 0; its.it_interval.tv_nsec = 0; its.it_value.tv_sec = TIMERSEC; its.it_value.tv_nsec = 0; if (timer_settime(tid, 0, &its, NULL) != 0) { perror("timer_settime() did not return success\n"); return PTS_UNRESOLVED; } if (clock_gettime(CLOCK_REALTIME, &tsclock) != 0) { printf("clock_gettime() did not return success\n"); return PTS_UNRESOLVED; } tsclock.tv_sec += CLOCKOFFSET; getBeforeTime(&tsreset); if (clock_settime(CLOCK_REALTIME, &tsclock) != 0) { printf("clock_settime() was not successful\n"); return PTS_UNRESOLVED; } ts.tv_sec=TIMERSEC+SLEEPDELTA; ts.tv_nsec=0; if (nanosleep(&ts, &tsleft) != -1) { printf("nanosleep() not interrupted\n"); return PTS_FAIL; } if ( abs(tsleft.tv_sec-SLEEPDELTA) <= ACCEPTABLEDELTA) { printf("Test PASSED\n"); tsreset.tv_sec += TIMERSEC; setBackTime(tsreset); return PTS_PASS; } else { printf("Timer did not last for correct amount of time\n"); printf("timer: %d != correct %d\n", (int) ts.tv_sec- (int) tsleft.tv_sec, TIMERSEC); return PTS_FAIL; } printf("This code should not be executed.\n"); return PTS_UNRESOLVED; } posixtestsuite/conformance/interfaces/clock_settime/16-1.sh0100755000000000000000000000102707566257557023106 0ustar rootroot#!/bin/sh # Copyright (c) 2002, Intel Corporation. All rights reserved. # Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com # This file is licensed under the GPL license. For the full content # of this license, see the COPYING file at the top level of this # source tree. # Copyright (c) 2002, Intel Corporation. All rights reserved. # # Test that clock_settime() returns -1 on failure. # # This is tested implicitly via assertions 17-21. echo "Tested implicitly via assertions 17-21. See output for status." exit 0 posixtestsuite/conformance/interfaces/clock_settime/3-1.sh0100755000000000000000000000076207566257557023027 0ustar rootroot#!/bin/sh # Copyright (c) 2002, Intel Corporation. All rights reserved. # Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com # This file is licensed under the GPL license. For the full content # of this license, see the COPYING file at the top level of this # source tree. # Test that clock_settime() supports CLOCK_REALTIME. # # This is tested implicitly assertion 1 since CLOCK_REALTIME is # used as the clock echo "Test implicitly via assertion 1. See output for status." exit 0 posixtestsuite/conformance/interfaces/clock_settime/1-1.c0100644000000000000000000000406710154041573022604 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that clock_settime() sets clock_id to tp. * * The clock_id chosen for this test is CLOCK_REALTIME. * The date chosen is Nov 12, 2002 ~11:13am (date when test was first * written). */ #include #include #include #include #include "posixtest.h" #include "helpers.h" #ifndef PR_NSEC_PER_SEC #define PR_NSEC_PER_SEC 1000000000UL #endif #define TESTTIME 1037128358 #define ACCEPTABLEDELTA 1 int main(int argc, char *argv[]) { struct timespec tpset, tpget, tpreset, tpres; int delta,nsdelta; /* Check that we're root...can't call clock_settime with CLOCK_REALTIME otherwise */ if(getuid() != 0) { printf("Run this test as ROOT, not as a Regular User\n"); return PTS_UNTESTED; } if (clock_getres(CLOCK_REALTIME, &tpres) != 0){ printf("Time resolution is not provided\n"); tpres.tv_sec = 0; tpres.tv_nsec = 10000000; } getBeforeTime(&tpreset); tpset.tv_sec = TESTTIME; tpset.tv_nsec = 0; if (clock_settime(CLOCK_REALTIME, &tpset) == 0) { if (clock_gettime(CLOCK_REALTIME, &tpget) == -1) { printf("Error in clock_gettime()\n"); setBackTime(tpreset); return PTS_UNRESOLVED; } delta = tpget.tv_sec-tpset.tv_sec; nsdelta = PR_NSEC_PER_SEC - tpget.tv_nsec; if ( (delta <= ACCEPTABLEDELTA) && (delta >= 0) ) { printf("Test PASSED\n"); setBackTime(tpreset); return PTS_PASS; } else if( (nsdelta <= tpres.tv_nsec) && (delta == -1 )) { printf("Test PASSED\n"); setBackTime(tpreset); return PTS_PASS; } else { printf("clock does not appear to be set\n"); setBackTime(tpreset); return PTS_FAIL; } } else { printf("clock_settime() failed\n"); setBackTime(tpreset); return PTS_UNRESOLVED; } printf("This code should not be executed.\n"); setBackTime(tpreset); return PTS_UNRESOLVED; } posixtestsuite/conformance/interfaces/clock_settime/20-1.c0100644000000000000000000000205407575170274022675 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * * Test that clock_settime() sets errno = EINVAL if clock_id is * CLOCK_MONOTONIC. * * The date chosen is Nov 12, 2002 ~11:13am. */ #include #include #include #include "posixtest.h" #define TESTTIME 1037128358 int main(int argc, char *argv[]) { #ifdef CLOCK_MONOTONIC struct timespec tpset; tpset.tv_sec = TESTTIME; tpset.tv_nsec = 0; if (clock_settime(CLOCK_MONOTONIC, &tpset) == -1) { if (EINVAL == errno) { printf("Test PASSED\n"); return PTS_PASS; } else { printf("errno != EINVAL\n"); return PTS_FAIL; } } else { printf("clock_settime() did not fail with CLOCK_MONOTONIC\n"); return PTS_UNRESOLVED; } return PTS_UNRESOLVED; #else printf("CLOCK_MONOTONIC not supported\n"); return PTS_UNSUPPORTED; #endif } posixtestsuite/conformance/interfaces/clock_settime/helpers.h0100644000000000000000000000201207606620315023746 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * * Helper functions used to reset the time to close to the current * time at the end of the test. * * Since these helper functions are made specifically to be included * in certain tests, they make use of some libraries already included * by those tests. */ int getBeforeTime(struct timespec *tpget) { if (clock_gettime(CLOCK_REALTIME, tpget) != 0) { perror("clock_gettime() did not return success\n"); perror("clock may not be reset properly\n"); return PTS_UNRESOLVED; } return PTS_PASS; } int setBackTime(struct timespec tpset) { if (clock_settime(CLOCK_REALTIME, &tpset) != 0) { perror("clock_settime() did not return success\n"); perror("clock may not be reset properly\n"); return PTS_UNRESOLVED; } return PTS_PASS; } posixtestsuite/conformance/interfaces/clock_settime/6-1.c0100644000000000000000000000174407575170274022626 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that clock_settime() cannot set the monotonic clock CLOCK_MONOTONIC, * and will fail if invoked with clock CLOCK_MONOTONIC. * * The date chosen is Nov 12, 2002 ~11:13am. */ #include #include #include "posixtest.h" #define TESTTIME 1037128358 int main(int argc, char *argv[]) { #ifdef CLOCK_MONOTONIC struct timespec tpset; tpset.tv_sec = TESTTIME; tpset.tv_nsec = 0; if (clock_settime(CLOCK_MONOTONIC, &tpset) == -1) { printf("Test PASSED\n"); return PTS_PASS; } else { printf("clock_settime() did not fail with CLOCK_MONOTONIC\n"); return PTS_FAIL; } return PTS_UNRESOLVED; #else printf("CLOCK_MONOTONIC not supported\n"); return PTS_UNSUPPORTED; #endif } posixtestsuite/conformance/interfaces/clock_settime/7-1.c0100644000000000000000000000554310021017161022577 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * * Test that if clock_settime() changes the time for CLOCK_REALTIME, * then any threads blocked on clock_nanosleep() for the CLOCK_REALTIME * clock will use the new time for expiration. * * Steps: * - get time T0 * - in child: set clock_nanosleep() to sleep until time * T1 = T0 + SLEEPOFFSET * - in parent: sleep SMALLTIME (< SLEEPOFFSET) * - in parent: set time back to T0 * - in child: ensure time when clock_nanosleep() expires is within * ACCEPTABLEDELTA of T1 */ #include #include #include #include #include #include "posixtest.h" #include "helpers.h" #define SLEEPOFFSET 5 #define SMALLTIME 2 #define ACCEPTABLEDELTA 1 #define CHILDPASS 1 #define CHILDFAIL 0 int main(int argc, char *argv[]) { struct timespec tsT0, tsT1; int pid; /* Check that we're root...can't call clock_settime with CLOCK_REALTIME otherwise */ if(getuid() != 0) { printf("Run this test as ROOT, not as a Regular User\n"); return PTS_UNTESTED; } if (clock_gettime(CLOCK_REALTIME, &tsT0) != 0) { perror("clock_gettime() did not return success\n"); return PTS_UNRESOLVED; } if ((pid = fork()) == 0) { /* child here */ int flags = 0; struct timespec tsT2; tsT1.tv_sec=tsT0.tv_sec + SLEEPOFFSET; tsT1.tv_nsec=tsT0.tv_nsec; flags |= TIMER_ABSTIME; if (clock_nanosleep(CLOCK_REALTIME, flags, &tsT1, NULL) != 0) { printf("clock_nanosleep() did not return success\n"); return CHILDFAIL; } if (clock_gettime(CLOCK_REALTIME, &tsT2) != 0) { perror("clock_gettime() did not return success\n"); return CHILDFAIL; } if (tsT2.tv_sec >= tsT1.tv_sec) { if ( (tsT2.tv_sec-tsT1.tv_sec) <= ACCEPTABLEDELTA) { return CHILDPASS; } else { printf("Ended too late. %d >> %d\n", (int) tsT2.tv_sec, (int) tsT1.tv_sec); return CHILDFAIL; } } else { printf("Did not sleep for long enough %d < %d\n", (int) tsT2.tv_sec, (int) tsT1.tv_sec); return CHILDFAIL; } return CHILDFAIL; } else { /* parent here */ int i; struct timespec tsreset; sleep(SMALLTIME); if (clock_settime(CLOCK_REALTIME, &tsT0) != 0) { printf("clock_settime() did not return success\n"); return PTS_UNRESOLVED; } if (wait(&i) == -1) { perror("Error waiting for child to exit\n"); return PTS_UNRESOLVED; } getBeforeTime(&tsreset); // get current time tsreset.tv_sec += SMALLTIME; setBackTime(tsreset); if (WIFEXITED(i) && WEXITSTATUS(i)) { printf("Test PASSED\n"); return PTS_PASS; } else { printf("Test FAILED\n"); return PTS_FAIL; } } return PTS_UNRESOLVED; } posixtestsuite/conformance/interfaces/clock_settime/assertions.xml0100644000000000000000000001021607575522350025061 0ustar rootroot clock_settime() sets the clock clock_id to the value specified by tp. clock_settime() truncates time values that are between resolution multiples to the smaller resolution multiple clock_settime() supports CLOCK_REALTIME If clock_settime() changes the time for CLOCK_REALTIME, then any absolute timers will use the new time for expiration. If at this point, the timer should have expired in the past, it will expire immediately (no error). clock_settime() does not affect _relative_ timers (either timers or nanosleep() calls). These expire when the relative time interval elapses, regardless of what the clock says. clock_settime() cannot set the monotonic clock CLOCK_MONOTONIC and will fail if invoked with clock_id CLOCK_MONOTONIC If clock_settime() changes the time for CLOCK_REALTIME, then any threads blocked on clock_nanosleep() for the CLOCK_REALTIME clock will use the new time for expiration. If at this point, the timer should have expired in the past, it will expire immediately (no error). clock_settime() does not affect clock_nanosleep() _relative_ timers. These expire when the relative time interval elapses, regardless of what the clock says. If _POSIX_CPUTIME is defined, clock_settime() supports clock_ids obtained via clock_getcpuclockid(). The value set is the amount of execution time of the process associated with the clock. If _POSIX_CPUTIME is defined, clock_settime() supports clock_id CLOCK_PROCESS_CPUTIME_ID (= the CPU clock of the calling process). The value set is the amount of execution time of the calling process. If clock_settime() is used to change the value of a CPU-time clock, sporadic server scheduling policy is unaffected. If _POSIX_THREAD_CPUTIME is defined, clock_settime() supports clock_ids obtained via pthread_getcpuclockid(). The value set is the amount of execution time of the thread associated with the clock. If _POSIX_THREAD_CPUTIME is defined, clock_settime() supports clock_id CLOCK_THREAD_CPUTIME_ID (= the CPU clock of the calling thread). The value set is the amount of execution time of the calling thread. If clock_settime() is used to change the value of a CPU-time clock, sporadic server scheduling policy is unaffected. clock_settime() returns 0 on success clock_settime() returns -1 on failure clock_settime() sets errno=EINVAL if clock_id does not specify a known clock clock_settime() sets errno=EINVAL if tp is outside the valid range for clock_id clock_settime() sets errno=EINVAL if tp has a nsec value below 0 or above (or equal to) 1000 million clock_settime() sets errno=EINVAL if clock_id is CLOCK_MONOTONIC clock_settime() sets errno=EPERM if the calling process does not have privileges to set clockid (MAY, not SHOULD). posixtestsuite/conformance/interfaces/clock_settime/15-1.sh0100755000000000000000000000071407566257557023107 0ustar rootroot#!/bin/sh # Copyright (c) 2002, Intel Corporation. All rights reserved. # Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com # This file is licensed under the GPL license. For the full content # of this license, see the COPYING file at the top level of this # source tree. # Test that clock_settime() returns 0 on success. # # This is tested implicitly via assertion 1. echo "Tested implicitly via assertion 1. See output for status." exit 0 posixtestsuite/conformance/interfaces/clock_settime/coverage.txt0100644000000000000000000000213707572736545024516 0ustar rootrootThis document specifies the coverage of function clock_settime(). Assertion Covered? 1 YES 2 NO* 3 YES 4 YES - FAILing on this implementation 5 YES 6 YES 7 YES 8 YES 9 NO** Skipping CPU-time tests for now 10 NO** Skipping CPU-time tests for now 11 NO** Skipping CPU-time tests for now 12 NO** Skipping CPU-time tests for now 13 NO** Skipping CPU-time tests for now 14 NO** Skipping CPU-time tests for now 15 YES 16 YES 17 YES 18 YES 19 YES - FAILing on this implementation (possibly serious) 20 YES 21 WON'T - Will not test as this is a _may_ not a _should_. *Decided not to test this assertion. It seems like a lot of work for little payoff in terms of if the test passes. Would need to: Get the resolution; Set the time to desired value + 1/2 resolution time. Get the time. Ensure that time gotten isn't too much larger than desired value + resolution time. Depending on execution time of the test, this could never really be conclusive. The date chosen for all tests is November 12, 2002 at ~11:13am (The date when these tests were first written.) This corresponds to number 1037128358 posixtestsuite/conformance/interfaces/clock_settime/18-1.sh0100755000000000000000000000116207566257557023110 0ustar rootroot#!/bin/sh # Copyright (c) 2002, Intel Corporation. All rights reserved. # Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com # This file is licensed under the GPL license. For the full content # of this license, see the COPYING file at the top level of this # source tree. # # Test that clock_settime() sets errno=EINVAL if tp is outside the # valid range for clock_id. # # This is tested implicitly via assertion 19 to the best of tester's # knowledge. Cannot find additional parameters for CLOCK_REALTIME # in the POSIX specification echo "Tested implicitly via assertion 19. See output for status." exit 0 posixtestsuite/conformance/interfaces/clock_settime/8-1.c0100644000000000000000000000543310021017161022576 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * * Test that clock_settime() does not affect clock_nanosleep() * relative timers expiration times. * * Steps: * - get time T0 * - in child: set clock_nanosleep() to sleep for SLEEPSEC seconds * - in parent: sleep SMALLTIME (< SLEEPSEC) * - in parent: set time back to T0 * - in child: ensure time when clock_nanosleep() expires is within * ACCEPTABLEDELTA of T0+(SLEEPSEC-SMALLTIME) */ #include #include #include #include #include #include "posixtest.h" #include "helpers.h" #define SLEEPSEC 5 #define SMALLTIME 2 #define ACCEPTABLEDELTA 1 #define CHILDPASS 1 #define CHILDFAIL 0 int main(int argc, char *argv[]) { struct timespec tsT0, tssleep; int pid; /* Check that we're root...can't call clock_settime with CLOCK_REALTIME otherwise */ if(getuid() != 0) { printf("Run this test as ROOT, not as a Regular User\n"); return PTS_UNTESTED; } if (clock_gettime(CLOCK_REALTIME, &tsT0) != 0) { perror("clock_gettime() did not return success\n"); return PTS_UNRESOLVED; } if ((pid = fork()) == 0) { /* child here */ struct timespec tsend; int expectedsec; tssleep.tv_sec = SLEEPSEC; tssleep.tv_nsec = 0; if (clock_nanosleep(CLOCK_REALTIME, 0, &tssleep, NULL) != 0) { printf("clock_nanosleep() did not return success\n"); return CHILDFAIL; } if (clock_gettime(CLOCK_REALTIME, &tsend) != 0) { perror("clock_gettime() did not return success\n"); return CHILDFAIL; } expectedsec = tsT0.tv_sec + (SLEEPSEC-SMALLTIME); if (tsend.tv_sec >= expectedsec) { if ( (tsend.tv_sec-expectedsec) <= ACCEPTABLEDELTA) { return CHILDPASS; } else { printf("Ended too late. %d >> %d\n", (int) tsend.tv_sec, (int) expectedsec); return CHILDFAIL; } } else { printf("Did not sleep for long enough %d < %d\n", (int) tsend.tv_sec, (int) expectedsec); return CHILDFAIL; } return CHILDFAIL; } else { /* parent here */ int i; struct timespec tsreset; sleep(SMALLTIME); if (clock_settime(CLOCK_REALTIME, &tsT0) != 0) { printf("clock_settime() did not return success\n"); return PTS_UNRESOLVED; } if (wait(&i) == -1) { perror("Error waiting for child to exit\n"); return PTS_UNRESOLVED; } getBeforeTime(&tsreset); // get current time tsreset.tv_sec += SMALLTIME; setBackTime(tsreset); if (WIFEXITED(i) && WEXITSTATUS(i)) { printf("Test PASSED\n"); return PTS_PASS; } else { printf("Test FAILED\n"); return PTS_FAIL; } } return PTS_UNRESOLVED; } posixtestsuite/conformance/interfaces/clock_settime/7-2.c0100644000000000000000000000562610021017161022602 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * * Test that if clock_settime() changes the time for CLOCK_REALTIME, * then any threads blocked on clock_nanosleep() for the CLOCK_REALTIME * clock that would now have expired in the past will expire immediately. * * Steps: * - get time T0 * - in child: set clock_nanosleep() to sleep until time * T1 = T0 + SLEEPOFFSET * - in parent: set time forward to T2 = T1 + SMALLTIME * - in child: ensure clock_nanosleep() expires within ACCEPTABLEDELTA of * T2 */ #include #include #include #include #include #include "posixtest.h" #include "helpers.h" #define SLEEPOFFSET 5 #define SMALLTIME 2 #define ACCEPTABLEDELTA 1 #define CHILDPASS 1 #define CHILDFAIL 0 int main(int argc, char *argv[]) { struct timespec tsT0, tsT1, tsT2; int pid; /* Check that we're root...can't call clock_settime with CLOCK_REALTIME otherwise */ if(getuid() != 0) { printf("Run this test as ROOT, not as a Regular User\n"); return PTS_UNTESTED; } if (clock_gettime(CLOCK_REALTIME, &tsT0) != 0) { perror("clock_gettime() did not return success\n"); return PTS_UNRESOLVED; } tsT1.tv_sec=tsT0.tv_sec + SLEEPOFFSET; tsT1.tv_nsec=tsT0.tv_nsec; tsT2.tv_sec = tsT1.tv_sec + SMALLTIME; tsT2.tv_nsec = tsT1.tv_nsec; if ((pid = fork()) == 0) { /* child here */ int flags = 0; struct timespec tsT3; flags |= TIMER_ABSTIME; if (clock_nanosleep(CLOCK_REALTIME, flags, &tsT1, NULL) != 0) { printf("clock_nanosleep() did not return success\n"); return CHILDFAIL; } if (clock_gettime(CLOCK_REALTIME, &tsT3) != 0) { perror("clock_gettime() did not return success\n"); return CHILDFAIL; } if (tsT3.tv_sec >= tsT2.tv_sec) { if ( (tsT3.tv_sec-tsT2.tv_sec) <= ACCEPTABLEDELTA) { return CHILDPASS; } else { printf("Ended too late. %d >> %d\n", (int) tsT3.tv_sec, (int) tsT2.tv_sec); return CHILDFAIL; } } else { printf("Did not sleep for long enough %d < %d\n", (int) tsT3.tv_sec, (int) tsT2.tv_sec); return CHILDFAIL; } return CHILDFAIL; } else { /* parent here */ int i; struct timespec tsreset; sleep(1); getBeforeTime(&tsreset); if (clock_settime(CLOCK_REALTIME, &tsT2) != 0) { printf("clock_settime() did not return success\n"); return PTS_UNRESOLVED; } if (wait(&i) == -1) { perror("Error waiting for child to exit\n"); return PTS_UNRESOLVED; } setBackTime(tsreset); //should be ~= before time if (WIFEXITED(i) && WEXITSTATUS(i)) { printf("Test PASSED\n"); return PTS_PASS; } else { printf("Test FAILED\n"); return PTS_FAIL; } } return PTS_UNRESOLVED; } posixtestsuite/conformance/interfaces/clock_settime/4-2.c0100644000000000000000000000507207606627054022621 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * * Test that if clock_settime() changes the value for CLOCK_REALTIME, * an absolute timer which would now have expired in the past * will expire immediately (with no error). * * Steps: * - get time T0 * - create/enable a timer to expire at T1 = T0 + TIMEROFFSET * - set time forward to T1 + CLOCKOFFSET * - ensure that timer has expired with no error * * signal SIGTOTEST is used. */ #include #include #include #include #include #include "posixtest.h" #include "helpers.h" #define TIMEROFFSET 9 #define CLOCKOFFSET 4 #define SHORTTIME 1 #define SIGTOTEST SIGALRM struct timespec tpreset; void handler(int signo) { printf("Caught signal\n"); printf("Test PASSED\n"); setBackTime(tpreset); exit(PTS_PASS); } int main(int argc, char *argv[]) { struct sigevent ev; struct sigaction act; struct timespec tpT0, tpclock; struct itimerspec its; timer_t tid; int flags = 0; /* * set up sigevent for timer * set up sigaction to catch signal */ ev.sigev_notify = SIGEV_SIGNAL; ev.sigev_signo = SIGTOTEST; act.sa_handler=handler; act.sa_flags=0; if (sigemptyset(&act.sa_mask) != 0) { perror("sigemptyset() was not successful\n"); return PTS_UNRESOLVED; } if (sigaction(SIGTOTEST, &act, 0) != 0) { perror("sigaction() was not successful\n"); return PTS_UNRESOLVED; } if (clock_gettime(CLOCK_REALTIME, &tpT0) != 0) { perror("clock_gettime() was not successful\n"); return PTS_UNRESOLVED; } if (timer_create(CLOCK_REALTIME, &ev, &tid) != 0) { perror("timer_create() did not return success\n"); return PTS_UNRESOLVED; } flags |= TIMER_ABSTIME; its.it_interval.tv_sec = 0; its.it_interval.tv_nsec = 0; its.it_value.tv_sec = tpT0.tv_sec + TIMEROFFSET; its.it_value.tv_nsec = tpT0.tv_nsec; if (timer_settime(tid, flags, &its, NULL) != 0) { perror("timer_settime() did not return success\n"); return PTS_UNRESOLVED; } tpclock.tv_sec = its.it_value.tv_sec + CLOCKOFFSET; tpclock.tv_nsec = its.it_value.tv_nsec; getBeforeTime(&tpreset); if (clock_settime(CLOCK_REALTIME, &tpclock) != 0) { printf("clock_settime() was not successful\n"); return PTS_UNRESOLVED; } sleep(SHORTTIME); printf("timer should have expired _immediately_\n"); tpreset.tv_sec += SHORTTIME; setBackTime(tpreset); return PTS_FAIL; } posixtestsuite/conformance/interfaces/clock/0040755000000000000000000000000010515625161020406 5ustar rootrootposixtestsuite/conformance/interfaces/clock/1-1.c0100644000000000000000000000301007577703017021052 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * * Test that clock() returns a clock_t containing the processor time * since a specific point in time. * Dividing the return value by CLOCKS_PER_SEC gives time in seconds. * * 12/17/02 - Checking in correction made by * jim.houston REMOVE-THIS AT attbi DOT com * Test needed to do something as opposed to idle sleep to * get the CPU time to increase. */ #include #include #include #include "posixtest.h" #define LARGENUMBER 8000000 int main(int argc, char *argv[]) { clock_t c1, c2; double sec1, sec2; int i; c1 = clock(); sec1 = c1/CLOCKS_PER_SEC; for (i = 0; i < LARGENUMBER; i++) { // keep busy so CPU time increases clock(); } c2 = clock(); sec2 = c2/CLOCKS_PER_SEC; if (sec2 > sec1) { printf("Times T1=%.2f, T2=%.2f\n", sec1, sec2); printf("Test PASSED\n"); return PTS_PASS; } else { if (sec2 < sec1) { /* * probably wrapping happened; however, since * we do not know the wrap value, results are * undefined */ printf("TEST AGAIN: Times probably wrapped\n"); return PTS_UNRESOLVED; } else { printf("Error with processor times T1=%.2f, T2=%.2f\n", sec1, sec2); return PTS_FAIL; } } return PTS_UNRESOLVED; } posixtestsuite/conformance/interfaces/clock/assertions.xml0100644000000000000000000000154407575522043023332 0ustar rootroot clock() returns a clock_t containing the processor time since a specific point in time (implementation defined). This return value should be divided by CLOCKS_PER_SEC to get the time in seconds. CLOCKS_PER_SEC == 1,000,000 in time.h clock() returns (clock_t) - 1 if the processor time used cannot be represented or is somehow unavailable clock() is best used to get a delta between two times in a program. It is acceptable for clock() to wrap on some implementations. (No specifics on when/where.) posixtestsuite/conformance/interfaces/clock/coverage.txt0100644000000000000000000000070207567272232022750 0ustar rootrootThis document defines the coverage for the clock() function. Assertion Covered? 1 YES 2 YES 3 WON'T 4 YES 5 WON'T ERRORS ====== 1 is failing on test implementation. It appears clock() is always returning 0. WON'T TEST ========== 3 - Will not test the error values of clock() because it is unknown how to cause these errors to happen. 5 - Cannot test that clock() can wrap because it is unknown which implementations it will wrap in. posixtestsuite/conformance/interfaces/clock/2-1.c0100644000000000000000000000204307600211201021030 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * * @pt:XSI * Test that CLOCKS_PER_SEC == 1,000,000 in */ // Applied patch from Craig Rodrigues; no longer assumes CLOCKS_PER_SEC is long // 12-18-02 Per suggestion by neal REMOVE-THIS AT cs DOT uml DOT edu started // using intmax_h and INTMAX_C. Also added use of PRIdMAX per his suggestion. #include #include #include #include #include "posixtest.h" #define EXPECTEDVALUE INTMAX_C(1000000) int main(int argc, char *argv[]) { intmax_t clocks_per_sec = (intmax_t)CLOCKS_PER_SEC; if (EXPECTEDVALUE == CLOCKS_PER_SEC) { printf("Test PASSED\n"); return PTS_PASS; } else { printf("FAIL: %" PRIdMAX " != %" PRIdMAX "\n", clocks_per_sec, EXPECTEDVALUE); return PTS_FAIL; } return PTS_UNRESOLVED; } posixtestsuite/conformance/interfaces/clock/4-1.sh0100755000000000000000000000075407567272232021263 0ustar rootroot#!/bin/sh # Copyright (c) 2002, Intel Corporation. All rights reserved. # Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com # This file is licensed under the GPL license. For the full content # of this license, see the COPYING file at the top level of this # source tree. # Test that clock() is best used to get a delta between two times in # a program. # # This is tested implicitly via assertion 1. echo "Tested implicitly via assertion 1. See output for status." exit 0 posixtestsuite/conformance/interfaces/pthread_equal/0040755000000000000000000000000010515625213022127 5ustar rootrootposixtestsuite/conformance/interfaces/pthread_equal/1-1.c0100644000000000000000000000237707626776064022623 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_equal() * shall compare the thread ids t1 and t2. The function shall return a non-zero * value if t1 and t2 are equal, othersise zero shall be returned. * No errors are defined. * * Steps: * 1. Create a thread * 2. Call pthread_equal and pass to it the new thread in both parameters. * They should both be equal. * */ #include #include #include "posixtest.h" void *a_thread_func() { pthread_exit(0); return NULL; } int main() { pthread_t new_th; /* Create a new thread. */ if(pthread_create(&new_th, NULL, a_thread_func, NULL) != 0) { perror("Error creating thread\n"); return PTS_UNRESOLVED; } /* Call pthread_equal() and pass to it the new thread ID in both * parameters. It should return a non-zero value, indicating that * they are equal. */ if(pthread_equal(new_th, new_th) == 0) { printf("Test FAILED\n"); return PTS_FAIL; } else { printf("Test PASSED\n"); return PTS_PASS; } } posixtestsuite/conformance/interfaces/pthread_equal/testfrmw.c0100644000000000000000000000407210126216076024147 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * * This file is a wrapper to use the tests from the NPTL Test & Trace Project * with either the Linux Test Project or the Open POSIX Test Suite. * The following function are defined: * void output_init() * void output_fini() * void output(char * string, ...) * * The are used to output informative text (as a printf). */ #include #include /* We use a mutex to avoid conflicts in traces */ static pthread_mutex_t m_trace = PTHREAD_MUTEX_INITIALIZER; /*****************************************************************************************/ /******************************* stdout module *****************************************/ /*****************************************************************************************/ /* The following functions will output to stdout */ #if (1) void output_init() { /* do nothing */ return; } void output( char * string, ... ) { va_list ap; char *ts="[??:??:??]"; struct tm * now; time_t nw; pthread_mutex_lock(&m_trace); nw = time(NULL); now = localtime(&nw); if (now == NULL) printf(ts); else printf("[%2.2d:%2.2d:%2.2d]", now->tm_hour, now->tm_min, now->tm_sec); va_start( ap, string); vprintf(string, ap); va_end(ap); pthread_mutex_unlock(&m_trace); } void output_fini() { /*do nothing */ return; } #endif posixtestsuite/conformance/interfaces/pthread_equal/1-2.c0100644000000000000000000000261407626776064022616 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_equal() * shall compare the thread ids t1 and t2. The function shall return a non-zero * value if t1 and t2 are equal, othersise zero shall be returned. * No errors are defined. * * Steps: * 1. Create 2 threads * 2. Call pthread_equal and pass to it the two threads. * They should not be equal. * */ #include #include #include "posixtest.h" void *a_thread_func() { pthread_exit(0); return NULL; } int main() { pthread_t new_th1, new_th2; /* Create a new thread. */ if(pthread_create(&new_th1, NULL, a_thread_func, NULL) != 0) { perror("Error creating thread\n"); return PTS_UNRESOLVED; } /* Create another new thread. */ if(pthread_create(&new_th2, NULL, a_thread_func, NULL) != 0) { perror("Error creating thread\n"); return PTS_UNRESOLVED; } /* Call pthread_equal() and pass to it the 2 new threads. * It should return a zero value, indicating that * they are not equal. */ if(pthread_equal(new_th1, new_th2) != 0) { printf("Test FAILED\n"); return PTS_FAIL; } else { printf("Test PASSED\n"); return PTS_PASS; } } posixtestsuite/conformance/interfaces/pthread_equal/assertions.xml0100644000000000000000000000063110123753153025040 0ustar rootroot The function int pthread_equal(pthread_t t1, pthread_t t2) compares the thread ids t1 and t2. It returns a non-zero value if t1 and t2 are equal, othersise it returns zero. No errors are defined. The function must not return EINTR posixtestsuite/conformance/interfaces/pthread_equal/coverage.txt0100644000000000000000000000014607610632300024456 0ustar rootrootThis document defines the coverage for the pthread_equal() function: Assertion Tested? 1 YES NOTE: posixtestsuite/conformance/interfaces/pthread_equal/testfrmw.h0100644000000000000000000000456410126216076024162 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * * This file is a wrapper to use the tests from the NPTL Test & Trace Project * with either the Linux Test Project or the Open POSIX Test Suite. * The following macros are defined here: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate without calling one of those macros. * * */ #include "posixtest.h" #include /* for the strerror() routine */ #ifdef __GNUC__ /* We are using GCC */ #define UNRESOLVED(x, s) \ { output("Test %s unresolved: got %i (%s) on line %i (%s)\n", __FILE__, x, strerror(x), __LINE__, s); \ output_fini(); \ exit(PTS_UNRESOLVED); } #define FAILED(s) \ { output("Test %s FAILED: %s\n", __FILE__, s); \ output_fini(); \ exit(PTS_FAIL); } #define PASSED \ output_fini(); \ exit(PTS_PASS); #define UNTESTED(s) \ { output("File %s cannot test: %s\n", __FILE__, s); \ output_fini(); \ exit(PTS_UNTESTED); \ } #else /* not using GCC */ #define UNRESOLVED(x, s) \ { output("Test unresolved: got %i (%s) on line %i (%s)\n", x, strerror(x), __LINE__, s); \ output_fini(); \ exit(PTS_UNRESOLVED); } #define FAILED(s) \ { output("Test FAILED: %s\n", s); \ output_fini(); \ exit(PTS_FAIL); } #define PASSED \ output_fini(); \ exit(PTS_PASS); #define UNTESTED(s) \ { output("Unable to test: %s\n", s); \ output_fini(); \ exit(PTS_UNTESTED); \ } #endif posixtestsuite/conformance/interfaces/pthread_equal/2-1.c0100644000000000000000000001652410126216076022600 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertion: * * The function does not return EINTR * The steps are: * -> kill a thread which calls pthread_equal * -> check that EINTR is never returned */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /********************************************************************************************/ /****************************** standard includes *****************************************/ /********************************************************************************************/ #include #include #include #include #include #include #include #include #include /********************************************************************************************/ /****************************** Test framework *****************************************/ /********************************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /********************************************************************************************/ /********************************** Configuration ******************************************/ /********************************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif #define WITH_SYNCHRO /********************************************************************************************/ /*********************************** Test cases *****************************************/ /********************************************************************************************/ char do_it=1; unsigned long count_ope=0; #ifdef WITH_SYNCHRO sem_t semsig1; sem_t semsig2; unsigned long count_sig=0; #endif sigset_t usersigs; typedef struct { int sig; #ifdef WITH_SYNCHRO sem_t *sem; #endif } thestruct; /* the following function keeps on sending the signal to the process */ void * sendsig (void * arg) { thestruct *thearg = (thestruct *) arg; int ret; pid_t process; process=getpid(); /* We block the signals SIGUSR1 and SIGUSR2 for this THREAD */ ret = pthread_sigmask(SIG_BLOCK, &usersigs, NULL); if (ret != 0) { UNRESOLVED(ret, "Unable to block SIGUSR1 and SIGUSR2 in signal thread"); } while (do_it) { #ifdef WITH_SYNCHRO if ((ret = sem_wait(thearg->sem))) { UNRESOLVED(errno, "Sem_wait in sendsig"); } count_sig++; #endif ret = kill(process, thearg->sig); if (ret != 0) { UNRESOLVED(errno, "Kill in sendsig"); } } return NULL; } /* Next are the signal handlers. */ /* This one is registered for signal SIGUSR1 */ void sighdl1(int sig) { #ifdef WITH_SYNCHRO if (sem_post(&semsig1)) { UNRESOLVED(errno, "Sem_post in signal handler 1"); } #endif } /* This one is registered for signal SIGUSR2 */ void sighdl2(int sig) { #ifdef WITH_SYNCHRO if (sem_post(&semsig2)) { UNRESOLVED(errno, "Sem_post in signal handler 2"); } #endif } /* Test function -- calls pthread_equal() and checks that EINTR is never returned. */ void * test(void * arg) { int ret=0; pthread_t me = pthread_self(); /* We don't block the signals SIGUSR1 and SIGUSR2 for this THREAD */ ret = pthread_sigmask(SIG_UNBLOCK, &usersigs, NULL); if (ret != 0) { UNRESOLVED(ret, "Unable to unblock SIGUSR1 and SIGUSR2 in worker thread"); } while (do_it) { count_ope++; ret = pthread_equal(me, *(pthread_t *)arg); if (ret != 0) { UNRESOLVED(ret, "pthread_equal failed to return the correct value"); } ret = pthread_equal(me, me); if (ret == 0) { UNRESOLVED(ret, "pthread_equal returned a bad result"); } if (ret == EINTR) { FAILED("pthread_equal returned EINTR status"); } } return NULL; } /* Main function */ int main (int argc, char * argv[]) { int ret; pthread_t th_work, th_sig1, th_sig2, me; thestruct arg1, arg2; struct sigaction sa; /* Initialize output routine */ output_init(); /* We need to register the signal handlers for the PROCESS */ sigemptyset (&sa.sa_mask); sa.sa_flags = 0; sa.sa_handler = sighdl1; if ((ret = sigaction (SIGUSR1, &sa, NULL))) { UNRESOLVED(ret, "Unable to register signal handler1"); } sa.sa_handler = sighdl2; if ((ret = sigaction (SIGUSR2, &sa, NULL))) { UNRESOLVED(ret, "Unable to register signal handler2"); } /* We prepare a signal set which includes SIGUSR1 and SIGUSR2 */ sigemptyset(&usersigs); ret = sigaddset(&usersigs, SIGUSR1); ret |= sigaddset(&usersigs, SIGUSR2); if (ret != 0) { UNRESOLVED(ret, "Unable to add SIGUSR1 or 2 to a signal set"); } /* We now block the signals SIGUSR1 and SIGUSR2 for this THREAD */ ret = pthread_sigmask(SIG_BLOCK, &usersigs, NULL); if (ret != 0) { UNRESOLVED(ret, "Unable to block SIGUSR1 and SIGUSR2 in main thread"); } #ifdef WITH_SYNCHRO if (sem_init(&semsig1, 0, 1)) { UNRESOLVED(errno, "Semsig1 init"); } if (sem_init(&semsig2, 0, 1)) { UNRESOLVED(errno, "Semsig2 init"); } #endif me = pthread_self(); if ((ret = pthread_create(&th_work, NULL, test, (void *)&me))) { UNRESOLVED(ret, "Worker thread creation failed"); } arg1.sig = SIGUSR1; arg2.sig = SIGUSR2; #ifdef WITH_SYNCHRO arg1.sem = &semsig1; arg2.sem = &semsig2; #endif if ((ret = pthread_create(&th_sig1, NULL, sendsig, (void *)&arg1))) { UNRESOLVED(ret, "Signal 1 sender thread creation failed"); } if ((ret = pthread_create(&th_sig2, NULL, sendsig, (void *)&arg2))) { UNRESOLVED(ret, "Signal 2 sender thread creation failed"); } /* Let's wait for a while now */ sleep(1); /* Now stop the threads and join them */ do { do_it=0; } while (do_it); if ((ret = pthread_join(th_sig1, NULL))) { UNRESOLVED(ret, "Signal 1 sender thread join failed"); } if ((ret = pthread_join(th_sig2, NULL))) { UNRESOLVED(ret, "Signal 2 sender thread join failed"); } if ((ret = pthread_join(th_work, NULL))) { UNRESOLVED(ret, "Worker thread join failed"); } #if VERBOSE > 0 output("Test executed successfully.\n"); output(" %d thread comparison.\n", count_ope); #ifdef WITH_SYNCHRO output(" %d signals were sent meanwhile.\n", count_sig); #endif #endif PASSED; } posixtestsuite/conformance/interfaces/pthread_mutexattr_gettype/0040755000000000000000000000000010515625221024615 5ustar rootrootposixtestsuite/conformance/interfaces/pthread_mutexattr_gettype/speculative/0040755000000000000000000000000010515625221027141 5ustar rootrootposixtestsuite/conformance/interfaces/pthread_mutexattr_gettype/speculative/3-1.c0100644000000000000000000000213507663470506027621 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: bing.wei.liu REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_mutexattr_gettype() * * It shall fail if: * * [EINVAL] - The value specified by 'attr' is invalid. * * * Steps: * 1. Initialize a pthread_mutexattr_t object with pthread_mutexattr_init() * 2. Call pthread_mutexattr_gettype() with an invalid 'attr'. * */ #define _XOPEN_SOURCE 600 #include #include #include #include "posixtest.h" #include int main() { pthread_mutexattr_t mta; int type, ret; /* Make 'attr' invalid by not initializing it and using memset. */ memset(&mta, 0, sizeof(mta)); /* Pass an invalid 'attr'. */ ret=pthread_mutexattr_gettype(&mta, &type); if(ret != EINVAL) { printf("Test FAILED: Incorrect return code. Expected EINVAL, but got: %d\n", ret); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_mutexattr_gettype/1-5.c0100644000000000000000000000342407640433051025266 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: bing.wei.liu REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_mutexattr_gettype() * * Gets the mutex 'type' attribute. This attribute is set in the 'type' parameter to * these functions. The default value is PTHREAD_MUTEX_DEFAULT. * * Testing the PTHREAD_MUTEX_RECURSIVE type. * * Steps: * 1. Initialize a pthread_mutexattr_t object with pthread_mutexattr_init() * 2. Set tye mutexattr type to PTHREAD_MUTEX_RECURSIVE * 3. Call pthread_mutexattr_gettype() to check if type * attribute is set as the value PTHREAD_MUTEX_RECURSIVE. * */ #define _XOPEN_SOURCE 600 #include #include #include "posixtest.h" int main() { pthread_mutexattr_t mta; int type; /* Initialize a mutex attributes object */ if(pthread_mutexattr_init(&mta) != 0) { perror("Error at pthread_mutexattr_init()\n"); return PTS_UNRESOLVED; } /* Set the mutex attribute 'type' to PTHREAD_MUTEX_RECURSIVE. */ if(pthread_mutexattr_settype(&mta, PTHREAD_MUTEX_RECURSIVE) != 0) { fprintf(stderr,"pthread_mutexattr_settype(): Error setting the attribute 'type'\n"); return PTS_UNRESOLVED; } /* The 'type' attribute should be PTHREAD_MUTEX_RECURSIVE */ if(pthread_mutexattr_gettype(&mta, &type) != 0) { fprintf(stderr,"pthread_mutexattr_gettype(): Error obtaining the attribute 'type'\n"); return PTS_UNRESOLVED; } if(type != PTHREAD_MUTEX_RECURSIVE) { printf("Test FAILED: Incorrect mutexattr 'type' value: %d. Should be PTHREAD_MUTEX_RECURSIVE\n", type); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_mutexattr_gettype/1-3.c0100644000000000000000000000337407640433051025270 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: bing.wei.liu REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_mutexattr_gettype() * * Gets the mutex 'type' attribute. This attribute is set in the 'type' parameter to * these functions. The default value is PTHREAD_MUTEX_DEFAULT. * * Testing the PTHREAD_MUTEX_NORMAL type. * * Steps: * 1. Initialize a pthread_mutexattr_t object with pthread_mutexattr_init() * 2. Set tye mutexattr type to PTHREAD_MUTEX_NORMAL * 3. Call pthread_mutexattr_gettype() to check if type * attribute is set as the value PTHREAD_MUTEX_NORMAL. * */ #define _XOPEN_SOURCE 600 #include #include #include "posixtest.h" int main() { pthread_mutexattr_t mta; int type; /* Initialize a mutex attributes object */ if(pthread_mutexattr_init(&mta) != 0) { perror("Error at pthread_mutexattr_init()\n"); return PTS_UNRESOLVED; } /* Set the mutex attribute 'type' to PTHREAD_MUTEX_NORMAL. */ if(pthread_mutexattr_settype(&mta, PTHREAD_MUTEX_NORMAL) != 0) { fprintf(stderr,"pthread_mutexattr_settype(): Error setting the attribute 'type'\n"); return PTS_UNRESOLVED; } /* The 'type' attribute should be PTHREAD_MUTEX_NORMAL */ if(pthread_mutexattr_gettype(&mta, &type) != 0) { fprintf(stderr,"pthread_mutexattr_gettype(): Error obtaining the attribute 'type'\n"); return PTS_UNRESOLVED; } if(type != PTHREAD_MUTEX_NORMAL) { printf("Test FAILED: Incorrect mutexattr 'type' value: %d. Should be PTHREAD_MUTEX_NORMAL\n", type); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_mutexattr_gettype/1-1.c0100644000000000000000000000270607640433051025264 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: bing.wei.liu REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_mutexattr_gettype() * * Gets the mutex 'type' attribute. This attribute is set in the 'type' parameter to * these functions. The default value is PTHREAD_MUTEX_DEFAULT. * * Testing the default 'type' value. * * Steps: * 1. Initialize a pthread_mutexattr_t object with pthread_mutexattr_init() * 2. Call pthread_mutexattr_gettype() to check if type * attribute is set as the default value PTHREAD_MUTEX_DEFAULT. * */ #define _XOPEN_SOURCE 600 #include #include #include "posixtest.h" int main() { pthread_mutexattr_t mta; int type; /* Initialize a mutex attributes object */ if(pthread_mutexattr_init(&mta) != 0) { perror("Error at pthread_mutexattr_init()\n"); return PTS_UNRESOLVED; } /* The default 'type' attribute should be PTHREAD_MUTEX_DEFAULT */ if(pthread_mutexattr_gettype(&mta, &type) != 0) { fprintf(stderr,"pthread_mutexattr_gettype(): Error obtaining the attribute 'type'\n"); return PTS_UNRESOLVED; } if(type != PTHREAD_MUTEX_DEFAULT) { printf("Test FAILED: Incorrect default mutexattr 'type' value: %d\n", type); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_mutexattr_gettype/1-2.c0100644000000000000000000000341407640433051025262 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: bing.wei.liu REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_mutexattr_gettype() * * Gets the mutex 'type' attribute. This attribute is set in the 'type' parameter to * these functions. The default value is PTHREAD_MUTEX_DEFAULT. * * Testing the PTHREAD_MUTEX_DEFAULT type. * * Steps: * 1. Initialize a pthread_mutexattr_t object with pthread_mutexattr_init() * 2. Set tye mutexattr type to PTHREAD_MUTEX_DEFAULT * 3. Call pthread_mutexattr_gettype() to check if type * attribute is set as the default value PTHREAD_MUTEX_DEFAULT. * */ #define _XOPEN_SOURCE 600 #include #include #include "posixtest.h" int main() { pthread_mutexattr_t mta; int type; /* Initialize a mutex attributes object */ if(pthread_mutexattr_init(&mta) != 0) { perror("Error at pthread_mutexattr_init()\n"); return PTS_UNRESOLVED; } /* Set the mutex attribute 'type' to PTHREAD_MUTEX_DEFAULT. */ if(pthread_mutexattr_settype(&mta, PTHREAD_MUTEX_DEFAULT) != 0) { fprintf(stderr,"pthread_mutexattr_settype(): Error setting the attribute 'type'\n"); return PTS_UNRESOLVED; } /* The 'type' attribute should be PTHREAD_MUTEX_DEFAULT */ if(pthread_mutexattr_gettype(&mta, &type) != 0) { fprintf(stderr,"pthread_mutexattr_gettype(): Error obtaining the attribute 'type'\n"); return PTS_UNRESOLVED; } if(type != PTHREAD_MUTEX_DEFAULT) { printf("Test FAILED: Incorrect mutexattr 'type' value: %d. Should be PTHREAD_MUTEX_DEFAULT\n", type); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_mutexattr_gettype/assertions.xml0100644000000000000000000000126107640215326027534 0ustar rootroot The function int pthread_mutexattr_gettype(const pthread_mutexattr_t *attr, int *restrict type); Gets the mutex 'type' attribute. This attribute is set in the 'type' parameter to these functions. The default value is PTHREAD_MUTEX_DEFAULT. It returns 0 upon success and stores the value of the type of the attribute object 'attr' into the reference of the 'type' parameter. It shall fail if: [EINVAL] - The value specified by 'attr' is invalid. posixtestsuite/conformance/interfaces/pthread_mutexattr_gettype/2.sh0100755000000000000000000000110507640463067025324 0ustar rootroot#!/bin/sh # Copyright (c) 2002, Intel Corporation. All rights reserved. # Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com # This file is licensed under the GPL license. For the full content # of this license, see the COPYING file at the top level of this # source tree. # Test pthread_mutexattr_gettype() # It returns 0 upon success and stores the value of the type of the attribute object 'attr' # into the reference of the 'type' parameter. # This is tested implicitly via assertion 1. echo "Tested implicitly via assertion 1. See output for status" exit 0 posixtestsuite/conformance/interfaces/pthread_mutexattr_gettype/coverage.txt0100644000000000000000000000017607640433051027155 0ustar rootrootThis document defines the coverage for the pthread_mutexattr_gettype function: Assertion Tested? 1 YES 2 YES 3 YES NOTE: posixtestsuite/conformance/interfaces/pthread_mutexattr_gettype/1-4.c0100644000000000000000000000343407640433051025266 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: bing.wei.liu REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_mutexattr_gettype() * * Gets the mutex 'type' attribute. This attribute is set in the 'type' parameter to * these functions. The default value is PTHREAD_MUTEX_DEFAULT. * * Testing the PTHREAD_MUTEX_ERRORCHECK type. * * Steps: * 1. Initialize a pthread_mutexattr_t object with pthread_mutexattr_init() * 2. Set tye mutexattr type to PTHREAD_MUTEX_ERRORCHECK * 3. Call pthread_mutexattr_gettype() to check if type * attribute is set as the value PTHREAD_MUTEX_ERRORCHECK. * */ #define _XOPEN_SOURCE 600 #include #include #include "posixtest.h" int main() { pthread_mutexattr_t mta; int type; /* Initialize a mutex attributes object */ if(pthread_mutexattr_init(&mta) != 0) { perror("Error at pthread_mutexattr_init()\n"); return PTS_UNRESOLVED; } /* Set the mutex attribute 'type' to PTHREAD_MUTEX_ERRORCHECK. */ if(pthread_mutexattr_settype(&mta, PTHREAD_MUTEX_ERRORCHECK) != 0) { fprintf(stderr,"pthread_mutexattr_settype(): Error setting the attribute 'type'\n"); return PTS_UNRESOLVED; } /* The 'type' attribute should be PTHREAD_MUTEX_ERRORCHECK */ if(pthread_mutexattr_gettype(&mta, &type) != 0) { fprintf(stderr,"pthread_mutexattr_gettype(): Error obtaining the attribute 'type'\n"); return PTS_UNRESOLVED; } if(type != PTHREAD_MUTEX_ERRORCHECK) { printf("Test FAILED: Incorrect mutexattr 'type' value: %d. Should be PTHREAD_MUTEX_ERRORCHECK\n", type); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_attr_setinheritsched/0040755000000000000000000000000010515625177025250 5ustar rootrootposixtestsuite/conformance/interfaces/pthread_attr_setinheritsched/2-4.c0100644000000000000000000000464210067765235025723 0ustar rootroot/* * Copyright (c) 2004, QUALCOMM Inc. All rights reserved. * Created by: abisain REMOVE-THIS AT qualcomm DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_attr_setinheritsched() sets the inheritance of * policy and priority. * Steps: * 1. Create a pthread_attr struct using pthread_attr_init * 2. Change main's priority and policy * 3. Set the inherit sched in it by calling pthread_attr_setinheritsched * 4. Create a new thread. * 5. Check that it has correct priority and policy */ #include #include #include #include "posixtest.h" #define TEST "4-2" #define AREA "scheduler" #define ERROR_PREFIX "unexpected error: " AREA " " TEST ": " #define PRIORITY 20 #define POLICY SCHED_RR /* Flags that the threads use to indicate events */ int policy_correct = -1; int priority_correct = -1; void *thread(void *tmp) { struct sched_param param; int policy; int rc = 0; rc = pthread_getschedparam(pthread_self(), &policy, ¶m); if(rc != 0) { printf(ERROR_PREFIX "pthread_getschedparam\n"); exit(PTS_UNRESOLVED); } if(policy == POLICY) { policy_correct = 1; } if(param.sched_priority == PRIORITY) { priority_correct = 1; } return NULL; } int main() { pthread_attr_t attr; pthread_t thread_id; struct sched_param param; int rc = 0; param.sched_priority = PRIORITY; rc = pthread_setschedparam(pthread_self(), POLICY, ¶m); if(rc != 0) { printf(ERROR_PREFIX "pthread_setschedparam\n"); exit(PTS_UNRESOLVED); } rc = pthread_attr_init(&attr); if(rc != 0) { printf(ERROR_PREFIX "pthread_attr_init\n"); exit(PTS_UNRESOLVED); } rc = pthread_attr_setinheritsched(&attr, PTHREAD_INHERIT_SCHED); if(rc != 0) { printf(ERROR_PREFIX "pthread_attr_setinheritsched\n"); printf("Test FAILED\n"); exit(PTS_FAIL); } rc = pthread_create(&thread_id, &attr, thread, NULL); if(rc != 0) { printf(ERROR_PREFIX "pthread_create\n"); exit(PTS_UNRESOLVED); } rc = pthread_join(thread_id, NULL); if(rc != 0) { printf(ERROR_PREFIX "pthread_join\n"); exit(PTS_UNRESOLVED); } if((priority_correct != 1) || (policy_correct != 1)) { printf("Test FAIL\n"); exit(PTS_FAIL); } printf("Test PASS\n"); exit(PTS_PASS); } posixtestsuite/conformance/interfaces/pthread_attr_setinheritsched/2-2.c0100644000000000000000000000617010044430567025707 0ustar rootroot/* * Copyright (c) 2004, Intel Corporation. All rights reserved. * Created by: crystal.xiong REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test pthread_attr_setinheritsched() * * Steps: * 1. Initialize pthread_attr_t object (attr) * 2. Set schedule policy (policy) in attr to SCHED_FIFO * 3. Set inheritsched to PTHREAD_EXPLICIT_SCHED in attr * 4. Call pthread_create with attr * 5. Call pthread_getschedparam in the created thread and get the * policy value(new_policy) * 6. Compare new_policy with SCHED_OTHER. SCHED_OTHER is the * default policy value in the creating thread. if new_policy is * equal to SCHED_OTHER, the case fails. * * - adam.li@intel.com: 2004-04-30 * add code pthread_attr_setschedparam(). Otherwise pthread_create() * will fail with EINVAL. And, the perror() thing is not correct. */ #include #include #include #include #include #include "posixtest.h" #define TEST "2-2" #define FUNCTION "pthread_attr_setinheritsched" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " const long int policy = SCHED_FIFO; const long int old_policy = SCHED_OTHER; void *thread_func(void* arg) { int rc; int new_policy; pthread_t self = pthread_self(); struct sched_param param; memset(¶m, 0, sizeof(param)); rc = pthread_getschedparam(self, &new_policy, ¶m); if (rc != 0 ) { perror(ERROR_PREFIX "pthread_getschedparam"); exit(PTS_UNRESOLVED); } if (new_policy == old_policy) { fprintf(stderr, ERROR_PREFIX "The scheduling attribute should " "not be inherited from creating thread \n"); exit(PTS_FAIL); } pthread_exit(0); return NULL; } int main() { pthread_t new_th; pthread_attr_t attr; int rc; struct sched_param sp; /* Initialize attr */ rc = pthread_attr_init(&attr); if( rc != 0) { printf(ERROR_PREFIX "pthread_attr_init"); exit(PTS_UNRESOLVED); } rc = pthread_attr_setschedpolicy(&attr, policy); if (rc != 0 ) { printf(ERROR_PREFIX "pthread_attr_setschedpolicy"); exit(PTS_UNRESOLVED); } sp.sched_priority = 1; rc = pthread_attr_setschedparam(&attr, &sp); if (rc != 0 ) { printf(ERROR_PREFIX "pthread_attr_setschedparam"); exit(PTS_UNRESOLVED); } int insched = PTHREAD_EXPLICIT_SCHED; rc = pthread_attr_setinheritsched(&attr, insched); if (rc != 0 ) { printf(ERROR_PREFIX "pthread_attr_setinheritsched"); exit(PTS_UNRESOLVED); } rc = pthread_create(&new_th, &attr, thread_func, NULL); if (rc !=0 ) { printf("Error at pthread_create(): %s\n", strerror(rc)); exit(PTS_UNRESOLVED); } rc = pthread_join(new_th, NULL); if(rc != 0) { printf(ERROR_PREFIX "pthread_join"); exit(PTS_UNRESOLVED); } rc = pthread_attr_destroy(&attr); if(rc != 0) { printf(ERROR_PREFIX "pthread_attr_destroy"); exit(PTS_UNRESOLVED); } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_attr_setinheritsched/4-1.c0100644000000000000000000000241110025741545025702 0ustar rootroot/* * Copyright (c) 2004, Intel Corporation. All rights reserved. * Created by: crystal.xiong REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test pthread_attr_setinheritsched() * * Steps: * 1. Initialize a pthread_attr_t object using pthread_attr_init() * 2. Call pthread_attr_setinheritsched with unsupported inheritsched * parameter * */ #include #include #include #include #include "posixtest.h" #define TEST "4-1" #define FUNCTION "pthread_attr_setinheritsched" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " #define INVALIDSCHED 999 int main() { int rc=0; pthread_attr_t attr; rc = pthread_attr_init(&attr); if (rc != 0) { perror(ERROR_PREFIX "pthread_attr_init"); exit(PTS_UNRESOLVED); } rc = pthread_attr_setinheritsched(&attr, INVALIDSCHED); if ((rc != EINVAL)) { perror(ERROR_PREFIX "pthread_attr_setinheritsched"); exit(PTS_FAIL); } rc = pthread_attr_destroy(&attr); if( rc != 0) { perror(ERROR_PREFIX "pthread_attr_destroy"); exit(PTS_UNRESOLVED); } printf("Test PASS\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_attr_setinheritsched/3-1.sh0100755000000000000000000000071710025741545026103 0ustar rootroot #!/bin/sh # Copyright (c) 2004, Intel Corporation. All rights reserved. # Created by: crystal.xiong REMOVE-THIS AT intel DOT com # This file is licensed under the GPL license. For the full content # of this license, see the COPYING file at the top level of this # source tree. # Test pthread_attr_setinheritsched returns 0 on success. # This is tested implicitly via assertion 1. echo "Tested implicitly via assertion 1. See output for status" exit 0 posixtestsuite/conformance/interfaces/pthread_attr_setinheritsched/1-1.c0100644000000000000000000000426010025741545025703 0ustar rootroot/* * Copyright (c) 2004, Intel Corporation. All rights reserved. * Created by: crystal.xiong REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test pthread_attr_setinheritsched() * * Steps: * 1. Initialize a pthread_attr_t object using pthread_attr_init() * 2. Call pthread_attr_setinheritsched with inheritsched parameter * 3. Call pthread_attr_getinheritsched to get the inheritsched * */ #include #include #include #include "posixtest.h" #define TEST "1-1" #define FUNCTION "pthread_attr_setinheritsched" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " #define EXPLICIT PTHREAD_EXPLICIT_SCHED #define INHERIT PTHREAD_INHERIT_SCHED int verify_inheritsched(pthread_attr_t *attr, int schedtype) { int rc; int inheritsched; rc = pthread_attr_getinheritsched(attr, &inheritsched); if( rc != 0) { perror(ERROR_PREFIX "pthread_attr_getinheritsched"); exit(PTS_UNRESOLVED); } switch(schedtype) { case INHERIT: if (inheritsched != INHERIT) { perror(ERROR_PREFIX "got wrong inheritsched param"); exit(PTS_FAIL); } break; case EXPLICIT: if (inheritsched != EXPLICIT) { perror(ERROR_PREFIX "got wrong inheritsched param"); exit(PTS_FAIL); } break; } return 0; } int main() { int rc=0; pthread_attr_t attr; rc = pthread_attr_init(&attr); if( rc != 0) { perror(ERROR_PREFIX "pthread_attr_init"); exit(PTS_UNRESOLVED); } rc = pthread_attr_setinheritsched(&attr, INHERIT); if( rc != 0) { perror(ERROR_PREFIX "pthread_attr_setinheritsched"); exit(PTS_UNRESOLVED); } verify_inheritsched(&attr, INHERIT); rc = pthread_attr_setinheritsched(&attr, EXPLICIT); if( rc != 0) { perror(ERROR_PREFIX "pthread_attr_setinheritsched"); exit(PTS_UNRESOLVED); } verify_inheritsched(&attr, EXPLICIT); rc = pthread_attr_destroy(&attr); if( rc != 0) { perror(ERROR_PREFIX "pthread_attr_destroy"); exit(PTS_UNRESOLVED); } printf("Test PASS\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_attr_setinheritsched/assertions.xml0100644000000000000000000000263710025741545030163 0ustar rootroot pthread_attr_setinheritsched shall set the inheritsched attribute in the attr argument. When pthread_create uses the attributes objects, the inheritsched attribute determines how the other scheduling attributes of the created thread shall be set. PTHREAD_INHERIT_SCHED specifies that the thread scheduling attributes shall be inherited from the creating thread, and the scheduling attributes in this attr argument shall be ignored. PTHREAD_EXPLICIT_SCHED specifies that the thread scheduling attributes shall be set to the corresponding values from this attributes object. The schedpolicy, schedparam, cotentionscope are affected by the inherisched attribute. If successful, pthread_attr_setinheritsched functions return zero. If fail, an error number shall be returned to indicate the error. [EINVAL] The value of inheritsched is not valid. If fail, an error number shall be returned to indicate the error. [ENOTSUP] An attempt was made to set the attribute to an unsupported value. Shall not return an error code of [EINTR] posixtestsuite/conformance/interfaces/pthread_attr_setinheritsched/coverage.txt0100644000000000000000000000031410044433023027557 0ustar rootrootThis document defines the coverage for the pthread_attr_setinheritsched function: Assertion Tested? 1 YES 2 YES 3 YES 4 YES 5 NO Incorrect test -- What's the unsupported value? 6 Won't test NOTE: posixtestsuite/conformance/interfaces/pthread_attr_setinheritsched/2-3.c0100644000000000000000000000456610067765235025727 0ustar rootroot/* * Copyright (c) 2004, QUALCOMM Inc. All rights reserved. * Created by: abisain REMOVE-THIS AT qualcomm DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_attr_setinheritsched() sets the inheritance of * policy and priority. * Steps: * 1. Create a pthread_attr struct using pthread_attr_init * 2. Set the inherit sched in it by calling pthread_attr_setinheritsched * 3. Change main's priority and policy * 4. Create a new thread. * 5. Check that it has correct priority and policy */ #include #include #include #include "posixtest.h" #define TEST "4-1" #define AREA "scheduler" #define ERROR_PREFIX "unexpected error: " AREA " " TEST ": " #define PRIORITY 20 #define POLICY SCHED_FIFO /* Flags that the threads use to indicate events */ int policy_correct = -1; int priority_correct = -1; void *thread(void *tmp) { struct sched_param param; int policy; int rc = 0; rc = pthread_getschedparam(pthread_self(), &policy, ¶m); if(rc != 0) { printf(ERROR_PREFIX "pthread_getschedparam\n"); exit(PTS_UNRESOLVED); } if(policy == POLICY) { policy_correct = 1; } if(param.sched_priority == PRIORITY) { priority_correct = 1; } return NULL; } int main() { pthread_attr_t attr; pthread_t thread_id; struct sched_param param; int rc = 0; param.sched_priority = PRIORITY; rc = pthread_attr_init(&attr); if(rc != 0) { printf(ERROR_PREFIX "pthread_attr_init\n"); exit(PTS_UNRESOLVED); } rc = pthread_attr_setinheritsched(&attr, PTHREAD_INHERIT_SCHED); if(rc != 0) { printf(ERROR_PREFIX "pthread_attr_setinheritsched\n"); exit(PTS_UNRESOLVED); } rc = pthread_setschedparam(pthread_self(), POLICY, ¶m); if(rc != 0) { printf(ERROR_PREFIX "pthread_setschedparam\n"); exit(PTS_UNRESOLVED); } rc = pthread_create(&thread_id, &attr, thread, NULL); if(rc != 0) { printf(ERROR_PREFIX "pthread_create\n"); exit(PTS_UNRESOLVED); } rc = pthread_join(thread_id, NULL); if(rc != 0) { printf(ERROR_PREFIX "pthread_join\n"); exit(PTS_UNRESOLVED); } if((priority_correct != 1) || (policy_correct != 1)) { printf("Test FAILED\n"); exit(PTS_FAIL); } printf("Test PASS\n"); exit(PTS_PASS); } posixtestsuite/conformance/interfaces/pthread_attr_setinheritsched/2-1.c0100644000000000000000000000522310025741545025704 0ustar rootroot/* * Copyright (c) 2004, Intel Corporation. All rights reserved. * Created by: crystal.xiong REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test pthread_attr_setinheritsched() * * Steps: * 1. Initialize pthread_attr_t object (attr) * 2. Set schedule policy (policy) in attr to SCHED_FIFO * 3. Set inheritsched to PTHREAD_INHERIT_SCHED in attr * 4. Call pthread_create with attr * 5. Call pthread_getschedparam in the created thread and get the * policy value(new_policy) * 6. Compare new_policy with SCHED_OTHER. SCHED_OTHER is the * default policy value in the creating thread. if new_policy is * equal to SCHED_OTHER, the case pass. */ #include #include #include #include #include "posixtest.h" #define TEST "2-1" #define FUNCTION "pthread_attr_setinheritsched" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " const long int policy = SCHED_FIFO; void *thread_func() { int rc; int new_policy; pthread_t self = pthread_self(); struct sched_param param; memset(¶m, 0, sizeof(param)); rc = pthread_getschedparam(self, &new_policy, ¶m); if (rc != 0 ) { perror(ERROR_PREFIX "pthread_getschedparam"); exit(PTS_UNRESOLVED); } if (new_policy == policy) { fprintf(stderr, ERROR_PREFIX "The scheduling attribute is not " "inherited from creating thread \n"); exit(PTS_FAIL); } pthread_exit(0); return NULL; } int main() { pthread_t new_th; pthread_attr_t attr; int rc; /* Initialize attr */ rc = pthread_attr_init(&attr); if( rc != 0) { perror(ERROR_PREFIX "pthread_attr_init"); exit(PTS_UNRESOLVED); } rc = pthread_attr_setschedpolicy(&attr, policy); if (rc != 0 ) { perror(ERROR_PREFIX "pthread_attr_setschedpolicy"); exit(PTS_UNRESOLVED); } int insched = PTHREAD_INHERIT_SCHED; rc = pthread_attr_setinheritsched(&attr, insched); if (rc != 0 ) { perror(ERROR_PREFIX "pthread_attr_setinheritsched"); exit(PTS_UNRESOLVED); } rc = pthread_create(&new_th, &attr, thread_func, NULL); if (rc !=0 ) { perror(ERROR_PREFIX "pthread_create"); exit(PTS_UNRESOLVED); } rc = pthread_join(new_th, NULL); if(rc != 0) { perror(ERROR_PREFIX "pthread_join"); exit(PTS_UNRESOLVED); } rc = pthread_attr_destroy(&attr); if(rc != 0) { perror(ERROR_PREFIX "pthread_attr_destroy"); exit(PTS_UNRESOLVED); } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_barrierattr_getpshared/0040755000000000000000000000000010515625201025544 5ustar rootrootposixtestsuite/conformance/interfaces/pthread_barrierattr_getpshared/3-1.sh0100755000000000000000000000074107705320324026407 0ustar rootroot#!/bin/sh # Copyright (c) 2002, Intel Corporation. All rights reserved. # This file is licensed under the GPL license. For the full content # of this license, see the COPYING file at the top level of this # source tree. # Upon successful completion, these functions shall return zero; # otherwise, an error number shall be returned to indicate the error. # This is tested implicitly via assertion 1. echo "Tested implicitly via assertion 1. See output for status" exit 0 posixtestsuite/conformance/interfaces/pthread_barrierattr_getpshared/1-1.c0100644000000000000000000000265207705320324026215 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * * pthread_barrierattr_getpshared() * * The pthread_barrierattr_getpshared( ) function shall obtain the value of * the process-shared attribute from the attributes object referenced by attr. * */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include #include "posixtest.h" int main() { int rc; pthread_barrierattr_t ba; int pshared; /* Initialize the barrier attribute object */ rc = pthread_barrierattr_init(&ba); if(rc != 0) { printf("Error while initialize attribute object\n"); return PTS_UNRESOLVED; } /* Get pshared */ if(pthread_barrierattr_getpshared(&ba, &pshared) != 0) { printf("Error at pthread_barrierattr_getpshared()\n"); return PTS_FAIL; } if(pshared != PTHREAD_PROCESS_PRIVATE) { printf("The process shared attribute was not set to " "default value of PTHREAD_PROCESS_PRIVATE\n"); return PTS_UNRESOLVED; } /* Cleanup */ rc = pthread_barrierattr_destroy(&ba); if(rc != 0) { printf("Error at pthread_barrierattr_destroy() " "return code: %d, %s", rc, strerror(rc)); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_barrierattr_getpshared/assertions.xml0100644000000000000000000000272507705320324030470 0ustar rootroot The pthread_barrierattr_getpshared( ) function shall obtain the value of the process-shared attribute from the attributes object referenced by attr. The process-shared attribute is set to PTHREAD_PROCESS_SHARED to permit a barrier to be operated upon by any thread that has access to the memory where the barrier is allocated. If the process-shared attribute is PTHREAD_PROCESS_PRIVATE, the barrier shall only be operated upon by threads created within the same process as the thread that initialized the barrier; if threads of different processes attempt to operate on such a barrier, the behavior is undefined. The default value of the attribute shall be PTHREAD_PROCESS_PRIVATE. Both constants PTHREAD_PROCESS_SHARED and PTHREAD_PROCESS_PRIVATE are defined in "pthread.h". If successful, the pthread_barrierattr_getpshared( ) function shall return zero and store the value of the process-shared attribute of attr into the object referenced by the pshared parameter. Otherwise, an error number shall be returned to indicate the error. These functions may fail if: [EINVAL] The value specified by attr is invalid. These functions shall not return an error code of EINTR. posixtestsuite/conformance/interfaces/pthread_barrierattr_getpshared/coverage.txt0100644000000000000000000000021407705320324030077 0ustar rootrootThis document defines the coverage for the pthread_barrierattr_destroy() function: Assertion Tested? 1 YES 2 YES 3 YES 4 NO NOTE: posixtestsuite/conformance/interfaces/pthread_barrierattr_getpshared/2-1.c0100644000000000000000000001354310220477627026224 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * * The idea of this case comes from GNU C library NPTL test tst-barrier2.c. * * The process-shared attribute is set to PTHREAD_PROCESS_SHARED to permit * a barrier to be operated upon by any thread that has access to the memory * where the barrier is allocated. If the process-shared attribute * is PTHREAD_PROCESS_PRIVATE, the barrier shall only be operated * upon by threads created within the same process as the thread * that initialized the barrier; if threads of different processes attempt * to operate on such a barrier, the behavior is undefined. * The default value of the attribute shall be PTHREAD_PROCESS_PRIVATE. Both constants * PTHREAD_PROCESS_SHARED and PTHREAD_PROCESS_PRIVATE are defined in . * * steps: * 1. Create a piece of shared memory object, create pthread barrier object 'barrier' * and set the PTHREAD_PROCESS_SHARED attribute. * 2. Parent map the shared memory to its memory space, put 'barrier' into it; * 3. Parent fork to create child process; * 4. Child process map the 'barrier' to its memory space; * 5. Parent and Child execute same code: loop N times, calling pthread_barrier_wait() * 6. Parent and Child should not block on pthread_barrier_wait() */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include #include #include #include #include "posixtest.h" #define LOOP_NUM 10 void sig_handler() { printf("Interrupted by SIGALRM\n"); printf("Test Fail: block on pthread_barrier_wait()\n"); exit(PTS_FAIL); } int main() { /* Make sure there is process-shared capability. */ #ifndef PTHREAD_PROCESS_SHARED fprintf(stderr,"process-shared attribute is not available for testing\n"); return PTS_UNSUPPORTED; #endif static pthread_barrier_t* barrier; pthread_barrierattr_t ba; int pshared = PTHREAD_PROCESS_SHARED; char shm_name[] = "tmp_pthread_barrierattr_getpshared"; int shm_fd; int pid; int loop; int serial = 0; int rc; int status = 0; struct sigaction act; /* Set up parent to handle SIGALRM */ act.sa_flags = 0; act.sa_handler = sig_handler; sigfillset(&act.sa_mask); sigaction(SIGALRM, &act, 0); /* Initialize a barrier attributes object */ if(pthread_barrierattr_init(&ba) != 0) { printf("Error at pthread_barrierattr_init()\n"); return PTS_UNRESOLVED; } /* Set the pshard value to private to shared */ if(pthread_barrierattr_setpshared(&ba, pshared) != 0) { printf("Error at pthread_barrierattr_setpshared()\n"); return PTS_UNRESOLVED; } if(pthread_barrierattr_getpshared(&ba, &pshared) != 0) { printf("Test FAILED: Error at pthread_barrierattr_getpshared()\n"); return PTS_FAIL; } if(pshared != PTHREAD_PROCESS_SHARED) { printf("Test FAILED: Incorrect pshared value %d\n", pshared); return PTS_FAIL; } /* Create shared object */ shm_unlink(shm_name); shm_fd = shm_open(shm_name, O_RDWR|O_CREAT|O_EXCL, S_IRUSR|S_IWUSR); if(shm_fd == -1) { perror("Error at shm_open()"); return PTS_UNRESOLVED; } if(ftruncate(shm_fd, sizeof(pthread_barrier_t)) != 0) { perror("Error at ftruncate()"); shm_unlink(shm_name); return PTS_UNRESOLVED; } /* Map the shared memory object to my memory */ barrier = mmap(NULL, sizeof(pthread_barrier_t), PROT_READ|PROT_WRITE, MAP_SHARED, shm_fd, 0); if(barrier == MAP_FAILED) { perror("Error at first mmap()"); shm_unlink(shm_name); return PTS_UNRESOLVED; } /* Initialize a barrier */ if((pthread_barrier_init(barrier, &ba, 2)) != 0) { printf("Error at pthread_barrier_init()\n"); return PTS_UNRESOLVED; } /* Cleanup */ if((pthread_barrierattr_destroy(&ba)) != 0) { printf("Error at pthread_barrierattr_destroy()\n"); return PTS_UNRESOLVED; } /* Fork a child process */ pid = fork(); if(pid == -1) { perror("Error at fork()"); return PTS_UNRESOLVED; } else if(pid == 0) { /* Child */ /* Map the shared object to child's memory */ barrier = mmap(NULL, sizeof(pthread_barrier_t), PROT_READ|PROT_WRITE, MAP_SHARED, shm_fd, 0); if(barrier == MAP_FAILED) { perror("child: Error at first mmap()"); return PTS_UNRESOLVED; } } else { printf("parent pid : %d, child pid : %d\n", getpid(), pid); printf("parent: send me SIGALRM 2 secs later in case I am blocked\n"); alarm(2); } for(loop = 0; loop < LOOP_NUM; loop++) { rc = pthread_barrier_wait(barrier); if(rc != 0 && rc != PTHREAD_BARRIER_SERIAL_THREAD) { printf("Test FAILED: %d: pthread_barrier_wait() got unexpected " "return code : %d\n" , getpid(), rc); exit(PTS_FAIL); } else if(rc == PTHREAD_BARRIER_SERIAL_THREAD) { serial++; printf("process %d: get PTHREAD_BARRIER_SERIAL_THREAD\n" , getpid()); } } if(pid > 0) { /* parent */ if( wait(&status) != pid) { printf("parent: error at waitpid()\n"); return PTS_UNRESOLVED; } if(!WIFEXITED(status)) { printf("Child exited abnormally\n"); return PTS_UNRESOLVED; } if((WEXITSTATUS(status) + serial) != LOOP_NUM) { printf("status = %d\n", status); printf("serial = %d\n", serial); printf("Test FAILED: One of the two processes should get " "PTHREAD_BARRIER_SERIAL_THREAD\n"); return PTS_FAIL; } /* Cleanup */ if(pthread_barrier_destroy(barrier) != 0) { printf("Error at pthread_barrier_destroy()"); return PTS_UNRESOLVED; } if((shm_unlink(shm_name)) != 0) { perror("Error at shm_unlink()"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } if(pid == 0) { exit(serial); } } posixtestsuite/conformance/interfaces/pthread_exit/0040755000000000000000000000000010515625214021772 5ustar rootrootposixtestsuite/conformance/interfaces/pthread_exit/2-2.c0100644000000000000000000001402510124544413022432 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertion: * * Pending cancelation cleanup handlers are executed in FILO order. * The steps are: * * -> Create threads with different attributes (but all must be joinable) * -> inside the thread, * -> register three cancelation handlers * -> call pthread_exit. * -> In the main thread, we join the thread and check the cleanups were executed in order. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /* Some routines are part of the XSI Extensions */ #ifndef WITHOUT_XOPEN #define _XOPEN_SOURCE 600 #endif /********************************************************************************************/ /****************************** standard includes *****************************************/ /********************************************************************************************/ #include #include #include #include #include #include #include #include #include #include /********************************************************************************************/ /****************************** Test framework *****************************************/ /********************************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /********************************************************************************************/ /********************************** Configuration ******************************************/ /********************************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif /********************************************************************************************/ /*********************************** Test cases *****************************************/ /********************************************************************************************/ #include "threads_scenarii.c" /* This file will define the following objects: * scenarii: array of struct __scenario type. * NSCENAR : macro giving the total # of scenarii * scenar_init(): function to call before use the scenarii array. * scenar_fini(): function to call after end of use of the scenarii array. */ /********************************************************************************************/ /*********************************** Real Test *****************************************/ /********************************************************************************************/ int global=0; int tab[3]; #define CLEANUP(n) void clnp##n(void * arg)\ {\ tab[global]=n; \ global++; \ } CLEANUP(1) CLEANUP(2) CLEANUP(3) void * threaded (void * arg) { pthread_cleanup_push(clnp3, NULL); pthread_cleanup_push(clnp2, NULL); pthread_cleanup_push(clnp1, NULL); pthread_exit(NULL + 1); pthread_cleanup_pop(0); pthread_cleanup_pop(0); pthread_cleanup_pop(0); FAILED("pthread_exit() did not terminate the thread"); return NULL; } int main (int argc, char *argv[]) { int ret=0; void * rval; pthread_t child; int i,j; output_init(); scenar_init(); for (i=0; i < NSCENAR; i++) { if (scenarii[i].detached == 0) { #if VERBOSE > 0 output("-----\n"); output("Starting test with scenario (%i): %s\n", i, scenarii[i].descr); #endif for (j=0; j<3; j++) tab[j]=0; global=0; ret = pthread_create(&child, &scenarii[i].ta, threaded, NULL); switch (scenarii[i].result) { case 0: /* Operation was expected to succeed */ if (ret != 0) { UNRESOLVED(ret, "Failed to create this thread"); } break; case 1: /* Operation was expected to fail */ if (ret == 0) { UNRESOLVED(-1, "An error was expected but the thread creation succeeded"); } break; case 2: /* We did not know the expected result */ default: #if VERBOSE > 0 if (ret == 0) { output("Thread has been created successfully for this scenario\n"); } else { output("Thread creation failed with the error: %s\n", strerror(ret)); } #endif } if (ret == 0) /* The new thread is running */ { ret = pthread_join(child, &rval); if (ret != 0) { UNRESOLVED(ret, "Unable to join a thread"); } if (rval != (NULL+1)) { FAILED("pthread_join() did not retrieve the pthread_exit() param"); } for (j=0; j<3; j++) if (tab[j] != j+1) { output("dump:\ntab[0]=%i\ntab[1]=%i\ntab[2]=%i\n", tab[0], tab[1], tab[2]); FAILED("The cleanup handlers were not called as expected"); } } } } scenar_fini(); #if VERBOSE > 0 output("-----\n"); output("All test data destroyed\n"); output("Test PASSED\n"); #endif PASSED; } posixtestsuite/conformance/interfaces/pthread_exit/6-2.c0100644000000000000000000001030110124544413022427 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertion: * * The pthread_exit() routine never returns to its caller * The steps are: * * -> create some threads with different attributes * -> in the thread call pthread_exit * -> if the function returns, the test fails. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /* Some routines are part of the XSI Extensions */ #ifndef WITHOUT_XOPEN #define _XOPEN_SOURCE 600 #endif /********************************************************************************************/ /****************************** standard includes *****************************************/ /********************************************************************************************/ #include #include #include #include #include #include #include #include #include #include /********************************************************************************************/ /****************************** Test framework *****************************************/ /********************************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /********************************************************************************************/ /********************************** Configuration ******************************************/ /********************************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif /********************************************************************************************/ /*********************************** Test cases *****************************************/ /********************************************************************************************/ /* main is defined in the next file */ #define STD_MAIN #include "threads_scenarii.c" /* This file will define the following objects: * scenarii: array of struct __scenario type. * NSCENAR : macro giving the total # of scenarii * scenar_init(): function to call before use the scenarii array. * scenar_fini(): function to call after end of use of the scenarii array. */ /********************************************************************************************/ /*********************************** Real Test *****************************************/ /********************************************************************************************/ /* Thread routine */ void * threaded (void * arg) { int ret = 0; /* Signal we're done (especially in case of a detached thread) */ do { ret = sem_post(&scenarii[sc].sem); } while ((ret == -1) && (errno == EINTR)); if (ret == -1) { UNRESOLVED(errno, "Failed to wait for the semaphore"); } pthread_exit(arg); FAILED("pthread_exit() returned"); /* Compiler complaisance */ return NULL; } posixtestsuite/conformance/interfaces/pthread_exit/5-1.c0100644000000000000000000001475310124544413022444 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertion: * * When a thread other than the first thread of a process returns, * an implicit call to pthread_exit() is made with the returned value * as a parameter. * The steps are: * * Same test as 1-2, 3-2, 4-1, but with return in place of pthread_exit. * The results shall be the same. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /* Some routines are part of the XSI Extensions */ #ifndef WITHOUT_XOPEN #define _XOPEN_SOURCE 600 #endif /********************************************************************************************/ /****************************** standard includes *****************************************/ /********************************************************************************************/ #include #include #include #include #include #include #include #include #include #include /********************************************************************************************/ /****************************** Test framework *****************************************/ /********************************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /********************************************************************************************/ /********************************** Configuration ******************************************/ /********************************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif /********************************************************************************************/ /*********************************** Test cases *****************************************/ /********************************************************************************************/ #include "threads_scenarii.c" /* This file will define the following objects: * scenarii: array of struct __scenario type. * NSCENAR : macro giving the total # of scenarii * scenar_init(): function to call before use the scenarii array. * scenar_fini(): function to call after end of use of the scenarii array. */ /********************************************************************************************/ /*********************************** Real Test *****************************************/ /********************************************************************************************/ int atctl=0; pthread_key_t tld[3]; /* atexit() routines */ void at1(void) { atctl+=1; } void at2(void) { atctl+=2; } /* TLD destructor */ void destructor(void * arg) { *(int *) arg += 1; } /* Thread routine */ void * threaded (void * arg) { int ret = 0; ret = atexit(at2); if (ret != 0) { UNRESOLVED(ret, "Failed to register an atexit() routine"); } ret = pthread_setspecific(tld[0], arg); if (ret != 0) { UNRESOLVED(ret, "Failed to set TLD data"); } ret = pthread_setspecific(tld[1], arg); if (ret != 0) { UNRESOLVED(ret, "Failed to set TLD data"); } ret = pthread_setspecific(tld[2], arg); if (ret != 0) { UNRESOLVED(ret, "Failed to set TLD data"); } return NULL + 1; FAILED("return did not terminate the thread (oO)"); return NULL; } /* Main routine */ int main (int argc, char *argv[]) { int ret=0; int ctl=0; void * rval; pthread_t child; int i,j; output_init(); scenar_init(); for (j=0; j<3; j++) { ret = pthread_key_create(&tld[j], destructor); if (ret != 0) { UNRESOLVED(ret, "Failed to create a TLD key"); } } for (i=0; i < NSCENAR; i++) { if (scenarii[i].detached == 0) { #if VERBOSE > 0 output("-----\n"); output("Starting test with scenario (%i): %s\n", i, scenarii[i].descr); #endif ctl=0; ret = pthread_create(&child, &scenarii[i].ta, threaded, &ctl); switch (scenarii[i].result) { case 0: /* Operation was expected to succeed */ if (ret != 0) { UNRESOLVED(ret, "Failed to create this thread"); } break; case 1: /* Operation was expected to fail */ if (ret == 0) { UNRESOLVED(-1, "An error was expected but the thread creation succeeded"); } break; case 2: /* We did not know the expected result */ default: #if VERBOSE > 0 if (ret == 0) { output("Thread has been created successfully for this scenario\n"); } else { output("Thread creation failed with the error: %s\n", strerror(ret)); } #endif } if (ret == 0) /* The new thread is running */ { ret = pthread_join(child, &rval); if (ret != 0) { UNRESOLVED(ret, "Unable to join a thread"); } if (rval != (NULL+1)) { FAILED("pthread_join() did not retrieve the pthread_exit() param"); } if (atctl != 0) { FAILED("The function registered with atexit() executed"); } if (ctl != 3) { FAILED("The TLD destructors were not called"); } } } } for (j=0; j<3; j++) { ret = pthread_key_delete(tld[j]); if (ret != 0) { UNRESOLVED(ret, "Failed to delete a TLD key"); } } scenar_fini(); #if VERBOSE > 0 output("-----\n"); output("All test data destroyed\n"); output("Test PASSED\n"); #endif PASSED; } posixtestsuite/conformance/interfaces/pthread_exit/4-1.c0100644000000000000000000001402110124544413022427 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertion: * * No atexit() registered routine shall be called because of pthread_exit(). * The steps are: * * -> Create threads with different attributes (but all must be joinable) * -> inside the thread, * -> register a function with atexit() * -> call pthread_exit. * -> In the main thread, we join the thread and check the function did not execute. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /* Some routines are part of the XSI Extensions */ #ifndef WITHOUT_XOPEN #define _XOPEN_SOURCE 600 #endif /********************************************************************************************/ /****************************** standard includes *****************************************/ /********************************************************************************************/ #include #include #include #include #include #include #include #include #include #include /********************************************************************************************/ /****************************** Test framework *****************************************/ /********************************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /********************************************************************************************/ /********************************** Configuration ******************************************/ /********************************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif /********************************************************************************************/ /*********************************** Test cases *****************************************/ /********************************************************************************************/ #include "threads_scenarii.c" /* This file will define the following objects: * scenarii: array of struct __scenario type. * NSCENAR : macro giving the total # of scenarii * scenar_init(): function to call before use the scenarii array. * scenar_fini(): function to call after end of use of the scenarii array. */ /********************************************************************************************/ /*********************************** Real Test *****************************************/ /********************************************************************************************/ int global=0; /* atexit() routines */ void at1(void) { global+=1; } void at2(void) { global+=2; } /* Thread routine */ void * threaded (void * arg) { int ret = 0; /* Note that this funtion will be registered once again for each scenario. POSIX requires the ability to register at least 32 functions so it should not be an issue in our case, as long as we don't get more than 32 scenarii (with joinable threads) */ ret = atexit(at2); if (ret != 0) { UNRESOLVED(ret, "Failed to register an atexit() routine"); } pthread_exit(NULL + 1); FAILED("pthread_exit() did not terminate the thread"); return NULL; } int main (int argc, char *argv[]) { int ret=0; void * rval; pthread_t child; int i; output_init(); scenar_init(); for (i=0; i < NSCENAR; i++) { if (scenarii[i].detached == 0) { #if VERBOSE > 0 output("-----\n"); output("Starting test with scenario (%i): %s\n", i, scenarii[i].descr); #endif ret = pthread_create(&child, &scenarii[i].ta, threaded, NULL); switch (scenarii[i].result) { case 0: /* Operation was expected to succeed */ if (ret != 0) { UNRESOLVED(ret, "Failed to create this thread"); } break; case 1: /* Operation was expected to fail */ if (ret == 0) { UNRESOLVED(-1, "An error was expected but the thread creation succeeded"); } break; case 2: /* We did not know the expected result */ default: #if VERBOSE > 0 if (ret == 0) { output("Thread has been created successfully for this scenario\n"); } else { output("Thread creation failed with the error: %s\n", strerror(ret)); } #endif } if (ret == 0) /* The new thread is running */ { ret = pthread_join(child, &rval); if (ret != 0) { UNRESOLVED(ret, "Unable to join a thread"); } if (rval != (NULL+1)) { FAILED("pthread_join() did not retrieve the pthread_exit() param"); } if (global != 0) { FAILED("The function registered with atexit() executed"); } } } } scenar_fini(); #if VERBOSE > 0 output("-----\n"); output("All test data destroyed\n"); output("Test PASSED\n"); #endif PASSED; } posixtestsuite/conformance/interfaces/pthread_exit/1-1.c0100644000000000000000000000420207647616456022453 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_exit() * * terminates the calling thread and makes the value 'value_ptr' available * to any successful join with the terminating thread. * * Steps: * 1. Create a new thread. Have it return a return code on pthread_exit(); * 2. Call pthread_join() in main(), and pass to it 'value_ptr'. * 3. Check to see of the value_ptr and the value returned by pthread_exit() are the same; * */ #include #include #include #include "posixtest.h" #define RETURN_CODE 100 /* Set a random return code number. This shall be the return code of the thread when using pthread_exit().*/ # define INTHREAD 0 /* Control going to or is already for Thread */ # define INMAIN 1 /* Control going to or is already for Main */ int sem; /* Manual semaphore used to indicate when the thread has been created. */ /* Thread's function. */ void *a_thread_func() { sem=INMAIN; pthread_exit((void*)RETURN_CODE); return NULL; } int main() { pthread_t new_th; int *value_ptr; /* Initializing variables. */ value_ptr=0; sem=INTHREAD; /* Create a new thread. */ if(pthread_create(&new_th, NULL, a_thread_func, NULL) != 0) { perror("Error creating thread\n"); return PTS_UNRESOLVED; } /* Make sure the thread was created before we join it. */ while(sem==INTHREAD) sleep(1); /* Wait for thread to return */ if(pthread_join(new_th, (void*)&value_ptr) != 0) { perror("Error in pthread_join()\n"); return PTS_UNRESOLVED; } /* Check to make sure that 'value_ptr' that was passed to pthread_join() and the * pthread_exit() return code that was used in the thread funciton are the same. */ if((long)value_ptr != RETURN_CODE) { printf("Test FAILED: pthread_exit() could not pass the return value of the thread in 'value_ptr' to pthread_join().\n"); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_exit/testfrmw.c0100644000000000000000000000407210124544413024006 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * * This file is a wrapper to use the tests from the NPTL Test & Trace Project * with either the Linux Test Project or the Open POSIX Test Suite. * The following function are defined: * void output_init() * void output_fini() * void output(char * string, ...) * * The are used to output informative text (as a printf). */ #include #include /* We use a mutex to avoid conflicts in traces */ static pthread_mutex_t m_trace = PTHREAD_MUTEX_INITIALIZER; /*****************************************************************************************/ /******************************* stdout module *****************************************/ /*****************************************************************************************/ /* The following functions will output to stdout */ #if (1) void output_init() { /* do nothing */ return; } void output( char * string, ... ) { va_list ap; char *ts="[??:??:??]"; struct tm * now; time_t nw; pthread_mutex_lock(&m_trace); nw = time(NULL); now = localtime(&nw); if (now == NULL) printf(ts); else printf("[%2.2d:%2.2d:%2.2d]", now->tm_hour, now->tm_min, now->tm_sec); va_start( ap, string); vprintf(string, ap); va_end(ap); pthread_mutex_unlock(&m_trace); } void output_fini() { /*do nothing */ return; } #endif posixtestsuite/conformance/interfaces/pthread_exit/threads_scenarii.c0100644000000000000000000003476010124544413025451 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This file is a helper file for the pthread_create tests * It defines the following objects: * scenarii: array of struct __scenario type. * NSCENAR : macro giving the total # of scenarii * scenar_init(): function to call before use the scenarii array. * scenar_fini(): function to call after end of use of the scenarii array. * */ struct __scenario { /* Object to hold the given configuration, and which will be used to create the threads */ pthread_attr_t ta; /* General parameters */ int detached; /* 0 => joinable; 1 => detached */ /* Scheduling parameters */ int explicitsched; /* 0 => sched policy is inherited; 1 => sched policy from the attr param */ int schedpolicy; /* 0 => default; 1=> SCHED_FIFO; 2=> SCHED_RR */ int schedparam; /* 0 => default sched param; 1 => max value for sched param; -1 => min value for sched param */ int altscope; /* 0 => default contension scope; 1 => alternative contension scope */ /* Stack parameters */ int altstack; /* 0 => system manages the stack; 1 => stack is provided */ int guard; /* 0 => default guardsize; 1=> guardsize is 0; 2=> guard is 1 page -- this setting only affect system stacks (not user's). */ int altsize; /* 0 => default stack size; 1 => stack size specified (min value) -- ignored when stack is provided */ /* Additionnal information */ char * descr; /* object description */ void * bottom; /* Stores the stack start when an alternate stack is required */ int result; /* This thread creation is expected to: 0 => succeed; 1 => fail; 2 => unknown */ sem_t sem; /* This semaphore is used to signal the end of the detached threads execution */ } scenarii[]= #define CASE(det,expl,scp,spa,sco,sta,gua,ssi,desc,res) \ { \ .detached=det, \ .explicitsched=expl, \ .schedpolicy=scp, \ .schedparam=spa, \ .altscope=sco, \ .altstack=sta, \ .guard=gua, \ .altsize=ssi, \ .descr=desc, \ .bottom=NULL, \ .result=res } #define CASE_POS(det,expl,scp,spa,sco,sta,gua,ssi,desc) CASE(det,expl,scp,spa,sco,sta,gua,ssi,desc,0) #define CASE_NEG(det,expl,scp,spa,sco,sta,gua,ssi,desc) CASE(det,expl,scp,spa,sco,sta,gua,ssi,desc,1) #define CASE_UNK(det,expl,scp,spa,sco,sta,gua,ssi,desc) CASE(det,expl,scp,spa,sco,sta,gua,ssi,desc,2) /* * This array gives the different combinations of threads attributes for the testcases. * * Some combinations must be avoided. * -> Do not have a detached thread use an alternative stack; * as we don't know when the thread terminates to free the stack memory * -> ... (to be completed) * */ { /* Unary tests */ /* 0*/ CASE_POS( 0, 0, 0, 0, 0, 0, 0, 0, "default") /* 1*/ ,CASE_POS( 1, 0, 0, 0, 0, 0, 0, 0, "detached") /* 2*/ ,CASE_POS( 0, 1, 0, 0, 0, 0, 0, 0, "Explicit sched") /* 3*/ ,CASE_UNK( 0, 0, 1, 0, 0, 0, 0, 0, "FIFO Policy") /* 4*/ ,CASE_UNK( 0, 0, 2, 0, 0, 0, 0, 0, "RR Policy") /* 5*/ ,CASE_UNK( 0, 0, 0, 1, 0, 0, 0, 0, "Max sched param") /* 6*/ ,CASE_UNK( 0, 0, 0,-1, 0, 0, 0, 0, "Min sched param") /* 7*/ ,CASE_POS( 0, 0, 0, 0, 1, 0, 0, 0, "Alternative contension scope") /* 8*/ ,CASE_POS( 0, 0, 0, 0, 0, 1, 0, 0, "Alternative stack") /* 9*/ ,CASE_POS( 0, 0, 0, 0, 0, 0, 1, 0, "No guard size") /*10*/ ,CASE_UNK( 0, 0, 0, 0, 0, 0, 2, 0, "1p guard size") /*11*/ ,CASE_POS( 0, 0, 0, 0, 0, 0, 0, 1, "Min stack size") /* Stack play */ ,CASE_POS( 0, 0, 0, 0, 0, 0, 1, 1, "Min stack size, no guard") ,CASE_UNK( 0, 0, 0, 0, 0, 0, 2, 1, "Min stack size, 1p guard") ,CASE_POS( 1, 0, 0, 0, 0, 1, 0, 0, "Detached, Alternative stack") ,CASE_POS( 1, 0, 0, 0, 0, 0, 1, 1, "Detached, Min stack size, no guard") ,CASE_UNK( 1, 0, 0, 0, 0, 0, 2, 1, "Detached, Min stack size, 1p guard") /* Scheduling play -- all results are unknown since it might depend on the user priviledges */ ,CASE_UNK( 0, 1, 1, 1, 0, 0, 0, 0, "Explicit FIFO max param") ,CASE_UNK( 0, 1, 2, 1, 0, 0, 0, 0, "Explicit RR max param") ,CASE_UNK( 0, 1, 1,-1, 0, 0, 0, 0, "Explicit FIFO min param") ,CASE_UNK( 0, 1, 2,-1, 0, 0, 0, 0, "Explicit RR min param") ,CASE_UNK( 0, 1, 1, 1, 1, 0, 0, 0, "Explicit FIFO max param, alt scope") ,CASE_UNK( 0, 1, 2, 1, 1, 0, 0, 0, "Explicit RR max param, alt scope") ,CASE_UNK( 0, 1, 1,-1, 1, 0, 0, 0, "Explicit FIFO min param, alt scope") ,CASE_UNK( 0, 1, 2,-1, 1, 0, 0, 0, "Explicit RR min param, alt scope") ,CASE_UNK( 1, 1, 1, 1, 0, 0, 0, 0, "Detached, explicit FIFO max param") ,CASE_UNK( 1, 1, 2, 1, 0, 0, 0, 0, "Detached, explicit RR max param") ,CASE_UNK( 1, 1, 1,-1, 0, 0, 0, 0, "Detached, explicit FIFO min param") ,CASE_UNK( 1, 1, 2,-1, 0, 0, 0, 0, "Detached, explicit RR min param") ,CASE_UNK( 1, 1, 1, 1, 1, 0, 0, 0, "Detached, explicit FIFO max param, alt scope") ,CASE_UNK( 1, 1, 2, 1, 1, 0, 0, 0, "Detached, explicit RR max param, alt scope") ,CASE_UNK( 1, 1, 1,-1, 1, 0, 0, 0, "Detached, explicit FIFO min param, alt scope") ,CASE_UNK( 1, 1, 2,-1, 1, 0, 0, 0, "Detached, explicit RR min param, alt scope") }; #define NSCENAR (sizeof(scenarii) / sizeof(scenarii[0])) /* This function will initialize every pthread_attr_t object in the scenarii array */ void scenar_init() { int ret=0; int i; int old; long pagesize, minstacksize; long tsa, tss, tps; pagesize =sysconf(_SC_PAGESIZE); minstacksize =sysconf(_SC_THREAD_STACK_MIN); tsa =sysconf(_SC_THREAD_ATTR_STACKADDR); tss =sysconf(_SC_THREAD_ATTR_STACKSIZE); tps =sysconf(_SC_THREAD_PRIORITY_SCHEDULING); #if VERBOSE > 0 output("System abilities:\n"); output(" TSA: %li\n", tsa); output(" TSS: %li\n", tss); output(" TPS: %li\n", tps); output(" pagesize: %li\n", pagesize); output(" min stack size: %li\n", minstacksize); #endif if (minstacksize % pagesize) { UNTESTED("The min stack size is not a multiple of the page size"); } for (i=0; i 2 output("Initializing attribute for scenario %i: %s\n", i, scenarii[i].descr); #endif ret = pthread_attr_init(&scenarii[i].ta); if (ret != 0) { UNRESOLVED(ret, "Failed to initialize a thread attribute object"); } /* Set the attributes according to the scenario */ if (scenarii[i].detached == 1) { ret = pthread_attr_setdetachstate(&scenarii[i].ta, PTHREAD_CREATE_DETACHED); if (ret != 0) { UNRESOLVED(ret, "Unable to set detachstate"); } } else { ret = pthread_attr_getdetachstate(&scenarii[i].ta, &old); if (ret != 0) { UNRESOLVED(ret, "Unable to get detachstate from initialized attribute"); } if (old != PTHREAD_CREATE_JOINABLE) { FAILED("The default attribute is not PTHREAD_CREATE_JOINABLE"); } } #if VERBOSE > 4 output("Detach state was set sucessfully\n"); #endif /* Sched related attributes */ if (tps>0) /* This routine is dependent on the Thread Execution Scheduling option */ { if (scenarii[i].explicitsched == 1) ret = pthread_attr_setinheritsched(&scenarii[i].ta, PTHREAD_EXPLICIT_SCHED); else ret = pthread_attr_setinheritsched(&scenarii[i].ta, PTHREAD_INHERIT_SCHED); if (ret != 0) { UNRESOLVED(ret, "Unable to set inheritsched attribute"); } #if VERBOSE > 4 output("inheritsched state was set sucessfully\n"); #endif } #if VERBOSE > 4 else output("TPS unsupported => inheritsched parameter untouched\n"); #endif if (tps>0) /* This routine is dependent on the Thread Execution Scheduling option */ { if (scenarii[i].schedpolicy == 1) { ret = pthread_attr_setschedpolicy(&scenarii[i].ta, SCHED_FIFO); } if (scenarii[i].schedpolicy == 2) { ret = pthread_attr_setschedpolicy(&scenarii[i].ta, SCHED_RR); } if (ret != 0) { UNRESOLVED(ret, "Unable to set the sched policy"); } #if VERBOSE > 4 if (scenarii[i].schedpolicy) output("Sched policy was set sucessfully\n"); else output("Sched policy untouched\n"); #endif } #if VERBOSE > 4 else output("TPS unsupported => sched policy parameter untouched\n"); #endif if (scenarii[i].schedparam != 0) { struct sched_param sp; ret = pthread_attr_getschedpolicy(&scenarii[i].ta, &old); if (ret != 0) { UNRESOLVED(ret, "Unable to get sched policy from attribute"); } if (scenarii[i].schedparam == 1) sp.sched_priority = sched_get_priority_max(old); if (scenarii[i].schedparam == -1) sp.sched_priority = sched_get_priority_min(old); ret = pthread_attr_setschedparam(&scenarii[i].ta, &sp); if (ret != 0) { UNRESOLVED(ret, "Failed to set the sched param"); } #if VERBOSE > 4 output("Sched param was set sucessfully to %i\n", sp.sched_priority); } else { output("Sched param untouched\n"); #endif } if (tps>0) /* This routine is dependent on the Thread Execution Scheduling option */ { ret = pthread_attr_getscope(&scenarii[i].ta, &old); if (ret != 0) { UNRESOLVED(ret, "Failed to get contension scope from thread attribute"); } if (scenarii[i].altscope != 0) { if (old == PTHREAD_SCOPE_PROCESS) old = PTHREAD_SCOPE_SYSTEM; else old = PTHREAD_SCOPE_PROCESS; ret = pthread_attr_setscope(&scenarii[i].ta, old); //if (ret != 0) { UNRESOLVED(ret, "Failed to set contension scope"); } #if VERBOSE > 0 if (ret != 0) { output("WARNING: The TPS option is claimed to be supported but setscope fails\n"); } #endif #if VERBOSE > 4 output("Contension scope set to %s\n", old==PTHREAD_SCOPE_PROCESS?"PTHREAD_SCOPE_PROCESS":"PTHREAD_SCOPE_SYSTEM"); } else { output("Contension scope untouched (%s)\n", old==PTHREAD_SCOPE_PROCESS?"PTHREAD_SCOPE_PROCESS":"PTHREAD_SCOPE_SYSTEM"); #endif } } #if VERBOSE > 4 else output("TPS unsupported => sched contension scope parameter untouched\n"); #endif /* Stack related attributes */ if ((tss>0) && (tsa>0)) /* This routine is dependent on the Thread Stack Address Attribute and Thread Stack Size Attribute options */ { if (scenarii[i].altstack != 0) { /* This is slightly more complicated. We need to alloc a new stack and free it upon test termination */ /* We will alloc with a simulated guardsize of 1 pagesize */ scenarii[i].bottom = malloc(minstacksize + pagesize); if (scenarii[i].bottom == NULL) { UNRESOLVED(errno,"Unable to alloc enough memory for alternative stack"); } ret = pthread_attr_setstack(&scenarii[i].ta, scenarii[i].bottom, minstacksize); if (ret != 0) { UNRESOLVED(ret, "Failed to specify alternate stack"); } #if VERBOSE > 1 output("Alternate stack created successfully. Bottom=%p, Size=%i\n", scenarii[i].bottom, minstacksize); #endif } } #if VERBOSE > 4 else output("TSA or TSS unsupported => No alternative stack\n"); #endif #ifndef WITHOUT_XOPEN if (scenarii[i].guard != 0) { if (scenarii[i].guard == 1) ret = pthread_attr_setguardsize(&scenarii[i].ta, 0); if (scenarii[i].guard == 2) ret = pthread_attr_setguardsize(&scenarii[i].ta, pagesize); if (ret != 0) { UNRESOLVED(ret, "Unable to set guard area size in thread stack"); } #if VERBOSE > 4 output("Guard size set to %i\n", (scenarii[i].guard==1)?1:pagesize); #endif } #endif if (tss>0) /* This routine is dependent on the Thread Stack Size Attribute option */ { if (scenarii[i].altsize != 0) { ret = pthread_attr_setstacksize(&scenarii[i].ta, minstacksize); if (ret != 0) { UNRESOLVED(ret, "Unable to change stack size"); } #if VERBOSE > 4 output("Stack size set to %i (this is the min)\n", minstacksize); #endif } } #if VERBOSE > 4 else output("TSS unsupported => stack size unchanged\n"); #endif ret = sem_init(&scenarii[i].sem, 0,0); if (ret == -1) { UNRESOLVED(errno, "Unable to init a semaphore"); } } #if VERBOSE > 0 output("All %i thread attribute objects were initialized\n\n", NSCENAR); #endif } /* This function will free all resources consumed in the scenar_init() routine */ void scenar_fini(void) { int ret = 0, i; for (i=0; i 0 output("-----\n"); output("Starting test with scenario (%i): %s\n", sc, scenarii[sc].descr); #endif ret = pthread_create(&child, &scenarii[sc].ta, threaded, NULL); switch (scenarii[sc].result) { case 0: /* Operation was expected to succeed */ if (ret != 0) { UNRESOLVED(ret, "Failed to create this thread"); } break; case 1: /* Operation was expected to fail */ if (ret == 0) { UNRESOLVED(-1, "An error was expected but the thread creation succeeded"); } break; case 2: /* We did not know the expected result */ default: #if VERBOSE > 0 if (ret == 0) { output("Thread has been created successfully for this scenario\n"); } else { output("Thread creation failed with the error: %s\n", strerror(ret)); } #endif } if (ret == 0) /* The new thread is running */ { if (scenarii[sc].detached == 0) { ret = pthread_join(child, NULL); if (ret != 0) { UNRESOLVED(ret, "Unable to join a thread"); } } else { /* Just wait for the thread to terminate */ do { ret = sem_wait(&scenarii[sc].sem); } while ((ret == -1) && (errno == EINTR)); if (ret == -1) { UNRESOLVED(errno, "Failed to wait for the semaphore"); } } } } scenar_fini(); #if VERBOSE > 0 output("-----\n"); output("All test data destroyed\n"); output("Test PASSED\n"); #endif PASSED; } #endif posixtestsuite/conformance/interfaces/pthread_exit/6-1.c0100644000000000000000000002063010124544413022434 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertion: * * If the calling thread is the last thread in the process, * the effect are as if an implicit call to exit(0) had been made. * The steps are: * * -> main creates a thread. * -> this thread forks(). The new process contains only 1 thread. * -> the thread in the new process calls pthread_exit(non-0 value). * -> main process joins the child process and checks the behavior * is as if exit(0) had been called. * The checked items are: * -> the return value. * -> the atexit() routines have been called. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /* Some routines are part of the XSI Extensions */ #ifndef WITHOUT_XOPEN #define _XOPEN_SOURCE 600 #endif /********************************************************************************************/ /****************************** standard includes *****************************************/ /********************************************************************************************/ #include #include #include #include #include #include #include #include #include #include #include #include /********************************************************************************************/ /****************************** Test framework *****************************************/ /********************************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /********************************************************************************************/ /********************************** Configuration ******************************************/ /********************************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif /********************************************************************************************/ /*********************************** Test cases *****************************************/ /********************************************************************************************/ #include "threads_scenarii.c" /* This file will define the following objects: * scenarii: array of struct __scenario type. * NSCENAR : macro giving the total # of scenarii * scenar_init(): function to call before use the scenarii array. * scenar_fini(): function to call after end of use of the scenarii array. */ /********************************************************************************************/ /*********************************** Real Test *****************************************/ /********************************************************************************************/ /* This will be used to control that atexit() has been called */ int * ctl; long mf; void clnp(void) { *ctl = 1; } /* Thread routine */ void * threaded (void * arg) { int ret = 0; pid_t pid, chk; int status; if (mf > 0) *ctl = 0; pid = fork(); if (pid == (pid_t)-1) { UNRESOLVED(errno, "Failed to fork()"); } if (pid == 0) { /* children */ if (mf > 0) { ret = atexit(clnp); if (ret != 0) { UNRESOLVED(ret, "Failed to register atexit function"); } } /* exit the last (and only) thread */ pthread_exit(&ret); FAILED("pthread_exit() did not terminate the process when there was only 1 thread"); } /* Only the parent process goes this far */ chk = waitpid(pid, &status, 0); if (chk != pid) { output("Expected pid: %i. Got %i\n", (int)pid, (int)chk); UNRESOLVED(errno, "Waitpid failed"); } if (WIFSIGNALED(status)) { output("Child process killed with signal %d\n",WTERMSIG(status)); UNRESOLVED( -1 , "Child process was killed"); } if (WIFEXITED(status)) { ret = WEXITSTATUS(status); } else { UNRESOLVED( -1, "Child process was neither killed nor exited"); } if (ret != 0) { output("Exit status was: %i\n", ret); FAILED("The child process did not exit with 0 status."); } if (mf > 0) if (*ctl != 1) FAILED("pthread_exit() in the last thread did not execute atexit() routines"); /* Signal we're done (especially in case of a detached thread) */ do { ret = sem_post(&scenarii[sc].sem); } while ((ret == -1) && (errno == EINTR)); if (ret == -1) { UNRESOLVED(errno, "Failed to wait for the semaphore"); } return NULL; } /* Main routine */ int main (int argc, char *argv[]) { int ret=0; pthread_t child; mf =sysconf(_SC_MAPPED_FILES); output_init(); scenar_init(); /* We want to share some memory with the child process */ if (mf> 0) { /* We will place the test data in a mmaped file */ char filename[] = "/tmp/pthread_exit_6-1-XXXXXX"; size_t sz; void * mmaped; int fd; char * tmp; /* We now create the temp files */ fd = mkstemp(filename); if (fd == -1) { UNRESOLVED(errno, "Temporary file could not be created"); } /* and make sure the file will be deleted when closed */ unlink(filename); #if VERBOSE > 1 output("Temp file created (%s).\n", filename); #endif sz= (size_t)sysconf(_SC_PAGESIZE); tmp = calloc(1, sz); if (tmp == NULL) { UNRESOLVED(errno, "Memory allocation failed"); } /* Write the data to the file. */ if (write (fd, tmp, sz) != (ssize_t) sz) { UNRESOLVED(sz, "Writting to the file failed"); } free(tmp); /* Now we can map the file in memory */ mmaped = mmap(NULL, sz, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); if (mmaped == MAP_FAILED) { UNRESOLVED(errno, "mmap failed"); } ctl = (int *) mmaped; /* Our datatest structure is now in shared memory */ #if VERBOSE > 1 output("Testdata allocated in shared memory.\n"); #endif } for (sc=0; sc < NSCENAR; sc++) { #if VERBOSE > 0 output("-----\n"); output("Starting test with scenario (%i): %s\n", sc, scenarii[sc].descr); #endif ret = pthread_create(&child, &scenarii[sc].ta, threaded, &ctl); switch (scenarii[sc].result) { case 0: /* Operation was expected to succeed */ if (ret != 0) { UNRESOLVED(ret, "Failed to create this thread"); } break; case 1: /* Operation was expected to fail */ if (ret == 0) { UNRESOLVED(-1, "An error was expected but the thread creation succeeded"); } break; case 2: /* We did not know the expected result */ default: #if VERBOSE > 0 if (ret == 0) { output("Thread has been created successfully for this scenario\n"); } else { output("Thread creation failed with the error: %s\n", strerror(ret)); } #endif } if (ret == 0) /* The new thread is running */ { if (scenarii[sc].detached == 0) { ret = pthread_join(child, NULL); if (ret != 0) { UNRESOLVED(ret, "Unable to join a thread"); } } else { /* Just wait for the thread to terminate */ do { ret = sem_wait(&scenarii[sc].sem); } while ((ret == -1) && (errno == EINTR)); if (ret == -1) { UNRESOLVED(errno, "Failed to wait for the semaphore"); } } } } scenar_fini(); #if VERBOSE > 0 output("-----\n"); output("All test data destroyed\n"); output("Test PASSED\n"); #endif PASSED; } posixtestsuite/conformance/interfaces/pthread_exit/3-2.c0100644000000000000000000001563410124544413022442 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertion: * * The TLD destructors (if any) are executed after the cancelation cleanup handlers, * in unspecified order. * The steps are: * * -> Create threads with different attributes (but all must be joinable) * -> inside the thread, * -> register three cancelation handlers * -> call pthread_exit. * -> In the main thread, we join the thread and check the cleanups were executed in order. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /* Some routines are part of the XSI Extensions */ #ifndef WITHOUT_XOPEN #define _XOPEN_SOURCE 600 #endif /********************************************************************************************/ /****************************** standard includes *****************************************/ /********************************************************************************************/ #include #include #include #include #include #include #include #include #include #include /********************************************************************************************/ /****************************** Test framework *****************************************/ /********************************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /********************************************************************************************/ /********************************** Configuration ******************************************/ /********************************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif /********************************************************************************************/ /*********************************** Test cases *****************************************/ /********************************************************************************************/ #include "threads_scenarii.c" /* This file will define the following objects: * scenarii: array of struct __scenario type. * NSCENAR : macro giving the total # of scenarii * scenar_init(): function to call before use the scenarii array. * scenar_fini(): function to call after end of use of the scenarii array. */ /********************************************************************************************/ /*********************************** Real Test *****************************************/ /********************************************************************************************/ int global=0; int tab[4]; pthread_key_t tld[3]; #define CLEANUP(n) void clnp##n(void * arg)\ {\ tab[global]=n; \ global++; \ } /* Cancelation cleanup handlers */ CLEANUP(1) CLEANUP(2) CLEANUP(3) /* TLD destructor */ void destructor(void * arg) { *(int *) arg += global; } /* Thread routine */ void * threaded (void * arg) { int ret = 0; ret = pthread_setspecific(tld[0], (void *)&tab[3]); if (ret != 0) { UNRESOLVED(ret, "Failed to set TLD data"); } pthread_cleanup_push(clnp3, NULL); pthread_cleanup_push(clnp2, NULL); ret = pthread_setspecific(tld[1], (void *)&tab[3]); if (ret != 0) { UNRESOLVED(ret, "Failed to set TLD data"); } pthread_cleanup_push(clnp1, NULL); ret = pthread_setspecific(tld[2], (void *)&tab[3]); if (ret != 0) { UNRESOLVED(ret, "Failed to set TLD data"); } pthread_exit(NULL + 1); pthread_cleanup_pop(0); pthread_cleanup_pop(0); pthread_cleanup_pop(0); FAILED("pthread_exit() did not terminate the thread"); return NULL; } int main (int argc, char *argv[]) { int ret=0; void * rval; pthread_t child; int i,j; output_init(); scenar_init(); for (j=0; j<3; j++) { ret = pthread_key_create(&tld[j], destructor); if (ret != 0) { UNRESOLVED(ret, "Failed to create a TLD key"); } } for (i=0; i < NSCENAR; i++) { if (scenarii[i].detached == 0) { #if VERBOSE > 0 output("-----\n"); output("Starting test with scenario (%i): %s\n", i, scenarii[i].descr); #endif for (j=0; j<4; j++) tab[j]=0; global=0; ret = pthread_create(&child, &scenarii[i].ta, threaded, NULL); switch (scenarii[i].result) { case 0: /* Operation was expected to succeed */ if (ret != 0) { UNRESOLVED(ret, "Failed to create this thread"); } break; case 1: /* Operation was expected to fail */ if (ret == 0) { UNRESOLVED(-1, "An error was expected but the thread creation succeeded"); } break; case 2: /* We did not know the expected result */ default: #if VERBOSE > 0 if (ret == 0) { output("Thread has been created successfully for this scenario\n"); } else { output("Thread creation failed with the error: %s\n", strerror(ret)); } #endif } if (ret == 0) /* The new thread is running */ { ret = pthread_join(child, &rval); if (ret != 0) { UNRESOLVED(ret, "Unable to join a thread"); } if (rval != (NULL+1)) { FAILED("pthread_join() did not retrieve the pthread_exit() param"); } for (j=0; j<3; j++) { if ((tab[j] != j+1) || (tab[3] != 9)) { output("dump:\ntab[0]=%i\ntab[1]=%i\ntab[2]=%i\ntab[3]=%i\n", tab[0], tab[1], tab[2], tab[3]); FAILED("The cleanup handlers were not called as expected"); } } } } } for (j=0; j<3; j++) { ret = pthread_key_delete(tld[j]); if (ret != 0) { UNRESOLVED(ret, "Failed to delete a TLD key"); } } scenar_fini(); #if VERBOSE > 0 output("-----\n"); output("All test data destroyed\n"); output("Test PASSED\n"); #endif PASSED; } posixtestsuite/conformance/interfaces/pthread_exit/1-2.c0100644000000000000000000001305410124544410022427 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertion: * * pthread_exit() terminates the current thread and * allows a call to pthread_join() on this thread retrieve * the argument (if the thread is not detached). * The steps are: * * -> Create threads with different attributes (but all must be joinable) * -> inside the thread, a call to pthread_exit() is made with a certain value. * -> In the main thread, we join the thread and check the value is as expected. * The test fails if the values are different. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /* Some routines are part of the XSI Extensions */ #ifndef WITHOUT_XOPEN #define _XOPEN_SOURCE 600 #endif /********************************************************************************************/ /****************************** standard includes *****************************************/ /********************************************************************************************/ #include #include #include #include #include #include #include #include #include #include /********************************************************************************************/ /****************************** Test framework *****************************************/ /********************************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /********************************************************************************************/ /********************************** Configuration ******************************************/ /********************************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif /********************************************************************************************/ /*********************************** Test cases *****************************************/ /********************************************************************************************/ #include "threads_scenarii.c" /* This file will define the following objects: * scenarii: array of struct __scenario type. * NSCENAR : macro giving the total # of scenarii * scenar_init(): function to call before use the scenarii array. * scenar_fini(): function to call after end of use of the scenarii array. */ /********************************************************************************************/ /*********************************** Real Test *****************************************/ /********************************************************************************************/ void * threaded (void * arg) { pthread_exit(NULL + 1); FAILED("pthread_exit() did not terminate the thread"); return NULL; } int main (int argc, char *argv[]) { int ret=0; void * rval; pthread_t child; int i; output_init(); scenar_init(); for (i=0; i < NSCENAR; i++) { if (scenarii[i].detached == 0) { #if VERBOSE > 0 output("-----\n"); output("Starting test with scenario (%i): %s\n", i, scenarii[i].descr); #endif ret = pthread_create(&child, &scenarii[i].ta, threaded, NULL); switch (scenarii[i].result) { case 0: /* Operation was expected to succeed */ if (ret != 0) { UNRESOLVED(ret, "Failed to create this thread"); } break; case 1: /* Operation was expected to fail */ if (ret == 0) { UNRESOLVED(-1, "An error was expected but the thread creation succeeded"); } break; case 2: /* We did not know the expected result */ default: #if VERBOSE > 0 if (ret == 0) { output("Thread has been created successfully for this scenario\n"); } else { output("Thread creation failed with the error: %s\n", strerror(ret)); } #endif } if (ret == 0) /* The new thread is running */ { ret = pthread_join(child, &rval); if (ret != 0) { UNRESOLVED(ret, "Unable to join a thread"); } if (rval != (NULL+1)) { FAILED("pthread_join() did not retrieve the pthread_exit() param"); } } } } scenar_fini(); #if VERBOSE > 0 output("-----\n"); output("All test data destroyed\n"); output("Test PASSED\n"); #endif PASSED; } posixtestsuite/conformance/interfaces/pthread_exit/assertions.xml0100644000000000000000000000330710124246154024704 0ustar rootroot The function void pthread_exit(void *value_ptr); terminates the calling thread and makes the value 'value_ptr' available to any successful join with the terminating thread. Any cancelation cleanup handlers that have been pushed and not yet popped shall be popped and executed in the reverse order that they were pushed. After all cancelation cleanup handlers have been executed, if the thread has any thread-specific data, appriopriate destructor functions shall be called in an unspecified order. Thread termination does not release any application visible process resources include, but not limited to, mutexes and file descriptors, nor does it perform any process-level cleanup actions, including but not limited to, calling any atexit() routines that may exist. An implicit call to pthread_exit() is made when a thread other than the thread in which main() was first invoked returns from the start routine that was used to create it. The function's return value shall serve as the thread's exit status. The process shall exit with an exit status of 0 after the last thread has been terminated. The behavior shall be as if the implemenation called exit() with a zero argument at thread termination time. The pthread_exit() function cannot return to its called. posixtestsuite/conformance/interfaces/pthread_exit/coverage.txt0100644000000000000000000000030210065776714024332 0ustar rootrootThis document defines the coverage for the pthread_exit function: Assertion Tested? 1 YES 2 YES 3 YES 4 NO ** Skipping for now. 5 NO ** Skipping for now. 6 NO ** Skipping for now. NOTE: posixtestsuite/conformance/interfaces/pthread_exit/testfrmw.h0100644000000000000000000000456410124544413024021 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * * This file is a wrapper to use the tests from the NPTL Test & Trace Project * with either the Linux Test Project or the Open POSIX Test Suite. * The following macros are defined here: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate without calling one of those macros. * * */ #include "posixtest.h" #include /* for the strerror() routine */ #ifdef __GNUC__ /* We are using GCC */ #define UNRESOLVED(x, s) \ { output("Test %s unresolved: got %i (%s) on line %i (%s)\n", __FILE__, x, strerror(x), __LINE__, s); \ output_fini(); \ exit(PTS_UNRESOLVED); } #define FAILED(s) \ { output("Test %s FAILED: %s\n", __FILE__, s); \ output_fini(); \ exit(PTS_FAIL); } #define PASSED \ output_fini(); \ exit(PTS_PASS); #define UNTESTED(s) \ { output("File %s cannot test: %s\n", __FILE__, s); \ output_fini(); \ exit(PTS_UNTESTED); \ } #else /* not using GCC */ #define UNRESOLVED(x, s) \ { output("Test unresolved: got %i (%s) on line %i (%s)\n", x, strerror(x), __LINE__, s); \ output_fini(); \ exit(PTS_UNRESOLVED); } #define FAILED(s) \ { output("Test FAILED: %s\n", s); \ output_fini(); \ exit(PTS_FAIL); } #define PASSED \ output_fini(); \ exit(PTS_PASS); #define UNTESTED(s) \ { output("Unable to test: %s\n", s); \ output_fini(); \ exit(PTS_UNTESTED); \ } #endif posixtestsuite/conformance/interfaces/pthread_exit/2-1.c0100644000000000000000000000561710124246153022440 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_exit() * * Any cancelation cleanup handlers that have been pushed and not yet popped * shall be popped and executed in the reverse order that they were pushed. * * Steps: * 1. Create a new thread. * 2. The thread will call pthread_exit(). * 3. When this happens, the cleanup handler should be called. * 4. Main will test that when pthread_join allows main to continue with the process that * the thread has ended execution. If the cleanup_handler was not called, then the * test fails. * */ #include #include #include #include "posixtest.h" int i[3], j; /* Cleanup function that the thread executes when it is canceled. So if * cleanup_flag is 1, it means that the thread was canceled. */ void a_cleanup_func1() { i[j]=1; j++; return; } /* Cleanup function that the thread executes when it is canceled. So if * cleanup_flag is 1, it means that the thread was canceled. */ void a_cleanup_func2() { i[j]=2; j++; return; } /* Cleanup function that the thread executes when it is canceled. So if * cleanup_flag is 1, it means that the thread was canceled. */ void a_cleanup_func3() { i[j]=3; j++; return; } /* Thread's function. */ void *a_thread_func() { /* Set up 3 cleanup handlers */ pthread_cleanup_push(a_cleanup_func1,NULL); pthread_cleanup_push(a_cleanup_func2,NULL); pthread_cleanup_push(a_cleanup_func3,NULL); /* Terminate the thread here. */ pthread_exit(0); /* Need these here for it to compile nicely. We never reach here though. */ pthread_cleanup_pop(0); pthread_cleanup_pop(0); pthread_cleanup_pop(0); return NULL; } int main() { pthread_t new_th; /* Initialize integer array. */ for(j=0;j<3;j++) i[j] = 0; /* Initialize counter. */ j=0; /* Create a new thread. */ if(pthread_create(&new_th, NULL, a_thread_func, NULL) != 0) { perror("Error creating thread\n"); return PTS_UNRESOLVED; } /* Wait for thread to return */ if(pthread_join(new_th, NULL) != 0) { perror("Error in pthread_join()\n"); return PTS_UNRESOLVED; } /* Check to make sure that the cleanup handlers were executed in order. */ if(i[0] == 3) { if(i[1] == 2) { if(i[2] == 1) { printf("Test PASSED\n"); return PTS_PASS; } printf("Test FAILED: Did not execute cleanup handlers in order.\n"); return PTS_FAIL; } printf("Test FAILED: Did not execute cleanup handlers in order.\n"); return PTS_FAIL; } else if(i[0] == 0) { printf("Test FAILED: Did not execute cleanup handlers.\n"); return PTS_FAIL; } printf("Test FAILED: Did not execute cleanup handlers in order.\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/pthread_exit/3-1.c0100644000000000000000000000357310065776714022457 0ustar rootroot/* * Copyright (c) 2004, QUALCOMM Inc. All rights reserved. * Created by: abisain REMOVE-THIS AT qualcomm DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test pthread_exit() * * Any destructors for thread_specific data will be called when * pthread_exit is called * * Steps: * 1. Create a new thread. * 2. Create thread specific data, with a destructor in the thread * 3. Call pthread_exit in the thread. * 4. Make sure that the destructor was called * */ #include #include #include #include #include "posixtest.h" #define TEST "3-1" #define FUNCTION "pthread_exit" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " /* Flag to indicate that the destructor was called */ int cleanup_flag = 0; void destructor(void *tmp) { cleanup_flag = 1; } /* Thread's function. */ void *a_thread_func(void *tmp) { pthread_key_t key; int value = 1; int rc = 0; rc = pthread_key_create(&key, destructor); if(rc != 0 ) { printf(ERROR_PREFIX "pthread_key_create\n"); exit(PTS_UNRESOLVED); } rc = pthread_setspecific(key, &value); if(rc != 0 ) { printf(ERROR_PREFIX "pthread_setspecific\n"); exit(PTS_UNRESOLVED); } pthread_exit(0); return NULL; } int main() { pthread_t new_th; int rc = 0; /* Create a new thread. */ rc = pthread_create(&new_th, NULL, a_thread_func, NULL); if(rc != 0) { printf(ERROR_PREFIX "pthread_create\n"); return PTS_UNRESOLVED; } /* Wait for thread to return */ rc = pthread_join(new_th, NULL); if(rc != 0) { printf(ERROR_PREFIX "pthread_join\n"); return PTS_UNRESOLVED; } if(cleanup_flag != 1 ) { printf("Test FAIL: Destructor was not called.\n"); return PTS_FAIL; } printf("Test PASS\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/sched_get_priority_min/0040755000000000000000000000000010515625231024042 5ustar rootrootposixtestsuite/conformance/interfaces/sched_get_priority_min/1-3.c0100644000000000000000000000243210234132767024511 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * * Test that sched_get_priority_min() returns the appropriate minimum value on * success for SCHED_SPORADIC policy. */ #include #include #include #include #include "posixtest.h" #if defined(_POSIX_SPORADIC_SERVER)&&(_POSIX_SPORADIC_SERVER != -1)||defined(_POSIX_THREAD_SPORADIC_SERVER)&&(_POSIX_THREAD_SPORADIC_SERVER != -1) int main(int argc, char **argv) { int result = -1; result = sched_get_priority_min(SCHED_SPORADIC); if(result != -1 && errno == 0 ) { printf("The minimum priority for policy SCHED_SPORADIC is %i.\n", result); printf("Test PASSED\n"); return PTS_PASS; } else { perror("An error occurs"); return PTS_FAIL; } printf("This code should not be executed.\n"); return PTS_UNRESOLVED; } #else int main() { printf("Does not support SS (SPORADIC SERVER)\n"); return PTS_UNSUPPORTED; } #endif posixtestsuite/conformance/interfaces/sched_get_priority_min/3-1.sh0100755000000000000000000000031307643300513024674 0ustar rootroot#! /bin/sh # # Test that sched_get_priority_min() sets errno == EINVAL if policy is not a # valid policy # This is tested implicitly via assertion 2. echo "Tested implicitly via assertion 2." exit 0 posixtestsuite/conformance/interfaces/sched_get_priority_min/1-1.c0100644000000000000000000000175407643277423024526 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * * Test that sched_get_priority_min() returns the minimum value on * success for SCHED_RR policy. */ #include #include #include #include "posixtest.h" int main(int argc, char **argv) { int result = -1; result = sched_get_priority_min(SCHED_RR); if(result != -1 && errno == 0 ) { printf("The minimum priority for policy SCHED_RR is %i.\n", result); printf("Test PASSED\n"); return PTS_PASS; } else { perror("An error occurs"); return PTS_FAIL; } printf("This code should not be executed.\n"); return PTS_UNRESOLVED; } posixtestsuite/conformance/interfaces/sched_get_priority_min/1-2.c0100644000000000000000000000177607643277423024533 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * * Test that sched_get_priority_min() returns the appropriate minimum value on * success for SCHED_FIFO policy. */ #include #include #include #include "posixtest.h" int main(int argc, char **argv) { int result = -1; result = sched_get_priority_min(SCHED_FIFO); if(result != -1 && errno == 0 ) { printf("The minimum priority for policy SCHED_FIFO is %i.\n", result); printf("Test PASSED\n"); return PTS_PASS; } else { perror("An error occurs"); return PTS_FAIL; } printf("This code should not be executed.\n"); return PTS_UNRESOLVED; } posixtestsuite/conformance/interfaces/sched_get_priority_min/assertions.xml0100644000000000000000000000104707643277516026776 0ustar rootroot sched_get_priority_min() returns the minimum priority value on success sched_get_priority_min() returns -1 on failure sched_get_priority_min() sets errno == EINVAL if policy is not a valid policy posixtestsuite/conformance/interfaces/sched_get_priority_min/coverage.txt0100644000000000000000000000060407643277516026414 0ustar rootrootThis document explains why certain assertions were not tested. Assertions not listed here should be covered by the tests in this directory. Assertions Tested ? Remarks 1 YES max and min priorities are taken from the system (AIX) only tested for SCHED_FIFO, SCHED_RR and SCHED_OTHER policy speculative for AIX (FIFO2, FIFO3, FIFO4) 2 YES 3 YESposixtestsuite/conformance/interfaces/sched_get_priority_min/2-1.c0100644000000000000000000000204307643277424024520 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * * Test that sched_get_priority_min() returns -1 on failure */ #include #include #include #include "posixtest.h" int main(int argc, char **argv) { int result = -1; result = sched_get_priority_min(-1); if(result == -1 && errno == EINVAL ) { printf("Test PASSED\n"); return PTS_PASS; } if (result != -1) { printf("did not returned -1.\n"); return PTS_FAIL; } if (errno != EINVAL) { perror("error is not EINVAL"); return PTS_FAIL; } else { printf("Unresolved test error\n"); return PTS_UNRESOLVED; } printf("This code should not be executed.\n"); return PTS_UNRESOLVED; } posixtestsuite/conformance/interfaces/sched_get_priority_min/1-4.c0100644000000000000000000000200107643277424024514 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * * Test that sched_get_priority_min() returns the appropriate minimum value on * success for SCHED_OTHER policy. */ #include #include #include #include "posixtest.h" int main(int argc, char **argv) { int result = -1; result = sched_get_priority_min(SCHED_OTHER); if(result != -1 && errno == 0 ) { printf("The minimum priority for policy SCHED_OTHER is %i.\n", result); printf("Test PASSED\n"); return PTS_PASS; } else { perror("An error occurs"); return PTS_FAIL; } printf("This code should not be executed.\n"); return PTS_UNRESOLVED; } posixtestsuite/conformance/interfaces/pthread_mutexattr_setprotocol/0040755000000000000000000000000010515625222025512 5ustar rootrootposixtestsuite/conformance/interfaces/pthread_mutexattr_setprotocol/1-1.c0100644000000000000000000000354707660004677026176 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: bing.wei.liu REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_mutexattr_setprotocol() * * Sets the protocol attribute of a mutexattr object (which was prev. created * by the function pthread_mutexattr_init()). * * Steps: * 1. In a for loop, call pthread_mutexattr_setprotocol with all the valid 'protocol' values. * 2. In the for loop, then call pthread_mutexattr_getprotocol and ensure that the same * value that was set was the same value that was retrieved from this function. */ #include #include #include #include "posixtest.h" int main() { pthread_mutexattr_t mta; int protocol, protcls[3],i; /* Initialize a mutex attributes object */ if(pthread_mutexattr_init(&mta) != 0) { perror("Error at pthread_mutexattr_init()\n"); return PTS_UNRESOLVED; } protcls[0]=PTHREAD_PRIO_NONE; protcls[1]=PTHREAD_PRIO_INHERIT; protcls[2]=PTHREAD_PRIO_PROTECT; for(i=0;i<3;i++) { /* Set the protocol to one of the 3 valid protocols. */ if(pthread_mutexattr_setprotocol(&mta,protcls[i]) != 0) { printf("Error setting protocol to %d\n", protcls[i]); return PTS_UNRESOLVED; } /* Get the protocol mutex attr. */ if(pthread_mutexattr_getprotocol(&mta, &protocol) != 0) { fprintf(stderr,"Error obtaining the protocol attribute.\n"); return PTS_UNRESOLVED; } /* Make sure that the protocol set is the protocl we get when calling * pthread_mutexattr_getprocol() */ if(protocol != protcls[i]) { printf("Test FAILED: Set protocol %d, but instead got protocol %d.\n", protcls[i], protocol); return PTS_FAIL; } } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_mutexattr_setprotocol/2-2.sh0100755000000000000000000000075410015270666026357 0ustar rootroot#!/bin/sh # Copyright (c) 2002, Intel Corporation. All rights reserved. # Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com # This file is licensed under the GPL license. For the full content # of this license, see the COPYING file at the top level of this # source tree. # Upon success, it returns 0, and stores the value of the prioceiling in 'prioceiling'. # This is tested implicitly via assertion 1. echo "Tested implicitly via assertion 1. See output for status" exit 0 posixtestsuite/conformance/interfaces/pthread_mutexattr_setprotocol/3-2.c0100644000000000000000000000213007660004677026164 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: bing.wei.liu REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_mutexattr_setprotocol() * * It may fail if: * [EINVAL] The value specified by 'attr' is invalid. * * Steps: * 1. Call pthread_mutexattr_setprotocol with an uninitialized pthread_mutexattr_t object. */ #include #include #include #include #include "posixtest.h" int main() { pthread_mutexattr_t mta; int ret; /* Set the protocol to an invalid value. */ ret = pthread_mutexattr_setprotocol(&mta,PTHREAD_PRIO_NONE); if(ret == EINVAL) { printf("Test PASSED\n"); return PTS_PASS; } else if (ret == 0){ printf("Test PASSED: NOTE*: Expected error code EINVAL, got %d, though standard states 'may' fail.\n", ret); return PTS_PASS; } else { printf("Test FAILED: Incorrect return code %d. Expected EINVAL or 0.\n", ret); return PTS_FAIL; } } posixtestsuite/conformance/interfaces/pthread_mutexattr_setprotocol/assertions.xml0100644000000000000000000000137407660000753030433 0ustar rootroot The function int pthread_mutexattr_setprotocol(const pthread_mutexattr_t *restrict attr, int protocol); Sets the protocol attribute of a mutex attribute object which was prev. created by the function pthread_mutexattr_init(). Upon success, it returns 0. It Shall fail if: [ENOTSUP] The value specified by protocol is an unsupported value. If may fail if: [EINVAL] - 'attr' or 'protocol' is invalid. [EPERM] - The caller doesn't have the privilege to perform the operation. Shall not return error code of [EINTR]. posixtestsuite/conformance/interfaces/pthread_mutexattr_setprotocol/coverage.txt0100644000000000000000000000020207660004677030051 0ustar rootrootThis document defines the coverage for the pthread_mutexattr_getprotocol function: Assertion Tested? 1 YES 2 YES 3 YES NOTE: posixtestsuite/conformance/interfaces/pthread_mutexattr_setprotocol/3-1.c0100644000000000000000000000241607660004677026172 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: bing.wei.liu REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_mutexattr_setprotocol() * * It Shall fail if: * [ENOTSUP] The value specified by protocol is an unsupported value. * It may fail if: * [EINVAL] 'protocol' is invalid */ #include #include #include #include #include "posixtest.h" #define INVALID_PROTOCOL -1 int main() { pthread_mutexattr_t mta; int protocol = INVALID_PROTOCOL; int ret; /* Initialize a mutex attributes object */ if(pthread_mutexattr_init(&mta) != 0) { perror("Error at pthread_mutexattr_init()\n"); return PTS_UNRESOLVED; } while(protocol == PTHREAD_PRIO_NONE || protocol == PTHREAD_PRIO_INHERIT || protocol == PTHREAD_PRIO_PROTECT){ protocol--; } /* Set the protocol to an invalid value. */ ret = pthread_mutexattr_setprotocol(&mta,protocol); if((ret == ENOTSUP) || (ret == EINVAL)) { printf("Test PASSED\n"); return PTS_PASS; } else{ printf("Test FAILED: Expected error code ENOTSUP, got %d.\n", ret); return PTS_FAIL; } } posixtestsuite/conformance/interfaces/pthread_attr_getstack/0040755000000000000000000000000010515625177023670 5ustar rootrootposixtestsuite/conformance/interfaces/pthread_attr_getstack/1-1.c0100644000000000000000000000441010160323207024307 0ustar rootroot/* * Copyright (c) 2004, Intel Corporation. All rights reserved. * Created by: crystal.xiong REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test pthread_attr_getstack() * * Steps: * 1. Initialize pthread_attr_t object (attr) * 2. set the stackaddr and stacksize to attr * 3. get the stackaddr and stacksize */ #include #include #include #include #include #include #include #include #include "posixtest.h" #define TEST "1-1" #define FUNCTION "pthread_attr_getstack" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " int main() { pthread_attr_t attr; void *stack_addr; size_t stack_size; size_t ssize; void *saddr; int rc; /* Initialize attr */ rc = pthread_attr_init(&attr); if( rc != 0) { perror(ERROR_PREFIX "pthread_attr_init"); exit(PTS_UNRESOLVED); } /* Get the default stack_addr and stack_size value */ rc = pthread_attr_getstack(&attr, &stack_addr, &stack_size); if( rc != 0) { perror(ERROR_PREFIX "pthread_attr_getstack"); exit(PTS_UNRESOLVED); } printf("stack_addr = %p, stack_size = %zu\n", stack_addr, stack_size); stack_size = PTHREAD_STACK_MIN; if (posix_memalign (&stack_addr, sysconf(_SC_PAGE_SIZE), stack_size) != 0) { perror (ERROR_PREFIX "out of memory while " "allocating the stack memory"); exit(PTS_UNRESOLVED); } printf("stack_addr = %p, stack_size = %zu\n", stack_addr, stack_size); rc = pthread_attr_setstack(&attr, stack_addr, stack_size); if (rc != 0 ) { perror(ERROR_PREFIX "pthread_attr_setstack"); exit(PTS_UNRESOLVED); } rc = pthread_attr_getstack(&attr, &saddr, &ssize); if (rc != 0 ) { perror(ERROR_PREFIX "pthread_attr_getstack"); exit(PTS_UNRESOLVED); } printf("saddr = %p, ssize = %zu\n", saddr, ssize); rc = pthread_attr_destroy(&attr); if(rc != 0) { perror(ERROR_PREFIX "pthread_attr_destroy"); exit(PTS_UNRESOLVED); } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_attr_getstack/assertions.xml0100644000000000000000000000064510031765207026576 0ustar rootroot The pthread_attr_getstack() shall get the thread creation stack attributes stackaddr and stacksize in the attr ojbect. If success, it returns zero. Shall not return an error code of [EINTR] posixtestsuite/conformance/interfaces/pthread_attr_getstack/coverage.txt0100644000000000000000000000020410031765207026205 0ustar rootrootThis document defines the coverage for the pthread_attr_getstack function: Assertion Tested? 1 YES 2 YES 3 won't test Note: posixtestsuite/conformance/interfaces/pthread_attr_getstack/2-1.sh0100755000000000000000000000071010030774416024512 0ustar rootroot #!/bin/sh # Copyright (c) 2004, Intel Corporation. All rights reserved. # Created by: crystal.xiong REMOVE-THIS AT intel DOT com # This file is licensed under the GPL license. For the full content # of this license, see the COPYING file at the top level of this # source tree. # Test pthread_attr_getstack returns 0 on success. # This is tested implicitly via assertion 1. echo "Tested implicitly via assertion 1. See output for status" exit 0 posixtestsuite/conformance/interfaces/pthread_testcancel/0040755000000000000000000000000010515625230023144 5ustar rootrootposixtestsuite/conformance/interfaces/pthread_testcancel/1-1.c0100644000000000000000000001063007627740373023623 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test pthread_testcancel * Atomically sets the cancelability type to 'type' and returns the old * cancelability type in the location referenced by 'oldtype'. * 'state' can either be PTHREAD_CANCEL_DEFERRED, or PTHREAD_CANCEL_ASYNCHRONOUS. * * Test when a thread is PTHREAD_CANCEL_DEFERRED * * STEPS: * 1. Setup a mutex and lock it in main() * 2. Create a thread. * 3. In the thread function, set the type to PTHREAD_CANCEL_DEFERRED * 4. Setup a cleanup handler for the thread. * 5. Make the thread block on the locked mutex * 6. Send out a thread cancel request to the new thread, and unlock the mutex allowing the * thread to continue execution. * 7. If the cancel request was honored immediately, the * cleanup handler would have been executed, setting the cleanup_flag to -1, making the * test fail. * 8. If not, the thread will continue execution, pop the cleanup handler, set the cleanup * flag to 1, and call the cancelation point pthread_testcancel(). The test will pass. * 9. If the thread did not cancel at the cancelation point like it was supposed to, the thread * will continue execution and set the cleanup_flag to -2, failing the test. */ #include #include #include #include #include "posixtest.h" # define INTHREAD 0 /* Control going to or is already for Thread */ # define INMAIN 1 /* Control going to or is already for Main */ int sem1; /* Manual semaphore */ int cleanup_flag; /* Flag to indicate the thread's cleanup handler was called */ pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; /* Mutex */ /* Cleanup function that the thread executes when it is canceled. So if * cleanup_flag is 1, it means that the thread was canceled. */ void a_cleanup_func() { cleanup_flag=-1; return; } /* Function that the thread executes upon its creation */ void *a_thread_func() { pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL); pthread_cleanup_push(a_cleanup_func,NULL); /* Indicate to main() that the thread has been created. */ sem1=INMAIN; /* Lock the mutex. It should have already been locked in main, so the thread * should block. */ if(pthread_mutex_lock(&mutex) != 0) { perror("Error in pthread_mutex_lock()\n"); pthread_exit((void*)PTS_UNRESOLVED); return (void*)PTS_UNRESOLVED; } /* Should get here if the cancel request was deffered. */ pthread_cleanup_pop(0); cleanup_flag=1; /* Cancelation point. Cancel request should not be honored here. */ pthread_testcancel(); /* Should not get here if the cancel request was honored at the cancelation point * pthread_testcancel(). */ cleanup_flag=-2; pthread_exit(0); return NULL; } int main() { pthread_t new_th; /* Initializing values */ sem1=INTHREAD; cleanup_flag=0; /* Lock the mutex */ if(pthread_mutex_lock(&mutex) != 0) { perror("Error in pthread_mutex_lock()\n"); return PTS_UNRESOLVED; } /* Create a new thread. */ if(pthread_create(&new_th, NULL, a_thread_func, NULL) != 0) { perror("Error creating thread\n"); return PTS_UNRESOLVED; } /* Make sure thread is created before we cancel it. (wait for * a_thread_func() to set sem1=INMAIN.) */ while(sem1==INTHREAD) sleep(1); /* Send cancel request to the thread. */ if(pthread_cancel(new_th) != 0) { printf("Test FAILED: Couldn't cancel thread\n"); return PTS_FAIL; } /* Cancel request has been sent, unlock the mutex */ if(pthread_mutex_unlock(&mutex) != 0) { perror("Error in pthread_mutex_unlock()\n"); return PTS_UNRESOLVED; } /* Wait 'till the thread has been canceled or has ended execution. */ if(pthread_join(new_th, NULL) != 0) { perror("Error in pthread_join()\n"); return PTS_UNRESOLVED; } /* This means that the cleanup function wasn't called, so the cancel * request was not honord immediately like it should have been. */ if(cleanup_flag == -1) { perror("Cancel request was not deferred.\n"); return PTS_UNRESOLVED; } if(cleanup_flag == -2) { printf("Test FAILED:pthread_testcancel() not treated as a cancelation point.\n"); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_testcancel/assertions.xml0100644000000000000000000000053207627240715026070 0ustar rootroot The function void pthread_testcancel(void); It will create a cancelation point in the calling thread. It will have no affect on the calling thread if cancelability is disabled. posixtestsuite/conformance/interfaces/pthread_testcancel/coverage.txt0100644000000000000000000000015207627740373025513 0ustar rootrootThis document defines the coverage for the pthread_testcancel function: Assertion Tested? 1 YES 2 YES posixtestsuite/conformance/interfaces/pthread_testcancel/2-1.c0100644000000000000000000000564507627740373023636 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test pthread_cancelstate * It will have no affect on the calling thread if cancelability is disabled. * * STEPS: * 1. Create a thread. * 2. In the thread function, set the state to * PTHREAD_CANCEL_DISABLE and the cancel_flag to -1. * 3. Send out a thread cancel request to the new thread * 4. If the cancel request was honored, the cancel_flag will remain -1. * 5. If not, the thread will continue until the end of execution, cancel_flag will be set to 1 * and,therefore passing the test. */ #include #include #include #include #include "posixtest.h" # define INTHREAD 0 /* Control going to or is already for Thread */ # define INMAIN 1 /* Control going to or is already for Main */ int sem1; /* Manual semaphore */ int cancel_flag; /* Function that the thread executes upon its creation */ void *a_thread_func() { /* Set cancel state to DISABLE, meaning it shouldn't honor any cancel requests. */ pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL); cancel_flag=-1; /* Indicate to main() that the thread has been created. */ sem1=INMAIN; /* Wait until main() has sent out a cancel request, meaning until it * sets sem1==INTHREAD. */ while(sem1==INMAIN) sleep(1); /* If the thread incorrectly honors the cancel request, then the cancel_flag will * remain -1. If it contiues on with the thread execution, then the cancel_flag * will be 1, and therefore passing this test. */ pthread_testcancel(); /* Should reach here if the thread correctly ignores the cancel * request. */ cancel_flag=1; pthread_exit(0); return NULL; } int main() { pthread_t new_th; /* Initializing values */ sem1=INTHREAD; cancel_flag=0; /* Create a new thread. */ if(pthread_create(&new_th, NULL, a_thread_func, NULL) != 0) { perror("Error creating thread\n"); return PTS_UNRESOLVED; } /* Make sure thread is created before we cancel it. (wait for * a_thread_func() to set sem1=INMAIN.) */ while(sem1==INTHREAD) sleep(1); if(pthread_cancel(new_th) != 0) { perror("Error sending cancel request\n"); return PTS_UNRESOLVED; } /* Indicate to the thread function that the thread cancel request * has been sent to it. */ sem1=INTHREAD; /* Wait for thread to end execution. */ if(pthread_join(new_th, NULL) != 0) { perror("Error in pthread_join()\n"); return PTS_UNRESOLVED; } /* This means that the cancel request was honored rather than ignored, and * the test fails. */ if(cancel_flag <= 0) { printf("Test FAILED: pthread_testcancel() was honored even though cancelability was disabled.\n"); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_rwlock_tryrdlock/0040755000000000000000000000000010515625225024421 5ustar rootrootposixtestsuite/conformance/interfaces/pthread_rwlock_tryrdlock/3-1.sh0100755000000000000000000000105707671426232025266 0ustar rootroot#!/bin/sh # Copyright (c) 2002, Intel Corporation. All rights reserved. # This file is licensed under the GPL license. For the full content # of this license, see the COPYING file at the top level of this # source tree. #The pthread_rwlock_tryrdlock( ) function shall fail if: #[EBUSY] The read-write lock could not be acquired for reading because a writer holds #the lock or a writer with the appropriate priority was blocked on it. # This is tested implicitly via assertion 1. echo "Tested implicitly via assertion 1. See output for status" exit 0 posixtestsuite/conformance/interfaces/pthread_rwlock_tryrdlock/1-1.c0100644000000000000000000001224607671426232025073 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_rwlock_tryrdlock(pthread_rwlock_t *rwlock) * * The pthread_rwlock_tryrdlock( ) function shall apply a read lock as in the * pthread_rwlock_rdlock( ) * function, with the exception that the function shall fail if the * equivalent pthread_rwlock_rdlock( ) * call would have blocked the calling thread. In no case shall the * pthread_rwlock_tryrdlock( ) * function ever block; it always either acquires the lock or fails and * returns immediately. * * Steps: * 1. Initialize a pthread_rwlock_t object 'rwlock' with pthread_rwlock_init() * 2. Main thread read lock 'rwlock' * 3. Create a child thread, the thread read lock 'rwlock' using pthread_rwlock_tryrdlock(), should success * 4. Main thread unlock 'rwlock' * 5. Main thread write lock 'rwlock' * 6. Create child thread to read lock 'rwlock' with pthread_rwlock_tryrdlock(), should not block and get EBUSY * 7. Main thread unlock 'rwlock' */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include "posixtest.h" static pthread_rwlock_t rwlock; static int thread_state; /* thread_state indicates child thread state: 1: not in child thread yet; 2: just enter child thread ; 3: just before child thread exit; */ #define NOT_CREATED_THREAD 1 #define ENTERED_THREAD 2 #define EXITING_THREAD 3 static void* fn_rd_1(void *arg) { int rc = 0; thread_state = ENTERED_THREAD; printf("rd_thread1: attempt pthread_rwlock_tryrdlock\n"); rc = pthread_rwlock_tryrdlock(&rwlock); if(rc != 0) { printf("Test fail at pthread_rwlock_tryrdlock(): error code: %d\n", rc); exit(PTS_FAIL); } printf("rd_thread1: acquired read lock\n"); printf("rd_thread1: unlock read lock\n"); if(pthread_rwlock_unlock(&rwlock) != 0) { printf("Error at pthread_rwlock_unlock()\n"); exit(PTS_UNRESOLVED); } thread_state = EXITING_THREAD; return NULL; } static void* fn_rd_2(void *arg) { int ret; thread_state = ENTERED_THREAD; printf("rd_thread2: attempt pthread_rwlock_tryrdlock\n"); ret = pthread_rwlock_tryrdlock(&rwlock); if(ret != EBUSY) { printf("Test FAILED: expected EBUSY, got %d\n", ret); exit(PTS_FAIL); } printf("rd_thread2: Correctly got EBUSY\n"); thread_state = EXITING_THREAD; return NULL; } int main() { int cnt = 0; int rc = 0; pthread_t rd_thread1, rd_thread2; if(pthread_rwlock_init(&rwlock, NULL) != 0) { printf("main: Error at pthrad_rwlock_init()\n"); return PTS_UNRESOLVED; } printf("main: attempt pthread_rwlock_tryrdlock\n"); /* We have no lock, this read lock should succeed */ rc = pthread_rwlock_tryrdlock(&rwlock); if(rc != 0) { printf("Test FAILED: in main() at pthread_rwlock_tryrdlock, error code:%d\n", rc); return PTS_FAIL; } printf("main: acquired read lock\n"); thread_state = NOT_CREATED_THREAD; printf("main: create rd_thread1\n"); if(pthread_create(&rd_thread1, NULL, fn_rd_1, NULL) != 0) { printf("main: Error at creating rd_thread1\n"); return PTS_UNRESOLVED; } /* If the shared data is not altered by child after 5 seconds, we regard it as blocked */ /* We did not expect the thread to block */ cnt = 0; do{ sleep(1); }while (thread_state !=EXITING_THREAD && cnt++ < 3); if(thread_state == ENTERED_THREAD) { /* the child thread started but blocked */ printf("Test FAILED: rd_thread1 block at pthread_rwlock_tryrdlock()\n"); return PTS_FAIL; } else if(thread_state != EXITING_THREAD) { printf("Unexpected thread state for rd_thread1: %d\n", thread_state); return PTS_UNRESOLVED; } printf("main: unlock read lock\n"); if(pthread_rwlock_unlock(&rwlock) != 0) { printf("main: Error at pthread_rwlock_unlock\n"); return PTS_UNRESOLVED; } if(pthread_join(rd_thread1, NULL) != 0) { printf("main: Error joining rd_thread1\n"); return PTS_UNRESOLVED; } printf("main: attempt write lock\n"); if(pthread_rwlock_wrlock(&rwlock) != 0) { printf("main: Error getting write lock\n"); return PTS_UNRESOLVED; } printf("main: acquired write lock\n"); thread_state = NOT_CREATED_THREAD; cnt = 0; printf("main: create rd_thread2\n"); if(pthread_create(&rd_thread2, NULL, fn_rd_2, NULL) != 0) { printf("main: Error at creating rd_thread2\n"); return PTS_UNRESOLVED; } /* we do not expect rd_thread2 to block */ do{ sleep(1); }while (thread_state !=EXITING_THREAD && cnt++ < 3); if(thread_state == ENTERED_THREAD) { printf("Test FAILED: pthread_rwlock_trylock() should not block rd_thread2\n"); return PTS_FAIL; } else if(thread_state != EXITING_THREAD) { printf("Unexpected thread state for rd_thread2\n"); return PTS_UNRESOLVED; } printf("main: unlock write lock\n"); thread_state = NOT_CREATED_THREAD; if(pthread_rwlock_unlock(&rwlock) != 0) { printf("main: Error at releasing write lock\n"); return PTS_UNRESOLVED; } if(pthread_rwlock_destroy(&rwlock) != 0) { printf("Error at pthread_rwlockattr_destroy()\n"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_rwlock_tryrdlock/assertions.xml0100644000000000000000000000213407671426232027340 0ustar rootroot The pthread_rwlock_tryrdlock( ) function shall apply a read lock as in the pthread_rwlock_rdlock( ) function, with the exception that the function shall fail if the equivalent pthread_rwlock_rdlock( ) call would have blocked the calling thread. In no case shall the pthread_rwlock_tryrdlock( ) function ever block; it always either acquires the lock or fails and returns immediately. The pthread_rwlock_tryrdlock( ) function shall return zero if the lock for reading on the read-write lock object referenced by rwlock is acquired. Otherwise, an error number shall be returned to indicate the error. The pthread_rwlock_tryrdlock( ) function shall fail if: [EBUSY] The read-write lock could not be acquired for reading because a writer holds the lock or a writer with the appropriate priority was blocked on it. The function shall not return an error code of [EINTR]. posixtestsuite/conformance/interfaces/pthread_rwlock_tryrdlock/coverage.txt0100644000000000000000000000017707671426232026765 0ustar rootrootThis document defines the coverage for the pthread_rwlock_tryrdlock() function: Assertion Tested? 1 YES 2 YES 3 YES NOTE: posixtestsuite/conformance/interfaces/pthread_rwlock_tryrdlock/2-1.sh0100755000000000000000000000062007671426232025260 0ustar rootroot#!/bin/sh # Copyright (c) 2002, Intel Corporation. All rights reserved. # This file is licensed under the GPL license. For the full content # of this license, see the COPYING file at the top level of this # source tree. # Test pthread_rwlock_tryrdlock() returns 0 on success. # This is tested implicitly via assertion 1. echo "Tested implicitly via assertion 1. See output for status" exit 0 posixtestsuite/conformance/interfaces/sem_timedwait/0040755000000000000000000000000010515625236022151 5ustar rootrootposixtestsuite/conformance/interfaces/sem_timedwait/2-2.c0100644000000000000000000000330207634220622022606 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: majid.awad REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * This test case will verify that sem_timedwait will wait one second to * unlock the locked semaphore, and then when the semaphore fails to * unlock should return -1, and leave the semaphore status unchanged * by doing sem_post on the sempahore and check the current value of * the semaphore. */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include #include "posixtest.h" #define TEST "2-2" #define FUNCTION "sem_timedwait" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " int main() { sem_t mysemp; struct timespec ts; int sts, val; if ( sem_init (&mysemp, 0, 0) == -1 ) { perror(ERROR_PREFIX "sem_init"); return PTS_UNRESOLVED; } ts.tv_sec=time(NULL)+1; ts.tv_nsec=0; /* Try to lock Semaphore */ sts = sem_timedwait(&mysemp, &ts); if ( sem_post(&mysemp) == -1 ) { perror(ERROR_PREFIX "sem_post"); return PTS_UNRESOLVED; } if( sem_getvalue(&mysemp, &val) == -1 ) { perror(ERROR_PREFIX "sem_getvalue"); return PTS_UNRESOLVED; } if ((val == 1) && (sts == -1)) { puts("TEST PASSED"); sem_destroy(&mysemp); return PTS_PASS; } else { puts("TEST FAILED"); return PTS_FAIL; } } posixtestsuite/conformance/interfaces/sem_timedwait/6-2.c0100644000000000000000000000236007634220622022615 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: majid.awad REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * The process would be blocked, and the timeout parameter is * secified in nanoseconds field value greater than or equal to * 1000 million. Should return ERROR (EINVAL). */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include #include "posixtest.h" #define TEST "5-1" #define FUNCTION "sem_timedwait" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " #define NANOSEC 1000000000 int main() { sem_t mysemp; struct timespec ts; int sts; if ( sem_init (&mysemp, 0, 0) == -1 ) { perror(ERROR_PREFIX "sem_init"); return PTS_UNRESOLVED; } ts.tv_sec=time(NULL); ts.tv_nsec= NANOSEC; sts = sem_timedwait(&mysemp, &ts); if(( errno == EINVAL) && ( sts == -1)) { puts("TEST PASSED"); sem_destroy(&mysemp); return PTS_PASS; } else { puts("TEST FAILED"); return PTS_FAIL; } } posixtestsuite/conformance/interfaces/sem_timedwait/4-1.c0100644000000000000000000000261507634220622022615 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: majid.awad REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* sem_timedwait shall return zero if the calling process successfully * performed the semaphore lock operation on the semaphore designated * by sem. */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include #include "posixtest.h" #define TEST "4-1" #define FUNCTION "sem_timedwait" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " int main() { sem_t mysemp; struct timespec ts; int unresolved=0, sts; if ( sem_init (&mysemp, 0, 1) == -1 ) { perror(ERROR_PREFIX "sem_init"); unresolved=1; } ts.tv_sec=time(NULL)+1; ts.tv_nsec=0; /* Lock Semaphore */ sts = sem_timedwait(&mysemp, &ts); if ( sts == -1 ) { perror(ERROR_PREFIX "sem_timedwait"); unresolved=1; } /* unlock Semaphore */ if( sem_post(&mysemp) == -1 ) { perror(ERROR_PREFIX "sem_post"); unresolved=1; } if (( sts == 0) && (unresolved == 0)) { puts("TEST PASSED"); sem_destroy(&mysemp); return PTS_PASS; } else { puts("TEST FAILED"); return PTS_FAIL; } } posixtestsuite/conformance/interfaces/sem_timedwait/1-1.c0100644000000000000000000000270407634220621022610 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: majid.awad REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * sem_timedwait shall lock the unlocked semaphore and decrement the * semaphore * value by one. */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include #include "posixtest.h" #define TEST "1-1" #define FUNCTION "sem_timedwait" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " int main() { sem_t mysemp; struct timespec ts; int val, sts; if ( sem_init (&mysemp, 0, 1) == -1 ) { perror(ERROR_PREFIX "sem_init"); return PTS_UNRESOLVED; } ts.tv_sec=time(NULL); ts.tv_nsec=0; /* Lock Semaphore */ sts = sem_timedwait(&mysemp, &ts); if ( sts == -1 ) { perror(ERROR_PREFIX "sem_timedwait"); return PTS_UNRESOLVED; } /* Value of Semaphore */ if( sem_getvalue(&mysemp, &val) == -1 ) { perror(ERROR_PREFIX "sem_getvalue"); return PTS_UNRESOLVED; } /* Checking if the value of the Semaphore decremented by one */ if(( val == 0 ) && ( sts == 0)) { puts("TEST PASSED"); sem_destroy(&mysemp); return PTS_PASS; } else { puts("TEST FAILED"); return PTS_FAIL; } } posixtestsuite/conformance/interfaces/sem_timedwait/9-1.c0100644000000000000000000000506107634220622022620 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: majid.awad REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* This tests case will send a SIGABRT to sem_timedwait, and should * return error EINTR. */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include #include #include #include "posixtest.h" #define TEST "9-1" #define FUNCTION "sem_timedwait" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " #define CHILDPASS 1 #define CHILDFAIL 0 void handler(int signo) { printf("In handler\n"); } int main() { sem_t mysemp; struct timespec ts; int pid, status; if ( sem_init (&mysemp, 0, 1) == -1 ) { perror(ERROR_PREFIX "sem_init"); return PTS_UNRESOLVED; } if( sem_wait(&mysemp) == -1 ) { perror(ERROR_PREFIX "sem_wait"); return PTS_UNRESOLVED; } pid = fork(); if (pid == 0) { // child create the semaphore. struct sigaction act; act.sa_handler=handler; act.sa_flags=0; if (sigemptyset(&act.sa_mask) == -1) { perror("Error calling sigemptyset\n"); return CHILDFAIL; } if (sigaction(SIGABRT, &act, 0) == -1) { perror("Error calling sigaction\n"); return CHILDFAIL; } ts.tv_sec = time(NULL)+3; ts.tv_nsec = 0; sem_timedwait(&mysemp, &ts); if (errno == EINTR) { printf("Test PASSED\n"); return (CHILDPASS); } puts("TEST FAILED: errno != EINTR"); return (CHILDFAIL); } else { // parent to send a signal to child int i; sleep(1); status = kill(pid,SIGABRT); // send signal to child if (wait(&i) == -1) { perror("Error waiting for child to exit\n"); return PTS_UNRESOLVED; } if (!WEXITSTATUS(i)) { return PTS_FAIL; } puts("TEST PASSED"); return PTS_PASS; } return PTS_UNRESOLVED; } posixtestsuite/conformance/interfaces/sem_timedwait/11-1.c0100644000000000000000000000357110023271460022665 0ustar rootroot/* * Copyright (c) 2003, 2004, Intel Corporation. All rights reserved. * Created by: crystal.xiong REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * Under no circumstance shall the function fail with a timeout if * the semaphore can be locked immediately. The validity of the * abs_timeout need not be checked if the semaphore can be locked * immediately. */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include #include "posixtest.h" #define TIMEOUT 2 #define INVALIDTIMEOUT -2 #define TEST "11-1" #define FUNCTION "sem_timedwait" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " int main() { sem_t mysemp[2]; struct timespec ts[2]; int val[2], sts[2]; int i; for ( i = 0; i < 2; i++ ) { if ( sem_init (&mysemp[i], 0, 1) == -1 ) { perror(ERROR_PREFIX "sem_init"); return PTS_UNRESOLVED; } if ( i == 0 ) { ts[i].tv_sec=time(NULL) + TIMEOUT; ts[i].tv_nsec=0; } else if ( i == 1 ) { ts[i].tv_sec=time(NULL) + INVALIDTIMEOUT; ts[i].tv_nsec=0; } /* Lock Semaphore */ sts[i] = sem_timedwait(&mysemp[i], &ts[i]); if ( sts[i] == -1 ) { perror(ERROR_PREFIX "sem_timedwait"); return PTS_UNRESOLVED; } /* Value of Semaphore */ if( sem_getvalue(&mysemp[i], &val[i]) == -1 ) { perror(ERROR_PREFIX "sem_getvalue"); return PTS_UNRESOLVED; } /* Checking if the value of the Semaphore decremented by one */ if(( val[i] == 0 ) && ( sts[i] == 0)) { puts("TEST PASSED"); sem_destroy(&mysemp[i]); return PTS_PASS; } else { puts("TEST FAILED"); sem_destroy(&mysemp[i]); return PTS_FAIL; } } } posixtestsuite/conformance/interfaces/sem_timedwait/6-1.c0100644000000000000000000000227107634220622022615 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: majid.awad REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * The process would be blocked, and the timeout parameter is * secified in nanoseconds field value less than zero. Should * return ERROR (EINVAL). */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include #include "posixtest.h" #define TEST "6-1" #define FUNCTION "sem_timedwait" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " int main() { sem_t mysemp; struct timespec ts; int sts; if ( sem_init (&mysemp, 0, 0) == -1 ) { perror(ERROR_PREFIX "sem_init"); return PTS_UNRESOLVED; } ts.tv_sec=time(NULL); ts.tv_nsec= -3; sts = sem_timedwait(&mysemp, &ts); if((errno == EINVAL) && ( sts == -1)) { puts("TEST PASSED"); sem_destroy(&mysemp); return PTS_PASS; } else { puts("TEST FAILED"); return PTS_FAIL; } } posixtestsuite/conformance/interfaces/sem_timedwait/10-1.c0100644000000000000000000000362710035215667022700 0ustar rootroot/* * Copyright (c) 2004, Intel Corporation. All rights reserved. * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * * adam.li@intel.com * If the Timers option is supported, the timeout shall be based on * the CLOCK_REALTIME clock. If the Timers option is not supported, * the timeout shall be based on the system clock as returned by * the time() function. * */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include #include "posixtest.h" #define TEST "10-1" #define FUNCTION "sem_timedwait" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " #define SLEEP_SEC 1 int main() { sem_t mysemp; struct timespec ts, ts_2; int rc; /* Init the value to 0 */ if ( sem_init (&mysemp, 0, 0) == -1 ) { perror(ERROR_PREFIX "sem_init"); return PTS_UNRESOLVED; } /* Set the abs timeout */ #ifdef CLOCK_REALTIME printf("Test CLOCK_REALTIME\n"); if (clock_gettime(CLOCK_REALTIME, &ts) != 0) { perror("clock_gettime()"); return PTS_UNRESOLVED; } ts.tv_sec += SLEEP_SEC; ts.tv_nsec=0; #else ts.tv_sec=time(NULL); ts.tv_sec += SLEEP_SEC; ts.tv_nsec=0; #endif /* Lock Semaphore */ rc = sem_timedwait(&mysemp, &ts); if ( rc != -1 || (rc == -1 && errno != ETIMEDOUT)) { perror(ERROR_PREFIX "sem_timedwait"); printf("Expect timedout\n"); return PTS_UNRESOLVED; } /* Check the time */ #ifdef CLOCK_REALTIME if (clock_gettime(CLOCK_REALTIME, &ts_2) != 0) { perror("clock_gettime()"); return PTS_UNRESOLVED; } #else ts_2.tv_sec = time(NULL); #endif if(ts_2.tv_sec == ts.tv_sec) { puts("TEST PASSED"); sem_destroy(&mysemp); return PTS_PASS; } else { puts("TEST FAILED"); return PTS_FAIL; } } posixtestsuite/conformance/interfaces/sem_timedwait/7-1.c0100644000000000000000000000245007634220622022615 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: majid.awad REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* This tests case will open a locked semaphore. The time will tick 5 times * until the absolute time passes. The sempahore will unlock, then the * sem_timedwait call will immediately lock again. */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include #include #include #include #include "posixtest.h" #define TEST "7-1" #define FUNCTION "sem_timedwait" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " int main(){ struct timespec ts; sem_t mysemp; if ( sem_init (&mysemp, 0, 0) == -1 ) { perror(ERROR_PREFIX "sem_init"); return PTS_UNRESOLVED; } ts.tv_sec=time(NULL); ts.tv_nsec=0; while (sem_timedwait(&mysemp, &ts) == -1 ) { if (errno == ETIMEDOUT) { puts("TEST PASSED"); sem_destroy(&mysemp); return PTS_PASS; } else { puts("TEST FAILED"); return PTS_FAIL; } return PTS_UNRESOLVED; } return PTS_UNRESOLVED; } posixtestsuite/conformance/interfaces/sem_timedwait/assertions.xml0100644000000000000000000000502210117555070025055 0ustar rootroot sem_timedwait will lock the unlocked semaphore. if the sempahore can't be locked without waiting for another process or thread to unlock the semaphore by performing sem_post function. This wait shall be terminated when the specified timout expires. The timeout shall expire when the absolute time specified by abs_timeout passes, as measured by the clock on which timeouts are based, or if the absolute time specified by abs_timeout has already been passed at the time of the call. sem_timedwait function shall return zero if the calling process successfully performed the semaphore lock. Return -1 if the call unsuccessful which shall keep the state of the semaphore unchanged. The sem_timedout function shall fail with: EINVAL Error: SEM argument doesn't refer to a valid semaphore. The sem_timedout function shall fail with: EINVAL Error: The process or thread would have blocked, and the abs_timeout parameter specified a nanoseconds field value less than zero or greater than or equal to 1000 million. The sem_timedout function shall fail with: ETIMEDOUT Error: The semaphore could not be locked before the specified timeout expired. The sem_timedout function may fail with: EDEADLK Error: A deadlock condition was detected. The sem_timedout function may fail with: EINTR Error: A signal interrupted this function. If the Timers option is supported, the timeout shall be based on the CLOCK_REALTIME clock. If the Timers option is not supported, the timeout shall be based on the system clock as returned by the time() function. The resolution of the timeout shall be the resolution of the clock on which it is based. Under no circumstance shall the function fail with a timeout if the semaphore can be locked immediately. The validity of the abs_timeout need not be checked if the semaphore can be locked immediately. posixtestsuite/conformance/interfaces/sem_timedwait/coverage.txt0100644000000000000000000000031410035215667024500 0ustar rootroot This file defines the coverage for sem_timedwait ASSERTION COVERED? 1 YES 2 YES 3 YES 4 YES 5 NO 6 YES 7 YES 8 WON'T -- couldn't figure out away of doing it. 9 YES 10 YES 11 YES ~ posixtestsuite/conformance/interfaces/sem_timedwait/2-1.c0100644000000000000000000000322307636705223022616 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: majid.awad REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* sem_timedwait will return successfully when sem_post * will unlock the semaphore from another process. */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include #include #include #include "posixtest.h" #define TEST "2-1" #define FUNCTION "sem_timedwait" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " int main() { sem_t mysemp; struct timespec ts; int pid; /* Semaphore started out locked */ if ( sem_init (&mysemp, 0, 0) == -1 ) { perror(ERROR_PREFIX "sem_init"); return PTS_UNRESOLVED; } pid = fork(); if (pid == 0) // child to lock semaphore { ts.tv_sec=time(NULL)+2; ts.tv_nsec=0; if( sem_timedwait(&mysemp, &ts) == -1 ) { puts ("TEST FAILED"); return PTS_FAIL; } else { puts("TEST PASSED"); sem_destroy(&mysemp); return PTS_PASS; } } else if (pid > 0) // parent to unlock semaphore { int i; sleep(1); if (sem_post(&mysemp) == -1 ) { perror(ERROR_PREFIX "sem_post"); return PTS_FAIL; } if (wait(&i) == -1) { perror("Error waiting for child to exit"); return PTS_UNRESOLVED; } if (!WEXITSTATUS(i)) { return PTS_FAIL; } puts("TEST PASSED"); sem_destroy(&mysemp); return PTS_PASS; } return PTS_UNRESOLVED; } posixtestsuite/conformance/interfaces/sem_timedwait/3-1.c0100644000000000000000000000315007634220622022607 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: majid.awad REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* This tests case will open a locked semaphore. The time will tick 5 times * until the absolute time passes. The sempahore will unlock, then the * sem_timedwait call will immediately lock again. */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include #include #include #include "posixtest.h" #define TEST "3-1" #define FUNCTION "sem_timedwait" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " int main(){ struct timespec ts; sem_t mysemp; int i=0; int val; if ( sem_init (&mysemp, 0, 0) == -1 ) { perror(ERROR_PREFIX "sem_init"); return PTS_UNRESOLVED; } ts.tv_sec=time(NULL); ts.tv_nsec=0; while (sem_timedwait(&mysemp, &ts) == -1 ) { ts.tv_sec += 1; // printf("%s \n", asctime(localtime(&ts.tv_sec))); i++; // printf("i=%d\n",i); if (i==5) { sem_post(&mysemp); } } /* Value of Semaphore */ if( sem_getvalue(&mysemp, &val) == -1 ) { perror(ERROR_PREFIX "sem_getvalue"); return PTS_UNRESOLVED; } /* Checking if the value of the Semaphore after lock & unlock */ if( val == 0 ) { puts("TEST PASSED: Sem unlocked after 5 timeouts"); sem_destroy(&mysemp); return PTS_PASS; } else { puts("TEST FAILED"); return PTS_FAIL; } } posixtestsuite/conformance/interfaces/nanosleep/0040755000000000000000000000000010515625176021305 5ustar rootrootposixtestsuite/conformance/interfaces/nanosleep/5-1.c0100644000000000000000000000155507575215635021765 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that nanosleep() returns -1 on failure. * Simulate failure condition by sending -1 as the nsec to sleep for. */ #include #include #include "posixtest.h" int main(int argc, char *argv[]) { struct timespec tssleepfor, tsstorage; int sleepnsec = -1; tssleepfor.tv_sec=0; tssleepfor.tv_nsec=sleepnsec; if (nanosleep(&tssleepfor, &tsstorage) == -1) { printf("Test PASSED\n"); return PTS_PASS; } else { printf("nanosleep() did not return -1 on failure\n"); return PTS_FAIL; } printf("This code should not be executed.\n"); return PTS_UNRESOLVED; } posixtestsuite/conformance/interfaces/nanosleep/5-2.c0100644000000000000000000000343007640675653021763 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that nanosleep() returns -1 if interrupted. * Test by sending a signal to a child doing nanosleep(). If nanosleep * returns -1, return success from the child. */ #include #include #include #include #include #include "posixtest.h" #define CHILDSUCCESS 1 #define CHILDFAILURE 0 void handler(int signo) { printf("In handler\n"); } int main(int argc, char *argv[]) { struct timespec tssleepfor, tsstorage; int sleepsec = 30; int pid; struct sigaction act; if ((pid = fork()) == 0) { /* child here */ act.sa_handler=handler; act.sa_flags=0; if (sigemptyset(&act.sa_mask) == -1) { perror("Error calling sigemptyset\n"); return CHILDFAILURE; } if (sigaction(SIGABRT, &act, 0) == -1) { perror("Error calling sigaction\n"); return CHILDFAILURE; } tssleepfor.tv_sec=sleepsec; tssleepfor.tv_nsec=0; if (nanosleep(&tssleepfor, &tsstorage) == -1) { return CHILDSUCCESS; } else { return CHILDFAILURE; } return CHILDFAILURE; } else { /* parent here */ int i; sleep(1); if (kill(pid, SIGABRT) != 0) { printf("Could not raise signal being tested\n"); return PTS_UNRESOLVED; } if (wait(&i) == -1) { perror("Error waiting for child to exit\n"); return PTS_UNRESOLVED; } if (WIFEXITED(i) && WEXITSTATUS(i)) { printf("Test PASSED\n"); return PTS_PASS; } else { printf("Child did not exit normally.\n"); printf("Test FAILED\n"); return PTS_FAIL; } } return PTS_UNRESOLVED; } posixtestsuite/conformance/interfaces/nanosleep/1-3.c0100644000000000000000000000404507575215635021760 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that nanosleep() causes the current thread to be suspended * until a signal whose action is to invoke a signal handling function * is received. */ #include #include #include #include #include #include "posixtest.h" void handler(int signo) { printf("In handler\n"); } int main(int argc, char *argv[]) { struct timespec tssleepfor, tsstorage, tsbefore, tsafter; int sleepsec = 30; int pid; struct sigaction act; if (clock_gettime(CLOCK_REALTIME, &tsbefore) == -1) { perror("Error in clock_gettime()\n"); return PTS_UNRESOLVED; } if ((pid = fork()) == 0) { /* child here */ act.sa_handler=handler; act.sa_flags=0; if (sigemptyset(&act.sa_mask) == -1) { perror("Error calling sigemptyset\n"); return PTS_UNRESOLVED; } if (sigaction(SIGABRT, &act, 0) == -1) { perror("Error calling sigaction\n"); return PTS_UNRESOLVED; } tssleepfor.tv_sec=sleepsec; tssleepfor.tv_nsec=0; nanosleep(&tssleepfor, &tsstorage); } else { /* parent here */ int i; sleep(1); if (kill(pid, SIGABRT) != 0) { printf("Could not raise signal being tested\n"); return PTS_UNRESOLVED; } if (wait(&i) == -1) { perror("Error waiting for child to exit\n"); return PTS_UNRESOLVED; } if (clock_gettime(CLOCK_REALTIME, &tsafter) == -1) { perror("Error in clock_gettime()\n"); return PTS_UNRESOLVED; } /* * pass if we slept for less than the (large) sleep time * allotted */ if ( (tsafter.tv_sec-tsbefore.tv_sec) < sleepsec) { printf("Test PASSED\n"); return PTS_PASS; } else { printf("Slept for too long: %d >= %d\n", (int)tsafter.tv_sec-(int)tsbefore.tv_sec, sleepsec); printf("Test FAILED\n"); return PTS_FAIL; } } return PTS_UNRESOLVED; } posixtestsuite/conformance/interfaces/nanosleep/1-1.c0100644000000000000000000000272507575215635021761 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that nanosleep() causes the current thread to be suspended * until the time interval in rqtp passes. */ #include #include #include "posixtest.h" int main(int argc, char *argv[]) { struct timespec tssleepfor, tsstorage, tsbefore, tsafter; int sleepnsec = 3; int slepts=0,sleptns=0; if (clock_gettime(CLOCK_REALTIME, &tsbefore) == -1) { perror("Error in clock_gettime()\n"); return PTS_UNRESOLVED; } tssleepfor.tv_sec=0; tssleepfor.tv_nsec=sleepnsec; if (nanosleep(&tssleepfor, &tsstorage) != 0) { printf("nanosleep() did not return success\n"); return PTS_UNRESOLVED; } if (clock_gettime(CLOCK_REALTIME, &tsafter) == -1) { perror("Error in clock_gettime()\n"); return PTS_UNRESOLVED; } /* * Generic alg for calculating slept time. */ slepts=tsafter.tv_sec-tsbefore.tv_sec; sleptns=tsafter.tv_nsec-tsbefore.tv_nsec; if (sleptns < 0) { sleptns = sleptns+1000000000; slepts = slepts-1; } if ((slepts > 0) || (sleptns > sleepnsec)) { printf("Test PASSED\n"); return PTS_PASS; } else { printf("nanosleep() did not sleep long enough\n"); return PTS_FAIL; } printf("This code should not be executed.\n"); return PTS_UNRESOLVED; } posixtestsuite/conformance/interfaces/nanosleep/6-1.c0100644000000000000000000000226407575215635021764 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that nanosleep() sets errno to EINVAL if rqtp contained a * nanosecond value < 0 or >= 1,000 million */ #include #include #include #include "posixtest.h" #define NUMTESTS 7 int main(int argc, char *argv[]) { struct timespec tssleepfor, tsstorage; int sleepnsec[NUMTESTS] = {-1, -5, -1000000000, 1000000000, 1000000001, 2000000000, 2000000000 }; int i; int failure = 0; tssleepfor.tv_sec=0; for (i=0; i #include #include #include #include #include #include "posixtest.h" #define SLEEPSEC 5 #define CHILDPASS 0 //if interrupted, child will return 0 #define CHILDFAIL 1 int main(int argc, char *argv[]) { int pid, slepts; struct timespec tsbefore, tsafter; if (clock_gettime(CLOCK_REALTIME, &tsbefore) != 0) { perror("clock_gettime() did not return success\n"); return PTS_UNRESOLVED; } if ((pid = fork()) == 0) { /* child here */ struct timespec tssleep; tssleep.tv_sec=SLEEPSEC; tssleep.tv_nsec=0; if (nanosleep(&tssleep, NULL) == 0) { printf("nanosleep() returned success\n"); return CHILDPASS; } else { printf("nanosleep() did not return success\n"); return CHILDFAIL; } return CHILDFAIL; } else { /* parent here */ int i; sleep(1); if (kill(pid, SIGSTOP) != 0) { printf("Could not raise SIGSTOP\n"); return PTS_UNRESOLVED; } if (kill(pid, SIGCONT) != 0) { printf("Could not raise SIGCONT\n"); return PTS_UNRESOLVED; } if (wait(&i) == -1) { perror("Error waiting for child to exit\n"); return PTS_UNRESOLVED; } if (!WIFEXITED(i)) { printf("nanosleep() did not return 0\n"); return PTS_FAIL; } if (clock_gettime(CLOCK_REALTIME, &tsafter) == -1) { perror("Error in clock_gettime()\n"); return PTS_UNRESOLVED; } slepts=tsafter.tv_sec-tsbefore.tv_sec; printf("Start %d sec; End %d sec\n", (int) tsbefore.tv_sec, (int) tsafter.tv_sec); if (slepts >= SLEEPSEC) { printf("Test PASSED\n"); return PTS_PASS; } else { printf("nanosleep() did not sleep long enough\n"); return PTS_FAIL; } } //end fork return PTS_UNRESOLVED; } posixtestsuite/conformance/interfaces/nanosleep/1-2.c0100644000000000000000000000327107575215635021757 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that nanosleep() causes the current thread to be suspended * until a signal whose action is to terminate the process is received. */ #include #include #include #include #include #include "posixtest.h" int main(int argc, char *argv[]) { struct timespec tssleepfor, tsstorage, tsbefore, tsafter; int sleepsec = 30; int pid; if (clock_gettime(CLOCK_REALTIME, &tsbefore) == -1) { perror("Error in clock_gettime()\n"); return PTS_UNRESOLVED; } if ((pid = fork()) == 0) { /* child here */ tssleepfor.tv_sec=sleepsec; tssleepfor.tv_nsec=0; nanosleep(&tssleepfor, &tsstorage); } else { /* parent here */ int i; sleep(1); if (kill(pid, SIGABRT) != 0) { printf("Could not raise signal being tested\n"); return PTS_UNRESOLVED; } if (wait(&i) == -1) { perror("Error waiting for child to exit\n"); return PTS_UNRESOLVED; } if (clock_gettime(CLOCK_REALTIME, &tsafter) == -1) { perror("Error in clock_gettime()\n"); return PTS_UNRESOLVED; } /* * pass if we slept for less than the (large) sleep time * allotted */ if ( (tsafter.tv_sec-tsbefore.tv_sec) < sleepsec) { printf("Test PASSED\n"); return PTS_PASS; } else { printf("Slept for too long: %d >= %d\n", (int)tsafter.tv_sec-(int)tsbefore.tv_sec, sleepsec); printf("Test FAILED\n"); return PTS_FAIL; } } return PTS_UNRESOLVED; } posixtestsuite/conformance/interfaces/nanosleep/7-1.c0100644000000000000000000000377107640675653021774 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that nanosleep() sets errno to EINTR if it is interrupted by a signal. * Test by sending a signal to a child doing nanosleep(). If nanosleep * errno = EINTR, return success from the child. */ #include #include #include #include #include #include #include "posixtest.h" #define CHILDSUCCESS 1 #define CHILDFAILURE 0 void handler(int signo) { printf("In handler\n"); } int main(int argc, char *argv[]) { struct timespec tssleepfor, tsstorage; int sleepsec = 30; int pid; struct sigaction act; if ((pid = fork()) == 0) { /* child here */ act.sa_handler=handler; act.sa_flags=0; if (sigemptyset(&act.sa_mask) == -1) { perror("Error calling sigemptyset\n"); return CHILDFAILURE; } if (sigaction(SIGABRT, &act, 0) == -1) { perror("Error calling sigaction\n"); return CHILDFAILURE; } tssleepfor.tv_sec=sleepsec; tssleepfor.tv_nsec=0; if (nanosleep(&tssleepfor, &tsstorage) == -1) { if (EINTR == errno) { printf("errno == EINTR\n"); return CHILDSUCCESS; } else { printf("errno != EINTR\n"); return CHILDFAILURE; } } else { printf("nanosleep did not return -1\n"); return CHILDFAILURE; } return CHILDFAILURE; } else { /* parent here */ int i; sleep(1); if (kill(pid, SIGABRT) != 0) { printf("Could not raise signal being tested\n"); return PTS_UNRESOLVED; } if (wait(&i) == -1) { perror("Error waiting for child to exit\n"); return PTS_UNRESOLVED; } if (WIFEXITED(i) && WEXITSTATUS(i)) { printf("Test PASSED\n"); return PTS_PASS; } else { printf("Child did not exit normally.\n"); printf("Test FAILED\n"); return PTS_FAIL; } } return PTS_UNRESOLVED; } posixtestsuite/conformance/interfaces/nanosleep/assertions.xml0100644000000000000000000000303707575522776024237 0ustar rootroot nanosleep() causes the current thread to be suspended until either: 1) the time interval in rqtp passes 2) a signal whose action is to terminate the process or invoke a signal catching function is delivered to the current thread Unless nanosleep() is interrupted (as in 2) above), nanosleep() must always suspend the process for _at least_ the time interval in rqtp - as measured by CLOCK_REALTIME. [Occasionally, the time could be > rqtp interval because of scheduling/rounding.] nanosleep() does not effect the action/blockage of a signal nanosleep() returns 0 if it returns because the time interval in rqtp has elapsed nanosleep() returns -1 on failure or if interrupted nanosleep() sets errno to EINVAL if rqtp contained a nanosecond value below 0 or above (or equal to) 1,000 million nanosleep() sets errno to EINTR if it is interrupted by a signal. Also, if rmtp != NULL, rmtp will be set to the time remaining (i.e., requested time - time slept). Otherwise, time remaining is not returned. posixtestsuite/conformance/interfaces/nanosleep/10000-1.c0100644000000000000000000000635507575215635022264 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test nanosleep() on a variety of valid and invalid input parameters. * * For valid parameters, if the seconds spent is within OKSECERR, the * test is considered a pass (Note: This is not too accurate since * accuracy is at the second level.). * * For invalid parameters, nanosleep should fail with -1 exit and * errno set to EINVAL. */ #include #include #include #include "posixtest.h" #define NUMVALID 6 #define NUMINVALID 8 #define OKSECERR 1 /* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * input tests */ static int sleepvalid[NUMVALID][2] = { {0, 30000000}, {1, 0}, {1, 30000000}, {2, 0}, {10, 5000}, {13, 5} }; static int sleepinvalid[NUMINVALID][2] = { {-1, -1}, {0, -1}, {1, 1000000000}, {2, 1000000000}, {-2147483647, -2147483647}, {1, 2147483647}, {-1073743192, 0}, {0, 1075002478} }; int main(int argc, char *argv[]) { struct timespec tssleepfor, tsstorage, tsbefore, tsafter; int i; int failure = 0; int slepts=0, sleptns=0; for (i=0; i OKSECERR) { printf("FAIL - slept %ds%dns >> %ds%dns\n", slepts, sleptns, (int) tssleepfor.tv_sec, (int) tssleepfor.tv_nsec); } else { printf("PASS - slept %ds%dns ~= %ds%dns\n", slepts, sleptns, (int) tssleepfor.tv_sec, (int) tssleepfor.tv_nsec); } } else { printf("nanosleep() did not return 0 on success\n"); failure = 1; } } for (i=0; i #include #include #include #include #include #include "posixtest.h" #define CHILDSUCCESS 1 #define CHILDFAILURE 0 #define OKDELTA 1 void handler(int signo) { printf("In handler\n"); } int main(int argc, char *argv[]) { struct timespec tssleepfor, tsstorage, tsbefore, tsafter; int sleepsec = 30; int pid; struct sigaction act; if (clock_gettime(CLOCK_REALTIME, &tsbefore) == -1) { perror("Error in clock_gettime()\n"); return PTS_UNRESOLVED; } if ((pid = fork()) == 0) { /* child here */ int sleptplusremaining; act.sa_handler=handler; act.sa_flags=0; if (sigemptyset(&act.sa_mask) == -1) { perror("Error calling sigemptyset\n"); return CHILDFAILURE; } if (sigaction(SIGABRT, &act, 0) == -1) { perror("Error calling sigaction\n"); return CHILDFAILURE; } tssleepfor.tv_sec=sleepsec; tssleepfor.tv_nsec=0; if (nanosleep(&tssleepfor, &tsstorage) != -1) { printf("nanosleep() was not interrupted\n"); return CHILDFAILURE; } if (clock_gettime(CLOCK_REALTIME, &tsafter) == -1) { perror("Error in clock_gettime()\n"); return CHILDFAILURE; } sleptplusremaining = (tsafter.tv_sec-tsbefore.tv_sec) + tsstorage.tv_sec; if (abs(sleptplusremaining - sleepsec) <= OKDELTA) { printf("PASS - within %d difference\n", abs(sleptplusremaining - sleepsec)); return CHILDSUCCESS; } else { printf("FAIL - within %d difference\n", abs(sleptplusremaining - sleepsec)); return CHILDFAILURE; } } else { /* parent here */ int i; sleep(1); if (kill(pid, SIGABRT) != 0) { printf("Could not raise signal being tested\n"); return PTS_UNRESOLVED; } if (wait(&i) == -1) { perror("Error waiting for child to exit\n"); return PTS_UNRESOLVED; } if (WIFEXITED(i) && WEXITSTATUS(i)) { printf("Child exited normally\n"); printf("Test PASSED\n"); return PTS_PASS; } else { printf("Child did not exit normally.\n"); printf("Test FAILED\n"); return PTS_FAIL; } } return PTS_UNRESOLVED; } posixtestsuite/conformance/interfaces/nanosleep/2-1.c0100644000000000000000000000370207575215635021756 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that nanosleep() causes the current thread to be suspended * until _at least_ the time interval in rqtp passes. * Test for a variety of time intervals (in nsecs) */ #include #include #include "posixtest.h" #define NUMINTERVALS 13 int main(int argc, char *argv[]) { struct timespec tssleepfor, tsstorage, tsbefore, tsafter; int sleepnsec[NUMINTERVALS] = {1, 2, 10, 100, 1000, 10000, 1000000, 10000000, 100000000, 200000000, 500000000, 750000000, 999999900}; int i; int failure = 0; int slepts, sleptns; if (clock_gettime(CLOCK_REALTIME, &tsbefore) == -1) { perror("Error in clock_gettime()\n"); return PTS_UNRESOLVED; } tssleepfor.tv_sec=0; for (i=0; i= 1) || (sleptns > sleepnsec[i]) ) { printf("PASS slept %ds %dns >= %d\n", slepts, sleptns, sleepnsec[i]); } else { printf("FAIL slept %ds %dns < %d\n", slepts, sleptns, sleepnsec[i]); failure = 1; } } if (failure) { printf("At least one test FAILED\n"); return PTS_FAIL; } else { printf("All tests PASSED\n"); return PTS_PASS; } printf("This code should not be executed.\n"); return PTS_UNRESOLVED; } posixtestsuite/conformance/interfaces/nanosleep/4-1.sh0100755000000000000000000000104007566257733022151 0ustar rootroot#!/bin/sh # Copyright (c) 2002, Intel Corporation. All rights reserved. # Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com # This file is licensed under the GPL license. For the full content # of this license, see the COPYING file at the top level of this # source tree. # Test that nanosleep() returns 0 if it is returning because the time # interval in rqtp has passed. # This is tested implicitly via assertion #1. See that output for status. echo "Tested implicitly via assertion 1. See that output for status." exit 0 posixtestsuite/conformance/interfaces/nanosleep/3-1.c0100644000000000000000000000364207640675653021765 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that nanosleep() does not effect the action of a signal. * - Start nanosleep() in a child process * - Send a signal to the child process and have the handler exit with * success; if the handler is not called, return 0 * - In the parent, if the child exitted success, return success. */ #include #include #include #include #include #include #include "posixtest.h" #define CHILDSUCCESS 1 #define CHILDFAIL 0 void handler(int signo) { printf("Received signal - exit success\n"); exit(CHILDSUCCESS); } int main(int argc, char *argv[]) { struct timespec tssleepfor, tsstorage; int sleepsec = 30; int pid; struct sigaction act; if ((pid = fork()) == 0) { /* child here */ act.sa_handler=handler; act.sa_flags=0; if (sigemptyset(&act.sa_mask) == -1) { perror("Error calling sigemptyset\n"); return CHILDFAIL; } if (sigaction(SIGABRT, &act, 0) == -1) { perror("Error calling sigaction\n"); return CHILDFAIL; } tssleepfor.tv_sec=sleepsec; tssleepfor.tv_nsec=0; nanosleep(&tssleepfor, &tsstorage); return CHILDFAIL; } else { /* parent here */ int i; sleep(1); if (kill(pid, SIGABRT) != 0) { printf("Could not raise signal being tested\n"); return PTS_UNRESOLVED; } if (wait(&i) == -1) { perror("Error waiting for child to exit\n"); return PTS_UNRESOLVED; } if (WIFEXITED(i) && WEXITSTATUS(i)) { printf("Child exited normally\n"); printf("Test PASSED\n"); return PTS_PASS; } else { printf("Child did not exit normally.\n"); printf("Test FAILED\n"); return PTS_FAIL; } } return PTS_UNRESOLVED; } posixtestsuite/conformance/interfaces/munlock/0040755000000000000000000000000010515625175020770 5ustar rootrootposixtestsuite/conformance/interfaces/munlock/9-1.sh0100755000000000000000000000031307700522276021627 0ustar rootroot#! /bin/sh # # Test that the munlock() function return -1 upon unsuccessful completion. # # This is tested implicitly via assertions 10 and 11. echo "Tested implicitly via assertions 10 and 11." exit 0 posixtestsuite/conformance/interfaces/munlock/11-1.c0100644000000000000000000000325307700522276021513 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that munlock() set errno = EINVAL when addr is not a multiple of * {PAGESIZE} if the implementation requires that addr be a multiple of * {PAGESIZE}. */ #include #include #include #include #include #include "posixtest.h" int main() { int result; long page_size; void *ptr, *notpage_ptr; page_size = sysconf(_SC_PAGESIZE); if(errno) { perror("An error occurs when calling sysconf()"); return PTS_UNRESOLVED; } ptr = malloc(page_size); if(ptr == NULL) { printf("Can not allocate memory.\n"); return PTS_UNRESOLVED; } notpage_ptr = ((long)ptr % page_size) ? ptr : ptr+1; result = munlock(notpage_ptr, page_size - 1); if(result == 0){ printf("munlock() does not require that addr be a multiple of {PAGESIZE}.\nTest PASSED\n"); return PTS_PASS; } else if(result == -1 && errno == EINVAL){ printf("munlock() requires that addr be a multiple of {PAGESIZE}.\nTest PASSED\n"); return PTS_PASS; } else if(result != -1){ printf("munlock() returns a value of %i instead of 0 or 1.\n", result); perror("munlock"); return PTS_FAIL; } perror("Unexpected error"); return PTS_UNRESOLVED; } posixtestsuite/conformance/interfaces/munlock/10-1.c0100644000000000000000000000244607700522276021515 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that the munlock() function sets errno = ENOMEM if some or all of the * address range specified by the addr and len arguments does not correspond to * valid mapped pages in the address space of the process. * * Assume that the value LONG_MAX is an invalid pointer. */ #include #include #include #include #include #include "posixtest.h" #define BUFSIZE 8 int main() { int result; long page_size; void *page_ptr; page_size = sysconf(_SC_PAGESIZE); if(errno) { perror("An error occurs when calling sysconf()"); return PTS_UNRESOLVED; } page_ptr = (void*)( LONG_MAX - (LONG_MAX % page_size) ); result = munlock(page_ptr, BUFSIZE); if(result == -1 && errno == ENOMEM) { printf("Test PASSED\n"); return PTS_PASS; } else { perror("Unexpected error"); return PTS_UNRESOLVED; } } posixtestsuite/conformance/interfaces/munlock/7-1.c0100644000000000000000000000244307700522276021440 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that munlock return a value of zero upon successful completion. * */ #include #include #include #include #include "posixtest.h" #define BUFSIZE 8 int main() { int result; void *ptr; ptr = malloc(BUFSIZE); if(ptr == NULL) { printf("Can not allocate memory.\n"); return PTS_UNRESOLVED; } if(mlock(ptr, BUFSIZE) != 0){ if(errno == EPERM) { printf("You don't have permission to lock your address space.\nTry to rerun this test as root.\n"); } else { perror("An error occurs when calling mlock()"); } return PTS_UNRESOLVED; } result = munlock(ptr, BUFSIZE); if(result == 0 && errno == 0){ printf("Test PASSED\n"); return PTS_PASS; } else if(errno == 0) { printf("mlock did not return a value of zero\n"); return PTS_FAIL; } perror("Unexpected error"); return PTS_UNRESOLVED; } posixtestsuite/conformance/interfaces/munlock/assertions.xml0100644000000000000000000000517607700522276023712 0ustar rootroot The munlock() function shall unlock those whole pages containing any part of the address space of the process starting at address addr and continuing for len bytes, regardless of how many times mlock() has been called by the process for any of the pages in the specified range The implementation may require that addr be a multiple of {PAGESIZE} If any of the pages in the range specified to a call to munlock() are also mapped into the address spaces of other processes, any locks established on those pages by another process are unaffected by the call of this process to munlock() If any of the pages in the range specified by a call to munlock() are also mapped into other portions of the address space of the calling process outside the range specified, any locks established on those pages via the other mappings are also unaffected by this call Upon successful return from munlock(), pages in the specified range shall be unlocked with respect to the address space of the process Memory residency of unlocked pages is unspecified Upon successful completion, the munlock() function shall return a value of zero Upon unsuccessful completion, no change is made to any locks in the address space of the process Upon unsuccessful completion, the function shall return a value of -1 The munlock() function shall set errno = ENOMEM if some or all of the address range specified by the addr and len arguments does not correspond to valid mapped pages in the address space of the process The munlock() function may set errno = EINVAL if the addr argument is not a multiple of {PAGESIZE} posixtestsuite/conformance/interfaces/munlock/coverage.txt0100644000000000000000000000055707700522276023330 0ustar rootrootThis document explains why certain assertions were not tested. Assertions not listed here should be covered by the tests in this directory. Assertions Tested ? Remarks 1 NO 2 YES May assertion 3 NO 4 NO 5 NO 6 NO Unspecified 7 YES 8 NO 9 YES 10 YES 11 YES May assertion posixtestsuite/conformance/interfaces/munlock/2-1.sh0100755000000000000000000000030407700522276021620 0ustar rootroot#! /bin/sh # # Test whether the implementation requires that addr be a multiple of # {PAGESIZE}. # # This is tested implicitly via assertion 11. echo "Tested implicitly via assertion 11." exit 0 posixtestsuite/conformance/interfaces/pthread_cond_timedwait/0040755000000000000000000000000010515625207024015 5ustar rootrootposixtestsuite/conformance/interfaces/pthread_cond_timedwait/2-4.c0100644000000000000000000004340210066714720024463 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertion: * * When the function returns successfully, everything is as if * the thread had locked the mutex. * * The steps are: * -> For each mutex type; * -> with and without process-shared primitive if this is supported; * -> with different clocks if this is supported, * -> Initialize a condvar and a mutex. * -> Create a new thread (or process for process-shared condvars & mutex) * -> The new thread (process) locks the mutex, then enters a timedwait which will expire far later. * -> The parent thread (process) then locks the mutex, ensures that the child is waiting, * then signals the condition; and checks the child does not leave the wait function. * -> The parent unlocks the mutex then waits for the child. * -> The child checks that it owns the mutex; then it leaves. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /* We need the XSI extention for the mutex attributes and the mkstemp() routine */ #ifndef WITHOUT_XOPEN #define _XOPEN_SOURCE 600 #endif /********************************************************************************************/ /****************************** standard includes *****************************************/ /********************************************************************************************/ #include #include #include #include #include #include #include #include #include #include /********************************************************************************************/ /****************************** Test framework *****************************************/ /********************************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /********************************************************************************************/ /********************************** Configuration ******************************************/ /********************************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif #ifndef WITHOUT_ALTCLK #define USE_ALTCLK /* make tests with MONOTONIC CLOCK if supported */ #endif /********************************************************************************************/ /*********************************** Test case *****************************************/ /********************************************************************************************/ #ifndef WITHOUT_XOPEN typedef struct { pthread_mutex_t mtx; pthread_cond_t cnd; clockid_t cid; /* Clock id used by the cond var */ int type; /* Mutex type */ int ctrl; /* checkpoints */ int bool; /* Boolean predicate for the condition */ int status; /* error code */ } testdata_t; struct _scenar { int m_type; /* Mutex type to use */ int mc_pshared; /* 0: mutex and cond are process-private (default) ~ !0: Both are process-shared, if supported */ int c_clock; /* 0: cond uses the default clock. ~ !0: Cond uses monotonic clock, if supported. */ int fork; /* 0: Test between threads. ~ !0: Test across processes, if supported (mmap) */ char * descr; /* Case description */ } scenarii[] = { {PTHREAD_MUTEX_DEFAULT, 0, 0, 0, "Default mutex"} ,{PTHREAD_MUTEX_NORMAL, 0, 0, 0, "Normal mutex"} ,{PTHREAD_MUTEX_ERRORCHECK, 0, 0, 0, "Errorcheck mutex"} ,{PTHREAD_MUTEX_RECURSIVE, 0, 0, 0, "Recursive mutex"} ,{PTHREAD_MUTEX_DEFAULT, 1, 0, 0, "PShared default mutex"} ,{PTHREAD_MUTEX_NORMAL, 1, 0, 0, "Pshared normal mutex"} ,{PTHREAD_MUTEX_ERRORCHECK, 1, 0, 0, "Pshared errorcheck mutex"} ,{PTHREAD_MUTEX_RECURSIVE, 1, 0, 0, "Pshared recursive mutex"} ,{PTHREAD_MUTEX_DEFAULT, 1, 0, 1, "Pshared default mutex across processes"} ,{PTHREAD_MUTEX_NORMAL, 1, 0, 1, "Pshared normal mutex across processes"} ,{PTHREAD_MUTEX_ERRORCHECK, 1, 0, 1, "Pshared errorcheck mutex across processes"} ,{PTHREAD_MUTEX_RECURSIVE, 1, 0, 1, "Pshared recursive mutex across processes"} #ifdef USE_ALTCLK ,{PTHREAD_MUTEX_DEFAULT, 1, 1, 1, "Pshared default mutex and alt clock condvar across processes"} ,{PTHREAD_MUTEX_NORMAL, 1, 1, 1, "Pshared normal mutex and alt clock condvar across processes"} ,{PTHREAD_MUTEX_ERRORCHECK, 1, 1, 1, "Pshared errorcheck mutex and alt clock condvar across processes"} ,{PTHREAD_MUTEX_RECURSIVE, 1, 1, 1, "Pshared recursive mutex and alt clock condvar across processes"} ,{PTHREAD_MUTEX_DEFAULT, 0, 1, 0, "Default mutex and alt clock condvar"} ,{PTHREAD_MUTEX_NORMAL, 0, 1, 0, "Normal mutex and alt clock condvar"} ,{PTHREAD_MUTEX_ERRORCHECK, 0, 1, 0, "Errorcheck mutex and alt clock condvar"} ,{PTHREAD_MUTEX_RECURSIVE, 0, 1, 0, "Recursive mutex and alt clock condvar"} ,{PTHREAD_MUTEX_DEFAULT, 1, 1, 0, "PShared default mutex and alt clock condvar"} ,{PTHREAD_MUTEX_NORMAL, 1, 1, 0, "Pshared normal mutex and alt clock condvar"} ,{PTHREAD_MUTEX_ERRORCHECK, 1, 1, 0, "Pshared errorcheck mutex and alt clock condvar"} ,{PTHREAD_MUTEX_RECURSIVE, 1, 1, 0, "Pshared recursive mutex and alt clock condvar"} #endif }; void * tf(void * arg) { int ret=0; struct timespec ts; testdata_t * td = (testdata_t *)arg; /* Lock the mutex */ ret = pthread_mutex_lock(&(td->mtx)); if (ret != 0) { td->status = ret; UNRESOLVED(ret, "[child] Unable to lock the mutex"); } /* Tell the parent the mutex is locked */ td->ctrl = 1; /* Prepare the timeout parameter */ ret = clock_gettime(td->cid, &ts); if (ret != 0) { td->status = ret; UNRESOLVED(errno, "[child] Unable get clock time"); } ts.tv_sec += 10; #if VERBOSE > 1 output("[child] Will timeout at %i.%09i\n", ts.tv_sec, ts.tv_nsec); #endif /* Enter the timed wait */ do { ret = pthread_cond_timedwait(&(td->cnd), &(td->mtx), &ts); td->ctrl = 2; } while ((ret == 0) && (td->bool == 0)); td->ctrl = 3; if (ret != 0) { td->status = ret; UNRESOLVED(ret, "[child] Cond timedwait returned an error"); } /* Make sure we are owning the mutex */ ret = pthread_mutex_trylock(&(td->mtx)); if (td->type == PTHREAD_MUTEX_RECURSIVE) { #if VERBOSE > 1 output("[child] Recursive mutex. Test if we are able to re-lock.\n"); #endif if (ret != 0) { td->status = ret; FAILED("[child] Unable to relock the recursive mutex"); } ret = pthread_mutex_unlock(&(td->mtx)); if (ret != 0) { td->status = ret; UNRESOLVED(ret, "[child] Failed to unlock the mutex"); } } else /* This was not a recursive mutex; the call must have failed */ { if (ret == 0) { td->status = -1; FAILED("[child] Thread did not owned the mutex after the timedwait return."); } if (ret != EBUSY) { td-> status = ret; UNRESOLVED(ret, "[child] Mutex trylock did not return EBUSY"); } #if VERBOSE > 1 output("[child] The mutex was busy (normal).\n"); #endif } ret = pthread_mutex_unlock(&(td->mtx)); if (ret != 0) { td->status=ret; output("[child] Got error %i: %s\n", ret, strerror(ret)); FAILED("[child] Failed to unlock the mutex - owned by another thread?"); } td->ctrl = 4; return NULL; } int main(int argc, char * argv[]) { int ret, i; pthread_mutexattr_t ma; pthread_condattr_t ca; testdata_t * td; testdata_t alternativ; int do_fork; pid_t child_pr=0, chkpid; int status; pthread_t child_th; long pshared, monotonic, cs, mf; output_init(); pshared = sysconf(_SC_THREAD_PROCESS_SHARED); cs = sysconf(_SC_CLOCK_SELECTION); monotonic = sysconf(_SC_MONOTONIC_CLOCK); mf =sysconf(_SC_MAPPED_FILES); #if VERBOSE > 0 output("Test starting\n"); output("System abilities:\n"); output(" TPS : %li\n", pshared); output(" CS : %li\n", cs); output(" MON : %li\n", monotonic); output(" MF : %li\n", mf); if ((mf < 0) || (pshared < 0)) output("Process-shared attributes won't be tested\n"); if ((cs < 0) || (monotonic < 0)) output("Alternative clock won't be tested\n"); #endif /* We are not interested in testing the clock if we have no other clock available.. */ if (monotonic < 0) cs = -1; #ifndef USE_ALTCLK if (cs > 0) output("Implementation supports the MONOTONIC CLOCK but option is disabled in test.\n"); #endif /********** * Allocate space for the testdata structure */ if (mf < 0) { /* Cannot mmap a file, we use an alternative method */ td = &alternativ; pshared = -1; /* We won't do this testing anyway */ #if VERBOSE > 0 output("Testdata allocated in the process memory.\n"); #endif } else { /* We will place the test data in a mmaped file */ char filename[] = "/tmp/cond_timedwait_3-2-XXXXXX"; size_t sz; void * mmaped; int fd; char * tmp; /* We now create the temp files */ fd = mkstemp(filename); if (fd == -1) { UNRESOLVED(errno, "Temporary file could not be created"); } /* and make sure the file will be deleted when closed */ unlink(filename); #if VERBOSE > 1 output("Temp file created (%s).\n", filename); #endif sz= (size_t)sysconf(_SC_PAGESIZE); tmp = calloc(1, sz); if (tmp == NULL) { UNRESOLVED(errno, "Memory allocation failed"); } /* Write the data to the file. */ if (write (fd, tmp, sz) != (ssize_t) sz) { UNRESOLVED(sz, "Writting to the file failed"); } free(tmp); /* Now we can map the file in memory */ mmaped = mmap(NULL, sz, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); if (mmaped == MAP_FAILED) { UNRESOLVED(errno, "mmap failed"); } td = (testdata_t *) mmaped; /* Our datatest structure is now in shared memory */ #if VERBOSE > 1 output("Testdata allocated in shared memory.\n"); #endif } /********** * For each test scenario, initialize the attributes and other variables. */ for ( i=0; i< (sizeof(scenarii) / sizeof(scenarii[0])); i++) { #if VERBOSE > 1 output("[parent] Preparing attributes for: %s\n", scenarii[i].descr); #endif /* set / reset everything */ do_fork=0; ret = pthread_mutexattr_init(&ma); if (ret != 0) { UNRESOLVED(ret, "[parent] Unable to initialize the mutex attribute object"); } ret = pthread_condattr_init(&ca); if (ret != 0) { UNRESOLVED(ret, "[parent] Unable to initialize the cond attribute object"); } /* Set the mutex type */ ret = pthread_mutexattr_settype(&ma, scenarii[i].m_type); if (ret != 0) { UNRESOLVED(ret, "[parent] Unable to set mutex type"); } #if VERBOSE > 1 output("[parent] Mutex type : %i\n", scenarii[i].m_type); #endif /* Set the pshared attributes, if supported */ if ((pshared > 0) && (scenarii[i].mc_pshared != 0)) { ret = pthread_mutexattr_setpshared(&ma, PTHREAD_PROCESS_SHARED); if (ret != 0) { UNRESOLVED(ret, "[parent] Unable to set the mutex process-shared"); } ret = pthread_condattr_setpshared(&ca, PTHREAD_PROCESS_SHARED); if (ret != 0) { UNRESOLVED(ret, "[parent] Unable to set the cond var process-shared"); } #if VERBOSE > 1 output("[parent] Mutex & cond are process-shared\n"); #endif } #if VERBOSE > 1 else { output("[parent] Mutex & cond are process-private\n"); } #endif /* Set the alternative clock, if supported */ #ifdef USE_ALTCLK if ((cs > 0) && (scenarii[i].c_clock != 0)) { ret = pthread_condattr_setclock(&ca, CLOCK_MONOTONIC); if (ret != 0) { UNRESOLVED(ret, "[parent] Unable to set the monotonic clock for the cond"); } #if VERBOSE > 1 output("[parent] Cond uses the Monotonic clock\n"); #endif } #if VERBOSE > 1 else { output("[parent] Cond uses the default clock\n"); } #endif #endif /* Tell whether the test will be across processes */ if ((pshared > 0) && (scenarii[i].fork != 0)) { do_fork = 1; #if VERBOSE > 1 output("[parent] Child will be a new process\n"); #endif } #if VERBOSE > 1 else { output("[parent] Child will be a new thread\n"); } #endif /********** * Initialize the testdata_t structure with the previously defined attributes */ /* Initialize the mutex */ ret = pthread_mutex_init(&(td->mtx), &ma); if (ret != 0) { UNRESOLVED(ret, "[parent] Mutex init failed"); } /* initialize the condvar */ ret = pthread_cond_init(&(td->cnd), &ca); if (ret != 0) { UNRESOLVED(ret, "[parent] Cond init failed"); } /* Initialize the other datas from the test structure */ #ifdef USE_ALTCLK ret = pthread_condattr_getclock(&ca, &(td->cid)); if (ret != 0) { UNRESOLVED(ret, "[parent] Unable to read cond clock attribute"); } #else td->cid = CLOCK_REALTIME; #endif ret = pthread_mutexattr_gettype(&ma, &(td->type)); if (ret != 0) { UNRESOLVED(ret, "[parent] Unable to read mutex type attribute"); } td->ctrl=0; td->bool=0; td->status=0; /********** * Proceed to the actual testing */ /* Create the child */ if (do_fork != 0) { /* We are testing across two processes */ child_pr = fork(); if (child_pr == -1) { UNRESOLVED(errno, "[parent] Fork failed"); } if (child_pr == 0) { #if VERBOSE > 1 output("[child] Child process starting...\n"); #endif if (tf((void *)td) != NULL) { UNRESOLVED( -1, "[child] Got an unexpected return value from test function"); } else { /* We cannot use the PASSED macro here since it would terminate the output */ exit (0); } } /* Only the parent process goes further */ } else /* do_fork == 0 */ { /* We are testing across two threads */ ret = pthread_create(&child_th, NULL, tf, td); if (ret != 0) { UNRESOLVED(ret, "[parent] Unable to create the child thread."); } } /* Note: in case of an error, the child process will be alive for 10 sec then exit. */ /* Child is now running and will enter the timedwait */ /* We are waiting for this; and we have to monitor the status value as well. */ ret = pthread_mutex_lock(&(td->mtx)); if (ret != 0) { UNRESOLVED(ret, "[parent] Unable to lock the mutex"); } while ((td->ctrl == 0) && (td->status == 0)) { ret = pthread_mutex_unlock(&(td->mtx)); if (ret != 0) { UNRESOLVED(ret, "[parent] Unable to unlock the mutex"); } sched_yield(); ret = pthread_mutex_lock(&(td->mtx)); if (ret != 0) { UNRESOLVED(ret, "[parent] Unable to lock the mutex"); } } if ((td->ctrl == 2) && (td->status == 0)) /* Spurious wakeups hapenned */ { output("Spurious wake ups have happened. Maybe pthread_cond_timedwait is broken?\n"); td->ctrl = 1; } if (td->ctrl == 1)/* The child is inside the cond timedwait */ { ret = pthread_cond_signal(&(td->cnd)); if (ret != 0) { UNRESOLVED(ret, "[parent] Unable to signal the condition"); } /* Let the child leave the wait function if something is broken */ usleep(100); if (td->ctrl != 1) { FAILED("[parent] Child went out from pthread_cond_timedwait without locking the mutex"); } /* Allow the child to continue */ td->bool=1; } /* Let the child do its checking */ ret = pthread_mutex_unlock(&(td->mtx)); if (ret != 0) { UNRESOLVED(ret, "[parent] Unable to unlock the mutex"); } /* Wait for the child to terminate */ if (do_fork != 0) { /* We were testing across two processes */ chkpid = waitpid(child_pr, &status, 0); if (chkpid != child_pr) { output("Expected pid: %i. Got %i\n", (int)child_pr, (int)chkpid); UNRESOLVED(errno, "Waitpid failed"); } if (WIFSIGNALED(status)) { output("Child process killed with signal %d\n",WTERMSIG(status)); UNRESOLVED( td->status , "Child process was killed"); } if (WIFEXITED(status)) { ret = WEXITSTATUS(status); } else { UNRESOLVED( td->status, "Child process was neither killed nor exited"); } if (ret != 0) { exit(ret); /* Output has already been closed in child */ } } else /* child was a thread */ { ret = pthread_join(child_th, NULL); if (ret != 0) { UNRESOLVED(ret, "[parent] Unable to join the thread"); } } /********** * Destroy the data */ ret = pthread_cond_destroy(&(td->cnd)); if (ret != 0) { UNRESOLVED(ret, "Failed to destroy the cond var"); } ret = pthread_mutex_destroy(&(td->mtx)); if (ret != 0) { UNRESOLVED(ret, "Failed to destroy the mutex"); } ret = pthread_condattr_destroy(&ca); if (ret != 0) { UNRESOLVED(ret, "Failed to destroy the cond var attribute object"); } ret = pthread_mutexattr_destroy(&ma); if (ret != 0) { UNRESOLVED(ret, "Failed to destroy the mutex attribute object"); } } /* Proceed to the next scenario */ #if VERBOSE > 0 output("Test passed\n"); #endif PASSED; } #else /* WITHOUT_XOPEN */ int main(int argc, char * argv[]) { output_init(); UNTESTED("This test requires XSI features"); } #endif posixtestsuite/conformance/interfaces/pthread_cond_timedwait/2-2.c0100644000000000000000000000640707654036335024475 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: bing.wei.liu REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_cond_timedwait() * shall be equivalent to pthread_cond_wait(), except that an error is returned * if the absolute time specified by abstime passes before the condition cond is * signaled or broadcasted. * */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include "posixtest.h" #define INTERVAL 5 #define TIMEOUT 1 struct testdata { pthread_mutex_t mutex; pthread_cond_t cond; } td; int t1_start = 0; void *t1_func(void *arg) { int rc; struct timeval curtime; struct timespec timeout; fprintf(stderr,"Thread1 started\n"); /* Lock the mutex */ if (pthread_mutex_lock(&td.mutex) != 0) { fprintf(stderr,"Thread1 failed to acquire the mutex\n"); exit(PTS_UNRESOLVED); } /* Tell main it may continue running now that the thread started. */ t1_start = 1; /* Set time for pthread_cond_timedwait to wait */ if (gettimeofday(&curtime, NULL) !=0 ) { fprintf(stderr,"Fail to get current time\n"); exit(PTS_UNRESOLVED); } timeout.tv_sec = curtime.tv_sec + TIMEOUT; timeout.tv_nsec = curtime.tv_usec * 1000; /* Thread will now release the mutex and wait on the condition variable */ /* The condition variable will not be signaled until AFTER the timeout * period, so we should receive an ETIMEDOUT error. */ fprintf(stderr,"Thread1 is waiting for the cond\n"); rc = pthread_cond_timedwait(&td.cond, &td.mutex, &timeout); if (rc == ETIMEDOUT) { fprintf(stderr,"Thread1 stops waiting when time is out\n"); pthread_exit((void*)PTS_PASS); } else { fprintf(stderr,"Test FAILED: pthread_cond_timedwait return %d instead of ETIMEDOUT\n", rc); pthread_exit((void*)PTS_FAIL); } } int main() { pthread_t thread1; int th_ret; if (pthread_mutex_init(&td.mutex, NULL) != 0) { fprintf(stderr,"Fail to initialize mutex\n"); return PTS_UNRESOLVED; } if (pthread_cond_init(&td.cond, NULL) != 0) { fprintf(stderr,"Fail to initialize cond\n"); return PTS_UNRESOLVED; } if (pthread_create(&thread1, NULL, t1_func, NULL) != 0) { fprintf(stderr,"Fail to create thread 1\n"); return PTS_UNRESOLVED; } while(!t1_start) /* wait for thread1 started */ usleep(100); /* acquire the mutex released by pthread_cond_wait() within thread 1 */ if (pthread_mutex_lock(&td.mutex) != 0) { fprintf(stderr,"Main failed to acquire mutex\n"); return PTS_UNRESOLVED; } if (pthread_mutex_unlock(&td.mutex) != 0) { fprintf(stderr,"Main failed to release mutex\n"); return PTS_UNRESOLVED; } /* Set an alarm signal in case the thread never returns probably because * pthread_cond_timedwait functioned incorrectly and waited too long. */ alarm(INTERVAL); /* Wait for the thread to return. */ if(pthread_join(thread1, (void*)&th_ret) != 0) { fprintf(stderr, "Could not join the thread.\n"); return PTS_UNRESOLVED; } if(th_ret == PTS_PASS) { printf("Test PASSED\n"); return PTS_PASS; } else { printf("Test FAILED\n"); return PTS_FAIL; } } posixtestsuite/conformance/interfaces/pthread_cond_timedwait/2-6.c0100644000000000000000000003064110106621262024457 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertion: * * This function is a cancelation point: when cancelability * is PTHREAD_CANCEL_DEFERRED and a cancel request falls, the thread * must relock the mutex before the first (if any) clean up handler is called. * The steps are: * -> Create a thread * -> this thread locks a mutex then waits for a condition * -> cancel the thread * -> the cancelation handler will test if the thread owns the mutex. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /* We need the XSI extention for the mutex attributes */ #ifndef WITHOUT_XOPEN #define _XOPEN_SOURCE 600 #endif /********************************************************************************************/ /****************************** standard includes *****************************************/ /********************************************************************************************/ #include #include #include #include #include #include #include #include /********************************************************************************************/ /****************************** Test framework *****************************************/ /********************************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /********************************************************************************************/ /********************************** Configuration ******************************************/ /********************************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif #ifndef WITHOUT_ALTCLK #define USE_ALTCLK /* make tests with MONOTONIC CLOCK if supported */ #endif /********************************************************************************************/ /*********************************** Test case *****************************************/ /********************************************************************************************/ struct { pthread_mutex_t mtx; pthread_cond_t cnd; int type; clockid_t cid; sem_t semA; sem_t semB; int bool; } data; /**** First handler that will be poped * This one works only with recursive mutexes */ void clnp1 (void * arg) { int ret; if (data.type == PTHREAD_MUTEX_RECURSIVE) { ret = pthread_mutex_trylock(&(data.mtx)); if (ret != 0) { FAILED("Unable to double-lock a recursive mutex in clean-up handler 1"); } ret = pthread_mutex_unlock(&(data.mtx)); if (ret != 0) { UNRESOLVED(ret, "Unable to unlock double-locked recursive mutex in clean-up handler 1"); } } return; } /**** Second handler * This one will trigger an action in main thread, while we are owning the mutex */ void clnp2 (void * arg) { int ret; do { ret = sem_post(&(data.semA)); } while ((ret != 0) && (errno == EINTR)); if (ret != 0) { UNRESOLVED(errno, "Sem post failed in cleanup handler 2"); } do { ret = sem_wait(&(data.semB)); } while ((ret != 0) && (errno == EINTR)); if (ret != 0) { UNRESOLVED(errno, "Sem wait failed in cleanup handler 2"); } return; } /**** Third handler * Will actually unlock the mutex, then try to unlock second time to check an error is returned */ void clnp3 (void * arg) { int ret; ret = pthread_mutex_unlock(&(data.mtx)); if (ret != 0) { UNRESOLVED(ret, "Unable to unlock mutex in clean-up handler 3"); } if ((data.type == PTHREAD_MUTEX_ERRORCHECK) || (data.type == PTHREAD_MUTEX_RECURSIVE)) { ret = pthread_mutex_unlock(&(data.mtx)); if (ret == 0) { UNRESOLVED(ret, "Was able to unlock unlocked mutex in clean-up handler 3"); } } return; } /**** Thread function * This function will lock the mutex, then install the cleanup handlers * and wait for the cond. At this point it will be canceled. */ void * threaded (void * arg) { int ret; struct timespec ts; ret = clock_gettime(data.cid, &ts); if (ret != 0) { UNRESOLVED(ret, "Unable to get time from clock"); } ts.tv_sec += 30; ret= pthread_mutex_lock(&(data.mtx)); if (ret != 0) { UNRESOLVED(ret, "Failed to lock the mutex in thread"); } do { ret = sem_post(&(data.semA)); } while ((ret != 0) && (errno == EINTR)); if (ret != 0) { UNRESOLVED(errno, "Sem post failed in thread"); } pthread_cleanup_push ( clnp3, NULL); pthread_cleanup_push ( clnp2, NULL); pthread_cleanup_push ( clnp1, NULL); do { ret = pthread_cond_timedwait(&(data.cnd), &(data.mtx), &ts); } while ((ret == 0) && (data.bool == 0)); if (ret != 0) { UNRESOLVED(ret , "Timedwait failed"); } /* We will exit even if the error is timedwait */ /* If we are here, the thread was not canceled */ FAILED("The thread has not been canceled"); pthread_cleanup_pop(0); pthread_cleanup_pop(0); pthread_cleanup_pop(1); return NULL; } int main(int argc, char * argv[]) { int ret, i; void * rc; pthread_mutexattr_t ma; pthread_condattr_t ca; pthread_t th; long altclk_ok, pshared_ok; struct { char altclk; /* Want to use alternative clock */ char pshared; /* Want to use process-shared primitives */ int type; /* mutex type */ char * descr; /* Description of the case */ } scenar[] = { {0, 0, PTHREAD_MUTEX_NORMAL, "Normal mutex" } #ifdef USE_ALTCLK ,{1, 0, PTHREAD_MUTEX_NORMAL, "Normal mutex + altclock cond" } ,{1, 1, PTHREAD_MUTEX_NORMAL, "PShared mutex + altclock cond" } #endif ,{0, 1, PTHREAD_MUTEX_NORMAL, "Pshared mutex" } #ifndef WITHOUT_XOPEN ,{0, 0, PTHREAD_MUTEX_ERRORCHECK, "Errorcheck mutex" } ,{0, 0, PTHREAD_MUTEX_RECURSIVE , "Recursive mutex" } #ifdef USE_ALTCLK ,{1, 0, PTHREAD_MUTEX_RECURSIVE , "Recursive mutex + altclock cond" } ,{1, 0, PTHREAD_MUTEX_ERRORCHECK, "Errorcheck mutex + altclock cond" } ,{1, 1, PTHREAD_MUTEX_RECURSIVE , "Recursive pshared mutex + altclock cond" } ,{1, 1, PTHREAD_MUTEX_ERRORCHECK, "Errorcheck pshared mutex + altclock cond" } #endif ,{0, 1, PTHREAD_MUTEX_RECURSIVE , "Recursive pshared mutex" } ,{0, 1, PTHREAD_MUTEX_ERRORCHECK, "Errorcheck pshared mutex" } #endif }; output_init(); /* Initialize the constants */ altclk_ok = sysconf(_SC_CLOCK_SELECTION); if (altclk_ok > 0) altclk_ok = sysconf(_SC_MONOTONIC_CLOCK); #ifndef USE_ALTCLK if (altclk_ok > 0) output("Implementation supports the MONOTONIC CLOCK but option is disabled in test.\n"); #endif pshared_ok = sysconf(_SC_THREAD_PROCESS_SHARED); #if VERBOSE > 0 output("Test starting\n"); output(" Process-shared primitive %s be tested\n", (pshared_ok>0)?"will":"won't"); output(" Alternative clock for cond %s be tested\n", (altclk_ok>0)?"will":"won't"); #endif ret = sem_init(&(data.semA), 0, 0); if (ret != 0) { UNRESOLVED(errno, "Unable to init sem A"); } ret = sem_init(&(data.semB), 0, 0); if (ret != 0) { UNRESOLVED(errno, "Unable to init sem B"); } for (i=0; i< (sizeof(scenar) / sizeof(scenar[0])); i++) { #if VERBOSE > 1 output("Starting test for %s\n", scenar[i].descr); #endif /* Initialize the data structure */ ret = pthread_mutexattr_init(&ma); if (ret != 0) { UNRESOLVED(ret, "Mutex attribute object init failed"); } ret = pthread_mutexattr_settype(&ma, scenar[i].type); if (ret != 0) { UNRESOLVED(ret, "Unable to set mutex type"); } if ((pshared_ok > 0) && (scenar[i].pshared != 0)) { ret = pthread_mutexattr_setpshared(&ma, PTHREAD_PROCESS_SHARED); if (ret != 0) { UNRESOLVED(ret, "Unable to set mutex process-shared"); } } ret = pthread_condattr_init(&ca); if (ret != 0) { UNRESOLVED(ret, "Cond attribute object init failed"); } if ((pshared_ok > 0) && (scenar[i].pshared != 0)) { ret = pthread_condattr_setpshared(&ca, PTHREAD_PROCESS_SHARED); if (ret != 0) { UNRESOLVED(ret, "Unable to set cond process-shared"); } } #ifdef USE_ALTCLK if ((altclk_ok > 0) && (scenar[i].altclk != 0)) { ret = pthread_condattr_setclock(&ca, CLOCK_MONOTONIC); if (ret != 0) { UNRESOLVED(ret, "Unable to set alternative (monotonic) clock for cond"); } } #endif ret = pthread_mutex_init(&(data.mtx), &ma); if (ret != 0) { UNRESOLVED(ret, "Unable to init mutex"); } ret = pthread_cond_init(&(data.cnd), &ca); if (ret != 0) { UNRESOLVED(ret, "Unable to initialize condvar"); } ret = pthread_mutexattr_gettype(&ma, &(data.type)); if (ret != 0) { UNRESOLVED(ret, "Unable to get type from mutex attr"); } #ifdef USE_ALTCLK ret = pthread_condattr_getclock(&ca, &(data.cid)); if (ret != 0) { UNRESOLVED(ret, "Unable to get clock ID from cond attr"); } #else data.cid = CLOCK_REALTIME; #endif data.bool = 0; /** Data is ready, create the thread */ #if VERBOSE > 1 output("Initialization OK, starting thread\n"); #endif ret = pthread_create(&th, NULL, threaded, NULL); if (ret != 0) { UNRESOLVED(ret, "Thread creation failed"); } /** Wait for the thread to be waiting */ do { ret = sem_wait(&(data.semA)); } while ((ret != 0) && (errno == EINTR)); if (ret != 0) { UNRESOLVED(errno, "Sem wait failed in main"); } ret = pthread_mutex_lock(&(data.mtx)); if (ret != 0) { UNRESOLVED(ret, "Unable to lock mutex in main"); } data.bool = 1; /** Cancel the thread */ ret = pthread_cancel(th); if (ret != 0) { UNRESOLVED(ret, "Thread cancelation failed"); } sched_yield(); #ifndef WITHOUT_XOPEN usleep(100); #endif ret = pthread_mutex_unlock(&(data.mtx)); if (ret != 0) { UNRESOLVED(ret, "Unable to unlock mutex in main"); } /** Wait for the thread to be executing second cleanup handler */ do { ret = sem_wait(&(data.semA)); } while ((ret != 0) && (errno == EINTR)); if (ret != 0) { UNRESOLVED(errno, "Sem wait failed in main"); } /** Here the child should own the mutex, we check this */ ret = pthread_mutex_trylock(&(data.mtx)); if (ret == 0) { FAILED("The child did not own the mutex inside the cleanup handler"); } /** Let the cleanups go on */ do { ret = sem_post(&(data.semB)); } while ((ret != 0) && (errno == EINTR)); if (ret != 0) { UNRESOLVED(errno, "Sem post failed in main"); } /** Join the thread */ ret = pthread_join(th, &rc); if (ret != 0) { UNRESOLVED(ret, "Unable to join the thread"); } if (rc != PTHREAD_CANCELED) { FAILED("thread was not canceled"); } #if VERBOSE > 1 output("Test passed for %s\n", scenar[i].descr); #endif /* Destroy datas */ ret = pthread_cond_destroy(&(data.cnd)); if (ret != 0) { UNRESOLVED(ret, "Cond destroy failed"); } ret = pthread_mutex_destroy(&(data.mtx)); if (ret != 0) { UNRESOLVED(ret, "Mutex destroy failed"); } ret = pthread_condattr_destroy(&ca); if (ret != 0) { UNRESOLVED(ret, "Cond attribute destroy failed"); } ret = pthread_mutexattr_destroy(&ma); if (ret != 0) { UNRESOLVED(ret, "Mutex attr destroy failed"); } } /* Proceed to next case */ ret = sem_destroy(&(data.semA)); if (ret != 0) { UNRESOLVED(errno, "Sem destroy failed"); } ret = sem_destroy(&(data.semB)); if (ret != 0) { UNRESOLVED(errno, "Sem destroy failed"); } PASSED; } posixtestsuite/conformance/interfaces/pthread_cond_timedwait/4-1.c0100644000000000000000000000410407654036335024466 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: bing.wei.liu REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_cond_timedwait() * shall return ETIMEDOUT if the time specified by 'abstime' has passed. * */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include "posixtest.h" #define TIMEOUT 3 struct testdata { pthread_mutex_t mutex; pthread_cond_t cond; } td; void *t1_func(void *arg) { int rc; struct timespec timeout; struct timeval curtime; if (pthread_mutex_lock(&td.mutex) != 0) { fprintf(stderr,"Thread1 failed to acquire the mutex\n"); exit(PTS_UNRESOLVED); } fprintf(stderr,"Thread1 started\n"); if (gettimeofday(&curtime, NULL) !=0 ) { fprintf(stderr,"Fail to get current time\n"); exit(PTS_UNRESOLVED); } timeout.tv_sec = curtime.tv_sec + TIMEOUT; timeout.tv_nsec = curtime.tv_usec * 1000; fprintf(stderr,"Thread1 is waiting for the cond for %d seconds\n", TIMEOUT); rc = pthread_cond_timedwait(&td.cond, &td.mutex, &timeout); if (rc == ETIMEDOUT) { fprintf(stderr,"Thread1 stops waiting when time is out\n"); printf("Test PASSED\n"); exit(PTS_PASS); } else { fprintf(stderr,"pthread_cond_timedwait return %d instead of ETIMEDOUT\n", rc); printf("Test FAILED\n"); exit(PTS_FAIL); } } int main() { pthread_t thread1; int th_ret; if (pthread_mutex_init(&td.mutex, NULL) != 0) { fprintf(stderr,"Fail to initialize mutex\n"); return PTS_UNRESOLVED; } if (pthread_cond_init(&td.cond, NULL) != 0) { fprintf(stderr,"Fail to initialize cond\n"); return PTS_UNRESOLVED; } if (pthread_create(&thread1, NULL, t1_func, NULL) != 0) { fprintf(stderr,"Fail to create thread 1\n"); return PTS_UNRESOLVED; } fprintf(stderr,"Main: no condition is going to be met\n"); pthread_join(thread1, (void*)&th_ret); return th_ret; } posixtestsuite/conformance/interfaces/pthread_cond_timedwait/1-1.c0100644000000000000000000000571107654036332024465 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: bing.wei.liu REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_cond_timedwait() * shall block on a condition variable. It shall be called with mutex locked * by the calling thread or undefined behavior results. */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include "posixtest.h" #define TIMEOUT 5 struct testdata { pthread_mutex_t mutex; pthread_cond_t cond; } td; int t1_start = 0; int signaled = 0; void *t1_func(void *arg) { int rc; struct timespec timeout; struct timeval curtime; if (pthread_mutex_lock(&td.mutex) != 0) { fprintf(stderr,"Thread1: Fail to acquire mutex\n"); exit(PTS_UNRESOLVED); } fprintf(stderr,"Thread1 started\n"); t1_start = 1; /* let main thread continue */ if (gettimeofday(&curtime, NULL) !=0 ) { fprintf(stderr,"Fail to get current time\n"); exit(PTS_UNRESOLVED); } timeout.tv_sec = curtime.tv_sec; timeout.tv_nsec = curtime.tv_usec * 1000; timeout.tv_sec += TIMEOUT; fprintf(stderr,"Thread1 is waiting for the cond\n"); rc = pthread_cond_timedwait(&td.cond, &td.mutex, &timeout); if(rc != 0) { if (rc == ETIMEDOUT) { fprintf(stderr,"Thread1 stops waiting when time is out\n"); exit(PTS_UNRESOLVED); } else { fprintf(stderr,"pthread_cond_timedwait return %d\n", rc); exit(PTS_UNRESOLVED); } } fprintf(stderr,"Thread1 wakened up\n"); if(signaled == 0) { fprintf(stderr,"Thread1 did not block on the cond at all\n"); printf("Test FAILED\n"); exit(PTS_FAIL); } pthread_mutex_unlock(&td.mutex); return NULL; } int main() { pthread_t thread1; if (pthread_mutex_init(&td.mutex, NULL) != 0) { fprintf(stderr,"Fail to initialize mutex\n"); return PTS_UNRESOLVED; } if (pthread_cond_init(&td.cond, NULL) != 0) { fprintf(stderr,"Fail to initialize cond\n"); return PTS_UNRESOLVED; } if (pthread_create(&thread1, NULL, t1_func, NULL) != 0) { fprintf(stderr,"Fail to create thread 1\n"); return PTS_UNRESOLVED; } while(!t1_start) /* wait for thread1 started */ usleep(100); /* acquire the mutex released by pthread_cond_wait() within thread 1 */ if (pthread_mutex_lock(&td.mutex) != 0) { fprintf(stderr,"Main: Fail to acquire mutex\n"); return PTS_UNRESOLVED; } if (pthread_mutex_unlock(&td.mutex) != 0) { fprintf(stderr,"Main: Fail to release mutex\n"); return PTS_UNRESOLVED; } sleep(1); fprintf(stderr,"Time to wake up thread1 by signaling a condition\n"); signaled = 1; if (pthread_cond_signal(&td.cond) != 0) { fprintf(stderr,"Main: Fail to signal cond\n"); return PTS_UNRESOLVED; } pthread_join(thread1, NULL); printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_cond_timedwait/testfrmw.c0100644000000000000000000000343610066714721026040 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * * This file is a wrapper to use the tests from the NPTL Test & Trace Project * with either the Linux Test Project or the Open POSIX Test Suite. * The following function are defined: * void output_init() * void output_fini() * void output(char * string, ...) * * The are used to output informative text (as a printf). */ /* We use a mutex to avoid conflicts in traces */ static pthread_mutex_t m_trace = PTHREAD_MUTEX_INITIALIZER; /*****************************************************************************************/ /******************************* stdout module *****************************************/ /*****************************************************************************************/ /* The following functions will output to stdout */ #if (1) void output_init() { /* do nothing */ return; } void output( char * string, ... ) { va_list ap; pthread_mutex_lock(&m_trace); va_start( ap, string); vprintf(string, ap); va_end(ap); pthread_mutex_unlock(&m_trace); } void output_fini() { /*do nothing */ return; } #endif posixtestsuite/conformance/interfaces/pthread_cond_timedwait/4-3.c0100644000000000000000000002237610336125321024464 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertion: * * This sample test aims to check the following assertion: * The function does not return an error code of EINTR * The steps are: * * -> Create a thread which wait in a condition for a small time. * -> Another thread will signal this condition from time to time. * -> Another thread which loops on sending a signal to the first thread. * */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /********************************************************************************************/ /****************************** standard includes *****************************************/ /********************************************************************************************/ #include #include #include #include #include #include #include #include #include /********************************************************************************************/ /****************************** Test framework *****************************************/ /********************************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /********************************************************************************************/ /********************************** Configuration ******************************************/ /********************************************************************************************/ #define WITH_SYNCHRO #ifndef VERBOSE #define VERBOSE 2 #endif #define TIMEOUT (1000) /* ns, timeout parameter for pthread_cond_timedwait */ #define INTERVAL (700) /* ns, frequency (actually, period) for the condition signaling */ /********************************************************************************************/ /*********************************** Test case *****************************************/ /********************************************************************************************/ char do_it=1; unsigned long count_cnd_sig=0, count_cnd_wup=0; #ifdef WITH_SYNCHRO sem_t semsig1; sem_t semsig2; unsigned long count_sig=0; #endif sigset_t usersigs; typedef struct { int sig; #ifdef WITH_SYNCHRO sem_t *sem; #endif } thestruct; struct { pthread_mutex_t mtx; pthread_cond_t cnd; } data; /* the following function keeps on sending the signal to the process */ void * sendsig (void * arg) { thestruct *thearg = (thestruct *) arg; int ret; pid_t process; process=getpid(); /* We block the signals SIGUSR1 and SIGUSR2 for this THREAD */ ret = pthread_sigmask(SIG_BLOCK, &usersigs, NULL); if (ret != 0) { UNRESOLVED(ret, "Unable to block SIGUSR1 and SIGUSR2 in signal thread"); } while (do_it) { #ifdef WITH_SYNCHRO if ((ret = sem_wait(thearg->sem))) { UNRESOLVED(errno, "Sem_wait in sendsig"); } count_sig++; #endif ret = kill(process, thearg->sig); if (ret != 0) { UNRESOLVED(errno, "Kill in sendsig"); } } return NULL; } /* Next are the signal handlers. */ /* This one is registered for signal SIGUSR1 */ void sighdl1(int sig) { #ifdef WITH_SYNCHRO if (sem_post(&semsig1)) { UNRESOLVED(errno, "Sem_post in signal handler 1"); } #endif } /* This one is registered for signal SIGUSR2 */ void sighdl2(int sig) { #ifdef WITH_SYNCHRO if (sem_post(&semsig2)) { UNRESOLVED(errno, "Sem_post in signal handler 2"); } #endif } /* The following function will timedwait on the cond * it does check that no error code of EINTR is returned */ void * waiter(void * arg) { int ret; struct timespec ts; /* We don't block the signals SIGUSR1 and SIGUSR2 for this THREAD */ ret = pthread_sigmask(SIG_UNBLOCK, &usersigs, NULL); if (ret != 0) { UNRESOLVED(ret, "Unable to unblock SIGUSR1 and SIGUSR2 in worker thread"); } ret = pthread_mutex_lock(&(data.mtx)); if (ret != 0) { UNRESOLVED(ret, "Unable to lock mutex in waiter thread"); } while (do_it) { ret = clock_gettime(CLOCK_REALTIME, &ts); if (ret != 0) { UNRESOLVED(ret, "Unable to get system time"); } ts.tv_nsec += TIMEOUT; while (ts.tv_nsec >= 1000000000) { ts.tv_nsec -= 1000000000; ts.tv_sec += 1; } do { ret = pthread_cond_timedwait(&(data.cnd),&(data.mtx),&ts); count_cnd_wup++; } while (ret == 0); if (ret == EINTR) { FAILED("pthread_cond_timedwait returned EINTR"); } if (ret != ETIMEDOUT) { UNRESOLVED(ret, "pthread_cond_timedwait returned an unexpected error"); } } ret = pthread_mutex_unlock(&(data.mtx)); if (ret != 0) { UNRESOLVED(ret, "Unable to unlock mutex in waiter thread"); } return NULL; } /* The next function will signal the condition at periodic interval */ void * worker (void * arg) { int ret=0; struct timespec ts, tsrem; /* We block the signals SIGUSR1 and SIGUSR2 for this THREAD */ ret = pthread_sigmask(SIG_BLOCK, &usersigs, NULL); if (ret != 0) { UNRESOLVED(ret, "Unable to block SIGUSR1 and SIGUSR2 in signal thread"); } ts.tv_sec=0; ts.tv_nsec= INTERVAL; while (ts.tv_nsec >= 1000000000) { ts.tv_nsec -= 1000000000; ts.tv_sec +=1; } while (do_it) { tsrem.tv_sec = ts.tv_sec; tsrem.tv_nsec = ts.tv_nsec; do { ret = nanosleep(&tsrem, &tsrem); } while ((ret != 0) && (errno == EINTR)); ret = pthread_cond_signal(&(data.cnd)); if (ret != 0) { UNRESOLVED(ret, "Failed to signal the condition"); } count_cnd_sig++; } return NULL; } /* Main function */ int main (int argc, char * argv[]) { int ret; pthread_t th_waiter, th_worker, th_sig1, th_sig2; thestruct arg1, arg2; struct sigaction sa; output_init(); /* We need to register the signal handlers for the PROCESS */ sigemptyset (&sa.sa_mask); sa.sa_flags = 0; sa.sa_handler = sighdl1; if ((ret = sigaction (SIGUSR1, &sa, NULL))) { UNRESOLVED(ret, "Unable to register signal handler1"); } sa.sa_handler = sighdl2; if ((ret = sigaction (SIGUSR2, &sa, NULL))) { UNRESOLVED(ret, "Unable to register signal handler2"); } /* We prepare a signal set which includes SIGUSR1 and SIGUSR2 */ sigemptyset(&usersigs); ret = sigaddset(&usersigs, SIGUSR1); ret |= sigaddset(&usersigs, SIGUSR2); if (ret != 0) { UNRESOLVED(ret, "Unable to add SIGUSR1 or 2 to a signal set"); } /* We now block the signals SIGUSR1 and SIGUSR2 for this THREAD */ ret = pthread_sigmask(SIG_BLOCK, &usersigs, NULL); if (ret != 0) { UNRESOLVED(ret, "Unable to block SIGUSR1 and SIGUSR2 in main thread"); } #ifdef WITH_SYNCHRO if (sem_init(&semsig1, 0, 1)) { UNRESOLVED(errno, "Semsig1 init"); } if (sem_init(&semsig2, 0, 1)) { UNRESOLVED(errno, "Semsig2 init"); } #endif if ((ret = pthread_create(&th_waiter, NULL, waiter, NULL))) { UNRESOLVED(ret, "Waiter thread creation failed"); } if ((ret = pthread_create(&th_worker, NULL, worker, NULL))) { UNRESOLVED(ret, "Worker thread creation failed"); } arg1.sig = SIGUSR1; arg2.sig = SIGUSR2; #ifdef WITH_SYNCHRO arg1.sem = &semsig1; arg2.sem = &semsig2; #endif if ((ret = pthread_create(&th_sig1, NULL, sendsig, (void *)&arg1))) { UNRESOLVED(ret, "Signal 1 sender thread creation failed"); } if ((ret = pthread_create(&th_sig2, NULL, sendsig, (void *)&arg2))) { UNRESOLVED(ret, "Signal 2 sender thread creation failed"); } /* Let's wait for a while now */ sleep(1); /* Now stop the threads and join them */ do { do_it=0; } while (do_it); if ((ret = pthread_join(th_sig1, NULL))) { UNRESOLVED(ret, "Signal 1 sender thread join failed"); } if ((ret = pthread_join(th_sig2, NULL))) { UNRESOLVED(ret, "Signal 2 sender thread join failed"); } if ((ret = pthread_join(th_worker, NULL))) { UNRESOLVED(ret, "Worker thread join failed"); } if ((ret = pthread_join(th_waiter, NULL))) { UNRESOLVED(ret, "Waiter thread join failed"); } #if VERBOSE > 0 output("Test executed successfully.\n"); output(" Condition was signaled %d times.\n", count_cnd_sig); output(" pthread_timed_wait exited %d times.\n", count_cnd_wup); #ifdef WITH_SYNCHRO output(" %d signals were sent meanwhile.\n", count_sig); #endif #endif PASSED; } posixtestsuite/conformance/interfaces/pthread_cond_timedwait/assertions.xml0100644000000000000000000000311610055306234026722 0ustar rootroot The function int pthread_cond_timedwait(pthread_cond_t *restrict cond, pthread_mutex_t *restrict mutex); const struct timespec *restrict abstime); shall block on a condition variable. It shall be called with mutex locked by the calling thread or undefined behavior results. The pthread_cond_timedwait() function shall be equivalent to pthread_cond_wait(), except that an error is returned if the absolute time specified by abstime passes (that is, system time equals or exceeds abstime) before the condition cond is signaled or broadcasted, or if the absolute time specified by abstime has already been passed at the time of the call. Upon successful completion, a value of zero shall be returned; The pthread_cond_timedwait() function shall fail if: [ETIMEDOUT] The time specified by 'abstime' has passed. The pthread_cond_timedwait() function may fail if: [EINVAL] The value specified by cond, mutex,or abstime is invalid. [EINVAL] Different mutexes were supplied for concurrent pthread_cond_timedwait() or pthread_cond_wait() operations on the same condition variable. [EPERM] The mutex was not owned by the current thread at the time of the call. These functions shall not return an error code of [EINTR]. posixtestsuite/conformance/interfaces/pthread_cond_timedwait/coverage.txt0100644000000000000000000000063310066714721026351 0ustar rootrootThis document defines the coverage for the pthread_cond_timedwait function: Assertion Tested? 1 YES 2 YES *2-2 and 2-3 seem to pass but hang on nptl 0.36 3 YES 4 YES * When it specifies it 'may' fail and not 'shall' fail, it will always return PASS, but will return a PASS and print out a warning if it fails. * Tested EINVAL when abs time spec is invalid * Tested EINTR NOTE: posixtestsuite/conformance/interfaces/pthread_cond_timedwait/testfrmw.h0100644000000000000000000000456410066714721026050 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * * This file is a wrapper to use the tests from the NPTL Test & Trace Project * with either the Linux Test Project or the Open POSIX Test Suite. * The following macros are defined here: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate without calling one of those macros. * * */ #include "posixtest.h" #include /* for the strerror() routine */ #ifdef __GNUC__ /* We are using GCC */ #define UNRESOLVED(x, s) \ { output("Test %s unresolved: got %i (%s) on line %i (%s)\n", __FILE__, x, strerror(x), __LINE__, s); \ output_fini(); \ exit(PTS_UNRESOLVED); } #define FAILED(s) \ { output("Test %s FAILED: %s\n", __FILE__, s); \ output_fini(); \ exit(PTS_FAIL); } #define PASSED \ output_fini(); \ exit(PTS_PASS); #define UNTESTED(s) \ { output("File %s cannot test: %s\n", __FILE__, s); \ output_fini(); \ exit(PTS_UNTESTED); \ } #else /* not using GCC */ #define UNRESOLVED(x, s) \ { output("Test unresolved: got %i (%s) on line %i (%s)\n", x, strerror(x), __LINE__, s); \ output_fini(); \ exit(PTS_UNRESOLVED); } #define FAILED(s) \ { output("Test FAILED: %s\n", s); \ output_fini(); \ exit(PTS_FAIL); } #define PASSED \ output_fini(); \ exit(PTS_PASS); #define UNTESTED(s) \ { output("Unable to test: %s\n", s); \ output_fini(); \ exit(PTS_UNTESTED); \ } #endif posixtestsuite/conformance/interfaces/pthread_cond_timedwait/2-5.c0100644000000000000000000003076310310031511024450 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertion: * * While a thread is blocked on a conditionnal variable, * a dynamic binding exists between this conditionnal variable * and the mutex which was the second argument. * This dynamic binding stops existing when the last thread is unblocked. * Even if the conditionnal variable can then be reused with another mutex, * the threads which have been unblocked must still acquire * the mutex they had associated with the conditionnal variable at call time. * * The steps are: * -> Create two mutexes m1 and m2 (errorcheck or recursive) * -> Create a condition variable c depending on a bootlean b * -> create N threads which will * -> lock m1 * -> wait or timedwait c, m1 (while b is false) * -> check it owns m1 (check depends on the mutex type) * -> lock m2 * -> wait or timedwait c, m2 (while b is false) * -> check it owns m2 * -> mark this thread as terminate * -> Once all threads are waiting on (c,m1), * mark b as true then broadcast c until all threads are terminated. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /* We need the XSI extention for the mutex attributes */ #ifndef WITHOUT_XOPEN #define _XOPEN_SOURCE 600 #endif /********************************************************************************************/ /****************************** standard includes *****************************************/ /********************************************************************************************/ #include #include #include #include #include #include /********************************************************************************************/ /****************************** Test framework *****************************************/ /********************************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /********************************************************************************************/ /********************************** Configuration ******************************************/ /********************************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif #define NTHREADS (100) #ifndef WITHOUT_ALTCLK #define USE_ALTCLK /* make tests with MONOTONIC CLOCK if supported */ #endif /********************************************************************************************/ /*********************************** Test case *****************************************/ /********************************************************************************************/ #ifndef WITHOUT_XOPEN struct _td { pthread_mutex_t mtx1, mtx2; /* The two mutex m1 and m2 */ pthread_cond_t cnd; /* The cond var c */ char boolcnd; /* The boolean predicate b associated with c */ int type; /* Type of mutex */ clockid_t cid; /* Clock used by cond c */ int started; /* # of threads which are already waiting */ int stopped; /* # of threads which are terminated */ } data; void * threaded ( void * arg ) { int ret; struct timespec ts; /* Prepare the timeout parameter */ ret = clock_gettime(data.cid, &ts); if (ret != 0) { UNRESOLVED(ret, "Unable to get time from clock"); } ts.tv_sec += 30; /* Lock m1 */ ret = pthread_mutex_lock(&(data.mtx1)); if (ret != 0) { UNRESOLVED(ret, "Unable tu lock m1 in thread"); } /* Tell the parent this thread is started */ data.started++; /* wait for the cond - bind the cond to the mutex m1 */ do { if (arg == (void *)0) ret = pthread_cond_wait(&(data.cnd), &(data.mtx1)); else ret = pthread_cond_timedwait(&(data.cnd), &(data.mtx1), &ts); } while ((ret == 0) && (data.boolcnd == 0)); if (ret != 0) { UNRESOLVED(ret, "First wait failed in thread"); } /* Test ownership and unlock m1 */ if (data.type == PTHREAD_MUTEX_RECURSIVE) { ret = pthread_mutex_trylock(&(data.mtx1)); if (ret != 0) { FAILED("Unable to re-lock recursive mutex after cond wait"); } ret = pthread_mutex_unlock(&(data.mtx1)); if (ret != 0) { UNRESOLVED(ret, "Mutex unlock failed"); } } ret = pthread_mutex_unlock(&(data.mtx1)); if (ret != 0) { FAILED("Unable to unlock m1 in thread - not owner?"); } ret = pthread_mutex_unlock(&(data.mtx1)); if (ret == 0) { FAILED("Unlocking an unlocked mutex succeeded"); } /* Failed while this is not a default mutex */ /* Lock m2 */ ret = pthread_mutex_lock(&(data.mtx2)); if (ret != 0) { UNRESOLVED(ret, "Unable tu lock m2 in thread"); } /* wait for the cond - bind the cond to the mutex m2 */ do { if (arg == (void *)0) ret = pthread_cond_wait(&(data.cnd), &(data.mtx2)); else ret = pthread_cond_timedwait(&(data.cnd), &(data.mtx2), &ts); } while ((ret == 0) && (data.boolcnd == 0)); if (ret != 0) { UNRESOLVED(ret, "Second wait failed in thread"); } /* Mark the thread as terminated while we are protected by m2 */ data.stopped++; /* Test ownership and unlock m2*/ if (data.type == PTHREAD_MUTEX_RECURSIVE) { ret = pthread_mutex_trylock(&(data.mtx2)); if (ret != 0) { FAILED("Unable to re-lock recursive mutex after cond wait"); } ret = pthread_mutex_unlock(&(data.mtx2)); if (ret != 0) { UNRESOLVED(ret, "Mutex unlock failed"); } } ret = pthread_mutex_unlock(&(data.mtx2)); if (ret != 0) { FAILED("Unable to unlock m2 in thread - not owner?"); } ret = pthread_mutex_unlock(&(data.mtx2)); if (ret == 0) { FAILED("Unlocking an unlocked mutex succeeded"); } /* Failed while this is not a default mutex */ return NULL; } int main(int argc, char * argv[]) { int ret, i, j; pthread_mutexattr_t ma; pthread_condattr_t ca; pthread_t th[NTHREADS]; int loc_started, loc_stopped; long altclk_ok, pshared_ok; struct { char altclk; /* Want to use alternative clock */ char pshared; /* Want to use process-shared primitives */ int type; /* mutex type */ char * descr; /* Description of the case */ } scenar[] = { {0, 0, PTHREAD_MUTEX_RECURSIVE , "Recursive mutex" } ,{0, 0, PTHREAD_MUTEX_ERRORCHECK, "Errorcheck mutex" } #ifdef USE_ALTCLK ,{1, 0, PTHREAD_MUTEX_RECURSIVE , "Recursive mutex + altclock cond" } ,{1, 0, PTHREAD_MUTEX_ERRORCHECK, "Errorcheck mutex + altclock cond" } ,{1, 1, PTHREAD_MUTEX_RECURSIVE , "Recursive pshared mutex + altclock cond" } ,{1, 1, PTHREAD_MUTEX_ERRORCHECK, "Errorcheck pshared mutex + altclock cond" } #endif ,{0, 1, PTHREAD_MUTEX_RECURSIVE , "Recursive pshared mutex" } ,{0, 1, PTHREAD_MUTEX_ERRORCHECK, "Errorcheck pshared mutex" } }; output_init(); /* Initialize the constants */ altclk_ok = sysconf(_SC_CLOCK_SELECTION); if (altclk_ok > 0) altclk_ok = sysconf(_SC_MONOTONIC_CLOCK); #ifndef USE_ALTCLK if (altclk_ok > 0) output("Implementation supports the MONOTONIC CLOCK but option is disabled in test.\n"); #endif pshared_ok = sysconf(_SC_THREAD_PROCESS_SHARED); #if VERBOSE > 0 output("Test starting\n"); output(" Process-shared primitive %s be tested\n", (pshared_ok>0)?"will":"won't"); output(" Alternative clock for cond %s be tested\n", (altclk_ok>0)?"will":"won't"); #endif for (i=0; i< (sizeof(scenar) / sizeof(scenar[0])); i++) { #if VERBOSE > 1 output("Starting test for %s\n", scenar[i].descr); #endif /* Initialize the data structure */ ret = pthread_mutexattr_init(&ma); if (ret != 0) { UNRESOLVED(ret, "Mutex attribute object init failed"); } ret = pthread_mutexattr_settype(&ma, scenar[i].type); if (ret != 0) { UNRESOLVED(ret, "Unable to set mutex type"); } if ((pshared_ok > 0) && (scenar[i].pshared != 0)) { ret = pthread_mutexattr_setpshared(&ma, PTHREAD_PROCESS_SHARED); if (ret != 0) { UNRESOLVED(ret, "Unable to set mutex process-shared"); } } ret = pthread_condattr_init(&ca); if (ret != 0) { UNRESOLVED(ret, "Cond attribute object init failed"); } if ((pshared_ok > 0) && (scenar[i].pshared != 0)) { ret = pthread_condattr_setpshared(&ca, PTHREAD_PROCESS_SHARED); if (ret != 0) { UNRESOLVED(ret, "Unable to set cond process-shared"); } } #ifdef USE_ALTCLK if ((altclk_ok > 0) && (scenar[i].altclk != 0)) { ret = pthread_condattr_setclock(&ca, CLOCK_MONOTONIC); if (ret != 0) { UNRESOLVED(ret, "Unable to set alternative (monotonic) clock for cond"); } } #endif ret = pthread_mutex_init(&(data.mtx1), &ma); if (ret != 0) { UNRESOLVED(ret, "Unable to init mutex 1"); } ret = pthread_mutex_init(&(data.mtx2), &ma); if (ret != 0) { UNRESOLVED(ret, "Unable to init mutex 2"); } ret = pthread_cond_init(&(data.cnd), &ca); if (ret != 0) { UNRESOLVED(ret, "Unable to initialize condvar"); } data.boolcnd = 0; ret = pthread_mutexattr_gettype(&ma, &(data.type)); if (ret != 0) { UNRESOLVED(ret, "Unable to get type from mutex attr"); } #ifdef USE_ALTCLK ret = pthread_condattr_getclock(&ca, &(data.cid)); if (ret != 0) { UNRESOLVED(ret, "Unable to get clock ID from cond attr"); } #else data.cid = CLOCK_REALTIME; #endif data.started = 0; data.stopped = 0; /* Start the threads */ #if VERBOSE > 1 output("Initialization OK, starting threads\n"); #endif for (j = 0; j < NTHREADS; j++) { ret = pthread_create(&th[j], NULL, threaded, (void *)(long)(j & 1)); if (ret != 0) { UNRESOLVED(ret, "Thread creation failed"); } } /* Wait for the threads to be started */ do { ret = pthread_mutex_lock(&(data.mtx1)); if (ret != 0) { UNRESOLVED(ret, "Unable to lock m1 in parent"); } loc_started = data.started; ret = pthread_mutex_unlock(&(data.mtx1)); if (ret != 0) { UNRESOLVED(ret, "Unable to unlock m1 in parent"); } } while (loc_started < NTHREADS); /* Broadcast the condition until all threads are terminated */ data.boolcnd = 1; do { ret = pthread_cond_broadcast(&(data.cnd)); if (ret != 0) { UNRESOLVED(ret, "Unable to broadcast cnd"); } sched_yield(); ret = pthread_mutex_lock(&(data.mtx2)); if (ret != 0) { UNRESOLVED(ret, "Unable to lock m2 in parent"); } loc_stopped = data.stopped; ret = pthread_mutex_unlock(&(data.mtx2)); if (ret != 0) { UNRESOLVED(ret, "Unable to unlock m2 in parent"); } } while (loc_stopped < NTHREADS); /* Join the threads */ for (j = 0; j < NTHREADS; j++) { ret = pthread_join(th[j], NULL); if (ret != 0) { UNRESOLVED(ret, "Thread join failed"); } } #if VERBOSE > 1 output("Test passed for %s\n", scenar[i].descr); #endif /* Destroy data */ ret = pthread_cond_destroy(&(data.cnd)); if (ret != 0) { UNRESOLVED(ret, "Cond destroy failed"); } ret = pthread_mutex_destroy(&(data.mtx1)); if (ret != 0) { UNRESOLVED(ret, "Mutex 1 destroy failed"); } ret = pthread_mutex_destroy(&(data.mtx2)); if (ret != 0) { UNRESOLVED(ret, "Mutex 2 destroy failed"); } ret = pthread_condattr_destroy(&ca); if (ret != 0) { UNRESOLVED(ret, "Cond attribute destroy failed"); } ret = pthread_mutexattr_destroy(&ma); if (ret != 0) { UNRESOLVED(ret, "Mutex attr destroy failed"); } } /* Proceed to next case */ PASSED; } #else /* WITHOUT_XOPEN */ int main(int argc, char * argv[]) { output_init(); UNTESTED("This test requires XSI features"); } #endif posixtestsuite/conformance/interfaces/pthread_cond_timedwait/4-2.c0100644000000000000000000004211710066714721024466 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertion: * * When the abstime parameter is invalid, * the function must return EINVAL and * the mutex state must not have changed during the call. * The steps are: * -> parent (for each mutex type and each condvar options, across threads or processes) * -> locks the mutex m * -> sets ctrl = 0 * -> creates a bunch of children, which: * -> lock the mutex m * -> if ctrl == 0, test has failed * -> unlock the mutex then exit * -> calls pthread_cond_timedwait with invalid values (nsec > 999999999) * -> sets ctrl = non-zero value * -> unlocks the mutex m */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /* We need the XSI extention for the mutex attributes and the mkstemp() routine */ #ifndef WITHOUT_XOPEN #define _XOPEN_SOURCE 600 #endif /********************************************************************************************/ /****************************** standard includes *****************************************/ /********************************************************************************************/ #include #include #include #include #include #include #include #include #include #include /********************************************************************************************/ /****************************** Test framework *****************************************/ /********************************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /********************************************************************************************/ /********************************** Configuration ******************************************/ /********************************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif #define NCHILDREN (20) #ifndef WITHOUT_ALTCLK #define USE_ALTCLK /* make tests with MONOTONIC CLOCK if supported */ #endif /********************************************************************************************/ /*********************************** Test case *****************************************/ /********************************************************************************************/ #ifndef WITHOUT_XOPEN typedef struct { pthread_mutex_t mtx; int ctrl; /* Control value */ int gotit; /* Thread locked the mutex while ctrl == 0 */ int status; /* error code */ } testdata_t; struct _scenar { int m_type; /* Mutex type to use */ int mc_pshared; /* 0: mutex and cond are process-private (default) ~ !0: Both are process-shared, if supported */ int c_clock; /* 0: cond uses the default clock. ~ !0: Cond uses monotonic clock, if supported. */ int fork; /* 0: Test between threads. ~ !0: Test across processes, if supported (mmap) */ char * descr; /* Case description */ } scenarii[] = { {PTHREAD_MUTEX_DEFAULT, 0, 0, 0, "Default mutex"} ,{PTHREAD_MUTEX_NORMAL, 0, 0, 0, "Normal mutex"} ,{PTHREAD_MUTEX_ERRORCHECK, 0, 0, 0, "Errorcheck mutex"} ,{PTHREAD_MUTEX_RECURSIVE, 0, 0, 0, "Recursive mutex"} ,{PTHREAD_MUTEX_DEFAULT, 1, 0, 0, "PShared default mutex"} ,{PTHREAD_MUTEX_NORMAL, 1, 0, 0, "Pshared normal mutex"} ,{PTHREAD_MUTEX_ERRORCHECK, 1, 0, 0, "Pshared errorcheck mutex"} ,{PTHREAD_MUTEX_RECURSIVE, 1, 0, 0, "Pshared recursive mutex"} ,{PTHREAD_MUTEX_DEFAULT, 1, 0, 1, "Pshared default mutex across processes"} ,{PTHREAD_MUTEX_NORMAL, 1, 0, 1, "Pshared normal mutex across processes"} ,{PTHREAD_MUTEX_ERRORCHECK, 1, 0, 1, "Pshared errorcheck mutex across processes"} ,{PTHREAD_MUTEX_RECURSIVE, 1, 0, 1, "Pshared recursive mutex across processes"} #ifdef USE_ALTCLK ,{PTHREAD_MUTEX_DEFAULT, 1, 1, 1, "Pshared default mutex and alt clock condvar across processes"} ,{PTHREAD_MUTEX_NORMAL, 1, 1, 1, "Pshared normal mutex and alt clock condvar across processes"} ,{PTHREAD_MUTEX_ERRORCHECK, 1, 1, 1, "Pshared errorcheck mutex and alt clock condvar across processes"} ,{PTHREAD_MUTEX_RECURSIVE, 1, 1, 1, "Pshared recursive mutex and alt clock condvar across processes"} ,{PTHREAD_MUTEX_DEFAULT, 0, 1, 0, "Default mutex and alt clock condvar"} ,{PTHREAD_MUTEX_NORMAL, 0, 1, 0, "Normal mutex and alt clock condvar"} ,{PTHREAD_MUTEX_ERRORCHECK, 0, 1, 0, "Errorcheck mutex and alt clock condvar"} ,{PTHREAD_MUTEX_RECURSIVE, 0, 1, 0, "Recursive mutex and alt clock condvar"} ,{PTHREAD_MUTEX_DEFAULT, 1, 1, 0, "PShared default mutex and alt clock condvar"} ,{PTHREAD_MUTEX_NORMAL, 1, 1, 0, "Pshared normal mutex and alt clock condvar"} ,{PTHREAD_MUTEX_ERRORCHECK, 1, 1, 0, "Pshared errorcheck mutex and alt clock condvar"} ,{PTHREAD_MUTEX_RECURSIVE, 1, 1, 0, "Pshared recursive mutex and alt clock condvar"} #endif }; struct { long sec_val; /* Value for seconds */ short sec_is_offset; /* Seconds value is added to current time or is absolute */ long nsec_val; /* Value for nanoseconds */ short nsec_is_offset; /* Nanoseconds value is added to current time or is absolute */ } junks_ts[]={ { -2 , 1, 1000000000, 1 } ,{ -2 , 1, -1, 0 } ,{ -3 , 1, 2000000000, 0 } }; void * tf(void * arg) { int ret=0; testdata_t * td = (testdata_t *)arg; /* Lock the mutex */ ret = pthread_mutex_lock(&(td->mtx)); if (ret != 0) { td->status = ret; UNRESOLVED(ret, "[child] Unable to lock the mutex"); } /* Checks whether the parent release the lock inside the timedwait function */ if (td->ctrl == 0) td->gotit += 1; /* Unlock and exit */ ret = pthread_mutex_unlock(&(td->mtx)); if (ret != 0) { td->status=ret; UNRESOLVED(ret, "[child] Failed to unlock the mutex."); } return NULL; } int main(int argc, char * argv[]) { int ret, i, j, k; pthread_mutexattr_t ma; pthread_condattr_t ca; pthread_cond_t cnd; clockid_t cid = CLOCK_REALTIME; struct timespec ts, ts_junk; testdata_t * td; testdata_t alternativ; int do_fork; pid_t child_pr[NCHILDREN], chkpid; int status; pthread_t child_th[NCHILDREN]; long pshared, monotonic, cs, mf; output_init(); pshared = sysconf(_SC_THREAD_PROCESS_SHARED); cs = sysconf(_SC_CLOCK_SELECTION); monotonic = sysconf(_SC_MONOTONIC_CLOCK); mf =sysconf(_SC_MAPPED_FILES); #if VERBOSE > 0 output("Test starting\n"); output("System abilities:\n"); output(" TPS : %li\n", pshared); output(" CS : %li\n", cs); output(" MON : %li\n", monotonic); output(" MF : %li\n", mf); if ((mf < 0) || (pshared < 0)) output("Process-shared attributes won't be tested\n"); if ((cs < 0) || (monotonic < 0)) output("Alternative clock won't be tested\n"); #endif /* We are not interested in testing the clock if we have no other clock available.. */ if (monotonic < 0) cs = -1; #ifndef USE_ALTCLK if (cs > 0) output("Implementation supports the MONOTONIC CLOCK but option is disabled in test.\n"); #endif /********** * Allocate space for the testdata structure */ if (mf < 0) { /* Cannot mmap a file, we use an alternative method */ td = &alternativ; pshared = -1; /* We won't do this testing anyway */ #if VERBOSE > 0 output("Testdata allocated in the process memory.\n"); #endif } else { /* We will place the test data in a mmaped file */ char filename[] = "/tmp/cond_timedwait_2-4-XXXXXX"; size_t sz; void * mmaped; int fd; char * tmp; /* We now create the temp files */ fd = mkstemp(filename); if (fd == -1) { UNRESOLVED(errno, "Temporary file could not be created"); } /* and make sure the file will be deleted when closed */ unlink(filename); #if VERBOSE > 1 output("Temp file created (%s).\n", filename); #endif sz= (size_t)sysconf(_SC_PAGESIZE); tmp = calloc(1, sz); if (tmp == NULL) { UNRESOLVED(errno, "Memory allocation failed"); } /* Write the data to the file. */ if (write (fd, tmp, sz) != (ssize_t) sz) { UNRESOLVED(sz, "Writting to the file failed"); } free(tmp); /* Now we can map the file in memory */ mmaped = mmap(NULL, sz, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); if (mmaped == MAP_FAILED) { UNRESOLVED(errno, "mmap failed"); } td = (testdata_t *) mmaped; /* Our datatest structure is now in shared memory */ #if VERBOSE > 1 output("Testdata allocated in shared memory.\n"); #endif } /********** * For each test scenario, initialize the attributes and other variables. * Do the whole thing for each time to test. */ for ( i=0; i< (sizeof(scenarii) / sizeof(scenarii[0])); i++) { for ( j=0; j< (sizeof(junks_ts) / sizeof(junks_ts[0])); j++) { #if VERBOSE > 1 output("[parent] Preparing attributes for: %s\n", scenarii[i].descr); #endif /* set / reset everything */ do_fork=0; ret = pthread_mutexattr_init(&ma); if (ret != 0) { UNRESOLVED(ret, "[parent] Unable to initialize the mutex attribute object"); } ret = pthread_condattr_init(&ca); if (ret != 0) { UNRESOLVED(ret, "[parent] Unable to initialize the cond attribute object"); } /* Set the mutex type */ ret = pthread_mutexattr_settype(&ma, scenarii[i].m_type); if (ret != 0) { UNRESOLVED(ret, "[parent] Unable to set mutex type"); } #if VERBOSE > 1 output("[parent] Mutex type : %i\n", scenarii[i].m_type); #endif /* Set the pshared attributes, if supported */ if ((pshared > 0) && (scenarii[i].mc_pshared != 0)) { ret = pthread_mutexattr_setpshared(&ma, PTHREAD_PROCESS_SHARED); if (ret != 0) { UNRESOLVED(ret, "[parent] Unable to set the mutex process-shared"); } ret = pthread_condattr_setpshared(&ca, PTHREAD_PROCESS_SHARED); if (ret != 0) { UNRESOLVED(ret, "[parent] Unable to set the cond var process-shared"); } #if VERBOSE > 1 output("[parent] Mutex & cond are process-shared\n"); #endif } #if VERBOSE > 1 else { output("[parent] Mutex & cond are process-private\n"); } #endif /* Set the alternative clock, if supported */ #ifdef USE_ALTCLK if ((cs > 0) && (scenarii[i].c_clock != 0)) { ret = pthread_condattr_setclock(&ca, CLOCK_MONOTONIC); if (ret != 0) { UNRESOLVED(ret, "[parent] Unable to set the monotonic clock for the cond"); } #if VERBOSE > 1 output("[parent] Cond uses the Monotonic clock\n"); #endif } #if VERBOSE > 1 else { output("[parent] Cond uses the default clock\n"); } #endif ret = pthread_condattr_getclock(&ca, &cid); if (ret != 0) { UNRESOLVED(ret, "Unable to get clock from cond attr"); } #endif /* Tell whether the test will be across processes */ if ((pshared > 0) && (scenarii[i].fork != 0)) { do_fork = 1; #if VERBOSE > 1 output("[parent] Child will be a new process\n"); #endif } #if VERBOSE > 1 else { output("[parent] Child will be a new thread\n"); } #endif /* initialize the condvar */ ret = pthread_cond_init(&cnd, &ca); if (ret != 0) { UNRESOLVED(ret, "[parent] Cond init failed"); } /********** * Initialize the testdata_t structure with the previously defined attributes */ /* Initialize the mutex */ ret = pthread_mutex_init(&(td->mtx), &ma); if (ret != 0) { UNRESOLVED(ret, "[parent] Mutex init failed"); } /* Initialize the other datas from the test structure */ td->ctrl=0; td->gotit=0; td->status=0; /********** * Proceed to the actual testing */ /* Lock the mutex before creating children */ ret = pthread_mutex_lock(&(td->mtx)); if (ret != 0) { UNRESOLVED(ret, "[parent] Unable to lock the mutex"); } /* Create the children */ if (do_fork != 0) { /* We are testing across processes */ for (k=0; k 3 output("[child] Child process %i starting...\n", k); #endif if (tf((void *)td) != NULL) { UNRESOLVED( -1, "[child] Got an unexpected return value from test function"); } else { /* We cannot use the PASSED macro here since it would terminate the output */ exit (0); } } } /* Only the parent process goes further */ } else /* do_fork == 0 */ { /* We are testing across two threads */ for (k=0; k 2 output("TS: s = %s%li ; ns = %s%li\n", junks_ts[j].sec_is_offset?"n + ":" ", junks_ts[j].sec_val, junks_ts[j].nsec_is_offset?"n + ":" ", junks_ts[j].nsec_val); output("Now is: %i.%09li\n", ts.tv_sec, ts.tv_nsec); output("Junk is: %i.%09li\n", ts_junk.tv_sec, ts_junk.tv_nsec); #endif do { ret = pthread_cond_timedwait(&cnd, &(td->mtx), &ts_junk); } while (ret == 0); #if VERBOSE > 2 output("timedwait returns %d (%s) - gotit = %d\n", ret, strerror(ret), td->gotit); #endif /* check that when EINVAL is returned, the mutex has not been released */ if (ret == EINVAL) { if (td->gotit != 0) { FAILED("The mutex was released when an invalid timestamp was detected in the function"); } #if VERBOSE > 0 } else { output("Warning, struct timespec with tv_sec = %i and tv_nsec = %li was not invalid\n", ts_junk.tv_sec, ts_junk.tv_nsec); } #endif /* Finally unlock the mutex */ td->ctrl = 1; ret = pthread_mutex_unlock(&(td->mtx)); if (ret != 0) { UNRESOLVED(ret, "[parent] Unable to unlock the mutex"); } /* Wait for the child to terminate */ if (do_fork != 0) { /* We were testing across processes */ ret = 0; for (k=0; k< NCHILDREN; k++) { chkpid = waitpid(child_pr[k], &status, 0); if (chkpid != child_pr[k]) { output("Expected pid: %i. Got %i\n", (int)child_pr[k], (int)chkpid); UNRESOLVED(errno, "Waitpid failed"); } if (WIFSIGNALED(status)) { output("Child process killed with signal %d\n",WTERMSIG(status)); UNRESOLVED( -1 , "Child process was killed"); } if (WIFEXITED(status)) { ret |= WEXITSTATUS(status); } else { UNRESOLVED( -1, "Child process was neither killed nor exited"); } } if (ret != 0) { exit(ret); /* Output has already been closed in child */ } } else /* child was a thread */ { for (k=0; kmtx)); if (ret != 0) { UNRESOLVED(ret, "Failed to destroy the mutex"); } ret = pthread_condattr_destroy(&ca); if (ret != 0) { UNRESOLVED(ret, "Failed to destroy the cond var attribute object"); } ret = pthread_mutexattr_destroy(&ma); if (ret != 0) { UNRESOLVED(ret, "Failed to destroy the mutex attribute object"); } } /* Proceed to the next junk timedwait value */ } /* Proceed to the next scenario */ #if VERBOSE > 0 output("Test passed\n"); #endif PASSED; } #else /* WITHOUT_XOPEN */ int main(int argc, char * argv[]) { output_init(); UNTESTED("This test requires XSI features"); } #endif posixtestsuite/conformance/interfaces/pthread_cond_timedwait/2-3.c0100644000000000000000000000564507712041731024470 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: bing.wei.liu REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_cond_timedwait() * shall be equivalent to pthread_cond_wait(), except that an error is returned * if the absolute time specified by abstime has already been passed at the time * of the call. * */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include "posixtest.h" #define INTERVAL 2 struct testdata { pthread_mutex_t mutex; pthread_cond_t cond; } td; int t1_start = 0; void *t1_func(void *arg) { int rc; struct timeval curtime; struct timespec timeout; if (pthread_mutex_lock(&td.mutex) != 0) { fprintf(stderr,"Thread1 failed to acquire the mutex\n"); exit(PTS_UNRESOLVED); } fprintf(stderr,"Thread1 started\n"); t1_start = 1; /* let main thread continue */ if (gettimeofday(&curtime, NULL) !=0 ) { fprintf(stderr,"Fail to get current time\n"); exit(PTS_UNRESOLVED); } timeout.tv_sec = curtime.tv_sec; timeout.tv_nsec = 0; fprintf(stderr,"Thread1 is waiting for the cond\n"); rc = pthread_cond_timedwait(&td.cond, &td.mutex, &timeout); if (rc == ETIMEDOUT) { fprintf(stderr,"Thread1 stops waiting when time is out\n"); pthread_exit((void*)PTS_PASS); } else { fprintf(stderr,"pthread_cond_timedwait return %d instead of ETIMEDOUT\n", rc); exit(PTS_FAIL); } } int main() { pthread_t thread1; int rc, th_ret; if (pthread_mutex_init(&td.mutex, NULL) != 0) { fprintf(stderr,"Fail to initialize mutex\n"); return PTS_UNRESOLVED; } if (pthread_cond_init(&td.cond, NULL) != 0) { fprintf(stderr,"Fail to initialize cond\n"); return PTS_UNRESOLVED; } if (pthread_create(&thread1, NULL, t1_func, NULL) != 0) { fprintf(stderr,"Fail to create thread 1\n"); return PTS_UNRESOLVED; } /* If the thread hasn't ended in 5 seconds, then most probably * pthread_cond_timedwait is failing to function correctly. */ alarm(5); /* Wait for thread to end execution. */ if(pthread_join(thread1, (void*)&th_ret) != 0) { fprintf(stderr, "Could not join the thread. \n"); return PTS_UNRESOLVED; } /* Make sure pthread_cond_timedwait released and re-acquired the mutex * as it should. */ rc=pthread_mutex_trylock(&td.mutex); if (rc == 0) { fprintf(stderr,"Test FAILED: Did not re-acquire mutex after timedout out call to pthread_cond_timedwait\n"); return PTS_FAIL; } if (pthread_mutex_unlock(&td.mutex) != 0) { fprintf(stderr,"Main failed to release mutex\n"); return PTS_UNRESOLVED; } if(th_ret == PTS_PASS) { printf("Test PASSED\n"); return PTS_PASS; } else if(th_ret == PTS_FAIL) { printf("Test FAILED\n"); return PTS_FAIL; } else return PTS_UNRESOLVED; } posixtestsuite/conformance/interfaces/pthread_cond_timedwait/2-7.c0100644000000000000000000004357610066714721024503 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertion: * * When the function fails because of a timeout, * it must reacquire the mutex (as when it is successful) * The steps are: * -> For each mutex type; * -> with and without process-shared primitive if this is supported; * -> with different clocks if this is supported, * -> Initialize a condvar and a mutex. * -> Create a new thread (or process for process-shared condvars & mutex) * -> The new thread (process) locks the mutex, then enters a timedwait which will timeout soon. * -> The parent thread (process) then locks the mutex, ensures that the child is waiting, * then sleeps until the timeout is terminated; and checks the child does not leave the wait function. * -> The parent unlocks the mutex then waits for the child. * -> The child checks that it owns the mutex; then it leaves. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /* We need the XSI extention for the mutex attributes and the mkstemp() routine */ #ifndef WITHOUT_XOPEN #define _XOPEN_SOURCE 600 #endif /********************************************************************************************/ /****************************** standard includes *****************************************/ /********************************************************************************************/ #include #include #include #include #include #include #include #include #include #include /********************************************************************************************/ /****************************** Test framework *****************************************/ /********************************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /********************************************************************************************/ /********************************** Configuration ******************************************/ /********************************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif #define TIMEOUT (20) /* Number of microseconds to wait */ #ifndef WITHOUT_ALTCLK #define USE_ALTCLK /* make tests with MONOTONIC CLOCK if supported */ #endif /********************************************************************************************/ /*********************************** Test case *****************************************/ /********************************************************************************************/ #ifndef WITHOUT_XOPEN typedef struct { pthread_mutex_t mtx; pthread_cond_t cnd; clockid_t cid; /* Clock id used by the cond var */ int type; /* Mutex type */ int ctrl; /* checkpoints */ int bool; /* Boolean predicate for the condition */ int status; /* error code */ } testdata_t; struct _scenar { int m_type; /* Mutex type to use */ int mc_pshared; /* 0: mutex and cond are process-private (default) ~ !0: Both are process-shared, if supported */ int c_clock; /* 0: cond uses the default clock. ~ !0: Cond uses monotonic clock, if supported. */ int fork; /* 0: Test between threads. ~ !0: Test across processes, if supported (mmap) */ char * descr; /* Case description */ } scenarii[] = { {PTHREAD_MUTEX_DEFAULT, 0, 0, 0, "Default mutex"} ,{PTHREAD_MUTEX_NORMAL, 0, 0, 0, "Normal mutex"} ,{PTHREAD_MUTEX_ERRORCHECK, 0, 0, 0, "Errorcheck mutex"} ,{PTHREAD_MUTEX_RECURSIVE, 0, 0, 0, "Recursive mutex"} ,{PTHREAD_MUTEX_DEFAULT, 1, 0, 0, "PShared default mutex"} ,{PTHREAD_MUTEX_NORMAL, 1, 0, 0, "Pshared normal mutex"} ,{PTHREAD_MUTEX_ERRORCHECK, 1, 0, 0, "Pshared errorcheck mutex"} ,{PTHREAD_MUTEX_RECURSIVE, 1, 0, 0, "Pshared recursive mutex"} ,{PTHREAD_MUTEX_DEFAULT, 1, 0, 1, "Pshared default mutex across processes"} ,{PTHREAD_MUTEX_NORMAL, 1, 0, 1, "Pshared normal mutex across processes"} ,{PTHREAD_MUTEX_ERRORCHECK, 1, 0, 1, "Pshared errorcheck mutex across processes"} ,{PTHREAD_MUTEX_RECURSIVE, 1, 0, 1, "Pshared recursive mutex across processes"} #ifdef USE_ALTCLK ,{PTHREAD_MUTEX_DEFAULT, 1, 1, 1, "Pshared default mutex and alt clock condvar across processes"} ,{PTHREAD_MUTEX_NORMAL, 1, 1, 1, "Pshared normal mutex and alt clock condvar across processes"} ,{PTHREAD_MUTEX_ERRORCHECK, 1, 1, 1, "Pshared errorcheck mutex and alt clock condvar across processes"} ,{PTHREAD_MUTEX_RECURSIVE, 1, 1, 1, "Pshared recursive mutex and alt clock condvar across processes"} ,{PTHREAD_MUTEX_DEFAULT, 0, 1, 0, "Default mutex and alt clock condvar"} ,{PTHREAD_MUTEX_NORMAL, 0, 1, 0, "Normal mutex and alt clock condvar"} ,{PTHREAD_MUTEX_ERRORCHECK, 0, 1, 0, "Errorcheck mutex and alt clock condvar"} ,{PTHREAD_MUTEX_RECURSIVE, 0, 1, 0, "Recursive mutex and alt clock condvar"} ,{PTHREAD_MUTEX_DEFAULT, 1, 1, 0, "PShared default mutex and alt clock condvar"} ,{PTHREAD_MUTEX_NORMAL, 1, 1, 0, "Pshared normal mutex and alt clock condvar"} ,{PTHREAD_MUTEX_ERRORCHECK, 1, 1, 0, "Pshared errorcheck mutex and alt clock condvar"} ,{PTHREAD_MUTEX_RECURSIVE, 1, 1, 0, "Pshared recursive mutex and alt clock condvar"} #endif }; void * tf(void * arg) { int ret=0; struct timespec ts; testdata_t * td = (testdata_t *)arg; /* Lock the mutex */ ret = pthread_mutex_lock(&(td->mtx)); if (ret != 0) { td->status = ret; UNRESOLVED(ret, "[child] Unable to lock the mutex"); } /* Tell the parent the mutex is locked */ td->ctrl = 1; /* Prepare the timeout parameter */ ret = clock_gettime(td->cid, &ts); if (ret != 0) { td->status = ret; UNRESOLVED(errno, "[child] Unable get clock time"); } /* Compute the timeout */ ts.tv_nsec += TIMEOUT * 1000; if (ts.tv_nsec >= 1000000000) { ts.tv_sec++; ts.tv_nsec -= 1000000000; } #if VERBOSE > 1 output("[child] Will timeout at %i.%09i\n", ts.tv_sec, ts.tv_nsec); #endif /* Enter the timed wait */ do { ret = pthread_cond_timedwait(&(td->cnd), &(td->mtx), &ts); td->ctrl = 2; } while ((ret == 0) && (td->bool == 0)); td->ctrl = 3; if (ret != ETIMEDOUT) { td->status = ret; UNRESOLVED(ret, "[child] Cond timedwait returned an error"); } /* Make sure we are owning the mutex */ ret = pthread_mutex_trylock(&(td->mtx)); if (td->type == PTHREAD_MUTEX_RECURSIVE) { #if VERBOSE > 1 output("[child] Recursive mutex. Test if we are able to re-lock.\n"); #endif if (ret != 0) { td->status = ret; FAILED("[child] Unable to relock the recursive mutex"); } ret = pthread_mutex_unlock(&(td->mtx)); if (ret != 0) { td->status = ret; UNRESOLVED(ret, "[child] Failed to unlock the mutex"); } } else /* This was not a recursive mutex; the call must have failed */ { if (ret == 0) { td->status = -1; FAILED("[child] Thread did not owned the mutex after the timedwait return."); } if (ret != EBUSY) { td-> status = ret; UNRESOLVED(ret, "[child] Mutex trylock did not return EBUSY"); } #if VERBOSE > 1 output("[child] The mutex was busy (normal).\n"); #endif } ret = pthread_mutex_unlock(&(td->mtx)); if (ret != 0) { td->status=ret; output("[child] Got error %i: %s\n", ret, strerror(ret)); FAILED("[child] Failed to unlock the mutex - owned by another thread?"); } td->ctrl = 4; return NULL; } int main(int argc, char * argv[]) { int ret, i; pthread_mutexattr_t ma; pthread_condattr_t ca; testdata_t * td; int do_fork; pid_t child_pr=0, chkpid; int status; pthread_t child_th; long pshared, monotonic, cs, mf; output_init(); pshared = sysconf(_SC_THREAD_PROCESS_SHARED); cs = sysconf(_SC_CLOCK_SELECTION); monotonic = sysconf(_SC_MONOTONIC_CLOCK); mf =sysconf(_SC_MAPPED_FILES); #if VERBOSE > 0 output("Test starting\n"); output("System abilities:\n"); output(" TPS : %li\n", pshared); output(" CS : %li\n", cs); output(" MON : %li\n", monotonic); output(" MF : %li\n", mf); if ((mf < 0) || (pshared < 0)) output("Process-shared attributes won't be tested\n"); if ((cs < 0) || (monotonic < 0)) output("Alternative clock won't be tested\n"); #endif /* We are not interested in testing the clock if we have no other clock available.. */ if (monotonic < 0) cs = -1; #ifndef USE_ALTCLK if (cs > 0) output("Implementation supports the MONOTONIC CLOCK but option is disabled in test.\n"); #endif /********** * Allocate space for the testdata structure */ if (mf < 0) { /* Cannot mmap a file, we use an alternative method */ testdata_t alternativ; td = &alternativ; pshared = -1; /* We won't do this testing anyway */ #if VERBOSE > 0 output("Testdata allocated in the process memory.\n"); #endif } else { /* We will place the test data in a mmaped file */ char filename[] = "/tmp/cond_timedwait_2-4-XXXXXX"; size_t sz; void * mmaped; int fd; char * tmp; /* We now create the temp files */ fd = mkstemp(filename); if (fd == -1) { UNRESOLVED(errno, "Temporary file could not be created"); } /* and make sure the file will be deleted when closed */ unlink(filename); #if VERBOSE > 1 output("Temp file created (%s).\n", filename); #endif sz= (size_t)sysconf(_SC_PAGESIZE); tmp = calloc(1, sz); if (tmp == NULL) { UNRESOLVED(errno, "Memory allocation failed"); } /* Write the data to the file. */ if (write (fd, tmp, sz) != (ssize_t) sz) { UNRESOLVED(sz, "Writting to the file failed"); } free(tmp); /* Now we can map the file in memory */ mmaped = mmap(NULL, sz, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); if (mmaped == MAP_FAILED) { UNRESOLVED(errno, "mmap failed"); } td = (testdata_t *) mmaped; /* Our datatest structure is now in shared memory */ #if VERBOSE > 1 output("Testdata allocated in shared memory.\n"); #endif } /********** * For each test scenario, initialize the attributes and other variables. */ for ( i=0; i< (sizeof(scenarii) / sizeof(scenarii[0])); i++) { #if VERBOSE > 1 output("[parent] Preparing attributes for scenario %i\n", i); #endif /* set / reset everything */ do_fork=0; ret = pthread_mutexattr_init(&ma); if (ret != 0) { UNRESOLVED(ret, "[parent] Unable to initialize the mutex attribute object"); } ret = pthread_condattr_init(&ca); if (ret != 0) { UNRESOLVED(ret, "[parent] Unable to initialize the cond attribute object"); } /* Set the mutex type */ ret = pthread_mutexattr_settype(&ma, scenarii[i].m_type); if (ret != 0) { UNRESOLVED(ret, "[parent] Unable to set mutex type"); } #if VERBOSE > 1 output("[parent] Mutex type : %i\n", scenarii[i].m_type); #endif /* Set the pshared attributes, if supported */ if ((pshared > 0) && (scenarii[i].mc_pshared != 0)) { ret = pthread_mutexattr_setpshared(&ma, PTHREAD_PROCESS_SHARED); if (ret != 0) { UNRESOLVED(ret, "[parent] Unable to set the mutex process-shared"); } ret = pthread_condattr_setpshared(&ca, PTHREAD_PROCESS_SHARED); if (ret != 0) { UNRESOLVED(ret, "[parent] Unable to set the cond var process-shared"); } #if VERBOSE > 1 output("[parent] Mutex & cond are process-shared\n"); #endif } #if VERBOSE > 1 else { output("[parent] Mutex & cond are process-private\n"); } #endif /* Set the alternative clock, if supported */ #ifdef USE_ALTCLK if ((cs > 0) && (scenarii[i].c_clock != 0)) { ret = pthread_condattr_setclock(&ca, CLOCK_MONOTONIC); if (ret != 0) { UNRESOLVED(ret, "[parent] Unable to set the monotonic clock for the cond"); } #if VERBOSE > 1 output("[parent] Cond uses the Monotonic clock\n"); #endif } #if VERBOSE > 1 else { output("[parent] Cond uses the default clock\n"); } #endif #endif /* Tell whether the test will be across processes */ if ((pshared > 0) && (scenarii[i].fork != 0)) { do_fork = 1; #if VERBOSE > 1 output("[parent] Child will be a new process\n"); #endif } #if VERBOSE > 1 else { output("[parent] Child will be a new thread\n"); } #endif /********** * Initialize the testdata_t structure with the previously defined attributes */ /* Initialize the mutex */ ret = pthread_mutex_init(&(td->mtx), &ma); if (ret != 0) { UNRESOLVED(ret, "[parent] Mutex init failed"); } /* initialize the condvar */ ret = pthread_cond_init(&(td->cnd), &ca); if (ret != 0) { UNRESOLVED(ret, "[parent] Cond init failed"); } /* Initialize the other datas from the test structure */ #ifdef USE_ALTCLK ret = pthread_condattr_getclock(&ca, &(td->cid)); if (ret != 0) { UNRESOLVED(ret, "[parent] Unable to read cond clock attribute"); } #else td->cid=CLOCK_REALTIME; #endif ret = pthread_mutexattr_gettype(&ma, &(td->type)); if (ret != 0) { UNRESOLVED(ret, "[parent] Unable to read mutex type attribute"); } td->ctrl=0; td->bool=0; td->status=0; /********** * Proceed to the actual testing */ /* Create the child */ if (do_fork != 0) { /* We are testing across two processes */ child_pr = fork(); if (child_pr == -1) { UNRESOLVED(errno, "[parent] Fork failed"); } if (child_pr == 0) { #if VERBOSE > 1 output("[child] Child process starting...\n"); #endif if (tf((void *)td) != NULL) { UNRESOLVED( -1, "[child] Got an unexpected return value from test function"); } else { /* We cannot use the PASSED macro here since it would terminate the output */ exit (0); } } /* Only the parent process goes further */ } else /* do_fork == 0 */ { /* We are testing across two threads */ ret = pthread_create(&child_th, NULL, tf, td); if (ret != 0) { UNRESOLVED(ret, "[parent] Unable to create the child thread."); } } /* Note: in case of an error, the child process will be alive for 1 sec then exit. */ /* Child is now running and will enter the timedwait */ /* We are waiting for this; and we have to monitor the status value as well. */ ret = pthread_mutex_lock(&(td->mtx)); if (ret != 0) { UNRESOLVED(ret, "[parent] Unable to lock the mutex"); } while ((td->ctrl == 0) && (td->status == 0)) { ret = pthread_mutex_unlock(&(td->mtx)); if (ret != 0) { UNRESOLVED(ret, "[parent] Unable to unlock the mutex"); } sched_yield(); ret = pthread_mutex_lock(&(td->mtx)); if (ret != 0) { UNRESOLVED(ret, "[parent] Unable to lock the mutex"); } } if ((td->ctrl == 2) && (td->status == 0)) /* Spurious wakeups hapenned */ { output("Spurious wake ups have happened. Maybe pthread_cond_timedwait is broken?\n"); td->ctrl = 1; } if (td->ctrl == 1)/* The child is inside the cond timedwait */ { #if VERBOSE > 1 output("[parent] Child has not timedout yet, we will wait.\n"); #endif /* Let the child leave the wait function if something is broken */ usleep(TIMEOUT); if (td->ctrl != 1) { FAILED("[parent] Child went out from pthread_cond_timedwait without locking the mutex"); } } /* Let the child do its checking */ ret = pthread_mutex_unlock(&(td->mtx)); if (ret != 0) { UNRESOLVED(ret, "[parent] Unable to unlock the mutex"); } /* Wait for the child to terminate */ if (do_fork != 0) { /* We were testing across two processes */ chkpid = waitpid(child_pr, &status, 0); if (chkpid != child_pr) { output("Expected pid: %i. Got %i\n", (int)child_pr, (int)chkpid); UNRESOLVED(errno, "Waitpid failed"); } if (WIFSIGNALED(status)) { output("Child process killed with signal %d\n",WTERMSIG(status)); UNRESOLVED( td->status , "Child process was killed"); } if (WIFEXITED(status)) { ret = WEXITSTATUS(status); } else { UNRESOLVED( td->status, "Child process was neither killed nor exited"); } if (ret != 0) { exit(ret); /* Output has already been closed in child */ } } else /* child was a thread */ { ret = pthread_join(child_th, NULL); if (ret != 0) { UNRESOLVED(ret, "[parent] Unable to join the thread"); } } /********** * Destroy the data */ ret = pthread_cond_destroy(&(td->cnd)); if (ret != 0) { UNRESOLVED(ret, "Failed to destroy the cond var"); } ret = pthread_mutex_destroy(&(td->mtx)); if (ret != 0) { UNRESOLVED(ret, "Failed to destroy the mutex"); } ret = pthread_condattr_destroy(&ca); if (ret != 0) { UNRESOLVED(ret, "Failed to destroy the cond var attribute object"); } ret = pthread_mutexattr_destroy(&ma); if (ret != 0) { UNRESOLVED(ret, "Failed to destroy the mutex attribute object"); } } /* Proceed to the next scenario */ #if VERBOSE > 0 output("Test passed\n"); #endif PASSED; } #else /* WITHOUT_XOPEN */ int main(int argc, char * argv[]) { output_init(); UNTESTED("This test requires XSI features"); } #endif posixtestsuite/conformance/interfaces/pthread_cond_timedwait/2-1.c0100644000000000000000000000722107654036334024466 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: bing.wei.liu REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_cond_timedwait() * shall be equivalent to pthread_cond_wait(), except that an error is returned * if the absolute time specified by abstime passes before the condition cond is * signaled or broadcasted, or if the absolute time specified by abstime has * already been passed at the time of the call. * * Case 2-1 * Upon successful return, the mutex shall have been locked and shall * be owned by the calling thread. */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include "posixtest.h" #define INTERVAL 1 #define TIMEOUT 5 struct testdata { pthread_mutex_t mutex; pthread_cond_t cond; } td; int t1_start = 0; int signaled = 0; void *t1_func(void *arg) { int rc; struct timespec timeout; struct timeval curtime; if (pthread_mutex_lock(&td.mutex) != 0) { fprintf(stderr,"Thread1 failed to acquire the mutex\n"); exit(PTS_UNRESOLVED); } fprintf(stderr,"Thread1 started\n"); t1_start = 1; /* let main thread continue */ if (gettimeofday(&curtime, NULL) !=0 ) { fprintf(stderr,"Fail to get current time\n"); exit(PTS_UNRESOLVED); } timeout.tv_sec = curtime.tv_sec + TIMEOUT; timeout.tv_nsec = curtime.tv_usec * 1000; fprintf(stderr,"Thread1 is waiting for the cond\n"); rc = pthread_cond_timedwait(&td.cond, &td.mutex, &timeout); if(rc != 0) { if (rc == ETIMEDOUT) { fprintf(stderr,"Thread1 stops waiting when time is out\n"); exit(PTS_UNRESOLVED); } else { fprintf(stderr,"pthread_cond_timedwait return %d\n", rc); exit(PTS_UNRESOLVED); } } fprintf(stderr,"Thread1 wakened\n"); if(signaled == 0) { fprintf(stderr,"Thread1 did not block on the cond at all\n"); exit(PTS_UNRESOLVED); } if (pthread_mutex_trylock(&td.mutex) == 0) { fprintf(stderr,"Thread1 should not be able to lock the mutex again\n"); printf("Test FAILED\n"); exit(PTS_FAIL); } fprintf(stderr,"Thread1 failed to trylock the mutex (as expected)\n"); if (pthread_mutex_unlock(&td.mutex) != 0) { fprintf(stderr,"Thread1 failed to release the mutex\n"); printf("Test FAILED\n"); exit(PTS_FAIL); } fprintf(stderr,"Thread1 released the mutex\n"); return NULL; } int main() { pthread_t thread1; if (pthread_mutex_init(&td.mutex, NULL) != 0) { fprintf(stderr,"Fail to initialize mutex\n"); return PTS_UNRESOLVED; } if (pthread_cond_init(&td.cond, NULL) != 0) { fprintf(stderr,"Fail to initialize cond\n"); return PTS_UNRESOLVED; } if (pthread_create(&thread1, NULL, t1_func, NULL) != 0) { fprintf(stderr,"Fail to create thread 1\n"); return PTS_UNRESOLVED; } while(!t1_start) /* wait for thread1 started */ usleep(100); /* acquire the mutex released by pthread_cond_wait() within thread 1 */ if (pthread_mutex_lock(&td.mutex) != 0) { fprintf(stderr,"Main failed to acquire mutex\n"); return PTS_UNRESOLVED; } if (pthread_mutex_unlock(&td.mutex) != 0) { fprintf(stderr,"Main failed to release mutex\n"); return PTS_UNRESOLVED; } sleep(INTERVAL); fprintf(stderr,"Time to wake up thread1 by signaling a condition\n"); signaled = 1; if (pthread_cond_signal(&td.cond) != 0) { fprintf(stderr,"Main failed to signal the condition\n"); return PTS_UNRESOLVED; } pthread_join(thread1, NULL); printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_cond_timedwait/3-1.c0100644000000000000000000000611107654036335024465 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: bing.wei.liu REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_cond_timedwait() * Upon successful completion, a value of zero shall be returned. */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include "posixtest.h" #define INTERVAL 1 #define TIMEOUT 5 struct testdata { pthread_mutex_t mutex; pthread_cond_t cond; } td; int t1_start = 0; int signaled = 0; void *t1_func(void *arg) { int rc; struct timespec timeout; struct timeval curtime; if (pthread_mutex_lock(&td.mutex) != 0) { fprintf(stderr,"Thread1 failed to acquire the mutex\n"); exit(PTS_UNRESOLVED); } fprintf(stderr,"Thread1 started\n"); t1_start = 1; /* let main thread continue */ if (gettimeofday(&curtime, NULL) !=0 ) { fprintf(stderr,"Fail to get current time\n"); exit(PTS_UNRESOLVED); } timeout.tv_sec = curtime.tv_sec + TIMEOUT; timeout.tv_nsec = curtime.tv_usec * 1000; fprintf(stderr,"Thread1 is waiting for the cond\n"); rc = pthread_cond_timedwait(&td.cond, &td.mutex, &timeout); if (rc != 0) { if (rc == ETIMEDOUT) { fprintf(stderr,"Thread1 stops waiting when time is out\n"); exit(PTS_UNRESOLVED); } else { fprintf(stderr,"pthread_cond_timedwait return %d\n", rc); printf("Test FAILED\n"); exit(PTS_FAIL); } } if (signaled == 0) { fprintf(stderr,"Thread1 did not block on the cond at all\n"); exit(PTS_UNRESOLVED); } fprintf(stderr,"Thread1 wakened and got returned value 0\n"); if (pthread_mutex_unlock(&td.mutex) != 0) { fprintf(stderr,"Thread1 failed to release the mutex\n"); exit(PTS_UNRESOLVED); } fprintf(stderr,"Thread1 released the mutex\n"); return NULL; } int main() { pthread_t thread1; if (pthread_mutex_init(&td.mutex, NULL) != 0) { fprintf(stderr,"Fail to initialize mutex\n"); return PTS_UNRESOLVED; } if (pthread_cond_init(&td.cond, NULL) != 0) { fprintf(stderr,"Fail to initialize cond\n"); return PTS_UNRESOLVED; } if (pthread_create(&thread1, NULL, t1_func, NULL) != 0) { fprintf(stderr,"Fail to create thread 1\n"); return PTS_UNRESOLVED; } while(!t1_start) /* wait for thread1 started */ usleep(100); /* acquire the mutex released by pthread_cond_wait() within thread 1 */ if (pthread_mutex_lock(&td.mutex) != 0) { fprintf(stderr,"Main failed to acquire mutex\n"); return PTS_UNRESOLVED; } if (pthread_mutex_unlock(&td.mutex) != 0) { fprintf(stderr,"Main failed to release mutex\n"); return PTS_UNRESOLVED; } sleep(INTERVAL); fprintf(stderr,"Time to wake up thread1 by signaling a condition\n"); signaled = 1; if (pthread_cond_signal(&td.cond) != 0) { fprintf(stderr,"Main failed to signal the condition\n"); return PTS_UNRESOLVED; } pthread_join(thread1, NULL); printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/sigfillset/0040755000000000000000000000000010515625264021464 5ustar rootrootposixtestsuite/conformance/interfaces/sigfillset/1-1.c0100644000000000000000000000256607645116222022133 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: salwan.searty REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. If any of the signals listed in the array below are not is "signalset" after sigfillset is called on it, then fail, otherwise pass. */ #include #include #include #include "posixtest.h" #define NUMSIGNALS 28 int main(void) { sigset_t signalset; int i, test_failed=0; int siglist[] = { SIGABRT, SIGALRM, SIGBUS, SIGCHLD, SIGCONT, SIGFPE, SIGHUP, SIGILL, SIGINT, SIGKILL, SIGPIPE, SIGQUIT, SIGSEGV, SIGSTOP, SIGTERM, SIGTSTP, SIGTTIN, SIGTTOU, SIGUSR1, SIGUSR2, SIGPOLL, SIGPROF, SIGSYS, SIGTRAP, SIGURG, SIGVTALRM, SIGXCPU, SIGXFSZ }; if (sigfillset(&signalset) == -1) { perror("sigfillset failed -- test aborted"); return PTS_FAIL; } for (i=NUMSIGNALS-1; i>=0; i--) { if (sigismember(&signalset, siglist[i]) == 0) { #ifdef DEBUG printf("sigfillset did not insert signal %s\n in set", siglist[i]); #endif test_failed=1; } } if (test_failed == 1) { return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/sigfillset/assertions.xml0100644000000000000000000000076607616570171024412 0ustar rootroot sigfillset() initializes the signal set pointed to by set, such that all signals defined in IEEE Std 1003.1-2001 are included in the set. sigfillset() returns 0 upon successful completion sigfillset() returns -1 and sets errno to indicate the error in case of unsuccessful completion. posixtestsuite/conformance/interfaces/sigfillset/coverage.txt0100644000000000000000000000040707613567764024035 0ustar rootrootThis document defines the coverage for function sigemptyset(). Assertion Covered? 1 YES 2 YES 3 WON'T WON'T TEST 3-1 - Not possible to make sigfillset() fail at will to return a -1. POSIX spec doesn't mention how to cause sigfillset() to fail when called. posixtestsuite/conformance/interfaces/sigfillset/2-1.c0100644000000000000000000000131007616570171022123 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: salwan.searty REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Simply, as long as sigfillset returns a 0, the test passes. */ #include #include #include "posixtest.h" int main() { sigset_t signalset; /* int returnval; returnval = sigfillset(&signalset); if (returnval != 0) { */ if (sigfillset(&signalset) != 0) { perror("sigfillset failed -- test aborted"); return PTS_FAIL; } #ifdef DEBUG printf("sigfillset passed\n"); #endif return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_mutexattr_getprotocol/0040755000000000000000000000000010515625221025475 5ustar rootrootposixtestsuite/conformance/interfaces/pthread_mutexattr_getprotocol/1-1.c0100644000000000000000000000223107645121451026140 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: bing.wei.liu REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_mutexattr_getprotocol() * * Gets the protocol attribute of a mutexattr object (which was prev. created * by the function pthread_mutexattr_init()). * * Steps: * 1. Initialize a pthread_mutexattr_t object with pthread_mutexattr_init() * 2. Call pthread_mutexattr_getprotocol() to obtain the protocol. * */ #include #include #include #include "posixtest.h" int main() { pthread_mutexattr_t mta; int protocol,rc; /* Initialize a mutex attributes object */ if(pthread_mutexattr_init(&mta) != 0) { perror("Error at pthread_mutexattr_init()\n"); return PTS_UNRESOLVED; } /* Get the protocol mutex attr. */ if((rc=pthread_mutexattr_getprotocol(&mta, &protocol)) != 0) { printf("Test FAILED: Error in pthread_mutexattr_getprotocol rc=%d\n", rc); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_mutexattr_getprotocol/1-2.c0100644000000000000000000000312007656312311026136 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: bing.wei.liu REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_mutexattr_getprotocol() * * Gets the protocol attribute of a mutexattr object (which was prev. created * by the function pthread_mutexattr_init()). * */ #include #include #include #include "posixtest.h" int main() { pthread_mutexattr_t mta; int protocol, protcls[3],i; /* Initialize a mutex attributes object */ if(pthread_mutexattr_init(&mta) != 0) { perror("Error at pthread_mutexattr_init()\n"); return PTS_UNRESOLVED; } protcls[0]=PTHREAD_PRIO_NONE; protcls[1]=PTHREAD_PRIO_INHERIT; protcls[2]=PTHREAD_PRIO_PROTECT; for(i=0;i<3;i++) { /* Set the protocol to one of the 3 valid protocols. */ if(pthread_mutexattr_setprotocol(&mta,protcls[i])) { printf("Error setting protocol to %d\n", protcls[i]); return PTS_UNRESOLVED; } /* Get the protocol mutex attr. */ if(pthread_mutexattr_getprotocol(&mta, &protocol) != 0) { fprintf(stderr,"Error obtaining the protocol attribute.\n"); return PTS_UNRESOLVED; } /* Make sure that the protocol set is the protocl we get when calling * pthread_mutexattr_getprocol() */ if(protocol != protcls[i]) { printf("Test FAILED: Set protocol %d, but instead got protocol %d.\n", protcls[i], protocol); return PTS_FAIL; } } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_mutexattr_getprotocol/assertions.xml0100644000000000000000000000646007656312311030421 0ustar rootroot The function int pthread_mutexattr_getprotocol(const pthread_mutexattr_t *restrict attr, int *restrict protocol); Gets the protocol attribute of a mutexattr object (which was prev. created by the function pthread_mutexattr_init()). Upon success, it returns 0. It MAY fail if: [EINVAL] - 'attr' or 'protocol' is invalid. [EPERM] - The caller doesn't have the privilege to perform the operation. Shall not return error code of [EINTR]. When a thread owns a mutex with the PTHREAD_PRIO_NONE protocol attribute, its priority and scheduling shall not be affected by its mutex ownership. When a thread is blocking higher priority threads because of owning one or more mutexes with the PTHREAD_PRIO_INHERIT protocol attribute, it shall execute at the higher of its priority or the priority of the highest priority thread waiting on any of the mutexes owned by this thread and initialized with this protocol. When a thread owns one or more mutexes initialized with the PTHREAD_PRIO_PROTECT protocol, it shall execute at the higher of its priority or the highest of the priority ceilings of all the mutexes owned by this thread and initialized with this attribute, regardless of whether other threads are blocked on any of these mutexes or not. While a thread is holding a mutex which has been initialized with the PTHREAD_PRIO_INHERIT or PTHREAD_PRIO_PROTECT protocol attributes, it shall not be subject to being moved to the tail of the scheduling queue at its priority in the event that its original priority is changed, such as by a call to sched_setparam( ). Likewise, when a thread unlocks a mutex that has been initialized with the PTHREAD_PRIO_INHERIT or PTHREAD_PRIO_PROTECT protocol attributes, it shall not be subject to being moved to the tail of the scheduling queue at its priority in the event that its original priority is changed. If a thread simultaneously owns several mutexes initialized with different protocols, it shall execute at the highest of the priorities that it would have obtained by each of these protocols. When a thread makes a call to pthread_mutex_lock( ), the mutex was initialized with the protocol attribute having the value PTHREAD_PRIO_INHERIT, when the calling thread is blocked because the mutex is owned by another thread, that owner thread shall inherit the priority level of the calling thread as long as it continues to own the mutex. The implementation shall update its execution priority to the maximum of its assigned priority and all its inherited priorities. Furthermore, if this owner thread itself becomes blocked on another mutex, the same priority inheritance effect shall be propagated to this other owner thread, in a recursive manner posixtestsuite/conformance/interfaces/pthread_mutexattr_getprotocol/coverage.txt0100644000000000000000000000024407656312311030033 0ustar rootrootThis document defines the coverage for the pthread_mutexattr_getprotocol function: Assertion Tested? 1 YES 2 YES 3 NO 4 NO 5 No 6 No 7 NO 8 NO 9 NO NOTE: posixtestsuite/conformance/interfaces/pthread_mutexattr_init/0040755000000000000000000000000010515625221024077 5ustar rootrootposixtestsuite/conformance/interfaces/pthread_mutexattr_init/1-1.c0100644000000000000000000000323707634202501024543 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: bing.wei.liu REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_mutexattr_init() * shall initialize a mutex attributes object 'attr' with the default * value for all of the attributes defined by the implementation. * Steps: * 1. Initialize a pthread_mutexattr_t object with pthread_mutexattr_init() * 2. Call pthread_mutexattr_getpshared() to check if the process-shared * attribute is set as the default value PTHREAD_PROCESS_PRIVATE. * */ #include #include #include "posixtest.h" int main() { pthread_mutexattr_t mta; int rc; #ifdef PTHREAD_PROCESS_SHARED int pshared; #endif /* Initialize a mutex attributes object */ if((rc=pthread_mutexattr_init(&mta)) != 0) { fprintf(stderr,"Error at pthread_mutexattr_init(), rc=%d\n",rc); printf("Test FAILED\n"); return PTS_FAIL; } #ifdef PTHREAD_PROCESS_SHARED /* If the symbol {PTHREAD_PROCESS_SHARED} is defined, the attribute * process-shared should be provided and its default value should be * PTHREAD_PROCESS_PRIVATE */ if(pthread_mutexattr_getpshared(&mta, &pshared) != 0) { fprintf(stderr,"Error obtaining the attribute process-shared\n"); return PTS_UNRESOLVED; } if(pshared == PTHREAD_PROCESS_PRIVATE) { printf("Test PASSED\n"); return PTS_PASS; } else { printf("Test FAILED\n"); return PTS_FAIL; } #endif fprintf(stderr,"process-shared attribute is not available for testing\n"); return PTS_UNRESOLVED; } posixtestsuite/conformance/interfaces/pthread_mutexattr_init/assertions.xml0100644000000000000000000000170507621015103027007 0ustar rootroot The function int pthread_mutexattr_init(pthread_mutexattr_t *attr) initializes a mutex attributes object 'attr' with the default value for all of the attributes defined by the implementation. Results are undefined if it is called specifying an already initialized 'attr' attributes object. After a mutex attributes object has been used to initialize one or more mutexes, any function affecting the attributes object (including destruction) shall not affect any previously initialized mutexes. Upon success it returns 0. If it fails, an error number shall be returned: [ENOMEM] - Insufficient memory exists to initialize the mutex attributes object. posixtestsuite/conformance/interfaces/pthread_mutexattr_init/coverage.txt0100644000000000000000000000067407613731474026454 0ustar rootrootThis document defines the coverage for the pthread_mutexattr_init function: Assertion Tested? 1 YES 2 NO *Looking for indicators to judge if initialized mutexes are affected. The prioceiling or protocol attributes may be relied on, but they belong to REALTIME_THREADS scope, which is low priority in the schedule. 3 YES 4 NO *Looking for a way to use up the memory without screwing up the machine. Note: posixtestsuite/conformance/interfaces/pthread_mutexattr_init/3-1.c0100644000000000000000000000225607613731473024561 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: bing.wei.liu REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_mutexattr_init() * Upon successful completion, pthread_mutexattr_init() shall return a value of 0. * Steps: * 1. Initialize a pthread_mutexattr_t object with pthread_mutexattr_init() * 2. ENOMEM is the only error it returns, so if it doesn't return that error, * the return number should be 0. */ #include #include #include #include "posixtest.h" int main() { pthread_mutexattr_t mta; int rc; /* Initialize a mutex attributes object */ if((rc=pthread_mutexattr_init(&mta)) == 0) { printf("Test PASSED\n"); return PTS_PASS; } /* Insufficient memory exists to initialize the mutex attributes object */ else if(rc == ENOMEM) { fprintf(stderr,"pthread_mutexattr_init() returns ENOMEM\n"); return PTS_UNRESOLVED; } /* Any other returned value means the test failed */ else { printf("Test FAILED\n"); return PTS_FAIL; } } posixtestsuite/conformance/interfaces/pthread_cleanup_push/0040755000000000000000000000000010515625202023504 5ustar rootrootposixtestsuite/conformance/interfaces/pthread_cleanup_push/1-3.c0100644000000000000000000000410710033204322024136 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * * void pthread_cleanup_push(void (*routine) (void*), void *arg); * * Shall push the specified cancelation cleanup handler routine onto the calling thread's * cancelation cleanup stack. The cancelation cleanup handler shall be popped from the * cancelation cleanup stack and invoked with the argument arg when: * * (a)- The thread exits (calls pthread_exit()) * (b)- The thread acts upon a cancelation request * (c)- the thread calls pthread_cleanup_pop() with a non-zero execution argument * * Testing (c) * * STEPS: * 1. Create a thread * 2. The thread will push a cleanup handler routine, then pop the cleanup handler routine. * 3. Verify that the cleanup handler was called. * */ #include #include #include #include #include "posixtest.h" # define CLEANUP_NOTCALLED 0 # define CLEANUP_CALLED 1 int cleanup_flag; /* Cleanup handler */ void a_cleanup_func(void *flag_val) { cleanup_flag = (long)flag_val; return; } /* Function that the thread executes upon its creation */ void *a_thread_func() { pthread_cleanup_push(a_cleanup_func, (void*) CLEANUP_CALLED); pthread_cleanup_pop(1); pthread_exit(0); return NULL; } int main() { pthread_t new_th; /* Initializing values */ cleanup_flag = CLEANUP_NOTCALLED; /* Create a new thread. */ if(pthread_create(&new_th, NULL, a_thread_func, NULL) != 0) { perror("Error creating thread\n"); return PTS_UNRESOLVED; } /* Wait for thread to end execution */ if(pthread_join(new_th, NULL) != 0) { perror("Error in pthread_join()\n"); return PTS_UNRESOLVED; } /* Check to verify that the cleanup handler was called */ if(cleanup_flag != CLEANUP_CALLED) { printf("Test FAILED: Cleanup handler not called\n"); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_cleanup_push/1-1.c0100644000000000000000000000415710206355747024165 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * * void pthread_cleanup_push(void (*routine) (void*), void *arg); * * Shall push the specified cancelation cleanup handler routine onto the calling thread's * cancelation cleanup stack. The cancelation cleanup handler shall be popped from the * cancelation cleanup stack and invoked with the argument arg when: * * (a)- The thread exits (calls pthread_exit()) * (b)- The thread acts upon a cancelation request * (c)- the thread calls pthread_cleanup_pop() with a non-zero execution argument * * Testing (a) * * STEPS: * 1. Create a thread * 2. The thread will push a cleanup handler routine and then exit befor the cleanup_pop * routine is reached. * 3. Verify that the cleanup handler was called. * */ #include #include #include #include #include "posixtest.h" # define CLEANUP_NOTCALLED 0 # define CLEANUP_CALLED 1 int cleanup_flag; /* Cleanup handler */ void a_cleanup_func(void *flag_val) { cleanup_flag = (long)flag_val; return; } /* Function that the thread executes upon its creation */ void *a_thread_func() { pthread_cleanup_push(a_cleanup_func, (void*) CLEANUP_CALLED); pthread_exit(0); pthread_cleanup_pop(0); return NULL; } int main() { pthread_t new_th; /* Initializing values */ cleanup_flag = CLEANUP_NOTCALLED; /* Create a new thread. */ if(pthread_create(&new_th, NULL, a_thread_func, NULL) != 0) { perror("Error creating thread\n"); return PTS_UNRESOLVED; } /* Wait for thread to end execution */ if(pthread_join(new_th, NULL) != 0) { perror("Error in pthread_join()\n"); return PTS_UNRESOLVED; } /* Check to verify that the cleanup handler was called */ if(cleanup_flag != CLEANUP_CALLED) { printf("Test FAILED: Cleanup handler not called upon exit\n"); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_cleanup_push/1-2.c0100644000000000000000000000713310033204322024137 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * * void pthread_cleanup_push(void (*routine) (void*), void *arg); * * Shall push the specified cancelation cleanup handler routine onto the calling thread's * cancelation cleanup stack. The cancelation cleanup handler shall be popped from the * cancelation cleanup stack and invoked with the argument arg when: * * (a)- The thread exits (calls pthread_exit()) * (b)- The thread acts upon a cancelation request * (c)- the thread calls pthread_cleanup_pop() with a non-zero execution argument * * Testing (b) * * STEPS: * 1. Create a thread * 2. In the thread, push a cancelation handler * 3. Main will cancel the thread before the thread exits * 4. Verify that the cleanup handler was called */ #include #include #include #include #include "posixtest.h" # define CLEANUP_NOTCALLED 0 # define CLEANUP_CALLED 1 # define INTHREAD 0 /* Control going to or is already for Thread */ # define INMAIN 1 /* Control going to or is already for Main */ int sem1; /* Manual semaphore */ int cleanup_flag; /* The cleanup handler */ void a_cleanup_func(void *flag_val) { cleanup_flag = (long)flag_val; sem1 = INMAIN; return; } /* Function that the thread executes upon its creation */ void *a_thread_func() { pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL); pthread_cleanup_push(a_cleanup_func, (void*) CLEANUP_CALLED); /* Indicate to main() that the thread has been created. */ sem1=INMAIN; /* Wait until main() has sent out a cancel request, meaning until it * sets sem1==INTHREAD */ while(sem1==INMAIN) sleep(1); /* Give thread 10 seconds to time out. If the cancel request was not * honored until now, the test is unresolved because the cancel request * was not handled correctly. */ sleep(10); /* Shouldn't get here if the cancel request was honored immediately * like it should have been. */ pthread_cleanup_pop(0); pthread_exit((void*)PTS_UNRESOLVED); return NULL; } int main() { pthread_t new_th; void *value_ptr; /* hold return value of thread from pthread_join */ /* Initializing values */ sem1=INTHREAD; cleanup_flag=CLEANUP_NOTCALLED; /* Create a new thread. */ if(pthread_create(&new_th, NULL, a_thread_func, NULL) != 0) { perror("Error creating thread\n"); return PTS_UNRESOLVED; } /* Make sure thread is created before we cancel it. (wait for * a_thread_func() to set sem1=1.) */ while(sem1==INTHREAD) sleep(1); if(pthread_cancel(new_th) != 0) { printf("Error: Couldn't cancel thread\n"); return PTS_UNRESOLVED; } /* Indicate to the thread function that the thread cancel request * has been sent to it. */ sem1=INTHREAD; /* Wait for thread to return. */ if(pthread_join(new_th, &value_ptr) != 0) { printf("Error in pthread_join()\n"); return PTS_UNRESOLVED; } /* Make sure cancellation happened correctly */ if((long)value_ptr == PTS_UNRESOLVED) { printf("Error: cancellation not correctly handled\n"); return PTS_UNRESOLVED; } /* This means that the cleanup function wasn't called, so the cancel * request was not honord immediately like it should have been. */ if(cleanup_flag != CLEANUP_CALLED) { printf("Test FAILED: Cleanup hanlder not called up cancellation\n"); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_cleanup_push/assertions.xml0100644000000000000000000000131207673441075026431 0ustar rootroot The function void pthread_cleanup_push(void (*routine) (void*), void *arg); Shall push the specified cancelation cleanup handler routine onto the calling thread's cancelation cleanup stack. The cancelation cleanup handler shall be popped from the cancelation cleanup stack and invoked with the argument arg when: - The thread exits (calls pthread_exit()) - The thread acts upon a cancelation request - the thread calls pthread_cleanup_pop() with a non-zero execution argument It will not return a value, or an error code of [EINTR] posixtestsuite/conformance/interfaces/pthread_cleanup_push/coverage.txt0100644000000000000000000000016307673441075026054 0ustar rootrootThis document defines the coverage for the pthread_cleanup_push function: Assertion Tested? 1 YES 2 YES NOTE: posixtestsuite/conformance/interfaces/pthread_cleanup_push/2-1.sh0100755000000000000000000000075007673441075024360 0ustar rootroot#!/bin/sh # Copyright (c) 2002, Intel Corporation. All rights reserved. # Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com # This file is licensed under the GPL license. For the full content # of this license, see the COPYING file at the top level of this # source tree. # Test pthread_cleanup_push() does not return a value or an error code of [EINTR] # This is tested implicitly via assertion 1. echo "Tested implicitly via assertion 1. See output for status" exit 0 posixtestsuite/conformance/interfaces/pthread_key_delete/0040755000000000000000000000000010515625215023134 5ustar rootrootposixtestsuite/conformance/interfaces/pthread_key_delete/3-1.sh0100755000000000000000000000073507711611101023766 0ustar rootroot#!/bin/sh # Copyright (c) 2002, Intel Corporation. All rights reserved. # Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com # This file is licensed under the GPL license. For the full content # of this license, see the COPYING file at the top level of this # source tree. # Test pthread_key_delete # # If successful, it returns zero. # This is tested implicitly via assertion 1 & 2. echo "Tested implicitly via assertion 1 & 2. See output for status." exit 0 posixtestsuite/conformance/interfaces/pthread_key_delete/1-1.c0100644000000000000000000000314307711611101023565 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: bing.wei.liu REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_key_delete() * * Shall delete a thread-specific data key previously returned by pthread_key_create. The * thread-specific data values specified data values associated with 'key' need not be NULL at * the time pthread_key_delete is called. It is the responsibility of the application to free * any application storage or perform any cleanup actions for data structures related to the * deleted key or associated thread-specific data in any threads; this cleanup can be done * either before or after pthread_key_delete is called. Any attempt to use 'key' following * the call to pthread_key_delete results in undefined behavior. * * Steps: * 1. Create many keys, and do not specify and value to them (default is NULL) * 2. Delete the keys with pthread_key_delete * 3. Verify that this will not result in an error * */ #include #include #include #include #include "posixtest.h" #define NUM_OF_KEYS 10 int main() { pthread_key_t keys[NUM_OF_KEYS]; int i; for(i = 0;i #include #include #include #include "posixtest.h" #define NUM_OF_KEYS 10 #define KEY_VALUE 100 int main() { pthread_key_t keys[NUM_OF_KEYS]; int i; for(i = 0;i The function int pthread_key_delete(pthread_key_t key); Shall delete a thread-specific data key previously returned by pthread_key_create. The thread-specific data values specified data values associated with 'key' need not be NULL at the time pthread_key_delete is called. It is the responsibility of the application to free any application storage or perform any cleanup actions for data structures related to the deleted key or associated thread-specific data in any threads; this cleanup can be done either before or after pthread_key_delete is called. Any attempt to use 'key' following the call to pthread_key_delete results in undefined behavior. pthread_key_delete function shall be callable from within destructor functions. No destructor functions shall be invoked by pthread_key_delete. Any destructor function that may have been associated with 'key' shall no longer be called up thread exit. If successful, it returns zero. It may fail if: [EINVAL] - The 'key' value is invalid. it shall not return [EINTR] posixtestsuite/conformance/interfaces/pthread_key_delete/coverage.txt0100644000000000000000000000016707711611101025462 0ustar rootrootThis document defines the coverage for the pthread_key_delete function: Assertion Tested? 1 YES 2 YES 3 YES NOTE: posixtestsuite/conformance/interfaces/pthread_key_delete/2-1.c0100644000000000000000000000464107711611101023572 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: bing.wei.liu REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_key_delete() * pthread_key_delete function shall be callable from within destructor functions. No destructor functions shall be invoked by pthread_key_delete. Any destructor function that may have been associated with 'key' shall no longer be called up thread exit. * * Steps: * 1. Create a key with a destructor function associated with it * 2. In the destructor function, call pthread_key_delete * 3. Verify that this can be done with no errors * */ #include #include #include #include #include "posixtest.h" #define KEY_VALUE 1000 pthread_key_t key; int dest_cnt; /* Destructor funciton */ void dest_func(void *p) { dest_cnt++; /* Delete the key and check if an error has occured */ if(pthread_key_delete(key) != 0) { dest_cnt++; } } /* Thread function */ void *a_thread_func() { /* Set the value of the key to a value */ if(pthread_setspecific(key, (void *)(KEY_VALUE)) != 0) { printf("Error: pthread_setspecific() failed\n"); pthread_exit((void*) PTS_UNRESOLVED); } /* The thread ends here, the destructor for the key should now be called after this */ pthread_exit(0); } int main() { pthread_t new_th; /* Inialize the destructor flag */ dest_cnt = 0; /* Create a key with a destructor function */ if(pthread_key_create(&key, dest_func) != 0) { printf("Error: pthread_key_create() failed\n"); pthread_exit((void*) PTS_UNRESOLVED); } /* Create a thread */ if(pthread_create(&new_th, NULL, a_thread_func, NULL) != 0) { perror("Error creating thread\n"); return PTS_UNRESOLVED; } /* Wait for the thread's return */ if(pthread_join(new_th, NULL) != 0) { perror("Error in pthread_join()\n"); return PTS_UNRESOLVED; } /* Check if the destructor was called and if the pthread_key_delete function was * called successfully */ if(dest_cnt != 1) { if(dest_cnt == 0) { printf("Error calling the key destructor function\n"); return PTS_UNRESOLVED; } else { printf("Test FAILED: pthread_key_delete failed to be called from the destructor function\n"); return PTS_FAIL; } } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_mutexattr_destroy/0040755000000000000000000000000010515625221024625 5ustar rootrootposixtestsuite/conformance/interfaces/pthread_mutexattr_destroy/4-1.c0100644000000000000000000000213007622561602025272 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: bing.wei.liu REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test pthread_mutexattr_destroy() * If it fails, an error number shall be returned to indicate the error: * [EINVAL] The value specified by 'attr' is invalid * * Steps: * Try to destroy a NULL mutex attributes object using pthread_mutexattr_destroy(). * If it returns EINVAL, the test passes. * */ #include #include #include #include "posixtest.h" int main() { pthread_mutexattr_t *mta=NULL; int rc; /* Try to destroy a NULL mutex attributes object using pthread_mutexattr_destroy() * It should return EINVAL */ if((rc=pthread_mutexattr_destroy(mta)) == EINVAL) { printf("Test PASSED\n"); return PTS_PASS; } else { printf("Test PASSED: *NOTE: Expect %d(EINVAL), but return %d, though standard states 'may' fail\n", EINVAL, rc); return PTS_PASS; } } posixtestsuite/conformance/interfaces/pthread_mutexattr_destroy/1-1.c0100644000000000000000000000213407613731625025277 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: bing.wei.liu REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_mutexattr_destroy() * shall destroy a mutex attributes object. * * Steps: * 1. Initialize a pthread_mutexattr_t object using pthread_mutexattr_init() * 2. Destroy the attributes object using pthread_mutexattr_destroy() * */ #include #include #include #include "posixtest.h" int main() { pthread_mutexattr_t mta; int rc; /* Initialize a mutex attributes object */ if((rc=pthread_mutexattr_init(&mta)) != 0) { fprintf(stderr,"Cannot initialize mutex attributes object\n"); return PTS_UNRESOLVED; } /* Destroy the mutex attributes object */ if(pthread_mutexattr_destroy(&mta) != 0) { fprintf(stderr,"Error at pthread_mutexattr_destroy(), rc=%d\n", rc); printf("Test FAILED\n"); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_mutexattr_destroy/assertions.xml0100644000000000000000000000171107622322634027545 0ustar rootroot The function int pthread_mutexattr_destroy(pthread_mutexattr_t *attr) destroys a mutex attributes object; the object becomes, in effect, uninitialized. An implementation may cause pthread_mutexattr_destroy() to set the object referenced by 'attr' to an invalid value. *NOTE: What the last sentence states is implementation specific, thus it will not be covered. A destroyed 'attr' attributes object can be reinitialized using pthread_mutexattr_init(); the results of referencing an 'attr' object after it has been destroyed are undefined. If success, it returns 0. An error number may be returned if: [EINVAL] The value specified by 'attr' is invalid posixtestsuite/conformance/interfaces/pthread_mutexattr_destroy/coverage.txt0100644000000000000000000000045207622322634027166 0ustar rootrootThis document defines the coverage for the pthread_mutexattr_destroy function: Assertion Tested? 1 YES 2 YES 3 YES 4 YES ** Keeping in mind it 'may' fail and not 'shall' fail, so it will always return PASS, but will return a PASS and print out a warning if it fails. Note: posixtestsuite/conformance/interfaces/pthread_mutexattr_destroy/2-1.c0100644000000000000000000000276007613731625025305 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: bing.wei.liu REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test pthread_mutexattr_destroy() * A destroyed 'attr' attributes object can be reinitialized using * pthread_mutexattr_init(); the results of otherwise referencing the * object after it has been destroyed are undefined. * * Steps: * 1. Initialize a pthread_mutexattr_t object using pthread_mutexattr_init() * 2. Destroy that initialized attribute using pthread_mutexattr_destroy() * 3. Initialize the pthread_mutexattr_t object again. This should not result * in any error. * */ #include #include #include #include "posixtest.h" int main() { pthread_mutexattr_t mta; /* Initialize a mutex attributes object */ if(pthread_mutexattr_init(&mta) != 0) { fprintf(stderr,"Cannot initialize mutex attributes object\n"); return PTS_UNRESOLVED; } /* Destroy the mutex attributes object */ if(pthread_mutexattr_destroy(&mta) != 0) { fprintf(stderr,"Cannot destroy the mutex attributes object\n"); return PTS_UNRESOLVED; } /* Initialize the mutex attributes object again. This shouldn't result in an error. */ if(pthread_mutexattr_init(&mta) != 0) { printf("Test FAILED\n"); return PTS_FAIL; } else { printf("Test PASSED\n"); return PTS_PASS; } } posixtestsuite/conformance/interfaces/pthread_mutexattr_destroy/3-1.c0100644000000000000000000000214207613731625025300 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: bing.wei.liu REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test pthread_mutexattr_destroy() * Upon successful completion, pthread_mutexattr_destroy() shall * return a value of 0. * * Steps: * 1. Initialize a pthread_mutexattr_t object using pthread_mutexattr_init() * 2. Destroy that initialized attribute using pthread_mutexattr_destroy(). * This should return 0; * */ #include #include #include #include "posixtest.h" int main() { pthread_mutexattr_t mta; /* Initialize a mutex attributes object */ if(pthread_mutexattr_init(&mta) != 0) { fprintf(stderr,"Cannot initialize mutex attributes object\n"); return PTS_UNRESOLVED; } /* Destroy the mutex attributes object */ if(pthread_mutexattr_destroy(&mta) != 0) { printf("Test FAILED\n"); return PTS_FAIL; } else { printf("Test PASSED\n"); return PTS_PASS; } } posixtestsuite/conformance/interfaces/clock_getcpuclockid/0040755000000000000000000000000010515625161023306 5ustar rootrootposixtestsuite/conformance/interfaces/clock_getcpuclockid/1-1.c0100644000000000000000000000311610470232722023743 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * * @pt:CPT * General test that clock_getcpuclockid() returns CPU-time clock for a * process. The process chosen is the current process. * * * 12/17/02 - Checking in correction made by * jim.houston REMOVE-THIS AT attbi DOT com * Test needed to do something as opposed to idle sleep to * get the CPU time to increase. */ #define _XOPEN_SOURCE 600 #include #include #include #include "posixtest.h" #define LARGENUMBER 900000 void dosomething() { int i; for (i=0; i < LARGENUMBER; i++) { clock(); } } int main(int argc, char *argv[]) { #if _POSIX_CPUTIME == -1 printf("_POSIX_CPUTIME unsupported\n"); return PTS_UNSUPPORTED; #else clockid_t clockid; struct timespec tp1 = {.tv_sec = 0, .tv_nsec = 0}; if (sysconf(_SC_CPUTIME) == -1) { printf("_POSIX_CPUTIME unsupported\n"); return PTS_UNSUPPORTED; } dosomething(); if (clock_getcpuclockid(getpid(), &clockid) != 0) { printf("clock_getcpuclockid() failed\n"); return PTS_FAIL; } /* Verify that it returned a valid clockid_t that can be used in other functions */ if (clock_gettime(clockid, &tp1) != 0) { printf("clock_getcpuclockid() returned an invalid clockid_t: %d\n", clockid); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; #endif } posixtestsuite/conformance/interfaces/clock_getcpuclockid/assertions.xml0100644000000000000000000000176407566263004026235 0ustar rootroot clock_getcpuclockid() takes a process ID, pid, as input and returns the CPU-time clock, clock_id. If pid=0, then clock_getcpuclockid() will return the CPU-time clock of the calling process. clock_getcpuclockid() returns 0 on success. clock_getcpuclockid() returns -1 on failure. clock_getcpuclockid() sets errno to EPERM if the calling process doesn't have the permission to know the CPU-time clock for process ID, pid. When this happens is implementation-defined. clock_getcpuclockid() _may_ fail and set errno to ESRCH if no process can be found corresponding to pid. posixtestsuite/conformance/interfaces/clock_getcpuclockid/coverage.txt0100644000000000000000000000001410035207702025624 0ustar rootroot1 YES 2 YES posixtestsuite/conformance/interfaces/clock_getcpuclockid/2-1.c0100644000000000000000000000334010470232722023743 0ustar rootroot/* * Copyright (c) 2004, Intel Corporation. All rights reserved. * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * * If pid=0, then clock_getcpuclockid() will return the CPU-time clock of * the calling process. * */ #define _XOPEN_SOURCE 600 #include #include #include #include #include "posixtest.h" int main(int argc, char *argv[]) { #if _POSIX_CPUTIME == -1 printf("_POSIX_CPUTIME unsupported\n"); return PTS_UNSUPPORTED; #else unsigned long time_to_set; clockid_t clockid_1, clockid_2; struct timespec tp1, tp2; if (sysconf(_SC_CPUTIME) == -1) { printf("_POSIX_CPUTIME unsupported\n"); return PTS_UNSUPPORTED; } if (clock_getcpuclockid(getpid(), &clockid_1) != 0) { printf("clock_getcpuclockid(getpid(), ) failed\n"); return PTS_FAIL; } if (clock_getcpuclockid(0, &clockid_2) != 0) { printf("clock_getcpuclockid(0, ) failed\n"); return PTS_FAIL; } /* Set clockid_1 as a random value from 1 sec to 10 sec */ srand((unsigned long)time(NULL)); time_to_set = rand() * 10.0 / RAND_MAX + 1; tp1.tv_sec = time_to_set; tp1.tv_nsec = 0; if (clock_settime(clockid_1, &tp1) != 0) { printf("clock_getcpuclockid() returned an invalid clockid_t: " "%d\n", clockid_1); return PTS_FAIL; } /* Get the time of clockid_2, should almost the same as clockid_1 */ if (clock_gettime(clockid_2, &tp2) != 0) { printf("clock_getcpuclockid() returned an invalid clockid_t: " "%d\n", clockid_2); return PTS_FAIL; } if (tp1.tv_sec == tp2.tv_sec) { printf("Test PASSED\n"); return PTS_PASS; } printf("Test FAILED\n"); return PTS_FAIL; #endif } posixtestsuite/conformance/interfaces/aio_read/0040755000000000000000000000000010515625160021055 5ustar rootrootposixtestsuite/conformance/interfaces/aio_read/11-2.c0100644000000000000000000000336210247562115021604 0ustar rootroot/* * Copyright (c) 2004, Bull SA. All rights reserved. * Created by: Laurent.Vivier@bull.net * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * assertion: * * aio_read() shall fail with [EINVAL] or the error status of the operation * shall be [EINVAL] if aio_offset would be invalid, or aio_reqprio is not a valid * value, or aio_nbytes is an invalid value. * * Testing invalid reqprio * * method: * * - Create an aiocb with an invalid aio_reqprio * - call aio_read with this aiocb */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include #include #include #include "posixtest.h" #define TNAME "aio_read/11-2.c" int main() { char tmpfname[256]; #define BUF_SIZE 111 char buf[BUF_SIZE]; int fd; struct aiocb aiocb; #if _POSIX_ASYNCHRONOUS_IO != 200112L exit(PTS_UNSUPPORTED); #endif snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_aio_read_11_2%d", getpid()); unlink(tmpfname); fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL, S_IRUSR | S_IWUSR); if (fd == -1) { printf(TNAME " Error at open(): %s\n", strerror(errno)); exit(PTS_UNRESOLVED); } unlink(tmpfname); memset(&aiocb, 0, sizeof(struct aiocb)); aiocb.aio_fildes = fd; aiocb.aio_buf = buf; aiocb.aio_reqprio = -1; aiocb.aio_nbytes = BUF_SIZE; if (aio_read(&aiocb) != -1) { printf(TNAME " bad aio_read return value()\n"); exit(PTS_FAIL); } if (errno != EINVAL) { printf(TNAME " errno is not EINVAL %s\n", strerror(errno)); exit(PTS_FAIL); } close(fd); printf ("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/aio_read/15-1.c0100644000000000000000000000146010504222550021574 0ustar rootroot/* * Copyright (c) 2004, Bull SA. All rights reserved. * Created by: Laurent.Vivier@bull.net * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * assertion: * * aio_read() shall fail with: * [EOVERFLOW] if aio_nbytes is greater than 0, aio_offset is before EOF * and is at or beyond the offset maximum associated with aio_fildes. * * method: * * UNTESTED * */ #define _XOPEN_SOURCE 600 #include #include #include #include "posixtest.h" int main() { char tmpfname[256]; #define BUF_SIZE 1024 char buf[BUF_SIZE]; int fd; struct aiocb aiocb; struct rlimit limit; #if _POSIX_ASYNCHRONOUS_IO != 200112L exit(PTS_UNSUPPORTED); #endif return PTS_UNTESTED; } posixtestsuite/conformance/interfaces/aio_read/5-1.c0100644000000000000000000000455410247562115021532 0ustar rootroot/* * Copyright (c) 2004, Bull SA. All rights reserved. * Created by: Laurent.Vivier@bull.net * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * assertion: * * aio_lio_opcode shall be ignored. * * method: * * - write data to a file * - fill in an aiocb with an LIO_WRITE aio_lio_opcode * - call aio_read with this aiocb * - check data is effectively read (ignoring aio_lio_opcode) */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include #include #include #include "posixtest.h" #define TNAME "aio_read/5-1.c" int main() { char tmpfname[256]; #define BUF_SIZE 111 unsigned char buf[BUF_SIZE]; unsigned char check[BUF_SIZE]; int fd; struct aiocb aiocb; int i; #if _POSIX_ASYNCHRONOUS_IO != 200112L exit(PTS_UNSUPPORTED); #endif snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_aio_read_5_1_%d", getpid()); unlink(tmpfname); fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL, S_IRUSR | S_IWUSR); if (fd == -1) { printf(TNAME " Error at open(): %s\n", strerror(errno)); exit(PTS_UNRESOLVED); } unlink(tmpfname); for (i = 0; i < BUF_SIZE; i++) buf[i] = i; if (write(fd, buf, BUF_SIZE) != BUF_SIZE) { printf(TNAME " Error at write(): %s\n", strerror(errno)); exit(PTS_UNRESOLVED); } memset(check, 0xaa, BUF_SIZE); memset(&aiocb, 0, sizeof(struct aiocb)); aiocb.aio_fildes = fd; aiocb.aio_buf = check; aiocb.aio_nbytes = BUF_SIZE; aiocb.aio_lio_opcode = LIO_WRITE; if (aio_read(&aiocb) == -1) { printf(TNAME " Error at aio_read(): %s\n", strerror(errno)); exit(PTS_FAIL); } int err; int ret; /* Wait until end of transaction */ while ((err = aio_error (&aiocb)) == EINPROGRESS); err = aio_error(&aiocb); ret = aio_return(&aiocb); if (err != 0) { printf(TNAME " Error at aio_error() : %s\n", strerror (err)); close(fd); exit(PTS_FAIL); } if (ret != BUF_SIZE) { printf(TNAME " Error at aio_return()\n"); close(fd); exit(PTS_FAIL); } /* check it */ for (i = 0; i < BUF_SIZE; i++) { if (buf[i] != check[i]) { printf(TNAME " read values are corrupted\n"); exit(PTS_FAIL); } } close(fd); printf ("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/aio_read/4-1.c0100644000000000000000000000452410247562115021526 0ustar rootroot/* * Copyright (c) 2004, Bull SA. All rights reserved. * Created by: Laurent.Vivier@bull.net * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * assertion: * * The file is read at offset given by aio_offset. * * method: * * - write data to a file * - read file using aio_read at a given offset * - check data is consistent */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include #include #include #include "posixtest.h" #define TNAME "aio_read/4-1.c" int main() { char tmpfname[256]; #define BUF_SIZE 512 unsigned char buf[BUF_SIZE*2]; unsigned char check[BUF_SIZE]; int fd; struct aiocb aiocb; int i; #if _POSIX_ASYNCHRONOUS_IO != 200112L exit(PTS_UNSUPPORTED); #endif snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_aio_read_4_1_%d", getpid()); unlink(tmpfname); fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL, S_IRUSR | S_IWUSR); if (fd == -1) { printf(TNAME " Error at open(): %s\n", strerror(errno)); exit(PTS_UNRESOLVED); } unlink(tmpfname); memset (&buf[0], 1, BUF_SIZE); memset (&buf[BUF_SIZE], 2, BUF_SIZE); if (write(fd, buf, BUF_SIZE*2) != BUF_SIZE*2) { printf(TNAME " Error at write(): %s\n", strerror(errno)); exit(PTS_UNRESOLVED); } memset(check, 0xaa, BUF_SIZE); memset(&aiocb, 0, sizeof(struct aiocb)); aiocb.aio_fildes = fd; aiocb.aio_buf = check; aiocb.aio_nbytes = BUF_SIZE; aiocb.aio_offset = BUF_SIZE; if (aio_read(&aiocb) == -1) { printf(TNAME " Error at aio_read(): %s\n", strerror(errno)); exit(PTS_FAIL); } int err; int ret; /* Wait until end of transaction */ while ((err = aio_error (&aiocb)) == EINPROGRESS); err = aio_error(&aiocb); ret = aio_return(&aiocb); if (err != 0) { printf(TNAME " Error at aio_error() : %s\n", strerror (err)); close(fd); exit(PTS_FAIL); } if (ret != BUF_SIZE) { printf(TNAME " Error at aio_return()\n"); close(fd); exit(PTS_FAIL); } /* check it */ for (i = 0; i < BUF_SIZE; i++) { if (check[i] != 2) { printf(TNAME " read values are corrupted\n"); close(fd); exit(PTS_FAIL); } } close(fd); printf ("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/aio_read/14-1.c0100644000000000000000000000134410247562115021604 0ustar rootroot/* * Copyright (c) 2004, Bull SA. All rights reserved. * Created by: Laurent.Vivier@bull.net * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * assertion: * * The error status of a succesfully queued operation shall be: * [EINVAL] if aio_offset woud be invalid, or aio_reqprio is not a valid * value, or aio_nbytes is an invalid value. * * method: * * UNTESTED * */ #define _XOPEN_SOURCE 600 #include #include #include #include "posixtest.h" #define TNAME "aio_read/14-1.c" int main() { #if _POSIX_ASYNCHRONOUS_IO != 200112L exit(PTS_UNSUPPORTED); #endif return PTS_UNTESTED; } posixtestsuite/conformance/interfaces/aio_read/12-1.c0100644000000000000000000000131010247562115021573 0ustar rootroot/* * Copyright (c) 2004, Bull SA. All rights reserved. * Created by: Laurent.Vivier@bull.net * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * assertion: * * The error status of a succesfully queued operation shall be: * [EBADF] if the aio_fildes argument is not a valid file descriptor open for * reading. * * method: * * UNTESTED * */ #define _XOPEN_SOURCE 600 #include #include #include #include "posixtest.h" #define TNAME "aio_read/12-1.c" int main() { #if _POSIX_ASYNCHRONOUS_IO != 200112L exit(PTS_UNSUPPORTED); #endif return PTS_UNTESTED; } posixtestsuite/conformance/interfaces/aio_read/1-1.c0100644000000000000000000000436010247562115021521 0ustar rootroot/* * Copyright (c) 2004, Bull SA. All rights reserved. * Created by: Laurent.Vivier@bull.net * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * assertion: * * aio_read() shall read aio_nbytes from the files aio_fildes into the * buffer aio_buf. * * method: * * - write 1024 bytes into a file * - read 256 bytes using aio_read */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include "posixtest.h" #define TNAME "aio_read/1-1.c" int main() { char tmpfname[256]; #define WBUF_SIZE 1024 char buf[WBUF_SIZE]; #define RBUF_SIZE 256 char check[RBUF_SIZE]; int fd; int i; int err; int ret; struct aiocb aiocb; #if _POSIX_ASYNCHRONOUS_IO != 200112L exit(PTS_UNSUPPORTED); #endif snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_aio_read_1_1_%d", getpid()); unlink(tmpfname); fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL, S_IRUSR | S_IWUSR); if (fd == -1) { printf(TNAME " Error at open(): %s\n", strerror(errno)); exit(PTS_UNRESOLVED); } unlink(tmpfname); for (i=0; i #include #include #include #include #include #include "posixtest.h" #define TNAME "aio_read/9-1.c" #define NUM_AIOCBS 1024 int main() { char tmpfname[256]; #define BUF_SIZE 512 char buf[BUF_SIZE]; int fd; int i; struct aiocb aiocbs[NUM_AIOCBS]; int last_req; int err; int ret; #if _POSIX_ASYNCHRONOUS_IO != 200112L exit(PTS_UNSUPPORTED); #endif snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_aio_write_4_1_%d", getpid()); unlink(tmpfname); fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL, S_IRUSR | S_IWUSR); if (fd == -1) { printf(TNAME " Error at open(): %s\n", strerror(errno)); exit(PTS_UNRESOLVED); } unlink(tmpfname); if (write(fd, buf, BUF_SIZE) != BUF_SIZE) { printf(TNAME " Error at write(): %s\n", strerror(errno)); close(fd); exit(PTS_UNRESOLVED); } for (i=0; i #include #include #include #include #include #include #include #include #include "posixtest.h" #define TNAME "aio_read/11-1.c" int main() { char tmpfname[256]; #define BUF_SIZE 111 char buf[BUF_SIZE]; int fd; struct aiocb aiocb; #if _POSIX_ASYNCHRONOUS_IO != 200112L exit(PTS_UNSUPPORTED); #endif snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_aio_read_11_1_%d", getpid()); unlink(tmpfname); fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL, S_IRUSR | S_IWUSR); if (fd == -1) { printf(TNAME " Error at open(): %s\n", strerror(errno)); exit(PTS_UNRESOLVED); } unlink(tmpfname); if (write(fd, buf, BUF_SIZE) != BUF_SIZE) { printf(TNAME " Error at write(): %s\n", strerror(errno)); exit(PTS_UNRESOLVED); } memset(&aiocb, 0, sizeof(struct aiocb)); aiocb.aio_fildes = fd; aiocb.aio_buf = buf; aiocb.aio_offset = -1; aiocb.aio_nbytes = BUF_SIZE; if (aio_read(&aiocb) != -1) { while (aio_error (&aiocb) == EINPROGRESS); int err = aio_error (&aiocb); int ret = aio_return (&aiocb); if (ret != -1) { printf(TNAME " bad aio_read return value\n"); close (fd); exit(PTS_FAIL); } else if (err != EINVAL) { printf(TNAME " error code is not EINVAL %s\n", strerror(errno)); close (fd); exit(PTS_FAIL); } } else { if (errno != EINVAL) { printf(TNAME " errno is not EINVAL %s\n", strerror(errno)); close(fd); exit(PTS_FAIL); } } close(fd); printf ("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/aio_read/6-1.c0100644000000000000000000000124510504222550021515 0ustar rootroot/* * Copyright (c) 2004, Bull SA. All rights reserved. * Created by: Laurent.Vivier@bull.net * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * assertion: * * For regular files, no data transfer shall occur past the offset * maximum established in the open file description associated with * aio_fildes. * * method: * * UNTESTED * */ #define _XOPEN_SOURCE 600 #include #include #include #include "posixtest.h" int main() { #if _POSIX_ASYNCHRONOUS_IO != 200112L exit(PTS_UNSUPPORTED); #endif return PTS_UNTESTED; } posixtestsuite/conformance/interfaces/aio_read/10-1.c0100644000000000000000000000257110247562115021603 0ustar rootroot/* * Copyright (c) 2004, Bull SA. All rights reserved. * Created by: Laurent.Vivier@bull.net * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * assertion: * * aio_read() shall fail with [EBADF] or the error status of the operation * shall be [EBADF] if aio_fildes argument is not a valid file descriptor open for * reading. * * method: * * - Create an aiocb with an invalid aio_filedes * - call aio_read with this aiocb * - check return code and errno */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include #include #include #include "posixtest.h" #define TNAME "aio_read/10-1.c" int main() { #define BUF_SIZE 111 char buf[BUF_SIZE]; struct aiocb aiocb; #if _POSIX_ASYNCHRONOUS_IO != 200112L exit(PTS_UNSUPPORTED); #endif memset(buf, 0xaa, BUF_SIZE); memset(&aiocb, 0, sizeof(struct aiocb)); aiocb.aio_fildes = -1; aiocb.aio_buf = buf; aiocb.aio_nbytes = BUF_SIZE; if (aio_read(&aiocb) != -1) { printf(TNAME " bad aio_read return value()\n"); exit(PTS_FAIL); } if (errno != EBADF) { printf(TNAME " errno is not EBADF %s\n", strerror(errno)); exit(PTS_FAIL); } printf ("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/aio_read/13-1.c0100644000000000000000000000127110247562115021602 0ustar rootroot/* * Copyright (c) 2004, Bull SA. All rights reserved. * Created by: Laurent.Vivier@bull.net * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * assertion: * * The error status of a succesfully queued operation shall be: * [ECANCELED] if The requested I/O was canceled before the I/O completed. * * method: * * UNTESTED * */ #define _XOPEN_SOURCE 600 #include #include #include #include "posixtest.h" #define TNAME "aio_read/13-1.c" int main() { #if _POSIX_ASYNCHRONOUS_IO != 200112L exit(PTS_UNSUPPORTED); #endif return PTS_UNTESTED; } posixtestsuite/conformance/interfaces/aio_read/3-2.c0100644000000000000000000000416010247562115021522 0ustar rootroot/* * Copyright (c) 2004, Bull SA. All rights reserved. * Created by: Laurent.Vivier@bull.net * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * assertion: * * aiocbp may be be used as an argument to aio_error() and aio_return(). * * method: (short read) * * - write data to a file * - read file using aio_read * - check error and return codes using previous aiocb */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include #include #include #include "posixtest.h" #define TNAME "aio_read/3-2.c" int main() { char tmpfname[256]; #define BUF_SIZE 1024 char buf[BUF_SIZE]; int fd; struct aiocb aiocb; #if _POSIX_ASYNCHRONOUS_IO != 200112L exit(PTS_UNSUPPORTED); #endif snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_aio_read_3_2_%d", getpid()); unlink(tmpfname); fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL, S_IRUSR | S_IWUSR); if (fd == -1) { printf(TNAME " Error at open(): %s\n", strerror(errno)); exit(PTS_UNRESOLVED); } unlink(tmpfname); if (write(fd, buf, BUF_SIZE/2) != BUF_SIZE/2) { printf(TNAME " Error at write(): %s\n", strerror(errno)); exit(PTS_UNRESOLVED); } /* try to read BUF_SIZE bytes whereas the file is BUF_SIZE/2 long */ memset(&aiocb, 0, sizeof(struct aiocb)); aiocb.aio_fildes = fd; aiocb.aio_buf = buf; aiocb.aio_nbytes = BUF_SIZE; if (aio_read(&aiocb) == -1) { printf(TNAME " Error at aio_read(): %s\n", strerror(errno)); exit(PTS_FAIL); } /* Wait for request completion */ while (aio_error(&aiocb) == EINPROGRESS); /* error status shall be 0 and return status shall be BUF_SIZE/2 */ while (aio_error(&aiocb) == EINPROGRESS); if (aio_error(&aiocb) != 0) { printf(TNAME " Error at aio_error()\n"); exit(PTS_FAIL); } if (aio_return(&aiocb) != BUF_SIZE/2) { printf(TNAME " Error at aio_return()\n"); exit(PTS_FAIL); } close(fd); printf ("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/aio_read/7-1.c0100644000000000000000000000304610247562115021527 0ustar rootroot/* * Copyright (c) 2004, Bull SA. All rights reserved. * Created by: Laurent.Vivier@bull.net * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * assertion: * * The aio_read() function shall return the value zero if operation is * successfuly queued. * * method: * * - write data to a file * - read file using aio_read * - check aio_read return value */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include #include #include #include "posixtest.h" #define TNAME "aio_read/7-1.c" int main() { char tmpfname[256]; #define BUF_SIZE 111 unsigned char check[BUF_SIZE]; int fd; struct aiocb aiocb; #if _POSIX_ASYNCHRONOUS_IO != 200112L exit(PTS_UNSUPPORTED); #endif snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_aio_read_7_1_%d", getpid()); unlink(tmpfname); fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL, S_IRUSR | S_IWUSR); if (fd == -1) { printf(TNAME " Error at open(): %s\n", strerror(errno)); exit(PTS_UNRESOLVED); } unlink(tmpfname); memset(check, 0xaa, BUF_SIZE); memset(&aiocb, 0, sizeof(struct aiocb)); aiocb.aio_fildes = fd; aiocb.aio_buf = check; aiocb.aio_nbytes = BUF_SIZE; if (aio_read(&aiocb) == -1) { printf(TNAME " Error at aio_read(): %s\n", strerror(errno)); exit(PTS_FAIL); } close(fd); printf ("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/aio_read/assertions.xml0100644000000000000000000000544710245504305023775 0ustar rootroot aio_read() shall read aio_nbytes from the files aio_fildes into the buffer aio_buf. If prioritized I/O is supported asynchronous operation shall be submitted at priority equal to a base schedulling priority minus aio_reqprio. aiocbp may be be used as an argument to aio_error() and aio_return(). The file is read at offset given by aio_offset. aio_lio_opcode shall be ignored. For regular files, no data transfer shall occur past the offset maximum established in the open file description associated with aio_fildes. The aio_read() function shall return the value zero if operation is successfuly queued. The aio_read() function shall return the value -1 and set errno to indicate error if the operation is not succesfully queued. aio_read() shall fail with [EAGAIN] if: The requested AIO operation was not queued to the system due to system resource limitations. aio_read() shall fail with [EBADF] or the error status of the operation shall be [EBADF] if aio_fildes argument is not a valid file descriptor open for reading. aio_read() shall fail with [EINVAL] or the error status of the operation shall be [EINVAL] if aio_offset would be invalid, or aio_reqprio is not a valid value, or aio_nbytes is an invalid value. The error status of a succesfully queued operation shall be: [EBADF] if the aio_fildes argument is not a valid file descriptor open for reading. The error status of a succesfully queued operation shall be: [ECANCELED] if The requested I/O was canceled before the I/O completed. The error status of a succesfully queued operation shall be: [EINVAL] if aio_offset would be invalid, or aio_reqprio is not a valid value, or aio_nbytes is an invalid value. aio_read() shall fail with: [EOVERFLOW] if aio_nbytes is greater than 0, aio_offset is before EOF and is at or beyond the offset maximum associated with aio_fildes. posixtestsuite/conformance/interfaces/aio_read/coverage.txt0100644000000000000000000000030310245504305023377 0ustar rootrootthis file defines the coverage for the aio_read() function testing. Assertion Covered? 1 YES 2 NO 3 YES 4 YES 5 YES 6 YES 7 YES 8 YES 9 YES 10 YES 11 YES 12 NO 13 NO 14 NO 15 YES posixtestsuite/conformance/interfaces/aio_read/8-1.c0100644000000000000000000000222410247562115021525 0ustar rootroot/* * Copyright (c) 2004, Bull SA. All rights reserved. * Created by: Laurent.Vivier@bull.net * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * assertion: * * The aio_read() function shall return the value -1 and set errno to * indicate error if the operation is not succesfully queued. * * method: * * - fill in an aiocb with a NULL aio_buf * - call aio_read * - check aio_read return value */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include #include #include #include "posixtest.h" #define TNAME "aio_read/8-1.c" int main() { struct aiocb aiocb; #if _POSIX_ASYNCHRONOUS_IO != 200112L exit(PTS_UNSUPPORTED); #endif /* submit a request with a NULL buffer */ aiocb.aio_fildes = 0; aiocb.aio_buf = NULL; aiocb.aio_nbytes = 0; aiocb.aio_offset = 0; if (aio_read(&aiocb) != -1) { printf(TNAME " aio_read() should fail!\n"); exit(PTS_FAIL); } printf ("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/aio_read/2-1.c0100644000000000000000000000141110247562115021514 0ustar rootroot/* * Copyright (c) 2004, Bull SA. All rights reserved. * Created by: Laurent.Vivier@bull.net * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * assertion: * * If prioritized I/O is supported asynchronous operation shall be * submitted at priority equal to a base schedulling priority minus * aio_reqprio. * * method: * */ #define _XOPEN_SOURCE 600 #include #include #include #include #include "posixtest.h" #define TNAME "aio_read/2-1.c" int main() { #if _POSIX_ASYNCHRONOUS_IO != 200112L exit(PTS_UNSUPPORTED); #endif #ifndef _POSIX_PRIORITIZED_IO exit(PTS_UNSUPPORTED); #endif return PTS_UNTESTED; } posixtestsuite/conformance/interfaces/aio_read/3-1.c0100644000000000000000000000402310247562115021517 0ustar rootroot/* * Copyright (c) 2004, Bull SA. All rights reserved. * Created by: Laurent.Vivier@bull.net * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * assertion: * * aiocbp may be be used as an argument to aio_error() and aio_return(). * * method: * * - write data to a file * - read file using aio_read * - check error and return codes using previous aiocb */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include #include #include #include "posixtest.h" #define TNAME "aio_read/3-1.c" int main() { char tmpfname[256]; #define BUF_SIZE 111 char buf[BUF_SIZE]; int fd; struct aiocb aiocb; #if _POSIX_ASYNCHRONOUS_IO != 200112L exit(PTS_UNSUPPORTED); #endif snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_aio_read_3_1_%d", getpid()); unlink(tmpfname); fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL, S_IRUSR | S_IWUSR); if (fd == -1) { printf(TNAME " Error at open(): %s\n", strerror(errno)); exit(PTS_UNRESOLVED); } unlink(tmpfname); if (write(fd, buf, BUF_SIZE) != BUF_SIZE) { printf(TNAME " Error at write(): %s\n", strerror(errno)); exit(PTS_UNRESOLVED); } memset(&aiocb, 0, sizeof(struct aiocb)); aiocb.aio_fildes = fd; aiocb.aio_buf = buf; aiocb.aio_nbytes = BUF_SIZE; if (aio_read(&aiocb) == -1) { printf(TNAME " Error at aio_read(): %s\n", strerror(errno)); exit(PTS_FAIL); } /* Wait for request completion */ while (aio_error(&aiocb) == EINPROGRESS); /* error status shall be 0 and return status shall be BUF_SIZE */ while (aio_error(&aiocb) == EINPROGRESS); if (aio_error(&aiocb) != 0) { printf(TNAME " Error at aio_error()\n"); exit(PTS_FAIL); } if (aio_return(&aiocb) != BUF_SIZE) { printf(TNAME " Error at aio_return()\n"); exit(PTS_FAIL); } close(fd); printf ("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_rwlock_init/0040755000000000000000000000000010515625223023345 5ustar rootrootposixtestsuite/conformance/interfaces/pthread_rwlock_init/1-1.c0100644000000000000000000000534507670214457024026 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * * Test pthread_rwlock_init(). * * pthread_rwlock_init( ) function shall allocate any resources * required to use the read-write lock referenced by rwlock and * initializes the lock to an unlocked state with attributes referenced * by attr. * * Steps: * 1. Initialize a pthread_rwlock_t object 'rwlock' with pthread_rwlock_init() * 2. Create a child thread, the thread lock 'rwlock' for reading, shall not block. */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include "posixtest.h" static pthread_rwlock_t rwlock; static int thread_state; static void* fn_rd(void *arg) { thread_state = 2; int rc; printf("child: lock for reading\n"); rc = pthread_rwlock_rdlock(&rwlock); if(rc == 0) { printf("child: get read lock\n"); printf("child: unlock\n"); if(pthread_rwlock_unlock(&rwlock) != 0) { printf("child: release read lock\n"); exit(PTS_UNRESOLVED); } } else { printf("Error in pthread_rwlock_rdlock().\n"); exit(PTS_FAIL); } thread_state = 3; pthread_exit(0); return NULL; } int main() { int cnt = 0; int rc = 0; thread_state=0; pthread_t thread; pthread_rwlockattr_t rwlockattr; if(pthread_rwlockattr_init(&rwlockattr) != 0) { printf("main: Error at pthread_rwlockattr_init()\n"); return PTS_UNRESOLVED; } rc = pthread_rwlock_init(&rwlock, &rwlockattr); if(rc != 0) { printf("Test FAILED: Error at pthread_rwlock_init(), returns %d\n", rc); return PTS_FAIL; } thread_state = 1; printf("main: create thread\n"); if(pthread_create(&thread, NULL, fn_rd, NULL) != 0) { printf("main: failed to create thread\n"); return PTS_UNRESOLVED; } /* If the shared data is not altered by child after 3 seconds, we regard it as blocked */ /* We expect the thread not to block*/ cnt = 0; do{ sleep(1); }while (thread_state !=3 && cnt++ < 3); if(thread_state == 2) { printf("Test FAILED: thread blocked on read lock\n"); exit(PTS_FAIL); } else if(thread_state != 3) { printf("main: Unexpected thread state\n"); exit(PTS_UNRESOLVED); } if(pthread_join(thread, NULL) != 0) { printf("main: Error at pthread_join()\n"); exit(PTS_UNRESOLVED); } /* Cleanup */ if(pthread_rwlock_destroy(&rwlock) != 0) { printf("Error at pthread_rwlock_destroy()\n"); return PTS_UNRESOLVED; } if(pthread_rwlockattr_destroy(&rwlockattr) != 0) { printf("Error at pthread_rwlockattr_destroy()\n"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_rwlock_init/6-1.c0100644000000000000000000000311107670214457024020 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * * Test pthread_rwlock_init(). * * May fail if: * [EBUSY] The implementation has detected an attempt to reinitialize the object * referenced by rwlock, a previously initialized but not yet destroyed read-write * lock. * * Steps: * 1. Initialize a pthread_rwlock_t object 'rwlock' with pthread_rwlock_init(). * 2. Re-initialize it again without destroying it first. * */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include "posixtest.h" int main() { static pthread_rwlock_t rwlock; int rc; /* Initialize the rwlock */ rc = pthread_rwlock_init(&rwlock, NULL); if(rc != 0) { printf("Test FAILED: Error at pthread_rwlock_init(), returns %d\n", rc); return PTS_FAIL; } /* Re-intialize without destroying it first */ rc = pthread_rwlock_init(&rwlock, NULL); /* Cleanup */ if(pthread_rwlock_destroy(&rwlock) != 0) { printf("Error at pthread_rwlock_destroy()\n"); return PTS_UNRESOLVED; } if(rc == EBUSY) { printf("Test PASSED\n"); return PTS_PASS; } else if (rc == 0) { printf("Test PASSED: Note*: pthread_rwlock_init() returned 0 instead of EBUSY, but standard specifies _may_ fail\n"); return PTS_PASS; } else { printf("Test FAILED: Error at pthread_rwlock_init(), should return 0 or EBUSY, but returns %d\n", rc); return PTS_FAIL; } } posixtestsuite/conformance/interfaces/pthread_rwlock_init/assertions.xml0100644000000000000000000000323107670214457026270 0ustar rootroot pthread_rwlock_init(pthread_rwlock_t *restrict rwlock, const pthread_rwlockattr_t *restrict attr); pthread_rwlock_init( ) function shall allocate any resources required to use the read-write lock referenced by rwlock and initializes the lock to an unlocked state with attributes referenced by attr. If attr is NULL, the default read-write lock attributes shall be used; the effect is the same as passing the address of a default read-write lock attributes object. Once initialized, the lock can be used any number of times without being reinitialized. If successful, the pthread_rwlock_init( ) function shall return zero; otherwise, an error number shall be returned to indicate the error. ptread_rwlock_init( ) function shall fail if: [EAGAIN] The system lacked the necessary resources (other than memory) to initialize another read-write lock. [ENOMEM] Insufficient memory exists to initialize the read-write lock. [EPERM] The caller does not have the privilege to perform the operation. pthread_rwlock_init( ) may fail if: [EBUSY] The implementation has detected an attempt to reinitialize the object referenced by rwlock, a previously initialized but not yet destroyed read-write lock. [EINVAL] The value specified by attr is invalid. posixtestsuite/conformance/interfaces/pthread_rwlock_init/coverage.txt0100644000000000000000000000034307670214457025711 0ustar rootrootThis document defines the coverage for the pthread_rwlock_init() function: Assertion Tested? 1 YES 2 YES 3 YES 4 YES 5 NO **Need to find out how to test EGAIN, ENOMEM and EPERM 6 YES *Tested EBUSY, but not EINVAL NOTE: posixtestsuite/conformance/interfaces/pthread_rwlock_init/2-1.c0100644000000000000000000000460107670214457024021 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * * Test pthread_rwlock_init(). * * If attr is NULL, the default read-write lock attributes shall be used; * the effect is the same as passing the address of a default read-write * lock attributes object. * * Steps: * 1. Initialize a pthread_rwlock_t object 'rwlock' with pthread_rwlock_init(), * set 'attr' as NULL. * 2. Create a child thread, the thread lock 'rwlock' for reading, shall not block. */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include "posixtest.h" static pthread_rwlock_t rwlock; static int thread_state; static void* fn_rd(void *arg) { thread_state = 2; int rc; printf("child: lock for reading\n"); rc = pthread_rwlock_rdlock(&rwlock); if(rc == 0) { printf("child: get read lock\n"); printf("child: unlock\n"); if(pthread_rwlock_unlock(&rwlock) != 0) { printf("child: release read lock\n"); exit(PTS_UNRESOLVED); } } else { printf("Error in pthread_rwlock_rdlock().\n"); exit(PTS_FAIL); } thread_state = 3; pthread_exit(0); return NULL; } int main() { int cnt = 0; int rc = 0; pthread_t thread; rc = pthread_rwlock_init(&rwlock, NULL); if(rc != 0) { printf("Test FAILED: Error at pthread_rwlock_init(), returns %d\n", rc); return PTS_FAIL; } thread_state = 1; printf("main: create thread\n"); if(pthread_create(&thread, NULL, fn_rd, NULL) != 0) { printf("main: failed to create thread\n"); return PTS_UNRESOLVED; } /* If the shared data is not altered by child after 3 seconds, we regard it as blocked */ /* We expect the thread not to block*/ cnt = 0; do{ sleep(1); }while (thread_state !=3 && cnt++ < 3); if(thread_state == 2) { printf("Test FAILED: thread blocked on read lock\n"); exit(PTS_FAIL); } else if(thread_state != 3) { printf("main: Unexpected thread state\n"); exit(PTS_UNRESOLVED); } if(pthread_join(thread, NULL) != 0) { printf("main: Error at pthread_join()\n"); exit(PTS_UNRESOLVED); } if(pthread_rwlock_destroy(&rwlock) != 0) { printf("Error at pthread_rwlock_destroy()\n"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_rwlock_init/4-1.sh0100755000000000000000000000061407670214457024216 0ustar rootroot#!/bin/sh # Copyright (c) 2002, Intel Corporation. All rights reserved. # This file is licensed under the GPL license. For the full content # of this license, see the COPYING file at the top level of this # source tree. # Test pthread_rwlock_destroy returns 0 on success. # This is tested implicitly via assertion 1. echo "Tested implicitly via assertion 1. See output for status" exit 0 posixtestsuite/conformance/interfaces/pthread_rwlock_init/3-1.c0100644000000000000000000000370307670214457024024 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * * Test pthread_rwlock_init(). * * Once initialized, the lock can be used any number of times without being * reinitialized. * * Steps: * 1. Initialize a pthread_rwlock_t object 'rwlock' with pthread_rwlock_init() * 2. Loop for COUNT time: lock for reading, unlock, lock for writing, unlock; */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include "posixtest.h" #define COUNT 1000 static pthread_rwlock_t rwlock; int main() { int cnt = 0; pthread_rwlockattr_t rwlockattr; if(pthread_rwlockattr_init(&rwlockattr) != 0) { printf("Error at pthread_rwlockattr_init()\n"); return PTS_UNRESOLVED; } if(pthread_rwlock_init(&rwlock, &rwlockattr) != 0) { printf("Test FAILED: Error in pthread_rwlock_init()\n"); return PTS_FAIL; } while(cnt++ < COUNT) { if(pthread_rwlock_rdlock(&rwlock) != 0) { printf("Test FAILED: cannot get read lock on %dth loop\n", cnt); return PTS_FAIL; } if(pthread_rwlock_unlock(&rwlock) != 0) { printf("Test FAILED: cannot release read lock on %dth loop\n", cnt); return PTS_FAIL; } if(pthread_rwlock_wrlock(&rwlock) != 0) { printf("Test FAILED: cannot get write lock on %dth loop\n", cnt); return PTS_FAIL; } if(pthread_rwlock_unlock(&rwlock) != 0) { printf("Test FAILED: cannot release write lock on %dth loop\n", cnt); return PTS_FAIL; } } if(pthread_rwlock_destroy(&rwlock) != 0) { printf("Error at pthread_rwlockattr_destroy()\n"); return PTS_UNRESOLVED; } if(pthread_rwlockattr_destroy(&rwlockattr) != 0) { printf("Error at pthread_rwlockattr_destroy()\n"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_setcanceltype/0040755000000000000000000000000010515625226023667 5ustar rootrootposixtestsuite/conformance/interfaces/pthread_setcanceltype/1-1.c0100644000000000000000000000751007627740327024343 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test pthread_setcanceltype * Atomically sets the cancelability type to 'type' and returns the old * cancelability type in the location referenced by 'oldtype'. * 'state' can either be PTHREAD_CANCEL_DEFERRED, or PTHREAD_CANCEL_ASYNCHRONOUS. * * Test when a thread is PTHREAD_CANCEL_ASYNCHRONOUS * * STEPS: * 1. Setup a mutex and lock it in main() * 2. Create a thread. * 3. In the thread function, set the type to PTHREAD_CANCEL_ASYNCHRONOUS * 4. Setup a cleanup handler for the thread. * 5. Make the thread block on the locked mutex * 6. Send out a thread cancel request to the new thread * 7. If the cancel request was honored immediately and correctly, the * cleanup handler would have been executed, and the test will pass. * 8. If not, main will wait for 10 seconds before it unlocks the mutex, and the thread * will exit, failing the test. */ #include #include #include #include #include "posixtest.h" # define INTHREAD 0 /* Control going to or is already for Thread */ # define INMAIN 1 /* Control going to or is already for Main */ # define TIMEOUT 10 /* Time out time in seconds */ int sem1; /* Manual semaphore */ int cleanup_flag; /* Flag to indicate the thread's cleanup handler was called */ pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; /* Mutex */ /* Cleanup function that the thread executes when it is canceled. So if * cleanup_flag is 1, it means that the thread was canceled. */ void a_cleanup_func() { cleanup_flag=1; return; } /* Function that the thread executes upon its creation */ void *a_thread_func() { pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL); pthread_cleanup_push(a_cleanup_func,NULL); /* Indicate to main() that the thread has been created. */ sem1=INMAIN; /* Lock the mutex. It should have already been locked in main, so the thread * should block. */ if(pthread_mutex_lock(&mutex) != 0) { perror("Error in pthread_mutex_lock()\n"); pthread_exit((void*)PTS_UNRESOLVED); return (void*)PTS_UNRESOLVED; } /* Shouldn't get here if the cancel request was honored immediately * like it should have been. */ cleanup_flag=-1; pthread_cleanup_pop(0); pthread_exit(0); return NULL; } int main() { pthread_t new_th; int i=0; /* Initializing values */ sem1=INTHREAD; cleanup_flag=0; /* Lock the mutex */ if(pthread_mutex_lock(&mutex) != 0) { perror("Error in pthread_mutex_lock()\n"); return PTS_UNRESOLVED; } /* Create a new thread. */ if(pthread_create(&new_th, NULL, a_thread_func, NULL) != 0) { perror("Error creating thread\n"); return PTS_UNRESOLVED; } /* Make sure thread is created before we cancel it. (wait for * a_thread_func() to set sem1=INMAIN.) */ while(sem1==INTHREAD) sleep(1); /* Send cancel request to the thread. */ if(pthread_cancel(new_th) != 0) { perror("Test FAILED: Error in pthread_cancel()\n"); return PTS_UNRESOLVED; } /* Wait for the thread to either cancel immediately (as it should do) and call it's * cleanup handler, or for TIMEOUT(10) seconds if the cancel request was not honored * immediately. */ while((cleanup_flag == 0) && (i != TIMEOUT)) { sleep(1); i++; } /* Unlock the mutex */ pthread_mutex_unlock(&mutex); /* This means that the cleanup function wasn't called, so the cancel * request was not honord immediately like it should have been. */ if(cleanup_flag <= 0) { printf("Test FAILED: Cancel request timed out\n"); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_setcanceltype/1-2.c0100644000000000000000000001076307627740330024342 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test pthread_setcanceltype * Atomically sets the cancelability type to 'type' and returns the old * cancelability type in the location referenced by 'oldtype'. * 'state' can either be PTHREAD_CANCEL_DEFERRED, or PTHREAD_CANCEL_ASYNCHRONOUS. * * Test when a thread is PTHREAD_CANCEL_DEFERRED * * STEPS: * 1. Setup a mutex and lock it in main() * 2. Create a thread. * 3. In the thread function, set the type to PTHREAD_CANCEL_DEFERRED * 4. Setup a cleanup handler for the thread. * 5. Make the thread block on the locked mutex * 6. Send out a thread cancel request to the new thread, and unlock the mutex allowing the * thread to continue execution. * 7. If the cancel request was honored immediately, the * cleanup handler would have been executed, setting the cleanup_flag to -1, making the * test fail. * 8. If not, the thread will continue execution, pop the cleanup handler, set the cleanup * flag to 1, and call the cancelation point pthread_testcancel(). The test will pass. * 9. If the thread did not cancel at the cancelation point like it was supposed to, the thread * will continue execution and set the cleanup_flag to -2, failing the test. */ #include #include #include #include #include "posixtest.h" # define INTHREAD 0 /* Control going to or is already for Thread */ # define INMAIN 1 /* Control going to or is already for Main */ int sem1; /* Manual semaphore */ int cleanup_flag; /* Flag to indicate the thread's cleanup handler was called */ pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; /* Mutex */ /* Cleanup function that the thread executes when it is canceled. So if * cleanup_flag is 1, it means that the thread was canceled. */ void a_cleanup_func() { cleanup_flag=-1; return; } /* Function that the thread executes upon its creation */ void *a_thread_func() { pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL); pthread_cleanup_push(a_cleanup_func,NULL); /* Indicate to main() that the thread has been created. */ sem1=INMAIN; /* Lock the mutex. It should have already been locked in main, so the thread * should block. */ if(pthread_mutex_lock(&mutex) != 0) { perror("Error in pthread_mutex_lock()\n"); pthread_exit((void*)PTS_UNRESOLVED); return (void*)PTS_UNRESOLVED; } /* Should get here if the cancel request was deffered. */ pthread_cleanup_pop(0); cleanup_flag=1; /* Cancelation point. Cancel request should not be honored here. */ pthread_testcancel(); /* Should not get here if the cancel request was honored at the cancelation point * pthread_testcancel(). */ cleanup_flag=-2; pthread_exit(0); return NULL; } int main() { pthread_t new_th; /* Initializing values */ sem1=INTHREAD; cleanup_flag=0; /* Lock the mutex */ if(pthread_mutex_lock(&mutex) != 0) { perror("Error in pthread_mutex_lock()\n"); return PTS_UNRESOLVED; } /* Create a new thread. */ if(pthread_create(&new_th, NULL, a_thread_func, NULL) != 0) { perror("Error creating thread\n"); return PTS_UNRESOLVED; } /* Make sure thread is created before we cancel it. (wait for * a_thread_func() to set sem1=INMAIN.) */ while(sem1==INTHREAD) sleep(1); /* Send cancel request to the thread. */ if(pthread_cancel(new_th) != 0) { printf("Test FAILED: Couldn't cancel thread\n"); return PTS_FAIL; } /* Cancel request has been sent, unlock the mutex */ if(pthread_mutex_unlock(&mutex) != 0) { perror("Error in pthread_mutex_unlock()\n"); return PTS_UNRESOLVED; } /* Wait 'till the thread has been canceled or has ended execution. */ if(pthread_join(new_th, NULL) != 0) { perror("Error in pthread_join()\n"); return PTS_UNRESOLVED; } /* This means that the cleanup function wasn't called, so the cancel * request was not honord immediately like it should have been. */ if(cleanup_flag == -1) { printf("Test FAILED: Cancel request was not deferred.\n"); return PTS_FAIL; } if(cleanup_flag == -2) { printf("Test FAILED: (1) Cancel request not honored at cancelation point pthread_testcancel() OR (2) pthread_testcancel() not treated as a cancelation point.\n"); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_setcanceltype/assertions.xml0100644000000000000000000000140707627740331026607 0ustar rootroot The function int pthread_setcanceltype(int type, int* oldtype); Atomically sets the cancelability type to 'type' and returns the old cancelability type in the location referenced by 'oldtype'. 'state' can either be PTHREAD_CANCEL_DEFERRED, or PTHREAD_CANCEL_ASYNCHRONOUS. The cancelability type of a newly created thread is PTHREAD_CANCEL_DEFERRED. It returns a 0 on success. It may return an error code of: [EINVAL] The specified state is not PTHREAD_CANCEL_DEFERRED or PTHREAD_CANCEL_ASYNCHRONOUS. It will not return EINTR. posixtestsuite/conformance/interfaces/pthread_setcanceltype/coverage.txt0100644000000000000000000000016407627740332026227 0ustar rootrootThis document defines the coverage for the pthread_setcanceltype function: Assertion Tested? 1 YES 2 YES 3 YES posixtestsuite/conformance/interfaces/pthread_setcanceltype/2-1.c0100644000000000000000000001043007627740331024332 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test pthread_setcanceltype The cancelability type of a newly created thread is PTHREAD_CANCEL_DEFERRED. * * STEPS: * 1. Setup a mutex and lock it in main() * 2. Create a thread. Without setting the cancel type, the default should be * PTHREAD_CANCEL_DEFERRED. * 3. Setup a cleanup handler for the thread. * 4. Make the thread block on the locked mutex * 5. Send out a thread cancel request to the new thread, and unlock the mutex allowing the * thread to continue execution. * 6. If the cancel request was honored immediately, the * cleanup handler would have been executed, setting the cleanup_flag to -1, making the * test fail. * 7. If not, the thread will continue execution, pop the cleanup handler, set the cleanup * flag to 1, and call the cancelation point pthread_testcancel(). The test will pass. * 8. If the thread did not cancel at the cancelation point like it was supposed to, the thread * will continue execution and set the cleanup_flag to -2, failing the test. */ #include #include #include #include #include "posixtest.h" # define INTHREAD 0 /* Control going to or is already for Thread */ # define INMAIN 1 /* Control going to or is already for Main */ int sem1; /* Manual semaphore */ int cleanup_flag; /* Flag to indicate the thread's cleanup handler was called */ pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; /* Mutex */ /* Cleanup function that the thread executes when it is canceled. So if * cleanup_flag is 1, it means that the thread was canceled. */ void a_cleanup_func() { cleanup_flag=-1; return; } /* Function that the thread executes upon its creation */ void *a_thread_func() { pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); pthread_cleanup_push(a_cleanup_func,NULL); /* Indicate to main() that the thread has been created. */ sem1=INMAIN; /* Lock the mutex. It should have already been locked in main, so the thread * should block. */ if(pthread_mutex_lock(&mutex) != 0) { perror("Error in pthread_mutex_lock()\n"); pthread_exit((void*)PTS_UNRESOLVED); return (void*)PTS_UNRESOLVED; } /* Should get here if the cancel request was deffered. */ pthread_cleanup_pop(0); cleanup_flag=1; /* Cancelation point. Cancel request should not be honored here. */ pthread_testcancel(); /* Should not get here if the cancel request was honored at the cancelation point * pthread_testcancel(). */ cleanup_flag=-2; pthread_exit(0); return NULL; } int main() { pthread_t new_th; /* Initializing values */ sem1=INTHREAD; cleanup_flag=0; /* Lock the mutex */ if(pthread_mutex_lock(&mutex) != 0) { perror("Error in pthread_mutex_lock()\n"); return PTS_UNRESOLVED; } /* Create a new thread. */ if(pthread_create(&new_th, NULL, a_thread_func, NULL) != 0) { perror("Error creating thread\n"); return PTS_UNRESOLVED; } /* Make sure thread is created before we cancel it. (wait for * a_thread_func() to set sem1=INMAIN.) */ while(sem1==INTHREAD) sleep(1); /* Send cancel request to the thread. */ if(pthread_cancel(new_th) != 0) { perror("Test FAILED: Error in pthread_cancel()\n"); return PTS_UNRESOLVED; } /* Cancel request has been sent, unlock the mutex */ if(pthread_mutex_unlock(&mutex) != 0) { perror("Error in pthread_mutex_unlock()\n"); return PTS_UNRESOLVED; } /* Wait 'till the thread has been canceled or has ended execution. */ if(pthread_join(new_th, NULL) != 0) { perror("Error in pthread_join()\n"); return PTS_UNRESOLVED; } /* This means that the cleanup function wasn't called, so the cancel * request was not honord immediately like it should have been. */ if(cleanup_flag == -1) { printf("Test FAILED: Cancel request was not deferred.\n"); return PTS_FAIL; } if(cleanup_flag == -2) { printf("Test FAILED: (1) Cancel request not honored at cancelation point pthread_testcancel() OR (2) pthread_testcancel() not treated as a cancelation point.\n"); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/sched_getscheduler/0040755000000000000000000000000010515625231023135 5ustar rootrootposixtestsuite/conformance/interfaces/sched_getscheduler/5-1.c0100644000000000000000000000311407652175536023617 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * * Test that sched_getscheduler() returns -1 on failure. * * The test create a child process which exit immediately and call * sched_getscheduler with the pid of defunct child. */ #include #include #include #include #include #include #include "posixtest.h" int main(int argc, char **argv) { int result = -1, child_pid; int stat_loc; /* Create a child process which exit immediately */ child_pid = fork(); if(child_pid == -1){ perror("An error occurs when calling fork()"); return PTS_UNRESOLVED; } else if (child_pid == 0){ exit(0); } /* Wait for the child process to exit */ if(wait(&stat_loc) == -1){ perror("An error occurs when calling wait()"); return PTS_UNRESOLVED; } /* Assume the pid is not yet reatributed to an other process */ result = sched_getscheduler(child_pid); if(result == -1) { printf("Test PASSED\n"); return PTS_PASS; } if(errno != ESRCH ) { perror("ESRCH is not returned"); return PTS_FAIL; } if(result != -1) { printf("Returned code is not -1.\n"); return PTS_FAIL; } else { perror("Unresolved test error"); return PTS_UNRESOLVED; } } posixtestsuite/conformance/interfaces/sched_getscheduler/4-1.c0100644000000000000000000000164007652175536023620 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * * Test that sched_getscheduler() returns the scheduling policy of the * specified process on success. */ #include #include #include #include "posixtest.h" int main(int argc, char **argv) { int result = -1; result = sched_getscheduler(0); if(result != -1 && errno == 0) { printf("Test PASSED\n"); return PTS_PASS; } if(errno != 0 ) { perror("Unexpected error"); return PTS_FAIL; } else { perror("Unresolved test error"); return PTS_UNRESOLVED; } } posixtestsuite/conformance/interfaces/sched_getscheduler/1-1.c0100644000000000000000000000213407652175535023613 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * * Test that the scheduling policy is returned for the calling process when * pid = 0 */ #include #include #include #include #include "posixtest.h" int main(int argc, char **argv) { int result0 = -1; int result1 = -1; result0 = sched_getscheduler(0); result1 = sched_getscheduler(getpid()); if(result0 == result1 && errno == 0) { printf("Test PASSED\n"); return PTS_PASS; } else if (result0 != result1) { printf("Different results between pid == 0 and pid == getpid().\n"); return PTS_FAIL; } else { perror("Unexpected error"); return PTS_FAIL; } printf("This code should not be executed.\n"); return PTS_UNRESOLVED; } posixtestsuite/conformance/interfaces/sched_getscheduler/7-1.c0100644000000000000000000000411310033204324023570 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * * Test that sched_getscheduler() sets errno == EPERM when the requesting * process does not have permission */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include #include "posixtest.h" /** Set the euid of this process to a non-root uid */ int set_nonroot() { struct passwd *pw; setpwent(); /* search for the first user which is non root */ while((pw = getpwent()) != NULL) if(strcmp(pw->pw_name, "root")) break; endpwent(); if(pw == NULL) { printf("There is no other user than current and root.\n"); return 1; } if(seteuid(pw->pw_uid) != 0) { if(errno == EPERM) { printf("You don't have permission to change your UID.\n"); return 1; } perror("An error occurs when calling seteuid()"); return 1; } printf("Testing with user '%s' (uid: %d)\n", pw->pw_name, (int)geteuid()); return 0; } int main(int argc, char **argv) { int result = -1; /* We assume process Number 1 is created by root */ /* and can only be accessed by root */ /* This test should be run under standard user permissions */ if (getuid() == 0) { if (set_nonroot() != 0) { printf("Cannot run this test as non-root user\n"); return PTS_UNTESTED; } } result = sched_getscheduler( 1 ); if(result == -1 && errno == EPERM) { printf("Test PASSED\n"); return PTS_PASS; } if(result == 0) { printf("The function sched_getscheduler has successed.\n"); return PTS_FAIL; } if(errno != EPERM ) { perror("errno is not EPERM"); return PTS_FAIL; } else { perror("Unresolved test error"); return PTS_UNRESOLVED; } } posixtestsuite/conformance/interfaces/sched_getscheduler/assertions.xml0100644000000000000000000000236707643302212026055 0ustar rootroot When pid = 0, the scheduling policy is returned for the calling process If pid is negative, the behavior is unspecified The values that can be returned by sched_getscheduler() are defined in the sched.h header sched_getscheduler() returns the scheduling policy of the specified process on success sched_getscheduler() returns -1 on failure sched_getscheduler() sets errno == ESRCH if the pid cannot be found sched_getscheduler() sets errno == EPERM if the requesting process does not have permission posixtestsuite/conformance/interfaces/sched_getscheduler/coverage.txt0100644000000000000000000000070107660447136025501 0ustar rootrootThis document explains why certain assertions were not tested. Assertions not listed here should be covered by the tests in this directory. Assertions Tested ? Remarks 1 YES 2 YES Behavior is unspecified 3 YES Can not test the implementation defined policies 4 YES Don't test that the result is right. 5 YES Assume that a pid is not reatributed immediately 6 YES 7 YES posixtestsuite/conformance/interfaces/sched_getscheduler/2-1.c0100644000000000000000000000131707660447136023614 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Will not test the behavior of sched_getscheduler() when pid is negative * because it is unspecified. */ #include #include "posixtest.h" int main() { printf("Will not test the behavior of sched_getscheduler() when pid is negative\n because it is unspecified.\n"); return PTS_UNTESTED; } posixtestsuite/conformance/interfaces/sched_getscheduler/6-1.sh0100755000000000000000000000030107643302212023765 0ustar rootroot#! /bin/sh # # Test that sched_getscheduler() sets errno == ESRCH if the pid cannot be # found. # This is tested implicitly via assertion 5. echo "Tested implicitly via assertion 5." exit 0 posixtestsuite/conformance/interfaces/sched_getscheduler/3-1.c0100644000000000000000000000266507652175535023626 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * * Test that the values that can be returned by sched_getscheduler() are * defined in the sched.h header */ #include #include #include #include "posixtest.h" struct unique { int value; char *name; } sym[] = { #ifdef SCHED_FIFO { SCHED_FIFO, "SCHED_FIFO" }, #endif #ifdef SCHED_RR { SCHED_RR, "SCHED_RR" }, #endif #ifdef SCHED_SPORADIC { SCHED_SPORADIC,"SCHED_SPORADIC" }, #endif #ifdef SCHED_OTHER { SCHED_OTHER, "SCHED_OTHER" }, #endif { 0, 0 } }; int main(int argc, char **argv) { int result = -1; struct unique *tst; tst = sym; result = sched_getscheduler(0); if(result == -1){ printf("Returned code is -1.\n"); return PTS_FAIL; } if(errno != 0 ) { perror("Unexpected error"); return PTS_FAIL; } while (tst->name) { if(result == tst->value) { printf("Test PASSED\n"); return PTS_PASS; } tst++; } printf("The resulting scheduling policy is not one of standard policy.\nIt could be an implementation defined policy."); return PTS_UNRESOLVED; } posixtestsuite/conformance/interfaces/pthread_attr_setstacksize/0040755000000000000000000000000010515625200024562 5ustar rootrootposixtestsuite/conformance/interfaces/pthread_attr_setstacksize/4-1.c0100644000000000000000000000333010061226115025221 0ustar rootroot/* * Copyright (c) 2004, Intel Corporation. All rights reserved. * Created by: crystal.xiong REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test pthread_attr_setstacksize() * * Steps: * 1. Initialize pthread_attr_t object (attr) * 2. set the stacksize less tha PTHREAD_STACK_MIN */ #include #include #include #include #include #include #include #include #include "posixtest.h" #define TEST "4-1" #define FUNCTION "pthread_attr_setstacksize" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " #define STACKSIZE PTHREAD_STACK_MIN - sysconf(_SC_PAGE_SIZE) void *thread_func() { pthread_exit(0); return NULL; } int main() { pthread_attr_t attr; void *saddr; size_t stack_size; int rc; /* Initialize attr */ rc = pthread_attr_init(&attr); if( rc != 0) { perror(ERROR_PREFIX "pthread_attr_init"); exit(PTS_UNRESOLVED); } stack_size = STACKSIZE; if (posix_memalign (&saddr, sysconf(_SC_PAGE_SIZE), stack_size) != 0) { perror (ERROR_PREFIX "out of memory while " "allocating the stack memory"); exit(PTS_UNRESOLVED); } rc = pthread_attr_setstacksize(&attr, stack_size); if (rc != EINVAL ) { perror(ERROR_PREFIX "Got the wrong return value"); exit(PTS_FAIL); } rc = pthread_attr_destroy(&attr); if(rc != 0) { perror(ERROR_PREFIX "pthread_attr_destroy"); exit(PTS_UNRESOLVED); } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_attr_setstacksize/3-1.sh0100755000000000000000000000071010031752461025417 0ustar rootroot #!/bin/sh # Copyright (c) 2004, Intel Corporation. All rights reserved. # Created by: crystal.xiong REMOVE-THIS AT intel DOT com # This file is licensed under the GPL license. For the full content # of this license, see the COPYING file at the top level of this # source tree. # Test pthread_attr_setstack returns 0 on success. # This is tested implicitly via assertion 1. echo "Tested implicitly via assertion 1. See output for status" exit 0 posixtestsuite/conformance/interfaces/pthread_attr_setstacksize/1-1.c0100644000000000000000000000447410061223272025231 0ustar rootroot/* * Copyright (c) 2004, Intel Corporation. All rights reserved. * Created by: crystal.xiong REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test pthread_attr_setstacksizesize() * * Steps: * 1. Initialize pthread_attr_t object (attr) * 2. set stacksize to attr * 3. create a thread with the attr */ #include #include #include #include #include #include #include #include #include "posixtest.h" #define TEST "1-1" #define FUNCTION "pthread_attr_setstacksize" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " #define STACKADDROFFSET 0x8000000 void *thread_func() { pthread_exit(0); return NULL; } int main() { pthread_t new_th; pthread_attr_t attr; size_t stack_size = PTHREAD_STACK_MIN; size_t ssize; void *saddr; int rc; /* Initialize attr */ rc = pthread_attr_init(&attr); if( rc != 0) { perror(ERROR_PREFIX "pthread_attr_init"); exit(PTS_UNRESOLVED); } /* printf("stack_size = %lu\n", stack_size); */ if (posix_memalign (&saddr, sysconf(_SC_PAGE_SIZE), stack_size) != 0) { perror (ERROR_PREFIX "out of memory while " "allocating the stack memory"); exit(PTS_UNRESOLVED); } rc = pthread_attr_setstacksize(&attr, stack_size); if (rc != 0 ) { perror(ERROR_PREFIX "pthread_attr_setstacksize"); exit(PTS_UNRESOLVED); } rc = pthread_attr_getstacksize(&attr, &ssize); if (rc != 0 ) { perror(ERROR_PREFIX "pthread_attr_getstacksize"); exit(PTS_UNRESOLVED); } /* printf("stack_size = %lu\n", ssize); */ rc = pthread_create(&new_th, &attr, thread_func, NULL); if (rc !=0 ) { perror(ERROR_PREFIX "failed to create a thread"); exit(PTS_FAIL); } rc = pthread_join(new_th, NULL); if(rc != 0) { perror(ERROR_PREFIX "pthread_join"); exit(PTS_UNRESOLVED); } rc = pthread_attr_destroy(&attr); if(rc != 0) { perror(ERROR_PREFIX "pthread_attr_destroy"); exit(PTS_UNRESOLVED); } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_attr_setstacksize/assertions.xml0100644000000000000000000000174510031752461027505 0ustar rootroot The pthread_attr_setstack() shall set the thread creation stack stacksize in the attr ojbect. The stacksize attribute shall define the minimum stack size (in bytes) allocated for the created thread stack. If success, it returns zero and stores the stacksize attribute in the stacksize if successful. if fail, an error number shall be returned to indicate the error. The pthread_attr_setstacksize() function shall fail if: [EINVAL] The value of stacksize is less than {PTHREAD_STACK_MIN} or exceeds an implementation-defined limit. Shall not return an error code of [EINTR] posixtestsuite/conformance/interfaces/pthread_attr_setstacksize/coverage.txt0100644000000000000000000000040710031752461027117 0ustar rootrootThis document defines the coverage for the pthread_attr_setstacksize function: Assertion Tested? 1 YES 2 YES (The test uses a Non-POSIX-Compliant API pthread_getattr_np to get attr in a created thread) 3 YES 4 YES 5 won't test Note: posixtestsuite/conformance/interfaces/pthread_attr_setstacksize/2-1.c0100644000000000000000000000551410061226115025225 0ustar rootroot/* * Copyright (c) 2004, Intel Corporation. All rights reserved. * Created by: crystal.xiong REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test pthread_attr_setstacksize() * * Steps: * 1. Initialize pthread_attr_t object (attr) * 2. set stacksize to attr * 3. create a thread with the attr * 4. In the created thread, read stackaddr * * NOTE: pthread_getattr_np is not a POSIX compliant API. It is * provided by nptl, which is developed by Ulrich Drepper. */ #ifndef _GNU_SOURCE #define _GNU_SOURCE #endif #include #include #include #include #include #include #include #include #include "posixtest.h" #define TEST "2-1" #define FUNCTION "pthread_attr_setstacksize" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " size_t stack_size; void *thread_func() { pthread_attr_t attr; size_t ssize; int rc; /* pthread_getattr_np is not POSIX Compliant API*/ rc = pthread_getattr_np(pthread_self(), &attr); if (rc != 0) { perror(ERROR_PREFIX "pthread_getattr_np"); exit(PTS_UNRESOLVED); } pthread_attr_getstacksize(&attr, &ssize); if (ssize != stack_size) { perror(ERROR_PREFIX "got the wrong stacksize or stackaddr"); exit(PTS_FAIL); } pthread_exit(0); return NULL; } int main() { pthread_t new_th; pthread_attr_t attr; size_t ssize; void *saddr; int rc; /* Initialize attr */ rc = pthread_attr_init(&attr); if( rc != 0) { perror(ERROR_PREFIX "pthread_attr_init"); exit(PTS_UNRESOLVED); } stack_size = PTHREAD_STACK_MIN; if (posix_memalign (&saddr, sysconf(_SC_PAGE_SIZE), stack_size) != 0) { perror (ERROR_PREFIX "out of memory while " "allocating the stack memory"); exit(PTS_UNRESOLVED); } rc = pthread_attr_setstacksize(&attr, stack_size); if (rc != 0 ) { perror(ERROR_PREFIX "pthread_attr_setstacksize"); exit(PTS_UNRESOLVED); } rc = pthread_attr_getstacksize(&attr, &ssize); if (rc != 0 ) { perror(ERROR_PREFIX "pthread_attr_getstacksize"); exit(PTS_UNRESOLVED); } rc = pthread_create(&new_th, &attr, thread_func, NULL); if (rc !=0 ) { perror(ERROR_PREFIX "failed to create a thread"); exit(PTS_FAIL); } rc = pthread_join(new_th, NULL); if(rc != 0) { perror(ERROR_PREFIX "pthread_join"); exit(PTS_UNRESOLVED); } rc = pthread_attr_destroy(&attr); if(rc != 0) { perror(ERROR_PREFIX "pthread_attr_destroy"); exit(PTS_UNRESOLVED); } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_rwlock_timedrdlock/0040755000000000000000000000000010515625224024704 5ustar rootrootposixtestsuite/conformance/interfaces/pthread_rwlock_timedrdlock/6-2.c0100644000000000000000000001354110021017163025342 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test pthread_rwlock_timedrdlock(pthread_rwlock_t * rwlock) * * If a signal that causes a signal handler to be executed is delivered to * a thread blocked on a read-write lock via a call to pthread_rwlock_timedrdlock( ), * upon return from the signal handler the thread shall resume waiting for the lock * as if it was not interrupted. * * Steps: * 1. main thread create read-write lock 'rwlock', and lock it for writing * 2. main thread create a thread sig_thread, the thread is set to handle SIGUSR1 * 3. sig_thread timed lock 'rwlock' for reading, but blocked * 4. While the sig_thread is waiting(not expried yet), main thread send SIGUSR1 * to sig_thread via pthread_kill * 5. test that thread handler is called, inside the handler, make the thread sleep * for a period that the specified 'timeout' for pthread_rwlock_timedrdlock() * should have expired (timeout * 2) * 6. While sig_thread sleeping in signal handler, main thread unlock 'rwlock' * 7. check that when thread handler returns, sig_thread get the read lock without * getting ETIMEDOUT. */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include #include #include "posixtest.h" /* thread_state indicates child thread state: 1: not in child thread yet; 2: just enter child thread ; 3: just before child thread exit; */ #define NOT_CREATED_THREAD 1 #define ENTERED_THREAD 2 #define EXITING_THREAD 3 #define TIMEOUT 2 static pthread_t sig_thread; static pthread_rwlock_t rwlock; static int thread_state; static int handler_state; static int expired; static struct timeval before_wait, after_wait; static void sig_handler() { struct timespec sleep_time_req; sleep_time_req.tv_sec = TIMEOUT*2; sleep_time_req.tv_nsec = 0; if(pthread_equal(pthread_self(), sig_thread)) { printf("sig_handler: signal is handled by thread\n"); /* sig_handler will not sleep 2 times more than the timeout for the * pthread_rwlock_timerdlock is waiting for */ printf("sig_handler: sleeping for %d seconds\n", (int)sleep_time_req.tv_sec); handler_state = 2; sleep((int)sleep_time_req.tv_sec); } else { printf("sig_handler: signal is not handled by thread\n"); exit(PTS_UNRESOLVED); } handler_state = 3; } static void * th_fn(void *arg) { struct sigaction act; struct timespec abs_timeout; int rc; handler_state = 2; expired = 0; /* Set up handler for SIGUSR1 */ act.sa_flags = 0; act.sa_handler = sig_handler; /* block all the signal when hanlding SIGUSR1 */ sigfillset(&act.sa_mask); sigaction(SIGUSR1, &act, 0); gettimeofday(&before_wait, NULL); abs_timeout.tv_sec = before_wait.tv_sec + TIMEOUT; abs_timeout.tv_nsec = before_wait.tv_usec * 1000; thread_state = ENTERED_THREAD; printf("thread: attempt timed read lock, %d seconds\n", TIMEOUT); rc = pthread_rwlock_timedrdlock(&rwlock, &abs_timeout); if(rc == 0) { printf("thread: correctly acquired read lock\n"); expired = 0; } else if(rc == ETIMEDOUT) { printf("thread: timer expired, did not acquire read lock"); expired = 1; } else { printf("Error at pthread_rwlock_timedrdlock()"); exit(PTS_UNRESOLVED); } gettimeofday(&after_wait, NULL); thread_state = EXITING_THREAD; pthread_exit(0); return NULL; } int main() { int cnt; if(pthread_rwlock_init(&rwlock, NULL) != 0) { printf("Error at pthread_rwlock_init()\n"); return PTS_UNRESOLVED; } printf("main: attempt write lock\n"); if(pthread_rwlock_wrlock(&rwlock) != 0) { printf("pthread_rwlock_wrlock()\n"); return PTS_UNRESOLVED; } printf("main: acquired write lock\n"); thread_state = NOT_CREATED_THREAD; if(pthread_create(&sig_thread, NULL, th_fn, NULL) != 0) { printf("Error at pthread_create()\n"); return PTS_UNRESOLVED; } /* wait for the thread to get ready for handling signal */ cnt = 0; do{ sleep(1); }while(thread_state != ENTERED_THREAD && cnt++ < TIMEOUT); if(thread_state != ENTERED_THREAD) { printf("Error: thread did not block when getting read lock\n"); exit(PTS_UNRESOLVED); } printf("main: fire SIGUSR1 to thread\n"); if(pthread_kill(sig_thread, SIGUSR1) != 0) { printf("Error in pthread_kill()"); exit(PTS_UNRESOLVED); } /* Wait for signal handler to sleep so that main can unlock the rwlock while * it is sleeping. (this way, the rwlock will be unlocked when the signal handler * returns, and control is given back to the thread) */ cnt = 0; do{ sleep(TIMEOUT); }while(handler_state !=2 && cnt++ < 2); if(handler_state == 1) { printf("Error: signal handler did not get called\n"); exit(PTS_UNRESOLVED); } else if(handler_state == 3) { printf("Error: signal handler incorrectly exited\n"); exit(PTS_UNRESOLVED); } if(expired == 1) { printf("Error: thread timeout in sig_handler\n"); exit(PTS_UNRESOLVED); } printf("main: unlock write lock\n"); if(pthread_rwlock_unlock(&rwlock) != 0) { printf("Error at pthread_rwlock_unlock()\n"); exit(PTS_UNRESOLVED); } /* wait at most 4*TIMEOUT seconds for thread to exit */ cnt = 0; do{ sleep(1); }while(thread_state != EXITING_THREAD && cnt++ < 4*TIMEOUT); if(cnt >= 4*TIMEOUT) { /* thread blocked*/ printf("Test FAILED: thread blocked even afer the abs_timeout expires\n"); exit(PTS_FAIL); } if(expired == 1) { printf("Test FAILED: thread should get the read lock\n"); exit(PTS_FAIL); } if(pthread_join(sig_thread, NULL) != 0) { printf("Error at pthread_join()"); return PTS_UNRESOLVED; } if(pthread_rwlock_destroy(&rwlock) != 0) { printf("Error at pthread_destroy()"); exit(PTS_UNRESOLVED); } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_rwlock_timedrdlock/5-1.c0100644000000000000000000001332107672145337025363 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_rwlock_timedrdlock(pthread_rwlock_t *rwlock) * * Under no circumstances shall the function fail with a timeout if the lock can be * acquired immediately. The abs_timeout parameter need not be checked if the lock * can be immediately acquired. * * Steps:n * 1. Main thread create a thread. * 2. Child thread lock 'rwlock' for reading with pthread_rwlock_timedrdlock(), * should not fail with timeout * 3. The child thread unlocks the 'rwlock' and exits. * 4. Main thread create another thread. * 4. The child thread lock 'rwlock' for reading, with pthread_rwlock_timedrdlock(), * specifying a 'abs_timeout'. The thread sleeps until 'abs_timeout' expires. * 5. The thread call pthread_rwlock_timedrdlock(). Should _NOT_ get ETIMEDOUT. */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include "posixtest.h" #define NOT_CREATED_THREAD 1 #define ENTERED_THREAD 2 #define EXITING_THREAD 3 #define TIMEOUT 1 static int thread_state; static int currsec1; static int expired; static void* fn_rd_1(void *arg) { thread_state = ENTERED_THREAD; struct timespec abs_timeout; int rc; pthread_rwlock_t rwlock; if(pthread_rwlock_init(&rwlock, NULL) != 0) { printf("thread1: Error at pthread_rwlock_init\n"); exit(PTS_UNRESOLVED); } currsec1 = time(NULL); /* Absolute time, not relative. */ abs_timeout.tv_sec = currsec1 + TIMEOUT; abs_timeout.tv_nsec = 0; printf("thread1: attempt timed read-lock\n"); rc = pthread_rwlock_timedrdlock(&rwlock, &abs_timeout); if(rc == ETIMEDOUT) { printf("thread1: timed read-lock expired\n"); expired = 1; } else if(rc == 0) { printf("thread1: acquired read lock\n"); expired = 0; printf("thread1: unlock read lock\n"); if(pthread_rwlock_unlock(&rwlock) != 0) { printf("thread1: failed to release read lock\n"); exit(PTS_UNRESOLVED); } } else { printf("thread1: Error in pthread_rwlock_timedrdlock().\n"); exit(PTS_UNRESOLVED); } if(pthread_rwlock_destroy(&rwlock) != 0) { printf("thread1: Error at pthread_rwlockattr_destroy()"); exit(PTS_UNRESOLVED); } thread_state = EXITING_THREAD; pthread_exit(0); return NULL; } static void* fn_rd_2(void *arg) { thread_state = ENTERED_THREAD; struct timespec abs_timeout; int rc; pthread_rwlock_t rwlock; if(pthread_rwlock_init(&rwlock, NULL) != 0) { printf("thread2: Error at pthread_rwlock_init\n"); exit(PTS_UNRESOLVED); } currsec1 = time(NULL); /* Ensure that the abs_timeout has passed by _subtracting_ the timeout value of 1 * from the current time. */ abs_timeout.tv_sec = currsec1 - TIMEOUT; abs_timeout.tv_nsec = 0; printf("thread2: attempt timed read-lock\n"); rc = pthread_rwlock_timedrdlock(&rwlock, &abs_timeout); if(rc == ETIMEDOUT) { printf("thread2: timed read-lock expired\n"); expired = 1; } else if(rc == 0) { printf("thread2: acquired read lock\n"); expired = 0; printf("thread2: unlock read lock\n"); if(pthread_rwlock_unlock(&rwlock) != 0) { printf("thread2: failed to release read lock\n"); exit(PTS_UNRESOLVED); } } else { printf("thread2: Error in pthread_rwlock_timedrdlock().\n"); exit(PTS_UNRESOLVED); } if(pthread_rwlock_destroy(&rwlock) != 0) { printf("thread2: Error at pthread_rwlockattr_destroy()\n"); exit(PTS_UNRESOLVED); } thread_state = EXITING_THREAD; pthread_exit(0); return NULL; } int main() { int cnt = 0; pthread_t thread1, thread2; thread_state = NOT_CREATED_THREAD; printf("main: create thread1\n"); if(pthread_create(&thread1, NULL, fn_rd_1, NULL) != 0) { printf("Error when creating thread1\n"); return PTS_UNRESOLVED; } /* If the shared data is not altered by child after 5 seconds, we regard it as blocked */ /* we expect thread1 NOT to block, but rather for the timed read-lock to expire */ cnt = 0; do{ sleep(1); }while (thread_state !=EXITING_THREAD && cnt++ < 5); if(thread_state == EXITING_THREAD) { /* the child thread does not block, check the time expired or not */ if(expired == 1) { printf("Test FAILED: thread1 incorrectly received ETIMEDOUT\n"); return PTS_FAIL; } } else if(thread_state == ENTERED_THREAD) { printf("Test FAILED: thread1 incorrectly blocked for reading rwlock\n"); return PTS_FAIL; } else { printf("Unexpected state for thread1 %d\n", thread_state); return PTS_UNRESOLVED; } if(pthread_join(thread1, NULL) != 0) { printf("Error when joining thread1\n"); return PTS_UNRESOLVED; } printf("main: create thread2\n"); thread_state = NOT_CREATED_THREAD; if(pthread_create(&thread2, NULL, fn_rd_2, NULL) != 0) { printf("Error when creating thread2\n"); return PTS_UNRESOLVED; } /* If the shared data is not altered by child after 5 seconds, we regard it as blocked */ /* we expect thread2 NOT to block */ cnt = 0; do{ sleep(1); }while (thread_state !=EXITING_THREAD && cnt++ < 5); if(thread_state == EXITING_THREAD) { /* the child thread does not block, check the time expired or not */ if(expired == 1) { printf("Test FAILED: thread2 incorrectly received ETIMEDOUT\n"); return PTS_FAIL; } } else if(thread_state == ENTERED_THREAD) { printf("Test FAILED: thread2 incorrectly blocked for reading rwlock\n"); return PTS_FAIL; } else { printf("Unexpected state for thread2 %d\n", thread_state); return PTS_UNRESOLVED; } if(pthread_join(thread2, NULL) != 0) { printf("Error when join thread2\n"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_rwlock_timedrdlock/7-1.sh0100755000000000000000000000106007672157416025556 0ustar rootroot#!/bin/sh # Copyright (c) 2002, Intel Corporation. All rights reserved. # This file is licensed under the GPL license. For the full content # of this license, see the COPYING file at the top level of this # source tree. # Test pthread_rwlock_timedrdlock() # Shall return zero if the lock for writing on the read-write lock object # referenced by rwlock is acquired. Otherwise, an error number shall be returned # to indicate the error # This is tested implicitly via assertion 1. echo "Tested implicitly via assertion 1. See output for status" exit 0 posixtestsuite/conformance/interfaces/pthread_rwlock_timedrdlock/1-1.c0100644000000000000000000001337610021017163025342 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_rwlock_timedrdlock(pthread_rwlock_t *rwlock) * * The function shall apply a read lock to the read-write lock referenced by * rwlock as in the pthread_rwlock_rdlock(). However, if the lock cannot be * acquired with out waiting for other threads to unlock the lock, this wait * shall be terminated when the specified timeout expires. * * Steps: * 1. Initialize a pthread_rwlock_t object 'rwlock' with pthread_rwlock_init() * 2. Main thread lock 'rwlock' for reading with pthread_rwlock_rdlock() * 3. Create a child thread, the thread lock 'rwlock' for reading, * using pthread_rwlock_timedrdlock(), should get read lock. Thread unlocks 'rwlock'. * 4. Main thread unlock 'rwlock' * 5. Main thread lock 'rwlock' for writing * 6. Create child thread to lock 'rwlock' for reading, * using pthread_rwlock_timedrdlock, should block * but when the timer expires, the wait will be terminated * 7. Main thread unlock 'rwlock' */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include "posixtest.h" /* thread_state indicates child thread state: 1: not in child thread yet; 2: just enter child thread ; 3: just before child thread exit; */ #define NOT_CREATED_THREAD 1 #define ENTERED_THREAD 2 #define EXITING_THREAD 3 #define TIMEOUT 3 static pthread_rwlock_t rwlock; static int thread_state; static struct timeval currsec1, currsec2; static void* fn_rd(void *arg) { thread_state = ENTERED_THREAD; struct timespec timeout; int rc; gettimeofday(&currsec1, NULL); /* Absolute time, not relative. */ timeout.tv_sec = currsec1.tv_sec + TIMEOUT; timeout.tv_nsec = currsec1.tv_usec * 1000; printf("thread: attempt timed read lock, %d secs\n", TIMEOUT); rc = pthread_rwlock_timedrdlock(&rwlock, &timeout); if(rc == ETIMEDOUT) printf("thread: timer expired\n"); else if(rc == 0) { printf("thread: acquired read lock\n"); printf("thread: unlock read lock\n"); if(pthread_rwlock_unlock(&rwlock) != 0) { exit(PTS_UNRESOLVED); } } else { printf("Error: thread: in pthread_rwlock_timedrdlock(), return code:%d\n", rc); exit(PTS_UNRESOLVED); } /* Get time after the pthread_rwlock_timedrdlock() call. */ gettimeofday(&currsec2, NULL); thread_state = EXITING_THREAD; pthread_exit(0); return NULL; } int main() { int cnt = 0; pthread_t rd_thread1, rd_thread2; if(pthread_rwlock_init(&rwlock, NULL) != 0) { printf("main: Error at pthread_rwlock_init()\n"); return PTS_UNRESOLVED; } printf("main: attempt read lock\n"); if(pthread_rwlock_rdlock(&rwlock) != 0) { printf("main: Error at pthread_rwlock_rdlock()\n"); return PTS_UNRESOLVED; } printf("main: acquired read lock\n"); thread_state = NOT_CREATED_THREAD; printf("main: create rd_thread1\n"); if(pthread_create(&rd_thread1, NULL, fn_rd, NULL) != 0) { printf("main: Error when creating rd_thread1\n"); return PTS_UNRESOLVED; } /* If the shared data is not altered by child after 5 seconds, we regard it as blocked */ /* we expect the thread not to block */ cnt = 0; do{ sleep(1); }while (thread_state !=EXITING_THREAD && cnt++ < 5); if(thread_state == ENTERED_THREAD) { /* the child thread started but blocked */ printf("Test FAILED: rd_thread1 blocked on pthread_rwlock_timedrdlock()\n"); exit(PTS_FAIL); } else if(thread_state != EXITING_THREAD) { printf("Unexpected thread state %d\n", thread_state); exit(PTS_UNRESOLVED); } if(pthread_join(rd_thread1, NULL) != 0) { printf("main: Error when join rd_thread1\n"); exit(PTS_UNRESOLVED); } printf("main: unlock read lock\n"); if(pthread_rwlock_unlock(&rwlock) != 0) { printf("main: Error when release read lock\n"); return PTS_UNRESOLVED; } printf("main: attempt write lock\n"); if(pthread_rwlock_wrlock(&rwlock) != 0) { printf("main: Failed to get write lock\n"); return PTS_UNRESOLVED; } printf("main: acquired write lock\n"); thread_state = NOT_CREATED_THREAD; printf("main: create rd_thread2\n"); if(pthread_create(&rd_thread2, NULL, fn_rd, NULL) != 0) { printf("main: Failed to create rd_thread2\n"); return PTS_UNRESOLVED; } /* we expect rd_thread2 to block and timeout. */ cnt = 0; do{ sleep(1); }while (thread_state !=EXITING_THREAD && cnt++ < 5); if(thread_state == EXITING_THREAD) { /* the child thread does not block, check the time interval */ struct timeval time_diff; time_diff.tv_sec = currsec2.tv_sec - currsec1.tv_sec; time_diff.tv_usec = currsec2.tv_usec - currsec1.tv_usec; if (time_diff.tv_usec < 0) { --time_diff.tv_sec; time_diff.tv_usec += 1000000; } if(time_diff.tv_sec < TIMEOUT) { printf("Test FAILED: the timer expired and thread terminated, but the timeout is not correct: start time %ld.%06ld, end time %ld.%06ld\n", (long) currsec1.tv_sec, (long) currsec1.tv_usec, (long) currsec2.tv_sec, (long) currsec2.tv_usec); exit(PTS_FAIL); } else printf("thread: read lock correctly timed out\n"); } else if(thread_state == ENTERED_THREAD) { printf("Test FAILED: read block was not terminated even when the timer expired\n"); exit(PTS_FAIL); } else { printf("Unexpected thread state %d\n", thread_state); return PTS_UNRESOLVED; } printf("main: unlock write lock\n"); if(pthread_rwlock_unlock(&rwlock) != 0) { printf("main: Failed to release write lock\n"); exit(PTS_UNRESOLVED); } if(pthread_rwlock_destroy(&rwlock) != 0) { printf("Error at pthread_rwlockattr_destroy()\n"); exit(PTS_UNRESOLVED); } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_rwlock_timedrdlock/6-1.c0100644000000000000000000001273710021017163025347 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test pthread_rwlock_timedrdlock(pthread_rwlock_t * rwlock) * * If a signal that causes a signal handler to be executed is delivered to * a thread blocked on a read-write lock via a call to pthread_rwlock_timedrdlock( ), * upon return from the signal handler the thread shall resume waiting for the lock * as if it was not interrupted. * * Test that after returning from a signal handler, the reader will continue * to wait with timedrdlock as long as the specified 'timeout' does not expire (the * time spent in signal handler is longer than the specifed 'timeout'). * * Steps: * 1. main thread create and write lock 'rwlock' * 2. main thread create a thread sig_thread, the thread is set to handle SIGUSR1 * 3. sig_thread timed read-lock 'rwlock' for reading, it should block * 4. While the sig_thread is waiting (not expired yet), main thread sends SIGUSR1 * to sig_thread via pthread_kill * 5. Check that when thread handler returns, sig_thread resume block * 7. When the wait is terminated, check that the thread wait for a proper period before * expiring. * */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include #include #include "posixtest.h" static pthread_t sig_thread; static pthread_rwlock_t rwlock; static int thread_state; static int handler_called; static struct timeval before_wait, after_wait; /* thread_state indicates child thread state: 1: not in child thread yet; 2: just enter child thread ; 3: just before child thread exit; */ #define NOT_CREATED_THREAD 1 #define ENTERED_THREAD 2 #define EXITING_THREAD 3 #define TIMEOUT 5 /* Signal handler called by the thread when SIGUSR1 is received */ static void sig_handler() { if(pthread_equal(pthread_self(), sig_thread)) { printf("sig_handler: signal is handled by sig_thread\n"); handler_called = 1; } else { printf("sig_handler: signal is not handled by sig_thread\n"); exit(PTS_UNRESOLVED); } } static void * th_fn(void *arg) { struct sigaction act; struct timespec abs_timeout; int rc = 0; handler_called = 0; /* Set up signal handler for SIGUSR1 */ act.sa_flags = 0; act.sa_handler = sig_handler; /* block all the signal when hanlding SIGUSR1 */ sigfillset(&act.sa_mask); sigaction(SIGUSR1, &act, 0); gettimeofday(&before_wait, NULL); abs_timeout.tv_sec = before_wait.tv_sec; abs_timeout.tv_nsec = before_wait.tv_usec * 1000; abs_timeout.tv_sec += TIMEOUT; printf("thread: attempt timed read lock, %d seconds\n", TIMEOUT); thread_state = ENTERED_THREAD; rc = pthread_rwlock_timedrdlock(&rwlock, &abs_timeout); if(rc != ETIMEDOUT) { printf("sig_thread: pthread_rwlock_timedlock returns %d\n", rc); exit(PTS_FAIL); } printf("thread: timer correctly expired\n"); gettimeofday(&after_wait, NULL); thread_state = EXITING_THREAD; pthread_exit(0); return NULL; } int main() { int cnt; struct timeval wait_time; if(pthread_rwlock_init(&rwlock, NULL) != 0) { printf("Error at pthread_rwlock_init()\n"); return PTS_UNRESOLVED; } printf("main: attempt write lock\n"); if(pthread_rwlock_wrlock(&rwlock) != 0) { printf("main: Error at pthread_rwlock_wrlock()\n"); return PTS_UNRESOLVED; } printf("main: acquired write lock\n"); thread_state = NOT_CREATED_THREAD; if(pthread_create(&sig_thread, NULL, th_fn, NULL) != 0) { printf("Error at pthread_create()\n"); return PTS_UNRESOLVED; } /* Wait for the thread to get ready for handling signal (the thread should * be block on rwlock since main() has the write lock at this point) */ cnt = 0; do{ sleep(1); }while(thread_state != ENTERED_THREAD && cnt++ < TIMEOUT); if(thread_state != ENTERED_THREAD) { printf("Unexpected thread state %d\n", thread_state); exit(PTS_UNRESOLVED); } printf("main: fire SIGUSR1 to thread\n"); if(pthread_kill(sig_thread, SIGUSR1) != 0) { printf("main: Error at pthread_kill()\n"); exit(PTS_UNRESOLVED); } /* wait at most 2*TIMEOUT seconds */ cnt = 0; do{ sleep(1); }while(thread_state != EXITING_THREAD && cnt++ < 2*TIMEOUT); if(cnt >= 2*TIMEOUT) { /* thread blocked*/ printf("Test FAILED: thread blocked even afer the abs_timeout expired\n"); exit(PTS_FAIL); } if(handler_called != 1) { printf("The handler for SIGUSR1 did not get called\n"); exit(PTS_UNRESOLVED); } /* Test that the thread block for the correct TIMOUT time */ wait_time.tv_sec = after_wait.tv_sec - before_wait.tv_sec; wait_time.tv_usec = after_wait.tv_usec - before_wait.tv_usec; if (wait_time.tv_usec < 0) { --wait_time.tv_sec; wait_time.tv_usec += 1000000; } if(wait_time.tv_sec < TIMEOUT) { printf("Test FAILED: Timeout was for %d seconds, but waited for %ld.%06ld seconds instead\n", TIMEOUT, (long int)wait_time.tv_sec, (long int)wait_time.tv_usec); exit(PTS_FAIL); } printf("main: unlock write lock\n"); if(pthread_rwlock_unlock(&rwlock) != 0) { printf("main: Error at pthread_rwlock_unlock()\n"); return PTS_UNRESOLVED; } if(pthread_join(sig_thread, NULL) != 0) { printf("main: Error at pthread_join()\n"); return PTS_UNRESOLVED; } if(pthread_rwlock_destroy(&rwlock) != 0) { printf("Error at pthread_destroy()\n"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_rwlock_timedrdlock/assertions.xml0100644000000000000000000000437407672145337027641 0ustar rootroot The function shall apply a read lock to the read-write lock referenced by rwlock as in the pthread_rwlock_rdlock(). However, if the lock cannot be acquired wither out waiting for other threads to unlock the lock, this wait shall be terminated when the specified timeout expires. The timeout shall expire when the absolute time specified by abs_timeout passes, as measured by the clock on which timeouts are based (that is, when the value of that clock equals or exceeds abs_timeout), or if the absolute time specified by abs_timeout has already been passed at the time of the call. If the Timers option is supported, the timeout shall be based on the CLOCK_REALTIME clock. If the Timers option is not supported, the timeout shall be based on the system clock as returned by the time( ) function. The resolution of the timeout shall be the resolution of the clock on which it is based. The timespec data type is defined in the 'time.h' header. Under no circumstances shall the function fail with a timeout if the lock can be acquired immediately. The abs_timeout parameter need not be checked if the lock can be immediately acquired. If a signal that causes a signal handler to be executed is delivered to a thread blocked on a read-write lock via a call to pthread_rwlock_timedwrlock( ), upon return from the signal handler the thread shall resume waiting for the lock as if it was not interrupted. Shall return zero if the lock for writing on the read-write lock object referenced by rwlock is acquired. Otherwise, an error number shall be returned to indicate the error pthread_rwlock_timedwrlock( ) function shall fail if: [ETIMEDOUT] The lock could not be acquired before the specified timeout expired. The function shall not return an error code of [EINTR]. posixtestsuite/conformance/interfaces/pthread_rwlock_timedrdlock/coverage.txt0100644000000000000000000000023410035221503027221 0ustar rootrootThis document defines the coverage for the pthread_rwlock_timerdlock() function: Assertion Tested? 1 YES 2 YES 3 YES 4 YES 5 YES 6 YES 7 YES NOTE: posixtestsuite/conformance/interfaces/pthread_rwlock_timedrdlock/2-1.c0100644000000000000000000001022207672145337025355 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_rwlock_timedrdlock(pthread_rwlock_t *rwlock) * * The timeout shall expire when the absolute time specified by abs_timeout passes, * as measured by the clock on which timeouts are based (that is, when the * value of that clock equals or exceeds abs_timeout), or if the absolute time * specified by abs_timeout has already been passed at the time of the call. * * Steps: * 1. Initialize a pthread_rwlock_t object 'rwlock' with pthread_rwlock_init() * 2. Main thread lock 'rwlock' for writing with pthread_rwlock_rdlock() * 3. Create a child thread, specify a 'abs_timeout' as being the current time _minus_ * a timeout value of 1. (this ensures that the abs_timeout has already passed) * 4. The thread lock 'rwlock' for reading, using pthread_rwlock_timedrdlock(). Should * get an ETIMEOUT error. */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include "posixtest.h" /* thread_state indicates child thread state: 1: not in child thread yet; 2: just enter child thread ; 3: just before child thread exit; */ #define NOT_CREATED_THREAD 1 #define ENTERED_THREAD 2 #define EXITING_THREAD 3 #define TIMEOUT 1 static pthread_rwlock_t rwlock; static int thread_state; static int currsec1, currsec2; static int expired; static void* fn_rd(void *arg) { struct timespec abs_timeout; int rc; thread_state = ENTERED_THREAD; currsec1 = time(NULL); /* Absolute time, not relative. */ abs_timeout.tv_sec = currsec1 - TIMEOUT; abs_timeout.tv_nsec = 0; printf("thread: attempt timed read-lock\n"); rc = pthread_rwlock_timedrdlock(&rwlock, &abs_timeout); if(rc == ETIMEDOUT) { printf("thread: timed read-lock correctly expired\n"); expired = 1; } else if(rc == 0) { printf("thread: acquired read-lock\n"); expired = 0; printf("thread: unlock read lock\n"); if(pthread_rwlock_unlock(&rwlock) != 0) { printf("thread: failed to release lock\n"); exit(PTS_UNRESOLVED); } } else { printf("Error in pthread_rwlock_timedrdlock(), error code:%d.\n", rc); exit(PTS_UNRESOLVED); } /* Get time after the mutex timed out in locking. */ currsec2 = time(NULL); thread_state = EXITING_THREAD; pthread_exit(0); return NULL; } int main() { int cnt = 0; pthread_t thread1; expired = 0; if(pthread_rwlock_init(&rwlock, NULL) != 0) { printf("Error at pthread_rwlock_init()\n"); return PTS_UNRESOLVED; } printf("main: attempt write lock\n"); if(pthread_rwlock_wrlock(&rwlock) != 0) { printf("Error at pthread_rwlock_wrlock()\n"); return PTS_UNRESOLVED; } printf("main: acquired write lock\n"); printf("main: create thread\n"); thread_state = NOT_CREATED_THREAD; if(pthread_create(&thread1, NULL, fn_rd, NULL) != 0) { printf("Error creating thread1\n"); return PTS_UNRESOLVED; } /* If the shared data is not altered by child after 5 seconds, we regard it as blocked */ /* We expect the thread _NOT_ to block, and instead time out */ cnt = 0; do{ sleep(1); }while (thread_state !=EXITING_THREAD && cnt++ < 5); if(thread_state == EXITING_THREAD) { /* the child thread does not block, check the time expired or not */ if(expired != 1) { printf("Test FAILED: abs_timeout should expire\n"); exit(PTS_FAIL); } } else if(thread_state == ENTERED_THREAD) { printf("Test FAILED: thread blocked even when the timer expired\n"); exit(PTS_FAIL); } else { printf("Unexpected thread state %d\n", thread_state); exit(PTS_UNRESOLVED); } printf("main: unlock write lock\n"); if(pthread_rwlock_unlock(&rwlock) != 0) { printf("main: Error at pthread_rwlock_unlock()\n"); return PTS_UNRESOLVED; } if(pthread_join(thread1, NULL) != 0) { printf("main: Error at pthread_join()\n"); return PTS_UNRESOLVED; } if(pthread_rwlock_destroy(&rwlock) != 0) { printf("main: Error at pthread_rwlock_destroy()\n"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_rwlock_timedrdlock/4-1.sh0100755000000000000000000000122507672145337025555 0ustar rootroot#!/bin/sh # Copyright (c) 2002, Intel Corporation. All rights reserved. # This file is licensed under the GPL license. For the full content # of this license, see the COPYING file at the top level of this # source tree. # Test pthread_rwlock_timedwrlock() # If the Timers option is not supported, the timeout shall be based on the # system clock as returned by the time( ) function. The resolution of the timeout # shall be the resolution of the clock on which it is based. The timespec data type # is defined in the header. # This is tested implicitly via assertion 1. echo "Tested implicitly via assertion 1. See output for status" exit 0 posixtestsuite/conformance/interfaces/pthread_rwlock_timedrdlock/3-1.c0100644000000000000000000001416410035221503025340 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_rwlock_timedrdlock(pthread_rwlock_t *rwlock) * * The function shall apply a read lock to the read-write lock referenced by * rwlock as in the pthread_rwlock_rdlock(). However, if the lock cannot be * acquired with out waiting for other threads to unlock the lock, this wait * shall be terminated when the specified timeout expires. * * Steps: * 1. Initialize a pthread_rwlock_t object 'rwlock' with pthread_rwlock_init() * 2. Main thread lock 'rwlock' for reading with pthread_rwlock_rdlock() * 3. Create a child thread, the thread lock 'rwlock' for reading, * using pthread_rwlock_timedrdlock(), should get read lock. Thread unlocks 'rwlock'. * 4. Main thread unlock 'rwlock' * 5. Main thread lock 'rwlock' for writing * 6. Create child thread to lock 'rwlock' for reading, * using pthread_rwlock_timedrdlock, should block * but when the timer expires, the wait will be terminated * 7. Main thread unlock 'rwlock' */ /* Test for CLOCK_REALTIME */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include "posixtest.h" /* thread_state indicates child thread state: 1: not in child thread yet; 2: just enter child thread ; 3: just before child thread exit; */ #define NOT_CREATED_THREAD 1 #define ENTERED_THREAD 2 #define EXITING_THREAD 3 #define TIMEOUT 3 static pthread_rwlock_t rwlock; static int thread_state; static struct timeval currsec1, currsec2; static void* fn_rd(void *arg) { thread_state = ENTERED_THREAD; struct timespec timeout, ts; int rc; #ifdef CLOCK_REALTIME printf("Test CLOCK_REALTIME\n"); clock_gettime(CLOCK_REALTIME, &ts); currsec1.tv_sec = ts.tv_sec; currsec1.tv_usec = ts.tv_nsec / 1000; #else gettimeofday(&currsec1, NULL); #endif /* Absolute time, not relative. */ timeout.tv_sec = currsec1.tv_sec + TIMEOUT; timeout.tv_nsec = currsec1.tv_usec * 1000; printf("thread: attempt timed read lock, %d secs\n", TIMEOUT); rc = pthread_rwlock_timedrdlock(&rwlock, &timeout); if(rc == ETIMEDOUT) printf("thread: timer expired\n"); else if(rc == 0) { printf("thread: acquired read lock\n"); printf("thread: unlock read lock\n"); if(pthread_rwlock_unlock(&rwlock) != 0) { exit(PTS_UNRESOLVED); } } else { printf("Error: thread: in pthread_rwlock_timedrdlock(), return code:%d\n", rc); exit(PTS_UNRESOLVED); } /* Get time after the pthread_rwlock_timedrdlock() call. */ #ifdef CLOCK_REALTIME clock_gettime(CLOCK_REALTIME, &ts); currsec2.tv_sec = ts.tv_sec; currsec2.tv_usec = ts.tv_nsec / 1000; #else gettimeofday(&currsec2, NULL); #endif thread_state = EXITING_THREAD; pthread_exit(0); return NULL; } int main() { int cnt = 0; pthread_t rd_thread1, rd_thread2; if(pthread_rwlock_init(&rwlock, NULL) != 0) { printf("main: Error at pthread_rwlock_init()\n"); return PTS_UNRESOLVED; } printf("main: attempt read lock\n"); if(pthread_rwlock_rdlock(&rwlock) != 0) { printf("main: Error at pthread_rwlock_rdlock()\n"); return PTS_UNRESOLVED; } printf("main: acquired read lock\n"); thread_state = NOT_CREATED_THREAD; printf("main: create rd_thread1\n"); if(pthread_create(&rd_thread1, NULL, fn_rd, NULL) != 0) { printf("main: Error when creating rd_thread1\n"); return PTS_UNRESOLVED; } /* If the shared data is not altered by child after 5 seconds, we regard it as blocked */ /* we expect the thread not to block */ cnt = 0; do{ sleep(1); }while (thread_state !=EXITING_THREAD && cnt++ < 5); if(thread_state == ENTERED_THREAD) { /* the child thread started but blocked */ printf("Test FAILED: rd_thread1 blocked on pthread_rwlock_timedrdlock()\n"); exit(PTS_FAIL); } else if(thread_state != EXITING_THREAD) { printf("Unexpected thread state %d\n", thread_state); exit(PTS_UNRESOLVED); } if(pthread_join(rd_thread1, NULL) != 0) { printf("main: Error when join rd_thread1\n"); exit(PTS_UNRESOLVED); } printf("main: unlock read lock\n"); if(pthread_rwlock_unlock(&rwlock) != 0) { printf("main: Error when release read lock\n"); return PTS_UNRESOLVED; } printf("main: attempt write lock\n"); if(pthread_rwlock_wrlock(&rwlock) != 0) { printf("main: Failed to get write lock\n"); return PTS_UNRESOLVED; } printf("main: acquired write lock\n"); thread_state = NOT_CREATED_THREAD; printf("main: create rd_thread2\n"); if(pthread_create(&rd_thread2, NULL, fn_rd, NULL) != 0) { printf("main: Failed to create rd_thread2\n"); return PTS_UNRESOLVED; } /* we expect rd_thread2 to block and timeout. */ cnt = 0; do{ sleep(1); }while (thread_state !=EXITING_THREAD && cnt++ < 5); if(thread_state == EXITING_THREAD) { /* the child thread does not block, check the time interval */ struct timeval time_diff; time_diff.tv_sec = currsec2.tv_sec - currsec1.tv_sec; time_diff.tv_usec = currsec2.tv_usec - currsec1.tv_usec; if (time_diff.tv_usec < 0) { --time_diff.tv_sec; time_diff.tv_usec += 1000000; } if(time_diff.tv_sec < TIMEOUT) { printf("Test FAILED: the timer expired and thread terminated, " "but the timeout is not correct: " "start time %ld.%06ld, end time %ld.%06ld\n", (long) currsec1.tv_sec, (long) currsec1.tv_usec, (long) currsec2.tv_sec, (long) currsec2.tv_usec); exit(PTS_FAIL); } else printf("thread: read lock correctly timed out\n"); } else if(thread_state == ENTERED_THREAD) { printf("Test FAILED: read block was not terminated even when the timer expired\n"); exit(PTS_FAIL); } else { printf("Unexpected thread state %d\n", thread_state); return PTS_UNRESOLVED; } printf("main: unlock write lock\n"); if(pthread_rwlock_unlock(&rwlock) != 0) { printf("main: Failed to release write lock\n"); exit(PTS_UNRESOLVED); } if(pthread_rwlock_destroy(&rwlock) != 0) { printf("Error at pthread_rwlockattr_destroy()\n"); exit(PTS_UNRESOLVED); } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/sem_destroy/0040755000000000000000000000000010515625234021651 5ustar rootrootposixtestsuite/conformance/interfaces/sem_destroy/cln.sh0100755000000000000000000000025607631171234022765 0ustar rootroot rm -f /tmp/mysem >/dev/null 2>&1 rm -f /tmp/sem_* >/dev/null 2>&1 rm -f a.out for sem_id in `ipcs -s | awk '{print $2}'` ; do ipcrm sem $sem_id > /dev/null 2>&1 done posixtestsuite/conformance/interfaces/sem_destroy/4-1.c0100644000000000000000000000205107631451530022312 0ustar rootroot/* Copyright (c) 2003, Intel Corporation. All rights reserved. Created by: majid.awad REMOVE-THIS AT intel DOT com This file is licensed under the GPL license. For the full content of this license, see the COPYING file at the top level of this source tree. */ /* * This test case verify the unamed semaphore is destroyed by calling * sem_destroy to return 0 on successful call. */ #include #include #include #include #include #include #include #include "posixtest.h" #define TEST "4-1" #define FUNCTION "sem_destroy" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " int main () { sem_t mysemp; if ( sem_init(&mysemp, 0, 0) == -1 ) { perror(ERROR_PREFIX "sem_init"); return PTS_UNRESOLVED; } if (sem_destroy(&mysemp) == 0 ) { puts("TEST PASSED"); return PTS_PASS; } else { puts("TEST FAILED: couldn't destroy sempahore."); return PTS_FAIL; } } posixtestsuite/conformance/interfaces/sem_destroy/assertions.xml0100644000000000000000000000174110211606407024557 0ustar rootroot sem_destroy shall destroy the unamed semaphore indicated by sem. sem_destroy shall destroy an initialized semaphore upon which no threads are currently blocked. sem_destroy return 0 on successful completion, otherwise, -1 returned with errno set. EINVAL: the sem argument is not valid semaphore. EBUSY: there are currently processes blocked on the semaphore. The effect of calling sem_destroy on named semaphore is undefined. The effect of destroying a semaphore upon which other threads are currently blocked is undefined. posixtestsuite/conformance/interfaces/sem_destroy/coverage.txt0100644000000000000000000000033107663253571024212 0ustar rootroot-- assertion 5: not tested. -- assertion 6: ERROR EBUSY: is not tested. Please contribute your help for this test case. -- assertion 7: Won't be tested. (Undefined). -- assertion 8: Won't be tested. (Undefined). posixtestsuite/conformance/interfaces/sem_destroy/3-1.c0100644000000000000000000000372710215336315022317 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: majid.awad REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * Test case vrifies sem_destroy shall destroy on intialized semaphore * upon which no threads are currently blocked. */ #include #include #include #include #include #include #include #include #include "posixtest.h" #define TEST "3-1" #define FUNCTION "sem_destroy" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " sem_t psem, csem; int n; int main() { pthread_t prod, cons; void *producer(void *); void *consumer(void *); long cnt = 3; n = 0; if (sem_init(&csem, 0, 0) < 0) { perror("sem_init"); return PTS_UNRESOLVED; } if (sem_init(&psem, 0, 1) < 0) { perror("sem_init"); return PTS_UNRESOLVED; } if (pthread_create(&prod, NULL, producer, (void *)cnt) != 0) { perror("pthread_create"); return PTS_UNRESOLVED; } if (pthread_create(&cons, NULL, consumer, (void *)cnt) != 0) { perror("pthread_create"); return PTS_UNRESOLVED; } if (( pthread_join(prod, NULL) == 0) && ( pthread_join(cons, NULL) == 0)) { puts("TEST PASS"); pthread_exit(NULL); if (( sem_destroy(&psem) == 0) &&( sem_destroy (&csem)) == 0 ) return PTS_PASS; } else { puts("TEST FAILED"); return PTS_FAIL; } } void * producer(void *arg) { int i, cnt; cnt = (long)arg; for (i=0; i #include #include #include #include "posixtest.h" #define NUM_OF_KEYS 10 #define KEY_VALUE 0 int main() { pthread_key_t keys[NUM_OF_KEYS]; int i; void* rc; for(i = 0;i #include #include #include #include "posixtest.h" #define KEY_VALUE_1 100 #define KEY_VALUE_2 200 pthread_key_t key; void* rc1; void* rc2; void *a_thread_func() { /* Bind a value to key for this thread (this will be different from the value * that we bind for the main thread) */ if(pthread_setspecific(key, (void *)(KEY_VALUE_2)) != 0) { printf("Test FAILED: Could not set the value of the key to %d\n", (KEY_VALUE_2)); pthread_exit((void*)PTS_FAIL); return NULL; } /* Get the bound value of the key that we just set. */ rc2 = pthread_getspecific(key); pthread_exit(0); return NULL; } int main() { pthread_t new_th; /* Create the key */ if(pthread_key_create(&key, NULL) != 0) { printf("Error: pthread_key_create() failed\n"); return PTS_UNRESOLVED; } /* Bind a value for this main thread */ if(pthread_setspecific(key, (void *)(KEY_VALUE_1)) != 0) { printf("Test FAILED: Could not set the value of the key to %d\n", (KEY_VALUE_1)); return PTS_FAIL; } /* Create another thread. This thread will also bind a value to the key */ if(pthread_create(&new_th, NULL, a_thread_func, NULL) != 0) { printf("Error: in pthread_create()\n"); return PTS_UNRESOLVED; } /* Wait for thread to end execution */ pthread_join(new_th, NULL); /* Get the value associated for the key in this main thread */ rc1 = pthread_getspecific(key); /* Compare this value with the value associated for the key in the newly created * thread, they should be different. */ if(rc1 != (void *)(KEY_VALUE_1)) { printf("Test FAILED: Incorrect value bound to key, expected %d, got %ld\n", KEY_VALUE_1, (long)rc1); return PTS_FAIL; } if(rc2 != (void *)(KEY_VALUE_2)) { printf("Test FAILED: Incorrect value bound to key, expected %d, got %ld\n", KEY_VALUE_2, (long)rc2); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_setspecific/assertions.xml0100644000000000000000000000203210117555066026235 0ustar rootroot The function void *pthread_setspecific(pthread_key_t key) shall acssociate a thread-specific value with a key obtained via a previouse call to pthread_key_create. Different threads may bind different values to the same key. Calling pthread_setspecific with a key value not obtiained from pthread_key_create of after the key has been deleted with pthread_key_delete is undefined. pthread_setspecific may be called from a thread-specific data destructor function. A call to pthread_getspecific() from a thread-specific data destructor routine may result either in lost storage or in an infinite loop. It returns 0 upon success, and an error number otherwise: Shall fail if: [ENOMEM] - Insufficient memory exists to associate the value with the key May fail if: [EINVAL] - The key value is invalid posixtestsuite/conformance/interfaces/pthread_setspecific/coverage.txt0100644000000000000000000000023607676163523025672 0ustar rootrootThis document defines the coverage for the pthread_getspecific function: Assertion Tested? 1 YES 2 NO *Will not test 3 YES *Will not test [ENOMEM] NOTE: posixtestsuite/conformance/interfaces/pthread_rwlock_trywrlock/0040755000000000000000000000000010515625225024444 5ustar rootrootposixtestsuite/conformance/interfaces/pthread_rwlock_trywrlock/speculative/0040755000000000000000000000000010515625225026770 5ustar rootrootposixtestsuite/conformance/interfaces/pthread_rwlock_trywrlock/speculative/3-1.c0100644000000000000000000000260710055336732027437 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test pthread_rwlock_trywrlock(pthread_rwlock_t *rwlock) * * It may fail if: * [EINVAL] rwlock does not refer to an intialized read-write lock object * * Steps: * 1. Call pthread_rwlock_trywrlock with an uninitialized rwlock object * 2. Test for the return code. It may be EINVAL or 0. */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include "posixtest.h" int main() { static pthread_rwlock_t rwlock; int rc; /* Call without initializing rwlock */ rc = pthread_rwlock_trywrlock(&rwlock); /* Clean up before checking return value */ if(pthread_rwlock_unlock(&rwlock) != 0) { printf("main: Error at pthread_rwlock_unlock()\n"); exit(PTS_UNRESOLVED); } if(pthread_rwlock_destroy(&rwlock) != 0) { printf("Error at pthread_rwlock_destroy()\n"); return PTS_UNRESOLVED; } if(rc != 0) { if(rc == EINVAL) { printf("Test PASSED\n"); return PTS_PASS; } else { printf("Test FAILED: Incorrect return code %d\n", rc); return PTS_FAIL; } } printf("Test PASSED: Note*: Returned 0 instead of EINVAL, but standard specified _may_ fail. \n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_rwlock_trywrlock/1-1.c0100644000000000000000000001163007671441054025111 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test pthread_rwlock_trywrlock(pthread_rwlock_t *rwlock) * * The function shall apply a write lock like the pthread_rwlock_wrlock(), with the exception * that the funciton shall fail if any thread currently holds rwlock(for reading and writing). * * Steps: * 1. Initialize a pthread_rwlock_t object 'rwlock' with pthread_rwlock_init() * 2. Main thread lock 'rwlock' for reading with pthread_rwlock_rdlock() * 3. Create a child thread, the thread locks 'rwlock' for writing, using * pthread_rwlock_trywrlock(), should get EBUSY * 4. Main thread unlocks 'rwlock' * 5. Main thread locks 'rwlock' for writing, using pthread_rwlock_trywrlock(), * should get the lock successfully * 6. Create child thread to lock 'rwlock' for writing, with pthread_rwlock_trywrlock(), * should get EBUSY * 7. Main thread unlock 'rwlock' */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include "posixtest.h" static pthread_rwlock_t rwlock; static int thread_state; static int get_ebusy; /* thread_state indicates child thread state: 1: not in child thread yet; 2: just enter child thread ; 3: just before child thread exit; */ #define NOT_CREATED_THREAD 1 #define ENTERED_THREAD 2 #define EXITING_THREAD 3 static void* fn_wr(void *arg) { thread_state = ENTERED_THREAD; int rc; printf("thread: attempt pthread_rwlock_trywrlock()\n"); rc = pthread_rwlock_trywrlock(&rwlock); if(rc != EBUSY) { printf("Test FAILED: thread: Expected EBUSY, got %d\n", rc); exit(PTS_FAIL); } get_ebusy = 1; printf("thread: correctly got EBUSY\n"); thread_state = EXITING_THREAD; pthread_exit(0); return NULL; } int main() { int cnt = 0; int rc = 0; pthread_t thread1, thread2; get_ebusy = 0; if(pthread_rwlock_init(&rwlock, NULL) != 0) { printf("main: Error at pthread_rwlock_init()\n"); return PTS_UNRESOLVED; } printf("main: attempt read lock\n"); /* We have no lock, this read lock should succeed */ if(pthread_rwlock_rdlock(&rwlock) != 0) { printf("main: Error at pthread_rwlock_rdlock()\n"); return PTS_UNRESOLVED; } printf("main: acquired read lock\n"); thread_state = NOT_CREATED_THREAD; printf("main: create thread1\n"); if(pthread_create(&thread1, NULL, fn_wr, NULL) != 0) { printf("Error creating thread1\n"); return PTS_UNRESOLVED; } /* If the shared data is not altered by child after 3 seconds, we regard it as blocked */ /* We do no expect thread1 to block */ cnt = 0; do{ sleep(1); }while (thread_state !=EXITING_THREAD && cnt++ < 3); if(thread_state == ENTERED_THREAD) { /* the child thread blocked */ printf("Test FAILED: thread1 should not block on pthread_rwlock_trywrlock()\n"); exit(PTS_FAIL); } else if(thread_state != EXITING_THREAD) { printf("Unexpected thread state for thread1: %d\n", thread_state); exit(PTS_UNRESOLVED); } if(get_ebusy != 1) { printf("Test FAILED: thread1 should get EBUSY\n"); exit(PTS_FAIL); } printf("main: unlock read lock\n"); if(pthread_rwlock_unlock(&rwlock) != 0) { printf("main: Error releasing read lock\n"); exit(PTS_UNRESOLVED); } if(pthread_join(thread1, NULL) != 0) { printf("main: Error joining thread1\n"); exit(PTS_UNRESOLVED); } printf("main: attempt pthread_rwlock_trywrlock()\n"); /* Should get the write lock*/ rc = pthread_rwlock_trywrlock(&rwlock); if(rc != 0) { printf("Test FAILED: main failed at pthread_rwlock_trywrlock(), error code: %d\n", rc); return PTS_FAIL; } printf("main: acquired write lock\n"); get_ebusy = 0; thread_state = NOT_CREATED_THREAD; cnt = 0; printf("main: create thread2\n"); if(pthread_create(&thread2, NULL, fn_wr, NULL) != 0) { printf("main: Error creating thread2\n"); return PTS_UNRESOLVED; } /* We do not expect thread2 to block */ do{ sleep(1); }while (thread_state !=EXITING_THREAD && cnt++ < 3); if(thread_state == ENTERED_THREAD) { printf("Test FAILED: thread2 should not block on pthread_rwlock_trywrlock()\n"); exit(PTS_FAIL); } else if(thread_state != EXITING_THREAD) { printf("Unexpected thread state: %d\n", thread_state); exit(PTS_UNRESOLVED); } if(get_ebusy != 1) { printf("Test FAILED: thread2 should get EBUSY\n"); exit(PTS_FAIL); } printf("main: unlock write lock\n"); thread_state = 1; if(pthread_rwlock_unlock(&rwlock) != 0) { printf("main: Error at 2nd pthread_rwlock_unlock()\n"); exit(PTS_UNRESOLVED); } if(pthread_join(thread2, NULL) != 0) { printf("main: Error at 2cn pthread_join()\n"); exit(PTS_UNRESOLVED); } if(pthread_rwlock_destroy(&rwlock) != 0) { printf("Error at pthread_rwlockattr_destroy()\n"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_rwlock_trywrlock/assertions.xml0100644000000000000000000000176407671441054027372 0ustar rootroot pthread_rwlock_trywrlock( ) function shall apply a write lock like the pthread_rwlock_wrlock( ) function, with the exception that the function shall fail if any thread currently holds rwlock (for reading or writing) The pthread_rwlock_trywrlock( ) function shall return zero if the lock for writing on the read-write lock object referenced by rwlock is acquired. Otherwise, an error number shall be returned to indicate the error. The pthread_rwlock_trywrlock( ) function shall fail if: [EBUSY] The read-write lock could not be acquired for writing because a writer holds the lock or a writer with the appropriate priority was blocked on it. It may fail if: [EINVAL] rwlock does not refer to an intialized read-write lock object It shall not return EINTR. posixtestsuite/conformance/interfaces/pthread_rwlock_trywrlock/coverage.txt0100644000000000000000000000017707671441054027007 0ustar rootrootThis document defines the coverage for the pthread_rwlock_tryrdlock() function: Assertion Tested? 1 YES 2 YES 3 YES NOTE: posixtestsuite/conformance/interfaces/pthread_rwlock_trywrlock/2-1.sh0100755000000000000000000000062007671441054025302 0ustar rootroot#!/bin/sh # Copyright (c) 2002, Intel Corporation. All rights reserved. # This file is licensed under the GPL license. For the full content # of this license, see the COPYING file at the top level of this # source tree. # Test pthread_rwlock_trywrlock() returns 0 on success. # This is tested implicitly via assertion 1. echo "Tested implicitly via assertion 1. See output for status" exit 0 posixtestsuite/conformance/interfaces/aio_fsync/0040755000000000000000000000000010515625157021272 5ustar rootrootposixtestsuite/conformance/interfaces/aio_fsync/5-1.c0100644000000000000000000000351210247562115021732 0ustar rootroot/* * Copyright (c) 2004, Bull SA. All rights reserved. * Created by: Laurent.Vivier@bull.net * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include #include #include #include "posixtest.h" #define TNAME "aio_fsync/5-1.c" #define BUF_SIZE 1024 int main() { char tmpfname[256]; char buf[BUF_SIZE]; int fd; struct aiocb aiocb_write; struct aiocb aiocb_fsync; int ret; #if _POSIX_ASYNCHRONOUS_IO != 200112L exit(PTS_UNSUPPORTED); #endif snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_aio_fsync_5_1_%d", getpid()); unlink(tmpfname); fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL, S_IRUSR | S_IWUSR); if (fd == -1) { printf(TNAME " Error at open(): %s\n", strerror(errno)); exit(PTS_UNRESOLVED); } unlink(tmpfname); memset(&aiocb_write, 0, sizeof(aiocb_write)); aiocb_write.aio_fildes = fd; aiocb_write.aio_buf = buf; aiocb_write.aio_nbytes = BUF_SIZE; if (aio_write(&aiocb_write) == -1) { printf(TNAME " Error at aio_write(): %s\n", strerror(errno)); exit(PTS_FAIL); } memset(&aiocb_fsync, 0, sizeof(aiocb_fsync)); aiocb_fsync.aio_fildes = fd; if (aio_fsync(O_SYNC, &aiocb_fsync) != 0) { printf(TNAME " Error at aio_fsync(): %s\n", strerror(errno)); exit(PTS_FAIL); } ret = PTS_UNTESTED; if (aio_error(&aiocb_fsync) == EINPROGRESS) ret = PTS_PASS; /* allow to check if aio_error() move from EINPROGRESS to * something else * otherwise test hangs */ while (aio_error(&aiocb_fsync) == EINPROGRESS); close(fd); /* we didn't check if the operation is really performed */ return ret; } posixtestsuite/conformance/interfaces/aio_fsync/4-1.c0100644000000000000000000000322310247562115021730 0ustar rootroot/* * Copyright (c) 2004, Bull SA. All rights reserved. * Created by: Laurent.Vivier@bull.net * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include #include #include #include "posixtest.h" #define TNAME "aio_fsync/4-1.c" int main() { char tmpfname[256]; #define BUF_SIZE 111 char buf[BUF_SIZE]; int fd; struct aiocb aiocb_write; struct aiocb aiocb_fsync; #if _POSIX_ASYNCHRONOUS_IO != 200112L exit(PTS_UNSUPPORTED); #endif snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_aio_fsync_4_1_%d", getpid()); unlink(tmpfname); fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL, S_IRUSR | S_IWUSR); if (fd == -1) { printf(TNAME " Error at open(): %s\n", strerror(errno)); exit(PTS_UNRESOLVED); } unlink(tmpfname); memset(&aiocb_write, 0, sizeof(aiocb_write)); aiocb_write.aio_fildes = fd; aiocb_write.aio_buf = buf; aiocb_write.aio_nbytes = BUF_SIZE; if (aio_write(&aiocb_write) == -1) { printf(TNAME " Error at aio_write(): %s\n", strerror(errno)); exit(PTS_FAIL); } memset(&aiocb_fsync, 0, sizeof(aiocb_fsync)); aiocb_fsync.aio_fildes = fd; if (aio_fsync(O_SYNC, &aiocb_fsync) != 0) { printf(TNAME " Error at aio_fsync()\n"); exit(PTS_FAIL); } if (aio_error(&aiocb_fsync) < 0) { printf(TNAME " Error at aio_error() : %s\n", strerror(errno)); exit(PTS_FAIL); } close(fd); printf ("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/aio_fsync/14-1.c0100644000000000000000000000320210247562115022006 0ustar rootroot/* * Copyright (c) 2004, Bull SA. All rights reserved. * Created by: Laurent.Vivier@bull.net * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include #include #include #include "posixtest.h" #define TNAME "aio_fsync/14-1.c" int main() { char tmpfname[256]; #define BUF_SIZE 111 char buf[BUF_SIZE]; int fd; struct aiocb aiocb_write; struct aiocb aiocb_fsync; #if _POSIX_ASYNCHRONOUS_IO != 200112L exit(PTS_UNSUPPORTED); #endif snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_aio_fsync_14_1_%d", getpid()); unlink(tmpfname); fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL, S_IRUSR | S_IWUSR); if (fd == -1) { printf(TNAME " Error at open(): %s\n", strerror(errno)); exit(PTS_UNRESOLVED); } unlink(tmpfname); memset(&aiocb_write, 0, sizeof(aiocb_write)); aiocb_write.aio_fildes = fd; aiocb_write.aio_buf = buf; aiocb_write.aio_nbytes = BUF_SIZE; if (aio_write(&aiocb_write) == -1) { printf(TNAME " Error at aio_write(): %s\n", strerror(errno)); exit(PTS_FAIL); } memset(&aiocb_fsync, 0, sizeof(aiocb_fsync)); aiocb_fsync.aio_fildes = fd; if (aio_fsync(-1, &aiocb_fsync) != -1) { printf(TNAME " aio_fsync() accepts bad op\n"); exit(PTS_FAIL); } if (errno != EINVAL) { printf(TNAME " errno is not EINVAL (%d)\n", errno); exit(PTS_FAIL); } close(fd); printf ("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/aio_fsync/12-1.c0100644000000000000000000000167110247562115022014 0ustar rootroot/* * Copyright (c) 2004, Bull SA. All rights reserved. * Created by: Laurent.Vivier@bull.net * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include #include #include #include "posixtest.h" #define TNAME "aio_fsync/12-1.c" int main() { struct aiocb aiocb; #if _POSIX_ASYNCHRONOUS_IO != 200112L exit(PTS_UNSUPPORTED); #endif memset(&aiocb, 0, sizeof(struct aiocb)); aiocb.aio_fildes = -1; if (aio_fsync(O_SYNC, &aiocb) != -1) { printf(TNAME " aio_fsync() accepts bad filedes\n"); exit(PTS_FAIL); } if (errno != EBADF) { printf(TNAME " errno is not EBADF (%d)\n", errno); exit(PTS_FAIL); } printf ("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/aio_fsync/1-1.c0100644000000000000000000000072410247562115021730 0ustar rootroot/* * Copyright (c) 2004, Bull SA. All rights reserved. * Created by: Laurent.Vivier@bull.net * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ #define _XOPEN_SOURCE 600 #include #include #include #include "posixtest.h" int main() { #if _POSIX_ASYNCHRONOUS_IO != 200112L exit(PTS_UNSUPPORTED); #endif return PTS_UNTESTED; } posixtestsuite/conformance/interfaces/aio_fsync/9-1.c0100644000000000000000000000305410247562115021737 0ustar rootroot/* * Copyright (c) 2004, Bull SA. All rights reserved. * Created by: Laurent.Vivier@bull.net * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include #include #include #include "posixtest.h" #define TNAME "aio_fsync/9-1.c" int main() { char tmpfname[256]; #define BUF_SIZE 111 char buf[BUF_SIZE]; int fd; struct aiocb aiocb_write; struct aiocb aiocb_fsync; #if _POSIX_ASYNCHRONOUS_IO != 200112L exit(PTS_UNSUPPORTED); #endif snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_aio_fsync_9_1_%d", getpid()); unlink(tmpfname); fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL, S_IRUSR | S_IWUSR); if (fd == -1) { printf(TNAME " Error at open(): %s\n", strerror(errno)); exit(PTS_UNRESOLVED); } unlink(tmpfname); memset(&aiocb_write, 0, sizeof(aiocb_write)); aiocb_write.aio_fildes = fd; aiocb_write.aio_buf = buf; aiocb_write.aio_nbytes = BUF_SIZE; if (aio_write(&aiocb_write) == -1) { printf(TNAME " Error at aio_write(): %s\n", strerror(errno)); exit(PTS_FAIL); } memset(&aiocb_fsync, 0, sizeof(aiocb_fsync)); aiocb_fsync.aio_fildes = fd; if (aio_fsync(O_SYNC, &aiocb_fsync) != 0) { printf(TNAME " Error at aio_fsync(): %s\n", strerror(errno)); exit(PTS_FAIL); } close(fd); printf ("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/aio_fsync/11-1.c0100644000000000000000000000072410247562115022011 0ustar rootroot/* * Copyright (c) 2004, Bull SA. All rights reserved. * Created by: Laurent.Vivier@bull.net * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ #define _XOPEN_SOURCE 600 #include #include #include #include "posixtest.h" int main() { #if _POSIX_ASYNCHRONOUS_IO != 200112L exit(PTS_UNSUPPORTED); #endif return PTS_UNTESTED; } posixtestsuite/conformance/interfaces/aio_fsync/8-3.c0100644000000000000000000000311310247562115021734 0ustar rootroot/* * Copyright (c) 2004, Bull SA. All rights reserved. * Created by: Laurent.Vivier@bull.net * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include #include #include #include "posixtest.h" #define TNAME "aio_fsync/8-3.c" int main() { char tmpfname[256]; #define BUF_SIZE 111 char buf[BUF_SIZE]; int fd; struct aiocb aiocb_write; struct aiocb aiocb_fsync; #if _POSIX_ASYNCHRONOUS_IO != 200112L exit(PTS_UNSUPPORTED); #endif snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_aio_fsync_8_3_%d", getpid()); unlink(tmpfname); fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL, S_IRUSR | S_IWUSR); if (fd == -1) { printf(TNAME " Error at open(): %s\n", strerror(errno)); exit(PTS_UNRESOLVED); } unlink(tmpfname); memset(&aiocb_write, 0, sizeof(aiocb_write)); aiocb_write.aio_fildes = fd; aiocb_write.aio_buf = buf; aiocb_write.aio_nbytes = BUF_SIZE; if (aio_write(&aiocb_write) == -1) { printf(TNAME " Error at aio_write(): %s\n", strerror(errno)); exit(PTS_FAIL); } memset(&aiocb_fsync, 0, sizeof(aiocb_fsync)); aiocb_fsync.aio_fildes = fd; aiocb_fsync.aio_reqprio = -1; if (aio_fsync(O_SYNC, &aiocb_fsync) != 0) { printf(TNAME " Error at aio_fsync(): %s\n", strerror(errno)); exit(PTS_FAIL); } close(fd); printf ("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/aio_fsync/6-1.c0100644000000000000000000000072410247562115021735 0ustar rootroot/* * Copyright (c) 2004, Bull SA. All rights reserved. * Created by: Laurent.Vivier@bull.net * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ #define _XOPEN_SOURCE 600 #include #include #include #include "posixtest.h" int main() { #if _POSIX_ASYNCHRONOUS_IO != 200112L exit(PTS_UNSUPPORTED); #endif return PTS_UNTESTED; } posixtestsuite/conformance/interfaces/aio_fsync/10-1.c0100644000000000000000000000125010247562115022003 0ustar rootroot/* * Copyright (c) 2004, Bull SA. All rights reserved. * Created by: Laurent.Vivier@bull.net * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * assertion: * * aio_fsync() shall asynchronously force I/O operations associated * with aio_fildes. * * method: * * UNTESTED * * We are not able to check if I/O operations have been forced. * */ #define _XOPEN_SOURCE 600 #include #include #include #include "posixtest.h" int main() { #if _POSIX_ASYNCHRONOUS_IO != 200112L exit(PTS_UNSUPPORTED); #endif return PTS_UNTESTED; } posixtestsuite/conformance/interfaces/aio_fsync/13-1.c0100644000000000000000000000072410247562115022013 0ustar rootroot/* * Copyright (c) 2004, Bull SA. All rights reserved. * Created by: Laurent.Vivier@bull.net * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ #define _XOPEN_SOURCE 600 #include #include #include #include "posixtest.h" int main() { #if _POSIX_ASYNCHRONOUS_IO != 200112L exit(PTS_UNSUPPORTED); #endif return PTS_UNTESTED; } posixtestsuite/conformance/interfaces/aio_fsync/8-2.c0100644000000000000000000000311110247562115021731 0ustar rootroot/* * Copyright (c) 2004, Bull SA. All rights reserved. * Created by: Laurent.Vivier@bull.net * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include #include #include #include "posixtest.h" #define TNAME "aio_fsync/8-2.c" int main() { char tmpfname[256]; #define BUF_SIZE 111 char buf[BUF_SIZE]; int fd; struct aiocb aiocb_write; struct aiocb aiocb_fsync; #if _POSIX_ASYNCHRONOUS_IO != 200112L exit(PTS_UNSUPPORTED); #endif snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_aio_fsync_8_2_%d", getpid()); unlink(tmpfname); fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL, S_IRUSR | S_IWUSR); if (fd == -1) { printf(TNAME " Error at open(): %s\n", strerror(errno)); exit(PTS_UNRESOLVED); } unlink(tmpfname); memset(&aiocb_write, 0, sizeof(aiocb_write)); aiocb_write.aio_fildes = fd; aiocb_write.aio_buf = buf; aiocb_write.aio_nbytes = BUF_SIZE; if (aio_write(&aiocb_write) == -1) { printf(TNAME " Error at aio_write(): %s\n", strerror(errno)); exit(PTS_FAIL); } memset(&aiocb_fsync, 0, sizeof(aiocb_fsync)); aiocb_fsync.aio_fildes = fd; aiocb_fsync.aio_buf = NULL; if (aio_fsync(O_SYNC, &aiocb_fsync) != 0) { printf(TNAME " Error at aio_fsync(): %s\n", strerror(errno)); exit(PTS_FAIL); } close(fd); printf ("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/aio_fsync/7-1.c0100644000000000000000000000072410247562115021736 0ustar rootroot/* * Copyright (c) 2004, Bull SA. All rights reserved. * Created by: Laurent.Vivier@bull.net * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ #define _XOPEN_SOURCE 600 #include #include #include #include "posixtest.h" int main() { #if _POSIX_ASYNCHRONOUS_IO != 200112L exit(PTS_UNSUPPORTED); #endif return PTS_UNTESTED; } posixtestsuite/conformance/interfaces/aio_fsync/assertions.xml0100644000000000000000000000423710160256051024176 0ustar rootroot aio_fsync() shall asynchronously force I/O operations associated with aio_fildes. if op is O_DSYNC, all queued I/O operations shall be completed as if by a call to fdatasync(). if op is O_SYNC, all queued I/O operations shall be completed as if by a call to fsync(). aio_error() and aio_return() may be used in order to determine the error status and return status of aio_fsync opertation. When the request is queued, error status is [EINPROGRESS]. If the operation does not complete successfully, the error status shall be set to indicate the error. The aio_sigevent member determines the asynchronous notificiation to occur. Except aio_fildes and aio_sigevent, all other members of the structure are ignored. aio_fsync() shall return the value 0 if the operation is successfully queued. aio_fsync() shall return the value -1 and set errno to indicate error if the operation is not successfully queued. aio_fsync() shall fail if: [EAGAIN] Operation was not queued due to temporary resource limitations. aio_fsync() shall fail if: [EBADF] aio_fildes is not a valid file descriptor for writing. aio_fsync() shall fail if: [EINVAL] This implementation does not support synchronized I/O for this file. aio_fsync() shall fail if: [EINVAL] op is not set to O_DSYNC or O_SYNC. posixtestsuite/conformance/interfaces/aio_fsync/coverage.txt0100644000000000000000000000026710160256051023615 0ustar rootrootthis file defines the coverage for the aio_fsync() function testing. Assertion Covered? 1 NO 2 NO 3 NO 4 YES 5 NO 6 NO 7 NO 8 YES 9 YES 10 NO 11 NO 12 YES 13 NO 14 YES posixtestsuite/conformance/interfaces/aio_fsync/8-1.c0100644000000000000000000000311210247562115021731 0ustar rootroot/* * Copyright (c) 2004, Bull SA. All rights reserved. * Created by: Laurent.Vivier@bull.net * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include #include #include #include "posixtest.h" #define TNAME "aio_fsync/8-1.c" int main() { char tmpfname[256]; #define BUF_SIZE 111 char buf[BUF_SIZE]; int fd; struct aiocb aiocb_write; struct aiocb aiocb_fsync; #if _POSIX_ASYNCHRONOUS_IO != 200112L exit(PTS_UNSUPPORTED); #endif snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_aio_fsync_8_1_%d", getpid()); unlink(tmpfname); fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL, S_IRUSR | S_IWUSR); if (fd == -1) { printf(TNAME " Error at open(): %s\n", strerror(errno)); exit(PTS_UNRESOLVED); } unlink(tmpfname); memset(&aiocb_write, 0, sizeof(aiocb_write)); aiocb_write.aio_fildes = fd; aiocb_write.aio_buf = buf; aiocb_write.aio_nbytes = BUF_SIZE; if (aio_write(&aiocb_write) == -1) { printf(TNAME " Error at aio_write(): %s\n", strerror(errno)); exit(PTS_FAIL); } memset(&aiocb_fsync, 0, sizeof(aiocb_fsync)); aiocb_fsync.aio_fildes = fd; aiocb_fsync.aio_nbytes = -1; if (aio_fsync(O_SYNC, &aiocb_fsync) != 0) { printf(TNAME " Error at aio_fsync(): %s\n", strerror(errno)); exit(PTS_FAIL); } close(fd); printf ("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/aio_fsync/4-2.c0100644000000000000000000000325110247562115021732 0ustar rootroot/* * Copyright (c) 2004, Bull SA. All rights reserved. * Created by: Laurent.Vivier@bull.net * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include #include #include #include "posixtest.h" #define TNAME "aio_fsync/4-2.c" int main() { char tmpfname[256]; #define BUF_SIZE 111 char buf[BUF_SIZE]; int fd; struct aiocb aiocb_write; struct aiocb aiocb_fsync; #if _POSIX_ASYNCHRONOUS_IO != 200112L exit(PTS_UNSUPPORTED); #endif snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_aio_fsync_4_2_%d", getpid()); unlink(tmpfname); fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL, S_IRUSR | S_IWUSR); if (fd == -1) { printf(TNAME " Error at open(): %s\n", strerror(errno)); exit(PTS_UNRESOLVED); } unlink(tmpfname); memset(&aiocb_write, 0, sizeof(aiocb_write)); aiocb_write.aio_fildes = fd; aiocb_write.aio_buf = buf; aiocb_write.aio_nbytes = BUF_SIZE; if (aio_write(&aiocb_write) == -1) { printf(TNAME " Error at aio_write(): %s\n", strerror(errno)); exit(PTS_FAIL); } memset(&aiocb_fsync, 0, sizeof(aiocb_fsync)); aiocb_fsync.aio_fildes = fd; if (aio_fsync(O_SYNC, &aiocb_fsync) != 0) { printf(TNAME " Error at aio_fsync()\n"); exit(PTS_FAIL); } errno = 0; aio_return(&aiocb_fsync); if (errno != 0) { printf(TNAME " Error at aio_return() : %s\n", strerror(errno)); exit(PTS_FAIL); } close(fd); printf ("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/aio_fsync/8-4.c0100644000000000000000000000311210247562115021734 0ustar rootroot/* * Copyright (c) 2004, Bull SA. All rights reserved. * Created by: Laurent.Vivier@bull.net * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include #include #include #include "posixtest.h" #define TNAME "aio_fsync/8-4.c" int main() { char tmpfname[256]; #define BUF_SIZE 111 char buf[BUF_SIZE]; int fd; struct aiocb aiocb_write; struct aiocb aiocb_fsync; #if _POSIX_ASYNCHRONOUS_IO != 200112L exit(PTS_UNSUPPORTED); #endif snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_aio_fsync_8_4_%d", getpid()); unlink(tmpfname); fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL, S_IRUSR | S_IWUSR); if (fd == -1) { printf(TNAME " Error at open(): %s\n", strerror(errno)); exit(PTS_UNRESOLVED); } unlink(tmpfname); memset(&aiocb_write, 0, sizeof(aiocb_write)); aiocb_write.aio_fildes = fd; aiocb_write.aio_buf = buf; aiocb_write.aio_nbytes = BUF_SIZE; if (aio_write(&aiocb_write) == -1) { printf(TNAME " Error at aio_write(): %s\n", strerror(errno)); exit(PTS_FAIL); } memset(&aiocb_fsync, 0, sizeof(aiocb_fsync)); aiocb_fsync.aio_fildes = fd; aiocb_fsync.aio_offset = -1; if (aio_fsync(O_SYNC, &aiocb_fsync) != 0) { printf(TNAME " Error at aio_fsync(): %s\n", strerror(errno)); exit(PTS_FAIL); } close(fd); printf ("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/aio_fsync/2-1.c0100644000000000000000000000312610247562115021730 0ustar rootroot/* * Copyright (c) 2004, Bull SA. All rights reserved. * Created by: Laurent.Vivier@bull.net * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include #include #include #include "posixtest.h" #define TNAME "aio_fsync/2-1.c" #define BUF_SIZE 1024 int main() { char tmpfname[256]; char buf[BUF_SIZE]; int fd; struct aiocb aiocb_write; struct aiocb aiocb_fsync; #if _POSIX_ASYNCHRONOUS_IO != 200112L exit(PTS_UNSUPPORTED); #endif snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_aio_fsync_2_1_%d", getpid()); unlink(tmpfname); fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL, S_IRUSR | S_IWUSR); if (fd == -1) { printf(TNAME " Error at open(): %s\n", strerror(errno)); exit(PTS_UNRESOLVED); } unlink(tmpfname); memset(&aiocb_write, 0, sizeof(aiocb_write)); aiocb_write.aio_fildes = fd; aiocb_write.aio_buf = buf; aiocb_write.aio_nbytes = BUF_SIZE; if (aio_write(&aiocb_write) == -1) { printf(TNAME " Error at aio_write(): %s\n", strerror(errno)); exit(PTS_FAIL); } memset(&aiocb_fsync, 0, sizeof(aiocb_fsync)); aiocb_fsync.aio_fildes = fd; if (aio_fsync(O_DSYNC, &aiocb_fsync) != 0) { printf(TNAME " Error at aio_fsync(): %s\n", strerror(errno)); exit(PTS_FAIL); } close(fd); /* we didn't check if the operation is really performed */ return PTS_UNTESTED; } posixtestsuite/conformance/interfaces/aio_fsync/3-1.c0100644000000000000000000000312510247562115021730 0ustar rootroot/* * Copyright (c) 2004, Bull SA. All rights reserved. * Created by: Laurent.Vivier@bull.net * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include #include #include #include "posixtest.h" #define TNAME "aio_fsync/3-1.c" #define BUF_SIZE 1024 int main() { char tmpfname[256]; char buf[BUF_SIZE]; int fd; struct aiocb aiocb_write; struct aiocb aiocb_fsync; #if _POSIX_ASYNCHRONOUS_IO != 200112L exit(PTS_UNSUPPORTED); #endif snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_aio_fsync_3_1_%d", getpid()); unlink(tmpfname); fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL, S_IRUSR | S_IWUSR); if (fd == -1) { printf(TNAME " Error at open(): %s\n", strerror(errno)); exit(PTS_UNRESOLVED); } unlink(tmpfname); memset(&aiocb_write, 0, sizeof(aiocb_write)); aiocb_write.aio_fildes = fd; aiocb_write.aio_buf = buf; aiocb_write.aio_nbytes = BUF_SIZE; if (aio_write(&aiocb_write) == -1) { printf(TNAME " Error at aio_write(): %s\n", strerror(errno)); exit(PTS_FAIL); } memset(&aiocb_fsync, 0, sizeof(aiocb_fsync)); aiocb_fsync.aio_fildes = fd; if (aio_fsync(O_SYNC, &aiocb_fsync) != 0) { printf(TNAME " Error at aio_fsync(): %s\n", strerror(errno)); exit(PTS_FAIL); } close(fd); /* we didn't check if the operation is really performed */ return PTS_UNTESTED; } posixtestsuite/conformance/interfaces/timer_delete/0040755000000000000000000000000010515625271021757 5ustar rootrootposixtestsuite/conformance/interfaces/timer_delete/speculative/0040755000000000000000000000000010515625271024303 5ustar rootrootposixtestsuite/conformance/interfaces/timer_delete/speculative/5-1.c0100644000000000000000000000171710021017163024737 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test to see if timer_delete() returns -1 and sets errno==EINVAL if * timerid is not a valid timer ID or not. * Since this is a "may" requirement, either option is a PASS. */ #include #include #include #include "posixtest.h" #define BOGUSTIMERID 99999 int main(int argc, char *argv[]) { timer_t tid; tid = (timer_t) BOGUSTIMERID; if (timer_delete(tid) == -1) { if (errno==EINVAL) { printf("timer_delete() returned -1 and set errno=EINVAL\n"); return PTS_PASS; } else { printf("timer_delete() returned -1, but didn't set errno!=EINVAL\n"); return PTS_FAIL; } } printf("timer_delete() did not return -1\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/timer_delete/speculative/5-2.c0100644000000000000000000000431507663173050024755 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test to see if timer_delete() returns -1 and sets errno==EINVAL when * trying to delete a timer that has already been deleted or not. * Since this is a "may" assertion, either option is a pass. * Steps: * - Run test case 1-1.c and then try to delete the timer again. * * For this test, signal SIGTOTEST will be used, clock CLOCK_REALTIME * will be used. */ #include #include #include #include #include #include #include "posixtest.h" #define SIGTOTEST SIGALRM #define TIMERSEC 3 void handler(int signo) { printf("Should not have caught signal\n"); exit(PTS_FAIL); } int main(int argc, char *argv[]) { struct sigevent ev; struct sigaction act; timer_t tid; struct itimerspec its; ev.sigev_notify = SIGEV_SIGNAL; ev.sigev_signo = SIGTOTEST; act.sa_handler=handler; act.sa_flags=0; its.it_interval.tv_sec = 0; its.it_interval.tv_nsec = 0; its.it_value.tv_sec = TIMERSEC; its.it_value.tv_nsec = 0; if (sigemptyset(&act.sa_mask) == -1) { perror("Error calling sigemptyset\n"); return PTS_UNRESOLVED; } if (sigaction(SIGTOTEST, &act, 0) == -1) { perror("Error calling sigaction\n"); return PTS_UNRESOLVED; } if (timer_create(CLOCK_REALTIME, &ev, &tid) != 0) { perror("timer_create() did not return success\n"); return PTS_UNRESOLVED; } if (timer_settime(tid, 0, &its, NULL) != 0) { perror("timer_settime() did not return success\n"); return PTS_UNRESOLVED; } if (timer_delete(tid) != 0) { perror("timer_delete() did not return success\n"); return PTS_UNRESOLVED; } if (sleep(TIMERSEC) != 0) { printf("sleep() did not sleep full time\n"); return PTS_UNRESOLVED; } if (timer_delete(tid) == -1) { if (errno==EINVAL) { printf("fcn returned -1 and set errno=EINVAL\n"); return PTS_PASS; } else { printf("errno!=EINVAL, but fcn returned -1\n"); return PTS_FAIL; } } printf("fcn did not return -1\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/timer_delete/3-1.sh0100755000000000000000000000070307570455574022631 0ustar rootroot#!/bin/sh # Copyright (c) 2002, Intel Corporation. All rights reserved. # Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com # This file is licensed under the GPL license. For the full content # of this license, see the COPYING file at the top level of this # source tree. # # Test that timer_delete() returns 0 on success. # # Tested implicitly via assertion 1. echo "Tested implicitly via assertion 1. See output for status." exit 0 posixtestsuite/conformance/interfaces/timer_delete/1-1.c0100644000000000000000000000430307570452331022420 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that timer_delete() deletes a timer. * Steps: * - Create a timer to send SIGTOTEST on expiration and set up a signal * handler to catch it. * - Activate the timer. * - Delete the timer before the timer had a chance to expire. [Potential * false failure here if the timer cannot be deleted in time. However, * the timer expiration will be set large enough that this should not * be likely.] * - Sleep until the timer would have expired. * - If no signal was caught, PASS. Otherwise, FAIL. * * For this test, signal SIGTOTEST will be used, clock CLOCK_REALTIME * will be used. */ #include #include #include #include #include #include "posixtest.h" #define SIGTOTEST SIGALRM #define TIMERSEC 3 void handler(int signo) { printf("Should not have caught signal\n"); exit(PTS_FAIL); } int main(int argc, char *argv[]) { struct sigevent ev; struct sigaction act; timer_t tid; struct itimerspec its; ev.sigev_notify = SIGEV_SIGNAL; ev.sigev_signo = SIGTOTEST; act.sa_handler=handler; act.sa_flags=0; its.it_interval.tv_sec = 0; its.it_interval.tv_nsec = 0; its.it_value.tv_sec = TIMERSEC; its.it_value.tv_nsec = 0; if (sigemptyset(&act.sa_mask) == -1) { perror("Error calling sigemptyset\n"); return PTS_UNRESOLVED; } if (sigaction(SIGTOTEST, &act, 0) == -1) { perror("Error calling sigaction\n"); return PTS_UNRESOLVED; } if (timer_create(CLOCK_REALTIME, &ev, &tid) != 0) { perror("timer_create() did not return success\n"); return PTS_UNRESOLVED; } if (timer_settime(tid, 0, &its, NULL) != 0) { perror("timer_settime() did not return success\n"); return PTS_UNRESOLVED; } if (timer_delete(tid) != 0) { perror("timer_delete() did not return success\n"); return PTS_UNRESOLVED; } if (sleep(TIMERSEC) != 0) { printf("sleep() did not sleep full time\n"); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/timer_delete/1-2.c0100644000000000000000000000323407570455531022430 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that after a timer is deleted by calling timer_delete(), it * cannot be armed by calling timer_settime(). * Steps: * - Create a timer * - Delete that timer * - Try to call timer_settime() on that timer and ensure it fails * with errno==EINVAL. * * For this test, signal SIGTOTEST will be used, clock CLOCK_REALTIME * will be used. */ #include #include #include #include #include "posixtest.h" #define SIGTOTEST SIGALRM #define TIMERSEC 3 int main(int argc, char *argv[]) { struct sigevent ev; timer_t tid; struct itimerspec its; ev.sigev_notify = SIGEV_SIGNAL; ev.sigev_signo = SIGTOTEST; if (timer_create(CLOCK_REALTIME, &ev, &tid) != 0) { perror("timer_create() did not return success\n"); return PTS_UNRESOLVED; } if (timer_delete(tid) != 0) { perror("timer_delete() did not return success\n"); return PTS_UNRESOLVED; } its.it_interval.tv_sec = 0; its.it_interval.tv_nsec = 0; its.it_value.tv_sec = TIMERSEC; its.it_value.tv_nsec = 0; if (timer_settime(tid, 0, &its, NULL) == -1) { if (errno==EINVAL) { printf("Test PASSED\n"); return PTS_PASS; } else { printf("errno!=EINVAL after a timer_delete()\n"); return PTS_FAIL; } } else { printf("timer_settime() did not fail after timer_delete()\n"); return PTS_FAIL; } printf("This code should not be executed\n"); return PTS_UNRESOLVED; } posixtestsuite/conformance/interfaces/timer_delete/assertions.xml0100644000000000000000000000146207663171627024706 0ustar rootroot timer_delete() deletes timer, timerid. [timerid is created by timer_create().] If timerid is an armed timer when timer_delete() is called, it will appear as if the timer is automatically disarmed before removal. [It is unspecified what happens to any pending signals.] timer_delete() returns 0 on success timer_delete returns -1 on failure timer_delete() may set errno==EINVAL if timerid is not a valid timer ID posixtestsuite/conformance/interfaces/timer_delete/coverage.txt0100644000000000000000000000016307570457016024317 0ustar rootrootThis file defines the coverage for function timer_delete(). Assertion Covered? 1 YES 2 YES 3 YES 4 YES 5 YES posixtestsuite/conformance/interfaces/timer_delete/2-1.sh0100755000000000000000000000074507570455574022636 0ustar rootroot#!/bin/sh # Copyright (c) 2002, Intel Corporation. All rights reserved. # Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com # This file is licensed under the GPL license. For the full content # of this license, see the COPYING file at the top level of this # source tree. # # Test that timer_delete() appears as if it disarms armed timers before # removal. # # Tested implicitly via assertion 1. echo "Tested implicitly via assertion 1. See output for status." exit 0 posixtestsuite/conformance/interfaces/timer_delete/4-1.sh0100755000000000000000000000070407570457016022624 0ustar rootroot#!/bin/sh # Copyright (c) 2002, Intel Corporation. All rights reserved. # Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com # This file is licensed under the GPL license. For the full content # of this license, see the COPYING file at the top level of this # source tree. # # Test that timer_delete() returns -1 on failure. # # Tested implicitly via assertion 5. echo "Tested implicitly via assertion 5. See output for status." exit 0 posixtestsuite/conformance/interfaces/pthread_mutexattr_setpshared/0040755000000000000000000000000010515625222025277 5ustar rootrootposixtestsuite/conformance/interfaces/pthread_mutexattr_setpshared/2-2.c0100644000000000000000000000236207640462277025761 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: bing.wei.liu REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_mutexattr_setpshared() * * Upon success, it returns 0. * * Steps: * * 1. Initialized a mutexattr object. * 2. Set the attributes object to PTHREAD_PROCESS_SHARED. The error return code should be 0. * */ #include #include #include "posixtest.h" int main() { /* Make sure there is process-shared capability. */ #ifndef PTHREAD_PROCESS_SHARED fprintf(stderr,"process-shared attribute is not available for testing\n"); return PTS_UNRESOLVED; #endif pthread_mutexattr_t mta; int ret; /* Initialize a mutex attributes object */ if(pthread_mutexattr_init(&mta) != 0) { perror("Error at pthread_mutexattr_init()\n"); return PTS_UNRESOLVED; } /* Set the attribute to PTHREAD_PROCESS_PRIVATE. */ ret=pthread_mutexattr_setpshared(&mta, PTHREAD_PROCESS_SHARED); if(ret != 0) { printf("Test FAILED: Expected return code 0, got: %d\n", ret); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_mutexattr_setpshared/1-1.c0100644000000000000000000000477007640462277025764 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: bing.wei.liu REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_mutexattr_setpshared() * * It shall set the process-shared attribute in an initialized attributes object 'attr'. * The process-shared attribute is set to PTHREAD_PROCESS_SHARED to permit a mutex to be * operated upon by any thread that has access to the memory where the mutex is allocated, * even if the mutex is allocated in memory that is shared by multiple processes. * * If the process-shared attribute is PTHREAD_PROCESS_PRIVATE, the mutex shall only be * operated upon by threads created within the same process as the thread that initialized * the mutex; if threads of differing processes attempt to operate on such a mutex, * the behavior is undefined. * * Steps: * * Explanation: To share a mutex between 2 processes, you need to map shared memory for * the mutex. So whether the 'type' of the mutexattr is shared or private, it really will * not make a difference since both processes will always have access to the shared memory * as long as they the pointer to it. So all we check here is that you can actually call * the pthread_mutexattr_setpshared() function, passing to it PTHREAD_PROCESS_SHARED and * PTHREAD_PROCESS_PRIVATE. * * 1. Initialize a pthread_mutexattr_t object. * 2. Call pthread_mutexattr_getpshared(), passing to it both PTHREAD_PROCESS_SHARE and * PTHREAD_PROCESS_PRIVATE. * */ #include #include #include "posixtest.h" pthread_mutex_t new_mutex; /* The mutex. */ int main() { pthread_mutexattr_t mta; int ret; /* Initialize a mutex attributes object */ if(pthread_mutexattr_init(&mta) != 0) { perror("Error at pthread_mutexattr_init()\n"); return PTS_UNRESOLVED; } /* Set the 'pshared' attribute to PTHREAD_PROCESS_PRIVATE */ if((ret=pthread_mutexattr_setpshared(&mta, PTHREAD_PROCESS_PRIVATE)) != 0) { printf("Test FAILED: Cannot set pshared attribute to PTHREAD_PROCESS_PRIVATE. Error: %d\n", ret); return PTS_FAIL; } /* Set the 'pshared' attribute to PTHREAD_PROCESS_SHARED */ if((ret=pthread_mutexattr_setpshared(&mta, PTHREAD_PROCESS_SHARED)) != 0) { printf("Test FAILED: Cannot set pshared attribute to PTHREAD_PROCESS_SHARED. Error code: %d\n", ret); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_mutexattr_setpshared/3-2.c0100644000000000000000000000260507676707564025774 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: bing.wei.liu REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_mutexattr_setpshared() * * It MAY fail if: * * [EINVAL] - the new value pshared value is outside the range of legal values for that * attribute. * * Steps: * * 1. Pass to pthread_mutexattr_setpshared() a negative value in the 'pshared' parameter.. * 2. It may return the value of EINVAL. * */ #include #include #include #include "posixtest.h" #define INVALID_PSHARED_VALUE -1 int main() { /* Make sure there is process-shared capability. */ #ifndef PTHREAD_PROCESS_SHARED fprintf(stderr,"process-shared attribute is not available for testing\n"); return PTS_UNRESOLVED; #endif pthread_mutexattr_t mta; int ret; /* Set the attribute to INVALID_PSHARED_VALUE. */ ret=pthread_mutexattr_setpshared(&mta, INVALID_PSHARED_VALUE); if(ret != 0) { if(ret == EINVAL) { printf("Test PASSED\n"); return PTS_PASS; } printf("Test FAILED: Expected return code 0 or EINVAL, got: %d", ret); return PTS_FAIL; } printf("Test PASSED: NOTE*: Returned 0 on error, though standard states 'may' fail.\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_mutexattr_setpshared/1-2.c0100644000000000000000000000311507640462277025755 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: bing.wei.liu REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_mutexattr_setpshared() * * The default value of the 'pshared' attribute is PTHREAD_PROCESS_PRIVATE. * * Steps: * 1. Initialize a pthread_mutexattr_t object with pthread_mutexattr_init() * 2. Call pthread_mutexattr_getpshared() to check if the process-shared * attribute is set as the default value PTHREAD_PROCESS_PRIVATE. * */ #include #include #include "posixtest.h" int main() { /* Make sure there is process-shared capability. */ #ifndef PTHREAD_PROCESS_SHARED fprintf(stderr,"process-shared attribute is not available for testing\n"); return PTS_UNRESOLVED; #endif pthread_mutexattr_t mta; int pshared; /* Initialize a mutex attributes object */ if(pthread_mutexattr_init(&mta) != 0) { perror("Error at pthread_mutexattr_init()\n"); return PTS_UNRESOLVED; } /* The default 'pshared' attribute should be PTHREAD_PROCESS_PRIVATE */ if(pthread_mutexattr_getpshared(&mta, &pshared) != 0) { fprintf(stderr,"Error obtaining the attribute process-shared\n"); return PTS_UNRESOLVED; } /* Make sure that the default is PTHREAD_PROCESS_PRIVATE. */ if(pshared != PTHREAD_PROCESS_PRIVATE) { printf("Test FAILED: Incorrect default pshared value: %d\n", pshared); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_mutexattr_setpshared/assertions.xml0100644000000000000000000000230207634212527030215 0ustar rootroot The function int pthread_mutexattr_setpshared(const pthread_mutexattr_t *attr, int pshared); It shall set the process-shared attribute in an initialized attributes object 'attr'. The process-shared attribute is set to PTHREAD_PROCESS_SHARED to permit a mutex to be operated upon by any thread that has access to the memory where the mutex is allocated, even if the mutex is allocated in memory that is shared by multiple processes. If the process-shared attribute is PTHREAD_PROCESS_PRIVATE, the mutex shall only be operated upon by threads created within the same process as the thread that initialized the mutex; if threads of differing processes attempt to operate on such a mutex, the behavior is undefined. The default value of the attribute is PTHREAD_PROCESS_PRIVATE. Upon success, it returns 0. It MAY fail if: [EINVAL] - 'attr' is invalid. [EINVAL] - the new value pshared value is outside the range of legal values for that attribute. posixtestsuite/conformance/interfaces/pthread_mutexattr_setpshared/coverage.txt0100644000000000000000000000020007640462277027636 0ustar rootrootThis document defines the coverage for the pthread_mutexattr_setpshared function: Assertion Tested? YES 2 YES 3 YES NOTE: posixtestsuite/conformance/interfaces/pthread_mutexattr_setpshared/2-1.c0100644000000000000000000000236207634212526025751 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: bing.wei.liu REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_mutexattr_setpshared() * * Upon success, it returns 0. * * Steps: * * 1. Initialized a mutexattr object. * 2. Set the attributes object to PTHREAD_PROCESS_PRIVATE. The error return code should be 0. * */ #include #include #include "posixtest.h" int main() { /* Make sure there is process-shared capability. */ #ifndef PTHREAD_PROCESS_SHARED fprintf(stderr,"process-shared attribute is not available for testing\n"); return PTS_UNRESOLVED; #endif pthread_mutexattr_t mta; int ret; /* Initialize a mutex attributes object */ if(pthread_mutexattr_init(&mta) != 0) { perror("Error at pthread_mutexattr_init()\n"); return PTS_UNRESOLVED; } /* Set the attribute to PTHREAD_PROCESS_PRIVATE. */ ret=pthread_mutexattr_setpshared(&mta, PTHREAD_PROCESS_PRIVATE); if(ret != 0) { printf("Test FAILED: Expected return code 0, got: %d", ret); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_mutexattr_setpshared/3-1.c0100644000000000000000000000241407634213621025745 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: bing.wei.liu REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_mutexattr_setpshared() * * It MAY fail if: * * [EINVAL] - 'attr' is invalid. * * Steps: * * 1. Pass to pthread_mutexattr_setpshared() an uninitialized attributes object. * 2. It may return the value of EINVAL. * */ #include #include #include #include "posixtest.h" int main() { /* Make sure there is process-shared capability. */ #ifndef PTHREAD_PROCESS_SHARED fprintf(stderr,"process-shared attribute is not available for testing\n"); return PTS_UNRESOLVED; #endif pthread_mutexattr_t mta; int ret; /* Set the attribute to PTHREAD_PROCESS_PRIVATE. */ ret=pthread_mutexattr_setpshared(&mta, PTHREAD_PROCESS_PRIVATE); if(ret != 0) { if(ret == EINVAL) { printf("Test PASSED\n"); return PTS_PASS; } printf("Test FAILED: Expected return code 0 or EINVAL, got: %d", ret); return PTS_FAIL; } printf("Test PASSED: NOTE*: Returned 0 on error, though standard states 'may' fail.\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_mutex_init/0040755000000000000000000000000010515625217023211 5ustar rootrootposixtestsuite/conformance/interfaces/pthread_mutex_init/5-1.c0100644000000000000000000001613710050613077023657 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * * This sample test aims to check the following assertion: * The function fails and returns ENOMEM if there is not enough memory. * The steps are: * * Fork * * New process sets its memory resource limit to a minimum value, then * -> Allocate all the available memory * -> call pthread_mutex_init() * -> free the memory * -> Checks that pthread_mutex_init() returned 0 or ENOMEM. * * Parent process waits for the child. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /* We need the setrlimit() function from X/OPEN standard */ #ifndef WITHOUT_XOPEN #define _XOPEN_SOURCE 600 /********************************************************************************************/ /****************************** standard includes *****************************************/ /********************************************************************************************/ #include #include #include #include #include #include #include #include #include /********************************************************************************************/ /****************************** Test framework *****************************************/ /********************************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /********************************************************************************************/ /********************************** Configuration ******************************************/ /********************************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif /********************************************************************************************/ /*********************************** Test case *****************************************/ /********************************************************************************************/ int main(int argc, char * argv[]) { pid_t child; pthread_mutex_t mtx; pthread_mutexattr_t ma[4]; pthread_mutexattr_t *pma[5]; int ret=0; int i; int retini[5] = {-1,-1,-1,-1,-1}; int retdtr[5]= {-1,-1,-1,-1,-1}; void * ptr, *ptr_prev=NULL; int sz = 0; struct rlimit rl; int status=0; output_init(); child = fork(); if (child == (pid_t)-1) { UNRESOLVED(errno, "Fork failed"); } if (child != 0) /* We are the father */ { if (child != waitpid(child, &status, 0)) { UNRESOLVED(errno, "Waitpid failed"); } if (WIFSIGNALED(status)) { UNRESOLVED(WTERMSIG(status), "The child process was killed."); } if (WIFEXITED(status)) return WEXITSTATUS(status); UNRESOLVED(0, "Child process neither returned nor was killed."); } /* Only the child goes further */ /* We initialize the different mutex attributes */ for (i=0; (i<4) && (ret == 0); i++) { pma[i] = &ma[i]; ret = pthread_mutexattr_init(pma[i]); } if (ret) { UNRESOLVED(ret, "Mutex attribute init failed"); } pma[4] = (pthread_mutexattr_t *) NULL; if ((ret = pthread_mutexattr_settype(pma[0], PTHREAD_MUTEX_NORMAL))) { UNRESOLVED(ret, "Mutex attribute NORMAL failed"); } if ((ret = pthread_mutexattr_settype(pma[0], PTHREAD_MUTEX_DEFAULT))) { UNRESOLVED(ret, "Mutex attribute DEFAULT failed"); } if ((ret = pthread_mutexattr_settype(pma[0], PTHREAD_MUTEX_RECURSIVE))) { UNRESOLVED(ret, "Mutex attribute RECURSIVE failed"); } if ((ret = pthread_mutexattr_settype(pma[0], PTHREAD_MUTEX_ERRORCHECK))) { UNRESOLVED(ret, "Mutex attribute ERRORCHECK failed"); } sz = sysconf(_SC_PAGESIZE); /* Limit the process memory to a small value (64Mb for example). */ rl.rlim_max=1024*1024*64; rl.rlim_cur=1024*1024*64; if ((ret = setrlimit(RLIMIT_AS, &rl))) { UNRESOLVED(ret, "Memory limitation failed"); } #if VERBOSE > 1 output("Ready to take over memory. Page size is %d\n", sz); #endif /* Allocate all available memory */ while (1) { ptr = malloc( sz ); /* Allocate one page of memory */ if (ptr == NULL) break; #if VERBOSE > 1 ret++; #endif *(void **)ptr = ptr_prev; /* Write into the allocated page */ ptr_prev = ptr; } #if VERBOSE > 1 output("%d pages were allocated before failure\n", ret); ret = 0; #endif while (1) { ptr = malloc( sizeof(void*) ); /* Allocate every remaining bits of memory */ if (ptr == NULL) break; #if VERBOSE > 1 ret++; #endif *(void **)ptr = ptr_prev; /* Keep track of allocated memory */ ptr_prev = ptr; } #if VERBOSE > 1 output("%d additional spaces were allocated before failure\n", ret); ret = 0; #endif if (errno != ENOMEM) UNRESOLVED(errno, "Memory not full"); /* Now that memory is full, we try to initialize a mutex */ for (i=0; i<5; i++) { retini[i] = pthread_mutex_init(&mtx, pma[i]); if (!retini[i]) /* If mutex has been initialized, we destroy it */ retdtr[i] = pthread_mutex_destroy(&mtx); } /* We can now free the memory */ while (ptr_prev != NULL) { ptr = ptr_prev; ptr_prev = *(void **)ptr; free(ptr); } #if VERBOSE > 1 output("Memory is released\n"); #endif for (i=0; i<4; i++) pthread_mutexattr_destroy(pma[i]); for (i=0; i<5; i++) { if (retini[i] != 0 && retini[i] !=ENOMEM) { FAILED("Mutex init returned a wrong error code when no memory was left"); } if (retini[i] == 0) { #if VERBOSE > 0 output("Mutex initialization for attribute %d succeeds when memory is full\n", i); #endif if (retdtr[i] != 0) { UNRESOLVED( retdtr[i], "Mutex destroy failed on mutex inilialized under heavy loaded memory"); } } #if VERBOSE > 0 else { output("Mutex initialization for attribute %d fails with ENOMEM when memory is full\n", i); } #endif } PASSED; } #else /* WITHOUT_XOPEN */ int main(int argc, char * argv[]) { output_init(); UNTESTED("This test requires XSI features"); } #endif posixtestsuite/conformance/interfaces/pthread_mutex_init/speculative/0040755000000000000000000000000010515625217025535 5ustar rootrootposixtestsuite/conformance/interfaces/pthread_mutex_init/speculative/5-2.c0100644000000000000000000001024210051111124026156 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * * This sample test aims to check the following assertion: * The function fails and return EPERM if caller has not the * privilege to perform the operation. * The steps are: * -> if this implementation does not support privileges, return PTS_UNSUPPORTED * -> Otherwise, use the implementation features to come to a situation where * pthread_mutex_init should fail because of the privileges, and then check * that the return code is EPERM. * -> return PTS_UNTESTED if the architecture is not present in the test. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /********************************************************************************************/ /****************************** standard includes *****************************************/ /********************************************************************************************/ #include #include #include #include #include #include #include #include /********************************************************************************************/ /****************************** Test framework *****************************************/ /********************************************************************************************/ #include "../testfrmw.h" #include "../testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /********************************************************************************************/ /********************************** Configuration ******************************************/ /********************************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif #ifndef PTS_UNSUPPORTED #define PTS_UNSUPPORTED 4 #endif #ifndef PTS_UNTESTED #define PTS_UNTESTED 5 #endif /********************************************************************************************/ /*********************************** Test case *****************************************/ /********************************************************************************************/ int main(int argc, char * argv[]) { int ret; struct utsname un; output_init(); ret = uname(&un); if (ret == -1) { UNRESOLVED(errno, "Unable to get Implementation name"); } #if VERBOSE > 0 output("Implementation is: \n\t%s\n\t%s\n\t%s\n", un.sysname, un.release, un.version); #endif /* If we are running Linux */ if (strcmp(un.sysname, "Linux") == 0 ) { /* Linux does not provide privilege access to pthread_mutex_init function */ ret = PTS_UNSUPPORTED; output("Linux does not provide this feature\n"); output_fini(); return ret; } /* If we are running AIX */ if (strcmp(un.sysname, "AIX") == 0 ) { ; } /* If we are running Solaris */ if (strcmp(un.sysname, "SunOS") == 0 ) { ; } output("This implementation is not tested yet\n"); output_fini(); return PTS_UNTESTED; } posixtestsuite/conformance/interfaces/pthread_mutex_init/4-1.c0100644000000000000000000000277307615426126023671 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: bing.wei.liu REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_mutex_init() * Upon succesful completion, it shall return a 0 * */ #include #include #include #include "posixtest.h" int main() { pthread_mutexattr_t mta; pthread_mutex_t mutex; int rc; /* Initialize a mutex attributes object */ if((rc=pthread_mutexattr_init(&mta)) != 0) { fprintf(stderr,"Error at pthread_mutexattr_init(), rc=%d\n",rc); return PTS_UNRESOLVED; } /* Initialize a mutex object with the default mutex attributes */ if((rc=pthread_mutex_init(&mutex,&mta)) == 0) { printf("Test PASSED\n"); return PTS_PASS; } /* Check if returned values are tolerable */ else if(rc == ENOMEM) { fprintf(stderr,"Insufficient memory to initialize the mutex\n"); return PTS_UNRESOLVED; } else if(rc == EAGAIN) { fprintf(stderr,"Lack of the necessary resources to initilize the mutex\n"); return PTS_UNRESOLVED; } else if(rc == EPERM) { fprintf(stderr,"Permission denied\n"); return PTS_UNRESOLVED; } else if(rc == EBUSY) { fprintf(stderr,"Detected an attemp to reinitilize a previously initilized mutex\n"); return PTS_UNRESOLVED; } /* Any other returned value means the test failed */ else { printf("Test FAILED\n"); return PTS_FAIL; } } posixtestsuite/conformance/interfaces/pthread_mutex_init/1-1.c0100644000000000000000000000276607615426126023670 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: bing.wei.liu REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_mutex_init() * initializes a mutex referenced by 'mutex' with attributes specified * by 'attr'. If 'attr' is NULL, the default mutex attributes are used. * The effect shall be the same as passing the address of a default * mutex attributes. * NOTE: There is no direct way to judge if two mutexes have the same effect, * thus this test does not cover the statement in the last sentence. * */ #include #include #include "posixtest.h" int main() { pthread_mutexattr_t mta; pthread_mutex_t mutex1, mutex2; int rc; /* Initialize a mutex attributes object */ if((rc=pthread_mutexattr_init(&mta)) != 0) { fprintf(stderr,"Error at pthread_mutexattr_init(), rc=%d\n",rc); return PTS_UNRESOLVED; } /* Initialize mutex1 with the default mutex attributes */ if((rc=pthread_mutex_init(&mutex1,&mta)) != 0) { fprintf(stderr,"Fail to initialize mutex1, rc=%d\n",rc); printf("Test FAILED\n"); return PTS_FAIL; } /* Initialize mutex2 with NULL attributes */ if((rc=pthread_mutex_init(&mutex2,NULL)) != 0) { fprintf(stderr,"Fail to initialize mutex2, rc=%d\n",rc); printf("Test FAILED\n"); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_mutex_init/testfrmw.c0100644000000000000000000000334410047132143025220 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * * This file is a wrapper to use the tests from the NPTL Test & Trace Project * with either the Linux Test Project or the Open POSIX Test Suite. * The following function are defined: * void output_init() * void output_fini() * void output(char * string, ...) * * The are used to output informative text (as a printf). */ /* We use a mutex to avoid conflicts in traces */ static pthread_mutex_t m_trace = PTHREAD_MUTEX_INITIALIZER; /*****************************************************************************************/ /******************************* stdout module *****************************************/ /*****************************************************************************************/ /* The following functions will output to stdout */ #if (1) void output_init() { /* do nothing */ return; } void output( char * string, ... ) { va_list ap; pthread_mutex_lock(&m_trace); va_start( ap, string); vprintf(string, ap); va_end(ap); pthread_mutex_unlock(&m_trace); } void output_fini() { /*do nothing */ return; } #endif posixtestsuite/conformance/interfaces/pthread_mutex_init/3-2.c0100644000000000000000000002341410047321246023652 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * * This sample test aims to check the following assertion: * * The macro PTHREAD_MUTEX_INITIALIZER can be used * to initialize mutexes that are statically allocated. * The effect are equivalent to dynamic initialization by a call to * pthread_mutex_init() with parameter attr specified as NULL, * except that no error checks are performed. * * The steps are: * * create two mutexes. One is initialized with NULL attribute, * the other is statically initialized with the macro PTHREAD_MUTEX_INITIALIZER. * * Compare the following features between the two mutexes: * -> Can it cause / detect a deadlock? (attempt to lock a mutex the thread already owns). * If detected, do both mutexes cause the same error code? * -> Is an error returned when unlocking the mutex in unlocked state? * When unlocking the mutex owned by another thread? * * * The test will pass if the results of each feature are the same for the two mutexes * (making no assumption on what is the default behavior). * The test will be unresolved if any initialization fails. * The test will fail if a feature differs between the two mutex objects. */ /* * - adam.li@intel.com 2004-05-09 * Add to PTS. Please refer to http://nptl.bullopensource.org/phpBB/ * for general information */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /********************************************************************************************/ /****************************** standard includes *****************************************/ /********************************************************************************************/ #include #include #include #include #include #include #include /********************************************************************************************/ /****************************** Test framework *****************************************/ /********************************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /********************************************************************************************/ /********************************** Configuration ******************************************/ /********************************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif /********************************************************************************************/ /*********************************** Test case *****************************************/ /********************************************************************************************/ /**** global variables ****/ pthread_mutex_t * p_mtx; int retval = 0; int returned = 0; int canceled = 0; sem_t semA, semB; /***** Cancelation handlers *****/ void cleanup_deadlk(void * arg) { canceled = 1; pthread_mutex_unlock(p_mtx); } /***** Threads functions *****/ void * deadlk_issue(void * arg) { int ret, tmp; if ((ret=pthread_mutex_lock(p_mtx))) { UNRESOLVED(ret, "First mutex lock in deadlk_issue"); } pthread_cleanup_push(cleanup_deadlk, NULL); if ((ret = pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &tmp))) { UNRESOLVED(ret, "Set cancel type in deadlk_issue"); } if ((ret = pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &tmp))) { UNRESOLVED(ret, "Set cancel state in deadlk_issue"); } #if VERBOSE >1 output("Thread releases the semaphore...\n"); #endif if ((ret = sem_post(&semA))) { UNRESOLVED(errno, "Sem_post in deadlk_issue"); } returned = 0; retval = pthread_mutex_lock(p_mtx); returned = 1; if ((ret = pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &tmp))) { UNRESOLVED(ret, "Set cancel state in deadlk_issue"); } pthread_cleanup_pop(0); return NULL; } void * unlock_issue(void * arg) { int ret; #if VERBOSE >1 output("Locking in child...\n"); #endif if ((ret=pthread_mutex_lock(p_mtx))) { UNRESOLVED(ret, "First mutex lock in unlock_issue"); } if ((ret = sem_post(&semA))) { UNRESOLVED(errno, "Sem_post in unlock_issue"); } if ((ret = sem_wait(&semB))) { UNRESOLVED(errno, "Sem_wait in unlock_issue"); } if (retval != 0) /* parent thread failed to unlock the mutex) */ { #if VERBOSE >1 output("Unlocking in child...\n"); #endif if ((ret=pthread_mutex_unlock(p_mtx))) { FAILED("Mutex unlock returned an error but mutex is unlocked."); } } return NULL; } /***** main program *****/ int main(int argc, char *argv[]) { pthread_mutex_t mtx_null, mtx_macro = PTHREAD_MUTEX_INITIALIZER; pthread_t thr; pthread_mutex_t * tab_mutex[2]={&mtx_null, &mtx_macro}; int tab_res[2][3]={{0,0,0},{0,0,0}}; int ret; void * th_ret; int i; output_init(); #if VERBOSE >1 output("Test starting...\n"); #endif /* We first initialize the two mutexes. */ if ((ret=pthread_mutex_init(&mtx_null, NULL))) { UNRESOLVED(ret, "NULL mutex init"); } if ((ret=sem_init(&semA, 0, 0))) { UNRESOLVED(errno, "Sem A init"); } if ((ret=sem_init(&semB, 0, 0))) { UNRESOLVED(errno, "Sem B init"); } #if VERBOSE >1 output("Data initialized...\n"); #endif /* OK let's go for the first part of the test : abnormals unlocking */ /* We first check if unlocking an unlocked mutex returns an error. */ retval = pthread_mutex_unlock(tab_mutex[0]); ret = pthread_mutex_unlock(tab_mutex[1]); #if VERBOSE >0 output("Results for unlock issue #1:\n mutex 1 unlocking returned %i\n mutex 2 unlocking returned %i\n", retval, ret); #endif if (ret != retval) { FAILED("Unlocking an unlocked mutex behaves differently."); } /* Now we focus on unlocking a mutex lock by another thread */ for (i=0; i<2; i++) { p_mtx = tab_mutex[i]; tab_res[i][0]=0; tab_res[i][1]=0; tab_res[i][2]=0; #if VERBOSE >1 output("Creating thread (unlock)...\n"); #endif if ((ret = pthread_create(&thr, NULL, unlock_issue, NULL))) { UNRESOLVED(ret, "Unlock issue thread create"); } if ((ret = sem_wait(&semA))) { UNRESOLVED(errno, "Sem A wait failed for unlock issue."); } #if VERBOSE >1 output("Unlocking in parent...\n"); #endif retval = pthread_mutex_unlock(p_mtx); if ((ret = sem_post(&semB))) { UNRESOLVED(errno, "Sem B post failed for unlock issue."); } if ((ret=pthread_join(thr, &th_ret))) { UNRESOLVED(ret, "Join thread"); } #if VERBOSE >1 output("Thread joined successfully...\n"); #endif tab_res[i][0] = retval; } #if VERBOSE >0 output("Results for unlock issue #2:\n mutex 1 returned %i\n mutex 2 returned %i\n", tab_res[0][0],tab_res[1][0]); #endif if (tab_res[0][0] != tab_res[1][0]) { FAILED("Unlocking an unowned mutex behaves differently."); } /* We now are going to test the deadlock issue */ /* We start with testing the NULL mutex features */ for (i=0; i<2; i++) { p_mtx = tab_mutex[i]; tab_res[i][0]=0; tab_res[i][1]=0; tab_res[i][2]=0; #if VERBOSE >1 output("Creating thread (deadlk)...\n"); #endif if ((ret = pthread_create(&thr, NULL, deadlk_issue, NULL))) { UNRESOLVED(ret, "Deadlk_issue thread create"); } /* Now we are waiting the thread is ready to relock the mutex. */ if ((ret=sem_wait(&semA))) { UNRESOLVED(errno, "Sem wait"); } /* To ensure thread runs until second lock, we yield here */ sched_yield(); /* OK, now we cancel the thread */ canceled=0; #if VERBOSE >1 output("Cancel thread...\n"); #endif if (returned ==0) if ((ret=pthread_cancel(thr))) { UNRESOLVED(ret, "Cancel thread (deadlk_issue)"); } #if VERBOSE >1 output("Thread canceled...\n"); #endif if ((ret=pthread_join(thr, &th_ret))) { UNRESOLVED(ret, "Join thread"); } #if VERBOSE >1 output("Thread joined successfully...\n"); #endif tab_res[i][2] = retval; tab_res[i][1] = returned; tab_res[i][0] = canceled; } /* Now we parse the results */ #if VERBOSE >0 output("Results for deadlock issue:\n mutex 1 \t%s\t%s%i\n mutex 2 \t%s\t%s%i\n", tab_res[0][0]?"deadlock" : "no deadlock", tab_res[0][1]?"returned " : "did not return ", tab_res[0][2], tab_res[1][0]?"deadlock" : "no deadlock", tab_res[1][1]?"returned " : "did not return ", tab_res[1][2]); #endif if (tab_res[0][0] != tab_res[1][0]) { FAILED("One mutex deadlocks, not the other"); } if (tab_res[0][1] != tab_res[1][1]) { UNRESOLVED(tab_res[0][1], "Abnormal situation!"); } if ((tab_res[0][1] == 1) && (tab_res[0][2] != tab_res[1][2])) { FAILED("The locks returned different error codes."); } PASSED; } posixtestsuite/conformance/interfaces/pthread_mutex_init/1-2.c0100644000000000000000000002354310047321246023653 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertion: * * If the mutex attribute pointer passed to pthread_mutex_init is NULL, * the effects on the mutex are the same as if a default mutex attribute object had been passed. * * The steps are: * * create two mutexes. One is initialized with NULL attribute, the other with a default attribute object. * * Compare the following features between the two mutexes: * -> Can it cause / detect a deadlock? (attempt to lock a mutex the thread already owns). * If detected, do both mutexes cause the same error code? * -> Is an error returned when unlocking the mutex in unlocked state? * When unlocking the mutex owned by another thread? * * The test will pass if the results of each feature are the same for the two mutexes * (making no assumption on what is the default behavior). * The test will be unresolved if any initialization fails. * The test will fail if a feature differs between the two mutex objects. */ /* * - adam.li@intel.com 2004-05-09 * Add to PTS. Please refer to http://nptl.bullopensource.org/phpBB/ * for general information */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /********************************************************************************************/ /****************************** standard includes *****************************************/ /********************************************************************************************/ #include #include #include #include #include #include #include /********************************************************************************************/ /****************************** Test framework *****************************************/ /********************************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /********************************************************************************************/ /********************************** Configuration ******************************************/ /********************************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif /********************************************************************************************/ /*********************************** Test case *****************************************/ /********************************************************************************************/ /**** global variables ****/ pthread_mutex_t * p_mtx; int retval = 0; int returned = 0; int canceled = 0; sem_t semA, semB; /***** Cancelation handlers *****/ void cleanup_deadlk(void * arg) { canceled = 1; pthread_mutex_unlock(p_mtx); } /***** Threads functions *****/ void * deadlk_issue(void * arg) { int ret, tmp; if ((ret=pthread_mutex_lock(p_mtx))) { UNRESOLVED(ret, "First mutex lock in deadlk_issue"); } pthread_cleanup_push(cleanup_deadlk, NULL); if ((ret = pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &tmp))) { UNRESOLVED(ret, "Set cancel type in deadlk_issue"); } if ((ret = pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &tmp))) { UNRESOLVED(ret, "Set cancel state in deadlk_issue"); } #if VERBOSE >1 output("Thread releases the semaphore...\n"); #endif if ((ret = sem_post(&semA))) { UNRESOLVED(errno, "Sem_post in deadlk_issue"); } returned = 0; retval = pthread_mutex_lock(p_mtx); returned = 1; if ((ret = pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &tmp))) { UNRESOLVED(ret, "Set cancel state in deadlk_issue"); } pthread_cleanup_pop(0); return NULL; } void * unlock_issue(void * arg) { int ret; #if VERBOSE >1 output("Locking in child...\n"); #endif if ((ret=pthread_mutex_lock(p_mtx))) { UNRESOLVED(ret, "First mutex lock in unlock_issue"); } if ((ret = sem_post(&semA))) { UNRESOLVED(errno, "Sem_post in unlock_issue"); } if ((ret = sem_wait(&semB))) { UNRESOLVED(errno, "Sem_wait in unlock_issue"); } if (retval != 0) /* parent thread failed to unlock the mutex) */ { #if VERBOSE >1 output("Unlocking in child...\n"); #endif if ((ret=pthread_mutex_unlock(p_mtx))) { FAILED("Mutex unlock returned an error but mutex is unlocked."); } } return NULL; } /***** main program *****/ int main(int argc, char *argv[]) { pthread_mutex_t mtx_null, mtx_def; pthread_mutexattr_t mattr; pthread_t thr; pthread_mutex_t * tab_mutex[2]={&mtx_null, &mtx_def}; int tab_res[2][3]={{0,0,0},{0,0,0}}; int ret; void * th_ret; int i; output_init(); #if VERBOSE >1 output("Test starting...\n"); #endif /* We first initialize the two mutexes. */ if ((ret=pthread_mutex_init(&mtx_null, NULL))) { UNRESOLVED(ret, "NULL mutex init"); } if ((ret=pthread_mutexattr_init(&mattr))) { UNRESOLVED(ret, "Mutex attribute init"); } if ((ret=pthread_mutex_init(&mtx_def, &mattr))) { UNRESOLVED(ret, "Default attribute mutex init"); } if ((ret=pthread_mutexattr_destroy(&mattr))) { UNRESOLVED(ret, "Mutex attribute destroy"); } if ((ret=sem_init(&semA, 0, 0))) { UNRESOLVED(errno, "Sem A init"); } if ((ret=sem_init(&semB, 0, 0))) { UNRESOLVED(errno, "Sem B init"); } #if VERBOSE >1 output("Data initialized...\n"); #endif /* OK let's go for the first part of the test : abnormals unlocking */ /* We first check if unlocking an unlocked mutex returns an error. */ retval = pthread_mutex_unlock(tab_mutex[0]); ret = pthread_mutex_unlock(tab_mutex[1]); #if VERBOSE >0 output("Results for unlock issue #1:\n mutex 1 unlocking returned %i\n mutex 2 unlocking returned %i\n", retval, ret); #endif if (ret != retval) { FAILED("Unlocking an unlocked mutex behaves differently."); } /* Now we focus on unlocking a mutex lock by another thread */ for (i=0; i<2; i++) { p_mtx = tab_mutex[i]; tab_res[i][0]=0; tab_res[i][1]=0; tab_res[i][2]=0; #if VERBOSE >1 output("Creating thread (unlock)...\n"); #endif if ((ret = pthread_create(&thr, NULL, unlock_issue, NULL))) { UNRESOLVED(ret, "Unlock issue thread create"); } if ((ret = sem_wait(&semA))) { UNRESOLVED(errno, "Sem A wait failed for unlock issue."); } #if VERBOSE >1 output("Unlocking in parent...\n"); #endif retval = pthread_mutex_unlock(p_mtx); if ((ret = sem_post(&semB))) { UNRESOLVED(errno, "Sem B post failed for unlock issue."); } if ((ret=pthread_join(thr, &th_ret))) { UNRESOLVED(ret, "Join thread"); } #if VERBOSE >1 output("Thread joined successfully...\n"); #endif tab_res[i][0] = retval; } #if VERBOSE >0 output("Results for unlock issue #2:\n mutex 1 returned %i\n mutex 2 returned %i\n", tab_res[0][0],tab_res[1][0]); #endif if (tab_res[0][0] != tab_res[1][0]) { FAILED("Unlocking an unowned mutex behaves differently."); } /* We now are going to test the deadlock issue */ /* We start with testing the NULL mutex features */ for (i=0; i<2; i++) { p_mtx = tab_mutex[i]; tab_res[i][0]=0; tab_res[i][1]=0; tab_res[i][2]=0; #if VERBOSE >1 output("Creating thread (deadlk)...\n"); #endif if ((ret = pthread_create(&thr, NULL, deadlk_issue, NULL))) { UNRESOLVED(ret, "Deadlk_issue thread create"); } /* Now we are waiting the thread is ready to relock the mutex. */ if ((ret=sem_wait(&semA))) { UNRESOLVED(errno, "Sem wait"); } /* To ensure thread runs until second lock, we yield here */ sched_yield(); /* OK, now we cancel the thread */ canceled=0; #if VERBOSE >1 output("Cancel thread...\n"); #endif if (returned ==0) if ((ret=pthread_cancel(thr))) { UNRESOLVED(ret, "Cancel thread (deadlk_issue)"); } #if VERBOSE >1 output("Thread canceled...\n"); #endif if ((ret=pthread_join(thr, &th_ret))) { UNRESOLVED(ret, "Join thread"); } #if VERBOSE >1 output("Thread joined successfully...\n"); #endif tab_res[i][2] = retval; tab_res[i][1] = returned; tab_res[i][0] = canceled; } /* Now we parse the results */ #if VERBOSE >0 output("Results for deadlock issue:\n mutex 1 \t%s\t%s%i\n mutex 2 \t%s\t%s%i\n", tab_res[0][0]?"deadlock" : "no deadlock", tab_res[0][1]?"returned " : "did not return ", tab_res[0][2], tab_res[1][0]?"deadlock" : "no deadlock", tab_res[1][1]?"returned " : "did not return ", tab_res[1][2]); #endif if (tab_res[0][0] != tab_res[1][0]) { FAILED("One mutex deadlocks, not the other"); } if (tab_res[0][1] != tab_res[1][1]) { UNRESOLVED(tab_res[0][1], "Abnormal situation!"); } if ((tab_res[0][1] == 1) && (tab_res[0][2] != tab_res[1][2])) { FAILED("The locks returned different error codes."); } PASSED; } posixtestsuite/conformance/interfaces/pthread_mutex_init/assertions.xml0100644000000000000000000000347407621015461026130 0ustar rootroot The function int pthread_mutex_init(pthread_mutex_t *restrict mutex, const pthread_mutexattr_t *restrict attr); pthread_mutex_t = PHTREAD_MUTEX_INITIALIZER initializes a mutex referenced by 'mutex' with attributes specified by 'attr'. If 'attr' is NULL, the default mutex attributes are used. The effect shall be the same as passing the address of a default mutex attributes object. Upon successful initialization, the state of the mutex becomes initialized and unlocked. Attempting to initialize an already intialized mutex results in undefined behavior. In cases where default mutex attributes are appropriate, the macro PTHREAD_MUTEX_INITIALIZER can be used to intiailize mutexes that are statically allocated. The effect shall be equivilant to dynamic intialization by a call to pthread_mutex_init() with paramter 'attr' specified as NULL, except that no error checks are performed. Upon success, it returns a 0; It SHALL fail if: -[EAGAIN] The system lacked the neccessary resources (other than memory) to intialize another mutex. -[ENOMEM] Insufficient memory exists to initialize the mutex. -[EPERM] The caller does not have the privilage to perform the operation. It MAY fail if: -[EBUSY] The implementation has detected an attempt to reinitialize the object referenced by 'mutex', a previously intialized, but not yet destroyed, mutex. -[EINVAL] The value specified by 'attr' is invalid. It shall not return [EINTR] posixtestsuite/conformance/interfaces/pthread_mutex_init/coverage.txt0100644000000000000000000000036510050636576025552 0ustar rootrootThis document defines the coverage for the pthread_mutex_init function: Assertion Tested? 1 YES 2 YES 3 YES 4 YES 5 YES 5-1.c: Test for ENOMEM 5-3.c: Test for EINTR speculative/5-2.c: Test for EPERM. Not available on Linux. NOTE: posixtestsuite/conformance/interfaces/pthread_mutex_init/testfrmw.h0100644000000000000000000000427610047132143025232 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * * This file is a wrapper to use the tests from the NPTL Test & Trace Project * with either the Linux Test Project or the Open POSIX Test Suite. * The following macros are defined here: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate without calling one of those macros. * * */ #include "posixtest.h" #ifdef __GNUC__ /* We are using GCC */ #define UNRESOLVED(x, s) \ { output("Test %s unresolved: got %i on line %i (%s)\n", __FILE__, x, __LINE__, s); \ output_fini(); \ exit(PTS_UNRESOLVED); } #define FAILED(s) \ { output("Test %s FAILED: %s\n", __FILE__, s); \ output_fini(); \ exit(PTS_FAIL); } #define PASSED \ output_fini(); \ exit(PTS_PASS); #define UNTESTED(s) \ { output("File %s cannot test: %s\n", __FILE__, s); \ output_fini(); \ exit(PTS_UNTESTED); #else /* not using GCC */ #define UNRESOLVED(x, s) \ { output("Test unresolved: got %i on line %i (%s)\n", x, __LINE__, s); \ output_fini(); \ exit(PTS_UNRESOLVED); } #define FAILED(s) \ { output("Test FAILED: %s\n", s); \ output_fini(); \ exit(PTS_FAIL); } #define PASSED \ output_fini(); \ exit(PTS_PASS); #define UNTESTED(s) \ { output("Unable to test: %s\n", s); \ output_fini(); \ exit(PTS_UNTESTED); #endif posixtestsuite/conformance/interfaces/pthread_mutex_init/5-3.c0100644000000000000000000002120210047132143023642 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * * This sample test aims to check the following assertion: * The function does not return an error code of EINTR * The steps are: * * -> Create a thread which loops on pthread_mutex_init and pthread_mutex_destroy * operations. * -> Create another thread which loops on sending a signal to the first thread. * * */ /* - adam.li@intel.com 2004.05.08 * Add to PTS. Please refer to http://nptl.bullopensource.org/phpBB/ * for general information */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /* We enable the following line to have mutex attributes defined */ #ifndef WITHOUT_XOPEN #define _XOPEN_SOURCE 600 #endif /********************************************************************************************/ /****************************** standard includes *****************************************/ /********************************************************************************************/ #include #include #include #include #include #include #include #include /********************************************************************************************/ /****************************** Test framework *****************************************/ /********************************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /********************************************************************************************/ /********************************** Configuration ******************************************/ /********************************************************************************************/ #define WITH_SYNCHRO #ifndef VERBOSE #define VERBOSE 2 #endif /********************************************************************************************/ /*********************************** Test case *****************************************/ /********************************************************************************************/ char do_it=1; unsigned long count_ope=0; pthread_mutex_t count_protect = PTHREAD_MUTEX_INITIALIZER; #ifdef WITH_SYNCHRO sem_t semsig1; sem_t semsig2; unsigned long count_sig=0; #endif sem_t semsync; typedef struct { pthread_t *thr; int sig; #ifdef WITH_SYNCHRO sem_t *sem; #endif } thestruct; /* the following function keeps on sending the signal to the thread pointed by arg * If WITH_SYNCHRO is defined, the target thread has a handler for the signal */ void * sendsig (void * arg) { thestruct *thearg = (thestruct *) arg; int ret; while (do_it) { #ifdef WITH_SYNCHRO if ((ret = sem_wait(thearg->sem))) { UNRESOLVED(errno, "Sem_wait in sendsig"); } count_sig++; #endif if ((ret = pthread_kill (*(thearg->thr), thearg->sig))) { UNRESOLVED(ret, "Pthread_kill in sendsig"); } } return NULL; } /* Next are the signal handlers. */ void sighdl1(int sig) { #ifdef WITH_SYNCHRO if (sem_post(&semsig1)) { UNRESOLVED(errno, "Sem_post in signal handler 1"); } #endif } void sighdl2(int sig) { #ifdef WITH_SYNCHRO if (sem_post(&semsig2)) { UNRESOLVED(errno, "Sem_post in signal handler 2"); } #endif } /* The following function loops on init/destroy some mutex (with different attributes) * it does check that no error code of EINTR is returned */ void * threaded(void * arg) { pthread_mutexattr_t ma[4], *pma[5]; pthread_mutex_t m[5]; int i; int ret; /* We need to register the signal handlers */ struct sigaction sa; sigemptyset (&sa.sa_mask); sa.sa_flags = 0; sa.sa_handler = sighdl1; if ((ret = sigaction (SIGUSR1, &sa, NULL))) { UNRESOLVED(ret, "Unable to register signal handler1"); } sa.sa_handler = sighdl2; if ((ret = sigaction (SIGUSR2, &sa, NULL))) { UNRESOLVED(ret, "Unable to register signal handler2"); } /* Initialize the different mutex attributes */ pma[4]=NULL; for (i=0; i<4; i++) { pma[i]=&ma[i]; if ((ret = pthread_mutexattr_init(pma[i]))) { UNRESOLVED(ret, "pthread_mutexattr_init"); } } #ifndef WITHOUT_XOPEN if ((ret = pthread_mutexattr_settype(pma[0], PTHREAD_MUTEX_NORMAL))) { UNRESOLVED(ret, "pthread_mutexattr_settype (normal)"); } if ((ret = pthread_mutexattr_settype(pma[1], PTHREAD_MUTEX_ERRORCHECK))) { UNRESOLVED(ret, "pthread_mutexattr_settype (errorcheck)"); } if ((ret = pthread_mutexattr_settype(pma[2], PTHREAD_MUTEX_RECURSIVE))) { UNRESOLVED(ret, "pthread_mutexattr_settype (recursive)"); } if ((ret = pthread_mutexattr_settype(pma[3], PTHREAD_MUTEX_DEFAULT))) { UNRESOLVED(ret, "pthread_mutexattr_settype (default)"); } #if VERBOSE >1 output("Mutex attributes NORMAL,ERRORCHECK,RECURSIVE,DEFAULT initialized\n"); #endif #else #if VERBOSE > 0 output("Mutex attributes NORMAL,ERRORCHECK,RECURSIVE,DEFAULT unavailable\n"); #endif #endif /* We are ready to proceed */ while (do_it) { for (i=0; i<5; i++) { ret = pthread_mutex_init(&m[i], pma[i]); if (ret == EINTR) { FAILED("pthread_mutex_init returned EINTR"); } if (ret != 0) { UNRESOLVED(ret, "pthread_mutex_init failed"); } ret = pthread_mutex_destroy(&m[i]); if (ret == EINTR) { FAILED("pthread_mutex_destroy returned EINTR"); } if (ret != 0) { UNRESOLVED(ret, "pthread_mutex_destroy failed"); } pthread_mutex_lock(&count_protect); count_ope++; pthread_mutex_unlock(&count_protect); } } /* Now we can destroy the mutex attributes objects */ for (i=0; i<4; i++) { if ((ret = pthread_mutexattr_destroy(pma[i]))) { UNRESOLVED(ret, "pthread_mutexattr_init"); } } do { ret = sem_wait(&semsync); } while (ret && (errno == EINTR)); if (ret) { UNRESOLVED(errno, "Could not wait for sig senders termination"); } return NULL; } /* At last (but not least) we need a main */ int main (int argc, char * argv[]) { int ret; pthread_t th_work, th_sig1, th_sig2; thestruct arg1, arg2; output_init(); #ifdef WITH_SYNCHRO if (sem_init(&semsig1, 0, 1)) { UNRESOLVED(errno, "Semsig1 init"); } if (sem_init(&semsig2, 0, 1)) { UNRESOLVED(errno, "Semsig2 init"); } #endif if (sem_init(&semsync, 0, 0)) { UNRESOLVED(errno, "semsync init"); } if ((ret = pthread_create(&th_work, NULL, threaded, NULL))) { UNRESOLVED(ret, "Worker thread creation failed"); } arg1.thr = &th_work; arg2.thr = &th_work; arg1.sig = SIGUSR1; arg2.sig = SIGUSR2; #ifdef WITH_SYNCHRO arg1.sem = &semsig1; arg2.sem = &semsig2; #endif if ((ret = pthread_create(&th_sig1, NULL, sendsig, (void *)&arg1))) { UNRESOLVED(ret, "Signal 1 sender thread creation failed"); } if ((ret = pthread_create(&th_sig2, NULL, sendsig, (void *)&arg2))) { UNRESOLVED(ret, "Signal 2 sender thread creation failed"); } /* Let's wait for a while now */ sleep(1); /* Now stop the threads and join them */ do { do_it=0; } while (do_it); if ((ret = pthread_join(th_sig1, NULL))) { UNRESOLVED(ret, "Signal 1 sender thread join failed"); } if ((ret = pthread_join(th_sig2, NULL))) { UNRESOLVED(ret, "Signal 2 sender thread join failed"); } if (sem_post(&semsync)) { UNRESOLVED(errno, "could not post semsync"); } if ((ret = pthread_join(th_work, NULL))) { UNRESOLVED(ret, "Worker thread join failed"); } #if VERBOSE > 0 output("Test executed successfully.\n"); output(" %d mutex initialization and destruction were done.\n", count_ope); #ifdef WITH_SYNCHRO output(" %d signals were sent meanwhile.\n", count_sig); #endif #endif PASSED; } posixtestsuite/conformance/interfaces/pthread_mutex_init/2-1.c0100644000000000000000000000261707621015460023654 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: bing.wei.liu REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_mutex_init() * Upon successful initialization, the state of the mutex becomes * initialized and unlocked. * */ #include #include #include #include "posixtest.h" int main() { pthread_mutex_t mutex; int rc; /* Initialize a mutex object */ if((rc=pthread_mutex_init(&mutex,NULL)) != 0) { fprintf(stderr,"Fail to initialize mutex, rc=%d\n",rc); printf("Test FAILED\n"); return PTS_FAIL; } /* Acquire the mutex object using pthread_mutex_lock */ if((rc=pthread_mutex_lock(&mutex)) != 0) { fprintf(stderr,"Fail to lock the mutex, rc=%d\n",rc); printf("Test FAILED\n"); return PTS_FAIL; } fprintf(stderr,"Main: hold the mutex for a while\n"); sleep(1); /* Release the mutex object using pthread_mutex_unlock */ if((rc=pthread_mutex_unlock(&mutex)) != 0) { fprintf(stderr,"Fail to unlock the mutex, rc=%d\n",rc); return PTS_UNRESOLVED; } /* Destory the mutex object */ if((rc=pthread_mutex_destroy(&mutex)) != 0) { fprintf(stderr,"Fail to destory the mutex, rc=%d\n",rc); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_mutex_init/3-1.c0100644000000000000000000000140007615426126023652 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: bing.wei.liu REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that the macro PTHREAD_MUTEX_INITIALIZER can be sued to intiailize * mutexes that are statically allocated. * */ #include #include #include #include "posixtest.h" typedef struct my_data { pthread_mutex_t mutex; /* Protects access to value */ int value; /* Access protected by mutex */ } my_data_t; my_data_t data = {PTHREAD_MUTEX_INITIALIZER, 0}; int main() { printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_attr_getdetachstate/0040755000000000000000000000000010515625176025053 5ustar rootrootposixtestsuite/conformance/interfaces/pthread_attr_getdetachstate/1-1.c0100644000000000000000000000254407607657156025532 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_attr_getdetachstate() * shall get the detachstate attribute in the 'attr' object. The detach state * is either PTHREAD_CREATE_DETACHED or PTHEAD_CREATE_JOINABLE. * * Steps: * 1. Initialize a pthread_attr_t object using pthread_attr_init() * 2. Using pthread_attr_getdetachstate(), get the detachstate of the * attribute object. It should be PTHREAD_CREATE_JOINABLE. * */ #include #include #include "posixtest.h" int main() { pthread_attr_t new_attr; int detach_state; /* Initialize attribute */ if(pthread_attr_init(&new_attr) != 0) { perror("Cannot initialize attribute object\n"); return PTS_UNRESOLVED; } /* The test passes if pthread_attr_getdetachstate gets the attribute * of PTHREAD_CREATE_JOINABLE from the attribute object. */ if(pthread_attr_getdetachstate(&new_attr, &detach_state) != 0) { printf("Test FAILED\n"); return PTS_FAIL; } if(detach_state == PTHREAD_CREATE_JOINABLE) { printf("Test PASSED\n"); return PTS_PASS; } else { printf("Test FAILED\n"); return PTS_FAIL; } } posixtestsuite/conformance/interfaces/pthread_attr_getdetachstate/1-2.c0100644000000000000000000000333607607657157025534 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_attr_getdetachstate() * shall get the detachstate attribute in the 'attr' object. The detach state * is either PTHREAD_CREATE_DETACHED or PTHEAD_CREATE_JOINABLE. * * Steps: * 1. Initialize a pthread_attr_t object using pthread_attr_init(), this will * make detachstate be PTHREAD_CREATE_JOINABLE. * 2. Use pthread_attr_setdetachstate() to set the attribute to * PTHREAD_CREATE_DETACHED. * 3. Using pthread_attr_getdetachstate(), get the detachstate of the * attribute object, is should be PTHREAD_CREATE_DETACHED. * * */ #include #include #include "posixtest.h" int main() { pthread_attr_t new_attr; int detach_state; /* Initialize attribute */ if(pthread_attr_init(&new_attr) != 0) { perror("Cannot initialize attribute object\n"); return PTS_UNRESOLVED; } /* Set the detachstate to PTHREAD_CREATE_DETACHED. */ if(pthread_attr_setdetachstate(&new_attr, PTHREAD_CREATE_DETACHED) != 0) { perror("Error in pthread_attr_setdetachstate()\n"); return PTS_UNRESOLVED; } /* The test passes if pthread_attr_getdetachstate gets the attribute * of PTHREAD_CREATE_DETACHED from the attribute object. */ if(pthread_attr_getdetachstate(&new_attr, &detach_state) != 0) { printf("Test FAILED\n"); return PTS_FAIL; } if(detach_state == PTHREAD_CREATE_DETACHED) { printf("Test PASSED\n"); return PTS_PASS; } else { printf("Test FAILED\n"); return PTS_FAIL; } } posixtestsuite/conformance/interfaces/pthread_attr_getdetachstate/assertions.xml0100644000000000000000000000065507621010552027760 0ustar rootroot The function int pthread_attr_getdetachstate(const pthread_attr_t *attr, int *detachstate) will get the detachstate attribute in the 'attr' object. The detach state can be either PTHREAD_CREATE_DETACHED or PTHEAD_CREATE_JOINABLE. If success, it returns 0. posixtestsuite/conformance/interfaces/pthread_attr_getdetachstate/coverage.txt0100644000000000000000000000017107607657157027417 0ustar rootrootThis document defines the coverage for the pthread_attr_getdetachstate function: Assertion Tested? 1 YES 2 YES NOTE: posixtestsuite/conformance/interfaces/pthread_attr_getdetachstate/2-1.sh0100755000000000000000000000071607607657157025726 0ustar rootroot#!/bin/sh # Copyright (c) 2002, Intel Corporation. All rights reserved. # Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com # This file is licensed under the GPL license. For the full content # of this license, see the COPYING file at the top level of this # source tree. # Test pthread_attr_getdetachstate returns 0 on success. # This is tested implicitly via assertion 1. echo "Tested implicitly via assertion 1. See output for status" exit 0 posixtestsuite/conformance/interfaces/pthread_mutexattr_settype/0040755000000000000000000000000010515625222024632 5ustar rootrootposixtestsuite/conformance/interfaces/pthread_mutexattr_settype/1-1.c0100644000000000000000000000477707656314600025317 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: bing.wei.liu REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test pthread_mutexattr_settype() * int pthread_mutexattr_settype(pthread_mutexattr_t *attr, int type); * Sets the mutex 'type' attribute. This attribute is set in the 'type' parameter to * these functions. The default value is PTHREAD_MUTEX_DEFAULT. */ #define _XOPEN_SOURCE 600 #include #include #include #include "posixtest.h" int main() { pthread_mutexattr_t mta; int type; /* Initialize a mutex attributes object */ if(pthread_mutexattr_init(&mta) != 0) { perror("Error at pthread_mutexattr_init()\n"); return PTS_UNRESOLVED; } if(pthread_mutexattr_gettype(&mta, &type) != 0) { printf("Error getting the attribute 'type'\n"); return PTS_UNRESOLVED; } if(type != PTHREAD_MUTEX_DEFAULT) { printf("Test FAILED: Default value of the 'type' attribute is not PTHREAD_MUTEX_DEFAULT \n"); return PTS_FAIL; } if(pthread_mutexattr_settype(&mta, PTHREAD_MUTEX_NORMAL) != 0) { printf("Test FAILED: Error setting the attribute 'type'\n"); return PTS_FAIL; } if(pthread_mutexattr_gettype(&mta, &type) != 0) { printf("Error getting the attribute 'type'\n"); return PTS_UNRESOLVED; } if(type != PTHREAD_MUTEX_NORMAL) { printf("Test FAILED: Type not correct get/set \n"); return PTS_FAIL; } if(pthread_mutexattr_settype(&mta, PTHREAD_MUTEX_ERRORCHECK) != 0) { printf("Test FAILED: Error setting the attribute 'type'\n"); return PTS_FAIL; } if(pthread_mutexattr_gettype(&mta, &type) != 0) { printf("Error getting the attribute 'type'\n"); return PTS_UNRESOLVED; } if(type != PTHREAD_MUTEX_ERRORCHECK) { printf("Test FAILED: Type not correct get/set \n"); return PTS_FAIL; } if(pthread_mutexattr_settype(&mta, PTHREAD_MUTEX_RECURSIVE) != 0) { printf("Test FAILED: Error setting the attribute 'type'\n"); return PTS_FAIL; } if(pthread_mutexattr_gettype(&mta, &type) != 0) { printf("Error getting the attribute 'type'\n"); return PTS_UNRESOLVED; } if(type != PTHREAD_MUTEX_RECURSIVE) { printf("Test FAILED: Type not correct get/set \n"); return PTS_FAIL; } if(pthread_mutexattr_destroy(&mta) != 0) { printf("Error at pthread_mutexattr_destroy()\n"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_mutexattr_settype/3-2.c0100644000000000000000000000542507712042441025303 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: bing.wei.liu REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test pthread_mutexattr_settype() * * PTHREAD_MUTEX_ERRORCHECK * Provides errorchecking. A thread attempting to relock this mutex without unlocking it * first will return with an error. A thread attempting to unlock a mutex which another * thread has locked will return with an error. A thread attempting to unlock an unlocked * mutex will return with an error. * * Steps: * 1. Initialize a pthread_mutexattr_t object with pthread_mutexattr_init() * 2 Set the 'type' of the mutexattr object to PTHREAD_MUTEX_ERRORCHECK. * 3. Create a mutex with that mutexattr object. * 4. Lock the mutex. * 5. Create a thread, and in that thread, attempt to unlock the mutex. It should return an * error. * */ #define _XOPEN_SOURCE 600 #include #include #include #include "posixtest.h" pthread_t thread1; pthread_mutex_t mutex; pthread_mutexattr_t mta; int ret; /* Return value of the thread unlocking the mutex. */ void *a_thread_func() { /* Try to unlock the mutex that main already locked. */ ret=pthread_mutex_unlock(&mutex); pthread_exit((void*)0); } int main() { /* Initialize a mutex attributes object */ if(pthread_mutexattr_init(&mta) != 0) { perror("Error at pthread_mutexattr_init()\n"); return PTS_UNRESOLVED; } /* Set the 'type' attribute to be PTHREAD_MUTEX_ERRORCHECK */ if(pthread_mutexattr_settype(&mta, PTHREAD_MUTEX_ERRORCHECK) != 0) { printf("Test FAILED: Error setting the attribute 'type'\n"); return PTS_FAIL; } /* Initialize the mutex with that attribute obj. */ if(pthread_mutex_init(&mutex, &mta) != 0) { perror("Error intializing the mutex.\n"); return PTS_UNRESOLVED; } /* Lock the mutex. */ if(pthread_mutex_lock(&mutex) != 0 ) { perror("Error locking the mutex first time around.\n"); return PTS_UNRESOLVED; } /* Create the thread that will try to unlock the mutex we just locked. */ if(pthread_create(&thread1, NULL, a_thread_func, NULL) != 0) { perror("Error creating a thread.\n"); return PTS_UNRESOLVED; } /* Wait for that thread to end execution */ pthread_join(thread1, NULL); if(ret == 0) { printf("Test FAILED: Expected an error when trying to unlock a mutex that was locked by another thread. Returned 0 instead.\n"); return PTS_FAIL; } /* cleanup */ pthread_mutex_unlock(&mutex); pthread_mutex_destroy(&mutex); if(pthread_mutexattr_destroy(&mta)) { perror("Error at pthread_mutexattr_destory().\n"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_mutexattr_settype/7-1.c0100644000000000000000000000271307656314601025312 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: bing.wei.liu REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test pthread_mutexattr_settype() * * It shall fail if: * [EINVAL] - The value 'type' is invalid. * It may fail if: * [EINVAL] - The value specified by 'attr' is invalid. * * Steps: * 1. Initialize a pthread_mutexattr_t object. * 2. Pass to pthread_mutexattr_settype an invalid type. It shall fail. * */ #define _XOPEN_SOURCE 600 #include #include #include #include "posixtest.h" int main() { pthread_mutexattr_t mta; int ret; int invalid_type = -1; /* Initialize a mutex attributes object */ if(pthread_mutexattr_init(&mta) != 0) { perror("Error at pthread_mutexattr_init()\n"); return PTS_UNRESOLVED; } while(invalid_type == PTHREAD_MUTEX_NORMAL || invalid_type == PTHREAD_MUTEX_ERRORCHECK || invalid_type == PTHREAD_MUTEX_RECURSIVE || invalid_type == PTHREAD_MUTEX_DEFAULT) { invalid_type --; } /* Set the 'type' attribute to be a negative number. */ ret=pthread_mutexattr_settype(&mta, invalid_type); if (ret != EINVAL) { printf("Test FAILED: Expected return code of EINVAL, got: %d\n", ret); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_mutexattr_settype/assertions.xml0100644000000000000000000000360110054547406027550 0ustar rootroot The function int pthread_mutexattr_settype(pthread_mutexattr_t *attr, int type); Sets the mutex 'type' attribute. This attribute is set in the 'type' parameter to these functions. The default value is PTHREAD_MUTEX_DEFAULT. PTHREAD_MUTEX_NORMAL This type of mutex doesn't detect deadlock. So a thread attempting to relock this mutex without unlocking it first will deadllock. Attempting to unlock a mutex locked by a different thread results in undefined behavior. Attemping to unlock an unlocked mutex results in undefined behavior. PTHREAD_MUTEX_ERRORCHECK Provides errorchecking. A thread attempting to relock this mutex without unlocking it first will return with an error. A thread attempting to unlock a mutex which another thread has locked will return with an error. A thread attempting to unlock an unlocked mutex will return with an error. PTHREAD_MUTEX_DEFAULT Attempting to recursively lock a mutex of this type will result in undefined behavior. Attempting to unlock a mutex of this type which was not locked by the calling thread results in undefined behavior. Attempting to unlock a mutex of this type which is locked results in undefined behavior. An implementation may map this mutex to one of the other mutex types. It returns 0 upon success. It shall fail if: [EINVAL] - The value 'type' is invalid. It may fail if: [EINVAL] - The value specified by 'attr' is invalid. It shall not return an error code of [EINTR]. posixtestsuite/conformance/interfaces/pthread_mutexattr_settype/coverage.txt0100644000000000000000000000051610054547406027172 0ustar rootrootThis document defines the coverage for the pthread_mutexattr_settype function: Assertion Tested? 1 YES 2 YES 3 YES 4 NO **Removed, since duplicate with assertion **in pthread_mutex_lock:4 and pthread_mutex_unlock:5 5 NO **Will not test because all behavior is undefined. 6 YES 7 YES NOTE: posixtestsuite/conformance/interfaces/pthread_mutexattr_settype/3-3.c0100644000000000000000000000366507640470511025313 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: bing.wei.liu REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test pthread_mutexattr_settype() * PTHREAD_MUTEX_ERRORCHECK Provides errorchecking. A thread attempting to relock this mutex without unlocking it first will return with an error. A thread attempting to unlock a mutex which another thread has locked will return with an error. A thread attempting to unlock an unlocked mutex will return with an error. * * Steps: * 1. Initialize a pthread_mutexattr_t object with pthread_mutexattr_init() * 2 Set the 'type' of the mutexattr object to PTHREAD_MUTEX_ERRORCHECK. * 3. Create a mutex with that mutexattr object. * 4. Attempt to unlock it without locking it first. It should return an error. * */ #define _XOPEN_SOURCE 600 #include #include #include #include "posixtest.h" int main() { pthread_mutex_t mutex; pthread_mutexattr_t mta; /* Initialize a mutex attributes object */ if(pthread_mutexattr_init(&mta) != 0) { perror("Error at pthread_mutexattr_init()\n"); return PTS_UNRESOLVED; } /* Set the 'type' attribute to be PTHREAD_MUTEX_ERRORCHECK */ if(pthread_mutexattr_settype(&mta, PTHREAD_MUTEX_ERRORCHECK) != 0) { printf("Test FAILED: Error setting the attribute 'type'\n"); return PTS_FAIL; } /* Initialize the mutex with that attribute obj. */ if(pthread_mutex_init(&mutex, &mta) != 0) { perror("Error intializing the mutex.\n"); return PTS_UNRESOLVED; } /* Unlock an already unlocked mutex. Here, an error should be returned. */ if(pthread_mutex_unlock(&mutex) == 0 ) { perror("Test FAILED: Did not return error when unlocking an already unlocked mutex.\n"); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_mutexattr_settype/3-4.c0100644000000000000000000000461107656314601025310 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: bing.wei.liu REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test pthread_mutexattr_settype() * PTHREAD_MUTEX_ERRORCHECK Provides errorchecking. A thread attempting to relock this mutex without unlocking it first will return with an error. A thread attempting to unlock a mutex which another thread has locked will return with an error. A thread attempting to unlock an unlocked mutex will return with an error. * * Steps: * 1. Initialize a pthread_mutexattr_t object with pthread_mutexattr_init() * 2 Set the 'type' of the mutexattr object to PTHREAD_MUTEX_ERRORCHECK. * 3. Create a mutex with that mutexattr object. * 4. Attempt to unlock an unlocked mutex. It should return an error. * */ #define _XOPEN_SOURCE 600 #include #include #include #include "posixtest.h" int main() { pthread_mutex_t mutex; pthread_mutexattr_t mta; /* Initialize a mutex attributes object */ if(pthread_mutexattr_init(&mta) != 0) { perror("Error at pthread_mutexattr_init()\n"); return PTS_UNRESOLVED; } /* Set the 'type' attribute to be PTHREAD_MUTEX_ERRORCHECK */ if(pthread_mutexattr_settype(&mta, PTHREAD_MUTEX_ERRORCHECK) != 0) { printf("Test FAILED: Error setting the attribute 'type'\n"); return PTS_FAIL; } /* Initialize the mutex with that attribute obj. */ if(pthread_mutex_init(&mutex, &mta) != 0) { perror("Error intializing the mutex.\n"); return PTS_UNRESOLVED; } if(pthread_mutex_lock(&mutex) != 0) { perror("Error at pthread_mutex_lock().\n"); return PTS_UNRESOLVED; } if(pthread_mutex_unlock(&mutex) != 0) { perror("Error at pthread_mutex_unlock().\n"); return PTS_UNRESOLVED; } /* Unlock an already unlocked mutex. Here, an error should be returned. */ if(pthread_mutex_unlock(&mutex) == 0 ) { perror("Test FAILED: Did not return error when unlocking an already unlocked mutex.\n"); return PTS_FAIL; } if(pthread_mutex_destroy(&mutex)) { perror("Error at pthread_mutex_destory().\n"); return PTS_UNRESOLVED; } if(pthread_mutexattr_destroy(&mta)) { perror("Error at pthread_mutexattr_destory().\n"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_mutexattr_settype/2-1.c0100644000000000000000000000441310041637741025277 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: bing.wei.liu REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test pthread_mutexattr_settype() * * PTHREAD_MUTEX_NORMAL * This type of mutex doesn't detect deadlock. So a thread attempting to relock this mutex * without unlocking it first will not return an error. Attempting to unlock a mutex locked * by a different thread results in undefined behavior. Attemping to unlock an unlocked mutex * results in undefined behavior. * * Steps: * 1. Initialize a pthread_mutexattr_t object with pthread_mutexattr_init() * 2 Set the 'type' of the mutexattr object to PTHREAD_MUTEX_NORMAL. * 3. Create a mutex with that mutexattr object. * 4. Lock the mutex, then relock it. Expect dead lock. Timer will be use * to interrupt the deadlock. */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include "posixtest.h" void alarm_handler(int signo) { printf("Got SIGALRM after 1 second\n"); printf("Test PASSED\n"); exit(PTS_PASS); } int main() { pthread_mutex_t mutex; pthread_mutexattr_t mta; int ret; /* Initialize a mutex attributes object */ if(pthread_mutexattr_init(&mta) != 0) { perror("Error at pthread_mutexattr_init()\n"); return PTS_UNRESOLVED; } /* Set the 'type' attribute to be PTHREAD_MUTEX_NORMAL */ if(pthread_mutexattr_settype(&mta, PTHREAD_MUTEX_NORMAL) != 0) { printf("Test FAILED: Error setting the attribute 'type'\n"); return PTS_FAIL; } /* Initialize the mutex with that attribute obj. */ if(pthread_mutex_init(&mutex, &mta) != 0) { perror("Error intializing the mutex.\n"); return PTS_UNRESOLVED; } ret=pthread_mutex_lock(&mutex); if(ret != 0) { printf("Test Unresolved: Error at pthread_mutex_lock, " "error code %d\n", ret); return PTS_UNRESOLVED; } signal(SIGALRM, alarm_handler); alarm(1); /* This lock will cause deadlock */ ret=pthread_mutex_lock(&mutex); /* We should not get here */ printf("Relock the mutex did not get deadlock\n"); printf("Test FAILED\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/pthread_mutexattr_settype/6-1.sh0100755000000000000000000000104707640470511025477 0ustar rootroot#!/bin/sh # Copyright (c) 2002, Intel Corporation. All rights reserved. # Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com # This file is licensed under the GPL license. For the full content # of this license, see the COPYING file at the top level of this # source tree. # Test pthread_mutexattr_settype() # It returns 0 upon success. # This is tested implicitly via assertion 2,3 and 4 of pthread_mutexattr_settype. echo "Tested implicitly via assertions 2,3 and 4 of pthread_mutexattr_settype(). See output for status" exit 0 posixtestsuite/conformance/interfaces/pthread_mutexattr_settype/3-1.c0100644000000000000000000000442507712042441025301 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: bing.wei.liu REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test pthread_mutexattr_settype() * * PTHREAD_MUTEX_ERRORCHECK * Provides errorchecking. A thread attempting to relock this mutex without unlocking it * first will return with an error. A thread attempting to unlock a mutex which another * thread has locked will return with an error. A thread attempting to unlock an unlocked * mutex will return with an error. * * Steps: * 1. Initialize a pthread_mutexattr_t object with pthread_mutexattr_init() * 2 Set the 'type' of the mutexattr object to PTHREAD_MUTEX_ERRORCHECK. * 3. Create a mutex with that mutexattr object. * 4. Attempt to relock a mutex without unlocking it first. It should return an error. * */ #define _XOPEN_SOURCE 600 #include #include #include #include "posixtest.h" int main() { pthread_mutex_t mutex; pthread_mutexattr_t mta; /* Initialize a mutex attributes object */ if(pthread_mutexattr_init(&mta) != 0) { perror("Error at pthread_mutexattr_init()\n"); return PTS_UNRESOLVED; } /* Set the 'type' attribute to be PTHREAD_MUTEX_ERRORCHECK */ if(pthread_mutexattr_settype(&mta, PTHREAD_MUTEX_ERRORCHECK) != 0) { printf("Test FAILED: Error setting the attribute 'type'\n"); return PTS_FAIL; } /* Initialize the mutex with that attribute obj. */ if(pthread_mutex_init(&mutex, &mta) != 0) { perror("Error intializing the mutex.\n"); return PTS_UNRESOLVED; } /* Lock the mutex. */ if(pthread_mutex_lock(&mutex) != 0 ) { perror("Error locking the mutex first time around.\n"); return PTS_UNRESOLVED; } /* Lock the mutex again. Here, an error should be returned. */ if(pthread_mutex_lock(&mutex) == 0 ) { perror("Test FAILED: Did not return error when locking an already locked mutex.\n"); return PTS_FAIL; } /* cleanup */ pthread_mutex_unlock(&mutex); pthread_mutex_destroy(&mutex); if(pthread_mutexattr_destroy(&mta) != 0) { perror("Error at pthread_mutex_destroy()\n"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_rwlock_rdlock/0040755000000000000000000000000010515625223023660 5ustar rootrootposixtestsuite/conformance/interfaces/pthread_rwlock_rdlock/2-2.c0100644000000000000000000001715210033204323024314 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_rwlock_rdlock(pthread_rwlock_t *rwlock) * * If the Thread Execution Scheduling option is supported, * and the threads involved in the lock are executing with the * scheduling policies SCHED_FIFO or SCHED_RR, the calling thread shall not * acquire the lock if a writer holds the lock or if writers of * higher or equal priority are blocked on the lock; * otherwise, the calling thread shall acquire the lock. * * In this case, we test "equal priority writer block" * Steps: * We have three threads, main(also a reader), writer, reader * * 1. Main thread set its shcedule policy as "SCHED_FIFO", with highest priority * the three: sched_get_priority_min()+2. * 2. Main thread read lock 'rwlock' * 3. Create a writer thread, with schedule policy as "SCHED_FIFO", and priority * using sched_get_priority_min()+1. * 4. The thread write lock 'rwlock', should block. * 5. Main thread create a reader thread, with schedule policy as "SCHED_FIFO", and * priority sched_get_priority_min()+1 * 6. Reader thread read lock 'rwlock', should block, since there is an equal priority * writer blocked on 'rwlock' * 7. Main thread release the 'rwlock', the writer should get the lock first */ /* NOTE: The test result is UNSUPPORTED if Thread Execution Scheduling option * is not supported. */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include "posixtest.h" #define TRD_POLICY SCHED_FIFO static pthread_rwlock_t rwlock; static int rd_thread_state; static int wr_thread_state; /* thread states: 1: not in child thread yet; 2: just enter child thread ; 3: just before child thread exit; */ #define NOT_CREATED_THREAD 1 #define ENTERED_THREAD 2 #define EXITING_THREAD 3 static int set_priority(pthread_t pid, unsigned policy, unsigned prio) { struct sched_param sched_param; memset(&sched_param, 0, sizeof(sched_param)); sched_param.sched_priority = prio; if (pthread_setschedparam(pid, policy, &sched_param) == -1) { printf("Can't set policy to %d and prio to %d\n", policy, prio); exit(PTS_UNRESOLVED); } return 0; } static void* fn_rd(void *arg) { int rc = 0; int priority; rd_thread_state = ENTERED_THREAD; priority = (long)arg; set_priority(pthread_self(), TRD_POLICY, priority); printf("rd_thread: attempt read lock\n"); rc = pthread_rwlock_rdlock(&rwlock); if(rc != 0) { printf("Test fail: rd_thread failed to get read lock, Error code:%d\n" , rc); exit(PTS_FAIL); } else printf("rd_thread: acquired read lock\n"); sleep(1); printf("rd_thread: unlock read lock\n"); if(pthread_rwlock_unlock(&rwlock) != 0) { printf("rd_thread: Error at pthread_rwlock_unlock()\n"); exit(PTS_UNRESOLVED); } rd_thread_state = EXITING_THREAD; pthread_exit(0); return NULL; } static void* fn_wr(void *arg) { int rc = 0; int priority; wr_thread_state = ENTERED_THREAD; priority = (long)arg; set_priority(pthread_self(), TRD_POLICY, priority); printf("wr_thread: attempt write lock\n"); rc = pthread_rwlock_wrlock(&rwlock); if(rc != 0) { printf("Test fail: wr_thread failed to get write lock, Error code:%d\n" , rc); exit(PTS_UNRESOLVED); } else printf("wr_thread: acquired write lock\n"); sleep(1); printf("wr_thread: unlock write lock\n"); if(pthread_rwlock_unlock(&rwlock) != 0) { printf("wr_thread: Error at pthread_rwlock_unlock()\n"); exit(PTS_UNRESOLVED); } wr_thread_state = EXITING_THREAD; pthread_exit(0); return NULL; } int main() { #ifndef _POSIX_THREAD_PRIORITY_SCHEDULING printf("Posix Thread Execution Scheduling not supported\n"); return PTS_UNSUPPORTED; #endif int cnt = 0; pthread_t rd_thread, wr_thread; int priority; /* main thread needs to have the highest priority*/ priority = sched_get_priority_min(TRD_POLICY) + 2; set_priority(pthread_self(), TRD_POLICY, priority); if(pthread_rwlock_init(&rwlock, NULL) != 0) { printf("main: Error at pthread_rwlock_init()\n"); return PTS_UNRESOLVED; } printf("main: attempt read lock\n"); /* We have no lock, this read lock should succeed */ if(pthread_rwlock_rdlock(&rwlock) != 0) { printf("Test FAILED: main cannot get read lock when no one owns the lock\n"); return PTS_FAIL; } else printf("main: acquired read lock\n"); wr_thread_state = NOT_CREATED_THREAD; priority = sched_get_priority_min(TRD_POLICY) + 1; printf("main: create wr_thread, with priority: %d\n", priority); if(pthread_create(&wr_thread, NULL, fn_wr, (void*)(long)priority) != 0) { printf("main: Error at 1st pthread_create()\n"); return PTS_UNRESOLVED; } /* If the shared data is not altered by child after 3 seconds, we regard it as blocked */ /* We expect the wr_thread to block */ cnt = 0; do{ sleep(1); }while (wr_thread_state !=EXITING_THREAD && cnt++ < 3); if(wr_thread_state == EXITING_THREAD ) { printf("wr_thread did not block on write lock, when a reader owns the lock\n"); exit(PTS_UNRESOLVED); } else if(wr_thread_state != ENTERED_THREAD) { printf("Unexpected wr_thread state: %d\n", wr_thread_state); exit(PTS_UNRESOLVED); } rd_thread_state = NOT_CREATED_THREAD; priority = sched_get_priority_min(TRD_POLICY) + 1; printf("main: create rd_thread, with priority: %d\n", priority); if(pthread_create(&rd_thread, NULL, fn_rd, (void*)(long)priority) != 0) { printf("main: failed at creating rd_thread\n"); return PTS_UNRESOLVED; } /* We expect the rd_thread to block*/ cnt = 0; do{ sleep(1); }while (rd_thread_state !=EXITING_THREAD && cnt++ < 3); if(rd_thread_state == EXITING_THREAD ) { printf("Test FAILED: rd_thread did not block on read lock, when a reader owns the lock, and an equal priority writer is waiting for the lock\n"); exit(PTS_FAIL); } else if(rd_thread_state != ENTERED_THREAD) { printf("Unexpected rd_thread state: %d\n", rd_thread_state); exit(PTS_UNRESOLVED); } printf("main: unlock read lock\n"); if(pthread_rwlock_unlock(&rwlock) != 0) { printf("main: failed to release read lock\n"); exit(PTS_UNRESOLVED); } /* we expect the writer get the lock */ cnt = 0; do{ sleep(1); }while (wr_thread_state !=EXITING_THREAD && cnt++ < 3); if(wr_thread_state == ENTERED_THREAD ) { printf("Test FAILED: higher priority wr_thread still blocked on write lock, when a reader released the lock\n"); exit(PTS_FAIL); } else if(wr_thread_state != EXITING_THREAD) { printf("Unexpected wr_thread state: %d\n", wr_thread_state); exit(PTS_UNRESOLVED); } if(pthread_join(wr_thread, NULL) != 0) { printf("main: Error at 1st pthread_join()\n"); exit(PTS_UNRESOLVED); } /* we expect the reader get the lock when writer has release the lock*/ cnt = 0; do{ sleep(1); }while (rd_thread_state !=EXITING_THREAD && cnt++ < 3); if(rd_thread_state == ENTERED_THREAD ) { printf("Test FAILED: rd_thread still blocked on read lock when the lock has no owner\n"); exit(PTS_FAIL); } else if(rd_thread_state != EXITING_THREAD) { printf("Unexpected rd_thread state: %d\n", rd_thread_state); exit(PTS_UNRESOLVED); } if(pthread_join(rd_thread, NULL) != 0) { printf("main: Error at 2nd pthread_join()\n"); exit(PTS_UNRESOLVED); } if(pthread_rwlock_destroy(&rwlock) != 0) { printf("Error at pthread_rwlockattr_destroy()"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_rwlock_rdlock/5-1.c0100644000000000000000000000272507671202056024335 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_rwlock_rdlock(pthread_rwlock_t *rwlock) * * A thread may hold multiple concurrent read locks on 'rwlock' and the application shall * ensure that the thread will perform matching unlocks for each read lock. * * Steps: * 1. Initialize a pthread_rwlock_t object 'rwlock' with pthread_rwlock_init() * 2. Main read locks 'rwlock' 10 times * 3. Main unlocks 'rwlock' 10 times. * */ #define _XOPEN_SOURCE 600 #include #include #include #include #include "posixtest.h" #define COUNT 10 int main() { static pthread_rwlock_t rwlock; int i; if(pthread_rwlock_init(&rwlock, NULL) != 0) { printf("main: Error at pthread_rwlock_init()\n"); return PTS_UNRESOLVED; } for(i=0;i < COUNT;i++) { if(pthread_rwlock_rdlock(&rwlock) != 0) { printf("Test FAILED: main cannot get read-lock rwlock number: %d\n", i); return PTS_FAIL; } } for(i = 0;i < COUNT;i++) { if(pthread_rwlock_unlock(&rwlock) != 0) { printf("Test FAILED: main cannot unlock rwlock number %d", i); return PTS_FAIL; } } if(pthread_rwlock_destroy(&rwlock) != 0) { printf("Error at pthread_rwlockattr_destroy()"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_rwlock_rdlock/4-1.c0100644000000000000000000001225007671434356024340 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test pthread_rwlock_rdlock(pthread_rwlock_t * rwlock) * * If a signal is delivered to a thread waiting for a read-write lock for reading, upon * return from the signal handler the thread resumes waiting for the read-write lock for * reading as if it was not interrupted. * * Steps: * 1. main thread create read-write lock 'rwlock', and lock it for writing * 2. main thread create a thread sig_thread, the thread is set to handle SIGUSR1 * 3. sig_thread try to lock 'rwlock' for reading but will block * 4. main thread sends SIGUSR1 to sig_thread via pthread_kill * 5. test that thread handler is called * 6. check that when thread handler returns, sig_thread resumes blocking for rwlock * 7. main thread unlock 'rwlock', sig_thread should get the lock */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include "posixtest.h" static pthread_t sig_thread; static pthread_rwlock_t rwlock; static int thread_state; static int handler_called; /* thread_state indicates child thread state: 1: not in child thread yet; 2: just enter child thread ; 3: just before child thread exit; */ #define NOT_CREATED_THREAD 1 #define ENTERED_THREAD 2 #define EXITING_THREAD 3 static void sig_handler() { if(pthread_equal(pthread_self(), sig_thread)) { printf("sig_handler: handled signal SIGUSR1\n"); handler_called = 1; } else { printf("signal is not handled by sig_thread\n"); exit(PTS_UNRESOLVED); } } static void * th_fn(void *arg) { struct sigaction act; int rc = 0; act.sa_flags = 0; act.sa_handler = sig_handler; /* Try to block all signals when handling SIGUSR1 */ sigfillset(&act.sa_mask); sigaction(SIGUSR1, &act, 0); thread_state = ENTERED_THREAD; printf("sig_thread: attemp read lock\n"); rc = pthread_rwlock_rdlock(&rwlock); if(rc != 0) { printf("Test FAILED: sig_thread: Error at pthread_rwlock_rdlock(), Error code=%d\n", rc); exit(PTS_FAIL); } else printf("sig_thread: acquired read lock\n"); printf("sig_thread: unlock read lock\n"); if(pthread_rwlock_unlock(&rwlock) != 0) { printf("sig_thread: Error release readlock\n"); exit(PTS_UNRESOLVED); } thread_state = EXITING_THREAD; pthread_exit(0); return NULL; } int main() { int cnt; handler_called = 0; if(pthread_rwlock_init(&rwlock, NULL) != 0) { printf("main: Error at pthread_rwlock_init()\n"); return PTS_UNRESOLVED; } printf("main: attempt write lock\n"); if(pthread_rwlock_wrlock(&rwlock) != 0) { printf("main: Error at pthread_rwlock_wrlock()\n"); return PTS_UNRESOLVED; } else printf("main: acquired write lock\n"); thread_state = NOT_CREATED_THREAD; if(pthread_create(&sig_thread, NULL, th_fn, NULL) != 0) { printf("main: Error at pthread_create()\n"); return PTS_UNRESOLVED; } /* wait at most 3 seconds for sig_thread to block*/ cnt = 0; do{ sleep(1); }while(thread_state != EXITING_THREAD && cnt++ < 3); if(thread_state == EXITING_THREAD) { printf("Test FAILED: thread did not block on read lock when a writer holds the lock\n"); exit(PTS_FAIL); } else if(thread_state != ENTERED_THREAD) { printf("Unexpected thread state: %d\n", thread_state); exit(PTS_UNRESOLVED); } /* sig_thread is blocking */ printf("main: fire SIGUSR1 to sig_thread\n"); if(pthread_kill(sig_thread, SIGUSR1) != 0) { printf("main: failed to send SIGUSER to sig_thread\n"); exit(PTS_UNRESOLVED); } /* wait at most 3 seconds for the signal to be handled */ cnt = 0; do{ sleep(1); }while(handler_called == 0 && cnt++ < 3); if(handler_called != 1) { printf("SIGUSR1 was not caught by sig_thread\n"); exit(PTS_UNRESOLVED); } /* sig_thread resume to block? */ cnt = 0; do{ sleep(1); }while(thread_state != EXITING_THREAD && cnt++ < 3); if(thread_state == EXITING_THREAD) { printf("Test FAILED: upon return from signal handler, sig_thread does not resume to block\n"); exit(PTS_FAIL); }else if(thread_state != ENTERED_THREAD) { printf("Unexpected thread state: %d\n", thread_state); exit(PTS_UNRESOLVED); } printf("sig_thread: correctly still blocking after signal handler returns\n"); printf("main: unlock write lock\n"); if(pthread_rwlock_unlock(&rwlock) != 0) { printf("main: Failed to release write lock\n"); exit(PTS_UNRESOLVED); } /* sig_thread got the read lock? */ cnt = 0; do{ sleep(1); }while(thread_state != EXITING_THREAD && cnt++ < 3); if(thread_state == ENTERED_THREAD) { printf("Test FAILED: sig_thread blocked on read lock when writer release the lock\n"); exit(PTS_FAIL); }else if(thread_state != EXITING_THREAD) { printf("Unexpected thread state: %d\n", thread_state); exit(PTS_UNRESOLVED); } if(pthread_join(sig_thread, NULL) != 0) { printf("main: failed at pthread_join()\n"); exit(PTS_UNRESOLVED); } if(pthread_rwlock_destroy(&rwlock) != 0) { printf("main: failed at pthread_rwlock_destroy()\n"); exit(PTS_UNRESOLVED); } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_rwlock_rdlock/1-1.c0100644000000000000000000001207007671202056024323 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_rwlock_rdlock(pthread_rwlock_t *rwlock) * * pthread_rwlock_rdlock( ) function shall apply a read lock to the * read-write lock referenced by rwlock. The calling thread acquires * the read lock if a writer does not hold the lock and there are * no writers blocked on the lock. * * NOTE: This case will not test whether a thread can get the read lock if * there are writers blocked on the lock -- it is implementation dependant. * * Steps: * 1. Initialize a pthread_rwlock_t object 'rwlock' with pthread_rwlock_init() * 2. Main thread read lock 'rwlock' * 3. Create a child thread. The thread read lock 'rwlock', should not block. Then unlock it. * 4. Main thread unlock 'rwlock' * 5. Main thread write lock 'rwlock' * 6. Create child thread to read lock 'rwlock', should block * 7. Main thread unlock 'rwlock' */ #define _XOPEN_SOURCE 600 #include #include #include #include #include "posixtest.h" static pthread_rwlock_t rwlock; static int thread_state; /* thread_state indicates child thread state: 1: not in child thread yet; 2: just enter child thread ; 3: just before child thread exit; */ #define NOT_CREATED_THREAD 1 #define ENTERED_THREAD 2 #define EXITING_THREAD 3 static void* fn_rd(void *arg) { int rc = 0; thread_state = ENTERED_THREAD; printf("rd_thread: attempt read lock\n"); rc = pthread_rwlock_rdlock(&rwlock); if(rc != 0) { printf("Test FAILED: rd_thread failed to get read lock, Error code:%d\n" , rc); exit(PTS_FAIL); } else printf("rd_thread: acquired read lock\n"); sleep(1); printf("rd_thread: unlock read lock\n"); if(pthread_rwlock_unlock(&rwlock) != 0) { printf("rd_thread: Error at pthread_rwlock_unlock()\n"); exit(PTS_UNRESOLVED); } thread_state = EXITING_THREAD; pthread_exit(0); return NULL; } int main() { int cnt = 0; pthread_t rd_thread1, rd_thread2; if(pthread_rwlock_init(&rwlock, NULL) != 0) { printf("main: Error at pthread_rwlock_init()\n"); return PTS_UNRESOLVED; } printf("main: attempt read lock\n"); /* We have no lock, this read lock should succeed */ if(pthread_rwlock_rdlock(&rwlock) != 0) { printf("Test FAILED: main cannot get read lock when no one owns the lock\n"); return PTS_FAIL; } else printf("main: acquired read lock\n"); thread_state = NOT_CREATED_THREAD; printf("main: create rd_thread1\n"); if(pthread_create(&rd_thread1, NULL, fn_rd, NULL) != 0) { printf("main: Error at 1st pthread_create()\n"); return PTS_UNRESOLVED; } /* If the shared data is not altered by child after 3 seconds, we regard it as blocked */ cnt = 0; do{ sleep(1); }while (thread_state !=EXITING_THREAD && cnt++ < 3); if(thread_state == ENTERED_THREAD) { /* the child thread started but blocked */ printf("Test FAILED: thread blocked on read lock, when a reader owns the lock\n"); exit(PTS_FAIL); } else if(thread_state != EXITING_THREAD) { printf("Unexpected thread state\n"); exit(PTS_UNRESOLVED); } printf("main: unlock read lock\n"); if(pthread_rwlock_unlock(&rwlock) != 0) { printf("main: failed to release read lock\n"); exit(PTS_UNRESOLVED); } if(pthread_join(rd_thread1, NULL) != 0) { printf("main: Error at 1st pthread_join()\n"); exit(PTS_UNRESOLVED); } /* Passed first part of the test, now for the second part. */ printf("main: attempt write lock\n"); if(pthread_rwlock_wrlock(&rwlock) != 0) { printf("main: failed to get write lock\n"); return PTS_UNRESOLVED; } else printf("main: acquired write lock\n"); thread_state = NOT_CREATED_THREAD; printf("main: create rd_thread2\n"); if(pthread_create(&rd_thread2, NULL, fn_rd, NULL) != 0) { printf("main: failed at 2nd pthread_create()\n"); return PTS_UNRESOLVED; } cnt = 0; /* Expect the child thread block on read lock */ do{ sleep(1); }while (thread_state !=EXITING_THREAD && cnt++ < 3); if(thread_state == EXITING_THREAD) { printf("Test FAILED: thread did not block on read lock when a writer holds the lock\n"); return PTS_FAIL; } else if(thread_state != ENTERED_THREAD) { printf("main: Unexpected thread state\n"); return PTS_UNRESOLVED; } printf("main: unlock write lock\n"); if(pthread_rwlock_unlock(&rwlock) != 0) { printf("main: failed to release write lock\n"); return PTS_UNRESOLVED; } /* We expected the child get the read lock and exit */ cnt = 1; do{ sleep(1); }while (thread_state !=EXITING_THREAD && cnt++ < 3); if(thread_state == ENTERED_THREAD) { printf("Test FAILED: thread blocked on read lock after the writer released the lock\n"); return PTS_FAIL; } else if(thread_state != EXITING_THREAD) { printf("main: Unexpected thread state\n"); return PTS_UNRESOLVED; } if(pthread_rwlock_destroy(&rwlock) != 0) { printf("Error at pthread_rwlockattr_destroy()"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_rwlock_rdlock/6-2.sh0100755000000000000000000000074610015271721024522 0ustar rootroot#!/bin/sh # Copyright (c) 2002, Intel Corporation. All rights reserved. # This file is licensed under the GPL license. For the full content # of this license, see the COPYING file at the top level of this # source tree. #If successful, the pthread_rwlock_rdlock( ) function shall return zero; otherwise, an error number #shall be returned to indicate the error. # This is tested implicitly via assertion 1. echo "Tested implicitly via assertion 1. See output for status" exit 0 posixtestsuite/conformance/interfaces/pthread_rwlock_rdlock/assertions.xml0100644000000000000000000000363407671202056026603 0ustar rootroot pthread_rwlock_rdlock( ) function shall apply a read lock to the read-write lock referenced by rwlock. The calling thread acquires the read lock if a writer does not hold the lock and there are no writers blocked on the lock. If the Thread Execution Scheduling option is supported, and the threads involved in the lock are executing with the scheduling policies SCHED_FIFO or SCHED_RR, the calling thread shall not acquire the lock if a writer holds the lock or if writers of higher or equal priority are blocked on the lock; otherwise, the calling thread shall acquire the lock. If the Threads Execution Scheduling option is supported, and the threads involved in the lock are executing with the SCHED_SPORADIC scheduling policy, the calling thread shall not acquire the lock if a writer holds the lock or if writers of higher or equal priority are blocked on the lock; otherwise, the calling thread shall acquire the lock. If a signal is delivered to a thread waiting for a read-write lock for reading, upon return from the signal handler the thread resumes waiting for the read-write lock for reading as if it was not interrupted. A thread may hold multiple concurrent read locks on 'rwlock' and the application shall ensure that the thread will perform matching unlocks for each read lock. If successful, the pthread_rwlock_rdlock( ) function shall return zero; otherwise, an error number shall be returned to indicate the error. These functions shall not return an error code of [EINTR]. posixtestsuite/conformance/interfaces/pthread_rwlock_rdlock/coverage.txt0100644000000000000000000000034307671202056026215 0ustar rootrootThis document defines the coverage for the pthread_rwlock_rdlock() function: Assertion Tested? 1 YES 2 YES ** Need support of Threads Execution Scheduling 3 NO: ** Need support of SCHED_SPORADIC 4 YES 5 YES 6 YES NOTE: posixtestsuite/conformance/interfaces/pthread_rwlock_rdlock/2-3.c0100644000000000000000000001603210033204323024311 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_rwlock_rdlock(pthread_rwlock_t *rwlock) * * If the Thread Execution Scheduling option is supported, * and the threads involved in the lock are executing with the * scheduling policies SCHED_FIFO or SCHED_RR, the calling thread shall not * acquire the lock if a writer holds the lock or if writers of * higher or equal priority are blocked on the lock; * otherwise, the calling thread shall acquire the lock. * * In this case, reader has higher priority than the writer * Steps: * We have three threads, main(also a reader), writer, reader * * 1. Main thread set its shcedule policy as "SCHED_FIFO", with highest priority * the three: sched_get_priority_min()+2. * 2. Main thread read lock 'rwlock' * 3. Create a writer thread, with schedule policy as "SCHED_FIFO", and priority * using sched_get_priority_min(). * 4. The thread write lock 'rwlock', should block. * 5. Main thread create a reader thread, with schedule policy as "SCHED_FIFO", and * priority sched_get_priority_min()+1 * 6. Reader thread read lock 'rwlock', shouldn't block, since it has a higher priority * than the writer blocked on 'rwlock' * 7. Main thread release the 'rwlock', the writer should get the lock first. */ /* NOTE: The test result is UNSUPPORTED if Thread Execution Scheduling option * is not supported. */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include "posixtest.h" #define TRD_POLICY SCHED_FIFO static pthread_rwlock_t rwlock; static int rd_thread_state; static int wr_thread_state; /* thread states: 1: not in thread yet; 2: just entered thread ; 3: just before thread exits; */ #define NOT_CREATED_THREAD 1 #define ENTERED_THREAD 2 #define EXITING_THREAD 3 static int set_priority(pthread_t pid, unsigned policy, unsigned prio) { struct sched_param sched_param; memset(&sched_param, 0, sizeof(sched_param)); sched_param.sched_priority = prio; if (pthread_setschedparam(pid, policy, &sched_param) == -1) { printf("Can't set policy to %d and prio to %d\n", policy, prio); exit(PTS_UNRESOLVED); } return 0; } static void* fn_rd(void *arg) { int rc = 0; int priority; rd_thread_state = ENTERED_THREAD; priority = (int)(long)arg; set_priority(pthread_self(), TRD_POLICY, priority); printf("rd_thread: attempt read lock\n"); rc = pthread_rwlock_rdlock(&rwlock); if(rc != 0) { printf("Test FAILED: rd_thread failed to get read lock, Error code:%d\n" , rc); exit(PTS_FAIL); } else printf("rd_thread: acquired read lock\n"); sleep(1); printf("rd_thread: unlock read lock\n"); if(pthread_rwlock_unlock(&rwlock) != 0) { printf("rd_thread: Error at pthread_rwlock_unlock()\n"); exit(PTS_UNRESOLVED); } rd_thread_state = EXITING_THREAD; pthread_exit(0); return NULL; } static void* fn_wr(void *arg) { int rc = 0; int priority; wr_thread_state = ENTERED_THREAD; priority = (long)arg; set_priority(pthread_self(), TRD_POLICY, priority); printf("wr_thread: attempt write lock\n"); rc = pthread_rwlock_wrlock(&rwlock); if(rc != 0) { printf("Test FAILED: wr_thread failed to get write lock, Error code:%d\n" , rc); exit(PTS_UNRESOLVED); } else printf("wr_thread: acquired write lock\n"); sleep(1); printf("wr_thread: unlock write lock\n"); if(pthread_rwlock_unlock(&rwlock) != 0) { printf("wr_thread: Error at pthread_rwlock_unlock()\n"); exit(PTS_UNRESOLVED); } wr_thread_state = EXITING_THREAD; pthread_exit(0); return NULL; } int main() { #ifndef _POSIX_THREAD_PRIORITY_SCHEDULING printf("Posix Thread Execution Scheduling not supported\n"); return PTS_UNSUPPORTED; #endif int cnt = 0; pthread_t rd_thread, wr_thread; int priority; /* main thread needs to have the highest priority*/ priority = sched_get_priority_min(TRD_POLICY) + 2; set_priority(pthread_self(), TRD_POLICY, priority); if(pthread_rwlock_init(&rwlock, NULL) != 0) { printf("main: Error at pthread_rwlock_init()\n"); return PTS_UNRESOLVED; } printf("main: attempt read lock\n"); /* We have no lock, this read lock should succeed */ if(pthread_rwlock_rdlock(&rwlock) != 0) { printf("Test FAILED: main cannot get read lock when no one owns the lock\n"); return PTS_FAIL; } else printf("main: acquired read lock\n"); wr_thread_state = NOT_CREATED_THREAD; priority = sched_get_priority_min(TRD_POLICY); printf("main: create wr_thread, with priority: %d\n", priority); if(pthread_create(&wr_thread, NULL, fn_wr, (void*)(long)priority) != 0) { printf("main: Error at 1st pthread_create()\n"); return PTS_UNRESOLVED; } /* If the shared data is not altered by child after 3 seconds, we regard it as blocked */ /* We expect the wr_thread to block */ cnt = 0; do{ sleep(1); }while (wr_thread_state !=EXITING_THREAD && cnt++ < 3); if(wr_thread_state == EXITING_THREAD ) { printf("wr_thread did not block on write lock, when a reader owns the lock\n"); exit(PTS_UNRESOLVED); } else if(wr_thread_state != ENTERED_THREAD) { printf("Unexpected wr_thread state\n"); exit(PTS_UNRESOLVED); } rd_thread_state = NOT_CREATED_THREAD; priority = sched_get_priority_min(TRD_POLICY) + 1; printf("main: create rd_thread, with priority: %d\n", priority); if(pthread_create(&rd_thread, NULL, fn_rd, (void*)(long)priority) != 0) { printf("main: failed at creating rd_thread\n"); return PTS_UNRESOLVED; } /* We expect the rd_thread get the read lock*/ cnt = 0; do{ sleep(1); }while (rd_thread_state !=EXITING_THREAD && cnt++ < 3); if(rd_thread_state == ENTERED_THREAD ) { printf("Test FAILED: rd_thread blocked on read lock\n"); exit(PTS_FAIL); } else if(rd_thread_state != EXITING_THREAD) { printf("Unexpected rd_thread state\n"); exit(PTS_UNRESOLVED); } printf("main: unlock read lock\n"); if(pthread_rwlock_unlock(&rwlock) != 0) { printf("main: failed to release read lock\n"); exit(PTS_UNRESOLVED); } /* we expect the writer get the lock */ cnt = 0; do{ sleep(1); }while (wr_thread_state !=EXITING_THREAD && cnt++ < 3); if(wr_thread_state == ENTERED_THREAD ) { printf("Test FAILED: higher priority wr_thread still blocked on write lock, when a reader release the lock\n"); exit(PTS_FAIL); } else if(wr_thread_state != EXITING_THREAD) { printf("Unexpected wr_thread state\n"); exit(PTS_UNRESOLVED); } if(pthread_join(wr_thread, NULL) != 0) { printf("main: Error at 1st pthread_join()\n"); exit(PTS_UNRESOLVED); } if(pthread_join(rd_thread, NULL) != 0) { printf("main: Error at 2nd pthread_join()\n"); exit(PTS_UNRESOLVED); } if(pthread_rwlock_destroy(&rwlock) != 0) { printf("Error at pthread_rwlockattr_destroy()"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_rwlock_rdlock/2-1.c0100644000000000000000000001713110033204323024310 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_rwlock_rdlock(pthread_rwlock_t *rwlock) * * If the Thread Execution Scheduling option is supported, * and the threads involved in the lock are executing with the * scheduling policies SCHED_FIFO or SCHED_RR, the calling thread shall not * acquire the lock if a writer holds the lock or if writers of * higher or equal priority are blocked on the lock; * otherwise, the calling thread shall acquire the lock. * * In this case, we test "higher priority writer block" * Steps: * We have three threads, main(also a reader), writer, reader * * 1. Main thread set its shcedule policy as "SCHED_FIFO", with highest priority * the three: sched_get_priority_min()+2. * 2. Main thread read lock 'rwlock' * 3. Create a writer thread, with schedule policy as "SCHED_FIFO", and priority * using sched_get_priority_min()+1. * 4. The thread write lock 'rwlock', should block. * 5. Main thread create a reader thread, with schedule policy as "SCHED_FIFO", and * priority sched_get_priority_min() * 6. Reader thread read lock 'rwlock', should block, since there is a higher priority * writer blocked on 'rwlock' * 7. Main thread release the 'rwlock', the writer should get the lock first */ /* NOTE: The test result is UNSUPPORTED if Thread Execution Scheduling option * is not supported. */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include "posixtest.h" #define TRD_POLICY SCHED_FIFO static pthread_rwlock_t rwlock; static int rd_thread_state; static int wr_thread_state; /* thread states: 1: not in child thread yet; 2: just enter child thread ; 3: just before child thread exit; */ #define NOT_CREATED_THREAD 1 #define ENTERED_THREAD 2 #define EXITING_THREAD 3 static int set_priority(pthread_t pid, unsigned policy, unsigned prio) { struct sched_param sched_param; memset(&sched_param, 0, sizeof(sched_param)); sched_param.sched_priority = prio; if (pthread_setschedparam(pid, policy, &sched_param) == -1) { printf("Can't set policy to %d and prio to %d\n", policy, prio); exit(PTS_UNRESOLVED); } return 0; } static void* fn_rd(void *arg) { int rc = 0; int priority; rd_thread_state = ENTERED_THREAD; priority = (long)arg; set_priority(pthread_self(), TRD_POLICY, priority); printf("rd_thread: attempt read lock\n"); rc = pthread_rwlock_rdlock(&rwlock); if(rc != 0) { printf("Test FAILED: rd_thread failed to get read lock, Error code:%d\n" , rc); exit(PTS_FAIL); } else printf("rd_thread: acquired read lock\n"); sleep(1); printf("rd_thread: unlock read lock\n"); if(pthread_rwlock_unlock(&rwlock) != 0) { printf("rd_thread: Error at pthread_rwlock_unlock()\n"); exit(PTS_UNRESOLVED); } rd_thread_state = EXITING_THREAD; pthread_exit(0); return NULL; } static void* fn_wr(void *arg) { int rc = 0; int priority; wr_thread_state = ENTERED_THREAD; priority = (long)arg; set_priority(pthread_self(), TRD_POLICY, priority); printf("wr_thread: attempt write lock\n"); rc = pthread_rwlock_wrlock(&rwlock); if(rc != 0) { printf("Error: wr_thread failed to get write lock, Error code:%d\n" , rc); exit(PTS_UNRESOLVED); } else printf("wr_thread: acquired write lock\n"); sleep(1); printf("wr_thread: unlock write lock\n"); if(pthread_rwlock_unlock(&rwlock) != 0) { printf("wr_thread: Error at pthread_rwlock_unlock()\n"); exit(PTS_UNRESOLVED); } wr_thread_state = EXITING_THREAD; pthread_exit(0); return NULL; } int main() { #ifndef _POSIX_THREAD_PRIORITY_SCHEDULING printf("Posix Thread Execution Scheduling not supported\n"); return PTS_UNSUPPORTED; #endif int cnt = 0; pthread_t rd_thread, wr_thread; int priority; /* main thread needs to have the highest priority*/ priority = sched_get_priority_min(TRD_POLICY) + 2; set_priority(pthread_self(), TRD_POLICY, priority); printf("main: has priority: %d\n", priority); if(pthread_rwlock_init(&rwlock, NULL) != 0) { printf("main: Error at pthread_rwlock_init()\n"); return PTS_UNRESOLVED; } printf("main: attempt read lock\n"); /* This read lock should succeed */ if(pthread_rwlock_rdlock(&rwlock) != 0) { printf("Test FAILED: main cannot get read lock when no one owns the lock\n"); return PTS_FAIL; } else printf("main: acquired read lock\n"); wr_thread_state = NOT_CREATED_THREAD; priority = sched_get_priority_min(TRD_POLICY) + 1; printf("main: create wr_thread, with priority: %d\n", priority); if(pthread_create(&wr_thread, NULL, fn_wr, (void*)(long)priority) != 0) { printf("main: Error at 1st pthread_create()\n"); return PTS_UNRESOLVED; } /* If the shared data is not altered by child after 3 seconds, we regard it as blocked */ /* We expect the wr_thread to block */ cnt = 0; do{ sleep(1); }while (wr_thread_state !=EXITING_THREAD && cnt++ < 3); if(wr_thread_state == EXITING_THREAD) { printf("wr_thread did not block on write lock, when a reader owns the lock\n"); exit(PTS_UNRESOLVED); } else if(wr_thread_state != ENTERED_THREAD) { printf("Unexpected wr_thread state: %d\n", wr_thread_state); exit(PTS_UNRESOLVED); } rd_thread_state = 1; priority = sched_get_priority_min(TRD_POLICY); printf("main: create rd_thread, with priority: %d\n", priority); if(pthread_create(&rd_thread, NULL, fn_rd, (void*)(long)priority) != 0) { printf("main: failed at creating rd_thread\n"); return PTS_UNRESOLVED; } /* We expect the rd_thread to block*/ cnt = 0; do{ sleep(1); }while (rd_thread_state !=EXITING_THREAD && cnt++ < 3); if(rd_thread_state == EXITING_THREAD) { printf("Test FAILED: rd_thread did not block on read lock, when a reader owns the lock, and a higher priority writer is waiting for the lock\n"); exit(PTS_FAIL); } else if(rd_thread_state != ENTERED_THREAD) { printf("Unexpected rd_thread state: %d\n", rd_thread_state); exit(PTS_UNRESOLVED); } printf("main: unlock read lock\n"); if(pthread_rwlock_unlock(&rwlock) != 0) { printf("main: failed to unlock read lock\n"); exit(PTS_UNRESOLVED); } /* we expect the writer get the lock */ cnt = 0; do{ sleep(1); }while (wr_thread_state !=EXITING_THREAD && cnt++ < 3); if(wr_thread_state == ENTERED_THREAD) { printf("Test FAILED: higher priority wr_thread still blocked on write lock, when a reader release the lock\n"); exit(PTS_FAIL); } else if(wr_thread_state != EXITING_THREAD) { printf("Unexpected wr_thread state: %d\n", wr_thread_state); exit(PTS_UNRESOLVED); } if(pthread_join(wr_thread, NULL) != 0) { printf("main: Error at 1st pthread_join()\n"); exit(PTS_UNRESOLVED); } /* we expect the reader get the lock when writer has unlocked the lock*/ cnt = 0; do{ sleep(1); }while (rd_thread_state !=EXITING_THREAD && cnt++ < 3); if(rd_thread_state == ENTERED_THREAD ) { printf("Test FAILED: rd_thread still block on read lock when the lock has no owner\n"); exit(PTS_FAIL); } else if(rd_thread_state != EXITING_THREAD) { printf("Unexpected rd_thread state\n"); exit(PTS_UNRESOLVED); } if(pthread_join(rd_thread, NULL) != 0) { printf("main: Error at 2nd pthread_join()\n"); exit(PTS_UNRESOLVED); } if(pthread_rwlock_destroy(&rwlock) != 0) { printf("Error at pthread_rwlockattr_destroy()"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_condattr_getpshared/0040755000000000000000000000000010515625210025041 5ustar rootrootposixtestsuite/conformance/interfaces/pthread_condattr_getpshared/3-1.sh0100755000000000000000000000107407676677137025734 0ustar rootroot#!/bin/sh # Copyright (c) 2002, Intel Corporation. All rights reserved. # Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com # This file is licensed under the GPL license. For the full content # of this license, see the COPYING file at the top level of this # source tree. # Test pthread_condattr_getpshared() # # Upon success, it returns 0, and stores the value of the process-shared attribute of 'attr' # into 'pshared'. # # This is tested implicitly via assertion 1 and 2. echo "Tested implicitly via assertion 1 and 2. See output for status" exit 0 posixtestsuite/conformance/interfaces/pthread_condattr_getpshared/1-1.c0100644000000000000000000000412007676677137025532 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: bing.wei.liu REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_condattr_getpshared() * * It shall obtain the value of the process-shared attribute from 'attr'. * * Steps: * 1. In a loop, initialize a pthread_condattr_t object with pthread_condattr_init() * 2. Set 'pshared' of the object to PTHREAD_PROCESS_PRIVATE. * 3. Call pthread_condattr_getpshared() to check if the process-shared * attribute is set as PTHREAD_PROCESS_PRIVATE. * */ #include #include #include #include "posixtest.h" #define NUM_OF_CONDATTR 10 int main() { /* Make sure there is process-shared capability. */ #ifndef PTHREAD_PROCESS_SHARED fprintf(stderr,"process-shared attribute is not available for testing\n"); return PTS_UNRESOLVED; #endif pthread_condattr_t attr[NUM_OF_CONDATTR]; int ret, i, pshared; for(i=0;i #include #include #include "posixtest.h" #define NUM_OF_CONDATTR 10 int main() { /* Make sure there is process-shared capability. */ #ifndef PTHREAD_PROCESS_SHARED fprintf(stderr,"process-shared attribute is not available for testing\n"); return PTS_UNRESOLVED; #endif pthread_condattr_t attr[NUM_OF_CONDATTR]; int ret, i, pshared; for(i=0;i The function int pthread_condattr_getpshared(const pthread_condattr_t *restrict attr, int *restrict pshared); shall obtain the value of the process-shared attribute from the attributes object referenced by attr. The default value of the attribute is PTHREAD_PROCESS_PRIVATE. If successful, the pthread_condattr_getpshared() function shall return zero and store the value of the process-shared attribute of attr into the object referenced by the pshared parameter. The pthread_condattr_getpshared() function may fail if: [EINVAL] The value specified by attr is invalid. posixtestsuite/conformance/interfaces/pthread_condattr_getpshared/coverage.txt0100644000000000000000000000020007676677137027417 0ustar rootrootThis document defines the coverage for the pthread_condattr_getpshared function: Assertion Tested? 1 YES 2 YES 3 YES NOTE: posixtestsuite/conformance/interfaces/pthread_condattr_getpshared/2-1.c0100644000000000000000000000301107676677137025531 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: bing.wei.liu REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_condattr_getpshared() * * It shall obtain the value of the process-shared attribute from 'attr'. * * Steps: * 1. Initialize a pthread_condattr_t object with pthread_condattr_init() * 2. Call pthread_condattr_getpshared() to check if the process-shared * attribute is set as the default value PTHREAD_PROCESS_PRIVATE. * */ #include #include #include "posixtest.h" int main() { /* Make sure there is process-shared capability. */ #ifndef PTHREAD_PROCESS_SHARED fprintf(stderr,"process-shared attribute is not available for testing\n"); return PTS_UNRESOLVED; #endif pthread_condattr_t attr; int pshared; /* Initialize a mutex attributes object */ if(pthread_condattr_init(&attr) != 0) { perror("Error at pthread_condattr_init()\n"); return PTS_UNRESOLVED; } /* The default 'pshared' attribute should be PTHREAD_PROCESS_PRIVATE */ if(pthread_condattr_getpshared(&attr, &pshared) != 0) { fprintf(stderr,"Error obtaining the attribute process-shared\n"); return PTS_UNRESOLVED; } if(pshared != PTHREAD_PROCESS_PRIVATE) { printf("Test FAILED: Incorrect default pshared value: %d\n", pshared); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/munlockall/0040755000000000000000000000000010515625175021461 5ustar rootrootposixtestsuite/conformance/interfaces/munlockall/5-1.c0100644000000000000000000000336607700521654022133 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that the munlockall() function always return a value of zero if it is * supported by the implementation. */ #include #include #include #include #include "posixtest.h" #if !defined(_POSIX_MEMLOCK) || _POSIX_MEMLOCK == -1 int main(){ printf("Does not support ML (Memory Lock).\n"); return PTS_UNSUPPORTED; } #else #if _POSIX_MEMLOCK != 0 int main(){ int result; result = munlockall(); if(result == 0){ printf("Test PASSED\n"); return PTS_PASS; } else if(errno == EPERM){ printf("You don't have permission to unlock your address space.\nTry to rerun this test as root.\n"); return PTS_UNRESOLVED; } else { printf("munlockall() returns %i instead of zero.\n", result); return PTS_FAIL; } } #else int main(){ int result; long memlock; memlock = sysconf(_SC_MEMLOCK); if(errno){ perror("An errno occurs when calling sysconf().\n"); return PTS_UNRESOLVED; } result = munlockall(); if( (result == 0 && memlock > 0) || (result == -1 && memlock <=0) ){ printf("Test PASSED\n"); return PTS_PASS; } else if(errno == EPERM){ printf("You don't have permission to unlock your address space.\nTry to rerun this test as root.\n"); return PTS_UNRESOLVED; } else { printf("munlockall() returns %i instead of zero.\n", result); return PTS_FAIL; } } #endif #endif posixtestsuite/conformance/interfaces/munlockall/assertions.xml0100644000000000000000000000307710117555063024375 0ustar rootroot Any pages that become mapped into the address space of the process after a call to munlockall() shall not be locked, unless there is an intervening call to mlockall() specifying MCL_FUTURE or a subsequent call to mlockall() specifying MCL_CURRENT If pages mapped into the address space of the process are also mapped into the address spaces of other processes and are locked by those processes, the locks established by the other processes shall be unaffected by a call by this process to munlockall() Upon return from the munlockall() function, all currently mapped pages of the process' address space shall be unlocked with respect to the process' address space The memory residency of unlocked pages is unspecified If it is supported by the implementation, the munlockall() function shall always return a value of zero If it is not supported by the implementation, the munlockall() function shall return a value of -1 and set errno to indicate the error posixtestsuite/conformance/interfaces/munlockall/coverage.txt0100644000000000000000000000041407700521654024010 0ustar rootrootThis document explains why certain assertions were not tested. Assertions not listed here should be covered by the tests in this directory. Assertions Tested ? Remarks 1 NO 2 NO 3 NO 4 NO Unspecified 5 YES 6 YES posixtestsuite/conformance/interfaces/munlockall/6-1.sh0100755000000000000000000000033207700521654022315 0ustar rootroot#! /bin/sh # # Test that the munlockall() function return a value of -1 if it is not # supported by the implementation. # # This is tested implicitly via assertion 5. echo "Tested implicitly via assertion 5." exit 0 posixtestsuite/conformance/interfaces/aio_write/0040755000000000000000000000000010515625161021275 5ustar rootrootposixtestsuite/conformance/interfaces/aio_write/5-1.c0100644000000000000000000000354610247562115021751 0ustar rootroot/* * Copyright (c) 2004, Bull SA. All rights reserved. * Created by: Laurent.Vivier@bull.net * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * assertion: * * The aio_write() function shall return the value zero if operation is * successfuly queued. * * method: * * - open file * - write 512 bytes using aio_write * - check return code * */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include #include #include #include "posixtest.h" #define TNAME "aio_write/5-1.c" int main() { char tmpfname[256]; #define BUF_SIZE 512 char buf[BUF_SIZE]; int fd; struct aiocb aiocb; int err; int ret; #if _POSIX_ASYNCHRONOUS_IO != 200112L exit(PTS_UNSUPPORTED); #endif snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_aio_write_5_1_%d", getpid()); unlink(tmpfname); fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL, S_IRUSR | S_IWUSR); if (fd == -1) { printf(TNAME " Error at open(): %s\n", strerror(errno)); exit(PTS_UNRESOLVED); } unlink(tmpfname); memset(&aiocb, 0, sizeof(struct aiocb)); aiocb.aio_fildes = fd; aiocb.aio_buf = buf; aiocb.aio_nbytes = BUF_SIZE; if (aio_write(&aiocb) == -1) { printf(TNAME " Error at aio_write(): %s\n", strerror(errno)); exit(PTS_FAIL); } /* Wait until completion */ while (aio_error (&aiocb) == EINPROGRESS); err = aio_error(&aiocb); ret = aio_return(&aiocb); if (err != 0) { printf (TNAME " Error at aio_error() : %s\n", strerror (err)); close (fd); exit(PTS_FAIL); } if (ret != BUF_SIZE) { printf(TNAME " Error at aio_return()\n"); close(fd); exit(PTS_FAIL); } close(fd); printf ("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/aio_write/4-1.c0100644000000000000000000000124410504222550021731 0ustar rootroot/* * Copyright (c) 2004, Bull SA. All rights reserved. * Created by: Laurent.Vivier@bull.net * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * assertion: * * For regular files, no data transfer shall occur past the offset * maximum established in the open file description associated with * aio_fildes. * * method: * * UNTESTED * */ #define _XOPEN_SOURCE 600 #include #include #include #include "posixtest.h" int main() { #if _POSIX_ASYNCHRONOUS_IO != 200112L exit(PTS_UNSUPPORTED); #endif return PTS_UNTESTED; } posixtestsuite/conformance/interfaces/aio_write/12-1.c0100644000000000000000000000122410247562115022016 0ustar rootroot/* * Copyright (c) 2004, Bull SA. All rights reserved. * Created by: Laurent.Vivier@bull.net * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * assertion: * * The error status of a succesfully queued operation shall be: [ECANCELED] The requested I/O was canceled before the I/O completed. * * method: * * UNTESTED * */ #define _XOPEN_SOURCE 600 #include #include #include #include "posixtest.h" int main() { #if _POSIX_ASYNCHRONOUS_IO != 200112L exit(PTS_UNSUPPORTED); #endif return PTS_UNTESTED; } posixtestsuite/conformance/interfaces/aio_write/1-1.c0100644000000000000000000000511710247562115021741 0ustar rootroot/* * Copyright (c) 2004, Bull SA. All rights reserved. * Created by: Laurent.Vivier@bull.net * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * assertion: * * The aio_write() function shall write aio_nbytes to the files associated * with aio_fildes from the buffer pointer to by aio_buf. * * method: * * - open file * - write 512 bytes using aio_write * - read 513 bytes * - check read data * */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include #include #include #include "posixtest.h" #define TNAME "aio_write/1-1.c" int main() { char tmpfname[256]; #define BUF_SIZE 512 char buf[BUF_SIZE]; char check[BUF_SIZE+1]; int fd; struct aiocb aiocb; int err; int ret; #if _POSIX_ASYNCHRONOUS_IO != 200112L exit(PTS_UNSUPPORTED); #endif snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_aio_write_1_1_%d", getpid()); unlink(tmpfname); fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL, S_IRUSR | S_IWUSR); if (fd == -1) { printf(TNAME " Error at open(): %s\n", strerror(errno)); exit(PTS_UNRESOLVED); } unlink(tmpfname); memset(buf, 0xaa, BUF_SIZE); memset(&aiocb, 0, sizeof(struct aiocb)); aiocb.aio_fildes = fd; aiocb.aio_buf = buf; aiocb.aio_nbytes = BUF_SIZE; if (aio_write(&aiocb) == -1) { printf(TNAME " Error at aio_write(): %s\n", strerror(errno)); close(fd); exit(PTS_FAIL); } /* Wait until completion */ while (aio_error (&aiocb) == EINPROGRESS); err = aio_error(&aiocb); ret = aio_return(&aiocb); if (err != 0) { printf (TNAME " Error at aio_error() : %s\n", strerror (err)); close (fd); exit(PTS_FAIL); } if (ret != BUF_SIZE) { printf(TNAME " Error at aio_return()\n"); close(fd); exit(PTS_FAIL); } /* check the values written */ if (lseek(fd, 0, SEEK_SET) == -1) { printf(TNAME " Error at lseek(): %s\n", strerror(errno)); close(fd); exit(PTS_FAIL); } /* we try to read more than we wrote to be sure of the size written */ check[BUF_SIZE] = 1; if (read(fd, check, BUF_SIZE + 1) != BUF_SIZE) { printf(TNAME " Error at read(): %s\n", strerror(errno)); close(fd); exit(PTS_FAIL); } if ( check[BUF_SIZE] != 1) { printf(TNAME " Buffer overflow\n"); close(fd); exit(PTS_FAIL); } if (memcmp(buf, check, BUF_SIZE)) { printf(TNAME " Bad value in buffer\n"); close(fd); exit(PTS_FAIL); } close(fd); printf ("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/aio_write/9-1.c0100644000000000000000000000410110247562115021741 0ustar rootroot/* * Copyright (c) 2004, Bull SA. All rights reserved. * Created by: Laurent.Vivier@bull.net * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * assertion: * * aio_write() shall fail or the error status of the operation shall be [EINVAL] if: * aio_offset would be invalid, or aio_reqprio is not a valid value, or * aio_nbytes is an invalid value. * * Testing invalid offset * * method: * * - setup an aiocb with an invalid aio_offset * - call aio_write with this aiocb * - check return code and errno * */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include #include #include #include "posixtest.h" #define TNAME "aio_write/9-1.c" int main() { char tmpfname[256]; #define BUF_SIZE 111 char buf[BUF_SIZE]; int fd; struct aiocb aiocb; #if _POSIX_ASYNCHRONOUS_IO != 200112L exit(PTS_UNSUPPORTED); #endif snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_aio_write_9_1_%d", getpid()); unlink(tmpfname); fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL, S_IRUSR | S_IWUSR); if (fd == -1) { printf(TNAME " Error at open(): %s\n", strerror(errno)); exit(PTS_UNRESOLVED); } unlink(tmpfname); memset(&aiocb, 0, sizeof(struct aiocb)); aiocb.aio_fildes = fd; aiocb.aio_buf = buf; aiocb.aio_offset = -1; aiocb.aio_nbytes = BUF_SIZE; if (aio_write(&aiocb) != -1) { while (aio_error (&aiocb) == EINPROGRESS); int err = aio_error (&aiocb); int ret = aio_return (&aiocb); if (ret != -1) { printf(TNAME " bad aio_write return value\n"); close (fd); exit(PTS_FAIL); } else if (err != EINVAL) { printf(TNAME " error code is not EINVAL %s\n", strerror(errno)); close (fd); exit(PTS_FAIL); } } else { if (errno != EINVAL) { printf(TNAME " errno is not EINVAL %s\n", strerror(errno)); close(fd); exit(PTS_FAIL); } } close(fd); printf ("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/aio_write/11-1.c0100644000000000000000000000130510247562115022015 0ustar rootroot/* * Copyright (c) 2004, Bull SA. All rights reserved. * Created by: Laurent.Vivier@bull.net * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * assertion: * * The error status of a succesfully queued operation shall be: * [EINVAL] if aio_offset would be invalid, or aio_reqprio is not a valid * value, or aio_nbytes is an invalid value. * * method: * * UNTESTED * */ #define _XOPEN_SOURCE 600 #include #include #include #include "posixtest.h" int main() { #if _POSIX_ASYNCHRONOUS_IO != 200112L exit(PTS_UNSUPPORTED); #endif return PTS_UNTESTED; } posixtestsuite/conformance/interfaces/aio_write/6-1.c0100644000000000000000000000236610247562115021751 0ustar rootroot/* * Copyright (c) 2004, Bull SA. All rights reserved. * Created by: Laurent.Vivier@bull.net * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * assertion: * * The aio_write() function shall return the value -1 and set errno to indicate error if the operation is not succesfully queued. * * method: * * - fill in an aiocb with a NULL aio_buf * - call aio_write * - check aio_write return value * */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include #include #include #include "posixtest.h" #define TNAME "aio_write/6-1.c" int main() { struct aiocb aiocb; #if _POSIX_ASYNCHRONOUS_IO != 200112L exit(PTS_UNSUPPORTED); #endif /* submit a request with a NULL buffer */ aiocb.aio_fildes = 0; aiocb.aio_buf = NULL; aiocb.aio_nbytes = 0; aiocb.aio_offset = 0; if (aio_write(&aiocb) != -1) { printf(TNAME " aio_write should fail!\n"); exit(PTS_FAIL); } if (errno != EINVAL) { printf(TNAME " errno should be EINVAL!\n"); exit(PTS_FAIL); } printf ("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/aio_write/10-1.c0100644000000000000000000000125010247562115022013 0ustar rootroot/* * Copyright (c) 2004, Bull SA. All rights reserved. * Created by: Laurent.Vivier@bull.net * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * assertion: * * The error status of a succesfully queued operation shall be: * [EBADF] if the aio_fildes argument is not a valid file descriptor open for * writing. * * method: * * UNTESTED * */ #define _XOPEN_SOURCE 600 #include #include #include #include "posixtest.h" int main() { #if _POSIX_ASYNCHRONOUS_IO != 200112L exit(PTS_UNSUPPORTED); #endif return PTS_UNTESTED; } posixtestsuite/conformance/interfaces/aio_write/13-1.c0100644000000000000000000000130610504222550022010 0ustar rootroot/* * Copyright (c) 2004, Bull SA. All rights reserved. * Created by: Laurent.Vivier@bull.net * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * assertion: * * aio_write() shall fail or the error status of the operation shall be [EFBIG]: * if aio_nbytes is greater than 0 and aio_offset is at or beyond the * offset maximum of aio_fildes. * * method: * * UNTESTED * */ #define _XOPEN_SOURCE 600 #include #include #include #include "posixtest.h" int main() { #if _POSIX_ASYNCHRONOUS_IO != 200112L exit(PTS_UNSUPPORTED); #endif return PTS_UNTESTED; } posixtestsuite/conformance/interfaces/aio_write/8-2.c0100644000000000000000000000340710247562115021751 0ustar rootroot/* * Copyright (c) 2004, Bull SA. All rights reserved. * Created by: Laurent.Vivier@bull.net * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * assertion: * * aio_write() shall fail or the error status of the operation shall be [EBADF] if: * aio_fildes argument is not a valid file descriptor open for writing. * * method: Test with an invalid file descriptor opened read-only * * - setup an aiocb with an read-only aio_fildes * - call aio_write with this aiocb * - check return code and errno * */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include #include #include #include "posixtest.h" #define TNAME "aio_write/8-2.c" int main() { char tmpfname[256]; #define BUF_SIZE 512 char buf[BUF_SIZE]; int fd; struct aiocb aiocb; #if _POSIX_ASYNCHRONOUS_IO != 200112L exit(PTS_UNSUPPORTED); #endif snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_aio_write_8_2_%d", getpid()); unlink(tmpfname); fd = open(tmpfname, O_CREAT | O_RDONLY | O_EXCL, S_IRUSR | S_IWUSR); if (fd == -1) { printf(TNAME " Error at open(): %s\n", strerror(errno)); exit(PTS_UNRESOLVED); } unlink(tmpfname); memset(buf, 0xaa, BUF_SIZE); memset(&aiocb, 0, sizeof(struct aiocb)); aiocb.aio_fildes = fd; aiocb.aio_buf = buf; aiocb.aio_nbytes = BUF_SIZE; if (aio_write(&aiocb) != -1) { printf(TNAME " bad aio_write return value()\n"); exit(PTS_FAIL); } if (errno != EBADF) { printf(TNAME " errno is not EBADF %s\n", strerror(errno)); exit(PTS_FAIL); } close(fd); printf ("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/aio_write/1-2.c0100644000000000000000000000615110247562115021741 0ustar rootroot/* * Copyright (c) 2004, Bull SA. All rights reserved. * Created by: Laurent.Vivier@bull.net * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * assertion: * * The aio_write() function shall write aio_nbytes to the files associated * with aio_fildes from the buffer pointer to by aio_buf. * * method: * * - open file * - write 2*1024 0x00 bytes using synchronous write * - write 1024 0xaa bytes at offset 512 using aio_write * - read 2*1024 bytes * - check read data * */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include #include #include #include "posixtest.h" #define TNAME "aio_write/1-2.c" int main() { char tmpfname[256]; #define BUF_SIZE 1024 char buf[BUF_SIZE]; char check[BUF_SIZE * 2]; int fd; struct aiocb aiocb; int err; int ret; #if _POSIX_ASYNCHRONOUS_IO != 200112L exit(PTS_UNSUPPORTED); #endif snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_aio_write_1_2_%d", getpid()); unlink(tmpfname); fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL, S_IRUSR | S_IWUSR); if (fd == -1) { printf(TNAME " Error at open(): %s\n", strerror(errno)); exit(PTS_UNRESOLVED); } unlink(tmpfname); memset(buf, 0x00, BUF_SIZE); if (write(fd, buf, BUF_SIZE) != BUF_SIZE) { printf(TNAME " Error at write(): %s\n", strerror(errno)); exit(PTS_UNRESOLVED); } if (write(fd, buf, BUF_SIZE) != BUF_SIZE) { printf(TNAME " Error at write(): %s\n", strerror(errno)); exit(PTS_UNRESOLVED); } memset(buf, 0xaa, BUF_SIZE); memset(&aiocb, 0, sizeof(struct aiocb)); aiocb.aio_fildes = fd; aiocb.aio_buf = buf; aiocb.aio_nbytes = BUF_SIZE; aiocb.aio_offset = BUF_SIZE / 2; if (aio_write(&aiocb) == -1) { printf(TNAME " Error at aio_write(): %s\n", strerror(errno)); exit(PTS_FAIL); } /* Wait until end of transaction */ while (aio_error (&aiocb) == EINPROGRESS); err = aio_error(&aiocb); ret = aio_return(&aiocb); if (err != 0) { printf (TNAME " Error at aio_error() : %s\n", strerror (err)); close (fd); exit(PTS_FAIL); } if (ret != BUF_SIZE) { printf(TNAME " Error at aio_return()\n"); close(fd); exit(PTS_FAIL); } /* check the values written */ if (lseek(fd, 0, SEEK_SET) == -1) { printf(TNAME " Error at lseek(): %s\n", strerror(errno)); close(fd); exit(PTS_FAIL); } memset(check, 0x01, BUF_SIZE * 2); if (read(fd, check, BUF_SIZE * 2) != BUF_SIZE * 2) { printf(TNAME " Error at read(): %s\n", strerror(errno)); close(fd); exit(PTS_FAIL); } if (check[BUF_SIZE / 2 - 1] != 0) { printf(TNAME " write at bad offset\n"); close(fd); exit(PTS_FAIL); } if (check[BUF_SIZE / 2 + BUF_SIZE] != 0) { printf(TNAME " bad size written\n"); close(fd); exit(PTS_FAIL); } if (memcmp(buf, check + BUF_SIZE / 2, BUF_SIZE)) { printf(TNAME " Bad value in buffer\n"); close(fd); exit(PTS_FAIL); } close(fd); printf ("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/aio_write/7-1.c0100644000000000000000000000405210247562115021744 0ustar rootroot/* * Copyright (c) 2004, Bull SA. All rights reserved. * Created by: Laurent.Vivier@bull.net * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * assertion: * * aio_write() shall fail with [EAGAIN] if: * The requested AIO operation was not queued to the system * due to system resource limitations. * * method: * * - open file * - queue NUM_AIOCBS 512-byte aio_write * - wait until one returns EAGAIN * * NUM_AIOCBS might need to be adjusted for the system * */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include "posixtest.h" #define TNAME "aio_write/7-1.c" #define NUM_AIOCBS 1024 int main() { char tmpfname[256]; #define BUF_SIZE 512 char buf[BUF_SIZE]; int fd; int i; struct aiocb aiocbs[NUM_AIOCBS]; int last_req; int err; int ret; #if _POSIX_ASYNCHRONOUS_IO != 200112L exit(PTS_UNSUPPORTED); #endif snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_aio_write_4_1_%d", getpid()); unlink(tmpfname); fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL, S_IRUSR | S_IWUSR); if (fd == -1) { printf(TNAME " Error at open(): %s\n", strerror(errno)); exit(PTS_UNRESOLVED); } unlink(tmpfname); for (i=0; i The aio_write() function shall write aio_nbytes to the files associated with aio_fildes from the buffer pointer to by aio_buf. If O_APPEND is set for the file descripton, write operations append to the file in the same order as the calls were made. aio_lio_opcode shall be ignored. For regular files, no data transfer shall occur past the offset maximum established in the open file description associated with aio_fildes. The aio_write() function shall return the value zero if operation is successfuly queued. The aio_write() function shall return the value -1 and set errno to indicate error if the operation is not succesfully queued. aio_write() shall fail with [EAGAIN] if: The requested AIO operation was not queued to the system due to system resource limitations. aio_write() shall fail or the error status of the operation shall be [EBADF] if: aio_fildes argument is not a valid file descriptor open for writing. aio_write() shall fail or the error status of the operation shall be [EINVAL] if: aio_offset would be invalid, or aio_reqprio is not a valid value, or aio_nbytes is an invalid value. The error status of a succesfully queued operation shall be: [EBADF] if the aio_fildes argument is not a valid file descriptor open for writing. The error status of a succesfully queued operation shall be: [EINVAL] if aio_offset would be invalid, or aio_reqprio is not a valid value, or aio_nbytes is an invalid value. The error status of a succesfully queued operation shall be: [ECANCELED] The requested I/O was canceled before the I/O completed. aio_write() shall fail or the error status of the operation shall be [EFBIG]: if aio_nbytes is greater than 0 and aio_offset is at or beyond the offset maximum of aio_fildes. posixtestsuite/conformance/interfaces/aio_write/coverage.txt0100644000000000000000000000026510245504306023626 0ustar rootrootthis file defines the coverage for the aio_write() function testing. Assertion Covered? 1 YES 2 YES 3 YES 4 YES 5 YES 6 YES 7 YES 8 YES 9 YES 10 NO 11 NO 12 NO 13 YES posixtestsuite/conformance/interfaces/aio_write/8-1.c0100644000000000000000000000263110247562115021746 0ustar rootroot/* * Copyright (c) 2004, Bull SA. All rights reserved. * Created by: Laurent.Vivier@bull.net * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * assertion: * * aio_write() shall fail or the error status of the operation shall be [EBADF] if: * aio_fildes argument is not a valid file descriptor open for writing. * * method: Test with an invalid file descriptor (-1) * * - setup an aiocb with an invalid aio_fildes * - call aio_write with this aiocb * - check return code and errno * */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include #include #include #include "posixtest.h" #define TNAME "aio_write/8-1.c" int main() { #define BUF_SIZE 512 char buf[BUF_SIZE]; struct aiocb aiocb; #if _POSIX_ASYNCHRONOUS_IO != 200112L exit(PTS_UNSUPPORTED); #endif memset(buf, 0xaa, BUF_SIZE); memset(&aiocb, 0, sizeof(struct aiocb)); aiocb.aio_fildes = -1; aiocb.aio_buf = buf; aiocb.aio_nbytes = BUF_SIZE; if (aio_write(&aiocb) != -1) { printf(TNAME " bad aio_write return value()\n"); exit(PTS_FAIL); } if (errno != EBADF) { printf(TNAME " errno is not EBADF %s\n", strerror(errno)); exit(PTS_FAIL); } printf ("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/aio_write/2-1.c0100644000000000000000000000602510247562115021741 0ustar rootroot/* * Copyright (c) 2004, Bull SA. All rights reserved. * Created by: Laurent.Vivier@bull.net * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * assertion: * * If O_APPEND is set for the file descripton, write operations append to * the file in the same order as the calls were made. * * method: * * - open file in append mode * - call aio_write thrice with different buffers and sizes * - read all file * - check read data * */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include #include #include #include "posixtest.h" #define TNAME "aio_write/2-1.c" int main() { char tmpfname[256]; #define BUF_SIZE0 512 char buf0[BUF_SIZE0]; #define BUF_SIZE1 1024 char buf1[BUF_SIZE1]; #define BUF_SIZE2 1536 char buf2[BUF_SIZE2]; char *bufs[3] = {buf0, buf1, buf2}; ssize_t sizes[3] = {BUF_SIZE0, BUF_SIZE1, BUF_SIZE2}; #define CHECK_SIZE (BUF_SIZE0+BUF_SIZE1+BUF_SIZE2) char check[CHECK_SIZE]; int fd; struct aiocb aiocb[3]; int i; int err; int ret; #if _POSIX_ASYNCHRONOUS_IO != 200112L exit(PTS_UNSUPPORTED); #endif snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_aio_write_2_1_%d", getpid()); unlink(tmpfname); fd = open(tmpfname, O_CREAT | O_APPEND | O_RDWR | O_EXCL, S_IRUSR | S_IWUSR); if (fd == -1) { printf(TNAME " Error at open(): %s\n", strerror(errno)); exit(PTS_UNRESOLVED); } unlink(tmpfname); for (i=0; i<3; i++) { memset(bufs[i], i, sizes[i]); memset(&aiocb[i], 0, sizeof(struct aiocb)); aiocb[i].aio_fildes = fd; aiocb[i].aio_buf = bufs[i]; aiocb[i].aio_nbytes = sizes[i]; if (aio_write(&aiocb[i]) == -1) { printf(TNAME " Error at aio_write() %d: %s\n", i, strerror(errno)); close (fd); exit(PTS_FAIL); } } /* Wait until completion */ while (aio_error (&aiocb[2]) == EINPROGRESS); for (i=0; i<3; i++) { err = aio_error(&aiocb[i]); ret = aio_return(&aiocb[i]); if (err != 0) { printf (TNAME " Error at aio_error() %d: %s\n", i, strerror (err)); close (fd); exit(PTS_FAIL); } if (ret != sizes[i]) { printf(TNAME " Error at aio_return() %d\n",i); close(fd); exit(PTS_FAIL); } } /* check the values written */ if (lseek(fd, 0, SEEK_SET) == -1) { printf(TNAME " Error at lseek(): %s\n", strerror(errno)); exit(PTS_FAIL); } if (read(fd, check, CHECK_SIZE) != CHECK_SIZE) { printf(TNAME " Error at read(): %s\n", strerror(errno)); exit(PTS_FAIL); } if (memcmp(buf0, check, BUF_SIZE0)) { printf(TNAME " Bad value in buffer #0\n"); exit(PTS_FAIL); } if (memcmp(buf1, check + BUF_SIZE0, BUF_SIZE1)) { printf(TNAME " Bad value in buffer #1\n"); exit(PTS_FAIL); } if (memcmp(buf2, check + BUF_SIZE0 + BUF_SIZE1, BUF_SIZE2)) { printf(TNAME " Bad value in buffer #2\n"); exit(PTS_FAIL); } close(fd); printf ("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/aio_write/3-1.c0100644000000000000000000000453110247562115021742 0ustar rootroot/* * Copyright (c) 2004, Bull SA. All rights reserved. * Created by: Laurent.Vivier@bull.net * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * assertion: * * aio_lio_opcode shall be ignored. * * method: * * - open file * - fill in an aiocb with an LIO_READ aio_lio_opcode * - call aio_write with this aiocb * - read all file * - check read data * */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include #include #include #include "posixtest.h" #define TNAME "aio_write/3-1.c" int main() { char tmpfname[256]; #define BUF_SIZE 512 char buf[BUF_SIZE]; char check[BUF_SIZE]; int fd; struct aiocb aiocb; int err; int ret; #if _POSIX_ASYNCHRONOUS_IO != 200112L exit(PTS_UNSUPPORTED); #endif snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_aio_write_3_1_%d", getpid()); unlink(tmpfname); fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL, S_IRUSR | S_IWUSR); if (fd == -1) { printf(TNAME " Error at open(): %s\n", strerror(errno)); exit(PTS_UNRESOLVED); } unlink(tmpfname); memset(buf, 0xaa, BUF_SIZE); memset(&aiocb, 0, sizeof(struct aiocb)); aiocb.aio_fildes = fd; aiocb.aio_buf = buf; aiocb.aio_nbytes = BUF_SIZE; aiocb.aio_lio_opcode = LIO_READ; if (aio_write(&aiocb) == -1) { printf(TNAME " Error at aio_write(): %s\n", strerror(errno)); exit(PTS_FAIL); } /* Wait until completion */ while (aio_error (&aiocb) == EINPROGRESS); err = aio_error(&aiocb); ret = aio_return(&aiocb); if (err != 0) { printf (TNAME " Error at aio_error() : %s\n", strerror (err)); close (fd); exit(PTS_FAIL); } if (ret != BUF_SIZE) { printf(TNAME " Error at aio_return()\n"); close(fd); exit(PTS_FAIL); } /* check the values written */ if (lseek(fd, 0, SEEK_SET) == -1) { printf(TNAME " Error at lseek(): %s\n", strerror(errno)); exit(PTS_FAIL); } if (read(fd, check, BUF_SIZE) != BUF_SIZE) { printf(TNAME " Error at read(): %s\n", strerror(errno)); exit(PTS_FAIL); } if (memcmp(buf, check, BUF_SIZE)) { printf(TNAME " Bad value in buffer\n"); exit(PTS_FAIL); } close(fd); printf ("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/aio_write/9-2.c0100644000000000000000000000410410247562115021745 0ustar rootroot/* * Copyright (c) 2004, Bull SA. All rights reserved. * Created by: Laurent.Vivier@bull.net * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * assertion: * * aio_write() shall fail or the error status of the operation shall be [EINVAL] if: * aio_offset would be invalid, or aio_reqprio is not a valid value, or * aio_nbytes is an invalid value. * * Testing invalid reqprio * * method: * * - setup an aiocb with an invalid aio_reqprio * - call aio_write with this aiocb * - check return code and errno * */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include #include #include #include "posixtest.h" #define TNAME "aio_write/9-2.c" int main() { char tmpfname[256]; #define BUF_SIZE 512 char buf[BUF_SIZE]; int fd; struct aiocb aiocb; #if _POSIX_ASYNCHRONOUS_IO != 200112L exit(PTS_UNSUPPORTED); #endif snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_aio_write_9_2_%d", getpid()); unlink(tmpfname); fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL, S_IRUSR | S_IWUSR); if (fd == -1) { printf(TNAME " Error at open(): %s\n", strerror(errno)); exit(PTS_UNRESOLVED); } unlink(tmpfname); memset(&aiocb, 0, sizeof(struct aiocb)); aiocb.aio_fildes = fd; aiocb.aio_buf = buf; aiocb.aio_reqprio = -1; aiocb.aio_nbytes = BUF_SIZE; if (aio_write(&aiocb) != -1) { while (aio_error (&aiocb) == EINPROGRESS); int err = aio_error (&aiocb); int ret = aio_return (&aiocb); if (ret != -1) { printf(TNAME " bad aio_write return value\n"); close (fd); exit(PTS_FAIL); } else if (err != EINVAL) { printf(TNAME " error code is not EINVAL %s\n", strerror(errno)); close (fd); exit(PTS_FAIL); } } else { if (errno != EINVAL) { printf(TNAME " errno is not EINVAL %s\n", strerror(errno)); close(fd); exit(PTS_FAIL); } } close(fd); printf ("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_kill/0040755000000000000000000000000010515625216021756 5ustar rootrootposixtestsuite/conformance/interfaces/pthread_kill/1-1.c0100644000000000000000000000575007635772550022441 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: salwan.searty REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. This program verifies that the pthread_kill() function requests from the kernel to deliver a specified signal to a specified thread. Using two global values of sem1 (INTHREAD and INMAIN), we are going to control when we want execution to be in main() and when we want execution to be a_thread_func(). When the main() function sets sem1 to INTHREAD and keeps looping until sem1 gets changed back to INMAIN, the a_thread_func() will be exclusively running. Similarly, when the a_thread_func() sets sem1 to INMAIN and keeps looping until sem1 gets changed back to INTHREAD, the main() function will be exclusively running. Steps: 1. From the main() function, create a new thread. Using the above methodology, let the new thread run "exclusively." 2. Inside the new thread, prepare for catching the signal indicated by SIGTOTEST, and calling a handler that sets handler_called to 1. Now let the main() thread run "exclusively". 3. Have main() send the signal indicated by SIGTOTEST to the new thread, using pthread_kill(). Let the new thread continue running, and from the main function, wait until handler_called is set to something other than 0. 4. In the new thread, if the handler wasn't called for more than 5 seconds, then set handler_called to -1, otherwise set it to 1. 5. In either case, the main() function will continue execution and return a PTS_PASS if handler_called was 1, and a PTS_FAIL if handler_called was -1. */ #include #include #include #include #include #include "posixtest.h" # define INTHREAD 0 # define INMAIN 1 # define SIGTOTEST SIGABRT int sem1; /* Manual semaphore */ int handler_called = 0; void handler() { printf("signal was called\n"); handler_called = 1; return; } void *a_thread_func() { struct sigaction act; act.sa_flags = 0; act.sa_handler = handler; sigemptyset(&act.sa_mask); sigaction(SIGTOTEST, &act, 0); sem1=INMAIN; while(sem1==INMAIN) sleep(1); sleep(5); handler_called=-1; pthread_exit(0); return NULL; } int main() { pthread_t new_th; sem1=INTHREAD; if(pthread_create(&new_th, NULL, a_thread_func, NULL) != 0) { perror("Error creating thread\n"); return PTS_UNRESOLVED; } while(sem1==INTHREAD) sleep(1); if(pthread_kill(new_th, SIGTOTEST) != 0) { printf("Test FAILED: Couldn't send signal to thread\n"); return PTS_FAIL; } sem1=INTHREAD; while(handler_called==0) sleep(1); if(handler_called == -1) { printf("Test FAILED: Kill request timed out\n"); return PTS_FAIL; } else if (handler_called == 0) { printf("Test FAILED: Thread did not recieve or handle\n"); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_kill/testfrmw.c0100644000000000000000000000407210202407655023773 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * * This file is a wrapper to use the tests from the NPTL Test & Trace Project * with either the Linux Test Project or the Open POSIX Test Suite. * The following function are defined: * void output_init() * void output_fini() * void output(char * string, ...) * * The are used to output informative text (as a printf). */ #include #include /* We use a mutex to avoid conflicts in traces */ static pthread_mutex_t m_trace = PTHREAD_MUTEX_INITIALIZER; /*****************************************************************************************/ /******************************* stdout module *****************************************/ /*****************************************************************************************/ /* The following functions will output to stdout */ #if (1) void output_init() { /* do nothing */ return; } void output( char * string, ... ) { va_list ap; char *ts="[??:??:??]"; struct tm * now; time_t nw; pthread_mutex_lock(&m_trace); nw = time(NULL); now = localtime(&nw); if (now == NULL) printf(ts); else printf("[%2.2d:%2.2d:%2.2d]", now->tm_hour, now->tm_min, now->tm_sec); va_start( ap, string); vprintf(string, ap); va_end(ap); pthread_mutex_unlock(&m_trace); } void output_fini() { /*do nothing */ return; } #endif posixtestsuite/conformance/interfaces/pthread_kill/6-1.c0100644000000000000000000000264010153044505022416 0ustar rootroot/* * Copyright (c) 2002-3, Intel Corporation. All rights reserved. * Created by: salwan.searty REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * * Test that the pthread_kill() function shall return ESRCH when no * thread could be found corresponding to that specified by the given * thread ID. * * NOTE: Cannot find 6-1.c in PTS cvs. So write this one. */ #include #include #include #include #include #include #include #include "posixtest.h" void * thread_function(void *arg) { /* Does nothing */ pthread_exit((void*)0); /* To please some compilers */ return NULL; } int main() { pthread_t child_thread; pthread_t invalid_tid; int rc; rc = pthread_create(&child_thread, NULL, thread_function, NULL); if (rc != 0) { printf("Error at pthread_create()\n"); return PTS_UNRESOLVED; } rc = pthread_join(child_thread, NULL); if (rc != 0) { printf("Error at pthread_join()\n"); return PTS_UNRESOLVED; } /* Now the child_thread exited, it is an invalid tid */ memcpy(&invalid_tid, &child_thread, sizeof(pthread_t)); if (pthread_kill(invalid_tid, 0) == ESRCH) { printf("pthread_kill() returns ESRCH.\n"); return PTS_PASS; } printf("Test Fail\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/pthread_kill/1-2.c0100644000000000000000000001072110202407655022415 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertions: * * pthread_kill() sends the specified signal to the specified thread. * The steps are: * -> set a signal handler * -> Create a new thread * -> pthread_kill this thread from the main thread * -> Wait that the signal handler is called * -> Check that the correct signal is received in the correct thread * The test fails if a bad signal is received or bad thread receives it. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /******************************************************************************/ /*************************** standard includes ********************************/ /******************************************************************************/ #include #include #include #include #include #include #include #include /******************************************************************************/ /*************************** Test framework *******************************/ /******************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int * (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /******************************************************************************/ /**************************** Configuration ***********************************/ /******************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif /******************************************************************************/ /*************************** Test case ***********************************/ /******************************************************************************/ int handler_called = 0; pthread_t ch; /* Signal handler */ void handler( int sig ) { handler_called = sig; if ( !pthread_equal( pthread_self(), ch ) ) { FAILED( "The signal handler was not trigged in the killed thread" ); } } /* Thread function */ void * threaded( void * arg ) { int rebours = 3; /* sleep up to 3 seconds */ while ( ( !handler_called ) && ( rebours-- ) ) sleep( 1 ); /* quit */ return NULL; } /* The main test function. */ int main( int argc, char * argv[] ) { int ret; struct sigaction sa; /* Initialize output */ output_init(); /* Set the signal handler */ sa.sa_flags = 0; sa.sa_handler = handler; ret = sigemptyset( &sa.sa_mask ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to empty signal set" ); } sigaction( SIGUSR2, &sa, 0 ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to set signal handler" ); } /* Create the child */ ret = pthread_create( &ch, NULL, threaded, NULL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to create a thread" ); } /* kill the child thread */ ret = pthread_kill( ch, SIGUSR2 ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to kill child thread" ); } /* Wait for child thread termination */ ret = pthread_join( ch, NULL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to join the thread" ); } /* Check if handler has been trigged inside the child */ if ( handler_called != SIGUSR2 ) { FAILED( "Wrong signal received in thread" ); } /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/pthread_kill/7-1.c0100644000000000000000000000140107635772550022434 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: salwan.searty REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that when the null signal is sent to pthread_kill(), error checking is still performed. */ #include #include #include #include #include #include #include #include "posixtest.h" int main() { pthread_t main_thread; main_thread = pthread_self(); if (EINVAL != pthread_kill(main_thread, -1)) { printf("pthread_kill() did not fail on EINVAL\n"); return PTS_FAIL; } return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_kill/assertions.xml0100644000000000000000000000243207635705466024707 0ustar rootroot The pthread_kill() function requests from the kernel to deliver a specified signal be to a specified thread. Just like in the kill() function, error checking shall be performed but no signal shall actually be sent, if sig is zero. The function shall return a value of zero, upon successful completion. The function shall return an error number otherwise. No signal shall be sent if the pthread_kill() function fails. [ESRCH] No thread could be found corresponding to that specified by the given thread ID. [EINVAL] The value of the sig argument is an invalid or unsupported signal number. The pthread_kill () function shall not return an error code of [EINTR]. posixtestsuite/conformance/interfaces/pthread_kill/coverage.txt0100644000000000000000000000041107744654571024323 0ustar rootrootThis file defines the coverage for the kill() function testing. Assertion Status 1 YES 2 YES 3 YES 4 IMPLICITLY tested by assertions 6 and 7. 5 IMPLICITLY tested by assertions 6 and 7. 6 YES 7 YES 8 WON'T test. No way to interrupt the pthread_kill() call. posixtestsuite/conformance/interfaces/pthread_kill/testfrmw.h0100644000000000000000000000456410202407655024006 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * * This file is a wrapper to use the tests from the NPTL Test & Trace Project * with either the Linux Test Project or the Open POSIX Test Suite. * The following macros are defined here: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate without calling one of those macros. * * */ #include "posixtest.h" #include /* for the strerror() routine */ #ifdef __GNUC__ /* We are using GCC */ #define UNRESOLVED(x, s) \ { output("Test %s unresolved: got %i (%s) on line %i (%s)\n", __FILE__, x, strerror(x), __LINE__, s); \ output_fini(); \ exit(PTS_UNRESOLVED); } #define FAILED(s) \ { output("Test %s FAILED: %s\n", __FILE__, s); \ output_fini(); \ exit(PTS_FAIL); } #define PASSED \ output_fini(); \ exit(PTS_PASS); #define UNTESTED(s) \ { output("File %s cannot test: %s\n", __FILE__, s); \ output_fini(); \ exit(PTS_UNTESTED); \ } #else /* not using GCC */ #define UNRESOLVED(x, s) \ { output("Test unresolved: got %i (%s) on line %i (%s)\n", x, strerror(x), __LINE__, s); \ output_fini(); \ exit(PTS_UNRESOLVED); } #define FAILED(s) \ { output("Test FAILED: %s\n", s); \ output_fini(); \ exit(PTS_FAIL); } #define PASSED \ output_fini(); \ exit(PTS_PASS); #define UNTESTED(s) \ { output("Unable to test: %s\n", s); \ output_fini(); \ exit(PTS_UNTESTED); \ } #endif posixtestsuite/conformance/interfaces/pthread_kill/8-1.c0100644000000000000000000001717610202407655022436 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertion: * * The function does not return EINTR * The steps are: * -> kill a thread which calls pthread_kill * -> check that EINTR is never returned */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /********************************************************************************************/ /****************************** standard includes *****************************************/ /********************************************************************************************/ #include #include #include #include #include #include #include #include #include /********************************************************************************************/ /****************************** Test framework *****************************************/ /********************************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /********************************************************************************************/ /********************************** Configuration ******************************************/ /********************************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif #define WITH_SYNCHRO /********************************************************************************************/ /*********************************** Test cases *****************************************/ /********************************************************************************************/ char do_it = 1; unsigned long count_ope = 0; #ifdef WITH_SYNCHRO sem_t semsig1; sem_t semsig2; unsigned long count_sig = 0; #endif sigset_t usersigs; typedef struct { int sig; #ifdef WITH_SYNCHRO sem_t *sem; #endif } thestruct; /* the following function keeps on sending the signal to the process */ void * sendsig ( void * arg ) { thestruct * thearg = ( thestruct * ) arg; int ret; pid_t process; process = getpid(); /* We block the signals SIGUSR1 and SIGUSR2 for this THREAD */ ret = pthread_sigmask( SIG_BLOCK, &usersigs, NULL ); if ( ret != 0 ) { UNRESOLVED( ret, "Unable to block SIGUSR1 and SIGUSR2 in signal thread" ); } while ( do_it ) { #ifdef WITH_SYNCHRO if ( ( ret = sem_wait( thearg->sem ) ) ) { UNRESOLVED( errno, "Sem_wait in sendsig" ); } count_sig++; #endif ret = kill( process, thearg->sig ); if ( ret != 0 ) { UNRESOLVED( errno, "Kill in sendsig" ); } } return NULL; } /* Next are the signal handlers. */ /* This one is registered for signal SIGUSR1 */ void sighdl1( int sig ) { #ifdef WITH_SYNCHRO if ( sem_post( &semsig1 ) ) { UNRESOLVED( errno, "Sem_post in signal handler 1" ); } #endif } /* This one is registered for signal SIGUSR2 */ void sighdl2( int sig ) { #ifdef WITH_SYNCHRO if ( sem_post( &semsig2 ) ) { UNRESOLVED( errno, "Sem_post in signal handler 2" ); } #endif } int init_ctl; /* Init function */ void initializer( void ) { init_ctl++; return ; } /* Test function -- calls pthread_kill() and checks that EINTR is never returned. */ void * test( void * arg ) { int ret = 0; /* We don't block the signals SIGUSR1 and SIGUSR2 for this THREAD */ ret = pthread_sigmask( SIG_UNBLOCK, &usersigs, NULL ); if ( ret != 0 ) { UNRESOLVED( ret, "Unable to unblock SIGUSR1 and SIGUSR2 in worker thread" ); } while ( do_it ) { count_ope++; ret = pthread_kill( pthread_self(), 0 ); if ( ret == EINTR ) { FAILED( "pthread_kill returned EINTR" ); } if ( ret != 0 ) { UNRESOLVED( ret, "pthread_kill returned an unexpected error" ); } ret = pthread_kill( pthread_self(), SIGUSR1 ); if ( ret == EINTR ) { FAILED( "pthread_kill returned EINTR" ); } if ( ret != 0 ) { UNRESOLVED( ret, "pthread_kill returned an unexpected error" ); } } return NULL; } /* Main function */ int main ( int argc, char * argv[] ) { int ret; pthread_t th_work, th_sig1, th_sig2; thestruct arg1, arg2; struct sigaction sa; /* Initialize output routine */ output_init(); /* We need to register the signal handlers for the PROCESS */ sigemptyset ( &sa.sa_mask ); sa.sa_flags = 0; sa.sa_handler = sighdl1; if ( ( ret = sigaction ( SIGUSR1, &sa, NULL ) ) ) { UNRESOLVED( ret, "Unable to register signal handler1" ); } sa.sa_handler = sighdl2; if ( ( ret = sigaction ( SIGUSR2, &sa, NULL ) ) ) { UNRESOLVED( ret, "Unable to register signal handler2" ); } /* We prepare a signal set which includes SIGUSR1 and SIGUSR2 */ sigemptyset( &usersigs ); ret = sigaddset( &usersigs, SIGUSR1 ); ret |= sigaddset( &usersigs, SIGUSR2 ); if ( ret != 0 ) { UNRESOLVED( ret, "Unable to add SIGUSR1 or 2 to a signal set" ); } /* We now block the signals SIGUSR1 and SIGUSR2 for this THREAD */ ret = pthread_sigmask( SIG_BLOCK, &usersigs, NULL ); if ( ret != 0 ) { UNRESOLVED( ret, "Unable to block SIGUSR1 and SIGUSR2 in main thread" ); } #ifdef WITH_SYNCHRO if ( sem_init( &semsig1, 0, 1 ) ) { UNRESOLVED( errno, "Semsig1 init" ); } if ( sem_init( &semsig2, 0, 1 ) ) { UNRESOLVED( errno, "Semsig2 init" ); } #endif if ( ( ret = pthread_create( &th_work, NULL, test, NULL ) ) ) { UNRESOLVED( ret, "Worker thread creation failed" ); } arg1.sig = SIGUSR1; arg2.sig = SIGUSR2; #ifdef WITH_SYNCHRO arg1.sem = &semsig1; arg2.sem = &semsig2; #endif if ( ( ret = pthread_create( &th_sig1, NULL, sendsig, ( void * ) & arg1 ) ) ) { UNRESOLVED( ret, "Signal 1 sender thread creation failed" ); } if ( ( ret = pthread_create( &th_sig2, NULL, sendsig, ( void * ) & arg2 ) ) ) { UNRESOLVED( ret, "Signal 2 sender thread creation failed" ); } /* Let's wait for a while now */ sleep( 1 ); /* Now stop the threads and join them */ do { do_it = 0; } while ( do_it ); if ( ( ret = pthread_join( th_sig1, NULL ) ) ) { UNRESOLVED( ret, "Signal 1 sender thread join failed" ); } if ( ( ret = pthread_join( th_sig2, NULL ) ) ) { UNRESOLVED( ret, "Signal 2 sender thread join failed" ); } if ( ( ret = pthread_join( th_work, NULL ) ) ) { UNRESOLVED( ret, "Worker thread join failed" ); } #if VERBOSE > 0 output( "Test executed successfully.\n" ); output( " %d operations.\n", count_ope ); #ifdef WITH_SYNCHRO output( " %d signals were sent meanwhile.\n", count_sig ); #endif #endif PASSED; } posixtestsuite/conformance/interfaces/pthread_kill/2-1.c0100644000000000000000000000162307635765713022440 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: salwan.searty REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that if the signal is the null signal (0), no signal is sent. * 1) Call pthread_kill on the current thread with the null signal. * 2) If process is still functional after kill() is called, consider * the test a pass (most likely no signal was sent). */ #include #include #include #include #include #include "posixtest.h" int main() { pthread_t main_thread; main_thread=pthread_self(); if (pthread_kill(main_thread, 0) != 0) { printf("Could not call pthread_kill with sig = 0\n"); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_kill/3-1.c0100644000000000000000000000132607635772550022436 0ustar rootroot/* * Copyright (c) 2002-3, Intel Corporation. All rights reserved. * Created by: salwan.searty REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that the pthread_kill() function shall return 0 upon success. */ #include #include #include #include #include #include "posixtest.h" int main() { pthread_t main_thread; main_thread = pthread_self(); if (pthread_kill(main_thread, 0) != 0) { printf("pthread_kill did not return success.\n"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/sem_post/0040755000000000000000000000000010515625235021146 5ustar rootrootposixtestsuite/conformance/interfaces/sem_post/cln.sh0100755000000000000000000000025607606431301022255 0ustar rootroot rm -f /tmp/mysem >/dev/null 2>&1 rm -f /tmp/sem_* >/dev/null 2>&1 rm -f a.out for sem_id in `ipcs -s | awk '{print $2}'` ; do ipcrm sem $sem_id > /dev/null 2>&1 done posixtestsuite/conformance/interfaces/sem_post/5-1.c0100644000000000000000000000371510514633054021614 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: majid.awad REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * sem_post() can be entered into again if interrupted by a signal * --> This is tough to do with 100% guarantees. This test does a * best attempt. * * 1) Set up a signal catching function for SIGALRM. * 2) Set up a semaphore * 3) Call sleep(1) and then alarm(1) * 4) Call sempost() immediately after (thinking that alarm(1) will interrupt * 5) If sempost() succeeds (verified if val is incremented by 1), * test passes. Otherwise, failure. */ #include #include #include #include #include #include #include "posixtest.h" #define TEST "5-1" #define FUNCTION "sem_post" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " #define SEMINITVAL 0 //initial value of semaphore = 0 sem_t *gsemp; void sighdl(int sig) { return; } int main() { char semname[20]; int val; sprintf(semname, "/" FUNCTION "_" TEST "_%d", getpid()); gsemp = sem_open(semname, O_CREAT, 0777, SEMINITVAL); if( gsemp == SEM_FAILED || gsemp == NULL ) { perror(ERROR_PREFIX "sem_open"); return PTS_UNRESOLVED; } signal(SIGALRM, sighdl); sleep(1); alarm(1); if( sem_post(gsemp) == -1 ) { perror(ERROR_PREFIX "sem_post"); exit(PTS_UNRESOLVED); } /* Checking if the value of the Semaphore incremented by one */ if( sem_getvalue(gsemp, &val) == -1 ) { perror(ERROR_PREFIX "sem_getvalue"); return PTS_UNRESOLVED; } if (val != SEMINITVAL+1) { #ifdef DEBUG printf("semaphore value was not incremented\n"); #endif printf("TEST FAILED\n"); return PTS_FAIL; } #ifdef DEBUG printf("semaphore value was %d\n", val); #endif printf("TEST PASSED\n"); sem_close(gsemp); sem_unlink(semname); return PTS_PASS; } posixtestsuite/conformance/interfaces/sem_post/4-1.c0100644000000000000000000000231007636705223021612 0ustar rootroot/* Copyright (c) 2003, Intel Corporation. All rights reserved. Created by: majid.awad REMOVE-THIS AT intel DOT com This file is licensed under the GPL license. For the full content of this license, see the COPYING file at the top level of this source tree. */ /* * This test case verifies the sem_post returns 0 on successful call. */ #include #include #include #include #include #include #include "posixtest.h" #define TEST "4-1" #define FUNCTION "sem_post" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " int main() { sem_t *mysemp; char semname[20]; sprintf(semname, "/" FUNCTION "_" TEST "_%d", getpid()); /* Initial value of Semaphore is 0 */ mysemp = sem_open(semname, O_CREAT, 0777, 0); if( mysemp == SEM_FAILED || mysemp == NULL ) { perror(ERROR_PREFIX "sem_open"); return PTS_UNRESOLVED; } if( sem_post(mysemp) == 0 ) { puts("TEST PASSED"); sem_close(mysemp); sem_unlink(semname); return PTS_PASS; } else { puts("TEST FAILED: value of sem_post is not returning zero"); return PTS_FAIL; } printf("This code should not be executed.\n"); return PTS_UNRESOLVED; } posixtestsuite/conformance/interfaces/sem_post/1-1.c0100644000000000000000000000257507636705223021624 0ustar rootroot/* Copyright (c) 2003, Intel Corporation. All rights reserved. Created by: majid.awad REMOVE-THIS AT intel DOT com This file is licensed under the GPL license. For the full content of this license, see the COPYING file at the top level of this source tree. */ /* * sem_post shall unlock the locked semaphore and increment the semaphore * value by one. */ #include #include #include #include #include #include #include "posixtest.h" #define TEST "1-1" #define FUNCTION "sem_post" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " int main() { sem_t *mysemp; char semname[20]; int val; sprintf(semname, "/" FUNCTION "_" TEST "_%d", getpid()); /* Initial value of Semaphore is 0 */ mysemp = sem_open(semname, O_CREAT, 0777, 0); if( mysemp == SEM_FAILED || mysemp == NULL ) { perror(ERROR_PREFIX "sem_open"); return PTS_UNRESOLVED; } if( sem_post(mysemp) == -1 ) { perror(ERROR_PREFIX "sem_post"); return PTS_UNRESOLVED; } if( sem_getvalue(mysemp, &val) == -1 ) { perror(ERROR_PREFIX "sem_getvalue"); return PTS_UNRESOLVED; /* Checking if the value of the Semaphore incremented by one */ } else if( val == 1 ) { puts("TEST PASSED"); sem_close(mysemp); sem_unlink(semname); return PTS_PASS; } else { puts("TEST FAILED"); return PTS_FAIL; } } posixtestsuite/conformance/interfaces/sem_post/6-1.c0100644000000000000000000000411407636705223021620 0ustar rootroot/* * * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: majid.awad REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * sem_post() can be called from within a signal catching function * * 1) Set up a signal catching function for SIGALRM. * 2) Set up a semaphore * 3) Call alarm(1) * 4) Call sempost() from within the handler for SIGALRM * 5) If sempost() succeeds (verified if val is incremented by 1), * test passes. Otherwise, failure. */ #include #include #include #include #include #include #include "posixtest.h" #define TEST "6-1" #define FUNCTION "sem_post" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " #define SEMINITVAL 0 //initial value of semaphore = 0 sem_t *gsemp; void handler(int signo) { if( sem_post(gsemp) == -1 ) { perror(ERROR_PREFIX "sem_post"); exit(PTS_UNRESOLVED); } } int main() { char semname[20]; struct sigaction act; int val; sprintf(semname, "/" FUNCTION "_" TEST "_%d", getpid()); gsemp = sem_open(semname, O_CREAT, 0777, SEMINITVAL); act.sa_handler=handler; act.sa_flags=0; if (sigemptyset(&act.sa_mask) == -1) { perror("Error calling sigemptyset\n"); return PTS_UNRESOLVED; } if (sigaction(SIGALRM, &act, 0) == -1) { perror("Error calling sigaction\n"); return PTS_UNRESOLVED; } if( gsemp == SEM_FAILED || gsemp == NULL ) { perror(ERROR_PREFIX "sem_open"); return PTS_UNRESOLVED; } alarm(1); sleep(2); /* Checking if the value of the Semaphore incremented by one */ if( sem_getvalue(gsemp, &val) == -1 ) { perror(ERROR_PREFIX "sem_getvalue"); return PTS_UNRESOLVED; } if (val != SEMINITVAL+1) { #ifdef DEBUG printf("semaphore value was not incremented\n"); #endif printf("TEST FAILED\n"); return PTS_FAIL; } #ifdef DEBUG printf("semaphore value was %d\n", val); #endif printf("TEST PASSED\n"); sem_close(gsemp); sem_unlink(semname); return PTS_PASS; } posixtestsuite/conformance/interfaces/sem_post/1-2.c0100644000000000000000000000261207636705223021615 0ustar rootroot/* Copyright (c) 2003, Intel Corporation. All rights reserved. Created by: majid.awad REMOVE-THIS AT intel DOT com This file is licensed under the GPL license. For the full content of this license, see the COPYING file at the top level of this source tree. */ /* * sem_post shall increment the value of the semaphore when its unlocked * and in positive value */ #include #include #include #include #include #include #include "posixtest.h" #define TEST "1-2" #define FUNCTION "sem_post" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " int main() { sem_t *mysemp; char semname[20]; int val; sprintf(semname, "/" FUNCTION "_" TEST "_%d", getpid()); /* Initial value of Semaphore is unlocked */ mysemp = sem_open(semname, O_CREAT, 0777, 2); if( mysemp == SEM_FAILED || mysemp == NULL ) { perror(ERROR_PREFIX "sem_open"); return PTS_UNRESOLVED; } if( sem_post(mysemp) == -1 ) { perror(ERROR_PREFIX "sem_post"); return PTS_UNRESOLVED; } if( sem_getvalue(mysemp, &val) == -1 ) { perror(ERROR_PREFIX "sem_getvalue"); return PTS_UNRESOLVED; /* Checking if the value of the Semaphore incremented by one */ } else if( val == 3 ) { puts("TEST PASSED"); sem_close(mysemp); sem_unlink(semname); return PTS_PASS; } else { puts("TEST FAILED"); return PTS_FAIL; } } posixtestsuite/conformance/interfaces/sem_post/assertions.xml0100644000000000000000000000214010210636013024040 0ustar rootroot sem_post will unlock a locked semaphore, and will increment the value of the semaphore when the value is positive. sem_post will return a value of 0 on successful calls when it unlock a semaphore. sem_post return EINVAL ERROR on invalid reference to a semaphore. sem_post return zero on a successful call. sem_post will continue after it is interrupted by a signal sem_post cam be called from within a signal catching function If Process Scheduling extension is supported, and scheduler is SCHED_FIFO or SCHED_RR, the highest priority thread is awaken first. If several threads with equal priority are waiting, the threads are awaken in FIFO order. posixtestsuite/conformance/interfaces/sem_post/coverage.txt0100644000000000000000000000003207663254271023502 0ustar rootroot assertion 3: not tested. posixtestsuite/conformance/interfaces/sem_post/8-1.c0100644000000000000000000001371410514633054021617 0ustar rootroot/* * Copyright (c) 2003-2004, Intel Corporation. All rights reserved. * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * adam.li@intel.com 2004-03 */ /* * If the Process Scheduling option is supported, the thread to be unblocked * shall be chosen in a manner appropriate to the scheduling policies * and parameters in effect for the blocked threads. * In the case of the schedulers SCHED_FIFO and SCHED_RR, the highest * priority waiting thread shall be unblocked, and if there is * more than one highest priority thread blocked waiting for the semaphore, * then the highest priority thread that has been waiting the * longest shall be unblocked. * If the Process Scheduling option is not defined, the choice of a thread * to unblock is unspecified. * * Test Steps: * Here we test SCHED_FIFO * 1. Parent locks a semaphore, it has highest priority P0. * 2. It forks 2 child processes 1, 2, as for priority P1, P2, P0 > P2 > P1 * 3. The children lock the semaphore. * Make sure the two children are waiting. * 4. Parent forks another child 3, with priority P3, P3 = P2, it locks * the semaphore too. * 5. Parent unlocks the semaphore, make sure the children * wake up in the order of 2 -> 3 -> 1 */ #include #include #include #include #include #include #include "posixtest.h" #include #include #include #include #define TEST "8-1" #define FUNCTION "sem_wait" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " static char semname[20]; static char semname_1[20]; /* Used to record state */ /* set my schedule priority to @priority */ int set_my_prio(int priority) { struct sched_param sp; sp.sched_priority = priority; /* Set priority */ if (sched_setscheduler(0, SCHED_FIFO, &sp) == -1) { perror("Error at sched_setscheduler()\n"); return -1; } return 0; } int get_my_prio() { struct sched_param sp; if (sched_getparam(0, &sp) == -1) { perror("Error at sched_getparam()\n"); return -1; } return sp.sched_priority; } int child_fn(int priority, int id) { sem_t *sem, *sem_1; if (set_my_prio(priority) == -1) exit(-1); sem = sem_open(semname, 0); if( sem == SEM_FAILED || sem == NULL ) { perror(ERROR_PREFIX "sem_open: sem"); return -1; } sem_1 = sem_open(semname_1, 0); if( sem_1 == SEM_FAILED || sem_1 == NULL ) { perror(ERROR_PREFIX "sem_open: sem_1"); return -1; } sem_wait(sem_1); fprintf(stderr, "child %d try to get lock, prio: %d\n", id, get_my_prio()); if (sem_wait(sem) == -1) { perror("Error at sem_wait"); fprintf(stderr, "Child %d: Cannot get lock", id); exit(-1); } fprintf(stderr, "child %d got lock\n", id); exit(0); } int main() { #ifndef _POSIX_PRIORITY_SCHEDULING printf("_POSIX_PRIORITY_SCHEDULING not defined\n"); return PTS_UNTESTED; #endif sem_t *sem, *sem_1; int val = 3; /* for sem_1 to track the child state */ int priority; pid_t c_1, c_2, c_3, ret_pid; int retval = PTS_UNRESOLVED; int status; snprintf(semname, 20, "/" TEST "_%d", getpid()); /* Initial value of Semaphore is 1 */ sem = sem_open(semname, O_CREAT, 0777, 1); if( sem == SEM_FAILED || sem == NULL ) { perror(ERROR_PREFIX "sem_open"); return PTS_UNRESOLVED; } snprintf(semname_1, 20, "/" TEST "_%d_1", getpid()); sem_1 = sem_open(semname_1, O_CREAT, 0777, val); if( sem_1 == SEM_FAILED || sem_1 == NULL ) { perror(ERROR_PREFIX "sem_open: sem_1"); sem_unlink(semname); return PTS_UNRESOLVED; } /* The parent has highest priority */ priority = sched_get_priority_min(SCHED_FIFO) + 3; if (set_my_prio(priority) == -1) { retval = PTS_UNRESOLVED; goto clean_up; } /* Lock Semaphore */ if( sem_wait(sem) == -1 ) { perror(ERROR_PREFIX "sem_wait"); retval = PTS_UNRESOLVED; goto clean_up; } c_1 = fork(); if (c_1 == 0) { /* Child 1, should block */ child_fn(priority - 2, 1); } else if (c_1 < 0) { perror("Error at fork"); retval = PTS_UNRESOLVED; goto clean_up; } fprintf(stderr, "P: child_1:%d forked\n", c_1); sleep(1); c_2 = fork(); if (c_2 == 0) { /* Child 2 */ child_fn(priority - 1, 2); } else if (c_2 < 0) { perror("Error at fork"); retval = PTS_UNRESOLVED; goto clean_up; } fprintf(stderr, "P: child_2: %d forked\n", c_2); /* Make sure the two children has been waiting */ /*do { sleep(1); sem_getvalue(sem_1, &val); //printf("val = %d\n", val); } while (val != 1); */ c_3 = fork(); if (c_3 == 0) { /* Child 3 */ child_fn(priority - 1, 3); } fprintf(stderr, "P: child_3: %d forked\n", c_3); /* Make sure child 3 has been waiting for the lock */ /*do { sleep(1); sem_getvalue(sem_1, &val); //printf("val = %d\n", val); } while (val != 0); */ /* Ok, let's release the lock */ fprintf(stderr, "P: release lock\n"); sem_post(sem); ret_pid = wait(&status); if (ret_pid == c_2 && WIFEXITED(status) && WEXITSTATUS(status) == 0) { fprintf(stderr, "P: release lock\n"); sem_post(sem); ret_pid = wait(&status); if (ret_pid == c_3 && WIFEXITED(status) && WEXITSTATUS(status) == 0) { fprintf(stderr, "P: release lock\n"); sem_post(sem); ret_pid = wait(&status); if (ret_pid == c_1 && WIFEXITED(status) && WEXITSTATUS(status) == 0) { printf("Test Pass\n"); retval = PTS_PASS; goto clean_up; } printf("Test Fail: Expect child_1: %d, got %d\n", c_1, ret_pid); retval = PTS_FAIL; goto clean_up; } else { printf("Test Fail: Expect child_3: %d, got %d\n", c_3, ret_pid); retval = PTS_FAIL; sem_post(sem); while((wait(NULL) > 0)); goto clean_up; } } else { printf("Test Fail: Expect child_2: %d, got %d\n", c_2, ret_pid); retval = PTS_FAIL; sem_post(sem); sem_post(sem); while((wait(NULL) > 0)); goto clean_up; } clean_up: sem_close(sem); sem_close(sem_1); sem_unlink(semname); sem_unlink(semname_1); return retval; } posixtestsuite/conformance/interfaces/sem_post/2-1.c0100644000000000000000000000241307636705223021614 0ustar rootroot/* Copyright (c) 2003, Intel Corporation. All rights reserved. Created by: majid.awad REMOVE-THIS AT intel DOT com This file is licensed under the GPL license. For the full content of this license, see the COPYING file at the top level of this source tree. */ /* * This test case verifies the semaphore value is 0, then shows a successful * call to release the unlock from mysemp. */ #include #include #include #include #include #include #include "posixtest.h" #define TEST "2-1" #define FUNCTION "sem_post" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " int main() { sem_t *mysemp; char semname[20]; sprintf(semname, "/" FUNCTION "_" TEST "_%d", getpid()); /* Initial value of Semaphore is 0 */ mysemp = sem_open(semname, O_CREAT, 0777, 1); if( mysemp == SEM_FAILED || mysemp == NULL ) { perror(ERROR_PREFIX "sem_open"); return PTS_UNRESOLVED; } if( sem_wait(mysemp) == -1 ) { perror(ERROR_PREFIX "sem_post"); return PTS_UNRESOLVED; } if(( sem_post(mysemp)) == 0 ) { puts("TEST PASSED"); sem_close(mysemp); sem_unlink(semname); return PTS_PASS; } else { puts("TEST FAILED: value of sem_post is not zero"); return PTS_FAIL; } } posixtestsuite/conformance/interfaces/pthread_condattr_setpshared/0040755000000000000000000000000010515625210025055 5ustar rootrootposixtestsuite/conformance/interfaces/pthread_condattr_setpshared/1-1.c0100644000000000000000000000523007676710155025535 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: bing.wei.liu REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_condattr_setpshared() * * It shall obtain the value of the process-shared attribute from 'attr'. * * Explanation: To share a mutex between 2 processes, you need to map shared memory for * the mutex. So whether the 'type' of the condattr is shared or private, it really will * not make a difference since both processes will always have access to the shared memory * as long as they the pointer to it. So all we check here is that you can actually call * the pthread_condattr_setpshared() function, passing to it PTHREAD_PROCESS_SHARED and * PTHREAD_PROCESS_PRIVATE. * * Steps: * 1. In a loop, initialize a pthread_condattr_t object with pthread_condattr_init() * 2. Set 'pshared' of the object to PTHREAD_PROCESS_PRIVATE using pthread_condattr_setpshared * 3. Call pthread_condattr_getpshared() to check if the process-shared * attribute is set as PTHREAD_PROCESS_PRIVATE. * */ #include #include #include #include "posixtest.h" #define NUM_OF_CONDATTR 10 int main() { /* Make sure there is process-shared capability. */ #ifndef PTHREAD_PROCESS_SHARED fprintf(stderr,"process-shared attribute is not available for testing\n"); return PTS_UNRESOLVED; #endif pthread_condattr_t attr[NUM_OF_CONDATTR]; int ret, i, pshared; for(i=0;i #include #include #include "posixtest.h" #define NUM_OF_CONDATTR 10 int main() { /* Make sure there is process-shared capability. */ #ifndef PTHREAD_PROCESS_SHARED fprintf(stderr,"process-shared attribute is not available for testing\n"); return PTS_UNRESOLVED; #endif pthread_condattr_t attr[NUM_OF_CONDATTR]; int ret, i, pshared; for(i=0;i The function int pthread_condattr_setpshared(pthread_condattr_t *attr, int pshared); shall set the process-shared attribute in an initialized attributes object referenced by attr. The process-shared attribute is set to PTHREAD_PROCESS_SHARED to permit a condition variable to be operated upon by any thread that has access to the memory where the condition variable is allocated, even if the condition variale is allocated in memory that is shared by multiple processes. If the process-shared attribute is set to PTHREAD_PROCESS_PRIVATE, the condition variable shall only be operated upon by threads create within the same process as the thread that initialized the condition varible; if threads of differing processes attempt to operate on such a condition variable, the behavior is undefined. If successful, the pthread_condattr_setpshared() function shall return zero; The pthread_condattr_setpshared() function may fail if: [EINVAL] The value specified by attr is invalid. [EINVAL] The new value specified for the attribute is outside the range of legal values for that attribute. posixtestsuite/conformance/interfaces/pthread_condattr_setpshared/coverage.txt0100644000000000000000000000017107676710155027426 0ustar rootrootThis document defines the coverage for the pthread_condattr_setpshared function: Assertion Tested? 1 YES 2 YES NOTE: posixtestsuite/conformance/interfaces/pthread_condattr_setpshared/2-1.c0100644000000000000000000000352307676710155025541 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: bing.wei.liu REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_condattr_setpshared() * * If successful, the pthread_condattr_setpshared() function shall return zero; * The pthread_condattr_setpshared() function may fail if: * [EINVAL] The new value specified for the attribute is outside the range of legal values * for that attribute. * * * Steps: * * 1. Pass to pthread_condattr_setpshared() a negative value for 'pshared' * 2. It may return EINVAL * */ #include #include #include #include "posixtest.h" #define INVALID_PSHARED_VALUE -100 int main() { /* Make sure there is process-shared capability. */ #ifndef PTHREAD_PROCESS_SHARED fprintf(stderr,"process-shared attribute is not available for testing\n"); return PTS_UNRESOLVED; #endif pthread_condattr_t attr; int ret; /* Initialize a cond attributes object */ if(pthread_condattr_init(&attr) != 0) { perror("Error at pthread_condattr_init()\n"); return PTS_UNRESOLVED; } /* Set 'pshared' to INVALID_PSHARED_VALUE. */ ret=pthread_condattr_setpshared(&attr, INVALID_PSHARED_VALUE); if(ret != 0) { if(ret == EINVAL) { printf("Test PASSED\n"); return PTS_PASS; } printf("Test FAILED: Invalid return code, expected 0 or EINVAL, but got: %d\n", ret); return PTS_FAIL; } /* Destory the cond attributes object */ if(pthread_condattr_destroy(&attr) != 0) { perror("Error at pthread_condattr_destroy()\n"); return PTS_UNRESOLVED; } printf("Test PASSED: NOTE*: Returned 0 when passed an invalid 'pshared', but standard says 'may' fail.\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_getcpuclockid/0040755000000000000000000000000010515625214023641 5ustar rootrootposixtestsuite/conformance/interfaces/pthread_getcpuclockid/speculative/0040755000000000000000000000000010515625214026165 5ustar rootrootposixtestsuite/conformance/interfaces/pthread_getcpuclockid/speculative/3-1.c0100644000000000000000000000313310032235073026620 0ustar rootroot/* * Copyright (c) 2004, Intel Corporation. All rights reserved. * Created by: crystal.xiong REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test pthread_getcpuclockid() * * Steps: * 1. Create a thread * 2. pthread_join the created thread * 3. Call the API to get the clockid of this thread, it may fail. */ #include #include #include #include #include #include #include #include #include #include "posixtest.h" #define TEST "3-1" #define FUNCTION "pthread_getcpuclockid" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " void *thread_func() { pthread_exit(0); return NULL; } int main() { int rc; clockid_t cid; pthread_t new_th; rc = pthread_create(&new_th, NULL, thread_func, NULL); if (rc !=0 ) { perror(ERROR_PREFIX "failed to create a thread"); exit(PTS_UNRESOLVED); } rc = pthread_join(new_th, NULL); if(rc != 0) { perror(ERROR_PREFIX "pthread_join"); exit(PTS_UNRESOLVED); } rc = pthread_getcpuclockid(new_th, &cid); if (rc == ESRCH ) { printf("pthread_getcpuclockid returns ESRCH " "when thread_id doesn't exist\n"); } else { printf("pthread_getcpuclockid doesn't return " "ESRCH when thread_id doesn't exist\n"); } return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_getcpuclockid/1-1.c0100644000000000000000000000271110032235073024273 0ustar rootroot/* * Copyright (c) 2004, Intel Corporation. All rights reserved. * Created by: crystal.xiong REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test pthread_getcpuclockid() * * Steps: * 1. Create a thread * 2. Call the API to get the clockid in the created thread */ #include #include #include #include #include #include #include #include #include #include "posixtest.h" #define TEST "1-1" #define FUNCTION "pthread_getcpuclockid" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " void *thread_func() { int rc; clockid_t cid; rc = pthread_getcpuclockid(pthread_self(), &cid); if (rc !=0 ) { perror(ERROR_PREFIX "pthread_getcpuclockid"); exit(PTS_FAIL); } printf("clock id of new thread is %d\n", cid); pthread_exit(0); return NULL; } int main() { int rc; pthread_t new_th; rc = pthread_create(&new_th, NULL, thread_func, NULL); if (rc !=0 ) { perror(ERROR_PREFIX "failed to create a thread"); exit(PTS_UNRESOLVED); } rc = pthread_join(new_th, NULL); if(rc != 0) { perror(ERROR_PREFIX "pthread_join"); exit(PTS_UNRESOLVED); } return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_getcpuclockid/assertions.xml0100644000000000000000000000115610032235073026547 0ustar rootroot pthread_getcpuclockid() function shall return in the clock ID of the CPU-time clock of the thread specified by thread_id, if the thread specified by thread_id exists. If success, it returns zero. If fails, an error number shall be returned to indicate the error. The pthread_getcpuclockid() may fail if: [ESRCH] The value specified by thread_id does not refer to an existing thread. posixtestsuite/conformance/interfaces/pthread_getcpuclockid/coverage.txt0100644000000000000000000000017510032235073026167 0ustar rootrootThis document defines the coverage for the pthread_getcpuclockid function: Assertion Tested? 1 YES 2 YES 3 YES Note: posixtestsuite/conformance/interfaces/pthread_getcpuclockid/2-1.sh0100755000000000000000000000071010032235073024464 0ustar rootroot #!/bin/sh # Copyright (c) 2004, Intel Corporation. All rights reserved. # Created by: crystal.xiong REMOVE-THIS AT intel DOT com # This file is licensed under the GPL license. For the full content # of this license, see the COPYING file at the top level of this # source tree. # Test pthread_getcpuclockid returns 0 on success. # This is tested implicitly via assertion 1. echo "Tested implicitly via assertion 1. See output for status" exit 0 posixtestsuite/conformance/interfaces/pthread_spin_trylock/0040755000000000000000000000000010515625230023537 5ustar rootrootposixtestsuite/conformance/interfaces/pthread_spin_trylock/4-1.c0100644000000000000000000000211507703374572024217 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test pthread_spin_trylock(pthread_spinlock_t *lock) * * Note: This case will always pass * * These functions may fail if: * [EINVAL] The value specified by lock does not refer to an initialized spin lock object. * */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include #include "posixtest.h" int main() { pthread_spinlock_t spinlock; int rc; /* attemp to lock an uninitalized spin lock */ rc = pthread_spin_trylock(&spinlock); if(rc == EINVAL) { printf("Correctly got EINVAL at pthread_spin_trylock()\n"); printf("Test PASSED\n"); } else { printf("Expected EINVAL, but get return code: %d,%s\n", rc, strerror(rc)); printf("Test PASSED: *Note: Returned incorrect value, but standard says 'may' fail\n"); } return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_spin_trylock/3-1.sh0100755000000000000000000000067107703374572024416 0ustar rootroot#!/bin/sh # Copyright (c) 2002, Intel Corporation. All rights reserved. # This file is licensed under the GPL license. For the full content # of this license, see the COPYING file at the top level of this # source tree. #The pthread_spin_trylock( ) function shall fail if: #[EBUSY] A thread currently holds the lock. # This is tested implicitly via assertion 1. echo "Tested implicitly via assertion 1. See output for status" exit 0 posixtestsuite/conformance/interfaces/pthread_spin_trylock/1-1.c0100644000000000000000000000564507703374572024227 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test pthread_spin_trylock(pthread_spinlock_t *lock) * * The function shall lock the spin lock referenced by 'lock' if it is not * held by any thread. Otherwise, the function shall fail. * * Steps: * 1. Initialize a pthread_spinlock_t object 'spinlock' with * pthread_spin_init() * 2. Main thread lock 'spinlock', using pthread_spin_trylock(), * should get the lock successfully. * 3. Create a child thread. The thread lock 'spinlock', * using pthread_spin_trylock(), shall fail with EBUSY. * 4. If the child spins on the lock, after 2 seconds, send SIGALRM to it. * 5. Child thread check its state in the signal handler. */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include "posixtest.h" static pthread_spinlock_t spinlock; volatile static int thread_state; int rc; #define NOT_CREATED_THREAD 1 #define ENTERED_THREAD 2 #define EXITING_THREAD 3 static void sig_handler() { if(thread_state == ENTERED_THREAD) { printf("Test FAILED: thread incorrectly spins on trylock\n"); exit(PTS_FAIL); } else { printf("UNRESOLVED: Unexpected child thread state %d\n", thread_state); exit(PTS_UNRESOLVED); } } static void* fn_chld(void *arg) { rc = 0; struct sigaction act; thread_state = ENTERED_THREAD; /* Set up child thread to handle SIGALRM */ act.sa_flags = 0; act.sa_handler = sig_handler; sigfillset(&act.sa_mask); sigaction(SIGALRM, &act, 0); /* thread: send SIGALRM to me after 2 seconds in case in spins on trylock */ alarm(2); printf("thread: attempt trylock\n"); rc = pthread_spin_trylock(&spinlock); pthread_exit(0); return NULL; } int main() { pthread_t child_thread; if(pthread_spin_init(&spinlock, PTHREAD_PROCESS_PRIVATE) != 0) { printf("main: Error at pthread_spin_init()\n"); return PTS_UNRESOLVED; } printf("main: attempt to trylock\n"); /* We should get the lock */ if(pthread_spin_trylock(&spinlock) != 0) { printf("Test FAILED: main cannot get spin lock when no one owns the lock\n"); return PTS_FAIL; } printf("main: acquired spin lock\n"); thread_state = NOT_CREATED_THREAD; printf("main: create thread\n"); if(pthread_create(&child_thread, NULL, fn_chld, NULL) != 0) { printf("main: Error creating child thread\n"); return PTS_UNRESOLVED; } /* Wait for thread to end execution */ pthread_join(child_thread, NULL); /* Check the return code of pthread_spin_trylock */ if(rc != EBUSY) { printf("Test FAILED: pthread_spin_trylock should return EBUSY, instead got error code:%d\n" , rc); return PTS_FAIL; } printf("thread: correctly returned EBUSY on trylock\n"); printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_spin_trylock/assertions.xml0100644000000000000000000000153007703374572026466 0ustar rootroot pthread_spin_trylock( ) function shall lock the spin lock referenced by lock if it is not held by any thread. Otherwise, the function shall fail. Upon successful completion, these functions shall return zero; otherwise, an error number shall be returned to indicate the error. The pthread_spin_trylock( ) function shall fail if: [EBUSY] A thread currently holds the lock. These functions may fail if: [EINVAL] The value specified by lock does not refer to an initialized spin lock object. These functions shall not return an error code of EINTR. posixtestsuite/conformance/interfaces/pthread_spin_trylock/coverage.txt0100644000000000000000000000020307703374572026102 0ustar rootrootThis document defines the coverage for the pthread_spin_trylock() function: Assertion Tested? 1 YES 2 YES 3 YES 4 YES NOTE: posixtestsuite/conformance/interfaces/pthread_spin_trylock/2-1.sh0100755000000000000000000000074607703374572024420 0ustar rootroot#!/bin/sh # Copyright (c) 2002, Intel Corporation. All rights reserved. # This file is licensed under the GPL license. For the full content # of this license, see the COPYING file at the top level of this # source tree. #If successful, the pthread_spin_trylock( ) function shall return zero; otherwise, an error #number shall be returned to indicate the error. # This is tested implicitly via assertion 1. echo "Tested implicitly via assertion 1. See output for status" exit 0 posixtestsuite/conformance/interfaces/pthread_attr_getscope/0040755000000000000000000000000010515625177023674 5ustar rootrootposixtestsuite/conformance/interfaces/pthread_attr_getscope/1-1.c0100644000000000000000000000423110030002570024305 0ustar rootroot/* * Copyright (c) 2004, Intel Corporation. All rights reserved. * Created by: crystal.xiong REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test pthread_attr_getscope() * * Steps: * 1. Initialize a pthread_attr_t object using pthread_attr_init() * 2. Call pthread_attr_setscope with contentionscope parameter * 3. Call pthread_attr_getscope to get the contentionscope * NOTE: The contension scope value is a may requirement. * */ #include #include #include #include "posixtest.h" #define TEST "1-1" #define FUNCTION "pthread_attr_getscope" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " #define SYSTEMSCOPE PTHREAD_SCOPE_SYSTEM #define PROCESSSCOPE PTHREAD_SCOPE_PROCESS int verify_scope(pthread_attr_t *attr, int scopetype) { int rc; int scope; rc = pthread_attr_getscope(attr, &scope); if( rc != 0) { perror(ERROR_PREFIX "pthread_attr_getscope"); exit(PTS_UNRESOLVED); } switch(scopetype) { case SYSTEMSCOPE: if (scope != SYSTEMSCOPE) { perror(ERROR_PREFIX "got wrong scope param"); exit(PTS_FAIL); } break; case PROCESSSCOPE: if (scope != PROCESSSCOPE) { perror(ERROR_PREFIX "got wrong scope param"); exit(PTS_FAIL); } break; } return 0; } int main() { int rc=0; pthread_attr_t attr; rc = pthread_attr_init(&attr); if( rc != 0) { perror(ERROR_PREFIX "pthread_attr_init"); exit(PTS_UNRESOLVED); } rc = pthread_attr_setscope(&attr, SYSTEMSCOPE); if( rc != 0) { perror(ERROR_PREFIX "PTHREAD_SCOPE_SYSTEM is not supported"); } else { verify_scope(&attr, SYSTEMSCOPE); } rc = pthread_attr_setscope(&attr, PROCESSSCOPE); if( rc != 0) { perror(ERROR_PREFIX "PTHREAD_SCOPE_SYSTEM is not supported"); } else { verify_scope(&attr, PROCESSSCOPE); } rc = pthread_attr_destroy(&attr); if( rc != 0) { perror(ERROR_PREFIX "pthread_attr_destroy"); exit(PTS_UNRESOLVED); } printf("Test PASS\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_attr_getscope/assertions.xml0100644000000000000000000000114610030002570026561 0ustar rootroot pthread_attr_getscope shall get the inheritsched attribute in the attr argument The contentionscope attribute may have the values PTHREAD_SCOPE_SYSTEM, signifying system scheduling contention scope, or PTHREAD_SCOPE_PROCESS, signifying process scheduling contention scope. If succesful, the pthread_attr_getscope shall return zero. If fail, the pthread_attr_getscope shall return an error number. posixtestsuite/conformance/interfaces/pthread_attr_getscope/coverage.txt0100644000000000000000000000020110030002570026170 0ustar rootrootThis document defines the coverage for the pthread_attr_getscope function: Assertion Tested? 1 YES 2 YES 3 won't test NOTE: posixtestsuite/conformance/interfaces/pthread_attr_getscope/2-1.sh0100755000000000000000000000071010030002570024477 0ustar rootroot #!/bin/sh # Copyright (c) 2004, Intel Corporation. All rights reserved. # Created by: crystal.xiong REMOVE-THIS AT intel DOT com # This file is licensed under the GPL license. For the full content # of this license, see the COPYING file at the top level of this # source tree. # Test pthread_attr_getscope returns 0 on success. # This is tested implicitly via assertion 1. echo "Tested implicitly via assertion 1. See output for status" exit 0 posixtestsuite/conformance/interfaces/pthread_setschedprio/0040755000000000000000000000000010515625227023521 5ustar rootrootposixtestsuite/conformance/interfaces/pthread_setschedprio/1-1.c0100644000000000000000000000475210035441001024147 0ustar rootroot/* * Copyright (c) 2004, Intel Corporation. All rights reserved. * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * adam.li@intel.com * * The pthread_getschedparam( ) function shall retrieve the scheduling * policy and scheduling parameters for the thread whose thread ID is * given by thread and shall store those values in * policy and param, respectively. The priority value returned from * pthread_getschedparam( ) shall be * the value specified by the most recent pthread_setschedparam( ), * pthread_setschedprio( ), or pthread_create( ) call affecting the * target thread. It shall not reflect any temporary adjustments to * its priority as a result of any priority inheritance or ceiling functions. * */ /* Set the sched parameter with pthread_setschedprio then get */ #include #include #include #include "posixtest.h" void *a_thread_func() { struct sched_param sparam; int policy, priority, policy_1; int rc; policy = SCHED_FIFO; priority = sched_get_priority_min(policy); sparam.sched_priority = priority; rc = pthread_setschedparam(pthread_self(), policy, &sparam); if (rc != 0) { printf("Error at pthread_setschedparam: rc=%d\n", rc); exit(PTS_UNRESOLVED); } rc = pthread_getschedparam(pthread_self(), &policy_1, &sparam); if (rc != 0) { printf("Error at pthread_getschedparam: rc=%d\n", rc); exit(PTS_UNRESOLVED); } printf("policy: %d, priority: %d\n", policy_1, sparam.sched_priority); if (policy_1 != policy || sparam.sched_priority != priority) { printf("pthread_getschedparam did not get the correct value\n"); exit(PTS_UNRESOLVED); } rc = pthread_setschedprio(pthread_self(), priority + 1); if (rc != 0) { printf("Error at pthread_setschedprio: rc=%d\n", rc); exit(PTS_FAIL); } rc = pthread_getschedparam(pthread_self(), &policy_1, &sparam); if (rc != 0) { printf("Error at pthread_getschedparam: rc=%d\n", rc); exit(PTS_UNRESOLVED); } printf("policy: %d, priority: %d\n", policy_1, sparam.sched_priority); if (sparam.sched_priority != (priority + 1)) { printf("Priority is not set correctly\n"); exit(PTS_FAIL); } pthread_exit(0); return NULL; } int main() { pthread_t new_th; if(pthread_create(&new_th, NULL, a_thread_func, NULL) != 0) { perror("Error creating thread\n"); return PTS_UNRESOLVED; } pthread_join(new_th, NULL); printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_setschedprio/assertions.xml0100644000000000000000000000250110035441001026407 0ustar rootroot pthread_setschedprio( ) function shall set the scheduling priority for the thread whose thread ID is given by thread to the value given by prio. See Scheduling Policies (on page 44) for a description on how this function call affects the ordering of the thread in the thread list for its new priority. If the pthread_setschedprio( ) function fails, the scheduling priority of the target thread shall not be changed. If successful, the pthread_setschedprio( ) function shall return zero; otherwise, an error number shall be returned to indicate the error. If a thread whose policy or priority has been modified by pthread_setschedprio( ) is a running thread or is runnable, the effect on its position in the thread list depends on the direction of the modification, as follows: a. If the priority is raised, the thread becomes the tail of the thread list. b. If the priority is unchanged, the thread does not change position in the thread list. c. If the priority is lowered, the thread becomes the head of the thread list. posixtestsuite/conformance/interfaces/pthread_setschedprio/coverage.txt0100644000000000000000000000023410035441001026030 0ustar rootrootThis document defines the coverage for the pthread_setschedprio() function: Assertion Tested? 1 YES 2 NO 3 YES *Tested implictly by 1-1 4 NO Note: posixtestsuite/conformance/interfaces/sigrelse/0040755000000000000000000000000010515625266021136 5ustar rootrootposixtestsuite/conformance/interfaces/sigrelse/3-4.sh0100755000000000000000000000063007631521317021771 0ustar rootroot#!/bin/sh # Copyright (c) 2003, Intel Corporation. All rights reserved. # Created by: salwan.searty REMOVE-THIS AT intel DOT com # This file is licensed under the GPL license. For the full content # of this license, see the COPYING file at the top level of this # source tree. # # Test various methods of adding invalid signals to sigrelse(). # conformance/interfaces/sigrelse/3-core-buildonly.test 4 posixtestsuite/conformance/interfaces/sigrelse/3-3.sh0100755000000000000000000000063007631521317021770 0ustar rootroot#!/bin/sh # Copyright (c) 2003, Intel Corporation. All rights reserved. # Created by: salwan.searty REMOVE-THIS AT intel DOT com # This file is licensed under the GPL license. For the full content # of this license, see the COPYING file at the top level of this # source tree. # # Test various methods of adding invalid signals to sigrelse(). # conformance/interfaces/sigrelse/3-core-buildonly.test 3 posixtestsuite/conformance/interfaces/sigrelse/3-1.sh0100755000000000000000000000063007631521317021766 0ustar rootroot#!/bin/sh # Copyright (c) 2003, Intel Corporation. All rights reserved. # Created by: salwan.searty REMOVE-THIS AT intel DOT com # This file is licensed under the GPL license. For the full content # of this license, see the COPYING file at the top level of this # source tree. # # Test various methods of adding invalid signals to sigrelse(). # conformance/interfaces/sigrelse/3-core-buildonly.test 1 posixtestsuite/conformance/interfaces/sigrelse/1-1.c0100644000000000000000000000314607637667507021620 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: salwan.searty REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Steps: 1. Set up a handler for signal SIGABRT, such that it is called if signal is ever raised. 2. Call sighold on that SIGABRT. 3. Raise a SIGABRT and verify that the signal handler was not called. Otherwise, the test exits with unresolved results. 4. Call sigrelse on SIGABRT. 5. Verify that the handler gets called this time. */ #define _XOPEN_SOURCE 600 #include #include #include #include "posixtest.h" int handler_called = 0; void handler(int signo) { handler_called = 1; } int main() { struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); if (sigaction(SIGABRT, &act, 0) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } sighold(SIGABRT); if (raise(SIGABRT) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (handler_called) { printf("UNRESOLVED. possible problem in sigrelse\n"); return PTS_UNRESOLVED; } if (sigrelse(SIGABRT) == -1) { printf("UNRESOLVED. possible problem in sigrelse\n"); return PTS_UNRESOLVED; } sleep(1); if (handler_called) { printf("PASS: SIGABRT successfully removed from signal mask\n"); return PTS_PASS; } printf("FAIL\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sigrelse/3-2.sh0100755000000000000000000000063007631521317021767 0ustar rootroot#!/bin/sh # Copyright (c) 2003, Intel Corporation. All rights reserved. # Created by: salwan.searty REMOVE-THIS AT intel DOT com # This file is licensed under the GPL license. For the full content # of this license, see the COPYING file at the top level of this # source tree. # # Test various methods of adding invalid signals to sigrelse(). # conformance/interfaces/sigrelse/3-core-buildonly.test 2 posixtestsuite/conformance/interfaces/sigrelse/3-core-buildonly.c0100644000000000000000000000464407656062025024376 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: salwan.searty REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Testing passing an invalid signals to sigrelse(). After sighold is called on an invalid signal, sigrelse() should return -1 and set errno to EINVAL The invalid signal passed to sigrelse() depends on the argument passed to this program. There are currently 4 invalid signals. */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include "posixtest.h" jmp_buf sig11_recover; void sig11_handler(int sig); int main(int argc, char *argv[]) { int signo, TEST_RETURN; struct sigaction sa, osa; if (argc < 2) { printf("Usage: %s [1|2|3|4]\n", argv[0]); return PTS_UNRESOLVED; } /* Various error conditions */ switch (argv[1][0]) { case '1': signo=-1; break; case '2': signo=-10000; break; case '3': signo=INT32_MIN+1; break; case '4': signo=INT32_MIN; break; default: printf("Usage: %s [1|2|3|4]\n", argv[0]); return PTS_UNRESOLVED; } /* special sig11 case */ sa.sa_handler = &sig11_handler; sigemptyset(&sa.sa_mask); sa.sa_flags = 0; sigaction(SIGSEGV, NULL, &osa); sigaction(SIGSEGV, &sa, NULL); if (setjmp(sig11_recover)) { errno = EINVAL; TEST_RETURN=-2; } else { TEST_RETURN=sigrelse(signo); } sigaction(SIGSEGV, &osa, NULL); if (TEST_RETURN == -1) { if (EINVAL == errno) { printf ("errno set to EINVAL\n"); return PTS_PASS; } else { printf ("errno not set to EINVAL\n"); return PTS_FAIL; } } if (TEST_RETURN == -2) { printf ("test received SIGSEGV\n"); return PTS_UNRESOLVED; } printf("sigrelse did not return -1\n"); return PTS_FAIL; } /****************************************************************** * sig11_handler() - our segfault recover hack ******************************************************************/ void sig11_handler(int sig) { longjmp(sig11_recover, 1); } posixtestsuite/conformance/interfaces/sigrelse/assertions.xml0100644000000000000000000000076507631521317024054 0ustar rootroot The sigrelse () function removes a signal sig from the signal mask of the calling process. sigrelse will return 0 upon successful completion. If the function is passed an illegal signal number, then errno will be set to [EINVAL], and sigrelse() will return -1. posixtestsuite/conformance/interfaces/sigrelse/coverage.txt0100644000000000000000000000014507631521317023464 0ustar rootrootThis document defines the coverage for function sigrelse(). Assertion Covered? 1 YES 2 YES 3 YES posixtestsuite/conformance/interfaces/sigrelse/2-1.c0100644000000000000000000000115007631521317021570 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: salwan.searty REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Simply, if sigrelse returns a 0 here, test passes. */ #define _XOPEN_SOURCE 600 #include #include #include "posixtest.h" int main() { if ((int)sigrelse(SIGABRT) != 0) { perror("sigrelse failed -- returned -- test aborted"); return PTS_UNRESOLVED; } printf("sigrelse passed\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_spin_lock/0040755000000000000000000000000010515625230023000 5ustar rootrootposixtestsuite/conformance/interfaces/pthread_spin_lock/1-1.c0100644000000000000000000001015010307606012023430 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test pthread_spin_lock(pthread_spinlock_t *lock) * * The function shall lock the spin lock referenced by lock. The calling thread * shall acquire the lock if it is not held by another thread. Otherwise, the * thread shall spin (that is, shall not return from the pthread_spin_lock()) * until the lock becomes available. * * Steps: * 1. Initialize a pthread_spinlock_t object 'spinlock' with * pthread_spin_init() * 2. Main thread lock 'spinlock', should get the lock * 3. Create a child thread. The thread lock 'spinlock', should spin. * 4. After child thread spin for 2 seconds, send SIGALRM to it. * 5. Child thread check its status in the signal handler. */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include "posixtest.h" static pthread_spinlock_t spinlock; volatile static int thread_state; #define NOT_CREATED_THREAD 1 #define ENTERED_THREAD 2 #define EXITING_THREAD 3 #define GET_SPIN_LOCK 4 static void sig_handler() { /* Just return */ pthread_exit(0); return; } static void* fn_chld(void *arg) { int rc = 0; struct sigaction act; struct timespec ts; thread_state = ENTERED_THREAD; int cnt = 0; /* Unblock the SIGALRM signal for the thread */ sigemptyset (&act.sa_mask); sigaddset(&act.sa_mask, SIGALRM); if (pthread_sigmask (SIG_UNBLOCK, &act.sa_mask, NULL)) { perror("thread: could not unblock SIGALRM\n"); return (void *)PTS_UNRESOLVED; } /* Set up child thread to handle SIGALRM */ act.sa_flags = 0; act.sa_handler = sig_handler; sigfillset(&act.sa_mask); sigaction(SIGALRM, &act, 0); printf("thread: send SIGALRM to me after 2 secs\n"); alarm(2); printf("thread: attempt spin lock\n"); rc = pthread_spin_lock(&spinlock); if(rc != 0) { printf("Test FAILED: thread failed to get spin lock,error code:%d\n" , rc); pthread_exit((void*)PTS_FAIL); } printf("thread: acquired spin lock\n"); thread_state = GET_SPIN_LOCK; /* Wait 10 seconds for SIGALRM to be sent */ while( cnt++ < 10) { ts.tv_sec = 1; ts.tv_nsec = 0; nanosleep(&ts, NULL); } /* Shouldn't get here. If we do, it means that SIGALRM wasn't sent/received */ printf("Error in thread: SIGALRM was not received/sent correctly, timedout after 10 secs of waiting.\n"); pthread_exit((void*)PTS_UNRESOLVED); return NULL; } int main() { pthread_t child_thread; void *value_ptr; struct sigaction sa; /* Block the SIGALRM signal for main thread */ sigemptyset (&sa.sa_mask); sigaddset(&sa.sa_mask, SIGALRM); if (pthread_sigmask (SIG_BLOCK, &sa.sa_mask, NULL)) { perror("main: could not block SIGALRM\n"); return PTS_UNRESOLVED; } if(pthread_spin_init(&spinlock, PTHREAD_PROCESS_PRIVATE) != 0) { perror("main: Error at pthread_spin_init()\n"); return PTS_UNRESOLVED; } printf("main: attempt spin lock\n"); /* We should get the lock */ if(pthread_spin_lock(&spinlock) != 0) { printf("Test FAILED: main cannot get spin lock when no one owns the lock\n"); return PTS_FAIL; } printf("main: acquired spin lock\n"); thread_state = NOT_CREATED_THREAD; printf("main: create thread\n"); if(pthread_create(&child_thread, NULL, fn_chld, NULL) != 0) { printf("main: Error creating child thread\n"); return PTS_UNRESOLVED; } /* Wait for thread to end execution */ if(pthread_join(child_thread, &value_ptr) != 0) { perror("Error in pthread_join()\n"); return PTS_UNRESOLVED; } /* Check the return value of the thread */ if(thread_state == GET_SPIN_LOCK) { printf("Test FAILED: Child thread did not spin on spin lock when other thread holds the lock\n"); exit(PTS_FAIL); } else if(thread_state == ENTERED_THREAD) { printf("thread: spins on spin lock\n"); printf("Test PASSED\n"); exit(PTS_PASS); } else { printf("Unexpected child thread state: %d\n", thread_state); exit(PTS_UNRESOLVED); } } posixtestsuite/conformance/interfaces/pthread_spin_lock/3-2.c0100644000000000000000000000331207703140567023453 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test pthread_spin_lock(pthread_spinlock_t *lock) * * 35543 These functions may fail if: * 35544 [EINVAL] The value specified by lock does not * refer to an initialized spin lock object. * * This case will always pass. */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include #include "posixtest.h" int rc; static void sig_handler() { printf("main: interrupted by SIGALARM\n"); if(rc == EINVAL) { printf("main: correctly got EINVAL\n"); printf("Test PASSED\n"); } else { printf("main: get return code: %d, %s\n", rc, strerror(rc)); printf("Test PASSED: *Note: Did not return EINVAL when attempting to lock an uninitialized spinlock, but standard says 'may' fail\n"); } exit(PTS_PASS); } int main() { pthread_spinlock_t spinlock; struct sigaction act; /* Set up child thread to handle SIGALRM */ act.sa_flags = 0; act.sa_handler = sig_handler; sigfillset(&act.sa_mask); sigaction(SIGALRM, &act, 0); printf("main: attemp to lock an un-initialized spin lock\n"); printf("main: Send SIGALRM to me after 5 secs\n"); alarm(5); /* Attempt to lock an uninitialized spinlock */ rc = pthread_spin_lock(&spinlock); /* If we get here, call sig_handler() to check the return code of * pthread_spin_lock() */ sig_handler(); /* Unlock spinlock */ pthread_spin_unlock(&spinlock); /* Destroy spinlock */ pthread_spin_destroy(&spinlock); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_spin_lock/1-2.c0100644000000000000000000000757007703137446023465 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test pthread_spin_lock(pthread_spinlock_t *lock) * * The function shall lock the spin lock referenced by lock. The calling thread * shall acquire the lock if it is not held by another thread. Otherwise, the * thread shall spin (that is, shall not return from the pthread_spin_lock()) * until the lock becomes available. * * Steps: * 1. Initialize a pthread_spinlock_t object 'spinlock' with * pthread_spin_init() * 2. Main thread lock 'spinlock', should get the lock * 3. Create a child thread. The thread lock 'spinlock', should spin. * 4. Main thread unlock 'spinlock' * 5. Child thread should get 'spinlock' */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include "posixtest.h" static pthread_spinlock_t spinlock; volatile static int thread_state; #define NOT_CREATED_THREAD 1 #define ENTERED_THREAD 2 #define EXITING_THREAD 3 static void* fn_chld(void *arg) { int rc = 0; thread_state = ENTERED_THREAD; /* Lock the spinlock */ printf("thread: attempt spin lock\n"); rc = pthread_spin_lock(&spinlock); if(rc != 0) { printf("Test FAILED: child failed to get spin lock,error code:%d\n" , rc); exit(PTS_FAIL); } printf("thread: acquired spin lock\n"); /* Just some time between locking and unlocking */ sleep(1); /* Unlock the spin lock */ printf("thread: unlock spin lock\n"); if(pthread_spin_unlock(&spinlock)) { printf("child: Error at pthread_spin_unlock()\n"); exit(PTS_UNRESOLVED); } thread_state = EXITING_THREAD; pthread_exit(0); return NULL; } int main() { int cnt = 0; pthread_t child_thread; /* Initialize spinlock */ if(pthread_spin_init(&spinlock, PTHREAD_PROCESS_PRIVATE) != 0) { printf("main: Error at pthread_spin_init()\n"); return PTS_UNRESOLVED; } printf("main: attempt spin lock\n"); /* We should get the lock */ if(pthread_spin_lock(&spinlock) != 0) { printf("Test FAILED: main cannot get spin lock when no one owns the lock\n"); return PTS_FAIL; } printf("main: acquired spin lock\n"); /* Initialize thread state */ thread_state = NOT_CREATED_THREAD; /* Create thread */ printf("main: create thread\n"); if(pthread_create(&child_thread, NULL, fn_chld, NULL) != 0) { printf("main: Error creating child thread\n"); return PTS_UNRESOLVED; } cnt = 0; /* Expect the child thread to spin on spin lock. Wait for 3 seconds. */ do{ sleep(1); }while (thread_state != EXITING_THREAD && cnt++ < 3); if(thread_state == EXITING_THREAD) { printf("Test FAILED: child thread did not spin on spin lock when other thread holds the lock\n"); return PTS_FAIL; } else if(thread_state != ENTERED_THREAD) { printf("main: Unexpected thread state %d\n", thread_state); return PTS_UNRESOLVED; } printf("main: unlock spin lock\n"); if(pthread_spin_unlock(&spinlock) != 0) { printf("main: Error at pthread_spin_unlock()\n"); return PTS_UNRESOLVED; } /* We expected the child get the spin lock and exit */ cnt = 0; do{ sleep(1); }while (thread_state != EXITING_THREAD && cnt++ < 3); if(thread_state == ENTERED_THREAD) { printf("Test FAILED: child thread did not get spin lock\n"); return PTS_FAIL; } else if(thread_state != EXITING_THREAD) { printf("main: Unexpected thread state %d\n", thread_state); return PTS_UNRESOLVED; } /* Wait for thread to finish execution */ if(pthread_join(child_thread, NULL) != 0) { printf("main: Error at pthread_join()\n"); return PTS_UNRESOLVED; } /* Destroy the spinlock */ if(pthread_spin_destroy(&spinlock) != 0) { printf("Error at pthread_spin_destroy()"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_spin_lock/assertions.xml0100644000000000000000000000155607703137446025734 0ustar rootroot The function shall lock the spin lock referenced by lock. The calling thread shall acquire the lock if it is not held by another thread. Otherwise, the thread shall spin (that is, shall not return from the pthread_spin_lock()) until the lock becomes available. Upon successful completion, these functions shall return zero; otherwise, an error number shall be returned to indicate the error. The pthread_spin_lock( ) function may fail if: [EDEADLK] The calling thread already holds the lock. [EINVAL] The value specified by lock does not refer to an initialized spin lock object. These functions shall not return an error code of EINTR. posixtestsuite/conformance/interfaces/pthread_spin_lock/coverage.txt0100644000000000000000000000017107703137446025344 0ustar rootrootThis document defines the coverage for the pthread_spin_lock() function: Assertion Tested? 1 YES 2 YES 3 YES NOTE: posixtestsuite/conformance/interfaces/pthread_spin_lock/2-1.sh0100755000000000000000000000074107703137446023651 0ustar rootroot#!/bin/sh # Copyright (c) 2002, Intel Corporation. All rights reserved. # This file is licensed under the GPL license. For the full content # of this license, see the COPYING file at the top level of this # source tree. # Upon successful completion, these functions shall return zero; # otherwise, an error number shall be returned to indicate the error. # This is tested implicitly via assertion 1. echo "Tested implicitly via assertion 1. See output for status" exit 0 posixtestsuite/conformance/interfaces/pthread_spin_lock/3-1.c0100644000000000000000000000415607703140567023461 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test pthread_spin_lock(pthread_spinlock_t *lock) * * The pthread_spin_lock( ) function may fail if: * [EDEADLK] The calling thread already holds the lock. * * This case will always pass. The thread might keep spin * when re-lock the spin lock. * */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include #include "posixtest.h" static void sig_handler() { printf("main: interrupted by SIGALARM\n"); printf("Test PASSED: *Note: Did not return EDEADLK when re-locking a spinlock already in use, but standard says 'may' fail\n"); pthread_exit((void*)PTS_PASS); } int main() { int rc; pthread_spinlock_t spinlock; struct sigaction act; /* Set up child thread to handle SIGALRM */ act.sa_flags = 0; act.sa_handler = sig_handler; sigfillset(&act.sa_mask); sigaction(SIGALRM, &act, 0); if(pthread_spin_init(&spinlock, PTHREAD_PROCESS_PRIVATE) != 0) { printf("main: Error at pthread_spin_init()\n"); return PTS_UNRESOLVED; } printf("main: attempt spin lock\n"); /* We should get the lock */ if(pthread_spin_lock(&spinlock) != 0) { printf("Test FAILED: main cannot get spin lock when no one owns the lock\n"); return PTS_FAIL; } printf("main: acquired spin lock\n"); printf("main: send SIGALRM to me after 2 secs\n"); alarm(2); printf("main: re-lock spin lock\n"); rc = pthread_spin_lock(&spinlock); if(rc == EDEADLK) { printf("main: correctly got EDEADLK when re-locking the spin lock\n"); printf("Test PASSED\n"); } else { printf("main: get return code: %d , %s\n", rc, strerror(rc)); printf("Test PASSED: *Note: Did not return EDEADLK when re-locking a spinlock already in use, but standard says 'may' fail\n"); } /* Unlock spinlock */ pthread_spin_unlock(&spinlock); /* Destroy spinlock */ pthread_spin_destroy(&spinlock); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_rwlock_timedwrlock/0040755000000000000000000000000010515625224024727 5ustar rootrootposixtestsuite/conformance/interfaces/pthread_rwlock_timedwrlock/6-2.c0100644000000000000000000001355710021017163025374 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test pthread_rwlock_timedwrlock(pthread_rwlock_t * rwlock) * * If a signal that causes a signal handler to be executed is delivered to * a thread blocked on a read-write lock via a call to pthread_rwlock_timedwrlock( ), * upon return from the signal handler the thread shall resume waiting for the lock * as if it was not interrupted. * * Steps: * 1. main thread create read-write lock 'rwlock', and lock it for writing * 2. main thread create a thread sig_thread, the thread is set to handle SIGUSR1 * 3. sig_thread timed lock 'rwlock' for writing, but blocked * 4. While the sig_thread is waiting(not expried yet), main thread send SIGUSR1 * to sig_thread via pthread_kill * 5. test that thread handler is called, inside the handler, make the thread sleep * for a period that the specified 'timeout' for pthread_rwlock_timedwrlock() * should have expired (timeout * 2) * 6. While sig_thread sleeping in signal handler, main thread unlock 'rwlock' * 7. check that when thread handler returns, sig_thread get the read lock without * getting ETIMEDOUT. */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include #include #include "posixtest.h" /* thread_state indicates child thread state: 1: not in child thread yet; 2: just enter child thread ; 3: just before child thread exit; */ #define NOT_CREATED_THREAD 1 #define ENTERED_THREAD 2 #define EXITING_THREAD 3 #define TIMEOUT 2 static pthread_t sig_thread; static pthread_rwlock_t rwlock; static int thread_state; static int handler_state; static int expired; static struct timeval before_wait, after_wait; static void sig_handler() { struct timespec sleep_time_req; sleep_time_req.tv_sec = TIMEOUT*2; sleep_time_req.tv_nsec = 0; if(pthread_equal(pthread_self(), sig_thread)) { printf("sig_handler: signal is handled by thread\n"); /* sig_handler will not sleep 2 times more than the timeout for the * pthread_rwlock_timerdlock is waiting for */ printf("sig_handler: sleeping for %d seconds\n", (int)sleep_time_req.tv_sec); handler_state = 2; sleep((int)sleep_time_req.tv_sec); } else { printf("sig_handler: signal is not handled by thread\n"); exit(PTS_UNRESOLVED); } handler_state = 3; } static void * th_fn(void *arg) { struct sigaction act; struct timespec abs_timeout; int rc; handler_state = 2; expired = 0; /* Set up handler for SIGUSR1 */ act.sa_flags = 0; act.sa_handler = sig_handler; /* block all the signal when hanlding SIGUSR1 */ sigfillset(&act.sa_mask); sigaction(SIGUSR1, &act, 0); gettimeofday(&before_wait, NULL); abs_timeout.tv_sec = before_wait.tv_sec + TIMEOUT; abs_timeout.tv_nsec = before_wait.tv_usec * 1000; thread_state = ENTERED_THREAD; printf("thread: attempt timed write lock, %d seconds\n", TIMEOUT); rc = pthread_rwlock_timedwrlock(&rwlock, &abs_timeout); if(rc == 0) { printf("thread: correctly acquired write lock\n"); expired = 0; } else if(rc == ETIMEDOUT) { printf("thread: timer expired, did not acquire write lock"); expired = 1; } else { printf("Error %d at pthread_rwlock_timedwrlock()\n", rc); exit(PTS_UNRESOLVED); } gettimeofday(&after_wait, NULL); thread_state = EXITING_THREAD; pthread_exit(0); return NULL; } int main() { int cnt; if(pthread_rwlock_init(&rwlock, NULL) != 0) { printf("Error at pthread_rwlock_init()\n"); return PTS_UNRESOLVED; } printf("main: attempt write lock\n"); if(pthread_rwlock_wrlock(&rwlock) != 0) { printf("pthread_rwlock_wrlock()\n"); return PTS_UNRESOLVED; } printf("main: acquired write lock\n"); thread_state = NOT_CREATED_THREAD; if(pthread_create(&sig_thread, NULL, th_fn, NULL) != 0) { printf("Error at pthread_create()\n"); return PTS_UNRESOLVED; } /* wait for the thread to get ready for handling signal */ cnt = 0; do{ sleep(1); }while(thread_state != ENTERED_THREAD && cnt++ < TIMEOUT); if(thread_state != ENTERED_THREAD) { printf("Error: thread did not block when getting write lock\n"); exit(PTS_UNRESOLVED); } printf("main: fire SIGUSR1 to thread\n"); if(pthread_kill(sig_thread, SIGUSR1) != 0) { printf("Error in pthread_kill()"); exit(PTS_UNRESOLVED); } /* Wait for signal handler to sleep so that main can unlock the rwlock while * it is sleeping. (this way, the rwlock will be unlocked when the signal handler * returns, and control is given back to the thread) */ cnt = 0; do{ sleep(TIMEOUT); }while(handler_state !=2 && cnt++ < 2); if(handler_state == 1) { printf("Error: signal handler did not get called\n"); exit(PTS_UNRESOLVED); } else if(handler_state == 3) { printf("Error: signal handler incorrectly exited\n"); exit(PTS_UNRESOLVED); } if(expired == 1) { printf("Error: thread timeout in sig_handler\n"); exit(PTS_UNRESOLVED); } printf("main: unlock write lock\n"); if(pthread_rwlock_unlock(&rwlock) != 0) { printf("Error at pthread_rwlock_unlock()\n"); exit(PTS_UNRESOLVED); } /* wait at most 4*TIMEOUT seconds for thread to exit */ cnt = 0; do{ sleep(1); }while(thread_state != EXITING_THREAD && cnt++ < 4*TIMEOUT); if(cnt >= 4*TIMEOUT) { /* thread blocked*/ printf("Test FAILED: thread blocked even afer the abs_timeout expires\n"); exit(PTS_FAIL); } if(expired == 1) { printf("Test FAILED: thread should get the write lock\n"); exit(PTS_FAIL); } if(pthread_join(sig_thread, NULL) != 0) { printf("Error at pthread_join()"); return PTS_UNRESOLVED; } if(pthread_rwlock_destroy(&rwlock) != 0) { printf("Error at pthread_destroy()"); exit(PTS_UNRESOLVED); } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_rwlock_timedwrlock/5-1.c0100644000000000000000000001316007672160417025403 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_rwlock_timedwrlock(pthread_rwlock_t *rwlock) * * Under no circumstances shall the function fail with a timeout if the lock can be * acquired immediately. The abs_timeout parameter need not be checked if the lock * can be immediately acquired. * * Steps: * 1. Main thread create a thread. * 2. Child thread lock 'rwlock' for writing with pthread_rwlock_timedwrlock(), * should not fail with timeout * 3. The child thread unlocks the 'rwlock' and exit. * 4. Main thread create another thread. * 5. The child thread lock 'rwlock' for write, with pthread_rwlock_timedwrlock(), * specifying a 'abs_timeout'. The thread sleeps untile 'abs_timeout' expires. * 6. The thread call pthread_rwlock_timedwrlock(). Should not get ETIMEDOUT. */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include "posixtest.h" #define TIMEOUT 1 static int thread_state; static int currsec1; static int expired; /* thread_state indicates child thread state: 1: not in child thread yet; 2: just enter child thread ; 3: just before child thread exit; */ #define NOT_CREATED_THREAD 1 #define ENTERED_THREAD 2 #define EXITING_THREAD 3 static void* fn_wr_1(void *arg) { thread_state = ENTERED_THREAD; struct timespec abs_timeout; int rc; pthread_rwlock_t rwlock; if(pthread_rwlock_init(&rwlock, NULL) != 0) { printf("thread1: Error at pthread_rwlock_init\n"); exit(PTS_UNRESOLVED); } currsec1 = time(NULL); /* Absolute time, not relative. */ abs_timeout.tv_sec = currsec1 + TIMEOUT; abs_timeout.tv_nsec = 0; printf("thread1: attempt timed lock for writing\n"); rc = pthread_rwlock_timedwrlock(&rwlock, &abs_timeout); if(rc == ETIMEDOUT) { printf("thread1: timer expired\n"); expired = 1; } else if(rc == 0) { printf("thread1: acquired write lock\n"); expired = 0; printf("thread1: unlock write lock\n"); if(pthread_rwlock_unlock(&rwlock) != 0) { printf("thread1: failed to release write lock\n"); exit(PTS_UNRESOLVED); } } else { printf("thread1: Error in pthread_rwlock_timedwrlock().\n"); exit(PTS_UNRESOLVED); } if(pthread_rwlock_destroy(&rwlock) != 0) { printf("thread1: Error at pthread_rwlockattr_destroy()"); exit(PTS_UNRESOLVED); } thread_state = EXITING_THREAD; pthread_exit(0); return NULL; } static void* fn_wr_2(void *arg) { thread_state = ENTERED_THREAD; struct timespec abs_timeout; int rc; pthread_rwlock_t rwlock; if(pthread_rwlock_init(&rwlock, NULL) != 0) { printf("thread2: Error at pthread_rwlock_init\n"); exit(PTS_UNRESOLVED); } currsec1 = time(NULL); /* Absolute time, not relative. */ abs_timeout.tv_sec = currsec1 - TIMEOUT; abs_timeout.tv_nsec = 0; printf("thread2: attempt timed lock for writing\n"); rc = pthread_rwlock_timedwrlock(&rwlock, &abs_timeout); if(rc == ETIMEDOUT) { printf("thread2: timer expired\n"); expired = 1; } else if(rc == 0) { printf("thread2: acquired write lock\n"); expired = 0; printf("thread2: unlock write lock\n"); if(pthread_rwlock_unlock(&rwlock) != 0) { printf("thread2: failed to release write lock\n"); exit(PTS_UNRESOLVED); } } else { printf("thread2: Error in pthread_rwlock_timedwrlock().\n"); exit(PTS_UNRESOLVED); } if(pthread_rwlock_destroy(&rwlock) != 0) { printf("thread2: Error at pthread_rwlock_destroy()\n"); exit(PTS_UNRESOLVED); } thread_state = EXITING_THREAD; pthread_exit(0); return NULL; } int main() { int cnt = 0; pthread_t thread1, thread2; thread_state = NOT_CREATED_THREAD; printf("main: create thread1\n"); if(pthread_create(&thread1, NULL, fn_wr_1, NULL) != 0) { printf("Error when creating thread1\n"); return PTS_UNRESOLVED; } /* If the shared data is not altered by child after 5 seconds, we regard it as blocked */ /* we expect thread1 NOT to block */ cnt = 0; do{ sleep(1); }while (thread_state !=3 && cnt++ < 5); if(thread_state == 3) { /* the child thread does not block, check the time expired or not */ if(expired == 1) { printf("Test FAILED: thread1 got ETIMEOUT when get the lock\n"); return PTS_FAIL; } } else if(thread_state == ENTERED_THREAD) { printf("Test FAILED: thread1 blocked\n"); return PTS_FAIL; } else { printf("Unexpected state for thread1 %d\n", thread_state); return PTS_UNRESOLVED; } if(pthread_join(thread1, NULL) != 0) { printf("Error when joining thread1\n"); return PTS_UNRESOLVED; } thread_state = ENTERED_THREAD; printf("main: create thread2\n"); if(pthread_create(&thread2, NULL, fn_wr_2, NULL) != 0) { printf("Error when creating thread2\n"); return PTS_UNRESOLVED; } /* If the shared data is not altered by child after 5 seconds, we regard it as blocked */ /* we expect thread2 NOT to block */ cnt = 0; do{ sleep(1); }while (thread_state !=EXITING_THREAD && cnt++ < 3); if(thread_state == EXITING_THREAD) { /* the child thread does not block, check the time expired or not */ if(expired == 1) { printf("Test FAILED: thread2 got ETIMEOUT\n"); return PTS_FAIL; } } else if(thread_state == ENTERED_THREAD) { printf("Test FAILED: thread2 blocked\n"); return PTS_FAIL; } else { printf("Unexpected state for thread2 %d\n", thread_state); return PTS_UNRESOLVED; } if(pthread_join(thread2, NULL) != 0) { printf("Error when join thread2\n"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_rwlock_timedwrlock/7-1.sh0100755000000000000000000000106007672160417025574 0ustar rootroot#!/bin/sh # Copyright (c) 2002, Intel Corporation. All rights reserved. # This file is licensed under the GPL license. For the full content # of this license, see the COPYING file at the top level of this # source tree. # Test pthread_rwlock_timedwrlock() # Shall return zero if the lock for writing on the read-write lock object # referenced by rwlock is acquired. Otherwise, an error number shall be returned # to indicate the error # This is tested implicitly via assertion 1. echo "Tested implicitly via assertion 1. See output for status" exit 0 posixtestsuite/conformance/interfaces/pthread_rwlock_timedwrlock/1-1.c0100644000000000000000000001667310021017163025370 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_rwlock_timedwrlock(pthread_rwlock_t *rwlock) * * pthread_rwlock_timedwrlock( ) function shall apply a write lock to the * read-write lock referenced by rwlock as in the pthread_rwlock_wrlock( ) function. * However, if the lock cannot be acquired without waiting for other threads to * unlock the lock, this wait shall be terminate when the specified timeout expires. * * Steps: * 1. Initialize rwlock * 2. Main creats thread0. * 3. Thread0 does pthread_rwlock_timedwrlock(), should get the lock successfully then unlock. * 4. Main thread locks 'rwlock' for reading with pthread_rwlock_rdlock() * 5. Create a child thread, the thread time-locks 'rwlock' for writing, * using pthread_rwlock_timedwrlock(), should block, but when the timer expires, * that wait will be terminated. * 6. Main thread unlocks 'rwlock' * 7. Main thread locks 'rwlock' for writing. * 8. Create child thread to lock 'rwlock' for writing, using pthread_rwlock_timedwrlock, * it should block but when the timer expires, the wait will be terminated * 8. Main thread unlocks 'rwlock' */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include "posixtest.h" #define TIMEOUT 3 static pthread_rwlock_t rwlock; static int thread_state; static struct timeval currsec1, currsec2; static int expired; /* thread_state indicates child thread state: 1: not in child thread yet; 2: just enter child thread ; 3: just before child thread exit; */ #define NOT_CREATED_THREAD 1 #define ENTERED_THREAD 2 #define EXITING_THREAD 3 static void* fn_wr(void *arg) { struct timespec timeout; int rc; thread_state = ENTERED_THREAD; gettimeofday(&currsec1, NULL); /* Absolute time, not relative. */ timeout.tv_sec = currsec1.tv_sec + TIMEOUT; timeout.tv_nsec = currsec1.tv_usec * 1000; printf("thread: attempt timed write lock, %d secs\n", TIMEOUT); rc = pthread_rwlock_timedwrlock(&rwlock, &timeout); if(rc == ETIMEDOUT) { printf("thread: timer expired\n"); expired = 1; } else if(rc == 0) { printf("thread: acquired write lock\n"); expired = 0; printf("thread: unlock write lock\n"); if(pthread_rwlock_unlock(&rwlock) != 0) { printf("thread: error release write lock\n"); exit(PTS_UNRESOLVED); } } else { printf("thread: Error in pthread_rwlock_timedrdlock().\n"); exit(PTS_UNRESOLVED); } /* Get time after the mutex timed out in locking. */ gettimeofday(&currsec2, NULL); thread_state = EXITING_THREAD; pthread_exit(0); return NULL; } int main() { int cnt = 0; pthread_t thread0, thread1, thread2; if(pthread_rwlock_init(&rwlock, NULL) != 0) { printf("Error at pthread_rwlock_init()\n"); return PTS_UNRESOLVED; } printf("main: create thread0\n"); thread_state = NOT_CREATED_THREAD; if(pthread_create(&thread0, NULL, fn_wr, NULL) != 0) { printf("Error creating thread0\n"); return PTS_UNRESOLVED; } /* thread0 should not block at all since no one else has locked rwlock */ cnt = 0; expired = 0; do{ sleep(1); }while (thread_state !=EXITING_THREAD && cnt++ < 2*TIMEOUT); if(thread_state == EXITING_THREAD) { if(expired == 1) { printf("Test FAILED: the timer expired\n"); exit(PTS_FAIL); } else printf("thread0 correctly acquired the write lock.\n"); } else if(thread_state == ENTERED_THREAD) { printf("Test FAILED: thread0 incorrectly blocked on timedwrlock\n"); exit(PTS_FAIL); } else { printf("Unexpected state for thread0 %d\n", thread_state); exit(PTS_UNRESOLVED); } if(pthread_join(thread0, NULL) != 0) { printf("Error when joining thread0\n"); return PTS_UNRESOLVED; } printf("main: attempt read lock\n"); /* We have no lock, this read lock should succeed */ if(pthread_rwlock_rdlock(&rwlock) != 0) { printf("Error at pthread_rwlock_rdlock()\n"); return PTS_UNRESOLVED; } printf("main: acquired read lock\n"); thread_state = NOT_CREATED_THREAD; printf("main: create thread1\n"); if(pthread_create(&thread1, NULL, fn_wr, NULL) != 0) { printf("Error when creating thread1\n"); return PTS_UNRESOLVED; } /* If the shared data is not altered by child after TIMEOUT*2 seconds, we regard it as blocked */ /* we expect the thread to expire blocking after timeout*/ cnt = 0; do{ sleep(1); }while (thread_state !=EXITING_THREAD && cnt++ < 2*TIMEOUT); if(thread_state == EXITING_THREAD) { /* the child thread does not block, check the time interval */ struct timeval time_diff; time_diff.tv_sec = currsec2.tv_sec - currsec1.tv_sec; time_diff.tv_usec = currsec2.tv_usec - currsec1.tv_usec; if (time_diff.tv_usec < 0) { --time_diff.tv_sec; time_diff.tv_usec += 1000000; } if(time_diff.tv_sec < TIMEOUT) { printf("Test FAILED: the timer expired and blocking was terminated, but the timeout is not correct: expected to wait for %d, but waited for %ld.%06ld\n", TIMEOUT, (long)time_diff.tv_sec, (long)time_diff.tv_usec); exit(PTS_FAIL); } else printf("thread1 correctly expired at timeout.\n"); } else if(thread_state == ENTERED_THREAD) { printf("Test FAILED: wait is not terminated even when the timer expired\n"); exit(PTS_FAIL); } else { printf("Unexpected state for thread1 %d\n", thread_state); exit(PTS_UNRESOLVED); } printf("main: unlock read lock\n"); if(pthread_rwlock_unlock(&rwlock) != 0) { printf("Error when release read lock\n"); exit(PTS_UNRESOLVED); } if(pthread_join(thread1, NULL) != 0) { printf("Error when joining thread1\n"); return PTS_UNRESOLVED; } printf("main: attempt write lock\n"); if(pthread_rwlock_wrlock(&rwlock) != 0) { printf("Error at pthread_rwlock_wrlock()\n"); return PTS_UNRESOLVED; } printf("main: acquired write lock\n"); thread_state = NOT_CREATED_THREAD; cnt = 0; printf("main: create thread2\n"); if(pthread_create(&thread2, NULL, fn_wr, NULL) != 0) { printf("Error when creating thread2\n"); return PTS_UNRESOLVED; } /* we expect thread2 to expire blocking after timeout */ do{ sleep(1); }while (thread_state !=EXITING_THREAD && cnt++ < 2*TIMEOUT); if(thread_state == EXITING_THREAD) { /* the child thread does not block, check the time interval */ struct timeval time_diff; time_diff.tv_sec = currsec2.tv_sec - currsec1.tv_sec; time_diff.tv_usec = currsec2.tv_usec - currsec1.tv_usec; if (time_diff.tv_usec < 0) { --time_diff.tv_sec; time_diff.tv_usec += 1000000; } if(time_diff.tv_sec < TIMEOUT) { printf("Test FAILED: for thread 2, the timer expired and waiter terminated, but the timeout is not correct\n"); exit(PTS_FAIL); } else printf("thread2 correctly expired at timeout.\n"); } else if(thread_state == ENTERED_THREAD) { printf("Test FAILED: for thread2, wait is not terminated even when the timer expired\n"); exit(PTS_FAIL); } else { printf("Unexpected state for thread2 %d\n", thread_state); exit(PTS_UNRESOLVED); } printf("main: unlock write lock\n"); thread_state = NOT_CREATED_THREAD; if(pthread_rwlock_unlock(&rwlock) != 0) { printf("Error releasing write lock\n"); exit(PTS_UNRESOLVED); } if(pthread_rwlock_destroy(&rwlock) != 0) { printf("Error at pthread_rwlockattr_destroy()\n"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_rwlock_timedwrlock/6-1.c0100644000000000000000000001270510021017163025365 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test pthread_rwlock_timedwrlock(pthread_rwlock_t * rwlock) * * If a signal that causes a signal handler to be executed is delivered to * a thread blocked on a read-write lock via a call to pthread_rwlock_timedwrlock( ), * upon return from the signal handler the thread shall resume waiting for the lock * as if it was not interrupted. * * Test that after returning from a signal handler, the reader will continue * to wait with timedrdlock as long as the specified 'timeout' does not expire (the * time spent in signal handler is longer than the specifed 'timeout'). * * Steps: * 1. main thread create and write lock 'rwlock' * 2. main thread create a thread sig_thread, the thread is set to handle SIGUSR1 * 3. sig_thread timed write-lock 'rwlock' for writing, it should block * 4. While the sig_thread is waiting (not expired yet), main thread sends SIGUSR1 * to sig_thread via pthread_kill * 5. Check that when thread handler returns, sig_thread resume block * 7. When the wait is terminated, check that the thread wait for a proper period before * expiring. * */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include #include #include "posixtest.h" static pthread_t sig_thread; static pthread_rwlock_t rwlock; static int thread_state; static int handler_called; static struct timeval before_wait, after_wait; /* thread_state indicates child thread state: 1: not in child thread yet; 2: just enter child thread ; 3: just before child thread exit; */ #define NOT_CREATED_THREAD 1 #define ENTERED_THREAD 2 #define EXITING_THREAD 3 #define TIMEOUT 5 /* Signal handler called by the thread when SIGUSR1 is received */ static void sig_handler() { if(pthread_equal(pthread_self(), sig_thread)) { printf("sig_handler: signal is handled by sig_thread\n"); handler_called = 1; } else { printf("sig_handler: signal is not handled by sig_thread\n"); exit(PTS_UNRESOLVED); } } static void * th_fn(void *arg) { struct sigaction act; struct timespec abs_timeout; int rc = 0; handler_called = 0; /* Set up signal handler for SIGUSR1 */ act.sa_flags = 0; act.sa_handler = sig_handler; /* block all the signal when hanlding SIGUSR1 */ sigfillset(&act.sa_mask); sigaction(SIGUSR1, &act, 0); gettimeofday(&before_wait, NULL); abs_timeout.tv_sec = before_wait.tv_sec + TIMEOUT; abs_timeout.tv_nsec = before_wait.tv_usec * 1000; printf("thread: attempt timed write lock, %d seconds\n", TIMEOUT); thread_state = ENTERED_THREAD; rc = pthread_rwlock_timedwrlock(&rwlock, &abs_timeout); if(rc != ETIMEDOUT) { printf("sig_thread: pthread_rwlock_timedwrlock returns %d\n", rc); exit(PTS_FAIL); } printf("thread: timer correctly expired\n"); gettimeofday(&after_wait, NULL); thread_state = EXITING_THREAD; pthread_exit(0); return NULL; } int main() { int cnt; struct timeval time_diff; if(pthread_rwlock_init(&rwlock, NULL) != 0) { printf("Error at pthread_rwlock_init()\n"); return PTS_UNRESOLVED; } printf("main: attempt write lock\n"); if(pthread_rwlock_wrlock(&rwlock) != 0) { printf("main: Error at pthread_rwlock_wrlock()\n"); return PTS_UNRESOLVED; } printf("main: acquired write lock\n"); thread_state = NOT_CREATED_THREAD; if(pthread_create(&sig_thread, NULL, th_fn, NULL) != 0) { printf("Error at pthread_create()\n"); return PTS_UNRESOLVED; } /* Wait for the thread to get ready for handling signal (the thread should * be block on rwlock since main() has the write lock at this point) */ cnt = 0; do{ sleep(1); }while(thread_state != ENTERED_THREAD && cnt++ < TIMEOUT); if(thread_state != ENTERED_THREAD) { printf("Unexpected thread state %d\n", thread_state); exit(PTS_UNRESOLVED); } printf("main: fire SIGUSR1 to thread\n"); if(pthread_kill(sig_thread, SIGUSR1) != 0) { printf("main: Error at pthread_kill()\n"); exit(PTS_UNRESOLVED); } /* wait at most 2*TIMEOUT seconds */ cnt = 0; do{ sleep(1); }while(thread_state != EXITING_THREAD && cnt++ < 2*TIMEOUT); if(cnt >= 2*TIMEOUT) { /* thread blocked*/ printf("Test FAILED: thread blocked even afer the abs_timeout expired\n"); exit(PTS_FAIL); } if(handler_called != 1) { printf("The handler for SIGUSR1 did not get called\n"); exit(PTS_UNRESOLVED); } /* Test that the thread block for the correct TIMOUT time */ time_diff.tv_sec = after_wait.tv_sec - before_wait.tv_sec; time_diff.tv_usec = after_wait.tv_usec - before_wait.tv_usec; if (time_diff.tv_usec < 0) { --time_diff.tv_sec; time_diff.tv_usec += 1000000; } if(time_diff.tv_sec < TIMEOUT) { printf("Test FAILED: Timeout was for %d seconds, but waited for %ld.%06ld seconds instead\n", TIMEOUT, (long)time_diff.tv_sec, (long)time_diff.tv_usec); exit(PTS_FAIL); } printf("main: unlock write lock\n"); if(pthread_rwlock_unlock(&rwlock) != 0) { printf("main: Error at pthread_rwlock_unlock()\n"); return PTS_UNRESOLVED; } if(pthread_join(sig_thread, NULL) != 0) { printf("main: Error at pthread_join()\n"); return PTS_UNRESOLVED; } if(pthread_rwlock_destroy(&rwlock) != 0) { printf("Error at pthread_destroy()\n"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_rwlock_timedwrlock/assertions.xml0100644000000000000000000000442310117555066027647 0ustar rootroot pthread_rwlock_timedwrlock( ) function shall apply a write lock to the read-write lock referenced by rwlock as in the pthread_rwlock_wrlock( ) function. However, if the lock cannot be acquired without waiting for other threads to unlock the lock, this wait shall be terminate when the specified timeout expires. The timeout shall expire when the absolute time specified by abs_timeout passes, as measured by the clock on which timeouts are based (that is, when the value of that clock equals or exceeds abs_timeout), or if the absolute time specified by abs_timeout has already been passed at the time of the call. If the Timers option is supported, the timeout shall be based on the CLOCK_REALTIME clock. If the Timers option is not supported, the timeout shall be based on the system clock as returned by the time( ) function. The resolution of the timeout shall be the resolution of the clock on which it is based. The timespec data type is defined in the time.h header. Under no circumstances shall the function fail with a timeout if the lock can be acquired immediately. The abs_timeout parameter need not be checked if the lock can be immediately acquired. If a signal that causes a signal handler to be executed is delivered to a thread blocked on a read-write lock via a call to pthread_rwlock_timedwrlock( ), upon return from the signal handler the thread shall resume waiting for the lock as if it was not interrupted. Shall return zero if the lock for writing on the read-write lock object referenced by rwlock is acquired. Otherwise, an error number shall be returned to indicate the error pthread_rwlock_timedwrlock( ) function shall fail if: [ETIMEDOUT] The lock could not be acquired before the specified timeout expired. The function shall not return an error code of [EINTR]. posixtestsuite/conformance/interfaces/pthread_rwlock_timedwrlock/coverage.txt0100644000000000000000000000023510035222730027250 0ustar rootrootThis document defines the coverage for the pthread_rwlock_timedwrlock() function: Assertion Tested? 1 YES 2 YES 3 YES 4 YES 5 YES 6 YES 7 YES NOTE: posixtestsuite/conformance/interfaces/pthread_rwlock_timedwrlock/2-1.c0100644000000000000000000001023407672160417025377 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_rwlock_timedwrlock(pthread_rwlock_t *rwlock) * * The timeout shall expire when the absolute time specified by abs_timeout passes, * as measured by the clock on which timeouts are based (that is, when the * value of that clock equals or exceeds abs_timeout), or if the absolute time * specified by abs_timeout has already been passed at the time of the call. * * Steps: * 1. Initialize 'rwlock' * 2. Main thread locks 'rwlock' for writing with pthread_rwlock_wrlock() * 3. Create a child thread, specify a 'abs_timeout' as being the current time _minus_ a * timeout period, meaning this will ensure that the abs_timeout would have already * passed. * 4. The thread locks 'rwlock' for writing, using pthread_rwlock_timedwrlock(). Should * get an ETIMEOUT error. */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include "posixtest.h" #define TIMEOUT 1 static pthread_rwlock_t rwlock; static int thread_state; static int currsec1, currsec2; static int expired; /* thread_state indicates child thread state: 1: not in child thread yet; 2: just enter child thread ; 3: just before child thread exit; */ #define NOT_CREATED_THREAD 1 #define ENTERED_THREAD 2 #define EXITING_THREAD 3 static void* fn(void *arg) { struct timespec abs_timeout; int rc; thread_state = ENTERED_THREAD; /* Absolute time, not relative. */ abs_timeout.tv_sec = currsec1 - TIMEOUT; abs_timeout.tv_nsec = 0; printf("thread: attempt timed write-lock\n"); rc = pthread_rwlock_timedwrlock(&rwlock, &abs_timeout); if(rc == ETIMEDOUT) { printf("thread: timer expired\n"); expired = 1; } else if(rc == 0) { printf("thread: acquired write lock\n"); expired = 0; printf("thread: unlock write lock\n"); if(pthread_rwlock_unlock(&rwlock) != 0) { printf("thread: failed to release lock\n"); exit(PTS_UNRESOLVED); } } else { printf("Error in pthread_rwlock_timedwrlock(), error code:%d.\n", rc); exit(PTS_UNRESOLVED); } /* Get time after the mutex timed out in locking. */ currsec2 = time(NULL); thread_state = EXITING_THREAD; pthread_exit(0); return NULL; } int main() { int cnt = 0; pthread_t thread1; if(pthread_rwlock_init(&rwlock, NULL) != 0) { printf("Error at pthread_rwlock_init()\n"); return PTS_UNRESOLVED; } printf("main: attempt write lock\n"); /* We have no lock, this write lock should succeed */ if(pthread_rwlock_wrlock(&rwlock) != 0) { printf("Error at pthread_rwlock_wrlock()\n"); return PTS_UNRESOLVED; } printf("main: acquired write lock\n"); thread_state = NOT_CREATED_THREAD; printf("main: create thread\n"); if(pthread_create(&thread1, NULL, fn, NULL) != 0) { printf("Error creating thread\n"); return PTS_UNRESOLVED; } /* If the shared data is not altered by child after 3 seconds, we regard it as blocked */ /* We expect the thread _NOT_ to block */ cnt = 0; do{ sleep(1); }while (thread_state !=EXITING_THREAD && cnt++ < 3); if(thread_state == EXITING_THREAD) { /* the child thread does not block, check the time expired or not */ if(expired != 1) { printf("Test FAILED: abs_timeout should expire\n"); exit(PTS_FAIL); } else printf("thread correctly expired and did not wait\n"); } else if(thread_state == ENTERED_THREAD) { printf("Test FAILED: thread blocked even when the timer expired\n"); exit(PTS_FAIL); } else { printf("Unexpected thread state %d\n", thread_state); exit(PTS_UNRESOLVED); } printf("main: unlock write lock\n"); if(pthread_rwlock_unlock(&rwlock) != 0) { printf("main: Error at pthread_rwlock_unlock()\n"); return PTS_UNRESOLVED; } if(pthread_join(thread1, NULL) != 0) { printf("main: Error at pthread_join()\n"); return PTS_UNRESOLVED; } if(pthread_rwlock_destroy(&rwlock) != 0) { printf("main: Error at pthread_rwlockattr_destroy()\n"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_rwlock_timedwrlock/4-1.sh0100755000000000000000000000122507672160417025574 0ustar rootroot#!/bin/sh # Copyright (c) 2002, Intel Corporation. All rights reserved. # This file is licensed under the GPL license. For the full content # of this license, see the COPYING file at the top level of this # source tree. # Test pthread_rwlock_timedwrlock() # If the Timers option is not supported, the timeout shall be based on the # system clock as returned by the time( ) function. The resolution of the timeout # shall be the resolution of the clock on which it is based. The timespec data type # is defined in the header. # This is tested implicitly via assertion 1. echo "Tested implicitly via assertion 1. See output for status" exit 0 posixtestsuite/conformance/interfaces/pthread_rwlock_timedwrlock/3-1.c0100644000000000000000000001767710035222727025410 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_rwlock_timedwrlock(pthread_rwlock_t *rwlock) * * pthread_rwlock_timedwrlock( ) function shall apply a write lock to the * read-write lock referenced by rwlock as in the pthread_rwlock_wrlock( ) function. * However, if the lock cannot be acquired without waiting for other threads to * unlock the lock, this wait shall be terminate when the specified timeout expires. * * Steps: * 1. Initialize rwlock * 2. Main creats thread0. * 3. Thread0 does pthread_rwlock_timedwrlock(), should get the lock successfully then unlock. * 4. Main thread locks 'rwlock' for reading with pthread_rwlock_rdlock() * 5. Create a child thread, the thread time-locks 'rwlock' for writing, * using pthread_rwlock_timedwrlock(), should block, but when the timer expires, * that wait will be terminated. * 6. Main thread unlocks 'rwlock' * 7. Main thread locks 'rwlock' for writing. * 8. Create child thread to lock 'rwlock' for writing, using pthread_rwlock_timedwrlock, * it should block but when the timer expires, the wait will be terminated * 8. Main thread unlocks 'rwlock' */ /* Test with CLOCK_REALTIME */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include "posixtest.h" #define TIMEOUT 3 static pthread_rwlock_t rwlock; static int thread_state; static struct timeval currsec1, currsec2; static int expired; /* thread_state indicates child thread state: 1: not in child thread yet; 2: just enter child thread ; 3: just before child thread exit; */ #define NOT_CREATED_THREAD 1 #define ENTERED_THREAD 2 #define EXITING_THREAD 3 static void* fn_wr(void *arg) { struct timespec timeout, ts; int rc; thread_state = ENTERED_THREAD; #ifdef CLOCK_REALTIME rc = clock_gettime(CLOCK_REALTIME, &ts); if (rc != 0) { perror("clock_gettime()"); exit(PTS_UNRESOLVED); } currsec1.tv_sec = ts.tv_sec; currsec1.tv_usec = ts.tv_nsec / 1000; #else gettimeofday(&currsec1, NULL); #endif /* Absolute time, not relative. */ timeout.tv_sec = currsec1.tv_sec + TIMEOUT; timeout.tv_nsec = currsec1.tv_usec * 1000; printf("thread: attempt timed write lock, %d secs\n", TIMEOUT); rc = pthread_rwlock_timedwrlock(&rwlock, &timeout); if(rc == ETIMEDOUT) { printf("thread: timer expired\n"); expired = 1; } else if(rc == 0) { printf("thread: acquired write lock\n"); expired = 0; printf("thread: unlock write lock\n"); if(pthread_rwlock_unlock(&rwlock) != 0) { printf("thread: error release write lock\n"); exit(PTS_UNRESOLVED); } } else { printf("thread: Error in pthread_rwlock_timedrdlock().\n"); exit(PTS_UNRESOLVED); } /* Get time after the mutex timed out in locking. */ #ifdef CLOCK_REALTIME rc = clock_gettime(CLOCK_REALTIME, &ts); if (rc != 0) { perror("clock_gettime()"); exit(PTS_UNRESOLVED); } currsec2.tv_sec = ts.tv_sec; currsec2.tv_usec = ts.tv_nsec / 1000; #else gettimeofday(&currsec2, NULL); #endif thread_state = EXITING_THREAD; pthread_exit(0); return NULL; } int main() { int cnt = 0; pthread_t thread0, thread1, thread2; if(pthread_rwlock_init(&rwlock, NULL) != 0) { printf("Error at pthread_rwlock_init()\n"); return PTS_UNRESOLVED; } printf("main: create thread0\n"); thread_state = NOT_CREATED_THREAD; if(pthread_create(&thread0, NULL, fn_wr, NULL) != 0) { printf("Error creating thread0\n"); return PTS_UNRESOLVED; } /* thread0 should not block at all since no one else has locked rwlock */ cnt = 0; expired = 0; do{ sleep(1); }while (thread_state !=EXITING_THREAD && cnt++ < 2*TIMEOUT); if(thread_state == EXITING_THREAD) { if(expired == 1) { printf("Test FAILED: the timer expired\n"); exit(PTS_FAIL); } else printf("thread0 correctly acquired the write lock.\n"); } else if(thread_state == ENTERED_THREAD) { printf("Test FAILED: thread0 incorrectly blocked on timedwrlock\n"); exit(PTS_FAIL); } else { printf("Unexpected state for thread0 %d\n", thread_state); exit(PTS_UNRESOLVED); } if(pthread_join(thread0, NULL) != 0) { printf("Error when joining thread0\n"); return PTS_UNRESOLVED; } printf("main: attempt read lock\n"); /* We have no lock, this read lock should succeed */ if(pthread_rwlock_rdlock(&rwlock) != 0) { printf("Error at pthread_rwlock_rdlock()\n"); return PTS_UNRESOLVED; } printf("main: acquired read lock\n"); thread_state = NOT_CREATED_THREAD; printf("main: create thread1\n"); if(pthread_create(&thread1, NULL, fn_wr, NULL) != 0) { printf("Error when creating thread1\n"); return PTS_UNRESOLVED; } /* If the shared data is not altered by child after TIMEOUT*2 seconds, we regard it as blocked */ /* we expect the thread to expire blocking after timeout*/ cnt = 0; do{ sleep(1); }while (thread_state !=EXITING_THREAD && cnt++ < 2*TIMEOUT); if(thread_state == EXITING_THREAD) { /* the child thread does not block, check the time interval */ struct timeval time_diff; time_diff.tv_sec = currsec2.tv_sec - currsec1.tv_sec; time_diff.tv_usec = currsec2.tv_usec - currsec1.tv_usec; if (time_diff.tv_usec < 0) { --time_diff.tv_sec; time_diff.tv_usec += 1000000; } if(time_diff.tv_sec < TIMEOUT) { printf("Test FAILED: the timer expired and blocking " "was terminated, but the timeout is not correct: " "expected to wait for %d, but waited for %ld.%06ld\n", TIMEOUT, (long)time_diff.tv_sec, (long)time_diff.tv_usec); exit(PTS_FAIL); } else printf("thread1 correctly expired at timeout.\n"); } else if(thread_state == ENTERED_THREAD) { printf("Test FAILED: wait is not terminated even " "when the timer expired\n"); exit(PTS_FAIL); } else { printf("Unexpected state for thread1 %d\n", thread_state); exit(PTS_UNRESOLVED); } printf("main: unlock read lock\n"); if(pthread_rwlock_unlock(&rwlock) != 0) { printf("Error when release read lock\n"); exit(PTS_UNRESOLVED); } if(pthread_join(thread1, NULL) != 0) { printf("Error when joining thread1\n"); return PTS_UNRESOLVED; } printf("main: attempt write lock\n"); if(pthread_rwlock_wrlock(&rwlock) != 0) { printf("Error at pthread_rwlock_wrlock()\n"); return PTS_UNRESOLVED; } printf("main: acquired write lock\n"); thread_state = NOT_CREATED_THREAD; cnt = 0; printf("main: create thread2\n"); if(pthread_create(&thread2, NULL, fn_wr, NULL) != 0) { printf("Error when creating thread2\n"); return PTS_UNRESOLVED; } /* we expect thread2 to expire blocking after timeout */ do{ sleep(1); }while (thread_state !=EXITING_THREAD && cnt++ < 2*TIMEOUT); if(thread_state == EXITING_THREAD) { /* the child thread does not block, check the time interval */ struct timeval time_diff; time_diff.tv_sec = currsec2.tv_sec - currsec1.tv_sec; time_diff.tv_usec = currsec2.tv_usec - currsec1.tv_usec; if (time_diff.tv_usec < 0) { --time_diff.tv_sec; time_diff.tv_usec += 1000000; } if(time_diff.tv_sec < TIMEOUT) { printf("Test FAILED: for thread 2, the timer expired " "and waiter terminated, but the timeout is not correct\n"); exit(PTS_FAIL); } else printf("thread2 correctly expired at timeout.\n"); } else if(thread_state == ENTERED_THREAD) { printf("Test FAILED: for thread2, wait is not terminated " "even when the timer expired\n"); exit(PTS_FAIL); } else { printf("Unexpected state for thread2 %d\n", thread_state); exit(PTS_UNRESOLVED); } printf("main: unlock write lock\n"); thread_state = NOT_CREATED_THREAD; if(pthread_rwlock_unlock(&rwlock) != 0) { printf("Error releasing write lock\n"); exit(PTS_UNRESOLVED); } if(pthread_rwlock_destroy(&rwlock) != 0) { printf("Error at pthread_rwlockattr_destroy()\n"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_create/0040755000000000000000000000000010515625212022262 5ustar rootrootposixtestsuite/conformance/interfaces/pthread_create/15-1.c0100644000000000000000000001236210121521263023004 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertion: * * If the current thread has an alternate stack, the new thread does not inherit * this stack * The steps are: * -> Create a thread with an alternate stack. * -> From this thread, create another thread. * -> Check that the new thread does not use the same stack. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /* Some routines are part of the XSI Extensions */ #ifndef WITHOUT_XOPEN #define _XOPEN_SOURCE 600 #endif /********************************************************************************************/ /****************************** standard includes *****************************************/ /********************************************************************************************/ #include #include #include #include #include #include #include #include #include #include #include /********************************************************************************************/ /****************************** Test framework *****************************************/ /********************************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /********************************************************************************************/ /********************************** Configuration ******************************************/ /********************************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif /********************************************************************************************/ /*********************************** Test cases *****************************************/ /********************************************************************************************/ #define STD_MAIN #include "threads_scenarii.c" /* This file will define the following objects: * scenarii: array of struct __scenario type. * NSCENAR : macro giving the total # of scenarii * scenar_init(): function to call before use the scenarii array. * scenar_fini(): function to call after end of use of the scenarii array. */ /********************************************************************************************/ /*********************************** Real Test *****************************************/ /********************************************************************************************/ void * teststack(void * arg) { int ret=0; *(int **)arg = &ret; return NULL; } /* Thread function */ void * threaded(void * arg) { int ret; int * child_stack; pthread_t gchild; int sz = sysconf(_SC_THREAD_STACK_MIN); if (scenarii[sc].bottom != NULL) { #if VERBOSE > 1 output("Processing test\n"); #endif /* Create a new thread and get a location inside its stack */ ret = pthread_create(&gchild, NULL, teststack, &child_stack); if (ret != 0) { UNRESOLVED(ret, "Failed to create a thread with default attribute"); } ret = pthread_join(gchild, NULL); if (ret != 0) { UNRESOLVED(ret, "Failed to join the test thread"); } /* Check the new thread stack location was outside of the current thread location */ /* We convert all the @ to longs */ #if VERBOSE > 4 output("Current stack : %p -> %p\n", scenarii[sc].bottom, sz + (long)scenarii[sc].bottom); output("Child location: %p\n", child_stack); #endif if ( (((long)scenarii[sc].bottom) < ((long)child_stack)) && (((long)child_stack) < (((long)scenarii[sc].bottom) + sz))) { FAILED("The new thread inherited th alternate stack from its parent"); } } /* Signal we're done (especially in case of a detached thread) */ do { ret = sem_post(&scenarii[sc].sem); } while ((ret == -1) && (errno == EINTR)); if (ret == -1) { UNRESOLVED(errno, "Failed to wait for the semaphore"); } /* return */ return arg; } posixtestsuite/conformance/interfaces/pthread_create/5-1.c0100644000000000000000000000233507647616143022747 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test pthread_create() * The thread is created executing 'start_routine' with 'arg' as its only * argument. * * Steps: * 1. Create 5 separete threads using pthread_create() passing to it a single int 'arg'. * 2. Use that passed int argument in the thread function start routine and make sure no * errors occur. */ #include #include #include #include "posixtest.h" #define NUM_THREADS 5 /* The thread start routine. */ void *a_thread_func(void* num) { intptr_t i = (intptr_t) num; printf("Passed argument for thread: %d\n", (int)i); pthread_exit(0); return NULL; } int main() { pthread_t new_th; long i; for(i=1;i #include #include "posixtest.h" void *a_thread_func(); pthread_t self_th; /* Save the value of the function call pthread_self() within the thread. Keeping it global so 'main' can see it too. */ int main() { pthread_t new_th; /* Create a new thread */ if(pthread_create(&new_th, NULL, a_thread_func, NULL) != 0) { perror("Error creating thread\n"); return PTS_UNRESOLVED; } /* Wait for the thread function to return to make sure we got * the thread ID value from pthread_self(). */ if(pthread_join(new_th, NULL) != 0) { perror("Error calling pthread_join()\n"); return PTS_UNRESOLVED; } /* If the value of pthread_self() and the return value from * pthread_create() is equal, then the test passes. */ if(pthread_equal(new_th, self_th) == 0) { printf("Test FAILED\n"); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } /* The thread function that calls pthread_self() to obtain its thread ID */ void *a_thread_func() { self_th=pthread_self(); pthread_exit(0); return NULL; } posixtestsuite/conformance/interfaces/pthread_create/14-1.c0100644000000000000000000002307210121521263023003 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertion: * * The function does not return EINTR * The steps are: * -> pthread_kill a thread which creates threads * -> check that EINTR is never returned */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /* Some routines are part of the XSI Extensions */ #ifndef WITHOUT_XOPEN #define _XOPEN_SOURCE 600 #endif /********************************************************************************************/ /****************************** standard includes *****************************************/ /********************************************************************************************/ #include #include #include #include #include #include #include #include #include #include #include #include #include /********************************************************************************************/ /****************************** Test framework *****************************************/ /********************************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /********************************************************************************************/ /********************************** Configuration ******************************************/ /********************************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif #define WITH_SYNCHRO /********************************************************************************************/ /*********************************** Test cases *****************************************/ /********************************************************************************************/ #include "threads_scenarii.c" /* This file will define the following objects: * scenarii: array of struct __scenario type. * NSCENAR : macro giving the total # of scenarii * scenar_init(): function to call before use the scenarii array. * scenar_fini(): function to call after end of use of the scenarii array. */ /********************************************************************************************/ /*********************************** Real Test *****************************************/ /********************************************************************************************/ char do_it=1; char woken=0; unsigned long count_ope=0; #ifdef WITH_SYNCHRO sem_t semsig1; sem_t semsig2; unsigned long count_sig=0; #endif sigset_t usersigs; typedef struct { int sig; #ifdef WITH_SYNCHRO sem_t *sem; #endif } thestruct; /* the following function keeps on sending the signal to the process */ void * sendsig (void * arg) { thestruct *thearg = (thestruct *) arg; int ret; pid_t process; process=getpid(); /* We block the signals SIGUSR1 and SIGUSR2 for this THREAD */ ret = pthread_sigmask(SIG_BLOCK, &usersigs, NULL); if (ret != 0) { UNRESOLVED(ret, "Unable to block SIGUSR1 and SIGUSR2 in signal thread"); } while (do_it) { #ifdef WITH_SYNCHRO if ((ret = sem_wait(thearg->sem))) { UNRESOLVED(errno, "Sem_wait in sendsig"); } count_sig++; #endif ret = kill(process, thearg->sig); if (ret != 0) { UNRESOLVED(errno, "Kill in sendsig"); } } return NULL; } /* Next are the signal handlers. */ /* This one is registered for signal SIGUSR1 */ void sighdl1(int sig) { #ifdef WITH_SYNCHRO if (sem_post(&semsig1)) { UNRESOLVED(errno, "Sem_post in signal handler 1"); } #endif } /* This one is registered for signal SIGUSR2 */ void sighdl2(int sig) { #ifdef WITH_SYNCHRO if (sem_post(&semsig2)) { UNRESOLVED(errno, "Sem_post in signal handler 2"); } #endif } /* Thread function -- almost does nothing */ void * threaded(void * arg) { int ret; /* Signal we're done (especially in case of a detached thread) */ do { ret = sem_post(&scenarii[sc].sem); } while ((ret == -1) && (errno == EINTR)); if (ret == -1) { UNRESOLVED(errno, "Failed to wait for the semaphore"); } /* return */ return arg; } /* Test function -- creates the threads and check that EINTR is never returned. */ void * test(void * arg) { int ret=0; pthread_t child; /* We don't block the signals SIGUSR1 and SIGUSR2 for this THREAD */ ret = pthread_sigmask(SIG_UNBLOCK, &usersigs, NULL); if (ret != 0) { UNRESOLVED(ret, "Unable to unblock SIGUSR1 and SIGUSR2 in worker thread"); } sc = 0; while (do_it) { #if VERBOSE > 5 output("-----\n"); output("Starting test with scenario (%i): %s\n", sc, scenarii[sc].descr); #endif count_ope++; ret = pthread_create(&child, &scenarii[sc].ta, threaded, NULL); if (ret == EINTR) { FAILED("pthread_create returned EINTR"); } switch (scenarii[sc].result) { case 0: /* Operation was expected to succeed */ if (ret != 0) { UNRESOLVED(ret, "Failed to create this thread"); } break; case 1: /* Operation was expected to fail */ if (ret == 0) { UNRESOLVED(-1, "An error was expected but the thread creation succeeded"); } break; case 2: /* We did not know the expected result */ default: #if VERBOSE > 5 if (ret == 0) { output("Thread has been created successfully for this scenario\n"); } else { output("Thread creation failed with the error: %s\n", strerror(ret)); } #endif ; } if (ret == 0) /* The new thread is running */ { if (scenarii[sc].detached == 0) { ret = pthread_join(child, NULL); if (ret != 0) { UNRESOLVED(ret, "Unable to join a thread"); } } else { /* Just wait for the thread to terminate */ do { ret = sem_wait(&scenarii[sc].sem); } while ((ret == -1) && (errno == EINTR)); if (ret == -1) { UNRESOLVED(errno, "Failed to wait for the semaphore"); } } } /* Change thread attribute for the next loop */ sc++; sc %= NSCENAR; } return NULL; } /* Main function */ int main (int argc, char * argv[]) { int ret; pthread_t th_work, th_sig1, th_sig2; thestruct arg1, arg2; struct sigaction sa; /* Initialize output routine */ output_init(); /* Initialize thread attribute objects */ scenar_init(); /* We need to register the signal handlers for the PROCESS */ sigemptyset (&sa.sa_mask); sa.sa_flags = 0; sa.sa_handler = sighdl1; if ((ret = sigaction (SIGUSR1, &sa, NULL))) { UNRESOLVED(ret, "Unable to register signal handler1"); } sa.sa_handler = sighdl2; if ((ret = sigaction (SIGUSR2, &sa, NULL))) { UNRESOLVED(ret, "Unable to register signal handler2"); } /* We prepare a signal set which includes SIGUSR1 and SIGUSR2 */ sigemptyset(&usersigs); ret = sigaddset(&usersigs, SIGUSR1); ret |= sigaddset(&usersigs, SIGUSR2); if (ret != 0) { UNRESOLVED(ret, "Unable to add SIGUSR1 or 2 to a signal set"); } /* We now block the signals SIGUSR1 and SIGUSR2 for this THREAD */ ret = pthread_sigmask(SIG_BLOCK, &usersigs, NULL); if (ret != 0) { UNRESOLVED(ret, "Unable to block SIGUSR1 and SIGUSR2 in main thread"); } #ifdef WITH_SYNCHRO if (sem_init(&semsig1, 0, 1)) { UNRESOLVED(errno, "Semsig1 init"); } if (sem_init(&semsig2, 0, 1)) { UNRESOLVED(errno, "Semsig2 init"); } #endif if ((ret = pthread_create(&th_work, NULL, test, NULL))) { UNRESOLVED(ret, "Worker thread creation failed"); } arg1.sig = SIGUSR1; arg2.sig = SIGUSR2; #ifdef WITH_SYNCHRO arg1.sem = &semsig1; arg2.sem = &semsig2; #endif if ((ret = pthread_create(&th_sig1, NULL, sendsig, (void *)&arg1))) { UNRESOLVED(ret, "Signal 1 sender thread creation failed"); } if ((ret = pthread_create(&th_sig2, NULL, sendsig, (void *)&arg2))) { UNRESOLVED(ret, "Signal 2 sender thread creation failed"); } /* Let's wait for a while now */ sleep(1); /* Now stop the threads and join them */ do { do_it=0; } while (do_it); if ((ret = pthread_join(th_sig1, NULL))) { UNRESOLVED(ret, "Signal 1 sender thread join failed"); } if ((ret = pthread_join(th_sig2, NULL))) { UNRESOLVED(ret, "Signal 2 sender thread join failed"); } if ((ret = pthread_join(th_work, NULL))) { UNRESOLVED(ret, "Worker thread join failed"); } scenar_fini(); #if VERBOSE > 0 output("Test executed successfully.\n"); output(" %d thread creations.\n", count_ope); #ifdef WITH_SYNCHRO output(" %d signals were sent meanwhile.\n", count_sig); #endif #endif PASSED; } posixtestsuite/conformance/interfaces/pthread_create/1-5.c0100644000000000000000000002221010121521263022714 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertion: * * pthread_create creates a thread with attributes as specified in the attr parameter. * The steps are: * * -> Create a new thread with known parameters. * -> Check the thread behavior conforms to these parameters. * This checking consists in: * -> If an alternative stack has been specified, check that the new thread stack is within this specified area. * -> If stack size and guard size are known, check that accessing the guard size fails. (new process) * -> If we are able to run threads with high priority and known sched policy, check that a high priority thread executes before a low priority thread. (This will be done in another test has it fails with Linux kernel (2.6.8 at least) * -> The previous test could be extended to cross-process threads to check the scope attribute behavior (postponned for now). * (*) The detachstate attribute is not tested cause this would mean a speculative test. Moreover, it is already tested elsewhere. * The test fails if one of those tests fails. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /* Some routines are part of the XSI Extensions */ #ifndef WITHOUT_XOPEN #define _XOPEN_SOURCE 600 #endif /********************************************************************************************/ /****************************** standard includes *****************************************/ /********************************************************************************************/ #include #include #include #include #include #include #include #include #include #include #include /********************************************************************************************/ /****************************** Test framework *****************************************/ /********************************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /********************************************************************************************/ /********************************** Configuration ******************************************/ /********************************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif /********************************************************************************************/ /*********************************** Test cases *****************************************/ /********************************************************************************************/ #define STD_MAIN /* This allows main() to be defined in the included file */ #include "threads_scenarii.c" /* This file will define the following objects: * scenarii: array of struct __scenario type. * NSCENAR : macro giving the total # of scenarii * scenar_init(): function to call before use the scenarii array. * scenar_fini(): function to call after end of use of the scenarii array. */ /********************************************************************************************/ /*********************************** Real Test *****************************************/ /********************************************************************************************/ /* The overflow function is used to test the stack overflow */ void * overflow(void * arg) { void * current; void * pad[50]; /* We want to consume the stack quickly */ long stacksize = sysconf(_SC_THREAD_STACK_MIN); /* make sure we touch the current stack memory */ int ret=0; pad[1]=NULL; /* so compiler stops complaining about unused variables */ if (arg == NULL) { /* first call */ current = overflow(¤t); /* Terminate the overflow thread */ /* Post the semaphore to unlock the main thread in case of a detached thread */ do { ret = sem_post(&scenarii[sc].sem); } while ((ret == -1) && (errno == EINTR)); if (ret == -1) { UNRESOLVED(errno, "Failed to post the semaphore"); } return NULL; } /* we cast the pointers into long, which might be a problem on some architectures... */ if ( ((long)arg) < ((long)¤t)) { /* the stack is growing up */ if ( ((long)¤t) - ((long)arg) >= stacksize) { output("Growing up stack started below %p and we are currently up to %p\n", arg, ¤t); return (void *)0; } } else { /* the stack is growing down */ if ( ((long)arg) - ((long)¤t) >= stacksize) { output("Growing down stack started upon %p and we are currently down to %p\n", arg, ¤t); return (void *)0; } } /* We are not yet overflowing, so we loop */ { return overflow(arg); } } void * threaded (void * arg) { int ret = 0; #if VERBOSE > 4 output("Thread %i starting...\n", sc); #endif /* Alternate stack test */ if (scenarii[sc].bottom != NULL) { #ifdef WITHOUT_XOPEN output("Unable to test the alternate stack feature; need an integer pointer cast\n"); #else intptr_t stack_start, stack_end, current_pos; stack_start = (intptr_t) scenarii[sc].bottom; stack_end = stack_start + (intptr_t)sysconf(_SC_THREAD_STACK_MIN); current_pos = (intptr_t)&ret; #if VERBOSE > 2 output("Stack bottom: %p\n", scenarii[sc].bottom); output("Stack end : %p (stack is 0x%lx bytes)\n", (void *)stack_end, stack_end - stack_start); output("Current pos : %p\n", &ret); #endif if ((stack_start > current_pos) || (current_pos > stack_end)) { FAILED("The specified stack was not used.\n"); } #endif // WITHOUT_XOPEN } /* Guard size test */ if ((scenarii[sc].bottom == NULL) /* no alternative stack was specified */ && (scenarii[sc].guard == 2) /* guard area size is 1 memory page */ && (scenarii[sc].altsize == 1))/* We know the stack size */ { pid_t child, ctrl; int status; child=fork(); /* We'll test the feature in another process as this test may segfault */ if (child == -1) { UNRESOLVED(errno, "Failed to fork()"); } if (child != 0) /* father */ { /* Just wait for the child and check its return value */ ctrl = waitpid(child, &status, 0); if (ctrl != child) { UNRESOLVED(errno, "Failed to wait for process termination"); } if (WIFEXITED(status)) /* The process exited */ { if (WEXITSTATUS(status) == 0) { FAILED("Overflow into the guard area did not fail"); } if (WEXITSTATUS(status) == PTS_UNRESOLVED) { UNRESOLVED(-1, "The child process returned unresolved status"); } #if VERBOSE > 4 else { output("The child process returned: %i\n", WEXITSTATUS(status)); } } else { output("The child process did not returned\n"); if (WIFSIGNALED(status)) output("It was killed with signal %i\n", WTERMSIG(status)); else output("neither was it killed. (status = %i)\n", status); #endif } } if (child == 0) /* this is the new process */ { pthread_t th; ret = pthread_create(&th, &scenarii[sc].ta, overflow, NULL); /* Create a new thread with the same attributes */ if (ret != 0) { UNRESOLVED(ret, "Unable to create another thread with the same attributes in the new process"); } if (scenarii[sc].detached == 0) { ret = pthread_join(th, NULL); if (ret != 0) { UNRESOLVED(ret, "Unable to join a thread"); } } else { /* Just wait for the thread to terminate */ do { ret = sem_wait(&scenarii[sc].sem); } while ((ret == -1) && (errno == EINTR)); if (ret == -1) { UNRESOLVED(errno, "Failed to wait for the semaphore"); } } /* Terminate the child process here */ exit(0); } } /* Post the semaphore to unlock the main thread in case of a detached thread */ do { ret = sem_post(&scenarii[sc].sem); } while ((ret == -1) && (errno == EINTR)); if (ret == -1) { UNRESOLVED(errno, "Failed to post the semaphore"); } return arg; } posixtestsuite/conformance/interfaces/pthread_create/5-2.c0100644000000000000000000000237207631514674022750 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test pthread_create() * The thread is created executing 'start_routine' with 'arg' as its only * argument. * * Steps: * 1. Create a thread using pthread_create() passing to it an array of 'int's as an argument. * 2. Use that passed int argument in the thread function start routine and make sure no * errors occur. */ #include #include #include "posixtest.h" #define NUM_THREADS 5 /* The thread start routine. */ void *a_thread_func(void* num) { int *i, j; i = (int *)num; for(j=0;j #include #include #include #include #include "posixtest.h" void *a_thread_function(); void alarm_handler(); pthread_t a; int main() { /* Set the action for SIGALRM to generate an error if it is * reached. This is because if SIGALRM was sent, then the * test timed out. */ if (signal(SIGALRM, alarm_handler) == SIG_ERR) { printf("Error in signal()\n"); return PTS_UNRESOLVED; } /* SIGALRM will be sent in 5 seconds. */ alarm(5); /* Create a new thread. */ if(pthread_create(&a, NULL, a_thread_function, NULL) != 0) { perror("Error creating thread\n"); return PTS_UNRESOLVED; } pthread_cancel(a); /* If 'main' has reached here, then the test passed because it means * that the thread is truly asynchronise, and main isn't waiting for * it to return in order to move on. */ printf("Test PASSED\n"); return PTS_PASS; } /* A never-ending thread function */ void *a_thread_function() { pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); while(1) sleep(1); pthread_exit(0); return NULL; } /* If this handler is called, that means that the test has failed. */ void alarm_handler() { printf("Test FAILED\n"); exit(PTS_FAIL); } posixtestsuite/conformance/interfaces/pthread_create/12-1.c0100644000000000000000000000211107631757720023015 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test pthread_create() * * If success, pthread_create() returns zero. * * Steps: * 1. Create a thread using pthread_create(), passing to it all valid values. * 2. If the return code was not EGAIN, EPERM or EINVAL, it should return 0. */ #include #include #include #include "posixtest.h" /* Thread starting routine that really does nothing. */ void *a_thread_func() { pthread_exit(0); return NULL; } int main() { pthread_t new_th; int ret; /* Create new thread and check the return value. */ ret = pthread_create(&new_th, NULL, a_thread_func, NULL); if(ret != 0) { if((ret != EINVAL) && (ret != EAGAIN) && (ret != EPERM)) printf("Test FAILED: Wrong return code: %d\n", ret); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_create/1-1.c0100644000000000000000000000233607626776061022747 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_create() creates a new thread with attributes specified * by 'attr', within a process. * * Steps: * 1. Create a thread using pthread_create() * 2. Compare the thread ID of 'main' to the thread ID of the newly created * thread. They should be different. */ #include #include #include "posixtest.h" void *a_thread_func() { pthread_exit(0); return NULL; } int main() { pthread_t main_th, new_th; if(pthread_create(&new_th, NULL, a_thread_func, NULL) != 0) { perror("Error creating thread\n"); return PTS_UNRESOLVED; } /* Obtain the thread ID of this main function */ main_th=pthread_self(); /* Compare the thread ID of the new thread to the main thread. * They should be different. If not, the test fails. */ if(pthread_equal(new_th, main_th) != 0) { printf("Test FAILED: A new thread wasn't created\n"); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_create/testfrmw.c0100644000000000000000000000407210121521263024273 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * * This file is a wrapper to use the tests from the NPTL Test & Trace Project * with either the Linux Test Project or the Open POSIX Test Suite. * The following function are defined: * void output_init() * void output_fini() * void output(char * string, ...) * * The are used to output informative text (as a printf). */ #include #include /* We use a mutex to avoid conflicts in traces */ static pthread_mutex_t m_trace = PTHREAD_MUTEX_INITIALIZER; /*****************************************************************************************/ /******************************* stdout module *****************************************/ /*****************************************************************************************/ /* The following functions will output to stdout */ #if (1) void output_init() { /* do nothing */ return; } void output( char * string, ... ) { va_list ap; char *ts="[??:??:??]"; struct tm * now; time_t nw; pthread_mutex_lock(&m_trace); nw = time(NULL); now = localtime(&nw); if (now == NULL) printf(ts); else printf("[%2.2d:%2.2d:%2.2d]", now->tm_hour, now->tm_min, now->tm_sec); va_start( ap, string); vprintf(string, ap); va_end(ap); pthread_mutex_unlock(&m_trace); } void output_fini() { /*do nothing */ return; } #endif posixtestsuite/conformance/interfaces/pthread_create/13.sh0100755000000000000000000000166607631757720023071 0ustar rootroot#!/bin/sh # Copyright (c) 2002, Intel Corporation. All rights reserved. # Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com # This file is licensed under the GPL license. For the full content # of this license, see the COPYING file at the top level of this # source tree. # Test pthread_create() fails and an error number is returned if: # - [EAGAIN] The system lacked the resources to create another thread, # or the system-imposed limit on the total number of threads # in a process {PTHREAD_THREADS_MAX} would be exceeded. # - [EINVAL] The value specified by 'attr' is invalid. # - [EPERM] The caller does not have the appropriate permission to set # the required scheduling parameters or scheduling policy. # This is tested implicitly via assertion 10. Note: only EINVAL is tested because the other # 2 conditions are hard to emmulate. echo "Tested implicitly via assertion 10. See output for status" exit 0 posixtestsuite/conformance/interfaces/pthread_create/threads_scenarii.c0100644000000000000000000003472110121521263025733 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This file is a helper file for the pthread_create tests * It defines the following objects: * scenarii: array of struct __scenario type. * NSCENAR : macro giving the total # of scenarii * scenar_init(): function to call before use the scenarii array. * scenar_fini(): function to call after end of use of the scenarii array. * */ struct __scenario { /* Object to hold the given configuration, and which will be used to create the threads */ pthread_attr_t ta; /* General parameters */ int detached; /* 0 => joinable; 1 => detached */ /* Scheduling parameters */ int explicitsched; /* 0 => sched policy is inherited; 1 => sched policy from the attr param */ int schedpolicy; /* 0 => default; 1=> SCHED_FIFO; 2=> SCHED_RR */ int schedparam; /* 0 => default sched param; 1 => max value for sched param; -1 => min value for sched param */ int altscope; /* 0 => default contension scope; 1 => alternative contension scope */ /* Stack parameters */ int altstack; /* 0 => system manages the stack; 1 => stack is provided */ int guard; /* 0 => default guardsize; 1=> guardsize is 0; 2=> guard is 1 page -- this setting only affect system stacks (not user's). */ int altsize; /* 0 => default stack size; 1 => stack size specified (min value) -- ignored when stack is provided */ /* Additionnal information */ char * descr; /* object description */ void * bottom; /* Stores the stack start when an alternate stack is required */ int result; /* This thread creation is expected to: 0 => succeed; 1 => fail; 2 => unknown */ sem_t sem; /* This semaphore is used to signal the end of the detached threads execution */ } scenarii[]= #define CASE(det,expl,scp,spa,sco,sta,gua,ssi,desc,res) \ { \ .detached=det, \ .explicitsched=expl, \ .schedpolicy=scp, \ .schedparam=spa, \ .altscope=sco, \ .altstack=sta, \ .guard=gua, \ .altsize=ssi, \ .descr=desc, \ .bottom=NULL, \ .result=res } #define CASE_POS(det,expl,scp,spa,sco,sta,gua,ssi,desc) CASE(det,expl,scp,spa,sco,sta,gua,ssi,desc,0) #define CASE_NEG(det,expl,scp,spa,sco,sta,gua,ssi,desc) CASE(det,expl,scp,spa,sco,sta,gua,ssi,desc,1) #define CASE_UNK(det,expl,scp,spa,sco,sta,gua,ssi,desc) CASE(det,expl,scp,spa,sco,sta,gua,ssi,desc,2) /* * This array gives the different combinations of threads attributes for the testcases. * * Some combinations must be avoided. * -> Do not have a detached thread use an alternative stack; * as we don't know when the thread terminates to free the stack memory * -> ... (to be completed) * */ { /* Unary tests */ /* 0*/ CASE_POS( 0, 0, 0, 0, 0, 0, 0, 0, "default") /* 1*/ ,CASE_POS( 1, 0, 0, 0, 0, 0, 0, 0, "detached") /* 2*/ ,CASE_POS( 0, 1, 0, 0, 0, 0, 0, 0, "Explicit sched") /* 3*/ ,CASE_UNK( 0, 0, 1, 0, 0, 0, 0, 0, "FIFO Policy") /* 4*/ ,CASE_UNK( 0, 0, 2, 0, 0, 0, 0, 0, "RR Policy") /* 5*/ ,CASE_UNK( 0, 0, 0, 1, 0, 0, 0, 0, "Max sched param") /* 6*/ ,CASE_UNK( 0, 0, 0,-1, 0, 0, 0, 0, "Min sched param") /* 7*/ ,CASE_POS( 0, 0, 0, 0, 1, 0, 0, 0, "Alternative contension scope") /* 8*/ ,CASE_POS( 0, 0, 0, 0, 0, 1, 0, 0, "Alternative stack") /* 9*/ ,CASE_POS( 0, 0, 0, 0, 0, 0, 1, 0, "No guard size") /*10*/ ,CASE_UNK( 0, 0, 0, 0, 0, 0, 2, 0, "1p guard size") /*11*/ ,CASE_POS( 0, 0, 0, 0, 0, 0, 0, 1, "Min stack size") /* Stack play */ ,CASE_POS( 0, 0, 0, 0, 0, 0, 1, 1, "Min stack size, no guard") ,CASE_UNK( 0, 0, 0, 0, 0, 0, 2, 1, "Min stack size, 1p guard") ,CASE_POS( 1, 0, 0, 0, 0, 1, 0, 0, "Detached, Alternative stack") ,CASE_POS( 1, 0, 0, 0, 0, 0, 1, 1, "Detached, Min stack size, no guard") ,CASE_UNK( 1, 0, 0, 0, 0, 0, 2, 1, "Detached, Min stack size, 1p guard") /* Scheduling play -- all results are unknown since it might depend on the user priviledges */ ,CASE_UNK( 0, 1, 1, 1, 0, 0, 0, 0, "Explicit FIFO max param") ,CASE_UNK( 0, 1, 2, 1, 0, 0, 0, 0, "Explicit RR max param") ,CASE_UNK( 0, 1, 1,-1, 0, 0, 0, 0, "Explicit FIFO min param") ,CASE_UNK( 0, 1, 2,-1, 0, 0, 0, 0, "Explicit RR min param") ,CASE_UNK( 0, 1, 1, 1, 1, 0, 0, 0, "Explicit FIFO max param, alt scope") ,CASE_UNK( 0, 1, 2, 1, 1, 0, 0, 0, "Explicit RR max param, alt scope") ,CASE_UNK( 0, 1, 1,-1, 1, 0, 0, 0, "Explicit FIFO min param, alt scope") ,CASE_UNK( 0, 1, 2,-1, 1, 0, 0, 0, "Explicit RR min param, alt scope") ,CASE_UNK( 1, 1, 1, 1, 0, 0, 0, 0, "Detached, explicit FIFO max param") ,CASE_UNK( 1, 1, 2, 1, 0, 0, 0, 0, "Detached, explicit RR max param") ,CASE_UNK( 1, 1, 1,-1, 0, 0, 0, 0, "Detached, explicit FIFO min param") ,CASE_UNK( 1, 1, 2,-1, 0, 0, 0, 0, "Detached, explicit RR min param") ,CASE_UNK( 1, 1, 1, 1, 1, 0, 0, 0, "Detached, explicit FIFO max param, alt scope") ,CASE_UNK( 1, 1, 2, 1, 1, 0, 0, 0, "Detached, explicit RR max param, alt scope") ,CASE_UNK( 1, 1, 1,-1, 1, 0, 0, 0, "Detached, explicit FIFO min param, alt scope") ,CASE_UNK( 1, 1, 2,-1, 1, 0, 0, 0, "Detached, explicit RR min param, alt scope") }; #define NSCENAR (sizeof(scenarii) / sizeof(scenarii[0])) /* This function will initialize every pthread_attr_t object in the scenarii array */ void scenar_init() { int ret=0; int i; int old; long pagesize, minstacksize; long tsa, tss, tps; pagesize =sysconf(_SC_PAGESIZE); minstacksize =sysconf(_SC_THREAD_STACK_MIN); tsa =sysconf(_SC_THREAD_ATTR_STACKADDR); tss =sysconf(_SC_THREAD_ATTR_STACKSIZE); tps =sysconf(_SC_THREAD_PRIORITY_SCHEDULING); #if VERBOSE > 0 output("System abilities:\n"); output(" TSA: %li\n", tsa); output(" TSS: %li\n", tss); output(" TPS: %li\n", tps); output(" pagesize: %li\n", pagesize); output(" min stack size: %li\n", minstacksize); #endif if (minstacksize % pagesize) { UNTESTED("The min stack size is not a multiple of the page size"); } for (i=0; i 2 output("Initializing attribute for scenario %i: %s\n", i, scenarii[i].descr); #endif ret = pthread_attr_init(&scenarii[i].ta); if (ret != 0) { UNRESOLVED(ret, "Failed to initialize a thread attribute object"); } /* Set the attributes according to the scenario */ if (scenarii[i].detached == 1) { ret = pthread_attr_setdetachstate(&scenarii[i].ta, PTHREAD_CREATE_DETACHED); if (ret != 0) { UNRESOLVED(ret, "Unable to set detachstate"); } } else { ret = pthread_attr_getdetachstate(&scenarii[i].ta, &old); if (ret != 0) { UNRESOLVED(ret, "Unable to get detachstate from initialized attribute"); } if (old != PTHREAD_CREATE_JOINABLE) { FAILED("The default attribute is not PTHREAD_CREATE_JOINABLE"); } } #if VERBOSE > 4 output("Detach state was set sucessfully\n"); #endif /* Sched related attributes */ if (tps>0) /* This routine is dependent on the Thread Execution Scheduling option */ { if (scenarii[i].explicitsched == 1) ret = pthread_attr_setinheritsched(&scenarii[i].ta, PTHREAD_EXPLICIT_SCHED); else ret = pthread_attr_setinheritsched(&scenarii[i].ta, PTHREAD_INHERIT_SCHED); if (ret != 0) { UNRESOLVED(ret, "Unable to set inheritsched attribute"); } #if VERBOSE > 4 output("inheritsched state was set sucessfully\n"); #endif } #if VERBOSE > 4 else output("TPS unsupported => inheritsched parameter untouched\n"); #endif if (tps>0) /* This routine is dependent on the Thread Execution Scheduling option */ { if (scenarii[i].schedpolicy == 1) { ret = pthread_attr_setschedpolicy(&scenarii[i].ta, SCHED_FIFO); } if (scenarii[i].schedpolicy == 2) { ret = pthread_attr_setschedpolicy(&scenarii[i].ta, SCHED_RR); } if (ret != 0) { UNRESOLVED(ret, "Unable to set the sched policy"); } #if VERBOSE > 4 if (scenarii[i].schedpolicy) output("Sched policy was set sucessfully\n"); else output("Sched policy untouched\n"); #endif } #if VERBOSE > 4 else output("TPS unsupported => sched policy parameter untouched\n"); #endif if (scenarii[i].schedparam != 0) { struct sched_param sp; ret = pthread_attr_getschedpolicy(&scenarii[i].ta, &old); if (ret != 0) { UNRESOLVED(ret, "Unable to get sched policy from attribute"); } if (scenarii[i].schedparam == 1) sp.sched_priority = sched_get_priority_max(old); if (scenarii[i].schedparam == -1) sp.sched_priority = sched_get_priority_min(old); ret = pthread_attr_setschedparam(&scenarii[i].ta, &sp); if (ret != 0) { UNRESOLVED(ret, "Failed to set the sched param"); } #if VERBOSE > 4 output("Sched param was set sucessfully to %i\n", sp.sched_priority); } else { output("Sched param untouched\n"); #endif } if (tps>0) /* This routine is dependent on the Thread Execution Scheduling option */ { ret = pthread_attr_getscope(&scenarii[i].ta, &old); if (ret != 0) { UNRESOLVED(ret, "Failed to get contension scope from thread attribute"); } if (scenarii[i].altscope != 0) { if (old == PTHREAD_SCOPE_PROCESS) old = PTHREAD_SCOPE_SYSTEM; else old = PTHREAD_SCOPE_PROCESS; ret = pthread_attr_setscope(&scenarii[i].ta, old); //if (ret != 0) { UNRESOLVED(ret, "Failed to set contension scope"); } if (ret != 0) { output("WARNING: The TPS option is claimed to be supported but setscope fails\n"); } #if VERBOSE > 4 output("Contension scope set to %s\n", old==PTHREAD_SCOPE_PROCESS?"PTHREAD_SCOPE_PROCESS":"PTHREAD_SCOPE_SYSTEM"); } else { output("Contension scope untouched (%s)\n", old==PTHREAD_SCOPE_PROCESS?"PTHREAD_SCOPE_PROCESS":"PTHREAD_SCOPE_SYSTEM"); #endif } } #if VERBOSE > 4 else output("TPS unsupported => sched contension scope parameter untouched\n"); #endif /* Stack related attributes */ if ((tss>0) && (tsa>0)) /* This routine is dependent on the Thread Stack Address Attribute and Thread Stack Size Attribute options */ { if (scenarii[i].altstack != 0) { /* This is slightly more complicated. We need to alloc a new stack and free it upon test termination */ /* We will alloc with a simulated guardsize of 1 pagesize */ scenarii[i].bottom = malloc(minstacksize + pagesize); if (scenarii[i].bottom == NULL) { UNRESOLVED(errno,"Unable to alloc enough memory for alternative stack"); } ret = pthread_attr_setstack(&scenarii[i].ta, scenarii[i].bottom, minstacksize); if (ret != 0) { UNRESOLVED(ret, "Failed to specify alternate stack"); } #if VERBOSE > 1 output("Alternate stack created successfully. Bottom=%p, Size=%i\n", scenarii[i].bottom, minstacksize); #endif } } #if VERBOSE > 4 else output("TSA or TSS unsupported => No alternative stack\n"); #endif #ifndef WITHOUT_XOPEN if (scenarii[i].guard != 0) { if (scenarii[i].guard == 1) ret = pthread_attr_setguardsize(&scenarii[i].ta, 0); if (scenarii[i].guard == 2) ret = pthread_attr_setguardsize(&scenarii[i].ta, pagesize); if (ret != 0) { UNRESOLVED(ret, "Unable to set guard area size in thread stack"); } #if VERBOSE > 4 output("Guard size set to %i\n", (scenarii[i].guard==1)?1:pagesize); #endif } #endif if (tss>0) /* This routine is dependent on the Thread Stack Size Attribute option */ { if (scenarii[i].altsize != 0) { ret = pthread_attr_setstacksize(&scenarii[i].ta, minstacksize); if (ret != 0) { UNRESOLVED(ret, "Unable to change stack size"); } #if VERBOSE > 4 output("Stack size set to %i (this is the min)\n", minstacksize); #endif } } #if VERBOSE > 4 else output("TSS unsupported => stack size unchanged\n"); #endif ret = sem_init(&scenarii[i].sem, 0,0); if (ret == -1) { UNRESOLVED(errno, "Unable to init a semaphore"); } } #if VERBOSE > 0 output("All %i thread attribute objects were initialized\n\n", NSCENAR); #endif } /* This function will free all resources consumed in the scenar_init() routine */ void scenar_fini(void) { int ret = 0, i; for (i=0; i 0 output("-----\n"); output("Starting test with scenario (%i): %s\n", sc, scenarii[sc].descr); #endif ret = pthread_create(&child, &scenarii[sc].ta, threaded, NULL); switch (scenarii[sc].result) { case 0: /* Operation was expected to succeed */ if (ret != 0) { UNRESOLVED(ret, "Failed to create this thread"); } break; case 1: /* Operation was expected to fail */ if (ret == 0) { UNRESOLVED(-1, "An error was expected but the thread creation succeeded"); } break; case 2: /* We did not know the expected result */ default: #if VERBOSE > 0 if (ret == 0) { output("Thread has been created successfully for this scenario\n"); } else { output("Thread creation failed with the error: %s\n", strerror(ret)); } #endif } if (ret == 0) /* The new thread is running */ { if (scenarii[sc].detached == 0) { ret = pthread_join(child, NULL); if (ret != 0) { UNRESOLVED(ret, "Unable to join a thread"); } } else { /* Just wait for the thread to terminate */ do { ret = sem_wait(&scenarii[sc].sem); } while ((ret == -1) && (errno == EINTR)); if (ret == -1) { UNRESOLVED(errno, "Failed to wait for the semaphore"); } } } } scenar_fini(); #if VERBOSE > 0 output("-----\n"); output("All test data destroyed\n"); output("Test PASSED\n"); #endif PASSED; } #endif posixtestsuite/conformance/interfaces/pthread_create/11-1.c0100644000000000000000000000314410470232724023006 0ustar rootroot/* * Copyright (c) 2004, Intel Corporation. All rights reserved. * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * * adam.li@intel.com * * if _POSIX_THREAD_CPUTIME is defined, the new thread shall have a CPU-time * clock accessible, and the initial value of this clock shall be set to 0. */ /* Create a new thread and get the time of the thread CUP-time clock * using clock_gettime(). * Note, the tv_nsec cannot be exactly 0 at the time of calling * clock_gettime() since the thread has executed some time. */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include "posixtest.h" void *a_thread_func() { clockid_t cpuclock; struct timespec ts = {.tv_sec = 1, .tv_nsec = 1}; pthread_getcpuclockid(pthread_self(), &cpuclock); clock_gettime(cpuclock, &ts); /* Just test the tv_sec field here. */ if (ts.tv_sec != 0) { printf("ts.tv_sec: %ld, ts.tv_nsec: %ld\n", ts.tv_sec, ts.tv_nsec); exit(PTS_FAIL); } pthread_exit(0); return NULL; } int main() { #if _POSIX_THREAD_CPUTIME == -1 printf("_POSIX_THREAD_CPUTIME not supported\n"); return PTS_UNSUPPORTED; #endif pthread_t new_th; if (sysconf(_SC_THREAD_CPUTIME) == -1) { printf("_POSIX_THREAD_CPUTIME not supported\n"); return PTS_UNSUPPORTED; } if(pthread_create(&new_th, NULL, a_thread_func, NULL) != 0) { perror("Error creating thread\n"); return PTS_UNRESOLVED; } pthread_join(new_th, NULL); printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_create/10-1.c0100644000000000000000000001100310044455743023003 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test pthread_create(). * * If pthread_create() fails, no new thread is created and the contents of the * location referenced by 'thread' is undefined. * * EXPLANATION: 3 ways that pthread_create can fail is if (1) The system lacked memory * resources. (2) The caller did not have the appropriate permissions. (3) An invalid * attributes object was passed. Since the last situation is the easiest to implement, that * is the one I chose to use in order to make pthread_create fail. * * The problem with that is that accessing an uninitialized attributes object will cause a * segmentation fault (since it usually points to garbage). So the idea here is to catch * the SIGSEGV signal (segmentation faults), and to see if the thread was ever created, by * setting a flag in the thread's starting routine. * * I recognize that causing pthread_create() to fail gracefully is a very difficult task, * especially taking into consideration that a lot of it is implementation-specific. I did * try to manually set the members of a pthread_attr_t object to invalid values, but that didn't * seem to make pthread_create() fail at all, in any of the implementations I tested on. So for * now, this is what we have. * * * Steps: * 1. Create a thread using pthread_create() with an invalid attributes object (uninitialized). * 2. Catch the SIGSEGV (seg fault) signal. In the signal handler, check to make sure that * the start routine for the thread was never reached, meaning the thread was never created. * 3. If SIGSEGV was not caught in 10 seconds, the test times out and fails. If the signal * was caught, but the thread start routine was called at some point, the test also fails. * * * - adam.li@intel.com: 2004-04-30 * This case will end with segmentation fault. * I happened to find on NPTL pthread_create() can fail is * pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_INHERIT), while * does not call pthread_attr_setschedparam() to set the prority. (since * by default the priority will be 0. But this is implementation specific. */ #include #include #include #include #include #include "posixtest.h" int created_thread; /* Flag indicating that the thread start routine was reached, and therefore, the thread was created. */ int segfault_flag; /* Flag indicating that a segmentation fault occured. */ /* Thread's start routine. */ void *a_thread_func() { /* Indicate that the thread start routine was reached. If it was reached, the test * fails, as the thread should have not been created in the first place. */ created_thread = 1; pthread_exit(0); return NULL; } /* Signal handler for SIGSEGV (segmentation fault signal) */ void sig_handler(int sig) { /* If a segmentation fault occured when it was supposed to (i.e. when pthread_create() * was called with the invalid attributes object). */ if(segfault_flag == 1) { /* check if the thread start routine was called. If yes, then the thread was * created, meaning the test fails. */ if(created_thread == 1) { printf("Test FAILED: Created thread though an invalid attribute was passed to pthread_create().\n"); pthread_exit((void*)PTS_FAIL); } printf("Test PASSED\n"); pthread_exit((void*)PTS_PASS); return; } printf("Test FAILED: Did not receive segmentation fault signal, waited 10 seconds.\n"); pthread_exit((void*)PTS_FAIL); return; } /* MAIN */ int main() { pthread_t new_th; pthread_attr_t inv_attr; struct sigaction act; /* Inializing flags. */ segfault_flag = 1; created_thread = 0; /* Set signal handler for SIGSEGV (seg fault) */ act.sa_handler = sig_handler; act.sa_flags = 0; sigaction(SIGSEGV, &act, NULL); /* Create the thread with the invalid, uninitialized attributes object. */ pthread_create(&new_th, &inv_attr, a_thread_func, NULL); /* Should not reach here if process correctly seg-faulted. */ segfault_flag = 0; /* Timeout after 10 seconds if a segfault was not encountered. The test then fails. */ sleep(10); /* Manually send the SIGSEGV signal to the signal handler. If this point is reached, * the test fails. */ if(raise(SIGSEGV) != 0) { perror("Error in raise()\n"); return PTS_UNRESOLVED; } printf("Test FAILED.\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/pthread_create/8-2.c0100644000000000000000000002147610220477770022752 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertion: * * The new thread inherits is signal mask from the calling thread, * and has no pending signal at creation time. * The steps are: * 1. In main(), create a signal mask with a few signals in the set (SIGUSR1 and SIGUSR2). * 2. Raise those signals in main. These signals now should be pending. * 3. Create a thread using pthread_create(). * 4. The thread should have the same signal mask, but no signals should be pending. * Parts of this test are copied from 8-1.c (author: rolla.n.selbak REMOVE-THIS AT intel DOT com) */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /* Some routines are part of the XSI Extensions */ #ifndef WITHOUT_XOPEN #define _XOPEN_SOURCE 600 #endif /********************************************************************************************/ /****************************** standard includes *****************************************/ /********************************************************************************************/ #include #include #include #include #include #include #include #include #include #include #include #include /********************************************************************************************/ /****************************** Test framework *****************************************/ /********************************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /********************************************************************************************/ /********************************** Configuration ******************************************/ /********************************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif /********************************************************************************************/ /*********************************** Test cases *****************************************/ /********************************************************************************************/ #include "threads_scenarii.c" /* This file will define the following objects: * scenarii: array of struct __scenario type. * NSCENAR : macro giving the total # of scenarii * scenar_init(): function to call before use the scenarii array. * scenar_fini(): function to call after end of use of the scenarii array. */ /********************************************************************************************/ /*********************************** Real Test *****************************************/ /********************************************************************************************/ typedef struct { sigset_t mask; sigset_t pending; } testdata_t; /* Thread function; which will check the signal mask and pending signals */ void * threaded(void * arg) { int ret; testdata_t * td=(testdata_t *)arg; /* Obtain the signal mask of this thread. */ ret = pthread_sigmask(SIG_SETMASK, NULL, &(td->mask)); if (ret != 0) { UNRESOLVED(ret, "Failed to get the signal mask of the thread"); } /* Obtain the pending signals of this thread. It should be empty. */ ret = sigpending(&(td->pending)); if (ret != 0) { UNRESOLVED(errno, "Failed to get pending signals from the thread"); } /* Signal we're done (especially in case of a detached thread) */ do { ret = sem_post(&scenarii[sc].sem); } while ((ret == -1) && (errno == EINTR)); if (ret == -1) { UNRESOLVED(errno, "Failed to wait for the semaphore"); } /* return */ return arg; } int main (int argc, char *argv[]) { int ret=0; pthread_t child; testdata_t td_parent, td_thread; /* Initialize output routine */ output_init(); /* Initialize thread attribute objects */ scenar_init(); /* Initialize the signal state */ ret = sigemptyset(&(td_parent.mask)); if (ret != 0) { UNRESOLVED(ret, "Failed to initialize a signal set"); } ret = sigemptyset(&(td_parent.pending)); if (ret != 0) { UNRESOLVED(ret, "Failed to initialize a signal set"); } /* Add SIGCONT, SIGUSR1 and SIGUSR2 to the set of blocked signals */ ret = sigaddset(&(td_parent.mask), SIGUSR1); if (ret != 0) { UNRESOLVED(ret, "Failed to add SIGUSR1 to the signal set"); } ret = sigaddset(&(td_parent.mask), SIGUSR2); if (ret != 0) { UNRESOLVED(ret, "Failed to add SIGUSR2 to the signal set"); } /* Block those signals. */ ret = pthread_sigmask(SIG_SETMASK, &(td_parent.mask), NULL); if (ret != 0) { UNRESOLVED(ret, "Failed to mask the singals in main"); } /* Raise those signals so they are now pending. */ ret = raise(SIGUSR1); if (ret != 0) { UNRESOLVED(errno, "Failed to raise SIGUSR1"); } ret = raise(SIGUSR2); if (ret != 0) { UNRESOLVED(errno, "Failed to raise SIGUSR2"); } /* Do the testing for each thread */ for (sc=0; sc < NSCENAR; sc++) { #if VERBOSE > 0 output("-----\n"); output("Starting test with scenario (%i): %s\n", sc, scenarii[sc].descr); #endif /* (re)initialize thread signal sets */ ret = sigemptyset(&(td_thread.mask)); if (ret != 0) { UNRESOLVED(ret, "Failed to initialize a signal set"); } ret = sigemptyset(&(td_thread.pending)); if (ret != 0) { UNRESOLVED(ret, "Failed to initialize a signal set"); } ret = pthread_create(&child, &scenarii[sc].ta, threaded, &td_thread); switch (scenarii[sc].result) { case 0: /* Operation was expected to succeed */ if (ret != 0) { UNRESOLVED(ret, "Failed to create this thread"); } break; case 1: /* Operation was expected to fail */ if (ret == 0) { UNRESOLVED(-1, "An error was expected but the thread creation succeeded"); } break; case 2: /* We did not know the expected result */ default: #if VERBOSE > 0 if (ret == 0) { output("Thread has been created successfully for this scenario\n"); } else { output("Thread creation failed with the error: %s\n", strerror(ret)); } #endif } if (ret == 0) /* The new thread is running */ { if (scenarii[sc].detached == 0) { ret = pthread_join(child, NULL); if (ret != 0) { UNRESOLVED(ret, "Unable to join a thread"); } } else { /* Just wait for the thread to terminate */ do { ret = sem_wait(&scenarii[sc].sem); } while ((ret == -1) && (errno == EINTR)); if (ret == -1) { UNRESOLVED(errno, "Failed to wait for the semaphore"); } } /* The thread has terminated its work, so we can now control */ ret = sigismember(&(td_thread.mask), SIGUSR1); if (ret != 1) { if (ret == 0) { FAILED("The thread did not inherit the signal mask"); } /* else */ UNRESOLVED(ret, "sigismember() failed"); } ret = sigismember(&(td_thread.mask), SIGUSR2); if (ret != 1) { if (ret == 0) { FAILED("The thread did not inherit the signal mask"); } /* else */ UNRESOLVED(ret, "sigismember() failed"); } ret = sigismember(&(td_thread.pending), SIGUSR1); if (ret != 0) { if (ret == 1) { FAILED("The thread inherited the pending signal SIGUSR1"); } /* else */ UNRESOLVED(ret, "sigismember() failed"); } ret = sigismember(&(td_thread.pending), SIGUSR2); if (ret != 0) { if (ret == 1) { FAILED("The thread inherited the pending signal SIGUSR2"); } /* else */ UNRESOLVED(ret, "sigismember() failed"); } } } scenar_fini(); #if VERBOSE > 0 output("-----\n"); output("All test data destroyed\n"); output("Test PASSED\n"); #endif PASSED; } posixtestsuite/conformance/interfaces/pthread_create/3-2.c0100644000000000000000000005170510310236030022721 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertion: * * Once the thread has been created, subsequent changes to the * thread attribute object don't affect the running thread. * The steps are: * -> stack grow * -> create a thread with minimal stack size * -> change the stack size to a bigger value * -> check that the thread stack size did not change. * -> stack decrease * -> create a thread with a known stack size (> minimum) * -> change the stack size to the min value * -> check that the thread stack size did not change. * -> sched policy/param change * -> create a new thread with a known policy * -> change the policy in the thread attribute and check the thread policy did not change * -> change the schedparam in the thread attribute and check the thread priority did not change * -> change the policy in the running thread and check the thread attribute did not change. * -> change the priority in the running thread and check the thread attribute did not change. * The test fails if one of the checking fails */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /* Some routines are part of the XSI Extensions */ #ifndef WITHOUT_XOPEN #define _XOPEN_SOURCE 600 #endif /********************************************************************************************/ /****************************** standard includes *****************************************/ /********************************************************************************************/ #include #include #include #include #include #include #include #include #include #include #include /********************************************************************************************/ /****************************** Test framework *****************************************/ /********************************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /********************************************************************************************/ /********************************** Configuration ******************************************/ /********************************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif /********************************************************************************************/ /*********************************** Test cases *****************************************/ /********************************************************************************************/ #include "threads_scenarii.c" /* This file will define the following objects: * scenarii: array of struct __scenario type. * NSCENAR : macro giving the total # of scenarii * scenar_init(): function to call before use the scenarii array. * scenar_fini(): function to call after end of use of the scenarii array. */ /********************************************************************************************/ /*********************************** Real Test *****************************************/ /********************************************************************************************/ sem_t semsync[2]; /* These semaphores will only be used in child process! */ /* The overflow function is used to test the stack overflow */ void * overflow(void * arg) { void * current; void * pad[50]; /* We want to consume the stack quickly */ long stacksize = sysconf(_SC_THREAD_STACK_MIN); /* make sure we touch the current stack memory */ pad[1]=NULL; /* so compiler stops complaining about unused variables */ int ret = 0; if (arg == NULL) { /* first call */ /* Synchronize with the parent */ do { ret = sem_wait(&semsync[0]); } while ((ret == -1) && (errno == EINTR)); if (ret == -1) { UNRESOLVED(errno, "Failed to wait for the semaphore"); } /* Go to recursion */ current = overflow(¤t); /* Terminated */ do { ret = sem_post(&semsync[1]); } while ((ret == -1) && (errno == EINTR)); if (ret == -1) { UNRESOLVED(errno, "Failed to post the semaphore"); } /* Terminate the overflow thread */ return current; } /* we cast the pointers into long, which might be a problem on some architectures... */ if ( ((long)arg) < ((long)¤t)) { /* the stack is growing up */ if ( ((long)¤t) - ((long)arg) >= stacksize) { output("Growing up stack started below %p and we are currently up to %p\n", arg, ¤t); return (void *)0; } } else { /* the stack is growing down */ if ( ((long)arg) - ((long)¤t) >= stacksize) { output("Growing down stack started upon %p and we are currently down to %p\n", arg, ¤t); return (void *)0; } } /* We are not yet overflowing, so we loop */ return overflow(arg); } /* The following function will return 0 if a thread created with the attribute ta is able to fill the stack up to {minstacksize}. 1 if the operation failed. 2 if an error prevented the test to complete If newsize is not 0, the stack size in ta will be set to this value once the thread is created. */ int test_stack(pthread_attr_t * ta, size_t newsize) { pid_t child, ctrl; int status; int ret; child=fork(); /* We'll test the feature in another process as this test may segfault */ if (child == -1) { output("Failed to fork (%s)\n", strerror(errno)); return 2; } if (child != 0) /* father */ { /* Just wait for the child and check its return value */ ctrl = waitpid(child, &status, 0); if (ctrl != child) { output("Failed to wait for process termination (%s)\n", strerror(errno)); return 2; } if (WIFEXITED(status)) /* The process exited */ { if (WEXITSTATUS(status) == 0) { return 0; } /* We were able to fill the stack */ if (WEXITSTATUS(status) == PTS_UNRESOLVED) { output("The child process returned unresolved status\n"); return 2; } else { output("The child process returned: %i\n", WEXITSTATUS(status)); return 2; } } else { #if VERBOSE > 4 output("The child process did not return\n"); if (WIFSIGNALED(status)) output("It was killed with signal %i\n", WTERMSIG(status)); else output("neither was it killed. (status = %i)\n", status); #endif } return 1; } /* else */ /* this is the new process */ { pthread_t th; void * rc; int detach; /* Semaphore to force the child to wait */ ret = sem_init(&semsync[0], 0,0); if (ret == -1) { UNRESOLVED(errno, "Unable to init a semaphore"); } /* Semaphore to detect thread ending */ ret = sem_init(&semsync[1], 0,0); if (ret == -1) { UNRESOLVED(errno, "Unable to init a semaphore"); } ret = pthread_create(&th, ta, overflow, NULL); /* Create a new thread with the same attributes */ if (ret != 0) { UNRESOLVED(ret, "Unable to create a thread in the new process"); } /* If we were asked to perform a change on ta, do it now. */ if (newsize) { ret = pthread_attr_setstacksize(ta, newsize); if (ret != 0) { UNRESOLVED(ret, "Failed to set the new stack size"); } } /* Ok the child can run now */ do { ret = sem_post(&semsync[0]); } while ((ret == -1) && (errno == EINTR)); if (ret == -1) { UNRESOLVED(errno, "Failed to post the semaphore"); } /* Wait for its termination */ do { ret = sem_wait(&semsync[1]); } while ((ret == -1) && (errno == EINTR)); if (ret == -1) { UNRESOLVED(errno, "Failed to wait for the semaphore"); } if (ta != NULL) { ret = pthread_attr_getdetachstate(ta, &detach); if (ret != 0) { UNRESOLVED(ret, "Failed to get detach state from the thread attribute"); } } else { detach = PTHREAD_CREATE_JOINABLE; /* default */ } if (detach == PTHREAD_CREATE_JOINABLE) { ret = pthread_join(th, &rc); if (ret != 0) { UNRESOLVED(ret, "Unable to join a thread"); } if (rc != (void *)0) { UNRESOLVED((int)(long)rc, "The overflow function returned an unexpected value"); } } /* Terminate the child process here */ exit(0); } } typedef struct { pthread_barrier_t bar; int policy; struct sched_param param; } testdata_t; void * schedtest(void * arg) { testdata_t * td = (testdata_t *)arg; int newpol, ret=0; struct sched_param newparam; /* Read the current sched policy & param */ ret = pthread_getschedparam(pthread_self(), &(td->policy), &(td->param)); if (ret != 0) { UNRESOLVED(ret, "Failed to read current thread policy / param"); } /* sync 1 */ ret = pthread_barrier_wait(&(td->bar)); if ((ret != 0) && (ret != PTHREAD_BARRIER_SERIAL_THREAD)) { UNRESOLVED(ret, "Failed to synchronize on the barrier"); } /* sync 2 */ ret = pthread_barrier_wait(&(td->bar)); if ((ret != 0) && (ret != PTHREAD_BARRIER_SERIAL_THREAD)) { UNRESOLVED(ret, "Failed to synchronize on the barrier"); } /* Read the current sched policy & param */ ret = pthread_getschedparam(pthread_self(), &(td->policy), &(td->param)); if (ret != 0) { UNRESOLVED(ret, "Failed to read current thread policy / param"); } /* sync 3 */ ret = pthread_barrier_wait(&(td->bar)); if ((ret != 0) && (ret != PTHREAD_BARRIER_SERIAL_THREAD)) { UNRESOLVED(ret, "Failed to synchronize on the barrier"); } /* sync 4 */ ret = pthread_barrier_wait(&(td->bar)); if ((ret != 0) && (ret != PTHREAD_BARRIER_SERIAL_THREAD)) { UNRESOLVED(ret, "Failed to synchronize on the barrier"); } /* Change the current sched policy & param */ if (td->policy == SCHED_RR) newpol = SCHED_FIFO; else newpol = SCHED_RR; newparam.sched_priority = sched_get_priority_max(newpol); if (newparam.sched_priority == td->param.sched_priority) newparam.sched_priority--; ret = pthread_setschedparam(pthread_self(), newpol, &newparam); #if VERBOSE > 0 if (ret != 0) output("Changing the current thread sched policy failed with error: %s\n", strerror(ret)); #endif #if VERBOSE > 2 else output("Executing thread scheduling policy changed\n"); #endif /* sync 5 */ ret = pthread_barrier_wait(&(td->bar)); if ((ret != 0) && (ret != PTHREAD_BARRIER_SERIAL_THREAD)) { UNRESOLVED(ret, "Failed to synchronize on the barrier"); } /* Post the sem in case of a detached thread */ do { ret = sem_post(&scenarii[sc].sem); } while ((ret == -1) && (errno == EINTR)); if (ret == -1) { UNRESOLVED(errno, "Failed to post the semaphore"); } return NULL; } int main (int argc, char *argv[]) { int ret=0; int do_stack_tests; int do_sched_tests; /* Initialize output routine */ output_init(); /* Test abilities */ do_sched_tests = (sysconf(_SC_THREAD_PRIORITY_SCHEDULING)>0?1:0); do_stack_tests = (test_stack(NULL,0)==0?1:0); #if VERBOSE > 0 output("Test starting\n Stack tests %s be executed.\n Sched tests %s be executed.\n", do_stack_tests?"will":"won't", do_sched_tests?"will":"won't"); #endif /* Initialize thread attribute objects */ scenar_init(); for (sc=0; sc < NSCENAR; sc++) { #if VERBOSE > 0 output("-----\n"); output("Starting test with scenario (%i): %s\n", sc, scenarii[sc].descr); #endif if (do_stack_tests) { /* stack grow test */ /* We need the thread attribute to specify a minimal stack */ if ((scenarii[sc].altstack == 0) && (scenarii[sc].altsize == 1)) { #if VERBOSE > 2 output("Processing stack grow test\n"); #endif ret = test_stack(&scenarii[sc].ta, 2*sysconf(_SC_THREAD_STACK_MIN)); if (ret == 0) { if (scenarii[sc].guard == 2) { FAILED("Changing the stacksize after the thread was created changed the running thread stack size"); } #if VERBOSE > 2 else output("We were able to overflow the stack, but the guard area is unknow or null\n"); #endif } if ((ret != 2) && (scenarii[sc].result == 1)) { UNRESOLVED(-1, "An error was expected but the thread creation succeeded"); } #if VERBOSE > 2 if ((ret == 1)) { output("Stack grow test passed\n"); } if ((ret == 2) && (scenarii[sc].result == 2)) { output("Something went wrong -- we don't care in this case\n"); } #endif if ((ret == 2) && (scenarii[sc].result == 0)) { UNRESOLVED(-1, "An unexpected error occured\n"); } /* Ok, set back the thread attribute object to a correct value */ ret = pthread_attr_setstacksize(&scenarii[sc].ta, sysconf(_SC_THREAD_STACK_MIN)); if (ret != 0) { UNRESOLVED(ret, "Failed to set stacksize back"); } } /* stack decrease test */ if ((scenarii[sc].altstack == 0) && (scenarii[sc].altsize == 0)) { #if VERBOSE > 2 output("Processing stack decrease test\n"); #endif ret = test_stack(&scenarii[sc].ta, sysconf(_SC_THREAD_STACK_MIN)); if (ret == 1) { FAILED("Decreasing the stack size after thread is created had an influence on the thread"); } if ((ret == 0) && (scenarii[sc].result == 1)) { UNRESOLVED(-1, "An error was expected but the thread creation succeeded"); } if ((ret == 2) && (scenarii[sc].result == 0)) { UNRESOLVED(-1, "An unexpected error occured\n"); } #if VERBOSE > 2 if (ret == 0) output("Stack decrease test passed.\n"); else output("Something failed but we don't care here.\n"); #endif } } /* if do_stack_tests */ if (do_sched_tests) { /* Sched policy/param change test */ if (scenarii[sc].explicitsched != 0) /* We need a specified policy */ { pthread_t child; int policy_ori, newpol_max; struct sched_param param_ori, tmp; testdata_t td; #if VERBOSE > 2 output("Processing sched policy/param change test\n"); #endif /* Backup the scenario object */ ret = pthread_attr_getschedpolicy(&(scenarii[sc].ta), &policy_ori); if (ret != 0) { UNRESOLVED(ret, "Unable to read sched policy from thread attribute"); } ret = pthread_attr_getschedparam(&(scenarii[sc].ta), ¶m_ori); if (ret != 0) { UNRESOLVED(ret, "Unable to read sched param from thread attribute"); } /* Initialize the barrier */ ret = pthread_barrier_init(&(td.bar), NULL, 2); if (ret != 0) { UNRESOLVED(ret, "Unable to initialize the barrier"); } /* Create a new thread with this scenario attribute */ ret = pthread_create(&child, &(scenarii[sc].ta), schedtest, &td); if (ret != 0) { if (scenarii[sc].result == 0) { UNRESOLVED(ret , "Failed to create a thread"); } #if VERBOSE > 2 if (scenarii[sc].result == 2) { output("The thread creation failed -- we don't care\n"); } if (scenarii[sc].result == 1) { output("The thread creation failed as expected\n"); } #endif } else /* Thread created */ { if (scenarii[sc].result == 1) { UNRESOLVED(-1, "The thread was created where an error was expected"); } #if VERBOSE > 2 if (scenarii[sc].result == 2) output("Thread is created\n"); #endif /* sync 1 */ ret = pthread_barrier_wait(&(td.bar)); if ((ret != 0) && (ret != PTHREAD_BARRIER_SERIAL_THREAD)) { UNRESOLVED(ret, "Failed to synchronize on the barrier"); } /* Check the new thread reports the attributes */ if (td.policy != policy_ori) { FAILED("The new thread does not report the scheluling policy that was specified"); } if (td.param.sched_priority != param_ori.sched_priority) { FAILED("The new thread does not report the scheduling priority that was specified at creation"); } /* Change the thread attribute object policy & param */ if (policy_ori == SCHED_RR) { ret = pthread_attr_setschedpolicy(&(scenarii[sc].ta), SCHED_FIFO); newpol_max = sched_get_priority_max(SCHED_FIFO); } else { ret = pthread_attr_setschedpolicy(&(scenarii[sc].ta), SCHED_RR); newpol_max = sched_get_priority_max(SCHED_RR); } if (ret != 0) { UNRESOLVED(ret, "Failed to change the attribute object"); } if (newpol_max == param_ori.sched_priority) newpol_max--; tmp.sched_priority = newpol_max; ret = pthread_attr_setschedparam(&(scenarii[sc].ta), &tmp); if (ret != 0) { UNRESOLVED(ret, "Failed to set the attribute sched param"); } /* sync 2 */ ret = pthread_barrier_wait(&(td.bar)); if ((ret != 0) && (ret != PTHREAD_BARRIER_SERIAL_THREAD)) { UNRESOLVED(ret, "Failed to synchronize on the barrier"); } /* sync 3 */ ret = pthread_barrier_wait(&(td.bar)); if ((ret != 0) && (ret != PTHREAD_BARRIER_SERIAL_THREAD)) { UNRESOLVED(ret, "Failed to synchronize on the barrier"); } /* Check if the thread saw the change (should not) */ if (td.policy != policy_ori) { FAILED("The new thread does not report the scheluling policy that was specified"); } if (td.param.sched_priority != param_ori.sched_priority) { FAILED("The new thread does not report the scheduling priority that was specified at creation"); } /* Check what we can see for the child thread from here */ ret = pthread_getschedparam(child, &(td.policy), &(td.param)); if (ret != 0) { UNRESOLVED(ret, "Failed to read child thread policy / param"); } if (td.policy != policy_ori) { FAILED("The child thread does not report the scheduling policy that was specified at creation"); } if (td.param.sched_priority != param_ori.sched_priority) { FAILED("The child thread does not report the scheduling priority that was specified at creation"); } /* Restore the thread attribute */ ret = pthread_attr_setschedpolicy(&(scenarii[sc].ta), policy_ori); if (ret != 0) { UNRESOLVED(ret, "Unable to read sched policy from thread attribute"); } ret = pthread_attr_setschedparam(&(scenarii[sc].ta), ¶m_ori); if (ret != 0) { UNRESOLVED(ret, "Unable to read sched param from thread attribute"); } /* sync 4*/ ret = pthread_barrier_wait(&(td.bar)); if ((ret != 0) && (ret != PTHREAD_BARRIER_SERIAL_THREAD)) { UNRESOLVED(ret, "Failed to synchronize on the barrier"); } /* sync 5*/ ret = pthread_barrier_wait(&(td.bar)); if ((ret != 0) && (ret != PTHREAD_BARRIER_SERIAL_THREAD)) { UNRESOLVED(ret, "Failed to synchronize on the barrier"); } /* check if the thread attribute reports a change (should not) */ ret = pthread_attr_getschedpolicy(&(scenarii[sc].ta), &(td.policy)); if (ret != 0) { UNRESOLVED(ret, "Unable to read sched policy from thread attribute"); } ret = pthread_attr_getschedparam(&(scenarii[sc].ta), &(td.param)); if (ret != 0) { UNRESOLVED(ret, "Unable to read sched param from thread attribute"); } if (td.policy != policy_ori) { FAILED("The child thread does not report the scheduling policy that was specified at creation"); } if (td.param.sched_priority != param_ori.sched_priority) { FAILED("The child thread does not report the scheduling priority that was specified at creation"); } /* Wait for the sem and join eventually the thread */ do { ret = sem_wait(&scenarii[sc].sem); } while ((ret == -1) && (errno == EINTR)); if (ret == -1) { UNRESOLVED(errno, "Failed to wait for the semaphore"); } if (scenarii[sc].detached == 0) { ret = pthread_join(child, NULL); if (ret != 0) { UNRESOLVED(ret, "Unable to join a thread"); } } #if VERBOSE > 2 output("Sched policy/param change test passed\n"); #endif } /* thread created */ } /* We could also test if the inheritsched does not influence the new thread */ } /* if do_sched_tests */ } scenar_fini(); #if VERBOSE > 0 output("-----\n"); output("All test data destroyed\n"); output("Test PASSED\n"); #endif PASSED; } posixtestsuite/conformance/interfaces/pthread_create/1-2.c0100644000000000000000000000264607626776061022754 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_create() creates a new thread with attributes specified * by 'attr', within a process. * * Steps: * 1. Create a thread using pthread_create() * 2. Cancel that thread with pthread_cancel() * 3. If that thread doesn't exist, then it pthread_cancel() will return * an error code. This would mean that pthread_create() did not create * a thread successfully. */ #include #include #include #include "posixtest.h" void *a_thread_func() { sleep(10); /* Shouldn't reach here. If we do, then the pthread_cancel() * function did not succeed. */ perror("Could not send cancel request correctly\n"); pthread_exit(0); return NULL; } int main() { pthread_t new_th; if(pthread_create(&new_th, NULL, a_thread_func, NULL) < 0) { perror("Error creating thread\n"); return PTS_UNRESOLVED; } /* Try to cancel the newly created thread. If an error is returned, * then the thread wasn't created successfully. */ if(pthread_cancel(new_th) != 0) { printf("Test FAILED: A new thread wasn't created\n"); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_create/assertions.xml0100644000000000000000000000657010112610347025177 0ustar rootroot The int pthread_create(pthread_t *restrict thread, const pthread_attr_t *restrict attr, void *(*start_routine) (void*), void *restrict arg); creates a new thread, with attributes specified by 'attr', within a process. If 'attr' is NULL, the default attributes shall be used. The attribute that will be tested is the detached state, because that is the only state that has a default listed in the specification. default: PTHREAD_CREATE_JOINABLE Other valid values: PTHREAD_CREATE_DETACHED If the attributes specified by 'attr' are modified later after the thread is create, the thread's attributes should not be affected. If success, pthread_create() will store the ID of the the created thread in the location referenced by 'thread'. The thread is created executing 'start_routine' with 'arg' as its only argument. If the 'start_routine' returns, the effect shall be as if there was an implicit call to pthread_exit() using the return value of 'start_routine' as the exit status. NOTE: that the thread in which main() was originally invoked is different from this When it returns from main(), the effect shall be as if there was an implicit call to exit() using the return value of main() as the exit status. The signal state of the new thread will be initialized as so: - The signal mask shall be inherited from the created thread - The set of signals pending for the new thread shall be empty. The floating point environment shall be inherited from the created thread. If pthread_create() fails, no new thread is created and the contents of the location referenced by 'thread' is undefined. if _POSIX_THREAD_CPUTIME is defined, the new thread shall have a CPU-time clock accessible, and the initial value of this clock shall be set to 0. If success, pthread_create() returns zero. If pthread_create() fails, an error number is returned: - [EAGAIN] The system lacked the resources to create another thread, or the system-imposed limit on the total number of threads in a process {PTHREAD_THREADS_MAX} would be exceeded. - [EINVAL] The value specified by 'attr' is invalid. - [EPERM] The caller does not have the appropriate permission to set the required scheduling parameters or scheduling policy. [EINTR] must not be returned. If the current thread uses an alternate stack, the new thread does not inherit this stack. posixtestsuite/conformance/interfaces/pthread_create/coverage.txt0100644000000000000000000000060410035445060024611 0ustar rootrootThis document defines the coverage for the pthread_create function: Assertion Tested? 1 YES - Also, need to test 'attr' values. 2 YES 3 YES 4 YES 5 YES 6 NO - Skipping. 7 NO - Skipping. 8 YES 9 NO - Skipping. (Floating point environment?) 10 YES - Peculiar behavior of passing the test and then freezing on the linuxthreads implementation. 11 YES 12 YES 13 YES Note: posixtestsuite/conformance/interfaces/pthread_create/testfrmw.h0100644000000000000000000000456410121521263024306 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * * This file is a wrapper to use the tests from the NPTL Test & Trace Project * with either the Linux Test Project or the Open POSIX Test Suite. * The following macros are defined here: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate without calling one of those macros. * * */ #include "posixtest.h" #include /* for the strerror() routine */ #ifdef __GNUC__ /* We are using GCC */ #define UNRESOLVED(x, s) \ { output("Test %s unresolved: got %i (%s) on line %i (%s)\n", __FILE__, x, strerror(x), __LINE__, s); \ output_fini(); \ exit(PTS_UNRESOLVED); } #define FAILED(s) \ { output("Test %s FAILED: %s\n", __FILE__, s); \ output_fini(); \ exit(PTS_FAIL); } #define PASSED \ output_fini(); \ exit(PTS_PASS); #define UNTESTED(s) \ { output("File %s cannot test: %s\n", __FILE__, s); \ output_fini(); \ exit(PTS_UNTESTED); \ } #else /* not using GCC */ #define UNRESOLVED(x, s) \ { output("Test unresolved: got %i (%s) on line %i (%s)\n", x, strerror(x), __LINE__, s); \ output_fini(); \ exit(PTS_UNRESOLVED); } #define FAILED(s) \ { output("Test FAILED: %s\n", s); \ output_fini(); \ exit(PTS_FAIL); } #define PASSED \ output_fini(); \ exit(PTS_PASS); #define UNTESTED(s) \ { output("Unable to test: %s\n", s); \ output_fini(); \ exit(PTS_UNTESTED); \ } #endif posixtestsuite/conformance/interfaces/pthread_create/8-1.c0100644000000000000000000000756707631757720022766 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test pthread_create() * * The signal state of the new thread will be initialized as so: * * - The signal mask shall be inherited from the created thread * - The set of signals pending for the new thread shall be empty. * * Steps: * 1. In main(), create a signal mask with a few signals in the set (SIGUSR1 and SIGUSR2). * 2. Raise those signals in main. These signals now should be pending. * 3. Create a thread using pthread_create(). * 4. The thread should have the same signal mask, but no signals should be pending. * */ #include #include #include #include "posixtest.h" sigset_t th_pendingset, th_sigmask; void *a_thread_func() { /* Obtain the signal mask of this thread. */ pthread_sigmask(SIG_SETMASK, NULL, &th_sigmask); /* Obtain the pending signals of this thread. It should be empty. */ if (sigpending(&th_pendingset) != 0) { printf("Error calling sigpending()\n"); return (void *)PTS_UNRESOLVED; } pthread_exit(0); return NULL; } int main() { pthread_t new_th; sigset_t main_sigmask, main_pendingset; int ret; /* Empty set of signal mask and blocked signals */ if ( (sigemptyset(&main_sigmask) != 0) || (sigemptyset(&main_pendingset) != 0) ) { perror("Error in sigemptyset()\n"); return PTS_UNRESOLVED; } /* Add SIGCONT, SIGUSR1 and SIGUSR2 to the set of blocked signals */ if (sigaddset(&main_sigmask, SIGUSR1) != 0) { perror("Error in sigaddset()\n"); return PTS_UNRESOLVED; } if (sigaddset(&main_sigmask, SIGUSR2) != 0) { perror("Error in sigaddset()\n"); return PTS_UNRESOLVED; } /* Block those signals. */ if (pthread_sigmask(SIG_SETMASK, &main_sigmask, NULL) != 0) { printf("Error in pthread_sigmask()\n"); return PTS_UNRESOLVED; } /* Raise those signals so they are now pending. */ if (raise(SIGUSR1) != 0) { printf("Could not raise SIGALRM\n"); return -1; } if (raise(SIGUSR2) != 0) { printf("Could not raise SIGALRM\n"); return -1; } /* Create a new thread. */ if(pthread_create(&new_th, NULL, a_thread_func, NULL) != 0) { perror("Error creating thread\n"); return PTS_UNRESOLVED; } /* Wait until the thread has finished execution. */ if(pthread_join(new_th, NULL) != 0) { perror("Error in pthread_join()\n"); return PTS_UNRESOLVED; } /* Check to make sure that the sigmask of the thread is the same as the main thread */ ret = sigismember(&th_sigmask, SIGUSR1); if(ret != 1) { if(ret == 0) { printf("Error: Thread did not inherit main()s signal mask. SIGUSR1 not a member of the signal set.\n"); return PTS_FAIL; } perror("Error is sigismember()\n"); return PTS_UNRESOLVED; } ret = sigismember(&th_sigmask, SIGUSR2); if(ret != 1) { if(ret == 0) { printf("Test FAILED: Thread did not inherit main()s signal mask. SIGUSR2 not a member of the signal set.\n"); return PTS_FAIL; } perror("Error is sigismember()\n"); return PTS_UNRESOLVED; } /* Check to make sure that the pending set of the thread does not contain SIGUSR1 or * SIGUSR2. */ ret = sigismember(&th_pendingset, SIGUSR1); if(ret != 0) { if(ret == 1) { printf("Error: Thread did not inherit main()s signal mask. SIGUSR1 not a member of the signal set.\n"); return PTS_FAIL; } perror("Error is sigismember()\n"); return PTS_UNRESOLVED; } ret = sigismember(&th_pendingset, SIGUSR2); if(ret != 0) { if(ret == 1) { printf("Test FAILED: Thread did not inherit main()s signal mask. SIGUSR2 not a member of the signal set.\n"); return PTS_FAIL; } perror("Error is sigismember()\n"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_create/2-1.c0100644000000000000000000000314107626776062022744 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test If 'attr' is NULL, the default attributes shall be used. * The attribute that will be tested is the detached state, because that is * the only state that has a default listed in the specification. * * default: PTHREAD_CREATE_JOINABLE * Other valid values: PTHREAD_CREATE_DETACHED * * Steps: * 1. Create a thread using pthread_create() and passing 'NULL' for 'attr'. * 2. Check to see if the thread is joinable, since that is the default. * 3. We do this by calling pthread_join() and pthread_detach(). If * they fail, then the thread is not joinable, and the test fails. */ #include #include #include #include "posixtest.h" void *a_thread_func() { pthread_exit(0); return NULL; } int main() { pthread_t new_th; /* Create a new thread. The default attribute should be that * it is joinable. */ if(pthread_create(&new_th, NULL, a_thread_func, NULL) != 0) { perror("Error creating thread\n"); return PTS_UNRESOLVED; } /* The new thread should be able to be joined. */ if(pthread_join(new_th, NULL) == EINVAL) { printf("Test FAILED\n"); return PTS_FAIL; } /* The new thread should be able to be detached. */ if(pthread_detach(new_th) == EINVAL) { printf("Test FAILED\n"); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_create/1-6.c0100644000000000000000000002263310121521263022726 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertion: * * pthread_create creates a thread with attributes as specified in the attr parameter. * The steps are: * * -> See test 1-5.c for details * -> This one will test the scheduling behavior is correct. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /* Some routines are part of the XSI Extensions */ #ifndef WITHOUT_XOPEN #define _XOPEN_SOURCE 600 #endif /********************************************************************************************/ /****************************** standard includes *****************************************/ /********************************************************************************************/ #include #include #include #include #include #include #include #include #include #include #include /********************************************************************************************/ /****************************** Test framework *****************************************/ /********************************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /********************************************************************************************/ /********************************** Configuration ******************************************/ /********************************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif /* The value below shall be >= to the # of CPU on the test architecture */ #define NCPU (4) /********************************************************************************************/ /*********************************** Test cases *****************************************/ /********************************************************************************************/ #define STD_MAIN /* This allows main() to be defined in the included file */ #include "threads_scenarii.c" /* This file will define the following objects: * scenarii: array of struct __scenario type. * NSCENAR : macro giving the total # of scenarii * scenar_init(): function to call before use the scenarii array. * scenar_fini(): function to call after end of use of the scenarii array. */ /********************************************************************************************/ /*********************************** Real Test *****************************************/ /********************************************************************************************/ /* The 2 following functions are used for the scheduling tests */ void * lp_func(void * arg) { int * ctrl = (int *) arg; *ctrl=2; return NULL; } void * hp_func(void * arg) { int *ctrl = (int *) arg; int dummy=0, i; do { /* some dummy task */ dummy += 3; dummy %= 17; dummy *= 47; for (i=0; i<1000000000; i++); #if VERBOSE > 6 output("%p\n", pthread_self()); #endif } while (*ctrl == 0); return NULL; } void * threaded (void * arg) { int ret = 0; #if VERBOSE > 4 output("Thread %i starting...\n", sc); #endif /* Scheduling (priority) tests */ if ((sysconf(_SC_THREAD_PRIORITY_SCHEDULING) > 0) && (scenarii[sc].explicitsched != 0) && (scenarii[sc].schedpolicy != 0) && (scenarii[sc].schedparam == 1)) { /* We will create NCPU threads running with a high priority with the same sched policy policy and one with a low-priority. The low-priority thread should not run until the other threads stop running, unless the machine has more than NCPU processors... */ pthread_t hpth[NCPU]; /* High priority threads */ pthread_t lpth; /* Low Priority thread */ int ctrl; /* Check value */ pthread_attr_t ta; struct sched_param sp; int policy; int i=0; struct timespec now, timeout; /* Start with checking we are executing with the required parameters */ ret = pthread_getschedparam(pthread_self(), &policy, &sp); if (ret != 0) { UNRESOLVED(ret , "Failed to get current thread policy"); } if (((scenarii[sc].schedpolicy == 1) && (policy != SCHED_FIFO)) || ((scenarii[sc].schedpolicy == 2) && (policy != SCHED_RR))) { FAILED("The thread is not using the scheduling policy that was required"); } if (((scenarii[sc].schedparam == 1) && (sp.sched_priority != sched_get_priority_max(policy))) || ((scenarii[sc].schedparam ==-1) && (sp.sched_priority != sched_get_priority_min(policy)))) { FAILED("The thread is not using the scheduling parameter that was required"); } ctrl = 0; /* Initial state */ /* Get the policy information */ ret = pthread_attr_getschedpolicy(&scenarii[sc].ta, &policy); if (ret != 0) { UNRESOLVED(ret, "Failed to read sched policy"); } /* We put a timeout cause the test might lock the machine when it runs */ alarm(60); /* Create the high priority threads */ ret = pthread_attr_init(&ta); if (ret != 0) { UNRESOLVED(ret, "Failed to initialize a thread attribute object"); } ret = pthread_attr_setinheritsched(&ta, PTHREAD_EXPLICIT_SCHED); if (ret != 0) { UNRESOLVED(ret, "Unable to set inheritsched attribute"); } ret = pthread_attr_setschedpolicy(&ta, policy); if (ret != 0) { UNRESOLVED(ret, "Unable to set the sched policy"); } sp.sched_priority = sched_get_priority_max(policy) - 1; ret = pthread_attr_setschedparam(&ta, &sp); if (ret != 0) { UNRESOLVED(ret, "Failed to set the sched param"); } #if VERBOSE > 1 output("Starting %i high- and 1 low-priority threads.\n", NCPU); #endif for (i=0; i 5 output("The %i high-priority threads are running\n", NCPU); #endif /* Create the low-priority thread */ sp.sched_priority = sched_get_priority_min(policy); ret = pthread_attr_setschedparam(&ta, &sp); if (ret != 0) { UNRESOLVED(ret, "Failed to set the sched param"); } ret = pthread_create(&lpth, &ta, lp_func, &ctrl); if (ret != 0) { UNRESOLVED(ret, "Failed to create enough threads"); } /* Keep going */ ret = clock_gettime(CLOCK_REALTIME, &now); if (ret != 0) { UNRESOLVED(errno, "Failed to read current time"); } timeout.tv_sec = now.tv_sec; timeout.tv_nsec = now.tv_nsec + 500000000; while (timeout.tv_nsec >= 1000000000) { timeout.tv_sec++; timeout.tv_nsec -= 1000000000; } do { if (ctrl != 0) { output("The low priority thread executed. This might be normal if you have more than %i CPU.\n", NCPU + 1); FAILED("Low priority thread executed -- the sched parameters are ignored?"); } ret = clock_gettime(CLOCK_REALTIME, &now); if (ret != 0) { UNRESOLVED(errno, "Failed to read current time"); } #if VERBOSE > 5 output("Time: %d.%09d (to: %d.%09d)\n", now.tv_sec, now.tv_nsec, timeout.tv_sec, timeout.tv_nsec); #endif } while ((now.tv_sec <= timeout.tv_sec) && (now.tv_nsec <= timeout.tv_nsec)); /* Ok the low priority thread did not execute :) */ /* tell the other high priority to terminate */ ctrl = 1; for (i=0; i 1 output("The scheduling parameter was set accordingly to the thread attribute.\n"); #endif /* We're done. */ ret = pthread_attr_destroy(&ta); if (ret != 0) { UNRESOLVED(ret, "Failed to destroy a thread attribute object"); } } /* Post the semaphore to unlock the main thread in case of a detached thread */ do { ret = sem_post(&scenarii[sc].sem); } while ((ret == -1) && (errno == EINTR)); if (ret == -1) { UNRESOLVED(errno, "Failed to post the semaphore"); } return arg; } posixtestsuite/conformance/interfaces/pthread_create/1-4.c0100644000000000000000000001566610121521263022734 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertion: * * pthread_create creates a new thread within the process * The steps are: * * -> get the thread ID and the process ID of the main thread. * -> create a new thread, get the thread & process ID. * -> check that the thread IDs are different but process IDs are the same * The test fails if the thread IDs are the same or the proces IDs are different. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /* Some routines are part of the XSI Extensions */ #ifndef WITHOUT_XOPEN #define _XOPEN_SOURCE 600 #endif /********************************************************************************************/ /****************************** standard includes *****************************************/ /********************************************************************************************/ #include #include #include #include #include #include #include #include #include #include /********************************************************************************************/ /****************************** Test framework *****************************************/ /********************************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /********************************************************************************************/ /********************************** Configuration ******************************************/ /********************************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif /********************************************************************************************/ /*********************************** Test cases *****************************************/ /********************************************************************************************/ #include "threads_scenarii.c" /* This file will define the following objects: * scenarii: array of struct __scenario type. * NSCENAR : macro giving the total # of scenarii * scenar_init(): function to call before use the scenarii array. * scenar_fini(): function to call after end of use of the scenarii array. */ /********************************************************************************************/ /*********************************** Real Test *****************************************/ /********************************************************************************************/ struct testdata { pthread_t tid; pid_t pid; sem_t * sem; }; int global; /* This value is used to check both threads share the same process memory (and not a copy) */ void * threaded (void * arg) { struct testdata * td=(struct testdata *) arg; pthread_t mytid; pid_t mypid; int ret = 0; /* Compare the process IDs */ mypid=getpid(); #if VERBOSE > 0 output(" Main pid: %i thread pid: %i\n", td->pid, mypid); #endif if (mypid != td->pid) { FAILED("New thread does not belong to the same process as its parent thread"); } /* Compare the threads IDs */ mytid = pthread_self(); #if VERBOSE > 0 /* pthread_t is a pointer with Linux/nptl. This output can be erroneous for other arcs */ output(" Main tid: %p thread tid: %p\n", td->tid, mytid); #endif if (pthread_equal(mytid, td->tid) != 0) { FAILED("The created thread has the same thread ID as its parent"); } /* Change the global value */ global++; /* Post the semaphore to unlock the main thread in case of a detached thread */ do { ret = sem_post(td->sem); } while ((ret == -1) && (errno == EINTR)); if (ret == -1) { UNRESOLVED(errno, "Failed to post the semaphore"); } return arg; } int main (int argc, char *argv[]) { int ret=0; struct testdata td; void * rval; pthread_t child; int i; output_init(); td.tid=pthread_self(); td.pid=getpid(); scenar_init(); for (i=0; i < NSCENAR; i++) { #if VERBOSE > 0 output("-----\n"); output("Starting test with scenario (%i): %s\n", i, scenarii[i].descr); #endif td.sem = &scenarii[i].sem; global = 2*i; ret = pthread_create(&child, &scenarii[i].ta, threaded, &td); switch (scenarii[i].result) { case 0: /* Operation was expected to succeed */ if (ret != 0) { UNRESOLVED(ret, "Failed to create this thread"); } break; case 1: /* Operation was expected to fail */ if (ret == 0) { UNRESOLVED(-1, "An error was expected but the thread creation succeeded"); } break; case 2: /* We did not know the expected result */ default: #if VERBOSE > 0 if (ret == 0) { output("Thread has been created successfully for this scenario\n"); } else { output("Thread creation failed with the error: %s\n", strerror(ret)); } #endif } if (ret == 0) /* The new thread is running */ { if (scenarii[i].detached == 0) { ret = pthread_join(child, &rval); if (ret != 0) { UNRESOLVED(ret, "Unable to join a thread"); } if (rval != &td) { FAILED("Could not get the thread return value. Did it execute?"); } } else { /* Just wait for the thread terminate */ do { ret = sem_wait(td.sem); } while ((ret == -1) && (errno == EINTR)); if (ret == -1) { UNRESOLVED(errno, "Failed to post the semaphore"); } } if (global != (2*i + 1)) { /* Maybe a possible issue with CPU memory-caching here? */ FAILED("The threads do not share the same process memory."); } } } scenar_fini(); #if VERBOSE > 0 output("-----\n"); output("All test data destroyed\n"); output("Test PASSED\n"); #endif PASSED; } posixtestsuite/conformance/interfaces/pthread_create/3-1.c0100644000000000000000000000553307652343741022745 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test if the attributes specified by 'attr' are modified later, the thread's * attributes shall not be affected. * The attribute that will be tested is the detached state. * * * Steps: * 1. Set a pthread_attr_t object to be PTHREAD_CREATE_JOINABLE. * 2. Create a new thread using pthread_create() and passing this attribute * object. * 3. Change the attribute object to be in a detached state rather than * joinable. * 4. Doing this should not effect the fact that the thread that was created * is joinable, and so calling the functions pthread_detach() should not fail. */ #include #include #include #include #include "posixtest.h" # define TIMEOUT 10 /* Timeout value of 10 seconds. */ # define INTHREAD 0 /* Control going to or is already for Thread */ # define INMAIN 1 /* Control going to or is already for Main */ int sem1; /* Manual semaphore */ void *a_thread_func() { /* Indicate to main() that the thread was created. */ sem1=INTHREAD; /* Wait for main to detach change the attribute object and try and detach this thread. * Wait for a timeout value of 10 seconds before timing out if the thread was not able * to be detached. */ sleep(TIMEOUT); printf("Test FAILED: Did not detach the thread, main still waiting for it to end execution.\n"); pthread_exit((void*)PTS_FAIL); return NULL; } int main() { pthread_t new_th; pthread_attr_t new_attr; int ret; /* Initializing */ sem1 = INMAIN; if(pthread_attr_init(&new_attr) != 0) { perror("Error intializing attribute object\n"); return PTS_UNRESOLVED; } /* Make the new attribute object joinable */ if(pthread_attr_setdetachstate(&new_attr, PTHREAD_CREATE_JOINABLE) != 0) { perror("Error setting the detached state of the attribute\n"); return PTS_UNRESOLVED; } /* Create a new thread and pass it the attribute object that will * make it joinable. */ if(pthread_create(&new_th, &new_attr, a_thread_func, NULL) != 0) { perror("Error creating thread\n"); return PTS_UNRESOLVED; } while(sem1==INMAIN) sleep(1); /* Now change the attribute object to be in a detached state */ if(pthread_attr_setdetachstate(&new_attr, PTHREAD_CREATE_DETACHED) != 0) { perror("Error setting the detached state of the attribute\n"); return PTS_UNRESOLVED; } /* The new thread should still be able to be detached. */ if((ret=pthread_detach(new_th)) == EINVAL) { printf("Test FAILED: pthread_detach failed on joinable thread. Return value is %d\n", ret); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_atfork/0040755000000000000000000000000010515625176022316 5ustar rootrootposixtestsuite/conformance/interfaces/pthread_atfork/2-2.c0100644000000000000000000001466410200447116022755 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertion: * * NULL can be passed as any of these handlers when no treatment is required. * The steps are: * -> Create a new thread * -> Try all NULL / non NULL combinations (7) of pthread_atfork parameters. * The test fails if the registered handlers are not executed as expected. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /******************************************************************************/ /*************************** standard includes ********************************/ /******************************************************************************/ #include #include #include #include #include #include #include #include /******************************************************************************/ /*************************** Test framework *******************************/ /******************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int * (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /******************************************************************************/ /**************************** Configuration ***********************************/ /******************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif /******************************************************************************/ /*************************** Test case ***********************************/ /******************************************************************************/ int iPrepare = 0, iParent = 0, iChild = 0; pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER; /* pthread_atfork handlers */ /* 0: NULL NULL NULL (1) 1: p1 NULL NULL (2) 2: NULL pa2 NULL (4) 3: NULL NULL c3 (8) 4: p4 pa4 NULL (16) 5: p5 NULL c5 (32) 6: NULL pa6 c6 (64) The ultimate combination is already tested in other testcase. tot: 50 84 104 */ void p1( void ) { iPrepare |= 1 << 1; } void p4( void ) { iPrepare |= 1 << 4; } void p5( void ) { iPrepare |= 1 << 5; } void pa2( void ) { iParent |= 1 << 2; } void pa4( void ) { iParent |= 1 << 4; } void pa6( void ) { iParent |= 1 << 6; } void c3( void ) { iChild |= 1 << 3; } void c5( void ) { iChild |= 1 << 5; } void c6( void ) { iChild |= 1 << 6; } /* Thread function */ void * threaded( void * arg ) { int ret, status; pid_t child, ctl; /* Wait main thread has registered the handler */ ret = pthread_mutex_lock( &mtx ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to lock mutex" ); } ret = pthread_mutex_unlock( &mtx ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to unlock mutex" ); } /* fork */ child = fork(); if ( child == ( pid_t ) - 1 ) { UNRESOLVED( errno, "Failed to fork" ); } /* child */ if ( child == ( pid_t ) 0 ) { if ( iPrepare != 50 ) { FAILED( "prepare handler were not called as expected" ); } if ( iChild != 104 ) { FAILED( "prepare handler were not called as expected" ); } /* We're done */ exit( PTS_PASS ); } if ( iPrepare != 50 ) { FAILED( "prepare handler were not called as expected" ); } if ( iParent != 84 ) { FAILED( "prepare handler were not called as expected" ); } /* Parent joins the child */ ctl = waitpid( child, &status, 0 ); if ( ctl != child ) { UNRESOLVED( errno, "Waitpid returned the wrong PID" ); } if ( ( !WIFEXITED( status ) ) || ( WEXITSTATUS( status ) != PTS_PASS ) ) { FAILED( "Child exited abnormally" ); } /* quit */ return NULL; } /* The main test function. */ int main( int argc, char * argv[] ) { int ret; pthread_t ch; /* Initialize output */ output_init(); ret = pthread_mutex_lock( &mtx ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to lock mutex" ); } ret = pthread_create( &ch, NULL, threaded, NULL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to create a thread" ); } /* Register the handlers */ ret = pthread_atfork( NULL, NULL, NULL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to register the atfork handlers(N,N,N)" ); } ret = pthread_atfork( p1, NULL, NULL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to register the atfork handlers(h,N,N)" ); } ret = pthread_atfork( NULL, pa2, NULL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to register the atfork handlers(N,h,N)" ); } ret = pthread_atfork( NULL, NULL, c3 ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to register the atfork handlers(N,N,h)" ); } ret = pthread_atfork( p4, pa4, NULL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to register the atfork handlers(h,h,N)" ); } ret = pthread_atfork( p5, NULL, c5 ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to register the atfork handlers(h,N,h)" ); } ret = pthread_atfork( NULL, pa6, c6 ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to register the atfork handlers(N,h,h)" ); } /* Let the child go on */ ret = pthread_mutex_unlock( &mtx ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to unlock mutex" ); } ret = pthread_join( ch, NULL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to join the thread" ); } /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/pthread_atfork/4-1.c0100644000000000000000000001336110200447116022747 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertion: * * When pthread_atfork is called several times, the prepare handlers are executed * in reversed order as they were registered, and child and parent handlers are * executed in the same order as they were registered. * The steps are: * -> Register some handlers for which call order is traceable. * The test fails if the registered handlers are not executed as expected. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /******************************************************************************/ /*************************** standard includes ********************************/ /******************************************************************************/ #include #include #include #include #include #include #include #include /******************************************************************************/ /*************************** Test framework *******************************/ /******************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int * (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /******************************************************************************/ /**************************** Configuration ***********************************/ /******************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif /******************************************************************************/ /*************************** Test case ***********************************/ /******************************************************************************/ pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER; int control = 0; int nerrors = 0; /* pthread_atfork handlers */ void pre3( void ) { control++; if ( control != 1 ) nerrors++; } void pre2( void ) { control++; if ( control != 2 ) nerrors++; } void pre1( void ) { control++; if ( control != 3 ) nerrors++; } void par1( void ) { control++; if ( control != 4 ) nerrors++; } void par2( void ) { control++; if ( control != 5 ) nerrors++; } void par3( void ) { control++; if ( control != 6 ) nerrors++; } void chi1( void ) { control += 2; if ( control != 5 ) nerrors++; } void chi2( void ) { control += 2; if ( control != 7 ) nerrors++; } void chi3( void ) { control += 2; if ( control != 9 ) nerrors++; } /* Thread function */ void * threaded( void * arg ) { int ret, status; pid_t child, ctl; /* Wait main thread has registered the handler */ ret = pthread_mutex_lock( &mtx ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to lock mutex" ); } ret = pthread_mutex_unlock( &mtx ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to unlock mutex" ); } /* fork */ child = fork(); if ( child == ( pid_t ) - 1 ) { UNRESOLVED( errno, "Failed to fork" ); } /* child */ if ( child == ( pid_t ) 0 ) { if ( nerrors ) { FAILED( "Errors occured in the child" ); } /* We're done */ exit( PTS_PASS ); } /* Parent joins the child */ ctl = waitpid( child, &status, 0 ); if ( ctl != child ) { UNRESOLVED( errno, "Waitpid returned the wrong PID" ); } if ( ( !WIFEXITED( status ) ) || ( WEXITSTATUS( status ) != PTS_PASS ) ) { FAILED( "Child exited abnormally" ); } if ( nerrors ) { FAILED( "Errors occured in the parent (only)" ); } /* quit */ return NULL; } /* The main test function. */ int main( int argc, char * argv[] ) { int ret; pthread_t ch; /* Initialize output */ output_init(); ret = pthread_mutex_lock( &mtx ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to lock mutex" ); } ret = pthread_create( &ch, NULL, threaded, NULL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to create a thread" ); } /* Register the handlers */ ret = pthread_atfork( pre1, par1, chi1 ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to register the atfork handlers" ); } ret = pthread_atfork( pre2, par2, chi2 ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to register the atfork handlers" ); } ret = pthread_atfork( pre3, par3, chi3 ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to register the atfork handlers" ); } /* Let the child go on */ ret = pthread_mutex_unlock( &mtx ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to unlock mutex" ); } ret = pthread_join( ch, NULL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to join the thread" ); } /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/pthread_atfork/3-1.sh0100755000000000000000000000100207674171640023147 0ustar rootroot#!/bin/sh # Copyright (c) 2002, Intel Corporation. All rights reserved. # Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com # This file is licensed under the GPL license. For the full content # of this license, see the COPYING file at the top level of this # source tree. # Test int pthread_atfork(void (*prepare) (void), void (*parent) (void), void (*child) (void)) # This is tested implicitly via assertion 1 and 2. echo "Tested implicitly via assertions 1 and 2. See output for status" exit 0 posixtestsuite/conformance/interfaces/pthread_atfork/1-1.c0100644000000000000000000000510607674171640022763 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * * int pthread_atfork(void (*prepare) (void), void (*parent) (void), void (*child) (void)) * * shall declare fork handlers to be called before and after a fork() command, in the context * of the thread that called the fork(). The 'prepare' fork handler shall be called before * fork() processing commences. The 'parent' fork handle shall be called after fork() * processing completes in the parent process. The 'child' fork shall be called after * fork() processing completes in the child process. * * STEPS: * 1. Call pthread_atfork() before a fork() call, setting all three fork handlers for * prepare, parent and child. * 2. Call fork() * 3. Verify that all three fork handlers were called * */ #include #include #include #include #include #include #include #include #include "posixtest.h" # define HANDLER_NOTCALLED 0 # define HANDLER_CALLED 1 int prep_val; int parent_val; int child_val; static void prepare_handler() { prep_val = HANDLER_CALLED; return; } static void parent_handler() { parent_val = HANDLER_CALLED; return; } static void child_handler() { child_val = HANDLER_CALLED; return; } int main () { pid_t pid; /* Initialize values */ prep_val = HANDLER_NOTCALLED; parent_val = HANDLER_NOTCALLED; child_val = HANDLER_NOTCALLED; /* Set up the fork handlers */ if(pthread_atfork(prepare_handler, parent_handler, child_handler) != 0) { printf("Error in pthread_atfork\n"); return PTS_UNRESOLVED; } /* Now call fork() */ pid = fork(); if(pid < 0) { perror("Error in fork()\n"); return PTS_UNRESOLVED; } if(pid == 0) { /* Child process */ pthread_exit(0); } else { /* Parent process */ wait(NULL); } /* Check if fork handlers were called */ if(prep_val == 1) { if(parent_val == 1) { if(parent_val == 1) { printf("Test PASSED\n"); return PTS_PASS; } else { printf("Test FAILED: child handler not called\n"); return PTS_FAIL; } } else { printf("Test FAILED: parent handler not called\n"); return PTS_FAIL; } } else { printf("Test FAILED: prepare handler not called\n"); return PTS_FAIL; } /* Should not reach here */ printf("Error: control should not reach here\n"); return PTS_UNRESOLVED; } posixtestsuite/conformance/interfaces/pthread_atfork/testfrmw.c0100644000000000000000000000407210200447116024320 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * * This file is a wrapper to use the tests from the NPTL Test & Trace Project * with either the Linux Test Project or the Open POSIX Test Suite. * The following function are defined: * void output_init() * void output_fini() * void output(char * string, ...) * * The are used to output informative text (as a printf). */ #include #include /* We use a mutex to avoid conflicts in traces */ static pthread_mutex_t m_trace = PTHREAD_MUTEX_INITIALIZER; /*****************************************************************************************/ /******************************* stdout module *****************************************/ /*****************************************************************************************/ /* The following functions will output to stdout */ #if (1) void output_init() { /* do nothing */ return; } void output( char * string, ... ) { va_list ap; char *ts="[??:??:??]"; struct tm * now; time_t nw; pthread_mutex_lock(&m_trace); nw = time(NULL); now = localtime(&nw); if (now == NULL) printf(ts); else printf("[%2.2d:%2.2d:%2.2d]", now->tm_hour, now->tm_min, now->tm_sec); va_start( ap, string); vprintf(string, ap); va_end(ap); pthread_mutex_unlock(&m_trace); } void output_fini() { /*do nothing */ return; } #endif posixtestsuite/conformance/interfaces/pthread_atfork/3-2.c0100644000000000000000000001243510200447116022750 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertion: * * If there is not enough memory to store handler adresses, * the function returns ENOMEM. * The steps are: * -> Register up to 10000 handlers. * -> In case of failure, check the error code is ENOMEM. * -> Otherwise, check the handlers are all executed.. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /******************************************************************************/ /*************************** standard includes ********************************/ /******************************************************************************/ #include #include #include #include #include #include #include #include /******************************************************************************/ /*************************** Test framework *******************************/ /******************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int * (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /******************************************************************************/ /**************************** Configuration ***********************************/ /******************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif /******************************************************************************/ /*************************** Test case ***********************************/ /******************************************************************************/ pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER; int controls[ 3 ] = {0, 0, 0}; /* pthread_atfork handlers */ void prepare( void ) { controls[ 0 ] ++; } void parent( void ) { controls[ 1 ] ++; } void child( void ) { controls[ 2 ] ++; } /* Thread function */ void * threaded( void * arg ) { int ret, status; pid_t child, ctl; /* Wait main thread has registered the handler */ ret = pthread_mutex_lock( &mtx ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to lock mutex" ); } ret = pthread_mutex_unlock( &mtx ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to unlock mutex" ); } /* fork */ child = fork(); if ( child == ( pid_t ) - 1 ) { UNRESOLVED( errno, "Failed to fork" ); } /* child */ if ( child == ( pid_t ) 0 ) { if ( controls[ 0 ] != 10000 ) { FAILED( "prepare handler skipped some rounds" ); } if ( controls[ 2 ] != 10000 ) { FAILED( "child handler skipped some rounds" ); } /* We're done */ exit( PTS_PASS ); } if ( controls[ 0 ] != 10000 ) { FAILED( "prepare handler skipped some rounds" ); } if ( controls[ 1 ] != 10000 ) { FAILED( "parent handler skipped some rounds" ); } /* Parent joins the child */ ctl = waitpid( child, &status, 0 ); if ( ctl != child ) { UNRESOLVED( errno, "Waitpid returned the wrong PID" ); } if ( ( !WIFEXITED( status ) ) || ( WEXITSTATUS( status ) != PTS_PASS ) ) { FAILED( "Child exited abnormally" ); } /* quit */ return NULL; } /* The main test function. */ int main( int argc, char * argv[] ) { int ret, i; pthread_t ch; /* Initialize output */ output_init(); ret = pthread_mutex_lock( &mtx ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to lock mutex" ); } ret = pthread_create( &ch, NULL, threaded, NULL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to create a thread" ); } /* Register the handlers */ for ( i = 0; i < 10000; i++ ) { ret = pthread_atfork( prepare, parent, child ); if ( ret == ENOMEM ) { output( "ENOMEM returned after %i iterations\n", i ); break; } if ( ret != 0 ) { UNRESOLVED( ret, "Failed to register the atfork handlers" ); } } if ( ret == 0 ) { /* Let the child go on */ ret = pthread_mutex_unlock( &mtx ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to unlock mutex" ); } ret = pthread_join( ch, NULL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to join the thread" ); } } /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/pthread_atfork/1-2.c0100644000000000000000000001344010200447116022743 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertions: * * pthread_atfork registers the 'prepare' handler to be called before fork() * processing in the context of the fork() calling thread. * * pthread_atfork registers the 'parent' handler to be called after fork() * processing in the context of the fork() calling thread in the parent process. * * pthread_atfork registers the 'child' handler to be called after fork() * processing in the context of the fork() calling thread in the child process. * The steps are: * -> Create a new thread * -> Call pthread_atfork from the main thread. * -> Child thread forks. * -> Check that the handlers have been called, and in the context of the * calling thread. * The test fails if the thread executing the handlers is not the one expected, * or if the handlers are not executed. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /******************************************************************************/ /*************************** standard includes ********************************/ /******************************************************************************/ #include #include #include #include #include #include #include #include /******************************************************************************/ /*************************** Test framework *******************************/ /******************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int * (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /******************************************************************************/ /**************************** Configuration ***********************************/ /******************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif /******************************************************************************/ /*************************** Test case ***********************************/ /******************************************************************************/ pthread_t threads[ 3 ]; pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER; pthread_t ch; /* at fork handlers */ void prepare( void ) { threads[ 0 ] = pthread_self(); } void parent( void ) { threads[ 1 ] = pthread_self(); } void child( void ) { threads[ 2 ] = pthread_self(); } /* Thread function */ void * threaded( void * arg ) { int ret, status; pid_t child, ctl; /* Wait main thread has registered the handler */ ret = pthread_mutex_lock( &mtx ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to lock mutex" ); } ret = pthread_mutex_unlock( &mtx ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to unlock mutex" ); } /* fork */ child = fork(); if ( child == ( pid_t ) - 1 ) { UNRESOLVED( errno, "Failed to fork" ); } /* child */ if ( child == ( pid_t ) 0 ) { if ( !pthread_equal( ch, threads[ 0 ] ) ) { FAILED( "prepare handler was not called in the thread s context" ); } if ( !pthread_equal( pthread_self(), threads[ 2 ] ) ) { FAILED( "child handler was not called in the thread s context" ); } /* We're done */ exit( PTS_PASS ); } if ( !pthread_equal( ch, threads[ 0 ] ) ) { FAILED( "prepare handler was not called in the thread s context" ); } if ( !pthread_equal( pthread_self(), threads[ 1 ] ) ) { FAILED( "parent handler was not called in the thread s context" ); } /* Parent joins the child */ ctl = waitpid( child, &status, 0 ); if ( ctl != child ) { UNRESOLVED( errno, "Waitpid returned the wrong PID" ); } if ( ( !WIFEXITED( status ) ) || ( WEXITSTATUS( status ) != PTS_PASS ) ) { FAILED( "Child exited abnormally" ); } /* quit */ return NULL; } /* The main test function. */ int main( int argc, char * argv[] ) { int ret; /* Initialize output */ output_init(); ret = pthread_mutex_lock( &mtx ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to lock mutex" ); } ret = pthread_create( &ch, NULL, threaded, NULL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to create a thread" ); } /* Register the handlers */ ret = pthread_atfork( prepare, parent, child ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to register the atfork handlers" ); } /* Let the child go on */ ret = pthread_mutex_unlock( &mtx ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to unlock mutex" ); } ret = pthread_join( ch, NULL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to join the thread" ); } /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/pthread_atfork/assertions.xml0100644000000000000000000000263710173430770025231 0ustar rootroot The function int pthread_atfork(void (*prepare) (void), void (*parent) (void), void (*child) (void)) shall declare fork handlers to be called before and after a fork() command, in the context of the thread that called the fork(). The 'prepare' fork handler shall be called before fork() processing commences. The 'parent' fork handle shall be called after fork() processing completes in the parent process. The 'child' fork shall be called after fork() processing completes in the child process. If no handling is desired at one or more of these three points, the corresponding fork handler address(es) may be set to NULL. Upon successful completion, pthread_atfork() shall return a value of zero; otherwise an error number shall be returned to indicate the error: [ENOMEM] - insufficient table space exists to record the fork handler addresses. The function shall not return an error code of [EINTR] When pthread_atfork is called several times, the prepare handlers are executed in reversed order as they were registered, and child and parent handlers are executed in the same order as they were registered. posixtestsuite/conformance/interfaces/pthread_atfork/coverage.txt0100644000000000000000000000022307674171640024650 0ustar rootrootThis document defines the coverage for the pthread_atfork() function: Assertion Tested? 1 YES 2 YES 3 YES - *Note: will not test ENOMEM NOTE: posixtestsuite/conformance/interfaces/pthread_atfork/testfrmw.h0100644000000000000000000000456410200447116024333 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * * This file is a wrapper to use the tests from the NPTL Test & Trace Project * with either the Linux Test Project or the Open POSIX Test Suite. * The following macros are defined here: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate without calling one of those macros. * * */ #include "posixtest.h" #include /* for the strerror() routine */ #ifdef __GNUC__ /* We are using GCC */ #define UNRESOLVED(x, s) \ { output("Test %s unresolved: got %i (%s) on line %i (%s)\n", __FILE__, x, strerror(x), __LINE__, s); \ output_fini(); \ exit(PTS_UNRESOLVED); } #define FAILED(s) \ { output("Test %s FAILED: %s\n", __FILE__, s); \ output_fini(); \ exit(PTS_FAIL); } #define PASSED \ output_fini(); \ exit(PTS_PASS); #define UNTESTED(s) \ { output("File %s cannot test: %s\n", __FILE__, s); \ output_fini(); \ exit(PTS_UNTESTED); \ } #else /* not using GCC */ #define UNRESOLVED(x, s) \ { output("Test unresolved: got %i (%s) on line %i (%s)\n", x, strerror(x), __LINE__, s); \ output_fini(); \ exit(PTS_UNRESOLVED); } #define FAILED(s) \ { output("Test FAILED: %s\n", s); \ output_fini(); \ exit(PTS_FAIL); } #define PASSED \ output_fini(); \ exit(PTS_PASS); #define UNTESTED(s) \ { output("Unable to test: %s\n", s); \ output_fini(); \ exit(PTS_UNTESTED); \ } #endif posixtestsuite/conformance/interfaces/pthread_atfork/3-3.c0100644000000000000000000001634610200447116022756 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertion: * * The function does not return EINTR * The steps are: * -> kill a thread which calls pthread_atfork * -> check that EINTR is never returned */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /******************************************************************************/ /*********************** standard includes ************************************/ /******************************************************************************/ #include #include #include #include #include #include #include #include #include #include /******************************************************************************/ /*********************** Test framework ***********************************/ /******************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int * (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /******************************************************************************/ /***************************** Configuration **********************************/ /******************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif #define WITH_SYNCHRO /******************************************************************************/ /***************************** Test case *********************************/ /******************************************************************************/ char do_it = 1; unsigned long count_ope = 0; #ifdef WITH_SYNCHRO sem_t semsig1; sem_t semsig2; unsigned long count_sig = 0; #endif sigset_t usersigs; typedef struct { int sig; #ifdef WITH_SYNCHRO sem_t *sem; #endif } thestruct; /* the following function keeps on sending the signal to the process */ void * sendsig ( void * arg ) { thestruct * thearg = ( thestruct * ) arg; int ret; pid_t process; process = getpid(); /* We block the signals SIGUSR1 and SIGUSR2 for this THREAD */ ret = pthread_sigmask( SIG_BLOCK, &usersigs, NULL ); if ( ret != 0 ) { UNRESOLVED( ret, "Unable to block SIGUSR1 and SIGUSR2 in signal thread" ); } while ( do_it ) { #ifdef WITH_SYNCHRO if ( ( ret = sem_wait( thearg->sem ) ) ) { UNRESOLVED( errno, "Sem_wait in sendsig" ); } count_sig++; #endif ret = kill( process, thearg->sig ); if ( ret != 0 ) { UNRESOLVED( errno, "Kill in sendsig" ); } } return NULL; } /* Next are the signal handlers. */ /* This one is registered for signal SIGUSR1 */ void sighdl1( int sig ) { #ifdef WITH_SYNCHRO if ( sem_post( &semsig1 ) ) { UNRESOLVED( errno, "Sem_post in signal handler 1" ); } #endif } /* This one is registered for signal SIGUSR2 */ void sighdl2( int sig ) { #ifdef WITH_SYNCHRO if ( sem_post( &semsig2 ) ) { UNRESOLVED( errno, "Sem_post in signal handler 2" ); } #endif } void prepare( void ) { return ; } void parent( void ) { return ; } void child( void ) { return ; } /* Test function -- calls pthread_setschedparam() and checks that EINTR is never returned. */ void * test( void * arg ) { int ret = 0; /* We don't block the signals SIGUSR1 and SIGUSR2 for this THREAD */ ret = pthread_sigmask( SIG_UNBLOCK, &usersigs, NULL ); if ( ret != 0 ) { UNRESOLVED( ret, "Unable to unblock SIGUSR1 and SIGUSR2 in worker thread" ); } while ( do_it ) { count_ope++; ret = pthread_atfork( prepare, parent, child ); if ( ret == EINTR ) { FAILED( "EINTR was returned" ); } } return NULL; } /* Main function */ int main ( int argc, char * argv[] ) { int ret; pthread_t th_work, th_sig1, th_sig2, me; thestruct arg1, arg2; struct sigaction sa; /* Initialize output routine */ output_init(); /* We need to register the signal handlers for the PROCESS */ sigemptyset ( &sa.sa_mask ); sa.sa_flags = 0; sa.sa_handler = sighdl1; if ( ( ret = sigaction ( SIGUSR1, &sa, NULL ) ) ) { UNRESOLVED( ret, "Unable to register signal handler1" ); } sa.sa_handler = sighdl2; if ( ( ret = sigaction ( SIGUSR2, &sa, NULL ) ) ) { UNRESOLVED( ret, "Unable to register signal handler2" ); } /* We prepare a signal set which includes SIGUSR1 and SIGUSR2 */ sigemptyset( &usersigs ); ret = sigaddset( &usersigs, SIGUSR1 ); ret |= sigaddset( &usersigs, SIGUSR2 ); if ( ret != 0 ) { UNRESOLVED( ret, "Unable to add SIGUSR1 or 2 to a signal set" ); } /* We now block the signals SIGUSR1 and SIGUSR2 for this THREAD */ ret = pthread_sigmask( SIG_BLOCK, &usersigs, NULL ); if ( ret != 0 ) { UNRESOLVED( ret, "Unable to block SIGUSR1 and SIGUSR2 in main thread" ); } #ifdef WITH_SYNCHRO if ( sem_init( &semsig1, 0, 1 ) ) { UNRESOLVED( errno, "Semsig1 init" ); } if ( sem_init( &semsig2, 0, 1 ) ) { UNRESOLVED( errno, "Semsig2 init" ); } #endif me = pthread_self(); if ( ( ret = pthread_create( &th_work, NULL, test, &me ) ) ) { UNRESOLVED( ret, "Worker thread creation failed" ); } arg1.sig = SIGUSR1; arg2.sig = SIGUSR2; #ifdef WITH_SYNCHRO arg1.sem = &semsig1; arg2.sem = &semsig2; #endif if ( ( ret = pthread_create( &th_sig1, NULL, sendsig, ( void * ) & arg1 ) ) ) { UNRESOLVED( ret, "Signal 1 sender thread creation failed" ); } if ( ( ret = pthread_create( &th_sig2, NULL, sendsig, ( void * ) & arg2 ) ) ) { UNRESOLVED( ret, "Signal 2 sender thread creation failed" ); } /* Let's wait for a while now */ sleep( 1 ); /* Now stop the threads and join them */ do { do_it = 0; } while ( do_it ); if ( ( ret = pthread_join( th_sig1, NULL ) ) ) { UNRESOLVED( ret, "Signal 1 sender thread join failed" ); } if ( ( ret = pthread_join( th_sig2, NULL ) ) ) { UNRESOLVED( ret, "Signal 2 sender thread join failed" ); } if ( ( ret = pthread_join( th_work, NULL ) ) ) { UNRESOLVED( ret, "Worker thread join failed" ); } #if VERBOSE > 0 output( "Test executed successfully.\n" ); output( " %d operations.\n", count_ope ); #ifdef WITH_SYNCHRO output( " %d signals were sent meanwhile.\n", count_sig ); #endif #endif PASSED; } posixtestsuite/conformance/interfaces/pthread_atfork/2-1.c0100644000000000000000000000270407674171640022765 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * * int pthread_atfork(void (*prepare) (void), void (*parent) (void), void (*child) (void)) * * If no handling is desired at one or more of these three points, the corresponding fork * handler address(es) may be set to NULL. * * STEPS: * 1. Call pthread_atfork() with all NULL paramters * 2. Check to make sure the function returns success * */ #include #include #include #include #include #include #include #include #include "posixtest.h" int main () { pid_t pid; int ret; /* Set up the fork handlers */ ret = pthread_atfork(NULL, NULL, NULL); if(ret != 0) { if(ret == ENOMEM) { printf("Error: ran out of memory\n"); return PTS_UNRESOLVED; } printf("Test FAILED: Expected return value success, instead received %d\n", ret); return PTS_FAIL; } /* Now call fork() to make sure everything goes smoothly */ pid = fork(); if(pid < 0) { perror("Error in fork()\n"); return PTS_UNRESOLVED; } if(pid == 0) { /* Child process */ pthread_exit(0); } else { /* Parent process */ wait(NULL); } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_mutexattr_getpshared/0040755000000000000000000000000010515625221025262 5ustar rootrootposixtestsuite/conformance/interfaces/pthread_mutexattr_getpshared/1-3.c0100644000000000000000000000345207640455317025743 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: bing.wei.liu REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_mutexattr_getpshared() * * It shall obtain the value of the process-shared attribute from 'attr'. * * Steps: * 1. Initialize a pthread_mutexattr_t object with pthread_mutexattr_init() * 2. Set 'pshared' of the object to PTHREAD_PROCESS_PRIVATE. * 3. Call pthread_mutexattr_getpshared() to check if the process-shared * attribute is set as PTHREAD_PROCESS_PRIVATE. * */ #include #include #include #include "posixtest.h" int main() { /* Make sure there is process-shared capability. */ #ifndef PTHREAD_PROCESS_SHARED fprintf(stderr,"process-shared attribute is not available for testing\n"); return PTS_UNRESOLVED; #endif pthread_mutexattr_t mta; int ret; int pshared; /* Initialize a mutex attributes object */ if(pthread_mutexattr_init(&mta) != 0) { perror("Error at pthread_mutexattr_init()\n"); return PTS_UNRESOLVED; } /* Set 'pshared' to PTHREAD_PROCESS_PRIVATE. */ ret=pthread_mutexattr_setpshared(&mta, PTHREAD_PROCESS_PRIVATE); if(ret != 0) { printf("Error in pthread_mutexattr_setpshared(), error: %d\n", ret); return PTS_UNRESOLVED; } /* Get 'pshared'. It should be PTHREAD_PROCESS_PRIVATE. */ if(pthread_mutexattr_getpshared(&mta, &pshared) != 0) { fprintf(stderr,"Error obtaining the attribute process-shared\n"); return PTS_UNRESOLVED; } if(pshared != PTHREAD_PROCESS_PRIVATE) { printf("Test FAILED: Incorrect pshared value: %d\n", pshared); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_mutexattr_getpshared/1-1.c0100644000000000000000000000301607640455317025735 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: bing.wei.liu REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_mutexattr_getpshared() * * It shall obtain the value of the process-shared attribute from 'attr'. * * Steps: * 1. Initialize a pthread_mutexattr_t object with pthread_mutexattr_init() * 2. Call pthread_mutexattr_getpshared() to check if the process-shared * attribute is set as the default value PTHREAD_PROCESS_PRIVATE. * */ #include #include #include "posixtest.h" int main() { /* Make sure there is process-shared capability. */ #ifndef PTHREAD_PROCESS_SHARED fprintf(stderr,"process-shared attribute is not available for testing\n"); return PTS_UNRESOLVED; #endif pthread_mutexattr_t mta; int pshared; /* Initialize a mutex attributes object */ if(pthread_mutexattr_init(&mta) != 0) { perror("Error at pthread_mutexattr_init()\n"); return PTS_UNRESOLVED; } /* The default 'pshared' attribute should be PTHREAD_PROCESS_PRIVATE */ if(pthread_mutexattr_getpshared(&mta, &pshared) != 0) { fprintf(stderr,"Error obtaining the attribute process-shared\n"); return PTS_UNRESOLVED; } if(pshared != PTHREAD_PROCESS_PRIVATE) { printf("Test FAILED: Incorrect default pshared value: %d\n", pshared); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_mutexattr_getpshared/1-2.c0100644000000000000000000000337407640455317025745 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: bing.wei.liu REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_mutexattr_getpshared() * * It shall obtain the value of the process-shared attribute from 'attr'. * * Steps: * 1. Initialize a pthread_mutexattr_t object with pthread_mutexattr_init() * 2. Set 'pshared' of the object to PTHREAD_PROCESS_SHARED. * 3. Call pthread_mutexattr_getpshared() to check if the process-shared * attribute is set as PTHREAD_PROCESS_SHARED. * */ #include #include #include #include "posixtest.h" int main() { /* Make sure there is process-shared capability. */ #ifndef PTHREAD_PROCESS_SHARED fprintf(stderr,"process-shared attribute is not available for testing\n"); return PTS_UNRESOLVED; #endif pthread_mutexattr_t mta; int ret; int pshared; /* Initialize a mutex attributes object */ if(pthread_mutexattr_init(&mta) != 0) { perror("Error at pthread_mutexattr_init()\n"); return PTS_UNRESOLVED; } /* Set 'pshared' to PTHREAD_PROCESS_SHARED. */ ret=pthread_mutexattr_setpshared(&mta, PTHREAD_PROCESS_SHARED); if(ret != 0) { printf("Error in pthread_mutexattr_setpshared(), error: %d\n", ret); return PTS_UNRESOLVED; } /* Get 'pshared'. */ if(pthread_mutexattr_getpshared(&mta, &pshared) != 0) { fprintf(stderr,"Error obtaining the attribute process-shared\n"); return PTS_UNRESOLVED; } if(pshared != PTHREAD_PROCESS_SHARED) { printf("Test FAILED: Incorrect pshared value: %d\n", pshared); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_mutexattr_getpshared/assertions.xml0100644000000000000000000000110007633513320030166 0ustar rootroot The function int pthread_mutexattr_getpshared(const pthread_mutexattr_t *restrict attr, int *restrict pshared); It shall obtain the value of the process-shared attribute from 'attr'. Upon success, it returns 0, and stores the value of the process-shared attribute of 'attr' into 'pshared'. It MAY fail if: [EINVAL] - 'attr' is invalid. posixtestsuite/conformance/interfaces/pthread_mutexattr_getpshared/coverage.txt0100644000000000000000000000020107634221533027612 0ustar rootrootThis document defines the coverage for the pthread_mutexattr_getpshared function: Assertion Tested? 1 YES 2 YES 3 YES NOTE: posixtestsuite/conformance/interfaces/pthread_mutexattr_getpshared/2-1.sh0100755000000000000000000000113307634221533026121 0ustar rootroot#!/bin/sh # Copyright (c) 2002, Intel Corporation. All rights reserved. # Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com # This file is licensed under the GPL license. For the full content # of this license, see the COPYING file at the top level of this # source tree. # Test pthread_mutexattr_getpshared() fails and an error number is returned if: # # Upon success, it returns 0, and stores the value of the process-shared attribute of 'attr' # into 'pshared'. # # This is tested implicitly via assertion 1. echo "Tested implicitly via assertion 1. See output for status" exit 0 posixtestsuite/conformance/interfaces/pthread_mutexattr_getpshared/3-1.c0100644000000000000000000000264607640432651025743 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: bing.wei.liu REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_mutexattr_getpshared() * * It MAY fail if: * * [EINVAL] - 'attr' is invalid. * * Steps: * 1. Pass to pthread_mutexattr_getpshared() an uninitialized and invalid 'attr' object. * 2. The error code returned may be EINVAL. * */ #include #include #include #include #include "posixtest.h" int main() { /* Make sure there is process-shared capability. */ #ifndef PTHREAD_PROCESS_SHARED fprintf(stderr,"process-shared attribute is not available for testing\n"); return PTS_UNRESOLVED; #endif pthread_mutexattr_t mta; int ret; int pshared; /* Pass the uninitialized and invalid 'attr' object.*/ memset(&mta, 0, sizeof(mta)); /* The default 'pshared' attribute should be PTHREAD_PROCESS_PRIVATE */ ret=pthread_mutexattr_getpshared(&mta, &pshared); if(ret != 0) { if(ret == EINVAL) { printf("Test PASSED\n"); return PTS_PASS; } printf("Test FAILED: Incorrect return code. Expected 0 or EINVAL, got: %d\n", ret); return PTS_FAIL; } printf("Test PASSED: NOTE*: Returned 0 on error, though standard states 'may' fail.\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_cleanup_pop/0040755000000000000000000000000010515625202023323 5ustar rootrootposixtestsuite/conformance/interfaces/pthread_cleanup_pop/1-3.c0100644000000000000000000000451507673464447024020 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * * void pthread_cleanup_pop(int execution); * * Shall remove the routine at the top of the calling thread's cancelation cleanup stack and * optionally invoke it (if execute is non-zero). * * STEPS: * 1. Create a thread * 2. The thread will push 3 cleanup handler routines, then it will call the pop function 3 * times. * 3. Verify that the cleanup handlers are popped in order. * */ #include #include #include #include #include "posixtest.h" # define CLEANUP_NOTCALLED 0 # define CLEANUP_CALLED 1 int cleanup_flag[3]; /* Array to hold the cleanup flags for the 3 cleanup handlers */ int i; /* 3 Cleanup handlers */ void a_cleanup_func1(void *flag_val) { cleanup_flag[i] = 1; i++; return; } void a_cleanup_func2(void *flag_val) { cleanup_flag[i] = 2; i++; return; } void a_cleanup_func3(void *flag_val) { cleanup_flag[i] = 3; i++; return; } /* Function that the thread executes upon its creation */ void *a_thread_func() { pthread_cleanup_push(a_cleanup_func1, NULL); pthread_cleanup_push(a_cleanup_func2, NULL); pthread_cleanup_push(a_cleanup_func3, NULL); pthread_cleanup_pop(1); pthread_cleanup_pop(1); pthread_cleanup_pop(1); pthread_exit(0); return NULL; } int main() { pthread_t new_th; /* Initializing values */ for(i = 0;i < 3;i++) cleanup_flag[i] = 0; i = 0; /* Create a new thread. */ if(pthread_create(&new_th, NULL, a_thread_func, NULL) != 0) { perror("Error creating thread\n"); return PTS_UNRESOLVED; } /* Wait for thread to end execution */ if(pthread_join(new_th, NULL) != 0) { perror("Error in pthread_join()\n"); return PTS_UNRESOLVED; } /* Verify that the cancellation handlers are popped in order, that is: * 3, 2, then 1. */ if((cleanup_flag[0] != 3) || (cleanup_flag[1] != 2) || (cleanup_flag[2] != 1)) { printf("Test FAILED: Cleanup handlers not popped in order, expected 3,2,1, but got:\n"); printf("%d, %d, %d\n", cleanup_flag[0], cleanup_flag[1], cleanup_flag[2]); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_cleanup_pop/1-1.c0100644000000000000000000000445710033204322023763 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * * void pthread_cleanup_pop(int execution); * * Shall remove the routine at the top of the calling thread's cancelation cleanup stack and * optionally invoke it (if execute is non-zero). * * STEPS: * 1. Create a thread * 2. The thread will push a cleanup handler routine, then call pthread_cleanup_pop, setting * 'execution' to a non-zero value (meaning the cleanup handler should be executed) * 3. Verify that the cleanup handler was called. * */ #include #include #include #include #include "posixtest.h" # define CLEANUP_NOTCALLED 0 # define CLEANUP_CALLED 1 # define INTHREAD 0 # define INMAIN 1 int sem1; /* Manual semaphore */ int cleanup_flag; /* Cleanup handler */ void a_cleanup_func(void *flag_val) { cleanup_flag = (long)flag_val; return; } /* Function that the thread executes upon its creation */ void *a_thread_func() { pthread_cleanup_push(a_cleanup_func, (void*) CLEANUP_CALLED); pthread_cleanup_pop(1); /* Tell main that the thread has called the pop function */ sem1 = INMAIN; /* Wait for main to say it's ok to continue (as it checks to make sure that * the cleanup handler was called */ while (sem1 == INMAIN) sleep(1); pthread_exit(0); return NULL; } int main() { pthread_t new_th; /* Initializing values */ sem1=INTHREAD; cleanup_flag = CLEANUP_NOTCALLED; /* Create a new thread. */ if(pthread_create(&new_th, NULL, a_thread_func, NULL) != 0) { perror("Error creating thread\n"); return PTS_UNRESOLVED; } /* Wait for thread to call the pthread_cleanup_pop */ while(sem1==INTHREAD) sleep(1); /* Check to verify that the cleanup handler was called */ if(cleanup_flag != CLEANUP_CALLED) { printf("Test FAILED: Cleanup handler was not called\n"); return PTS_FAIL; } /* Tell thread it can keep going now */ sem1=INTHREAD; /* Wait for thread to end execution */ if(pthread_join(new_th, NULL) != 0) { perror("Error in pthread_join()\n"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_cleanup_pop/1-2.c0100644000000000000000000000446210033204322023760 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * * void pthread_cleanup_pop(int execution); * * Shall remove the routine at the top of the calling thread's cancelation cleanup stack and * optionally invoke it (if execute is non-zero). * * STEPS: * 1. Create a thread * 2. The thread will push a cleanup handler routine, then call pthread_cleanup_pop, setting * 'execution' to a zero value (meaning the cleanup handler shouldn't be executed) * 3. Verify that the cleanup handler was not called. * */ #include #include #include #include #include "posixtest.h" # define CLEANUP_NOTCALLED 0 # define CLEANUP_CALLED 1 # define INTHREAD 0 # define INMAIN 1 int sem1; /* Manual semaphore */ int cleanup_flag; /* Cleanup handler */ void a_cleanup_func(void *flag_val) { cleanup_flag = (long)flag_val; return; } /* Function that the thread executes upon its creation */ void *a_thread_func() { pthread_cleanup_push(a_cleanup_func, (void*) CLEANUP_CALLED); pthread_cleanup_pop(0); /* Tell main that the thread has called the pop function */ sem1 = INMAIN; /* Wait for main to say it's ok to continue (as it checks to make sure that * the cleanup handler was called */ while (sem1 == INMAIN) sleep(1); pthread_exit(0); return NULL; } int main() { pthread_t new_th; /* Initializing values */ sem1=INTHREAD; cleanup_flag = CLEANUP_NOTCALLED; /* Create a new thread. */ if(pthread_create(&new_th, NULL, a_thread_func, NULL) != 0) { perror("Error creating thread\n"); return PTS_UNRESOLVED; } /* Wait for thread to call the pthread_cleanup_pop */ while(sem1==INTHREAD) sleep(1); /* Check to verify that the cleanup handler was called */ if(cleanup_flag == CLEANUP_CALLED) { printf("Test FAILED: Cleanup was incorrectly called\n"); return PTS_FAIL; } /* Tell thread it can keep going now */ sem1=INTHREAD; /* Wait for thread to end execution */ if(pthread_join(new_th, NULL) != 0) { perror("Error in pthread_join()\n"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_cleanup_pop/assertions.xml0100644000000000000000000000064007673464447026263 0ustar rootroot The function void pthread_cleanup_pop(int execute); Shall remove the routine at the top of the calling thread's cancelation cleanup stack and optionally invoke it (if execute is non-zero). It will not return a value, or an error code of [EINTR] posixtestsuite/conformance/interfaces/pthread_cleanup_pop/coverage.txt0100644000000000000000000000016207673464447025702 0ustar rootrootThis document defines the coverage for the pthread_cleanup_pop function: Assertion Tested? 1 YES 2 YES NOTE: posixtestsuite/conformance/interfaces/pthread_cleanup_pop/2-1.sh0100755000000000000000000000074707673464447024215 0ustar rootroot#!/bin/sh # Copyright (c) 2002, Intel Corporation. All rights reserved. # Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com # This file is licensed under the GPL license. For the full content # of this license, see the COPYING file at the top level of this # source tree. # Test pthread_cleanup_pop() does not return a value or an error code of [EINTR] # This is tested implicitly via assertion 1. echo "Tested implicitly via assertion 1. See output for status" exit 0 posixtestsuite/conformance/interfaces/mq_close/0040755000000000000000000000000010515625170021115 5ustar rootrootposixtestsuite/conformance/interfaces/mq_close/5-1.c0100644000000000000000000000137207631176306021572 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: geoffrey.r.gustafson REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * Since it is undefined what will happen if mqdes is used after * mq_close() is successfully called and mq_open() has not been * called again, this will not be tested. (Eventually, this could * be a speculative test) */ #include #include "posixtest.h" int main() { printf("Functionality of using mqdes after mq_close() and before\n"); printf("mq_open() will not be tested as POSIX says this is "); printf("undefined.\n"); return PTS_UNTESTED; } posixtestsuite/conformance/interfaces/mq_close/4-1.c0100644000000000000000000000315010037721254021555 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: geoffrey.r.gustafson REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* Test that a closed message queue descriptor has been disassociated from its message queue by attempting to set a notification on the descriptor and verifying that mq_notify returns -1 and sets errno to EBADF */ #include #include #include #include #include #include #include #include #include "posixtest.h" #define TEST "4-1" #define FUNCTION "mq_close" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " int main() { char qname[50]; mqd_t queue; struct sigevent se; sprintf(qname, "/" FUNCTION "_" TEST "_%d", getpid()); queue = mq_open(qname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, NULL); if (queue == (mqd_t)-1) { perror(ERROR_PREFIX "mq_open"); return PTS_UNRESOLVED; } if (mq_close(queue) == -1) { perror(ERROR_PREFIX "mq_close"); return PTS_UNRESOLVED; } se.sigev_notify = SIGEV_SIGNAL; se.sigev_signo = SIGUSR1; if (mq_notify(queue, &se) != -1) { printf("mq_notify() did not fail as expected\n"); printf("Test FAILED\n"); return PTS_FAIL; } if (errno != EBADF) { printf("errno != EBADF\n"); printf("Test FAILED\n"); return PTS_FAIL; } if (mq_unlink(qname) != 0) { perror("mq_unlink() did not return success"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/mq_close/1-1.c0100644000000000000000000000214707631174414021565 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: geoffrey.r.gustafson REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * mq_close test case that attempts to open a new message queue, * close the message queue and verify that mq_close returns 0. */ #include #include #include #include #include #include #include "posixtest.h" #define TEST "1-1" #define FUNCTION "mq_close" int main() { char qname[50]; mqd_t queue; sprintf(qname, "/" FUNCTION "_" TEST "_%d", getpid()); queue = mq_open(qname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, NULL); if (queue == (mqd_t)-1) { perror("mq_open() did not return success"); return PTS_UNRESOLVED; } if (mq_close(queue) != 0) { printf("Test FAILED\n"); return PTS_FAIL; } if (mq_unlink(qname) != 0) { perror("mq_unlink() did not return success"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/mq_close/3-2.c0100644000000000000000000000146410014346265021563 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: geoffrey.r.gustafson REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* mq_close test plan: Attempt to close a invalid descriptor and verify that returns the correct error. */ #include #include #include #include "posixtest.h" int main() { if (mq_close((mqd_t)-1) != -1) { printf("mq_close() did not return -1 on invalid descriptor\n"); printf("Test FAILED\n"); return PTS_FAIL; } if (errno != EBADF) { printf("errno != EBADF on invalid descriptor\n"); printf("Test FAILED\n"); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/mq_close/assertions.xml0100644000000000000000000000172207622016507024033 0ustar rootroot mq_close will return zero after successful completion. All notification requests that have been successfully attached to the message queue through the descriptor being closed will be removed, so another process will be able to set up notification. Calling mq_close with an invalid descriptor will result in a mq_close returning -1 and errno being set to EBADF. mq_close removes the association between the descriptor being closed and the message queue it represents. It is undefined what will happen if mqdes is used after mq_close() is successfully called and mq_open() has not been called again. posixtestsuite/conformance/interfaces/mq_close/coverage.txt0100644000000000000000000000024607631216332023451 0ustar rootrootThis document defines the coverage for the mq_close function. ASSERTION COVERED? 1 YES 2 YES 3 YES 4 YES 5 WON'T - will not cover as this is undefined behavior posixtestsuite/conformance/interfaces/mq_close/3-3.c0100644000000000000000000000171710035502455021563 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: geoffrey.r.gustafson REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* mq_close test plan: Attempt to close a invalid descriptor and verify that returns the correct error. */ /* Note: Add a new test case. Use a large number as fd. Idea from * Drepper's patch */ #include #include #include #include "posixtest.h" int main() { /* Use some arbitrary but high number for the descriptor. */ if (mq_close((mqd_t)274) != -1) { printf("mq_close() did not return -1 on invalid descriptor\n"); printf("Test FAILED\n"); return PTS_FAIL; } if (errno != EBADF) { printf("errno != EBADF on invalid descriptor\n"); printf("Test FAILED\n"); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/mq_close/2-1.c0100644000000000000000000001275210035502455021561 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: geoffrey.r.gustafson REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* mq_close test plan: 1. Create pipes to communicate with child process 2. Fork, child waits for command on pipe 3. Create and open message queue, set up notification, sends command 4. Child opens message queue and tries to set up notification, sends command 5. Parent closes the queue, sends command 6. Child tries again to set up notification (should succeed verifying that the close successfully removed notify association), sends command 7. Parent reports result */ #include #include #include #include #include #include #include #include #include "posixtest.h" #define TEST "2-1" #define FUNCTION "mq_close" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " #define PIPE_READ 0 #define PIPE_WRITE 1 int parent_process(char *qname, int read_pipe, int write_pipe, int child_pid); int child_process(char *qname, int read_pipe, int write_pipe); mqd_t open_queue(char *qname, int oflag, int mode); int send_receive(int read_pipe, int write_pipe, char send, char *reply); int main() { char qname[50]; pid_t pid; int rval; int to_parent[2]; int to_child[2]; struct sigaction sa; sprintf(qname, "/" FUNCTION "_" TEST "_%d", getpid()); rval = pipe(to_parent); if (rval == -1) { perror(ERROR_PREFIX "pipe (1)"); return PTS_UNRESOLVED; } rval = pipe(to_child); if (rval == -1) { perror(ERROR_PREFIX "pipe (2)"); return PTS_UNRESOLVED; } sa.sa_handler = SIG_IGN; sa.sa_flags = 0; sigemptyset(&sa.sa_mask); sigaction(SIGCHLD, &sa, NULL); pid = fork(); if (pid == -1) { perror(ERROR_PREFIX "fork"); return PTS_UNRESOLVED; } if (pid == 0) { // child process close(to_parent[PIPE_READ]); close(to_child[PIPE_WRITE]); return child_process(qname, to_child[PIPE_READ], to_parent[PIPE_WRITE]); } else { // parent process close(to_parent[PIPE_WRITE]); close(to_child[PIPE_READ]); return parent_process(qname, to_parent[PIPE_READ], to_child[PIPE_WRITE], pid); } return PTS_UNRESOLVED; } int parent_process(char *qname, int read_pipe, int write_pipe, int child_pid) { mqd_t queue; struct sigevent se; int rval; char reply; queue = open_queue(qname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR); if (queue == (mqd_t)-1) { return PTS_UNRESOLVED; } se.sigev_notify = SIGEV_SIGNAL; se.sigev_signo = SIGUSR1; if (mq_notify(queue, &se)) { perror(ERROR_PREFIX "mq_notify (1)"); mq_close(queue); mq_unlink(qname); return PTS_UNRESOLVED; } // send 'a' - signal child to verify it can't call notify rval = send_receive(read_pipe, write_pipe, 'a', &reply); if (rval) { mq_close(queue); mq_unlink(qname); return rval; } if (reply != 'b') { puts(ERROR_PREFIX "send_receive: " "expected a 'b'"); mq_close(queue); mq_unlink(qname); return PTS_UNRESOLVED; } // close the queue to perform test rval = mq_close(queue); mq_unlink(qname); if (rval) { perror(ERROR_PREFIX "mq_close:"); return PTS_UNRESOLVED; } // send 'c' - signal child to verify it can call notify rval = send_receive(read_pipe, write_pipe, 'c', &reply); if (rval) { return rval; } if (reply == 'd') { puts("Test PASSED"); return PTS_PASS; } else if (reply == 'e') { puts("Test FAILED"); return PTS_FAIL; } else { puts(ERROR_PREFIX "bad reply from child"); return PTS_UNRESOLVED; } } int child_process(char *qname, int read_pipe, int write_pipe) { mqd_t queue; struct sigevent se; char reply; int rval; // wait for 'a' signal from parent rval = send_receive(read_pipe, write_pipe, 0, &reply); if (rval) { return rval; } if (reply != 'a') { puts(ERROR_PREFIX "send_receive: " "expected an 'a'"); return PTS_UNRESOLVED; } // open the queue and attempt to set up notification queue = open_queue(qname, O_RDWR, 0); if (queue == (mqd_t)-1) { return PTS_UNRESOLVED; } // try notify while parent still has queue open - should fail se.sigev_notify = SIGEV_SIGNAL; if (!mq_notify(queue, &se)) { puts(ERROR_PREFIX "mq_notify (2): " "should have failed"); return PTS_UNRESOLVED; } // send 'b' - signal parent to close queue rval = send_receive(read_pipe, write_pipe, 'b', &reply); if (rval) { return rval; } if (reply != 'c') { puts(ERROR_PREFIX "send_receive: " "expected a 'c'"); return PTS_UNRESOLVED; } // try notify after parent closed queue - should succeed se.sigev_notify = SIGEV_SIGNAL; se.sigev_signo = 0; rval = mq_notify(queue, &se); // send 'd' for success and 'e' for failure send_receive(read_pipe, write_pipe, rval ? 'e':'d', NULL); return 0; } mqd_t open_queue(char *qname, int oflag, int mode) { mqd_t queue; queue = mq_open(qname, oflag, mode, NULL); if (queue == (mqd_t)-1) { perror(ERROR_PREFIX "mq_open"); } return queue; } int send_receive(int read_pipe, int write_pipe, char send, char *reply) { ssize_t bytes; if (send) { bytes = write(write_pipe, &send, 1); if (bytes == -1) { perror(ERROR_PREFIX "write (1)"); return PTS_UNRESOLVED; } } if (reply) { bytes = read(read_pipe, reply, 1); if (bytes == -1) { perror(ERROR_PREFIX "read"); return PTS_UNRESOLVED; } else if (bytes == 0) { puts(ERROR_PREFIX "read: EOF"); return PTS_UNRESOLVED; } } return 0; } posixtestsuite/conformance/interfaces/mq_close/3-1.c0100644000000000000000000000273310014345731021557 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: geoffrey.r.gustafson REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* mq_close test plan: 1. Create a new message queue 2. Close the message queue, verify success 3. Attempt to close the same descriptor again, and verify that mq_close returns EBADF */ #include #include #include #include #include #include #include #include "posixtest.h" #define TEST "3-1" #define FUNCTION "mq_close" #define ERROR_PREFIX "unexpected error: " FUNCTION " " TEST ": " int main() { char qname[50]; mqd_t queue; sprintf(qname, "/" FUNCTION "_" TEST "_%d", getpid()); queue = mq_open(qname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, NULL); if (queue == (mqd_t)-1) { perror(ERROR_PREFIX "mq_open"); return PTS_UNRESOLVED; } if (mq_close(queue) == -1) { perror(ERROR_PREFIX "mq_close"); mq_unlink(qname); return PTS_UNRESOLVED; } if (mq_unlink(qname) != 0) { perror("mq_unlink() did not return success"); return PTS_UNRESOLVED; } if (mq_close(queue) != -1) { printf("mq_close() did not return failure\n"); printf("Test FAILED\n"); return PTS_FAIL; } if (errno != EBADF) { printf("errno != EBADF\n"); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_rwlock_unlock/0040755000000000000000000000000010515625225023677 5ustar rootrootposixtestsuite/conformance/interfaces/pthread_rwlock_unlock/4-1.c0100644000000000000000000000233307671706004024346 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_rwlock_unlock(pthread_rwlock_t *rwlock) * * It 'may' fail if: * [EINVAL] rwlock doesn't refer to an intialized read-write lock * [EPERM] the current thread doesn't hold the lock on the rwlock * * Testing EINVAL in this test. * * Steps: * 1. Call pthread_rwlock_unlock with an uninitialized rwlock * 2. The test will pass even if it returns 0, but with a note stating that the standard * states it 'may' fail. * */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include "posixtest.h" int main() { static pthread_rwlock_t rwlock; int rc; rc = pthread_rwlock_unlock(&rwlock); if(rc != 0) { if(rc == EINVAL) { printf("Test PASSED\n"); return PTS_PASS; } printf("Test FAILED: Incorrect error code, expected 0 or EINVAL, got %d\n", rc); return PTS_FAIL; } printf("Test PASSED: Note*: Returned 0 instead of EINVAL, but standard specified _may_ fail.\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_rwlock_unlock/1-1.c0100644000000000000000000001225707671706004024351 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_rwlock_unlock(pthread_rwlock_t *rwlock) * * pthread_rwlock_unlock( ) function shall release a lock held on the * read-write lock object referenced by rwlock * If this function is called to release a read lock from the read-write lock object * and there are other read locks currently held on this read-write lock object, * the read-write lock object remains in the read locked state. * If this function releases the last read lock for this read-write lock object, * the read-write lock object shall be put in the unlocked state with no owners. * * Steps: * 1. Initialize a pthread_rwlock_t object 'rwlock' with pthread_rwlock_init() * 2. Main thread read lock 'rwlock' * 3. Create a child thread, the thread read lock 'rwlock', should not block * 4. Child thread unlock 'rwlock', while the main thread still hold the read lock. * 5. Child thread read lock 'rwlock' again, should succeed, then unlock again * 6. Child thread write lock 'rwlock', should block * 7. Main thread unlock the read lock, the 'rwlock' is in unlocked state * 8. Child thread should get the lock for writing. */ #define _XOPEN_SOURCE 600 #include #include #include #include #include "posixtest.h" static pthread_rwlock_t rwlock; static int thread_state; /* thread_state indicates child thread state: 1: not in child thread yet; 2: just enter child thread ; 3: after 1st read lock 4: after 2nd read lock and before write lock; 5: just before child thread exit; */ #define NOT_CREATED_THREAD 1 #define ENTERED_THREAD 2 #define PASSED_RLOCK1 3 #define PASSED_RLOCK2 4 #define EXITING_THREAD 5 static void* fn_rd(void *arg) { int rc = 0; thread_state = ENTERED_THREAD; printf("thread: attempt 1st read lock\n"); if(pthread_rwlock_rdlock(&rwlock) != 0) { printf("thread: cannot get read lock\n"); exit(PTS_UNRESOLVED); } printf("thread: acquired read lock\n"); printf("thread: unlock read lock\n"); rc = pthread_rwlock_unlock(&rwlock); if(rc != 0) { printf("Test FAILED: thread: Error at pthread_rwlock_unlock(), Error Code=%d\n", rc); exit(PTS_FAIL); } thread_state = PASSED_RLOCK1; printf("thread: attempt 2nd read lock\n"); if(pthread_rwlock_rdlock(&rwlock) != 0) { printf("thread: cannot get read lock\n"); exit(PTS_UNRESOLVED); } printf("thread: acquired read lock\n"); printf("thread: unlock read lock\n"); rc = pthread_rwlock_unlock(&rwlock); if(rc != 0) { printf("Test FAILED: thread: Error at 2nd pthread_rwlock_unlock(), Error Code=%d\n", rc); exit(PTS_FAIL); } thread_state = PASSED_RLOCK2; /* The thread should block here */ printf("thread: attempt write lock\n"); if(pthread_rwlock_wrlock(&rwlock) != 0) { printf("thread: cannot get write lock\n"); exit(PTS_UNRESOLVED); } printf("thread: acquired write lock\n"); printf("thread: unlock write lock\n"); rc = pthread_rwlock_unlock(&rwlock); if(rc != 0) { printf("Test FAILED: thread failed to release write lock, Error Code=%d\n", rc); exit(PTS_FAIL); } thread_state = EXITING_THREAD; return NULL; } int main() { int cnt = 0; int rc = 0; pthread_t rd_thread; if(pthread_rwlock_init(&rwlock, NULL) != 0) { printf("main: Error at pthread_rwlock_init()\n"); return PTS_UNRESOLVED; } printf("main: attempt read lock\n"); /* This read lock should succeed */ if(pthread_rwlock_rdlock(&rwlock) != 0) { printf("main: Error at pthread_rwlock_rdlock()\n"); return PTS_UNRESOLVED; } thread_state = NOT_CREATED_THREAD; printf("main: create thread\n"); if(pthread_create(&rd_thread, NULL, fn_rd, NULL) != 0) { printf("main: Error at pthread_create()\n"); return PTS_UNRESOLVED; } /* If the shared data is not altered by child after 3 seconds, we regard it as blocked */ cnt = 0; do{ sleep(1); }while (thread_state !=PASSED_RLOCK2 && cnt++ < 3); if(thread_state == ENTERED_THREAD) { printf("Thread should not block on first read lock\n"); exit(PTS_UNRESOLVED); } else if(thread_state == PASSED_RLOCK1) { /* child thread blocked on second read lock*/ printf("thread should not block on second read lock\n"); exit(PTS_UNRESOLVED); } else if(thread_state != PASSED_RLOCK2) { printf("Unexpected thread state: %d\n", thread_state); exit(PTS_UNRESOLVED); } /* thread_state == 4, i.e. child thread blocks on write lock */ printf("main: unlock read lock\n"); rc = pthread_rwlock_unlock(&rwlock); if(rc != 0) { printf("Test FAILED: Main cannot release read lock\n"); exit(PTS_FAIL); } cnt = 0; do{ sleep(1); }while (thread_state !=EXITING_THREAD && cnt++ < 3); if(thread_state != EXITING_THREAD) { printf("Test FAILED: thread did not get write lock even when the lock has no owner\n"); exit(PTS_FAIL); } if(pthread_join(rd_thread, NULL) != 0) { printf("Error at pthread_join()\n"); exit(PTS_UNRESOLVED); } if(pthread_rwlock_destroy(&rwlock) != 0) { printf("Error at pthread_rwlock_destroy()\n"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_rwlock_unlock/assertions.xml0100644000000000000000000000337710117555066026625 0ustar rootroot pthread_rwlock_unlock( ) function shall release a lock held on the read-write lock objectreferenced by rwlock If this function is called to release a read lock from the read-write lock object and there are other read locks currently held on this read-write lock object, the read-write lock object remains in the read locked state. If this function releases the last read lock for this read-write lock object, the read-write lock object shall be put in the unlocked state with no owners. If this function is called to release a write lock for this read-write lock object, the read-write lock object shall be put in the unlocked state. If there are threads blocked on the lock when it becomes available, the scheduling policy shall determine which thread(s) shall acquire the lock. If the Thread Execution Scheduling option is supported, when threads executing with the scheduling policies SCHED_FIFO, SCHED_RR, or SCHED_SPORADIC are waiting on the lock, they shall acquire the lock in priority order when the lock becomes available. For equal priority threads, write locks shall take precedence over read locks. If successful, the pthread_rwlock_unlock( ) function shall return zero; otherwise, an error number shall be returned to indicate the error. [EINVAL] rwlock doesn't refer to an intialized read-write lock [EPERM] the current thread doesn't hold the lock on the rwlock The pthread_rwlock_unlock( ) function shall not return an error code of [EINTR]. posixtestsuite/conformance/interfaces/pthread_rwlock_unlock/coverage.txt0100644000000000000000000000020307671706004026227 0ustar rootrootThis document defines the coverage for the pthread_rwlock_unlock() function: Assertion Tested? 1 YES 2 YES 3 YES 4 YES NOTE: posixtestsuite/conformance/interfaces/pthread_rwlock_unlock/4-2.c0100644000000000000000000000570507671706004024355 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_rwlock_unlock(pthread_rwlock_t *rwlock) * * It 'may' fail if: * [EINVAL] rwlock doesn't refer to an intialized read-write lock * [EPERM] the current thread doesn't hold the lock on the rwlock * * Testing EPERM in this test. * * * Steps: * 1. Initialize a pthread_rwlock_t object 'rwlock' with pthread_rwlock_init() * 2. Main thread read lock 'rwlock' * 3. Create a child thread, the thread should try to unlock the 'rwlock' * 4. The test will pass even if it returns 0, but with a note stating that the standard * states it 'may' fail. */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include "posixtest.h" static pthread_rwlock_t rwlock; static int rc, thread_state; /* thread_state indicates child thread state: 1: not in child thread yet; 2: just enter child thread ; 3: just before child thread exit; */ #define NOT_CREATED_THREAD 1 #define ENTERED_THREAD 2 #define EXITING_THREAD 3 static void* fn_unlk(void *arg) { thread_state = ENTERED_THREAD; printf("un_thread: unlock read lock\n"); rc = pthread_rwlock_unlock(&rwlock); thread_state = EXITING_THREAD; return NULL; } int main() { int cnt = 0; int rc = 0; pthread_t un_thread; if(pthread_rwlock_init(&rwlock, NULL) != 0) { printf("main: Error at pthread_rwlock_init()\n"); return PTS_UNRESOLVED; } printf("main: attempt read lock\n"); if(pthread_rwlock_rdlock(&rwlock) != 0) { printf("main: Error at pthread_rwlock_rdlock()\n"); return PTS_UNRESOLVED; } printf("main: acquired read lock\n"); thread_state = NOT_CREATED_THREAD; printf("main: create un_thread\n"); if(pthread_create(&un_thread, NULL, fn_unlk, NULL) != 0) { printf("main: Error at pthread_create()\n"); return PTS_UNRESOLVED; } /* Wait for child to exit */ cnt = 0; do{ sleep(1); }while (thread_state !=EXITING_THREAD && cnt++ < 3); if(thread_state != EXITING_THREAD) { printf("Unexpected thread state %d\n", thread_state); exit(PTS_UNRESOLVED); } if(pthread_join(un_thread, NULL) != 0) { printf("Error at pthread_join()\n"); exit(PTS_UNRESOLVED); } /* Cleaning up */ pthread_rwlock_unlock(&rwlock); if(pthread_rwlock_destroy(&rwlock) != 0) { printf("error at pthread_rwlock_destroy()\n"); return PTS_UNRESOLVED; } /* Test the return code of un_thread when it attempt to unlock the rwlock it didn't * own in the first place. */ if(rc != 0) { if(rc == EPERM) { printf("Test PASSED\n"); return PTS_PASS; } printf("Test FAILED: Incorrect error code, expected 0 or EPERM, got %d\n", rc); return PTS_FAIL; } printf("Test PASSED: Note*: Returned 0 instead of EPERM, but standard specified _may_ fail.\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_rwlock_unlock/2-1.c0100644000000000000000000000730407671706004024347 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_rwlock_unlock(pthread_rwlock_t *rwlock) * * pthread_rwlock_unlock( ) function shall release a lock held on the * read-write lock object referenced by rwlock * If this function is called to release a write lock for this read-write * lock object, the read-write lock object shall be put in the unlocked state. * * In the case: if a lock in an unlocked state, it can be acquired by a thread for write lock * successfully * * Steps: * 1. Initialize a pthread_rwlock_t object 'rwlock' with pthread_rwlock_init() * 2. Main thread write lock 'rwlock' * 3. Create a child thread, the thread write lock 'rwlock', should block * 4. Main thread unlock the write lock, the 'rwlock' is in unlocked state * 5. Child thread should get the lock for writing. */ #define _XOPEN_SOURCE 600 #include #include #include #include #include "posixtest.h" static pthread_rwlock_t rwlock; static int thread_state; /* thread_state indicates child thread state: 1: not in child thread yet; 2: just enter child thread ; 3: just before child thread exit; */ #define NOT_CREATED_THREAD 1 #define ENTERED_THREAD 2 #define EXITING_THREAD 3 static void* fn_wr(void *arg) { int rc = 0; thread_state = ENTERED_THREAD; printf("thread: attempt write block\n"); /* This should block */ if(pthread_rwlock_wrlock(&rwlock) != 0) { printf("thread: cannot get write lock\n"); exit(PTS_UNRESOLVED); } printf("thread: acquired write lock\n"); printf("thread: unlock write lock\n"); rc = pthread_rwlock_unlock(&rwlock); if(rc != 0) { printf("Test FAILED: thread failed to release write lock, Error Code=%d\n", rc); exit(PTS_FAIL); } thread_state = EXITING_THREAD; return NULL; } int main() { int cnt = 0; int rc = 0; pthread_t wr_thread; if(pthread_rwlock_init(&rwlock, NULL) != 0) { printf("main: Error at pthread_rwlock_init()\n"); return PTS_UNRESOLVED; } printf("main: attempt write lock\n"); /* This write lock should succeed */ if(pthread_rwlock_wrlock(&rwlock) != 0) { printf("main: Error at pthread_rwlock_wrlock()\n"); return PTS_UNRESOLVED; } thread_state = NOT_CREATED_THREAD; printf("main: create thread\n"); if(pthread_create(&wr_thread, NULL, fn_wr, NULL) != 0) { printf("main: Error at pthread_create()\n"); return PTS_UNRESOLVED; } /* If the shared data is not altered by child after 3 seconds, we regard it as blocked */ cnt = 0; do{ sleep(1); }while (thread_state != EXITING_THREAD && cnt++ < 3); if(thread_state == EXITING_THREAD) { printf("Thread should block on write lock\n"); exit(PTS_UNRESOLVED); } else if(thread_state != ENTERED_THREAD) { printf("Unexpected thread state: %d\n", thread_state); exit(PTS_UNRESOLVED); } /* thread_state == ENTERED_THREAD, i.e. thread correctly blocks on write lock */ printf("main: unlock write lock\n"); rc = pthread_rwlock_unlock(&rwlock); if(rc != 0) { printf("Test FAILED: Main cannot release write lock\n"); exit(PTS_FAIL); } cnt = 0; do{ sleep(1); }while (thread_state != EXITING_THREAD && cnt++ < 3); if(thread_state != EXITING_THREAD) { printf("Test FAILED: thread did not get write lock even when the lock has no owner\n"); exit(PTS_FAIL); } if(pthread_join(wr_thread, NULL) != 0) { printf("Error at pthread_join()\n"); exit(PTS_UNRESOLVED); } if(pthread_rwlock_destroy(&rwlock) != 0) { printf("Error at pthread_rwlock_destroy()\n"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_rwlock_unlock/3-1.c0100644000000000000000000002325110033204323024326 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * If there are threads blocked on the lock when it becomes available, * the scheduling policy shall determine which thread(s) shall acquire the lock. * If the Thread Execution Scheduling option is supported, when threads executing * with the scheduling policies SCHED_FIFO, SCHED_RR, or SCHED_SPORADIC are waiting * on the lock, they shall acquire the lock in priority order when the lock * becomes available. For equal priority threads, write locks shall take precedence * over read locks. * Steps: * We have four threads, main(also a reader), writer1, reader, writer2 * main has the highest priority, writer1 and reader has same priority, writer2 has lowest * priority. * * 1. Main thread set its shcedule policy as "SCHED_FIFO", with highest priority * the three: sched_get_priority_min()+3. * 2. Main thread write lock 'rwlock' * 3. Create a writer1 thread, with schedule policy as "SCHED_FIFO", and priority * using sched_get_priority_min()+2. The writer should block. * 4. Create reader thread, with same priority as writer1. The reader should also block. * 5. Create a writer2 thread, with priority sched_get_priority_min(). It should block * on write lock too. * 7. Main thread release the 'rwlock', make sure the threads got the lock in the order * writer1, reader, writer2. * */ /* NOTE: The test result is UNSUPPORTED if Thread Execution Scheduling option * is not supported. */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include "posixtest.h" #define TRD_POLICY SCHED_FIFO static pthread_rwlock_t rwlock; static int rd_thread_state; static int wr_thread_state_1, wr_thread_state_2; /* thread_state: 1: not in child thread yet; 2: just enter child thread ; 3: after locking 4: thread is exiting */ #define NOT_CREATED_THREAD 1 #define ENTERED_THREAD 2 #define PASSED_LOCK 3 #define EXITING_THREAD 4 static int set_priority(pthread_t pid, unsigned policy, unsigned prio) { struct sched_param sched_param; memset(&sched_param, 0, sizeof(sched_param)); sched_param.sched_priority = prio; if (pthread_setschedparam(pid, policy, &sched_param) == -1) { printf("Can't set policy to %d and prio to %d\n", policy, prio); exit(PTS_UNRESOLVED); } return 0; } static void* fn_rd(void *arg) { int rc = 0; int priority; rd_thread_state = ENTERED_THREAD; priority = (long)arg; set_priority(pthread_self(), TRD_POLICY, priority); printf("reader: attempt read lock\n"); rc = pthread_rwlock_rdlock(&rwlock); if(rc != 0) { printf("Error: rd_thread failed to get read lock, Error code:%d\n" , rc); exit(PTS_UNRESOLVED); } rd_thread_state = PASSED_LOCK; printf("reader: acquired read lock\n"); /* Wait for main to wake us up */ do{ sleep(1); }while(rd_thread_state != EXITING_THREAD); printf("reader: unlock read lock\n"); if(pthread_rwlock_unlock(&rwlock) != 0) { printf("rd_thread: Error at pthread_rwlock_unlock()\n"); exit(PTS_UNRESOLVED); } pthread_exit(0); return NULL; } static void* fn_wr_1(void *arg) { int rc = 0; int priority; wr_thread_state_1 = ENTERED_THREAD; priority = (int)(long)arg; set_priority(pthread_self(), TRD_POLICY, priority); printf("writer1: attempt write lock\n"); rc = pthread_rwlock_wrlock(&rwlock); if(rc != 0) { printf("Error: wr_thread failed to get write lock, Error code:%d\n" , rc); exit(PTS_UNRESOLVED); } wr_thread_state_1 = PASSED_LOCK; printf("writer1: acquired write lock\n"); /* Wait for main to wake us up */ do{ sleep(1); }while(wr_thread_state_1 != EXITING_THREAD); printf("writer1: unlock write lock\n"); if(pthread_rwlock_unlock(&rwlock) != 0) { printf("wr_thread: Error at pthread_rwlock_unlock()\n"); exit(PTS_UNRESOLVED); } pthread_exit(0); return NULL; } static void* fn_wr_2(void *arg) { int rc = 0; int priority; wr_thread_state_2 = ENTERED_THREAD; priority = (long)arg; set_priority(pthread_self(), TRD_POLICY, priority); printf("writer2: attempt write lock\n"); rc = pthread_rwlock_wrlock(&rwlock); if(rc != 0) { printf("Error: wr_thread failed to get write lock, Error code:%d\n" , rc); exit(PTS_UNRESOLVED); } wr_thread_state_2 = PASSED_LOCK; printf("writer2: acquired writer lock\n"); /* Wait for main to wake us up */ do{ sleep(1); }while(wr_thread_state_2 != EXITING_THREAD); printf("writer2: unlock writer lock\n"); if(pthread_rwlock_unlock(&rwlock) != 0) { printf("wr_thread: Error at pthread_rwlock_unlock()\n"); exit(PTS_UNRESOLVED); } pthread_exit(0); return NULL; } int main() { #ifndef _POSIX_THREAD_PRIORITY_SCHEDULING printf("Posix Thread Execution Scheduling not supported\n"); return PTS_UNSUPPORTED; #endif int cnt = 0; pthread_t writer1, reader, writer2; int priority; /* main thread needs to have the highest priority*/ priority = sched_get_priority_min(TRD_POLICY) + 3; set_priority(pthread_self(), TRD_POLICY, priority); if(pthread_rwlock_init(&rwlock, NULL) != 0) { printf("main: Error at pthread_rwlock_init()\n"); return PTS_UNRESOLVED; } printf("main: write lock\n"); /* We have no lock, this read lock should succeed */ if(pthread_rwlock_wrlock(&rwlock) != 0) { printf("Error: main cannot get write lock when no one owns the lock\n"); return PTS_UNRESOLVED; } /* Now create 3 threads that block on this rwlock */ wr_thread_state_1 = NOT_CREATED_THREAD; priority = sched_get_priority_min(TRD_POLICY) + 2; printf("main: create writer1, with priority: %d\n", priority); if(pthread_create(&writer1, NULL, fn_wr_1, (void*)(long)priority) != 0) { printf("main: Error creating writer1\n"); return PTS_UNRESOLVED; } /* If the shared data is not altered by child after 2 seconds, we regard it as blocked */ /* We expect the writer1 to block */ cnt = 0; do{ sleep(1); }while (wr_thread_state_1 != 3 && cnt++ < 3); if(wr_thread_state_1 == 3 ) { printf("writer1 did not block on write lock, when main owns the lock\n"); exit(PTS_UNRESOLVED); } else if(wr_thread_state_1 != 2) { printf("Unexpected writer1 state\n"); exit(PTS_UNRESOLVED); } /* Reader thread same priority as Writer1 thread */ rd_thread_state = 1; priority = sched_get_priority_min(TRD_POLICY)+2; printf("main: create reader, with priority: %d\n", priority); if(pthread_create(&reader, NULL, fn_rd, (void*)(long)priority) != 0) { printf("main: failed at creating reader\n"); return PTS_UNRESOLVED; } /* We expect the reader to block*/ cnt = 0; do{ sleep(1); }while (rd_thread_state != 3 && cnt++ < 2); if(rd_thread_state == 3 ) { printf("Test Fail: reader did not block on read lock\n"); exit(PTS_FAIL); } else if(rd_thread_state != 2) { printf("Unexpected reader state\n"); exit(PTS_UNRESOLVED); } /* Writer2 is the lowest priority thread */ wr_thread_state_2 = 1; priority = sched_get_priority_min(TRD_POLICY); printf("main: create writer2, with priority: %d\n", priority); if(pthread_create(&writer2, NULL, fn_wr_2, (void*)(long)priority) != 0) { printf("main: Error creating writer2\n"); return PTS_UNRESOLVED; } /* If the shared data is not altered by child after 3 seconds, we regard it as blocked */ /* We expect the writer2 to block */ cnt = 0; do{ sleep(1); }while (wr_thread_state_2 != 3 && cnt++ < 2); if(wr_thread_state_2 == 3) { printf("writer2 did not block on write lock, when main owns the lock\n"); exit(PTS_UNRESOLVED); } else if(wr_thread_state_2 != 2) { printf("Unexpected writer1 state\n"); exit(PTS_UNRESOLVED); } printf("main: release write lock\n"); if(pthread_rwlock_unlock(&rwlock) != 0) { printf("main: failed to release write lock\n"); exit(PTS_UNRESOLVED); } /* we expect writer1 get the lock */ cnt = 0; do{ sleep(1); }while (wr_thread_state_1 != 3 && cnt++ < 3); if(wr_thread_state_1 == 2 ) { printf("Test fail: writer did not get write lock, when main release the lock\n"); exit(PTS_FAIL); } else if(wr_thread_state_1 != 3) { printf("Unexpected writer1 state\n"); exit(PTS_UNRESOLVED); } /* Let writer1 release the lock*/ wr_thread_state_1 = 4; if(pthread_join(writer1, NULL) != 0) { printf("main: Error joining writer1\n"); exit(PTS_UNRESOLVED); } /* we expect the reader get the lock when writer1 has release the lock*/ cnt = 0; do{ sleep(1); }while (rd_thread_state !=3 && cnt++ < 3); if(rd_thread_state == 2 ) { printf("Test failed: reader did not get the lock when writer1 release the lock\n"); exit(PTS_FAIL); } else if(rd_thread_state != 3) { printf("Unexpected reader state\n"); exit(PTS_UNRESOLVED); } /* Inform reader release the lock */ rd_thread_state = 4; if(pthread_join(reader, NULL) != 0) { printf("main: Error joining reader\n"); exit(PTS_UNRESOLVED); } /* we expect writer2 get the lock */ cnt = 0; do{ sleep(1); }while (wr_thread_state_2 !=3 && cnt++ < 3); if(wr_thread_state_2 == 2 ) { printf("Test fail: writer2 still blocked on write lock, when main release the lock\n"); exit(PTS_FAIL); } else if(wr_thread_state_2 != 3) { printf("Unexpected writer2 state\n"); exit(PTS_UNRESOLVED); } wr_thread_state_2 = 4; if(pthread_join(writer2, NULL) != 0) { printf("main: Error joining writer1\n"); exit(PTS_UNRESOLVED); } if(pthread_rwlock_destroy(&rwlock) != 0) { printf("Error at pthread_rwlockattr_destroy()"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_join/0040755000000000000000000000000010515625215021761 5ustar rootrootposixtestsuite/conformance/interfaces/pthread_join/6-2.c0100644000000000000000000000343610156263340022432 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_join() * * pthread_join() SHALL fail if: * * -[ESRCH] No thread could be found corresponding to that thread ID * * pthread_join() MAY fail if: * -[EINVAL] The implementation has detected that the value specified by * 'thread' does not refer to a joinable thread. * -[EDEADLK] A deadlock was detected or the value of 'thread' specifies the * calling thread. * It shall not return an error code of [EINTR] * * Testing ESRCH * * Steps: * 1. Create a new thread. * 2. Call pthread_join() in main. This means that the thread should have ended execution. * 3. Call pthread_join() again, it should give the error code ESRCH. * */ #include #include #include #include #include "posixtest.h" /* Thread's function. */ void *a_thread_func() { pthread_exit(0); return NULL; } int main() { pthread_t new_th; int ret; /* Create a new thread. */ if(pthread_create(&new_th, NULL, a_thread_func, NULL) != 0) { perror("Error creating thread\n"); return PTS_UNRESOLVED; } /* Wait for thread to return */ ret=pthread_join(new_th, NULL); if(ret != 0) { perror("Error in pthread_join()\n"); return PTS_UNRESOLVED; } /* Now that the thread has returned, try to join it again. It should give the error * code of ESRCH. */ ret=pthread_join(new_th, NULL); if(ret != ESRCH) { printf("Test FAILED: Return code should be ESRCH, but is: %d instead.\n", ret); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_join/5-1.c0100644000000000000000000000232507632251502022426 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_join() * * Upon successful completion, it returns 0; * * Steps: * 1. Create a new thread. * 2. Join that thread to main. If the return code is not 0, or the other valid error * codes of EINVAL, ESRCH or EDEADLK, then the test fails. * */ #include #include #include #include #include "posixtest.h" /* Thread's function. */ void *a_thread_func() { pthread_exit(0); return NULL; } int main() { pthread_t new_th; int ret; /* Create a new thread. */ if(pthread_create(&new_th, NULL, a_thread_func, NULL) != 0) { perror("Error creating thread\n"); return PTS_UNRESOLVED; } /* Wait for thread to return */ ret=pthread_join(new_th, NULL); if(ret != 0) { if((ret != EINVAL) && (ret != ESRCH) && (ret != EDEADLK)) { printf("Test FAILED: Invalid return code %d.\n", ret); return PTS_FAIL; } } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_join/speculative/0040755000000000000000000000000010515625215024305 5ustar rootrootposixtestsuite/conformance/interfaces/pthread_join/speculative/6-1.c0100644000000000000000000000326710156263411024756 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_join() * * pthread_join() SHALL fail if: * * -[ESRCH] No thread could be found corresponding to that thread ID * * pthread_join() MAY fail if: * -[EINVAL] The implementation has detected that the value specified by * 'thread' does not refer to a joinable thread. * -[EDEADLK] A deadlock was detected or the value of 'thread' specifies the * calling thread. * It shall not return an error code of [EINTR] * * Testing EINVAL * * Steps: * 1. Create a new thread that is non-joinable (i.e. detached state attribute is * PTHREAD_CREATE_DETACHED. * 2. Call pthread_join() in main. It should return EINVAL. If not, the test fails. * */ #include #include #include #include #include "posixtest.h" /* Thread's function. */ void *a_thread_func() { pthread_exit(0); return NULL; } int main() { pthread_t new_th; pthread_attr_t attr; int ret; pthread_attr_init(&attr); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); /* Create a new thread. */ if(pthread_create(&new_th, &attr, a_thread_func, NULL) != 0) { perror("Error creating thread\n"); return PTS_UNRESOLVED; } /* Wait for thread to return */ ret=pthread_join(new_th, NULL); if(ret != EINVAL) { printf("Test FAILED: Return code should be EINVAL, but is: %d instead.\n", ret); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_join/4-1.c0100644000000000000000000001555610173214164022434 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertion: * * If the thread calling pthread_join is canceled, the joined thread remains joinable. * The steps are: * -> create a thread blocked on a mutex. * -> create another thread which tries and join the first thread. * -> cancel the 2nd thread. * -> unblock the semaphore then join the 1st thread * The test fails if the main thread is unable to join the 1st thread. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /********************************************************************************************/ /****************************** standard includes *****************************************/ /********************************************************************************************/ #include #include #include #include #include #include #include /********************************************************************************************/ /****************************** Test framework *****************************************/ /********************************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /********************************************************************************************/ /********************************** Configuration ******************************************/ /********************************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif /********************************************************************************************/ /*********************************** Helper *****************************************/ /********************************************************************************************/ #include "threads_scenarii.c" /* this file defines: * scenarii: array of struct __scenario type. * NSCENAR : macro giving the total # of scenarii * scenar_init(): function to call before use the scenarii array. * scenar_fini(): function to call after end of use of the scenarii array. */ /********************************************************************************************/ /*********************************** Test case *****************************************/ /********************************************************************************************/ pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER; /* 1st thread function */ void * threaded ( void * arg ) { int ret = 0; /* Try and lock the mutex, then exit */ ret = pthread_mutex_lock( &mtx ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to lock mutex" ); } ret = pthread_mutex_unlock( &mtx ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to unlock mutex" ); } return NULL; } /* Canceled thread */ void * joiner_func( void * arg ) { ( void ) pthread_join( *( pthread_t * ) arg, NULL ); FAILED( "The joiner thread was not canceled" ); /* please the compiler */ return NULL; } /* The main test function. */ int main( int argc, char *argv[] ) { int ret = 0; pthread_t child; pthread_t joiner; /* Initialize output routine */ output_init(); /* Initialize thread attribute objects */ scenar_init(); for ( sc = 0; sc < NSCENAR; sc++ ) { #if VERBOSE > 0 output( "-----\n" ); output( "Starting test with scenario (%i): %s\n", sc, scenarii[ sc ].descr ); #endif /* Lock the mutex */ ret = pthread_mutex_lock( &mtx ); if ( ret != 0 ) { UNRESOLVED( ret, "failed to lock the mutex" ); } ret = pthread_create( &child, &scenarii[ sc ].ta, threaded, NULL ); switch ( scenarii[ sc ].result ) { case 0: /* Operation was expected to succeed */ if ( ret != 0 ) { UNRESOLVED( ret, "Failed to create this thread" ); } break; case 1: /* Operation was expected to fail */ if ( ret == 0 ) { UNRESOLVED( -1, "An error was expected but the thread creation succeeded" ); } break; case 2: /* We did not know the expected result */ default: #if VERBOSE > 0 if ( ret == 0 ) { output( "Thread has been created successfully for this scenario\n" ); } else { output( "Thread creation failed with the error: %s\n", strerror( ret ) ); } #endif } if ( ret == 0 ) /* The new thread is running */ { /* Now create the joiner thread */ ret = pthread_create( &joiner, NULL, joiner_func, &child ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to create the joiner thread" ); } /* Let it enter pthread_join */ sched_yield(); /* Cancel the joiner thread */ ret = pthread_cancel( joiner ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to cancel the thread" ); } /* Join the canceled thread */ ret = pthread_join( joiner, NULL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to join the canceled thread" ); } /* Unblock the child thread */ ret = pthread_mutex_unlock( &mtx ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to unlock the mutex" ); } /* Check the first thread is still joinable */ ret = pthread_join( child, NULL ); if ( ret != 0 ) { output( "Error returned: %d\n" ); FAILED( "The thread is no more joinable" ); } } else { ret = pthread_mutex_unlock( &mtx ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to unlock the mutex" ); } } } scenar_fini(); #if VERBOSE > 0 output( "-----\n" ); output( "All test data destroyed\n" ); output( "Test PASSED\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/pthread_join/1-1.c0100644000000000000000000000324307632251502022422 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_join() * * shall suspend the execution of the calling thread until the target * 'thread' terminates, unless 'thread' has already terminated. * * Steps: * 1. Create a new thread. Have it sleep for 3 seconds. * 2. The main() thread should wait for the new thread to finish execution before exiting out. * */ #include #include #include #include "posixtest.h" int end_exec; /* Global flag indicating the the thread function has finished execution. */ /* Thread's function. */ void *a_thread_func() { int i; printf("Wait for 3 seconds for thread to finish execution:\n"); for(i=1;i<4;i++) { printf("Waited (%d) second\n", i); sleep(1); } /* Indicate that the thread has ended execution. */ end_exec=1; pthread_exit(0); return NULL; } int main() { pthread_t new_th; /* Initialize flag */ end_exec = 0; /* Create a new thread. */ if(pthread_create(&new_th, NULL, a_thread_func, NULL) != 0) { perror("Error creating thread\n"); return PTS_UNRESOLVED; } /* Wait for thread to return */ if(pthread_join(new_th, NULL) != 0) { perror("Error in pthread_join()\n"); return PTS_UNRESOLVED; } if(end_exec == 0) { printf("Test FAILED: When using pthread_join(), main() did not wait for thread to finish execution before continuing.\n"); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_join/testfrmw.c0100644000000000000000000000407210173214164023775 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * * This file is a wrapper to use the tests from the NPTL Test & Trace Project * with either the Linux Test Project or the Open POSIX Test Suite. * The following function are defined: * void output_init() * void output_fini() * void output(char * string, ...) * * The are used to output informative text (as a printf). */ #include #include /* We use a mutex to avoid conflicts in traces */ static pthread_mutex_t m_trace = PTHREAD_MUTEX_INITIALIZER; /*****************************************************************************************/ /******************************* stdout module *****************************************/ /*****************************************************************************************/ /* The following functions will output to stdout */ #if (1) void output_init() { /* do nothing */ return; } void output( char * string, ... ) { va_list ap; char *ts="[??:??:??]"; struct tm * now; time_t nw; pthread_mutex_lock(&m_trace); nw = time(NULL); now = localtime(&nw); if (now == NULL) printf(ts); else printf("[%2.2d:%2.2d:%2.2d]", now->tm_hour, now->tm_min, now->tm_sec); va_start( ap, string); vprintf(string, ap); va_end(ap); pthread_mutex_unlock(&m_trace); } void output_fini() { /*do nothing */ return; } #endif posixtestsuite/conformance/interfaces/pthread_join/threads_scenarii.c0100644000000000000000000003305710173214164025436 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This file is a helper file for the pthread_join tests * It defines the following objects: * scenarii: array of struct __scenario type. * NSCENAR : macro giving the total # of scenarii * scenar_init(): function to call before use the scenarii array. * scenar_fini(): function to call after end of use of the scenarii array. * It is derived from the file in pthread_create tests, with the detached stuff removed * */ struct __scenario { /* Object to hold the given configuration, and which will be used to create the threads */ pthread_attr_t ta; /* Scheduling parameters */ int explicitsched; /* 0 => sched policy is inherited; 1 => sched policy from the attr param */ int schedpolicy; /* 0 => default; 1=> SCHED_FIFO; 2=> SCHED_RR */ int schedparam; /* 0 => default sched param; 1 => max value for sched param; -1 => min value for sched param */ int altscope; /* 0 => default contension scope; 1 => alternative contension scope */ /* Stack parameters */ int altstack; /* 0 => system manages the stack; 1 => stack is provided */ int guard; /* 0 => default guardsize; 1=> guardsize is 0; 2=> guard is 1 page -- this setting only affect system stacks (not user's). */ int altsize; /* 0 => default stack size; 1 => stack size specified (min value) -- ignored when stack is provided */ /* Additionnal information */ char * descr; /* object description */ void * bottom; /* Stores the stack start when an alternate stack is required */ int result; /* This thread creation is expected to: 0 => succeed; 1 => fail; 2 => unknown */ } scenarii[] = #define CASE(expl,scp,spa,sco,sta,gua,ssi,desc,res) \ { \ .explicitsched=expl, \ .schedpolicy=scp, \ .schedparam=spa, \ .altscope=sco, \ .altstack=sta, \ .guard=gua, \ .altsize=ssi, \ .descr=desc, \ .bottom=NULL, \ .result=res } #define CASE_POS(expl,scp,spa,sco,sta,gua,ssi,desc) CASE(expl,scp,spa,sco,sta,gua,ssi,desc,0) #define CASE_NEG(expl,scp,spa,sco,sta,gua,ssi,desc) CASE(expl,scp,spa,sco,sta,gua,ssi,desc,1) #define CASE_UNK(expl,scp,spa,sco,sta,gua,ssi,desc) CASE(expl,scp,spa,sco,sta,gua,ssi,desc,2) /* * This array gives the different combinations of threads attributes for the testcases. * * Some combinations must be avoided. * -> Do not have a detached thread use an alternative stack; * as we don't know when the thread terminates to free the stack memory * -> ... (to be completed) * */ { /* Unary tests */ /* 0*/ CASE_POS( 0, 0, 0, 0, 0, 0, 0, "default" ) /* 1*/ , CASE_POS( 1, 0, 0, 0, 0, 0, 0, "Explicit sched" ) /* 3*/ , CASE_UNK( 0, 1, 0, 0, 0, 0, 0, "FIFO Policy" ) /* 4*/ , CASE_UNK( 0, 2, 0, 0, 0, 0, 0, "RR Policy" ) /* 5*/ , CASE_UNK( 0, 0, 1, 0, 0, 0, 0, "Max sched param" ) /* 6*/ , CASE_UNK( 0, 0, -1, 0, 0, 0, 0, "Min sched param" ) /* 7*/ , CASE_POS( 0, 0, 0, 1, 0, 0, 0, "Alternative contension scope" ) /* 8*/ , CASE_POS( 0, 0, 0, 0, 1, 0, 0, "Alternative stack" ) /* 9*/ , CASE_POS( 0, 0, 0, 0, 0, 1, 0, "No guard size" ) /*10*/ , CASE_UNK( 0, 0, 0, 0, 0, 2, 0, "1p guard size" ) /*11*/ , CASE_POS( 0, 0, 0, 0, 0, 0, 1, "Min stack size" ) /* Stack play */ , CASE_POS( 0, 0, 0, 0, 0, 1, 1, "Min stack size, no guard" ) , CASE_UNK( 0, 0, 0, 0, 0, 2, 1, "Min stack size, 1p guard" ) /* Scheduling play -- all results are unknown since it might depend on the user priviledges */ , CASE_UNK( 1, 1, 1, 0, 0, 0, 0, "Explicit FIFO max param" ) , CASE_UNK( 1, 2, 1, 0, 0, 0, 0, "Explicit RR max param" ) , CASE_UNK( 1, 1, -1, 0, 0, 0, 0, "Explicit FIFO min param" ) , CASE_UNK( 1, 2, -1, 0, 0, 0, 0, "Explicit RR min param" ) , CASE_UNK( 1, 1, 1, 1, 0, 0, 0, "Explicit FIFO max param, alt scope" ) , CASE_UNK( 1, 2, 1, 1, 0, 0, 0, "Explicit RR max param, alt scope" ) , CASE_UNK( 1, 1, -1, 1, 0, 0, 0, "Explicit FIFO min param, alt scope" ) , CASE_UNK( 1, 2, -1, 1, 0, 0, 0, "Explicit RR min param, alt scope" ) }; #define NSCENAR (sizeof(scenarii) / sizeof(scenarii[0])) /* This function will initialize every pthread_attr_t object in the scenarii array */ void scenar_init() { int ret = 0; int i; int old; long pagesize, minstacksize; long tsa, tss, tps; pagesize = sysconf( _SC_PAGESIZE ); minstacksize = sysconf( _SC_THREAD_STACK_MIN ); tsa = sysconf( _SC_THREAD_ATTR_STACKADDR ); tss = sysconf( _SC_THREAD_ATTR_STACKSIZE ); tps = sysconf( _SC_THREAD_PRIORITY_SCHEDULING ); #if VERBOSE > 0 output( "System abilities:\n" ); output( " TSA: %li\n", tsa ); output( " TSS: %li\n", tss ); output( " TPS: %li\n", tps ); output( " pagesize: %li\n", pagesize ); output( " min stack size: %li\n", minstacksize ); #endif if ( minstacksize % pagesize ) { UNTESTED( "The min stack size is not a multiple of the page size" ); } for ( i = 0; i < NSCENAR; i++ ) { #if VERBOSE > 2 output( "Initializing attribute for scenario %i: %s\n", i, scenarii[ i ].descr ); #endif ret = pthread_attr_init( &scenarii[ i ].ta ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to initialize a thread attribute object" ); } /* Sched related attributes */ if ( tps > 0 ) /* This routine is dependent on the Thread Execution Scheduling option */ { if ( scenarii[ i ].explicitsched == 1 ) ret = pthread_attr_setinheritsched( &scenarii[ i ].ta, PTHREAD_EXPLICIT_SCHED ); else ret = pthread_attr_setinheritsched( &scenarii[ i ].ta, PTHREAD_INHERIT_SCHED ); if ( ret != 0 ) { UNRESOLVED( ret, "Unable to set inheritsched attribute" ); } #if VERBOSE > 4 output( "inheritsched state was set sucessfully\n" ); #endif } #if VERBOSE > 4 else output( "TPS unsupported => inheritsched parameter untouched\n" ); #endif if ( tps > 0 ) /* This routine is dependent on the Thread Execution Scheduling option */ { if ( scenarii[ i ].schedpolicy == 1 ) { ret = pthread_attr_setschedpolicy( &scenarii[ i ].ta, SCHED_FIFO ); } if ( scenarii[ i ].schedpolicy == 2 ) { ret = pthread_attr_setschedpolicy( &scenarii[ i ].ta, SCHED_RR ); } if ( ret != 0 ) { UNRESOLVED( ret, "Unable to set the sched policy" ); } #if VERBOSE > 4 if ( scenarii[ i ].schedpolicy ) output( "Sched policy was set sucessfully\n" ); else output( "Sched policy untouched\n" ); #endif } #if VERBOSE > 4 else output( "TPS unsupported => sched policy parameter untouched\n" ); #endif if ( scenarii[ i ].schedparam != 0 ) { struct sched_param sp; ret = pthread_attr_getschedpolicy( &scenarii[ i ].ta, &old ); if ( ret != 0 ) { UNRESOLVED( ret, "Unable to get sched policy from attribute" ); } if ( scenarii[ i ].schedparam == 1 ) sp.sched_priority = sched_get_priority_max( old ); if ( scenarii[ i ].schedparam == -1 ) sp.sched_priority = sched_get_priority_min( old ); ret = pthread_attr_setschedparam( &scenarii[ i ].ta, &sp ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to set the sched param" ); } #if VERBOSE > 4 output( "Sched param was set sucessfully to %i\n", sp.sched_priority ); } else { output( "Sched param untouched\n" ); #endif } if ( tps > 0 ) /* This routine is dependent on the Thread Execution Scheduling option */ { ret = pthread_attr_getscope( &scenarii[ i ].ta, &old ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to get contension scope from thread attribute" ); } if ( scenarii[ i ].altscope != 0 ) { if ( old == PTHREAD_SCOPE_PROCESS ) old = PTHREAD_SCOPE_SYSTEM; else old = PTHREAD_SCOPE_PROCESS; ret = pthread_attr_setscope( &scenarii[ i ].ta, old ); //if (ret != 0) { UNRESOLVED(ret, "Failed to set contension scope"); } if ( ret != 0 ) { output( "WARNING: The TPS option is claimed to be supported but setscope fails\n" ); } #if VERBOSE > 4 output( "Contension scope set to %s\n", old == PTHREAD_SCOPE_PROCESS ? "PTHREAD_SCOPE_PROCESS" : "PTHREAD_SCOPE_SYSTEM" ); } else { output( "Contension scope untouched (%s)\n", old == PTHREAD_SCOPE_PROCESS ? "PTHREAD_SCOPE_PROCESS" : "PTHREAD_SCOPE_SYSTEM" ); #endif } } #if VERBOSE > 4 else output( "TPS unsupported => sched contension scope parameter untouched\n" ); #endif /* Stack related attributes */ if ( ( tss > 0 ) && ( tsa > 0 ) ) /* This routine is dependent on the Thread Stack Address Attribute and Thread Stack Size Attribute options */ { if ( scenarii[ i ].altstack != 0 ) { /* This is slightly more complicated. We need to alloc a new stack and free it upon test termination */ /* We will alloc with a simulated guardsize of 1 pagesize */ scenarii[ i ].bottom = malloc( minstacksize + pagesize ); if ( scenarii[ i ].bottom == NULL ) { UNRESOLVED( errno, "Unable to alloc enough memory for alternative stack" ); } ret = pthread_attr_setstack( &scenarii[ i ].ta, scenarii[ i ].bottom, minstacksize ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to specify alternate stack" ); } #if VERBOSE > 1 output( "Alternate stack created successfully. Bottom=%p, Size=%i\n", scenarii[ i ].bottom, minstacksize ); #endif } } #if VERBOSE > 4 else output( "TSA or TSS unsupported => No alternative stack\n" ); #endif #ifndef WITHOUT_XOPEN if ( scenarii[ i ].guard != 0 ) { if ( scenarii[ i ].guard == 1 ) ret = pthread_attr_setguardsize( &scenarii[ i ].ta, 0 ); if ( scenarii[ i ].guard == 2 ) ret = pthread_attr_setguardsize( &scenarii[ i ].ta, pagesize ); if ( ret != 0 ) { UNRESOLVED( ret, "Unable to set guard area size in thread stack" ); } #if VERBOSE > 4 output( "Guard size set to %i\n", ( scenarii[ i ].guard == 1 ) ? 1 : pagesize ); #endif } #endif if ( tss > 0 ) /* This routine is dependent on the Thread Stack Size Attribute option */ { if ( scenarii[ i ].altsize != 0 ) { ret = pthread_attr_setstacksize( &scenarii[ i ].ta, minstacksize ); if ( ret != 0 ) { UNRESOLVED( ret, "Unable to change stack size" ); } #if VERBOSE > 4 output( "Stack size set to %i (this is the min)\n", minstacksize ); #endif } } #if VERBOSE > 4 else output( "TSS unsupported => stack size unchanged\n" ); #endif } #if VERBOSE > 0 output( "All %i thread attribute objects were initialized\n\n", NSCENAR ); #endif } /* This function will free all resources consumed in the scenar_init() routine */ void scenar_fini( void ) { int ret = 0, i; for ( i = 0; i < NSCENAR; i++ ) { if ( scenarii[ i ].bottom != NULL ) free( scenarii[ i ].bottom ); ret = pthread_attr_destroy( &scenarii[ i ].ta ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to destroy a thread attribute object" ); } } } int sc = 0; /* This might be very dirty... but is much simpler */ #ifdef STD_MAIN /* We want main to be defined here */ extern void * threaded( void *arg ); /* This is the test function */ int main ( int argc, char *argv[] ) { int ret = 0; pthread_t child; /* Initialize output routine */ output_init(); /* Initialize thread attribute objects */ scenar_init(); for ( sc = 0; sc < NSCENAR; sc++ ) { #if VERBOSE > 0 output( "-----\n" ); output( "Starting test with scenario (%i): %s\n", sc, scenarii[ sc ].descr ); #endif ret = pthread_create( &child, &scenarii[ sc ].ta, threaded, NULL ); switch ( scenarii[ sc ].result ) { case 0: /* Operation was expected to succeed */ if ( ret != 0 ) { UNRESOLVED( ret, "Failed to create this thread" ); } break; case 1: /* Operation was expected to fail */ if ( ret == 0 ) { UNRESOLVED( -1, "An error was expected but the thread creation succeeded" ); } break; case 2: /* We did not know the expected result */ default: #if VERBOSE > 0 if ( ret == 0 ) { output( "Thread has been created successfully for this scenario\n" ); } else { output( "Thread creation failed with the error: %s\n", strerror( ret ) ); } #endif } if ( ret == 0 ) /* The new thread is running */ { ret = pthread_join( child, NULL ); if ( ret != 0 ) { UNRESOLVED( ret, "Unable to join a thread" ); } } } scenar_fini(); #if VERBOSE > 0 output( "-----\n" ); output( "All test data destroyed\n" ); output( "Test PASSED\n" ); #endif PASSED; } #endif posixtestsuite/conformance/interfaces/pthread_join/6-3.c0100644000000000000000000002105710173214164022431 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertion: * * The function does not return EINTR * The steps are: * -> kill a thread which calls pthread_join * -> check that EINTR is never returned */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /********************************************************************************************/ /****************************** standard includes *****************************************/ /********************************************************************************************/ #include #include #include #include #include #include #include #include #include /********************************************************************************************/ /****************************** Test framework *****************************************/ /********************************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /********************************************************************************************/ /********************************** Configuration ******************************************/ /********************************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif #define WITH_SYNCHRO /********************************************************************************************/ /*********************************** Helper *****************************************/ /********************************************************************************************/ #include "threads_scenarii.c" /* this file defines: * scenarii: array of struct __scenario type. * NSCENAR : macro giving the total # of scenarii * scenar_init(): function to call before use the scenarii array. * scenar_fini(): function to call after end of use of the scenarii array. */ /********************************************************************************************/ /*********************************** Test cases *****************************************/ /********************************************************************************************/ char do_it = 1; unsigned long count_ope = 0; #ifdef WITH_SYNCHRO sem_t semsig1; sem_t semsig2; unsigned long count_sig = 0; #endif sigset_t usersigs; typedef struct { int sig; #ifdef WITH_SYNCHRO sem_t *sem; #endif } thestruct; /* the following function keeps on sending the signal to the process */ void * sendsig ( void * arg ) { thestruct * thearg = ( thestruct * ) arg; int ret; pid_t process; process = getpid(); /* We block the signals SIGUSR1 and SIGUSR2 for this THREAD */ ret = pthread_sigmask( SIG_BLOCK, &usersigs, NULL ); if ( ret != 0 ) { UNRESOLVED( ret, "Unable to block SIGUSR1 and SIGUSR2 in signal thread" ); } while ( do_it ) { #ifdef WITH_SYNCHRO if ( ( ret = sem_wait( thearg->sem ) ) ) { UNRESOLVED( errno, "Sem_wait in sendsig" ); } count_sig++; #endif ret = kill( process, thearg->sig ); if ( ret != 0 ) { UNRESOLVED( errno, "Kill in sendsig" ); } } return NULL; } /* Next are the signal handlers. */ /* This one is registered for signal SIGUSR1 */ void sighdl1( int sig ) { #ifdef WITH_SYNCHRO if ( sem_post( &semsig1 ) ) { UNRESOLVED( errno, "Sem_post in signal handler 1" ); } #endif } /* This one is registered for signal SIGUSR2 */ void sighdl2( int sig ) { #ifdef WITH_SYNCHRO if ( sem_post( &semsig2 ) ) { UNRESOLVED( errno, "Sem_post in signal handler 2" ); } #endif } /* thread function */ void *threaded( void* arg ) { /* do nothing */ sched_yield(); return NULL; } /* Test function -- calls pthread_join() and checks that EINTR is never returned. */ void * test( void * arg ) { int ret = 0; pthread_t child; /* We don't block the signals SIGUSR1 and SIGUSR2 for this THREAD */ ret = pthread_sigmask( SIG_UNBLOCK, &usersigs, NULL ); if ( ret != 0 ) { UNRESOLVED( ret, "Unable to unblock SIGUSR1 and SIGUSR2 in worker thread" ); } while ( do_it ) { for ( sc = 0; sc < NSCENAR; sc++ ) { ret = pthread_create( &child, &scenarii[ sc ].ta, threaded, NULL ); if ( ( scenarii[ sc ].result == 0 ) && ( ret != 0 ) ) { UNRESOLVED( ret, "Failed to create this thread" ); } if ( ( scenarii[ sc ].result == 1 ) && ( ret == 0 ) ) { UNRESOLVED( -1, "An error was expected but the thread creation succeeded" ); } if ( ret == 0 ) /* The new thread is running */ { count_ope++; ret = pthread_join( child, NULL ); if ( ret == EINTR ) { FAILED( "pthread_join returned EINTR" ); } if ( ret != 0 ) { UNRESOLVED( ret, "Unable to join a thread" ); } } } } return NULL; } /* Main function */ int main ( int argc, char * argv[] ) { int ret; pthread_t th_work, th_sig1, th_sig2; thestruct arg1, arg2; struct sigaction sa; /* Initialize output routine */ output_init(); /* We need to register the signal handlers for the PROCESS */ sigemptyset ( &sa.sa_mask ); sa.sa_flags = 0; sa.sa_handler = sighdl1; if ( ( ret = sigaction ( SIGUSR1, &sa, NULL ) ) ) { UNRESOLVED( ret, "Unable to register signal handler1" ); } sa.sa_handler = sighdl2; if ( ( ret = sigaction ( SIGUSR2, &sa, NULL ) ) ) { UNRESOLVED( ret, "Unable to register signal handler2" ); } /* We prepare a signal set which includes SIGUSR1 and SIGUSR2 */ sigemptyset( &usersigs ); ret = sigaddset( &usersigs, SIGUSR1 ); ret |= sigaddset( &usersigs, SIGUSR2 ); if ( ret != 0 ) { UNRESOLVED( ret, "Unable to add SIGUSR1 or 2 to a signal set" ); } /* We now block the signals SIGUSR1 and SIGUSR2 for this THREAD */ ret = pthread_sigmask( SIG_BLOCK, &usersigs, NULL ); if ( ret != 0 ) { UNRESOLVED( ret, "Unable to block SIGUSR1 and SIGUSR2 in main thread" ); } #ifdef WITH_SYNCHRO if ( sem_init( &semsig1, 0, 1 ) ) { UNRESOLVED( errno, "Semsig1 init" ); } if ( sem_init( &semsig2, 0, 1 ) ) { UNRESOLVED( errno, "Semsig2 init" ); } #endif /* Initialize thread attribute objects */ scenar_init(); if ( ( ret = pthread_create( &th_work, NULL, test, NULL ) ) ) { UNRESOLVED( ret, "Worker thread creation failed" ); } arg1.sig = SIGUSR1; arg2.sig = SIGUSR2; #ifdef WITH_SYNCHRO arg1.sem = &semsig1; arg2.sem = &semsig2; #endif if ( ( ret = pthread_create( &th_sig1, NULL, sendsig, ( void * ) & arg1 ) ) ) { UNRESOLVED( ret, "Signal 1 sender thread creation failed" ); } if ( ( ret = pthread_create( &th_sig2, NULL, sendsig, ( void * ) & arg2 ) ) ) { UNRESOLVED( ret, "Signal 2 sender thread creation failed" ); } /* Let's wait for a while now */ sleep( 10 ); /* Now stop the threads and join them */ do { do_it = 0; } while ( do_it ); if ( ( ret = pthread_join( th_sig1, NULL ) ) ) { UNRESOLVED( ret, "Signal 1 sender thread join failed" ); } if ( ( ret = pthread_join( th_sig2, NULL ) ) ) { UNRESOLVED( ret, "Signal 2 sender thread join failed" ); } if ( ( ret = pthread_join( th_work, NULL ) ) ) { UNRESOLVED( ret, "Worker thread join failed" ); } scenar_fini(); #if VERBOSE > 0 output( "Test executed successfully.\n" ); output( " %d pthread_join calls.\n", count_ope ); #ifdef WITH_SYNCHRO output( " %d signals were sent meanwhile.\n", count_sig ); #endif #endif PASSED; } posixtestsuite/conformance/interfaces/pthread_join/1-2.c0100644000000000000000000001500410173214164022416 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertion: * * pthread_join() returns only when the joined thread has terminated. * The steps are: * -> create a thread * -> the thread yields then read clock and exit * -> check the read clock value is before pthread_join return. * The test fails if the time read is not coherent */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /********************************************************************************************/ /****************************** standard includes *****************************************/ /********************************************************************************************/ #include #include #include #include #include #include #include #include /********************************************************************************************/ /****************************** Test framework *****************************************/ /********************************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /********************************************************************************************/ /********************************** Configuration ******************************************/ /********************************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif /********************************************************************************************/ /*********************************** Helper *****************************************/ /********************************************************************************************/ #include "threads_scenarii.c" /* this file defines: * scenarii: array of struct __scenario type. * NSCENAR : macro giving the total # of scenarii * scenar_init(): function to call before use the scenarii array. * scenar_fini(): function to call after end of use of the scenarii array. */ /********************************************************************************************/ /*********************************** Test case *****************************************/ /********************************************************************************************/ /* thread function */ void * threaded ( void * arg ) { int ret = 0; int i; /* yield the control some times */ for ( i = 0; i < 10; i++ ) sched_yield(); /* Now tell we're done */ ret = clock_gettime( CLOCK_REALTIME, arg ); if ( ret != 0 ) { UNRESOLVED( errno, "Failed to get clock time" ); } return NULL; } /* The main test function. */ int main( int argc, char *argv[] ) { int ret = 0; pthread_t child; struct timespec ts_pre, ts_th, ts_post; /* Initialize output routine */ output_init(); /* Initialize thread attribute objects */ scenar_init(); for ( sc = 0; sc < NSCENAR; sc++ ) { #if VERBOSE > 0 output( "-----\n" ); output( "Starting test with scenario (%i): %s\n", sc, scenarii[ sc ].descr ); #endif ret = clock_gettime( CLOCK_REALTIME, &ts_pre ); if ( ret != 0 ) { UNRESOLVED( errno, "Failed to read clock" ); } ret = pthread_create( &child, &scenarii[ sc ].ta, threaded, &ts_th ); switch ( scenarii[ sc ].result ) { case 0: /* Operation was expected to succeed */ if ( ret != 0 ) { UNRESOLVED( ret, "Failed to create this thread" ); } break; case 1: /* Operation was expected to fail */ if ( ret == 0 ) { UNRESOLVED( -1, "An error was expected but the thread creation succeeded" ); } break; case 2: /* We did not know the expected result */ default: #if VERBOSE > 0 if ( ret == 0 ) { output( "Thread has been created successfully for this scenario\n" ); } else { output( "Thread creation failed with the error: %s\n", strerror( ret ) ); } #endif } if ( ret == 0 ) /* The new thread is running */ { ret = pthread_join( child, NULL ); if ( ret != 0 ) { UNRESOLVED( ret, "Unable to join a thread" ); } ret = clock_gettime( CLOCK_REALTIME, &ts_post ); if ( ret != 0 ) { UNRESOLVED( errno, "Failed to read clock" ); } /* Now check that ts_pre <= ts_th <= ts_post */ if ( ( ts_th.tv_sec < ts_pre.tv_sec ) || ( ( ts_th.tv_sec == ts_pre.tv_sec ) && ( ts_th.tv_nsec < ts_pre.tv_nsec ) ) ) { output( "Pre : %d.%09d\n", ts_pre.tv_sec, ts_pre.tv_nsec ); output( "child: %d.%09d\n", ts_th.tv_sec, ts_th.tv_nsec ); output( "Post : %d.%09d\n", ts_post.tv_sec, ts_post.tv_nsec ); FAILED( "Child returned before its creation ???" ); } if ( ( ts_post.tv_sec < ts_th.tv_sec ) || ( ( ts_post.tv_sec == ts_th.tv_sec ) && ( ts_post.tv_nsec < ts_th.tv_nsec ) ) ) { output( "Pre : %d.%09d\n", ts_pre.tv_sec, ts_pre.tv_nsec ); output( "child: %d.%09d\n", ts_th.tv_sec, ts_th.tv_nsec ); output( "Post : %d.%09d\n", ts_post.tv_sec, ts_post.tv_nsec ); FAILED( "pthread_join returned before child terminated" ); } } } scenar_fini(); #if VERBOSE > 0 output( "-----\n" ); output( "All test data destroyed\n" ); output( "Test PASSED\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/pthread_join/assertions.xml0100644000000000000000000000270510156263340024674 0ustar rootroot The function int pthread_join(pthread_t thread, void **value_ptr); shall suspend the execution of the calling thread until the target 'thread' terminates, unless 'thread' has already terminated. On return from a successful pthread_join() call with a non-NULL 'value_ptr' argument, the value passed to pthread_exit() by the terminating thread shall be made available in the location referenced by 'value_ptr'. When pthread_join() returns successfully, the target thread has been terminated. If the thread calling pthread_join() is canceled, then the target thread shall not be detached. Upon successful completion, it returns 0; pthread_join() SHALL fail if: -[ESRCH] No thread could be found corresponding to that thread ID pthread_join() MAY fail if: -[EINVAL] The implementation has detected that the value specified by 'thread' does not refer to a joinable thread. -[EDEADLK] A deadlock was detected or the value of 'thread' specifies the calling thread. It shall not return an error code of [EINTR] posixtestsuite/conformance/interfaces/pthread_join/coverage.txt0100644000000000000000000000047007632251502024313 0ustar rootrootThis document defines the coverage for the pthread_join function: Assertion Tested? 1 YES 2 YES 3 YES 4 NO ** Skipping for now. 5 YES 6 YES ** When it specifies 'may' fail and not 'shall' fail, it will always return PASS, but will return a PASS and print out a warning if it fails. NOTE: posixtestsuite/conformance/interfaces/pthread_join/testfrmw.h0100644000000000000000000000456410173214164024010 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * * This file is a wrapper to use the tests from the NPTL Test & Trace Project * with either the Linux Test Project or the Open POSIX Test Suite. * The following macros are defined here: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate without calling one of those macros. * * */ #include "posixtest.h" #include /* for the strerror() routine */ #ifdef __GNUC__ /* We are using GCC */ #define UNRESOLVED(x, s) \ { output("Test %s unresolved: got %i (%s) on line %i (%s)\n", __FILE__, x, strerror(x), __LINE__, s); \ output_fini(); \ exit(PTS_UNRESOLVED); } #define FAILED(s) \ { output("Test %s FAILED: %s\n", __FILE__, s); \ output_fini(); \ exit(PTS_FAIL); } #define PASSED \ output_fini(); \ exit(PTS_PASS); #define UNTESTED(s) \ { output("File %s cannot test: %s\n", __FILE__, s); \ output_fini(); \ exit(PTS_UNTESTED); \ } #else /* not using GCC */ #define UNRESOLVED(x, s) \ { output("Test unresolved: got %i (%s) on line %i (%s)\n", x, strerror(x), __LINE__, s); \ output_fini(); \ exit(PTS_UNRESOLVED); } #define FAILED(s) \ { output("Test FAILED: %s\n", s); \ output_fini(); \ exit(PTS_FAIL); } #define PASSED \ output_fini(); \ exit(PTS_PASS); #define UNTESTED(s) \ { output("Unable to test: %s\n", s); \ output_fini(); \ exit(PTS_UNTESTED); \ } #endif posixtestsuite/conformance/interfaces/pthread_join/2-1.c0100644000000000000000000000431007655471772022441 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_join() * * On return from a successful pthread_join() call with a non-NULL 'value_ptr' * argument, the avlue passed to pthread_exit() by the terminating thread shall * be made available in the location referenced by 'value_ptr'. * * Steps: * 1. Create a new thread. Have it return a return code on pthread_exit(); * 2. Call pthread_join() in main(), and pass to it 'value_ptr'. * 3. Check to see of the value_ptr and the value returned by pthread_exit() are the same; * */ #include #include #include #include "posixtest.h" #define RETURN_CODE ((void*)100) /* Set a random return code number. This shall be the return code of the thread when using pthread_exit().*/ # define INTHREAD 0 /* Control going to or is already for Thread */ # define INMAIN 1 /* Control going to or is already for Main */ int sem; /* Manual semaphore used to indicate when the thread has been created. */ /* Thread's function. */ void *a_thread_func() { sem=INMAIN; pthread_exit(RETURN_CODE); return NULL; } int main() { pthread_t new_th; void *value_ptr; /* Initializing variables. */ value_ptr=0; sem=INTHREAD; /* Create a new thread. */ if(pthread_create(&new_th, NULL, a_thread_func, NULL) != 0) { perror("Error creating thread\n"); return PTS_UNRESOLVED; } /* Make sure the thread was created before we join it. */ while(sem==INTHREAD) sleep(1); /* Wait for thread to return */ if(pthread_join(new_th, &value_ptr) != 0) { perror("Error in pthread_join()\n"); return PTS_UNRESOLVED; } /* Check to make sure that 'value_ptr' that was passed to pthread_join() and the * pthread_exit() return code that was used in the thread funciton are the same. */ if(value_ptr != RETURN_CODE) { printf("Test FAILED: pthread_join() did not return the pthread_exit value of the thread in 'value_ptr'.\n"); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_join/3-1.c0100644000000000000000000000527707632251502022435 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_join() * * When pthread_join() returns successfully, the target thread has been * terminated. * * Steps: * 1. Create a new thread. * 2. Send a cancel request to it from main, then use pthread_join to wait for it to end. * 3. The thread will sleep for 3 seconds, then call test_cancel() to cancel execution. * 4. When this happens, the cleanup handler should be called. * 5. Main will test that when pthread_join allows main to continue with the process that * the thread has ended execution. If the cleanup_handler was not called, then the * test fails. * */ #include #include #include #include "posixtest.h" #define TIMEOUT 10 /* Timeout period for cancel request is 10 seconds. */ int cleanup_flag; /* Flag to indicate the thread's cleanup handler was called */ /* Cleanup function that the thread executes when it is canceled. So if * cleanup_flag is 1, it means that the thread was canceled. */ void a_cleanup_func() { cleanup_flag=1; return; } /* Thread's function. */ void *a_thread_func() { pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL); /* Set up the cleanup handler */ pthread_cleanup_push(a_cleanup_func,NULL); /* Wait for a timeout period for the cancel request to be sent. */ /* Cancelation point. Should call cleanup handler now. . */ sleep(TIMEOUT); /* Should not get here, but just in case pthread_testcancel() didn't work. */ /* Cancel request timed out. */ pthread_cleanup_pop(0); cleanup_flag=-1; pthread_exit(0); return NULL; } int main() { pthread_t new_th; /* Initialize flag */ cleanup_flag = 0; /* Create a new thread. */ if(pthread_create(&new_th, NULL, a_thread_func, NULL) != 0) { perror("Error creating thread\n"); return PTS_UNRESOLVED; } /* Send cancel request to the thread. */ if(pthread_cancel(new_th) != 0) { perror("Couldn't cancel thread\n"); return PTS_UNRESOLVED; } /* Wait for thread to return */ if(pthread_join(new_th, NULL) != 0) { perror("Error in pthread_join()\n"); return PTS_UNRESOLVED; } if(cleanup_flag == 0) { printf("Test FAILED: Thread did not finish execution when pthread_join returned. \n"); return PTS_FAIL; } if(cleanup_flag == -1) { perror("Error in pthread_testcancel(). Cancel request timed out.\n"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/clock_nanosleep/0040755000000000000000000000000010515625162022453 5ustar rootrootposixtestsuite/conformance/interfaces/clock_nanosleep/8-1.sh0100755000000000000000000000073407571257037023332 0ustar rootroot#!/bin/sh # Copyright (c) 2002, Intel Corporation. All rights reserved. # Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com # This file is licensed under the GPL license. For the full content # of this license, see the COPYING file at the top level of this # source tree. # # Test that clock_nanosleep() returns 0 on success. # # This is tested implicitly via assertions 1 and 2. echo "Tested implicitly via assertions 1 and 2. See output for status." exit 0 posixtestsuite/conformance/interfaces/clock_nanosleep/2-2.c0100644000000000000000000000510607571206074023123 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that clock_nanosleep() causes the current thread to be suspended * until a signal whose action is to invoke a signal handling function * is received for an absolute nanosleep (same as 1-3.c with * TIMER_ABSTIME set). * * Note: This test case has some limitations: * - clock_nanosleep() could not be executed at all, and the test would * pass [Hopefully, the sleep() in the parent ensures clock_nanosleep() * will be executed.] * - There is no way of knowing for sure that it was the signal that * stopped clock_nanosleep(). */ #include #include #include #include #include #include "posixtest.h" #define SLEEPSEC 30 void handler(int signo) { printf("In handler\n"); } int main(int argc, char *argv[]) { struct timespec tssleep, tsbefore, tsafter; int pid, sleepuntilsec; struct sigaction act; if (clock_gettime(CLOCK_REALTIME, &tsbefore) != 0) { perror("clock_gettime() did not return success\n"); return PTS_UNRESOLVED; } sleepuntilsec = tsbefore.tv_sec + SLEEPSEC; if ((pid = fork()) == 0) { /* child here */ int flags = 0; act.sa_handler=handler; act.sa_flags=0; if (sigemptyset(&act.sa_mask) != 0) { perror("sigemptyset() did not return success\n"); return PTS_UNRESOLVED; } if (sigaction(SIGABRT, &act, 0) != 0) { perror("sigaction() did not return success\n"); return PTS_UNRESOLVED; } tssleep.tv_sec=sleepuntilsec; tssleep.tv_nsec=tsbefore.tv_nsec; flags |= TIMER_ABSTIME; clock_nanosleep(CLOCK_REALTIME, flags, &tssleep, NULL); } else { /* parent here */ int i; sleep(1); if (kill(pid, SIGABRT) != 0) { printf("Could not raise signal being tested\n"); return PTS_UNRESOLVED; } if (wait(&i) == -1) { perror("Error waiting for child to exit\n"); return PTS_UNRESOLVED; } if (clock_gettime(CLOCK_REALTIME, &tsafter) != 0) { perror("clock_gettime() did not return success\n"); return PTS_UNRESOLVED; } /* * pass if we slept for less than the (large) sleep time * allotted */ if ( tsafter.tv_sec < sleepuntilsec) { printf("Test PASSED\n"); return PTS_PASS; } else { printf("Slept for too long: %d >= %d\n", (int) tsafter.tv_sec, sleepuntilsec); printf("Test FAILED\n"); return PTS_FAIL; } } return PTS_UNRESOLVED; } posixtestsuite/conformance/interfaces/clock_nanosleep/1-5.c0100644000000000000000000000440107640673267023133 0ustar rootroot/* * Copyright (c) 2002-3, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that clock_nanosleep() does not stop if a signal is received * that has no signal handler. clock_nanosleep() should still respond * to the signal, but should resume after a SIGCONT signal is received. * * SIGSTOP will be used to stop the sleep. */ #include #include #include #include #include #include #include "posixtest.h" #define SLEEPSEC 5 #define CHILDPASS 1 #define CHILDFAIL 0 int main(int argc, char *argv[]) { int pid, slepts; struct timespec tsbefore, tsafter; if (clock_gettime(CLOCK_REALTIME, &tsbefore) != 0) { perror("clock_gettime() did not return success\n"); return PTS_UNRESOLVED; } if ((pid = fork()) == 0) { /* child here */ struct timespec tssleep; tssleep.tv_sec=SLEEPSEC; tssleep.tv_nsec=0; if (clock_nanosleep(CLOCK_REALTIME, 0, &tssleep, NULL) == 0) { printf("clock_nanosleep() returned success\n"); return CHILDPASS; } else { printf("clock_nanosleep() did not return success\n"); return CHILDFAIL; } return CHILDFAIL; } else { /* parent here */ int i; sleep(1); if (kill(pid, SIGSTOP) != 0) { printf("Could not raise SIGSTOP\n"); return PTS_UNRESOLVED; } if (kill(pid, SIGCONT) != 0) { printf("Could not raise SIGCONT\n"); return PTS_UNRESOLVED; } if (wait(&i) == -1) { perror("Error waiting for child to exit\n"); return PTS_UNRESOLVED; } if (!WIFEXITED(i) || !WEXITSTATUS(i)) { printf("Test FAILED\n"); return PTS_FAIL; } if (clock_gettime(CLOCK_REALTIME, &tsafter) == -1) { perror("Error in clock_gettime()\n"); return PTS_UNRESOLVED; } slepts=tsafter.tv_sec-tsbefore.tv_sec; #ifdef DEBUG printf("Start %d sec; End %d sec\n", (int) tsbefore.tv_sec, (int) tsafter.tv_sec); #endif if (slepts >= SLEEPSEC) { printf("Test PASSED\n"); return PTS_PASS; } else { printf("clock_nanosleep() did not sleep long enough\n"); return PTS_FAIL; } } //end fork return PTS_UNRESOLVED; } posixtestsuite/conformance/interfaces/clock_nanosleep/1-3.c0100644000000000000000000000463007571204344023122 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that clock_nanosleep() causes the current thread to be suspended * until a signal whose action is to invoke a signal handling function * is received. * * Note: This test case has some limitations: * - clock_nanosleep() could not be executed at all, and the test would * pass [Hopefully, the sleep() in the parent ensures clock_nanosleep() * will be executed.] * - There is no way of knowing for sure that it was the signal that * stopped clock_nanosleep(). */ #include #include #include #include #include #include "posixtest.h" #define SLEEPSEC 30 void handler(int signo) { printf("In handler\n"); } int main(int argc, char *argv[]) { struct timespec tssleep, tsbefore, tsafter; int pid; struct sigaction act; if (clock_gettime(CLOCK_REALTIME, &tsbefore) != 0) { perror("clock_gettime() did not return success\n"); return PTS_UNRESOLVED; } if ((pid = fork()) == 0) { /* child here */ act.sa_handler=handler; act.sa_flags=0; if (sigemptyset(&act.sa_mask) != 0) { perror("sigemptyset() did not return success\n"); return PTS_UNRESOLVED; } if (sigaction(SIGABRT, &act, 0) != 0) { perror("sigaction() did not return success\n"); return PTS_UNRESOLVED; } tssleep.tv_sec=SLEEPSEC; tssleep.tv_nsec=0; clock_nanosleep(CLOCK_REALTIME, 0, &tssleep, NULL); } else { /* parent here */ int i; sleep(1); if (kill(pid, SIGABRT) != 0) { printf("Could not raise signal being tested\n"); return PTS_UNRESOLVED; } if (wait(&i) == -1) { perror("Error waiting for child to exit\n"); return PTS_UNRESOLVED; } if (clock_gettime(CLOCK_REALTIME, &tsafter) != 0) { perror("clock_gettime() did not return success\n"); return PTS_UNRESOLVED; } /* * pass if we slept for less than the (large) sleep time * allotted */ if ( (tsafter.tv_sec-tsbefore.tv_sec) < SLEEPSEC) { printf("Test PASSED\n"); return PTS_PASS; } else { printf("Slept for too long: %d >= %d\n", (int)tsafter.tv_sec-(int)tsbefore.tv_sec, SLEEPSEC); printf("Test FAILED\n"); return PTS_FAIL; } } return PTS_UNRESOLVED; } posixtestsuite/conformance/interfaces/clock_nanosleep/1-1.c0100644000000000000000000000303707571204417023121 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that clock_nanosleep() causes the current thread to be suspended * until the time interval in rqtp passes if TIMER_ABSTIME is not set * in flags. */ #include #include #include "posixtest.h" #define SLEEPNSEC 3000000 int main(int argc, char *argv[]) { struct timespec tssleep, tsbefore, tsafter; int slepts=0,sleptns=0; if (clock_gettime(CLOCK_REALTIME, &tsbefore) != 0) { perror("clock_gettime() did not return success\n"); return PTS_UNRESOLVED; } tssleep.tv_sec=0; tssleep.tv_nsec=SLEEPNSEC; if (clock_nanosleep(CLOCK_REALTIME, 0, &tssleep, NULL) != 0) { printf("clock_nanosleep() did not return success\n"); return PTS_UNRESOLVED; } if (clock_gettime(CLOCK_REALTIME, &tsafter) == -1) { perror("Error in clock_gettime()\n"); return PTS_UNRESOLVED; } /* * Generic alg for calculating slept time. */ slepts=tsafter.tv_sec-tsbefore.tv_sec; sleptns=tsafter.tv_nsec-tsbefore.tv_nsec; if (sleptns < 0) { sleptns = sleptns+1000000000; slepts = slepts-1; } if ((slepts > 0) || (sleptns > SLEEPNSEC)) { printf("Test PASSED\n"); return PTS_PASS; } else { printf("clock_nanosleep() did not sleep long enough\n"); return PTS_FAIL; } printf("This code should not be executed.\n"); return PTS_UNRESOLVED; } posixtestsuite/conformance/interfaces/clock_nanosleep/9-1.c0100644000000000000000000000507407776770550023151 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that when clock_nanosleep() is interrupted by a signal, rmtp * contains the amount of time remaining (test with relative sleep). * */ #include #include #include #include #include #include #include #include "posixtest.h" #define SLEEPSEC 30 #define CHILDPASS 1 #define CHILDFAIL 0 #define OKDELTA 1 void handler(int signo) { printf("In handler\n"); } int main(int argc, char *argv[]) { struct timespec tssleep, tsbefore, tsafter, tsremain; int pid; struct sigaction act; if (clock_gettime(CLOCK_REALTIME, &tsbefore) != 0) { perror("clock_gettime() did not return success\n"); return PTS_UNRESOLVED; } if ((pid = fork()) == 0) { /* child here */ int sleptplusremaining; act.sa_handler=handler; act.sa_flags=0; if (sigemptyset(&act.sa_mask) != 0) { perror("sigemptyset() did not return success\n"); return CHILDFAIL; } if (sigaction(SIGABRT, &act, 0) != 0) { perror("sigaction() did not return success\n"); return CHILDFAIL; } tssleep.tv_sec=SLEEPSEC; tssleep.tv_nsec=0; if (clock_nanosleep(CLOCK_REALTIME, 0, &tssleep, &tsremain) == EINTR) { if (clock_gettime(CLOCK_REALTIME, &tsafter) != 0) { perror("clock_gettime() failed\n"); return CHILDFAIL; } sleptplusremaining = (tsafter.tv_sec-tsbefore.tv_sec) + tsremain.tv_sec; if (abs(sleptplusremaining - SLEEPSEC) <= OKDELTA) { printf("PASS - within %d difference\n", abs(sleptplusremaining - SLEEPSEC)); return CHILDPASS; } else { printf("FAIL - within %d difference\n", abs(sleptplusremaining - SLEEPSEC)); return CHILDFAIL; } return CHILDFAIL; } else { printf("clock_nanosleep() did not return EINTR\n"); return CHILDFAIL; } } else { /* parent here */ int i; sleep(1); if (kill(pid, SIGABRT) != 0) { printf("Could not raise signal being tested\n"); return PTS_UNRESOLVED; } if (wait(&i) == -1) { perror("Error waiting for child to exit\n"); return PTS_UNRESOLVED; } if (WIFEXITED(i) && WEXITSTATUS(i)) { printf("Child exited normally\n"); printf("Test PASSED\n"); return PTS_PASS; } else { printf("Child did not exit normally.\n"); printf("Test FAILED\n"); return PTS_FAIL; } } return PTS_UNRESOLVED; } posixtestsuite/conformance/interfaces/clock_nanosleep/11-1.c0100644000000000000000000000225107776766557023230 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that clock_nanosleep() sets errno to EINVAL if rqtp contained a * nanosecond value < 0 or >= 1,000 million */ #include #include #include #include #include "posixtest.h" #define NUMINVALIDTESTS 9 static int invalid_tests[NUMINVALIDTESTS] = { INT32_MIN, INT32_MAX, 2147483647, -2147483647, -1073743192, 1073743192, -1, 1000000000, 1000000001 }; int main(int argc, char *argv[]) { struct timespec tssleep; int i; int failure = 0; tssleep.tv_sec=0; for (i=0; i #include #include #include #include #include #include "posixtest.h" #define SLEEPSEC 30 #define CHILDPASS 1 #define CHILDFAIL 0 void handler(int signo) { printf("In handler\n"); } int main(int argc, char *argv[]) { struct timespec tssleep; int pid; struct sigaction act; if ((pid = fork()) == 0) { /* child here */ act.sa_handler=handler; act.sa_flags=0; if (sigemptyset(&act.sa_mask) != 0) { perror("sigemptyset() did not return success\n"); return CHILDFAIL; } if (sigaction(SIGABRT, &act, 0) != 0) { perror("sigaction() did not return success\n"); return CHILDFAIL; } tssleep.tv_sec=SLEEPSEC; tssleep.tv_nsec=0; if (clock_nanosleep(CLOCK_REALTIME, 0, &tssleep, NULL) == EINTR) { return CHILDPASS; } else { printf("errno != EINTR\n"); return CHILDFAIL; } } else { /* parent here */ int i; sleep(1); if (kill(pid, SIGABRT) != 0) { printf("Could not raise signal being tested\n"); return PTS_UNRESOLVED; } if (wait(&i) == -1) { perror("Error waiting for child to exit\n"); return PTS_UNRESOLVED; } if (WIFEXITED(i) && WEXITSTATUS(i)) { printf("Test PASSED\n"); return PTS_PASS; } else { printf("Test FAILED\n"); return PTS_FAIL; } } return PTS_UNRESOLVED; } posixtestsuite/conformance/interfaces/clock_nanosleep/13-1.c0100644000000000000000000000155507776767375023237 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that clock_nanosleep() sets errno to EINVAL if clock_id does * not refer to a known clock. */ #include #include #include #include "posixtest.h" #define SLEEPSEC 4 #define BOGUSCLOCKID 99999 int main(int argc, char *argv[]) { struct timespec tssleep; tssleep.tv_sec=SLEEPSEC; tssleep.tv_nsec=0; if (clock_nanosleep(BOGUSCLOCKID, 0, &tssleep, NULL) == EINVAL) { printf("Test PASSED\n"); return PTS_PASS; } else { printf("errno != EINVAL\n"); return PTS_FAIL; } printf("This code should not be executed\n"); return PTS_UNRESOLVED; } posixtestsuite/conformance/interfaces/clock_nanosleep/assertions.xml0100644000000000000000000000660407575522774025413 0ustar rootroot clock_nanosleep() causes the current thread to stop executing for the time interval (clocked by clock_id) in rqtp unless: - TIMER_ABSTIME is set in the flags argument - a signal whose action is to invoke a signal catching function is delivered to the current thread - the process is terminated If TIMER_ABSTIME is set in flags, then clock_nanosleep() uses absolute time for the suspension of execution. That is, it stops for: - the absolute time specified by rqtp or until - a signal whose action is to invoke a signal catching function is delivered to the current thread - the process is terminated If TIMER_ABSTIME is set in flags, then if, when clock_nanosleep() is called, rqtp time value less than or equal to specified clock\'s time value, clock_nanosleep() returns immediately and the calling process is *not* suspended. For TIMER_ABSTIME _not_ set: Suspension time is always greater than or equal to the rqtp time interval. [May be greater b/c of rounding or scheduling, just never less than.] Unless clock_nanosleep() is interrupted by a signal. For TIMER_ABSTIME set: Syspension time is always at least until the corresponding clock reaches time rqtp. Unless clock_nanosleep() is interrupted by a signal. clock_nanosleep() does not affect the action/blockage of a signal. clock_nanosleep() fails if clock_id is for the CPU-time clock of the calling thread clock_nanosleep() returns 0 on success (i.e., the full time requested by rqtp has elapsed) For relative clock_nanosleep(), if clock_nanosleep() is interrupted by a signal and rmtp is not-NULL, rmtp contains the amount of time remaining. [If rmtp is NULL, no time is returned.] -- Absolute timers have no effect on rmtp. clock_nanosleep sets errno=EINTR if it was interrupted by a signal clock_nanosleep sets errno=EINVAL if rqpt below 0 or above (or equal to) 1,000 million clock_nanosleep sets errno=EINVAL if TIMER_ABSTIME was specified and rqpt is outside the range for clock_id clock_nanosleep sets errno=EINVAL if clock_id does not refer to a known clock or refers to the CPU-time clock of the calling thread clock_nanosleep sets errno=ENOTSUP if clock_id refers to a clock that clock_nanosleep does not support (ex. if CPU-time clock is not supported) clock_nanosleep() with CLOCK_REALTIME == nanosleep() posixtestsuite/conformance/interfaces/clock_nanosleep/15-1.sh0100755000000000000000000000115007571265056023401 0ustar rootroot#!/bin/sh # Copyright (c) 2002, Intel Corporation. All rights reserved. # Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com # This file is licensed under the GPL license. For the full content # of this license, see the COPYING file at the top level of this # source tree. # # Test that clock_nanosleep() with CLOCK_REALTIME == nanosleep(). # # This is not necessarily something that can be tested; however, it could # also be considered to be tested implicitly via the other clock_nanosleep() # tests which use CLOCK_REALTIME. echo "Tested implicitly via other tests. See output for status." exit 0 posixtestsuite/conformance/interfaces/clock_nanosleep/coverage.txt0100644000000000000000000000117007576212021025002 0ustar rootrootThis document specifies the coverage for function clock_nanosleep(). Assertion Covered? 1 YES 2 YES 3 YES 4 YES 5 YES 6 YES 7 SKIP 8 YES 9 YES 10 YES 11 YES 12 WON'T 13 SKIP 14 SKIP 15 YES **Eventually will want to look at the Rational section in XSH6 because it gives motivation for some good functional and stress tests. SKIP ---- 7-1 Skipping for now as skipping CPU-Time tests 13-2 Skipping checking for EINVAL on CPU-Time clock b/c skipping CPU-Time tests 14-1 Skipping for now as skipping CPU-Time tests 12-1 Won't do for now as unsure how to find (or if it is available) the range for CLOCK_REALTIME. posixtestsuite/conformance/interfaces/clock_nanosleep/5-1.sh0100755000000000000000000000100707571257037023321 0ustar rootroot#!/bin/sh # Copyright (c) 2002, Intel Corporation. All rights reserved. # Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com # This file is licensed under the GPL license. For the full content # of this license, see the COPYING file at the top level of this # source tree. # # Test that clock_nanosleep() always sleeps until at least the time # specified in rqtp for absolute sleeps. # # This is tested implicitly via assertion 2. echo "Tested implicitly via assertion 2. See output for status." exit 0 posixtestsuite/conformance/interfaces/clock_nanosleep/2-3.c0100644000000000000000000000361507571244165023132 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that clock_nanosleep() causes the current thread to be suspended * until a signal whose action is to terminate the process is received * for an absolute clock. [Same as test 1-4.c except with TIMER_ABSTIME * set.] */ #include #include #include #include #include #include "posixtest.h" #define SLEEPSEC 30 int main(int argc, char *argv[]) { struct timespec tssleep, tsbefore, tsafter; int pid, sleepuntilsec; if (clock_gettime(CLOCK_REALTIME, &tsbefore) != 0) { perror("clock_gettime() did not return success\n"); return PTS_UNRESOLVED; } sleepuntilsec = tsbefore.tv_sec + SLEEPSEC; if ((pid = fork()) == 0) { int flags = 0; /* child here */ tssleep.tv_sec=sleepuntilsec; tssleep.tv_nsec=tsbefore.tv_nsec; flags |= TIMER_ABSTIME; clock_nanosleep(CLOCK_REALTIME, flags, &tssleep, NULL); } else { /* parent here */ int i; sleep(1); if (kill(pid, SIGABRT) != 0) { printf("Could not raise signal being tested\n"); return PTS_UNRESOLVED; } if (wait(&i) == -1) { perror("Error waiting for child to exit\n"); return PTS_UNRESOLVED; } if (clock_gettime(CLOCK_REALTIME, &tsafter) != 0) { perror("clock_gettime() did not return success\n"); return PTS_UNRESOLVED; } /* * pass if we slept for less than the (large) sleep time * allotted */ if ( tsafter.tv_sec < sleepuntilsec) { printf("Test PASSED\n"); return PTS_PASS; } else { printf("Slept for too long: %d >= %d\n", (int)tsafter.tv_sec, sleepuntilsec); printf("Test FAILED\n"); return PTS_FAIL; } } return PTS_UNRESOLVED; } posixtestsuite/conformance/interfaces/clock_nanosleep/2-1.c0100644000000000000000000000341207571204462023117 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that if TIMER_ABSTIME is set in flags, then clock_nanosleep() * sleeps for the absolute time specified in rqtp. * * - Get the current time. * - Set clock_nanosleep() to sleep for current time + SLEEPSEC * seconds. * - Get the current time after sleeping and ensure it is within * ACCEPTABLEDELTA of current time + SLEEPSEC */ #include #include #include "posixtest.h" #define SLEEPSEC 3 #define ACCEPTABLEDELTA 1 int main(int argc, char *argv[]) { struct timespec tssleep, tsbefore, tsafter; int sleepuntilsec, flags = 0; if (clock_gettime(CLOCK_REALTIME, &tsbefore) != 0) { perror("clock_gettime() did not return success\n"); return PTS_UNRESOLVED; } sleepuntilsec = tsbefore.tv_sec + SLEEPSEC; tssleep.tv_sec = sleepuntilsec; tssleep.tv_nsec = tsbefore.tv_nsec; flags |= TIMER_ABSTIME; if (clock_nanosleep(CLOCK_REALTIME, flags, &tssleep, NULL) != 0) { printf("clock_nanosleep() did not return success\n"); return PTS_UNRESOLVED; } if (clock_gettime(CLOCK_REALTIME, &tsafter) == -1) { perror("Error in clock_gettime()\n"); return PTS_UNRESOLVED; } if (tsafter.tv_sec >= sleepuntilsec) { if (tsafter.tv_sec <= (sleepuntilsec+ACCEPTABLEDELTA)) { printf("Test PASSED\n"); return PTS_PASS; } else { printf("clock_nanosleep() slept too long\n"); return PTS_FAIL; } } else { printf("clock_nanosleep() did not sleep long enough\n"); return PTS_FAIL; } printf("This code should not be executed.\n"); return PTS_UNRESOLVED; } posixtestsuite/conformance/interfaces/clock_nanosleep/1-4.c0100644000000000000000000000332707571204344023125 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that clock_nanosleep() causes the current thread to be suspended * until a signal whose action is to terminate the process is received. */ #include #include #include #include #include #include "posixtest.h" #define SLEEPSEC 30 int main(int argc, char *argv[]) { struct timespec tssleep, tsbefore, tsafter; int pid; if (clock_gettime(CLOCK_REALTIME, &tsbefore) != 0) { perror("clock_gettime() did not return success\n"); return PTS_UNRESOLVED; } if ((pid = fork()) == 0) { /* child here */ tssleep.tv_sec=SLEEPSEC; tssleep.tv_nsec=0; clock_nanosleep(CLOCK_REALTIME, 0, &tssleep, NULL); } else { /* parent here */ int i; sleep(1); if (kill(pid, SIGABRT) != 0) { printf("Could not raise signal being tested\n"); return PTS_UNRESOLVED; } if (wait(&i) == -1) { perror("Error waiting for child to exit\n"); return PTS_UNRESOLVED; } if (clock_gettime(CLOCK_REALTIME, &tsafter) != 0) { perror("clock_gettime() did not return success\n"); return PTS_UNRESOLVED; } /* * pass if we slept for less than the (large) sleep time * allotted */ if ( (tsafter.tv_sec-tsbefore.tv_sec) < SLEEPSEC) { printf("Test PASSED\n"); return PTS_PASS; } else { printf("Slept for too long: %d >= %d\n", (int)tsafter.tv_sec-(int)tsbefore.tv_sec, SLEEPSEC); printf("Test FAILED\n"); return PTS_FAIL; } } return PTS_UNRESOLVED; } posixtestsuite/conformance/interfaces/clock_nanosleep/4-1.sh0100755000000000000000000000076107571257037023326 0ustar rootroot#!/bin/sh # Copyright (c) 2002, Intel Corporation. All rights reserved. # Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com # This file is licensed under the GPL license. For the full content # of this license, see the COPYING file at the top level of this # source tree. # # Test that clock_nanosleep() always sleeps for at least the amount # of time in rqtp. # # This is tested implicitly via assertion 1. echo "Tested implicitly via assertion 1. See output for status." exit 0 posixtestsuite/conformance/interfaces/clock_nanosleep/1-2.sh0100755000000000000000000000106007571204343023305 0ustar rootroot#!/bin/sh # Copyright (c) 2002, Intel Corporation. All rights reserved. # Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com # This file is licensed under the GPL license. For the full content # of this license, see the COPYING file at the top level of this # source tree. # # Test that clock_nanosleep() causes the current thread to stop # executing for the time interval in rqtp unless TIMER_ABSTIME is set # in the flags. # # This is tested implicitly via assertion 2. echo "Tested implicitly via assertion 2. See output for status." exit 0 posixtestsuite/conformance/interfaces/clock_nanosleep/6-1.sh0100755000000000000000000000077207571257037023332 0ustar rootroot#!/bin/sh # Copyright (c) 2002, Intel Corporation. All rights reserved. # Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com # This file is licensed under the GPL license. For the full content # of this license, see the COPYING file at the top level of this # source tree. # # Test that clock_nanosleep() does not affect the action/blockage of # a signal. # # This is tested implicitly via assertions 1 and 2. echo "Tested implicitly via assertions 1 and 2. See output for status." exit 0 posixtestsuite/conformance/interfaces/clock_nanosleep/3-1.c0100644000000000000000000000351707571246754023140 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that if TIMER_ABSTIME is set in flags, then if clock_nanosleep() * parameter rqtp specifies a time in the past, clock_nanosleep() * returns immediately and no suspension occurs. * * - Get the current time. * - Set clock_nanosleep() to sleep until current time - SLEEPSEC * seconds. * - Get the current time after sleeping and ensure it is within * ACCEPTABLEDELTA of current time (i.e., didn't sleep) */ #include #include #include "posixtest.h" #define SLEEPSEC 3 #define ACCEPTABLEDELTA 1 int main(int argc, char *argv[]) { struct timespec tssleep, tsbefore, tsafter; int sleepuntilsec, flags = 0; if (clock_gettime(CLOCK_REALTIME, &tsbefore) != 0) { perror("clock_gettime() did not return success\n"); return PTS_UNRESOLVED; } sleepuntilsec = tsbefore.tv_sec - SLEEPSEC; tssleep.tv_sec = sleepuntilsec; tssleep.tv_nsec = tsbefore.tv_nsec; flags |= TIMER_ABSTIME; if (clock_nanosleep(CLOCK_REALTIME, flags, &tssleep, NULL) != 0) { printf("clock_nanosleep() did not return success\n"); return PTS_UNRESOLVED; } if (clock_gettime(CLOCK_REALTIME, &tsafter) == -1) { perror("Error in clock_gettime()\n"); return PTS_UNRESOLVED; } if (tsafter.tv_sec >= tsbefore.tv_sec) { if (tsafter.tv_sec <= (tsbefore.tv_sec+ACCEPTABLEDELTA)) { printf("Test PASSED\n"); return PTS_PASS; } else { printf("FAIL: clock_nanosleep() slept\n"); return PTS_FAIL; } } else { printf("FAIL: error in clock_gettime()\n"); return PTS_FAIL; } printf("This code should not be executed.\n"); return PTS_UNRESOLVED; } posixtestsuite/conformance/interfaces/mlock/0040755000000000000000000000000010515625166020425 5ustar rootrootposixtestsuite/conformance/interfaces/mlock/5-1.c0100644000000000000000000000227707700524230021070 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that mlock return a value of zero upon successful completion. * */ #include #include #include #include #include "posixtest.h" #define BUFSIZE 8 int main() { int result; void *ptr; ptr = malloc(BUFSIZE); if(ptr == NULL) { printf("Can not allocate memory.\n"); return PTS_UNRESOLVED; } result = mlock(ptr, BUFSIZE); if(result == 0 && errno == 0){ printf("Test PASSED\n"); return PTS_PASS; } else if(errno == 0) { printf("mlock did not return a value of zero\n"); return PTS_FAIL; } else if(errno == EPERM) { printf("You don't have permission to lock your address space.\nTry to rerun this test as root.\n"); return PTS_UNRESOLVED; } perror("Unexpected error"); return PTS_UNRESOLVED; } posixtestsuite/conformance/interfaces/mlock/speculative/0040755000000000000000000000000010515625166022751 5ustar rootrootposixtestsuite/conformance/interfaces/mlock/speculative/12-1.c0100644000000000000000000000414710350022205023456 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that the mlock() function sets errno = EPERM if the calling process * does not have the appropriate privilege to perform the requested operation. */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include #include #include #include "posixtest.h" #define BUFSIZE 8 /** Set the euid of this process to a non-root uid */ int set_nonroot() { struct passwd *pw; setpwent(); /* search for the first user which is non root */ while((pw = getpwent()) != NULL) if(strcmp(pw->pw_name, "root")) break; endpwent(); if(pw == NULL) { printf("There is no other user than current and root.\n"); return 1; } if(seteuid(pw->pw_uid) != 0) { if(errno == EPERM) { printf("You don't have permission to change your UID.\n"); return 1; } perror("An error occurs when calling seteuid()"); return 1; } printf("Testing with user '%s' (uid: %d)\n", pw->pw_name, (int)geteuid()); return 0; } int main() { int result; void *ptr; /* This test should be run under standard user permissions */ if (getuid() == 0) { if (set_nonroot() != 0) { printf("Cannot run this test as non-root user\n"); return PTS_UNTESTED; } } ptr = malloc(BUFSIZE); if(ptr == NULL) { printf("Can not allocate memory.\n"); return PTS_UNRESOLVED; } result = mlock(ptr, BUFSIZE); if(result == -1 && errno == EPERM) { printf("Test PASSED\n"); return PTS_PASS; } else if(result == 0) { printf("You have the right to call mlock\n"); return PTS_FAIL; } else { perror("Unexpected error"); return PTS_UNRESOLVED; } } posixtestsuite/conformance/interfaces/mlock/7-1.sh0100755000000000000000000000030507700524230021253 0ustar rootroot#! /bin/sh # # Test that the mlock() function return -1 upon unsuccessful completion. # # This is tested implicitly via assertions 8 to 12. echo "Tested implicitly via assertions 8 to 12." exit 0 posixtestsuite/conformance/interfaces/mlock/10-1.c0100644000000000000000000000347307700524230021143 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that mlock() set errno = EINVAL when addr is not a multiple of * {PAGESIZE} if the implementation requires that addr be a multiple of * {PAGESIZE}. */ #include #include #include #include #include #include "posixtest.h" int main() { int result; long page_size; void *ptr, *notpage_ptr; page_size = sysconf(_SC_PAGESIZE); if(errno) { perror("An error occurs when calling sysconf()"); return PTS_UNRESOLVED; } ptr = malloc(page_size); if(ptr == NULL) { printf("Can not allocate memory.\n"); return PTS_UNRESOLVED; } notpage_ptr = ((long)ptr % page_size) ? ptr : ptr+1; result = mlock(notpage_ptr, page_size - 1); if(result == 0){ printf("mlock() does not require that addr be a multiple of {PAGESIZE}.\nTest PASSED\n"); return PTS_PASS; } else if(result == -1 && errno == EINVAL){ printf("mlock() requires that addr be a multiple of {PAGESIZE}.\nTest PASSED\n"); return PTS_PASS; } else if(errno == EPERM) { printf("You don't have permission to lock your address space.\nTry to rerun this test as root.\n"); return PTS_UNRESOLVED; } else if(result != -1){ printf("mlock() returns a value of %i instead of 0 or 1.\n", result); perror("mlock"); return PTS_FAIL; } perror("Unexpected error"); return PTS_UNRESOLVED; } posixtestsuite/conformance/interfaces/mlock/assertions.xml0100644000000000000000000000516007700524230023330 0ustar rootroot The mlock() function shall cause those whole pages containing any part of the address space of the process starting at address addr and continuing for len bytes to be memory-resident until unlocked or until the process exits or execs another process image The implementation may require that addr be a multiple of {PAGESIZE} Upon successful return from mlock(), pages in the specified range shall be locked and memory-resident The appropriate privilege is required to lock process memory with mlock() Upon successful completion, the mlock() function shall return a value of zero Upon unsuccessful completion, no change is made to any locks in the address space of the process Upon unsuccessful completion, the function shall return a value of -1 The mlock() function shall set errno = ENOMEM if some or all of the address range specified by the addr and len arguments does not correspond to valid mapped pages in the address space of the process The mlock() function shall set errno = EAGAIN if some or all of the memory identified by the operation could not be locked when the call was made The mlock() function may set errno = EINVAL if the addr argument is not a multiple of {PAGESIZE} The mlock() function may set errno = ENOMEM if locking the pages mapped by the specified range would exceed an implementation-defined limit on the amount of memory that the process may lock The mlock() function may set errno = EPERM if the calling process does not have the appropriate privilege to perform the requested operation posixtestsuite/conformance/interfaces/mlock/coverage.txt0100644000000000000000000000062407700524230022750 0ustar rootrootThis document explains why certain assertions were not tested. Assertions not listed here should be covered by the tests in this directory. Assertions Tested ? Remarks 1 NO 2 YES May assertion 3 NO 4 YES 5 YES 6 NO 7 YES 8 YES 9 NO 10 YES May assertion 11 NO May assertion 12 YES May assertion posixtestsuite/conformance/interfaces/mlock/8-1.c0100644000000000000000000000267607700524230021076 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * Test that the mlock() function sets errno = ENOMEM if some or all of the * address range specified by the addr and len arguments does not correspond to * valid mapped pages in the address space of the process. * * Assume that the value LONG_MAX is an invalid pointer. */ #include #include #include #include #include #include "posixtest.h" #define BUFSIZE 8 int main() { int result; long page_size; void *page_ptr; page_size = sysconf(_SC_PAGESIZE); if(errno) { perror("An error occurs when calling sysconf()"); return PTS_UNRESOLVED; } page_ptr = (void*)( LONG_MAX - (LONG_MAX % page_size) ); result = mlock(page_ptr, BUFSIZE); if(result == -1 && errno == ENOMEM) { printf("Test PASSED\n"); return PTS_PASS; } else if(errno == EPERM) { printf("You don't have permission to lock your address space.\nTry to rerun this test as root.\n"); return PTS_UNRESOLVED; } else { perror("Unexpected error"); return PTS_UNRESOLVED; } } posixtestsuite/conformance/interfaces/mlock/2-1.sh0100755000000000000000000000030407700524230021245 0ustar rootroot#! /bin/sh # # Test whether the implementation requires that addr be a multiple of # {PAGESIZE}. # # This is tested implicitly via assertion 10. echo "Tested implicitly via assertion 10." exit 0 posixtestsuite/conformance/interfaces/mlock/4-1.sh0100755000000000000000000000031007700524230021244 0ustar rootroot#! /bin/sh # # Test that the appropriate privilege is required to lock process memory with # mlock() # # This is tested implicitly via assertion 12. echo "Tested implicitly via assertion 12." exit 0 posixtestsuite/conformance/interfaces/pthread_attr_setdetachstate/0040755000000000000000000000000010515625177025070 5ustar rootrootposixtestsuite/conformance/interfaces/pthread_attr_setdetachstate/4-1.c0100644000000000000000000000223007621011517025516 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_attr_setdetachstate() * * shall fail if: * -[EINVAL] The value of detachstate was not valid * * Steps: * 1. Initialize a pthread_attr_t object using pthread_attr_init() * 2. Call pthread_attr_setdetachstate() using an invalid value of 0 * */ #include #include #include #include "posixtest.h" int main() { pthread_attr_t new_attr; int ret_val, invalid_val; /* Initialize attribute */ if(pthread_attr_init(&new_attr) != 0) { perror("Cannot initialize attribute object\n"); return PTS_UNRESOLVED; } /* Set the attribute object to an invalid value of 1000000. */ invalid_val=1000000; ret_val=pthread_attr_setdetachstate(&new_attr, invalid_val); if(ret_val != EINVAL) { printf("Test FAILED: Returned %d instead of EINVAL\n", ret_val); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_attr_setdetachstate/3-1.sh0100755000000000000000000000073307607701455025731 0ustar rootroot#!/bin/sh # Copyright (c) 2002, Intel Corporation. All rights reserved. # Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com # This file is licensed under the GPL license. For the full content # of this license, see the COPYING file at the top level of this # source tree. # Test pthread_attr_getdetachstate returns 0 on success. # This is tested implicitly via assertion 1 and 2. echo "Tested implicitly via assertions 1 and 2. See output for status" exit 0 posixtestsuite/conformance/interfaces/pthread_attr_setdetachstate/1-1.c0100644000000000000000000000370507607701251025530 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_attr_setdetachstate() * * shall set the detachstate attribute in the 'attr' object. * The detach state is either PTHREAD_CREATE_DETACHED or * PTHEAD_CREATE_JOINABLE. * A value of PTHREAD_CREATE_DETACHED shall cause all threads created with * 'attr' to be in the detached state, wheras using a value of * PTHREAD_CREATE_JOINABLE shall cause threads created with 'attr' to be in * the joinable state. * The default value of the detachstate attribute shall be * PTHREAD_CREATE_JOINABLE. * * Steps: * 1. Initialize a pthread_attr_t object using pthread_attr_init() * 2. Using pthread_attr_setdetachstate(), set the detachstate to * PTHREAD_CREATE_JOINABLE. * 3. Get the detachedstate and make sure that it is really set to * PTHREAD_CREATE_JOINABLE. * */ #include #include #include "posixtest.h" int main() { pthread_attr_t new_attr; int detach_state; /* Initialize attribute */ if(pthread_attr_init(&new_attr) != 0) { perror("Cannot initialize attribute object\n"); return PTS_UNRESOLVED; } /* Set the attribute object to PTHREAD_CREATE_JOINABLE. */ if(pthread_attr_setdetachstate(&new_attr, PTHREAD_CREATE_JOINABLE) != 0) { perror("Error in pthread_attr_setdetachstate()\n"); return PTS_UNRESOLVED; } /* Check to see if the detachstate is truly PTHREAD_CREATE_JOINABLE. */ if(pthread_attr_getdetachstate(&new_attr, &detach_state) != 0) { perror("Error in pthread_attr_getdetachstate.\n"); return PTS_UNRESOLVED; } if(detach_state == PTHREAD_CREATE_JOINABLE) { printf("Test PASSED\n"); return PTS_PASS; } else { printf("Test FAILED\n"); return PTS_FAIL; } } posixtestsuite/conformance/interfaces/pthread_attr_setdetachstate/1-2.c0100644000000000000000000000370507607701251025531 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_attr_setdetachstate() * * shall set the detachstate attribute in the 'attr' object. * The detach state is either PTHREAD_CREATE_DETACHED or * PTHEAD_CREATE_JOINABLE. * A value of PTHREAD_CREATE_DETACHED shall cause all threads created with * 'attr' to be in the detached state, wheras using a value of * PTHREAD_CREATE_JOINABLE shall cause threads created with 'attr' to be in * the joinable state. * The default value of the detachstate attribute shall be * PTHREAD_CREATE_JOINABLE. * * Steps: * 1. Initialize a pthread_attr_t object using pthread_attr_init() * 2. Using pthread_attr_setdetachstate(), set the detachstate to * PTHREAD_CREATE_DETACHED. * 3. Get the detachedstate and make sure that it is really set to * PTHREAD_CREATE_DETACHED. * */ #include #include #include "posixtest.h" int main() { pthread_attr_t new_attr; int detach_state; /* Initialize attribute */ if(pthread_attr_init(&new_attr) != 0) { perror("Cannot initialize attribute object\n"); return PTS_UNRESOLVED; } /* Set the attribute object to PTHREAD_CREATE_DETACHED. */ if(pthread_attr_setdetachstate(&new_attr, PTHREAD_CREATE_DETACHED) != 0) { perror("Error in pthread_attr_setdetachstate()\n"); return PTS_UNRESOLVED; } /* Check to see if the detachstate is truly PTHREAD_CREATE_DETACHED. */ if(pthread_attr_getdetachstate(&new_attr, &detach_state) != 0) { perror("Error in pthread_attr_getdetachstate.\n"); return PTS_UNRESOLVED; } if(detach_state == PTHREAD_CREATE_DETACHED) { printf("Test PASSED\n"); return PTS_PASS; } else { printf("Test FAILED\n"); return PTS_FAIL; } } posixtestsuite/conformance/interfaces/pthread_attr_setdetachstate/assertions.xml0100644000000000000000000000210207621011520027755 0ustar rootroot The function int pthread_attr_setdetachstate(const pthread_attr_t *attr, int *detachstate) sets the detachstate attribute in the 'attr' object. The detach state can be either PTHREAD_CREATE_DETACHED or PTHEAD_CREATE_JOINABLE. A value of PTHREAD_CREATE_DETACHED causes all threads created with 'attr' to be in a detached state, and using a value of PTHREAD_CREATE_JOINABLE causes threads created with 'attr' to be in the joinable state. The default value of the detachstate attribute is PTHREAD_CREATE_JOINABLE. If the thread is created detached, then use of the ID of the newly created thread by the pthread_detach() or pthread_join() function will producer an error. If success, it returns 0. It shall fail if: -[EINVAL] The value of detachstate was invalid posixtestsuite/conformance/interfaces/pthread_attr_setdetachstate/coverage.txt0100644000000000000000000000020707607701251027414 0ustar rootrootThis document defines the coverage for the pthread_attr_getdetachstate function: Assertion Tested? 1 YES 2 YES 3 YES 4 YES NOTE: posixtestsuite/conformance/interfaces/pthread_attr_setdetachstate/2-1.c0100644000000000000000000000367707626776060025554 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: rolla.n.selbak REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_attr_setdetachstate() * * If the thread is created detached, then use of the ID of the newly created * thread by the pthread_detach() or pthread_join() function is an error. * * Steps: * 1. Initialize a pthread_attr_t object using pthread_attr_init(). * 2. Using pthread_attr_setdetachstate(), set the detachstate to * PTHREAD_CREATE_DETACHED. * 3. Create a thread with this attribute. * 4. Call pthread_detach() and pthread_join() on this thread, it should give * an error. * */ #include #include #include #include "posixtest.h" void *a_thread_func() { pthread_exit(0); return NULL; } int main() { pthread_t new_th; pthread_attr_t new_attr; int ret_val; /* Initialize attribute */ if(pthread_attr_init(&new_attr) != 0) { perror("Cannot initialize attribute object\n"); return PTS_UNRESOLVED; } /* Set the attribute object to PTHREAD_CREATE_DETACHED. */ if(pthread_attr_setdetachstate(&new_attr, PTHREAD_CREATE_DETACHED) != 0) { perror("Error in pthread_attr_setdetachstate()\n"); return PTS_UNRESOLVED; } /* Create a new thread passing it the new attribute object */ if(pthread_create(&new_th, &new_attr, a_thread_func, NULL) != 0) { perror("Error creating thread\n"); return PTS_UNRESOLVED; } /* If pthread_join() or pthread_detach fail, that means that the * test fails as well. */ ret_val=pthread_join(new_th, NULL); if(ret_val != EINVAL) { printf("Test FAILED\n"); return PTS_FAIL; } ret_val=pthread_detach(new_th); if(ret_val != EINVAL) { printf("Test FAILED\n"); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/mq_timedsend/0040755000000000000000000000000010515625174021770 5ustar rootrootposixtestsuite/conformance/interfaces/mq_timedsend/11-2.c0100644000000000000000000000337710035502500022503 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * Test that mq_timedsend() returns errno == EBADF if mqdes is not open for * writing. */ #include #include #include #include #include #include #include #include #include #include "posixtest.h" #define NAMESIZE 50 #define MSGSTR "0123456789" int main() { char qname[NAMESIZE]; const char *msgptr = MSGSTR; struct timespec ts; mqd_t queue; int unresolved=0, failure=0; sprintf(qname, "/mq_timedsend_11-2_%d", getpid()); queue = mq_open(qname, O_CREAT | O_RDONLY, S_IRUSR | S_IWUSR, NULL); if (queue == (mqd_t)-1) { perror("mq_open() did not return success"); return PTS_UNRESOLVED; } ts.tv_sec=time(NULL)+1; ts.tv_nsec=0; if (mq_timedsend(queue, msgptr, strlen(msgptr), 1, &ts) != -1) { printf("mq_timedsend() did not return -1 on invalid queue\n"); failure=1; } if (errno != EBADF) { printf("errno != EBADF\n"); failure = 1; } if (mq_close(queue) != 0) { perror("mq_close() did not return success"); unresolved=1; } if (mq_unlink(qname) != 0) { perror("mq_unlink() did not return success"); unresolved=1; } if (failure==1) { printf("Test FAILED\n"); return PTS_FAIL; } if (unresolved==1) { printf("Test UNRESOLVED\n"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/mq_timedsend/15-1.c0100644000000000000000000000524510035502500022502 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * Test that if abs_timeout has already passed when mq_timedsend is * called, then the timeout shall expire. * * Test by setting the timeout to a time in the past and then sending * messages until one would block. Ensure that the error on this message * that would block is * ETIMEDOUT and that the time is close to the start time. */ #include #include #include #include #include #include #include #include #include #include #include #include #include "posixtest.h" #define NAMESIZE 50 #define MSGSTR "0123456789" #define TIMEOUT 5 #define DELTA 1 #define BUFFER 40 #define MAXMSG 5 char gqname[NAMESIZE]; mqd_t gqueue; void testfailed_handler(int signo) { printf("Timeout never happened\n"); printf("Test FAILED\n"); mq_close(gqueue); mq_unlink(gqname); exit(PTS_FAIL); } int main() { char *msgptr=MSGSTR; struct timespec ts; struct sigaction act; struct mq_attr attr; time_t currsec; int maxreached=0, i; sprintf(gqname, "/mq_timedsend_15-1_%d", getpid()); attr.mq_msgsize = BUFFER; attr.mq_maxmsg = MAXMSG; gqueue = mq_open(gqname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, &attr); if (gqueue == (mqd_t)-1) { perror("mq_open() did not return success"); printf("Test UNRESOLVED\n"); return PTS_UNRESOLVED; } currsec = time(NULL); ts.tv_sec=currsec-5; //time in past ts.tv_nsec=0; /* * If timeout never happens, set up an alarm that will go off * after TIMEOUT seconds and call a handler to end the test */ act.sa_handler=testfailed_handler; act.sa_flags=0; sigemptyset(&act.sa_mask); sigaction(SIGALRM, &act, 0); alarm(TIMEOUT); for (i=0; i currsec+DELTA) { printf("Timeout lasted too long\n"); printf("Test FAILED\n"); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/mq_timedsend/17-1.c0100644000000000000000000000106507633704010022512 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: geoffrey.r.gustafson REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * Since timeouts can happen at any time on the system, resolution of * timeouts cannot be determined. Will not test timeout resolution. */ #include #include "posixtest.h" int main() { printf("Will not test timeout resolution.\n"); return PTS_UNTESTED; } posixtestsuite/conformance/interfaces/mq_timedsend/19-1.c0100644000000000000000000000540110035502500022500 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * Test that mq_timedsend() will return EINVAL if the message queue is * full and abs_timeout has a tv_nsec < 0 or >= 1000 million. * * Fill message queue until full and then call mq_timedsend with invalid * abs_timeout values. */ #include #include #include #include #include #include #include #include #include #include #include "posixtest.h" #define NAMESIZE 50 #define MSGSTR "0123456789" #define NUMTESTS 5 #define BUFFER 40 #define MAXMSG 5 int invalid_tests[NUMTESTS] = {-1, INT32_MIN, 1000000000, 1000000001 , INT32_MAX }; int main() { char qname[NAMESIZE]; char *msgptr=MSGSTR; struct timespec ts; mqd_t queue; struct mq_attr attr; int failure=0, i, maxreached=0; sprintf(qname, "/mq_timedsend_19-1_%d", getpid()); attr.mq_maxmsg = MAXMSG; attr.mq_msgsize = BUFFER; queue = mq_open(qname, O_CREAT | O_RDWR | O_NONBLOCK, S_IRUSR | S_IWUSR, &attr); if (queue == (mqd_t)-1) { perror("mq_open() did not return success"); printf("Test UNRESOLVED\n"); return PTS_UNRESOLVED; } ts.tv_sec=time(NULL); ts.tv_nsec=0; for (i=0; i= BUFFER. * */ #include #include #include #include #include #include #include #include #include #include #include #include #include "posixtest.h" #define NAMESIZE 50 #define MSGSTR "0123456789" #define BUFFER 40 #define MAXMSG 5 char gqname[NAMESIZE]; mqd_t gqueue; /* * This handler is just used to catch the signal and stop sleep (so the * parent knows the child is still busy sending signals). */ void stopsleep_handler(int signo) { return; } int main() { int pid; char msgrcd[BUFFER]; const char *msgptr = MSGSTR; struct mq_attr attr; int unresolved=0; unsigned pri; sprintf(gqname, "/mq_timedsend_5-1_%d", getpid()); attr.mq_msgsize = BUFFER; attr.mq_maxmsg = MAXMSG; gqueue = mq_open(gqname, O_CREAT |O_RDWR, S_IRUSR | S_IWUSR, &attr); if (gqueue == (mqd_t)-1) { perror("mq_open() did not return success"); return PTS_UNRESOLVED; } if ((pid = fork()) == 0) { /* child here */ int i; struct timespec ts; /* set up timeout to be as long as possible */ ts.tv_sec=INT32_MAX; ts.tv_nsec=0; sleep(1); // give parent time to set up handler for (i=0; i #include #include #include #include #include #include #include #include "posixtest.h" #define NAMESIZE 50 #define MSGSTR "0123456789" int main() { char qname[NAMESIZE]; const char *msgptr = MSGSTR; struct timespec ts; mqd_t queue; sprintf(qname, "/msgqueue_%d", getpid()); queue = mq_open(qname, O_CREAT |O_RDWR, S_IRUSR | S_IWUSR, NULL); if (queue == (mqd_t)-1) { perror("mq_open() did not return success"); printf("Test UNRESOLVED\n"); return PTS_UNRESOLVED; } ts.tv_sec=time(NULL)-1; ts.tv_nsec=-1; if (mq_timedsend(queue, msgptr, strlen(msgptr), 1, &ts) == -1) { printf("mq_timedsend() did fail on invalid abs_time\n"); mq_close(queue); mq_unlink(qname); return PTS_PASS; } mq_close(queue); mq_unlink(qname); printf("mq_timedsend() did not fail on invalid abs_time\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/mq_timedsend/4-1.c0100644000000000000000000000324510035502500022416 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * Test that msg_prio must be less than MQ_PRIO_MAX. */ #include #include #include #include #include #include #include #include #include #include "posixtest.h" #define NAMESIZE 50 #define MSGSTR "0123456789" int main() { char qname[NAMESIZE]; const char *msgptr = MSGSTR; struct timespec ts; mqd_t queue; int unresolved=0, failure=0; sprintf(qname, "/mq_timedsend_4-1_%d", getpid()); queue = mq_open(qname, O_CREAT |O_RDWR, S_IRUSR | S_IWUSR, NULL); if (queue == (mqd_t)-1) { perror("mq_open() did not return success"); return PTS_UNRESOLVED; } ts.tv_sec=time(NULL)+1; ts.tv_nsec=0; if (mq_timedsend(queue, msgptr, strlen(msgptr), MQ_PRIO_MAX+1, &ts) == 0) { printf("mq_timedsend() ret success with pri > MQ_PRIO_MAX\n"); failure=1; } if (mq_close(queue) != 0) { perror("mq_close() did not return success"); unresolved=1; } if (mq_unlink(qname) != 0) { perror("mq_unlink() did not return success"); unresolved=1; } if (failure==1) { printf("Test FAILED\n"); return PTS_FAIL; } if (unresolved==1) { printf("Test UNRESOLVED\n"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/mq_timedsend/14-1.c0100644000000000000000000000377610035502500022510 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * Test that EMSGSIZE is returned if msg_len is not <= mq_attr->mq_msgsize. */ #include #include #include #include #include #include #include #include #include #include #include "posixtest.h" #define NAMESIZE 50 #define MSGSTR "01234567890123456789" #define NUMINVALID 3 static long messagesize[NUMINVALID] = { 19, 2, 1 }; int main() { char qname[NAMESIZE]; const char *msgptr = MSGSTR; struct timespec ts; mqd_t queue; int unresolved=0, failure=0, i; struct mq_attr attr; sprintf(qname, "/mq_timedsend_14-1_%d", getpid()); ts.tv_sec=time(NULL); ts.tv_nsec=0; for (i=0; i #include #include #include #include #include #include #include #include #include #include #include #include "posixtest.h" #define NAMESIZE 50 #define MSGSTR "0123456789" #define BUFFER 40 #define MAXMSG 5 #define CHILDPASS 1 #define CHILDFAIL 0 char gqname[NAMESIZE]; mqd_t gqueue; /* * This handler is just used to catch the signal and stop sleep (so the * parent knows the child is still busy sending signals). */ void justreturn_handler(int signo) { return; } int main() { int pid; const char *msgptr = MSGSTR; struct mq_attr attr; struct sigaction act; sprintf(gqname, "/mq_timedsend_5-2_%d", getpid()); attr.mq_msgsize = BUFFER; attr.mq_maxmsg = MAXMSG; gqueue = mq_open(gqname, O_CREAT |O_RDWR, S_IRUSR | S_IWUSR, &attr); if (gqueue == (mqd_t)-1) { perror("mq_open() did not return success"); return PTS_UNRESOLVED; } /* parent and child use justreturn_handler to just return out of * situations -- parent uses to stop it's sleep and wait again for * the child; child uses to stop its mq_timedsend */ act.sa_handler=justreturn_handler; act.sa_flags=0; sigemptyset(&act.sa_mask); sigaction(SIGABRT, &act, 0); if ((pid = fork()) == 0) { /* child here */ int i; struct timespec ts; /* set up timeout to be as long as possible */ ts.tv_sec=INT32_MAX; ts.tv_nsec=0; sleep(1); // give parent time to set up handler for (i=0; i #include #include #include #include #include #include #include #include "posixtest.h" #define NAMESIZE 50 #define MSGSTR "0123456789" int main() { char qname[NAMESIZE]; const char *msgptr = MSGSTR; struct timespec ts; mqd_t queue; sprintf(qname, "/mq_timedsend_18-1_%d", getpid()); queue = mq_open(qname, O_CREAT |O_RDWR, S_IRUSR | S_IWUSR, NULL); if (queue == (mqd_t)-1) { perror("mq_open() did not return success"); printf("Test UNRESOLVED\n"); return PTS_UNRESOLVED; } ts.tv_sec=time(NULL)-1; ts.tv_nsec=0; if (mq_timedsend(queue, msgptr, strlen(msgptr), 1, &ts) != 0) { perror("mq_timedsend() did not return success on empty queue"); printf("Test FAILED\n"); mq_close(queue); mq_unlink(qname); return PTS_FAIL; } mq_close(queue); mq_unlink(qname); printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/mq_timedsend/12-1.c0100644000000000000000000001101210035502500022464 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * Test mq_timedsend() will set errno == EINTR if it is interrupted by a signal. * * Steps: * 1. Create a thread and set up a signal handler for SIGUSR1 * 2. Thread indicates to main that it is ready to start calling mq_timedsend until it * blocks for a timeout of 10 seconds. * 3. In main, send the thread the SIGUSR1 signal while mq_timedsend is blocking. * 4. Check to make sure that mq_timedsend blocked, and that it returned EINTR when it was * interrupted by SIGUSR1. * */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "posixtest.h" #define NAMESIZE 50 #define MSGSTR "0123456789" #define BUFFER 40 #define MAXMSG 10 #define INTHREAD 0 #define INMAIN 1 int sem; /* manual semaphore */ int in_handler; /* flag to indicate signal handler was called */ int errno_eintr; /* flag to indicate that errno was set to eintr when mq_timedsend() was interruped. */ /* * This handler is just used to catch the signal and stop sleep (so the * parent knows the child is still busy sending signals). */ void justreturn_handler(int signo) { /* Indicate that the signal handler was called */ in_handler=1; return; } void *a_thread_func() { int i; struct sigaction act; char gqname[NAMESIZE]; mqd_t gqueue; const char *msgptr = MSGSTR; struct mq_attr attr; struct timespec ts; /* Set up handler for SIGUSR1 */ act.sa_handler=justreturn_handler; act.sa_flags=0; sigemptyset(&act.sa_mask); sigaction(SIGUSR1, &act, 0); /* Set up mq */ sprintf(gqname, "/mq_timedsend_12-1_%d", getpid()); attr.mq_maxmsg = MAXMSG; attr.mq_msgsize = BUFFER; gqueue = mq_open(gqname, O_CREAT |O_RDWR, S_IRUSR | S_IWUSR, &attr); if (gqueue == (mqd_t)-1) { perror("mq_open() did not return success"); pthread_exit((void*)PTS_UNRESOLVED); return NULL; } /* mq_timedsend will block for 10 seconds when it waits */ ts.tv_sec=time(NULL)+10; ts.tv_nsec=0; /* Tell main it can go ahead and start sending SIGUSR1 signal */ sem = INMAIN; for (i=0; i= BUFFER. */ #include #include #include #include #include #include #include #include #include "posixtest.h" #define NAMESIZE 50 #define MSGSTR "0123456789" #define BUFFER 40 #define MAXMSG 10 int main() { char qname[NAMESIZE], msgrcd[BUFFER]; const char *msgptr = MSGSTR; struct timespec ts; mqd_t queue; struct mq_attr attr; int unresolved=0, failure=0; unsigned pri; sprintf(qname, "/mq_timedsend_1-1_%d", getpid()); attr.mq_msgsize = BUFFER; attr.mq_maxmsg = MAXMSG; queue = mq_open(qname, O_CREAT |O_RDWR, S_IRUSR | S_IWUSR, &attr); if (queue == (mqd_t)-1) { perror("mq_open() did not return success"); return PTS_UNRESOLVED; } ts.tv_sec=time(NULL)+1; ts.tv_nsec=0; if (mq_timedsend(queue, msgptr, strlen(msgptr), 1, &ts) != 0) { perror("mq_timedsend() did not return success"); failure=1; } if (mq_receive(queue, msgrcd, BUFFER, &pri) == -1) { perror("mq_receive() returned failure"); failure=1; } if (strncmp(msgptr, msgrcd, strlen(msgptr)) != 0) { printf("FAIL: sent %s received %s\n", msgptr, msgrcd); failure = 1; } if (mq_close(queue) != 0) { perror("mq_close() did not return success"); unresolved=1; } if (mq_unlink(qname) != 0) { perror("mq_unlink() did not return success"); unresolved=1; } if (failure==1) { printf("Test FAILED\n"); return PTS_FAIL; } if (unresolved==1) { printf("Test UNRESOLVED\n"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/mq_timedsend/9-1.c0100644000000000000000000000471010336125321022427 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * Test that mq_timedsend() returns -1 on failure, no message is queued, and * errno is set. * The failure case chosen is an invalid message queue descriptor. * * 3/13/03 - Added fix from Gregoire Pichon for specifying an attr * with a mq_maxmsg >= BUFFER. * */ #include #include #include #include #include #include #include #include #include #include "posixtest.h" #define NAMESIZE 50 #define MSGSTR "0123456789" #define BUFFER 40 int main() { char qname[NAMESIZE], msgrcd[BUFFER]; const char *msgptr = MSGSTR; struct timespec ts; mqd_t queue; struct mq_attr attr; int unresolved=0, failure=0; unsigned pri; sprintf(qname, "/mq_timedsend_9-1_%d", getpid()); attr.mq_msgsize = BUFFER; attr.mq_maxmsg = BUFFER; queue = mq_open(qname, O_CREAT |O_RDWR | O_NONBLOCK, S_IRUSR | S_IWUSR, &attr); if (queue == (mqd_t)-1) { perror("mq_open() did not return success"); return PTS_UNRESOLVED; } // Verify mq_timedsend() returns -1 ts.tv_sec=time(NULL)+1; ts.tv_nsec=0; if (mq_timedsend(queue+1, msgptr, strlen(msgptr), 1, &ts) != -1) { printf("mq_timedsend() did not return -1 on invalid queue\n"); failure=1; } // Verify errno is set if (errno != EBADF) { printf("errno was not set on invalid queue\n"); failure = 1; } // Verify message was not queued (cannot be received) if (mq_receive(queue, msgrcd, BUFFER, &pri) != -1) { if (strcmp(msgptr, msgrcd) == 0) { printf("Message ended up being sent\n"); failure = 1; } else { printf("Error with mq_receive()\n"); unresolved = 1; } } if (mq_close(queue) != 0) { perror("mq_close() did not return success"); unresolved=1; } if (mq_unlink(qname) != 0) { perror("mq_unlink() did not return success"); unresolved=1; } if (failure==1) { printf("Test FAILED\n"); return PTS_FAIL; } if (unresolved==1) { printf("Test UNRESOLVED\n"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/mq_timedsend/20-1.c0100644000000000000000000000527210035502500022476 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * Test that mq_timedsend() will return ETIMEDOUT if O_NONBLOCK * was not set when mq_open() was called and the message could * not be added to the queue because it timed out. * * Test by sending messages until a block happens and then verify * that mq_timedsend() times out. */ #include #include #include #include #include #include #include #include #include #include #include #include #include "posixtest.h" #define NAMESIZE 50 #define MSGSTR "0123456789" #define TIMEOUT 5 #define DELTA 1 #define BUFFER 40 #define MAXMSG 5 char gqname[NAMESIZE]; mqd_t gqueue; void testfailed_handler(int signo) { printf("Timeout never happened\n"); printf("Test FAILED\n"); mq_close(gqueue); mq_unlink(gqname); exit(PTS_FAIL); } int main() { char *msgptr=MSGSTR; struct timespec ts; struct sigaction act; time_t currsec; struct mq_attr attr; int failure=0, i, maxreached=0; sprintf(gqname, "/mq_timedsend_20-1_%d", getpid()); attr.mq_msgsize = BUFFER; attr.mq_maxmsg = MAXMSG; gqueue = mq_open(gqname, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR, &attr); if (gqueue == (mqd_t)-1) { perror("mq_open() did not return success"); printf("Test UNRESOLVED\n"); return PTS_UNRESOLVED; } currsec = time(NULL); ts.tv_sec=currsec+TIMEOUT; ts.tv_nsec=0; /* * If timeout never happens, set up an alarm that will go off * after TIMEOUT+1 seconds and call a handler to end the test */ act.sa_handler=testfailed_handler; act.sa_flags=0; sigemptyset(&act.sa_mask); sigaction(SIGALRM, &act, 0); alarm(TIMEOUT+1); for (i=0; i ts.tv_sec+DELTA) { printf("Timeout lasted too long\n"); printf("Test FAILED\n"); return PTS_FAIL; } if (failure==1) { printf("Test FAILED\n"); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/mq_timedsend/11-1.c0100644000000000000000000000341610035502500022474 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * Test that mq_timedsend() returns errno == EBADF if mqdes is not a valid * message queue descriptor. */ #include #include #include #include #include #include #include #include #include #include "posixtest.h" #define NAMESIZE 50 #define MSGSTR "0123456789" int main() { char qname[NAMESIZE]; const char *msgptr = MSGSTR; struct timespec ts; mqd_t queue; int unresolved=0, failure=0; sprintf(qname, "/mq_timedsend_11-1_%d", getpid()); queue = mq_open(qname, O_CREAT |O_RDWR, S_IRUSR | S_IWUSR, NULL); if (queue == (mqd_t)-1) { perror("mq_open() did not return success"); return PTS_UNRESOLVED; } ts.tv_sec=time(NULL)+1; ts.tv_nsec=0; if (mq_timedsend(queue+1, msgptr, strlen(msgptr), 1, &ts) != -1) { printf("mq_timedsend() did not return -1 on invalid queue\n"); failure=1; } if (errno != EBADF) { printf("errno != EBADF\n"); failure = 1; } if (mq_close(queue) != 0) { perror("mq_close() did not return success"); unresolved=1; } if (mq_unlink(qname) != 0) { perror("mq_unlink() did not return success"); unresolved=1; } if (failure==1) { printf("Test FAILED\n"); return PTS_FAIL; } if (unresolved==1) { printf("Test UNRESOLVED\n"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/mq_timedsend/6-1.c0100644000000000000000000000134207632155071022434 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: geoffrey.r.gustafson REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * Since the implementation of the order in which items are placed into * a message queue is undetermined unless Priority Scheduling is enabled, * this test will not be written right now. It needs priority scheduling * to complete. */ #include #include "posixtest.h" int main() { printf("Priority Scheduling needed to make a reliable test case\n"); printf("for this instance. Will not be tested.\n"); return PTS_UNTESTED; } posixtestsuite/conformance/interfaces/mq_timedsend/4-3.c0100644000000000000000000000422310336125321022423 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * Test that msg_prio can be equal to MQ_PRIO_MAX-1. * * 3/13/03 - Added fix from Gregoire Pichon for specifying an attr * with a mq_maxmsg >= BUFFER. * */ #include #include #include #include #include #include #include #include #include #include "posixtest.h" #define NAMESIZE 50 #define MSGSTR "0123456789" #define BUFFER 40 #define MAXMSG 5 int main() { char qname[NAMESIZE], msgrcd[BUFFER]; const char *msgptr = MSGSTR; struct timespec ts; mqd_t queue; struct mq_attr attr; int unresolved=0, failure=0; unsigned pri; sprintf(qname, "/mq_timedsend_4-3_%d", getpid()); attr.mq_msgsize = BUFFER; attr.mq_maxmsg = MAXMSG; queue = mq_open(qname, O_CREAT |O_RDWR, S_IRUSR | S_IWUSR, &attr); if (queue == (mqd_t)-1) { perror("mq_open() did not return success"); return PTS_UNRESOLVED; } ts.tv_sec=time(NULL)+1; ts.tv_nsec=0; if (mq_timedsend(queue, msgptr, strlen(msgptr), MQ_PRIO_MAX-1, &ts) != 0) { perror("mq_timedsend() did not return success"); failure=1; } if (mq_receive(queue, msgrcd, BUFFER, &pri) == -1) { perror("mq_receive() returned failure"); failure=1; } if (strncmp(msgptr, msgrcd, strlen(msgptr)) != 0) { printf("FAIL: sent %s received %s\n", msgptr, msgrcd); failure = 1; } if (mq_close(queue) != 0) { perror("mq_close() did not return success"); unresolved=1; } if (mq_unlink(qname) != 0) { perror("mq_unlink() did not return success"); unresolved=1; } if (failure==1) { printf("Test FAILED\n"); return PTS_FAIL; } if (unresolved==1) { printf("Test UNRESOLVED\n"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/mq_timedsend/10-1.c0100644000000000000000000000412110035502500022465 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * Test that if O_NONBLOCK is set and the message queue is full, mq_timedsend() * will set errno == EAGAIN (subset of 7-1.c). */ #include #include #include #include #include #include #include #include #include #include #include "posixtest.h" #define NAMESIZE 50 #define MESSAGESIZE 50 #define BUFFER 100 #define MAXMSG 5 int main() { char qname[NAMESIZE]; char msgptr[MESSAGESIZE]; struct timespec ts; struct mq_attr attr; mqd_t queue; int unresolved=0, failure=0, i, maxreached=0; sprintf(qname, "/mq_timedsend_10-1_%d", getpid()); attr.mq_msgsize = BUFFER; attr.mq_maxmsg = MAXMSG; queue = mq_open(qname, O_CREAT | O_RDWR | O_NONBLOCK, S_IRUSR | S_IWUSR, &attr); if (queue == (mqd_t)-1) { perror("mq_open() did not return success"); return PTS_UNRESOLVED; } ts.tv_sec=time(NULL)+1; ts.tv_nsec=0; for (i=0; i= MQ_PRIO_MAX or < 0 (<0 N/A * for an unsigned, so not tested). */ #include #include #include #include #include #include #include #include #include #include #include "posixtest.h" #define NAMESIZE 50 #define MSGSTR "0123456789" #define NUMINVALID 3 static unsigned invalidpri[NUMINVALID] = { MQ_PRIO_MAX, MQ_PRIO_MAX+1, MQ_PRIO_MAX+5 }; int main() { char qname[NAMESIZE]; const char *msgptr = MSGSTR; struct timespec ts; mqd_t queue; int unresolved=0, failure=0, i; sprintf(qname, "/mq_timedsend_13-1_%d", getpid()); queue = mq_open(qname, O_CREAT |O_RDWR, S_IRUSR | S_IWUSR, NULL); if (queue == (mqd_t)-1) { perror("mq_open() did not return success"); return PTS_UNRESOLVED; } ts.tv_sec=time(NULL)+1; ts.tv_nsec=0; for (i=0; i= BUFFER. * */ #include #include #include #include #include #include #include #include #include "posixtest.h" #define NAMESIZE 50 #define MSG1 "1234567890" #define PRI1 10 #define MSG2 "234567890" #define PRI2 8 #define MSG3 "34567890" #define PRI3 2 #define MSG4 "4567890" #define PRI4 2 #define MSG5 "567890" #define PRI5 1 #define BUFFER 40 #define MAXMSG 10 int main() { char qname[NAMESIZE], msgrcd[BUFFER]; const char *msgptr1 = MSG1; const char *msgptr2 = MSG2; const char *msgptr3 = MSG3; const char *msgptr4 = MSG4; const char *msgptr5 = MSG5; struct timespec ts; mqd_t queue; struct mq_attr attr; int unresolved=0, failure=0; unsigned pri; sprintf(qname, "/mq_timedsend_3-2_%d", getpid()); attr.mq_msgsize = BUFFER; attr.mq_maxmsg = BUFFER; queue = mq_open(qname, O_CREAT |O_RDWR, S_IRUSR | S_IWUSR, &attr); if (queue == (mqd_t)-1) { perror("mq_open() did not return success"); return PTS_UNRESOLVED; } ts.tv_sec=time(NULL)+1; ts.tv_nsec=0; if (mq_timedsend(queue, msgptr3, strlen(msgptr3), PRI3, &ts) != 0) { perror("mq_timedsend() did not return success"); printf("error sending %s\n", msgptr3); failure=1; } ts.tv_sec++; if (mq_timedsend(queue, msgptr1, strlen(msgptr1), PRI1, &ts) != 0) { perror("mq_timedsend() did not return success"); printf("error sending %s\n", msgptr1); failure=1; } ts.tv_sec++; if (mq_timedsend(queue, msgptr4, strlen(msgptr4), PRI4, &ts) != 0) { perror("mq_timedsend() did not return success"); printf("error sending %s\n", msgptr4); failure=1; } ts.tv_sec++; if (mq_timedsend(queue, msgptr2, strlen(msgptr2), PRI2, &ts) != 0) { perror("mq_timedsend() did not return success"); printf("error sending %s\n", msgptr2); failure=1; } ts.tv_sec++; if (mq_timedsend(queue, msgptr5, strlen(msgptr5), PRI5, &ts) != 0) { perror("mq_timedsend() did not return success"); printf("error sending %s\n", msgptr5); failure=1; } if (mq_receive(queue, msgrcd, BUFFER, &pri) == -1) { perror("mq_receive() returned failure"); unresolved=1; } if (strncmp(msgptr1, msgrcd, strlen(msgptr1)) != 0) { printf("FAIL: sent %s received %s\n", msgptr1, msgrcd); failure = 1; } if (mq_receive(queue, msgrcd, BUFFER, &pri) == -1) { perror("mq_receive() returned failure"); unresolved=1; } if (strncmp(msgptr2, msgrcd, strlen(msgptr2)) != 0) { printf("FAIL: sent %s received %s\n", msgptr2, msgrcd); failure = 1; } if (mq_receive(queue, msgrcd, BUFFER, &pri) == -1) { perror("mq_receive() returned failure"); unresolved=1; } if (strncmp(msgptr3, msgrcd, strlen(msgptr3)) != 0) { printf("FAIL: sent %s received %s\n", msgptr3, msgrcd); failure = 1; } if (mq_receive(queue, msgrcd, BUFFER, &pri) == -1) { perror("mq_receive() returned failure"); unresolved=1; } if (strncmp(msgptr4, msgrcd, strlen(msgptr4)) != 0) { printf("FAIL: sent %s received %s\n", msgptr4, msgrcd); failure = 1; } if (mq_receive(queue, msgrcd, BUFFER, &pri) == -1) { perror("mq_receive() returned failure"); unresolved=1; } if (strncmp(msgptr5, msgrcd, strlen(msgptr5)) != 0) { printf("FAIL: sent %s received %s\n", msgptr5, msgrcd); failure = 1; } if (mq_close(queue) != 0) { perror("mq_close() did not return success"); unresolved=1; } if (mq_unlink(qname) != 0) { perror("mq_unlink() did not return success"); unresolved=1; } if (failure==1) { printf("Test FAILED\n"); return PTS_FAIL; } if (unresolved==1) { printf("Test UNRESOLVED\n"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/mq_timedsend/7-1.c0100644000000000000000000000540110336125321022423 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * Test that if O_NONBLOCK is set and the message queue is full, mq_timedsend() * will just return an error message and the message will not be queued. * * Test by sending messages with increasing priority number until a failure * is received. Then test that the message just sent (highest priority) is * not the one received. * * 3/13/03 - Added fix from Gregoire Pichon for specifying an attr * with a mq_msgsize >= BUFFER. * */ #include #include #include #include #include #include #include #include #include #include #include "posixtest.h" #define NAMESIZE 50 #define MESSAGESIZE 50 #define MSGSTR "0123456789" #define BUFFER 40 #define MAXMSG 5 int main() { char qname[NAMESIZE], msgrcd[BUFFER]; char msgptr[MESSAGESIZE]; struct timespec ts; struct mq_attr attr; mqd_t queue; int unresolved=0, failure=0, spri=1, i, maxreached=0; unsigned pri; sprintf(qname, "/mq_timedsend_7-1_%d", getpid()); attr.mq_msgsize = BUFFER; attr.mq_maxmsg = MAXMSG; queue = mq_open(qname, O_CREAT | O_RDWR | O_NONBLOCK, S_IRUSR | S_IWUSR, &attr); if (queue == (mqd_t)-1) { perror("mq_open() did not return success"); return PTS_UNRESOLVED; } ts.tv_sec=time(NULL); ts.tv_nsec=0; for (i=0; i mq_timedsend() places the message msg_ptr points to into message queue mqdes mq_timedsend() will fail if msg_len, the message length, is not less than or equal to mq_attr->mq_msgsize. mq_timedsend() will insert the message into the message queue according to msg_prio (if the message queue is not full): - Larger msg_prio values mean the message is inserted before those with lower values. - For messages with equal msg_prio values, the message is inserted after those. msg_prio must be less than MQ_PRIO_MAX If the message queue pointed to by msg_ptr is full and O_NONBLOCK is not set, then mq_timedsend() will block until it can place the message in the queue or until a signal interrupts mq_timedsend() or when the time specified by abs_timeout expires. abs_timeout refers to the absolute time at which the timeout will expire (current time meets or exceeds that time). If there are greater than one threads which are waiting to place a message in the message queue, the thread which will be able to place its message when space is available is the one with the greatest priority that has been waiting the longest if Priority Scheduling is supported. If not, then it is unspecified which thread is able to place its message. If the message queue pointed to by msg_ptr is full and O_NONBLOCK is set, then mq_timedsend() will just return an error and the message will not be queued. mq_timedsend() will return 0 on success. mq_timedsend() will return -1 on failure, no message will be queued, and errno will be set. mq_timedsend() will return EAGAIN if O_NONBLOCK is set and the message queue is full mq_timedsend() will return EBADF if mqdes is not a valid message queue descriptor that is also open for writing mq_timedsend() will return EINTR if it is interrupted by a signal mq_timedsend() will return EINVAL if msg_prio wasn't in the valid range mq_timedsend() will return EMSGSIZE if msg_len is greater than the message queues message size attribute If abs_timeout has already passed at the time mq_timedsend is called, then the timeout shall expire. If Timers is supported, then abs_timeout is based on CLOCK_REALTIME. Otherwise, the timeout is based on the system clock (time() function). The timeout has the same resolution as the clock it's based on. If the queue already has room, then mq_timedsend() should never fail. Also, in this case, abs_timeout doesn't need to be checked for validity. mq_timedsend() will return EINVAL if the message queue was full and abs_timeout had a tv_nsec field less than 0 or greater than or equal to 1000 million. mq_timedsend() will return ETIMEDOUT if O_NONBLOCK was not set when mq_open() was called for the message queue, but the message could not be added to the queue because it timed out posixtestsuite/conformance/interfaces/mq_timedsend/coverage.txt0100644000000000000000000000113510044130265024306 0ustar rootrootThis file defines the coverage for mq_timedsend. Note: Most tests in mq_timedsend() are cut and pastes from mq_send. Due to the structure of the test suite, there wasn't a better, quick way I could find to reduce this redundancy. Note 2: These tests assume that the TMR functionality isn't implemented. If it is, the time() calls should be replaced with clock_gettime(). ASSERTION COVERED? 1 YES 2 YES 3 YES 4 YES 5 YES 6 WON'T - won't test b/c TBD if Priority Scheduling is enabled 7 YES 8 YES 9 YES 10 YES 11 YES 12 YES 13 YES 14 YES 15 YES 16 YES 17 WON'T 18 YES 19 YES 20 YES posixtestsuite/conformance/interfaces/mq_timedsend/5-3.c0100644000000000000000000000706710035502500022427 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * Test that if the message queue is full and O_NONBLOCK is not set, * mq_timedsend() will block until abs_timeout is reached. * * Test by sending messages in a child process until the message queue is full. * At this point, the child should be blocking on sending. Then, have the * parent wait for the timeout and return pass when the next message is sent * to the message queue. */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include "posixtest.h" #define NAMESIZE 50 #define MSGSTR "0123456789" #define BUFFER 40 #define MAXMSG 5 #define TIMEOUT 7 #define CHILDPASS 1 #define CHILDFAIL 0 char gqname[NAMESIZE]; mqd_t gqueue; /* * This handler is just used to catch the signal and stop sleep (so the * parent knows the child is still busy sending signals). */ void stopsleep_handler(int signo) { return; } int main() { int pid; struct mq_attr attr; const char *msgptr = MSGSTR; sprintf(gqname, "/mq_timedsend_5-3_%d", getpid()); attr.mq_maxmsg = MAXMSG; attr.mq_msgsize = BUFFER; gqueue = mq_open(gqname, O_CREAT |O_RDWR, S_IRUSR | S_IWUSR, &attr); if (gqueue == (mqd_t)-1) { perror("mq_open() did not return success"); return PTS_UNRESOLVED; } if ((pid = fork()) == 0) { /* child here */ int i, sig; struct timespec ts; sigset_t mask; /* wait for parent to set up handler */ sigemptyset(&mask); sigaddset(&mask, SIGUSR1); sigprocmask(SIG_BLOCK,&mask,NULL); sigwait(&mask, &sig); /* child should block in < TIMEOUT seconds */ ts.tv_sec=time(NULL)+TIMEOUT; ts.tv_nsec=0; for (i=0; i= BUFFER. * */ #include #include #include #include #include #include #include #include #include "posixtest.h" #define NAMESIZE 50 #define MSGSTR "0123456789" #define BUFFER 40 #define MAXMSG 5 int main() { char qname[NAMESIZE], msgrcd[BUFFER]; const char *msgptr = MSGSTR; struct timespec ts; mqd_t queue; struct mq_attr attr; int unresolved=0, ret; unsigned pri; sprintf(qname, "/mq_timedsend_8-1_%d", getpid()); attr.mq_msgsize = BUFFER; attr.mq_maxmsg = MAXMSG; queue = mq_open(qname, O_CREAT |O_RDWR, S_IRUSR | S_IWUSR, &attr); if (queue == (mqd_t)-1) { perror("mq_open() did not return success"); return PTS_UNRESOLVED; } ts.tv_sec=time(NULL)+1; ts.tv_nsec=0; ret = mq_timedsend(queue, msgptr, strlen(msgptr), 1, &ts); if (mq_receive(queue, msgrcd, BUFFER, &pri) == -1) { perror("mq_receive() returned failure"); unresolved=1; } if (strncmp(msgptr, msgrcd, strlen(msgptr)) != 0) { printf("send was unsuccessful: sent %s received %s\n", msgptr, msgrcd); unresolved = 1; } if (mq_close(queue) != 0) { perror("mq_close() did not return success"); unresolved=1; } if (mq_unlink(qname) != 0) { perror("mq_unlink() did not return success"); unresolved=1; } if (unresolved==1) { printf("Test UNRESOLVED\n"); return PTS_UNRESOLVED; } if (ret != 0) { printf("mq_timedsend() did not return 0 on success\n"); printf("Test FAILED\n"); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/mq_timedsend/4-2.c0100644000000000000000000000324510035502500022417 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * Test that msg_prio cannot be equal to MQ_PRIO_MAX. */ #include #include #include #include #include #include #include #include #include #include "posixtest.h" #define NAMESIZE 50 #define MSGSTR "0123456789" int main() { char qname[NAMESIZE]; const char *msgptr = MSGSTR; struct timespec ts; mqd_t queue; int unresolved=0, failure=0; sprintf(qname, "/mq_timedsend_4-2_%d", getpid()); queue = mq_open(qname, O_CREAT |O_RDWR, S_IRUSR | S_IWUSR, NULL); if (queue == (mqd_t)-1) { perror("mq_open() did not return success"); return PTS_UNRESOLVED; } ts.tv_sec=time(NULL)+1; ts.tv_nsec=0; if (mq_timedsend(queue, msgptr, strlen(msgptr), MQ_PRIO_MAX, &ts) == 0) { printf("mq_timedsend() ret success with pri = MQ_PRIO_MAX\n"); failure=1; } if (mq_close(queue) != 0) { perror("mq_close() did not return success"); unresolved=1; } if (mq_unlink(qname) != 0) { perror("mq_unlink() did not return success"); unresolved=1; } if (failure==1) { printf("Test FAILED\n"); return PTS_FAIL; } if (unresolved==1) { printf("Test UNRESOLVED\n"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/mq_timedsend/16-1.c0100644000000000000000000000776710044130265022523 0ustar rootroot/* * Copyright (c) 2004, Intel Corporation. All rights reserved. * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * adam.li@intel.com - 2004-04-29 */ /* * Test that if the message queue is full and O_NONBLOCK is not set, * mq_timedsend() will block until abs_timeout is reached. * * Test by sending messages in a child process until the message queue is full. * At this point, the child should be blocking on sending. Then, have the * parent wait for the timeout and return pass when the next message is sent * to the message queue. * * If Timers is supported, then abs_timeout is based on CLOCK_REALTIME. * Otherwise, the timeout is based on the system clock (time() function). */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include "posixtest.h" #define NAMESIZE 50 #define MSGSTR "0123456789" #define BUFFER 40 #define MAXMSG 5 #define TIMEOUT 7 #define CHILDPASS 1 #define CHILDFAIL 0 char gqname[NAMESIZE]; mqd_t gqueue; /* * This handler is just used to catch the signal and stop sleep (so the * parent knows the child is still busy sending signals). */ void stopsleep_handler(int signo) { return; } int main() { int pid; struct mq_attr attr; const char *msgptr = MSGSTR; sprintf(gqname, "/mq_timedsend_16-1_%d", getpid()); attr.mq_maxmsg = MAXMSG; attr.mq_msgsize = BUFFER; gqueue = mq_open(gqname, O_CREAT |O_RDWR, S_IRUSR | S_IWUSR, &attr); mq_unlink(gqname); if (gqueue == (mqd_t)-1) { perror("mq_open() did not return success"); return PTS_UNRESOLVED; } if ((pid = fork()) == 0) { /* child here */ int i, sig; struct timespec ts; sigset_t mask; /* wait for parent to set up handler */ sigemptyset(&mask); sigaddset(&mask, SIGUSR1); sigprocmask(SIG_BLOCK,&mask,NULL); sigwait(&mask, &sig); /* child should block in < TIMEOUT seconds */ #ifdef _POSIX_TIMERS printf("Using CLOCK_REALTIME\n"); clock_gettime(CLOCK_REALTIME, &ts); ts.tv_sec += TIMEOUT; #else ts.tv_sec=time(NULL)+TIMEOUT; #endif ts.tv_nsec=0; for (i=0; imq_msgsize. */ #include #include #include #include #include #include #include #include #include "posixtest.h" #define NAMESIZE 50 #define MSGSTR "01234567890123456789" #define MSGSIZE 10 // < strlen(MSGSTR) int main() { char qname[NAMESIZE]; const char *msgptr = MSGSTR; struct timespec ts; mqd_t queue; int unresolved=0, failure=0; struct mq_attr attr; sprintf(qname, "/mq_timedsend_2-1_%d", getpid()); attr.mq_msgsize = MSGSIZE; attr.mq_maxmsg = MSGSIZE; queue = mq_open(qname, O_CREAT |O_RDWR, S_IRUSR | S_IWUSR, &attr); if (queue == (mqd_t)-1) { perror("mq_open() did not return success"); return PTS_UNRESOLVED; } ts.tv_sec=time(NULL)+1; ts.tv_nsec=0; if (mq_timedsend(queue, msgptr, strlen(msgptr), 1, &ts) == 0) { printf("mq_timedsend() ret success w/msg_len>=mq_msgsize\n"); failure=1; } if (mq_close(queue) != 0) { perror("mq_close() did not return success"); unresolved=1; } if (mq_unlink(qname) != 0) { perror("mq_unlink() did not return success"); unresolved=1; } if (failure==1) { printf("Test FAILED\n"); return PTS_FAIL; } if (unresolved==1) { printf("Test UNRESOLVED\n"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/mq_timedsend/3-1.c0100644000000000000000000001047010336125321022421 0ustar rootroot/* * Copyright (c) 2003, Intel Corporation. All rights reserved. * Created by: julie.n.fleischer REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. */ /* * Test that mq_timedsend() inserts messages into the message queue according * to the priority given. * Test by inserting multiple messages into the queue not in priority order. * Ensure messages are received in priority order. * * 3/13/03 - Added fix from Gregoire Pichon for specifying an attr * with a mq_maxmsg >= BUFFER. * */ #include #include #include #include #include #include #include #include #include "posixtest.h" #define NAMESIZE 50 #define MSG1 "1234567890" #define PRI1 10 #define MSG2 "234567890" #define PRI2 8 #define MSG3 "34567890" #define PRI3 6 #define MSG4 "4567890" #define PRI4 2 #define MSG5 "567890" #define PRI5 1 #define BUFFER 40 #define MAXMSG 10 int main() { char qname[NAMESIZE], msgrcd[BUFFER]; const char *msgptr1 = MSG1; const char *msgptr2 = MSG2; const char *msgptr3 = MSG3; const char *msgptr4 = MSG4; const char *msgptr5 = MSG5; struct timespec ts; struct mq_attr attr; mqd_t queue; int unresolved=0, failure=0; unsigned pri; sprintf(qname, "/mq_timedsend_3-1_%d", getpid()); attr.mq_msgsize = BUFFER; attr.mq_maxmsg = MAXMSG; queue = mq_open(qname, O_CREAT |O_RDWR, S_IRUSR | S_IWUSR, &attr); if (queue == (mqd_t)-1) { perror("mq_open() did not return success"); return PTS_UNRESOLVED; } ts.tv_sec=time(NULL)+1; ts.tv_nsec=0; if (mq_timedsend(queue, msgptr3, strlen(msgptr3), PRI3, &ts) != 0) { perror("mq_timedsend() did not return success"); failure=1; } ts.tv_sec++; if (mq_timedsend(queue, msgptr1, strlen(msgptr1), PRI1, &ts) != 0) { perror("mq_timedsend() did not return success"); failure=1; } ts.tv_sec++; if (mq_timedsend(queue, msgptr4, strlen(msgptr4), PRI4, &ts) != 0) { perror("mq_timedsend() did not return success"); failure=1; } ts.tv_sec++; if (mq_timedsend(queue, msgptr2, strlen(msgptr2), PRI2, &ts) != 0) { perror("mq_timedsend() did not return success"); failure=1; } ts.tv_sec++; if (mq_timedsend(queue, msgptr5, strlen(msgptr5), PRI5, &ts) != 0) { perror("mq_timedsend() did not return success"); failure=1; } if (mq_receive(queue, msgrcd, BUFFER, &pri) == -1) { perror("mq_receive() returned failure"); failure=1; } if (strncmp(msgptr1, msgrcd, strlen(msgptr1)) != 0) { printf("FAIL: expected %s received %s\n", msgptr1, msgrcd); failure = 1; } if (mq_receive(queue, msgrcd, BUFFER, &pri) == -1) { perror("mq_receive() returned failure"); failure=1; } if (strncmp(msgptr2, msgrcd, strlen(msgptr2)) != 0) { printf("FAIL: expected %s received %s\n", msgptr2, msgrcd); failure = 1; } if (mq_receive(queue, msgrcd, BUFFER, &pri) == -1) { perror("mq_receive() returned failure"); failure=1; } if (strncmp(msgptr3, msgrcd, strlen(msgptr3)) != 0) { printf("FAIL: expected %s received %s\n", msgptr3, msgrcd); failure = 1; } if (mq_receive(queue, msgrcd, BUFFER, &pri) == -1) { perror("mq_receive() returned failure"); failure=1; } if (strncmp(msgptr4, msgrcd, strlen(msgptr4)) != 0) { printf("FAIL: expected %s received %s\n", msgptr4, msgrcd); failure = 1; } if (mq_receive(queue, msgrcd, BUFFER, &pri) == -1) { perror("mq_receive() returned failure"); failure=1; } if (strncmp(msgptr5, msgrcd, strlen(msgptr5)) != 0) { printf("FAIL: expected %s received %s\n", msgptr5, msgrcd); failure = 1; } if (mq_close(queue) != 0) { perror("mq_close() did not return success"); unresolved=1; } if (mq_unlink(qname) != 0) { perror("mq_unlink() did not return success"); unresolved=1; } if (failure==1) { printf("Test FAILED\n"); return PTS_FAIL; } if (unresolved==1) { printf("Test UNRESOLVED\n"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/pthread_mutex_lock/0040755000000000000000000000000010515625217023176 5ustar rootrootposixtestsuite/conformance/interfaces/pthread_mutex_lock/5-1.c0100644000000000000000000002110210050631762023631 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * * This sample test aims to check the following assertion: * If a signal is delivered to a thread waiting for a mutex, * upon return from the signal handler the thread resumes * waiting for the mutex as if it had not been interrupted. * The steps are: * -> Create a child thread * -> Child registers a signal handler * -> Child tries to lock a mutex owned by another thread * -> A signal is sent to the child * -> Check that the signal handler executes and then that the thread still waits for the mutex. * -> Release the mutex and check that the child takes it. * -> Do all of this several times with different mutex attributes * * The test shall be considered to FAIL if it hangs! * a call to alarm() might eventually be added but this is a problem under high * system stress. */ /* * - adam.li@intel.com 2004-05-13 * Add to PTS. Please refer to http://nptl.bullopensource.org/phpBB/ * for general information */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /* We enable the following line to have mutex attributes defined */ #ifndef WITHOUT_XOPEN #define _XOPEN_SOURCE 600 #endif /********************************************************************************************/ /****************************** standard includes *****************************************/ /********************************************************************************************/ #include #include #include #include #include #include #include #include /********************************************************************************************/ /****************************** Test framework *****************************************/ /********************************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /********************************************************************************************/ /********************************** Configuration ******************************************/ /********************************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif /********************************************************************************************/ /*********************************** Test case *****************************************/ /********************************************************************************************/ pthread_mutex_t mtx[5]; sem_t semsig, semstart; int ctrl=0; /********* signal handler **********/ void sighdl(int sig) { if (sem_post(&semsig)) { UNRESOLVED(errno, "Sem_post in signal handler"); } } /********** thread *********/ void * threaded(void * arg) { int ret, i; /* We register the signal handler */ struct sigaction sa; sigemptyset (&sa.sa_mask); sa.sa_flags = 0; sa.sa_handler = sighdl; if ((ret = sigaction (SIGUSR1, &sa, NULL))) { UNRESOLVED(ret, "Unable to register signal handler"); } /* Start the real work */ for (i=0; i<5; i++) /* We'll do this with the 5 kinds of mutex */ { if (sem_post(&semstart)) /* Tell the father we are ready */ { UNRESOLVED(errno, "Sem post in thread"); } if ((ret = pthread_mutex_lock(&mtx[i]))) /* Attempt to lock the mutex */ { UNRESOLVED(ret, "Mutex lock failed in thread"); } ctrl++; /* Notify the main we have passed the lock */ if ((ret = pthread_mutex_unlock(&mtx[i]))) /* We don't need the mutex anymore */ { UNRESOLVED(ret, "Mutex unlock failed in thread"); } } return NULL; } /********* main ********/ int main (int argc, char * argv[]) { int ret, i, j; pthread_t th; pthread_mutexattr_t ma[4], *pma[5]; pma[4]=NULL; output_init(); /* Initialize the mutex attributes */ for (i=0; i<4; i++) { pma[i]=&ma[i]; if ((ret = pthread_mutexattr_init(pma[i]))) { UNRESOLVED(ret, "pthread_mutexattr_init"); } } #ifndef WITHOUT_XOPEN if ((ret = pthread_mutexattr_settype(pma[0], PTHREAD_MUTEX_NORMAL))) { UNRESOLVED(ret, "pthread_mutexattr_settype (normal)"); } if ((ret = pthread_mutexattr_settype(pma[1], PTHREAD_MUTEX_ERRORCHECK))) { UNRESOLVED(ret, "pthread_mutexattr_settype (errorcheck)"); } if ((ret = pthread_mutexattr_settype(pma[2], PTHREAD_MUTEX_RECURSIVE))) { UNRESOLVED(ret, "pthread_mutexattr_settype (recursive)"); } if ((ret = pthread_mutexattr_settype(pma[3], PTHREAD_MUTEX_DEFAULT))) { UNRESOLVED(ret, "pthread_mutexattr_settype (default)"); } #if VERBOSE >1 output("Mutex attributes NORMAL,ERRORCHECK,RECURSIVE,DEFAULT initialized\n"); #endif #else #if VERBOSE > 0 output("Mutex attributes NORMAL,ERRORCHECK,RECURSIVE,DEFAULT unavailable\n"); #endif #endif /* Initialize the 5 mutex */ for (i=0; i<5; i++) { if ((ret = pthread_mutex_init(&mtx[i], pma[i]))) { UNRESOLVED(ret, "pthread_mutex_init failed")} if ((ret = pthread_mutex_lock(&mtx[i]))) { UNRESOLVED(ret, "Initial pthread_mutex_lock failed")} } #if VERBOSE >1 output("Mutex objects are initialized\n"); #endif /* We don't need the mutex attribute objects anymore */ for (i=0; i<4; i++) { if ((ret = pthread_mutexattr_destroy(pma[i]))) { UNRESOLVED(ret, "pthread_mutexattr_destroy"); } } /* Initialize the semaphores */ if (sem_init(&semsig, 0, 1)) { UNRESOLVED(errno, "Sem init (1) failed"); } if (sem_init(&semstart, 0, 0)) { UNRESOLVED(errno, "Sem init (0) failed"); } #if VERBOSE >1 output("Going to create the child thread\n"); #endif /* Start the child */ if ((ret = pthread_create(&th, NULL, threaded, NULL))) { UNRESOLVED(ret, "Unable to create the thread"); } #if VERBOSE >1 output("Child created\n"); #endif /* Monitor the child */ for (i=0; i<5; i++) /* We will do this for the 5 kinds of mutex */ { if (sem_wait(&semstart)) /* Wait for the thread to be ready */ { UNRESOLVED(errno, "Unable to wait for the child"); } #if VERBOSE >1 output("Child is ready for iteration %i\n", i+1); #endif ctrl=0; /* init the ctrl var */ /* Send some signals to the thread */ for (j=0; j<10; j++) { if ((ret = sem_wait(&semsig))) { UNRESOLVED(errno, "Sem_wait failed from the signal handler"); } sched_yield(); /* Let the child do its stuff - might be a nanosleep here*/ if ((ret = pthread_kill (th, SIGUSR1))) { UNRESOLVED(ret, "Pthread_kill failed"); } } #if VERBOSE >1 output("Child was killed 10 times\n"); #endif /* Now check the thread is still waiting for the mutex */ if (ctrl != 0) { FAILED("Killed child passed the pthread_mutex_lock without owning it"); } #if VERBOSE >1 output("Control was OK\n"); #endif /* Unlock the mutex so the thread can proceed to the next one */ if ((ret = pthread_mutex_unlock(&mtx[i]))) { UNRESOLVED(ret, "Mutex unlock in main failed"); } } #if VERBOSE >1 output("The test has passed, we are now going to clean up everything.\n"); #endif /* Clean everything: the test has passed */ if ((ret = pthread_join(th, NULL))) { UNRESOLVED(ret, "Unable to join the child"); } for (i=0; i<5; i++) { if ((ret = pthread_mutex_destroy(&mtx[i]))) { UNRESOLVED(ret, "Unable to finally destroy a mutex"); } } if (sem_destroy(&semstart)) { UNRESOLVED(errno, "Unable to destroy semstart semaphore"); } if (sem_destroy(&semsig)) { UNRESOLVED(errno, "Unable to destroy semsig semaphore"); } PASSED; } posixtestsuite/conformance/interfaces/pthread_mutex_lock/4-1.c0100644000000000000000000002000710050631762023633 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertion: * * If the mutex type is PTHREAD_MUTEX_RECURSIVE, * then the mutex maintains the concept of a lock count. * When a thread successfully acquires a mutex for the first time, * the lock count is set to one. Every time a thread relocks this mutex, * the lock count is incremented by one. * Each time the thread unlocks the mutex, * the lock count is decremented by one. * When the lock count reaches zero, * the mutex becomes available and others threads can acquire it. * The steps are: * ->Create a mutex with recursive attribute * ->Create a threads * ->Parent locks the mutex twice, unlocks once. * ->Child attempts to lock the mutex. * ->Parent unlocks the mutex. * ->Parent unlocks the mutex (shall fail) * ->Child unlocks the mutex. */ /* * - adam.li@intel.com 2004-05-13 * Add to PTS. Please refer to http://nptl.bullopensource.org/phpBB/ * for general information */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /* We need the setrlimit() function from X/OPEN standard */ #ifndef WITHOUT_XOPEN #define _XOPEN_SOURCE 600 /********************************************************************************************/ /****************************** standard includes *****************************************/ /********************************************************************************************/ #include #include #include #include #include #include /* for synchronization */ #include /********************************************************************************************/ /****************************** Test framework *****************************************/ /********************************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /********************************************************************************************/ /********************************** Configuration ******************************************/ /********************************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif /********************************************************************************************/ /*********************************** Test case *****************************************/ /********************************************************************************************/ pthread_mutex_t mtx; sem_t sem; /** child thread function **/ void * threaded(void * arg) { int ret; /* Try to lock the mutex once. The call must fail here. */ ret = pthread_mutex_trylock(&mtx); if (ret == 0) { FAILED("Child first trylock succeeded"); } #if VERBOSE >1 output("[thrd] Try to lock the mutex.... failed (normal)\n"); #endif /* Free the parent thread and lock the mutex (must success)*/ if ((ret = sem_post(&sem))) { UNRESOLVED(errno, "1st post sem in child failed"); } if ((ret = pthread_mutex_lock(&mtx))) { UNRESOLVED(ret, "Child lock failed"); } #if VERBOSE >1 output("[thrd] Successfully locked the mutex\n"); #endif /* Wait for the parent to let us go on */ if ((ret = sem_post(&sem))) { UNRESOLVED(errno, "2nd post sem in child failed"); } /* Unlock and exit */ if ((ret = pthread_mutex_unlock(&mtx))) { UNRESOLVED(ret, "Unlock in child failed"); } #if VERBOSE >1 output("[thrd] Unlocked the mutex, ready to terminate.\n"); #endif return NULL; } /** parent thread function **/ int main(int argc, char * argv[]) { int ret; int i; pthread_mutexattr_t ma; pthread_t child; output_init(); #if VERBOSE >1 output("Initialize the PTHREAD_MUTEX_RECURSIVE mutex\n"); #endif /* Initialize the semaphore */ if ((ret = sem_init(&sem, 0, 0))) { UNRESOLVED(ret, "Sem init failed"); } /* We initialize the recursive mutex */ if ((ret = pthread_mutexattr_init(&ma))) { UNRESOLVED(ret, "Mutex attribute init failed"); } if ((ret = pthread_mutexattr_settype(&ma, PTHREAD_MUTEX_RECURSIVE))) { UNRESOLVED(ret, "Set type RECURSIVE failed"); } if ((ret = pthread_mutex_init(&mtx, &ma))) { UNRESOLVED(ret, "Recursive mutex init failed"); } if ((ret = pthread_mutexattr_destroy(&ma))) { UNRESOLVED(ret, "Mutex attribute destroy failed"); } /* -- The mutex is now ready for testing -- */ /* First, we lock it twice and unlock once */ if ((ret = pthread_mutex_lock(&mtx))) { UNRESOLVED(ret, "First lock failed"); } if ((ret = pthread_mutex_lock(&mtx))) { FAILED("Second lock failed"); } if ((ret = pthread_mutex_unlock(&mtx))) { FAILED("First unlock failed"); } #if VERBOSE >1 output("The mutex has been locked twice and unlocked once, start the thread now.\n"); #endif /* Here this thread owns the mutex and the internal count is "1" */ /* We create the child thread */ if ((ret = pthread_create(&child, NULL, threaded, NULL))) { UNRESOLVED(ret, "Unable to create child thread"); } /* then wait for child to be ready */ if ((ret = sem_wait(&sem))) { UNRESOLVED(errno, "Wait sem in child failed"); } #if VERBOSE >1 output("[main] unlock the mutex.\n"); #endif /* We can now unlock the mutex */ if ((ret = pthread_mutex_unlock(&mtx))) { FAILED("Second unlock failed"); } /* We wait for the child to lock the mutex */ if ((ret = sem_wait(&sem))) { UNRESOLVED(errno, "Wait sem in child failed"); } /* Then, try to unlock the mutex (owned by the child or unlocked) */ ret = pthread_mutex_unlock(&mtx); if (ret == 0) { FAILED("Unlock of unowned mutex succeeds"); } /* Everything seems OK here */ if ((ret = pthread_join(child, NULL))) { UNRESOLVED(ret, "Child join failed"); } /* Simple loop to double-check */ #if VERBOSE >1 output("[main] joined the thread.\n"); output("Lock & unlock the mutex 50 times.\n"); #endif for (i=0; i<50; i++) { if ((ret = pthread_mutex_lock(&mtx))) { FAILED("Lock failed in loop"); } } for (i=0; i<50; i++) { if ((ret = pthread_mutex_unlock(&mtx))) { FAILED("Unlock failed in loop"); } } ret = pthread_mutex_unlock(&mtx); if (ret == 0) { FAILED("Unlock succeeds after the loop"); } #if VERBOSE >1 output("Everything went OK; destroy the mutex.\n"); #endif /* The test passed, we destroy the mutex */ if ((ret = pthread_mutex_destroy(&mtx))) { UNRESOLVED(ret, "Final mutex destroy failed"); } PASSED; } #else /* WITHOUT_XOPEN */ int main(int argc, char * argv[]) { output_init(); UNTESTED("This test requires XSI features"); } #endif posixtestsuite/conformance/interfaces/pthread_mutex_lock/1-1.c0100644000000000000000000000574307645130531023646 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: bing.wei.liu REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_mutex_lock() * shall lock the mutex object referenced by 'mutex'. If the mutex is * already locked, the calling thread shall block until the mutex becomes * available. This operation shall return with the mutex object referenced * by 'mutex' in the locked state with the calling thread as its owner. * Steps: * -- Initialize a mutex to protect a global variable 'value' * -- Create N threads. Each is looped M times to acquire the mutex, * increase the value, and then release the mutex. * -- Check if the value has increased properly (M*N); a broken mutex * implementation may cause lost augments. * */ #define _XOPEN_SOURCE 600 #include #include #include #include "posixtest.h" #define THREAD_NUM 5 #define LOOPS 4 void *f1(void *parm); pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; int value; /* value protected by mutex */ int main() { int i, rc; pthread_attr_t pta; pthread_t threads[THREAD_NUM]; //pthread_t self = pthread_self(); pthread_attr_init(&pta); pthread_attr_setdetachstate(&pta, PTHREAD_CREATE_JOINABLE); /* Create threads */ fprintf(stderr,"Creating %d threads\n", THREAD_NUM); for (i=0; i The function int pthread_mutex_lock(pthread_mutex_t *mutex); locks the mutex object referenced by 'mutex'. If the mutex is already locked, the calling thread shall block until the mutex becomes available. This operation returns with the mutex object referenced by 'mutex' in the locked state with the calling thread as its owner. Upon success, it returns 0. Upon failure, it shall return: -[EINVAL] The mutex was created with the protocol attribute PTHREAD_PRIO_PROTECT and the calling thread's priority is higher than the mutex's current priority calling. It may fail if: -[EINVAL] 'mutex' does not refer to an initialized mutex object -[EDEADLK] The current thread already owns the mutex It shall not return [EINTR]. If the mutex type is PTHREAD_MUTEX_RECURSIVE, the mutex shall maintain the concept of a lock count If a signal is delivered to a thread waiting for a mutex, when return from the signal handler the thread shall resume waiting. posixtestsuite/conformance/interfaces/pthread_mutex_lock/coverage.txt0100644000000000000000000000023310050631762025521 0ustar rootrootThis document defines the coverage for the pthread_mutex_lock function: Assertion Tested? 1 YES 2 YES 3 YES 3-1.c: Test [EINTR] 4 YES 5 YES NOTE: posixtestsuite/conformance/interfaces/pthread_mutex_lock/testfrmw.h0100644000000000000000000000427610072213502025214 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * * This file is a wrapper to use the tests from the NPTL Test & Trace Project * with either the Linux Test Project or the Open POSIX Test Suite. * The following macros are defined here: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate without calling one of those macros. * * */ #include "posixtest.h" #ifdef __GNUC__ /* We are using GCC */ #define UNRESOLVED(x, s) \ { output("Test %s unresolved: got %i on line %i (%s)\n", __FILE__, x, __LINE__, s); \ output_fini(); \ exit(PTS_UNRESOLVED); } #define FAILED(s) \ { output("Test %s FAILED: %s\n", __FILE__, s); \ output_fini(); \ exit(PTS_FAIL); } #define PASSED \ output_fini(); \ exit(PTS_PASS); #define UNTESTED(s) \ { output("File %s cannot test: %s\n", __FILE__, s); \ output_fini(); \ exit(PTS_UNTESTED); #else /* not using GCC */ #define UNRESOLVED(x, s) \ { output("Test unresolved: got %i on line %i (%s)\n", x, __LINE__, s); \ output_fini(); \ exit(PTS_UNRESOLVED); } #define FAILED(s) \ { output("Test FAILED: %s\n", s); \ output_fini(); \ exit(PTS_FAIL); } #define PASSED \ output_fini(); \ exit(PTS_PASS); #define UNTESTED(s) \ { output("Unable to test: %s\n", s); \ output_fini(); \ exit(PTS_UNTESTED); #endif posixtestsuite/conformance/interfaces/pthread_mutex_lock/2-1.c0100644000000000000000000000257107615641003023641 0ustar rootroot/* * Copyright (c) 2002, Intel Corporation. All rights reserved. * Created by: bing.wei.liu REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. * Test that pthread_mutex_lock() * Upon succesful completion, it shall return a 0 * */ #include #include #include #include "posixtest.h" int main() { pthread_mutex_t mutex; int rc; /* Initialize a mutex object with the default mutex attributes */ if((rc=pthread_mutex_init(&mutex,NULL)) != 0) { fprintf(stderr,"Error at pthread_mutex_init(), rc=%d\n",rc); return PTS_UNRESOLVED; } /* Lock the mutex using pthread_mutex_lock() */ if((rc=pthread_mutex_lock(&mutex)) == 0) { pthread_mutex_unlock(&mutex); printf("Test PASSED\n"); return PTS_PASS; } /* Check if returned values are tolerable */ else if(rc == EINVAL) { fprintf(stderr,"Invalid mutex object\n"); return PTS_UNRESOLVED; } else if(rc == EAGAIN) { fprintf(stderr,"The maximum number of recursive locks has been exceeded\n"); return PTS_UNRESOLVED; } else if(rc == EDEADLK) { fprintf(stderr,"The current thread already owns the mutex\n"); return PTS_UNRESOLVED; } /* Any other returned value means the test failed */ else { printf("Test FAILED\n"); return PTS_FAIL; } } posixtestsuite/conformance/interfaces/pthread_mutex_lock/3-1.c0100644000000000000000000002340710050631762023641 0ustar rootroot/* * Copyright (c) 2004, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * * This sample test aims to check the following assertion: * The function does not return an error code of EINTR * The steps are: * * -> Create a thread which loops on pthread_mutex_lock and pthread_mutex_unlock * operations. * -> Create another thread which loops on sending a signal to the first thread. * * */ /* * - adam.li@intel.com 2004-05-13 * Add to PTS. Please refer to http://nptl.bullopensource.org/phpBB/ * for general information */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /* We enable the following line to have mutex attributes defined */ #ifndef WITHOUT_XOPEN #define _XOPEN_SOURCE 600 #endif /********************************************************************************************/ /****************************** standard includes *****************************************/ /********************************************************************************************/ #include #include #include #include #include #include #include #include /********************************************************************************************/ /****************************** Test framework *****************************************/ /********************************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /********************************************************************************************/ /********************************** Configuration ******************************************/ /********************************************************************************************/ #define WITH_SYNCHRO #ifndef VERBOSE #define VERBOSE 1 #endif /********************************************************************************************/ /*********************************** Test case *****************************************/ /********************************************************************************************/ char do_it=1; unsigned long count_ope=0; pthread_mutex_t count_protect = PTHREAD_MUTEX_INITIALIZER; #ifdef WITH_SYNCHRO sem_t semsig1; sem_t semsig2; unsigned long count_sig=0; #endif sem_t semsync; typedef struct { pthread_t *thr; int sig; #ifdef WITH_SYNCHRO sem_t *sem; #endif } thestruct; /* the following function keeps on sending the signal to the thread pointed by arg * If WITH_SYNCHRO is defined, the target thread has a handler for the signal */ void * sendsig (void * arg) { thestruct *thearg = (thestruct *) arg; int ret; while (do_it) { #ifdef WITH_SYNCHRO if ((ret = sem_wait(thearg->sem))) { UNRESOLVED(errno, "Sem_wait in sendsig"); } count_sig++; #endif if ((ret = pthread_kill (*(thearg->thr), thearg->sig))) { UNRESOLVED(ret, "Pthread_kill in sendsig"); } } return NULL; } /* Next are the signal handlers. */ void sighdl1(int sig) { #ifdef WITH_SYNCHRO if ((sem_post(&semsig1))) { UNRESOLVED(errno, "Sem_post in signal handler 1"); } #endif } void sighdl2(int sig) { #ifdef WITH_SYNCHRO if ((sem_post(&semsig2))) { UNRESOLVED(errno, "Sem_post in signal handler 2"); } #endif } /* The following function loops on init/destroy some mutex (with different attributes) * it does check that no error code of EINTR is returned */ void * threaded(void * arg) { pthread_mutexattr_t ma[4], *pma[5]; pthread_mutex_t m[5]; int i; int ret; /* We need to register the signal handlers */ struct sigaction sa; sigemptyset (&sa.sa_mask); sa.sa_flags = 0; sa.sa_handler = sighdl1; if ((ret = sigaction (SIGUSR1, &sa, NULL))) { UNRESOLVED(ret, "Unable to register signal handler1"); } sa.sa_handler = sighdl2; if ((ret = sigaction (SIGUSR2, &sa, NULL))) { UNRESOLVED(ret, "Unable to register signal handler2"); } /* Initialize the different mutex */ pma[4]=NULL; for (i=0; i<4; i++) { pma[i]=&ma[i]; if ((ret = pthread_mutexattr_init(pma[i]))) { UNRESOLVED(ret, "pthread_mutexattr_init"); } } #ifndef WITHOUT_XOPEN if ((ret = pthread_mutexattr_settype(pma[0], PTHREAD_MUTEX_NORMAL))) { UNRESOLVED(ret, "pthread_mutexattr_settype (normal)"); } if ((ret = pthread_mutexattr_settype(pma[1], PTHREAD_MUTEX_ERRORCHECK))) { UNRESOLVED(ret, "pthread_mutexattr_settype (errorcheck)"); } if ((ret = pthread_mutexattr_settype(pma[2], PTHREAD_MUTEX_RECURSIVE))) { UNRESOLVED(ret, "pthread_mutexattr_settype (recursive)"); } if ((ret = pthread_mutexattr_settype(pma[3], PTHREAD_MUTEX_DEFAULT))) { UNRESOLVED(ret, "pthread_mutexattr_settype (default)"); } #if VERBOSE >1 output("Mutex attributes NORMAL,ERRORCHECK,RECURSIVE,DEFAULT initialized\n"); #endif #else #if VERBOSE > 0 output("Mutex attributes NORMAL,ERRORCHECK,RECURSIVE,DEFAULT unavailable\n"); #endif #endif for (i=0; i<5; i++) { ret = pthread_mutex_init(&m[i], pma[i]); if (ret == EINTR) { FAILED("pthread_mutex_init returned EINTR"); } if (ret != 0) { UNRESOLVED(ret, "pthread_mutex_init failed"); } } /* The mutex are ready, we will loop on lock/unlock now */ while (do_it) { for (i=0; i<5; i++) { ret = pthread_mutex_lock(&m[i]); if (ret == EINTR) { FAILED("pthread_mutex_lock returned EINTR"); } if (ret != 0) { UNRESOLVED(ret, "pthread_mutex_lock failed"); } ret = pthread_mutex_unlock(&m[i]); if (ret == EINTR) { FAILED("pthread_mutex_unlock returned EINTR"); } if (ret != 0) { UNRESOLVED(ret, "pthread_mutex_unlock failed"); } } ret = pthread_mutex_lock(&count_protect); if (ret == EINTR) { FAILED("pthread_mutex_lock returned EINTR"); } if (ret != 0) { UNRESOLVED(ret, "pthread_mutex_lock failed"); } count_ope++; pthread_mutex_unlock(&count_protect); if (ret == EINTR) { FAILED("pthread_mutex_unlock returned EINTR"); } if (ret != 0) { UNRESOLVED(ret, "pthread_mutex_unlock failed"); } } /* Now we can destroy the mutex objects */ for (i=0; i<4; i++) { if ((ret = pthread_mutexattr_destroy(pma[i]))) { UNRESOLVED(ret, "pthread_mutexattr_init"); } } for (i=0; i<5; i++) { ret = pthread_mutex_destroy(&m[i]); if (ret == EINTR) { FAILED("pthread_mutex_destroy returned EINTR"); } if (ret != 0) { UNRESOLVED(ret, "pthread_mutex_destroy failed"); } } do { ret = sem_wait(&semsync); } while (ret && (errno == EINTR)); if (ret) { UNRESOLVED(errno, "Could not wait for sig senders termination"); } return NULL; } /* At last (but not least) we need a main */ int main (int argc, char * argv[]) { int ret; pthread_t th_work, th_sig1, th_sig2; thestruct arg1, arg2; output_init(); #ifdef WITH_SYNCHRO #if VERBOSE >1 output("Running in synchronized mode\n"); #endif if ((sem_init(&semsig1, 0, 1))) { UNRESOLVED(errno, "Semsig1 init"); } if ((sem_init(&semsig2, 0, 1))) { UNRESOLVED(errno, "Semsig2 init"); } #endif if ((sem_init(&semsync, 0, 0))) { UNRESOLVED(errno, "semsync init"); } #if VERBOSE >1 output("Starting the worker thread\n"); #endif if ((ret = pthread_create(&th_work, NULL, threaded, NULL))) { UNRESOLVED(ret, "Worker thread creation failed"); } arg1.thr = &th_work; arg2.thr = &th_work; arg1.sig = SIGUSR1; arg2.sig = SIGUSR2; #ifdef WITH_SYNCHRO arg1.sem = &semsig1; arg2.sem = &semsig2; #endif #if VERBOSE >1 output("Starting the signal sources\n"); #endif if ((ret = pthread_create(&th_sig1, NULL, sendsig, (void *)&arg1))) { UNRESOLVED(ret, "Signal 1 sender thread creation failed"); } if ((ret = pthread_create(&th_sig2, NULL, sendsig, (void *)&arg2))) { UNRESOLVED(ret, "Signal 2 sender thread creation failed"); } /* Let's wait for a while now */ #if VERBOSE >1 output("Let the worker be killed for a second\n"); #endif sleep(1); /* Now stop the threads and join them */ #if VERBOSE >1 output("Stop everybody\n"); #endif do { do_it=0; } while (do_it); if ((ret = pthread_join(th_sig1, NULL))) { UNRESOLVED(ret, "Signal 1 sender thread join failed"); } if ((ret = pthread_join(th_sig2, NULL))) { UNRESOLVED(ret, "Signal 2 sender thread join failed"); } #if VERBOSE >1 output("Signal sources are stopped, we can stop the worker\n"); #endif if ((sem_post(&semsync))) { UNRESOLVED(errno, "could not post semsync"); } if ((ret = pthread_join(th_work, NULL))) { UNRESOLVED(ret, "Worker thread join failed"); } #if VERBOSE > 0 output("Test executed successfully.\n"); output(" %d mutex lock and unlock were done.\n", count_ope); #ifdef WITH_SYNCHRO output(" %d signals were sent meanwhile.\n", count_sig); #endif #endif PASSED; } posixtestsuite/conformance/interfaces/sched_get_priority_max/0040755000000000000000000000000010515625231024044 5ustar rootrootposixtestsuite/conformance/interfaces/sched_get_priority_max/1-3.c0100644000000000000000000000241610234132605024504 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * * Test that sched_get_priority_max() returns the maximum value on * success for SCHED_SPORADIC policy. */ #include #include #include #include #include "posixtest.h" #if defined(_POSIX_SPORADIC_SERVER)&&(_POSIX_SPORADIC_SERVER != -1)||defined(_POSIX_THREAD_SPORADIC_SERVER)&&(_POSIX_THREAD_SPORADIC_SERVER != -1) int main(int argc, char **argv) { int result = -1; result = sched_get_priority_max(SCHED_SPORADIC); if(result != -1 && errno == 0 ) { printf("The maximum priority for policy SCHED_SPORADIC is %i.\n", result); printf("Test PASSED\n"); return PTS_PASS; } else { perror("An error occurs"); return PTS_FAIL; } printf("This code should not be executed.\n"); return PTS_UNRESOLVED; } #else int main() { printf("Does not support SS (SPORADIC SERVER)\n"); return PTS_UNSUPPORTED; } #endif posixtestsuite/conformance/interfaces/sched_get_priority_max/3-1.sh0100755000000000000000000000031407643300017024676 0ustar rootroot#! /bin/sh # # Test that sched_get_priority_max() sets errno == EINVAL if policy is not a # valid policy. # This is tested implicitly via assertion 2. echo "Tested implicitly via assertion 2." exit 0 posixtestsuite/conformance/interfaces/sched_get_priority_max/1-1.c0100644000000000000000000000175407643300017024512 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * * Test that sched_get_priority_max() returns the maximum value on * success for SCHED_RR policy. */ #include #include #include #include "posixtest.h" int main(int argc, char **argv) { int result = -1; result = sched_get_priority_max(SCHED_RR); if(result != -1 && errno == 0 ) { printf("The maximum priority for policy SCHED_RR is %i.\n", result); printf("Test PASSED\n"); return PTS_PASS; } else { perror("An error occurs"); return PTS_FAIL; } printf("This code should not be executed.\n"); return PTS_UNRESOLVED; } posixtestsuite/conformance/interfaces/sched_get_priority_max/1-2.c0100644000000000000000000000176207643300017024512 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * * Test that sched_get_priority_max() returns the maximum value on * success for SCHED_FIFO policy. */ #include #include #include #include "posixtest.h" int main(int argc, char **argv) { int result = -1; result = sched_get_priority_max(SCHED_FIFO); if(result != -1 && errno == 0 ) { printf("The maximum priority for policy SCHED_FIFO is %i.\n", result); printf("Test PASSED\n"); return PTS_PASS; } else { perror("An error occurs"); return PTS_FAIL; } printf("This code should not be executed.\n"); return PTS_UNRESOLVED; } posixtestsuite/conformance/interfaces/sched_get_priority_max/assertions.xml0100644000000000000000000000104307643300020026745 0ustar rootroot sched_get_priority_max() returns the maximum priority value on success sched_get_priority_max() returns -1 on failure sched_get_priority_max() sets errno == EINVAL if policy is not a valid policy posixtestsuite/conformance/interfaces/sched_get_priority_max/coverage.txt0100644000000000000000000000033007643300020026363 0ustar rootrootThis document explains why certain assertions were not tested. Assertions not listed here should be covered by the tests in this directory. Assertions Tested ? Remarks 1 YES 2 YES 3 YESposixtestsuite/conformance/interfaces/sched_get_priority_max/2-1.c0100644000000000000000000000204307643300017024503 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * * Test that sched_get_priority_max() returns -1 on failure. */ #include #include #include #include "posixtest.h" int main(int argc, char **argv) { int result = -1; result = sched_get_priority_max(-1); if(result == -1 && errno == EINVAL ) { printf("Test PASSED\n"); return PTS_PASS; } if (result != -1) { printf("did no returned -1.\n"); return PTS_FAIL; } if (errno != EINVAL) { perror("error is not EINVAL"); return PTS_FAIL; } else { printf("Unresolved test error\n"); return PTS_UNRESOLVED; } printf("This code should not be executed.\n"); return PTS_UNRESOLVED; } posixtestsuite/conformance/interfaces/sched_get_priority_max/1-4.c0100644000000000000000000000176307662216136024526 0ustar rootroot/* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2. * * This program 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 General Public License for more details. * * * Test that sched_get_priority_max() returns the maximum value on * success for SCHED_OTHER policy. */ #include #include #include #include "posixtest.h" int main(int argc, char **argv) { int result = -1; result = sched_get_priority_max(SCHED_OTHER); if(result != -1 && errno == 0 ) { printf("The maximum priority for policy SCHED_OTHER is %i.\n", result); printf("Test PASSED\n"); return PTS_PASS; } else { perror("An error occurs"); return PTS_FAIL; } printf("This code should not be executed.\n"); return PTS_UNRESOLVED; } posixtestsuite/conformance/interfaces/sigaction/0040755000000000000000000000000010515625263021276 5ustar rootrootposixtestsuite/conformance/interfaces/sigaction/16-17.c0100644000000000000000000001261010205365423022105 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertions: * * If SA_RESTART is set in sa_flags, interruptible function interrupted by signal * shall restart silently. * The steps are: * -> create a child thread * -> child registers a handler for SIGUSR1 with SA_RESTART, then waits for the semaphore * -> parent kills the child with SIGUSR1, then post the semaphore. * The test fails if the sem_wait function returns EINTR *Note: This test uses sem_wait to check if EINTR is returned. As the function is not required to fail with EINTR, the test may return PASS and the feature not be correct (false positive). Anyway, a false negative status cannot be returned. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /* This test tests for an XSI feature */ #define _XOPEN_SOURCE 600 /******************************************************************************/ /*************************** standard includes ********************************/ /******************************************************************************/ #include #include #include #include #include #include #include #include #include /******************************************************************************/ /*************************** Test framework *******************************/ /******************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int * (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /******************************************************************************/ /**************************** Configuration ***********************************/ /******************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif #define SIGNAL SIGUSR1 /******************************************************************************/ /*************************** Test case ***********************************/ /******************************************************************************/ volatile sig_atomic_t caught = 0; sem_t sem; /* Handler function */ void handler( int signo ) { printf( "Caught signal %d\n", signo ); caught++; } /* Thread function */ void * threaded ( void * arg ) { int ret = 0; ret = sem_wait( &sem ); if ( ret != 0 ) { if ( errno == EINTR ) { FAILED( "The function returned EINTR while SA_RESTART is set" ); } else { UNRESOLVED( errno, "sem_wait failed" ); } } return NULL; } /* main function */ int main() { int ret; pthread_t child; struct sigaction sa; /* Initialize output */ output_init(); /* Set the signal handler */ sa.sa_flags = SA_RESTART; sa.sa_handler = handler; ret = sigemptyset( &sa.sa_mask ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to empty signal set" ); } /* Install the signal handler for SIGNAL */ ret = sigaction( SIGNAL, &sa, 0 ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to set signal handler" ); } /* Initialize the semaphore */ ret = sem_init( &sem, 0, 0 ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to init a semaphore" ); } /* Create the child thread */ ret = pthread_create( &child, NULL, threaded, NULL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to create a child thread" ); } /* Let the child thread enter the wait routine... we use sched_yield as there is no certain way to test that the child is waiting for the semaphore... */ sched_yield(); sched_yield(); sched_yield(); /* Ok, now kill the child */ ret = pthread_kill( child, SIGNAL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to kill the child thread" ); } /* wait that the child receives the signal */ while ( !caught ) sched_yield(); /* Now let the child run and terminate */ ret = sem_post( &sem ); if ( ret != 0 ) { UNRESOLVED( errno, "Failed to post the semaphore" ); } ret = pthread_join( child, NULL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to join the thread" ); } /* terminate */ ret = sem_destroy( &sem ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to destroy the semaphore" ); } /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/sigaction/13-18.c0100644000000000000000000000327207646610406022120 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #13 of the sigaction system call that verifies signal-catching functions are executed on the current stack if the SA_ONSTACK flag is cleared in the sigaction.sa_flags parameter to the sigaction function call. NOTE: This test case does not attempt to verify the proper operation of sigaltstack. */ #define _XOPEN_SOURCE 600 #include #include #include #include "posixtest.h" stack_t current; void handler(int signo) { stack_t oss; printf("Caught SIGUSR2\n"); if (sigaltstack((stack_t *)0, &oss) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); exit(-1); } if (oss.ss_sp != current.ss_sp || oss.ss_size != current.ss_size) { printf("Test FAILED\n"); exit(-1); } } int main() { struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); if (sigaction(SIGUSR2, &act, 0) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (sigaltstack((stack_t *)0, ¤t) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (raise(SIGUSR2) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/sigaction/28-9.c0100644000000000000000000001407310206323213022026 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertions: * * If the signal action was set with the signal() function, getting it into oact then reinstalling it with act must be valid. * The steps are: * -> register a signal handler for SIGINT with signal(). * -> check this signal handler works. * -> change the signal handler with sigaction, saving old handler in oact. * -> check the new signal handler works. * -> set the old signal handler back * -> check the old signal handler still works. * The test fails if a signal handler does not work as expected. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /******************************************************************************/ /*************************** standard includes ********************************/ /******************************************************************************/ #include #include #include #include #include #include #include /******************************************************************************/ /*************************** Test framework *******************************/ /******************************************************************************/ /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int * (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ #include "posixtest.h" #include #include #ifdef __GNUC__ /* We are using GCC */ #define UNRESOLVED(x, s) \ { output("Test %s unresolved: got %i (%s) on line %i (%s)\n", __FILE__, x, strerror(x), __LINE__, s); \ output_fini(); \ exit(PTS_UNRESOLVED); } #define FAILED(s) \ { output("Test %s FAILED: %s\n", __FILE__, s); \ output_fini(); \ exit(PTS_FAIL); } #define PASSED \ output_fini(); \ exit(PTS_PASS); #define UNTESTED(s) \ { output("File %s cannot test: %s\n", __FILE__, s); \ output_fini(); \ exit(PTS_UNTESTED); \ } #else /* not using GCC */ #define UNRESOLVED(x, s) \ { output("Test unresolved: got %i (%s) on line %i (%s)\n", x, strerror(x), __LINE__, s); \ output_fini(); \ exit(PTS_UNRESOLVED); } #define FAILED(s) \ { output("Test FAILED: %s\n", s); \ output_fini(); \ exit(PTS_FAIL); } #define PASSED \ output_fini(); \ exit(PTS_PASS); #define UNTESTED(s) \ { output("Unable to test: %s\n", s); \ output_fini(); \ exit(PTS_UNTESTED); \ } #endif void output_init() { /* do nothing */ return ; } void output( char * string, ... ) { va_list ap; #ifndef PLOT_OUTPUT char *ts = "[??:??:??]"; struct tm * now; time_t nw; #endif #ifndef PLOT_OUTPUT nw = time( NULL ); now = localtime( &nw ); if ( now == NULL ) printf( ts ); else printf( "[%2.2d:%2.2d:%2.2d]", now->tm_hour, now->tm_min, now->tm_sec ); #endif va_start( ap, string ); vprintf( string, ap ); va_end( ap ); } void output_fini() { /*do nothing */ return ; } /******************************************************************************/ /**************************** Configuration ***********************************/ /******************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif #define SIGNAL SIGINT /******************************************************************************/ /*************************** Test case ***********************************/ /******************************************************************************/ sig_atomic_t called = 1; void handler_1( int sig ) { called++; } void handler_2( int sig ) { called--; } /* main function */ int main() { int ret; struct sigaction sa, save; /* Initialize output */ output_init(); /* Register the signal handler with signal */ if ( SIG_ERR == signal( SIGNAL, handler_1 ) ) { UNRESOLVED( errno, "Failed to register signal handler with signal()" ); } /* As whether signal handler is restored to default when executed is implementation defined, we cannot check it was registered here. */ /* Set the new signal handler with sigaction*/ sa.sa_flags = 0; sa.sa_handler = handler_2; ret = sigemptyset( &sa.sa_mask ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to empty signal set" ); } /* Install the signal handler for SIGINT */ ret = sigaction( SIGNAL, &sa, &save ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to set signal handler" ); } /* Check the signal handler has been set up */ ret = raise( SIGNAL ); if ( ret != 0 ) { UNRESOLVED( ret , "Failed to raise the signal" ); } if ( called != 0 ) { FAILED( "handler not executed" ); } /* Restore the first signal handler */ ret = sigaction( SIGNAL, &save, 0 ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to set signal handler" ); } /* Check the signal handler has been set up */ ret = raise( SIGNAL ); if ( ret != 0 ) { UNRESOLVED( ret , "Failed to raise the signal" ); } if ( called != 1 ) { FAILED( "handler not executed" ); } /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/sigaction/28-14.c0100644000000000000000000001407610206323206022107 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertions: * * If the signal action was set with the signal() function, getting it into oact then reinstalling it with act must be valid. * The steps are: * -> register a signal handler for SIGTSTP with signal(). * -> check this signal handler works. * -> change the signal handler with sigaction, saving old handler in oact. * -> check the new signal handler works. * -> set the old signal handler back * -> check the old signal handler still works. * The test fails if a signal handler does not work as expected. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /******************************************************************************/ /*************************** standard includes ********************************/ /******************************************************************************/ #include #include #include #include #include #include #include /******************************************************************************/ /*************************** Test framework *******************************/ /******************************************************************************/ /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int * (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ #include "posixtest.h" #include #include #ifdef __GNUC__ /* We are using GCC */ #define UNRESOLVED(x, s) \ { output("Test %s unresolved: got %i (%s) on line %i (%s)\n", __FILE__, x, strerror(x), __LINE__, s); \ output_fini(); \ exit(PTS_UNRESOLVED); } #define FAILED(s) \ { output("Test %s FAILED: %s\n", __FILE__, s); \ output_fini(); \ exit(PTS_FAIL); } #define PASSED \ output_fini(); \ exit(PTS_PASS); #define UNTESTED(s) \ { output("File %s cannot test: %s\n", __FILE__, s); \ output_fini(); \ exit(PTS_UNTESTED); \ } #else /* not using GCC */ #define UNRESOLVED(x, s) \ { output("Test unresolved: got %i (%s) on line %i (%s)\n", x, strerror(x), __LINE__, s); \ output_fini(); \ exit(PTS_UNRESOLVED); } #define FAILED(s) \ { output("Test FAILED: %s\n", s); \ output_fini(); \ exit(PTS_FAIL); } #define PASSED \ output_fini(); \ exit(PTS_PASS); #define UNTESTED(s) \ { output("Unable to test: %s\n", s); \ output_fini(); \ exit(PTS_UNTESTED); \ } #endif void output_init() { /* do nothing */ return ; } void output( char * string, ... ) { va_list ap; #ifndef PLOT_OUTPUT char *ts = "[??:??:??]"; struct tm * now; time_t nw; #endif #ifndef PLOT_OUTPUT nw = time( NULL ); now = localtime( &nw ); if ( now == NULL ) printf( ts ); else printf( "[%2.2d:%2.2d:%2.2d]", now->tm_hour, now->tm_min, now->tm_sec ); #endif va_start( ap, string ); vprintf( string, ap ); va_end( ap ); } void output_fini() { /*do nothing */ return ; } /******************************************************************************/ /**************************** Configuration ***********************************/ /******************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif #define SIGNAL SIGTSTP /******************************************************************************/ /*************************** Test case ***********************************/ /******************************************************************************/ sig_atomic_t called = 1; void handler_1( int sig ) { called++; } void handler_2( int sig ) { called--; } /* main function */ int main() { int ret; struct sigaction sa, save; /* Initialize output */ output_init(); /* Register the signal handler with signal */ if ( SIG_ERR == signal( SIGNAL, handler_1 ) ) { UNRESOLVED( errno, "Failed to register signal handler with signal()" ); } /* As whether signal handler is restored to default when executed is implementation defined, we cannot check it was registered here. */ /* Set the new signal handler with sigaction*/ sa.sa_flags = 0; sa.sa_handler = handler_2; ret = sigemptyset( &sa.sa_mask ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to empty signal set" ); } /* Install the signal handler for SIGTSTP */ ret = sigaction( SIGNAL, &sa, &save ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to set signal handler" ); } /* Check the signal handler has been set up */ ret = raise( SIGNAL ); if ( ret != 0 ) { UNRESOLVED( ret , "Failed to raise the signal" ); } if ( called != 0 ) { FAILED( "handler not executed" ); } /* Restore the first signal handler */ ret = sigaction( SIGNAL, &save, 0 ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to set signal handler" ); } /* Check the signal handler has been set up */ ret = raise( SIGNAL ); if ( ret != 0 ) { UNRESOLVED( ret , "Failed to raise the signal" ); } if ( called != 1 ) { FAILED( "handler not executed" ); } /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/sigaction/12-52.c0100644000000000000000000000335507650040164022110 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #12 of the sigaction system call that verifies signal-catching functions are executed on the current stack if the SA_ONSTACK flag is set in the sigaction.sa_flags parameter to the sigaction function call, but a new stack has not be set by sigaltstack(). NOTE: This test case does not attempt to verify the proper operation of sigaltstack. */ #define _XOPEN_SOURCE 600 #include #include #include #include "posixtest.h" stack_t current; void handler(int signo) { stack_t oss; printf("Caught SIGXFSZ\n"); if (sigaltstack((stack_t *)0, &oss) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); exit(-1); } if (oss.ss_sp != current.ss_sp || oss.ss_size != current.ss_size) { printf("Test FAILED\n"); exit(-1); } } int main() { struct sigaction act; act.sa_handler = handler; act.sa_flags = SA_ONSTACK; sigemptyset(&act.sa_mask); if (sigaction(SIGXFSZ, &act, 0) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (sigaltstack((stack_t *)0, ¤t) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (raise(SIGXFSZ) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/sigaction/22-11.c0100644000000000000000000000470507646610411022107 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #22 of the sigaction system call that verifies that if the SA_NODEFER flag is set for a given signal, then when the sa_sigaction signal-catching function is entered, then the signal that was caught is not added to the signal mask by raising that signal in the signal handler and verifying that the handler is reentered. Steps: 1. Fork a new process 2. (parent) wait for child 3. (child) Setup a signal handler for SIGQUIT with SA_NODEFER set in the sa_flags field 4. (child) raise SIGQUIT 5. (child, signal handler) increment handler count 6. (child, signal handler) if count is 1 then raise SIGQUIT 7. (child, signal handler) if count is 1 then set error variable 8. (child) if error is set then return -1, else return 0 6. (parent - returning from wait) If child returned 0 then exit 0, otherwise exit -1. */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include "posixtest.h" int handler_count = 0; void handler(int signo) { static int inside_handler = 0; printf("SIGQUIT caught\n"); if (inside_handler) { printf("Signal caught while inside handler\n"); exit(0); } inside_handler++; handler_count++; if (handler_count == 1) { printf("Raising SIGQUIT\n"); raise(SIGQUIT); printf("Returning from raising SIGQUIT\n"); } inside_handler--; } int main() { if (fork() == 0) { /* child */ struct sigaction act; act.sa_handler = handler; act.sa_flags = SA_NODEFER; sigemptyset(&act.sa_mask); if (sigaction(SIGQUIT, &act, 0) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); return PTS_UNRESOLVED; } if (raise(SIGQUIT) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); return PTS_UNRESOLVED; } return PTS_FAIL; } else { int s; /* parent */ if (wait(&s) == -1) { perror("Unexpected error while setting up test " "pre-conditions"); return PTS_UNRESOLVED; } if (!WEXITSTATUS(s)) { printf("Test PASSED\n"); return PTS_PASS; } } printf("Test FAILED\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sigaction/18-9.c0100644000000000000000000000743410205365423022040 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertions: * * If SA_SIGINFO is not set in sa_flags, sa_handler is used as the signal * handling function. * The steps are: * -> register a handler for SIGINT without SA_SIGINFO, and a known function * as saèhandler * -> raise SIGINT, and check the function has been called. * The test fails if the function is not called */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /******************************************************************************/ /*************************** standard includes ********************************/ /******************************************************************************/ #include #include #include #include #include #include #include #include /******************************************************************************/ /*************************** Test framework *******************************/ /******************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int * (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /******************************************************************************/ /**************************** Configuration ***********************************/ /******************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif #define SIGNAL SIGINT /******************************************************************************/ /*************************** Test case ***********************************/ /******************************************************************************/ int called = 0; void handler( int sig ) { called = 1; } /* main function */ int main() { int ret; struct sigaction sa; /* Initialize output */ output_init(); /* Set the signal handler */ sa.sa_flags = 0; sa.sa_handler = handler; ret = sigemptyset( &sa.sa_mask ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to empty signal set" ); } /* Install the signal handler for SIGINT */ ret = sigaction( SIGNAL, &sa, 0 ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to set signal handler" ); } if ( called ) { FAILED( "The signal handler has been called when no signal was raised" ); } ret = raise( SIGNAL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to raise SIGINT" ); } if ( !called ) { FAILED( "the sa_handler was not called whereas SA_SIGINFO was not set" ); } /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/sigaction/23-25.c0100644000000000000000000001036010205365424022103 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertions: * * If SA_NODEFER is not set in sa_flags, the caught signal is added to the * thread's signal mask during the handler execution. * The steps are: * -> register a signal handler for SIGXCPU * -> raise SIGXCPU * -> In handler, check for reentrance then raise SIGXCPU again. * The test fails if signal handler if reentered or signal is not pending when raised again. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /******************************************************************************/ /*************************** standard includes ********************************/ /******************************************************************************/ #include #include #include #include #include #include #include #include /******************************************************************************/ /*************************** Test framework *******************************/ /******************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int * (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /******************************************************************************/ /**************************** Configuration ***********************************/ /******************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif #define SIGNAL SIGXCPU /******************************************************************************/ /*************************** Test case ***********************************/ /******************************************************************************/ int called = 0; void handler( int sig ) { int ret; sigset_t pending; called++; if ( called == 2 ) { FAILED( "Signal was not masked in signal handler" ); } if ( called == 1 ) { /* Raise the signal again. It should be masked */ ret = raise( SIGNAL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to raise SIGXCPU again" ); } /* check the signal is pending */ ret = sigpending( &pending ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to get pending signal set" ); } ret = sigismember( &pending, SIGNAL ); if ( ret != 1 ) { FAILED( "signal is not pending" ); } } called++; } /* main function */ int main() { int ret; struct sigaction sa; /* Initialize output */ output_init(); /* Set the signal handler */ sa.sa_flags = 0; sa.sa_handler = handler; ret = sigemptyset( &sa.sa_mask ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to empty signal set" ); } /* Install the signal handler for SIGXCPU */ ret = sigaction( SIGNAL, &sa, 0 ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to set signal handler" ); } ret = raise( SIGNAL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to raise SIGXCPU" ); } while ( called != 4 ) sched_yield(); /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/sigaction/4-10.c0100644000000000000000000000355607631716557022045 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #4 of the sigaction system call that shows that attempting to add SIGKILL can not be added to the signal mask for a signal handler. Steps: 1. Fork a new process 2. (parent) wait for child 3. (child) Setup a signal handler for SIGPIPE with SIGKILL added to the signal mask 4. (child) raise SIGPIPE 5. (child, signal handler) raise SIGKILL 5. (child) If still alive then exit -1 6. (parent - returning from wait) If child was killed then return success, otherwise fail. */ #include #include #include #include #include #include "posixtest.h" void handler(int signo) { raise(SIGKILL); exit(0); } int main() { if (fork() == 0) { /* child */ /* * NOTE: This block of code will return 0 for error * and anything else for success. */ struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); sigaddset(&act.sa_mask, SIGKILL); if (sigaction(SIGPIPE, &act, 0) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); return PTS_PASS; } if (raise(SIGPIPE) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); } return PTS_PASS; } else { int s; /* parent */ if (wait(&s) == -1) { perror("Unexpected error while setting up test " "pre-conditions"); return PTS_UNRESOLVED; } if (!WIFEXITED(s)) { printf("Test PASSED\n"); return PTS_PASS; } } printf("Test FAILED\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sigaction/4-97.c0100644000000000000000000000161007631716567022052 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #4 of the sigaction system call that shows that attempting to add SIGSTOP to the signal mask of SIGPOLL will not result in sigaction returning -1 */ #include #include #include #include #include #include "posixtest.h" void handler(int signo) { } int main() { struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); sigaddset(&act.sa_mask, SIGSTOP); if (sigaction(SIGPOLL, &act, 0) == -1) { printf("Test FAILED\n"); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/sigaction/17-17.c0100644000000000000000000000420510205365423022107 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test assertion #17 by verifying that select returns -1 with errno set to EINTR if a handler for the SIGUSR1 signal is setup with the SA_RESTART flag cleared. * 12/18/02 - Adding in include of sys/time.h per * rodrigc REMOVE-THIS AT attbi DOT com input that it needs * to be included whenever the timeval struct is used. */ #include #include #include #include #include #include #include #include #include #include "posixtest.h" volatile sig_atomic_t wakeup = 1; void handler(int signo) { printf("Caught SIGUSR1\n"); wakeup++; } int main() { pid_t pid; struct timeval tv; if ((pid = fork()) == 0) { /* child */ struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); sigaction(SIGUSR1, &act, 0); while(wakeup == 1) { tv.tv_sec = 3; tv.tv_usec = 0; if (select(0, NULL, NULL, NULL, &tv)== -1 && errno == EINTR) { perror("select"); return PTS_PASS; } } return PTS_FAIL; } else { /* parent */ int s; /* There is a race condition between the parent process sending the SIGUSR1 signal, and the child process being inside the 'select' function call. I could not find a pure POSIX method for determining the state of the child process, so I just added a delay so that the test is valid in most conditions. (The problem is that it would be perfectly legal for a POSIX conformant OS to not schedule the child process for a long time.) */ tv.tv_sec = 1; tv.tv_usec = 0; select(0, NULL, NULL, NULL, &tv); kill(pid, SIGUSR1); waitpid(pid, &s, 0); if (WEXITSTATUS(s) == PTS_PASS) { printf("Test PASSED\n"); return PTS_PASS; } } printf("Test FAILED\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sigaction/2-4.c0100644000000000000000000000272007631716535021752 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #2 of the sigaction system call that shows sigaction (when used with a non-null oact pointer) changes the action for a signal. Steps: 1. Call sigaction to set handler for SIGCHLD to use handler1 2. Call sigaction again to set handler for SIGCHLD to use handler2, but this time use a non-null oarg and verify the sa_handler for oarg is set for handler1. */ #include #include #include "posixtest.h" int handler_called = 0; void handler1(int signo) { } void handler2(int signo) { } int main() { struct sigaction act; struct sigaction oact; act.sa_handler = handler1; act.sa_flags = 0; sigemptyset(&act.sa_mask); if (sigaction(SIGCHLD, &act, 0) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } act.sa_handler = handler2; sigemptyset(&act.sa_mask); if (sigaction(SIGCHLD, &act, &oact) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (oact.sa_handler == handler1) { printf("Test PASSED\n"); return PTS_PASS; } printf("Test Failed\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sigaction/4-87.c0100644000000000000000000000160607631716565022054 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #4 of the sigaction system call that shows that attempting to add SIGSTOP to the signal mask of SIGINT will not result in sigaction returning -1 */ #include #include #include #include #include #include "posixtest.h" void handler(int signo) { } int main() { struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); sigaddset(&act.sa_mask, SIGSTOP); if (sigaction(SIGINT, &act, 0) == -1) { printf("Test FAILED\n"); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/sigaction/23-15.c0100644000000000000000000001036010205365424022102 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertions: * * If SA_NODEFER is not set in sa_flags, the caught signal is added to the * thread's signal mask during the handler execution. * The steps are: * -> register a signal handler for SIGTTIN * -> raise SIGTTIN * -> In handler, check for reentrance then raise SIGTTIN again. * The test fails if signal handler if reentered or signal is not pending when raised again. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /******************************************************************************/ /*************************** standard includes ********************************/ /******************************************************************************/ #include #include #include #include #include #include #include #include /******************************************************************************/ /*************************** Test framework *******************************/ /******************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int * (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /******************************************************************************/ /**************************** Configuration ***********************************/ /******************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif #define SIGNAL SIGTTIN /******************************************************************************/ /*************************** Test case ***********************************/ /******************************************************************************/ int called = 0; void handler( int sig ) { int ret; sigset_t pending; called++; if ( called == 2 ) { FAILED( "Signal was not masked in signal handler" ); } if ( called == 1 ) { /* Raise the signal again. It should be masked */ ret = raise( SIGNAL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to raise SIGTTIN again" ); } /* check the signal is pending */ ret = sigpending( &pending ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to get pending signal set" ); } ret = sigismember( &pending, SIGNAL ); if ( ret != 1 ) { FAILED( "signal is not pending" ); } } called++; } /* main function */ int main() { int ret; struct sigaction sa; /* Initialize output */ output_init(); /* Set the signal handler */ sa.sa_flags = 0; sa.sa_handler = handler; ret = sigemptyset( &sa.sa_mask ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to empty signal set" ); } /* Install the signal handler for SIGTTIN */ ret = sigaction( SIGNAL, &sa, 0 ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to set signal handler" ); } ret = raise( SIGNAL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to raise SIGTTIN" ); } while ( called != 4 ) sched_yield(); /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/sigaction/12-10.c0100644000000000000000000000372707646610401022107 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #12 of the sigaction system call that verifies signal-catching functions are executed on the alternate stack if the SA_ONSTACK flag is set in the sigaction.sa_flags parameter to the sigaction function call, and an alternate stack has been setup with sigaltstack(). NOTE: This test case does not attempt to verify the proper operation of sigaltstack. */ #define _XOPEN_SOURCE 600 #include #include #include #include "posixtest.h" stack_t alt_ss; void handler(int signo) { stack_t ss; printf("Caught SIGPIPE\n"); if (sigaltstack((stack_t *)0, &ss) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); exit(-1); } if (ss.ss_sp != alt_ss.ss_sp || ss.ss_size != alt_ss.ss_size) { printf("Test FAILED\n"); exit(-1); } } int main() { struct sigaction act; act.sa_handler = handler; act.sa_flags = SA_ONSTACK; sigemptyset(&act.sa_mask); if (sigaction(SIGPIPE, &act, 0) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if ((alt_ss.ss_sp = (void *)malloc(SIGSTKSZ)) == NULL) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } alt_ss.ss_size = SIGSTKSZ; alt_ss.ss_flags = 0; if (sigaltstack(&alt_ss, (stack_t *)0) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (raise(SIGPIPE) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/sigaction/19-2.c0100644000000000000000000001017610205365423022027 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertions: * * If SA_SIGINFO is set in sa_flags and Real Time Signals extension is supported, * sa_sigaction is used as the signal handling function. * The steps are: * -> test for RTS extension * -> register a handler for SIGALRM with SA_SIGINFO, and a known function * as sa_sigaction * -> raise SIGALRM, and check the function has been called. * The test fails if the function is not called */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /******************************************************************************/ /*************************** standard includes ********************************/ /******************************************************************************/ #include #include #include #include #include #include #include #include /******************************************************************************/ /*************************** Test framework *******************************/ /******************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int * (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /******************************************************************************/ /**************************** Configuration ***********************************/ /******************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif #define SIGNAL SIGALRM /******************************************************************************/ /*************************** Test case ***********************************/ /******************************************************************************/ int called = 0; void handler( int sig, siginfo_t *info, void *context ) { if ( info->si_signo != SIGNAL ) { FAILED( "Wrong signal generated?" ); } called = 1; } /* main function */ int main() { int ret; long rts; struct sigaction sa; /* Initialize output */ output_init(); /* Test the RTS extension */ rts = sysconf( _SC_REALTIME_SIGNALS ); if ( rts < 0L ) { UNTESTED( "This test needs the RTS extension" ); } /* Set the signal handler */ sa.sa_flags = SA_SIGINFO; sa.sa_sigaction = handler; ret = sigemptyset( &sa.sa_mask ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to empty signal set" ); } /* Install the signal handler for SIGALRM */ ret = sigaction( SIGNAL, &sa, 0 ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to set signal handler" ); } if ( called ) { FAILED( "The signal handler has been called when no signal was raised" ); } ret = raise( SIGNAL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to raise SIGALRM" ); } if ( !called ) { FAILED( "the sa_handler was not called whereas SA_SIGINFO was not set" ); } /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/sigaction/19-6.c0100644000000000000000000001017110205365424022027 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertions: * * If SA_SIGINFO is set in sa_flags and Real Time Signals extension is supported, * sa_sigaction is used as the signal handling function. * The steps are: * -> test for RTS extension * -> register a handler for SIGFPE with SA_SIGINFO, and a known function * as sa_sigaction * -> raise SIGFPE, and check the function has been called. * The test fails if the function is not called */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /******************************************************************************/ /*************************** standard includes ********************************/ /******************************************************************************/ #include #include #include #include #include #include #include #include /******************************************************************************/ /*************************** Test framework *******************************/ /******************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int * (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /******************************************************************************/ /**************************** Configuration ***********************************/ /******************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif #define SIGNAL SIGFPE /******************************************************************************/ /*************************** Test case ***********************************/ /******************************************************************************/ int called = 0; void handler( int sig, siginfo_t *info, void *context ) { if ( info->si_signo != SIGNAL ) { FAILED( "Wrong signal generated?" ); } called = 1; } /* main function */ int main() { int ret; long rts; struct sigaction sa; /* Initialize output */ output_init(); /* Test the RTS extension */ rts = sysconf( _SC_REALTIME_SIGNALS ); if ( rts < 0L ) { UNTESTED( "This test needs the RTS extension" ); } /* Set the signal handler */ sa.sa_flags = SA_SIGINFO; sa.sa_sigaction = handler; ret = sigemptyset( &sa.sa_mask ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to empty signal set" ); } /* Install the signal handler for SIGFPE */ ret = sigaction( SIGNAL, &sa, 0 ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to set signal handler" ); } if ( called ) { FAILED( "The signal handler has been called when no signal was raised" ); } ret = raise( SIGNAL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to raise SIGFPE" ); } if ( !called ) { FAILED( "the sa_handler was not called whereas SA_SIGINFO was not set" ); } /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/sigaction/2-15.c0100644000000000000000000000272007631716533022032 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #2 of the sigaction system call that shows sigaction (when used with a non-null oact pointer) changes the action for a signal. Steps: 1. Call sigaction to set handler for SIGTTIN to use handler1 2. Call sigaction again to set handler for SIGTTIN to use handler2, but this time use a non-null oarg and verify the sa_handler for oarg is set for handler1. */ #include #include #include "posixtest.h" int handler_called = 0; void handler1(int signo) { } void handler2(int signo) { } int main() { struct sigaction act; struct sigaction oact; act.sa_handler = handler1; act.sa_flags = 0; sigemptyset(&act.sa_mask); if (sigaction(SIGTTIN, &act, 0) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } act.sa_handler = handler2; sigemptyset(&act.sa_mask); if (sigaction(SIGTTIN, &act, &oact) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (oact.sa_handler == handler1) { printf("Test PASSED\n"); return PTS_PASS; } printf("Test Failed\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sigaction/3-15.c0100644000000000000000000000276507631716555022050 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #3 of the sigaction system call that shows calling sigaction with a null act argument does not change the signal handler. Steps: 1. Initialize global variable to indicate handler has not been called 2. Set the signal handler for SIGTTIN to handler 3. Call sigaction with a null act 4. raise SIGTTIN 5. Verify handler was called. */ #include #include #include "posixtest.h" int handler_called = 0; void handler(int signo) { handler_called = 1; } int main() { struct sigaction act; struct sigaction oact; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); if (sigaction(SIGTTIN, &act, 0) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (sigaction(SIGTTIN, 0, &oact) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (raise(SIGTTIN) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (handler_called) { printf("Test PASSED\n"); return PTS_PASS; } printf("Test FAILED\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sigaction/16-4.c0100644000000000000000000001261010205365423022021 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertions: * * If SA_RESTART is set in sa_flags, interruptible function interrupted by signal * shall restart silently. * The steps are: * -> create a child thread * -> child registers a handler for SIGCHLD with SA_RESTART, then waits for the semaphore * -> parent kills the child with SIGCHLD, then post the semaphore. * The test fails if the sem_wait function returns EINTR *Note: This test uses sem_wait to check if EINTR is returned. As the function is not required to fail with EINTR, the test may return PASS and the feature not be correct (false positive). Anyway, a false negative status cannot be returned. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /* This test tests for an XSI feature */ #define _XOPEN_SOURCE 600 /******************************************************************************/ /*************************** standard includes ********************************/ /******************************************************************************/ #include #include #include #include #include #include #include #include #include /******************************************************************************/ /*************************** Test framework *******************************/ /******************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int * (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /******************************************************************************/ /**************************** Configuration ***********************************/ /******************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif #define SIGNAL SIGCHLD /******************************************************************************/ /*************************** Test case ***********************************/ /******************************************************************************/ volatile sig_atomic_t caught = 0; sem_t sem; /* Handler function */ void handler( int signo ) { printf( "Caught signal %d\n", signo ); caught++; } /* Thread function */ void * threaded ( void * arg ) { int ret = 0; ret = sem_wait( &sem ); if ( ret != 0 ) { if ( errno == EINTR ) { FAILED( "The function returned EINTR while SA_RESTART is set" ); } else { UNRESOLVED( errno, "sem_wait failed" ); } } return NULL; } /* main function */ int main() { int ret; pthread_t child; struct sigaction sa; /* Initialize output */ output_init(); /* Set the signal handler */ sa.sa_flags = SA_RESTART; sa.sa_handler = handler; ret = sigemptyset( &sa.sa_mask ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to empty signal set" ); } /* Install the signal handler for SIGNAL */ ret = sigaction( SIGNAL, &sa, 0 ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to set signal handler" ); } /* Initialize the semaphore */ ret = sem_init( &sem, 0, 0 ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to init a semaphore" ); } /* Create the child thread */ ret = pthread_create( &child, NULL, threaded, NULL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to create a child thread" ); } /* Let the child thread enter the wait routine... we use sched_yield as there is no certain way to test that the child is waiting for the semaphore... */ sched_yield(); sched_yield(); sched_yield(); /* Ok, now kill the child */ ret = pthread_kill( child, SIGNAL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to kill the child thread" ); } /* wait that the child receives the signal */ while ( !caught ) sched_yield(); /* Now let the child run and terminate */ ret = sem_post( &sem ); if ( ret != 0 ) { UNRESOLVED( errno, "Failed to post the semaphore" ); } ret = pthread_join( child, NULL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to join the thread" ); } /* terminate */ ret = sem_destroy( &sem ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to destroy the semaphore" ); } /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/sigaction/8-25.c0100644000000000000000000000324307631716573022046 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #8 of the sigaction system call that verifies that if signals in the sa_mask (passed in the sigaction struct of the sigaction function call) are added to the process signal mask during execution of the signal-catching function. */ #include #include #include #include #include #include "posixtest.h" int SIGVTALRM_count = 0; void SIGVTALRM_handler(int signo) { SIGVTALRM_count++; printf("Caught SIGVTALRM\n"); } void SIGXCPU_handler(int signo) { printf("Caught SIGXCPU\n"); raise(SIGVTALRM); if (SIGVTALRM_count) { printf("Test FAILED\n"); exit(-1); } } int main() { struct sigaction act; act.sa_handler = SIGXCPU_handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); sigaddset(&act.sa_mask, SIGVTALRM); if (sigaction(SIGXCPU, &act, 0) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); return PTS_UNRESOLVED; } act.sa_handler = SIGVTALRM_handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); if (sigaction(SIGVTALRM, &act, 0) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); return PTS_UNRESOLVED; } if (raise(SIGXCPU) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/sigaction/17-7.c0100644000000000000000000000420010205365423022021 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test assertion #17 by verifying that select returns -1 with errno set to EINTR if a handler for the SIGHUP signal is setup with the SA_RESTART flag cleared. * 12/18/02 - Adding in include of sys/time.h per * rodrigc REMOVE-THIS AT attbi DOT com input that it needs * to be included whenever the timeval struct is used. */ #include #include #include #include #include #include #include #include #include #include "posixtest.h" volatile sig_atomic_t wakeup = 1; void handler(int signo) { printf("Caught SIGHUP\n"); wakeup++; } int main() { pid_t pid; struct timeval tv; if ((pid = fork()) == 0) { /* child */ struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); sigaction(SIGHUP, &act, 0); while(wakeup == 1) { tv.tv_sec = 3; tv.tv_usec = 0; if (select(0, NULL, NULL, NULL, &tv)== -1 && errno == EINTR) { perror("select"); return PTS_PASS; } } return PTS_FAIL; } else { /* parent */ int s; /* There is a race condition between the parent process sending the SIGHUP signal, and the child process being inside the 'select' function call. I could not find a pure POSIX method for determining the state of the child process, so I just added a delay so that the test is valid in most conditions. (The problem is that it would be perfectly legal for a POSIX conformant OS to not schedule the child process for a long time.) */ tv.tv_sec = 1; tv.tv_usec = 0; select(0, NULL, NULL, NULL, &tv); kill(pid, SIGHUP); waitpid(pid, &s, 0); if (WEXITSTATUS(s) == PTS_PASS) { printf("Test PASSED\n"); return PTS_PASS; } } printf("Test FAILED\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sigaction/6-11.c0100644000000000000000000000246507646610421022033 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #5 of the sigaction system call that verifies setting the SA_INFO bit in the signal mask for SIGQUIT will result in sa_sigaction identifying the signal-catching function. */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include "posixtest.h" int handler_called = 0; void handler(int signo, siginfo_t *info, void *context) { handler_called = 1; } int main() { struct sigaction act; act.sa_sigaction = handler; act.sa_flags = SA_SIGINFO; sigemptyset(&act.sa_mask); sigaddset(&act.sa_mask, SIGSTOP); if (sigaction(SIGQUIT, &act, 0) == -1) { printf("Unexpected error while attempting to setup test " "pre-conditions\n"); return PTS_UNRESOLVED; } if (raise(SIGQUIT) == -1) { printf("Unexpected error while attempting to setup test " "pre-conditions\n"); return PTS_UNRESOLVED; } if (handler_called) { printf("Test PASSED\n"); return PTS_PASS; } printf("Test FAILED\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sigaction/2-2.c0100644000000000000000000000272007631716534021747 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #2 of the sigaction system call that shows sigaction (when used with a non-null oact pointer) changes the action for a signal. Steps: 1. Call sigaction to set handler for SIGALRM to use handler1 2. Call sigaction again to set handler for SIGALRM to use handler2, but this time use a non-null oarg and verify the sa_handler for oarg is set for handler1. */ #include #include #include "posixtest.h" int handler_called = 0; void handler1(int signo) { } void handler2(int signo) { } int main() { struct sigaction act; struct sigaction oact; act.sa_handler = handler1; act.sa_flags = 0; sigemptyset(&act.sa_mask); if (sigaction(SIGALRM, &act, 0) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } act.sa_handler = handler2; sigemptyset(&act.sa_mask); if (sigaction(SIGALRM, &act, &oact) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (oact.sa_handler == handler1) { printf("Test PASSED\n"); return PTS_PASS; } printf("Test Failed\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sigaction/4-7.c0100644000000000000000000000355207631716563021764 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #4 of the sigaction system call that shows that attempting to add SIGKILL can not be added to the signal mask for a signal handler. Steps: 1. Fork a new process 2. (parent) wait for child 3. (child) Setup a signal handler for SIGHUP with SIGKILL added to the signal mask 4. (child) raise SIGHUP 5. (child, signal handler) raise SIGKILL 5. (child) If still alive then exit -1 6. (parent - returning from wait) If child was killed then return success, otherwise fail. */ #include #include #include #include #include #include "posixtest.h" void handler(int signo) { raise(SIGKILL); exit(0); } int main() { if (fork() == 0) { /* child */ /* * NOTE: This block of code will return 0 for error * and anything else for success. */ struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); sigaddset(&act.sa_mask, SIGKILL); if (sigaction(SIGHUP, &act, 0) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); return PTS_PASS; } if (raise(SIGHUP) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); } return PTS_PASS; } else { int s; /* parent */ if (wait(&s) == -1) { perror("Unexpected error while setting up test " "pre-conditions"); return PTS_UNRESOLVED; } if (!WIFEXITED(s)) { printf("Test PASSED\n"); return PTS_PASS; } } printf("Test FAILED\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sigaction/4-72.c0100644000000000000000000000161007631716564022040 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #4 of the sigaction system call that shows that attempting to add SIGKILL to the signal mask of SIGPROF will not result in sigaction returning -1 */ #include #include #include #include #include #include "posixtest.h" void handler(int signo) { } int main() { struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); sigaddset(&act.sa_mask, SIGKILL); if (sigaction(SIGPROF, &act, 0) == -1) { printf("Test FAILED\n"); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/sigaction/13-4.c0100644000000000000000000000327207646610411022027 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #13 of the sigaction system call that verifies signal-catching functions are executed on the current stack if the SA_ONSTACK flag is cleared in the sigaction.sa_flags parameter to the sigaction function call. NOTE: This test case does not attempt to verify the proper operation of sigaltstack. */ #define _XOPEN_SOURCE 600 #include #include #include #include "posixtest.h" stack_t current; void handler(int signo) { stack_t oss; printf("Caught SIGCHLD\n"); if (sigaltstack((stack_t *)0, &oss) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); exit(-1); } if (oss.ss_sp != current.ss_sp || oss.ss_size != current.ss_size) { printf("Test FAILED\n"); exit(-1); } } int main() { struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); if (sigaction(SIGCHLD, &act, 0) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (sigaltstack((stack_t *)0, ¤t) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (raise(SIGCHLD) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/sigaction/23-11.c0100644000000000000000000001036010205365424022076 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertions: * * If SA_NODEFER is not set in sa_flags, the caught signal is added to the * thread's signal mask during the handler execution. * The steps are: * -> register a signal handler for SIGQUIT * -> raise SIGQUIT * -> In handler, check for reentrance then raise SIGQUIT again. * The test fails if signal handler if reentered or signal is not pending when raised again. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /******************************************************************************/ /*************************** standard includes ********************************/ /******************************************************************************/ #include #include #include #include #include #include #include #include /******************************************************************************/ /*************************** Test framework *******************************/ /******************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int * (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /******************************************************************************/ /**************************** Configuration ***********************************/ /******************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif #define SIGNAL SIGQUIT /******************************************************************************/ /*************************** Test case ***********************************/ /******************************************************************************/ int called = 0; void handler( int sig ) { int ret; sigset_t pending; called++; if ( called == 2 ) { FAILED( "Signal was not masked in signal handler" ); } if ( called == 1 ) { /* Raise the signal again. It should be masked */ ret = raise( SIGNAL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to raise SIGQUIT again" ); } /* check the signal is pending */ ret = sigpending( &pending ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to get pending signal set" ); } ret = sigismember( &pending, SIGNAL ); if ( ret != 1 ) { FAILED( "signal is not pending" ); } } called++; } /* main function */ int main() { int ret; struct sigaction sa; /* Initialize output */ output_init(); /* Set the signal handler */ sa.sa_flags = 0; sa.sa_handler = handler; ret = sigemptyset( &sa.sa_mask ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to empty signal set" ); } /* Install the signal handler for SIGQUIT */ ret = sigaction( SIGNAL, &sa, 0 ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to set signal handler" ); } ret = raise( SIGNAL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to raise SIGQUIT" ); } while ( called != 4 ) sched_yield(); /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/sigaction/2-16.c0100644000000000000000000000272007631716533022033 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #2 of the sigaction system call that shows sigaction (when used with a non-null oact pointer) changes the action for a signal. Steps: 1. Call sigaction to set handler for SIGTTOU to use handler1 2. Call sigaction again to set handler for SIGTTOU to use handler2, but this time use a non-null oarg and verify the sa_handler for oarg is set for handler1. */ #include #include #include "posixtest.h" int handler_called = 0; void handler1(int signo) { } void handler2(int signo) { } int main() { struct sigaction act; struct sigaction oact; act.sa_handler = handler1; act.sa_flags = 0; sigemptyset(&act.sa_mask); if (sigaction(SIGTTOU, &act, 0) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } act.sa_handler = handler2; sigemptyset(&act.sa_mask); if (sigaction(SIGTTOU, &act, &oact) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (oact.sa_handler == handler1) { printf("Test PASSED\n"); return PTS_PASS; } printf("Test Failed\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sigaction/25-23.c0100644000000000000000000000461107646610416022116 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #25 of the sigaction system call that verifies that when the sa_sigaction signal-catching function is entered, then the signal that was caught is added to the signal mask by raising that signal in the signal handler and verifying that the handler is not reentered. Steps: 1. Fork a new process 2. (parent) wait for child 3. (child) Setup a signal handler for SIGURG 4. (child) raise SIGURG 5. (child, signal handler) increment handler count 6. (child, signal handler) if count is 1 then raise SIGURG 7. (child, signal handler) if count is 2 then set error variable 8. (child) if error is set then return -1, else return 0 6. (parent - returning from wait) If child returned 0 then exit 0, otherwise exit -1. */ #include #include #include #include #include #include "posixtest.h" int handler_count = 0; int handler_error = 0; void handler(int signo) { static int inside_handler = 0; printf("SIGURG caught\n"); if (inside_handler) { printf("Signal caught while inside handler\n"); handler_error++; exit(-1); } inside_handler++; handler_count++; if (handler_count == 1) { printf("Raising SIGURG\n"); raise(SIGURG); printf("Returning from raising SIGURG\n"); } inside_handler--; } int main() { if (fork() == 0) { /* child */ struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); if (sigaction(SIGURG, &act, 0) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); return PTS_UNRESOLVED; } if (raise(SIGURG) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); return PTS_UNRESOLVED; } if (handler_error) return PTS_UNRESOLVED; return PTS_PASS; } else { int s; /* parent */ if (wait(&s) == -1) { perror("Unexpected error while setting up test " "pre-conditions"); return PTS_UNRESOLVED; } if (!WEXITSTATUS(s)) { printf("Test PASSED\n"); return PTS_PASS; } } printf("Test FAILED\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sigaction/12-45.c0100644000000000000000000000335507650040125022107 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #12 of the sigaction system call that verifies signal-catching functions are executed on the current stack if the SA_ONSTACK flag is set in the sigaction.sa_flags parameter to the sigaction function call, but a new stack has not be set by sigaltstack(). NOTE: This test case does not attempt to verify the proper operation of sigaltstack. */ #define _XOPEN_SOURCE 600 #include #include #include #include "posixtest.h" stack_t current; void handler(int signo) { stack_t oss; printf("Caught SIGPOLL\n"); if (sigaltstack((stack_t *)0, &oss) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); exit(-1); } if (oss.ss_sp != current.ss_sp || oss.ss_size != current.ss_size) { printf("Test FAILED\n"); exit(-1); } } int main() { struct sigaction act; act.sa_handler = handler; act.sa_flags = SA_ONSTACK; sigemptyset(&act.sa_mask); if (sigaction(SIGPOLL, &act, 0) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (sigaltstack((stack_t *)0, ¤t) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (raise(SIGPOLL) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/sigaction/8-15.c0100644000000000000000000000322107631716573022041 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #8 of the sigaction system call that verifies that if signals in the sa_mask (passed in the sigaction struct of the sigaction function call) are added to the process signal mask during execution of the signal-catching function. */ #include #include #include #include #include #include "posixtest.h" int SIGTSTP_count = 0; void SIGTSTP_handler(int signo) { SIGTSTP_count++; printf("Caught SIGTSTP\n"); } void SIGTTIN_handler(int signo) { printf("Caught SIGTTIN\n"); raise(SIGTSTP); if (SIGTSTP_count) { printf("Test FAILED\n"); exit(-1); } } int main() { struct sigaction act; act.sa_handler = SIGTTIN_handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); sigaddset(&act.sa_mask, SIGTSTP); if (sigaction(SIGTTIN, &act, 0) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); return PTS_UNRESOLVED; } act.sa_handler = SIGTSTP_handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); if (sigaction(SIGTSTP, &act, 0) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); return PTS_UNRESOLVED; } if (raise(SIGTTIN) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/sigaction/3-8.c0100644000000000000000000000276007631716557021767 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #3 of the sigaction system call that shows calling sigaction with a null act argument does not change the signal handler. Steps: 1. Initialize global variable to indicate handler has not been called 2. Set the signal handler for SIGILL to handler 3. Call sigaction with a null act 4. raise SIGILL 5. Verify handler was called. */ #include #include #include "posixtest.h" int handler_called = 0; void handler(int signo) { handler_called = 1; } int main() { struct sigaction act; struct sigaction oact; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); if (sigaction(SIGILL, &act, 0) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (sigaction(SIGILL, 0, &oact) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (raise(SIGILL) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (handler_called) { printf("Test PASSED\n"); return PTS_PASS; } printf("Test FAILED\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sigaction/28-8.c0100644000000000000000000001407310206323213022025 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertions: * * If the signal action was set with the signal() function, getting it into oact then reinstalling it with act must be valid. * The steps are: * -> register a signal handler for SIGILL with signal(). * -> check this signal handler works. * -> change the signal handler with sigaction, saving old handler in oact. * -> check the new signal handler works. * -> set the old signal handler back * -> check the old signal handler still works. * The test fails if a signal handler does not work as expected. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /******************************************************************************/ /*************************** standard includes ********************************/ /******************************************************************************/ #include #include #include #include #include #include #include /******************************************************************************/ /*************************** Test framework *******************************/ /******************************************************************************/ /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int * (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ #include "posixtest.h" #include #include #ifdef __GNUC__ /* We are using GCC */ #define UNRESOLVED(x, s) \ { output("Test %s unresolved: got %i (%s) on line %i (%s)\n", __FILE__, x, strerror(x), __LINE__, s); \ output_fini(); \ exit(PTS_UNRESOLVED); } #define FAILED(s) \ { output("Test %s FAILED: %s\n", __FILE__, s); \ output_fini(); \ exit(PTS_FAIL); } #define PASSED \ output_fini(); \ exit(PTS_PASS); #define UNTESTED(s) \ { output("File %s cannot test: %s\n", __FILE__, s); \ output_fini(); \ exit(PTS_UNTESTED); \ } #else /* not using GCC */ #define UNRESOLVED(x, s) \ { output("Test unresolved: got %i (%s) on line %i (%s)\n", x, strerror(x), __LINE__, s); \ output_fini(); \ exit(PTS_UNRESOLVED); } #define FAILED(s) \ { output("Test FAILED: %s\n", s); \ output_fini(); \ exit(PTS_FAIL); } #define PASSED \ output_fini(); \ exit(PTS_PASS); #define UNTESTED(s) \ { output("Unable to test: %s\n", s); \ output_fini(); \ exit(PTS_UNTESTED); \ } #endif void output_init() { /* do nothing */ return ; } void output( char * string, ... ) { va_list ap; #ifndef PLOT_OUTPUT char *ts = "[??:??:??]"; struct tm * now; time_t nw; #endif #ifndef PLOT_OUTPUT nw = time( NULL ); now = localtime( &nw ); if ( now == NULL ) printf( ts ); else printf( "[%2.2d:%2.2d:%2.2d]", now->tm_hour, now->tm_min, now->tm_sec ); #endif va_start( ap, string ); vprintf( string, ap ); va_end( ap ); } void output_fini() { /*do nothing */ return ; } /******************************************************************************/ /**************************** Configuration ***********************************/ /******************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif #define SIGNAL SIGILL /******************************************************************************/ /*************************** Test case ***********************************/ /******************************************************************************/ sig_atomic_t called = 1; void handler_1( int sig ) { called++; } void handler_2( int sig ) { called--; } /* main function */ int main() { int ret; struct sigaction sa, save; /* Initialize output */ output_init(); /* Register the signal handler with signal */ if ( SIG_ERR == signal( SIGNAL, handler_1 ) ) { UNRESOLVED( errno, "Failed to register signal handler with signal()" ); } /* As whether signal handler is restored to default when executed is implementation defined, we cannot check it was registered here. */ /* Set the new signal handler with sigaction*/ sa.sa_flags = 0; sa.sa_handler = handler_2; ret = sigemptyset( &sa.sa_mask ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to empty signal set" ); } /* Install the signal handler for SIGILL */ ret = sigaction( SIGNAL, &sa, &save ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to set signal handler" ); } /* Check the signal handler has been set up */ ret = raise( SIGNAL ); if ( ret != 0 ) { UNRESOLVED( ret , "Failed to raise the signal" ); } if ( called != 0 ) { FAILED( "handler not executed" ); } /* Restore the first signal handler */ ret = sigaction( SIGNAL, &save, 0 ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to set signal handler" ); } /* Check the signal handler has been set up */ ret = raise( SIGNAL ); if ( ret != 0 ) { UNRESOLVED( ret , "Failed to raise the signal" ); } if ( called != 1 ) { FAILED( "handler not executed" ); } /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/sigaction/18-11.c0100644000000000000000000000744110205365423022107 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertions: * * If SA_SIGINFO is not set in sa_flags, sa_handler is used as the signal * handling function. * The steps are: * -> register a handler for SIGQUIT without SA_SIGINFO, and a known function * as saèhandler * -> raise SIGQUIT, and check the function has been called. * The test fails if the function is not called */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /******************************************************************************/ /*************************** standard includes ********************************/ /******************************************************************************/ #include #include #include #include #include #include #include #include /******************************************************************************/ /*************************** Test framework *******************************/ /******************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int * (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /******************************************************************************/ /**************************** Configuration ***********************************/ /******************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif #define SIGNAL SIGQUIT /******************************************************************************/ /*************************** Test case ***********************************/ /******************************************************************************/ int called = 0; void handler( int sig ) { called = 1; } /* main function */ int main() { int ret; struct sigaction sa; /* Initialize output */ output_init(); /* Set the signal handler */ sa.sa_flags = 0; sa.sa_handler = handler; ret = sigemptyset( &sa.sa_mask ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to empty signal set" ); } /* Install the signal handler for SIGQUIT */ ret = sigaction( SIGNAL, &sa, 0 ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to set signal handler" ); } if ( called ) { FAILED( "The signal handler has been called when no signal was raised" ); } ret = raise( SIGNAL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to raise SIGQUIT" ); } if ( !called ) { FAILED( "the sa_handler was not called whereas SA_SIGINFO was not set" ); } /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/sigaction/6-24.c0100644000000000000000000000247307646610423022040 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #5 of the sigaction system call that verifies setting the SA_INFO bit in the signal mask for SIGVTALRM will result in sa_sigaction identifying the signal-catching function. */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include "posixtest.h" int handler_called = 0; void handler(int signo, siginfo_t *info, void *context) { handler_called = 1; } int main() { struct sigaction act; act.sa_sigaction = handler; act.sa_flags = SA_SIGINFO; sigemptyset(&act.sa_mask); sigaddset(&act.sa_mask, SIGSTOP); if (sigaction(SIGVTALRM, &act, 0) == -1) { printf("Unexpected error while attempting to setup test " "pre-conditions\n"); return PTS_UNRESOLVED; } if (raise(SIGVTALRM) == -1) { printf("Unexpected error while attempting to setup test " "pre-conditions\n"); return PTS_UNRESOLVED; } if (handler_called) { printf("Test PASSED\n"); return PTS_PASS; } printf("Test FAILED\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sigaction/22-2.c0100644000000000000000000000470507646610413022031 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #22 of the sigaction system call that verifies that if the SA_NODEFER flag is set for a given signal, then when the sa_sigaction signal-catching function is entered, then the signal that was caught is not added to the signal mask by raising that signal in the signal handler and verifying that the handler is reentered. Steps: 1. Fork a new process 2. (parent) wait for child 3. (child) Setup a signal handler for SIGALRM with SA_NODEFER set in the sa_flags field 4. (child) raise SIGALRM 5. (child, signal handler) increment handler count 6. (child, signal handler) if count is 1 then raise SIGALRM 7. (child, signal handler) if count is 1 then set error variable 8. (child) if error is set then return -1, else return 0 6. (parent - returning from wait) If child returned 0 then exit 0, otherwise exit -1. */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include "posixtest.h" int handler_count = 0; void handler(int signo) { static int inside_handler = 0; printf("SIGALRM caught\n"); if (inside_handler) { printf("Signal caught while inside handler\n"); exit(0); } inside_handler++; handler_count++; if (handler_count == 1) { printf("Raising SIGALRM\n"); raise(SIGALRM); printf("Returning from raising SIGALRM\n"); } inside_handler--; } int main() { if (fork() == 0) { /* child */ struct sigaction act; act.sa_handler = handler; act.sa_flags = SA_NODEFER; sigemptyset(&act.sa_mask); if (sigaction(SIGALRM, &act, 0) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); return PTS_UNRESOLVED; } if (raise(SIGALRM) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); return PTS_UNRESOLVED; } return PTS_FAIL; } else { int s; /* parent */ if (wait(&s) == -1) { perror("Unexpected error while setting up test " "pre-conditions"); return PTS_UNRESOLVED; } if (!WEXITSTATUS(s)) { printf("Test PASSED\n"); return PTS_PASS; } } printf("Test FAILED\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sigaction/4-32.c0100644000000000000000000000370107646624646022044 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #4 of the sigaction system call that shows that attempting to add SIGSTOP can not be added to the signal mask for a signal handler. Steps: 1. Fork a new process 2. (parent) wait for child 3. (child) Setup a signal handler for SIGFPE with SIGSTOP added to the signal mask 4. (child) raise SIGFPE 5. (child, signal handler) raise SIGSTOP 5. (child) If still around then return -1 6. (parent - returning from wait) If child was stopped then return kill the child and return success, otherwise fail. */ #include #include #include #include #include #include #include "posixtest.h" void handler(int signo) { printf("About to stop child\n"); raise(SIGSTOP); printf("Child has continued\n"); exit(0); } int main() { pid_t pid; if ((pid = fork()) == 0) { /* child */ struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); sigaddset(&act.sa_mask, SIGSTOP); if (sigaction(SIGFPE, &act, 0) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); return PTS_UNRESOLVED; } if (raise(SIGFPE) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); } return PTS_UNRESOLVED; } else { int s; /* parent */ if (waitpid(pid, &s, WUNTRACED) == -1) { perror("Unexpected error while setting up test " "pre-conditions"); return PTS_UNRESOLVED; } if (WIFSTOPPED(s)) { printf("Test PASSED\n"); kill(pid, SIGKILL); return PTS_PASS; } } printf("Test FAILED\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sigaction/4-100.c0100644000000000000000000000161007631716557022112 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #4 of the sigaction system call that shows that attempting to add SIGSTOP to the signal mask of SIGTRAP will not result in sigaction returning -1 */ #include #include #include #include #include #include "posixtest.h" void handler(int signo) { } int main() { struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); sigaddset(&act.sa_mask, SIGSTOP); if (sigaction(SIGTRAP, &act, 0) == -1) { printf("Test FAILED\n"); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/sigaction/4-35.c0100644000000000000000000000370107646624735022046 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #4 of the sigaction system call that shows that attempting to add SIGSTOP can not be added to the signal mask for a signal handler. Steps: 1. Fork a new process 2. (parent) wait for child 3. (child) Setup a signal handler for SIGINT with SIGSTOP added to the signal mask 4. (child) raise SIGINT 5. (child, signal handler) raise SIGSTOP 5. (child) If still around then return -1 6. (parent - returning from wait) If child was stopped then return kill the child and return success, otherwise fail. */ #include #include #include #include #include #include #include "posixtest.h" void handler(int signo) { printf("About to stop child\n"); raise(SIGSTOP); printf("Child has continued\n"); exit(0); } int main() { pid_t pid; if ((pid = fork()) == 0) { /* child */ struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); sigaddset(&act.sa_mask, SIGSTOP); if (sigaction(SIGINT, &act, 0) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); return PTS_UNRESOLVED; } if (raise(SIGINT) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); } return PTS_UNRESOLVED; } else { int s; /* parent */ if (waitpid(pid, &s, WUNTRACED) == -1) { perror("Unexpected error while setting up test " "pre-conditions"); return PTS_UNRESOLVED; } if (WIFSTOPPED(s)) { printf("Test PASSED\n"); kill(pid, SIGKILL); return PTS_PASS; } } printf("Test FAILED\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sigaction/25-9.c0100644000000000000000000000461107646610421022036 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #25 of the sigaction system call that verifies that when the sa_sigaction signal-catching function is entered, then the signal that was caught is added to the signal mask by raising that signal in the signal handler and verifying that the handler is not reentered. Steps: 1. Fork a new process 2. (parent) wait for child 3. (child) Setup a signal handler for SIGINT 4. (child) raise SIGINT 5. (child, signal handler) increment handler count 6. (child, signal handler) if count is 1 then raise SIGINT 7. (child, signal handler) if count is 2 then set error variable 8. (child) if error is set then return -1, else return 0 6. (parent - returning from wait) If child returned 0 then exit 0, otherwise exit -1. */ #include #include #include #include #include #include "posixtest.h" int handler_count = 0; int handler_error = 0; void handler(int signo) { static int inside_handler = 0; printf("SIGINT caught\n"); if (inside_handler) { printf("Signal caught while inside handler\n"); handler_error++; exit(-1); } inside_handler++; handler_count++; if (handler_count == 1) { printf("Raising SIGINT\n"); raise(SIGINT); printf("Returning from raising SIGINT\n"); } inside_handler--; } int main() { if (fork() == 0) { /* child */ struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); if (sigaction(SIGINT, &act, 0) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); return PTS_UNRESOLVED; } if (raise(SIGINT) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); return PTS_UNRESOLVED; } if (handler_error) return PTS_UNRESOLVED; return PTS_PASS; } else { int s; /* parent */ if (wait(&s) == -1) { perror("Unexpected error while setting up test " "pre-conditions"); return PTS_UNRESOLVED; } if (!WEXITSTATUS(s)) { printf("Test PASSED\n"); return PTS_PASS; } } printf("Test FAILED\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sigaction/6-2.c0100644000000000000000000000246507646610423021755 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #5 of the sigaction system call that verifies setting the SA_INFO bit in the signal mask for SIGALRM will result in sa_sigaction identifying the signal-catching function. */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include "posixtest.h" int handler_called = 0; void handler(int signo, siginfo_t *info, void *context) { handler_called = 1; } int main() { struct sigaction act; act.sa_sigaction = handler; act.sa_flags = SA_SIGINFO; sigemptyset(&act.sa_mask); sigaddset(&act.sa_mask, SIGSTOP); if (sigaction(SIGALRM, &act, 0) == -1) { printf("Unexpected error while attempting to setup test " "pre-conditions\n"); return PTS_UNRESOLVED; } if (raise(SIGALRM) == -1) { printf("Unexpected error while attempting to setup test " "pre-conditions\n"); return PTS_UNRESOLVED; } if (handler_called) { printf("Test PASSED\n"); return PTS_PASS; } printf("Test FAILED\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sigaction/28-15.c0100644000000000000000000001407610206323206022110 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertions: * * If the signal action was set with the signal() function, getting it into oact then reinstalling it with act must be valid. * The steps are: * -> register a signal handler for SIGTTIN with signal(). * -> check this signal handler works. * -> change the signal handler with sigaction, saving old handler in oact. * -> check the new signal handler works. * -> set the old signal handler back * -> check the old signal handler still works. * The test fails if a signal handler does not work as expected. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /******************************************************************************/ /*************************** standard includes ********************************/ /******************************************************************************/ #include #include #include #include #include #include #include /******************************************************************************/ /*************************** Test framework *******************************/ /******************************************************************************/ /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int * (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ #include "posixtest.h" #include #include #ifdef __GNUC__ /* We are using GCC */ #define UNRESOLVED(x, s) \ { output("Test %s unresolved: got %i (%s) on line %i (%s)\n", __FILE__, x, strerror(x), __LINE__, s); \ output_fini(); \ exit(PTS_UNRESOLVED); } #define FAILED(s) \ { output("Test %s FAILED: %s\n", __FILE__, s); \ output_fini(); \ exit(PTS_FAIL); } #define PASSED \ output_fini(); \ exit(PTS_PASS); #define UNTESTED(s) \ { output("File %s cannot test: %s\n", __FILE__, s); \ output_fini(); \ exit(PTS_UNTESTED); \ } #else /* not using GCC */ #define UNRESOLVED(x, s) \ { output("Test unresolved: got %i (%s) on line %i (%s)\n", x, strerror(x), __LINE__, s); \ output_fini(); \ exit(PTS_UNRESOLVED); } #define FAILED(s) \ { output("Test FAILED: %s\n", s); \ output_fini(); \ exit(PTS_FAIL); } #define PASSED \ output_fini(); \ exit(PTS_PASS); #define UNTESTED(s) \ { output("Unable to test: %s\n", s); \ output_fini(); \ exit(PTS_UNTESTED); \ } #endif void output_init() { /* do nothing */ return ; } void output( char * string, ... ) { va_list ap; #ifndef PLOT_OUTPUT char *ts = "[??:??:??]"; struct tm * now; time_t nw; #endif #ifndef PLOT_OUTPUT nw = time( NULL ); now = localtime( &nw ); if ( now == NULL ) printf( ts ); else printf( "[%2.2d:%2.2d:%2.2d]", now->tm_hour, now->tm_min, now->tm_sec ); #endif va_start( ap, string ); vprintf( string, ap ); va_end( ap ); } void output_fini() { /*do nothing */ return ; } /******************************************************************************/ /**************************** Configuration ***********************************/ /******************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif #define SIGNAL SIGTTIN /******************************************************************************/ /*************************** Test case ***********************************/ /******************************************************************************/ sig_atomic_t called = 1; void handler_1( int sig ) { called++; } void handler_2( int sig ) { called--; } /* main function */ int main() { int ret; struct sigaction sa, save; /* Initialize output */ output_init(); /* Register the signal handler with signal */ if ( SIG_ERR == signal( SIGNAL, handler_1 ) ) { UNRESOLVED( errno, "Failed to register signal handler with signal()" ); } /* As whether signal handler is restored to default when executed is implementation defined, we cannot check it was registered here. */ /* Set the new signal handler with sigaction*/ sa.sa_flags = 0; sa.sa_handler = handler_2; ret = sigemptyset( &sa.sa_mask ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to empty signal set" ); } /* Install the signal handler for SIGTTIN */ ret = sigaction( SIGNAL, &sa, &save ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to set signal handler" ); } /* Check the signal handler has been set up */ ret = raise( SIGNAL ); if ( ret != 0 ) { UNRESOLVED( ret , "Failed to raise the signal" ); } if ( called != 0 ) { FAILED( "handler not executed" ); } /* Restore the first signal handler */ ret = sigaction( SIGNAL, &save, 0 ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to set signal handler" ); } /* Check the signal handler has been set up */ ret = raise( SIGNAL ); if ( ret != 0 ) { UNRESOLVED( ret , "Failed to raise the signal" ); } if ( called != 1 ) { FAILED( "handler not executed" ); } /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/sigaction/18-18.c0100644000000000000000000000744110205365423022116 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertions: * * If SA_SIGINFO is not set in sa_flags, sa_handler is used as the signal * handling function. * The steps are: * -> register a handler for SIGUSR2 without SA_SIGINFO, and a known function * as saèhandler * -> raise SIGUSR2, and check the function has been called. * The test fails if the function is not called */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /******************************************************************************/ /*************************** standard includes ********************************/ /******************************************************************************/ #include #include #include #include #include #include #include #include /******************************************************************************/ /*************************** Test framework *******************************/ /******************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int * (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /******************************************************************************/ /**************************** Configuration ***********************************/ /******************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif #define SIGNAL SIGUSR2 /******************************************************************************/ /*************************** Test case ***********************************/ /******************************************************************************/ int called = 0; void handler( int sig ) { called = 1; } /* main function */ int main() { int ret; struct sigaction sa; /* Initialize output */ output_init(); /* Set the signal handler */ sa.sa_flags = 0; sa.sa_handler = handler; ret = sigemptyset( &sa.sa_mask ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to empty signal set" ); } /* Install the signal handler for SIGUSR2 */ ret = sigaction( SIGNAL, &sa, 0 ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to set signal handler" ); } if ( called ) { FAILED( "The signal handler has been called when no signal was raised" ); } ret = raise( SIGNAL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to raise SIGUSR2" ); } if ( !called ) { FAILED( "the sa_handler was not called whereas SA_SIGINFO was not set" ); } /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/sigaction/12-4.c0100644000000000000000000000372707646610406022037 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #12 of the sigaction system call that verifies signal-catching functions are executed on the alternate stack if the SA_ONSTACK flag is set in the sigaction.sa_flags parameter to the sigaction function call, and an alternate stack has been setup with sigaltstack(). NOTE: This test case does not attempt to verify the proper operation of sigaltstack. */ #define _XOPEN_SOURCE 600 #include #include #include #include "posixtest.h" stack_t alt_ss; void handler(int signo) { stack_t ss; printf("Caught SIGCHLD\n"); if (sigaltstack((stack_t *)0, &ss) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); exit(-1); } if (ss.ss_sp != alt_ss.ss_sp || ss.ss_size != alt_ss.ss_size) { printf("Test FAILED\n"); exit(-1); } } int main() { struct sigaction act; act.sa_handler = handler; act.sa_flags = SA_ONSTACK; sigemptyset(&act.sa_mask); if (sigaction(SIGCHLD, &act, 0) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if ((alt_ss.ss_sp = (void *)malloc(SIGSTKSZ)) == NULL) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } alt_ss.ss_size = SIGSTKSZ; alt_ss.ss_flags = 0; if (sigaltstack(&alt_ss, (stack_t *)0) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (raise(SIGCHLD) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/sigaction/4-67.c0100644000000000000000000000161007631716563022043 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #4 of the sigaction system call that shows that attempting to add SIGKILL to the signal mask of SIGTTIN will not result in sigaction returning -1 */ #include #include #include #include #include #include "posixtest.h" void handler(int signo) { } int main() { struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); sigaddset(&act.sa_mask, SIGKILL); if (sigaction(SIGTTIN, &act, 0) == -1) { printf("Test FAILED\n"); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/sigaction/18-6.c0100644000000000000000000000743410205365423022035 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertions: * * If SA_SIGINFO is not set in sa_flags, sa_handler is used as the signal * handling function. * The steps are: * -> register a handler for SIGFPE without SA_SIGINFO, and a known function * as saèhandler * -> raise SIGFPE, and check the function has been called. * The test fails if the function is not called */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /******************************************************************************/ /*************************** standard includes ********************************/ /******************************************************************************/ #include #include #include #include #include #include #include #include /******************************************************************************/ /*************************** Test framework *******************************/ /******************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int * (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /******************************************************************************/ /**************************** Configuration ***********************************/ /******************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif #define SIGNAL SIGFPE /******************************************************************************/ /*************************** Test case ***********************************/ /******************************************************************************/ int called = 0; void handler( int sig ) { called = 1; } /* main function */ int main() { int ret; struct sigaction sa; /* Initialize output */ output_init(); /* Set the signal handler */ sa.sa_flags = 0; sa.sa_handler = handler; ret = sigemptyset( &sa.sa_mask ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to empty signal set" ); } /* Install the signal handler for SIGFPE */ ret = sigaction( SIGNAL, &sa, 0 ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to set signal handler" ); } if ( called ) { FAILED( "The signal handler has been called when no signal was raised" ); } ret = raise( SIGNAL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to raise SIGFPE" ); } if ( !called ) { FAILED( "the sa_handler was not called whereas SA_SIGINFO was not set" ); } /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/sigaction/12-5.c0100644000000000000000000000372707646610406022040 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #12 of the sigaction system call that verifies signal-catching functions are executed on the alternate stack if the SA_ONSTACK flag is set in the sigaction.sa_flags parameter to the sigaction function call, and an alternate stack has been setup with sigaltstack(). NOTE: This test case does not attempt to verify the proper operation of sigaltstack. */ #define _XOPEN_SOURCE 600 #include #include #include #include "posixtest.h" stack_t alt_ss; void handler(int signo) { stack_t ss; printf("Caught SIGCONT\n"); if (sigaltstack((stack_t *)0, &ss) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); exit(-1); } if (ss.ss_sp != alt_ss.ss_sp || ss.ss_size != alt_ss.ss_size) { printf("Test FAILED\n"); exit(-1); } } int main() { struct sigaction act; act.sa_handler = handler; act.sa_flags = SA_ONSTACK; sigemptyset(&act.sa_mask); if (sigaction(SIGCONT, &act, 0) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if ((alt_ss.ss_sp = (void *)malloc(SIGSTKSZ)) == NULL) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } alt_ss.ss_size = SIGSTKSZ; alt_ss.ss_flags = 0; if (sigaltstack(&alt_ss, (stack_t *)0) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (raise(SIGCONT) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/sigaction/13-3.c0100644000000000000000000000326707646610411022032 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #13 of the sigaction system call that verifies signal-catching functions are executed on the current stack if the SA_ONSTACK flag is cleared in the sigaction.sa_flags parameter to the sigaction function call. NOTE: This test case does not attempt to verify the proper operation of sigaltstack. */ #define _XOPEN_SOURCE 600 #include #include #include #include "posixtest.h" stack_t current; void handler(int signo) { stack_t oss; printf("Caught SIGBUS\n"); if (sigaltstack((stack_t *)0, &oss) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); exit(-1); } if (oss.ss_sp != current.ss_sp || oss.ss_size != current.ss_size) { printf("Test FAILED\n"); exit(-1); } } int main() { struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); if (sigaction(SIGBUS, &act, 0) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (sigaltstack((stack_t *)0, ¤t) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (raise(SIGBUS) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/sigaction/22-3.c0100644000000000000000000000467407646610413022037 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #22 of the sigaction system call that verifies that if the SA_NODEFER flag is set for a given signal, then when the sa_sigaction signal-catching function is entered, then the signal that was caught is not added to the signal mask by raising that signal in the signal handler and verifying that the handler is reentered. Steps: 1. Fork a new process 2. (parent) wait for child 3. (child) Setup a signal handler for SIGBUS with SA_NODEFER set in the sa_flags field 4. (child) raise SIGBUS 5. (child, signal handler) increment handler count 6. (child, signal handler) if count is 1 then raise SIGBUS 7. (child, signal handler) if count is 1 then set error variable 8. (child) if error is set then return -1, else return 0 6. (parent - returning from wait) If child returned 0 then exit 0, otherwise exit -1. */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include "posixtest.h" int handler_count = 0; void handler(int signo) { static int inside_handler = 0; printf("SIGBUS caught\n"); if (inside_handler) { printf("Signal caught while inside handler\n"); exit(0); } inside_handler++; handler_count++; if (handler_count == 1) { printf("Raising SIGBUS\n"); raise(SIGBUS); printf("Returning from raising SIGBUS\n"); } inside_handler--; } int main() { if (fork() == 0) { /* child */ struct sigaction act; act.sa_handler = handler; act.sa_flags = SA_NODEFER; sigemptyset(&act.sa_mask); if (sigaction(SIGBUS, &act, 0) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); return PTS_UNRESOLVED; } if (raise(SIGBUS) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); return PTS_UNRESOLVED; } return PTS_FAIL; } else { int s; /* parent */ if (wait(&s) == -1) { perror("Unexpected error while setting up test " "pre-conditions"); return PTS_UNRESOLVED; } if (!WEXITSTATUS(s)) { printf("Test PASSED\n"); return PTS_PASS; } } printf("Test FAILED\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sigaction/13-14.c0100644000000000000000000000327207646610406022114 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #13 of the sigaction system call that verifies signal-catching functions are executed on the current stack if the SA_ONSTACK flag is cleared in the sigaction.sa_flags parameter to the sigaction function call. NOTE: This test case does not attempt to verify the proper operation of sigaltstack. */ #define _XOPEN_SOURCE 600 #include #include #include #include "posixtest.h" stack_t current; void handler(int signo) { stack_t oss; printf("Caught SIGTSTP\n"); if (sigaltstack((stack_t *)0, &oss) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); exit(-1); } if (oss.ss_sp != current.ss_sp || oss.ss_size != current.ss_size) { printf("Test FAILED\n"); exit(-1); } } int main() { struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); if (sigaction(SIGTSTP, &act, 0) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (sigaltstack((stack_t *)0, ¤t) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (raise(SIGTSTP) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/sigaction/6-22.c0100644000000000000000000000246507646610423022037 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #5 of the sigaction system call that verifies setting the SA_INFO bit in the signal mask for SIGTRAP will result in sa_sigaction identifying the signal-catching function. */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include "posixtest.h" int handler_called = 0; void handler(int signo, siginfo_t *info, void *context) { handler_called = 1; } int main() { struct sigaction act; act.sa_sigaction = handler; act.sa_flags = SA_SIGINFO; sigemptyset(&act.sa_mask); sigaddset(&act.sa_mask, SIGSTOP); if (sigaction(SIGTRAP, &act, 0) == -1) { printf("Unexpected error while attempting to setup test " "pre-conditions\n"); return PTS_UNRESOLVED; } if (raise(SIGTRAP) == -1) { printf("Unexpected error while attempting to setup test " "pre-conditions\n"); return PTS_UNRESOLVED; } if (handler_called) { printf("Test PASSED\n"); return PTS_PASS; } printf("Test FAILED\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sigaction/4-74.c0100644000000000000000000000161007631716564022042 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #4 of the sigaction system call that shows that attempting to add SIGKILL to the signal mask of SIGTRAP will not result in sigaction returning -1 */ #include #include #include #include #include #include "posixtest.h" void handler(int signo) { } int main() { struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); sigaddset(&act.sa_mask, SIGKILL); if (sigaction(SIGTRAP, &act, 0) == -1) { printf("Test FAILED\n"); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/sigaction/28-24.c0100644000000000000000000001410410206323212022075 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertions: * * If the signal action was set with the signal() function, getting it into oact then reinstalling it with act must be valid. * The steps are: * -> register a signal handler for SIGVTALRM with signal(). * -> check this signal handler works. * -> change the signal handler with sigaction, saving old handler in oact. * -> check the new signal handler works. * -> set the old signal handler back * -> check the old signal handler still works. * The test fails if a signal handler does not work as expected. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /******************************************************************************/ /*************************** standard includes ********************************/ /******************************************************************************/ #include #include #include #include #include #include #include /******************************************************************************/ /*************************** Test framework *******************************/ /******************************************************************************/ /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int * (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ #include "posixtest.h" #include #include #ifdef __GNUC__ /* We are using GCC */ #define UNRESOLVED(x, s) \ { output("Test %s unresolved: got %i (%s) on line %i (%s)\n", __FILE__, x, strerror(x), __LINE__, s); \ output_fini(); \ exit(PTS_UNRESOLVED); } #define FAILED(s) \ { output("Test %s FAILED: %s\n", __FILE__, s); \ output_fini(); \ exit(PTS_FAIL); } #define PASSED \ output_fini(); \ exit(PTS_PASS); #define UNTESTED(s) \ { output("File %s cannot test: %s\n", __FILE__, s); \ output_fini(); \ exit(PTS_UNTESTED); \ } #else /* not using GCC */ #define UNRESOLVED(x, s) \ { output("Test unresolved: got %i (%s) on line %i (%s)\n", x, strerror(x), __LINE__, s); \ output_fini(); \ exit(PTS_UNRESOLVED); } #define FAILED(s) \ { output("Test FAILED: %s\n", s); \ output_fini(); \ exit(PTS_FAIL); } #define PASSED \ output_fini(); \ exit(PTS_PASS); #define UNTESTED(s) \ { output("Unable to test: %s\n", s); \ output_fini(); \ exit(PTS_UNTESTED); \ } #endif void output_init() { /* do nothing */ return ; } void output( char * string, ... ) { va_list ap; #ifndef PLOT_OUTPUT char *ts = "[??:??:??]"; struct tm * now; time_t nw; #endif #ifndef PLOT_OUTPUT nw = time( NULL ); now = localtime( &nw ); if ( now == NULL ) printf( ts ); else printf( "[%2.2d:%2.2d:%2.2d]", now->tm_hour, now->tm_min, now->tm_sec ); #endif va_start( ap, string ); vprintf( string, ap ); va_end( ap ); } void output_fini() { /*do nothing */ return ; } /******************************************************************************/ /**************************** Configuration ***********************************/ /******************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif #define SIGNAL SIGVTALRM /******************************************************************************/ /*************************** Test case ***********************************/ /******************************************************************************/ sig_atomic_t called = 1; void handler_1( int sig ) { called++; } void handler_2( int sig ) { called--; } /* main function */ int main() { int ret; struct sigaction sa, save; /* Initialize output */ output_init(); /* Register the signal handler with signal */ if ( SIG_ERR == signal( SIGNAL, handler_1 ) ) { UNRESOLVED( errno, "Failed to register signal handler with signal()" ); } /* As whether signal handler is restored to default when executed is implementation defined, we cannot check it was registered here. */ /* Set the new signal handler with sigaction*/ sa.sa_flags = 0; sa.sa_handler = handler_2; ret = sigemptyset( &sa.sa_mask ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to empty signal set" ); } /* Install the signal handler for SIGVTALRM */ ret = sigaction( SIGNAL, &sa, &save ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to set signal handler" ); } /* Check the signal handler has been set up */ ret = raise( SIGNAL ); if ( ret != 0 ) { UNRESOLVED( ret , "Failed to raise the signal" ); } if ( called != 0 ) { FAILED( "handler not executed" ); } /* Restore the first signal handler */ ret = sigaction( SIGNAL, &save, 0 ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to set signal handler" ); } /* Check the signal handler has been set up */ ret = raise( SIGNAL ); if ( ret != 0 ) { UNRESOLVED( ret , "Failed to raise the signal" ); } if ( called != 1 ) { FAILED( "handler not executed" ); } /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/sigaction/4-58.c0100644000000000000000000000160607631716563022050 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #4 of the sigaction system call that shows that attempting to add SIGKILL to the signal mask of SIGFPE will not result in sigaction returning -1 */ #include #include #include #include #include #include "posixtest.h" void handler(int signo) { } int main() { struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); sigaddset(&act.sa_mask, SIGKILL); if (sigaction(SIGFPE, &act, 0) == -1) { printf("Test FAILED\n"); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/sigaction/2-23.c0100644000000000000000000000271407631716534022035 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #2 of the sigaction system call that shows sigaction (when used with a non-null oact pointer) changes the action for a signal. Steps: 1. Call sigaction to set handler for SIGURG to use handler1 2. Call sigaction again to set handler for SIGURG to use handler2, but this time use a non-null oarg and verify the sa_handler for oarg is set for handler1. */ #include #include #include "posixtest.h" int handler_called = 0; void handler1(int signo) { } void handler2(int signo) { } int main() { struct sigaction act; struct sigaction oact; act.sa_handler = handler1; act.sa_flags = 0; sigemptyset(&act.sa_mask); if (sigaction(SIGURG, &act, 0) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } act.sa_handler = handler2; sigemptyset(&act.sa_mask); if (sigaction(SIGURG, &act, &oact) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (oact.sa_handler == handler1) { printf("Test PASSED\n"); return PTS_PASS; } printf("Test Failed\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sigaction/19-19.c0100644000000000000000000001017610205365423022117 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertions: * * If SA_SIGINFO is set in sa_flags and Real Time Signals extension is supported, * sa_sigaction is used as the signal handling function. * The steps are: * -> test for RTS extension * -> register a handler for SIGPOLL with SA_SIGINFO, and a known function * as sa_sigaction * -> raise SIGPOLL, and check the function has been called. * The test fails if the function is not called */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /******************************************************************************/ /*************************** standard includes ********************************/ /******************************************************************************/ #include #include #include #include #include #include #include #include /******************************************************************************/ /*************************** Test framework *******************************/ /******************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int * (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /******************************************************************************/ /**************************** Configuration ***********************************/ /******************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif #define SIGNAL SIGPOLL /******************************************************************************/ /*************************** Test case ***********************************/ /******************************************************************************/ int called = 0; void handler( int sig, siginfo_t *info, void *context ) { if ( info->si_signo != SIGNAL ) { FAILED( "Wrong signal generated?" ); } called = 1; } /* main function */ int main() { int ret; long rts; struct sigaction sa; /* Initialize output */ output_init(); /* Test the RTS extension */ rts = sysconf( _SC_REALTIME_SIGNALS ); if ( rts < 0L ) { UNTESTED( "This test needs the RTS extension" ); } /* Set the signal handler */ sa.sa_flags = SA_SIGINFO; sa.sa_sigaction = handler; ret = sigemptyset( &sa.sa_mask ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to empty signal set" ); } /* Install the signal handler for SIGPOLL */ ret = sigaction( SIGNAL, &sa, 0 ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to set signal handler" ); } if ( called ) { FAILED( "The signal handler has been called when no signal was raised" ); } ret = raise( SIGNAL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to raise SIGPOLL" ); } if ( !called ) { FAILED( "the sa_handler was not called whereas SA_SIGINFO was not set" ); } /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/sigaction/3-13.c0100644000000000000000000000276507631716554022045 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #3 of the sigaction system call that shows calling sigaction with a null act argument does not change the signal handler. Steps: 1. Initialize global variable to indicate handler has not been called 2. Set the signal handler for SIGTERM to handler 3. Call sigaction with a null act 4. raise SIGTERM 5. Verify handler was called. */ #include #include #include "posixtest.h" int handler_called = 0; void handler(int signo) { handler_called = 1; } int main() { struct sigaction act; struct sigaction oact; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); if (sigaction(SIGTERM, &act, 0) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (sigaction(SIGTERM, 0, &oact) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (raise(SIGTERM) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (handler_called) { printf("Test PASSED\n"); return PTS_PASS; } printf("Test FAILED\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sigaction/4-40.c0100644000000000000000000000370507646625056022043 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #4 of the sigaction system call that shows that attempting to add SIGSTOP can not be added to the signal mask for a signal handler. Steps: 1. Fork a new process 2. (parent) wait for child 3. (child) Setup a signal handler for SIGTSTP with SIGSTOP added to the signal mask 4. (child) raise SIGTSTP 5. (child, signal handler) raise SIGSTOP 5. (child) If still around then return -1 6. (parent - returning from wait) If child was stopped then return kill the child and return success, otherwise fail. */ #include #include #include #include #include #include #include "posixtest.h" void handler(int signo) { printf("About to stop child\n"); raise(SIGSTOP); printf("Child has continued\n"); exit(0); } int main() { pid_t pid; if ((pid = fork()) == 0) { /* child */ struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); sigaddset(&act.sa_mask, SIGSTOP); if (sigaction(SIGTSTP, &act, 0) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); return PTS_UNRESOLVED; } if (raise(SIGTSTP) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); } return PTS_UNRESOLVED; } else { int s; /* parent */ if (waitpid(pid, &s, WUNTRACED) == -1) { perror("Unexpected error while setting up test " "pre-conditions"); return PTS_UNRESOLVED; } if (WIFSTOPPED(s)) { printf("Test PASSED\n"); kill(pid, SIGKILL); return PTS_PASS; } } printf("Test FAILED\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sigaction/17-24.c0100644000000000000000000000421710205365423022110 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test assertion #17 by verifying that select returns -1 with errno set to EINTR if a handler for the SIGVTALRM signal is setup with the SA_RESTART flag cleared. * 12/18/02 - Adding in include of sys/time.h per * rodrigc REMOVE-THIS AT attbi DOT com input that it needs * to be included whenever the timeval struct is used. */ #include #include #include #include #include #include #include #include #include #include "posixtest.h" volatile sig_atomic_t wakeup = 1; void handler(int signo) { printf("Caught SIGVTALRM\n"); wakeup++; } int main() { pid_t pid; struct timeval tv; if ((pid = fork()) == 0) { /* child */ struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); sigaction(SIGVTALRM, &act, 0); while(wakeup == 1) { tv.tv_sec = 3; tv.tv_usec = 0; if (select(0, NULL, NULL, NULL, &tv)== -1 && errno == EINTR) { perror("select"); return PTS_PASS; } } return PTS_FAIL; } else { /* parent */ int s; /* There is a race condition between the parent process sending the SIGVTALRM signal, and the child process being inside the 'select' function call. I could not find a pure POSIX method for determining the state of the child process, so I just added a delay so that the test is valid in most conditions. (The problem is that it would be perfectly legal for a POSIX conformant OS to not schedule the child process for a long time.) */ tv.tv_sec = 1; tv.tv_usec = 0; select(0, NULL, NULL, NULL, &tv); kill(pid, SIGVTALRM); waitpid(pid, &s, 0); if (WEXITSTATUS(s) == PTS_PASS) { printf("Test PASSED\n"); return PTS_PASS; } } printf("Test FAILED\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sigaction/23-8.c0100644000000000000000000001035110205365424022024 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertions: * * If SA_NODEFER is not set in sa_flags, the caught signal is added to the * thread's signal mask during the handler execution. * The steps are: * -> register a signal handler for SIGILL * -> raise SIGILL * -> In handler, check for reentrance then raise SIGILL again. * The test fails if signal handler if reentered or signal is not pending when raised again. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /******************************************************************************/ /*************************** standard includes ********************************/ /******************************************************************************/ #include #include #include #include #include #include #include #include /******************************************************************************/ /*************************** Test framework *******************************/ /******************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int * (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /******************************************************************************/ /**************************** Configuration ***********************************/ /******************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif #define SIGNAL SIGILL /******************************************************************************/ /*************************** Test case ***********************************/ /******************************************************************************/ int called = 0; void handler( int sig ) { int ret; sigset_t pending; called++; if ( called == 2 ) { FAILED( "Signal was not masked in signal handler" ); } if ( called == 1 ) { /* Raise the signal again. It should be masked */ ret = raise( SIGNAL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to raise SIGILL again" ); } /* check the signal is pending */ ret = sigpending( &pending ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to get pending signal set" ); } ret = sigismember( &pending, SIGNAL ); if ( ret != 1 ) { FAILED( "signal is not pending" ); } } called++; } /* main function */ int main() { int ret; struct sigaction sa; /* Initialize output */ output_init(); /* Set the signal handler */ sa.sa_flags = 0; sa.sa_handler = handler; ret = sigemptyset( &sa.sa_mask ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to empty signal set" ); } /* Install the signal handler for SIGILL */ ret = sigaction( SIGNAL, &sa, 0 ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to set signal handler" ); } ret = raise( SIGNAL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to raise SIGILL" ); } while ( called != 4 ) sched_yield(); /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/sigaction/12-48.c0100644000000000000000000000335507650040125022112 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #12 of the sigaction system call that verifies signal-catching functions are executed on the current stack if the SA_ONSTACK flag is set in the sigaction.sa_flags parameter to the sigaction function call, but a new stack has not be set by sigaltstack(). NOTE: This test case does not attempt to verify the proper operation of sigaltstack. */ #define _XOPEN_SOURCE 600 #include #include #include #include "posixtest.h" stack_t current; void handler(int signo) { stack_t oss; printf("Caught SIGTRAP\n"); if (sigaltstack((stack_t *)0, &oss) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); exit(-1); } if (oss.ss_sp != current.ss_sp || oss.ss_size != current.ss_size) { printf("Test FAILED\n"); exit(-1); } } int main() { struct sigaction act; act.sa_handler = handler; act.sa_flags = SA_ONSTACK; sigemptyset(&act.sa_mask); if (sigaction(SIGTRAP, &act, 0) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (sigaltstack((stack_t *)0, ¤t) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (raise(SIGTRAP) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/sigaction/17-12.c0100644000000000000000000000420510205365423022102 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test assertion #17 by verifying that select returns -1 with errno set to EINTR if a handler for the SIGSEGV signal is setup with the SA_RESTART flag cleared. * 12/18/02 - Adding in include of sys/time.h per * rodrigc REMOVE-THIS AT attbi DOT com input that it needs * to be included whenever the timeval struct is used. */ #include #include #include #include #include #include #include #include #include #include "posixtest.h" volatile sig_atomic_t wakeup = 1; void handler(int signo) { printf("Caught SIGSEGV\n"); wakeup++; } int main() { pid_t pid; struct timeval tv; if ((pid = fork()) == 0) { /* child */ struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); sigaction(SIGSEGV, &act, 0); while(wakeup == 1) { tv.tv_sec = 3; tv.tv_usec = 0; if (select(0, NULL, NULL, NULL, &tv)== -1 && errno == EINTR) { perror("select"); return PTS_PASS; } } return PTS_FAIL; } else { /* parent */ int s; /* There is a race condition between the parent process sending the SIGSEGV signal, and the child process being inside the 'select' function call. I could not find a pure POSIX method for determining the state of the child process, so I just added a delay so that the test is valid in most conditions. (The problem is that it would be perfectly legal for a POSIX conformant OS to not schedule the child process for a long time.) */ tv.tv_sec = 1; tv.tv_usec = 0; select(0, NULL, NULL, NULL, &tv); kill(pid, SIGSEGV); waitpid(pid, &s, 0); if (WEXITSTATUS(s) == PTS_PASS) { printf("Test PASSED\n"); return PTS_PASS; } } printf("Test FAILED\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sigaction/13-12.c0100644000000000000000000000327207646610406022112 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #13 of the sigaction system call that verifies signal-catching functions are executed on the current stack if the SA_ONSTACK flag is cleared in the sigaction.sa_flags parameter to the sigaction function call. NOTE: This test case does not attempt to verify the proper operation of sigaltstack. */ #define _XOPEN_SOURCE 600 #include #include #include #include "posixtest.h" stack_t current; void handler(int signo) { stack_t oss; printf("Caught SIGSEGV\n"); if (sigaltstack((stack_t *)0, &oss) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); exit(-1); } if (oss.ss_sp != current.ss_sp || oss.ss_size != current.ss_size) { printf("Test FAILED\n"); exit(-1); } } int main() { struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); if (sigaction(SIGSEGV, &act, 0) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (sigaltstack((stack_t *)0, ¤t) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (raise(SIGSEGV) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/sigaction/1-12.c0100644000000000000000000000270407631716431022025 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: Rusty.Lnch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #1 of the sigaction system call that shows sigaction (when used with a non-null act pointer) changes the action for a signal. Steps: 1. Initialize a global variable to indicate the signal handler has not been called. (A signal handler of the prototype "void func(int signo);" will set the global variable to indicate otherwise. 2. Use sigaction to setup a signal handler for SIGSEGV 3. Raise SIGSEGV. 4. Verify the global indicates the signal was called. */ #include #include #include "posixtest.h" int handler_called = 0; void handler(int signo) { handler_called = 1; } int main() { struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); if (sigaction(SIGSEGV, &act, 0) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (raise(SIGSEGV) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (handler_called) { printf("Test PASSED\n"); return PTS_PASS; } printf("Test FAILED\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sigaction/2-22.c0100644000000000000000000000272007631716534022031 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #2 of the sigaction system call that shows sigaction (when used with a non-null oact pointer) changes the action for a signal. Steps: 1. Call sigaction to set handler for SIGTRAP to use handler1 2. Call sigaction again to set handler for SIGTRAP to use handler2, but this time use a non-null oarg and verify the sa_handler for oarg is set for handler1. */ #include #include #include "posixtest.h" int handler_called = 0; void handler1(int signo) { } void handler2(int signo) { } int main() { struct sigaction act; struct sigaction oact; act.sa_handler = handler1; act.sa_flags = 0; sigemptyset(&act.sa_mask); if (sigaction(SIGTRAP, &act, 0) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } act.sa_handler = handler2; sigemptyset(&act.sa_mask); if (sigaction(SIGTRAP, &act, &oact) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (oact.sa_handler == handler1) { printf("Test PASSED\n"); return PTS_PASS; } printf("Test Failed\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sigaction/17-1.c0100644000000000000000000000420510205365423022020 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test assertion #17 by verifying that select returns -1 with errno set to EINTR if a handler for the SIGABRT signal is setup with the SA_RESTART flag cleared. * 12/18/02 - Adding in include of sys/time.h per * rodrigc REMOVE-THIS AT attbi DOT com input that it needs * to be included whenever the timeval struct is used. */ #include #include #include #include #include #include #include #include #include #include "posixtest.h" volatile sig_atomic_t wakeup = 1; void handler(int signo) { printf("Caught SIGABRT\n"); wakeup++; } int main() { pid_t pid; struct timeval tv; if ((pid = fork()) == 0) { /* child */ struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); sigaction(SIGABRT, &act, 0); while(wakeup == 1) { tv.tv_sec = 3; tv.tv_usec = 0; if (select(0, NULL, NULL, NULL, &tv)== -1 && errno == EINTR) { perror("select"); return PTS_PASS; } } return PTS_FAIL; } else { /* parent */ int s; /* There is a race condition between the parent process sending the SIGABRT signal, and the child process being inside the 'select' function call. I could not find a pure POSIX method for determining the state of the child process, so I just added a delay so that the test is valid in most conditions. (The problem is that it would be perfectly legal for a POSIX conformant OS to not schedule the child process for a long time.) */ tv.tv_sec = 1; tv.tv_usec = 0; select(0, NULL, NULL, NULL, &tv); kill(pid, SIGABRT); waitpid(pid, &s, 0); if (WEXITSTATUS(s) == PTS_PASS) { printf("Test PASSED\n"); return PTS_PASS; } } printf("Test FAILED\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sigaction/19-1.c0100644000000000000000000001017610205365423022026 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertions: * * If SA_SIGINFO is set in sa_flags and Real Time Signals extension is supported, * sa_sigaction is used as the signal handling function. * The steps are: * -> test for RTS extension * -> register a handler for SIGABRT with SA_SIGINFO, and a known function * as sa_sigaction * -> raise SIGABRT, and check the function has been called. * The test fails if the function is not called */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /******************************************************************************/ /*************************** standard includes ********************************/ /******************************************************************************/ #include #include #include #include #include #include #include #include /******************************************************************************/ /*************************** Test framework *******************************/ /******************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int * (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /******************************************************************************/ /**************************** Configuration ***********************************/ /******************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif #define SIGNAL SIGABRT /******************************************************************************/ /*************************** Test case ***********************************/ /******************************************************************************/ int called = 0; void handler( int sig, siginfo_t *info, void *context ) { if ( info->si_signo != SIGNAL ) { FAILED( "Wrong signal generated?" ); } called = 1; } /* main function */ int main() { int ret; long rts; struct sigaction sa; /* Initialize output */ output_init(); /* Test the RTS extension */ rts = sysconf( _SC_REALTIME_SIGNALS ); if ( rts < 0L ) { UNTESTED( "This test needs the RTS extension" ); } /* Set the signal handler */ sa.sa_flags = SA_SIGINFO; sa.sa_sigaction = handler; ret = sigemptyset( &sa.sa_mask ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to empty signal set" ); } /* Install the signal handler for SIGABRT */ ret = sigaction( SIGNAL, &sa, 0 ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to set signal handler" ); } if ( called ) { FAILED( "The signal handler has been called when no signal was raised" ); } ret = raise( SIGNAL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to raise SIGABRT" ); } if ( !called ) { FAILED( "the sa_handler was not called whereas SA_SIGINFO was not set" ); } /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/sigaction/13-17.c0100644000000000000000000000327207646610406022117 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #13 of the sigaction system call that verifies signal-catching functions are executed on the current stack if the SA_ONSTACK flag is cleared in the sigaction.sa_flags parameter to the sigaction function call. NOTE: This test case does not attempt to verify the proper operation of sigaltstack. */ #define _XOPEN_SOURCE 600 #include #include #include #include "posixtest.h" stack_t current; void handler(int signo) { stack_t oss; printf("Caught SIGUSR1\n"); if (sigaltstack((stack_t *)0, &oss) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); exit(-1); } if (oss.ss_sp != current.ss_sp || oss.ss_size != current.ss_size) { printf("Test FAILED\n"); exit(-1); } } int main() { struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); if (sigaction(SIGUSR1, &act, 0) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (sigaltstack((stack_t *)0, ¤t) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (raise(SIGUSR1) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/sigaction/3-12.c0100644000000000000000000000276507631716554022044 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #3 of the sigaction system call that shows calling sigaction with a null act argument does not change the signal handler. Steps: 1. Initialize global variable to indicate handler has not been called 2. Set the signal handler for SIGSEGV to handler 3. Call sigaction with a null act 4. raise SIGSEGV 5. Verify handler was called. */ #include #include #include "posixtest.h" int handler_called = 0; void handler(int signo) { handler_called = 1; } int main() { struct sigaction act; struct sigaction oact; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); if (sigaction(SIGSEGV, &act, 0) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (sigaction(SIGSEGV, 0, &oact) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (raise(SIGSEGV) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (handler_called) { printf("Test PASSED\n"); return PTS_PASS; } printf("Test FAILED\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sigaction/12-11.c0100644000000000000000000000372707646610402022111 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #12 of the sigaction system call that verifies signal-catching functions are executed on the alternate stack if the SA_ONSTACK flag is set in the sigaction.sa_flags parameter to the sigaction function call, and an alternate stack has been setup with sigaltstack(). NOTE: This test case does not attempt to verify the proper operation of sigaltstack. */ #define _XOPEN_SOURCE 600 #include #include #include #include "posixtest.h" stack_t alt_ss; void handler(int signo) { stack_t ss; printf("Caught SIGQUIT\n"); if (sigaltstack((stack_t *)0, &ss) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); exit(-1); } if (ss.ss_sp != alt_ss.ss_sp || ss.ss_size != alt_ss.ss_size) { printf("Test FAILED\n"); exit(-1); } } int main() { struct sigaction act; act.sa_handler = handler; act.sa_flags = SA_ONSTACK; sigemptyset(&act.sa_mask); if (sigaction(SIGQUIT, &act, 0) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if ((alt_ss.ss_sp = (void *)malloc(SIGSTKSZ)) == NULL) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } alt_ss.ss_size = SIGSTKSZ; alt_ss.ss_flags = 0; if (sigaltstack(&alt_ss, (stack_t *)0) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (raise(SIGQUIT) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/sigaction/28-19.c0100644000000000000000000001407610206323210022107 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertions: * * If the signal action was set with the signal() function, getting it into oact then reinstalling it with act must be valid. * The steps are: * -> register a signal handler for SIGPOLL with signal(). * -> check this signal handler works. * -> change the signal handler with sigaction, saving old handler in oact. * -> check the new signal handler works. * -> set the old signal handler back * -> check the old signal handler still works. * The test fails if a signal handler does not work as expected. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /******************************************************************************/ /*************************** standard includes ********************************/ /******************************************************************************/ #include #include #include #include #include #include #include /******************************************************************************/ /*************************** Test framework *******************************/ /******************************************************************************/ /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int * (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ #include "posixtest.h" #include #include #ifdef __GNUC__ /* We are using GCC */ #define UNRESOLVED(x, s) \ { output("Test %s unresolved: got %i (%s) on line %i (%s)\n", __FILE__, x, strerror(x), __LINE__, s); \ output_fini(); \ exit(PTS_UNRESOLVED); } #define FAILED(s) \ { output("Test %s FAILED: %s\n", __FILE__, s); \ output_fini(); \ exit(PTS_FAIL); } #define PASSED \ output_fini(); \ exit(PTS_PASS); #define UNTESTED(s) \ { output("File %s cannot test: %s\n", __FILE__, s); \ output_fini(); \ exit(PTS_UNTESTED); \ } #else /* not using GCC */ #define UNRESOLVED(x, s) \ { output("Test unresolved: got %i (%s) on line %i (%s)\n", x, strerror(x), __LINE__, s); \ output_fini(); \ exit(PTS_UNRESOLVED); } #define FAILED(s) \ { output("Test FAILED: %s\n", s); \ output_fini(); \ exit(PTS_FAIL); } #define PASSED \ output_fini(); \ exit(PTS_PASS); #define UNTESTED(s) \ { output("Unable to test: %s\n", s); \ output_fini(); \ exit(PTS_UNTESTED); \ } #endif void output_init() { /* do nothing */ return ; } void output( char * string, ... ) { va_list ap; #ifndef PLOT_OUTPUT char *ts = "[??:??:??]"; struct tm * now; time_t nw; #endif #ifndef PLOT_OUTPUT nw = time( NULL ); now = localtime( &nw ); if ( now == NULL ) printf( ts ); else printf( "[%2.2d:%2.2d:%2.2d]", now->tm_hour, now->tm_min, now->tm_sec ); #endif va_start( ap, string ); vprintf( string, ap ); va_end( ap ); } void output_fini() { /*do nothing */ return ; } /******************************************************************************/ /**************************** Configuration ***********************************/ /******************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif #define SIGNAL SIGPOLL /******************************************************************************/ /*************************** Test case ***********************************/ /******************************************************************************/ sig_atomic_t called = 1; void handler_1( int sig ) { called++; } void handler_2( int sig ) { called--; } /* main function */ int main() { int ret; struct sigaction sa, save; /* Initialize output */ output_init(); /* Register the signal handler with signal */ if ( SIG_ERR == signal( SIGNAL, handler_1 ) ) { UNRESOLVED( errno, "Failed to register signal handler with signal()" ); } /* As whether signal handler is restored to default when executed is implementation defined, we cannot check it was registered here. */ /* Set the new signal handler with sigaction*/ sa.sa_flags = 0; sa.sa_handler = handler_2; ret = sigemptyset( &sa.sa_mask ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to empty signal set" ); } /* Install the signal handler for SIGPOLL */ ret = sigaction( SIGNAL, &sa, &save ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to set signal handler" ); } /* Check the signal handler has been set up */ ret = raise( SIGNAL ); if ( ret != 0 ) { UNRESOLVED( ret , "Failed to raise the signal" ); } if ( called != 0 ) { FAILED( "handler not executed" ); } /* Restore the first signal handler */ ret = sigaction( SIGNAL, &save, 0 ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to set signal handler" ); } /* Check the signal handler has been set up */ ret = raise( SIGNAL ); if ( ret != 0 ) { UNRESOLVED( ret , "Failed to raise the signal" ); } if ( called != 1 ) { FAILED( "handler not executed" ); } /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/sigaction/6-17.c0100644000000000000000000000246507646610423022043 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #5 of the sigaction system call that verifies setting the SA_INFO bit in the signal mask for SIGUSR1 will result in sa_sigaction identifying the signal-catching function. */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include "posixtest.h" int handler_called = 0; void handler(int signo, siginfo_t *info, void *context) { handler_called = 1; } int main() { struct sigaction act; act.sa_sigaction = handler; act.sa_flags = SA_SIGINFO; sigemptyset(&act.sa_mask); sigaddset(&act.sa_mask, SIGSTOP); if (sigaction(SIGUSR1, &act, 0) == -1) { printf("Unexpected error while attempting to setup test " "pre-conditions\n"); return PTS_UNRESOLVED; } if (raise(SIGUSR1) == -1) { printf("Unexpected error while attempting to setup test " "pre-conditions\n"); return PTS_UNRESOLVED; } if (handler_called) { printf("Test PASSED\n"); return PTS_PASS; } printf("Test FAILED\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sigaction/16-15.c0100644000000000000000000001261010205365423022103 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertions: * * If SA_RESTART is set in sa_flags, interruptible function interrupted by signal * shall restart silently. * The steps are: * -> create a child thread * -> child registers a handler for SIGTTIN with SA_RESTART, then waits for the semaphore * -> parent kills the child with SIGTTIN, then post the semaphore. * The test fails if the sem_wait function returns EINTR *Note: This test uses sem_wait to check if EINTR is returned. As the function is not required to fail with EINTR, the test may return PASS and the feature not be correct (false positive). Anyway, a false negative status cannot be returned. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /* This test tests for an XSI feature */ #define _XOPEN_SOURCE 600 /******************************************************************************/ /*************************** standard includes ********************************/ /******************************************************************************/ #include #include #include #include #include #include #include #include #include /******************************************************************************/ /*************************** Test framework *******************************/ /******************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int * (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /******************************************************************************/ /**************************** Configuration ***********************************/ /******************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif #define SIGNAL SIGTTIN /******************************************************************************/ /*************************** Test case ***********************************/ /******************************************************************************/ volatile sig_atomic_t caught = 0; sem_t sem; /* Handler function */ void handler( int signo ) { printf( "Caught signal %d\n", signo ); caught++; } /* Thread function */ void * threaded ( void * arg ) { int ret = 0; ret = sem_wait( &sem ); if ( ret != 0 ) { if ( errno == EINTR ) { FAILED( "The function returned EINTR while SA_RESTART is set" ); } else { UNRESOLVED( errno, "sem_wait failed" ); } } return NULL; } /* main function */ int main() { int ret; pthread_t child; struct sigaction sa; /* Initialize output */ output_init(); /* Set the signal handler */ sa.sa_flags = SA_RESTART; sa.sa_handler = handler; ret = sigemptyset( &sa.sa_mask ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to empty signal set" ); } /* Install the signal handler for SIGNAL */ ret = sigaction( SIGNAL, &sa, 0 ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to set signal handler" ); } /* Initialize the semaphore */ ret = sem_init( &sem, 0, 0 ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to init a semaphore" ); } /* Create the child thread */ ret = pthread_create( &child, NULL, threaded, NULL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to create a child thread" ); } /* Let the child thread enter the wait routine... we use sched_yield as there is no certain way to test that the child is waiting for the semaphore... */ sched_yield(); sched_yield(); sched_yield(); /* Ok, now kill the child */ ret = pthread_kill( child, SIGNAL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to kill the child thread" ); } /* wait that the child receives the signal */ while ( !caught ) sched_yield(); /* Now let the child run and terminate */ ret = sem_post( &sem ); if ( ret != 0 ) { UNRESOLVED( errno, "Failed to post the semaphore" ); } ret = pthread_join( child, NULL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to join the thread" ); } /* terminate */ ret = sem_destroy( &sem ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to destroy the semaphore" ); } /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/sigaction/19-16.c0100644000000000000000000001017610205365423022114 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertions: * * If SA_SIGINFO is set in sa_flags and Real Time Signals extension is supported, * sa_sigaction is used as the signal handling function. * The steps are: * -> test for RTS extension * -> register a handler for SIGTTOU with SA_SIGINFO, and a known function * as sa_sigaction * -> raise SIGTTOU, and check the function has been called. * The test fails if the function is not called */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /******************************************************************************/ /*************************** standard includes ********************************/ /******************************************************************************/ #include #include #include #include #include #include #include #include /******************************************************************************/ /*************************** Test framework *******************************/ /******************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int * (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /******************************************************************************/ /**************************** Configuration ***********************************/ /******************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif #define SIGNAL SIGTTOU /******************************************************************************/ /*************************** Test case ***********************************/ /******************************************************************************/ int called = 0; void handler( int sig, siginfo_t *info, void *context ) { if ( info->si_signo != SIGNAL ) { FAILED( "Wrong signal generated?" ); } called = 1; } /* main function */ int main() { int ret; long rts; struct sigaction sa; /* Initialize output */ output_init(); /* Test the RTS extension */ rts = sysconf( _SC_REALTIME_SIGNALS ); if ( rts < 0L ) { UNTESTED( "This test needs the RTS extension" ); } /* Set the signal handler */ sa.sa_flags = SA_SIGINFO; sa.sa_sigaction = handler; ret = sigemptyset( &sa.sa_mask ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to empty signal set" ); } /* Install the signal handler for SIGTTOU */ ret = sigaction( SIGNAL, &sa, 0 ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to set signal handler" ); } if ( called ) { FAILED( "The signal handler has been called when no signal was raised" ); } ret = raise( SIGNAL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to raise SIGTTOU" ); } if ( !called ) { FAILED( "the sa_handler was not called whereas SA_SIGINFO was not set" ); } /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/sigaction/16-26.c0100644000000000000000000001261010205365423022105 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertions: * * If SA_RESTART is set in sa_flags, interruptible function interrupted by signal * shall restart silently. * The steps are: * -> create a child thread * -> child registers a handler for SIGXFSZ with SA_RESTART, then waits for the semaphore * -> parent kills the child with SIGXFSZ, then post the semaphore. * The test fails if the sem_wait function returns EINTR *Note: This test uses sem_wait to check if EINTR is returned. As the function is not required to fail with EINTR, the test may return PASS and the feature not be correct (false positive). Anyway, a false negative status cannot be returned. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /* This test tests for an XSI feature */ #define _XOPEN_SOURCE 600 /******************************************************************************/ /*************************** standard includes ********************************/ /******************************************************************************/ #include #include #include #include #include #include #include #include #include /******************************************************************************/ /*************************** Test framework *******************************/ /******************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int * (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /******************************************************************************/ /**************************** Configuration ***********************************/ /******************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif #define SIGNAL SIGXFSZ /******************************************************************************/ /*************************** Test case ***********************************/ /******************************************************************************/ volatile sig_atomic_t caught = 0; sem_t sem; /* Handler function */ void handler( int signo ) { printf( "Caught signal %d\n", signo ); caught++; } /* Thread function */ void * threaded ( void * arg ) { int ret = 0; ret = sem_wait( &sem ); if ( ret != 0 ) { if ( errno == EINTR ) { FAILED( "The function returned EINTR while SA_RESTART is set" ); } else { UNRESOLVED( errno, "sem_wait failed" ); } } return NULL; } /* main function */ int main() { int ret; pthread_t child; struct sigaction sa; /* Initialize output */ output_init(); /* Set the signal handler */ sa.sa_flags = SA_RESTART; sa.sa_handler = handler; ret = sigemptyset( &sa.sa_mask ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to empty signal set" ); } /* Install the signal handler for SIGNAL */ ret = sigaction( SIGNAL, &sa, 0 ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to set signal handler" ); } /* Initialize the semaphore */ ret = sem_init( &sem, 0, 0 ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to init a semaphore" ); } /* Create the child thread */ ret = pthread_create( &child, NULL, threaded, NULL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to create a child thread" ); } /* Let the child thread enter the wait routine... we use sched_yield as there is no certain way to test that the child is waiting for the semaphore... */ sched_yield(); sched_yield(); sched_yield(); /* Ok, now kill the child */ ret = pthread_kill( child, SIGNAL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to kill the child thread" ); } /* wait that the child receives the signal */ while ( !caught ) sched_yield(); /* Now let the child run and terminate */ ret = sem_post( &sem ); if ( ret != 0 ) { UNRESOLVED( errno, "Failed to post the semaphore" ); } ret = pthread_join( child, NULL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to join the thread" ); } /* terminate */ ret = sem_destroy( &sem ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to destroy the semaphore" ); } /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/sigaction/12-41.c0100644000000000000000000000335507650040125022103 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #12 of the sigaction system call that verifies signal-catching functions are executed on the current stack if the SA_ONSTACK flag is set in the sigaction.sa_flags parameter to the sigaction function call, but a new stack has not be set by sigaltstack(). NOTE: This test case does not attempt to verify the proper operation of sigaltstack. */ #define _XOPEN_SOURCE 600 #include #include #include #include "posixtest.h" stack_t current; void handler(int signo) { stack_t oss; printf("Caught SIGTTIN\n"); if (sigaltstack((stack_t *)0, &oss) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); exit(-1); } if (oss.ss_sp != current.ss_sp || oss.ss_size != current.ss_size) { printf("Test FAILED\n"); exit(-1); } } int main() { struct sigaction act; act.sa_handler = handler; act.sa_flags = SA_ONSTACK; sigemptyset(&act.sa_mask); if (sigaction(SIGTTIN, &act, 0) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (sigaltstack((stack_t *)0, ¤t) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (raise(SIGTTIN) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/sigaction/4-68.c0100644000000000000000000000161007631716563022044 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #4 of the sigaction system call that shows that attempting to add SIGKILL to the signal mask of SIGTTOU will not result in sigaction returning -1 */ #include #include #include #include #include #include "posixtest.h" void handler(int signo) { } int main() { struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); sigaddset(&act.sa_mask, SIGKILL); if (sigaction(SIGTTOU, &act, 0) == -1) { printf("Test FAILED\n"); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/sigaction/25-19.c0100644000000000000000000000462207646610414022123 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #25 of the sigaction system call that verifies that when the sa_sigaction signal-catching function is entered, then the signal that was caught is added to the signal mask by raising that signal in the signal handler and verifying that the handler is not reentered. Steps: 1. Fork a new process 2. (parent) wait for child 3. (child) Setup a signal handler for SIGPOLL 4. (child) raise SIGPOLL 5. (child, signal handler) increment handler count 6. (child, signal handler) if count is 1 then raise SIGPOLL 7. (child, signal handler) if count is 2 then set error variable 8. (child) if error is set then return -1, else return 0 6. (parent - returning from wait) If child returned 0 then exit 0, otherwise exit -1. */ #include #include #include #include #include #include "posixtest.h" int handler_count = 0; int handler_error = 0; void handler(int signo) { static int inside_handler = 0; printf("SIGPOLL caught\n"); if (inside_handler) { printf("Signal caught while inside handler\n"); handler_error++; exit(-1); } inside_handler++; handler_count++; if (handler_count == 1) { printf("Raising SIGPOLL\n"); raise(SIGPOLL); printf("Returning from raising SIGPOLL\n"); } inside_handler--; } int main() { if (fork() == 0) { /* child */ struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); if (sigaction(SIGPOLL, &act, 0) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); return PTS_UNRESOLVED; } if (raise(SIGPOLL) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); return PTS_UNRESOLVED; } if (handler_error) return PTS_UNRESOLVED; return PTS_PASS; } else { int s; /* parent */ if (wait(&s) == -1) { perror("Unexpected error while setting up test " "pre-conditions"); return PTS_UNRESOLVED; } if (!WEXITSTATUS(s)) { printf("Test PASSED\n"); return PTS_PASS; } } printf("Test FAILED\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sigaction/4-65.c0100644000000000000000000000161007631716563022041 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #4 of the sigaction system call that shows that attempting to add SIGKILL to the signal mask of SIGTERM will not result in sigaction returning -1 */ #include #include #include #include #include #include "posixtest.h" void handler(int signo) { } int main() { struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); sigaddset(&act.sa_mask, SIGKILL); if (sigaction(SIGTERM, &act, 0) == -1) { printf("Test FAILED\n"); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/sigaction/1-24.c0100644000000000000000000000271407631716437022037 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: Rusty.Lnch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #1 of the sigaction system call that shows sigaction (when used with a non-null act pointer) changes the action for a signal. Steps: 1. Initialize a global variable to indicate the signal handler has not been called. (A signal handler of the prototype "void func(int signo);" will set the global variable to indicate otherwise. 2. Use sigaction to setup a signal handler for SIGVTALRM 3. Raise SIGVTALRM. 4. Verify the global indicates the signal was called. */ #include #include #include "posixtest.h" int handler_called = 0; void handler(int signo) { handler_called = 1; } int main() { struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); if (sigaction(SIGVTALRM, &act, 0) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (raise(SIGVTALRM) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (handler_called) { printf("Test PASSED\n"); return PTS_PASS; } printf("Test FAILED\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sigaction/2-6.c0100644000000000000000000000271407631716536021760 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #2 of the sigaction system call that shows sigaction (when used with a non-null oact pointer) changes the action for a signal. Steps: 1. Call sigaction to set handler for SIGFPE to use handler1 2. Call sigaction again to set handler for SIGFPE to use handler2, but this time use a non-null oarg and verify the sa_handler for oarg is set for handler1. */ #include #include #include "posixtest.h" int handler_called = 0; void handler1(int signo) { } void handler2(int signo) { } int main() { struct sigaction act; struct sigaction oact; act.sa_handler = handler1; act.sa_flags = 0; sigemptyset(&act.sa_mask); if (sigaction(SIGFPE, &act, 0) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } act.sa_handler = handler2; sigemptyset(&act.sa_mask); if (sigaction(SIGFPE, &act, &oact) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (oact.sa_handler == handler1) { printf("Test PASSED\n"); return PTS_PASS; } printf("Test Failed\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sigaction/23-10.c0100644000000000000000000001036010205365424022075 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertions: * * If SA_NODEFER is not set in sa_flags, the caught signal is added to the * thread's signal mask during the handler execution. * The steps are: * -> register a signal handler for SIGPIPE * -> raise SIGPIPE * -> In handler, check for reentrance then raise SIGPIPE again. * The test fails if signal handler if reentered or signal is not pending when raised again. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /******************************************************************************/ /*************************** standard includes ********************************/ /******************************************************************************/ #include #include #include #include #include #include #include #include /******************************************************************************/ /*************************** Test framework *******************************/ /******************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int * (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /******************************************************************************/ /**************************** Configuration ***********************************/ /******************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif #define SIGNAL SIGPIPE /******************************************************************************/ /*************************** Test case ***********************************/ /******************************************************************************/ int called = 0; void handler( int sig ) { int ret; sigset_t pending; called++; if ( called == 2 ) { FAILED( "Signal was not masked in signal handler" ); } if ( called == 1 ) { /* Raise the signal again. It should be masked */ ret = raise( SIGNAL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to raise SIGPIPE again" ); } /* check the signal is pending */ ret = sigpending( &pending ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to get pending signal set" ); } ret = sigismember( &pending, SIGNAL ); if ( ret != 1 ) { FAILED( "signal is not pending" ); } } called++; } /* main function */ int main() { int ret; struct sigaction sa; /* Initialize output */ output_init(); /* Set the signal handler */ sa.sa_flags = 0; sa.sa_handler = handler; ret = sigemptyset( &sa.sa_mask ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to empty signal set" ); } /* Install the signal handler for SIGPIPE */ ret = sigaction( SIGNAL, &sa, 0 ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to set signal handler" ); } ret = raise( SIGNAL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to raise SIGPIPE" ); } while ( called != 4 ) sched_yield(); /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/sigaction/3-10.c0100644000000000000000000000276507631716554022042 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #3 of the sigaction system call that shows calling sigaction with a null act argument does not change the signal handler. Steps: 1. Initialize global variable to indicate handler has not been called 2. Set the signal handler for SIGPIPE to handler 3. Call sigaction with a null act 4. raise SIGPIPE 5. Verify handler was called. */ #include #include #include "posixtest.h" int handler_called = 0; void handler(int signo) { handler_called = 1; } int main() { struct sigaction act; struct sigaction oact; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); if (sigaction(SIGPIPE, &act, 0) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (sigaction(SIGPIPE, 0, &oact) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (raise(SIGPIPE) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (handler_called) { printf("Test PASSED\n"); return PTS_PASS; } printf("Test FAILED\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sigaction/23-13.c0100644000000000000000000001036010205365424022100 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertions: * * If SA_NODEFER is not set in sa_flags, the caught signal is added to the * thread's signal mask during the handler execution. * The steps are: * -> register a signal handler for SIGTERM * -> raise SIGTERM * -> In handler, check for reentrance then raise SIGTERM again. * The test fails if signal handler if reentered or signal is not pending when raised again. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /******************************************************************************/ /*************************** standard includes ********************************/ /******************************************************************************/ #include #include #include #include #include #include #include #include /******************************************************************************/ /*************************** Test framework *******************************/ /******************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int * (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /******************************************************************************/ /**************************** Configuration ***********************************/ /******************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif #define SIGNAL SIGTERM /******************************************************************************/ /*************************** Test case ***********************************/ /******************************************************************************/ int called = 0; void handler( int sig ) { int ret; sigset_t pending; called++; if ( called == 2 ) { FAILED( "Signal was not masked in signal handler" ); } if ( called == 1 ) { /* Raise the signal again. It should be masked */ ret = raise( SIGNAL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to raise SIGTERM again" ); } /* check the signal is pending */ ret = sigpending( &pending ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to get pending signal set" ); } ret = sigismember( &pending, SIGNAL ); if ( ret != 1 ) { FAILED( "signal is not pending" ); } } called++; } /* main function */ int main() { int ret; struct sigaction sa; /* Initialize output */ output_init(); /* Set the signal handler */ sa.sa_flags = 0; sa.sa_handler = handler; ret = sigemptyset( &sa.sa_mask ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to empty signal set" ); } /* Install the signal handler for SIGTERM */ ret = sigaction( SIGNAL, &sa, 0 ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to set signal handler" ); } ret = raise( SIGNAL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to raise SIGTERM" ); } while ( called != 4 ) sched_yield(); /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/sigaction/4-62.c0100644000000000000000000000161007631716563022036 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #4 of the sigaction system call that shows that attempting to add SIGKILL to the signal mask of SIGPIPE will not result in sigaction returning -1 */ #include #include #include #include #include #include "posixtest.h" void handler(int signo) { } int main() { struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); sigaddset(&act.sa_mask, SIGKILL); if (sigaction(SIGPIPE, &act, 0) == -1) { printf("Test FAILED\n"); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/sigaction/28-23.c0100644000000000000000000001407310206323212022101 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertions: * * If the signal action was set with the signal() function, getting it into oact then reinstalling it with act must be valid. * The steps are: * -> register a signal handler for SIGURG with signal(). * -> check this signal handler works. * -> change the signal handler with sigaction, saving old handler in oact. * -> check the new signal handler works. * -> set the old signal handler back * -> check the old signal handler still works. * The test fails if a signal handler does not work as expected. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /******************************************************************************/ /*************************** standard includes ********************************/ /******************************************************************************/ #include #include #include #include #include #include #include /******************************************************************************/ /*************************** Test framework *******************************/ /******************************************************************************/ /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int * (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ #include "posixtest.h" #include #include #ifdef __GNUC__ /* We are using GCC */ #define UNRESOLVED(x, s) \ { output("Test %s unresolved: got %i (%s) on line %i (%s)\n", __FILE__, x, strerror(x), __LINE__, s); \ output_fini(); \ exit(PTS_UNRESOLVED); } #define FAILED(s) \ { output("Test %s FAILED: %s\n", __FILE__, s); \ output_fini(); \ exit(PTS_FAIL); } #define PASSED \ output_fini(); \ exit(PTS_PASS); #define UNTESTED(s) \ { output("File %s cannot test: %s\n", __FILE__, s); \ output_fini(); \ exit(PTS_UNTESTED); \ } #else /* not using GCC */ #define UNRESOLVED(x, s) \ { output("Test unresolved: got %i (%s) on line %i (%s)\n", x, strerror(x), __LINE__, s); \ output_fini(); \ exit(PTS_UNRESOLVED); } #define FAILED(s) \ { output("Test FAILED: %s\n", s); \ output_fini(); \ exit(PTS_FAIL); } #define PASSED \ output_fini(); \ exit(PTS_PASS); #define UNTESTED(s) \ { output("Unable to test: %s\n", s); \ output_fini(); \ exit(PTS_UNTESTED); \ } #endif void output_init() { /* do nothing */ return ; } void output( char * string, ... ) { va_list ap; #ifndef PLOT_OUTPUT char *ts = "[??:??:??]"; struct tm * now; time_t nw; #endif #ifndef PLOT_OUTPUT nw = time( NULL ); now = localtime( &nw ); if ( now == NULL ) printf( ts ); else printf( "[%2.2d:%2.2d:%2.2d]", now->tm_hour, now->tm_min, now->tm_sec ); #endif va_start( ap, string ); vprintf( string, ap ); va_end( ap ); } void output_fini() { /*do nothing */ return ; } /******************************************************************************/ /**************************** Configuration ***********************************/ /******************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif #define SIGNAL SIGURG /******************************************************************************/ /*************************** Test case ***********************************/ /******************************************************************************/ sig_atomic_t called = 1; void handler_1( int sig ) { called++; } void handler_2( int sig ) { called--; } /* main function */ int main() { int ret; struct sigaction sa, save; /* Initialize output */ output_init(); /* Register the signal handler with signal */ if ( SIG_ERR == signal( SIGNAL, handler_1 ) ) { UNRESOLVED( errno, "Failed to register signal handler with signal()" ); } /* As whether signal handler is restored to default when executed is implementation defined, we cannot check it was registered here. */ /* Set the new signal handler with sigaction*/ sa.sa_flags = 0; sa.sa_handler = handler_2; ret = sigemptyset( &sa.sa_mask ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to empty signal set" ); } /* Install the signal handler for SIGURG */ ret = sigaction( SIGNAL, &sa, &save ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to set signal handler" ); } /* Check the signal handler has been set up */ ret = raise( SIGNAL ); if ( ret != 0 ) { UNRESOLVED( ret , "Failed to raise the signal" ); } if ( called != 0 ) { FAILED( "handler not executed" ); } /* Restore the first signal handler */ ret = sigaction( SIGNAL, &save, 0 ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to set signal handler" ); } /* Check the signal handler has been set up */ ret = raise( SIGNAL ); if ( ret != 0 ) { UNRESOLVED( ret , "Failed to raise the signal" ); } if ( called != 1 ) { FAILED( "handler not executed" ); } /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/sigaction/23-18.c0100644000000000000000000001036010205365424022105 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertions: * * If SA_NODEFER is not set in sa_flags, the caught signal is added to the * thread's signal mask during the handler execution. * The steps are: * -> register a signal handler for SIGUSR2 * -> raise SIGUSR2 * -> In handler, check for reentrance then raise SIGUSR2 again. * The test fails if signal handler if reentered or signal is not pending when raised again. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /******************************************************************************/ /*************************** standard includes ********************************/ /******************************************************************************/ #include #include #include #include #include #include #include #include /******************************************************************************/ /*************************** Test framework *******************************/ /******************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int * (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /******************************************************************************/ /**************************** Configuration ***********************************/ /******************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif #define SIGNAL SIGUSR2 /******************************************************************************/ /*************************** Test case ***********************************/ /******************************************************************************/ int called = 0; void handler( int sig ) { int ret; sigset_t pending; called++; if ( called == 2 ) { FAILED( "Signal was not masked in signal handler" ); } if ( called == 1 ) { /* Raise the signal again. It should be masked */ ret = raise( SIGNAL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to raise SIGUSR2 again" ); } /* check the signal is pending */ ret = sigpending( &pending ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to get pending signal set" ); } ret = sigismember( &pending, SIGNAL ); if ( ret != 1 ) { FAILED( "signal is not pending" ); } } called++; } /* main function */ int main() { int ret; struct sigaction sa; /* Initialize output */ output_init(); /* Set the signal handler */ sa.sa_flags = 0; sa.sa_handler = handler; ret = sigemptyset( &sa.sa_mask ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to empty signal set" ); } /* Install the signal handler for SIGUSR2 */ ret = sigaction( SIGNAL, &sa, 0 ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to set signal handler" ); } ret = raise( SIGNAL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to raise SIGUSR2" ); } while ( called != 4 ) sched_yield(); /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/sigaction/18-15.c0100644000000000000000000000744110205365423022113 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertions: * * If SA_SIGINFO is not set in sa_flags, sa_handler is used as the signal * handling function. * The steps are: * -> register a handler for SIGTTIN without SA_SIGINFO, and a known function * as saèhandler * -> raise SIGTTIN, and check the function has been called. * The test fails if the function is not called */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /******************************************************************************/ /*************************** standard includes ********************************/ /******************************************************************************/ #include #include #include #include #include #include #include #include /******************************************************************************/ /*************************** Test framework *******************************/ /******************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int * (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /******************************************************************************/ /**************************** Configuration ***********************************/ /******************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif #define SIGNAL SIGTTIN /******************************************************************************/ /*************************** Test case ***********************************/ /******************************************************************************/ int called = 0; void handler( int sig ) { called = 1; } /* main function */ int main() { int ret; struct sigaction sa; /* Initialize output */ output_init(); /* Set the signal handler */ sa.sa_flags = 0; sa.sa_handler = handler; ret = sigemptyset( &sa.sa_mask ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to empty signal set" ); } /* Install the signal handler for SIGTTIN */ ret = sigaction( SIGNAL, &sa, 0 ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to set signal handler" ); } if ( called ) { FAILED( "The signal handler has been called when no signal was raised" ); } ret = raise( SIGNAL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to raise SIGTTIN" ); } if ( !called ) { FAILED( "the sa_handler was not called whereas SA_SIGINFO was not set" ); } /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/sigaction/4-66.c0100644000000000000000000000161007631716563022042 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #4 of the sigaction system call that shows that attempting to add SIGKILL to the signal mask of SIGTSTP will not result in sigaction returning -1 */ #include #include #include #include #include #include "posixtest.h" void handler(int signo) { } int main() { struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); sigaddset(&act.sa_mask, SIGKILL); if (sigaction(SIGTSTP, &act, 0) == -1) { printf("Test FAILED\n"); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/sigaction/25-17.c0100644000000000000000000000462207646610414022121 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #25 of the sigaction system call that verifies that when the sa_sigaction signal-catching function is entered, then the signal that was caught is added to the signal mask by raising that signal in the signal handler and verifying that the handler is not reentered. Steps: 1. Fork a new process 2. (parent) wait for child 3. (child) Setup a signal handler for SIGUSR1 4. (child) raise SIGUSR1 5. (child, signal handler) increment handler count 6. (child, signal handler) if count is 1 then raise SIGUSR1 7. (child, signal handler) if count is 2 then set error variable 8. (child) if error is set then return -1, else return 0 6. (parent - returning from wait) If child returned 0 then exit 0, otherwise exit -1. */ #include #include #include #include #include #include "posixtest.h" int handler_count = 0; int handler_error = 0; void handler(int signo) { static int inside_handler = 0; printf("SIGUSR1 caught\n"); if (inside_handler) { printf("Signal caught while inside handler\n"); handler_error++; exit(-1); } inside_handler++; handler_count++; if (handler_count == 1) { printf("Raising SIGUSR1\n"); raise(SIGUSR1); printf("Returning from raising SIGUSR1\n"); } inside_handler--; } int main() { if (fork() == 0) { /* child */ struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); if (sigaction(SIGUSR1, &act, 0) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); return PTS_UNRESOLVED; } if (raise(SIGUSR1) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); return PTS_UNRESOLVED; } if (handler_error) return PTS_UNRESOLVED; return PTS_PASS; } else { int s; /* parent */ if (wait(&s) == -1) { perror("Unexpected error while setting up test " "pre-conditions"); return PTS_UNRESOLVED; } if (!WEXITSTATUS(s)) { printf("Test PASSED\n"); return PTS_PASS; } } printf("Test FAILED\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sigaction/13-5.c0100644000000000000000000000327207646610411022030 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #13 of the sigaction system call that verifies signal-catching functions are executed on the current stack if the SA_ONSTACK flag is cleared in the sigaction.sa_flags parameter to the sigaction function call. NOTE: This test case does not attempt to verify the proper operation of sigaltstack. */ #define _XOPEN_SOURCE 600 #include #include #include #include "posixtest.h" stack_t current; void handler(int signo) { stack_t oss; printf("Caught SIGCONT\n"); if (sigaltstack((stack_t *)0, &oss) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); exit(-1); } if (oss.ss_sp != current.ss_sp || oss.ss_size != current.ss_size) { printf("Test FAILED\n"); exit(-1); } } int main() { struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); if (sigaction(SIGCONT, &act, 0) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (sigaltstack((stack_t *)0, ¤t) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (raise(SIGCONT) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/sigaction/12-3.c0100644000000000000000000000372407646610404022031 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #12 of the sigaction system call that verifies signal-catching functions are executed on the alternate stack if the SA_ONSTACK flag is set in the sigaction.sa_flags parameter to the sigaction function call, and an alternate stack has been setup with sigaltstack(). NOTE: This test case does not attempt to verify the proper operation of sigaltstack. */ #define _XOPEN_SOURCE 600 #include #include #include #include "posixtest.h" stack_t alt_ss; void handler(int signo) { stack_t ss; printf("Caught SIGBUS\n"); if (sigaltstack((stack_t *)0, &ss) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); exit(-1); } if (ss.ss_sp != alt_ss.ss_sp || ss.ss_size != alt_ss.ss_size) { printf("Test FAILED\n"); exit(-1); } } int main() { struct sigaction act; act.sa_handler = handler; act.sa_flags = SA_ONSTACK; sigemptyset(&act.sa_mask); if (sigaction(SIGBUS, &act, 0) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if ((alt_ss.ss_sp = (void *)malloc(SIGSTKSZ)) == NULL) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } alt_ss.ss_size = SIGSTKSZ; alt_ss.ss_flags = 0; if (sigaltstack(&alt_ss, (stack_t *)0) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (raise(SIGBUS) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/sigaction/23-24.c0100644000000000000000000001037610205365424022111 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertions: * * If SA_NODEFER is not set in sa_flags, the caught signal is added to the * thread's signal mask during the handler execution. * The steps are: * -> register a signal handler for SIGVTALRM * -> raise SIGVTALRM * -> In handler, check for reentrance then raise SIGVTALRM again. * The test fails if signal handler if reentered or signal is not pending when raised again. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /******************************************************************************/ /*************************** standard includes ********************************/ /******************************************************************************/ #include #include #include #include #include #include #include #include /******************************************************************************/ /*************************** Test framework *******************************/ /******************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int * (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /******************************************************************************/ /**************************** Configuration ***********************************/ /******************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif #define SIGNAL SIGVTALRM /******************************************************************************/ /*************************** Test case ***********************************/ /******************************************************************************/ int called = 0; void handler( int sig ) { int ret; sigset_t pending; called++; if ( called == 2 ) { FAILED( "Signal was not masked in signal handler" ); } if ( called == 1 ) { /* Raise the signal again. It should be masked */ ret = raise( SIGNAL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to raise SIGVTALRM again" ); } /* check the signal is pending */ ret = sigpending( &pending ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to get pending signal set" ); } ret = sigismember( &pending, SIGNAL ); if ( ret != 1 ) { FAILED( "signal is not pending" ); } } called++; } /* main function */ int main() { int ret; struct sigaction sa; /* Initialize output */ output_init(); /* Set the signal handler */ sa.sa_flags = 0; sa.sa_handler = handler; ret = sigemptyset( &sa.sa_mask ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to empty signal set" ); } /* Install the signal handler for SIGVTALRM */ ret = sigaction( SIGNAL, &sa, 0 ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to set signal handler" ); } ret = raise( SIGNAL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to raise SIGVTALRM" ); } while ( called != 4 ) sched_yield(); /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/sigaction/23-22.c0100644000000000000000000001036010205365424022100 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertions: * * If SA_NODEFER is not set in sa_flags, the caught signal is added to the * thread's signal mask during the handler execution. * The steps are: * -> register a signal handler for SIGTRAP * -> raise SIGTRAP * -> In handler, check for reentrance then raise SIGTRAP again. * The test fails if signal handler if reentered or signal is not pending when raised again. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /******************************************************************************/ /*************************** standard includes ********************************/ /******************************************************************************/ #include #include #include #include #include #include #include #include /******************************************************************************/ /*************************** Test framework *******************************/ /******************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int * (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /******************************************************************************/ /**************************** Configuration ***********************************/ /******************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif #define SIGNAL SIGTRAP /******************************************************************************/ /*************************** Test case ***********************************/ /******************************************************************************/ int called = 0; void handler( int sig ) { int ret; sigset_t pending; called++; if ( called == 2 ) { FAILED( "Signal was not masked in signal handler" ); } if ( called == 1 ) { /* Raise the signal again. It should be masked */ ret = raise( SIGNAL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to raise SIGTRAP again" ); } /* check the signal is pending */ ret = sigpending( &pending ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to get pending signal set" ); } ret = sigismember( &pending, SIGNAL ); if ( ret != 1 ) { FAILED( "signal is not pending" ); } } called++; } /* main function */ int main() { int ret; struct sigaction sa; /* Initialize output */ output_init(); /* Set the signal handler */ sa.sa_flags = 0; sa.sa_handler = handler; ret = sigemptyset( &sa.sa_mask ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to empty signal set" ); } /* Install the signal handler for SIGTRAP */ ret = sigaction( SIGNAL, &sa, 0 ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to set signal handler" ); } ret = raise( SIGNAL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to raise SIGTRAP" ); } while ( called != 4 ) sched_yield(); /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/sigaction/4-84.c0100644000000000000000000000160607631716565022051 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #4 of the sigaction system call that shows that attempting to add SIGSTOP to the signal mask of SIGFPE will not result in sigaction returning -1 */ #include #include #include #include #include #include "posixtest.h" void handler(int signo) { } int main() { struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); sigaddset(&act.sa_mask, SIGSTOP); if (sigaction(SIGFPE, &act, 0) == -1) { printf("Test FAILED\n"); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/sigaction/28-2.c0100644000000000000000000001407610206323210022017 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertions: * * If the signal action was set with the signal() function, getting it into oact then reinstalling it with act must be valid. * The steps are: * -> register a signal handler for SIGALRM with signal(). * -> check this signal handler works. * -> change the signal handler with sigaction, saving old handler in oact. * -> check the new signal handler works. * -> set the old signal handler back * -> check the old signal handler still works. * The test fails if a signal handler does not work as expected. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /******************************************************************************/ /*************************** standard includes ********************************/ /******************************************************************************/ #include #include #include #include #include #include #include /******************************************************************************/ /*************************** Test framework *******************************/ /******************************************************************************/ /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int * (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ #include "posixtest.h" #include #include #ifdef __GNUC__ /* We are using GCC */ #define UNRESOLVED(x, s) \ { output("Test %s unresolved: got %i (%s) on line %i (%s)\n", __FILE__, x, strerror(x), __LINE__, s); \ output_fini(); \ exit(PTS_UNRESOLVED); } #define FAILED(s) \ { output("Test %s FAILED: %s\n", __FILE__, s); \ output_fini(); \ exit(PTS_FAIL); } #define PASSED \ output_fini(); \ exit(PTS_PASS); #define UNTESTED(s) \ { output("File %s cannot test: %s\n", __FILE__, s); \ output_fini(); \ exit(PTS_UNTESTED); \ } #else /* not using GCC */ #define UNRESOLVED(x, s) \ { output("Test unresolved: got %i (%s) on line %i (%s)\n", x, strerror(x), __LINE__, s); \ output_fini(); \ exit(PTS_UNRESOLVED); } #define FAILED(s) \ { output("Test FAILED: %s\n", s); \ output_fini(); \ exit(PTS_FAIL); } #define PASSED \ output_fini(); \ exit(PTS_PASS); #define UNTESTED(s) \ { output("Unable to test: %s\n", s); \ output_fini(); \ exit(PTS_UNTESTED); \ } #endif void output_init() { /* do nothing */ return ; } void output( char * string, ... ) { va_list ap; #ifndef PLOT_OUTPUT char *ts = "[??:??:??]"; struct tm * now; time_t nw; #endif #ifndef PLOT_OUTPUT nw = time( NULL ); now = localtime( &nw ); if ( now == NULL ) printf( ts ); else printf( "[%2.2d:%2.2d:%2.2d]", now->tm_hour, now->tm_min, now->tm_sec ); #endif va_start( ap, string ); vprintf( string, ap ); va_end( ap ); } void output_fini() { /*do nothing */ return ; } /******************************************************************************/ /**************************** Configuration ***********************************/ /******************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif #define SIGNAL SIGALRM /******************************************************************************/ /*************************** Test case ***********************************/ /******************************************************************************/ sig_atomic_t called = 1; void handler_1( int sig ) { called++; } void handler_2( int sig ) { called--; } /* main function */ int main() { int ret; struct sigaction sa, save; /* Initialize output */ output_init(); /* Register the signal handler with signal */ if ( SIG_ERR == signal( SIGNAL, handler_1 ) ) { UNRESOLVED( errno, "Failed to register signal handler with signal()" ); } /* As whether signal handler is restored to default when executed is implementation defined, we cannot check it was registered here. */ /* Set the new signal handler with sigaction*/ sa.sa_flags = 0; sa.sa_handler = handler_2; ret = sigemptyset( &sa.sa_mask ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to empty signal set" ); } /* Install the signal handler for SIGALRM */ ret = sigaction( SIGNAL, &sa, &save ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to set signal handler" ); } /* Check the signal handler has been set up */ ret = raise( SIGNAL ); if ( ret != 0 ) { UNRESOLVED( ret , "Failed to raise the signal" ); } if ( called != 0 ) { FAILED( "handler not executed" ); } /* Restore the first signal handler */ ret = sigaction( SIGNAL, &save, 0 ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to set signal handler" ); } /* Check the signal handler has been set up */ ret = raise( SIGNAL ); if ( ret != 0 ) { UNRESOLVED( ret , "Failed to raise the signal" ); } if ( called != 1 ) { FAILED( "handler not executed" ); } /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/sigaction/18-21.c0100644000000000000000000000743410205365423022112 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertions: * * If SA_SIGINFO is not set in sa_flags, sa_handler is used as the signal * handling function. * The steps are: * -> register a handler for SIGSYS without SA_SIGINFO, and a known function * as saèhandler * -> raise SIGSYS, and check the function has been called. * The test fails if the function is not called */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /******************************************************************************/ /*************************** standard includes ********************************/ /******************************************************************************/ #include #include #include #include #include #include #include #include /******************************************************************************/ /*************************** Test framework *******************************/ /******************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int * (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /******************************************************************************/ /**************************** Configuration ***********************************/ /******************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif #define SIGNAL SIGSYS /******************************************************************************/ /*************************** Test case ***********************************/ /******************************************************************************/ int called = 0; void handler( int sig ) { called = 1; } /* main function */ int main() { int ret; struct sigaction sa; /* Initialize output */ output_init(); /* Set the signal handler */ sa.sa_flags = 0; sa.sa_handler = handler; ret = sigemptyset( &sa.sa_mask ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to empty signal set" ); } /* Install the signal handler for SIGSYS */ ret = sigaction( SIGNAL, &sa, 0 ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to set signal handler" ); } if ( called ) { FAILED( "The signal handler has been called when no signal was raised" ); } ret = raise( SIGNAL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to raise SIGSYS" ); } if ( !called ) { FAILED( "the sa_handler was not called whereas SA_SIGINFO was not set" ); } /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/sigaction/8-9.c0100644000000000000000000000320307631716574021765 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #8 of the sigaction system call that verifies that if signals in the sa_mask (passed in the sigaction struct of the sigaction function call) are added to the process signal mask during execution of the signal-catching function. */ #include #include #include #include #include #include "posixtest.h" int SIGILL_count = 0; void SIGILL_handler(int signo) { SIGILL_count++; printf("Caught SIGILL\n"); } void SIGINT_handler(int signo) { printf("Caught SIGINT\n"); raise(SIGILL); if (SIGILL_count) { printf("Test FAILED\n"); exit(-1); } } int main() { struct sigaction act; act.sa_handler = SIGINT_handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); sigaddset(&act.sa_mask, SIGILL); if (sigaction(SIGINT, &act, 0) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); return PTS_UNRESOLVED; } act.sa_handler = SIGILL_handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); if (sigaction(SIGILL, &act, 0) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); return PTS_UNRESOLVED; } if (raise(SIGINT) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/sigaction/12-39.c0100644000000000000000000000335507650040046022114 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #12 of the sigaction system call that verifies signal-catching functions are executed on the current stack if the SA_ONSTACK flag is set in the sigaction.sa_flags parameter to the sigaction function call, but a new stack has not be set by sigaltstack(). NOTE: This test case does not attempt to verify the proper operation of sigaltstack. */ #define _XOPEN_SOURCE 600 #include #include #include #include "posixtest.h" stack_t current; void handler(int signo) { stack_t oss; printf("Caught SIGTERM\n"); if (sigaltstack((stack_t *)0, &oss) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); exit(-1); } if (oss.ss_sp != current.ss_sp || oss.ss_size != current.ss_size) { printf("Test FAILED\n"); exit(-1); } } int main() { struct sigaction act; act.sa_handler = handler; act.sa_flags = SA_ONSTACK; sigemptyset(&act.sa_mask); if (sigaction(SIGTERM, &act, 0) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (sigaltstack((stack_t *)0, ¤t) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (raise(SIGTERM) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/sigaction/4-63.c0100644000000000000000000000161007631716563022037 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #4 of the sigaction system call that shows that attempting to add SIGKILL to the signal mask of SIGQUIT will not result in sigaction returning -1 */ #include #include #include #include #include #include "posixtest.h" void handler(int signo) { } int main() { struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); sigaddset(&act.sa_mask, SIGKILL); if (sigaction(SIGQUIT, &act, 0) == -1) { printf("Test FAILED\n"); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/sigaction/6-15.c0100644000000000000000000000246507646610423022041 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #5 of the sigaction system call that verifies setting the SA_INFO bit in the signal mask for SIGTTIN will result in sa_sigaction identifying the signal-catching function. */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include "posixtest.h" int handler_called = 0; void handler(int signo, siginfo_t *info, void *context) { handler_called = 1; } int main() { struct sigaction act; act.sa_sigaction = handler; act.sa_flags = SA_SIGINFO; sigemptyset(&act.sa_mask); sigaddset(&act.sa_mask, SIGSTOP); if (sigaction(SIGTTIN, &act, 0) == -1) { printf("Unexpected error while attempting to setup test " "pre-conditions\n"); return PTS_UNRESOLVED; } if (raise(SIGTTIN) == -1) { printf("Unexpected error while attempting to setup test " "pre-conditions\n"); return PTS_UNRESOLVED; } if (handler_called) { printf("Test PASSED\n"); return PTS_PASS; } printf("Test FAILED\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sigaction/8-6.c0100644000000000000000000000321407631716573021763 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #8 of the sigaction system call that verifies that if signals in the sa_mask (passed in the sigaction struct of the sigaction function call) are added to the process signal mask during execution of the signal-catching function. */ #include #include #include #include #include #include "posixtest.h" int SIGCONT_count = 0; void SIGCONT_handler(int signo) { SIGCONT_count++; printf("Caught SIGCONT\n"); } void SIGFPE_handler(int signo) { printf("Caught SIGFPE\n"); raise(SIGCONT); if (SIGCONT_count) { printf("Test FAILED\n"); exit(-1); } } int main() { struct sigaction act; act.sa_handler = SIGFPE_handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); sigaddset(&act.sa_mask, SIGCONT); if (sigaction(SIGFPE, &act, 0) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); return PTS_UNRESOLVED; } act.sa_handler = SIGCONT_handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); if (sigaction(SIGCONT, &act, 0) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); return PTS_UNRESOLVED; } if (raise(SIGFPE) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/sigaction/4-17.c0100644000000000000000000000355607631716560022046 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #4 of the sigaction system call that shows that attempting to add SIGKILL can not be added to the signal mask for a signal handler. Steps: 1. Fork a new process 2. (parent) wait for child 3. (child) Setup a signal handler for SIGUSR1 with SIGKILL added to the signal mask 4. (child) raise SIGUSR1 5. (child, signal handler) raise SIGKILL 5. (child) If still alive then exit -1 6. (parent - returning from wait) If child was killed then return success, otherwise fail. */ #include #include #include #include #include #include "posixtest.h" void handler(int signo) { raise(SIGKILL); exit(0); } int main() { if (fork() == 0) { /* child */ /* * NOTE: This block of code will return 0 for error * and anything else for success. */ struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); sigaddset(&act.sa_mask, SIGKILL); if (sigaction(SIGUSR1, &act, 0) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); return PTS_PASS; } if (raise(SIGUSR1) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); } return PTS_PASS; } else { int s; /* parent */ if (wait(&s) == -1) { perror("Unexpected error while setting up test " "pre-conditions"); return PTS_UNRESOLVED; } if (!WIFEXITED(s)) { printf("Test PASSED\n"); return PTS_PASS; } } printf("Test FAILED\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sigaction/18-22.c0100644000000000000000000000744110205365423022111 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertions: * * If SA_SIGINFO is not set in sa_flags, sa_handler is used as the signal * handling function. * The steps are: * -> register a handler for SIGTRAP without SA_SIGINFO, and a known function * as saèhandler * -> raise SIGTRAP, and check the function has been called. * The test fails if the function is not called */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /******************************************************************************/ /*************************** standard includes ********************************/ /******************************************************************************/ #include #include #include #include #include #include #include #include /******************************************************************************/ /*************************** Test framework *******************************/ /******************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int * (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /******************************************************************************/ /**************************** Configuration ***********************************/ /******************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif #define SIGNAL SIGTRAP /******************************************************************************/ /*************************** Test case ***********************************/ /******************************************************************************/ int called = 0; void handler( int sig ) { called = 1; } /* main function */ int main() { int ret; struct sigaction sa; /* Initialize output */ output_init(); /* Set the signal handler */ sa.sa_flags = 0; sa.sa_handler = handler; ret = sigemptyset( &sa.sa_mask ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to empty signal set" ); } /* Install the signal handler for SIGTRAP */ ret = sigaction( SIGNAL, &sa, 0 ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to set signal handler" ); } if ( called ) { FAILED( "The signal handler has been called when no signal was raised" ); } ret = raise( SIGNAL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to raise SIGTRAP" ); } if ( !called ) { FAILED( "the sa_handler was not called whereas SA_SIGINFO was not set" ); } /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/sigaction/12-7.c0100644000000000000000000000372407646610406022037 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #12 of the sigaction system call that verifies signal-catching functions are executed on the alternate stack if the SA_ONSTACK flag is set in the sigaction.sa_flags parameter to the sigaction function call, and an alternate stack has been setup with sigaltstack(). NOTE: This test case does not attempt to verify the proper operation of sigaltstack. */ #define _XOPEN_SOURCE 600 #include #include #include #include "posixtest.h" stack_t alt_ss; void handler(int signo) { stack_t ss; printf("Caught SIGHUP\n"); if (sigaltstack((stack_t *)0, &ss) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); exit(-1); } if (ss.ss_sp != alt_ss.ss_sp || ss.ss_size != alt_ss.ss_size) { printf("Test FAILED\n"); exit(-1); } } int main() { struct sigaction act; act.sa_handler = handler; act.sa_flags = SA_ONSTACK; sigemptyset(&act.sa_mask); if (sigaction(SIGHUP, &act, 0) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if ((alt_ss.ss_sp = (void *)malloc(SIGSTKSZ)) == NULL) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } alt_ss.ss_size = SIGSTKSZ; alt_ss.ss_flags = 0; if (sigaltstack(&alt_ss, (stack_t *)0) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (raise(SIGHUP) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/sigaction/25-10.c0100644000000000000000000000462207646610414022112 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #25 of the sigaction system call that verifies that when the sa_sigaction signal-catching function is entered, then the signal that was caught is added to the signal mask by raising that signal in the signal handler and verifying that the handler is not reentered. Steps: 1. Fork a new process 2. (parent) wait for child 3. (child) Setup a signal handler for SIGPIPE 4. (child) raise SIGPIPE 5. (child, signal handler) increment handler count 6. (child, signal handler) if count is 1 then raise SIGPIPE 7. (child, signal handler) if count is 2 then set error variable 8. (child) if error is set then return -1, else return 0 6. (parent - returning from wait) If child returned 0 then exit 0, otherwise exit -1. */ #include #include #include #include #include #include "posixtest.h" int handler_count = 0; int handler_error = 0; void handler(int signo) { static int inside_handler = 0; printf("SIGPIPE caught\n"); if (inside_handler) { printf("Signal caught while inside handler\n"); handler_error++; exit(-1); } inside_handler++; handler_count++; if (handler_count == 1) { printf("Raising SIGPIPE\n"); raise(SIGPIPE); printf("Returning from raising SIGPIPE\n"); } inside_handler--; } int main() { if (fork() == 0) { /* child */ struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); if (sigaction(SIGPIPE, &act, 0) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); return PTS_UNRESOLVED; } if (raise(SIGPIPE) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); return PTS_UNRESOLVED; } if (handler_error) return PTS_UNRESOLVED; return PTS_PASS; } else { int s; /* parent */ if (wait(&s) == -1) { perror("Unexpected error while setting up test " "pre-conditions"); return PTS_UNRESOLVED; } if (!WEXITSTATUS(s)) { printf("Test PASSED\n"); return PTS_PASS; } } printf("Test FAILED\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sigaction/16-5.c0100644000000000000000000001261010205365423022022 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertions: * * If SA_RESTART is set in sa_flags, interruptible function interrupted by signal * shall restart silently. * The steps are: * -> create a child thread * -> child registers a handler for SIGCONT with SA_RESTART, then waits for the semaphore * -> parent kills the child with SIGCONT, then post the semaphore. * The test fails if the sem_wait function returns EINTR *Note: This test uses sem_wait to check if EINTR is returned. As the function is not required to fail with EINTR, the test may return PASS and the feature not be correct (false positive). Anyway, a false negative status cannot be returned. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /* This test tests for an XSI feature */ #define _XOPEN_SOURCE 600 /******************************************************************************/ /*************************** standard includes ********************************/ /******************************************************************************/ #include #include #include #include #include #include #include #include #include /******************************************************************************/ /*************************** Test framework *******************************/ /******************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int * (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /******************************************************************************/ /**************************** Configuration ***********************************/ /******************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif #define SIGNAL SIGCONT /******************************************************************************/ /*************************** Test case ***********************************/ /******************************************************************************/ volatile sig_atomic_t caught = 0; sem_t sem; /* Handler function */ void handler( int signo ) { printf( "Caught signal %d\n", signo ); caught++; } /* Thread function */ void * threaded ( void * arg ) { int ret = 0; ret = sem_wait( &sem ); if ( ret != 0 ) { if ( errno == EINTR ) { FAILED( "The function returned EINTR while SA_RESTART is set" ); } else { UNRESOLVED( errno, "sem_wait failed" ); } } return NULL; } /* main function */ int main() { int ret; pthread_t child; struct sigaction sa; /* Initialize output */ output_init(); /* Set the signal handler */ sa.sa_flags = SA_RESTART; sa.sa_handler = handler; ret = sigemptyset( &sa.sa_mask ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to empty signal set" ); } /* Install the signal handler for SIGNAL */ ret = sigaction( SIGNAL, &sa, 0 ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to set signal handler" ); } /* Initialize the semaphore */ ret = sem_init( &sem, 0, 0 ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to init a semaphore" ); } /* Create the child thread */ ret = pthread_create( &child, NULL, threaded, NULL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to create a child thread" ); } /* Let the child thread enter the wait routine... we use sched_yield as there is no certain way to test that the child is waiting for the semaphore... */ sched_yield(); sched_yield(); sched_yield(); /* Ok, now kill the child */ ret = pthread_kill( child, SIGNAL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to kill the child thread" ); } /* wait that the child receives the signal */ while ( !caught ) sched_yield(); /* Now let the child run and terminate */ ret = sem_post( &sem ); if ( ret != 0 ) { UNRESOLVED( errno, "Failed to post the semaphore" ); } ret = pthread_join( child, NULL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to join the thread" ); } /* terminate */ ret = sem_destroy( &sem ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to destroy the semaphore" ); } /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/sigaction/19-22.c0100644000000000000000000001017610205365423022111 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertions: * * If SA_SIGINFO is set in sa_flags and Real Time Signals extension is supported, * sa_sigaction is used as the signal handling function. * The steps are: * -> test for RTS extension * -> register a handler for SIGTRAP with SA_SIGINFO, and a known function * as sa_sigaction * -> raise SIGTRAP, and check the function has been called. * The test fails if the function is not called */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /******************************************************************************/ /*************************** standard includes ********************************/ /******************************************************************************/ #include #include #include #include #include #include #include #include /******************************************************************************/ /*************************** Test framework *******************************/ /******************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int * (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /******************************************************************************/ /**************************** Configuration ***********************************/ /******************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif #define SIGNAL SIGTRAP /******************************************************************************/ /*************************** Test case ***********************************/ /******************************************************************************/ int called = 0; void handler( int sig, siginfo_t *info, void *context ) { if ( info->si_signo != SIGNAL ) { FAILED( "Wrong signal generated?" ); } called = 1; } /* main function */ int main() { int ret; long rts; struct sigaction sa; /* Initialize output */ output_init(); /* Test the RTS extension */ rts = sysconf( _SC_REALTIME_SIGNALS ); if ( rts < 0L ) { UNTESTED( "This test needs the RTS extension" ); } /* Set the signal handler */ sa.sa_flags = SA_SIGINFO; sa.sa_sigaction = handler; ret = sigemptyset( &sa.sa_mask ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to empty signal set" ); } /* Install the signal handler for SIGTRAP */ ret = sigaction( SIGNAL, &sa, 0 ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to set signal handler" ); } if ( called ) { FAILED( "The signal handler has been called when no signal was raised" ); } ret = raise( SIGNAL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to raise SIGTRAP" ); } if ( !called ) { FAILED( "the sa_handler was not called whereas SA_SIGINFO was not set" ); } /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/sigaction/30-1.c0100644000000000000000000001327310205365424022021 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertions: * * sigaction returns -1 and errno is set to EINVAL if signal number is invalid * or an attempt to do an operation which is not allowed is made. * The steps are: * -> Try setting a signal handler for signal SIGRTMAX + 1 * -> Try setting a signal handler for SIGKILL * -> Try setting a signal handler for SIGSTOP * -> Try ignoring SIGSTOP * -> Try ignoring SIGKILL * The test fails if the signals are not delivered in FIFO order. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /******************************************************************************/ /*************************** standard includes ********************************/ /******************************************************************************/ #include #include #include #include #include #include #include #include /******************************************************************************/ /*************************** Test framework *******************************/ /******************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int * (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /******************************************************************************/ /**************************** Configuration ***********************************/ /******************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif #define SIG_INVALID SIGRTMAX+10 /******************************************************************************/ /*************************** Test case ***********************************/ /******************************************************************************/ void handler( int signo ) { return ; } /* main function */ int main() { int ret; struct sigaction sa; /* Initialize output */ output_init(); /* Set the signal handler */ sa.sa_flags = 0; sa.sa_handler = handler; ret = sigemptyset( &sa.sa_mask ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to empty signal set" ); } /* Install the signal handler for SIGRTMAX */ #if VERBOSE > 0 output( "Trying to catch invalid signal %d\n", SIG_INVALID ); #endif ret = sigaction( SIG_INVALID, &sa, 0 ); if ( ret == 0 ) { output( "Is signal %d valid on this implementation?\n", SIG_INVALID ); FAILED( "Setting handler for invalid signal did not fail" ); } if ( errno != EINVAL ) { output( "Got error %d (%s) instead of %d (%s)\n", errno, strerror( errno ), EINVAL, strerror( EINVAL ) ); FAILED( "Wrong error code returned" ); } /* Install the signal handler for SIGKILL */ #if VERBOSE > 0 output( "Trying to catch unauthorized signal SIGKILL (%d)\n", SIGKILL ); #endif ret = sigaction( SIGKILL, &sa, 0 ); if ( ret == 0 ) { FAILED( "Setting handler for SIGKILL did not fail" ); } if ( errno != EINVAL ) { output( "Got error %d (%s) instead of %d (%s)\n", errno, strerror( errno ), EINVAL, strerror( EINVAL ) ); FAILED( "Wrong error code returned" ); } /* Install the signal handler for SIGSTOP */ #if VERBOSE > 0 output( "Trying to catch unauthorized signal SIGSTOP (%d)\n", SIGSTOP ); #endif ret = sigaction( SIGSTOP, &sa, 0 ); if ( ret == 0 ) { FAILED( "Setting handler for SIGSTOP did not fail" ); } if ( errno != EINVAL ) { output( "Got error %d (%s) instead of %d (%s)\n", errno, strerror( errno ), EINVAL, strerror( EINVAL ) ); FAILED( "Wrong error code returned" ); } sa.sa_handler = SIG_IGN; /* Ingrore SIGKILL */ #if VERBOSE > 0 output( "Trying to ignore unauthorized signal SIGKILL (%d)\n", SIGKILL ); #endif ret = sigaction( SIGKILL, &sa, 0 ); if ( ret == 0 ) { FAILED( "Ignoring SIGKILL did not fail" ); } if ( errno != EINVAL ) { output( "Got error %d (%s) instead of %d (%s)\n", errno, strerror( errno ), EINVAL, strerror( EINVAL ) ); FAILED( "Wrong error code returned" ); } /* Ignore SIGSTOP */ #if VERBOSE > 0 output( "Trying to ignore unauthorized signal SIGSTOP (%d)\n", SIGSTOP ); #endif ret = sigaction( SIGSTOP, &sa, 0 ); if ( ret == 0 ) { FAILED( "Ignoring SIGSTOP did not fail" ); } if ( errno != EINVAL ) { output( "Got error %d (%s) instead of %d (%s)\n", errno, strerror( errno ), EINVAL, strerror( EINVAL ) ); FAILED( "Wrong error code returned" ); } /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/sigaction/12-46.c0100644000000000000000000000335507650040125022110 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #12 of the sigaction system call that verifies signal-catching functions are executed on the current stack if the SA_ONSTACK flag is set in the sigaction.sa_flags parameter to the sigaction function call, but a new stack has not be set by sigaltstack(). NOTE: This test case does not attempt to verify the proper operation of sigaltstack. */ #define _XOPEN_SOURCE 600 #include #include #include #include "posixtest.h" stack_t current; void handler(int signo) { stack_t oss; printf("Caught SIGPROF\n"); if (sigaltstack((stack_t *)0, &oss) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); exit(-1); } if (oss.ss_sp != current.ss_sp || oss.ss_size != current.ss_size) { printf("Test FAILED\n"); exit(-1); } } int main() { struct sigaction act; act.sa_handler = handler; act.sa_flags = SA_ONSTACK; sigemptyset(&act.sa_mask); if (sigaction(SIGPROF, &act, 0) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (sigaltstack((stack_t *)0, ¤t) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (raise(SIGPROF) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/sigaction/6-8.c0100644000000000000000000000246207646610427021764 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #5 of the sigaction system call that verifies setting the SA_INFO bit in the signal mask for SIGILL will result in sa_sigaction identifying the signal-catching function. */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include "posixtest.h" int handler_called = 0; void handler(int signo, siginfo_t *info, void *context) { handler_called = 1; } int main() { struct sigaction act; act.sa_sigaction = handler; act.sa_flags = SA_SIGINFO; sigemptyset(&act.sa_mask); sigaddset(&act.sa_mask, SIGSTOP); if (sigaction(SIGILL, &act, 0) == -1) { printf("Unexpected error while attempting to setup test " "pre-conditions\n"); return PTS_UNRESOLVED; } if (raise(SIGILL) == -1) { printf("Unexpected error while attempting to setup test " "pre-conditions\n"); return PTS_UNRESOLVED; } if (handler_called) { printf("Test PASSED\n"); return PTS_PASS; } printf("Test FAILED\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sigaction/22-7.c0100644000000000000000000000467407646610413022043 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #22 of the sigaction system call that verifies that if the SA_NODEFER flag is set for a given signal, then when the sa_sigaction signal-catching function is entered, then the signal that was caught is not added to the signal mask by raising that signal in the signal handler and verifying that the handler is reentered. Steps: 1. Fork a new process 2. (parent) wait for child 3. (child) Setup a signal handler for SIGHUP with SA_NODEFER set in the sa_flags field 4. (child) raise SIGHUP 5. (child, signal handler) increment handler count 6. (child, signal handler) if count is 1 then raise SIGHUP 7. (child, signal handler) if count is 1 then set error variable 8. (child) if error is set then return -1, else return 0 6. (parent - returning from wait) If child returned 0 then exit 0, otherwise exit -1. */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include "posixtest.h" int handler_count = 0; void handler(int signo) { static int inside_handler = 0; printf("SIGHUP caught\n"); if (inside_handler) { printf("Signal caught while inside handler\n"); exit(0); } inside_handler++; handler_count++; if (handler_count == 1) { printf("Raising SIGHUP\n"); raise(SIGHUP); printf("Returning from raising SIGHUP\n"); } inside_handler--; } int main() { if (fork() == 0) { /* child */ struct sigaction act; act.sa_handler = handler; act.sa_flags = SA_NODEFER; sigemptyset(&act.sa_mask); if (sigaction(SIGHUP, &act, 0) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); return PTS_UNRESOLVED; } if (raise(SIGHUP) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); return PTS_UNRESOLVED; } return PTS_FAIL; } else { int s; /* parent */ if (wait(&s) == -1) { perror("Unexpected error while setting up test " "pre-conditions"); return PTS_UNRESOLVED; } if (!WEXITSTATUS(s)) { printf("Test PASSED\n"); return PTS_PASS; } } printf("Test FAILED\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sigaction/12-2.c0100644000000000000000000000372707646610403022032 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #12 of the sigaction system call that verifies signal-catching functions are executed on the alternate stack if the SA_ONSTACK flag is set in the sigaction.sa_flags parameter to the sigaction function call, and an alternate stack has been setup with sigaltstack(). NOTE: This test case does not attempt to verify the proper operation of sigaltstack. */ #define _XOPEN_SOURCE 600 #include #include #include #include "posixtest.h" stack_t alt_ss; void handler(int signo) { stack_t ss; printf("Caught SIGALRM\n"); if (sigaltstack((stack_t *)0, &ss) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); exit(-1); } if (ss.ss_sp != alt_ss.ss_sp || ss.ss_size != alt_ss.ss_size) { printf("Test FAILED\n"); exit(-1); } } int main() { struct sigaction act; act.sa_handler = handler; act.sa_flags = SA_ONSTACK; sigemptyset(&act.sa_mask); if (sigaction(SIGALRM, &act, 0) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if ((alt_ss.ss_sp = (void *)malloc(SIGSTKSZ)) == NULL) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } alt_ss.ss_size = SIGSTKSZ; alt_ss.ss_flags = 0; if (sigaltstack(&alt_ss, (stack_t *)0) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (raise(SIGALRM) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/sigaction/4-29.c0100644000000000000000000000370107646624576022054 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #4 of the sigaction system call that shows that attempting to add SIGSTOP can not be added to the signal mask for a signal handler. Steps: 1. Fork a new process 2. (parent) wait for child 3. (child) Setup a signal handler for SIGBUS with SIGSTOP added to the signal mask 4. (child) raise SIGBUS 5. (child, signal handler) raise SIGSTOP 5. (child) If still around then return -1 6. (parent - returning from wait) If child was stopped then return kill the child and return success, otherwise fail. */ #include #include #include #include #include #include #include "posixtest.h" void handler(int signo) { printf("About to stop child\n"); raise(SIGSTOP); printf("Child has continued\n"); exit(0); } int main() { pid_t pid; if ((pid = fork()) == 0) { /* child */ struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); sigaddset(&act.sa_mask, SIGSTOP); if (sigaction(SIGBUS, &act, 0) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); return PTS_UNRESOLVED; } if (raise(SIGBUS) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); } return PTS_UNRESOLVED; } else { int s; /* parent */ if (waitpid(pid, &s, WUNTRACED) == -1) { perror("Unexpected error while setting up test " "pre-conditions"); return PTS_UNRESOLVED; } if (WIFSTOPPED(s)) { printf("Test PASSED\n"); kill(pid, SIGKILL); return PTS_PASS; } } printf("Test FAILED\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sigaction/4-11.c0100644000000000000000000000355607631716560022040 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #4 of the sigaction system call that shows that attempting to add SIGKILL can not be added to the signal mask for a signal handler. Steps: 1. Fork a new process 2. (parent) wait for child 3. (child) Setup a signal handler for SIGQUIT with SIGKILL added to the signal mask 4. (child) raise SIGQUIT 5. (child, signal handler) raise SIGKILL 5. (child) If still alive then exit -1 6. (parent - returning from wait) If child was killed then return success, otherwise fail. */ #include #include #include #include #include #include "posixtest.h" void handler(int signo) { raise(SIGKILL); exit(0); } int main() { if (fork() == 0) { /* child */ /* * NOTE: This block of code will return 0 for error * and anything else for success. */ struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); sigaddset(&act.sa_mask, SIGKILL); if (sigaction(SIGQUIT, &act, 0) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); return PTS_PASS; } if (raise(SIGQUIT) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); } return PTS_PASS; } else { int s; /* parent */ if (wait(&s) == -1) { perror("Unexpected error while setting up test " "pre-conditions"); return PTS_UNRESOLVED; } if (!WIFEXITED(s)) { printf("Test PASSED\n"); return PTS_PASS; } } printf("Test FAILED\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sigaction/2-20.c0100644000000000000000000000272007631716534022027 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #2 of the sigaction system call that shows sigaction (when used with a non-null oact pointer) changes the action for a signal. Steps: 1. Call sigaction to set handler for SIGPROF to use handler1 2. Call sigaction again to set handler for SIGPROF to use handler2, but this time use a non-null oarg and verify the sa_handler for oarg is set for handler1. */ #include #include #include "posixtest.h" int handler_called = 0; void handler1(int signo) { } void handler2(int signo) { } int main() { struct sigaction act; struct sigaction oact; act.sa_handler = handler1; act.sa_flags = 0; sigemptyset(&act.sa_mask); if (sigaction(SIGPROF, &act, 0) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } act.sa_handler = handler2; sigemptyset(&act.sa_mask); if (sigaction(SIGPROF, &act, &oact) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (oact.sa_handler == handler1) { printf("Test PASSED\n"); return PTS_PASS; } printf("Test Failed\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sigaction/28-20.c0100644000000000000000000001407610206323210022077 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertions: * * If the signal action was set with the signal() function, getting it into oact then reinstalling it with act must be valid. * The steps are: * -> register a signal handler for SIGPROF with signal(). * -> check this signal handler works. * -> change the signal handler with sigaction, saving old handler in oact. * -> check the new signal handler works. * -> set the old signal handler back * -> check the old signal handler still works. * The test fails if a signal handler does not work as expected. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /******************************************************************************/ /*************************** standard includes ********************************/ /******************************************************************************/ #include #include #include #include #include #include #include /******************************************************************************/ /*************************** Test framework *******************************/ /******************************************************************************/ /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int * (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ #include "posixtest.h" #include #include #ifdef __GNUC__ /* We are using GCC */ #define UNRESOLVED(x, s) \ { output("Test %s unresolved: got %i (%s) on line %i (%s)\n", __FILE__, x, strerror(x), __LINE__, s); \ output_fini(); \ exit(PTS_UNRESOLVED); } #define FAILED(s) \ { output("Test %s FAILED: %s\n", __FILE__, s); \ output_fini(); \ exit(PTS_FAIL); } #define PASSED \ output_fini(); \ exit(PTS_PASS); #define UNTESTED(s) \ { output("File %s cannot test: %s\n", __FILE__, s); \ output_fini(); \ exit(PTS_UNTESTED); \ } #else /* not using GCC */ #define UNRESOLVED(x, s) \ { output("Test unresolved: got %i (%s) on line %i (%s)\n", x, strerror(x), __LINE__, s); \ output_fini(); \ exit(PTS_UNRESOLVED); } #define FAILED(s) \ { output("Test FAILED: %s\n", s); \ output_fini(); \ exit(PTS_FAIL); } #define PASSED \ output_fini(); \ exit(PTS_PASS); #define UNTESTED(s) \ { output("Unable to test: %s\n", s); \ output_fini(); \ exit(PTS_UNTESTED); \ } #endif void output_init() { /* do nothing */ return ; } void output( char * string, ... ) { va_list ap; #ifndef PLOT_OUTPUT char *ts = "[??:??:??]"; struct tm * now; time_t nw; #endif #ifndef PLOT_OUTPUT nw = time( NULL ); now = localtime( &nw ); if ( now == NULL ) printf( ts ); else printf( "[%2.2d:%2.2d:%2.2d]", now->tm_hour, now->tm_min, now->tm_sec ); #endif va_start( ap, string ); vprintf( string, ap ); va_end( ap ); } void output_fini() { /*do nothing */ return ; } /******************************************************************************/ /**************************** Configuration ***********************************/ /******************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif #define SIGNAL SIGPROF /******************************************************************************/ /*************************** Test case ***********************************/ /******************************************************************************/ sig_atomic_t called = 1; void handler_1( int sig ) { called++; } void handler_2( int sig ) { called--; } /* main function */ int main() { int ret; struct sigaction sa, save; /* Initialize output */ output_init(); /* Register the signal handler with signal */ if ( SIG_ERR == signal( SIGNAL, handler_1 ) ) { UNRESOLVED( errno, "Failed to register signal handler with signal()" ); } /* As whether signal handler is restored to default when executed is implementation defined, we cannot check it was registered here. */ /* Set the new signal handler with sigaction*/ sa.sa_flags = 0; sa.sa_handler = handler_2; ret = sigemptyset( &sa.sa_mask ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to empty signal set" ); } /* Install the signal handler for SIGPROF */ ret = sigaction( SIGNAL, &sa, &save ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to set signal handler" ); } /* Check the signal handler has been set up */ ret = raise( SIGNAL ); if ( ret != 0 ) { UNRESOLVED( ret , "Failed to raise the signal" ); } if ( called != 0 ) { FAILED( "handler not executed" ); } /* Restore the first signal handler */ ret = sigaction( SIGNAL, &save, 0 ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to set signal handler" ); } /* Check the signal handler has been set up */ ret = raise( SIGNAL ); if ( ret != 0 ) { UNRESOLVED( ret , "Failed to raise the signal" ); } if ( called != 1 ) { FAILED( "handler not executed" ); } /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/sigaction/13-22.c0100644000000000000000000000327207646610407022114 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #13 of the sigaction system call that verifies signal-catching functions are executed on the current stack if the SA_ONSTACK flag is cleared in the sigaction.sa_flags parameter to the sigaction function call. NOTE: This test case does not attempt to verify the proper operation of sigaltstack. */ #define _XOPEN_SOURCE 600 #include #include #include #include "posixtest.h" stack_t current; void handler(int signo) { stack_t oss; printf("Caught SIGTRAP\n"); if (sigaltstack((stack_t *)0, &oss) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); exit(-1); } if (oss.ss_sp != current.ss_sp || oss.ss_size != current.ss_size) { printf("Test FAILED\n"); exit(-1); } } int main() { struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); if (sigaction(SIGTRAP, &act, 0) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (sigaltstack((stack_t *)0, ¤t) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (raise(SIGTRAP) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/sigaction/17-16.c0100644000000000000000000000420510205365423022106 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test assertion #17 by verifying that select returns -1 with errno set to EINTR if a handler for the SIGTTOU signal is setup with the SA_RESTART flag cleared. * 12/18/02 - Adding in include of sys/time.h per * rodrigc REMOVE-THIS AT attbi DOT com input that it needs * to be included whenever the timeval struct is used. */ #include #include #include #include #include #include #include #include #include #include "posixtest.h" volatile sig_atomic_t wakeup = 1; void handler(int signo) { printf("Caught SIGTTOU\n"); wakeup++; } int main() { pid_t pid; struct timeval tv; if ((pid = fork()) == 0) { /* child */ struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); sigaction(SIGTTOU, &act, 0); while(wakeup == 1) { tv.tv_sec = 3; tv.tv_usec = 0; if (select(0, NULL, NULL, NULL, &tv)== -1 && errno == EINTR) { perror("select"); return PTS_PASS; } } return PTS_FAIL; } else { /* parent */ int s; /* There is a race condition between the parent process sending the SIGTTOU signal, and the child process being inside the 'select' function call. I could not find a pure POSIX method for determining the state of the child process, so I just added a delay so that the test is valid in most conditions. (The problem is that it would be perfectly legal for a POSIX conformant OS to not schedule the child process for a long time.) */ tv.tv_sec = 1; tv.tv_usec = 0; select(0, NULL, NULL, NULL, &tv); kill(pid, SIGTTOU); waitpid(pid, &s, 0); if (WEXITSTATUS(s) == PTS_PASS) { printf("Test PASSED\n"); return PTS_PASS; } } printf("Test FAILED\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sigaction/22-6.c0100644000000000000000000000467407646610413022042 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #22 of the sigaction system call that verifies that if the SA_NODEFER flag is set for a given signal, then when the sa_sigaction signal-catching function is entered, then the signal that was caught is not added to the signal mask by raising that signal in the signal handler and verifying that the handler is reentered. Steps: 1. Fork a new process 2. (parent) wait for child 3. (child) Setup a signal handler for SIGFPE with SA_NODEFER set in the sa_flags field 4. (child) raise SIGFPE 5. (child, signal handler) increment handler count 6. (child, signal handler) if count is 1 then raise SIGFPE 7. (child, signal handler) if count is 1 then set error variable 8. (child) if error is set then return -1, else return 0 6. (parent - returning from wait) If child returned 0 then exit 0, otherwise exit -1. */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include "posixtest.h" int handler_count = 0; void handler(int signo) { static int inside_handler = 0; printf("SIGFPE caught\n"); if (inside_handler) { printf("Signal caught while inside handler\n"); exit(0); } inside_handler++; handler_count++; if (handler_count == 1) { printf("Raising SIGFPE\n"); raise(SIGFPE); printf("Returning from raising SIGFPE\n"); } inside_handler--; } int main() { if (fork() == 0) { /* child */ struct sigaction act; act.sa_handler = handler; act.sa_flags = SA_NODEFER; sigemptyset(&act.sa_mask); if (sigaction(SIGFPE, &act, 0) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); return PTS_UNRESOLVED; } if (raise(SIGFPE) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); return PTS_UNRESOLVED; } return PTS_FAIL; } else { int s; /* parent */ if (wait(&s) == -1) { perror("Unexpected error while setting up test " "pre-conditions"); return PTS_UNRESOLVED; } if (!WEXITSTATUS(s)) { printf("Test PASSED\n"); return PTS_PASS; } } printf("Test FAILED\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sigaction/4-13.c0100644000000000000000000000355607631716560022042 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #4 of the sigaction system call that shows that attempting to add SIGKILL can not be added to the signal mask for a signal handler. Steps: 1. Fork a new process 2. (parent) wait for child 3. (child) Setup a signal handler for SIGTERM with SIGKILL added to the signal mask 4. (child) raise SIGTERM 5. (child, signal handler) raise SIGKILL 5. (child) If still alive then exit -1 6. (parent - returning from wait) If child was killed then return success, otherwise fail. */ #include #include #include #include #include #include "posixtest.h" void handler(int signo) { raise(SIGKILL); exit(0); } int main() { if (fork() == 0) { /* child */ /* * NOTE: This block of code will return 0 for error * and anything else for success. */ struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); sigaddset(&act.sa_mask, SIGKILL); if (sigaction(SIGTERM, &act, 0) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); return PTS_PASS; } if (raise(SIGTERM) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); } return PTS_PASS; } else { int s; /* parent */ if (wait(&s) == -1) { perror("Unexpected error while setting up test " "pre-conditions"); return PTS_UNRESOLVED; } if (!WIFEXITED(s)) { printf("Test PASSED\n"); return PTS_PASS; } } printf("Test FAILED\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sigaction/23-16.c0100644000000000000000000001036010205365424022103 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertions: * * If SA_NODEFER is not set in sa_flags, the caught signal is added to the * thread's signal mask during the handler execution. * The steps are: * -> register a signal handler for SIGTTOU * -> raise SIGTTOU * -> In handler, check for reentrance then raise SIGTTOU again. * The test fails if signal handler if reentered or signal is not pending when raised again. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /******************************************************************************/ /*************************** standard includes ********************************/ /******************************************************************************/ #include #include #include #include #include #include #include #include /******************************************************************************/ /*************************** Test framework *******************************/ /******************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int * (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /******************************************************************************/ /**************************** Configuration ***********************************/ /******************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif #define SIGNAL SIGTTOU /******************************************************************************/ /*************************** Test case ***********************************/ /******************************************************************************/ int called = 0; void handler( int sig ) { int ret; sigset_t pending; called++; if ( called == 2 ) { FAILED( "Signal was not masked in signal handler" ); } if ( called == 1 ) { /* Raise the signal again. It should be masked */ ret = raise( SIGNAL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to raise SIGTTOU again" ); } /* check the signal is pending */ ret = sigpending( &pending ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to get pending signal set" ); } ret = sigismember( &pending, SIGNAL ); if ( ret != 1 ) { FAILED( "signal is not pending" ); } } called++; } /* main function */ int main() { int ret; struct sigaction sa; /* Initialize output */ output_init(); /* Set the signal handler */ sa.sa_flags = 0; sa.sa_handler = handler; ret = sigemptyset( &sa.sa_mask ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to empty signal set" ); } /* Install the signal handler for SIGTTOU */ ret = sigaction( SIGNAL, &sa, 0 ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to set signal handler" ); } ret = raise( SIGNAL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to raise SIGTTOU" ); } while ( called != 4 ) sched_yield(); /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/sigaction/16-25.c0100644000000000000000000001261010205365423022104 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertions: * * If SA_RESTART is set in sa_flags, interruptible function interrupted by signal * shall restart silently. * The steps are: * -> create a child thread * -> child registers a handler for SIGXCPU with SA_RESTART, then waits for the semaphore * -> parent kills the child with SIGXCPU, then post the semaphore. * The test fails if the sem_wait function returns EINTR *Note: This test uses sem_wait to check if EINTR is returned. As the function is not required to fail with EINTR, the test may return PASS and the feature not be correct (false positive). Anyway, a false negative status cannot be returned. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /* This test tests for an XSI feature */ #define _XOPEN_SOURCE 600 /******************************************************************************/ /*************************** standard includes ********************************/ /******************************************************************************/ #include #include #include #include #include #include #include #include #include /******************************************************************************/ /*************************** Test framework *******************************/ /******************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int * (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /******************************************************************************/ /**************************** Configuration ***********************************/ /******************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif #define SIGNAL SIGXCPU /******************************************************************************/ /*************************** Test case ***********************************/ /******************************************************************************/ volatile sig_atomic_t caught = 0; sem_t sem; /* Handler function */ void handler( int signo ) { printf( "Caught signal %d\n", signo ); caught++; } /* Thread function */ void * threaded ( void * arg ) { int ret = 0; ret = sem_wait( &sem ); if ( ret != 0 ) { if ( errno == EINTR ) { FAILED( "The function returned EINTR while SA_RESTART is set" ); } else { UNRESOLVED( errno, "sem_wait failed" ); } } return NULL; } /* main function */ int main() { int ret; pthread_t child; struct sigaction sa; /* Initialize output */ output_init(); /* Set the signal handler */ sa.sa_flags = SA_RESTART; sa.sa_handler = handler; ret = sigemptyset( &sa.sa_mask ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to empty signal set" ); } /* Install the signal handler for SIGNAL */ ret = sigaction( SIGNAL, &sa, 0 ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to set signal handler" ); } /* Initialize the semaphore */ ret = sem_init( &sem, 0, 0 ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to init a semaphore" ); } /* Create the child thread */ ret = pthread_create( &child, NULL, threaded, NULL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to create a child thread" ); } /* Let the child thread enter the wait routine... we use sched_yield as there is no certain way to test that the child is waiting for the semaphore... */ sched_yield(); sched_yield(); sched_yield(); /* Ok, now kill the child */ ret = pthread_kill( child, SIGNAL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to kill the child thread" ); } /* wait that the child receives the signal */ while ( !caught ) sched_yield(); /* Now let the child run and terminate */ ret = sem_post( &sem ); if ( ret != 0 ) { UNRESOLVED( errno, "Failed to post the semaphore" ); } ret = pthread_join( child, NULL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to join the thread" ); } /* terminate */ ret = sem_destroy( &sem ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to destroy the semaphore" ); } /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/sigaction/3-19.c0100644000000000000000000000276507631716555022054 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #3 of the sigaction system call that shows calling sigaction with a null act argument does not change the signal handler. Steps: 1. Initialize global variable to indicate handler has not been called 2. Set the signal handler for SIGPOLL to handler 3. Call sigaction with a null act 4. raise SIGPOLL 5. Verify handler was called. */ #include #include #include "posixtest.h" int handler_called = 0; void handler(int signo) { handler_called = 1; } int main() { struct sigaction act; struct sigaction oact; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); if (sigaction(SIGPOLL, &act, 0) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (sigaction(SIGPOLL, 0, &oact) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (raise(SIGPOLL) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (handler_called) { printf("Test PASSED\n"); return PTS_PASS; } printf("Test FAILED\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sigaction/3-5.c0100644000000000000000000000276507631716556021770 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #3 of the sigaction system call that shows calling sigaction with a null act argument does not change the signal handler. Steps: 1. Initialize global variable to indicate handler has not been called 2. Set the signal handler for SIGCONT to handler 3. Call sigaction with a null act 4. raise SIGCONT 5. Verify handler was called. */ #include #include #include "posixtest.h" int handler_called = 0; void handler(int signo) { handler_called = 1; } int main() { struct sigaction act; struct sigaction oact; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); if (sigaction(SIGCONT, &act, 0) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (sigaction(SIGCONT, 0, &oact) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (raise(SIGCONT) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (handler_called) { printf("Test PASSED\n"); return PTS_PASS; } printf("Test FAILED\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sigaction/4-24.c0100644000000000000000000000356607631716560022045 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #4 of the sigaction system call that shows that attempting to add SIGKILL can not be added to the signal mask for a signal handler. Steps: 1. Fork a new process 2. (parent) wait for child 3. (child) Setup a signal handler for SIGVTALRM with SIGKILL added to the signal mask 4. (child) raise SIGVTALRM 5. (child, signal handler) raise SIGKILL 5. (child) If still alive then exit -1 6. (parent - returning from wait) If child was killed then return success, otherwise fail. */ #include #include #include #include #include #include "posixtest.h" void handler(int signo) { raise(SIGKILL); exit(0); } int main() { if (fork() == 0) { /* child */ /* * NOTE: This block of code will return 0 for error * and anything else for success. */ struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); sigaddset(&act.sa_mask, SIGKILL); if (sigaction(SIGVTALRM, &act, 0) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); return PTS_PASS; } if (raise(SIGVTALRM) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); } return PTS_PASS; } else { int s; /* parent */ if (wait(&s) == -1) { perror("Unexpected error while setting up test " "pre-conditions"); return PTS_UNRESOLVED; } if (!WIFEXITED(s)) { printf("Test PASSED\n"); return PTS_PASS; } } printf("Test FAILED\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sigaction/18-8.c0100644000000000000000000000743410205365423022037 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertions: * * If SA_SIGINFO is not set in sa_flags, sa_handler is used as the signal * handling function. * The steps are: * -> register a handler for SIGILL without SA_SIGINFO, and a known function * as saèhandler * -> raise SIGILL, and check the function has been called. * The test fails if the function is not called */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /******************************************************************************/ /*************************** standard includes ********************************/ /******************************************************************************/ #include #include #include #include #include #include #include #include /******************************************************************************/ /*************************** Test framework *******************************/ /******************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int * (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /******************************************************************************/ /**************************** Configuration ***********************************/ /******************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif #define SIGNAL SIGILL /******************************************************************************/ /*************************** Test case ***********************************/ /******************************************************************************/ int called = 0; void handler( int sig ) { called = 1; } /* main function */ int main() { int ret; struct sigaction sa; /* Initialize output */ output_init(); /* Set the signal handler */ sa.sa_flags = 0; sa.sa_handler = handler; ret = sigemptyset( &sa.sa_mask ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to empty signal set" ); } /* Install the signal handler for SIGILL */ ret = sigaction( SIGNAL, &sa, 0 ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to set signal handler" ); } if ( called ) { FAILED( "The signal handler has been called when no signal was raised" ); } ret = raise( SIGNAL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to raise SIGILL" ); } if ( !called ) { FAILED( "the sa_handler was not called whereas SA_SIGINFO was not set" ); } /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/sigaction/4-31.c0100644000000000000000000000370507646624631022041 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #4 of the sigaction system call that shows that attempting to add SIGSTOP can not be added to the signal mask for a signal handler. Steps: 1. Fork a new process 2. (parent) wait for child 3. (child) Setup a signal handler for SIGCONT with SIGSTOP added to the signal mask 4. (child) raise SIGCONT 5. (child, signal handler) raise SIGSTOP 5. (child) If still around then return -1 6. (parent - returning from wait) If child was stopped then return kill the child and return success, otherwise fail. */ #include #include #include #include #include #include #include "posixtest.h" void handler(int signo) { printf("About to stop child\n"); raise(SIGSTOP); printf("Child has continued\n"); exit(0); } int main() { pid_t pid; if ((pid = fork()) == 0) { /* child */ struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); sigaddset(&act.sa_mask, SIGSTOP); if (sigaction(SIGCONT, &act, 0) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); return PTS_UNRESOLVED; } if (raise(SIGCONT) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); } return PTS_UNRESOLVED; } else { int s; /* parent */ if (waitpid(pid, &s, WUNTRACED) == -1) { perror("Unexpected error while setting up test " "pre-conditions"); return PTS_UNRESOLVED; } if (WIFSTOPPED(s)) { printf("Test PASSED\n"); kill(pid, SIGKILL); return PTS_PASS; } } printf("Test FAILED\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sigaction/25-3.c0100644000000000000000000000461107646610420022027 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #25 of the sigaction system call that verifies that when the sa_sigaction signal-catching function is entered, then the signal that was caught is added to the signal mask by raising that signal in the signal handler and verifying that the handler is not reentered. Steps: 1. Fork a new process 2. (parent) wait for child 3. (child) Setup a signal handler for SIGBUS 4. (child) raise SIGBUS 5. (child, signal handler) increment handler count 6. (child, signal handler) if count is 1 then raise SIGBUS 7. (child, signal handler) if count is 2 then set error variable 8. (child) if error is set then return -1, else return 0 6. (parent - returning from wait) If child returned 0 then exit 0, otherwise exit -1. */ #include #include #include #include #include #include "posixtest.h" int handler_count = 0; int handler_error = 0; void handler(int signo) { static int inside_handler = 0; printf("SIGBUS caught\n"); if (inside_handler) { printf("Signal caught while inside handler\n"); handler_error++; exit(-1); } inside_handler++; handler_count++; if (handler_count == 1) { printf("Raising SIGBUS\n"); raise(SIGBUS); printf("Returning from raising SIGBUS\n"); } inside_handler--; } int main() { if (fork() == 0) { /* child */ struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); if (sigaction(SIGBUS, &act, 0) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); return PTS_UNRESOLVED; } if (raise(SIGBUS) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); return PTS_UNRESOLVED; } if (handler_error) return PTS_UNRESOLVED; return PTS_PASS; } else { int s; /* parent */ if (wait(&s) == -1) { perror("Unexpected error while setting up test " "pre-conditions"); return PTS_UNRESOLVED; } if (!WEXITSTATUS(s)) { printf("Test PASSED\n"); return PTS_PASS; } } printf("Test FAILED\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sigaction/17-25.c0100644000000000000000000000420510205365423022106 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test assertion #17 by verifying that select returns -1 with errno set to EINTR if a handler for the SIGXCPU signal is setup with the SA_RESTART flag cleared. * 12/18/02 - Adding in include of sys/time.h per * rodrigc REMOVE-THIS AT attbi DOT com input that it needs * to be included whenever the timeval struct is used. */ #include #include #include #include #include #include #include #include #include #include "posixtest.h" volatile sig_atomic_t wakeup = 1; void handler(int signo) { printf("Caught SIGXCPU\n"); wakeup++; } int main() { pid_t pid; struct timeval tv; if ((pid = fork()) == 0) { /* child */ struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); sigaction(SIGXCPU, &act, 0); while(wakeup == 1) { tv.tv_sec = 3; tv.tv_usec = 0; if (select(0, NULL, NULL, NULL, &tv)== -1 && errno == EINTR) { perror("select"); return PTS_PASS; } } return PTS_FAIL; } else { /* parent */ int s; /* There is a race condition between the parent process sending the SIGXCPU signal, and the child process being inside the 'select' function call. I could not find a pure POSIX method for determining the state of the child process, so I just added a delay so that the test is valid in most conditions. (The problem is that it would be perfectly legal for a POSIX conformant OS to not schedule the child process for a long time.) */ tv.tv_sec = 1; tv.tv_usec = 0; select(0, NULL, NULL, NULL, &tv); kill(pid, SIGXCPU); waitpid(pid, &s, 0); if (WEXITSTATUS(s) == PTS_PASS) { printf("Test PASSED\n"); return PTS_PASS; } } printf("Test FAILED\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sigaction/4-83.c0100644000000000000000000000161007631716565022043 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #4 of the sigaction system call that shows that attempting to add SIGSTOP to the signal mask of SIGCONT will not result in sigaction returning -1 */ #include #include #include #include #include #include "posixtest.h" void handler(int signo) { } int main() { struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); sigaddset(&act.sa_mask, SIGSTOP); if (sigaction(SIGCONT, &act, 0) == -1) { printf("Test FAILED\n"); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/sigaction/6-12.c0100644000000000000000000000246507646610422022035 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #5 of the sigaction system call that verifies setting the SA_INFO bit in the signal mask for SIGSEGV will result in sa_sigaction identifying the signal-catching function. */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include "posixtest.h" int handler_called = 0; void handler(int signo, siginfo_t *info, void *context) { handler_called = 1; } int main() { struct sigaction act; act.sa_sigaction = handler; act.sa_flags = SA_SIGINFO; sigemptyset(&act.sa_mask); sigaddset(&act.sa_mask, SIGSTOP); if (sigaction(SIGSEGV, &act, 0) == -1) { printf("Unexpected error while attempting to setup test " "pre-conditions\n"); return PTS_UNRESOLVED; } if (raise(SIGSEGV) == -1) { printf("Unexpected error while attempting to setup test " "pre-conditions\n"); return PTS_UNRESOLVED; } if (handler_called) { printf("Test PASSED\n"); return PTS_PASS; } printf("Test FAILED\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sigaction/17-2.c0100644000000000000000000000420510205365423022021 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test assertion #17 by verifying that select returns -1 with errno set to EINTR if a handler for the SIGALRM signal is setup with the SA_RESTART flag cleared. * 12/18/02 - Adding in include of sys/time.h per * rodrigc REMOVE-THIS AT attbi DOT com input that it needs * to be included whenever the timeval struct is used. */ #include #include #include #include #include #include #include #include #include #include "posixtest.h" volatile sig_atomic_t wakeup = 1; void handler(int signo) { printf("Caught SIGALRM\n"); wakeup++; } int main() { pid_t pid; struct timeval tv; if ((pid = fork()) == 0) { /* child */ struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); sigaction(SIGALRM, &act, 0); while(wakeup == 1) { tv.tv_sec = 3; tv.tv_usec = 0; if (select(0, NULL, NULL, NULL, &tv)== -1 && errno == EINTR) { perror("select"); return PTS_PASS; } } return PTS_FAIL; } else { /* parent */ int s; /* There is a race condition between the parent process sending the SIGALRM signal, and the child process being inside the 'select' function call. I could not find a pure POSIX method for determining the state of the child process, so I just added a delay so that the test is valid in most conditions. (The problem is that it would be perfectly legal for a POSIX conformant OS to not schedule the child process for a long time.) */ tv.tv_sec = 1; tv.tv_usec = 0; select(0, NULL, NULL, NULL, &tv); kill(pid, SIGALRM); waitpid(pid, &s, 0); if (WEXITSTATUS(s) == PTS_PASS) { printf("Test PASSED\n"); return PTS_PASS; } } printf("Test FAILED\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sigaction/17-10.c0100644000000000000000000000420510205365423022100 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test assertion #17 by verifying that select returns -1 with errno set to EINTR if a handler for the SIGPIPE signal is setup with the SA_RESTART flag cleared. * 12/18/02 - Adding in include of sys/time.h per * rodrigc REMOVE-THIS AT attbi DOT com input that it needs * to be included whenever the timeval struct is used. */ #include #include #include #include #include #include #include #include #include #include "posixtest.h" volatile sig_atomic_t wakeup = 1; void handler(int signo) { printf("Caught SIGPIPE\n"); wakeup++; } int main() { pid_t pid; struct timeval tv; if ((pid = fork()) == 0) { /* child */ struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); sigaction(SIGPIPE, &act, 0); while(wakeup == 1) { tv.tv_sec = 3; tv.tv_usec = 0; if (select(0, NULL, NULL, NULL, &tv)== -1 && errno == EINTR) { perror("select"); return PTS_PASS; } } return PTS_FAIL; } else { /* parent */ int s; /* There is a race condition between the parent process sending the SIGPIPE signal, and the child process being inside the 'select' function call. I could not find a pure POSIX method for determining the state of the child process, so I just added a delay so that the test is valid in most conditions. (The problem is that it would be perfectly legal for a POSIX conformant OS to not schedule the child process for a long time.) */ tv.tv_sec = 1; tv.tv_usec = 0; select(0, NULL, NULL, NULL, &tv); kill(pid, SIGPIPE); waitpid(pid, &s, 0); if (WEXITSTATUS(s) == PTS_PASS) { printf("Test PASSED\n"); return PTS_PASS; } } printf("Test FAILED\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sigaction/25-16.c0100644000000000000000000000462207646610414022120 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #25 of the sigaction system call that verifies that when the sa_sigaction signal-catching function is entered, then the signal that was caught is added to the signal mask by raising that signal in the signal handler and verifying that the handler is not reentered. Steps: 1. Fork a new process 2. (parent) wait for child 3. (child) Setup a signal handler for SIGTTOU 4. (child) raise SIGTTOU 5. (child, signal handler) increment handler count 6. (child, signal handler) if count is 1 then raise SIGTTOU 7. (child, signal handler) if count is 2 then set error variable 8. (child) if error is set then return -1, else return 0 6. (parent - returning from wait) If child returned 0 then exit 0, otherwise exit -1. */ #include #include #include #include #include #include "posixtest.h" int handler_count = 0; int handler_error = 0; void handler(int signo) { static int inside_handler = 0; printf("SIGTTOU caught\n"); if (inside_handler) { printf("Signal caught while inside handler\n"); handler_error++; exit(-1); } inside_handler++; handler_count++; if (handler_count == 1) { printf("Raising SIGTTOU\n"); raise(SIGTTOU); printf("Returning from raising SIGTTOU\n"); } inside_handler--; } int main() { if (fork() == 0) { /* child */ struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); if (sigaction(SIGTTOU, &act, 0) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); return PTS_UNRESOLVED; } if (raise(SIGTTOU) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); return PTS_UNRESOLVED; } if (handler_error) return PTS_UNRESOLVED; return PTS_PASS; } else { int s; /* parent */ if (wait(&s) == -1) { perror("Unexpected error while setting up test " "pre-conditions"); return PTS_UNRESOLVED; } if (!WEXITSTATUS(s)) { printf("Test PASSED\n"); return PTS_PASS; } } printf("Test FAILED\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sigaction/13-19.c0100644000000000000000000000327207646610406022121 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #13 of the sigaction system call that verifies signal-catching functions are executed on the current stack if the SA_ONSTACK flag is cleared in the sigaction.sa_flags parameter to the sigaction function call. NOTE: This test case does not attempt to verify the proper operation of sigaltstack. */ #define _XOPEN_SOURCE 600 #include #include #include #include "posixtest.h" stack_t current; void handler(int signo) { stack_t oss; printf("Caught SIGPOLL\n"); if (sigaltstack((stack_t *)0, &oss) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); exit(-1); } if (oss.ss_sp != current.ss_sp || oss.ss_size != current.ss_size) { printf("Test FAILED\n"); exit(-1); } } int main() { struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); if (sigaction(SIGPOLL, &act, 0) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (sigaltstack((stack_t *)0, ¤t) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (raise(SIGPOLL) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/sigaction/4-61.c0100644000000000000000000000160607631716563022042 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #4 of the sigaction system call that shows that attempting to add SIGKILL to the signal mask of SIGINT will not result in sigaction returning -1 */ #include #include #include #include #include #include "posixtest.h" void handler(int signo) { } int main() { struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); sigaddset(&act.sa_mask, SIGKILL); if (sigaction(SIGINT, &act, 0) == -1) { printf("Test FAILED\n"); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/sigaction/6-13.c0100644000000000000000000000246507646610422022036 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #5 of the sigaction system call that verifies setting the SA_INFO bit in the signal mask for SIGTERM will result in sa_sigaction identifying the signal-catching function. */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include "posixtest.h" int handler_called = 0; void handler(int signo, siginfo_t *info, void *context) { handler_called = 1; } int main() { struct sigaction act; act.sa_sigaction = handler; act.sa_flags = SA_SIGINFO; sigemptyset(&act.sa_mask); sigaddset(&act.sa_mask, SIGSTOP); if (sigaction(SIGTERM, &act, 0) == -1) { printf("Unexpected error while attempting to setup test " "pre-conditions\n"); return PTS_UNRESOLVED; } if (raise(SIGTERM) == -1) { printf("Unexpected error while attempting to setup test " "pre-conditions\n"); return PTS_UNRESOLVED; } if (handler_called) { printf("Test PASSED\n"); return PTS_PASS; } printf("Test FAILED\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sigaction/12-33.c0100644000000000000000000000335207650040046022103 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #12 of the sigaction system call that verifies signal-catching functions are executed on the current stack if the SA_ONSTACK flag is set in the sigaction.sa_flags parameter to the sigaction function call, but a new stack has not be set by sigaltstack(). NOTE: This test case does not attempt to verify the proper operation of sigaltstack. */ #define _XOPEN_SOURCE 600 #include #include #include #include "posixtest.h" stack_t current; void handler(int signo) { stack_t oss; printf("Caught SIGHUP\n"); if (sigaltstack((stack_t *)0, &oss) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); exit(-1); } if (oss.ss_sp != current.ss_sp || oss.ss_size != current.ss_size) { printf("Test FAILED\n"); exit(-1); } } int main() { struct sigaction act; act.sa_handler = handler; act.sa_flags = SA_ONSTACK; sigemptyset(&act.sa_mask); if (sigaction(SIGHUP, &act, 0) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (sigaltstack((stack_t *)0, ¤t) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (raise(SIGHUP) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/sigaction/12-12.c0100644000000000000000000000372707646610402022112 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #12 of the sigaction system call that verifies signal-catching functions are executed on the alternate stack if the SA_ONSTACK flag is set in the sigaction.sa_flags parameter to the sigaction function call, and an alternate stack has been setup with sigaltstack(). NOTE: This test case does not attempt to verify the proper operation of sigaltstack. */ #define _XOPEN_SOURCE 600 #include #include #include #include "posixtest.h" stack_t alt_ss; void handler(int signo) { stack_t ss; printf("Caught SIGSEGV\n"); if (sigaltstack((stack_t *)0, &ss) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); exit(-1); } if (ss.ss_sp != alt_ss.ss_sp || ss.ss_size != alt_ss.ss_size) { printf("Test FAILED\n"); exit(-1); } } int main() { struct sigaction act; act.sa_handler = handler; act.sa_flags = SA_ONSTACK; sigemptyset(&act.sa_mask); if (sigaction(SIGSEGV, &act, 0) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if ((alt_ss.ss_sp = (void *)malloc(SIGSTKSZ)) == NULL) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } alt_ss.ss_size = SIGSTKSZ; alt_ss.ss_flags = 0; if (sigaltstack(&alt_ss, (stack_t *)0) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (raise(SIGSEGV) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/sigaction/4-4.c0100644000000000000000000000355607631716561021763 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #4 of the sigaction system call that shows that attempting to add SIGKILL can not be added to the signal mask for a signal handler. Steps: 1. Fork a new process 2. (parent) wait for child 3. (child) Setup a signal handler for SIGCHLD with SIGKILL added to the signal mask 4. (child) raise SIGCHLD 5. (child, signal handler) raise SIGKILL 5. (child) If still alive then exit -1 6. (parent - returning from wait) If child was killed then return success, otherwise fail. */ #include #include #include #include #include #include "posixtest.h" void handler(int signo) { raise(SIGKILL); exit(0); } int main() { if (fork() == 0) { /* child */ /* * NOTE: This block of code will return 0 for error * and anything else for success. */ struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); sigaddset(&act.sa_mask, SIGKILL); if (sigaction(SIGCHLD, &act, 0) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); return PTS_PASS; } if (raise(SIGCHLD) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); } return PTS_PASS; } else { int s; /* parent */ if (wait(&s) == -1) { perror("Unexpected error while setting up test " "pre-conditions"); return PTS_UNRESOLVED; } if (!WIFEXITED(s)) { printf("Test PASSED\n"); return PTS_PASS; } } printf("Test FAILED\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sigaction/19-11.c0100644000000000000000000001017610205365423022107 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertions: * * If SA_SIGINFO is set in sa_flags and Real Time Signals extension is supported, * sa_sigaction is used as the signal handling function. * The steps are: * -> test for RTS extension * -> register a handler for SIGQUIT with SA_SIGINFO, and a known function * as sa_sigaction * -> raise SIGQUIT, and check the function has been called. * The test fails if the function is not called */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /******************************************************************************/ /*************************** standard includes ********************************/ /******************************************************************************/ #include #include #include #include #include #include #include #include /******************************************************************************/ /*************************** Test framework *******************************/ /******************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int * (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /******************************************************************************/ /**************************** Configuration ***********************************/ /******************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif #define SIGNAL SIGQUIT /******************************************************************************/ /*************************** Test case ***********************************/ /******************************************************************************/ int called = 0; void handler( int sig, siginfo_t *info, void *context ) { if ( info->si_signo != SIGNAL ) { FAILED( "Wrong signal generated?" ); } called = 1; } /* main function */ int main() { int ret; long rts; struct sigaction sa; /* Initialize output */ output_init(); /* Test the RTS extension */ rts = sysconf( _SC_REALTIME_SIGNALS ); if ( rts < 0L ) { UNTESTED( "This test needs the RTS extension" ); } /* Set the signal handler */ sa.sa_flags = SA_SIGINFO; sa.sa_sigaction = handler; ret = sigemptyset( &sa.sa_mask ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to empty signal set" ); } /* Install the signal handler for SIGQUIT */ ret = sigaction( SIGNAL, &sa, 0 ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to set signal handler" ); } if ( called ) { FAILED( "The signal handler has been called when no signal was raised" ); } ret = raise( SIGNAL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to raise SIGQUIT" ); } if ( !called ) { FAILED( "the sa_handler was not called whereas SA_SIGINFO was not set" ); } /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/sigaction/18-16.c0100644000000000000000000000744110205365423022114 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertions: * * If SA_SIGINFO is not set in sa_flags, sa_handler is used as the signal * handling function. * The steps are: * -> register a handler for SIGTTOU without SA_SIGINFO, and a known function * as saèhandler * -> raise SIGTTOU, and check the function has been called. * The test fails if the function is not called */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /******************************************************************************/ /*************************** standard includes ********************************/ /******************************************************************************/ #include #include #include #include #include #include #include #include /******************************************************************************/ /*************************** Test framework *******************************/ /******************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int * (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /******************************************************************************/ /**************************** Configuration ***********************************/ /******************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif #define SIGNAL SIGTTOU /******************************************************************************/ /*************************** Test case ***********************************/ /******************************************************************************/ int called = 0; void handler( int sig ) { called = 1; } /* main function */ int main() { int ret; struct sigaction sa; /* Initialize output */ output_init(); /* Set the signal handler */ sa.sa_flags = 0; sa.sa_handler = handler; ret = sigemptyset( &sa.sa_mask ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to empty signal set" ); } /* Install the signal handler for SIGTTOU */ ret = sigaction( SIGNAL, &sa, 0 ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to set signal handler" ); } if ( called ) { FAILED( "The signal handler has been called when no signal was raised" ); } ret = raise( SIGNAL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to raise SIGTTOU" ); } if ( !called ) { FAILED( "the sa_handler was not called whereas SA_SIGINFO was not set" ); } /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/sigaction/18-17.c0100644000000000000000000000744110205365423022115 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertions: * * If SA_SIGINFO is not set in sa_flags, sa_handler is used as the signal * handling function. * The steps are: * -> register a handler for SIGUSR1 without SA_SIGINFO, and a known function * as saèhandler * -> raise SIGUSR1, and check the function has been called. * The test fails if the function is not called */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /******************************************************************************/ /*************************** standard includes ********************************/ /******************************************************************************/ #include #include #include #include #include #include #include #include /******************************************************************************/ /*************************** Test framework *******************************/ /******************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int * (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /******************************************************************************/ /**************************** Configuration ***********************************/ /******************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif #define SIGNAL SIGUSR1 /******************************************************************************/ /*************************** Test case ***********************************/ /******************************************************************************/ int called = 0; void handler( int sig ) { called = 1; } /* main function */ int main() { int ret; struct sigaction sa; /* Initialize output */ output_init(); /* Set the signal handler */ sa.sa_flags = 0; sa.sa_handler = handler; ret = sigemptyset( &sa.sa_mask ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to empty signal set" ); } /* Install the signal handler for SIGUSR1 */ ret = sigaction( SIGNAL, &sa, 0 ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to set signal handler" ); } if ( called ) { FAILED( "The signal handler has been called when no signal was raised" ); } ret = raise( SIGNAL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to raise SIGUSR1" ); } if ( !called ) { FAILED( "the sa_handler was not called whereas SA_SIGINFO was not set" ); } /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/sigaction/25-8.c0100644000000000000000000000461107646610420022034 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #25 of the sigaction system call that verifies that when the sa_sigaction signal-catching function is entered, then the signal that was caught is added to the signal mask by raising that signal in the signal handler and verifying that the handler is not reentered. Steps: 1. Fork a new process 2. (parent) wait for child 3. (child) Setup a signal handler for SIGILL 4. (child) raise SIGILL 5. (child, signal handler) increment handler count 6. (child, signal handler) if count is 1 then raise SIGILL 7. (child, signal handler) if count is 2 then set error variable 8. (child) if error is set then return -1, else return 0 6. (parent - returning from wait) If child returned 0 then exit 0, otherwise exit -1. */ #include #include #include #include #include #include "posixtest.h" int handler_count = 0; int handler_error = 0; void handler(int signo) { static int inside_handler = 0; printf("SIGILL caught\n"); if (inside_handler) { printf("Signal caught while inside handler\n"); handler_error++; exit(-1); } inside_handler++; handler_count++; if (handler_count == 1) { printf("Raising SIGILL\n"); raise(SIGILL); printf("Returning from raising SIGILL\n"); } inside_handler--; } int main() { if (fork() == 0) { /* child */ struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); if (sigaction(SIGILL, &act, 0) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); return PTS_UNRESOLVED; } if (raise(SIGILL) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); return PTS_UNRESOLVED; } if (handler_error) return PTS_UNRESOLVED; return PTS_PASS; } else { int s; /* parent */ if (wait(&s) == -1) { perror("Unexpected error while setting up test " "pre-conditions"); return PTS_UNRESOLVED; } if (!WEXITSTATUS(s)) { printf("Test PASSED\n"); return PTS_PASS; } } printf("Test FAILED\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sigaction/19-17.c0100644000000000000000000001017610205365423022115 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertions: * * If SA_SIGINFO is set in sa_flags and Real Time Signals extension is supported, * sa_sigaction is used as the signal handling function. * The steps are: * -> test for RTS extension * -> register a handler for SIGUSR1 with SA_SIGINFO, and a known function * as sa_sigaction * -> raise SIGUSR1, and check the function has been called. * The test fails if the function is not called */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /******************************************************************************/ /*************************** standard includes ********************************/ /******************************************************************************/ #include #include #include #include #include #include #include #include /******************************************************************************/ /*************************** Test framework *******************************/ /******************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int * (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /******************************************************************************/ /**************************** Configuration ***********************************/ /******************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif #define SIGNAL SIGUSR1 /******************************************************************************/ /*************************** Test case ***********************************/ /******************************************************************************/ int called = 0; void handler( int sig, siginfo_t *info, void *context ) { if ( info->si_signo != SIGNAL ) { FAILED( "Wrong signal generated?" ); } called = 1; } /* main function */ int main() { int ret; long rts; struct sigaction sa; /* Initialize output */ output_init(); /* Test the RTS extension */ rts = sysconf( _SC_REALTIME_SIGNALS ); if ( rts < 0L ) { UNTESTED( "This test needs the RTS extension" ); } /* Set the signal handler */ sa.sa_flags = SA_SIGINFO; sa.sa_sigaction = handler; ret = sigemptyset( &sa.sa_mask ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to empty signal set" ); } /* Install the signal handler for SIGUSR1 */ ret = sigaction( SIGNAL, &sa, 0 ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to set signal handler" ); } if ( called ) { FAILED( "The signal handler has been called when no signal was raised" ); } ret = raise( SIGNAL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to raise SIGUSR1" ); } if ( !called ) { FAILED( "the sa_handler was not called whereas SA_SIGINFO was not set" ); } /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/sigaction/4-1.c0100644000000000000000000000355607631716557021765 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #4 of the sigaction system call that shows that attempting to add SIGKILL can not be added to the signal mask for a signal handler. Steps: 1. Fork a new process 2. (parent) wait for child 3. (child) Setup a signal handler for SIGABRT with SIGKILL added to the signal mask 4. (child) raise SIGABRT 5. (child, signal handler) raise SIGKILL 5. (child) If still alive then exit -1 6. (parent - returning from wait) If child was killed then return success, otherwise fail. */ #include #include #include #include #include #include "posixtest.h" void handler(int signo) { raise(SIGKILL); exit(0); } int main() { if (fork() == 0) { /* child */ /* * NOTE: This block of code will return 0 for error * and anything else for success. */ struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); sigaddset(&act.sa_mask, SIGKILL); if (sigaction(SIGABRT, &act, 0) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); return PTS_PASS; } if (raise(SIGABRT) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); } return PTS_PASS; } else { int s; /* parent */ if (wait(&s) == -1) { perror("Unexpected error while setting up test " "pre-conditions"); return PTS_UNRESOLVED; } if (!WIFEXITED(s)) { printf("Test PASSED\n"); return PTS_PASS; } } printf("Test FAILED\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sigaction/23-26.c0100644000000000000000000001036010205365424022104 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertions: * * If SA_NODEFER is not set in sa_flags, the caught signal is added to the * thread's signal mask during the handler execution. * The steps are: * -> register a signal handler for SIGXFSZ * -> raise SIGXFSZ * -> In handler, check for reentrance then raise SIGXFSZ again. * The test fails if signal handler if reentered or signal is not pending when raised again. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /******************************************************************************/ /*************************** standard includes ********************************/ /******************************************************************************/ #include #include #include #include #include #include #include #include /******************************************************************************/ /*************************** Test framework *******************************/ /******************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int * (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /******************************************************************************/ /**************************** Configuration ***********************************/ /******************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif #define SIGNAL SIGXFSZ /******************************************************************************/ /*************************** Test case ***********************************/ /******************************************************************************/ int called = 0; void handler( int sig ) { int ret; sigset_t pending; called++; if ( called == 2 ) { FAILED( "Signal was not masked in signal handler" ); } if ( called == 1 ) { /* Raise the signal again. It should be masked */ ret = raise( SIGNAL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to raise SIGXFSZ again" ); } /* check the signal is pending */ ret = sigpending( &pending ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to get pending signal set" ); } ret = sigismember( &pending, SIGNAL ); if ( ret != 1 ) { FAILED( "signal is not pending" ); } } called++; } /* main function */ int main() { int ret; struct sigaction sa; /* Initialize output */ output_init(); /* Set the signal handler */ sa.sa_flags = 0; sa.sa_handler = handler; ret = sigemptyset( &sa.sa_mask ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to empty signal set" ); } /* Install the signal handler for SIGXFSZ */ ret = sigaction( SIGNAL, &sa, 0 ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to set signal handler" ); } ret = raise( SIGNAL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to raise SIGXFSZ" ); } while ( called != 4 ) sched_yield(); /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/sigaction/17-6.c0100644000000000000000000000420010205365423022020 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test assertion #17 by verifying that select returns -1 with errno set to EINTR if a handler for the SIGFPE signal is setup with the SA_RESTART flag cleared. * 12/18/02 - Adding in include of sys/time.h per * rodrigc REMOVE-THIS AT attbi DOT com input that it needs * to be included whenever the timeval struct is used. */ #include #include #include #include #include #include #include #include #include #include "posixtest.h" volatile sig_atomic_t wakeup = 1; void handler(int signo) { printf("Caught SIGFPE\n"); wakeup++; } int main() { pid_t pid; struct timeval tv; if ((pid = fork()) == 0) { /* child */ struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); sigaction(SIGFPE, &act, 0); while(wakeup == 1) { tv.tv_sec = 3; tv.tv_usec = 0; if (select(0, NULL, NULL, NULL, &tv)== -1 && errno == EINTR) { perror("select"); return PTS_PASS; } } return PTS_FAIL; } else { /* parent */ int s; /* There is a race condition between the parent process sending the SIGFPE signal, and the child process being inside the 'select' function call. I could not find a pure POSIX method for determining the state of the child process, so I just added a delay so that the test is valid in most conditions. (The problem is that it would be perfectly legal for a POSIX conformant OS to not schedule the child process for a long time.) */ tv.tv_sec = 1; tv.tv_usec = 0; select(0, NULL, NULL, NULL, &tv); kill(pid, SIGFPE); waitpid(pid, &s, 0); if (WEXITSTATUS(s) == PTS_PASS) { printf("Test PASSED\n"); return PTS_PASS; } } printf("Test FAILED\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sigaction/6-20.c0100644000000000000000000000246507646610423022035 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #5 of the sigaction system call that verifies setting the SA_INFO bit in the signal mask for SIGPROF will result in sa_sigaction identifying the signal-catching function. */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include "posixtest.h" int handler_called = 0; void handler(int signo, siginfo_t *info, void *context) { handler_called = 1; } int main() { struct sigaction act; act.sa_sigaction = handler; act.sa_flags = SA_SIGINFO; sigemptyset(&act.sa_mask); sigaddset(&act.sa_mask, SIGSTOP); if (sigaction(SIGPROF, &act, 0) == -1) { printf("Unexpected error while attempting to setup test " "pre-conditions\n"); return PTS_UNRESOLVED; } if (raise(SIGPROF) == -1) { printf("Unexpected error while attempting to setup test " "pre-conditions\n"); return PTS_UNRESOLVED; } if (handler_called) { printf("Test PASSED\n"); return PTS_PASS; } printf("Test FAILED\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sigaction/4-14.c0100644000000000000000000000355607631716560022043 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #4 of the sigaction system call that shows that attempting to add SIGKILL can not be added to the signal mask for a signal handler. Steps: 1. Fork a new process 2. (parent) wait for child 3. (child) Setup a signal handler for SIGTSTP with SIGKILL added to the signal mask 4. (child) raise SIGTSTP 5. (child, signal handler) raise SIGKILL 5. (child) If still alive then exit -1 6. (parent - returning from wait) If child was killed then return success, otherwise fail. */ #include #include #include #include #include #include "posixtest.h" void handler(int signo) { raise(SIGKILL); exit(0); } int main() { if (fork() == 0) { /* child */ /* * NOTE: This block of code will return 0 for error * and anything else for success. */ struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); sigaddset(&act.sa_mask, SIGKILL); if (sigaction(SIGTSTP, &act, 0) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); return PTS_PASS; } if (raise(SIGTSTP) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); } return PTS_PASS; } else { int s; /* parent */ if (wait(&s) == -1) { perror("Unexpected error while setting up test " "pre-conditions"); return PTS_UNRESOLVED; } if (!WIFEXITED(s)) { printf("Test PASSED\n"); return PTS_PASS; } } printf("Test FAILED\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sigaction/22-23.c0100644000000000000000000000467407646610413022121 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #22 of the sigaction system call that verifies that if the SA_NODEFER flag is set for a given signal, then when the sa_sigaction signal-catching function is entered, then the signal that was caught is not added to the signal mask by raising that signal in the signal handler and verifying that the handler is reentered. Steps: 1. Fork a new process 2. (parent) wait for child 3. (child) Setup a signal handler for SIGURG with SA_NODEFER set in the sa_flags field 4. (child) raise SIGURG 5. (child, signal handler) increment handler count 6. (child, signal handler) if count is 1 then raise SIGURG 7. (child, signal handler) if count is 1 then set error variable 8. (child) if error is set then return -1, else return 0 6. (parent - returning from wait) If child returned 0 then exit 0, otherwise exit -1. */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include "posixtest.h" int handler_count = 0; void handler(int signo) { static int inside_handler = 0; printf("SIGURG caught\n"); if (inside_handler) { printf("Signal caught while inside handler\n"); exit(0); } inside_handler++; handler_count++; if (handler_count == 1) { printf("Raising SIGURG\n"); raise(SIGURG); printf("Returning from raising SIGURG\n"); } inside_handler--; } int main() { if (fork() == 0) { /* child */ struct sigaction act; act.sa_handler = handler; act.sa_flags = SA_NODEFER; sigemptyset(&act.sa_mask); if (sigaction(SIGURG, &act, 0) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); return PTS_UNRESOLVED; } if (raise(SIGURG) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); return PTS_UNRESOLVED; } return PTS_FAIL; } else { int s; /* parent */ if (wait(&s) == -1) { perror("Unexpected error while setting up test " "pre-conditions"); return PTS_UNRESOLVED; } if (!WEXITSTATUS(s)) { printf("Test PASSED\n"); return PTS_PASS; } } printf("Test FAILED\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sigaction/28-6.c0100644000000000000000000001407310206323212022022 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertions: * * If the signal action was set with the signal() function, getting it into oact then reinstalling it with act must be valid. * The steps are: * -> register a signal handler for SIGFPE with signal(). * -> check this signal handler works. * -> change the signal handler with sigaction, saving old handler in oact. * -> check the new signal handler works. * -> set the old signal handler back * -> check the old signal handler still works. * The test fails if a signal handler does not work as expected. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /******************************************************************************/ /*************************** standard includes ********************************/ /******************************************************************************/ #include #include #include #include #include #include #include /******************************************************************************/ /*************************** Test framework *******************************/ /******************************************************************************/ /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int * (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ #include "posixtest.h" #include #include #ifdef __GNUC__ /* We are using GCC */ #define UNRESOLVED(x, s) \ { output("Test %s unresolved: got %i (%s) on line %i (%s)\n", __FILE__, x, strerror(x), __LINE__, s); \ output_fini(); \ exit(PTS_UNRESOLVED); } #define FAILED(s) \ { output("Test %s FAILED: %s\n", __FILE__, s); \ output_fini(); \ exit(PTS_FAIL); } #define PASSED \ output_fini(); \ exit(PTS_PASS); #define UNTESTED(s) \ { output("File %s cannot test: %s\n", __FILE__, s); \ output_fini(); \ exit(PTS_UNTESTED); \ } #else /* not using GCC */ #define UNRESOLVED(x, s) \ { output("Test unresolved: got %i (%s) on line %i (%s)\n", x, strerror(x), __LINE__, s); \ output_fini(); \ exit(PTS_UNRESOLVED); } #define FAILED(s) \ { output("Test FAILED: %s\n", s); \ output_fini(); \ exit(PTS_FAIL); } #define PASSED \ output_fini(); \ exit(PTS_PASS); #define UNTESTED(s) \ { output("Unable to test: %s\n", s); \ output_fini(); \ exit(PTS_UNTESTED); \ } #endif void output_init() { /* do nothing */ return ; } void output( char * string, ... ) { va_list ap; #ifndef PLOT_OUTPUT char *ts = "[??:??:??]"; struct tm * now; time_t nw; #endif #ifndef PLOT_OUTPUT nw = time( NULL ); now = localtime( &nw ); if ( now == NULL ) printf( ts ); else printf( "[%2.2d:%2.2d:%2.2d]", now->tm_hour, now->tm_min, now->tm_sec ); #endif va_start( ap, string ); vprintf( string, ap ); va_end( ap ); } void output_fini() { /*do nothing */ return ; } /******************************************************************************/ /**************************** Configuration ***********************************/ /******************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif #define SIGNAL SIGFPE /******************************************************************************/ /*************************** Test case ***********************************/ /******************************************************************************/ sig_atomic_t called = 1; void handler_1( int sig ) { called++; } void handler_2( int sig ) { called--; } /* main function */ int main() { int ret; struct sigaction sa, save; /* Initialize output */ output_init(); /* Register the signal handler with signal */ if ( SIG_ERR == signal( SIGNAL, handler_1 ) ) { UNRESOLVED( errno, "Failed to register signal handler with signal()" ); } /* As whether signal handler is restored to default when executed is implementation defined, we cannot check it was registered here. */ /* Set the new signal handler with sigaction*/ sa.sa_flags = 0; sa.sa_handler = handler_2; ret = sigemptyset( &sa.sa_mask ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to empty signal set" ); } /* Install the signal handler for SIGFPE */ ret = sigaction( SIGNAL, &sa, &save ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to set signal handler" ); } /* Check the signal handler has been set up */ ret = raise( SIGNAL ); if ( ret != 0 ) { UNRESOLVED( ret , "Failed to raise the signal" ); } if ( called != 0 ) { FAILED( "handler not executed" ); } /* Restore the first signal handler */ ret = sigaction( SIGNAL, &save, 0 ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to set signal handler" ); } /* Check the signal handler has been set up */ ret = raise( SIGNAL ); if ( ret != 0 ) { UNRESOLVED( ret , "Failed to raise the signal" ); } if ( called != 1 ) { FAILED( "handler not executed" ); } /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/sigaction/8-14.c0100644000000000000000000000322107631716573022040 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #8 of the sigaction system call that verifies that if signals in the sa_mask (passed in the sigaction struct of the sigaction function call) are added to the process signal mask during execution of the signal-catching function. */ #include #include #include #include #include #include "posixtest.h" int SIGTERM_count = 0; void SIGTERM_handler(int signo) { SIGTERM_count++; printf("Caught SIGTERM\n"); } void SIGTSTP_handler(int signo) { printf("Caught SIGTSTP\n"); raise(SIGTERM); if (SIGTERM_count) { printf("Test FAILED\n"); exit(-1); } } int main() { struct sigaction act; act.sa_handler = SIGTSTP_handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); sigaddset(&act.sa_mask, SIGTERM); if (sigaction(SIGTSTP, &act, 0) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); return PTS_UNRESOLVED; } act.sa_handler = SIGTERM_handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); if (sigaction(SIGTERM, &act, 0) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); return PTS_UNRESOLVED; } if (raise(SIGTSTP) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/sigaction/6-9.c0100644000000000000000000000246207646610427021765 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #5 of the sigaction system call that verifies setting the SA_INFO bit in the signal mask for SIGINT will result in sa_sigaction identifying the signal-catching function. */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include "posixtest.h" int handler_called = 0; void handler(int signo, siginfo_t *info, void *context) { handler_called = 1; } int main() { struct sigaction act; act.sa_sigaction = handler; act.sa_flags = SA_SIGINFO; sigemptyset(&act.sa_mask); sigaddset(&act.sa_mask, SIGSTOP); if (sigaction(SIGINT, &act, 0) == -1) { printf("Unexpected error while attempting to setup test " "pre-conditions\n"); return PTS_UNRESOLVED; } if (raise(SIGINT) == -1) { printf("Unexpected error while attempting to setup test " "pre-conditions\n"); return PTS_UNRESOLVED; } if (handler_called) { printf("Test PASSED\n"); return PTS_PASS; } printf("Test FAILED\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sigaction/1-21.c0100644000000000000000000000270007631716435022025 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: Rusty.Lnch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #1 of the sigaction system call that shows sigaction (when used with a non-null act pointer) changes the action for a signal. Steps: 1. Initialize a global variable to indicate the signal handler has not been called. (A signal handler of the prototype "void func(int signo);" will set the global variable to indicate otherwise. 2. Use sigaction to setup a signal handler for SIGSYS 3. Raise SIGSYS. 4. Verify the global indicates the signal was called. */ #include #include #include "posixtest.h" int handler_called = 0; void handler(int signo) { handler_called = 1; } int main() { struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); if (sigaction(SIGSYS, &act, 0) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (raise(SIGSYS) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (handler_called) { printf("Test PASSED\n"); return PTS_PASS; } printf("Test FAILED\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sigaction/22-1.c0100644000000000000000000000470507646610412022027 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #22 of the sigaction system call that verifies that if the SA_NODEFER flag is set for a given signal, then when the sa_sigaction signal-catching function is entered, then the signal that was caught is not added to the signal mask by raising that signal in the signal handler and verifying that the handler is reentered. Steps: 1. Fork a new process 2. (parent) wait for child 3. (child) Setup a signal handler for SIGABRT with SA_NODEFER set in the sa_flags field 4. (child) raise SIGABRT 5. (child, signal handler) increment handler count 6. (child, signal handler) if count is 1 then raise SIGABRT 7. (child, signal handler) if count is 1 then set error variable 8. (child) if error is set then return -1, else return 0 6. (parent - returning from wait) If child returned 0 then exit 0, otherwise exit -1. */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include "posixtest.h" int handler_count = 0; void handler(int signo) { static int inside_handler = 0; printf("SIGABRT caught\n"); if (inside_handler) { printf("Signal caught while inside handler\n"); exit(0); } inside_handler++; handler_count++; if (handler_count == 1) { printf("Raising SIGABRT\n"); raise(SIGABRT); printf("Returning from raising SIGABRT\n"); } inside_handler--; } int main() { if (fork() == 0) { /* child */ struct sigaction act; act.sa_handler = handler; act.sa_flags = SA_NODEFER; sigemptyset(&act.sa_mask); if (sigaction(SIGABRT, &act, 0) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); return PTS_UNRESOLVED; } if (raise(SIGABRT) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); return PTS_UNRESOLVED; } return PTS_FAIL; } else { int s; /* parent */ if (wait(&s) == -1) { perror("Unexpected error while setting up test " "pre-conditions"); return PTS_UNRESOLVED; } if (!WEXITSTATUS(s)) { printf("Test PASSED\n"); return PTS_PASS; } } printf("Test FAILED\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sigaction/16-23.c0100644000000000000000000001260510205365423022106 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertions: * * If SA_RESTART is set in sa_flags, interruptible function interrupted by signal * shall restart silently. * The steps are: * -> create a child thread * -> child registers a handler for SIGURG with SA_RESTART, then waits for the semaphore * -> parent kills the child with SIGURG, then post the semaphore. * The test fails if the sem_wait function returns EINTR *Note: This test uses sem_wait to check if EINTR is returned. As the function is not required to fail with EINTR, the test may return PASS and the feature not be correct (false positive). Anyway, a false negative status cannot be returned. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /* This test tests for an XSI feature */ #define _XOPEN_SOURCE 600 /******************************************************************************/ /*************************** standard includes ********************************/ /******************************************************************************/ #include #include #include #include #include #include #include #include #include /******************************************************************************/ /*************************** Test framework *******************************/ /******************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int * (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /******************************************************************************/ /**************************** Configuration ***********************************/ /******************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif #define SIGNAL SIGURG /******************************************************************************/ /*************************** Test case ***********************************/ /******************************************************************************/ volatile sig_atomic_t caught = 0; sem_t sem; /* Handler function */ void handler( int signo ) { printf( "Caught signal %d\n", signo ); caught++; } /* Thread function */ void * threaded ( void * arg ) { int ret = 0; ret = sem_wait( &sem ); if ( ret != 0 ) { if ( errno == EINTR ) { FAILED( "The function returned EINTR while SA_RESTART is set" ); } else { UNRESOLVED( errno, "sem_wait failed" ); } } return NULL; } /* main function */ int main() { int ret; pthread_t child; struct sigaction sa; /* Initialize output */ output_init(); /* Set the signal handler */ sa.sa_flags = SA_RESTART; sa.sa_handler = handler; ret = sigemptyset( &sa.sa_mask ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to empty signal set" ); } /* Install the signal handler for SIGNAL */ ret = sigaction( SIGNAL, &sa, 0 ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to set signal handler" ); } /* Initialize the semaphore */ ret = sem_init( &sem, 0, 0 ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to init a semaphore" ); } /* Create the child thread */ ret = pthread_create( &child, NULL, threaded, NULL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to create a child thread" ); } /* Let the child thread enter the wait routine... we use sched_yield as there is no certain way to test that the child is waiting for the semaphore... */ sched_yield(); sched_yield(); sched_yield(); /* Ok, now kill the child */ ret = pthread_kill( child, SIGNAL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to kill the child thread" ); } /* wait that the child receives the signal */ while ( !caught ) sched_yield(); /* Now let the child run and terminate */ ret = sem_post( &sem ); if ( ret != 0 ) { UNRESOLVED( errno, "Failed to post the semaphore" ); } ret = pthread_join( child, NULL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to join the thread" ); } /* terminate */ ret = sem_destroy( &sem ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to destroy the semaphore" ); } /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/sigaction/13-9.c0100644000000000000000000000326707646610411022040 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #13 of the sigaction system call that verifies signal-catching functions are executed on the current stack if the SA_ONSTACK flag is cleared in the sigaction.sa_flags parameter to the sigaction function call. NOTE: This test case does not attempt to verify the proper operation of sigaltstack. */ #define _XOPEN_SOURCE 600 #include #include #include #include "posixtest.h" stack_t current; void handler(int signo) { stack_t oss; printf("Caught SIGINT\n"); if (sigaltstack((stack_t *)0, &oss) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); exit(-1); } if (oss.ss_sp != current.ss_sp || oss.ss_size != current.ss_size) { printf("Test FAILED\n"); exit(-1); } } int main() { struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); if (sigaction(SIGINT, &act, 0) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (sigaltstack((stack_t *)0, ¤t) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (raise(SIGINT) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/sigaction/4-77.c0100644000000000000000000000161007631716564022045 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #4 of the sigaction system call that shows that attempting to add SIGKILL to the signal mask of SIGXCPU will not result in sigaction returning -1 */ #include #include #include #include #include #include "posixtest.h" void handler(int signo) { } int main() { struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); sigaddset(&act.sa_mask, SIGKILL); if (sigaction(SIGXCPU, &act, 0) == -1) { printf("Test FAILED\n"); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/sigaction/18-3.c0100644000000000000000000000743410205365423022032 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertions: * * If SA_SIGINFO is not set in sa_flags, sa_handler is used as the signal * handling function. * The steps are: * -> register a handler for SIGBUS without SA_SIGINFO, and a known function * as saèhandler * -> raise SIGBUS, and check the function has been called. * The test fails if the function is not called */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /******************************************************************************/ /*************************** standard includes ********************************/ /******************************************************************************/ #include #include #include #include #include #include #include #include /******************************************************************************/ /*************************** Test framework *******************************/ /******************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int * (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /******************************************************************************/ /**************************** Configuration ***********************************/ /******************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif #define SIGNAL SIGBUS /******************************************************************************/ /*************************** Test case ***********************************/ /******************************************************************************/ int called = 0; void handler( int sig ) { called = 1; } /* main function */ int main() { int ret; struct sigaction sa; /* Initialize output */ output_init(); /* Set the signal handler */ sa.sa_flags = 0; sa.sa_handler = handler; ret = sigemptyset( &sa.sa_mask ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to empty signal set" ); } /* Install the signal handler for SIGBUS */ ret = sigaction( SIGNAL, &sa, 0 ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to set signal handler" ); } if ( called ) { FAILED( "The signal handler has been called when no signal was raised" ); } ret = raise( SIGNAL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to raise SIGBUS" ); } if ( !called ) { FAILED( "the sa_handler was not called whereas SA_SIGINFO was not set" ); } /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/sigaction/23-17.c0100644000000000000000000001036010205365424022104 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertions: * * If SA_NODEFER is not set in sa_flags, the caught signal is added to the * thread's signal mask during the handler execution. * The steps are: * -> register a signal handler for SIGUSR1 * -> raise SIGUSR1 * -> In handler, check for reentrance then raise SIGUSR1 again. * The test fails if signal handler if reentered or signal is not pending when raised again. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /******************************************************************************/ /*************************** standard includes ********************************/ /******************************************************************************/ #include #include #include #include #include #include #include #include /******************************************************************************/ /*************************** Test framework *******************************/ /******************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int * (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /******************************************************************************/ /**************************** Configuration ***********************************/ /******************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif #define SIGNAL SIGUSR1 /******************************************************************************/ /*************************** Test case ***********************************/ /******************************************************************************/ int called = 0; void handler( int sig ) { int ret; sigset_t pending; called++; if ( called == 2 ) { FAILED( "Signal was not masked in signal handler" ); } if ( called == 1 ) { /* Raise the signal again. It should be masked */ ret = raise( SIGNAL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to raise SIGUSR1 again" ); } /* check the signal is pending */ ret = sigpending( &pending ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to get pending signal set" ); } ret = sigismember( &pending, SIGNAL ); if ( ret != 1 ) { FAILED( "signal is not pending" ); } } called++; } /* main function */ int main() { int ret; struct sigaction sa; /* Initialize output */ output_init(); /* Set the signal handler */ sa.sa_flags = 0; sa.sa_handler = handler; ret = sigemptyset( &sa.sa_mask ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to empty signal set" ); } /* Install the signal handler for SIGUSR1 */ ret = sigaction( SIGNAL, &sa, 0 ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to set signal handler" ); } ret = raise( SIGNAL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to raise SIGUSR1" ); } while ( called != 4 ) sched_yield(); /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/sigaction/8-20.c0100644000000000000000000000322107631716573022035 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #8 of the sigaction system call that verifies that if signals in the sa_mask (passed in the sigaction struct of the sigaction function call) are added to the process signal mask during execution of the signal-catching function. */ #include #include #include #include #include #include "posixtest.h" int SIGPOLL_count = 0; void SIGPOLL_handler(int signo) { SIGPOLL_count++; printf("Caught SIGPOLL\n"); } void SIGPROF_handler(int signo) { printf("Caught SIGPROF\n"); raise(SIGPOLL); if (SIGPOLL_count) { printf("Test FAILED\n"); exit(-1); } } int main() { struct sigaction act; act.sa_handler = SIGPROF_handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); sigaddset(&act.sa_mask, SIGPOLL); if (sigaction(SIGPROF, &act, 0) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); return PTS_UNRESOLVED; } act.sa_handler = SIGPOLL_handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); if (sigaction(SIGPOLL, &act, 0) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); return PTS_UNRESOLVED; } if (raise(SIGPROF) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/sigaction/22-18.c0100644000000000000000000000470507646610411022116 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #22 of the sigaction system call that verifies that if the SA_NODEFER flag is set for a given signal, then when the sa_sigaction signal-catching function is entered, then the signal that was caught is not added to the signal mask by raising that signal in the signal handler and verifying that the handler is reentered. Steps: 1. Fork a new process 2. (parent) wait for child 3. (child) Setup a signal handler for SIGUSR2 with SA_NODEFER set in the sa_flags field 4. (child) raise SIGUSR2 5. (child, signal handler) increment handler count 6. (child, signal handler) if count is 1 then raise SIGUSR2 7. (child, signal handler) if count is 1 then set error variable 8. (child) if error is set then return -1, else return 0 6. (parent - returning from wait) If child returned 0 then exit 0, otherwise exit -1. */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include "posixtest.h" int handler_count = 0; void handler(int signo) { static int inside_handler = 0; printf("SIGUSR2 caught\n"); if (inside_handler) { printf("Signal caught while inside handler\n"); exit(0); } inside_handler++; handler_count++; if (handler_count == 1) { printf("Raising SIGUSR2\n"); raise(SIGUSR2); printf("Returning from raising SIGUSR2\n"); } inside_handler--; } int main() { if (fork() == 0) { /* child */ struct sigaction act; act.sa_handler = handler; act.sa_flags = SA_NODEFER; sigemptyset(&act.sa_mask); if (sigaction(SIGUSR2, &act, 0) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); return PTS_UNRESOLVED; } if (raise(SIGUSR2) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); return PTS_UNRESOLVED; } return PTS_FAIL; } else { int s; /* parent */ if (wait(&s) == -1) { perror("Unexpected error while setting up test " "pre-conditions"); return PTS_UNRESOLVED; } if (!WEXITSTATUS(s)) { printf("Test PASSED\n"); return PTS_PASS; } } printf("Test FAILED\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sigaction/16-7.c0100644000000000000000000001260510205365423022030 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertions: * * If SA_RESTART is set in sa_flags, interruptible function interrupted by signal * shall restart silently. * The steps are: * -> create a child thread * -> child registers a handler for SIGHUP with SA_RESTART, then waits for the semaphore * -> parent kills the child with SIGHUP, then post the semaphore. * The test fails if the sem_wait function returns EINTR *Note: This test uses sem_wait to check if EINTR is returned. As the function is not required to fail with EINTR, the test may return PASS and the feature not be correct (false positive). Anyway, a false negative status cannot be returned. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /* This test tests for an XSI feature */ #define _XOPEN_SOURCE 600 /******************************************************************************/ /*************************** standard includes ********************************/ /******************************************************************************/ #include #include #include #include #include #include #include #include #include /******************************************************************************/ /*************************** Test framework *******************************/ /******************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int * (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /******************************************************************************/ /**************************** Configuration ***********************************/ /******************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif #define SIGNAL SIGHUP /******************************************************************************/ /*************************** Test case ***********************************/ /******************************************************************************/ volatile sig_atomic_t caught = 0; sem_t sem; /* Handler function */ void handler( int signo ) { printf( "Caught signal %d\n", signo ); caught++; } /* Thread function */ void * threaded ( void * arg ) { int ret = 0; ret = sem_wait( &sem ); if ( ret != 0 ) { if ( errno == EINTR ) { FAILED( "The function returned EINTR while SA_RESTART is set" ); } else { UNRESOLVED( errno, "sem_wait failed" ); } } return NULL; } /* main function */ int main() { int ret; pthread_t child; struct sigaction sa; /* Initialize output */ output_init(); /* Set the signal handler */ sa.sa_flags = SA_RESTART; sa.sa_handler = handler; ret = sigemptyset( &sa.sa_mask ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to empty signal set" ); } /* Install the signal handler for SIGNAL */ ret = sigaction( SIGNAL, &sa, 0 ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to set signal handler" ); } /* Initialize the semaphore */ ret = sem_init( &sem, 0, 0 ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to init a semaphore" ); } /* Create the child thread */ ret = pthread_create( &child, NULL, threaded, NULL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to create a child thread" ); } /* Let the child thread enter the wait routine... we use sched_yield as there is no certain way to test that the child is waiting for the semaphore... */ sched_yield(); sched_yield(); sched_yield(); /* Ok, now kill the child */ ret = pthread_kill( child, SIGNAL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to kill the child thread" ); } /* wait that the child receives the signal */ while ( !caught ) sched_yield(); /* Now let the child run and terminate */ ret = sem_post( &sem ); if ( ret != 0 ) { UNRESOLVED( errno, "Failed to post the semaphore" ); } ret = pthread_join( child, NULL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to join the thread" ); } /* terminate */ ret = sem_destroy( &sem ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to destroy the semaphore" ); } /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/sigaction/4-71.c0100644000000000000000000000161007631716564022037 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #4 of the sigaction system call that shows that attempting to add SIGKILL to the signal mask of SIGPOLL will not result in sigaction returning -1 */ #include #include #include #include #include #include "posixtest.h" void handler(int signo) { } int main() { struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); sigaddset(&act.sa_mask, SIGKILL); if (sigaction(SIGPOLL, &act, 0) == -1) { printf("Test FAILED\n"); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/sigaction/2-26.c0100644000000000000000000000272007631716534022035 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #2 of the sigaction system call that shows sigaction (when used with a non-null oact pointer) changes the action for a signal. Steps: 1. Call sigaction to set handler for SIGXFSZ to use handler1 2. Call sigaction again to set handler for SIGXFSZ to use handler2, but this time use a non-null oarg and verify the sa_handler for oarg is set for handler1. */ #include #include #include "posixtest.h" int handler_called = 0; void handler1(int signo) { } void handler2(int signo) { } int main() { struct sigaction act; struct sigaction oact; act.sa_handler = handler1; act.sa_flags = 0; sigemptyset(&act.sa_mask); if (sigaction(SIGXFSZ, &act, 0) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } act.sa_handler = handler2; sigemptyset(&act.sa_mask); if (sigaction(SIGXFSZ, &act, &oact) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (oact.sa_handler == handler1) { printf("Test PASSED\n"); return PTS_PASS; } printf("Test Failed\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sigaction/6-7.c0100644000000000000000000000246207646610427021763 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #5 of the sigaction system call that verifies setting the SA_INFO bit in the signal mask for SIGHUP will result in sa_sigaction identifying the signal-catching function. */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include "posixtest.h" int handler_called = 0; void handler(int signo, siginfo_t *info, void *context) { handler_called = 1; } int main() { struct sigaction act; act.sa_sigaction = handler; act.sa_flags = SA_SIGINFO; sigemptyset(&act.sa_mask); sigaddset(&act.sa_mask, SIGSTOP); if (sigaction(SIGHUP, &act, 0) == -1) { printf("Unexpected error while attempting to setup test " "pre-conditions\n"); return PTS_UNRESOLVED; } if (raise(SIGHUP) == -1) { printf("Unexpected error while attempting to setup test " "pre-conditions\n"); return PTS_UNRESOLVED; } if (handler_called) { printf("Test PASSED\n"); return PTS_PASS; } printf("Test FAILED\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sigaction/4-78.c0100644000000000000000000000161007631716564022046 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #4 of the sigaction system call that shows that attempting to add SIGKILL to the signal mask of SIGXFSZ will not result in sigaction returning -1 */ #include #include #include #include #include #include "posixtest.h" void handler(int signo) { } int main() { struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); sigaddset(&act.sa_mask, SIGKILL); if (sigaction(SIGXFSZ, &act, 0) == -1) { printf("Test FAILED\n"); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/sigaction/4-25.c0100644000000000000000000000355607631716560022045 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #4 of the sigaction system call that shows that attempting to add SIGKILL can not be added to the signal mask for a signal handler. Steps: 1. Fork a new process 2. (parent) wait for child 3. (child) Setup a signal handler for SIGXCPU with SIGKILL added to the signal mask 4. (child) raise SIGXCPU 5. (child, signal handler) raise SIGKILL 5. (child) If still alive then exit -1 6. (parent - returning from wait) If child was killed then return success, otherwise fail. */ #include #include #include #include #include #include "posixtest.h" void handler(int signo) { raise(SIGKILL); exit(0); } int main() { if (fork() == 0) { /* child */ /* * NOTE: This block of code will return 0 for error * and anything else for success. */ struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); sigaddset(&act.sa_mask, SIGKILL); if (sigaction(SIGXCPU, &act, 0) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); return PTS_PASS; } if (raise(SIGXCPU) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); } return PTS_PASS; } else { int s; /* parent */ if (wait(&s) == -1) { perror("Unexpected error while setting up test " "pre-conditions"); return PTS_UNRESOLVED; } if (!WIFEXITED(s)) { printf("Test PASSED\n"); return PTS_PASS; } } printf("Test FAILED\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sigaction/6-4.c0100644000000000000000000000246507646610424021760 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #5 of the sigaction system call that verifies setting the SA_INFO bit in the signal mask for SIGCHLD will result in sa_sigaction identifying the signal-catching function. */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include "posixtest.h" int handler_called = 0; void handler(int signo, siginfo_t *info, void *context) { handler_called = 1; } int main() { struct sigaction act; act.sa_sigaction = handler; act.sa_flags = SA_SIGINFO; sigemptyset(&act.sa_mask); sigaddset(&act.sa_mask, SIGSTOP); if (sigaction(SIGCHLD, &act, 0) == -1) { printf("Unexpected error while attempting to setup test " "pre-conditions\n"); return PTS_UNRESOLVED; } if (raise(SIGCHLD) == -1) { printf("Unexpected error while attempting to setup test " "pre-conditions\n"); return PTS_UNRESOLVED; } if (handler_called) { printf("Test PASSED\n"); return PTS_PASS; } printf("Test FAILED\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sigaction/16-14.c0100644000000000000000000001261010205365423022102 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertions: * * If SA_RESTART is set in sa_flags, interruptible function interrupted by signal * shall restart silently. * The steps are: * -> create a child thread * -> child registers a handler for SIGTSTP with SA_RESTART, then waits for the semaphore * -> parent kills the child with SIGTSTP, then post the semaphore. * The test fails if the sem_wait function returns EINTR *Note: This test uses sem_wait to check if EINTR is returned. As the function is not required to fail with EINTR, the test may return PASS and the feature not be correct (false positive). Anyway, a false negative status cannot be returned. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /* This test tests for an XSI feature */ #define _XOPEN_SOURCE 600 /******************************************************************************/ /*************************** standard includes ********************************/ /******************************************************************************/ #include #include #include #include #include #include #include #include #include /******************************************************************************/ /*************************** Test framework *******************************/ /******************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int * (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /******************************************************************************/ /**************************** Configuration ***********************************/ /******************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif #define SIGNAL SIGTSTP /******************************************************************************/ /*************************** Test case ***********************************/ /******************************************************************************/ volatile sig_atomic_t caught = 0; sem_t sem; /* Handler function */ void handler( int signo ) { printf( "Caught signal %d\n", signo ); caught++; } /* Thread function */ void * threaded ( void * arg ) { int ret = 0; ret = sem_wait( &sem ); if ( ret != 0 ) { if ( errno == EINTR ) { FAILED( "The function returned EINTR while SA_RESTART is set" ); } else { UNRESOLVED( errno, "sem_wait failed" ); } } return NULL; } /* main function */ int main() { int ret; pthread_t child; struct sigaction sa; /* Initialize output */ output_init(); /* Set the signal handler */ sa.sa_flags = SA_RESTART; sa.sa_handler = handler; ret = sigemptyset( &sa.sa_mask ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to empty signal set" ); } /* Install the signal handler for SIGNAL */ ret = sigaction( SIGNAL, &sa, 0 ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to set signal handler" ); } /* Initialize the semaphore */ ret = sem_init( &sem, 0, 0 ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to init a semaphore" ); } /* Create the child thread */ ret = pthread_create( &child, NULL, threaded, NULL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to create a child thread" ); } /* Let the child thread enter the wait routine... we use sched_yield as there is no certain way to test that the child is waiting for the semaphore... */ sched_yield(); sched_yield(); sched_yield(); /* Ok, now kill the child */ ret = pthread_kill( child, SIGNAL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to kill the child thread" ); } /* wait that the child receives the signal */ while ( !caught ) sched_yield(); /* Now let the child run and terminate */ ret = sem_post( &sem ); if ( ret != 0 ) { UNRESOLVED( errno, "Failed to post the semaphore" ); } ret = pthread_join( child, NULL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to join the thread" ); } /* terminate */ ret = sem_destroy( &sem ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to destroy the semaphore" ); } /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/sigaction/4-49.c0100644000000000000000000000370107646625253022047 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #4 of the sigaction system call that shows that attempting to add SIGSTOP can not be added to the signal mask for a signal handler. Steps: 1. Fork a new process 2. (parent) wait for child 3. (child) Setup a signal handler for SIGURG with SIGSTOP added to the signal mask 4. (child) raise SIGURG 5. (child, signal handler) raise SIGSTOP 5. (child) If still around then return -1 6. (parent - returning from wait) If child was stopped then return kill the child and return success, otherwise fail. */ #include #include #include #include #include #include #include "posixtest.h" void handler(int signo) { printf("About to stop child\n"); raise(SIGSTOP); printf("Child has continued\n"); exit(0); } int main() { pid_t pid; if ((pid = fork()) == 0) { /* child */ struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); sigaddset(&act.sa_mask, SIGSTOP); if (sigaction(SIGURG, &act, 0) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); return PTS_UNRESOLVED; } if (raise(SIGURG) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); } return PTS_UNRESOLVED; } else { int s; /* parent */ if (waitpid(pid, &s, WUNTRACED) == -1) { perror("Unexpected error while setting up test " "pre-conditions"); return PTS_UNRESOLVED; } if (WIFSTOPPED(s)) { printf("Test PASSED\n"); kill(pid, SIGKILL); return PTS_PASS; } } printf("Test FAILED\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sigaction/25-21.c0100644000000000000000000000461107646610415022113 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #25 of the sigaction system call that verifies that when the sa_sigaction signal-catching function is entered, then the signal that was caught is added to the signal mask by raising that signal in the signal handler and verifying that the handler is not reentered. Steps: 1. Fork a new process 2. (parent) wait for child 3. (child) Setup a signal handler for SIGSYS 4. (child) raise SIGSYS 5. (child, signal handler) increment handler count 6. (child, signal handler) if count is 1 then raise SIGSYS 7. (child, signal handler) if count is 2 then set error variable 8. (child) if error is set then return -1, else return 0 6. (parent - returning from wait) If child returned 0 then exit 0, otherwise exit -1. */ #include #include #include #include #include #include "posixtest.h" int handler_count = 0; int handler_error = 0; void handler(int signo) { static int inside_handler = 0; printf("SIGSYS caught\n"); if (inside_handler) { printf("Signal caught while inside handler\n"); handler_error++; exit(-1); } inside_handler++; handler_count++; if (handler_count == 1) { printf("Raising SIGSYS\n"); raise(SIGSYS); printf("Returning from raising SIGSYS\n"); } inside_handler--; } int main() { if (fork() == 0) { /* child */ struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); if (sigaction(SIGSYS, &act, 0) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); return PTS_UNRESOLVED; } if (raise(SIGSYS) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); return PTS_UNRESOLVED; } if (handler_error) return PTS_UNRESOLVED; return PTS_PASS; } else { int s; /* parent */ if (wait(&s) == -1) { perror("Unexpected error while setting up test " "pre-conditions"); return PTS_UNRESOLVED; } if (!WEXITSTATUS(s)) { printf("Test PASSED\n"); return PTS_PASS; } } printf("Test FAILED\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sigaction/12-22.c0100644000000000000000000000372707646610403022114 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #12 of the sigaction system call that verifies signal-catching functions are executed on the alternate stack if the SA_ONSTACK flag is set in the sigaction.sa_flags parameter to the sigaction function call, and an alternate stack has been setup with sigaltstack(). NOTE: This test case does not attempt to verify the proper operation of sigaltstack. */ #define _XOPEN_SOURCE 600 #include #include #include #include "posixtest.h" stack_t alt_ss; void handler(int signo) { stack_t ss; printf("Caught SIGTRAP\n"); if (sigaltstack((stack_t *)0, &ss) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); exit(-1); } if (ss.ss_sp != alt_ss.ss_sp || ss.ss_size != alt_ss.ss_size) { printf("Test FAILED\n"); exit(-1); } } int main() { struct sigaction act; act.sa_handler = handler; act.sa_flags = SA_ONSTACK; sigemptyset(&act.sa_mask); if (sigaction(SIGTRAP, &act, 0) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if ((alt_ss.ss_sp = (void *)malloc(SIGSTKSZ)) == NULL) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } alt_ss.ss_size = SIGSTKSZ; alt_ss.ss_flags = 0; if (sigaltstack(&alt_ss, (stack_t *)0) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (raise(SIGTRAP) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/sigaction/16-12.c0100644000000000000000000001261010205365423022100 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertions: * * If SA_RESTART is set in sa_flags, interruptible function interrupted by signal * shall restart silently. * The steps are: * -> create a child thread * -> child registers a handler for SIGSEGV with SA_RESTART, then waits for the semaphore * -> parent kills the child with SIGSEGV, then post the semaphore. * The test fails if the sem_wait function returns EINTR *Note: This test uses sem_wait to check if EINTR is returned. As the function is not required to fail with EINTR, the test may return PASS and the feature not be correct (false positive). Anyway, a false negative status cannot be returned. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /* This test tests for an XSI feature */ #define _XOPEN_SOURCE 600 /******************************************************************************/ /*************************** standard includes ********************************/ /******************************************************************************/ #include #include #include #include #include #include #include #include #include /******************************************************************************/ /*************************** Test framework *******************************/ /******************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int * (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /******************************************************************************/ /**************************** Configuration ***********************************/ /******************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif #define SIGNAL SIGSEGV /******************************************************************************/ /*************************** Test case ***********************************/ /******************************************************************************/ volatile sig_atomic_t caught = 0; sem_t sem; /* Handler function */ void handler( int signo ) { printf( "Caught signal %d\n", signo ); caught++; } /* Thread function */ void * threaded ( void * arg ) { int ret = 0; ret = sem_wait( &sem ); if ( ret != 0 ) { if ( errno == EINTR ) { FAILED( "The function returned EINTR while SA_RESTART is set" ); } else { UNRESOLVED( errno, "sem_wait failed" ); } } return NULL; } /* main function */ int main() { int ret; pthread_t child; struct sigaction sa; /* Initialize output */ output_init(); /* Set the signal handler */ sa.sa_flags = SA_RESTART; sa.sa_handler = handler; ret = sigemptyset( &sa.sa_mask ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to empty signal set" ); } /* Install the signal handler for SIGNAL */ ret = sigaction( SIGNAL, &sa, 0 ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to set signal handler" ); } /* Initialize the semaphore */ ret = sem_init( &sem, 0, 0 ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to init a semaphore" ); } /* Create the child thread */ ret = pthread_create( &child, NULL, threaded, NULL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to create a child thread" ); } /* Let the child thread enter the wait routine... we use sched_yield as there is no certain way to test that the child is waiting for the semaphore... */ sched_yield(); sched_yield(); sched_yield(); /* Ok, now kill the child */ ret = pthread_kill( child, SIGNAL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to kill the child thread" ); } /* wait that the child receives the signal */ while ( !caught ) sched_yield(); /* Now let the child run and terminate */ ret = sem_post( &sem ); if ( ret != 0 ) { UNRESOLVED( errno, "Failed to post the semaphore" ); } ret = pthread_join( child, NULL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to join the thread" ); } /* terminate */ ret = sem_destroy( &sem ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to destroy the semaphore" ); } /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/sigaction/1-5.c0100644000000000000000000000270407631716440021747 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: Rusty.Lnch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #1 of the sigaction system call that shows sigaction (when used with a non-null act pointer) changes the action for a signal. Steps: 1. Initialize a global variable to indicate the signal handler has not been called. (A signal handler of the prototype "void func(int signo);" will set the global variable to indicate otherwise. 2. Use sigaction to setup a signal handler for SIGCONT 3. Raise SIGCONT. 4. Verify the global indicates the signal was called. */ #include #include #include "posixtest.h" int handler_called = 0; void handler(int signo) { handler_called = 1; } int main() { struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); if (sigaction(SIGCONT, &act, 0) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (raise(SIGCONT) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (handler_called) { printf("Test PASSED\n"); return PTS_PASS; } printf("Test FAILED\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sigaction/8-24.c0100644000000000000000000000322207631716573022042 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #8 of the sigaction system call that verifies that if signals in the sa_mask (passed in the sigaction struct of the sigaction function call) are added to the process signal mask during execution of the signal-catching function. */ #include #include #include #include #include #include "posixtest.h" int SIGURG_count = 0; void SIGURG_handler(int signo) { SIGURG_count++; printf("Caught SIGURG\n"); } void SIGVTALRM_handler(int signo) { printf("Caught SIGVTALRM\n"); raise(SIGURG); if (SIGURG_count) { printf("Test FAILED\n"); exit(-1); } } int main() { struct sigaction act; act.sa_handler = SIGVTALRM_handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); sigaddset(&act.sa_mask, SIGURG); if (sigaction(SIGVTALRM, &act, 0) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); return PTS_UNRESOLVED; } act.sa_handler = SIGURG_handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); if (sigaction(SIGURG, &act, 0) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); return PTS_UNRESOLVED; } if (raise(SIGVTALRM) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/sigaction/28-25.c0100644000000000000000000001407610206323212022106 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertions: * * If the signal action was set with the signal() function, getting it into oact then reinstalling it with act must be valid. * The steps are: * -> register a signal handler for SIGXCPU with signal(). * -> check this signal handler works. * -> change the signal handler with sigaction, saving old handler in oact. * -> check the new signal handler works. * -> set the old signal handler back * -> check the old signal handler still works. * The test fails if a signal handler does not work as expected. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /******************************************************************************/ /*************************** standard includes ********************************/ /******************************************************************************/ #include #include #include #include #include #include #include /******************************************************************************/ /*************************** Test framework *******************************/ /******************************************************************************/ /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int * (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ #include "posixtest.h" #include #include #ifdef __GNUC__ /* We are using GCC */ #define UNRESOLVED(x, s) \ { output("Test %s unresolved: got %i (%s) on line %i (%s)\n", __FILE__, x, strerror(x), __LINE__, s); \ output_fini(); \ exit(PTS_UNRESOLVED); } #define FAILED(s) \ { output("Test %s FAILED: %s\n", __FILE__, s); \ output_fini(); \ exit(PTS_FAIL); } #define PASSED \ output_fini(); \ exit(PTS_PASS); #define UNTESTED(s) \ { output("File %s cannot test: %s\n", __FILE__, s); \ output_fini(); \ exit(PTS_UNTESTED); \ } #else /* not using GCC */ #define UNRESOLVED(x, s) \ { output("Test unresolved: got %i (%s) on line %i (%s)\n", x, strerror(x), __LINE__, s); \ output_fini(); \ exit(PTS_UNRESOLVED); } #define FAILED(s) \ { output("Test FAILED: %s\n", s); \ output_fini(); \ exit(PTS_FAIL); } #define PASSED \ output_fini(); \ exit(PTS_PASS); #define UNTESTED(s) \ { output("Unable to test: %s\n", s); \ output_fini(); \ exit(PTS_UNTESTED); \ } #endif void output_init() { /* do nothing */ return ; } void output( char * string, ... ) { va_list ap; #ifndef PLOT_OUTPUT char *ts = "[??:??:??]"; struct tm * now; time_t nw; #endif #ifndef PLOT_OUTPUT nw = time( NULL ); now = localtime( &nw ); if ( now == NULL ) printf( ts ); else printf( "[%2.2d:%2.2d:%2.2d]", now->tm_hour, now->tm_min, now->tm_sec ); #endif va_start( ap, string ); vprintf( string, ap ); va_end( ap ); } void output_fini() { /*do nothing */ return ; } /******************************************************************************/ /**************************** Configuration ***********************************/ /******************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif #define SIGNAL SIGXCPU /******************************************************************************/ /*************************** Test case ***********************************/ /******************************************************************************/ sig_atomic_t called = 1; void handler_1( int sig ) { called++; } void handler_2( int sig ) { called--; } /* main function */ int main() { int ret; struct sigaction sa, save; /* Initialize output */ output_init(); /* Register the signal handler with signal */ if ( SIG_ERR == signal( SIGNAL, handler_1 ) ) { UNRESOLVED( errno, "Failed to register signal handler with signal()" ); } /* As whether signal handler is restored to default when executed is implementation defined, we cannot check it was registered here. */ /* Set the new signal handler with sigaction*/ sa.sa_flags = 0; sa.sa_handler = handler_2; ret = sigemptyset( &sa.sa_mask ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to empty signal set" ); } /* Install the signal handler for SIGXCPU */ ret = sigaction( SIGNAL, &sa, &save ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to set signal handler" ); } /* Check the signal handler has been set up */ ret = raise( SIGNAL ); if ( ret != 0 ) { UNRESOLVED( ret , "Failed to raise the signal" ); } if ( called != 0 ) { FAILED( "handler not executed" ); } /* Restore the first signal handler */ ret = sigaction( SIGNAL, &save, 0 ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to set signal handler" ); } /* Check the signal handler has been set up */ ret = raise( SIGNAL ); if ( ret != 0 ) { UNRESOLVED( ret , "Failed to raise the signal" ); } if ( called != 1 ) { FAILED( "handler not executed" ); } /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/sigaction/12-51.c0100644000000000000000000000335507650040164022107 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #12 of the sigaction system call that verifies signal-catching functions are executed on the current stack if the SA_ONSTACK flag is set in the sigaction.sa_flags parameter to the sigaction function call, but a new stack has not be set by sigaltstack(). NOTE: This test case does not attempt to verify the proper operation of sigaltstack. */ #define _XOPEN_SOURCE 600 #include #include #include #include "posixtest.h" stack_t current; void handler(int signo) { stack_t oss; printf("Caught SIGXCPU\n"); if (sigaltstack((stack_t *)0, &oss) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); exit(-1); } if (oss.ss_sp != current.ss_sp || oss.ss_size != current.ss_size) { printf("Test FAILED\n"); exit(-1); } } int main() { struct sigaction act; act.sa_handler = handler; act.sa_flags = SA_ONSTACK; sigemptyset(&act.sa_mask); if (sigaction(SIGXCPU, &act, 0) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (sigaltstack((stack_t *)0, ¤t) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (raise(SIGXCPU) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/sigaction/19-14.c0100644000000000000000000001017610205365423022112 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertions: * * If SA_SIGINFO is set in sa_flags and Real Time Signals extension is supported, * sa_sigaction is used as the signal handling function. * The steps are: * -> test for RTS extension * -> register a handler for SIGTSTP with SA_SIGINFO, and a known function * as sa_sigaction * -> raise SIGTSTP, and check the function has been called. * The test fails if the function is not called */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /******************************************************************************/ /*************************** standard includes ********************************/ /******************************************************************************/ #include #include #include #include #include #include #include #include /******************************************************************************/ /*************************** Test framework *******************************/ /******************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int * (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /******************************************************************************/ /**************************** Configuration ***********************************/ /******************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif #define SIGNAL SIGTSTP /******************************************************************************/ /*************************** Test case ***********************************/ /******************************************************************************/ int called = 0; void handler( int sig, siginfo_t *info, void *context ) { if ( info->si_signo != SIGNAL ) { FAILED( "Wrong signal generated?" ); } called = 1; } /* main function */ int main() { int ret; long rts; struct sigaction sa; /* Initialize output */ output_init(); /* Test the RTS extension */ rts = sysconf( _SC_REALTIME_SIGNALS ); if ( rts < 0L ) { UNTESTED( "This test needs the RTS extension" ); } /* Set the signal handler */ sa.sa_flags = SA_SIGINFO; sa.sa_sigaction = handler; ret = sigemptyset( &sa.sa_mask ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to empty signal set" ); } /* Install the signal handler for SIGTSTP */ ret = sigaction( SIGNAL, &sa, 0 ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to set signal handler" ); } if ( called ) { FAILED( "The signal handler has been called when no signal was raised" ); } ret = raise( SIGNAL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to raise SIGTSTP" ); } if ( !called ) { FAILED( "the sa_handler was not called whereas SA_SIGINFO was not set" ); } /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/sigaction/18-24.c0100644000000000000000000000745310205365423022116 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertions: * * If SA_SIGINFO is not set in sa_flags, sa_handler is used as the signal * handling function. * The steps are: * -> register a handler for SIGVTALRM without SA_SIGINFO, and a known function * as saèhandler * -> raise SIGVTALRM, and check the function has been called. * The test fails if the function is not called */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /******************************************************************************/ /*************************** standard includes ********************************/ /******************************************************************************/ #include #include #include #include #include #include #include #include /******************************************************************************/ /*************************** Test framework *******************************/ /******************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int * (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /******************************************************************************/ /**************************** Configuration ***********************************/ /******************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif #define SIGNAL SIGVTALRM /******************************************************************************/ /*************************** Test case ***********************************/ /******************************************************************************/ int called = 0; void handler( int sig ) { called = 1; } /* main function */ int main() { int ret; struct sigaction sa; /* Initialize output */ output_init(); /* Set the signal handler */ sa.sa_flags = 0; sa.sa_handler = handler; ret = sigemptyset( &sa.sa_mask ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to empty signal set" ); } /* Install the signal handler for SIGVTALRM */ ret = sigaction( SIGNAL, &sa, 0 ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to set signal handler" ); } if ( called ) { FAILED( "The signal handler has been called when no signal was raised" ); } ret = raise( SIGNAL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to raise SIGVTALRM" ); } if ( !called ) { FAILED( "the sa_handler was not called whereas SA_SIGINFO was not set" ); } /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/sigaction/16-22.c0100644000000000000000000001261010205365423022101 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertions: * * If SA_RESTART is set in sa_flags, interruptible function interrupted by signal * shall restart silently. * The steps are: * -> create a child thread * -> child registers a handler for SIGTRAP with SA_RESTART, then waits for the semaphore * -> parent kills the child with SIGTRAP, then post the semaphore. * The test fails if the sem_wait function returns EINTR *Note: This test uses sem_wait to check if EINTR is returned. As the function is not required to fail with EINTR, the test may return PASS and the feature not be correct (false positive). Anyway, a false negative status cannot be returned. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /* This test tests for an XSI feature */ #define _XOPEN_SOURCE 600 /******************************************************************************/ /*************************** standard includes ********************************/ /******************************************************************************/ #include #include #include #include #include #include #include #include #include /******************************************************************************/ /*************************** Test framework *******************************/ /******************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int * (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /******************************************************************************/ /**************************** Configuration ***********************************/ /******************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif #define SIGNAL SIGTRAP /******************************************************************************/ /*************************** Test case ***********************************/ /******************************************************************************/ volatile sig_atomic_t caught = 0; sem_t sem; /* Handler function */ void handler( int signo ) { printf( "Caught signal %d\n", signo ); caught++; } /* Thread function */ void * threaded ( void * arg ) { int ret = 0; ret = sem_wait( &sem ); if ( ret != 0 ) { if ( errno == EINTR ) { FAILED( "The function returned EINTR while SA_RESTART is set" ); } else { UNRESOLVED( errno, "sem_wait failed" ); } } return NULL; } /* main function */ int main() { int ret; pthread_t child; struct sigaction sa; /* Initialize output */ output_init(); /* Set the signal handler */ sa.sa_flags = SA_RESTART; sa.sa_handler = handler; ret = sigemptyset( &sa.sa_mask ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to empty signal set" ); } /* Install the signal handler for SIGNAL */ ret = sigaction( SIGNAL, &sa, 0 ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to set signal handler" ); } /* Initialize the semaphore */ ret = sem_init( &sem, 0, 0 ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to init a semaphore" ); } /* Create the child thread */ ret = pthread_create( &child, NULL, threaded, NULL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to create a child thread" ); } /* Let the child thread enter the wait routine... we use sched_yield as there is no certain way to test that the child is waiting for the semaphore... */ sched_yield(); sched_yield(); sched_yield(); /* Ok, now kill the child */ ret = pthread_kill( child, SIGNAL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to kill the child thread" ); } /* wait that the child receives the signal */ while ( !caught ) sched_yield(); /* Now let the child run and terminate */ ret = sem_post( &sem ); if ( ret != 0 ) { UNRESOLVED( errno, "Failed to post the semaphore" ); } ret = pthread_join( child, NULL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to join the thread" ); } /* terminate */ ret = sem_destroy( &sem ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to destroy the semaphore" ); } /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/sigaction/28-7.c0100644000000000000000000001407310206323212022023 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertions: * * If the signal action was set with the signal() function, getting it into oact then reinstalling it with act must be valid. * The steps are: * -> register a signal handler for SIGHUP with signal(). * -> check this signal handler works. * -> change the signal handler with sigaction, saving old handler in oact. * -> check the new signal handler works. * -> set the old signal handler back * -> check the old signal handler still works. * The test fails if a signal handler does not work as expected. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /******************************************************************************/ /*************************** standard includes ********************************/ /******************************************************************************/ #include #include #include #include #include #include #include /******************************************************************************/ /*************************** Test framework *******************************/ /******************************************************************************/ /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int * (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ #include "posixtest.h" #include #include #ifdef __GNUC__ /* We are using GCC */ #define UNRESOLVED(x, s) \ { output("Test %s unresolved: got %i (%s) on line %i (%s)\n", __FILE__, x, strerror(x), __LINE__, s); \ output_fini(); \ exit(PTS_UNRESOLVED); } #define FAILED(s) \ { output("Test %s FAILED: %s\n", __FILE__, s); \ output_fini(); \ exit(PTS_FAIL); } #define PASSED \ output_fini(); \ exit(PTS_PASS); #define UNTESTED(s) \ { output("File %s cannot test: %s\n", __FILE__, s); \ output_fini(); \ exit(PTS_UNTESTED); \ } #else /* not using GCC */ #define UNRESOLVED(x, s) \ { output("Test unresolved: got %i (%s) on line %i (%s)\n", x, strerror(x), __LINE__, s); \ output_fini(); \ exit(PTS_UNRESOLVED); } #define FAILED(s) \ { output("Test FAILED: %s\n", s); \ output_fini(); \ exit(PTS_FAIL); } #define PASSED \ output_fini(); \ exit(PTS_PASS); #define UNTESTED(s) \ { output("Unable to test: %s\n", s); \ output_fini(); \ exit(PTS_UNTESTED); \ } #endif void output_init() { /* do nothing */ return ; } void output( char * string, ... ) { va_list ap; #ifndef PLOT_OUTPUT char *ts = "[??:??:??]"; struct tm * now; time_t nw; #endif #ifndef PLOT_OUTPUT nw = time( NULL ); now = localtime( &nw ); if ( now == NULL ) printf( ts ); else printf( "[%2.2d:%2.2d:%2.2d]", now->tm_hour, now->tm_min, now->tm_sec ); #endif va_start( ap, string ); vprintf( string, ap ); va_end( ap ); } void output_fini() { /*do nothing */ return ; } /******************************************************************************/ /**************************** Configuration ***********************************/ /******************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif #define SIGNAL SIGHUP /******************************************************************************/ /*************************** Test case ***********************************/ /******************************************************************************/ sig_atomic_t called = 1; void handler_1( int sig ) { called++; } void handler_2( int sig ) { called--; } /* main function */ int main() { int ret; struct sigaction sa, save; /* Initialize output */ output_init(); /* Register the signal handler with signal */ if ( SIG_ERR == signal( SIGNAL, handler_1 ) ) { UNRESOLVED( errno, "Failed to register signal handler with signal()" ); } /* As whether signal handler is restored to default when executed is implementation defined, we cannot check it was registered here. */ /* Set the new signal handler with sigaction*/ sa.sa_flags = 0; sa.sa_handler = handler_2; ret = sigemptyset( &sa.sa_mask ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to empty signal set" ); } /* Install the signal handler for SIGHUP */ ret = sigaction( SIGNAL, &sa, &save ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to set signal handler" ); } /* Check the signal handler has been set up */ ret = raise( SIGNAL ); if ( ret != 0 ) { UNRESOLVED( ret , "Failed to raise the signal" ); } if ( called != 0 ) { FAILED( "handler not executed" ); } /* Restore the first signal handler */ ret = sigaction( SIGNAL, &save, 0 ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to set signal handler" ); } /* Check the signal handler has been set up */ ret = raise( SIGNAL ); if ( ret != 0 ) { UNRESOLVED( ret , "Failed to raise the signal" ); } if ( called != 1 ) { FAILED( "handler not executed" ); } /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/sigaction/4-6.c0100644000000000000000000000355207631716563021763 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #4 of the sigaction system call that shows that attempting to add SIGKILL can not be added to the signal mask for a signal handler. Steps: 1. Fork a new process 2. (parent) wait for child 3. (child) Setup a signal handler for SIGFPE with SIGKILL added to the signal mask 4. (child) raise SIGFPE 5. (child, signal handler) raise SIGKILL 5. (child) If still alive then exit -1 6. (parent - returning from wait) If child was killed then return success, otherwise fail. */ #include #include #include #include #include #include "posixtest.h" void handler(int signo) { raise(SIGKILL); exit(0); } int main() { if (fork() == 0) { /* child */ /* * NOTE: This block of code will return 0 for error * and anything else for success. */ struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); sigaddset(&act.sa_mask, SIGKILL); if (sigaction(SIGFPE, &act, 0) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); return PTS_PASS; } if (raise(SIGFPE) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); } return PTS_PASS; } else { int s; /* parent */ if (wait(&s) == -1) { perror("Unexpected error while setting up test " "pre-conditions"); return PTS_UNRESOLVED; } if (!WIFEXITED(s)) { printf("Test PASSED\n"); return PTS_PASS; } } printf("Test FAILED\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sigaction/23-23.c0100644000000000000000000001035110205365424022101 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertions: * * If SA_NODEFER is not set in sa_flags, the caught signal is added to the * thread's signal mask during the handler execution. * The steps are: * -> register a signal handler for SIGURG * -> raise SIGURG * -> In handler, check for reentrance then raise SIGURG again. * The test fails if signal handler if reentered or signal is not pending when raised again. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /******************************************************************************/ /*************************** standard includes ********************************/ /******************************************************************************/ #include #include #include #include #include #include #include #include /******************************************************************************/ /*************************** Test framework *******************************/ /******************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int * (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /******************************************************************************/ /**************************** Configuration ***********************************/ /******************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif #define SIGNAL SIGURG /******************************************************************************/ /*************************** Test case ***********************************/ /******************************************************************************/ int called = 0; void handler( int sig ) { int ret; sigset_t pending; called++; if ( called == 2 ) { FAILED( "Signal was not masked in signal handler" ); } if ( called == 1 ) { /* Raise the signal again. It should be masked */ ret = raise( SIGNAL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to raise SIGURG again" ); } /* check the signal is pending */ ret = sigpending( &pending ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to get pending signal set" ); } ret = sigismember( &pending, SIGNAL ); if ( ret != 1 ) { FAILED( "signal is not pending" ); } } called++; } /* main function */ int main() { int ret; struct sigaction sa; /* Initialize output */ output_init(); /* Set the signal handler */ sa.sa_flags = 0; sa.sa_handler = handler; ret = sigemptyset( &sa.sa_mask ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to empty signal set" ); } /* Install the signal handler for SIGURG */ ret = sigaction( SIGNAL, &sa, 0 ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to set signal handler" ); } ret = raise( SIGNAL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to raise SIGURG" ); } while ( called != 4 ) sched_yield(); /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/sigaction/13-15.c0100644000000000000000000000327207646610406022115 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #13 of the sigaction system call that verifies signal-catching functions are executed on the current stack if the SA_ONSTACK flag is cleared in the sigaction.sa_flags parameter to the sigaction function call. NOTE: This test case does not attempt to verify the proper operation of sigaltstack. */ #define _XOPEN_SOURCE 600 #include #include #include #include "posixtest.h" stack_t current; void handler(int signo) { stack_t oss; printf("Caught SIGTTIN\n"); if (sigaltstack((stack_t *)0, &oss) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); exit(-1); } if (oss.ss_sp != current.ss_sp || oss.ss_size != current.ss_size) { printf("Test FAILED\n"); exit(-1); } } int main() { struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); if (sigaction(SIGTTIN, &act, 0) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (sigaltstack((stack_t *)0, ¤t) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (raise(SIGTTIN) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/sigaction/18-1.c0100644000000000000000000000744110205365423022026 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertions: * * If SA_SIGINFO is not set in sa_flags, sa_handler is used as the signal * handling function. * The steps are: * -> register a handler for SIGABRT without SA_SIGINFO, and a known function * as saèhandler * -> raise SIGABRT, and check the function has been called. * The test fails if the function is not called */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /******************************************************************************/ /*************************** standard includes ********************************/ /******************************************************************************/ #include #include #include #include #include #include #include #include /******************************************************************************/ /*************************** Test framework *******************************/ /******************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int * (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /******************************************************************************/ /**************************** Configuration ***********************************/ /******************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif #define SIGNAL SIGABRT /******************************************************************************/ /*************************** Test case ***********************************/ /******************************************************************************/ int called = 0; void handler( int sig ) { called = 1; } /* main function */ int main() { int ret; struct sigaction sa; /* Initialize output */ output_init(); /* Set the signal handler */ sa.sa_flags = 0; sa.sa_handler = handler; ret = sigemptyset( &sa.sa_mask ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to empty signal set" ); } /* Install the signal handler for SIGABRT */ ret = sigaction( SIGNAL, &sa, 0 ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to set signal handler" ); } if ( called ) { FAILED( "The signal handler has been called when no signal was raised" ); } ret = raise( SIGNAL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to raise SIGABRT" ); } if ( !called ) { FAILED( "the sa_handler was not called whereas SA_SIGINFO was not set" ); } /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/sigaction/4-75.c0100644000000000000000000000160607631716564022050 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #4 of the sigaction system call that shows that attempting to add SIGKILL to the signal mask of SIGURG will not result in sigaction returning -1 */ #include #include #include #include #include #include "posixtest.h" void handler(int signo) { } int main() { struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); sigaddset(&act.sa_mask, SIGKILL); if (sigaction(SIGURG, &act, 0) == -1) { printf("Test FAILED\n"); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/sigaction/3-14.c0100644000000000000000000000276507631716555022047 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #3 of the sigaction system call that shows calling sigaction with a null act argument does not change the signal handler. Steps: 1. Initialize global variable to indicate handler has not been called 2. Set the signal handler for SIGTSTP to handler 3. Call sigaction with a null act 4. raise SIGTSTP 5. Verify handler was called. */ #include #include #include "posixtest.h" int handler_called = 0; void handler(int signo) { handler_called = 1; } int main() { struct sigaction act; struct sigaction oact; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); if (sigaction(SIGTSTP, &act, 0) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (sigaction(SIGTSTP, 0, &oact) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (raise(SIGTSTP) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (handler_called) { printf("Test PASSED\n"); return PTS_PASS; } printf("Test FAILED\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sigaction/13-2.c0100644000000000000000000000327207646610411022025 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #13 of the sigaction system call that verifies signal-catching functions are executed on the current stack if the SA_ONSTACK flag is cleared in the sigaction.sa_flags parameter to the sigaction function call. NOTE: This test case does not attempt to verify the proper operation of sigaltstack. */ #define _XOPEN_SOURCE 600 #include #include #include #include "posixtest.h" stack_t current; void handler(int signo) { stack_t oss; printf("Caught SIGALRM\n"); if (sigaltstack((stack_t *)0, &oss) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); exit(-1); } if (oss.ss_sp != current.ss_sp || oss.ss_size != current.ss_size) { printf("Test FAILED\n"); exit(-1); } } int main() { struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); if (sigaction(SIGALRM, &act, 0) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (sigaltstack((stack_t *)0, ¤t) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (raise(SIGALRM) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/sigaction/12-26.c0100644000000000000000000000372707646610403022120 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #12 of the sigaction system call that verifies signal-catching functions are executed on the alternate stack if the SA_ONSTACK flag is set in the sigaction.sa_flags parameter to the sigaction function call, and an alternate stack has been setup with sigaltstack(). NOTE: This test case does not attempt to verify the proper operation of sigaltstack. */ #define _XOPEN_SOURCE 600 #include #include #include #include "posixtest.h" stack_t alt_ss; void handler(int signo) { stack_t ss; printf("Caught SIGXFSZ\n"); if (sigaltstack((stack_t *)0, &ss) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); exit(-1); } if (ss.ss_sp != alt_ss.ss_sp || ss.ss_size != alt_ss.ss_size) { printf("Test FAILED\n"); exit(-1); } } int main() { struct sigaction act; act.sa_handler = handler; act.sa_flags = SA_ONSTACK; sigemptyset(&act.sa_mask); if (sigaction(SIGXFSZ, &act, 0) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if ((alt_ss.ss_sp = (void *)malloc(SIGSTKSZ)) == NULL) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } alt_ss.ss_size = SIGSTKSZ; alt_ss.ss_flags = 0; if (sigaltstack(&alt_ss, (stack_t *)0) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (raise(SIGXFSZ) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/sigaction/4-76.c0100644000000000000000000000161407631716564022050 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #4 of the sigaction system call that shows that attempting to add SIGKILL to the signal mask of SIGVTALRM will not result in sigaction returning -1 */ #include #include #include #include #include #include "posixtest.h" void handler(int signo) { } int main() { struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); sigaddset(&act.sa_mask, SIGKILL); if (sigaction(SIGVTALRM, &act, 0) == -1) { printf("Test FAILED\n"); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/sigaction/25-20.c0100644000000000000000000000462207646610414022113 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #25 of the sigaction system call that verifies that when the sa_sigaction signal-catching function is entered, then the signal that was caught is added to the signal mask by raising that signal in the signal handler and verifying that the handler is not reentered. Steps: 1. Fork a new process 2. (parent) wait for child 3. (child) Setup a signal handler for SIGPROF 4. (child) raise SIGPROF 5. (child, signal handler) increment handler count 6. (child, signal handler) if count is 1 then raise SIGPROF 7. (child, signal handler) if count is 2 then set error variable 8. (child) if error is set then return -1, else return 0 6. (parent - returning from wait) If child returned 0 then exit 0, otherwise exit -1. */ #include #include #include #include #include #include "posixtest.h" int handler_count = 0; int handler_error = 0; void handler(int signo) { static int inside_handler = 0; printf("SIGPROF caught\n"); if (inside_handler) { printf("Signal caught while inside handler\n"); handler_error++; exit(-1); } inside_handler++; handler_count++; if (handler_count == 1) { printf("Raising SIGPROF\n"); raise(SIGPROF); printf("Returning from raising SIGPROF\n"); } inside_handler--; } int main() { if (fork() == 0) { /* child */ struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); if (sigaction(SIGPROF, &act, 0) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); return PTS_UNRESOLVED; } if (raise(SIGPROF) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); return PTS_UNRESOLVED; } if (handler_error) return PTS_UNRESOLVED; return PTS_PASS; } else { int s; /* parent */ if (wait(&s) == -1) { perror("Unexpected error while setting up test " "pre-conditions"); return PTS_UNRESOLVED; } if (!WEXITSTATUS(s)) { printf("Test PASSED\n"); return PTS_PASS; } } printf("Test FAILED\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sigaction/12-37.c0100644000000000000000000000335507650040046022112 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #12 of the sigaction system call that verifies signal-catching functions are executed on the current stack if the SA_ONSTACK flag is set in the sigaction.sa_flags parameter to the sigaction function call, but a new stack has not be set by sigaltstack(). NOTE: This test case does not attempt to verify the proper operation of sigaltstack. */ #define _XOPEN_SOURCE 600 #include #include #include #include "posixtest.h" stack_t current; void handler(int signo) { stack_t oss; printf("Caught SIGQUIT\n"); if (sigaltstack((stack_t *)0, &oss) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); exit(-1); } if (oss.ss_sp != current.ss_sp || oss.ss_size != current.ss_size) { printf("Test FAILED\n"); exit(-1); } } int main() { struct sigaction act; act.sa_handler = handler; act.sa_flags = SA_ONSTACK; sigemptyset(&act.sa_mask); if (sigaction(SIGQUIT, &act, 0) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (sigaltstack((stack_t *)0, ¤t) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (raise(SIGQUIT) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/sigaction/18-23.c0100644000000000000000000000743410205365423022114 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertions: * * If SA_SIGINFO is not set in sa_flags, sa_handler is used as the signal * handling function. * The steps are: * -> register a handler for SIGURG without SA_SIGINFO, and a known function * as saèhandler * -> raise SIGURG, and check the function has been called. * The test fails if the function is not called */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /******************************************************************************/ /*************************** standard includes ********************************/ /******************************************************************************/ #include #include #include #include #include #include #include #include /******************************************************************************/ /*************************** Test framework *******************************/ /******************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int * (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /******************************************************************************/ /**************************** Configuration ***********************************/ /******************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif #define SIGNAL SIGURG /******************************************************************************/ /*************************** Test case ***********************************/ /******************************************************************************/ int called = 0; void handler( int sig ) { called = 1; } /* main function */ int main() { int ret; struct sigaction sa; /* Initialize output */ output_init(); /* Set the signal handler */ sa.sa_flags = 0; sa.sa_handler = handler; ret = sigemptyset( &sa.sa_mask ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to empty signal set" ); } /* Install the signal handler for SIGURG */ ret = sigaction( SIGNAL, &sa, 0 ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to set signal handler" ); } if ( called ) { FAILED( "The signal handler has been called when no signal was raised" ); } ret = raise( SIGNAL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to raise SIGURG" ); } if ( !called ) { FAILED( "the sa_handler was not called whereas SA_SIGINFO was not set" ); } /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/sigaction/1-3.c0100644000000000000000000000270007631716440021741 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: Rusty.Lnch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #1 of the sigaction system call that shows sigaction (when used with a non-null act pointer) changes the action for a signal. Steps: 1. Initialize a global variable to indicate the signal handler has not been called. (A signal handler of the prototype "void func(int signo);" will set the global variable to indicate otherwise. 2. Use sigaction to setup a signal handler for SIGBUS 3. Raise SIGBUS. 4. Verify the global indicates the signal was called. */ #include #include #include "posixtest.h" int handler_called = 0; void handler(int signo) { handler_called = 1; } int main() { struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); if (sigaction(SIGBUS, &act, 0) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (raise(SIGBUS) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (handler_called) { printf("Test PASSED\n"); return PTS_PASS; } printf("Test FAILED\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sigaction/3-9.c0100644000000000000000000000276007631716557021770 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #3 of the sigaction system call that shows calling sigaction with a null act argument does not change the signal handler. Steps: 1. Initialize global variable to indicate handler has not been called 2. Set the signal handler for SIGINT to handler 3. Call sigaction with a null act 4. raise SIGINT 5. Verify handler was called. */ #include #include #include "posixtest.h" int handler_called = 0; void handler(int signo) { handler_called = 1; } int main() { struct sigaction act; struct sigaction oact; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); if (sigaction(SIGINT, &act, 0) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (sigaction(SIGINT, 0, &oact) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (raise(SIGINT) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (handler_called) { printf("Test PASSED\n"); return PTS_PASS; } printf("Test FAILED\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sigaction/22-15.c0100644000000000000000000000470507646610411022113 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #22 of the sigaction system call that verifies that if the SA_NODEFER flag is set for a given signal, then when the sa_sigaction signal-catching function is entered, then the signal that was caught is not added to the signal mask by raising that signal in the signal handler and verifying that the handler is reentered. Steps: 1. Fork a new process 2. (parent) wait for child 3. (child) Setup a signal handler for SIGTTIN with SA_NODEFER set in the sa_flags field 4. (child) raise SIGTTIN 5. (child, signal handler) increment handler count 6. (child, signal handler) if count is 1 then raise SIGTTIN 7. (child, signal handler) if count is 1 then set error variable 8. (child) if error is set then return -1, else return 0 6. (parent - returning from wait) If child returned 0 then exit 0, otherwise exit -1. */ #define _XOPEN_SOURCE 600 #include #include #include #include #include #include "posixtest.h" int handler_count = 0; void handler(int signo) { static int inside_handler = 0; printf("SIGTTIN caught\n"); if (inside_handler) { printf("Signal caught while inside handler\n"); exit(0); } inside_handler++; handler_count++; if (handler_count == 1) { printf("Raising SIGTTIN\n"); raise(SIGTTIN); printf("Returning from raising SIGTTIN\n"); } inside_handler--; } int main() { if (fork() == 0) { /* child */ struct sigaction act; act.sa_handler = handler; act.sa_flags = SA_NODEFER; sigemptyset(&act.sa_mask); if (sigaction(SIGTTIN, &act, 0) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); return PTS_UNRESOLVED; } if (raise(SIGTTIN) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); return PTS_UNRESOLVED; } return PTS_FAIL; } else { int s; /* parent */ if (wait(&s) == -1) { perror("Unexpected error while setting up test " "pre-conditions"); return PTS_UNRESOLVED; } if (!WEXITSTATUS(s)) { printf("Test PASSED\n"); return PTS_PASS; } } printf("Test FAILED\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sigaction/28-17.c0100644000000000000000000001407610206323210022105 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertions: * * If the signal action was set with the signal() function, getting it into oact then reinstalling it with act must be valid. * The steps are: * -> register a signal handler for SIGUSR1 with signal(). * -> check this signal handler works. * -> change the signal handler with sigaction, saving old handler in oact. * -> check the new signal handler works. * -> set the old signal handler back * -> check the old signal handler still works. * The test fails if a signal handler does not work as expected. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /******************************************************************************/ /*************************** standard includes ********************************/ /******************************************************************************/ #include #include #include #include #include #include #include /******************************************************************************/ /*************************** Test framework *******************************/ /******************************************************************************/ /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int * (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ #include "posixtest.h" #include #include #ifdef __GNUC__ /* We are using GCC */ #define UNRESOLVED(x, s) \ { output("Test %s unresolved: got %i (%s) on line %i (%s)\n", __FILE__, x, strerror(x), __LINE__, s); \ output_fini(); \ exit(PTS_UNRESOLVED); } #define FAILED(s) \ { output("Test %s FAILED: %s\n", __FILE__, s); \ output_fini(); \ exit(PTS_FAIL); } #define PASSED \ output_fini(); \ exit(PTS_PASS); #define UNTESTED(s) \ { output("File %s cannot test: %s\n", __FILE__, s); \ output_fini(); \ exit(PTS_UNTESTED); \ } #else /* not using GCC */ #define UNRESOLVED(x, s) \ { output("Test unresolved: got %i (%s) on line %i (%s)\n", x, strerror(x), __LINE__, s); \ output_fini(); \ exit(PTS_UNRESOLVED); } #define FAILED(s) \ { output("Test FAILED: %s\n", s); \ output_fini(); \ exit(PTS_FAIL); } #define PASSED \ output_fini(); \ exit(PTS_PASS); #define UNTESTED(s) \ { output("Unable to test: %s\n", s); \ output_fini(); \ exit(PTS_UNTESTED); \ } #endif void output_init() { /* do nothing */ return ; } void output( char * string, ... ) { va_list ap; #ifndef PLOT_OUTPUT char *ts = "[??:??:??]"; struct tm * now; time_t nw; #endif #ifndef PLOT_OUTPUT nw = time( NULL ); now = localtime( &nw ); if ( now == NULL ) printf( ts ); else printf( "[%2.2d:%2.2d:%2.2d]", now->tm_hour, now->tm_min, now->tm_sec ); #endif va_start( ap, string ); vprintf( string, ap ); va_end( ap ); } void output_fini() { /*do nothing */ return ; } /******************************************************************************/ /**************************** Configuration ***********************************/ /******************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif #define SIGNAL SIGUSR1 /******************************************************************************/ /*************************** Test case ***********************************/ /******************************************************************************/ sig_atomic_t called = 1; void handler_1( int sig ) { called++; } void handler_2( int sig ) { called--; } /* main function */ int main() { int ret; struct sigaction sa, save; /* Initialize output */ output_init(); /* Register the signal handler with signal */ if ( SIG_ERR == signal( SIGNAL, handler_1 ) ) { UNRESOLVED( errno, "Failed to register signal handler with signal()" ); } /* As whether signal handler is restored to default when executed is implementation defined, we cannot check it was registered here. */ /* Set the new signal handler with sigaction*/ sa.sa_flags = 0; sa.sa_handler = handler_2; ret = sigemptyset( &sa.sa_mask ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to empty signal set" ); } /* Install the signal handler for SIGUSR1 */ ret = sigaction( SIGNAL, &sa, &save ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to set signal handler" ); } /* Check the signal handler has been set up */ ret = raise( SIGNAL ); if ( ret != 0 ) { UNRESOLVED( ret , "Failed to raise the signal" ); } if ( called != 0 ) { FAILED( "handler not executed" ); } /* Restore the first signal handler */ ret = sigaction( SIGNAL, &save, 0 ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to set signal handler" ); } /* Check the signal handler has been set up */ ret = raise( SIGNAL ); if ( ret != 0 ) { UNRESOLVED( ret , "Failed to raise the signal" ); } if ( called != 1 ) { FAILED( "handler not executed" ); } /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/sigaction/16-24.c0100644000000000000000000001261610205365423022111 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertions: * * If SA_RESTART is set in sa_flags, interruptible function interrupted by signal * shall restart silently. * The steps are: * -> create a child thread * -> child registers a handler for SIGVTALRM with SA_RESTART, then waits for the semaphore * -> parent kills the child with SIGVTALRM, then post the semaphore. * The test fails if the sem_wait function returns EINTR *Note: This test uses sem_wait to check if EINTR is returned. As the function is not required to fail with EINTR, the test may return PASS and the feature not be correct (false positive). Anyway, a false negative status cannot be returned. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /* This test tests for an XSI feature */ #define _XOPEN_SOURCE 600 /******************************************************************************/ /*************************** standard includes ********************************/ /******************************************************************************/ #include #include #include #include #include #include #include #include #include /******************************************************************************/ /*************************** Test framework *******************************/ /******************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int * (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /******************************************************************************/ /**************************** Configuration ***********************************/ /******************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif #define SIGNAL SIGVTALRM /******************************************************************************/ /*************************** Test case ***********************************/ /******************************************************************************/ volatile sig_atomic_t caught = 0; sem_t sem; /* Handler function */ void handler( int signo ) { printf( "Caught signal %d\n", signo ); caught++; } /* Thread function */ void * threaded ( void * arg ) { int ret = 0; ret = sem_wait( &sem ); if ( ret != 0 ) { if ( errno == EINTR ) { FAILED( "The function returned EINTR while SA_RESTART is set" ); } else { UNRESOLVED( errno, "sem_wait failed" ); } } return NULL; } /* main function */ int main() { int ret; pthread_t child; struct sigaction sa; /* Initialize output */ output_init(); /* Set the signal handler */ sa.sa_flags = SA_RESTART; sa.sa_handler = handler; ret = sigemptyset( &sa.sa_mask ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to empty signal set" ); } /* Install the signal handler for SIGNAL */ ret = sigaction( SIGNAL, &sa, 0 ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to set signal handler" ); } /* Initialize the semaphore */ ret = sem_init( &sem, 0, 0 ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to init a semaphore" ); } /* Create the child thread */ ret = pthread_create( &child, NULL, threaded, NULL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to create a child thread" ); } /* Let the child thread enter the wait routine... we use sched_yield as there is no certain way to test that the child is waiting for the semaphore... */ sched_yield(); sched_yield(); sched_yield(); /* Ok, now kill the child */ ret = pthread_kill( child, SIGNAL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to kill the child thread" ); } /* wait that the child receives the signal */ while ( !caught ) sched_yield(); /* Now let the child run and terminate */ ret = sem_post( &sem ); if ( ret != 0 ) { UNRESOLVED( errno, "Failed to post the semaphore" ); } ret = pthread_join( child, NULL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to join the thread" ); } /* terminate */ ret = sem_destroy( &sem ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to destroy the semaphore" ); } /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/sigaction/17-26.c0100644000000000000000000000420510205365423022107 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test assertion #17 by verifying that select returns -1 with errno set to EINTR if a handler for the SIGXFSZ signal is setup with the SA_RESTART flag cleared. * 12/18/02 - Adding in include of sys/time.h per * rodrigc REMOVE-THIS AT attbi DOT com input that it needs * to be included whenever the timeval struct is used. */ #include #include #include #include #include #include #include #include #include #include "posixtest.h" volatile sig_atomic_t wakeup = 1; void handler(int signo) { printf("Caught SIGXFSZ\n"); wakeup++; } int main() { pid_t pid; struct timeval tv; if ((pid = fork()) == 0) { /* child */ struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); sigaction(SIGXFSZ, &act, 0); while(wakeup == 1) { tv.tv_sec = 3; tv.tv_usec = 0; if (select(0, NULL, NULL, NULL, &tv)== -1 && errno == EINTR) { perror("select"); return PTS_PASS; } } return PTS_FAIL; } else { /* parent */ int s; /* There is a race condition between the parent process sending the SIGXFSZ signal, and the child process being inside the 'select' function call. I could not find a pure POSIX method for determining the state of the child process, so I just added a delay so that the test is valid in most conditions. (The problem is that it would be perfectly legal for a POSIX conformant OS to not schedule the child process for a long time.) */ tv.tv_sec = 1; tv.tv_usec = 0; select(0, NULL, NULL, NULL, &tv); kill(pid, SIGXFSZ); waitpid(pid, &s, 0); if (WEXITSTATUS(s) == PTS_PASS) { printf("Test PASSED\n"); return PTS_PASS; } } printf("Test FAILED\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sigaction/23-3.c0100644000000000000000000001035110205365424022017 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertions: * * If SA_NODEFER is not set in sa_flags, the caught signal is added to the * thread's signal mask during the handler execution. * The steps are: * -> register a signal handler for SIGBUS * -> raise SIGBUS * -> In handler, check for reentrance then raise SIGBUS again. * The test fails if signal handler if reentered or signal is not pending when raised again. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /******************************************************************************/ /*************************** standard includes ********************************/ /******************************************************************************/ #include #include #include #include #include #include #include #include /******************************************************************************/ /*************************** Test framework *******************************/ /******************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int * (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /******************************************************************************/ /**************************** Configuration ***********************************/ /******************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif #define SIGNAL SIGBUS /******************************************************************************/ /*************************** Test case ***********************************/ /******************************************************************************/ int called = 0; void handler( int sig ) { int ret; sigset_t pending; called++; if ( called == 2 ) { FAILED( "Signal was not masked in signal handler" ); } if ( called == 1 ) { /* Raise the signal again. It should be masked */ ret = raise( SIGNAL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to raise SIGBUS again" ); } /* check the signal is pending */ ret = sigpending( &pending ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to get pending signal set" ); } ret = sigismember( &pending, SIGNAL ); if ( ret != 1 ) { FAILED( "signal is not pending" ); } } called++; } /* main function */ int main() { int ret; struct sigaction sa; /* Initialize output */ output_init(); /* Set the signal handler */ sa.sa_flags = 0; sa.sa_handler = handler; ret = sigemptyset( &sa.sa_mask ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to empty signal set" ); } /* Install the signal handler for SIGBUS */ ret = sigaction( SIGNAL, &sa, 0 ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to set signal handler" ); } ret = raise( SIGNAL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to raise SIGBUS" ); } while ( called != 4 ) sched_yield(); /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/sigaction/25-26.c0100644000000000000000000000462207646610417022124 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #25 of the sigaction system call that verifies that when the sa_sigaction signal-catching function is entered, then the signal that was caught is added to the signal mask by raising that signal in the signal handler and verifying that the handler is not reentered. Steps: 1. Fork a new process 2. (parent) wait for child 3. (child) Setup a signal handler for SIGXFSZ 4. (child) raise SIGXFSZ 5. (child, signal handler) increment handler count 6. (child, signal handler) if count is 1 then raise SIGXFSZ 7. (child, signal handler) if count is 2 then set error variable 8. (child) if error is set then return -1, else return 0 6. (parent - returning from wait) If child returned 0 then exit 0, otherwise exit -1. */ #include #include #include #include #include #include "posixtest.h" int handler_count = 0; int handler_error = 0; void handler(int signo) { static int inside_handler = 0; printf("SIGXFSZ caught\n"); if (inside_handler) { printf("Signal caught while inside handler\n"); handler_error++; exit(-1); } inside_handler++; handler_count++; if (handler_count == 1) { printf("Raising SIGXFSZ\n"); raise(SIGXFSZ); printf("Returning from raising SIGXFSZ\n"); } inside_handler--; } int main() { if (fork() == 0) { /* child */ struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); if (sigaction(SIGXFSZ, &act, 0) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); return PTS_UNRESOLVED; } if (raise(SIGXFSZ) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); return PTS_UNRESOLVED; } if (handler_error) return PTS_UNRESOLVED; return PTS_PASS; } else { int s; /* parent */ if (wait(&s) == -1) { perror("Unexpected error while setting up test " "pre-conditions"); return PTS_UNRESOLVED; } if (!WEXITSTATUS(s)) { printf("Test PASSED\n"); return PTS_PASS; } } printf("Test FAILED\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sigaction/4-86.c0100644000000000000000000000160607631716565022053 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #4 of the sigaction system call that shows that attempting to add SIGSTOP to the signal mask of SIGILL will not result in sigaction returning -1 */ #include #include #include #include #include #include "posixtest.h" void handler(int signo) { } int main() { struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); sigaddset(&act.sa_mask, SIGSTOP); if (sigaction(SIGILL, &act, 0) == -1) { printf("Test FAILED\n"); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/sigaction/4-73.c0100644000000000000000000000160607631716564022046 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #4 of the sigaction system call that shows that attempting to add SIGKILL to the signal mask of SIGSYS will not result in sigaction returning -1 */ #include #include #include #include #include #include "posixtest.h" void handler(int signo) { } int main() { struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); sigaddset(&act.sa_mask, SIGKILL); if (sigaction(SIGSYS, &act, 0) == -1) { printf("Test FAILED\n"); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/sigaction/4-12.c0100644000000000000000000000355607631716560022041 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #4 of the sigaction system call that shows that attempting to add SIGKILL can not be added to the signal mask for a signal handler. Steps: 1. Fork a new process 2. (parent) wait for child 3. (child) Setup a signal handler for SIGSEGV with SIGKILL added to the signal mask 4. (child) raise SIGSEGV 5. (child, signal handler) raise SIGKILL 5. (child) If still alive then exit -1 6. (parent - returning from wait) If child was killed then return success, otherwise fail. */ #include #include #include #include #include #include "posixtest.h" void handler(int signo) { raise(SIGKILL); exit(0); } int main() { if (fork() == 0) { /* child */ /* * NOTE: This block of code will return 0 for error * and anything else for success. */ struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); sigaddset(&act.sa_mask, SIGKILL); if (sigaction(SIGSEGV, &act, 0) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); return PTS_PASS; } if (raise(SIGSEGV) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); } return PTS_PASS; } else { int s; /* parent */ if (wait(&s) == -1) { perror("Unexpected error while setting up test " "pre-conditions"); return PTS_UNRESOLVED; } if (!WIFEXITED(s)) { printf("Test PASSED\n"); return PTS_PASS; } } printf("Test FAILED\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sigaction/17-21.c0100644000000000000000000000420010205365423022075 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test assertion #17 by verifying that select returns -1 with errno set to EINTR if a handler for the SIGSYS signal is setup with the SA_RESTART flag cleared. * 12/18/02 - Adding in include of sys/time.h per * rodrigc REMOVE-THIS AT attbi DOT com input that it needs * to be included whenever the timeval struct is used. */ #include #include #include #include #include #include #include #include #include #include "posixtest.h" volatile sig_atomic_t wakeup = 1; void handler(int signo) { printf("Caught SIGSYS\n"); wakeup++; } int main() { pid_t pid; struct timeval tv; if ((pid = fork()) == 0) { /* child */ struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); sigaction(SIGSYS, &act, 0); while(wakeup == 1) { tv.tv_sec = 3; tv.tv_usec = 0; if (select(0, NULL, NULL, NULL, &tv)== -1 && errno == EINTR) { perror("select"); return PTS_PASS; } } return PTS_FAIL; } else { /* parent */ int s; /* There is a race condition between the parent process sending the SIGSYS signal, and the child process being inside the 'select' function call. I could not find a pure POSIX method for determining the state of the child process, so I just added a delay so that the test is valid in most conditions. (The problem is that it would be perfectly legal for a POSIX conformant OS to not schedule the child process for a long time.) */ tv.tv_sec = 1; tv.tv_usec = 0; select(0, NULL, NULL, NULL, &tv); kill(pid, SIGSYS); waitpid(pid, &s, 0); if (WEXITSTATUS(s) == PTS_PASS) { printf("Test PASSED\n"); return PTS_PASS; } } printf("Test FAILED\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sigaction/4-27.c0100644000000000000000000000370507646624377022055 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #4 of the sigaction system call that shows that attempting to add SIGSTOP can not be added to the signal mask for a signal handler. Steps: 1. Fork a new process 2. (parent) wait for child 3. (child) Setup a signal handler for SIGABRT with SIGSTOP added to the signal mask 4. (child) raise SIGABRT 5. (child, signal handler) raise SIGSTOP 5. (child) If still around then return -1 6. (parent - returning from wait) If child was stopped then return kill the child and return success, otherwise fail. */ #include #include #include #include #include #include #include "posixtest.h" void handler(int signo) { printf("About to stop child\n"); raise(SIGSTOP); printf("Child has continued\n"); exit(0); } int main() { pid_t pid; if ((pid = fork()) == 0) { /* child */ struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); sigaddset(&act.sa_mask, SIGSTOP); if (sigaction(SIGABRT, &act, 0) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); return PTS_UNRESOLVED; } if (raise(SIGABRT) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); } return PTS_UNRESOLVED; } else { int s; /* parent */ if (waitpid(pid, &s, WUNTRACED) == -1) { perror("Unexpected error while setting up test " "pre-conditions"); return PTS_UNRESOLVED; } if (WIFSTOPPED(s)) { printf("Test PASSED\n"); kill(pid, SIGKILL); return PTS_PASS; } } printf("Test FAILED\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sigaction/25-12.c0100644000000000000000000000462207646610414022114 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #25 of the sigaction system call that verifies that when the sa_sigaction signal-catching function is entered, then the signal that was caught is added to the signal mask by raising that signal in the signal handler and verifying that the handler is not reentered. Steps: 1. Fork a new process 2. (parent) wait for child 3. (child) Setup a signal handler for SIGSEGV 4. (child) raise SIGSEGV 5. (child, signal handler) increment handler count 6. (child, signal handler) if count is 1 then raise SIGSEGV 7. (child, signal handler) if count is 2 then set error variable 8. (child) if error is set then return -1, else return 0 6. (parent - returning from wait) If child returned 0 then exit 0, otherwise exit -1. */ #include #include #include #include #include #include "posixtest.h" int handler_count = 0; int handler_error = 0; void handler(int signo) { static int inside_handler = 0; printf("SIGSEGV caught\n"); if (inside_handler) { printf("Signal caught while inside handler\n"); handler_error++; exit(-1); } inside_handler++; handler_count++; if (handler_count == 1) { printf("Raising SIGSEGV\n"); raise(SIGSEGV); printf("Returning from raising SIGSEGV\n"); } inside_handler--; } int main() { if (fork() == 0) { /* child */ struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); if (sigaction(SIGSEGV, &act, 0) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); return PTS_UNRESOLVED; } if (raise(SIGSEGV) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); return PTS_UNRESOLVED; } if (handler_error) return PTS_UNRESOLVED; return PTS_PASS; } else { int s; /* parent */ if (wait(&s) == -1) { perror("Unexpected error while setting up test " "pre-conditions"); return PTS_UNRESOLVED; } if (!WEXITSTATUS(s)) { printf("Test PASSED\n"); return PTS_PASS; } } printf("Test FAILED\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sigaction/4-38.c0100644000000000000000000000370507646625016022046 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #4 of the sigaction system call that shows that attempting to add SIGSTOP can not be added to the signal mask for a signal handler. Steps: 1. Fork a new process 2. (parent) wait for child 3. (child) Setup a signal handler for SIGSEGV with SIGSTOP added to the signal mask 4. (child) raise SIGSEGV 5. (child, signal handler) raise SIGSTOP 5. (child) If still around then return -1 6. (parent - returning from wait) If child was stopped then return kill the child and return success, otherwise fail. */ #include #include #include #include #include #include #include "posixtest.h" void handler(int signo) { printf("About to stop child\n"); raise(SIGSTOP); printf("Child has continued\n"); exit(0); } int main() { pid_t pid; if ((pid = fork()) == 0) { /* child */ struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); sigaddset(&act.sa_mask, SIGSTOP); if (sigaction(SIGSEGV, &act, 0) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); return PTS_UNRESOLVED; } if (raise(SIGSEGV) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); } return PTS_UNRESOLVED; } else { int s; /* parent */ if (waitpid(pid, &s, WUNTRACED) == -1) { perror("Unexpected error while setting up test " "pre-conditions"); return PTS_UNRESOLVED; } if (WIFSTOPPED(s)) { printf("Test PASSED\n"); kill(pid, SIGKILL); return PTS_PASS; } } printf("Test FAILED\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sigaction/12-27.c0100644000000000000000000000335507650040236022112 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #12 of the sigaction system call that verifies signal-catching functions are executed on the current stack if the SA_ONSTACK flag is set in the sigaction.sa_flags parameter to the sigaction function call, but a new stack has not be set by sigaltstack(). NOTE: This test case does not attempt to verify the proper operation of sigaltstack. */ #define _XOPEN_SOURCE 600 #include #include #include #include "posixtest.h" stack_t current; void handler(int signo) { stack_t oss; printf("Caught SIGABRT\n"); if (sigaltstack((stack_t *)0, &oss) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); exit(-1); } if (oss.ss_sp != current.ss_sp || oss.ss_size != current.ss_size) { printf("Test FAILED\n"); exit(-1); } } int main() { struct sigaction act; act.sa_handler = handler; act.sa_flags = SA_ONSTACK; sigemptyset(&act.sa_mask); if (sigaction(SIGABRT, &act, 0) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (sigaltstack((stack_t *)0, ¤t) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (raise(SIGABRT) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/sigaction/25-15.c0100644000000000000000000000462207646610414022117 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #25 of the sigaction system call that verifies that when the sa_sigaction signal-catching function is entered, then the signal that was caught is added to the signal mask by raising that signal in the signal handler and verifying that the handler is not reentered. Steps: 1. Fork a new process 2. (parent) wait for child 3. (child) Setup a signal handler for SIGTTIN 4. (child) raise SIGTTIN 5. (child, signal handler) increment handler count 6. (child, signal handler) if count is 1 then raise SIGTTIN 7. (child, signal handler) if count is 2 then set error variable 8. (child) if error is set then return -1, else return 0 6. (parent - returning from wait) If child returned 0 then exit 0, otherwise exit -1. */ #include #include #include #include #include #include "posixtest.h" int handler_count = 0; int handler_error = 0; void handler(int signo) { static int inside_handler = 0; printf("SIGTTIN caught\n"); if (inside_handler) { printf("Signal caught while inside handler\n"); handler_error++; exit(-1); } inside_handler++; handler_count++; if (handler_count == 1) { printf("Raising SIGTTIN\n"); raise(SIGTTIN); printf("Returning from raising SIGTTIN\n"); } inside_handler--; } int main() { if (fork() == 0) { /* child */ struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); if (sigaction(SIGTTIN, &act, 0) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); return PTS_UNRESOLVED; } if (raise(SIGTTIN) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); return PTS_UNRESOLVED; } if (handler_error) return PTS_UNRESOLVED; return PTS_PASS; } else { int s; /* parent */ if (wait(&s) == -1) { perror("Unexpected error while setting up test " "pre-conditions"); return PTS_UNRESOLVED; } if (!WEXITSTATUS(s)) { printf("Test PASSED\n"); return PTS_PASS; } } printf("Test FAILED\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sigaction/12-42.c0100644000000000000000000000335507650040125022104 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #12 of the sigaction system call that verifies signal-catching functions are executed on the current stack if the SA_ONSTACK flag is set in the sigaction.sa_flags parameter to the sigaction function call, but a new stack has not be set by sigaltstack(). NOTE: This test case does not attempt to verify the proper operation of sigaltstack. */ #define _XOPEN_SOURCE 600 #include #include #include #include "posixtest.h" stack_t current; void handler(int signo) { stack_t oss; printf("Caught SIGTTOU\n"); if (sigaltstack((stack_t *)0, &oss) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); exit(-1); } if (oss.ss_sp != current.ss_sp || oss.ss_size != current.ss_size) { printf("Test FAILED\n"); exit(-1); } } int main() { struct sigaction act; act.sa_handler = handler; act.sa_flags = SA_ONSTACK; sigemptyset(&act.sa_mask); if (sigaction(SIGTTOU, &act, 0) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (sigaltstack((stack_t *)0, ¤t) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (raise(SIGTTOU) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/sigaction/2-10.c0100644000000000000000000000272007631716532022024 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #2 of the sigaction system call that shows sigaction (when used with a non-null oact pointer) changes the action for a signal. Steps: 1. Call sigaction to set handler for SIGPIPE to use handler1 2. Call sigaction again to set handler for SIGPIPE to use handler2, but this time use a non-null oarg and verify the sa_handler for oarg is set for handler1. */ #include #include #include "posixtest.h" int handler_called = 0; void handler1(int signo) { } void handler2(int signo) { } int main() { struct sigaction act; struct sigaction oact; act.sa_handler = handler1; act.sa_flags = 0; sigemptyset(&act.sa_mask); if (sigaction(SIGPIPE, &act, 0) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } act.sa_handler = handler2; sigemptyset(&act.sa_mask); if (sigaction(SIGPIPE, &act, &oact) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (oact.sa_handler == handler1) { printf("Test PASSED\n"); return PTS_PASS; } printf("Test Failed\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sigaction/17-15.c0100644000000000000000000000420510205365423022105 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test assertion #17 by verifying that select returns -1 with errno set to EINTR if a handler for the SIGTTIN signal is setup with the SA_RESTART flag cleared. * 12/18/02 - Adding in include of sys/time.h per * rodrigc REMOVE-THIS AT attbi DOT com input that it needs * to be included whenever the timeval struct is used. */ #include #include #include #include #include #include #include #include #include #include "posixtest.h" volatile sig_atomic_t wakeup = 1; void handler(int signo) { printf("Caught SIGTTIN\n"); wakeup++; } int main() { pid_t pid; struct timeval tv; if ((pid = fork()) == 0) { /* child */ struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); sigaction(SIGTTIN, &act, 0); while(wakeup == 1) { tv.tv_sec = 3; tv.tv_usec = 0; if (select(0, NULL, NULL, NULL, &tv)== -1 && errno == EINTR) { perror("select"); return PTS_PASS; } } return PTS_FAIL; } else { /* parent */ int s; /* There is a race condition between the parent process sending the SIGTTIN signal, and the child process being inside the 'select' function call. I could not find a pure POSIX method for determining the state of the child process, so I just added a delay so that the test is valid in most conditions. (The problem is that it would be perfectly legal for a POSIX conformant OS to not schedule the child process for a long time.) */ tv.tv_sec = 1; tv.tv_usec = 0; select(0, NULL, NULL, NULL, &tv); kill(pid, SIGTTIN); waitpid(pid, &s, 0); if (WEXITSTATUS(s) == PTS_PASS) { printf("Test PASSED\n"); return PTS_PASS; } } printf("Test FAILED\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sigaction/12-1.c0100644000000000000000000000372707646610403022031 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #12 of the sigaction system call that verifies signal-catching functions are executed on the alternate stack if the SA_ONSTACK flag is set in the sigaction.sa_flags parameter to the sigaction function call, and an alternate stack has been setup with sigaltstack(). NOTE: This test case does not attempt to verify the proper operation of sigaltstack. */ #define _XOPEN_SOURCE 600 #include #include #include #include "posixtest.h" stack_t alt_ss; void handler(int signo) { stack_t ss; printf("Caught SIGABRT\n"); if (sigaltstack((stack_t *)0, &ss) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); exit(-1); } if (ss.ss_sp != alt_ss.ss_sp || ss.ss_size != alt_ss.ss_size) { printf("Test FAILED\n"); exit(-1); } } int main() { struct sigaction act; act.sa_handler = handler; act.sa_flags = SA_ONSTACK; sigemptyset(&act.sa_mask); if (sigaction(SIGABRT, &act, 0) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if ((alt_ss.ss_sp = (void *)malloc(SIGSTKSZ)) == NULL) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } alt_ss.ss_size = SIGSTKSZ; alt_ss.ss_flags = 0; if (sigaltstack(&alt_ss, (stack_t *)0) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (raise(SIGABRT) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/sigaction/16-21.c0100644000000000000000000001260510205365423022104 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertions: * * If SA_RESTART is set in sa_flags, interruptible function interrupted by signal * shall restart silently. * The steps are: * -> create a child thread * -> child registers a handler for SIGSYS with SA_RESTART, then waits for the semaphore * -> parent kills the child with SIGSYS, then post the semaphore. * The test fails if the sem_wait function returns EINTR *Note: This test uses sem_wait to check if EINTR is returned. As the function is not required to fail with EINTR, the test may return PASS and the feature not be correct (false positive). Anyway, a false negative status cannot be returned. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /* This test tests for an XSI feature */ #define _XOPEN_SOURCE 600 /******************************************************************************/ /*************************** standard includes ********************************/ /******************************************************************************/ #include #include #include #include #include #include #include #include #include /******************************************************************************/ /*************************** Test framework *******************************/ /******************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int * (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /******************************************************************************/ /**************************** Configuration ***********************************/ /******************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif #define SIGNAL SIGSYS /******************************************************************************/ /*************************** Test case ***********************************/ /******************************************************************************/ volatile sig_atomic_t caught = 0; sem_t sem; /* Handler function */ void handler( int signo ) { printf( "Caught signal %d\n", signo ); caught++; } /* Thread function */ void * threaded ( void * arg ) { int ret = 0; ret = sem_wait( &sem ); if ( ret != 0 ) { if ( errno == EINTR ) { FAILED( "The function returned EINTR while SA_RESTART is set" ); } else { UNRESOLVED( errno, "sem_wait failed" ); } } return NULL; } /* main function */ int main() { int ret; pthread_t child; struct sigaction sa; /* Initialize output */ output_init(); /* Set the signal handler */ sa.sa_flags = SA_RESTART; sa.sa_handler = handler; ret = sigemptyset( &sa.sa_mask ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to empty signal set" ); } /* Install the signal handler for SIGNAL */ ret = sigaction( SIGNAL, &sa, 0 ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to set signal handler" ); } /* Initialize the semaphore */ ret = sem_init( &sem, 0, 0 ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to init a semaphore" ); } /* Create the child thread */ ret = pthread_create( &child, NULL, threaded, NULL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to create a child thread" ); } /* Let the child thread enter the wait routine... we use sched_yield as there is no certain way to test that the child is waiting for the semaphore... */ sched_yield(); sched_yield(); sched_yield(); /* Ok, now kill the child */ ret = pthread_kill( child, SIGNAL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to kill the child thread" ); } /* wait that the child receives the signal */ while ( !caught ) sched_yield(); /* Now let the child run and terminate */ ret = sem_post( &sem ); if ( ret != 0 ) { UNRESOLVED( errno, "Failed to post the semaphore" ); } ret = pthread_join( child, NULL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to join the thread" ); } /* terminate */ ret = sem_destroy( &sem ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to destroy the semaphore" ); } /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/sigaction/19-13.c0100644000000000000000000001017610205365423022111 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertions: * * If SA_SIGINFO is set in sa_flags and Real Time Signals extension is supported, * sa_sigaction is used as the signal handling function. * The steps are: * -> test for RTS extension * -> register a handler for SIGTERM with SA_SIGINFO, and a known function * as sa_sigaction * -> raise SIGTERM, and check the function has been called. * The test fails if the function is not called */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /******************************************************************************/ /*************************** standard includes ********************************/ /******************************************************************************/ #include #include #include #include #include #include #include #include /******************************************************************************/ /*************************** Test framework *******************************/ /******************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int * (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /******************************************************************************/ /**************************** Configuration ***********************************/ /******************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif #define SIGNAL SIGTERM /******************************************************************************/ /*************************** Test case ***********************************/ /******************************************************************************/ int called = 0; void handler( int sig, siginfo_t *info, void *context ) { if ( info->si_signo != SIGNAL ) { FAILED( "Wrong signal generated?" ); } called = 1; } /* main function */ int main() { int ret; long rts; struct sigaction sa; /* Initialize output */ output_init(); /* Test the RTS extension */ rts = sysconf( _SC_REALTIME_SIGNALS ); if ( rts < 0L ) { UNTESTED( "This test needs the RTS extension" ); } /* Set the signal handler */ sa.sa_flags = SA_SIGINFO; sa.sa_sigaction = handler; ret = sigemptyset( &sa.sa_mask ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to empty signal set" ); } /* Install the signal handler for SIGTERM */ ret = sigaction( SIGNAL, &sa, 0 ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to set signal handler" ); } if ( called ) { FAILED( "The signal handler has been called when no signal was raised" ); } ret = raise( SIGNAL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to raise SIGTERM" ); } if ( !called ) { FAILED( "the sa_handler was not called whereas SA_SIGINFO was not set" ); } /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/sigaction/1-1.c0100644000000000000000000000270407631716427021750 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: Rusty.Lnch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #1 of the sigaction system call that shows sigaction (when used with a non-null act pointer) changes the action for a signal. Steps: 1. Initialize a global variable to indicate the signal handler has not been called. (A signal handler of the prototype "void func(int signo);" will set the global variable to indicate otherwise. 2. Use sigaction to setup a signal handler for SIGABRT 3. Raise SIGABRT. 4. Verify the global indicates the signal was called. */ #include #include #include "posixtest.h" int handler_called = 0; void handler(int signo) { handler_called = 1; } int main() { struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); if (sigaction(SIGABRT, &act, 0) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (raise(SIGABRT) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (handler_called) { printf("Test PASSED\n"); return PTS_PASS; } printf("Test FAILED\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sigaction/4-54.c0100644000000000000000000000161007631716562022036 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #4 of the sigaction system call that shows that attempting to add SIGKILL to the signal mask of SIGALRM will not result in sigaction returning -1 */ #include #include #include #include #include #include "posixtest.h" void handler(int signo) { } int main() { struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); sigaddset(&act.sa_mask, SIGKILL); if (sigaction(SIGALRM, &act, 0) == -1) { printf("Test FAILED\n"); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/sigaction/18-14.c0100644000000000000000000000744110205365423022112 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertions: * * If SA_SIGINFO is not set in sa_flags, sa_handler is used as the signal * handling function. * The steps are: * -> register a handler for SIGTSTP without SA_SIGINFO, and a known function * as saèhandler * -> raise SIGTSTP, and check the function has been called. * The test fails if the function is not called */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /******************************************************************************/ /*************************** standard includes ********************************/ /******************************************************************************/ #include #include #include #include #include #include #include #include /******************************************************************************/ /*************************** Test framework *******************************/ /******************************************************************************/ #include "testfrmw.h" #include "testfrmw.c" /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int * (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ /******************************************************************************/ /**************************** Configuration ***********************************/ /******************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif #define SIGNAL SIGTSTP /******************************************************************************/ /*************************** Test case ***********************************/ /******************************************************************************/ int called = 0; void handler( int sig ) { called = 1; } /* main function */ int main() { int ret; struct sigaction sa; /* Initialize output */ output_init(); /* Set the signal handler */ sa.sa_flags = 0; sa.sa_handler = handler; ret = sigemptyset( &sa.sa_mask ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to empty signal set" ); } /* Install the signal handler for SIGTSTP */ ret = sigaction( SIGNAL, &sa, 0 ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to set signal handler" ); } if ( called ) { FAILED( "The signal handler has been called when no signal was raised" ); } ret = raise( SIGNAL ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to raise SIGTSTP" ); } if ( !called ) { FAILED( "the sa_handler was not called whereas SA_SIGINFO was not set" ); } /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/sigaction/8-11.c0100644000000000000000000000322107631716571022033 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #8 of the sigaction system call that verifies that if signals in the sa_mask (passed in the sigaction struct of the sigaction function call) are added to the process signal mask during execution of the signal-catching function. */ #include #include #include #include #include #include "posixtest.h" int SIGPIPE_count = 0; void SIGPIPE_handler(int signo) { SIGPIPE_count++; printf("Caught SIGPIPE\n"); } void SIGQUIT_handler(int signo) { printf("Caught SIGQUIT\n"); raise(SIGPIPE); if (SIGPIPE_count) { printf("Test FAILED\n"); exit(-1); } } int main() { struct sigaction act; act.sa_handler = SIGQUIT_handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); sigaddset(&act.sa_mask, SIGPIPE); if (sigaction(SIGQUIT, &act, 0) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); return PTS_UNRESOLVED; } act.sa_handler = SIGPIPE_handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); if (sigaction(SIGPIPE, &act, 0) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); return PTS_UNRESOLVED; } if (raise(SIGQUIT) == -1) { perror("Unexpected error while attempting to " "setup test pre-conditions"); return PTS_UNRESOLVED; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/sigaction/9-1.c0100644000000000000000000000503410056775065021755 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: Rusty.Lnch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test assertion #9 by verifying that SIGCHLD signals are not sent when the parent has setup a SIGCHLD signal handler with the SA_NOCLDSTOP flag set * 12/18/02 - Adding in include of sys/time.h per * rodrigc REMOVE-THIS AT attbi DOT com input that it needs * to be included whenever the timeval struct is used. * */ /* * adam.li@intel.com: 2004-05-26: select should block child */ #include #include #include #include #include #include #include #include #define NUMSTOPS 10 volatile int child_stopped = 0; void handler(int signo, siginfo_t *info, void *context) { if (info && info->si_code == CLD_STOPPED) { printf("Child has been stopped\n"); child_stopped++; } } int main() { pid_t pid; struct sigaction act; struct timeval tv; act.sa_sigaction = handler; act.sa_flags = SA_SIGINFO | SA_NOCLDSTOP; sigemptyset(&act.sa_mask); sigaction(SIGCHLD, &act, 0); if ((pid = fork()) == 0) { /* child */ /* wait forever, or until we are interrupted by a signal */ select(0, NULL, NULL, NULL, NULL); return 0; } else { /* parent */ int s; int i; for (i = 0; i < NUMSTOPS; i++) { printf("--> Sending SIGSTOP\n"); kill(pid, SIGSTOP); /* If we send a bunch of SIGSTOP/SIGCONT signals one after the other then it is perfectly OK for the OS to not send the SIGSTOP/SIGCONT combination as an optimization. I can't think of any POSIX method to determine if a process has been stopped, so I'm going to punt with a one second sleep and assume the child process gets put to sleep within that time period. This will be problem when this test is run on a really stressed system. (Although since we are sending multiple SIGSTOP's then maybe in practice this will cause any problems.) */ tv.tv_sec = 1; tv.tv_usec = 0; select(0, NULL, NULL, NULL, &tv); printf("--> Sending SIGCONT\n"); kill(pid, SIGCONT); } /* POSIX specifies default action to be abnormal termination */ kill(pid, SIGHUP); waitpid(pid, &s, 0); } if (child_stopped == 0) { printf("Test PASSED\n"); return 0; } printf("Test FAILED\n"); return -1; } posixtestsuite/conformance/interfaces/sigaction/4-91.c0100644000000000000000000000161007631716565022042 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #4 of the sigaction system call that shows that attempting to add SIGSTOP to the signal mask of SIGTERM will not result in sigaction returning -1 */ #include #include #include #include #include #include "posixtest.h" void handler(int signo) { } int main() { struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); sigaddset(&act.sa_mask, SIGSTOP); if (sigaction(SIGTERM, &act, 0) == -1) { printf("Test FAILED\n"); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/sigaction/4-80.c0100644000000000000000000000161007631716564022037 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #4 of the sigaction system call that shows that attempting to add SIGSTOP to the signal mask of SIGALRM will not result in sigaction returning -1 */ #include #include #include #include #include #include "posixtest.h" void handler(int signo) { } int main() { struct sigaction act; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); sigaddset(&act.sa_mask, SIGSTOP); if (sigaction(SIGALRM, &act, 0) == -1) { printf("Test FAILED\n"); return PTS_FAIL; } printf("Test PASSED\n"); return PTS_PASS; } posixtestsuite/conformance/interfaces/sigaction/3-16.c0100644000000000000000000000276507631716555022051 0ustar rootroot/* * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. * Created by: rusty.lynch REMOVE-THIS AT intel DOT com * This file is licensed under the GPL license. For the full content * of this license, see the COPYING file at the top level of this * source tree. Test case for assertion #3 of the sigaction system call that shows calling sigaction with a null act argument does not change the signal handler. Steps: 1. Initialize global variable to indicate handler has not been called 2. Set the signal handler for SIGTTOU to handler 3. Call sigaction with a null act 4. raise SIGTTOU 5. Verify handler was called. */ #include #include #include "posixtest.h" int handler_called = 0; void handler(int signo) { handler_called = 1; } int main() { struct sigaction act; struct sigaction oact; act.sa_handler = handler; act.sa_flags = 0; sigemptyset(&act.sa_mask); if (sigaction(SIGTTOU, &act, 0) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (sigaction(SIGTTOU, 0, &oact) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (raise(SIGTTOU) == -1) { perror("Unexpected error while attempting to setup test " "pre-conditions"); return PTS_UNRESOLVED; } if (handler_called) { printf("Test PASSED\n"); return PTS_PASS; } printf("Test FAILED\n"); return PTS_FAIL; } posixtestsuite/conformance/interfaces/sigaction/28-3.c0100644000000000000000000001407310206323212022017 0ustar rootroot/* * Copyright (c) 2005, Bull S.A.. All rights reserved. * Created by: Sebastien Decugis * This program is free software; you can redistribute it and/or modify it * under the terms of version 2 of the GNU General Public License as * published by the Free Software Foundation. * * This program is distributed in the hope that it would be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * * You should have received a copy of the GNU General Public License along * with this program; if not, write the Free Software Foundation, Inc., 59 * Temple Place - Suite 330, Boston MA 02111-1307, USA. * This sample test aims to check the following assertions: * * If the signal action was set with the signal() function, getting it into oact then reinstalling it with act must be valid. * The steps are: * -> register a signal handler for SIGBUS with signal(). * -> check this signal handler works. * -> change the signal handler with sigaction, saving old handler in oact. * -> check the new signal handler works. * -> set the old signal handler back * -> check the old signal handler still works. * The test fails if a signal handler does not work as expected. */ /* We are testing conformance to IEEE Std 1003.1, 2003 Edition */ #define _POSIX_C_SOURCE 200112L /******************************************************************************/ /*************************** standard includes ********************************/ /******************************************************************************/ #include #include #include #include #include #include #include /******************************************************************************/ /*************************** Test framework *******************************/ /******************************************************************************/ /* This header is responsible for defining the following macros: * UNRESOLVED(ret, descr); * where descr is a description of the error and ret is an int * (error code for example) * FAILED(descr); * where descr is a short text saying why the test has failed. * PASSED(); * No parameter. * * Both three macros shall terminate the calling process. * The testcase shall not terminate in any other maneer. * * The other file defines the functions * void output_init() * void output(char * string, ...) * * Those may be used to output information. */ #include "posixtest.h" #include #include #ifdef __GNUC__ /* We are using GCC */ #define UNRESOLVED(x, s) \ { output("Test %s unresolved: got %i (%s) on line %i (%s)\n", __FILE__, x, strerror(x), __LINE__, s); \ output_fini(); \ exit(PTS_UNRESOLVED); } #define FAILED(s) \ { output("Test %s FAILED: %s\n", __FILE__, s); \ output_fini(); \ exit(PTS_FAIL); } #define PASSED \ output_fini(); \ exit(PTS_PASS); #define UNTESTED(s) \ { output("File %s cannot test: %s\n", __FILE__, s); \ output_fini(); \ exit(PTS_UNTESTED); \ } #else /* not using GCC */ #define UNRESOLVED(x, s) \ { output("Test unresolved: got %i (%s) on line %i (%s)\n", x, strerror(x), __LINE__, s); \ output_fini(); \ exit(PTS_UNRESOLVED); } #define FAILED(s) \ { output("Test FAILED: %s\n", s); \ output_fini(); \ exit(PTS_FAIL); } #define PASSED \ output_fini(); \ exit(PTS_PASS); #define UNTESTED(s) \ { output("Unable to test: %s\n", s); \ output_fini(); \ exit(PTS_UNTESTED); \ } #endif void output_init() { /* do nothing */ return ; } void output( char * string, ... ) { va_list ap; #ifndef PLOT_OUTPUT char *ts = "[??:??:??]"; struct tm * now; time_t nw; #endif #ifndef PLOT_OUTPUT nw = time( NULL ); now = localtime( &nw ); if ( now == NULL ) printf( ts ); else printf( "[%2.2d:%2.2d:%2.2d]", now->tm_hour, now->tm_min, now->tm_sec ); #endif va_start( ap, string ); vprintf( string, ap ); va_end( ap ); } void output_fini() { /*do nothing */ return ; } /******************************************************************************/ /**************************** Configuration ***********************************/ /******************************************************************************/ #ifndef VERBOSE #define VERBOSE 1 #endif #define SIGNAL SIGBUS /******************************************************************************/ /*************************** Test case ***********************************/ /******************************************************************************/ sig_atomic_t called = 1; void handler_1( int sig ) { called++; } void handler_2( int sig ) { called--; } /* main function */ int main() { int ret; struct sigaction sa, save; /* Initialize output */ output_init(); /* Register the signal handler with signal */ if ( SIG_ERR == signal( SIGNAL, handler_1 ) ) { UNRESOLVED( errno, "Failed to register signal handler with signal()" ); } /* As whether signal handler is restored to default when executed is implementation defined, we cannot check it was registered here. */ /* Set the new signal handler with sigaction*/ sa.sa_flags = 0; sa.sa_handler = handler_2; ret = sigemptyset( &sa.sa_mask ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to empty signal set" ); } /* Install the signal handler for SIGBUS */ ret = sigaction( SIGNAL, &sa, &save ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to set signal handler" ); } /* Check the signal handler has been set up */ ret = raise( SIGNAL ); if ( ret != 0 ) { UNRESOLVED( ret , "Failed to raise the signal" ); } if ( called != 0 ) { FAILED( "handler not executed" ); } /* Restore the first signal handler */ ret = sigaction( SIGNAL, &save, 0 ); if ( ret != 0 ) { UNRESOLVED( ret, "Failed to set signal handler" ); } /* Check the signal handler has been set up */ ret = raise( SIGNAL ); if ( ret != 0 ) { UNRESOLVED( ret , "Failed to raise the signal" ); } if ( called != 1 ) { FAILED( "handler not executed" ); } /* Test passed */ #if VERBOSE > 0 output( "Test passed\n" ); #endif PASSED; } posixtestsuite/conformance/interfaces/sigaction/gentests.pl0100755000000000000000000000252307631716574023504 0ustar rootroot#!/usr/bin/perl -w # Copyright (c) 2002-2003, Intel Corporation. All rights reserved. # Created by: rusty.lynch REMOVE-THIS AT intel DOT com # This file is licensed under the GPL license. For the full content # of this license, see the COPYING file at the top level of this # source tree. my (@signals) = ("SIGABRT", "SIGALRM", "SIGBUS", "SIGCHLD", "SIGCONT", "SIGFPE", "SIGHUP", "SIGILL", "SIGINT", "SIGPIPE", "SIGQUIT", "SIGSEGV", "SIGTERM", "SIGTSTP", "SIGTTIN", "SIGTTOU", "SIGUSR1", "SIGUSR2", "SIGPOLL", "SIGPROF", "SIGSYS", "SIGTRAP", "SIGURG", "SIGVTALRM", "SIGXCPU", "SIGXFSZ"); my (%testcases, $prev); $prev = "SIGALRM"; open (LIST, "ls ./templates/*.in|") or die "Could not get listing"; while () { my ($fname) = $_; chomp $fname; if ($fname =~ /template_([0-9]*)-.*\.in/) { my ($assertion) = $1; open (TEMPLATE, "$fname") or die "Could not open $fname"; my (@t) =