diff --git a/README b/README index 9c3d31a..58b9c28 100644 --- a/README +++ b/README @@ -17,7 +17,7 @@ Testing with exactness composed of the following stages: A set of pre-recorded tests already resides under 'data/recording' folder. To record a test just issue the command: - exactness -r + exactness -r [-b BaseDir] [TestName1] [TestName2 ...] Example: exactness -r test_hover @@ -25,8 +25,13 @@ Testing with exactness composed of the following stages: The record file will be produced in the current-working-directory as: test_hover.rec + To save your recordings in any other directory, + pass the directory-name as base-dir: + exactness -r -b /home/username/my_recordings test_hover + In case you tried to run exactness with specific TestName - and nothing happens, this means you misspelled the test name. + getting "No test matching" Error. + This means you misspelled the test name. You may review test names as it appears in tsuite.c source file. NOTE: omitting the test name causes recording all tests one after another. @@ -34,7 +39,7 @@ Testing with exactness composed of the following stages: This rule applies to ALL proceeding stages as well. As widget test run you may press F2 at any point to set a screenshot. - (screenshot procduced in 'play' stage, set timing of screenshot here) + (screenshot produced in 'play' stage, set timing of screenshot here) However, don't do this while animation is ongoing or you get inconsistent PNG output each time test played. @@ -47,24 +52,41 @@ Testing with exactness composed of the following stages: To start you need to produce original screenshot set before code change. To do that just issue the command: - exactness -i TestName1 [TestName2 ...] + exactness -i [-b BaseDir] [TestName1] [TestName2 ...] This command will play the test (TestName.rec file) and place PNG files under 'orig' folders created in current-working-directory. You need to do this just once. Again, omitting the TestName will play and produce PNG files for all tests. - Example: exactness -i test_hover + (locate "test_hover.rec" in cwd) + This will produce PNG files such orig/test_hover_1.png + By default exactness looks for ".rec" files in current-working-directory + Use -b DirName to ask exactness to locate the ".rec" files + in a specific location. + + Example: + exactness -i -b ~/e17/exactness/data/recordings test_hover + (locate "test_hover.rec" in "~/e17/exactness/data/recordings") + + 3. Test playing, producing current state PNG files. After doing Test Initiation (2) and updating elementary code, you may run tests for current state of elm: - exactness -p [-d DestDir] TestName1 [TestName2 ...] + exactness -p [-b BaseDir] [-d DestDir] TestName1 [TestName2 ...] Omitting DestDir param will cause exactness place all PNG files under (default) folder named 'current'. + + You may put record-files at specific folder with -b (base dir) argument: + Example: + exactness -p -b ~/e17/exactness/data/recordings test_hover + + Play test_hover, find ".rec" file at "~/e17/exactness/data/recordings" + Write resulting PNG files at cwd/current (default) dir. 4. Comparing PNG files. This is the final stage of testing in which we compare output diff --git a/src/bin/tsuite.c b/src/bin/tsuite.c index 3e2f35b..6d3f676 100644 --- a/src/bin/tsuite.c +++ b/src/bin/tsuite.c @@ -7,6 +7,8 @@ #define IMAGE_FILENAME_EXT ".png" #include #include "tsuite_file_data.h" +#include +#include void test_3d(void); void test_actionslider(void); @@ -153,7 +155,7 @@ struct _Test_Item typedef struct _Test_Item Test_Item; static Tsuite_Data ts; -static char *recording = NULL; +static int recording = 0; static char *dest_dir = NULL; Eina_List * @@ -649,48 +651,87 @@ do_test(char *rec_dir, void (* func) (void)) vr_list = free_events(vr_list); } -static char * -_argument_get(char *name, int argc, char **argv, int *idx) -{ - int i = 1; - Eina_Bool found_name = EINA_FALSE; - while(i < argc) - { - *idx = i; - if (found_name) - return argv[i]; - - if (!strcmp(name, argv[i])) - { /* if this is the argument we looking for */ - if (!strcmp(name, "--record")) - return argv[i]; /* recording, This does not requires name */ - - if (!strcmp(name, "--destdir")) - found_name = EINA_TRUE; - - if (!strcmp(name, "--basedir")) - found_name = EINA_TRUE; - - if (!strcmp(name, "--tests")) - return argv[i]; /* This marks tests-args */ - } - - i++; - } - - *idx = (-1); - return NULL; -} - EAPI int elm_main(int argc, char **argv) { Eina_List *tests = NULL; Eina_Bool test_all; - char *tests_arg = NULL; char *rec_dir = NULL; int i, first_arg; + int opt_tests = 0; + Eina_List *opt_destdir = NULL; + Eina_List *opt_basedir = NULL; + + static const Ecore_Getopt optdesc = { + "Test_suite", + NULL, + "0.0", + "(C) 2011 Enlightenment", + "Enlightenment", + "The Elementary auto test suite", + 0, + { + ECORE_GETOPT_COUNT('r', "record", "Recording mode"), + ECORE_GETOPT_APPEND_METAVAR('d',"destdir","Destir for PNG files", + "STRING", ECORE_GETOPT_TYPE_STR), + ECORE_GETOPT_APPEND_METAVAR('b',"basedir","Directory of rec files", + "STRING", ECORE_GETOPT_TYPE_STR), + ECORE_GETOPT_COUNT('t', "tests", "Tests names marker"), + ECORE_GETOPT_SENTINEL + } + }; + + Ecore_Getopt_Value values[] = { + ECORE_GETOPT_VALUE_INT(recording), + ECORE_GETOPT_VALUE_LIST(opt_destdir), + ECORE_GETOPT_VALUE_LIST(opt_basedir), + ECORE_GETOPT_VALUE_INT(opt_tests), + ECORE_GETOPT_VALUE_NONE + }; + +#ifdef DEBUG_TSUITE + printf("Got args:\n"); + for(i = 0; i < argc; i++) + printf("%d=<%s>\n", i, (char *) argv[i]); +#endif + ecore_init(); + + if (ecore_getopt_parse(&optdesc, values, argc, argv) < 0) + { + printf("Argument parsing failed\n"); + exit(1); + } + +#ifdef DEBUG_TSUITE + printf("Values from command line:\n"); + printf("recording=<%d>\nopt_tests=<%d>\n", recording, opt_tests); + if (opt_destdir) + printf("opt_destdir=<%s>\n", opt_destdir->data); + if (opt_basedir) + printf("opt_basedir=<%s>\n", opt_basedir->data); +#endif + + if (!opt_tests) + { /* This in case user runs mannualy and mistakes */ + printf ("Tests Marker (arg) missing.\n"); + exit(1); + } + + /* Find index of first-test name, for ALL first_arg = (argc-1) */ + for(first_arg = 1; first_arg < argc; first_arg++) + if (!strcmp(argv[first_arg], "--tests")) + break; + + first_arg++; /* First arg now is index of first test or == argc */ + +#ifdef DEBUG_TSUITE + if (first_arg == argc) + printf("TEST ALL: first_arg=<%d>\n", first_arg); + else + printf("test=<%s> first_arg=<%d>\n", argv[first_arg], first_arg); +#endif + elm_policy_set(ELM_POLICY_QUIT, ELM_POLICY_QUIT_LAST_WINDOW_CLOSED); /* tell elm about our app so it can figure out where to get files */ @@ -698,16 +739,12 @@ elm_main(int argc, char **argv) elm_app_compile_data_dir_set(PACKAGE_DATA_DIR); elm_app_info_set(elm_main, "elementary", "images/logo.png"); - recording = _argument_get("--record", argc, argv, &i); - dest_dir = _argument_get("--destdir", argc, argv, &i); - rec_dir = _argument_get("--basedir", argc, argv, &i); - tests_arg = _argument_get("--tests", argc, argv, &first_arg); + if (opt_destdir) + dest_dir = opt_destdir->data; + + if (opt_basedir) + rec_dir = opt_basedir->data; - if (!tests_arg) - { - printf ("No tests requested, exit.\n"); - return 0; - } /* if we got here, found test_arg, now find it's index */ if (recording) @@ -715,10 +752,10 @@ elm_main(int argc, char **argv) _init_recording_funcs(); } - first_arg++; /* First arg now is index of first test or == argc */ #ifdef DEBUG_TSUITE printf("argc=<%d> first_arg=<%d>\n", argc, first_arg); #endif + /* If no test specified in command line, set all */ test_all = (argc - first_arg) == 0; tests = _add_test(tests, "test_3d", test_3d, test_all); diff --git a/src/scripts/write.sh b/src/scripts/write.sh index b8677b0..c89438d 100755 --- a/src/scripts/write.sh +++ b/src/scripts/write.sh @@ -6,9 +6,9 @@ cat <<-ENDOFMESSAGE>exactness #!/usr/bin/env bash # tsuite_script.sh -i this makes new 'orig' folder -# tsuite_script.sh -i TestName1 [TestName2 ...] rewrite files for selcted tests in 'orig' folder -# tsuite_script.sh -r [TestName1 TestName2 ...] ; this means record [all tests or TestName additional arg] -# tsuite_script.sh -d FolderName -p [TestName1 TestName2 ...] this means play a record and put screenshots FolderName +# tsuite_script.sh -i -b [BaseDir] TestName1 [TestName2 ...] rewrite files for selcted tests in 'orig' folder +# tsuite_script.sh -r -b [BaseDir] [TestName1 TestName2 ...] ; this means record [all tests or TestName additional arg] +# tsuite_script.sh -b [BaseDir] -d FolderName -p [TestName1 TestName2 ...] this means play a record and put screenshots FolderName # tsuite_script.sh -d FolderName -c [TestName1 TestName2 ...] this means compare "orig" with screenshots in FolderName # When omitting DestDir we will use 'current' as default DestDir @@ -21,17 +21,20 @@ function DEBUG() do_help () { echo "Record tests to produce input-stream to play and set screenshot timing" echo "To record all tests:" -echo "\$0 -r" +echo "\$0 -r [-b BaseDir]" echo "To record specific tests:" -echo "\$0 -r TestName1 [TestName2 ...]" +echo "\$0 -r [-b BaseDir] TestName1 [TestName2 ...]" +echo "Use BaseDir arg to write record-files to specific folder." echo echo "Play tests to produce PNG files of screenshot defined while recording." echo "To play all tests:" -echo "\$0 -p d DestDir" +echo "\$0 -p [-b BaseDir] [-d DestDir]" echo "To play specific tests:" -echo "\$0 -p -d DestDir TestName1 [TestName2 ...]" -echo "To play and rewrite 'orig' dir, use init option for all test: \$0 -i" -echo "To play and rewrite 'orig' dir, use init option for selected tests: \$0 -i [TestName1 ...]" +echo "\$0 -p [-b BaseDir] [-d DestDir] TestName1 [TestName2 ...]" +echo "To play and rewrite 'orig' dir, use init option for all test: \$0 -i [-b BaseDir]" +echo "To play and rewrite 'orig' dir, use init option for selected tests: \$0 -i [-b BaseDir] [TestName1 ...]" +echo "Use BaseDir arg tell \$0 where record-files are found." +echo "Otherwise, \$0 will try to find it in cwd." echo echo "Run comprison to produce comp_*.png files" echo "To compare all tests:" @@ -40,7 +43,8 @@ echo "To compare specific tests:" echo "\$0 -c -d DestDir TestName1 [TestName2 ...]" echo echo "NOTE:" -echo "For all actions require DestDir, when omitting this param we use 'current' as default" +echo "For all actions require DestDir, when omitting this param we use 'current' as default." +echo "For all actions require using record-files, when omitting BaseDir param we use current-working-directory to locate record-files." } do_record () { @@ -52,11 +56,17 @@ DEBUG echo do_record "\$*" OUR_LIBPATH="$1" +local _dest='--destdir='"\$_dest_dir" +if [ -z "\$_dest_dir" ] +then + local _dest= +fi + if [ -z "\$*" ] then - LD_PRELOAD=\${OUR_LIBPATH}/libexactness.so exactness_raw --basedir "\$_base_dir" --record --tests + LD_PRELOAD=\${OUR_LIBPATH}/libexactness.so exactness_raw \$_dest --basedir "\$_base_dir" --record --tests else - LD_PRELOAD=\${OUR_LIBPATH}/libexactness.so exactness_raw --basedir "\$_base_dir" --record --tests \$* + LD_PRELOAD=\${OUR_LIBPATH}/libexactness.so exactness_raw \$_dest --basedir "\$_base_dir" --record --tests \$* fi return 0 } @@ -75,7 +85,7 @@ if [ -z "\$*" ] then # Clear all files before producing all PNG files. rm -rf "\$_dest_dir" &> /dev/null - mkdir -p "\$_dest_dir" + mkdir -p "\$_dest_dir" &> /dev/null ELM_ENGINE="buffer" exactness_raw --destdir "\$_dest_dir" --basedir "\$_base_dir" --tests else if [ -e "\$_dest_dir" ] @@ -87,7 +97,7 @@ else done else # Create dest dir - mkdir -p "\$_dest_dir" + mkdir -p "\$_dest_dir" &> /dev/null fi ELM_ENGINE="buffer" exactness_raw --destdir "\$_dest_dir" --basedir "\$_base_dir" --tests \$* @@ -152,6 +162,8 @@ process_compare () { do_compare () { DEBUG printf "do_compare()\n" +DEBUG echo orig dir: "\$_orig_dir" +DEBUG echo dest dir: "\$_dest_dir" # This will compare files in 'orig' folder with files in _dest_dir if [ \$comp_unavail -ne 0 ] then @@ -179,7 +191,7 @@ if [ -z "\$*" ] # No test names given, compare all then rm -f "\$_dest_dir"/comp_* &> /dev/null - files_list=( \`ls "\$_dest_dir"/test_*\` ) + files_list=( \`ls "\$_dest_dir"/test_*.png\` ) process_compare "\${files_list[@]}" else for test_name in \$*