Exemple #1
0
int main(int argc, char *argv[])
{
	printf("*****************************\nTest shm\n"
	       "*****************************\n");
	(void)argc;
	(void)argv;
	
	const char *c="page_test_shm";
	int fid=pcreate(1);
	int ret;
	int pid=start("test_shm1",10000,getprio(getpid()),(void *)fid);
	void *pagep = shm_create(c);
	assert(pagep!=NULL);
	*((int*)pagep+4)=23;
	psend(fid, 1);
	preceive(fid,&ret);
	printf("[process %i] : %i\n",getpid(),*((int*)pagep+4));
	pdelete(fid);
	shm_release(c);
	waitpid(pid,&ret);
	assert(shm_acquire(c)==NULL);
	printf("\n*****************************\nTest fini\n"
	       "*****************************\n");
	return 0;
}
int main(void *arg)
{
    int i, count, fid, pid;
    struct tst16 *p = NULL;
    int pids[2 * NB_PROCS];

    (void)arg;
    p = (struct tst16*) shm_create("test16_shm");
    assert(p != NULL);

    assert(getprio(getpid()) == 128);
    for (count = 1; count <= 100; count++) {
        fid = pcreate(count);
        assert(fid >= 0);
        p->count = count;
        p->fid = fid;
        pid = start("proc16_1", 2000, 128, 0);
        assert(pid > 0);
        for (i=0; i<=count; i++) {
            assert(psend(fid, i) == 0);
            test_it();
        }
        assert(waitpid(pid, 0) == pid);
        assert(pdelete(fid) == 0);
    }

    p->count = 20000;
    fid = pcreate(50);
    assert(fid >= 0);
    p->fid = fid;
    for (i = 0; i< NB_PROCS; i++) {
        pid = start("proc16_2", 2000, 127, 0);
        assert(pid > 0);
        pids[i] = pid;
    }
    for (i=0; i < NB_PROCS; i++) {
        pid = start("proc16_3", 2000, 127, 0);
        assert(pid > 0);
        pids[NB_PROCS + i] = pid;
    }
    for (i=0; i < 2 * NB_PROCS; i++) {
        assert(waitpid(pids[i], 0) == pids[i]);
    }
    assert(pcount(fid, &count) == 0);
    assert(count == 0);
    assert(pdelete(fid) == 0);

    shm_release("test16_shm");
    printf("ok.\n");
    return 0;
}
int main(void *arg)
{
    struct psender *ps = NULL;
    int ps_index = (int)arg;
    unsigned i;
    unsigned n;

    ps = shm_acquire("test13_shm");
    assert(ps != NULL);
    n = strlen(ps[ps_index].data);

    for(i = 0; i < n; i++) {
        assert(psend(ps[ps_index].fid, ps[ps_index].data[i]) == 0);
    }
    shm_release("test13_shm");
    return 0;
}
Exemple #4
0
void main(int argc, char* argv[])
{
    SHM_FD fd,fd1;

    shm_init(SHM_PULL_MODEL);
    do{
        fd= shm_chn_attach(3);
        sleep(1);
    }while(-1== fd);

    SHARE_BUF_NODE *r_tmp;
    r_tmp= malloc(sizeof(SHARE_BUF_NODE));

    if(argc< 2){
        printf("usage: test_pull filename!\n");
    }

    FILE* file_fd;//output file path
    ssize_t wr_size;//write size

    file_fd= fopen(argv[1], "wb");//open output file
    if(NULL== file_fd){
        printf("file open error!\n");
        return;
    }

    while(1)
    {
        int handle= shm_pull(fd, r_tmp);//pull data from shm channel

        wr_size= fwrite(r_tmp->share_pt, 1, r_tmp->share_size, file_fd);//write data to output file
        if(-1== wr_size){
            printf("write error!\n");
            return ;
        }
//        printf("share mem buffer size is %d\n",r_tmp->share_size);
        shm_release(handle);

        if(5000!= wr_size){
            fclose(file_fd);
            return;
        }
    }
}
int main(void *arg)
{
        struct test17_buf_st *st = NULL;
        unsigned long long tsc, tsc2;
        int count;

        (void)arg;

        st = (struct test17_buf_st*) shm_acquire("test17_shm");

        __asm__ __volatile__("rdtsc":"=A"(tsc));
        tsc2 = tsc + 1000000000;
        assert(tsc < tsc2);
        do {
                int j;
                for (j=0; j<256; j++) {
                        buf_send((char)j, st);
                }
                count++;
                __asm__ __volatile__("rdtsc":"=A"(tsc));
        } while (tsc < tsc2);
        shm_release("test17_shm");
        return count;
}