[Lldb-commits] [lldb] 71fd5a7 - [lldb] [test] Use secondary pty end for testing Terminal
Michał Górny via lldb-commits
lldb-commits at lists.llvm.org
Fri Oct 8 05:42:55 PDT 2021
Author: Michał Górny
Date: 2021-10-08T14:42:47+02:00
New Revision: 71fd5a735ec2f30105249dc367754a604ad00308
URL: https://github.com/llvm/llvm-project/commit/71fd5a735ec2f30105249dc367754a604ad00308
DIFF: https://github.com/llvm/llvm-project/commit/71fd5a735ec2f30105249dc367754a604ad00308.diff
LOG: [lldb] [test] Use secondary pty end for testing Terminal
Open and use the secondary end of a pty for testing Terminal properties
in order to fix the tests on Darwin. While at it, streamline getting
the fd and Terminal class.
Differential Revision: https://reviews.llvm.org/D111402
Added:
Modified:
lldb/unittests/Host/posix/TerminalTest.cpp
Removed:
################################################################################
diff --git a/lldb/unittests/Host/posix/TerminalTest.cpp b/lldb/unittests/Host/posix/TerminalTest.cpp
index 788c2a6ea579e..dc5c6e9d0f37e 100644
--- a/lldb/unittests/Host/posix/TerminalTest.cpp
+++ b/lldb/unittests/Host/posix/TerminalTest.cpp
@@ -21,16 +21,22 @@ using namespace lldb_private;
class TerminalTest : public ::testing::Test {
protected:
PseudoTerminal m_pty;
+ int m_fd;
+ Terminal m_term;
void SetUp() override {
- EXPECT_THAT_ERROR(m_pty.OpenFirstAvailablePrimary(O_RDWR | O_NOCTTY),
+ ASSERT_THAT_ERROR(m_pty.OpenFirstAvailablePrimary(O_RDWR | O_NOCTTY),
llvm::Succeeded());
+ ASSERT_THAT_ERROR(m_pty.OpenSecondary(O_RDWR | O_NOCTTY),
+ llvm::Succeeded());
+ m_fd = m_pty.GetSecondaryFileDescriptor();
+ ASSERT_NE(m_fd, -1);
+ m_term.SetFileDescriptor(m_fd);
}
};
TEST_F(TerminalTest, PtyIsATerminal) {
- Terminal term{m_pty.GetPrimaryFileDescriptor()};
- EXPECT_EQ(term.IsATerminal(), true);
+ EXPECT_EQ(m_term.IsATerminal(), true);
}
TEST_F(TerminalTest, PipeIsNotATerminal) {
@@ -44,39 +50,35 @@ TEST_F(TerminalTest, PipeIsNotATerminal) {
TEST_F(TerminalTest, SetEcho) {
struct termios terminfo;
- Terminal term{m_pty.GetPrimaryFileDescriptor()};
- ASSERT_EQ(term.SetEcho(true), true);
- ASSERT_EQ(tcgetattr(m_pty.GetPrimaryFileDescriptor(), &terminfo), 0);
+ ASSERT_EQ(m_term.SetEcho(true), true);
+ ASSERT_EQ(tcgetattr(m_fd, &terminfo), 0);
EXPECT_NE(terminfo.c_lflag & ECHO, 0U);
- ASSERT_EQ(term.SetEcho(false), true);
- ASSERT_EQ(tcgetattr(m_pty.GetPrimaryFileDescriptor(), &terminfo), 0);
+ ASSERT_EQ(m_term.SetEcho(false), true);
+ ASSERT_EQ(tcgetattr(m_fd, &terminfo), 0);
EXPECT_EQ(terminfo.c_lflag & ECHO, 0U);
}
TEST_F(TerminalTest, SetCanonical) {
struct termios terminfo;
- Terminal term{m_pty.GetPrimaryFileDescriptor()};
- ASSERT_EQ(term.SetCanonical(true), true);
- ASSERT_EQ(tcgetattr(m_pty.GetPrimaryFileDescriptor(), &terminfo), 0);
+ ASSERT_EQ(m_term.SetCanonical(true), true);
+ ASSERT_EQ(tcgetattr(m_fd, &terminfo), 0);
EXPECT_NE(terminfo.c_lflag & ICANON, 0U);
- ASSERT_EQ(term.SetCanonical(false), true);
- ASSERT_EQ(tcgetattr(m_pty.GetPrimaryFileDescriptor(), &terminfo), 0);
+ ASSERT_EQ(m_term.SetCanonical(false), true);
+ ASSERT_EQ(tcgetattr(m_fd, &terminfo), 0);
EXPECT_EQ(terminfo.c_lflag & ICANON, 0U);
}
TEST_F(TerminalTest, SaveRestoreRAII) {
struct termios orig_terminfo;
struct termios terminfo;
- ASSERT_EQ(tcgetattr(m_pty.GetPrimaryFileDescriptor(), &orig_terminfo), 0);
-
- Terminal term{m_pty.GetPrimaryFileDescriptor()};
+ ASSERT_EQ(tcgetattr(m_fd, &orig_terminfo), 0);
{
- TerminalState term_state{term};
+ TerminalState term_state{m_term};
terminfo = orig_terminfo;
// make an arbitrary change
@@ -85,11 +87,11 @@ TEST_F(TerminalTest, SaveRestoreRAII) {
cfsetospeed(&terminfo,
cfgetospeed(&orig_terminfo) == B9600 ? B4800 : B9600);
- ASSERT_EQ(tcsetattr(m_pty.GetPrimaryFileDescriptor(), TCSANOW, &terminfo),
+ ASSERT_EQ(tcsetattr(m_fd, TCSANOW, &terminfo),
0);
}
- ASSERT_EQ(tcgetattr(m_pty.GetPrimaryFileDescriptor(), &terminfo), 0);
+ ASSERT_EQ(tcgetattr(m_fd, &terminfo), 0);
ASSERT_EQ(memcmp(&terminfo, &orig_terminfo, sizeof(terminfo)), 0);
}
@@ -98,19 +100,18 @@ TEST_F(TerminalTest, SaveRestore) {
struct termios orig_terminfo;
struct termios terminfo;
- ASSERT_EQ(tcgetattr(m_pty.GetPrimaryFileDescriptor(), &orig_terminfo), 0);
+ ASSERT_EQ(tcgetattr(m_fd, &orig_terminfo), 0);
- Terminal term{m_pty.GetPrimaryFileDescriptor()};
- term_state.Save(term, false);
+ term_state.Save(m_term, false);
terminfo = orig_terminfo;
// make an arbitrary change
cfsetispeed(&terminfo, cfgetispeed(&orig_terminfo) == B9600 ? B4800 : B9600);
cfsetospeed(&terminfo, cfgetospeed(&orig_terminfo) == B9600 ? B4800 : B9600);
- ASSERT_EQ(tcsetattr(m_pty.GetPrimaryFileDescriptor(), TCSANOW, &terminfo), 0);
+ ASSERT_EQ(tcsetattr(m_fd, TCSANOW, &terminfo), 0);
term_state.Restore();
- ASSERT_EQ(tcgetattr(m_pty.GetPrimaryFileDescriptor(), &terminfo), 0);
+ ASSERT_EQ(tcgetattr(m_fd, &terminfo), 0);
ASSERT_EQ(memcmp(&terminfo, &orig_terminfo, sizeof(terminfo)), 0);
}
More information about the lldb-commits
mailing list