[Darshan-commits] [Git][darshan/darshan][dev-stdio] get fscanf working

Philip Carns xgitlab at cels.anl.gov
Fri May 27 16:17:38 CDT 2016


Philip Carns pushed to branch dev-stdio at darshan / darshan


Commits:
9cd5e5c0 by Phil Carns at 2016-05-27T17:16:33-04:00
get fscanf working

- includes regression test for fprintf and fscanf
- apparently you have to wrap __isoc99_fscanf instead of fscanf
  sometimes

- - - - -


4 changed files:

- darshan-runtime/lib/darshan-stdio.c
- darshan-runtime/share/ld-opts/darshan-stdio-ld-opts
- + darshan-test/regression/test-cases/fprintf-fscanf-test.sh
- + darshan-test/regression/test-cases/src/fprintf-fscanf-test.c


Changes:

=====================================
darshan-runtime/lib/darshan-stdio.c
=====================================
--- a/darshan-runtime/lib/darshan-stdio.c
+++ b/darshan-runtime/lib/darshan-stdio.c
@@ -6,8 +6,6 @@
 
 /* TODO list (general) for this module:
  * - add stdio page to darshan-job-summary
- * - add regression test cases for all functions captured here
- *   - especially the scanf and printf variants with variable arguments
  * - figure out what to do about posix module compatibility
  *   - remove stdio counters in POSIX or keep and set to -1?
  *   - affected counters in posix module:
@@ -117,6 +115,7 @@ DARSHAN_FORWARD_DECL(getw, int, (FILE *stream));
 DARSHAN_FORWARD_DECL(_IO_getc, int, (FILE *stream));
 DARSHAN_FORWARD_DECL(_IO_putc, int, (int, FILE *stream));
 DARSHAN_FORWARD_DECL(fscanf, int, (FILE *stream, const char *format, ...));
+DARSHAN_FORWARD_DECL(__isoc99_fscanf, int, (FILE *stream, const char *format, ...));
 DARSHAN_FORWARD_DECL(vfscanf, int, (FILE *stream, const char *format, va_list ap));
 DARSHAN_FORWARD_DECL(fgets, char*, (char *s, int size, FILE *stream));
 DARSHAN_FORWARD_DECL(fseek, int, (FILE *stream, long offset, int whence));
@@ -672,6 +671,38 @@ size_t DARSHAN_DECL(getw)(FILE *stream)
     return(ret);
 }
 
+/* NOTE: some glibc versions use __isoc99_fscanf as the underlying symbol
+ * rather than fscanf
+ */
+int DARSHAN_DECL(__isoc99_fscanf)(FILE *stream, const char *format, ...)
+{
+    int ret;
+    double tm1, tm2;
+    va_list ap;
+    long start_off, end_off;
+
+    MAP_OR_FAIL(vfscanf);
+
+    tm1 = darshan_core_wtime();
+    /* NOTE: we intentionally switch to vfscanf here to handle the variable
+     * length arguments.
+     */
+    start_off = ftell(stream);
+    va_start(ap, format);
+    ret = __real_vfscanf(stream, format, ap);
+    va_end(ap);
+    end_off = ftell(stream);
+    tm2 = darshan_core_wtime();
+
+    STDIO_LOCK();
+    stdio_runtime_initialize();
+    if(ret != 0)
+        STDIO_RECORD_READ(stream, (end_off-start_off), tm1, tm2);
+    STDIO_UNLOCK();
+
+    return(ret);
+}
+
 
 int DARSHAN_DECL(fscanf)(FILE *stream, const char *format, ...)
 {


=====================================
darshan-runtime/share/ld-opts/darshan-stdio-ld-opts
=====================================
--- a/darshan-runtime/share/ld-opts/darshan-stdio-ld-opts
+++ b/darshan-runtime/share/ld-opts/darshan-stdio-ld-opts
@@ -26,3 +26,4 @@
 --wrap=fsetpos
 --wrap=fsetpos64
 --wrap=rewind
+--wrap=__isoc99_fscanf


=====================================
darshan-test/regression/test-cases/fprintf-fscanf-test.sh
=====================================
--- /dev/null
+++ b/darshan-test/regression/test-cases/fprintf-fscanf-test.sh
@@ -0,0 +1,53 @@
+#!/bin/bash
+
+PROG=fprintf-fscanf-test
+
+# set log file path; remove previous log if present
+export DARSHAN_LOGFILE=$DARSHAN_TMP/${PROG}.darshan
+rm -f ${DARSHAN_LOGFILE}
+
+# compile
+$DARSHAN_CC $DARSHAN_TESTDIR/test-cases/src/${PROG}.c -o $DARSHAN_TMP/${PROG}
+if [ $? -ne 0 ]; then
+    echo "Error: failed to compile ${PROG}" 1>&2
+    exit 1
+fi
+
+# execute
+$DARSHAN_RUNJOB $DARSHAN_TMP/${PROG} -f $DARSHAN_TMP/${PROG}.tmp.dat
+if [ $? -ne 0 ]; then
+    echo "Error: failed to execute ${PROG}" 1>&2
+    exit 1
+fi
+
+# parse log
+$DARSHAN_PATH/bin/darshan-parser $DARSHAN_LOGFILE > $DARSHAN_TMP/${PROG}.darshan.txt
+if [ $? -ne 0 ]; then
+    echo "Error: failed to parse ${DARSHAN_LOGFILE}" 1>&2
+    exit 1
+fi
+
+# check results
+
+STDIO_OPENS=`grep STDIO_OPENS $DARSHAN_TMP/${PROG}.darshan.txt | cut -f 5`
+if [ ! "$STDIO_OPENS" -eq 4 ]; then
+    echo "Error: STDIO open count of $STDIO_OPENS is incorrect" 1>&2
+    exit 1
+fi
+
+# this will check fprintf counting
+STDIO_BYTES_WRITTEN=`grep STDIO_BYTES_WRITTEN $DARSHAN_TMP/${PROG}.darshan.txt | cut -f 5`
+if [ ! "$STDIO_BYTES_WRITTEN" -eq 15 ]; then
+    echo "Error: STDIO bytes written count of $STDIO_BYTES_WRITTEN is incorrect" 1>&2
+    exit 1
+fi
+
+# this will check fscanf counting
+STDIO_BYTES_READ=`grep STDIO_BYTES_READ $DARSHAN_TMP/${PROG}.darshan.txt | cut -f 5`
+if [ ! "$STDIO_BYTES_READ" -eq 15 ]; then
+    echo "Error: STDIO bytes read count of $STDIO_BYTES_READ is incorrect" 1>&2
+    exit 1
+fi
+
+
+exit 0


=====================================
darshan-test/regression/test-cases/src/fprintf-fscanf-test.c
=====================================
--- /dev/null
+++ b/darshan-test/regression/test-cases/src/fprintf-fscanf-test.c
@@ -0,0 +1,106 @@
+/*
+ * (C) 1995-2001 Clemson University and Argonne National Laboratory.
+ *
+ * See COPYING in top-level directory.
+ */
+
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <string.h>
+#include <sys/time.h>
+#include <mpi.h>
+#include <errno.h>
+#include <getopt.h>
+
+/* DEFAULT VALUES FOR OPTIONS */
+static char    opt_file[256] = "test-fprintf-fscanf.out";
+
+/* function prototypes */
+static int parse_args(int argc, char **argv);
+static void usage(void);
+
+/* global vars */
+static int mynod = 0;
+static int nprocs = 1;
+
+int main(int argc, char **argv)
+{
+   int namelen;
+   char processor_name[MPI_MAX_PROCESSOR_NAME];
+   FILE *file;
+   char buffer[128] = {0};
+   int number = 0;
+
+   /* startup MPI and determine the rank of this process */
+   MPI_Init(&argc,&argv);
+   MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
+   MPI_Comm_rank(MPI_COMM_WORLD, &mynod);
+   MPI_Get_processor_name(processor_name, &namelen); 
+   
+   /* parse the command line arguments */
+   parse_args(argc, argv);
+
+   if (mynod == 0) printf("# Using stdio calls.\n");
+
+   file = fopen(opt_file, "w+");
+   if(!file)
+   {
+      perror("fopen");
+      return(-1);
+   }
+
+   if(mynod == 0)
+   {
+      fprintf(file, "a number: %d", 12345);
+      fseek(file, 0, SEEK_SET);
+      fscanf(file, "a number: %d", &number);
+   }
+
+   fclose(file);
+
+   MPI_Finalize();
+   return(0);
+}
+
+static int parse_args(int argc, char **argv)
+{
+   int c;
+   
+   while ((c = getopt(argc, argv, "f:")) != EOF) {
+      switch (c) {
+         case 'f': /* filename */
+            strncpy(opt_file, optarg, 255);
+            break;
+         case '?': /* unknown */
+            if (mynod == 0)
+                usage();
+            exit(1);
+         default:
+            break;
+      }
+   }
+   return(0);
+}
+
+static void usage(void)
+{
+    printf("Usage: stdio-test [<OPTIONS>...]\n");
+    printf("\n<OPTIONS> is one of\n");
+    printf(" -f       filename [default: /foo/test.out]\n");
+    printf(" -h       print this help\n");
+}
+
+/*
+ * Local variables:
+ *  c-indent-level: 3
+ *  c-basic-offset: 3
+ *  tab-width: 3
+ *
+ * vim: ts=3
+ * End:
+ */ 
+
+



View it on GitLab: https://xgitlab.cels.anl.gov/darshan/darshan/commit/9cd5e5c01a2e346b10a4479340e6a2c73efa44cd
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mcs.anl.gov/pipermail/darshan-commits/attachments/20160527/2d089eaf/attachment-0001.html>


More information about the Darshan-commits mailing list