summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@gmail.com>2009-09-17 03:18:51 +0000
committerTavian Barnes <tavianator@gmail.com>2009-09-17 03:18:51 +0000
commit66084b816dd25a41f774240328a31d57efd276e4 (patch)
treeacd22d0e3eb5f5608184fc18479e8890906cbe7f /tests
parentf46ea7eb1b6f55036f10b6ae919c1785cb72c836 (diff)
downloadlibsandglass-66084b816dd25a41f774240328a31d57efd276e4.tar.xz
Begin libsandglass implementation.
Diffstat (limited to 'tests')
-rwxr-xr-xtests/simple-test2
-rw-r--r--tests/simple.c27
2 files changed, 28 insertions, 1 deletions
diff --git a/tests/simple-test b/tests/simple-test
index 407febc..8fbcf16 100755
--- a/tests/simple-test
+++ b/tests/simple-test
@@ -32,7 +32,7 @@ DUALCASE=1; export DUALCASE # for MKS sh
# if CDPATH is set.
(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
-relink_command="(cd /home/tavianator/libsandglass/tests; { test -z \"\${LIBRARY_PATH+set}\" || unset LIBRARY_PATH || { LIBRARY_PATH=; export LIBRARY_PATH; }; }; { test -z \"\${COMPILER_PATH+set}\" || unset COMPILER_PATH || { COMPILER_PATH=; export COMPILER_PATH; }; }; { test -z \"\${GCC_EXEC_PREFIX+set}\" || unset GCC_EXEC_PREFIX || { GCC_EXEC_PREFIX=; export GCC_EXEC_PREFIX; }; }; { test -z \"\${LD_RUN_PATH+set}\" || unset LD_RUN_PATH || { LD_RUN_PATH=; export LD_RUN_PATH; }; }; { test -z \"\${LD_LIBRARY_PATH+set}\" || unset LD_LIBRARY_PATH || { LD_LIBRARY_PATH=; export LD_LIBRARY_PATH; }; }; PATH=/bin:/usr/bin:/sbin:/usr/sbin:/opt/java/bin:/opt/java/jre/bin:/home/tavianator/bin:/usr/bin/perlbin/site:/usr/bin/perlbin/vendor:/usr/bin/perlbin/core:/opt/qt/bin; export PATH; gcc -g -Wall -o \$progdir/\$file simple.o ../src/.libs/libsandglass.so -Wl,-rpath -Wl,/home/tavianator/libsandglass/src/.libs)"
+relink_command="(cd /home/tavianator/libsandglass/tests; { test -z \"\${LIBRARY_PATH+set}\" || unset LIBRARY_PATH || { LIBRARY_PATH=; export LIBRARY_PATH; }; }; { test -z \"\${COMPILER_PATH+set}\" || unset COMPILER_PATH || { COMPILER_PATH=; export COMPILER_PATH; }; }; { test -z \"\${GCC_EXEC_PREFIX+set}\" || unset GCC_EXEC_PREFIX || { GCC_EXEC_PREFIX=; export GCC_EXEC_PREFIX; }; }; { test -z \"\${LD_RUN_PATH+set}\" || unset LD_RUN_PATH || { LD_RUN_PATH=; export LD_RUN_PATH; }; }; { test -z \"\${LD_LIBRARY_PATH+set}\" || unset LD_LIBRARY_PATH || { LD_LIBRARY_PATH=; export LD_LIBRARY_PATH; }; }; PATH=/bin:/usr/bin:/sbin:/usr/sbin:/opt/java/bin:/opt/java/jre/bin:/home/tavianator/bin:/usr/bin/perlbin/site:/usr/bin/perlbin/vendor:/usr/bin/perlbin/core:/opt/qt/bin; export PATH; gcc -g -Wall -o \$progdir/\$file simple.o ../src/.libs/libsandglass.so -lrt -Wl,-rpath -Wl,/home/tavianator/libsandglass/src/.libs)"
# This environment variable determines our operation mode.
if test "$libtool_install_magic" = "%%%MAGIC variable%%%"; then
diff --git a/tests/simple.c b/tests/simple.c
index 921ab6c..85dacb6 100644
--- a/tests/simple.c
+++ b/tests/simple.c
@@ -19,10 +19,37 @@
*************************************************************************/
#include <sandglass.h>
+#include <unistd.h>
+#include <time.h>
#include <stdlib.h>
+#include <stdio.h>
int
main()
{
+ sandglass_t sandglass;
+ sandglass_attributes_t min = { SANDGLASS_MONOTONIC, SANDGLASS_SYSTEM },
+ max = { SANDGLASS_MONOTONIC, SANDGLASS_CPUTIME };
+ struct timespec tosleep = { .tv_sec = 0, .tv_nsec = 100000000 };
+
+ if (sandglass_create(&sandglass, &min, &max) != 0) {
+ perror("sandglass_create()");
+ return EXIT_FAILURE;
+ }
+
+ if (sandglass_begin(&sandglass) != 0) {
+ perror("sandglass_begin()");
+ return EXIT_FAILURE;
+ }
+ while (nanosleep(&tosleep, &tosleep) != 0);
+ if (sandglass_elapse(&sandglass) != 0) {
+ perror("sandglass_elapse()");
+ return EXIT_FAILURE;
+ }
+
+ printf("0.1 seconds timed by sandglass as %ld grains; %g s\n",
+ sandglass.grains,
+ sandglass.grains/sandglass.resolution);
+
return EXIT_SUCCESS;
}