From owner-svn-src-all@freebsd.org Fri May 10 07:46:15 2019 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id A5E2C159ADA9; Fri, 10 May 2019 07:46:15 +0000 (UTC) (envelope-from trasz@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4DC9894556; Fri, 10 May 2019 07:46:15 +0000 (UTC) (envelope-from trasz@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 mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 2425F12F8; Fri, 10 May 2019 07:46:15 +0000 (UTC) (envelope-from trasz@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x4A7kEVR003908; Fri, 10 May 2019 07:46:14 GMT (envelope-from trasz@FreeBSD.org) Received: (from trasz@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x4A7kEqb003905; Fri, 10 May 2019 07:46:14 GMT (envelope-from trasz@FreeBSD.org) Message-Id: <201905100746.x4A7kEqb003905@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: trasz set sender to trasz@FreeBSD.org using -f From: Edward Tomasz Napierala Date: Fri, 10 May 2019 07:46:14 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r347425 - head/tests/sys/sys X-SVN-Group: head X-SVN-Commit-Author: trasz X-SVN-Commit-Paths: head/tests/sys/sys X-SVN-Commit-Revision: 347425 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 4DC9894556 X-Spamd-Bar: -- Authentication-Results: mx1.freebsd.org X-Spamd-Result: default: False [-2.95 / 15.00]; local_wl_from(0.00)[FreeBSD.org]; NEURAL_HAM_MEDIUM(-0.99)[-0.993,0]; NEURAL_HAM_SHORT(-0.96)[-0.960,0]; ASN(0.00)[asn:11403, ipnet:2610:1c1:1::/48, country:US]; NEURAL_HAM_LONG(-1.00)[-1.000,0] X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 10 May 2019 07:46:15 -0000 Author: trasz Date: Fri May 10 07:46:14 2019 New Revision: 347425 URL: https://svnweb.freebsd.org/changeset/base/347425 Log: Add simple regression tests for tree(3). Those are ATF-ified versions of OpenBSD's regress/sys/sys/tree/. Reviewed by: ngie MFC after: 2 weeks Sponsored by: Klara Inc. Differential Revision: https://reviews.freebsd.org/D20186 Added: head/tests/sys/sys/rb_test.c (contents, props changed) head/tests/sys/sys/splay_test.c (contents, props changed) Modified: head/tests/sys/sys/Makefile Modified: head/tests/sys/sys/Makefile ============================================================================== --- head/tests/sys/sys/Makefile Fri May 10 07:28:58 2019 (r347424) +++ head/tests/sys/sys/Makefile Fri May 10 07:46:14 2019 (r347425) @@ -2,7 +2,7 @@ TESTSDIR= ${TESTSBASE}/sys/sys -ATF_TESTS_C= bitstring_test +ATF_TESTS_C= bitstring_test rb_test splay_test WARNS?= 5 Added: head/tests/sys/sys/rb_test.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/tests/sys/sys/rb_test.c Fri May 10 07:46:14 2019 (r347425) @@ -0,0 +1,108 @@ +/* $OpenBSD: rb-test.c,v 1.4 2008/04/13 00:22:17 djm Exp $ */ +/* + * Copyright 2002 Niels Provos + * 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. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + * + * $FreeBSD$ + */ +#include + +#include +#include + +#include + +struct node { + RB_ENTRY(node) node; + int key; +}; + +RB_HEAD(tree, node) root; + +static int +compare(struct node *a, struct node *b) +{ + if (a->key < b->key) return (-1); + else if (a->key > b->key) return (1); + return (0); +} + +RB_PROTOTYPE(tree, node, node, compare); + +RB_GENERATE(tree, node, node, compare); + +#define ITER 150 +#define MIN 5 +#define MAX 5000 + +ATF_TC_WITHOUT_HEAD(rb_test); +ATF_TC_BODY(rb_test, tc) +{ + struct node *tmp, *ins; + int i, max, min; + + RB_INIT(&root); + + for (i = 0; i < ITER; i++) { + tmp = malloc(sizeof(struct node)); + ATF_CHECK_MSG(tmp != NULL, "malloc failed"); + do { + tmp->key = arc4random_uniform(MAX-MIN); + tmp->key += MIN; + } while (RB_FIND(tree, &root, tmp) != NULL); + if (i == 0) + max = min = tmp->key; + else { + if (tmp->key > max) + max = tmp->key; + if (tmp->key < min) + min = tmp->key; + } + ATF_CHECK_EQ(NULL, RB_INSERT(tree, &root, tmp)); + } + + ins = RB_MIN(tree, &root); + ATF_CHECK_EQ(min, ins->key); + tmp = ins; + ins = RB_MAX(tree, &root); + ATF_CHECK_EQ(max, ins->key); + + ATF_CHECK_EQ(tmp, RB_REMOVE(tree, &root, tmp)); + + for (i = 0; i < ITER - 1; i++) { + tmp = RB_ROOT(&root); + ATF_CHECK_MSG(tmp != NULL, "RB_ROOT error"); + ATF_CHECK_EQ(tmp, RB_REMOVE(tree, &root, tmp)); + free(tmp); + } +} + +ATF_TP_ADD_TCS(tp) +{ + + ATF_TP_ADD_TC(tp, rb_test); + + return (atf_no_error()); +} Added: head/tests/sys/sys/splay_test.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/tests/sys/sys/splay_test.c Fri May 10 07:46:14 2019 (r347425) @@ -0,0 +1,108 @@ +/* $OpenBSD: splay-test.c,v 1.4 2008/04/13 00:22:17 djm Exp $ */ +/* + * Copyright 2002 Niels Provos + * 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. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. + * + * $FreeBSD$ + */ +#include + +#include +#include + +#include + +struct node { + SPLAY_ENTRY(node) node; + int key; +}; + +SPLAY_HEAD(tree, node) root; + +static int +compare(struct node *a, struct node *b) +{ + if (a->key < b->key) return (-1); + else if (a->key > b->key) return (1); + return (0); +} + +SPLAY_PROTOTYPE(tree, node, node, compare); + +SPLAY_GENERATE(tree, node, node, compare); + +#define ITER 150 +#define MIN 5 +#define MAX 5000 + +ATF_TC_WITHOUT_HEAD(splay_test); +ATF_TC_BODY(splay_test, tc) +{ + struct node *tmp, *ins; + int i, max, min; + + SPLAY_INIT(&root); + + for (i = 0; i < ITER; i++) { + tmp = malloc(sizeof(struct node)); + ATF_CHECK_MSG(tmp != NULL, "malloc failed"); + do { + tmp->key = arc4random_uniform(MAX-MIN); + tmp->key += MIN; + } while (SPLAY_FIND(tree, &root, tmp) != NULL); + if (i == 0) + max = min = tmp->key; + else { + if (tmp->key > max) + max = tmp->key; + if (tmp->key < min) + min = tmp->key; + } + ATF_CHECK_EQ(NULL, SPLAY_INSERT(tree, &root, tmp)); + } + + ins = SPLAY_MIN(tree, &root); + ATF_CHECK_EQ(min, ins->key); + tmp = ins; + ins = SPLAY_MAX(tree, &root); + ATF_CHECK_EQ(max, ins->key); + + ATF_CHECK_EQ(tmp, SPLAY_REMOVE(tree, &root, tmp)); + + for (i = 0; i < ITER - 1; i++) { + tmp = SPLAY_ROOT(&root); + ATF_CHECK_MSG(tmp != NULL, "SPLAY_ROOT error"); + ATF_CHECK_EQ(tmp, SPLAY_REMOVE(tree, &root, tmp)); + free(tmp); + } +} + +ATF_TP_ADD_TCS(tp) +{ + + ATF_TP_ADD_TC(tp, splay_test); + + return (atf_no_error()); +}