Module Name: src Committed By: pgoyette Date: Sat Mar 5 18:14:33 UTC 2011
Modified Files: src/tests/kernel: Makefile Added Files: src/tests/kernel: h_ps_strings1.c h_ps_strings2.c t_ps_strings.sh Log Message: Add tests for verifying the recent changes to ps_strings >From joerg@ with atf-ification from myself. To generate a diff of this commit: cvs rdiff -u -r1.9 -r1.10 src/tests/kernel/Makefile cvs rdiff -u -r0 -r1.1 src/tests/kernel/h_ps_strings1.c \ src/tests/kernel/h_ps_strings2.c src/tests/kernel/t_ps_strings.sh Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/tests/kernel/Makefile diff -u src/tests/kernel/Makefile:1.9 src/tests/kernel/Makefile:1.10 --- src/tests/kernel/Makefile:1.9 Thu Nov 11 17:36:57 2010 +++ src/tests/kernel/Makefile Sat Mar 5 18:14:33 2011 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.9 2010/11/11 17:36:57 pooka Exp $ +# $NetBSD: Makefile,v 1.10 2011/03/05 18:14:33 pgoyette Exp $ NOMAN= # defined @@ -23,6 +23,11 @@ TESTS_C+= t_filedesc TESTS_SH= t_umount +TESTS_SH+= t_ps_strings + +BINDIR= ${TESTSDIR} +PROGS= h_ps_strings1 +PROGS+= h_ps_strings2 LDADD.t_rnd+= -lrumpvfs -lrumpdev_rnd -lrumpdev -lrump -lrumpuser -lpthread LDADD.t_filedesc+= -lrumpvfs -lrumpdev_rnd -lrumpdev -lrump -lrumpuser -lpthread Added files: Index: src/tests/kernel/h_ps_strings1.c diff -u /dev/null src/tests/kernel/h_ps_strings1.c:1.1 --- /dev/null Sat Mar 5 18:14:33 2011 +++ src/tests/kernel/h_ps_strings1.c Sat Mar 5 18:14:33 2011 @@ -0,0 +1,74 @@ +/* $NetBSD: h_ps_strings1.c,v 1.1 2011/03/05 18:14:33 pgoyette Exp $ */ +/*- + * Copyright (c) 2011 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Joerg Sonnenberger. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <sys/types.h> +#include <sys/exec.h> +#include <stdlib.h> +#include <unistd.h> + +extern struct ps_strings *__ps_strings; + +int +main(int argc, char **argv, char **environ) +{ + int ret = 0; + int nenv; + + if (__ps_strings->ps_nargvstr != argc) { + static const char nargv_err[] = "Wrong argc in ps_strings"; + write(STDOUT_FILENO, nargv_err, sizeof(nargv_err)); + ret = 1; + } + + if (__ps_strings->ps_argvstr != argv) { + static const char argv_err[] = "Wrong argv in ps_strings"; + write(STDOUT_FILENO, argv_err, sizeof(argv_err)); + ret = 1; + } + + if (__ps_strings->ps_envstr != environ) { + static const char env_err[] = "Wrong env in ps_strings"; + write(STDOUT_FILENO, env_err, sizeof(env_err)); + ret = 1; + } + nenv = 0; + while (environ[nenv]) + ++nenv; + if (__ps_strings->ps_nenvstr != nenv) { + static const char nenv_err[] = "Wrong nenv in ps_strings"; + write(STDOUT_FILENO, nenv_err, sizeof(nenv_err)); + ret = 1; + } + + return ret; +} Index: src/tests/kernel/h_ps_strings2.c diff -u /dev/null src/tests/kernel/h_ps_strings2.c:1.1 --- /dev/null Sat Mar 5 18:14:33 2011 +++ src/tests/kernel/h_ps_strings2.c Sat Mar 5 18:14:33 2011 @@ -0,0 +1,69 @@ +/* $NetBSD: h_ps_strings2.c,v 1.1 2011/03/05 18:14:33 pgoyette Exp $ */ +/*- + * Copyright (c) 2011 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Joerg Sonnenberger. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, + * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT + * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include <sys/types.h> +#include <sys/exec.h> +#include <err.h> +#include <limits.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +#define LEN 16384 + +extern struct ps_strings *__ps_strings; + +int +main(void) +{ + size_t i; + char buf[16]; + char **argv; + + if ((argv = calloc(LEN, sizeof(*argv))) == NULL) + errx(1, "calloc failed"); + for (i = 0; i < LEN; ++i) { + snprintf(buf, sizeof(buf), "arg%04zx", i); + if ((argv[i] = strdup(buf)) == NULL) + errx(1, "strdup failed"); + } + __ps_strings->ps_argvstr = argv; + __ps_strings->ps_nargvstr = LEN; + + printf("Sleeping forever...\n"); + do { + sleep(UINT_MAX); + } while /* CONSTCOND */ (1); + return 0; +} Index: src/tests/kernel/t_ps_strings.sh diff -u /dev/null src/tests/kernel/t_ps_strings.sh:1.1 --- /dev/null Sat Mar 5 18:14:33 2011 +++ src/tests/kernel/t_ps_strings.sh Sat Mar 5 18:14:33 2011 @@ -0,0 +1,85 @@ +# $NetBSD: t_ps_strings.sh,v 1.1 2011/03/05 18:14:33 pgoyette Exp $ +# +# Copyright (c) 2008 The NetBSD Foundation, Inc. +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS +# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED +# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS +# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +# POSSIBILITY OF SUCH DAMAGE. +# + +atf_test_case validate +validate_head() +{ + atf_set "descr" "Validates ps_strings passed to program" +} +validate_body() +{ + atf_check -s exit:0 -o ignore -e ignore \ + $(atf_get_srcdir)/h_ps_strings1 +} + +# Function to parse and validate the output from ps + +parse_ps() { + local pid seq arg + + pid="$1" ; shift + + while [ "$1" != "$pid" ] ; do + echo $1 + shift + done + if [ $# -eq 0 ] ; then + echo "NO_PID" + return + fi + shift + + seq=0 + while [ $# -gt 1 ] ; do + arg=$(printf "arg%04x" $seq) + if [ "$arg" != "$1" ] ; then + echo BAD_$seq + return + fi + shift + done + echo "OK" +} + +atf_test_case update +update_head() +{ + atf_set "descr" "Check updating of ps_strings" +} +update_body() +{ + $(atf_get_srcdir)/h_ps_strings2 > /dev/null 2>&1 & + h_pid=$! + parse=$(parse_ps $h_pid $(ps -wwo pid,args -p $h_pid) ) + kill $h_pid +} + +atf_init_test_cases() +{ + atf_add_test_case validate + atf_add_test_case update +}