[Feature][ZXW-88]merge P50 version
Only Configure: No
Affected branch: master
Affected module: unknown
Is it affected on both ZXIC and MTK: only ZXIC
Self-test: Yes
Doc Update: No
Change-Id: I34667719d9e0e7e29e8e4368848601cde0a48408
diff --git a/ap/app/shm_test/Makefile b/ap/app/shm_test/Makefile
index 0e1093f..90a203f 100755
--- a/ap/app/shm_test/Makefile
+++ b/ap/app/shm_test/Makefile
@@ -3,8 +3,21 @@
include $(COMMON_MK)
##############USER COMIZE BEGIN################
-EXEC = shm_test
-OBJS = shm_test.o
+EXEC1 = shm_read
+OBJS1 = shm_read.o
+
+EXEC2 = shm_write
+OBJS2 = shm_write.o
+EXEC3 = shm_test
+OBJS3 = shm_test.o
+EXEC4 = shm_posix_test
+OBJS4 = shm_posix_test.o
+
+EXEC5 = shm_posix_read
+OBJS5 = shm_posix_read.o
+
+EXEC6 = shm_posix_write
+OBJS6 = shm_posix_write.o
CFLAGS += -I.
CFLAGS += -I$(APP_DIR)/include
@@ -12,23 +25,45 @@
CFLAGS += -g -Werror=implicit-function-declaration
-LDLIBS += -lpthread
+LDLIBS += -lpthread -lrt
##############USER COMIZE END##################
#*******************************************************************************
# targets
#*******************************************************************************
-all: $(EXEC)
+all: $(EXEC1) $(EXEC2) $(EXEC3) $(EXEC4) $(EXEC5) $(EXEC6)
-$(EXEC): $(OBJS)
+$(EXEC1): $(OBJS1)
$(CC) $(LDFLAGS) -o $@ $^ -Wl,--start-group $(LDLIBS) $(LDLIBS_$@) -Wl,--end-group
@cp $@ $@.elf
+$(EXEC2): $(OBJS2)
+ $(CC) $(LDFLAGS) -o $@ $^ -Wl,--start-group $(LDLIBS) $(LDLIBS_$@) -Wl,--end-group
+ @cp $@ $@.elf
+$(EXEC3): $(OBJS3)
+ $(CC) $(LDFLAGS) -o $@ $^ -Wl,--start-group $(LDLIBS) $(LDLIBS_$@) -Wl,--end-group
+ @cp $@ $@.elf
+
+$(EXEC4): $(OBJS4)
+ $(CC) $(LDFLAGS) -o $@ $^ -Wl,--start-group $(LDLIBS) $(LDLIBS_$@) -Wl,--end-group
+ @cp $@ $@.elf
+
+$(EXEC5): $(OBJS5)
+ $(CC) $(LDFLAGS) -o $@ $^ -Wl,--start-group $(LDLIBS) $(LDLIBS_$@) -Wl,--end-group
+ @cp $@ $@.elf
+
+$(EXEC6): $(OBJS6)
+ $(CC) $(LDFLAGS) -o $@ $^ -Wl,--start-group $(LDLIBS) $(LDLIBS_$@) -Wl,--end-group
+ @cp $@ $@.elf
romfs:
- $(ROMFSINST) $(EXEC) /bin/$(EXEC)
-
+ $(ROMFSINST) $(EXEC1) /bin/$(EXEC1)
+ $(ROMFSINST) $(EXEC2) /bin/$(EXEC2)
+ $(ROMFSINST) $(EXEC3) /bin/$(EXEC3)
+ $(ROMFSINST) $(EXEC4) /bin/$(EXEC4)
+ $(ROMFSINST) $(EXEC5) /bin/$(EXEC5)
+ $(ROMFSINST) $(EXEC6) /bin/$(EXEC6)
+
clean:
- -@rm -f $(EXEC) *.elf *.gdb *.o
-
+ -@rm -f $(EXEC1) $(EXEC2) $(EXEC3) $(EXEC4) $(EXEC5) $(EXEC6) *.elf *.gdb *.o
\ No newline at end of file
diff --git a/ap/app/shm_test/shm_posix_read.c b/ap/app/shm_test/shm_posix_read.c
new file mode 100755
index 0000000..15576f3
--- /dev/null
+++ b/ap/app/shm_test/shm_posix_read.c
@@ -0,0 +1,170 @@
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <signal.h>
+#include <time.h>
+#include <pthread.h>
+#include <sys/prctl.h>
+#include <sys/ipc.h>
+#include <sys/shm.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <assert.h>
+#include <sys/mman.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+/**
+ * ºê¶¨Òå
+ */
+#define SHM_NAME_SIZE (128)
+#define SHM_TEXT_SIZE (8192)
+#define SHM_PAGE_SIZE (4096)
+#define SHM_ALLOC_ONE_PAGE_SIZE (1024)
+#define SHM_ALLOC_TWO_PAGE_SIZE (8100)
+#define SHM_ALLOC_FOUR_PAGE_SIZE (16000)
+#define SHM_NAME_CROSS_PREFIX ("remote-")
+
+/**
+ * Êý¾ÝÀàÐͶ¨Òå
+ */
+typedef int bool;
+enum
+{
+ FALSE,
+ TRUE
+};
+
+typedef struct
+{
+ unsigned int shm_size;
+ char name[SHM_NAME_SIZE];
+}shm_node_t;
+
+typedef struct
+{
+ int write;
+ char data[SHM_TEXT_SIZE];
+}shm_use_remote;
+
+shm_node_t shm_node;
+
+bool shm_is_remote(const char *shm_name)
+{
+ if (!shm_name)
+ return FALSE;
+ if (strncmp(shm_name, SHM_NAME_CROSS_PREFIX, strlen(SHM_NAME_CROSS_PREFIX)) == 0)
+ return TRUE;
+ else
+ return FALSE;
+}
+
+int main (int argc, char *argv[])
+{
+ int opt;
+ int shmfd = 0;
+ int ret = 0;
+ unsigned int shm_size = 0;
+ char *name = NULL;
+ char *pshm = NULL;
+ char *read_data = NULL;
+ extern char *optarg;
+
+ shm_use_remote *shared;
+
+ while ((opt = getopt(argc,argv,"n:d:s::")) != EOF)
+ {
+ switch (opt)
+ {
+ case 'n':
+ name = optarg;
+ break;
+ case 'd':
+ read_data = optarg;
+ break;
+ case 's':
+ shm_size = atoi(optarg);
+ break;
+ default:
+ break;
+ }
+ }
+
+ if (!name || !read_data)
+ {
+ printf("param error: you can input \"shm_posix_read -n \"remote-shm_test\" -d \"123456\" -s1024 \n");
+ printf("or \"shm_posix_read -n \"remote-shm_test\" -d \"123456\" \n");
+ printf("-n \"remote-shm_test\": create a shm using name remote-shm_test\n");
+ printf("-d \"123456\": if we write 123456 to shm, then can read 123456 form shm, the test case is pass! \n");
+ printf("-s1024: set the size of shm, then the default size is 1024 \n");
+ return -1;
+ }
+
+ if (shm_size == 0)
+ shm_size = SHM_ALLOC_ONE_PAGE_SIZE;
+
+ printf("AP read test: name is %s, shm_size is %d\n", name, shm_size);
+
+ shmfd = shm_open(name, O_CREAT | O_RDWR, 0666);
+ if(shmfd < 0)
+ {
+ perror("shm_open fail\n");
+ exit(1);
+ }
+ printf("shm_open return ok\n");
+
+ if(ftruncate(shmfd, shm_size) == -1)
+ {
+ perror("ftruncate fail\n");
+ exit(1);
+ }
+
+ pshm = (char *)mmap(NULL, shm_size, PROT_READ|PROT_WRITE, MAP_SHARED, shmfd, 0);
+ if (pshm == MAP_FAILED)
+ {
+ perror("mmap fail\n");
+ exit(1);
+ }
+ printf("mmap return ok\n");
+ shm_node.shm_size = shm_size;
+ strncpy(shm_node.name, name, SHM_NAME_SIZE-1);
+
+ shared = (shm_use_remote *)pshm;
+ shared->write = 1;
+ printf("read_data %s ok\n", read_data);
+
+ while(1)
+ {
+ if(strncmp(shared->data, read_data, sizeof(read_data)) == 0)
+ {
+ printf("Success, AP read %s from shm\n", read_data);
+ break;
+ }
+ else
+ sleep(2);
+ }
+
+ ret = munmap(pshm, shm_size);
+ if(ret < 0)
+ {
+ printf("munmap return errno %d: %s\n", errno, strerror(errno));
+ exit(1);
+ }
+
+ if(shm_is_remote(name))
+ {
+ ret = shm_unlink(name);
+ if(ret < 0)
+ {
+ printf("shm_unlink errno %d: %s\n", errno, strerror(errno));
+ exit(1);
+ }
+ }
+ close(shmfd);
+
+ printf("shm posix read end\n");
+ return 0;
+}
+
diff --git a/ap/app/shm_test/shm_posix_test.c b/ap/app/shm_test/shm_posix_test.c
new file mode 100755
index 0000000..eec9f8e
--- /dev/null
+++ b/ap/app/shm_test/shm_posix_test.c
@@ -0,0 +1,288 @@
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <signal.h>
+#include <time.h>
+#include <pthread.h>
+#include <sys/prctl.h>
+#include <sys/ipc.h>
+#include <sys/shm.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <assert.h>
+#include <sys/mman.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+/**
+ * ºê¶¨Òå
+ */
+#define SHM_TEST_ALLOC_THREAD (0)
+#define SHM_TEST_MEMGET_THREAD (1)
+#define SHM_TEST_UNLINK_THREAD (2)
+#define SHM_TEST_TRANS_THREAD (3)
+#define SHM_TEST_THREAD_NUM (4)
+#define SHM_TEST_STR_NUM (20)
+#define SHM_TEST_CAP_INIT_VALUE (0x16)
+
+#define SHM_TEST_MARK_0X1 (0x1)
+#define SHM_TEST_MARK_0X3 (0x3)
+#define SHM_TEST_MARK_0X5 (0x5)
+#define SHM_TEST_MARK_0X7 (0x7)
+#define SHM_TEST_MARK_NUM (0xA)
+
+#define SHM_PAGE_SIZE (4096)
+#define SHM_ALLOC_ONE_PAGE_SIZE (1024)
+#define SHM_ALLOC_TWO_PAGE_SIZE (8100)
+#define SHM_ALLOC_FOUR_PAGE_SIZE (16000)
+
+#define SHM_TEST_READ_FROM_SHM_PAGE0 (0x0A)
+#define SHM_TEST_WRITE_TO_SHM_PAGE1 (0x1B)
+#define SHM_TEST_READ_FROM_SHM_PAGE2 (0x2A)
+#define SHM_TEST_WRITE_TO_SHM_PAGE3 (0x3B)
+
+#define SHM_IPC_FILE_NAME "remote-posix_test"
+#define SHM_TRANS_FILE_NAME "remote-posix_transfer"
+
+/**
+ * È«¾Ö±äÁ¿¶¨Òå
+ */
+pthread_t shm_pcross_thread;
+pthread_t shm_unlink_thread;
+
+int g_shmfd[SHM_TEST_THREAD_NUM] = {0};
+char *g_pshm[SHM_TEST_THREAD_NUM] = {NULL};
+int g_mark_path[SHM_TEST_MARK_NUM] = {0xFFFF};
+
+void *ap_shm_fourpage_cross(void* args)
+{
+ int i = 0;
+ int ret = 0;
+ int shmfd = 0;
+ char test_num = 0;
+ char *pshm = NULL;
+ struct stat buf;
+
+ prctl(PR_SET_NAME, "shm_posix_trans_task");
+
+ shmfd = shm_open(SHM_TRANS_FILE_NAME, O_CREAT | O_RDWR, 0666);
+ if(shmfd < 0)
+ {
+ printf("shm_open return error\n");
+ assert(0);
+ }
+
+ if(ftruncate(shmfd, SHM_ALLOC_FOUR_PAGE_SIZE) == -1)
+ {
+ perror("ftruncate failed\n");
+ exit(1);
+ }
+
+ if (fstat(shmfd, &buf) == -1)
+ {
+ printf("fstat error\n");
+ }
+ printf("size = %d, mode = %o\n",buf.st_size, buf.st_mode & 0777);
+
+ pshm = (char *)mmap(NULL, SHM_ALLOC_FOUR_PAGE_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, shmfd, 0);
+ if (pshm == NULL)
+ {
+ perror("mmap failed\n");
+ exit(1);
+ }
+ g_shmfd[SHM_TEST_TRANS_THREAD] = shmfd;
+ g_pshm[SHM_TEST_TRANS_THREAD] = pshm;
+
+ for(;;)
+ {
+ while(1)
+ {
+ test_num = *(char *)pshm;
+ if(test_num == SHM_TEST_READ_FROM_SHM_PAGE0)
+ {
+ *(char *)(pshm + SHM_PAGE_SIZE) = SHM_TEST_WRITE_TO_SHM_PAGE1;
+ g_mark_path[2] = SHM_TEST_READ_FROM_SHM_PAGE0;
+ printf("shmat test_num, AP write %x to shm\n",SHM_TEST_WRITE_TO_SHM_PAGE1);
+ break;
+ }
+ sleep(2);
+ }
+ while(1)
+ {
+ test_num = *(char *)(pshm + 2 * SHM_PAGE_SIZE);
+ if(test_num == SHM_TEST_READ_FROM_SHM_PAGE2)
+ {
+ *(char *)(pshm + 3 * SHM_PAGE_SIZE) = SHM_TEST_WRITE_TO_SHM_PAGE3;
+ g_mark_path[4] = SHM_TEST_READ_FROM_SHM_PAGE2;
+ printf("shmat test_num, AP write %x to shm\n", SHM_TEST_WRITE_TO_SHM_PAGE3);
+ break;
+ }
+ sleep(2);
+ }
+ if (i++ >= 10)
+ break;
+ }
+ ret = munmap(pshm, SHM_ALLOC_FOUR_PAGE_SIZE);
+ if(ret < 0)
+ {
+ printf("munmap errno %d: %s\n", errno, strerror(errno));
+ exit(1);
+ }
+ printf("munmap return ok\n");
+
+ ret = shm_unlink(SHM_TRANS_FILE_NAME);
+ if(ret < 0)
+ {
+ printf("shm_unlink errno %d: %s\n", errno, strerror(errno));
+ return -1;
+ }
+
+ printf("shm_unlink return ok\n");
+ close(shmfd);
+ while(1)
+ {
+ sleep(5);
+ }
+}
+
+void *ap_write_and_unlink(void* args)
+{
+ int shmfd = 0;
+ int ret = 0;
+ char *pshm = NULL;
+ struct stat buf;
+ int test_num = 0;
+
+ prctl(PR_SET_NAME, "shm_posix_task");
+
+ shmfd = shm_open(SHM_IPC_FILE_NAME, O_CREAT | O_RDWR, 0666);
+ if(shmfd < 0)
+ {
+ printf("shm_open return error\n");
+ assert(0);
+ }
+
+ if(ftruncate(shmfd, SHM_ALLOC_TWO_PAGE_SIZE) == -1)
+ {
+ perror("ftruncate failed\n");
+ exit(1);
+ }
+
+ if (fstat(shmfd, &buf) == -1)
+ {
+ printf("fstat error\n");
+ }
+ printf("size = %d, mode = %o\n",buf.st_size, buf.st_mode & 0777);
+
+ pshm = (char *)mmap(NULL, SHM_ALLOC_TWO_PAGE_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, shmfd, 0);
+ if (pshm == MAP_FAILED)
+ {
+ perror("mmap failed\n");
+ exit(1);
+ }
+
+ g_shmfd[SHM_TEST_ALLOC_THREAD] = shmfd;
+ g_pshm[SHM_TEST_ALLOC_THREAD] = pshm;
+
+ while(1)
+ {
+ test_num = *(int *)pshm;
+ if(test_num == SHM_TEST_CAP_INIT_VALUE)
+ {
+ *(int *)pshm = SHM_TEST_MARK_0X1 + 1;
+ g_mark_path[1] = SHM_TEST_MARK_0X1;
+ printf("shmat test_num 0x16, g_mark_path[1] = %x\n", g_mark_path[1]);
+ break;
+ }
+ sleep(1);
+ }
+
+ while(1)
+ {
+ test_num = *(int *)pshm;
+ if(test_num == SHM_TEST_MARK_0X3)
+ {
+ *(int *)pshm = SHM_TEST_MARK_0X3 + 1;
+ g_mark_path[3] = SHM_TEST_MARK_0X3;
+ printf("shmat test_num 3, g_mark_path[3] before= %x\n", g_mark_path[3]);
+ break;
+ }
+ sleep(1);
+ }
+
+ while(1)
+ {
+ test_num = *(int *)pshm;
+ if(test_num == SHM_TEST_MARK_0X5)
+ {
+ *(int *)pshm = SHM_TEST_MARK_0X5 + 1;
+ g_mark_path[5] = SHM_TEST_MARK_0X5;
+ printf("shmat test_num 5, g_mark_path5 before= %x\n", g_mark_path[5]);
+ break;
+ }
+ sleep(1);
+ }
+
+ while(1)
+ {
+ test_num = *(int *)pshm;
+ if(test_num == SHM_TEST_MARK_0X7)
+ {
+ *(int *)pshm = SHM_TEST_MARK_0X7 + 1;
+ g_mark_path[7] = SHM_TEST_MARK_0X7;
+ printf("shmat test_num 7, g_mark_path7 before= %x\n", g_mark_path[7]);
+ break;
+ }
+ sleep(1);
+ }
+ memcpy(pshm + 32, "123456", SHM_TEST_STR_NUM);
+
+ ret = munmap(pshm, SHM_ALLOC_TWO_PAGE_SIZE);
+ if(ret < 0)
+ {
+ printf("munmap errno %d: %s\n", errno, strerror(errno));
+ exit(1);
+ }
+ ret = shm_unlink(SHM_IPC_FILE_NAME);
+ if(ret < 0)
+ {
+ printf("shm_unlink errno %d: %s\n", errno, strerror(errno));
+ assert(0);
+ }
+ close(shmfd);
+
+ while(1)
+ {
+ sleep(5);
+ }
+ return 0;
+}
+
+
+int main (int argc, char *argv[])
+{
+ int ret = 0;
+
+ ret = pthread_create(&shm_pcross_thread, NULL, ap_shm_fourpage_cross, NULL);
+ if(ret != 0)
+ {
+ printf("pthread_create shm_pcross_thread error\n");
+ }
+
+ ret = pthread_create(&shm_unlink_thread, NULL, ap_write_and_unlink, NULL);
+ if(ret != 0)
+ {
+ printf("pthread_create shm_unlink_thread error\n");
+ }
+
+ if(shm_pcross_thread > 0)
+ pthread_join(shm_pcross_thread, NULL);
+
+ if(shm_unlink_thread > 0)
+ pthread_join(shm_unlink_thread, NULL);
+
+ return 0;
+}
+
diff --git a/ap/app/shm_test/shm_posix_write.c b/ap/app/shm_test/shm_posix_write.c
new file mode 100755
index 0000000..4752fc1
--- /dev/null
+++ b/ap/app/shm_test/shm_posix_write.c
@@ -0,0 +1,150 @@
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <signal.h>
+#include <time.h>
+#include <pthread.h>
+#include <sys/prctl.h>
+#include <sys/ipc.h>
+#include <sys/shm.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <assert.h>
+#include <sys/mman.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+/**
+ * ºê¶¨Òå
+ */
+#define SHM_NAME_SIZE (128)
+#define SHM_TEXT_SIZE (8192)
+#define SHM_PAGE_SIZE (4096)
+#define SHM_ALLOC_ONE_PAGE_SIZE (1024)
+#define SHM_ALLOC_TWO_PAGE_SIZE (8100)
+#define SHM_ALLOC_FOUR_PAGE_SIZE (16000)
+#define SHM_MIN(x,y) ((x)<(y)?(x):(y))
+
+typedef struct
+{
+ unsigned int shm_size;
+ char name[SHM_NAME_SIZE];
+}shm_node_t;
+
+typedef struct
+{
+ int write;
+ char data[SHM_TEXT_SIZE];
+}shm_use_remote;
+
+shm_node_t shm_node;
+
+int main (int argc, char *argv[])
+{
+ int opt;
+ int ret = 0;
+ int copy_size = 0;
+ unsigned int shm_size = 0;
+ int shmfd = 0;
+ char *name = NULL;
+ char *pshm = NULL;
+ char *write_data = NULL;
+ extern char *optarg;
+ shm_use_remote *shared;
+
+ while ((opt = getopt(argc,argv,"n:d:s::")) != EOF)
+ {
+ switch (opt)
+ {
+ case 'n':
+ name = optarg;
+ break;
+ case 'd':
+ write_data = optarg;
+ break;
+ case 's':
+ shm_size = atoi(optarg);
+ break;
+ default:
+ break;
+ }
+ }
+
+ if (!name || !write_data)
+ {
+ printf("param error: you can input \"shm_posix_write -n \"remote-shm_test\" -d \"123456\" -s1024 \n");
+ printf("or \"shm_posix_write -n \"remote-shm_test\" -d \"123456\" \n");
+ printf("-k -200: create a shm using name remote-shm_test\n");
+ printf("-d \"123456\": the data write to shm: for example, if we write 123456 to shm, then can read 123456 form shm, the test case is pass! \n");
+ printf("-s1024: set the size of shm, then the default size is 1024 \n");
+ return -1;
+ }
+ if (shm_size == 0)
+ shm_size = SHM_ALLOC_ONE_PAGE_SIZE;
+
+ printf("AP write test: name is %s, shm_size is %d\n", name, shm_size);
+
+ shmfd = shm_open(name, O_CREAT | O_RDWR, 0666);
+ if(shmfd < 0)
+ {
+ printf("shm_open return error\n");
+ assert(0);
+ }
+ printf("AP write test: shm_open shmfd %d\n",shmfd);
+
+ if(ftruncate(shmfd, shm_size) == -1)
+ {
+ perror("ftruncate failed\n");
+ exit(1);
+ }
+
+ pshm = (char *)mmap(NULL, shm_size, PROT_READ|PROT_WRITE, MAP_SHARED, shmfd, 0);
+ if (pshm == MAP_FAILED)
+ {
+ perror("mmap failed\n");
+ exit(1);
+ }
+ shm_node.shm_size = shm_size;
+ strncpy(shm_node.name, name, SHM_NAME_SIZE-1);
+
+ printf("AP write test : mmap return ok\n");
+ shared = (shm_use_remote *)pshm;
+ copy_size = SHM_MIN(strlen(write_data), (SHM_TEXT_SIZE - 1));
+
+ printf("AP write test : shared->write %d\n",shared->write);
+
+ while(1)
+ {
+ if(shared->write == 1)
+ {
+ strncpy(shared->data, write_data, copy_size);
+ printf("AP write %s to shm\n", write_data);
+ shared->write = 0;
+ break;
+ }
+ else{
+ sleep(2);
+ }
+ }
+ ret = munmap(pshm, shm_size);
+ if(ret < 0)
+ {
+ printf("munmap errno %d: %s\n", errno, strerror(errno));
+ exit(1);
+ }
+
+ ret = shm_unlink(name);
+ if(ret < 0)
+ {
+ printf("shm_unlink errno %d: %s\n", errno, strerror(errno));
+ }
+ close(shmfd);
+
+ printf("shm posix write end\n");
+
+ return 0;
+}
+
+
diff --git a/ap/app/shm_test/shm_read.c b/ap/app/shm_test/shm_read.c
new file mode 100755
index 0000000..ccf6a83
--- /dev/null
+++ b/ap/app/shm_test/shm_read.c
@@ -0,0 +1,134 @@
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <signal.h>
+#include <time.h>
+#include <pthread.h>
+#include <sys/prctl.h>
+#include <sys/ipc.h>
+#include <sys/shm.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <assert.h>
+#include <sys/mman.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+/**
+ * ºê¶¨Òå
+ */
+#define SHM_TEXT_SIZE (8192)
+#define SHM_PAGE_SIZE (4096)
+#define SHM_ALLOC_ONE_PAGE_SIZE (1024)
+#define SHM_ALLOC_TWO_PAGE_SIZE (8100)
+#define SHM_ALLOC_FOUR_PAGE_SIZE (16000)
+
+typedef struct
+{
+ key_t key;
+ int shmid;
+ unsigned int shm_size;
+}shm_node_t;
+
+typedef struct
+{
+ int write;
+ char data[SHM_TEXT_SIZE];
+}shm_use_remote;
+
+shm_node_t shm_node;
+
+int main (int argc, char *argv[])
+{
+ int opt;
+ int ret = 0;
+ int shmid = 0;
+ unsigned int shm_size = 0;
+ key_t key = 0;
+ char *pshm = NULL;
+ char *read_data = NULL;
+ extern char *optarg;
+
+ shm_use_remote *shared;
+
+ while ((opt = getopt(argc,argv,"k:d:s::")) != EOF)
+ {
+ switch (opt)
+ {
+ case 'k':
+ key = atoi(optarg);
+ break;
+ case 'd':
+ read_data = optarg;
+ break;
+ case 's':
+ shm_size = atoi(optarg);
+ break;
+ default:
+ break;
+ }
+ }
+
+ if (key == 0 || !read_data)
+ {
+ printf("param error: you can input \"shm_read -k -200 -d \"123456\" -s1024 \n");
+ printf("or \"shm_read -k -200 -d \"123456\" \n");
+ printf("-k -200: create a shm using key -200\n");
+ printf("-d \"123456\": if we write 123456 to shm, then can read 123456 form shm, the test case is pass! \n");
+ printf("-s1024: set the size of shm, then the default size is 1024 \n");
+ return -1;
+ }
+
+ if (shm_size == 0)
+ shm_size = SHM_ALLOC_ONE_PAGE_SIZE;
+
+ printf("AP read test: key is %d, shm_size is %d\n", key, shm_size);
+
+ shmid = shmget(key, shm_size, 0666|IPC_CREAT);
+ if(shmid < 0)
+ {
+ printf("shmid return error\n");
+ return -1;
+ }
+
+ pshm = (char *)shmat(shmid, 0, 0);
+ if (pshm == NULL)
+ {
+ printf("shmat return error\n");
+ return -1;
+ }
+ shm_node.key = key;
+ shm_node.shm_size = shm_size;
+
+ shared = (shm_use_remote *)pshm;
+ shared->write = 1;
+
+ while(1)
+ {
+ if(strncmp(shared->data, read_data, sizeof(read_data)) == 0)
+ {
+ printf("Success, AP read %s from shm\n", read_data);
+ break;
+ }
+ else
+ sleep(2);
+ }
+
+ if(shmdt(pshm) < 0)
+ {
+ printf("shmdt errno %d: %s\n", errno, strerror(errno));
+ return -1;
+ }
+
+ if(shmctl(shmid, IPC_RMID, NULL) == -1)
+ {
+ printf("shmctl errno %d: %s\n", errno, strerror(errno));
+ return -1;
+ }
+
+ printf("shm read end\n");
+ return 0;
+}
+
diff --git a/ap/app/shm_test/shm_test.c b/ap/app/shm_test/shm_test.c
index 2bc1dea..2fdf0e5 100755
--- a/ap/app/shm_test/shm_test.c
+++ b/ap/app/shm_test/shm_test.c
@@ -55,24 +55,33 @@
{
int shmid = 0;
char *pshm = NULL;
- key_t key = 0xFFFFF001;
+ key_t key = 0xFFFFF801;
prctl(PR_SET_NAME, "shm_alloc_task");
/*alloc two pages*/
shmid = shmget(key, SHM_ALLOC_TWO_PAGE_SIZE, 0666|IPC_CREAT);
if(shmid < 0)
+ {
printf("shmid return error\n");
+ return -1;
+ }
pshm = (char *)shmat(shmid, 0, 0);
if (pshm == NULL)
+ {
printf("shmat return error\n");
+ return -1;
+ }
g_shmid[SHM_TEST_ALLOC_THREAD] = shmid;
g_pshm[SHM_TEST_ALLOC_THREAD] = pshm;
shmdt(pshm);
if(shmctl(shmid, IPC_RMID,0) == -1)
+ {
printf("shmctl error\n");
+ return -1;
+ }
while(1)
{
@@ -84,7 +93,7 @@
{
int shmid = 0;
char *pshm = NULL;
- key_t key = 0xFFFFF002;
+ key_t key = 0xFFFFF802;
prctl(PR_SET_NAME, "shm_mem_task");
@@ -114,7 +123,7 @@
int shmid = 0;
int test_num = 0;
int *pshm = NULL;
- key_t key = 0xFFFFF003;
+ key_t key = 0xFFFFF803;
prctl(PR_SET_NAME, "shm_task");
@@ -197,7 +206,7 @@
int shmid = 0;
char test_num = 0;
char *pshm = NULL;
- key_t key = 0xFFFFF004;
+ key_t key = 0xFFFFF804;
prctl(PR_SET_NAME, "shm_cross_task");
diff --git a/ap/app/shm_test/shm_write.c b/ap/app/shm_test/shm_write.c
new file mode 100755
index 0000000..a609e49
--- /dev/null
+++ b/ap/app/shm_test/shm_write.c
@@ -0,0 +1,143 @@
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <signal.h>
+#include <time.h>
+#include <pthread.h>
+#include <sys/prctl.h>
+#include <sys/ipc.h>
+#include <sys/shm.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <assert.h>
+#include <sys/mman.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+
+/**
+ * ºê¶¨Òå
+ */
+#define SHM_TEXT_SIZE (8192)
+#define SHM_PAGE_SIZE (4096)
+#define SHM_ALLOC_ONE_PAGE_SIZE (1024)
+#define SHM_ALLOC_TWO_PAGE_SIZE (8100)
+#define SHM_ALLOC_FOUR_PAGE_SIZE (16000)
+#define SHM_MIN(x,y) ((x)<(y)?(x):(y))
+
+typedef struct
+{
+ key_t key;
+ int shmid;
+ unsigned int shm_size;
+}shm_node_t;
+
+typedef struct
+{
+ int write;
+ char data[SHM_TEXT_SIZE];
+}shm_use_remote;
+
+shm_node_t shm_node;
+
+int main (int argc, char *argv[])
+{
+ int opt;
+ int ret = 0;
+ int shmid = 0;
+ int copy_size = 0;
+ unsigned int shm_size = 0;
+ key_t key = 0;
+ char *pshm = NULL;
+ char *write_data = NULL;
+ extern char *optarg;
+ shm_use_remote *shared;
+
+ while ((opt = getopt(argc,argv,"k:d:s::")) != EOF)
+ {
+ switch (opt)
+ {
+ case 'k':
+ key = atoi(optarg);
+ break;
+ case 'd':
+ write_data = optarg;
+ break;
+ case 's':
+ shm_size = atoi(optarg);
+ break;
+ default:
+ break;
+ }
+ }
+
+ if (key == 0 || !write_data)
+ {
+ printf("param error: you can input \"shm_write -k -200 -d \"123456\" -s1024 \n");
+ printf("or \"shm_read -k -200 -d \"123456\" \n");
+ printf("-k -200: create a shm using key -200\n");
+ printf("-d \"123456\": the data write to shm: for example, if we write 123456 to shm, then can read 123456 form shm, the test case is pass! \n");
+ printf("-s1024: set the size of shm, then the default size is 1024 \n");
+ return -1;
+ }
+ if (shm_size == 0)
+ shm_size = SHM_ALLOC_ONE_PAGE_SIZE;
+
+ printf("AP write test: key is %d, shm_size is %d\n", key, shm_size);
+
+ shmid = shmget(key, shm_size, 0666|IPC_CREAT);
+ if(shmid < 0)
+ {
+ printf("shmid return error\n");
+ return -1;
+ }
+ printf("shmid %d \n",shmid);
+
+ pshm = (char *)shmat(shmid, 0, 0);
+ if (pshm == NULL)
+ {
+ printf("shmat return error\n");
+ return -1;
+ }
+
+ printf("pshm 0x%x \n",pshm);
+ shared = (shm_use_remote *)pshm;
+
+ shm_node.key = key;
+ shm_node.shm_size = shm_size;
+
+ copy_size = SHM_MIN(strlen(write_data), (SHM_TEXT_SIZE - 1));
+
+ while(1)
+ {
+ if(shared->write == 1)
+ {
+ strncpy(shared->data, write_data, copy_size);
+ printf("AP write %s to shm\n", write_data);
+ shared->write = 0;
+ break;
+ }
+ else{
+ sleep(2);
+ }
+ }
+
+ if(shmdt(pshm) < 0)
+ {
+ printf("shmdt errno %d: %s\n", errno, strerror(errno));
+ return -1;
+ }
+
+ if(shmctl(shmid, IPC_RMID, NULL) == -1)
+ {
+ printf("shmctl errno %d: %s\n", errno, strerror(errno));
+ return -1;
+ }
+
+ printf("shm write end\n");
+
+ return 0;
+}
+
+