From dfe1d008f14ad368c88e0fae2067127a57529b56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferm=C3=ADn=20Olaiz?= Date: Wed, 4 Dec 2024 23:07:49 -0300 Subject: [PATCH 01/12] git: ignore .idea --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index d8e39552..5ac20b87 100644 --- a/.gitignore +++ b/.gitignore @@ -31,3 +31,5 @@ gui/app/resources/app.gresource rmlint.*.sh rmlint.*.json +# JetBrains' IDE +.idea From ba2eb82fb9bdb71ac4f2d2a21ae03338a32c31ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferm=C3=ADn=20Olaiz?= Date: Wed, 4 Dec 2024 23:17:36 -0300 Subject: [PATCH 02/12] gh-actions: add initial build+test job --- .github/workflows/build-and-test.yml | 30 +++++++++++++++++++ .travis.yml | 24 --------------- .../requirements.txt | 1 + 3 files changed, 31 insertions(+), 24 deletions(-) create mode 100644 .github/workflows/build-and-test.yml delete mode 100644 .travis.yml rename test-requirements.txt => tests/requirements.txt (81%) diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml new file mode 100644 index 00000000..a0a60fb9 --- /dev/null +++ b/.github/workflows/build-and-test.yml @@ -0,0 +1,30 @@ +name: Build and test rmlint (master) + +on: + push: + branches: + - master + +jobs: + build: + runs-on: ubuntu-latest + env: + RM_TS_DIR: "/tmp/rmlint-unit-testdir" + steps: + - uses: actions/checkout@v4 + - name: Set up build environment + run: | + apt update + apt install -y --no-install-recommends \ + scons python3-sphinx gettext python3-setuptools \ + libblkid-dev libelf-dev libglib2.0-dev libjson-glib-dev \ + clang python3-pip python3-cffi python3-dev libffi-dev + pip3 install -r tests/requirements.txt + - name: Build + # Todo: eventually run tests with valgrind (RM_TS_USE_VALGRIND) + # Todo enable slow tests in pytest + run: | + scons config + scons VERBOSE=1 DEBUG=1 O=release + mkdir -p "${RM_TS_DIR}" + RM_TS_PRINT_CMD=1 RM_TS_PEDANTIC=0 python -m pytest diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 1b11f23e..00000000 --- a/.travis.yml +++ /dev/null @@ -1,24 +0,0 @@ -language: c - -install: - - sudo apt-get update - - sudo apt-get install scons python3-sphinx gettext python3-setuptools - - sudo apt-get install libblkid-dev libelf-dev libglib2.0-dev libjson-glib-dev - - sudo apt-get install clang python3-pip python3-cffi libffi-dev - - sudo pip3 install -r test-requirements.txt - -compiler: - - clang - - gcc - -notifications: - email: - - sahib@online.de - - thomas_d_j@yahoo.com.au - -script: - - scons VERBOSE=1 DEBUG=1 O=release - - scons config - - export RM_TS_PRINT_CMD=1 - - export RM_TS_PEDANTIC=0 - - sudo -E nosetests -s -v -a '!slow' diff --git a/test-requirements.txt b/tests/requirements.txt similarity index 81% rename from test-requirements.txt rename to tests/requirements.txt index 1882435d..79ec5370 100644 --- a/test-requirements.txt +++ b/tests/requirements.txt @@ -1,4 +1,5 @@ nose==1.3.7 +pytest==8.3.4 parameterized==0.6.1 xattr==0.9.6 psutil==5.6.6 From 126d53d0ebc51bea363fc587595fb25b54253363 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferm=C3=ADn=20Olaiz?= Date: Thu, 5 Dec 2024 00:06:05 -0300 Subject: [PATCH 03/12] tests: cleanup test directory between tests --- .github/workflows/build-and-test.yml | 2 +- tests/conftest.py | 7 +++++++ tests/utils.py | 10 ++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 tests/conftest.py diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index a0a60fb9..336f9656 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -26,5 +26,5 @@ jobs: run: | scons config scons VERBOSE=1 DEBUG=1 O=release - mkdir -p "${RM_TS_DIR}" + rm -rfv "${RM_TS_DIR}"; mkdir "${RM_TS_DIR}" RM_TS_PRINT_CMD=1 RM_TS_PEDANTIC=0 python -m pytest diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 00000000..a900bc5b --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,7 @@ +import pytest +from tests.utils import cleanup_testdir, create_testdir + +@pytest.fixture(autouse=True) +def with_cleanup_between_runs(): + cleanup_testdir() + create_testdir() diff --git a/tests/utils.py b/tests/utils.py index 47ade03e..469175f8 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -78,6 +78,16 @@ def create_testdir(*extra_path): except OSError: pass +def cleanup_testdir(*extra_path): + try: + path = TESTDIR_NAME + if extra_path: + path = os.path.join(TESTDIR_NAME, *extra_path) + + subprocess.run(["/bin/bash", "-c", f"rm -rf '{path}'"]) + except OSError: + pass + def which(program): def is_exe(fpath): From 4fec69f8d56c0e70632c02f683d14aaa4b73585e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferm=C3=ADn=20Olaiz?= Date: Thu, 5 Dec 2024 00:55:14 -0300 Subject: [PATCH 04/12] gh-actions: use tmpfs for files --- .github/workflows/build-and-test.yml | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index 336f9656..f6fc528c 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -12,7 +12,7 @@ jobs: RM_TS_DIR: "/tmp/rmlint-unit-testdir" steps: - uses: actions/checkout@v4 - - name: Set up build environment + - name: "Prepare build environment" run: | apt update apt install -y --no-install-recommends \ @@ -20,11 +20,16 @@ jobs: libblkid-dev libelf-dev libglib2.0-dev libjson-glib-dev \ clang python3-pip python3-cffi python3-dev libffi-dev pip3 install -r tests/requirements.txt - - name: Build + - name: "Build" # Todo: eventually run tests with valgrind (RM_TS_USE_VALGRIND) # Todo enable slow tests in pytest run: | scons config scons VERBOSE=1 DEBUG=1 O=release - rm -rfv "${RM_TS_DIR}"; mkdir "${RM_TS_DIR}" + - name: "Prepare test environment" + # Based off https://github.com/LeastAuthority/mount-tmpfs-action + run: | + mount -o size=14G,nr_inodes=0 -t tmpfs tmpfs "${RM_TS_DIR}" + - name: "Test" + run: | RM_TS_PRINT_CMD=1 RM_TS_PEDANTIC=0 python -m pytest From 774ddd5e193b1c1680244d5949b081980f2eaa78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferm=C3=ADn=20Olaiz?= Date: Thu, 5 Dec 2024 19:01:57 -0300 Subject: [PATCH 05/12] gh-actions: enable build-and-test on PRs --- .github/workflows/build-and-test.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index f6fc528c..14d9225a 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -1,6 +1,8 @@ name: Build and test rmlint (master) on: + pull_request: + types: [opened, synchronize, reopened] push: branches: - master From 2a639c83d8c778d484047378ae11f43ed103a739 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferm=C3=ADn=20Olaiz?= Date: Thu, 5 Dec 2024 19:04:58 -0300 Subject: [PATCH 06/12] gh-actions: use sudo where necessary --- .github/workflows/build-and-test.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index 14d9225a..725b4738 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -16,8 +16,8 @@ jobs: - uses: actions/checkout@v4 - name: "Prepare build environment" run: | - apt update - apt install -y --no-install-recommends \ + sudo apt update + sudo apt install -y --no-install-recommends \ scons python3-sphinx gettext python3-setuptools \ libblkid-dev libelf-dev libglib2.0-dev libjson-glib-dev \ clang python3-pip python3-cffi python3-dev libffi-dev @@ -31,7 +31,7 @@ jobs: - name: "Prepare test environment" # Based off https://github.com/LeastAuthority/mount-tmpfs-action run: | - mount -o size=14G,nr_inodes=0 -t tmpfs tmpfs "${RM_TS_DIR}" + sudo mount -o size=14G,nr_inodes=0 -t tmpfs tmpfs "${RM_TS_DIR}" - name: "Test" run: | RM_TS_PRINT_CMD=1 RM_TS_PEDANTIC=0 python -m pytest From 8305af4f57f1ef55a60c91dcc277a347294695c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferm=C3=ADn=20Olaiz?= Date: Thu, 5 Dec 2024 19:06:18 -0300 Subject: [PATCH 07/12] gh-actions: create tmp dir --- .github/workflows/build-and-test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index 725b4738..f3c83937 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -31,6 +31,7 @@ jobs: - name: "Prepare test environment" # Based off https://github.com/LeastAuthority/mount-tmpfs-action run: | + sudo mkdir "${RM_TS_DIR}" sudo mount -o size=14G,nr_inodes=0 -t tmpfs tmpfs "${RM_TS_DIR}" - name: "Test" run: | From 0ebb71fa668991a3b5cf5767731ee319e9eeff84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferm=C3=ADn=20Olaiz?= Date: Sat, 7 Dec 2024 18:55:33 -0300 Subject: [PATCH 08/12] tests: cleanup test dir with shutil.rmtree Co-authored-by: Yaroslav Halchenko --- tests/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/utils.py b/tests/utils.py index 469175f8..aa0a73c3 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -84,7 +84,7 @@ def cleanup_testdir(*extra_path): if extra_path: path = os.path.join(TESTDIR_NAME, *extra_path) - subprocess.run(["/bin/bash", "-c", f"rm -rf '{path}'"]) + shutil.rmtree(path, ignore_errors=True) except OSError: pass From 8962c777fc94ab6a327023d85097616f2e048160 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferm=C3=ADn=20Olaiz?= Date: Sat, 7 Dec 2024 18:58:43 -0300 Subject: [PATCH 09/12] tests: simplify cleanup_testdir() --- tests/utils.py | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/tests/utils.py b/tests/utils.py index aa0a73c3..55a165e6 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -78,15 +78,9 @@ def create_testdir(*extra_path): except OSError: pass -def cleanup_testdir(*extra_path): - try: - path = TESTDIR_NAME - if extra_path: - path = os.path.join(TESTDIR_NAME, *extra_path) - shutil.rmtree(path, ignore_errors=True) - except OSError: - pass +def cleanup_testdir(): + shutil.rmtree(TESTDIR_NAME, ignore_errors=True) def which(program): From ebd84dfc118ae43676d051ae33363bd39545c365 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferm=C3=ADn=20Olaiz?= Date: Sat, 7 Dec 2024 19:00:09 -0300 Subject: [PATCH 10/12] tests: show detailed information on test runs Co-authored-by: Yaroslav Halchenko --- .github/workflows/build-and-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index f3c83937..238035ed 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -35,4 +35,4 @@ jobs: sudo mount -o size=14G,nr_inodes=0 -t tmpfs tmpfs "${RM_TS_DIR}" - name: "Test" run: | - RM_TS_PRINT_CMD=1 RM_TS_PEDANTIC=0 python -m pytest + RM_TS_PRINT_CMD=1 RM_TS_PEDANTIC=0 python -m pytest -s -v From a91aac8d168671dacbd48fb89e71ff911503485c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferm=C3=ADn=20Olaiz?= Date: Sat, 7 Dec 2024 19:05:05 -0300 Subject: [PATCH 11/12] tests: add comment on github-runner specifics --- .github/workflows/build-and-test.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index 238035ed..35987de5 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -29,7 +29,9 @@ jobs: scons config scons VERBOSE=1 DEBUG=1 O=release - name: "Prepare test environment" - # Based off https://github.com/LeastAuthority/mount-tmpfs-action + # The test suite is seriously disk-intensive. Given that linux + # instances hosted in GitHub have 16G of RAM available we will + # use it to speed up the run. run: | sudo mkdir "${RM_TS_DIR}" sudo mount -o size=14G,nr_inodes=0 -t tmpfs tmpfs "${RM_TS_DIR}" From 809966c60926dee0161f8fd6c7f83e92387dfb7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ferm=C3=ADn=20Olaiz?= Date: Sat, 7 Dec 2024 19:08:38 -0300 Subject: [PATCH 12/12] gh-actions: decrease tests tmpfs to 12G --- .github/workflows/build-and-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-and-test.yml b/.github/workflows/build-and-test.yml index 35987de5..7b8bd93c 100644 --- a/.github/workflows/build-and-test.yml +++ b/.github/workflows/build-and-test.yml @@ -34,7 +34,7 @@ jobs: # use it to speed up the run. run: | sudo mkdir "${RM_TS_DIR}" - sudo mount -o size=14G,nr_inodes=0 -t tmpfs tmpfs "${RM_TS_DIR}" + sudo mount -o size=12G,nr_inodes=0 -t tmpfs tmpfs "${RM_TS_DIR}" - name: "Test" run: | RM_TS_PRINT_CMD=1 RM_TS_PEDANTIC=0 python -m pytest -s -v