Skip to content

Commit 1432aa4

Browse files
author
=
committed
Updated python binding unit tests
This commit updates the Python bindings unit tests simplifyig the build and test process (moved from explicit commands to cibuildwheels)
1 parent 877eba0 commit 1432aa4

4 files changed

Lines changed: 46 additions & 132 deletions

File tree

.github/workflows/ci-test.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ jobs:
4343
apt-get update
4444
apt-get install -y git \
4545
cmake make ninja-build sudo \
46-
python3 python3-pip python3-venv \
47-
libcurl4-gnutls-dev
46+
python3 python3-pip python3-venv
4847
4948
- name: "Run CMake"
5049
shell: bash
@@ -77,7 +76,7 @@ jobs:
7776
sudo apt-get install -y git \
7877
cmake make ninja-build sudo \
7978
python3 python3-pip python3-venv \
80-
gcc g++ libcurl4-gnutls-dev
79+
gcc g++
8180
8281
- name: "Compile tests"
8382
run: |
Lines changed: 37 additions & 119 deletions
Original file line numberDiff line numberDiff line change
@@ -1,139 +1,57 @@
1-
name: "Python Bindings Unit Tests"
1+
name: "Python Bindings Build & Test"
2+
23
on:
34
push:
4-
branches:
5-
- main
5+
branches: [ main ]
66
pull_request:
7-
branches:
8-
- main
7+
branches: [ main ]
8+
99
concurrency:
1010
group: build-python-${{ github.event.pull_request.number || github.ref }}
1111
cancel-in-progress: true
12+
1213
jobs:
13-
python-tests:
14-
name: "Test Python bindings"
14+
build_wheels:
15+
name: Build wheels on ${{ matrix.os }}
16+
runs-on: ${{ matrix.os }}
1517
strategy:
1618
matrix:
17-
on: [ 'ubuntu-24.04', 'macos-15-intel', 'macos-26' ]
18-
python: [ '3.10', '3.11', '3.12', '3.13', '3.14' ]
19+
os:
20+
- 'ubuntu-24.04'
21+
- 'ubuntu-24.04-arm'
22+
- 'macos-26-intel'
23+
- 'macos-26'
1924

20-
runs-on: ${{ matrix.on }}
2125
env:
22-
INSTALL_PREFIX: "/usr/local"
23-
24-
steps:
25-
- name: "Checkout repository"
26-
uses: actions/checkout@v6
27-
28-
- name: "Set up Python ${{ matrix.python }}"
29-
uses: actions/setup-python@v6
30-
with:
31-
python-version: ${{ matrix.python }}
32-
33-
# Install platform build dependencies
34-
- name: "Install system packages (Ubuntu)"
35-
if: startsWith(matrix.on, 'ubuntu-')
36-
run: sudo apt-get update && sudo apt-get install -y ninja-build g++ cmake libcurl4-gnutls-dev
37-
38-
- name: "Setup Homebrew (macOS)"
39-
if: startsWith(matrix.on, 'macos-')
40-
uses: Homebrew/actions/setup-homebrew@main
41-
42-
- name: "Install system packages (macOS)"
43-
if: startsWith(matrix.on, 'macos-')
44-
run: brew install ninja gcc cmake curl
45-
46-
- name: "Create virtual environment"
47-
run: |
48-
pip install -r build-requirements.txt
49-
pip install -r test-requirements.txt
26+
CIBW_BEFORE_ALL_LINUX: >
27+
pip install cmake ninja
28+
CIBW_BEFORE_ALL_MACOS: >
29+
brew install ninja gcc cmake curl
5030
51-
# Install Python build dependencies
52-
- name: "Build and Install Python package"
53-
run: |
54-
mkdir -p /tmp/capio_cl_jsons
55-
mkdir -p /tmp/capio_cl_tomls
56-
cp -r tests/jsons/* /tmp/capio_cl_jsons
57-
cp -r tests/tomls/* /tmp/capio_cl_tomls
58-
pip install .
31+
CIBW_BEFORE_BUILD: >
32+
pip install -r build-requirements.txt &&
33+
mkdir -p /tmp/capio_cl_jsons /tmp/capio_cl_tomls &&
34+
cp -r tests/jsons/* /tmp/capio_cl_jsons/ &&
35+
cp -r tests/tomls/* /tmp/capio_cl_tomls/
5936
60-
# Run unit tests
61-
- name: "Run Python tests (Ubuntu)"
62-
if: startsWith(matrix.on, 'ubuntu-')
63-
run: |
64-
pytest -v tests/python/test_*
37+
CIBW_BEFORE_TEST: pip install -r test-requirements.txt
6538

66-
- name: "Run Python tests (MacOS)"
67-
if: startsWith(matrix.on, 'macos-')
68-
run: |
69-
pytest -k "not test_home_node" -v tests/python/test_*
39+
CIBW_TEST_COMMAND_LINUX: "pytest -v {project}/tests/python/test_*"
40+
CIBW_TEST_COMMAND_MACOS: "pytest -k 'not test_home_node' -v {project}/tests/python/test_*"
7041

71-
72-
- name: "Generate coverage report"
73-
if: ${{ startsWith(matrix.on, 'ubuntu-') }}
74-
run: |
75-
pip install --upgrade gcovr
76-
gcovr \
77-
--exclude-throw-branches \
78-
--gcov-ignore-parse-errors=negative_hits.warn \
79-
--exclude tests/ \
80-
--xml coverage.xml \
81-
.
82-
83-
- name: "Upload coverage report"
84-
if: ${{ startsWith(matrix.on, 'ubuntu-') }}
85-
uses: actions/upload-artifact@v7
86-
with:
87-
name: ${{ format('{0}-{1}-tests', matrix.on, matrix.python) }}
88-
path: ./coverage.xml
89-
retention-days: 1
90-
if-no-files-found: error
91-
92-
riscv-tests:
93-
name: "Build & Test on RISC-V (QEMU)"
94-
strategy:
95-
matrix:
96-
python: [ '3.10', '3.11', '3.12', '3.13', '3.14' ]
97-
runs-on: ubuntu-latest
98-
99-
env:
100-
INSTALL_PREFIX: "/usr/local"
101-
PYTHON_VERSION: "${{ matrix.python }}"
42+
CIBW_BUILD: "cp310-* cp311-* cp312-* cp313-* cp314-*"
10243

10344
steps:
104-
- name: "Checkout repository"
45+
- name: Checkout repository
10546
uses: actions/checkout@v6
10647

107-
- name: "Build and test inside RISC-V emulated environment (Debian based)"
108-
uses: uraimo/run-on-arch-action@v3
109-
with:
110-
arch: riscv64
111-
distro: ubuntu_latest
112-
githubToken: ${{ github.token }}
113-
114-
install: |
115-
apt-get update
116-
DEBIAN_FRONTEND=noninteractive apt-get install -y \
117-
python3 python3-pip python3-venv python3-wheel python3-setuptools \
118-
g++ cmake ninja-build git
119-
120-
run: |
121-
set -eux
122-
echo "Building for RISC-V on Ubuntu 22.04"
123-
124-
python3 -m pip install -r build-requirements.txt --break-system-packages
125-
126-
mkdir -p /tmp/capio_cl_jsons
127-
mkdir -p /tmp/capio_cl_tomls
128-
cp -r tests/jsons/* /tmp/capio_cl_jsons
129-
cp -r tests/tomls/* /tmp/capio_cl_tomls
130-
131-
python3 -m build \
132-
-Ccmake.define.ENABLE_COVERAGE=OFF \
133-
-Ccmake.build-type=Release \
134-
-Ccmake.define.CAPIO_CL_BUILD_TESTS=OFF
135-
136-
pip install dist/*.whl --break-system-packages
137-
python3 -m pip install -r test-requirements.txt --break-system-packages
48+
- name: Build wheels
49+
uses: pypa/cibuildwheel@v3.4.0
50+
env:
51+
MACOSX_DEPLOYMENT_TARGET: "10.15"
13852

139-
pytest -v tests/python/test_* | tee pytest-riscv.log
53+
- name: Upload artifacts
54+
uses: actions/upload-artifact@v4
55+
with:
56+
name: cibw-wheels-${{ matrix.os }}-${{ strategy.job-index }}
57+
path: ./wheelhouse/*.whl

CMakeLists.txt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,6 @@ endif ()
181181
#####################################
182182
if (CAPIO_CL_BUILD_TESTS)
183183

184-
find_package(CURL REQUIRED)
185-
186184
message(STATUS "Building CAPIO-CL tests")
187185

188186
FetchContent_Declare(
@@ -199,7 +197,6 @@ if (CAPIO_CL_BUILD_TESTS)
199197
target_link_libraries(CAPIO_CL_tests PRIVATE
200198
libcapio_cl
201199
GTest::gtest_main
202-
CURL::libcurl
203200
)
204201

205202
if(LIBANL)

src/api.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
#include <arpa/inet.h>
22
#include <condition_variable>
3-
#include <iostream>
3+
#include <csignal>
44
#include <jsoncons/json.hpp>
55
#include <mutex>
66
#include <netinet/in.h>
7-
#include <signal.h>
87
#include <sys/socket.h>
8+
#include <sys/time.h>
99
#include <unistd.h>
1010

1111
#include "capiocl/api.h"
1212
#include "capiocl/engine.h"
1313
#include "capiocl/printer.h"
1414

15-
std::mutex _setupMtx;
16-
std::condition_variable _setupCv;
15+
std::mutex setupMtx;
16+
std::condition_variable setupCv;
1717
bool thread_ready = false;
1818

1919
/// @brief Main WebServer thread function
@@ -52,7 +52,7 @@ void server(const std::string &address, const int port, capiocl::engine::Engine
5252
setsockopt(fd, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));
5353

5454
thread_ready = true;
55-
_setupCv.notify_all();
55+
setupCv.notify_all();
5656

5757
while (!*terminate) {
5858
// GCOVR_EXCL_START
@@ -120,8 +120,8 @@ capiocl::api::CapioClApiServer::CapioClApiServer(engine::Engine *engine,
120120

121121
_webApiThread = std::thread(server, address, port, engine, &_terminate);
122122

123-
std::unique_lock lock(_setupMtx);
124-
_setupCv.wait(lock, [] { return thread_ready; });
123+
std::unique_lock lock(setupMtx);
124+
setupCv.wait(lock, [] { return thread_ready; });
125125

126126
printer::print(printer::CLI_LEVEL_INFO, "API server @ " + address + ":" + std::to_string(port));
127127
}

0 commit comments

Comments
 (0)