From a0e84f62def6276f38e518a2724d9f7ac4daa9ad Mon Sep 17 00:00:00 2001 From: Peter Hillman Date: Thu, 13 Feb 2020 11:45:17 +1300 Subject: [PATCH] add help and options information IlmImfTest and IlmImfFuzzTest Signed-off-by: Peter Hillman --- OpenEXR/IlmImfFuzzTest/main.cpp | 54 ++++++++++++++++-- OpenEXR/IlmImfTest/main.cpp | 99 +++++++++++++++++++++++++++------ 2 files changed, 132 insertions(+), 21 deletions(-) diff --git a/OpenEXR/IlmImfFuzzTest/main.cpp b/OpenEXR/IlmImfFuzzTest/main.cpp index 255b777056..19ad55efc2 100644 --- a/OpenEXR/IlmImfFuzzTest/main.cpp +++ b/OpenEXR/IlmImfFuzzTest/main.cpp @@ -46,36 +46,82 @@ #include #include +#include #include +#include #ifdef OPENEXR_IMF_HAVE_LINUX_PROCFS #include #include #endif -#define TEST(x) if (argc < 2 || !strcmp (argv[1], #x)) x(argc==3 ? argv[2] : nullptr); + +using std::set; +using std::string; +using std::cout; +using std::endl; + +#define TEST(x) if (helpMode) tests.insert(string(#x)); else if (argc < 2 || !strcmp (argv[1], #x)) x(argc==3 ? argv[2] : nullptr); int main (int argc, char *argv[]) { + bool helpMode = false; + if( argc==2 && (strcmp(argv[1],"--help")==0 || strcmp(argv[1],"-h")==0)) + { + helpMode = true; + } + set tests; + + TEST (testFuzzScanLines); TEST (testFuzzTiles); TEST (testFuzzDeepScanLines); TEST (testFuzzDeepTiles); - + + + if(helpMode) + { + cout << "IlmImfFuzzTest tests how resilient the IlmImf library is with\n" + "respect to broken input files: the program first damages\n" + "OpenEXR files by partially overwriting them with random data;\n" + "then it tries to read the damaged files. If all goes well,\n" + "then the program doesn't crash.\n"; + cout << "\n"; + cout << "If IlmImfFuzzTest does crash, it will leave a file in the current\n" + "directory, or /var/tmp. Running 'IlmImfFuzzTest test file' will\n" + "usually quickly reproduce the issue by attempting to reload the file,\n" + "(without running the normal tests) and is useful for debugging\n" + "the exact cause of the crash or confirming a bug is fixed.\n"; + cout << "\n"; + cout << "usage:\n"; + cout << " IlmImfFuzzTest : with no arguments, run all tests\n"; + cout << " IlmImfFuzzTest TEST : run specific TEST only\n"; + cout << " IlmImfFuzzTest TEST file : try to read 'file' with given TEST\n"; + cout << "\n"; + cout << "TEST can be one of the following:\n"; + for ( auto i = tests.begin() ; i!= tests.end() ; ++i ) + { + cout << ' ' << *i << endl; + } + + } + else + { + #ifdef OPENEXR_IMF_HAVE_LINUX_PROCFS // // Allow the user to check for file descriptor leaks // - std::cout << "open file descriptors:" << std::endl; + cout << "open file descriptors:" << endl; std::stringstream ss; ss << "ls -lG /proc/" << getpid() << "/fd"; system (ss.str().c_str()); #endif - + } return 0; } diff --git a/OpenEXR/IlmImfTest/main.cpp b/OpenEXR/IlmImfTest/main.cpp index 26d1ccf9e5..3245fc4812 100644 --- a/OpenEXR/IlmImfTest/main.cpp +++ b/OpenEXR/IlmImfTest/main.cpp @@ -107,6 +107,8 @@ #include #include +#include + #ifdef _WIN32 # include #else @@ -118,22 +120,23 @@ using namespace std; #define TEST_STRING(x) #x #define TEST(x,y) \ - if (argc < 2 || (!strcmp (argv[1], TEST_STRING(x)) || !strcmp (argv[1], y))) \ + if (helpMode)\ + {\ + tests.insert(string(TEST_STRING(x)));\ + suites.insert(string(y));\ + }\ + else if (argc < 2 || (!strcmp (argv[1], TEST_STRING(x)) || !strcmp (argv[1], y))) \ { \ cout << "\n=======\nRunning " << TEST_STRING(x) < 4095) { cerr << "Cannot retrieve temporary directory" << endl; - return 1; + exit(1); } tempDir = tmpbuf; // windows does this automatically @@ -168,10 +171,37 @@ main (int argc, char *argv[]) { std::cerr << "ERROR -- mkdir(" << tempDir << ") failed: " "errno = " << errno << std::endl; - return 1; + exit(1); } } + return tempDir; + +} + +int +main (int argc, char *argv[]) +{ + // Create temporary files in a uniquely named private temporary + // subdirectory of IMF_TMP_DIR to avoid colliding with other + // running instances of this program. + + std::string tempDir; + + bool helpMode = false; + if( argc==2 && (strcmp(argv[1],"--help")==0 || strcmp(argv[1],"-h")==0)) + { + helpMode = true; + } + set tests; + set suites; + + + if ( !helpMode ) + { + tempDir = makeTempDir(); + } + TEST (testMagic, "core"); TEST (testXdr, "core"); TEST (testHuf, "core"); @@ -235,8 +265,43 @@ main (int argc, char *argv[]) #endif - std::cout << "removing temp dir " << tempDir << std::endl; - rmdir (tempDir.c_str()); + if ( helpMode ) + { + cout << "IlmImfTest runs a series of tests to confirm\n" + "correct behavior of the IlmImf OpenEXR library.\n" + "If all is correct, IlmImfTest will complete without\n" + "crashing or leaking memory.\n"; + cout << "\n"; + cout << "If a test fails, an individual test can be re-run, avoiding\n" + "the wait for previous tests to complete. This allows easier debugging\n" + "of the failure.\n"; + cout << "\n"; + cout << "A 'suite' of tests can also be run, to allow a subset of\n" + << "tests to run. This is useful as an initial confirmation\n" + << "that a modification to the library has not introduced an error.\n" + << "Suites can be run in parallel for speed. Every test is in one suite.\n"; + cout << "\n"; + cout << "usage:\n" + << "IlmImfTest : with no arguments, run all tests\n" + << "IlmImfTest TEST : run only specific test, then quit\n" + << "IlmImfTest SUITE : run all the tests in the given SUITE\n"; + cout << "\n"; + cout << "available TESTs:\n"; + for ( auto i = tests.begin() ; i!= tests.end() ; ++i) + { + cout << ' ' << *i << endl; + } + cout << "\n"; + cout << "available SUITEs:\n"; + for ( auto i = suites.begin() ; i!= suites.end() ; ++i ) + { + cout << ' ' << *i << endl; + } + } + else + { + cout << "removing temp dir " << tempDir << endl; + rmdir (tempDir.c_str()); #ifdef OPENEXR_IMF_HAVE_LINUX_PROCFS @@ -244,19 +309,19 @@ main (int argc, char *argv[]) // Allow the user to check for file descriptor leaks // - std::cout << "open file descriptors:" << std::endl; + cout << "open file descriptors:" << endl; - std::stringstream ss; + stringstream ss; ss << "ls -lG /proc/" << getpid() << "/fd"; if (system (ss.str().c_str()) == -1) { - std::cout << "failed to run ls\n"; + cout << "failed to run ls\n"; } - std::cout << std::endl; + cout << endl; #endif - + } return 0; }