// Tests DHCPDISCOVER options void test1() { struct options opts; memset(&opts, 0, sizeof(struct options)); parse_options(test1_opts, sizeof(test1_opts), &opts); ASSERT_EQ(MESSAGE_DHCPDISCOVER, opts.message_type); ASSERT_EQ(1500, opts.max_size); char hostname[] = { "lozenge" }; ASSERT_EQ(0, strcmp(hostname, opts.hostname)); ASSERT_EQ(7776000, opts.lease_time); ASSERT_EQ(1, opts.client_id_type); ASSERT_EQ(6, opts.client_id_length); uint8_t mac[] = { 0x00, 0x0a, 0x095, 0xbe, 0x88, 0xc6 }; ASSERT_EQ(0, memcmp(mac, opts.client_id, 6)); uint8_t params[] = { DHCP_SUBNET_MASK, DHCP_ROUTER, DHCP_DNS, DHCP_DOMAIN }; ASSERT_EQ(4, opts.param_size); ASSERT_EQ(0, memcmp(params, opts.param_list, 4)); ASSERT_EQ(0, opts.server_id); ASSERT_EQ(0, opts.subnet); ASSERT_EQ(0, opts.router_num); ASSERT_EQ(0, opts.dns_num); ASSERT_EQ(0, strlen(opts.domain)); uint8_t buf[1024]; uint16_t size = 1024; write_options(&opts, buf, &size); ASSERT_EQ(size, sizeof(test1_output)); ASSERT_ARRAY_EQ(test1_output, buf, size); }
// Tests DHCPOFFER options void test4() { struct options opts; memset(&opts, 0, sizeof(struct options)); parse_options(test4_opts, sizeof(test4_opts), &opts); ASSERT_EQ(MESSAGE_DHCPACK, opts.message_type); uint8_t id[] = { 10, 0, 1, 1 }; ASSERT_EQ(0, memcmp(id, &opts.server_id, 4)); uint8_t subnet[] = { 255, 255, 255, 0 }; ASSERT_EQ(0, memcmp(subnet, &opts.subnet, 4)); ASSERT_EQ(14400, opts.lease_time); ASSERT_EQ(1, opts.router_num); ASSERT_EQ(0, memcmp(id, &opts.router, 4)); ASSERT_EQ(1, opts.dns_num); ASSERT_EQ(0, memcmp(id, &opts.dns, 4)); char domain[] = { "thebends.org" }; ASSERT_EQ(0, strcmp(domain, opts.domain)); // Options NOT in the response ASSERT_EQ(0, opts.max_size); ASSERT_EQ(0, strlen(opts.hostname)); ASSERT_EQ(0, opts.client_id_type); ASSERT_EQ(0, opts.client_id_length); ASSERT_EQ(0, opts.param_size); uint8_t buf[1024]; uint16_t size = 1024; write_options(&opts, buf, &size); ASSERT_ARRAY_EQ(test4_output, buf, size); ASSERT_EQ(size, sizeof(test4_output)); }
TEST(Transformation, Bin) { for(int i = 11; i < 12; i++) { cudaDeviceReset(); srand(i); int size = (1<<i); int batch = 1; int bincount = 5; tfloat* h_input = (tfloat*)malloc(size * size * batch * sizeof(tfloat)); for(int b = 0; b < batch; b++) { for(int j = 0; j < size * size; j++) h_input[b * size * size + j] = (tfloat)(j % (1<<bincount)); } tfloat* d_input = (tfloat*)CudaMallocFromHostArray(h_input, size * size * batch * sizeof(tfloat)); tfloat* d_result; cudaMalloc((void**)&d_result, size * size / (1<<(bincount * 2)) * sizeof(tfloat)); int3 dims; dims.x = size; dims.y = size; d_Bin(d_input, d_result, dims, bincount, 1); tfloat* h_result = (tfloat*)MallocFromDeviceArray(d_result, size * size / (1<<(bincount * 2)) * sizeof(tfloat)); ASSERT_ARRAY_EQ(h_result, (tfloat)((1<<bincount) - 1) / (tfloat)2, size * size / (1<<(bincount * 2))); cudaFree(d_input); cudaFree(d_result); free(h_input); free(h_result); cudaDeviceReset(); } for(int i = 9; i < 10; i++) { cudaDeviceReset(); srand(i); size_t size = (1<<i); size_t batch = 1; size_t bincount = 2; tfloat* h_input; cudaMallocHost((void**)&h_input, size * size * size * batch * sizeof(tfloat), 0); for(int b = 0; b < batch; b++) { for(int j = 0; j < size * size * size; j++) h_input[b * size * size * size + j] = (tfloat)(j % (1<<bincount)); } tfloat* d_input = (tfloat*)CudaMallocFromHostArray(h_input, size * size * size * batch * sizeof(tfloat)); tfloat* d_result; cudaMalloc((void**)&d_result, size * size * size / (1<<(bincount * 3)) * batch * sizeof(tfloat)); int3 dims; dims.x = size; dims.y = size; dims.z = size; d_Bin(d_input, d_result, dims, bincount, batch); tfloat* h_result = (tfloat*)MallocFromDeviceArray(d_result, size * size * size / (1<<(bincount * 3)) * batch * sizeof(tfloat)); ASSERT_ARRAY_EQ(h_result, (tfloat)((1<<bincount) - 1) / (tfloat)2, size * size / (1<<(bincount * 2))); cudaFreeHost(h_input); free(h_result); cudaFree(d_input); cudaFree(d_result); cudaDeviceReset(); } }