]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - keystone-rtos/netapi.git/blobdiff - ti/runtime/netapi/OLD/shmtest.c
Merge branch 'master' of gtgit01.gt.design.ti.com:git/projects/netapi
[keystone-rtos/netapi.git] / ti / runtime / netapi / OLD / shmtest.c
diff --git a/ti/runtime/netapi/OLD/shmtest.c b/ti/runtime/netapi/OLD/shmtest.c
new file mode 100755 (executable)
index 0000000..f4c9479
--- /dev/null
@@ -0,0 +1,118 @@
+/*************************************************\r
+* FILE:  shmtest.c\r
+ * \r
+ * DESCRIPTION:  netapi user space transport\r
+ *               library  test application (not used, kept as refenence)\r
+ * \r
+ * REVISION HISTORY:  rev 0.0.1 \r
+ *\r
+ *  Copyright (c) Texas Instruments Incorporated 2010-2011\r
+ * \r
+ *  Redistribution and use in source and binary forms, with or without \r
+ *  modification, are permitted provided that the following conditions \r
+ *  are met:\r
+ *\r
+ *    Redistributions of source code must retain the above copyright \r
+ *    notice, this list of conditions and the following disclaimer.\r
+ *\r
+ *    Redistributions in binary form must reproduce the above copyright\r
+ *    notice, this list of conditions and the following disclaimer in the \r
+ *    documentation and/or other materials provided with the   \r
+ *    distribution.\r
+ *\r
+ *    Neither the name of Texas Instruments Incorporated nor the names of\r
+ *    its contributors may be used to endorse or promote products derived\r
+ *    from this software without specific prior written permission.\r
+ *\r
+ *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \r
+ *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT \r
+ *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\r
+ *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT \r
+ *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, \r
+ *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT \r
+ *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
+ *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
+ *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT \r
+ *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE \r
+ *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+ **********************************************************************/\r
+\r
+\r
+#include <stdlib.h>\r
+#include <sys/shm.h>\r
+#include <errno.h>\r
+\r
+ char * p= NULL;\r
+main(int argc, char * argv[])\r
+{\r
+int fd;\r
+int op=0;\r
+int name = 0xfeed;\r
+int err;\r
+if (argc<3) {printf("shmtest  (c[reate]| d[delete]| o[open])  key\n"); exit(1);}\r
+\r
+\r
+switch (argv[1][0])\r
+{\r
+case 'D':\r
+case 'd':\r
+       op =2; //delete\r
+       break;\r
+case 'c':\r
+case 'C':\r
+       op =0; //create\r
+       break;\r
+case 'o':\r
+case 'O':\r
+       op =1; //open\r
+        break;\r
+default:\r
+printf(" unknown op code %c.  Need d, o, or c\n", argv[1][0]);\r
+exit(1);\r
+break;\r
+}\r
+\r
+name = atoi(argv[2]); printf("key = %d op=%d\n", name,op);\r
+switch (op)\r
+{\r
+case(1): /* open */\r
+default:\r
+       fd = shmget( (key_t) name, 100000, 0666 );\r
+       if (fd <0) {\r
+          perror(" shget open failed\n"); \r
+          exit( 1);\r
+        }\r
+        break;\r
+\r
+case(0): /* create */\r
+  fd = shmget(name, 100000, IPC_CREAT | 0666 );\r
+  if (fd<0) {perror(" shget create failed , exiting "); exit(1);}\r
+  break;\r
+\r
+case(2):\r
+   fd = shmget( (key_t) name, 100000, 0666 );\r
+  if (fd <0) {\r
+      perror(" delete: shget open failed\n");\r
+      exit( 1);\r
+  }\r
+  err=shmctl(fd, IPC_RMID, 0);\r
+  if(err<0) {perror("ctl failed: ");}\r
+  exit( 0);  //all we do \r
+  break;\r
+}\r
+\r
+/* map into us */  \r
+p = shmat(fd, 0, 0);\r
+if (p == -1) {\r
+perror("shmat failed\n"); exit(1);\r
+}\r
+ else {printf("mapped to %x\n",p);}\r
+\r
+if (op==1) { printf("got something: %s\n", p);}\r
+else if(op==0) \r
+{\r
+sprintf(p,"created some shared memory, key=%d...\n",name); \r
+printf("creating shm ok: %s",p);\r
+}\r
+\r
+}\r