// File: /workspace/github_cpp_makefile_star2_O1/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 %rbx
subq $0x10, %rsp
callq 0x4256
movl %eax, %ebx
leaq 0x2b53(%rip), %rdi      # 0x7347
leaq 0x2b57(%rip), %rdx      # 0x7352
movl $0x1c200, %esi          # imm = 0x1C200
callq 0x5b0d
movq %rax, %r14
xorl %edi, %edi
testq %rax, %rax
setne %dil
leaq 0x2b3e(%rip), %rsi      # 0x7356
leaq 0x310b(%rip), %rcx      # 0x792a
leaq 0x2b50(%rip), %r8       # 0x7376
movl $0x8b, %edx
xorl %eax, %eax
callq 0x28d6
testl %eax, %eax
je 0x4ab1
leaq 0x2b40(%rip), %rdi      # 0x7381
leaq 0x2b0a(%rip), %rdx      # 0x7352
movl $0x1c200, %esi          # imm = 0x1C200
callq 0x5b0d
movq %rax, %r15
xorl %edi, %edi
testq %rax, %rax
setne %dil
leaq 0x2af1(%rip), %rsi      # 0x7356
leaq 0x30be(%rip), %rcx      # 0x792a
leaq 0x2b19(%rip), %r8       # 0x738c
movl $0x8d, %edx
xorl %eax, %eax
callq 0x28d6
testl %eax, %eax
je 0x4ab1
leaq 0x2c9b(%rip), %rsi      # 0x7529
movl $0x1, %edx
movq %r14, %rdi
callq 0x59df
leaq 0x2cc8(%rip), %rsi      # 0x756a
movl $0x1, %edx
movq %r14, %rdi
callq 0x59df
leaq 0x2c75(%rip), %rsi      # 0x752b
movl $0x1, %edx
movq %r14, %rdi
callq 0x59df
leaq 0x6(%rsp), %rsi
movl $0x64, %ecx
movq %r15, %rdi
movl $0xa, %edx
callq 0x685d
xorl %edi, %edi
cmpq $0x2, %rax
sete %dil
leaq 0x2a6b(%rip), %rsi      # 0x7356
leaq 0x3038(%rip), %rcx      # 0x792a
leaq 0x2c34(%rip), %r8       # 0x752d
movl $0x92, %edx
xorl %eax, %eax
callq 0x28d6
testl %eax, %eax
je 0x4ab1
movzwl 0x6(%rsp), %eax
xorl $0x6261, %eax           # imm = 0x6261
movzbl 0x8(%rsp), %ecx
xorl %edi, %edi
orw %ax, %cx
sete %dil
leaq 0x2a2a(%rip), %rsi      # 0x7356
leaq 0x2ff7(%rip), %rcx      # 0x792a
leaq 0x2c32(%rip), %r8       # 0x756c
movl $0x93, %edx
xorl %eax, %eax
callq 0x28d6
testl %eax, %eax
je 0x4ab1
leaq 0x2c31(%rip), %rsi      # 0x7586
movl $0x3, %edx
movq %r15, %rdi
callq 0x59df
leaq 0x6(%rsp), %rsi
movl $0x64, %ecx
movq %r14, %rdi
movl $0xa, %edx
callq 0x685d
xorl %edi, %edi
cmpq $0x2, %rax
sete %dil
leaq 0x29cc(%rip), %rsi      # 0x7356
leaq 0x2f99(%rip), %rcx      # 0x792a
leaq 0x2bf2(%rip), %r8       # 0x758a
movl $0x96, %edx
xorl %eax, %eax
callq 0x28d6
testl %eax, %eax
je 0x4ab1
movzwl 0x6(%rsp), %eax
xorl $0x6463, %eax           # imm = 0x6463
movzbl 0x8(%rsp), %ecx
xorl %edi, %edi
orw %ax, %cx
sete %dil
leaq 0x298b(%rip), %rsi      # 0x7356
leaq 0x2f58(%rip), %rcx      # 0x792a
leaq 0x2bf0(%rip), %r8       # 0x75c9
movl $0x97, %edx
xorl %eax, %eax
callq 0x28d6
testl %eax, %eax
je 0x4ab1
leaq 0x2bef(%rip), %rsi      # 0x75e3
movl $0x2, %edx
movq %r15, %rdi
callq 0x59df
leaq 0x6(%rsp), %rsi
movl $0x64, %ecx
movq %r14, %rdi
movl $0xa, %edx
callq 0x685d
shrq $0x3f, %rax
leaq 0x2933(%rip), %rsi      # 0x7356
leaq 0x2f00(%rip), %rcx      # 0x792a
leaq 0x2bb5(%rip), %r8       # 0x75e6
movl %eax, %edi
movl $0x9a, %edx
xorl %eax, %eax
callq 0x28d6
testl %eax, %eax
je 0x4ab1
movzwl 0x6(%rsp), %eax
xorl $0x6665, %eax           # imm = 0x6665
movzbl 0x8(%rsp), %ecx
xorl %edi, %edi
orw %ax, %cx
sete %dil
leaq 0x28f4(%rip), %rsi      # 0x7356
leaq 0x2ec1(%rip), %rcx      # 0x792a
leaq 0x2bb1(%rip), %r8       # 0x7621
movl $0x9b, %edx
xorl %eax, %eax
callq 0x28d6
testl %eax, %eax
je 0x4ab1
movq %r14, %rdi
callq 0x5ad5
movq %r15, %rdi
callq 0x5ad5
movl %ebx, %edi
movl $0x1, %esi
callq 0x2270
movl %ebx, %edi
xorl %esi, %esi
xorl %edx, %edx
callq 0x22f0
addq $0x10, %rsp
popq %rbx
popq %r14
popq %r15
retq
callq 0x31a2