/** * @brief TEST_F SdkTestNodeOperations * * It performs different operations with nodes, assuming the Cloud folder is empty at the beginning. * * - Create a new folder * - Rename a node * - Copy a node * - Get child nodes of given node * - Get child node by name * - Get node by path * - Get node by name * - Move a node * - Get parent node * - Move a node to Rubbish bin * - Remove a node */ TEST_F(SdkTest, SdkTestNodeOperations) { // --- Create a new folder --- MegaNode *rootnode = megaApi->getRootNode(); char name1[64] = "New folder"; responseReceived = false; megaApi->createFolder(name1, rootnode); waitForResponse(&responseReceived); ASSERT_EQ(MegaError::API_OK, lastError) << "Cannot create a folder (error: " << lastError << ")"; // --- Rename a node --- MegaNode *n1 = megaApi->getNodeByHandle(h); strcpy(name1, "Folder renamed"); responseReceived = false; megaApi->renameNode(n1, name1); waitForResponse(&responseReceived); ASSERT_EQ(MegaError::API_OK, lastError) << "Cannot rename a node (error: " << lastError << ")"; // --- Copy a node --- MegaNode *n2; char name2[64] = "Folder copy"; responseReceived = false; megaApi->copyNode(n1, rootnode, name2); waitForResponse(&responseReceived); ASSERT_EQ(MegaError::API_OK, lastError) << "Cannot create a copy of a node (error: " << lastError << ")"; n2 = megaApi->getNodeByHandle(h); // --- Get child nodes --- MegaNodeList *children; children = megaApi->getChildren(rootnode); EXPECT_EQ(megaApi->getNumChildren(rootnode), children->size()) << "Wrong number of child nodes"; ASSERT_LE(2, children->size()) << "Wrong number of children nodes found"; EXPECT_STREQ(name2, children->get(0)->getName()) << "Wrong name of child node"; // "Folder copy" EXPECT_STREQ(name1, children->get(1)->getName()) << "Wrong name of child node"; // "Folder rename" delete children; // --- Get child node by name --- MegaNode *n3; n3 = megaApi->getChildNode(rootnode, name2); bool null_pointer = (n3 == NULL); EXPECT_FALSE(null_pointer) << "Child node by name not found"; // ASSERT_EQ(n2->getHandle(), n3->getHandle()); This test may fail due to multiple nodes with the same name // --- Get node by path --- char path[128] = "/Folder copy"; MegaNode *n4; n4 = megaApi->getNodeByPath(path); null_pointer = (n4 == NULL); EXPECT_FALSE(null_pointer) << "Node by path not found"; // --- Search for a node --- MegaNodeList *nlist; nlist = megaApi->search(rootnode, "copy"); ASSERT_EQ(1, nlist->size()); EXPECT_EQ(n4->getHandle(), nlist->get(0)->getHandle()) << "Search node by pattern failed"; delete nlist; // --- Move a node --- responseReceived = false; megaApi->moveNode(n1, n2); waitForResponse(&responseReceived); ASSERT_EQ(MegaError::API_OK, lastError) << "Cannot move node (error: " << lastError << ")"; // --- Get parent node --- MegaNode *n5; n5 = megaApi->getParentNode(n1); ASSERT_EQ(n2->getHandle(), n5->getHandle()) << "Wrong parent node"; // --- Send to Rubbish bin --- responseReceived = false; megaApi->moveNode(n2, megaApi->getRubbishNode()); waitForResponse(&responseReceived); ASSERT_EQ(MegaError::API_OK, lastError) << "Cannot move node to Rubbish bin (error: " << lastError << ")"; // --- Remove a node --- responseReceived = false; megaApi->remove(n2); waitForResponse(&responseReceived); ASSERT_EQ(MegaError::API_OK, lastError) << "Cannot remove a node (error: " << lastError << ")"; delete rootnode; delete n1; delete n2; delete n3; delete n4; delete n5; }
TEST(Correlation, Peak) { cudaDeviceReset(); //Case 1: { int3 dims = {8, 8, 1}; tfloat* d_input = (tfloat*)CudaMallocFromBinaryFile("Data\\Correlation\\Input_Peak_1.bin"); tfloat3* desired_output = (tfloat3*)MallocFromBinaryFile("Data\\Correlation\\Output_Peak_1.bin"); tfloat3* d_positions; cudaMalloc((void**)&d_positions, sizeof(tfloat3)); tfloat* d_values; cudaMalloc((void**)&d_values, sizeof(tfloat)); d_Peak(d_input, d_positions, d_values, dims, T_PEAK_MODE::T_PEAK_INTEGER); tfloat3* h_positions = (tfloat3*)MallocFromDeviceArray(d_positions, sizeof(tfloat3)); tfloat* h_values = (tfloat*)MallocFromDeviceArray(d_values, sizeof(tfloat)); double MeanRelative = GetMeanRelativeError((tfloat*)desired_output, (tfloat*)h_positions, 3); ASSERT_LE(MeanRelative, 1e-5); cudaFree(d_input); cudaFree(d_positions); cudaFree(d_values); free(desired_output); free(h_positions); free(h_values); } //Case 2: { int3 dims = {20, 20, 1}; tfloat* d_input = (tfloat*)CudaMallocFromBinaryFile("Data\\Correlation\\Input_Peak_2.bin"); tfloat3* desired_output = (tfloat3*)MallocFromBinaryFile("Data\\Correlation\\Output_Peak_2.bin"); tfloat3* d_positions; cudaMalloc((void**)&d_positions, sizeof(tfloat3)); tfloat* d_values; cudaMalloc((void**)&d_values, sizeof(tfloat)); d_Peak(d_input, d_positions, d_values, dims, T_PEAK_MODE::T_PEAK_SUBCOARSE); tfloat3* h_positions = (tfloat3*)MallocFromDeviceArray(d_positions, sizeof(tfloat3)); tfloat* h_values = (tfloat*)MallocFromDeviceArray(d_values, sizeof(tfloat)); double MeanRelative = GetMeanAbsoluteError((tfloat*)desired_output, (tfloat*)h_positions, DimensionCount(dims)); ASSERT_LE(MeanRelative, 0.05); cudaFree(d_input); cudaFree(d_positions); cudaFree(d_values); free(desired_output); free(h_positions); free(h_values); } //Case 3: { int3 dims = {20, 20, 1}; tfloat* d_input = (tfloat*)CudaMallocFromBinaryFile("Data\\Correlation\\Input_Peak_2.bin"); tfloat3* desired_output = (tfloat3*)MallocFromBinaryFile("Data\\Correlation\\Output_Peak_2.bin"); tfloat3* d_positions; cudaMalloc((void**)&d_positions, sizeof(tfloat3)); tfloat* d_values; cudaMalloc((void**)&d_values, sizeof(tfloat)); d_Peak(d_input, d_positions, d_values, dims, T_PEAK_MODE::T_PEAK_SUBFINE); tfloat3* h_positions = (tfloat3*)MallocFromDeviceArray(d_positions, sizeof(tfloat3)); tfloat* h_values = (tfloat*)MallocFromDeviceArray(d_values, sizeof(tfloat)); double MeanRelative = GetMeanAbsoluteError((tfloat*)desired_output, (tfloat*)h_positions, DimensionCount(dims)); ASSERT_LE(MeanRelative, 0.02); cudaFree(d_input); cudaFree(d_positions); cudaFree(d_values); free(desired_output); free(h_positions); free(h_values); } cudaDeviceReset(); }
void Setup::start_ganesha() { ASSERT_TRUE(!fs::exists(ganesha_pid_file(topdir_))); ASSERT_TRUE(fs::exists(ganesha_config_file(topdir_))); std::vector<char*> args; args.reserve(20); // just a guess to prevent too many reallocs BOOST_SCOPE_EXIT((&args)) { for (auto a : args) { free(a); } } BOOST_SCOPE_EXIT_END; #define CARG(cstr) \ args.push_back(::strdup(cstr)) #define SARG(str) \ CARG((str).c_str()) #define PARG(path) \ SARG((path).string()) if (gdbserver_port_) { CARG("gdbserver"); SARG(std::string(":") + boost::lexical_cast<std::string>(*gdbserver_port_)); } PARG(ganesha_path_); CARG("-p"); PARG(ganesha_pid_file(topdir_)); CARG("-f"); PARG(ganesha_config_file(topdir_)); CARG("-L"); PARG(topdir_ / "ganesha.log"); CARG("-N"); CARG("NIV_EVENT"); #undef CARG #undef SARG #undef PARG args.push_back(nullptr); pid_t pid = ::fork(); ASSERT_LE(0, pid); if (pid == 0) { // child int ret = 0; if (gdbserver_port_) { ret = execvp("gdbserver", args.data()); } else { ret = ::execv(ganesha_path_.c_str(), args.data()); } ASSERT_EQ(0, ret); exit(0); } ASSERT_LT(0, pid); child_pid_ = pid; wait_for_ganesha_(); }
int main(int argc, char **argv) { char *nacl_file; struct NaClApp state; struct NaClApp *nap = &state; struct NaClAppThread nat, *natp = &nat; int errcode; uint32_t initial_addr; uint32_t addr; struct NaClVmmap *mem_map; struct NaClVmmapEntry *ent; char *nacl_verbosity = getenv("NACLVERBOSITY"); NaClHandleBootstrapArgs(&argc, &argv); if (argc < 2) { printf("No nexe file!\n\nFAIL\n"); } nacl_file = argv[1]; NaClAllModulesInit(); NaClLogSetVerbosity((NULL == nacl_verbosity) ? 0 : strtol(nacl_verbosity, (char **) 0, 0)); errcode = NaClAppCtor(&state); ASSERT_NE(errcode, 0); errcode = NaClAppLoadFileFromFilename(nap, nacl_file); ASSERT_EQ(errcode, LOAD_OK); InitThread(&state, natp); /* * Initial mappings: * 0. -- Zero page * 1. rx Static code segment * 2. r Read-only data segment * 3. rw Writable data segment * 4. rw Stack * There is no dynamic code area in this case. */ /* Check the initial mappings. */ mem_map = &state.mem_map; ASSERT_EQ(mem_map->nvalid, 5); CheckLowerMappings(mem_map); /* Allocate range */ addr = NaClSysMmapIntern(nap, 0, 3 * NACL_MAP_PAGESIZE, NACL_ABI_PROT_READ | NACL_ABI_PROT_WRITE, NACL_ABI_MAP_ANONYMOUS | NACL_ABI_MAP_PRIVATE, -1, 0); printf("addr=0x%"NACL_PRIx32"\n", addr); initial_addr = addr; /* * The mappings have changed to become: * 0. -- Zero page * 1. rx Static code segment * 2. r Read-only data segment * 3. rw Writable data segment * 4. rw mmap()'d anonymous, 3 pages (new) * 5. rw Stack */ /* Map to overwrite the start of the previously allocated range */ addr = NaClSysMmapIntern(nap, (void *) (uintptr_t) initial_addr, 2 * NACL_MAP_PAGESIZE, NACL_ABI_PROT_READ | NACL_ABI_PROT_WRITE, NACL_ABI_MAP_ANONYMOUS | NACL_ABI_MAP_PRIVATE | NACL_ABI_MAP_FIXED, -1, 0); printf("addr=0x%"NACL_PRIx32"\n", addr); ASSERT_EQ(addr, initial_addr); /* * The mappings have changed to become: * 0. -- Zero page * 1. rx Static code segment * 2. r Read-only data segment * 3. rw Writable data segment * 4. rw mmap()'d anonymous, 2 pages (new) * 5. rw mmap()'d anonymous, 1 pages (previous) * 6. rw Stack */ /* Allocate new page */ addr = NaClSysMmapIntern(nap, 0, NACL_MAP_PAGESIZE, NACL_ABI_PROT_READ | NACL_ABI_PROT_WRITE, NACL_ABI_MAP_ANONYMOUS | NACL_ABI_MAP_PRIVATE, -1, 0); printf("addr=0x%"NACL_PRIx32"\n", addr); /* * Our allocation strategy is to scan down from stack. This is an * implementation detail and not part of the guaranteed semantics, * but it is good to test that what we expect of our implementation * didn't change. */ ASSERT_EQ_MSG(addr, initial_addr - NACL_MAP_PAGESIZE, "Allocation strategy changed!"); /* * The mappings have changed to become: * 0. -- Zero page * 1. rx Static code segment * 2. r Read-only data segment * 3. rw Writable data segment * 4. rw mmap()'d anonymous, 1 pages (new) * 5. rw mmap()'d anonymous, 2 pages * 6. rw mmap()'d anonymous, 1 pages * 7. rw Stack */ NaClVmmapMakeSorted(mem_map); ASSERT_EQ(mem_map->nvalid, 8); CheckLowerMappings(mem_map); NaClVmmapDebug(mem_map, "After allocations"); /* Skip mappings 0, 1, 2 and 3. */ ASSERT_EQ(mem_map->vmentry[4]->page_num, (initial_addr - NACL_MAP_PAGESIZE) >> NACL_PAGESHIFT); ASSERT_EQ(mem_map->vmentry[4]->npages, NACL_PAGES_PER_MAP); ASSERT_EQ(mem_map->vmentry[5]->page_num, initial_addr >> NACL_PAGESHIFT); ASSERT_EQ(mem_map->vmentry[5]->npages, 2 * NACL_PAGES_PER_MAP); ASSERT_EQ(mem_map->vmentry[6]->page_num, (initial_addr + 2 * NACL_MAP_PAGESIZE) >> NACL_PAGESHIFT); ASSERT_EQ(mem_map->vmentry[6]->npages, NACL_PAGES_PER_MAP); /* * Undo effects of previous mmaps */ errcode = NaClSysMunmap(natp, (void *) (uintptr_t) (initial_addr - NACL_MAP_PAGESIZE), NACL_MAP_PAGESIZE * 4); ASSERT_EQ(errcode, 0); /* * Mappings return to being: * 0. -- Zero page * 1. rx Static code segment * 2. r Read-only data segment * 3. rw Writable data segment * 4. rw Stack */ ASSERT_EQ(mem_map->nvalid, 5); CheckLowerMappings(mem_map); /* Allocate range */ addr = NaClSysMmapIntern(nap, 0, 9 * NACL_MAP_PAGESIZE, NACL_ABI_PROT_READ | NACL_ABI_PROT_WRITE, NACL_ABI_MAP_ANONYMOUS | NACL_ABI_MAP_PRIVATE, -1, 0); printf("addr=0x%"NACL_PRIx32"\n", addr); initial_addr = addr; /* * The mappings have changed to become: * 0. -- Zero page * 1. rx Static code segment * 2. r Read-only data segment * 3. rw Writable data segment * 4. rw mmap()'d anonymous, 9 pages (new) * 5. rw Stack */ /* Map into middle of previously allocated range */ addr = NaClSysMmapIntern(nap, (void *) (uintptr_t) (initial_addr + 2 * NACL_MAP_PAGESIZE), 3 * NACL_MAP_PAGESIZE, NACL_ABI_PROT_READ | NACL_ABI_PROT_WRITE, NACL_ABI_MAP_ANONYMOUS | NACL_ABI_MAP_PRIVATE | NACL_ABI_MAP_FIXED, -1, 0); printf("addr=0x%"NACL_PRIx32"\n", addr); ASSERT_EQ(addr, initial_addr + NACL_MAP_PAGESIZE * 2); /* * The mappings have changed to become: * 0. -- Zero page * 1. rx Static code segment * 2. r Read-only data segment * 3. rw Writable data segment * 4. rw mmap()'d anonymous, 2 pages (previous) * 5. rw mmap()'d anonymous, 3 pages (new) * 6. rw mmap()'d anonymous, 4 pages (previous) * 7. rw Stack */ NaClVmmapMakeSorted(mem_map); ASSERT_EQ(mem_map->nvalid, 8); CheckLowerMappings(mem_map); ASSERT_EQ(mem_map->vmentry[4]->page_num, initial_addr >> NACL_PAGESHIFT); ASSERT_EQ(mem_map->vmentry[4]->npages, 2 * NACL_PAGES_PER_MAP); ASSERT_EQ(mem_map->vmentry[5]->page_num, (initial_addr + 2 * NACL_MAP_PAGESIZE) >> NACL_PAGESHIFT); ASSERT_EQ(mem_map->vmentry[5]->npages, 3 * NACL_PAGES_PER_MAP); ASSERT_EQ(mem_map->vmentry[6]->page_num, (initial_addr + 5 * NACL_MAP_PAGESIZE) >> NACL_PAGESHIFT); ASSERT_EQ(mem_map->vmentry[6]->npages, 4 * NACL_PAGES_PER_MAP); /* Change the memory protection of previously allocated range */ errcode = NaClSysMprotectInternal(nap, (initial_addr + 1 * NACL_MAP_PAGESIZE), 5 * NACL_MAP_PAGESIZE, NACL_ABI_PROT_READ); ASSERT_EQ(errcode, 0); /* * The mappings have changed to become: * 0. -- Zero page * 1. rx Static code segment * 2. r Read-only data segment * 3. rw Writable data segment * 4. rw mmap()'d anonymous, 1 pages (previous) * 5. r mmap()'d anonymous, 1 pages (new) * 6. r mmap()'d anonymous, 3 pages (new) * 7. r mmap()'d anonymous, 1 pages (new) * 8. rw mmap()'d anonymous, 3 pages (previous) * 9. rw Stack */ NaClVmmapMakeSorted(mem_map); ASSERT_EQ(mem_map->nvalid, 10); CheckLowerMappings(mem_map); ASSERT_EQ(mem_map->vmentry[4]->npages, 1 * NACL_PAGES_PER_MAP); ASSERT_EQ(mem_map->vmentry[4]->prot, NACL_ABI_PROT_READ | NACL_ABI_PROT_WRITE); ASSERT_EQ(mem_map->vmentry[5]->npages, 1 * NACL_PAGES_PER_MAP); ASSERT_EQ(mem_map->vmentry[5]->prot, NACL_ABI_PROT_READ); ASSERT_EQ(mem_map->vmentry[6]->npages, 3 * NACL_PAGES_PER_MAP); ASSERT_EQ(mem_map->vmentry[6]->prot, NACL_ABI_PROT_READ); ASSERT_EQ(mem_map->vmentry[7]->npages, 1 * NACL_PAGES_PER_MAP); ASSERT_EQ(mem_map->vmentry[7]->prot, NACL_ABI_PROT_READ); ASSERT_EQ(mem_map->vmentry[8]->npages, 3 * NACL_PAGES_PER_MAP); ASSERT_EQ(mem_map->vmentry[8]->prot, NACL_ABI_PROT_READ | NACL_ABI_PROT_WRITE); /* Change the memory protection of previously allocated range */ errcode = NaClSysMprotectInternal(nap, (initial_addr + 2 * NACL_MAP_PAGESIZE), 3 * NACL_MAP_PAGESIZE, NACL_ABI_PROT_NONE); ASSERT_EQ(errcode, 0); /* * The mappings have changed to become: * 0. -- Zero page * 1. rx Static code segment * 2. r Read-only data segment * 3. rw Writable data segment * 4. rw mmap()'d anonymous, 1 pages (previous) * 5. r mmap()'d anonymous, 1 pages (previous) * 6. -- mmap()'d anonymous, 3 pages (new) * 7. r mmap()'d anonymous, 1 pages (previous) * 8. rw mmap()'d anonymous, 3 pages (previous) * 9. rw Stack */ NaClVmmapMakeSorted(mem_map); ASSERT_EQ(mem_map->nvalid, 10); CheckLowerMappings(mem_map); ASSERT_EQ(mem_map->vmentry[4]->npages, 1 * NACL_PAGES_PER_MAP); ASSERT_EQ(mem_map->vmentry[4]->prot, NACL_ABI_PROT_READ | NACL_ABI_PROT_WRITE); ASSERT_EQ(mem_map->vmentry[5]->npages, 1 * NACL_PAGES_PER_MAP); ASSERT_EQ(mem_map->vmentry[5]->prot, NACL_ABI_PROT_READ); ASSERT_EQ(mem_map->vmentry[6]->npages, 3 * NACL_PAGES_PER_MAP); ASSERT_EQ(mem_map->vmentry[6]->prot, NACL_ABI_PROT_NONE); ASSERT_EQ(mem_map->vmentry[7]->npages, 1 * NACL_PAGES_PER_MAP); ASSERT_EQ(mem_map->vmentry[7]->prot, NACL_ABI_PROT_READ); ASSERT_EQ(mem_map->vmentry[8]->npages, 3 * NACL_PAGES_PER_MAP); ASSERT_EQ(mem_map->vmentry[8]->prot, NACL_ABI_PROT_READ | NACL_ABI_PROT_WRITE); /* * Undo effects of previous mmaps */ errcode = NaClSysMunmap(natp, (void *) (uintptr_t) initial_addr, 9 * NACL_MAP_PAGESIZE); ASSERT_EQ(errcode, 0); ASSERT_EQ(mem_map->nvalid, 5); CheckLowerMappings(mem_map); /* * Mappings return to being: * 0. -- Zero page * 1. rx Static code segment * 2. r Read-only data segment * 3. rw Writable data segment * 4. rw Stack */ /* * Check use of hint. */ addr = NaClSysMmapIntern(nap, (void *) (uintptr_t) initial_addr, NACL_MAP_PAGESIZE, NACL_ABI_PROT_READ | NACL_ABI_PROT_WRITE, NACL_ABI_MAP_ANONYMOUS | NACL_ABI_MAP_PRIVATE, -1, 0); ASSERT_LE(addr, 0xffff0000u); printf("addr=0x%"NACL_PRIx32"\n", addr); ASSERT_LE_MSG(initial_addr, addr, "returned address not at or above hint"); errcode = NaClSysMunmap(natp, (void *) (uintptr_t) addr, NACL_MAP_PAGESIZE); ASSERT_EQ(errcode, 0); /* Check handling of zero-sized mappings. */ addr = NaClSysMmapIntern(nap, 0, 0, NACL_ABI_PROT_READ | NACL_ABI_PROT_WRITE, NACL_ABI_MAP_ANONYMOUS | NACL_ABI_MAP_PRIVATE, -1, 0); ASSERT_EQ((int) addr, -NACL_ABI_EINVAL); errcode = NaClSysMunmap(natp, (void *) (uintptr_t) initial_addr, 0); ASSERT_EQ(errcode, -NACL_ABI_EINVAL); /* Check changing the memory protection of neighbouring mmaps */ addr = NaClSysMmapIntern(nap, 0, NACL_MAP_PAGESIZE, NACL_ABI_PROT_READ | NACL_ABI_PROT_WRITE, NACL_ABI_MAP_ANONYMOUS | NACL_ABI_MAP_PRIVATE, -1, 0); printf("addr=0x%"NACL_PRIx32"\n", addr); initial_addr = addr; addr = NaClSysMmapIntern(nap, (void *) (uintptr_t) (initial_addr + NACL_MAP_PAGESIZE), NACL_MAP_PAGESIZE, NACL_ABI_PROT_READ | NACL_ABI_PROT_WRITE, NACL_ABI_MAP_ANONYMOUS | NACL_ABI_MAP_PRIVATE | NACL_ABI_MAP_FIXED, -1, 0); printf("addr=0x%"NACL_PRIx32"\n", addr); ASSERT_EQ(addr, initial_addr + NACL_MAP_PAGESIZE); errcode = NaClSysMprotectInternal(nap, initial_addr, 2 * NACL_MAP_PAGESIZE, NACL_ABI_PROT_READ); ASSERT_EQ(errcode, 0); /* Undo effects of previous mmaps */ errcode = NaClSysMunmap(natp, (void *) (uintptr_t) initial_addr, 2 * NACL_MAP_PAGESIZE); ASSERT_EQ(errcode, 0); /* Check that we cannot make the read-only data segment writable */ ent = mem_map->vmentry[2]; errcode = NaClSysMprotectInternal(nap, (uint32_t) (ent->page_num << NACL_PAGESHIFT), ent->npages * NACL_MAP_PAGESIZE, NACL_ABI_PROT_WRITE); ASSERT_EQ(errcode, -NACL_ABI_EACCES); #if NACL_ARCH(NACL_BUILD_ARCH) == NACL_x86 && NACL_BUILD_SUBARCH == 64 CheckForGuardRegion(nap->mem_start - ((size_t) 40 << 30), (size_t) 40 << 30); CheckForGuardRegion(nap->mem_start + ((size_t) 4 << 30), (size_t) 40 << 30); #endif NaClAddrSpaceFree(nap); printf("PASS\n"); return 0; }
TEST(logcat, blocking_clear) { FILE *fp; unsigned long long v = 0xDEADBEEFA55C0000ULL; pid_t pid = getpid(); v += pid & 0xFFFF; // This test is racey; an event occurs between clear and dump. // We accept that we will get a false positive, but never a false negative. ASSERT_EQ(0, NULL == (fp = popen( "( trap exit HUP QUIT INT PIPE KILL ; sleep 6; echo DONE )&" " logcat -b events -c 2>&1 ;" " logcat -b events 2>&1", "r"))); char buffer[5120]; int count = 0; int signals = 0; signal(SIGALRM, caught_blocking_clear); alarm(2); while (fgets(buffer, sizeof(buffer), fp)) { alarm(2); if (!strncmp(buffer, "clearLog: ", 10)) { fprintf(stderr, "WARNING: Test lacks permission to run :-(\n"); count = signals = 1; break; } if (!strncmp(buffer, "DONE", 4)) { break; } ++count; int p; unsigned long long l; if ((2 != sscanf(buffer, "I/[0] ( %u): %lld", &p, &l)) || (p != pid)) { continue; } if (l == v) { if (count > 1) { fprintf(stderr, "WARNING: Possible false positive\n"); } ++signals; break; } } alarm(0); signal(SIGALRM, SIG_DFL); // Generate SIGPIPE fclose(fp); caught_blocking_clear(0); pclose(fp); ASSERT_LE(1, count); ASSERT_EQ(1, signals); }
TEST(logcat, blocking_tail) { FILE *fp; unsigned long long v = 0xA55FDEADBEEF0000ULL; pid_t pid = getpid(); v += pid & 0xFFFF; LOG_FAILURE_RETRY(__android_log_btwrite(0, EVENT_TYPE_LONG, &v, sizeof(v))); v &= 0xFFFAFFFFFFFFFFFFULL; ASSERT_EQ(0, NULL == (fp = popen( "( trap exit HUP QUIT INT PIPE KILL ; sleep 6; echo DONE )&" " logcat -b events -T 5 2>&1", "r"))); char buffer[5120]; int count = 0; int signals = 0; signal(SIGALRM, caught_blocking_tail); alarm(2); while (fgets(buffer, sizeof(buffer), fp)) { alarm(2); if (!strncmp(buffer, "DONE", 4)) { break; } ++count; int p; unsigned long long l; if ((2 != sscanf(buffer, "I/[0] ( %u): %lld", &p, &l)) || (p != pid)) { continue; } if (l == v) { if (count >= 5) { ++signals; } break; } } alarm(0); signal(SIGALRM, SIG_DFL); // Generate SIGPIPE fclose(fp); caught_blocking_tail(0); pclose(fp); ASSERT_LE(2, count); ASSERT_EQ(1, signals); }
void Environment::SetUp() { uint32_t count; VkResult U_ASSERT_ONLY err; VkInstanceCreateInfo inst_info = {}; std::vector<VkExtensionProperties> instance_extensions; std::vector<VkExtensionProperties> device_extensions; std::vector<const char *> instance_extension_names; std::vector<const char *> device_extension_names; instance_extension_names.push_back(VK_KHR_SURFACE_EXTENSION_NAME); device_extension_names.push_back(VK_KHR_SWAPCHAIN_EXTENSION_NAME); #ifdef _WIN32 instance_extension_names.push_back(VK_KHR_WIN32_SURFACE_EXTENSION_NAME); #endif #ifdef VK_USE_PLATFORM_XCB_KHR instance_extension_names.push_back(VK_KHR_XCB_SURFACE_EXTENSION_NAME); #endif VkBool32 extFound; instance_extensions = vk_testing::GetGlobalExtensions(); for (uint32_t i = 0; i < instance_extension_names.size(); i++) { extFound = 0; for (uint32_t j = 0; j < instance_extensions.size(); j++) { if (!strcmp(instance_extension_names[i], instance_extensions[j].extensionName)) { extFound = 1; } } ASSERT_EQ(extFound, 1) << "ERROR: Cannot find extension named " << instance_extension_names[i] << " which is necessary to pass this test"; } inst_info.sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO; inst_info.pNext = NULL; inst_info.pApplicationInfo = &app_; inst_info.enabledExtensionCount = instance_extension_names.size(); inst_info.ppEnabledExtensionNames = (instance_extension_names.size()) ? &instance_extension_names[0] : NULL; inst_info.enabledLayerCount = 0; inst_info.ppEnabledLayerNames = NULL; err = vkCreateInstance(&inst_info, NULL, &inst); ASSERT_EQ(VK_SUCCESS, err); err = vkEnumeratePhysicalDevices(inst, &count, NULL); ASSERT_EQ(VK_SUCCESS, err); ASSERT_LE(count, ARRAY_SIZE(gpus)); err = vkEnumeratePhysicalDevices(inst, &count, gpus); ASSERT_EQ(VK_SUCCESS, err); ASSERT_GT(count, default_dev_); vk_testing::PhysicalDevice phys_dev(gpus[0]); device_extensions = phys_dev.extensions(); for (uint32_t i = 0; i < device_extension_names.size(); i++) { extFound = 0; for (uint32_t j = 0; j < device_extensions.size(); j++) { if (!strcmp(device_extension_names[i], device_extensions[j].extensionName)) { extFound = 1; } } ASSERT_EQ(extFound, 1) << "ERROR: Cannot find extension named " << device_extension_names[i] << " which is necessary to pass this test"; } devs_.reserve(count); for (uint32_t i = 0; i < count; i++) { devs_.push_back(new Device(gpus[i])); if (i == default_dev_) { devs_[i]->init(device_extension_names); ASSERT_NE(true, devs_[i]->graphics_queues().empty()); } } }
void NasmInsnRunner::ParseAndTestLine(const char* filename, const llvm::StringRef& line, int linenum) { SCOPED_TRACE(llvm::format("%s:%d", filename, linenum)); llvm::StringRef insn_in, golden_in; llvm::tie(insn_in, golden_in) = line.split(';'); insn_in = strip(insn_in); golden_in = strip(golden_in); // Handle bits directive if (golden_in.empty() && insn_in.startswith("[bits ")) { int bits = atoi(insn_in.substr(6, 2).str().c_str()); if (bits == 64) m_arch->setMachine("amd64"); else m_arch->setMachine("x86"); m_arch->setVar("mode_bits", bits); return; } if (insn_in.empty() || golden_in.empty()) return; // skip lines that don't have both text and a comment // // parse the golden result // llvm::SmallVector<unsigned char, 64> golden; llvm::StringRef golden_errwarn; for (;;) { // strip whitespace golden_in = strip(golden_in); if (golden_in.empty() || !isxdigit(golden_in[0])) break; unsigned int byte_val = 0x100; llvm::StringRef byte_str; llvm::tie(byte_str, golden_in) = golden_in.split(' '); if (byte_str.size() == 2) // assume hex byte_val = (fromhexdigit(byte_str[0]) << 4) | fromhexdigit(byte_str[1]); else if (byte_str.size() == 3) // assume octal byte_val = (fromoctdigit(byte_str[0]) << 6) | (fromoctdigit(byte_str[1]) << 3) | fromoctdigit(byte_str[2]); ASSERT_LE(byte_val, 0xffU) << "invalid golden value"; golden.push_back(byte_val); } // interpret string in [] as error/warning if (!golden_in.empty() && golden_in[0] == '[') llvm::tie(golden_errwarn, golden_in) = golden_in.substr(1).split(']'); // // parse the instruction // ::testing::StrictMock<MockDiagnosticString> mock_consumer; llvm::IntrusiveRefCntPtr<DiagnosticIDs> diagids(new DiagnosticIDs); DiagnosticsEngine diags(diagids, &mock_consumer, false); FileSystemOptions opts; FileManager fmgr(opts); SourceManager smgr(diags, fmgr); diags.setSourceManager(&smgr); // instruction name is the first thing on the line llvm::StringRef insn_name; llvm::tie(insn_name, insn_in) = insn_in.split(' '); Arch::InsnPrefix insnprefix = m_arch->ParseCheckInsnPrefix(insn_name, SourceLocation(), diags); ASSERT_TRUE(insnprefix.isType(Arch::InsnPrefix::INSN)); std::auto_ptr<Insn> insn = m_arch->CreateInsn(insnprefix.getInsn()); ASSERT_TRUE(insn.get() != 0) << "unrecognized instruction '" << insn_name.str() << "'"; // parse insn arguments unsigned int wsize = m_arch_module->getWordSize(); // strip whitespace from arguments insn_in = strip(insn_in); while (!insn_in.empty()) { llvm::StringRef arg_str; llvm::tie(arg_str, insn_in) = insn_in.split(','); // strip whitespace from arg arg_str = strip(arg_str); unsigned int size = 0; bool strict = false; for (;;) { int next; int nsize = 0; // operand overrides (size and strict) if (arg_str.startswith("byte ")) { nsize = 8; next = 5; } else if (arg_str.startswith("hword ")) { nsize = wsize/2; next = 6; } else if (arg_str.startswith("word ")) { nsize = wsize; next = 5; } else if (arg_str.startswith("dword ")) { nsize = wsize*2; next = 6; } else if (arg_str.startswith("qword ")) { nsize = wsize*4; next = 6; } else if (arg_str.startswith("tword ")) { nsize = 80; next = 6; } else if (arg_str.startswith("dqword ")) { nsize = wsize*8; next = 7; } else if (arg_str.startswith("oword ")) { nsize = wsize*8; next = 6; } else if (arg_str.startswith("yword ")) { nsize = 256; next = 6; } else if (arg_str.startswith("strict ")) { strict = true; next = 7; } else break; if (size == 0) size = nsize; arg_str = arg_str.substr(next); } if (arg_str[0] == '[') { // Very simple int/reg expression parser. Does not handle parens or // order of operations; simply builds expr from left to right. // This means r8*4+r9 will have a different result than r9+r8*4! // Also only handles binary operators * and +. llvm::StringRef estr = arg_str.slice(1, arg_str.find(']')+1); std::auto_ptr<Expr> e(new Expr); char pendingop = '\0'; std::size_t tokstart = 0; for (std::size_t pos = 0; pos < estr.size(); ++pos) { if (estr[pos] == '*' || estr[pos] == '+' || estr[pos] == ']') { // figure out this token llvm::StringRef tok = strip(estr.slice(tokstart, pos)); if (isdigit(estr[tokstart])) e->Append(strtoint(tok)); else { Arch::RegTmod regtmod = m_arch->ParseCheckRegTmod(tok, SourceLocation(), diags); ASSERT_TRUE(regtmod.isType(Arch::RegTmod::REG)) << "cannot handle label '" << tok.str() << "'"; e->Append(*regtmod.getReg()); } // append pending operator if (pendingop == '*') e->AppendOp(Op::MUL, 2); else if (pendingop == '+') e->AppendOp(Op::ADD, 2); // store new operator pendingop = estr[pos]; tokstart = pos+1; } } Operand operand(m_arch->CreateEffAddr(e)); operand.setSize(size); operand.setStrict(strict); insn->AddOperand(operand); continue; } // TODO: split by space to allow target modifiers // Test for registers Arch::RegTmod regtmod = m_arch->ParseCheckRegTmod(arg_str, SourceLocation(), diags); if (const Register* reg = regtmod.getReg()) { Operand operand(reg); operand.setSize(size); operand.setStrict(strict); insn->AddOperand(operand); continue; } else if (const SegmentRegister* segreg = regtmod.getSegReg()) { Operand operand(segreg); operand.setSize(size); operand.setStrict(strict); insn->AddOperand(operand); continue; } else if (regtmod.getTargetMod()) { FAIL() << "cannot handle target modifier"; } else if (regtmod.getRegGroup()) { FAIL() << "cannot handle register group"; } // Can't handle labels ASSERT_TRUE(isdigit(arg_str[0]) || arg_str[0] == '-') << "cannot handle label '" << arg_str.str() << "'"; // Convert to integer expression Operand intop(Expr::Ptr(new Expr(strtoint(arg_str)))); intop.setSize(size); intop.setStrict(strict); insn->AddOperand(intop); } TestInsn(insn.get(), golden.size(), golden.data(), golden_errwarn); }
TEST( SDCFsiTest, reuse ) { std::vector<int> nbIter; for ( int nbReuse = 0; nbReuse < 3; nbReuse++ ) { scalar r0 = 0.2; scalar a0 = M_PI * r0 * r0; scalar u0 = 0.1; scalar p0 = 0; scalar dt = 0.01; int N = 20; scalar L = 1; scalar T = 1; scalar dx = L / N; scalar rho = 1.225; scalar E = 490; scalar h = 1.0e-3; scalar cmk = std::sqrt( E * h / (2 * rho * r0) ); scalar c0 = std::sqrt( cmk * cmk - p0 / (2 * rho) ); scalar kappa = c0 / u0; bool parallel = false; int extrapolation = 0; scalar tol = 1.0e-5; int maxIter = 50; scalar initialRelaxation = 1.0e-3; int maxUsedIterations = 50; scalar singularityLimit = 1.0e-13; int reuseInformationStartingFromTimeIndex = 0; bool scaling = false; bool updateJacobian = false; scalar beta = 0.1; int minIter = 5; ASSERT_NEAR( kappa, 10, 1.0e-13 ); ASSERT_TRUE( dx > 0 ); std::shared_ptr<tubeflow::SDCTubeFlowFluidSolver> fluid( new tubeflow::SDCTubeFlowFluidSolver( a0, u0, p0, dt, cmk, N, L, T, rho ) ); std::shared_ptr<tubeflow::SDCTubeFlowSolidSolver> solid( new tubeflow::SDCTubeFlowSolidSolver( a0, cmk, p0, rho, L, N ) ); shared_ptr<RBFFunctionInterface> rbfFunction; shared_ptr<RBFInterpolation> rbfInterpolator; shared_ptr<RBFCoarsening> rbfInterpToCouplingMesh; shared_ptr<RBFCoarsening> rbfInterpToMesh; rbfFunction = shared_ptr<RBFFunctionInterface>( new TPSFunction() ); rbfInterpolator = shared_ptr<RBFInterpolation>( new RBFInterpolation( rbfFunction ) ); rbfInterpToCouplingMesh = shared_ptr<RBFCoarsening> ( new RBFCoarsening( rbfInterpolator ) ); rbfFunction = shared_ptr<RBFFunctionInterface>( new TPSFunction() ); rbfInterpolator = shared_ptr<RBFInterpolation>( new RBFInterpolation( rbfFunction ) ); rbfInterpToMesh = shared_ptr<RBFCoarsening> ( new RBFCoarsening( rbfInterpolator ) ); shared_ptr<MultiLevelSolver> fluidSolver( new MultiLevelSolver( fluid, fluid, rbfInterpToCouplingMesh, rbfInterpToMesh, 0, 0 ) ); rbfFunction = shared_ptr<RBFFunctionInterface>( new TPSFunction() ); rbfInterpolator = shared_ptr<RBFInterpolation>( new RBFInterpolation( rbfFunction ) ); rbfInterpToCouplingMesh = shared_ptr<RBFCoarsening> ( new RBFCoarsening( rbfInterpolator ) ); rbfFunction = shared_ptr<RBFFunctionInterface>( new TPSFunction() ); rbfInterpolator = shared_ptr<RBFInterpolation>( new RBFInterpolation( rbfFunction ) ); rbfInterpToMesh = shared_ptr<RBFCoarsening> ( new RBFCoarsening( rbfInterpolator ) ); shared_ptr<MultiLevelSolver> solidSolver( new MultiLevelSolver( solid, fluid, rbfInterpToCouplingMesh, rbfInterpToMesh, 1, 0 ) ); std::shared_ptr< std::list<std::shared_ptr<ConvergenceMeasure> > > convergenceMeasures; convergenceMeasures = std::shared_ptr<std::list<std::shared_ptr<ConvergenceMeasure> > >( new std::list<std::shared_ptr<ConvergenceMeasure> > ); convergenceMeasures->push_back( std::shared_ptr<ConvergenceMeasure>( new RelativeConvergenceMeasure( 0, false, tol ) ) ); convergenceMeasures->push_back( std::shared_ptr<ConvergenceMeasure>( new MinIterationConvergenceMeasure( 0, false, minIter ) ) ); shared_ptr<MultiLevelFsiSolver> fsi( new MultiLevelFsiSolver( fluidSolver, solidSolver, convergenceMeasures, parallel, extrapolation ) ); shared_ptr<PostProcessing> postProcessing( new AndersonPostProcessing( fsi, maxIter, initialRelaxation, maxUsedIterations, nbReuse, singularityLimit, reuseInformationStartingFromTimeIndex, scaling, beta, updateJacobian ) ); std::shared_ptr<sdc::SDCFsiSolverInterface> sdcFluidSolver = std::dynamic_pointer_cast<sdc::SDCFsiSolverInterface>( fluid ); std::shared_ptr<sdc::SDCFsiSolverInterface> sdcSolidSolver = std::dynamic_pointer_cast<sdc::SDCFsiSolverInterface>( solid ); assert( sdcFluidSolver ); assert( sdcSolidSolver ); std::shared_ptr<fsi::SDCFsiSolver> fsiSolver( new fsi::SDCFsiSolver( sdcFluidSolver, sdcSolidSolver, postProcessing, extrapolation ) ); int nbNodes = 3; std::shared_ptr<fsi::quadrature::IQuadrature<scalar> > quadrature; quadrature = std::shared_ptr<fsi::quadrature::IQuadrature<scalar> >( new fsi::quadrature::Uniform<scalar>( nbNodes ) ); std::shared_ptr<sdc::SDC> sdc( new sdc::SDC( fsiSolver, quadrature, 1.0e-10, nbNodes, nbNodes ) ); sdc->run(); nbIter.push_back( fsi->nbIter ); } int iprev; int index = 0; for ( int i : nbIter ) { std::cout << "nbIter = " << i << std::endl; if ( index > 0 ) ASSERT_LE( i, iprev ); iprev = i; index++; } }