Skip to content
Extraits de code Groupes Projets
Valider 2f29a5b3 rédigé par Laurent Paucot's avatar Laurent Paucot
Parcourir les fichiers

plus de segfault

parent c4fcbb68
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
Pipeline #3208 réussi
<?xml version="1.0" ?>
<?xml-stylesheet type="text/xsl" href="CUnit-Run.xsl" ?>
<!DOCTYPE CUNIT_TEST_RUN_REPORT SYSTEM "CUnit-Run.dtd">
<CUNIT_TEST_RUN_REPORT>
<CUNIT_HEADER/>
<CUNIT_RESULT_LISTING>
<CUNIT_RUN_SUITE>
<CUNIT_RUN_SUITE_SUCCESS>
<SUITE_NAME> ma_suite </SUITE_NAME>
<CUNIT_RUN_TEST_RECORD>
<CUNIT_RUN_TEST_SUCCESS>
<TEST_NAME> test_is_div </TEST_NAME>
</CUNIT_RUN_TEST_SUCCESS>
</CUNIT_RUN_TEST_RECORD>
<CUNIT_RUN_TEST_RECORD>
<CUNIT_RUN_TEST_SUCCESS>
<TEST_NAME> test_is_prime </TEST_NAME>
</CUNIT_RUN_TEST_SUCCESS>
</CUNIT_RUN_TEST_RECORD>
<CUNIT_RUN_TEST_RECORD>
<CUNIT_RUN_TEST_SUCCESS>
<TEST_NAME> test_is_not_prime </TEST_NAME>
</CUNIT_RUN_TEST_SUCCESS>
</CUNIT_RUN_TEST_RECORD>
</CUNIT_RUN_SUITE_SUCCESS>
</CUNIT_RUN_SUITE>
</CUNIT_RESULT_LISTING>
<CUNIT_RUN_SUMMARY>
<CUNIT_RUN_SUMMARY_RECORD>
<TYPE> Suites </TYPE>
<TOTAL> 1 </TOTAL>
<RUN> 1 </RUN>
<SUCCEEDED> - NA - </SUCCEEDED>
<FAILED> 0 </FAILED>
<INACTIVE> 0 </INACTIVE>
</CUNIT_RUN_SUMMARY_RECORD>
<CUNIT_RUN_SUMMARY_RECORD>
<TYPE> Test Cases </TYPE>
<TOTAL> 3 </TOTAL>
<RUN> 3 </RUN>
<SUCCEEDED> 3 </SUCCEEDED>
<FAILED> 0 </FAILED>
<INACTIVE> 0 </INACTIVE>
</CUNIT_RUN_SUMMARY_RECORD>
<CUNIT_RUN_SUMMARY_RECORD>
<TYPE> Assertions </TYPE>
<TOTAL> 3 </TOTAL>
<RUN> 3 </RUN>
<SUCCEEDED> 3 </SUCCEEDED>
<FAILED> 0 </FAILED>
<INACTIVE> n/a </INACTIVE>
</CUNIT_RUN_SUMMARY_RECORD>
</CUNIT_RUN_SUMMARY>
<CUNIT_FOOTER> File Generated By CUnit v2.1-3 - Sat Apr 11 19:51:18 2020
</CUNIT_FOOTER>
</CUNIT_TEST_RUN_REPORT>
\ No newline at end of file
run 0 → 100755
Fichier ajouté
...@@ -27,6 +27,7 @@ struct buffer_rc{ ...@@ -27,6 +27,7 @@ struct buffer_rc{
int len; int len;
int head; int head;
int tail; int tail;
int stop;
}; };
struct buffer_rc buffer_1; struct buffer_rc buffer_1;
...@@ -37,8 +38,9 @@ struct buffer_cw ...@@ -37,8 +38,9 @@ struct buffer_cw
int len; int len;
int head; int head;
int tail; int tail;
int stop;
}; };
struct buffer_rc buffer_2; struct buffer_cw buffer_2;
pthread_mutex_t mutex1; pthread_mutex_t mutex1;
...@@ -52,6 +54,7 @@ sem_t full2; ...@@ -52,6 +54,7 @@ sem_t full2;
void put_in_buffer_1(char *c){ void put_in_buffer_1(char *c){
buffer_1.tab[buffer_1.head] = malloc(sizeof(c));
buffer_1.tab[buffer_1.head] = c; buffer_1.tab[buffer_1.head] = c;
buffer_1.len++; buffer_1.len++;
buffer_1.head = (buffer_1.head + 1)%buffer_1.size; buffer_1.head = (buffer_1.head + 1)%buffer_1.size;
...@@ -60,6 +63,7 @@ void put_in_buffer_1(char *c){ ...@@ -60,6 +63,7 @@ void put_in_buffer_1(char *c){
char *get_from_buffer_1(void){ char *get_from_buffer_1(void){
char *result; char *result;
result = buffer_1.tab[buffer_1.tail]; result = buffer_1.tab[buffer_1.tail];
buffer_1.tab[buffer_1.tail] = NULL;
buffer_1.len--; buffer_1.len--;
buffer_1.tail = (buffer_1.tail + 1)%buffer_1.size; buffer_1.tail = (buffer_1.tail + 1)%buffer_1.size;
...@@ -104,7 +108,7 @@ int is_prime(long number) { // Vérifie si number est un nombre premier. Return ...@@ -104,7 +108,7 @@ int is_prime(long number) { // Vérifie si number est un nombre premier. Return
} }
queue_t* enqueue(queue_t* q, long val){ void enqueue(queue_t* q, long val){
struct node new_node; struct node new_node;
new_node.value = val; new_node.value = val;
...@@ -112,7 +116,7 @@ queue_t* enqueue(queue_t* q, long val){ ...@@ -112,7 +116,7 @@ queue_t* enqueue(queue_t* q, long val){
struct node *ptr; struct node *ptr;
ptr = malloc(sizeof(node_t)); ptr = malloc(sizeof(node_t));
if (ptr == NULL){return NULL;} if (ptr == NULL){return;}
*ptr = new_node; *ptr = new_node;
if (q->size == 0) if (q->size == 0)
...@@ -125,7 +129,7 @@ queue_t* enqueue(queue_t* q, long val){ ...@@ -125,7 +129,7 @@ queue_t* enqueue(queue_t* q, long val){
*q->tail->next = *ptr; *q->tail->next = *ptr;
} }
q->size++; q->size++;
return q; //return q;
} }
...@@ -144,19 +148,20 @@ queue_t* prime_divs(long number){ ...@@ -144,19 +148,20 @@ queue_t* prime_divs(long number){
for (long i = 2; i <= number/2; i++){ for (long i = 2; i <= number/2; i++){
if (is_div(number, i) && is_prime(i) == 1){ if (is_div(number, i) && is_prime(i) == 1){
ptr = enqueue(ptr,i); enqueue(ptr,i);
if (ptr == NULL){return NULL;} if (ptr == NULL){return NULL;}
} }
} }
enqueue(ptr,number);
return ptr; return ptr;
} }
void *writing(void *param){ void *writing(void *param){
int i = 0;
while(i==0){ //trouver une condition de fin !! while(buffer_2.stop == 0 || buffer_2.len > 0){
sem_wait(&full2); sem_wait(&full2);
pthread_mutex_lock(&mutex2); pthread_mutex_lock(&mutex2);
...@@ -164,7 +169,7 @@ void *writing(void *param){ ...@@ -164,7 +169,7 @@ void *writing(void *param){
pthread_mutex_unlock(&mutex2); pthread_mutex_unlock(&mutex2);
FILE *file2 = (FILE*) param; FILE *file2 = (FILE*) param;
char *chaine = NULL; //juste pour que le code compile //char *chaine = NULL; //juste pour que le code compile
struct node *current; struct node *current;
current = malloc(sizeof(node_t)); current = malloc(sizeof(node_t));
...@@ -172,7 +177,7 @@ void *writing(void *param){ ...@@ -172,7 +177,7 @@ void *writing(void *param){
*current = *pr_divs->tail; *current = *pr_divs->tail;
current = current->next; current = current->next;
fprintf(file2,"%s",chaine); //fprintf(file2,"%s",chaine);
for (int i = 0; i < pr_divs->size; i++) for (int i = 0; i < pr_divs->size; i++)
{ {
fprintf(file2," %ld",current->value); fprintf(file2," %ld",current->value);
...@@ -184,48 +189,52 @@ void *writing(void *param){ ...@@ -184,48 +189,52 @@ void *writing(void *param){
} }
void *calculating(void *param){ void *calculating(void *param){
int i = 0;
while(i == 0){ //trouver une condition de fin de calcul !! while(buffer_1.stop == 0 || buffer_1.len > 0){
sem_wait(&full1); sem_wait(&full1);
pthread_mutex_lock(&mutex1); pthread_mutex_lock(&mutex1);
char *chaine = get_from_buffer_1(); char *chaine = get_from_buffer_1();
pthread_mutex_unlock(&mutex1); pthread_mutex_unlock(&mutex1);
struct queue *pr_divs; struct queue *pr_divs;
pr_divs = malloc(sizeof(queue_t)); pr_divs = malloc(sizeof(queue_t));
if (pr_divs == NULL){return NULL;} if (pr_divs == NULL){return NULL;}
pr_divs = prime_divs(strtol(chaine,NULL,0)); pr_divs = prime_divs(strtol(chaine,NULL,0));
char *ptr; /* char *ptr;
ptr = malloc(50); ptr = malloc(20);
ptr = strchr(chaine,'\n'); ptr = strchr(chaine,'\n');
*ptr = '\0'; *ptr = '\0'; */
//putting pr_divs in buffer #2 //putting pr_divs in buffer #2
sem_wait(&empty2); sem_wait(&empty2);
pthread_mutex_lock(&mutex2); pthread_mutex_lock(&mutex2);
put_in_buffer_2(pr_divs); //has to be implemented put_in_buffer_2(pr_divs);
pthread_mutex_unlock(&mutex2); pthread_mutex_unlock(&mutex2);
} }
buffer_2.stop = 1;
return NULL; return NULL;
} }
void *reading (void *param){ void *reading (void *param){
char *chaine = malloc(sizeof(char[20])); char chaine[20];
while (fgets(chaine,sizeof(char[20]),(FILE*)param) != NULL){
while (fgets(chaine,20,(FILE*)param) != NULL){
//put each line in the buffer #1
sem_wait(&empty1); sem_wait(&empty1);
pthread_mutex_lock(&mutex1); pthread_mutex_lock(&mutex1);
put_in_buffer_1(chaine); put_in_buffer_1(chaine); //put each line in the buffer #1
pthread_mutex_unlock(&mutex1); pthread_mutex_unlock(&mutex1);
sem_post(&full1); sem_post(&full1);
} }
buffer_1.stop = 1;
return NULL; return NULL;
} }
...@@ -242,16 +251,19 @@ void sem_initializer(void){ ...@@ -242,16 +251,19 @@ void sem_initializer(void){
} }
void buffer_initializer(void){ void buffer_initializer(void){
*buffer_1.tab = malloc(sizeof(char[8]));
buffer_1.size = 8; buffer_1.size = 8;
buffer_1.len = 0; buffer_1.len = 0;
buffer_1.head = 0; buffer_1.head = 0;
buffer_1.tail = 0; buffer_1.tail = 0;
buffer_1.stop = 0;
buffer_2.size = 8; buffer_2.size = 8;
buffer_2.len = 0; buffer_2.len = 0;
buffer_2.head = 0; buffer_2.head = 0;
buffer_2.tail = 0; buffer_2.tail = 0;
buffer_2.stop = 0;
} }
int run (char *input,char *output){ int run (char *input,char *output){
...@@ -273,20 +285,19 @@ int run (char *input,char *output){ ...@@ -273,20 +285,19 @@ int run (char *input,char *output){
pthread_t writer; pthread_t writer;
FILE *arg1 = file1; //FILE *arg2 = file2;
FILE *arg2 = file2;
buffer_initializer(); buffer_initializer();
sem_initializer(); sem_initializer();
pthread_create(&reader,NULL,&reading,&arg1); pthread_create(&reader,NULL,&reading,file1);
for (int i = 0; i < 4; i++) for (int i = 0; i < 4; i++)
{ {
pthread_create(&calculators[i],NULL,&calculating,NULL); pthread_create(&calculators[i],NULL,&calculating,NULL);
} }
pthread_create(&writer,NULL,&writing,&arg2); pthread_create(&writer,NULL,&writing,&file2);
pthread_join(reader,NULL); pthread_join(reader,NULL);
for (int i = 0; i < 4; i++) for (int i = 0; i < 4; i++)
......
...@@ -49,7 +49,7 @@ queue_t *get_from_buffer_2(void); ...@@ -49,7 +49,7 @@ queue_t *get_from_buffer_2(void);
int is_div(long number, long i); int is_div(long number, long i);
int is_prime(long number); int is_prime(long number);
int enqueue(queue_t* q, long val); void enqueue(queue_t* q, long val);
queue_t* prime_divs(long number); queue_t* prime_divs(long number);
void *reading (void *param); void *reading (void *param);
......
Fichier ajouté
...@@ -85,7 +85,7 @@ int main(){ ...@@ -85,7 +85,7 @@ int main(){
if (NULL == CU_add_test(pSuite,"test_is_div",test_is_div) || if (NULL == CU_add_test(pSuite,"test_is_div",test_is_div) ||
NULL == CU_add_test(pSuite, "test_is_prime",test_is_prime) || NULL == CU_add_test(pSuite, "test_is_prime",test_is_prime) ||
NULL == CU_add_test(pSuite, "test_is_not_prime",test_is_not_prime) NULL == CU_add_test(pSuite, "test_is_not_prime",test_is_not_prime)
//|| NULL == CU_add_test(pSuite,"file_test",file_test)) //|| NULL == CU_add_test(pSuite,"file_test",file_test)
) )
{ {
CU_cleanup_registry(); CU_cleanup_registry();
......
Fichier ajouté
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter