summaryrefslogtreecommitdiffstats
path: root/hl/test
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2014-07-17 22:38:07 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2014-07-17 22:38:07 (GMT)
commita1701cb901f62ccaaa08ad2c1ae9b421919c9bf9 (patch)
tree37b3ccb6c39538cf335b24dfd7f839fcd386c9fd /hl/test
parent08590f3759614957a1fa48a25b01d165d26d2c63 (diff)
downloadhdf5-a1701cb901f62ccaaa08ad2c1ae9b421919c9bf9.zip
hdf5-a1701cb901f62ccaaa08ad2c1ae9b421919c9bf9.tar.gz
hdf5-a1701cb901f62ccaaa08ad2c1ae9b421919c9bf9.tar.bz2
[svn-r25429] Description:
Add code to ld_monitor test so that a keypress will stop it (instead of ctrl-c, which was messing up valgrind). Tested on: Mac OSX/64 10.9.3 (amazon) w/valgrind (h5committest not required on this branch)
Diffstat (limited to 'hl/test')
-rw-r--r--hl/test/ld_monitor.c60
1 files changed, 48 insertions, 12 deletions
diff --git a/hl/test/ld_monitor.c b/hl/test/ld_monitor.c
index 7b90715..cc17b8c 100644
--- a/hl/test/ld_monitor.c
+++ b/hl/test/ld_monitor.c
@@ -4,6 +4,43 @@
#include <assert.h>
#include <stdlib.h>
#include <unistd.h>
+#include <termios.h>
+#include <fcntl.h>
+
+static void set_mode(int want_key)
+{
+ static struct termios old_val, new_val;
+
+ if (!want_key) {
+ HDtcsetattr(STDIN_FILENO, TCSANOW, &old_val);
+ return;
+ }
+
+ HDtcgetattr(STDIN_FILENO, &old_val);
+ new_val = old_val;
+ new_val.c_lflag &= (tcflag_t)~(ICANON | ECHO);
+ HDtcsetattr(STDIN_FILENO, TCSANOW, &new_val);
+}
+
+static int get_key(void)
+{
+ int c = 0;
+ struct timeval tv;
+ fd_set fs;
+
+ tv.tv_sec = 0;
+ tv.tv_usec = 0;
+
+ FD_ZERO(&fs);
+ FD_SET(STDIN_FILENO, &fs);
+ HDselect(STDIN_FILENO + 1, &fs, 0, 0, &tv);
+
+ if (FD_ISSET(STDIN_FILENO, &fs)) {
+ c = HDgetchar();
+ set_mode(0);
+ }
+ return c;
+}
#define TEST_BUF_SIZE 100
@@ -17,7 +54,7 @@
* retrieve the appended data and print them
*/
static int
-monitor_dset(const char *fname, char *dname)
+monitor_dset(const char *fname, const char *dname)
{
hid_t fid; /* dataset id */
hid_t did; /* dataset id */
@@ -56,6 +93,9 @@ monitor_dset(const char *fname, char *dname)
goto done;
}
+ /* Monitor for keypresses */
+ set_mode(1);
+
/* Monitor the dataset for changes */
while(1) {
@@ -102,11 +142,15 @@ monitor_dset(const char *fname, char *dname)
/* Flush the output to stdout */
HDfflush(stdout);
/* Update the dimension sizes */
- HDmemcpy(prev_dims, cur_dims, ndims * sizeof(hsize_t));
+ HDmemcpy(prev_dims, cur_dims, (size_t)ndims * sizeof(hsize_t));
}
/* Sleep before next monitor */
sleep(1);
+
+ /* Check for keypress */
+ if(get_key())
+ break;
} /* end while */
done:
@@ -123,26 +167,18 @@ done:
int
main(int argc, const char *argv[])
{
- char *dname = NULL; /* dataset name */
- char *fname = NULL; /* file name */
-
if(argc != 3) {
HDfprintf(stderr, "Should have file name and dataset name to be monitored...\n");
goto done;
}
- /* Get the file name and dataset name to be extended */
- fname = strdup(argv[1]);
- dname = strdup(argv[2]);
-
/* only integer dataset */
- if(monitor_dset(fname, dname) < 0)
+ if(monitor_dset(argv[1], argv[2]) < 0)
goto done;
exit(EXIT_SUCCESS);
done:
- if(dname) free(dname);
- if(fname) free(fname);
exit(EXIT_FAILURE);
}
+