gparted/tests
Mike Fleetwood cc4687a2aa Also check links to block devices when skipping BlockSpecial unit tests (!113)
Fragment of a failed CI test job from a GiLab job runner which didn't
allow creation of block special devices looked like:

    $ tests/makedev.sh
    mknod -m 0660 /dev/sda b 8 0
    mknod: '/dev/sda': Operation not permitted
    chown: cannot access '/dev/sda': No such file or directory
    mknod -m 0660 /dev/sda1 b 8 1
    mknod: '/dev/sda1': Operation not permitted
    chown: cannot access '/dev/sda1': No such file or directory
    mkdir: created directory '/dev/disk'
    mkdir: created directory '/dev/disk/by-id/'
    '/dev/disk/by-id/gparted-sda' -> '/dev/sda'

test/makedev.sh attempted to create two block devices it wanted for
testing, but that failed with "Operation not permitted".  It then
created dangling symbolic link /dev/disk/by-id/gparted-sda -> /dev/sda;
gparted-sda pointed to a name which didn't exist.

Despite the previous commit testing and skipping every test where the
block device doesn't exist this unit test still failed:

    [ RUN      ] BlockSpecialTest.NamedBlockSpecialObjectBySymlinkMatches
    test_BlockSpecial.cc:186: Failure
    Failed
    follow_link_name(): Failed to resolve symbolic link '/dev/disk/by-id/gparted-sda'
    test_BlockSpecial.cc:271: Skip test.  Block device '' does not exist
    [  FAILED  ] BlockSpecialTest.NamedBlockSpecialObjectBySymlinkMatches (0 ms)

The unit test called get_link_name() which read the directory
/dev/disk/by-id and found symbolic link gparted-sda.  It then called
follow_link_name() passing /dev/disk/by-id/gparted-sda which used
realpath(3) to get the canonicalised absolute pathname, which includes
following links.  But as gparted-sda pointed to a non-existent file it
failed and reported message "Failed to resolve symbolic link ...".  Then
after that the unit test skips the non-existent block device, but the
test has already failed at that point.

Fix the unit test by also checking the symbolic link points to an
existing block device before calling follow_link_name() on it.  This
works because SKIP_IF_BLOCK_DEVICE_DOESNT_EXIST() uses stat(3), which
follows symbolic links, in it's verification.

Also put SKIP_IF_BLOCK_DEVICE_DOESNT_EXIST() immediately after each
initialisation of a block device name for some sort of consistency with
it's need in this fixed NamedBlockSpecialObjectBySymlinkMatches unit
test.

Closed !113 - Fix occasional GitLab CI test jobs failures on
              BlockSpecial unit tests
2023-05-20 16:18:11 +00:00
..
common.cc Move duplicated test code into shared modules (#220) 2023-02-13 16:33:57 +00:00
common.h Move duplicated test code into shared modules (#220) 2023-02-13 16:33:57 +00:00
exclude_loopdev_tests.sh Automate exclusion of loop device tests from CI image (!105) 2022-08-25 15:41:31 +00:00
insertion_operators.cc Move duplicated test code into shared modules (#220) 2023-02-13 16:33:57 +00:00
insertion_operators.h Move duplicated test code into shared modules (#220) 2023-02-13 16:33:57 +00:00
makedev.sh Add /dev/disk/by-id/ symlink in CI for test_BlockSpecial 2020-03-14 15:31:37 +00:00
Makefile.am Move duplicated test code into shared modules (#220) 2023-02-13 16:33:57 +00:00
test_BlockSpecial.cc Also check links to block devices when skipping BlockSpecial unit tests (!113) 2023-05-20 16:18:11 +00:00
test_dummy.cc Add unit test suites with initial successful dummy test (#781978) 2017-06-02 10:13:16 -06:00
test_EraseFileSystemSignatures.cc Add unit test of erasing Promise FastTrack RAID signatures (#220) 2023-02-13 16:33:57 +00:00
test_PasswordRAMStore.cc Resolve compiler warning from gen_password() 2023-02-13 16:33:57 +00:00
test_PipeCapture.cc Move duplicated test code into shared modules (#220) 2023-02-13 16:33:57 +00:00
test_SupportedFileSystems.cc Replace fragment of unit test code with trim_trailing_new_line() 2023-02-13 16:33:57 +00:00