// File: AndreRenaud[P]simple_uart/simple_uart_test.c
// Function: test_loopback
void test_loopback(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);

    TEST_ASSERT(simple_uart_write(u1, "foo", 3) == 3);
    usleep(1000);
    TEST_ASSERT(simple_uart_read(u2, buffer, sizeof(buffer)) == 3);
    TEST_ASSERT(memcmp(buffer, "foo", 3) == 0);

    TEST_ASSERT(simple_uart_write(u2, "fnord", 5) == 5);
    usleep(1000);
    TEST_ASSERT(simple_uart_read(u1, buffer, sizeof(buffer)) == 5);
    TEST_ASSERT(memcmp(buffer, "fnord", 5) == 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 0x4958(%rip), %rdi      # 0x931f
movl $0x1c200, %esi          # imm = 0x1C200
leaq 0x4957(%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 0x493a(%rip), %rsi      # 0x932e
movl $0x50, %edx
leaq 0x4f04(%rip), %rcx      # 0x9904
leaq 0x4947(%rip), %r8       # 0x934e
movb $0x0, %al
callq 0x26e0
cmpl $0x0, %eax
jne 0x4a18
callq 0x3290
jmp 0x4a1a
leaq 0x4938(%rip), %rdi      # 0x9359
movl $0x1c200, %esi          # imm = 0x1C200
leaq 0x48fd(%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 0x48e0(%rip), %rsi      # 0x932e
movl $0x52, %edx
leaq 0x4eaa(%rip), %rcx      # 0x9904
leaq 0x4903(%rip), %r8       # 0x9364
movb $0x0, %al
callq 0x26e0
cmpl $0x0, %eax
jne 0x4a72
callq 0x3290
jmp 0x4a74
jmp 0x4a76
movq -0x8(%rbp), %rdi
leaq 0x48ee(%rip), %rsi      # 0x936f
movl $0x3, %edx
callq 0x68b0
cmpq $0x3, %rax
sete %al
xorb $-0x1, %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %edi
leaq 0x488c(%rip), %rsi      # 0x932e
movl $0x54, %edx
leaq 0x4e56(%rip), %rcx      # 0x9904
leaq 0x48be(%rip), %r8       # 0x9373
movb $0x0, %al
callq 0x26e0
cmpl $0x0, %eax
jne 0x4ac6
callq 0x3290
jmp 0x4ac8
movl $0x3e8, %edi            # imm = 0x3E8
callq 0x23e0
movq -0x10(%rbp), %rdi
leaq -0x1a(%rbp), %rsi
movl $0xa, %edx
callq 0x6600
cmpq $0x3, %rax
sete %al
xorb $-0x1, %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %edi
leaq 0x4833(%rip), %rsi      # 0x932e
movl $0x56, %edx
leaq 0x4dfd(%rip), %rcx      # 0x9904
leaq 0x488a(%rip), %r8       # 0x9398
movb $0x0, %al
callq 0x26e0
cmpl $0x0, %eax
jne 0x4b1f
callq 0x3290
jmp 0x4b21
jmp 0x4b23
leaq -0x1a(%rbp), %rdi
leaq 0x4841(%rip), %rsi      # 0x936f
movl $0x3, %edx
callq 0x21d0
cmpl $0x0, %eax
sete %al
xorb $-0x1, %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %edi
leaq 0x47e0(%rip), %rsi      # 0x932e
movl $0x57, %edx
leaq 0x4daa(%rip), %rcx      # 0x9904
leaq 0x4869(%rip), %r8       # 0x93ca
movb $0x0, %al
callq 0x26e0
cmpl $0x0, %eax
jne 0x4b72
callq 0x3290
jmp 0x4b74
jmp 0x4b76
movq -0x10(%rbp), %rdi
leaq 0x4867(%rip), %rsi      # 0x93e8
movl $0x5, %edx
callq 0x68b0
cmpq $0x5, %rax
sete %al
xorb $-0x1, %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %edi
leaq 0x478c(%rip), %rsi      # 0x932e
movl $0x59, %edx
leaq 0x4d56(%rip), %rcx      # 0x9904
leaq 0x4839(%rip), %r8       # 0x93ee
movb $0x0, %al
callq 0x26e0
cmpl $0x0, %eax
jne 0x4bc6
callq 0x3290
jmp 0x4bc8
movl $0x3e8, %edi            # imm = 0x3E8
callq 0x23e0
movq -0x8(%rbp), %rdi
leaq -0x1a(%rbp), %rsi
movl $0xa, %edx
callq 0x6600
cmpq $0x5, %rax
sete %al
xorb $-0x1, %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %edi
leaq 0x4733(%rip), %rsi      # 0x932e
movl $0x5b, %edx
leaq 0x4cfd(%rip), %rcx      # 0x9904
leaq 0x4807(%rip), %r8       # 0x9415
movb $0x0, %al
callq 0x26e0
cmpl $0x0, %eax
jne 0x4c1f
callq 0x3290
jmp 0x4c21
jmp 0x4c23
leaq -0x1a(%rbp), %rdi
leaq 0x47ba(%rip), %rsi      # 0x93e8
movl $0x5, %edx
callq 0x21d0
cmpl $0x0, %eax
sete %al
xorb $-0x1, %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %edi
leaq 0x46e0(%rip), %rsi      # 0x932e
movl $0x5c, %edx
leaq 0x4caa(%rip), %rcx      # 0x9904
leaq 0x47e6(%rip), %r8       # 0x9447
movb $0x0, %al
callq 0x26e0
cmpl $0x0, %eax
jne 0x4c72
callq 0x3290
jmp 0x4c74
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)