Add missing tests to fix osci.brew-build.tier0.functional

resolves: rhbz#2190425
This commit is contained in:
Pavel Filipenský 2023-05-24 12:07:31 +02:00
parent bf00a4bc41
commit 36891a9595
6 changed files with 303 additions and 12 deletions

View File

@ -8,7 +8,7 @@
Name: libtevent
Version: 0.14.1
Release: 1%{?dist}
Release: 2%{?dist}
Summary: The tevent library
License: LGPL-3.0-or-later
URL: http://tevent.samba.org/
@ -107,6 +107,9 @@ cp -a doc/man/man3 %{buildroot}%{_mandir}
%ldconfig_scriptlets
%changelog
* Wed May 24 2023 Pavel Filipenský <pfilipen@redhat.com> - 0.14.1-2
- resolves: rhbz#2190425 - Add missing tests to fix osci.brew-build.tier0.functional
* Thu May 18 2023 Pavel Filipenský <pfilipen@redhat.com> - 0.14.1-1
- resolves: rhbz#2190425 Update to version 0.14.1

View File

@ -0,0 +1,46 @@
# SPDX-License-Identifier: LGPL-2.1+
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#
# Makefile of /CoreOS/libtevent
# Description: Test if libtevent working ok
# Author: Susant Sahani<susant@redhat.com>
#
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
export TEST=/CoreOS/libtevent
export TESTVERSION=1.0
OBJS = test-libtevent.c
CFLAG = -Wall -g3
CC = gcc
LIBS = -ltevent -ltalloc -lpthread
test-libtevent:${OBJ}
${CC} ${CFLAGS} ${INCLUDES} -o $@ ${OBJS} ${LIBS}
run: test-libtevent
./runtest.sh
clean:
-rm -f *~ test-libtevent
.c.o:
${CC} ${CFLAGS} ${INCLUDES} -c $<
CC = gcc
include /usr/share/rhts/lib/rhts-make.include
$(METADATA): Makefile
@echo "Owner: Susant Sahani<susant@redhat.com>" > $(METADATA)
@echo "Name: $(TEST)" >> $(METADATA)
@echo "TestVersion: $(TESTVERSION)" >> $(METADATA)
@echo "Path: $(TEST_DIR)" >> $(METADATA)
@echo "Description: Test libtevent works ok" >> $(METADATA)
@echo "Type: Sanity" >> $(METADATA)
@echo "TestTime: 5m" >> $(METADATA)
@echo "RunFor: libtevent" >> $(METADATA)
@echo "Requires: libtevent libtevent-devel" >> $(METADATA)
@echo "Priority: Normal" >> $(METADATA)
@echo "License: GPLv2" >> $(METADATA)
@echo "Confidential: no" >> $(METADATA)
@echo "Destructive: no" >> $(METADATA)
@echo "Releases: -RedHat Linux 8" >> $(METADATA)
rhts-lint $(METADATA)

34
tests/sanity-tests/runtest.sh Executable file
View File

@ -0,0 +1,34 @@
#!/bin/bash
# SPDX-License-Identifier: LGPL-2.1+
# ~~~
# runtest.sh of libtevent
# Description: Tests for libtevent
#
# Author: Susant Sahani <susant@redhat.com>
# Copyright (c) 2018 Red Hat, Inc.
# ~~~
# Include Beaker environment
. /usr/share/beakerlib/beakerlib.sh || exit 1
PACKAGE="libtevent"
rlJournalStart
rlPhaseStartSetup
rlAssertRpm $PACKAGE
rlRun "cp test-libtevent /usr/bin/"
rlPhaseEnd
rlPhaseStartTest
rlLog "Starting libtevent tests ..."
rlRun "/usr/bin/test-libtevent"
rlPhaseEnd
rlPhaseStartCleanup
rlRun "rm /usr/bin/test-libtevent"
rlLog "libtevent tests done"
rlPhaseEnd
rlJournalPrintText
rlJournalEnd
rlGetTestState

View File

@ -0,0 +1,207 @@
#include <stdio.h>
#include <unistd.h>
#include <tevent.h>
#include <sys/time.h>
#include <signal.h>
#include <assert.h>
#include <pthread.h>
struct state {
struct timeval endtime;
int counter;
TALLOC_CTX *ctx;
};
struct info_struct {
int counter;
};
static void callback(struct tevent_context *ev, struct tevent_timer *tim,
struct timeval current_time, void *private_data) {
struct state *data = talloc_get_type_abort(private_data, struct state);
struct tevent_timer *time_event;
struct timeval schedule;
data->counter += 1;
if (tevent_timeval_compare(&current_time, &(data->endtime)) < 0) {
schedule = tevent_timeval_current_ofs(1, 0);
time_event = tevent_add_timer(ev, data->ctx, schedule, callback, data);
assert(time_event);
}
}
int test_tevent_timer(void) {
struct tevent_context *event_ctx;
struct tevent_timer *time_event;
struct timeval schedule;
struct state *data;
TALLOC_CTX *mem_ctx;
assert((mem_ctx = talloc_new(NULL)));
assert((event_ctx = tevent_context_init(mem_ctx)));
assert((data = talloc(mem_ctx, struct state)));
schedule = tevent_timeval_current_ofs(1, 0);
data->endtime = tevent_timeval_add(&schedule, 2, 0);
data->ctx = mem_ctx;
data->counter = 0;
time_event = tevent_add_timer(event_ctx, mem_ctx, schedule, callback, data);
tevent_loop_wait(event_ctx);
assert(data->counter == 3);
talloc_free(mem_ctx);
}
static void foo(struct tevent_context *ev, struct tevent_immediate *im, void *private_data) {
struct info_struct *data = talloc_get_type_abort(private_data, struct info_struct);
data->counter++;
}
int test_tevent_immediate(void) {
struct tevent_context *event_ctx;
struct tevent_immediate *im;
struct info_struct *data;
TALLOC_CTX *mem_ctx;
assert((mem_ctx = talloc_new(NULL)));
event_ctx = tevent_context_init(mem_ctx);
assert((data = talloc(mem_ctx, struct info_struct)));
data->counter = 0;
assert((im = tevent_create_immediate(mem_ctx)));
tevent_schedule_immediate(im, event_ctx, foo, data);
tevent_loop_wait(event_ctx);
assert(data->counter == 1);
talloc_free(mem_ctx);
return 0;
}
int signal_data;
static void handler(struct tevent_context *ev, struct tevent_signal *se, int signum, int count, void *siginfo, void *private_data) {
signal_data = 1;
}
int test_tevent_signal(void) {
struct tevent_context *event_ctx;
struct tevent_signal *sig;
TALLOC_CTX *mem_ctx;
mem_ctx = talloc_new(NULL);
assert(mem_ctx);
event_ctx = tevent_context_init(mem_ctx);
assert(event_ctx);
if (tevent_signal_support(event_ctx)) {
sig = tevent_add_signal(event_ctx, mem_ctx, SIGINT, 0, handler, NULL);
assert(sig);
tevent_loop_once(event_ctx);
}
talloc_free(mem_ctx);
}
struct foo_state {
int x;
};
struct testA {
int y;
};
static void foo_done(struct tevent_req *req) {
struct foo_state *a = tevent_req_data(req, struct foo_state);
struct testA *b = tevent_req_callback_data(req, struct testA);
struct testA *c = (struct testA *) tevent_req_callback_data_void(req);
assert(a->x == 10);
assert(b->y == 9);
assert(c->y == 9);
printf("a->x: %d\n", a->x);
printf("b->y: %d\n", b->y);
printf("c->y: %d\n", c->y);
}
struct tevent_req * foo_send(TALLOC_CTX *mem_ctx, struct tevent_context *event_ctx) {
struct tevent_req *req;
struct foo_state *state;
printf("_send\n");
req = tevent_req_create(event_ctx, &state, struct foo_state);
state->x = 10;
return req;
}
static void run(struct tevent_context *ev, struct tevent_timer *te,
struct timeval current_time, void *private_data) {
struct tevent_req *req;
struct testA *tmp = talloc(ev, struct testA);
tmp->y = 9;
req = foo_send(ev, ev);
tevent_req_set_callback(req, foo_done, tmp);
tevent_req_done(req);
}
int test_event_data(void) {
struct tevent_context *event_ctx;
struct tevent_timer *time_event;
struct testA *data;
TALLOC_CTX *mem_ctx;
mem_ctx = talloc_new(NULL);
assert(mem_ctx);
event_ctx = tevent_context_init(mem_ctx);
assert(event_ctx);
data = talloc(mem_ctx, struct testA);
data->y = 11;
time_event = tevent_add_timer(event_ctx,
mem_ctx,
tevent_timeval_current(),
run,
data);
assert(time_event);
tevent_loop_once(event_ctx);
talloc_free(mem_ctx);
return 0;
}
int main() {
pid_t pid, ppid;
int r;
test_tevent_timer();
test_tevent_immediate();
/* signal test */
ppid = getpid();
if((pid = fork()) == 0) {
sleep(1);
kill(ppid, SIGINT);
exit(0);
} else {
test_tevent_signal();
}
assert(signal_data == 1);
test_event_data();
}

12
tests/tests.yml Normal file
View File

@ -0,0 +1,12 @@
- hosts: localhost
roles:
- role: standard-test-beakerlib
tags:
- classic
tests:
- sanity-tests
required_packages:
- libtevent
- libtevent-devel
- glibc
- gcc

View File

@ -1,11 +0,0 @@
-----BEGIN PGP SIGNATURE-----
iQEzBAABCgAdFiEEkUejOXGVGO6QEby1R5ORYRMIQCUFAmLgAnsACgkQR5ORYRMI
QCXT+Qf/Sw3PKIDVsTwQ2Rk6tUNL1Ji+qPnjDHOJeS2E7wpjZd1JPbaPGfxB6N3+
ahMWrXbJhUNYf849c80i5sq2sivzvXZG79MDYlIzQb6nGVl3fD15D0vp8xU8ot7p
bijYJTd+8v9uQitGGqbWncQ2+5GG/Wlq82S7asI0Dm5yrB5N6Q8ozVejBqlAm6To
jC1bp2BK3bQUA5zpORfVuK8s8EpgcY9PmGx7HqvPb/NMFl7StpnruvSh/05TSB5L
yOXEYpiAkpW/kqxfofZiRsZVRJWNPJvo+g5HFNE5DQUSuRw3jKtWmfJ1cn05DVIQ
l62907jEVxyaFwZORbrvDChn6e7c8w==
=d2iL
-----END PGP SIGNATURE-----