Changeset 110dbd0 in rtems-libbsd


Ignore:
Timestamp:
Jul 14, 2016, 1:34:13 PM (4 years ago)
Author:
Christian Mauderer <Christian.Mauderer@…>
Branches:
4.11
Children:
c78c296
Parents:
c117a28
git-author:
Christian Mauderer <Christian.Mauderer@…> (07/14/16 13:34:13)
git-committer:
Sebastian Huber <sebastian.huber@…> (08/03/16 12:13:18)
Message:

testsuite/syscalls01: Split out program01 part.

This allows to use normal functions for sockets and similar while
allowing to test the upcoming rtems_bsd_program_opan/close/... for the
program part.

Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • libbsd.py

    rc117a28 r110dbd0  
    24662466    mod.addTest(mm.generator['test']('sleep01', ['test_main']))
    24672467    mod.addTest(mm.generator['test']('syscalls01', ['test_main']))
     2468    mod.addTest(mm.generator['test']('program01', ['test_main']))
    24682469    mod.addTest(mm.generator['test']('commands01', ['test_main']))
    24692470    mod.addTest(mm.generator['test']('usb01', ['init', 'test-file-system'], False))
  • testsuite/syscalls01/test_main.c

    rc117a28 r110dbd0  
    5252#include <unistd.h>
    5353#include <syslog.h>
    54 
    55 #define RTEMS_BSD_PROGRAM_NO_EXIT_WRAP
    56 #define RTEMS_BSD_PROGRAM_NO_PRINTF_WRAP
    57 #include <machine/rtems-bsd-program.h>
    5854
    5955#include <rtems.h>
     
    15531549}
    15541550
    1555 static const char prog_name[] = "prog";
    1556 
    1557 static int
    1558 invalid_prog(void *ctx)
    1559 {
    1560         (void) ctx;
    1561 
    1562         assert(0);
    1563 }
    1564 
    1565 static int
    1566 invalid_main(int argc, char **argv)
    1567 {
    1568         (void) argc;
    1569         (void) argv;
    1570 
    1571         assert(0);
    1572 }
    1573 
    1574 static void *const some_context = (void *) 0xcafe;
    1575 
    1576 static int
    1577 some_prog(void *ctx)
    1578 {
    1579         assert(ctx == some_context);
    1580         assert(strcmp(rtems_bsd_program_get_name(), prog_name) == 0);
    1581         assert(rtems_bsd_program_get_context() == some_context);
    1582         errno = 0;
    1583         rtems_bsd_program_exit(456);
    1584 }
    1585 
    1586 static const int some_argc = 1;
    1587 
    1588 static char *some_argv[] = { "a", NULL };
    1589 
    1590 static int
    1591 some_main(int argc, char **argv)
    1592 {
    1593         assert(argc == some_argc);
    1594         assert(argv == some_argv);
    1595         assert(strcmp(rtems_bsd_program_get_name(), prog_name) == 0);
    1596         errno = 0;
    1597         rtems_bsd_program_exit(789);
    1598 }
    1599 
    1600 static void
    1601 no_mem_bsd_program(int fd)
    1602 {
    1603         (void) fd;
    1604 
    1605         assert(rtems_bsd_program_call(prog_name, invalid_prog, NULL)
    1606             == EXIT_FAILURE);
    1607         assert(rtems_bsd_program_call_main(prog_name, invalid_main, some_argc,
    1608             some_argv) == EXIT_FAILURE);
    1609         assert(strcmp(rtems_bsd_program_get_name(), "?") == 0);
    1610         assert(rtems_bsd_program_get_context() == NULL);
    1611 }
    1612 
    1613 static void
    1614 test_bsd_program(void)
    1615 {
    1616         rtems_resource_snapshot snapshot;
    1617         int exit_code;
    1618         void *greedy;
    1619         char *invalid_argv[2] = { "a", "b" };
    1620 
    1621         assert(rtems_configuration_get_unified_work_area());
    1622 
    1623         puts("test BSD program");
    1624 
    1625         rtems_resource_snapshot_take(&snapshot);
    1626 
    1627         do_no_mem_test(no_mem_bsd_program, -1);
    1628 
    1629         greedy = rtems_workspace_greedy_allocate(NULL, 0);
    1630         no_mem_bsd_program(-1);
    1631         rtems_workspace_greedy_free(greedy);
    1632 
    1633         errno = 0;
    1634         exit_code = rtems_bsd_program_call_main(prog_name, NULL, 1, invalid_argv);
    1635         assert(errno == EFAULT);
    1636         assert(exit_code == EXIT_FAILURE);
    1637 
    1638         errno = EINVAL;
    1639         exit_code = rtems_bsd_program_call(prog_name, some_prog, some_context);
    1640         assert(errno == 0);
    1641         assert(exit_code == 456);
    1642         assert(strcmp(rtems_bsd_program_get_name(), "?") == 0);
    1643         assert(rtems_bsd_program_get_context() == NULL);
    1644 
    1645         errno = EINVAL;
    1646         exit_code = rtems_bsd_program_call_main(prog_name, some_main,
    1647             some_argc, some_argv);
    1648         assert(errno == 0);
    1649         assert(exit_code == 789);
    1650         assert(strcmp(rtems_bsd_program_get_name(), "?") == 0);
    1651         assert(rtems_bsd_program_get_context() == NULL);
    1652 
    1653         assert(rtems_resource_snapshot_check(&snapshot));
    1654 }
    1655 
    1656 static void
    1657 test_warn(void)
    1658 {
    1659         puts("test warn");
    1660 
    1661         errno = EAGAIN;
    1662         warn("%s", "warn");
    1663 
    1664         errno = ENAMETOOLONG;
    1665         warn(NULL);
    1666 
    1667         errno = 0;
    1668         warnc(EDOM, "%s", "warnc");
    1669 
    1670         errno = 0;
    1671         warnc(ERANGE, NULL);
    1672 
    1673         warnx("%s", "warnx");
    1674 
    1675         warnx(NULL);
    1676 }
    1677 
    1678 static int
    1679 call_err(void *ctx)
    1680 {
    1681         errno = EAGAIN;
    1682         err(10, "%s", "call_err");
    1683 }
    1684 
    1685 static int
    1686 call_err_null(void *ctx)
    1687 {
    1688         errno = ENAMETOOLONG;
    1689         err(11, NULL);
    1690 }
    1691 
    1692 static int
    1693 call_errc(void *ctx)
    1694 {
    1695         errc(12, EDOM, "%s", "call_errc");
    1696 }
    1697 
    1698 static int
    1699 call_errc_null(void *ctx)
    1700 {
    1701         errc(13, ERANGE, NULL);
    1702 }
    1703 
    1704 static int
    1705 call_errx(void *ctx)
    1706 {
    1707         errx(14, "%s", "call_errx");
    1708 }
    1709 
    1710 static int
    1711 call_errx_null(void *ctx)
    1712 {
    1713         errx(15, NULL);
    1714 }
    1715 
    1716 static void
    1717 test_err(void)
    1718 {
    1719         int exit_code;
    1720 
    1721         puts("test err");
    1722 
    1723         exit_code = rtems_bsd_program_call("err", call_err, NULL);
    1724         assert(exit_code == 10);
    1725 
    1726         exit_code = rtems_bsd_program_call("err", call_err_null, NULL);
    1727         assert(exit_code == 11);
    1728 
    1729         exit_code = rtems_bsd_program_call("errc", call_errc, NULL);
    1730         assert(exit_code == 12);
    1731 
    1732         exit_code = rtems_bsd_program_call("errc", call_errc_null, NULL);
    1733         assert(exit_code == 13);
    1734 
    1735         exit_code = rtems_bsd_program_call("errx", call_errx, NULL);
    1736         assert(exit_code == 14);
    1737 
    1738         exit_code = rtems_bsd_program_call("errx", call_errx_null, NULL);
    1739         assert(exit_code == 15);
    1740 }
    1741 
    17421551static void
    17431552test_syslog(void)
     
    18081617        test_kqueue_kevent();
    18091618
    1810         test_bsd_program();
    1811         test_warn();
    1812         test_err();
    18131619        test_syslog();
    18141620        test_setgethostname();
  • wscript

    rc117a28 r110dbd0  
    13621362                install_path = None)
    13631363
     1364    test_program01 = ['testsuite/program01/test_main.c']
     1365    bld.program(target = "program01",
     1366                features = "cprogram",
     1367                cflags = cflags,
     1368                includes = includes,
     1369                source = test_program01,
     1370                use = ["bsd"],
     1371                lib = ["m", "z"],
     1372                install_path = None)
     1373
    13641374    test_swi01 = ['testsuite/swi01/init.c',
    13651375                  'testsuite/swi01/swi_test.c']
Note: See TracChangeset for help on using the changeset viewer.