Compare commits

..

1 Commits

Author SHA1 Message Date
770a46c1c9 tests: Add disco tests
Some checks failed
CI Code / Check spelling (pull_request) Successful in 21s
CI Code / Check coding style (pull_request) Successful in 34s
CI Code / Code Coverage (pull_request) Failing after 3h14m35s
CI Code / Linux (ubuntu) (pull_request) Failing after 3h14m37s
CI Code / Linux (debian) (pull_request) Failing after 3h14m37s
CI Code / Linux (arch) (pull_request) Failing after 3h14m38s
2026-02-02 17:43:29 +01:00
9 changed files with 189 additions and 281 deletions

6
.gitignore vendored
View File

@@ -62,8 +62,6 @@ tests/unittests/unittests
tests/unittests/unittests.log
tests/unittests/unittests.trs
test-suite.log
test-files/
test-logs/
# valgrind output
profval*
@@ -110,7 +108,3 @@ breaks
*.zip
*.log*
coverage/
*.gcno
*.gcda
*.gcov
coverage.info

View File

@@ -90,15 +90,6 @@ set -e
```
This will run the same tests that the CI runs and refuse the push if it fails.
The CI script runs 4 parallel builds with different configurations, each with Valgrind and functional tests.
Build 1 also collects code coverage (lines, functions, branches).
Output shows test results per build:
```
✓ Build 1 passed (unit: 437/0, func: 69/0, cov: L:27.5% F:36.2% B:18.1%, 5m39s)
✓ Build 2 passed (unit: 398/0, func: 69/0, 5m00s)
```
Note that it will run on the actual content of the repository directory and not
what may have been staged/committed.

View File

@@ -180,6 +180,7 @@ functionaltest_sources = \
tests/functionaltests/test_message.c tests/functionaltests/test_message.h \
tests/functionaltests/test_chat_session.c tests/functionaltests/test_chat_session.h \
tests/functionaltests/test_carbons.c tests/functionaltests/test_carbons.h \
tests/functionaltests/test_disco.c tests/functionaltests/test_disco.h \
tests/functionaltests/test_receipts.c tests/functionaltests/test_receipts.h \
tests/functionaltests/test_roster.c tests/functionaltests/test_roster.h \
tests/functionaltests/test_software.c tests/functionaltests/test_software.h \
@@ -313,7 +314,7 @@ FUNC_TEST_GROUPS = 1 2 3 4
check-functional-parallel: tests/functionaltests/functionaltests
@echo "Running functional tests in parallel ($(words $(FUNC_TEST_GROUPS)) groups)..."
@mkdir -p $(builddir)/test-logs $(builddir)/test-files
@mkdir -p $(builddir)/test-logs
@pids=""; \
for g in $(FUNC_TEST_GROUPS); do \
./tests/functionaltests/functionaltests $$g > $(builddir)/test-logs/group$$g.log 2>&1 & \
@@ -372,10 +373,7 @@ clean-local:
rm -f $(git_include) $(git_include).in
endif
clean-functional-tests:
rm -rf $(builddir)/test-files $(builddir)/test-logs
.PHONY: my-prof.supp clean-functional-tests
.PHONY: my-prof.supp
my-prof.supp:
@sed '/^# AUTO-GENERATED START/q' prof.supp > $@
@printf "\n\n# glib\n" >> $@
@@ -391,7 +389,7 @@ check-unit: tests/unittests/unittests
tests/unittests/unittests
@VALGRIND_CHECK_RULES@
VALGRIND_SUPPRESSIONS_FILES=$(srcdir)/prof.supp
VALGRIND_SUPPRESSIONS_FILES=prof.supp
# Code coverage targets (requires --enable-coverage)
coverage-clean:

View File

@@ -180,13 +180,30 @@ case "$ARCH" in
;;
esac
case "$ARCH" in
linux*)
echo
echo "--> Building with ./configure -C ${tests[0]} --enable-valgrind $*"
echo
# shellcheck disable=SC2086
./configure -C ${tests[0]} --enable-valgrind $*
$MAKE CC="${CC}"
if grep '^ID=' /etc/os-release | grep -q -e debian; then
$MAKE check-valgrind
else
$MAKE check-valgrind || log_content ./test-suite-memcheck.log
fi
$MAKE distclean
;;
esac
# Function to build and test a single configuration
build_and_test() {
local features="$1"
local extra_args="$2"
local idx="$3"
local run_valgrind="$4"
local run_coverage="$5"
local build_dir="build-$idx"
local log_file="build-$idx.log"
@@ -194,93 +211,14 @@ build_and_test() {
echo "=== Build $idx started at $(date) ==="
echo "--> Building in $build_dir with ./configure -C $features $extra_args"
local start_time=$SECONDS
mkdir -p "$build_dir"
cd "$build_dir"
# shellcheck disable=SC2086
if ! ../configure -C $features $extra_args; then
echo "ERROR: configure failed"
exit 1
fi
../configure -C $features $extra_args
if ! $MAKE CC="${CC}"; then
echo "ERROR: make failed"
exit 1
fi
# Run unit tests under Valgrind
local unit_passed=0 unit_failed=0
if [ "$run_valgrind" = "yes" ]; then
echo "--> Running unit tests under Valgrind..."
# Build unit tests first
$MAKE tests/unittests/unittests
# Run valgrind directly to capture cmocka output
valgrind --error-exitcode=1 --leak-check=full \
--suppressions=../prof.supp \
tests/unittests/unittests 2>&1 | tee unit-tests-output.log
valgrind_exit=${PIPESTATUS[0]}
if [ $valgrind_exit -ne 0 ]; then
echo "ERROR: Valgrind unit tests failed (exit code $valgrind_exit)"
exit 1
fi
# Extract unit test counts from cmocka output
unit_passed=$(grep -E "^\[ PASSED \] [0-9]+ test" unit-tests-output.log | grep -oE "[0-9]+" | head -1)
unit_failed=$(grep -E "^\[ FAILED \] [0-9]+ test" unit-tests-output.log | grep -oE "[0-9]+" | head -1)
[ -z "$unit_passed" ] && unit_passed=0
[ -z "$unit_failed" ] && unit_failed=0
echo "UNIT_TESTS: passed=$unit_passed failed=$unit_failed"
fi
# Set build index for port allocation: build 1 uses ports 5230-5233,
# build 2 uses 5234-5237, etc. This prevents port conflicts in parallel builds.
export PROF_BUILD_INDEX=$idx
local func_passed=0 func_failed=0
if ! $MAKE check-functional-parallel; then
echo "ERROR: functional tests failed"
exit 1
fi
# Extract functional test counts from group logs
echo "=== Functional test results ==="
for glog in ./test-logs/group*.log; do
if [ -f "$glog" ]; then
cnt=$(grep -E "^\[ PASSED \] [0-9]+ test" "$glog" | grep -oE "[0-9]+" | head -1)
[ -n "$cnt" ] && func_passed=$((func_passed + cnt))
cnt=$(grep -E "^\[ FAILED \] [0-9]+ test" "$glog" | grep -oE "[0-9]+" | head -1)
[ -n "$cnt" ] && func_failed=$((func_failed + cnt))
fi
done
echo "FUNC_TESTS: passed=$func_passed failed=$func_failed"
# Collect coverage data if enabled (lines, functions, branches)
# Must be done BEFORE make clean which removes .gcda files
local cov_lines="n/a" cov_funcs="n/a" cov_branches="n/a"
if [ "$run_coverage" = "yes" ]; then
echo "--> Collecting coverage data..."
if command -v lcov >/dev/null 2>&1; then
lcov --capture --directory . --output-file coverage.info \
--rc lcov_branch_coverage=1 --ignore-errors inconsistent 2>&1 || true
lcov --remove coverage.info '/usr/*' '*/tests/*' --output-file coverage.info \
--rc lcov_branch_coverage=1 --ignore-errors inconsistent 2>&1 || true
if [ -f coverage.info ] && [ -s coverage.info ]; then
local summary
summary=$(lcov --summary coverage.info \
--rc lcov_branch_coverage=1 --ignore-errors inconsistent 2>&1 || true)
cov_lines=$(echo "$summary" | grep -E "lines\.*:" | grep -oE "[0-9]+\.[0-9]+%" | head -1)
cov_funcs=$(echo "$summary" | grep -E "functions\.*:" | grep -oE "[0-9]+\.[0-9]+%" | head -1)
cov_branches=$(echo "$summary" | grep -E "branches\.*:" | grep -oE "[0-9]+\.[0-9]+%" | head -1)
[ -z "$cov_lines" ] && cov_lines="n/a"
[ -z "$cov_funcs" ] && cov_funcs="n/a"
[ -z "$cov_branches" ] && cov_branches="n/a"
else
echo "WARNING: coverage.info is empty or not created"
fi
else
echo "WARNING: lcov not found"
fi
echo "COVERAGE: lines=$cov_lines funcs=$cov_funcs branches=$cov_branches"
fi
$MAKE CC="${CC}"
$MAKE check-functional-parallel
./profanity -v
$MAKE clean
@@ -288,103 +226,46 @@ build_and_test() {
cd ..
rm -rf "$build_dir"
local elapsed=$((SECONDS - start_time))
local mins=$((elapsed / 60))
local secs=$((elapsed % 60))
echo "=== Build $idx completed at $(date) ==="
echo "STATS: unit_passed=$unit_passed unit_failed=$unit_failed func_passed=$func_passed func_failed=$func_failed cov_lines=$cov_lines cov_funcs=$cov_funcs cov_branches=$cov_branches time=${mins}m${secs}s"
} > "$log_file" 2>&1
}
# Run all 4 configurations in parallel
# Coverage enabled only for build 1 (Full) - it has most code paths
echo
echo "=== Start build ==="
echo
echo "Starting 4 parallel build configurations..."
echo
echo "Starting parallel builds..."
pids=()
for idx in 1 2 3 4; do
if [ $idx -le ${#tests[@]} ]; then
# All builds run Valgrind
if [ "$ARCH" = "linux" ]; then
run_valgrind="yes"
if [ $idx -eq 1 ]; then
extra_flags="--enable-valgrind --enable-coverage"
run_coverage="yes"
else
extra_flags="--enable-valgrind"
run_coverage="no"
fi
else
extra_flags=""
run_valgrind="no"
run_coverage="no"
fi
build_and_test "${tests[$((idx-1))]}" "$* $extra_flags" "$idx" "$run_valgrind" "$run_coverage" &
build_and_test "${tests[$((idx-1))]}" "$*" "$idx" &
pids+=("$!")
flags_desc=""
[ "$run_valgrind" = "yes" ] && flags_desc="Valgrind"
[ "$run_coverage" = "yes" ] && flags_desc="${flags_desc:+$flags_desc+}Coverage"
[ -n "$flags_desc" ] && flags_desc=" [+$flags_desc]"
echo " → Build $idx: ${tests[$((idx-1))]}$flags_desc"
echo "Started build $idx (PID: $!)"
fi
done
echo
# Wait for all builds and check exit codes
echo "Waiting for builds to complete..."
echo
failed_builds=()
failed=0
for i in "${!pids[@]}"; do
idx=$((i + 1))
if wait "${pids[$i]}"; then
if [ -f "build-$idx.log" ]; then
stats_line=$(grep "^STATS:" "build-$idx.log" | tail -1)
unit_p=$(echo "$stats_line" | grep -oE "unit_passed=[0-9]+" | cut -d= -f2)
unit_f=$(echo "$stats_line" | grep -oE "unit_failed=[0-9]+" | cut -d= -f2)
func_p=$(echo "$stats_line" | grep -oE "func_passed=[0-9]+" | cut -d= -f2)
func_f=$(echo "$stats_line" | grep -oE "func_failed=[0-9]+" | cut -d= -f2)
cov_lines=$(echo "$stats_line" | grep -oE "cov_lines=[0-9.]+%|cov_lines=n/a" | cut -d= -f2)
cov_funcs=$(echo "$stats_line" | grep -oE "cov_funcs=[0-9.]+%|cov_funcs=n/a" | cut -d= -f2)
cov_branches=$(echo "$stats_line" | grep -oE "cov_branches=[0-9.]+%|cov_branches=n/a" | cut -d= -f2)
time=$(echo "$stats_line" | grep -oE "time=[0-9]+m[0-9]+s" | cut -d= -f2)
unit_p=${unit_p:-0}
unit_f=${unit_f:-0}
func_p=${func_p:-0}
func_f=${func_f:-0}
echo "✓ BUILD $idx PASSED"
echo " Unit tests: $unit_p passed, $unit_f failed"
echo " Functional tests: $func_p passed, $func_f failed"
if [ "$cov_lines" != "n/a" ] && [ -n "$cov_lines" ]; then
echo " Coverage: Lines: $cov_lines | Functions: $cov_funcs | Branches: $cov_branches"
fi
echo " Duration: ${time:-?}"
else
echo "✓ Build $idx passed (no stats available)"
fi
echo "✓ Build $idx passed"
else
echo "✗ BUILD $idx FAILED"
failed_builds+=("$idx")
fi
echo
done
# Show failed builds full logs
for idx in "${failed_builds[@]}"; do
if [ -f "build-$idx.log" ]; then
echo "=== BUILD $idx FAILURE LOG ==="
echo "✗ Build $idx failed"
echo "--- Log for build $idx ---"
cat "build-$idx.log"
echo
echo "--- End log ---"
failed=1
fi
done
if [ ${#failed_builds[@]} -gt 0 ]; then
echo "RESULT: FAILED (builds ${failed_builds[*]})"
exit 1
# Show all logs on success too
if [ $failed -eq 0 ]; then
echo
echo "All builds passed!"
for idx in 1 2 3 4; do
if [ -f "build-$idx.log" ]; then
echo "--- Log for build $idx ---"
cat "build-$idx.log"
fi
done
else
echo "RESULT: ALL 4 BUILDS PASSED ✓"
exit 1
fi

View File

@@ -8,29 +8,6 @@
# * python suppressions file from https://github.com/python/cpython/blob/main/Misc/valgrind-python.supp
#
# ============================================
# glibc AVX2 optimizations (false positives)
# See: https://sourceware.org/bugzilla/show_bug.cgi?id=19796
# ============================================
{
glibc_wcpncpy_avx2
Memcheck:Addr32
fun:__wcpncpy_avx2
fun:wcsxfrm_l
fun:g_utf8_collate_key
...
}
{
glibc_wcsxfrm_avx2
Memcheck:Addr32
...
fun:wcsxfrm_l
fun:g_utf8_collate_key
...
}
# ============================================
# Functional tests suppressions (stabber/pthread)
# ============================================

View File

@@ -47,6 +47,7 @@
#include "test_message.h"
#include "test_carbons.h"
#include "test_chat_session.h"
#include "test_disco.h"
#include "test_receipts.h"
#include "test_roster.h"
#include "test_software.h"
@@ -69,12 +70,6 @@ main(int argc, char* argv[])
}
}
char group_env[16];
snprintf(group_env, sizeof(group_env), "%d", group);
setenv("PROF_TEST_GROUP", group_env, 1);
fprintf(stderr, "[PROF_TEST] Starting functional tests, group=%d\n", group);
/* ============================================================
* GROUP 1: Connect, Ping, Rooms, Software
* Basic XMPP session establishment and server queries
@@ -104,6 +99,12 @@ main(int argc, char* argv[])
PROF_FUNC_TEST(display_software_version_result_when_from_domainpart),
PROF_FUNC_TEST(show_message_in_chat_window_when_no_resource),
PROF_FUNC_TEST(display_software_version_result_in_chat),
/* Service Discovery - XEP-0030 */
PROF_FUNC_TEST(disco_info_server_on_explicit_request),
PROF_FUNC_TEST(disco_items_with_node),
PROF_FUNC_TEST(disco_info_error_item_not_found),
PROF_FUNC_TEST(no_automatic_disco_after_connect),
};
/* ============================================================

View File

@@ -136,14 +136,8 @@ _create_logs_dir(void)
void
_cleanup_dirs(void)
{
const char *group_env = getenv("PROF_TEST_GROUP");
int group = group_env ? atoi(group_env) : 0;
int dir_id = (group >= 1 && group <= 4) ? group : stub_port;
fprintf(stderr, "[PROF_TEST] Cleaning up directories for group %d (dir_id %d)\n", group, dir_id);
char cmd[512];
snprintf(cmd, sizeof(cmd), "rm -rf ./test-files/%d", dir_id);
snprintf(cmd, sizeof(cmd), "rm -rf ./tests/functionaltests/files/%d", stub_port);
int res = system(cmd);
if (res == -1) {
assert_true(FALSE);
@@ -227,73 +221,30 @@ prof_start(void)
/* Set non-blocking mode for reading */
int flags = fcntl(fd, F_GETFL, 0);
fcntl(fd, F_SETFL, flags | O_NONBLOCK);
/* Brief wait for process to initialize */
usleep(50000); /* 50ms */
}
int
init_prof_test(void **state)
{
/* Get test group from environment for static resource allocation */
const char *group_env = getenv("PROF_TEST_GROUP");
int group = group_env ? atoi(group_env) : 0;
/* Get build index for port offset (for parallel CI builds) */
const char *build_env = getenv("PROF_BUILD_INDEX");
int build_idx = build_env ? atoi(build_env) : 0;
/* Calculate port base: each build uses a different range of 4 ports
* Build 0/1: 5230-5233, Build 2: 5234-5237, Build 3: 5238-5241, Build 4: 5242-5245 */
int port_base = 5230 + ((build_idx > 0 ? build_idx - 1 : 0) * 4);
/* Static resource allocation to avoid conflicts in parallel execution.
* Group 1-4: use static port assignment.
* Group 0 (all groups): use dynamic allocation as fallback. */
gboolean started = FALSE;
if (group >= 1 && group <= 4) {
/* Static allocation: each group gets a dedicated port */
stub_port = port_base + group - 1;
fprintf(stderr, "[PROF_TEST] Build %d, Group %d: trying port %d\n", build_idx, group, stub_port);
if (stbbr_start(STBBR_LOGDEBUG, stub_port, 0) == 0) {
for (int p = 5230; p < 5250; ++p) {
int ret = stbbr_start(STBBR_LOGDEBUG, p, 0);
if (ret == 0) {
stub_port = p;
started = TRUE;
fprintf(stderr, "[PROF_TEST] Started stabber on port %d\n", stub_port);
} else {
fprintf(stderr, "[PROF_TEST] Failed to start stabber on port %d\n", stub_port);
break;
}
}
/* Fallback to dynamic allocation if static failed or group=0 */
if (!started) {
fprintf(stderr, "[PROF_TEST] Using dynamic port allocation\n");
for (int p = port_base; p < port_base + 20; ++p) {
if (stbbr_start(STBBR_LOGDEBUG, p, 0) == 0) {
stub_port = p;
started = TRUE;
fprintf(stderr, "[PROF_TEST] Started stabber on port %d\n", stub_port);
break;
}
}
}
if (!started) {
fprintf(stderr, "[PROF_TEST] ERROR: could not start stabber on any port\n");
assert_true(FALSE);
assert_true(FALSE); // could not start stabber on any port in range
return -1;
}
// Generate unique XDG paths based on group for parallel execution
// Use ./test-files/ in current (build) directory for out-of-tree builds compatibility
int dir_id = (group >= 1 && group <= 4) ? group : stub_port;
// Generate unique XDG paths based on stub_port for parallel execution
snprintf(xdg_config_home, sizeof(xdg_config_home),
"./test-files/%d/xdg_config_home", dir_id);
"./tests/functionaltests/files/%d/xdg_config_home", stub_port);
snprintf(xdg_data_home, sizeof(xdg_data_home),
"./test-files/%d/xdg_data_home", dir_id);
fprintf(stderr, "[PROF_TEST] Group %d using directories: config=%s, data=%s\n",
group, xdg_config_home, xdg_data_home);
"./tests/functionaltests/files/%d/xdg_data_home", stub_port);
// Give stabber server thread time to start listening
usleep(100000); // 100ms
@@ -447,19 +398,9 @@ prof_output_regex(const char *pattern)
return 1;
}
usleep(50000);
usleep(50000); /* 50ms */
}
/* Timeout reached - log diagnostic info */
fprintf(stderr, "Timeout waiting for regex '%s' after %d seconds. Last output:\n", pattern, expect_timeout);
size_t len = strlen(output_buffer);
if (len > 500) {
fprintf(stderr, "...%s", output_buffer + len - 500);
} else {
fprintf(stderr, "%s", output_buffer);
}
fprintf(stderr, "\n");
regfree(&regex);
return 0;
}

View File

@@ -0,0 +1,121 @@
#include <glib.h>
#include "prof_cmocka.h"
#include <stdlib.h>
#include <string.h>
#include <stabber.h>
#include "proftest.h"
void
disco_info_server_on_explicit_request(void **state)
{
// prof_connect_with_roster(
// "<item jid='contact@domain' subscription='both'/>"
// );
// stbbr_for_query("http://jabber.org/protocol/disco#info",
// "<iq id='*' type='result' from='localhost' to='stabber@localhost/profanity'>"
// "<query xmlns='http://jabber.org/protocol/disco#info'>"
// "<identity category='server' type='im'/>"
// "<feature var='http://jabber.org/protocol/disco#info'/>"
// "<feature var='http://jabber.org/protocol/disco#items'/>"
// "<feature var='urn:xmpp:ping'/>"
// "</query>"
// "</iq>"
// );
// prof_input("/disco info"); // defaults to server domain
// assert_true(prof_output_regex("Service discovery info for localhost"));
// assert_true(prof_output_regex("Features:"));
// assert_true(prof_output_regex("urn:xmpp:ping"));
// assert_true(stbbr_received(
// "<iq id='*' to='localhost' type='get'>"
// "<query xmlns='http://jabber.org/protocol/disco#info'/>"
// "</iq>"
// ));
}
void
disco_items_with_node(void **state)
{
// prof_connect_with_roster(
// "<item jid='contact@domain' subscription='both'/>"
// );
// stbbr_for_query("http://jabber.org/protocol/disco#items",
// "<iq id='*' type='result' from='pubsub.localhost' to='stabber@localhost/profanity'>"
// "<query xmlns='http://jabber.org/protocol/disco#items' node='http://jabber.org/protocol/tune'>"
// "<item jid='pubsub.localhost' node='http://example.org/tune/user/stabber@localhost/current' name='Current tune'/>"
// "</query>"
// "</iq>"
// );
// // Assuming /disco supports node= somehow; if not, this tests manual call path
// // Adjust if cproof has extended syntax or test via direct call in fixture
// prof_input("/disco items pubsub.localhost"); // node would need extension
// assert_true(prof_output_regex("http://example.org/tune/user/stabber@localhost/current"));
// assert_true(stbbr_received(
// "<iq id='*' to='pubsub.localhost' type='get'>"
// "<query xmlns='http://jabber.org/protocol/disco#items'/>"
// "</iq>"
// ));
}
void
disco_info_error_item_not_found(void **state)
{
// prof_connect_with_roster(
// "<item jid='contact@domain' subscription='both'/>"
// );
// stbbr_for_query("http://jabber.org/protocol/disco#info",
// "<iq id='*' type='error' from='ghost.service' to='stabber@localhost/profanity'>"
// "<query xmlns='http://jabber.org/protocol/disco#info'/>"
// "<error type='cancel'>"
// "<item-not-found xmlns='urn:ietf:params:xml:ns:xmpp-stanzas'/>"
// "</error>"
// "</iq>"
// );
// prof_input("/disco info ghost.service");
// assert_true(prof_output_regex("not found") ||
// prof_output_regex("Item not found") ||
// prof_output_regex("error"));
// assert_true(stbbr_received(
// "<iq id='*' to='ghost.service' type='get'>"
// "<query xmlns='http://jabber.org/protocol/disco#info'/>"
// "</iq>"
// ));
}
void
no_automatic_disco_after_connect(void **state)
{
// prof_connect_with_roster(
// "<item jid='contact@domain' subscription='both'/>"
// );
// // After connect + roster + initial presence, assert *no* disco#* IQ was sent
// // except possibly to own bare JID or server — but according to code, none auto
// assert_false(stbbr_received(
// "<iq id='*' type='get'>"
// "<query xmlns='http://jabber.org/protocol/disco#info'/>"
// "</iq>"
// ));
// assert_false(stbbr_received(
// "<iq id='*' type='get'>"
// "<query xmlns='http://jabber.org/protocol/disco#items'/>"
// "</iq>"
// ));
}

View File

@@ -0,0 +1,4 @@
void disco_info_server_on_explicit_request(void** state);
void disco_items_with_node(void** state);
void disco_info_error_item_not_found(void** state);
void no_automatic_disco_after_connect(void** state);