static int test_circle(const char *pattern, gp_size w, gp_size h, gp_coord x, gp_coord y, const int r, uint8_t seg_flag) { gp_pixmap *c; int err; c = gp_pixmap_alloc(w, h, GP_PIXEL_G8); if (c == NULL) { tst_err("Failed to allocate pixmap"); return TST_UNTESTED; } /* zero the pixels buffer */ memset(c->pixels, 0, c->w * c->h); gp_circle_seg(c, x, y, r, seg_flag, 1); err = compare_buffers(pattern, c); if (err) { tst_msg("Patterns are different"); return TST_FAILED; } return TST_SUCCESS; }
static int load_eacces(enum fmt fmt) { char buf[256]; GP_Context *img; snprintf(buf, sizeof(buf), "test.%s", strfmt(fmt)); FILE *f = fopen(buf, "w"); if (f == NULL) { tst_err("Failed to create file 'test': %s", strerror(errno)); return TST_UNTESTED; } fclose(f); if (chmod(buf, 200)) { tst_err("chmod failed: %s", strerror(errno)); return TST_UNTESTED; } img = load(fmt, "test"); if (img != NULL) { tst_msg("Test succedded unexpectedly"); return TST_FAILED; } if (errno == ENOSYS) { tst_msg("Load %s: ENOSYS", strfmt(fmt)); return TST_SKIPPED; } if (errno != EACCES) { tst_msg("Expected errno = EACCES, have %s", strerror(errno)); return TST_FAILED; } return TST_SUCCESS; }
static int bench_circle(GP_PixelType type) { GP_Context *img = GP_ContextAlloc(800, 600, type); if (img == NULL) { tst_err("Malloc failed"); return TST_UNTESTED; } unsigned int i; for (i = 0; i < 100000; i++) { GP_Circle(img, img->w/2, img->h/2, i % 1000, i%0xff); } return TST_SUCCESS; }
static int save_img(enum fmt fmt, const GP_Context *img, const char *name) { char buf[256]; snprintf(buf, sizeof(buf), "%s.%s", name, strfmt(fmt)); switch (fmt) { case PNG: return GP_SavePNG(img, buf, NULL); case JPG: return GP_SaveJPG(img, buf, NULL); case BMP: return GP_SaveBMP(img, buf, NULL); default: tst_err("Trying to save %s image", strfmt(fmt)); exit(TST_UNTESTED); } }
static int bench_line(GP_PixelType type) { GP_Context *img = GP_ContextAlloc(800, 600, type); if (img == NULL) { tst_err("Malloc failed"); return TST_UNTESTED; } unsigned int i; for (i = 0; i < 100000; i++) { GP_Line(img, 0 + i % 100, 0 - i % 100, 800 - i%200, 600 + i%200, i % 0xff); } return TST_SUCCESS; }
static GP_Context *load(enum fmt fmt, const char *name) { char buf[256]; snprintf(buf, sizeof(buf), "%s.%s", name, strfmt(fmt)); switch (fmt) { case PNG: return GP_LoadPNG(buf, NULL); case JPG: return GP_LoadJPG(buf, NULL); case GIF: return GP_LoadGIF(buf, NULL); case BMP: return GP_LoadBMP(buf, NULL); default: tst_err("Trying to load %s image", strfmt(fmt)); exit(TST_UNTESTED); } }
static int test_circle(const struct testcase *t) { GP_Context *c; int err; c = GP_ContextAlloc(t->w, t->h, GP_PIXEL_G8); if (c == NULL) { tst_err("Failed to allocate context"); return TST_UNTESTED; } /* zero the pixels buffer */ memset(c->pixels, 0, c->w * c->h); GP_FillCircle(c, t->x, t->y, t->r, 1); err = compare_buffers(t->pixmap, c); if (err) return TST_FAILED; return TST_SUCCESS; }
int main(int argc, char **argv) { int p[2]; struct ct_arg ca; libct_session_t s; ct_handler_t ct; ct_process_desc_t pd; ct_process_t pr; struct ct_net_veth_arg va; ct_net_t nd, nd_peer; ca.mark = mmap(NULL, 4096, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_ANON, 0, 0); pipe(p); ca.mark[0] = 0; ca.mark[1] = 0; ca.mark[2] = 0; ca.wait_pipe = p[0]; va.host_name = VETH_HOST_NAME; va.ct_name = VETH_CT_NAME; s = libct_session_open_local(); ct = libct_container_create(s, "test"); pd = libct_process_desc_create(s); libct_container_set_nsmask(ct, CLONE_NEWNET); nd = libct_net_add(ct, CT_NET_VETH, &va); if (libct_handle_is_err(nd)) return tst_err("Can't add hostnic"); nd_peer = libct_net_dev_get_peer(nd); if (libct_handle_is_err(nd_peer)) return tst_err("Can't get a veth peer"); if (libct_net_dev_set_mac_addr(nd_peer, "00:11:22:33:44:66")) return tst_err("Can't set mac"); if (libct_net_dev_set_mac_addr(nd, "00:11:22:33:44:55")) return tst_err("Can't set mac"); if (libct_net_dev_add_ip_addr(nd, "192.168.123.123/32")) return tst_err("Can't set addr"); pr = libct_container_spawn_cb(ct, pd, check_ct_net, &ca); if (libct_handle_is_err(pr)) return tst_err("Can't spawn CT"); if (!system("ip link l " VETH_HOST_NAME "")) ca.mark[1] = 1; write(p[1], "a", 1); libct_container_wait(ct); libct_container_destroy(ct); libct_session_close(s); if (!ca.mark[0]) return fail("CT is not alive"); if (!ca.mark[1]) return fail("VETH not created"); if (!ca.mark[2]) return fail("VETH not assigned"); return pass("VETH works OK"); }