fr: Begin with a GRE/FrameRelay test due the recent regression

The framerelay code is seldomly used and the socket clean ups introduced
a regression. Create a testcase that will work as a user not having the
right capabilities to create raw sockets.

We have to make sure that this test is working even when not ran as root.
The easiest way to do this is to provide our own socket implementation.
This is done with dlopen/dlsym to convert the raw socket request to an UDP
one.
This commit is contained in:
Holger Hans Peter Freyther 2012-11-11 14:21:26 +01:00
parent e04a14d9a2
commit 97602d9734
6 changed files with 93 additions and 2 deletions

1
.gitignore vendored
View File

@ -68,6 +68,7 @@ tests/gsm0808/gsm0808_test
tests/gb/bssgp_fc_test
tests/gsm0408/gsm0408_test
tests/logging/logging_test
tests/fr/fr_test
utils/osmo-arfcn
utils/osmo-auc-gen

View File

@ -4,7 +4,7 @@ check_PROGRAMS = timer/timer_test sms/sms_test ussd/ussd_test \
smscb/smscb_test bits/bitrev_test a5/a5_test \
conv/conv_test auth/milenage_test lapd/lapd_test \
gsm0808/gsm0808_test gsm0408/gsm0408_test \
gb/bssgp_fc_test logging/logging_test
gb/bssgp_fc_test logging/logging_test fr/fr_test
if ENABLE_MSGFILE
check_PROGRAMS += msgfile/msgfile_test
endif
@ -51,6 +51,10 @@ gb_bssgp_fc_test_LDADD = $(top_builddir)/src/libosmocore.la $(top_builddir)/src/
logging_logging_test_SOURCES = logging/logging_test.c
logging_logging_test_LDADD = $(top_builddir)/src/libosmocore.la
fr_fr_test_SOURCES = fr/fr_test.c
fr_fr_test_LDADD = $(top_builddir)/src/libosmocore.la $(top_builddir)/src/gb/libosmogb.la
# The `:;' works around a Bash 3.2 bug when the output is not writeable.
$(srcdir)/package.m4: $(top_srcdir)/configure.ac
:;{ \
@ -77,7 +81,8 @@ EXTRA_DIST = testsuite.at $(srcdir)/package.m4 $(TESTSUITE) \
gsm0808/gsm0808_test.ok gb/bssgp_fc_tests.err \
gb/bssgp_fc_tests.ok gb/bssgp_fc_tests.sh \
msgfile/msgfile_test.ok msgfile/msgconfig.cfg \
logging/logging_test.ok logging/logging_test.err
logging/logging_test.ok logging/logging_test.err \
fr/fr_test.ok
DISTCLEANFILES = atconfig

76
tests/fr/fr_test.c Normal file
View File

@ -0,0 +1,76 @@
/*
* (C) 2012 by Holger Hans Peter Freyther <zecke@selfish.org>
* All Rights Reserved
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
#define _GNU_SOURCE
#include <osmocom/core/application.h>
#include <osmocom/gprs/gprs_ns.h>
#include <stdio.h>
#include <stdlib.h>
#include <dlfcn.h>
int (*real_socket)(int, int, int);
static int GR_SOCKET = -1;
static void resolve_real(void)
{
if (real_socket)
return;
real_socket = dlsym(RTLD_NEXT, "socket");
}
int socket(int domain, int type, int protocol)
{
int fd;
resolve_real();
if (domain != AF_INET || type != SOCK_RAW || protocol != IPPROTO_GRE)
return (*real_socket)(domain, type, protocol);
/* Now call socket with a normal UDP/IP socket and assign to GR_SOCKET */
fd = (*real_socket)(domain, SOCK_DGRAM, IPPROTO_UDP);
GR_SOCKET = fd;
return fd;
}
void bssgp_prim_cb()
{
}
static const struct log_info log_info = {};
int main(int argc, char **argv)
{
int rc;
struct gprs_ns_inst *nsi;
log_init(&log_info, NULL);
nsi = gprs_ns_instantiate(NULL, NULL);
nsi->frgre.enabled = 1;
rc = gprs_ns_frgre_listen(nsi);
printf("Result: %s\n", rc == GR_SOCKET ? "PASSED" : "FAILED");
return rc == GR_SOCKET ? EXIT_SUCCESS : EXIT_FAILURE;
}

0
tests/fr/fr_test.err Normal file
View File

1
tests/fr/fr_test.ok Normal file
View File

@ -0,0 +1 @@
Result: PASSED

View File

@ -91,3 +91,11 @@ cat $abs_srcdir/logging/logging_test.ok > expout
cat $abs_srcdir/logging/logging_test.err > experr
AT_CHECK([$abs_top_builddir/tests/logging/logging_test], [], [expout], [experr])
AT_CLEANUP
AT_SETUP([fr])
AT_KEYWORDS([fr])
cat $abs_srcdir/fr/fr_test.ok > expout
cat $abs_srcdir/fr/fr_test.err > experr
AT_CHECK([$abs_top_builddir/tests/fr/fr_test], [], [expout], [experr])
AT_CLEANUP