Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add code coverage for simgrid compilation
[simgrid.git] / buildtools / CPACK / prog_test / prog_AC_CHECK_MCSC.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <ucontext.h>
4
5 ucontext_t uc_child;
6 ucontext_t uc_main;
7
8 void child(void)
9 {
10     if (swapcontext(&uc_child, &uc_main) != 0)
11         exit(2);
12 }
13
14 int main(int argc, char *argv[])
15 {
16     FILE *fp;
17     void *stack;
18
19     /* the default is that it fails */
20     if ((fp = fopen("conftestval", "w")) == NULL)
21         exit(3);
22     fprintf(fp, "no\n");
23     fclose(fp);
24
25     /* configure a child user-space context */
26     if ((stack = malloc(64*1024)) == NULL)
27         exit(4);
28     if (getcontext(&uc_child) != 0)
29         exit(5);
30     uc_child.uc_link = NULL;
31     uc_child.uc_stack.ss_sp = (char *)stack+(32*1024);
32     uc_child.uc_stack.ss_size = 32*1024;
33     uc_child.uc_stack.ss_flags = 0;
34     makecontext(&uc_child, child, 0);
35
36     /* switch into the user context */
37     if (swapcontext(&uc_main, &uc_child) != 0)
38         exit(6);
39
40     /* Fine, child came home */
41     if ((fp = fopen("conftestval", "w")) == NULL)
42         exit(7);
43     fprintf(fp, "yes\n");
44     fclose(fp);
45
46     /* die successfully */
47     exit(0);
48 }