// File: /workspace/github_c_makefile_star2_O0/deepika9294[P]Threading-Library/one-one/test/methods.c
// Function: main
int main() {

    //for getting return values
    void *tret;
    signal(SIGUSR2, signal_handler);

    printf("\n\n-----------------ALL THE METHODS TESTING (CREATE, JOIN, EXIT, KILL)--------------\n\n");
	dthread_init();

	int c1 = dthread_create( &t1[0], add , NULL);
    int j1 = dthread_join(t1[0], &tret);
    if( c1 == 0 && j1 == 0 ) {
        check = testing((intptr_t)tret, 100);
        if(check == 0) {
            printf(RED "**FAILED**: Addition test with create and join return value\n" NONE);
        }
        else {
            printf(GREEN "**PASSED**: Addition test with create and join return value\n" NONE);
        }
    }
    else {
        printf("*****Issue in creating or joining thread *****\n");
    }

    c1 = dthread_create( &t1[1], add , NULL);
    j1 = dthread_join(25, &tret);
    if(c1 == 0) {
       check = testing(j1,ESRCH);
       if(check == 0) {
            printf(RED "**FAILED**: Joining an invalid thread test\n" NONE);
        }
        else {
            printf(GREEN "**PASSED**: Joining an invalid thread test\n" NONE);
        }
    }

    j1 = dthread_join(t1[0], NULL);
    check = testing(j1, EINVAL);
    if(check == 0) {
        printf(RED "**FAILED**: Joining on already joined thread test\n" NONE);
    }
    else {
        printf(GREEN "**PASSED**: Joining on already joined thread test\n" NONE);
    }


    c1 = dthread_create( &t1[2], deadlock , NULL);

    
    c1 = dthread_create( &t1[3], exit_test, NULL);
    j1 = dthread_join(t1[3], &tret);

    if(c1 == 0) {
        check = testing((intptr_t)tret, 100);
        if(check == 0) {
            printf(RED "**FAILED**: Thread exit test with retval\n" NONE);
        }
        else {
            printf(GREEN "**PASSED**: Thread exit test with retval\n" NONE);
        }
    }
    
    c1 = dthread_create( &t1[4], exit_control, NULL);
    j1 = dthread_join(t1[4], &tret);
    if(c1 == 0) {
        check = testing(counter, 1);
        if(check == 0) {
            printf(RED "**FAILED**: Thread exit test, i.e rest of the instructions are not executed\n" NONE);
        }
        else {
            printf(GREEN "**PASSED**: Thread exit test, i.e rest of the instructions are not executed\n" NONE);
        }
    }

    c1 = dthread_create( &t1[8], sig_loop, NULL);
    int s = dthread_kill(t1[8], SIGUSR2);
    dthread_join(t1[8],&tret);

    if(c1 == 0) {
        check = testing(run, 0);
        if(check == 0) {
            printf(RED "**FAILED**: Signal Handler test case for infinite loop\n" NONE);
        }
        else {
            printf(GREEN "**PASSED**: Signal Handler test case for infinite loop\n" NONE);
        }
    }

    c1 = dthread_create( &t1[5], looping, NULL);
    // j1 = dthread_join(t1[5], &tret);
    int k = dthread_kill(t1[5], -20);
    if(c1 == 0) {
        check = testing(k, EINVAL);
        if(check == 0) {
            printf(RED "**FAILED**: Invalid Signal Test\n" NONE);
        }
        else {
            printf(GREEN "**PASSED**: Invalid Signal Test\n" NONE);
        }
    }
    k = dthread_kill(34, SIGUSR1);
    if(c1 == 0) {
        check = testing(k, ESRCH);
        if(check == 0) {
            printf(RED "**FAILED**: Thread kill test on invalid thread\n" NONE);
        }
        else {
            printf(GREEN "**PASSED**: Thread kill test on invalid thread\n" NONE);
        }
    }
    k = dthread_kill(t1[5], SIGTSTP);
    
    if(c1 == 0) {
        check = testing(k, 0);
        if(check == 0) {
            printf(RED "**FAILED**: Valid Signal Test : SIGTSTP\n" NONE);
        }
        else {
            printf(GREEN "**PASSED**: Valid Signal Test : SIGTSTP\n" NONE);
        }
    }

    c1 = dthread_create( &t1[6], cont, NULL);
    //stopping the thread
    k = dthread_kill(t1[6], SIGTSTP);
    //restarting again
    int k2 = dthread_kill(t1[6], SIGCONT);
    sleep(1);
    if(c1 == 0) {
        check = testing(signal_counter, 1);
        if(check == 0) {
            printf(RED "**FAILED**: SIGCONT handling test\n" NONE);
        }
        else {
            printf(GREEN "**PASSED**: SIGCONT handling test\n" NONE);
        }
    }
    j1 = dthread_join(t1[5], &tret);
    j1 = dthread_join(t1[6], &tret);

    c1 = dthread_create( &t1[7], square, (void *)(intptr_t)(4));
    j1 = dthread_join(t1[7], &tret);
    if(c1 == 0 && j1 == 0) {
        check = testing((intptr_t)tret, 16);
        if(check == 0) {
            printf(RED "**FAILED**: Creating threads with args and join return value test\n" NONE);
        }
        else {
            printf(GREEN "**PASSED**: Creating threads with args and join return value test\n" NONE);
        }
    }
    printf("\n--------------------------------EXITING METHODS TEST--------------------------------\n\n");
    
    dthread_exit(NULL);
    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movl $0x0, -0x4(%rbp)
movl $0xc, %edi
leaq -0x3b(%rip), %rsi       # 0x1d20
callq 0x1090
leaq 0x1334(%rip), %rdi      # 0x309b
movb $0x0, %al
callq 0x1080
callq 0x1210
leaq 0x3356(%rip), %rdi      # 0x50d0
leaq -0x1c1(%rip), %rsi      # 0x1bc0
xorl %eax, %eax
movl %eax, %edx
callq 0x1380
movl %eax, -0x14(%rbp)
movq 0x333c(%rip), %rdi      # 0x50d0
leaq -0x10(%rbp), %rsi
callq 0x15e0
movl %eax, -0x18(%rbp)
cmpl $0x0, -0x14(%rbp)
jne 0x1deb
cmpl $0x0, -0x18(%rbp)
jne 0x1deb
movq -0x10(%rbp), %rax
movl %eax, %edi
movl $0x64, %esi
callq 0x1b90
movl %eax, 0x335e(%rip)      # 0x5120
cmpl $0x0, 0x3357(%rip)      # 0x5120
jne 0x1ddb
leaq 0x131f(%rip), %rdi      # 0x30f1
movb $0x0, %al
callq 0x1080
jmp 0x1de9
leaq 0x1359(%rip), %rdi      # 0x313b
movb $0x0, %al
callq 0x1080
jmp 0x1df9
leaq 0x1393(%rip), %rdi      # 0x3185
movb $0x0, %al
callq 0x1080
leaq 0x32d0(%rip), %rdi      # 0x50d0
addq $0x8, %rdi
leaq -0x24b(%rip), %rsi      # 0x1bc0
xorl %eax, %eax
movl %eax, %edx
callq 0x1380
movl %eax, -0x14(%rbp)
movl $0x19, %edi
leaq -0x10(%rbp), %rsi
callq 0x15e0
movl %eax, -0x18(%rbp)
cmpl $0x0, -0x14(%rbp)
jne 0x1e6a
movl -0x18(%rbp), %edi
movl $0x3, %esi
callq 0x1b90
movl %eax, 0x32df(%rip)      # 0x5120
cmpl $0x0, 0x32d8(%rip)      # 0x5120
jne 0x1e5a
leaq 0x1364(%rip), %rdi      # 0x31b5
movb $0x0, %al
callq 0x1080
jmp 0x1e68
leaq 0x138d(%rip), %rdi      # 0x31ee
movb $0x0, %al
callq 0x1080
jmp 0x1e6a
movq 0x325f(%rip), %rdi      # 0x50d0
xorl %eax, %eax
movl %eax, %esi
callq 0x15e0
movl %eax, -0x18(%rbp)
movl -0x18(%rbp), %edi
movl $0x16, %esi
callq 0x1b90
movl %eax, 0x3290(%rip)      # 0x5120
cmpl $0x0, 0x3289(%rip)      # 0x5120
jne 0x1ea9
leaq 0x1387(%rip), %rdi      # 0x3227
movb $0x0, %al
callq 0x1080
jmp 0x1eb7
leaq 0x13b7(%rip), %rdi      # 0x3267
movb $0x0, %al
callq 0x1080
leaq 0x3212(%rip), %rdi      # 0x50d0
addq $0x10, %rdi
leaq -0x2c9(%rip), %rsi      # 0x1c00
xorl %eax, %eax
movl %eax, %edx
callq 0x1380
movl %eax, -0x14(%rbp)
leaq 0x31f4(%rip), %rdi      # 0x50d0
addq $0x18, %rdi
leaq -0x277(%rip), %rsi      # 0x1c70
xorl %eax, %eax
movl %eax, %edx
callq 0x1380
movl %eax, -0x14(%rbp)
movq 0x31ee(%rip), %rdi      # 0x50e8
leaq -0x10(%rbp), %rsi
callq 0x15e0
movl %eax, -0x18(%rbp)
cmpl $0x0, -0x14(%rbp)
jne 0x1f4b
movq -0x10(%rbp), %rax
movl %eax, %edi
movl $0x64, %esi
callq 0x1b90
movl %eax, 0x31fe(%rip)      # 0x5120
cmpl $0x0, 0x31f7(%rip)      # 0x5120
jne 0x1f3b
leaq 0x1375(%rip), %rdi      # 0x32a7
movb $0x0, %al
callq 0x1080
jmp 0x1f49
leaq 0x139c(%rip), %rdi      # 0x32de
movb $0x0, %al
callq 0x1080
jmp 0x1f4b
leaq 0x317e(%rip), %rdi      # 0x50d0
addq $0x20, %rdi
leaq -0x2cd(%rip), %rsi      # 0x1c90
xorl %eax, %eax
movl %eax, %edx
callq 0x1380
movl %eax, -0x14(%rbp)
movq 0x3180(%rip), %rdi      # 0x50f0
leaq -0x10(%rbp), %rsi
callq 0x15e0
movl %eax, -0x18(%rbp)
cmpl $0x0, -0x14(%rbp)
jne 0x1fc1
movl 0x319c(%rip), %edi      # 0x5124
movl $0x1, %esi
callq 0x1b90
movl %eax, 0x3188(%rip)      # 0x5120
cmpl $0x0, 0x3181(%rip)      # 0x5120
jne 0x1fb1
leaq 0x136d(%rip), %rdi      # 0x3315
movb $0x0, %al
callq 0x1080
jmp 0x1fbf
leaq 0x13b7(%rip), %rdi      # 0x336f
movb $0x0, %al
callq 0x1080
jmp 0x1fc1
leaq 0x3108(%rip), %rdi      # 0x50d0
addq $0x40, %rdi
leaq -0x2d3(%rip), %rsi      # 0x1d00
xorl %eax, %eax
movl %eax, %edx
callq 0x1380
movl %eax, -0x14(%rbp)
movq 0x312a(%rip), %rdi      # 0x5110
movl $0xc, %esi
callq 0x16d0
movl %eax, -0x1c(%rbp)
movq 0x3116(%rip), %rdi      # 0x5110
leaq -0x10(%rbp), %rsi
callq 0x15e0
cmpl $0x0, -0x14(%rbp)
jne 0x2045
movl 0x30b1(%rip), %edi      # 0x50c0
xorl %esi, %esi
callq 0x1b90
movl %eax, 0x3104(%rip)      # 0x5120
cmpl $0x0, 0x30fd(%rip)      # 0x5120
jne 0x2035
leaq 0x139d(%rip), %rdi      # 0x33c9
movb $0x0, %al
callq 0x1080
jmp 0x2043
leaq 0x13d2(%rip), %rdi      # 0x340e
movb $0x0, %al
callq 0x1080
jmp 0x2045
leaq 0x3084(%rip), %rdi      # 0x50d0
addq $0x28, %rdi
leaq -0x387(%rip), %rsi      # 0x1cd0
xorl %eax, %eax
movl %eax, %edx
callq 0x1380
movl %eax, -0x14(%rbp)
movq 0x308e(%rip), %rdi      # 0x50f8
movl $0xffffffec, %esi       # imm = 0xFFFFFFEC
callq 0x16d0
movl %eax, -0x20(%rbp)
cmpl $0x0, -0x14(%rbp)
jne 0x20b9
movl -0x20(%rbp), %edi
movl $0x16, %esi
callq 0x1b90
movl %eax, 0x3090(%rip)      # 0x5120
cmpl $0x0, 0x3089(%rip)      # 0x5120
jne 0x20a9
leaq 0x13b3(%rip), %rdi      # 0x3453
movb $0x0, %al
callq 0x1080
jmp 0x20b7
leaq 0x13d1(%rip), %rdi      # 0x3481
movb $0x0, %al
callq 0x1080
jmp 0x20b9
movl $0x22, %edi
movl $0xa, %esi
callq 0x16d0
movl %eax, -0x20(%rbp)
cmpl $0x0, -0x14(%rbp)
jne 0x210d
movl -0x20(%rbp), %edi
movl $0x3, %esi
callq 0x1b90
movl %eax, 0x303c(%rip)      # 0x5120
cmpl $0x0, 0x3035(%rip)      # 0x5120
jne 0x20fd
leaq 0x13bb(%rip), %rdi      # 0x34af
movb $0x0, %al
callq 0x1080
jmp 0x210b
leaq 0x13e8(%rip), %rdi      # 0x34ec
movb $0x0, %al
callq 0x1080
jmp 0x210d
movq 0x2fe4(%rip), %rdi      # 0x50f8
movl $0x14, %esi
callq 0x16d0
movl %eax, -0x20(%rbp)
cmpl $0x0, -0x14(%rbp)
jne 0x2160
movl -0x20(%rbp), %edi
xorl %esi, %esi
callq 0x1b90
movl %eax, 0x2fe9(%rip)      # 0x5120
cmpl $0x0, 0x2fe2(%rip)      # 0x5120
jne 0x2150
leaq 0x13e2(%rip), %rdi      # 0x3529
movb $0x0, %al
callq 0x1080
jmp 0x215e
leaq 0x1408(%rip), %rdi      # 0x355f
movb $0x0, %al
callq 0x1080
jmp 0x2160
leaq 0x2f69(%rip), %rdi      # 0x50d0
addq $0x30, %rdi
leaq -0x492(%rip), %rsi      # 0x1ce0
xorl %eax, %eax
movl %eax, %edx
callq 0x1380
movl %eax, -0x14(%rbp)
movq 0x2f7b(%rip), %rdi      # 0x5100
movl $0x14, %esi
callq 0x16d0
movl %eax, -0x20(%rbp)
movq 0x2f67(%rip), %rdi      # 0x5100
movl $0x12, %esi
callq 0x16d0
movl %eax, -0x24(%rbp)
movl $0x1, %edi
callq 0x1100
cmpl $0x0, -0x14(%rbp)
jne 0x21f5
movl 0x2f6c(%rip), %edi      # 0x5128
movl $0x1, %esi
callq 0x1b90
movl %eax, 0x2f54(%rip)      # 0x5120
cmpl $0x0, 0x2f4d(%rip)      # 0x5120
jne 0x21e5
leaq 0x13b9(%rip), %rdi      # 0x3595
movb $0x0, %al
callq 0x1080
jmp 0x21f3
leaq 0x13d9(%rip), %rdi      # 0x35c5
movb $0x0, %al
callq 0x1080
jmp 0x21f5
movq 0x2efc(%rip), %rdi      # 0x50f8
leaq -0x10(%rbp), %rsi
callq 0x15e0
movl %eax, -0x18(%rbp)
movq 0x2ef1(%rip), %rdi      # 0x5100
leaq -0x10(%rbp), %rsi
callq 0x15e0
movl %eax, -0x18(%rbp)
leaq 0x2eae(%rip), %rdi      # 0x50d0
addq $0x38, %rdi
leaq -0x64d(%rip), %rsi      # 0x1be0
movl $0x4, %edx
callq 0x1380
movl %eax, -0x14(%rbp)
movq 0x2ec7(%rip), %rdi      # 0x5108
leaq -0x10(%rbp), %rsi
callq 0x15e0
movl %eax, -0x18(%rbp)
cmpl $0x0, -0x14(%rbp)
jne 0x2298
cmpl $0x0, -0x18(%rbp)
jne 0x2298
movq -0x10(%rbp), %rax
movl %eax, %edi
movl $0x10, %esi
callq 0x1b90
movl %eax, 0x2eb1(%rip)      # 0x5120
cmpl $0x0, 0x2eaa(%rip)      # 0x5120
jne 0x2288
leaq 0x1376(%rip), %rdi      # 0x35f5
movb $0x0, %al
callq 0x1080
jmp 0x2296
leaq 0x13b6(%rip), %rdi      # 0x3645
movb $0x0, %al
callq 0x1080
jmp 0x2298
leaq 0x13f6(%rip), %rdi      # 0x3695
movb $0x0, %al
callq 0x1080
xorl %eax, %eax
movl %eax, %edi
callq 0x14e0
xorl %eax, %eax
addq $0x30, %rsp
popq %rbp
retq