Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Light: Add smoke testcases for Example Msg Generator source #4216

Draft
wants to merge 34 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
402b7dc
configure.ac: add support for building Python virtualenv for development
bazsi Oct 26, 2022
8e1bf2e
cmake: add support for building Python virtualenv for development
bazsi Oct 31, 2022
969cb7e
configure.ac: remove support for a configurable pylint path
bazsi Oct 31, 2022
59442bf
cmake: remove support for a configurable pylint path
bazsi Oct 31, 2022
f18345d
python: separate dev-requirements.txt from runtime requirements
bazsi Oct 31, 2022
f38085f
.github/workflows: avoid direct use of requirements.txt
bazsi Oct 31, 2022
a373ed0
tests/copyright: add coverage for python build venv script
bazsi Nov 2, 2022
3139d94
dbparser: don't check for NULL before calling g_free
bazsi Sep 14, 2022
7184a86
dbparser: simplify log_db_parser_init()
bazsi Sep 14, 2022
4743d94
dbparser: use wrapper struct to store values in a SyntheticMessage
bazsi Sep 14, 2022
c4eddc6
dbparser: add SyntheticMessage accessor functions to values and tags …
bazsi Sep 14, 2022
839c1d0
dbparser: add prefix support for radix
bazsi Sep 14, 2022
67dad4a
dbparser: add prefix to SyntheticMessage
bazsi Sep 15, 2022
da8559a
dbparser: add prefix constructor argument to PatternDB
bazsi Sep 14, 2022
37e3664
dbparser: add prefix() option to db-parser()
bazsi Sep 18, 2022
dd892a9
dbparser: add support for prefix() to grouping-by()
bazsi Sep 18, 2022
c4e5d15
news: added news file
bazsi Sep 28, 2022
9ae4d71
cfg: accept FEATURE_topic_MIN_VERSION to be zero
bazsi Nov 11, 2022
087b338
tests: fix all unit test issues that stemmed from the 4.0 flip
bazsi Nov 11, 2022
d17f75d
test_lexer: remove unit test case that covers TYPING related feature …
bazsi Nov 12, 2022
0e32adc
.github/workflows/gh-tools: use GITHUB_OUTPUT environment file
bazsi Nov 1, 2022
45ffaf5
LightFixtures: Introduction of 'teardown' fixture
Micek12343 Oct 25, 2022
6cccbe6
LightFile: Remove deinit from File()
Micek12343 Oct 31, 2022
2658832
LightConfigFixture: Extend config fixture with teardown
Micek12343 Oct 31, 2022
8c85271
LightFileBasedDrivers: Register closing fd callbacks for file based d…
Micek12343 Oct 31, 2022
90c76d0
LightSocketBasedDrivers: Replace deinit with registering teardown cal…
Micek12343 Oct 31, 2022
53b1888
LightSyslogNgFixture: Extend syslog_ng fixture with teardown
Micek12343 Oct 31, 2022
1d6e159
LightConsoleLogReader: Closing open stderr fd on teardown
Micek12343 Nov 4, 2022
09b9070
LightSetup: Add checking for open fds before each testcase start
Micek12343 Oct 31, 2022
a5234c2
LightFile: Simplify write and close operation on internal File objects
Micek12343 Nov 4, 2022
7d578f4
LightDevRequirements: Add networkx as a new package dependency
Micek12343 Nov 22, 2022
e288175
Light: Add option and value generator to parametrize smoke testcases
Micek12343 Nov 10, 2022
e9960ac
LightGeneratorSource: Add smoke test for generator source
Micek12343 Nov 10, 2022
3e38158
tmp/workaround for GitHubActions, drop before merge
Micek12343 Nov 11, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions .github/workflows/devshell.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
general:
runs-on: ubuntu-18.04
container:
image: ghcr.io/syslog-ng/dbld-devshell:latest
image: ghcr.io/mitzkia/dbld-devshell:latest
options: --privileged --ulimit core=-1

strategy:
Expand Down Expand Up @@ -146,7 +146,7 @@ jobs:
distcheck:
runs-on: ubuntu-18.04
container:
image: ghcr.io/syslog-ng/dbld-devshell:latest
image: ghcr.io/mitzkia/dbld-devshell:latest
options: --security-opt seccomp=unconfined --ulimit core=-1

steps:
Expand Down Expand Up @@ -187,7 +187,7 @@ jobs:
style-check:
runs-on: ubuntu-18.04
container:
image: ghcr.io/syslog-ng/dbld-devshell:latest
image: ghcr.io/mitzkia/dbld-devshell:latest

steps:
- name: Checkout syslog-ng source
Expand All @@ -211,20 +211,16 @@ jobs:
working-directory: ./build
continue-on-error: true # Fix errors from pylint
run: |
make python-pep8 && make python-pylint || (git reset --hard HEAD && exit 1)
make pymodules-checks || (git reset --hard HEAD && exit 1)

- name: Style check (Light)
id: light-style-check
if: always()
working-directory: ./build
shell: bash
run: |
python3.11 -m venv venv
source venv/bin/activate
python -m pip install -r "${GITHUB_WORKSPACE}/requirements.txt"
make light-linters || \
(git diff > ../light-style-problems.diff ; git reset --hard HEAD && exit 1)
deactivate

- name: "Artifact: c-style-problems"
uses: actions/upload-artifact@v2
Expand All @@ -243,7 +239,7 @@ jobs:
copyright-check:
runs-on: ubuntu-18.04
container:
image: ghcr.io/syslog-ng/dbld-devshell:latest
image: ghcr.io/mitzkia/dbld-devshell:latest
env:
COPYRIGHTVERBOSITY: 1

Expand All @@ -264,7 +260,7 @@ jobs:
commits-check:
runs-on: ubuntu-18.04
container:
image: ghcr.io/syslog-ng/dbld-devshell:latest
image: ghcr.io/mitzkia/dbld-devshell:latest

steps:
- name: Checkout syslog-ng source
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/gh-tools.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ gh_path()
gh_output()
{
while [ "x$1" != "x" ]; do
echo "::set-output name=$1::$(eval echo \$$1)"
echo "$1=$(eval echo \$$1)" >> $GITHUB_OUTPUT
shift;
done
}
1 change: 0 additions & 1 deletion .github/workflows/macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ jobs:
run: |
brew update --preinstall
brew bundle --file=contrib/Brewfile
pip3 install --user -r requirements.txt

- name: Set ENV variables
run: |
Expand Down
12 changes: 1 addition & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -257,17 +257,7 @@ else ()
endif ()

MESSAGE(STATUS "Detected pythonlib version: ${PYTHONLIBS_VERSION_STRING}")

set (PYLINT "" CACHE STRING "pylint binary")

if (PYLINT)
set(PYLINT_BIN ${PYLINT})
else ()
find_program(PYLINT_BIN "pylint3")
if (NOT PYLINT_BIN)
find_program(PYLINT_BIN "pylint")
endif()
endif()
include(python_build_venv)

include(openssl_functions)
openssl_set_defines()
Expand Down
2 changes: 2 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ EXTRA_DIST = ${BUILT_SOURCES} VERSION NEWS.md autogen.sh \
syslog-ng-native-connector.pc.cmake \
syslog-ng-ctl/CMakeLists.txt \
requirements.txt \
dev-requirements.txt \
README.md \
.astylerc

Expand Down Expand Up @@ -212,6 +213,7 @@ install_loggenpluginLTLIBRARIES = install-loggenpluginLTLIBRARIES
$(install_loggenpluginLTLIBRARIES): install-libLTLIBRARIES

include Mk/lex-rules.am
include Mk/python-venv.am
include Mk/Makefile.am
if ENABLE_TESTING
include libtest/Makefile.am
Expand Down
16 changes: 16 additions & 0 deletions Mk/python-venv.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

PYTHON_VENV_TOUCHFILE=$(abs_builddir)/.python-venv-built

$(PYTHON_VENV_TOUCHFILE): Makefile
if [ "$(with_python_packages)" = "venv" ]; then \
$(top_srcdir)/scripts/build-python-venv.sh "$(PYTHON)" "$(PYTHON_VENV_DIR)" "$(top_srcdir)"; \
fi
touch $@

python-venv: $(PYTHON_VENV_TOUCHFILE)

python-venv-clean:
rm -rf "$(PYTHON_VENV_DIR)"
rm -rf "$(PYTHON_VENV_TOUCHFILE)"

CLEAN_HOOKS += python-venv-clean
17 changes: 17 additions & 0 deletions cmake/python_build_venv.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

set(PYTHON_VENV_DIR "${PROJECT_BINARY_DIR}/venv")
set(PYTHON_VENV_TOUCHFILE "${PROJECT_BINARY_DIR}/.python-venv-built")
set(PYTHON_VENV_EXECUTABLE "${PYTHON_VENV_DIR}/bin/python")

add_custom_command(
OUTPUT ${PYTHON_VENV_TOUCHFILE}
COMMAND ${PROJECT_SOURCE_DIR}/scripts/build-python-venv.sh "${PYTHON_EXECUTABLE}" "${PROJECT_BINARY_DIR}/venv" "${PROJECT_SOURCE_DIR}" && touch "${PYTHON_VENV_TOUCHFILE}"
VERBATIM
)

# the touchfile is cleaned up by cmake automatically, we only need to remove
# the venv directory
set_directory_properties(PROPERTIES ADDITIONAL_MAKE_CLEAN_FILES "${PYTHON_VENV_DIR}")

add_custom_target(BuildPyVirtualEnv
DEPENDS ${PYTHON_VENV_TOUCHFILE})
38 changes: 20 additions & 18 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -331,18 +331,23 @@ AC_ARG_WITH(systemd-journal,
Link against the system supplied or the wrapper library. (default: auto)]
,,with_systemd_journal="auto")

AC_ARG_ENABLE(kafka,
[ --enable-kafka Enable rdkafka support]
,,enable_kafka="auto")

AC_ARG_ENABLE(python,
[ --disable-python Disable Python module]
,,enable_python="auto")

AC_ARG_ENABLE(kafka,
[ --enable-kafka Enable rdkafka support]
,,enable_kafka="auto")

AC_ARG_WITH(python,
[ --with-python=VERSION Build with a specific version of python]
,,with_python="auto")

AC_ARG_WITH(python-packages,
[ --with-python-packages=[system|venv] Use Python packages from the system or a private virtualenv (default: venv)]
,,with_python_packages="venv")

AC_ARG_WITH(python3-home,
[ --with-python3-home=path Use path as a hard-coded Python home directory that can not be overwritten by the PYTHONHOME environment variable],
python3_home_dir=$with_python3_home)
Expand Down Expand Up @@ -1516,21 +1521,17 @@ else
with_python=""
fi

dnl ***************************************************************************
dnl pylint
dnl ***************************************************************************

if test "x$with_pylint" != "x"; then
PYLINT=$with_pylint
else
if test "$python_found" = "yes"; then
AC_CHECK_PROG(PYLINT, pylint3, pylint3)
if test "x$PYLINT" = "x"; then
AC_CHECK_PROG(PYLINT, pylint, pylint)
fi
if test "x$enable_python" = "xyes"; then
if test "x$with_python_packages" = "xvenv"; then
PYTHON_VENV_DIR=`pwd`/venv
PYTHON_VENV=${PYTHON_VENV_DIR}/bin/python
else
with_python_packages="system"
PYTHON_VENV=$PYTHON
fi
fi


dnl ***************************************************************************
dnl docbook
dnl ***************************************************************************
Expand Down Expand Up @@ -1969,10 +1970,11 @@ AM_CONDITIONAL([HAVE_INOTIFY], [test x$ac_cv_func_inotify_init = xyes])
AM_CONDITIONAL([HAVE_GETRANDOM], [test x$ac_cv_func_getrandom = xyes])
AM_CONDITIONAL([HAVE_FMEMOPEN], [test x$ac_cv_func_fmemopen = xyes])
AM_CONDITIONAL(ENABLE_IPV6, [test $enable_ipv6 = yes])
AM_CONDITIONAL(PYLINT, [test "x$PYLINT" != "x"])


AC_SUBST(PYLINT)
AC_SUBST(PYTHON_VENV)
AC_SUBST(PYTHON_VENV_DIR)
AC_SUBST(with_python_packages)
AC_SUBST(timezonedir)
AC_SUBST(pidfiledir)
AC_SUBST(moduledir)
Expand Down Expand Up @@ -2093,7 +2095,7 @@ echo " GEOIP2 support (module) : ${enable_geoip2:=no}"
echo " Redis support (module) : ${enable_redis:=no}"
echo " Kafka support (module) : ${enable_kafka:=no}"
echo " Riemann destination (module): ${enable_riemann:=no}, microseconds: ${riemann_micros:=no}"
echo " python : ${enable_python:=no} (pkg-config package: ${with_python:=none})"
echo " python : ${enable_python:=no} (pkg-config package: ${with_python:=none}, packages: ${with_python_packages})"
echo " java : ${enable_java:=no}"
echo " java modules : ${enable_java_modules:=no}"
echo " afsnmp module : ${enable_afsnmp:=no}"
Expand Down
2 changes: 1 addition & 1 deletion dbld/rules
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ TARBALL_IMAGE ?= tarball
DEFAULT_DEB_IMAGE=ubuntu-bionic
DEFAULT_RPM_IMAGE=centos-7
DOCKER=docker
CONTAINER_REGISTRY ?= ghcr.io/syslog-ng
CONTAINER_REGISTRY ?= ghcr.io/mitzkia
MODE ?= snapshot
VERSION ?= $(shell MODE=${MODE} scripts/version.sh)
DOCKER_RUN_ARGS=-e USER_NAME_ON_HOST=$(shell whoami) \
Expand Down
12 changes: 12 additions & 0 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
-r requirements.txt

ply==3.10
pep8==1.7.1
isort==4.3.4
pylint==1.8.2
astroid==1.6.1
logilab-common<=0.63.0
psutil
pytest
pre-commit
networkx
2 changes: 1 addition & 1 deletion lib/cfg.h
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ __cfg_is_config_version_older(GlobalConfig *cfg, gint req)
*/
#define __cfg_is_feature_enabled(cfg, min_version) \
({ \
/* the flip-over for min_version reached, set min_version to 0 */ G_STATIC_ASSERT(VERSION_VALUE_CURRENT < ((min_version) - 1)); \
/* the flip-over for min_version reached, set min_version to 0 */ G_STATIC_ASSERT(min_version == 0 || VERSION_VALUE_CURRENT < ((min_version) - 1)); \
version_convert_from_user(cfg->user_version) >= (min_version) - 1; \
})

Expand Down
9 changes: 6 additions & 3 deletions lib/template/tests/test_template.c
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ Test(template, test_macros_v3x)
/* pri 3, fac 19 == local3 */

/* v3.x behavior */
cfg_set_version_without_validation(configuration, VERSION_VALUE_3_38);

assert_template_format_value_and_type("$FACILITY", "local3", LM_VT_STRING);
assert_template_format_value_and_type("$FACILITY_NUM", "19", LM_VT_STRING);
Expand Down Expand Up @@ -483,18 +484,20 @@ Test(template, test_single_values_and_literal_strings_are_considered_trivial)
{
LogMessage *msg = create_sample_message();

cfg_set_version_without_validation(configuration, VERSION_VALUE_4_0);
assert_template_trivial_value("", msg, "", LM_VT_STRING);
assert_template_trivial_value(" ", msg, " ", LM_VT_STRING);
assert_template_trivial_value("literal", msg, "literal", LM_VT_STRING);
assert_template_trivial_value("$1", msg, "first-match", LM_VT_STRING);
assert_template_trivial_value("$MSG", msg, "árvíztűrőtükörfúrógép", LM_VT_STRING);
assert_template_trivial_value("$HOST", msg, "bzorp", LM_VT_STRING);
assert_template_trivial_value("${APP.VALUE}", msg, "value", LM_VT_STRING);
assert_template_trivial_value("${number1}", msg, "123", LM_VT_STRING);

cfg_set_version_without_validation(configuration, VERSION_VALUE_4_0);
assert_template_trivial_value("${number1}", msg, "123", LM_VT_INTEGER);


cfg_set_version_without_validation(configuration, VERSION_VALUE_3_38);
assert_template_trivial_value("${number1}", msg, "123", LM_VT_STRING);

log_msg_unref(msg);
}

Expand Down
34 changes: 0 additions & 34 deletions lib/tests/test_lexer.c
Original file line number Diff line number Diff line change
Expand Up @@ -345,40 +345,6 @@ foo\n");
"@version parsing mismatch, value %04x expected %04x", configuration->user_version, VERSION_VALUE_CURRENT);
}

Test(lexer, feature_flip_to_typing)
{
gchar buf[128];
parser->lexer->ignore_pragma = FALSE;

start_grabbing_messages();

cfg_set_version_without_validation(configuration, 0);

gint flip_version = FEATURE_TYPING_MIN_VERSION - 1;
g_snprintf(buf, sizeof(buf), "@version: %d.%d\nbar\n",
(flip_version & 0xFF00) >> 8,
flip_version & 0xFF);
_input(buf);
assert_parser_identifier("bar");
cr_assert(configuration->user_version == flip_version);
assert_grabbed_log_contains("experimental behaviors of the future syslog-ng");

cr_assert(cfg_is_config_version_older(configuration, VERSION_VALUE_4_0));
cr_assert(cfg_is_typing_feature_enabled(configuration));

reset_grabbed_messages();

cfg_set_version_without_validation(configuration, 0);
g_snprintf(buf, sizeof(buf), "@version: %d.%d\nbar\n",
(VERSION_VALUE_4_0 & 0xFF00) >> 8,
VERSION_VALUE_4_0 & 0xFF);
_input(buf);
assert_parser_identifier("bar");
assert_grabbed_log_contains("experimental behaviors of the future syslog-ng");
cr_assert(!cfg_is_config_version_older(configuration, VERSION_VALUE_4_0));
cr_assert(cfg_is_typing_feature_enabled(configuration));
}

Test(lexer, test_lexer_others)
{
_input("#This is a full line comment\nfoobar");
Expand Down
3 changes: 3 additions & 0 deletions modules/dbparser/dbparser-grammar.ym
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ SyntheticMessage *last_message;
%token KW_PROGRAM_TEMPLATE
%token KW_MESSAGE_TEMPLATE
%token KW_SORT_KEY
%token KW_PREFIX

%type <num> stateful_parser_inject_mode
%type <ptr> synthetic_message
Expand Down Expand Up @@ -107,6 +108,7 @@ parser_db_opt
log_db_parser_set_program_template_ref(last_parser, $3);
}
| KW_MESSAGE_TEMPLATE '(' template_content ')' { log_parser_set_template(last_parser, $3); }
| KW_PREFIX '(' string ')' { log_db_parser_set_prefix(((LogDBParser *) last_parser), $3); free($3); };
| stateful_parser_opt
;

Expand Down Expand Up @@ -163,6 +165,7 @@ grouping_by_opt
CHECK_ERROR_WITHOUT_MESSAGE(cfg_parser_parse(&filter_expr_parser, lexer, (gpointer *) &filter_expr, NULL), @1);
grouping_by_set_trigger_condition(last_parser, filter_expr);
} ')'
| KW_PREFIX '(' string ')' { grouping_by_set_prefix(last_parser, $3); free($3); };
| stateful_parser_opt
;

Expand Down
1 change: 1 addition & 0 deletions modules/dbparser/dbparser-parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ static CfgLexerKeyword dbparser_keywords[] =
{ "having", KW_HAVING },
{ "trigger", KW_TRIGGER },
{ "value", KW_VALUE },
{ "prefix", KW_PREFIX },
{ "program_template", KW_PROGRAM_TEMPLATE },
{ "message_template", KW_MESSAGE_TEMPLATE },
{ NULL }
Expand Down
Loading