// File: /workspace/github_cpp_makefile_star2_O2/AndreRenaud[P]simple_uart/simple_uart_test.c
// Function: test_read_line
void test_read_line(void)
{
    struct simple_uart *u1, *u2;
    char buffer[10];
    pid_t pid;

    pid = setup_loopback();

    u1 = simple_uart_open(UART_LOOPBACK_1, 115200, "8N1");
    TEST_ASSERT(u1 != NULL);
    u2 = simple_uart_open(UART_LOOPBACK_2, 115200, "8N1");
    TEST_ASSERT(u2 != NULL);

    simple_uart_write(u1, "a", 1);
    simple_uart_write(u1, "b", 1);
    simple_uart_write(u1, "\r", 1);
    TEST_ASSERT(simple_uart_read_line(u2, buffer, sizeof(buffer), 100) == 2);
    TEST_ASSERT(strcmp(buffer, "ab") == 0);

    simple_uart_write(u2, "cd\n", 3);
    TEST_ASSERT(simple_uart_read_line(u1, buffer, sizeof(buffer), 100) == 2);
    TEST_ASSERT(strcmp(buffer, "cd") == 0);

    simple_uart_write(u2, "ef", 2);
    TEST_ASSERT(simple_uart_read_line(u1, buffer, sizeof(buffer), 100) < 0);
    TEST_ASSERT(strcmp(buffer, "ef") == 0);

    simple_uart_close(u1);
    simple_uart_close(u2);
    shutdown_loopback(pid);
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x18, %rsp
callq 0x3e43
movl %eax, %ebx
leaq 0x2fa6(%rip), %rdi      # 0x7347
leaq 0x2faa(%rip), %rdx      # 0x7352
movl $0x1c200, %esi          # imm = 0x1C200
callq 0x54e4
movq %rax, %r14
xorl %edi, %edi
testq %rax, %rax
setne %dil
leaq 0x2f91(%rip), %rsi      # 0x7356
leaq 0x355b(%rip), %rcx      # 0x7927
leaq 0x2fa3(%rip), %r8       # 0x7376
movl $0x8b, %edx
xorl %eax, %eax
callq 0x269a
testl %eax, %eax
je 0x464a
leaq 0x2f93(%rip), %rdi      # 0x7381
leaq 0x2f5d(%rip), %rdx      # 0x7352
movl $0x1c200, %esi          # imm = 0x1C200
callq 0x54e4
movq %rax, %r15
xorl %edi, %edi
testq %rax, %rax
setne %dil
leaq 0x2f44(%rip), %rsi      # 0x7356
leaq 0x350e(%rip), %rcx      # 0x7927
leaq 0x2f6c(%rip), %r8       # 0x738c
movl $0x8d, %edx
xorl %eax, %eax
callq 0x269a
testl %eax, %eax
je 0x464a
leaq 0x30ee(%rip), %rsi      # 0x7529
pushq $0x1
popq %r12
movq %r14, %rdi
movq %r12, %rdx
callq 0x53e0
leaq 0x3119(%rip), %rsi      # 0x756a
movq %r14, %rdi
movq %r12, %rdx
callq 0x53e0
leaq 0x30c8(%rip), %rsi      # 0x752b
movq %r14, %rdi
movq %r12, %rdx
callq 0x53e0
leaq 0xe(%rsp), %rsi
pushq $0xa
popq %rdx
pushq $0x64
popq %rcx
movq %r15, %rdi
callq 0x6097
xorl %edi, %edi
cmpq $0x2, %rax
sete %dil
leaq 0x2ec4(%rip), %rsi      # 0x7356
leaq 0x348e(%rip), %rcx      # 0x7927
leaq 0x308d(%rip), %r8       # 0x752d
movl $0x92, %edx
xorl %eax, %eax
callq 0x269a
testl %eax, %eax
je 0x464a
leaq 0x30ae(%rip), %rsi      # 0x7569
leaq 0xe(%rsp), %rdi
pushq $0x3
popq %rdx
callq 0x22c0
xorl %edi, %edi
testl %eax, %eax
sete %dil
leaq 0x2e7f(%rip), %rsi      # 0x7356
leaq 0x3449(%rip), %rcx      # 0x7927
leaq 0x3087(%rip), %r8       # 0x756c
movl $0x93, %edx
xorl %eax, %eax
callq 0x269a
testl %eax, %eax
je 0x464a
leaq 0x3086(%rip), %rsi      # 0x7586
pushq $0x3
popq %rdx
movq %r15, %rdi
callq 0x53e0
leaq 0xe(%rsp), %rsi
pushq $0xa
popq %rdx
pushq $0x64
popq %rcx
movq %r14, %rdi
callq 0x6097
xorl %edi, %edi
cmpq $0x2, %rax
sete %dil
leaq 0x2e27(%rip), %rsi      # 0x7356
leaq 0x33f1(%rip), %rcx      # 0x7927
leaq 0x304d(%rip), %r8       # 0x758a
movl $0x96, %edx
xorl %eax, %eax
callq 0x269a
testl %eax, %eax
je 0x464a
leaq 0x306e(%rip), %rsi      # 0x75c6
leaq 0xe(%rsp), %rdi
pushq $0x3
popq %rdx
callq 0x22c0
xorl %edi, %edi
testl %eax, %eax
sete %dil
leaq 0x2de2(%rip), %rsi      # 0x7356
leaq 0x33ac(%rip), %rcx      # 0x7927
leaq 0x3047(%rip), %r8       # 0x75c9
movl $0x97, %edx
xorl %eax, %eax
callq 0x269a
testl %eax, %eax
je 0x464a
leaq 0x3046(%rip), %rsi      # 0x75e3
pushq $0x2
popq %rdx
movq %r15, %rdi
callq 0x53e0
leaq 0xe(%rsp), %rsi
pushq $0xa
popq %rdx
pushq $0x64
popq %rcx
movq %r14, %rdi
callq 0x6097
shrq $0x3f, %rax
leaq 0x2d90(%rip), %rsi      # 0x7356
leaq 0x335a(%rip), %rcx      # 0x7927
leaq 0x3012(%rip), %r8       # 0x75e6
movl %eax, %edi
movl $0x9a, %edx
xorl %eax, %eax
callq 0x269a
testl %eax, %eax
je 0x464a
leaq 0x2ff6(%rip), %rsi      # 0x75e3
leaq 0xe(%rsp), %rdi
pushq $0x3
popq %rdx
callq 0x22c0
xorl %edi, %edi
testl %eax, %eax
sete %dil
leaq 0x2d4d(%rip), %rsi      # 0x7356
leaq 0x3317(%rip), %rcx      # 0x7927
leaq 0x300a(%rip), %r8       # 0x7621
movl $0x9b, %edx
xorl %eax, %eax
callq 0x269a
testl %eax, %eax
je 0x464a
movq %r14, %rdi
callq 0x54b1
movq %r15, %rdi
callq 0x54b1
movl %ebx, %edi
callq 0x3eba
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
callq 0x2f01