summaryrefslogtreecommitdiffstats
path: root/file_io/repeated_opens/test.c
blob: 5106621be0766e345b77d69bb3e9fa0356cf46f3 (plain) (blame)
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
/* Open/close test */

#include <rtems.h>
#include <rtems/clockdrv.h>
#include <rtems/console.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <memory.h>

#include <errno.h>
#include <stdlib.h>
#include <string.h>

rtems_task Init(rtems_task_argument a)
{
    int         i;
    int         fd;
    char        msg[16];
    int         len;
    int         l;

    printf("Open/close test (%d)\n",(int)a);

    strcpy(msg,"OK!\n");
    len = strlen(msg);

    for(i = 0; i < 10000; i++){
        fd = open("/tempfile",O_RDWR|O_CREAT, 0666);
        if(fd < 0){
            printf("open failed on %dth try (%s).\n",i, strerror(errno));
            continue;
        }
        l = write(fd,msg,len);
        if(l != len){
            printf("write failed on %dth try. (%d)\n",i,l);
            break;
        }
        close(fd);
        if ( i && (i%100 == 0)) printf("pass %d\n", i);
        
    }
    printf("Done.\n");
    exit(0);
}

/* NOTICE: the clock driver is explicitly disabled */
#define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER
#define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER

#define CONFIGURE_USE_IMFS_AS_BASE_FILESYSTEM

#define CONFIGURE_MAXIMUM_TASKS            1
#define CONFIGURE_LIBIO_MAXIMUM_FILE_DESCRIPTORS 4
#define CONFIGURE_RTEMS_INIT_TASKS_TABLE

#define CONFIGURE_INIT
#include <rtems/confdefs.h>