Added Open POSIX* Testsuite test: timer_gettime
diff --git a/testcases/kernel/timers/timer_gettime/Makefile b/testcases/kernel/timers/timer_gettime/Makefile
new file mode 100644
index 0000000..68b8ffa
--- /dev/null
+++ b/testcases/kernel/timers/timer_gettime/Makefile
@@ -0,0 +1,15 @@
+CFLAGS := -Wall -I ../../../../include -I../include -D _GNU_SOURCE
+LDFLAGS := -L ../../../../lib -lltp 
+
+SRCS=$(wildcard *.c)
+TARGETS=$(patsubst %.c,%,$(SRCS))
+TEST=timer_gettime01
+
+all: $(TARGETS)
+	@chmod 755 $(TEST)
+
+install:
+	for i in $(TARGETS) $(TEST) ; do ln -f $$i ../../../bin/$$i ; done ;
+
+clean:
+	rm -f $(TARGETS)
diff --git a/testcases/kernel/timers/timer_gettime/assertions.xml b/testcases/kernel/timers/timer_gettime/assertions.xml
new file mode 100644
index 0000000..5a39144
--- /dev/null
+++ b/testcases/kernel/timers/timer_gettime/assertions.xml
@@ -0,0 +1,25 @@
+<assertions>
+  <assertion id="1" tag="ref:XSH6:46888:46889 pt:TMR">
+   timer_gettime() places in itimerspec the amount of time until timer,
+   timerid, expires (in itimerspec.it_value) and the reload value of
+   the timer (in itimerspec.it_interval).
+  </assertion>
+  <assertion id="2" tag="ref:XSH6:46890:46891 pt:TMR">
+   itimerspec.it_value contains 0 if the timer was disarmed.
+  </assertion>
+  <assertion id="3" tag="ref:XSH6:46891:46892 pt:TMR">
+   itimerspec.it_value returns a relative time amount, even if the timer
+   was absolute.
+  </assertion>
+  <assertion id="4" tag="ref:XSH6:46935:46935 pt:TMR">
+   timer_gettime() returns 0 on success
+  </assertion>
+  <assertion id="5" tag="ref:XSH6:46936:46936 pt:TMR">
+   timer_gettime() returns -1 on failure
+  </assertion>
+  <assertion id="6" tag="ref:XSH6:46940:46941 pt:TMR">
+   timer_gettime() returns errno==EINVAL if timer ID does not correspond
+   to a valid timer ID (i.e., one created using timer_create() but not
+   yet deleted with timer_delete()).
+  </assertion>
+</assertions>
diff --git a/testcases/kernel/timers/timer_gettime/coverage.txt b/testcases/kernel/timers/timer_gettime/coverage.txt
new file mode 100644
index 0000000..aa9a47e
--- /dev/null
+++ b/testcases/kernel/timers/timer_gettime/coverage.txt
@@ -0,0 +1,9 @@
+This file defines the coverage for function timer_gettime().
+
+Assertion	Coverage
+1		YES
+2		YES
+3		YES
+4		YES
+5		YES
+6		YES
diff --git a/testcases/kernel/timers/timer_gettime/timer_gettime01 b/testcases/kernel/timers/timer_gettime/timer_gettime01
new file mode 100755
index 0000000..54baeb9
--- /dev/null
+++ b/testcases/kernel/timers/timer_gettime/timer_gettime01
@@ -0,0 +1,93 @@
+#!/bin/sh
+####################################################
+#    Copyright (c) International Business Machines  Corp., 2003
+#
+#    This program is free software;  you can redistribute it and/or modify
+#    it under the terms of the GNU General Public License as published by
+#    the Free Software Foundation; either version 2 of the License, or
+#    (at your option) any later version.
+#
+#    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.
+#
+#    You should have received a copy of the GNU General Public License
+#    along with this program;  if not, write to the Free Software
+#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+#   DESCRIPTION : a wrapper interface for tests from the Open POSIX* Testsuite.
+#   HISTORY     :
+#       02/19/2003 Robbie Williamson (robbiew@austin.ibm.com)
+#               written
+####################################################
+
+#Set variables NAME and TST_TOTAL
+NAME=timer_gettime01
+export TST_TOTAL=10
+
+check_return_code()
+{
+  #PTS_PASS
+  if [ $RC -eq 0 ];then
+      $LTPBIN/tst_resm TPASS "`cat $OUTPUT_FILE`" 
+  fi
+
+  #PTS_FAIL
+  if [ $RC -eq 1 ];then
+      $LTPBIN/tst_resm TFAIL "`cat $OUTPUT_FILE`"
+      NOPASS=1
+  fi
+  #PTS_UNRESOLVED 
+  if [ $RC -eq 2 ];then
+      $LTPBIN/tst_resm TBROK "`cat $OUTPUT_FILE`"
+      NOPASS=1
+  fi
+  #PTS_UNSUPPORTED 
+  if [ $RC -eq 4 ];then
+      $LTPBIN/tst_resm TCONF "`cat $OUTPUT_FILE`"
+  fi
+  #define PTS_UNTESTED    
+  if [ $RC -eq 5 ];then
+      $LTPBIN/tst_resm TINFO "UNTESTED: `cat $OUTPUT_FILE`"
+  fi
+
+}
+
+if [[ -z $LTPROOT ]]
+  then
+    BIN=.
+    ls | grep tst_resm >/dev/null 2>&1
+    if [ $? -eq 0 ]; then
+      LTPBIN=$BIN
+    else
+      LTPBIN=../../../bin
+    fi
+  else
+    BIN=$LTPROOT/testcases/bin
+    LTPBIN=$BIN
+fi
+
+if [[ -z $TMP ]]
+then
+    TMP=/tmp
+fi
+
+OUTPUT_FILE=$TMP/$NAME.$$
+export TCID=$NAME
+NOPASS=0
+COUNT=0
+TST_LIST=`ls $NAME.*|grep -v "\.c"|cut -d. -f1,2`
+for TEST in $TST_LIST
+do
+
+  COUNT=$(($COUNT + 1))
+  export TST_COUNT=$COUNT
+  $BIN/$TEST >$OUTPUT_FILE 2>&1
+  RC=$?
+  check_return_code
+done
+
+rm -f $OUTPUT_FILE
+
+exit $NOPASS
diff --git a/testcases/kernel/timers/timer_gettime/timer_gettime01.1-1.c b/testcases/kernel/timers/timer_gettime/timer_gettime01.1-1.c
new file mode 100644
index 0000000..2229324
--- /dev/null
+++ b/testcases/kernel/timers/timer_gettime/timer_gettime01.1-1.c
@@ -0,0 +1,81 @@
+/*   
+ * 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_gettime() sets sets itimerspec.it_value to the
+ * amount of time remaining.
+ * - Create and arm a timer.
+ * - Call timer_gettime().
+ * - Ensure the value returned is within ACCEPTABLEDELTA less than
+ *   the value set.
+ *
+ * Signal SIGCONT will be used so that it will not affect the test if
+ * the timer expires.
+ * Clock CLOCK_REALTIME will be used.
+ */
+
+#include <time.h>
+#include <signal.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include "posixtest.h"
+
+#define TIMERSEC 5
+#define ACCEPTABLEDELTA 1
+
+int main(int argc, char *argv[])
+{
+	struct sigevent ev;
+	timer_t tid;
+	struct itimerspec itsset, itsget;
+	int delta;
+
+	ev.sigev_notify = SIGEV_SIGNAL;
+	ev.sigev_signo = SIGCONT;
+
+	itsset.it_interval.tv_sec = 0;
+	itsset.it_interval.tv_nsec = 0;
+	itsset.it_value.tv_sec = TIMERSEC;
+	itsset.it_value.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, &itsset, NULL) != 0) {
+		perror("timer_settime() did not return success\n");
+		return PTS_UNRESOLVED;
+	}
+
+	if (timer_gettime(tid, &itsget) != 0) {
+		perror("timer_gettime() did not return success\n");
+		return PTS_UNRESOLVED;
+	}
+
+	delta = itsset.it_value.tv_sec - itsget.it_value.tv_sec;
+
+	if (delta < 0) {
+		printf("FAIL:  timer_gettime() value > timer_settime()\n");
+		printf("%d > %d\n", (int) itsget.it_value.tv_sec, 
+				(int) itsset.it_value.tv_sec);
+		return PTS_FAIL;
+	}
+
+	if (delta <= ACCEPTABLEDELTA) {
+		printf("Test PASSED\n");
+		return PTS_PASS;
+	} else {
+		printf("FAIL:  timer_gettime() value !~= timer_settime()\n");
+		printf("%d !~= %d\n", (int) itsget.it_value.tv_sec, 
+					(int) itsset.it_value.tv_sec);
+		return PTS_FAIL;
+	}
+
+	printf("This code should not be executed\n");
+	return PTS_UNRESOLVED;
+}
diff --git a/testcases/kernel/timers/timer_gettime/timer_gettime01.1-2.c b/testcases/kernel/timers/timer_gettime/timer_gettime01.1-2.c
new file mode 100644
index 0000000..5f63c92
--- /dev/null
+++ b/testcases/kernel/timers/timer_gettime/timer_gettime01.1-2.c
@@ -0,0 +1,88 @@
+/*   
+ * 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_gettime() sets sets itimerspec.it_value to the
+ * amount of time remaining in the middle of a timer.
+ * - Create and arm a timer for TIMERSEC seconds.
+ * - Sleep for SLEEPSEC < TIMERSEC.
+ * - Call timer_gettime().
+ * - Ensure the value returned is within ACCEPTABLEDELTA less than
+ *   TIMERSEC-SLEEPSEC.
+ *
+ * Signal SIGCONT will be used so that it will not affect the test if
+ * the timer expires.
+ * Clock CLOCK_REALTIME will be used.
+ */
+
+#include <time.h>
+#include <signal.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include "posixtest.h"
+
+#define TIMERSEC 8
+#define SLEEPSEC 2
+#define ACCEPTABLEDELTA 1
+
+int main(int argc, char *argv[])
+{
+	struct sigevent ev;
+	timer_t tid;
+	struct itimerspec itsset, itsget;
+	int delta;
+
+	ev.sigev_notify = SIGEV_SIGNAL;
+	ev.sigev_signo = SIGCONT;
+
+	itsset.it_interval.tv_sec = 0;
+	itsset.it_interval.tv_nsec = 0;
+	itsset.it_value.tv_sec = TIMERSEC;
+	itsset.it_value.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, &itsset, NULL) != 0) {
+		perror("timer_settime() did not return success\n");
+		return PTS_UNRESOLVED;
+	}
+
+	if (sleep(SLEEPSEC) != 0) {
+		perror("sleep() did not return 0\n");
+		return PTS_UNRESOLVED;
+	}
+
+	if (timer_gettime(tid, &itsget) != 0) {
+		perror("timer_gettime() did not return success\n");
+		return PTS_UNRESOLVED;
+	}
+
+	delta = (itsset.it_value.tv_sec - SLEEPSEC) - itsget.it_value.tv_sec;
+
+	if (delta < 0) {
+		printf("FAIL:  timer_gettime() value > time expected left\n");
+		printf("%d > %d\n", (int) itsget.it_value.tv_sec, 
+				(int) itsset.it_value.tv_sec - SLEEPSEC);
+		return PTS_FAIL;
+	}
+
+	if (delta <= ACCEPTABLEDELTA) {
+		printf("Test PASSED\n");
+		return PTS_PASS;
+	} else {
+		printf("FAIL:  timer_gettime() value !~= time expected left\n");
+		printf("%d !~= %d\n", (int) itsget.it_value.tv_sec, 
+				(int) itsset.it_value.tv_sec - SLEEPSEC);
+		return PTS_FAIL;
+	}
+
+	printf("This code should not be executed\n");
+	return PTS_UNRESOLVED;
+}
diff --git a/testcases/kernel/timers/timer_gettime/timer_gettime01.1-3.c b/testcases/kernel/timers/timer_gettime/timer_gettime01.1-3.c
new file mode 100644
index 0000000..6260156
--- /dev/null
+++ b/testcases/kernel/timers/timer_gettime/timer_gettime01.1-3.c
@@ -0,0 +1,106 @@
+/*   
+ * 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_gettime() sets sets itimerspec.it_value to the
+ * amount of time remaining in the middle of a timer.
+ * - Create and arm a timer for TIMERNSEC nanoseconds.
+ * - Sleep for SLEEPNSEC < TIMERNSEC.
+ * - Call timer_gettime().
+ * - Ensure the value returned is within ACCEPTABLEDELTA less than
+ *   TIMERNSEC-SLEEPNSEC.
+ *
+ * Signal SIGCONT will be used so that it will not affect the test if
+ * the timer expires.
+ * Clock CLOCK_REALTIME will be used.
+ */
+
+#include <time.h>
+#include <signal.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include "posixtest.h"
+
+#define TIMERNSEC 80000000
+#define SLEEPNSEC 40000000
+#define ACCEPTABLEDELTA 3000000
+
+int main(int argc, char *argv[])
+{
+	struct sigevent ev;
+	timer_t tid;
+	struct itimerspec itsset, itsget;
+	struct timespec ts;
+	int deltans;
+
+	ev.sigev_notify = SIGEV_SIGNAL;
+	ev.sigev_signo = SIGCONT;
+
+	itsset.it_interval.tv_sec = 0;
+	itsset.it_interval.tv_nsec = 0;
+	itsset.it_value.tv_sec = 0;
+	itsset.it_value.tv_nsec = TIMERNSEC;
+
+	if (timer_create(CLOCK_REALTIME, &ev, &tid) != 0) {
+		perror("timer_create() did not return success\n");
+		return PTS_UNRESOLVED;
+	}
+
+	if (timer_settime(tid, 0, &itsset, NULL) != 0) {
+		perror("timer_settime() did not return success\n");
+		return PTS_UNRESOLVED;
+	}
+
+	ts.tv_sec=0;
+	ts.tv_nsec=SLEEPNSEC;
+	if (nanosleep(&ts, NULL) != 0) {
+		perror("nanosleep() did not return success\n");
+		return PTS_UNRESOLVED;
+	}
+
+	if (timer_gettime(tid, &itsget) != 0) {
+		perror("timer_gettime() did not return success\n");
+		return PTS_UNRESOLVED;
+	}
+
+	/*
+	 * Algorithm for determining success:
+	 * - itsget must be < itsset
+	 * - itsset-itsget nsec must be <= ACCEPTABLEDELTA
+	 */
+
+	if (itsget.it_value.tv_sec > 0) {
+		printf("FAIL:  timer_gettime() value > time expected left\n");
+		printf("%d seconds > 0 seconds\n", 
+				(int) itsget.it_value.tv_sec);
+		return PTS_FAIL;
+	}
+
+	deltans=(itsset.it_value.tv_nsec - ts.tv_nsec)- itsget.it_value.tv_nsec;
+
+	if (deltans < 0) {
+		printf("FAIL:  timer_gettime() value > time expected left\n");
+		printf("%d > %d\n", (int) itsget.it_value.tv_nsec, 
+				(int) itsset.it_value.tv_nsec - 
+					(int) ts.tv_nsec);
+		return PTS_FAIL;
+	}
+
+	if (deltans <= ACCEPTABLEDELTA) {
+		printf("Test PASSED\n");
+		return PTS_PASS;
+	} else {
+		printf("FAIL:  timer_gettime() value !~= time expected left\n");
+		printf("%d !~= %d\n", (int) itsget.it_value.tv_nsec, 
+				(int) itsset.it_value.tv_nsec - 
+					(int) ts.tv_nsec);
+		return PTS_FAIL;
+	}
+
+	printf("This code should not be executed\n");
+	return PTS_UNRESOLVED;
+}
diff --git a/testcases/kernel/timers/timer_gettime/timer_gettime01.1-4.c b/testcases/kernel/timers/timer_gettime/timer_gettime01.1-4.c
new file mode 100644
index 0000000..16dbc10
--- /dev/null
+++ b/testcases/kernel/timers/timer_gettime/timer_gettime01.1-4.c
@@ -0,0 +1,114 @@
+/*   
+ * 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_gettime() sets itimerspec.it_value to the amount of
+ * time remaining after it has expired once and is reloaded.  Also
+ * test that timer_gettime() sets itimerspec.it_interval to the
+ * interval remaining.
+ * - Create and arm a timer for TIMERVALSEC seconds with interval
+ *   TIMERINTERVALSEC seconds.
+ * - Sleep for SLEEPSEC > TIMERVALSEC, but < TIMERINTERVAL seconds
+ * - Call timer_gettime().
+ * - Ensure the value returned is within ACCEPTABLEDELTA less than
+ *   TIMERINTERVALSEC - (SLEEPSEC-TIMERVALSEC).
+ * - Ensure that interval TIMERINTERVALSEC is returned.
+ *
+ * Signal SIGCONT will be used so that it will not affect the test if
+ * the timer expires.
+ * Clock CLOCK_REALTIME will be used.
+ */
+
+#include <time.h>
+#include <signal.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include "posixtest.h"
+
+#define TIMERVALSEC 2
+#define TIMERINTERVALSEC 8
+#define SLEEPSEC 3
+#define ACCEPTABLEDELTA 1
+
+int main(int argc, char *argv[])
+{
+	struct sigevent ev;
+	timer_t tid;
+	struct itimerspec itsset, itsget;
+	int delta;
+	int expectedleft;
+
+	ev.sigev_notify = SIGEV_SIGNAL;
+	ev.sigev_signo = SIGCONT;
+
+	itsset.it_interval.tv_sec = TIMERINTERVALSEC;
+	itsset.it_interval.tv_nsec = 0;
+	itsset.it_value.tv_sec = TIMERVALSEC;
+	itsset.it_value.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, &itsset, NULL) != 0) {
+		perror("timer_settime() did not return success\n");
+		return PTS_UNRESOLVED;
+	}
+
+	if (sleep(SLEEPSEC) != 0) {
+		perror("sleep() did not return 0\n");
+		return PTS_UNRESOLVED;
+	}
+
+	if (timer_gettime(tid, &itsget) != 0) {
+		perror("timer_gettime() did not return success\n");
+		return PTS_UNRESOLVED;
+	}
+
+	/*
+	 * Check interval first
+	 */
+	if ( (itsget.it_interval.tv_sec != itsset.it_interval.tv_sec) ||
+		(itsget.it_interval.tv_nsec != itsset.it_interval.tv_nsec) ) {
+		printf("FAIL:  it_interval not correctly set\n");
+		printf("%d != (expected) %d or %d != (expected) %d\n",
+				(int) itsget.it_interval.tv_sec,
+				(int) itsset.it_interval.tv_sec,
+				(int) itsget.it_interval.tv_nsec,
+				(int) itsset.it_interval.tv_nsec);
+		return PTS_UNRESOLVED;
+	}
+
+	/*
+	 * Check value next
+	 * value should be < TIMERINTERVALSEC - (SLEEPSEC-TIMERVALSEC)
+	 */
+	expectedleft = itsset.it_interval.tv_sec - 
+				(SLEEPSEC - itsset.it_value.tv_sec);
+	delta = expectedleft - itsget.it_value.tv_sec;
+
+	if (delta < 0) {
+		printf("FAIL:  timer_gettime() value > time expected left\n");
+		printf("%d > %d\n", (int) itsget.it_value.tv_sec, 
+				expectedleft);
+		return PTS_FAIL;
+	}
+
+	if (delta <= ACCEPTABLEDELTA) {
+		printf("Test PASSED\n");
+		return PTS_PASS;
+	} else {
+		printf("FAIL:  timer_gettime() value !~= time expected left\n");
+		printf("%d !~= %d\n", (int) itsget.it_value.tv_sec, 
+				(int) itsset.it_value.tv_sec - SLEEPSEC);
+		return PTS_FAIL;
+	}
+
+	printf("This code should not be executed\n");
+	return PTS_UNRESOLVED;
+}
diff --git a/testcases/kernel/timers/timer_gettime/timer_gettime01.2-1.c b/testcases/kernel/timers/timer_gettime/timer_gettime01.2-1.c
new file mode 100644
index 0000000..57480d8
--- /dev/null
+++ b/testcases/kernel/timers/timer_gettime/timer_gettime01.2-1.c
@@ -0,0 +1,55 @@
+/*   
+ * 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_gettime() sets itimerspec.it_value = 0 if the timer
+ * was previously disarmed because it had just been created.
+ *
+ * For this test, signal SIGCONT will be used so that the test will
+ * not abort.  Clock CLOCK_REALTIME will be used.
+ */
+
+#include <time.h>
+#include <signal.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include "posixtest.h"
+
+#define TIMERSEC 1
+
+int main(int argc, char *argv[])
+{
+	struct sigevent ev;
+	timer_t tid;
+	struct itimerspec its;
+
+	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_gettime(tid, &its) != 0) {
+		perror("timer_gettime() did not return success\n");
+		return PTS_UNRESOLVED;
+	}
+
+	if ( (0 == its.it_value.tv_sec) &&
+		(0 == its.it_value.tv_nsec) ) {
+		printf("Test PASSED\n");
+		return PTS_PASS;
+	} else {
+		printf("Test FAILED:  tv_sec %d tv_nsec %d\n",
+				(int) its.it_value.tv_sec,
+				(int) its.it_value.tv_nsec);
+		return PTS_FAIL;
+	}
+
+	return PTS_UNRESOLVED;
+}
diff --git a/testcases/kernel/timers/timer_gettime/timer_gettime01.2-2.c b/testcases/kernel/timers/timer_gettime/timer_gettime01.2-2.c
new file mode 100644
index 0000000..9a4e89e
--- /dev/null
+++ b/testcases/kernel/timers/timer_gettime/timer_gettime01.2-2.c
@@ -0,0 +1,77 @@
+/*   
+ * 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_gettime() sets itimerspec.it_value = 0 if 
+ * the timer was previously disarmed because it had just expired with
+ * no repeating interval.
+ *
+ * For this test, signal SIGCONT will be used so that the test will
+ * not abort.  Clock CLOCK_REALTIME will be used.
+ */
+
+#include <time.h>
+#include <signal.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include "posixtest.h"
+
+#define TIMERSEC 1
+#define SLEEPDELTA 1
+
+int main(int argc, char *argv[])
+{
+	struct sigevent ev;
+	timer_t tid;
+	struct itimerspec itsset, itsget;
+
+	ev.sigev_notify = SIGEV_SIGNAL;
+	ev.sigev_signo = SIGCONT;
+
+	itsset.it_interval.tv_sec = 0; 
+	itsset.it_interval.tv_nsec = 0;
+	itsset.it_value.tv_sec = TIMERSEC;
+	itsset.it_value.tv_nsec = 0;
+
+	if (timer_create(CLOCK_REALTIME, &ev, &tid) != 0) {
+		perror("timer_create() did not return success\n");
+		return PTS_UNRESOLVED;
+	}
+
+	/*
+	 * set up timer that will expire
+	 */
+	if (timer_settime(tid, 0, &itsset, NULL) != 0) {
+		perror("timer_settime() did not return success\n");
+		return PTS_UNRESOLVED;
+	}
+
+	/*
+	 * let timer expire (just call sleep())
+	 */
+	sleep(TIMERSEC+SLEEPDELTA);
+
+	if (timer_gettime(tid, &itsget) != 0) {
+		perror("timer_gettime() did not return success\n");
+		return PTS_UNRESOLVED;
+	}
+
+
+	if ( (0 == itsget.it_value.tv_sec) &&
+		(0 == itsget.it_value.tv_nsec) ) {
+		printf("Test PASSED\n");
+		return PTS_PASS;
+	} else {
+		printf("Test FAILED:  tv_sec %d tv_nsec %d\n",
+				(int) itsget.it_value.tv_sec,
+				(int) itsget.it_value.tv_nsec);
+		return PTS_FAIL;
+	}
+
+	printf("This code should not be executed\n");
+	return PTS_UNRESOLVED;
+}
diff --git a/testcases/kernel/timers/timer_gettime/timer_gettime01.3-1.c b/testcases/kernel/timers/timer_gettime/timer_gettime01.3-1.c
new file mode 100644
index 0000000..470938f
--- /dev/null
+++ b/testcases/kernel/timers/timer_gettime/timer_gettime01.3-1.c
@@ -0,0 +1,90 @@
+/*   
+ * 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_gettime() returns a relative amount even on
+ * absolute timers.
+ * - Create and arm an absolute timer.
+ * - Call timer_gettime()
+ * - Ensure the value returned is within ACCEPTABLEDELTA less than
+ *   the TIMERSEC.  If it is, the values returned were indeed relative.
+ *
+ * Signal SIGCONT will be used so that it will not affect the test if
+ * the timer expires.
+ * Clock CLOCK_REALTIME will be used.
+ */
+
+#include <time.h>
+#include <signal.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include "posixtest.h"
+
+#define TIMERSEC 2
+#define SLEEPDELTA 3
+#define ACCEPTABLEDELTA 1
+
+int main(int argc, char *argv[])
+{
+	struct sigevent ev;
+	timer_t tid;
+	struct itimerspec itsset, itsget;
+	struct timespec ts;
+	int flags = 0;
+	int delta;
+
+	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 (clock_gettime(CLOCK_REALTIME, &ts) != 0) {
+		perror("clock_gettime() did not return success\n");
+		return PTS_UNRESOLVED;
+	}
+
+	itsset.it_interval.tv_sec = 0;
+	itsset.it_interval.tv_nsec = 0;
+	itsset.it_value.tv_sec = ts.tv_sec+TIMERSEC;
+	itsset.it_value.tv_nsec = ts.tv_nsec;
+
+	flags |= TIMER_ABSTIME;
+	if (timer_settime(tid, flags, &itsset, NULL) != 0) {
+		perror("timer_settime() did not return success\n");
+		return PTS_UNRESOLVED;
+	}
+
+	if (timer_gettime(tid, &itsget) != 0) {
+		perror("timer_gettime() did not return success\n");
+		return PTS_UNRESOLVED;
+	}
+
+	delta = TIMERSEC - itsget.it_value.tv_sec;
+
+	if (delta < 0) {
+		printf("FAIL:  timer_gettime() value > timer_settime()\n");
+		printf("%d > %d\n", (int) itsget.it_value.tv_sec, 
+			(int) itsset.it_value.tv_sec);
+		return PTS_FAIL;
+	}
+
+	if (delta <= ACCEPTABLEDELTA) {
+		printf("Test PASSED\n");
+		return PTS_PASS;
+	} else {
+		printf("FAIL:  timer_gettime() value !~= timer_settime()\n");
+		printf("%d !~= %d\n", (int) itsget.it_value.tv_sec, 
+			(int) itsset.it_value.tv_sec);
+		return PTS_FAIL;
+	}
+
+	printf("This code should not be executed\n");
+	return PTS_UNRESOLVED;
+}
diff --git a/testcases/kernel/timers/timer_gettime/timer_gettime01.6-1.c b/testcases/kernel/timers/timer_gettime/timer_gettime01.6-1.c
new file mode 100644
index 0000000..cd0ba05
--- /dev/null
+++ b/testcases/kernel/timers/timer_gettime/timer_gettime01.6-1.c
@@ -0,0 +1,40 @@
+/*   
+ * 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_gettime() sets errno = EINVAL if no timers have been
+ * created yet and it is called with a bogus timer ID.
+ */
+
+#include <time.h>
+#include <stdio.h>
+#include <errno.h>
+#include "posixtest.h"
+
+#define BOGUSTID 9999
+
+int main(int argc, char *argv[])
+{
+	timer_t tid;
+	struct itimerspec its;
+
+	tid = BOGUSTID;
+	if (timer_gettime(tid, &its) == -1) {
+		if (EINVAL == errno) {
+			printf("Test PASSED\n");
+			return PTS_PASS;
+		} else {
+			printf("returned -1, but errno not set\n");
+			return PTS_FAIL;
+		}
+	} else {
+		printf("timer_settime() did not return failure\n");
+		return PTS_UNRESOLVED;
+	}
+
+	printf("This code should not be executed\n");
+	return PTS_UNRESOLVED;
+}
diff --git a/testcases/kernel/timers/timer_gettime/timer_gettime01.6-2.c b/testcases/kernel/timers/timer_gettime/timer_gettime01.6-2.c
new file mode 100644
index 0000000..61f327f
--- /dev/null
+++ b/testcases/kernel/timers/timer_gettime/timer_gettime01.6-2.c
@@ -0,0 +1,50 @@
+/*   
+ * 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_gettime() sets errno = EINVAL timerid != a timer ID
+ * created via timer_create().  [Try to set timerid to a timer ID
+ * created + 1.]
+ *
+ * For this test, signal SIGCONT will be used, clock CLOCK_REALTIME
+ * will be used.
+ */
+
+#include <time.h>
+#include <signal.h>
+#include <stdio.h>
+#include <errno.h>
+#include "posixtest.h"
+
+int main(int argc, char *argv[])
+{
+	struct sigevent ev;
+	timer_t tid;
+	struct itimerspec its;
+
+	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_gettime(tid+1, &its) == -1) {
+		if (EINVAL == errno) {
+			printf("Test PASSED\n");
+			return PTS_PASS;
+		} else {
+			printf("returned -1, but errno not set\n");
+			return PTS_FAIL;
+		}
+	} else {
+		printf("timer_settime() did not return failure\n");
+		return PTS_UNRESOLVED;
+	}
+
+	return PTS_UNRESOLVED;
+}
diff --git a/testcases/kernel/timers/timer_gettime/timer_gettime01.6-3.c b/testcases/kernel/timers/timer_gettime/timer_gettime01.6-3.c
new file mode 100644
index 0000000..e438647
--- /dev/null
+++ b/testcases/kernel/timers/timer_gettime/timer_gettime01.6-3.c
@@ -0,0 +1,54 @@
+/*   
+ * 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_gettime() sets errno = EINVAL when timerid =
+ * a timer ID of a deleted timer.
+ *
+ * For this test, signal SIGCONT will be used.
+ * Clock CLOCK_REALTIME will be used.
+ */
+
+#include <time.h>
+#include <signal.h>
+#include <stdio.h>
+#include <errno.h>
+#include "posixtest.h"
+
+int main(int argc, char *argv[])
+{
+	struct sigevent ev;
+	timer_t tid;
+	struct itimerspec its;
+
+	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_gettime(tid, &its) == -1) {
+		if (EINVAL == errno) {
+			printf("Test PASSED\n");
+			return PTS_PASS;
+		} else {
+			printf("returned -1, but errno not set\n");
+			return PTS_FAIL;
+		}
+	} else {
+		printf("timer_settime() did not return failure\n");
+		return PTS_UNRESOLVED;
+	}
+
+	printf("This code should not be executed\n");
+	return PTS_UNRESOLVED;
+}