blob: f7f784d688fdc88939e2ae66884251003f8617c6 [file] [log] [blame]
Kyle Swenson74ad7532023-02-16 11:05:29 -07001#include <stdio.h>
2#include <fcntl.h>
3#include <unistd.h>
4#include <string.h>
5#include <sys/ioctl.h>
6
7int main()
8{
9 int fdusb, fdpm;
10 int i;
11
12 if ( (fdusb = open("/dev/cp_lkm_usb", O_RDWR)) < 0 ) {
13 printf("%s() open failed\n", __FUNCTION__);
14 return fdusb;
15 }
16
17 if ( (fdpm = open("/dev/cp_lkm_pm", O_RDWR)) < 0 ) {
18 printf("%s() open failed\n", __FUNCTION__);
19 close(fdusb);
20 return fdpm;
21 }
22
23 printf("testing write fd:%d\n", fdusb);
24 char buffer[52];
25 for (i=0; i < 52; i++) {
26 if (i < 26) {
27 buffer[i] = 'A' + i;
28 } else {
29 buffer[i] = 'a' + i;
30 }
31 }
32 int nwrite = write(fdusb, buffer, 52);
33 if (nwrite != 52) {
34 printf("%s() - write error -> %d of %d written\n", __FUNCTION__, nwrite, 52);
35 }
36
37 printf("testing write fd:%d\n", fdpm);
38 char bufferpm[26];
39 for (i=0; i < 26; i++) {
40 bufferpm[i] = 'a' + i;
41 }
42 nwrite = write(fdpm, bufferpm, 26);
43 if (nwrite != 26) {
44 printf("%s() - write error -> %d of %d written\n", __FUNCTION__, nwrite, 26);
45 }
46
47 char read_buffer[52];
48 int nread = read(fdusb, read_buffer, 52);
49 if (nread != 52) {
50 printf("%s() - read error -> %d of %d read\n", __FUNCTION__, nread, 52);
51 }
52 if (memcmp(buffer, read_buffer, 52)) {
53 printf("%s() - read/write memcmp failed\n", __FUNCTION__);
54 } else {
55 printf("%s() - read/write memcmp succeeded\n", __FUNCTION__);
56 }
57
58 nread = read(fdpm, read_buffer, 26);
59 if (nread != 26) {
60 printf("%s() - read error -> %d of %d read\n", __FUNCTION__, nread, 26);
61 }
62 if (memcmp(bufferpm, read_buffer, 26)) {
63 printf("%s() - read/write memcmp failed %s\n", __FUNCTION__, read_buffer);
64 } else {
65 printf("%s() - read/write memcmp succeeded\n", __FUNCTION__);
66 }
67
68
69 printf("%s() - testing ioctl\n", __FUNCTION__);
70
71 int ioctl_resl = ioctl(fdusb, 322, 0xdeadbeef);
72 printf("%s() - ioctl resl:%d\n", __FUNCTION__, ioctl_resl);
73
74 close(fdusb);
75 close(fdpm);
76
77 return 0;
78}