From owner-svn-src-head@freebsd.org Tue Jun 6 03:40:47 2017 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 52055BEF670; Tue, 6 Jun 2017 03:40:47 +0000 (UTC) (envelope-from will@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 211DF7B438; Tue, 6 Jun 2017 03:40:47 +0000 (UTC) (envelope-from will@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v563ekaY068977; Tue, 6 Jun 2017 03:40:46 GMT (envelope-from will@FreeBSD.org) Received: (from will@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v563ektw068976; Tue, 6 Jun 2017 03:40:46 GMT (envelope-from will@FreeBSD.org) Message-Id: <201706060340.v563ektw068976@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: will set sender to will@FreeBSD.org using -f From: Will Andrews Date: Tue, 6 Jun 2017 03:40:46 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r319613 - head/lib/libc/tests/stdlib X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 06 Jun 2017 03:40:47 -0000 Author: will Date: Tue Jun 6 03:40:45 2017 New Revision: 319613 URL: https://svnweb.freebsd.org/changeset/base/319613 Log: tsearch_test: Test twalk & add some determinism. Modified: head/lib/libc/tests/stdlib/tsearch_test.c Modified: head/lib/libc/tests/stdlib/tsearch_test.c ============================================================================== --- head/lib/libc/tests/stdlib/tsearch_test.c Tue Jun 6 03:32:17 2017 (r319612) +++ head/lib/libc/tests/stdlib/tsearch_test.c Tue Jun 6 03:40:45 2017 (r319613) @@ -31,7 +31,11 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include +static int n_nodes = 0; +static int n_seen = 0; + /* Validates the integrity of an AVL tree. */ static inline unsigned int tnode_assert(const posix_tnode *n) @@ -57,6 +61,14 @@ compar(const void *a, const void *b) return *(int *)a - *(int *)b; } +static void +treewalk(const posix_tnode *node, VISIT v, int level) +{ + + if (v == postorder || v == leaf) + n_seen++; +} + ATF_TC_WITHOUT_HEAD(tsearch_test); ATF_TC_BODY(tsearch_test, tc) { @@ -83,11 +95,22 @@ ATF_TC_BODY(tsearch_test, tc) bool present[NKEYS] = {}; for (int i = 0; i < NKEYS * 10; ++i) { int key = nrand48(random_state) % NKEYS; - switch (nrand48(random_state) % 3) { + int sample = i; + + /* + * Ensure each case is tested at least 10 times, plus a + * random sampling. + */ + if ((sample % NKEYS) > 3) + sample = nrand48(random_state) % 3; + + switch (sample) { case 0: /* tdelete(). */ if (present[key]) { ATF_CHECK(tdelete(&key, &root, compar) != NULL); present[key] = false; + ATF_CHECK(n_nodes > 0); + n_nodes--; } else { ATF_CHECK_EQ(NULL, tdelete(&key, &root, compar)); @@ -109,11 +132,16 @@ ATF_TC_BODY(tsearch_test, tc) ATF_CHECK_EQ(&keys[key], *(int **)tsearch( &keys[key], &root, compar)); present[key] = true; + n_nodes++; } break; } tnode_assert(root); } + + /* Walk the tree. */ + twalk(root, treewalk); + ATF_CHECK_EQ(n_nodes, n_seen); /* Remove all entries from the tree. */ for (int key = 0; key < NKEYS; ++key)