*** Settings ***
Library           OperatingSystem

*** Variables ***
${kcov}           %{WORKSPACE}/build/src/kcov
${out}            %{WORKSPACE}/kcov
${kcov_path}      %{WORKSPACE}
${xml_lookup}     ${kcov_path}/tests/tools/lookup-xml-node.py

*** Test Cases ***
too-few-arguments
    ${rc}=    Run and return RC    ${kcov} --include-pattern=kcov --exclude-pattern=helper.cc,library.cc,html-data-files.cc /tmp/kcov-kcov ${kcov} ${out}
    Should be equal as integers    ${rc}    1

wrong-arguments
    ${rc}=    Run and return RC    ${kcov} --include-pattern=kcov --exclude-pattern=helper.cc,library.cc,html-data-files.cc /tmp/kcov-kcov ${kcov} --abcd=efg ${out} tests-stripped
    Should be equal as integers    ${rc}    1

illegal-insn
    ${output}=    Run    ${kcov} ${out} ./illegal-insn
    Should Contain    ${output}    Illegal instructions are

unit test
    ${rc}=    Run and return RC    ${kcov} --include-pattern=kcov --exclude-pattern=helper.cc,library.cc,html-data-files.cc /tmp/kcov-kcov ../unit-tests/ut

fork-no-wait
    Run                            rm -rf ${out}/fork_no_wait
    ${no_kcov_rc}=    Run and return RC    ./fork_no_wait
    ${rc}=    Run and return RC    ${kcov} ${out} ./fork_no_wait
    Should be equal as integers    ${rc}    ${no_kcov_rc}
    ${output}=    Run    ${xml_lookup} ${out}/fork_no_wait/cobertura.xml fork_no_wait_c 20
    Should Contain    ${output}    1
    ${output}=    Run    ${xml_lookup} ${out}/fork_no_wait/cobertura.xml fork_no_wait_c 22
    Should Contain    ${output}    1
    ${output}=    Run    ${xml_lookup} ${out}/fork_no_wait/cobertura.xml fork_no_wait_c 24
    Should Contain    ${output}    1

fork
    Run                            rm -rf ${out}/fork
    ${no_kcov_rc}=    Run and return RC    ./fork
    ${rc}=    Run and return RC    ${kcov} ${out} ./fork
    Should be equal as integers    ${rc}    ${no_kcov_rc}
    ${output}=    Run    ${xml_lookup} ${out}/fork/cobertura.xml fork_c 21
    Should Contain    ${output}    0
    ${output}=    Run    ${xml_lookup} ${out}/fork/cobertura.xml fork_c 26
    Should Contain    ${output}    1
    ${output}=    Run    ${xml_lookup} ${out}/fork/cobertura.xml fork_c 34
    Should Contain    ${output}    1
    ${output}=    Run    ${xml_lookup} ${out}/fork/cobertura.xml fork_c 37
    Should Contain    ${output}    1
    ${output}=    Run    ${xml_lookup} ${out}/fork/cobertura.xml fork_c 46
    Should Contain    ${output}    1

fork-32
    Run                            rm -rf ${out}/fork-32
    ${no_kcov_rc}=    Run and return RC    ./fork-32
    ${rc}=    Run and return RC    ${kcov} ${out} ./fork-32
    Should be equal as integers    ${rc}    ${no_kcov_rc}
    ${output}=    Run    ${xml_lookup} ${out}/fork-32/cobertura.xml fork_c 21
    Should Contain    ${output}    0
    ${output}=    Run    ${xml_lookup} ${out}/fork-32/cobertura.xml fork_c 26
    Should Contain    ${output}    1
    ${output}=    Run    ${xml_lookup} ${out}/fork-32/cobertura.xml fork_c 34
    Should Contain    ${output}    1
    ${output}=    Run    ${xml_lookup} ${out}/fork-32/cobertura.xml fork_c 37
    Should Contain    ${output}    1
    ${output}=    Run    ${xml_lookup} ${out}/fork-32/cobertura.xml fork_c 46
    Should Contain    ${output}    1

shared-library
	[Tags]	not_ready
    Run                            rm -rf ${out}/shared_library_test
    ${no_kcov_rc}=    Run and return RC    ./shared_library_test
    ${rc}=    Run and return RC    ${kcov} ${out} ./shared_library_test
    Should be equal as integers    ${rc}    ${no_kcov_rc}
    ${output}=    Run    ${xml_lookup} ${out}/shared_library_test/cobertura.xml main_c 9
    Should Contain    ${output}    1
    ${output}=    Run    ${xml_lookup} ${out}/shared_library_test/cobertura.xml solib_c 5
    Should Contain    ${output}    1

shared-library-skip
    Run                            rm -rf ${out}/shared_library_test
    ${rc}=    Run and return RC    ${kcov} --skip-solibs ${out} ./shared_library_test
    ${output}=    Run    ${xml_lookup} ${out}/shared_library_test/cobertura.xml main_c 9
    Should Contain    ${output}    1
    ${output}=    Run    ${xml_lookup} ${out}/shared_library_test/cobertura.xml solib_c 5
    Should Contain    ${output}    nocode

shared-library-filter-out
    Run                            rm -rf ${out}/shared_library_test
    ${no_kcov_rc}=    Run and return RC    ./shared_library_test
    ${rc}=    Run and return RC    ${kcov} --exclude-pattern=solib ${out} ./shared_library_test
    Should be equal as integers    ${rc}    ${no_kcov_rc}
    ${output}=    Run    ${xml_lookup} ${out}/shared_library_test/cobertura.xml main_c 9
    Should Contain    ${output}    1
    ${output}=    Run    ${xml_lookup} ${out}/shared_library_test/cobertura.xml solib_c 5
    Should Contain    ${output}    nocode

shared-library-accumulate
	[Tags]	not_ready
    Run                            rm -rf ${out}/shared_library_test
    ${rc}=    Run and return RC    ${kcov} ${out} ./shared_library_test 5
    ${output}=    Run    ${xml_lookup} ${out}/shared_library_test/cobertura.xml main_c 9
    Should Contain    ${output}    1
    ${output}=    Run    ${xml_lookup} ${out}/shared_library_test/cobertura.xml solib_c 5
    Should Contain    ${output}    1
    ${output}=    Run    ${xml_lookup} ${out}/shared_library_test/cobertura.xml solib_c 10
    Should Contain    ${output}    1
    ${rc}=    Run and return RC    ${kcov} ${out} ./shared_library_test
    ${output}=    Run    ${xml_lookup} ${out}/shared_library_test/cobertura.xml solib_c 10
    Should Contain    ${output}    1

dlopen
	[Tags]	not_ready
    Run                            rm -rf ${out}/dlopen
    ${no_kcov_rc}=    Run and return RC    ./dlopen
    ${rc}=    Run and return RC    ${kcov} ${out} ./dlopen
    Should be equal as integers    ${rc}    ${no_kcov_rc}
    ${output}=    Run    ${xml_lookup} ${out}/dlopen/cobertura.xml dlopen_cc 11
    Should Contain    ${output}    1
    ${output}=    Run    ${xml_lookup} ${out}/dlopen/cobertura.xml dlopen_cc 12
    Should Contain    ${output}    0
    ${output}=    Run    ${xml_lookup} ${out}/dlopen/cobertura.xml solib_c 5
    Should Contain    ${output}    1
    ${output}=    Run    ${xml_lookup} ${out}/dlopen/cobertura.xml solib_c 12
    Should Contain    ${output}    0

dlopen-in-ignored-source-file
	[Tags]	not_ready
    Run                            rm -rf ${out}/dlopen
    ${no_kcov_rc}=    Run and return RC    ./dlopen
    ${rc}=    Run and return RC    ${kcov} --exclude-pattern=dlopen.cc ${out} ./dlopen
    Should be equal as integers    ${rc}    ${no_kcov_rc}
    ${output}=    Run    ${xml_lookup} ${out}/dlopen/cobertura.xml dlopen_main_cc 10
    Should Contain    ${output}    1
    ${output}=    Run    ${xml_lookup} ${out}/dlopen/cobertura.xml dlopen_cc 11
    Should Contain    ${output}    nocode
    ${output}=    Run    ${xml_lookup} ${out}/dlopen/cobertura.xml solib_c 5
    Should Contain    ${output}    1
    ${output}=    Run    ${xml_lookup} ${out}/dlopen/cobertura.xml solib_c 12
    Should Contain    ${output}    0


include-exclude-pattern
    Run                            rm -rf ${out}/main-tests
    ${rc}=    Run and return RC    ${kcov} --exclude-pattern=.cc ${out} ./main-tests
    ${output}=    Run    ${xml_lookup} ${out}/main-tests/cobertura.xml main_cc 9
    Should Contain    ${output}    nocode
    ${output}=    Run    ${xml_lookup} ${out}/main-tests/cobertura.xml file_c 6
    Should Contain    ${output}    1
    ${rc}=    Run and return RC    ${kcov} --include-pattern=subdir2 ${out} ./main-tests
    ${output}=    Run    ${xml_lookup} ${out}/main-tests/cobertura.xml main_cc 9
    Should Contain    ${output}    nocode
    ${output}=    Run    ${xml_lookup} ${out}/main-tests/cobertura.xml file_c 6
    Should Contain    ${output}    nocode
    ${output}=    Run    ${xml_lookup} ${out}/main-tests/cobertura.xml file2_c 6
    Should Contain    ${output}    1
    ${rc}=    Run and return RC    ${kcov} --include-pattern=subdir ${out} ./main-tests
    ${output}=    Run    ${xml_lookup} ${out}/main-tests/cobertura.xml main_cc 9
    Should Contain    ${output}    nocode
    ${output}=    Run    ${xml_lookup} ${out}/main-tests/cobertura.xml file_c 6
    Should Contain    ${output}    1
    ${output}=    Run    ${xml_lookup} ${out}/main-tests/cobertura.xml file2_c 6
    Should Contain    ${output}    1
    ${rc}=    Run and return RC    ${kcov} --include-pattern=subdir --exclude-pattern=file2 ${out} ./main-tests
    ${output}=    Run    ${xml_lookup} ${out}/main-tests/cobertura.xml main_cc 9
    Should Contain    ${output}    nocode
    ${output}=    Run    ${xml_lookup} ${out}/main-tests/cobertura.xml file_c 6
    Should Contain    ${output}    1
    ${output}=    Run    ${xml_lookup} ${out}/main-tests/cobertura.xml file2_c 6
    Should Contain    ${output}    nocode

main-test
    Run                            rm -rf ${out}/main-tests
    ${no_kcov_rc}=    Run and return RC    ./main-tests
    ${rc}=    Run and return RC    ${kcov} ${out} ./main-tests
    Should be equal as integers    ${rc}    ${no_kcov_rc}
    ${output}=    Run    ${xml_lookup} ${out}/main-tests/cobertura.xml main_cc 9
    Should Contain    ${output}    1
    ${output}=    Run    ${xml_lookup} ${out}/main-tests/cobertura.xml main_cc 14
    Should Contain    ${output}    nocode
    ${output}=    Run    ${xml_lookup} ${out}/main-tests/cobertura.xml main_cc 18
    Should Be True    ${output} >= 1
    ${output}=    Run    ${xml_lookup} ${out}/main-tests/cobertura.xml main_cc 25
    Should Contain    ${output}    1
    ${output}=    Run    ${xml_lookup} ${out}/main-tests/cobertura.xml file_c 6
    Should Contain    ${output}    1
    ${output}=    Run    ${xml_lookup} ${out}/main-tests/cobertura.xml file2_c 7
    Should Contain    ${output}    0

main-test-gcov
    [Tags]	not_ready
    Run                            rm -rf ${out}/main-tests-gcov
    ${no_kcov_rc}=    Run and return RC    ./main-tests-gcov
    ${rc}=    Run and return RC    ${kcov} --include-pattern=kcov --exclude-pattern=helper.cc,library.cc,html-data-files.cc /tmp/kcov-kcov ${kcov} --gcov ${out} ./main-tests-gcov
    Should be equal as integers    ${rc}    ${no_kcov_rc}
    ${output}=    Run    ${xml_lookup} ${out}/main-tests-gcov/cobertura.xml main_cc 9
    Should Contain    ${output}    1
    ${output}=    Run    ${xml_lookup} ${out}/main-tests-gcov/cobertura.xml main_cc 14
    Should Contain    ${output}    nocode
    ${output}=    Run    ${xml_lookup} ${out}/main-tests-gcov/cobertura.xml main_cc 18
    Should Be True    ${output} >= 1
    ${output}=    Run    ${xml_lookup} ${out}/main-tests-gcov/cobertura.xml main_cc 25
    Should Contain    ${output}    1
    ${output}=    Run    ${xml_lookup} ${out}/main-tests-gcov/cobertura.xml file_c 6
    Should Contain    ${output}    1
    ${output}=    Run    ${xml_lookup} ${out}/main-tests-gcov/cobertura.xml file2_c 7
    Should Contain    ${output}    0

gcov-tests-tricky
    [Tags]	not_ready
    Run                            rm -rf ${out}/main-tests-gcov
    ${no_kcov_rc}=    Run and return RC    ./main-tests-gcov
    ${rc}=    Run and return RC    ${kcov} --include-pattern=kcov --exclude-pattern=helper.cc,library.cc,html-data-files.cc /tmp/kcov-kcov ${kcov} --gcov ${out} ./main-tests-gcov
    ${output}=    Run    ${xml_lookup} ${out}/main-tests-gcov/cobertura.xml main_cc 20
    Should Contain    ${output}    nocode

accumulate-data
    Run                            rm -rf ${out}/argv_dependent/
    ${rc}=    Run and return RC    ${kcov} ${out} ./argv_dependent
    Should be equal as integers    ${rc}    0
    ${output}=    Run    ${xml_lookup} ${out}/argv_dependent/cobertura.xml argv_dependent_c 5
    Should Contain    ${output}    1
    ${output}=    Run    ${xml_lookup} ${out}/argv_dependent/cobertura.xml argv_dependent_c 11
    Should Contain    ${output}    0
    ${rc}=    Run and return RC    ${kcov} ${out} ./argv_dependent a
    Should be equal as integers    ${rc}    0
    ${output}=    Run    ${xml_lookup} ${out}/argv_dependent/cobertura.xml argv_dependent_c 11
    Should Contain    ${output}    1
    ${output}=    Run    ${xml_lookup} ${out}/argv_dependent/cobertura.xml argv_dependent_c 5
    Should Contain    ${output}    1

popen-test
    Run                            rm -rf ${out}/test_popen
    ${no_kcov_rc}=    Run and return RC    ./test_popen
    ${rc}=    Run and return RC    ${kcov} ${out} ./test_popen
    Should be equal as integers    ${rc}    ${no_kcov_rc}
    ${output}=    Run    ${kcov} ${out} ./test_popen
    Should Contain    ${output}    popen OK

global-constructors-test
    Run                            rm -rf ${out}/global-constructors
    ${no_kcov_rc}=    Run and return RC    ./global-constructors
    ${rc}=    Run and return RC    ${kcov} ${out} ./global-constructors
    Should be equal as integers    ${rc}    ${no_kcov_rc}
    ${output}=    Run    ${xml_lookup} ${out}/global-constructors/cobertura.xml test_global_ctors_cc 4
    Should Be True    ${output} >= 1

daemon-wait-for-last-child-test
	Run                            rm -rf ${out}/test_daemon
    ${no_kcov_rc}=    Run and return RC    ./test_daemon
    Should be equal as integers    ${no_kcov_rc}    2
    ${rc}=    Run and return RC    ${kcov} ${out} ./test_daemon
    Should be equal as integers    ${rc}    4
    ${output}=    Run    ${xml_lookup} ${out}/test_daemon/cobertura.xml test_daemon_cc 31
    Should Contain    ${output}    1
    
daemon-no-wait-for-last-child-test
	[Tags]	not_ready
	Run                            rm -rf ${out}/test_daemon/cobertura.xml
    ${no_kcov_rc}=    Run and return RC    ./test_daemon
    ${rc}=    Run and return RC    ${kcov} --exit-first-process ${out} ./test_daemon
    Should be equal as integers    ${no_kcov_rc}    ${rc}
    ${output}=    Run    ${xml_lookup} ${out}/test_daemon/cobertura.xml test_daemon_cc 31
    Should Contain    ${output}    0
    Run                            sleep 5
    ${output}=    Run    ${xml_lookup} ${out}/test_daemon/cobertura.xml test_daemon_cc 31
    Should Contain    ${output}    1
    
signals
    Run                            rm -rf ${out}/signals
    ${no_kcov_rc}=    Run and return RC    ./signals hup
    ${rc}=    Run and return RC    ${kcov} ${out} ./signals hup
    Should be equal as integers    ${no_kcov_rc}    ${rc}
    ${output}=    Run    ${xml_lookup} ${out}/signals/cobertura.xml test_signals_c 14
    ${no_kcov_rc}=    Run and return RC    ./signals int
    ${rc}=    Run and return RC    ${kcov} ${out} ./signals int
    Should be equal as integers    ${no_kcov_rc}    ${rc}
    ${output}=    Run    ${xml_lookup} ${out}/signals/cobertura.xml test_signals_c 19
    ${no_kcov_rc}=    Run and return RC    ./signals quit
    ${rc}=    Run and return RC    ${kcov} ${out} ./signals quit
    Should be equal as integers    ${no_kcov_rc}    ${rc}
    ${output}=    Run    ${xml_lookup} ${out}/signals/cobertura.xml test_signals_c 24
    ${no_kcov_rc}=    Run and return RC    ./signals abrt
    ${rc}=    Run and return RC    ${kcov} ${out} ./signals abrt
    Should be equal as integers    ${no_kcov_rc}    ${rc}
    ${output}=    Run    ${xml_lookup} ${out}/signals/cobertura.xml test_signals_c 39
    ${no_kcov_rc}=    Run and return RC    ./signals segv
    ${rc}=    Run and return RC    ${kcov} ${out} ./signals segv
    Should be equal as integers    ${no_kcov_rc}    ${rc}
    ${output}=    Run    ${xml_lookup} ${out}/signals/cobertura.xml test_signals_c 69
    ${no_kcov_rc}=    Run and return RC    ./signals term
    ${rc}=    Run and return RC    ${kcov} ${out} ./signals term
    Should be equal as integers    ${no_kcov_rc}    ${rc}
    ${output}=    Run    ${xml_lookup} ${out}/signals/cobertura.xml test_signals_c 89

signals-self
	Run								rm -rf ${out}/signals/
    ${output}=   Run				${kcov} ${out} ./signals segv self
	Should Contain					${output}	kcov: Process exited with signal 11
    ${output}=   Run				${kcov} ${out} ./signals abrt self
	Should Contain					${output}	kcov: Process exited with signal 6

collect-only-and-report-only
	Run								rm -rf ${out}/main-tests/
    ${no_kcov_rc}=    Run and return RC    ./main-tests
    ${rc}=    Run and return RC    ${kcov} --collect-only ${out} ./main-tests
    Should be equal as integers    ${rc}    ${no_kcov_rc}
    ${rc}=    Run and return RC    test -e ${out}/main-tests/cobertura.xml
    Should be equal as integers    ${rc}    1
    ${rc}=    Run and return RC    ${kcov} --collect-only ${out} ./main-tests
    Should be equal as integers    ${rc}    0
    ${output}=    Run    ${xml_lookup} ${out}/main-tests/cobertura.xml main_cc 9
    Should Contain    ${output}    1

setpgid
	Run								rm -rf ${out}
    ${output}=   Run				${kcov_path}/tests/setpgid-kill/test-script.sh ./setpgid-kill
    Should Contain    ${output}    SUCCESS
    ${output}=   Run				${kcov_path}/tests/setpgid-kill/test-script.sh ${kcov} ${out} ./setpgid-kill
    Should Contain    ${output}    SUCCESS

# Issue 31
attach-process-with-threads
	Run								rm -rf ${out}
    ${output}=   Run				${kcov_path}/tests/daemon/test-script.sh ${kcov} ${out} ./issue31
    ${output}=   Run   ${xml_lookup} ${out}/issue31/cobertura.xml test_issue31_cc 28
    Should Contain     ${output}    1
    ${output}=   Run   ${xml_lookup} ${out}/issue31/cobertura.xml test_issue31_cc 11
    Should Contain     ${output}    1
    ${output}=   Run   ${xml_lookup} ${out}/issue31/cobertura.xml test_issue31_cc 8
    Should Contain     ${output}    0


python-exit-status
	Run								rm -rf ${out}/main
    ${no_kcov_rc}=    Run and return RC    python ${kcov_path}/tests/python/main 5
    ${rc}=    Run and return RC    ${kcov} --include-pattern=kcov --exclude-pattern=helper.cc,library.cc,html-data-files.cc /tmp/kcov-kcov ${kcov} ${out} ${kcov_path}/tests/python/main 5
    Should be equal as integers    ${rc}    ${no_kcov_rc}

python-unittest
	Run								rm -rf ${out}/testdriver
    ${rc}=    Run and return RC    ${kcov} --include-pattern=kcov --exclude-pattern=helper.cc,library.cc,html-data-files.cc /tmp/kcov-kcov ${kcov} ${out} ${kcov_path}/tests/python/unittest/testdriver
    ${output}=    Run    ${xml_lookup} ${out}/testdriver/cobertura.xml testdriver 14
    Should Contain    ${output}    1

python-short-file
	Run								rm -rf ${out}/short-test.py
    ${rc}=    Run and return RC    ${kcov} --include-pattern=kcov --exclude-pattern=helper.cc,library.cc,html-data-files.cc /tmp/kcov-kcov ${kcov} ${out} ${kcov_path}/tests/python/short-test.py
    Should be equal as integers    ${rc}    0
    ${output}=    Run    ${xml_lookup} ${out}/short-test.py/cobertura.xml short_test_py 6
    Should Contain    ${output}    1

python-coverage
	Run								rm -rf ${out}/main
    ${rc}=    Run and return RC    ${kcov} --include-pattern=kcov --exclude-pattern=helper.cc,library.cc,html-data-files.cc /tmp/kcov-kcov ${kcov} ${out} ${kcov_path}/tests/python/main 5
    ${output}=    Run    ${xml_lookup} ${out}/main/cobertura.xml main 10
    Should Contain    ${output}    2
    ${output}=    Run    ${xml_lookup} ${out}/main/cobertura.xml main 17
    Should Contain    ${output}    0
    ${output}=    Run    ${xml_lookup} ${out}/main/cobertura.xml main 22
    Should Contain    ${output}    nocode
    ${output}=    Run    ${xml_lookup} ${out}/main/cobertura.xml second_py 2
    Should Contain    ${output}    1
    ${output}=    Run    ${xml_lookup} ${out}/main/cobertura.xml second_py 4
    Should Contain    ${output}    nocode
    ${output}=    Run    ${xml_lookup} ${out}/main/cobertura.xml second_py 11
    Should Contain    ${output}    nocode
    ${output}=    Run    ${xml_lookup} ${out}/main/cobertura.xml second_py 31
    Should Contain    ${output}    0
    ${output}=    Run    ${xml_lookup} ${out}/main/cobertura.xml second_py 38
    Should Contain    ${output}    1
    ${output}=    Run    ${xml_lookup} ${out}/main/cobertura.xml second_py 39
    Should Contain    ${output}    0
    ${output}=    Run    ${xml_lookup} ${out}/main/cobertura.xml second_py 40
    Should Contain    ${output}    nocode
    ${output}=    Run    ${xml_lookup} ${out}/main/cobertura.xml second_py 41
    Should Contain    ${output}    1
    ${output}=    Run    ${xml_lookup} ${out}/main/cobertura.xml second_py 56
    Should Contain    ${output}    nocode
    ${output}=    Run    ${xml_lookup} ${out}/main/cobertura.xml second_py 60
    Should Contain    ${output}    nocode
    ${output}=    Run    ${xml_lookup} ${out}/main/cobertura.xml second_py 65
    Should Contain    ${output}    nocode
    ${output}=    Run    ${xml_lookup} ${out}/main/cobertura.xml second_py 77
    Should Contain    ${output}    nocode

python-accumulate-data
	Run								rm -rf ${out}/main
    ${rc}=    Run and return RC    ${kcov} --include-pattern=kcov --exclude-pattern=helper.cc,library.cc,html-data-files.cc /tmp/kcov-kcov ${kcov} ${out} ${kcov_path}/tests/python/main 5
    ${output}=    Run    ${xml_lookup} ${out}/main/cobertura.xml main 16
    Should Contain    ${output}    0
    ${output}=    Run    ${xml_lookup} ${out}/main/cobertura.xml main 19
    Should Contain    ${output}    1
    ${rc}=    Run and return RC    ${kcov} ${out} ${kcov_path}/tests/python/main
    ${output}=    Run    ${xml_lookup} ${out}/main/cobertura.xml main 16
    Should Contain    ${output}    1
    ${output}=    Run    ${xml_lookup} ${out}/main/cobertura.xml main 19
    Should Contain    ${output}    1

python-coverage-python3
    Run                            rm -rf ${out}/main
    ${rc}=    Run and return RC    ${kcov} --include-pattern=kcov --exclude-pattern=helper.cc,library.cc,html-data-files.cc /tmp/kcov-kcov ${kcov} --python-parser=python3 ${out} ${kcov_path}/tests/python/main 5
    ${output}=    Run    ${xml_lookup} ${out}/main/cobertura.xml main 10
    Should Contain    ${output}    2
    ${output}=    Run    ${xml_lookup} ${out}/main/cobertura.xml main 17
    Should Contain    ${output}    0
    ${output}=    Run    ${xml_lookup} ${out}/main/cobertura.xml main 22
    Should Contain    ${output}    nocode
    ${output}=    Run    ${xml_lookup} ${out}/main/cobertura.xml second_py 2
    Should Contain    ${output}    1
    ${output}=    Run    ${xml_lookup} ${out}/main/cobertura.xml second_py 4
    Should Contain    ${output}    nocode

python-tricky-single-line-string-assignment
	[Tags]	not_ready
	Run								rm -rf ${out}/main
    ${rc}=    Run and return RC    ${kcov} --include-pattern=kcov --exclude-pattern=helper.cc,library.cc,html-data-files.cc /tmp/kcov-kcov ${kcov} ${out} ${kcov_path}/tests/python/main 5
    ${output}=    Run    ${xml_lookup} ${out}/main/cobertura.xml second_py 34
    Should Contain    ${output}    1

python-tricky-single-dict-assignment
	[Tags]	not_ready
	Run								rm -rf ${out}/main
    ${rc}=    Run and return RC    ${kcov} --include-pattern=kcov --exclude-pattern=helper.cc,library.cc,html-data-files.cc /tmp/kcov-kcov ${kcov} ${out} ${kcov_path}/tests/python/main 5
    ${output}=    Run    ${xml_lookup} ${out}/main/cobertura.xml second_py 57
    Should Contain    ${output}    1
    ${output}=    Run    ${xml_lookup} ${out}/main/cobertura.xml second_py 61
    Should Contain    ${output}    1


#python-select-parser
#	Run								rm -rf ${out}/main
#    ${rc}=    Run and return RC    ${kcov} --python-parser=${kcov_path}/tests/tools/dummy-python.sh ${out} ${kcov_path}/tests/python/main 5
#    Should be equal as integers    ${rc}   99

# Not sure why this fails in some settings (works in F20 at least)
bash-exit-status
	[Tags]	not_ready
	Run								rm -rf ${out}/main
    ${no_kcov_rc}=    Run and return RC    ${kcov_path}/tests/bash/shell-main 5
    ${rc}=    Run and return RC    ${kcov} --include-pattern=kcov --exclude-pattern=helper.cc,library.cc,html-data-files.cc /tmp/kcov-kcov ${kcov} ${out} ${kcov_path}/tests/bash/shell-main 5
    Should be equal as integers    ${rc}   ${no_kcov_rc}

bash-coverage
	Run								rm -rf ${out}/shell-main
    ${rc}=    Run and return RC    ${kcov} --include-pattern=kcov --exclude-pattern=helper.cc,library.cc,html-data-files.cc /tmp/kcov-kcov ${kcov} ${out} ${kcov_path}/tests/bash/shell-main 5
    ${output}=    Run    ${xml_lookup} ${out}/shell-main/cobertura.xml shell_main 3
    Should Contain    ${output}    nocode
    ${output}=    Run    ${xml_lookup} ${out}/shell-main/cobertura.xml shell_main 4
    Should Contain    ${output}    1
    ${output}=    Run    ${xml_lookup} ${out}/shell-main/cobertura.xml shell_main 13
    Should Contain    ${output}    0
    ${output}=    Run    ${xml_lookup} ${out}/shell-main/cobertura.xml shell_main 26
    Should Contain    ${output}    nocode
    ${output}=    Run    ${xml_lookup} ${out}/shell-main/cobertura.xml shell_main 30
    Should Contain    ${output}    5
    ${output}=    Run    ${xml_lookup} ${out}/shell-main/cobertura.xml shell_main 34
    Should Contain    ${output}    nocode
    ${output}=    Run    ${xml_lookup} ${out}/shell-main/cobertura.xml shell_main 38
    Should Contain    ${output}    nocode
    ${output}=    Run    ${xml_lookup} ${out}/shell-main/cobertura.xml other_sh 5
    Should Contain    ${output}    1
    ${rc}=    Run and return RC    ${kcov} --include-pattern=kcov --exclude-pattern=helper.cc,library.cc,html-data-files.cc /tmp/kcov-kcov ${kcov} ${out} ${kcov_path}/tests/bash/shell-main
    ${output}=    Run    ${xml_lookup} ${out}/shell-main/cobertura.xml short_test_sh 5
    Should Contain    ${output}    11

bash-short-file
	Run								rm -rf ${out}/short-test.sh
    ${rc}=    Run and return RC    ${kcov} --include-pattern=kcov --exclude-pattern=helper.cc,library.cc,html-data-files.cc /tmp/kcov-kcov ${kcov} ${out} ${kcov_path}/tests/bash/short-test.sh
    Should be equal as integers    ${rc}    0
    ${output}=    Run    ${xml_lookup} ${out}/short-test.sh/cobertura.xml short_test_sh 5
    Should Contain    ${output}    11


bash-coverage-heredoc-backslashes
	Run								rm -rf ${out}
    ${rc}=    Run and return RC    ${kcov} --include-pattern=kcov --exclude-pattern=helper.cc,library.cc,html-data-files.cc /tmp/kcov-kcov ${kcov} ${out} ${kcov_path}/tests/bash/shell-main 5
	${output}=    Run    ${xml_lookup} ${out}/shell-main/cobertura.xml shell_main 52
    Should Contain    ${output}    4
	${output}=    Run    ${xml_lookup} ${out}/shell-main/cobertura.xml shell_main 53
    Should Contain    ${output}    nocode
	${output}=    Run    ${xml_lookup} ${out}/shell-main/cobertura.xml shell_main 55
    Should Contain    ${output}    nocode
	${output}=    Run    ${xml_lookup} ${out}/shell-main/cobertura.xml shell_main 59
    Should Contain    ${output}    1
	${output}=    Run    ${xml_lookup} ${out}/shell-main/cobertura.xml shell_main 61
    Should Contain    ${output}    nocode
	${output}=    Run    ${xml_lookup} ${out}/shell-main/cobertura.xml shell_main 62
    Should Contain    ${output}    nocode

bash-issue-44-heredoc-special-cases
	Run								rm -rf ${out}/shell-main
    ${rc}=    Run and return RC    ${kcov} --include-pattern=kcov --exclude-pattern=helper.cc,library.cc,html-data-files.cc /tmp/kcov-kcov ${kcov} ${out} ${kcov_path}/tests/bash/shell-main
    ${output}=    Run    ${xml_lookup} ${out}/shell-main/cobertura.xml shell_main 77
    Should Contain    ${output}    1
    ${output}=    Run    ${xml_lookup} ${out}/shell-main/cobertura.xml shell_main 83
    Should Contain    ${output}    1
    ${output}=    Run    ${xml_lookup} ${out}/shell-main/cobertura.xml shell_main 88
    Should Contain    ${output}    1
    ${output}=    Run    ${xml_lookup} ${out}/shell-main/cobertura.xml shell_main 93
    Should Contain    ${output}    1

bash-coverage-tricky
	Run								rm -rf ${out}/shell-main
    ${rc}=    Run and return RC    ${kcov} --include-pattern=kcov --exclude-pattern=helper.cc,library.cc,html-data-files.cc /tmp/kcov-kcov ${kcov} ${out} ${kcov_path}/tests/bash/shell-main 5
	${output}=    Run    ${xml_lookup} ${out}/shell-main/cobertura.xml shell_main 36
    Should Contain    ${output}    nocode
	${output}=    Run    ${xml_lookup} ${out}/shell-main/cobertura.xml shell_main 44
    Should Contain    ${output}    nocode
	${output}=    Run    ${xml_lookup} ${out}/shell-main/cobertura.xml shell_main 7
    Should Contain    ${output}    nocode

bash-honor-signal
	Run								rm -rf ${out}
    ${output}=   Run				${kcov_path}/tests/setpgid-kill/test-script.sh ${kcov} ${out} ${kcov_path}/tests/bash/trap.sh
    Should Contain    ${output}    SUCCESS
	${output}=    Run    ${xml_lookup} ${out}/shell-main/cobertura.xml trap_sh 5
    Should Contain    ${output}    1

bash-accumulate-data
	Run								rm -rf ${out}
    ${rc}=    Run and return RC    ${kcov} --include-pattern=kcov --exclude-pattern=helper.cc,library.cc,html-data-files.cc /tmp/kcov-kcov ${kcov} ${out} ${kcov_path}/tests/bash/unitundertest.sh 1
    ${output}=    Run    ${xml_lookup} ${out}/unitundertest.sh/cobertura.xml unitundertest_sh 6
    Should Contain    ${output}    1
    ${output}=    Run    ${xml_lookup} ${out}/unitundertest.sh/cobertura.xml unitundertest_sh 16
    Should Contain    ${output}    0
    ${rc}=    Run and return RC    ${kcov} ${out} ${kcov_path}/tests/bash/unitundertest.sh 2
    ${output}=    Run    ${xml_lookup} ${out}/unitundertest.sh/cobertura.xml unitundertest_sh 16
    Should Contain    ${output}    1
    ${output}=    Run    ${xml_lookup} ${out}/unitundertest.sh/cobertura.xml unitundertest_sh 6
    Should Contain    ${output}    1

bash-accumulate-changed-data
	Run								rm -rf ${out}
    ${rc}=    Run and return RC    	cp ${kcov_path}/tests/bash/shell-main .
    ${rc}=    Run and return RC    	cp ${kcov_path}/tests/bash/other.sh .
    ${rc}=    Run and return RC    	${kcov} --include-pattern=kcov --exclude-pattern=helper.cc,library.cc,html-data-files.cc /tmp/kcov-kcov ${kcov} ${out} ./shell-main 5 9
	${output}=    Run    ${xml_lookup} ${out}/shell-main/cobertura.xml shell_main 40
    Should Contain    ${output}    	1
	${output}=    Run    ${xml_lookup} ${out}/shell-main/cobertura.xml shell_main 67
    Should Contain    ${output}    	2
	${output}=    Run    ${xml_lookup} ${out}/shell-main/cobertura.xml other_sh 6
    Should Contain    ${output}    	2
    Run                             echo 'echo arne-anka' >> shell-main
    ${rc}=    Run and return RC    	${kcov} --include-pattern=kcov --exclude-pattern=helper.cc,library.cc,html-data-files.cc /tmp/kcov-kcov ${kcov} ${out} ./shell-main 5
	${output}=    Run    ${xml_lookup} ${out}/shell-main/cobertura.xml shell_main 40
    Should Contain    ${output}    	0
	${output}=    Run    ${xml_lookup} ${out}/shell-main/cobertura.xml shell_main 67
    Should Contain    ${output}    	0
	${output}=    Run    ${xml_lookup} ${out}/shell-main/cobertura.xml other_sh 6
    Should Contain    ${output}    	3

bash-merge-data-issue-38
	Run								rm -rf ${out}
    ${rc}=    Run and return RC    ${kcov} ${out} ./dlopen
    ${rc}=    Run and return RC    ${kcov} --include-pattern=kcov --exclude-pattern=helper.cc,library.cc,html-data-files.cc /tmp/kcov-kcov ${kcov} ${out} ${kcov_path}/tests/bash/unitundertest.sh 1
    ${output}=    Run    ${xml_lookup} ${out}/unitundertest.sh/cobertura.xml unitundertest_sh 6
    Should Contain    ${output}    1
    ${output}=    Run    ${xml_lookup} ${out}/unitundertest.sh/cobertura.xml unitundertest_sh 16
    Should Contain    ${output}    0
    ${rc}=    Run and return RC    ${kcov} ${out} ${kcov_path}/tests/bash/unitundertest.sh 2
    ${output}=    Run    ${xml_lookup} ${out}/unitundertest.sh/cobertura.xml unitundertest_sh 16
    Should Contain    ${output}    1
    ${output}=    Run    ${xml_lookup} ${out}/unitundertest.sh/cobertura.xml unitundertest_sh 6
    Should Contain    ${output}    1
    ${rc}=    Run and return RC    ${kcov} ${out} ${kcov_path}/tests/bash/unitundertest.sh all
    ${output}=    Run    ${xml_lookup} ${out}/unitundertest.sh/cobertura.xml unitundertest_sh 36
    Should Contain    ${output}    1
    ${output}=    Run    ${xml_lookup} ${out}/kcov-merged/cobertura.xml unitundertest_sh 30
    Should Contain    ${output}    1
    ${output}=    Run    ${xml_lookup} ${out}/kcov-merged/cobertura.xml unitundertest_sh 33
    Should Contain    ${output}    1
    ${output}=    Run    ${xml_lookup} ${out}/kcov-merged/cobertura.xml unitundertest_sh 36
    Should Contain    ${output}    1

bash-output-crc
	Run								rm -rf ${out}/a.sh
    ${rc}=    Run and return RC    ${kcov} --include-pattern=kcov --exclude-pattern=helper.cc,library.cc,html-data-files.cc /tmp/kcov-kcov ${kcov} ${out} ${kcov_path}/tests/bash/first-dir/a.sh
    ${rc}=    Run and return RC    ${kcov} --include-pattern=kcov --exclude-pattern=helper.cc,library.cc,html-data-files.cc /tmp/kcov-kcov ${kcov} ${out} ${kcov_path}/tests/bash/second-dir/a.sh
    ${output}=    Run              ls -l ${out}/a.sh/a.*.json | wc -l
    Should Contain    ${output}    2
    ${output}=    Run              ls -l ${out}/a.sh/b.*.json | wc -l
    Should Contain    ${output}    2

bash-sh-shebang
	[Tags]	not_ready
	Run								rm -rf ${out}/shell-main
    ${rc}=    Run and return RC    ${kcov} --include-pattern=kcov --exclude-pattern=helper.cc,library.cc,html-data-files.cc /tmp/kcov-kcov ${kcov} ${out} ${kcov_path}/tests/bash/shell-main 5
	${output}=    Run    ${xml_lookup} ${out}/shell-main/cobertura.xml sh_shebang_sh 4
    Should Contain    ${output}    	1

merge-basic
	Run								rm -rf ${out}
    ${rc}=    Run and return RC    ${kcov} --include-pattern=kcov --exclude-pattern=helper.cc,library.cc,html-data-files.cc /tmp/kcov-kcov ${kcov} ${out} ${kcov_path}/tests/python/main 5
    ${rc}=    Run and return RC    ${kcov} ${out} ./main-tests
    ${output}=    Run    ${xml_lookup} ${out}/main/cobertura.xml main 10
    Should Contain    ${output}    2
    ${output}=    Run    ${xml_lookup} ${out}/main-tests/cobertura.xml main_cc 9
    Should Contain    ${output}    1
    ${output}=    Run    ${xml_lookup} ${out}/kcov-merged/cobertura.xml main 10
    Should Contain    ${output}    1
    ${output}=    Run    ${xml_lookup} ${out}/kcov-merged/cobertura.xml main_cc 9
    Should Contain    ${output}    1


merge-same-file-in-multiple-binaries
	Run								rm -rf ${out}
    ${rc}=    Run and return RC    ${kcov} ${out} ./multi_1
    ${output}=    Run    ${xml_lookup} ${out}/multi_1/cobertura.xml main_1_c 9
    Should Contain    ${output}    1
    ${output}=    Run    ${xml_lookup} ${out}/multi_1/cobertura.xml main_1_c 10
    ${output}=    Run    ${xml_lookup} ${out}/multi_1/cobertura.xml file_c 3
    Should Contain    ${output}    0
    Should Contain    ${output}    0
    ${rc}=    Run and return RC    ${kcov} ${out} ./multi_2
    ${output}=    Run    ${xml_lookup} ${out}/kcov-merged/cobertura.xml main_2_c 9
    Should Contain    ${output}    1
    ${output}=    Run    ${xml_lookup} ${out}/kcov-merged/cobertura.xml main_2_c 9
    Should Contain    ${output}    1
    ${output}=    Run    ${xml_lookup} ${out}/kcov-merged/cobertura.xml file_c 3
    Should Contain    ${output}    0
    ${output}=    Run    ${xml_lookup} ${out}/kcov-merged/cobertura.xml file_c 8
    Should Contain    ${output}    0
    ${rc}=    Run and return RC    ${kcov} ${out} ./multi_2 1
    ${output}=    Run    ${xml_lookup} ${out}/kcov-merged/cobertura.xml file_c 8
    Should Contain    ${output}    1
    ${rc}=    Run and return RC    ${kcov} ${out} ./multi_1 1
    ${output}=    Run    ${xml_lookup} ${out}/kcov-merged/cobertura.xml file_c 3
    Should Contain    ${output}    1

merge-changed-file
    Run								rm -rf ${out} file.c file.o main_1.o main_2.o
    ${rc}=    Run and return RC    	cp ${kcov_path}/tests/merge-tests/file.c .
    Should be equal as integers		${rc}    0
    ${rc}=    Run and return RC    	gcc -c -g -o file.o file.c
    ${rc}=    Run and return RC    	gcc -c -g -o main_1.o ${kcov_path}/tests/merge-tests/main_1.c
    ${rc}=    Run and return RC    	gcc -o multi_3 main_1.o file.o
    ${rc}=    Run and return RC    ${kcov} ${out} ./multi_3 9
    ${output}=    Run    ${xml_lookup} ${out}/multi_3/cobertura.xml file_c 3
    Should Contain    ${output}    1
    ${output}=    Run    ${xml_lookup} ${out}/multi_3/cobertura.xml file_c 8
    Should Contain    ${output}    0
    ${output}=    Run    ${xml_lookup} ${out}/multi_3/cobertura.xml file_c 10
    Should Contain    ${output}    nocode
    ${rc}=    Run and return RC    	echo "int kalle(void) { return 129; }" >> file.c
    ${rc}=    Run and return RC    	gcc -c -g -o file.o file.c
    ${rc}=    Run and return RC    	gcc -c -g -o main_2.o ${kcov_path}/tests/merge-tests/main_2.c
    ${rc}=    Run and return RC    	gcc -o multi_4 main_2.o file.o
    ${rc}=    Run and return RC    	${kcov} ${out} ./multi_4 9
    ${output}=    Run    ${xml_lookup} ${out}/kcov-merged/cobertura.xml file_c 3
    Should Contain    ${output}    0
    ${output}=    Run    ${xml_lookup} ${out}/kcov-merged/cobertura.xml file_c 8
    Should Contain    ${output}    1
    ${output}=    Run    ${xml_lookup} ${out}/kcov-merged/cobertura.xml file_c 10
    Should Contain    ${output}    0
