Skip to content

Commit

Permalink
Changes for CI tests
Browse files Browse the repository at this point in the history
  • Loading branch information
joachimmetz committed Oct 9, 2023
1 parent 79d6f9f commit 55eb2d4
Show file tree
Hide file tree
Showing 8 changed files with 221 additions and 201 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/build_wheel.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Build wheel from source using tox.
name: build_wheel
on: [push, pull_request]
permissions: read-all
jobs:
build_wheel:
runs-on: ubuntu-22.04
strategy:
matrix:
include:
- python-version: '3.7'
toxenv: 'py37'
- python-version: '3.8'
toxenv: 'py38'
- python-version: '3.9'
toxenv: 'py39'
- python-version: '3.10'
toxenv: 'py310'
- python-version: '3.11'
toxenv: 'py311'
- python-version: '3.12'
toxenv: 'py312'
steps:
- uses: actions/checkout@v3
- name: Install build dependencies
run: |
sudo add-apt-repository universe &&
sudo add-apt-repository -y ppa:deadsnakes/ppa &&
sudo apt-get update &&
sudo apt-get install -y autoconf automake autopoint build-essential git libtool pkg-config python${{ matrix.python-version }} python${{ matrix.python-version }}-dev python${{ matrix.python-version }}-venv python3-distutils python3-pip python3-setuptools
- name: Install tox
run: |
python3 -m pip install tox
- name: Download test data
run: |
if test -x "synctestdata.sh"; then ./synctestdata.sh; fi
- name: Prepare build
run: |
./synclibs.sh --use-head && ./autogen.sh && ./configure
- name: Build Python wheel
run: |
tox -e${{ matrix.toxenv }}
13 changes: 13 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,18 +84,24 @@ environment:
APPVEYOR_BUILD_WORKER_IMAGE: macos-monterey
HOMEBREW_NO_INSTALL_CLEANUP: 1
CC: clang
CFLAGS: "-I/usr/local/include"
LDFLAGS: "-L/usr/local/lib"
CONFIGURE_OPTIONS: ""
- TARGET: macos-x64-gcc
BUILD_ENVIRONMENT: xcode
APPVEYOR_BUILD_WORKER_IMAGE: macos-monterey
HOMEBREW_NO_INSTALL_CLEANUP: 1
CC: gcc
CFLAGS: "-I/usr/local/include"
LDFLAGS: "-L/usr/local/lib"
CONFIGURE_OPTIONS: ""
- TARGET: macos-x64-gcc-python
BUILD_ENVIRONMENT: xcode
APPVEYOR_BUILD_WORKER_IMAGE: macos-monterey
PYTHON: "/usr/local/opt/python@3.11/bin/python3"
PYTHON_CONFIG: "/usr/local/opt/python@3.11/bin/python3-config"
HOMEBREW_NO_INSTALL_CLEANUP: 1
CC: gcc
CFLAGS: "-I/usr/local/include"
LDFLAGS: "-L/usr/local/lib"
CONFIGURE_OPTIONS: "--enable-python"
Expand All @@ -105,6 +111,7 @@ environment:
PYTHON: "/usr/local/opt/python@3.11/bin/python3"
PYTHON_CONFIG: "/usr/local/opt/python@3.11/bin/python3-config"
HOMEBREW_NO_INSTALL_CLEANUP: 1
CC: gcc
CFLAGS: "-I/usr/local/include"
LDFLAGS: "-L/usr/local/lib"
CONFIGURE_OPTIONS: "--disable-dependency-tracking --prefix=/usr/local --enable-python --with-pyprefix"
Expand Down Expand Up @@ -140,6 +147,12 @@ environment:
HOMEBREW_NO_INSTALL_CLEANUP: 1
PYTHON_VERSION: 3.11
TOXENV: py311
- TARGET: macos-tox-py312
BUILD_ENVIRONMENT: python-tox
APPVEYOR_BUILD_WORKER_IMAGE: macos-monterey
HOMEBREW_NO_INSTALL_CLEANUP: 1
PYTHON_VERSION: 3.12
TOXENV: py312
- TARGET: cygwin64-gcc
BUILD_ENVIRONMENT: cygwin64
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2022
Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ AC_PREREQ([2.71])

AC_INIT(
[libfcrypto],
[20230929],
[20231009],
[joachim.metz@gmail.com])

AC_CONFIG_SRCDIR(
Expand Down
76 changes: 76 additions & 0 deletions tests/runtests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#!/usr/bin/env python
#
# Script to run Python test scripts.
#
# Version: 20231004

import glob
import os
import sys
import unittest


test_profile = ".pyfcrypto"
input_glob = "*"
option_sets = []


def ReadIgnoreList(test_profile):
"""Reads the test profile ignore file if it exists.
Args:
test_profile (str): test profile.
Returns:
set[str]: ignore list.
"""
ignore_file_path = os.path.join("tests", "input", test_profile, "ignore")
if os.path.isfile(ignore_file_path):
with open(ignore_file_path, "r", encoding="utf-8") as file_object:
return set([line.strip() for line in file_object.readlines()])

return set()


if __name__ == "__main__":
print(f"Using Python version {sys.version!s}")

test_loader = unittest.TestLoader()
test_runner = unittest.TextTestRunner(verbosity=2)

test_scripts = test_loader.discover("tests", pattern="*.py")

ignore_list = ReadIgnoreList(test_profile)

test_set = None
source_file = None

for test_set in glob.glob(os.path.join("tests", "input", "*")):
test_set = test_set.rsplit(os.path.sep, maxsplit=1)[-1]
if not test_set or test_set[0] == '.' or test_set in ignore_list:
continue

source_files = glob.glob(os.path.join(
"tests", "input", test_set, input_glob))
if source_files:
source_file = source_files[0]
break

setattr(unittest, "source", source_file)

for option_set in option_sets:
test_file = os.path.basename(source_file)
test_options_file_path = os.path.join(
"tests", "input", test_profile, test_set,
f"{test_file:s}.{option_set:s}")
if os.path.isfile(test_options_file_path):
with open(test_options_file_path, "r", encoding="utf-8") as file_object:
lines = [line.strip() for line in file_object.readlines()]
if lines[0] == "# libyal test data options":
for line in lines[1:]:
key, value = line.split("=", maxsplit=1)
setattr(unittest, key, value)

test_results = test_runner.run(test_scripts)
if not test_results.wasSuccessful():
sys.exit(1)
75 changes: 41 additions & 34 deletions tests/test_library.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#!/usr/bin/env bash
# Tests library functions and types.
#
# Version: 20230410
# Version: 20231007

EXIT_SUCCESS=0;
EXIT_FAILURE=1;
EXIT_IGNORE=77;

LIBRARY_TESTS="des3_context error rc4_context serpent_context support";
LIBRARY_TESTS_WITH_INPUT="";
OPTION_SETS="";
OPTION_SETS=();

INPUT_GLOB="*";

Expand Down Expand Up @@ -78,47 +78,54 @@ run_test_with_input()

local TEST_SET_DIRECTORY=$(get_test_set_directory "${TEST_PROFILE_DIRECTORY}" "${TEST_SET_INPUT_DIRECTORY}");

local OLDIFS=${IFS};

# IFS="\n" is not supported by all platforms.
IFS="
";

if test -f "${TEST_SET_DIRECTORY}/files";
then
for INPUT_FILE in `cat ${TEST_SET_DIRECTORY}/files | sed "s?^?${TEST_SET_INPUT_DIRECTORY}/?"`;
IFS="" read -a INPUT_FILES <<< $(cat ${TEST_SET_DIRECTORY}/files | sed "s?^?${TEST_SET_INPUT_DIRECTORY}/?");
else
IFS="" read -a INPUT_FILES <<< $(ls -1d ${TEST_SET_INPUT_DIRECTORY}/${INPUT_GLOB});
fi
for INPUT_FILE in "${INPUT_FILES[@]}";
do
OPTION_INPUT_FILE="${INPUT_FILE}";

if test "${OSTYPE}" = "msys";
then
# A test executable built with MinGW expects a Windows path.
INPUT_FILE=`echo ${INPUT_FILE} | sed 's?/?\\\\?g'`;
fi
local TESTED_WITH_OPTIONS=0;

for OPTION_SET in ${OPTION_SETS[@]};
do
if test "${OSTYPE}" = "msys";
then
# A test executable built with MinGW expects a Windows path.
INPUT_FILE=`echo ${INPUT_FILE} | sed 's?/?\\\\?g'`;
fi
run_test_on_input_file_with_options "${TEST_SET_DIRECTORY}" "${TEST_DESCRIPTION}" "default" "${OPTION_SETS}" "${TEST_EXECUTABLE}" "${INPUT_FILE}";
RESULT=$?;
local TEST_DATA_OPTION_FILE=$(get_test_data_option_file "${TEST_SET_DIRECTORY}" "${OPTION_INPUT_FILE}" "${OPTION_SET}");

if test ${RESULT} -ne ${EXIT_SUCCESS};
if test -f ${TEST_DATA_OPTION_FILE};
then
break;
TESTED_WITH_OPTIONS=1;

IFS=" " read -a OPTIONS <<< $(read_test_data_option_file "${TEST_SET_DIRECTORY}" "${INPUT_FILE}" "${OPTION_SET}");

run_test_on_input_file "${TEST_SET_DIRECTORY}" "${TEST_DESCRIPTION}" "default" "${OPTION_SET}" "${TEST_EXECUTABLE}" "${INPUT_FILE}" "${OPTIONS[@]}";
RESULT=$?;

if test ${RESULT} -ne ${EXIT_SUCCESS};
then
break;
fi
fi
done
else
for INPUT_FILE in `ls -1d ${TEST_SET_INPUT_DIRECTORY}/${INPUT_GLOB}`;
do
if test "${OSTYPE}" = "msys";
then
# A test executable built with MinGW expects a Windows path.
INPUT_FILE=`echo ${INPUT_FILE} | sed 's?/?\\\\?g'`;
fi
run_test_on_input_file_with_options "${TEST_SET_DIRECTORY}" "${TEST_DESCRIPTION}" "default" "${OPTION_SETS}" "${TEST_EXECUTABLE}" "${INPUT_FILE}";

if test ${TESTED_WITH_OPTIONS} -eq 0;
then
run_test_on_input_file "${TEST_SET_DIRECTORY}" "${TEST_DESCRIPTION}" "default" "" "${TEST_EXECUTABLE}" "${INPUT_FILE}";
RESULT=$?;
fi

if test ${RESULT} -ne ${EXIT_SUCCESS};
then
break;
fi
done
fi
IFS=${OLDIFS};
if test ${RESULT} -ne ${EXIT_SUCCESS};
then
break;
fi
done

if test ${RESULT} -ne ${EXIT_SUCCESS};
then
Expand Down
58 changes: 34 additions & 24 deletions tests/test_python_module.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#!/usr/bin/env bash
# Tests Python module functions and types.
#
# Version: 20230410
# Version: 20231005

EXIT_SUCCESS=0;
EXIT_FAILURE=1;
EXIT_IGNORE=77;

TEST_FUNCTIONS="des3_context rc4_context support";
TEST_FUNCTIONS_WITH_INPUT="";
OPTION_SETS="";
OPTION_SETS=();

TEST_TOOL_DIRECTORY=".";
INPUT_GLOB="*";
Expand Down Expand Up @@ -68,37 +68,47 @@ test_python_function_with_input()

local TEST_SET_DIRECTORY=$(get_test_set_directory "${TEST_PROFILE_DIRECTORY}" "${TEST_SET_INPUT_DIRECTORY}");

local OLDIFS=${IFS};

# IFS="\n"; is not supported by all platforms.
IFS="
";

if test -f "${TEST_SET_DIRECTORY}/files";
then
for INPUT_FILE in `cat ${TEST_SET_DIRECTORY}/files | sed "s?^?${TEST_SET_INPUT_DIRECTORY}/?"`;
IFS="" read -a INPUT_FILES <<< $(cat ${TEST_SET_DIRECTORY}/files | sed "s?^?${TEST_SET_INPUT_DIRECTORY}/?");
else
IFS="" read -a INPUT_FILES <<< $(ls -1d ${TEST_SET_INPUT_DIRECTORY}/${INPUT_GLOB});
fi
for INPUT_FILE in "${INPUT_FILES[@]}";
do
local TESTED_WITH_OPTIONS=0;

for OPTION_SET in ${OPTION_SETS[@]};
do
run_test_on_input_file_with_options "${TEST_SET_DIRECTORY}" "${TEST_DESCRIPTION}" "default" "${OPTION_SETS}" "${TEST_SCRIPT}" "${INPUT_FILE}";
RESULT=$?;
local TEST_DATA_OPTION_FILE=$(get_test_data_option_file "${TEST_SET_DIRECTORY}" "${INPUT_FILE}" "${OPTION_SET}");

if test ${RESULT} -ne ${EXIT_SUCCESS};
if test -f ${TEST_DATA_OPTION_FILE};
then
break;
TESTED_WITH_OPTIONS=1;

IFS=" " read -a OPTIONS <<< $(read_test_data_option_file "${TEST_SET_DIRECTORY}" "${INPUT_FILE}" "${OPTION_SET}");

run_test_on_input_file "${TEST_SET_DIRECTORY}" "${TEST_DESCRIPTION}" "default" "${OPTION_SET}" "${TEST_SCRIPT}" "${INPUT_FILE}" "${OPTIONS[@]}";
RESULT=$?;

if test ${RESULT} -ne ${EXIT_SUCCESS};
then
break;
fi
fi
done
else
for INPUT_FILE in `ls -1d ${TEST_SET_INPUT_DIRECTORY}/${INPUT_GLOB}`;
do
run_test_on_input_file_with_options "${TEST_SET_DIRECTORY}" "${TEST_DESCRIPTION}" "default" "${OPTION_SETS}" "${TEST_SCRIPT}" "${INPUT_FILE}";

if test ${TESTED_WITH_OPTIONS} -eq 0;
then
run_test_on_input_file "${TEST_SET_DIRECTORY}" "${TEST_DESCRIPTION}" "default" "" "${TEST_SCRIPT}" "${INPUT_FILE}";
RESULT=$?;
fi

if test ${RESULT} -ne ${EXIT_SUCCESS};
then
break;
fi
done
fi
IFS=${OLDIFS};
if test ${RESULT} -ne ${EXIT_SUCCESS};
then
break;
fi
done

if test ${RESULT} -ne ${EXIT_SUCCESS};
then
Expand Down
Loading

0 comments on commit 55eb2d4

Please sign in to comment.