[llvm-commits] [test-suite] r152985 - /test-suite/trunk/tools/timeit.c
Daniel Dunbar
daniel at zuster.org
Sat Mar 17 09:37:52 PDT 2012
Author: ddunbar
Date: Sat Mar 17 11:37:51 2012
New Revision: 152985
URL: http://llvm.org/viewvc/llvm-project?rev=152985&view=rev
Log:
[test-suite] tools/timeit: Add support for passing a directory to execute the
target in.
Modified:
test-suite/trunk/tools/timeit.c
Modified: test-suite/trunk/tools/timeit.c
URL: http://llvm.org/viewvc/llvm-project/test-suite/trunk/tools/timeit.c?rev=152985&r1=152984&r2=152985&view=diff
==============================================================================
--- test-suite/trunk/tools/timeit.c (original)
+++ test-suite/trunk/tools/timeit.c Sat Mar 17 11:37:51 2012
@@ -36,6 +36,10 @@
/* \brief If non-zero, the PID of the process being monitored. */
static pid_t g_monitored_pid = 0;
+/* \brief If non-zero, the path to attempt to chdir() to before executing the
+ * target. */
+static const char *g_target_exec_directory = 0;
+
static double sample_wall_time(void) {
struct timeval t;
gettimeofday(&t, NULL);
@@ -133,6 +137,14 @@
*/
setpgrp();
+ /* Honor the desired target execute directory. */
+ if (g_target_exec_directory) {
+ if (chdir(g_target_exec_directory) < 0) {
+ perror("chdir");
+ return;
+ }
+ }
+
execv(argv[0], argv);
perror("execv");
}
@@ -184,6 +196,8 @@
"Report time in /usr/bin/time POSIX format.\n");
fprintf(stderr, " %-20s %s", "{-t,--timeout} <N>",
"Execute the subprocess with a timeout of N seconds.\n");
+ fprintf(stderr, " %-20s %s", "{-c,--chdir} <PATH>",
+ "Execute the subprocess in the given working directory.\n");
_exit(is_error);
}
@@ -208,13 +222,22 @@
if (streq(arg, "-t") || streq(arg, "--timeout")) {
if (i + 1 == argc) {
- fprintf(stderr, "error: -t argument requires an option\n");
+ fprintf(stderr, "error: %s argument requires an option\n", arg);
usage(/*is_error=*/1);
}
g_timeout_in_seconds = atoi(argv[++i]);
continue;
}
+ if (streq(arg, "-c") || streq(arg, "--chdir")) {
+ if (i + 1 == argc) {
+ fprintf(stderr, "error: %s argument requires an option\n", arg);
+ usage(/*is_error=*/1);
+ }
+ g_target_exec_directory = argv[++i];
+ continue;
+ }
+
fprintf(stderr, "error: invalid argument '%s'\n", argv[i]);
usage(/*is_error=*/1);
}
More information about the llvm-commits
mailing list