Source-Changes-HG archive

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

[src/trunk]: src/tests/lib/libc/sys add tests for maxrss, msgsnd



details:   https://anonhg.NetBSD.org/src/rev/a00b08395edf
branches:  trunk
changeset: 318867:a00b08395edf
user:      christos <christos%NetBSD.org@localhost>
date:      Tue May 08 01:02:38 2018 +0000
description:
add tests for maxrss, msgsnd

diffstat:

 tests/lib/libc/sys/t_getrusage.c |  68 ++++++++++++++++++++++++++++++++++++++-
 1 files changed, 66 insertions(+), 2 deletions(-)

diffs (106 lines):

diff -r c02a1472c722 -r a00b08395edf tests/lib/libc/sys/t_getrusage.c
--- a/tests/lib/libc/sys/t_getrusage.c  Mon May 07 23:42:13 2018 +0000
+++ b/tests/lib/libc/sys/t_getrusage.c  Tue May 08 01:02:38 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: t_getrusage.c,v 1.5 2017/01/13 20:31:06 christos Exp $ */
+/* $NetBSD: t_getrusage.c,v 1.6 2018/05/08 01:02:38 christos Exp $ */
 
 /*-
  * Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -29,17 +29,21 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: t_getrusage.c,v 1.5 2017/01/13 20:31:06 christos Exp $");
+__RCSID("$NetBSD: t_getrusage.c,v 1.6 2018/05/08 01:02:38 christos Exp $");
 
 #include <sys/resource.h>
 #include <sys/time.h>
 
 #include <atf-c.h>
+#include <stdio.h>
 #include <errno.h>
 #include <limits.h>
 #include <signal.h>
 #include <stdint.h>
+#include <stdlib.h>
 #include <string.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
 
 static void            work(void);
 static void            sighandler(int);
@@ -117,6 +121,64 @@
                atf_tc_fail("getrusage(2) did not record signals");
 }
 
+ATF_TC(getrusage_maxrss);
+ATF_TC_HEAD(getrusage_maxrss, tc)
+{
+       atf_tc_set_md_var(tc, "descr", "Test maxrss growing with getrusage(2)");
+}
+
+ATF_TC_BODY(getrusage_maxrss, tc)
+{
+       struct rusage ru;
+       long maxrss;
+       int i;
+
+       (void)memset(&ru, 0, sizeof(struct rusage));
+       ATF_REQUIRE(getrusage(RUSAGE_SELF, &ru) == 0);
+       maxrss = ru.ru_maxrss;
+
+#define CHUNK (1024 * 1024)
+       for (i = 0; i < 40; i++) {
+               void *p = malloc(CHUNK);
+               memset(p, 0, CHUNK);
+       }
+       ATF_REQUIRE(getrusage(RUSAGE_SELF, &ru) == 0);
+       ATF_REQUIRE(maxrss < ru.ru_maxrss);
+}
+
+ATF_TC(getrusage_msgsnd);
+ATF_TC_HEAD(getrusage_msgsnd, tc)
+{
+       atf_tc_set_md_var(tc, "descr", "Test send growing with getrusage(2)");
+}
+
+ATF_TC_BODY(getrusage_msgsnd, tc)
+{
+       struct rusage ru;
+       long msgsnd;
+       int s, i;
+       struct sockaddr_in sin;
+
+       ATF_REQUIRE(getrusage(RUSAGE_SELF, &ru) == 0);
+       msgsnd = ru.ru_msgsnd;
+
+       s = socket(AF_INET, SOCK_DGRAM, 0);
+       ATF_REQUIRE(s >= 0);
+       memset(&sin, 0, sizeof(sin));
+       sin.sin_family = AF_INET;
+       sin.sin_len = sizeof(sin);
+       sin.sin_addr.s_addr = ntohl(INADDR_LOOPBACK);
+       sin.sin_port = htons(3333);
+
+       for (i = 0; i < 10; i++)
+               ATF_REQUIRE(sendto(s, &sin, sizeof(sin), 0, (void *)&sin,
+                       (socklen_t)sizeof(sin)) != -1);
+
+       ATF_REQUIRE(getrusage(RUSAGE_SELF, &ru) == 0);
+       ATF_REQUIRE(msgsnd + 10 == ru.ru_msgsnd);
+       close(s);
+}
+
 ATF_TC(getrusage_utime_back);
 ATF_TC_HEAD(getrusage_utime_back, tc)
 {
@@ -192,6 +254,8 @@
 
        ATF_TP_ADD_TC(tp, getrusage_err);
        ATF_TP_ADD_TC(tp, getrusage_sig);
+       ATF_TP_ADD_TC(tp, getrusage_maxrss);
+       ATF_TP_ADD_TC(tp, getrusage_msgsnd);
        ATF_TP_ADD_TC(tp, getrusage_utime_back);
        ATF_TP_ADD_TC(tp, getrusage_utime_zero);
 



Home | Main Index | Thread Index | Old Index