Add cpmodem_shim
Change-Id: I469fe04efac7b6636f9d2d1a8ae93c6c1ac30dc1
diff --git a/cpmodem_shim/cpmodem_test.c b/cpmodem_shim/cpmodem_test.c
new file mode 100755
index 0000000..f7f784d
--- /dev/null
+++ b/cpmodem_shim/cpmodem_test.c
@@ -0,0 +1,78 @@
+#include <stdio.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <string.h>
+#include <sys/ioctl.h>
+
+int main()
+{
+ int fdusb, fdpm;
+ int i;
+
+ if ( (fdusb = open("/dev/cp_lkm_usb", O_RDWR)) < 0 ) {
+ printf("%s() open failed\n", __FUNCTION__);
+ return fdusb;
+ }
+
+ if ( (fdpm = open("/dev/cp_lkm_pm", O_RDWR)) < 0 ) {
+ printf("%s() open failed\n", __FUNCTION__);
+ close(fdusb);
+ return fdpm;
+ }
+
+ printf("testing write fd:%d\n", fdusb);
+ char buffer[52];
+ for (i=0; i < 52; i++) {
+ if (i < 26) {
+ buffer[i] = 'A' + i;
+ } else {
+ buffer[i] = 'a' + i;
+ }
+ }
+ int nwrite = write(fdusb, buffer, 52);
+ if (nwrite != 52) {
+ printf("%s() - write error -> %d of %d written\n", __FUNCTION__, nwrite, 52);
+ }
+
+ printf("testing write fd:%d\n", fdpm);
+ char bufferpm[26];
+ for (i=0; i < 26; i++) {
+ bufferpm[i] = 'a' + i;
+ }
+ nwrite = write(fdpm, bufferpm, 26);
+ if (nwrite != 26) {
+ printf("%s() - write error -> %d of %d written\n", __FUNCTION__, nwrite, 26);
+ }
+
+ char read_buffer[52];
+ int nread = read(fdusb, read_buffer, 52);
+ if (nread != 52) {
+ printf("%s() - read error -> %d of %d read\n", __FUNCTION__, nread, 52);
+ }
+ if (memcmp(buffer, read_buffer, 52)) {
+ printf("%s() - read/write memcmp failed\n", __FUNCTION__);
+ } else {
+ printf("%s() - read/write memcmp succeeded\n", __FUNCTION__);
+ }
+
+ nread = read(fdpm, read_buffer, 26);
+ if (nread != 26) {
+ printf("%s() - read error -> %d of %d read\n", __FUNCTION__, nread, 26);
+ }
+ if (memcmp(bufferpm, read_buffer, 26)) {
+ printf("%s() - read/write memcmp failed %s\n", __FUNCTION__, read_buffer);
+ } else {
+ printf("%s() - read/write memcmp succeeded\n", __FUNCTION__);
+ }
+
+
+ printf("%s() - testing ioctl\n", __FUNCTION__);
+
+ int ioctl_resl = ioctl(fdusb, 322, 0xdeadbeef);
+ printf("%s() - ioctl resl:%d\n", __FUNCTION__, ioctl_resl);
+
+ close(fdusb);
+ close(fdpm);
+
+ return 0;
+}