aboutsummaryrefslogtreecommitdiffstats
path: root/src/tests/klaar/pfs-writer.c
blob: 34d9685cabf7192ef3f0e94d2fae5166fe5bee7c (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
/* Part of pfs.c suite.

   Write on the disk. Each time the buffer is filled with same
   character. Different character every time!
 */

#include <syscall.h>
#include <stdio.h>
#include <string.h>

#include "../lib.h"
#include "pfs.h"

static void fill_buffer(char* buf, int size, char c)
{
  for (int i = 0; i < size; i++)
  {
    buf[i] = c;
  }
}

char buffer[BIG];

int main (int argc, char *argv[]) 
{
  test_name = argv[0];
  quiet = true;

  if (argc != 3 || strlen(argv[1]) != 1 || strlen(argv[2]) != 1)
    return 1;
  
  char start = argv[1][0];
  char end   = argv[2][0];

  char c = start;
  for (int i = 0; i < TIMES; ++i)
  {
    fill_buffer(buffer, BIG, c);
    
    int id = open ("file.1");
    CHECK ( id > 1, "open \"file.1\"");    
    int bytes = write(id, buffer, BIG);
    CHECK ( bytes == BIG, "write \"file.1\"");
    close(id);

    c = c + 1;
    
    if ( c > end )
      c = start;
  }
  return 0;
}