From 1ea153590eb705528aa8cdf33a034b97c6cd57ba Mon Sep 17 00:00:00 2001 From: phk Date: Wed, 10 Mar 2004 20:30:19 +0000 Subject: Add an option to write collected data to file in binary format. This is very useful for collecting test-data for trial runs. --- tools/test/ppsapi/ppsapitest.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'tools/test/ppsapi') diff --git a/tools/test/ppsapi/ppsapitest.c b/tools/test/ppsapi/ppsapitest.c index b80c853..78e7382 100644 --- a/tools/test/ppsapi/ppsapitest.c +++ b/tools/test/ppsapi/ppsapitest.c @@ -31,14 +31,17 @@ int main(int argc, char **argv) { int fd; + FILE *fdo; pps_info_t pi; pps_params_t pp; pps_handle_t ph; int i, mode; u_int olda, oldc; struct timespec to; + char const *ofn; - while ((i = getopt(argc, argv, "aAbBcCeuv")) != -1) { + ofn = NULL; + while ((i = getopt(argc, argv, "aAbBcCeo:uv")) != -1) { switch (i) { case 'a': aflag = 1; break; case 'A': Aflag = 1; break; @@ -47,6 +50,7 @@ main(int argc, char **argv) case 'c': cflag = 1; break; case 'C': Cflag = 1; break; case 'e': eflag = 1; break; + case 'o': ofn = optarg; break; case 'u': uflag = 1; break; case 'v': vflag = 1; break; case '?': @@ -56,6 +60,13 @@ main(int argc, char **argv) exit (1); } } + if (ofn != NULL) { + fdo = fopen(ofn, "w"); + if (fdo == NULL) + err(1, "Cannot open %s", ofn); + } else { + fdo = NULL; + } argc -= optind; argv += optind; if (argc > 0) { @@ -163,6 +174,12 @@ main(int argc, char **argv) usleep(10000); continue; } + if (fdo != NULL) { + if (fwrite(&pi, sizeof pi, 1, fdo) != 1) + err(1, "Write error on %s", ofn); + if (uflag) + fflush(fdo); + } Chew(&pi.assert_timestamp, &pi.clear_timestamp, pi.assert_sequence, pi.clear_sequence); olda = pi.assert_sequence; -- cgit v1.1