Riferimenti per il file mkdir_suite.c

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <mcheck.h>
#include "CUnit.h"
#include "TestDB.h"
#include "Basic.h"
#include "fat.h"
#include "format.h"
#include "load_fat.h"
#include "list.h"
#include "make_dir.h"
#include "mkdir_suite.h"

Vai al codice sorgente di questo file.

Funzioni

int mkdir_init (void)
int mkdir_clean (void)
void test_pathname (void)
void run_mkdir (char *fname, int block_size, unsigned int num_block)
void test_add_blk (char *fname, int block_size, unsigned int num_block)
void test_recursive (char *fname, int block_size, unsigned int num_block)
void test_rel_path (char *fname, int block_size, unsigned int num_block)
void test_mkdir_128 (void)
void test_mkdir_1K (void)
void test_mkdir_2K (void)
void test_mkdir_4K (void)
void test_add_blk_128 (void)
void test_add_blk_1K (void)
void test_add_blk_2K (void)
void test_add_blk_4K (void)
void test_recursive_128 (void)
void test_recursive_1K (void)
void test_recursive_2K (void)
void test_recursive_4K (void)
void test_rel_path_128 (void)
void test_rel_path_1K (void)
void test_rel_path_2K (void)
void test_rel_path_4K (void)
void add_suite_mkdir (void)

Descrizione dettagliata

Questo file definisce la test_suite per la funzione di creazione di una directory fat_mkdir e per la funzione di listing di una directory fat_ls.

Definizione nel file mkdir_suite.c.


Documentazione delle funzioni

int mkdir_init ( void   ) 

Funzione di inizializzazione della suite

Definizione alla linea 27 del file mkdir_suite.c.

00027 {  return 0; }

int mkdir_clean ( void   ) 

Funzione di inizializzazione della suite

Definizione alla linea 30 del file mkdir_suite.c.

00030 {    return 0; }

void test_pathname ( void   ) 
Test:

Questo test ha il compito di controllare che pathname non corretti vengano riconosciuti. In particolare si controlla che venga generato un errore se si cerca di generare una nuova directory utilizzando i seguenti path:

  • Path name non assoluti, come ad esempio not/abs/path
  • Path name che usano nomi troppo lunghi (che eccedono gli 8 caratteri).

Definizione alla linea 42 del file mkdir_suite.c.

00043 {
00044     FILE *fs;
00045     struct fat_ctrl f_ctrl;
00046     int ret;
00047      
00048     fs = fopen("./DataFile/FAT_MKDIR", "w");
00049     fat_format(fs, 128, 10);
00050     fclose(fs);
00051     fs = fopen("./DataFile/FAT_MKDIR", "r+");
00052     ret = mount_fat(fs, &f_ctrl);
00053     CU_ASSERT_EQUAL_FATAL(0, ret);
00054 
00055     /*
00056      * Controlla che i path non assoluti vengano scartati
00057      */
00058     ret = fat_mkdir(fs, &f_ctrl, NULL);
00059     CU_ASSERT_EQUAL_FATAL(ret, EBDP);
00060     ret = fat_mkdir(fs, &f_ctrl, "not/abs/path");
00061     CU_ASSERT_EQUAL_FATAL(ret, EBDP);
00062 
00063     /*
00064      * Controlla che i nomi non eccadano MAX_LEN_NAME
00065      */
00066     ret = fat_mkdir(fs, &f_ctrl, "/toooooooo/long");
00067     CU_ASSERT_EQUAL_FATAL(ret, ENTL);
00068     ret = fat_mkdir(fs, &f_ctrl, "/looooooooooooong");
00069     CU_ASSERT_EQUAL_FATAL(ret, ENTL);
00070    
00071     /*
00072      * Cleanup
00073      */
00074     fclose(fs);
00075     unlink("./DataFile/FAT_MKDIR"); 
00076 }

void run_mkdir ( char *  fname,
int  block_size,
unsigned int  num_block 
)
Test:

Esegue il test di creazione di una directory. In particolare vengono eseguite le seguenti operazioni:

  • Formattazione di un filesystem SFAT con num_block blocchi di dimensione block_size.
  • Creazione della sirectory /dir1.
  • Controllo che le informazioni del boot sector siano corrette (in particolare non siano state modificate).
  • Controllo che la directory table della root (/) contenga le 3 entries ".", "..", "dir1"
  • Controllo che la directory table per dir1 sia stata correttamente creata.
  • Controllo che la FAT contenga le corrette informazioni per ciascun blocco.
  • Infine controllo che sia possibile effettuare il listing della nuova directory.
Parametri:
fname il nome del file utilizzato per memorizzare il filesystem FAT.
block_size la dimensione di ciascun blocco del filesystem FAT.
num_block numero di blocchi utilizzati dal filesystem FAT.

Definizione alla linea 103 del file mkdir_suite.c.

00104 {
00105     FILE *fs;
00106     struct fat_ctrl f_ctrl;
00107     struct dir_entry root_info;
00108     unsigned int len, *f_ptr;
00109     int i, cnt, n_entr, b_size, ret, index_dir1;
00110     struct stat st;
00111     char *list;
00112     char ex_list[ ] = ".\t..\tdir1";
00113      
00114     /*
00115      * Formata il file e ....
00116      */
00117     fs = fopen(fname, "w");
00118     fat_format(fs, block_size, num_block);
00119     fclose(fs);
00120     /* ... lo carica !!!! */
00121     fs = fopen(fname, "r+");
00122     ret = mount_fat(fs, &f_ctrl);
00123     CU_ASSERT_EQUAL_FATAL(ret, 0);
00124 
00125     /*
00126      *  Prova a creare una sottodirectory e chiude il filesystem
00127      */
00128     ret = fat_mkdir(fs, &f_ctrl, "/dir1");
00129     CU_ASSERT_EQUAL_FATAL(ret, 0);
00130     fclose(fs);
00131     /* 
00132      * ... prova a ricaricarlo ...
00133      **/
00134     fs = fopen(fname, "r+");
00135     ret = mount_fat(fs, &f_ctrl);
00136     CU_ASSERT_EQUAL_FATAL(ret, 0);
00137 
00138     /*
00139      * Prima controlla il boot sector e poi ...
00140      */
00141     CU_ASSERT_EQUAL_FATAL(f_ctrl.b_sector.fs_type, FAT_TYPE); 
00142     CU_ASSERT_EQUAL_FATAL(f_ctrl.b_sector.block_size, block_size);
00143     CU_ASSERT_EQUAL_FATAL(f_ctrl.b_sector.num_block, num_block);
00144 
00145     /* ... controlla l'inizio dei dati. */
00146     len = sizeof(struct boot_sector) + sizeof(unsigned int)*num_block; 
00147     CU_ASSERT_EQUAL_FATAL(f_ctrl.blk_base, len);
00148 
00149 
00150     /* 
00151      * La root directory table deve contenere 3 entry valide
00152      * ".", ".." e "dir1" rispettivamente.
00153      * Prima mi sposto nel blocco giusto....
00154      */
00155     fseek(fs, f_ctrl.blk_base + (ROOT_IDX)*f_ctrl.b_sector.block_size, SEEK_SET); 
00156 
00157     /* ... e poi leggo l'entry "." */
00158     ret = fread(&root_info, sizeof(struct dir_entry), 1, fs); 
00159     CU_ASSERT_EQUAL_FATAL(ret, 1);
00160     CU_ASSERT_EQUAL_FATAL(root_info.used, DIR_ENTRY_BUSY);
00161     CU_ASSERT_STRING_EQUAL_FATAL(root_info.name, ".");
00162     CU_ASSERT_EQUAL_FATAL(root_info.attr, SUB_ENTRY);
00163     CU_ASSERT_EQUAL_FATAL(root_info.index, ROOT_IDX);
00164     /* .... l'entry ".."  */
00165     ret = fread(&root_info, sizeof(struct dir_entry), 1, fs);
00166     CU_ASSERT_EQUAL_FATAL(ret, 1);
00167     CU_ASSERT_EQUAL_FATAL(root_info.used, DIR_ENTRY_BUSY);
00168     CU_ASSERT_STRING_EQUAL_FATAL(root_info.name, "..");
00169     CU_ASSERT_EQUAL_FATAL(root_info.attr, SUB_ENTRY);
00170     CU_ASSERT_EQUAL_FATAL(root_info.index, ROOT_IDX);
00171     /* .. e l'entry "dir1" */
00172     ret = fread(&root_info, sizeof(struct dir_entry), 1, fs); 
00173     CU_ASSERT_EQUAL_FATAL(ret, 1);
00174     CU_ASSERT_EQUAL_FATAL(root_info.used, DIR_ENTRY_BUSY);
00175     CU_ASSERT_STRING_EQUAL_FATAL(root_info.name, "dir1");
00176     CU_ASSERT_EQUAL_FATAL(root_info.attr, SUB_ENTRY);
00177     index_dir1 = root_info.index;
00178     /* Le entry restanti devono essere vuote */
00179     b_size = f_ctrl.b_sector.block_size;
00180     n_entr = b_size / sizeof(struct dir_entry);
00181     for (i=3; i<n_entr; i++) {
00182         fread(&root_info, sizeof(struct dir_entry), 1, fs);
00183         CU_ASSERT_EQUAL_FATAL(root_info.used, DIR_ENTRY_FREE);
00184     }
00185 
00186     /*
00187      * Controlla che la directory table per /dir1
00188      * contenga due entry ("." e "..").
00189      */
00190     len = f_ctrl.blk_base + (index_dir1)*f_ctrl.b_sector.block_size;
00191     fseek(fs, len, SEEK_SET); 
00192     fread(&root_info, sizeof(struct dir_entry), 1, fs); /* Lettura "."  */
00193     CU_ASSERT_EQUAL_FATAL(root_info.used, DIR_ENTRY_BUSY);
00194     CU_ASSERT_STRING_EQUAL_FATAL(root_info.name, ".");
00195     CU_ASSERT_EQUAL_FATAL(root_info.attr, SUB_ENTRY);
00196 
00197     fread(&root_info, sizeof(struct dir_entry), 1, fs); /* Lettura ".."*/
00198     CU_ASSERT_EQUAL_FATAL(root_info.used, DIR_ENTRY_BUSY);
00199     CU_ASSERT_STRING_EQUAL_FATAL(root_info.name, "..");
00200     CU_ASSERT_EQUAL_FATAL(root_info.attr, SUB_ENTRY);
00201     CU_ASSERT_EQUAL_FATAL(root_info.index, ROOT_IDX);
00202 
00203     for (i=2; i<n_entr; i++) {
00204         fread(&root_info, sizeof(struct dir_entry), 1, fs);
00205         CU_ASSERT_EQUAL_FATAL(root_info.used, DIR_ENTRY_FREE);
00206     }
00207 
00208     /*
00209      * Controlliamo ora la FAT: 
00210      * esattamente due blocchi devono essere marcati LAST_BLOCK 
00211      * e gli altri BLOCK_FREE 
00212      */
00213     f_ptr = f_ctrl.fat_ptr;
00214     cnt = 0; 
00215     for (i=0; i<f_ctrl.b_sector.num_block; i++) {
00216         if (f_ptr[i] == LAST_BLOCK)
00217             cnt++;
00218         else /* e controllo che gli altri siano free */
00219             CU_ASSERT_EQUAL_FATAL(f_ptr[i], BLOCK_FREE);
00220     }
00221     CU_ASSERT_EQUAL_FATAL(cnt, 2);
00222 
00223     /*
00224      * Controlla la lunghezza dei file
00225      */
00226     len = sizeof(struct boot_sector);
00227     len = len + sizeof(unsigned int) * f_ctrl.b_sector.num_block;
00228     len = len + f_ctrl.b_sector.block_size * f_ctrl.b_sector.num_block;
00229     stat(fname, &st);
00230     CU_TEST_FATAL(len == st.st_size);
00231 
00232     /*
00233      * controlla il listing della directory appena creata
00234      */
00235     ret = fat_ls(fs, &f_ctrl, "/", &list);
00236     CU_ASSERT_EQUAL_FATAL(ret, 0);
00237     CU_ASSERT_STRING_EQUAL_FATAL(list, ex_list);
00238 
00239     /*
00240      * Cleanup
00241      */
00242     fclose(fs);
00243     unlink(fname); 
00244 }

void test_add_blk ( char *  fname,
int  block_size,
unsigned int  num_block 
)
Test:

Questo test ha lo scopo di controllare che venga gestita correttamente la situazione in cui occorre aggiungere un nuovo blocco per contenere una directory table. In particolare il test viene realizzato come segue:

  • Viene richiesta la creazione di N directory sotto "/" in modo da riempire il primo blocco della directory table.
  • Viene creata una nuova directory in modo che la funzione fat_mkdir aggiunga un nuovo blocco alla directory table.

Il test termina con successo se sono verificate le seguenti condizioni:

  • La directory table deve essere distribuita su due blocchi.
  • Il listing delle directory deve tornare tutte le subdirectory create.
Parametri:
fname il nome del file utilizzato per memorizzare il filesystem FAT.
block_size la dimensione di ciascun blocco delfilesystem FAT.
num_block numero di blocchi utilizzati dal filesystem FAT.

Definizione alla linea 270 del file mkdir_suite.c.

00271 {
00272     FILE *fs;
00273     struct fat_ctrl f_ctrl;
00274     unsigned int data_reg;
00275     int i, n_entr, b_size, len, ret;
00276     char dir_name[MAX_LEN_NAME + 2], *exp_list, *list;
00277      
00278     /*
00279      * Formatta il file ed effettua
00280      * il mounting
00281      */
00282     fs = fopen(fname, "w");
00283     fat_format(fs, block_size, num_block);
00284     fclose(fs);
00285     fs = fopen(fname, "r+");
00286     ret = mount_fat(fs, &f_ctrl);
00287     CU_ASSERT_EQUAL_FATAL(ret, 0);
00288 
00289     /*
00290      * Crea alcune directory in modo da riempire il 
00291      * primo blocco della directory table
00292      */
00293     data_reg = f_ctrl.blk_base;                /* Inizio primo blocco */
00294     b_size = f_ctrl.b_sector.block_size;       /* Size del blocco */
00295     n_entr = b_size / sizeof(struct dir_entry); /* Numero di entry per blocco */
00296 
00297     
00298     for (i=0; i<n_entr - 2; i++) {
00299         snprintf(dir_name, MAX_LEN_NAME + 2, "/d%i", i);
00300         ret = fat_mkdir(fs, &f_ctrl, dir_name);
00301         CU_ASSERT_EQUAL_FATAL(ret, 0);
00302     }
00303 
00304     /*... aggiunge una nuova entry, cosi' che e' necessario un nuovo blocco */
00305     snprintf(dir_name, MAX_LEN_NAME + 2, "/d%i", n_entr - 2);
00306     ret = fat_mkdir(fs, &f_ctrl, dir_name);
00307     CU_ASSERT_EQUAL_FATAL(ret, 0);
00308 
00309     /*
00310      * Rimonta il file system per verificare che la struttura sia corretta
00311      */
00312     fclose(fs);
00313     fs = fopen(fname, "r+");
00314     ret = mount_fat(fs, &f_ctrl);
00315     CU_ASSERT_EQUAL_FATAL(ret, 0);
00316 
00317     /* 
00318      * Controlliamo che tutta la directory sia stata creata 
00319      * correttamente attraverso il listing 
00320      */
00321     ret = fat_ls(fs, &f_ctrl, "/", &list);
00322     CU_ASSERT_EQUAL_FATAL(ret, 0);
00323 
00324     /* Costruisce la stringa attesa  */
00325     exp_list = malloc(MAX_LEN_NAME + 1);
00326     CU_ASSERT_PTR_NOT_NULL_FATAL(exp_list);
00327 
00328     snprintf(exp_list,MAX_LEN_NAME + 1, "%s", ".\t..");
00329     for (i=0; i<n_entr - 1; i++) {
00330         snprintf(dir_name, MAX_LEN_NAME + 2,  "d%i", i);
00331         len = strlen(exp_list) + strlen(dir_name);
00332         exp_list = realloc(exp_list, len + 2);
00333         strcat(exp_list, "\t");
00334         strcat(exp_list, dir_name);
00335     }
00336     CU_ASSERT_STRING_EQUAL_FATAL(list, exp_list);
00337     free(list);
00338 
00339     for (i=0; i<n_entr - 1; i++) {
00340         snprintf(dir_name, MAX_LEN_NAME + 2,  "/d%i", i);
00341         ret = fat_ls(fs, &f_ctrl, dir_name, &list);
00342         CU_ASSERT_EQUAL_FATAL(ret, 0);
00343         CU_ASSERT_STRING_EQUAL_FATAL(list, ".\t..");
00344         free(list);
00345     }
00346 
00347     /*
00348      * Cleanup
00349      */
00350     fclose(fs);
00351     unlink(fname); 
00352 }

void test_recursive ( char *  fname,
int  block_size,
unsigned int  num_block 
)
Test:

Questo test ha lo scopo di controllare che la creazione dinested directory venga gestita correttamente dalla funzione fat_mkdir. In particolare questo test viene realizzato come segue:

  • Viene generato l'albero di directory illustrato nella figura sotostante utilizzando la funzione fat_mkdir.
  • Tramite la funzione fat_ls si controlla che ciascuna direcotry contenga il corretto insieme di subdirectory (incluso "." e "..").
  • Si controlla che la duplicazione di una directory non a livello di root sia gestita correttamente.
  • Si controlla che il tentativo di effettuare il listing di una directory non esistente sia gestito correttamente.
dirTest.jpg

Albero delle direcotry utilizato per il test

Parametri:
fname il nome del file utilizzato per memorizzare il filesystem FAT.
block_size la dimensione di ciascun blocco delfilesystem FAT.
num_block numero di blocchi utilizzati dal filesystem FAT.

Definizione alla linea 376 del file mkdir_suite.c.

00377 {
00378     FILE *fs;
00379     struct fat_ctrl f_ctrl;
00380     int ret;
00381     char *list;
00382 
00383     /*
00384      * Formatta il filesystem
00385      */
00386     fs = fopen(fname, "w");
00387     fat_format(fs, block_size, num_block);
00388     fclose(fs);
00389     /* ... lo carica */
00390     fs = fopen(fname, "r+");
00391     ret = mount_fat(fs, &f_ctrl);
00392     CU_ASSERT_EQUAL_FATAL(ret, 0);
00393 
00394     /*
00395      * Crea le directory D1, D2, D3 e D4 nella 
00396      * root directory ("/").
00397      */
00398     ret = fat_mkdir(fs, &f_ctrl, "/D1");
00399     CU_ASSERT_EQUAL_FATAL(ret, 0);
00400     ret = fat_mkdir(fs, &f_ctrl, "/D2");
00401     CU_ASSERT_EQUAL_FATAL(ret, 0);
00402     ret = fat_mkdir(fs, &f_ctrl, "/D3");
00403     CU_ASSERT_EQUAL_FATAL(ret, 0);
00404     ret = fat_mkdir(fs, &f_ctrl, "/D4");
00405     CU_ASSERT_EQUAL_FATAL(ret, 0);
00406 
00407     /*
00408      * Crea le directory D2_1, D2_2 e D2_3 nella
00409      * directory D2.
00410      */
00411     ret = fat_mkdir(fs, &f_ctrl, "/D2/D2_1");
00412     CU_ASSERT_EQUAL_FATAL(ret, 0);
00413     ret = fat_mkdir(fs, &f_ctrl, "/D2/D2_2");
00414     CU_ASSERT_EQUAL_FATAL(ret, 0);
00415     ret = fat_mkdir(fs, &f_ctrl, "/D2/D2_3");
00416     CU_ASSERT_EQUAL_FATAL(ret, 0);
00417 
00418     /*
00419      * Crea le directory D2_3_1 e D2_3_2 nella
00420      * directory D2_3.
00421      */
00422     ret = fat_mkdir(fs, &f_ctrl, "/D2/D2_3/D2_3_1");
00423     CU_ASSERT_EQUAL_FATAL(ret, 0);
00424     ret = fat_mkdir(fs, &f_ctrl, "/D2/D2_3/D2_3_2");
00425     CU_ASSERT_EQUAL_FATAL(ret, 0);
00426 
00427     /*
00428      * Crea D4_1 e D4_2 nella
00429      * directory D4.
00430      */
00431     ret = fat_mkdir(fs, &f_ctrl, "/D4/D4_1");
00432     CU_ASSERT_EQUAL_FATAL(ret, 0);
00433     ret = fat_mkdir(fs, &f_ctrl, "/D4/D4_2");
00434     CU_ASSERT_EQUAL_FATAL(ret, 0);
00435 
00436     /*
00437      * Controlla il contenuto della root
00438      */
00439     ret = fat_ls(fs, &f_ctrl, "/", &list);
00440     CU_ASSERT_EQUAL_FATAL(ret, 0);
00441     CU_ASSERT_STRING_EQUAL_FATAL(list, ".\t..\tD1\tD2\tD3\tD4");
00442     free(list);
00443 
00444     /*
00445      * Controlla il contenuto di /D1 
00446      */
00447     ret = fat_ls(fs, &f_ctrl, "/D1", &list);
00448     CU_ASSERT_EQUAL_FATAL(ret, 0);
00449     CU_ASSERT_STRING_EQUAL_FATAL(list, ".\t..");
00450     free(list);
00451 
00452     /*
00453      * Controlla il contenuto di /D2
00454      */
00455     ret = fat_ls(fs, &f_ctrl, "/D2", &list);
00456     CU_ASSERT_EQUAL_FATAL(ret, 0);
00457     CU_ASSERT_STRING_EQUAL_FATAL(list, ".\t..\tD2_1\tD2_2\tD2_3");
00458     free(list);
00459     
00460     /*
00461      * Controlla /D2/D2_1 e /D2/D2_2 
00462      */
00463     ret = fat_ls(fs, &f_ctrl, "/D2/D2_1", &list);
00464     CU_ASSERT_EQUAL_FATAL(ret, 0);
00465     CU_ASSERT_STRING_EQUAL_FATAL(list, ".\t..");
00466     free(list);
00467     ret = fat_ls(fs, &f_ctrl, "/D2/D2_2", &list);
00468     CU_ASSERT_EQUAL_FATAL(ret, 0);
00469     CU_ASSERT_STRING_EQUAL_FATAL(list, ".\t..");
00470     free(list);
00471     /*
00472      * Controlla /D2/D2_3 
00473      */
00474     ret = fat_ls(fs, &f_ctrl, "/D2/D2_3", &list);
00475     CU_ASSERT_EQUAL_FATAL(ret, 0); 
00476     CU_ASSERT_STRING_EQUAL_FATAL(list, ".\t..\tD2_3_1\tD2_3_2");
00477 
00478     /*
00479      * Controlla /D2/D2_3/D2_3_1 e /D2/D2_3/D2_3_2
00480      */
00481     ret = fat_ls(fs, &f_ctrl, "/D2/D2_3/D2_3_1", &list);
00482     CU_ASSERT_EQUAL_FATAL(ret, 0); 
00483     CU_ASSERT_STRING_EQUAL_FATAL(list, ".\t..");
00484     ret = fat_ls(fs, &f_ctrl, "/D2/D2_3/D2_3_2", &list);
00485     CU_ASSERT_EQUAL_FATAL(ret, 0); 
00486     CU_ASSERT_STRING_EQUAL_FATAL(list, ".\t..");
00487     
00488     /*
00489      * Controlla /D3
00490      */
00491     ret = fat_ls(fs, &f_ctrl, "/D3", &list);
00492     CU_ASSERT_EQUAL_FATAL(ret, 0);
00493     CU_ASSERT_STRING_EQUAL_FATAL(list, ".\t..");
00494 
00495     /*
00496      * Controlla /D4
00497      */
00498     ret = fat_ls(fs, &f_ctrl, "/D4", &list);
00499     CU_ASSERT_EQUAL_FATAL(ret, 0);
00500     CU_ASSERT_STRING_EQUAL_FATAL(list, ".\t..\tD4_1\tD4_2");
00501 
00502     /*
00503      * Controllo per directory duplicate
00504      */
00505     ret = fat_mkdir(fs, &f_ctrl, "/D2/D2_3/D2_3_2");
00506     CU_ASSERT_EQUAL_FATAL(ret, EDAEX);
00507     ret = fat_ls(fs, &f_ctrl, "/D2/D4_2/D4_2_1", &list);
00508     CU_ASSERT_EQUAL_FATAL(ret, ENSFD);
00509 
00510     /*
00511      * Cleanup
00512      */
00513     fclose(fs);
00514     unlink(fname); 
00515 }

void test_rel_path ( char *  fname,
int  block_size,
unsigned int  num_block 
)
Test:

Questo test ha lo scopo di controllare la navigazione all'interno del file system FAT utilizzando path che includiono "." e ".." In particolare questo test viene realizzato come segue:

  • Viene generato l'albero di directory utilizzato per il test test_recursive_128.
  • Tramite la funzione fat_ls si controlla che il contenuto delle seguenti directories sia corretto:
    • /D4/.
    • /D2/D2_3/..
    • /D2/D2_3/../.
    • /D4/D4_2/../../D2/D2_3
    • /D4/D4_2/../../D2/D2_3/D2_3_1/../../../D4
Parametri:
fname il nome del file utilizzato per memorizzare il filesystem FAT.
block_size la dimensione di ciascun blocco delfilesystem FAT.
num_block numero di blocchi utilizzati dal filesystem FAT.

Definizione alla linea 538 del file mkdir_suite.c.

00539 {
00540     FILE *fs;
00541     struct fat_ctrl f_ctrl;
00542     int ret;
00543     char *list;
00544 
00545     /*
00546      * Formatta il filesystem ....
00547      */
00548     fs = fopen(fname, "w");
00549     fat_format(fs, block_size, num_block);
00550     fclose(fs);
00551 
00552     /* lo carica ... */
00553     fs = fopen(fname, "r+");
00554     ret = mount_fat(fs, &f_ctrl);
00555     CU_ASSERT_EQUAL_FATAL(ret, 0);
00556 
00557     /*
00558      * D1, D2, D3 e D4 
00559      */
00560     ret = fat_mkdir(fs, &f_ctrl, "/D1");
00561     CU_ASSERT_EQUAL_FATAL(ret, 0);
00562     ret = fat_mkdir(fs, &f_ctrl, "/D2");
00563     CU_ASSERT_EQUAL_FATAL(ret, 0);
00564     ret = fat_mkdir(fs, &f_ctrl, "/D3");
00565     CU_ASSERT_EQUAL_FATAL(ret, 0);
00566     ret = fat_mkdir(fs, &f_ctrl, "/D4");
00567     CU_ASSERT_EQUAL_FATAL(ret, 0);
00568 
00569     /*
00570      * D2_1, D2_2 e D2_3 
00571      */
00572     ret = fat_mkdir(fs, &f_ctrl, "/D2/D2_1");
00573     CU_ASSERT_EQUAL_FATAL(ret, 0);
00574     ret = fat_mkdir(fs, &f_ctrl, "/D2/D2_2");
00575     CU_ASSERT_EQUAL_FATAL(ret, 0);
00576     ret = fat_mkdir(fs, &f_ctrl, "/D2/D2_3");
00577     CU_ASSERT_EQUAL_FATAL(ret, 0);
00578 
00579     /*
00580      * D2_3_1, D2_3_2 e D2_3.
00581      */
00582     ret = fat_mkdir(fs, &f_ctrl, "/D2/D2_3/D2_3_1");
00583     CU_ASSERT_EQUAL_FATAL(ret, 0);
00584     ret = fat_mkdir(fs, &f_ctrl, "/D2/D2_3/D2_3_2");
00585     CU_ASSERT_EQUAL_FATAL(ret, 0);
00586 
00587     /*
00588      * D4_1 e D4_2
00589      */
00590     ret = fat_mkdir(fs, &f_ctrl, "/D4/D4_1");
00591     CU_ASSERT_EQUAL_FATAL(ret, 0);
00592     ret = fat_mkdir(fs, &f_ctrl, "/D4/D4_2");
00593     CU_ASSERT_EQUAL_FATAL(ret, 0);
00594     
00595     /*
00596      * Controlla /D4/. 
00597      */
00598     ret = fat_ls(fs, &f_ctrl, "/D4/.", &list);
00599     CU_ASSERT_EQUAL_FATAL(ret, 0);
00600     CU_ASSERT_STRING_EQUAL_FATAL(list, ".\t..\tD4_1\tD4_2");
00601 
00602     /*
00603      * Controlla /D2/D2_3/.. 
00604      */
00605     ret = fat_ls(fs, &f_ctrl, "/D2/D2_3/..", &list);
00606     CU_ASSERT_EQUAL_FATAL(ret, 0);
00607     CU_ASSERT_STRING_EQUAL_FATAL(list, ".\t..\tD2_1\tD2_2\tD2_3");
00608 
00609     /*
00610      * Controlla /D2/D2_3/../. 
00611      */
00612     ret = fat_ls(fs, &f_ctrl, "/D2/D2_3/../.", &list);
00613     CU_ASSERT_EQUAL_FATAL(ret, 0);
00614     CU_ASSERT_STRING_EQUAL_FATAL(list, ".\t..\tD2_1\tD2_2\tD2_3");
00615 
00616 
00617     /*
00618      * Controlla /D4/D4_2/../../D2/D2_3 
00619      */
00620     ret = fat_ls(fs, &f_ctrl, "/D4/D4_2/../../D2/D2_3", &list);
00621     CU_ASSERT_EQUAL_FATAL(ret, 0); 
00622     CU_ASSERT_STRING_EQUAL_FATAL(list, ".\t..\tD2_3_1\tD2_3_2");
00623 
00624     /*
00625      * Controlla /D4/D4_2/../../D2/D2_3/D2_3_1/../../../D4 
00626      */
00627     ret = fat_ls(fs, &f_ctrl, "/D4/.", &list);
00628     CU_ASSERT_EQUAL_FATAL(ret, 0);
00629     CU_ASSERT_STRING_EQUAL_FATAL(list, ".\t..\tD4_1\tD4_2");
00630 
00631     /*
00632      * Cleanup
00633      */
00634     fclose(fs);
00635     unlink(fname); 
00636 }

void test_mkdir_128 ( void   ) 

Test creazone di una directory per un filsystem formattato utilizzando 10 blocchi di dimensione 128 Bytes ciascuno.

Definizione alla linea 643 del file mkdir_suite.c.

00644 {
00645     run_mkdir("DataFile/fat_128", 128, 10);
00646 }

void test_mkdir_1K ( void   ) 

Test creazone di una directory per un filsystem formattato utilizzando 10 blocchi di dimensione 1KB ciascuno.

Definizione alla linea 652 del file mkdir_suite.c.

00653 {
00654     run_mkdir("DataFile/fat_1K", 1024, 10);
00655 }

void test_mkdir_2K ( void   ) 

Test creazone di una directory per un filsystem formattato utilizzando 10 blocchi di dimensione 2KB ciascuno.

Definizione alla linea 661 del file mkdir_suite.c.

00662 {
00663     run_mkdir("DataFile/fat_2K", 1024*2, 10);
00664 }

void test_mkdir_4K ( void   ) 

Test creazone di una directory per un filsystem formattato utilizzando 10 blocchi di dimensione 4KB ciascuno.

Definizione alla linea 670 del file mkdir_suite.c.

00671 {
00672     run_mkdir("DataFile/fat_4K", 1024*4, 10);
00673 }

void test_add_blk_128 ( void   ) 

Test di aggiunta di un blocco alla directory table per un filsystem formattato utilizzando 10 blocchi di dimensione 128 Bytes ciascuno.

Definizione alla linea 679 del file mkdir_suite.c.

00680 {
00681     test_add_blk("DataFile/fat_128", 128, 256);
00682 }

void test_add_blk_1K ( void   ) 

Test di aggiunta di un blocco alla directory table per un filsystem formattato utilizzando 2K blocchi di dimensione 1KB ciascuno.

Definizione alla linea 688 del file mkdir_suite.c.

00689 {
00690     test_add_blk("DataFile/fat_1K", 1024, 1024*2);
00691 }

void test_add_blk_2K ( void   ) 

Test di aggiunta di un blocco alla directory table per un filsystem formattato utilizzando 4K blocchi di dimensione 1KB ciascuno.

Definizione alla linea 697 del file mkdir_suite.c.

00698 {
00699     test_add_blk("DataFile/fat_2K", 1024*2, 1024*4);
00700 }

void test_add_blk_4K ( void   ) 

Test di aggiunta di un blocco alla directory table per un filsystem formattato utilizzando 8K blocchi di dimensione 1KB ciascuno.

Definizione alla linea 706 del file mkdir_suite.c.

00707 {
00708     test_add_blk("DataFile/fat_4K", 1024*4, 1024*8);
00709 }

void test_recursive_128 ( void   ) 

Test creazone di un albero di directories per un filsystem formattato utilizzando 20 blocchi di dimensione 128 Bytes ciascuno.

Definizione alla linea 715 del file mkdir_suite.c.

00716 {
00717     test_recursive("DataFile/fat_128", 128, 20);
00718 }

void test_recursive_1K ( void   ) 

Test creazone di un albero di directories per un filsystem formattato utilizzando 20 blocchi di dimensione 1KB ciascuno.

Definizione alla linea 724 del file mkdir_suite.c.

00725 {
00726     test_recursive("DataFile/fat_1K", 1024, 20);
00727 }

void test_recursive_2K ( void   ) 

Test creazone di un albero di directories per un filsystem formattato utilizzando 20 blocchi di dimensione 2KB ciascuno.

Definizione alla linea 733 del file mkdir_suite.c.

00734 {
00735     test_recursive("DataFile/fat_2K", 1024*2, 20);
00736 }

void test_recursive_4K ( void   ) 

Test creazone di un albero di directories per un filsystem formattato utilizzando 20 blocchi di dimensione 4KB ciascuno.

Definizione alla linea 742 del file mkdir_suite.c.

00743 {
00744     test_recursive("DataFile/fat_4K", 1024*4, 20);
00745 }

void test_rel_path_128 ( void   ) 

Test navigazione tramie path relativi per un filsystem formattato utilizzando 20 blocchi di dimensione 128 ciascuno.

Definizione alla linea 751 del file mkdir_suite.c.

00752 {
00753     test_rel_path("DataFile/fat_128", 128, 20);
00754 }

void test_rel_path_1K ( void   ) 

Test navigazione tramie path relativi per un filsystem formattato utilizzando 20 blocchi di dimensione 1KB ciascuno.

Definizione alla linea 760 del file mkdir_suite.c.

00761 {
00762     test_rel_path("DataFile/fat_1K", 1024, 20);
00763 }

void test_rel_path_2K ( void   ) 

Test navigazione tramie path relativi per un filsystem formattato utilizzando 20 blocchi di dimensione 2KB ciascuno.

Definizione alla linea 769 del file mkdir_suite.c.

00770 {
00771     test_rel_path("DataFile/fat_2K", 1024*2, 20);
00772 }

void test_rel_path_4K ( void   ) 

Test navigazione tramie path relativi per un filsystem formattato utilizzando 20 blocchi di dimensione 4KB ciascuno.

Definizione alla linea 778 del file mkdir_suite.c.

00779 {
00780     test_rel_path("DataFile/fat_4K", 1024*4, 20);
00781 }

void add_suite_mkdir ( void   ) 

Test suite per la funzione fat_mkdir

Definizione alla linea 786 del file mkdir_suite.c.

00787 {
00788     CU_pSuite mkdir_suite = NULL;
00789 
00790     mkdir_suite = CU_add_suite("Creating Directory", mkdir_init, mkdir_clean);
00791     /* Bad path test. */
00792     CU_add_test(mkdir_suite, "Incorrect pathname detection", test_pathname); 
00793     /* Simple directory creation tests. */ 
00794     CU_add_test(mkdir_suite, "Make a directory with block size 128 bytes", test_mkdir_128); 
00795     CU_add_test(mkdir_suite, "Make a directory with block size 1KB", test_mkdir_1K); 
00796     CU_add_test(mkdir_suite, "Make a directory with block size 2KB", test_mkdir_2K);
00797     CU_add_test(mkdir_suite, "Make a directory with block size 4KB", test_mkdir_4K);  
00798     /* Add directiry table block tests. */
00799     CU_add_test(mkdir_suite, "Exceeding block size for directory table (128 bytes)", test_add_blk_128);
00800     CU_add_test(mkdir_suite, "Exceeding block size for directory table (1KB)", test_add_blk_1K);
00801     CU_add_test(mkdir_suite, "Exceeding block size for directory table (2KB)", test_add_blk_2K);
00802     CU_add_test(mkdir_suite, "Exceeding block size for directory table (4KB)", test_add_blk_4K);
00803     /* Nested directory tests. */
00804     CU_add_test(mkdir_suite, "Nested directories creation (128 bytes)", test_recursive_128);
00805     CU_add_test(mkdir_suite, "Nested directories creation (1KB)", test_recursive_1K);
00806     CU_add_test(mkdir_suite, "Nested directories creation (2KB)", test_recursive_2K);
00807     CU_add_test(mkdir_suite, "Nested directories creation (4KB)", test_recursive_4K);
00808     /* Relative path navigation tests. */
00809     CU_add_test(mkdir_suite, "Relative path navigation (128 bytes)", test_rel_path_128 );
00810     CU_add_test(mkdir_suite, "Relative path navigation (1KB)", test_rel_path_1K );
00811     CU_add_test(mkdir_suite, "Relative path navigation (2KB)", test_rel_path_2K );
00812     CU_add_test(mkdir_suite, "Relative path navigation (4KB bytes)", test_rel_path_4K );
00813 }

Generato il Fri Jan 28 22:16:31 2011 per SFAT: Simplified File Allocation Table Project da  doxygen 1.6.3