[lxc-devel] [PATCH] introduce a simple test for testing add_device_node and remove_device_node

Serge Hallyn serge.hallyn at ubuntu.com
Mon Jan 13 16:09:55 UTC 2014


Quoting S.Çağlar Onur (caglar at 10ur.org):
> Signed-off-by: S.Çağlar Onur <caglar at 10ur.org>

Acked-by: Serge E. Hallyn <serge.hallyn at ubuntu.com>

> ---
>  .gitignore                    |  7 +++--
>  src/tests/Makefile.am         |  4 ++-
>  src/tests/device_add_remove.c | 72 +++++++++++++++++++++++++++++++++++++++++++
>  3 files changed, 79 insertions(+), 4 deletions(-)
>  create mode 100644 src/tests/device_add_remove.c
> 
> diff --git a/.gitignore b/.gitignore
> index 89f1640..d986f6a 100644
> --- a/.gitignore
> +++ b/.gitignore
> @@ -81,6 +81,7 @@ src/lxc/version.h
>  src/python-lxc/build/
>  src/python-lxc/lxc/__pycache__/
>  
> +src/tests/lxc-test-device-add-remove
>  src/tests/lxc-test-attach
>  src/tests/lxc-test-cgpath
>  src/tests/lxc-test-clonetest
> @@ -91,16 +92,16 @@ src/tests/lxc-test-createtest
>  src/tests/lxc-test-destroytest
>  src/tests/lxc-test-get_item
>  src/tests/lxc-test-getkeys
> +src/tests/lxc-test-list
>  src/tests/lxc-test-locktests
>  src/tests/lxc-test-lxcpath
> +src/tests/lxc-test-may-control
> +src/tests/lxc-test-reboot
>  src/tests/lxc-test-saveconfig
>  src/tests/lxc-test-shutdowntest
>  src/tests/lxc-test-snapshot
>  src/tests/lxc-test-startone
>  src/tests/lxc-usernic-test
> -src/tests/lxc-test-may-control
> -src/tests/lxc-test-reboot
> -src/tests/lxc-test-list
>  
>  config/compile
>  config/config.guess
> diff --git a/src/tests/Makefile.am b/src/tests/Makefile.am
> index ab956be..c7f0e88 100644
> --- a/src/tests/Makefile.am
> +++ b/src/tests/Makefile.am
> @@ -21,6 +21,7 @@ lxc_test_may_control_SOURCES = may_control.c
>  lxc_test_reboot_SOURCES = reboot.c
>  lxc_test_list_SOURCES = list.c
>  lxc_test_attach_SOURCES = attach.c
> +lxc_test_device_add_remove_SOURCES = device_add_remove.c
>  
>  AM_CFLAGS=-I$(top_srcdir)/src \
>  	-DLXCROOTFSMOUNT=\"$(LXCROOTFSMOUNT)\" \
> @@ -42,7 +43,7 @@ bin_PROGRAMS = lxc-test-containertests lxc-test-locktests lxc-test-startone \
>  	lxc-test-shutdowntest lxc-test-get_item lxc-test-getkeys lxc-test-lxcpath \
>  	lxc-test-cgpath lxc-test-clonetest lxc-test-console \
>  	lxc-test-snapshot lxc-test-concurrent lxc-test-may-control \
> -	lxc-test-reboot lxc-test-list lxc-test-attach
> +	lxc-test-reboot lxc-test-list lxc-test-attach lxc-test-device-add-remove
>  
>  bin_SCRIPTS = lxc-test-usernic
>  
> @@ -71,4 +72,5 @@ EXTRA_DIST = \
>  	concurrent.c \
>  	may_control.c \
>  	lxc-test-ubuntu \
> +	device_add_remove.c \
>  	list.c
> diff --git a/src/tests/device_add_remove.c b/src/tests/device_add_remove.c
> new file mode 100644
> index 0000000..c776729
> --- /dev/null
> +++ b/src/tests/device_add_remove.c
> @@ -0,0 +1,72 @@
> +/* DEVICE_add_remove.c
> + *
> + * Copyright © 2014 S.Çağlar Onur <caglar at 10ur.org>
> + *
> + * This program is free software; you can redistribute it and/or modify
> + * it under the terms of the GNU General Public License version 2, as
> + * published by the Free Software Foundation.
> + *
> + * 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.
> + */
> +
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <lxc/lxccontainer.h>
> +
> +#define NAME "device_add_remove_test"
> +#define DEVICE "/dev/network_latency"
> +
> +int main(int argc, char *argv[])
> +{
> +	int ret = 1;
> +	struct lxc_container *c;
> +
> +	c = lxc_container_new(NAME, NULL);
> +	if (!c) {
> +		fprintf(stderr, "Unable to instantiate container (%s)...\n", NAME);
> +		goto out;
> +	}
> +
> +	if (!c->create(c, "busybox", NULL, NULL, 1, NULL)) {
> +		fprintf(stderr, "Creating the container (%s) failed...\n", NAME);
> +		goto out;
> +	}
> +
> +	c->want_daemonize(c, true);
> +
> +	if (!c->start(c, false, NULL)) {
> +		fprintf(stderr, "Starting the container (%s) failed...\n", NAME);
> +		goto out;
> +	}
> +
> +	if (!c->add_device_node(c, DEVICE, DEVICE)) {
> +		fprintf(stderr, "Adding %s to the container (%s) failed...\n", DEVICE, NAME);
> +		goto out;
> +	}
> +	if (!c->remove_device_node(c, DEVICE, DEVICE)) {
> +		fprintf(stderr, "Removing %s from the container (%s) failed...\n", DEVICE, NAME);
> +		goto out;
> +	}
> +
> +	if (!c->stop(c)) {
> +		fprintf(stderr, "Stopping the container (%s) failed...\n", NAME);
> +		goto out;
> +	}
> +
> +	if (!c->destroy(c)) {
> +		fprintf(stderr, "Destroying the container (%s) failed...\n", NAME);
> +		goto out;
> +	}
> +	ret = 0;
> +
> +out:
> +	lxc_container_put(c);
> +	return ret;
> +}
> -- 
> 1.8.3.2
> 
> _______________________________________________
> lxc-devel mailing list
> lxc-devel at lists.linuxcontainers.org
> http://lists.linuxcontainers.org/listinfo/lxc-devel


More information about the lxc-devel mailing list