Présentation par Loïc BRANSTETT
Le 17/04/2019
Sommaire
Présentation du projet
minishell2 est one step closer to the 42sh...
Organisation
Architecture
Récupération d'un input
Découpage par mots
Découpage par séparateur
Évaluation des blocs de niveau 1
Initialization
Attente de la fin des processus
Évaluation des blocs de niveau 2
Libération de la mémoire et affichage du prompt
Architecture
/* FUNCTIONS */
int sh_funcs_eval(sh_t *sh, cmd_pipe_t *pipe);
int sh_func_exit(sh_t *sh, sstring_t *argv);
int sh_func_cd(sh_t *sh, sstring_t *argv);
int sh_func_env(sh_t *sh, sstring_t *argv);
int sh_func_setenv(sh_t *sh, sstring_t *argv);
int sh_func_unsetenv(sh_t *sh, sstring_t *argv);
int sh_func_which(sh_t *sh, sstring_t *argv);
int sh_func_builtins(sh_t *sh, sstring_t *argv);
/* UTILS EXEC */
int sh_cmd_expand_double_redirect(char *endval, int pfd[2]);
int sh_dup_openw(char *path, int flags);
int sh_dup_openr(char *path);
int sh_dup(int fdin, int fdout);
Tests automatisés
[===] Synthèse: Testés: 82 | Validés: 82 | Échoués: 0 | Plantages: 0
sh_cmd: 16 tests
sh_sstring: 13 tests
utils: 13 tests
sh_eval: 12 tests
sh_env: 10 tests
funcs_env: 5 tests
sh_binary: 4 tests
funcs_sys: 3 tests
sh: 3 tests
signals: 3 tests
Tests automatisés
#include <criterion.h>
#include "my_sh.h"
static void redirect_all_std(void)
{
cr_redirect_stdout();
cr_redirect_stderr();
}
Test(sh_binary, sh_find_binary_location, .init=redirect_all_std)
{
char *env[] = {
"TOTO=test",
"PATH=/bin",
NULL
};
env_t *env_list = sh_env_list_parse(env);
cr_assert_neq(env_list, NULL);
cr_assert_neq(env_list->next, NULL);
cr_assert_str_eq(sh_find_binary_location(env_list, "ls"), "/bin/ls");
cr_assert_eq(sh_find_binary_location(env_list, "lsss"), NULL);
cr_assert_eq(sh_find_binary_location(env_list, "blablabla"), NULL);
}
Tests automatisés
#include <criterion.h>
#include "my_sh.h"
Test(sh_eval, eval_empty, .init=redirect_all_std)
{
sh_t *sh = sh_create((char *[]) {"PATH=/bin", NULL});
cr_assert_neq(sh, NULL);
cr_assert_eq(sh_eval(sh, ""), -1);
}
Test(sh_eval, eval_bad, .init=redirect_all_std)
{
sh_t *sh = sh_create((char *[]) {"PATH=/bin", NULL});
cr_assert_neq(sh, NULL);
cr_assert_eq(sh_eval(sh, "ù >"), -1);
}
Test(sh_eval, eval_redirects, .init=redirect_all_std)
{
sh_t *sh = sh_create((char *[]) {"PATH=/bin", NULL});
cr_assert_neq(sh, NULL);
cr_assert_eq(sh_eval(sh, "ls -1 | wc -l | wc -l"), 0);
cr_assert_stdout_eq_str("1\n");
}
Tests automatisés
------------------------------------------------------------------------------
GCC Code Coverage Report
Directory: .
------------------------------------------------------------------------------
File Lines Exec Cover Missing
------------------------------------------------------------------------------
sh.c 24 20 83% 19,29-30,40
sh_binary.c 36 34 94% 24,31
sh_cmd.c 15 12 80% 17,21,28
sh_cmd_block.c 31 28 90% 17,30,33
sh_cmd_check.c 36 33 91% 36,40,54
sh_cmd_parse.c 35 33 94% 36,58
sh_cmd_pipe.c 37 35 94% 17,29
sh_cmd_redirect.c 33 30 90% 17,31,44
sh_env.c 53 50 94% 25,46,51
sh_env_list.c 37 32 86% 17,28,62-64
sh_eval.c 49 45 91% 25,39,53,80
sh_exec.c 29 25 86% 32-33,47,50
sh_exec_redirect.c 43 31 72% 24,30,42,45-50,64,67,70
sh_funcs.c 27 19 70% 33,35,50,57,59-61,63
sh_funcs_env.c 30 24 80% 15,31,36,39,49,51
sh_funcs_system.c 55 27 49% 18-19,26-29,39,[...]
sh_main.c 28 0 0% 14,16-20,23,[...]
sh_signals.c 16 14 87% 28,30
sh_sstring.c 62 59 95% 20,43,97
sh_sstring_array.c 14 11 78% 18,21,26
sh_sstring_list.c 43 40 93% 17,45,57
utils.c 50 49 98% 46
utils_exec.c 28 11 39% 15,19-20,22-28,[...]
utils_tab.c 37 37 100%
------------------------------------------------------------------------------
TOTAL 848 699 82%
------------------------------------------------------------------------------
Bonus
Path handling:
~/mysh
cd ~
Separators:
- &&
- ||
Functions:
- builtins
- which
- pwd
Sequences:
\a \b \n \t
ENV:
- $SHELL
- $SHLVL
Bonus
Questions ?
FIN