-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_common.c
79 lines (54 loc) · 1.51 KB
/
test_common.c
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
/*
* Copyright 2010 Abdelhalim Ragab ([email protected])
*
*
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "sstore.h"
int sstore_dev = -1;
/* test write operation */
void test_write(int index, int size, void *data, char need_close) {
int written = 0;
struct data_buffer buf;
sstore_dev = open("/dev/sstore0", O_RDWR, S_IRWXU);
if (sstore_dev < 0)
perror("opening sstore0");
buf.index = index;
buf.size = size;
buf.data = data;
printf("write to sstore0 index:%i size:%i ..\n", index, size);
written = write(sstore_dev, &buf, sizeof (struct data_buffer));
if (written < 0)
perror("write");
if (need_close)
close(sstore_dev);
}
/* test read() operation */
void test_read(int index, int size, void* data, char need_close) {
struct data_buffer buf;
sstore_dev = open("/dev/sstore0", O_RDONLY, S_IRWXU);
if (sstore_dev < 0)
perror("opening sstore0");
buf.index = index;
buf.size = size;
buf.data = data;
printf("read from sstore0 index:%i size:%i ..\n", index, size);
read(sstore_dev, &buf, sizeof (struct data_buffer));
if (need_close)
close(sstore_dev);
}
/* test delete ioctl */
void test_del(int index, char need_close) {
sstore_dev = open("/dev/sstore0", O_RDWR, S_IRWXU);
if (sstore_dev < 0)
perror("opening sstore0");
printf("delete from sstore0 index:%i..\n", index);
ioctl(sstore_dev, SSTORE_IOCREMOVE, &index);
if (need_close)
close(sstore_dev);
}