From owner-svn-src-head@freebsd.org Wed Jan 31 18:02:03 2018 Return-Path: Delivered-To: svn-src-head@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 8AEEDED9DB8; Wed, 31 Jan 2018 18:02:03 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 3933F71354; Wed, 31 Jan 2018 18:02:03 +0000 (UTC) (envelope-from jhb@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 34102294ED; Wed, 31 Jan 2018 18:02:03 +0000 (UTC) (envelope-from jhb@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w0VI23mZ039352; Wed, 31 Jan 2018 18:02:03 GMT (envelope-from jhb@FreeBSD.org) Received: (from jhb@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w0VI22ab039350; Wed, 31 Jan 2018 18:02:02 GMT (envelope-from jhb@FreeBSD.org) Message-Id: <201801311802.w0VI22ab039350@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: jhb set sender to jhb@FreeBSD.org using -f From: John Baldwin Date: Wed, 31 Jan 2018 18:02:02 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r328633 - head/lib/libc/tests/gen X-SVN-Group: head X-SVN-Commit-Author: jhb X-SVN-Commit-Paths: head/lib/libc/tests/gen X-SVN-Commit-Revision: 328633 X-SVN-Commit-Repository: base 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.25 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: Wed, 31 Jan 2018 18:02:03 -0000 Author: jhb Date: Wed Jan 31 18:02:02 2018 New Revision: 328633 URL: https://svnweb.freebsd.org/changeset/base/328633 Log: Add a new set of simple tests for makecontext(). In contrast to the existing NetBSD setcontext_link test, these tests verify that passing from 1 to 6 arguments through to the callback function work correctly which can be useful for testing ABIs which split arguments between registers and the stack. Sponsored by: DARPA / AFRL Added: head/lib/libc/tests/gen/makecontext_test.c (contents, props changed) Modified: head/lib/libc/tests/gen/Makefile Modified: head/lib/libc/tests/gen/Makefile ============================================================================== --- head/lib/libc/tests/gen/Makefile Wed Jan 31 18:00:23 2018 (r328632) +++ head/lib/libc/tests/gen/Makefile Wed Jan 31 18:02:02 2018 (r328633) @@ -12,6 +12,7 @@ ATF_TESTS_C+= fpclassify2_test ATF_TESTS_C+= ftw_test ATF_TESTS_C+= getmntinfo_test ATF_TESTS_C+= glob2_test +ATF_TESTS_C+= makecontext_test ATF_TESTS_C+= popen_test ATF_TESTS_C+= posix_spawn_test ATF_TESTS_C+= realpath2_test Added: head/lib/libc/tests/gen/makecontext_test.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/lib/libc/tests/gen/makecontext_test.c Wed Jan 31 18:02:02 2018 (r328633) @@ -0,0 +1,189 @@ +/*- + * SPDX-License-Identifier: BSD-2-Clause-FreeBSD + * + * Copyright (c) 2018 John H. Baldwin + * 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 AUTHOR 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 AUTHOR 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 +__FBSDID("$FreeBSD$"); + +#include +#include + +static char uc_stack[16 * 1024]; + +static void +check_1(int arg1) +{ + + ATF_REQUIRE_EQ(arg1, 1); +} + +ATF_TC_WITHOUT_HEAD(makecontext_arg1); +ATF_TC_BODY(makecontext_arg1, tc) +{ + ucontext_t ctx[2]; + + ATF_REQUIRE_EQ(getcontext(&ctx[1]), 0); + ctx[1].uc_stack.ss_sp = uc_stack; + ctx[1].uc_stack.ss_size = sizeof(uc_stack); + ctx[1].uc_link = &ctx[0]; + makecontext(&ctx[1], (void (*)(void))check_1, 1, 1); + + ATF_REQUIRE_EQ(swapcontext(&ctx[0], &ctx[1]), 0); +} + +static void +check_2(int arg1, int arg2) +{ + + ATF_REQUIRE_EQ(arg1, 1); + ATF_REQUIRE_EQ(arg2, 2); +} + +ATF_TC_WITHOUT_HEAD(makecontext_arg2); +ATF_TC_BODY(makecontext_arg2, tc) +{ + ucontext_t ctx[2]; + + ATF_REQUIRE_EQ(getcontext(&ctx[1]), 0); + ctx[1].uc_stack.ss_sp = uc_stack; + ctx[1].uc_stack.ss_size = sizeof(uc_stack); + ctx[1].uc_link = &ctx[0]; + makecontext(&ctx[1], (void (*)(void))check_2, 2, 1, 2); + + ATF_REQUIRE_EQ(swapcontext(&ctx[0], &ctx[1]), 0); +} + +static void +check_3(int arg1, int arg2, int arg3) +{ + + ATF_REQUIRE_EQ(arg1, 1); + ATF_REQUIRE_EQ(arg2, 2); + ATF_REQUIRE_EQ(arg3, 3); +} + +ATF_TC_WITHOUT_HEAD(makecontext_arg3); +ATF_TC_BODY(makecontext_arg3, tc) +{ + ucontext_t ctx[2]; + + ATF_REQUIRE_EQ(getcontext(&ctx[1]), 0); + ctx[1].uc_stack.ss_sp = uc_stack; + ctx[1].uc_stack.ss_size = sizeof(uc_stack); + ctx[1].uc_link = &ctx[0]; + makecontext(&ctx[1], (void (*)(void))check_3, 3, 1, 2, 3); + + ATF_REQUIRE_EQ(swapcontext(&ctx[0], &ctx[1]), 0); +} + +static void +check_4(int arg1, int arg2, int arg3, int arg4) +{ + + ATF_REQUIRE_EQ(arg1, 1); + ATF_REQUIRE_EQ(arg2, 2); + ATF_REQUIRE_EQ(arg3, 3); + ATF_REQUIRE_EQ(arg4, 4); +} + +ATF_TC_WITHOUT_HEAD(makecontext_arg4); +ATF_TC_BODY(makecontext_arg4, tc) +{ + ucontext_t ctx[2]; + + ATF_REQUIRE_EQ(getcontext(&ctx[1]), 0); + ctx[1].uc_stack.ss_sp = uc_stack; + ctx[1].uc_stack.ss_size = sizeof(uc_stack); + ctx[1].uc_link = &ctx[0]; + makecontext(&ctx[1], (void (*)(void))check_4, 4, 1, 2, 3, 4); + + ATF_REQUIRE_EQ(swapcontext(&ctx[0], &ctx[1]), 0); +} + +static void +check_5(int arg1, int arg2, int arg3, int arg4, int arg5) +{ + + ATF_REQUIRE_EQ(arg1, 1); + ATF_REQUIRE_EQ(arg2, 2); + ATF_REQUIRE_EQ(arg3, 3); + ATF_REQUIRE_EQ(arg4, 4); + ATF_REQUIRE_EQ(arg5, 5); +} + +ATF_TC_WITHOUT_HEAD(makecontext_arg5); +ATF_TC_BODY(makecontext_arg5, tc) +{ + ucontext_t ctx[2]; + + ATF_REQUIRE_EQ(getcontext(&ctx[1]), 0); + ctx[1].uc_stack.ss_sp = uc_stack; + ctx[1].uc_stack.ss_size = sizeof(uc_stack); + ctx[1].uc_link = &ctx[0]; + makecontext(&ctx[1], (void (*)(void))check_5, 5, 1, 2, 3, 4, 5); + + ATF_REQUIRE_EQ(swapcontext(&ctx[0], &ctx[1]), 0); +} + +static void +check_6(int arg1, int arg2, int arg3, int arg4, int arg5, int arg6) +{ + + ATF_REQUIRE_EQ(arg1, 1); + ATF_REQUIRE_EQ(arg2, 2); + ATF_REQUIRE_EQ(arg3, 3); + ATF_REQUIRE_EQ(arg4, 4); + ATF_REQUIRE_EQ(arg5, 5); + ATF_REQUIRE_EQ(arg6, 6); +} + +ATF_TC_WITHOUT_HEAD(makecontext_arg6); +ATF_TC_BODY(makecontext_arg6, tc) +{ + ucontext_t ctx[2]; + + ATF_REQUIRE_EQ(getcontext(&ctx[1]), 0); + ctx[1].uc_stack.ss_sp = uc_stack; + ctx[1].uc_stack.ss_size = sizeof(uc_stack); + ctx[1].uc_link = &ctx[0]; + makecontext(&ctx[1], (void (*)(void))check_6, 6, 1, 2, 3, 4, 5, 6); + + ATF_REQUIRE_EQ(swapcontext(&ctx[0], &ctx[1]), 0); +} + +ATF_TP_ADD_TCS(tp) +{ + + ATF_TP_ADD_TC(tp, makecontext_arg1); + ATF_TP_ADD_TC(tp, makecontext_arg2); + ATF_TP_ADD_TC(tp, makecontext_arg3); + ATF_TP_ADD_TC(tp, makecontext_arg4); + ATF_TP_ADD_TC(tp, makecontext_arg5); + ATF_TP_ADD_TC(tp, makecontext_arg6); + + return (atf_no_error()); +}