// File: 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 %rbp
movq %rsp, %rbp
subq $0x20, %rsp
callq 0x48e0
movl %eax, -0x20(%rbp)
leaq 0x4388(%rip), %rdi      # 0x931f
movl $0x1c200, %esi          # imm = 0x1C200
leaq 0x4387(%rip), %rdx      # 0x932a
callq 0x6a90
movq %rax, -0x8(%rbp)
cmpq $0x0, -0x8(%rbp)
setne %al
xorb $-0x1, %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %edi
leaq 0x436a(%rip), %rsi      # 0x932e
movl $0x8b, %edx
leaq 0x4934(%rip), %rcx      # 0x9904
leaq 0x4377(%rip), %r8       # 0x934e
movb $0x0, %al
callq 0x26e0
cmpl $0x0, %eax
jne 0x4fe8
callq 0x3290
jmp 0x4fea
leaq 0x4368(%rip), %rdi      # 0x9359
movl $0x1c200, %esi          # imm = 0x1C200
leaq 0x432d(%rip), %rdx      # 0x932a
callq 0x6a90
movq %rax, -0x10(%rbp)
cmpq $0x0, -0x10(%rbp)
setne %al
xorb $-0x1, %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %edi
leaq 0x4310(%rip), %rsi      # 0x932e
movl $0x8d, %edx
leaq 0x48da(%rip), %rcx      # 0x9904
leaq 0x4333(%rip), %r8       # 0x9364
movb $0x0, %al
callq 0x26e0
cmpl $0x0, %eax
jne 0x5042
callq 0x3290
jmp 0x5044
movq -0x8(%rbp), %rdi
leaq 0x44b2(%rip), %rsi      # 0x9501
movl $0x1, %edx
callq 0x68b0
movq -0x8(%rbp), %rdi
leaq 0x44de(%rip), %rsi      # 0x9542
movl $0x1, %edx
callq 0x68b0
movq -0x8(%rbp), %rdi
leaq 0x448a(%rip), %rsi      # 0x9503
movl $0x1, %edx
callq 0x68b0
movq -0x10(%rbp), %rdi
leaq -0x1a(%rbp), %rsi
movl $0xa, %edx
movl $0x64, %ecx
callq 0x7dd0
cmpq $0x2, %rax
sete %al
xorb $-0x1, %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %edi
leaq 0x427d(%rip), %rsi      # 0x932e
movl $0x92, %edx
leaq 0x4847(%rip), %rcx      # 0x9904
leaq 0x4441(%rip), %r8       # 0x9505
movb $0x0, %al
callq 0x26e0
cmpl $0x0, %eax
jne 0x50d5
callq 0x3290
jmp 0x50d7
jmp 0x50d9
leaq -0x1a(%rbp), %rdi
leaq 0x445d(%rip), %rsi      # 0x9541
callq 0x2200
cmpl $0x0, %eax
sete %al
xorb $-0x1, %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %edi
leaq 0x422f(%rip), %rsi      # 0x932e
movl $0x93, %edx
leaq 0x47f9(%rip), %rcx      # 0x9904
leaq 0x4432(%rip), %r8       # 0x9544
movb $0x0, %al
callq 0x26e0
cmpl $0x0, %eax
jne 0x5123
callq 0x3290
jmp 0x5125
movq -0x10(%rbp), %rdi
leaq 0x442e(%rip), %rsi      # 0x955e
movl $0x3, %edx
callq 0x68b0
movq -0x8(%rbp), %rdi
leaq -0x1a(%rbp), %rsi
movl $0xa, %edx
movl $0x64, %ecx
callq 0x7dd0
cmpq $0x2, %rax
sete %al
xorb $-0x1, %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %edi
leaq 0x41c6(%rip), %rsi      # 0x932e
movl $0x96, %edx
leaq 0x4790(%rip), %rcx      # 0x9904
leaq 0x43e7(%rip), %r8       # 0x9562
movb $0x0, %al
callq 0x26e0
cmpl $0x0, %eax
jne 0x518c
callq 0x3290
jmp 0x518e
jmp 0x5190
leaq -0x1a(%rbp), %rdi
leaq 0x4403(%rip), %rsi      # 0x959e
callq 0x2200
cmpl $0x0, %eax
sete %al
xorb $-0x1, %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %edi
leaq 0x4178(%rip), %rsi      # 0x932e
movl $0x97, %edx
leaq 0x4742(%rip), %rcx      # 0x9904
leaq 0x43d8(%rip), %r8       # 0x95a1
movb $0x0, %al
callq 0x26e0
cmpl $0x0, %eax
jne 0x51da
callq 0x3290
jmp 0x51dc
movq -0x10(%rbp), %rdi
leaq 0x43d4(%rip), %rsi      # 0x95bb
movl $0x2, %edx
callq 0x68b0
movq -0x8(%rbp), %rdi
leaq -0x1a(%rbp), %rsi
movl $0xa, %edx
movl $0x64, %ecx
callq 0x7dd0
cmpq $0x0, %rax
setl %al
xorb $-0x1, %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %edi
leaq 0x410f(%rip), %rsi      # 0x932e
movl $0x9a, %edx
leaq 0x46d9(%rip), %rcx      # 0x9904
leaq 0x438c(%rip), %r8       # 0x95be
movb $0x0, %al
callq 0x26e0
cmpl $0x0, %eax
jne 0x5243
callq 0x3290
jmp 0x5245
jmp 0x5247
leaq -0x1a(%rbp), %rdi
leaq 0x4369(%rip), %rsi      # 0x95bb
callq 0x2200
cmpl $0x0, %eax
sete %al
xorb $-0x1, %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %edi
leaq 0x40c1(%rip), %rsi      # 0x932e
movl $0x9b, %edx
leaq 0x468b(%rip), %rcx      # 0x9904
leaq 0x4379(%rip), %r8       # 0x95f9
movb $0x0, %al
callq 0x26e0
cmpl $0x0, %eax
jne 0x5291
callq 0x3290
jmp 0x5293
movq -0x8(%rbp), %rdi
callq 0x6a20
movq -0x10(%rbp), %rdi
callq 0x6a20
movl -0x20(%rbp), %edi
callq 0x4980
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)