From ce700d94f54eae64d0f3aac0c6ef50a051dd9a2b Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Tue, 14 Apr 2015 22:34:01 +0200 Subject: [PATCH] platform: add nm-platform-utils.[ch] files There is no general purpose file for platform utilities. We only have nm-platform.h, which contains (mostly) functions that operate on a NMPlatform instance (and that can be mocked using NMFakePlatform). Add a new file for independent utility functions. nm-platform-utils.c should not call into functions having a NMPlatform instance, to have them independent from platform caching and the platform singleton. --- src/Makefile.am | 4 ++++ src/platform/nm-platform-utils.c | 23 +++++++++++++++++++ src/platform/nm-platform-utils.h | 29 +++++++++++++++++++++++ src/platform/tests/.gitignore | 9 ++++---- src/platform/tests/Makefile.am | 8 +++++++ src/platform/tests/test-general.c | 38 +++++++++++++++++++++++++++++++ 6 files changed, 107 insertions(+), 4 deletions(-) create mode 100644 src/platform/nm-platform-utils.c create mode 100644 src/platform/nm-platform-utils.h create mode 100644 src/platform/tests/test-general.c diff --git a/src/Makefile.am b/src/Makefile.am index 911bec9163..76b0bd4ca6 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -225,6 +225,8 @@ nm_sources = \ platform/nm-linux-platform.h \ platform/nm-platform.c \ platform/nm-platform.h \ + platform/nm-platform-utils.c \ + platform/nm-platform-utils.h \ platform/wifi/wifi-utils-nl80211.c \ platform/wifi/wifi-utils-nl80211.h \ platform/wifi/wifi-utils-private.h \ @@ -464,6 +466,8 @@ libnm_iface_helper_la_SOURCES = \ platform/nm-linux-platform.h \ platform/nm-platform.c \ platform/nm-platform.h \ + platform/nm-platform-utils.c \ + platform/nm-platform-utils.h \ platform/wifi/wifi-utils-nl80211.c \ platform/wifi/wifi-utils-nl80211.h \ platform/wifi/wifi-utils-private.h \ diff --git a/src/platform/nm-platform-utils.c b/src/platform/nm-platform-utils.c new file mode 100644 index 0000000000..34d4b0a69a --- /dev/null +++ b/src/platform/nm-platform-utils.c @@ -0,0 +1,23 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ +/* nm-platform.c - Handle runtime kernel networking configuration + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, 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 General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Copyright (C) 2015 Red Hat, Inc. + */ + +#include "nm-platform-utils.h" + + diff --git a/src/platform/nm-platform-utils.h b/src/platform/nm-platform-utils.h new file mode 100644 index 0000000000..a6da1a8934 --- /dev/null +++ b/src/platform/nm-platform-utils.h @@ -0,0 +1,29 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ +/* nm-platform.c - Handle runtime kernel networking configuration + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, 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 General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Copyright (C) 2015 Red Hat, Inc. + */ + +#ifndef __NM_PLATFORM_UTILS_H__ +#define __NM_PLATFORM_UTILS_H__ + +#include "config.h" + +#include "nm-platform.h" + + +#endif /* __NM_PLATFORM_UTILS_H__ */ diff --git a/src/platform/tests/.gitignore b/src/platform/tests/.gitignore index 5457fbca6c..cdd8a51f83 100644 --- a/src/platform/tests/.gitignore +++ b/src/platform/tests/.gitignore @@ -1,11 +1,12 @@ /dump /monitor /platform -/test-link-fake -/test-link-linux /test-address-fake /test-address-linux +/test-cleanup-fake +/test-cleanup-linux +/test-general +/test-link-fake +/test-link-linux /test-route-fake /test-route-linux -/test-cleanup-fake -/test-cleanup-linux \ No newline at end of file diff --git a/src/platform/tests/Makefile.am b/src/platform/tests/Makefile.am index 92400f9091..76b40f7ca3 100644 --- a/src/platform/tests/Makefile.am +++ b/src/platform/tests/Makefile.am @@ -37,6 +37,7 @@ noinst_PROGRAMS = \ test-link-linux \ test-address-fake \ test-address-linux \ + test-general \ test-route-fake \ test-route-linux \ test-cleanup-fake \ @@ -109,12 +110,19 @@ test_cleanup_linux_CPPFLAGS = \ -DKERNEL_HACKS=1 test_cleanup_linux_LDADD = $(PLATFORM_LDADD) +test_general_SOURCES = \ + test-general.c +test_general_LDADD = \ + $(top_builddir)/src/libNetworkManager.la + + @VALGRIND_RULES@ TESTS = \ test-address-fake \ test-address-linux \ test-cleanup-fake \ test-cleanup-linux \ + test-general \ test-link-fake \ test-link-linux \ test-route-fake \ diff --git a/src/platform/tests/test-general.c b/src/platform/tests/test-general.c new file mode 100644 index 0000000000..2f29d7de70 --- /dev/null +++ b/src/platform/tests/test-general.c @@ -0,0 +1,38 @@ +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ +/* nm-platform.c - Handle runtime kernel networking configuration + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, 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 General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Copyright (C) 2015 Red Hat, Inc. + */ + +#include "nm-platform-utils.h" + +#include "nm-logging.h" + +#include "nm-test-utils.h" + + +/******************************************************************/ + +NMTST_DEFINE (); + +int +main (int argc, char **argv) +{ + nmtst_init_assert_logging (&argc, &argv, "INFO", "DEFAULT"); + + return g_test_run (); +}