diff --git a/contrib/netbsd-tests/dev/cgd/t_cgd_3des.c b/contrib/netbsd-tests/dev/cgd/t_cgd_3des.c index 91e81f45ec5e..a79ac740d45d 100644 --- a/contrib/netbsd-tests/dev/cgd/t_cgd_3des.c +++ b/contrib/netbsd-tests/dev/cgd/t_cgd_3des.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_cgd_3des.c,v 1.1 2016/11/11 07:39:58 alnsn Exp $ */ +/* $NetBSD: t_cgd_3des.c,v 1.2 2017/01/13 21:30:39 christos Exp $ */ /*- * Copyright (c) 2016 The NetBSD Foundation, Inc. * All rights reserved. @@ -48,7 +48,7 @@ #include #include -#include "../../h_macros.h" +#include "h_macros.h" #define SECSIZE 512 diff --git a/contrib/netbsd-tests/dev/cgd/t_cgd_aes.c b/contrib/netbsd-tests/dev/cgd/t_cgd_aes.c index 9416333a2d71..edda1eb71aa1 100644 --- a/contrib/netbsd-tests/dev/cgd/t_cgd_aes.c +++ b/contrib/netbsd-tests/dev/cgd/t_cgd_aes.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_cgd_aes.c,v 1.5 2016/12/11 00:23:44 alnsn Exp $ */ +/* $NetBSD: t_cgd_aes.c,v 1.6 2017/01/13 21:30:39 christos Exp $ */ /*- * Copyright (c) 2016 The NetBSD Foundation, Inc. * Copyright (c) 2007 The Institute of Electrical and Electronics Engineers, Inc @@ -49,7 +49,7 @@ #include #include -#include "../../h_macros.h" +#include "h_macros.h" #define SECSIZE 512 diff --git a/contrib/netbsd-tests/dev/cgd/t_cgd_blowfish.c b/contrib/netbsd-tests/dev/cgd/t_cgd_blowfish.c index 958ebaccf6ad..93aa834aaa41 100644 --- a/contrib/netbsd-tests/dev/cgd/t_cgd_blowfish.c +++ b/contrib/netbsd-tests/dev/cgd/t_cgd_blowfish.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_cgd_blowfish.c,v 1.1 2016/11/10 23:44:36 alnsn Exp $ */ +/* $NetBSD: t_cgd_blowfish.c,v 1.2 2017/01/13 21:30:39 christos Exp $ */ /*- * Copyright (c) 2016 The NetBSD Foundation, Inc. * All rights reserved. @@ -48,7 +48,7 @@ #include #include -#include "../../h_macros.h" +#include "h_macros.h" #define SECSIZE 512 diff --git a/contrib/netbsd-tests/dev/clock_subr/clock_subr_test_data_gen.sh b/contrib/netbsd-tests/dev/clock_subr/clock_subr_test_data_gen.sh new file mode 100755 index 000000000000..2da21a8da1bd --- /dev/null +++ b/contrib/netbsd-tests/dev/clock_subr/clock_subr_test_data_gen.sh @@ -0,0 +1,25 @@ +#!/bin/ksh + +export TZ=Etc/Universal + +datesub() { + gdate "$@" '+ FILL(%_11s,%_4Y,%_m,%_d,%w,%_H,%_M,%_S), // %a %b %e %H:%M:%S %Z %Y' +} + +( + datesub -d '1970/01/01 00:00:00' + datesub -d '1981/04/12 12:00:03' + datesub -d '2011/07/21 09:57:00' + datesub -d @2147483647 + datesub -d @2147483648 + datesub -d '2063/04/05 00:00:00' + for year in `seq 1970 1 2030`; do + datesub -d "${year}/01/01 00:00:00" + datesub -d "${year}/07/01 00:00:00" + done + for year in `seq 2000 25 2600`; do + datesub -d "$((${year} - 1))/12/31 23:59:59" + datesub -d "$((${year} + 0))/01/01 00:00:00" + datesub -d "$((${year} + 1))/01/01 00:00:00" + done +)|sort -u diff --git a/contrib/netbsd-tests/dev/clock_subr/t_clock_subr.c b/contrib/netbsd-tests/dev/clock_subr/t_clock_subr.c new file mode 100644 index 000000000000..bb03c688bf79 --- /dev/null +++ b/contrib/netbsd-tests/dev/clock_subr/t_clock_subr.c @@ -0,0 +1,309 @@ +/* $NetBSD: t_clock_subr.c,v 1.3 2017/01/13 21:30:39 christos Exp $ */ + +/* + * Copyright (c) 2016 Jonathan A. Kollasch + * 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 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 HOLDER 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 +__COPYRIGHT("@(#) Copyright (c) 2016\ + Jonathan A. Kollasch. All rights reserved."); +__RCSID("$NetBSD: t_clock_subr.c,v 1.3 2017/01/13 21:30:39 christos Exp $"); + +#include +#include + +#include +#include +#include + +#include + +#include "h_macros.h" + +#define FILL(ti,ye,mo,da,wd,ho,mi,se) \ +{ .time = (ti), .clock = { .dt_year = (ye), .dt_mon = (mo), .dt_day = (da), \ + .dt_wday = (wd), .dt_hour = (ho), .dt_min = (mi), .dt_sec = (se), } } + +static struct clock_test { + time_t time; + struct clock_ymdhms clock; +} const clock_tests[] = { + FILL( 0,1970, 1, 1,4, 0, 0, 0), // Thu Jan 1 00:00:00 UTC 1970 + FILL( 15638400,1970, 7, 1,3, 0, 0, 0), // Wed Jul 1 00:00:00 UTC 1970 + FILL( 31536000,1971, 1, 1,5, 0, 0, 0), // Fri Jan 1 00:00:00 UTC 1971 + FILL( 47174400,1971, 7, 1,4, 0, 0, 0), // Thu Jul 1 00:00:00 UTC 1971 + FILL( 63072000,1972, 1, 1,6, 0, 0, 0), // Sat Jan 1 00:00:00 UTC 1972 + FILL( 78796800,1972, 7, 1,6, 0, 0, 0), // Sat Jul 1 00:00:00 UTC 1972 + FILL( 94694400,1973, 1, 1,1, 0, 0, 0), // Mon Jan 1 00:00:00 UTC 1973 + FILL( 110332800,1973, 7, 1,0, 0, 0, 0), // Sun Jul 1 00:00:00 UTC 1973 + FILL( 126230400,1974, 1, 1,2, 0, 0, 0), // Tue Jan 1 00:00:00 UTC 1974 + FILL( 141868800,1974, 7, 1,1, 0, 0, 0), // Mon Jul 1 00:00:00 UTC 1974 + FILL( 157766400,1975, 1, 1,3, 0, 0, 0), // Wed Jan 1 00:00:00 UTC 1975 + FILL( 173404800,1975, 7, 1,2, 0, 0, 0), // Tue Jul 1 00:00:00 UTC 1975 + FILL( 189302400,1976, 1, 1,4, 0, 0, 0), // Thu Jan 1 00:00:00 UTC 1976 + FILL( 205027200,1976, 7, 1,4, 0, 0, 0), // Thu Jul 1 00:00:00 UTC 1976 + FILL( 220924800,1977, 1, 1,6, 0, 0, 0), // Sat Jan 1 00:00:00 UTC 1977 + FILL( 236563200,1977, 7, 1,5, 0, 0, 0), // Fri Jul 1 00:00:00 UTC 1977 + FILL( 252460800,1978, 1, 1,0, 0, 0, 0), // Sun Jan 1 00:00:00 UTC 1978 + FILL( 268099200,1978, 7, 1,6, 0, 0, 0), // Sat Jul 1 00:00:00 UTC 1978 + FILL( 283996800,1979, 1, 1,1, 0, 0, 0), // Mon Jan 1 00:00:00 UTC 1979 + FILL( 299635200,1979, 7, 1,0, 0, 0, 0), // Sun Jul 1 00:00:00 UTC 1979 + FILL( 315532800,1980, 1, 1,2, 0, 0, 0), // Tue Jan 1 00:00:00 UTC 1980 + FILL( 331257600,1980, 7, 1,2, 0, 0, 0), // Tue Jul 1 00:00:00 UTC 1980 + FILL( 347155200,1981, 1, 1,4, 0, 0, 0), // Thu Jan 1 00:00:00 UTC 1981 + FILL( 355924803,1981, 4,12,0,12, 0, 3), // Sun Apr 12 12:00:03 UTC 1981 + FILL( 362793600,1981, 7, 1,3, 0, 0, 0), // Wed Jul 1 00:00:00 UTC 1981 + FILL( 378691200,1982, 1, 1,5, 0, 0, 0), // Fri Jan 1 00:00:00 UTC 1982 + FILL( 394329600,1982, 7, 1,4, 0, 0, 0), // Thu Jul 1 00:00:00 UTC 1982 + FILL( 410227200,1983, 1, 1,6, 0, 0, 0), // Sat Jan 1 00:00:00 UTC 1983 + FILL( 425865600,1983, 7, 1,5, 0, 0, 0), // Fri Jul 1 00:00:00 UTC 1983 + FILL( 441763200,1984, 1, 1,0, 0, 0, 0), // Sun Jan 1 00:00:00 UTC 1984 + FILL( 457488000,1984, 7, 1,0, 0, 0, 0), // Sun Jul 1 00:00:00 UTC 1984 + FILL( 473385600,1985, 1, 1,2, 0, 0, 0), // Tue Jan 1 00:00:00 UTC 1985 + FILL( 489024000,1985, 7, 1,1, 0, 0, 0), // Mon Jul 1 00:00:00 UTC 1985 + FILL( 504921600,1986, 1, 1,3, 0, 0, 0), // Wed Jan 1 00:00:00 UTC 1986 + FILL( 520560000,1986, 7, 1,2, 0, 0, 0), // Tue Jul 1 00:00:00 UTC 1986 + FILL( 536457600,1987, 1, 1,4, 0, 0, 0), // Thu Jan 1 00:00:00 UTC 1987 + FILL( 552096000,1987, 7, 1,3, 0, 0, 0), // Wed Jul 1 00:00:00 UTC 1987 + FILL( 567993600,1988, 1, 1,5, 0, 0, 0), // Fri Jan 1 00:00:00 UTC 1988 + FILL( 583718400,1988, 7, 1,5, 0, 0, 0), // Fri Jul 1 00:00:00 UTC 1988 + FILL( 599616000,1989, 1, 1,0, 0, 0, 0), // Sun Jan 1 00:00:00 UTC 1989 + FILL( 615254400,1989, 7, 1,6, 0, 0, 0), // Sat Jul 1 00:00:00 UTC 1989 + FILL( 631152000,1990, 1, 1,1, 0, 0, 0), // Mon Jan 1 00:00:00 UTC 1990 + FILL( 646790400,1990, 7, 1,0, 0, 0, 0), // Sun Jul 1 00:00:00 UTC 1990 + FILL( 662688000,1991, 1, 1,2, 0, 0, 0), // Tue Jan 1 00:00:00 UTC 1991 + FILL( 678326400,1991, 7, 1,1, 0, 0, 0), // Mon Jul 1 00:00:00 UTC 1991 + FILL( 694224000,1992, 1, 1,3, 0, 0, 0), // Wed Jan 1 00:00:00 UTC 1992 + FILL( 709948800,1992, 7, 1,3, 0, 0, 0), // Wed Jul 1 00:00:00 UTC 1992 + FILL( 725846400,1993, 1, 1,5, 0, 0, 0), // Fri Jan 1 00:00:00 UTC 1993 + FILL( 741484800,1993, 7, 1,4, 0, 0, 0), // Thu Jul 1 00:00:00 UTC 1993 + FILL( 757382400,1994, 1, 1,6, 0, 0, 0), // Sat Jan 1 00:00:00 UTC 1994 + FILL( 773020800,1994, 7, 1,5, 0, 0, 0), // Fri Jul 1 00:00:00 UTC 1994 + FILL( 788918400,1995, 1, 1,0, 0, 0, 0), // Sun Jan 1 00:00:00 UTC 1995 + FILL( 804556800,1995, 7, 1,6, 0, 0, 0), // Sat Jul 1 00:00:00 UTC 1995 + FILL( 820454400,1996, 1, 1,1, 0, 0, 0), // Mon Jan 1 00:00:00 UTC 1996 + FILL( 836179200,1996, 7, 1,1, 0, 0, 0), // Mon Jul 1 00:00:00 UTC 1996 + FILL( 852076800,1997, 1, 1,3, 0, 0, 0), // Wed Jan 1 00:00:00 UTC 1997 + FILL( 867715200,1997, 7, 1,2, 0, 0, 0), // Tue Jul 1 00:00:00 UTC 1997 + FILL( 883612800,1998, 1, 1,4, 0, 0, 0), // Thu Jan 1 00:00:00 UTC 1998 + FILL( 899251200,1998, 7, 1,3, 0, 0, 0), // Wed Jul 1 00:00:00 UTC 1998 + FILL( 915148800,1999, 1, 1,5, 0, 0, 0), // Fri Jan 1 00:00:00 UTC 1999 + FILL( 930787200,1999, 7, 1,4, 0, 0, 0), // Thu Jul 1 00:00:00 UTC 1999 + FILL( 946684799,1999,12,31,5,23,59,59), // Fri Dec 31 23:59:59 UTC 1999 + FILL( 946684800,2000, 1, 1,6, 0, 0, 0), // Sat Jan 1 00:00:00 UTC 2000 + FILL( 962409600,2000, 7, 1,6, 0, 0, 0), // Sat Jul 1 00:00:00 UTC 2000 + FILL( 978307200,2001, 1, 1,1, 0, 0, 0), // Mon Jan 1 00:00:00 UTC 2001 + FILL( 993945600,2001, 7, 1,0, 0, 0, 0), // Sun Jul 1 00:00:00 UTC 2001 + FILL( 1009843200,2002, 1, 1,2, 0, 0, 0), // Tue Jan 1 00:00:00 UTC 2002 + FILL( 1025481600,2002, 7, 1,1, 0, 0, 0), // Mon Jul 1 00:00:00 UTC 2002 + FILL( 1041379200,2003, 1, 1,3, 0, 0, 0), // Wed Jan 1 00:00:00 UTC 2003 + FILL( 1057017600,2003, 7, 1,2, 0, 0, 0), // Tue Jul 1 00:00:00 UTC 2003 + FILL( 1072915200,2004, 1, 1,4, 0, 0, 0), // Thu Jan 1 00:00:00 UTC 2004 + FILL( 1088640000,2004, 7, 1,4, 0, 0, 0), // Thu Jul 1 00:00:00 UTC 2004 + FILL( 1104537600,2005, 1, 1,6, 0, 0, 0), // Sat Jan 1 00:00:00 UTC 2005 + FILL( 1120176000,2005, 7, 1,5, 0, 0, 0), // Fri Jul 1 00:00:00 UTC 2005 + FILL( 1136073600,2006, 1, 1,0, 0, 0, 0), // Sun Jan 1 00:00:00 UTC 2006 + FILL( 1151712000,2006, 7, 1,6, 0, 0, 0), // Sat Jul 1 00:00:00 UTC 2006 + FILL( 1167609600,2007, 1, 1,1, 0, 0, 0), // Mon Jan 1 00:00:00 UTC 2007 + FILL( 1183248000,2007, 7, 1,0, 0, 0, 0), // Sun Jul 1 00:00:00 UTC 2007 + FILL( 1199145600,2008, 1, 1,2, 0, 0, 0), // Tue Jan 1 00:00:00 UTC 2008 + FILL( 1214870400,2008, 7, 1,2, 0, 0, 0), // Tue Jul 1 00:00:00 UTC 2008 + FILL( 1230768000,2009, 1, 1,4, 0, 0, 0), // Thu Jan 1 00:00:00 UTC 2009 + FILL( 1246406400,2009, 7, 1,3, 0, 0, 0), // Wed Jul 1 00:00:00 UTC 2009 + FILL( 1262304000,2010, 1, 1,5, 0, 0, 0), // Fri Jan 1 00:00:00 UTC 2010 + FILL( 1277942400,2010, 7, 1,4, 0, 0, 0), // Thu Jul 1 00:00:00 UTC 2010 + FILL( 1293840000,2011, 1, 1,6, 0, 0, 0), // Sat Jan 1 00:00:00 UTC 2011 + FILL( 1309478400,2011, 7, 1,5, 0, 0, 0), // Fri Jul 1 00:00:00 UTC 2011 + FILL( 1311242220,2011, 7,21,4, 9,57, 0), // Thu Jul 21 09:57:00 UTC 2011 + FILL( 1325376000,2012, 1, 1,0, 0, 0, 0), // Sun Jan 1 00:00:00 UTC 2012 + FILL( 1341100800,2012, 7, 1,0, 0, 0, 0), // Sun Jul 1 00:00:00 UTC 2012 + FILL( 1356998400,2013, 1, 1,2, 0, 0, 0), // Tue Jan 1 00:00:00 UTC 2013 + FILL( 1372636800,2013, 7, 1,1, 0, 0, 0), // Mon Jul 1 00:00:00 UTC 2013 + FILL( 1388534400,2014, 1, 1,3, 0, 0, 0), // Wed Jan 1 00:00:00 UTC 2014 + FILL( 1404172800,2014, 7, 1,2, 0, 0, 0), // Tue Jul 1 00:00:00 UTC 2014 + FILL( 1420070400,2015, 1, 1,4, 0, 0, 0), // Thu Jan 1 00:00:00 UTC 2015 + FILL( 1435708800,2015, 7, 1,3, 0, 0, 0), // Wed Jul 1 00:00:00 UTC 2015 + FILL( 1451606400,2016, 1, 1,5, 0, 0, 0), // Fri Jan 1 00:00:00 UTC 2016 + FILL( 1467331200,2016, 7, 1,5, 0, 0, 0), // Fri Jul 1 00:00:00 UTC 2016 + FILL( 1483228800,2017, 1, 1,0, 0, 0, 0), // Sun Jan 1 00:00:00 UTC 2017 + FILL( 1498867200,2017, 7, 1,6, 0, 0, 0), // Sat Jul 1 00:00:00 UTC 2017 + FILL( 1514764800,2018, 1, 1,1, 0, 0, 0), // Mon Jan 1 00:00:00 UTC 2018 + FILL( 1530403200,2018, 7, 1,0, 0, 0, 0), // Sun Jul 1 00:00:00 UTC 2018 + FILL( 1546300800,2019, 1, 1,2, 0, 0, 0), // Tue Jan 1 00:00:00 UTC 2019 + FILL( 1561939200,2019, 7, 1,1, 0, 0, 0), // Mon Jul 1 00:00:00 UTC 2019 + FILL( 1577836800,2020, 1, 1,3, 0, 0, 0), // Wed Jan 1 00:00:00 UTC 2020 + FILL( 1593561600,2020, 7, 1,3, 0, 0, 0), // Wed Jul 1 00:00:00 UTC 2020 + FILL( 1609459200,2021, 1, 1,5, 0, 0, 0), // Fri Jan 1 00:00:00 UTC 2021 + FILL( 1625097600,2021, 7, 1,4, 0, 0, 0), // Thu Jul 1 00:00:00 UTC 2021 + FILL( 1640995200,2022, 1, 1,6, 0, 0, 0), // Sat Jan 1 00:00:00 UTC 2022 + FILL( 1656633600,2022, 7, 1,5, 0, 0, 0), // Fri Jul 1 00:00:00 UTC 2022 + FILL( 1672531200,2023, 1, 1,0, 0, 0, 0), // Sun Jan 1 00:00:00 UTC 2023 + FILL( 1688169600,2023, 7, 1,6, 0, 0, 0), // Sat Jul 1 00:00:00 UTC 2023 + FILL( 1704067200,2024, 1, 1,1, 0, 0, 0), // Mon Jan 1 00:00:00 UTC 2024 + FILL( 1719792000,2024, 7, 1,1, 0, 0, 0), // Mon Jul 1 00:00:00 UTC 2024 + FILL( 1735689599,2024,12,31,2,23,59,59), // Tue Dec 31 23:59:59 UTC 2024 + FILL( 1735689600,2025, 1, 1,3, 0, 0, 0), // Wed Jan 1 00:00:00 UTC 2025 + FILL( 1751328000,2025, 7, 1,2, 0, 0, 0), // Tue Jul 1 00:00:00 UTC 2025 + FILL( 1767225600,2026, 1, 1,4, 0, 0, 0), // Thu Jan 1 00:00:00 UTC 2026 + FILL( 1782864000,2026, 7, 1,3, 0, 0, 0), // Wed Jul 1 00:00:00 UTC 2026 + FILL( 1798761600,2027, 1, 1,5, 0, 0, 0), // Fri Jan 1 00:00:00 UTC 2027 + FILL( 1814400000,2027, 7, 1,4, 0, 0, 0), // Thu Jul 1 00:00:00 UTC 2027 + FILL( 1830297600,2028, 1, 1,6, 0, 0, 0), // Sat Jan 1 00:00:00 UTC 2028 + FILL( 1846022400,2028, 7, 1,6, 0, 0, 0), // Sat Jul 1 00:00:00 UTC 2028 + FILL( 1861920000,2029, 1, 1,1, 0, 0, 0), // Mon Jan 1 00:00:00 UTC 2029 + FILL( 1877558400,2029, 7, 1,0, 0, 0, 0), // Sun Jul 1 00:00:00 UTC 2029 + FILL( 1893456000,2030, 1, 1,2, 0, 0, 0), // Tue Jan 1 00:00:00 UTC 2030 + FILL( 1909094400,2030, 7, 1,1, 0, 0, 0), // Mon Jul 1 00:00:00 UTC 2030 + FILL( 2147483647,2038, 1,19,2, 3,14, 7), // Tue Jan 19 03:14:07 UTC 2038 + FILL( 2147483648,2038, 1,19,2, 3,14, 8), // Tue Jan 19 03:14:08 UTC 2038 + FILL( 2524607999,2049,12,31,5,23,59,59), // Fri Dec 31 23:59:59 UTC 2049 + FILL( 2524608000,2050, 1, 1,6, 0, 0, 0), // Sat Jan 1 00:00:00 UTC 2050 + FILL( 2556144000,2051, 1, 1,0, 0, 0, 0), // Sun Jan 1 00:00:00 UTC 2051 + FILL( 2942956800,2063, 4, 5,4, 0, 0, 0), // Thu Apr 5 00:00:00 UTC 2063 + FILL( 3313526399,2074,12,31,1,23,59,59), // Mon Dec 31 23:59:59 UTC 2074 + FILL( 3313526400,2075, 1, 1,2, 0, 0, 0), // Tue Jan 1 00:00:00 UTC 2075 + FILL( 3345062400,2076, 1, 1,3, 0, 0, 0), // Wed Jan 1 00:00:00 UTC 2076 + FILL( 4102444799,2099,12,31,4,23,59,59), // Thu Dec 31 23:59:59 UTC 2099 + FILL( 4102444800,2100, 1, 1,5, 0, 0, 0), // Fri Jan 1 00:00:00 UTC 2100 + FILL( 4133980800,2101, 1, 1,6, 0, 0, 0), // Sat Jan 1 00:00:00 UTC 2101 + FILL( 4891363199,2124,12,31,0,23,59,59), // Sun Dec 31 23:59:59 UTC 2124 + FILL( 4891363200,2125, 1, 1,1, 0, 0, 0), // Mon Jan 1 00:00:00 UTC 2125 + FILL( 4922899200,2126, 1, 1,2, 0, 0, 0), // Tue Jan 1 00:00:00 UTC 2126 + FILL( 5680281599,2149,12,31,3,23,59,59), // Wed Dec 31 23:59:59 UTC 2149 + FILL( 5680281600,2150, 1, 1,4, 0, 0, 0), // Thu Jan 1 00:00:00 UTC 2150 + FILL( 5711817600,2151, 1, 1,5, 0, 0, 0), // Fri Jan 1 00:00:00 UTC 2151 + FILL( 6469199999,2174,12,31,6,23,59,59), // Sat Dec 31 23:59:59 UTC 2174 + FILL( 6469200000,2175, 1, 1,0, 0, 0, 0), // Sun Jan 1 00:00:00 UTC 2175 + FILL( 6500736000,2176, 1, 1,1, 0, 0, 0), // Mon Jan 1 00:00:00 UTC 2176 + FILL( 7258118399,2199,12,31,2,23,59,59), // Tue Dec 31 23:59:59 UTC 2199 + FILL( 7258118400,2200, 1, 1,3, 0, 0, 0), // Wed Jan 1 00:00:00 UTC 2200 + FILL( 7289654400,2201, 1, 1,4, 0, 0, 0), // Thu Jan 1 00:00:00 UTC 2201 + FILL( 8047036799,2224,12,31,5,23,59,59), // Fri Dec 31 23:59:59 UTC 2224 + FILL( 8047036800,2225, 1, 1,6, 0, 0, 0), // Sat Jan 1 00:00:00 UTC 2225 + FILL( 8078572800,2226, 1, 1,0, 0, 0, 0), // Sun Jan 1 00:00:00 UTC 2226 + FILL( 8835955199,2249,12,31,1,23,59,59), // Mon Dec 31 23:59:59 UTC 2249 + FILL( 8835955200,2250, 1, 1,2, 0, 0, 0), // Tue Jan 1 00:00:00 UTC 2250 + FILL( 8867491200,2251, 1, 1,3, 0, 0, 0), // Wed Jan 1 00:00:00 UTC 2251 + FILL( 9624873599,2274,12,31,4,23,59,59), // Thu Dec 31 23:59:59 UTC 2274 + FILL( 9624873600,2275, 1, 1,5, 0, 0, 0), // Fri Jan 1 00:00:00 UTC 2275 + FILL( 9656409600,2276, 1, 1,6, 0, 0, 0), // Sat Jan 1 00:00:00 UTC 2276 + FILL(10413791999,2299,12,31,0,23,59,59), // Sun Dec 31 23:59:59 UTC 2299 + FILL(10413792000,2300, 1, 1,1, 0, 0, 0), // Mon Jan 1 00:00:00 UTC 2300 + FILL(10445328000,2301, 1, 1,2, 0, 0, 0), // Tue Jan 1 00:00:00 UTC 2301 + FILL(11202710399,2324,12,31,3,23,59,59), // Wed Dec 31 23:59:59 UTC 2324 + FILL(11202710400,2325, 1, 1,4, 0, 0, 0), // Thu Jan 1 00:00:00 UTC 2325 + FILL(11234246400,2326, 1, 1,5, 0, 0, 0), // Fri Jan 1 00:00:00 UTC 2326 + FILL(11991628799,2349,12,31,6,23,59,59), // Sat Dec 31 23:59:59 UTC 2349 + FILL(11991628800,2350, 1, 1,0, 0, 0, 0), // Sun Jan 1 00:00:00 UTC 2350 + FILL(12023164800,2351, 1, 1,1, 0, 0, 0), // Mon Jan 1 00:00:00 UTC 2351 + FILL(12780547199,2374,12,31,2,23,59,59), // Tue Dec 31 23:59:59 UTC 2374 + FILL(12780547200,2375, 1, 1,3, 0, 0, 0), // Wed Jan 1 00:00:00 UTC 2375 + FILL(12812083200,2376, 1, 1,4, 0, 0, 0), // Thu Jan 1 00:00:00 UTC 2376 + FILL(13569465599,2399,12,31,5,23,59,59), // Fri Dec 31 23:59:59 UTC 2399 + FILL(13569465600,2400, 1, 1,6, 0, 0, 0), // Sat Jan 1 00:00:00 UTC 2400 + FILL(13601088000,2401, 1, 1,1, 0, 0, 0), // Mon Jan 1 00:00:00 UTC 2401 + FILL(14358470399,2424,12,31,2,23,59,59), // Tue Dec 31 23:59:59 UTC 2424 + FILL(14358470400,2425, 1, 1,3, 0, 0, 0), // Wed Jan 1 00:00:00 UTC 2425 + FILL(14390006400,2426, 1, 1,4, 0, 0, 0), // Thu Jan 1 00:00:00 UTC 2426 + FILL(15147388799,2449,12,31,5,23,59,59), // Fri Dec 31 23:59:59 UTC 2449 + FILL(15147388800,2450, 1, 1,6, 0, 0, 0), // Sat Jan 1 00:00:00 UTC 2450 + FILL(15178924800,2451, 1, 1,0, 0, 0, 0), // Sun Jan 1 00:00:00 UTC 2451 + FILL(15936307199,2474,12,31,1,23,59,59), // Mon Dec 31 23:59:59 UTC 2474 + FILL(15936307200,2475, 1, 1,2, 0, 0, 0), // Tue Jan 1 00:00:00 UTC 2475 + FILL(15967843200,2476, 1, 1,3, 0, 0, 0), // Wed Jan 1 00:00:00 UTC 2476 + FILL(16725225599,2499,12,31,4,23,59,59), // Thu Dec 31 23:59:59 UTC 2499 + FILL(16725225600,2500, 1, 1,5, 0, 0, 0), // Fri Jan 1 00:00:00 UTC 2500 + FILL(16756761600,2501, 1, 1,6, 0, 0, 0), // Sat Jan 1 00:00:00 UTC 2501 + FILL(17514143999,2524,12,31,0,23,59,59), // Sun Dec 31 23:59:59 UTC 2524 + FILL(17514144000,2525, 1, 1,1, 0, 0, 0), // Mon Jan 1 00:00:00 UTC 2525 + FILL(17545680000,2526, 1, 1,2, 0, 0, 0), // Tue Jan 1 00:00:00 UTC 2526 + FILL(18303062399,2549,12,31,3,23,59,59), // Wed Dec 31 23:59:59 UTC 2549 + FILL(18303062400,2550, 1, 1,4, 0, 0, 0), // Thu Jan 1 00:00:00 UTC 2550 + FILL(18334598400,2551, 1, 1,5, 0, 0, 0), // Fri Jan 1 00:00:00 UTC 2551 + FILL(19091980799,2574,12,31,6,23,59,59), // Sat Dec 31 23:59:59 UTC 2574 + FILL(19091980800,2575, 1, 1,0, 0, 0, 0), // Sun Jan 1 00:00:00 UTC 2575 + FILL(19123516800,2576, 1, 1,1, 0, 0, 0), // Mon Jan 1 00:00:00 UTC 2576 + FILL(19880899199,2599,12,31,2,23,59,59), // Tue Dec 31 23:59:59 UTC 2599 + FILL(19880899200,2600, 1, 1,3, 0, 0, 0), // Wed Jan 1 00:00:00 UTC 2600 + FILL(19912435200,2601, 1, 1,4, 0, 0, 0), // Thu Jan 1 00:00:00 UTC 2601 +}; +#undef FILL + +ATF_TC(ymdhms_to_secs); +ATF_TC_HEAD(ymdhms_to_secs, tc) +{ + + atf_tc_set_md_var(tc, "descr", "check clock_ymdhms_to_secs"); +} +ATF_TC_BODY(ymdhms_to_secs, tc) +{ + time_t secs; + size_t i; + + for (i = 0; i < __arraycount(clock_tests); i++) { + secs = clock_ymdhms_to_secs(__UNCONST(&clock_tests[i].clock)); + ATF_CHECK_EQ_MSG(clock_tests[i].time, secs, "%jd != %jd", + (intmax_t)clock_tests[i].time, (intmax_t)secs); + } +} + +ATF_TC(secs_to_ymdhms); +ATF_TC_HEAD(secs_to_ymdhms, tc) +{ + + atf_tc_set_md_var(tc, "descr", "check clock_secs_to_ymdhms"); +} +ATF_TC_BODY(secs_to_ymdhms, tc) +{ + struct clock_ymdhms ymdhms; + size_t i; + +#define CHECK_FIELD(f) \ + ATF_CHECK_EQ_MSG(ymdhms.dt_##f, clock_tests[i].clock.dt_##f, \ + "%jd != %jd for %jd", (intmax_t)ymdhms.dt_##f, \ + (intmax_t)clock_tests[i].clock.dt_##f, \ + (intmax_t)clock_tests[i].time) + + for (i = 0; i < __arraycount(clock_tests); i++) { + clock_secs_to_ymdhms(clock_tests[i].time, &ymdhms); + CHECK_FIELD(year); + CHECK_FIELD(mon); + CHECK_FIELD(day); + CHECK_FIELD(wday); + CHECK_FIELD(hour); + CHECK_FIELD(min); + CHECK_FIELD(sec); + } +#undef CHECK_FIELD +} + +ATF_TP_ADD_TCS(tp) +{ + + ATF_TP_ADD_TC(tp, ymdhms_to_secs); + ATF_TP_ADD_TC(tp, secs_to_ymdhms); + + return atf_no_error(); +} diff --git a/contrib/netbsd-tests/dev/scsipi/t_cd.c b/contrib/netbsd-tests/dev/scsipi/t_cd.c index 58e61a564ea0..6e856de187ca 100644 --- a/contrib/netbsd-tests/dev/scsipi/t_cd.c +++ b/contrib/netbsd-tests/dev/scsipi/t_cd.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_cd.c,v 1.7 2014/04/25 00:24:39 pooka Exp $ */ +/* $NetBSD: t_cd.c,v 1.8 2017/01/13 21:30:39 christos Exp $ */ /* * Copyright (c) 2010 Antti Kantee. All Rights Reserved. @@ -39,7 +39,7 @@ #include "scsitest.h" -#include "../../h_macros.h" +#include "h_macros.h" ATF_TC(noisyeject); ATF_TC_HEAD(noisyeject, tc) diff --git a/contrib/netbsd-tests/dev/sysmon/t_swwdog.c b/contrib/netbsd-tests/dev/sysmon/t_swwdog.c index 1635884447ea..5e5fd991e1ba 100644 --- a/contrib/netbsd-tests/dev/sysmon/t_swwdog.c +++ b/contrib/netbsd-tests/dev/sysmon/t_swwdog.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_swwdog.c,v 1.6 2015/04/23 04:49:37 pgoyette Exp $ */ +/* $NetBSD: t_swwdog.c,v 1.7 2017/01/13 21:30:39 christos Exp $ */ /* * Copyright (c) 2010 Antti Kantee. All Rights Reserved. @@ -43,7 +43,7 @@ #include #include -#include "../../h_macros.h" +#include "h_macros.h" static volatile sig_atomic_t tcount; diff --git a/contrib/netbsd-tests/fs/common/h_fsmacros.h b/contrib/netbsd-tests/fs/common/h_fsmacros.h index b295cf28104c..eb8376873b2f 100644 --- a/contrib/netbsd-tests/fs/common/h_fsmacros.h +++ b/contrib/netbsd-tests/fs/common/h_fsmacros.h @@ -1,4 +1,4 @@ -/* $NetBSD: h_fsmacros.h,v 1.40 2015/08/29 19:19:43 dholland Exp $ */ +/* $NetBSD: h_fsmacros.h,v 1.41 2017/01/13 21:30:39 christos Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -40,7 +40,7 @@ #include -#include "../../h_macros.h" +#include "h_macros.h" #define FSPROTOS(_fs_) \ int _fs_##_fstest_newfs(const atf_tc_t *, void **, const char *, \ diff --git a/contrib/netbsd-tests/fs/ffs/h_quota2_tests.c b/contrib/netbsd-tests/fs/ffs/h_quota2_tests.c index 59f3ea3b0917..71cf3b4958f1 100644 --- a/contrib/netbsd-tests/fs/ffs/h_quota2_tests.c +++ b/contrib/netbsd-tests/fs/ffs/h_quota2_tests.c @@ -1,4 +1,4 @@ -/* $NetBSD: h_quota2_tests.c,v 1.4 2012/09/30 21:26:57 bouyer Exp $ */ +/* $NetBSD: h_quota2_tests.c,v 1.5 2017/01/13 21:30:39 christos Exp $ */ /* * rump server for advanced quota tests @@ -22,7 +22,7 @@ #include #include -#include "../../h_macros.h" +#include "h_macros.h" int background = 0; diff --git a/contrib/netbsd-tests/fs/ffs/t_fifos.c b/contrib/netbsd-tests/fs/ffs/t_fifos.c index fe1d4254a352..10b50bbd792d 100644 --- a/contrib/netbsd-tests/fs/ffs/t_fifos.c +++ b/contrib/netbsd-tests/fs/ffs/t_fifos.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_fifos.c,v 1.5 2010/11/07 17:51:17 jmmv Exp $ */ +/* $NetBSD: t_fifos.c,v 1.6 2017/01/13 21:30:39 christos Exp $ */ #include #include @@ -17,7 +17,7 @@ #include -#include "../../h_macros.h" +#include "h_macros.h" ATF_TC_WITH_CLEANUP(fifos); ATF_TC_HEAD(fifos, tc) diff --git a/contrib/netbsd-tests/fs/ffs/t_mount.c b/contrib/netbsd-tests/fs/ffs/t_mount.c index 6a8f74f455f8..20960953406b 100644 --- a/contrib/netbsd-tests/fs/ffs/t_mount.c +++ b/contrib/netbsd-tests/fs/ffs/t_mount.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_mount.c,v 1.13 2012/11/27 16:01:49 jakllsch Exp $ */ +/* $NetBSD: t_mount.c,v 1.14 2017/01/13 21:30:39 christos Exp $ */ /* * Basic tests for mounting @@ -25,7 +25,7 @@ #include #include -#include "../../h_macros.h" +#include "h_macros.h" ATF_TC(48Kimage); ATF_TC_HEAD(48Kimage, tc) diff --git a/contrib/netbsd-tests/fs/ffs/t_quota2_1.c b/contrib/netbsd-tests/fs/ffs/t_quota2_1.c index 333f3c712708..22cd5d24512a 100644 --- a/contrib/netbsd-tests/fs/ffs/t_quota2_1.c +++ b/contrib/netbsd-tests/fs/ffs/t_quota2_1.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_quota2_1.c,v 1.4 2012/03/15 02:02:22 joerg Exp $ */ +/* $NetBSD: t_quota2_1.c,v 1.5 2017/01/13 21:30:39 christos Exp $ */ /* * Basic tests for quota2 @@ -18,7 +18,7 @@ #include #include -#include "../../h_macros.h" +#include "h_macros.h" static void do_quota(const atf_tc_t *tc, int n, const char *newfs_opts, int log) diff --git a/contrib/netbsd-tests/fs/ffs/t_quota2_remount.c b/contrib/netbsd-tests/fs/ffs/t_quota2_remount.c index f648856bbf70..d843cf891b4b 100644 --- a/contrib/netbsd-tests/fs/ffs/t_quota2_remount.c +++ b/contrib/netbsd-tests/fs/ffs/t_quota2_remount.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_quota2_remount.c,v 1.4 2012/03/15 02:02:22 joerg Exp $ */ +/* $NetBSD: t_quota2_remount.c,v 1.5 2017/01/13 21:30:39 christos Exp $ */ /* * Basic tests for quota2 @@ -19,7 +19,7 @@ #include #include -#include "../../h_macros.h" +#include "h_macros.h" static void do_quota(const atf_tc_t *tc, int n, const char *newfs_opts, int log) diff --git a/contrib/netbsd-tests/fs/ffs/t_snapshot.c b/contrib/netbsd-tests/fs/ffs/t_snapshot.c index 180a8ccd92b0..f661bec2634c 100644 --- a/contrib/netbsd-tests/fs/ffs/t_snapshot.c +++ b/contrib/netbsd-tests/fs/ffs/t_snapshot.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_snapshot.c,v 1.6 2013/02/06 09:05:01 hannken Exp $ */ +/* $NetBSD: t_snapshot.c,v 1.7 2017/01/13 21:30:39 christos Exp $ */ #include #include @@ -15,7 +15,7 @@ #include #include -#include "../../h_macros.h" +#include "h_macros.h" #define IMGNAME "ffs.img" #define NEWFS "newfs -F -s 10000 " IMGNAME diff --git a/contrib/netbsd-tests/fs/ffs/t_snapshot_log.c b/contrib/netbsd-tests/fs/ffs/t_snapshot_log.c index e1ce17e1006a..31b28e53df2d 100644 --- a/contrib/netbsd-tests/fs/ffs/t_snapshot_log.c +++ b/contrib/netbsd-tests/fs/ffs/t_snapshot_log.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_snapshot_log.c,v 1.2 2013/02/06 09:05:01 hannken Exp $ */ +/* $NetBSD: t_snapshot_log.c,v 1.3 2017/01/13 21:30:39 christos Exp $ */ #include #include @@ -15,7 +15,7 @@ #include #include -#include "../../h_macros.h" +#include "h_macros.h" #define IMGNAME "ffs.img" #define NEWFS "newfs -F -s 10000 " IMGNAME diff --git a/contrib/netbsd-tests/fs/ffs/t_snapshot_v2.c b/contrib/netbsd-tests/fs/ffs/t_snapshot_v2.c index 393f3d41a6c3..b27929cb12d8 100644 --- a/contrib/netbsd-tests/fs/ffs/t_snapshot_v2.c +++ b/contrib/netbsd-tests/fs/ffs/t_snapshot_v2.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_snapshot_v2.c,v 1.2 2013/02/06 09:05:01 hannken Exp $ */ +/* $NetBSD: t_snapshot_v2.c,v 1.3 2017/01/13 21:30:39 christos Exp $ */ #include #include @@ -15,7 +15,7 @@ #include #include -#include "../../h_macros.h" +#include "h_macros.h" #define IMGNAME "ffs.img" #define NEWFS "newfs -F -s 10000 -O 2 " IMGNAME diff --git a/contrib/netbsd-tests/fs/hfs/t_pathconvert.c b/contrib/netbsd-tests/fs/hfs/t_pathconvert.c index 307de709be8b..056726a1a6c2 100644 --- a/contrib/netbsd-tests/fs/hfs/t_pathconvert.c +++ b/contrib/netbsd-tests/fs/hfs/t_pathconvert.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_pathconvert.c,v 1.5 2011/02/25 20:54:18 martin Exp $ */ +/* $NetBSD: t_pathconvert.c,v 1.6 2017/01/13 21:30:40 christos Exp $ */ #include #include @@ -18,7 +18,7 @@ #include -#include "../../h_macros.h" +#include "h_macros.h" ATF_TC(colonslash); ATF_TC_HEAD(colonslash, tc) diff --git a/contrib/netbsd-tests/fs/kernfs/t_basic.c b/contrib/netbsd-tests/fs/kernfs/t_basic.c index e5ba4a77e1b7..77acd1149c66 100644 --- a/contrib/netbsd-tests/fs/kernfs/t_basic.c +++ b/contrib/netbsd-tests/fs/kernfs/t_basic.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_basic.c,v 1.3 2010/05/31 23:44:54 pooka Exp $ */ +/* $NetBSD: t_basic.c,v 1.4 2017/01/13 21:30:40 christos Exp $ */ #include #include @@ -20,7 +20,7 @@ #include -#include "../../h_macros.h" +#include "h_macros.h" ATF_TC(getdents); ATF_TC_HEAD(getdents, tc) diff --git a/contrib/netbsd-tests/fs/lfs/t_pr.c b/contrib/netbsd-tests/fs/lfs/t_pr.c index 97cb1dbbbf77..ed676d8bf9b0 100644 --- a/contrib/netbsd-tests/fs/lfs/t_pr.c +++ b/contrib/netbsd-tests/fs/lfs/t_pr.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_pr.c,v 1.6 2011/02/22 18:41:05 pooka Exp $ */ +/* $NetBSD: t_pr.c,v 1.7 2017/01/13 21:30:40 christos Exp $ */ #include #include @@ -17,7 +17,7 @@ #include -#include "../../h_macros.h" +#include "h_macros.h" ATF_TC(mknod); ATF_TC_HEAD(mknod, tc) diff --git a/contrib/netbsd-tests/fs/msdosfs/t_snapshot.c b/contrib/netbsd-tests/fs/msdosfs/t_snapshot.c index 8b5708f843a3..449e62545ab7 100644 --- a/contrib/netbsd-tests/fs/msdosfs/t_snapshot.c +++ b/contrib/netbsd-tests/fs/msdosfs/t_snapshot.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_snapshot.c,v 1.3 2014/06/10 13:15:18 martin Exp $ */ +/* $NetBSD: t_snapshot.c,v 1.4 2017/01/13 21:30:40 christos Exp $ */ #include #include @@ -17,7 +17,7 @@ #include #include -#include "../../h_macros.h" +#include "h_macros.h" #define IMGNAME "msdosfs.img" #define NEWFS "newfs_msdos -C 5M " IMGNAME diff --git a/contrib/netbsd-tests/fs/nfs/t_mountd.c b/contrib/netbsd-tests/fs/nfs/t_mountd.c index b6c15287791c..6272587d71a0 100644 --- a/contrib/netbsd-tests/fs/nfs/t_mountd.c +++ b/contrib/netbsd-tests/fs/nfs/t_mountd.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_mountd.c,v 1.5 2012/02/24 13:53:46 joerg Exp $ */ +/* $NetBSD: t_mountd.c,v 1.6 2017/01/13 21:30:40 christos Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -41,7 +41,7 @@ #include #include -#include "../../h_macros.h" +#include "h_macros.h" #include "../common/h_fsmacros.h" ATF_TC(mountdhup); diff --git a/contrib/netbsd-tests/fs/nullfs/t_basic.c b/contrib/netbsd-tests/fs/nullfs/t_basic.c index 21dfccdb80f1..d54f7739bafc 100644 --- a/contrib/netbsd-tests/fs/nullfs/t_basic.c +++ b/contrib/netbsd-tests/fs/nullfs/t_basic.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_basic.c,v 1.3 2010/06/09 08:37:16 pooka Exp $ */ +/* $NetBSD: t_basic.c,v 1.4 2017/01/13 21:30:40 christos Exp $ */ #include #include @@ -18,7 +18,7 @@ #include #include -#include "../../h_macros.h" +#include "h_macros.h" ATF_TC(basic); ATF_TC_HEAD(basic, tc) diff --git a/contrib/netbsd-tests/fs/ptyfs/t_nullpts.c b/contrib/netbsd-tests/fs/ptyfs/t_nullpts.c index 9265f32ffa0a..fcc7e47f6215 100644 --- a/contrib/netbsd-tests/fs/ptyfs/t_nullpts.c +++ b/contrib/netbsd-tests/fs/ptyfs/t_nullpts.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_nullpts.c,v 1.5 2011/01/10 11:11:04 hannken Exp $ */ +/* $NetBSD: t_nullpts.c,v 1.6 2017/01/13 21:30:40 christos Exp $ */ #include #include @@ -19,7 +19,7 @@ #include #include -#include "../../h_macros.h" +#include "h_macros.h" static void mountptyfs(const char *mp, int flags) diff --git a/contrib/netbsd-tests/fs/ptyfs/t_ptyfs.c b/contrib/netbsd-tests/fs/ptyfs/t_ptyfs.c index 90001b92ee94..108c344c343c 100644 --- a/contrib/netbsd-tests/fs/ptyfs/t_ptyfs.c +++ b/contrib/netbsd-tests/fs/ptyfs/t_ptyfs.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_ptyfs.c,v 1.1 2010/06/11 23:52:38 pooka Exp $ */ +/* $NetBSD: t_ptyfs.c,v 1.2 2017/01/13 21:30:40 christos Exp $ */ #include #include @@ -17,7 +17,7 @@ #include -#include "../../h_macros.h" +#include "h_macros.h" static void mountptyfs(const char *mp, int flags) diff --git a/contrib/netbsd-tests/fs/puffs/t_basic.c b/contrib/netbsd-tests/fs/puffs/t_basic.c index 735108d64f44..4b5b7b81b2a4 100644 --- a/contrib/netbsd-tests/fs/puffs/t_basic.c +++ b/contrib/netbsd-tests/fs/puffs/t_basic.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_basic.c,v 1.13 2016/12/01 14:49:04 hannken Exp $ */ +/* $NetBSD: t_basic.c,v 1.14 2017/01/13 21:30:40 christos Exp $ */ #include #include @@ -20,7 +20,7 @@ #include #include -#include "../../h_macros.h" +#include "h_macros.h" #include "../common/h_fsmacros.h" /* diff --git a/contrib/netbsd-tests/fs/puffs/t_fuzz.c b/contrib/netbsd-tests/fs/puffs/t_fuzz.c index 1d249c0a8be1..b2e000d07e5c 100644 --- a/contrib/netbsd-tests/fs/puffs/t_fuzz.c +++ b/contrib/netbsd-tests/fs/puffs/t_fuzz.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_fuzz.c,v 1.5 2012/04/21 01:03:46 manu Exp $ */ +/* $NetBSD: t_fuzz.c,v 1.6 2017/01/13 21:30:40 christos Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -56,7 +56,7 @@ #include #include -#include "../../h_macros.h" +#include "h_macros.h" #define ITERATIONS 100 diff --git a/contrib/netbsd-tests/fs/puffs/t_io.c b/contrib/netbsd-tests/fs/puffs/t_io.c index 37c386c83d5a..72b5d85e23ff 100644 --- a/contrib/netbsd-tests/fs/puffs/t_io.c +++ b/contrib/netbsd-tests/fs/puffs/t_io.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_io.c,v 1.1 2010/11/12 17:33:28 pooka Exp $ */ +/* $NetBSD: t_io.c,v 1.2 2017/01/13 21:30:40 christos Exp $ */ #include #include @@ -20,7 +20,7 @@ #include #include -#include "../../h_macros.h" +#include "h_macros.h" #include "../common/h_fsmacros.h" #define MAKEOPTS(...) \ diff --git a/contrib/netbsd-tests/fs/tmpfs/t_renamerace.c b/contrib/netbsd-tests/fs/tmpfs/t_renamerace.c index 044937a930c8..d7c10e4c6679 100644 --- a/contrib/netbsd-tests/fs/tmpfs/t_renamerace.c +++ b/contrib/netbsd-tests/fs/tmpfs/t_renamerace.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_renamerace.c,v 1.13 2011/08/18 21:44:55 riastradh Exp $ */ +/* $NetBSD: t_renamerace.c,v 1.14 2017/01/13 21:30:40 christos Exp $ */ /* * Modified for rump and atf from a program supplied @@ -23,7 +23,7 @@ #include -#include "../../h_macros.h" +#include "h_macros.h" ATF_TC(renamerace2); ATF_TC_HEAD(renamerace2, tc) diff --git a/contrib/netbsd-tests/fs/umapfs/t_basic.c b/contrib/netbsd-tests/fs/umapfs/t_basic.c index 259f6fe8c11b..c9b2d9b7a5dc 100644 --- a/contrib/netbsd-tests/fs/umapfs/t_basic.c +++ b/contrib/netbsd-tests/fs/umapfs/t_basic.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_basic.c,v 1.4 2010/07/19 15:35:39 pooka Exp $ */ +/* $NetBSD: t_basic.c,v 1.5 2017/01/13 21:30:40 christos Exp $ */ #include #include @@ -20,7 +20,7 @@ #include #include -#include "../../h_macros.h" +#include "h_macros.h" ATF_TC(basic); ATF_TC_HEAD(basic, tc) diff --git a/contrib/netbsd-tests/fs/union/t_pr.c b/contrib/netbsd-tests/fs/union/t_pr.c index 2d0c0c84db49..fc70bcadf36b 100644 --- a/contrib/netbsd-tests/fs/union/t_pr.c +++ b/contrib/netbsd-tests/fs/union/t_pr.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_pr.c,v 1.8 2011/08/10 06:27:02 hannken Exp $ */ +/* $NetBSD: t_pr.c,v 1.9 2017/01/13 21:30:40 christos Exp $ */ #include #include @@ -17,7 +17,7 @@ #include -#include "../../h_macros.h" +#include "h_macros.h" ATF_TC(multilayer); ATF_TC_HEAD(multilayer, tc) diff --git a/contrib/netbsd-tests/fs/vfs/t_full.c b/contrib/netbsd-tests/fs/vfs/t_full.c index f338a0221f0a..51347deca70d 100644 --- a/contrib/netbsd-tests/fs/vfs/t_full.c +++ b/contrib/netbsd-tests/fs/vfs/t_full.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_full.c,v 1.8 2013/03/16 05:45:37 jmmv Exp $ */ +/* $NetBSD: t_full.c,v 1.9 2017/01/13 21:30:40 christos Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -39,7 +39,7 @@ #include #include "../common/h_fsmacros.h" -#include "../../h_macros.h" +#include "h_macros.h" /* * Write this much over the image size. This is to force an NFS commit, diff --git a/contrib/netbsd-tests/fs/vfs/t_io.c b/contrib/netbsd-tests/fs/vfs/t_io.c index 23c3a157f802..b7f652936e10 100644 --- a/contrib/netbsd-tests/fs/vfs/t_io.c +++ b/contrib/netbsd-tests/fs/vfs/t_io.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_io.c,v 1.16 2015/04/04 12:34:44 riastradh Exp $ */ +/* $NetBSD: t_io.c,v 1.17 2017/01/13 21:30:40 christos Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -39,7 +39,7 @@ #include #include "../common/h_fsmacros.h" -#include "../../h_macros.h" +#include "h_macros.h" #define TESTSTR "this is a string. collect enough and you'll have Em" #define TESTSZ sizeof(TESTSTR) diff --git a/contrib/netbsd-tests/fs/vfs/t_renamerace.c b/contrib/netbsd-tests/fs/vfs/t_renamerace.c index 809c380c5e22..63cfb4479c89 100644 --- a/contrib/netbsd-tests/fs/vfs/t_renamerace.c +++ b/contrib/netbsd-tests/fs/vfs/t_renamerace.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_renamerace.c,v 1.33 2016/05/04 08:30:22 dholland Exp $ */ +/* $NetBSD: t_renamerace.c,v 1.34 2017/01/13 21:30:40 christos Exp $ */ /* * Modified for rump and atf from a program supplied @@ -34,7 +34,7 @@ #define FSTEST_IMGSIZE (50000 * 512) #include "../common/h_fsmacros.h" -#include "../../h_macros.h" +#include "h_macros.h" static volatile int quittingtime; pid_t wrkpid; diff --git a/contrib/netbsd-tests/fs/vfs/t_ro.c b/contrib/netbsd-tests/fs/vfs/t_ro.c index b1e1179956b0..f7f45813e7b7 100644 --- a/contrib/netbsd-tests/fs/vfs/t_ro.c +++ b/contrib/netbsd-tests/fs/vfs/t_ro.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_ro.c,v 1.5 2011/02/22 21:23:19 yamt Exp $ */ +/* $NetBSD: t_ro.c,v 1.6 2017/01/13 21:30:40 christos Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -39,7 +39,7 @@ #include #include "../common/h_fsmacros.h" -#include "../../h_macros.h" +#include "h_macros.h" #define AFILE "testfile" #define ADIR "testdir" diff --git a/contrib/netbsd-tests/fs/vfs/t_union.c b/contrib/netbsd-tests/fs/vfs/t_union.c index bdcef939354e..5da1ea1ff39b 100644 --- a/contrib/netbsd-tests/fs/vfs/t_union.c +++ b/contrib/netbsd-tests/fs/vfs/t_union.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_union.c,v 1.8 2011/08/07 06:01:51 hannken Exp $ */ +/* $NetBSD: t_union.c,v 1.9 2017/01/13 21:30:40 christos Exp $ */ #include #include @@ -17,7 +17,7 @@ #include -#include "../../h_macros.h" +#include "h_macros.h" #include "../common/h_fsmacros.h" #define MSTR "magic bus" diff --git a/contrib/netbsd-tests/fs/vfs/t_unpriv.c b/contrib/netbsd-tests/fs/vfs/t_unpriv.c index 6da771b45bcd..6536c21d9572 100644 --- a/contrib/netbsd-tests/fs/vfs/t_unpriv.c +++ b/contrib/netbsd-tests/fs/vfs/t_unpriv.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_unpriv.c,v 1.12 2015/04/09 19:51:13 riastradh Exp $ */ +/* $NetBSD: t_unpriv.c,v 1.13 2017/01/13 21:30:40 christos Exp $ */ /*- * Copyright (c) 2011 The NetBSD Foundation, Inc. @@ -38,7 +38,7 @@ #include #include "../common/h_fsmacros.h" -#include "../../h_macros.h" +#include "h_macros.h" #define USES_OWNER \ if (FSTYPE_MSDOS(tc)) \ diff --git a/contrib/netbsd-tests/fs/vfs/t_vfsops.c b/contrib/netbsd-tests/fs/vfs/t_vfsops.c index 1bcee89e573d..bbed9f9d3089 100644 --- a/contrib/netbsd-tests/fs/vfs/t_vfsops.c +++ b/contrib/netbsd-tests/fs/vfs/t_vfsops.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_vfsops.c,v 1.11 2011/04/04 19:16:58 hannken Exp $ */ +/* $NetBSD: t_vfsops.c,v 1.12 2017/01/13 21:30:40 christos Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -39,7 +39,7 @@ #include #include "../common/h_fsmacros.h" -#include "../../h_macros.h" +#include "h_macros.h" static void tmount(const atf_tc_t *tc, const char *path) diff --git a/contrib/netbsd-tests/fs/vfs/t_vnops.c b/contrib/netbsd-tests/fs/vfs/t_vnops.c index 978fadb04c26..7da53c8d4386 100644 --- a/contrib/netbsd-tests/fs/vfs/t_vnops.c +++ b/contrib/netbsd-tests/fs/vfs/t_vnops.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_vnops.c,v 1.58 2016/08/29 02:31:46 kre Exp $ */ +/* $NetBSD: t_vnops.c,v 1.59 2017/01/13 21:30:40 christos Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -43,7 +43,7 @@ #include #include "../common/h_fsmacros.h" -#include "../../h_macros.h" +#include "h_macros.h" #define TESTFILE "afile" diff --git a/contrib/netbsd-tests/include/sys/t_socket.c b/contrib/netbsd-tests/include/sys/t_socket.c index f60941c1ab1a..9db224780180 100644 --- a/contrib/netbsd-tests/include/sys/t_socket.c +++ b/contrib/netbsd-tests/include/sys/t_socket.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_socket.c,v 1.4 2015/02/27 08:30:30 martin Exp $ */ +/* $NetBSD: t_socket.c,v 1.5 2017/01/13 21:30:41 christos Exp $ */ #include #include @@ -18,7 +18,7 @@ #include #include -#include "../../h_macros.h" +#include "h_macros.h" ATF_TC(cmsg_sendfd_bounds); ATF_TC_HEAD(cmsg_sendfd_bounds, tc) diff --git a/contrib/netbsd-tests/kernel/arch/amd64/t_ptrace_wait.c b/contrib/netbsd-tests/kernel/arch/amd64/t_ptrace_wait.c new file mode 100644 index 000000000000..5adbb0e94554 --- /dev/null +++ b/contrib/netbsd-tests/kernel/arch/amd64/t_ptrace_wait.c @@ -0,0 +1,1388 @@ +/* $NetBSD: t_ptrace_wait.c,v 1.9 2017/01/13 21:30:41 christos Exp $ */ + +/*- + * Copyright (c) 2016 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. + */ + +#include +__RCSID("$NetBSD: t_ptrace_wait.c,v 1.9 2017/01/13 21:30:41 christos Exp $"); + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "h_macros.h" + +#include "../../t_ptrace_wait.h" + + +#if defined(HAVE_GPREGS) +ATF_TC(regs1); +ATF_TC_HEAD(regs1, tc) +{ + atf_tc_set_md_var(tc, "descr", + "Call PT_GETREGS and iterate over General Purpose registers"); +} + +ATF_TC_BODY(regs1, tc) +{ + const int exitval = 5; + const int sigval = SIGSTOP; + pid_t child, wpid; +#if defined(TWAIT_HAVE_STATUS) + int status; +#endif + struct reg r; + + printf("Before forking process PID=%d\n", getpid()); + ATF_REQUIRE((child = fork()) != -1); + if (child == 0) { + printf("Before calling PT_TRACE_ME from child %d\n", getpid()); + FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); + + printf("Before raising %s from child\n", strsignal(sigval)); + FORKEE_ASSERT(raise(sigval) == 0); + + printf("Before exiting of the child process\n"); + _exit(exitval); + } + printf("Parent process PID=%d, child's PID=%d\n", getpid(), child); + + printf("Before calling %s() for the child\n", TWAIT_FNAME); + TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); + + validate_status_stopped(status, sigval); + + printf("Call GETREGS for the child process\n"); + ATF_REQUIRE(ptrace(PT_GETREGS, child, &r, 0) != -1); + + printf("RAX=%#" PRIxREGISTER "\n", r.regs[_REG_RAX]); + printf("RBX=%#" PRIxREGISTER "\n", r.regs[_REG_RBX]); + printf("RCX=%#" PRIxREGISTER "\n", r.regs[_REG_RCX]); + printf("RDX=%#" PRIxREGISTER "\n", r.regs[_REG_RDX]); + + printf("RDI=%#" PRIxREGISTER "\n", r.regs[_REG_RDI]); + printf("RSI=%#" PRIxREGISTER "\n", r.regs[_REG_RSI]); + + printf("GS=%#" PRIxREGISTER "\n", r.regs[_REG_GS]); + printf("FS=%#" PRIxREGISTER "\n", r.regs[_REG_FS]); + printf("ES=%#" PRIxREGISTER "\n", r.regs[_REG_ES]); + printf("DS=%#" PRIxREGISTER "\n", r.regs[_REG_DS]); + printf("CS=%#" PRIxREGISTER "\n", r.regs[_REG_CS]); + printf("SS=%#" PRIxREGISTER "\n", r.regs[_REG_SS]); + + printf("RSP=%#" PRIxREGISTER "\n", r.regs[_REG_RSP]); + printf("RIP=%#" PRIxREGISTER "\n", r.regs[_REG_RIP]); + + printf("RFLAGS=%#" PRIxREGISTER "\n", r.regs[_REG_RFLAGS]); + + printf("R8=%#" PRIxREGISTER "\n", r.regs[_REG_R8]); + printf("R9=%#" PRIxREGISTER "\n", r.regs[_REG_R9]); + printf("R10=%#" PRIxREGISTER "\n", r.regs[_REG_R10]); + printf("R11=%#" PRIxREGISTER "\n", r.regs[_REG_R11]); + printf("R12=%#" PRIxREGISTER "\n", r.regs[_REG_R12]); + printf("R13=%#" PRIxREGISTER "\n", r.regs[_REG_R13]); + printf("R14=%#" PRIxREGISTER "\n", r.regs[_REG_R14]); + printf("R15=%#" PRIxREGISTER "\n", r.regs[_REG_R15]); + + printf("Before resuming the child process where it left off and " + "without signal to be sent\n"); + ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); + + printf("Before calling %s() for the child\n", TWAIT_FNAME); + TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); + + validate_status_exited(status, exitval); + + printf("Before calling %s() for the child\n", TWAIT_FNAME); + TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); +} +#endif + +#if defined(__HAVE_PTRACE_WATCHPOINTS) +ATF_TC(watchpoint_count); +ATF_TC_HEAD(watchpoint_count, tc) +{ + atf_tc_set_md_var(tc, "descr", + "Call PT_COUNT_WATCHPOINTS and assert four available watchpoints"); +} + +ATF_TC_BODY(watchpoint_count, tc) +{ + const int exitval = 5; + const int sigval = SIGSTOP; + pid_t child, wpid; +#if defined(TWAIT_HAVE_STATUS) + int status; +#endif + int N; + + printf("Before forking process PID=%d\n", getpid()); + ATF_REQUIRE((child = fork()) != -1); + if (child == 0) { + printf("Before calling PT_TRACE_ME from child %d\n", getpid()); + FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); + + printf("Before raising %s from child\n", strsignal(sigval)); + FORKEE_ASSERT(raise(sigval) == 0); + + printf("Before exiting of the child process\n"); + _exit(exitval); + } + printf("Parent process PID=%d, child's PID=%d\n", getpid(), child); + + printf("Before calling %s() for the child\n", TWAIT_FNAME); + TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); + + validate_status_stopped(status, sigval); + + printf("Call GETREGS for the child process\n"); + ATF_REQUIRE((N = ptrace(PT_COUNT_WATCHPOINTS, child, NULL, 0)) != -1); + printf("Reported %d watchpoints\n", N); + + ATF_REQUIRE_EQ_MSG(N, 4, "Expected 4 hw watchpoints - got %d", N); + + printf("Before resuming the child process where it left off and " + "without signal to be sent\n"); + ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); + + printf("Before calling %s() for the child\n", TWAIT_FNAME); + TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); + + validate_status_exited(status, exitval); + + printf("Before calling %s() for the child\n", TWAIT_FNAME); + TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); +} +#endif + +#if defined(__HAVE_PTRACE_WATCHPOINTS) +ATF_TC(watchpoint_read); +ATF_TC_HEAD(watchpoint_read, tc) +{ + atf_tc_set_md_var(tc, "descr", + "Call PT_COUNT_WATCHPOINTS and assert four available watchpoints"); +} + +ATF_TC_BODY(watchpoint_read, tc) +{ + const int exitval = 5; + const int sigval = SIGSTOP; + pid_t child, wpid; +#if defined(TWAIT_HAVE_STATUS) + int status; +#endif + int i, N; + struct ptrace_watchpoint pw; + int len = sizeof(pw); + + printf("Before forking process PID=%d\n", getpid()); + ATF_REQUIRE((child = fork()) != -1); + if (child == 0) { + printf("Before calling PT_TRACE_ME from child %d\n", getpid()); + FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); + + printf("Before raising %s from child\n", strsignal(sigval)); + FORKEE_ASSERT(raise(sigval) == 0); + + printf("Before exiting of the child process\n"); + _exit(exitval); + } + printf("Parent process PID=%d, child's PID=%d\n", getpid(), child); + + printf("Before calling %s() for the child\n", TWAIT_FNAME); + TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); + + validate_status_stopped(status, sigval); + + printf("Call GETREGS for the child process\n"); + ATF_REQUIRE((N = ptrace(PT_COUNT_WATCHPOINTS, child, NULL, 0)) != -1); + + ATF_REQUIRE_EQ_MSG(N, 4, "Expected 4 hw watchpoints - got %d", N); + + for (i = 0; i < N; i++) { + printf("Before reading watchpoint %d\n", i); + pw.pw_index = i; + ATF_REQUIRE(ptrace(PT_READ_WATCHPOINT, child, &pw, len) != -1); + + printf("struct ptrace {\n"); + printf("\t.pw_index=%d\n", pw.pw_index); + printf("\t.pw_lwpid=%d\n", pw.pw_lwpid); + printf("\t.pw_md.md_address=%p\n", pw.pw_md.md_address); + printf("\t.pw_md.md_condition=%#x\n", pw.pw_md.md_condition); + printf("\t.pw_md.md_length=%#x\n", pw.pw_md.md_length); + printf("}\n"); + } + + printf("Before resuming the child process where it left off and " + "without signal to be sent\n"); + ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); + + printf("Before calling %s() for the child\n", TWAIT_FNAME); + TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); + + validate_status_exited(status, exitval); + + printf("Before calling %s() for the child\n", TWAIT_FNAME); + TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); +} +#endif + +#if defined(__HAVE_PTRACE_WATCHPOINTS) +ATF_TC(watchpoint_write_unmodified); +ATF_TC_HEAD(watchpoint_write_unmodified, tc) +{ + atf_tc_set_md_var(tc, "descr", + "Call PT_COUNT_WATCHPOINTS and assert functional write of " + "unmodified data"); +} + +ATF_TC_BODY(watchpoint_write_unmodified, tc) +{ + const int exitval = 5; + const int sigval = SIGSTOP; + pid_t child, wpid; +#if defined(TWAIT_HAVE_STATUS) + int status; +#endif + int i, N; + struct ptrace_watchpoint pw; + int len = sizeof(pw); + + printf("Before forking process PID=%d\n", getpid()); + ATF_REQUIRE((child = fork()) != -1); + if (child == 0) { + printf("Before calling PT_TRACE_ME from child %d\n", getpid()); + FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); + + printf("Before raising %s from child\n", strsignal(sigval)); + FORKEE_ASSERT(raise(sigval) == 0); + + printf("Before exiting of the child process\n"); + _exit(exitval); + } + printf("Parent process PID=%d, child's PID=%d\n", getpid(), child); + + printf("Before calling %s() for the child\n", TWAIT_FNAME); + TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); + + validate_status_stopped(status, sigval); + + printf("Call GETREGS for the child process\n"); + ATF_REQUIRE((N = ptrace(PT_COUNT_WATCHPOINTS, child, NULL, 0)) != -1); + + ATF_REQUIRE_EQ_MSG(N, 4, "Expected 4 hw watchpoints - got %d", N); + + for (i = 0; i < N; i++) { + printf("Before reading watchpoint %d\n", i); + pw.pw_index = i; + ATF_REQUIRE(ptrace(PT_READ_WATCHPOINT, child, &pw, len) != -1); + + printf("struct ptrace {\n"); + printf("\t.pw_index=%d\n", pw.pw_index); + printf("\t.pw_lwpid=%d\n", pw.pw_lwpid); + printf("\t.pw_md.md_address=%p\n", pw.pw_md.md_address); + printf("\t.pw_md.md_condition=%#x\n", pw.pw_md.md_condition); + printf("\t.pw_md.md_length=%#x\n", pw.pw_md.md_length); + printf("}\n"); + + printf("Before writing watchpoint %d (unmodified)\n", i); + ATF_REQUIRE(ptrace(PT_WRITE_WATCHPOINT, child, &pw, len) + != -1); + } + + printf("Before resuming the child process where it left off and " + "without signal to be sent\n"); + ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); + + printf("Before calling %s() for the child\n", TWAIT_FNAME); + TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); + + validate_status_exited(status, exitval); + + printf("Before calling %s() for the child\n", TWAIT_FNAME); + TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); +} +#endif + +#if defined(__HAVE_PTRACE_WATCHPOINTS) +ATF_TC(watchpoint_trap_code0); +ATF_TC_HEAD(watchpoint_trap_code0, tc) +{ + atf_tc_set_md_var(tc, "descr", + "Call PT_COUNT_WATCHPOINTS and test code trap with watchpoint 0"); +} + +ATF_TC_BODY(watchpoint_trap_code0, tc) +{ + const int exitval = 5; + const int sigval = SIGSTOP; + pid_t child, wpid; +#if defined(TWAIT_HAVE_STATUS) + int status; +#endif + const int i = 0; + struct ptrace_watchpoint pw; + int len = sizeof(pw); + int watchme = 1234; + + printf("Before forking process PID=%d\n", getpid()); + ATF_REQUIRE((child = fork()) != -1); + if (child == 0) { + printf("Before calling PT_TRACE_ME from child %d\n", getpid()); + FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); + + printf("Before raising %s from child\n", strsignal(sigval)); + FORKEE_ASSERT(raise(sigval) == 0); + + printf("check_happy(%d)=%d\n", watchme, check_happy(watchme)); + + printf("Before exiting of the child process\n"); + _exit(exitval); + } + printf("Parent process PID=%d, child's PID=%d\n", getpid(), child); + + printf("Before calling %s() for the child\n", TWAIT_FNAME); + TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); + + validate_status_stopped(status, sigval); + + printf("Preparing code watchpoint trap %d\n", i); + + pw.pw_index = i; + pw.pw_lwpid = 0; + pw.pw_md.md_address = (void *)check_happy; + pw.pw_md.md_condition = X86_HW_WATCHPOINT_DR7_CONDITION_EXECUTION; + pw.pw_md.md_length = X86_HW_WATCHPOINT_DR7_LENGTH_BYTE; + + printf("struct ptrace {\n"); + printf("\t.pw_index=%d\n", pw.pw_index); + printf("\t.pw_lwpid=%d\n", pw.pw_lwpid); + printf("\t.pw_md.md_address=%p\n", pw.pw_md.md_address); + printf("\t.pw_md.md_condition=%#x\n", pw.pw_md.md_condition); + printf("\t.pw_md.md_length=%#x\n", pw.pw_md.md_length); + printf("}\n"); + + printf("Before writing watchpoint %d\n", i); + ATF_REQUIRE(ptrace(PT_WRITE_WATCHPOINT, child, &pw, len) != -1); + + printf("Before resuming the child process where it left off " + "and without signal to be sent\n"); + ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); + + printf("Before calling %s() for the child\n", TWAIT_FNAME); + TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); + + validate_status_stopped(status, SIGTRAP); + + pw.pw_md.md_address = NULL; + printf("Before writing watchpoint %d (disable it)\n", i); + ATF_REQUIRE(ptrace(PT_WRITE_WATCHPOINT, child, &pw, len) != -1); + + printf("Before resuming the child process where it left off and " + "without signal to be sent\n"); + ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); + + printf("Before calling %s() for the child\n", TWAIT_FNAME); + TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); + + validate_status_exited(status, exitval); + + printf("Before calling %s() for the child\n", TWAIT_FNAME); + TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); +} +#endif + +#if defined(__HAVE_PTRACE_WATCHPOINTS) +ATF_TC(watchpoint_trap_code1); +ATF_TC_HEAD(watchpoint_trap_code1, tc) +{ + atf_tc_set_md_var(tc, "descr", + "Call PT_COUNT_WATCHPOINTS and test code trap with watchpoint 1"); +} + +ATF_TC_BODY(watchpoint_trap_code1, tc) +{ + const int exitval = 5; + const int sigval = SIGSTOP; + pid_t child, wpid; +#if defined(TWAIT_HAVE_STATUS) + int status; +#endif + const int i = 1; + struct ptrace_watchpoint pw; + int len = sizeof(pw); + int watchme = 1234; + + printf("Before forking process PID=%d\n", getpid()); + ATF_REQUIRE((child = fork()) != -1); + if (child == 0) { + printf("Before calling PT_TRACE_ME from child %d\n", getpid()); + FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); + + printf("Before raising %s from child\n", strsignal(sigval)); + FORKEE_ASSERT(raise(sigval) == 0); + + printf("check_happy(%d)=%d\n", watchme, check_happy(watchme)); + + printf("Before exiting of the child process\n"); + _exit(exitval); + } + printf("Parent process PID=%d, child's PID=%d\n", getpid(), child); + + printf("Before calling %s() for the child\n", TWAIT_FNAME); + TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); + + validate_status_stopped(status, sigval); + + printf("Preparing code watchpoint trap %d\n", i); + + pw.pw_index = i; + pw.pw_lwpid = 0; + pw.pw_md.md_address = (void *)check_happy; + pw.pw_md.md_condition = X86_HW_WATCHPOINT_DR7_CONDITION_EXECUTION; + pw.pw_md.md_length = X86_HW_WATCHPOINT_DR7_LENGTH_BYTE; + + printf("struct ptrace {\n"); + printf("\t.pw_index=%d\n", pw.pw_index); + printf("\t.pw_lwpid=%d\n", pw.pw_lwpid); + printf("\t.pw_md.md_address=%p\n", pw.pw_md.md_address); + printf("\t.pw_md.md_condition=%#x\n", pw.pw_md.md_condition); + printf("\t.pw_md.md_length=%#x\n", pw.pw_md.md_length); + printf("}\n"); + + printf("Before writing watchpoint %d\n", i); + ATF_REQUIRE(ptrace(PT_WRITE_WATCHPOINT, child, &pw, len) != -1); + + printf("Before resuming the child process where it left off " + "and without signal to be sent\n"); + ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); + + printf("Before calling %s() for the child\n", TWAIT_FNAME); + TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); + + validate_status_stopped(status, SIGTRAP); + + pw.pw_md.md_address = NULL; + printf("Before writing watchpoint %d (disable it)\n", i); + ATF_REQUIRE(ptrace(PT_WRITE_WATCHPOINT, child, &pw, len) != -1); + + printf("Before resuming the child process where it left off and " + "without signal to be sent\n"); + ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); + + printf("Before calling %s() for the child\n", TWAIT_FNAME); + TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); + + validate_status_exited(status, exitval); + + printf("Before calling %s() for the child\n", TWAIT_FNAME); + TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); +} +#endif + +#if defined(__HAVE_PTRACE_WATCHPOINTS) +ATF_TC(watchpoint_trap_code2); +ATF_TC_HEAD(watchpoint_trap_code2, tc) +{ + atf_tc_set_md_var(tc, "descr", + "Call PT_COUNT_WATCHPOINTS and test code trap with watchpoint 2"); +} + +ATF_TC_BODY(watchpoint_trap_code2, tc) +{ + const int exitval = 5; + const int sigval = SIGSTOP; + pid_t child, wpid; +#if defined(TWAIT_HAVE_STATUS) + int status; +#endif + const int i = 2; + struct ptrace_watchpoint pw; + int len = sizeof(pw); + int watchme = 1234; + + printf("Before forking process PID=%d\n", getpid()); + ATF_REQUIRE((child = fork()) != -1); + if (child == 0) { + printf("Before calling PT_TRACE_ME from child %d\n", getpid()); + FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); + + printf("Before raising %s from child\n", strsignal(sigval)); + FORKEE_ASSERT(raise(sigval) == 0); + + printf("check_happy(%d)=%d\n", watchme, check_happy(watchme)); + + printf("Before exiting of the child process\n"); + _exit(exitval); + } + printf("Parent process PID=%d, child's PID=%d\n", getpid(), child); + + printf("Before calling %s() for the child\n", TWAIT_FNAME); + TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); + + validate_status_stopped(status, sigval); + + printf("Preparing code watchpoint trap %d\n", i); + + pw.pw_index = i; + pw.pw_lwpid = 0; + pw.pw_md.md_address = (void *)check_happy; + pw.pw_md.md_condition = X86_HW_WATCHPOINT_DR7_CONDITION_EXECUTION; + pw.pw_md.md_length = X86_HW_WATCHPOINT_DR7_LENGTH_BYTE; + + printf("struct ptrace {\n"); + printf("\t.pw_index=%d\n", pw.pw_index); + printf("\t.pw_lwpid=%d\n", pw.pw_lwpid); + printf("\t.pw_md.md_address=%p\n", pw.pw_md.md_address); + printf("\t.pw_md.md_condition=%#x\n", pw.pw_md.md_condition); + printf("\t.pw_md.md_length=%#x\n", pw.pw_md.md_length); + printf("}\n"); + + printf("Before writing watchpoint %d\n", i); + ATF_REQUIRE(ptrace(PT_WRITE_WATCHPOINT, child, &pw, len) != -1); + + printf("Before resuming the child process where it left off " + "and without signal to be sent\n"); + ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); + + printf("Before calling %s() for the child\n", TWAIT_FNAME); + TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); + + validate_status_stopped(status, SIGTRAP); + + pw.pw_md.md_address = NULL; + printf("Before writing watchpoint %d (disable it)\n", i); + ATF_REQUIRE(ptrace(PT_WRITE_WATCHPOINT, child, &pw, len) != -1); + + printf("Before resuming the child process where it left off and " + "without signal to be sent\n"); + ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); + + printf("Before calling %s() for the child\n", TWAIT_FNAME); + TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); + + validate_status_exited(status, exitval); + + printf("Before calling %s() for the child\n", TWAIT_FNAME); + TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); +} +#endif + +#if defined(__HAVE_PTRACE_WATCHPOINTS) +ATF_TC(watchpoint_trap_code3); +ATF_TC_HEAD(watchpoint_trap_code3, tc) +{ + atf_tc_set_md_var(tc, "descr", + "Call PT_COUNT_WATCHPOINTS and test code trap with watchpoint 3"); +} + +ATF_TC_BODY(watchpoint_trap_code3, tc) +{ + const int exitval = 5; + const int sigval = SIGSTOP; + pid_t child, wpid; +#if defined(TWAIT_HAVE_STATUS) + int status; +#endif + const int i = 3; + struct ptrace_watchpoint pw; + int len = sizeof(pw); + int watchme = 1234; + + printf("Before forking process PID=%d\n", getpid()); + ATF_REQUIRE((child = fork()) != -1); + if (child == 0) { + printf("Before calling PT_TRACE_ME from child %d\n", getpid()); + FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); + + printf("Before raising %s from child\n", strsignal(sigval)); + FORKEE_ASSERT(raise(sigval) == 0); + + printf("check_happy(%d)=%d\n", watchme, check_happy(watchme)); + + printf("Before exiting of the child process\n"); + _exit(exitval); + } + printf("Parent process PID=%d, child's PID=%d\n", getpid(), child); + + printf("Before calling %s() for the child\n", TWAIT_FNAME); + TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); + + validate_status_stopped(status, sigval); + + printf("Preparing code watchpoint trap %d\n", i); + + pw.pw_index = i; + pw.pw_lwpid = 0; + pw.pw_md.md_address = (void *)check_happy; + pw.pw_md.md_condition = X86_HW_WATCHPOINT_DR7_CONDITION_EXECUTION; + pw.pw_md.md_length = X86_HW_WATCHPOINT_DR7_LENGTH_BYTE; + + printf("struct ptrace {\n"); + printf("\t.pw_index=%d\n", pw.pw_index); + printf("\t.pw_lwpid=%d\n", pw.pw_lwpid); + printf("\t.pw_md.md_address=%p\n", pw.pw_md.md_address); + printf("\t.pw_md.md_condition=%#x\n", pw.pw_md.md_condition); + printf("\t.pw_md.md_length=%#x\n", pw.pw_md.md_length); + printf("}\n"); + + printf("Before writing watchpoint %d\n", i); + ATF_REQUIRE(ptrace(PT_WRITE_WATCHPOINT, child, &pw, len) != -1); + + printf("Before resuming the child process where it left off " + "and without signal to be sent\n"); + ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); + + printf("Before calling %s() for the child\n", TWAIT_FNAME); + TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); + + validate_status_stopped(status, SIGTRAP); + + pw.pw_md.md_address = NULL; + printf("Before writing watchpoint %d (disable it)\n", i); + ATF_REQUIRE(ptrace(PT_WRITE_WATCHPOINT, child, &pw, len) != -1); + + printf("Before resuming the child process where it left off and " + "without signal to be sent\n"); + ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); + + printf("Before calling %s() for the child\n", TWAIT_FNAME); + TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); + + validate_status_exited(status, exitval); + + printf("Before calling %s() for the child\n", TWAIT_FNAME); + TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); +} +#endif + +#if defined(__HAVE_PTRACE_WATCHPOINTS) +ATF_TC(watchpoint_trap_data_write0); +ATF_TC_HEAD(watchpoint_trap_data_write0, tc) +{ + atf_tc_set_md_var(tc, "descr", + "Call PT_COUNT_WATCHPOINTS and test write trap with watchpoint 0"); +} + +ATF_TC_BODY(watchpoint_trap_data_write0, tc) +{ + const int exitval = 5; + const int sigval = SIGSTOP; + pid_t child, wpid; +#if defined(TWAIT_HAVE_STATUS) + int status; +#endif + const int i = 0; + struct ptrace_watchpoint pw; + int len = sizeof(pw); + int watchme = 1234; + + printf("Before forking process PID=%d\n", getpid()); + ATF_REQUIRE((child = fork()) != -1); + if (child == 0) { + printf("Before calling PT_TRACE_ME from child %d\n", getpid()); + FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); + + printf("Before raising %s from child\n", strsignal(sigval)); + FORKEE_ASSERT(raise(sigval) == 0); + + ++watchme; + + printf("Before exiting of the child process\n"); + _exit(exitval); + } + printf("Parent process PID=%d, child's PID=%d\n", getpid(), child); + + printf("Before calling %s() for the child\n", TWAIT_FNAME); + TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); + + validate_status_stopped(status, sigval); + + printf("Preparing code watchpoint trap %d\n", i); + + pw.pw_index = 0; + pw.pw_md.md_address = &watchme; + pw.pw_md.md_condition = X86_HW_WATCHPOINT_DR7_CONDITION_DATA_WRITE; + pw.pw_md.md_length = X86_HW_WATCHPOINT_DR7_LENGTH_BYTE; + + printf("struct ptrace {\n"); + printf("\t.pw_index=%d\n", pw.pw_index); + printf("\t.pw_lwpid=%d\n", pw.pw_lwpid); + printf("\t.pw_md.md_address=%p\n", pw.pw_md.md_address); + printf("\t.pw_md.md_condition=%#x\n", pw.pw_md.md_condition); + printf("\t.pw_md.md_length=%#x\n", pw.pw_md.md_length); + printf("}\n"); + + printf("Before writing watchpoint %d\n", i); + ATF_REQUIRE(ptrace(PT_WRITE_WATCHPOINT, child, &pw, len) != -1); + + printf("Before resuming the child process where it left off " + "and without signal to be sent\n"); + ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); + + printf("Before calling %s() for the child\n", TWAIT_FNAME); + TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); + + validate_status_stopped(status, SIGTRAP); + + printf("Before resuming the child process where it left off and " + "without signal to be sent\n"); + ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); + + printf("Before calling %s() for the child\n", TWAIT_FNAME); + TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); + + validate_status_exited(status, exitval); + + printf("Before calling %s() for the child\n", TWAIT_FNAME); + TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); +} +#endif + +#if defined(__HAVE_PTRACE_WATCHPOINTS) +ATF_TC(watchpoint_trap_data_write1); +ATF_TC_HEAD(watchpoint_trap_data_write1, tc) +{ + atf_tc_set_md_var(tc, "descr", + "Call PT_COUNT_WATCHPOINTS and test write trap with watchpoint 1"); +} + +ATF_TC_BODY(watchpoint_trap_data_write1, tc) +{ + const int exitval = 5; + const int sigval = SIGSTOP; + pid_t child, wpid; +#if defined(TWAIT_HAVE_STATUS) + int status; +#endif + const int i = 1; + struct ptrace_watchpoint pw; + int len = sizeof(pw); + int watchme = 1234; + + printf("Before forking process PID=%d\n", getpid()); + ATF_REQUIRE((child = fork()) != -1); + if (child == 0) { + printf("Before calling PT_TRACE_ME from child %d\n", getpid()); + FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); + + printf("Before raising %s from child\n", strsignal(sigval)); + FORKEE_ASSERT(raise(sigval) == 0); + + ++watchme; + + printf("Before exiting of the child process\n"); + _exit(exitval); + } + printf("Parent process PID=%d, child's PID=%d\n", getpid(), child); + + printf("Before calling %s() for the child\n", TWAIT_FNAME); + TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); + + validate_status_stopped(status, sigval); + + printf("Preparing code watchpoint trap %d\n", i); + + pw.pw_index = i; + pw.pw_md.md_address = &watchme; + pw.pw_md.md_condition = X86_HW_WATCHPOINT_DR7_CONDITION_DATA_WRITE; + pw.pw_md.md_length = X86_HW_WATCHPOINT_DR7_LENGTH_BYTE; + + printf("struct ptrace {\n"); + printf("\t.pw_index=%d\n", pw.pw_index); + printf("\t.pw_lwpid=%d\n", pw.pw_lwpid); + printf("\t.pw_md.md_address=%p\n", pw.pw_md.md_address); + printf("\t.pw_md.md_condition=%#x\n", pw.pw_md.md_condition); + printf("\t.pw_md.md_length=%#x\n", pw.pw_md.md_length); + printf("}\n"); + + printf("Before writing watchpoint %d\n", i); + ATF_REQUIRE(ptrace(PT_WRITE_WATCHPOINT, child, &pw, len) != -1); + + printf("Before resuming the child process where it left off " + "and without signal to be sent\n"); + ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); + + printf("Before calling %s() for the child\n", TWAIT_FNAME); + TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); + + validate_status_stopped(status, SIGTRAP); + + printf("Before resuming the child process where it left off and " + "without signal to be sent\n"); + ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); + + printf("Before calling %s() for the child\n", TWAIT_FNAME); + TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); + + validate_status_exited(status, exitval); + + printf("Before calling %s() for the child\n", TWAIT_FNAME); + TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); +} +#endif + +#if defined(__HAVE_PTRACE_WATCHPOINTS) +ATF_TC(watchpoint_trap_data_write2); +ATF_TC_HEAD(watchpoint_trap_data_write2, tc) +{ + atf_tc_set_md_var(tc, "descr", + "Call PT_COUNT_WATCHPOINTS and test write trap with watchpoint 2"); +} + +ATF_TC_BODY(watchpoint_trap_data_write2, tc) +{ + const int exitval = 5; + const int sigval = SIGSTOP; + pid_t child, wpid; +#if defined(TWAIT_HAVE_STATUS) + int status; +#endif + const int i = 2; + struct ptrace_watchpoint pw; + int len = sizeof(pw); + int watchme = 1234; + + printf("Before forking process PID=%d\n", getpid()); + ATF_REQUIRE((child = fork()) != -1); + if (child == 0) { + printf("Before calling PT_TRACE_ME from child %d\n", getpid()); + FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); + + printf("Before raising %s from child\n", strsignal(sigval)); + FORKEE_ASSERT(raise(sigval) == 0); + + ++watchme; + + printf("Before exiting of the child process\n"); + _exit(exitval); + } + printf("Parent process PID=%d, child's PID=%d\n", getpid(), child); + + printf("Before calling %s() for the child\n", TWAIT_FNAME); + TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); + + validate_status_stopped(status, sigval); + + printf("Preparing code watchpoint trap %d\n", i); + + pw.pw_index = i; + pw.pw_md.md_address = &watchme; + pw.pw_md.md_condition = X86_HW_WATCHPOINT_DR7_CONDITION_DATA_WRITE; + pw.pw_md.md_length = X86_HW_WATCHPOINT_DR7_LENGTH_BYTE; + + printf("struct ptrace {\n"); + printf("\t.pw_index=%d\n", pw.pw_index); + printf("\t.pw_lwpid=%d\n", pw.pw_lwpid); + printf("\t.pw_md.md_address=%p\n", pw.pw_md.md_address); + printf("\t.pw_md.md_condition=%#x\n", pw.pw_md.md_condition); + printf("\t.pw_md.md_length=%#x\n", pw.pw_md.md_length); + printf("}\n"); + + printf("Before writing watchpoint %d\n", i); + ATF_REQUIRE(ptrace(PT_WRITE_WATCHPOINT, child, &pw, len) != -1); + + printf("Before resuming the child process where it left off " + "and without signal to be sent\n"); + ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); + + printf("Before calling %s() for the child\n", TWAIT_FNAME); + TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); + + validate_status_stopped(status, SIGTRAP); + + printf("Before resuming the child process where it left off and " + "without signal to be sent\n"); + ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); + + printf("Before calling %s() for the child\n", TWAIT_FNAME); + TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); + + validate_status_exited(status, exitval); + + printf("Before calling %s() for the child\n", TWAIT_FNAME); + TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); +} +#endif + + +#if defined(__HAVE_PTRACE_WATCHPOINTS) +ATF_TC(watchpoint_trap_data_write3); +ATF_TC_HEAD(watchpoint_trap_data_write3, tc) +{ + atf_tc_set_md_var(tc, "descr", + "Call PT_COUNT_WATCHPOINTS and test write trap with watchpoint 3"); +} + +ATF_TC_BODY(watchpoint_trap_data_write3, tc) +{ + const int exitval = 5; + const int sigval = SIGSTOP; + pid_t child, wpid; +#if defined(TWAIT_HAVE_STATUS) + int status; +#endif + const int i = 3; + struct ptrace_watchpoint pw; + int len = sizeof(pw); + int watchme = 1234; + + printf("Before forking process PID=%d\n", getpid()); + ATF_REQUIRE((child = fork()) != -1); + if (child == 0) { + printf("Before calling PT_TRACE_ME from child %d\n", getpid()); + FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); + + printf("Before raising %s from child\n", strsignal(sigval)); + FORKEE_ASSERT(raise(sigval) == 0); + + ++watchme; + + printf("Before exiting of the child process\n"); + _exit(exitval); + } + printf("Parent process PID=%d, child's PID=%d\n", getpid(), child); + + printf("Before calling %s() for the child\n", TWAIT_FNAME); + TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); + + validate_status_stopped(status, sigval); + + printf("Preparing code watchpoint trap %d\n", i); + + pw.pw_index = i; + pw.pw_md.md_address = &watchme; + pw.pw_md.md_condition = X86_HW_WATCHPOINT_DR7_CONDITION_DATA_WRITE; + pw.pw_md.md_length = X86_HW_WATCHPOINT_DR7_LENGTH_BYTE; + + printf("struct ptrace {\n"); + printf("\t.pw_index=%d\n", pw.pw_index); + printf("\t.pw_lwpid=%d\n", pw.pw_lwpid); + printf("\t.pw_md.md_address=%p\n", pw.pw_md.md_address); + printf("\t.pw_md.md_condition=%#x\n", pw.pw_md.md_condition); + printf("\t.pw_md.md_length=%#x\n", pw.pw_md.md_length); + printf("}\n"); + + printf("Before writing watchpoint %d\n", i); + ATF_REQUIRE(ptrace(PT_WRITE_WATCHPOINT, child, &pw, len) != -1); + + printf("Before resuming the child process where it left off " + "and without signal to be sent\n"); + ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); + + printf("Before calling %s() for the child\n", TWAIT_FNAME); + TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); + + validate_status_stopped(status, SIGTRAP); + + printf("Before resuming the child process where it left off and " + "without signal to be sent\n"); + ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); + + printf("Before calling %s() for the child\n", TWAIT_FNAME); + TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); + + validate_status_exited(status, exitval); + + printf("Before calling %s() for the child\n", TWAIT_FNAME); + TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); +} +#endif + +#if defined(__HAVE_PTRACE_WATCHPOINTS) +ATF_TC(watchpoint_trap_data_rw0); +ATF_TC_HEAD(watchpoint_trap_data_rw0, tc) +{ + atf_tc_set_md_var(tc, "descr", + "Call PT_COUNT_WATCHPOINTS and test write trap with watchpoint 0"); +} + +ATF_TC_BODY(watchpoint_trap_data_rw0, tc) +{ + const int exitval = 5; + const int sigval = SIGSTOP; + pid_t child, wpid; +#if defined(TWAIT_HAVE_STATUS) + int status; +#endif + const int i = 0; + struct ptrace_watchpoint pw; + int len = sizeof(pw); + int watchme = 1234; + + printf("Before forking process PID=%d\n", getpid()); + ATF_REQUIRE((child = fork()) != -1); + if (child == 0) { + printf("Before calling PT_TRACE_ME from child %d\n", getpid()); + FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); + + printf("Before raising %s from child\n", strsignal(sigval)); + FORKEE_ASSERT(raise(sigval) == 0); + + printf("watchme=%d\n", watchme); + + printf("Before exiting of the child process\n"); + _exit(exitval); + } + printf("Parent process PID=%d, child's PID=%d\n", getpid(), child); + + printf("Before calling %s() for the child\n", TWAIT_FNAME); + TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); + + validate_status_stopped(status, sigval); + + printf("Preparing code watchpoint trap %d\n", i); + + pw.pw_index = i; + pw.pw_md.md_address = &watchme; + pw.pw_md.md_condition = X86_HW_WATCHPOINT_DR7_CONDITION_DATA_READWRITE; + pw.pw_md.md_length = X86_HW_WATCHPOINT_DR7_LENGTH_BYTE; + + printf("struct ptrace {\n"); + printf("\t.pw_index=%d\n", pw.pw_index); + printf("\t.pw_lwpid=%d\n", pw.pw_lwpid); + printf("\t.pw_md.md_address=%p\n", pw.pw_md.md_address); + printf("\t.pw_md.md_condition=%#x\n", pw.pw_md.md_condition); + printf("\t.pw_md.md_length=%#x\n", pw.pw_md.md_length); + printf("}\n"); + + printf("Before writing watchpoint %d\n", i); + ATF_REQUIRE(ptrace(PT_WRITE_WATCHPOINT, child, &pw, len) != -1); + + printf("Before resuming the child process where it left off " + "and without signal to be sent\n"); + ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); + + printf("Before calling %s() for the child\n", TWAIT_FNAME); + TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); + + validate_status_stopped(status, SIGTRAP); + + printf("Before resuming the child process where it left off and " + "without signal to be sent\n"); + ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); + + printf("Before calling %s() for the child\n", TWAIT_FNAME); + TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); + + validate_status_exited(status, exitval); + + printf("Before calling %s() for the child\n", TWAIT_FNAME); + TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); +} +#endif + +#if defined(__HAVE_PTRACE_WATCHPOINTS) +ATF_TC(watchpoint_trap_data_rw1); +ATF_TC_HEAD(watchpoint_trap_data_rw1, tc) +{ + atf_tc_set_md_var(tc, "descr", + "Call PT_COUNT_WATCHPOINTS and test write trap with watchpoint 1"); +} + +ATF_TC_BODY(watchpoint_trap_data_rw1, tc) +{ + const int exitval = 5; + const int sigval = SIGSTOP; + pid_t child, wpid; +#if defined(TWAIT_HAVE_STATUS) + int status; +#endif + const int i = 1; + struct ptrace_watchpoint pw; + int len = sizeof(pw); + int watchme = 1234; + + printf("Before forking process PID=%d\n", getpid()); + ATF_REQUIRE((child = fork()) != -1); + if (child == 0) { + printf("Before calling PT_TRACE_ME from child %d\n", getpid()); + FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); + + printf("Before raising %s from child\n", strsignal(sigval)); + FORKEE_ASSERT(raise(sigval) == 0); + + printf("watchme=%d\n", watchme); + + printf("Before exiting of the child process\n"); + _exit(exitval); + } + printf("Parent process PID=%d, child's PID=%d\n", getpid(), child); + + printf("Before calling %s() for the child\n", TWAIT_FNAME); + TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); + + validate_status_stopped(status, sigval); + + printf("Preparing code watchpoint trap %d\n", i); + + pw.pw_index = i; + pw.pw_md.md_address = &watchme; + pw.pw_md.md_condition = X86_HW_WATCHPOINT_DR7_CONDITION_DATA_READWRITE; + pw.pw_md.md_length = X86_HW_WATCHPOINT_DR7_LENGTH_BYTE; + + printf("struct ptrace {\n"); + printf("\t.pw_index=%d\n", pw.pw_index); + printf("\t.pw_lwpid=%d\n", pw.pw_lwpid); + printf("\t.pw_md.md_address=%p\n", pw.pw_md.md_address); + printf("\t.pw_md.md_condition=%#x\n", pw.pw_md.md_condition); + printf("\t.pw_md.md_length=%#x\n", pw.pw_md.md_length); + printf("}\n"); + + printf("Before writing watchpoint %d\n", i); + ATF_REQUIRE(ptrace(PT_WRITE_WATCHPOINT, child, &pw, len) != -1); + + printf("Before resuming the child process where it left off " + "and without signal to be sent\n"); + ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); + + printf("Before calling %s() for the child\n", TWAIT_FNAME); + TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); + + validate_status_stopped(status, SIGTRAP); + + printf("Before resuming the child process where it left off and " + "without signal to be sent\n"); + ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); + + printf("Before calling %s() for the child\n", TWAIT_FNAME); + TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); + + validate_status_exited(status, exitval); + + printf("Before calling %s() for the child\n", TWAIT_FNAME); + TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); +} +#endif + +#if defined(__HAVE_PTRACE_WATCHPOINTS) +ATF_TC(watchpoint_trap_data_rw2); +ATF_TC_HEAD(watchpoint_trap_data_rw2, tc) +{ + atf_tc_set_md_var(tc, "descr", + "Call PT_COUNT_WATCHPOINTS and test write trap with watchpoint 2"); +} + +ATF_TC_BODY(watchpoint_trap_data_rw2, tc) +{ + const int exitval = 5; + const int sigval = SIGSTOP; + pid_t child, wpid; +#if defined(TWAIT_HAVE_STATUS) + int status; +#endif + const int i = 2; + struct ptrace_watchpoint pw; + int len = sizeof(pw); + int watchme = 1234; + + printf("Before forking process PID=%d\n", getpid()); + ATF_REQUIRE((child = fork()) != -1); + if (child == 0) { + printf("Before calling PT_TRACE_ME from child %d\n", getpid()); + FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); + + printf("Before raising %s from child\n", strsignal(sigval)); + FORKEE_ASSERT(raise(sigval) == 0); + + printf("watchme=%d\n", watchme); + + printf("Before exiting of the child process\n"); + _exit(exitval); + } + printf("Parent process PID=%d, child's PID=%d\n", getpid(), child); + + printf("Before calling %s() for the child\n", TWAIT_FNAME); + TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); + + validate_status_stopped(status, sigval); + + printf("Preparing code watchpoint trap %d\n", i); + + pw.pw_index = i; + pw.pw_md.md_address = &watchme; + pw.pw_md.md_condition = X86_HW_WATCHPOINT_DR7_CONDITION_DATA_READWRITE; + pw.pw_md.md_length = X86_HW_WATCHPOINT_DR7_LENGTH_BYTE; + + printf("struct ptrace {\n"); + printf("\t.pw_index=%d\n", pw.pw_index); + printf("\t.pw_lwpid=%d\n", pw.pw_lwpid); + printf("\t.pw_md.md_address=%p\n", pw.pw_md.md_address); + printf("\t.pw_md.md_condition=%#x\n", pw.pw_md.md_condition); + printf("\t.pw_md.md_length=%#x\n", pw.pw_md.md_length); + printf("}\n"); + + printf("Before writing watchpoint %d\n", i); + ATF_REQUIRE(ptrace(PT_WRITE_WATCHPOINT, child, &pw, len) != -1); + + printf("Before resuming the child process where it left off " + "and without signal to be sent\n"); + ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); + + printf("Before calling %s() for the child\n", TWAIT_FNAME); + TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); + + validate_status_stopped(status, SIGTRAP); + + printf("Before resuming the child process where it left off and " + "without signal to be sent\n"); + ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); + + printf("Before calling %s() for the child\n", TWAIT_FNAME); + TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); + + validate_status_exited(status, exitval); + + printf("Before calling %s() for the child\n", TWAIT_FNAME); + TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); +} +#endif + +#if defined(__HAVE_PTRACE_WATCHPOINTS) +ATF_TC(watchpoint_trap_data_rw3); +ATF_TC_HEAD(watchpoint_trap_data_rw3, tc) +{ + atf_tc_set_md_var(tc, "descr", + "Call PT_COUNT_WATCHPOINTS and test write trap with watchpoint 3"); +} + +ATF_TC_BODY(watchpoint_trap_data_rw3, tc) +{ + const int exitval = 5; + const int sigval = SIGSTOP; + pid_t child, wpid; +#if defined(TWAIT_HAVE_STATUS) + int status; +#endif + const int i = 3; + struct ptrace_watchpoint pw; + int len = sizeof(pw); + int watchme = 1234; + + printf("Before forking process PID=%d\n", getpid()); + ATF_REQUIRE((child = fork()) != -1); + if (child == 0) { + printf("Before calling PT_TRACE_ME from child %d\n", getpid()); + FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); + + printf("Before raising %s from child\n", strsignal(sigval)); + FORKEE_ASSERT(raise(sigval) == 0); + + printf("watchme=%d\n", watchme); + + printf("Before exiting of the child process\n"); + _exit(exitval); + } + printf("Parent process PID=%d, child's PID=%d\n", getpid(), child); + + printf("Before calling %s() for the child\n", TWAIT_FNAME); + TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); + + validate_status_stopped(status, sigval); + + printf("Preparing code watchpoint trap %d\n", i); + + pw.pw_index = i; + pw.pw_md.md_address = &watchme; + pw.pw_md.md_condition = X86_HW_WATCHPOINT_DR7_CONDITION_DATA_READWRITE; + pw.pw_md.md_length = X86_HW_WATCHPOINT_DR7_LENGTH_BYTE; + + printf("struct ptrace {\n"); + printf("\t.pw_index=%d\n", pw.pw_index); + printf("\t.pw_lwpid=%d\n", pw.pw_lwpid); + printf("\t.pw_md.md_address=%p\n", pw.pw_md.md_address); + printf("\t.pw_md.md_condition=%#x\n", pw.pw_md.md_condition); + printf("\t.pw_md.md_length=%#x\n", pw.pw_md.md_length); + printf("}\n"); + + printf("Before writing watchpoint %d\n", i); + ATF_REQUIRE(ptrace(PT_WRITE_WATCHPOINT, child, &pw, len) != -1); + + printf("Before resuming the child process where it left off " + "and without signal to be sent\n"); + ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); + + printf("Before calling %s() for the child\n", TWAIT_FNAME); + TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); + + validate_status_stopped(status, SIGTRAP); + + printf("Before resuming the child process where it left off and " + "without signal to be sent\n"); + ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); + + printf("Before calling %s() for the child\n", TWAIT_FNAME); + TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); + + validate_status_exited(status, exitval); + + printf("Before calling %s() for the child\n", TWAIT_FNAME); + TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); +} +#endif + +ATF_TP_ADD_TCS(tp) +{ + setvbuf(stdout, NULL, _IONBF, 0); + setvbuf(stderr, NULL, _IONBF, 0); + + ATF_TP_ADD_TC_HAVE_GPREGS(tp, regs1); + + ATF_TP_ADD_TC_HAVE_PTRACE_WATCHPOINTS(tp, watchpoint_count); + ATF_TP_ADD_TC_HAVE_PTRACE_WATCHPOINTS(tp, watchpoint_read); + ATF_TP_ADD_TC_HAVE_PTRACE_WATCHPOINTS(tp, watchpoint_write_unmodified); + ATF_TP_ADD_TC_HAVE_PTRACE_WATCHPOINTS(tp, watchpoint_trap_code0); + ATF_TP_ADD_TC_HAVE_PTRACE_WATCHPOINTS(tp, watchpoint_trap_code1); + ATF_TP_ADD_TC_HAVE_PTRACE_WATCHPOINTS(tp, watchpoint_trap_code2); + ATF_TP_ADD_TC_HAVE_PTRACE_WATCHPOINTS(tp, watchpoint_trap_code3); + ATF_TP_ADD_TC_HAVE_PTRACE_WATCHPOINTS(tp, watchpoint_trap_data_write0); + ATF_TP_ADD_TC_HAVE_PTRACE_WATCHPOINTS(tp, watchpoint_trap_data_write1); + ATF_TP_ADD_TC_HAVE_PTRACE_WATCHPOINTS(tp, watchpoint_trap_data_write2); + ATF_TP_ADD_TC_HAVE_PTRACE_WATCHPOINTS(tp, watchpoint_trap_data_write3); + ATF_TP_ADD_TC_HAVE_PTRACE_WATCHPOINTS(tp, watchpoint_trap_data_rw0); + ATF_TP_ADD_TC_HAVE_PTRACE_WATCHPOINTS(tp, watchpoint_trap_data_rw1); + ATF_TP_ADD_TC_HAVE_PTRACE_WATCHPOINTS(tp, watchpoint_trap_data_rw2); + ATF_TP_ADD_TC_HAVE_PTRACE_WATCHPOINTS(tp, watchpoint_trap_data_rw3); + + return atf_no_error(); +} diff --git a/contrib/netbsd-tests/kernel/arch/amd64/t_ptrace_wait3.c b/contrib/netbsd-tests/kernel/arch/amd64/t_ptrace_wait3.c new file mode 100644 index 000000000000..c5dfe7358738 --- /dev/null +++ b/contrib/netbsd-tests/kernel/arch/amd64/t_ptrace_wait3.c @@ -0,0 +1,30 @@ +/* $NetBSD: t_ptrace_wait3.c,v 1.1 2016/12/02 05:54:15 kamil Exp $ */ + +/*- + * Copyright (c) 2016 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. + */ + +#define TWAIT_WAIT3 +#include "t_ptrace_wait.c" diff --git a/contrib/netbsd-tests/kernel/arch/amd64/t_ptrace_wait4.c b/contrib/netbsd-tests/kernel/arch/amd64/t_ptrace_wait4.c new file mode 100644 index 000000000000..7e1fed95ee62 --- /dev/null +++ b/contrib/netbsd-tests/kernel/arch/amd64/t_ptrace_wait4.c @@ -0,0 +1,30 @@ +/* $NetBSD: t_ptrace_wait4.c,v 1.1 2016/12/02 05:54:15 kamil Exp $ */ + +/*- + * Copyright (c) 2016 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. + */ + +#define TWAIT_WAIT4 +#include "t_ptrace_wait.c" diff --git a/contrib/netbsd-tests/kernel/arch/amd64/t_ptrace_wait6.c b/contrib/netbsd-tests/kernel/arch/amd64/t_ptrace_wait6.c new file mode 100644 index 000000000000..601efe3f3d62 --- /dev/null +++ b/contrib/netbsd-tests/kernel/arch/amd64/t_ptrace_wait6.c @@ -0,0 +1,30 @@ +/* $NetBSD: t_ptrace_wait6.c,v 1.1 2016/12/02 05:54:15 kamil Exp $ */ + +/*- + * Copyright (c) 2016 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. + */ + +#define TWAIT_WAIT6 +#include "t_ptrace_wait.c" diff --git a/contrib/netbsd-tests/kernel/arch/amd64/t_ptrace_waitid.c b/contrib/netbsd-tests/kernel/arch/amd64/t_ptrace_waitid.c new file mode 100644 index 000000000000..5ec17a9b8d24 --- /dev/null +++ b/contrib/netbsd-tests/kernel/arch/amd64/t_ptrace_waitid.c @@ -0,0 +1,30 @@ +/* $NetBSD: t_ptrace_waitid.c,v 1.1 2016/12/02 05:54:15 kamil Exp $ */ + +/*- + * Copyright (c) 2016 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. + */ + +#define TWAIT_WAITID +#include "t_ptrace_wait.c" diff --git a/contrib/netbsd-tests/kernel/arch/amd64/t_ptrace_waitpid.c b/contrib/netbsd-tests/kernel/arch/amd64/t_ptrace_waitpid.c new file mode 100644 index 000000000000..78b341c111f3 --- /dev/null +++ b/contrib/netbsd-tests/kernel/arch/amd64/t_ptrace_waitpid.c @@ -0,0 +1,30 @@ +/* $NetBSD: t_ptrace_waitpid.c,v 1.1 2016/12/02 05:54:15 kamil Exp $ */ + +/*- + * Copyright (c) 2016 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. + */ + +#define TWAIT_WAITPID +#include "t_ptrace_wait.c" diff --git a/contrib/netbsd-tests/kernel/arch/i386/t_ptrace_wait.c b/contrib/netbsd-tests/kernel/arch/i386/t_ptrace_wait.c new file mode 100644 index 000000000000..698573bb0985 --- /dev/null +++ b/contrib/netbsd-tests/kernel/arch/i386/t_ptrace_wait.c @@ -0,0 +1,141 @@ +/* $NetBSD: t_ptrace_wait.c,v 1.2 2017/01/13 21:30:41 christos Exp $ */ + +/*- + * Copyright (c) 2016 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. + */ + +#include +__RCSID("$NetBSD: t_ptrace_wait.c,v 1.2 2017/01/13 21:30:41 christos Exp $"); + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "h_macros.h" + +#include "../../t_ptrace_wait.h" + + +#if defined(HAVE_GPREGS) +ATF_TC(regs1); +ATF_TC_HEAD(regs1, tc) +{ + atf_tc_set_md_var(tc, "descr", + "Call PT_GETREGS and iterate over General Purpose registers"); +} + +ATF_TC_BODY(regs1, tc) +{ + const int exitval = 5; + const int sigval = SIGSTOP; + pid_t child, wpid; +#if defined(TWAIT_HAVE_STATUS) + int status; +#endif + struct reg r; + + printf("Before forking process PID=%d\n", getpid()); + ATF_REQUIRE((child = fork()) != -1); + if (child == 0) { + printf("Before calling PT_TRACE_ME from child %d\n", getpid()); + FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); + + printf("Before raising %s from child\n", strsignal(sigval)); + FORKEE_ASSERT(raise(sigval) == 0); + + printf("Before exiting of the child process\n"); + _exit(exitval); + } + printf("Parent process PID=%d, child's PID=%d\n", getpid(), child); + + printf("Before calling %s() for the child\n", TWAIT_FNAME); + TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); + + validate_status_stopped(status, sigval); + + printf("Call GETREGS for the child process\n"); + ATF_REQUIRE(ptrace(PT_GETREGS, child, &r, 0) != -1); + + printf("EAX=%#" PRIxREGISTER "\n", r.r_eax); + printf("EBX=%#" PRIxREGISTER "\n", r.r_ebx); + printf("ECX=%#" PRIxREGISTER "\n", r.r_ecx); + printf("EDX=%#" PRIxREGISTER "\n", r.r_edx); + + printf("ESP=%#" PRIxREGISTER "\n", r.r_esp); + printf("EBP=%#" PRIxREGISTER "\n", r.r_ebp); + + printf("ESI=%#" PRIxREGISTER "\n", r.r_esi); + printf("EDI=%#" PRIxREGISTER "\n", r.r_edi); + + printf("EIP=%#" PRIxREGISTER "\n", r.r_eip); + + printf("EFLAGS=%#" PRIxREGISTER "\n", r.r_eflags); + + printf("CS=%#" PRIxREGISTER "\n", r.r_cs); + printf("SS=%#" PRIxREGISTER "\n", r.r_ss); + printf("DS=%#" PRIxREGISTER "\n", r.r_ds); + printf("ES=%#" PRIxREGISTER "\n", r.r_es); + printf("FS=%#" PRIxREGISTER "\n", r.r_fs); + printf("GS=%#" PRIxREGISTER "\n", r.r_gs); + + printf("Before resuming the child process where it left off and " + "without signal to be sent\n"); + ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); + + printf("Before calling %s() for the child\n", TWAIT_FNAME); + TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); + + validate_status_exited(status, exitval); + + printf("Before calling %s() for the child\n", TWAIT_FNAME); + TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); +} +#endif + +ATF_TP_ADD_TCS(tp) +{ + setvbuf(stdout, NULL, _IONBF, 0); + setvbuf(stderr, NULL, _IONBF, 0); + + ATF_TP_ADD_TC_HAVE_GPREGS(tp, regs1); + + return atf_no_error(); +} diff --git a/contrib/netbsd-tests/kernel/arch/i386/t_ptrace_wait3.c b/contrib/netbsd-tests/kernel/arch/i386/t_ptrace_wait3.c new file mode 100644 index 000000000000..56dda8e6978d --- /dev/null +++ b/contrib/netbsd-tests/kernel/arch/i386/t_ptrace_wait3.c @@ -0,0 +1,30 @@ +/* $NetBSD: t_ptrace_wait3.c,v 1.1 2016/12/13 18:00:10 kamil Exp $ */ + +/*- + * Copyright (c) 2016 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. + */ + +#define TWAIT_WAIT3 +#include "t_ptrace_wait.c" diff --git a/contrib/netbsd-tests/kernel/arch/i386/t_ptrace_wait4.c b/contrib/netbsd-tests/kernel/arch/i386/t_ptrace_wait4.c new file mode 100644 index 000000000000..5fbdb53503b9 --- /dev/null +++ b/contrib/netbsd-tests/kernel/arch/i386/t_ptrace_wait4.c @@ -0,0 +1,30 @@ +/* $NetBSD: t_ptrace_wait4.c,v 1.1 2016/12/13 18:00:10 kamil Exp $ */ + +/*- + * Copyright (c) 2016 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. + */ + +#define TWAIT_WAIT4 +#include "t_ptrace_wait.c" diff --git a/contrib/netbsd-tests/kernel/arch/i386/t_ptrace_wait6.c b/contrib/netbsd-tests/kernel/arch/i386/t_ptrace_wait6.c new file mode 100644 index 000000000000..117c844123c9 --- /dev/null +++ b/contrib/netbsd-tests/kernel/arch/i386/t_ptrace_wait6.c @@ -0,0 +1,30 @@ +/* $NetBSD: t_ptrace_wait6.c,v 1.1 2016/12/13 18:00:10 kamil Exp $ */ + +/*- + * Copyright (c) 2016 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. + */ + +#define TWAIT_WAIT6 +#include "t_ptrace_wait.c" diff --git a/contrib/netbsd-tests/kernel/arch/i386/t_ptrace_waitid.c b/contrib/netbsd-tests/kernel/arch/i386/t_ptrace_waitid.c new file mode 100644 index 000000000000..274e8bd9f19c --- /dev/null +++ b/contrib/netbsd-tests/kernel/arch/i386/t_ptrace_waitid.c @@ -0,0 +1,30 @@ +/* $NetBSD: t_ptrace_waitid.c,v 1.1 2016/12/13 18:00:10 kamil Exp $ */ + +/*- + * Copyright (c) 2016 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. + */ + +#define TWAIT_WAITID +#include "t_ptrace_wait.c" diff --git a/contrib/netbsd-tests/kernel/arch/i386/t_ptrace_waitpid.c b/contrib/netbsd-tests/kernel/arch/i386/t_ptrace_waitpid.c new file mode 100644 index 000000000000..2fe5c570f9f7 --- /dev/null +++ b/contrib/netbsd-tests/kernel/arch/i386/t_ptrace_waitpid.c @@ -0,0 +1,30 @@ +/* $NetBSD: t_ptrace_waitpid.c,v 1.1 2016/12/13 18:00:10 kamil Exp $ */ + +/*- + * Copyright (c) 2016 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. + */ + +#define TWAIT_WAITPID +#include "t_ptrace_wait.c" diff --git a/contrib/netbsd-tests/kernel/kqueue/read/t_fifo.c b/contrib/netbsd-tests/kernel/kqueue/read/t_fifo.c index 19c7b02ea325..1f40ada392a5 100644 --- a/contrib/netbsd-tests/kernel/kqueue/read/t_fifo.c +++ b/contrib/netbsd-tests/kernel/kqueue/read/t_fifo.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_fifo.c,v 1.3 2010/11/07 17:51:20 jmmv Exp $ */ +/* $NetBSD: t_fifo.c,v 1.4 2017/01/13 21:30:41 christos Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -32,7 +32,7 @@ #include __COPYRIGHT("@(#) Copyright (c) 2008\ The NetBSD Foundation, inc. All rights reserved."); -__RCSID("$NetBSD: t_fifo.c,v 1.3 2010/11/07 17:51:20 jmmv Exp $"); +__RCSID("$NetBSD: t_fifo.c,v 1.4 2017/01/13 21:30:41 christos Exp $"); #include #include @@ -46,7 +46,7 @@ __RCSID("$NetBSD: t_fifo.c,v 1.3 2010/11/07 17:51:20 jmmv Exp $"); #include -#include "../../../h_macros.h" +#include "h_macros.h" #define FIFONAME "fifo" diff --git a/contrib/netbsd-tests/kernel/kqueue/read/t_file.c b/contrib/netbsd-tests/kernel/kqueue/read/t_file.c index 80479afc7f7e..f4669d24a09a 100644 --- a/contrib/netbsd-tests/kernel/kqueue/read/t_file.c +++ b/contrib/netbsd-tests/kernel/kqueue/read/t_file.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_file.c,v 1.3 2010/11/07 17:51:20 jmmv Exp $ */ +/* $NetBSD: t_file.c,v 1.4 2017/01/13 21:30:41 christos Exp $ */ /*- * Copyright (c) 2002, 2008 The NetBSD Foundation, Inc. @@ -32,7 +32,7 @@ #include __COPYRIGHT("@(#) Copyright (c) 2008\ The NetBSD Foundation, inc. All rights reserved."); -__RCSID("$NetBSD: t_file.c,v 1.3 2010/11/07 17:51:20 jmmv Exp $"); +__RCSID("$NetBSD: t_file.c,v 1.4 2017/01/13 21:30:41 christos Exp $"); #include #include @@ -50,7 +50,7 @@ __RCSID("$NetBSD: t_file.c,v 1.3 2010/11/07 17:51:20 jmmv Exp $"); #include -#include "../../../h_macros.h" +#include "h_macros.h" #define FILENAME "file" #define NLINES 5 diff --git a/contrib/netbsd-tests/kernel/kqueue/read/t_file2.c b/contrib/netbsd-tests/kernel/kqueue/read/t_file2.c index c77d2830e93d..733caebbf1e4 100644 --- a/contrib/netbsd-tests/kernel/kqueue/read/t_file2.c +++ b/contrib/netbsd-tests/kernel/kqueue/read/t_file2.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_file2.c,v 1.3 2010/11/07 17:51:20 jmmv Exp $ */ +/* $NetBSD: t_file2.c,v 1.4 2017/01/13 21:30:41 christos Exp $ */ /*- * Copyright (c) 2002, 2008 The NetBSD Foundation, Inc. @@ -32,7 +32,7 @@ #include __COPYRIGHT("@(#) Copyright (c) 2008\ The NetBSD Foundation, inc. All rights reserved."); -__RCSID("$NetBSD: t_file2.c,v 1.3 2010/11/07 17:51:20 jmmv Exp $"); +__RCSID("$NetBSD: t_file2.c,v 1.4 2017/01/13 21:30:41 christos Exp $"); #include @@ -41,7 +41,7 @@ __RCSID("$NetBSD: t_file2.c,v 1.3 2010/11/07 17:51:20 jmmv Exp $"); #include -#include "../../../h_macros.h" +#include "h_macros.h" ATF_TC(file2); ATF_TC_HEAD(file2, tc) diff --git a/contrib/netbsd-tests/kernel/kqueue/read/t_pipe.c b/contrib/netbsd-tests/kernel/kqueue/read/t_pipe.c index 2cdd0159341c..56cb037e9529 100644 --- a/contrib/netbsd-tests/kernel/kqueue/read/t_pipe.c +++ b/contrib/netbsd-tests/kernel/kqueue/read/t_pipe.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_pipe.c,v 1.1 2009/02/20 21:39:57 jmmv Exp $ */ +/* $NetBSD: t_pipe.c,v 1.2 2017/01/13 21:30:41 christos Exp $ */ /*- * Copyright (c) 2002, 2008 The NetBSD Foundation, Inc. @@ -32,7 +32,7 @@ #include __COPYRIGHT("@(#) Copyright (c) 2008\ The NetBSD Foundation, inc. All rights reserved."); -__RCSID("$NetBSD: t_pipe.c,v 1.1 2009/02/20 21:39:57 jmmv Exp $"); +__RCSID("$NetBSD: t_pipe.c,v 1.2 2017/01/13 21:30:41 christos Exp $"); #include @@ -41,7 +41,7 @@ __RCSID("$NetBSD: t_pipe.c,v 1.1 2009/02/20 21:39:57 jmmv Exp $"); #include -#include "../../../h_macros.h" +#include "h_macros.h" ATF_TC(pipe); ATF_TC_HEAD(pipe, tc) diff --git a/contrib/netbsd-tests/kernel/kqueue/read/t_ttypty.c b/contrib/netbsd-tests/kernel/kqueue/read/t_ttypty.c index 57ccf9256251..37038299956a 100644 --- a/contrib/netbsd-tests/kernel/kqueue/read/t_ttypty.c +++ b/contrib/netbsd-tests/kernel/kqueue/read/t_ttypty.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_ttypty.c,v 1.1 2009/02/20 21:39:57 jmmv Exp $ */ +/* $NetBSD: t_ttypty.c,v 1.2 2017/01/13 21:30:41 christos Exp $ */ /*- * Copyright (c) 2002, 2008 The NetBSD Foundation, Inc. @@ -32,7 +32,7 @@ #include __COPYRIGHT("@(#) Copyright (c) 2008\ The NetBSD Foundation, inc. All rights reserved."); -__RCSID("$NetBSD: t_ttypty.c,v 1.1 2009/02/20 21:39:57 jmmv Exp $"); +__RCSID("$NetBSD: t_ttypty.c,v 1.2 2017/01/13 21:30:41 christos Exp $"); #include #include @@ -45,7 +45,7 @@ __RCSID("$NetBSD: t_ttypty.c,v 1.1 2009/02/20 21:39:57 jmmv Exp $"); #include -#include "../../../h_macros.h" +#include "h_macros.h" static void h_check(bool check_master) diff --git a/contrib/netbsd-tests/kernel/kqueue/t_ioctl.c b/contrib/netbsd-tests/kernel/kqueue/t_ioctl.c index d996fdfbd575..78b058733457 100644 --- a/contrib/netbsd-tests/kernel/kqueue/t_ioctl.c +++ b/contrib/netbsd-tests/kernel/kqueue/t_ioctl.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_ioctl.c,v 1.2 2015/01/14 22:22:32 christos Exp $ */ +/* $NetBSD: t_ioctl.c,v 1.3 2017/01/13 21:30:41 christos Exp $ */ /*- * Copyright (c) 2002, 2008 The NetBSD Foundation, Inc. @@ -32,7 +32,7 @@ #include __COPYRIGHT("@(#) Copyright (c) 2008\ The NetBSD Foundation, inc. All rights reserved."); -__RCSID("$NetBSD: t_ioctl.c,v 1.2 2015/01/14 22:22:32 christos Exp $"); +__RCSID("$NetBSD: t_ioctl.c,v 1.3 2017/01/13 21:30:41 christos Exp $"); #include #include @@ -42,7 +42,7 @@ __RCSID("$NetBSD: t_ioctl.c,v 1.2 2015/01/14 22:22:32 christos Exp $"); #include -#include "../../h_macros.h" +#include "h_macros.h" ATF_TC(kfilter_byfilter); ATF_TC_HEAD(kfilter_byfilter, tc) diff --git a/contrib/netbsd-tests/kernel/kqueue/t_proc1.c b/contrib/netbsd-tests/kernel/kqueue/t_proc1.c index aa806ba1a8fa..5f8c2a4948b2 100644 --- a/contrib/netbsd-tests/kernel/kqueue/t_proc1.c +++ b/contrib/netbsd-tests/kernel/kqueue/t_proc1.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_proc1.c,v 1.2 2015/01/14 22:22:32 christos Exp $ */ +/* $NetBSD: t_proc1.c,v 1.3 2017/01/13 21:30:41 christos Exp $ */ /*- * Copyright (c) 2002, 2008 The NetBSD Foundation, Inc. @@ -32,7 +32,7 @@ #include __COPYRIGHT("@(#) Copyright (c) 2008\ The NetBSD Foundation, inc. All rights reserved."); -__RCSID("$NetBSD: t_proc1.c,v 1.2 2015/01/14 22:22:32 christos Exp $"); +__RCSID("$NetBSD: t_proc1.c,v 1.3 2017/01/13 21:30:41 christos Exp $"); /* * this also used to trigger problem fixed in @@ -51,7 +51,7 @@ __RCSID("$NetBSD: t_proc1.c,v 1.2 2015/01/14 22:22:32 christos Exp $"); #include -#include "../../h_macros.h" +#include "h_macros.h" static int child(void) diff --git a/contrib/netbsd-tests/kernel/kqueue/t_proc2.c b/contrib/netbsd-tests/kernel/kqueue/t_proc2.c index 2d8d7f70f9dd..49c621abe35c 100644 --- a/contrib/netbsd-tests/kernel/kqueue/t_proc2.c +++ b/contrib/netbsd-tests/kernel/kqueue/t_proc2.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_proc2.c,v 1.2 2015/01/14 22:22:32 christos Exp $ */ +/* $NetBSD: t_proc2.c,v 1.3 2017/01/13 21:30:41 christos Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -32,7 +32,7 @@ #include __COPYRIGHT("@(#) Copyright (c) 2008\ The NetBSD Foundation, inc. All rights reserved."); -__RCSID("$NetBSD: t_proc2.c,v 1.2 2015/01/14 22:22:32 christos Exp $"); +__RCSID("$NetBSD: t_proc2.c,v 1.3 2017/01/13 21:30:41 christos Exp $"); #ifdef __FreeBSD__ #include @@ -50,7 +50,7 @@ __RCSID("$NetBSD: t_proc2.c,v 1.2 2015/01/14 22:22:32 christos Exp $"); #include -#include "../../h_macros.h" +#include "h_macros.h" static void child_two(void) diff --git a/contrib/netbsd-tests/kernel/kqueue/t_proc3.c b/contrib/netbsd-tests/kernel/kqueue/t_proc3.c index eac2f9ce984a..bb20aedc278e 100644 --- a/contrib/netbsd-tests/kernel/kqueue/t_proc3.c +++ b/contrib/netbsd-tests/kernel/kqueue/t_proc3.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_proc3.c,v 1.2 2015/01/14 22:22:32 christos Exp $ */ +/* $NetBSD: t_proc3.c,v 1.3 2017/01/13 21:30:41 christos Exp $ */ /*- * Copyright (c) 2012 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include -__RCSID("$NetBSD: t_proc3.c,v 1.2 2015/01/14 22:22:32 christos Exp $"); +__RCSID("$NetBSD: t_proc3.c,v 1.3 2017/01/13 21:30:41 christos Exp $"); #ifdef __FreeBSD__ #include @@ -48,7 +48,7 @@ __RCSID("$NetBSD: t_proc3.c,v 1.2 2015/01/14 22:22:32 christos Exp $"); #include -#include "../../h_macros.h" +#include "h_macros.h" ATF_TC(proc3); ATF_TC_HEAD(proc3, tc) diff --git a/contrib/netbsd-tests/kernel/kqueue/t_sig.c b/contrib/netbsd-tests/kernel/kqueue/t_sig.c index ebbd76ec8873..3557ba57bdca 100644 --- a/contrib/netbsd-tests/kernel/kqueue/t_sig.c +++ b/contrib/netbsd-tests/kernel/kqueue/t_sig.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_sig.c,v 1.2 2010/11/03 16:10:20 christos Exp $ */ +/* $NetBSD: t_sig.c,v 1.3 2017/01/13 21:30:41 christos Exp $ */ /*- * Copyright (c) 2002, 2008 The NetBSD Foundation, Inc. @@ -32,7 +32,7 @@ #include __COPYRIGHT("@(#) Copyright (c) 2008\ The NetBSD Foundation, inc. All rights reserved."); -__RCSID("$NetBSD: t_sig.c,v 1.2 2010/11/03 16:10:20 christos Exp $"); +__RCSID("$NetBSD: t_sig.c,v 1.3 2017/01/13 21:30:41 christos Exp $"); #ifdef __FreeBSD__ #include @@ -51,7 +51,7 @@ __RCSID("$NetBSD: t_sig.c,v 1.2 2010/11/03 16:10:20 christos Exp $"); #include -#include "../../h_macros.h" +#include "h_macros.h" #define NSIGNALS 5 diff --git a/contrib/netbsd-tests/kernel/kqueue/write/t_fifo.c b/contrib/netbsd-tests/kernel/kqueue/write/t_fifo.c index 82b256cb625c..fe375b8fa943 100644 --- a/contrib/netbsd-tests/kernel/kqueue/write/t_fifo.c +++ b/contrib/netbsd-tests/kernel/kqueue/write/t_fifo.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_fifo.c,v 1.3 2010/11/07 17:51:20 jmmv Exp $ */ +/* $NetBSD: t_fifo.c,v 1.4 2017/01/13 21:30:41 christos Exp $ */ /*- * Copyright (c) 2002, 2008 The NetBSD Foundation, Inc. @@ -32,7 +32,7 @@ #include __COPYRIGHT("@(#) Copyright (c) 2008\ The NetBSD Foundation, inc. All rights reserved."); -__RCSID("$NetBSD: t_fifo.c,v 1.3 2010/11/07 17:51:20 jmmv Exp $"); +__RCSID("$NetBSD: t_fifo.c,v 1.4 2017/01/13 21:30:41 christos Exp $"); #include #include @@ -46,7 +46,7 @@ __RCSID("$NetBSD: t_fifo.c,v 1.3 2010/11/07 17:51:20 jmmv Exp $"); #include -#include "../../../h_macros.h" +#include "h_macros.h" #define FIFONAME "fifo" diff --git a/contrib/netbsd-tests/kernel/kqueue/write/t_pipe.c b/contrib/netbsd-tests/kernel/kqueue/write/t_pipe.c index 459a1f7ad0b2..5b2ca8c22f5e 100644 --- a/contrib/netbsd-tests/kernel/kqueue/write/t_pipe.c +++ b/contrib/netbsd-tests/kernel/kqueue/write/t_pipe.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_pipe.c,v 1.1 2009/02/20 21:39:57 jmmv Exp $ */ +/* $NetBSD: t_pipe.c,v 1.2 2017/01/13 21:30:41 christos Exp $ */ /*- * Copyright (c) 2002 The NetBSD Foundation, Inc. @@ -32,7 +32,7 @@ #include __COPYRIGHT("@(#) Copyright (c) 2008\ The NetBSD Foundation, inc. All rights reserved."); -__RCSID("$NetBSD: t_pipe.c,v 1.1 2009/02/20 21:39:57 jmmv Exp $"); +__RCSID("$NetBSD: t_pipe.c,v 1.2 2017/01/13 21:30:41 christos Exp $"); #include #include @@ -44,7 +44,7 @@ __RCSID("$NetBSD: t_pipe.c,v 1.1 2009/02/20 21:39:57 jmmv Exp $"); #include -#include "../../../h_macros.h" +#include "h_macros.h" ATF_TC(pipe1); ATF_TC_HEAD(pipe1, tc) diff --git a/contrib/netbsd-tests/kernel/kqueue/write/t_ttypty.c b/contrib/netbsd-tests/kernel/kqueue/write/t_ttypty.c index 6983910f9573..45a67500f5b8 100644 --- a/contrib/netbsd-tests/kernel/kqueue/write/t_ttypty.c +++ b/contrib/netbsd-tests/kernel/kqueue/write/t_ttypty.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_ttypty.c,v 1.1 2009/02/20 21:39:58 jmmv Exp $ */ +/* $NetBSD: t_ttypty.c,v 1.2 2017/01/13 21:30:41 christos Exp $ */ /*- * Copyright (c) 2002, 2008 The NetBSD Foundation, Inc. @@ -32,7 +32,7 @@ #include __COPYRIGHT("@(#) Copyright (c) 2008\ The NetBSD Foundation, inc. All rights reserved."); -__RCSID("$NetBSD: t_ttypty.c,v 1.1 2009/02/20 21:39:58 jmmv Exp $"); +__RCSID("$NetBSD: t_ttypty.c,v 1.2 2017/01/13 21:30:41 christos Exp $"); #include #include @@ -47,7 +47,7 @@ __RCSID("$NetBSD: t_ttypty.c,v 1.1 2009/02/20 21:39:58 jmmv Exp $"); #include -#include "../../../h_macros.h" +#include "h_macros.h" static void h_check(bool check_master) diff --git a/contrib/netbsd-tests/kernel/t_extent.c b/contrib/netbsd-tests/kernel/t_extent.c index faefafae5f8d..57dfc2b6780f 100644 --- a/contrib/netbsd-tests/kernel/t_extent.c +++ b/contrib/netbsd-tests/kernel/t_extent.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_extent.c,v 1.4 2012/01/27 18:53:10 para Exp $ */ +/* $NetBSD: t_extent.c,v 1.5 2017/01/13 21:30:41 christos Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -29,7 +29,7 @@ #include __COPYRIGHT("@(#) Copyright (c) 2008\ The NetBSD Foundation, inc. All rights reserved."); -__RCSID("$NetBSD: t_extent.c,v 1.4 2012/01/27 18:53:10 para Exp $"); +__RCSID("$NetBSD: t_extent.c,v 1.5 2017/01/13 21:30:41 christos Exp $"); #include #include @@ -41,7 +41,7 @@ __RCSID("$NetBSD: t_extent.c,v 1.4 2012/01/27 18:53:10 para Exp $"); #include -#include "../h_macros.h" +#include "h_macros.h" static int ret; static struct extent *ex; diff --git a/contrib/netbsd-tests/kernel/t_filedesc.c b/contrib/netbsd-tests/kernel/t_filedesc.c index 6b367ee701c7..a938d6f0b178 100644 --- a/contrib/netbsd-tests/kernel/t_filedesc.c +++ b/contrib/netbsd-tests/kernel/t_filedesc.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_filedesc.c,v 1.5 2012/03/18 09:46:50 jruoho Exp $ */ +/* $NetBSD: t_filedesc.c,v 1.6 2017/01/13 21:30:41 christos Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -27,7 +27,7 @@ */ #include -__RCSID("$NetBSD: t_filedesc.c,v 1.5 2012/03/18 09:46:50 jruoho Exp $"); +__RCSID("$NetBSD: t_filedesc.c,v 1.6 2017/01/13 21:30:41 christos Exp $"); #include @@ -40,7 +40,7 @@ __RCSID("$NetBSD: t_filedesc.c,v 1.5 2012/03/18 09:46:50 jruoho Exp $"); #include #include -#include "../h_macros.h" +#include "h_macros.h" ATF_TC(getfilerace); ATF_TC_HEAD(getfilerace, tc) diff --git a/contrib/netbsd-tests/kernel/t_lock.c b/contrib/netbsd-tests/kernel/t_lock.c index 3704afb14bc0..bd83abe97933 100644 --- a/contrib/netbsd-tests/kernel/t_lock.c +++ b/contrib/netbsd-tests/kernel/t_lock.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_lock.c,v 1.1 2009/02/20 21:39:57 jmmv Exp $ */ +/* $NetBSD: t_lock.c,v 1.2 2017/01/13 21:30:41 christos Exp $ */ /*- * Copyright (c) 2002, 2008 The NetBSD Foundation, Inc. @@ -29,7 +29,7 @@ #include __COPYRIGHT("@(#) Copyright (c) 2008\ The NetBSD Foundation, inc. All rights reserved."); -__RCSID("$NetBSD: t_lock.c,v 1.1 2009/02/20 21:39:57 jmmv Exp $"); +__RCSID("$NetBSD: t_lock.c,v 1.2 2017/01/13 21:30:41 christos Exp $"); #include @@ -38,7 +38,7 @@ __RCSID("$NetBSD: t_lock.c,v 1.1 2009/02/20 21:39:57 jmmv Exp $"); #include -#include "../h_macros.h" +#include "h_macros.h" __cpu_simple_lock_t lk; volatile int handled = 0; diff --git a/contrib/netbsd-tests/kernel/t_ptrace.c b/contrib/netbsd-tests/kernel/t_ptrace.c index 074a953a93e7..dc0bbdb6e14b 100644 --- a/contrib/netbsd-tests/kernel/t_ptrace.c +++ b/contrib/netbsd-tests/kernel/t_ptrace.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_ptrace.c,v 1.17 2016/11/13 22:59:31 kamil Exp $ */ +/* $NetBSD: t_ptrace.c,v 1.18 2017/01/13 21:30:41 christos Exp $ */ /*- * Copyright (c) 2016 The NetBSD Foundation, Inc. @@ -27,7 +27,7 @@ */ #include -__RCSID("$NetBSD: t_ptrace.c,v 1.17 2016/11/13 22:59:31 kamil Exp $"); +__RCSID("$NetBSD: t_ptrace.c,v 1.18 2017/01/13 21:30:41 christos Exp $"); #include #include @@ -40,7 +40,7 @@ __RCSID("$NetBSD: t_ptrace.c,v 1.17 2016/11/13 22:59:31 kamil Exp $"); #include -#include "../h_macros.h" +#include "h_macros.h" /* * A child process cannot call atf functions and expect them to magically diff --git a/contrib/netbsd-tests/kernel/t_ptrace_wait.c b/contrib/netbsd-tests/kernel/t_ptrace_wait.c index e502a034eb1b..b1b4d1bef2c2 100644 --- a/contrib/netbsd-tests/kernel/t_ptrace_wait.c +++ b/contrib/netbsd-tests/kernel/t_ptrace_wait.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_ptrace_wait.c,v 1.53 2017/01/10 05:08:24 kamil Exp $ */ +/* $NetBSD: t_ptrace_wait.c,v 1.58 2017/01/14 04:37:55 kamil Exp $ */ /*- * Copyright (c) 2016 The NetBSD Foundation, Inc. @@ -27,7 +27,7 @@ */ #include -__RCSID("$NetBSD: t_ptrace_wait.c,v 1.53 2017/01/10 05:08:24 kamil Exp $"); +__RCSID("$NetBSD: t_ptrace_wait.c,v 1.58 2017/01/14 04:37:55 kamil Exp $"); #include #include @@ -48,7 +48,7 @@ __RCSID("$NetBSD: t_ptrace_wait.c,v 1.53 2017/01/10 05:08:24 kamil Exp $"); #include -#include "../h_macros.h" +#include "h_macros.h" #include "t_ptrace_wait.h" #include "msg.h" @@ -65,6 +65,7 @@ __RCSID("$NetBSD: t_ptrace_wait.c,v 1.53 2017/01/10 05:08:24 kamil Exp $"); #define PARENT_FROM_CHILD(info, fds, msg) \ ATF_REQUIRE(msg_read_child(info " from parent " # fds, &fds, &msg, sizeof(msg)) == 0) + ATF_TC(traceme1); ATF_TC_HEAD(traceme1, tc) { @@ -1071,6 +1072,118 @@ ATF_TC_BODY(eventmask2, tc) TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); } +ATF_TC(eventmask3); +ATF_TC_HEAD(eventmask3, tc) +{ + atf_tc_set_md_var(tc, "descr", + "Verify that PTRACE_VFORK in EVENT_MASK is preserved"); +} + +ATF_TC_BODY(eventmask3, tc) +{ + const int exitval = 5; + const int sigval = SIGSTOP; + pid_t child, wpid; +#if defined(TWAIT_HAVE_STATUS) + int status; +#endif + ptrace_event_t set_event, get_event; + const int len = sizeof(ptrace_event_t); + + atf_tc_expect_fail("PR kern/51630"); + + printf("Before forking process PID=%d\n", getpid()); + ATF_REQUIRE((child = fork()) != -1); + if (child == 0) { + printf("Before calling PT_TRACE_ME from child %d\n", getpid()); + FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); + + printf("Before raising %s from child\n", strsignal(sigval)); + FORKEE_ASSERT(raise(sigval) == 0); + + printf("Before exiting of the child process\n"); + _exit(exitval); + } + printf("Parent process PID=%d, child's PID=%d\n", getpid(), child); + + printf("Before calling %s() for the child\n", TWAIT_FNAME); + TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); + + validate_status_stopped(status, sigval); + + set_event.pe_set_event = PTRACE_VFORK; + ATF_REQUIRE(ptrace(PT_SET_EVENT_MASK, child, &set_event, len) != -1); + ATF_REQUIRE(ptrace(PT_GET_EVENT_MASK, child, &get_event, len) != -1); + ATF_REQUIRE(memcmp(&set_event, &get_event, len) == 0); + + printf("Before resuming the child process where it left off and " + "without signal to be sent\n"); + ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); + + printf("Before calling %s() for the child\n", TWAIT_FNAME); + TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); + + validate_status_exited(status, exitval); + + printf("Before calling %s() for the child\n", TWAIT_FNAME); + TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); +} + +ATF_TC(eventmask4); +ATF_TC_HEAD(eventmask4, tc) +{ + atf_tc_set_md_var(tc, "descr", + "Verify that PTRACE_VFORK_DONE in EVENT_MASK is preserved"); +} + +ATF_TC_BODY(eventmask4, tc) +{ + const int exitval = 5; + const int sigval = SIGSTOP; + pid_t child, wpid; +#if defined(TWAIT_HAVE_STATUS) + int status; +#endif + ptrace_event_t set_event, get_event; + const int len = sizeof(ptrace_event_t); + + printf("Before forking process PID=%d\n", getpid()); + ATF_REQUIRE((child = fork()) != -1); + if (child == 0) { + printf("Before calling PT_TRACE_ME from child %d\n", getpid()); + FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); + + printf("Before raising %s from child\n", strsignal(sigval)); + FORKEE_ASSERT(raise(sigval) == 0); + + printf("Before exiting of the child process\n"); + _exit(exitval); + } + printf("Parent process PID=%d, child's PID=%d\n", getpid(), child); + + printf("Before calling %s() for the child\n", TWAIT_FNAME); + TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); + + validate_status_stopped(status, sigval); + + set_event.pe_set_event = PTRACE_VFORK_DONE; + ATF_REQUIRE(ptrace(PT_SET_EVENT_MASK, child, &set_event, len) != -1); + ATF_REQUIRE(ptrace(PT_GET_EVENT_MASK, child, &get_event, len) != -1); + ATF_REQUIRE(memcmp(&set_event, &get_event, len) == 0); + + printf("Before resuming the child process where it left off and " + "without signal to be sent\n"); + ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); + + printf("Before calling %s() for the child\n", TWAIT_FNAME); + TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); + + validate_status_exited(status, exitval); + + printf("Before calling %s() for the child\n", TWAIT_FNAME); + TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); +} + #if defined(TWAIT_HAVE_PID) ATF_TC(fork1); ATF_TC_HEAD(fork1, tc) @@ -1296,12 +1409,6 @@ ATF_TC_BODY(vfork1, tc) ptrace_event_t event; const int elen = sizeof(event); - /* - * ptrace(2) command PT_SET_EVENT_MASK: option PTRACE_VFORK unsupported - */ -#ifndef PTRACE_VFORK -#define PTRACE_VFORK 0 -#endif atf_tc_expect_fail("PR kern/51630"); printf("Before forking process PID=%d\n", getpid()); @@ -1483,6 +1590,196 @@ ATF_TC_BODY(vfork2, tc) TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); } +ATF_TC(vforkdone1); +ATF_TC_HEAD(vforkdone1, tc) +{ + atf_tc_set_md_var(tc, "descr", + "Verify that vfork(2) is intercepted by ptrace(2) with EVENT_MASK " + "set to PTRACE_VFORK_DONE"); +} + +ATF_TC_BODY(vforkdone1, tc) +{ + const int exitval = 5; + const int exitval2 = 15; + const int sigval = SIGSTOP; + pid_t child, child2, wpid; +#if defined(TWAIT_HAVE_STATUS) + int status; +#endif + ptrace_state_t state; + const int slen = sizeof(state); + ptrace_event_t event; + const int elen = sizeof(event); + + printf("Before forking process PID=%d\n", getpid()); + ATF_REQUIRE((child = fork()) != -1); + if (child == 0) { + printf("Before calling PT_TRACE_ME from child %d\n", getpid()); + FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); + + printf("Before raising %s from child\n", strsignal(sigval)); + FORKEE_ASSERT(raise(sigval) == 0); + + FORKEE_ASSERT((child2 = vfork()) != 1); + + if (child2 == 0) + _exit(exitval2); + + FORKEE_REQUIRE_SUCCESS + (wpid = TWAIT_GENERIC(child2, &status, 0), child2); + + forkee_status_exited(status, exitval2); + + printf("Before exiting of the child process\n"); + _exit(exitval); + } + printf("Parent process PID=%d, child's PID=%d\n", getpid(), child); + + printf("Before calling %s() for the child\n", TWAIT_FNAME); + TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); + + validate_status_stopped(status, sigval); + + printf("Enable PTRACE_VFORK in EVENT_MASK for the child %d\n", child); + event.pe_set_event = PTRACE_VFORK_DONE; + ATF_REQUIRE(ptrace(PT_SET_EVENT_MASK, child, &event, elen) != -1); + + printf("Before resuming the child process where it left off and " + "without signal to be sent\n"); + ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); + + printf("Before calling %s() for the child %d\n", TWAIT_FNAME, child); + TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); + + validate_status_stopped(status, SIGTRAP); + + ATF_REQUIRE(ptrace(PT_GET_PROCESS_STATE, child, &state, slen) != -1); + ATF_REQUIRE_EQ(state.pe_report_event, PTRACE_VFORK_DONE); + + child2 = state.pe_other_pid; + printf("Reported PTRACE_VFORK_DONE event with forkee %d\n", child2); + + printf("Before resuming the child process where it left off and " + "without signal to be sent\n"); + ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); + + printf("Before calling %s() for the child - expected stopped " + "SIGCHLD\n", TWAIT_FNAME); + TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); + + validate_status_stopped(status, SIGCHLD); + + printf("Before resuming the child process where it left off and " + "without signal to be sent\n"); + ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); + + printf("Before calling %s() for the child - expected exited\n", + TWAIT_FNAME); + TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); + + validate_status_exited(status, exitval); + + printf("Before calling %s() for the child - expected no process\n", + TWAIT_FNAME); + TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); +} + +ATF_TC(vforkdone2); +ATF_TC_HEAD(vforkdone2, tc) +{ + atf_tc_set_md_var(tc, "descr", + "Verify that vfork(2) is intercepted by ptrace(2) with EVENT_MASK " + "set to PTRACE_FORK | PTRACE_VFORK_DONE"); +} + +ATF_TC_BODY(vforkdone2, tc) +{ + const int exitval = 5; + const int exitval2 = 15; + const int sigval = SIGSTOP; + pid_t child, child2, wpid; +#if defined(TWAIT_HAVE_STATUS) + int status; +#endif + ptrace_state_t state; + const int slen = sizeof(state); + ptrace_event_t event; + const int elen = sizeof(event); + + printf("Before forking process PID=%d\n", getpid()); + ATF_REQUIRE((child = fork()) != -1); + if (child == 0) { + printf("Before calling PT_TRACE_ME from child %d\n", getpid()); + FORKEE_ASSERT(ptrace(PT_TRACE_ME, 0, NULL, 0) != -1); + + printf("Before raising %s from child\n", strsignal(sigval)); + FORKEE_ASSERT(raise(sigval) == 0); + + FORKEE_ASSERT((child2 = vfork()) != 1); + + if (child2 == 0) + _exit(exitval2); + + FORKEE_REQUIRE_SUCCESS + (wpid = TWAIT_GENERIC(child2, &status, 0), child2); + + forkee_status_exited(status, exitval2); + + printf("Before exiting of the child process\n"); + _exit(exitval); + } + printf("Parent process PID=%d, child's PID=%d\n", getpid(), child); + + printf("Before calling %s() for the child\n", TWAIT_FNAME); + TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); + + validate_status_stopped(status, sigval); + + printf("Enable PTRACE_VFORK in EVENT_MASK for the child %d\n", child); + event.pe_set_event = PTRACE_FORK | PTRACE_VFORK_DONE; + ATF_REQUIRE(ptrace(PT_SET_EVENT_MASK, child, &event, elen) != -1); + + printf("Before resuming the child process where it left off and " + "without signal to be sent\n"); + ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); + + printf("Before calling %s() for the child %d\n", TWAIT_FNAME, child); + TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); + + validate_status_stopped(status, SIGTRAP); + + ATF_REQUIRE(ptrace(PT_GET_PROCESS_STATE, child, &state, slen) != -1); + ATF_REQUIRE_EQ(state.pe_report_event, PTRACE_VFORK_DONE); + + child2 = state.pe_other_pid; + printf("Reported PTRACE_VFORK_DONE event with forkee %d\n", child2); + + printf("Before resuming the child process where it left off and " + "without signal to be sent\n"); + ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); + + printf("Before calling %s() for the child - expected stopped " + "SIGCHLD\n", TWAIT_FNAME); + TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); + + validate_status_stopped(status, SIGCHLD); + + printf("Before resuming the child process where it left off and " + "without signal to be sent\n"); + ATF_REQUIRE(ptrace(PT_CONTINUE, child, (void *)1, 0) != -1); + + printf("Before calling %s() for the child - expected exited\n", + TWAIT_FNAME); + TWAIT_REQUIRE_SUCCESS(wpid = TWAIT_GENERIC(child, &status, 0), child); + + validate_status_exited(status, exitval); + + printf("Before calling %s() for the child - expected no process\n", + TWAIT_FNAME); + TWAIT_REQUIRE_FAILURE(ECHILD, wpid = TWAIT_GENERIC(child, &status, 0)); +} + ATF_TC(io_read_d1); ATF_TC_HEAD(io_read_d1, tc) { @@ -5008,6 +5305,8 @@ ATF_TP_ADD_TCS(tp) ATF_TP_ADD_TC(tp, eventmask1); ATF_TP_ADD_TC(tp, eventmask2); + ATF_TP_ADD_TC(tp, eventmask3); + ATF_TP_ADD_TC(tp, eventmask4); ATF_TP_ADD_TC_HAVE_PID(tp, fork1); ATF_TP_ADD_TC(tp, fork2); @@ -5015,6 +5314,9 @@ ATF_TP_ADD_TCS(tp) ATF_TP_ADD_TC_HAVE_PID(tp, vfork1); ATF_TP_ADD_TC(tp, vfork2); + ATF_TP_ADD_TC(tp, vforkdone1); + ATF_TP_ADD_TC(tp, vforkdone2); + ATF_TP_ADD_TC(tp, io_read_d1); ATF_TP_ADD_TC(tp, io_read_d2); ATF_TP_ADD_TC(tp, io_read_d3); diff --git a/contrib/netbsd-tests/kernel/t_pty.c b/contrib/netbsd-tests/kernel/t_pty.c index fccfc17b6eda..3b079ef616ba 100644 --- a/contrib/netbsd-tests/kernel/t_pty.c +++ b/contrib/netbsd-tests/kernel/t_pty.c @@ -1,4 +1,4 @@ -/* $Id: t_pty.c,v 1.1 2011/09/24 15:53:01 christos Exp $ */ +/* $Id: t_pty.c,v 1.2 2017/01/13 21:30:41 christos Exp $ */ /* * Allocates a pty(4) device, and sends the specified number of packets of the @@ -9,7 +9,7 @@ */ #include -__RCSID("$NetBSD: t_pty.c,v 1.1 2011/09/24 15:53:01 christos Exp $"); +__RCSID("$NetBSD: t_pty.c,v 1.2 2017/01/13 21:30:41 christos Exp $"); #include #include @@ -35,7 +35,7 @@ static __dead void usage(const char *); static void parse_args(int, char **); #else #include -#include "../h_macros.h" +#include "h_macros.h" #endif static int pty_open(void); diff --git a/contrib/netbsd-tests/kernel/t_rnd.c b/contrib/netbsd-tests/kernel/t_rnd.c index 86461308daa4..ae9ef5572023 100644 --- a/contrib/netbsd-tests/kernel/t_rnd.c +++ b/contrib/netbsd-tests/kernel/t_rnd.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_rnd.c,v 1.9 2016/05/22 04:34:44 riastradh Exp $ */ +/* $NetBSD: t_rnd.c,v 1.10 2017/01/13 21:30:41 christos Exp $ */ /* * Copyright (c) 2009 The NetBSD Foundation, Inc. @@ -27,7 +27,7 @@ */ #include -__RCSID("$NetBSD: t_rnd.c,v 1.9 2016/05/22 04:34:44 riastradh Exp $"); +__RCSID("$NetBSD: t_rnd.c,v 1.10 2017/01/13 21:30:41 christos Exp $"); #include #include @@ -39,7 +39,7 @@ __RCSID("$NetBSD: t_rnd.c,v 1.9 2016/05/22 04:34:44 riastradh Exp $"); #include #include -#include "../h_macros.h" +#include "h_macros.h" ATF_TC(RNDADDDATA); ATF_TC_HEAD(RNDADDDATA, tc) diff --git a/contrib/netbsd-tests/lib/libc/gen/exect/t_exect.c b/contrib/netbsd-tests/lib/libc/gen/exect/t_exect.c new file mode 100644 index 000000000000..4c85e4b2db4b --- /dev/null +++ b/contrib/netbsd-tests/lib/libc/gen/exect/t_exect.c @@ -0,0 +1,90 @@ +/* $NetBSD: t_exect.c,v 1.6 2016/12/12 10:34:55 joerg Exp $ */ + +/*- + * Copyright (c) 2014 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. + */ + +#include + +#include +#include +#include +#include +#include + +ATF_TC(t_exect_null); + +ATF_TC_HEAD(t_exect_null, tc) +{ + atf_tc_set_md_var(tc, "descr", + "Tests an empty exect(2) executing"); +} + +static volatile sig_atomic_t caught = 0; + +static void +sigtrap_handler(int sig, siginfo_t *info, void *ctx) +{ + ATF_REQUIRE_EQ(sig, SIGTRAP); + ATF_REQUIRE_EQ(info->si_code, TRAP_TRACE); + + ++caught; +} + +ATF_TC_BODY(t_exect_null, tc) +{ + struct sigaction act; + + /* + * Currently exect(3) is misdesigned -- see PR port-amd64/51700 and it + * needs to be redone from scratch. + * + * This test affects amd64 releng machines causing tests to hang or + * fail. As there is little point to test interface that is still not, + * designed and implemented and is breaking tests - skip it + * unconditionally for all ports. + */ + /* Prevent static analysis from requiring t_exec_null to be __dead. */ + if (!caught) + atf_tc_skip("exect(3) misdesigned and hangs - PR port-amd64/51700"); + + ATF_REQUIRE(sigemptyset(&act.sa_mask) == 0); + act.sa_sigaction = sigtrap_handler; + act.sa_flags = SA_SIGINFO; + + ATF_REQUIRE(sigaction(SIGTRAP, &act, 0) == 0); + + ATF_REQUIRE_ERRNO(EFAULT, exect(NULL, NULL, NULL) == -1); + + ATF_REQUIRE_EQ_MSG(caught, 1, "expected caught (1) != received (%d)", + (int)caught); +} + +ATF_TP_ADD_TCS(tp) +{ + ATF_TP_ADD_TC(tp, t_exect_null); + + return atf_no_error(); +} diff --git a/contrib/netbsd-tests/lib/libc/gen/t_glob.c b/contrib/netbsd-tests/lib/libc/gen/t_glob.c index 0572a42023a6..c0d3a3d2ae38 100644 --- a/contrib/netbsd-tests/lib/libc/gen/t_glob.c +++ b/contrib/netbsd-tests/lib/libc/gen/t_glob.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_glob.c,v 1.3 2013/01/02 11:28:48 martin Exp $ */ +/* $NetBSD: t_glob.c,v 1.4 2017/01/13 21:30:41 christos Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. * All rights reserved. @@ -32,7 +32,7 @@ */ #include -__RCSID("$NetBSD: t_glob.c,v 1.3 2013/01/02 11:28:48 martin Exp $"); +__RCSID("$NetBSD: t_glob.c,v 1.4 2017/01/13 21:30:41 christos Exp $"); #include @@ -46,12 +46,11 @@ __RCSID("$NetBSD: t_glob.c,v 1.3 2013/01/02 11:28:48 martin Exp $"); #include #include -#ifdef __FreeBSD__ #include "h_macros.h" + +#ifdef __FreeBSD__ #define __gl_stat_t struct stat #define _S_IFDIR S_IFDIR -#else -#include "../../../h_macros.h" #endif diff --git a/contrib/netbsd-tests/lib/libc/regex/debug.c b/contrib/netbsd-tests/lib/libc/regex/debug.c index 22f0b90d2272..18ab6ea6b611 100644 --- a/contrib/netbsd-tests/lib/libc/regex/debug.c +++ b/contrib/netbsd-tests/lib/libc/regex/debug.c @@ -1,4 +1,4 @@ -/* $NetBSD: debug.c,v 1.2 2011/10/10 04:32:41 christos Exp $ */ +/* $NetBSD: debug.c,v 1.3 2017/01/14 00:50:56 christos Exp $ */ /*- * Copyright (c) 1993 The NetBSD Foundation, Inc. @@ -26,18 +26,15 @@ * POSSIBILITY OF SUCH DAMAGE. */ +#include #include #include #include #include #include #include - -#include -#ifdef __FreeBSD__ #include #include -#endif /* Don't sort these! */ #include "utils.h" diff --git a/contrib/netbsd-tests/lib/libc/regex/t_exhaust.c b/contrib/netbsd-tests/lib/libc/regex/t_exhaust.c index 0670e514e7e1..f9bd276f63d6 100644 --- a/contrib/netbsd-tests/lib/libc/regex/t_exhaust.c +++ b/contrib/netbsd-tests/lib/libc/regex/t_exhaust.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_exhaust.c,v 1.7 2011/11/16 18:37:31 christos Exp $ */ +/* $NetBSD: t_exhaust.c,v 1.8 2017/01/14 00:50:56 christos Exp $ */ /*- * Copyright (c) 2011 The NetBSD Foundation, Inc. @@ -37,17 +37,15 @@ */ #include -__RCSID("$NetBSD: t_exhaust.c,v 1.7 2011/11/16 18:37:31 christos Exp $"); +__RCSID("$NetBSD: t_exhaust.c,v 1.8 2017/01/14 00:50:56 christos Exp $"); -#include -#include -#include -#include -#include -#include -#ifdef __FreeBSD__ #include -#endif +#include +#include +#include +#include +#include +#include #ifndef REGEX_MAXSIZE #define REGEX_MAXSIZE 9999 @@ -179,25 +177,17 @@ ATF_TC_HEAD(regcomp_too_big, tc) " crash, but return a proper error code"); // libtre needs it. atf_tc_set_md_var(tc, "timeout", "600"); -#ifdef __FreeBSD__ atf_tc_set_md_var(tc, "require.memory", "64M"); -#else - atf_tc_set_md_var(tc, "require.memory", "120M"); -#endif } ATF_TC_BODY(regcomp_too_big, tc) { regex_t re; -#ifdef __FreeBSD__ struct rlimit limit; -#endif int e; -#ifdef __FreeBSD__ limit.rlim_cur = limit.rlim_max = 64 * 1024 * 1024; ATF_REQUIRE(setrlimit(RLIMIT_VMEM, &limit) != -1); -#endif for (size_t i = 0; i < __arraycount(tests); i++) { char *d = (*tests[i].pattern)(REGEX_MAXSIZE); e = regcomp(&re, d, tests[i].type); diff --git a/contrib/netbsd-tests/lib/libc/regex/t_regex_att.c b/contrib/netbsd-tests/lib/libc/regex/t_regex_att.c index 0ca44b47577e..5f4353fa1240 100644 --- a/contrib/netbsd-tests/lib/libc/regex/t_regex_att.c +++ b/contrib/netbsd-tests/lib/libc/regex/t_regex_att.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_regex_att.c,v 1.1 2012/08/24 20:24:40 jmmv Exp $ */ +/* $NetBSD: t_regex_att.c,v 1.2 2017/01/14 00:50:56 christos Exp $ */ /*- * Copyright (c) 2011 The NetBSD Foundation, Inc. @@ -37,7 +37,7 @@ */ #include -__RCSID("$NetBSD: t_regex_att.c,v 1.1 2012/08/24 20:24:40 jmmv Exp $"); +__RCSID("$NetBSD: t_regex_att.c,v 1.2 2017/01/14 00:50:56 christos Exp $"); #include @@ -377,11 +377,7 @@ checkmatches(const char *matches, size_t nm, const regmatch_t *pm, " cur=%d, max=%zu", res, l, len - off); off += l; } -#ifdef __FreeBSD__ ATF_CHECK_STREQ_MSG(res, matches, " at line %zu", lineno); -#else - ATF_REQUIRE_STREQ_MSG(res, matches, " at line %zu", lineno); -#endif free(res); } diff --git a/contrib/netbsd-tests/lib/libc/sys/t_clock_gettime.c b/contrib/netbsd-tests/lib/libc/sys/t_clock_gettime.c index 229c343c7a8b..3a18286091b3 100644 --- a/contrib/netbsd-tests/lib/libc/sys/t_clock_gettime.c +++ b/contrib/netbsd-tests/lib/libc/sys/t_clock_gettime.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_clock_gettime.c,v 1.1 2011/10/15 06:42:16 jruoho Exp $ */ +/* $NetBSD: t_clock_gettime.c,v 1.3 2017/01/13 21:30:41 christos Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -58,30 +58,22 @@ #include __COPYRIGHT("@(#) Copyright (c) 2008\ The NetBSD Foundation, inc. All rights reserved."); -__RCSID("$NetBSD: t_clock_gettime.c,v 1.1 2011/10/15 06:42:16 jruoho Exp $"); +__RCSID("$NetBSD: t_clock_gettime.c,v 1.3 2017/01/13 21:30:41 christos Exp $"); #include #include -#ifdef __NetBSD__ -#include -#endif - #include #include +#include #include +#include #include #include #include #include -#ifdef __NetBSD__ -#include "../../../h_macros.h" -#else -#include -#include #include "h_macros.h" -#endif #define MINPOSDIFF 15000000 /* 15 ms for now */ #define TIMEOUT 5 diff --git a/contrib/netbsd-tests/lib/libc/sys/t_connect.c b/contrib/netbsd-tests/lib/libc/sys/t_connect.c index 672a022c326e..5dc88d5661ca 100644 --- a/contrib/netbsd-tests/lib/libc/sys/t_connect.c +++ b/contrib/netbsd-tests/lib/libc/sys/t_connect.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_connect.c,v 1.2 2015/04/05 23:17:41 rtr Exp $ */ +/* $NetBSD: t_connect.c,v 1.3 2017/01/13 20:09:48 christos Exp $ */ /* * Copyright (c) 2007, 2008 The NetBSD Foundation, Inc. * All rights reserved. @@ -26,6 +26,7 @@ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include #include #include #include @@ -56,10 +57,8 @@ ATF_TC_BODY(connect_low_port, tc) slist = socket(AF_INET, SOCK_STREAM, 0); sd = socket(AF_INET, SOCK_STREAM, 0); -#ifdef __FreeBSD__ ATF_REQUIRE(sd > 0); ATF_REQUIRE(slist > 0); -#endif /* bind listening socket */ memset(&sinlist, 0, sizeof(sinlist)); @@ -97,9 +96,7 @@ ATF_TC_BODY(connect_low_port, tc) ATF_REQUIRE(ntohs(sin.sin_port) <= IPPORT_RESERVEDMAX); close(sd); -#ifdef __FreeBSD__ close(slist); -#endif } ATF_TC(connect_foreign_family); diff --git a/contrib/netbsd-tests/lib/libc/sys/t_dup.c b/contrib/netbsd-tests/lib/libc/sys/t_dup.c index d8125ab33531..044b6e37dc20 100644 --- a/contrib/netbsd-tests/lib/libc/sys/t_dup.c +++ b/contrib/netbsd-tests/lib/libc/sys/t_dup.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_dup.c,v 1.8 2012/03/18 07:00:51 jruoho Exp $ */ +/* $NetBSD: t_dup.c,v 1.9 2017/01/13 20:31:53 christos Exp $ */ /*- * Copyright (c) 2011 The NetBSD Foundation, Inc. @@ -29,7 +29,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ #include -__RCSID("$NetBSD: t_dup.c,v 1.8 2012/03/18 07:00:51 jruoho Exp $"); +__RCSID("$NetBSD: t_dup.c,v 1.9 2017/01/13 20:31:53 christos Exp $"); #include #include @@ -39,6 +39,7 @@ __RCSID("$NetBSD: t_dup.c,v 1.8 2012/03/18 07:00:51 jruoho Exp $"); #include #include #include +#include #include #include #include diff --git a/contrib/netbsd-tests/lib/libc/sys/t_getrusage.c b/contrib/netbsd-tests/lib/libc/sys/t_getrusage.c index f4ee96b057f2..273fd836a952 100644 --- a/contrib/netbsd-tests/lib/libc/sys/t_getrusage.c +++ b/contrib/netbsd-tests/lib/libc/sys/t_getrusage.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_getrusage.c,v 1.4 2016/08/05 15:01:39 scole Exp $ */ +/* $NetBSD: t_getrusage.c,v 1.5 2017/01/13 20:31:06 christos Exp $ */ /*- * Copyright (c) 2011 The NetBSD Foundation, Inc. @@ -29,7 +29,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ #include -__RCSID("$NetBSD: t_getrusage.c,v 1.4 2016/08/05 15:01:39 scole Exp $"); +__RCSID("$NetBSD: t_getrusage.c,v 1.5 2017/01/13 20:31:06 christos Exp $"); #include #include @@ -47,11 +47,7 @@ static void sighandler(int); static const size_t maxiter = 2000; static void -#ifdef __FreeBSD__ sighandler(int signo __unused) -#else -sighandler(int signo) -#endif { /* Nothing. */ } diff --git a/contrib/netbsd-tests/lib/libc/sys/t_link.c b/contrib/netbsd-tests/lib/libc/sys/t_link.c index b8dcacc994fe..5663d9ae946a 100644 --- a/contrib/netbsd-tests/lib/libc/sys/t_link.c +++ b/contrib/netbsd-tests/lib/libc/sys/t_link.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_link.c,v 1.2 2014/04/21 14:39:36 martin Exp $ */ +/* $NetBSD: t_link.c,v 1.3 2017/01/13 20:42:36 christos Exp $ */ /*- * Copyright (c) 2011 The NetBSD Foundation, Inc. @@ -29,7 +29,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ #include -__RCSID("$NetBSD: t_link.c,v 1.2 2014/04/21 14:39:36 martin Exp $"); +__RCSID("$NetBSD: t_link.c,v 1.3 2017/01/13 20:42:36 christos Exp $"); #include #include @@ -37,6 +37,7 @@ __RCSID("$NetBSD: t_link.c,v 1.2 2014/04/21 14:39:36 martin Exp $"); #include #include #include +#include #include #include #include diff --git a/contrib/netbsd-tests/lib/libc/sys/t_listen.c b/contrib/netbsd-tests/lib/libc/sys/t_listen.c index a9ee733c737e..f9ac1dcd87c4 100644 --- a/contrib/netbsd-tests/lib/libc/sys/t_listen.c +++ b/contrib/netbsd-tests/lib/libc/sys/t_listen.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_listen.c,v 1.4 2012/03/18 07:00:52 jruoho Exp $ */ +/* $NetBSD: t_listen.c,v 1.5 2017/01/13 20:41:50 christos Exp $ */ /* * Copyright (c) 2007 The NetBSD Foundation, Inc. * All rights reserved. @@ -26,6 +26,7 @@ * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include #include #include #include @@ -110,9 +111,7 @@ ATF_TC_BODY(listen_low_port, tc) int sd, val; sd = socket(AF_INET, SOCK_STREAM, 0); -#ifdef __FreeBSD__ ATF_REQUIRE_MSG(sd != -1, "socket failed: %s", strerror(errno)); -#endif val = IP_PORTRANGE_LOW; if (setsockopt(sd, IPPROTO_IP, IP_PORTRANGE, &val, diff --git a/contrib/netbsd-tests/lib/libc/sys/t_mmap.c b/contrib/netbsd-tests/lib/libc/sys/t_mmap.c index 738758c637f7..33adcf2e0fee 100644 --- a/contrib/netbsd-tests/lib/libc/sys/t_mmap.c +++ b/contrib/netbsd-tests/lib/libc/sys/t_mmap.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_mmap.c,v 1.10 2017/01/10 22:36:29 christos Exp $ */ +/* $NetBSD: t_mmap.c,v 1.11 2017/01/13 20:43:11 christos Exp $ */ /*- * Copyright (c) 2011 The NetBSD Foundation, Inc. @@ -55,7 +55,7 @@ * SUCH DAMAGE. */ #include -__RCSID("$NetBSD: t_mmap.c,v 1.10 2017/01/10 22:36:29 christos Exp $"); +__RCSID("$NetBSD: t_mmap.c,v 1.11 2017/01/13 20:43:11 christos Exp $"); #include #include @@ -460,9 +460,7 @@ ATF_TC_BODY(mmap_truncate, tc) ATF_REQUIRE(ftruncate(fd, page / 12) == 0); ATF_REQUIRE(ftruncate(fd, page / 64) == 0); -#ifdef __FreeBSD__ (void)munmap(map, page); -#endif ATF_REQUIRE(close(fd) == 0); } @@ -519,10 +517,8 @@ ATF_TC_BODY(mmap_truncate_signal, tc) prevent the access to be optimized out */ ATF_REQUIRE(i == 0); ATF_REQUIRE(sta == 0); -#ifdef __FreeBSD__ (void)munmap(map, page); (void)close(fd); -#endif return; } diff --git a/contrib/netbsd-tests/lib/libc/sys/t_msgctl.c b/contrib/netbsd-tests/lib/libc/sys/t_msgctl.c index b9b306742699..a573d158fb10 100644 --- a/contrib/netbsd-tests/lib/libc/sys/t_msgctl.c +++ b/contrib/netbsd-tests/lib/libc/sys/t_msgctl.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_msgctl.c,v 1.4 2014/02/27 00:59:50 joerg Exp $ */ +/* $NetBSD: t_msgctl.c,v 1.5 2017/01/13 20:44:45 christos Exp $ */ /*- * Copyright (c) 2011 The NetBSD Foundation, Inc. @@ -29,7 +29,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ #include -__RCSID("$NetBSD: t_msgctl.c,v 1.4 2014/02/27 00:59:50 joerg Exp $"); +__RCSID("$NetBSD: t_msgctl.c,v 1.5 2017/01/13 20:44:45 christos Exp $"); #include #include @@ -38,6 +38,7 @@ __RCSID("$NetBSD: t_msgctl.c,v 1.4 2014/02/27 00:59:50 joerg Exp $"); #include #include +#include #include #include #include diff --git a/contrib/netbsd-tests/lib/libc/sys/t_msgrcv.c b/contrib/netbsd-tests/lib/libc/sys/t_msgrcv.c index 70f890682a76..bd8024754fa4 100644 --- a/contrib/netbsd-tests/lib/libc/sys/t_msgrcv.c +++ b/contrib/netbsd-tests/lib/libc/sys/t_msgrcv.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_msgrcv.c,v 1.3 2013/07/24 11:44:10 skrll Exp $ */ +/* $NetBSD: t_msgrcv.c,v 1.4 2017/01/13 20:44:45 christos Exp $ */ /*- * Copyright (c) 2011 The NetBSD Foundation, Inc. @@ -29,7 +29,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ #include -__RCSID("$NetBSD: t_msgrcv.c,v 1.3 2013/07/24 11:44:10 skrll Exp $"); +__RCSID("$NetBSD: t_msgrcv.c,v 1.4 2017/01/13 20:44:45 christos Exp $"); #include #include @@ -38,6 +38,7 @@ __RCSID("$NetBSD: t_msgrcv.c,v 1.3 2013/07/24 11:44:10 skrll Exp $"); #include #include +#include #include #include #include diff --git a/contrib/netbsd-tests/lib/libc/sys/t_msgsnd.c b/contrib/netbsd-tests/lib/libc/sys/t_msgsnd.c index d30cb7b97f26..36a428a84321 100644 --- a/contrib/netbsd-tests/lib/libc/sys/t_msgsnd.c +++ b/contrib/netbsd-tests/lib/libc/sys/t_msgsnd.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_msgsnd.c,v 1.2 2011/11/05 08:47:54 jruoho Exp $ */ +/* $NetBSD: t_msgsnd.c,v 1.3 2017/01/13 20:44:45 christos Exp $ */ /*- * Copyright (c) 2011 The NetBSD Foundation, Inc. @@ -29,7 +29,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ #include -__RCSID("$NetBSD: t_msgsnd.c,v 1.2 2011/11/05 08:47:54 jruoho Exp $"); +__RCSID("$NetBSD: t_msgsnd.c,v 1.3 2017/01/13 20:44:45 christos Exp $"); #include #include @@ -38,6 +38,7 @@ __RCSID("$NetBSD: t_msgsnd.c,v 1.2 2011/11/05 08:47:54 jruoho Exp $"); #include #include +#include #include #include #include diff --git a/contrib/netbsd-tests/lib/libc/sys/t_nanosleep.c b/contrib/netbsd-tests/lib/libc/sys/t_nanosleep.c index b4d9f8a809eb..1ad6661c808f 100644 --- a/contrib/netbsd-tests/lib/libc/sys/t_nanosleep.c +++ b/contrib/netbsd-tests/lib/libc/sys/t_nanosleep.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_nanosleep.c,v 1.3 2013/03/31 16:47:16 christos Exp $ */ +/* $NetBSD: t_nanosleep.c,v 1.4 2017/01/13 21:15:14 christos Exp $ */ /*- * Copyright (c) 2011 The NetBSD Foundation, Inc. @@ -29,7 +29,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ #include -__RCSID("$NetBSD: t_nanosleep.c,v 1.3 2013/03/31 16:47:16 christos Exp $"); +__RCSID("$NetBSD: t_nanosleep.c,v 1.4 2017/01/13 21:15:14 christos Exp $"); #include #include @@ -45,11 +45,7 @@ __RCSID("$NetBSD: t_nanosleep.c,v 1.3 2013/03/31 16:47:16 christos Exp $"); #include static void -#ifdef __FreeBSD__ handler(int signo __unused) -#else -handler(int signo) -#endif { /* Nothing. */ } diff --git a/contrib/netbsd-tests/lib/libc/sys/t_pipe.c b/contrib/netbsd-tests/lib/libc/sys/t_pipe.c index 32beeccb3b60..df8f1edd1d16 100644 --- a/contrib/netbsd-tests/lib/libc/sys/t_pipe.c +++ b/contrib/netbsd-tests/lib/libc/sys/t_pipe.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_pipe.c,v 1.3 2011/10/31 15:41:31 christos Exp $ */ +/* $NetBSD: t_pipe.c,v 1.5 2017/01/13 21:30:41 christos Exp $ */ /*- * Copyright (c) 2001, 2008 The NetBSD Foundation, Inc. @@ -29,7 +29,7 @@ #include __COPYRIGHT("@(#) Copyright (c) 2008\ The NetBSD Foundation, inc. All rights reserved."); -__RCSID("$NetBSD: t_pipe.c,v 1.3 2011/10/31 15:41:31 christos Exp $"); +__RCSID("$NetBSD: t_pipe.c,v 1.5 2017/01/13 21:30:41 christos Exp $"); #include #include @@ -45,7 +45,7 @@ __RCSID("$NetBSD: t_pipe.c,v 1.3 2011/10/31 15:41:31 christos Exp $"); #include -#include "../../../h_macros.h" +#include "h_macros.h" static pid_t pid; static int nsiginfo = 0; @@ -153,9 +153,7 @@ ATF_TC_BODY(pipe_restart, tc) ATF_REQUIRE_EQ(WEXITSTATUS(st), 0); } -#ifdef __FreeBSD__ free(f); -#endif } ATF_TP_ADD_TCS(tp) diff --git a/contrib/netbsd-tests/lib/libc/sys/t_pipe2.c b/contrib/netbsd-tests/lib/libc/sys/t_pipe2.c index 8208cf79231f..48f973488c7a 100644 --- a/contrib/netbsd-tests/lib/libc/sys/t_pipe2.c +++ b/contrib/netbsd-tests/lib/libc/sys/t_pipe2.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_pipe2.c,v 1.8 2012/05/16 13:54:28 jruoho Exp $ */ +/* $NetBSD: t_pipe2.c,v 1.9 2017/01/13 21:19:45 christos Exp $ */ /*- * Copyright (c) 2011 The NetBSD Foundation, Inc. @@ -36,7 +36,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ #include -__RCSID("$NetBSD: t_pipe2.c,v 1.8 2012/05/16 13:54:28 jruoho Exp $"); +__RCSID("$NetBSD: t_pipe2.c,v 1.9 2017/01/13 21:19:45 christos Exp $"); #include #include @@ -56,7 +56,8 @@ run(int flags) #ifdef __FreeBSD__ closefrom(3); #else - ATF_REQUIRE(fcntl(3, F_CLOSEM) != -1); + ATF_REQUIRE_MSG(closefrom(3) != -1, "closefrom failed: %s", + strerror(errno)); #endif ATF_REQUIRE(pipe2(fd, flags) == 0); @@ -116,13 +117,13 @@ ATF_TC_BODY(pipe2_consume, tc) { struct rlimit rl; int err, filedes[2]; -#ifdef __FreeBSD__ int old; +#ifdef __FreeBSD__ closefrom(4); #else - err = fcntl(4, F_CLOSEM); - ATF_REQUIRE(err == 0); + ATF_REQUIRE_MSG(closefrom(4) != -1, "closefrom failed: %s", + strerror(errno)); #endif err = getrlimit(RLIMIT_NOFILE, &rl); @@ -132,19 +133,15 @@ ATF_TC_BODY(pipe2_consume, tc) * file descriptor limit in the middle of a pipe2() call - i.e. * before the call only a single descriptor may be openend. */ -#ifdef __FreeBSD__ old = rl.rlim_cur; -#endif rl.rlim_cur = 4; err = setrlimit(RLIMIT_NOFILE, &rl); ATF_REQUIRE(err == 0); err = pipe2(filedes, O_CLOEXEC); ATF_REQUIRE(err == -1); -#ifdef __FreeBSD__ rl.rlim_cur = old; err = setrlimit(RLIMIT_NOFILE, &rl); -#endif } ATF_TC(pipe2_nonblock); diff --git a/contrib/netbsd-tests/lib/libc/sys/t_posix_fadvise.c b/contrib/netbsd-tests/lib/libc/sys/t_posix_fadvise.c index da4e7461c8af..813bfb8cba11 100644 --- a/contrib/netbsd-tests/lib/libc/sys/t_posix_fadvise.c +++ b/contrib/netbsd-tests/lib/libc/sys/t_posix_fadvise.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_posix_fadvise.c,v 1.1 2011/10/15 06:10:26 jruoho Exp $ */ +/* $NetBSD: t_posix_fadvise.c,v 1.2 2017/01/13 21:30:41 christos Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -58,7 +58,7 @@ #include __COPYRIGHT("@(#) Copyright (c) 2008\ The NetBSD Foundation, inc. All rights reserved."); -__RCSID("$NetBSD: t_posix_fadvise.c,v 1.1 2011/10/15 06:10:26 jruoho Exp $"); +__RCSID("$NetBSD: t_posix_fadvise.c,v 1.2 2017/01/13 21:30:41 christos Exp $"); #include @@ -68,7 +68,7 @@ __RCSID("$NetBSD: t_posix_fadvise.c,v 1.1 2011/10/15 06:10:26 jruoho Exp $"); #include -#include "../../../h_macros.h" +#include "h_macros.h" #include #include diff --git a/contrib/netbsd-tests/lib/libc/sys/t_revoke.c b/contrib/netbsd-tests/lib/libc/sys/t_revoke.c index 8e4c2a399353..ec225b9be491 100644 --- a/contrib/netbsd-tests/lib/libc/sys/t_revoke.c +++ b/contrib/netbsd-tests/lib/libc/sys/t_revoke.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_revoke.c,v 1.1 2011/07/07 06:57:54 jruoho Exp $ */ +/* $NetBSD: t_revoke.c,v 1.2 2017/01/13 21:15:57 christos Exp $ */ /*- * Copyright (c) 2011 The NetBSD Foundation, Inc. @@ -29,7 +29,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ #include -__RCSID("$NetBSD: t_revoke.c,v 1.1 2011/07/07 06:57:54 jruoho Exp $"); +__RCSID("$NetBSD: t_revoke.c,v 1.2 2017/01/13 21:15:57 christos Exp $"); #include #include @@ -176,9 +176,7 @@ ATF_TC_BODY(revoke_perm, tc) if (WIFEXITED(sta) == 0 || WEXITSTATUS(sta) != EXIT_SUCCESS) atf_tc_fail("revoke(2) did not obey permissions"); -#ifdef __FreeBSD__ (void)close(fd); -#endif ATF_REQUIRE(unlink(path) == 0); } diff --git a/contrib/netbsd-tests/lib/libc/sys/t_select.c b/contrib/netbsd-tests/lib/libc/sys/t_select.c index 437b67b5e9cc..04a684a8cdea 100644 --- a/contrib/netbsd-tests/lib/libc/sys/t_select.c +++ b/contrib/netbsd-tests/lib/libc/sys/t_select.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_select.c,v 1.3 2012/03/18 07:00:52 jruoho Exp $ */ +/* $NetBSD: t_select.c,v 1.4 2017/01/13 21:18:33 christos Exp $ */ /*- * Copyright (c) 2011 The NetBSD Foundation, Inc. @@ -47,21 +47,13 @@ static sig_atomic_t keep_going = 1; static void -#ifdef __FreeBSD__ sig_handler(int signum __unused) -#else -sig_handler(int signum) -#endif { keep_going = 0; } static void -#ifdef __FreeBSD__ sigchld(int signum __unused) -#else -sigchld(int signum) -#endif { } @@ -90,7 +82,7 @@ prmask(const sigset_t *m, char *buf, size_t len) return buf; } -static void +static __dead void child(const struct timespec *ts) { struct sigaction sa; @@ -135,9 +127,7 @@ child(const struct timespec *ts) "after timeout %s != %s", prmask(&nset, nbuf, sizeof(nbuf)), prmask(&oset, obuf, sizeof(obuf))); -#ifdef __FreeBSD__ _exit(0); -#endif } ATF_TC(pselect_sigmask); @@ -157,9 +147,7 @@ ATF_TC_BODY(pselect_sigmask, tc) switch (pid = fork()) { case 0: child(NULL); -#ifdef __FreeBSD__ - break; -#endif + /*NOTREACHED*/ case -1: err(1, "fork"); default: diff --git a/contrib/netbsd-tests/lib/libc/sys/t_setrlimit.c b/contrib/netbsd-tests/lib/libc/sys/t_setrlimit.c index 31db878c5851..6b90deab8f3f 100644 --- a/contrib/netbsd-tests/lib/libc/sys/t_setrlimit.c +++ b/contrib/netbsd-tests/lib/libc/sys/t_setrlimit.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_setrlimit.c,v 1.5 2016/07/13 09:53:16 njoly Exp $ */ +/* $NetBSD: t_setrlimit.c,v 1.6 2017/01/13 21:16:38 christos Exp $ */ /*- * Copyright (c) 2011 The NetBSD Foundation, Inc. @@ -29,7 +29,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ #include -__RCSID("$NetBSD: t_setrlimit.c,v 1.5 2016/07/13 09:53:16 njoly Exp $"); +__RCSID("$NetBSD: t_setrlimit.c,v 1.6 2017/01/13 21:16:38 christos Exp $"); #include #include @@ -129,9 +129,7 @@ ATF_TC_BODY(setrlimit_basic, tc) if (lim != 0) atf_tc_fail("failed to set limit (%d)", lim); -#ifdef __FreeBSD__ free(buf); -#endif } ATF_TC(setrlimit_current); diff --git a/contrib/netbsd-tests/lib/libc/sys/t_sigaction.c b/contrib/netbsd-tests/lib/libc/sys/t_sigaction.c index 23ca36a659f8..4bbf421c6204 100644 --- a/contrib/netbsd-tests/lib/libc/sys/t_sigaction.c +++ b/contrib/netbsd-tests/lib/libc/sys/t_sigaction.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_sigaction.c,v 1.3 2014/11/04 00:20:19 justin Exp $ */ +/* $NetBSD: t_sigaction.c,v 1.5 2017/01/13 21:30:41 christos Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -29,7 +29,7 @@ #include __COPYRIGHT("@(#) Copyright (c) 2010\ The NetBSD Foundation, inc. All rights reserved."); -__RCSID("$NetBSD: t_sigaction.c,v 1.3 2014/11/04 00:20:19 justin Exp $"); +__RCSID("$NetBSD: t_sigaction.c,v 1.5 2017/01/13 21:30:41 christos Exp $"); #include @@ -41,20 +41,12 @@ __RCSID("$NetBSD: t_sigaction.c,v 1.3 2014/11/04 00:20:19 justin Exp $"); #include -#ifdef __NetBSD__ -#include "../../../h_macros.h" -#else #include "h_macros.h" -#endif static bool handler_called = false; static void -#ifdef __FreeBSD__ handler(int signo __unused) -#else -handler(int signo) -#endif { handler_called = true; } @@ -87,11 +79,7 @@ wait_and_check_child(const pid_t pid, const char *fail_message) } static void -#ifdef __FreeBSD__ catch(int sig __unused) -#else -catch(int sig) -#endif { return; } diff --git a/contrib/netbsd-tests/lib/libc/sys/t_sigqueue.c b/contrib/netbsd-tests/lib/libc/sys/t_sigqueue.c index e911d42e93a0..a309f53d5550 100644 --- a/contrib/netbsd-tests/lib/libc/sys/t_sigqueue.c +++ b/contrib/netbsd-tests/lib/libc/sys/t_sigqueue.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_sigqueue.c,v 1.6 2016/08/04 06:43:43 christos Exp $ */ +/* $NetBSD: t_sigqueue.c,v 1.7 2017/01/13 20:44:10 christos Exp $ */ /*- * Copyright (c) 2011 The NetBSD Foundation, Inc. @@ -30,11 +30,13 @@ */ #include -__RCSID("$NetBSD: t_sigqueue.c,v 1.6 2016/08/04 06:43:43 christos Exp $"); +__RCSID("$NetBSD: t_sigqueue.c,v 1.7 2017/01/13 20:44:10 christos Exp $"); #include +#include #include #include +#include #include #include #include @@ -50,11 +52,7 @@ static void handler(int, siginfo_t *, void *); static int value; static void -#ifdef __FreeBSD__ -handler(int signo __unused, siginfo_t *info __unused, void *data __unused) -#else -handler(int signo, siginfo_t *info, void *data) -#endif +handler(int signo __unused, siginfo_t *info, void *data __unused) { value = info->si_value.sival_int; kill(0, SIGINFO); @@ -123,12 +121,10 @@ static sig_atomic_t count = 0; static int delivered[CNT]; static void -myhandler(int signo, siginfo_t *info, void *context) +myhandler(int signo, siginfo_t *info, void *context __unused) { delivered[count++] = signo; -#ifdef __FreeBSD__ printf("Signal #%zu: signo: %d\n", (size_t)count, signo); -#endif } static int @@ -213,12 +209,9 @@ ATF_TC_BODY(sigqueue_rt, tc) sigset_t mask, orig; sigemptyset(&mask); for (size_t i = 0; i < CNT; i++) -#ifdef __FreeBSD__ if (sigaddset(&mask, signals[i]) == -1) warn("sigaddset"); -#else - sigaddset(&mask, signals[i]); -#endif + ATF_REQUIRE(sigprocmask(SIG_BLOCK, &mask, &orig) != -1); @@ -227,23 +220,17 @@ ATF_TC_BODY(sigqueue_rt, tc) ATF_REQUIRE(sigprocmask(SIG_UNBLOCK, &mask, &orig) != -1); sleep(1); -#ifdef __FreeBSD__ ATF_CHECK_MSG((size_t)count == ndelivered, "count %zu != ndelivered %zu", (size_t)count, ndelivered); -#else - ATF_REQUIRE_MSG((size_t)count == ndelivered, - "count %zu != ndelivered %zu", (size_t)count, ndelivered); -#endif + for (size_t i = 0; i < ndelivered; i++) ATF_REQUIRE_MSG(ordered[i] == delivered[i], "%zu: ordered %d != delivered %d", i, ordered[i], delivered[i]); -#ifdef __FreeBSD__ - if (count > ndelivered) - for (size_t i = ndelivered; i < count; i++) + if ((size_t)count > ndelivered) + for (size_t i = ndelivered; i < (size_t)count; i++) printf("Undelivered signal #%zu: %d\n", i, ordered[i]); -#endif for (size_t i = 0; i < ndelivered; i++) ATF_REQUIRE(sigaction(signals[i], &oact[i], NULL) != -1); diff --git a/contrib/netbsd-tests/lib/libc/sys/t_socketpair.c b/contrib/netbsd-tests/lib/libc/sys/t_socketpair.c index 9da7861b1b8a..7a0cc205ece5 100644 --- a/contrib/netbsd-tests/lib/libc/sys/t_socketpair.c +++ b/contrib/netbsd-tests/lib/libc/sys/t_socketpair.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_socketpair.c,v 1.1 2011/11/05 18:19:02 jruoho Exp $ */ +/* $NetBSD: t_socketpair.c,v 1.2 2017/01/13 20:04:52 christos Exp $ */ /*- * Copyright (c) 2011 The NetBSD Foundation, Inc. @@ -36,7 +36,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ #include -__RCSID("$NetBSD: t_socketpair.c,v 1.1 2011/11/05 18:19:02 jruoho Exp $"); +__RCSID("$NetBSD: t_socketpair.c,v 1.2 2017/01/13 20:04:52 christos Exp $"); #include #include @@ -66,7 +66,7 @@ run(int flags) #ifdef __FreeBSD__ closefrom(3); #else - ATF_REQUIRE(fcntl(3, F_CLOSEM) != -1); + ATF_REQUIRE(closefrom(3) != -1); #endif ATF_REQUIRE(socketpair(AF_UNIX, SOCK_DGRAM | flags, 0, fd) == 0); diff --git a/contrib/netbsd-tests/lib/libc/sys/t_stat.c b/contrib/netbsd-tests/lib/libc/sys/t_stat.c index 300c6e89593c..956075275c33 100644 --- a/contrib/netbsd-tests/lib/libc/sys/t_stat.c +++ b/contrib/netbsd-tests/lib/libc/sys/t_stat.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_stat.c,v 1.4 2012/03/17 08:37:08 jruoho Exp $ */ +/* $NetBSD: t_stat.c,v 1.5 2017/01/13 20:06:50 christos Exp $ */ /*- * Copyright (c) 2011 The NetBSD Foundation, Inc. @@ -29,13 +29,14 @@ * POSSIBILITY OF SUCH DAMAGE. */ #include -__RCSID("$NetBSD: t_stat.c,v 1.4 2012/03/17 08:37:08 jruoho Exp $"); +__RCSID("$NetBSD: t_stat.c,v 1.5 2017/01/13 20:06:50 christos Exp $"); #include #include #include #include +#include #include #include @@ -396,6 +397,7 @@ ATF_TC_BODY(stat_symlink, tc) if (sa.st_mode == sb.st_mode) atf_tc_fail("inconsistencies between stat(2) and lstat(2)"); + (void)close(fd); ATF_REQUIRE(unlink(path) == 0); ATF_REQUIRE(unlink(pathlink) == 0); #ifdef __FreeBSD__ diff --git a/contrib/netbsd-tests/lib/libc/sys/t_truncate.c b/contrib/netbsd-tests/lib/libc/sys/t_truncate.c index 59193a953f37..695ac37d4b37 100644 --- a/contrib/netbsd-tests/lib/libc/sys/t_truncate.c +++ b/contrib/netbsd-tests/lib/libc/sys/t_truncate.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_truncate.c,v 1.2 2011/08/18 19:48:03 dholland Exp $ */ +/* $NetBSD: t_truncate.c,v 1.3 2017/01/13 20:03:51 christos Exp $ */ /*- * Copyright (c) 2011 The NetBSD Foundation, Inc. @@ -29,13 +29,14 @@ * POSSIBILITY OF SUCH DAMAGE. */ #include -__RCSID("$NetBSD: t_truncate.c,v 1.2 2011/08/18 19:48:03 dholland Exp $"); +__RCSID("$NetBSD: t_truncate.c,v 1.3 2017/01/13 20:03:51 christos Exp $"); #include #include #include #include +#include #include #include #include @@ -153,9 +154,7 @@ ATF_TC_HEAD(truncate_err, tc) ATF_TC_BODY(truncate_err, tc) { -#ifndef __NetBSD__ char buf[PATH_MAX]; -#endif errno = 0; ATF_REQUIRE_ERRNO(EFAULT, truncate((void *)-1, 999) == -1); @@ -167,13 +166,9 @@ ATF_TC_BODY(truncate_err, tc) ATF_REQUIRE_ERRNO(ENOENT, truncate("/a/b/c/d/e/f/g", 999) == -1); errno = 0; -#ifdef __NetBSD__ - ATF_REQUIRE_ERRNO(EACCES, truncate("/usr/bin/fpr", 999) == -1); -#else snprintf(buf, sizeof(buf), "%s/truncate_test.root_owned", atf_tc_get_config_var(tc, "srcdir")); ATF_REQUIRE_ERRNO(EACCES, truncate(buf, 999) == -1); -#endif } ATF_TP_ADD_TCS(tp) diff --git a/contrib/netbsd-tests/lib/libc/sys/t_umask.c b/contrib/netbsd-tests/lib/libc/sys/t_umask.c index 7a65574742b8..fb3e405b5aa2 100644 --- a/contrib/netbsd-tests/lib/libc/sys/t_umask.c +++ b/contrib/netbsd-tests/lib/libc/sys/t_umask.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_umask.c,v 1.1 2011/07/07 06:57:54 jruoho Exp $ */ +/* $NetBSD: t_umask.c,v 1.2 2017/01/13 19:34:19 christos Exp $ */ /*- * Copyright (c) 2011 The NetBSD Foundation, Inc. @@ -29,7 +29,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ #include -__RCSID("$NetBSD: t_umask.c,v 1.1 2011/07/07 06:57:54 jruoho Exp $"); +__RCSID("$NetBSD: t_umask.c,v 1.2 2017/01/13 19:34:19 christos Exp $"); #include #include @@ -129,9 +129,7 @@ ATF_TC_BODY(umask_open, tc) if (fd < 0) continue; -#ifdef __FreeBSD__ (void)close(fd); -#endif (void)memset(&st, 0, sizeof(struct stat)); if (stat(path, &st) != 0) { diff --git a/contrib/netbsd-tests/lib/libc/sys/t_unlink.c b/contrib/netbsd-tests/lib/libc/sys/t_unlink.c index b504bb06debc..9e0bd42ae155 100644 --- a/contrib/netbsd-tests/lib/libc/sys/t_unlink.c +++ b/contrib/netbsd-tests/lib/libc/sys/t_unlink.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_unlink.c,v 1.2 2014/04/21 18:05:17 martin Exp $ */ +/* $NetBSD: t_unlink.c,v 1.3 2017/01/13 19:33:03 christos Exp $ */ /*- * Copyright (c) 2011 The NetBSD Foundation, Inc. @@ -29,7 +29,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ #include -__RCSID("$NetBSD: t_unlink.c,v 1.2 2014/04/21 18:05:17 martin Exp $"); +__RCSID("$NetBSD: t_unlink.c,v 1.3 2017/01/13 19:33:03 christos Exp $"); #include @@ -111,15 +111,11 @@ ATF_TC_HEAD(unlink_fifo, tc) ATF_TC_BODY(unlink_fifo, tc) { -#ifdef __FreeBSD__ int fd; ATF_REQUIRE_MSG((fd = mkfifo(path, 0666)) == 0, "mkfifo failed: %s", strerror(errno)); (void)close(fd); -#else - ATF_REQUIRE(mkfifo(path, 0666) == 0); -#endif ATF_REQUIRE(unlink(path) == 0); errno = 0; diff --git a/contrib/netbsd-tests/lib/libc/sys/t_wait.c b/contrib/netbsd-tests/lib/libc/sys/t_wait.c index 86532652c6e6..9f749cb2daae 100644 --- a/contrib/netbsd-tests/lib/libc/sys/t_wait.c +++ b/contrib/netbsd-tests/lib/libc/sys/t_wait.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_wait.c,v 1.7 2016/11/06 15:04:14 kamil Exp $ */ +/* $NetBSD: t_wait.c,v 1.8 2017/01/13 19:28:55 christos Exp $ */ /*- * Copyright (c) 2016 The NetBSD Foundation, Inc. @@ -29,16 +29,17 @@ * POSSIBILITY OF SUCH DAMAGE. */ #include -__RCSID("$NetBSD: t_wait.c,v 1.7 2016/11/06 15:04:14 kamil Exp $"); +__RCSID("$NetBSD: t_wait.c,v 1.8 2017/01/13 19:28:55 christos Exp $"); #include #include -#include #include +#include #include #include #include +#include #include #include diff --git a/contrib/netbsd-tests/lib/libc/sys/t_write.c b/contrib/netbsd-tests/lib/libc/sys/t_write.c index a3783cb5deee..576ce7e7c0b5 100644 --- a/contrib/netbsd-tests/lib/libc/sys/t_write.c +++ b/contrib/netbsd-tests/lib/libc/sys/t_write.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_write.c,v 1.2 2011/10/19 16:19:30 jruoho Exp $ */ +/* $NetBSD: t_write.c,v 1.3 2017/01/13 19:27:23 christos Exp $ */ /*- * Copyright (c) 2001, 2008 The NetBSD Foundation, Inc. @@ -29,37 +29,27 @@ #include __COPYRIGHT("@(#) Copyright (c) 2008\ The NetBSD Foundation, inc. All rights reserved."); -__RCSID("$NetBSD: t_write.c,v 1.2 2011/10/19 16:19:30 jruoho Exp $"); +__RCSID("$NetBSD: t_write.c,v 1.3 2017/01/13 19:27:23 christos Exp $"); #include -#ifdef __NetBSD__ -#include -#endif #include #include #include #include +#include #include #include #include #include -#ifdef __FreeBSD__ -#include -#endif - static void sighandler(int); static bool fail = false; static const char *path = "write"; static void -#ifdef __FreeBSD__ sighandler(int signo __unused) -#else -sighandler(int signo) -#endif { fail = false; } diff --git a/contrib/netbsd-tests/lib/libm/t_ilogb.c b/contrib/netbsd-tests/lib/libm/t_ilogb.c index b3c212645603..4a36a610e538 100644 --- a/contrib/netbsd-tests/lib/libm/t_ilogb.c +++ b/contrib/netbsd-tests/lib/libm/t_ilogb.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_ilogb.c,v 1.6 2016/08/26 08:01:55 christos Exp $ */ +/* $NetBSD: t_ilogb.c,v 1.7 2017/01/13 19:23:40 christos Exp $ */ /*- * Copyright (c) 2016 The NetBSD Foundation, Inc. @@ -28,18 +28,21 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ +#include +__RCSID("$NetBSD: t_ilogb.c,v 1.7 2017/01/13 19:23:40 christos Exp $"); #ifdef __FreeBSD__ #include #endif #include #include +#include #include #ifndef __HAVE_FENV -# define ATF_CHECK_RAISED_INVALID -# define ATF_CHECK_RAISED_NOTHING +# define ATF_CHECK_RAISED_INVALID +# define ATF_CHECK_RAISED_NOTHING #else # define ATF_CHECK_RAISED_INVALID do { \ diff --git a/contrib/netbsd-tests/lib/libm/t_scalbn.c b/contrib/netbsd-tests/lib/libm/t_scalbn.c index fe70b3cd7382..4bf00c3415d1 100644 --- a/contrib/netbsd-tests/lib/libm/t_scalbn.c +++ b/contrib/netbsd-tests/lib/libm/t_scalbn.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_scalbn.c,v 1.11 2014/03/03 10:39:08 martin Exp $ */ +/* $NetBSD: t_scalbn.c,v 1.14 2017/01/13 21:09:12 agc Exp $ */ /*- * Copyright (c) 2011 The NetBSD Foundation, Inc. @@ -29,7 +29,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ #include -__RCSID("$NetBSD: t_scalbn.c,v 1.11 2014/03/03 10:39:08 martin Exp $"); +__RCSID("$NetBSD: t_scalbn.c,v 1.14 2017/01/13 21:09:12 agc Exp $"); #include #include @@ -81,9 +81,7 @@ ATF_TC_BODY(scalbn_val, tc) double rv; for (i = 0; i < tcnt; i++) { -#ifdef __FreeBSD__ errno = 0; -#endif rv = scalbn(tests[i].inval, tests[i].exp); ATF_CHECK_EQ_MSG(errno, tests[i].error, "test %zu: errno %d instead of %d", i, errno, @@ -225,9 +223,7 @@ ATF_TC_BODY(scalbnf_val, tc) double rv; for (i = 0; i < tcnt; i++) { -#ifdef __FreeBSD__ errno = 0; -#endif rv = scalbnf(tests[i].inval, tests[i].exp); ATF_CHECK_EQ_MSG(errno, tests[i].error, "test %zu: errno %d instead of %d", i, errno, @@ -372,9 +368,7 @@ ATF_TC_BODY(scalbnl_val, tc) long double rv; for (i = 0; i < tcnt; i++) { -#ifdef __FreeBSD__ errno = 0; -#endif rv = scalbnl(tests[i].inval, tests[i].exp); ATF_CHECK_EQ_MSG(errno, tests[i].error, "test %zu: errno %d instead of %d", i, errno, diff --git a/contrib/netbsd-tests/lib/libposix/t_rename.c b/contrib/netbsd-tests/lib/libposix/t_rename.c index 85b2b95b3a68..8c18ec50168d 100644 --- a/contrib/netbsd-tests/lib/libposix/t_rename.c +++ b/contrib/netbsd-tests/lib/libposix/t_rename.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_rename.c,v 1.2 2011/05/16 00:03:36 christos Exp $ */ +/* $NetBSD: t_rename.c,v 1.3 2017/01/13 21:30:41 christos Exp $ */ /* * Copyright (c) 2001, 2008, 2010 The NetBSD Foundation, Inc. @@ -29,7 +29,7 @@ #include __COPYRIGHT("@(#) Copyright (c) 2008, 2010\ The NetBSD Foundation, inc. All rights reserved."); -__RCSID("$NetBSD: t_rename.c,v 1.2 2011/05/16 00:03:36 christos Exp $"); +__RCSID("$NetBSD: t_rename.c,v 1.3 2017/01/13 21:30:41 christos Exp $"); #include #include @@ -43,7 +43,7 @@ __RCSID("$NetBSD: t_rename.c,v 1.2 2011/05/16 00:03:36 christos Exp $"); #include -#include "../../h_macros.h" +#include "h_macros.h" ATF_TC(rename); ATF_TC_HEAD(rename, tc) diff --git a/contrib/netbsd-tests/lib/libpthread_dbg/h_common.h b/contrib/netbsd-tests/lib/libpthread_dbg/h_common.h new file mode 100644 index 000000000000..0a02b963d436 --- /dev/null +++ b/contrib/netbsd-tests/lib/libpthread_dbg/h_common.h @@ -0,0 +1,128 @@ +/* $NetBSD: h_common.h,v 1.2 2016/11/19 02:30:54 kamil Exp $ */ + +/*- + * Copyright (c) 2016 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. + */ + + +#ifndef H_COMMON_H +#define H_COMMON_H + +#include +#include +#include +#include + +#include + +#define PTHREAD_REQUIRE(x) \ + do { \ + int ret = (x); \ + ATF_REQUIRE_MSG(ret == 0, "%s: %s", #x, strerror(ret)); \ + } while (0) + +#define PTHREAD_REQUIRE_STATUS(x, v) \ + do { \ + int ret = (x); \ + ATF_REQUIRE_MSG(ret == (v), "%s: %s", #x, strerror(ret)); \ + } while (0) + +static int __used +dummy_proc_read(void *arg, caddr_t addr, void *buf, size_t size) +{ + return TD_ERR_ERR; +} + +static int __used +dummy_proc_write(void *arg, caddr_t addr, void *buf, size_t size) +{ + return TD_ERR_ERR; +} + +static int __used +dummy_proc_lookup(void *arg, const char *sym, caddr_t *addr) +{ + return TD_ERR_ERR; +} + +static int __used +dummy_proc_regsize(void *arg, int regset, size_t *size) +{ + return TD_ERR_ERR; +} + +static int __used +dummy_proc_getregs(void *arg, int regset, int lwp, void *buf) +{ + return TD_ERR_ERR; +} + +static int __used +dummy_proc_setregs(void *arg, int regset, int lwp, void *buf) +{ + return TD_ERR_ERR; +} + +/* Minimalistic basic implementation */ + +static int __used +basic_proc_read(void *arg, caddr_t addr, void *buf, size_t size) +{ + memcpy(buf, addr, size); + + return TD_ERR_OK; +} + +static int __used +basic_proc_write(void *arg, caddr_t addr, void *buf, size_t size) +{ + memcpy(addr, buf, size); + + return TD_ERR_OK; +} + +static int __used +basic_proc_lookup(void *arg, const char *sym, caddr_t *addr) +{ + void *handle; + void *symbol; + + ATF_REQUIRE_MSG((handle = dlopen(NULL, RTLD_LOCAL | RTLD_LAZY)) + != NULL, "dlopen(3) failed: %s", dlerror()); + + symbol = dlsym(handle, sym); + + ATF_REQUIRE_MSG(dlclose(handle) == 0, "dlclose(3) failed: %s", + dlerror()); + + if (!symbol) + return TD_ERR_NOSYM; + + *addr = (caddr_t)(uintptr_t)symbol; + + return TD_ERR_OK; +} + +#endif // H_COMMON_H diff --git a/contrib/netbsd-tests/lib/libpthread_dbg/t_dummy.c b/contrib/netbsd-tests/lib/libpthread_dbg/t_dummy.c new file mode 100644 index 000000000000..367443cd0351 --- /dev/null +++ b/contrib/netbsd-tests/lib/libpthread_dbg/t_dummy.c @@ -0,0 +1,131 @@ +/* $NetBSD: t_dummy.c,v 1.6 2016/11/19 15:13:46 kamil Exp $ */ + +/*- + * Copyright (c) 2016 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. + */ + + +#include +__RCSID("$NetBSD: t_dummy.c,v 1.6 2016/11/19 15:13:46 kamil Exp $"); + +#include "h_common.h" +#include +#include + +#include + + +ATF_TC(dummy1); +ATF_TC_HEAD(dummy1, tc) +{ + + atf_tc_set_md_var(tc, "descr", + "Asserts that dummy lookup functions stop td_open() with failure"); +} + +ATF_TC_BODY(dummy1, tc) +{ + + struct td_proc_callbacks_t dummy_callbacks; + td_proc_t *main_ta; + + dummy_callbacks.proc_read = dummy_proc_read; + dummy_callbacks.proc_write = dummy_proc_write; + dummy_callbacks.proc_lookup = dummy_proc_lookup; + dummy_callbacks.proc_regsize = dummy_proc_regsize; + dummy_callbacks.proc_getregs = dummy_proc_getregs; + dummy_callbacks.proc_setregs = dummy_proc_setregs; + + ATF_REQUIRE(td_open(&dummy_callbacks, NULL, &main_ta) == TD_ERR_ERR); +} + +ATF_TC(dummy2); +ATF_TC_HEAD(dummy2, tc) +{ + + atf_tc_set_md_var(tc, "descr", + "Asserts that td_open() for basic proc_{read,write,lookup} works"); +} + +ATF_TC_BODY(dummy2, tc) +{ + struct td_proc_callbacks_t dummy_callbacks; + td_proc_t *main_ta; + + dummy_callbacks.proc_read = basic_proc_read; + dummy_callbacks.proc_write = basic_proc_write; + dummy_callbacks.proc_lookup = basic_proc_lookup; + dummy_callbacks.proc_regsize = dummy_proc_regsize; + dummy_callbacks.proc_getregs = dummy_proc_getregs; + dummy_callbacks.proc_setregs = dummy_proc_setregs; + + printf("Calling td_open(3)\n"); + ATF_REQUIRE(td_open(&dummy_callbacks, NULL, &main_ta) == TD_ERR_OK); + + printf("Calling td_close(3)\n"); + ATF_REQUIRE(td_close(main_ta) == TD_ERR_OK); +} + +ATF_TC(dummy3); +ATF_TC_HEAD(dummy3, tc) +{ + + atf_tc_set_md_var(tc, "descr", + "Asserts that calling twice td_open() for the same process fails"); +} + +ATF_TC_BODY(dummy3, tc) +{ + struct td_proc_callbacks_t dummy_callbacks; + td_proc_t *main_ta1; + td_proc_t *main_ta2; + + dummy_callbacks.proc_read = basic_proc_read; + dummy_callbacks.proc_write = basic_proc_write; + dummy_callbacks.proc_lookup = basic_proc_lookup; + dummy_callbacks.proc_regsize = dummy_proc_regsize; + dummy_callbacks.proc_getregs = dummy_proc_getregs; + dummy_callbacks.proc_setregs = dummy_proc_setregs; + + printf("Calling td_open(3) for the first time - expecting success\n"); + ATF_REQUIRE(td_open(&dummy_callbacks, NULL, &main_ta1) == TD_ERR_OK); + + printf("Calling td_open(3) for the first time - expecting in-use\n"); + ATF_REQUIRE(td_open(&dummy_callbacks, NULL, &main_ta2) == + TD_ERR_INUSE); + + printf("Calling td_close(3) for the first successful call\n"); + ATF_REQUIRE(td_close(main_ta1) == TD_ERR_OK); +} + +ATF_TP_ADD_TCS(tp) +{ + + ATF_TP_ADD_TC(tp, dummy1); + ATF_TP_ADD_TC(tp, dummy2); + ATF_TP_ADD_TC(tp, dummy3); + + return atf_no_error(); +} diff --git a/contrib/netbsd-tests/lib/libpthread_dbg/t_threads.c b/contrib/netbsd-tests/lib/libpthread_dbg/t_threads.c new file mode 100644 index 000000000000..f22bbc9c0563 --- /dev/null +++ b/contrib/netbsd-tests/lib/libpthread_dbg/t_threads.c @@ -0,0 +1,719 @@ +/* $NetBSD: t_threads.c,v 1.9 2017/01/13 05:18:22 christos Exp $ */ + +/*- + * Copyright (c) 2016 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. + */ + + +#include +__RCSID("$NetBSD: t_threads.c,v 1.9 2017/01/13 05:18:22 christos Exp $"); + +#include +#include +#include +#include +#include +#include + +#include + +#include "h_common.h" + +#define MAX_THREADS (size_t)10 + +ATF_TC(threads1); +ATF_TC_HEAD(threads1, tc) +{ + + atf_tc_set_md_var(tc, "descr", + "Asserts that td_thr_iter() call without extra logic works"); +} + +static volatile int exiting1; + +static void * +busyFunction1(void *arg) +{ + + while (exiting1 == 0) + usleep(50000); + + return NULL; +} + +static int +iterateThreads1(td_thread_t *thread, void *arg) +{ + + return TD_ERR_OK; +} + +ATF_TC_BODY(threads1, tc) +{ + struct td_proc_callbacks_t dummy_callbacks; + td_proc_t *main_ta; + size_t i; + pthread_t threads[MAX_THREADS]; + + dummy_callbacks.proc_read = basic_proc_read; + dummy_callbacks.proc_write = basic_proc_write; + dummy_callbacks.proc_lookup = basic_proc_lookup; + dummy_callbacks.proc_regsize = dummy_proc_regsize; + dummy_callbacks.proc_getregs = dummy_proc_getregs; + dummy_callbacks.proc_setregs = dummy_proc_setregs; + + for (i = 0; i < MAX_THREADS; i++) { + printf("Creating thread %zu\n", i); + PTHREAD_REQUIRE + (pthread_create(&threads[i], NULL, busyFunction1, NULL)); + } + + printf("Calling td_open(3)\n"); + ATF_REQUIRE(td_open(&dummy_callbacks, NULL, &main_ta) == TD_ERR_OK); + + ATF_REQUIRE(td_thr_iter(main_ta, iterateThreads1, NULL) == TD_ERR_OK); + + exiting1 = 1; + + printf("Calling td_close(3)\n"); + ATF_REQUIRE(td_close(main_ta) == TD_ERR_OK); +} + +ATF_TC(threads2); +ATF_TC_HEAD(threads2, tc) +{ + + atf_tc_set_md_var(tc, "descr", + "Asserts that td_thr_iter() call is executed for each thread once"); +} + +static volatile int exiting2; + +static void * +busyFunction2(void *arg) +{ + + while (exiting2 == 0) + usleep(50000); + + return NULL; +} + +static int +iterateThreads2(td_thread_t *thread, void *arg) +{ + int *counter = (int *)arg; + + ++(*counter); + + return TD_ERR_OK; +} + +ATF_TC_BODY(threads2, tc) +{ + struct td_proc_callbacks_t dummy_callbacks; + td_proc_t *main_ta; + size_t i; + pthread_t threads[MAX_THREADS]; + int count = 0; + + dummy_callbacks.proc_read = basic_proc_read; + dummy_callbacks.proc_write = basic_proc_write; + dummy_callbacks.proc_lookup = basic_proc_lookup; + dummy_callbacks.proc_regsize = dummy_proc_regsize; + dummy_callbacks.proc_getregs = dummy_proc_getregs; + dummy_callbacks.proc_setregs = dummy_proc_setregs; + + + for (i = 0; i < MAX_THREADS; i++) { + printf("Creating thread %zu\n", i); + PTHREAD_REQUIRE + (pthread_create(&threads[i], NULL, busyFunction2, NULL)); + } + + printf("Calling td_open(3)\n"); + ATF_REQUIRE(td_open(&dummy_callbacks, NULL, &main_ta) == TD_ERR_OK); + + ATF_REQUIRE(td_thr_iter(main_ta, iterateThreads2, &count) == TD_ERR_OK); + + exiting2 = 1; + + printf("Calling td_close(3)\n"); + ATF_REQUIRE(td_close(main_ta) == TD_ERR_OK); + + ATF_REQUIRE_EQ_MSG(count, MAX_THREADS + 1, + "counted threads (%d) != expected threads (%zu)", + count, MAX_THREADS + 1); +} + +ATF_TC(threads3); +ATF_TC_HEAD(threads3, tc) +{ + + atf_tc_set_md_var(tc, "descr", + "Asserts that for each td_thr_iter() call td_thr_info() is valid"); +} + +static volatile int exiting3; + +static void * +busyFunction3(void *arg) +{ + + while (exiting3 == 0) + usleep(50000); + + return NULL; +} + +static int +iterateThreads3(td_thread_t *thread, void *arg) +{ + int *counter = (int *)arg; + td_thread_info_t info; + + ATF_REQUIRE(td_thr_info(thread, &info) == TD_ERR_OK); + + ++(*counter); + + return TD_ERR_OK; +} + +ATF_TC_BODY(threads3, tc) +{ + struct td_proc_callbacks_t dummy_callbacks; + td_proc_t *main_ta; + size_t i; + pthread_t threads[MAX_THREADS]; + int count = 0; + + dummy_callbacks.proc_read = basic_proc_read; + dummy_callbacks.proc_write = basic_proc_write; + dummy_callbacks.proc_lookup = basic_proc_lookup; + dummy_callbacks.proc_regsize = dummy_proc_regsize; + dummy_callbacks.proc_getregs = dummy_proc_getregs; + dummy_callbacks.proc_setregs = dummy_proc_setregs; + + + for (i = 0; i < MAX_THREADS; i++) { + printf("Creating thread %zu\n", i); + PTHREAD_REQUIRE + (pthread_create(&threads[i], NULL, busyFunction3, NULL)); + } + + printf("Calling td_open(3)\n"); + ATF_REQUIRE(td_open(&dummy_callbacks, NULL, &main_ta) == TD_ERR_OK); + + ATF_REQUIRE(td_thr_iter(main_ta, iterateThreads3, &count) == TD_ERR_OK); + + exiting3 = 1; + + printf("Calling td_close(3)\n"); + ATF_REQUIRE(td_close(main_ta) == TD_ERR_OK); + + ATF_REQUIRE_EQ_MSG(count, MAX_THREADS + 1, + "counted threads (%d) != expected threads (%zu)", + count, MAX_THREADS + 1); +} + +ATF_TC(threads4); +ATF_TC_HEAD(threads4, tc) +{ + + atf_tc_set_md_var(tc, "descr", + "Asserts that for each td_thr_iter() call td_thr_getname() is " + "valid"); +} + +static volatile int exiting4; + +static void * +busyFunction4(void *arg) +{ + + while (exiting4 == 0) + usleep(50000); + + return NULL; +} + +static int +iterateThreads4(td_thread_t *thread, void *arg) +{ + int *counter = (int *)arg; + char name[PTHREAD_MAX_NAMELEN_NP]; + + ATF_REQUIRE(td_thr_getname(thread, name, sizeof(name)) == TD_ERR_OK); + + printf("Thread name: %s\n", name); + + ++(*counter); + + return TD_ERR_OK; +} + +ATF_TC_BODY(threads4, tc) +{ + struct td_proc_callbacks_t dummy_callbacks; + td_proc_t *main_ta; + size_t i; + pthread_t threads[MAX_THREADS]; + int count = 0; + + dummy_callbacks.proc_read = basic_proc_read; + dummy_callbacks.proc_write = basic_proc_write; + dummy_callbacks.proc_lookup = basic_proc_lookup; + dummy_callbacks.proc_regsize = dummy_proc_regsize; + dummy_callbacks.proc_getregs = dummy_proc_getregs; + dummy_callbacks.proc_setregs = dummy_proc_setregs; + + for (i = 0; i < MAX_THREADS; i++) { + printf("Creating thread %zu\n", i); + PTHREAD_REQUIRE + (pthread_create(&threads[i], NULL, busyFunction4, NULL)); + } + + for (i = 0; i < MAX_THREADS; i++) { + PTHREAD_REQUIRE + (pthread_setname_np(threads[i], "test_%d", (void*)i)); + } + + printf("Calling td_open(3)\n"); + ATF_REQUIRE(td_open(&dummy_callbacks, NULL, &main_ta) == TD_ERR_OK); + + ATF_REQUIRE(td_thr_iter(main_ta, iterateThreads4, &count) == TD_ERR_OK); + + exiting4 = 1; + + printf("Calling td_close(3)\n"); + ATF_REQUIRE(td_close(main_ta) == TD_ERR_OK); + + ATF_REQUIRE_EQ_MSG(count, MAX_THREADS + 1, + "counted threads (%d) != expected threads (%zu)", + count, MAX_THREADS + 1); +} + +ATF_TC(threads5); +ATF_TC_HEAD(threads5, tc) +{ + + atf_tc_set_md_var(tc, "descr", + "Asserts that td_thr_getname() handles shorter buffer parameter " + "and the result is properly truncated"); +} + +static volatile int exiting5; + +static void * +busyFunction5(void *arg) +{ + + while (exiting5 == 0) + usleep(50000); + + return NULL; +} + +static int +iterateThreads5(td_thread_t *thread, void *arg) +{ + int *counter = (int *)arg; + /* Arbitrarily short string buffer */ + char name[3]; + + ATF_REQUIRE(td_thr_getname(thread, name, sizeof(name)) == TD_ERR_OK); + + printf("Thread name: %s\n", name); + + /* strlen(3) does not count including a '\0' character */ + ATF_REQUIRE(strlen(name) < sizeof(name)); + + ++(*counter); + + return TD_ERR_OK; +} + +ATF_TC_BODY(threads5, tc) +{ + struct td_proc_callbacks_t dummy_callbacks; + td_proc_t *main_ta; + size_t i; + pthread_t threads[MAX_THREADS]; + int count = 0; + + dummy_callbacks.proc_read = basic_proc_read; + dummy_callbacks.proc_write = basic_proc_write; + dummy_callbacks.proc_lookup = basic_proc_lookup; + dummy_callbacks.proc_regsize = dummy_proc_regsize; + dummy_callbacks.proc_getregs = dummy_proc_getregs; + dummy_callbacks.proc_setregs = dummy_proc_setregs; + + for (i = 0; i < MAX_THREADS; i++) { + printf("Creating thread %zu\n", i); + PTHREAD_REQUIRE + (pthread_create(&threads[i], NULL, busyFunction5, NULL)); + } + + for (i = 0; i < MAX_THREADS; i++) { + PTHREAD_REQUIRE + (pthread_setname_np(threads[i], "test_%d", (void*)i)); + } + + printf("Calling td_open(3)\n"); + ATF_REQUIRE(td_open(&dummy_callbacks, NULL, &main_ta) == TD_ERR_OK); + + ATF_REQUIRE(td_thr_iter(main_ta, iterateThreads5, &count) == TD_ERR_OK); + + exiting5 = 1; + + printf("Calling td_close(3)\n"); + ATF_REQUIRE(td_close(main_ta) == TD_ERR_OK); + + ATF_REQUIRE_EQ_MSG(count, MAX_THREADS + 1, + "counted threads (%d) != expected threads (%zu)", + count, MAX_THREADS + 1); +} + +ATF_TC(threads6); +ATF_TC_HEAD(threads6, tc) +{ + + atf_tc_set_md_var(tc, "descr", + "Asserts that pthread_t can be translated with td_map_pth2thr() " + "to td_thread_t -- and assert earlier that td_thr_iter() call is " + "valid"); +} + +static volatile int exiting6; + +static void * +busyFunction6(void *arg) +{ + + while (exiting6 == 0) + usleep(50000); + + return NULL; +} + +static int +iterateThreads6(td_thread_t *thread, void *arg) +{ + int *counter = (int *)arg; + + ++(*counter); + + return TD_ERR_OK; +} + +ATF_TC_BODY(threads6, tc) +{ + struct td_proc_callbacks_t dummy_callbacks; + td_proc_t *main_ta; + size_t i; + pthread_t threads[MAX_THREADS]; + int count = 0; + + dummy_callbacks.proc_read = basic_proc_read; + dummy_callbacks.proc_write = basic_proc_write; + dummy_callbacks.proc_lookup = basic_proc_lookup; + dummy_callbacks.proc_regsize = dummy_proc_regsize; + dummy_callbacks.proc_getregs = dummy_proc_getregs; + dummy_callbacks.proc_setregs = dummy_proc_setregs; + + for (i = 0; i < MAX_THREADS; i++) { + printf("Creating thread %zu\n", i); + PTHREAD_REQUIRE + (pthread_create(&threads[i], NULL, busyFunction6, NULL)); + } + + printf("Calling td_open(3)\n"); + ATF_REQUIRE(td_open(&dummy_callbacks, NULL, &main_ta) == TD_ERR_OK); + + ATF_REQUIRE(td_thr_iter(main_ta, iterateThreads6, &count) == TD_ERR_OK); + + for (i = 0; i < MAX_THREADS; i++) { + td_thread_t *td_thread; + ATF_REQUIRE(td_map_pth2thr(main_ta, threads[i], &td_thread) + == TD_ERR_OK); + } + + exiting6 = 1; + + printf("Calling td_close(3)\n"); + ATF_REQUIRE(td_close(main_ta) == TD_ERR_OK); + + ATF_REQUIRE_EQ_MSG(count, MAX_THREADS + 1, + "counted threads (%d) != expected threads (%zu)", + count, MAX_THREADS + 1); +} + +ATF_TC(threads7); +ATF_TC_HEAD(threads7, tc) +{ + + atf_tc_set_md_var(tc, "descr", + "Asserts that pthread_t can be translated with td_map_pth2thr() " + "to td_thread_t -- and assert later that td_thr_iter() call is " + "valid"); +} + +static volatile int exiting7; + +static void * +busyFunction7(void *arg) +{ + + while (exiting7 == 0) + usleep(50000); + + return NULL; +} + +static int +iterateThreads7(td_thread_t *thread, void *arg) +{ + int *counter = (int *)arg; + + ++(*counter); + + return TD_ERR_OK; +} + +ATF_TC_BODY(threads7, tc) +{ + struct td_proc_callbacks_t dummy_callbacks; + td_proc_t *main_ta; + size_t i; + pthread_t threads[MAX_THREADS]; + int count = 0; + + dummy_callbacks.proc_read = basic_proc_read; + dummy_callbacks.proc_write = basic_proc_write; + dummy_callbacks.proc_lookup = basic_proc_lookup; + dummy_callbacks.proc_regsize = dummy_proc_regsize; + dummy_callbacks.proc_getregs = dummy_proc_getregs; + dummy_callbacks.proc_setregs = dummy_proc_setregs; + + for (i = 0; i < MAX_THREADS; i++) { + printf("Creating thread %zu\n", i); + PTHREAD_REQUIRE + (pthread_create(&threads[i], NULL, busyFunction7, NULL)); + } + + printf("Calling td_open(3)\n"); + ATF_REQUIRE(td_open(&dummy_callbacks, NULL, &main_ta) == TD_ERR_OK); + + for (i = 0; i < MAX_THREADS; i++) { + td_thread_t *td_thread; + ATF_REQUIRE(td_map_pth2thr(main_ta, threads[i], &td_thread) + == TD_ERR_OK); + } + + ATF_REQUIRE(td_thr_iter(main_ta, iterateThreads7, &count) == TD_ERR_OK); + + exiting7 = 1; + + printf("Calling td_close(3)\n"); + ATF_REQUIRE(td_close(main_ta) == TD_ERR_OK); + + ATF_REQUIRE_EQ_MSG(count, MAX_THREADS + 1, + "counted threads (%d) != expected threads (%zu)", + count, MAX_THREADS + 1); +} + +ATF_TC(threads8); +ATF_TC_HEAD(threads8, tc) +{ + + atf_tc_set_md_var(tc, "descr", + "Asserts that pthread_t can be translated with td_map_pth2thr() " + "to td_thread_t -- compare thread's name of pthread_t and " + "td_thread_t"); +} + +static volatile int exiting8; + +static void * +busyFunction8(void *arg) +{ + + while (exiting8 == 0) + usleep(50000); + + return NULL; +} + +static int +iterateThreads8(td_thread_t *thread, void *arg) +{ + int *counter = (int *)arg; + + ++(*counter); + + return TD_ERR_OK; +} + +ATF_TC_BODY(threads8, tc) +{ + struct td_proc_callbacks_t dummy_callbacks; + td_proc_t *main_ta; + size_t i; + pthread_t threads[MAX_THREADS]; + int count = 0; + + dummy_callbacks.proc_read = basic_proc_read; + dummy_callbacks.proc_write = basic_proc_write; + dummy_callbacks.proc_lookup = basic_proc_lookup; + dummy_callbacks.proc_regsize = dummy_proc_regsize; + dummy_callbacks.proc_getregs = dummy_proc_getregs; + dummy_callbacks.proc_setregs = dummy_proc_setregs; + + for (i = 0; i < MAX_THREADS; i++) { + printf("Creating thread %zu\n", i); + PTHREAD_REQUIRE + (pthread_create(&threads[i], NULL, busyFunction8, NULL)); + } + + printf("Calling td_open(3)\n"); + ATF_REQUIRE(td_open(&dummy_callbacks, NULL, &main_ta) == TD_ERR_OK); + + ATF_REQUIRE(td_thr_iter(main_ta, iterateThreads8, &count) == TD_ERR_OK); + + for (i = 0; i < MAX_THREADS; i++) { + td_thread_t *td_thread; + char td_threadname[PTHREAD_MAX_NAMELEN_NP]; + char pth_threadname[PTHREAD_MAX_NAMELEN_NP]; + ATF_REQUIRE(td_map_pth2thr(main_ta, threads[i], &td_thread) + == TD_ERR_OK); + ATF_REQUIRE(td_thr_getname(td_thread, td_threadname, + sizeof(td_threadname)) == TD_ERR_OK); + PTHREAD_REQUIRE(pthread_getname_np(threads[i], pth_threadname, + sizeof(pth_threadname))); + ATF_REQUIRE(strcmp(td_threadname, pth_threadname) == 0); + } + + exiting8 = 1; + + printf("Calling td_close(3)\n"); + ATF_REQUIRE(td_close(main_ta) == TD_ERR_OK); + + ATF_REQUIRE_EQ_MSG(count, MAX_THREADS + 1, + "counted threads (%d) != expected threads (%zu)", + count, MAX_THREADS + 1); +} + +ATF_TC(threads9); +ATF_TC_HEAD(threads9, tc) +{ + + atf_tc_set_md_var(tc, "descr", + "Asserts that pthread_t can be translated with td_map_pth2thr() " + "to td_thread_t -- assert that thread is in the TD_STATE_RUNNING " + "state"); +} + +static volatile int exiting9; + +static void * +busyFunction9(void *arg) +{ + + while (exiting9 == 0) + usleep(50000); + + return NULL; +} + +static int +iterateThreads9(td_thread_t *thread, void *arg) +{ + int *counter = (int *)arg; + + ++(*counter); + + return TD_ERR_OK; +} + +ATF_TC_BODY(threads9, tc) +{ + struct td_proc_callbacks_t dummy_callbacks; + td_proc_t *main_ta; + size_t i; + pthread_t threads[MAX_THREADS]; + int count = 0; + + dummy_callbacks.proc_read = basic_proc_read; + dummy_callbacks.proc_write = basic_proc_write; + dummy_callbacks.proc_lookup = basic_proc_lookup; + dummy_callbacks.proc_regsize = dummy_proc_regsize; + dummy_callbacks.proc_getregs = dummy_proc_getregs; + dummy_callbacks.proc_setregs = dummy_proc_setregs; + + for (i = 0; i < MAX_THREADS; i++) { + printf("Creating thread %zu\n", i); + PTHREAD_REQUIRE + (pthread_create(&threads[i], NULL, busyFunction9, NULL)); + } + + printf("Calling td_open(3)\n"); + ATF_REQUIRE(td_open(&dummy_callbacks, NULL, &main_ta) == TD_ERR_OK); + + for (i = 0; i < MAX_THREADS; i++) { + td_thread_t *td_thread; + td_thread_info_t info; + ATF_REQUIRE(td_map_pth2thr(main_ta, threads[i], &td_thread) + == TD_ERR_OK); + ATF_REQUIRE(td_thr_info(td_thread, &info) == TD_ERR_OK); + ATF_REQUIRE_EQ(info.thread_state, TD_STATE_RUNNING); + } + + ATF_REQUIRE(td_thr_iter(main_ta, iterateThreads9, &count) == TD_ERR_OK); + + exiting9 = 1; + + printf("Calling td_close(3)\n"); + ATF_REQUIRE(td_close(main_ta) == TD_ERR_OK); + + ATF_REQUIRE_EQ_MSG(count, MAX_THREADS + 1, + "counted threads (%d) != expected threads (%zu)", + count, MAX_THREADS + 1); +} + +ATF_TP_ADD_TCS(tp) +{ + + ATF_TP_ADD_TC(tp, threads1); + ATF_TP_ADD_TC(tp, threads2); + ATF_TP_ADD_TC(tp, threads3); + ATF_TP_ADD_TC(tp, threads4); + ATF_TP_ADD_TC(tp, threads5); + ATF_TP_ADD_TC(tp, threads6); + ATF_TP_ADD_TC(tp, threads7); + ATF_TP_ADD_TC(tp, threads8); + ATF_TP_ADD_TC(tp, threads9); + + return atf_no_error(); +} diff --git a/contrib/netbsd-tests/lib/librefuse/t_refuse_opt.c b/contrib/netbsd-tests/lib/librefuse/t_refuse_opt.c new file mode 100644 index 000000000000..23c2803f8552 --- /dev/null +++ b/contrib/netbsd-tests/lib/librefuse/t_refuse_opt.c @@ -0,0 +1,418 @@ +/* $NetBSD: t_refuse_opt.c,v 1.8 2017/01/13 21:30:41 christos Exp $ */ + +/*- + * Copyright (c) 2016 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. + */ +#include +__RCSID("$NetBSD: t_refuse_opt.c,v 1.8 2017/01/13 21:30:41 christos Exp $"); + +#define _KERNTYPES +#include + +#include + +#include + +#include "h_macros.h" + +ATF_TC(t_fuse_opt_add_arg); +ATF_TC_HEAD(t_fuse_opt_add_arg, tc) +{ + atf_tc_set_md_var(tc, "descr", "Check that fuse_opt_add_arg(3) works"); +} + +ATF_TC_BODY(t_fuse_opt_add_arg, tc) +{ + struct fuse_args args = FUSE_ARGS_INIT(0, NULL); + + RZ(fuse_opt_add_arg(&args, "foo")); + RZ(fuse_opt_add_arg(&args, "bar")); + + ATF_REQUIRE_EQ(args.argc, 2); + ATF_CHECK_STREQ(args.argv[0], "foo"); + ATF_CHECK_STREQ(args.argv[1], "bar"); + ATF_CHECK(args.allocated != 0); +} + +ATF_TC(t_fuse_opt_insert_arg); +ATF_TC_HEAD(t_fuse_opt_insert_arg, tc) +{ + atf_tc_set_md_var(tc, "descr", "Check that fuse_opt_insert_arg(3) works"); +} + +ATF_TC_BODY(t_fuse_opt_insert_arg, tc) +{ + struct fuse_args args = FUSE_ARGS_INIT(0, NULL); + + RZ(fuse_opt_insert_arg(&args, 0, "foo")); + RZ(fuse_opt_insert_arg(&args, 0, "bar")); + + ATF_REQUIRE_EQ(args.argc, 2); + ATF_CHECK_STREQ(args.argv[0], "bar"); + ATF_CHECK_STREQ(args.argv[1], "foo"); + ATF_CHECK(args.allocated != 0); +} + +ATF_TC(t_fuse_opt_add_opt); +ATF_TC_HEAD(t_fuse_opt_add_opt, tc) +{ + atf_tc_set_md_var(tc, "descr", "Check that fuse_opt_add_opt(3) works"); +} + +ATF_TC_BODY(t_fuse_opt_add_opt, tc) +{ + char* opt = NULL; + + RZ(fuse_opt_add_opt(&opt, "fo\\o")); + ATF_CHECK_STREQ(opt, "fo\\o"); + + RZ(fuse_opt_add_opt(&opt, "ba,r")); + ATF_CHECK_STREQ(opt, "fo\\o,ba,r"); +} + +ATF_TC(t_fuse_opt_add_opt_escaped); +ATF_TC_HEAD(t_fuse_opt_add_opt_escaped, tc) +{ + atf_tc_set_md_var(tc, "descr", "Check that fuse_opt_add_opt_escaped(3) works"); +} + +ATF_TC_BODY(t_fuse_opt_add_opt_escaped, tc) +{ + char* opt = NULL; + + RZ(fuse_opt_add_opt_escaped(&opt, "fo\\o")); + ATF_CHECK_STREQ(opt, "fo\\\\o"); + + RZ(fuse_opt_add_opt_escaped(&opt, "ba,r")); + ATF_CHECK_STREQ(opt, "fo\\\\o,ba\\,r"); +} + +ATF_TC(t_fuse_opt_match); +ATF_TC_HEAD(t_fuse_opt_match, tc) +{ + atf_tc_set_md_var(tc, "descr", "Check that fuse_opt_match(3) works" + " for every form of templates"); +} + +ATF_TC_BODY(t_fuse_opt_match, tc) +{ + struct fuse_opt o1[] = { FUSE_OPT_KEY("-x" , 0), FUSE_OPT_END }; + struct fuse_opt o2[] = { FUSE_OPT_KEY("foo" , 0), FUSE_OPT_END }; + struct fuse_opt o3[] = { FUSE_OPT_KEY("foo=" , 0), FUSE_OPT_END }; + struct fuse_opt o4[] = { FUSE_OPT_KEY("foo=%s", 0), FUSE_OPT_END }; + struct fuse_opt o5[] = { FUSE_OPT_KEY("-x " , 0), FUSE_OPT_END }; + struct fuse_opt o6[] = { FUSE_OPT_KEY("-x %s" , 0), FUSE_OPT_END }; + + ATF_CHECK(fuse_opt_match(o1, "-x") == 1); + ATF_CHECK(fuse_opt_match(o1, "x") == 0); + + ATF_CHECK(fuse_opt_match(o2, "foo") == 1); + ATF_CHECK(fuse_opt_match(o2, "-foo") == 0); + + ATF_CHECK(fuse_opt_match(o3, "foo=bar") == 1); + ATF_CHECK(fuse_opt_match(o3, "foo" ) == 0); + + ATF_CHECK(fuse_opt_match(o4, "foo=bar") == 1); + ATF_CHECK(fuse_opt_match(o4, "foo" ) == 0); + + ATF_CHECK(fuse_opt_match(o5, "-xbar" ) == 1); + ATF_CHECK(fuse_opt_match(o5, "-x" ) == 1); + ATF_CHECK(fuse_opt_match(o5, "-x=bar") == 1); + ATF_CHECK(fuse_opt_match(o5, "bar" ) == 0); + + ATF_CHECK(fuse_opt_match(o6, "-xbar" ) == 1); + ATF_CHECK(fuse_opt_match(o6, "-x" ) == 1); + ATF_CHECK(fuse_opt_match(o6, "-x=bar") == 1); + ATF_CHECK(fuse_opt_match(o6, "bar" ) == 0); +} + +struct foofs_config { + int number; + char *string; + char* nonopt; +}; + +#define FOOFS_OPT(t, p, v) { t, offsetof(struct foofs_config, p), v } + +static struct fuse_opt foofs_opts[] = { + FOOFS_OPT("number=%i" , number, 0), + FOOFS_OPT("-n %i" , number, 0), + FOOFS_OPT("string=%s" , string, 0), + FOOFS_OPT("number1" , number, 1), + FOOFS_OPT("number2" , number, 2), + FOOFS_OPT("--number=three", number, 3), + FOOFS_OPT("--number=four" , number, 4), + FUSE_OPT_END +}; + +static int foo_opt_proc(void *data, const char *arg, int key, struct fuse_args *outargs) { + struct foofs_config *config = data; + + if (key == FUSE_OPT_KEY_NONOPT && config->nonopt == NULL) { + config->nonopt = strdup(arg); + return 0; + } + else { + return 1; + } +} + +ATF_TC(t_fuse_opt_parse_null_args); +ATF_TC_HEAD(t_fuse_opt_parse_null_args, tc) +{ + atf_tc_set_md_var(tc, "descr", "NULL args means an empty arguments vector"); +} + +ATF_TC_BODY(t_fuse_opt_parse_null_args, tc) +{ + struct foofs_config config; + + memset(&config, 0, sizeof(config)); + ATF_CHECK(fuse_opt_parse(NULL, &config, NULL, NULL) == 0); + ATF_CHECK_EQ(config.number, 0); + ATF_CHECK_EQ(config.string, NULL); + ATF_CHECK_EQ(config.nonopt, NULL); +} + +ATF_TC(t_fuse_opt_parse_null_opts); +ATF_TC_HEAD(t_fuse_opt_parse_null_opts, tc) +{ + atf_tc_set_md_var(tc, "descr", "NULL opts means an opts array which only has FUSE_OPT_END"); +} + +ATF_TC_BODY(t_fuse_opt_parse_null_opts, tc) +{ + struct fuse_args args = FUSE_ARGS_INIT(0, NULL); + struct foofs_config config; + + RZ(fuse_opt_add_arg(&args, "foofs")); + RZ(fuse_opt_add_arg(&args, "-o")); + RZ(fuse_opt_add_arg(&args, "number=1,string=foo")); + RZ(fuse_opt_add_arg(&args, "bar")); + + memset(&config, 0, sizeof(config)); + ATF_CHECK(fuse_opt_parse(&args, &config, NULL, NULL) == 0); + ATF_CHECK_EQ(config.number, 0); + ATF_CHECK_EQ(config.string, NULL); + ATF_CHECK_EQ(config.nonopt, NULL); + ATF_CHECK_EQ(args.argc, 4); + ATF_CHECK_STREQ(args.argv[0], "foofs"); + ATF_CHECK_STREQ(args.argv[1], "-o"); + ATF_CHECK_STREQ(args.argv[2], "number=1,string=foo"); + ATF_CHECK_STREQ(args.argv[3], "bar"); +} + +ATF_TC(t_fuse_opt_parse_null_proc); +ATF_TC_HEAD(t_fuse_opt_parse_null_proc, tc) +{ + atf_tc_set_md_var(tc, "descr", "NULL proc means a processor function always returning 1," + " i.e. keep the argument"); +} + +ATF_TC_BODY(t_fuse_opt_parse_null_proc, tc) +{ + struct fuse_args args = FUSE_ARGS_INIT(0, NULL); + struct foofs_config config; + + RZ(fuse_opt_add_arg(&args, "foofs")); + RZ(fuse_opt_add_arg(&args, "-o")); + RZ(fuse_opt_add_arg(&args, "number=1,string=foo")); + RZ(fuse_opt_add_arg(&args, "bar")); + + memset(&config, 0, sizeof(config)); + ATF_CHECK(fuse_opt_parse(&args, &config, foofs_opts, NULL) == 0); + ATF_CHECK_EQ(config.number, 1); + ATF_CHECK_STREQ(config.string, "foo"); + ATF_CHECK_EQ(config.nonopt, NULL); + ATF_CHECK_EQ(args.argc, 2); + ATF_CHECK_STREQ(args.argv[0], "foofs"); + ATF_CHECK_STREQ(args.argv[1], "bar"); +} + +ATF_TC(t_fuse_opt_parse); +ATF_TC_HEAD(t_fuse_opt_parse, tc) +{ + atf_tc_set_md_var(tc, "descr", "Check that fuse_opt_parse(3) fully works"); +} + +ATF_TC_BODY(t_fuse_opt_parse, tc) +{ + struct fuse_args args = FUSE_ARGS_INIT(0, NULL); + struct foofs_config config; + + /* Standard form */ + fuse_opt_free_args(&args); + RZ(fuse_opt_add_arg(&args, "foofs")); + RZ(fuse_opt_add_arg(&args, "-o")); + RZ(fuse_opt_add_arg(&args, "number=1,string=foo")); + RZ(fuse_opt_add_arg(&args, "bar")); + + memset(&config, 0, sizeof(config)); + ATF_CHECK(fuse_opt_parse(&args, &config, foofs_opts, foo_opt_proc) == 0); + ATF_CHECK_EQ(config.number, 1); + ATF_CHECK_STREQ(config.string, "foo"); + ATF_CHECK_STREQ(config.nonopt, "bar"); + ATF_CHECK_EQ(args.argc, 1); + ATF_CHECK_STREQ(args.argv[0], "foofs"); + + /* Concatenated -o */ + fuse_opt_free_args(&args); + RZ(fuse_opt_add_arg(&args, "foofs")); + RZ(fuse_opt_add_arg(&args, "-onumber=1,unknown,string=foo")); + RZ(fuse_opt_add_arg(&args, "bar")); + + memset(&config, 0, sizeof(config)); + ATF_CHECK(fuse_opt_parse(&args, &config, foofs_opts, foo_opt_proc) == 0); + ATF_CHECK_EQ(config.number, 1); + ATF_CHECK_STREQ(config.string, "foo"); + ATF_CHECK_STREQ(config.nonopt, "bar"); + ATF_CHECK_EQ(args.argc, 3); + ATF_CHECK_STREQ(args.argv[0], "foofs"); + ATF_CHECK_STREQ(args.argv[1], "-o"); + ATF_CHECK_STREQ(args.argv[2], "unknown"); + + /* Sparse -o */ + fuse_opt_free_args(&args); + RZ(fuse_opt_add_arg(&args, "foofs")); + RZ(fuse_opt_add_arg(&args, "bar")); + RZ(fuse_opt_add_arg(&args, "baz")); + RZ(fuse_opt_add_arg(&args, "-o")); + RZ(fuse_opt_add_arg(&args, "number=1")); + RZ(fuse_opt_add_arg(&args, "-o")); + RZ(fuse_opt_add_arg(&args, "unknown")); + RZ(fuse_opt_add_arg(&args, "-o")); + RZ(fuse_opt_add_arg(&args, "string=foo")); + + memset(&config, 0, sizeof(config)); + ATF_CHECK(fuse_opt_parse(&args, &config, foofs_opts, foo_opt_proc) == 0); + ATF_CHECK_EQ(config.number, 1); + ATF_CHECK_STREQ(config.string, "foo"); + ATF_CHECK_STREQ(config.nonopt, "bar"); + ATF_CHECK_EQ(args.argc, 4); + ATF_CHECK_STREQ(args.argv[0], "foofs"); + ATF_CHECK_STREQ(args.argv[1], "-o"); + ATF_CHECK_STREQ(args.argv[2], "unknown"); + ATF_CHECK_STREQ(args.argv[3], "baz"); + + /* Separate -n %i */ + fuse_opt_free_args(&args); + RZ(fuse_opt_add_arg(&args, "foofs")); + RZ(fuse_opt_add_arg(&args, "-n")); + RZ(fuse_opt_add_arg(&args, "3")); + + memset(&config, 0, sizeof(config)); + ATF_CHECK(fuse_opt_parse(&args, &config, foofs_opts, foo_opt_proc) == 0); + ATF_CHECK_EQ(config.number, 3); + ATF_CHECK_EQ(config.string, NULL); + ATF_CHECK_EQ(config.nonopt, NULL); + ATF_CHECK_EQ(args.argc, 1); + ATF_CHECK_STREQ(args.argv[0], "foofs"); + + /* Concatenated -n %i */ + fuse_opt_free_args(&args); + RZ(fuse_opt_add_arg(&args, "foofs")); + RZ(fuse_opt_add_arg(&args, "-n3")); + + memset(&config, 0, sizeof(config)); + ATF_CHECK(fuse_opt_parse(&args, &config, foofs_opts, foo_opt_proc) == 0); + ATF_CHECK_EQ(config.number, 3); + ATF_CHECK_EQ(config.string, NULL); + ATF_CHECK_EQ(config.nonopt, NULL); + ATF_CHECK_EQ(args.argc, 1); + ATF_CHECK_STREQ(args.argv[0], "foofs"); + + /* -o constant */ + fuse_opt_free_args(&args); + RZ(fuse_opt_add_arg(&args, "foofs")); + RZ(fuse_opt_add_arg(&args, "-o")); + RZ(fuse_opt_add_arg(&args, "number2")); + + memset(&config, 0, sizeof(config)); + ATF_CHECK(fuse_opt_parse(&args, &config, foofs_opts, foo_opt_proc) == 0); + ATF_CHECK_EQ(config.number, 2); + ATF_CHECK_EQ(config.string, NULL); + ATF_CHECK_EQ(config.nonopt, NULL); + ATF_CHECK_EQ(args.argc, 1); + ATF_CHECK_STREQ(args.argv[0], "foofs"); + + /* -x constant */ + fuse_opt_free_args(&args); + RZ(fuse_opt_add_arg(&args, "foofs")); + RZ(fuse_opt_add_arg(&args, "--number=four")); + + memset(&config, 0, sizeof(config)); + ATF_CHECK(fuse_opt_parse(&args, &config, foofs_opts, foo_opt_proc) == 0); + ATF_CHECK_EQ(config.number, 4); + ATF_CHECK_EQ(config.string, NULL); + ATF_CHECK_EQ(config.nonopt, NULL); + ATF_CHECK_EQ(args.argc, 1); + ATF_CHECK_STREQ(args.argv[0], "foofs"); + + /* end-of-options "--" marker */ + fuse_opt_free_args(&args); + RZ(fuse_opt_add_arg(&args, "foofs")); + RZ(fuse_opt_add_arg(&args, "--")); + RZ(fuse_opt_add_arg(&args, "-onumber=1")); + RZ(fuse_opt_add_arg(&args, "-ostring=foo")); + + memset(&config, 0, sizeof(config)); + ATF_CHECK(fuse_opt_parse(&args, &config, foofs_opts, foo_opt_proc) == 0); + ATF_CHECK_EQ(config.number, 0); + ATF_CHECK_EQ(config.string, NULL); + ATF_CHECK_STREQ(config.nonopt, "-onumber=1"); + ATF_CHECK_EQ(args.argc, 3); + ATF_CHECK_STREQ(args.argv[0], "foofs"); + ATF_CHECK_STREQ(args.argv[1], "--"); + ATF_CHECK_STREQ(args.argv[2], "-ostring=foo"); + + /* The "--" marker at the last of outargs should be removed */ + fuse_opt_free_args(&args); + RZ(fuse_opt_add_arg(&args, "foofs")); + RZ(fuse_opt_add_arg(&args, "--")); + RZ(fuse_opt_add_arg(&args, "-onumber=1")); + + memset(&config, 0, sizeof(config)); + ATF_CHECK(fuse_opt_parse(&args, &config, foofs_opts, foo_opt_proc) == 0); + ATF_CHECK_EQ(config.number, 0); + ATF_CHECK_EQ(config.string, NULL); + ATF_CHECK_STREQ(config.nonopt, "-onumber=1"); + ATF_CHECK_EQ(args.argc, 1); + ATF_CHECK_STREQ(args.argv[0], "foofs"); +} + +ATF_TP_ADD_TCS(tp) +{ + ATF_TP_ADD_TC(tp, t_fuse_opt_add_arg); + ATF_TP_ADD_TC(tp, t_fuse_opt_insert_arg); + ATF_TP_ADD_TC(tp, t_fuse_opt_add_opt); + ATF_TP_ADD_TC(tp, t_fuse_opt_add_opt_escaped); + ATF_TP_ADD_TC(tp, t_fuse_opt_match); + ATF_TP_ADD_TC(tp, t_fuse_opt_parse_null_args); + ATF_TP_ADD_TC(tp, t_fuse_opt_parse_null_opts); + ATF_TP_ADD_TC(tp, t_fuse_opt_parse_null_proc); + ATF_TP_ADD_TC(tp, t_fuse_opt_parse); + + return atf_no_error(); +} diff --git a/contrib/netbsd-tests/lib/librumpclient/t_fd.c b/contrib/netbsd-tests/lib/librumpclient/t_fd.c index 6e6d9470e7a1..70182ab8c515 100644 --- a/contrib/netbsd-tests/lib/librumpclient/t_fd.c +++ b/contrib/netbsd-tests/lib/librumpclient/t_fd.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_fd.c,v 1.5 2016/08/10 21:10:18 kre Exp $ */ +/* $NetBSD: t_fd.c,v 1.6 2017/01/13 21:30:41 christos Exp $ */ /* * Copyright (c) 2011 The NetBSD Foundation, Inc. @@ -42,7 +42,7 @@ #include #include -#include "../../h_macros.h" +#include "h_macros.h" ATF_TC_WITH_CLEANUP(bigenough); ATF_TC_HEAD(bigenough, tc) diff --git a/contrib/netbsd-tests/lib/semaphore/sem.c b/contrib/netbsd-tests/lib/semaphore/sem.c index 5967b88d3fff..6af9b0d97bd3 100644 --- a/contrib/netbsd-tests/lib/semaphore/sem.c +++ b/contrib/netbsd-tests/lib/semaphore/sem.c @@ -1,4 +1,4 @@ -/* $NetBSD: sem.c,v 1.10 2012/03/09 14:25:34 joerg Exp $ */ +/* $NetBSD: sem.c,v 1.11 2017/01/13 21:30:42 christos Exp $ */ /* * Common code for semaphore tests. This can be included both into @@ -21,7 +21,7 @@ #include #include -#include "../../h_macros.h" +#include "h_macros.h" ATF_TC(postwait); ATF_TC_HEAD(postwait, tc) diff --git a/contrib/netbsd-tests/libexec/ld.elf_so/t_dlerror-cleared.c b/contrib/netbsd-tests/libexec/ld.elf_so/t_dlerror-cleared.c index 03940c2de013..47c7f55bb285 100644 --- a/contrib/netbsd-tests/libexec/ld.elf_so/t_dlerror-cleared.c +++ b/contrib/netbsd-tests/libexec/ld.elf_so/t_dlerror-cleared.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_dlerror-cleared.c,v 1.1 2010/12/14 05:57:32 skrll Exp $ */ +/* $NetBSD: t_dlerror-cleared.c,v 1.2 2017/01/13 21:30:42 christos Exp $ */ /* * Copyright (c) 2009 The NetBSD Foundation, Inc. @@ -33,7 +33,7 @@ #include #include -#include "../../h_macros.h" +#include "h_macros.h" ATF_TC(rtld_dlerror_cleared); ATF_TC_HEAD(rtld_dlerror_cleared, tc) diff --git a/contrib/netbsd-tests/libexec/ld.elf_so/t_dlerror-false.c b/contrib/netbsd-tests/libexec/ld.elf_so/t_dlerror-false.c index 8b80c260d630..31b96e8c18c1 100644 --- a/contrib/netbsd-tests/libexec/ld.elf_so/t_dlerror-false.c +++ b/contrib/netbsd-tests/libexec/ld.elf_so/t_dlerror-false.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_dlerror-false.c,v 1.1 2010/12/14 05:57:32 skrll Exp $ */ +/* $NetBSD: t_dlerror-false.c,v 1.2 2017/01/13 21:30:42 christos Exp $ */ /* * Copyright (c) 2009 The NetBSD Foundation, Inc. @@ -33,7 +33,7 @@ #include #include -#include "../../h_macros.h" +#include "h_macros.h" ATF_TC(rtld_dlerror_false); ATF_TC_HEAD(rtld_dlerror_false, tc) diff --git a/contrib/netbsd-tests/libexec/ld.elf_so/t_dlinfo.c b/contrib/netbsd-tests/libexec/ld.elf_so/t_dlinfo.c index a15ba5d5a909..7b12528f9f54 100644 --- a/contrib/netbsd-tests/libexec/ld.elf_so/t_dlinfo.c +++ b/contrib/netbsd-tests/libexec/ld.elf_so/t_dlinfo.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_dlinfo.c,v 1.4 2011/03/25 14:47:31 pooka Exp $ */ +/* $NetBSD: t_dlinfo.c,v 1.5 2017/01/13 21:30:42 christos Exp $ */ /* * Copyright (c) 2009 The NetBSD Foundation, Inc. @@ -33,7 +33,7 @@ #include #include -#include "../../h_macros.h" +#include "h_macros.h" ATF_TC(rtld_dlinfo_linkmap_self); ATF_TC_HEAD(rtld_dlinfo_linkmap_self, tc) diff --git a/contrib/netbsd-tests/libexec/ld.elf_so/t_ifunc.c b/contrib/netbsd-tests/libexec/ld.elf_so/t_ifunc.c index 1c85672af5f7..68468d4483d4 100644 --- a/contrib/netbsd-tests/libexec/ld.elf_so/t_ifunc.c +++ b/contrib/netbsd-tests/libexec/ld.elf_so/t_ifunc.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_ifunc.c,v 1.1 2014/08/25 20:40:53 joerg Exp $ */ +/* $NetBSD: t_ifunc.c,v 1.2 2017/01/13 21:30:42 christos Exp $ */ /* * Copyright (c) 2014 The NetBSD Foundation, Inc. @@ -33,7 +33,7 @@ #include #include -#include "../../h_macros.h" +#include "h_macros.h" ATF_TC(rtld_ifunc); diff --git a/contrib/netbsd-tests/modules/t_builtin.c b/contrib/netbsd-tests/modules/t_builtin.c index 0d9a3f0dc129..79845b85c553 100644 --- a/contrib/netbsd-tests/modules/t_builtin.c +++ b/contrib/netbsd-tests/modules/t_builtin.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_builtin.c,v 1.2 2010/11/03 16:10:23 christos Exp $ */ +/* $NetBSD: t_builtin.c,v 1.3 2017/01/13 21:30:42 christos Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. All rights reserved. @@ -39,7 +39,7 @@ #include #include -#include "../h_macros.h" +#include "h_macros.h" #define MYMP "/mnt" #define HZFILE MYMP "/hz" diff --git a/contrib/netbsd-tests/net/bpf/t_bpf.c b/contrib/netbsd-tests/net/bpf/t_bpf.c index 95ca2fc48de7..5d7716c9738d 100644 --- a/contrib/netbsd-tests/net/bpf/t_bpf.c +++ b/contrib/netbsd-tests/net/bpf/t_bpf.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_bpf.c,v 1.5 2012/08/14 19:40:30 alnsn Exp $ */ +/* $NetBSD: t_bpf.c,v 1.6 2017/01/13 21:30:42 christos Exp $ */ /*- * Copyright (c) 2010 Antti Kantee. All Rights Reserved. @@ -25,7 +25,7 @@ * SUCH DAMAGE. */ #include -__RCSID("$NetBSD: t_bpf.c,v 1.5 2012/08/14 19:40:30 alnsn Exp $"); +__RCSID("$NetBSD: t_bpf.c,v 1.6 2017/01/13 21:30:42 christos Exp $"); #include #include @@ -50,7 +50,7 @@ __RCSID("$NetBSD: t_bpf.c,v 1.5 2012/08/14 19:40:30 alnsn Exp $"); #undef m_data #include -#include "../../h_macros.h" +#include "h_macros.h" #include "../config/netconfig.c" ATF_TC(bpfwriteleak); diff --git a/contrib/netbsd-tests/net/bpf/t_mbuf.c b/contrib/netbsd-tests/net/bpf/t_mbuf.c index 965dd02e285b..2076dc26aead 100644 --- a/contrib/netbsd-tests/net/bpf/t_mbuf.c +++ b/contrib/netbsd-tests/net/bpf/t_mbuf.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_mbuf.c,v 1.2 2014/07/08 21:44:26 alnsn Exp $ */ +/* $NetBSD: t_mbuf.c,v 1.3 2017/01/13 21:30:42 christos Exp $ */ /*- * Copyright (c) 2014 Alexander Nasonov. @@ -27,7 +27,7 @@ */ #include -__RCSID("$NetBSD: t_mbuf.c,v 1.2 2014/07/08 21:44:26 alnsn Exp $"); +__RCSID("$NetBSD: t_mbuf.c,v 1.3 2017/01/13 21:30:42 christos Exp $"); #include #include @@ -47,7 +47,7 @@ __RCSID("$NetBSD: t_mbuf.c,v 1.2 2014/07/08 21:44:26 alnsn Exp $"); #undef m_data #include -#include "../../h_macros.h" +#include "h_macros.h" static bool test_ldb_abs(size_t split) diff --git a/contrib/netbsd-tests/net/bpfilter/t_bpfilter.c b/contrib/netbsd-tests/net/bpfilter/t_bpfilter.c index 460b43e62d9b..15a9ab6e2c16 100644 --- a/contrib/netbsd-tests/net/bpfilter/t_bpfilter.c +++ b/contrib/netbsd-tests/net/bpfilter/t_bpfilter.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_bpfilter.c,v 1.10 2015/02/11 23:39:07 alnsn Exp $ */ +/* $NetBSD: t_bpfilter.c,v 1.11 2017/01/13 21:30:42 christos Exp $ */ /*- * Copyright (c) 2012 The NetBSD Foundation, Inc. @@ -25,7 +25,7 @@ * SUCH DAMAGE. */ #include -__RCSID("$NetBSD: t_bpfilter.c,v 1.10 2015/02/11 23:39:07 alnsn Exp $"); +__RCSID("$NetBSD: t_bpfilter.c,v 1.11 2017/01/13 21:30:42 christos Exp $"); #include #include @@ -53,7 +53,7 @@ __RCSID("$NetBSD: t_bpfilter.c,v 1.10 2015/02/11 23:39:07 alnsn Exp $"); #undef m_data #include -#include "../../h_macros.h" +#include "h_macros.h" #include "../config/netconfig.c" diff --git a/contrib/netbsd-tests/net/bpfjit/t_bpfjit.c b/contrib/netbsd-tests/net/bpfjit/t_bpfjit.c index 58db1e06a083..06c3d97b734f 100644 --- a/contrib/netbsd-tests/net/bpfjit/t_bpfjit.c +++ b/contrib/netbsd-tests/net/bpfjit/t_bpfjit.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_bpfjit.c,v 1.11 2015/02/14 22:34:33 alnsn Exp $ */ +/* $NetBSD: t_bpfjit.c,v 1.12 2017/01/13 21:30:42 christos Exp $ */ /*- * Copyright (c) 2011-2012, 2014-2015 Alexander Nasonov. @@ -27,7 +27,7 @@ */ #include -__RCSID("$NetBSD: t_bpfjit.c,v 1.11 2015/02/14 22:34:33 alnsn Exp $"); +__RCSID("$NetBSD: t_bpfjit.c,v 1.12 2017/01/13 21:30:42 christos Exp $"); #include #include @@ -49,7 +49,7 @@ __RCSID("$NetBSD: t_bpfjit.c,v 1.11 2015/02/14 22:34:33 alnsn Exp $"); #undef m_data #include -#include "../../h_macros.h" +#include "h_macros.h" static uint8_t deadbeef_at_5[16] = { diff --git a/contrib/netbsd-tests/net/bpfjit/t_cop.c b/contrib/netbsd-tests/net/bpfjit/t_cop.c index 5a007e6510a5..502c588e4a9b 100644 --- a/contrib/netbsd-tests/net/bpfjit/t_cop.c +++ b/contrib/netbsd-tests/net/bpfjit/t_cop.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_cop.c,v 1.3 2014/07/13 21:35:33 alnsn Exp $ */ +/* $NetBSD: t_cop.c,v 1.4 2017/01/13 21:30:42 christos Exp $ */ /*- * Copyright (c) 2014 Alexander Nasonov. @@ -30,7 +30,7 @@ */ #include -__RCSID("$NetBSD: t_cop.c,v 1.3 2014/07/13 21:35:33 alnsn Exp $"); +__RCSID("$NetBSD: t_cop.c,v 1.4 2017/01/13 21:30:42 christos Exp $"); #include #include @@ -46,7 +46,7 @@ __RCSID("$NetBSD: t_cop.c,v 1.3 2014/07/13 21:35:33 alnsn Exp $"); #undef m_data #include -#include "../../h_macros.h" +#include "h_macros.h" static uint32_t retA(const bpf_ctx_t *bc, bpf_args_t *args, uint32_t A); static uint32_t retBL(const bpf_ctx_t *bc, bpf_args_t *args, uint32_t A); diff --git a/contrib/netbsd-tests/net/bpfjit/t_extmem.c b/contrib/netbsd-tests/net/bpfjit/t_extmem.c index 915c4366467e..51761ec06128 100644 --- a/contrib/netbsd-tests/net/bpfjit/t_extmem.c +++ b/contrib/netbsd-tests/net/bpfjit/t_extmem.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_extmem.c,v 1.1 2014/07/09 13:49:49 alnsn Exp $ */ +/* $NetBSD: t_extmem.c,v 1.2 2017/01/13 21:30:42 christos Exp $ */ /*- * Copyright (c) 2014 Alexander Nasonov. @@ -30,7 +30,7 @@ */ #include -__RCSID("$NetBSD: t_extmem.c,v 1.1 2014/07/09 13:49:49 alnsn Exp $"); +__RCSID("$NetBSD: t_extmem.c,v 1.2 2017/01/13 21:30:42 christos Exp $"); #include #include @@ -46,7 +46,7 @@ __RCSID("$NetBSD: t_extmem.c,v 1.1 2014/07/09 13:49:49 alnsn Exp $"); #undef m_data #include -#include "../../h_macros.h" +#include "h_macros.h" static uint32_t retM(const bpf_ctx_t *bc, bpf_args_t *args, uint32_t A); diff --git a/contrib/netbsd-tests/net/bpfjit/t_mbuf.c b/contrib/netbsd-tests/net/bpfjit/t_mbuf.c index 489ef802d9ab..d3a2b994c5a9 100644 --- a/contrib/netbsd-tests/net/bpfjit/t_mbuf.c +++ b/contrib/netbsd-tests/net/bpfjit/t_mbuf.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_mbuf.c,v 1.1 2014/07/08 21:45:55 alnsn Exp $ */ +/* $NetBSD: t_mbuf.c,v 1.2 2017/01/13 21:30:42 christos Exp $ */ /*- * Copyright (c) 2014 Alexander Nasonov. @@ -27,7 +27,7 @@ */ #include -__RCSID("$NetBSD: t_mbuf.c,v 1.1 2014/07/08 21:45:55 alnsn Exp $"); +__RCSID("$NetBSD: t_mbuf.c,v 1.2 2017/01/13 21:30:42 christos Exp $"); #include #include @@ -48,7 +48,7 @@ __RCSID("$NetBSD: t_mbuf.c,v 1.1 2014/07/08 21:45:55 alnsn Exp $"); #undef m_data #include -#include "../../h_macros.h" +#include "h_macros.h" static bool test_ldb_abs(size_t split) diff --git a/contrib/netbsd-tests/net/carp/t_basic.c b/contrib/netbsd-tests/net/carp/t_basic.c index fe2e6b5f2f66..681b8bb179a7 100644 --- a/contrib/netbsd-tests/net/carp/t_basic.c +++ b/contrib/netbsd-tests/net/carp/t_basic.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_basic.c,v 1.5 2011/06/26 13:13:31 christos Exp $ */ +/* $NetBSD: t_basic.c,v 1.6 2017/01/13 21:30:42 christos Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -29,7 +29,7 @@ #include #ifndef lint -__RCSID("$NetBSD: t_basic.c,v 1.5 2011/06/26 13:13:31 christos Exp $"); +__RCSID("$NetBSD: t_basic.c,v 1.6 2017/01/13 21:30:42 christos Exp $"); #endif /* not lint */ #include @@ -52,7 +52,7 @@ __RCSID("$NetBSD: t_basic.c,v 1.5 2011/06/26 13:13:31 christos Exp $"); #include #include "../config/netconfig.c" -#include "../../h_macros.h" +#include "h_macros.h" static bool oknow = false; diff --git a/contrib/netbsd-tests/net/config/netconfig.c b/contrib/netbsd-tests/net/config/netconfig.c index c2f9dd477896..6fe37cc23da3 100644 --- a/contrib/netbsd-tests/net/config/netconfig.c +++ b/contrib/netbsd-tests/net/config/netconfig.c @@ -1,4 +1,4 @@ -/* $NetBSD: netconfig.c,v 1.8 2013/07/03 19:13:33 pooka Exp $ */ +/* $NetBSD: netconfig.c,v 1.9 2017/01/13 21:30:42 christos Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -29,7 +29,7 @@ #include #ifndef lint -__RCSID("$NetBSD: netconfig.c,v 1.8 2013/07/03 19:13:33 pooka Exp $"); +__RCSID("$NetBSD: netconfig.c,v 1.9 2017/01/13 21:30:42 christos Exp $"); #endif /* not lint */ #include @@ -53,7 +53,7 @@ __RCSID("$NetBSD: netconfig.c,v 1.8 2013/07/03 19:13:33 pooka Exp $"); #include #include -#include "../../h_macros.h" +#include "h_macros.h" int noatf; diff --git a/contrib/netbsd-tests/net/icmp/t_forward.c b/contrib/netbsd-tests/net/icmp/t_forward.c index d4180271b449..346614c07151 100644 --- a/contrib/netbsd-tests/net/icmp/t_forward.c +++ b/contrib/netbsd-tests/net/icmp/t_forward.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_forward.c,v 1.9 2015/02/26 13:03:21 martin Exp $ */ +/* $NetBSD: t_forward.c,v 1.10 2017/01/13 21:30:42 christos Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -29,7 +29,7 @@ #include #ifndef lint -__RCSID("$NetBSD: t_forward.c,v 1.9 2015/02/26 13:03:21 martin Exp $"); +__RCSID("$NetBSD: t_forward.c,v 1.10 2017/01/13 21:30:42 christos Exp $"); #endif /* not lint */ #include @@ -57,7 +57,7 @@ __RCSID("$NetBSD: t_forward.c,v 1.9 2015/02/26 13:03:21 martin Exp $"); #include #include -#include "../../h_macros.h" +#include "h_macros.h" #include "../config/netconfig.c" /* diff --git a/contrib/netbsd-tests/net/icmp/t_ping.c b/contrib/netbsd-tests/net/icmp/t_ping.c index 68a00c7c2237..b3327e10e9e2 100644 --- a/contrib/netbsd-tests/net/icmp/t_ping.c +++ b/contrib/netbsd-tests/net/icmp/t_ping.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_ping.c,v 1.16 2015/02/26 13:06:10 martin Exp $ */ +/* $NetBSD: t_ping.c,v 1.17 2017/01/13 21:30:42 christos Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -29,7 +29,7 @@ #include #ifndef lint -__RCSID("$NetBSD: t_ping.c,v 1.16 2015/02/26 13:06:10 martin Exp $"); +__RCSID("$NetBSD: t_ping.c,v 1.17 2017/01/13 21:30:42 christos Exp $"); #endif /* not lint */ #include @@ -52,7 +52,7 @@ __RCSID("$NetBSD: t_ping.c,v 1.16 2015/02/26 13:06:10 martin Exp $"); #include #include -#include "../../h_macros.h" +#include "h_macros.h" #include "../config/netconfig.c" ATF_TC(simpleping); diff --git a/contrib/netbsd-tests/net/if_loop/t_pr.c b/contrib/netbsd-tests/net/if_loop/t_pr.c index a22953f933b2..ee4f68472c82 100644 --- a/contrib/netbsd-tests/net/if_loop/t_pr.c +++ b/contrib/netbsd-tests/net/if_loop/t_pr.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_pr.c,v 1.7 2012/03/18 09:46:50 jruoho Exp $ */ +/* $NetBSD: t_pr.c,v 1.8 2017/01/13 21:30:42 christos Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -29,7 +29,7 @@ #include #ifndef lint -__RCSID("$NetBSD: t_pr.c,v 1.7 2012/03/18 09:46:50 jruoho Exp $"); +__RCSID("$NetBSD: t_pr.c,v 1.8 2017/01/13 21:30:42 christos Exp $"); #endif /* not lint */ #include @@ -50,7 +50,7 @@ __RCSID("$NetBSD: t_pr.c,v 1.7 2012/03/18 09:46:50 jruoho Exp $"); #include #include "../config/netconfig.c" -#include "../../h_macros.h" +#include "h_macros.h" /* * Prepare rump, configure interface and route to cause fragmentation diff --git a/contrib/netbsd-tests/net/if_tun/t_tun.sh b/contrib/netbsd-tests/net/if_tun/t_tun.sh new file mode 100755 index 000000000000..87df39ab5886 --- /dev/null +++ b/contrib/netbsd-tests/net/if_tun/t_tun.sh @@ -0,0 +1,138 @@ +# $NetBSD: t_tun.sh,v 1.4 2016/11/07 05:25:37 ozaki-r Exp $ +# +# Copyright (c) 2016 Internet Initiative Japan 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. +# + +RUMP_FLAGS="-lrumpnet -lrumpnet_net -lrumpnet_netinet -lrumpnet_netinet6" +RUMP_FLAGS="$RUMP_FLAGS -lrumpnet_shmif -lrumpnet_tun -lrumpdev" + +BUS=bus +SOCK_LOCAL=unix://commsock1 +SOCK_REMOTE=unix://commsock2 +IP_LOCAL=10.0.0.1 +IP_REMOTE=10.0.0.2 + +DEBUG=${DEBUG:-true} + +atf_test_case tun_create_destroy cleanup +tun_create_destroy_head() +{ + + atf_set "descr" "tests of creation and deletion of tun interface" + atf_set "require.progs" "rump_server" +} + +tun_create_destroy_body() +{ + + atf_check -s exit:0 rump_server ${RUMP_FLAGS} ${SOCK_LOCAL} + + export RUMP_SERVER=${SOCK_LOCAL} + + atf_check -s exit:0 rump.ifconfig tun0 create + atf_check -s exit:0 rump.ifconfig tun0 up + atf_check -s exit:0 rump.ifconfig tun0 down + atf_check -s exit:0 rump.ifconfig tun0 destroy +} + +tun_create_destroy_cleanup() +{ + + RUMP_SERVER=${SOCK_LOCAL} rump.halt +} + +atf_test_case tun_setup cleanup +tun_setup_head() +{ + + atf_set "descr" "tests of setting up a tunnel" + atf_set "require.progs" "rump_server" +} + +check_route_entry() +{ + local ip=$(echo $1 |sed 's/\./\\./g') + local gw=$2 + local flags=$3 + local iface=$4 + + atf_check -s exit:0 -o match:" $flags " -e ignore -x \ + "rump.netstat -rn -f inet | grep ^'$ip'" + atf_check -s exit:0 -o match:" $gw " -e ignore -x \ + "rump.netstat -rn -f inet | grep ^'$ip'" + atf_check -s exit:0 -o match:" $iface" -e ignore -x \ + "rump.netstat -rn -f inet | grep ^'$ip'" +} + +tun_setup_body() +{ + + atf_check -s exit:0 rump_server ${RUMP_FLAGS} ${SOCK_LOCAL} + atf_check -s exit:0 rump_server ${RUMP_FLAGS} ${SOCK_REMOTE} + + export RUMP_SERVER=${SOCK_LOCAL} + + atf_check -s exit:0 rump.ifconfig shmif0 create + atf_check -s exit:0 rump.ifconfig shmif0 linkstr $BUS + atf_check -s exit:0 rump.ifconfig shmif0 ${IP_LOCAL}/24 up + atf_check -s exit:0 rump.ifconfig -w 10 + + export RUMP_SERVER=${SOCK_REMOTE} + + atf_check -s exit:0 rump.ifconfig shmif0 create + atf_check -s exit:0 rump.ifconfig shmif0 linkstr $BUS + atf_check -s exit:0 rump.ifconfig shmif0 ${IP_REMOTE}/24 up + atf_check -s exit:0 rump.ifconfig -w 10 + + export RUMP_SERVER=${SOCK_LOCAL} + atf_check -s exit:0 rump.ifconfig tun0 create + atf_check -s exit:0 rump.ifconfig tun0 ${IP_LOCAL} ${IP_REMOTE} up + atf_check -s exit:0 \ + -o match:"inet ${IP_LOCAL}/32 -> ${IP_REMOTE}" rump.ifconfig tun0 + $DEBUG && rump.netstat -nr -f inet + check_route_entry ${IP_REMOTE} ${IP_LOCAL} UH tun0 + + export RUMP_SERVER=${SOCK_REMOTE} + atf_check -s exit:0 rump.ifconfig tun0 create + atf_check -s exit:0 rump.ifconfig tun0 ${IP_REMOTE} ${IP_LOCAL} up + atf_check -s exit:0 \ + -o match:"inet ${IP_REMOTE}/32 -> ${IP_LOCAL}" rump.ifconfig tun0 + $DEBUG && rump.netstat -nr -f inet + check_route_entry ${IP_LOCAL} ${IP_REMOTE} UH tun0 +} + +tun_setup_cleanup() +{ + + RUMP_SERVER=${SOCK_LOCAL} rump.halt + RUMP_SERVER=${SOCK_REMOTE} rump.halt +} + +atf_init_test_cases() +{ + + atf_add_test_case tun_create_destroy + atf_add_test_case tun_setup +} diff --git a/contrib/netbsd-tests/net/if_vlan/t_vlan.sh b/contrib/netbsd-tests/net/if_vlan/t_vlan.sh new file mode 100755 index 000000000000..a6902fb1e247 --- /dev/null +++ b/contrib/netbsd-tests/net/if_vlan/t_vlan.sh @@ -0,0 +1,115 @@ +# $NetBSD: t_vlan.sh,v 1.1 2016/11/26 03:19:49 ozaki-r Exp $ +# +# Copyright (c) 2016 Internet Initiative Japan 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. +# + +BUS=bus +SOCK_LOCAL=unix://commsock1 +SOCK_REMOTE=unix://commsock2 +IP_LOCAL=10.0.0.1 +IP_REMOTE=10.0.0.2 + +DEBUG=${DEBUG:-false} + +atf_test_case vlan_create_destroy cleanup +vlan_create_destroy_head() +{ + + atf_set "descr" "tests of creation and deletion of vlan interface" + atf_set "require.progs" "rump_server" +} + +vlan_create_destroy_body() +{ + + rump_server_start $SOCK_LOCAL vlan + + export RUMP_SERVER=${SOCK_LOCAL} + + atf_check -s exit:0 rump.ifconfig vlan0 create + atf_check -s exit:0 rump.ifconfig vlan0 up + atf_check -s exit:0 rump.ifconfig vlan0 down + atf_check -s exit:0 rump.ifconfig vlan0 destroy +} + +vlan_create_destroy_cleanup() +{ + + $DEBUG && dump + cleanup +} + +atf_test_case vlan_basic cleanup +vlan_basic_head() +{ + + atf_set "descr" "tests of communications over vlan interfaces" + atf_set "require.progs" "rump_server" +} + +vlan_basic_body() +{ + + rump_server_start $SOCK_LOCAL vlan + rump_server_add_iface $SOCK_LOCAL shmif0 $BUS + rump_server_start $SOCK_REMOTE vlan + rump_server_add_iface $SOCK_REMOTE shmif0 $BUS + + export RUMP_SERVER=$SOCK_LOCAL + atf_check -s exit:0 rump.ifconfig shmif0 up + export RUMP_SERVER=$SOCK_REMOTE + atf_check -s exit:0 rump.ifconfig shmif0 up + + export RUMP_SERVER=$SOCK_LOCAL + atf_check -s exit:0 rump.ifconfig vlan0 create + atf_check -s exit:0 rump.ifconfig vlan0 vlan 10 vlanif shmif0 + atf_check -s exit:0 rump.ifconfig vlan0 $IP_LOCAL/24 + atf_check -s exit:0 rump.ifconfig vlan0 up + atf_check -s exit:0 rump.ifconfig -w 10 + + export RUMP_SERVER=$SOCK_REMOTE + atf_check -s exit:0 rump.ifconfig vlan0 create + atf_check -s exit:0 rump.ifconfig vlan0 vlan 10 vlanif shmif0 + atf_check -s exit:0 rump.ifconfig vlan0 $IP_REMOTE/24 + atf_check -s exit:0 rump.ifconfig vlan0 up + atf_check -s exit:0 rump.ifconfig -w 10 + + export RUMP_SERVER=$SOCK_LOCAL + atf_check -s exit:0 -o ignore rump.ping -n -w 1 -c 1 $IP_REMOTE +} + +vlan_basic_cleanup() +{ + + $DEBUG && dump + cleanup +} + +atf_init_test_cases() +{ + + atf_add_test_case vlan_create_destroy + atf_add_test_case vlan_basic +} diff --git a/contrib/netbsd-tests/net/ndp/t_ra.sh b/contrib/netbsd-tests/net/ndp/t_ra.sh index b2345704f462..69f227af498e 100755 --- a/contrib/netbsd-tests/net/ndp/t_ra.sh +++ b/contrib/netbsd-tests/net/ndp/t_ra.sh @@ -1,4 +1,4 @@ -# $NetBSD: t_ra.sh,v 1.20 2017/01/11 03:15:44 ozaki-r Exp $ +# $NetBSD: t_ra.sh,v 1.24 2017/01/13 08:11:01 ozaki-r Exp $ # # Copyright (c) 2015 Internet Initiative Japan Inc. # All rights reserved. @@ -127,7 +127,8 @@ check_entries() -o match:"$ll_srv%shmif0 +$mac_srv +shmif0 +(23h59m|1d0h0m)..s S R" \ rump.ndp -n -a atf_check -s exit:0 -o match:$addr_prefix rump.ndp -n -a - atf_check -s exit:0 -o match:"$addr_prefix.+" \ + atf_check -s exit:0 \ + -o match:"$addr_prefix.+<(TENTATIVE,)?AUTOCONF>" \ rump.ifconfig shmif0 inet6 unset RUMP_SERVER } @@ -603,60 +604,75 @@ ra_temporary_address_head() atf_set "require.progs" "rump_server rump.rtadvd rump.ndp rump.ifconfig" } +check_echo_request_pkt() +{ + local pkt="$2 > $3: .+ echo request" + + extract_new_packets $1 > ./out + $DEBUG && echo $pkt + $DEBUG && cat ./out + atf_check -s exit:0 -o match:"$pkt" cat ./out +} + ra_temporary_address_body() { + local ip_auto= ip_temp= rump_server_fs_start $RUMPSRV netinet6 rump_server_start $RUMPCLI netinet6 - setup_shmif0 ${RUMPSRV} ${IP6SRV} + setup_shmif0 $RUMPSRV $IP6SRV init_server $RUMPSRV + setup_shmif0 $RUMPCLI $IP6CLI - setup_shmif0 ${RUMPCLI} ${IP6CLI} - export RUMP_SERVER=${RUMPCLI} - $DEBUG && rump.ndp -n -a - atf_check -s exit:0 -o match:'= 0' \ - rump.sysctl net.inet6.ip6.accept_rtadv - atf_check -s exit:0 -o match:'= 0' \ - rump.sysctl net.inet6.ip6.use_tempaddr - unset RUMP_SERVER - - create_rtadvdconfig - start_rtadvd $RUMPSRV $PIDFILE - sleep $WAITTIME - - export RUMP_SERVER=${RUMPCLI} - atf_check -s exit:0 -o empty rump.ndp -r - atf_check -s exit:0 -o not-match:'advertised' rump.ndp -p - atf_check -s exit:0 -o match:'linkmtu=0' rump.ndp -n -i shmif0 - atf_check -s exit:0 -o not-match:'S R' rump.ndp -n -a - atf_check -s exit:0 -o not-match:'fc00:1:' rump.ndp -n -a - atf_check -s exit:0 -o not-match:'fc00:1:' rump.ifconfig shmif0 inet6 - unset RUMP_SERVER - - atf_check -s exit:0 kill -TERM `cat ${PIDFILE}` - wait_term ${PIDFILE} - - export RUMP_SERVER=${RUMPCLI} + export RUMP_SERVER=$RUMPCLI atf_check -s exit:0 -o match:'0.->.1' \ rump.sysctl -w net.inet6.ip6.accept_rtadv=1 atf_check -s exit:0 -o match:'0.->.1' \ rump.sysctl -w net.inet6.ip6.use_tempaddr=1 unset RUMP_SERVER + create_rtadvdconfig start_rtadvd $RUMPSRV $PIDFILE sleep $WAITTIME check_entries $RUMPCLI $RUMPSRV $IP6SRV_PREFIX + export RUMP_SERVER=$RUMPCLI + # Check temporary address - export RUMP_SERVER=${RUMPCLI} - atf_check -s exit:0 -o match:"$IP6SRV_PREFIX.+" \ + atf_check -s exit:0 \ + -o match:"$IP6SRV_PREFIX.+<(TENTATIVE,)?AUTOCONF,TEMPORARY>" \ rump.ifconfig shmif0 inet6 + + # + # Testing net.inet6.ip6.prefer_tempaddr + # + atf_check -s exit:0 rump.ifconfig -w 10 + $DEBUG && rump.ifconfig shmif0 + ip_auto=$(rump.ifconfig shmif0 |awk '// {sub(/\/[0-9]*/, ""); print $2;}') + ip_temp=$(rump.ifconfig shmif0 |awk '// {sub(/\/[0-9]*/, ""); print $2;}') + $DEBUG && echo $ip_auto $ip_temp + + # Ignore old packets + extract_new_packets bus1 > /dev/null + + atf_check -s exit:0 -o ignore rump.ping6 -n -X 2 -c 1 $IP6SRV + # autoconf (non-temporal) address should be used as the source address + check_echo_request_pkt bus1 $ip_auto $IP6SRV + + # Enable net.inet6.ip6.prefer_tempaddr + atf_check -s exit:0 -o match:'0.->.1' \ + rump.sysctl -w net.inet6.ip6.prefer_tempaddr=1 + + atf_check -s exit:0 -o ignore rump.ping6 -n -X 2 -c 1 $IP6SRV + # autoconf, temporal address should be used as the source address + check_echo_request_pkt bus1 $ip_temp $IP6SRV + unset RUMP_SERVER atf_check -s exit:0 kill -TERM `cat ${PIDFILE}` - wait_term ${PIDFILE} + wait_term $PIDFILE rump_server_destroy_ifaces } diff --git a/contrib/netbsd-tests/net/net/t_raw.c b/contrib/netbsd-tests/net/net/t_raw.c index ef3262dfa372..5c483a180de5 100644 --- a/contrib/netbsd-tests/net/net/t_raw.c +++ b/contrib/netbsd-tests/net/net/t_raw.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_raw.c,v 1.1 2011/01/11 10:51:45 pooka Exp $ */ +/* $NetBSD: t_raw.c,v 1.2 2017/01/13 21:30:42 christos Exp $ */ #include #include @@ -12,7 +12,7 @@ #include -#include "../../h_macros.h" +#include "h_macros.h" ATF_TC(PRU_SENSE); ATF_TC_HEAD(PRU_SENSE, tc) diff --git a/contrib/netbsd-tests/rump/modautoload/t_modautoload.c b/contrib/netbsd-tests/rump/modautoload/t_modautoload.c index 2c21a90b664b..b45dae540993 100644 --- a/contrib/netbsd-tests/rump/modautoload/t_modautoload.c +++ b/contrib/netbsd-tests/rump/modautoload/t_modautoload.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_modautoload.c,v 1.5 2016/09/14 03:19:11 ozaki-r Exp $ */ +/* $NetBSD: t_modautoload.c,v 1.6 2017/01/13 21:30:42 christos Exp $ */ #include #include @@ -20,7 +20,7 @@ #include -#include "../../h_macros.h" +#include "h_macros.h" ATF_TC(modautoload); ATF_TC_HEAD(modautoload, tc) diff --git a/contrib/netbsd-tests/rump/rumpkern/t_kern.c b/contrib/netbsd-tests/rump/rumpkern/t_kern.c index fcaf1f8178de..15b258605ba9 100644 --- a/contrib/netbsd-tests/rump/rumpkern/t_kern.c +++ b/contrib/netbsd-tests/rump/rumpkern/t_kern.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_kern.c,v 1.3 2012/01/30 13:05:52 njoly Exp $ */ +/* $NetBSD: t_kern.c,v 1.4 2017/01/13 21:30:43 christos Exp $ */ /*- * Copyright (c) 2011 The NetBSD Foundation, Inc. @@ -38,7 +38,7 @@ #include #include -#include "../../h_macros.h" +#include "h_macros.h" #include "../kernspace/kernspace.h" #define LOCKFUN(_name_, _descr_,_needld_, _expect_) \ diff --git a/contrib/netbsd-tests/rump/rumpkern/t_lwproc.c b/contrib/netbsd-tests/rump/rumpkern/t_lwproc.c index 6e78d0219e2b..f31997982c79 100644 --- a/contrib/netbsd-tests/rump/rumpkern/t_lwproc.c +++ b/contrib/netbsd-tests/rump/rumpkern/t_lwproc.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_lwproc.c,v 1.8 2017/01/10 22:36:29 christos Exp $ */ +/* $NetBSD: t_lwproc.c,v 1.9 2017/01/13 21:30:43 christos Exp $ */ /* * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -44,7 +44,7 @@ #include #include -#include "../../h_macros.h" +#include "h_macros.h" ATF_TC(makelwp); ATF_TC_HEAD(makelwp, tc) diff --git a/contrib/netbsd-tests/rump/rumpkern/t_modcmd.c b/contrib/netbsd-tests/rump/rumpkern/t_modcmd.c index 032e31296a98..e48bcb53dbf7 100644 --- a/contrib/netbsd-tests/rump/rumpkern/t_modcmd.c +++ b/contrib/netbsd-tests/rump/rumpkern/t_modcmd.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_modcmd.c,v 1.9 2010/05/31 23:51:28 pooka Exp $ */ +/* $NetBSD: t_modcmd.c,v 1.10 2017/01/13 21:30:43 christos Exp $ */ /* * Copyright (c) 2009 The NetBSD Foundation, Inc. @@ -46,7 +46,7 @@ #include #include -#include "../../h_macros.h" +#include "h_macros.h" /* * We verify that modules can be loaded and unloaded. * tmpfs was chosen because it does not depend on an image. diff --git a/contrib/netbsd-tests/rump/rumpkern/t_modlinkset.c b/contrib/netbsd-tests/rump/rumpkern/t_modlinkset.c index a4d34bb913fd..7d725dc7cc07 100644 --- a/contrib/netbsd-tests/rump/rumpkern/t_modlinkset.c +++ b/contrib/netbsd-tests/rump/rumpkern/t_modlinkset.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_modlinkset.c,v 1.2 2009/11/06 15:26:54 pooka Exp $ */ +/* $NetBSD: t_modlinkset.c,v 1.3 2017/01/13 21:30:43 christos Exp $ */ /* * Copyright (c) 2009 The NetBSD Foundation, Inc. @@ -39,7 +39,7 @@ #include #include -#include "../../h_macros.h" +#include "h_macros.h" ATF_TC(modlinkset); ATF_TC_HEAD(modlinkset, tc) diff --git a/contrib/netbsd-tests/rump/rumpkern/t_signals.c b/contrib/netbsd-tests/rump/rumpkern/t_signals.c index e113af29a1fa..ba0c0ea36fb2 100644 --- a/contrib/netbsd-tests/rump/rumpkern/t_signals.c +++ b/contrib/netbsd-tests/rump/rumpkern/t_signals.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_signals.c,v 1.2 2011/02/20 19:45:45 pooka Exp $ */ +/* $NetBSD: t_signals.c,v 1.3 2017/01/13 21:30:43 christos Exp $ */ /*- * Copyright (c) 2011 The NetBSD Foundation, Inc. @@ -39,7 +39,7 @@ #include #include "../kernspace/kernspace.h" -#include "../../h_macros.h" +#include "h_macros.h" ATF_TC(sigraise); ATF_TC_HEAD(sigraise, tc) diff --git a/contrib/netbsd-tests/rump/rumpkern/t_threads.c b/contrib/netbsd-tests/rump/rumpkern/t_threads.c index 24155ec7ca14..2931fa60d148 100644 --- a/contrib/netbsd-tests/rump/rumpkern/t_threads.c +++ b/contrib/netbsd-tests/rump/rumpkern/t_threads.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_threads.c,v 1.1 2010/05/31 23:36:12 pooka Exp $ */ +/* $NetBSD: t_threads.c,v 1.2 2017/01/13 21:30:43 christos Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -35,7 +35,7 @@ #include -#include "../../h_macros.h" +#include "h_macros.h" #include "../kernspace/kernspace.h" ATF_TC(threadjoin); diff --git a/contrib/netbsd-tests/rump/rumpkern/t_tsleep.c b/contrib/netbsd-tests/rump/rumpkern/t_tsleep.c index efd9f4c4b270..126a89de5280 100644 --- a/contrib/netbsd-tests/rump/rumpkern/t_tsleep.c +++ b/contrib/netbsd-tests/rump/rumpkern/t_tsleep.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_tsleep.c,v 1.1 2010/05/31 23:36:12 pooka Exp $ */ +/* $NetBSD: t_tsleep.c,v 1.2 2017/01/13 21:30:43 christos Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -35,7 +35,7 @@ #include -#include "../../h_macros.h" +#include "h_macros.h" #include "../kernspace/kernspace.h" ATF_TC(tsleep); diff --git a/contrib/netbsd-tests/rump/rumpkern/t_vm.c b/contrib/netbsd-tests/rump/rumpkern/t_vm.c index 4445983dcb56..ddb005c8eeae 100644 --- a/contrib/netbsd-tests/rump/rumpkern/t_vm.c +++ b/contrib/netbsd-tests/rump/rumpkern/t_vm.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_vm.c,v 1.3 2012/03/17 18:00:28 hannken Exp $ */ +/* $NetBSD: t_vm.c,v 1.4 2017/01/13 21:30:43 christos Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -37,7 +37,7 @@ #include #include -#include "../../h_macros.h" +#include "h_macros.h" #include "../kernspace/kernspace.h" ATF_TC(busypage); diff --git a/contrib/netbsd-tests/rump/rumpvfs/t_basic.c b/contrib/netbsd-tests/rump/rumpvfs/t_basic.c index c136558b579b..278d99eb31c3 100644 --- a/contrib/netbsd-tests/rump/rumpvfs/t_basic.c +++ b/contrib/netbsd-tests/rump/rumpvfs/t_basic.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_basic.c,v 1.2 2011/02/22 13:25:18 pooka Exp $ */ +/* $NetBSD: t_basic.c,v 1.3 2017/01/13 21:30:43 christos Exp $ */ /*- * Copyright (c) 2011 The NetBSD Foundation, Inc. @@ -40,7 +40,7 @@ #include #include -#include "../../h_macros.h" +#include "h_macros.h" ATF_TC(lseekrv); ATF_TC_HEAD(lseekrv, tc) diff --git a/contrib/netbsd-tests/rump/rumpvfs/t_etfs.c b/contrib/netbsd-tests/rump/rumpvfs/t_etfs.c index 787f5e6eb9df..5935bead8ee6 100644 --- a/contrib/netbsd-tests/rump/rumpvfs/t_etfs.c +++ b/contrib/netbsd-tests/rump/rumpvfs/t_etfs.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_etfs.c,v 1.10 2014/05/12 15:33:12 christos Exp $ */ +/* $NetBSD: t_etfs.c,v 1.11 2017/01/13 21:30:43 christos Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -40,7 +40,7 @@ #include #include -#include "../../h_macros.h" +#include "h_macros.h" ATF_TC(reregister_reg); ATF_TC_HEAD(reregister_reg, tc) diff --git a/contrib/netbsd-tests/rump/rumpvfs/t_p2kifs.c b/contrib/netbsd-tests/rump/rumpvfs/t_p2kifs.c index c94e5e19200e..ec2423cf5b95 100644 --- a/contrib/netbsd-tests/rump/rumpvfs/t_p2kifs.c +++ b/contrib/netbsd-tests/rump/rumpvfs/t_p2kifs.c @@ -1,4 +1,4 @@ -/* $NetBSD: t_p2kifs.c,v 1.5 2016/01/25 11:45:57 pooka Exp $ */ +/* $NetBSD: t_p2kifs.c,v 1.6 2017/01/13 21:30:43 christos Exp $ */ /*- * Copyright (c) 2010 The NetBSD Foundation, Inc. @@ -41,7 +41,7 @@ #include #include -#include "../../h_macros.h" +#include "h_macros.h" ATF_TC(makecn); ATF_TC_HEAD(makecn, tc) diff --git a/contrib/netbsd-tests/sys/uvm/t_uvm_physseg.c b/contrib/netbsd-tests/sys/uvm/t_uvm_physseg.c new file mode 100644 index 000000000000..a5f2fa9e9067 --- /dev/null +++ b/contrib/netbsd-tests/sys/uvm/t_uvm_physseg.c @@ -0,0 +1,2377 @@ +/* $NetBSD: t_uvm_physseg.c,v 1.2 2016/12/22 08:15:20 cherry Exp $ */ + +/*- + * Copyright (c) 2015, 2016 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Santhosh N. Raju and + * by Cherry G. Mathew + * + * 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. + */ + +#include +__RCSID("$NetBSD: t_uvm_physseg.c,v 1.2 2016/12/22 08:15:20 cherry Exp $"); + +/* + * If this line is commented out tests related to uvm_physseg_get_pmseg() + * wont run. + * + * Have a look at machine/uvm_physseg.h for more details. + */ +#define __HAVE_PMAP_PHYSSEG + +/* + * This is a dummy struct used for testing purposes + * + * In reality this struct would exist in the MD part of the code residing in + * machines/vmparam.h + */ + +#ifdef __HAVE_PMAP_PHYSSEG +struct pmap_physseg { + int dummy_variable; /* Dummy variable use for testing */ +}; +#endif + +/* Testing API - assumes userland */ +/* Provide Kernel API equivalents */ +#include +#include +#include +#include /* memset(3) et. al */ +#include /* printf(3) */ +#include /* malloc(3) */ +#include +#include + +#define PRIxPADDR "lx" +#define PRIxPSIZE "lx" +#define PRIuPSIZE "lu" +#define PRIxVADDR "lx" +#define PRIxVSIZE "lx" +#define PRIuVSIZE "lu" + +#define UVM_HOTPLUG /* Enable hotplug with rbtree. */ +#define PMAP_STEAL_MEMORY +#define DEBUG /* Enable debug functionality. */ + +typedef unsigned long vaddr_t; +typedef unsigned long paddr_t; +typedef unsigned long psize_t; +typedef unsigned long vsize_t; + +#include +#include + +#ifndef DIAGNOSTIC +#define KASSERTMSG(e, msg, ...) /* NOTHING */ +#define KASSERT(e) /* NOTHING */ +#else +#define KASSERT(a) assert(a) +#define KASSERTMSG(exp, ...) printf(__VA_ARGS__); assert((exp)) +#endif + +#define VM_PHYSSEG_STRAT VM_PSTRAT_BSEARCH + +#define VM_NFREELIST 4 +#define VM_FREELIST_DEFAULT 0 +#define VM_FREELIST_FIRST16 3 +#define VM_FREELIST_FIRST1G 2 +#define VM_FREELIST_FIRST4G 1 + +/* + * Used in tests when Array implementation is tested + */ +#if !defined(VM_PHYSSEG_MAX) +#define VM_PHYSSEG_MAX 1 +#endif + +#define PAGE_SHIFT 12 +#define PAGE_SIZE (1 << PAGE_SHIFT) +#define PAGE_MASK (PAGE_SIZE - 1) +#define atop(x) (((paddr_t)(x)) >> PAGE_SHIFT) +#define ptoa(x) (((paddr_t)(x)) << PAGE_SHIFT) + +#define mutex_enter(l) +#define mutex_exit(l) + +psize_t physmem; + +struct uvmexp uvmexp; /* decl */ + +/* + * uvm structure borrowed from uvm.h + * + * Remember this is a dummy structure used within the ATF Tests and + * uses only necessary fields from the original uvm struct. + * See uvm/uvm.h for the full struct. + */ + +struct uvm { + /* vm_page related parameters */ + + bool page_init_done; /* TRUE if uvm_page_init() finished */ +} uvm; + +#include + +void * +kmem_alloc(size_t size, km_flag_t flags) +{ + return malloc(size); +} + +void * +kmem_zalloc(size_t size, km_flag_t flags) +{ + void *ptr; + ptr = malloc(size); + + memset(ptr, 0, size); + + return ptr; +} + +void +kmem_free(void *mem, size_t size) +{ + free(mem); +} + +static void +panic(const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + vprintf(fmt, ap); + printf("\n"); + va_end(ap); + KASSERT(false); + + /*NOTREACHED*/ +} + +static void +uvm_pagefree(struct vm_page *pg) +{ + return; +} + +#if defined(UVM_HOTPLUG) +static void +uvmpdpol_reinit(void) +{ + return; +} +#endif /* UVM_HOTPLUG */ + +/* end - Provide Kernel API equivalents */ + + +#include "uvm/uvm_physseg.c" + +#include + +#define SIXTYFOUR_KILO (64 * 1024) +#define ONETWENTYEIGHT_KILO (128 * 1024) +#define TWOFIFTYSIX_KILO (256 * 1024) +#define FIVEONETWO_KILO (512 * 1024) +#define ONE_MEGABYTE (1024 * 1024) +#define TWO_MEGABYTE (2 * 1024 * 1024) + +/* Sample Page Frame Numbers */ +#define VALID_START_PFN_1 atop(0) +#define VALID_END_PFN_1 atop(ONE_MEGABYTE) +#define VALID_AVAIL_START_PFN_1 atop(0) +#define VALID_AVAIL_END_PFN_1 atop(ONE_MEGABYTE) + +#define VALID_START_PFN_2 atop(ONE_MEGABYTE + 1) +#define VALID_END_PFN_2 atop(ONE_MEGABYTE * 2) +#define VALID_AVAIL_START_PFN_2 atop(ONE_MEGABYTE + 1) +#define VALID_AVAIL_END_PFN_2 atop(ONE_MEGABYTE * 2) + +#define VALID_START_PFN_3 atop((ONE_MEGABYTE * 2) + 1) +#define VALID_END_PFN_3 atop(ONE_MEGABYTE * 3) +#define VALID_AVAIL_START_PFN_3 atop((ONE_MEGABYTE * 2) + 1) +#define VALID_AVAIL_END_PFN_3 atop(ONE_MEGABYTE * 3) + +#define VALID_START_PFN_4 atop((ONE_MEGABYTE * 3) + 1) +#define VALID_END_PFN_4 atop(ONE_MEGABYTE * 4) +#define VALID_AVAIL_START_PFN_4 atop((ONE_MEGABYTE * 3) + 1) +#define VALID_AVAIL_END_PFN_4 atop(ONE_MEGABYTE * 4) + +/* + * Total number of pages (of 4K size each) should be 256 for 1MB of memory. + */ +#define PAGE_COUNT_1M 256 + +/* + * A debug fucntion to print the content of upm. + */ + static inline void + uvm_physseg_dump_seg(uvm_physseg_t upm) + { +#if defined(DEBUG) + printf("%s: seg->start == %ld\n", __func__, + uvm_physseg_get_start(upm)); + printf("%s: seg->end == %ld\n", __func__, + uvm_physseg_get_end(upm)); + printf("%s: seg->avail_start == %ld\n", __func__, + uvm_physseg_get_avail_start(upm)); + printf("%s: seg->avail_end == %ld\n", __func__, + uvm_physseg_get_avail_end(upm)); + + printf("====\n\n"); +#else + return; +#endif /* DEBUG */ + } + +/* + * Private accessor that gets the value of uvm_physseg_graph.nentries + */ +static int +uvm_physseg_get_entries(void) +{ +#if defined(UVM_HOTPLUG) + return uvm_physseg_graph.nentries; +#else + return vm_nphysmem; +#endif /* UVM_HOTPLUG */ +} + +#if !defined(UVM_HOTPLUG) +static void * +uvm_physseg_alloc(size_t sz) +{ + return &vm_physmem[vm_nphysseg++]; +} +#endif + +/* + * Test Fixture SetUp(). + */ +static void +setup(void) +{ + /* Prerequisites for running certain calls in uvm_physseg */ + uvmexp.pagesize = PAGE_SIZE; + uvmexp.npages = 0; + uvm.page_init_done = false; + uvm_physseg_init(); +} + + +/* <---- Tests for Internal functions ----> */ +#if defined(UVM_HOTPLUG) +ATF_TC(uvm_physseg_alloc_atboot_mismatch); +ATF_TC_HEAD(uvm_physseg_alloc_atboot_mismatch, tc) +{ + atf_tc_set_md_var(tc, "descr", "boot time uvm_physseg_alloc() sanity" + "size mismatch alloc() test."); +} + +ATF_TC_BODY(uvm_physseg_alloc_atboot_mismatch, tc) +{ + uvm.page_init_done = false; + + atf_tc_expect_signal(SIGABRT, "size mismatch alloc()"); + + uvm_physseg_alloc(sizeof(struct uvm_physseg) - 1); +} + +ATF_TC(uvm_physseg_alloc_atboot_overrun); +ATF_TC_HEAD(uvm_physseg_alloc_atboot_overrun, tc) +{ + atf_tc_set_md_var(tc, "descr", "boot time uvm_physseg_alloc() sanity" + "array overrun alloc() test."); +} + +ATF_TC_BODY(uvm_physseg_alloc_atboot_overrun, tc) +{ + uvm.page_init_done = false; + + atf_tc_expect_signal(SIGABRT, "array overrun alloc()"); + + uvm_physseg_alloc((VM_PHYSSEG_MAX + 1) * sizeof(struct uvm_physseg)); + +} + +ATF_TC(uvm_physseg_alloc_sanity); +ATF_TC_HEAD(uvm_physseg_alloc_sanity, tc) +{ + atf_tc_set_md_var(tc, "descr", "further uvm_physseg_alloc() sanity checks"); +} + +ATF_TC_BODY(uvm_physseg_alloc_sanity, tc) +{ + + /* At boot time */ + uvm.page_init_done = false; + + /* Correct alloc */ + ATF_REQUIRE(uvm_physseg_alloc(VM_PHYSSEG_MAX * sizeof(struct uvm_physseg))); + + /* Retry static alloc()s as dynamic - we expect them to pass */ + uvm.page_init_done = true; + ATF_REQUIRE(uvm_physseg_alloc(sizeof(struct uvm_physseg) - 1)); + ATF_REQUIRE(uvm_physseg_alloc(2 * VM_PHYSSEG_MAX * sizeof(struct uvm_physseg))); +} + +ATF_TC(uvm_physseg_free_atboot_mismatch); +ATF_TC_HEAD(uvm_physseg_free_atboot_mismatch, tc) +{ + atf_tc_set_md_var(tc, "descr", "boot time uvm_physseg_free() sanity" + "size mismatch free() test."); +} + +ATF_TC_BODY(uvm_physseg_free_atboot_mismatch, tc) +{ + uvm.page_init_done = false; + + atf_tc_expect_signal(SIGABRT, "size mismatch free()"); + + uvm_physseg_free(&uvm_physseg[0], sizeof(struct uvm_physseg) - 1); +} + +ATF_TC(uvm_physseg_free_sanity); +ATF_TC_HEAD(uvm_physseg_free_sanity, tc) +{ + atf_tc_set_md_var(tc, "descr", "further uvm_physseg_free() sanity checks"); +} + +ATF_TC_BODY(uvm_physseg_free_sanity, tc) +{ + + /* At boot time */ + uvm.page_init_done = false; + + struct uvm_physseg *seg; + +#if VM_PHYSSEG_MAX > 1 + /* + * Note: free()ing the entire array is considered to be an + * error. Thus VM_PHYSSEG_MAX - 1. + */ + + seg = uvm_physseg_alloc((VM_PHYSSEG_MAX - 1) * sizeof(*seg)); + uvm_physseg_free(seg, (VM_PHYSSEG_MAX - 1) * sizeof(struct uvm_physseg)); +#endif + + /* Retry static alloc()s as dynamic - we expect them to pass */ + uvm.page_init_done = true; + + seg = uvm_physseg_alloc(sizeof(struct uvm_physseg) - 1); + uvm_physseg_free(seg, sizeof(struct uvm_physseg) - 1); + + seg = uvm_physseg_alloc(2 * VM_PHYSSEG_MAX * sizeof(struct uvm_physseg)); + + uvm_physseg_free(seg, 2 * VM_PHYSSEG_MAX * sizeof(struct uvm_physseg)); +} + +#if VM_PHYSSEG_MAX > 1 +ATF_TC(uvm_physseg_atboot_free_leak); +ATF_TC_HEAD(uvm_physseg_atboot_free_leak, tc) +{ + atf_tc_set_md_var(tc, "descr", + "does free() leak at boot ?\n" + "This test needs VM_PHYSSEG_MAX > 1)"); +} + +ATF_TC_BODY(uvm_physseg_atboot_free_leak, tc) +{ + + /* At boot time */ + uvm.page_init_done = false; + + /* alloc to array size */ + struct uvm_physseg *seg; + seg = uvm_physseg_alloc(VM_PHYSSEG_MAX * sizeof(*seg)); + + uvm_physseg_free(seg, sizeof(*seg)); + + atf_tc_expect_signal(SIGABRT, "array overrun on alloc() after leak"); + + ATF_REQUIRE(uvm_physseg_alloc(sizeof(struct uvm_physseg))); +} +#endif /* VM_PHYSSEG_MAX */ +#endif /* UVM_HOTPLUG */ + +/* + * Note: This function replicates verbatim what happens in + * uvm_page.c:uvm_page_init(). + * + * Please track any changes that happen there. + */ +static void +uvm_page_init_fake(struct vm_page *pagearray, psize_t pagecount) +{ + uvm_physseg_t bank; + size_t n; + + for (bank = uvm_physseg_get_first(), + uvm_physseg_seg_chomp_slab(bank, pagearray, pagecount); + uvm_physseg_valid_p(bank); + bank = uvm_physseg_get_next(bank)) { + + n = uvm_physseg_get_end(bank) - uvm_physseg_get_start(bank); + uvm_physseg_seg_alloc_from_slab(bank, n); + uvm_physseg_init_seg(bank, pagearray); + + /* set up page array pointers */ + pagearray += n; + pagecount -= n; + } + + uvm.page_init_done = true; +} + +ATF_TC(uvm_physseg_plug); +ATF_TC_HEAD(uvm_physseg_plug, tc) +{ + atf_tc_set_md_var(tc, "descr", + "Test plug functionality."); +} +/* Note: We only do the second boot time plug if VM_PHYSSEG_MAX > 1 */ +ATF_TC_BODY(uvm_physseg_plug, tc) +{ + int nentries = 0; /* Count of entries via plug done so far */ + uvm_physseg_t upm1; +#if VM_PHYSSEG_MAX > 2 + uvm_physseg_t upm2; +#endif + +#if VM_PHYSSEG_MAX > 1 + uvm_physseg_t upm3; +#endif + uvm_physseg_t upm4; + psize_t npages1 = (VALID_END_PFN_1 - VALID_START_PFN_1); + psize_t npages2 = (VALID_END_PFN_2 - VALID_START_PFN_2); + psize_t npages3 = (VALID_END_PFN_3 - VALID_START_PFN_3); + psize_t npages4 = (VALID_END_PFN_4 - VALID_START_PFN_4); + struct vm_page *pgs, *slab = malloc(sizeof(struct vm_page) * (npages1 +#if VM_PHYSSEG_MAX > 2 + + npages2 +#endif + + npages3)); + + /* Fake early boot */ + + setup(); + + /* Vanilla plug x 2 */ + ATF_REQUIRE_EQ(uvm_physseg_plug(VALID_START_PFN_1, npages1, &upm1), true); + ATF_REQUIRE_EQ(++nentries, uvm_physseg_get_entries()); + ATF_REQUIRE_EQ(0, uvmexp.npages); + +#if VM_PHYSSEG_MAX > 2 + ATF_REQUIRE_EQ(uvm_physseg_plug(VALID_START_PFN_2, npages2, &upm2), true); + ATF_REQUIRE_EQ(++nentries, uvm_physseg_get_entries()); + ATF_REQUIRE_EQ(0, uvmexp.npages); +#endif + /* Post boot: Fake all segments and pages accounted for. */ + uvm_page_init_fake(slab, npages1 + npages2 + npages3); + + ATF_CHECK_EQ(npages1 +#if VM_PHYSSEG_MAX > 2 + + npages2 +#endif + , uvmexp.npages); +#if VM_PHYSSEG_MAX > 1 + /* Scavenge plug - goes into the same slab */ + ATF_REQUIRE_EQ(uvm_physseg_plug(VALID_START_PFN_3, npages3, &upm3), true); + ATF_REQUIRE_EQ(++nentries, uvm_physseg_get_entries()); + ATF_REQUIRE_EQ(npages1 +#if VM_PHYSSEG_MAX > 2 + + npages2 +#endif + + npages3, uvmexp.npages); + + /* Scavenge plug should fit right in the slab */ + pgs = uvm_physseg_get_pg(upm3, 0); + ATF_REQUIRE(pgs > slab && pgs < (slab + npages1 + npages2 + npages3)); +#endif + /* Hot plug - goes into a brand new slab */ + ATF_REQUIRE_EQ(uvm_physseg_plug(VALID_START_PFN_4, npages4, &upm4), true); + /* The hot plug slab should have nothing to do with the original slab */ + pgs = uvm_physseg_get_pg(upm4, 0); + ATF_REQUIRE(pgs < slab || pgs > (slab + npages1 +#if VM_PHYSSEG_MAX > 2 + + npages2 +#endif + + npages3)); + +} +ATF_TC(uvm_physseg_unplug); +ATF_TC_HEAD(uvm_physseg_unplug, tc) +{ + atf_tc_set_md_var(tc, "descr", + "Test unplug functionality."); +} +ATF_TC_BODY(uvm_physseg_unplug, tc) +{ + paddr_t pa = 0; + + psize_t npages1 = (VALID_END_PFN_1 - VALID_START_PFN_1); + psize_t npages2 = (VALID_END_PFN_2 - VALID_START_PFN_2); + psize_t npages3 = (VALID_END_PFN_3 - VALID_START_PFN_3); + + struct vm_page *slab = malloc(sizeof(struct vm_page) * (npages1 + npages2 + npages3)); + + uvm_physseg_t upm; + + /* Boot time */ + setup(); + + /* We start with zero segments */ + ATF_REQUIRE_EQ(true, uvm_physseg_plug(atop(0), atop(ONE_MEGABYTE), NULL)); + ATF_REQUIRE_EQ(1, uvm_physseg_get_entries()); + /* Do we have an arbitrary offset in there ? */ + uvm_physseg_find(atop(TWOFIFTYSIX_KILO), &pa); + ATF_REQUIRE_EQ(pa, atop(TWOFIFTYSIX_KILO)); + ATF_REQUIRE_EQ(0, uvmexp.npages); /* Boot time sanity */ + +#if VM_PHYSSEG_MAX == 1 + /* + * This is the curious case at boot time, of having one + * extent(9) static entry per segment, which means that a + * fragmenting unplug will fail. + */ + atf_tc_expect_signal(SIGABRT, "fragmenting unplug for single segment"); + + /* + * In order to test the fragmenting cases, please set + * VM_PHYSSEG_MAX > 1 + */ +#endif + /* Now let's unplug from the middle */ + ATF_REQUIRE_EQ(true, uvm_physseg_unplug(atop(TWOFIFTYSIX_KILO), atop(FIVEONETWO_KILO))); + /* verify that a gap exists at TWOFIFTYSIX_KILO */ + pa = 0; /* reset */ + uvm_physseg_find(atop(TWOFIFTYSIX_KILO), &pa); + ATF_REQUIRE_EQ(pa, 0); + + /* Post boot: Fake all segments and pages accounted for. */ + uvm_page_init_fake(slab, npages1 + npages2 + npages3); + /* Account for the unplug */ + ATF_CHECK_EQ(atop(FIVEONETWO_KILO), uvmexp.npages); + + /* Original entry should fragment into two */ + ATF_REQUIRE_EQ(2, uvm_physseg_get_entries()); + + upm = uvm_physseg_find(atop(TWOFIFTYSIX_KILO + FIVEONETWO_KILO), NULL); + + ATF_REQUIRE(uvm_physseg_valid_p(upm)); + + /* Now unplug the tail fragment - should swallow the complete entry */ + ATF_REQUIRE_EQ(true, uvm_physseg_unplug(atop(TWOFIFTYSIX_KILO + FIVEONETWO_KILO), atop(TWOFIFTYSIX_KILO))); + + /* The "swallow" above should have invalidated the handle */ + ATF_REQUIRE_EQ(false, uvm_physseg_valid_p(upm)); + + /* Only the first one is left now */ + ATF_REQUIRE_EQ(1, uvm_physseg_get_entries()); + + /* Unplug from the back */ + ATF_REQUIRE_EQ(true, uvm_physseg_unplug(atop(ONETWENTYEIGHT_KILO), atop(ONETWENTYEIGHT_KILO))); + /* Shouldn't change the number of segments */ + ATF_REQUIRE_EQ(1, uvm_physseg_get_entries()); + + /* Unplug from the front */ + ATF_REQUIRE_EQ(true, uvm_physseg_unplug(0, atop(SIXTYFOUR_KILO))); + /* Shouldn't change the number of segments */ + ATF_REQUIRE_EQ(1, uvm_physseg_get_entries()); + + /* Unplugging the final fragment should fail */ + atf_tc_expect_signal(SIGABRT, "Unplugging the last segment"); + ATF_REQUIRE_EQ(true, uvm_physseg_unplug(atop(SIXTYFOUR_KILO), atop(SIXTYFOUR_KILO))); +} + + +/* <---- end Tests for Internal functions ----> */ + +/* Tests for functions exported via uvm_physseg.h */ +ATF_TC(uvm_physseg_init); +ATF_TC_HEAD(uvm_physseg_init, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests if the basic uvm_page_init() call\ + initializes the vm_physmem struct which holds the rb_tree."); +} +ATF_TC_BODY(uvm_physseg_init, tc) +{ + uvm_physseg_init(); + + ATF_REQUIRE_EQ(0, uvm_physseg_get_entries()); +} + +ATF_TC(uvm_page_physload_preload); +ATF_TC_HEAD(uvm_page_physload_preload, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests if the basic uvm_page_physload() \ + call works without a panic() in a preload scenario."); +} +ATF_TC_BODY(uvm_page_physload_preload, tc) +{ + uvm_physseg_t upm; + + setup(); + + upm = uvm_page_physload(VALID_START_PFN_1, VALID_END_PFN_1, + VALID_AVAIL_START_PFN_1, VALID_AVAIL_END_PFN_1, VM_FREELIST_DEFAULT); + + /* Should return a valid handle */ + ATF_REQUIRE(uvm_physseg_valid_p(upm)); + + /* No pages should be allocated yet */ + ATF_REQUIRE_EQ(0, uvmexp.npages); + + /* After the first call one segment should exist */ + ATF_CHECK_EQ(1, uvm_physseg_get_entries()); + + /* Insert more than one segment iff VM_PHYSSEG_MAX > 1 */ +#if VM_PHYSSEG_MAX > 1 + upm = uvm_page_physload(VALID_START_PFN_2, VALID_END_PFN_2, + VALID_AVAIL_START_PFN_2, VALID_AVAIL_END_PFN_2, VM_FREELIST_DEFAULT); + + /* Should return a valid handle */ + ATF_REQUIRE(uvm_physseg_valid_p(upm)); + + ATF_REQUIRE_EQ(0, uvmexp.npages); + + /* After the second call two segments should exist */ + ATF_CHECK_EQ(2, uvm_physseg_get_entries()); +#endif +} + +ATF_TC(uvm_page_physload_postboot); +ATF_TC_HEAD(uvm_page_physload_postboot, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests if the basic uvm_page_physload() \ + panic()s in a post boot scenario."); +} +ATF_TC_BODY(uvm_page_physload_postboot, tc) +{ + uvm_physseg_t upm; + + psize_t npages1 = (VALID_END_PFN_1 - VALID_START_PFN_1); + psize_t npages2 = (VALID_END_PFN_2 - VALID_START_PFN_2); + + struct vm_page *slab = malloc(sizeof(struct vm_page) * (npages1 + npages2)); + + setup(); + + upm = uvm_page_physload(VALID_START_PFN_1, VALID_END_PFN_1, + VALID_AVAIL_START_PFN_1, VALID_AVAIL_END_PFN_1, VM_FREELIST_DEFAULT); + + /* Should return a valid handle */ + ATF_REQUIRE(uvm_physseg_valid_p(upm)); + + /* No pages should be allocated yet */ + ATF_REQUIRE_EQ(0, uvmexp.npages); + + /* After the first call one segment should exist */ + ATF_CHECK_EQ(1, uvm_physseg_get_entries()); + + /* Post boot: Fake all segments and pages accounted for. */ + uvm_page_init_fake(slab, npages1 + npages2); + + atf_tc_expect_signal(SIGABRT, + "uvm_page_physload() called post boot"); + + upm = uvm_page_physload(VALID_START_PFN_2, VALID_END_PFN_2, + VALID_AVAIL_START_PFN_2, VALID_AVAIL_END_PFN_2, VM_FREELIST_DEFAULT); + + /* Should return a valid handle */ + ATF_REQUIRE(uvm_physseg_valid_p(upm)); + + ATF_REQUIRE_EQ(npages1 + npages2, uvmexp.npages); + + /* After the second call two segments should exist */ + ATF_CHECK_EQ(2, uvm_physseg_get_entries()); +} + +ATF_TC(uvm_physseg_handle_immutable); +ATF_TC_HEAD(uvm_physseg_handle_immutable, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests if the uvm_physseg_t handle is \ + immutable."); +} +ATF_TC_BODY(uvm_physseg_handle_immutable, tc) +{ + uvm_physseg_t upm; + + /* We insert the segments in out of order */ + + setup(); + + upm = uvm_page_physload(VALID_START_PFN_2, VALID_END_PFN_2, + VALID_AVAIL_START_PFN_2, VALID_AVAIL_END_PFN_2, VM_FREELIST_DEFAULT); + + ATF_REQUIRE_EQ(0, uvmexp.npages); + + ATF_REQUIRE_EQ(1, uvm_physseg_get_entries()); + + ATF_CHECK_EQ(UVM_PHYSSEG_TYPE_INVALID_EMPTY, uvm_physseg_get_prev(upm)); + + /* Insert more than one segment iff VM_PHYSSEG_MAX > 1 */ +#if VM_PHYSSEG_MAX > 1 + uvm_page_physload(VALID_START_PFN_1, VALID_END_PFN_1, + VALID_AVAIL_START_PFN_1, VALID_AVAIL_END_PFN_1, VM_FREELIST_DEFAULT); + + ATF_REQUIRE_EQ(0, uvmexp.npages); + + ATF_REQUIRE_EQ(2, uvm_physseg_get_entries()); + + /* Fetch Previous, we inserted a lower value */ + upm = uvm_physseg_get_prev(upm); + +#if !defined(UVM_HOTPLUG) + /* + * This test is going to fail for the Array Implementation but is + * expected to pass in the RB Tree implementation. + */ + /* Failure can be expected iff there are more than one handles */ + atf_tc_expect_fail("Mutable handle in static array impl."); +#endif + ATF_CHECK(UVM_PHYSSEG_TYPE_INVALID_EMPTY != upm); + ATF_CHECK_EQ(VALID_START_PFN_1, uvm_physseg_get_start(upm)); + ATF_CHECK_EQ(VALID_END_PFN_1, uvm_physseg_get_end(upm)); +#endif +} + +ATF_TC(uvm_physseg_seg_chomp_slab); +ATF_TC_HEAD(uvm_physseg_seg_chomp_slab, tc) +{ + atf_tc_set_md_var(tc, "descr", "The slab import code.()"); + +} +ATF_TC_BODY(uvm_physseg_seg_chomp_slab, tc) +{ + int err; + size_t i; + struct uvm_physseg *seg; + struct vm_page *slab, *pgs; + const size_t npages = UVM_PHYSSEG_BOOT_UNPLUG_MAX; /* Number of pages */ + + setup(); + + /* This is boot time */ + slab = malloc(sizeof(struct vm_page) * npages * 2); + + seg = uvm_physseg_alloc(sizeof(struct uvm_physseg)); + + uvm_physseg_seg_chomp_slab(PHYSSEG_NODE_TO_HANDLE(seg), slab, npages * 2); + + /* Should be able to allocate two 128 * sizeof(*slab) */ + ATF_REQUIRE_EQ(0, extent_alloc(seg->ext, sizeof(*slab), 1, 0, EX_BOUNDZERO, (void *)&pgs)); + err = extent_free(seg->ext, (u_long) pgs, sizeof(*slab), EX_BOUNDZERO); + +#if VM_PHYSSEG_MAX == 1 + /* + * free() needs an extra region descriptor, but we only have + * one! The classic alloc() at free() problem + */ + + ATF_REQUIRE_EQ(ENOMEM, err); +#else + /* Try alloc/free at static time */ + for (i = 0; i < npages; i++) { + ATF_REQUIRE_EQ(0, extent_alloc(seg->ext, sizeof(*slab), 1, 0, EX_BOUNDZERO, (void *)&pgs)); + err = extent_free(seg->ext, (u_long) pgs, sizeof(*slab), EX_BOUNDZERO); + ATF_REQUIRE_EQ(0, err); + } +#endif + + /* Now setup post boot */ + uvm.page_init_done = true; + + uvm_physseg_seg_chomp_slab(PHYSSEG_NODE_TO_HANDLE(seg), slab, npages * 2); + + /* Try alloc/free after uvm_page.c:uvm_page_init() as well */ + for (i = 0; i < npages; i++) { + ATF_REQUIRE_EQ(0, extent_alloc(seg->ext, sizeof(*slab), 1, 0, EX_BOUNDZERO, (void *)&pgs)); + err = extent_free(seg->ext, (u_long) pgs, sizeof(*slab), EX_BOUNDZERO); + ATF_REQUIRE_EQ(0, err); + } + +} + +ATF_TC(uvm_physseg_alloc_from_slab); +ATF_TC_HEAD(uvm_physseg_alloc_from_slab, tc) +{ + atf_tc_set_md_var(tc, "descr", "The slab alloc code.()"); + +} +ATF_TC_BODY(uvm_physseg_alloc_from_slab, tc) +{ + struct uvm_physseg *seg; + struct vm_page *slab, *pgs; + const size_t npages = UVM_PHYSSEG_BOOT_UNPLUG_MAX; /* Number of pages */ + + setup(); + + /* This is boot time */ + slab = malloc(sizeof(struct vm_page) * npages * 2); + + seg = uvm_physseg_alloc(sizeof(struct uvm_physseg)); + + uvm_physseg_seg_chomp_slab(PHYSSEG_NODE_TO_HANDLE(seg), slab, npages * 2); + + pgs = uvm_physseg_seg_alloc_from_slab(PHYSSEG_NODE_TO_HANDLE(seg), npages); + + ATF_REQUIRE(pgs != NULL); + + /* Now setup post boot */ + uvm.page_init_done = true; + +#if VM_PHYSSEG_MAX > 1 + pgs = uvm_physseg_seg_alloc_from_slab(PHYSSEG_NODE_TO_HANDLE(seg), npages); + ATF_REQUIRE(pgs != NULL); +#endif + atf_tc_expect_fail("alloc beyond extent"); + + pgs = uvm_physseg_seg_alloc_from_slab(PHYSSEG_NODE_TO_HANDLE(seg), npages); + ATF_REQUIRE(pgs != NULL); +} + +ATF_TC(uvm_physseg_init_seg); +ATF_TC_HEAD(uvm_physseg_init_seg, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests if uvm_physseg_init_seg adds pages to" + "uvmexp.npages"); +} +ATF_TC_BODY(uvm_physseg_init_seg, tc) +{ + struct uvm_physseg *seg; + struct vm_page *slab, *pgs; + const size_t npages = UVM_PHYSSEG_BOOT_UNPLUG_MAX; /* Number of pages */ + + setup(); + + /* This is boot time */ + slab = malloc(sizeof(struct vm_page) * npages * 2); + + seg = uvm_physseg_alloc(sizeof(struct uvm_physseg)); + + uvm_physseg_seg_chomp_slab(PHYSSEG_NODE_TO_HANDLE(seg), slab, npages * 2); + + pgs = uvm_physseg_seg_alloc_from_slab(PHYSSEG_NODE_TO_HANDLE(seg), npages); + + ATF_REQUIRE_EQ(0, uvmexp.npages); + + seg->start = 0; + seg->end = npages; + + seg->avail_start = 0; + seg->avail_end = npages; + + uvm_physseg_init_seg(PHYSSEG_NODE_TO_HANDLE(seg), pgs); + + ATF_REQUIRE_EQ(npages, uvmexp.npages); +} + +#if 0 +ATF_TC(uvm_physseg_init_seg); +ATF_TC_HEAD(uvm_physseg_init_seg, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests if the basic uvm_page_physload() \ + call works without a panic() after Segment is inited."); +} +ATF_TC_BODY(uvm_physseg_init_seg, tc) +{ + uvm_physseg_t upm; + psize_t npages = (VALID_END_PFN_1 - VALID_START_PFN_1); + struct vm_page *pgs = malloc(sizeof(struct vm_page) * npages); + + setup(); + upm = uvm_page_physload(VALID_START_PFN_1, VALID_END_PFN_1, + VALID_AVAIL_START_PFN_1, VALID_AVAIL_END_PFN_1, VM_FREELIST_DEFAULT); + + ATF_REQUIRE_EQ(1, uvm_physseg_get_entries()); + + ATF_CHECK_EQ(0, uvmexp.npages); + + /* + * Boot time physplug needs explicit external init, + * Duplicate what uvm_page.c:uvm_page_init() does. + * Note: not everything uvm_page_init() does gets done here. + * Read the source. + */ + /* suck in backing slab, initialise extent. */ + uvm_physseg_seg_chomp_slab(upm, pgs, npages); + + /* + * Actual pgs[] allocation, from extent. + */ + uvm_physseg_alloc_from_slab(upm, npages); + + /* Now we initialize the segment */ + uvm_physseg_init_seg(upm, pgs); + + /* Done with boot simulation */ + extent_init(); + uvm.page_init_done = true; + + /* We have total memory of 1MB */ + ATF_CHECK_EQ(PAGE_COUNT_1M, uvmexp.npages); + + upm =uvm_page_physload(VALID_START_PFN_2, VALID_END_PFN_2, + VALID_AVAIL_START_PFN_2, VALID_AVAIL_END_PFN_2, VM_FREELIST_DEFAULT); + ATF_REQUIRE_EQ(2, uvm_physseg_get_entries()); + + /* We added another 1MB so PAGE_COUNT_1M + PAGE_COUNT_1M */ + ATF_CHECK_EQ(PAGE_COUNT_1M + PAGE_COUNT_1M, uvmexp.npages); + +} +#endif + +ATF_TC(uvm_physseg_get_start); +ATF_TC_HEAD(uvm_physseg_get_start, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests if the start PFN is returned \ + correctly from a segment created via uvm_page_physload()."); +} +ATF_TC_BODY(uvm_physseg_get_start, tc) +{ + uvm_physseg_t upm; + + /* Fake early boot */ + setup(); + + upm = uvm_page_physload(VALID_START_PFN_1, VALID_END_PFN_1, + VALID_AVAIL_START_PFN_1, VALID_AVAIL_END_PFN_1, VM_FREELIST_DEFAULT); + + ATF_REQUIRE_EQ(0, uvmexp.npages); + + ATF_REQUIRE_EQ(1, uvm_physseg_get_entries()); + + ATF_CHECK_EQ(VALID_START_PFN_1, uvm_physseg_get_start(upm)); + + /* This test will be triggered only if there are 2 or more segments. */ +#if VM_PHYSSEG_MAX > 1 + upm = uvm_page_physload(VALID_START_PFN_2, VALID_END_PFN_2, + VALID_AVAIL_START_PFN_2, VALID_AVAIL_END_PFN_2, VM_FREELIST_DEFAULT); + + ATF_REQUIRE_EQ(2, uvm_physseg_get_entries()); + + ATF_REQUIRE_EQ(0, uvmexp.npages); + + ATF_CHECK_EQ(VALID_START_PFN_2, uvm_physseg_get_start(upm)); +#endif +} + +ATF_TC(uvm_physseg_get_start_invalid); +ATF_TC_HEAD(uvm_physseg_get_start_invalid, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests the invalid / error conditions \ + correctly when uvm_physseg_get_start() is called with invalid \ + parameter values."); +} +ATF_TC_BODY(uvm_physseg_get_start_invalid, tc) +{ + /* Check for pgs == NULL */ + setup(); + uvm_page_physload(VALID_START_PFN_1, VALID_END_PFN_1, + VALID_AVAIL_START_PFN_1, VALID_AVAIL_END_PFN_1, VM_FREELIST_DEFAULT); + + /* Force other check conditions */ + uvm.page_init_done = true; + + ATF_REQUIRE_EQ(0, uvmexp.npages); + + ATF_REQUIRE_EQ(1, uvm_physseg_get_entries()); + + ATF_REQUIRE_EQ(true, uvm.page_init_done); + + /* Invalid uvm_physseg_t */ + ATF_CHECK_EQ((paddr_t) -1, + uvm_physseg_get_start(UVM_PHYSSEG_TYPE_INVALID)); +} + +ATF_TC(uvm_physseg_get_end); +ATF_TC_HEAD(uvm_physseg_get_end, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests if the end PFN is returned \ + correctly from a segment created via uvm_page_physload()."); +} +ATF_TC_BODY(uvm_physseg_get_end, tc) +{ + uvm_physseg_t upm; + + setup(); + upm = uvm_page_physload(VALID_START_PFN_1, VALID_END_PFN_1, + VALID_AVAIL_START_PFN_1, VALID_AVAIL_END_PFN_1, VM_FREELIST_DEFAULT); + + ATF_REQUIRE_EQ(0, uvmexp.npages); + + ATF_REQUIRE_EQ(1, uvm_physseg_get_entries()); + + ATF_CHECK_EQ(VALID_END_PFN_1, uvm_physseg_get_end(upm)); + + /* This test will be triggered only if there are 2 or more segments. */ +#if VM_PHYSSEG_MAX > 1 + upm = uvm_page_physload(VALID_START_PFN_2, VALID_END_PFN_2, + VALID_AVAIL_START_PFN_2, VALID_AVAIL_END_PFN_2, VM_FREELIST_DEFAULT); + + ATF_REQUIRE_EQ(2, uvm_physseg_get_entries()); + + ATF_REQUIRE_EQ(0, uvmexp.npages); + + ATF_CHECK_EQ(VALID_END_PFN_2, uvm_physseg_get_end(upm)); +#endif +} + +ATF_TC(uvm_physseg_get_end_invalid); +ATF_TC_HEAD(uvm_physseg_get_end_invalid, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests the invalid / error conditions \ + correctly when uvm_physseg_get_end() is called with invalid \ + parameter values."); +} +ATF_TC_BODY(uvm_physseg_get_end_invalid, tc) +{ + /* Check for pgs == NULL */ + setup(); + uvm_page_physload(VALID_START_PFN_1, VALID_END_PFN_1, + VALID_AVAIL_START_PFN_1, VALID_AVAIL_END_PFN_1, VM_FREELIST_DEFAULT); + + /* Force other check conditions */ + uvm.page_init_done = true; + + ATF_REQUIRE_EQ(0, uvmexp.npages); + + ATF_REQUIRE_EQ(1, uvm_physseg_get_entries()); + + ATF_REQUIRE_EQ(true, uvm.page_init_done); + + /* Invalid uvm_physseg_t */ + ATF_CHECK_EQ((paddr_t) -1, + uvm_physseg_get_end(UVM_PHYSSEG_TYPE_INVALID)); +} + +ATF_TC(uvm_physseg_get_avail_start); +ATF_TC_HEAD(uvm_physseg_get_avail_start, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests if the avail_start PFN is \ + returned correctly from a segment created via uvm_page_physload()."); +} +ATF_TC_BODY(uvm_physseg_get_avail_start, tc) +{ + uvm_physseg_t upm; + + setup(); + upm = uvm_page_physload(VALID_START_PFN_1, VALID_END_PFN_1, + VALID_AVAIL_START_PFN_1, VALID_AVAIL_END_PFN_1, VM_FREELIST_DEFAULT); + + ATF_REQUIRE_EQ(0, uvmexp.npages); + + ATF_REQUIRE_EQ(1, uvm_physseg_get_entries()); + + ATF_CHECK_EQ(VALID_AVAIL_START_PFN_1, uvm_physseg_get_avail_start(upm)); + + /* This test will be triggered only if there are 2 or more segments. */ +#if VM_PHYSSEG_MAX > 1 + upm = uvm_page_physload(VALID_START_PFN_2, VALID_END_PFN_2, + VALID_AVAIL_START_PFN_2, VALID_AVAIL_END_PFN_2, VM_FREELIST_DEFAULT); + + ATF_REQUIRE_EQ(0, uvmexp.npages); + + ATF_REQUIRE_EQ(2, uvm_physseg_get_entries()); + + ATF_CHECK_EQ(VALID_AVAIL_START_PFN_2, uvm_physseg_get_avail_start(upm)); +#endif +} + +ATF_TC(uvm_physseg_get_avail_start_invalid); +ATF_TC_HEAD(uvm_physseg_get_avail_start_invalid, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests the invalid / error conditions \ + correctly when uvm_physseg_get_avail_start() is called with invalid\ + parameter values."); +} +ATF_TC_BODY(uvm_physseg_get_avail_start_invalid, tc) +{ + /* Check for pgs == NULL */ + setup(); + uvm_page_physload(VALID_START_PFN_1, VALID_END_PFN_1, + VALID_AVAIL_START_PFN_1, VALID_AVAIL_END_PFN_1, VM_FREELIST_DEFAULT); + + /* Force other check conditions */ + uvm.page_init_done = true; + + ATF_REQUIRE_EQ(0, uvmexp.npages); + + ATF_REQUIRE_EQ(1, uvm_physseg_get_entries()); + + ATF_REQUIRE_EQ(true, uvm.page_init_done); + + /* Invalid uvm_physseg_t */ + ATF_CHECK_EQ((paddr_t) -1, + uvm_physseg_get_avail_start(UVM_PHYSSEG_TYPE_INVALID)); +} + +ATF_TC(uvm_physseg_get_avail_end); +ATF_TC_HEAD(uvm_physseg_get_avail_end, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests if the avail_end PFN is \ + returned correctly from a segment created via uvm_page_physload()."); +} +ATF_TC_BODY(uvm_physseg_get_avail_end, tc) +{ + uvm_physseg_t upm; + + setup(); + upm = uvm_page_physload(VALID_START_PFN_1, VALID_END_PFN_1, + VALID_AVAIL_START_PFN_1, VALID_AVAIL_END_PFN_1, VM_FREELIST_DEFAULT); + + ATF_REQUIRE_EQ(0, uvmexp.npages); + + ATF_REQUIRE_EQ(1, uvm_physseg_get_entries()); + + ATF_CHECK_EQ(VALID_AVAIL_END_PFN_1, uvm_physseg_get_avail_end(upm)); + + /* This test will be triggered only if there are 2 or more segments. */ +#if VM_PHYSSEG_MAX > 1 + upm = uvm_page_physload(VALID_START_PFN_2, VALID_END_PFN_2, + VALID_AVAIL_START_PFN_2, VALID_AVAIL_END_PFN_2, VM_FREELIST_DEFAULT); + + ATF_REQUIRE_EQ(2, uvm_physseg_get_entries()); + + ATF_REQUIRE_EQ(0, uvmexp.npages); + + ATF_CHECK_EQ(VALID_AVAIL_END_PFN_2, uvm_physseg_get_avail_end(upm)); +#endif +} + +ATF_TC(uvm_physseg_get_avail_end_invalid); +ATF_TC_HEAD(uvm_physseg_get_avail_end_invalid, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests the invalid / error conditions \ + correctly when uvm_physseg_get_avail_end() is called with invalid\ + parameter values."); +} +ATF_TC_BODY(uvm_physseg_get_avail_end_invalid, tc) +{ + /* Check for pgs == NULL */ + setup(); + uvm_page_physload(VALID_START_PFN_1, VALID_END_PFN_1, + VALID_AVAIL_START_PFN_1, VALID_AVAIL_END_PFN_1, VM_FREELIST_DEFAULT); + + /* Force other check conditions */ + uvm.page_init_done = true; + + ATF_REQUIRE_EQ(0, uvmexp.npages); + + ATF_REQUIRE_EQ(1, uvm_physseg_get_entries()); + + ATF_REQUIRE_EQ(true, uvm.page_init_done); + + /* Invalid uvm_physseg_t */ + ATF_CHECK_EQ((paddr_t) -1, + uvm_physseg_get_avail_end(UVM_PHYSSEG_TYPE_INVALID)); +} + +ATF_TC(uvm_physseg_get_next); +ATF_TC_HEAD(uvm_physseg_get_next, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests the pointer values for next \ + segment using the uvm_physseg_get_next() call."); +} +ATF_TC_BODY(uvm_physseg_get_next, tc) +{ + uvm_physseg_t upm; +#if VM_PHYSSEG_MAX > 1 + uvm_physseg_t upm_next; +#endif + + /* We insert the segments in ascending order */ + + setup(); + upm = uvm_page_physload(VALID_START_PFN_1, VALID_END_PFN_1, + VALID_AVAIL_START_PFN_1, VALID_AVAIL_END_PFN_1, VM_FREELIST_DEFAULT); + + ATF_REQUIRE_EQ(0, uvmexp.npages); + + ATF_REQUIRE_EQ(1, uvm_physseg_get_entries()); + + ATF_CHECK_EQ(UVM_PHYSSEG_TYPE_INVALID_OVERFLOW, + uvm_physseg_get_next(upm)); + + /* This test will be triggered only if there are 2 or more segments. */ +#if VM_PHYSSEG_MAX > 1 + upm_next = uvm_page_physload(VALID_START_PFN_2, VALID_END_PFN_2, + VALID_AVAIL_START_PFN_2, VALID_AVAIL_END_PFN_2, VM_FREELIST_DEFAULT); + + ATF_REQUIRE_EQ(0, uvmexp.npages); + + ATF_REQUIRE_EQ(2, uvm_physseg_get_entries()); + + upm = uvm_physseg_get_next(upm); /* Fetch Next */ + + ATF_CHECK_EQ(upm_next, upm); + ATF_CHECK_EQ(VALID_START_PFN_2, uvm_physseg_get_start(upm)); + ATF_CHECK_EQ(VALID_END_PFN_2, uvm_physseg_get_end(upm)); +#endif + + /* This test will be triggered only if there are 3 or more segments. */ +#if VM_PHYSSEG_MAX > 2 + upm_next = uvm_page_physload(VALID_START_PFN_3, VALID_END_PFN_3, + VALID_AVAIL_START_PFN_3, VALID_AVAIL_END_PFN_3, VM_FREELIST_DEFAULT); + + ATF_REQUIRE_EQ(0, uvmexp.npages); + + ATF_REQUIRE_EQ(3, uvm_physseg_get_entries()); + + upm = uvm_physseg_get_next(upm); /* Fetch Next */ + + ATF_CHECK_EQ(upm_next, upm); + ATF_CHECK_EQ(VALID_START_PFN_3, uvm_physseg_get_start(upm)); + ATF_CHECK_EQ(VALID_END_PFN_3, uvm_physseg_get_end(upm)); +#endif +} + +ATF_TC(uvm_physseg_get_next_invalid); +ATF_TC_HEAD(uvm_physseg_get_next_invalid, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests the invalid / error conditions \ + correctly when uvm_physseg_get_next() is called with invalid \ + parameter values."); +} +ATF_TC_BODY(uvm_physseg_get_next_invalid, tc) +{ + uvm_physseg_t upm = UVM_PHYSSEG_TYPE_INVALID; + + ATF_CHECK_EQ(UVM_PHYSSEG_TYPE_INVALID, uvm_physseg_get_next(upm)); +} + +ATF_TC(uvm_physseg_get_prev); +ATF_TC_HEAD(uvm_physseg_get_prev, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests the pointer values for previous \ + segment using the uvm_physseg_get_prev() call."); +} +ATF_TC_BODY(uvm_physseg_get_prev, tc) +{ +#if VM_PHYSSEG_MAX > 1 + uvm_physseg_t upm; +#endif + uvm_physseg_t upm_prev; + + + setup(); + upm_prev = uvm_page_physload(VALID_START_PFN_1, VALID_END_PFN_1, + VALID_AVAIL_START_PFN_1, VALID_AVAIL_END_PFN_1, VM_FREELIST_DEFAULT); + + ATF_REQUIRE_EQ(0, uvmexp.npages); + + ATF_REQUIRE_EQ(1, uvm_physseg_get_entries()); + + ATF_CHECK_EQ(UVM_PHYSSEG_TYPE_INVALID_EMPTY, + uvm_physseg_get_prev(upm_prev)); + + /* This test will be triggered only if there are 2 or more segments. */ +#if VM_PHYSSEG_MAX > 1 + upm = uvm_page_physload(VALID_START_PFN_2, VALID_END_PFN_2, + VALID_AVAIL_START_PFN_2, VALID_AVAIL_END_PFN_2, VM_FREELIST_DEFAULT); + + ATF_REQUIRE_EQ(0, uvmexp.npages); + + ATF_REQUIRE_EQ(2, uvm_physseg_get_entries()); + + /* Fetch Previous, we inserted a lower value */ + upm = uvm_physseg_get_prev(upm); + + ATF_CHECK_EQ(upm_prev, upm); + ATF_CHECK_EQ(VALID_START_PFN_1, uvm_physseg_get_start(upm)); + ATF_CHECK_EQ(VALID_END_PFN_1, uvm_physseg_get_end(upm)); +#endif + + /* This test will be triggered only if there are 3 or more segments. */ +#if VM_PHYSSEG_MAX > 2 + uvm_page_physload(VALID_START_PFN_3, VALID_END_PFN_3, + VALID_AVAIL_START_PFN_3, VALID_AVAIL_END_PFN_3, VM_FREELIST_DEFAULT); + + ATF_REQUIRE_EQ(0, uvmexp.npages); + + ATF_REQUIRE_EQ(3, uvm_physseg_get_entries()); + + /* + * This will return a UVM_PHYSSEG_TYPE_INVALID_EMPTY we are at the + * lowest + */ + upm = uvm_physseg_get_prev(upm); + + ATF_CHECK_EQ(UVM_PHYSSEG_TYPE_INVALID_EMPTY, upm); +#endif +} + +ATF_TC(uvm_physseg_get_prev_invalid); +ATF_TC_HEAD(uvm_physseg_get_prev_invalid, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests the invalid / error conditions \ + correctly when uvm_physseg_get_prev() is called with invalid \ + parameter values."); +} +ATF_TC_BODY(uvm_physseg_get_prev_invalid, tc) +{ + uvm_physseg_t upm = UVM_PHYSSEG_TYPE_INVALID; + + ATF_CHECK_EQ(UVM_PHYSSEG_TYPE_INVALID, uvm_physseg_get_prev(upm)); +} + +ATF_TC(uvm_physseg_get_first); +ATF_TC_HEAD(uvm_physseg_get_first, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests the pointer values for first \ + segment (lowest node) using the uvm_physseg_get_first() call."); +} +ATF_TC_BODY(uvm_physseg_get_first, tc) +{ + uvm_physseg_t upm = UVM_PHYSSEG_TYPE_INVALID_EMPTY; + uvm_physseg_t upm_first; + + /* Fake early boot */ + setup(); + + /* No nodes exist */ + ATF_CHECK_EQ(upm, uvm_physseg_get_first()); + + upm_first = uvm_page_physload(VALID_START_PFN_2, VALID_END_PFN_2, + VALID_AVAIL_START_PFN_2, VALID_AVAIL_END_PFN_2, VM_FREELIST_DEFAULT); + + ATF_REQUIRE_EQ(0, uvmexp.npages); + + ATF_REQUIRE_EQ(1, uvm_physseg_get_entries()); + + /* Pointer to first should be the least valued node */ + upm = uvm_physseg_get_first(); + ATF_CHECK_EQ(upm_first, upm); + ATF_CHECK_EQ(VALID_START_PFN_2, uvm_physseg_get_start(upm)); + ATF_CHECK_EQ(VALID_END_PFN_2, uvm_physseg_get_end(upm)); + ATF_CHECK_EQ(VALID_AVAIL_START_PFN_2, uvm_physseg_get_avail_start(upm)); + ATF_CHECK_EQ(VALID_AVAIL_END_PFN_2, uvm_physseg_get_avail_end(upm)); + + /* This test will be triggered only if there are 2 or more segments. */ +#if VM_PHYSSEG_MAX > 1 + /* Insert a node of lesser value */ + upm_first = uvm_page_physload(VALID_START_PFN_1, VALID_END_PFN_1, + VALID_AVAIL_START_PFN_1, VALID_AVAIL_END_PFN_1, VM_FREELIST_DEFAULT); + + ATF_CHECK_EQ(0, uvmexp.npages); + + ATF_REQUIRE_EQ(2, uvm_physseg_get_entries()); + + /* Pointer to first should be the least valued node */ + upm = uvm_physseg_get_first(); + ATF_CHECK_EQ(upm_first, upm); + ATF_CHECK_EQ(VALID_START_PFN_1, uvm_physseg_get_start(upm)); + ATF_CHECK_EQ(VALID_END_PFN_1, uvm_physseg_get_end(upm)); + ATF_CHECK_EQ(VALID_AVAIL_START_PFN_1, uvm_physseg_get_avail_start(upm)); + ATF_CHECK_EQ(VALID_AVAIL_END_PFN_1, uvm_physseg_get_avail_end(upm)); +#endif + + /* This test will be triggered only if there are 3 or more segments. */ +#if VM_PHYSSEG_MAX > 2 + /* Insert a node of higher value */ + upm_first =uvm_page_physload(VALID_START_PFN_3, VALID_END_PFN_3, + VALID_AVAIL_START_PFN_3, VALID_AVAIL_END_PFN_3, VM_FREELIST_DEFAULT); + + ATF_CHECK_EQ(0, uvmexp.npages); + + ATF_REQUIRE_EQ(3, uvm_physseg_get_entries()); + + /* Pointer to first should be the least valued node */ + upm = uvm_physseg_get_first(); + ATF_CHECK(upm_first != upm); + ATF_CHECK_EQ(VALID_START_PFN_1, uvm_physseg_get_start(upm)); + ATF_CHECK_EQ(VALID_END_PFN_1, uvm_physseg_get_end(upm)); + ATF_CHECK_EQ(VALID_AVAIL_START_PFN_1, uvm_physseg_get_avail_start(upm)); + ATF_CHECK_EQ(VALID_AVAIL_END_PFN_1, uvm_physseg_get_avail_end(upm)); +#endif +} + +ATF_TC(uvm_physseg_get_last); +ATF_TC_HEAD(uvm_physseg_get_last, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests the pointer values for last \ + segment using the uvm_physseg_get_last() call."); +} +ATF_TC_BODY(uvm_physseg_get_last, tc) +{ + uvm_physseg_t upm = UVM_PHYSSEG_TYPE_INVALID_EMPTY; + uvm_physseg_t upm_last; + + setup(); + + /* No nodes exist */ + ATF_CHECK_EQ(upm, uvm_physseg_get_last()); + + upm_last = uvm_page_physload(VALID_START_PFN_1, VALID_END_PFN_1, + VALID_AVAIL_START_PFN_1, VALID_AVAIL_END_PFN_1, VM_FREELIST_DEFAULT); + + ATF_REQUIRE_EQ(0, uvmexp.npages); + + ATF_REQUIRE_EQ(1, uvm_physseg_get_entries()); + + /* Pointer to last should be the most valued node */ + upm = uvm_physseg_get_last(); + ATF_CHECK_EQ(upm_last, upm); + ATF_CHECK_EQ(VALID_START_PFN_1, uvm_physseg_get_start(upm)); + ATF_CHECK_EQ(VALID_END_PFN_1, uvm_physseg_get_end(upm)); + ATF_CHECK_EQ(VALID_AVAIL_START_PFN_1, uvm_physseg_get_avail_start(upm)); + ATF_CHECK_EQ(VALID_AVAIL_END_PFN_1, uvm_physseg_get_avail_end(upm)); + + /* This test will be triggered only if there are 2 or more segments. */ +#if VM_PHYSSEG_MAX > 1 + /* Insert node of greater value */ + upm_last = uvm_page_physload(VALID_START_PFN_2, VALID_END_PFN_2, + VALID_AVAIL_START_PFN_2, VALID_AVAIL_END_PFN_2, VM_FREELIST_DEFAULT); + + ATF_REQUIRE_EQ(0, uvmexp.npages); + + ATF_REQUIRE_EQ(2, uvm_physseg_get_entries()); + + /* Pointer to last should be the most valued node */ + upm = uvm_physseg_get_last(); + ATF_CHECK_EQ(upm_last, upm); + ATF_CHECK_EQ(VALID_START_PFN_2, uvm_physseg_get_start(upm)); + ATF_CHECK_EQ(VALID_END_PFN_2, uvm_physseg_get_end(upm)); + ATF_CHECK_EQ(VALID_AVAIL_START_PFN_2, uvm_physseg_get_avail_start(upm)); + ATF_CHECK_EQ(VALID_AVAIL_END_PFN_2, uvm_physseg_get_avail_end(upm)); +#endif + + /* This test will be triggered only if there are 3 or more segments. */ +#if VM_PHYSSEG_MAX > 2 + /* Insert node of greater value */ + upm_last = uvm_page_physload(VALID_START_PFN_3, VALID_END_PFN_3, + VALID_AVAIL_START_PFN_3, VALID_AVAIL_END_PFN_3, VM_FREELIST_DEFAULT); + + ATF_REQUIRE_EQ(0, uvmexp.npages); + + ATF_REQUIRE_EQ(3, uvm_physseg_get_entries()); + + /* Pointer to last should be the most valued node */ + upm = uvm_physseg_get_last(); + ATF_CHECK_EQ(upm_last, upm); + ATF_CHECK_EQ(VALID_START_PFN_3, uvm_physseg_get_start(upm)); + ATF_CHECK_EQ(VALID_END_PFN_3, uvm_physseg_get_end(upm)); + ATF_CHECK_EQ(VALID_AVAIL_START_PFN_3, uvm_physseg_get_avail_start(upm)); + ATF_CHECK_EQ(VALID_AVAIL_END_PFN_3, uvm_physseg_get_avail_end(upm)); +#endif +} + +ATF_TC(uvm_physseg_valid); +ATF_TC_HEAD(uvm_physseg_valid, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests the pointer value for current \ + segment is valid using the uvm_physseg_valid_p() call."); +} +ATF_TC_BODY(uvm_physseg_valid, tc) +{ + psize_t npages = (VALID_END_PFN_1 - VALID_START_PFN_1); + + struct vm_page *pgs = malloc(sizeof(struct vm_page) * npages); + + uvm_physseg_t upm; + + setup(); + upm = uvm_page_physload(VALID_START_PFN_1, VALID_END_PFN_1, + VALID_AVAIL_START_PFN_1, VALID_AVAIL_END_PFN_1, VM_FREELIST_DEFAULT); + + ATF_REQUIRE_EQ(0, uvmexp.npages); + + ATF_REQUIRE_EQ(1, uvm_physseg_get_entries()); + + uvm_physseg_init_seg(upm, pgs); + + ATF_REQUIRE_EQ(PAGE_COUNT_1M, uvmexp.npages); + + ATF_CHECK_EQ(true, uvm_physseg_valid_p(upm)); +} + +ATF_TC(uvm_physseg_valid_invalid); +ATF_TC_HEAD(uvm_physseg_valid_invalid, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests the pointer value for current \ + segment is invalid using the uvm_physseg_valid_p() call."); +} +ATF_TC_BODY(uvm_physseg_valid_invalid, tc) +{ + uvm_physseg_t upm; + + setup(); + upm = uvm_page_physload(VALID_START_PFN_1, VALID_END_PFN_1, + VALID_AVAIL_START_PFN_1, VALID_AVAIL_END_PFN_1, VM_FREELIST_DEFAULT); + + /* Force other check conditions */ + uvm.page_init_done = true; + + ATF_REQUIRE_EQ(true, uvm.page_init_done); + + /* Invalid uvm_physseg_t */ + ATF_CHECK_EQ(false, uvm_physseg_valid_p(UVM_PHYSSEG_TYPE_INVALID)); + + /* + * Without any pages initialized for segment, it is considered + * invalid + */ + ATF_CHECK_EQ(false, uvm_physseg_valid_p(upm)); +} + +ATF_TC(uvm_physseg_get_highest); +ATF_TC_HEAD(uvm_physseg_get_highest, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests if the returned PFN matches \ + the highest PFN in use by the system."); +} +ATF_TC_BODY(uvm_physseg_get_highest, tc) +{ + setup(); + uvm_page_physload(VALID_START_PFN_1, VALID_END_PFN_1, + VALID_AVAIL_START_PFN_1, VALID_AVAIL_END_PFN_1, VM_FREELIST_DEFAULT); + + /* Only one segment so highest is the current */ + ATF_CHECK_EQ(VALID_AVAIL_END_PFN_1 - 1, uvm_physseg_get_highest_frame()); + + /* This test will be triggered only if there are 2 or more segments. */ +#if VM_PHYSSEG_MAX > 1 + uvm_page_physload(VALID_START_PFN_3, VALID_END_PFN_3, + VALID_AVAIL_START_PFN_3, VALID_AVAIL_END_PFN_3, VM_FREELIST_DEFAULT); + + /* PFN_3 > PFN_1 */ + ATF_CHECK_EQ(VALID_AVAIL_END_PFN_3 - 1, uvm_physseg_get_highest_frame()); +#endif + + /* This test will be triggered only if there are 3 or more segments. */ +#if VM_PHYSSEG_MAX > 2 + uvm_page_physload(VALID_START_PFN_2, VALID_END_PFN_2, + VALID_AVAIL_START_PFN_2, VALID_AVAIL_END_PFN_2, VM_FREELIST_DEFAULT); + + /* PFN_3 > PFN_2 */ + ATF_CHECK_EQ(VALID_AVAIL_END_PFN_3 - 1, uvm_physseg_get_highest_frame()); +#endif +} + +ATF_TC(uvm_physseg_get_free_list); +ATF_TC_HEAD(uvm_physseg_get_free_list, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests if the returned Free List type \ + of a segment matches the one returned from \ + uvm_physseg_get_free_list() call."); +} +ATF_TC_BODY(uvm_physseg_get_free_list, tc) +{ + uvm_physseg_t upm; + + /* Fake early boot */ + setup(); + + /* Insertions are made in ascending order */ + upm = uvm_page_physload(VALID_START_PFN_1, VALID_END_PFN_1, + VALID_AVAIL_START_PFN_1, VALID_AVAIL_END_PFN_1, VM_FREELIST_DEFAULT); + + ATF_CHECK_EQ(VM_FREELIST_DEFAULT, uvm_physseg_get_free_list(upm)); + + /* This test will be triggered only if there are 2 or more segments. */ +#if VM_PHYSSEG_MAX > 1 + upm = uvm_page_physload(VALID_START_PFN_2, VALID_END_PFN_2, + VALID_AVAIL_START_PFN_2, VALID_AVAIL_END_PFN_2, VM_FREELIST_FIRST16); + + ATF_CHECK_EQ(VM_FREELIST_FIRST16, uvm_physseg_get_free_list(upm)); +#endif + + /* This test will be triggered only if there are 3 or more segments. */ +#if VM_PHYSSEG_MAX > 2 + upm = uvm_page_physload(VALID_START_PFN_3, VALID_END_PFN_3, + VALID_AVAIL_START_PFN_3, VALID_AVAIL_END_PFN_3, VM_FREELIST_FIRST1G); + + ATF_CHECK_EQ(VM_FREELIST_FIRST1G, uvm_physseg_get_free_list(upm)); +#endif +} + +ATF_TC(uvm_physseg_get_start_hint); +ATF_TC_HEAD(uvm_physseg_get_start_hint, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests if the returned start_hint value \ + of a segment matches the one returned from \ + uvm_physseg_get_start_hint() call."); +} +ATF_TC_BODY(uvm_physseg_get_start_hint, tc) +{ + uvm_physseg_t upm; + + setup(); + upm = uvm_page_physload(VALID_START_PFN_1, VALID_END_PFN_1, + VALID_AVAIL_START_PFN_1, VALID_AVAIL_END_PFN_1, VM_FREELIST_DEFAULT); + + /* Will be Zero since no specific value is set during init */ + ATF_CHECK_EQ(0, uvm_physseg_get_start_hint(upm)); +} + +ATF_TC(uvm_physseg_set_start_hint); +ATF_TC_HEAD(uvm_physseg_set_start_hint, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests if the returned start_hint value \ + of a segment matches the one set by the \ + uvm_physseg_set_start_hint() call."); +} +ATF_TC_BODY(uvm_physseg_set_start_hint, tc) +{ + psize_t npages = (VALID_END_PFN_1 - VALID_START_PFN_1); + + struct vm_page *pgs = malloc(sizeof(struct vm_page) * npages); + + uvm_physseg_t upm; + + setup(); + upm = uvm_page_physload(VALID_START_PFN_1, VALID_END_PFN_1, + VALID_AVAIL_START_PFN_1, VALID_AVAIL_END_PFN_1, VM_FREELIST_DEFAULT); + + uvm_physseg_init_seg(upm, pgs); + + ATF_CHECK_EQ(true, uvm_physseg_set_start_hint(upm, atop(128))); + + /* Will be atop(128) since no specific value is set above */ + ATF_CHECK_EQ(atop(128), uvm_physseg_get_start_hint(upm)); +} + +ATF_TC(uvm_physseg_set_start_hint_invalid); +ATF_TC_HEAD(uvm_physseg_set_start_hint_invalid, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests if the returned value is false \ + when an invalid segment matches the one trying to set by the \ + uvm_physseg_set_start_hint() call."); +} +ATF_TC_BODY(uvm_physseg_set_start_hint_invalid, tc) +{ + uvm_physseg_t upm; + + setup(); + upm = uvm_page_physload(VALID_START_PFN_1, VALID_END_PFN_1, + VALID_AVAIL_START_PFN_1, VALID_AVAIL_END_PFN_1, VM_FREELIST_DEFAULT); + + /* Force other check conditions */ + uvm.page_init_done = true; + + ATF_REQUIRE_EQ(true, uvm.page_init_done); + + ATF_CHECK_EQ(false, uvm_physseg_set_start_hint(upm, atop(128))); + + /* + * Will be Zero since no specific value is set after the init + * due to failure + */ + atf_tc_expect_signal(SIGABRT, "invalid uvm_physseg_t handle"); + + ATF_CHECK_EQ(0, uvm_physseg_get_start_hint(upm)); +} + +ATF_TC(uvm_physseg_get_pg); +ATF_TC_HEAD(uvm_physseg_get_pg, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests if the returned vm_page struct \ + is correct when fetched by uvm_physseg_get_pg() call."); +} +ATF_TC_BODY(uvm_physseg_get_pg, tc) +{ + psize_t npages = (VALID_END_PFN_1 - VALID_START_PFN_1); + + struct vm_page *pgs = malloc(sizeof(struct vm_page) * npages); + + struct vm_page *extracted_pg = NULL; + + uvm_physseg_t upm; + + setup(); + upm = uvm_page_physload(VALID_START_PFN_1, VALID_END_PFN_1, + VALID_AVAIL_START_PFN_1, VALID_AVAIL_END_PFN_1, VM_FREELIST_DEFAULT); + + ATF_REQUIRE_EQ(1, uvm_physseg_get_entries()); + + ATF_REQUIRE_EQ(0, uvmexp.npages); + + /* Now we initialize the segment */ + uvm_physseg_init_seg(upm, pgs); + + ATF_REQUIRE_EQ(PAGE_COUNT_1M, uvmexp.npages); + + ATF_REQUIRE_EQ(NULL, extracted_pg); + + /* Try fetching the 5th Page in the Segment */ + extracted_pg = uvm_physseg_get_pg(upm, 5); + + /* Values of phys_addr is n * PAGE_SIZE where n is the page number */ + ATF_CHECK_EQ(5 * PAGE_SIZE, extracted_pg->phys_addr); + + /* Try fetching the 113th Page in the Segment */ + extracted_pg = uvm_physseg_get_pg(upm, 113); + + ATF_CHECK_EQ(113 * PAGE_SIZE, extracted_pg->phys_addr); +} + +#ifdef __HAVE_PMAP_PHYSSEG +ATF_TC(uvm_physseg_get_pmseg); +ATF_TC_HEAD(uvm_physseg_get_pmseg, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests if the returned pmap_physseg \ + struct is correct when fetched by uvm_physseg_get_pmseg() call."); +} +ATF_TC_BODY(uvm_physseg_get_pmseg, tc) +{ + psize_t npages = (VALID_END_PFN_1 - VALID_START_PFN_1); + + struct vm_page *pgs = malloc(sizeof(struct vm_page) * npages); + + struct pmap_physseg pmseg = { true }; + + struct pmap_physseg *extracted_pmseg = NULL; + + uvm_physseg_t upm; + + setup(); + upm = uvm_page_physload(VALID_START_PFN_1, VALID_END_PFN_1, + VALID_AVAIL_START_PFN_1, VALID_AVAIL_END_PFN_1, VM_FREELIST_DEFAULT); + + ATF_REQUIRE_EQ(1, uvm_physseg_get_entries()); + + ATF_REQUIRE_EQ(0, uvmexp.npages); + + /* Now we initialize the segment */ + uvm_physseg_init_seg(upm, pgs); + + ATF_REQUIRE_EQ(PAGE_COUNT_1M, uvmexp.npages); + + ATF_REQUIRE_EQ(NULL, extracted_pmseg); + + ATF_REQUIRE_EQ(true, pmseg.dummy_variable); + + /* Extract the current pmseg */ + extracted_pmseg = uvm_physseg_get_pmseg(upm); + + /* + * We can only check if it is not NULL + * We do not know the value it contains + */ + ATF_CHECK(NULL != extracted_pmseg); + + extracted_pmseg->dummy_variable = pmseg.dummy_variable; + + /* Invert value to ensure test integrity */ + pmseg.dummy_variable = false; + + ATF_REQUIRE_EQ(false, pmseg.dummy_variable); + + extracted_pmseg = uvm_physseg_get_pmseg(upm); + + ATF_CHECK(NULL != extracted_pmseg); + + ATF_CHECK_EQ(true, extracted_pmseg->dummy_variable); +} +#endif + +ATF_TC(vm_physseg_find); +ATF_TC_HEAD(vm_physseg_find, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests if the returned segment number \ + is correct when an PFN is passed into uvm_physseg_find() call. \ + In addition to this the offset of the PFN from the start of \ + segment is also set if the parameter is passed in as not NULL."); +} +ATF_TC_BODY(vm_physseg_find, tc) +{ + psize_t offset = (psize_t) -1; + + uvm_physseg_t upm_first, result; +#if VM_PHYSSEG_MAX > 1 + uvm_physseg_t upm_second; +#endif + + setup(); + + upm_first = uvm_page_physload(VALID_START_PFN_1, VALID_END_PFN_1, + VALID_AVAIL_START_PFN_1, VALID_AVAIL_END_PFN_1, VM_FREELIST_DEFAULT); + + ATF_REQUIRE_EQ(1, uvm_physseg_get_entries()); + + ATF_REQUIRE_EQ(0, uvmexp.npages); + + /* This test will be triggered only if there are 2 or more segments. */ +#if VM_PHYSSEG_MAX > 1 + upm_second = uvm_page_physload(VALID_START_PFN_2, VALID_END_PFN_2, + VALID_AVAIL_START_PFN_2, VALID_AVAIL_END_PFN_2, VM_FREELIST_DEFAULT); + + ATF_REQUIRE_EQ(2, uvm_physseg_get_entries()); + + ATF_REQUIRE_EQ(0, uvmexp.npages); +#endif + + /* Under ONE_MEGABYTE is segment upm_first */ + result = uvm_physseg_find(atop(ONE_MEGABYTE - 1024), NULL); + ATF_CHECK_EQ(upm_first, result); + ATF_CHECK_EQ(uvm_physseg_get_start(upm_first), + uvm_physseg_get_start(result)); + ATF_CHECK_EQ(uvm_physseg_get_end(upm_first), + uvm_physseg_get_end(result)); + ATF_CHECK_EQ(uvm_physseg_get_avail_start(upm_first), + uvm_physseg_get_avail_start(result)); + ATF_CHECK_EQ(uvm_physseg_get_avail_end(upm_first), + uvm_physseg_get_avail_end(result)); + + ATF_REQUIRE_EQ((psize_t) -1, offset); + + /* This test will be triggered only if there are 2 or more segments. */ +#if VM_PHYSSEG_MAX > 1 + /* Over ONE_MEGABYTE is segment upm_second */ + result = uvm_physseg_find(atop(ONE_MEGABYTE + 8192), &offset); + ATF_CHECK_EQ(upm_second, result); + ATF_CHECK_EQ(uvm_physseg_get_start(upm_second), + uvm_physseg_get_start(result)); + ATF_CHECK_EQ(uvm_physseg_get_end(upm_second), + uvm_physseg_get_end(result)); + ATF_CHECK_EQ(uvm_physseg_get_avail_start(upm_second), + uvm_physseg_get_avail_start(result)); + ATF_CHECK_EQ(uvm_physseg_get_avail_end(upm_second), + uvm_physseg_get_avail_end(result)); + + /* Offset is calculated based on PAGE_SIZE */ + /* atop(ONE_MEGABYTE + (2 * PAGE_SIZE)) - VALID_START_PFN1 = 2 */ + ATF_CHECK_EQ(2, offset); +#else + /* Under ONE_MEGABYTE is segment upm_first */ + result = uvm_physseg_find(atop(ONE_MEGABYTE - 12288), &offset); + ATF_CHECK_EQ(upm_first, result); + ATF_CHECK_EQ(uvm_physseg_get_start(upm_first), + uvm_physseg_get_start(result)); + ATF_CHECK_EQ(uvm_physseg_get_end(upm_first), + uvm_physseg_get_end(result)); + ATF_CHECK_EQ(uvm_physseg_get_avail_start(upm_first), + uvm_physseg_get_avail_start(result)); + ATF_CHECK_EQ(uvm_physseg_get_avail_end(upm_first), + uvm_physseg_get_avail_end(result)); + + /* Offset is calculated based on PAGE_SIZE */ + /* atop(ONE_MEGABYTE - (3 * PAGE_SIZE)) - VALID_START_PFN1 = 253 */ + ATF_CHECK_EQ(253, offset); +#endif +} + +ATF_TC(vm_physseg_find_invalid); +ATF_TC_HEAD(vm_physseg_find_invalid, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests if the returned segment number \ + is (paddr_t) -1 when a non existant PFN is passed into \ + uvm_physseg_find() call."); +} +ATF_TC_BODY(vm_physseg_find_invalid, tc) +{ + psize_t offset = (psize_t) -1; + + setup(); + uvm_page_physload(VALID_START_PFN_1, VALID_END_PFN_1, + VALID_AVAIL_START_PFN_1, VALID_AVAIL_END_PFN_1, VM_FREELIST_DEFAULT); + + ATF_REQUIRE_EQ(1, uvm_physseg_get_entries()); + + ATF_REQUIRE_EQ(0, uvmexp.npages); + + /* No segments over 3 MB exists at the moment */ + ATF_CHECK_EQ(UVM_PHYSSEG_TYPE_INVALID, + uvm_physseg_find(atop(ONE_MEGABYTE * 3), NULL)); + + ATF_REQUIRE_EQ((psize_t) -1, offset); + + /* No segments over 3 MB exists at the moment */ + ATF_CHECK_EQ(UVM_PHYSSEG_TYPE_INVALID, + uvm_physseg_find(atop(ONE_MEGABYTE * 3), &offset)); + + ATF_CHECK_EQ((psize_t) -1, offset); +} + +ATF_TC(uvm_page_physunload_start); +ATF_TC_HEAD(uvm_page_physunload_start, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests if the basic uvm_page_physunload()\ + call works without a panic(). Unloads from Start of the segment."); +} +ATF_TC_BODY(uvm_page_physunload_start, tc) +{ + /* + * Would uvmexp.npages reduce everytime an uvm_page_physunload is called? + */ + psize_t npages = (VALID_END_PFN_2 - VALID_START_PFN_2); + + struct vm_page *pgs = malloc(sizeof(struct vm_page) * npages); + + paddr_t p = 0; + + uvm_physseg_t upm; + + setup(); + upm = uvm_page_physload(VALID_START_PFN_2, VALID_END_PFN_2, + VALID_AVAIL_START_PFN_2, VALID_AVAIL_END_PFN_2, VM_FREELIST_DEFAULT); + + ATF_REQUIRE_EQ(1, uvm_physseg_get_entries()); + + ATF_REQUIRE_EQ(0, uvmexp.npages); + + uvm_physseg_init_seg(upm, pgs); + + ATF_CHECK_EQ(true, uvm_page_physunload(upm, VM_FREELIST_DEFAULT, &p)); + + /* + * When called for first time, uvm_page_physload() removes the first PFN + * + * New avail start will be VALID_AVAIL_START_PFN_2 + 1 + */ + ATF_CHECK_EQ(VALID_START_PFN_2, atop(p)); + + ATF_CHECK_EQ(VALID_AVAIL_START_PFN_2 + 1, + uvm_physseg_get_avail_start(upm)); + + ATF_CHECK_EQ(VALID_START_PFN_2 + 1, uvm_physseg_get_start(upm)); + + /* Rest of the stuff should remain the same */ + ATF_CHECK_EQ(VALID_END_PFN_2, uvm_physseg_get_end(upm)); + ATF_CHECK_EQ(VALID_AVAIL_END_PFN_2, uvm_physseg_get_avail_end(upm)); +} + +ATF_TC(uvm_page_physunload_end); +ATF_TC_HEAD(uvm_page_physunload_end, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests if the basic uvm_page_physunload()\ + call works without a panic(). Unloads from End of the segment."); +} +ATF_TC_BODY(uvm_page_physunload_end, tc) +{ + /* + * Would uvmexp.npages reduce everytime an uvm_page_physunload is called? + */ + paddr_t p = 0; + + uvm_physseg_t upm; + + setup(); + /* Note: start != avail_start to remove from end. */ + upm = uvm_page_physload(VALID_START_PFN_2, VALID_END_PFN_2, + VALID_AVAIL_START_PFN_2 + 1, VALID_AVAIL_END_PFN_2, + VM_FREELIST_DEFAULT); + + p = 0; + + ATF_REQUIRE_EQ(1, uvm_physseg_get_entries()); + + ATF_REQUIRE_EQ(0, uvmexp.npages); + + ATF_REQUIRE( + uvm_physseg_get_avail_start(upm) != uvm_physseg_get_start(upm)); + + ATF_CHECK_EQ(true, uvm_page_physunload(upm, VM_FREELIST_DEFAULT, &p)); + + /* + * Remember if X is the upper limit the actual valid pointer is X - 1 + * + * For example if 256 is the upper limit for 1MB memory, last valid + * pointer is 256 - 1 = 255 + */ + + ATF_CHECK_EQ(VALID_END_PFN_2 - 1, atop(p)); + + /* + * When called for second time, uvm_page_physload() removes the last PFN + * + * New avail end will be VALID_AVAIL_END_PFN_2 - 1 + * New end will be VALID_AVAIL_PFN_2 - 1 + */ + + ATF_CHECK_EQ(VALID_AVAIL_END_PFN_2 - 1, uvm_physseg_get_avail_end(upm)); + + ATF_CHECK_EQ(VALID_END_PFN_2 - 1, uvm_physseg_get_end(upm)); + + /* Rest of the stuff should remain the same */ + ATF_CHECK_EQ(VALID_AVAIL_START_PFN_2 + 1, + uvm_physseg_get_avail_start(upm)); + ATF_CHECK_EQ(VALID_START_PFN_2, uvm_physseg_get_start(upm)); +} + +ATF_TC(uvm_page_physunload_none); +ATF_TC_HEAD(uvm_page_physunload_none, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests if the basic uvm_page_physunload()\ + call works without a panic(). Does not unload from start or end \ + because of non-aligned start / avail_start and end / avail_end \ + respectively."); +} +ATF_TC_BODY(uvm_page_physunload_none, tc) +{ + psize_t npages = (VALID_END_PFN_2 - VALID_START_PFN_2); + + struct vm_page *pgs = malloc(sizeof(struct vm_page) * npages); + + paddr_t p = 0; + + uvm_physseg_t upm; + + setup(); + /* + * Note: start != avail_start and end != avail_end. + * + * This prevents any unload from occuring. + */ + upm = uvm_page_physload(VALID_START_PFN_2, VALID_END_PFN_2, + VALID_AVAIL_START_PFN_2 + 1, VALID_AVAIL_END_PFN_2 - 1, + VM_FREELIST_DEFAULT); + + p = 0; + + ATF_REQUIRE_EQ(1, uvm_physseg_get_entries()); + + ATF_REQUIRE_EQ(0, uvmexp.npages); + + ATF_REQUIRE( + uvm_physseg_get_avail_start(upm) != uvm_physseg_get_start(upm)); + + uvm_physseg_init_seg(upm, pgs); + + ATF_CHECK_EQ(false, uvm_page_physunload(upm, VM_FREELIST_DEFAULT, &p)); + + /* uvm_page_physload() will no longer unload memory */ + ATF_CHECK_EQ(0, p); + + /* Rest of the stuff should remain the same */ + ATF_CHECK_EQ(VALID_AVAIL_START_PFN_2 + 1, + uvm_physseg_get_avail_start(upm)); + ATF_CHECK_EQ(VALID_AVAIL_END_PFN_2 - 1, + uvm_physseg_get_avail_end(upm)); + ATF_CHECK_EQ(VALID_START_PFN_2, uvm_physseg_get_start(upm)); + ATF_CHECK_EQ(VALID_END_PFN_2, uvm_physseg_get_end(upm)); +} + +ATF_TC(uvm_page_physunload_delete_start); +ATF_TC_HEAD(uvm_page_physunload_delete_start, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests if the uvm_page_physunload() \ + works when the segment gets small enough to be deleted scenario. \ + NOTE: This one works deletes from start."); +} +ATF_TC_BODY(uvm_page_physunload_delete_start, tc) +{ + /* + * Would uvmexp.npages reduce everytime an uvm_page_physunload is called? + */ + paddr_t p = 0; + + uvm_physseg_t upm; + + setup(); + + /* + * Setup the Nuke from Starting point + */ + + upm = uvm_page_physload(VALID_END_PFN_1 - 1, VALID_END_PFN_1, + VALID_AVAIL_END_PFN_1 - 1, VALID_AVAIL_END_PFN_1, + VM_FREELIST_DEFAULT); + + ATF_REQUIRE_EQ(1, uvm_physseg_get_entries()); + + ATF_REQUIRE_EQ(0, uvmexp.npages); + + /* Insert more than one segment iff VM_PHYSSEG_MAX > 1 */ +#if VM_PHYSSEG_MAX > 1 + uvm_page_physload(VALID_START_PFN_2, VALID_END_PFN_2, + VALID_AVAIL_START_PFN_2, VALID_AVAIL_END_PFN_2, VM_FREELIST_DEFAULT); + + ATF_REQUIRE_EQ(2, uvm_physseg_get_entries()); +#endif + +#if VM_PHYSSEG_MAX == 1 + atf_tc_expect_signal(SIGABRT, + "cannot uvm_page_physunload() the last segment"); +#endif + + ATF_CHECK_EQ(true, uvm_page_physunload(upm, VM_FREELIST_DEFAULT, &p)); + + ATF_CHECK_EQ(VALID_END_PFN_1 - 1, atop(p)); + + ATF_CHECK_EQ(1, uvm_physseg_get_entries()); + + /* The only node now is the one we inserted second. */ + upm = uvm_physseg_get_first(); + + ATF_CHECK_EQ(VALID_START_PFN_2, uvm_physseg_get_start(upm)); + ATF_CHECK_EQ(VALID_END_PFN_2, uvm_physseg_get_end(upm)); + ATF_CHECK_EQ(VALID_AVAIL_START_PFN_2, uvm_physseg_get_avail_start(upm)); + ATF_CHECK_EQ(VALID_AVAIL_END_PFN_2, uvm_physseg_get_avail_end(upm)); +} + +ATF_TC(uvm_page_physunload_delete_end); +ATF_TC_HEAD(uvm_page_physunload_delete_end, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests if the uvm_page_physunload() \ + works when the segment gets small enough to be deleted scenario. \ + NOTE: This one works deletes from end."); +} +ATF_TC_BODY(uvm_page_physunload_delete_end, tc) +{ + /* + * Would uvmexp.npages reduce everytime an uvm_page_physunload is called? + */ + + paddr_t p = 0; + + uvm_physseg_t upm; + + setup(); + + /* + * Setup the Nuke from Ending point + */ + + upm = uvm_page_physload(VALID_START_PFN_1, VALID_START_PFN_1 + 2, + VALID_AVAIL_START_PFN_1 + 1, VALID_AVAIL_START_PFN_1 + 2, + VM_FREELIST_DEFAULT); + + ATF_REQUIRE_EQ(1, uvm_physseg_get_entries()); + + ATF_REQUIRE_EQ(0, uvmexp.npages); + + /* Insert more than one segment iff VM_PHYSSEG_MAX > 1 */ +#if VM_PHYSSEG_MAX > 1 + uvm_page_physload(VALID_START_PFN_2, VALID_END_PFN_2, + VALID_AVAIL_START_PFN_2, VALID_AVAIL_END_PFN_2, VM_FREELIST_DEFAULT); + + ATF_REQUIRE_EQ(2, uvm_physseg_get_entries()); +#endif + +#if VM_PHYSSEG_MAX == 1 + atf_tc_expect_signal(SIGABRT, + "cannot uvm_page_physunload() the last segment"); +#endif + + ATF_CHECK_EQ(true, uvm_page_physunload(upm, VM_FREELIST_DEFAULT, &p)); + + p = 0; + + ATF_CHECK_EQ(true, uvm_page_physunload(upm, VM_FREELIST_DEFAULT, &p)); + + ATF_CHECK_EQ(VALID_START_PFN_1 + 2, atop(p)); + + ATF_CHECK_EQ(1, uvm_physseg_get_entries()); + + /* The only node now is the one we inserted second. */ + upm = uvm_physseg_get_first(); + + ATF_CHECK_EQ(VALID_START_PFN_2, uvm_physseg_get_start(upm)); + ATF_CHECK_EQ(VALID_END_PFN_2, uvm_physseg_get_end(upm)); + ATF_CHECK_EQ(VALID_AVAIL_START_PFN_2, uvm_physseg_get_avail_start(upm)); + ATF_CHECK_EQ(VALID_AVAIL_END_PFN_2, uvm_physseg_get_avail_end(upm)); +} + +ATF_TC(uvm_page_physunload_invalid); +ATF_TC_HEAD(uvm_page_physunload_invalid, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests if the uvm_page_physunload() \ + fails when then Free list does not match."); +} +ATF_TC_BODY(uvm_page_physunload_invalid, tc) +{ + psize_t npages = (VALID_END_PFN_2 - VALID_START_PFN_2); + + struct vm_page *pgs = malloc(sizeof(struct vm_page) * npages); + + paddr_t p = 0; + + uvm_physseg_t upm; + + setup(); + upm = uvm_page_physload(VALID_START_PFN_2, VALID_END_PFN_2, + VALID_AVAIL_START_PFN_2, VALID_AVAIL_END_PFN_2, VM_FREELIST_DEFAULT); + + ATF_REQUIRE_EQ(1, uvm_physseg_get_entries()); + + ATF_REQUIRE_EQ(0, uvmexp.npages); + + uvm_physseg_init_seg(upm, pgs); + + ATF_CHECK_EQ(false, uvm_page_physunload(upm, VM_FREELIST_FIRST4G, &p)); +} + +ATF_TC(uvm_page_physunload_force); +ATF_TC_HEAD(uvm_page_physunload_force, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests if the basic \ + uvm_page_physunload_force() including delete works without."); +} +ATF_TC_BODY(uvm_page_physunload_force, tc) +{ + /* + * Would uvmexp.npages reduce everytime an uvm_page_physunload is called? + */ + paddr_t p = 0; + + uvm_physseg_t upm; + + setup(); + upm = uvm_page_physload(VALID_START_PFN_1, VALID_END_PFN_1, + VALID_AVAIL_START_PFN_1, VALID_AVAIL_END_PFN_1, VM_FREELIST_DEFAULT); + + ATF_REQUIRE_EQ(1, uvm_physseg_get_entries()); + + ATF_REQUIRE_EQ(0, uvmexp.npages); + + /* Insert more than one segment iff VM_PHYSSEG_MAX > 1 */ +#if VM_PHYSSEG_MAX > 1 + /* + * We have couple of physloads done this is bacause of the fact that if + * we physunload all the PFs from a given range and we have only one + * segment in total a panic() is called + */ + uvm_page_physload(VALID_START_PFN_2, VALID_END_PFN_2, + VALID_AVAIL_START_PFN_2, VALID_AVAIL_END_PFN_2, VM_FREELIST_DEFAULT); + + ATF_REQUIRE_EQ(2, uvm_physseg_get_entries()); +#endif + +#if VM_PHYSSEG_MAX == 1 + atf_tc_expect_signal(SIGABRT, + "cannot uvm_page_physunload() the last segment"); +#endif + + ATF_REQUIRE_EQ(VALID_AVAIL_START_PFN_1, + uvm_physseg_get_avail_start(upm)); + + for(paddr_t i = VALID_AVAIL_START_PFN_1; + i < VALID_AVAIL_END_PFN_1; i++) { + ATF_CHECK_EQ(true, + uvm_page_physunload_force(upm, VM_FREELIST_DEFAULT, &p)); + ATF_CHECK_EQ(i, atop(p)); + + if(i + 1 < VALID_AVAIL_END_PFN_1) + ATF_CHECK_EQ(i + 1, uvm_physseg_get_avail_start(upm)); + } + + /* + * Now we try to retrieve the segment, which has been removed + * from the system through force unloading all the pages inside it. + */ + upm = uvm_physseg_find(VALID_AVAIL_END_PFN_1 - 1, NULL); + + /* It should no longer exist */ + ATF_CHECK_EQ(NULL, upm); + + ATF_CHECK_EQ(1, uvm_physseg_get_entries()); +} + +ATF_TC(uvm_page_physunload_force_invalid); +ATF_TC_HEAD(uvm_page_physunload_force_invalid, tc) +{ + atf_tc_set_md_var(tc, "descr", "Tests if the invalid conditions for \ + uvm_page_physunload_force_invalid()."); +} +ATF_TC_BODY(uvm_page_physunload_force_invalid, tc) +{ + paddr_t p = 0; + + uvm_physseg_t upm; + + setup(); + upm = uvm_page_physload(VALID_START_PFN_2, VALID_START_PFN_2+ 1, + VALID_START_PFN_2, VALID_START_PFN_2, VM_FREELIST_DEFAULT); + + ATF_REQUIRE_EQ(1, uvm_physseg_get_entries()); + + ATF_REQUIRE_EQ(0, uvmexp.npages); + + ATF_CHECK_EQ(false, + uvm_page_physunload_force(upm, VM_FREELIST_DEFAULT, &p)); + + ATF_CHECK_EQ(0, p); +} + +ATF_TP_ADD_TCS(tp) +{ +#if defined(UVM_HOTPLUG) + /* Internal */ + ATF_TP_ADD_TC(tp, uvm_physseg_alloc_atboot_mismatch); + ATF_TP_ADD_TC(tp, uvm_physseg_alloc_atboot_overrun); + ATF_TP_ADD_TC(tp, uvm_physseg_alloc_sanity); + ATF_TP_ADD_TC(tp, uvm_physseg_free_atboot_mismatch); + ATF_TP_ADD_TC(tp, uvm_physseg_free_sanity); +#if VM_PHYSSEG_MAX > 1 + ATF_TP_ADD_TC(tp, uvm_physseg_atboot_free_leak); +#endif +#endif /* UVM_HOTPLUG */ + + ATF_TP_ADD_TC(tp, uvm_physseg_plug); + ATF_TP_ADD_TC(tp, uvm_physseg_unplug); + + /* Exported */ + ATF_TP_ADD_TC(tp, uvm_physseg_init); + ATF_TP_ADD_TC(tp, uvm_page_physload_preload); + ATF_TP_ADD_TC(tp, uvm_page_physload_postboot); + ATF_TP_ADD_TC(tp, uvm_physseg_handle_immutable); + ATF_TP_ADD_TC(tp, uvm_physseg_seg_chomp_slab); + ATF_TP_ADD_TC(tp, uvm_physseg_alloc_from_slab); + ATF_TP_ADD_TC(tp, uvm_physseg_init_seg); + ATF_TP_ADD_TC(tp, uvm_physseg_get_start); + ATF_TP_ADD_TC(tp, uvm_physseg_get_start_invalid); + ATF_TP_ADD_TC(tp, uvm_physseg_get_end); + ATF_TP_ADD_TC(tp, uvm_physseg_get_end_invalid); + ATF_TP_ADD_TC(tp, uvm_physseg_get_avail_start); + ATF_TP_ADD_TC(tp, uvm_physseg_get_avail_start_invalid); + ATF_TP_ADD_TC(tp, uvm_physseg_get_avail_end); + ATF_TP_ADD_TC(tp, uvm_physseg_get_avail_end_invalid); + ATF_TP_ADD_TC(tp, uvm_physseg_get_next); + ATF_TP_ADD_TC(tp, uvm_physseg_get_next_invalid); + ATF_TP_ADD_TC(tp, uvm_physseg_get_prev); + ATF_TP_ADD_TC(tp, uvm_physseg_get_prev_invalid); + ATF_TP_ADD_TC(tp, uvm_physseg_get_first); + ATF_TP_ADD_TC(tp, uvm_physseg_get_last); + ATF_TP_ADD_TC(tp, uvm_physseg_valid); + ATF_TP_ADD_TC(tp, uvm_physseg_valid_invalid); + ATF_TP_ADD_TC(tp, uvm_physseg_get_highest); + ATF_TP_ADD_TC(tp, uvm_physseg_get_free_list); + ATF_TP_ADD_TC(tp, uvm_physseg_get_start_hint); + ATF_TP_ADD_TC(tp, uvm_physseg_set_start_hint); + ATF_TP_ADD_TC(tp, uvm_physseg_set_start_hint_invalid); + ATF_TP_ADD_TC(tp, uvm_physseg_get_pg); + +#ifdef __HAVE_PMAP_PHYSSEG + ATF_TP_ADD_TC(tp, uvm_physseg_get_pmseg); +#endif + ATF_TP_ADD_TC(tp, vm_physseg_find); + ATF_TP_ADD_TC(tp, vm_physseg_find_invalid); + + ATF_TP_ADD_TC(tp, uvm_page_physunload_start); + ATF_TP_ADD_TC(tp, uvm_page_physunload_end); + ATF_TP_ADD_TC(tp, uvm_page_physunload_none); + ATF_TP_ADD_TC(tp, uvm_page_physunload_delete_start); + ATF_TP_ADD_TC(tp, uvm_page_physunload_delete_end); + ATF_TP_ADD_TC(tp, uvm_page_physunload_invalid); + ATF_TP_ADD_TC(tp, uvm_page_physunload_force); + ATF_TP_ADD_TC(tp, uvm_page_physunload_force_invalid); + + return atf_no_error(); +} diff --git a/contrib/netbsd-tests/sys/uvm/t_uvm_physseg_load.c b/contrib/netbsd-tests/sys/uvm/t_uvm_physseg_load.c new file mode 100644 index 000000000000..a150f6976c7b --- /dev/null +++ b/contrib/netbsd-tests/sys/uvm/t_uvm_physseg_load.c @@ -0,0 +1,740 @@ +/* $NetBSD: t_uvm_physseg_load.c,v 1.2 2016/12/22 08:15:20 cherry Exp $ */ + +/*- + * Copyright (c) 2015, 2016 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Santhosh N. Raju and + * by Cherry G. Mathew + * + * 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. + */ + +#include +__RCSID("$NetBSD: t_uvm_physseg_load.c,v 1.2 2016/12/22 08:15:20 cherry Exp $"); + +/* + * If this line is commented out tests related touvm_physseg_get_pmseg() + * wont run. + * + * Have a look at machine/uvm_physseg.h for more details. + */ +#define __HAVE_PMAP_PHYSSEG + +/* + * This is a dummy struct used for testing purposes + * + * In reality this struct would exist in the MD part of the code residing in + * machines/vmparam.h + */ + +#ifdef __HAVE_PMAP_PHYSSEG +struct pmap_physseg { + int dummy_variable; /* Dummy variable use for testing */ +}; +#endif + +/* Testing API - assumes userland */ +/* Provide Kernel API equivalents */ +#include +#include +#include /* memset(3) et. al */ +#include /* printf(3) */ +#include /* malloc(3) */ +#include +#include +#include + +#define PRIxPADDR "lx" +#define PRIxPSIZE "lx" +#define PRIuPSIZE "lu" +#define PRIxVADDR "lx" +#define PRIxVSIZE "lx" +#define PRIuVSIZE "lu" + +#define UVM_HOTPLUG /* Enable hotplug with rbtree. */ +#define PMAP_STEAL_MEMORY +#define DEBUG /* Enable debug functionality. */ + +typedef unsigned long vaddr_t; +typedef unsigned long paddr_t; +typedef unsigned long psize_t; +typedef unsigned long vsize_t; + +#include +#include + +#ifndef DIAGNOSTIC +#define KASSERTMSG(e, msg, ...) /* NOTHING */ +#define KASSERT(e) /* NOTHING */ +#else +#define KASSERT(a) assert(a) +#define KASSERTMSG(exp, ...) printf(__VA_ARGS__); assert((exp)) +#endif + +#define VM_PHYSSEG_STRAT VM_PSTRAT_BSEARCH + +#define VM_NFREELIST 4 +#define VM_FREELIST_DEFAULT 0 +#define VM_FREELIST_FIRST16 3 +#define VM_FREELIST_FIRST1G 2 +#define VM_FREELIST_FIRST4G 1 + +/* + * Used in tests when Array implementation is tested + */ +#if !defined(VM_PHYSSEG_MAX) +#define VM_PHYSSEG_MAX 32 +#endif + +#define PAGE_SIZE 4096 +#define PAGE_SHIFT 12 +#define atop(x) (((paddr_t)(x)) >> PAGE_SHIFT) + +#define mutex_enter(l) +#define mutex_exit(l) + +#define _SYS_KMEM_H_ /* Disallow the real kmem API (see below) */ +/* free(p) XXX: pgs management need more thought */ +#define kmem_alloc(size, flags) malloc(size) +#define kmem_zalloc(size, flags) malloc(size) +#define kmem_free(p, size) free(p) + +psize_t physmem; + +struct uvmexp uvmexp; /* decl */ + +/* + * uvm structure borrowed from uvm.h + * + * Remember this is a dummy structure used within the ATF Tests and + * uses only necessary fields from the original uvm struct. + * See uvm/uvm.h for the full struct. + */ + +struct uvm { + /* vm_page related parameters */ + + bool page_init_done; /* TRUE if uvm_page_init() finished */ +} uvm; + +static void +panic(const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + vprintf(fmt, ap); + printf("\n"); + va_end(ap); + KASSERT(false); + + /*NOTREACHED*/ +} + +static void +uvm_pagefree(struct vm_page *pg) +{ + return; +} + +#if defined(UVM_HOTPLUG) +static void +uvmpdpol_reinit(void) +{ + return; +} +#endif /* UVM_HOTPLUG */ + +/* end - Provide Kernel API equivalents */ + +#include "uvm/uvm_physseg.c" + +#include + +#define ONE_MEGABYTE 1024 * 1024 + +/* Sample Page Frame Numbers */ +#define VALID_START_PFN_1 atop(0) +#define VALID_END_PFN_1 atop(ONE_MEGABYTE) +#define VALID_AVAIL_START_PFN_1 atop(0) +#define VALID_AVAIL_END_PFN_1 atop(ONE_MEGABYTE) + +#define VALID_START_PFN_2 atop(ONE_MEGABYTE + 1) +#define VALID_END_PFN_2 atop(ONE_MEGABYTE * 2) +#define VALID_AVAIL_START_PFN_2 atop(ONE_MEGABYTE + 1) +#define VALID_AVAIL_END_PFN_2 atop(ONE_MEGABYTE * 2) + +#define VALID_START_PFN_3 atop((ONE_MEGABYTE * 2) + 1) +#define VALID_END_PFN_3 atop(ONE_MEGABYTE * 3) +#define VALID_AVAIL_START_PFN_3 atop((ONE_MEGABYTE * 2) + 1) +#define VALID_AVAIL_END_PFN_3 atop(ONE_MEGABYTE * 3) + +#define VALID_START_PFN_4 atop(ONE_MEGABYTE + 1) +#define VALID_END_PFN_4 atop(ONE_MEGABYTE * 128) +#define VALID_AVAIL_START_PFN_4 atop(ONE_MEGABYTE + 1) +#define VALID_AVAIL_END_PFN_4 atop(ONE_MEGABYTE * 128) + +#define VALID_START_PFN_5 atop(ONE_MEGABYTE + 1) +#define VALID_END_PFN_5 atop(ONE_MEGABYTE * 256) +#define VALID_AVAIL_START_PFN_5 atop(ONE_MEGABYTE + 1) +#define VALID_AVAIL_END_PFN_5 atop(ONE_MEGABYTE * 256) + +/* + * Total number of pages (of 4K size each) should be 256 for 1MB of memory. + */ +#define PAGE_COUNT_1M 256 + +/* + * The number of Page Frames to allot per segment + */ +#define PF_STEP 8 + +/* + * A debug fucntion to print the content of upm. + */ + static inline void + uvm_physseg_dump_seg(uvm_physseg_t upm) + { +#if defined(DEBUG) + printf("%s: seg->start == %ld\n", __func__, + uvm_physseg_get_start(upm)); + printf("%s: seg->end == %ld\n", __func__, + uvm_physseg_get_end(upm)); + printf("%s: seg->avail_start == %ld\n", __func__, + uvm_physseg_get_avail_start(upm)); + printf("%s: seg->avail_end == %ld\n", __func__, + uvm_physseg_get_avail_end(upm)); + + printf("====\n\n"); +#else + return; +#endif /* DEBUG */ + } + +/* + * Private accessor that gets the value of vm_physmem.nentries + */ +static int +uvm_physseg_get_entries(void) +{ +#if defined(UVM_HOTPLUG) + return uvm_physseg_graph.nentries; +#else + return vm_nphysmem; +#endif /* UVM_HOTPLUG */ +} + +/* + * Note: This function replicates verbatim what happens in + * uvm_page.c:uvm_page_init(). + * + * Please track any changes that happen there. + */ +static void +uvm_page_init_fake(struct vm_page *pagearray, psize_t pagecount) +{ + uvm_physseg_t bank; + size_t n; + + for (bank = uvm_physseg_get_first(), + uvm_physseg_seg_chomp_slab(bank, pagearray, pagecount); + uvm_physseg_valid_p(bank); + bank = uvm_physseg_get_next(bank)) { + + n = uvm_physseg_get_end(bank) - uvm_physseg_get_start(bank); + uvm_physseg_seg_alloc_from_slab(bank, n); + uvm_physseg_init_seg(bank, pagearray); + + /* set up page array pointers */ + pagearray += n; + pagecount -= n; + } + + uvm.page_init_done = true; +} + +/* + * PHYS_TO_VM_PAGE: find vm_page for a PA. used by MI code to get vm_pages + * back from an I/O mapping (ugh!). used in some MD code as well. + */ +static struct vm_page * +uvm_phys_to_vm_page(paddr_t pa) +{ + paddr_t pf = atop(pa); + paddr_t off; + uvm_physseg_t psi; + + psi = uvm_physseg_find(pf, &off); + if (psi != UVM_PHYSSEG_TYPE_INVALID) + return uvm_physseg_get_pg(psi, off); + return(NULL); +} + +//static paddr_t +//uvm_vm_page_to_phys(const struct vm_page *pg) +//{ +// +// return pg->phys_addr; +//} + +/* + * XXX: To do, write control test cases for uvm_vm_page_to_phys(). + */ + +/* #define VM_PAGE_TO_PHYS(entry) uvm_vm_page_to_phys(entry) */ + +#define PHYS_TO_VM_PAGE(pa) uvm_phys_to_vm_page(pa) + +/* + * Test Fixture SetUp(). + */ +static void +setup(void) +{ + /* Prerequisites for running certain calls in uvm_physseg */ + uvmexp.pagesize = PAGE_SIZE; + uvmexp.npages = 0; + uvm.page_init_done = false; + uvm_physseg_init(); +} + +ATF_TC(uvm_physseg_100); +ATF_TC_HEAD(uvm_physseg_100, tc) +{ + atf_tc_set_md_var(tc, "descr", "Load test uvm_phys_to_vm_page() with \ + 100 calls, VM_PHYSSEG_MAX is 32."); +} +ATF_TC_BODY(uvm_physseg_100, tc) +{ + paddr_t pa; + + setup(); + + for(paddr_t i = VALID_START_PFN_1; + i < VALID_END_PFN_1; i += PF_STEP) { + uvm_page_physload(i, i + PF_STEP, i, i + PF_STEP, + VM_FREELIST_DEFAULT); + } + + ATF_REQUIRE_EQ(VM_PHYSSEG_MAX, uvm_physseg_get_entries()); + + srandom((unsigned)time(NULL)); + for(int i = 0; i < 100; i++) { + pa = (paddr_t) random() % (paddr_t) ctob(VALID_END_PFN_1); + PHYS_TO_VM_PAGE(pa); + } + + ATF_CHECK_EQ(true, true); +} + +ATF_TC(uvm_physseg_1K); +ATF_TC_HEAD(uvm_physseg_1K, tc) +{ + atf_tc_set_md_var(tc, "descr", "Load test uvm_phys_to_vm_page() with \ + 1000 calls, VM_PHYSSEG_MAX is 32."); +} +ATF_TC_BODY(uvm_physseg_1K, tc) +{ + paddr_t pa; + + setup(); + + for(paddr_t i = VALID_START_PFN_1; + i < VALID_END_PFN_1; i += PF_STEP) { + uvm_page_physload(i, i + PF_STEP, i, i + PF_STEP, + VM_FREELIST_DEFAULT); + } + + ATF_REQUIRE_EQ(VM_PHYSSEG_MAX, uvm_physseg_get_entries()); + + srandom((unsigned)time(NULL)); + for(int i = 0; i < 1000; i++) { + pa = (paddr_t) random() % (paddr_t) ctob(VALID_END_PFN_1); + PHYS_TO_VM_PAGE(pa); + } + + ATF_CHECK_EQ(true, true); +} + +ATF_TC(uvm_physseg_10K); +ATF_TC_HEAD(uvm_physseg_10K, tc) +{ + atf_tc_set_md_var(tc, "descr", "Load test uvm_phys_to_vm_page() with \ + 10,000 calls, VM_PHYSSEG_MAX is 32."); +} +ATF_TC_BODY(uvm_physseg_10K, tc) +{ + paddr_t pa; + + setup(); + + for(paddr_t i = VALID_START_PFN_1; + i < VALID_END_PFN_1; i += PF_STEP) { + uvm_page_physload(i, i + PF_STEP, i, i + PF_STEP, + VM_FREELIST_DEFAULT); + } + + ATF_REQUIRE_EQ(VM_PHYSSEG_MAX, uvm_physseg_get_entries()); + + srandom((unsigned)time(NULL)); + for(int i = 0; i < 10000; i++) { + pa = (paddr_t) random() % (paddr_t) ctob(VALID_END_PFN_1); + PHYS_TO_VM_PAGE(pa); + } + + ATF_CHECK_EQ(true, true); +} + +ATF_TC(uvm_physseg_100K); +ATF_TC_HEAD(uvm_physseg_100K, tc) +{ + atf_tc_set_md_var(tc, "descr", "Load test uvm_phys_to_vm_page() with \ + 100,000 calls, VM_PHYSSEG_MAX is 32."); +} +ATF_TC_BODY(uvm_physseg_100K, tc) +{ + paddr_t pa; + + setup(); + + for(paddr_t i = VALID_START_PFN_1; + i < VALID_END_PFN_1; i += PF_STEP) { + uvm_page_physload(i, i + PF_STEP, i, i + PF_STEP, + VM_FREELIST_DEFAULT); + } + + ATF_REQUIRE_EQ(VM_PHYSSEG_MAX, uvm_physseg_get_entries()); + + srandom((unsigned)time(NULL)); + for(int i = 0; i < 100000; i++) { + pa = (paddr_t) random() % (paddr_t) ctob(VALID_END_PFN_1); + PHYS_TO_VM_PAGE(pa); + } + + ATF_CHECK_EQ(true, true); +} + +ATF_TC(uvm_physseg_1M); +ATF_TC_HEAD(uvm_physseg_1M, tc) +{ + atf_tc_set_md_var(tc, "descr", "Load test uvm_phys_to_vm_page() with \ + 1,000,000 calls, VM_PHYSSEG_MAX is 32."); +} +ATF_TC_BODY(uvm_physseg_1M, tc) +{ + paddr_t pa; + + setup(); + + for(paddr_t i = VALID_START_PFN_1; + i < VALID_END_PFN_1; i += PF_STEP) { + uvm_page_physload(i, i + PF_STEP, i, i + PF_STEP, + VM_FREELIST_DEFAULT); + } + + ATF_REQUIRE_EQ(VM_PHYSSEG_MAX, uvm_physseg_get_entries()); + + srandom((unsigned)time(NULL)); + for(int i = 0; i < 1000000; i++) { + pa = (paddr_t) random() % (paddr_t) ctob(VALID_END_PFN_1); + PHYS_TO_VM_PAGE(pa); + } + + ATF_CHECK_EQ(true, true); +} + +ATF_TC(uvm_physseg_10M); +ATF_TC_HEAD(uvm_physseg_10M, tc) +{ + atf_tc_set_md_var(tc, "descr", "Load test uvm_phys_to_vm_page() with \ + 10,000,000 calls, VM_PHYSSEG_MAX is 32."); +} +ATF_TC_BODY(uvm_physseg_10M, tc) +{ + paddr_t pa; + + setup(); + + for(paddr_t i = VALID_START_PFN_1; + i < VALID_END_PFN_1; i += PF_STEP) { + uvm_page_physload(i, i + PF_STEP, i, i + PF_STEP, + VM_FREELIST_DEFAULT); + } + + ATF_REQUIRE_EQ(VM_PHYSSEG_MAX, uvm_physseg_get_entries()); + + srandom((unsigned)time(NULL)); + for(int i = 0; i < 10000000; i++) { + pa = (paddr_t) random() % (paddr_t) ctob(VALID_END_PFN_1); + PHYS_TO_VM_PAGE(pa); + } + + ATF_CHECK_EQ(true, true); +} + +ATF_TC(uvm_physseg_100M); +ATF_TC_HEAD(uvm_physseg_100M, tc) +{ + atf_tc_set_md_var(tc, "descr", "Load test uvm_phys_to_vm_page() with \ + 100,000,000 calls, VM_PHYSSEG_MAX is 32."); +} +ATF_TC_BODY(uvm_physseg_100M, tc) +{ + paddr_t pa; + + setup(); + + for(paddr_t i = VALID_START_PFN_1; + i < VALID_END_PFN_1; i += PF_STEP) { + uvm_page_physload(i, i + PF_STEP, i, i + PF_STEP, + VM_FREELIST_DEFAULT); + } + + ATF_REQUIRE_EQ(VM_PHYSSEG_MAX, uvm_physseg_get_entries()); + + srandom((unsigned)time(NULL)); + for(int i = 0; i < 100000000; i++) { + pa = (paddr_t) random() % (paddr_t) ctob(VALID_END_PFN_1); + PHYS_TO_VM_PAGE(pa); + } + + ATF_CHECK_EQ(true, true); +} + +ATF_TC(uvm_physseg_1MB); +ATF_TC_HEAD(uvm_physseg_1MB, tc) +{ + atf_tc_set_md_var(tc, "descr", "Load test uvm_phys_to_vm_page() with \ + 10,000,000 calls, VM_PHYSSEG_MAX is 32 on 1 MB Segment."); +} +ATF_TC_BODY(uvm_physseg_1MB, t) +{ + paddr_t pa = 0; + + paddr_t pf = 0; + + psize_t pf_chunk_size = 0; + + psize_t npages1 = (VALID_END_PFN_1 - VALID_START_PFN_1); + + psize_t npages2 = (VALID_END_PFN_2 - VALID_START_PFN_2); + + struct vm_page *slab = malloc(sizeof(struct vm_page) * + (npages1 + npages2)); + + setup(); + + /* We start with zero segments */ + ATF_REQUIRE_EQ(true, uvm_physseg_plug(VALID_START_PFN_1, npages1, NULL)); + ATF_REQUIRE_EQ(1, uvm_physseg_get_entries()); + + /* Post boot: Fake all segments and pages accounted for. */ + uvm_page_init_fake(slab, npages1 + npages2); + + ATF_REQUIRE_EQ(true, uvm_physseg_plug(VALID_START_PFN_2, npages2, NULL)); + ATF_REQUIRE_EQ(2, uvm_physseg_get_entries()); + + srandom((unsigned)time(NULL)); + for(pf = VALID_START_PFN_2; pf < VALID_END_PFN_2; pf += PF_STEP) { + pf_chunk_size = (psize_t) random() % (psize_t) (PF_STEP - 1) + 1; + uvm_physseg_unplug(pf, pf_chunk_size); + } + + for(int i = 0; i < 10000000; i++) { + pa = (paddr_t) random() % (paddr_t) ctob(VALID_END_PFN_2); + if(pa < ctob(VALID_START_PFN_2)) + pa += ctob(VALID_START_PFN_2); + PHYS_TO_VM_PAGE(pa); + } + + ATF_CHECK_EQ(true, true); +} + +ATF_TC(uvm_physseg_64MB); +ATF_TC_HEAD(uvm_physseg_64MB, tc) +{ + atf_tc_set_md_var(tc, "descr", "Load test uvm_phys_to_vm_page() with \ + 10,000,000 calls, VM_PHYSSEG_MAX is 32 on 64 MB Segment."); +} +ATF_TC_BODY(uvm_physseg_64MB, t) +{ + paddr_t pa = 0; + + paddr_t pf = 0; + + psize_t pf_chunk_size = 0; + + psize_t npages1 = (VALID_END_PFN_1 - VALID_START_PFN_1); + + psize_t npages2 = (VALID_END_PFN_3 - VALID_START_PFN_3); + + struct vm_page *slab = malloc(sizeof(struct vm_page) * + (npages1 + npages2)); + + setup(); + + /* We start with zero segments */ + ATF_REQUIRE_EQ(true, uvm_physseg_plug(VALID_START_PFN_1, npages1, NULL)); + ATF_REQUIRE_EQ(1, uvm_physseg_get_entries()); + + /* Post boot: Fake all segments and pages accounted for. */ + uvm_page_init_fake(slab, npages1 + npages2); + + ATF_REQUIRE_EQ(true, uvm_physseg_plug(VALID_START_PFN_3, npages2, NULL)); + ATF_REQUIRE_EQ(2, uvm_physseg_get_entries()); + + srandom((unsigned)time(NULL)); + for(pf = VALID_START_PFN_3; pf < VALID_END_PFN_3; pf += PF_STEP) { + pf_chunk_size = (psize_t) random() % (psize_t) (PF_STEP - 1) + 1; + uvm_physseg_unplug(pf, pf_chunk_size); + } + + for(int i = 0; i < 10000000; i++) { + pa = (paddr_t) random() % (paddr_t) ctob(VALID_END_PFN_3); + if(pa < ctob(VALID_START_PFN_3)) + pa += ctob(VALID_START_PFN_3); + PHYS_TO_VM_PAGE(pa); + } + + ATF_CHECK_EQ(true, true); +} + +ATF_TC(uvm_physseg_128MB); +ATF_TC_HEAD(uvm_physseg_128MB, tc) +{ + atf_tc_set_md_var(tc, "descr", "Load test uvm_phys_to_vm_page() with \ + 10,000,000 calls, VM_PHYSSEG_MAX is 32 on 128 MB Segment."); +} +ATF_TC_BODY(uvm_physseg_128MB, t) +{ + paddr_t pa = 0; + + paddr_t pf = 0; + + psize_t pf_chunk_size = 0; + + psize_t npages1 = (VALID_END_PFN_1 - VALID_START_PFN_1); + + psize_t npages2 = (VALID_END_PFN_4 - VALID_START_PFN_4); + + struct vm_page *slab = malloc(sizeof(struct vm_page) + * (npages1 + npages2)); + + setup(); + + /* We start with zero segments */ + ATF_REQUIRE_EQ(true, uvm_physseg_plug(VALID_START_PFN_1, npages1, NULL)); + ATF_REQUIRE_EQ(1, uvm_physseg_get_entries()); + + /* Post boot: Fake all segments and pages accounted for. */ + uvm_page_init_fake(slab, npages1 + npages2); + + ATF_REQUIRE_EQ(true, uvm_physseg_plug(VALID_START_PFN_2, npages2, NULL)); + ATF_REQUIRE_EQ(2, uvm_physseg_get_entries()); + + srandom((unsigned)time(NULL)); + for(pf = VALID_START_PFN_4; pf < VALID_END_PFN_4; pf += PF_STEP) { + pf_chunk_size = (psize_t) random() % (psize_t) (PF_STEP - 1) + 1; + uvm_physseg_unplug(pf, pf_chunk_size); + } + + for(int i = 0; i < 10000000; i++) { + pa = (paddr_t) random() % (paddr_t) ctob(VALID_END_PFN_4); + if(pa < ctob(VALID_START_PFN_4)) + pa += ctob(VALID_START_PFN_4); + PHYS_TO_VM_PAGE(pa); + } + + ATF_CHECK_EQ(true, true); +} + +ATF_TC(uvm_physseg_256MB); +ATF_TC_HEAD(uvm_physseg_256MB, tc) +{ + atf_tc_set_md_var(tc, "descr", "Load test uvm_phys_to_vm_page() with \ + 10,000,000 calls, VM_PHYSSEG_MAX is 32 on 256 MB Segment."); +} +ATF_TC_BODY(uvm_physseg_256MB, t) +{ + paddr_t pa = 0; + + paddr_t pf = 0; + + psize_t pf_chunk_size = 0; + + psize_t npages1 = (VALID_END_PFN_1 - VALID_START_PFN_1); + + psize_t npages2 = (VALID_END_PFN_5 - VALID_START_PFN_5); + + struct vm_page *slab = malloc(sizeof(struct vm_page) * (npages1 + npages2)); + + setup(); + + /* We start with zero segments */ + ATF_REQUIRE_EQ(true, uvm_physseg_plug(VALID_START_PFN_1, npages1, NULL)); + ATF_REQUIRE_EQ(1, uvm_physseg_get_entries()); + + /* Post boot: Fake all segments and pages accounted for. */ + uvm_page_init_fake(slab, npages1 + npages2); + + ATF_REQUIRE_EQ(true, uvm_physseg_plug(VALID_START_PFN_2, npages2, NULL)); + ATF_REQUIRE_EQ(2, uvm_physseg_get_entries()); + + srandom((unsigned)time(NULL)); + for(pf = VALID_START_PFN_5; pf < VALID_END_PFN_5; pf += PF_STEP) { + pf_chunk_size = (psize_t) random() % (psize_t) (PF_STEP - 1) + 1; + uvm_physseg_unplug(pf, pf_chunk_size); + } + + for(int i = 0; i < 10000000; i++) { + pa = (paddr_t) random() % (paddr_t) ctob(VALID_END_PFN_5); + if(pa < ctob(VALID_END_PFN_5)) + pa += ctob(VALID_START_PFN_5); + PHYS_TO_VM_PAGE(pa); + } + + ATF_CHECK_EQ(true, true); +} + +ATF_TP_ADD_TCS(tp) +{ + /* Fixed memory size tests. */ + ATF_TP_ADD_TC(tp, uvm_physseg_100); + ATF_TP_ADD_TC(tp, uvm_physseg_1K); + ATF_TP_ADD_TC(tp, uvm_physseg_10K); + ATF_TP_ADD_TC(tp, uvm_physseg_100K); + ATF_TP_ADD_TC(tp, uvm_physseg_1M); + ATF_TP_ADD_TC(tp, uvm_physseg_10M); + ATF_TP_ADD_TC(tp, uvm_physseg_100M); + +#if defined(UVM_HOTPLUG) + /* Variable memory size tests. */ + ATF_TP_ADD_TC(tp, uvm_physseg_1MB); + ATF_TP_ADD_TC(tp, uvm_physseg_64MB); + ATF_TP_ADD_TC(tp, uvm_physseg_128MB); + ATF_TP_ADD_TC(tp, uvm_physseg_256MB); +#endif /* UVM_HOTPLUG */ + + return atf_no_error(); +} diff --git a/contrib/netbsd-tests/usr.bin/mixerctl/t_mixerctl.sh b/contrib/netbsd-tests/usr.bin/mixerctl/t_mixerctl.sh new file mode 100755 index 000000000000..94c0bdf8cdf4 --- /dev/null +++ b/contrib/netbsd-tests/usr.bin/mixerctl/t_mixerctl.sh @@ -0,0 +1,51 @@ +# $NetBSD: t_mixerctl.sh,v 1.1 2017/01/02 15:40:09 christos Exp $ + +atf_test_case noargs_usage +noargs_usage_head() { + atf_set "descr" "Ensure mixerctl(1) with no args prints a usage message" +} +noargs_usage_body() { + atf_check -s exit:0 -o not-empty -e ignore \ + mixerctl +} + +atf_test_case showvalue +showvalue_head() { + atf_set "descr" "Ensure mixerctl(1) can print the value for all variables" +} +showvalue_body() { + for var in $(mixerctl -a | awk -F= '{print $1}'); do + atf_check -s exit:0 -e ignore -o match:"^${var}=" \ + mixerctl ${var} + done +} + +atf_test_case nflag +nflag_head() { + atf_set "descr" "Ensure 'mixerctl -n' actually suppresses some output" +} +nflag_body() { + varname="$(mixerctl -a | head -1 | awk -F= '{print $1}')" + + atf_check -s exit:0 -o match:"${varname}" -e ignore \ + mixerctl ${varname} + + atf_check -s exit:0 -o not-match:"${varname}" -e ignore \ + mixerctl -n ${varname} +} + +atf_test_case nonexistant_device +nonexistant_device_head() { + atf_set "descr" "Ensure mixerctl(1) complains if provided a nonexistant mixer device" +} +nonexistant_device_body() { + atf_check -s not-exit:0 -o ignore -e match:"No such file" \ + mixerctl -d /a/b/c/d/e +} + +atf_init_test_cases() { + atf_add_test_case noargs_usage + atf_add_test_case showvalue + atf_add_test_case nflag + atf_add_test_case nonexistant_device +} diff --git a/contrib/netbsd-tests/usr.bin/uniq/d_basic.in b/contrib/netbsd-tests/usr.bin/uniq/d_basic.in new file mode 100644 index 000000000000..52a24bcfbb8c --- /dev/null +++ b/contrib/netbsd-tests/usr.bin/uniq/d_basic.in @@ -0,0 +1,4 @@ +1 +12 +1 +1 diff --git a/contrib/netbsd-tests/usr.bin/uniq/d_basic.out b/contrib/netbsd-tests/usr.bin/uniq/d_basic.out new file mode 100644 index 000000000000..d44fcba56f35 --- /dev/null +++ b/contrib/netbsd-tests/usr.bin/uniq/d_basic.out @@ -0,0 +1,3 @@ +1 +12 +1 diff --git a/contrib/netbsd-tests/usr.bin/uniq/d_counts.out b/contrib/netbsd-tests/usr.bin/uniq/d_counts.out new file mode 100644 index 000000000000..bb1c86ba3d6d --- /dev/null +++ b/contrib/netbsd-tests/usr.bin/uniq/d_counts.out @@ -0,0 +1,6 @@ + 1 #01 foo0 bar0 foo1 bar1 + 1 #02 bar0 foo1 bar1 foo1 + 1 #03 foo0 bar0 foo1 bar1 + 1 #04 + 2 #05 foo0 bar0 foo1 bar1 + 1 #07 bar0 foo1 bar1 foo0 diff --git a/contrib/netbsd-tests/usr.bin/uniq/d_input.in b/contrib/netbsd-tests/usr.bin/uniq/d_input.in new file mode 100644 index 000000000000..c32c44d44c0a --- /dev/null +++ b/contrib/netbsd-tests/usr.bin/uniq/d_input.in @@ -0,0 +1,7 @@ +#01 foo0 bar0 foo1 bar1 +#02 bar0 foo1 bar1 foo1 +#03 foo0 bar0 foo1 bar1 +#04 +#05 foo0 bar0 foo1 bar1 +#06 foo0 bar0 foo1 bar1 +#07 bar0 foo1 bar1 foo0 diff --git a/contrib/netbsd-tests/usr.bin/uniq/d_show_duplicates.out b/contrib/netbsd-tests/usr.bin/uniq/d_show_duplicates.out new file mode 100644 index 000000000000..45f4be7029a1 --- /dev/null +++ b/contrib/netbsd-tests/usr.bin/uniq/d_show_duplicates.out @@ -0,0 +1 @@ +#05 foo0 bar0 foo1 bar1 diff --git a/contrib/netbsd-tests/usr.bin/uniq/d_show_uniques.out b/contrib/netbsd-tests/usr.bin/uniq/d_show_uniques.out new file mode 100644 index 000000000000..1cc2ecbf3058 --- /dev/null +++ b/contrib/netbsd-tests/usr.bin/uniq/d_show_uniques.out @@ -0,0 +1,5 @@ +#01 foo0 bar0 foo1 bar1 +#02 bar0 foo1 bar1 foo1 +#03 foo0 bar0 foo1 bar1 +#04 +#07 bar0 foo1 bar1 foo0 diff --git a/contrib/netbsd-tests/usr.bin/uniq/t_uniq.sh b/contrib/netbsd-tests/usr.bin/uniq/t_uniq.sh new file mode 100755 index 000000000000..d90a4d595a86 --- /dev/null +++ b/contrib/netbsd-tests/usr.bin/uniq/t_uniq.sh @@ -0,0 +1,97 @@ +# $NetBSD: t_uniq.sh,v 1.1 2016/10/22 14:13:39 abhinav Exp $ +# +# Copyright (c) 2016 The NetBSD Foundation, Inc. +# All rights reserved. +# +# This code is derived from software contributed to The NetBSD Foundation +# by Abhinav Upadhyay +# +# 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 basic +basic_head() +{ + atf_set "descr" "Checks the basic functionality" +} +basic_body() +{ + atf_check -o file:$(atf_get_srcdir)/d_basic.out uniq \ + $(atf_get_srcdir)/d_basic.in +} + +atf_test_case test_counts +test_counts_head() +{ + atf_set "descr" "Tests the -c option, comparing each line of the input" \ + "file data starting from the second field" +} +test_counts_body() +{ + atf_check -o file:$(atf_get_srcdir)/d_counts.out uniq -c -f 1 \ + $(atf_get_srcdir)/d_input.in +} + +atf_test_case show_duplicates +show_duplicates_head() +{ + atf_set "descr" "Checks the -d option, comparing each line of the input" \ + "file data starting from the second field" +} +show_duplicates_body() +{ + atf_check -o file:$(atf_get_srcdir)/d_show_duplicates.out uniq -d -f 1 \ + $(atf_get_srcdir)/d_input.in +} + +atf_test_case show_uniques +show_uniques_head() +{ + atf_set "descr" "Checks the -u option, comparing each line of the input" \ + "file data starting from the second field" +} +show_uniques_body() +{ + atf_check -o file:$(atf_get_srcdir)/d_show_uniques.out uniq -u -f 1 \ + $(atf_get_srcdir)/d_input.in +} + +atf_test_case show_duplicates_from_third_character +show_duplicates_from_third_character_head() +{ + atf_set "descr" "Checks the -d option, comparing each line of the input" \ + "file data starting from the third character (-s option)" +} +show_duplicates_from_third_character_body() +{ + atf_check -o empty uniq -d -s 2 $(atf_get_srcdir)/d_input.in + +} + +atf_init_test_cases() +{ + atf_add_test_case basic + atf_add_test_case test_counts + atf_add_test_case show_duplicates + atf_add_test_case show_uniques + atf_add_test_case show_duplicates_from_third_character +}