Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/tests/kernel Add tests for verifying the recent changes to p...



details:   https://anonhg.NetBSD.org/src/rev/9c33e8063067
branches:  trunk
changeset: 762915:9c33e8063067
user:      pgoyette <pgoyette%NetBSD.org@localhost>
date:      Sat Mar 05 18:14:33 2011 +0000

description:
Add tests for verifying the recent changes to ps_strings

>From joerg@ with atf-ification from myself.

diffstat:

 tests/kernel/Makefile        |   7 +++-
 tests/kernel/h_ps_strings1.c |  74 ++++++++++++++++++++++++++++++++++++++
 tests/kernel/h_ps_strings2.c |  69 +++++++++++++++++++++++++++++++++++
 tests/kernel/t_ps_strings.sh |  85 ++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 234 insertions(+), 1 deletions(-)

diffs (261 lines):

diff -r 171b9cf0daac -r 9c33e8063067 tests/kernel/Makefile
--- a/tests/kernel/Makefile     Sat Mar 05 16:38:46 2011 +0000
+++ b/tests/kernel/Makefile     Sat Mar 05 18:14:33 2011 +0000
@@ -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
diff -r 171b9cf0daac -r 9c33e8063067 tests/kernel/h_ps_strings1.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/kernel/h_ps_strings1.c      Sat Mar 05 18:14:33 2011 +0000
@@ -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;
+}
diff -r 171b9cf0daac -r 9c33e8063067 tests/kernel/h_ps_strings2.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/kernel/h_ps_strings2.c      Sat Mar 05 18:14:33 2011 +0000
@@ -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;
+}
diff -r 171b9cf0daac -r 9c33e8063067 tests/kernel/t_ps_strings.sh
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/kernel/t_ps_strings.sh      Sat Mar 05 18:14:33 2011 +0000
@@ -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
+}



Home | Main Index | Thread Index | Old Index