Cisco-Talos / clamav

ClamAV - Documentation is here: https://docs.clamav.net
https://www.clamav.net/
GNU General Public License v2.0
4.47k stars 707 forks source link

ctest fails if clamav compiled directly in source directory #286

Open jpffitch opened 3 years ago

jpffitch commented 3 years ago

Buit 0.104 frm sources. Only oddity is tat it ignored te build directory

transcipt

Script started on 2021-09-07 21:19:23+01:00 [TERM="xterm" TTY="/dev/pts/3" COLUMNS="80" LINES="40"]
]0;jpff@snout: /home/jpff/clamav-0.104.0jpff@snout:~/clamav-0.104.0$ ~/.local/bin/ctest -V
UpdateCTestConfiguration  from :/home/jpff/clamav-0.104.0/DartConfiguration.tcl
Parse Config file:/home/jpff/clamav-0.104.0/DartConfiguration.tcl
UpdateCTestConfiguration  from :/home/jpff/clamav-0.104.0/DartConfiguration.tcl
Parse Config file:/home/jpff/clamav-0.104.0/DartConfiguration.tcl
Test project /home/jpff/clamav-0.104.0
Constructing a list of tests
Done constructing a list of tests
Updating test list for fixtures
Added 0 tests to meet fixture requirements
Checking test dependency graph...
Checking test dependency graph end
test 1
      Start  1: libclamav

1: Test command: /usr/bin/python3.7 "-m" "pytest" "-v" "libclamav_test.py"
1: Environment variables: 
1:  PYTHONTRACEMALLOC=1
1:  VERSION=0.104.0
1:  SOURCE=/home/jpff/clamav-0.104.0
1:  BUILD=/home/jpff/clamav-0.104.0
1:  TMP=/home/jpff/clamav-0.104.0/unit_tests
1:  CK_FORK=no
1:  CK_DEFAULT_TIMEOUT=60
1:  LD_LIBRARY_PATH=/home/jpff/clamav-0.104.0/libfreshclam:/home/jpff/clamav-0.104.0/libclamav:/home/jpff/clamav-0.104.0/libclammspack::/home/jpff/clamav-0.104.0/libclamunrar_iface:/home/jpff/clamav-0.104.0/libclamunrar
1:  SOURCE=/home/jpff/clamav-0.104.0
1:  BUILD=/home/jpff/clamav-0.104.0
1:  TMP=/home/jpff/clamav-0.104.0/unit_tests
1:  CHECK_CLAMAV=/home/jpff/clamav-0.104.0/unit_tests/check_clamav
1:  CHECK_CLAMD=/home/jpff/clamav-0.104.0/unit_tests/check_clamd
1:  CHECK_FPU_ENDIAN=/home/jpff/clamav-0.104.0/unit_tests/check_fpu_endian
1:  CLAMBC=/home/jpff/clamav-0.104.0/clambc/clambc
1:  CLAMD=/home/jpff/clamav-0.104.0/clamd/clamd
1:  CLAMDSCAN=/home/jpff/clamav-0.104.0/clamdscan/clamdscan
1:  CLAMDTOP=/home/jpff/clamav-0.104.0/clamdtop/clamdtop
1:  CLAMSCAN=/home/jpff/clamav-0.104.0/clamscan/clamscan
1:  CLAMSUBMIT=/home/jpff/clamav-0.104.0/clamsubmit/clamsubmit
1:  CLAMCONF=/home/jpff/clamav-0.104.0/clamconf/clamconf
1:  FRESHCLAM=/home/jpff/clamav-0.104.0/freshclam/freshclam
1:  SIGTOOL=/home/jpff/clamav-0.104.0/sigtool/sigtool
1:  CLAMAV_MILTER=/home/jpff/clamav-0.104.0/clamav-milter/clamav-milter
1:  CLAMONACC=/home/jpff/clamav-0.104.0/clamonacc/clamonacc
1: Test timeout computed to be: 1500
1: ============================= test session starts ==============================
1: platform linux -- Python 3.7.3, pytest-3.10.1, py-1.7.0, pluggy-0.8.0 -- /usr/bin/python3.7
1: cachedir: .pytest_cache
1: rootdir: /home/jpff/clamav-0.104.0/unit_tests, inifile:
1: collecting ... collected 1 item
1: 
1: libclamav_test.py::TC::test_libclamav_00_unit_test FAILED                [100%]
1: 
1: =================================== FAILURES ===================================
1: ________________________ TC.test_libclamav_00_unit_test ________________________
1: 
1: self = <libclamav_test.TC testMethod=test_libclamav_00_unit_test>
1: 
1:     def test_libclamav_00_unit_test(self):
1:         self.step_name('libclamav unit tests')
1:     
1:         # If no valgrind, valgrind nad valgrind args are empty strings
1:         command = '{valgrind} {valgrind_args} {check_clamav}'.format(
1:             valgrind=TC.valgrind, valgrind_args=TC.valgrind_args, check_clamav=TC.check_clamav
1:         )
1:         output = self.execute_command(command)
1:     
1: >       assert output.ec == 0  # success
1: E       AssertionError: assert 1 == 0
1: E        +  where 1 = CmdResult(ec=1, out="Using default test timeout; alter by setting 'T' env var (in seconds)\nRunning suite(s): cl_suite...i:checked_setup:0: testfiles: 98 != 49\nNOTICE: Use the 'T' environment variable to adjust testcase timeout\n", err='').ec
1: 
1: ../libclamav_test.py:47: AssertionError
1: ----------------------------- Captured stdout call -----------------------------
1: 
1: [INFO]: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1: [INFO]:                           libclamav unit tests                          
1: [INFO]: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1: [DEBUG]: Run command:   /home/jpff/clamav-0.104.0/unit_tests/check_clamav 
1: [DEBUG]: Exit code: 1
1: [DEBUG]: stdout: Using default test timeout; alter by setting 'T' env var (in seconds)
1: Running suite(s): cl_suite
1:  cli
1:  jsnorm
1:  str
1:  regex
1:  disasm
1:  unique
1:  matchers
1:  htmlnorm
1:  bytecode
1: 39%: Checks: 1127, Failures: 686, Errors: 0
1: /home/jpff/clamav-0.104.0/unit_tests/check_clamav.c:484:S:cl_scan_api:checked_setup:0: testfiles: 98 != 49
1: /home/jpff/clamav-0.104.0/unit_tests/check_clamav.c:484:S:cl_scan_api:checked_setup:0: testfiles: 98 != 49
1: /home/jpff/clamav-0.104.0/unit_tests/check_clamav.c:484:S:cl_scan_api:checked_setup:0: testfiles: 98 != 49
1: /home/jpff/clamav-0.104.0/unit_tests/check_clamav.c:484:S:cl_scan_api:checked_setup:0: testfiles: 98 != 49
1: /home/jpff/clamav-0.104.0/unit_tests/check_clamav.c:484:S:cl_scan_api:checked_setup:0: testfiles: 98 != 49
1: /home/jpff/clamav-0.104.0/unit_tests/check_clamav.c:484:S:cl_scan_api:checked_setup:0: testfiles: 98 != 49
1: /home/jpff/clamav-0.104.0/unit_tests/check_clamav.c:484:S:cl_scan_api:checked_setup:0: testfiles: 98 != 49
1: /home/jpff/clamav-0.104.0/unit_tests/check_clamav.c:484:S:cl_scan_api:checked_setup:0: testfiles: 98 != 49
1: /home/jpff/clamav-0.104.0/unit_tests/check_clamav.c:484:S:cl_scan_api:checked_setup:0: testfiles: 98 != 49
1: /home/jpff/clamav-0.104.0/unit_tests/check_clamav.c:484:S:cl_scan_api:checked_setup:0: testfiles: 98 != 49
1: /home/jpff/clamav-0.104.0/unit_tests/check_clamav.c:484:S:cl_scan_api:checked_setup:0: testfiles: 98 != 49
1: /home/jpff/clamav-0.104.0/unit_tests/check_clamav.c:484:S:cl_scan_api:checked_setup:0: testfiles: 98 != 49
1: /home/jpff/clamav-0.104.0/unit_tests/check_clamav.c:484:S:cl_scan_api:checked_setup:0: testfiles: 98 != 49
1: /home/jpff/clamav-0.104.0/unit_tests/check_clamav.c:484:S:cl_scan_api:checked_setup:0: testfiles: 98 != 49
1: /home/jpff/clamav-0.104.0/unit_tests/check_clamav.c:484:S:cl_scan_api:checked_setup:0: testfiles: 98 != 49
1: /home/jpff/clamav-0.104.0/unit_tests/check_clamav.c:484:S:cl_scan_api:checked_setup:0: testfiles: 98 != 49
1: /home/jpff/clamav-0.104.0/unit_tests/check_clamav.c:484:S:cl_scan_api:checked_setup:0: testfiles: 98 != 49
1: /home/jpff/clamav-0.104.0/unit_tests/check_clamav.c:484:S:cl_scan_api:checked_setup:0: testfiles: 98 != 49
1: /home/jpff/clamav-0.104.0/unit_tests/check_clamav.c:484:S:cl_scan_api:checked_setup:0: testfiles: 98 != 49
1: /home/jpff/clamav-0.104.0/unit_tests/check_clamav.c:484:S:cl_scan_api:checked_setup:0: testfiles: 98 != 49
1: /home/jpff/clamav-0.104.0/unit_tests/check_clamav.c:484:S:cl_scan_api:checked_setup:0: testfiles: 98 != 49
1: /home/jpff/clamav-0.104.0/unit_tests/check_clamav.c:484:S:cl_scan_api:checked_setup:0: testfiles: 98 != 49
1: /home/jpff/clamav-0.104.0/unit_tests/check_clamav.c:484:S:cl_scan_api:checked_setup:0: testfiles: 98 != 49
1: /home/jpff/clamav-0.104.0/unit_tests/check_clamav.c:484:S:cl_scan_api:checked_setup:0: testfiles: 98 != 49
1: /home/jpff/clamav-0.104.0/unit_tests/check_clamav.c:484:S:cl_scan_api:checked_setup:0: testfiles: 98 != 49
1: /home/jpff/clamav-0.104.0/unit_tests/check_clamav.c:484:S:cl_scan_api:checked_setup:0: testfiles: 98 != 49
1: /home/jpff/clamav-0.104.0/unit_tests/check_clamav.c:484:S:cl_scan_api:checked_setup:0: testfiles: 98 != 49
1: /home/jpff/clamav-0.104.0/unit_tests/check_clamav.c:484:S:cl_scan_api:checked_setup:0: testfiles: 98 != 49
1: /home/jpff/clamav-0.104.0/unit_tests/check_clamav.c:484:S:cl_scan_api:checked_setup:0: testfiles: 98 != 49
1: /home/jpff/clamav-0.104.0/unit_tests/check_clamav.c:484:S:cl_scan_api:checked_setup:0: testfiles: 98 != 49
1: /home/jpff/clamav-0.104.0/unit_tests/check_clamav.c:484:S:cl_scan_api:checked_setup:0: testfiles: 98 != 49
1: /home/jpff/clamav-0.104.0/unit_tests/check_clamav.c:484:S:cl_scan_api:checked_setup:0: testfiles: 98 != 49
1: /home/jpff/clamav-0.104.0/unit_tests/check_clamav.c:484:S:cl_scan_api:checked_setup:0: testfiles: 98 != 49
1: /home/jpff/clamav-0.104.0/unit_tests/check_clamav.c:484:S:cl_scan_api:checked_setup:0: testfiles: 98 != 49
1: /home/jpff/clamav-0.104.0/unit_tests/check_clamav.c:484:S:cl_scan_api:checked_setup:0: testfiles: 98 != 49
1: /home/jpff/clamav-0.104.0/unit_tests/check_clamav.c:484:S:cl_scan_api:checked_setup:0: testfiles: 98 != 49
1: /home/jpff/clamav-0.104.0/unit_tests/check_clamav.c:484:S:cl_scan_api:checked_setup:0: testfiles: 98 != 49
1: /home/jpff/clamav-0.104.0/unit_tests/check_clamav.c:484:S:cl_scan_api:checked_setup:0: testfiles: 98 != 49
1: /home/jpff/clamav-0.104.0/unit_tests/check_clamav.c:484:S:cl_scan_api:checked_setup:0: testfiles: 98 != 49
1: /home/jpff/clamav-0.104.0/unit_tests/check_clamav.c:484:S:cl_scan_api:checked_setup:0: testfiles: 98 != 49
1: /home/jpff/clamav-0.104.0/unit_tests/check_clamav.c:484:S:cl_scan_api:checked_setup:0: testfiles: 98 != 49
1: /home/jpff/clamav-0.104.0/unit_tests/check_clamav.c:484:S:cl_scan_api:checked_setup:0: testfiles: 98 != 49
1: /home/jpff/clamav-0.104.0/unit_tests/check_clamav.c:484:S:cl_scan_api:checked_setup:0: testfiles: 98 != 49
1: /home/jpff/clamav-0.104.0/unit_tests/check_clamav.c:484:S:cl_scan_api:checked_setup:0: testfiles: 98 != 49
1: /home/jpff/clamav-0.104.0/unit_tests/check_clamav.c:484:S:cl_scan_api:checked

and more thesame until

1: NOTICE: Use the 'T' environment variable to adjust testcase timeout
1: 
1: [DEBUG]: stderr: 
1: 
1: --------------------------- Captured stdout teardown ---------------------------
1: 
1: [INFO]: Removed tmp directory: /home/jpff/clamav-0.104.0/unit_tests/TC-e7gix6yb
1: =========================== 1 failed in 2.18 seconds ===========================
 1/10 Test  #1: libclamav ........................***Failed    4.25 sec
micahsnyder commented 3 years ago

Hi @jpffitch!

It looks like you did the build in the same directory as the source. We haven't tested in that way since restructuring our unit test directory and replacing our "split" test files with encrypted test files. It seems we have a bug with the new layout when building and testing in the source directory. Specifically the failure is because the encrypted *.xor test files end up co-located with the unencrypted ones after the build, and then the tests complain that there are more test files than expected:


74a1eb4ee73b:~/clamav-0.104.0 # ls unit_tests/input/clamav_hdb_scanfiles/
clam-aspack.exe      clam-upx.exe         clam.bin-be.cpio      clam.ea06.exe             clam.exe.rtf.xor              clam.odc.cpio      clam.zip
clam-aspack.exe.xor  clam-upx.exe.xor     clam.bin-be.cpio.xor  clam.ea06.exe.xor         clam.exe.szdd                 clam.odc.cpio.xor  clam.zip.xor
clam-fsg.exe         clam-v2.rar          clam.bin-le.cpio      clam.exe                  clam.exe.szdd.xor             clam.ole.doc       clam_IScab_ext.exe
clam-fsg.exe.xor     clam-v2.rar.xor      clam.bin-le.cpio.xor  clam.exe.binhex           clam.exe.xor                  clam.ole.doc.xor   clam_IScab_ext.exe.xor
clam-mew.exe         clam-v3.rar          clam.bz2.zip          clam.exe.binhex.xor       clam.exe_and_mail.tar.gz      clam.pdf           clam_IScab_int.exe
clam-mew.exe.xor     clam-v3.rar.xor      clam.bz2.zip.xor      clam.exe.bz2              clam.exe_and_mail.tar.gz.xor  clam.pdf.xor       clam_IScab_int.exe.xor
clam-nsis.exe        clam-wwpack.exe      clam.cab              clam.exe.bz2.xor          clam.impl.zip                 clam.ppt           clam_ISmsi_ext.exe
clam-nsis.exe.xor    clam-wwpack.exe.xor  clam.cab.xor          clam.exe.html             clam.impl.zip.xor             clam.ppt.xor       clam_ISmsi_ext.exe.xor
clam-pespin.exe      clam-yc.exe          clam.chm              clam.exe.html.xor         clam.iso                      clam.sis           clam_ISmsi_int.exe
clam-pespin.exe.xor  clam-yc.exe.xor      clam.chm.xor          clam.exe.mbox.base64      clam.iso.xor                  clam.sis.xor       clam_ISmsi_int.exe.xor
clam-petite.exe      clam.7z              clam.d64.zip          clam.exe.mbox.base64.xor  clam.mail                     clam.tar.gz        clam_cache_emax.tgz
clam-petite.exe.xor  clam.7z.xor          clam.d64.zip.xor      clam.exe.mbox.uu          clam.mail.xor                 clam.tar.gz.xor    clam_cache_emax.tgz.xor
clam-upack.exe       clam.arj             clam.ea05.exe         clam.exe.mbox.uu.xor      clam.newc.cpio                clam.tnef          clamjol.iso
clam-upack.exe.xor   clam.arj.xor         clam.ea05.exe.xor     clam.exe.rtf              clam.newc.cpio.xor            clam.tnef.xor      clamjol.iso.xor

Sorry about the confusion, and thanks for submitting this bug report!

We would have to store the encrypted test files in a different location to resolve this issue. Best practice is to do the build in a different directory anyways, like a subdirectory, or a directory outside of the source directory. So I'm not sure if it's worth fixing, but we should at least put a check during the build to stop people from running into this issue and to require doing the build in a different directory.

jpffitch commented 3 years ago

I did not intend buildinfd in the source directory. I issued mkdir build; cd build; cmake ..

and tere were no file in build and the last mesage was that ir had copied files into the parent directory of build. So I wenr back a level andram make.

That was wjhat I wastrying to express as "odd build"

What should I have done?

PS I tried the debian package but I failed to work out how to imstall it; another oddity but then I do not know whether I could specify the user/grpup

micahsnyder commented 3 years ago

Hi sorry I missed your response earlier.

CMake can be a little funny. If you do cmake . in the source directory once, it creates a CMakeFiles directory and and CMakeCache.txt file that store your configuration. Then if you try doing it again from a subdirectory like mkdir build && cd build && cmake .., it will just build in the source directory where you configured from rather than re-configure in your current directory. So if you do ls in your current build directory, you'll find it's still empty. And if you do make from that empty build subdirectory, you'll get:

❯ make
make: *** No targets specified and no makefile found.  Stop.

What you want to do is start over. Either delete the CMakeFiles directory and and CMakeCache.txt file, or better yet untar a fresh copy of the source. Then try again, this time only ever running cmake from a build subdirectory. You can follow these instructions: https://docs.clamav.net/manual/Installing/Installing-from-source-Unix.html#build-clamav

To-do for the clamav team: Let's either:

  1. add a check in CMake to ensure users never try to build from the source directory so folks run into this.
  2. use a different name for the testfile directory where decrypted test files are dropped so this doesn't confuse the test.