-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapplication.c
More file actions
111 lines (84 loc) · 2.6 KB
/
Copy pathapplication.c
File metadata and controls
111 lines (84 loc) · 2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*
BE Programmation système et concurrente
IENAC 12 L
Surveillance du fonctionnement d'une application
Application de test
Rev. : PRGCON-PTP-100-131220-131220-01
*/
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <unistd.h>
#include "fonction.h"
#define DEBUG 1
typedef
struct
{
int o;
int op1;
int op2;
} Parametres;
typedef
enum
{
OPERATION_0,
OPERATION_1,
OPERATION_2
} Operations;
int operation0( int a, int b )
{
printf( "- CRASHTEST > %s realisee\n", __FUNCTION__ );
return( a + b );
}
int operation1( int a, int b, int c )
{
unsigned int * p = NULL; /* Ne pas modifier ! */
unsigned int r;
srand( time( (time_t *) p ) );
if ((rand()%3)<2) /* L'application de test s'arretera sur une erreur avec une probabilite de 1/3 */
{
p = &r;
puts( "- CRASHTEST > l'application ne posera pas de probleme..." );
}
else
{
puts( "! CRASHTEST > l'application va s'arreter sur une erreur..." );
}
printf( "- CRASHTEST > P = %x\n", *p );
printf( "- CRASHTEST > %s realisee\n", __FUNCTION__ );
return( a * b + c );
}
int operation2( int a )
{
printf( "- CRASHTEST > %s realisee\n", __FUNCTION__ );
return( a * a );
}
int main( int argc, char ** argv )
{
Operations point_reprise = OPERATION_0;
Parametres parametres = { 1, 2, 3}; /* Valeurs modifiables a souhait */
if(DEBUG==1) printf("DEBUG : test 6, argument=%s\n",argv[0]);
point_reprise = initSurveillance(¶metres,sizeof(parametres));
puts( "_ CRASHTEST > Demarrage de la surveillance" );
switch( point_reprise )
{
case OPERATION_0 : printf( "_ CRASHTEST > Debut operation %d\n", point_reprise );
pointReprise(0,¶metres,sizeof(Parametres));
parametres.o = operation0( parametres.op1, parametres.op2 );
case OPERATION_1 : printf( "_ CRASHTEST > Debut operation %d\n", point_reprise );
pointReprise(1,¶metres,sizeof(Parametres));
parametres.o = operation1( parametres.op1, parametres.op2, parametres.o );
case OPERATION_2 : printf( "_ CRASHTEST > Debut operation %d\n", point_reprise );
pointReprise(2,¶metres,sizeof(Parametres));
parametres.o = operation2( parametres.o );
default : pointReprise(3,¶metres,sizeof(Parametres));
printf( "_ CRASHTEST > O = %d\n", parametres.o );
}
finAppli( );
puts( "_ CRASHTEST > Fin de la surveillance" );
return( EXIT_SUCCESS );
}
/*
Fin code
Application de test
*/