Exemple #1
0
static int shortcut1_edge_info_r(const struct agar_graph *gr,
                                 const void *nr, const void *e,
                                 struct agar_edge_info *eir)
{
    int ni = ptr2int(nr);
    int index = ptr2int(e);

    switch (ni) {
    case 1:
        if (index == 1) {
            eir->to = int2ptr(3);
            eir->icost = 3;
        } else {
            assert(index == 2);
            eir->to = int2ptr(2);
        }
        break;

    case 2:
        assert(index == 1);
        eir->to = int2ptr(3);
        break;

    default:
        assert(0);
    }
    return 0;
}
Exemple #2
0
/*
 * AdressRangeMapping REGISTERING:
 * start, length .... identifies addressrange
 * *initial_value ... pointer to buffer containing (if necessary) initial value
 *                    NULL means undefined
 * arm_tag .......... identifier for arm_tag_handler 
 *                    (usually pointer to raw1394_arm_reqhandle)
 * access_rights .... access-rights for registered addressrange handled 
 *                    by kernel-part. Value is one or more binary or of the 
 *                    following flags: ARM_READ, ARM_WRITE, ARM_LOCK
 * notification_options ... identifies for which type of request you want
 *                    to be notified. Value is one or more binary or of the 
 *                    following flags: ARM_READ, ARM_WRITE, ARM_LOCK
 * client_transactions ... identifies for which type of request you want
 *                    to handle the request by the client application.
 *                    for those requests no response will be generated, but
 *                    has to be generated by the application.
 *                    Value is one or more binary or of the 
 *                    following flags: ARM_READ, ARM_WRITE, ARM_LOCK
 *                    For each bit set here, notification_options and
 *                    access_rights will be ignored.
 * returnvalue:       0  ... success
 *                    <0 ... failure
 */
int ieee1394_arm_register(struct ieee1394_handle *handle, nodeaddr_t start, 
                         size_t length, byte_t *initial_value,
                         octlet_t arm_tag, arm_options_t access_rights,
                         arm_options_t notification_options,
                         arm_options_t client_transactions)
{
        int     retval=0;
        struct  raw1394_request req;

	if (((start & ~(0xFFFFFFFF)) != 0) ||
                (((start + length) & ~(0xFFFFFFFF)) != 0)) {
                errno = EINVAL;
                return (-1);
	}
        CLEAR_REQ(&req);
        req.type = RAW1394_REQ_ARM_REGISTER;
        req.generation = handle->generation; /* not necessary */
        req.address = start;
        req.length = length;
        req.tag = arm_tag;
        req.recvb = ptr2int(handle->buffer); /* arm_handle on success */ 
        req.misc = ((client_transactions & 0x0f) << 8)|((notification_options & 0x0F) << 4)|(access_rights & 0x0F)
                    |((ARM_REC_LENGTH & 0xFFFF) << 16);
        req.sendb = ptr2int(initial_value); 
        retval = (int) write(handle->fd, &req, sizeof(req));
        return (retval == sizeof(req)) ? 0:-1;
}
static int do_iso_listen(struct raw1394_handle *handle, int channel)
{
        struct sync_cb_data sd = { 0, 0 };
        struct raw1394_reqhandle rh = { (req_callback_t)_raw1394_sync_cb, &sd };
        int err;
        struct raw1394_request req;

        CLEAR_REQ(&req);
        req.type = RAW1394_REQ_ISO_LISTEN;
        req.generation = handle->generation;
        req.misc = channel;
        req.tag = ptr2int(&rh);
        req.recvb = ptr2int(handle->buffer);
        req.length = HBUF_SIZE;

        err = write(handle->fd, &req, sizeof(req));
        while (!sd.done) {
                if (err < 0) return err;
                err = raw1394_loop_iterate(handle);
        }

        switch (sd.errcode) {
        case RAW1394_ERROR_ALREADY:
                errno = EALREADY;
                return -1;

        case RAW1394_ERROR_INVALID_ARG:
                errno = EINVAL;
                return -1;

        default:
                errno = 0;
                return sd.errcode;
        }
}
Exemple #4
0
/* Once they ack, we can fail it on our side. */
static void fail_their_htlc_ourside(struct peer *peer, void *arg)
{
	size_t n;

	n = funding_htlc_by_id(&peer->us.staging_cstate->b, ptr2int(arg));
	funding_b_fail_htlc(peer->us.staging_cstate, n);
}
Exemple #5
0
int main(void)
{
	tds_condition cond;
	tds_thread th;
	void *res;

	check(tds_cond_init(&cond), "failed initializing condition");

	tds_mutex_lock(&mtx);

	check(tds_thread_create(&th, signal_proc, &cond) != 0, "error creating thread");

	sleep(1);

	check(tds_cond_wait(&cond, &mtx), "failed waiting condition");

	check(tds_thread_join(th, &res) != 0, "error waiting thread");

	check(ptr2int(res) != 0, "error signaling condition");

	tds_mutex_unlock(&mtx);

	check(tds_cond_destroy(&cond), "failed destroying condition");
	return 0;
}
Exemple #6
0
int ieee1394_get_port_info(struct ieee1394_handle *handle, 
                          struct raw1394_portinfo *pinf, int maxports)
{
        struct raw1394_request req;

        CLEAR_REQ(&req);
        req.type = RAW1394_REQ_LIST_CARDS;
        req.generation = handle->generation;
        /* IMPORTANT: raw1394 will be writing directly into the memory you
           provide in pinf. The viability of this approach assumes that the 
           structure of libraw1394's raw1394_portinfo and the kernel's 
           raw1394_khost_list structs are the same!!
        */
        req.recvb = ptr2int(pinf);
        req.length = sizeof(struct raw1394_portinfo) * maxports;

        while (1) {
                if (write(handle->fd, &req, sizeof(req)) < 0) return -1;
                if (read(handle->fd, &req, sizeof(req)) < 0) return -1;

                if (!req.error) break;

                if (req.error == RAW1394_ERROR_GENERATION) {
                        handle->generation = req.generation;
                        continue;
                }

                return -1;
        }

        return req.misc;
}
Exemple #7
0
static int traversal1_edge_info(const struct aga_graph *g,
				const struct aga_node *n,
				ptrint_t *e, struct aga_edge_info *ei)
{
	struct traversal1_graph *t1g = container_of(g, struct traversal1_graph,
						    sg.g);
	int ni = n - t1g->sg.nodes;
	int index = ptr2int(e);

	assert((index == 1) || (index == 2));

	switch (ni) {
	case 1:
		if (index == 1)
			ei->to = &t1g->sg.nodes[2];
		else
			ei->to = &t1g->sg.nodes[3];
		break;

	case 2:
		if (index == 1)
			ei->to = &t1g->sg.nodes[4];
		else
			ei->to = &t1g->sg.nodes[5];
		break;
	case 3:
		if (index == 1)
			ei->to = &t1g->sg.nodes[5];
		else
			ei->to = &t1g->sg.nodes[6];
		break;

	case 7:
		if (index == 1)
			ei->to = &t1g->sg.nodes[5];
		else
			ei->to = &t1g->sg.nodes[4];
		break;

	case 8:
		if (index == 1)
			ei->to = &t1g->sg.nodes[6];
		else
			ei->to = &t1g->sg.nodes[5];
		break;

	case 9:
		if (index == 1)
			ei->to = &t1g->sg.nodes[8];
		else
			ei->to = &t1g->sg.nodes[7];
		break;

	default:
		assert(0);
	}
	return 0;
}
Exemple #8
0
int main(void)
{
	tds_condition cond;
	tds_thread th;
	void *res;

	check(tds_cond_init(&cond), "failed initializing condition");

	tds_mutex_lock(&mtx);

	check(tds_thread_create(&th, signal_proc, &cond) != 0, "error creating thread");

	tds_sleep_ms(100);

	check(tds_cond_wait(&cond, &mtx), "failed waiting condition");

	res = &th;
	check(tds_thread_join(th, &res) != 0, "error waiting thread");

	check(ptr2int(res) != 0, "error signaling condition");

	/* under Windows mutex are recursive */
#ifndef _WIN32
	check(tds_mutex_trylock(&mtx) == 0, "mutex should be locked");
#endif

	/* check timed version */

	check(tds_cond_timedwait(&cond, &mtx, 1) == 0, "should not succeed to wait condition");

	check(tds_thread_create(&th, signal_proc, &cond) != 0, "error creating thread");

	check(tds_cond_timedwait(&cond, &mtx, 1), "error on timed waiting condition");

	res = &th;
	check(tds_thread_join(th, &res) != 0, "error waiting thread");

	check(ptr2int(res) != 0, "error signaling condition");

	tds_mutex_unlock(&mtx);

	check(tds_cond_destroy(&cond), "failed destroying condition");
	return 0;
}
Exemple #9
0
static const void *grid_next_edge_r(const struct agar_graph *gr,
				    const void *nr, const void *e)
{
	int index = ptr2int(e);

	if (index < 4)
		return int2ptr(index + 1);
	else
		return NULL;	       
}
Exemple #10
0
static ptrint_t *lazytrie_next_edge(const struct aga_graph *g,
				    const struct aga_node *n,
				    ptrint_t *e)
{
	int index = ptr2int(e);

	assert((index >= 1) && (index <= NLETTERS));
	if (index == NLETTERS)
		return NULL;
	else
		return int2ptr(index + 1);
}
Exemple #11
0
static const void *shortcut1_next_edge_r(const struct agar_graph *gr,
        const void *nr, const void *e)
{
    int ni = ptr2int(nr);
    int index = ptr2int(e);

    switch (ni) {
    case 1:
        if (index == 1)
            return int2ptr(2);
        assert(index == 2);
        return NULL;

    case 2:
        assert(index == 1);
        return NULL;

    default:
        assert(0);
    }
}
Exemple #12
0
static void test_parallel(void)
{
	struct parallel_graphr pgr;
	struct agar_state *sr;
	aga_icost_t cost;
	const void *node, *edge;

	parallel_graphr_init(&pgr, 3, 0);

	ok1(sr = agar_dijkstra_new(NULL, &pgr.gr, int2ptr(1)));
	ok1(agar_dijkstra_step(sr, &node));
	ok1(ptr2int(node) == 1);
	ok1(agar_dijkstra_step(sr, &node));
	ok1(ptr2int(node) == 2);
	ok1(!agar_dijkstra_step(sr, &node));
	ok1(agar_dijkstra_path(sr, int2ptr(1), &cost, NULL, NULL));
	ok1(cost == 0);
	ok1(agar_dijkstra_path(sr, int2ptr(2), &cost, &node, NULL));
	ok1(cost == 2);
	ok1(node == int2ptr(1));
	tal_free(sr);

	ok1(sr = agar_dijkstra_new(NULL, &pgr.gr, int2ptr(2)));
	ok1(agar_dijkstra_step(sr, &node));
	ok1(ptr2int(node) == 2);
	ok1(!agar_dijkstra_step(sr, &node));
	ok1(agar_dijkstra_path(sr, int2ptr(2), &cost, NULL, NULL));
	ok1(cost == 0);
	ok1(!agar_dijkstra_path(sr, int2ptr(1), NULL, NULL, NULL));
	tal_free(sr);

	parallel_graphr_init(&pgr, 3, 2);
	ok1(sr = agar_dijkstra_new(NULL, &pgr.gr, int2ptr(1)));
	ok1(agar_dijkstra_path(sr, int2ptr(2), &cost, &node, &edge));
	ok1(cost == 1);
	ok1(ptr2int(node) == 1);
	ok1(ptr2int(edge) == 2);
	tal_free(sr);
}
Exemple #13
0
static int grid_edge_info_r(const struct agar_graph *gr,
			    const void *nr, const void *e,
			    struct agar_edge_info *eir)
{
	struct grid_graphr *ggr = container_of(gr, struct grid_graphr, gr);
	int ni = ptr2int(nr);
	int x = ((ni - 1) % ggr->nx) + 1;
	int y = ((ni - 1) / ggr->nx) + 1;
	int i = ptr2int(e);

	assert((x >= 1) && (x <= ggr->nx));
	assert((y >= 1) && (y <= ggr->ny));

	switch (i) {
	case 1: /* right */
		if (ggr->right && (x != ggr->nx))
			eir->to = int2ptr(ni + 1);
		break;

	case 2: /* down */
		if (ggr->down && (y != ggr->ny))
			eir->to = int2ptr(ni + ggr->nx);
		break;
		
	case 3: /* left */
		if (ggr->left && (x != 1))
			eir->to = int2ptr(ni - 1);
		break;

	case 4: /* up */
		if (ggr->up && (y != 1))
			eir->to = int2ptr(ni - ggr->nx);
		break;

	default:
		assert(0);
	}
	return 0;
}
int raw1394_start_lock64(struct raw1394_handle *handle, nodeid_t node,
                         nodeaddr_t addr, unsigned int extcode, octlet_t data,
                         octlet_t arg, octlet_t *result, unsigned long tag)
{
        struct raw1394_request req;
        octlet_t sendbuf[2];

        if ((extcode > 7) || (extcode == 0)) {
                errno = EINVAL;
                return -1;
        }

        CLEAR_REQ(&req);

        req.type = RAW1394_REQ_LOCK64;
        req.generation = handle->generation;
        req.tag = tag;

        req.address = ((__u64)node << 48) | addr;
        req.sendb = ptr2int(sendbuf);
        req.recvb = ptr2int(result);
        req.misc = extcode;

        switch (extcode) {
        case 3: /* EXTCODE_FETCH_ADD */
        case 4: /* EXTCODE_LITTLE_ADD */
                sendbuf[0] = data;
                req.length = 8;
                break;
        default:
                sendbuf[0] = arg;
                sendbuf[1] = data;
                req.length = 16;
                break;
        }

        return (int)write(handle->fd, &req, sizeof(req));
}
Exemple #15
0
static void test_trivial(void)
{
	struct agar_state *sr;
	aga_icost_t cost;
	const void *node;

	ok1(sr = agar_dijkstra_new(NULL, &trivial_graphr.gr, int2ptr(1)));
	ok1(agar_dijkstra_step(sr, &node));
	ok1(ptr2int(node) == 1);
	ok1(!agar_dijkstra_step(sr, &node));
	ok1(agar_dijkstra_path(sr, int2ptr(1), &cost, NULL, NULL));
	ok1(cost == 0);
	tal_free(sr);
}
Exemple #16
0
/* accept a socket and read data as much as you can */
static TDS_THREAD_PROC_DECLARE(fake_thread_proc, arg)
{
	TDS_SYS_SOCKET s = ptr2int(arg), sock;
	socklen_t len;
	char buf[128];
	struct sockaddr_in sin;
	struct pollfd fd;

	memset(&sin, 0, sizeof(sin));
	len = sizeof(sin);

	fd.fd = s;
	fd.events = POLLIN;
	fd.revents = 0;
	if (poll(&fd, 1, 30000) <= 0) {
		perror("poll");
		exit(1);
	}

	if (TDS_IS_SOCKET_INVALID(sock = tds_accept(s, (struct sockaddr *) &sin, &len))) {
		perror("accept");
		exit(1);
	}
	tds_mutex_lock(&mtx);
	fake_sock = sock;
	tds_mutex_unlock(&mtx);
	CLOSESOCKET(s);

	for (;;) {
		int len;

		fd.fd = sock;
		fd.events = POLLIN;
		fd.revents = 0;
		if (poll(&fd, 1, 30000) <= 0) {
			perror("poll");
			exit(1);
		}

		/* just read and discard */
		len = READSOCKET(sock, buf, sizeof(buf));
		if (len == 0)
			break;
		if (len < 0 && sock_errno != TDSSOCK_EINPROGRESS)
			break;
	}
	return NULL;
}
Exemple #17
0
/*
 * AdressRangeMapping GET BUFFER:
 * start, length .... identifies addressrange
 * buf .............. pointer to buffer
 *
 * This function copies 'length' bytes from one
 * ARM block in kernel memory area with start offset `start`
 * to user memory area 'buf'
 *
 * returnvalue:       0  ... success
 *                    <0 ... failure, and errno - error code
 */
int ieee1394_arm_get_buf (struct ieee1394_handle *handle, nodeaddr_t start,
                         size_t length, void *buf)
{
        struct raw1394_request req;

        CLEAR_REQ(&req);

        req.type = RAW1394_REQ_ARM_GET_BUF;
        req.recvb = ptr2int(buf);
        req.length = length;
        req.address = start;

        if (write(handle->fd, &req, sizeof(req)) < 0) return -1;

        return 0;
}
Exemple #18
0
static void *
thread_test(void * arg)
{
	int i;
	int num = ptr2int(arg);
	DBPROCESS *dbproc;
	LOGINREC *login;

	login = dblogin();
	DBSETLPWD(login, PASSWORD);
	DBSETLUSER(login, USER);
	DBSETLAPP(login, "thread");

	dbproc = dbopen(login, SERVER);
	if (!dbproc) {
		dbloginfree(login);
		fprintf(stderr, "Unable to connect to %s\n", SERVER);
		set_failed();
		return NULL;
	}
	dbloginfree(login);

	if (strlen(DATABASE))
		dbuse(dbproc, DATABASE);

	pthread_mutex_lock(&mutex);
	++thread_count;
	pthread_mutex_unlock(&mutex);

	printf("thread %2d waiting for all threads to start\n", num+1);
	pthread_mutex_lock(&mutex);
	while (thread_count < NUM_THREAD) {
		pthread_mutex_unlock(&mutex);
		sleep(1);
		pthread_mutex_lock(&mutex);
	}
	pthread_mutex_unlock(&mutex);

	for (i = 1; i <= NUM_LOOP; ++i) {
		printf("thread %2d of %2d loop %d\n", num+1, NUM_THREAD, i);
		if (test(dbproc) || result != 0)
			break;
	}

	dbclose(dbproc);
	return NULL;
}
Exemple #19
0
static const void *shortcut1_first_edge_r(const struct agar_graph *gr,
        const void *nr)
{
    int ni = ptr2int(nr);

    switch (ni) {
    case 1:
    case 2:
        return int2ptr(1);

    case 3:
        return NULL;

    default:
        assert(0);
    }
}
Exemple #20
0
static ptrint_t *traversal1_next_edge(const struct aga_graph *g,
				      const struct aga_node *n,
				      ptrint_t *e)
{
	struct traversal1_graph *t1g = container_of(g, struct traversal1_graph,
						    sg.g);
	int ni = n - t1g->sg.nodes;
	int index = ptr2int(e);

	assert((ni < 4) || (ni > 6));
	if (index == 1)
		return int2ptr(2);
	else if (index == 2)
		return NULL;
	else
		assert(0);
}
int raw1394_start_write(struct raw1394_handle *handle, nodeid_t node,
                        nodeaddr_t addr, size_t length, quadlet_t *data,
                        unsigned long tag)
{
        struct raw1394_request req;

        CLEAR_REQ(&req);

        req.type = RAW1394_REQ_ASYNC_WRITE;
        req.generation = handle->generation;
        req.tag = tag;

        req.address = ((__u64)node << 48) | addr;
        req.length = length;
        req.sendb = ptr2int(data);

        return (int)write(handle->fd, &req, sizeof(req));
}
int raw1394_start_async_send(struct raw1394_handle *handle,
                             size_t length, size_t header_length, unsigned int expect_response,
                             quadlet_t *data, unsigned long rawtag)
{
        struct raw1394_request req;

        CLEAR_REQ(&req);

        req.type = RAW1394_REQ_ASYNC_SEND;
        req.generation = handle->generation;
        req.tag = rawtag;

        req.length = length;
        req.misc = (expect_response << 16) | (header_length & 0xffff);
        req.sendb = ptr2int(data);

        return (int)write(handle->fd, &req, sizeof(req));
}
Exemple #23
0
int main(int argc, char *argv[])
{
    // read in and assignment input arguments
    if(argc != 5)
    {   // print error and exit
        printf("Error: invalid input\n");
        return -1;
    }

    // declare variables
    struct complex_tag a, b, c, d, e;
    struct complex_tag *p1, *p2, *p3, *p4, *p5;
    struct complex_tag **dp1, **dp2;
    a.real = atoi(argv[1]);
    a.imaginary = atoi(argv[2]);
    b.real = atoi(argv[3]);
    b.imaginary = atoi(argv[4]);
    c.real = 0;
    c.imaginary = 0;
    p1 = &a;
    p2 = &b;
    p3 = &c;
    p4 = &d;
    p5 = &e;
    dp1 = &p4;
    dp2 = &p5;




    // PART C: accepts 2 complex tags and returns a complex type
    Complex_type part_A = tag2type(a, b);

    // PART D: accepts three complex_tag pointers and returns an int
    int part_B = tag2int(p1, p2, p3);

    // PART E: accepts 2 complex_tag & 2 double ptrs to complex_tag
    int part_C = ptr2int(a, b, dp1, dp2);

    return 0;

}
Exemple #24
0
void coroutine_init_(struct coroutine_state *cs,
                     void (*fn)(void *), void *arg,
                     struct coroutine_stack *stack)
{
    getcontext (&cs->uc);

    coroutine_uc_stack(&cs->uc.uc_stack, stack);

    if (HAVE_POINTER_SAFE_MAKECONTEXT) {
        makecontext(&cs->uc, (void *)fn, 1, arg);
    } else {
        ptrdiff_t si = ptr2int(arg);
        ptrdiff_t mask = (1UL << (sizeof(int) * 8)) - 1;
        int lo = si & mask;
        int hi = si >> (sizeof(int) * 8);

        makecontext(&cs->uc, (void *)fn, 2, lo, hi);
    }

}
int raw1394_start_iso_write(struct raw1394_handle *handle, unsigned int channel,
                            unsigned int tag, unsigned int sy,
                            unsigned int speed, size_t length, quadlet_t *data,
                            unsigned long rawtag)
{
        struct raw1394_request req;

        CLEAR_REQ(&req);

        req.type = RAW1394_REQ_ISO_SEND;
        req.generation = handle->generation;
        req.tag = rawtag;

        req.address = ((__u64)channel << 48) | speed;
        req.misc = (tag << 16) | sy;
        req.length = length;
        req.sendb = ptr2int(data);

        return (int)write(handle->fd, &req, sizeof(req));
}
Exemple #26
0
static int lazytrie_edge_info(const struct aga_graph *g,
			      const struct aga_node *n,
			      ptrint_t *e,
			      struct aga_edge_info *ei)
{
	struct trie_node *tn = container_of(n, struct trie_node, agan);
	struct trie_node *next;
	int index = ptr2int(e);

	assert((index >= 1) && (index <= NLETTERS));

	next = tn->next[index - 1];

	if (!next) {
		int depth = strlen(tn->prefix);
		int start, end;

		start = tn->start;
		while (start < tn->end) {
			if (wordarray[start][depth] >= LETTERS[index - 1])
				break;
			start++;
		}

		end = start;
		while (end < tn->end) {
			if (wordarray[end][depth] > LETTERS[index - 1])
				break;
			end++;
		}

		if (end > start) {
			char plus[2] = { LETTERS[index - 1], '\0' };
			next = tal(tn, struct trie_node);
			init_trie_node(next, start, end,
				       tal_strcat(next, tn->prefix, plus));
		}
Exemple #27
0
static void test_parallel(void)
{
	struct parallel_graph pg;
	aga_icost_t cost;
	struct aga_node *node;
	const void *edge;

	parallel_graph_init(&pg, 3, 0);

	ok1(aga_dijkstra_start(&pg.sg.g, &pg.sg.nodes[1]) == 0);
	ok1(aga_dijkstra_step(&pg.sg.g) == &pg.sg.nodes[1]);
	ok1(aga_dijkstra_step(&pg.sg.g) == &pg.sg.nodes[2]);
	ok1(aga_dijkstra_step(&pg.sg.g) == NULL);
	ok1(aga_dijkstra_path(&pg.sg.g, &pg.sg.nodes[1], &cost, NULL, NULL));
	ok1(cost == 0);
	ok1(aga_dijkstra_path(&pg.sg.g, &pg.sg.nodes[2], &cost, &node, NULL));
	ok1(cost == 2);
	ok1(node == &pg.sg.nodes[1]);
	aga_finish(&pg.sg.g);

	ok1(aga_dijkstra_start(&pg.sg.g, &pg.sg.nodes[2]) == 0);
	ok1(aga_dijkstra_step(&pg.sg.g) == &pg.sg.nodes[2]);
	ok1(aga_dijkstra_step(&pg.sg.g) == NULL);
	ok1(aga_dijkstra_path(&pg.sg.g, &pg.sg.nodes[2], &cost, NULL, NULL));
	ok1(cost == 0);
	ok1(!aga_dijkstra_path(&pg.sg.g, &pg.sg.nodes[1], NULL, NULL, NULL));
	aga_finish(&pg.sg.g);


	parallel_graph_init(&pg, 3, 2);
	ok1(aga_dijkstra_start(&pg.sg.g, &pg.sg.nodes[1]) == 0);
	ok1(aga_dijkstra_path(&pg.sg.g, &pg.sg.nodes[2], &cost, &node, &edge));
	ok1(cost == 1);
	ok1(node == &pg.sg.nodes[1]);
	ok1(ptr2int(edge) == 2);
	aga_finish(&pg.sg.g);
}
Exemple #28
0
static void test_adjacency(const char *name,
			   const struct agar_graph *gr,
			   const struct adjacency_listr *atr)
{
	int i;

	for (i = 0; atr[i].from != 0; i++) {
		const void *e;
		struct agar_edge_info eir;
		int j = 0;
		int err;
		ptrint_t *from = int2ptr(atr[i].from);

		agar_for_each_edge_info(e, eir, err, gr, from) {
			const void *cmpto;

			assert(j < MAX_EDGES);
			cmpto = int2ptr(atr[i].to[j]);
			ok(cmpto == eir.to,
			   "%s: %p #%d -> #%ld (expected #%d -> #%d)", name, e,
			   atr[i].from, ptr2int(eir.to),
			   atr[i].from, atr[i].to[j]);

			j++;
		}
		if (atr[i].to[j] < 0) {
			ok(err == atr[i].to[j], "%s: %p #%d -> ERROR %d",
			   name, e, atr[i].from, atr[i].to[j]);
			continue; /* Move onto next node on errors */
		}
		assert(j < MAX_EDGES);
		ok(atr[i].to[j] == 0,
		   "%s: %p #%d -> --- (expected #%d -> #%d)", name, e,
		   atr[i].from, atr[i].from, atr[i].to[j]);
	}
}
Exemple #29
0
static const void *trivial_first_edge_r(const struct agar_graph *g,
					const void *nr)
{
	assert(ptr2int(nr) == 1);
	return NULL;
}
Exemple #30
0
int main(void)
{
	struct parallel_graphr pgr;
	struct full_graphr fgr;
	struct chain_graphr cgr;
	struct grid_graphr ggr1, ggr2;
	struct agar_state *sr;
	const void *nr;
	
	plan_tests(2 * 13 + 12 + 10);

	test_bfs(&trivial_graphr.gr, 1, 1);

	parallel_graphr_init(&pgr, 3, 0);
	test_bfs(&pgr.gr, 1, 1, 2);

	full_graphr_init(&fgr, 5);
	test_bfs(&fgr.gr, 1, 1, 2, 3, 4, 5);
	test_bfs(&fgr.gr, 3, 3, 1, 2, 4, 5);

	chain_graphr_init(&cgr, 8);
	test_bfs(&cgr.fgr.gr, 1, 1, 2, 3, 4, 5, 6, 7, 8);
	test_bfs(&cgr.fgr.gr, 8, 8, 7, 6, 5, 4, 3, 2, 1);
	test_bfs(&cgr.fgr.gr, 5, 5, 4, 6, 3, 7, 2, 8, 1);

	grid_graphr_init(&ggr1, 3, 3, true, true, false, false);
	test_bfs(&ggr1.gr, 1, 1, 2, 4, 3, 5, 7, 6, 8, 9);
	test_bfs(&ggr1.gr, 5, 5, 6, 8, 9);
	test_bfs(&ggr1.gr, 9, 9);

	grid_graphr_init(&ggr2, 3, 3, true, true, true, true);
	test_bfs(&ggr2.gr, 1, 1, 2, 4, 3, 5, 7, 6, 8, 9);
	test_bfs(&ggr2.gr, 5, 5, 6, 8, 4, 2, 9, 3, 7, 1);
	test_bfs(&ggr2.gr, 9, 9, 8, 6, 7, 5, 3, 4, 2, 1);

	test_bfs(&error_graphr.gr, 1, 1, 2);
	ok((sr = agar_bfs_new(NULL, &error_graphr.gr)),
	   "started error traversal");
	ok1(agar_bfs_explore(sr, int2ptr(3), &nr));
	ok(ptr2int(nr) == 3, "Expected node #3, actually #%ld", ptr2int(nr));
	ok1(agar_bfs_explore(sr, nr, &nr));
	ok(ptr2int(nr) == 4, "Expected node #4, actually #%ld", ptr2int(nr));
	ok1(!agar_bfs_explore(sr, nr, &nr));
	ok1(agar_error(sr) == -1);
	ok1(!agar_bfs_explore(sr, nr, &nr));
	tal_free(sr);
	test_bfs(&error_graphr.gr, 1, 1, 2);

	test_bfs(&traversal1_graphr.gr, 1, 1, 2, 3, 4, 5, 6);
	test_bfs(&traversal1_graphr.gr, 9, 9, 8, 7, 6, 5, 4);

	ok1((sr = agar_bfs_new(NULL, &traversal1_graphr.gr)));
	test_bfs_partial(sr, 1, 1, 2, 3, 4, 5, 6);
	test_bfs_partial(sr, 9, 9, 8, 7);
	tal_free(sr);

	ok1((sr = agar_bfs_new(NULL, &traversal1_graphr.gr)));
	test_bfs_partial(sr, 9, 9, 8, 7, 6, 5, 4);
	test_bfs_partial(sr, 1, 1, 2, 3);
	tal_free(sr);

	return exit_status();
}