Changeset 06d14667 in rtems
- Timestamp:
- 02/24/17 10:46:26 (7 years ago)
- Branches:
- 5, master
- Children:
- 5244d31e
- Parents:
- c80f6aa9
- git-author:
- Sebastian Huber <sebastian.huber@…> (02/24/17 10:46:26)
- git-committer:
- Sebastian Huber <sebastian.huber@…> (02/28/17 08:05:47)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
testsuites/libtests/termios09/init.c
rc80f6aa9 r06d14667 222 222 } 223 223 224 static void clear_set_oflag( 225 test_context *ctx, 226 size_t i, 227 tcflag_t clear, 228 tcflag_t set 229 ) 230 { 231 ctx->term[i].c_oflag &= ~clear; 232 ctx->term[i].c_oflag |= set; 233 set_term(ctx, i); 234 } 235 224 236 static void set_vmin_vtime( 225 237 test_context *ctx, … … 558 570 set_veol_veol2(ctx, i, '\0', '\0'); 559 571 clear_set_lflag(ctx, i, ICANON, 0); 572 } 573 574 static void flush_output(test_context *ctx, size_t i) 575 { 576 if (i == INTERRUPT) { 577 device_context *dev = &ctx->devices[i]; 578 579 while (dev->output_pending != 0) { 580 rtems_termios_dequeue_characters(dev->tty, dev->output_pending); 581 } 582 } 583 } 584 585 static void clear_output(test_context *ctx, size_t i) 586 { 587 device_context *dev = &ctx->devices[i]; 588 589 dev->output_pending = 0; 590 dev->output_count = 0; 591 memset(&dev->output_buf, 0, OUTPUT_BUFFER_SIZE); 592 } 593 594 static void test_onlret(test_context *ctx) 595 { 596 tcflag_t oflags = OPOST | ONLRET; 597 size_t i; 598 599 for (i = 0; i < DEVICE_COUNT; ++i) { 600 device_context *dev = &ctx->devices[i]; 601 char c; 602 ssize_t n; 603 604 dev->tty->column = 0; 605 clear_output(ctx, i); 606 607 clear_set_oflag(ctx, i, 0, oflags); 608 609 c = 'a'; 610 n = write(ctx->fds[i], &c, sizeof(c)); 611 rtems_test_assert(n == 1); 612 rtems_test_assert(dev->tty->column == 1); 613 flush_output(ctx, i); 614 rtems_test_assert(dev->output_count == 1); 615 rtems_test_assert(dev->output_buf[0] == 'a'); 616 617 c = '\n'; 618 n = write(ctx->fds[i], &c, sizeof(c)); 619 rtems_test_assert(n == 1); 620 rtems_test_assert(dev->tty->column == 0); 621 flush_output(ctx, i); 622 rtems_test_assert(dev->output_count == 2); 623 rtems_test_assert(dev->output_buf[1] == '\n'); 624 625 clear_set_oflag(ctx, i, oflags, 0); 626 } 627 } 628 629 static void test_onlcr(test_context *ctx) 630 { 631 tcflag_t oflags = OPOST | ONLCR; 632 size_t i; 633 634 for (i = 0; i < DEVICE_COUNT; ++i) { 635 device_context *dev = &ctx->devices[i]; 636 char c; 637 ssize_t n; 638 639 dev->tty->column = 0; 640 clear_output(ctx, i); 641 642 clear_set_oflag(ctx, i, 0, oflags); 643 644 c = 'a'; 645 n = write(ctx->fds[i], &c, sizeof(c)); 646 rtems_test_assert(n == 1); 647 rtems_test_assert(dev->tty->column == 1); 648 flush_output(ctx, i); 649 rtems_test_assert(dev->output_count == 1); 650 rtems_test_assert(dev->output_buf[0] == 'a'); 651 652 c = '\n'; 653 n = write(ctx->fds[i], &c, sizeof(c)); 654 rtems_test_assert(n == 1); 655 rtems_test_assert(dev->tty->column == 0); 656 flush_output(ctx, i); 657 rtems_test_assert(dev->output_count == 3); 658 rtems_test_assert(dev->output_buf[1] == '\r'); 659 rtems_test_assert(dev->output_buf[2] == '\n'); 660 661 clear_set_oflag(ctx, i, oflags, 0); 662 } 663 } 664 665 static void test_onocr(test_context *ctx) 666 { 667 tcflag_t oflags = OPOST | ONOCR; 668 size_t i; 669 670 for (i = 0; i < DEVICE_COUNT; ++i) { 671 device_context *dev = &ctx->devices[i]; 672 char c; 673 ssize_t n; 674 675 dev->tty->column = 0; 676 clear_output(ctx, i); 677 678 clear_set_oflag(ctx, i, 0, oflags); 679 680 c = '\r'; 681 n = write(ctx->fds[i], &c, sizeof(c)); 682 rtems_test_assert(n == 1); 683 rtems_test_assert(dev->tty->column == 0); 684 flush_output(ctx, i); 685 rtems_test_assert(dev->output_count == 0); 686 687 c = 'a'; 688 n = write(ctx->fds[i], &c, sizeof(c)); 689 rtems_test_assert(n == 1); 690 rtems_test_assert(dev->tty->column == 1); 691 flush_output(ctx, i); 692 rtems_test_assert(dev->output_count == 1); 693 rtems_test_assert(dev->output_buf[0] == 'a'); 694 695 c = '\r'; 696 n = write(ctx->fds[i], &c, sizeof(c)); 697 rtems_test_assert(n == 1); 698 rtems_test_assert(dev->tty->column == 0); 699 flush_output(ctx, i); 700 rtems_test_assert(dev->output_count == 2); 701 rtems_test_assert(dev->output_buf[1] == '\r'); 702 703 clear_set_oflag(ctx, i, oflags, 0); 704 } 705 } 706 707 static void test_ocrnl(test_context *ctx) 708 { 709 tcflag_t oflags = OPOST | OCRNL; 710 size_t i; 711 712 for (i = 0; i < DEVICE_COUNT; ++i) { 713 device_context *dev = &ctx->devices[i]; 714 char c; 715 ssize_t n; 716 717 dev->tty->column = 0; 718 clear_output(ctx, i); 719 720 clear_set_oflag(ctx, i, 0, oflags); 721 722 c = '\r'; 723 n = write(ctx->fds[i], &c, sizeof(c)); 724 rtems_test_assert(n == 1); 725 rtems_test_assert(dev->tty->column == 0); 726 flush_output(ctx, i); 727 rtems_test_assert(dev->output_count == 1); 728 rtems_test_assert(dev->output_buf[0] == '\n'); 729 730 clear_set_oflag(ctx, i, oflags, 0); 731 } 732 } 733 734 static void test_ocrnl_onlret(test_context *ctx) 735 { 736 tcflag_t oflags = OPOST | OCRNL | ONLRET; 737 size_t i; 738 739 for (i = 0; i < DEVICE_COUNT; ++i) { 740 device_context *dev = &ctx->devices[i]; 741 char c; 742 ssize_t n; 743 744 dev->tty->column = 0; 745 clear_output(ctx, i); 746 747 clear_set_oflag(ctx, i, 0, oflags); 748 749 c = 'a'; 750 n = write(ctx->fds[i], &c, sizeof(c)); 751 rtems_test_assert(n == 1); 752 rtems_test_assert(dev->tty->column == 1); 753 flush_output(ctx, i); 754 rtems_test_assert(dev->output_count == 1); 755 rtems_test_assert(dev->output_buf[0] == 'a'); 756 757 c = '\r'; 758 n = write(ctx->fds[i], &c, sizeof(c)); 759 rtems_test_assert(n == 1); 760 rtems_test_assert(dev->tty->column == 0); 761 flush_output(ctx, i); 762 rtems_test_assert(dev->output_count == 2); 763 rtems_test_assert(dev->output_buf[1] == '\n'); 764 765 clear_set_oflag(ctx, i, oflags, 0); 766 } 767 } 768 769 static void test_opost(test_context *ctx) 770 { 771 tcflag_t oflags = OPOST; 772 size_t i; 773 774 for (i = 0; i < DEVICE_COUNT; ++i) { 775 device_context *dev = &ctx->devices[i]; 776 char c; 777 ssize_t n; 778 779 dev->tty->column = 0; 780 clear_output(ctx, i); 781 782 clear_set_oflag(ctx, i, 0, oflags); 783 784 c = 'a'; 785 n = write(ctx->fds[i], &c, sizeof(c)); 786 rtems_test_assert(n == 1); 787 rtems_test_assert(dev->tty->column == 1); 788 flush_output(ctx, i); 789 rtems_test_assert(dev->output_count == 1); 790 rtems_test_assert(dev->output_buf[0] == 'a'); 791 792 c = '\33'; 793 n = write(ctx->fds[i], &c, sizeof(c)); 794 rtems_test_assert(n == 1); 795 rtems_test_assert(dev->tty->column == 1); 796 flush_output(ctx, i); 797 rtems_test_assert(dev->output_count == 2); 798 rtems_test_assert(dev->output_buf[1] == '\33'); 799 800 c = '\t'; 801 n = write(ctx->fds[i], &c, sizeof(c)); 802 rtems_test_assert(n == 1); 803 rtems_test_assert(dev->tty->column == 8); 804 flush_output(ctx, i); 805 rtems_test_assert(dev->output_count == 3); 806 rtems_test_assert(dev->output_buf[2] == '\t'); 807 808 c = '\b'; 809 n = write(ctx->fds[i], &c, sizeof(c)); 810 rtems_test_assert(n == 1); 811 rtems_test_assert(dev->tty->column == 7); 812 flush_output(ctx, i); 813 rtems_test_assert(dev->output_count == 4); 814 rtems_test_assert(dev->output_buf[3] == '\b'); 815 816 c = '\r'; 817 n = write(ctx->fds[i], &c, sizeof(c)); 818 rtems_test_assert(n == 1); 819 rtems_test_assert(dev->tty->column == 0); 820 flush_output(ctx, i); 821 rtems_test_assert(dev->output_count == 5); 822 rtems_test_assert(dev->output_buf[4] == '\r'); 823 824 clear_set_oflag(ctx, i, oflags, 0); 825 } 826 } 827 828 static void test_xtabs(test_context *ctx) 829 { 830 tcflag_t oflags = OPOST | XTABS; 831 size_t i; 832 833 for (i = 0; i < DEVICE_COUNT; ++i) { 834 device_context *dev = &ctx->devices[i]; 835 char c; 836 ssize_t n; 837 838 dev->tty->column = 0; 839 clear_output(ctx, i); 840 841 clear_set_oflag(ctx, i, 0, oflags); 842 843 c = 'a'; 844 n = write(ctx->fds[i], &c, sizeof(c)); 845 rtems_test_assert(n == 1); 846 rtems_test_assert(dev->tty->column == 1); 847 flush_output(ctx, i); 848 rtems_test_assert(dev->output_count == 1); 849 rtems_test_assert(dev->output_buf[0] == 'a'); 850 851 c = '\t'; 852 n = write(ctx->fds[i], &c, sizeof(c)); 853 rtems_test_assert(n == 1); 854 rtems_test_assert(dev->tty->column == 8); 855 flush_output(ctx, i); 856 rtems_test_assert(dev->output_count == 8); 857 rtems_test_assert(dev->output_buf[1] == ' '); 858 rtems_test_assert(dev->output_buf[2] == ' '); 859 rtems_test_assert(dev->output_buf[3] == ' '); 860 rtems_test_assert(dev->output_buf[4] == ' '); 861 rtems_test_assert(dev->output_buf[5] == ' '); 862 rtems_test_assert(dev->output_buf[6] == ' '); 863 rtems_test_assert(dev->output_buf[7] == ' '); 864 865 clear_set_oflag(ctx, i, oflags, 0); 866 } 867 } 868 869 static void test_olcuc(test_context *ctx) 870 { 871 tcflag_t oflags = OPOST | OLCUC; 872 size_t i; 873 874 for (i = 0; i < DEVICE_COUNT; ++i) { 875 device_context *dev = &ctx->devices[i]; 876 char c; 877 ssize_t n; 878 879 dev->tty->column = 0; 880 clear_output(ctx, i); 881 882 clear_set_oflag(ctx, i, 0, oflags); 883 884 c = 'a'; 885 n = write(ctx->fds[i], &c, sizeof(c)); 886 rtems_test_assert(n == 1); 887 rtems_test_assert(dev->tty->column == 1); 888 flush_output(ctx, i); 889 rtems_test_assert(dev->output_count == 1); 890 rtems_test_assert(dev->output_buf[0] == 'A'); 891 892 c = 'B'; 893 n = write(ctx->fds[i], &c, sizeof(c)); 894 rtems_test_assert(n == 1); 895 rtems_test_assert(dev->tty->column == 2); 896 flush_output(ctx, i); 897 rtems_test_assert(dev->output_count == 2); 898 rtems_test_assert(dev->output_buf[1] == 'B'); 899 900 c = '9'; 901 n = write(ctx->fds[i], &c, sizeof(c)); 902 rtems_test_assert(n == 1); 903 rtems_test_assert(dev->tty->column == 3); 904 flush_output(ctx, i); 905 rtems_test_assert(dev->output_count == 3); 906 rtems_test_assert(dev->output_buf[2] == '9'); 907 908 clear_set_oflag(ctx, i, oflags, 0); 909 } 560 910 } 561 911 … … 574 924 test_rx_callback(ctx); 575 925 test_rx_callback_icanon(ctx); 926 test_onlret(ctx); 927 test_onlcr(ctx); 928 test_onocr(ctx); 929 test_ocrnl(ctx); 930 test_ocrnl_onlret(ctx); 931 test_opost(ctx); 932 test_xtabs(ctx); 933 test_olcuc(ctx); 576 934 577 935 TEST_END();
Note: See TracChangeset
for help on using the changeset viewer.