Skip to content

Commit

Permalink
Merge pull request #256 from Cskorpion/tests-in-github-ci
Browse files Browse the repository at this point in the history
Tests in GitHub CI
  • Loading branch information
cfbolz committed Sep 5, 2023
2 parents a1a1b52 + 8cc7cc5 commit b1d242b
Show file tree
Hide file tree
Showing 11 changed files with 121 additions and 71 deletions.
32 changes: 16 additions & 16 deletions .github/workflows/cibuildwheel.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
name: Test
name: build-wheels

# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the master branch
push:
branches: [ master ]
branches: [ master, unstuck-vmprof ]
pull_request:
branches: [ master ]
branches: [ master, unstuck-vmprof ]

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
Expand All @@ -18,24 +18,24 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ubuntu-20.04, windows-2019, macos-10.15]
os: [ubuntu-20.04, windows-2019, macos-latest]

steps:
# Note: the action happens inside a docker image
- uses: actions/checkout@v2
- uses: actions/checkout@v3

- name: Build wheels
uses: pypa/cibuildwheel@v2.1.3
uses: pypa/cibuildwheel@v2.11.4
env:
CIBW_MANYLINUX_X86_64_IMAGE: manylinux2014
CIBW_MANYLINUX_I686_IMAGE: manylinux2014
CIBW_SKIP: "pp* *-win32 *-manylinux_i686"
CIBW_SKIP: "pp* *-win32 *-manylinux_i686 *musllinux*"
CIBW_BEFORE_BUILD_LINUX: yum install -y libunwind-devel elfutils-libelf-devel libdwarf-devel
CIBW_BEFORE_TEST: pip install -r test_requirements.txt
CIBW_TEST_COMMAND: cd {package} && pytest vmprof jitlog
CIBW_TEST_COMMAND: cd {package} && pytest vmprof jitlog -vv
CIBW_TEST_COMMAND_WINDOWS: cd /d {package} && pytest vmprof jitlog -vv

- uses: actions/upload-artifact@v2
- uses: actions/upload-artifact@v3
with:
path: ./wheelhouse/*.whl

Expand All @@ -48,10 +48,10 @@ jobs:

steps:
# Note: not inside a docker
- uses: actions/checkout@v2
- uses: actions/setup-python@v2
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
with:
python-version: 'pypy-3.7'
python-version: 'pypy-3.9'

- name: Install system libraries
run: sudo apt install -y libunwind-dev libelf-dev libdwarf-dev
Expand All @@ -68,8 +68,8 @@ jobs:
run: |
FAILED=false
pypy -m pip install -r test_requirements.txt
pypy -m pytest vmprof || FAILED=true
pypy -m pytest jitlog || FAILED=true
pypy -m pytest vmprof -v || FAILED=true
pypy -m pytest jitlog -v || FAILED=true
if [ "FAILED" == true ]; then exit 1; fi
# Uh-oh. packaging.tags does not support a pp3-none-any wheel tag.
# The wheel name is something like
Expand All @@ -79,7 +79,7 @@ jobs:
# Once https://github.com/pypa/packaging/pull/466 goes in, uncomment
# mv vmprof*-{py3,pp3}-none-any.whl
- uses: actions/upload-artifact@v2
- uses: actions/upload-artifact@v3
with:
path: ./wheelhouse/*.whl
path: vmprof*.whl

50 changes: 50 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: test

on:
push:
branches: [master, unstuck-vmprof]
pull_request:
branches: [master, unstuck-vmprof]
workflow_dispatch:

jobs:
test:
runs-on: ${{ matrix.os }}
permissions:
pull-requests: write
name: ${{ matrix.os }} - ${{ matrix.python }}
strategy:
fail-fast: false
matrix:
# Test all supported versions on Ubuntu:
os: [ubuntu-latest]
python: ["3.9", "3.10", "pypy-3.9"]
experimental: [false]
# include:
# - os: macos-latest
# python: "3.10"
# experimental: false
# - os: windows-latest
# python: "3.10"
# experimental: false
steps:
- uses: actions/checkout@v3
- name: Install libunwind
run: |
sudo apt install -y libunwind-dev
pkg-config libunwind --cflags --libs-only-l
- name: Set up Python ${{ matrix.python }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python }}
- name: Install
run: |
python -m pip install --upgrade pip setuptools
python -m pip install -e .
python -m pip install -r test_requirements.txt
- name: Display Python version
run: python -c "import sys; print(sys.version)"
- name: Run Tests
id: vmprof
run: python -m pytest -v vmprof jitlog

4 changes: 2 additions & 2 deletions jitlog/test/test_encoding.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# coding: utf-8
import sys
import py
import pytest
from jitlog.objects import (TraceForest, MergePoint, FlatOp)
from jitlog import constants as const

PY3 = sys.version_info[0] >= 3

@py.test.mark.parametrize('encoding,text,decoded,bom',
@pytest.mark.parametrize('encoding,text,decoded,bom',
[('ascii', b'a!1%$', u'a!1%$', None),
('utf-8', b"\x41\xE2\x89\xA2\xCE\x91\x2E", u'A≢Α.', None),
('latin-1', b'\xDCber', u'Über', None),
Expand Down
17 changes: 1 addition & 16 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,6 @@ def _supported_unix():
extra_compile_args += ['-DVMPROF_BSD=1']
extra_compile_args += ['-I/usr/local/include']
extra_compile_args += ['-DVMPROF_UNIX=1']
if platform.machine().startswith("arm"):
libraries.append('unwind-arm')
elif (platform.machine().startswith("x86") or
platform.machine().startswith("i686") or
platform.machine().startswith("amd64")):
if sys.maxsize == 2**63-1:
libraries.append('unwind-x86_64')
else:
libraries.append('unwind-x86')
elif platform.machine() == 'aarch64':
libraries.append('unwind-aarch64')
elif platform.machine() == 'ppc64le':
libraries.append('unwind-ppc64')
else:
raise NotImplementedError("unknown platform.machine(): %s" %
platform.machine())
extra_source_files += [
'src/vmprof_mt.c',
'src/vmprof_unix.c',
Expand Down Expand Up @@ -137,6 +121,7 @@ def run(self):
'pytz',
'colorama',
] + extra_install_requires,
python_requires='>=3.6, <3.11',
tests_require=['pytest','cffi','hypothesis'],
entry_points = {
'console_scripts': [
Expand Down
4 changes: 3 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,7 @@ envlist = py27, py34, py35, pypy


[testenv]
deps=pytest
deps=
pytest
cffi
commands=py.test vmprof/test/
22 changes: 12 additions & 10 deletions vmprof/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,18 @@
def disable():
try:
# fish the file descriptor that is still open!
if hasattr(_vmprof, 'stop_sampling'):
fileno = _vmprof.stop_sampling()
if fileno >= 0:
# TODO does fileobj leak the fd? I dont think so, but need to check
fileobj = FdWrapper(fileno)
l = LogReaderDumpNative(fileobj, LogReaderState())
l.read_all()
if hasattr(_vmprof, 'write_all_code_objects'):
_vmprof.write_all_code_objects(l.dedup)
_vmprof.disable()
try:
if hasattr(_vmprof, 'stop_sampling'):
fileno = _vmprof.stop_sampling()
if fileno >= 0:
# TODO does fileobj leak the fd? I dont think so, but need to check
fileobj = FdWrapper(fileno)
l = LogReaderDumpNative(fileobj, LogReaderState())
l.read_all()
if hasattr(_vmprof, 'write_all_code_objects'):
_vmprof.write_all_code_objects(l.dedup)
finally:
_vmprof.disable()
except IOError as e:
raise Exception("Error while writing profile: " + str(e))

Expand Down
4 changes: 3 additions & 1 deletion vmprof/test/test_c_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
from cffi import FFI
from array import array

IS_PYPY = '__pypy__' in sys.builtin_module_names

sample = None
@pytest.mark.skipif("sys.platform == 'win32'")
@pytest.mark.skipif("sys.platform == 'win32' or IS_PYPY")
class TestStack(object):
def setup_class(cls):
stack_ffi = FFI()
Expand Down
8 changes: 5 additions & 3 deletions vmprof/test/test_c_symboltable.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import py
import os
import sys
import pytest
Expand Down Expand Up @@ -66,7 +65,7 @@

ffi.compile(verbose=True)

@py.test.mark.skipif("sys.platform == 'win32'")
@pytest.mark.skipif("sys.platform == 'win32'")
class TestSymbolTable(object):
def setup_class(cls):
from vmprof.test import _test_symboltable as clib
Expand All @@ -82,7 +81,10 @@ def test_resolve_addr(self):
lib.test_extract(name, _lineno, src)

assert ffi.string(name[0]) == b"vmp_resolve_addr"
assert ffi.string(src[0]).endswith(b"vmprof/test/_test_symboltable.c")
srcfile = ffi.string(src[0])
assert b"_test_symboltable" in srcfile
if not srcfile.endswith(b"vmprof/test/_test_symboltable.c"):
pytest.skip("couldn't determine source file, but shared library name seemed ok")
# lines are not included in stab
if sys.platform.startswith('linux'):
with open("vmprof/test/_test_symboltable.c", "rb") as fd:
Expand Down
4 changes: 2 additions & 2 deletions vmprof/test/test_reader.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

import struct, py
import struct, pytest
from vmprof import reader
from vmprof.reader import (FileReadError, MARKER_HEADER)
from vmprof.test.test_run import (read_one_marker, read_header,
Expand Down Expand Up @@ -41,7 +41,7 @@ def test_fileobj_wrapper():
f1 = FileObj([b"123456"])
fw = FileObjWrapper(f1)
assert fw.read(4) == b"1234"
exc = py.test.raises(BufferTooSmallError, fw.read, 4)
exc = pytest.raises(BufferTooSmallError, fw.read, 4)
f1.write(b"789")
fw = FileObjWrapper(f1, exc.value.get_buf())
assert fw.read(3) == b'123'
Expand Down
Loading

0 comments on commit b1d242b

Please sign in to comment.