Add additional tests missed in previous merges

Reminder: use cvs up -APd to pull new directories
This commit is contained in:
Enji Cooper 2017-01-14 06:18:54 +00:00
parent a72f1252fc
commit a567518138
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/vendor/NetBSD/tests/dist/; revision=312123
32 changed files with 7309 additions and 2 deletions

View File

@ -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

View File

@ -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 <sys/cdefs.h>
__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 <sys/types.h>
#include <dev/clock_subr.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <atf-c.h>
#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();
}

File diff suppressed because it is too large Load Diff

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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 <sys/cdefs.h>
__RCSID("$NetBSD: t_ptrace_wait.c,v 1.2 2017/01/13 21:30:41 christos Exp $");
#include <sys/param.h>
#include <sys/types.h>
#include <sys/ptrace.h>
#include <sys/resource.h>
#include <sys/stat.h>
#include <sys/sysctl.h>
#include <sys/wait.h>
#include <machine/reg.h>
#include <err.h>
#include <errno.h>
#include <sched.h>
#include <signal.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <unistd.h>
#include <atf-c.h>
#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();
}

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -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"

View File

@ -1,4 +1,4 @@
/* $NetBSD: t_ptrace_wait.c,v 1.57 2017/01/13 23:22:12 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 <sys/cdefs.h>
__RCSID("$NetBSD: t_ptrace_wait.c,v 1.57 2017/01/13 23:22:12 kamil Exp $");
__RCSID("$NetBSD: t_ptrace_wait.c,v 1.58 2017/01/14 04:37:55 kamil Exp $");
#include <sys/param.h>
#include <sys/types.h>
@ -1072,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)
@ -5193,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);

View File

@ -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 <atf-c.h>
#include <errno.h>
#include <signal.h>
#include <stddef.h>
#include <stdio.h>
#include <unistd.h>
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();
}

View File

@ -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 <sys/cdefs.h>
#include <dlfcn.h>
#include <pthread_dbg.h>
#include <string.h>
#include <atf-c.h>
#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

View File

@ -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 <sys/cdefs.h>
__RCSID("$NetBSD: t_dummy.c,v 1.6 2016/11/19 15:13:46 kamil Exp $");
#include "h_common.h"
#include <pthread_dbg.h>
#include <stdio.h>
#include <atf-c.h>
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();
}

View File

@ -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 <sys/cdefs.h>
__RCSID("$NetBSD: t_threads.c,v 1.9 2017/01/13 05:18:22 christos Exp $");
#include <dlfcn.h>
#include <pthread.h>
#include <pthread_dbg.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <atf-c.h>
#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();
}

View File

@ -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 <sys/cdefs.h>
__RCSID("$NetBSD: t_refuse_opt.c,v 1.8 2017/01/13 21:30:41 christos Exp $");
#define _KERNTYPES
#include <sys/types.h>
#include <atf-c.h>
#include <fuse.h>
#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();
}

138
net/if_tun/t_tun.sh Executable file
View File

@ -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
}

115
net/if_vlan/t_vlan.sh Executable file
View File

@ -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
}

2377
sys/uvm/t_uvm_physseg.c Normal file

File diff suppressed because it is too large Load Diff

View File

@ -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 <santhosh.raju@gmail.com> 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 <sys/cdefs.h>
__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 <assert.h>
#include <stdbool.h>
#include <string.h> /* memset(3) et. al */
#include <stdio.h> /* printf(3) */
#include <stdlib.h> /* malloc(3) */
#include <stdarg.h>
#include <stddef.h>
#include <time.h>
#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 <uvm/uvm_physseg.h>
#include <uvm/uvm_page.h>
#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 <atf-c.h>
#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();
}

51
usr.bin/mixerctl/t_mixerctl.sh Executable file
View File

@ -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
}

4
usr.bin/uniq/d_basic.in Normal file
View File

@ -0,0 +1,4 @@
1
12
1
1

3
usr.bin/uniq/d_basic.out Normal file
View File

@ -0,0 +1,3 @@
1
12
1

View File

@ -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

7
usr.bin/uniq/d_input.in Normal file
View File

@ -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

View File

@ -0,0 +1 @@
#05 foo0 bar0 foo1 bar1

View File

@ -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

97
usr.bin/uniq/t_uniq.sh Executable file
View File

@ -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
}