Compare commits
9 Commits
eadf7cde62
...
master
Author | SHA1 | Date | |
---|---|---|---|
66cc5c87d4 | |||
0b4d562ef9 | |||
42b7aab1ae | |||
e3b2eb0852 | |||
ebf0b0e442 | |||
3effb7caf5 | |||
27f25d2cea | |||
fdc1923211 | |||
cbed6c468f |
2
Makefile
2
Makefile
@ -24,7 +24,7 @@ all : $(NAME)
|
|||||||
|
|
||||||
test : $(NAME)
|
test : $(NAME)
|
||||||
$(CC) $(CFLAGS) test/test.c $(BUILDDIR)/$(NAME) -o $(BUILDDIR)/test
|
$(CC) $(CFLAGS) test/test.c $(BUILDDIR)/$(NAME) -o $(BUILDDIR)/test
|
||||||
$(BUILDDIR)/test
|
valgrind --leak-check=full $(BUILDDIR)/test
|
||||||
|
|
||||||
clean :
|
clean :
|
||||||
rm -rf $(OBJDIR)
|
rm -rf $(OBJDIR)
|
||||||
|
@ -3,14 +3,9 @@
|
|||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <aio.h>
|
#include <aio.h>
|
||||||
|
|
||||||
#include "./list.h"
|
|
||||||
|
|
||||||
char *ft_strcpy(char *dest, const char *src);
|
char *ft_strcpy(char *dest, const char *src);
|
||||||
size_t ft_strlen(const char *str);
|
size_t ft_strlen(const char *str);
|
||||||
int ft_strcmp( const char *first, const char *second);
|
int ft_strcmp( const char *first, const char *second);
|
||||||
ssize_t ft_write(int fd, const void *buf, size_t count);
|
ssize_t ft_write(int fd, const void *buf, size_t count);
|
||||||
char *ft_strdup(const char *s);
|
char *ft_strdup(const char *s);
|
||||||
ssize_t ft_read(int fildes, void *buf, size_t nbyte);
|
ssize_t ft_read(int fildes, void *buf, size_t nbyte);
|
||||||
|
|
||||||
int ft_list_size(t_list *begin_list);
|
|
||||||
void ft_list_push_front(t_list **begin_list, void *data);
|
|
@ -1,7 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
typedef struct s_list
|
|
||||||
{
|
|
||||||
void *data;
|
|
||||||
struct s_list *next;
|
|
||||||
} t_list;
|
|
@ -1,27 +0,0 @@
|
|||||||
extern malloc
|
|
||||||
|
|
||||||
section .text
|
|
||||||
global ft_list_push_front
|
|
||||||
ft_list_push_front:
|
|
||||||
|
|
||||||
push rdi
|
|
||||||
push rsi
|
|
||||||
|
|
||||||
mov rdi, 16
|
|
||||||
|
|
||||||
call malloc wrt ..plt
|
|
||||||
|
|
||||||
cmp rax, 0
|
|
||||||
je out
|
|
||||||
|
|
||||||
pop rsi
|
|
||||||
pop rdi
|
|
||||||
|
|
||||||
mov rdx, [rdi]
|
|
||||||
mov [rax + 0], rsi ; .data = arg#1
|
|
||||||
mov [rax + 8], rdx ; .next = *arg#0
|
|
||||||
|
|
||||||
mov [rdi], rax
|
|
||||||
|
|
||||||
out:
|
|
||||||
ret
|
|
@ -1,19 +0,0 @@
|
|||||||
section .text
|
|
||||||
global ft_list_size
|
|
||||||
|
|
||||||
ft_list_size:
|
|
||||||
xor rcx, rcx
|
|
||||||
|
|
||||||
loop:
|
|
||||||
cmp QWORD [rdi + 8], 0
|
|
||||||
je out
|
|
||||||
|
|
||||||
mov rdi, [rdi + 8]
|
|
||||||
|
|
||||||
inc rcx
|
|
||||||
|
|
||||||
jmp loop
|
|
||||||
|
|
||||||
out:
|
|
||||||
mov rax, rcx
|
|
||||||
ret
|
|
@ -15,6 +15,8 @@ section .text
|
|||||||
|
|
||||||
syscall_failed:
|
syscall_failed:
|
||||||
|
|
||||||
|
push rbx
|
||||||
|
|
||||||
neg rax
|
neg rax
|
||||||
mov rbx, rax
|
mov rbx, rax
|
||||||
|
|
||||||
@ -22,4 +24,7 @@ section .text
|
|||||||
|
|
||||||
mov [rax], rbx
|
mov [rax], rbx
|
||||||
mov rax, -1
|
mov rax, -1
|
||||||
|
|
||||||
|
pop rbx
|
||||||
|
|
||||||
ret
|
ret
|
@ -2,6 +2,8 @@ section .text
|
|||||||
global ft_strcmp
|
global ft_strcmp
|
||||||
|
|
||||||
ft_strcmp:
|
ft_strcmp:
|
||||||
|
push rbx
|
||||||
|
|
||||||
xor rcx, rcx
|
xor rcx, rcx
|
||||||
|
|
||||||
loop:
|
loop:
|
||||||
@ -20,4 +22,7 @@ section .text
|
|||||||
out:
|
out:
|
||||||
sub bl, dl
|
sub bl, dl
|
||||||
movsx rax, bl
|
movsx rax, bl
|
||||||
|
|
||||||
|
pop rbx
|
||||||
|
|
||||||
ret
|
ret
|
@ -5,10 +5,13 @@ extern ft_strcpy
|
|||||||
section .text
|
section .text
|
||||||
global ft_strdup
|
global ft_strdup
|
||||||
ft_strdup:
|
ft_strdup:
|
||||||
|
push rbx
|
||||||
|
|
||||||
call ft_strlen
|
call ft_strlen
|
||||||
|
|
||||||
mov rbx, rdi
|
mov rbx, rdi
|
||||||
mov rdi, rax
|
mov rdi, rax
|
||||||
|
add rdi, 1
|
||||||
|
|
||||||
call malloc wrt ..plt
|
call malloc wrt ..plt
|
||||||
|
|
||||||
@ -20,8 +23,13 @@ section .text
|
|||||||
|
|
||||||
call ft_strcpy
|
call ft_strcpy
|
||||||
|
|
||||||
|
pop rbx
|
||||||
|
|
||||||
ret
|
ret
|
||||||
|
|
||||||
error:
|
error:
|
||||||
xor rax, rax
|
xor rax, rax
|
||||||
|
|
||||||
|
pop rbx
|
||||||
|
|
||||||
ret
|
ret
|
@ -6,7 +6,9 @@ section .text
|
|||||||
loop:
|
loop:
|
||||||
cmp BYTE [rdi + rcx], 0
|
cmp BYTE [rdi + rcx], 0
|
||||||
je out
|
je out
|
||||||
|
|
||||||
inc rcx
|
inc rcx
|
||||||
|
|
||||||
jmp loop
|
jmp loop
|
||||||
out:
|
out:
|
||||||
mov rax, rcx
|
mov rax, rcx
|
@ -14,10 +14,15 @@ section .text
|
|||||||
|
|
||||||
syscall_failed:
|
syscall_failed:
|
||||||
|
|
||||||
|
push rbx
|
||||||
|
|
||||||
neg rax
|
neg rax
|
||||||
mov rbx, rax
|
mov rbx, rax
|
||||||
|
|
||||||
call __errno_location wrt ..plt
|
call __errno_location wrt ..plt
|
||||||
mov [rax], rbx
|
mov [rax], rbx
|
||||||
mov rax, -1
|
mov rax, -1
|
||||||
|
|
||||||
|
pop rbx
|
||||||
|
|
||||||
ret
|
ret
|
107
test/test.c
107
test/test.c
@ -1,7 +1,6 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include "../include/libasm.h"
|
#include "../headers/libasm.h"
|
||||||
#include "string.h"
|
#include "string.h"
|
||||||
#include "../include/list.h"
|
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
@ -75,90 +74,15 @@ void multiple_test_atoi_base(char *(*own_func)(char *, const char *), const char
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void destroy_list(t_list *root, void *(destroy_data)(void *))
|
void multiple_test_strdup(const char * const *values)
|
||||||
{
|
{
|
||||||
t_list *current = root;
|
char *tmp;
|
||||||
t_list *prev;
|
|
||||||
|
|
||||||
while (current != NULL)
|
for (size_t i = 0; values[i] != NULL; i++)
|
||||||
{
|
{
|
||||||
prev = current;
|
tmp = ft_strdup(values[i]);
|
||||||
if (current->data)
|
test_str(tmp, values[i]);
|
||||||
destroy_data(current->data);
|
free(tmp);
|
||||||
current = current->next;
|
|
||||||
free(prev);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
t_list *create_list(size_t len)
|
|
||||||
{
|
|
||||||
t_list *root;
|
|
||||||
t_list *current = root;
|
|
||||||
|
|
||||||
root = malloc(sizeof(t_list));
|
|
||||||
if (root == NULL)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
current = root;
|
|
||||||
for (size_t i = 0; i < len; i++)
|
|
||||||
{
|
|
||||||
current->next = malloc(sizeof(t_list));
|
|
||||||
current->data = (void *) i;
|
|
||||||
if (current->next == NULL)
|
|
||||||
{
|
|
||||||
destroy_list(current, NULL);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
current = current->next;
|
|
||||||
}
|
|
||||||
current->next = NULL;
|
|
||||||
return root;
|
|
||||||
}
|
|
||||||
|
|
||||||
#define nb_random_test 10
|
|
||||||
#define nb_specific_test 1
|
|
||||||
|
|
||||||
void multiple_test_list_size()
|
|
||||||
{
|
|
||||||
size_t len;
|
|
||||||
t_list *root;
|
|
||||||
size_t specific_size[nb_specific_test] = {0};
|
|
||||||
|
|
||||||
srand(time(NULL));
|
|
||||||
|
|
||||||
for (size_t i = 0; i < nb_random_test + nb_specific_test; i++)
|
|
||||||
{
|
|
||||||
len = i < nb_specific_test ? specific_size[i] : rand() % 100;
|
|
||||||
|
|
||||||
root = create_list(len);
|
|
||||||
if (root == NULL)
|
|
||||||
return;
|
|
||||||
test_int(len, ft_list_size(root));
|
|
||||||
printf("\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void multiple_test_push_front()
|
|
||||||
{
|
|
||||||
size_t len;
|
|
||||||
t_list *root;
|
|
||||||
|
|
||||||
srand(time(NULL));
|
|
||||||
|
|
||||||
for (size_t i = 0; i < nb_random_test; i++)
|
|
||||||
{
|
|
||||||
len = rand() % 100;
|
|
||||||
|
|
||||||
root = create_list(len);
|
|
||||||
if (root == NULL)
|
|
||||||
return;
|
|
||||||
ft_list_push_front(&root, (void *) 101);
|
|
||||||
printf("data: ");
|
|
||||||
test_size_t((size_t) root->data, 101);
|
|
||||||
printf(" data-next: ");
|
|
||||||
test_size_t((size_t) root->next->data, 0);
|
|
||||||
printf(" list-size: ");
|
|
||||||
test_int(len + 1, ft_list_size(root));
|
|
||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -180,19 +104,8 @@ int main()
|
|||||||
multiple_test_strcpy(ft_strcpy, strcpy_tests);
|
multiple_test_strcpy(ft_strcpy, strcpy_tests);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
|
||||||
ft_write(1, "bozo\n", 5);
|
printf("STRDUP\n");
|
||||||
printf("%s\n", ft_strdup("sdsfsd"));
|
const char *strdup_tests[] = {"yo", "", "bonjour", "co\0fgf", NULL};
|
||||||
/*
|
multiple_test_strdup(strdup_tests);
|
||||||
printf("ATOI_BASE\n");
|
|
||||||
const char *atoi_base_tests[][2] = {{"0123", ""}, {"0123", "0"}, {"0123", "0123456789"}, {"bonjour", "bonjour"}, {"", ""}, {"bonjour", "salut"}, {"co\0fgf", "co\0fgf"}, NULL};
|
|
||||||
multiple_test_int_2(strcmp, ft_strcmp, strcmp_tests);
|
|
||||||
printf("\n");*/
|
|
||||||
|
|
||||||
printf("FT_LIST_SIZE\n");
|
|
||||||
multiple_test_list_size();
|
|
||||||
printf("\n");
|
|
||||||
|
|
||||||
printf("FT_LIST_PUSH_FRONT\n");
|
|
||||||
multiple_test_push_front();
|
|
||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
Reference in New Issue
Block a user