Enable gating tests for libtevent
Resolves: rhbz#1962801
This commit is contained in:
parent
a34d31a502
commit
6d45680515
6
gating.yaml
Normal file
6
gating.yaml
Normal file
@ -0,0 +1,6 @@
|
||||
--- !Policy
|
||||
product_versions:
|
||||
- rhel-9
|
||||
decision_context: osci_compose_gate
|
||||
rules:
|
||||
- !PassingTestCaseRule {test_case_name: osci.brew-build.tier0.functional}
|
||||
46
tests/sanity-tests/Makefile
Normal file
46
tests/sanity-tests/Makefile
Normal 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
34
tests/sanity-tests/runtest.sh
Executable 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
|
||||
207
tests/sanity-tests/test-libtevent.c
Normal file
207
tests/sanity-tests/test-libtevent.c
Normal 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(¤t_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
12
tests/tests.yml
Normal file
@ -0,0 +1,12 @@
|
||||
- hosts: localhost
|
||||
roles:
|
||||
- role: standard-test-beakerlib
|
||||
tags:
|
||||
- classic
|
||||
tests:
|
||||
- sanity-tests
|
||||
required_packages:
|
||||
- libtevent
|
||||
- libtevent-devel
|
||||
- glibc
|
||||
- gcc
|
||||
Loading…
Reference in New Issue
Block a user