Commit e3ff9bd3 authored by Ramon Nou's avatar Ramon Nou
Browse files

Truncate errors test

parent 3574e007
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -50,11 +50,11 @@ gkfs:
  needs: []
  script:
    # Change config.hpp with sed to enable extra features
    - sed -i 's/\/\/constexpr auto use_atime = false;/constexpr auto use_atime = true;/g' "${CI_PROJECT_DIR}/src/config.hpp"
    - sed -i 's/\/\/constexpr auto use_ctime = false;/constexpr auto use_ctime = true;/g' "${CI_PROJECT_DIR}/src/config.hpp"
    - sed -i 's/\/\/constexpr auto use_mtime = false;/constexpr auto use_mtime = true;/g' "${CI_PROJECT_DIR}/src/config.hpp"
    - sed -i 's/\/\/constexpr auto use_link_cnt = false;/constexpr auto use_link_cnt = true;/g' "${CI_PROJECT_DIR}/src/config.hpp"
    - sed -i 's/\/\/constexpr auto use_blocks = false;/constexpr auto use_blocks = true;/g' "${CI_PROJECT_DIR}/src/config.hpp"
    - sed -i 's/\/\/constexpr auto use_atime = false;/constexpr auto use_atime = true;/g' "${CI_PROJECT_DIR}/src/include/config.hpp"
    - sed -i 's/\/\/constexpr auto use_ctime = false;/constexpr auto use_ctime = true;/g' "${CI_PROJECT_DIR}/src/include/config.hpp"
    - sed -i 's/\/\/constexpr auto use_mtime = false;/constexpr auto use_mtime = true;/g' "${CI_PROJECT_DIR}/src/include/config.hpp"
    - sed -i 's/\/\/constexpr auto use_link_cnt = false;/constexpr auto use_link_cnt = true;/g' "${CI_PROJECT_DIR}/src/include/config.hpp"
    - sed -i 's/\/\/constexpr auto use_blocks = false;/constexpr auto use_blocks = true;/g' "${CI_PROJECT_DIR}/src/include/config.hpp"
    - mkdir -p ${BUILD_PATH} && cd ${BUILD_PATH}
    - cmake
      -Wdev
+33 −0
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@
# from pathlib import Path
import os
import stat
import errno


# @pytest.mark.xfail(reason="invalid errno returned on success")
@@ -121,3 +122,35 @@ def test_truncate(gkfs_daemon, gkfs_client):
    ret = gkfs_client.file_compare(truncfile, truncfile_verify_2, trunc_size)

    assert ret.retval == 0


# Tests failure cases
def test_fail_truncate(gkfs_daemon, gkfs_client):
    truncfile = gkfs_daemon.mountdir / "trunc_file2"
    # open and create test file
    ret = gkfs_client.open(truncfile, os.O_CREAT | os.O_WRONLY, stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO)

    assert ret.retval != -1

    buf_length = 256
    ret = gkfs_client.write_random(truncfile, buf_length)
    assert ret.retval == buf_length

    ret = gkfs_client.truncate(truncfile, buf_length)
    assert ret.retval == 0

    # Size should not change
    ret = gkfs_client.stat(truncfile)
    assert ret.statbuf.st_size == buf_length

    # Truncate to a negative size
    ret = gkfs_client.truncate(truncfile, -1)
    assert ret.retval == -1
    assert ret.errno == errno.EINVAL

    # Truncate to a size greater than the file size
    ret = gkfs_client.truncate(truncfile, buf_length + 1)
    assert ret.retval == -1
    assert ret.errno == errno.EINVAL