From: Carl Worth Date: Sat, 12 Nov 2011 00:58:05 +0000 (-0800) Subject: Add "apitrace diff-images" command X-Git-Url: https://git.cworth.org/git?p=apitrace;a=commitdiff_plain;h=1cbf9182d7158859160ba8ef8405fad7390644b3 Add "apitrace diff-images" command Which simply calls out to the existing snapdiff.py script, (notably, it also passes "apitrace diff-images --help" to snapdiff.py as well). --- diff --git a/cli/CMakeLists.txt b/cli/CMakeLists.txt index 36a9d26..5196467 100644 --- a/cli/CMakeLists.txt +++ b/cli/CMakeLists.txt @@ -2,6 +2,7 @@ add_executable (apitrace cli_main.cpp cli_diff.cpp cli_diff_state.cpp + cli_diff_images.cpp cli_dump.cpp cli_trace.cpp ) diff --git a/cli/cli.hpp b/cli/cli.hpp index edada51..1461b4d 100644 --- a/cli/cli.hpp +++ b/cli/cli.hpp @@ -42,6 +42,7 @@ struct Command { extern const Command diff_command; extern const Command diff_state_command; +extern const Command diff_images_command; extern const Command dump_command; extern const Command trace_command; diff --git a/cli/cli_diff_images.cpp b/cli/cli_diff_images.cpp new file mode 100644 index 0000000..390174c --- /dev/null +++ b/cli/cli_diff_images.cpp @@ -0,0 +1,100 @@ +/********************************************************************* + * + * Copyright 2011 Intel Corporation + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person + * obtaining a copy of this software and associated documentation + * files (the "Software"), to deal in the Software without + * restriction, including without limitation the rights to use, copy, + * modify, merge, publish, distribute, sublicense, and/or sell copies + * of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be + * included in all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + *********************************************************************/ + +#include +#include + +#include "cli.hpp" +#include "os_path.hpp" +#include "trace_tools.hpp" + +static const char *synopsis = "Identify differences between two image dumps."; + +static os::Path +find_command(void) +{ +#define CLI_DIFF_IMAGES_COMMAND "snapdiff.py" + + return trace::findFile("scripts/" CLI_DIFF_IMAGES_COMMAND, + APITRACE_SCRIPTS_INSTALL_DIR "/" CLI_DIFF_IMAGES_COMMAND, + true); + +} + +static void +usage(void) +{ + char *args[3]; + + os::Path command = find_command(); + + args[0] = (char *) command.str(); + args[1] = (char *) "--help"; + args[2] = NULL; + +#ifdef _WIN32 + std::cerr << "The 'apitrace diff-images' command is not yet supported on this O/S.\n"; +#else + execv(command.str(), args); +#endif + + std::cerr << "Error: Failed to execute " << args[0] << "\n"; +} + +static int +command(int argc, char *argv[]) +{ + int i; + char **args = new char* [argc+2]; + + os::Path command = find_command(); + + args[0] = (char *) command.str(); + + for (i = 0; i < argc; i++) { + args[i+1] = argv[i]; + } + + args[i+1] = NULL; + +#ifdef _WIN32 + std::cerr << "The 'apitrace diff-images' command is not yet supported on this O/S.\n"; +#else + execv(command.str(), args); +#endif + + std::cerr << "Error: Failed to execute " << args[0] << "\n"; + + return 1; +} + +const Command diff_images_command = { + "diff-images", + synopsis, + usage, + command +}; diff --git a/cli/cli_main.cpp b/cli/cli_main.cpp index d996abd..fb4f88f 100644 --- a/cli/cli_main.cpp +++ b/cli/cli_main.cpp @@ -68,6 +68,7 @@ const Command help_command = { static const Command * commands[] = { &diff_command, &diff_state_command, + &diff_images_command, &dump_command, &trace_command, &help_command