@@ -1444,11 +1444,19 @@ fn test_android(target: &str) {
1444
1444
1445
1445
fn test_freebsd ( target : & str ) {
1446
1446
assert ! ( target. contains( "freebsd" ) ) ;
1447
- let x86 = target. contains ( "i686" ) || target. contains ( "x86_64" ) ;
1448
-
1449
1447
let mut cfg = ctest:: TestGenerator :: new ( ) ;
1448
+
1449
+ let freebsd_ver = which_freebsd ( ) ;
1450
+
1451
+ if let Some ( 12 ) = freebsd_ver {
1452
+ // If the host is FreeBSD 12, run FreeBSD 12 tests
1453
+ cfg. cfg ( "freebsd12" , None ) ;
1454
+ }
1455
+
1450
1456
// Required for `getline`:
1451
1457
cfg. define ( "_WITH_GETLINE" , None ) ;
1458
+ // Required for making freebsd11_stat available in the headers
1459
+ cfg. define ( "_WANT_FREEBSD11_STAT" , None ) ;
1452
1460
1453
1461
headers ! { cfg:
1454
1462
"aio.h" ,
@@ -1530,12 +1538,16 @@ fn test_freebsd(target: &str) {
1530
1538
// Just pass all these through, no need for a "struct" prefix
1531
1539
"FILE" | "fd_set" | "Dl_info" | "DIR" => ty. to_string ( ) ,
1532
1540
1541
+ // FIXME: https://github.com/rust-lang/libc/issues/1273
1533
1542
"sighandler_t" => "sig_t" . to_string ( ) ,
1534
1543
1535
1544
t if is_union => format ! ( "union {}" , t) ,
1536
1545
1537
1546
t if t. ends_with ( "_t" ) => t. to_string ( ) ,
1538
1547
1548
+ // sigval is a struct in Rust, but a union in C:
1549
+ "sigval" => format ! ( "union sigval" ) ,
1550
+
1539
1551
// put `struct` in front of all structs:.
1540
1552
t if is_struct => format ! ( "struct {}" , t) ,
1541
1553
@@ -1557,169 +1569,76 @@ fn test_freebsd(target: &str) {
1557
1569
}
1558
1570
} ) ;
1559
1571
1560
- cfg. skip_struct ( move |ty| {
1561
- match ty {
1562
- // This is actually a union, not a struct
1563
- // FIXME: still required?
1564
- "sigval" => true ,
1565
-
1566
- _ => false ,
1567
- }
1568
- } ) ;
1569
-
1570
- cfg. skip_signededness ( move |c| {
1571
- match c {
1572
- // FIXME: still required?
1573
- "LARGE_INTEGER" | "float" | "double" => true ,
1574
- // FIXME: still required?
1575
- n if n. starts_with ( "pthread" ) => true ,
1576
- // sem_t is a struct or pointer
1577
- // FIXME: still required?
1578
- "sem_t" => true ,
1579
- // mqd_t is a pointer on FreeBSD
1580
- // FIXME: still required?
1581
- "mqd_t" => true ,
1582
-
1583
- _ => false ,
1584
- }
1585
- } ) ;
1586
-
1587
1572
cfg. skip_const ( move |name| {
1588
1573
match name {
1589
- // FIXME: still required?
1590
- "SIG_DFL" | "SIG_ERR" | "SIG_IGN" => true , // sighandler_t weirdness
1574
+ // These constants were introduced in FreeBSD 12:
1575
+ "SF_USER_READAHEAD"
1576
+ | "EVFILT_EMPTY"
1577
+ | "SO_REUSEPORT_LB"
1578
+ | "IP_ORIGDSTADDR"
1579
+ | "IP_RECVORIGDSTADDR"
1580
+ | "IPV6_ORIGDSTADDR"
1581
+ | "IPV6_RECVORIGDSTADDR"
1582
+ if Some ( 12 ) != freebsd_ver =>
1583
+ {
1584
+ true
1585
+ }
1591
1586
1587
+ // FIXME: There are deprecated - remove in a couple of releases.
1592
1588
// These constants were removed in FreeBSD 11 (svn r273250) but will
1593
1589
// still be accepted and ignored at runtime.
1594
- "MAP_RENAME" | "MAP_NORESERVE" => true ,
1590
+ "MAP_RENAME" | "MAP_NORESERVE" if Some ( 10 ) != freebsd_ver => true ,
1595
1591
1592
+ // FIXME: There are deprecated - remove in a couple of releases.
1596
1593
// These constants were removed in FreeBSD 11 (svn r262489),
1597
1594
// and they've never had any legitimate use outside of the
1598
1595
// base system anyway.
1599
1596
"CTL_MAXID" | "KERN_MAXID" | "HW_MAXID" | "NET_MAXID"
1600
1597
| "USER_MAXID" => true ,
1601
1598
1602
- // These constants were added in FreeBSD 11
1603
- // FIXME: still required?
1604
- "EVFILT_PROCDESC" | "EVFILT_SENDFILE" | "EVFILT_EMPTY"
1605
- | "PD_CLOEXEC" | "PD_ALLOWED_AT_FORK" => true ,
1606
-
1607
- // These constants were added in FreeBSD 12
1608
- // FIXME: still required?
1609
- "SF_USER_READAHEAD" | "SO_REUSEPORT_LB" => true ,
1610
-
1611
- // These constants are tested in a separate test program generated
1612
- // below because there are header conflicts if we try to include the
1613
- // headers that define them here.
1614
- // FIXME: still required?
1615
- "F_CANCELLK" | "F_ADD_SEALS" | "F_GET_SEALS" => true ,
1616
- // FIXME: still required?
1617
- "F_SEAL_SEAL" | "F_SEAL_SHRINK" | "F_SEAL_GROW"
1618
- | "F_SEAL_WRITE" => true ,
1619
- // FIXME: still required?
1620
- "BOTHER" => true ,
1621
-
1622
- // MFD_HUGETLB is not available in some older libc versions on the
1623
- // CI builders. On the x86_64 and i686 builders it seems to be
1624
- // available for all targets, so at least test it there.
1625
- // FIXME: still required?
1626
- "MFD_HUGETLB" if !x86 => true ,
1627
-
1628
- // These change all the time from release to release of linux
1629
- // distros, let's just not bother trying to verify them. They
1630
- // shouldn't be used in code anyway...
1631
- // FIXME: still required?
1632
- "AF_MAX" | "PF_MAX" => true ,
1633
-
1634
- // FreeBSD 12 required, but CI has FreeBSD 11.
1635
- // FIXME: still required?
1636
- "IP_ORIGDSTADDR"
1637
- | "IP_RECVORIGDSTADDR"
1638
- | "IPV6_ORIGDSTADDR"
1639
- | "IPV6_RECVORIGDSTADDR" => true ,
1640
-
1641
1599
_ => false ,
1642
1600
}
1643
1601
} ) ;
1644
1602
1645
1603
cfg. skip_fn ( move |name| {
1646
1604
// skip those that are manually verified
1647
1605
match name {
1648
- // FIXME: still required?
1649
- "execv" | // crazy stuff with const/mut
1650
- "execve" |
1651
- "execvp" |
1652
- "execvpe" |
1653
- "fexecve" => true ,
1606
+ // FIXME: https://github.com/rust-lang/libc/issues/1272
1607
+ "execv" | "execve" | "execvp" | "execvpe" | "fexecve" => true ,
1654
1608
1655
1609
// The `uname` function in freebsd is now an inline wrapper that
1656
1610
// delegates to another, but the symbol still exists, so don't check
1657
1611
// the symbol.
1658
- // FIXME: still required?
1659
1612
"uname" => true ,
1660
1613
1661
- // FIXME: need to upgrade FreeBSD version; see https://github.com/rust-lang/libc/issues/938
1662
- // FIXME: still required?
1663
- "setgrent" => true ,
1664
-
1665
- // aio_waitcomplete's return type changed between FreeBSD 10 and 11.
1666
- // FIXME: still required?
1667
- "aio_waitcomplete" => true ,
1668
-
1669
- // lio_listio confuses the checker, probably because one of its
1670
- // arguments is an array
1671
- // FIXME: still required?
1614
+ // FIXME: Our API is unsound. The Rust API allows aliasing
1615
+ // pointers, but the C API requires pointers not to alias.
1616
+ // We should probably be at least using `&`/`&mut` here, see:
1617
+ // https://github.com/gnzlbg/ctest/issues/68
1672
1618
"lio_listio" => true ,
1673
1619
1674
- // Definition of those functions as changed since unified headers from NDK r14b
1675
- // These changes imply some API breaking changes but are still ABI compatible.
1676
- // We can wait for the next major release to be compliant with the new API.
1677
- // FIXME: unskip these for next major release
1678
- // FIXME: still required ?
1679
- "strerror_r" | "madvise" | "msync" | "mprotect" | "recvfrom" | "getpriority" |
1680
-
1681
1620
_ => false ,
1682
1621
}
1683
1622
} ) ;
1684
1623
1685
- cfg. skip_field_type ( move |struct_, field| {
1686
- // This is a weird union, don't check the type.
1687
- // FIXME: still required?
1688
- ( struct_ == "ifaddrs" && field == "ifa_ifu" ) ||
1689
- // FIXME: still required?
1690
- // sighandler_t type is super weird
1691
- ( struct_ == "sigaction" && field == "sa_sigaction" ) ||
1692
- // FIXME: still required?
1693
- // sigval is actually a union, but we pretend it's a struct
1694
- ( struct_ == "sigevent" && field == "sigev_value" ) ||
1695
- // aio_buf is "volatile void*" and Rust doesn't understand volatile
1696
- // FIXME: still required?
1697
- ( struct_ == "aiocb" && field == "aio_buf" ) ||
1698
- // stack_t.ss_sp's type changed from FreeBSD 10 to 11 in svn r294930
1699
- // FIXME: still required?
1700
- ( struct_ == "stack_t" && field == "ss_sp" )
1624
+ cfg. volatile_item ( |i| {
1625
+ use ctest:: VolatileItemKind :: * ;
1626
+ match i {
1627
+ // aio_buf is a volatile void** but since we cannot express that in
1628
+ // Rust types, we have to explicitly tell the checker about it here:
1629
+ StructField ( ref n, ref f) if n == "aiocb" && f == "aio_buf" => {
1630
+ true
1631
+ }
1632
+ _ => false ,
1633
+ }
1701
1634
} ) ;
1702
1635
1703
1636
cfg. skip_field ( move |struct_, field| {
1704
- // this is actually a union on linux, so we can't represent it well and
1705
- // just insert some padding.
1706
- // FIXME: still required?
1707
- ( struct_ == "siginfo_t" && field == "_pad" ) ||
1708
- // sigev_notify_thread_id is actually part of a sigev_un union
1709
- // FIXME: still required?
1710
- ( struct_ == "sigevent" && field == "sigev_notify_thread_id" ) ||
1711
- // signalfd had SIGSYS fields added in Linux 4.18, but no libc release has them yet.
1712
- // FIXME: still required?
1713
- ( struct_ == "signalfd_siginfo" && ( field == "ssi_addr_lsb" ||
1714
- field == "_pad2" ||
1715
- field == "ssi_syscall" ||
1716
- field == "ssi_call_addr" ||
1717
- field == "ssi_arch" ) )
1637
+ // FIXME: `sa_sigaction` has type `sighandler_t` but that type is
1638
+ // incorrect, see: https://github.com/rust-lang/libc/issues/1359
1639
+ ( struct_ == "sigaction" && field == "sa_sigaction" )
1718
1640
} ) ;
1719
1641
1720
- // FIXME: remove
1721
- cfg. fn_cname ( move |name, _cname| name. to_string ( ) ) ;
1722
-
1723
1642
cfg. generate ( "../src/lib.rs" , "main.rs" ) ;
1724
1643
}
1725
1644
@@ -2686,3 +2605,20 @@ fn test_linux_termios2(target: &str) {
2686
2605
} ) ;
2687
2606
cfg. generate ( "../src/lib.rs" , "linux_fcntl.rs" ) ;
2688
2607
}
2608
+
2609
+ fn which_freebsd ( ) -> Option < i32 > {
2610
+ let output = std:: process:: Command :: new ( "freebsd-version" )
2611
+ . output ( )
2612
+ . ok ( ) ?;
2613
+ if !output. status . success ( ) {
2614
+ return None ;
2615
+ }
2616
+
2617
+ let stdout = String :: from_utf8 ( output. stdout ) . ok ( ) ?;
2618
+
2619
+ match & stdout {
2620
+ s if s. starts_with ( "11" ) => Some ( 11 ) ,
2621
+ s if s. starts_with ( "12" ) => Some ( 12 ) ,
2622
+ _ => None ,
2623
+ }
2624
+ }
0 commit comments