diff options
author | Holger Hans Peter Freyther <zecke@selfish.org> | 2012-11-11 14:21:26 +0100 |
---|---|---|
committer | Holger Hans Peter Freyther <zecke@selfish.org> | 2013-01-15 20:06:40 +0100 |
commit | 97602d973457a5248ada6ca9e5c29c1a5811240d (patch) | |
tree | 3de3619f51a42d3f7e3df539d0068a942b316db6 /tests/fr | |
parent | e04a14d9a23ed42178c405cb0c0afb9a2d2b93ab (diff) |
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.
Diffstat (limited to 'tests/fr')
-rw-r--r-- | tests/fr/fr_test.c | 76 | ||||
-rw-r--r-- | tests/fr/fr_test.err | 0 | ||||
-rw-r--r-- | tests/fr/fr_test.ok | 1 |
3 files changed, 77 insertions, 0 deletions
diff --git a/tests/fr/fr_test.c b/tests/fr/fr_test.c new file mode 100644 index 00000000..c09ce7b4 --- /dev/null +++ b/tests/fr/fr_test.c @@ -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; +} + + diff --git a/tests/fr/fr_test.err b/tests/fr/fr_test.err new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/tests/fr/fr_test.err diff --git a/tests/fr/fr_test.ok b/tests/fr/fr_test.ok new file mode 100644 index 00000000..6a928840 --- /dev/null +++ b/tests/fr/fr_test.ok @@ -0,0 +1 @@ +Result: PASSED |